Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: tools/skiaserve/urlhandlers/InfoHandler.cpp

Issue 1741823002: Get SkiaServe Request started off with a little privacy (Closed) Base URL: https://skia.googlesource.com/skia@skiaserve-7-wireup
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/skiaserve/urlhandlers/EnableGPUHandler.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "UrlHandler.h" 8 #include "UrlHandler.h"
9 9
10 #include "microhttpd.h" 10 #include "microhttpd.h"
11 #include "SkJSONCanvas.h"
12 #include "../Request.h" 11 #include "../Request.h"
13 #include "../Response.h" 12 #include "../Response.h"
14 13
15 using namespace Response; 14 using namespace Response;
16 15
17 bool InfoHandler::canHandle(const char* method, const char* url) { 16 bool InfoHandler::canHandle(const char* method, const char* url) {
18 const char* kBaseName = "/info"; 17 const char* kBaseName = "/info";
19 return 0 == strcmp(method, MHD_HTTP_METHOD_GET) && 18 return 0 == strcmp(method, MHD_HTTP_METHOD_GET) &&
20 0 == strncmp(url, kBaseName, strlen(kBaseName)); 19 0 == strncmp(url, kBaseName, strlen(kBaseName));
21 } 20 }
22 21
23 int InfoHandler::handle(Request* request, MHD_Connection* connection, 22 int InfoHandler::handle(Request* request, MHD_Connection* connection,
24 const char* url, const char* method, 23 const char* url, const char* method,
25 const char* upload_data, size_t* upload_data_size) { 24 const char* upload_data, size_t* upload_data_size) {
26 SkTArray<SkString> commands; 25 SkTArray<SkString> commands;
27 SkStrSplit(url, "/", &commands); 26 SkStrSplit(url, "/", &commands);
28 27
29 if (!request->fPicture.get() || commands.count() > 2) { 28 if (!request->hasPicture() || commands.count() > 2) {
30 return MHD_NO; 29 return MHD_NO;
31 } 30 }
32 31
33 // drawTo
34 SkAutoTUnref<SkSurface> surface(request->createCPUSurface());
35 SkCanvas* canvas = surface->getCanvas();
36
37 int n; 32 int n;
38 // /info or /info/N 33 // /info or /info/N
39 if (commands.count() == 1) { 34 if (commands.count() == 1) {
40 n = request->fDebugCanvas->getSize() - 1; 35 n = request->getLastOp();
41 } else { 36 } else {
42 sscanf(commands[1].c_str(), "%d", &n); 37 sscanf(commands[1].c_str(), "%d", &n);
43 } 38 }
44 39
45 // TODO this is really slow and we should cache the matrix and clip 40 SkAutoTUnref<SkData> data(request->getJsonInfo(n));
46 request->fDebugCanvas->drawTo(canvas, n);
47
48 // make some json
49 SkMatrix vm = request->fDebugCanvas->getCurrentMatrix();
50 SkIRect clip = request->fDebugCanvas->getCurrentClip();
51 Json::Value info(Json::objectValue);
52 info["ViewMatrix"] = SkJSONCanvas::MakeMatrix(vm);
53 info["ClipRect"] = SkJSONCanvas::MakeIRect(clip);
54
55 std::string json = Json::FastWriter().write(info);
56
57 // We don't want the null terminator so strlen is correct
58 SkAutoTUnref<SkData> data(SkData::NewWithCopy(json.c_str(), strlen(json.c_st r())));
59 return SendData(connection, data, "application/json"); 41 return SendData(connection, data, "application/json");
60 } 42 }
61 43
OLDNEW
« no previous file with comments | « tools/skiaserve/urlhandlers/EnableGPUHandler.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698