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

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

Issue 1737643003: Move urlhandlers out of skiaserve.cpp (Closed) Base URL: https://skia.googlesource.com/skia@skiaserve-4
Patch Set: rebase Created 4 years, 10 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/ImgHandler.cpp ('k') | tools/skiaserve/urlhandlers/PostHandler.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "UrlHandler.h"
9
10 #include "microhttpd.h"
11 #include "SkJSONCanvas.h"
12 #include "../Request.h"
13 #include "../Response.h"
14
15 using namespace Response;
16
17 bool InfoHandler::canHandle(const char* method, const char* url) {
18 const char* kBaseName = "/info";
19 return 0 == strcmp(method, MHD_HTTP_METHOD_GET) &&
20 0 == strncmp(url, kBaseName, strlen(kBaseName));
21 }
22
23 int InfoHandler::handle(Request* request, MHD_Connection* connection,
24 const char* url, const char* method,
25 const char* upload_data, size_t* upload_data_size) {
26 SkTArray<SkString> commands;
27 SkStrSplit(url, "/", &commands);
28
29 if (!request->fPicture.get() || commands.count() > 2) {
30 return MHD_NO;
31 }
32
33 // drawTo
34 SkAutoTUnref<SkSurface> surface(request->createCPUSurface());
35 SkCanvas* canvas = surface->getCanvas();
36
37 int n;
38 // /info or /info/N
39 if (commands.count() == 1) {
40 n = request->fDebugCanvas->getSize() - 1;
41 } else {
42 sscanf(commands[1].c_str(), "%d", &n);
43 }
44
45 // TODO this is really slow and we should cache the matrix and clip
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");
60 }
61
OLDNEW
« no previous file with comments | « tools/skiaserve/urlhandlers/ImgHandler.cpp ('k') | tools/skiaserve/urlhandlers/PostHandler.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698