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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 SkStrSplit(url, "/", &commands); | 225 SkStrSplit(url, "/", &commands); |
226 | 226 |
227 if (!request->fPicture.get() || commands.count() > 3) { | 227 if (!request->fPicture.get() || commands.count() > 3) { |
228 return MHD_NO; | 228 return MHD_NO; |
229 } | 229 } |
230 | 230 |
231 // /cmd or /cmd/N | 231 // /cmd or /cmd/N |
232 if (0 == strcmp(method, MHD_HTTP_METHOD_GET)) { | 232 if (0 == strcmp(method, MHD_HTTP_METHOD_GET)) { |
233 int n; | 233 int n; |
234 if (commands.count() == 1) { | 234 if (commands.count() == 1) { |
235 n = request->fDebugCanvas->getSize(); | 235 n = request->fDebugCanvas->getSize() - 1; |
236 } else { | 236 } else { |
237 sscanf(commands[1].c_str(), "%d", &n); | 237 sscanf(commands[1].c_str(), "%d", &n); |
238 } | 238 } |
239 return SendJSON(connection, request->fDebugCanvas, &request->fUrlDat
aManager, n); | 239 return SendJSON(connection, request->fDebugCanvas, &request->fUrlDat
aManager, n); |
240 } | 240 } |
241 | 241 |
242 // /cmd/N, for now only delete supported | 242 // /cmd/N, for now only delete supported |
243 if (commands.count() == 2 && 0 == strcmp(method, MHD_HTTP_METHOD_DELETE)
) { | 243 if (commands.count() == 2 && 0 == strcmp(method, MHD_HTTP_METHOD_DELETE)
) { |
244 int n; | 244 int n; |
245 sscanf(commands[1].c_str(), "%d", &n); | 245 sscanf(commands[1].c_str(), "%d", &n); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 n = request->fDebugCanvas->getSize() - 1; | 284 n = request->fDebugCanvas->getSize() - 1; |
285 } else { | 285 } else { |
286 sscanf(commands[1].c_str(), "%d", &n); | 286 sscanf(commands[1].c_str(), "%d", &n); |
287 } | 287 } |
288 | 288 |
289 SkAutoTUnref<SkData> data(setupAndDrawToCanvasReturnPng(request, n)); | 289 SkAutoTUnref<SkData> data(setupAndDrawToCanvasReturnPng(request, n)); |
290 return SendData(connection, data, "image/png"); | 290 return SendData(connection, data, "image/png"); |
291 } | 291 } |
292 }; | 292 }; |
293 | 293 |
| 294 /** |
| 295 Updates the clip visualization alpha. On all subsequent /img requests, the cl
ip will be drawn in |
| 296 black with the specified alpha. 0 = no visible clip, 255 = fully opaque clip. |
| 297 */ |
| 298 class ClipAlphaHandler : public UrlHandler { |
| 299 public: |
| 300 bool canHandle(const char* method, const char* url) override { |
| 301 static const char* kBasePath = "/clipAlpha/"; |
| 302 return 0 == strcmp(method, MHD_HTTP_METHOD_GET) && |
| 303 0 == strncmp(url, kBasePath, strlen(kBasePath)); |
| 304 } |
| 305 |
| 306 int handle(Request* request, MHD_Connection* connection, |
| 307 const char* url, const char* method, |
| 308 const char* upload_data, size_t* upload_data_size) override { |
| 309 SkTArray<SkString> commands; |
| 310 SkStrSplit(url, "/", &commands); |
| 311 |
| 312 if (!request->fPicture.get() || commands.count() != 2) { |
| 313 return MHD_NO; |
| 314 } |
| 315 |
| 316 int alpha; |
| 317 sscanf(commands[1].c_str(), "%d", &alpha); |
| 318 |
| 319 request->fDebugCanvas->setClipVizColor(SkColorSetARGB(alpha, 0, 0, 0)); |
| 320 return SendOK(connection); |
| 321 } |
| 322 }; |
| 323 |
294 class PostHandler : public UrlHandler { | 324 class PostHandler : public UrlHandler { |
295 public: | 325 public: |
296 bool canHandle(const char* method, const char* url) override { | 326 bool canHandle(const char* method, const char* url) override { |
297 return 0 == strcmp(method, MHD_HTTP_METHOD_POST) && | 327 return 0 == strcmp(method, MHD_HTTP_METHOD_POST) && |
298 0 == strcmp(url, "/new"); | 328 0 == strcmp(url, "/new"); |
299 } | 329 } |
300 | 330 |
301 int handle(Request* request, MHD_Connection* connection, | 331 int handle(Request* request, MHD_Connection* connection, |
302 const char* url, const char* method, | 332 const char* url, const char* method, |
303 const char* upload_data, size_t* upload_data_size) override { | 333 const char* upload_data, size_t* upload_data_size) override { |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 } | 531 } |
502 }; | 532 }; |
503 | 533 |
504 class UrlManager { | 534 class UrlManager { |
505 public: | 535 public: |
506 UrlManager() { | 536 UrlManager() { |
507 // Register handlers | 537 // Register handlers |
508 fHandlers.push_back(new RootHandler); | 538 fHandlers.push_back(new RootHandler); |
509 fHandlers.push_back(new PostHandler); | 539 fHandlers.push_back(new PostHandler); |
510 fHandlers.push_back(new ImgHandler); | 540 fHandlers.push_back(new ImgHandler); |
| 541 fHandlers.push_back(new ClipAlphaHandler); |
511 fHandlers.push_back(new CmdHandler); | 542 fHandlers.push_back(new CmdHandler); |
512 fHandlers.push_back(new InfoHandler); | 543 fHandlers.push_back(new InfoHandler); |
513 fHandlers.push_back(new DownloadHandler); | 544 fHandlers.push_back(new DownloadHandler); |
514 fHandlers.push_back(new DataHandler); | 545 fHandlers.push_back(new DataHandler); |
515 fHandlers.push_back(new FaviconHandler); | 546 fHandlers.push_back(new FaviconHandler); |
516 } | 547 } |
517 | 548 |
518 ~UrlManager() { | 549 ~UrlManager() { |
519 for (int i = 0; i < fHandlers.count(); i++) { delete fHandlers[i]; } | 550 for (int i = 0; i < fHandlers.count(); i++) { delete fHandlers[i]; } |
520 } | 551 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 MHD_stop_daemon(daemon); | 598 MHD_stop_daemon(daemon); |
568 return 0; | 599 return 0; |
569 } | 600 } |
570 | 601 |
571 #if !defined SK_BUILD_FOR_IOS | 602 #if !defined SK_BUILD_FOR_IOS |
572 int main(int argc, char** argv) { | 603 int main(int argc, char** argv) { |
573 SkCommandLineFlags::Parse(argc, argv); | 604 SkCommandLineFlags::Parse(argc, argv); |
574 return skiaserve_main(); | 605 return skiaserve_main(); |
575 } | 606 } |
576 #endif | 607 #endif |
OLD | NEW |