diff --git a/gfx/thebes/gfxFcPlatformFontList.cpp b/gfx/thebes/gfxFcPlatformFontList.cpp index 5ff63baeaf87..8f900b7ceb1c 100644 --- a/gfx/thebes/gfxFcPlatformFontList.cpp +++ b/gfx/thebes/gfxFcPlatformFontList.cpp @@ -70,18 +70,6 @@ using namespace mozilla::unicode; #define LOG_CMAPDATA_ENABLED() \ MOZ_LOG_TEST(gfxPlatform::GetLog(eGfxLog_cmapdata), LogLevel::Debug) -template <> -class nsAutoRefTraits : public nsPointerRefTraits { - public: - static void Release(FcFontSet* ptr) { FcFontSetDestroy(ptr); } -}; - -template <> -class nsAutoRefTraits : public nsPointerRefTraits { - public: - static void Release(FcObjectSet* ptr) { FcObjectSetDestroy(ptr); } -}; - static const FcChar8* ToFcChar8Ptr(const char* aStr) { return reinterpret_cast(aStr); } @@ -258,7 +246,7 @@ gfxFontEntry* gfxFontconfigFontEntry::Clone() const { return new gfxFontconfigFontEntry(Name(), mFontPattern, mIgnoreFcCharmap); } -static FcPattern* CreatePatternForFace(FT_Face aFace) { +static already_AddRefed CreatePatternForFace(FT_Face aFace) { // Use fontconfig to fill out the pattern from the FTFace. // The "file" argument cannot be nullptr (in fontconfig-2.6.0 at // least). The dummy file passed here is removed below. @@ -269,10 +257,11 @@ static FcPattern* CreatePatternForFace(FT_Face aFace) { // "blanks", effectively assuming that, if the font has a blank glyph, // then the author intends any associated character to be rendered // blank. - FcPattern* pattern = FcFreeTypeQueryFace(aFace, ToFcChar8Ptr(""), 0, nullptr); + RefPtr pattern = + dont_AddRef(FcFreeTypeQueryFace(aFace, ToFcChar8Ptr(""), 0, nullptr)); // given that we have a FT_Face, not really sure this is possible... if (!pattern) { - pattern = FcPatternCreate(); + pattern = dont_AddRef(FcPatternCreate()); } FcPatternDel(pattern, FC_FILE); FcPatternDel(pattern, FC_INDEX); @@ -281,7 +270,7 @@ static FcPattern* CreatePatternForFace(FT_Face aFace) { // that when creating a cairo font face. FcPatternAddFTFace(pattern, FC_FT_FACE, aFace); - return pattern; + return pattern.forget(); } static already_AddRefed CreateFaceForPattern( @@ -790,7 +779,7 @@ static double ChooseFontSize(gfxFontconfigFontEntry* aEntry, gfxFont* gfxFontconfigFontEntry::CreateFontInstance( const gfxFontStyle* aFontStyle) { - nsAutoRef pattern(FcPatternCreate()); + RefPtr pattern = dont_AddRef(FcPatternCreate()); if (!pattern) { NS_WARNING("Failed to create Fontconfig pattern for font instance"); return nullptr; @@ -825,8 +814,8 @@ gfxFont* gfxFontconfigFontEntry::CreateFontInstance( } PreparePattern(pattern, aFontStyle->printerFont); - nsAutoRef renderPattern( - FcFontRenderPrepare(nullptr, pattern, mFontPattern)); + RefPtr renderPattern = + dont_AddRef(FcFontRenderPrepare(nullptr, pattern, mFontPattern)); if (!renderPattern) { NS_WARNING("Failed to prepare Fontconfig pattern for font instance"); return nullptr; @@ -1061,8 +1050,7 @@ void gfxFontconfigFontFamily::AddFontPattern(FcPattern* aFontPattern) { } } - nsCountedRef pattern(aFontPattern); - mFontPatterns.AppendElement(pattern); + mFontPatterns.AppendElement(aFontPattern); } static const double kRejectDistance = 10000.0; @@ -1801,12 +1789,12 @@ static void GetSystemFontList(nsTArray& aListOfFonts, nsAtom* aLangGroup) { aListOfFonts.Clear(); - nsAutoRef pat(FcPatternCreate()); + RefPtr pat = dont_AddRef(FcPatternCreate()); if (!pat) { return; } - nsAutoRef os(FcObjectSetBuild(FC_FAMILY, nullptr)); + UniquePtr os(FcObjectSetBuild(FC_FAMILY, nullptr)); if (!os) { return; } @@ -1820,7 +1808,7 @@ static void GetSystemFontList(nsTArray& aListOfFonts, FcPatternAddString(pat, FC_LANG, ToFcChar8Ptr(fcLang.get())); } - nsAutoRef fs(FcFontList(nullptr, pat, os)); + UniquePtr fs(FcFontList(nullptr, pat, os.get())); if (!fs) { return; } @@ -1987,13 +1975,13 @@ bool gfxFcPlatformFontList::FindAndAddFamilies( // It wasn't in the cache, so we need to ask fontconfig... const FcChar8* kSentinelName = ToFcChar8Ptr("-moz-sentinel"); FcChar8* sentinelFirstFamily = nullptr; - nsAutoRef sentinelSubst(FcPatternCreate()); + RefPtr sentinelSubst = dont_AddRef(FcPatternCreate()); FcPatternAddString(sentinelSubst, FC_FAMILY, kSentinelName); FcConfigSubstitute(nullptr, sentinelSubst, FcMatchPattern); FcPatternGetString(sentinelSubst, FC_FAMILY, 0, &sentinelFirstFamily); // substitutions for font, -moz-sentinel pattern - nsAutoRef fontWithSentinel(FcPatternCreate()); + RefPtr fontWithSentinel = dont_AddRef(FcPatternCreate()); FcPatternAddString(fontWithSentinel, FC_FAMILY, ToFcChar8Ptr(familyName.get())); FcPatternAddString(fontWithSentinel, FC_FAMILY, kSentinelName); @@ -2036,12 +2024,12 @@ bool gfxFcPlatformFontList::GetStandardFamilyName(const nsCString& aFontName, return true; } - nsAutoRef pat(FcPatternCreate()); + RefPtr pat = dont_AddRef(FcPatternCreate()); if (!pat) { return true; } - nsAutoRef os(FcObjectSetBuild(FC_FAMILY, nullptr)); + UniquePtr os(FcObjectSetBuild(FC_FAMILY, nullptr)); if (!os) { return true; } @@ -2049,7 +2037,7 @@ bool gfxFcPlatformFontList::GetStandardFamilyName(const nsCString& aFontName, // add the family name to the pattern FcPatternAddString(pat, FC_FAMILY, ToFcChar8Ptr(aFontName.get())); - nsAutoRef givenFS(FcFontList(nullptr, pat, os)); + UniquePtr givenFS(FcFontList(nullptr, pat, os.get())); if (!givenFS) { return true; } @@ -2088,7 +2076,7 @@ bool gfxFcPlatformFontList::GetStandardFamilyName(const nsCString& aFontName, FcPatternDel(pat, FC_FAMILY); FcPatternAddString(pat, FC_FAMILY, (FcChar8*)candidates[j].get()); - nsAutoRef candidateFS(FcFontList(nullptr, pat, os)); + UniquePtr candidateFS(FcFontList(nullptr, pat, os.get())); if (!candidateFS) { return true; } @@ -2198,7 +2186,7 @@ gfxPlatformFontList::PrefFontList* gfxFcPlatformFontList::FindGenericFamilies( } // if not found, ask fontconfig to pick the appropriate font - nsAutoRef genericPattern(FcPatternCreate()); + RefPtr genericPattern = dont_AddRef(FcPatternCreate()); FcPatternAddString(genericPattern, FC_FAMILY, ToFcChar8Ptr(aGeneric.get())); // -- prefer scalable fonts @@ -2215,7 +2203,7 @@ gfxPlatformFontList::PrefFontList* gfxFcPlatformFontList::FindGenericFamilies( // -- sort to get the closest matches FcResult result; - nsAutoRef faces( + UniquePtr faces( FcFontSort(nullptr, genericPattern, FcFalse, nullptr, &result)); if (!faces) { diff --git a/gfx/thebes/gfxFcPlatformFontList.h b/gfx/thebes/gfxFcPlatformFontList.h index c8dd8e5e3a2d..a922a5ca8010 100644 --- a/gfx/thebes/gfxFcPlatformFontList.h +++ b/gfx/thebes/gfxFcPlatformFontList.h @@ -10,7 +10,8 @@ #include "gfxPlatformFontList.h" #include "mozilla/FontPropertyTypes.h" #include "mozilla/mozalloc.h" -#include "nsAutoRef.h" +#include "mozilla/RefPtr.h" +#include "mozilla/UniquePtr.h" #include "nsClassHashtable.h" #include @@ -27,22 +28,35 @@ namespace mozilla { namespace dom { class SystemFontListEntry; }; -}; // namespace mozilla template <> -class nsAutoRefTraits : public nsPointerRefTraits { +class RefPtrTraits { public: static void Release(FcPattern* ptr) { FcPatternDestroy(ptr); } static void AddRef(FcPattern* ptr) { FcPatternReference(ptr); } }; template <> -class nsAutoRefTraits : public nsPointerRefTraits { +class RefPtrTraits { public: static void Release(FcConfig* ptr) { FcConfigDestroy(ptr); } static void AddRef(FcConfig* ptr) { FcConfigReference(ptr); } }; +template <> +class DefaultDelete { + public: + void operator()(FcFontSet* aPtr) { FcFontSetDestroy(aPtr); } +}; + +template <> +class DefaultDelete { + public: + void operator()(FcObjectSet* aPtr) { FcObjectSetDestroy(aPtr); } +}; + +}; // namespace mozilla + // The names for the font entry and font classes should really // the common 'Fc' abbreviation but the gfxPangoFontGroup code already // defines versions of these, so use the verbose name for now. @@ -100,7 +114,7 @@ class gfxFontconfigFontEntry final : public gfxFT2FontEntryBase { nsTArray& aBuffer) override; // pattern for a single face of a family - nsCountedRef mFontPattern; + RefPtr mFontPattern; // FTFace - initialized when needed RefPtr mFTFace; @@ -185,7 +199,7 @@ class gfxFontconfigFontFamily final : public gfxFontFamily { // helper for FilterForFontList bool SupportsLangGroup(nsAtom* aLangGroup) const; - nsTArray> mFontPatterns; + nsTArray> mFontPatterns; bool mContainsAppFonts; bool mHasNonScalableFaces; @@ -211,7 +225,7 @@ class gfxFontconfigFont final : public gfxFT2FontBase { private: virtual ~gfxFontconfigFont(); - nsCountedRef mPattern; + RefPtr mPattern; }; class gfxFcPlatformFontList final : public gfxPlatformFontList { @@ -336,8 +350,7 @@ class gfxFcPlatformFontList final : public gfxPlatformFontList { // to avoid enumerating all fonts, maintain a mapping of local font // names to family - nsBaseHashtable, FcPattern*> - mLocalNames; + nsBaseHashtable, FcPattern*> mLocalNames; // caching generic/lang ==> font family list nsClassHashtable mGenericMappings; @@ -352,7 +365,7 @@ class gfxFcPlatformFontList final : public gfxPlatformFontList { mFcSubstituteCache; nsCOMPtr mCheckFontUpdatesTimer; - nsCountedRef mLastConfig; + RefPtr mLastConfig; // By default, font prefs under Linux are set to simply lookup // via fontconfig the appropriate font for serif/sans-serif/monospace.