Remove BeginPaintBuffer (
bug 1409871 part 18, r=nical)
Now that BeginPaintBuffer and BeginPaint are both implemented by content client,
I think it makes sense to just merge them into one method. This simplifies the
interface clients have to use.
MozReview-Commit-ID: 8bjH6WcpZS9
--- a/gfx/layers/basic/BasicPaintedLayer.cpp
+++ b/gfx/layers/basic/BasicPaintedLayer.cpp
@@ -157,17 +157,17 @@ BasicPaintedLayer::Validate(LayerManager
flags |= ContentClient::PAINT_WILL_RESAMPLE;
}
}
#endif
if (mDrawAtomically) {
flags |= ContentClient::PAINT_NO_ROTATION;
}
PaintState state =
- mContentClient->BeginPaintBuffer(this, flags);
+ mContentClient->BeginPaint(this, flags);
SubtractFromValidRegion(state.mRegionToInvalidate);
DrawTarget* target = mContentClient->BorrowDrawTargetForPainting(state);
if (target && target->IsValid()) {
// The area that became invalid and is visible needs to be repainted
// (this could be the whole visible area if our buffer switched
// from RGB to RGBA, because we might need to repaint with
// subpixel AA)
--- a/gfx/layers/client/ClientPaintedLayer.cpp
+++ b/gfx/layers/client/ClientPaintedLayer.cpp
@@ -133,21 +133,19 @@ ClientPaintedLayer::GetPaintFlags()
void
ClientPaintedLayer::PaintThebes(nsTArray<ReadbackProcessor::Update>* aReadbackUpdates)
{
AUTO_PROFILER_LABEL("ClientPaintedLayer::PaintThebes", GRAPHICS);
NS_ASSERTION(ClientManager()->InDrawing(),
"Can only draw in drawing phase");
- mContentClient->BeginPaint();
-
uint32_t flags = GetPaintFlags();
- PaintState state = mContentClient->BeginPaintBuffer(this, flags);
+ PaintState state = mContentClient->BeginPaint(this, flags);
if (!UpdatePaintRegion(state)) {
return;
}
bool didUpdate = false;
RotatedBuffer::DrawIterator iter;
while (DrawTarget* target = mContentClient->BorrowDrawTargetForPainting(state, &iter)) {
if (!target || !target->IsValid()) {
@@ -203,21 +201,19 @@ ClientPaintedLayer::PaintThebes(nsTArray
* from trying to paint again. The underlying API however is NOT thread safe.
* 4) We have both "sync" and "async" OMTP. Sync OMTP means we paint on the main thread
* but block the main thread while the paint thread paints. Async OMTP doesn't block
* the main thread. Sync OMTP is only meant to be used as a debugging tool.
*/
bool
ClientPaintedLayer::PaintOffMainThread()
{
- mContentClient->BeginAsyncPaint();
-
uint32_t flags = GetPaintFlags();
- PaintState state = mContentClient->BeginPaintBuffer(this, flags);
+ PaintState state = mContentClient->BeginPaint(this, flags | ContentClient::PAINT_ASYNC);
if (!UpdatePaintRegion(state)) {
return false;
}
bool didUpdate = false;
RotatedBuffer::DrawIterator iter;
// Debug Protip: Change to BorrowDrawTargetForPainting if using sync OMTP.
--- a/gfx/layers/client/ContentClient.cpp
+++ b/gfx/layers/client/ContentClient.cpp
@@ -106,19 +106,23 @@ ContentClient::CreateContentClient(Compo
void
ContentClient::Clear()
{
mBuffer = nullptr;
}
ContentClient::PaintState
-ContentClient::BeginPaintBuffer(PaintedLayer* aLayer,
- uint32_t aFlags)
+ContentClient::BeginPaint(PaintedLayer* aLayer,
+ uint32_t aFlags)
{
+ if (aFlags & PAINT_ASYNC) {
+ mInAsyncPaint = true;
+ }
+
PaintState result;
BufferDecision dest = CalculateBufferForPaint(aLayer, aFlags);
result.mContentType = dest.mBufferContentType;
if (!dest.mCanKeepBufferContents) {
// We're effectively clearing the valid region, so we need to draw
// the entire needed region now.
@@ -472,22 +476,16 @@ ContentClient::BufferSizeOkFor(const Int
OpenMode
ContentClient::LockMode() const
{
return mInAsyncPaint ? OpenMode::OPEN_READ_ASYNC_WRITE
: OpenMode::OPEN_READ_WRITE;
}
void
-ContentClient::BeginAsyncPaint()
-{
- mInAsyncPaint = true;
-}
-
-void
ContentClient::EndPaint(nsTArray<ReadbackProcessor::Update>* aReadbackUpdates)
{
mInAsyncPaint = false;
}
void
ContentClient::PrintInfo(std::stringstream& aStream, const char* aPrefix)
{
@@ -840,53 +838,46 @@ ContentClientDoubleBuffered::SwapBuffers
std::swap(frontBuffer, backBuffer);
mFrontBuffer = frontBuffer;
mBuffer = backBuffer;
mFrontAndBackBufferDiffer = true;
}
-void
-ContentClientDoubleBuffered::BeginPaint()
+ContentClient::PaintState
+ContentClientDoubleBuffered::BeginPaint(PaintedLayer* aLayer,
+ uint32_t aFlags)
{
EnsureBackBufferIfFrontBuffer();
mIsNewBuffer = false;
- if (!mFrontAndBackBufferDiffer) {
- return;
- }
-
if (!mFrontBuffer || !mBuffer) {
mFrontAndBackBufferDiffer = false;
- return;
}
- if (mFrontBuffer->DidSelfCopy()) {
- // We can't easily draw our front buffer into us, since we're going to be
- // copying stuff around anyway it's easiest if we just move our situation
- // to non-rotated while we're at it. If this situation occurs we'll have
- // hit a self-copy path in PaintThebes before as well anyway.
- gfx::IntRect backBufferRect = mBuffer->BufferRect();
- backBufferRect.MoveTo(mFrontBuffer->BufferRect().TopLeft());
+ if (mFrontAndBackBufferDiffer) {
+ if (mFrontBuffer->DidSelfCopy()) {
+ // We can't easily draw our front buffer into us, since we're going to be
+ // copying stuff around anyway it's easiest if we just move our situation
+ // to non-rotated while we're at it. If this situation occurs we'll have
+ // hit a self-copy path in PaintThebes before as well anyway.
+ gfx::IntRect backBufferRect = mBuffer->BufferRect();
+ backBufferRect.MoveTo(mFrontBuffer->BufferRect().TopLeft());
- mBuffer->SetBufferRect(backBufferRect);
- mBuffer->SetBufferRotation(IntPoint(0,0));
- return;
+ mBuffer->SetBufferRect(backBufferRect);
+ mBuffer->SetBufferRotation(IntPoint(0,0));
+ } else {
+ mBuffer->SetBufferRect(mFrontBuffer->BufferRect());
+ mBuffer->SetBufferRotation(mFrontBuffer->BufferRotation());
+ }
}
- mBuffer->SetBufferRect(mFrontBuffer->BufferRect());
- mBuffer->SetBufferRotation(mFrontBuffer->BufferRotation());
-}
-void
-ContentClientDoubleBuffered::BeginAsyncPaint()
-{
- BeginPaint();
- mInAsyncPaint = true;
+ return ContentClient::BeginPaint(aLayer, aFlags);
}
// Sync front/back buffers content
// After executing, the new back buffer has the same (interesting) pixels as
// the new front buffer, and mValidRegion et al. are correct wrt the new
// back buffer (i.e. as they were for the old back buffer)
void
ContentClientDoubleBuffered::FinalizeFrame(const nsIntRegion& aRegionToDraw)
--- a/gfx/layers/client/ContentClient.h
+++ b/gfx/layers/client/ContentClient.h
@@ -114,17 +114,18 @@ public:
SurfaceMode mMode;
DrawRegionClip mClip;
gfxContentType mContentType;
};
enum {
PAINT_WILL_RESAMPLE = 0x01,
PAINT_NO_ROTATION = 0x02,
- PAINT_CAN_DRAW_ROTATED = 0x04
+ PAINT_CAN_DRAW_ROTATED = 0x04,
+ PAINT_ASYNC = 0x08,
};
/**
* Start a drawing operation. This returns a PaintState describing what
* needs to be drawn to bring the buffer up to date in the visible region.
* This queries aLayer to get the currently valid and visible regions.
* The returned mTarget may be null if mRegionToDraw is empty.
* Otherwise it must not be null.
@@ -137,17 +138,18 @@ public:
* make the entire buffer contents valid (since we don't want to sample
* invalid pixels outside the visible region, if the visible region doesn't
* fill the buffer bounds).
* PAINT_CAN_DRAW_ROTATED can be passed if the caller supports drawing
* rotated content that crosses the physical buffer boundary. The caller
* will need to call BorrowDrawTargetForPainting multiple times to achieve
* this.
*/
- PaintState BeginPaintBuffer(PaintedLayer* aLayer, uint32_t aFlags);
+ virtual PaintState BeginPaint(PaintedLayer* aLayer, uint32_t aFlags);
+ virtual void EndPaint(nsTArray<ReadbackProcessor::Update>* aReadbackUpdates = nullptr);
/**
* Fetch a DrawTarget for rendering. The DrawTarget remains owned by
* this. See notes on BorrowDrawTargetForQuadrantUpdate.
* May return null. If the return value is non-null, it must be
* 'un-borrowed' using ReturnDrawTarget.
*
* If PAINT_CAN_DRAW_ROTATED was specified for BeginPaint, then the caller
@@ -170,21 +172,16 @@ public:
*/
virtual RefPtr<CapturedPaintState> BorrowDrawTargetForRecording(
PaintState& aPaintState,
RotatedBuffer::DrawIterator* aIter,
bool aSetTransform = false);
void ReturnDrawTarget(gfx::DrawTarget*& aReturned);
- // Call before and after painting into this content client
- virtual void BeginPaint() {}
- virtual void BeginAsyncPaint();
- virtual void EndPaint(nsTArray<ReadbackProcessor::Update>* aReadbackUpdates = nullptr);
-
static bool PrepareDrawTargetForPainting(CapturedPaintState*);
enum {
BUFFER_COMPONENT_ALPHA = 0x02 // Dual buffers should be created for drawing with
// component alpha.
};
protected:
@@ -366,18 +363,17 @@ public:
const char* aPrefix="",
bool aDumpHtml=false,
TextureDumpMode aCompress=TextureDumpMode::Compress) override;
virtual void Clear() override;
virtual void SwapBuffers(const nsIntRegion& aFrontUpdatedRegion) override;
- virtual void BeginPaint() override;
- virtual void BeginAsyncPaint() override;
+ virtual PaintState BeginPaint(PaintedLayer* aLayer, uint32_t aFlags) override;
virtual void FinalizeFrame(const nsIntRegion& aRegionToDraw) override;
virtual TextureInfo GetTextureInfo() const override
{
return TextureInfo(CompositableType::CONTENT_DOUBLE, mTextureFlags);
}