From 94edce8cf6468d7184870e3d3bd72784e8b3ab2f Mon Sep 17 00:00:00 2001 From: Ryan Hunt Date: Mon, 23 Oct 2017 12:40:01 -0400 Subject: [PATCH] Simplify the code for creating a new back buffer (bug 1399692 part 2, r=bas) MozReview-Commit-ID: D28JNYWD9Uc --HG-- extra : rebase_source : 96468353c813a9fa9b82f1ffe98ad87f70367a8b extra : source : 9fcb661df79e51c80f5ffb24717dba655dc97d73 --- gfx/layers/client/ContentClient.cpp | 68 ++++++++++++++--------------- 1 file changed, 32 insertions(+), 36 deletions(-) diff --git a/gfx/layers/client/ContentClient.cpp b/gfx/layers/client/ContentClient.cpp index 72cf8679411e..86221e35d289 100644 --- a/gfx/layers/client/ContentClient.cpp +++ b/gfx/layers/client/ContentClient.cpp @@ -172,68 +172,64 @@ ContentClient::BeginPaint(PaintedLayer* aLayer, !(aFlags & (PAINT_WILL_RESAMPLE | PAINT_NO_ROTATION)) && !(aLayer->Manager()->AsWebRenderLayerManager()); bool canDrawRotated = aFlags & PAINT_CAN_DRAW_ROTATED; - IntRect drawBounds = result.mRegionToDraw.GetBounds(); - RefPtr newBuffer; - uint32_t bufferFlags = 0; - if (dest.mBufferMode == SurfaceMode::SURFACE_COMPONENT_ALPHA) { - bufferFlags |= BUFFER_COMPONENT_ALPHA; - } - if (dest.mCanReuseBuffer && mBuffer) { + + if (dest.mCanReuseBuffer) { + MOZ_ASSERT(mBuffer); + if (!mBuffer->AdjustTo(dest.mBufferRect, drawBounds, canHaveRotation, canDrawRotated)) { dest.mBufferRect = ComputeBufferRect(dest.mNeededRegion.GetBounds()); - newBuffer = CreateBuffer(result.mContentType, dest.mBufferRect, bufferFlags); - - if (!newBuffer) { - if (Factory::ReasonableSurfaceSize(IntSize(dest.mBufferRect.Width(), dest.mBufferRect.Height()))) { - gfxCriticalNote << "Failed 1 buffer for " - << dest.mBufferRect.x << ", " - << dest.mBufferRect.y << ", " - << dest.mBufferRect.Width() << ", " - << dest.mBufferRect.Height(); - } - return result; - } - } - } else { - // The buffer's not big enough, so allocate a new one - newBuffer = CreateBuffer(result.mContentType, dest.mBufferRect, bufferFlags); - if (!newBuffer) { - if (Factory::ReasonableSurfaceSize(IntSize(dest.mBufferRect.Width(), dest.mBufferRect.Height()))) { - gfxCriticalNote << "Failed 2 buffer for " - << dest.mBufferRect.x << ", " - << dest.mBufferRect.y << ", " - << dest.mBufferRect.Width() << ", " - << dest.mBufferRect.Height(); - } - return result; + dest.mCanReuseBuffer = false; } } NS_ASSERTION(!(aFlags & PAINT_WILL_RESAMPLE) || dest.mBufferRect == dest.mNeededRegion.GetBounds(), "If we're resampling, we need to validate the entire buffer"); - // If needed, copy the old buffer over to the new one - if (newBuffer) { + // The buffer's not big enough, changed content, or we failed to unrotate it, + // so we need to allocate a new one and prepare it for drawing + if (!dest.mCanReuseBuffer) { + uint32_t bufferFlags = 0; + if (dest.mBufferMode == SurfaceMode::SURFACE_COMPONENT_ALPHA) { + bufferFlags |= BUFFER_COMPONENT_ALPHA; + } + + RefPtr newBuffer = CreateBuffer(result.mContentType, + dest.mBufferRect, + bufferFlags); + + if (!newBuffer) { + if (Factory::ReasonableSurfaceSize(IntSize(dest.mBufferRect.Width(), dest.mBufferRect.Height()))) { + gfxCriticalNote << "Failed buffer for " + << dest.mBufferRect.x << ", " + << dest.mBufferRect.y << ", " + << dest.mBufferRect.Width() << ", " + << dest.mBufferRect.Height(); + } + Clear(); + return result; + } + if (!newBuffer->Lock(lockMode)) { gfxCriticalNote << "Failed to lock new back buffer."; Clear(); return result; } + // If we have an existing back buffer, copy it into the new back buffer if (mBuffer) { newBuffer->UpdateDestinationFrom(*mBuffer, newBuffer->BufferRect()); // We are done with the old back buffer now and it is about to be - // destroyed, so unlock it. + // destroyed, so unlock it mBuffer->Unlock(); } // Ensure our reference to the front buffer is released - // as well as the old back buffer. + // as well as the old back buffer Clear(); mBuffer = newBuffer;