Chromium Code Reviews| 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" |
| 11 #include "SkCodecImageGenerator.h" | |
| 11 #include "SkCommonFlags.h" | 12 #include "SkCommonFlags.h" |
| 12 #include "SkData.h" | 13 #include "SkData.h" |
| 13 #include "SkDocument.h" | 14 #include "SkDocument.h" |
| 14 #include "SkError.h" | 15 #include "SkError.h" |
| 15 #include "SkImageGenerator.h" | 16 #include "SkImageGenerator.h" |
| 16 #include "SkMallocPixelRef.h" | 17 #include "SkMallocPixelRef.h" |
| 17 #include "SkMultiPictureDraw.h" | 18 #include "SkMultiPictureDraw.h" |
| 18 #include "SkNullCanvas.h" | 19 #include "SkNullCanvas.h" |
| 19 #include "SkOSFile.h" | 20 #include "SkOSFile.h" |
| 20 #include "SkPictureData.h" | 21 #include "SkPictureData.h" |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ | 234 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ |
| 234 | 235 |
| 235 CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType, float scale) | 236 CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType, float scale) |
| 236 : fPath(path) | 237 : fPath(path) |
| 237 , fMode(mode) | 238 , fMode(mode) |
| 238 , fDstColorType(dstColorType) | 239 , fDstColorType(dstColorType) |
| 239 , fScale(scale) | 240 , fScale(scale) |
| 240 {} | 241 {} |
| 241 | 242 |
| 242 bool CodecSrc::veto(SinkFlags flags) const { | 243 bool CodecSrc::veto(SinkFlags flags) const { |
| 243 // No need to test decoding to non-raster or indirect backend. | 244 // Test to direct raster backend. Also enable CodecImageGenerator tests on gpu. |
|
scroggo
2016/01/19 18:37:48
Does this mean to test CodecImageGenerator on the
msarett
2016/01/19 22:35:27
I decided it would be interesting to test to 8888,
| |
| 244 // TODO: Once we implement GPU paths (e.g. JPEG YUV), we should use a deferr ed decode to | 245 return (flags.type != SinkFlags::kRaster || flags.approach != SinkFlags::kDi rect) && |
|
scroggo
2016/01/19 18:37:48
Nit: I think it would be easier to follow this wit
msarett
2016/01/19 22:35:27
Done.
As side comment, I find the concept of a ve
scroggo
2016/01/21 17:27:28
Haha, agreed. It confuses me every time I look at
| |
| 245 // let the GPU handle it. | 246 (kGen_Mode != fMode || flags.type != SinkFlags::kGPU); |
| 246 return flags.type != SinkFlags::kRaster | |
| 247 || flags.approach != SinkFlags::kDirect; | |
| 248 } | 247 } |
| 249 | 248 |
| 250 bool get_decode_info(SkImageInfo* decodeInfo, const SkImageInfo& defaultInfo, | 249 bool get_decode_info(SkImageInfo* decodeInfo, const SkImageInfo& defaultInfo, |
| 251 SkColorType canvasColorType, CodecSrc::DstColorType dstColorType) { | 250 SkColorType canvasColorType, CodecSrc::DstColorType dstColorType) { |
| 252 switch (dstColorType) { | 251 switch (dstColorType) { |
| 253 case CodecSrc::kIndex8_Always_DstColorType: | 252 case CodecSrc::kIndex8_Always_DstColorType: |
| 254 if (kRGB_565_SkColorType == canvasColorType) { | 253 if (kRGB_565_SkColorType == canvasColorType) { |
| 255 return false; | 254 return false; |
| 256 } | 255 } |
| 257 *decodeInfo = defaultInfo.makeColorType(kIndex_8_SkColorType); | 256 *decodeInfo = defaultInfo.makeColorType(kIndex_8_SkColorType); |
| 258 break; | 257 break; |
| 259 case CodecSrc::kGrayscale_Always_DstColorType: | 258 case CodecSrc::kGrayscale_Always_DstColorType: |
| 260 if (kRGB_565_SkColorType == canvasColorType) { | 259 if (kRGB_565_SkColorType == canvasColorType) { |
| 261 return false; | 260 return false; |
| 262 } | 261 } |
| 263 *decodeInfo = defaultInfo.makeColorType(kGray_8_SkColorType); | 262 *decodeInfo = defaultInfo.makeColorType(kGray_8_SkColorType); |
| 264 break; | 263 break; |
| 265 default: | 264 default: |
| 266 *decodeInfo = defaultInfo.makeColorType(canvasColorType); | 265 *decodeInfo = defaultInfo.makeColorType(canvasColorType); |
| 267 break; | 266 break; |
| 268 } | 267 } |
| 269 | 268 |
| 270 // FIXME: Currently we cannot draw unpremultiplied sources. | 269 // FIXME: Currently we cannot draw unpremultiplied sources. |
| 271 if (decodeInfo->alphaType() == kUnpremul_SkAlphaType) { | 270 if (decodeInfo->alphaType() == kUnpremul_SkAlphaType) { |
| 272 *decodeInfo = decodeInfo->makeAlphaType(kPremul_SkAlphaType); | 271 *decodeInfo = decodeInfo->makeAlphaType(kPremul_SkAlphaType); |
| 273 } | 272 } |
| 274 return true; | 273 return true; |
| 275 } | 274 } |
| 276 | 275 |
| 276 Error test_gen(SkCanvas* canvas, SkData* data) { | |
| 277 SkImageGenerator* gen = SkCodecImageGenerator::NewFromEncodedCodec(data); | |
| 278 if (!gen) { | |
| 279 return "Could not create image generator."; | |
| 280 } | |
| 281 | |
| 282 // FIXME: The gpu backend does not draw kGray sources correctly. | |
|
scroggo
2016/01/19 18:37:48
Is there a bug filed for this?
msarett
2016/01/19 22:35:27
I'll file one and reference it here.
| |
| 283 if (kGray_8_SkColorType == gen->getInfo().colorType()) { | |
|
scroggo
2016/01/19 18:37:48
Alternatively, we could skip before we ever get he
msarett
2016/01/19 22:35:27
Done.
| |
| 284 return Error::Nonfatal("Disabling kGray decodes with CodecImageGenerator ."); | |
| 285 } | |
| 286 | |
| 287 SkBitmap bitmap; | |
| 288 if (!SkDEPRECATED_InstallDiscardablePixelRef(gen, &bitmap)) { | |
|
scroggo
2016/01/19 18:37:48
I see this is deprecated. Why not call SkImage::Ne
msarett
2016/01/19 22:35:27
Ah yes of course.
| |
| 289 return "Could not install codec image generator."; | |
| 290 } | |
| 291 | |
| 292 canvas->drawBitmap(bitmap, 0, 0); | |
| 293 return ""; | |
| 294 } | |
| 295 | |
| 277 Error CodecSrc::draw(SkCanvas* canvas) const { | 296 Error CodecSrc::draw(SkCanvas* canvas) const { |
| 278 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 297 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
| 279 if (!encoded) { | 298 if (!encoded) { |
| 280 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); | 299 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
| 281 } | 300 } |
| 301 | |
| 302 // The CodecImageGenerator test does not share much code with the other test s, | |
| 303 // so we will handle it in its own function. | |
| 304 if (kGen_Mode == fMode) { | |
| 305 return test_gen(canvas, encoded); | |
| 306 } | |
| 307 | |
| 282 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | 308 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
| 283 if (nullptr == codec.get()) { | 309 if (nullptr == codec.get()) { |
| 284 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str()); | 310 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str()); |
| 285 } | 311 } |
| 286 | 312 |
| 287 SkImageInfo decodeInfo; | 313 SkImageInfo decodeInfo; |
| 288 if (!get_decode_info(&decodeInfo, codec->getInfo(), canvas->imageInfo().colo rType(), | 314 if (!get_decode_info(&decodeInfo, codec->getInfo(), canvas->imageInfo().colo rType(), |
| 289 fDstColorType)) { | 315 fDstColorType)) { |
| 290 return Error::Nonfatal("Testing non-565 to 565 is uninteresting."); | 316 return Error::Nonfatal("Testing non-565 to 565 is uninteresting."); |
| 291 } | 317 } |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 502 } | 528 } |
| 503 canvas->drawBitmap(subsetBm, SkIntToScalar(left), SkIntToSca lar(top)); | 529 canvas->drawBitmap(subsetBm, SkIntToScalar(left), SkIntToSca lar(top)); |
| 504 // translate by the scaled height. | 530 // translate by the scaled height. |
| 505 top += decodeInfo.height(); | 531 top += decodeInfo.height(); |
| 506 } | 532 } |
| 507 // translate by the scaled width. | 533 // translate by the scaled width. |
| 508 left += decodeInfo.width(); | 534 left += decodeInfo.width(); |
| 509 } | 535 } |
| 510 return ""; | 536 return ""; |
| 511 } | 537 } |
| 538 default: | |
| 539 SkASSERT(false); | |
| 540 return "Invalid fMode"; | |
| 512 } | 541 } |
| 513 return ""; | 542 return ""; |
| 514 } | 543 } |
| 515 | 544 |
| 516 SkISize CodecSrc::size() const { | 545 SkISize CodecSrc::size() const { |
| 517 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 546 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
| 518 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | 547 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
| 519 if (nullptr == codec) { | 548 if (nullptr == codec) { |
| 520 return SkISize::Make(0, 0); | 549 return SkISize::Make(0, 0); |
| 521 } | 550 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 534 AndroidCodecSrc::AndroidCodecSrc(Path path, Mode mode, CodecSrc::DstColorType ds tColorType, | 563 AndroidCodecSrc::AndroidCodecSrc(Path path, Mode mode, CodecSrc::DstColorType ds tColorType, |
| 535 int sampleSize) | 564 int sampleSize) |
| 536 : fPath(path) | 565 : fPath(path) |
| 537 , fMode(mode) | 566 , fMode(mode) |
| 538 , fDstColorType(dstColorType) | 567 , fDstColorType(dstColorType) |
| 539 , fSampleSize(sampleSize) | 568 , fSampleSize(sampleSize) |
| 540 {} | 569 {} |
| 541 | 570 |
| 542 bool AndroidCodecSrc::veto(SinkFlags flags) const { | 571 bool AndroidCodecSrc::veto(SinkFlags flags) const { |
| 543 // No need to test decoding to non-raster or indirect backend. | 572 // No need to test decoding to non-raster or indirect backend. |
| 544 // TODO: Once we implement GPU paths (e.g. JPEG YUV), we should use a deferr ed decode to | |
|
scroggo
2016/01/19 18:37:48
I assume the TODO has changed here? Or maybe it's
msarett
2016/01/19 22:35:27
Yes YUV does not support sampling or native scalin
| |
| 545 // let the GPU handle it. | |
| 546 return flags.type != SinkFlags::kRaster | 573 return flags.type != SinkFlags::kRaster |
| 547 || flags.approach != SinkFlags::kDirect; | 574 || flags.approach != SinkFlags::kDirect; |
| 548 } | 575 } |
| 549 | 576 |
| 550 Error AndroidCodecSrc::draw(SkCanvas* canvas) const { | 577 Error AndroidCodecSrc::draw(SkCanvas* canvas) const { |
| 551 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 578 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
| 552 if (!encoded) { | 579 if (!encoded) { |
| 553 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); | 580 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
| 554 } | 581 } |
| 555 SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(encoded)); | 582 SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(encoded)); |
| (...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1309 skr.visit<void>(i, drawsAsSingletonPictures); | 1336 skr.visit<void>(i, drawsAsSingletonPictures); |
| 1310 } | 1337 } |
| 1311 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); | 1338 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); |
| 1312 | 1339 |
| 1313 canvas->drawPicture(macroPic); | 1340 canvas->drawPicture(macroPic); |
| 1314 return check_against_reference(bitmap, src, fSink); | 1341 return check_against_reference(bitmap, src, fSink); |
| 1315 }); | 1342 }); |
| 1316 } | 1343 } |
| 1317 | 1344 |
| 1318 } // namespace DM | 1345 } // namespace DM |
| OLD | NEW |