diff --git a/gfx/src/thebes/nsThebesDeviceContext.cpp b/gfx/src/thebes/nsThebesDeviceContext.cpp index be0a2d86682f..252d6f6460a4 100644 --- a/gfx/src/thebes/nsThebesDeviceContext.cpp +++ b/gfx/src/thebes/nsThebesDeviceContext.cpp @@ -133,6 +133,13 @@ nsThebesDeviceContext::~nsThebesDeviceContext() { } +/* static */ void +nsThebesDeviceContext::Shutdown() +{ + delete gSystemFonts; + gSystemFonts = nsnull; +} + nsresult nsThebesDeviceContext::SetDPI() { diff --git a/gfx/src/thebes/nsThebesDeviceContext.h b/gfx/src/thebes/nsThebesDeviceContext.h index 46eef103e59d..da9967d653f4 100644 --- a/gfx/src/thebes/nsThebesDeviceContext.h +++ b/gfx/src/thebes/nsThebesDeviceContext.h @@ -67,6 +67,8 @@ public: nsThebesDeviceContext(); virtual ~nsThebesDeviceContext(); + static void Shutdown(); + NS_DECL_ISUPPORTS_INHERITED NS_IMETHOD Init(nsNativeWidget aWidget); diff --git a/gfx/src/thebes/nsThebesGfxFactory.cpp b/gfx/src/thebes/nsThebesGfxFactory.cpp index 1305feec5012..8512fcaf1de5 100644 --- a/gfx/src/thebes/nsThebesGfxFactory.cpp +++ b/gfx/src/thebes/nsThebesGfxFactory.cpp @@ -51,6 +51,7 @@ #include "nsThebesBlender.h" #include "nsThebesFontMetrics.h" #include "nsThebesFontEnumerator.h" +#include "gfxPlatform.h" NS_GENERIC_FACTORY_CONSTRUCTOR(nsThebesFontMetrics) NS_GENERIC_FACTORY_CONSTRUCTOR(nsThebesBlender) @@ -145,6 +146,8 @@ static const nsModuleComponentInfo components[] = PR_STATIC_CALLBACK(void) nsThebesGfxModuleDtor(nsIModule *self) { + nsThebesDeviceContext::Shutdown(); + gfxPlatform::Shutdown(); } NS_IMPL_NSGETMODULE_WITH_DTOR(nsGfxModule, components, nsThebesGfxModuleDtor) diff --git a/gfx/thebes/public/gfxBeOSPlatform.h b/gfx/thebes/public/gfxBeOSPlatform.h index e3aed6519671..f42c73645864 100644 --- a/gfx/thebes/public/gfxBeOSPlatform.h +++ b/gfx/thebes/public/gfxBeOSPlatform.h @@ -47,6 +47,7 @@ class gfxFontconfigUtils; class NS_EXPORT gfxBeOSPlatform : public gfxPlatform { public: gfxBeOSPlatform(); + virtual ~gfxBeOSPlatform(); static gfxBeOSPlatform *GetPlatform() { return (gfxBeOSPlatform*) gfxPlatform::GetPlatform(); diff --git a/gfx/thebes/public/gfxPlatform.h b/gfx/thebes/public/gfxPlatform.h index 89d110978848..16ab6d627421 100644 --- a/gfx/thebes/public/gfxPlatform.h +++ b/gfx/thebes/public/gfxPlatform.h @@ -56,6 +56,11 @@ public: */ static gfxPlatform *GetPlatform(); + /** + * Clean up static objects to shut down thebes. + */ + static void Shutdown(); + /** * Return PR_TRUE if we're to use Glitz for acceleration. */ @@ -119,7 +124,7 @@ public: protected: gfxPlatform() { } - virtual ~gfxPlatform() { } + virtual ~gfxPlatform(); }; diff --git a/gfx/thebes/public/gfxPlatformGtk.h b/gfx/thebes/public/gfxPlatformGtk.h index 523e356934e9..8ff9e4529673 100644 --- a/gfx/thebes/public/gfxPlatformGtk.h +++ b/gfx/thebes/public/gfxPlatformGtk.h @@ -48,6 +48,7 @@ class gfxFontconfigUtils; class THEBES_API gfxPlatformGtk : public gfxPlatform { public: gfxPlatformGtk(); + virtual ~gfxPlatformGtk(); static gfxPlatformGtk *GetPlatform() { return (gfxPlatformGtk*) gfxPlatform::GetPlatform(); diff --git a/gfx/thebes/src/gfxBeOSPlatform.cpp b/gfx/thebes/src/gfxBeOSPlatform.cpp index 305b9493ae8f..4c2929410d96 100644 --- a/gfx/thebes/src/gfxBeOSPlatform.cpp +++ b/gfx/thebes/src/gfxBeOSPlatform.cpp @@ -49,6 +49,20 @@ gfxBeOSPlatform::gfxBeOSPlatform() sFontconfigUtils = gfxFontconfigUtils::GetFontconfigUtils(); } +gfxBeOSPlatform::~gfxBeOSPlatform() +{ + gfxFontconfigUtils::Shutdown(); + sFontconfigUtils = nsnull; + +#if 0 + // It would be nice to do this (although it might need to be after + // the cairo shutdown that happens in ~gfxPlatform). It even looks + // idempotent. But it has fatal assertions that fire if stuff is + // leaked, and we hit them. + FcFini(); +#endif +} + already_AddRefed gfxBeOSPlatform::CreateOffscreenSurface (PRUint32 width, PRUint32 height, diff --git a/gfx/thebes/src/gfxFontconfigUtils.cpp b/gfx/thebes/src/gfxFontconfigUtils.cpp index 0548e2e80093..50f246f1bcdb 100755 --- a/gfx/thebes/src/gfxFontconfigUtils.cpp +++ b/gfx/thebes/src/gfxFontconfigUtils.cpp @@ -47,6 +47,8 @@ #include "nsIAtom.h" #include "nsCRT.h" +/* static */ gfxFontconfigUtils* gfxFontconfigUtils::sUtils = nsnull; + gfxFontconfigUtils::gfxFontconfigUtils() { mAliasTable.Init(50); diff --git a/gfx/thebes/src/gfxFontconfigUtils.h b/gfx/thebes/src/gfxFontconfigUtils.h index 49cf3ef27fc0..f716eed63e66 100755 --- a/gfx/thebes/src/gfxFontconfigUtils.h +++ b/gfx/thebes/src/gfxFontconfigUtils.h @@ -55,12 +55,16 @@ public: gfxFontconfigUtils(); static gfxFontconfigUtils* GetFontconfigUtils() { - static gfxFontconfigUtils* sUtils = nsnull; if (!sUtils) sUtils = new gfxFontconfigUtils(); return sUtils; } + static void Shutdown() { + delete sUtils; + sUtils = nsnull; + } + nsresult GetFontList(const nsACString& aLangGroup, const nsACString& aGenericFamily, nsStringArray& aListOfFonts); @@ -72,6 +76,8 @@ public: void *aClosure, PRBool& aAborted); protected: + static gfxFontconfigUtils* sUtils; + PRInt32 IsExistingFont(const nsACString& aFontName); nsresult GetResolvedFonts(const nsACString& aName, gfxFontNameList* aResult); diff --git a/gfx/thebes/src/gfxPlatform.cpp b/gfx/thebes/src/gfxPlatform.cpp index d40f162d3b52..bc83daf3c662 100644 --- a/gfx/thebes/src/gfxPlatform.cpp +++ b/gfx/thebes/src/gfxPlatform.cpp @@ -59,6 +59,8 @@ #include #endif +#include "cairo.h" + gfxPlatform *gPlatform = nsnull; int gGlitzState = -1; @@ -82,6 +84,22 @@ gfxPlatform::GetPlatform() return gPlatform; } +void +gfxPlatform::Shutdown() +{ + delete gPlatform; + gPlatform = nsnull; +} + +gfxPlatform::~gfxPlatform() +{ + // The cairo folks think we should only clean up in debug builds, + // but we're generally in the habit of trying to shut down as + // cleanly as possible even in production code, so call this + // cairo_debug_* function unconditionally. + cairo_debug_reset_static_data(); +} + PRBool gfxPlatform::UseGlitz() { diff --git a/gfx/thebes/src/gfxPlatformGtk.cpp b/gfx/thebes/src/gfxPlatformGtk.cpp index a2434451b2a3..e20062f4ef52 100644 --- a/gfx/thebes/src/gfxPlatformGtk.cpp +++ b/gfx/thebes/src/gfxPlatformGtk.cpp @@ -86,6 +86,23 @@ gfxPlatformGtk::gfxPlatformGtk() sFontconfigUtils = gfxFontconfigUtils::GetFontconfigUtils(); } +gfxPlatformGtk::~gfxPlatformGtk() +{ + gfxFontconfigUtils::Shutdown(); + sFontconfigUtils = nsnull; +#ifndef THEBES_USE_PANGO_CAIRO + pango_xft_shutdown_display(GDK_DISPLAY(), 0); +#endif + +#if 0 + // It would be nice to do this (although it might need to be after + // the cairo shutdown that happens in ~gfxPlatform). It even looks + // idempotent. But it has fatal assertions that fire if stuff is + // leaked, and we hit them. + FcFini(); +#endif +} + already_AddRefed gfxPlatformGtk::CreateOffscreenSurface(const gfxIntSize& size, gfxASurface::gfxImageFormat imageFormat)