From bdf5433ab49b00df7c0f9185a68fc39f74cda409 Mon Sep 17 00:00:00 2001 From: Ben Wagner Date: Tue, 15 May 2018 14:12:14 -0400 Subject: [PATCH] SkImage::onRefEncoded to return sk_sp. This changes SkImage::onRefEncoded and downstack calls to return sk_sp. All of the values returned are already sk_sp, so this just updates the API. This change is currently behind the new flag SK_IGNORE_SKIMAGE_ONREFENCODED_CHANGE so that Chromium can be updated. Change-Id: Ic53a88ae23fa8b3b41b84c4abdc4b74e9879da38 Reviewed-on: https://skia-review.googlesource.com/128311 Reviewed-by: Leon Scroggins Commit-Queue: Ben Wagner --- include/core/SkData.h | 3 --- include/core/SkImageGenerator.h | 10 ++++++++++ src/codec/SkCodecImageGenerator.cpp | 6 ++++++ src/codec/SkCodecImageGenerator.h | 4 ++++ src/core/SkStreamPriv.h | 4 +--- src/image/SkImage_Base.h | 4 ++++ src/image/SkImage_Lazy.cpp | 11 +++++++++++ src/ports/SkImageGeneratorCG.cpp | 6 ++++++ src/ports/SkImageGeneratorCG.h | 4 ++++ src/ports/SkImageGeneratorWIC.cpp | 6 ++++++ src/ports/SkImageGeneratorWIC.h | 4 ++++ 11 files changed, 56 insertions(+), 6 deletions(-) diff --git a/include/core/SkData.h b/include/core/SkData.h index 0622c9f0fa..8eca45095f 100644 --- a/include/core/SkData.h +++ b/include/core/SkData.h @@ -171,9 +171,6 @@ private: // Ensure the unsized delete is called. void operator delete(void* p) { ::operator delete(p); } - // Called the first time someone calls NewEmpty to initialize the singleton. - friend SkData* sk_new_empty_data(); - // shared internal factory static sk_sp PrivateNewWithCopy(const void* srcOrNull, size_t length); diff --git a/include/core/SkImageGenerator.h b/include/core/SkImageGenerator.h index 2763ef9c33..6a9919ce1a 100644 --- a/include/core/SkImageGenerator.h +++ b/include/core/SkImageGenerator.h @@ -41,9 +41,15 @@ public: * If non-NULL is returned, the caller is responsible for calling * unref() on the data when it is finished. */ +#if SK_IGNORE_SKIMAGE_ONREFENCODED_CHANGE SkData* refEncodedData() { return this->onRefEncodedData(); } +#else + sk_sp refEncodedData() { + return this->onRefEncodedData(); + } +#endif /** * Return the ImageInfo associated with this generator. @@ -174,7 +180,11 @@ protected: SkImageGenerator(const SkImageInfo& info, uint32_t uniqueId = kNeedNewImageUniqueID); +#if SK_IGNORE_SKIMAGE_ONREFENCODED_CHANGE virtual SkData* onRefEncodedData() { return nullptr; } +#else + virtual sk_sp onRefEncodedData() { return nullptr; } +#endif virtual bool onGetPixels(const SkImageInfo&, void*, size_t, const Options&) { return false; } virtual bool onIsValid(GrContext*) const { return true; } virtual bool onQueryYUV8(SkYUVSizeInfo*, SkYUVColorSpace*) const { return false; } diff --git a/src/codec/SkCodecImageGenerator.cpp b/src/codec/SkCodecImageGenerator.cpp index 3f03b2f03e..65702616a3 100644 --- a/src/codec/SkCodecImageGenerator.cpp +++ b/src/codec/SkCodecImageGenerator.cpp @@ -35,9 +35,15 @@ SkCodecImageGenerator::SkCodecImageGenerator(std::unique_ptr codec, sk_ , fData(std::move(data)) {} +#if SK_IGNORE_SKIMAGE_ONREFENCODED_CHANGE SkData* SkCodecImageGenerator::onRefEncodedData() { return SkRef(fData.get()); } +#else +sk_sp SkCodecImageGenerator::onRefEncodedData() { + return fData; +} +#endif bool SkCodecImageGenerator::onGetPixels(const SkImageInfo& requestInfo, void* requestPixels, size_t requestRowBytes, const Options& opts) { diff --git a/src/codec/SkCodecImageGenerator.h b/src/codec/SkCodecImageGenerator.h index 1b2cbc28b2..e608d8e717 100644 --- a/src/codec/SkCodecImageGenerator.h +++ b/src/codec/SkCodecImageGenerator.h @@ -21,7 +21,11 @@ public: static std::unique_ptr MakeFromEncodedCodec(sk_sp); protected: +#if SK_IGNORE_SKIMAGE_ONREFENCODED_CHANGE SkData* onRefEncodedData() override; +#else + sk_sp onRefEncodedData() override; +#endif bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, const Options& opts) override; diff --git a/src/core/SkStreamPriv.h b/src/core/SkStreamPriv.h index ac822c1110..6bec5f8288 100644 --- a/src/core/SkStreamPriv.h +++ b/src/core/SkStreamPriv.h @@ -21,9 +21,7 @@ class SkWStream; * but is not at the beginning, this call will fail (return NULL). * * @param stream SkStream to be copied into data. - * @return SkData* The resulting SkData after the copy. This data - * will have a ref count of one upon return and belongs to the - * caller. Returns nullptr on failure. + * @return The resulting SkData after the copy, nullptr on failure. */ sk_sp SkCopyStreamToData(SkStream* stream); diff --git a/src/image/SkImage_Base.h b/src/image/SkImage_Base.h index c74a7b97e0..ba89585cf4 100644 --- a/src/image/SkImage_Base.h +++ b/src/image/SkImage_Base.h @@ -76,7 +76,11 @@ public: virtual sk_sp onMakeSubset(const SkIRect&) const = 0; +#if SK_IGNORE_SKIMAGE_ONREFENCODED_CHANGE virtual SkData* onRefEncoded() const { return nullptr; } +#else + virtual sk_sp onRefEncoded() const { return nullptr; } +#endif virtual bool onAsLegacyBitmap(SkBitmap*) const; diff --git a/src/image/SkImage_Lazy.cpp b/src/image/SkImage_Lazy.cpp index 9ca9d0d782..c627f2224e 100644 --- a/src/image/SkImage_Lazy.cpp +++ b/src/image/SkImage_Lazy.cpp @@ -85,7 +85,11 @@ public: sk_sp*, SkScalar scaleAdjust[2]) const override; #endif +#if SK_IGNORE_SKIMAGE_ONREFENCODED_CHANGE SkData* onRefEncoded() const override; +#else + sk_sp onRefEncoded() const override; +#endif sk_sp onMakeSubset(const SkIRect&) const override; bool getROPixels(SkBitmap*, SkColorSpace* dstColorSpace, CachingHint) const override; bool onIsLazyGenerated() const override { return true; } @@ -568,10 +572,17 @@ bool SkImage_Lazy::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, siz return false; } +#if SK_IGNORE_SKIMAGE_ONREFENCODED_CHANGE SkData* SkImage_Lazy::onRefEncoded() const { ScopedGenerator generator(fSharedGenerator); return generator->refEncodedData(); } +#else +sk_sp SkImage_Lazy::onRefEncoded() const { + ScopedGenerator generator(fSharedGenerator); + return generator->refEncodedData(); +} +#endif bool SkImage_Lazy::getROPixels(SkBitmap* bitmap, SkColorSpace* dstColorSpace, CachingHint chint) const { diff --git a/src/ports/SkImageGeneratorCG.cpp b/src/ports/SkImageGeneratorCG.cpp index 2d2c3d3bd5..c3d2f77cfe 100644 --- a/src/ports/SkImageGeneratorCG.cpp +++ b/src/ports/SkImageGeneratorCG.cpp @@ -97,9 +97,15 @@ SkImageGeneratorCG::SkImageGeneratorCG(const SkImageInfo& info, const void* imag , fOrigin(origin) {} +#if SK_IGNORE_SKIMAGE_ONREFENCODED_CHANGE SkData* SkImageGeneratorCG::onRefEncodedData() { return SkRef(fData.get()); } +#else +sk_sp SkImageGeneratorCG::onRefEncodedData() { + return fData; +} +#endif bool SkImageGeneratorCG::onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, const Options&) { diff --git a/src/ports/SkImageGeneratorCG.h b/src/ports/SkImageGeneratorCG.h index 58aac4f01a..4f5a3a98b3 100644 --- a/src/ports/SkImageGeneratorCG.h +++ b/src/ports/SkImageGeneratorCG.h @@ -27,7 +27,11 @@ public: static std::unique_ptr MakeFromEncodedCG(sk_sp); protected: +#if SK_IGNORE_SKIMAGE_ONREFENCODED_CHANGE SkData* onRefEncodedData() override; +#else + sk_sp onRefEncodedData() override; +#endif bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, const Options&) override; diff --git a/src/ports/SkImageGeneratorWIC.cpp b/src/ports/SkImageGeneratorWIC.cpp index e69b2ee2e9..19d4080960 100644 --- a/src/ports/SkImageGeneratorWIC.cpp +++ b/src/ports/SkImageGeneratorWIC.cpp @@ -132,9 +132,15 @@ SkImageGeneratorWIC::SkImageGeneratorWIC(const SkImageInfo& info, , fData(SkRef(data)) {} +#if SK_IGNORE_SKIMAGE_ONREFENCODED_CHANGE SkData* SkImageGeneratorWIC::onRefEncodedData() { return SkRef(fData.get()); } +#else +sk_sp SkImageGeneratorWIC::onRefEncodedData() { + return fData; +} +#endif bool SkImageGeneratorWIC::onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, const Options&) { diff --git a/src/ports/SkImageGeneratorWIC.h b/src/ports/SkImageGeneratorWIC.h index 4770ee2111..c0ace676f4 100644 --- a/src/ports/SkImageGeneratorWIC.h +++ b/src/ports/SkImageGeneratorWIC.h @@ -39,7 +39,11 @@ public: static SkImageGenerator* NewFromEncodedWIC(SkData* data); protected: +#if SK_IGNORE_SKIMAGE_ONREFENCODED_CHANGE SkData* onRefEncodedData() override; +#else + sk_sp onRefEncodedData() override; +#endif bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, const Options&) override;