| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "DMSrcSink.h" | 8 #include "DMSrcSink.h" |
| 9 #include "SamplePipeControllers.h" | 9 #include "SamplePipeControllers.h" |
| 10 #include "SkCommonFlags.h" | 10 #include "SkCommonFlags.h" |
| 11 #include "SkCodec.h" | 11 #include "SkCodec.h" |
| 12 #include "SkData.h" |
| 12 #include "SkDocument.h" | 13 #include "SkDocument.h" |
| 13 #include "SkError.h" | 14 #include "SkError.h" |
| 15 #include "SkImageGenerator.h" |
| 14 #include "SkMultiPictureDraw.h" | 16 #include "SkMultiPictureDraw.h" |
| 15 #include "SkNullCanvas.h" | 17 #include "SkNullCanvas.h" |
| 16 #include "SkOSFile.h" | 18 #include "SkOSFile.h" |
| 17 #include "SkPictureData.h" | 19 #include "SkPictureData.h" |
| 18 #include "SkPictureRecorder.h" | 20 #include "SkPictureRecorder.h" |
| 19 #include "SkRandom.h" | 21 #include "SkRandom.h" |
| 20 #include "SkSVGCanvas.h" | 22 #include "SkSVGCanvas.h" |
| 21 #include "SkStream.h" | 23 #include "SkStream.h" |
| 22 #include "SkXMLWriter.h" | 24 #include "SkXMLWriter.h" |
| 23 | 25 |
| 26 static bool lazy_decode_bitmap(const void* src, size_t size, SkBitmap* dst) { |
| 27 SkAutoTUnref<SkData> encoded(SkData::NewWithCopy(src, size)); |
| 28 return encoded && SkInstallDiscardablePixelRef(encoded, dst); |
| 29 } |
| 30 |
| 24 namespace DM { | 31 namespace DM { |
| 25 | 32 |
| 26 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} | 33 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} |
| 27 | 34 |
| 28 Error GMSrc::draw(SkCanvas* canvas) const { | 35 Error GMSrc::draw(SkCanvas* canvas) const { |
| 29 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL)); | 36 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL)); |
| 30 canvas->concat(gm->getInitialTransform()); | 37 canvas->concat(gm->getInitialTransform()); |
| 31 gm->draw(canvas); | 38 gm->draw(canvas); |
| 32 return ""; | 39 return ""; |
| 33 } | 40 } |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 | 207 |
| 201 static const SkRect kSKPViewport = {0,0, 1000,1000}; | 208 static const SkRect kSKPViewport = {0,0, 1000,1000}; |
| 202 | 209 |
| 203 SKPSrc::SKPSrc(Path path) : fPath(path) {} | 210 SKPSrc::SKPSrc(Path path) : fPath(path) {} |
| 204 | 211 |
| 205 Error SKPSrc::draw(SkCanvas* canvas) const { | 212 Error SKPSrc::draw(SkCanvas* canvas) const { |
| 206 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str())); | 213 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str())); |
| 207 if (!stream) { | 214 if (!stream) { |
| 208 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); | 215 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
| 209 } | 216 } |
| 210 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream)); | 217 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream, &lazy_decode
_bitmap)); |
| 211 if (!pic) { | 218 if (!pic) { |
| 212 return SkStringPrintf("Couldn't decode %s as a picture.", fPath.c_str())
; | 219 return SkStringPrintf("Couldn't decode %s as a picture.", fPath.c_str())
; |
| 213 } | 220 } |
| 214 stream.reset((SkStream*)NULL); // Might as well drop this when we're done w
ith it. | 221 stream.reset((SkStream*)NULL); // Might as well drop this when we're done w
ith it. |
| 215 canvas->clipRect(kSKPViewport); | 222 canvas->clipRect(kSKPViewport); |
| 216 canvas->drawPicture(pic); | 223 canvas->drawPicture(pic); |
| 217 return ""; | 224 return ""; |
| 218 } | 225 } |
| 219 | 226 |
| 220 SkISize SKPSrc::size() const { | 227 SkISize SKPSrc::size() const { |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 Error err = src.draw(recorder.beginRecording(size.width(), size.height())); | 507 Error err = src.draw(recorder.beginRecording(size.width(), size.height())); |
| 501 if (!err.isEmpty()) { | 508 if (!err.isEmpty()) { |
| 502 return err; | 509 return err; |
| 503 } | 510 } |
| 504 SkAutoTUnref<SkPicture> pic(recorder.endRecording()); | 511 SkAutoTUnref<SkPicture> pic(recorder.endRecording()); |
| 505 | 512 |
| 506 // Serialize it and then deserialize it. | 513 // Serialize it and then deserialize it. |
| 507 SkDynamicMemoryWStream wStream; | 514 SkDynamicMemoryWStream wStream; |
| 508 pic->serialize(&wStream); | 515 pic->serialize(&wStream); |
| 509 SkAutoTDelete<SkStream> rStream(wStream.detachAsStream()); | 516 SkAutoTDelete<SkStream> rStream(wStream.detachAsStream()); |
| 510 SkAutoTUnref<SkPicture> deserialized(SkPicture::CreateFromStream(rStream)); | 517 SkAutoTUnref<SkPicture> deserialized(SkPicture::CreateFromStream(rStream, &l
azy_decode_bitmap)); |
| 511 | 518 |
| 512 // Turn that deserialized picture into a Src, draw it into our Sink to fill
bitmap or stream. | 519 // Turn that deserialized picture into a Src, draw it into our Sink to fill
bitmap or stream. |
| 513 struct ProxySrc : public Src { | 520 struct ProxySrc : public Src { |
| 514 const SkPicture* fPic; | 521 const SkPicture* fPic; |
| 515 const SkISize fSize; | 522 const SkISize fSize; |
| 516 ProxySrc(const SkPicture* pic, SkISize size) : fPic(pic), fSize(size) {} | 523 ProxySrc(const SkPicture* pic, SkISize size) : fPic(pic), fSize(size) {} |
| 517 | 524 |
| 518 Error draw(SkCanvas* canvas) const SK_OVERRIDE { | 525 Error draw(SkCanvas* canvas) const SK_OVERRIDE { |
| 519 canvas->drawPicture(fPic); | 526 canvas->drawPicture(fPic); |
| 520 return ""; | 527 return ""; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 surfaces.unrefAll(); | 592 surfaces.unrefAll(); |
| 586 return ""; | 593 return ""; |
| 587 } | 594 } |
| 588 SkISize size() const SK_OVERRIDE { return fSize; } | 595 SkISize size() const SK_OVERRIDE { return fSize; } |
| 589 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou
ld be calling this. | 596 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou
ld be calling this. |
| 590 } proxy(fW, fH, pic, src.size()); | 597 } proxy(fW, fH, pic, src.size()); |
| 591 return fSink->draw(proxy, bitmap, stream, log); | 598 return fSink->draw(proxy, bitmap, stream, log); |
| 592 } | 599 } |
| 593 | 600 |
| 594 } // namespace DM | 601 } // namespace DM |
| OLD | NEW |