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 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1036 SkCanvas canvas(*dst); | 1036 SkCanvas canvas(*dst); |
1037 return src.draw(&canvas); | 1037 return src.draw(&canvas); |
1038 } | 1038 } |
1039 | 1039 |
1040 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ | 1040 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
1041 | 1041 |
1042 // Handy for front-patching a Src. Do whatever up-front work you need, then cal
l draw_to_canvas(), | 1042 // Handy for front-patching a Src. Do whatever up-front work you need, then cal
l draw_to_canvas(), |
1043 // passing the Sink draw() arguments, a size, and a function draws into an SkCan
vas. | 1043 // passing the Sink draw() arguments, a size, and a function draws into an SkCan
vas. |
1044 // Several examples below. | 1044 // Several examples below. |
1045 | 1045 |
| 1046 template <typename Fn> |
1046 static Error draw_to_canvas(Sink* sink, SkBitmap* bitmap, SkWStream* stream, SkS
tring* log, | 1047 static Error draw_to_canvas(Sink* sink, SkBitmap* bitmap, SkWStream* stream, SkS
tring* log, |
1047 SkISize size, std::function<Error(SkCanvas*)> draw)
{ | 1048 SkISize size, const Fn& draw) { |
1048 class ProxySrc : public Src { | 1049 class ProxySrc : public Src { |
1049 public: | 1050 public: |
1050 ProxySrc(SkISize size, std::function<Error(SkCanvas*)> draw) : fSize(siz
e), fDraw(draw) {} | 1051 ProxySrc(SkISize size, const Fn& draw) : fSize(size), fDraw(draw) {} |
1051 Error draw(SkCanvas* canvas) const override { return fDraw(canvas); } | 1052 Error draw(SkCanvas* canvas) const override { return fDraw(canvas); } |
1052 Name name() const override { sk_throw(); return ""; }
// Won't be called. | 1053 Name name() const override { sk_throw(); return ""; }
// Won't be called. |
1053 SkISize size() const override { return fSize; } | 1054 SkISize size() const override { return fSize; } |
1054 private: | 1055 private: |
1055 SkISize fSize; | 1056 SkISize fSize; |
1056 std::function<Error(SkCanvas*)> fDraw; | 1057 const Fn& fDraw; |
1057 }; | 1058 }; |
1058 return sink->draw(ProxySrc(size, draw), bitmap, stream, log); | 1059 return sink->draw(ProxySrc(size, draw), bitmap, stream, log); |
1059 } | 1060 } |
1060 | 1061 |
1061 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ | 1062 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
1062 | 1063 |
1063 DEFINE_bool(check, true, "If true, have most Via- modes fail if they affect the
output."); | 1064 DEFINE_bool(check, true, "If true, have most Via- modes fail if they affect the
output."); |
1064 | 1065 |
1065 // Is *bitmap identical to what you get drawing src into sink? | 1066 // Is *bitmap identical to what you get drawing src into sink? |
1066 static Error check_against_reference(const SkBitmap* bitmap, const Src& src, Sin
k* sink) { | 1067 static Error check_against_reference(const SkBitmap* bitmap, const Src& src, Sin
k* sink) { |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1406 skr.visit<void>(i, drawsAsSingletonPictures); | 1407 skr.visit<void>(i, drawsAsSingletonPictures); |
1407 } | 1408 } |
1408 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); | 1409 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); |
1409 | 1410 |
1410 canvas->drawPicture(macroPic); | 1411 canvas->drawPicture(macroPic); |
1411 return check_against_reference(bitmap, src, fSink); | 1412 return check_against_reference(bitmap, src, fSink); |
1412 }); | 1413 }); |
1413 } | 1414 } |
1414 | 1415 |
1415 } // namespace DM | 1416 } // namespace DM |
OLD | NEW |