зеркало из https://github.com/mozilla/gecko-dev.git
b=597147 part 19: simplify gfxFcFont/gfxPangoFcFont ownership a little r=jfkthame
--HG-- extra : rebase_source : c7288edd9faefde36543d635c37b8a05d3d18a7b
This commit is contained in:
Родитель
5290b59221
Коммит
83a4e64a8b
|
@ -600,23 +600,16 @@ struct gfxPangoFcFont {
|
|||
PangoCoverage *mCoverage;
|
||||
gfxFcFont *mGfxFont;
|
||||
|
||||
// The gfxPangoFcFont adds a reference to |aGfxFont| and |aFontPattern|.
|
||||
// The caller promises to ensure that |aGfxFont| remains valid until the
|
||||
// new gfxPangoFcFont is destroyed. See PangoFontToggleNotify.
|
||||
//
|
||||
// The gfxPangoFcFont holds a reference to |aFontPattern|.
|
||||
// Providing one of fontconfig's font patterns uses much less memory than
|
||||
// using a fully resolved pattern, because fontconfig's font patterns are
|
||||
// shared and will exist anyway.
|
||||
//
|
||||
// Note that the ownership between this PangoFont and the gfxFcFont is
|
||||
// shared and the gfxFcFont will sometimes remove its reference added
|
||||
// here. See PangoFontToggleNotify.
|
||||
static nsReturnRef<PangoFont>
|
||||
NewFont(gfxFcFont *aGfxFont, FcPattern *aFontPattern);
|
||||
|
||||
// Tell |this| that it no longer needs the gfxFcFont and the caller
|
||||
// assumes ownership of the gfxFcFont reference added at construction of
|
||||
// |this|. The method is called just before the gfxFcFont removes the
|
||||
// last reference to |this|.
|
||||
void ForgetGfxFont() { mGfxFont = nsnull; }
|
||||
|
||||
gfxFcFont *GfxFont() { return mGfxFont; }
|
||||
|
||||
cairo_scaled_font_t *CairoFont()
|
||||
|
@ -641,7 +634,6 @@ gfxPangoFcFont::NewFont(gfxFcFont *aGfxFont, FcPattern *aFontPattern)
|
|||
gfxPangoFcFont *font = static_cast<gfxPangoFcFont*>
|
||||
(g_object_new(GFX_TYPE_PANGO_FC_FONT, "pattern", aFontPattern, NULL));
|
||||
|
||||
NS_ADDREF(aGfxFont);
|
||||
font->mGfxFont = aGfxFont;
|
||||
font->SetFontMap();
|
||||
|
||||
|
@ -704,7 +696,6 @@ gfx_pango_fc_font_finalize(GObject *object)
|
|||
|
||||
if (self->mCoverage)
|
||||
pango_coverage_unref(self->mCoverage);
|
||||
NS_IF_RELEASE(self->mGfxFont);
|
||||
|
||||
G_OBJECT_CLASS(gfx_pango_fc_font_parent_class)->finalize(object);
|
||||
}
|
||||
|
@ -1886,7 +1877,7 @@ gfxFcFont::gfxFcFont(cairo_scaled_font_t *aCairoFont,
|
|||
}
|
||||
|
||||
// The gfxFcFont keeps (only) a toggle_ref on mPangoFont.
|
||||
// While mPangoFont has other references, a reference (from mPangoFont) to the
|
||||
// While mPangoFont has other references, a reference to the
|
||||
// gfxFcFont is held. While mPangoFont has no other references, the reference
|
||||
// to the gfxFcFont is removed.
|
||||
static void
|
||||
|
@ -1907,13 +1898,15 @@ gfxFcFont::MakePangoFont()
|
|||
nsAutoRef<PangoFont> pangoFont(gfxPangoFcFont::NewFont(this, mFontPattern));
|
||||
mPangoFont = pangoFont;
|
||||
g_object_add_toggle_ref(G_OBJECT(mPangoFont), PangoFontToggleNotify, this);
|
||||
// This self-reference gets removed when the normal reference to the
|
||||
// PangoFont is removed as the nsAutoRef goes out of scope.
|
||||
NS_ADDREF(this);
|
||||
}
|
||||
|
||||
gfxFcFont::~gfxFcFont()
|
||||
{
|
||||
cairo_scaled_font_set_user_data(mScaledFont, &sGfxFontKey, NULL, NULL);
|
||||
if (mPangoFont) {
|
||||
GFX_PANGO_FC_FONT(mPangoFont)->ForgetGfxFont();
|
||||
g_object_remove_toggle_ref(G_OBJECT(mPangoFont),
|
||||
PangoFontToggleNotify, this);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче