Bug 603885, part 5: Move the code for getting a gfxContext for a quadrant update into its own method. r=roc
authorChris Jones <jones.chris.g@gmail.com>
Fri, 05 Nov 2010 02:17:07 -0500
changeset 56902 b5086952fc37ce26581b82665cb69bb439870a74
parent 56901 3c824e9712acebd8e77558d7ecb837b11358d317
child 56903 d6b5d3e3ffbf50787a266bbd316e4b9d5469d908
push id16725
push usercjones@mozilla.com
push dateFri, 05 Nov 2010 07:21:46 +0000
treeherdermozilla-central@0aa98eae87ed [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs603885
milestone2.0b8pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 603885, part 5: Move the code for getting a gfxContext for a quadrant update into its own method. r=roc
gfx/layers/ThebesLayerBuffer.cpp
gfx/layers/ThebesLayerBuffer.h
--- a/gfx/layers/ThebesLayerBuffer.cpp
+++ b/gfx/layers/ThebesLayerBuffer.cpp
@@ -143,16 +143,36 @@ ThebesLayerBuffer::DrawBufferWithRotatio
   // Draw four quadrants. We could use REPEAT_, but it's probably better
   // not to, to be performance-safe.
   DrawBufferQuadrant(aTarget, LEFT, TOP, aOpacity, aXRes, aYRes);
   DrawBufferQuadrant(aTarget, RIGHT, TOP, aOpacity, aXRes, aYRes);
   DrawBufferQuadrant(aTarget, LEFT, BOTTOM, aOpacity, aXRes, aYRes);
   DrawBufferQuadrant(aTarget, RIGHT, BOTTOM, aOpacity, aXRes, aYRes);
 }
 
+already_AddRefed<gfxContext>
+ThebesLayerBuffer::GetContextForQuadrantUpdate(const nsIntRect& aBounds,
+                                               float aXResolution,
+                                               float aYResolution)
+{
+  nsRefPtr<gfxContext> ctx = new gfxContext(mBuffer);
+
+  // Figure out which quadrant to draw in
+  PRInt32 xBoundary = mBufferRect.XMost() - mBufferRotation.x;
+  PRInt32 yBoundary = mBufferRect.YMost() - mBufferRotation.y;
+  XSide sideX = aBounds.XMost() <= xBoundary ? RIGHT : LEFT;
+  YSide sideY = aBounds.YMost() <= yBoundary ? BOTTOM : TOP;
+  nsIntRect quadrantRect = GetQuadrantRectangle(sideX, sideY);
+  NS_ASSERTION(quadrantRect.Contains(aBounds), "Messed up quadrants");
+  ctx->Scale(aXResolution, aYResolution);
+  ctx->Translate(-gfxPoint(quadrantRect.x, quadrantRect.y));
+
+  return ctx.forget();
+}
+
 static void
 WrapRotationAxis(PRInt32* aRotationPoint, PRInt32 aSize)
 {
   if (*aRotationPoint < 0) {
     *aRotationPoint += aSize;
   } else if (*aRotationPoint >= aSize) {
     *aRotationPoint -= aSize;
   }
@@ -285,27 +305,18 @@ ThebesLayerBuffer::BeginPaint(ThebesLaye
   if (bufferDimsChanged) {
     mBufferDims = destBufferDims;
   }
 
   nsIntRegion invalidate;
   invalidate.Sub(aLayer->GetValidRegion(), destBufferRect);
   result.mRegionToInvalidate.Or(result.mRegionToInvalidate, invalidate);
 
-  result.mContext = new gfxContext(mBuffer);
-
-  // Figure out which quadrant to draw in
-  PRInt32 xBoundary = mBufferRect.XMost() - mBufferRotation.x;
-  PRInt32 yBoundary = mBufferRect.YMost() - mBufferRotation.y;
-  XSide sideX = drawBounds.XMost() <= xBoundary ? RIGHT : LEFT;
-  YSide sideY = drawBounds.YMost() <= yBoundary ? BOTTOM : TOP;
-  nsIntRect quadrantRect = GetQuadrantRectangle(sideX, sideY);
-  NS_ASSERTION(quadrantRect.Contains(drawBounds), "Messed up quadrants");
-  result.mContext->Scale(aXResolution, aYResolution);
-  result.mContext->Translate(-gfxPoint(quadrantRect.x, quadrantRect.y));
+  result.mContext = GetContextForQuadrantUpdate(drawBounds,
+                                                aXResolution, aYResolution);
 
   gfxUtils::ClipToRegion(result.mContext, result.mRegionToDraw);
   if (aContentType == gfxASurface::CONTENT_COLOR_ALPHA && !isClear) {
     result.mContext->SetOperator(gfxContext::OPERATOR_CLEAR);
     result.mContext->Paint();
     result.mContext->SetOperator(gfxContext::OPERATOR_OVER);
   }
   return result;
--- a/gfx/layers/ThebesLayerBuffer.h
+++ b/gfx/layers/ThebesLayerBuffer.h
@@ -177,16 +177,24 @@ protected:
     nsRefPtr<gfxASurface> tmp = mBuffer.forget();
     mBuffer = aBuffer;
     mBufferDims = aBufferDims;
     mBufferRect = aBufferRect;
     mBufferRotation = aBufferRotation;
     return tmp.forget();
   }
 
+  /**
+   * Get a context at the specified resolution for updating |aBounds|,
+   * which must be contained within a single quadrant.
+   */
+  already_AddRefed<gfxContext>
+  GetContextForQuadrantUpdate(const nsIntRect& aBounds,
+                              float aXResolution, float aYResolution);
+
 private:
   PRBool BufferSizeOkFor(const nsIntSize& aSize)
   {
     return (aSize == mBufferDims ||
             (SizedToVisibleBounds != mBufferSizePolicy &&
              aSize < mBufferDims));
   }