| 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 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 default: | 427 default: |
| 428 // Everything else is considered a failure. | 428 // Everything else is considered a failure. |
| 429 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str(
)); | 429 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str(
)); |
| 430 } | 430 } |
| 431 premultiply_if_necessary(bitmap); | 431 premultiply_if_necessary(bitmap); |
| 432 swap_rb_if_necessary(bitmap, fDstColorType); | 432 swap_rb_if_necessary(bitmap, fDstColorType); |
| 433 canvas->drawBitmap(bitmap, 0, 0); | 433 canvas->drawBitmap(bitmap, 0, 0); |
| 434 break; | 434 break; |
| 435 } | 435 } |
| 436 case kScanline_Mode: { | 436 case kScanline_Mode: { |
| 437 if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo, NULL
, colorPtr, | 437 const bool supportsNewScanlineDecoding = fPath.endsWith("png"); |
| 438 colorCountPtr))
{ | 438 if (supportsNewScanlineDecoding) { |
| 439 return "Could not start scanline decoder"; | 439 if (SkCodec::kSuccess != codec->startIncrementalDecode(decodeInf
o, |
| 440 } | 440 nullptr, colorPtr, colorCountPtr)) { |
| 441 return "Could not start incremental decode"; |
| 442 } |
| 443 int rowsDecoded; |
| 444 if (SkCodec::kIncompleteInput == codec->incrementalDecode( |
| 445 [&bitmap](int rowNum) -> void* { |
| 446 return bitmap.getAddr(0, rowNum); |
| 447 }, &rowsDecoded)) { |
| 448 codec->fillIncompleteImage(decodeInfo, bitmap.getPixels(), b
itmap.rowBytes(), |
| 449 SkCodec::kNo_ZeroInitialized, dec
odeInfo.height(), |
| 450 rowsDecoded); |
| 451 } |
| 441 | 452 |
| 442 void* dst = bitmap.getAddr(0, 0); | 453 } else { |
| 443 size_t rowBytes = bitmap.rowBytes(); | 454 if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo,
NULL, colorPtr, |
| 444 uint32_t height = decodeInfo.height(); | 455 colorCountPt
r)) { |
| 445 switch (codec->getScanlineOrder()) { | 456 return "Could not start scanline decoder"; |
| 446 case SkCodec::kTopDown_SkScanlineOrder: | 457 } |
| 447 case SkCodec::kBottomUp_SkScanlineOrder: | 458 |
| 448 case SkCodec::kNone_SkScanlineOrder: | 459 void* dst = bitmap.getAddr(0, 0); |
| 449 // We do not need to check the return value. On an incomple
te | 460 size_t rowBytes = bitmap.rowBytes(); |
| 450 // image, memory will be filled with a default value. | 461 uint32_t height = decodeInfo.height(); |
| 451 codec->getScanlines(dst, height, rowBytes); | 462 switch (codec->getScanlineOrder()) { |
| 452 break; | 463 case SkCodec::kTopDown_SkScanlineOrder: |
| 453 case SkCodec::kOutOfOrder_SkScanlineOrder: { | 464 case SkCodec::kBottomUp_SkScanlineOrder: |
| 454 for (int y = 0; y < decodeInfo.height(); y++) { | 465 // We do not need to check the return value. On an inco
mplete |
| 455 int dstY = codec->outputScanline(y); | 466 // image, memory will be filled with a default value. |
| 456 void* dstPtr = bitmap.getAddr(0, dstY); | 467 codec->getScanlines(dst, height, rowBytes); |
| 457 // We complete the loop, even if this call begins to fai
l | 468 break; |
| 458 // due to an incomplete image. This ensures any uniniti
alized | 469 case SkCodec::kOutOfOrder_SkScanlineOrder: { |
| 459 // memory will be filled with the proper value. | 470 for (int y = 0; y < decodeInfo.height(); y++) { |
| 460 codec->getScanlines(dstPtr, 1, bitmap.rowBytes()); | 471 int dstY = codec->outputScanline(y); |
| 472 void* dstPtr = bitmap.getAddr(0, dstY); |
| 473 // We complete the loop, even if this call begins to
fail |
| 474 // due to an incomplete image. This ensures any uni
nitialized |
| 475 // memory will be filled with the proper value. |
| 476 codec->getScanlines(dstPtr, 1, bitmap.rowBytes()); |
| 477 } |
| 478 break; |
| 461 } | 479 } |
| 462 break; | |
| 463 } | 480 } |
| 464 } | 481 } |
| 465 | 482 |
| 466 premultiply_if_necessary(bitmap); | 483 premultiply_if_necessary(bitmap); |
| 467 swap_rb_if_necessary(bitmap, fDstColorType); | 484 swap_rb_if_necessary(bitmap, fDstColorType); |
| 468 canvas->drawBitmap(bitmap, 0, 0); | 485 canvas->drawBitmap(bitmap, 0, 0); |
| 469 break; | 486 break; |
| 470 } | 487 } |
| 471 case kStripe_Mode: { | 488 case kStripe_Mode: { |
| 472 const int height = decodeInfo.height(); | 489 const int height = decodeInfo.height(); |
| (...skipping 1026 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1499 skr.visit(i, drawsAsSingletonPictures); | 1516 skr.visit(i, drawsAsSingletonPictures); |
| 1500 } | 1517 } |
| 1501 sk_sp<SkPicture> macroPic(macroRec.finishRecordingAsPicture()); | 1518 sk_sp<SkPicture> macroPic(macroRec.finishRecordingAsPicture()); |
| 1502 | 1519 |
| 1503 canvas->drawPicture(macroPic); | 1520 canvas->drawPicture(macroPic); |
| 1504 return check_against_reference(bitmap, src, fSink); | 1521 return check_against_reference(bitmap, src, fSink); |
| 1505 }); | 1522 }); |
| 1506 } | 1523 } |
| 1507 | 1524 |
| 1508 } // namespace DM | 1525 } // namespace DM |
| OLD | NEW |