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

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

Issue 1691773002: wire up new json code in skiaserve (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fixup comment 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/debugger/SkDebugCanvas.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 "GrCaps.h" 8 #include "GrCaps.h"
9 #include "GrContextFactory.h" 9 #include "GrContextFactory.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 164
165 if (setContentDisposition) { 165 if (setContentDisposition) {
166 MHD_add_response_header(response, "Content-Disposition", dispositionStri ng); 166 MHD_add_response_header(response, "Content-Disposition", dispositionStri ng);
167 } 167 }
168 168
169 int ret = MHD_queue_response(connection, MHD_HTTP_OK, response); 169 int ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
170 MHD_destroy_response(response); 170 MHD_destroy_response(response);
171 return ret; 171 return ret;
172 } 172 }
173 173
174 static int SendJSON(MHD_Connection* connection, SkDebugCanvas* debugCanvas, int n) { 174 static int SendJSON(MHD_Connection* connection, SkDebugCanvas* debugCanvas,
175 UrlDataManager* urlDataManager, int n) {
176 Json::Value root = debugCanvas->toJSON(*urlDataManager, n);
175 SkDynamicMemoryWStream stream; 177 SkDynamicMemoryWStream stream;
176 SkAutoTUnref<SkJSONCanvas> jsonCanvas(new SkJSONCanvas(kImageWidth, kImageHe ight, stream)); 178 stream.writeText(Json::FastWriter().write(root).c_str());
177 debugCanvas->drawTo(jsonCanvas, n);
178 jsonCanvas->finish();
179 179
180 SkAutoTUnref<SkData> data(stream.copyToData()); 180 SkAutoTUnref<SkData> data(stream.copyToData());
181 return SendData(connection, data, "application/json"); 181 return SendData(connection, data, "application/json");
182 } 182 }
183 183
184 static int SendTemplate(MHD_Connection* connection, bool redirect = false, 184 static int SendTemplate(MHD_Connection* connection, bool redirect = false,
185 const char* redirectUrl = nullptr) { 185 const char* redirectUrl = nullptr) {
186 SkString debuggerTemplate = generateTemplate(SkString(FLAGS_source[0])); 186 SkString debuggerTemplate = generateTemplate(SkString(FLAGS_source[0]));
187 187
188 MHD_Response* response = MHD_create_response_from_buffer( 188 MHD_Response* response = MHD_create_response_from_buffer(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 int handle(Request* request, MHD_Connection* connection, 222 int handle(Request* request, MHD_Connection* connection,
223 const char* url, const char* method, 223 const char* url, const char* method,
224 const char* upload_data, size_t* upload_data_size) override { 224 const char* upload_data, size_t* upload_data_size) override {
225 SkTArray<SkString> commands; 225 SkTArray<SkString> commands;
226 SkStrSplit(url, "/", &commands); 226 SkStrSplit(url, "/", &commands);
227 227
228 if (!request->fPicture.get() || commands.count() > 3) { 228 if (!request->fPicture.get() || commands.count() > 3) {
229 return MHD_NO; 229 return MHD_NO;
230 } 230 }
231 231
232 // /cmd or /cmd/N or /cmd/N/[0|1] 232 // /cmd or /cmd/N
233 if (commands.count() == 1 && 0 == strcmp(method, MHD_HTTP_METHOD_GET)) { 233 if (0 == strcmp(method, MHD_HTTP_METHOD_GET)) {
234 int n = request->fDebugCanvas->getSize() - 1; 234 int n;
235 return SendJSON(connection, request->fDebugCanvas, n); 235 if (commands.count() == 1) {
236 n = request->fDebugCanvas->getSize() - 1;
237 } else {
238 sscanf(commands[1].c_str(), "%d", &n);
239 }
240 return SendJSON(connection, request->fDebugCanvas, &request->fUrlDat aManager, n);
236 } 241 }
237 242
238 // /cmd/N, for now only delete supported 243 // /cmd/N, for now only delete supported
239 if (commands.count() == 2 && 0 == strcmp(method, MHD_HTTP_METHOD_DELETE) ) { 244 if (commands.count() == 2 && 0 == strcmp(method, MHD_HTTP_METHOD_DELETE) ) {
240 int n; 245 int n;
241 sscanf(commands[1].c_str(), "%d", &n); 246 sscanf(commands[1].c_str(), "%d", &n);
242 request->fDebugCanvas->deleteDrawCommandAt(n); 247 request->fDebugCanvas->deleteDrawCommandAt(n);
243 return SendOK(connection); 248 return SendOK(connection);
244 } 249 }
245 250
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 MHD_stop_daemon(daemon); 563 MHD_stop_daemon(daemon);
559 return 0; 564 return 0;
560 } 565 }
561 566
562 #if !defined SK_BUILD_FOR_IOS 567 #if !defined SK_BUILD_FOR_IOS
563 int main(int argc, char** argv) { 568 int main(int argc, char** argv) {
564 SkCommandLineFlags::Parse(argc, argv); 569 SkCommandLineFlags::Parse(argc, argv);
565 return skiaserve_main(); 570 return skiaserve_main();
566 } 571 }
567 #endif 572 #endif
OLDNEW
« no previous file with comments | « tools/debugger/SkDebugCanvas.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698