From 1f88d8036d88b9f79e6b5dd16ee67e51d2d8709b Mon Sep 17 00:00:00 2001 From: Jonathan Watt Date: Fri, 15 Jun 2012 04:02:27 +0100 Subject: [PATCH] Bug 764813 - Avoid using gfxContext::SetMatrix in SVG code where possible. r=Bas. --- layout/svg/base/src/nsSVGGlyphFrame.cpp | 4 +--- layout/svg/base/src/nsSVGIntegrationUtils.cpp | 8 ++------ layout/svg/base/src/nsSVGUtils.cpp | 17 ++++++++--------- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/layout/svg/base/src/nsSVGGlyphFrame.cpp b/layout/svg/base/src/nsSVGGlyphFrame.cpp index 102446e8e414..703e7670c473 100644 --- a/layout/svg/base/src/nsSVGGlyphFrame.cpp +++ b/layout/svg/base/src/nsSVGGlyphFrame.cpp @@ -317,8 +317,7 @@ nsSVGGlyphFrame::PaintSVG(nsRenderingContext *aContext, } if (renderMode != SVGAutoRenderState::NORMAL) { - - gfxMatrix matrix = gfx->CurrentMatrix(); + gfxContextMatrixAutoSaveRestore matrixAutoSaveRestore(gfx); SetupGlobalTransform(gfx); CharacterIterator iter(this, true); @@ -336,7 +335,6 @@ nsSVGGlyphFrame::PaintSVG(nsRenderingContext *aContext, DrawCharacters(&iter, gfx, gfxFont::GLYPH_PATH); } - gfx->SetMatrix(matrix); return NS_OK; } diff --git a/layout/svg/base/src/nsSVGIntegrationUtils.cpp b/layout/svg/base/src/nsSVGIntegrationUtils.cpp index 017ba377d3f7..48089436aad9 100644 --- a/layout/svg/base/src/nsSVGIntegrationUtils.cpp +++ b/layout/svg/base/src/nsSVGIntegrationUtils.cpp @@ -250,7 +250,7 @@ nsSVGIntegrationUtils::PaintFramesWithEffects(nsRenderingContext* aCtx, } gfxContext* gfx = aCtx->ThebesContext(); - gfxMatrix savedCTM = gfx->CurrentMatrix(); + gfxContextMatrixAutoSaveRestore matrixAutoSaveRestore(gfx); //SVGAutoRenderState autoRenderState(aCtx, SVGAutoRenderState::NORMAL); @@ -286,7 +286,7 @@ nsSVGIntegrationUtils::PaintFramesWithEffects(nsRenderingContext* aCtx, nsIntRect r = (aDirtyRect - userSpaceRect.TopLeft()).ToOutsidePixels(appUnitsPerDevPixel); filterFrame->FilterPaint(aCtx, aEffectsFrame, &paint, &r); } else { - gfx->SetMatrix(savedCTM); + gfx->SetMatrix(matrixAutoSaveRestore.Matrix()); aInnerList->PaintForFrame(aBuilder, aCtx, aEffectsFrame, nsDisplayList::PAINT_DEFAULT); aCtx->Translate(userSpaceRect.TopLeft()); @@ -298,7 +298,6 @@ nsSVGIntegrationUtils::PaintFramesWithEffects(nsRenderingContext* aCtx, /* No more effects, we're done. */ if (!complexEffects) { - gfx->SetMatrix(savedCTM); return; } @@ -334,7 +333,6 @@ nsSVGIntegrationUtils::PaintFramesWithEffects(nsRenderingContext* aCtx, } gfx->Restore(); - gfx->SetMatrix(savedCTM); } gfxMatrix @@ -420,7 +418,6 @@ PaintFrameCallback::operator()(gfxContext* aContext, aContext->NewPath(); aContext->Rectangle(aFillRect); aContext->Clip(); - gfxMatrix savedMatrix(aContext->CurrentMatrix()); aContext->Multiply(gfxMatrix(aTransform).Invert()); @@ -450,7 +447,6 @@ PaintFrameCallback::operator()(gfxContext* aContext, nsLayoutUtils::PAINT_IN_TRANSFORM | nsLayoutUtils::PAINT_ALL_CONTINUATIONS); - aContext->SetMatrix(savedMatrix); aContext->Restore(); mFrame->RemoveStateBits(NS_FRAME_DRAWING_AS_PAINTSERVER); diff --git a/layout/svg/base/src/nsSVGUtils.cpp b/layout/svg/base/src/nsSVGUtils.cpp index e422a6bb3092..488211db2832 100644 --- a/layout/svg/base/src/nsSVGUtils.cpp +++ b/layout/svg/base/src/nsSVGUtils.cpp @@ -1407,15 +1407,15 @@ nsSVGUtils::HitTestRect(const gfxMatrix &aMatrix, float aRX, float aRY, float aRWidth, float aRHeight, float aX, float aY) { - if (aMatrix.IsSingular()) { + gfxRect rect(aRX, aRY, aRWidth, aRHeight); + if (rect.IsEmpty() || aMatrix.IsSingular()) { return false; } - gfxContext ctx(gfxPlatform::GetPlatform()->ScreenReferenceSurface()); - ctx.SetMatrix(aMatrix); - ctx.NewPath(); - ctx.Rectangle(gfxRect(aRX, aRY, aRWidth, aRHeight)); - ctx.IdentityMatrix(); - return ctx.PointInFill(gfxPoint(aX, aY)); + gfxMatrix toRectSpace = aMatrix; + toRectSpace.Invert(); + gfxPoint p = toRectSpace.Transform(gfxPoint(aX, aY)); + return rect.x <= p.x && p.x <= rect.XMost() && + rect.y <= p.y && p.y <= rect.YMost(); } gfxRect @@ -1518,10 +1518,9 @@ nsSVGUtils::SetClipRect(gfxContext *aContext, if (aCTM.IsSingular()) return; - gfxMatrix oldMatrix = aContext->CurrentMatrix(); + gfxContextMatrixAutoSaveRestore matrixAutoSaveRestore(aContext); aContext->Multiply(aCTM); aContext->Clip(aRect); - aContext->SetMatrix(oldMatrix); } void