Add batch information to json
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1705093002
Review URL: https://codereview.chromium.org/1705093002
diff --git a/tools/debugger/SkDebugCanvas.cpp b/tools/debugger/SkDebugCanvas.cpp
index 89e53e1..9c0465d 100644
--- a/tools/debugger/SkDebugCanvas.cpp
+++ b/tools/debugger/SkDebugCanvas.cpp
@@ -331,12 +331,12 @@
return fCommandVector;
}
-Json::Value SkDebugCanvas::toJSON(UrlDataManager& urlDataManager, int n) {
+Json::Value SkDebugCanvas::toJSON(UrlDataManager& urlDataManager, int n, SkCanvas* canvas) {
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++) {
- commands[i] = this->getDrawCommandAt(i)->toJSON(urlDataManager);
+ commands[i] = this->getDrawCommandAt(i)->drawToAndCollectJSON(canvas, urlDataManager);
}
result[SKDEBUGCANVAS_ATTRIBUTE_COMMANDS] = commands;
return result;
diff --git a/tools/debugger/SkDebugCanvas.h b/tools/debugger/SkDebugCanvas.h
index ac2f0d4..d06637d 100644
--- a/tools/debugger/SkDebugCanvas.h
+++ b/tools/debugger/SkDebugCanvas.h
@@ -151,7 +151,7 @@
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);
+ Json::Value toJSON(UrlDataManager& urlDataManager, int n, SkCanvas*);
////////////////////////////////////////////////////////////////////////////////
// Inherited from SkCanvas
diff --git a/tools/debugger/SkDrawCommand.cpp b/tools/debugger/SkDrawCommand.cpp
index f23c41a..674a359 100644
--- a/tools/debugger/SkDrawCommand.cpp
+++ b/tools/debugger/SkDrawCommand.cpp
@@ -8,6 +8,7 @@
#include "SkDrawCommand.h"
+
#include "SkBlurMaskFilter.h"
#include "SkColorFilter.h"
#include "SkDashPathEffect.h"
@@ -24,7 +25,13 @@
#include "SkValidatingReadBuffer.h"
#include "SkWriteBuffer.h"
+#if SK_SUPPORT_GPU
+#include "GrContext.h"
+#include "GrRenderTarget.h"
+#endif
+
#define SKDEBUGCANVAS_ATTRIBUTE_COMMAND "command"
+#define SKDEBUGCANVAS_ATTRIBUTE_AUDITTRAIL "auditTrail"
#define SKDEBUGCANVAS_ATTRIBUTE_MATRIX "matrix"
#define SKDEBUGCANVAS_ATTRIBUTE_COORDS "coords"
#define SKDEBUGCANVAS_ATTRIBUTE_BOUNDS "bounds"
@@ -218,6 +225,37 @@
return result;
}
+Json::Value SkDrawCommand::drawToAndCollectJSON(SkCanvas* canvas,
+ UrlDataManager& urlDataManager) const {
+ Json::Value result;
+ result[SKDEBUGCANVAS_ATTRIBUTE_COMMAND] = this->GetCommandString(fOpType);
+
+ SkASSERT(canvas);
+
+#if SK_SUPPORT_GPU
+ GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget();
+ if (rt) {
+ GrContext* ctx = rt->getContext();
+ if(ctx) {
+ this->execute(canvas);
+ GrAuditTrail* at = ctx->getAuditTrail();
+
+ // TODO if this is inefficient we could add a method to GrAuditTrail which takes
+ // a Json::Value and is only compiled in this file
+ Json::Value parsedFromString;
+ Json::Reader reader;
+ SkDEBUGCODE(bool parsingSuccessful = )reader.parse(at->toJson().c_str(),
+ parsedFromString);
+ SkASSERT(parsingSuccessful);
+
+ result[SKDEBUGCANVAS_ATTRIBUTE_AUDITTRAIL] = parsedFromString;
+ at->reset();
+ }
+ }
+#endif
+ return result;
+}
+
#define INSTALL_FACTORY(name) factories.set(SkString(GetCommandString(k ## name ##_OpType)), \
(FROM_JSON) Sk ## name ## Command::fromJSON)
SkDrawCommand* SkDrawCommand::fromJSON(Json::Value& command, UrlDataManager& urlDataManager) {
diff --git a/tools/debugger/SkDrawCommand.h b/tools/debugger/SkDrawCommand.h
index ff1e1c5..34832a7 100644
--- a/tools/debugger/SkDrawCommand.h
+++ b/tools/debugger/SkDrawCommand.h
@@ -102,6 +102,8 @@
virtual Json::Value toJSON(UrlDataManager& urlDataManager) const;
+ Json::Value drawToAndCollectJSON(SkCanvas*, UrlDataManager& urlDataManager) const;
+
/* Converts a JSON representation of a command into a newly-allocated SkDrawCommand object. It
* is the caller's responsibility to delete this object. This method may return null if an error
* occurs.
diff --git a/tools/skiaserve/skiaserve.cpp b/tools/skiaserve/skiaserve.cpp
index 119f065..717e685 100644
--- a/tools/skiaserve/skiaserve.cpp
+++ b/tools/skiaserve/skiaserve.cpp
@@ -136,13 +136,18 @@
return buffer.copyToData();
}
-SkData* setupAndDrawToCanvasReturnPng(Request* request, int n) {
+SkCanvas* getCanvasFromRequest(Request* request) {
GrContextFactory* factory = request->fContextFactory;
SkGLContext* gl = factory->getContextInfo(GrContextFactory::kNative_GLContextType,
GrContextFactory::kNone_GLContextOptions).fGLContext;
gl->makeCurrent();
SkASSERT(request->fDebugCanvas);
SkCanvas* target = request->fSurface->getCanvas();
+ return target;
+}
+
+SkData* setupAndDrawToCanvasReturnPng(Request* request, int n) {
+ SkCanvas* target = getCanvasFromRequest(request);
request->fDebugCanvas->drawTo(target, n);
return writeCanvasToPng(target);
}
@@ -195,9 +200,9 @@
return ret;
}
-static int SendJSON(MHD_Connection* connection, SkDebugCanvas* debugCanvas,
+static int SendJSON(MHD_Connection* connection, SkCanvas* canvas, SkDebugCanvas* debugCanvas,
UrlDataManager* urlDataManager, int n) {
- Json::Value root = debugCanvas->toJSON(*urlDataManager, n);
+ Json::Value root = debugCanvas->toJSON(*urlDataManager, n, canvas);
SkDynamicMemoryWStream stream;
stream.writeText(Json::FastWriter().write(root).c_str());
@@ -261,7 +266,8 @@
} else {
sscanf(commands[1].c_str(), "%d", &n);
}
- return SendJSON(connection, request->fDebugCanvas, &request->fUrlDataManager, n);
+ return SendJSON(connection, getCanvasFromRequest(request), request->fDebugCanvas,
+ &request->fUrlDataManager, n);
}
// /cmd/N, for now only delete supported