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 "SamplePipeControllers.h" | 9 #include "SamplePipeControllers.h" |
| 10 #include "SkAndroidCodec.h" | 10 #include "SkAndroidCodec.h" |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ | 233 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ |
| 234 | 234 |
| 235 CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType, float scale) | 235 CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType, float scale) |
| 236 : fPath(path) | 236 : fPath(path) |
| 237 , fMode(mode) | 237 , fMode(mode) |
| 238 , fDstColorType(dstColorType) | 238 , fDstColorType(dstColorType) |
| 239 , fScale(scale) | 239 , fScale(scale) |
| 240 {} | 240 {} |
| 241 | 241 |
| 242 bool CodecSrc::veto(SinkFlags flags) const { | 242 bool CodecSrc::veto(SinkFlags flags) const { |
| 243 if (kYUV_Mode == fMode) { | |
| 244 // YUV mode does not support scaling or non-canvas color types. | |
| 245 if (CodecSrc::kGetFromCanvas_DstColorType != fDstColorType || 1.0f != fS cale) { | |
|
scroggo
2016/01/13 21:04:54
For the DstColorType, can we just limit creating C
msarett
2016/01/15 18:57:34
Done.
| |
| 246 return true; | |
| 247 } | |
| 248 | |
| 249 return flags.type != SinkFlags::kGPU; | |
| 250 } | |
| 251 | |
| 243 // No need to test decoding to non-raster or indirect backend. | 252 // No need to test decoding to non-raster or indirect backend. |
| 244 // TODO: Once we implement GPU paths (e.g. JPEG YUV), we should use a deferr ed decode to | |
| 245 // let the GPU handle it. | |
| 246 return flags.type != SinkFlags::kRaster | 253 return flags.type != SinkFlags::kRaster |
| 247 || flags.approach != SinkFlags::kDirect; | 254 || flags.approach != SinkFlags::kDirect; |
| 248 } | 255 } |
| 249 | 256 |
| 250 bool get_decode_info(SkImageInfo* decodeInfo, const SkImageInfo& defaultInfo, | 257 bool get_decode_info(SkImageInfo* decodeInfo, const SkImageInfo& defaultInfo, |
| 251 SkColorType canvasColorType, CodecSrc::DstColorType dstColorType) { | 258 SkColorType canvasColorType, CodecSrc::DstColorType dstColorType) { |
| 252 switch (dstColorType) { | 259 switch (dstColorType) { |
| 253 case CodecSrc::kIndex8_Always_DstColorType: | 260 case CodecSrc::kIndex8_Always_DstColorType: |
| 254 if (kRGB_565_SkColorType == canvasColorType) { | 261 if (kRGB_565_SkColorType == canvasColorType) { |
| 255 return false; | 262 return false; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 267 break; | 274 break; |
| 268 } | 275 } |
| 269 | 276 |
| 270 // FIXME: Currently we cannot draw unpremultiplied sources. | 277 // FIXME: Currently we cannot draw unpremultiplied sources. |
| 271 if (decodeInfo->alphaType() == kUnpremul_SkAlphaType) { | 278 if (decodeInfo->alphaType() == kUnpremul_SkAlphaType) { |
| 272 *decodeInfo = decodeInfo->makeAlphaType(kPremul_SkAlphaType); | 279 *decodeInfo = decodeInfo->makeAlphaType(kPremul_SkAlphaType); |
| 273 } | 280 } |
| 274 return true; | 281 return true; |
| 275 } | 282 } |
| 276 | 283 |
| 284 Error test_yuv(SkCanvas* canvas, SkCodec* codec) { | |
| 285 SkAutoTDelete<SkCodec> deleter(codec); | |
| 286 | |
| 287 SkCodec::YUVPlanesSizes sizes; | |
| 288 SkCodec::YUVPlanesWidthBytes widthBytes; | |
| 289 SkYUVColorSpace colorSpace; | |
| 290 if (!codec->queryYUV8(&sizes, &widthBytes, &colorSpace)) { | |
| 291 return Error::Nonfatal("YUV not supported."); | |
| 292 } | |
| 293 | |
| 294 const size_t totalBytes = sizes.YSize.height() * widthBytes.YWidthBytes + | |
| 295 sizes.USize.height() * widthBytes.UWidthBytes + | |
| 296 sizes.VSize.height() * widthBytes.VWidthBytes; | |
| 297 SkAutoMalloc storage(totalBytes); | |
| 298 void* planes[3]; | |
| 299 planes[0] = storage.get(); | |
| 300 planes[1] = SkTAddOffset<void>(planes[0], sizes.YSize.height() * widthBytes. YWidthBytes); | |
| 301 planes[2] = SkTAddOffset<void>(planes[1], sizes.USize.height() * widthBytes. UWidthBytes); | |
| 302 | |
| 303 switch (codec->getYUV8Planes(&sizes, planes, &widthBytes)) { | |
| 304 case SkCodec::kSuccess: | |
| 305 case SkCodec::kIncompleteInput: { | |
| 306 /* How do we draw this to canvas? */ | |
| 307 return ""; | |
| 308 } | |
| 309 default: | |
| 310 return SkStringPrintf("Couldn't getYUV8Planes."); | |
| 311 } | |
| 312 } | |
| 313 | |
| 277 Error CodecSrc::draw(SkCanvas* canvas) const { | 314 Error CodecSrc::draw(SkCanvas* canvas) const { |
| 278 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 315 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
| 279 if (!encoded) { | 316 if (!encoded) { |
| 280 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); | 317 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
| 281 } | 318 } |
| 282 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | 319 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
| 283 if (nullptr == codec.get()) { | 320 if (nullptr == codec.get()) { |
| 284 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str()); | 321 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str()); |
| 285 } | 322 } |
| 286 | 323 |
| 324 // The YUV test does not share much code with the other tests, so we will ha ndle | |
| 325 // it in its own function. | |
| 326 if (kYUV_Mode == fMode) { | |
| 327 return test_yuv(canvas, codec.detach()); | |
|
scroggo
2016/01/13 21:04:54
Alternatively, you could let this method delete th
msarett
2016/01/15 18:57:35
Done.
| |
| 328 } | |
| 329 | |
| 287 SkImageInfo decodeInfo; | 330 SkImageInfo decodeInfo; |
| 288 if (!get_decode_info(&decodeInfo, codec->getInfo(), canvas->imageInfo().colo rType(), | 331 if (!get_decode_info(&decodeInfo, codec->getInfo(), canvas->imageInfo().colo rType(), |
| 289 fDstColorType)) { | 332 fDstColorType)) { |
| 290 return Error::Nonfatal("Testing non-565 to 565 is uninteresting."); | 333 return Error::Nonfatal("Testing non-565 to 565 is uninteresting."); |
| 291 } | 334 } |
| 292 | 335 |
| 293 // Try to scale the image if it is desired | 336 // Try to scale the image if it is desired |
| 294 SkISize size = codec->getScaledDimensions(fScale); | 337 SkISize size = codec->getScaledDimensions(fScale); |
| 295 if (size == decodeInfo.dimensions() && 1.0f != fScale) { | 338 if (size == decodeInfo.dimensions() && 1.0f != fScale) { |
| 296 return Error::Nonfatal("Test without scaling is uninteresting."); | 339 return Error::Nonfatal("Test without scaling is uninteresting."); |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 494 } | 537 } |
| 495 canvas->drawBitmap(subsetBm, SkIntToScalar(left), SkIntToSca lar(top)); | 538 canvas->drawBitmap(subsetBm, SkIntToScalar(left), SkIntToSca lar(top)); |
| 496 // translate by the scaled height. | 539 // translate by the scaled height. |
| 497 top += decodeInfo.height(); | 540 top += decodeInfo.height(); |
| 498 } | 541 } |
| 499 // translate by the scaled width. | 542 // translate by the scaled width. |
| 500 left += decodeInfo.width(); | 543 left += decodeInfo.width(); |
| 501 } | 544 } |
| 502 return ""; | 545 return ""; |
| 503 } | 546 } |
| 547 default: | |
| 548 SkASSERT(false); | |
| 549 return "Invalid fMode"; | |
| 504 } | 550 } |
| 505 return ""; | 551 return ""; |
| 506 } | 552 } |
| 507 | 553 |
| 508 SkISize CodecSrc::size() const { | 554 SkISize CodecSrc::size() const { |
| 509 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 555 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
| 510 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | 556 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
| 511 if (nullptr == codec) { | 557 if (nullptr == codec) { |
| 512 return SkISize::Make(0, 0); | 558 return SkISize::Make(0, 0); |
| 513 } | 559 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 526 AndroidCodecSrc::AndroidCodecSrc(Path path, Mode mode, CodecSrc::DstColorType ds tColorType, | 572 AndroidCodecSrc::AndroidCodecSrc(Path path, Mode mode, CodecSrc::DstColorType ds tColorType, |
| 527 int sampleSize) | 573 int sampleSize) |
| 528 : fPath(path) | 574 : fPath(path) |
| 529 , fMode(mode) | 575 , fMode(mode) |
| 530 , fDstColorType(dstColorType) | 576 , fDstColorType(dstColorType) |
| 531 , fSampleSize(sampleSize) | 577 , fSampleSize(sampleSize) |
| 532 {} | 578 {} |
| 533 | 579 |
| 534 bool AndroidCodecSrc::veto(SinkFlags flags) const { | 580 bool AndroidCodecSrc::veto(SinkFlags flags) const { |
| 535 // No need to test decoding to non-raster or indirect backend. | 581 // No need to test decoding to non-raster or indirect backend. |
| 536 // TODO: Once we implement GPU paths (e.g. JPEG YUV), we should use a deferr ed decode to | |
| 537 // let the GPU handle it. | |
| 538 return flags.type != SinkFlags::kRaster | 582 return flags.type != SinkFlags::kRaster |
| 539 || flags.approach != SinkFlags::kDirect; | 583 || flags.approach != SinkFlags::kDirect; |
| 540 } | 584 } |
| 541 | 585 |
| 542 Error AndroidCodecSrc::draw(SkCanvas* canvas) const { | 586 Error AndroidCodecSrc::draw(SkCanvas* canvas) const { |
| 543 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 587 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
| 544 if (!encoded) { | 588 if (!encoded) { |
| 545 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); | 589 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
| 546 } | 590 } |
| 547 SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(encoded)); | 591 SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(encoded)); |
| (...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1264 skr.visit<void>(i, drawsAsSingletonPictures); | 1308 skr.visit<void>(i, drawsAsSingletonPictures); |
| 1265 } | 1309 } |
| 1266 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); | 1310 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); |
| 1267 | 1311 |
| 1268 canvas->drawPicture(macroPic); | 1312 canvas->drawPicture(macroPic); |
| 1269 return ""; | 1313 return ""; |
| 1270 }); | 1314 }); |
| 1271 } | 1315 } |
| 1272 | 1316 |
| 1273 } // namespace DM | 1317 } // namespace DM |
| OLD | NEW |