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

--HG--
extra : rebase_source : 4a258b7332ba7a7edbffdc13c7f4b065fbe5eaa4
This commit is contained in:
cku 2016-10-19 17:31:36 +08:00
parent 999ca66251
commit 4d9495cf77
2 changed files with 61 additions and 0 deletions

View File

@ -749,6 +749,60 @@ nsSVGIntegrationUtils::IsMaskResourceReady(nsIFrame* aFrame)
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)
{

View File

@ -160,6 +160,13 @@ public:
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;