OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkDeduper.h" | 9 #include "SkDeduper.h" |
10 #include "SkPicture.h" | 10 #include "SkPicture.h" |
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 } | 682 } |
683 | 683 |
684 static sk_sp<SkImage> make_from_encoded(const sk_sp<SkData>& data) { | 684 static sk_sp<SkImage> make_from_encoded(const sk_sp<SkData>& data) { |
685 sk_sp<SkImage> image = make_from_skiaimageformat(data->data(), data->size())
; | 685 sk_sp<SkImage> image = make_from_skiaimageformat(data->data(), data->size())
; |
686 if (!image) { | 686 if (!image) { |
687 image = SkImage::MakeFromEncoded(data); | 687 image = SkImage::MakeFromEncoded(data); |
688 } | 688 } |
689 return image; | 689 return image; |
690 } | 690 } |
691 | 691 |
692 static void defineImage_handler(SkPipeReader& reader, uint32_t packedVerb, SkCan
vas* canvas) { | 692 static void defineImage_handler(SkPipeReader& reader, uint32_t packedVerb, SkCan
vas*) { |
693 SkASSERT(SkPipeVerb::kDefineImage == unpack_verb(packedVerb)); | 693 SkASSERT(SkPipeVerb::kDefineImage == unpack_verb(packedVerb)); |
694 SkPipeInflator* inflator = (SkPipeInflator*)reader.getInflator(); | 694 SkPipeInflator* inflator = (SkPipeInflator*)reader.getInflator(); |
695 uint32_t extra = unpack_verb_extra(packedVerb); | 695 uint32_t extra = unpack_verb_extra(packedVerb); |
696 int index = extra & kIndex_ObjectDefinitionMask; | 696 int index = extra & kIndex_ObjectDefinitionMask; |
697 | 697 |
698 if (extra & kUndef_ObjectDefinitionMask) { | 698 if (extra & kUndef_ObjectDefinitionMask) { |
699 // zero-index means we are "forgetting" that cache entry | 699 // zero-index means we are "forgetting" that cache entry |
700 inflator->setImage(index, nullptr); | 700 inflator->setImage(index, nullptr); |
701 } else { | 701 } else { |
702 // we are defining a new image | 702 // we are defining a new image |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 memcpy(&cull, data, sizeof(SkRect)); | 860 memcpy(&cull, data, sizeof(SkRect)); |
861 size -= sizeof(SkRect); data = (const char*)data + sizeof(SkRect); | 861 size -= sizeof(SkRect); data = (const char*)data + sizeof(SkRect); |
862 | 862 |
863 SkPictureRecorder recorder; | 863 SkPictureRecorder recorder; |
864 this->playback(data, size, recorder.beginRecording(cull)); | 864 this->playback(data, size, recorder.beginRecording(cull)); |
865 return recorder.finishRecordingAsPicture(); | 865 return recorder.finishRecordingAsPicture(); |
866 } | 866 } |
867 | 867 |
868 sk_sp<SkImage> SkPipeDeserializer::readImage(const void* data, size_t size) { | 868 sk_sp<SkImage> SkPipeDeserializer::readImage(const void* data, size_t size) { |
869 if (size < sizeof(uint32_t)) { | 869 if (size < sizeof(uint32_t)) { |
| 870 SkDebugf("-------- data length too short for readImage %d\n", size); |
870 return nullptr; | 871 return nullptr; |
871 } | 872 } |
872 | 873 |
873 uint32_t header; | 874 const uint32_t* ptr = (const uint32_t*)data; |
874 memcpy(&header, data, 4); size -= 4; data = (const char*)data + 4; | 875 uint32_t packedVerb = *ptr++; |
875 if (kDefineImage_ExtPipeVerb != header) { | 876 size -= 4; |
| 877 |
| 878 if (SkPipeVerb::kDefineImage == unpack_verb(packedVerb)) { |
| 879 SkPipeInflator inflator(&fImpl->fImages, &fImpl->fPictures, |
| 880 &fImpl->fTypefaces, &fImpl->fFactories, |
| 881 fImpl->fTFDeserializer); |
| 882 SkPipeReader reader(this, ptr, size); |
| 883 reader.setInflator(&inflator); |
| 884 defineImage_handler(reader, packedVerb, nullptr); |
| 885 packedVerb = reader.read32(); // read the next verb |
| 886 } |
| 887 if (SkPipeVerb::kWriteImage != unpack_verb(packedVerb)) { |
| 888 SkDebugf("-------- unexpected verb for readImage %d\n", unpack_verb(pack
edVerb)); |
876 return nullptr; | 889 return nullptr; |
877 } | 890 } |
878 | 891 int index = unpack_verb_extra(packedVerb); |
879 SkPipeInflator inflator(&fImpl->fImages, &fImpl->fPictures, | 892 if (0 == index) { |
880 &fImpl->fTypefaces, &fImpl->fFactories, | 893 return nullptr; // writer failed |
881 fImpl->fTFDeserializer); | 894 } |
882 SkPipeReader reader(this, data, size); | 895 return sk_ref_sp(fImpl->fImages.get(index - 1)); |
883 reader.setInflator(&inflator); | |
884 return sk_sp<SkImage>(reader.readImage()); | |
885 } | 896 } |
886 | 897 |
887 static bool do_playback(SkPipeReader& reader, SkCanvas* canvas, int* endPictureI
ndex) { | 898 static bool do_playback(SkPipeReader& reader, SkCanvas* canvas, int* endPictureI
ndex) { |
888 int indent = 0; | 899 int indent = 0; |
889 | 900 |
890 const bool showEachVerb = false; | 901 const bool showEachVerb = false; |
891 int counter = 0; | 902 int counter = 0; |
892 while (!reader.eof()) { | 903 while (!reader.eof()) { |
893 uint32_t prevOffset = reader.offset(); | 904 uint32_t prevOffset = reader.offset(); |
894 uint32_t packedVerb = reader.read32(); | 905 uint32_t packedVerb = reader.read32(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
935 | 946 |
936 bool SkPipeDeserializer::playback(const void* data, size_t size, SkCanvas* canva
s) { | 947 bool SkPipeDeserializer::playback(const void* data, size_t size, SkCanvas* canva
s) { |
937 SkPipeInflator inflator(&fImpl->fImages, &fImpl->fPictures, | 948 SkPipeInflator inflator(&fImpl->fImages, &fImpl->fPictures, |
938 &fImpl->fTypefaces, &fImpl->fFactories, | 949 &fImpl->fTypefaces, &fImpl->fFactories, |
939 fImpl->fTFDeserializer); | 950 fImpl->fTFDeserializer); |
940 SkPipeReader reader(this, data, size); | 951 SkPipeReader reader(this, data, size); |
941 reader.setInflator(&inflator); | 952 reader.setInflator(&inflator); |
942 return do_playback(reader, canvas); | 953 return do_playback(reader, canvas); |
943 } | 954 } |
944 | 955 |
OLD | NEW |