Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: dm/DMSrcSink.cpp

Issue 2333713002: change SkStreams to work with sk_sp<SkData> instead of SkData* (Closed)
Patch Set: fix xpsdevice Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « dm/DM.cpp ('k') | fuzz/Fuzz.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 // No need to test to non-raster or indirect backends. 97 // No need to test to non-raster or indirect backends.
98 return flags.type != SinkFlags::kRaster 98 return flags.type != SinkFlags::kRaster
99 || flags.approach != SinkFlags::kDirect; 99 || flags.approach != SinkFlags::kDirect;
100 } 100 }
101 101
102 static SkBitmapRegionDecoder* create_brd(Path path) { 102 static SkBitmapRegionDecoder* create_brd(Path path) {
103 sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str())); 103 sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
104 if (!encoded) { 104 if (!encoded) {
105 return NULL; 105 return NULL;
106 } 106 }
107 return SkBitmapRegionDecoder::Create(encoded.get(), 107 return SkBitmapRegionDecoder::Create(encoded, SkBitmapRegionDecoder::kAndroi dCodec_Strategy);
108 SkBitmapRegionDecoder::kAndroidCodec_St rategy);
109 } 108 }
110 109
111 Error BRDSrc::draw(SkCanvas* canvas) const { 110 Error BRDSrc::draw(SkCanvas* canvas) const {
112 SkColorType colorType = canvas->imageInfo().colorType(); 111 SkColorType colorType = canvas->imageInfo().colorType();
113 if (kRGB_565_SkColorType == colorType && 112 if (kRGB_565_SkColorType == colorType &&
114 CodecSrc::kGetFromCanvas_DstColorType != fDstColorType) { 113 CodecSrc::kGetFromCanvas_DstColorType != fDstColorType) {
115 return Error::Nonfatal("Testing non-565 to 565 is uninteresting."); 114 return Error::Nonfatal("Testing non-565 to 565 is uninteresting.");
116 } 115 }
117 switch (fDstColorType) { 116 switch (fDstColorType) {
118 case CodecSrc::kGetFromCanvas_DstColorType: 117 case CodecSrc::kGetFromCanvas_DstColorType:
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 swap_rb_if_necessary(bitmap, dstColorType); 376 swap_rb_if_necessary(bitmap, dstColorType);
378 canvas->drawBitmap(bitmap, left, top); 377 canvas->drawBitmap(bitmap, left, top);
379 } 378 }
380 379
381 Error CodecSrc::draw(SkCanvas* canvas) const { 380 Error CodecSrc::draw(SkCanvas* canvas) const {
382 sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str())); 381 sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
383 if (!encoded) { 382 if (!encoded) {
384 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); 383 return SkStringPrintf("Couldn't read %s.", fPath.c_str());
385 } 384 }
386 385
387 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded.get())); 386 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
388 if (nullptr == codec.get()) { 387 if (nullptr == codec.get()) {
389 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str()); 388 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str());
390 } 389 }
391 390
392 SkImageInfo decodeInfo = codec->getInfo(); 391 SkImageInfo decodeInfo = codec->getInfo();
393 if (!get_decode_info(&decodeInfo, canvas->imageInfo().colorType(), fDstColor Type, 392 if (!get_decode_info(&decodeInfo, canvas->imageInfo().colorType(), fDstColor Type,
394 fDstAlphaType)) { 393 fDstAlphaType)) {
395 return Error::Nonfatal("Testing non-565 to 565 is uninteresting."); 394 return Error::Nonfatal("Testing non-565 to 565 is uninteresting.");
396 } 395 }
397 396
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 } 624 }
626 default: 625 default:
627 SkASSERT(false); 626 SkASSERT(false);
628 return "Invalid fMode"; 627 return "Invalid fMode";
629 } 628 }
630 return ""; 629 return "";
631 } 630 }
632 631
633 SkISize CodecSrc::size() const { 632 SkISize CodecSrc::size() const {
634 sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str())); 633 sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
635 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded.get())); 634 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
636 if (nullptr == codec) { 635 if (nullptr == codec) {
637 return SkISize::Make(0, 0); 636 return SkISize::Make(0, 0);
638 } 637 }
639 return codec->getScaledDimensions(fScale); 638 return codec->getScaledDimensions(fScale);
640 } 639 }
641 640
642 Name CodecSrc::name() const { 641 Name CodecSrc::name() const {
643 if (1.0f == fScale) { 642 if (1.0f == fScale) {
644 return SkOSPath::Basename(fPath.c_str()); 643 return SkOSPath::Basename(fPath.c_str());
645 } 644 }
(...skipping 15 matching lines...) Expand all
661 // No need to test decoding to non-raster or indirect backend. 660 // No need to test decoding to non-raster or indirect backend.
662 return flags.type != SinkFlags::kRaster 661 return flags.type != SinkFlags::kRaster
663 || flags.approach != SinkFlags::kDirect; 662 || flags.approach != SinkFlags::kDirect;
664 } 663 }
665 664
666 Error AndroidCodecSrc::draw(SkCanvas* canvas) const { 665 Error AndroidCodecSrc::draw(SkCanvas* canvas) const {
667 sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str())); 666 sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
668 if (!encoded) { 667 if (!encoded) {
669 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); 668 return SkStringPrintf("Couldn't read %s.", fPath.c_str());
670 } 669 }
671 SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(encoded.get( ))); 670 SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(encoded));
672 if (nullptr == codec.get()) { 671 if (nullptr == codec.get()) {
673 return SkStringPrintf("Couldn't create android codec for %s.", fPath.c_s tr()); 672 return SkStringPrintf("Couldn't create android codec for %s.", fPath.c_s tr());
674 } 673 }
675 674
676 SkImageInfo decodeInfo = codec->getInfo(); 675 SkImageInfo decodeInfo = codec->getInfo();
677 if (!get_decode_info(&decodeInfo, canvas->imageInfo().colorType(), fDstColor Type, 676 if (!get_decode_info(&decodeInfo, canvas->imageInfo().colorType(), fDstColor Type,
678 fDstAlphaType)) { 677 fDstAlphaType)) {
679 return Error::Nonfatal("Testing non-565 to 565 is uninteresting."); 678 return Error::Nonfatal("Testing non-565 to 565 is uninteresting.");
680 } 679 }
681 680
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 break; 713 break;
715 default: 714 default:
716 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str()); 715 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str());
717 } 716 }
718 draw_to_canvas(canvas, bitmapInfo, pixels.get(), rowBytes, colorPtr, colorCo unt, fDstColorType); 717 draw_to_canvas(canvas, bitmapInfo, pixels.get(), rowBytes, colorPtr, colorCo unt, fDstColorType);
719 return ""; 718 return "";
720 } 719 }
721 720
722 SkISize AndroidCodecSrc::size() const { 721 SkISize AndroidCodecSrc::size() const {
723 sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str())); 722 sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
724 SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(encoded.get( ))); 723 SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(encoded));
725 if (nullptr == codec) { 724 if (nullptr == codec) {
726 return SkISize::Make(0, 0); 725 return SkISize::Make(0, 0);
727 } 726 }
728 return codec->getSampledDimensions(fSampleSize); 727 return codec->getSampledDimensions(fSampleSize);
729 } 728 }
730 729
731 Name AndroidCodecSrc::name() const { 730 Name AndroidCodecSrc::name() const {
732 // We will replicate the names used by CodecSrc so that images can 731 // We will replicate the names used by CodecSrc so that images can
733 // be compared in Gold. 732 // be compared in Gold.
734 if (1 == fSampleSize) { 733 if (1 == fSampleSize) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 return SkStringPrintf("Image generator could not getPixels() for %s\n", fPath.c_str()); 820 return SkStringPrintf("Image generator could not getPixels() for %s\n", fPath.c_str());
822 } 821 }
823 822
824 draw_to_canvas(canvas, decodeInfo, pixels.get(), rowBytes, colorPtr, colorCo unt, 823 draw_to_canvas(canvas, decodeInfo, pixels.get(), rowBytes, colorPtr, colorCo unt,
825 CodecSrc::kGetFromCanvas_DstColorType); 824 CodecSrc::kGetFromCanvas_DstColorType);
826 return ""; 825 return "";
827 } 826 }
828 827
829 SkISize ImageGenSrc::size() const { 828 SkISize ImageGenSrc::size() const {
830 sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str())); 829 sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
831 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded.get())); 830 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
832 if (nullptr == codec) { 831 if (nullptr == codec) {
833 return SkISize::Make(0, 0); 832 return SkISize::Make(0, 0);
834 } 833 }
835 return codec->getInfo().dimensions(); 834 return codec->getInfo().dimensions();
836 } 835 }
837 836
838 Name ImageGenSrc::name() const { 837 Name ImageGenSrc::name() const {
839 return SkOSPath::Basename(fPath.c_str()); 838 return SkOSPath::Basename(fPath.c_str());
840 } 839 }
841 840
(...skipping 24 matching lines...) Expand all
866 return Error::Nonfatal("Skipping tests that are only interesting in lega cy mode."); 865 return Error::Nonfatal("Skipping tests that are only interesting in lega cy mode.");
867 } else if (!runInLegacyMode && !canvas->imageInfo().colorSpace()) { 866 } else if (!runInLegacyMode && !canvas->imageInfo().colorSpace()) {
868 return Error::Nonfatal("Skipping tests that are only interesting in srgb mode."); 867 return Error::Nonfatal("Skipping tests that are only interesting in srgb mode.");
869 } 868 }
870 869
871 sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str())); 870 sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
872 if (!encoded) { 871 if (!encoded) {
873 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); 872 return SkStringPrintf("Couldn't read %s.", fPath.c_str());
874 } 873 }
875 874
876 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded.get())); 875 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
877 if (nullptr == codec.get()) { 876 if (nullptr == codec.get()) {
878 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str()); 877 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str());
879 } 878 }
880 879
881 // Load the dst ICC profile. This particular dst is fairly similar to Adobe RGB. 880 // Load the dst ICC profile. This particular dst is fairly similar to Adobe RGB.
882 sk_sp<SkData> dstData = SkData::MakeFromFileName( 881 sk_sp<SkData> dstData = SkData::MakeFromFileName(
883 GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str()); 882 GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str());
884 if (!dstData) { 883 if (!dstData) {
885 return "Cannot read monitor profile. Is the resource path set correctly ?"; 884 return "Cannot read monitor profile. Is the resource path set correctly ?";
886 } 885 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 #endif 971 #endif
973 default: 972 default:
974 SkASSERT(false); 973 SkASSERT(false);
975 return "Invalid fMode"; 974 return "Invalid fMode";
976 } 975 }
977 return ""; 976 return "";
978 } 977 }
979 978
980 SkISize ColorCodecSrc::size() const { 979 SkISize ColorCodecSrc::size() const {
981 sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str())); 980 sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
982 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded.get())); 981 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
983 if (nullptr == codec) { 982 if (nullptr == codec) {
984 return SkISize::Make(0, 0); 983 return SkISize::Make(0, 0);
985 } 984 }
986 return SkISize::Make(codec->getInfo().width(), codec->getInfo().height()); 985 return SkISize::Make(codec->getInfo().width(), codec->getInfo().height());
987 } 986 }
988 987
989 Name ColorCodecSrc::name() const { 988 Name ColorCodecSrc::name() const {
990 return SkOSPath::Basename(fPath.c_str()); 989 return SkOSPath::Basename(fPath.c_str());
991 } 990 }
992 991
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after
1636 Error err = src.draw(&rec); 1635 Error err = src.draw(&rec);
1637 if (!err.isEmpty()) { 1636 if (!err.isEmpty()) {
1638 return err; 1637 return err;
1639 } 1638 }
1640 dl->draw(canvas); 1639 dl->draw(canvas);
1641 return check_against_reference(bitmap, src, fSink); 1640 return check_against_reference(bitmap, src, fSink);
1642 }); 1641 });
1643 } 1642 }
1644 1643
1645 } // namespace DM 1644 } // namespace DM
OLDNEW
« no previous file with comments | « dm/DM.cpp ('k') | fuzz/Fuzz.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698