diff options
author | bungeman <bungeman@google.com> | 2016-09-16 06:24:20 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-09-16 06:24:20 -0700 |
commit | f93d71122e4fcfcdc674a0163455990b13855f2f (patch) | |
tree | b3713fad2da586bf997264247961c1a91453c383 /include | |
parent | f560ef86813f712eff70feb9b00b70d0fe92c3cd (diff) |
SkFontData to use smart pointers.
The SkFontData type is not exposed externally, so any method which uses
it can be updated to use smart pointers without affecting external
users. Updating this first will make updating the public API much
easier.
This also updates SkStreamAsset* SkStream::NewFromFile(const char*) to
std::unique_ptr<SkStreamAsset> SkStream::MakeFromFile(const char*). It
appears that no one outside Skia is currently using SkStream::NewfromFile
so this is a good time to update it as well.
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2339273002
Committed: https://skia.googlesource.com/skia/+/d8c2476a8b1e1e1a1771b17e8dd4db8645914f8c
Review-Url: https://codereview.chromium.org/2339273002
Diffstat (limited to 'include')
-rw-r--r-- | include/core/SkStream.h | 6 | ||||
-rw-r--r-- | include/core/SkTypeface.h | 15 | ||||
-rw-r--r-- | include/ports/SkFontMgr.h | 8 | ||||
-rw-r--r-- | include/utils/mac/SkCGUtils.h | 16 |
4 files changed, 19 insertions, 26 deletions
diff --git a/include/core/SkStream.h b/include/core/SkStream.h index 48ac577070..7afce71240 100644 --- a/include/core/SkStream.h +++ b/include/core/SkStream.h @@ -40,11 +40,9 @@ public: virtual ~SkStream() {} /** - * Attempts to open the specified file, and return a stream to it (using - * mmap if available). On success, the caller is responsible for deleting. - * On failure, returns NULL. + * Attempts to open the specified file as a stream, returns nullptr on failure. */ - static SkStreamAsset* NewFromFile(const char path[]); + static std::unique_ptr<SkStreamAsset> MakeFromFile(const char path[]); /** Reads or skips size number of bytes. * If buffer == NULL, skip size bytes, return how many were skipped. diff --git a/include/core/SkTypeface.h b/include/core/SkTypeface.h index b2c288ebcd..deaa7140e6 100644 --- a/include/core/SkTypeface.h +++ b/include/core/SkTypeface.h @@ -150,10 +150,9 @@ public: #endif /** Return a new typeface given font data and configuration. If the data - is not valid font data, returns nullptr. Ownership of the font data is - transferred, so the caller must not reference it again. + is not valid font data, returns nullptr. */ - static sk_sp<SkTypeface> MakeFromFontData(SkFontData*); + static sk_sp<SkTypeface> MakeFromFontData(std::unique_ptr<SkFontData>); /** Write a unique signature to a stream, sufficient to reconstruct a typeface referencing the same font when Deserialize is called. @@ -300,10 +299,9 @@ public: SkStreamAsset* openStream(int* ttcIndex) const; /** - * Return the font data, or NULL on failure. - * The caller is responsible for deleting the font data. + * Return the font data, or nullptr on failure. */ - SkFontData* createFontData() const; + std::unique_ptr<SkFontData> makeFontData() const; /** * Return a scalercontext for the given descriptor. If this fails, then @@ -361,7 +359,10 @@ protected: virtual SkStreamAsset* onOpenStream(int* ttcIndex) const = 0; // TODO: make pure virtual. - virtual SkFontData* onCreateFontData() const; + virtual std::unique_ptr<SkFontData> onMakeFontData() const; +#ifdef SK_DECLARE_LEGACY_CREATE_FROM_FONTDATA + virtual SkFontData* onCreateFontData() const { return nullptr; }; +#endif virtual void onGetFontDescriptor(SkFontDescriptor*, bool* isLocal) const = 0; diff --git a/include/ports/SkFontMgr.h b/include/ports/SkFontMgr.h index a5b78c6241..28e374f753 100644 --- a/include/ports/SkFontMgr.h +++ b/include/ports/SkFontMgr.h @@ -150,11 +150,10 @@ public: /** * Create a typeface from the specified font data. - * Takes ownership of the font data, so the caller should not reference it again. * Will return NULL if the typeface could not be created. * The caller must call unref() on the returned object if it is not null. */ - SkTypeface* createFromFontData(SkFontData*) const; + SkTypeface* createFromFontData(std::unique_ptr<SkFontData>) const; /** * Create a typeface for the specified fileName and TTC index @@ -192,7 +191,10 @@ protected: virtual SkTypeface* onCreateFromStream(SkStreamAsset*, int ttcIndex) const = 0; // TODO: make pure virtual. virtual SkTypeface* onCreateFromStream(SkStreamAsset*, const FontParameters&) const; - virtual SkTypeface* onCreateFromFontData(SkFontData*) const; + virtual SkTypeface* onCreateFromFontData(std::unique_ptr<SkFontData>) const; +#ifdef SK_DECLARE_LEGACY_CREATE_FROM_FONTDATA + virtual SkTypeface* onCreateFromFontData(SkFontData*) const { return nullptr; }; +#endif virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const = 0; virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle) const = 0; diff --git a/include/utils/mac/SkCGUtils.h b/include/utils/mac/SkCGUtils.h index 3d9aff4451..29df8b81a8 100644 --- a/include/utils/mac/SkCGUtils.h +++ b/include/utils/mac/SkCGUtils.h @@ -23,7 +23,7 @@ class SkBitmap; class SkData; -class SkStream; +class SkStreamRewindable; /** * Given a CGImage, allocate an SkBitmap and copy the image's pixels into it. If scaleToFit is not @@ -65,20 +65,12 @@ static inline CGImageRef SkCreateCGImageRef(const SkBitmap& bm) { void SkCGDrawBitmap(CGContextRef, const SkBitmap&, float x, float y); /** - * Create an SkBitmap drawing of the encoded PDF document, returning true on - * success. Deletes the stream when finished. - */ -bool SkPDFDocumentToBitmap(SkStream* stream, SkBitmap* output); - -/** - * Return a provider that wraps the specified stream. It will become the only - * owner of the stream, so the caller must stop referring to the stream. - * + * Return a provider that wraps the specified stream. * When the provider is finally deleted, it will delete the stream. */ -CGDataProviderRef SkCreateDataProviderFromStream(SkStream*); +CGDataProviderRef SkCreateDataProviderFromStream(std::unique_ptr<SkStreamRewindable>); -CGDataProviderRef SkCreateDataProviderFromData(SkData*); +CGDataProviderRef SkCreateDataProviderFromData(sk_sp<SkData>); #endif // defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) #endif // SkCGUtils_DEFINED |