Bug 1297031 - Force to use group in DrawTargetSkia::DrawSurface when colorType is kAlpha_8_SkColorType. r=lsalzman
authorEthan Lin <ethlin@mozilla.com>
Fri, 26 Aug 2016 12:42:12 +0800
changeset 311365 e78454e242072bbcada626874f2900bbe1c3e647
parent 311364 ccf3d0b90b0422b169c60d429029cdfdc0e5a5a0
child 311366 bb4b998ebc50f6bcb47471905ec54a6b8ab134c5
push id20395
push userryanvm@gmail.com
push dateFri, 26 Aug 2016 13:37:30 +0000
treeherderfx-team@a65b35c8e5b1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslsalzman
bugs1297031
milestone51.0a1
Bug 1297031 - Force to use group in DrawTargetSkia::DrawSurface when colorType is kAlpha_8_SkColorType. r=lsalzman MozReview-Commit-ID: 7It9JP4WLh5
gfx/2d/DrawTargetSkia.cpp
--- a/gfx/2d/DrawTargetSkia.cpp
+++ b/gfx/2d/DrawTargetSkia.cpp
@@ -416,47 +416,48 @@ GetClipBounds(SkCanvas *aCanvas)
   inverseCTM.mapRect(&localBounds, SkRect::Make(deviceBounds));
   return SkRectToRect(localBounds);
 }
 
 struct AutoPaintSetup {
   AutoPaintSetup(SkCanvas *aCanvas, const DrawOptions& aOptions, const Pattern& aPattern, const Rect* aMaskBounds = nullptr, Point aOffset = Point(0, 0))
     : mNeedsRestore(false), mAlpha(1.0)
   {
-    Init(aCanvas, aOptions, aMaskBounds);
+    Init(aCanvas, aOptions, aMaskBounds, false);
     SetPaintPattern(mPaint, aPattern, mAlpha, aOffset);
   }
 
-  AutoPaintSetup(SkCanvas *aCanvas, const DrawOptions& aOptions, const Rect* aMaskBounds = nullptr)
+  AutoPaintSetup(SkCanvas *aCanvas, const DrawOptions& aOptions, const Rect* aMaskBounds = nullptr, bool aForceGroup = false)
     : mNeedsRestore(false), mAlpha(1.0)
   {
-    Init(aCanvas, aOptions, aMaskBounds);
+    Init(aCanvas, aOptions, aMaskBounds, aForceGroup);
   }
 
   ~AutoPaintSetup()
   {
     if (mNeedsRestore) {
       mCanvas->restore();
     }
   }
 
-  void Init(SkCanvas *aCanvas, const DrawOptions& aOptions, const Rect* aMaskBounds)
+  void Init(SkCanvas *aCanvas, const DrawOptions& aOptions, const Rect* aMaskBounds, bool aForceGroup)
   {
     mPaint.setXfermodeMode(GfxOpToSkiaOp(aOptions.mCompositionOp));
     mCanvas = aCanvas;
 
     //TODO: Can we set greyscale somehow?
     if (aOptions.mAntialiasMode != AntialiasMode::NONE) {
       mPaint.setAntiAlias(true);
     } else {
       mPaint.setAntiAlias(false);
     }
 
-    bool needsGroup = !IsOperatorBoundByMask(aOptions.mCompositionOp) &&
-                      (!aMaskBounds || !aMaskBounds->Contains(GetClipBounds(aCanvas)));
+    bool needsGroup = aForceGroup ||
+                      (!IsOperatorBoundByMask(aOptions.mCompositionOp) &&
+                       (!aMaskBounds || !aMaskBounds->Contains(GetClipBounds(aCanvas))));
 
     // TODO: We could skip the temporary for operator_source and just
     // clear the clip rect. The other operators would be harder
     // but could be worth it to skip pushing a group.
     if (needsGroup) {
       mPaint.setXfermodeMode(SkXfermode::kSrcOver_Mode);
       SkPaint temp;
       temp.setXfermodeMode(GfxOpToSkiaOp(aOptions.mCompositionOp));
@@ -505,20 +506,21 @@ DrawTargetSkia::DrawSurface(SourceSurfac
   if (aSource.IsEmpty()) {
     return;
   }
 
   MarkChanged();
 
   SkRect destRect = RectToSkRect(aDest);
   SkRect sourceRect = RectToSkRect(aSource);
+  SkBitmap bitmap = GetBitmapForSurface(aSurface);
+  bool forceGroup = bitmap.colorType() == kAlpha_8_SkColorType &&
+                    aOptions.mCompositionOp != CompositionOp::OP_OVER;
 
-  SkBitmap bitmap = GetBitmapForSurface(aSurface);
-
-  AutoPaintSetup paint(mCanvas.get(), aOptions, &aDest);
+  AutoPaintSetup paint(mCanvas.get(), aOptions, &aDest, forceGroup);
   if (aSurfOptions.mSamplingFilter == SamplingFilter::POINT) {
     paint.mPaint.setFilterQuality(kNone_SkFilterQuality);
   }
 
   mCanvas->drawBitmapRect(bitmap, sourceRect, destRect, &paint.mPaint);
 }
 
 DrawTargetType