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 <mtklein@chromium.org>
Commit-Queue: Hal Canary <halcanary@google.com>
This commit is contained in:
Hal Canary 2016-10-25 10:33:27 -04:00 committed by Skia Commit-Bot
parent 7614794c9a
commit 85c7fe8d6d
3 changed files with 25 additions and 0 deletions

View File

@ -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;

View File

@ -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<SkCanvas> 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 {

View File

@ -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();