From d5f91aa2446fe09660b57db794ef20362be6afc0 Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Wed, 4 Jan 2017 14:00:17 -0500 Subject: [PATCH] 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 | 12 ++++++++++++ gfx/2d/Factory.cpp | 25 +++++++++++++++++++++++++ gfx/thebes/gfxAndroidPlatform.h | 4 +--- gfx/thebes/gfxFT2FontList.cpp | 10 +++++----- gfx/thebes/gfxFontconfigFonts.h | 5 ++--- gfx/thebes/gfxPlatform.cpp | 4 ++++ gfx/thebes/gfxPlatform.h | 5 +++++ gfx/thebes/gfxPlatformGtk.cpp | 10 ++++++++++ gfx/thebes/gfxPlatformGtk.h | 2 ++ 9 files changed, 66 insertions(+), 11 deletions(-) diff --git a/gfx/2d/2D.h b/gfx/2d/2D.h index f64f6ad30582..5848df26fdcc 100644 --- a/gfx/2d/2D.h +++ b/gfx/2d/2D.h @@ -42,6 +42,9 @@ 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; @@ -1494,6 +1497,15 @@ public: 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 CreateDrawTargetForD3D11Texture(ID3D11Texture2D *aTexture, SurfaceFormat aFormat); diff --git a/gfx/2d/Factory.cpp b/gfx/2d/Factory.cpp index de8d6109f023..2b01cd08c727 100644 --- a/gfx/2d/Factory.cpp +++ b/gfx/2d/Factory.cpp @@ -156,6 +156,10 @@ 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; @@ -192,6 +196,12 @@ Factory::ShutDown() delete sConfig; sConfig = nullptr; } + +#ifdef MOZ_ENABLE_FREETYPE + if (mFTLibrary) { + mFTLibrary = nullptr; + } +#endif } bool @@ -569,6 +579,21 @@ Factory::CreateDualDrawTarget(DrawTarget *targetA, DrawTarget *targetB) } +#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 Factory::CreateDrawTargetForD3D11Texture(ID3D11Texture2D *aTexture, SurfaceFormat aFormat) diff --git a/gfx/thebes/gfxAndroidPlatform.h b/gfx/thebes/gfxAndroidPlatform.h index 30e7c89babeb..889928da86a7 100644 --- a/gfx/thebes/gfxAndroidPlatform.h +++ b/gfx/thebes/gfxAndroidPlatform.h @@ -19,8 +19,6 @@ namespace mozilla { }; using mozilla::dom::FontListEntry; -typedef struct FT_LibraryRec_ *FT_Library; - class gfxAndroidPlatform : public gfxPlatform { public: gfxAndroidPlatform(); @@ -60,7 +58,7 @@ public: virtual bool FontHintingEnabled() override; virtual bool RequiresLinearZoom() override; - FT_Library GetFTLibrary(); + FT_Library GetFTLibrary() override; virtual bool CanRenderContentToDataSurface() const override { return true; diff --git a/gfx/thebes/gfxFT2FontList.cpp b/gfx/thebes/gfxFT2FontList.cpp index fd98ceb51d09..49d6cb6bc230 100644 --- a/gfx/thebes/gfxFT2FontList.cpp +++ b/gfx/thebes/gfxFT2FontList.cpp @@ -13,7 +13,6 @@ #include "mozilla/UniquePtr.h" #include "mozilla/UniquePtrExtensions.h" #include "nsIInputStream.h" -#define gfxToolkitPlatform gfxAndroidPlatform #include "nsXULAppAPI.h" #include @@ -85,7 +84,8 @@ public: 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. @@ -256,7 +256,7 @@ FT2FontEntry::CreateFontEntry(const nsAString& aFontName, // 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); @@ -974,7 +974,7 @@ gfxFT2FontList::AppendFacesFromFontFile(const nsCString& aFileName, 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())); @@ -1126,7 +1126,7 @@ gfxFT2FontList::AppendFacesFromOmnijarEntry(nsZipArchive* aArchive, 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)) { diff --git a/gfx/thebes/gfxFontconfigFonts.h b/gfx/thebes/gfxFontconfigFonts.h index cea9d0dbfaf2..cd59cfc68c62 100644 --- a/gfx/thebes/gfxFontconfigFonts.h +++ b/gfx/thebes/gfxFontconfigFonts.h @@ -55,6 +55,8 @@ public: const uint8_t* aFontData, uint32_t aLength); + static FT_Library GetFTLibrary(); + private: virtual gfxFont *GetFontAt(int32_t i, uint32_t aCh = 0x20); @@ -116,9 +118,6 @@ private: nsIAtom *aLanguage, nsTArray& aGenericFamilies); - - friend class gfxSystemFcFontEntry; - static FT_Library GetFTLibrary(); }; #endif /* GFX_FONTCONFIG_FONTS_H */ diff --git a/gfx/thebes/gfxPlatform.cpp b/gfx/thebes/gfxPlatform.cpp index 0f7b54237f90..6440da0de5cb 100644 --- a/gfx/thebes/gfxPlatform.cpp +++ b/gfx/thebes/gfxPlatform.cpp @@ -743,6 +743,10 @@ gfxPlatform::Init() 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); diff --git a/gfx/thebes/gfxPlatform.h b/gfx/thebes/gfxPlatform.h index bfc26d9b3bab..10fa5972674c 100644 --- a/gfx/thebes/gfxPlatform.h +++ b/gfx/thebes/gfxPlatform.h @@ -39,6 +39,7 @@ class nsIAtom; class nsIObserver; class SRGBOverrideObserver; class gfxTextPerfMetrics; +typedef struct FT_LibraryRec_ *FT_Library; namespace mozilla { namespace gl { @@ -699,6 +700,10 @@ public: */ virtual void ImportGPUDeviceData(const mozilla::gfx::GPUDeviceData& aData); + virtual FT_Library GetFTLibrary() { + return nullptr; + } + protected: gfxPlatform(); virtual ~gfxPlatform(); diff --git a/gfx/thebes/gfxPlatformGtk.cpp b/gfx/thebes/gfxPlatformGtk.cpp index 9d7f512f27a7..c8661a433111 100644 --- a/gfx/thebes/gfxPlatformGtk.cpp +++ b/gfx/thebes/gfxPlatformGtk.cpp @@ -348,6 +348,16 @@ gfxPlatformGtk::MakePlatformFont(const nsAString& aFontName, aFontData, aLength); } +FT_Library +gfxPlatformGtk::GetFTLibrary() +{ + if (sUseFcFontList) { + return gfxFcPlatformFontList::GetFTLibrary(); + } + + return gfxPangoFontGroup::GetFTLibrary(); +} + bool gfxPlatformGtk::IsFontFormatSupported(nsIURI *aFontURI, uint32_t aFormatFlags) { diff --git a/gfx/thebes/gfxPlatformGtk.h b/gfx/thebes/gfxPlatformGtk.h index 75026df396dd..c313f1a1648e 100644 --- a/gfx/thebes/gfxPlatformGtk.h +++ b/gfx/thebes/gfxPlatformGtk.h @@ -95,6 +95,8 @@ public: */ virtual void FlushContentDrawing() override; + FT_Library GetFTLibrary() override; + #if (MOZ_WIDGET_GTK == 2) static void SetGdkDrawable(cairo_surface_t *target, GdkDrawable *drawable);