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

Unified Diff: src/pipe/SkPipeReader.cpp

Issue 2335973003: change write-image to use pipeverbs like everyone else, and add test (Closed)
Patch Set: switch to [define_image] write_image Created 4 years, 3 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 | « src/pipe/SkPipeFormat.h ('k') | tests/PipeTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pipe/SkPipeReader.cpp
diff --git a/src/pipe/SkPipeReader.cpp b/src/pipe/SkPipeReader.cpp
index d4375486d09a62c7da26c27440b072105355fc21..2edc2dff20924f8913cd50b1726aeb6364196a15 100644
--- a/src/pipe/SkPipeReader.cpp
+++ b/src/pipe/SkPipeReader.cpp
@@ -689,7 +689,7 @@ static sk_sp<SkImage> make_from_encoded(const sk_sp<SkData>& data) {
return image;
}
-static void defineImage_handler(SkPipeReader& reader, uint32_t packedVerb, SkCanvas* canvas) {
+static void defineImage_handler(SkPipeReader& reader, uint32_t packedVerb, SkCanvas*) {
SkASSERT(SkPipeVerb::kDefineImage == unpack_verb(packedVerb));
SkPipeInflator* inflator = (SkPipeInflator*)reader.getInflator();
uint32_t extra = unpack_verb_extra(packedVerb);
@@ -867,21 +867,32 @@ sk_sp<SkPicture> SkPipeDeserializer::readPicture(const void* data, size_t size)
sk_sp<SkImage> SkPipeDeserializer::readImage(const void* data, size_t size) {
if (size < sizeof(uint32_t)) {
+ SkDebugf("-------- data length too short for readImage %d\n", size);
return nullptr;
}
- uint32_t header;
- memcpy(&header, data, 4); size -= 4; data = (const char*)data + 4;
- if (kDefineImage_ExtPipeVerb != header) {
+ const uint32_t* ptr = (const uint32_t*)data;
+ uint32_t packedVerb = *ptr++;
+ size -= 4;
+
+ if (SkPipeVerb::kDefineImage == unpack_verb(packedVerb)) {
+ SkPipeInflator inflator(&fImpl->fImages, &fImpl->fPictures,
+ &fImpl->fTypefaces, &fImpl->fFactories,
+ fImpl->fTFDeserializer);
+ SkPipeReader reader(this, ptr, size);
+ reader.setInflator(&inflator);
+ defineImage_handler(reader, packedVerb, nullptr);
+ packedVerb = reader.read32(); // read the next verb
+ }
+ if (SkPipeVerb::kWriteImage != unpack_verb(packedVerb)) {
+ SkDebugf("-------- unexpected verb for readImage %d\n", unpack_verb(packedVerb));
return nullptr;
}
-
- SkPipeInflator inflator(&fImpl->fImages, &fImpl->fPictures,
- &fImpl->fTypefaces, &fImpl->fFactories,
- fImpl->fTFDeserializer);
- SkPipeReader reader(this, data, size);
- reader.setInflator(&inflator);
- return sk_sp<SkImage>(reader.readImage());
+ int index = unpack_verb_extra(packedVerb);
+ if (0 == index) {
+ return nullptr; // writer failed
+ }
+ return sk_ref_sp(fImpl->fImages.get(index - 1));
}
static bool do_playback(SkPipeReader& reader, SkCanvas* canvas, int* endPictureIndex) {
« no previous file with comments | « src/pipe/SkPipeFormat.h ('k') | tests/PipeTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698