From a1f89017f4c5a8c68502fd8555f468f704e15161 Mon Sep 17 00:00:00 2001 From: Karl Tomlinson Date: Fri, 26 Sep 2008 10:38:25 +1200 Subject: [PATCH] b=454730 Move shutdown of GTK's fontmap from gfxPlatformGtk to nsAppRunner r=roc sr=bsmedberg --- config/autoconf.mk.in | 2 -- config/static-config.mk | 1 - configure.in | 10 ++------ gfx/thebes/src/Makefile.in | 6 ++--- gfx/thebes/src/gfxPangoFonts.cpp | 9 ------- gfx/thebes/test/Makefile.in | 2 +- toolkit/library/Makefile.in | 4 +-- toolkit/library/libxul-rules.mk | 4 --- toolkit/xre/nsAppRunner.cpp | 42 +++++++++++++++++++++++++++++--- 9 files changed, 47 insertions(+), 33 deletions(-) diff --git a/config/autoconf.mk.in b/config/autoconf.mk.in index 93cba5dda9f..a255266a020 100644 --- a/config/autoconf.mk.in +++ b/config/autoconf.mk.in @@ -523,8 +523,6 @@ 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@ diff --git a/config/static-config.mk b/config/static-config.mk index 04d10402389..e54feabd832 100644 --- a/config/static-config.mk +++ b/config/static-config.mk @@ -82,7 +82,6 @@ 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 diff --git a/configure.in b/configure.in index 6b1bf2d6b58..9ee2ede9f7f 100644 --- a/configure.in +++ b/configure.in @@ -5004,23 +5004,17 @@ MOZ_ARG_DISABLE_BOOL(pango, 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) diff --git a/gfx/thebes/src/Makefile.in b/gfx/thebes/src/Makefile.in index 120d1256383..0c2ef3a4ba5 100644 --- a/gfx/thebes/src/Makefile.in +++ b/gfx/thebes/src/Makefile.in @@ -105,7 +105,7 @@ 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 @@ -119,7 +119,7 @@ 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) @@ -128,7 +128,7 @@ 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) diff --git a/gfx/thebes/src/gfxPangoFonts.cpp b/gfx/thebes/src/gfxPangoFonts.cpp index 89de87720cf..773e703757f 100644 --- a/gfx/thebes/src/gfxPangoFonts.cpp +++ b/gfx/thebes/src/gfxPangoFonts.cpp @@ -608,15 +608,6 @@ gfxPangoFont::~gfxPangoFont() 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 diff --git a/gfx/thebes/test/Makefile.in b/gfx/thebes/test/Makefile.in index a89e7c8a37d..926956b4fa8 100644 --- a/gfx/thebes/test/Makefile.in +++ b/gfx/thebes/test/Makefile.in @@ -97,7 +97,7 @@ 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 diff --git a/toolkit/library/Makefile.in b/toolkit/library/Makefile.in index 50e2b65ec82..748816b5924 100644 --- a/toolkit/library/Makefile.in +++ b/toolkit/library/Makefile.in @@ -228,12 +228,12 @@ 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 diff --git a/toolkit/library/libxul-rules.mk b/toolkit/library/libxul-rules.mk index 401afd80267..55a324bacdb 100644 --- a/toolkit/library/libxul-rules.mk +++ b/toolkit/library/libxul-rules.mk @@ -86,10 +86,6 @@ 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 diff --git a/toolkit/xre/nsAppRunner.cpp b/toolkit/xre/nsAppRunner.cpp index 1e8941ed233..3a9413259e5 100644 --- a/toolkit/xre/nsAppRunner.cpp +++ b/toolkit/xre/nsAppRunner.cpp @@ -273,6 +273,12 @@ 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 +#endif #include #ifdef MOZ_X11 #include @@ -2424,12 +2430,42 @@ static void MOZ_gdk_display_close(GdkDisplay *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)) - cairo_debug_reset_static_data(); + +#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 // 2.8.0 +#endif // CLEANUP_MEMORY } } #endif // MOZ_WIDGET_GTK2