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

Side by Side Diff: dm/DMSrcSink.cpp

Issue 943383002: DM: lazy decoding on SKP playback (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-03-17 (Tuesday) 13:02:02 EDT Created 5 years, 9 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include "DMSrcSink.h" 1 #include "DMSrcSink.h"
2 #include "SamplePipeControllers.h" 2 #include "SamplePipeControllers.h"
3 #include "SkCommonFlags.h" 3 #include "SkCommonFlags.h"
4 #include "SkCodec.h" 4 #include "SkCodec.h"
5 #include "SkData.h"
5 #include "SkDocument.h" 6 #include "SkDocument.h"
6 #include "SkError.h" 7 #include "SkError.h"
8 #include "SkImageGenerator.h"
7 #include "SkMultiPictureDraw.h" 9 #include "SkMultiPictureDraw.h"
8 #include "SkNullCanvas.h" 10 #include "SkNullCanvas.h"
9 #include "SkOSFile.h" 11 #include "SkOSFile.h"
10 #include "SkPictureData.h" 12 #include "SkPictureData.h"
11 #include "SkPictureRecorder.h" 13 #include "SkPictureRecorder.h"
12 #include "SkRandom.h" 14 #include "SkRandom.h"
13 #include "SkSVGCanvas.h" 15 #include "SkSVGCanvas.h"
14 #include "SkStream.h" 16 #include "SkStream.h"
15 #include "SkXMLWriter.h" 17 #include "SkXMLWriter.h"
16 18
17 DEFINE_bool(codec, false, "Use SkCodec instead of SkImageDecoder"); 19 DEFINE_bool(codec, false, "Use SkCodec instead of SkImageDecoder");
20 DEFINE_bool(deferDecode, false, "if true, defer decoding of bitmaps until they a re locked.");
21
22 static bool lazy_decode_bitmap(const void* src, size_t size, SkBitmap* dst) {
23 SkAutoTUnref<SkData> encoded(SkData::NewWithCopy(src, size));
24 return encoded && SkInstallDiscardablePixelRef(encoded, dst);
25 }
26
27 static SkPicture* create_picture_from_stream(SkStream* stream) {
28 return FLAGS_deferDecode ? SkPicture::CreateFromStream(stream, &lazy_decode_ bitmap)
29 : SkPicture::CreateFromStream(stream);
30 }
18 31
19 namespace DM { 32 namespace DM {
20 33
21 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} 34 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {}
22 35
23 Error GMSrc::draw(SkCanvas* canvas) const { 36 Error GMSrc::draw(SkCanvas* canvas) const {
24 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL)); 37 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL));
25 canvas->concat(gm->getInitialTransform()); 38 canvas->concat(gm->getInitialTransform());
26 gm->draw(canvas); 39 gm->draw(canvas);
27 return ""; 40 return "";
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 // We consider incomplete to be valid, since we should still dec ode what is 89 // We consider incomplete to be valid, since we should still dec ode what is
77 // available. 90 // available.
78 case SkImageGenerator::kIncompleteInput: 91 case SkImageGenerator::kIncompleteInput:
79 break; 92 break;
80 case SkImageGenerator::kInvalidConversion: 93 case SkImageGenerator::kInvalidConversion:
81 return Error::Nonfatal("Incompatible colortype conversion"); 94 return Error::Nonfatal("Incompatible colortype conversion");
82 default: 95 default:
83 // Everything else is considered a failure. 96 // Everything else is considered a failure.
84 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str( )); 97 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str( ));
85 } 98 }
99 } else if (FLAGS_deferDecode) {
100 if (!SkInstallDiscardablePixelRef(encoded, &bitmap)) {
101 return SkStringPrintf("SkInstallDiscardablePixelRef failed for % s.",
102 fPath.c_str());
103 }
86 } else { 104 } else {
87 if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(), &bitmap, 105 if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(), &bitmap,
88 dstColorType, SkImageDecoder::kDec odePixels_Mode)) { 106 dstColorType, SkImageDecoder::kDec odePixels_Mode)) {
89 return SkStringPrintf("Couldn't decode %s.", fPath.c_str()); 107 return SkStringPrintf("Couldn't decode %s.", fPath.c_str());
90 } 108 }
91 if (kRGB_565_SkColorType == dstColorType && !bitmap.isOpaque()) { 109 if (kRGB_565_SkColorType == dstColorType && !bitmap.isOpaque()) {
92 // Do not draw a bitmap with alpha to a destination without alph a. 110 // Do not draw a bitmap with alpha to a destination without alph a.
93 return Error::Nonfatal("Uninteresting to decode image with alpha into 565."); 111 return Error::Nonfatal("Uninteresting to decode image with alpha into 565.");
94 } 112 }
95 } 113 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 if (FLAGS_codec) { 162 if (FLAGS_codec) {
145 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); 163 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
146 if (!codec) { 164 if (!codec) {
147 return SkISize::Make(0,0); 165 return SkISize::Make(0,0);
148 } 166 }
149 SkImageInfo info; 167 SkImageInfo info;
150 if (!codec->getInfo(&info)) { 168 if (!codec->getInfo(&info)) {
151 return SkISize::Make(0,0); 169 return SkISize::Make(0,0);
152 } 170 }
153 return info.dimensions(); 171 return info.dimensions();
172 } else if (FLAGS_deferDecode) {
173 SkAutoTDelete<SkImageGenerator> gen(SkImageGenerator::NewFromData(encode d));
174 SkImageInfo info;
175 return gen && gen->getInfo(&info) ? info.dimensions() : SkISize::Make(0, 0);
154 } else { 176 } else {
155 SkBitmap bitmap; 177 SkBitmap bitmap;
156 if (!encoded || !SkImageDecoder::DecodeMemory(encoded->data(), 178 if (!encoded || !SkImageDecoder::DecodeMemory(encoded->data(),
157 encoded->size(), 179 encoded->size(),
158 &bitmap, 180 &bitmap,
159 kUnknown_SkColorType, 181 kUnknown_SkColorType,
160 SkImageDecoder::kDecodeBou nds_Mode)) { 182 SkImageDecoder::kDecodeBou nds_Mode)) {
161 return SkISize::Make(0,0); 183 return SkISize::Make(0,0);
162 } 184 }
163 return bitmap.dimensions(); 185 return bitmap.dimensions();
164 } 186 }
165 } 187 }
166 188
167 Name ImageSrc::name() const { 189 Name ImageSrc::name() const {
168 return SkOSPath::Basename(fPath.c_str()); 190 return SkOSPath::Basename(fPath.c_str());
169 } 191 }
170 192
171 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 193 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
172 194
173 static const SkRect kSKPViewport = {0,0, 1000,1000}; 195 static const SkRect kSKPViewport = {0,0, 1000,1000};
174 196
175 SKPSrc::SKPSrc(Path path) : fPath(path) {} 197 SKPSrc::SKPSrc(Path path) : fPath(path) {}
176 198
177 Error SKPSrc::draw(SkCanvas* canvas) const { 199 Error SKPSrc::draw(SkCanvas* canvas) const {
178 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str())); 200 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str()));
179 if (!stream) { 201 if (!stream) {
180 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); 202 return SkStringPrintf("Couldn't read %s.", fPath.c_str());
181 } 203 }
182 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream)); 204 SkAutoTUnref<SkPicture> pic(create_picture_from_stream(stream));
183 if (!pic) { 205 if (!pic) {
184 return SkStringPrintf("Couldn't decode %s as a picture.", fPath.c_str()) ; 206 return SkStringPrintf("Couldn't decode %s as a picture.", fPath.c_str()) ;
185 } 207 }
186 stream.reset((SkStream*)NULL); // Might as well drop this when we're done w ith it. 208 stream.reset((SkStream*)NULL); // Might as well drop this when we're done w ith it.
187 canvas->clipRect(kSKPViewport); 209 canvas->clipRect(kSKPViewport);
188 canvas->drawPicture(pic); 210 canvas->drawPicture(pic);
189 return ""; 211 return "";
190 } 212 }
191 213
192 SkISize SKPSrc::size() const { 214 SkISize SKPSrc::size() const {
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 Error err = src.draw(recorder.beginRecording(size.width(), size.height())); 494 Error err = src.draw(recorder.beginRecording(size.width(), size.height()));
473 if (!err.isEmpty()) { 495 if (!err.isEmpty()) {
474 return err; 496 return err;
475 } 497 }
476 SkAutoTUnref<SkPicture> pic(recorder.endRecording()); 498 SkAutoTUnref<SkPicture> pic(recorder.endRecording());
477 499
478 // Serialize it and then deserialize it. 500 // Serialize it and then deserialize it.
479 SkDynamicMemoryWStream wStream; 501 SkDynamicMemoryWStream wStream;
480 pic->serialize(&wStream); 502 pic->serialize(&wStream);
481 SkAutoTDelete<SkStream> rStream(wStream.detachAsStream()); 503 SkAutoTDelete<SkStream> rStream(wStream.detachAsStream());
482 SkAutoTUnref<SkPicture> deserialized(SkPicture::CreateFromStream(rStream)); 504 SkAutoTUnref<SkPicture> deserialized(create_picture_from_stream(rStream));
483 505
484 // Turn that deserialized picture into a Src, draw it into our Sink to fill bitmap or stream. 506 // Turn that deserialized picture into a Src, draw it into our Sink to fill bitmap or stream.
485 struct ProxySrc : public Src { 507 struct ProxySrc : public Src {
486 const SkPicture* fPic; 508 const SkPicture* fPic;
487 const SkISize fSize; 509 const SkISize fSize;
488 ProxySrc(const SkPicture* pic, SkISize size) : fPic(pic), fSize(size) {} 510 ProxySrc(const SkPicture* pic, SkISize size) : fPic(pic), fSize(size) {}
489 511
490 Error draw(SkCanvas* canvas) const SK_OVERRIDE { 512 Error draw(SkCanvas* canvas) const SK_OVERRIDE {
491 canvas->drawPicture(fPic); 513 canvas->drawPicture(fPic);
492 return ""; 514 return "";
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 surfaces.unrefAll(); 579 surfaces.unrefAll();
558 return ""; 580 return "";
559 } 581 }
560 SkISize size() const SK_OVERRIDE { return fSize; } 582 SkISize size() const SK_OVERRIDE { return fSize; }
561 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou ld be calling this. 583 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou ld be calling this.
562 } proxy(fW, fH, pic, src.size()); 584 } proxy(fW, fH, pic, src.size());
563 return fSink->draw(proxy, bitmap, stream, log); 585 return fSink->draw(proxy, bitmap, stream, log);
564 } 586 }
565 587
566 } // namespace DM 588 } // namespace DM
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698