Index: dm/DMSrcSink.cpp |
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp |
index a7240b8579e636d29e27efa93147a95efa5a4319..8fe9e613aa305c11de3875ecd3b8e4c397f4c253 100644 |
--- a/dm/DMSrcSink.cpp |
+++ b/dm/DMSrcSink.cpp |
@@ -79,6 +79,26 @@ bool CodecSrc::veto(SinkFlags flags) const { |
|| flags.approach != SinkFlags::kDirect; |
} |
+SkScanlineDecoder* start_scanline_decoder(SkData* encoded, const SkImageInfo& info, |
+ SkPMColor* colorPtr, int* colorCountPtr) { |
+ SkAutoTDelete<SkScanlineDecoder> scanlineDecoder(SkScanlineDecoder::NewFromData(encoded)); |
+ if (NULL == scanlineDecoder) { |
+ return NULL; |
+ } |
+ // DM scanline test assume kTopDown scanline ordering. Other orderings are |
+ // tested from within SkScaledCodec. |
+ // TODO (msarett): Redesign the CodecSrc tests to improve our coverage of SkCodec and |
+ // SkScanlineDecoder functionality. Maybe we should write code to explicitly |
+ // test kNone, kOutOfOrder, and kBottomUp. |
+ if (SkScanlineDecoder::kTopDown_SkScanlineOrder != scanlineDecoder->getScanlineOrder()) { |
+ return NULL; |
+ } |
+ if (SkCodec::kSuccess != scanlineDecoder->start(info, NULL, colorPtr, colorCountPtr)) { |
+ return NULL; |
+ } |
+ return scanlineDecoder.detach(); |
+} |
+ |
Error CodecSrc::draw(SkCanvas* canvas) const { |
SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
if (!encoded) { |
@@ -170,10 +190,9 @@ Error CodecSrc::draw(SkCanvas* canvas) const { |
} |
case kScanline_Mode: { |
SkAutoTDelete<SkScanlineDecoder> scanlineDecoder( |
- SkScanlineDecoder::NewFromData(encoded)); |
- if (NULL == scanlineDecoder || SkCodec::kSuccess != |
- scanlineDecoder->start(decodeInfo, NULL, colorPtr, colorCountPtr)) { |
- return Error::Nonfatal("Cannot use scanline decoder for all images"); |
+ start_scanline_decoder(encoded.get(), decodeInfo, colorPtr, colorCountPtr)); |
+ if (NULL == scanlineDecoder) { |
+ return Error::Nonfatal("Could not start top-down scanline decoder"); |
} |
const SkCodec::Result result = scanlineDecoder->getScanlines( |
@@ -234,14 +253,12 @@ Error CodecSrc::draw(SkCanvas* canvas) const { |
const int y = row * subsetHeight; |
//create scanline decoder for each subset |
SkAutoTDelete<SkScanlineDecoder> subsetScanlineDecoder( |
- SkScanlineDecoder::NewFromData(encoded)); |
- if (NULL == subsetScanlineDecoder || SkCodec::kSuccess != |
- subsetScanlineDecoder->start( |
- decodeInfo, NULL, colorPtr, colorCountPtr)) |
- { |
+ start_scanline_decoder(encoded.get(), decodeInfo, |
+ colorPtr, colorCountPtr)); |
+ if (NULL == subsetScanlineDecoder) { |
if (x == 0 && y == 0) { |
//first try, image may not be compatible |
- return Error::Nonfatal("Cannot use scanline decoder for all images"); |
+ return Error::Nonfatal("Could not start top-down scanline decoder"); |
} else { |
return "Error scanline decoder is NULL"; |
} |
@@ -304,10 +321,10 @@ Error CodecSrc::draw(SkCanvas* canvas) const { |
const int numStripes = (height + stripeHeight - 1) / stripeHeight; |
// Decode odd stripes |
- SkAutoTDelete<SkScanlineDecoder> decoder(SkScanlineDecoder::NewFromData(encoded)); |
- if (NULL == decoder || SkCodec::kSuccess != |
- decoder->start(decodeInfo, NULL, colorPtr, colorCountPtr)) { |
- return Error::Nonfatal("Cannot use scanline decoder for all images"); |
+ SkAutoTDelete<SkScanlineDecoder> decoder( |
+ start_scanline_decoder(encoded.get(), decodeInfo, colorPtr, colorCountPtr)); |
+ if (NULL == decoder) { |
+ return Error::Nonfatal("Could not start top-down scanline decoder"); |
} |
for (int i = 0; i < numStripes; i += 2) { |
// Skip a stripe |