From df71bb31056428a47d5e5d979fbb52f0cd56950d Mon Sep 17 00:00:00 2001 From: Matt Woodrow Date: Tue, 6 Nov 2018 00:39:59 +0000 Subject: [PATCH] Bug 1456555 - Fix bugs in DrawTargetOffset. r=mstange MozReview-Commit-ID: I4XFoTp1szZ Depends on D10033 Differential Revision: https://phabricator.services.mozilla.com/D10036 --HG-- extra : moz-landing-system : lando --- gfx/2d/DrawTargetOffset.cpp | 28 +++++++++++++++++++--------- gfx/2d/DrawTargetOffset.h | 2 +- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/gfx/2d/DrawTargetOffset.cpp b/gfx/2d/DrawTargetOffset.cpp index bffc3ec18d71..f901fe68fdb8 100644 --- a/gfx/2d/DrawTargetOffset.cpp +++ b/gfx/2d/DrawTargetOffset.cpp @@ -83,7 +83,9 @@ DrawTargetOffset::DrawFilter(FilterNode* aNode, const Rect& aSourceRect, const P { auto clone = mTransform; bool invertible = clone.Invert(); - auto src = aSourceRect; + // aSourceRect is in filter space. The filter outputs from aSourceRect need + // to be drawn at aDestPoint in user space. + Rect userSpaceSource = Rect(aDestPoint, aSourceRect.Size()); if (invertible) { // Try to reduce the source rect so that it's not much bigger // than the draw target. The result is not minimal. Examples @@ -92,11 +94,16 @@ DrawTargetOffset::DrawFilter(FilterNode* aNode, const Rect& aSourceRect, const P mOrigin.y, mDrawTarget->GetSize().width, mDrawTarget->GetSize().height); - auto dtBounds = clone.TransformBounds(destRect); - src = aSourceRect.Intersect(dtBounds); + Rect userSpaceBounds = clone.TransformBounds(destRect); + userSpaceSource = userSpaceSource.Intersect(userSpaceBounds); } - auto shift = src.TopLeft() - aSourceRect.TopLeft(); - mDrawTarget->DrawFilter(aNode, src, aDestPoint + shift, aOptions); + + // Compute how much we moved the top-left of the source rect by, and use that + // to compute the new dest point, and move our intersected source rect back + // into the (new) filter space. + Point shift = userSpaceSource.TopLeft() - aDestPoint; + Rect filterSpaceSource = Rect(aSourceRect.TopLeft() + shift, userSpaceSource.Size()); + mDrawTarget->DrawFilter(aNode, filterSpaceSource, aDestPoint + shift, aOptions); } void @@ -184,9 +191,10 @@ DrawTargetOffset::PushLayer(bool aOpaque, Float aOpacity, SourceSurface* aMask, const Matrix& aMaskTransform, const IntRect& aBounds, bool aCopyBackground) { - IntRect bounds = aBounds; - bounds.MoveBy(mOrigin); + IntRect bounds = aBounds - mOrigin; + mDrawTarget->PushLayer(aOpaque, aOpacity, aMask, aMaskTransform, bounds, aCopyBackground); + SetPermitSubpixelAA(mDrawTarget->GetPermitSubpixelAA()); } void @@ -197,15 +205,17 @@ DrawTargetOffset::PushLayerWithBlend(bool aOpaque, Float aOpacity, bool aCopyBackground, CompositionOp aOp) { - IntRect bounds = aBounds; - bounds.MoveBy(mOrigin); + IntRect bounds = aBounds - mOrigin; + mDrawTarget->PushLayerWithBlend(aOpaque, aOpacity, aMask, aMaskTransform, bounds, aCopyBackground, aOp); + SetPermitSubpixelAA(mDrawTarget->GetPermitSubpixelAA()); } void DrawTargetOffset::PopLayer() { mDrawTarget->PopLayer(); + SetPermitSubpixelAA(mDrawTarget->GetPermitSubpixelAA()); } } // namespace gfx diff --git a/gfx/2d/DrawTargetOffset.h b/gfx/2d/DrawTargetOffset.h index 647018b0f04b..bab7a09a93e8 100644 --- a/gfx/2d/DrawTargetOffset.h +++ b/gfx/2d/DrawTargetOffset.h @@ -38,7 +38,7 @@ public: return mDrawTarget->GetSize(); } virtual IntRect GetRect() const override { - return mDrawTarget->GetRect(); + return IntRect(mOrigin, GetSize()); } virtual void Flush() override;