Skip to content

Commit

Permalink
Bug 1778718 - Make filters on the root work when using fallback drawi…
Browse files Browse the repository at this point in the history
…ng. r=tnikkel

This code-path will be hit with the next patch.

Depends on D151473

Differential Revision: https://phabricator.services.mozilla.com/D151474
  • Loading branch information
emilio committed Jul 12, 2022
1 parent c4ef579 commit bc6e066
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 20 deletions.
18 changes: 9 additions & 9 deletions layout/painting/nsDisplayList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7935,9 +7935,8 @@ bool nsDisplayMasksAndClipPaths::PaintMask(nsDisplayListBuilder* aBuilder,

imgDrawingParams imgParams(aBuilder->GetImageDecodeFlags());
nsRect borderArea = nsRect(ToReferenceFrame(), mFrame->GetSize());
SVGIntegrationUtils::PaintFramesParams params(*aMaskContext, mFrame, mBounds,
borderArea, aBuilder,
aHandleOpacity, imgParams);
PaintFramesParams params(*aMaskContext, mFrame, mBounds, borderArea, aBuilder,
aHandleOpacity, imgParams);
ComputeMaskGeometry(params);
bool maskIsComplete = false;
bool painted = SVGIntegrationUtils::PaintMask(params, maskIsComplete);
Expand Down Expand Up @@ -8002,9 +8001,8 @@ void nsDisplayMasksAndClipPaths::PaintWithContentsPaintCallback(

imgDrawingParams imgParams(aBuilder->GetImageDecodeFlags());
nsRect borderArea = nsRect(ToReferenceFrame(), mFrame->GetSize());
SVGIntegrationUtils::PaintFramesParams params(
*aCtx, mFrame, GetPaintRect(aBuilder, aCtx), borderArea, aBuilder, false,
imgParams);
PaintFramesParams params(*aCtx, mFrame, GetPaintRect(aBuilder, aCtx),
borderArea, aBuilder, false, imgParams);

ComputeMaskGeometry(params);

Expand Down Expand Up @@ -8391,17 +8389,19 @@ void nsDisplayFilters::ComputeInvalidationRegion(
void nsDisplayFilters::PaintWithContentsPaintCallback(
nsDisplayListBuilder* aBuilder, gfxContext* aCtx,
const std::function<void(gfxContext* aContext)>& aPaintChildren) {
MOZ_ASSERT(!mStyle, "Shouldn't get to this code path on the root");
imgDrawingParams imgParams(aBuilder->GetImageDecodeFlags());
nsRect borderArea = nsRect(ToReferenceFrame(), mFrame->GetSize());
SVGIntegrationUtils::PaintFramesParams params(
*aCtx, mFrame, mVisibleRect, borderArea, aBuilder, false, imgParams);
PaintFramesParams params(*aCtx, mFrame, mVisibleRect, borderArea, aBuilder,
false, imgParams);

gfxPoint userSpaceToFrameSpaceOffset =
SVGIntegrationUtils::GetOffsetToUserSpaceInDevPx(mFrame, params);

auto filterChain = mStyle ? mStyle->StyleEffects()->mFilters.AsSpan()
: mFrame->StyleEffects()->mFilters.AsSpan();
SVGIntegrationUtils::PaintFilter(
params,
filterChain,
[&](gfxContext& aContext, nsIFrame* aTarget, const gfxMatrix& aTransform,
const nsIntRect* aDirtyRect, imgDrawingParams& aImgParams) {
gfxContextMatrixAutoSaveRestore autoSR(&aContext);
Expand Down
9 changes: 4 additions & 5 deletions layout/svg/FilterInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ static UniquePtr<UserSpaceMetrics> UserSpaceMetricsForFrame(nsIFrame* aFrame) {
}

void FilterInstance::PaintFilteredFrame(
nsIFrame* aFilteredFrame, gfxContext* aCtx,
const SVGFilterPaintCallback& aPaintCallback, const nsRegion* aDirtyArea,
imgDrawingParams& aImgParams, float aOpacity) {
auto filterChain = aFilteredFrame->StyleEffects()->mFilters.AsSpan();
nsIFrame* aFilteredFrame, Span<const StyleFilter> aFilterChain,
gfxContext* aCtx, const SVGFilterPaintCallback& aPaintCallback,
const nsRegion* aDirtyArea, imgDrawingParams& aImgParams, float aOpacity) {
UniquePtr<UserSpaceMetrics> metrics =
UserSpaceMetricsForFrame(aFilteredFrame);

Expand All @@ -91,7 +90,7 @@ void FilterInstance::PaintFilteredFrame(
// Hardcode InputIsTainted to true because we don't want JS to be able to
// read the rendered contents of aFilteredFrame.
FilterInstance instance(aFilteredFrame, aFilteredFrame->GetContent(),
*metrics, filterChain, /* InputIsTainted */ true,
*metrics, aFilterChain, /* InputIsTainted */ true,
aPaintCallback, scaleMatrixInDevUnits, aDirtyArea,
nullptr, nullptr, nullptr);
if (instance.IsInitialized()) {
Expand Down
4 changes: 3 additions & 1 deletion layout/svg/FilterInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ class FilterInstance {
* frame space (i.e. relative to its origin, the top-left corner of its
* border box).
*/
static void PaintFilteredFrame(nsIFrame* aFilteredFrame, gfxContext* aCtx,
static void PaintFilteredFrame(nsIFrame* aFilteredFrame,
Span<const StyleFilter> aFilterChain,
gfxContext* aCtx,
const SVGFilterPaintCallback& aPaintCallback,
const nsRegion* aDirtyArea,
imgDrawingParams& aImgParams,
Expand Down
7 changes: 4 additions & 3 deletions layout/svg/SVGIntegrationUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -991,10 +991,11 @@ void SVGIntegrationUtils::PaintMaskAndClipPath(
}

void SVGIntegrationUtils::PaintFilter(const PaintFramesParams& aParams,
Span<const StyleFilter> aFilters,
const SVGFilterPaintCallback& aCallback) {
MOZ_ASSERT(!aParams.builder->IsForGenerateGlyphMask(),
"Filter effect is discarded while generating glyph mask.");
MOZ_ASSERT(aParams.frame->StyleEffects()->HasFilters(),
MOZ_ASSERT(!aFilters.IsEmpty(),
"Should not use this method when no filter effect on this frame");

nsIFrame* frame = aParams.frame;
Expand Down Expand Up @@ -1032,8 +1033,8 @@ void SVGIntegrationUtils::PaintFilter(const PaintFramesParams& aParams,
/* Paint the child and apply filters */
nsRegion dirtyRegion = aParams.dirtyRect - offsets.offsetToBoundingBox;

FilterInstance::PaintFilteredFrame(frame, &context, aCallback, &dirtyRegion,
aParams.imgParams, opacity);
FilterInstance::PaintFilteredFrame(frame, aFilters, &context, aCallback,
&dirtyRegion, aParams.imgParams, opacity);
}

bool SVGIntegrationUtils::CreateWebRenderCSSFilters(
Expand Down
1 change: 1 addition & 0 deletions layout/svg/SVGIntegrationUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ class SVGIntegrationUtils final {
* Paint non-SVG frame with filter and opacity effect.
*/
static void PaintFilter(const PaintFramesParams& aParams,
Span<const StyleFilter> aFilters,
const SVGFilterPaintCallback& aCallback);

/**
Expand Down
5 changes: 3 additions & 2 deletions layout/svg/SVGUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,8 +782,9 @@ void SVGUtils::PaintFrameWithEffects(nsIFrame* aFrame, gfxContext& aContext,
svgFrame->PaintSVG(aContext, SVGUtils::GetCSSPxToDevPxMatrix(aTarget),
aImgParams, dirtyRect);
};
FilterInstance::PaintFilteredFrame(aFrame, target, callback, dirtyRegion,
aImgParams);
FilterInstance::PaintFilteredFrame(
aFrame, aFrame->StyleEffects()->mFilters.AsSpan(), target, callback,
dirtyRegion, aImgParams);
} else {
svgFrame->PaintSVG(*target, aTransform, aImgParams, aDirtyRect);
}
Expand Down

0 comments on commit bc6e066

Please sign in to comment.