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
--- a/gfx/layers/RotatedBuffer.cpp
+++ b/gfx/layers/RotatedBuffer.cpp
@@ -200,16 +200,49 @@ bool IsClippingCheap(gfx::DrawTarget* aT
{
// Assume clipping is cheap if the draw target just has an integer
// translation, and the visible region is simple.
return !aTarget->GetTransform().HasNonIntegerTranslation() &&
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)
{
DrawIterator iter;
while (DrawTarget* destDT =
BorrowDrawTargetForQuadrantUpdate(aUpdateRegion.GetBounds(), BUFFER_BLACK, &iter)) {
bool isClippingCheap = IsClippingCheap(destDT, iter.mDrawRegion);
if (isClippingCheap) {
@@ -324,53 +357,16 @@ SourceRotatedBuffer::GetSourceSurface(Co
MOZ_ASSERT(aSource == BUFFER_WHITE);
surf = mSourceOnWhite;
}
MOZ_ASSERT(surf);
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()
{
if (mBufferProvider || (mDTBuffer && mDTBuffer->IsValid())) {
SurfaceFormat format = SurfaceFormat::B8G8R8A8;
if (mBufferProvider) {
format = mBufferProvider->GetFormat();
--- a/gfx/layers/RotatedBuffer.h
+++ b/gfx/layers/RotatedBuffer.h
@@ -101,16 +101,28 @@ public:
// It is the callers repsonsibility to ensure aTarget is flushed after calling
// this method.
void DrawBufferWithRotation(gfx::DrawTarget* aTarget, ContextSource aSource,
float aOpacity = 1.0,
gfx::CompositionOp aOperator = gfx::CompositionOp::OP_OVER,
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);
/**
* |BufferRect()| is the rect of device pixels that this
* RotatedBuffer covers. That is what DrawBufferWithRotation()
* will paint when it's called.
*/
@@ -359,28 +371,16 @@ public:
* will be used.
*/
virtual void
CreateBuffer(ContentType aType, const gfx::IntRect& aRect, uint32_t aFlags,
RefPtr<gfx::DrawTarget>* aBlackDT, RefPtr<gfx::DrawTarget>* aWhiteDT) = 0;
virtual already_AddRefed<gfx::SourceSurface> 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)
{
// Only this buffer provider can give us a buffer. If we
// already have one, something has gone wrong.
MOZ_ASSERT(!aClient || !mDTBuffer || !mDTBuffer->IsValid());
--- a/gfx/layers/client/ContentClient.cpp
+++ b/gfx/layers/client/ContentClient.cpp
@@ -114,16 +114,32 @@ ContentClient::PrintInfo(std::stringstre
// this client will not have a ContentHost on the other side.
ContentClientBasic::ContentClientBasic(gfx::BackendType aBackend)
: ContentClient(nullptr)
, RotatedContentBuffer(ContainsVisibleBounds)
, 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,
uint32_t aFlags,
RefPtr<gfx::DrawTarget>* aBlackDT,
RefPtr<gfx::DrawTarget>* aWhiteDT)
{
MOZ_ASSERT(!(aFlags & BUFFER_COMPONENT_ALPHA));
if (aFlags & BUFFER_COMPONENT_ALPHA) {
--- a/gfx/layers/client/ContentClient.h
+++ b/gfx/layers/client/ContentClient.h
@@ -144,21 +144,17 @@ public:
BorrowDrawTarget::ReturnDrawTarget(aReturned);
}
void DrawTo(PaintedLayer* aLayer,
gfx::DrawTarget* aTarget,
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<gfx::DrawTarget>* aBlackDT, RefPtr<gfx::DrawTarget>* aWhiteDT) override;
virtual TextureInfo GetTextureInfo() const override
{
MOZ_CRASH("GFX: Should not be called on non-remote ContentClient");
}