From 3e243339a6f3a388a275f9a978fece9b75159e4c Mon Sep 17 00:00:00 2001 From: Ryan Hunt Date: Wed, 11 Oct 2017 15:31:20 -0400 Subject: [PATCH] Move DrawTo to RotatedBuffer. (bug 1409871 part 3, r=nical) Similar to the previous patch, more functionality can be moved to rotated buffer and out of rotated content client. MozReview-Commit-ID: FNqfonyBBq9 --HG-- extra : rebase_source : cfc9c10d31baa48163107d0cf36c28a8ffda4ebb --- gfx/layers/RotatedBuffer.cpp | 70 ++++++++++++++--------------- gfx/layers/RotatedBuffer.h | 24 +++++----- gfx/layers/client/ContentClient.cpp | 16 +++++++ gfx/layers/client/ContentClient.h | 6 +-- 4 files changed, 62 insertions(+), 54 deletions(-) diff --git a/gfx/layers/RotatedBuffer.cpp b/gfx/layers/RotatedBuffer.cpp index 0fd87f04c799..32542a7d747b 100644 --- a/gfx/layers/RotatedBuffer.cpp +++ b/gfx/layers/RotatedBuffer.cpp @@ -204,6 +204,39 @@ bool IsClippingCheap(gfx::DrawTarget* aTarget, const nsIntRegion& aRegion) aRegion.GetNumRects() <= 1; } +void +RotatedBuffer::DrawTo(PaintedLayer* aLayer, + DrawTarget* aTarget, + float aOpacity, + CompositionOp aOp, + SourceSurface* aMask, + const Matrix* aMaskTransform) +{ + bool clipped = false; + + // If the entire buffer is valid, we can just draw the whole thing, + // no need to clip. But we'll still clip if clipping is cheap --- + // that might let us copy a smaller region of the buffer. + // Also clip to the visible region if we're told to. + if (!aLayer->GetValidRegion().Contains(BufferRect()) || + (ToData(aLayer)->GetClipToVisibleRegion() && + !aLayer->GetVisibleRegion().ToUnknownRegion().Contains(BufferRect())) || + IsClippingCheap(aTarget, aLayer->GetLocalVisibleRegion().ToUnknownRegion())) { + // We don't want to draw invalid stuff, so we need to clip. Might as + // well clip to the smallest area possible --- the visible region. + // Bug 599189 if there is a non-integer-translation transform in aTarget, + // we might sample pixels outside GetLocalVisibleRegion(), which is wrong + // and may cause gray lines. + gfxUtils::ClipToRegion(aTarget, aLayer->GetLocalVisibleRegion().ToUnknownRegion()); + clipped = true; + } + + DrawBufferWithRotation(aTarget, BUFFER_BLACK, aOpacity, aOp, aMask, aMaskTransform); + if (clipped) { + aTarget->PopClip(); + } +} + void RotatedBuffer::UpdateDestinationFrom(const RotatedBuffer& aSource, const nsIntRegion& aUpdateRegion) @@ -329,43 +362,6 @@ SourceRotatedBuffer::GetSourceSurface(ContextSource aSource) const return surf.forget(); } -void -RotatedContentBuffer::DrawTo(PaintedLayer* aLayer, - DrawTarget* aTarget, - float aOpacity, - CompositionOp aOp, - SourceSurface* aMask, - const Matrix* aMaskTransform) -{ - if (!EnsureBuffer()) { - return; - } - - bool clipped = false; - - // If the entire buffer is valid, we can just draw the whole thing, - // no need to clip. But we'll still clip if clipping is cheap --- - // that might let us copy a smaller region of the buffer. - // Also clip to the visible region if we're told to. - if (!aLayer->GetValidRegion().Contains(BufferRect()) || - (ToData(aLayer)->GetClipToVisibleRegion() && - !aLayer->GetVisibleRegion().ToUnknownRegion().Contains(BufferRect())) || - IsClippingCheap(aTarget, aLayer->GetLocalVisibleRegion().ToUnknownRegion())) { - // We don't want to draw invalid stuff, so we need to clip. Might as - // well clip to the smallest area possible --- the visible region. - // Bug 599189 if there is a non-integer-translation transform in aTarget, - // we might sample pixels outside GetLocalVisibleRegion(), which is wrong - // and may cause gray lines. - gfxUtils::ClipToRegion(aTarget, aLayer->GetLocalVisibleRegion().ToUnknownRegion()); - clipped = true; - } - - DrawBufferWithRotation(aTarget, BUFFER_BLACK, aOpacity, aOp, aMask, aMaskTransform); - if (clipped) { - aTarget->PopClip(); - } -} - gfxContentType RotatedContentBuffer::BufferContentType() { diff --git a/gfx/layers/RotatedBuffer.h b/gfx/layers/RotatedBuffer.h index 5c86c2132cd7..e9a5f22da9b8 100644 --- a/gfx/layers/RotatedBuffer.h +++ b/gfx/layers/RotatedBuffer.h @@ -106,6 +106,18 @@ public: gfx::SourceSurface* aMask = nullptr, const gfx::Matrix* aMaskTransform = nullptr) const; + /** + * Complete the drawing operation. The region to draw must have been + * drawn before this is called. The contents of the buffer are drawn + * to aTarget. + */ + void DrawTo(PaintedLayer* aLayer, + gfx::DrawTarget* aTarget, + float aOpacity, + gfx::CompositionOp aOp, + gfx::SourceSurface* aMask, + const gfx::Matrix* aMaskTransform); + void UpdateDestinationFrom(const RotatedBuffer& aSource, const nsIntRegion& aUpdateRegion); @@ -364,18 +376,6 @@ public: virtual already_AddRefed GetSourceSurface(ContextSource aSource) const; - /** - * Complete the drawing operation. The region to draw must have been - * drawn before this is called. The contents of the buffer are drawn - * to aTarget. - */ - void DrawTo(PaintedLayer* aLayer, - gfx::DrawTarget* aTarget, - float aOpacity, - gfx::CompositionOp aOp, - gfx::SourceSurface* aMask, - const gfx::Matrix* aMaskTransform); - protected: // new texture client versions void SetBufferProvider(TextureClient* aClient) diff --git a/gfx/layers/client/ContentClient.cpp b/gfx/layers/client/ContentClient.cpp index 5462a1edaf72..8fef6e3bb0cc 100644 --- a/gfx/layers/client/ContentClient.cpp +++ b/gfx/layers/client/ContentClient.cpp @@ -118,6 +118,22 @@ ContentClientBasic::ContentClientBasic(gfx::BackendType aBackend) , mBackend(aBackend) {} +void +ContentClientBasic::DrawTo(PaintedLayer* aLayer, + gfx::DrawTarget* aTarget, + float aOpacity, + gfx::CompositionOp aOp, + gfx::SourceSurface* aMask, + const gfx::Matrix* aMaskTransform) +{ + if (!EnsureBuffer()) { + return; + } + + RotatedContentBuffer::DrawTo(aLayer, aTarget, aOpacity, aOp, + aMask, aMaskTransform); +} + void ContentClientBasic::CreateBuffer(ContentType aType, const IntRect& aRect, diff --git a/gfx/layers/client/ContentClient.h b/gfx/layers/client/ContentClient.h index b40cad590f7b..a40e63aef0b7 100644 --- a/gfx/layers/client/ContentClient.h +++ b/gfx/layers/client/ContentClient.h @@ -149,11 +149,7 @@ public: float aOpacity, gfx::CompositionOp aOp, gfx::SourceSurface* aMask, - const gfx::Matrix* aMaskTransform) - { - RotatedContentBuffer::DrawTo(aLayer, aTarget, aOpacity, aOp, - aMask, aMaskTransform); - } + const gfx::Matrix* aMaskTransform); virtual void CreateBuffer(ContentType aType, const gfx::IntRect& aRect, uint32_t aFlags, RefPtr* aBlackDT, RefPtr* aWhiteDT) override;