From db6a254bdcf6884db172f716966d7787e0d6f264 Mon Sep 17 00:00:00 2001 From: joshualitt Date: Thu, 11 Feb 2016 07:09:51 -0800 Subject: [PATCH] wire up new json code in skiaserve BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1691773002 Review URL: https://codereview.chromium.org/1691773002 --- tools/debugger/SkDebugCanvas.cpp | 4 ++-- tools/debugger/SkDebugCanvas.h | 7 ++++--- tools/skiaserve/skiaserve.cpp | 21 +++++++++++++-------- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/tools/debugger/SkDebugCanvas.cpp b/tools/debugger/SkDebugCanvas.cpp index d8d51fe0ac..8b71c0fb2c 100644 --- a/tools/debugger/SkDebugCanvas.cpp +++ b/tools/debugger/SkDebugCanvas.cpp @@ -318,11 +318,11 @@ SkTDArray & SkDebugCanvas::getDrawCommands() { return fCommandVector; } -Json::Value SkDebugCanvas::toJSON(UrlDataManager& urlDataManager) { +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++) { + for (int i = 0; i < this->getSize() && i < n; i++) { commands[i] = this->getDrawCommandAt(i)->toJSON(); } result[SKDEBUGCANVAS_ATTRIBUTE_COMMANDS] = commands; diff --git a/tools/debugger/SkDebugCanvas.h b/tools/debugger/SkDebugCanvas.h index 505b5c79fa..339e7add4a 100644 --- a/tools/debugger/SkDebugCanvas.h +++ b/tools/debugger/SkDebugCanvas.h @@ -141,10 +141,11 @@ public: SkString clipStackData() const { return fClipStackData; } /** - Returns a JSON object representing all of the draws. 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 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. */ - Json::Value toJSON(UrlDataManager& urlDataManager); + Json::Value toJSON(UrlDataManager& urlDataManager, int n); //////////////////////////////////////////////////////////////////////////////// // Inherited from SkCanvas diff --git a/tools/skiaserve/skiaserve.cpp b/tools/skiaserve/skiaserve.cpp index 6bc7cc7846..4b2d52b612 100644 --- a/tools/skiaserve/skiaserve.cpp +++ b/tools/skiaserve/skiaserve.cpp @@ -171,11 +171,11 @@ static int SendData(MHD_Connection* connection, const SkData* data, const char* return ret; } -static int SendJSON(MHD_Connection* connection, SkDebugCanvas* debugCanvas, int n) { +static int SendJSON(MHD_Connection* connection, SkDebugCanvas* debugCanvas, + UrlDataManager* urlDataManager, int n) { + Json::Value root = debugCanvas->toJSON(*urlDataManager, n); SkDynamicMemoryWStream stream; - SkAutoTUnref jsonCanvas(new SkJSONCanvas(kImageWidth, kImageHeight, stream)); - debugCanvas->drawTo(jsonCanvas, n); - jsonCanvas->finish(); + stream.writeText(Json::FastWriter().write(root).c_str()); SkAutoTUnref data(stream.copyToData()); return SendData(connection, data, "application/json"); @@ -229,10 +229,15 @@ public: return MHD_NO; } - // /cmd or /cmd/N or /cmd/N/[0|1] - if (commands.count() == 1 && 0 == strcmp(method, MHD_HTTP_METHOD_GET)) { - int n = request->fDebugCanvas->getSize() - 1; - return SendJSON(connection, request->fDebugCanvas, n); + // /cmd or /cmd/N + if (0 == strcmp(method, MHD_HTTP_METHOD_GET)) { + int n; + if (commands.count() == 1) { + n = request->fDebugCanvas->getSize() - 1; + } else { + sscanf(commands[1].c_str(), "%d", &n); + } + return SendJSON(connection, request->fDebugCanvas, &request->fUrlDataManager, n); } // /cmd/N, for now only delete supported