Bug 1309205 - part 1 - allow querying FT_Library from gfxPlatform so that Moz2d Factory can use it. r=jfkthame
authorLee Salzman <lsalzman@mozilla.com>
Wed, 04 Jan 2017 14:00:17 -0500
changeset 327973 5c25a123203a599f20d48840910bccf3ef707027
parent 327972 3e3b75439ccaf3c0b661e2ce5d3af797a2734501
child 327974 2797f193a147a4a09d508ae2e7417cd83e657ebd
push id31160
push userphilringnalda@gmail.com
push dateThu, 05 Jan 2017 02:33:44 +0000
treeherdermozilla-central@f13abb8ba9f3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame
bugs1309205
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1309205 - part 1 - allow querying FT_Library from gfxPlatform so that Moz2d Factory can use it. r=jfkthame MozReview-Commit-ID: 7kxseOOVvWi
gfx/2d/2D.h
gfx/2d/Factory.cpp
gfx/thebes/gfxAndroidPlatform.h
gfx/thebes/gfxFT2FontList.cpp
gfx/thebes/gfxFontconfigFonts.h
gfx/thebes/gfxPlatform.cpp
gfx/thebes/gfxPlatform.h
gfx/thebes/gfxPlatformGtk.cpp
gfx/thebes/gfxPlatformGtk.h
--- a/gfx/2d/2D.h
+++ b/gfx/2d/2D.h
@@ -37,16 +37,19 @@ struct _cairo_surface;
 typedef _cairo_surface cairo_surface_t;
 
 struct _cairo_scaled_font;
 typedef _cairo_scaled_font cairo_scaled_font_t;
 
 struct _FcPattern;
 typedef _FcPattern FcPattern;
 
+struct FT_LibraryRec_;
+typedef FT_LibraryRec_* FT_Library;
+
 struct ID3D11Texture2D;
 struct ID3D11Device;
 struct ID2D1Device;
 struct IDWriteFactory;
 struct IDWriteRenderingParams;
 struct IDWriteFontFace;
 
 class GrContext;
@@ -1489,16 +1492,25 @@ public:
   static already_AddRefed<DrawTarget> CreateDrawTargetWithSkCanvas(SkCanvas* aCanvas);
 #endif
 
 #ifdef XP_DARWIN
   static already_AddRefed<GlyphRenderingOptions>
     CreateCGGlyphRenderingOptions(const Color &aFontSmoothingBackgroundColor);
 #endif
 
+#ifdef MOZ_ENABLE_FREETYPE
+  static void SetFTLibrary(FT_Library aFTLibrary);
+  static FT_Library GetFTLibrary();
+
+private:
+  static FT_Library mFTLibrary;
+public:
+#endif
+
 #ifdef WIN32
   static already_AddRefed<DrawTarget> CreateDrawTargetForD3D11Texture(ID3D11Texture2D *aTexture, SurfaceFormat aFormat);
 
   /*
    * Attempts to create and install a D2D1 device from the supplied Direct3D11 device.
    * Returns true on success, or false on failure and leaves the D2D1/Direct3D11 devices unset.
    */
   static bool SetDirect3D11Device(ID3D11Device *aDevice);
