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>
This commit is contained in:
parent
594706566a
commit
ef03848357
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -21,7 +21,6 @@ struct SkDeserialProcs;
|
||||
class SkImage;
|
||||
class SkPath;
|
||||
class SkPictureData;
|
||||
class SkPixelSerializer;
|
||||
class SkReadBuffer;
|
||||
class SkRefCntSet;
|
||||
struct SkSerialProcs;
|
||||
@ -107,20 +106,10 @@ 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.
|
||||
*/
|
||||
|
@ -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
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -12,7 +12,6 @@
|
||||
#include "SkOSFile.h"
|
||||
#include "SkOSPath.h"
|
||||
#include "SkStream.h"
|
||||
#include "SkPixelSerializer.h"
|
||||
|
||||
#include "sk_tool_utils.h"
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user