| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * Copyright 2016 Google Inc. | 2  * Copyright 2016 Google Inc. | 
| 3  * | 3  * | 
| 4  * Use of this source code is governed by a BSD-style license that can be | 4  * Use of this source code is governed by a BSD-style license that can be | 
| 5  * found in the LICENSE file. | 5  * found in the LICENSE file. | 
| 6  */ | 6  */ | 
| 7 | 7 | 
| 8 #include "GrCaps.h" | 8 #include "GrCaps.h" | 
| 9 #include "GrContextFactory.h" | 9 #include "GrContextFactory.h" | 
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" | 
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 60 | 60 | 
| 61 } | 61 } | 
| 62 | 62 | 
| 63 struct UploadContext { | 63 struct UploadContext { | 
| 64     SkDynamicMemoryWStream fStream; | 64     SkDynamicMemoryWStream fStream; | 
| 65     MHD_PostProcessor* fPostProcessor; | 65     MHD_PostProcessor* fPostProcessor; | 
| 66     MHD_Connection* connection; | 66     MHD_Connection* connection; | 
| 67 }; | 67 }; | 
| 68 | 68 | 
| 69 struct Request { | 69 struct Request { | 
| 70     Request(SkString rootUrl) : fUploadContext(nullptr), fUrlDataManager(rootUrl
     ) {} | 70     Request(SkString rootUrl) | 
|  | 71     : fUploadContext(nullptr) | 
|  | 72     , fUrlDataManager(rootUrl) | 
|  | 73     , fGPUEnabled(false) {} | 
|  | 74 | 
| 71     UploadContext* fUploadContext; | 75     UploadContext* fUploadContext; | 
| 72     SkAutoTUnref<SkPicture> fPicture; | 76     SkAutoTUnref<SkPicture> fPicture; | 
| 73     SkAutoTUnref<SkDebugCanvas> fDebugCanvas; | 77     SkAutoTUnref<SkDebugCanvas> fDebugCanvas; | 
| 74     SkAutoTDelete<GrContextFactory> fContextFactory; | 78     SkAutoTDelete<GrContextFactory> fContextFactory; | 
| 75     SkAutoTUnref<SkSurface> fSurface; | 79     SkAutoTUnref<SkSurface> fSurface; | 
| 76     UrlDataManager fUrlDataManager; | 80     UrlDataManager fUrlDataManager; | 
|  | 81     bool fGPUEnabled; | 
| 77 }; | 82 }; | 
| 78 | 83 | 
| 79 static void write_png_callback(png_structp png_ptr, png_bytep data, png_size_t l
     ength) { | 84 static void write_png_callback(png_structp png_ptr, png_bytep data, png_size_t l
     ength) { | 
| 80     SkWStream* out = (SkWStream*) png_get_io_ptr(png_ptr); | 85     SkWStream* out = (SkWStream*) png_get_io_ptr(png_ptr); | 
| 81     out->write(data, length); | 86     out->write(data, length); | 
| 82 } | 87 } | 
| 83 | 88 | 
| 84 static void write_png(const png_bytep rgba, png_uint_32 width, png_uint_32 heigh
     t, SkWStream& out) { | 89 static void write_png(const png_bytep rgba, png_uint_32 width, png_uint_32 heigh
     t, SkWStream& out) { | 
| 85     png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL,
      NULL); | 90     png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL,
      NULL); | 
