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
This commit is contained in:
parent
bbfe47bd0f
commit
0a0520afcc
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user