From 3546ff10c2e1e91f5afe1efaab4e5e14f71689d1 Mon Sep 17 00:00:00 2001 From: Ben Wagner Date: Tue, 3 Jan 2017 13:32:36 -0500 Subject: [PATCH] Stage SkFontMgr factories to return smart pointers. All the SkFontMgr factories currently return bare pointers and sometimes even document the ownership rules. Since such factories can be implemented by external ports, the ownership rules should be explicit in order to prevent simple reference counting issues. Change-Id: I25b598ce0954cd473a3fb1f8adc0cb86331583ca Reviewed-on: https://skia-review.googlesource.com/6533 Reviewed-by: Florin Malita Reviewed-by: Mike Reed Commit-Queue: Ben Wagner --- gm/fontmgr.cpp | 20 +++++++++++++++ include/ports/SkFontMgr.h | 17 +++++++++---- include/ports/SkFontMgr_FontConfigInterface.h | 4 +++ include/ports/SkFontMgr_android.h | 4 +++ include/ports/SkFontMgr_custom.h | 8 ++++++ include/ports/SkFontMgr_fontconfig.h | 4 +++ include/ports/SkTypeface_win.h | 25 +++++++++++++++++++ src/core/SkFontMgr.cpp | 13 ++++++++++ src/ports/SkFontHost_mac.cpp | 4 +++ src/ports/SkFontHost_win.cpp | 4 +++ src/ports/SkFontMgr_FontConfigInterface.cpp | 7 ++++++ .../SkFontMgr_FontConfigInterface_factory.cpp | 4 +++ src/ports/SkFontMgr_android.cpp | 9 ++++++- src/ports/SkFontMgr_android_factory.cpp | 4 +++ src/ports/SkFontMgr_custom.cpp | 18 +++++++++++++ .../SkFontMgr_custom_directory_factory.cpp | 4 +++ .../SkFontMgr_custom_embedded_factory.cpp | 8 ++++++ src/ports/SkFontMgr_custom_empty_factory.cpp | 4 +++ src/ports/SkFontMgr_empty_factory.cpp | 4 +++ src/ports/SkFontMgr_fontconfig.cpp | 6 +++++ src/ports/SkFontMgr_fontconfig_factory.cpp | 4 +++ src/ports/SkFontMgr_win_dw.cpp | 21 ++++++++++++++++ src/ports/SkFontMgr_win_dw_factory.cpp | 4 +++ src/ports/SkFontMgr_win_gdi_factory.cpp | 4 +++ 24 files changed, 198 insertions(+), 6 deletions(-) diff --git a/gm/fontmgr.cpp b/gm/fontmgr.cpp index 216fdd8249..18fc1d9250 100644 --- a/gm/fontmgr.cpp +++ b/gm/fontmgr.cpp @@ -55,6 +55,7 @@ static const char* ja = "ja"; class FontMgrGM : public skiagm::GM { public: +#ifdef SK_LEGACY_FONTMGR_FACTORY FontMgrGM(SkFontMgr* fontMgr = nullptr) { SkGraphics::SetFontCacheLimit(16 * 1024 * 1024); @@ -68,6 +69,21 @@ public: fName.append(sk_tool_utils::platform_os_name()); fName.append(sk_tool_utils::platform_extra_config("GDI")); } +#else + FontMgrGM(sk_sp fontMgr = nullptr) { + SkGraphics::SetFontCacheLimit(16 * 1024 * 1024); + + fName.set("fontmgr_iter"); + if (fontMgr) { + fName.append("_factory"); + fFM = std::move(fontMgr); + } else { + fFM = SkFontMgr::RefDefault(); + } + fName.append(sk_tool_utils::platform_os_name()); + fName.append(sk_tool_utils::platform_extra_config("GDI")); + } +#endif protected: SkString onShortName() override { @@ -225,7 +241,11 @@ public: } fName.append(sk_tool_utils::platform_os_name()); fName.append(sk_tool_utils::platform_extra_config("GDI")); +#ifdef SK_LEGACY_FONTMGR_FACTORY fFM.reset(SkFontMgr::RefDefault()); +#else + fFM = SkFontMgr::RefDefault(); +#endif } static void show_bounds(SkCanvas* canvas, const SkPaint& paint, SkScalar x, SkScalar y, diff --git a/include/ports/SkFontMgr.h b/include/ports/SkFontMgr.h index afadeaaa97..a9317d31e4 100644 --- a/include/ports/SkFontMgr.h +++ b/include/ports/SkFontMgr.h @@ -165,11 +165,12 @@ public: SkTypeface* legacyCreateTypeface(const char familyName[], SkFontStyle style) const; - /** - * Return a ref to the default fontmgr. The caller must call unref() on - * the returned object. - */ + /** Return the default fontmgr. */ +#ifdef SK_LEGACY_FONTMGR_FACTORY static SkFontMgr* RefDefault(); +#else + static sk_sp RefDefault(); +#endif protected: virtual int onCountFamilies() const = 0; @@ -197,7 +198,13 @@ protected: virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle) const = 0; private: - static SkFontMgr* Factory(); // implemented by porting layer + + /** Implemented by porting layer to return the default factory. */ +#ifdef SK_LEGACY_FONTMGR_FACTORY + static SkFontMgr* Factory(); +#else + static sk_sp Factory(); +#endif typedef SkRefCnt INHERITED; }; diff --git a/include/ports/SkFontMgr_FontConfigInterface.h b/include/ports/SkFontMgr_FontConfigInterface.h index 356e54c87d..6cf34d013c 100644 --- a/include/ports/SkFontMgr_FontConfigInterface.h +++ b/include/ports/SkFontMgr_FontConfigInterface.h @@ -15,6 +15,10 @@ class SkFontMgr; class SkFontConfigInterface; /** Creates a SkFontMgr which wraps a SkFontConfigInterface. */ +#ifdef SK_LEGACY_FONTMGR_FACTORY SK_API SkFontMgr* SkFontMgr_New_FCI(sk_sp fci); +#else +SK_API sk_sp SkFontMgr_New_FCI(sk_sp fci); +#endif #endif // #ifndef SkFontMgr_FontConfigInterface_DEFINED diff --git a/include/ports/SkFontMgr_android.h b/include/ports/SkFontMgr_android.h index f12f51f36a..9ed435dc0d 100644 --- a/include/ports/SkFontMgr_android.h +++ b/include/ports/SkFontMgr_android.h @@ -47,6 +47,10 @@ struct SkFontMgr_Android_CustomFonts { }; /** Create a font manager for Android. If 'custom' is NULL, use only system fonts. */ +#ifdef SK_LEGACY_FONTMGR_FACTORY SK_API SkFontMgr* SkFontMgr_New_Android(const SkFontMgr_Android_CustomFonts* custom); +#else +SK_API sk_sp SkFontMgr_New_Android(const SkFontMgr_Android_CustomFonts* custom); +#endif #endif // SkFontMgr_android_DEFINED diff --git a/include/ports/SkFontMgr_custom.h b/include/ports/SkFontMgr_custom.h index 53be63db1b..9d3986d161 100644 --- a/include/ports/SkFontMgr_custom.h +++ b/include/ports/SkFontMgr_custom.h @@ -13,9 +13,17 @@ class SkFontMgr; /** Create a custom font manager which scans a given directory for font files. */ +#ifdef SK_LEGACY_FONTMGR_FACTORY SK_API SkFontMgr* SkFontMgr_New_Custom_Directory(const char* dir); +#else +SK_API sk_sp SkFontMgr_New_Custom_Directory(const char* dir); +#endif /** Create a custom font manager that contains no built-in fonts. */ +#ifdef SK_LEGACY_FONTMGR_FACTORY SK_API SkFontMgr* SkFontMgr_New_Custom_Empty(); +#else +SK_API sk_sp SkFontMgr_New_Custom_Empty(); +#endif #endif // SkFontMgr_custom_DEFINED diff --git a/include/ports/SkFontMgr_fontconfig.h b/include/ports/SkFontMgr_fontconfig.h index 7a59ff0c46..ed479828ea 100644 --- a/include/ports/SkFontMgr_fontconfig.h +++ b/include/ports/SkFontMgr_fontconfig.h @@ -17,6 +17,10 @@ class SkFontMgr; * If 'fc' is NULL, will use a new default config. * Takes ownership of 'fc' and will call FcConfigDestroy on it. */ +#ifdef SK_LEGACY_FONTMGR_FACTORY SK_API SkFontMgr* SkFontMgr_New_FontConfig(FcConfig* fc); +#else +SK_API sk_sp SkFontMgr_New_FontConfig(FcConfig* fc); +#endif #endif // #ifndef SkFontMgr_fontconfig_DEFINED diff --git a/include/ports/SkTypeface_win.h b/include/ports/SkTypeface_win.h index f3a881f3cc..e332f00b72 100644 --- a/include/ports/SkTypeface_win.h +++ b/include/ports/SkTypeface_win.h @@ -44,6 +44,7 @@ struct IDWriteFactory; struct IDWriteFontCollection; struct IDWriteFontFallback; +#ifdef SK_LEGACY_FONTMGR_FACTORY SK_API SkFontMgr* SkFontMgr_New_GDI(); SK_API SkFontMgr* SkFontMgr_New_DirectWrite(IDWriteFactory* factory = NULL, IDWriteFontCollection* collection = NULL); @@ -66,6 +67,30 @@ SK_API SkFontMgr* SkFontMgr_New_DirectWriteRenderer(sk_sp); * If DirectWrite could not be initialized, will return NULL. */ SK_API SkRemotableFontMgr* SkRemotableFontMgr_New_DirectWrite(); +#else +SK_API sk_sp SkFontMgr_New_GDI(); +SK_API sk_sp SkFontMgr_New_DirectWrite(IDWriteFactory* factory = NULL, + IDWriteFontCollection* collection = NULL); +SK_API sk_sp SkFontMgr_New_DirectWrite(IDWriteFactory* factory, + IDWriteFontCollection* collection, + IDWriteFontFallback* fallback); + +/** + * Creates an SkFontMgr which renders using DirectWrite and obtains its data + * from the SkRemotableFontMgr. + * + * If DirectWrite could not be initialized, will return NULL. + */ +SK_API sk_sp SkFontMgr_New_DirectWriteRenderer(sk_sp); + +/** + * Creates an SkRemotableFontMgr backed by DirectWrite using the default + * system font collection in the current locale. + * + * If DirectWrite could not be initialized, will return NULL. + */ +SK_API sk_sp SkRemotableFontMgr_New_DirectWrite(); +#endif #endif // SK_BUILD_FOR_WIN #endif // SkTypeface_win_DEFINED diff --git a/src/core/SkFontMgr.cpp b/src/core/SkFontMgr.cpp index 57f82b03ba..b9865a2597 100644 --- a/src/core/SkFontMgr.cpp +++ b/src/core/SkFontMgr.cpp @@ -167,6 +167,7 @@ SkTypeface* SkFontMgr::legacyCreateTypeface(const char familyName[], SkFontStyle return this->onLegacyCreateTypeface(familyName, style); } +#ifdef SK_LEGACY_FONTMGR_FACTORY SkFontMgr* SkFontMgr::RefDefault() { static SkOnce once; static SkFontMgr* singleton; @@ -177,6 +178,18 @@ SkFontMgr* SkFontMgr::RefDefault() { }); return SkRef(singleton); } +#else +sk_sp SkFontMgr::RefDefault() { + static SkOnce once; + static sk_sp singleton; + + once([]{ + sk_sp fm = SkFontMgr::Factory(); + singleton = fm ? std::move(fm) : sk_make_sp(); + }); + return singleton; +} +#endif /** * Width has the greatest priority. diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp index 2c2f373db5..274c9253a9 100644 --- a/src/ports/SkFontHost_mac.cpp +++ b/src/ports/SkFontHost_mac.cpp @@ -2379,6 +2379,10 @@ protected: /////////////////////////////////////////////////////////////////////////////// +#ifdef SK_LEGACY_FONTMGR_FACTORY SkFontMgr* SkFontMgr::Factory() { return new SkFontMgr_Mac; } +#else +sk_sp SkFontMgr::Factory() { return sk_make_sp(); } +#endif #endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp index 9229be6d30..9caff02b54 100644 --- a/src/ports/SkFontHost_win.cpp +++ b/src/ports/SkFontHost_win.cpp @@ -2487,6 +2487,10 @@ private: /////////////////////////////////////////////////////////////////////////////// +#ifdef SK_LEGACY_FONTMGR_FACTORY SkFontMgr* SkFontMgr_New_GDI() { return new SkFontMgrGDI; } +#else +sk_sp SkFontMgr_New_GDI() { return sk_make_sp(); } +#endif #endif//defined(SK_BUILD_FOR_WIN32) diff --git a/src/ports/SkFontMgr_FontConfigInterface.cpp b/src/ports/SkFontMgr_FontConfigInterface.cpp index a8838046c5..201306c805 100644 --- a/src/ports/SkFontMgr_FontConfigInterface.cpp +++ b/src/ports/SkFontMgr_FontConfigInterface.cpp @@ -296,7 +296,14 @@ protected: } }; +#ifdef SK_LEGACY_FONTMGR_FACTORY SK_API SkFontMgr* SkFontMgr_New_FCI(sk_sp fci) { SkASSERT(fci); return new SkFontMgr_FCI(std::move(fci)); } +#else +SK_API sk_sp SkFontMgr_New_FCI(sk_sp fci) { + SkASSERT(fci); + return sk_make_sp(std::move(fci)); +} +#endif diff --git a/src/ports/SkFontMgr_FontConfigInterface_factory.cpp b/src/ports/SkFontMgr_FontConfigInterface_factory.cpp index b2bb74ee1d..2aa617c757 100644 --- a/src/ports/SkFontMgr_FontConfigInterface_factory.cpp +++ b/src/ports/SkFontMgr_FontConfigInterface_factory.cpp @@ -9,7 +9,11 @@ #include "SkFontMgr.h" #include "SkFontMgr_FontConfigInterface.h" +#ifdef SK_LEGACY_FONTMGR_FACTORY SkFontMgr* SkFontMgr::Factory() { +#else +sk_sp SkFontMgr::Factory() { +#endif sk_sp fci(SkFontConfigInterface::RefGlobal()); if (!fci) { return nullptr; diff --git a/src/ports/SkFontMgr_android.cpp b/src/ports/SkFontMgr_android.cpp index 116bc01549..fe4a82d964 100644 --- a/src/ports/SkFontMgr_android.cpp +++ b/src/ports/SkFontMgr_android.cpp @@ -535,7 +535,11 @@ static char const * const gSystemFontUseStrings[] = { "OnlyCustom", "PreferCustom", "PreferSystem" }; #endif +#ifdef SK_LEGACY_FONTMGR_FACTORY SkFontMgr* SkFontMgr_New_Android(const SkFontMgr_Android_CustomFonts* custom) { +#else +sk_sp SkFontMgr_New_Android(const SkFontMgr_Android_CustomFonts* custom) { +#endif if (custom) { SkASSERT(0 <= custom->fSystemFontUse); SkASSERT(custom->fSystemFontUse < SK_ARRAY_COUNT(gSystemFontUseStrings)); @@ -545,6 +549,9 @@ SkFontMgr* SkFontMgr_New_Android(const SkFontMgr_Android_CustomFonts* custom) { custom->fFontsXml, custom->fFallbackFontsXml)); } - +#ifdef SK_LEGACY_FONTMGR_FACTORY return new SkFontMgr_Android(custom); +#else + return sk_make_sp(custom); +#endif } diff --git a/src/ports/SkFontMgr_android_factory.cpp b/src/ports/SkFontMgr_android_factory.cpp index ce39b2cf97..74bcef2de5 100644 --- a/src/ports/SkFontMgr_android_factory.cpp +++ b/src/ports/SkFontMgr_android_factory.cpp @@ -28,7 +28,11 @@ void SkUseTestFontConfigFile(const char* fontsXml, const char* fallbackFontsXml, gTestBasePath, gTestFontsXml, gTestFallbackFontsXml)); } +#ifdef SK_LEGACY_FONTMGR_FACTORY SkFontMgr* SkFontMgr::Factory() { +#else +sk_sp SkFontMgr::Factory() { +#endif // These globals exist so that Chromium can override the environment. // TODO: these globals need to be removed, and Chromium use SkFontMgr_New_Android instead. if ((gTestFontsXml || gTestFallbackFontsXml) && gTestBasePath) { diff --git a/src/ports/SkFontMgr_custom.cpp b/src/ports/SkFontMgr_custom.cpp index ada7d0b190..5cfdb081d6 100644 --- a/src/ports/SkFontMgr_custom.cpp +++ b/src/ports/SkFontMgr_custom.cpp @@ -420,9 +420,15 @@ private: SkString fBaseDirectory; }; +#ifdef SK_LEGACY_FONTMGR_FACTORY SK_API SkFontMgr* SkFontMgr_New_Custom_Directory(const char* dir) { return new SkFontMgr_Custom(DirectorySystemFontLoader(dir)); } +#else +SK_API sk_sp SkFontMgr_New_Custom_Directory(const char* dir) { + return sk_make_sp(DirectorySystemFontLoader(dir)); +} +#endif /////////////////////////////////////////////////////////////////////////////// @@ -498,9 +504,15 @@ private: const SkEmbeddedResourceHeader* fHeader; }; +#ifdef SK_LEGACY_FONTMGR_FACTORY SkFontMgr* SkFontMgr_New_Custom_Embedded(const SkEmbeddedResourceHeader* header) { return new SkFontMgr_Custom(EmbeddedSystemFontLoader(header)); } +#else +sk_sp SkFontMgr_New_Custom_Embedded(const SkEmbeddedResourceHeader* header) { + return sk_make_sp(EmbeddedSystemFontLoader(header)); +} +#endif /////////////////////////////////////////////////////////////////////////////// @@ -518,6 +530,12 @@ public: }; +#ifdef SK_LEGACY_FONTMGR_FACTORY SK_API SkFontMgr* SkFontMgr_New_Custom_Empty() { return new SkFontMgr_Custom(EmptyFontLoader()); } +#else +SK_API sk_sp SkFontMgr_New_Custom_Empty() { + return sk_make_sp(EmptyFontLoader()); +} +#endif diff --git a/src/ports/SkFontMgr_custom_directory_factory.cpp b/src/ports/SkFontMgr_custom_directory_factory.cpp index 0ca6f4b3b4..5cf6d3cb04 100644 --- a/src/ports/SkFontMgr_custom_directory_factory.cpp +++ b/src/ports/SkFontMgr_custom_directory_factory.cpp @@ -12,6 +12,10 @@ # define SK_FONT_FILE_PREFIX "/usr/share/fonts/" #endif +#ifdef SK_LEGACY_FONTMGR_FACTORY SkFontMgr* SkFontMgr::Factory() { +#else +sk_sp SkFontMgr::Factory() { +#endif return SkFontMgr_New_Custom_Directory(SK_FONT_FILE_PREFIX); } diff --git a/src/ports/SkFontMgr_custom_embedded_factory.cpp b/src/ports/SkFontMgr_custom_embedded_factory.cpp index 6ea6a2d2af..79d5500648 100644 --- a/src/ports/SkFontMgr_custom_embedded_factory.cpp +++ b/src/ports/SkFontMgr_custom_embedded_factory.cpp @@ -9,9 +9,17 @@ struct SkEmbeddedResource { const uint8_t* data; size_t size; }; struct SkEmbeddedResourceHeader { const SkEmbeddedResource* entries; int count; }; +#ifdef SK_LEGACY_FONTMGR_FACTORY SkFontMgr* SkFontMgr_New_Custom_Embedded(const SkEmbeddedResourceHeader* header); +#else +sk_sp SkFontMgr_New_Custom_Embedded(const SkEmbeddedResourceHeader* header); +#endif extern "C" const SkEmbeddedResourceHeader SK_EMBEDDED_FONTS; +#ifdef SK_LEGACY_FONTMGR_FACTORY SkFontMgr* SkFontMgr::Factory() { +#else +sk_sp SkFontMgr::Factory() { +#endif return SkFontMgr_New_Custom_Embedded(&SK_EMBEDDED_FONTS); } diff --git a/src/ports/SkFontMgr_custom_empty_factory.cpp b/src/ports/SkFontMgr_custom_empty_factory.cpp index c9487cdcc7..c95647ef24 100644 --- a/src/ports/SkFontMgr_custom_empty_factory.cpp +++ b/src/ports/SkFontMgr_custom_empty_factory.cpp @@ -8,6 +8,10 @@ #include "SkFontMgr.h" #include "SkFontMgr_custom.h" +#ifdef SK_LEGACY_FONTMGR_FACTORY SkFontMgr* SkFontMgr::Factory() { +#else +sk_sp SkFontMgr::Factory() { +#endif return SkFontMgr_New_Custom_Empty(); } diff --git a/src/ports/SkFontMgr_empty_factory.cpp b/src/ports/SkFontMgr_empty_factory.cpp index b4232cde12..b01811a335 100644 --- a/src/ports/SkFontMgr_empty_factory.cpp +++ b/src/ports/SkFontMgr_empty_factory.cpp @@ -7,7 +7,11 @@ #include "SkFontMgr.h" +#ifdef SK_LEGACY_FONTMGR_FACTORY SkFontMgr* SkFontMgr::Factory() { +#else +sk_sp SkFontMgr::Factory() { +#endif // Always return nullptr, an empty SkFontMgr will be used. return nullptr; } diff --git a/src/ports/SkFontMgr_fontconfig.cpp b/src/ports/SkFontMgr_fontconfig.cpp index 3592feccfb..28edcf790b 100644 --- a/src/ports/SkFontMgr_fontconfig.cpp +++ b/src/ports/SkFontMgr_fontconfig.cpp @@ -953,6 +953,12 @@ protected: } }; +#ifdef SK_LEGACY_FONTMGR_FACTORY SK_API SkFontMgr* SkFontMgr_New_FontConfig(FcConfig* fc) { return new SkFontMgr_fontconfig(fc); } +#else +SK_API sk_sp SkFontMgr_New_FontConfig(FcConfig* fc) { + return sk_make_sp(fc); +} +#endif diff --git a/src/ports/SkFontMgr_fontconfig_factory.cpp b/src/ports/SkFontMgr_fontconfig_factory.cpp index cdf055608d..1a86ed5323 100644 --- a/src/ports/SkFontMgr_fontconfig_factory.cpp +++ b/src/ports/SkFontMgr_fontconfig_factory.cpp @@ -9,6 +9,10 @@ #include "SkFontMgr_fontconfig.h" #include "SkTypes.h" +#ifdef SK_LEGACY_FONTMGR_FACTORY SkFontMgr* SkFontMgr::Factory() { +#else +sk_sp SkFontMgr::Factory() { +#endif return SkFontMgr_New_FontConfig(nullptr); } diff --git a/src/ports/SkFontMgr_win_dw.cpp b/src/ports/SkFontMgr_win_dw.cpp index 547cbe3639..29069f069e 100644 --- a/src/ports/SkFontMgr_win_dw.cpp +++ b/src/ports/SkFontMgr_win_dw.cpp @@ -1043,12 +1043,20 @@ SkTypeface* SkFontStyleSet_DirectWrite::matchStyle(const SkFontStyle& pattern) { //////////////////////////////////////////////////////////////////////////////// #include "SkTypeface_win.h" +#ifdef SK_LEGACY_FONTMGR_FACTORY SK_API SkFontMgr* SkFontMgr_New_DirectWrite(IDWriteFactory* factory, +#else +SK_API sk_sp SkFontMgr_New_DirectWrite(IDWriteFactory* factory, +#endif IDWriteFontCollection* collection) { return SkFontMgr_New_DirectWrite(factory, collection, nullptr); } +#ifdef SK_LEGACY_FONTMGR_FACTORY SK_API SkFontMgr* SkFontMgr_New_DirectWrite(IDWriteFactory* factory, +#else +SK_API sk_sp SkFontMgr_New_DirectWrite(IDWriteFactory* factory, +#endif IDWriteFontCollection* collection, IDWriteFontFallback* fallback) { if (nullptr == factory) { @@ -1081,15 +1089,28 @@ SK_API SkFontMgr* SkFontMgr_New_DirectWrite(IDWriteFactory* factory, }; } +#ifdef SK_LEGACY_FONTMGR_FACTORY return new SkFontMgr_DirectWrite(factory, collection, fallback, localeName, localeNameLen); +#else + return sk_make_sp(factory, collection, fallback, + localeName, localeNameLen); +#endif } #include "SkFontMgr_indirect.h" +#ifdef SK_LEGACY_FONTMGR_FACTORY SK_API SkFontMgr* SkFontMgr_New_DirectWriteRenderer(sk_sp proxy) { +#else +SK_API sk_sp SkFontMgr_New_DirectWriteRenderer(sk_sp proxy) { +#endif sk_sp impl(SkFontMgr_New_DirectWrite()); if (!impl) { return nullptr; } +#ifdef SK_LEGACY_FONTMGR_FACTORY return new SkFontMgr_Indirect(std::move(impl), std::move(proxy)); +#else + return sk_make_sp(std::move(impl), std::move(proxy)); +#endif } #endif//defined(SK_BUILD_FOR_WIN32) diff --git a/src/ports/SkFontMgr_win_dw_factory.cpp b/src/ports/SkFontMgr_win_dw_factory.cpp index 52e22aec52..01a0e0be8a 100644 --- a/src/ports/SkFontMgr_win_dw_factory.cpp +++ b/src/ports/SkFontMgr_win_dw_factory.cpp @@ -11,7 +11,11 @@ #include "SkFontMgr.h" #include "SkTypeface_win.h" +#ifdef SK_LEGACY_FONTMGR_FACTORY SkFontMgr* SkFontMgr::Factory() { +#else +sk_sp SkFontMgr::Factory() { +#endif return SkFontMgr_New_DirectWrite(); } diff --git a/src/ports/SkFontMgr_win_gdi_factory.cpp b/src/ports/SkFontMgr_win_gdi_factory.cpp index c1ca822c28..040778e174 100644 --- a/src/ports/SkFontMgr_win_gdi_factory.cpp +++ b/src/ports/SkFontMgr_win_gdi_factory.cpp @@ -11,7 +11,11 @@ #include "SkFontMgr.h" #include "SkTypeface_win.h" +#ifdef SK_LEGACY_FONTMGR_FACTORY SkFontMgr* SkFontMgr::Factory() { +#else +sk_sp SkFontMgr::Factory() { +#endif return SkFontMgr_New_GDI(); }