b=454730 Move shutdown of GTK's fontmap from gfxPlatformGtk to nsAppRunner r=roc sr=bsmedberg
authorKarl Tomlinson <karlt+@karlt.net>
Fri, 26 Sep 2008 10:38:25 +1200
changeset 19744 71004cbe3d8a836e93cfa2d7accb6a7eca823ef7
parent 19743 3e7b639abe750e824dbce2fa9caccc9a39b912c1
child 19745 b3412569801fb11b3cc2f76f86645bc3bae1bb47
push idunknown
push userunknown
push dateunknown
reviewersroc, bsmedberg
bugs454730
milestone1.9.1b1pre
b=454730 Move shutdown of GTK's fontmap from gfxPlatformGtk to nsAppRunner r=roc sr=bsmedberg
config/autoconf.mk.in
config/static-config.mk
configure.in
gfx/thebes/src/Makefile.in
gfx/thebes/src/gfxPangoFonts.cpp
gfx/thebes/test/Makefile.in
toolkit/library/Makefile.in
toolkit/library/libxul-rules.mk
toolkit/xre/nsAppRunner.cpp
--- a/config/autoconf.mk.in
+++ b/config/autoconf.mk.in
@@ -518,18 +518,16 @@ MOZ_DBUS_GLIB_LIBS      = @MOZ_DBUS_GLIB
 MOZ_ENABLE_DBUS         = @MOZ_ENABLE_DBUS@
 
 MOZ_GTHREAD_CFLAGS      = @MOZ_GTHREAD_CFLAGS@
 MOZ_GTHREAD_LIBS        = @MOZ_GTHREAD_LIBS@
 
 FT2_CFLAGS             = @FT2_CFLAGS@
 FT2_LIBS               = @FT2_LIBS@
 
-MOZ_XFT_CFLAGS		= @MOZ_XFT_CFLAGS@
-MOZ_XFT_LIBS		= @MOZ_XFT_LIBS@
 MOZ_PANGO_CFLAGS        = @MOZ_PANGO_CFLAGS@
 MOZ_PANGO_LIBS          = @MOZ_PANGO_LIBS@
 
 MOZ_XIE_LIBS		= @MOZ_XIE_LIBS@
 XT_LIBS			= @XT_LIBS@
 
 GLIB_CFLAGS	= @GLIB_CFLAGS@
 GLIB_LIBS	= @GLIB_LIBS@
--- a/config/static-config.mk
+++ b/config/static-config.mk
@@ -77,17 +77,16 @@ STATIC_EXTRA_LIBS	+= \
 		$(NSS_LIBS) \
 		$(NULL)
 endif
 
 STATIC_EXTRA_LIBS	+= $(MOZ_CAIRO_LIBS)
 
 ifdef MOZ_ENABLE_GTK2
 STATIC_EXTRA_LIBS	+= $(XLDFLAGS) $(XT_LIBS) -lgthread-2.0
-STATIC_EXTRA_LIBS	+= $(MOZ_XFT_LIBS)
 STATIC_EXTRA_LIBS	+= $(MOZ_PANGO_LIBS)
 endif
 
 ifdef MOZ_STORAGE
 STATIC_EXTRA_LIBS	+= $(SQLITE_LIBS)
 endif
 
 ifdef MOZ_ENABLE_STARTUP_NOTIFICATION
--- a/configure.in
+++ b/configure.in
@@ -4999,33 +4999,27 @@ dnl ====================================
 MOZ_PANGO=1
 MOZ_ARG_DISABLE_BOOL(pango,
 [  --disable-pango Disable usage of Pango ],
     MOZ_PANGO=,
     MOZ_PANGO=1)
 
 
 dnl ========================================================
-dnl = Xft and Pango
+dnl = Pango
 dnl ========================================================
 if test "$MOZ_ENABLE_GTK2"
 then