--- a/gfx/2d/Factory.cpp
+++ b/gfx/2d/Factory.cpp
@@ -151,16 +151,20 @@ HasCPUIDBit(unsigned int level, CPUIDReg
 #endif
 
 namespace mozilla {
 namespace gfx {
 
 // In Gecko, this value is managed by gfx.logging.level in gfxPrefs.
 int32_t LoggingPrefs::sGfxLogLevel = LOG_DEFAULT;
 
+#ifdef MOZ_ENABLE_FREETYPE
+FT_Library Factory::mFTLibrary = nullptr;
+#endif
+
 #ifdef WIN32
 ID3D11Device *Factory::mD3D11Device = nullptr;
 ID2D1Device *Factory::mD2D1Device = nullptr;
 IDWriteFactory *Factory::mDWriteFactory = nullptr;
 #endif
 
 DrawEventRecorder *Factory::mRecorder;
 
@@ -187,16 +191,22 @@ Factory::Init(const Config& aConfig)
 void
 Factory::ShutDown()
 {
   if (sConfig) {
     delete sConfig->mLogForwarder;
     delete sConfig;
     sConfig = nullptr;
   }
+
+#ifdef MOZ_ENABLE_FREETYPE
+  if (mFTLibrary) {
+    mFTLibrary = nullptr;
+  }
+#endif
 }
 
 bool
 Factory::HasSSE2()
 {
 #if defined(__SSE2__) || defined(_M_X64) || \
     (defined(_M_IX86_FP) && _M_IX86_FP >= 2)
   // gcc with -msse2 (default on OSX and x86-64)
@@ -564,16 +574,31 @@ Factory::CreateDualDrawTarget(DrawTarget
   if (mRecorder) {
     retVal = new DrawTargetRecording(mRecorder, retVal);
   }
 
   return retVal.forget();
 }
 
 
+#ifdef MOZ_ENABLE_FREETYPE
+void
+Factory::SetFTLibrary(FT_Library aFTLibrary)
+{
+  mFTLibrary = aFTLibrary;
+}
+
+FT_Library
+Factory::GetFTLibrary()
+{
+  MOZ_ASSERT(mFTLibrary);
+  return mFTLibrary;
+}
+#endif
+
 #ifdef WIN32
 already_AddRefed<DrawTarget>
 Factory::CreateDrawTargetForD3D11Texture(ID3D11Texture2D *aTexture, SurfaceFormat aFormat)
 {
   MOZ_ASSERT(aTexture);
 
   RefPtr<DrawTargetD2D1> newTarget;
 
--- a/gfx/thebes/gfxAndroidPlatform.h
+++ b/gfx/thebes/gfxAndroidPlatform.h
@@ -14,18 +14,16 @@
 
 namespace mozilla {
     namespace dom {
         class FontListEntry;
     };
 };
 using mozilla::dom::FontListEntry;
 
-typedef struct FT_LibraryRec_ *FT_Library;
-
 class gfxAndroidPlatform : public gfxPlatform {
 public:
     gfxAndroidPlatform();
     virtual ~gfxAndroidPlatform();
 
     static gfxAndroidPlatform *GetPlatform() {
         return (gfxAndroidPlatform*) gfxPlatform::GetPlatform();
     }
@@ -55,17 +53,17 @@ public:
                     const gfxFontStyle *aStyle,
                     gfxTextPerfMetrics* aTextPerf,
                     gfxUserFontSet *aUserFontSet,
                     gfxFloat aDevToCssSize) override;
 
     virtual bool FontHintingEnabled() override;
     virtual bool RequiresLinearZoom() override;
 
-    FT_Library GetFTLibrary();
+    FT_Library GetFTLibrary() override;
 
     virtual bool CanRenderContentToDataSurface() const override {
       return true;
     }
 
     virtual already_AddRefed<mozilla::gfx::VsyncSource> CreateHardwareVsyncSource() override;
 
     virtual bool SupportsApzTouchInput() const override {
--- a/gfx/thebes/gfxFT2FontList.cpp
+++ b/gfx/thebes/gfxFT2FontList.cpp
@@ -8,17 +8,16 @@
 #include "mozilla/MemoryReporting.h"
 
 #include "mozilla/dom/ContentChild.h"
 #include "gfxAndroidPlatform.h"
 #include "mozilla/Omnijar.h"
 #include "mozilla/UniquePtr.h"
 #include "mozilla/UniquePtrExtensions.h"
 #include "nsIInputStream.h"
-#define gfxToolkitPlatform gfxAndroidPlatform
 
 #include "nsXULAppAPI.h"
 #include <dirent.h>
 #include <android/log.h>
 #define ALOG(args...)  __android_log_print(ANDROID_LOG_INFO, "Gecko" , ## args)
 
 #include "ft2build.h"
 #include FT_FREETYPE_H
@@ -80,17 +79,18 @@ public:
     {
         if (aFontEntry->mFTFace) {
             mFace = aFontEntry->mFTFace;
             return;
         }
 
         NS_ASSERTION(!aFontEntry->mFilename.IsEmpty(),
                      "can't use AutoFTFace for fonts without a filename");
-        FT_Library ft = gfxToolkitPlatform::GetPlatform()->GetFTLibrary();
+        FT_Library ft = gfxPlatform::GetPlatform()->GetFTLibrary();
+        MOZ_ASSERT(ft);
 
         // A relative path (no initial "/") means this is a resource in
         // omnijar, not an installed font on the device.
         // The NS_ASSERTIONs here should never fail, as the resource must have
         // been read successfully during font-list initialization or we'd never
         // have created the font entry. The only legitimate runtime failure
         // here would be memory allocation, in which case mFace remains null.
         if (aFontEntry->mFilename[0] != '/') {
@@ -251,17 +251,17 @@ FT2FontEntry::CreateFontEntry(const nsAS
                               const uint8_t* aFontData,
                               uint32_t aLength)
 {
     // Ownership of aFontData is passed in here; the fontEntry must
     // retain it as long as the FT_Face needs it, and ensure it is
     // eventually deleted.
     FT_Face face;
     FT_Error error =
-        FT_New_Memory_Face(gfxToolkitPlatform::GetPlatform()->GetFTLibrary(),
+        FT_New_Memory_Face(gfxPlatform::GetPlatform()->GetFTLibrary(),
                            aFontData, aLength, 0, &face);
     if (error != FT_Err_Ok) {
         free((void*)aFontData);
         return nullptr;
     }
     if (FT_Err_Ok != FT_Select_Charmap(face, FT_ENCODING_UNICODE)) {
         FT_Done_Face(face);
         free((void*)aFontData);
@@ -969,17 +969,17 @@ gfxFT2FontList::AppendFacesFromFontFile(
         s.st_mtime == timestamp && s.st_size == filesize)
     {
         LOG(("using cached font info for %s", aFileName.get()));
         AppendFacesFromCachedFaceList(aFileName, cachedFaceList, aStdFile,
                                       aVisibility);
         return;
     }
 
-    FT_Library ftLibrary = gfxAndroidPlatform::GetPlatform()->GetFTLibrary();
+    FT_Library ftLibrary = gfxPlatform::GetPlatform()->GetFTLibrary();
     FT_Face dummy;
     if (FT_Err_Ok == FT_New_Face(ftLibrary, aFileName.get(), -1, &dummy)) {
         LOG(("reading font info via FreeType for %s", aFileName.get()));
         nsCString newFaceList;
         timestamp = s.st_mtime;
         filesize = s.st_size;
         for (FT_Long i = 0; i < dummy->num_faces; i++) {
             FT_Face face;
@@ -1121,17 +1121,17 @@ gfxFT2FontList::AppendFacesFromOmnijarEn
     nsZipCursor cursor(item, aArchive, buf.get(), bufSize);
     uint8_t* data = cursor.Copy(&bufSize);
     NS_ASSERTION(data && bufSize == item->RealSize(),
                  "error reading bundled font");
     if (!data) {
         return;
     }
 
-    FT_Library ftLibrary = gfxAndroidPlatform::GetPlatform()->GetFTLibrary();
+    FT_Library ftLibrary = gfxPlatform::GetPlatform()->GetFTLibrary();
 
     FT_Face dummy;
     if (FT_Err_Ok != FT_New_Memory_Face(ftLibrary, buf.get(), bufSize, 0, &dummy)) {
         return;
     }
 
     for (FT_Long i = 0; i < dummy->num_faces; i++) {
         FT_Face face;
--- a/gfx/thebes/gfxFontconfigFonts.h
+++ b/gfx/thebes/gfxFontconfigFonts.h
@@ -50,16 +50,18 @@ public:
     // Used for @font-face { src: url(); }
     static gfxFontEntry *NewFontEntry(const nsAString& aFontName,
                                       uint16_t aWeight,
                                       int16_t aStretch,
                                       uint8_t aStyle,
                                       const uint8_t* aFontData,
                                       uint32_t aLength);
 
+    static FT_Library GetFTLibrary();
+
 private:
 
     virtual gfxFont *GetFontAt(int32_t i, uint32_t aCh = 0x20);
 
     // @param aLang [in] language to use for pref fonts and system default font
     //        selection, or nullptr for the language guessed from the
     //        gfxFontStyle.
     // The FontGroup holds a reference to this set.
@@ -111,14 +113,11 @@ private:
                              bool aUseFontSet,
                              void *aClosure);
 
     static void
     ResolveGenericFontNamesPFG(mozilla::FontFamilyType aGenericType,
                                nsIAtom *aLanguage,
                                nsTArray<nsString>& aGenericFamilies);
 
-
-    friend class gfxSystemFcFontEntry;
-    static FT_Library GetFTLibrary();
 };
 
 #endif /* GFX_FONTCONFIG_FONTS_H */
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -738,16 +738,20 @@ gfxPlatform::Init()
       MOZ_CRASH("Could not initialize mScreenReferenceDrawTarget");
     }
 
     rv = gfxFontCache::Init();
     if (NS_FAILED(rv)) {
         MOZ_CRASH("Could not initialize gfxFontCache");
     }
 
+#ifdef MOZ_ENABLE_FREETYPE
+    Factory::SetFTLibrary(gPlatform->GetFTLibrary());
+#endif
+
     /* Create and register our CMS Override observer. */
     gPlatform->mSRGBOverrideObserver = new SRGBOverrideObserver();
     Preferences::AddWeakObserver(gPlatform->mSRGBOverrideObserver, GFX_PREF_CMS_FORCE_SRGB);
 
     gPlatform->mFontPrefsObserver = new FontPrefsObserver();
     Preferences::AddStrongObservers(gPlatform->mFontPrefsObserver, kObservedPrefs);
 
     GLContext::PlatformStartup();
--- a/gfx/thebes/gfxPlatform.h
+++ b/gfx/thebes/gfxPlatform.h
@@ -34,16 +34,17 @@ class gfxUserFontSet;
 class gfxFontEntry;
 class gfxPlatformFontList;
 class gfxTextRun;
 class nsIURI;
 class nsIAtom;
 class nsIObserver;
 class SRGBOverrideObserver;
 class gfxTextPerfMetrics;
+typedef struct FT_LibraryRec_ *FT_Library;
 
 namespace mozilla {
 namespace gl {
 class SkiaGLGlue;
 } // namespace gl
 namespace gfx {
 class DrawTarget;
 class SourceSurface;
@@ -694,16 +695,20 @@ public:
     virtual void BuildContentDeviceData(mozilla::gfx::ContentDeviceData* aOut);
 
     /**
      * Imports settings from the GPU process. This should only be called through
      * GPUProcessManager, in the UI process.
      */
     virtual void ImportGPUDeviceData(const mozilla::gfx::GPUDeviceData& aData);
 
+    virtual FT_Library GetFTLibrary() {
+      return nullptr;
+    }
+
 protected:
     gfxPlatform();
     virtual ~gfxPlatform();
 
     virtual void InitAcceleration();
 
     /**
      * Called immediately before deleting the gfxPlatform object.
--- a/gfx/thebes/gfxPlatformGtk.cpp
+++ b/gfx/thebes/gfxPlatformGtk.cpp
@@ -343,16 +343,26 @@ gfxPlatformGtk::MakePlatformFont(const n
     }
 
     // passing ownership of the font data to the new font entry
     return gfxPangoFontGroup::NewFontEntry(aFontName, aWeight,
                                            aStretch, aStyle,
                                            aFontData, aLength);
 }
 
+FT_Library
+gfxPlatformGtk::GetFTLibrary()
+{
+    if (sUseFcFontList) {
+        return gfxFcPlatformFontList::GetFTLibrary();
+    }
+
+    return gfxPangoFontGroup::GetFTLibrary();
+}
+
 bool
 gfxPlatformGtk::IsFontFormatSupported(nsIURI *aFontURI, uint32_t aFormatFlags)
 {
     // check for strange format flags
     NS_ASSERTION(!(aFormatFlags & gfxUserFontSet::FLAG_FORMAT_NOT_USED),
                  "strange font format hint set");
 
     // accept supported formats
--- a/gfx/thebes/gfxPlatformGtk.h
+++ b/gfx/thebes/gfxPlatformGtk.h
@@ -90,16 +90,18 @@ public:
     virtual bool IsFontFormatSupported(nsIURI *aFontURI,
                                          uint32_t aFormatFlags) override;
 
     /**
      * Calls XFlush if xrender is enabled.
      */
     virtual void FlushContentDrawing() override;
 
+    FT_Library GetFTLibrary() override;
+
 #if (MOZ_WIDGET_GTK == 2)
     static void SetGdkDrawable(cairo_surface_t *target,
                                GdkDrawable *drawable);
     static GdkDrawable *GetGdkDrawable(cairo_surface_t *target);
 #endif
 
     static int32_t GetDPI();
     static double  GetDPIScale();