diff options
author | Mike Reed <reed@google.com> | 2017-07-11 16:03:13 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-07-12 15:44:35 +0000 |
commit | 6409f84fc3ae5e3b2df9eb0a900957fce404ad5c (patch) | |
tree | 41575591d345bf205d84d6d9e52a0e76c231be7d /src/image | |
parent | ebb38256c65f2d799dd64f0274256a0c1deffed1 (diff) |
Revert "Revert "Change image encode api to return sk_sp""
This reverts commit 64778d9f275d8ce3df8f4ab39ff334b7ef5b70d3.
Bug: skia:
Change-Id: I779515ff1e16a40c33890a4bac7a8a07171aadfe
Reviewed-on: https://skia-review.googlesource.com/22261
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'src/image')
-rw-r--r-- | src/image/SkImage.cpp | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp index 9dcf3d74dc..8cb526746c 100644 --- a/src/image/SkImage.cpp +++ b/src/image/SkImage.cpp @@ -94,21 +94,21 @@ sk_sp<SkShader> SkImage::makeShader(SkShader::TileMode tileX, SkShader::TileMode return SkImageShader::Make(sk_ref_sp(const_cast<SkImage*>(this)), tileX, tileY, localMatrix); } -SkData* SkImage::encode(SkEncodedImageFormat type, int quality) const { +sk_sp<SkData> SkImage::encodeToData(SkEncodedImageFormat type, int quality) const { SkBitmap bm; SkColorSpace* legacyColorSpace = nullptr; if (as_IB(this)->getROPixels(&bm, legacyColorSpace)) { SkDynamicMemoryWStream buf; - return SkEncodeImage(&buf, bm, type, quality) ? buf.detachAsData().release() : nullptr; + return SkEncodeImage(&buf, bm, type, quality) ? buf.detachAsData() : nullptr; } return nullptr; } -SkData* SkImage::encode(SkPixelSerializer* serializer) const { - sk_sp<SkData> encoded(this->refEncoded()); +sk_sp<SkData> SkImage::encodeToData(SkPixelSerializer* serializer) const { + sk_sp<SkData> encoded(this->refEncodedData()); if (encoded && (!serializer || serializer->useEncodedData(encoded->data(), encoded->size()))) { - return encoded.release(); + return encoded; } SkBitmap bm; @@ -116,19 +116,19 @@ SkData* SkImage::encode(SkPixelSerializer* serializer) const { SkColorSpace* legacyColorSpace = nullptr; if (as_IB(this)->getROPixels(&bm, legacyColorSpace) && bm.peekPixels(&pmap)) { if (serializer) { - return serializer->encode(pmap); + return serializer->encodeToData(pmap); } else { SkDynamicMemoryWStream buf; return SkEncodeImage(&buf, pmap, SkEncodedImageFormat::kPNG, 100) - ? buf.detachAsData().release() : nullptr; + ? buf.detachAsData() : nullptr; } } return nullptr; } -SkData* SkImage::refEncoded() const { - return as_IB(this)->onRefEncoded(); +sk_sp<SkData> SkImage::refEncodedData() const { + return sk_sp<SkData>(as_IB(this)->onRefEncoded()); } sk_sp<SkImage> SkImage::MakeFromEncoded(sk_sp<SkData> encoded, const SkIRect* subset) { @@ -138,6 +138,23 @@ sk_sp<SkImage> SkImage::MakeFromEncoded(sk_sp<SkData> encoded, const SkIRect* su return SkImage::MakeFromGenerator(SkImageGenerator::MakeFromEncoded(encoded), subset); } +#ifdef SK_SUPPORT_LEGACY_IMAGE_ENCODE_API +SkData* SkImage::encode(SkEncodedImageFormat format, int quality) const { + return this->encodeToData(format, quality).release(); +} +SkData* SkImage::encode(SkPixelSerializer* serial) const { + return this->encodeToData(serial).release(); +} +SkData* SkImage::refEncoded() const { + return this->refEncodedData().release(); +} +SkData* SkPixelSerializer::encode(const SkPixmap& pixmap) { + return this->encodeToData(pixmap).release(); +} +#endif + +/////////////////////////////////////////////////////////////////////////////////////////////////// + const char* SkImage::toString(SkString* str) const { str->appendf("image: (id:%d (%d, %d) %s)", this->uniqueID(), this->width(), this->height(), this->isOpaque() ? "opaque" : ""); |