| 86     SkASSERT(png != nullptr); | 91     SkASSERT(png != nullptr); | 
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 219 | 224 | 
| 220     if (setContentDisposition) { | 225     if (setContentDisposition) { | 
| 221         MHD_add_response_header(response, "Content-Disposition", dispositionStri
     ng); | 226         MHD_add_response_header(response, "Content-Disposition", dispositionStri
     ng); | 
| 222     } | 227     } | 
| 223 | 228 | 
| 224     int ret = MHD_queue_response(connection, MHD_HTTP_OK, response); | 229     int ret = MHD_queue_response(connection, MHD_HTTP_OK, response); | 
| 225     MHD_destroy_response(response); | 230     MHD_destroy_response(response); | 
| 226     return ret; | 231     return ret; | 
| 227 } | 232 } | 
| 228 | 233 | 
| 229 static int SendJSON(MHD_Connection* connection, SkCanvas* canvas, SkDebugCanvas*
      debugCanvas, | 234 static int SendJSON(MHD_Connection* connection, Request* request, int n) { | 
| 230                     UrlDataManager* urlDataManager, int n) { | 235     SkCanvas* canvas = getCanvasFromRequest(request); | 
|  | 236     SkDebugCanvas* debugCanvas = request->fDebugCanvas; | 
|  | 237     UrlDataManager* urlDataManager = &request->fUrlDataManager; | 
| 231     Json::Value root = debugCanvas->toJSON(*urlDataManager, n, canvas); | 238     Json::Value root = debugCanvas->toJSON(*urlDataManager, n, canvas); | 
|  | 239     root["mode"] = Json::Value(request->fGPUEnabled ? "gpu" : "cpu"); | 
| 232     SkDynamicMemoryWStream stream; | 240     SkDynamicMemoryWStream stream; | 
| 233     stream.writeText(Json::FastWriter().write(root).c_str()); | 241     stream.writeText(Json::FastWriter().write(root).c_str()); | 
| 234 | 242 | 
| 235     SkAutoTUnref<SkData> data(stream.copyToData()); | 243     SkAutoTUnref<SkData> data(stream.copyToData()); | 
| 236     return SendData(connection, data, "application/json"); | 244     return SendData(connection, data, "application/json"); | 
| 237 } | 245 } | 
| 238 | 246 | 
| 239 static int SendTemplate(MHD_Connection* connection, bool redirect = false, | 247 static int SendTemplate(MHD_Connection* connection, bool redirect = false, | 
| 240                         const char* redirectUrl = nullptr) { | 248                         const char* redirectUrl = nullptr) { | 
| 241     SkString debuggerTemplate = generateTemplate(SkString(FLAGS_source[0])); | 249     SkString debuggerTemplate = generateTemplate(SkString(FLAGS_source[0])); | 
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 285         } | 293         } | 
| 286 | 294 | 
| 287         // /cmd or /cmd/N | 295         // /cmd or /cmd/N | 
| 288         if (0 == strcmp(method, MHD_HTTP_METHOD_GET)) { | 296         if (0 == strcmp(method, MHD_HTTP_METHOD_GET)) { | 
| 289             int n; | 297             int n; | 
| 290             if (commands.count() == 1) { | 298             if (commands.count() == 1) { | 
| 291                 n = request->fDebugCanvas->getSize() - 1; | 299                 n = request->fDebugCanvas->getSize() - 1; | 
| 292             } else { | 300             } else { | 
| 293                 sscanf(commands[1].c_str(), "%d", &n); | 301                 sscanf(commands[1].c_str(), "%d", &n); | 
| 294             } | 302             } | 
| 295             return SendJSON(connection, getCanvasFromRequest(request), request->
     fDebugCanvas, | 303             return SendJSON(connection, request, n); | 
| 296                             &request->fUrlDataManager, n); |  | 
| 297         } | 304         } | 
| 298 | 305 | 
| 299         // /cmd/N, for now only delete supported | 306         // /cmd/N, for now only delete supported | 
| 300         if (commands.count() == 2 && 0 == strcmp(method, MHD_HTTP_METHOD_DELETE)
     ) { | 307         if (commands.count() == 2 && 0 == strcmp(method, MHD_HTTP_METHOD_DELETE)
     ) { | 
| 301             int n; | 308             int n; | 
| 302             sscanf(commands[1].c_str(), "%d", &n); | 309             sscanf(commands[1].c_str(), "%d", &n); | 
| 303             request->fDebugCanvas->deleteDrawCommandAt(n); | 310             request->fDebugCanvas->deleteDrawCommandAt(n); | 
| 304             return SendOK(connection); | 311             return SendOK(connection); | 
| 305         } | 312         } | 
| 306 | 313 | 
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 486             return MHD_NO; | 493             return MHD_NO; | 
| 487         } | 494         } | 
| 488 | 495 | 
| 489         int enable; | 496         int enable; | 
| 490         sscanf(commands[1].c_str(), "%d", &enable); | 497         sscanf(commands[1].c_str(), "%d", &enable); | 
| 491 | 498 | 
| 492         if (enable) { | 499         if (enable) { | 
| 493             SkSurface* surface = createGPUSurface(request); | 500             SkSurface* surface = createGPUSurface(request); | 
| 494             if (surface) { | 501             if (surface) { | 
| 495                 request->fSurface.reset(surface); | 502                 request->fSurface.reset(surface); | 
|  | 503                 request->fGPUEnabled = true; | 
| 496                 return SendOK(connection); | 504                 return SendOK(connection); | 
| 497             } | 505             } | 
| 498             return SendError(connection, "Unable to create GPU surface"); | 506             return SendError(connection, "Unable to create GPU surface"); | 
| 499         } | 507         } | 
| 500         request->fSurface.reset(createCPUSurface()); | 508         request->fSurface.reset(createCPUSurface()); | 
|  | 509         request->fGPUEnabled = false; | 
| 501         return SendOK(connection); | 510         return SendOK(connection); | 
| 502     } | 511     } | 
| 503 }; | 512 }; | 
| 504 | 513 | 
| 505 class PostHandler : public UrlHandler { | 514 class PostHandler : public UrlHandler { | 
| 506 public: | 515 public: | 
| 507     bool canHandle(const char* method, const char* url) override { | 516     bool canHandle(const char* method, const char* url) override { | 
| 508         return 0 == strcmp(method, MHD_HTTP_METHOD_POST) && | 517         return 0 == strcmp(method, MHD_HTTP_METHOD_POST) && | 
| 509                0 == strcmp(url, "/new"); | 518                0 == strcmp(url, "/new"); | 
| 510     } | 519     } | 
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 782     MHD_stop_daemon(daemon); | 791     MHD_stop_daemon(daemon); | 
| 783     return 0; | 792     return 0; | 
| 784 } | 793 } | 
| 785 | 794 | 
| 786 #if !defined SK_BUILD_FOR_IOS | 795 #if !defined SK_BUILD_FOR_IOS | 
| 787 int main(int argc, char** argv) { | 796 int main(int argc, char** argv) { | 
| 788     SkCommandLineFlags::Parse(argc, argv); | 797     SkCommandLineFlags::Parse(argc, argv); | 
| 789     return skiaserve_main(); | 798     return skiaserve_main(); | 
| 790 } | 799 } | 
| 791 #endif | 800 #endif | 
| OLD | NEW | 
|---|