OLD | NEW |
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"); |
18 | 20 |
| 21 static bool lazy_decode_bitmap(const void* src, size_t size, SkBitmap* dst) { |
| 22 SkAutoTUnref<SkData> encoded(SkData::NewWithCopy(src, size)); |
| 23 return encoded && SkInstallDiscardablePixelRef(encoded, dst); |
| 24 } |
| 25 |
19 namespace DM { | 26 namespace DM { |
20 | 27 |
21 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} | 28 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} |
22 | 29 |
23 Error GMSrc::draw(SkCanvas* canvas) const { | 30 Error GMSrc::draw(SkCanvas* canvas) const { |
24 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL)); | 31 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL)); |
25 canvas->concat(gm->getInitialTransform()); | 32 canvas->concat(gm->getInitialTransform()); |
26 gm->draw(canvas); | 33 gm->draw(canvas); |
27 return ""; | 34 return ""; |
28 } | 35 } |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 | 179 |
173 static const SkRect kSKPViewport = {0,0, 1000,1000}; | 180 static const SkRect kSKPViewport = {0,0, 1000,1000}; |
174 | 181 |
175 SKPSrc::SKPSrc(Path path) : fPath(path) {} | 182 SKPSrc::SKPSrc(Path path) : fPath(path) {} |
176 | 183 |
177 Error SKPSrc::draw(SkCanvas* canvas) const { | 184 Error SKPSrc::draw(SkCanvas* canvas) const { |
178 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str())); | 185 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str())); |
179 if (!stream) { | 186 if (!stream) { |
180 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); | 187 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
181 } | 188 } |
182 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream)); | 189 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream, &lazy_decode
_bitmap)); |
183 if (!pic) { | 190 if (!pic) { |
184 return SkStringPrintf("Couldn't decode %s as a picture.", fPath.c_str())
; | 191 return SkStringPrintf("Couldn't decode %s as a picture.", fPath.c_str())
; |
185 } | 192 } |
186 stream.reset((SkStream*)NULL); // Might as well drop this when we're done w
ith it. | 193 stream.reset((SkStream*)NULL); // Might as well drop this when we're done w
ith it. |
187 canvas->clipRect(kSKPViewport); | 194 canvas->clipRect(kSKPViewport); |
188 canvas->drawPicture(pic); | 195 canvas->drawPicture(pic); |
189 return ""; | 196 return ""; |
190 } | 197 } |
191 | 198 |
192 SkISize SKPSrc::size() const { | 199 SkISize SKPSrc::size() const { |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 Error err = src.draw(recorder.beginRecording(size.width(), size.height())); | 479 Error err = src.draw(recorder.beginRecording(size.width(), size.height())); |
473 if (!err.isEmpty()) { | 480 if (!err.isEmpty()) { |
474 return err; | 481 return err; |
475 } | 482 } |
476 SkAutoTUnref<SkPicture> pic(recorder.endRecording()); | 483 SkAutoTUnref<SkPicture> pic(recorder.endRecording()); |
477 | 484 |
478 // Serialize it and then deserialize it. | 485 // Serialize it and then deserialize it. |
479 SkDynamicMemoryWStream wStream; | 486 SkDynamicMemoryWStream wStream; |
480 pic->serialize(&wStream); | 487 pic->serialize(&wStream); |
481 SkAutoTDelete<SkStream> rStream(wStream.detachAsStream()); | 488 SkAutoTDelete<SkStream> rStream(wStream.detachAsStream()); |
482 SkAutoTUnref<SkPicture> deserialized(SkPicture::CreateFromStream(rStream)); | 489 SkAutoTUnref<SkPicture> deserialized(SkPicture::CreateFromStream(rStream, &l
azy_decode_bitmap)); |
483 | 490 |
484 // Turn that deserialized picture into a Src, draw it into our Sink to fill
bitmap or stream. | 491 // Turn that deserialized picture into a Src, draw it into our Sink to fill
bitmap or stream. |
485 struct ProxySrc : public Src { | 492 struct ProxySrc : public Src { |
486 const SkPicture* fPic; | 493 const SkPicture* fPic; |
487 const SkISize fSize; | 494 const SkISize fSize; |
488 ProxySrc(const SkPicture* pic, SkISize size) : fPic(pic), fSize(size) {} | 495 ProxySrc(const SkPicture* pic, SkISize size) : fPic(pic), fSize(size) {} |
489 | 496 |
490 Error draw(SkCanvas* canvas) const SK_OVERRIDE { | 497 Error draw(SkCanvas* canvas) const SK_OVERRIDE { |
491 canvas->drawPicture(fPic); | 498 canvas->drawPicture(fPic); |
492 return ""; | 499 return ""; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 surfaces.unrefAll(); | 564 surfaces.unrefAll(); |
558 return ""; | 565 return ""; |
559 } | 566 } |
560 SkISize size() const SK_OVERRIDE { return fSize; } | 567 SkISize size() const SK_OVERRIDE { return fSize; } |
561 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou
ld be calling this. | 568 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou
ld be calling this. |
562 } proxy(fW, fH, pic, src.size()); | 569 } proxy(fW, fH, pic, src.size()); |
563 return fSink->draw(proxy, bitmap, stream, log); | 570 return fSink->draw(proxy, bitmap, stream, log); |
564 } | 571 } |
565 | 572 |
566 } // namespace DM | 573 } // namespace DM |
OLD | NEW |