-    if test "$MOZ_X11"; then
-        PKG_CHECK_MODULES(MOZ_XFT, xft)
-        AC_SUBST(MOZ_XFT_CFLAGS)
-        AC_SUBST(MOZ_XFT_LIBS)
-    fi
-
     AC_SUBST(MOZ_PANGO)
 
     PKG_CHECK_MODULES(_PANGOCHK, pango >= $PANGO_VERSION)
 
     if test "$MOZ_PANGO"
     then
-        PKG_CHECK_MODULES(MOZ_PANGO, pango >= $PANGO_VERSION pangocairo >= $PANGO_VERSION pangoft2 >= $PANGO_VERSION)
+        PKG_CHECK_MODULES(MOZ_PANGO, pango >= $PANGO_VERSION pangoft2 >= $PANGO_VERSION)
         AC_SUBST(MOZ_PANGO_CFLAGS)
         AC_SUBST(MOZ_PANGO_LIBS)
         AC_DEFINE(MOZ_PANGO)
     else
         PKG_CHECK_MODULES(MOZ_PANGO, pango >= $PANGO_VERSION pangoft2 >= $PANGO_VERSION)
         AC_SUBST(MOZ_PANGO_CFLAGS)
         AC_SUBST(MOZ_PANGO_LIBS)
 
--- a/gfx/thebes/src/Makefile.in
+++ b/gfx/thebes/src/Makefile.in
@@ -100,40 +100,40 @@ CPPSRCS +=	nsUnicodeRange.cpp
 ifdef MOZ_X11
 CSRCS = cairo-xlib-utils.c
 endif
 
 ifdef MOZ_DFB
 CSRCS = cairo-gdk-utils.c
 endif
 
-EXTRA_DSO_LDOPTS += $(MOZ_PANGO_LIBS) $(ZLIB_LIBS) $(MOZ_XFT_LIBS) $(XLDFLAGS) $(XLIBS)
+EXTRA_DSO_LDOPTS += $(MOZ_PANGO_LIBS) $(ZLIB_LIBS) $(XLDFLAGS) $(XLIBS)
 endif
 
 ifdef MOZ_DFB
 CPPSRCS += gfxDirectFBSurface.cpp
 endif
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),qt)
 CPPSRCS += gfxQtPlatform.cpp gfxQPainterSurface.cpp
 CPPSRCS += gfxXlibSurface.cpp gfxQtNativeRenderer.cpp
 CPPSRCS +=	gfxFT2Fonts.cpp
 CPPSRCS +=	gfxFontconfigUtils.cpp
 CPPSRCS +=	nsUnicodeRange.cpp
 #CSRCS = cairo-xlib-utils.c
-EXTRA_DSO_LDOPTS += $(ZLIB_LIBS) $(MOZ_XFT_LIBS) $(XLDFLAGS) $(XLIBS) $(CAIRO_FT_LIBS)
+EXTRA_DSO_LDOPTS += $(ZLIB_LIBS) $(XLDFLAGS) $(XLIBS) $(CAIRO_FT_LIBS)
 endif
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),beos)
 CPPSRCS	+= 	gfxBeOSSurface.cpp gfxBeOSPlatform.cpp
 CPPSRCS +=	gfxPangoFonts.cpp 
 #CPPSRCS +=	gfxPDFSurface.cpp
 CPPSRCS +=	gfxFontconfigUtils.cpp
 CPPSRCS +=	nsUnicodeRange.cpp
-EXTRA_DSO_LDOPTS += $(MOZ_PANGO_LIBS) $(CAIRO_FT_LIBS) -lfontconfig -lpangocairo-1.0
+EXTRA_DSO_LDOPTS += $(MOZ_PANGO_LIBS) $(CAIRO_FT_LIBS) -lfontconfig
 endif
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
 CPPSRCS	+= \
 	gfxQuartzSurface.cpp \
 	gfxQuartzImageSurface.cpp \
 	gfxQuartzPDFSurface.cpp \
 	gfxPlatformMac.cpp \
