| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 , fSampleSize(sampleSize) | 90 , fSampleSize(sampleSize) |
| 91 {} | 91 {} |
| 92 | 92 |
| 93 bool BRDSrc::veto(SinkFlags flags) const { | 93 bool BRDSrc::veto(SinkFlags flags) const { |
| 94 // No need to test to non-raster or indirect backends. | 94 // No need to test to non-raster or indirect backends. |
| 95 return flags.type != SinkFlags::kRaster | 95 return flags.type != SinkFlags::kRaster |
| 96 || flags.approach != SinkFlags::kDirect; | 96 || flags.approach != SinkFlags::kDirect; |
| 97 } | 97 } |
| 98 | 98 |
| 99 static SkBitmapRegionDecoder* create_brd(Path path) { | 99 static SkBitmapRegionDecoder* create_brd(Path path) { |
| 100 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); | 100 sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str())); |
| 101 if (!encoded) { | 101 if (!encoded) { |
| 102 return NULL; | 102 return NULL; |
| 103 } | 103 } |
| 104 return SkBitmapRegionDecoder::Create(encoded, SkBitmapRegionDecoder::kAndroi
dCodec_Strategy); | 104 return SkBitmapRegionDecoder::Create(encoded.get(), |
| 105 SkBitmapRegionDecoder::kAndroidCodec_St
rategy); |
| 105 } | 106 } |
| 106 | 107 |
| 107 Error BRDSrc::draw(SkCanvas* canvas) const { | 108 Error BRDSrc::draw(SkCanvas* canvas) const { |
| 108 SkColorType colorType = canvas->imageInfo().colorType(); | 109 SkColorType colorType = canvas->imageInfo().colorType(); |
| 109 if (kRGB_565_SkColorType == colorType && | 110 if (kRGB_565_SkColorType == colorType && |
| 110 CodecSrc::kGetFromCanvas_DstColorType != fDstColorType) { | 111 CodecSrc::kGetFromCanvas_DstColorType != fDstColorType) { |
| 111 return Error::Nonfatal("Testing non-565 to 565 is uninteresting."); | 112 return Error::Nonfatal("Testing non-565 to 565 is uninteresting."); |
| 112 } | 113 } |
| 113 switch (fDstColorType) { | 114 switch (fDstColorType) { |
| 114 case CodecSrc::kGetFromCanvas_DstColorType: | 115 case CodecSrc::kGetFromCanvas_DstColorType: |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 SkScalar left = 0, SkScalar top = 0) { | 369 SkScalar left = 0, SkScalar top = 0) { |
| 369 SkAutoTUnref<SkColorTable> colorTable(new SkColorTable(colorPtr, colorCount)
); | 370 SkAutoTUnref<SkColorTable> colorTable(new SkColorTable(colorPtr, colorCount)
); |
| 370 SkBitmap bitmap; | 371 SkBitmap bitmap; |
| 371 bitmap.installPixels(info, pixels, rowBytes, colorTable.get(), nullptr, null
ptr); | 372 bitmap.installPixels(info, pixels, rowBytes, colorTable.get(), nullptr, null
ptr); |
| 372 premultiply_if_necessary(bitmap); | 373 premultiply_if_necessary(bitmap); |
| 373 swap_rb_if_necessary(bitmap, dstColorType); | 374 swap_rb_if_necessary(bitmap, dstColorType); |
| 374 canvas->drawBitmap(bitmap, left, top); | 375 canvas->drawBitmap(bitmap, left, top); |
| 375 } | 376 } |
| 376 | 377 |
| 377 Error CodecSrc::draw(SkCanvas* canvas) const { | 378 Error CodecSrc::draw(SkCanvas* canvas) const { |
| 378 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 379 sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str())); |
| 379 if (!encoded) { | 380 if (!encoded) { |
| 380 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); | 381 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
| 381 } | 382 } |
| 382 | 383 |
| 383 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | 384 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded.get())); |
| 384 if (nullptr == codec.get()) { | 385 if (nullptr == codec.get()) { |
| 385 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str()); | 386 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str()); |
| 386 } | 387 } |
| 387 | 388 |
| 388 SkImageInfo decodeInfo = codec->getInfo(); | 389 SkImageInfo decodeInfo = codec->getInfo(); |
| 389 if (!get_decode_info(&decodeInfo, canvas->imageInfo().colorType(), fDstColor
Type, | 390 if (!get_decode_info(&decodeInfo, canvas->imageInfo().colorType(), fDstColor
Type, |
| 390 fDstAlphaType)) { | 391 fDstAlphaType)) { |
| 391 return Error::Nonfatal("Testing non-565 to 565 is uninteresting."); | 392 return Error::Nonfatal("Testing non-565 to 565 is uninteresting."); |
| 392 } | 393 } |
| 393 | 394 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 return ""; | 621 return ""; |
| 621 } | 622 } |
| 622 default: | 623 default: |
| 623 SkASSERT(false); | 624 SkASSERT(false); |
| 624 return "Invalid fMode"; | 625 return "Invalid fMode"; |
| 625 } | 626 } |
| 626 return ""; | 627 return ""; |
| 627 } | 628 } |
| 628 | 629 |
| 629 SkISize CodecSrc::size() const { | 630 SkISize CodecSrc::size() const { |
| 630 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 631 sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str())); |
| 631 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | 632 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded.get())); |
| 632 if (nullptr == codec) { | 633 if (nullptr == codec) { |
| 633 return SkISize::Make(0, 0); | 634 return SkISize::Make(0, 0); |
| 634 } | 635 } |
| 635 return codec->getScaledDimensions(fScale); | 636 return codec->getScaledDimensions(fScale); |
| 636 } | 637 } |
| 637 | 638 |
| 638 Name CodecSrc::name() const { | 639 Name CodecSrc::name() const { |
| 639 if (1.0f == fScale) { | 640 if (1.0f == fScale) { |
| 640 return SkOSPath::Basename(fPath.c_str()); | 641 return SkOSPath::Basename(fPath.c_str()); |
| 641 } | 642 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 653 , fRunSerially(serial_from_path_name(path)) | 654 , fRunSerially(serial_from_path_name(path)) |
| 654 {} | 655 {} |
| 655 | 656 |
| 656 bool AndroidCodecSrc::veto(SinkFlags flags) const { | 657 bool AndroidCodecSrc::veto(SinkFlags flags) const { |
| 657 // No need to test decoding to non-raster or indirect backend. | 658 // No need to test decoding to non-raster or indirect backend. |
| 658 return flags.type != SinkFlags::kRaster | 659 return flags.type != SinkFlags::kRaster |
| 659 || flags.approach != SinkFlags::kDirect; | 660 || flags.approach != SinkFlags::kDirect; |
| 660 } | 661 } |
| 661 | 662 |
| 662 Error AndroidCodecSrc::draw(SkCanvas* canvas) const { | 663 Error AndroidCodecSrc::draw(SkCanvas* canvas) const { |
| 663 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 664 sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str())); |
| 664 if (!encoded) { | 665 if (!encoded) { |
| 665 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); | 666 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
| 666 } | 667 } |
| 667 SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(encoded)); | 668 SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(encoded.get(
))); |
| 668 if (nullptr == codec.get()) { | 669 if (nullptr == codec.get()) { |
| 669 return SkStringPrintf("Couldn't create android codec for %s.", fPath.c_s
tr()); | 670 return SkStringPrintf("Couldn't create android codec for %s.", fPath.c_s
tr()); |
| 670 } | 671 } |
| 671 | 672 |
| 672 SkImageInfo decodeInfo = codec->getInfo(); | 673 SkImageInfo decodeInfo = codec->getInfo(); |
| 673 if (!get_decode_info(&decodeInfo, canvas->imageInfo().colorType(), fDstColor
Type, | 674 if (!get_decode_info(&decodeInfo, canvas->imageInfo().colorType(), fDstColor
Type, |
| 674 fDstAlphaType)) { | 675 fDstAlphaType)) { |
| 675 return Error::Nonfatal("Testing non-565 to 565 is uninteresting."); | 676 return Error::Nonfatal("Testing non-565 to 565 is uninteresting."); |
| 676 } | 677 } |
| 677 | 678 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 case SkCodec::kIncompleteInput: | 710 case SkCodec::kIncompleteInput: |
| 710 break; | 711 break; |
| 711 default: | 712 default: |
| 712 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str()); | 713 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str()); |
| 713 } | 714 } |
| 714 draw_to_canvas(canvas, bitmapInfo, pixels.get(), rowBytes, colorPtr, colorCo
unt, fDstColorType); | 715 draw_to_canvas(canvas, bitmapInfo, pixels.get(), rowBytes, colorPtr, colorCo
unt, fDstColorType); |
| 715 return ""; | 716 return ""; |
| 716 } | 717 } |
| 717 | 718 |
| 718 SkISize AndroidCodecSrc::size() const { | 719 SkISize AndroidCodecSrc::size() const { |
| 719 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 720 sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str())); |
| 720 SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(encoded)); | 721 SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(encoded.get(
))); |
| 721 if (nullptr == codec) { | 722 if (nullptr == codec) { |
| 722 return SkISize::Make(0, 0); | 723 return SkISize::Make(0, 0); |
| 723 } | 724 } |
| 724 return codec->getSampledDimensions(fSampleSize); | 725 return codec->getSampledDimensions(fSampleSize); |
| 725 } | 726 } |
| 726 | 727 |
| 727 Name AndroidCodecSrc::name() const { | 728 Name AndroidCodecSrc::name() const { |
| 728 // We will replicate the names used by CodecSrc so that images can | 729 // We will replicate the names used by CodecSrc so that images can |
| 729 // be compared in Gold. | 730 // be compared in Gold. |
| 730 if (1 == fSampleSize) { | 731 if (1 == fSampleSize) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 749 } | 750 } |
| 750 | 751 |
| 751 return flags.type != SinkFlags::kRaster || flags.approach != SinkFlags::kDir
ect; | 752 return flags.type != SinkFlags::kRaster || flags.approach != SinkFlags::kDir
ect; |
| 752 } | 753 } |
| 753 | 754 |
| 754 Error ImageGenSrc::draw(SkCanvas* canvas) const { | 755 Error ImageGenSrc::draw(SkCanvas* canvas) const { |
| 755 if (kRGB_565_SkColorType == canvas->imageInfo().colorType()) { | 756 if (kRGB_565_SkColorType == canvas->imageInfo().colorType()) { |
| 756 return Error::Nonfatal("Uninteresting to test image generator to 565."); | 757 return Error::Nonfatal("Uninteresting to test image generator to 565."); |
| 757 } | 758 } |
| 758 | 759 |
| 759 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 760 sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str())); |
| 760 if (!encoded) { | 761 if (!encoded) { |
| 761 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); | 762 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
| 762 } | 763 } |
| 763 | 764 |
| 764 #if defined(SK_BUILD_FOR_WIN) | 765 #if defined(SK_BUILD_FOR_WIN) |
| 765 // Initialize COM in order to test with WIC. | 766 // Initialize COM in order to test with WIC. |
| 766 SkAutoCoInitialize com; | 767 SkAutoCoInitialize com; |
| 767 if (!com.succeeded()) { | 768 if (!com.succeeded()) { |
| 768 return "Could not initialize COM."; | 769 return "Could not initialize COM."; |
| 769 } | 770 } |
| 770 #endif | 771 #endif |
| 771 | 772 |
| 772 SkAutoTDelete<SkImageGenerator> gen(nullptr); | 773 SkAutoTDelete<SkImageGenerator> gen(nullptr); |
| 773 switch (fMode) { | 774 switch (fMode) { |
| 774 case kCodec_Mode: | 775 case kCodec_Mode: |
| 775 gen.reset(SkCodecImageGenerator::NewFromEncodedCodec(encoded)); | 776 gen.reset(SkCodecImageGenerator::NewFromEncodedCodec(encoded.get()))
; |
| 776 if (!gen) { | 777 if (!gen) { |
| 777 return "Could not create codec image generator."; | 778 return "Could not create codec image generator."; |
| 778 } | 779 } |
| 779 break; | 780 break; |
| 780 case kPlatform_Mode: { | 781 case kPlatform_Mode: { |
| 781 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) | 782 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) |
| 782 gen.reset(SkImageGeneratorCG::NewFromEncodedCG(encoded)); | 783 gen.reset(SkImageGeneratorCG::NewFromEncodedCG(encoded.get())); |
| 783 #elif defined(SK_BUILD_FOR_WIN) | 784 #elif defined(SK_BUILD_FOR_WIN) |
| 784 gen.reset(SkImageGeneratorWIC::NewFromEncodedWIC(encoded)); | 785 gen.reset(SkImageGeneratorWIC::NewFromEncodedWIC(encoded.get())); |
| 785 #endif | 786 #endif |
| 786 | 787 |
| 787 if (!gen) { | 788 if (!gen) { |
| 788 return "Could not create platform image generator."; | 789 return "Could not create platform image generator."; |
| 789 } | 790 } |
| 790 break; | 791 break; |
| 791 } | 792 } |
| 792 default: | 793 default: |
| 793 SkASSERT(false); | 794 SkASSERT(false); |
| 794 return "Invalid image generator mode"; | 795 return "Invalid image generator mode"; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 816 if (!gen->getPixels(decodeInfo, pixels.get(), rowBytes, colorPtr, &colorCoun
t)) { | 817 if (!gen->getPixels(decodeInfo, pixels.get(), rowBytes, colorPtr, &colorCoun
t)) { |
| 817 return SkStringPrintf("Image generator could not getPixels() for %s\n",
fPath.c_str()); | 818 return SkStringPrintf("Image generator could not getPixels() for %s\n",
fPath.c_str()); |
| 818 } | 819 } |
| 819 | 820 |
| 820 draw_to_canvas(canvas, decodeInfo, pixels.get(), rowBytes, colorPtr, colorCo
unt, | 821 draw_to_canvas(canvas, decodeInfo, pixels.get(), rowBytes, colorPtr, colorCo
unt, |
| 821 CodecSrc::kGetFromCanvas_DstColorType); | 822 CodecSrc::kGetFromCanvas_DstColorType); |
| 822 return ""; | 823 return ""; |
| 823 } | 824 } |
| 824 | 825 |
| 825 SkISize ImageGenSrc::size() const { | 826 SkISize ImageGenSrc::size() const { |
| 826 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 827 sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str())); |
| 827 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | 828 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded.get())); |
| 828 if (nullptr == codec) { | 829 if (nullptr == codec) { |
| 829 return SkISize::Make(0, 0); | 830 return SkISize::Make(0, 0); |
| 830 } | 831 } |
| 831 return codec->getInfo().dimensions(); | 832 return codec->getInfo().dimensions(); |
| 832 } | 833 } |
| 833 | 834 |
| 834 Name ImageGenSrc::name() const { | 835 Name ImageGenSrc::name() const { |
| 835 return SkOSPath::Basename(fPath.c_str()); | 836 return SkOSPath::Basename(fPath.c_str()); |
| 836 } | 837 } |
| 837 | 838 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 850 | 851 |
| 851 Error ColorCodecSrc::draw(SkCanvas* canvas) const { | 852 Error ColorCodecSrc::draw(SkCanvas* canvas) const { |
| 852 if (kRGB_565_SkColorType == canvas->imageInfo().colorType()) { | 853 if (kRGB_565_SkColorType == canvas->imageInfo().colorType()) { |
| 853 return Error::Nonfatal("No need to test color correction to 565 backend.
"); | 854 return Error::Nonfatal("No need to test color correction to 565 backend.
"); |
| 854 } | 855 } |
| 855 | 856 |
| 856 if (nullptr == canvas->imageInfo().colorSpace() && kRGBA_F16_SkColorType ==
fColorType) { | 857 if (nullptr == canvas->imageInfo().colorSpace() && kRGBA_F16_SkColorType ==
fColorType) { |
| 857 return Error::Nonfatal("F16 does not draw in legacy mode."); | 858 return Error::Nonfatal("F16 does not draw in legacy mode."); |
| 858 } | 859 } |
| 859 | 860 |
| 860 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 861 sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str())); |
| 861 if (!encoded) { | 862 if (!encoded) { |
| 862 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); | 863 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
| 863 } | 864 } |
| 864 | 865 |
| 865 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | 866 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded.get())); |
| 866 if (nullptr == codec.get()) { | 867 if (nullptr == codec.get()) { |
| 867 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str()); | 868 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str()); |
| 868 } | 869 } |
| 869 | 870 |
| 870 // Load the dst ICC profile. This particular dst is fairly similar to Adobe
RGB. | 871 // Load the dst ICC profile. This particular dst is fairly similar to Adobe
RGB. |
| 871 sk_sp<SkData> dstData = SkData::MakeFromFileName( | 872 sk_sp<SkData> dstData = SkData::MakeFromFileName( |
| 872 GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str()); | 873 GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str()); |
| 873 if (!dstData) { | 874 if (!dstData) { |
| 874 return "Cannot read monitor profile. Is the resource path set correctly
?"; | 875 return "Cannot read monitor profile. Is the resource path set correctly
?"; |
| 875 } | 876 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 949 } | 950 } |
| 950 #endif | 951 #endif |
| 951 default: | 952 default: |
| 952 SkASSERT(false); | 953 SkASSERT(false); |
| 953 return "Invalid fMode"; | 954 return "Invalid fMode"; |
| 954 } | 955 } |
| 955 return ""; | 956 return ""; |
| 956 } | 957 } |
| 957 | 958 |
| 958 SkISize ColorCodecSrc::size() const { | 959 SkISize ColorCodecSrc::size() const { |
| 959 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 960 sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str())); |
| 960 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | 961 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded.get())); |
| 961 if (nullptr == codec) { | 962 if (nullptr == codec) { |
| 962 return SkISize::Make(0, 0); | 963 return SkISize::Make(0, 0); |
| 963 } | 964 } |
| 964 return SkISize::Make(codec->getInfo().width(), codec->getInfo().height()); | 965 return SkISize::Make(codec->getInfo().width(), codec->getInfo().height()); |
| 965 } | 966 } |
| 966 | 967 |
| 967 Name ColorCodecSrc::name() const { | 968 Name ColorCodecSrc::name() const { |
| 968 return SkOSPath::Basename(fPath.c_str()); | 969 return SkOSPath::Basename(fPath.c_str()); |
| 969 } | 970 } |
| 970 | 971 |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1556 skr.visit(i, drawsAsSingletonPictures); | 1557 skr.visit(i, drawsAsSingletonPictures); |
| 1557 } | 1558 } |
| 1558 sk_sp<SkPicture> macroPic(macroRec.finishRecordingAsPicture()); | 1559 sk_sp<SkPicture> macroPic(macroRec.finishRecordingAsPicture()); |
| 1559 | 1560 |
| 1560 canvas->drawPicture(macroPic); | 1561 canvas->drawPicture(macroPic); |
| 1561 return check_against_reference(bitmap, src, fSink); | 1562 return check_against_reference(bitmap, src, fSink); |
| 1562 }); | 1563 }); |
| 1563 } | 1564 } |
| 1564 | 1565 |
| 1565 } // namespace DM | 1566 } // namespace DM |
| OLD | NEW |