From 85c7fe8d6d87850aed83599864b63dca37af5fcf Mon Sep 17 00:00:00 2001 From: Hal Canary Date: Tue, 25 Oct 2016 10:33:27 -0400 Subject: [PATCH] DM: JSON Debug Sink Currently, the following GMs crash the debug canvas: ~dont_clip_to_layer ~imageblur ~imagefilterscropped ~pictureimagefilter ~savelayer_lcdtext ~textfilter_image // TODO(halcanary): fix this. GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=3742 Change-Id: Ieed3502119cd639fe345f3a41d436d5e39f3bdf1 Reviewed-on: https://skia-review.googlesource.com/3742 Reviewed-by: Mike Klein Commit-Queue: Hal Canary --- dm/DM.cpp | 1 + dm/DMSrcSink.cpp | 17 +++++++++++++++++ dm/DMSrcSink.h | 7 +++++++ 3 files changed, 25 insertions(+) diff --git a/dm/DM.cpp b/dm/DM.cpp index 36808ad168..42922c2c0b 100644 --- a/dm/DM.cpp +++ b/dm/DM.cpp @@ -883,6 +883,7 @@ static Sink* create_sink(const SkCommandLineConfig* config) { SINK("null", NullSink); SINK("xps", XPSSink); SINK("pdfa", PDFSink, true); + SINK("jsdebug", DebugSink); } #undef SINK return nullptr; diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp index 274f7dbe6d..30185a2ab1 100644 --- a/dm/DMSrcSink.cpp +++ b/dm/DMSrcSink.cpp @@ -15,6 +15,7 @@ #include "SkColorSpaceXform.h" #include "SkCommonFlags.h" #include "SkData.h" +#include "SkDebugCanvas.h" #include "SkDeferredCanvas.h" #include "SkDocument.h" #include "SkImageGenerator.h" @@ -1397,6 +1398,22 @@ Error SKPSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +Error DebugSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const { + SkDebugCanvas debugCanvas(src.size().width(), src.size().height()); + Error err = src.draw(&debugCanvas); + if (!err.isEmpty()) { + return err; + } + sk_sp nullCanvas(SkCreateNullCanvas()); + UrlDataManager dataManager(SkString("data")); + Json::Value json = debugCanvas.toJSON( + dataManager, debugCanvas.getSize(), nullCanvas.get()); + std::string value = Json::StyledWriter().write(json); + return dst->write(value.c_str(), value.size()) ? "" : "SkWStream Error"; +} + +/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ + SVGSink::SVGSink() {} Error SVGSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const { diff --git a/dm/DMSrcSink.h b/dm/DMSrcSink.h index 4be9878afa..cad15c7e86 100644 --- a/dm/DMSrcSink.h +++ b/dm/DMSrcSink.h @@ -374,6 +374,13 @@ public: SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } }; +class DebugSink : public Sink { +public: + Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; + const char* fileExtension() const override { return "json"; } + SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } +}; + class SVGSink : public Sink { public: SVGSink();