Bug 1239040 - Cleanup of DrawTargetSkia Mask and MaskSurface. r=jrmuizel
authorLee Salzman <lsalzman@mozilla.com>
Tue, 12 Jan 2016 13:26:31 -0500
changeset 280120 0798566a8d006106e4100976436378ce7521c422
parent 280119 f52b5d9ac7637361306fb9e3b92f8bddda9e4c92
child 280121 a32088113b26dad281acdab51299a75b9022357e
push id29900
push usercbook@mozilla.com
push dateFri, 15 Jan 2016 10:47:20 +0000
treeherdermozilla-central@e1486d83107f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1239040
milestone46.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1239040 - Cleanup of DrawTargetSkia Mask and MaskSurface. r=jrmuizel
gfx/2d/DrawTargetSkia.cpp
gfx/2d/DrawTargetSkia.h
--- a/gfx/2d/DrawTargetSkia.cpp
+++ b/gfx/2d/DrawTargetSkia.cpp
@@ -191,61 +191,50 @@ SetPaintPattern(SkPaint& aPaint, const P
       GradientStopsSkia *stops = static_cast<GradientStopsSkia*>(pat.mStops.get());
       SkShader::TileMode mode = ExtendModeToTileMode(stops->mExtendMode, Axis::BOTH);
 
       if (stops->mCount >= 2) {
         SkPoint points[2];
         points[0] = SkPoint::Make(SkFloatToScalar(pat.mBegin.x), SkFloatToScalar(pat.mBegin.y));
         points[1] = SkPoint::Make(SkFloatToScalar(pat.mEnd.x), SkFloatToScalar(pat.mEnd.y));
 
+        SkMatrix mat;
+        GfxMatrixToSkiaMatrix(pat.mMatrix, mat);
         SkShader* shader = SkGradientShader::CreateLinear(points,
                                                           &stops->mColors.front(),
                                                           &stops->mPositions.front(),
                                                           stops->mCount,
-                                                          mode);
-
-        if (shader) {
-            SkMatrix mat;
-            GfxMatrixToSkiaMatrix(pat.mMatrix, mat);
-            SkShader* matrixShader = SkShader::CreateLocalMatrixShader(shader, mat);
-            SkSafeUnref(shader);
-            SkSafeUnref(aPaint.setShader(matrixShader));
-        }
-
+                                                          mode, 0, &mat);
+        SkSafeUnref(aPaint.setShader(shader));
       } else {
         aPaint.setColor(SkColorSetARGB(0, 0, 0, 0));
       }
       break;
     }
     case PatternType::RADIAL_GRADIENT: {
       const RadialGradientPattern& pat = static_cast<const RadialGradientPattern&>(aPattern);
       GradientStopsSkia *stops = static_cast<GradientStopsSkia*>(pat.mStops.get());
       SkShader::TileMode mode = ExtendModeToTileMode(stops->mExtendMode, Axis::BOTH);
 
       if (stops->mCount >= 2) {
         SkPoint points[2];
         points[0] = SkPoint::Make(SkFloatToScalar(pat.mCenter1.x), SkFloatToScalar(pat.mCenter1.y));
         points[1] = SkPoint::Make(SkFloatToScalar(pat.mCenter2.x), SkFloatToScalar(pat.mCenter2.y));
 
+        SkMatrix mat;
+        GfxMatrixToSkiaMatrix(pat.mMatrix, mat);
         SkShader* shader = SkGradientShader::CreateTwoPointConical(points[0],
                                                                    SkFloatToScalar(pat.mRadius1),
                                                                    points[1],
                                                                    SkFloatToScalar(pat.mRadius2),
                                                                    &stops->mColors.front(),
                                                                    &stops->mPositions.front(),
                                                                    stops->mCount,
-                                                                   mode);
-        if (shader) {
-            SkMatrix mat;
-            GfxMatrixToSkiaMatrix(pat.mMatrix, mat);
-            SkShader* matrixShader = SkShader::CreateLocalMatrixShader(shader, mat);
-            SkSafeUnref(shader);
-            SkSafeUnref(aPaint.setShader(matrixShader));
-        }
-
+                                                                   mode, 0, &mat);
+        SkSafeUnref(aPaint.setShader(shader));
       } else {
         aPaint.setColor(SkColorSetARGB(0, 0, 0, 0));
       }
       break;
     }
     case PatternType::SURFACE: {
       const SurfacePattern& pat = static_cast<const SurfacePattern&>(aPattern);
       SkBitmap bitmap = GetBitmapForSurface(pat.mSurface);
@@ -257,20 +246,18 @@ SetPaintPattern(SkPaint& aPaint, const P
         SkIRect rect = IntRectToSkIRect(pat.mSamplingRect);
         bitmap.extractSubset(&bitmap, rect);
         mat.preTranslate(rect.x(), rect.y());
       }
 
       SkShader::TileMode xTileMode = ExtendModeToTileMode(pat.mExtendMode, Axis::X_AXIS);
       SkShader::TileMode yTileMode = ExtendModeToTileMode(pat.mExtendMode, Axis::Y_AXIS);
 
-      SkShader* shader = SkShader::CreateBitmapShader(bitmap, xTileMode, yTileMode);
-      SkShader* matrixShader = SkShader::CreateLocalMatrixShader(shader, mat);
-      SkSafeUnref(shader);
-      SkSafeUnref(aPaint.setShader(matrixShader));
+      SkShader* shader = SkShader::CreateBitmapShader(bitmap, xTileMode, yTileMode, &mat);
+      SkSafeUnref(aPaint.setShader(shader));
       if (pat.mFilter == Filter::POINT) {
         aPaint.setFilterQuality(kNone_SkFilterQuality);
       }
       break;
     }
   }
 }
 
