return fCommandVector;
}
-Json::Value SkDebugCanvas::toJSON(UrlDataManager& urlDataManager) {
+Json::Value SkDebugCanvas::toJSON(UrlDataManager& urlDataManager, int n) {
Json::Value result = Json::Value(Json::objectValue);
result[SKDEBUGCANVAS_ATTRIBUTE_VERSION] = Json::Value(SKDEBUGCANVAS_VERSION);
Json::Value commands = Json::Value(Json::arrayValue);
- for (int i = 0; i < this->getSize(); i++) {
+ for (int i = 0; i < this->getSize() && i < n; i++) {
commands[i] = this->getDrawCommandAt(i)->toJSON();
}
result[SKDEBUGCANVAS_ATTRIBUTE_COMMANDS] = commands;
SkString clipStackData() const { return fClipStackData; }
/**
- Returns a JSON object representing all of the draws. The encoder may use the UrlDataManager
- to store binary data such as images, referring to them via URLs embedded in the JSON.
+ Returns a JSON object representing up to N draws, where N is < SkDebugCanvas::getSize().
+ The encoder may use the UrlDataManager to store binary data such as images, referring to
+ them via URLs embedded in the JSON.
*/
- Json::Value toJSON(UrlDataManager& urlDataManager);
+ Json::Value toJSON(UrlDataManager& urlDataManager, int n);
////////////////////////////////////////////////////////////////////////////////
// Inherited from SkCanvas
return ret;
}
-static int SendJSON(MHD_Connection* connection, SkDebugCanvas* debugCanvas, int n) {
+static int SendJSON(MHD_Connection* connection, SkDebugCanvas* debugCanvas,
+ UrlDataManager* urlDataManager, int n) {
+ Json::Value root = debugCanvas->toJSON(*urlDataManager, n);
SkDynamicMemoryWStream stream;
- SkAutoTUnref<SkJSONCanvas> jsonCanvas(new SkJSONCanvas(kImageWidth, kImageHeight, stream));
- debugCanvas->drawTo(jsonCanvas, n);
- jsonCanvas->finish();
+ stream.writeText(Json::FastWriter().write(root).c_str());
SkAutoTUnref<SkData> data(stream.copyToData());
return SendData(connection, data, "application/json");
return MHD_NO;
}
- // /cmd or /cmd/N or /cmd/N/[0|1]
- if (commands.count() == 1 && 0 == strcmp(method, MHD_HTTP_METHOD_GET)) {
- int n = request->fDebugCanvas->getSize() - 1;
- return SendJSON(connection, request->fDebugCanvas, n);
+ // /cmd or /cmd/N
+ if (0 == strcmp(method, MHD_HTTP_METHOD_GET)) {
+ int n;
+ if (commands.count() == 1) {
+ n = request->fDebugCanvas->getSize() - 1;
+ } else {
+ sscanf(commands[1].c_str(), "%d", &n);
+ }
+ return SendJSON(connection, request->fDebugCanvas, &request->fUrlDataManager, n);
}
// /cmd/N, for now only delete supported