Bug 1022930 - Fix crash in imgFrame::Draw() when drawing for an SVG mask. r=mwu, a=lmandel
authorJonathan Watt <jwatt@jwatt.org>
Tue, 10 Jun 2014 07:02:22 +0100
changeset 207416 417056b401e53b52ef6238c71797915f1857f70a
parent 207415 7a707f09673f43e68ada7a56d1336a0056a387db
child 207417 80f77d10896bdd11dff4a49962b344801136f7a9
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmwu, lmandel
bugs1022930
milestone32.0a2
Bug 1022930 - Fix crash in imgFrame::Draw() when drawing for an SVG mask. r=mwu, a=lmandel
gfx/thebes/gfx2DGlue.h
image/src/imgFrame.cpp
--- a/gfx/thebes/gfx2DGlue.h
+++ b/gfx/thebes/gfx2DGlue.h
@@ -44,16 +44,21 @@ inline IntRect ToIntRect(const nsIntRect
 }
 
 inline Color ToColor(const gfxRGBA &aRGBA)
 {
   return Color(Float(aRGBA.r), Float(aRGBA.g),
                Float(aRGBA.b), Float(aRGBA.a));
 }
 
+inline gfxRGBA ThebesColor(Color &aColor)
+{
+  return gfxRGBA(aColor.r, aColor.g, aColor.b, aColor.a);
+}
+
 inline Matrix ToMatrix(const gfxMatrix &aMatrix)
 {
   return Matrix(Float(aMatrix.xx), Float(aMatrix.yx), Float(aMatrix.xy),
                 Float(aMatrix.yy), Float(aMatrix.x0), Float(aMatrix.y0));
 }
 
 inline gfxMatrix ThebesMatrix(const Matrix &aMatrix)
 {
--- a/image/src/imgFrame.cpp
+++ b/image/src/imgFrame.cpp
@@ -385,26 +385,39 @@ bool imgFrame::Draw(gfxContext *aContext
 
   NS_ASSERTION(!aFill.IsEmpty(), "zero dest size --- fix caller");
   NS_ASSERTION(!aSubimage.IsEmpty(), "zero source size --- fix caller");
   NS_ASSERTION(!mPalettedImageData, "Directly drawing a paletted image!");
 
   bool doPadding = aPadding != nsIntMargin(0,0,0,0);
   bool doPartialDecode = !ImageComplete();
 
-  RefPtr<DrawTarget> dt = aContext->GetDrawTarget();
-
   if (mSinglePixel && !doPadding && !doPartialDecode) {
     if (mSinglePixelColor.a == 0.0) {
       return true;
     }
 
-    Rect target(aFill.x, aFill.y, aFill.width, aFill.height);
-    dt->FillRect(target, ColorPattern(mSinglePixelColor),
-                 DrawOptions(1.0f, CompositionOpForOp(aContext->CurrentOperator())));
+    if (aContext->IsCairo()) {
+      gfxContext::GraphicsOperator op = aContext->CurrentOperator();
+      if (op == gfxContext::OPERATOR_OVER && mSinglePixelColor.a == 1.0) {
+        aContext->SetOperator(gfxContext::OPERATOR_SOURCE);
+      }
+      aContext->SetDeviceColor(ThebesColor(mSinglePixelColor));
+      aContext->NewPath();
+      aContext->Rectangle(aFill);
+      aContext->Fill();
+      aContext->SetOperator(op);
+      aContext->SetDeviceColor(gfxRGBA(0,0,0,0));
+      return true;
+    }
+    RefPtr<DrawTarget> dt = aContext->GetDrawTarget();
+    dt->FillRect(ToRect(aFill),
+                 ColorPattern(mSinglePixelColor),
+                 DrawOptions(1.0f,
+                             CompositionOpForOp(aContext->CurrentOperator())));
     return true;
   }
 
   gfxMatrix userSpaceToImageSpace = aUserSpaceToImageSpace;
   gfxRect sourceRect = userSpaceToImageSpace.TransformBounds(aFill);
   gfxRect imageRect(0, 0, mSize.width + aPadding.LeftRight(),
                     mSize.height + aPadding.TopBottom());
   gfxRect subimage(aSubimage.x, aSubimage.y, aSubimage.width, aSubimage.height);