| 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 "Resources.h" | 9 #include "Resources.h" |
| 10 #include "SkAndroidCodec.h" | 10 #include "SkAndroidCodec.h" |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 } | 423 } |
| 424 | 424 |
| 425 SkImageInfo bitmapInfo = decodeInfo; | 425 SkImageInfo bitmapInfo = decodeInfo; |
| 426 if (kRGBA_8888_SkColorType == decodeInfo.colorType() || | 426 if (kRGBA_8888_SkColorType == decodeInfo.colorType() || |
| 427 kBGRA_8888_SkColorType == decodeInfo.colorType()) { | 427 kBGRA_8888_SkColorType == decodeInfo.colorType()) { |
| 428 bitmapInfo = bitmapInfo.makeColorType(kN32_SkColorType); | 428 bitmapInfo = bitmapInfo.makeColorType(kN32_SkColorType); |
| 429 } | 429 } |
| 430 | 430 |
| 431 switch (fMode) { | 431 switch (fMode) { |
| 432 case kAnimated_Mode: { | 432 case kAnimated_Mode: { |
| 433 std::vector<SkCodec::FrameInfo> frameInfos = codec->getFrameInfo(); | 433 std::vector<SkCodec::FrameInfo> frameInfos; |
| 434 if (frameInfos.size() <= 1) { | 434 const bool animated = codec->getFrameInfo(&frameInfos, nullptr); |
| 435 if (!animated || frameInfos.size() <= 1) { |
| 435 return SkStringPrintf("%s is not an animated image.", fPath.c_st
r()); | 436 return SkStringPrintf("%s is not an animated image.", fPath.c_st
r()); |
| 436 } | 437 } |
| 437 | 438 |
| 438 // As in CodecSrc::size(), compute a roughly square grid to draw the
frames | 439 // As in CodecSrc::size(), compute a roughly square grid to draw the
frames |
| 439 // into. "factor" is the number of frames to draw on one row. There
will be | 440 // into. "factor" is the number of frames to draw on one row. There
will be |
| 440 // up to "factor" rows as well. | 441 // up to "factor" rows as well. |
| 441 const float root = sqrt((float) frameInfos.size()); | 442 const float root = sqrt((float) frameInfos.size()); |
| 442 const int factor = sk_float_ceil2int(root); | 443 const int factor = sk_float_ceil2int(root); |
| 443 | 444 |
| 444 // Used to cache a frame that future frames will depend on. | 445 // Used to cache a frame that future frames will depend on. |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | 719 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
| 719 if (nullptr == codec) { | 720 if (nullptr == codec) { |
| 720 return SkISize::Make(0, 0); | 721 return SkISize::Make(0, 0); |
| 721 } | 722 } |
| 722 | 723 |
| 723 auto imageSize = codec->getScaledDimensions(fScale); | 724 auto imageSize = codec->getScaledDimensions(fScale); |
| 724 if (fMode == kAnimated_Mode) { | 725 if (fMode == kAnimated_Mode) { |
| 725 // We'll draw one of each frame, so make it big enough to hold them all | 726 // We'll draw one of each frame, so make it big enough to hold them all |
| 726 // in a grid. The grid will be roughly square, with "factor" frames per | 727 // in a grid. The grid will be roughly square, with "factor" frames per |
| 727 // row and up to "factor" rows. | 728 // row and up to "factor" rows. |
| 728 const size_t count = codec->getFrameInfo().size(); | 729 std::vector<SkCodec::FrameInfo> frameInfos; |
| 730 if (!codec->getFrameInfo(&frameInfos, nullptr)) { |
| 731 return imageSize; |
| 732 } |
| 733 const size_t count = frameInfos.size(); |
| 729 const float root = sqrt((float) count); | 734 const float root = sqrt((float) count); |
| 730 const int factor = sk_float_ceil2int(root); | 735 const int factor = sk_float_ceil2int(root); |
| 731 imageSize.fWidth = imageSize.fWidth * factor; | 736 imageSize.fWidth = imageSize.fWidth * factor; |
| 732 imageSize.fHeight = imageSize.fHeight * sk_float_ceil2int((float) count
/ (float) factor); | 737 imageSize.fHeight = imageSize.fHeight * sk_float_ceil2int((float) count
/ (float) factor); |
| 733 } | 738 } |
| 734 return imageSize; | 739 return imageSize; |
| 735 } | 740 } |
| 736 | 741 |
| 737 Name CodecSrc::name() const { | 742 Name CodecSrc::name() const { |
| 738 if (1.0f == fScale) { | 743 if (1.0f == fScale) { |
| (...skipping 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1803 Error err = src.draw(&rec); | 1808 Error err = src.draw(&rec); |
| 1804 if (!err.isEmpty()) { | 1809 if (!err.isEmpty()) { |
| 1805 return err; | 1810 return err; |
| 1806 } | 1811 } |
| 1807 dl->draw(canvas); | 1812 dl->draw(canvas); |
| 1808 return check_against_reference(bitmap, src, fSink); | 1813 return check_against_reference(bitmap, src, fSink); |
| 1809 }); | 1814 }); |
| 1810 } | 1815 } |
| 1811 | 1816 |
| 1812 } // namespace DM | 1817 } // namespace DM |
| OLD | NEW |