--- a/gfx/thebes/src/gfxPangoFonts.cpp
+++ b/gfx/thebes/src/gfxPangoFonts.cpp
@@ -603,25 +603,16 @@ gfxPangoFont::~gfxPangoFont()
     if (mCairoFont)
         cairo_scaled_font_destroy(mCairoFont);
 }
 
 /* static */ void
 gfxPangoFont::Shutdown()
 {
     gfxPangoFontCache::Shutdown();
-
-    // This just cleans up memory used by Pango's caches and may cause an
-    // assert and crash in cairo (Bug 399556), so only do this when we care
-    // about cleaning up memory on shutdown.
-#if defined(DEBUG) || defined(NS_BUILD_REFCNT_LOGGING) || defined(NS_TRACE_MALLOC)
-    PangoFontMap *fontmap = pango_cairo_font_map_get_default ();
-    if (PANGO_IS_FC_FONT_MAP (fontmap))
-        pango_fc_font_map_shutdown (PANGO_FC_FONT_MAP (fontmap));
-#endif
 }
 
 static PangoStyle
 ThebesStyleToPangoStyle (const gfxFontStyle *fs)
 {
     if (fs->style == FONT_STYLE_ITALIC)
         return PANGO_STYLE_ITALIC;
     if (fs->style == FONT_STYLE_OBLIQUE)
--- a/gfx/thebes/test/Makefile.in
+++ b/gfx/thebes/test/Makefile.in
@@ -92,14 +92,14 @@ ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
 OS_LIBS += $(call EXPAND_LIBNAME,$(_OS_LIBS))
 endif
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
 OS_LIBS += -framework Cocoa
 endif
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)
-OS_LIBS += $(MOZ_PANGO_LIBS) $(MOZ_XFT_LIBS) $(XLIBS)
+OS_LIBS += $(MOZ_PANGO_LIBS) $(XLIBS)
 CXXFLAGS += $(MOZ_PANGO_CFLAGS)
 endif
 
 CXXFLAGS += $(MOZ_CAIRO_CFLAGS) $(TK_CFLAGS)
 CFLAGS += $(MOZ_CAIRO_CFLAGS) $(TK_CFLAGS)
--- a/toolkit/library/Makefile.in
+++ b/toolkit/library/Makefile.in
@@ -223,22 +223,22 @@ ifdef NS_OSSO
 EXTRA_DSO_LDOPTS += $(LIBOSSO_LIBS)
 endif
 
 ifdef MOZ_ENABLE_DBUS
 EXTRA_DSO_LDOPTS += $(MOZ_DBUS_GLIB_LIBS)
 endif
 
 ifeq (gtk2,$(MOZ_WIDGET_TOOLKIT))
-EXTRA_DSO_LDOPTS += $(XLDFLAGS) $(XLIBS) $(MOZ_XFT_LIBS) $(MOZ_GTK2_LIBS) $(XT_LIBS) -lgthread-2.0
+EXTRA_DSO_LDOPTS += $(XLDFLAGS) $(XLIBS) $(MOZ_PANGO_LIBS) $(MOZ_GTK2_LIBS) $(XT_LIBS) -lgthread-2.0
 EXTRA_DSO_LDOPTS += $(FT2_LIBS)
 endif
 
 ifeq (qt,$(MOZ_WIDGET_TOOLKIT))
-EXTRA_DSO_LDOPTS += $(XLDFLAGS) $(XLIBS) $(MOZ_XFT_LIBS) $(XT_LIBS) $(MOZ_QT_LIBS) -lgthread-2.0
+EXTRA_DSO_LDOPTS += $(XLDFLAGS) $(XLIBS) $(XT_LIBS) $(MOZ_QT_LIBS) -lgthread-2.0
 EXTRA_DSO_LDOPTS += $(FT2_LIBS)
 endif
 
 EXTRA_DSO_LDOPTS += $(MOZ_LOCATION_LIBS)
 
 ifdef MOZ_ENABLE_STARTUP_NOTIFICATION
 EXTRA_DSO_LDOPTS += $(MOZ_STARTUP_NOTIFICATION_LIBS)
 endif
