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 "SkCodec.h" | 10 #include "SkCodec.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 {} | 72 {} |
73 | 73 |
74 bool CodecSrc::veto(SinkFlags flags) const { | 74 bool CodecSrc::veto(SinkFlags flags) const { |
75 // No need to test decoding to non-raster or indirect backend. | 75 // No need to test decoding to non-raster or indirect backend. |
76 // TODO: Once we implement GPU paths (e.g. JPEG YUV), we should use a deferr ed decode to | 76 // TODO: Once we implement GPU paths (e.g. JPEG YUV), we should use a deferr ed decode to |
77 // let the GPU handle it. | 77 // let the GPU handle it. |
78 return flags.type != SinkFlags::kRaster | 78 return flags.type != SinkFlags::kRaster |
79 || flags.approach != SinkFlags::kDirect; | 79 || flags.approach != SinkFlags::kDirect; |
80 } | 80 } |
81 | 81 |
82 SkScanlineDecoder* start_scanline_decoder(SkData* encoded, const SkImageInfo& in fo, | |
83 SkPMColor* colorPtr, int* colorCountPtr) { | |
84 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder(SkScanlineDecoder::NewFromD ata(encoded)); | |
85 if (NULL == scanlineDecoder) { | |
86 return NULL; | |
87 } | |
88 // DM scanline test assume kTopDown scanline ordering. Other orderings are | |
89 // tested from within SkScaledCodec. | |
90 if (SkScanlineDecoder::kTopDown_SkScanlineOrder != scanlineDecoder->getScanl ineOrder()) { | |
91 return NULL; | |
92 } | |
93 if (SkCodec::kSuccess != scanlineDecoder->start(info, NULL, colorPtr, colorC ountPtr)) { | |
94 return NULL; | |
95 } | |
96 return scanlineDecoder.detach(); | |
97 } | |
98 | |
82 Error CodecSrc::draw(SkCanvas* canvas) const { | 99 Error CodecSrc::draw(SkCanvas* canvas) const { |
83 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 100 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
84 if (!encoded) { | 101 if (!encoded) { |
85 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); | 102 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
86 } | 103 } |
87 SkAutoTDelete<SkCodec> codec(SkScaledCodec::NewFromData(encoded)); | 104 SkAutoTDelete<SkCodec> codec(SkScaledCodec::NewFromData(encoded)); |
88 if (NULL == codec.get()) { | 105 if (NULL == codec.get()) { |
89 // scaledCodec not supported, try normal codec | 106 // scaledCodec not supported, try normal codec |
90 codec.reset(SkCodec::NewFromData(encoded)); | 107 codec.reset(SkCodec::NewFromData(encoded)); |
91 if (NULL == codec.get()) { | 108 if (NULL == codec.get()) { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 return Error::Nonfatal("Incompatible colortype conversion"); | 180 return Error::Nonfatal("Incompatible colortype conversion"); |
164 default: | 181 default: |
165 // Everything else is considered a failure. | 182 // Everything else is considered a failure. |
166 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str( )); | 183 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str( )); |
167 } | 184 } |
168 canvas->drawBitmap(bitmap, 0, 0); | 185 canvas->drawBitmap(bitmap, 0, 0); |
169 break; | 186 break; |
170 } | 187 } |
171 case kScanline_Mode: { | 188 case kScanline_Mode: { |
172 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder( | 189 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder( |
173 SkScanlineDecoder::NewFromData(encoded)); | 190 start_scanline_decoder(encoded.get(), decodeInfo, colorPtr, colorCountPtr)); |
174 if (NULL == scanlineDecoder || SkCodec::kSuccess != | 191 if (NULL == scanlineDecoder) { |
175 scanlineDecoder->start(decodeInfo, NULL, colorPtr, colorCoun tPtr)) { | 192 return Error::Nonfatal("Could not start top-down scanline decode r"); |
176 return Error::Nonfatal("Cannot use scanline decoder for all imag es"); | |
177 } | 193 } |
178 | 194 |
179 const SkCodec::Result result = scanlineDecoder->getScanlines( | 195 const SkCodec::Result result = scanlineDecoder->getScanlines( |
180 bitmap.getAddr(0, 0), decodeInfo.height(), bitmap.rowBytes() ); | 196 bitmap.getAddr(0, 0), decodeInfo.height(), bitmap.rowBytes() ); |
181 switch (result) { | 197 switch (result) { |
182 case SkCodec::kSuccess: | 198 case SkCodec::kSuccess: |
183 case SkCodec::kIncompleteInput: | 199 case SkCodec::kIncompleteInput: |
184 break; | 200 break; |
185 default: | 201 default: |
186 return SkStringPrintf("%s failed with error message %d", | 202 return SkStringPrintf("%s failed with error message %d", |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 const int currentSubsetWidth = (col + 1 == divisor) ? | 243 const int currentSubsetWidth = (col + 1 == divisor) ? |
228 subsetWidth + extraX : subsetWidth; | 244 subsetWidth + extraX : subsetWidth; |
229 const int x = col * subsetWidth; | 245 const int x = col * subsetWidth; |
230 for (int row = 0; row < divisor; row++) { | 246 for (int row = 0; row < divisor; row++) { |
231 //currentSubsetHeight may be larger than subsetHeight for bo ttom subsets | 247 //currentSubsetHeight may be larger than subsetHeight for bo ttom subsets |
232 const int currentSubsetHeight = (row + 1 == divisor) ? | 248 const int currentSubsetHeight = (row + 1 == divisor) ? |
233 subsetHeight + extraY : subsetHeight; | 249 subsetHeight + extraY : subsetHeight; |
234 const int y = row * subsetHeight; | 250 const int y = row * subsetHeight; |
235 //create scanline decoder for each subset | 251 //create scanline decoder for each subset |
236 SkAutoTDelete<SkScanlineDecoder> subsetScanlineDecoder( | 252 SkAutoTDelete<SkScanlineDecoder> subsetScanlineDecoder( |
237 SkScanlineDecoder::NewFromData(encoded)); | 253 start_scanline_decoder(encoded.get(), decodeInfo, |
238 if (NULL == subsetScanlineDecoder || SkCodec::kSuccess != | 254 colorPtr, colorCountPtr)); |
239 subsetScanlineDecoder->start( | 255 if (NULL == subsetScanlineDecoder) { |
240 decodeInfo, NULL, colorPtr, colorCountPtr)) | |
241 { | |
242 if (x == 0 && y == 0) { | 256 if (x == 0 && y == 0) { |
243 //first try, image may not be compatible | 257 //first try, image may not be compatible |
244 return Error::Nonfatal("Cannot use scanline decoder for all images"); | 258 return Error::Nonfatal("Could not start top-down sca nline decoder"); |
245 } else { | 259 } else { |
246 return "Error scanline decoder is NULL"; | 260 return "Error scanline decoder is NULL"; |
247 } | 261 } |
248 } | 262 } |
263 if (SkScanlineDecoder::kTopDown_SkScanlineOrder != | |
264 subsetScanlineDecoder->getScanlineOrder()) { | |
265 return Error::Nonfatal("Test mode not supported"); | |
scroggo
2015/08/27 20:14:22
Wait, why do we require kTopDown? Don't we know ho
msarett
2015/08/27 21:21:46
First, this check should be deleted because it is
scroggo
2015/08/28 13:28:46
sgtm
| |
266 } | |
249 //skip to first line of subset | 267 //skip to first line of subset |
250 const SkCodec::Result skipResult = | 268 const SkCodec::Result skipResult = |
251 subsetScanlineDecoder->skipScanlines(y); | 269 subsetScanlineDecoder->skipScanlines(y); |
252 switch (skipResult) { | 270 switch (skipResult) { |
253 case SkCodec::kSuccess: | 271 case SkCodec::kSuccess: |
254 case SkCodec::kIncompleteInput: | 272 case SkCodec::kIncompleteInput: |
255 break; | 273 break; |
256 default: | 274 default: |
257 return SkStringPrintf("%s failed after attempting to skip %d scanlines" | 275 return SkStringPrintf("%s failed after attempting to skip %d scanlines" |
258 "with error message %d", fPath.c_str(), y, ( int) skipResult); | 276 "with error message %d", fPath.c_str(), y, ( int) skipResult); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
297 break; | 315 break; |
298 } | 316 } |
299 case kStripe_Mode: { | 317 case kStripe_Mode: { |
300 const int height = decodeInfo.height(); | 318 const int height = decodeInfo.height(); |
301 // This value is chosen arbitrarily. We exercise more cases by choo sing a value that | 319 // This value is chosen arbitrarily. We exercise more cases by choo sing a value that |
302 // does not align with image blocks. | 320 // does not align with image blocks. |
303 const int stripeHeight = 37; | 321 const int stripeHeight = 37; |
304 const int numStripes = (height + stripeHeight - 1) / stripeHeight; | 322 const int numStripes = (height + stripeHeight - 1) / stripeHeight; |
305 | 323 |
306 // Decode odd stripes | 324 // Decode odd stripes |
307 SkAutoTDelete<SkScanlineDecoder> decoder(SkScanlineDecoder::NewFromD ata(encoded)); | 325 SkAutoTDelete<SkScanlineDecoder> decoder( |
308 if (NULL == decoder || SkCodec::kSuccess != | 326 start_scanline_decoder(encoded.get(), decodeInfo, colorPtr, colorCountPtr)); |
309 decoder->start(decodeInfo, NULL, colorPtr, colorCountPtr)) { | 327 if (NULL == decoder) { |
310 return Error::Nonfatal("Cannot use scanline decoder for all imag es"); | 328 return Error::Nonfatal("Could not start top-down scanline decode r"); |
311 } | 329 } |
312 for (int i = 0; i < numStripes; i += 2) { | 330 for (int i = 0; i < numStripes; i += 2) { |
313 // Skip a stripe | 331 // Skip a stripe |
314 const int linesToSkip = SkTMin(stripeHeight, height - i * stripe Height); | 332 const int linesToSkip = SkTMin(stripeHeight, height - i * stripe Height); |
315 SkCodec::Result result = decoder->skipScanlines(linesToSkip); | 333 SkCodec::Result result = decoder->skipScanlines(linesToSkip); |
316 switch (result) { | 334 switch (result) { |
317 case SkCodec::kSuccess: | 335 case SkCodec::kSuccess: |
318 case SkCodec::kIncompleteInput: | 336 case SkCodec::kIncompleteInput: |
319 break; | 337 break; |
320 default: | 338 default: |
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1064 skr.visit<void>(i, drawsAsSingletonPictures); | 1082 skr.visit<void>(i, drawsAsSingletonPictures); |
1065 } | 1083 } |
1066 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); | 1084 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); |
1067 | 1085 |
1068 canvas->drawPicture(macroPic); | 1086 canvas->drawPicture(macroPic); |
1069 return ""; | 1087 return ""; |
1070 }); | 1088 }); |
1071 } | 1089 } |
1072 | 1090 |
1073 } // namespace DM | 1091 } // namespace DM |
OLD | NEW |