Bug 1295094 - Part 2. Implement ComputeClipExtsInDeviceSpace draft
authorcku <cku@mozilla.com>
Mon, 15 Aug 2016 23:49:21 +0800
changeset 409043 ced8b75d29621ec497472411ee86dcc05f8b8e6a
parent 409042 cd9da827877f92ce36b2d92eadfa5356b09b63fe
child 409044 edf563398a5a719dc52481850ec1d4ec454b9d57
push id28367
push userbmo:cku@mozilla.com
push dateFri, 02 Sep 2016 03:40:41 +0000
bugs1295094
milestone51.0a1
Bug 1295094 - Part 2. Implement ComputeClipExtsInDeviceSpace MozReview-Commit-ID: 8BFy0y83MeG
layout/svg/nsSVGIntegrationUtils.cpp
--- a/layout/svg/nsSVGIntegrationUtils.cpp
+++ b/layout/svg/nsSVGIntegrationUtils.cpp
@@ -406,16 +406,32 @@ public:
 
 private:
   nsDisplayListBuilder* mBuilder;
   LayerManager* mLayerManager;
   nsPoint mOffset;
 };
 
 static IntRect
+ComputeClipExtsInDeviceSpace(gfxContext& aCtx)
+{
+  gfxContextMatrixAutoSaveRestore matRestore(&aCtx);
+
+  // Get the clip extents in device space.
+  aCtx.SetMatrix(gfxMatrix());
+  gfxRect clippedFrameSurfaceRect = aCtx.GetClipExtents();
+  clippedFrameSurfaceRect.RoundOut();
+
+  IntRect result;
+  ToRect(clippedFrameSurfaceRect).ToIntRect(&result);
+  return mozilla::gfx::Factory::CheckSurfaceSize(result.Size()) ? result
+                                                                : IntRect();
+}
+
+static IntRect
 ComputeMaskGeometry(const nsSVGIntegrationUtils::PaintFramesParams& aParams,
                     const nsStyleSVGReset *svgReset,
                     const nsPoint& aOffsetToUserSpace,
                     const nsTArray<nsSVGMaskFrame *>& aMaskFrames)
 {
   gfxContext& ctx = aParams.ctx;
   nsIFrame* frame = aParams.frame;
 
@@ -458,27 +474,20 @@ ComputeMaskGeometry(const nsSVGIntegrati
   // maskInUserSpace might be empty if all mask references are not resolvable
   // or the size of them are empty. We still need to create a transparent mask
   // before bug 1276834 fixed, so don't clip ctx by an empty rectangle for for
   // now.
   if (!maskInUserSpace.IsEmpty()) {
     ctx.Clip(maskInUserSpace);
   }
 
-  // Get the clip extents in device space.
-  ctx.SetMatrix(gfxMatrix());
-  gfxRect clippedFrameSurfaceRect = ctx.GetClipExtents();
-  clippedFrameSurfaceRect.RoundOut();
-
+  IntRect result = ComputeClipExtsInDeviceSpace(ctx);
   ctx.Restore();
 
-  IntRect result;
-  ToRect(clippedFrameSurfaceRect).ToIntRect(&result);
-  return mozilla::gfx::Factory::CheckSurfaceSize(result.Size()) ? result
-                                                                : IntRect();
+  return result;
 }
 
 static DrawResult
 GenerateMaskSurface(const nsSVGIntegrationUtils::PaintFramesParams& aParams,
                     float aOpacity, nsStyleContext* aSC,
                     const nsTArray<nsSVGMaskFrame *>& aMaskFrames,
                     const nsPoint& aOffsetToUserSpace,
                     Matrix& aOutMaskTransform,
@@ -726,25 +735,17 @@ nsSVGIntegrationUtils::PaintFramesWithEf
 
   // These are used if we require a temporary surface for a custom blend mode.
   RefPtr<gfxContext> target = &aParams.ctx;
   IntPoint targetOffset;
 
   if (frame->StyleEffects()->mMixBlendMode != NS_STYLE_BLEND_NORMAL) {
     // Create a temporary context to draw to so we can blend it back with
     // another operator.
-    gfxRect clipRect;
-    {
-      gfxContextMatrixAutoSaveRestore matRestore(&context);
-
-      context.SetMatrix(gfxMatrix());
-      clipRect = context.GetClipExtents();
-    }
-
-    IntRect drawRect = RoundedOut(ToRect(clipRect));
+    IntRect drawRect = ComputeClipExtsInDeviceSpace(context);
 
     RefPtr<DrawTarget> targetDT = context.GetDrawTarget()->CreateSimilarDrawTarget(drawRect.Size(), SurfaceFormat::B8G8R8A8);
     if (!targetDT || !targetDT->IsValid()) {
       return DrawResult::TEMPORARY_ERROR;
     }
     target = gfxContext::CreateOrNull(targetDT);
     MOZ_ASSERT(target); // already checked the draw target above
     target->SetMatrix(context.CurrentMatrix() * gfxMatrix::Translation(-drawRect.TopLeft()));