| 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 "SkDocument.h" | 5 #include "SkDocument.h" |
| 6 #include "SkError.h" | 6 #include "SkError.h" |
| 7 #include "SkMultiPictureDraw.h" | 7 #include "SkMultiPictureDraw.h" |
| 8 #include "SkNullCanvas.h" | 8 #include "SkNullCanvas.h" |
| 9 #include "SkOSFile.h" | 9 #include "SkOSFile.h" |
| 10 #include "SkPictureData.h" | 10 #include "SkPictureData.h" |
| 11 #include "SkPictureRecorder.h" | 11 #include "SkPictureRecorder.h" |
| 12 #include "SkRandom.h" | 12 #include "SkRandom.h" |
| 13 #include "SkScanlineDecoder.h" |
| 14 #include "SkStream.h" |
| 13 #include "SkSVGCanvas.h" | 15 #include "SkSVGCanvas.h" |
| 14 #include "SkStream.h" | |
| 15 #include "SkXMLWriter.h" | 16 #include "SkXMLWriter.h" |
| 16 | 17 |
| 17 namespace DM { | 18 namespace DM { |
| 18 | 19 |
| 19 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} | 20 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} |
| 20 | 21 |
| 21 Error GMSrc::draw(SkCanvas* canvas) const { | 22 Error GMSrc::draw(SkCanvas* canvas) const { |
| 22 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL)); | 23 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL)); |
| 23 canvas->concat(gm->getInitialTransform()); | 24 canvas->concat(gm->getInitialTransform()); |
| 24 gm->draw(canvas); | 25 gm->draw(canvas); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 decodeInfo = decodeInfo.makeAlphaType(kPremul_SkAlphaType); | 64 decodeInfo = decodeInfo.makeAlphaType(kPremul_SkAlphaType); |
| 64 } | 65 } |
| 65 | 66 |
| 66 SkBitmap bitmap; | 67 SkBitmap bitmap; |
| 67 if (!bitmap.tryAllocPixels(decodeInfo)) { | 68 if (!bitmap.tryAllocPixels(decodeInfo)) { |
| 68 return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPath.c_str(
), | 69 return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPath.c_str(
), |
| 69 decodeInfo.width(), decodeInfo.height()); | 70 decodeInfo.width(), decodeInfo.height()); |
| 70 } | 71 } |
| 71 | 72 |
| 72 SkAutoLockPixels alp(bitmap); | 73 SkAutoLockPixels alp(bitmap); |
| 73 switch (codec->getPixels(decodeInfo, bitmap.getPixels(), bitmap.rowBytes()))
{ | 74 SkScanlineDecoder* scanlineDecoder = codec->getScanlineDecoder(decodeInfo); |
| 74 case SkImageGenerator::kSuccess: | 75 if (NULL == scanlineDecoder) { |
| 75 // We consider incomplete to be valid, since we should still decode what
is | 76 return Error::Nonfatal("Cannot use scanline decoder for all images"); |
| 76 // available. | |
| 77 case SkImageGenerator::kIncompleteInput: | |
| 78 canvas->drawBitmap(bitmap, 0, 0); | |
| 79 return ""; | |
| 80 case SkImageGenerator::kInvalidConversion: | |
| 81 return Error::Nonfatal("Incompatible colortype conversion"); | |
| 82 default: | |
| 83 // Everything else is considered a failure. | |
| 84 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str()); | |
| 85 } | 77 } |
| 78 |
| 79 for (int y = 0; y < decodeInfo.height(); ++y) { |
| 80 const SkImageGenerator::Result result = |
| 81 scanlineDecoder->getScanlines(bitmap.getAddr(0, y), 1, 0); |
| 82 switch (result) { |
| 83 case SkImageGenerator::kSuccess: |
| 84 // We consider incomplete to be valid, since we should still dec
ode what is |
| 85 // available. |
| 86 case SkImageGenerator::kIncompleteInput: |
| 87 break; |
| 88 default: |
| 89 // Everything else is considered a failure. |
| 90 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str()); |
| 91 } |
| 92 } |
| 93 |
| 94 const SkImageGenerator::Result result = scanlineDecoder->finish(); |
| 95 if (result != SkImageGenerator::kSuccess) { |
| 96 return SkStringPrintf("failed in finish!"); |
| 97 } |
| 98 canvas->drawBitmap(bitmap, 0, 0); |
| 99 return ""; |
| 86 } | 100 } |
| 87 | 101 |
| 88 SkISize CodecSrc::size() const { | 102 SkISize CodecSrc::size() const { |
| 89 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 103 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
| 90 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | 104 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
| 91 return codec->getInfo().dimensions(); | 105 return codec->getInfo().dimensions(); |
| 92 } | 106 } |
| 93 | 107 |
| 94 Name CodecSrc::name() const { | 108 Name CodecSrc::name() const { |
| 95 return SkOSPath::Basename(fPath.c_str()); | 109 return SkOSPath::Basename(fPath.c_str()); |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 surfaces.unrefAll(); | 588 surfaces.unrefAll(); |
| 575 return ""; | 589 return ""; |
| 576 } | 590 } |
| 577 SkISize size() const SK_OVERRIDE { return fSize; } | 591 SkISize size() const SK_OVERRIDE { return fSize; } |
| 578 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou
ld be calling this. | 592 Name name() const SK_OVERRIDE { sk_throw(); return ""; } // No one shou
ld be calling this. |
| 579 } proxy(fW, fH, pic, src.size()); | 593 } proxy(fW, fH, pic, src.size()); |
| 580 return fSink->draw(proxy, bitmap, stream, log); | 594 return fSink->draw(proxy, bitmap, stream, log); |
| 581 } | 595 } |
| 582 | 596 |
| 583 } // namespace DM | 597 } // namespace DM |
| OLD | NEW |