diff options
Diffstat (limited to 'tools/skiaserve')
-rw-r--r-- | tools/skiaserve/Request.cpp | 38 | ||||
-rw-r--r-- | tools/skiaserve/Request.h | 8 | ||||
-rw-r--r-- | tools/skiaserve/Response.cpp | 13 | ||||
-rw-r--r-- | tools/skiaserve/Response.h | 2 | ||||
-rw-r--r-- | tools/skiaserve/skiaserve.cpp | 1 | ||||
-rw-r--r-- | tools/skiaserve/urlhandlers/BatchesHandler.cpp | 41 | ||||
-rw-r--r-- | tools/skiaserve/urlhandlers/CmdHandler.cpp | 8 | ||||
-rw-r--r-- | tools/skiaserve/urlhandlers/UrlHandler.h | 11 |
8 files changed, 104 insertions, 18 deletions
diff --git a/tools/skiaserve/Request.cpp b/tools/skiaserve/Request.cpp index 33e94fdc40..3d9e9d37b3 100644 --- a/tools/skiaserve/Request.cpp +++ b/tools/skiaserve/Request.cpp @@ -111,3 +111,41 @@ SkSurface* Request::createGPUSurface() { return surface; } +SkData* Request::getJsonOps(int n) { + SkCanvas* canvas = this->getCanvas(); + Json::Value root = fDebugCanvas->toJSON(fUrlDataManager, n, canvas); + root["mode"] = Json::Value(fGPUEnabled ? "gpu" : "cpu"); + SkDynamicMemoryWStream stream; + stream.writeText(Json::FastWriter().write(root).c_str()); + + return stream.copyToData(); +} + +SkData* Request::getJsonBatchList(int n) { + SkCanvas* canvas = this->getCanvas(); + SkASSERT(fGPUEnabled); + + // 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; +#if SK_SUPPORT_GPU + GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget(); + SkASSERT(rt); + GrContext* ctx = rt->getContext(); + SkASSERT(ctx); + GrAuditTrail* at = ctx->getAuditTrail(); + GrAuditTrail::AutoManageBatchList enable(at); + + fDebugCanvas->drawTo(canvas, n); + + Json::Reader reader; + SkDEBUGCODE(bool parsingSuccessful = )reader.parse(at->toJson(true).c_str(), + parsedFromString); + SkASSERT(parsingSuccessful); +#endif + + SkDynamicMemoryWStream stream; + stream.writeText(Json::FastWriter().write(parsedFromString).c_str()); + + return stream.copyToData(); +} diff --git a/tools/skiaserve/Request.h b/tools/skiaserve/Request.h index a3276fa38b..f6ee994ecd 100644 --- a/tools/skiaserve/Request.h +++ b/tools/skiaserve/Request.h @@ -39,6 +39,14 @@ struct Request { SkCanvas* getCanvas(); SkData* writeCanvasToPng(SkCanvas* canvas); SkBitmap* getBitmapFromCanvas(SkCanvas* canvas); + bool hasPicture() const { return SkToBool(fPicture.get()); } + int getLastOp() const { return fDebugCanvas->getSize() - 1; } + + // Returns the json list of ops as an SkData + SkData* getJsonOps(int n); + + // Returns a json list of batches as an SkData + SkData* getJsonBatchList(int n); // TODO probably want to make this configurable static const int kImageWidth; diff --git a/tools/skiaserve/Response.cpp b/tools/skiaserve/Response.cpp index 16cb3b6e3d..61470f122a 100644 --- a/tools/skiaserve/Response.cpp +++ b/tools/skiaserve/Response.cpp @@ -77,19 +77,6 @@ int SendData(MHD_Connection* connection, const SkData* data, const char* type, return ret; } -int SendJSON(MHD_Connection* connection, Request* request, int n) { - SkCanvas* canvas = request->getCanvas(); - SkDebugCanvas* debugCanvas = request->fDebugCanvas; - UrlDataManager* urlDataManager = &request->fUrlDataManager; - Json::Value root = debugCanvas->toJSON(*urlDataManager, n, canvas); - root["mode"] = Json::Value(request->fGPUEnabled ? "gpu" : "cpu"); - SkDynamicMemoryWStream stream; - stream.writeText(Json::FastWriter().write(root).c_str()); - - SkAutoTUnref<SkData> data(stream.copyToData()); - return SendData(connection, data, "application/json"); -} - int SendTemplate(MHD_Connection* connection, bool redirect, const char* redirectUrl) { SkString debuggerTemplate = generate_template(SkString(FLAGS_source[0])); diff --git a/tools/skiaserve/Response.h b/tools/skiaserve/Response.h index ef115e9d23..7655d6f354 100644 --- a/tools/skiaserve/Response.h +++ b/tools/skiaserve/Response.h @@ -21,8 +21,6 @@ namespace Response { int SendData(MHD_Connection* connection, const SkData* data, const char* type, bool setContentDisposition = false, const char* dispositionString = nullptr); - int SendJSON(MHD_Connection* connection, Request* request, int n); - int SendTemplate(MHD_Connection* connection, bool redirect = false, const char* redirectUrl = nullptr); } diff --git a/tools/skiaserve/skiaserve.cpp b/tools/skiaserve/skiaserve.cpp index 622fbf114b..d493f7d923 100644 --- a/tools/skiaserve/skiaserve.cpp +++ b/tools/skiaserve/skiaserve.cpp @@ -41,6 +41,7 @@ public: fHandlers.push_back(new DownloadHandler); fHandlers.push_back(new DataHandler); fHandlers.push_back(new BreakHandler); + fHandlers.push_back(new BatchesHandler); } ~UrlManager() { diff --git a/tools/skiaserve/urlhandlers/BatchesHandler.cpp b/tools/skiaserve/urlhandlers/BatchesHandler.cpp new file mode 100644 index 0000000000..221c5393c7 --- /dev/null +++ b/tools/skiaserve/urlhandlers/BatchesHandler.cpp @@ -0,0 +1,41 @@ +/* + * Copyright 2016 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "UrlHandler.h" + +#include "microhttpd.h" +#include "../Request.h" +#include "../Response.h" + +using namespace Response; + +bool BatchesHandler::canHandle(const char* method, const char* url) { + const char* kBasePath = "/batches"; + return 0 == strncmp(url, kBasePath, strlen(kBasePath)); +} + +int BatchesHandler::handle(Request* request, MHD_Connection* connection, + const char* url, const char* method, + const char* upload_data, size_t* upload_data_size) { + SkTArray<SkString> commands; + SkStrSplit(url, "/", &commands); + + if (!request->hasPicture() || commands.count() > 1) { + return MHD_NO; + } + + // /batches + if (0 == strcmp(method, MHD_HTTP_METHOD_GET)) { + int n = request->getLastOp(); + + SkAutoTUnref<SkData> data(request->getJsonBatchList(n)); + return SendData(connection, data, "application/json"); + } + + return MHD_NO; +} + diff --git a/tools/skiaserve/urlhandlers/CmdHandler.cpp b/tools/skiaserve/urlhandlers/CmdHandler.cpp index c741eb9a43..1699bcbcfc 100644 --- a/tools/skiaserve/urlhandlers/CmdHandler.cpp +++ b/tools/skiaserve/urlhandlers/CmdHandler.cpp @@ -24,7 +24,7 @@ int CmdHandler::handle(Request* request, MHD_Connection* connection, SkTArray<SkString> commands; SkStrSplit(url, "/", &commands); - if (!request->fPicture.get() || commands.count() > 3) { + if (!request->hasPicture() || commands.count() > 3) { return MHD_NO; } @@ -32,11 +32,13 @@ int CmdHandler::handle(Request* request, MHD_Connection* connection, if (0 == strcmp(method, MHD_HTTP_METHOD_GET)) { int n; if (commands.count() == 1) { - n = request->fDebugCanvas->getSize() - 1; + n = request->getLastOp(); } else { sscanf(commands[1].c_str(), "%d", &n); } - return SendJSON(connection, request, n); + + SkAutoTUnref<SkData> data(request->getJsonOps(n)); + return SendData(connection, data, "application/json"); } // /cmd/N, for now only delete supported diff --git a/tools/skiaserve/urlhandlers/UrlHandler.h b/tools/skiaserve/urlhandlers/UrlHandler.h index 9eee35f489..28d378aaf9 100644 --- a/tools/skiaserve/urlhandlers/UrlHandler.h +++ b/tools/skiaserve/urlhandlers/UrlHandler.h @@ -101,6 +101,17 @@ public: const char* upload_data, size_t* upload_data_size) override; }; +/* + * Returns a json descripton of all the batches in the image + */ +class BatchesHandler : public UrlHandler { +public: + bool canHandle(const char* method, const char* url) override; + int handle(Request* request, MHD_Connection* connection, + const char* url, const char* method, + const char* upload_data, size_t* upload_data_size) override; +}; + class RootHandler : public UrlHandler { public: bool canHandle(const char* method, const char* url) override; |