Bug 1276834 - Part 1. Change return type of GenerateMaskSurface. draft
authorcku <cku@mozilla.com>
Thu, 02 Jun 2016 17:04:26 +0800
changeset 383252 1c79b8e51098831201a26cf33e87990337cee6bf
parent 383251 337b35e2a150481526a331dae75831dd31113468
child 383253 17a4c061ded551156fd36835c84acacef8f396e4
push id21967
push usercku@mozilla.com
push dateFri, 01 Jul 2016 21:02:32 +0000
bugs1276834
milestone50.0a1
Bug 1276834 - Part 1. Change return type of GenerateMaskSurface. MozReview-Commit-ID: Cc23ARLp7pi
layout/svg/nsSVGIntegrationUtils.cpp
--- a/layout/svg/nsSVGIntegrationUtils.cpp
+++ b/layout/svg/nsSVGIntegrationUtils.cpp
@@ -470,61 +470,60 @@ ComputeMaskGeometry(const nsSVGIntegrati
   ctx.Restore();
 
   IntRect result;
   ToRect(clippedFrameSurfaceRect).ToIntRect(&result);
   return mozilla::gfx::Factory::CheckSurfaceSize(result.Size()) ? result
                                                                 : IntRect();
 }
 
-static void
+static already_AddRefed<SourceSurface>
 GenerateMaskSurface(const nsSVGIntegrationUtils::PaintFramesParams& aParams,
                     float aOpacity, nsStyleContext* aSC,
                     const nsTArray<nsSVGMaskFrame *>& aMaskFrames,
                     const nsPoint& aOffsetToUserSpace,
-                    Matrix& aOutMaskTransform,
-                    RefPtr<SourceSurface>& aOutMaskSurface)
+                    Matrix& aOutMaskTransform)
 {
   const nsStyleSVGReset *svgReset = aSC->StyleSVGReset();
   MOZ_ASSERT(aMaskFrames.Length() > 0);
 
   gfxMatrix cssPxToDevPxMatrix =
     nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(aParams.frame);
 
   gfxContext& ctx = aParams.ctx;
 
   // There is only one SVG mask.
   if (((aMaskFrames.Length() == 1) && aMaskFrames[0])) {
-    aOutMaskSurface =
+    RefPtr<SourceSurface> maskSurface =
       aMaskFrames[0]->GetMaskForMaskedFrame(&ctx, aParams.frame,
                                             cssPxToDevPxMatrix, aOpacity,
                                             &aOutMaskTransform,
                                             svgReset->mMask.mLayers[0].mMaskMode);
-    return;
+    return maskSurface.forget();
   }
 
   IntRect maskSurfaceRect = ComputeMaskGeometry(aParams, svgReset,
                                                 aOffsetToUserSpace,
                                                 aMaskFrames);
   if (maskSurfaceRect.IsEmpty()) {
-    return;
+    return nullptr;
   }
 
   // Mask composition result on CoreGraphic::A8 surface is not correct
   // when mask-mode is not add(source over). Switch to skia when CG backend
   // detected.
   RefPtr<DrawTarget> maskDT =
     (ctx.GetDrawTarget()->GetBackendType() == BackendType::COREGRAPHICS ||
      ctx.GetDrawTarget()->GetBackendType() == BackendType::DIRECT2D1_1)
     ? Factory::CreateDrawTarget(BackendType::SKIA, maskSurfaceRect.Size(),
                                 SurfaceFormat::A8)
     : ctx.GetDrawTarget()->CreateSimilarDrawTarget(maskSurfaceRect.Size(),
                                                    SurfaceFormat::A8);
   if (!maskDT || !maskDT->IsValid()) {
-    return;
+    return nullptr;
   }
 
   RefPtr<gfxContext> maskContext = gfxContext::CreateOrNull(maskDT);
   MOZ_ASSERT(maskContext);
 
   nsPresContext* presContext = aParams.frame->PresContext();
   gfxPoint devPixelOffsetToUserSpace =
     nsLayoutUtils::PointToGfxPoint(aOffsetToUserSpace,
@@ -579,20 +578,21 @@ GenerateMaskSurface(const nsSVGIntegrati
       // FIXME We should use the return value, see bug 1258510.
       Unused << nsCSSRendering::PaintBackgroundWithSC(params, aSC,
                                                       *aParams.frame->StyleBorder());
     }
   }
 
   aOutMaskTransform = ToMatrix(maskSurfaceMatrix);
   if (!aOutMaskTransform.Invert()) {
-    return;
+    return nullptr;
   }
 
-  aOutMaskSurface = maskDT->Snapshot();
+  RefPtr<SourceSurface> maskSurface = maskDT->Snapshot();
+  return maskSurface.forget();
 }
 
 void
 nsSVGIntegrationUtils::PaintFramesWithEffects(const PaintFramesParams& aParams)
 {
 #ifdef DEBUG
   NS_ASSERTION(!(aParams.frame->GetStateBits() & NS_FRAME_SVG_LAYOUT) ||
                (NS_SVGDisplayListPaintingEnabled() &&
@@ -722,25 +722,25 @@ nsSVGIntegrationUtils::PaintFramesWithEf
       frame->GetVisualOverflowRectRelativeToSelf() + toUserSpace;
     context.Clip(NSRectToSnappedRect(clipRect,
                                   frame->PresContext()->AppUnitsPerDevPixel(),
                                   *drawTarget));
     Matrix maskTransform;
     RefPtr<SourceSurface> maskSurface;
 
     if (shouldGenerateMaskLayer) {
-      GenerateMaskSurface(aParams, opacity, firstFrame->StyleContext(),
-                          maskFrames, offsetToUserSpace,
-                          maskTransform, maskSurface);
-    }
-
-    if (shouldGenerateMaskLayer && !maskSurface) {
-      // Entire surface is clipped out.
-      context.Restore();
-      return;
+      maskSurface = GenerateMaskSurface(aParams, opacity,
+                                        firstFrame->StyleContext(),
+                                        maskFrames, offsetToUserSpace,
+                                        maskTransform);
+      if (!maskSurface) {
+        // Entire surface is clipped out.
+        context.Restore();
+        return;
+      }
     }
 
     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);