Bug 1234485 - Part 3. Implement nsSVGIntegrationUtils::PaintMask. r=mstange
authorcku <cku@mozilla.com>
Wed, 19 Oct 2016 17:31:36 +0800
changeset 351725 b110f0b3ff815d9b3fee1928b2f87ff129a074f8
parent 351724 d8d3d4789ab8e3f8d565843581f2be8a46241df9
child 351726 42ed9b2fcf5b81ec50587ef10b0b10a5426afc9e
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1234485
milestone52.0a1
Bug 1234485 - Part 3. Implement nsSVGIntegrationUtils::PaintMask. r=mstange Unlike nsSVGIntegrationUtils::PaintMaskAndClipPath, which paints masked content onto aParam.ctx, nsSVGIntegrationUtils::PaintMask paints only mask, no content, onto aParams.ctx. MozReview-Commit-ID: BaRbtHpoHzj
layout/svg/nsSVGIntegrationUtils.cpp
layout/svg/nsSVGIntegrationUtils.h
--- a/layout/svg/nsSVGIntegrationUtils.cpp
+++ b/layout/svg/nsSVGIntegrationUtils.cpp
@@ -745,16 +745,70 @@ nsSVGIntegrationUtils::IsMaskResourceRea
     }
   }
 
   // Either all mask resources are ready, or no mask resource is needed.
   return true;
 }
 
 DrawResult
+nsSVGIntegrationUtils::PaintMask(const PaintFramesParams& aParams)
+{
+  MaskUsage maskUsage;
+  DetermineMaskUsage(aParams.frame, aParams.handleOpacity, maskUsage);
+  MOZ_ASSERT(maskUsage.shouldGenerateMaskLayer);
+
+  nsIFrame* frame = aParams.frame;
+  DrawResult result = DrawResult::SUCCESS;
+  if (!ValidateSVGFrame(frame)) {
+    return result;
+  }
+
+  if (maskUsage.opacity == 0.0f) {
+    return DrawResult::SUCCESS;
+  }
+
+  gfxContext& ctx = aParams.ctx;
+
+  Matrix maskTransform;
+  RefPtr<SourceSurface> maskSurface;
+
+  gfxContextMatrixAutoSaveRestore matSR(&ctx);
+
+  nsIFrame* firstFrame =
+    nsLayoutUtils::FirstContinuationOrIBSplitSibling(frame);
+  nsSVGEffects::EffectProperties effectProperties =
+    nsSVGEffects::GetEffectProperties(firstFrame);
+  nsTArray<nsSVGMaskFrame *> maskFrames = effectProperties.GetMaskFrames();
+  bool opacityApplied = false;
+
+  nsPoint offsetToBoundingBox;
+  nsPoint offsetToUserSpace;
+  SetupContextMatrix(frame, aParams, offsetToBoundingBox,
+                     offsetToUserSpace, false);
+  result = GenerateMaskSurface(aParams, maskUsage.opacity,
+                               firstFrame->StyleContext(),
+                               maskFrames, offsetToUserSpace,
+                               maskTransform, maskSurface, opacityApplied);
+  if (!maskSurface) {
+    // Entire surface is clipped out.
+    return result;
+  }
+
+  ctx.Multiply(ThebesMatrix(maskTransform));
+
+  DrawTarget* target = ctx.GetDrawTarget();
+  MOZ_ASSERT(target->GetFormat() == SurfaceFormat::A8);
+  Rect drawingRect(Point(0, 0), Size(target->GetSize()));
+  target->DrawSurface(maskSurface, drawingRect, drawingRect);
+
+  return result;
+}
+
+DrawResult
 nsSVGIntegrationUtils::PaintMaskAndClipPath(const PaintFramesParams& aParams)
 {
   MOZ_ASSERT(UsingMaskOrClipPathForFrame(aParams.frame),
              "Should not use this method when no mask or clipPath effect"
              "on this frame");
 
   /* SVG defines the following rendering model:
    *
--- a/layout/svg/nsSVGIntegrationUtils.h
+++ b/layout/svg/nsSVGIntegrationUtils.h
@@ -155,16 +155,23 @@ public:
   };
 
   /**
    * Paint non-SVG frame with mask, clipPath and opacity effect.
    */
   static DrawResult
   PaintMaskAndClipPath(const PaintFramesParams& aParams);
 
+  /**
+   * Paint mask of non-SVG frame onto a given context, aParams.ctx.
+   * aParams.ctx must contain an A8 surface.
+   */
+  static DrawResult
+  PaintMask(const PaintFramesParams& aParams);
+
   struct MaskUsage {
     bool shouldGenerateMaskLayer;
     bool shouldGenerateClipMaskLayer;
     bool shouldApplyClipPath;
     bool shouldApplyBasicShape;
     float opacity;
 
     MaskUsage()