Bug 1525549 - Use SkTypefaceCache::FindByProcAndRef to associate typefaces with fontconfig fonts. r=rhunt, a=RyanVM
authorLee Salzman <lsalzman@mozilla.com>
Tue, 19 Feb 2019 15:08:03 -0500
changeset 516069 9013f0783507f41ec8276bdbb57a45926291075f
parent 516068 aa260d1ecdab207071ecfe87e10d783029c5b4b0
child 516070 e0a8013cd9c9723b19427ca24e7202e37822e3ad
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrhunt, RyanVM
bugs1525549
milestone66.0
Bug 1525549 - Use SkTypefaceCache::FindByProcAndRef to associate typefaces with fontconfig fonts. r=rhunt, a=RyanVM
gfx/skia/skia/src/ports/SkFontHost_cairo.cpp
--- a/gfx/skia/skia/src/ports/SkFontHost_cairo.cpp
+++ b/gfx/skia/skia/src/ports/SkFontHost_cairo.cpp
@@ -53,18 +53,16 @@ typedef enum FT_LcdFilter_
 #if SK_CAN_USE_DLOPEN
 #include <dlfcn.h>
 #endif
 
 #ifndef SK_FONTHOST_CAIRO_STANDALONE
 #define SK_FONTHOST_CAIRO_STANDALONE 1
 #endif
 
-static cairo_user_data_key_t kSkTypefaceKey;
-
 static bool gFontHintingEnabled = true;
 static FT_Error (*gSetLcdFilter)(FT_Library, FT_LcdFilter) = nullptr;
 static void (*gGlyphSlotEmbolden)(FT_GlyphSlot) = nullptr;
 
 extern "C"
 {
     void mozilla_LockFTLibrary(FT_Library aLibrary);
     void mozilla_UnlockFTLibrary(FT_Library aLibrary);
@@ -254,51 +252,53 @@ public:
         return 0;
     }
 
     SkCairoFTTypeface(cairo_font_face_t* fontFace, FcPattern* pattern)
         : SkTypeface(SkFontStyle::Normal())
         , fFontFace(fontFace)
         , fPattern(pattern)
     {
-        cairo_font_face_set_user_data(fFontFace, &kSkTypefaceKey, this, nullptr);
         cairo_font_face_reference(fFontFace);
 #ifdef CAIRO_HAS_FC_FONT
         if (fPattern) {
             FcPatternReference(fPattern);
         }
 #endif
     }
 
+    cairo_font_face_t* GetCairoFontFace() const { return fFontFace; }
+
 private:
     ~SkCairoFTTypeface()
     {
-        cairo_font_face_set_user_data(fFontFace, &kSkTypefaceKey, nullptr, nullptr);
         cairo_font_face_destroy(fFontFace);
 #ifdef CAIRO_HAS_FC_FONT
         if (fPattern) {
             FcPatternDestroy(fPattern);
         }
 #endif
     }
 
     cairo_font_face_t* fFontFace;
     FcPattern* fPattern;
 };
 
+static bool FindByCairoFontFace(SkTypeface* typeface, void* context) {
+    return static_cast<SkCairoFTTypeface*>(typeface)->GetCairoFontFace() == static_cast<cairo_font_face_t*>(context);
+}
+
 SkTypeface* SkCreateTypefaceFromCairoFTFontWithFontconfig(cairo_scaled_font_t* scaledFont, FcPattern* pattern)
 {
     cairo_font_face_t* fontFace = cairo_scaled_font_get_font_face(scaledFont);
     SkASSERT(cairo_font_face_status(fontFace) == CAIRO_STATUS_SUCCESS);
     SkASSERT(cairo_font_face_get_type(fontFace) == CAIRO_FONT_TYPE_FT);
 
-    SkTypeface* typeface = reinterpret_cast<SkTypeface*>(cairo_font_face_get_user_data(fontFace, &kSkTypefaceKey));
-    if (typeface) {
-        typeface->ref();
-    } else {
+    SkTypeface* typeface = SkTypefaceCache::FindByProcAndRef(FindByCairoFontFace, fontFace);
+    if (!typeface) {
         typeface = new SkCairoFTTypeface(fontFace, pattern);
         SkTypefaceCache::Add(typeface);
     }
 
     return typeface;
 }
 
 SkTypeface* SkCreateTypefaceFromCairoFTFont(cairo_scaled_font_t* scaledFont)