From 4491f22f3b9f111e6ad19297ee7ca2fff40e6107 Mon Sep 17 00:00:00 2001 From: Markus Stange Date: Mon, 19 Aug 2019 22:39:45 +0000 Subject: [PATCH] Bug 1573343 - Add mDrawTargetBounds to clarify the position of mDrawTarget in window space. r=mattwoodrow There was an interesting "ExpandToEnclose(IntPoint(0, 0))" call in CreateRenderTargetForWindow that snuck in some surprising behavior that this change makes a bit more visible. Differential Revision: https://phabricator.services.mozilla.com/D41676 --HG-- extra : moz-landing-system : lando --- gfx/layers/basic/BasicCompositor.cpp | 22 +++++++++++++++------- gfx/layers/basic/BasicCompositor.h | 3 +++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/gfx/layers/basic/BasicCompositor.cpp b/gfx/layers/basic/BasicCompositor.cpp index 4ff1fc67eacc..6ac74c220131 100644 --- a/gfx/layers/basic/BasicCompositor.cpp +++ b/gfx/layers/basic/BasicCompositor.cpp @@ -315,12 +315,7 @@ BasicCompositor::CreateRenderTargetForWindow( MOZ_ASSERT(target != mDrawTarget); rt = new BasicCompositingRenderTarget(target, rect); } else { - IntRect windowRect = rect; - // Adjust bounds rect to account for new origin at (0, 0). - if (windowRect.Size() != mDrawTarget->GetSize()) { - windowRect.ExpandToEnclose(IntPoint(0, 0)); - } - rt = new BasicCompositingRenderTarget(mDrawTarget, windowRect); + rt = new BasicCompositingRenderTarget(mDrawTarget, mDrawTargetBounds); } rt->mDrawTarget->SetTransform(Matrix::Translation(-rt->GetOrigin())); @@ -933,6 +928,7 @@ void BasicCompositor::BeginFrame( // draw target that we composite into, then copy the results the // destination. mDrawTarget = mTarget; + mDrawTargetBounds = mTargetBounds; bufferMode = BufferMode::BUFFER_NONE; } else { // StartRemoteDrawingInRegion can mutate mInvalidRegion. @@ -946,6 +942,18 @@ void BasicCompositor::BeginFrame( mWidget->EndRemoteDrawingInRegion(mDrawTarget, mInvalidRegion); return; } + + // The DrawTarget returned by StartRemoteDrawingInRegion can cover different + // rectangles in window space. It can either cover the entire window, or it + // can cover just the invalid region. We discern between the two cases by + // comparing the DrawTarget's size with the invalild region's size. + IntSize dtSize = mDrawTarget->GetSize(); + if (bufferMode == BufferMode::BUFFER_NONE && + dtSize == mInvalidRect.Size().ToUnknownSize()) { + mDrawTargetBounds = mInvalidRect.ToUnknownRect(); + } else { + mDrawTargetBounds = IntRect(IntPoint(0, 0), dtSize); + } } if (!mDrawTarget || mInvalidRect.IsEmpty()) { @@ -1061,7 +1069,7 @@ void BasicCompositor::TryToEndRemoteDrawing(bool aForceToEnd) { // drawing. RefPtr source = mWidget->EndBackBufferDrawing(); IntPoint srcOffset = mRenderTarget->GetOrigin(); - IntPoint dstOffset = mTarget ? mTargetBounds.TopLeft() : IntPoint(); + IntPoint dstOffset = mDrawTargetBounds.TopLeft(); // The source DrawTarget is clipped to the invalidation region, so we have // to copy the individual rectangles in the region or else we'll draw diff --git a/gfx/layers/basic/BasicCompositor.h b/gfx/layers/basic/BasicCompositor.h index 29c60ad54893..40bfe5b3cf89 100644 --- a/gfx/layers/basic/BasicCompositor.h +++ b/gfx/layers/basic/BasicCompositor.h @@ -183,6 +183,9 @@ class BasicCompositor : public Compositor { // The final destination surface RefPtr mDrawTarget; + // The bounds that mDrawTarget occupies in window space. + gfx::IntRect mDrawTargetBounds; + // The current render target for drawing RefPtr mRenderTarget;