diff options
author | Mike Reed <reed@google.com> | 2017-12-16 08:41:28 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-12-16 14:21:32 +0000 |
commit | ef0384835757df463f5157145650a60ba8b14a63 (patch) | |
tree | d33ade7923e75b2166f891cf1cbbd2a2ef18c4b8 | |
parent | 594706566a62da1e00fa1bb678cc84c36464e811 (diff) |
remove deprecated SkPixelSerializer
Bug: skia:
Change-Id: I25d33517f1ec7c08551c79d03763c676d1a662f5
Reviewed-on: https://skia-review.googlesource.com/86360
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
-rw-r--r-- | debugger/QT/SkDebuggerGUI.cpp | 5 | ||||
-rw-r--r-- | include/core/SkImage.h | 22 | ||||
-rw-r--r-- | include/core/SkPicture.h | 15 | ||||
-rw-r--r-- | include/core/SkPixelSerializer.h | 51 | ||||
-rw-r--r-- | include/core/SkWriteBuffer.h | 6 | ||||
-rw-r--r-- | src/core/SkPicture.cpp | 34 | ||||
-rw-r--r-- | src/core/SkPictureCommon.h | 1 | ||||
-rw-r--r-- | src/image/SkImage.cpp | 13 | ||||
-rw-r--r-- | tests/ImageTest.cpp | 73 | ||||
-rw-r--r-- | tests/PDFDocumentTest.cpp | 1 | ||||
-rw-r--r-- | tests/PictureTest.cpp | 1 | ||||
-rw-r--r-- | tools/get_images_from_skps.cpp | 20 | ||||
-rw-r--r-- | tools/sk_tool_utils.h | 15 | ||||
-rw-r--r-- | tools/skiaserve/Request.cpp | 10 |
14 files changed, 44 insertions, 223 deletions
diff --git a/debugger/QT/SkDebuggerGUI.cpp b/debugger/QT/SkDebuggerGUI.cpp index 601318334a..b8b9bb1b2f 100644 --- a/debugger/QT/SkDebuggerGUI.cpp +++ b/debugger/QT/SkDebuggerGUI.cpp @@ -279,10 +279,7 @@ void SkDebuggerGUI::drawComplete() { void SkDebuggerGUI::saveToFile(const SkString& filename) { SkFILEWStream file(filename.c_str()); - sk_sp<SkPicture> copy(fDebugger.copyPicture()); - - sk_sp<SkPixelSerializer> serializer(sk_tool_utils::MakePixelSerializer()); - copy->serialize(&file, serializer.get()); + fDebugger.copyPicture()->serialize(&file); } void SkDebuggerGUI::loadFile(QListWidgetItem *item) { diff --git a/include/core/SkImage.h b/include/core/SkImage.h index c0f8272c48..03d463d098 100644 --- a/include/core/SkImage.h +++ b/include/core/SkImage.h @@ -24,7 +24,6 @@ class SkCanvas; class SkImageGenerator; class SkPaint; class SkPicture; -class SkPixelSerializer; class SkString; class SkSurface; class GrBackendTexture; @@ -352,28 +351,21 @@ public: CachingHint cachingHint = kAllow_CachingHint) const; /** - * Encode the image's pixels and return the result as SkData. + * Encode the image's pixels and return the result as SkData. This will ignore any possible + * existing encoded data (see refEncodedData()), and will always attempt to encode the + * image using the specified encoded image format. * * If the image type cannot be encoded, or the requested encoder format is - * not supported, this will return NULL. + * not supported, this will return nullptr. */ sk_sp<SkData> encodeToData(SkEncodedImageFormat encodedImageFormat, int quality) const; /** * 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 - * 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). + * encoded data (as returned by refEncodedData). If there is no eisting data, the image + * will be encoded using PNG. On an error, this returns nullptr. */ - sk_sp<SkData> encodeToData(SkPixelSerializer* pixelSerializer = nullptr) const; + sk_sp<SkData> encodeToData() const; /** * If the image already has its contents in encoded form (e.g. PNG or JPEG), return that diff --git a/include/core/SkPicture.h b/include/core/SkPicture.h index 016be3759a..8edd183ede 100644 --- a/include/core/SkPicture.h +++ b/include/core/SkPicture.h @@ -21,7 +21,6 @@ struct SkDeserialProcs; class SkImage; class SkPath; class SkPictureData; -class SkPixelSerializer; class SkReadBuffer; class SkRefCntSet; struct SkSerialProcs; @@ -107,21 +106,11 @@ public: /** Returns a non-zero value unique among all pictures. */ uint32_t uniqueID() const; - /** - * Serialize the picture to SkData. If non nullptr, pixel-serializer will be used to - * customize how images reference by the picture are serialized/compressed. - */ - sk_sp<SkData> serialize(SkPixelSerializer* = nullptr) const; - + sk_sp<SkData> serialize() const; + void serialize(SkWStream*) const; sk_sp<SkData> serialize(const SkSerialProcs&) const; /** - * Serialize to a stream. If non nullptr, pixel-serializer will be used to - * customize how images reference by the picture are serialized/compressed. - */ - void serialize(SkWStream*, SkPixelSerializer* = nullptr) const; - - /** * Serialize to a buffer. */ void flatten(SkWriteBuffer&) const; diff --git a/include/core/SkPixelSerializer.h b/include/core/SkPixelSerializer.h deleted file mode 100644 index 28d5f5d2e6..0000000000 --- a/include/core/SkPixelSerializer.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2014 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkPixelSerializer_DEFINED -#define SkPixelSerializer_DEFINED - -#include "SkData.h" -#include "SkPixmap.h" -#include "SkRefCnt.h" - -/** - * Interface for serializing pixels, e.g. SkBitmaps in an SkPicture. - */ -class SkPixelSerializer : public SkRefCnt { -public: - virtual ~SkPixelSerializer() {} - - /** - * Call to determine if the client wants to serialize the encoded data. If - * false, serialize another version (e.g. the result of encodePixels). - */ - bool useEncodedData(const void* data, size_t len) { - return this->onUseEncodedData(data, len); - } - - /** - * Call to get the client's version of encoding these pixels. If it - * returns NULL, serialize the raw pixels. - */ - sk_sp<SkData> encodeToData(const SkPixmap& pixmap) { - return sk_sp<SkData>(this->onEncode(pixmap)); - } - -protected: - /** - * Return true if you want to serialize the encoded data, false if you want - * another version serialized (e.g. the result of this->encode()). - */ - virtual bool onUseEncodedData(const void* data, size_t len) = 0; - - /** - * If you want to encode these pixels, return the encoded data as an SkData - * Return null if you want to serialize the raw pixels. - */ - virtual SkData* onEncode(const SkPixmap&) = 0; -}; -#endif // SkPixelSerializer_DEFINED diff --git a/include/core/SkWriteBuffer.h b/include/core/SkWriteBuffer.h index 0b1ae0c1aa..5d03e91caa 100644 --- a/include/core/SkWriteBuffer.h +++ b/include/core/SkWriteBuffer.h @@ -18,8 +18,6 @@ #include "SkWriter32.h" #include "../private/SkTHash.h" -#include "SkPixelSerializer.h" - class SkBitmap; class SkDeduper; class SkFactorySet; @@ -153,8 +151,6 @@ public: SkFactorySet* setFactoryRecorder(SkFactorySet*); SkRefCntSet* setTypefaceRecorder(SkRefCntSet*); - void setPixelSerializer(sk_sp<SkPixelSerializer>); - private: const uint32_t fFlags; SkFactorySet* fFactorySet; @@ -164,8 +160,6 @@ private: // Only used if we do not have an fFactorySet SkTHashMap<SkString, uint32_t> fFlattenableDict; - - sk_sp<SkPixelSerializer> fPS; }; #endif // SkWriteBuffer_DEFINED diff --git a/src/core/SkPicture.cpp b/src/core/SkPicture.cpp index ba1f228a63..e12c059228 100644 --- a/src/core/SkPicture.cpp +++ b/src/core/SkPicture.cpp @@ -242,18 +242,13 @@ SkPictureData* SkPicture::backport() const { return new SkPictureData(rec, info); } -void SkPicture::serialize(SkWStream* stream, SkPixelSerializer* pixelSerializer) const { - SkSerialProcs procs; - if (pixelSerializer) { - procs.fImageProc = PixelSerializer_SkSerialImageProc; - procs.fImageCtx = pixelSerializer; - } - this->serialize(stream, procs, nullptr); +void SkPicture::serialize(SkWStream* stream) const { + this->serialize(stream, SkSerialProcs(), nullptr); } -sk_sp<SkData> SkPicture::serialize(SkPixelSerializer* pixelSerializer) const { +sk_sp<SkData> SkPicture::serialize() const { SkDynamicMemoryWStream stream; - this->serialize(&stream, pixelSerializer); + this->serialize(&stream); return stream.detachAsData(); } @@ -356,24 +351,3 @@ void SkPicture::SetPictureIOSecurityPrecautionsEnabled_Dangerous(bool set) { bool SkPicture::PictureIOSecurityPrecautionsEnabled() { return g_AllPictureIOSecurityPrecautionsEnabled; } - -////////////////////////////////////////////////////////////////////////////////////////////////// - -#include "SkReadBuffer.h" -#include "SkWriteBuffer.h" - -sk_sp<SkData> PixelSerializer_SkSerialImageProc(SkImage* img, void* ctx) { - SkASSERT(ctx); - return img->encodeToData(static_cast<SkPixelSerializer*>(ctx)); -} -void SkBinaryWriteBuffer::setPixelSerializer(sk_sp<SkPixelSerializer> ps) { - fPS = ps; - if (ps) { - fProcs.fImageProc = PixelSerializer_SkSerialImageProc; - fProcs.fImageCtx = ps.get(); - } else { - fProcs.fImageProc = nullptr; - fProcs.fImageCtx = nullptr; - } -} - diff --git a/src/core/SkPictureCommon.h b/src/core/SkPictureCommon.h index c282f01fec..23d43fd65b 100644 --- a/src/core/SkPictureCommon.h +++ b/src/core/SkPictureCommon.h @@ -142,7 +142,6 @@ struct SkPathCounter { int fNumSlowPathsAndDashEffects; }; -sk_sp<SkData> PixelSerializer_SkSerialImageProc(SkImage*, void* pixelserializer); sk_sp<SkImage> ImageDeserializer_SkDeserialImageProc(const void*, size_t, void* imagedeserializer); #endif // SkPictureCommon_DEFINED diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp index 2fcb34f865..09796cdd34 100644 --- a/src/image/SkImage.cpp +++ b/src/image/SkImage.cpp @@ -20,7 +20,6 @@ #include "SkNextID.h" #include "SkPicture.h" #include "SkPixelRef.h" -#include "SkPixelSerializer.h" #include "SkReadPixelsRec.h" #include "SkSpecialImage.h" #include "SkString.h" @@ -102,10 +101,8 @@ sk_sp<SkData> SkImage::encodeToData(SkEncodedImageFormat type, int quality) cons return nullptr; } -sk_sp<SkData> SkImage::encodeToData(SkPixelSerializer* serializer) const { - sk_sp<SkData> encoded(this->refEncodedData()); - if (encoded && - (!serializer || serializer->useEncodedData(encoded->data(), encoded->size()))) { +sk_sp<SkData> SkImage::encodeToData() const { + if (auto encoded = this->refEncodedData()) { return encoded; } @@ -113,11 +110,7 @@ sk_sp<SkData> SkImage::encodeToData(SkPixelSerializer* serializer) const { SkPixmap pmap; SkColorSpace* legacyColorSpace = nullptr; if (as_IB(this)->getROPixels(&bm, legacyColorSpace) && bm.peekPixels(&pmap)) { - if (serializer) { - return serializer->encodeToData(pmap); - } else { - return SkEncodePixmap(pmap, SkEncodedImageFormat::kPNG, 100); - } + return SkEncodePixmap(pmap, SkEncodedImageFormat::kPNG, 100); } return nullptr; } diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp index 31a5909d66..1415bcb67d 100644 --- a/tests/ImageTest.cpp +++ b/tests/ImageTest.cpp @@ -21,8 +21,8 @@ #include "SkMakeUnique.h" #include "SkPicture.h" #include "SkPictureRecorder.h" -#include "SkPixelSerializer.h" #include "SkRRect.h" +#include "SkSerialProcs.h" #include "SkStream.h" #include "SkSurface.h" #include "SkUtils.h" @@ -221,50 +221,6 @@ DEF_TEST(Image_MakeFromRasterBitmap, reporter) { } } -namespace { - -const char* kSerializedData = "serialized"; - -class MockSerializer : public SkPixelSerializer { -public: - MockSerializer(sk_sp<SkData> (*func)()) : fFunc(func), fDidEncode(false) { } - - bool didEncode() const { return fDidEncode; } - -protected: - bool onUseEncodedData(const void*, size_t) override { - return false; - } - - SkData* onEncode(const SkPixmap&) override { - fDidEncode = true; - return fFunc().release(); - } - -private: - sk_sp<SkData> (*fFunc)(); - bool fDidEncode; - - typedef SkPixelSerializer INHERITED; -}; - -} // anonymous namespace - -// Test that SkImage encoding observes custom pixel serializers. -DEF_TEST(Image_Encode_Serializer, reporter) { - MockSerializer serializer([]() -> sk_sp<SkData> { - return SkData::MakeWithCString(kSerializedData); - }); - sk_sp<SkImage> image(create_image()); - sk_sp<SkData> encoded = image->encodeToData(&serializer); - sk_sp<SkData> reference(SkData::MakeWithCString(kSerializedData)); - - REPORTER_ASSERT(reporter, serializer.didEncode()); - REPORTER_ASSERT(reporter, encoded); - REPORTER_ASSERT(reporter, encoded->size() > 0); - REPORTER_ASSERT(reporter, encoded->equals(reference.get())); -} - // Test that image encoding failures do not break picture serialization/deserialization. DEF_TEST(Image_Serialize_Encoding_Failure, reporter) { auto surface(SkSurface::MakeRasterN32Premul(100, 100)); @@ -279,21 +235,22 @@ DEF_TEST(Image_Serialize_Encoding_Failure, reporter) { REPORTER_ASSERT(reporter, picture); REPORTER_ASSERT(reporter, picture->approximateOpCount() > 0); - MockSerializer emptySerializer([]() -> sk_sp<SkData> { return SkData::MakeEmpty(); }); - MockSerializer nullSerializer([]() -> sk_sp<SkData> { return nullptr; }); - MockSerializer* serializers[] = { &emptySerializer, &nullSerializer }; + bool was_called = false; + SkSerialProcs procs; + procs.fImageProc = [](SkImage*, void* called) { + *(bool*)called = true; + return SkData::MakeEmpty(); + }; + procs.fImageCtx = &was_called; - for (size_t i = 0; i < SK_ARRAY_COUNT(serializers); ++i) { - SkDynamicMemoryWStream wstream; - REPORTER_ASSERT(reporter, !serializers[i]->didEncode()); - picture->serialize(&wstream, serializers[i]); - REPORTER_ASSERT(reporter, serializers[i]->didEncode()); + REPORTER_ASSERT(reporter, !was_called); + auto data = picture->serialize(procs); + REPORTER_ASSERT(reporter, was_called); + REPORTER_ASSERT(reporter, data && data->size() > 0); - std::unique_ptr<SkStream> rstream(wstream.detachAsStream()); - sk_sp<SkPicture> deserialized(SkPicture::MakeFromStream(rstream.get())); - REPORTER_ASSERT(reporter, deserialized); - REPORTER_ASSERT(reporter, deserialized->approximateOpCount() > 0); - } + auto deserialized = SkPicture::MakeFromData(data->data(), data->size()); + REPORTER_ASSERT(reporter, deserialized); + REPORTER_ASSERT(reporter, deserialized->approximateOpCount() > 0); } // Test that a draw that only partially covers the drawing surface isn't diff --git a/tests/PDFDocumentTest.cpp b/tests/PDFDocumentTest.cpp index d92929ea89..c88012291c 100644 --- a/tests/PDFDocumentTest.cpp +++ b/tests/PDFDocumentTest.cpp @@ -12,7 +12,6 @@ #include "SkOSFile.h" #include "SkOSPath.h" #include "SkStream.h" -#include "SkPixelSerializer.h" #include "sk_tool_utils.h" diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp index 19032a1537..7f83e139c0 100644 --- a/tests/PictureTest.cpp +++ b/tests/PictureTest.cpp @@ -22,7 +22,6 @@ #include "SkPictureAnalyzer.h" #include "SkPictureRecorder.h" #include "SkPixelRef.h" -#include "SkPixelSerializer.h" #include "SkMiniRecorder.h" #include "SkRRect.h" #include "SkRandom.h" diff --git a/tools/get_images_from_skps.cpp b/tools/get_images_from_skps.cpp index 0a2164cf39..c81254f2c7 100644 --- a/tools/get_images_from_skps.cpp +++ b/tools/get_images_from_skps.cpp @@ -15,7 +15,7 @@ #include "SkOSFile.h" #include "SkOSPath.h" #include "SkPicture.h" -#include "SkPixelSerializer.h" +#include "SkSerialProcs.h" #include "SkStream.h" #include "SkTHash.h" @@ -41,7 +41,7 @@ static std::map<std::string, unsigned int> gSkpToUnsupportedCount; static SkTHashSet<SkMD5::Digest> gSeen; -struct Sniffer : public SkPixelSerializer { +struct Sniffer { std::string skpName; @@ -122,12 +122,6 @@ struct Sniffer : public SkPixelSerializer { gKnown++; } - - bool onUseEncodedData(const void* ptr, size_t len) override { - this->sniff(ptr, len); - return true; - } - SkData* onEncode(const SkPixmap&) override { return nullptr; } }; static bool get_images_from_file(const SkString& file) { @@ -139,7 +133,15 @@ static bool get_images_from_file(const SkString& file) { SkDynamicMemoryWStream scratch; Sniffer sniff(file.c_str()); - picture->serialize(&scratch, &sniff); + SkSerialProcs procs; + procs.fImageProc = [](SkImage* image, void* ctx) { + if (auto data = image->refEncodedData()) { + ((Sniffer*)ctx)->sniff(data->data(), data->size()); + } + return SkData::MakeEmpty(); + }; + procs.fImageCtx = &sniff; + picture->serialize(procs); return true; } diff --git a/tools/sk_tool_utils.h b/tools/sk_tool_utils.h index b81610bc4f..0741b19644 100644 --- a/tools/sk_tool_utils.h +++ b/tools/sk_tool_utils.h @@ -11,7 +11,6 @@ #include "SkColor.h" #include "SkImageEncoder.h" #include "SkImageInfo.h" -#include "SkPixelSerializer.h" #include "SkRandom.h" #include "SkStream.h" #include "SkTDArray.h" @@ -244,20 +243,6 @@ namespace sk_tool_utils { return SkEncodeImage(&buf, src , f, q) ? buf.detachAsData() : nullptr; } - /** - * Uses SkEncodeImage to serialize images that are not already - * encoded as SkEncodedImageFormat::kPNG images. - */ - inline sk_sp<SkPixelSerializer> MakePixelSerializer() { - struct EncodeImagePixelSerializer final : SkPixelSerializer { - bool onUseEncodedData(const void*, size_t) override { return true; } - SkData* onEncode(const SkPixmap& pmap) override { - return EncodeImageToData(pmap, SkEncodedImageFormat::kPNG, 100).release(); - } - }; - return sk_make_sp<EncodeImagePixelSerializer>(); - } - bool copy_to(SkBitmap* dst, SkColorType dstCT, const SkBitmap& src); void copy_to_g8(SkBitmap* dst, const SkBitmap& src); diff --git a/tools/skiaserve/Request.cpp b/tools/skiaserve/Request.cpp index 6a0f4df0a9..6081c05c74 100644 --- a/tools/skiaserve/Request.cpp +++ b/tools/skiaserve/Request.cpp @@ -8,7 +8,6 @@ #include "Request.h" #include "SkPictureRecorder.h" -#include "SkPixelSerializer.h" #include "SkPM4fPriv.h" #include "picture_utils.h" #include "sk_tool_utils.h" @@ -114,14 +113,7 @@ sk_sp<SkData> Request::writeOutSkp() { fDebugCanvas->draw(canvas); - sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); - - SkDynamicMemoryWStream outStream; - - sk_sp<SkPixelSerializer> serializer = sk_tool_utils::MakePixelSerializer(); - picture->serialize(&outStream, serializer.get()); - - return outStream.detachAsData(); + return recorder.finishRecordingAsPicture()->serialize(); } GrContext* Request::getContext() { |