| 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 "SkDocument.h" | 4 #include "SkDocument.h" |
| 5 #include "SkMultiPictureDraw.h" | 5 #include "SkMultiPictureDraw.h" |
| 6 #include "SkOSFile.h" | 6 #include "SkOSFile.h" |
| 7 #include "SkPictureRecorder.h" | 7 #include "SkPictureRecorder.h" |
| 8 #include "SkRandom.h" | 8 #include "SkRandom.h" |
| 9 #include "SkStream.h" |
| 9 | 10 |
| 10 namespace DM { | 11 namespace DM { |
| 11 | 12 |
| 12 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} | 13 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} |
| 13 | 14 |
| 14 Error GMSrc::draw(SkCanvas* canvas) const { | 15 Error GMSrc::draw(SkCanvas* canvas) const { |
| 15 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL)); | 16 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL)); |
| 16 canvas->concat(gm->getInitialTransform()); | 17 canvas->concat(gm->getInitialTransform()); |
| 17 gm->draw(canvas); | 18 gm->draw(canvas); |
| 18 return ""; | 19 return ""; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 41 // Decode the full image. | 42 // Decode the full image. |
| 42 SkBitmap bitmap; | 43 SkBitmap bitmap; |
| 43 if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(), &bit
map)) { | 44 if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(), &bit
map)) { |
| 44 return SkStringPrintf("Couldn't decode %s.", fPath.c_str()); | 45 return SkStringPrintf("Couldn't decode %s.", fPath.c_str()); |
| 45 } | 46 } |
| 46 encoded.reset((SkData*)NULL); // Might as well drop this when we're don
e with it. | 47 encoded.reset((SkData*)NULL); // Might as well drop this when we're don
e with it. |
| 47 canvas->drawBitmap(bitmap, 0,0); | 48 canvas->drawBitmap(bitmap, 0,0); |
| 48 return ""; | 49 return ""; |
| 49 } | 50 } |
| 50 // Decode random subsets. This is a little involved. | 51 // Decode random subsets. This is a little involved. |
| 51 SkMemoryStream stream(encoded->data(), encoded->size()); | 52 SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(encoded)); |
| 52 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(&stream)); | 53 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream.get()))
; |
| 53 if (!decoder) { | 54 if (!decoder) { |
| 54 return SkStringPrintf("Can't find a good decoder for %s.", fPath.c_str()
); | 55 return SkStringPrintf("Can't find a good decoder for %s.", fPath.c_str()
); |
| 55 } | 56 } |
| 57 stream->rewind(); |
| 56 int w,h; | 58 int w,h; |
| 57 if (!decoder->buildTileIndex(&stream, &w, &h) || w*h == 1) { | 59 if (!decoder->buildTileIndex(stream.detach(), &w, &h) || w*h == 1) { |
| 58 return ""; // Not an error. Subset decoding is not always supported. | 60 return ""; // Not an error. Subset decoding is not always supported. |
| 59 } | 61 } |
| 60 SkRandom rand; | 62 SkRandom rand; |
| 61 for (int i = 0; i < fSubsets; i++) { | 63 for (int i = 0; i < fSubsets; i++) { |
| 62 SkIRect rect; | 64 SkIRect rect; |
| 63 do { | 65 do { |
| 64 rect.fLeft = rand.nextULessThan(w); | 66 rect.fLeft = rand.nextULessThan(w); |
| 65 rect.fTop = rand.nextULessThan(h); | 67 rect.fTop = rand.nextULessThan(h); |
| 66 rect.fRight = rand.nextULessThan(w); | 68 rect.fRight = rand.nextULessThan(w); |
| 67 rect.fBottom = rand.nextULessThan(h); | 69 rect.fBottom = rand.nextULessThan(h); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 97 return name; | 99 return name; |
| 98 } | 100 } |
| 99 | 101 |
| 100 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ | 102 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
| 101 | 103 |
| 102 static const SkRect kSKPViewport = {0,0, 1000,1000}; | 104 static const SkRect kSKPViewport = {0,0, 1000,1000}; |
| 103 | 105 |
| 104 SKPSrc::SKPSrc(SkString path) : fPath(path) {} | 106 SKPSrc::SKPSrc(SkString path) : fPath(path) {} |
| 105 | 107 |
| 106 Error SKPSrc::draw(SkCanvas* canvas) const { | 108 Error SKPSrc::draw(SkCanvas* canvas) const { |
| 107 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(fPath.c_str())); | 109 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str())); |
| 108 if (!stream) { | 110 if (!stream) { |
| 109 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); | 111 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
| 110 } | 112 } |
| 111 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream)); | 113 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream)); |
| 112 if (!pic) { | 114 if (!pic) { |
| 113 return SkStringPrintf("Couldn't decode %s as a picture.", fPath.c_str())
; | 115 return SkStringPrintf("Couldn't decode %s as a picture.", fPath.c_str())
; |
| 114 } | 116 } |
| 115 stream.reset((SkStream*)NULL); // Might as well drop this when we're done w
ith it. | 117 stream.reset((SkStream*)NULL); // Might as well drop this when we're done w
ith it. |
| 116 canvas->clipRect(kSKPViewport); | 118 canvas->clipRect(kSKPViewport); |
| 117 canvas->drawPicture(pic); | 119 canvas->drawPicture(pic); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 SkPictureRecorder recorder; | 263 SkPictureRecorder recorder; |
| 262 Error err = src.draw(recorder.beginRecording(size.width(), size.height())); | 264 Error err = src.draw(recorder.beginRecording(size.width(), size.height())); |
| 263 if (!err.isEmpty()) { | 265 if (!err.isEmpty()) { |
| 264 return err; | 266 return err; |
| 265 } | 267 } |
| 266 SkAutoTUnref<SkPicture> pic(recorder.endRecording()); | 268 SkAutoTUnref<SkPicture> pic(recorder.endRecording()); |
| 267 | 269 |
| 268 // Serialize it and then deserialize it. | 270 // Serialize it and then deserialize it. |
| 269 SkDynamicMemoryWStream wStream; | 271 SkDynamicMemoryWStream wStream; |
| 270 pic->serialize(&wStream); | 272 pic->serialize(&wStream); |
| 271 SkAutoTUnref<SkStream> rStream(wStream.detachAsStream()); | 273 SkAutoTDelete<SkStream> rStream(wStream.detachAsStream()); |
| 272 SkAutoTUnref<SkPicture> deserialized(SkPicture::CreateFromStream(rStream)); | 274 SkAutoTUnref<SkPicture> deserialized(SkPicture::CreateFromStream(rStream)); |
| 273 | 275 |
| 274 // Turn that deserialized picture into a Src, draw it into our Sink to fill
bitmap or stream. | 276 // Turn that deserialized picture into a Src, draw it into our Sink to fill
bitmap or stream. |
| 275 struct ProxySrc : public Src { | 277 struct ProxySrc : public Src { |
| 276 const SkPicture* fPic; | 278 const SkPicture* fPic; |
| 277 const SkISize fSize; | 279 const SkISize fSize; |
| 278 ProxySrc(const SkPicture* pic, SkISize size) : fPic(pic), fSize(size) {} | 280 ProxySrc(const SkPicture* pic, SkISize size) : fPic(pic), fSize(size) {} |
| 279 | 281 |
| 280 Error draw(SkCanvas* canvas) const SK_OVERRIDE { | 282 Error draw(SkCanvas* canvas) const SK_OVERRIDE { |
| 281 canvas->drawPicture(fPic); | 283 canvas->drawPicture(fPic); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 surfaces.unrefAll(); | 349 surfaces.unrefAll(); |
| 348 return ""; | 350 return ""; |
| 349 } | 351 } |
| 350 SkISize size() const SK_OVERRIDE { return fSize; } | 352 SkISize size() const SK_OVERRIDE { return fSize; } |
| 351 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou
ld be calling this. | 353 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou
ld be calling this. |
| 352 } proxy(fW, fH, pic, src.size()); | 354 } proxy(fW, fH, pic, src.size()); |
| 353 return fSink->draw(proxy, bitmap, stream); | 355 return fSink->draw(proxy, bitmap, stream); |
| 354 } | 356 } |
| 355 | 357 |
| 356 } // namespace DM | 358 } // namespace DM |
| OLD | NEW |