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 914 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
925 } | 925 } |
926 return codec->getInfo().dimensions(); | 926 return codec->getInfo().dimensions(); |
927 } | 927 } |
928 | 928 |
929 Name ImageGenSrc::name() const { | 929 Name ImageGenSrc::name() const { |
930 return SkOSPath::Basename(fPath.c_str()); | 930 return SkOSPath::Basename(fPath.c_str()); |
931 } | 931 } |
932 | 932 |
933 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ | 933 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
934 | 934 |
| 935 ColorCodecSrc::ColorCodecSrc(Path path, Mode mode) |
| 936 : fPath(path) |
| 937 , fMode(mode) |
| 938 {} |
| 939 |
| 940 bool ColorCodecSrc::veto(SinkFlags flags) const { |
| 941 // Test to direct raster backends (8888 and 565). |
| 942 return flags.type != SinkFlags::kRaster || flags.approach != SinkFlags::kDir
ect; |
| 943 } |
| 944 |
| 945 Error ColorCodecSrc::draw(SkCanvas* canvas) const { |
| 946 if (kRGB_565_SkColorType == canvas->imageInfo().colorType()) { |
| 947 return Error::Nonfatal("No need to test color correction to 565 backend.
"); |
| 948 } |
| 949 |
| 950 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
| 951 if (!encoded) { |
| 952 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
| 953 } |
| 954 |
| 955 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
| 956 if (nullptr == codec.get()) { |
| 957 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str()); |
| 958 } |
| 959 |
| 960 SkImageInfo decodeInfo = codec->getInfo().makeColorType(kN32_SkColorType); |
| 961 SkBitmap bitmap; |
| 962 if (!bitmap.tryAllocPixels(decodeInfo)) { |
| 963 return SkStringPrintf("Image(%s) is too large (%d x %d)", fPath.c_str(), |
| 964 decodeInfo.width(), decodeInfo.height()); |
| 965 } |
| 966 |
| 967 switch (fMode) { |
| 968 case kBaseline_Mode: |
| 969 switch (codec->getPixels(decodeInfo, bitmap.getPixels(), bitmap.rowB
ytes())) { |
| 970 case SkCodec::kSuccess: |
| 971 break; |
| 972 default: |
| 973 // Everything else is considered a failure. |
| 974 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str(
)); |
| 975 } |
| 976 canvas->drawBitmap(bitmap, 0, 0); |
| 977 break; |
| 978 default: |
| 979 SkASSERT(false); |
| 980 return "Invalid fMode"; |
| 981 } |
| 982 return ""; |
| 983 } |
| 984 |
| 985 SkISize ColorCodecSrc::size() const { |
| 986 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
| 987 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
| 988 if (nullptr == codec) { |
| 989 return SkISize::Make(0, 0); |
| 990 } |
| 991 return SkISize::Make(codec->getInfo().width(), codec->getInfo().height()); |
| 992 } |
| 993 |
| 994 Name ColorCodecSrc::name() const { |
| 995 return SkOSPath::Basename(fPath.c_str()); |
| 996 } |
| 997 |
| 998 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
| 999 |
935 static const SkRect kSKPViewport = {0,0, 1000,1000}; | 1000 static const SkRect kSKPViewport = {0,0, 1000,1000}; |
936 | 1001 |
937 SKPSrc::SKPSrc(Path path) : fPath(path) {} | 1002 SKPSrc::SKPSrc(Path path) : fPath(path) {} |
938 | 1003 |
939 Error SKPSrc::draw(SkCanvas* canvas) const { | 1004 Error SKPSrc::draw(SkCanvas* canvas) const { |
940 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str())); | 1005 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str())); |
941 if (!stream) { | 1006 if (!stream) { |
942 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); | 1007 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
943 } | 1008 } |
944 sk_sp<SkPicture> pic(SkPicture::MakeFromStream(stream)); | 1009 sk_sp<SkPicture> pic(SkPicture::MakeFromStream(stream)); |
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1498 skr.visit(i, drawsAsSingletonPictures); | 1563 skr.visit(i, drawsAsSingletonPictures); |
1499 } | 1564 } |
1500 sk_sp<SkPicture> macroPic(macroRec.finishRecordingAsPicture()); | 1565 sk_sp<SkPicture> macroPic(macroRec.finishRecordingAsPicture()); |
1501 | 1566 |
1502 canvas->drawPicture(macroPic); | 1567 canvas->drawPicture(macroPic); |
1503 return check_against_reference(bitmap, src, fSink); | 1568 return check_against_reference(bitmap, src, fSink); |
1504 }); | 1569 }); |
1505 } | 1570 } |
1506 | 1571 |
1507 } // namespace DM | 1572 } // namespace DM |
OLD | NEW |