diff options
author | Mike Reed <reed@google.com> | 2017-02-17 17:06:11 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-02-17 22:49:59 +0000 |
commit | f67c45994dedc96eb979e331ab156649847071a4 (patch) | |
tree | 2fe1634895566c3340e62aeaec74170ca36cd7c8 /dm | |
parent | e005edd3a5deb602beec59f59cdc8b14d3764d58 (diff) |
add ViaSVG to dm
BUG=skia:
Change-Id: I52892a0dd466bee6e3abcaa89a373b93493d201f
Reviewed-on: https://skia-review.googlesource.com/8682
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Mike Klein <mtklein@chromium.org>
Reviewed-by: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'dm')
-rw-r--r-- | dm/DM.cpp | 1 | ||||
-rw-r--r-- | dm/DMSrcSink.cpp | 25 | ||||
-rw-r--r-- | dm/DMSrcSink.h | 6 |
3 files changed, 32 insertions, 0 deletions
@@ -885,6 +885,7 @@ static Sink* create_via(const SkString& tag, Sink* wrapped) { VIA("lite", ViaLite, wrapped); VIA("pipe", ViaPipe, wrapped); VIA("twice", ViaTwice, wrapped); + VIA("svg", ViaSVG, wrapped); VIA("serialize", ViaSerialization, wrapped); VIA("pic", ViaPicture, wrapped); VIA("2ndpic", ViaSecondPicture, wrapped); diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp index d28c3a2ff2..6e84cc9885 100644 --- a/dm/DMSrcSink.cpp +++ b/dm/DMSrcSink.cpp @@ -1712,6 +1712,31 @@ Error ViaTwice::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStri /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +#include "SkXMLWriter.h" +#include "SkSVGCanvas.h" +#include "SkSVGDOM.h" + +Error ViaSVG::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const { + auto size = src.size(); + return draw_to_canvas(fSink.get(), bitmap, stream, log, size, [&](SkCanvas* canvas) -> Error { + SkDynamicMemoryWStream wstream; + SkXMLStreamWriter writer(&wstream); + Error err = src.draw(SkSVGCanvas::Make(SkRect::Make(size), &writer).get()); + if (!err.isEmpty()) { + return err; + } + std::unique_ptr<SkStream> rstream(wstream.detachAsStream()); + auto dom = SkSVGDOM::MakeFromStream(*rstream); + if (dom) { + dom->setContainerSize(SkSize::Make(size)); + dom->render(canvas); + } + return ""; + }); +} + +/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ + // This is like SkRecords::Draw, in that it plays back SkRecords ops into a Canvas. // Unlike SkRecords::Draw, it builds a single-op sub-picture out of each Draw-type op. // This is an only-slightly-exaggerated simluation of Blink's Slimming Paint pictures. diff --git a/dm/DMSrcSink.h b/dm/DMSrcSink.h index cac8848307..f2b09f6134 100644 --- a/dm/DMSrcSink.h +++ b/dm/DMSrcSink.h @@ -467,6 +467,12 @@ public: Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; }; +class ViaSVG : public Via { +public: + explicit ViaSVG(Sink* sink) : Via(sink) {} + Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; +}; + class ViaMojo : public Via { public: explicit ViaMojo(Sink* sink) : Via(sink) {} |