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>
diff --git a/debugger/QT/SkDebuggerGUI.cpp b/debugger/QT/SkDebuggerGUI.cpp
index 6013183..b8b9bb1 100644
--- a/debugger/QT/SkDebuggerGUI.cpp
+++ b/debugger/QT/SkDebuggerGUI.cpp
@@ -279,10 +279,7 @@
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 c0f8272..03d463d 100644
--- a/include/core/SkImage.h
+++ b/include/core/SkImage.h
@@ -24,7 +24,6 @@
class SkImageGenerator;
class SkPaint;
class SkPicture;
-class SkPixelSerializer;
class SkString;
class SkSurface;
class GrBackendTexture;
@@ -352,28 +351,21 @@
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 016be37..8edd183 100644
--- a/include/core/SkPicture.h
+++ b/include/core/SkPicture.h
@@ -21,7 +21,6 @@
class SkImage;
class SkPath;
class SkPictureData;
-class SkPixelSerializer;
class SkReadBuffer;
class SkRefCntSet;
struct SkSerialProcs;
@@ -107,21 +106,11 @@
/** 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 28d5f5d..0000000
--- 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 0b1ae0c..5d03e91 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 @@
SkFactorySet* setFactoryRecorder(SkFactorySet*);
SkRefCntSet* setTypefaceRecorder(SkRefCntSet*);
- void setPixelSerializer(sk_sp<SkPixelSerializer>);
-
private:
const uint32_t fFlags;
SkFactorySet* fFactorySet;
@@ -164,8 +160,6 @@
// 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 ba1f228..e12c059 100644
--- a/src/core/SkPicture.cpp
+++ b/src/core/SkPicture.cpp
@@ -242,18 +242,13 @@
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 @@
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 c282f01..23d43fd 100644
--- a/src/core/SkPictureCommon.h
+++ b/src/core/SkPictureCommon.h
@@ -142,7 +142,6 @@
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 2fcb34f..09796cd 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 @@
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 @@
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 31a5909..1415bcb 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 @@
}
}
-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 @@
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 d92929e..c880122 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 19032a1..7f83e13 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 0a2164cf..c81254f 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 SkTHashSet<SkMD5::Digest> gSeen;
-struct Sniffer : public SkPixelSerializer {
+struct Sniffer {
std::string skpName;
@@ -122,12 +122,6 @@
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 @@
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 b81610b..0741b19 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 @@
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 6a0f4df..6081c05 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 @@
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() {