Bug 1318418 - Eliminate one extra copy in nsSVGIntegrationUtils::PaintMask when we have both mask and clip-path. r=mstange
☠☠ backed out by 067773698619 ☠ ☠
authorcku <cku@mozilla.com>
Thu, 15 Dec 2016 14:17:50 +0800
changeset 450772 03090e5ca9b989f6b3823412425b9e0f50ef6ef6
parent 450771 18a793f65dcd0607536708270c1e11fb50ec7df7
child 450773 bd570e5a9b4546a15546d09e507d0769434a4163
push id38944
push userbmo:leftysolara@gmail.com
push dateSun, 18 Dec 2016 16:01:15 +0000
reviewersmstange
bugs1318418
milestone53.0a1
Bug 1318418 - Eliminate one extra copy in nsSVGIntegrationUtils::PaintMask when we have both mask and clip-path. r=mstange MozReview-Commit-ID: LlF3ZKi356S
layout/svg/nsSVGIntegrationUtils.cpp
--- a/layout/svg/nsSVGIntegrationUtils.cpp
+++ b/layout/svg/nsSVGIntegrationUtils.cpp
@@ -770,17 +770,29 @@ nsSVGIntegrationUtils::PaintMask(const P
     nsLayoutUtils::FirstContinuationOrIBSplitSibling(frame);
   nsSVGEffects::EffectProperties effectProperties =
     nsSVGEffects::GetEffectProperties(firstFrame);
 
   DrawResult result = DrawResult::SUCCESS;
   nsPoint offsetToBoundingBox;
   nsPoint offsetToUserSpace;
   gfxContextMatrixAutoSaveRestore matSR;
-  DrawTarget* target = 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);
+  }
 
   if (maskUsage.shouldApplyBasicShape) {
     matSR.SetContext(&ctx);
 
     SetupContextMatrix(firstFrame, aParams, offsetToBoundingBox,
                        offsetToUserSpace, false);
 
     nsCSSClipPathInstance::ApplyBasicShapeClip(ctx, frame);
@@ -801,17 +813,17 @@ nsSVGIntegrationUtils::PaintMask(const P
     matSR.SetContext(&ctx);
 
     SetupContextMatrix(frame, aParams, offsetToBoundingBox,
                        offsetToUserSpace, false);
     nsTArray<nsSVGMaskFrame *> maskFrames = effectProperties.GetMaskFrames();
     // XXX Bug 1323912.
     MOZ_ASSERT(maskUsage.opacity == 1.0,
                "nsSVGIntegrationUtils::PaintMask can not handle opacity now.");
-    result = PaintMaskSurface(aParams, target, 1.0,
+    result = PaintMaskSurface(aParams, maskTarget, 1.0,
                               firstFrame->StyleContext(), maskFrames,
                               ctx.CurrentMatrix(), offsetToUserSpace);
     if (result != DrawResult::SUCCESS) {
       if (maskUsage.shouldApplyBasicShape) {
         ctx.PopClip();
       }
 
       return result;
@@ -831,17 +843,17 @@ nsSVGIntegrationUtils::PaintMask(const P
     SetupContextMatrix(firstFrame, aParams, offsetToBoundingBox,
                        offsetToUserSpace, false);
 
     Matrix clipMaskTransform;
     gfxMatrix cssPxToDevPxMatrix = GetCSSPxToDevPxMatrix(frame);
 
     nsSVGClipPathFrame *clipPathFrame = effectProperties.GetClipPathFrame();
     RefPtr<SourceSurface> maskSurface =
-      maskUsage.shouldGenerateMaskLayer ? target->Snapshot() : nullptr;
+      maskUsage.shouldGenerateMaskLayer ? maskTarget->Snapshot() : nullptr;
     result =
       clipPathFrame->PaintClipMask(ctx, frame, cssPxToDevPxMatrix,
                                    &clipMaskTransform, maskSurface,
                                    ToMatrix(ctx.CurrentMatrix()));
   }
 
   return result;
 }