Refactor copying from the old buffer to the new buffer to use RotatedBuffer. (bug 1409871 part 7, r=nical) draft
authorRyan Hunt <rhunt@eqrion.net>
Thu, 12 Oct 2017 12:35:37 -0400
changeset 684129 ed1f305fccc7a67ed690b58b55a47072afba4b94
parent 684128 78cf5c683fba1640f3bb95bb345bb437d660c347
child 684130 410b136e1c49586545e7285a2994bdae061c1845
push id85567
push userbmo:rhunt@eqrion.net
push dateFri, 20 Oct 2017 22:13:22 +0000
reviewersnical
bugs1409871
milestone58.0a1
Refactor copying from the old buffer to the new buffer to use RotatedBuffer. (bug 1409871 part 7, r=nical) This commit refactors part of BeginPaint to treat the new and old back buffer's as rotated buffers. The goal of this is to simplify and prepare this function to be moved out of rotated content buffer. MozReview-Commit-ID: 5iHeMbCWfpo
gfx/layers/RotatedBuffer.cpp
--- a/gfx/layers/RotatedBuffer.cpp
+++ b/gfx/layers/RotatedBuffer.cpp
@@ -253,18 +253,17 @@ RotatedBuffer::UpdateDestinationFrom(con
     if (isClippingCheap) {
       destDT->PopClip();
     }
     // Flush the destination before the sources become inaccessible (Unlock).
     destDT->Flush();
     ReturnDrawTarget(destDT);
   }
 
-  if (aSource.HaveBufferOnWhite()) {
-    MOZ_ASSERT(HaveBufferOnWhite());
+  if (aSource.HaveBufferOnWhite() && HaveBufferOnWhite()) {
     DrawIterator whiteIter;
     while (DrawTarget* destDT =
       BorrowDrawTargetForQuadrantUpdate(aUpdateRegion.GetBounds(), BUFFER_WHITE, &whiteIter)) {
       bool isClippingCheap = IsClippingCheap(destDT, whiteIter.mDrawRegion);
       if (isClippingCheap) {
         gfxUtils::ClipToRegion(destDT, whiteIter.mDrawRegion);
       }
 
@@ -826,48 +825,35 @@ RotatedContentBuffer::BeginPaint(Painted
       }
       return result;
     }
   }
 
   NS_ASSERTION(!(aFlags & PAINT_WILL_RESAMPLE) || destBufferRect == neededRegion.GetBounds(),
                "If we're resampling, we need to validate the entire buffer");
 
-  // If we have no buffered data already, then destBuffer will be a fresh buffer
-  // and we do not need to clear it below.
-  bool isClear = !HaveBuffer();
-
+  // If needed, copy the old buffer over to the new one
   if (destDTBuffer) {
-    if (!isClear && (mode != SurfaceMode::SURFACE_COMPONENT_ALPHA || HaveBufferOnWhite())) {
-      // Copy the bits
-      IntPoint offset = -destBufferRect.TopLeft();
-      Matrix mat = Matrix::Translation(offset.x, offset.y);
-      destDTBuffer->SetTransform(mat);
-      if (!EnsureBuffer()) {
-        return result;
-      }
-      MOZ_ASSERT(mDTBuffer && mDTBuffer->IsValid(), "Have we got a Thebes buffer for some reason?");
-      DrawBufferWithRotation(destDTBuffer, BUFFER_BLACK, 1.0, CompositionOp::OP_SOURCE);
-      destDTBuffer->SetTransform(Matrix());
+    if ((HaveBuffer() && EnsureBuffer()) &&
+        (mode != SurfaceMode::SURFACE_COMPONENT_ALPHA || (HaveBufferOnWhite() && EnsureBufferOnWhite()))) {
+      DrawTargetRotatedBuffer oldBuffer = DrawTargetRotatedBuffer(mDTBuffer, mDTBufferOnWhite,
+                                                                  mBufferRect, mBufferRotation);
 
-      if (mode == SurfaceMode::SURFACE_COMPONENT_ALPHA) {
-        if (!destDTBufferOnWhite || !EnsureBufferOnWhite()) {
-          return result;
-        }
-        MOZ_ASSERT(mDTBufferOnWhite && mDTBufferOnWhite->IsValid(), "Have we got a Thebes buffer for some reason?");
-        destDTBufferOnWhite->SetTransform(mat);
-        DrawBufferWithRotation(destDTBufferOnWhite, BUFFER_WHITE, 1.0, CompositionOp::OP_SOURCE);
-        destDTBufferOnWhite->SetTransform(Matrix());
-      }
+      mDTBuffer = destDTBuffer.forget();
+      mDTBufferOnWhite = destDTBufferOnWhite.forget();
+      mBufferRect = destBufferRect;
+      mBufferRotation = IntPoint(0,0);
+
+      UpdateDestinationFrom(oldBuffer, nsIntRegion(mBufferRect));
+    } else {
+      mDTBuffer = destDTBuffer.forget();
+      mDTBufferOnWhite = destDTBufferOnWhite.forget();
+      mBufferRect = destBufferRect;
+      mBufferRotation = IntPoint(0,0);
     }
-
-    mDTBuffer = destDTBuffer.forget();
-    mDTBufferOnWhite = destDTBufferOnWhite.forget();
-    mBufferRect = destBufferRect;
-    mBufferRotation = IntPoint(0,0);
   }
   NS_ASSERTION(canHaveRotation || mBufferRotation == IntPoint(0,0),
                "Rotation disabled, but we have nonzero rotation?");
 
   nsIntRegion invalidate;
   invalidate.Sub(aLayer->GetValidRegion(), destBufferRect);
   result.mRegionToInvalidate.Or(result.mRegionToInvalidate, invalidate);
   result.mClip = DrawRegionClip::DRAW;