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 979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
990 return SkOSPath::Basename(fPath.c_str()); | 990 return SkOSPath::Basename(fPath.c_str()); |
991 } | 991 } |
992 | 992 |
993 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ | 993 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
994 | 994 |
995 static const SkRect kSKPViewport = {0,0, 1000,1000}; | 995 static const SkRect kSKPViewport = {0,0, 1000,1000}; |
996 | 996 |
997 SKPSrc::SKPSrc(Path path) : fPath(path) {} | 997 SKPSrc::SKPSrc(Path path) : fPath(path) {} |
998 | 998 |
999 Error SKPSrc::draw(SkCanvas* canvas) const { | 999 Error SKPSrc::draw(SkCanvas* canvas) const { |
1000 std::unique_ptr<SkStream> stream = SkStream::MakeFromFile(fPath.c_str()); | 1000 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str())); |
1001 if (!stream) { | 1001 if (!stream) { |
1002 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); | 1002 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
1003 } | 1003 } |
1004 sk_sp<SkPicture> pic(SkPicture::MakeFromStream(stream.get())); | 1004 sk_sp<SkPicture> pic(SkPicture::MakeFromStream(stream)); |
1005 if (!pic) { | 1005 if (!pic) { |
1006 return SkStringPrintf("Couldn't decode %s as a picture.", fPath.c_str())
; | 1006 return SkStringPrintf("Couldn't decode %s as a picture.", fPath.c_str())
; |
1007 } | 1007 } |
1008 stream = nullptr; // Might as well drop this when we're done with it. | 1008 stream.reset((SkStream*)nullptr); // Might as well drop this when we're don
e with it. |
1009 | 1009 |
1010 canvas->clipRect(kSKPViewport); | 1010 canvas->clipRect(kSKPViewport); |
1011 canvas->drawPicture(pic); | 1011 canvas->drawPicture(pic); |
1012 return ""; | 1012 return ""; |
1013 } | 1013 } |
1014 | 1014 |
1015 SkISize SKPSrc::size() const { | 1015 SkISize SKPSrc::size() const { |
1016 std::unique_ptr<SkStream> stream = SkStream::MakeFromFile(fPath.c_str()); | 1016 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str())); |
1017 if (!stream) { | 1017 if (!stream) { |
1018 return SkISize::Make(0,0); | 1018 return SkISize::Make(0,0); |
1019 } | 1019 } |
1020 SkPictInfo info; | 1020 SkPictInfo info; |
1021 if (!SkPicture::InternalOnly_StreamIsSKP(stream.get(), &info)) { | 1021 if (!SkPicture::InternalOnly_StreamIsSKP(stream, &info)) { |
1022 return SkISize::Make(0,0); | 1022 return SkISize::Make(0,0); |
1023 } | 1023 } |
1024 SkRect viewport = kSKPViewport; | 1024 SkRect viewport = kSKPViewport; |
1025 if (!viewport.intersect(info.fCullRect)) { | 1025 if (!viewport.intersect(info.fCullRect)) { |
1026 return SkISize::Make(0,0); | 1026 return SkISize::Make(0,0); |
1027 } | 1027 } |
1028 return viewport.roundOut().size(); | 1028 return viewport.roundOut().size(); |
1029 } | 1029 } |
1030 | 1030 |
1031 Name SKPSrc::name() const { return SkOSPath::Basename(fPath.c_str()); } | 1031 Name SKPSrc::name() const { return SkOSPath::Basename(fPath.c_str()); } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1065 bool type_ok = flags.type == SinkFlags::kRaster | 1065 bool type_ok = flags.type == SinkFlags::kRaster |
1066 || flags.type == SinkFlags::kGPU; | 1066 || flags.type == SinkFlags::kGPU; |
1067 | 1067 |
1068 return !type_ok || flags.approach != SinkFlags::kDirect; | 1068 return !type_ok || flags.approach != SinkFlags::kDirect; |
1069 } | 1069 } |
1070 | 1070 |
1071 #endif // defined(SK_XML) | 1071 #endif // defined(SK_XML) |
1072 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ | 1072 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
1073 | 1073 |
1074 MSKPSrc::MSKPSrc(Path path) : fPath(path) { | 1074 MSKPSrc::MSKPSrc(Path path) : fPath(path) { |
1075 std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(fPath.c_str()
); | 1075 std::unique_ptr<SkStreamAsset> stream(SkStream::NewFromFile(fPath.c_str())); |
1076 (void)fReader.init(stream.get()); | 1076 (void)fReader.init(stream.get()); |
1077 } | 1077 } |
1078 | 1078 |
1079 int MSKPSrc::pageCount() const { return fReader.pageCount(); } | 1079 int MSKPSrc::pageCount() const { return fReader.pageCount(); } |
1080 | 1080 |
1081 SkISize MSKPSrc::size() const { return this->size(0); } | 1081 SkISize MSKPSrc::size() const { return this->size(0); } |
1082 SkISize MSKPSrc::size(int i) const { return fReader.pageSize(i).toCeil(); } | 1082 SkISize MSKPSrc::size(int i) const { return fReader.pageSize(i).toCeil(); } |
1083 | 1083 |
1084 Error MSKPSrc::draw(SkCanvas* c) const { return this->draw(0, c); } | 1084 Error MSKPSrc::draw(SkCanvas* c) const { return this->draw(0, c); } |
1085 Error MSKPSrc::draw(int i, SkCanvas* canvas) const { | 1085 Error MSKPSrc::draw(int i, SkCanvas* canvas) const { |
1086 std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(fPath.c_str()
); | 1086 std::unique_ptr<SkStreamAsset> stream(SkStream::NewFromFile(fPath.c_str())); |
1087 if (!stream) { | 1087 if (!stream) { |
1088 return SkStringPrintf("Unable to open file: %s", fPath.c_str()); | 1088 return SkStringPrintf("Unable to open file: %s", fPath.c_str()); |
1089 } | 1089 } |
1090 if (fReader.pageCount() == 0) { | 1090 if (fReader.pageCount() == 0) { |
1091 return SkStringPrintf("Unable to parse MultiPictureDocument file: %s", f
Path.c_str()); | 1091 return SkStringPrintf("Unable to parse MultiPictureDocument file: %s", f
Path.c_str()); |
1092 } | 1092 } |
1093 if (i >= fReader.pageCount()) { | 1093 if (i >= fReader.pageCount()) { |
1094 return SkStringPrintf("MultiPictureDocument page number out of range: %d
", i); | 1094 return SkStringPrintf("MultiPictureDocument page number out of range: %d
", i); |
1095 } | 1095 } |
1096 sk_sp<SkPicture> page = fReader.readPage(stream.get(), i); | 1096 sk_sp<SkPicture> page = fReader.readPage(stream.get(), i); |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1659 Error err = src.draw(&rec); | 1659 Error err = src.draw(&rec); |
1660 if (!err.isEmpty()) { | 1660 if (!err.isEmpty()) { |
1661 return err; | 1661 return err; |
1662 } | 1662 } |
1663 dl->draw(canvas); | 1663 dl->draw(canvas); |
1664 return check_against_reference(bitmap, src, fSink); | 1664 return check_against_reference(bitmap, src, fSink); |
1665 }); | 1665 }); |
1666 } | 1666 } |
1667 | 1667 |
1668 } // namespace DM | 1668 } // namespace DM |
OLD | NEW |