Bug 1276834 - Part 1. Change return type of GenerateMaskSurface.
MozReview-Commit-ID: Cc23ARLp7pi
--- 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);