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 "SkAndroidCodec.h" | 9 #include "SkAndroidCodec.h" |
10 #include "SkCodec.h" | 10 #include "SkCodec.h" |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 // We will replicate the names used by CodecSrc so that images can | 226 // We will replicate the names used by CodecSrc so that images can |
227 // be compared in Gold. | 227 // be compared in Gold. |
228 if (1 == fSampleSize) { | 228 if (1 == fSampleSize) { |
229 return SkOSPath::Basename(fPath.c_str()); | 229 return SkOSPath::Basename(fPath.c_str()); |
230 } | 230 } |
231 return get_scaled_name(fPath, 1.0f / (float) fSampleSize); | 231 return get_scaled_name(fPath, 1.0f / (float) fSampleSize); |
232 } | 232 } |
233 | 233 |
234 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ | 234 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
235 | 235 |
236 CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType, float scale) | 236 CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType, SkAlphaType
dstAlphaType, |
| 237 float scale) |
237 : fPath(path) | 238 : fPath(path) |
238 , fMode(mode) | 239 , fMode(mode) |
239 , fDstColorType(dstColorType) | 240 , fDstColorType(dstColorType) |
| 241 , fDstAlphaType(dstAlphaType) |
240 , fScale(scale) | 242 , fScale(scale) |
241 {} | 243 {} |
242 | 244 |
243 bool CodecSrc::veto(SinkFlags flags) const { | 245 bool CodecSrc::veto(SinkFlags flags) const { |
244 // Test CodecImageGenerator on 8888, 565, and gpu | 246 // Test CodecImageGenerator on 8888, 565, and gpu |
245 if (kGen_Mode == fMode) { | 247 if (kGen_Mode == fMode) { |
246 return (flags.type != SinkFlags::kRaster || flags.approach != SinkFlags:
:kDirect) && | 248 return (flags.type != SinkFlags::kRaster || flags.approach != SinkFlags:
:kDirect) && |
247 flags.type != SinkFlags::kGPU; | 249 flags.type != SinkFlags::kGPU; |
248 } | 250 } |
249 | 251 |
250 // Test all other modes to direct raster backends (8888 and 565). | 252 // Test all other modes to direct raster backends (8888 and 565). |
251 return flags.type != SinkFlags::kRaster || flags.approach != SinkFlags::kDir
ect; | 253 return flags.type != SinkFlags::kRaster || flags.approach != SinkFlags::kDir
ect; |
252 } | 254 } |
253 | 255 |
254 bool get_decode_info(SkImageInfo* decodeInfo, const SkImageInfo& defaultInfo, | 256 bool get_decode_info(SkImageInfo* decodeInfo, SkColorType canvasColorType, |
255 SkColorType canvasColorType, CodecSrc::DstColorType dstColorType) { | 257 CodecSrc::DstColorType dstColorType) { |
256 switch (dstColorType) { | 258 switch (dstColorType) { |
257 case CodecSrc::kIndex8_Always_DstColorType: | 259 case CodecSrc::kIndex8_Always_DstColorType: |
258 if (kRGB_565_SkColorType == canvasColorType) { | 260 if (kRGB_565_SkColorType == canvasColorType) { |
259 return false; | 261 return false; |
260 } | 262 } |
261 *decodeInfo = defaultInfo.makeColorType(kIndex_8_SkColorType); | 263 *decodeInfo = decodeInfo->makeColorType(kIndex_8_SkColorType); |
262 break; | 264 break; |
263 case CodecSrc::kGrayscale_Always_DstColorType: | 265 case CodecSrc::kGrayscale_Always_DstColorType: |
264 if (kRGB_565_SkColorType == canvasColorType) { | 266 if (kRGB_565_SkColorType == canvasColorType) { |
265 return false; | 267 return false; |
266 } | 268 } |
267 *decodeInfo = defaultInfo.makeColorType(kGray_8_SkColorType); | 269 *decodeInfo = decodeInfo->makeColorType(kGray_8_SkColorType); |
268 break; | 270 break; |
269 default: | 271 default: |
270 *decodeInfo = defaultInfo.makeColorType(canvasColorType); | 272 *decodeInfo = decodeInfo->makeColorType(canvasColorType); |
271 break; | 273 break; |
272 } | 274 } |
273 | 275 |
274 // FIXME: Currently we cannot draw unpremultiplied sources. | |
275 if (decodeInfo->alphaType() == kUnpremul_SkAlphaType) { | |
276 *decodeInfo = decodeInfo->makeAlphaType(kPremul_SkAlphaType); | |
277 } | |
278 return true; | 276 return true; |
279 } | 277 } |
280 | 278 |
281 Error test_gen(SkCanvas* canvas, SkData* data) { | 279 Error test_gen(SkCanvas* canvas, SkData* data) { |
282 SkAutoTDelete<SkImageGenerator> gen = SkCodecImageGenerator::NewFromEncodedC
odec(data); | 280 SkAutoTDelete<SkImageGenerator> gen = SkCodecImageGenerator::NewFromEncodedC
odec(data); |
283 if (!gen) { | 281 if (!gen) { |
284 return "Could not create image generator."; | 282 return "Could not create image generator."; |
285 } | 283 } |
286 | 284 |
287 // FIXME: The gpu backend does not draw kGray sources correctly. (skbug.com/
4822) | 285 // FIXME: The gpu backend does not draw kGray sources correctly. (skbug.com/
4822) |
(...skipping 24 matching lines...) Expand all Loading... |
312 // so we will handle it in its own function. | 310 // so we will handle it in its own function. |
313 if (kGen_Mode == fMode) { | 311 if (kGen_Mode == fMode) { |
314 return test_gen(canvas, encoded); | 312 return test_gen(canvas, encoded); |
315 } | 313 } |
316 | 314 |
317 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | 315 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
318 if (nullptr == codec.get()) { | 316 if (nullptr == codec.get()) { |
319 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str()); | 317 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str()); |
320 } | 318 } |
321 | 319 |
322 SkImageInfo decodeInfo; | 320 SkImageInfo decodeInfo = codec->getInfo().makeAlphaType(fDstAlphaType); |
323 if (!get_decode_info(&decodeInfo, codec->getInfo(), canvas->imageInfo().colo
rType(), | 321 if (!get_decode_info(&decodeInfo, canvas->imageInfo().colorType(), fDstColor
Type)) { |
324 fDstColorType)) { | |
325 return Error::Nonfatal("Testing non-565 to 565 is uninteresting."); | 322 return Error::Nonfatal("Testing non-565 to 565 is uninteresting."); |
326 } | 323 } |
327 | 324 |
328 // Try to scale the image if it is desired | 325 // Try to scale the image if it is desired |
329 SkISize size = codec->getScaledDimensions(fScale); | 326 SkISize size = codec->getScaledDimensions(fScale); |
330 if (size == decodeInfo.dimensions() && 1.0f != fScale) { | 327 if (size == decodeInfo.dimensions() && 1.0f != fScale) { |
331 return Error::Nonfatal("Test without scaling is uninteresting."); | 328 return Error::Nonfatal("Test without scaling is uninteresting."); |
332 } | 329 } |
333 | 330 |
334 // Visually inspecting very small output images is not necessary. We will | 331 // Visually inspecting very small output images is not necessary. We will |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 Name CodecSrc::name() const { | 560 Name CodecSrc::name() const { |
564 if (1.0f == fScale) { | 561 if (1.0f == fScale) { |
565 return SkOSPath::Basename(fPath.c_str()); | 562 return SkOSPath::Basename(fPath.c_str()); |
566 } | 563 } |
567 return get_scaled_name(fPath, fScale); | 564 return get_scaled_name(fPath, fScale); |
568 } | 565 } |
569 | 566 |
570 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ | 567 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
571 | 568 |
572 AndroidCodecSrc::AndroidCodecSrc(Path path, Mode mode, CodecSrc::DstColorType ds
tColorType, | 569 AndroidCodecSrc::AndroidCodecSrc(Path path, Mode mode, CodecSrc::DstColorType ds
tColorType, |
573 int sampleSize) | 570 SkAlphaType dstAlphaType, int sampleSize) |
574 : fPath(path) | 571 : fPath(path) |
575 , fMode(mode) | 572 , fMode(mode) |
576 , fDstColorType(dstColorType) | 573 , fDstColorType(dstColorType) |
| 574 , fDstAlphaType(dstAlphaType) |
577 , fSampleSize(sampleSize) | 575 , fSampleSize(sampleSize) |
578 {} | 576 {} |
579 | 577 |
580 bool AndroidCodecSrc::veto(SinkFlags flags) const { | 578 bool AndroidCodecSrc::veto(SinkFlags flags) const { |
581 // No need to test decoding to non-raster or indirect backend. | 579 // No need to test decoding to non-raster or indirect backend. |
582 return flags.type != SinkFlags::kRaster | 580 return flags.type != SinkFlags::kRaster |
583 || flags.approach != SinkFlags::kDirect; | 581 || flags.approach != SinkFlags::kDirect; |
584 } | 582 } |
585 | 583 |
586 Error AndroidCodecSrc::draw(SkCanvas* canvas) const { | 584 Error AndroidCodecSrc::draw(SkCanvas* canvas) const { |
587 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 585 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
588 if (!encoded) { | 586 if (!encoded) { |
589 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); | 587 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
590 } | 588 } |
591 SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(encoded)); | 589 SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(encoded)); |
592 if (nullptr == codec.get()) { | 590 if (nullptr == codec.get()) { |
593 return SkStringPrintf("Couldn't create android codec for %s.", fPath.c_s
tr()); | 591 return SkStringPrintf("Couldn't create android codec for %s.", fPath.c_s
tr()); |
594 } | 592 } |
595 | 593 |
596 SkImageInfo decodeInfo; | 594 SkImageInfo decodeInfo = codec->getInfo().makeAlphaType(fDstAlphaType); |
597 if (!get_decode_info(&decodeInfo, codec->getInfo(), canvas->imageInfo().colo
rType(), | 595 if (!get_decode_info(&decodeInfo, canvas->imageInfo().colorType(), fDstColor
Type)) { |
598 fDstColorType)) { | |
599 return Error::Nonfatal("Testing non-565 to 565 is uninteresting."); | 596 return Error::Nonfatal("Testing non-565 to 565 is uninteresting."); |
600 } | 597 } |
601 | 598 |
602 // Scale the image if it is desired. | 599 // Scale the image if it is desired. |
603 SkISize size = codec->getSampledDimensions(fSampleSize); | 600 SkISize size = codec->getSampledDimensions(fSampleSize); |
604 | 601 |
605 // Visually inspecting very small output images is not necessary. We will | 602 // Visually inspecting very small output images is not necessary. We will |
606 // cover these cases in unit testing. | 603 // cover these cases in unit testing. |
607 if ((size.width() <= 10 || size.height() <= 10) && 1 != fSampleSize) { | 604 if ((size.width() <= 10 || size.height() <= 10) && 1 != fSampleSize) { |
608 return Error::Nonfatal("Scaling very small images is uninteresting."); | 605 return Error::Nonfatal("Scaling very small images is uninteresting."); |
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1295 skr.visit<void>(i, drawsAsSingletonPictures); | 1292 skr.visit<void>(i, drawsAsSingletonPictures); |
1296 } | 1293 } |
1297 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); | 1294 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); |
1298 | 1295 |
1299 canvas->drawPicture(macroPic); | 1296 canvas->drawPicture(macroPic); |
1300 return check_against_reference(bitmap, src, fSink); | 1297 return check_against_reference(bitmap, src, fSink); |
1301 }); | 1298 }); |
1302 } | 1299 } |
1303 | 1300 |
1304 } // namespace DM | 1301 } // namespace DM |
OLD | NEW |