added mode=cpu|gpu to skiaserve JSON
authorethannicholas <ethannicholas@google.com>
Mon, 22 Feb 2016 16:59:57 +0000 (08:59 -0800)
committerCommit bot <commit-bot@chromium.org>
Mon, 22 Feb 2016 16:59:57 +0000 (08:59 -0800)
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1719973002

Review URL: https://codereview.chromium.org/1719973002

tools/skiaserve/skiaserve.cpp

index 18a522a4c1b9170523f97741f5411356a2bdc77d..427ce4b8f31f8a9cb3b002884f0e68c575794f15 100644 (file)
@@ -67,13 +67,18 @@ struct UploadContext {
 };
 
 struct Request {
-    Request(SkString rootUrl) : fUploadContext(nullptr), fUrlDataManager(rootUrl) {}
+    Request(SkString rootUrl) 
+    : fUploadContext(nullptr)
+    , fUrlDataManager(rootUrl)
+    , fGPUEnabled(false) {}
+
     UploadContext* fUploadContext;
     SkAutoTUnref<SkPicture> fPicture;
     SkAutoTUnref<SkDebugCanvas> fDebugCanvas;
     SkAutoTDelete<GrContextFactory> fContextFactory;
     SkAutoTUnref<SkSurface> fSurface;
     UrlDataManager fUrlDataManager;
+    bool fGPUEnabled;
 };
 
 static void write_png_callback(png_structp png_ptr, png_bytep data, png_size_t length) {
@@ -226,9 +231,12 @@ static int SendData(MHD_Connection* connection, const SkData* data, const char*
     return ret;
 }
 
-static int SendJSON(MHD_Connection* connection, SkCanvas* canvas, SkDebugCanvas* debugCanvas,
-                    UrlDataManager* urlDataManager, int n) {
+static int SendJSON(MHD_Connection* connection, Request* request, int n) {
+    SkCanvas* canvas = getCanvasFromRequest(request);
+    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());
 
@@ -292,8 +300,7 @@ public:
             } else {
                 sscanf(commands[1].c_str(), "%d", &n);
             }
-            return SendJSON(connection, getCanvasFromRequest(request), request->fDebugCanvas,
-                            &request->fUrlDataManager, n);
+            return SendJSON(connection, request, n);
         }
 
         // /cmd/N, for now only delete supported
@@ -493,11 +500,13 @@ public:
             SkSurface* surface = createGPUSurface(request);
             if (surface) {
                 request->fSurface.reset(surface);
+                request->fGPUEnabled = true;
                 return SendOK(connection);
             }
             return SendError(connection, "Unable to create GPU surface");
         }
         request->fSurface.reset(createCPUSurface());
+        request->fGPUEnabled = false;
         return SendOK(connection);
     }
 };