Bug 1365935 - add Moz2D Factory methods for making an FT_Library. r=jrmuizel
authorLee Salzman <lsalzman@mozilla.com>
Thu, 18 May 2017 13:16:06 -0400
changeset 358999 3c508994ee44b4db6d7832fb5ad5ceeae13dcf61
parent 358998 4808d8fe4ea887a468fc8f1083ee51ef20f4d6ce
child 359000 60c8cc9c57d33d42cba84b2c21f029f218e2253e
push id90429
push userlsalzman@mozilla.com
push dateThu, 18 May 2017 17:16:53 +0000
treeherdermozilla-inbound@3c508994ee44 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1365935
milestone55.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 1365935 - add Moz2D Factory methods for making an FT_Library. r=jrmuizel MozReview-Commit-ID: 7gQuVrl38aT
gfx/2d/2D.h
gfx/2d/Factory.cpp
gfx/webrender_bindings/Moz2DImageRenderer.cpp
gfx/webrender_bindings/moz.build
--- a/gfx/2d/2D.h
+++ b/gfx/2d/2D.h
@@ -26,16 +26,22 @@
 // outparams using the &-operator. But it will have to do as there's no easy
 // solution.
 #include "mozilla/RefPtr.h"
 #include "mozilla/ServoUtils.h"
 #include "mozilla/WeakPtr.h"
 
 #include "mozilla/DebugOnly.h"
 
+#if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_GTK)
+  #ifndef MOZ_ENABLE_FREETYPE
+  #define MOZ_ENABLE_FREETYPE
+  #endif
+#endif
+
 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;
@@ -1613,16 +1619,19 @@ public:
   static already_AddRefed<GlyphRenderingOptions>
     CreateCGGlyphRenderingOptions(const Color &aFontSmoothingBackgroundColor);
 #endif
 
 #ifdef MOZ_ENABLE_FREETYPE
   static void SetFTLibrary(FT_Library aFTLibrary);
   static FT_Library GetFTLibrary();
 
+  static FT_Library NewFTLibrary();
+  static void ReleaseFTLibrary(FT_Library aFTLibrary);
+
   static FT_Face NewFTFace(FT_Library aFTLibrary, const char* aFileName, int aFaceIndex);
   static FT_Face NewFTFaceFromData(FT_Library aFTLibrary, const uint8_t* aData, size_t aDataSize, int aFaceIndex);
   static void ReleaseFTFace(FT_Face aFace);
 
 private:
   static FT_Library mFTLibrary;
   static Mutex* mFTLock;
 public:
--- a/gfx/2d/Factory.cpp
+++ b/gfx/2d/Factory.cpp
@@ -657,16 +657,32 @@ Factory::SetFTLibrary(FT_Library aFTLibr
 
 FT_Library
 Factory::GetFTLibrary()
 {
   MOZ_ASSERT(mFTLibrary);
   return mFTLibrary;
 }
 
+FT_Library
+Factory::NewFTLibrary()
+{
+  FT_Library library;
+  if (FT_Init_FreeType(&library) != FT_Err_Ok) {
+    return nullptr;
+  }
+  return library;
+}
+
+void
+Factory::ReleaseFTLibrary(FT_Library aFTLibrary)
+{
+  FT_Done_FreeType(aFTLibrary);
+}
+
 FT_Face
 Factory::NewFTFace(FT_Library aFTLibrary, const char* aFileName, int aFaceIndex)
 {
   MOZ_ASSERT(mFTLock);
   MutexAutoLock lock(*mFTLock);
   if (!aFTLibrary) {
     aFTLibrary = mFTLibrary;
   }
--- a/gfx/webrender_bindings/Moz2DImageRenderer.cpp
+++ b/gfx/webrender_bindings/Moz2DImageRenderer.cpp
@@ -9,19 +9,16 @@
 #include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/InlineTranslator.h"
 #include "mozilla/gfx/RecordedEvent.h"
 #include "WebRenderTypes.h"
 
 #include <iostream>
 
 #ifdef MOZ_ENABLE_FREETYPE
-#include "ft2build.h"
-#include FT_FREETYPE_H
-
 #include "mozilla/ThreadLocal.h"
 #endif
 
 namespace mozilla {
 namespace wr {
 
 class InMemoryStreamBuffer: public std::streambuf
 {
@@ -51,27 +48,29 @@ static bool Moz2DRenderCallback(const Ra
   }
 
   auto stride = aSize.width * gfx::BytesPerPixel(aFormat);
 
   if (aOutput.length() < static_cast<size_t>(aSize.height * stride)) {
     return false;
   }
 
+  void* fontContext = nullptr;
 #ifdef MOZ_ENABLE_FREETYPE
   if (!sFTLibrary.init()) {
     return false;
   }
   if (!sFTLibrary.get()) {
-    FT_Library library;
-    if (FT_Init_FreeType(&library) != FT_Err_Ok) {
+    FT_Library library = gfx::Factory::NewFTLibrary();
+    if (!library) {
       return false;
     }
     sFTLibrary.set(library);
   }
+  fontContext = sFTLibrary.get();
 #endif
 
   // In bindings.rs we allocate a buffer filled with opaque white.
   bool uninitialized = false;
 
   RefPtr<gfx::DrawTarget> dt = gfx::Factory::CreateDrawTargetForData(
     gfx::BackendType::SKIA,
     aOutput.begin().get(),
@@ -83,21 +82,17 @@ static bool Moz2DRenderCallback(const Ra
 
   if (!dt) {
     return false;
   }
 
   InMemoryStreamBuffer streamBuffer(aBlob);
   std::istream stream(&streamBuffer);
 
-#ifdef MOZ_ENABLE_FREETYPE
-  gfx::InlineTranslator translator(dt, sFTLibrary.get());
-#else
-  gfx::InlineTranslator translator(dt);
-#endif
+  gfx::InlineTranslator translator(dt, fontContext);
 
   auto ret = translator.TranslateRecording(stream);
 
 #if 0
   static int i = 0;
   char filename[40];
   sprintf(filename, "out%d.png", i++);
   gfxUtils::WriteAsPNG(dt, filename);
--- a/gfx/webrender_bindings/moz.build
+++ b/gfx/webrender_bindings/moz.build
@@ -32,15 +32,11 @@ UNIFIED_SOURCES += [
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
     EXPORTS.mozilla.webrender += [
         'RenderMacIOSurfaceTextureHostOGL.h',
     ]
     UNIFIED_SOURCES += [
         'RenderMacIOSurfaceTextureHostOGL.cpp',
     ]
 
-if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android', 'gtk2', 'gtk3'):
-    DEFINES['MOZ_ENABLE_FREETYPE'] = True
-    CXXFLAGS += CONFIG['CAIRO_FT_CFLAGS']
-
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'