Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Unified Diff: src/core/SkPicture.cpp

Issue 2187613002: Deserialize pictures with custom image-deserializer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix legacy case, remove null-check Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/core/SkPicture.h ('k') | src/core/SkPictureData.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkPicture.cpp
diff --git a/src/core/SkPicture.cpp b/src/core/SkPicture.cpp
index 4e994559e62f3318b48821ad4c6dad4479e86ffb..5d6986631b5ae894542fad6afd3b7aff0d492b82 100644
--- a/src/core/SkPicture.cpp
+++ b/src/core/SkPicture.cpp
@@ -6,6 +6,7 @@
*/
#include "SkAtomics.h"
+#include "SkImageDeserializer.h"
#include "SkImageGenerator.h"
#include "SkMessageBus.h"
#include "SkPicture.h"
@@ -23,6 +24,31 @@ static bool g_AllPictureIOSecurityPrecautionsEnabled = false;
DECLARE_SKMESSAGEBUS_MESSAGE(SkPicture::DeletionMessage);
+#ifdef SK_SUPPORT_LEGACY_PICTUREINSTALLPIXELREF
+class InstallProcImageDeserializer : public SkImageDeserializer {
+ SkPicture::InstallPixelRefProc fProc;
+public:
+ InstallProcImageDeserializer(SkPicture::InstallPixelRefProc proc) : fProc(proc) {}
+
+ sk_sp<SkImage> makeFromMemory(const void* data, size_t length, const SkIRect* subset) override {
+ SkBitmap bitmap;
+ if (fProc(data, length, &bitmap)) {
+ bitmap.setImmutable();
+ return SkImage::MakeFromBitmap(bitmap);
+ }
+ return nullptr;
+ }
+ sk_sp<SkImage> makeFromData(SkData* data, const SkIRect* subset) override {
+ return this->makeFromMemory(data->data(), data->size(), subset);
+ }
+};
+
+sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream, InstallPixelRefProc proc) {
+ InstallProcImageDeserializer deserializer(proc);
+ return MakeFromStream(stream, &deserializer);
+}
+#endif
+
/* SkPicture impl. This handles generic responsibilities like unique IDs and serialization. */
SkPicture::SkPicture() : fUniqueID(0) {}
@@ -141,28 +167,23 @@ sk_sp<SkPicture> SkPicture::Forwardport(const SkPictInfo& info,
return r.finishRecordingAsPicture();
}
-static bool default_install(const void* src, size_t length, SkBitmap* dst) {
- sk_sp<SkData> encoded(SkData::MakeWithCopy(src, length));
- return encoded && SkDEPRECATED_InstallDiscardablePixelRef(
- SkImageGenerator::NewFromEncoded(encoded.get()), dst);
+sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream, SkImageDeserializer* factory) {
+ return MakeFromStream(stream, factory, nullptr);
}
sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream) {
- return MakeFromStream(stream, &default_install, nullptr);
-}
-
-sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream, InstallPixelRefProc proc) {
- return MakeFromStream(stream, proc, nullptr);
+ SkImageDeserializer factory;
+ return MakeFromStream(stream, &factory);
}
-sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream, InstallPixelRefProc proc,
+sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream, SkImageDeserializer* factory,
SkTypefacePlayback* typefaces) {
SkPictInfo info;
if (!InternalOnly_StreamIsSKP(stream, &info) || !stream->readBool()) {
return nullptr;
}
SkAutoTDelete<SkPictureData> data(
- SkPictureData::CreateFromStream(stream, info, proc, typefaces));
+ SkPictureData::CreateFromStream(stream, info, factory, typefaces));
return Forwardport(info, data, nullptr);
}
« no previous file with comments | « include/core/SkPicture.h ('k') | src/core/SkPictureData.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698