diff options
author | Mike Reed <reed@google.com> | 2017-07-11 11:20:21 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-07-11 15:43:21 +0000 |
commit | dc799550e2d9965aa5b7cda496465b2a76b310a5 (patch) | |
tree | 9f5f2a1c9da5bbeab2363bae6bd8cd933019dfc3 /include/core | |
parent | f02fa6ffe72c596b87e277193ed82d288dbee18f (diff) |
Change image encode api to return sk_sp
Bug: skia:
Change-Id: I238289bc630be27795cb1384955dd6e887597c05
Reviewed-on: https://skia-review.googlesource.com/22208
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'include/core')
-rw-r--r-- | include/core/SkImage.h | 31 | ||||
-rw-r--r-- | include/core/SkPixelSerializer.h | 10 |
2 files changed, 24 insertions, 17 deletions
diff --git a/include/core/SkImage.h b/include/core/SkImage.h index bdb04ff766..fcee19df98 100644 --- a/include/core/SkImage.h +++ b/include/core/SkImage.h @@ -359,20 +359,16 @@ public: bool scalePixels(const SkPixmap& dst, SkFilterQuality, CachingHint = kAllow_CachingHint) const; /** - * Encode the image's pixels and return the result as a new SkData, which - * the caller must manage (i.e. call unref() when they are done). + * Encode the image's pixels and return the result as SkData. * - * If the image type cannot be encoded, or the requested encoder type is + * If the image type cannot be encoded, or the requested encoder format is * not supported, this will return NULL. - * - * Note: this will attempt to encode the image's pixels in the specified format, - * even if the image returns a data from refEncoded(). That data will be ignored. */ - SkData* encode(SkEncodedImageFormat, int quality) const; + sk_sp<SkData> encodeToData(SkEncodedImageFormat, int quality) const; /** - * Encode the image and return the result as a caller-managed SkData. This will - * attempt to reuse existing encoded data (as returned by refEncoded). + * Encode the image and return the result as SkData. This will attempt to reuse existing + * encoded data (as returned by refEncodedData). * * We defer to the SkPixelSerializer both for vetting existing encoded data * (useEncodedData) and for encoding the image (encode) when no such data is @@ -384,18 +380,21 @@ public: * If no compatible encoded data exists and encoding fails, this method will also * fail (return NULL). */ - SkData* encode(SkPixelSerializer* = nullptr) const; + sk_sp<SkData> encodeToData(SkPixelSerializer* = nullptr) const; /** - * If the image already has its contents in encoded form (e.g. PNG or JPEG), return a ref - * to that data (which the caller must call unref() on). The caller is responsible for calling - * unref on the data when they are done. - * - * If the image does not already has its contents in encoded form, return NULL. + * If the image already has its contents in encoded form (e.g. PNG or JPEG), return that + * as SkData. If the image does not already has its contents in encoded form, return NULL. * - * Note: to force the image to return its contents as encoded data, try calling encode(...). + * Note: to force the image to return its contents as encoded data, use encodeToData(...). */ + sk_sp<SkData> refEncodedData() const; + +#ifdef SK_SUPPORT_LEGACY_IMAGE_ENCODE_API + SkData* encode(SkEncodedImageFormat, int quality) const; + SkData* encode(SkPixelSerializer* = nullptr) const; SkData* refEncoded() const; +#endif const char* toString(SkString*) const; diff --git a/include/core/SkPixelSerializer.h b/include/core/SkPixelSerializer.h index b168f79dd1..05054557f6 100644 --- a/include/core/SkPixelSerializer.h +++ b/include/core/SkPixelSerializer.h @@ -32,7 +32,15 @@ public: * Call to get the client's version of encoding these pixels. If it * returns NULL, serialize the raw pixels. */ - SkData* encode(const SkPixmap& pixmap) { return this->onEncode(pixmap); } + sk_sp<SkData> encodeToData(const SkPixmap& pixmap) { + return sk_sp<SkData>(this->onEncode(pixmap)); + } + +#ifdef SK_SUPPORT_LEGACY_IMAGE_ENCODE_API + SkData* encode(const SkPixmap& pixmap) { + return this->encodeToData(pixmap).release(); + } +#endif protected: /** |