From 2be7125f3274a4b661f50e992fc0eb3c14c24f05 Mon Sep 17 00:00:00 2001 From: fmalita Date: Thu, 3 Sep 2015 07:17:25 -0700 Subject: Add a SkPixelSerializer SkImage encode variant R=reed@google.com BUG=skia:4285 Review URL: https://codereview.chromium.org/1310633006 --- include/core/SkImage.h | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/core/SkImage.h b/include/core/SkImage.h index 2bcb90b5d3..b302792c58 100644 --- a/include/core/SkImage.h +++ b/include/core/SkImage.h @@ -21,6 +21,7 @@ class SkColorTable; class SkImageGenerator; class SkPaint; class SkPicture; +class SkPixelSerializer; class SkString; class SkSurface; class SkSurfaceProps; @@ -234,12 +235,27 @@ public: * * If the image type cannot be encoded, or the requested encoder type 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(SkImageEncoder::Type, int quality) const; - SkData* encode() const { - return this->encode(SkImageEncoder::kPNG_Type, 100); - } + /** + * Encode the image and return the result as a caller-managed SkData. This will + * attempt to reuse existing encoded data (as returned by refEncoded). + * + * We defer to the SkPixelSerializer both for vetting existing encoded data + * (useEncodedData) and for encoding the image (encodePixels) when no such data is + * present or is rejected by the serializer. + * + * If not specified, we use a default serializer which 1) always accepts existing data + * (in any format) and 2) encodes to PNG. + * + * If no compatible encoded data exists and encoding fails, this method will also + * fail (return NULL). + */ + SkData* encode(SkPixelSerializer* = nullptr) const; /** * If the image already has its contents in encoded form (e.g. PNG or JPEG), return a ref -- cgit v1.2.3