From cd67756e2ecbe509bba440633af1207a67ac3b5a Mon Sep 17 00:00:00 2001 From: Matt Woodrow Date: Tue, 5 Nov 2013 17:50:57 +1300 Subject: [PATCH] Bug 923434 - Use DrawSurface in ThebesLayerBuffer instead of FillRect. r=Bas --- gfx/layers/ThebesLayerBuffer.cpp | 53 ++++++++++++++++++++++++-------- gfx/layers/ThebesLayerBuffer.h | 2 ++ 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/gfx/layers/ThebesLayerBuffer.cpp b/gfx/layers/ThebesLayerBuffer.cpp index faad24b01d70..e0b4cb0516ad 100644 --- a/gfx/layers/ThebesLayerBuffer.cpp +++ b/gfx/layers/ThebesLayerBuffer.cpp @@ -50,6 +50,27 @@ RotatedBuffer::GetQuadrantRectangle(XSide aXSide, YSide aYSide) const return mBufferRect + quadrantTranslation; } +Rect +RotatedBuffer::GetSourceRectangle(XSide aXSide, YSide aYSide) const +{ + Rect result; + if (aXSide == LEFT) { + result.x = 0; + result.width = mBufferRotation.x; + } else { + result.x = mBufferRotation.x; + result.width = mBufferRect.width - mBufferRotation.x; + } + if (aYSide == TOP) { + result.y = 0; + result.height = mBufferRotation.y; + } else { + result.y = mBufferRotation.y; + result.height = mBufferRect.height - mBufferRotation.y; + } + return result; +} + /** * @param aXSide LEFT means we draw from the left side of the buffer (which * is drawn on the right side of mBufferRect). RIGHT means we draw from @@ -199,16 +220,6 @@ RotatedBuffer::DrawBufferQuadrant(gfx::DrawTarget* aTarget, snapshot = mDTBufferOnWhite->Snapshot(); } - // Transform from user -> buffer space. - Matrix transform; - transform.Translate(quadrantTranslation.x, quadrantTranslation.y); - -#ifdef MOZ_GFX_OPTIMIZE_MOBILE - SurfacePattern source(snapshot, EXTEND_CLAMP, transform, FILTER_POINT); -#else - SurfacePattern source(snapshot, EXTEND_CLAMP, transform); -#endif - if (aOperator == OP_SOURCE) { // OP_SOURCE is unbounded in Azure, and we really don't want that behaviour here. // We also can't do a ClearRect+FillRect since we need the drawing to happen @@ -218,14 +229,30 @@ RotatedBuffer::DrawBufferQuadrant(gfx::DrawTarget* aTarget, } if (aMask) { + // Transform from user -> buffer space. + Matrix transform; + transform.Translate(quadrantTranslation.x, quadrantTranslation.y); + +#ifdef MOZ_GFX_OPTIMIZE_MOBILE + SurfacePattern source(snapshot, EXTEND_CLAMP, transform, FILTER_POINT); +#else + SurfacePattern source(snapshot, EXTEND_CLAMP, transform); +#endif + Matrix oldTransform = aTarget->GetTransform(); aTarget->SetTransform(*aMaskTransform); aTarget->MaskSurface(source, aMask, Point(0, 0), DrawOptions(aOpacity, aOperator)); aTarget->SetTransform(oldTransform); } else { - aTarget->FillRect(gfx::Rect(fillRect.x, fillRect.y, - fillRect.width, fillRect.height), - source, DrawOptions(aOpacity, aOperator)); +#ifdef MOZ_GFX_OPTIMIZE_MOBILE + DrawSurfaceOptions options(FILTER_POINT); +#else + DrawSurfaceOptions options; +#endif + aTarget->DrawSurface(snapshot, ToRect(fillRect), + GetSourceRectangle(aXSide, aYSide), + options, + DrawOptions(aOpacity, aOperator)); } if (aOperator == OP_SOURCE) { diff --git a/gfx/layers/ThebesLayerBuffer.h b/gfx/layers/ThebesLayerBuffer.h index 45fdb0e502a8..819eab4452c9 100644 --- a/gfx/layers/ThebesLayerBuffer.h +++ b/gfx/layers/ThebesLayerBuffer.h @@ -112,6 +112,8 @@ protected: }; nsIntRect GetQuadrantRectangle(XSide aXSide, YSide aYSide) const; + gfx::Rect GetSourceRectangle(XSide aXSide, YSide aYSide) const; + /* * If aMask is non-null, then it is used as an alpha mask for rendering this * buffer. aMaskTransform must be non-null if aMask is non-null, and is used