Chromium Code Reviews| 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 "SkDocument.h" | 5 #include "SkDocument.h" |
| 5 #include "SkMultiPictureDraw.h" | 6 #include "SkMultiPictureDraw.h" |
| 6 #include "SkNullCanvas.h" | 7 #include "SkNullCanvas.h" |
| 7 #include "SkOSFile.h" | 8 #include "SkOSFile.h" |
| 8 #include "SkPictureRecorder.h" | 9 #include "SkPictureRecorder.h" |
| 9 #include "SkRandom.h" | 10 #include "SkRandom.h" |
| 10 #include "SkSVGCanvas.h" | 11 #include "SkSVGCanvas.h" |
| 11 #include "SkStream.h" | 12 #include "SkStream.h" |
| 12 #include "SkXMLWriter.h" | 13 #include "SkXMLWriter.h" |
| 13 | 14 |
| 15 DEFINE_bool(codec, false, "Use SkCodec instead of SkImageDecoder"); | |
| 16 | |
| 14 namespace DM { | 17 namespace DM { |
| 15 | 18 |
| 16 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} | 19 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} |
| 17 | 20 |
| 18 Error GMSrc::draw(SkCanvas* canvas) const { | 21 Error GMSrc::draw(SkCanvas* canvas) const { |
| 19 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL)); | 22 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL)); |
| 20 canvas->concat(gm->getInitialTransform()); | 23 canvas->concat(gm->getInitialTransform()); |
| 21 gm->draw(canvas); | 24 gm->draw(canvas); |
| 22 return ""; | 25 return ""; |
| 23 } | 26 } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 38 | 41 |
| 39 Error ImageSrc::draw(SkCanvas* canvas) const { | 42 Error ImageSrc::draw(SkCanvas* canvas) const { |
| 40 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 43 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
| 41 if (!encoded) { | 44 if (!encoded) { |
| 42 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); | 45 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
| 43 } | 46 } |
| 44 const SkColorType dstColorType = canvas->imageInfo().colorType(); | 47 const SkColorType dstColorType = canvas->imageInfo().colorType(); |
| 45 if (fDivisor == 0) { | 48 if (fDivisor == 0) { |
| 46 // Decode the full image. | 49 // Decode the full image. |
| 47 SkBitmap bitmap; | 50 SkBitmap bitmap; |
| 48 if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(), &bit map, | 51 if (FLAGS_codec) { |
| 49 dstColorType, SkImageDecoder::kDecodeP ixels_Mode)) { | 52 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
|
mtklein
2015/02/26 20:41:13
You might want to split off a CodecSrc as a separa
scroggo
2015/02/26 21:00:11
Thanks for the feedback. This is really a stopgap
| |
| 50 return SkStringPrintf("Couldn't decode %s.", fPath.c_str()); | 53 if (!codec) { |
| 54 return SkStringPrintf("Couldn't decode %s.", fPath.c_str()); | |
| 55 } | |
| 56 SkImageInfo info; | |
| 57 if (!codec->getInfo(&info)) { | |
| 58 return SkStringPrintf("Couldn't getInfo %s.", fPath.c_str()); | |
| 59 } | |
| 60 info = info.makeColorType(dstColorType); | |
| 61 if (info.alphaType() == kUnpremul_SkAlphaType) { | |
| 62 // FIXME: Currently we cannot draw unpremultiplied sources. | |
| 63 info = info.makeAlphaType(kPremul_SkAlphaType); | |
| 64 } | |
| 65 if (!bitmap.tryAllocPixels(info)) { | |
| 66 return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPat h.c_str(), | |
| 67 info.width(), info.height()); | |
| 68 } | |
| 69 SkAutoLockPixels alp(bitmap); | |
| 70 const SkImageGenerator::Result result = codec->getPixels(info, bitma p.getPixels(), | |
| 71 bitmap.rowB ytes()); | |
| 72 if (result != SkImageGenerator::kSuccess) { | |
| 73 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str()); | |
| 74 } | |
| 75 } else { | |
| 76 if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(), &bitmap, | |
| 77 dstColorType, SkImageDecoder::kDec odePixels_Mode)) { | |
| 78 return SkStringPrintf("Couldn't decode %s.", fPath.c_str()); | |
| 79 } | |
| 51 } | 80 } |
| 52 encoded.reset((SkData*)NULL); // Might as well drop this when we're don e with it. | 81 encoded.reset((SkData*)NULL); // Might as well drop this when we're don e with it. |
| 53 canvas->drawBitmap(bitmap, 0,0); | 82 canvas->drawBitmap(bitmap, 0,0); |
| 54 return ""; | 83 return ""; |
| 55 } | 84 } |
| 56 // Decode subsets. This is a little involved. | 85 // Decode subsets. This is a little involved. |
| 57 SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(encoded)); | 86 SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(encoded)); |
| 58 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream.get())) ; | 87 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream.get())) ; |
| 59 if (!decoder) { | 88 if (!decoder) { |
| 60 return SkStringPrintf("Can't find a good decoder for %s.", fPath.c_str() ); | 89 return SkStringPrintf("Can't find a good decoder for %s.", fPath.c_str() ); |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 457 surfaces.unrefAll(); | 486 surfaces.unrefAll(); |
| 458 return ""; | 487 return ""; |
| 459 } | 488 } |
| 460 SkISize size() const SK_OVERRIDE { return fSize; } | 489 SkISize size() const SK_OVERRIDE { return fSize; } |
| 461 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou ld be calling this. | 490 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou ld be calling this. |
| 462 } proxy(fW, fH, pic, src.size()); | 491 } proxy(fW, fH, pic, src.size()); |
| 463 return fSink->draw(proxy, bitmap, stream, log); | 492 return fSink->draw(proxy, bitmap, stream, log); |
| 464 } | 493 } |
| 465 | 494 |
| 466 } // namespace DM | 495 } // namespace DM |
| OLD | NEW |