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

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-02-23 (Monday) 11:08:28 EST Created 5 years, 10 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 "SkData.h"
4 #include "SkDocument.h" 5 #include "SkDocument.h"
6 #include "SkImageGenerator.h"
5 #include "SkMultiPictureDraw.h" 7 #include "SkMultiPictureDraw.h"
6 #include "SkNullCanvas.h" 8 #include "SkNullCanvas.h"
7 #include "SkOSFile.h" 9 #include "SkOSFile.h"
8 #include "SkPictureRecorder.h" 10 #include "SkPictureRecorder.h"
9 #include "SkRandom.h" 11 #include "SkRandom.h"
10 #include "SkSVGCanvas.h" 12 #include "SkSVGCanvas.h"
11 #include "SkStream.h" 13 #include "SkStream.h"
12 #include "SkXMLWriter.h" 14 #include "SkXMLWriter.h"
13 15
mtklein 2015/02/23 17:01:10 Move here?
hal.canary 2015/02/23 18:16:35 Done.
14 namespace DM { 16 namespace DM {
15 17
16 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} 18 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {}
17 19
18 Error GMSrc::draw(SkCanvas* canvas) const { 20 Error GMSrc::draw(SkCanvas* canvas) const {
19 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL)); 21 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL));
20 canvas->concat(gm->getInitialTransform()); 22 canvas->concat(gm->getInitialTransform());
21 gm->draw(canvas); 23 gm->draw(canvas);
22 return ""; 24 return "";
23 } 25 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 103
102 Name ImageSrc::name() const { 104 Name ImageSrc::name() const {
103 return SkOSPath::Basename(fPath.c_str()); 105 return SkOSPath::Basename(fPath.c_str());
104 } 106 }
105 107
106 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 108 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
107 109
108 static const SkRect kSKPViewport = {0,0, 1000,1000}; 110 static const SkRect kSKPViewport = {0,0, 1000,1000};
109 111
110 SKPSrc::SKPSrc(Path path) : fPath(path) {} 112 SKPSrc::SKPSrc(Path path) : fPath(path) {}
113 namespace {
114 bool lazy_decode_bitmap(const void* src, size_t size, SkBitmap* dst) {
mtklein 2015/02/23 17:01:10 static instead?
hal.canary 2015/02/23 18:16:35 Done.
115 SkAutoTUnref<SkData> encoded(SkData::NewWithCopy(src, size));
116 return encoded.get() ? SkInstallDiscardablePixelRef(encoded, dst) : false;
117 }
118 } // namespace
111 119
112 Error SKPSrc::draw(SkCanvas* canvas) const { 120 Error SKPSrc::draw(SkCanvas* canvas) const {
113 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str())); 121 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str()));
114 if (!stream) { 122 if (!stream) {
115 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); 123 return SkStringPrintf("Couldn't read %s.", fPath.c_str());
116 } 124 }
117 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream)); 125 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream, &lazy_decode _bitmap));
118 if (!pic) { 126 if (!pic) {
119 return SkStringPrintf("Couldn't decode %s as a picture.", fPath.c_str()) ; 127 return SkStringPrintf("Couldn't decode %s as a picture.", fPath.c_str()) ;
120 } 128 }
121 stream.reset((SkStream*)NULL); // Might as well drop this when we're done w ith it. 129 stream.reset((SkStream*)NULL); // Might as well drop this when we're done w ith it.
122 canvas->clipRect(kSKPViewport); 130 canvas->clipRect(kSKPViewport);
123 canvas->drawPicture(pic); 131 canvas->drawPicture(pic);
124 return ""; 132 return "";
125 } 133 }
126 134
127 SkISize SKPSrc::size() const { 135 SkISize SKPSrc::size() const {
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 Error err = src.draw(recorder.beginRecording(size.width(), size.height())); 380 Error err = src.draw(recorder.beginRecording(size.width(), size.height()));
373 if (!err.isEmpty()) { 381 if (!err.isEmpty()) {
374 return err; 382 return err;
375 } 383 }
376 SkAutoTUnref<SkPicture> pic(recorder.endRecording()); 384 SkAutoTUnref<SkPicture> pic(recorder.endRecording());
377 385
378 // Serialize it and then deserialize it. 386 // Serialize it and then deserialize it.
379 SkDynamicMemoryWStream wStream; 387 SkDynamicMemoryWStream wStream;
380 pic->serialize(&wStream); 388 pic->serialize(&wStream);
381 SkAutoTDelete<SkStream> rStream(wStream.detachAsStream()); 389 SkAutoTDelete<SkStream> rStream(wStream.detachAsStream());
382 SkAutoTUnref<SkPicture> deserialized(SkPicture::CreateFromStream(rStream)); 390 SkAutoTUnref<SkPicture> deserialized(SkPicture::CreateFromStream(rStream));
mtklein 2015/02/23 17:01:10 Let's move lazy_decode_bitmap up to the very top (
hal.canary 2015/02/23 18:16:35 Done.
383 391
384 // Turn that deserialized picture into a Src, draw it into our Sink to fill bitmap or stream. 392 // Turn that deserialized picture into a Src, draw it into our Sink to fill bitmap or stream.
385 struct ProxySrc : public Src { 393 struct ProxySrc : public Src {
386 const SkPicture* fPic; 394 const SkPicture* fPic;
387 const SkISize fSize; 395 const SkISize fSize;
388 ProxySrc(const SkPicture* pic, SkISize size) : fPic(pic), fSize(size) {} 396 ProxySrc(const SkPicture* pic, SkISize size) : fPic(pic), fSize(size) {}
389 397
390 Error draw(SkCanvas* canvas) const SK_OVERRIDE { 398 Error draw(SkCanvas* canvas) const SK_OVERRIDE {
391 canvas->drawPicture(fPic); 399 canvas->drawPicture(fPic);
392 return ""; 400 return "";
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 surfaces.unrefAll(); 465 surfaces.unrefAll();
458 return ""; 466 return "";
459 } 467 }
460 SkISize size() const SK_OVERRIDE { return fSize; } 468 SkISize size() const SK_OVERRIDE { return fSize; }
461 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou ld be calling this. 469 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou ld be calling this.
462 } proxy(fW, fH, pic, src.size()); 470 } proxy(fW, fH, pic, src.size());
463 return fSink->draw(proxy, bitmap, stream, log); 471 return fSink->draw(proxy, bitmap, stream, log);
464 } 472 }
465 473
466 } // namespace DM 474 } // 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