diff options
author | ethannicholas <ethannicholas@google.com> | 2016-02-12 12:06:53 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-12 12:06:53 -0800 |
commit | 0a0520afccb9dcad9db2258c936456e69012fa34 (patch) | |
tree | 2ec83a3ec40290885b17822cf83d6528dc51b238 /tools | |
parent | bbfe47bd0fd328a387722e233304f35f4f9d27a2 (diff) |
added clip visualization to skiaserve
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1690023004
Review URL: https://codereview.chromium.org/1690023004
Diffstat (limited to 'tools')
-rw-r--r-- | tools/debugger/SkDebugCanvas.cpp | 16 | ||||
-rw-r--r-- | tools/debugger/SkDebugCanvas.h | 13 | ||||
-rw-r--r-- | tools/skiaserve/skiaserve.cpp | 33 |
3 files changed, 56 insertions, 6 deletions
diff --git a/tools/debugger/SkDebugCanvas.cpp b/tools/debugger/SkDebugCanvas.cpp index 11b10c04ee..89e53e1e7c 100644 --- a/tools/debugger/SkDebugCanvas.cpp +++ b/tools/debugger/SkDebugCanvas.cpp @@ -67,7 +67,8 @@ SkDebugCanvas::SkDebugCanvas(int width, int height) , fMegaVizMode(false) , fOverdrawViz(false) , fOverrideFilterQuality(false) - , fFilterQuality(kNone_SkFilterQuality) { + , fFilterQuality(kNone_SkFilterQuality) + , fClipVizColor(SK_ColorTRANSPARENT) { fUserMatrix.reset(); // SkPicturePlayback uses the base-class' quickReject calls to cull clipped @@ -233,6 +234,17 @@ void SkDebugCanvas::drawTo(SkCanvas* canvas, int index) { } } + if (SkColorGetA(fClipVizColor) != 0) { + canvas->save(); + #define LARGE_COORD 1000000000 + canvas->clipRect(SkRect::MakeLTRB(-LARGE_COORD, -LARGE_COORD, LARGE_COORD, LARGE_COORD), + SkRegion::kReverseDifference_Op); + SkPaint clipPaint; + clipPaint.setColor(fClipVizColor); + canvas->drawPaint(clipPaint); + canvas->restore(); + } + if (fMegaVizMode) { canvas->save(); // nuke the CTM @@ -323,7 +335,7 @@ Json::Value SkDebugCanvas::toJSON(UrlDataManager& urlDataManager, int n) { Json::Value result = Json::Value(Json::objectValue); result[SKDEBUGCANVAS_ATTRIBUTE_VERSION] = Json::Value(SKDEBUGCANVAS_VERSION); Json::Value commands = Json::Value(Json::arrayValue); - for (int i = 0; i < this->getSize() && i < n; i++) { + for (int i = 0; i < this->getSize() && i <= n; i++) { commands[i] = this->getDrawCommandAt(i)->toJSON(urlDataManager); } result[SKDEBUGCANVAS_ATTRIBUTE_COMMANDS] = commands; diff --git a/tools/debugger/SkDebugCanvas.h b/tools/debugger/SkDebugCanvas.h index 9a4a9d603b..ac2f0d4207 100644 --- a/tools/debugger/SkDebugCanvas.h +++ b/tools/debugger/SkDebugCanvas.h @@ -37,6 +37,12 @@ public: void setOverdrawViz(bool overdrawViz); bool getOverdrawViz() const { return fOverdrawViz; } + /** + * Set the color of the clip visualization. An alpha of zero renders the clip invisible. + */ + void setClipVizColor(SkColor clipVizColor) { this->fClipVizColor = clipVizColor; } + SkColor getClipVizColor() const { return fClipVizColor; } + bool getAllowSimplifyClip() const { return fAllowSimplifyClip; } void setPicture(SkPicture* picture) { fPicture = picture; } @@ -141,9 +147,9 @@ public: SkString clipStackData() const { return fClipStackData; } /** - Returns a JSON object representing up to N draws, where N is <= SkDebugCanvas::getSize(). - The encoder may use the UrlDataManager to store binary data such as images, referring to - them via URLs embedded in the JSON. + Returns a JSON object representing up to the Nth draw, where N is less than + SkDebugCanvas::getSize(). The encoder may use the UrlDataManager to store binary data such + as images, referring to them via URLs embedded in the JSON. */ Json::Value toJSON(UrlDataManager& urlDataManager, int n); @@ -238,6 +244,7 @@ private: bool fOverdrawViz; bool fOverrideFilterQuality; SkFilterQuality fFilterQuality; + SkColor fClipVizColor; SkAutoTUnref<SkNWayCanvas> fPaintFilterCanvas; diff --git a/tools/skiaserve/skiaserve.cpp b/tools/skiaserve/skiaserve.cpp index 1db8261bd4..d8430d7853 100644 --- a/tools/skiaserve/skiaserve.cpp +++ b/tools/skiaserve/skiaserve.cpp @@ -232,7 +232,7 @@ public: if (0 == strcmp(method, MHD_HTTP_METHOD_GET)) { int n; if (commands.count() == 1) { - n = request->fDebugCanvas->getSize(); + n = request->fDebugCanvas->getSize() - 1; } else { sscanf(commands[1].c_str(), "%d", &n); } @@ -291,6 +291,36 @@ public: } }; +/** + Updates the clip visualization alpha. On all subsequent /img requests, the clip will be drawn in + black with the specified alpha. 0 = no visible clip, 255 = fully opaque clip. + */ +class ClipAlphaHandler : public UrlHandler { +public: + bool canHandle(const char* method, const char* url) override { + static const char* kBasePath = "/clipAlpha/"; + return 0 == strcmp(method, MHD_HTTP_METHOD_GET) && + 0 == strncmp(url, kBasePath, strlen(kBasePath)); + } + + int handle(Request* request, MHD_Connection* connection, + const char* url, const char* method, + const char* upload_data, size_t* upload_data_size) override { + SkTArray<SkString> commands; + SkStrSplit(url, "/", &commands); + + if (!request->fPicture.get() || commands.count() != 2) { + return MHD_NO; + } + + int alpha; + sscanf(commands[1].c_str(), "%d", &alpha); + + request->fDebugCanvas->setClipVizColor(SkColorSetARGB(alpha, 0, 0, 0)); + return SendOK(connection); + } +}; + class PostHandler : public UrlHandler { public: bool canHandle(const char* method, const char* url) override { @@ -508,6 +538,7 @@ public: fHandlers.push_back(new RootHandler); fHandlers.push_back(new PostHandler); fHandlers.push_back(new ImgHandler); + fHandlers.push_back(new ClipAlphaHandler); fHandlers.push_back(new CmdHandler); fHandlers.push_back(new InfoHandler); fHandlers.push_back(new DownloadHandler); |