@@ -647,52 +634,43 @@ DrawTargetSkia::Mask(const Pattern &aSou
   SkPaint maskPaint;
   SetPaintPattern(maskPaint, aMask);
 
   SkLayerRasterizer::Builder builder;
   builder.addLayer(maskPaint);
   SkAutoTUnref<SkRasterizer> raster(builder.detachRasterizer());
   paint.mPaint.setRasterizer(raster.get());
 
-  mCanvas->drawRect(SkRectCoveringWholeSurface(), paint.mPaint);
+  mCanvas->drawPaint(paint.mPaint);
 }
 
 void
 DrawTargetSkia::MaskSurface(const Pattern &aSource,
                             SourceSurface *aMask,
                             Point aOffset,
                             const DrawOptions &aOptions)
 {
   MarkChanged();
   AutoPaintSetup paint(mCanvas.get(), aOptions, aSource);
 
   SkBitmap bitmap = GetBitmapForSurface(aMask);
-  if (bitmap.colorType() == kAlpha_8_SkColorType) {
-    if (aOffset != Point(0, 0)) {
-      SkMatrix transform;
-      transform.setTranslate(SkFloatToScalar(-aOffset.x), SkFloatToScalar(-aOffset.y));
-      SkShader* matrixShader = SkShader::CreateLocalMatrixShader(paint.mPaint.getShader(), transform);
-      SkSafeUnref(paint.mPaint.setShader(matrixShader));
-    }
+  if (bitmap.colorType() != kAlpha_8_SkColorType &&
+      !bitmap.extractAlpha(&bitmap)) {
+    gfxDebug() << *this << ": MaskSurface() failed to extract alpha for mask";
+    return;
+  }
 
-    mCanvas->drawBitmap(bitmap, aOffset.x, aOffset.y, &paint.mPaint);
-  } else {
-    SkPaint maskPaint;
-    SetPaintPattern(maskPaint,
-                    SurfacePattern(aMask, ExtendMode::CLAMP, Matrix::Translation(aOffset)));
+  if (aOffset != Point(0, 0)) {
+    SkMatrix transform;
+    transform.setTranslate(SkFloatToScalar(-aOffset.x), SkFloatToScalar(-aOffset.y));
+    SkShader* matrixShader = SkShader::CreateLocalMatrixShader(paint.mPaint.getShader(), transform);
+    SkSafeUnref(paint.mPaint.setShader(matrixShader));
+  }
 
-    SkLayerRasterizer::Builder builder;
-    builder.addLayer(maskPaint);
-    SkAutoTUnref<SkRasterizer> raster(builder.detachRasterizer());
-    paint.mPaint.setRasterizer(raster.get());
-
-    IntSize size = aMask->GetSize();
-    Rect rect = Rect(aOffset.x, aOffset.y, size.width, size.height);
-    mCanvas->drawRect(RectToSkRect(rect), paint.mPaint);
-  }
+  mCanvas->drawBitmap(bitmap, aOffset.x, aOffset.y, &paint.mPaint);
 }
 
 already_AddRefed<SourceSurface>
 DrawTargetSkia::CreateSourceSurfaceFromData(unsigned char *aData,
                                             const IntSize &aSize,
                                             int32_t aStride,
                                             SurfaceFormat aFormat) const
 {
@@ -1029,24 +1007,16 @@ void
 DrawTargetSkia::MarkChanged()
 {
   if (mSnapshot) {
     mSnapshot->DrawTargetWillChange();
     mSnapshot = nullptr;
   }
 }
 
-// Return a rect (in user space) that covers the entire surface by applying
-// the inverse of GetTransform() to (0, 0, mSize.width, mSize.height).
-SkRect
-DrawTargetSkia::SkRectCoveringWholeSurface() const
-{
-  return RectToSkRect(mTransform.TransformBounds(Rect(0, 0, mSize.width, mSize.height)));
-}
-
 void
 DrawTargetSkia::SnapshotDestroyed()
 {
   mSnapshot = nullptr;
 }
 
 } // namespace gfx
 } // namespace mozilla
--- a/gfx/2d/DrawTargetSkia.h
+++ b/gfx/2d/DrawTargetSkia.h
@@ -131,18 +131,16 @@ public:
 private:
   friend class SourceSurfaceSkia;
   void SnapshotDestroyed();
 
   void MarkChanged();
 
   bool ShouldLCDRenderText(FontType aFontType, AntialiasMode aAntialiasMode);
 
-  SkRect SkRectCoveringWholeSurface() const;
-
   bool UsingSkiaGPU() const;
 
 #ifdef USE_SKIA_GPU
   RefPtrSkia<GrContext> mGrContext;
   GrGLuint mTexture;
 #endif
 
   IntSize mSize;