Bug 1324174 - Simplify context management logic in nsSVGIntegrationUtils::PaintMask. draft
authorcku <cku@mozilla.com>
Fri, 30 Dec 2016 02:07:04 +0800
changeset 454557 7e6b1f14c1e72f909f2aeaf09e04712a2e725f79
parent 454520 87efd66165ddaa1b97608b92cd651b73c11aca6f
child 540748 a18e466618b8cc166ece0baf89b484ce63f985a3
push id39973
push usercku@mozilla.com
push dateThu, 29 Dec 2016 18:08:50 +0000
bugs1324174
milestone53.0a1
Bug 1324174 - Simplify context management logic in nsSVGIntegrationUtils::PaintMask. MozReview-Commit-ID: BwPSFlfqN8e
layout/svg/nsSVGIntegrationUtils.cpp
--- a/layout/svg/nsSVGIntegrationUtils.cpp
+++ b/layout/svg/nsSVGIntegrationUtils.cpp
@@ -745,90 +745,82 @@ nsSVGIntegrationUtils::PaintMask(const P
   nsSVGUtils::DetermineMaskUsage(aParams.frame, aParams.handleOpacity,
                                  maskUsage);
 
   nsIFrame* frame = aParams.frame;
   if (!ValidateSVGFrame(frame)) {
     return DrawResult::SUCCESS;
   }
 
-  if (maskUsage.opacity == 0.0f) {
-    return DrawResult::SUCCESS;
-  }
+  // XXX Bug 1323912.
+  MOZ_ASSERT(maskUsage.opacity == 1.0,
+             "nsSVGIntegrationUtils::PaintMask can not handle opacity now.");
 
   gfxContext& ctx = aParams.ctx;
   nsIFrame* firstFrame =
     nsLayoutUtils::FirstContinuationOrIBSplitSibling(frame);
   nsSVGEffects::EffectProperties effectProperties =
     nsSVGEffects::GetEffectProperties(firstFrame);
 
   DrawResult result = DrawResult::SUCCESS;
-  nsPoint offsetToBoundingBox;
-  nsPoint offsetToUserSpace;
-  gfxContextMatrixAutoSaveRestore matSR;
-    RefPtr<DrawTarget> maskTarget = ctx.GetDrawTarget();
+  RefPtr<DrawTarget> maskTarget = ctx.GetDrawTarget();
 
   if (maskUsage.shouldGenerateMaskLayer &&
       maskUsage.shouldGenerateClipMaskLayer) {
     // We will paint both mask of positioned mask and clip-path into
     // maskTarget.
     //
     // Create one extra draw target for drawing positioned mask, so that we do
     // not have to copy the content of maskTarget before painting
     // clip-path into it.
     maskTarget = maskTarget->CreateSimilarDrawTarget(maskTarget->GetSize(),
                                                      SurfaceFormat::A8);
   }
 
+  gfxContextMatrixAutoSaveRestore matSR;
+  nsPoint offsetToBoundingBox;
+  nsPoint offsetToUserSpace;
+
+  // Paint clip-path-basic-shape onto ctx
+  gfxContextAutoSaveRestore basicShapeSR;
   if (maskUsage.shouldApplyBasicShape) {
     matSR.SetContext(&ctx);
 
     SetupContextMatrix(firstFrame, aParams, offsetToBoundingBox,
                        offsetToUserSpace);
 
+    basicShapeSR.SetContext(&ctx);
     nsCSSClipPathInstance::ApplyBasicShapeClip(ctx, frame);
     if (!maskUsage.shouldGenerateMaskLayer) {
       // Only have basic-shape clip-path effect. Fill clipped region by
       // opaque white.
-      ctx.SetColor(Color(0.0, 0.0, 0.0, 1.0));
+      ctx.SetColor(Color(1.0, 1.0, 1.0, 1.0));
       ctx.Fill();
-      ctx.PopClip();
 
       return result;
     }
   }
 
   // Paint mask onto ctx.
   if (maskUsage.shouldGenerateMaskLayer) {
     matSR.Restore();
     matSR.SetContext(&ctx);
 
     SetupContextMatrix(frame, aParams, offsetToBoundingBox,
                        offsetToUserSpace);
     nsTArray<nsSVGMaskFrame *> maskFrames = effectProperties.GetMaskFrames();
-    // XXX Bug 1323912.
-    MOZ_ASSERT(maskUsage.opacity == 1.0,
-               "nsSVGIntegrationUtils::PaintMask can not handle opacity now.");
+
     result = PaintMaskSurface(aParams, maskTarget, 1.0,
                               firstFrame->StyleContext(), maskFrames,
                               ctx.CurrentMatrix(), offsetToUserSpace);
     if (result != DrawResult::SUCCESS) {
-      if (maskUsage.shouldApplyBasicShape) {
-        ctx.PopClip();
-      }
-
       return result;
     }
   }
 
-  if (maskUsage.shouldApplyBasicShape) {
-    ctx.PopClip();
-    return result;
-  }
-
   // Paint clip-path onto ctx.
   if (maskUsage.shouldGenerateClipMaskLayer || maskUsage.shouldApplyClipPath) {
     matSR.Restore();
     matSR.SetContext(&ctx);
 
     SetupContextMatrix(firstFrame, aParams, offsetToBoundingBox,
                        offsetToUserSpace);
     Matrix clipMaskTransform;