aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/ports
diff options
context:
space:
mode:
authorGravatar Ben Wagner <bungeman@google.com>2017-01-03 13:32:36 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-01-04 14:51:09 +0000
commit3546ff10c2e1e91f5afe1efaab4e5e14f71689d1 (patch)
treecbcf83ae724df22c6cc5704a75be9095a28058db /include/ports
parent8bc9f7b32867cb46fd7b56c11bf9dfa79a7d246e (diff)
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 <fmalita@chromium.org> Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Ben Wagner <bungeman@google.com>
Diffstat (limited to 'include/ports')
-rw-r--r--include/ports/SkFontMgr.h17
-rw-r--r--include/ports/SkFontMgr_FontConfigInterface.h4
-rw-r--r--include/ports/SkFontMgr_android.h4
-rw-r--r--include/ports/SkFontMgr_custom.h8
-rw-r--r--include/ports/SkFontMgr_fontconfig.h4
-rw-r--r--include/ports/SkTypeface_win.h25
6 files changed, 57 insertions, 5 deletions
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<SkFontMgr> 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<SkFontMgr> 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<SkFontConfigInterface> fci);
+#else
+SK_API sk_sp<SkFontMgr> SkFontMgr_New_FCI(sk_sp<SkFontConfigInterface> 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> 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> 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> 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> 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<SkRemotableFontMgr>);
* If DirectWrite could not be initialized, will return NULL.
*/
SK_API SkRemotableFontMgr* SkRemotableFontMgr_New_DirectWrite();
+#else
+SK_API sk_sp<SkFontMgr> SkFontMgr_New_GDI();
+SK_API sk_sp<SkFontMgr> SkFontMgr_New_DirectWrite(IDWriteFactory* factory = NULL,
+ IDWriteFontCollection* collection = NULL);
+SK_API sk_sp<SkFontMgr> 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> SkFontMgr_New_DirectWriteRenderer(sk_sp<SkRemotableFontMgr>);
+
+/**
+ * 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> SkRemotableFontMgr_New_DirectWrite();
+#endif
#endif // SK_BUILD_FOR_WIN
#endif // SkTypeface_win_DEFINED