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

Side by Side Diff: dm/DMSrcSink.cpp

Issue 947103005: Revert of DM: lazy decoding on SKP playback (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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"
5 #include "SkDocument.h" 4 #include "SkDocument.h"
6 #include "SkImageGenerator.h"
7 #include "SkMultiPictureDraw.h" 5 #include "SkMultiPictureDraw.h"
8 #include "SkNullCanvas.h" 6 #include "SkNullCanvas.h"
9 #include "SkOSFile.h" 7 #include "SkOSFile.h"
10 #include "SkPictureRecorder.h" 8 #include "SkPictureRecorder.h"
11 #include "SkRandom.h" 9 #include "SkRandom.h"
12 #include "SkSVGCanvas.h" 10 #include "SkSVGCanvas.h"
13 #include "SkStream.h" 11 #include "SkStream.h"
14 #include "SkXMLWriter.h" 12 #include "SkXMLWriter.h"
15 13
16 static bool lazy_decode_bitmap(const void* src, size_t size, SkBitmap* dst) {
17 SkAutoTUnref<SkData> encoded(SkData::NewWithCopy(src, size));
18 return encoded && SkInstallDiscardablePixelRef(encoded, dst);
19 }
20
21 namespace DM { 14 namespace DM {
22 15
23 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} 16 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {}
24 17
25 Error GMSrc::draw(SkCanvas* canvas) const { 18 Error GMSrc::draw(SkCanvas* canvas) const {
26 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL)); 19 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL));
27 canvas->concat(gm->getInitialTransform()); 20 canvas->concat(gm->getInitialTransform());
28 gm->draw(canvas); 21 gm->draw(canvas);
29 return ""; 22 return "";
30 } 23 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 107
115 static const SkRect kSKPViewport = {0,0, 1000,1000}; 108 static const SkRect kSKPViewport = {0,0, 1000,1000};
116 109
117 SKPSrc::SKPSrc(Path path) : fPath(path) {} 110 SKPSrc::SKPSrc(Path path) : fPath(path) {}
118 111
119 Error SKPSrc::draw(SkCanvas* canvas) const { 112 Error SKPSrc::draw(SkCanvas* canvas) const {
120 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str())); 113 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str()));
121 if (!stream) { 114 if (!stream) {
122 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); 115 return SkStringPrintf("Couldn't read %s.", fPath.c_str());
123 } 116 }
124 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream, &lazy_decode _bitmap)); 117 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream));
125 if (!pic) { 118 if (!pic) {
126 return SkStringPrintf("Couldn't decode %s as a picture.", fPath.c_str()) ; 119 return SkStringPrintf("Couldn't decode %s as a picture.", fPath.c_str()) ;
127 } 120 }
128 stream.reset((SkStream*)NULL); // Might as well drop this when we're done w ith it. 121 stream.reset((SkStream*)NULL); // Might as well drop this when we're done w ith it.
129 canvas->clipRect(kSKPViewport); 122 canvas->clipRect(kSKPViewport);
130 canvas->drawPicture(pic); 123 canvas->drawPicture(pic);
131 return ""; 124 return "";
132 } 125 }
133 126
134 SkISize SKPSrc::size() const { 127 SkISize SKPSrc::size() const {
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 Error err = src.draw(recorder.beginRecording(size.width(), size.height())); 372 Error err = src.draw(recorder.beginRecording(size.width(), size.height()));
380 if (!err.isEmpty()) { 373 if (!err.isEmpty()) {
381 return err; 374 return err;
382 } 375 }
383 SkAutoTUnref<SkPicture> pic(recorder.endRecording()); 376 SkAutoTUnref<SkPicture> pic(recorder.endRecording());
384 377
385 // Serialize it and then deserialize it. 378 // Serialize it and then deserialize it.
386 SkDynamicMemoryWStream wStream; 379 SkDynamicMemoryWStream wStream;
387 pic->serialize(&wStream); 380 pic->serialize(&wStream);
388 SkAutoTDelete<SkStream> rStream(wStream.detachAsStream()); 381 SkAutoTDelete<SkStream> rStream(wStream.detachAsStream());
389 SkAutoTUnref<SkPicture> deserialized(SkPicture::CreateFromStream(rStream, &l azy_decode_bitmap)); 382 SkAutoTUnref<SkPicture> deserialized(SkPicture::CreateFromStream(rStream));
390 383
391 // Turn that deserialized picture into a Src, draw it into our Sink to fill bitmap or stream. 384 // Turn that deserialized picture into a Src, draw it into our Sink to fill bitmap or stream.
392 struct ProxySrc : public Src { 385 struct ProxySrc : public Src {
393 const SkPicture* fPic; 386 const SkPicture* fPic;
394 const SkISize fSize; 387 const SkISize fSize;
395 ProxySrc(const SkPicture* pic, SkISize size) : fPic(pic), fSize(size) {} 388 ProxySrc(const SkPicture* pic, SkISize size) : fPic(pic), fSize(size) {}
396 389
397 Error draw(SkCanvas* canvas) const SK_OVERRIDE { 390 Error draw(SkCanvas* canvas) const SK_OVERRIDE {
398 canvas->drawPicture(fPic); 391 canvas->drawPicture(fPic);
399 return ""; 392 return "";
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 surfaces.unrefAll(); 457 surfaces.unrefAll();
465 return ""; 458 return "";
466 } 459 }
467 SkISize size() const SK_OVERRIDE { return fSize; } 460 SkISize size() const SK_OVERRIDE { return fSize; }
468 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou ld be calling this. 461 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou ld be calling this.
469 } proxy(fW, fH, pic, src.size()); 462 } proxy(fW, fH, pic, src.size());
470 return fSink->draw(proxy, bitmap, stream, log); 463 return fSink->draw(proxy, bitmap, stream, log);
471 } 464 }
472 465
473 } // namespace DM 466 } // 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