--- a/toolkit/library/libxul-rules.mk
+++ b/toolkit/library/libxul-rules.mk
@@ -81,18 +81,14 @@ endif
 endif
 ifneq (,$(filter $(MOZ_WIDGET_TOOLKIT),mac cocoa))
 EXTRA_DSO_LDOPTS += -lcups
 ifdef MOZ_ENABLE_GLITZ
 EXTRA_DSO_LDOPTS += -lmozglitzagl -framework OpenGL -framework AGL
 endif
 endif
 
-ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)
-EXTRA_DSO_LDOPTS += $(MOZ_PANGO_LIBS)
-endif
-
 export:: dlldeps.cpp
 
 dlldeps.cpp: $(topsrcdir)/xpcom/build/dlldeps.cpp
 	$(INSTALL) $^ .
 
 GARBAGE += dlldeps.cpp
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -268,16 +268,22 @@ char **gArgv;
 
 static char gToolkitVersion[20];
 static char gToolkitBuildID[40];
 
 static int    gRestartArgc;
 static char **gRestartArgv;
 
 #if defined(MOZ_WIDGET_GTK2)
+#if defined(DEBUG) || defined(NS_BUILD_REFCNT_LOGGING) \
+  || defined(NS_TRACE_MALLOC)
+#define CLEANUP_MEMORY 1
+#define PANGO_ENABLE_BACKEND
+#include <pango/pangofc-fontmap.h>
+#endif
 #include <gtk/gtk.h>
 #ifdef MOZ_X11
 #include <gdk/gdkx.h>
 #endif /* MOZ_X11 */
 #include "nsGTKToolkit.h"
 #endif
 
 // Save the given word to the specified environment variable.
@@ -2419,22 +2425,52 @@ static void MOZ_gdk_display_close(GdkDis
     Display* dpy = GDK_DISPLAY_XDISPLAY(display);
     if (!theme_is_qt)
       XCloseDisplay(dpy);
 #else
     gdk_display_close(display);
 #endif /* MOZ_X11 */
   }
   else {
+#if CLEANUP_MEMORY
+    // Get a (new) Pango context that holds a reference to the fontmap that
+    // GTK has been using.  gdk_pango_context_get() must be called while GTK
+    // has a default display.
+    PangoContext *pangoContext = gdk_pango_context_get();
+#endif
+
     if (!theme_is_qt)
       gdk_display_close(display);
-#if GTK_CHECK_VERSION(2,8,0) && \
-  (defined(DEBUG) || defined(NS_BUILD_REFCNT_LOGGING) || defined(NS_TRACE_MALLOC))
+
+#if CLEANUP_MEMORY
+    // This doesn't take a reference.
+    PangoFontMap *fontmap = pango_context_get_font_map(pangoContext);
+    // Do some shutdown of the fontmap, which releases the fonts, clearing a
+    // bunch of circular references from the fontmap through the fonts back to
+    // itself.  The shutdown that this does is much less than what's done by
+    // the fontmap's finalize, though.
+    if (PANGO_IS_FC_FONT_MAP(fontmap))
+        pango_fc_font_map_shutdown(PANGO_FC_FONT_MAP(fontmap));
+    g_object_unref(pangoContext);
+    // PangoCairo still holds a reference to the fontmap.
+    // Now that we have finished with GTK and Pango, we could unref fontmap,
+    // which would allow us to call FcFini, but removing what is really
+    // Pango's ref feels a bit evil.  Pango-1.22 will have support for
+    // pango_cairo_font_map_set_default(NULL), which would release the
+    // reference on the old fontmap.
+
+#if GTK_CHECK_VERSION(2,8,0)
+    // cairo_debug_reset_static_data() is prototyped through cairo.h included
+    // by gtk.h.
+#ifdef cairo_debug_reset_static_data
+#error "Looks like we're including Mozilla's cairo instead of system cairo"
+#endif
     cairo_debug_reset_static_data();
-#endif
+#endif // 2.8.0
+#endif // CLEANUP_MEMORY
   }
 }
 #endif // MOZ_WIDGET_GTK2
 
 /** 
  * NSPR will search for the "nspr_use_zone_allocator" symbol throughout
  * the process and use it to determine whether the application defines its own
  * memory allocator or not.