Bug 1276834 - Part 2. Draw nothing when any mask-image refer to an unresolvable URL
MozReview-Commit-ID: 7gdKz0L1wmd
--- a/layout/svg/nsSVGIntegrationUtils.cpp
+++ b/layout/svg/nsSVGIntegrationUtils.cpp
@@ -449,23 +449,17 @@ ComputeMaskGeometry(const nsSVGIntegrati
ctx.Save();
// Clip ctx by both frame's visual overflow rect and mask union.
gfxRect frameVisualOverflowRect =
nsLayoutUtils::RectToGfxRect(frame->GetVisualOverflowRectRelativeToSelf(),
appUnitsPerDevPixel);
ctx.Clip(frameVisualOverflowRect);
- // 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);
- }
+ ctx.Clip(maskInUserSpace);
// Get the clip extents in device space.
ctx.SetMatrix(gfxMatrix());
gfxRect clippedFrameSurfaceRect = ctx.GetClipExtents();
clippedFrameSurfaceRect.RoundOut();
ctx.Restore();
@@ -585,16 +579,53 @@ GenerateMaskSurface(const nsSVGIntegrati
if (!aOutMaskTransform.Invert()) {
return nullptr;
}
RefPtr<SourceSurface> maskSurface = maskDT->Snapshot();
return maskSurface.forget();
}
+static bool
+ShouldCreateMaskSurface(const nsIFrame* aFrame,
+ const nsStyleSVGReset* aSVGReset,
+ const nsTArray<nsSVGMaskFrame *>& maskFrames,
+ bool& aHasUnresolvableMaskLayer)
+{
+ aHasUnresolvableMaskLayer = false;
+
+ // For a HTML doc:
+ // According to css-masking spec, always create a mask surface when we
+ // have any item in maskFrame even if all of those items are
+ // non-resolvable <mask-sources> or <images>, we still need to create a
+ // transparent black mask layer under this condition.
+ // For a SVG doc:
+ // SVG 1.1 say that if we fail to resolve a mask, we should draw the
+ // object unmasked.
+ nsIDocument* currentDoc = aFrame->PresContext()->Document();
+ bool shouldCreateMaskSurface = currentDoc->IsSVGDocument()
+ ? maskFrames.Length() == 1 && maskFrames[0]
+ : maskFrames.Length() > 0;
+
+ if (!shouldCreateMaskSurface) {
+ return false;
+ }
+
+ for (size_t i = 0; i < maskFrames.Length() ; i++) {
+ nsSVGMaskFrame *maskFrame = maskFrames[i];
+
+ if (!maskFrame && !aSVGReset->mMask.mLayers[i].mImage.IsComplete()) {
+ aHasUnresolvableMaskLayer = true;
+ break;
+ }
+ }
+
+ return true;
+}
+
void
nsSVGIntegrationUtils::PaintFramesWithEffects(const PaintFramesParams& aParams)
{
#ifdef DEBUG
NS_ASSERTION(!(aParams.frame->GetStateBits() & NS_FRAME_SVG_LAYOUT) ||
(NS_SVGDisplayListPaintingEnabled() &&
!(aParams.frame->GetStateBits() & NS_FRAME_IS_NONDISPLAY)),
"Should not use nsSVGIntegrationUtils on this SVG frame");
@@ -687,57 +718,51 @@ nsSVGIntegrationUtils::PaintFramesWithEf
nsLayoutUtils::PointToGfxPoint(offsetToUserSpace,
frame->PresContext()->AppUnitsPerDevPixel());
context.SetMatrix(context.CurrentMatrix().Translate(devPixelOffsetToUserSpace));
gfxMatrix cssPxToDevPxMatrix = GetCSSPxToDevPxMatrix(frame);
const nsStyleSVGReset *svgReset = firstFrame->StyleSVGReset();
nsTArray<nsSVGMaskFrame *> maskFrames = effectProperties.GetMaskFrames();
- // For a HTML doc:
- // According to css-masking spec, always create a mask surface when we
- // have any item in maskFrame even if all of those items are
- // non-resolvable <mask-sources> or <images>, we still need to create a
- // transparent black mask layer under this condition.
- // For a SVG doc:
- // SVG 1.1 say that if we fail to resolve a mask, we should draw the
- // object unmasked.
- nsIDocument* currentDoc = frame->PresContext()->Document();
- bool shouldGenerateMaskLayer = currentDoc->IsSVGDocument()
- ? maskFrames.Length() == 1 && maskFrames[0]
- : maskFrames.Length() > 0;
+ bool hasUnresolvableMaskLayer = false;
+ bool shouldCreateMaskSurface =
+ ShouldCreateMaskSurface(frame, svgReset, maskFrames,
+ hasUnresolvableMaskLayer);
// These are used if we require a temporary surface for a custom blend mode.
RefPtr<gfxContext> target = &aParams.ctx;
IntPoint targetOffset;
bool complexEffects = false;
/* Check if we need to do additional operations on this child's
* rendering, which necessitates rendering into another surface. */
if (opacity != 1.0f || (clipPathFrame && !isTrivialClip)
|| frame->StyleEffects()->mMixBlendMode != NS_STYLE_BLEND_NORMAL
- || shouldGenerateMaskLayer) {
+ || shouldCreateMaskSurface) {
complexEffects = true;
context.Save();
nsRect clipRect =
frame->GetVisualOverflowRectRelativeToSelf() + toUserSpace;
context.Clip(NSRectToSnappedRect(clipRect,
frame->PresContext()->AppUnitsPerDevPixel(),
*drawTarget));
Matrix maskTransform;
RefPtr<SourceSurface> maskSurface;
- if (shouldGenerateMaskLayer) {
+ if (shouldCreateMaskSurface) {
maskSurface = GenerateMaskSurface(aParams, opacity,
firstFrame->StyleContext(),
maskFrames, offsetToUserSpace,
maskTransform);
- if (!maskSurface) {
- // Entire surface is clipped out.
+ if (!maskSurface || hasUnresolvableMaskLayer) {
+ // Entire surface is clipped out or we have non-resolvable masks.
+ // Check hasUnresolvableMaskLayer after calling GenerateMaskSurface
+ // to ensure we get invalidated for loads of the mask.
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.
@@ -768,17 +793,17 @@ nsSVGIntegrationUtils::PaintFramesWithEf
&clippedMaskTransform, maskSurface, maskTransform);
if (clipMaskSurface) {
maskSurface = clipMaskSurface;
maskTransform = clippedMaskTransform;
}
}
- if (opacity != 1.0f || shouldGenerateMaskLayer ||
+ if (opacity != 1.0f || shouldCreateMaskSurface ||
(clipPathFrame && !isTrivialClip)) {
target->PushGroupForBlendBack(gfxContentType::COLOR_ALPHA, opacity, maskSurface, maskTransform);
}
}
/* If this frame has only a trivial clipPath, set up cairo's clipping now so
* we can just do normal painting and get it clipped appropriately.
*/
@@ -814,17 +839,17 @@ nsSVGIntegrationUtils::PaintFramesWithEf
context.Restore();
}
/* No more effects, we're done. */
if (!complexEffects) {
return;
}
- if (opacity != 1.0f || shouldGenerateMaskLayer ||
+ if (opacity != 1.0f || shouldCreateMaskSurface ||
(clipPathFrame && !isTrivialClip)) {
target->PopGroupAndBlend();
}
if (frame->StyleEffects()->mMixBlendMode != NS_STYLE_BLEND_NORMAL) {
RefPtr<DrawTarget> targetDT = target->GetDrawTarget();
target = nullptr;
RefPtr<SourceSurface> targetSurf = targetDT->Snapshot();