diff --git a/content/svg/content/src/SVGMotionSMILPathUtils.h b/content/svg/content/src/SVGMotionSMILPathUtils.h index e1e42bf32e75..50f4fc1961f0 100644 --- a/content/svg/content/src/SVGMotionSMILPathUtils.h +++ b/content/svg/content/src/SVGMotionSMILPathUtils.h @@ -47,7 +47,6 @@ #include "nsDebug.h" #include "gfxContext.h" #include "nsSVGUtils.h" -#include "gfxPlatform.h" class nsSVGElement; class nsIContent; @@ -64,7 +63,7 @@ public: public: PathGenerator(nsSVGElement* aSVGElement) : mSVGElement(aSVGElement), - mGfxContext(gfxPlatform::GetPlatform()->ScreenReferenceSurface()), + mGfxContext(nsSVGUtils::GetThebesComputationalSurface()), mHaveReceivedCommands(PR_FALSE) {} diff --git a/content/svg/content/src/nsSVGPathElement.cpp b/content/svg/content/src/nsSVGPathElement.cpp index 1a0e4f9da019..35a9b56479fd 100644 --- a/content/svg/content/src/nsSVGPathElement.cpp +++ b/content/svg/content/src/nsSVGPathElement.cpp @@ -48,7 +48,6 @@ #include "nsSVGUtils.h" #include "nsSVGPoint.h" #include "gfxContext.h" -#include "gfxPlatform.h" nsSVGElement::NumberInfo nsSVGPathElement::sNumberInfo = { &nsGkAtoms::pathLength, 0 }; @@ -1042,7 +1041,7 @@ nsSVGPathList::Playback(gfxContext *aCtx) already_AddRefed nsSVGPathList::GetFlattenedPath(const gfxMatrix& aMatrix) { - gfxContext ctx(gfxPlatform::GetPlatform()->ScreenReferenceSurface()); + gfxContext ctx(nsSVGUtils::GetThebesComputationalSurface()); ctx.SetMatrix(aMatrix); Playback(&ctx); diff --git a/layout/build/nsLayoutStatics.cpp b/layout/build/nsLayoutStatics.cpp index ee4a7b79e0db..94f9538eab4a 100644 --- a/layout/build/nsLayoutStatics.cpp +++ b/layout/build/nsLayoutStatics.cpp @@ -316,6 +316,10 @@ nsLayoutStatics::Shutdown() nsCellMap::Shutdown(); nsFrame::ShutdownLayerActivityTimer(); +#ifdef MOZ_SVG + nsSVGUtils::Shutdown(); +#endif + // Release all of our atoms nsColorNames::ReleaseTable(); nsCSSProps::ReleaseTable(); diff --git a/layout/svg/base/src/nsSVGGlyphFrame.cpp b/layout/svg/base/src/nsSVGGlyphFrame.cpp index 0c46331c3d75..07fa870b447e 100644 --- a/layout/svg/base/src/nsSVGGlyphFrame.cpp +++ b/layout/svg/base/src/nsSVGGlyphFrame.cpp @@ -439,7 +439,7 @@ nsSVGGlyphFrame::GetCoveredRegion() static gfxContext * MakeTmpCtx() { - return new gfxContext(gfxPlatform::GetPlatform()->ScreenReferenceSurface()); + return new gfxContext(nsSVGUtils::GetThebesComputationalSurface()); } NS_IMETHODIMP diff --git a/layout/svg/base/src/nsSVGImageFrame.cpp b/layout/svg/base/src/nsSVGImageFrame.cpp index c5b18d218f0c..810d86c47d9e 100644 --- a/layout/svg/base/src/nsSVGImageFrame.cpp +++ b/layout/svg/base/src/nsSVGImageFrame.cpp @@ -45,7 +45,6 @@ #include "gfxContext.h" #include "gfxMatrix.h" #include "nsIInterfaceRequestorUtils.h" -#include "gfxPlatform.h" class nsSVGImageFrame; @@ -328,7 +327,7 @@ nsSVGImageFrame::UpdateCoveredRegion() { mRect.Empty(); - gfxContext context(gfxPlatform::GetPlatform()->ScreenReferenceSurface()); + gfxContext context(nsSVGUtils::GetThebesComputationalSurface()); GeneratePath(&context); context.IdentityMatrix(); diff --git a/layout/svg/base/src/nsSVGPathGeometryFrame.cpp b/layout/svg/base/src/nsSVGPathGeometryFrame.cpp index c44288e0fede..3fee04670855 100644 --- a/layout/svg/base/src/nsSVGPathGeometryFrame.cpp +++ b/layout/svg/base/src/nsSVGPathGeometryFrame.cpp @@ -46,7 +46,6 @@ #include "nsSVGRect.h" #include "nsSVGPathGeometryElement.h" #include "gfxContext.h" -#include "gfxPlatform.h" //---------------------------------------------------------------------- // Implementation @@ -170,7 +169,7 @@ nsSVGPathGeometryFrame::GetFrameForPoint(const nsPoint &aPoint) PRBool isHit = PR_FALSE; - gfxContext context(gfxPlatform::GetPlatform()->ScreenReferenceSurface()); + gfxContext context(nsSVGUtils::GetThebesComputationalSurface()); GeneratePath(&context); gfxPoint userSpacePoint = @@ -250,7 +249,7 @@ nsSVGPathGeometryFrame::UpdateCoveredRegion() { mRect.Empty(); - gfxContext context(gfxPlatform::GetPlatform()->ScreenReferenceSurface()); + gfxContext context(nsSVGUtils::GetThebesComputationalSurface()); GeneratePath(&context); context.IdentityMatrix(); @@ -362,7 +361,7 @@ nsSVGPathGeometryFrame::GetBBoxContribution(const gfxMatrix &aToBBoxUserspace) // XXX ReportToConsole return gfxRect(0.0, 0.0, 0.0, 0.0); } - gfxContext context(gfxPlatform::GetPlatform()->ScreenReferenceSurface()); + gfxContext context(nsSVGUtils::GetThebesComputationalSurface()); GeneratePath(&context, &aToBBoxUserspace); context.IdentityMatrix(); return context.GetUserPathExtent(); diff --git a/layout/svg/base/src/nsSVGUtils.cpp b/layout/svg/base/src/nsSVGUtils.cpp index 2f2c962cc09a..03737b619510 100644 --- a/layout/svg/base/src/nsSVGUtils.cpp +++ b/layout/svg/base/src/nsSVGUtils.cpp @@ -1204,6 +1204,28 @@ nsSVGUtils::ConvertToSurfaceSize(const gfxSize& aSize, PRBool *aResultOverflows) return surfaceSize; } +gfxASurface * +nsSVGUtils::GetThebesComputationalSurface() +{ + if (!gThebesComputationalSurface) { + nsRefPtr surface = + new gfxImageSurface(gfxIntSize(1, 1), gfxASurface::ImageFormatARGB32); + NS_ASSERTION(surface && !surface->CairoStatus(), + "Could not create offscreen surface"); + gThebesComputationalSurface = surface; + // we want to keep this surface around + NS_IF_ADDREF(gThebesComputationalSurface); + } + + return gThebesComputationalSurface; +} + +void +nsSVGUtils::Shutdown() +{ + NS_IF_RELEASE(gThebesComputationalSurface); +} + gfxMatrix nsSVGUtils::ConvertSVGMatrixToThebes(nsIDOMSVGMatrix *aMatrix) { @@ -1228,7 +1250,7 @@ nsSVGUtils::HitTestRect(const gfxMatrix &aMatrix, if (aMatrix.IsSingular()) { return PR_FALSE; } - gfxContext ctx(gfxPlatform::GetPlatform()->ScreenReferenceSurface()); + gfxContext ctx(GetThebesComputationalSurface()); ctx.SetMatrix(aMatrix); ctx.NewPath(); ctx.Rectangle(gfxRect(aRX, aRY, aRWidth, aRHeight)); diff --git a/layout/svg/base/src/nsSVGUtils.h b/layout/svg/base/src/nsSVGUtils.h index 547e25114a8e..e061f321b044 100644 --- a/layout/svg/base/src/nsSVGUtils.h +++ b/layout/svg/base/src/nsSVGUtils.h @@ -433,6 +433,13 @@ public: static gfxIntSize ConvertToSurfaceSize(const gfxSize& aSize, PRBool *aResultOverflows); + /* + * Get a pointer to a surface that can be used to create thebes + * contexts for various measurement purposes. + */ + static gfxASurface * + GetThebesComputationalSurface(); + /* * Convert a nsIDOMSVGMatrix to a gfxMatrix. */ @@ -563,6 +570,8 @@ public: static PRBool NumberFromString(const nsAString& aString, float* aValue, PRBool aAllowPercentages = PR_FALSE); + static void Shutdown(); + private: /* Computational (nil) surfaces */ static gfxASurface *gThebesComputationalSurface;