| 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 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 // We will replicate the names used by CodecSrc so that images can | 726 // We will replicate the names used by CodecSrc so that images can |
| 727 // be compared in Gold. | 727 // be compared in Gold. |
| 728 if (1 == fSampleSize) { | 728 if (1 == fSampleSize) { |
| 729 return SkOSPath::Basename(fPath.c_str()); | 729 return SkOSPath::Basename(fPath.c_str()); |
| 730 } | 730 } |
| 731 return get_scaled_name(fPath, 1.0f / (float) fSampleSize); | 731 return get_scaled_name(fPath, 1.0f / (float) fSampleSize); |
| 732 } | 732 } |
| 733 | 733 |
| 734 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ | 734 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
| 735 | 735 |
| 736 ImageSrc::ImageSrc(Path path) : fPath(path) {} | |
| 737 | |
| 738 bool ImageSrc::veto(SinkFlags flags) const { | |
| 739 // No need to test decoding to non-raster or indirect backend. | |
| 740 // TODO: Instead, use lazy decoding to allow the GPU to handle cases like YU
V. | |
| 741 return flags.type != SinkFlags::kRaster | |
| 742 || flags.approach != SinkFlags::kDirect; | |
| 743 } | |
| 744 | |
| 745 Error ImageSrc::draw(SkCanvas* canvas) const { | |
| 746 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | |
| 747 if (!encoded) { | |
| 748 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); | |
| 749 } | |
| 750 const SkColorType dstColorType = canvas->imageInfo().colorType(); | |
| 751 | |
| 752 // Decode the full image. | |
| 753 SkBitmap bitmap; | |
| 754 if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(), &bitmap, | |
| 755 dstColorType, SkImageDecoder::kDecodePixel
s_Mode)) { | |
| 756 return SkStringPrintf("Couldn't decode %s.", fPath.c_str()); | |
| 757 } | |
| 758 if (kRGB_565_SkColorType == dstColorType && !bitmap.isOpaque()) { | |
| 759 // Do not draw a bitmap with alpha to a destination without alpha. | |
| 760 return Error::Nonfatal("Uninteresting to decode image with alpha into 56
5."); | |
| 761 } | |
| 762 encoded.reset((SkData*)nullptr); // Might as well drop this when we're done
with it. | |
| 763 canvas->drawBitmap(bitmap, 0,0); | |
| 764 return ""; | |
| 765 } | |
| 766 | |
| 767 SkISize ImageSrc::size() const { | |
| 768 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | |
| 769 SkBitmap bitmap; | |
| 770 if (!encoded || !SkImageDecoder::DecodeMemory(encoded->data(), | |
| 771 encoded->size(), | |
| 772 &bitmap, | |
| 773 kUnknown_SkColorType, | |
| 774 SkImageDecoder::kDecodeBounds_
Mode)) { | |
| 775 return SkISize::Make(0,0); | |
| 776 } | |
| 777 return bitmap.dimensions(); | |
| 778 } | |
| 779 | |
| 780 Name ImageSrc::name() const { | |
| 781 return SkOSPath::Basename(fPath.c_str()); | |
| 782 } | |
| 783 | |
| 784 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ | |
| 785 | |
| 786 static const SkRect kSKPViewport = {0,0, 1000,1000}; | 736 static const SkRect kSKPViewport = {0,0, 1000,1000}; |
| 787 | 737 |
| 788 SKPSrc::SKPSrc(Path path) : fPath(path) {} | 738 SKPSrc::SKPSrc(Path path) : fPath(path) {} |
| 789 | 739 |
| 790 Error SKPSrc::draw(SkCanvas* canvas) const { | 740 Error SKPSrc::draw(SkCanvas* canvas) const { |
| 791 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str())); | 741 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str())); |
| 792 if (!stream) { | 742 if (!stream) { |
| 793 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); | 743 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
| 794 } | 744 } |
| 795 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream, &lazy_decode
_bitmap)); | 745 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream, &lazy_decode
_bitmap)); |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1345 skr.visit<void>(i, drawsAsSingletonPictures); | 1295 skr.visit<void>(i, drawsAsSingletonPictures); |
| 1346 } | 1296 } |
| 1347 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); | 1297 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); |
| 1348 | 1298 |
| 1349 canvas->drawPicture(macroPic); | 1299 canvas->drawPicture(macroPic); |
| 1350 return check_against_reference(bitmap, src, fSink); | 1300 return check_against_reference(bitmap, src, fSink); |
| 1351 }); | 1301 }); |
| 1352 } | 1302 } |
| 1353 | 1303 |
| 1354 } // namespace DM | 1304 } // namespace DM |
| OLD | NEW |