Refactor copying from the old buffer to the new buffer to use RotatedBuffer. (bug 1409871 part 7, r=nical)
authorRyan Hunt <rhunt@eqrion.net>
Thu, 12 Oct 2017 12:35:37 -0400
changeset 686293 a73b480ecb965462ea616dec32f6c7dab8de6f69
parent 686292 c34a0b48cdd146ac3c488bf210a3a1a44f622ad8
child 686294 75046ddbc41049178737b1448d119ad886457987
push id86150
push userbmo:mstriemer@mozilla.com
push dateWed, 25 Oct 2017 17:39:25 +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;