SkData* Request::getJsonBatchList(int n) { SkCanvas* canvas = this->getCanvas(); SkASSERT(fGPUEnabled); // TODO if this is inefficient we could add a method to GrAuditTrail which takes // a Json::Value and is only compiled in this file Json::Value parsedFromString; #if SK_SUPPORT_GPU GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget(); SkASSERT(rt); GrContext* ctx = rt->getContext(); SkASSERT(ctx); GrAuditTrail* at = ctx->getAuditTrail(); GrAuditTrail::AutoManageBatchList enable(at); fDebugCanvas->drawTo(canvas, n); Json::Reader reader; SkDEBUGCODE(bool parsingSuccessful = )reader.parse(at->toJson(true).c_str(), parsedFromString); SkASSERT(parsingSuccessful); #endif SkDynamicMemoryWStream stream; stream.writeText(Json::FastWriter().write(parsedFromString).c_str()); return stream.copyToData(); }
Json::Value SkDebugCanvas::toJSON(UrlDataManager& urlDataManager, int n, SkCanvas* canvas) { this->drawAndCollectBatches(n, canvas); // now collect json #if SK_SUPPORT_GPU GrAuditTrail* at = this->getAuditTrail(canvas); #endif 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 <= n; i++) { commands[i] = this->getDrawCommandAt(i)->toJSON(urlDataManager); #if SK_SUPPORT_GPU if (at) { // TODO if this is inefficient we could add a method to GrAuditTrail which takes // a Json::Value and is only compiled in this file Json::Value parsedFromString; Json::Reader reader; SkAssertResult(reader.parse(at->toJson(i).c_str(), parsedFromString)); commands[i][SKDEBUGCANVAS_ATTRIBUTE_AUDITTRAIL] = parsedFromString; } #endif } this->cleanupAuditTrail(canvas); result[SKDEBUGCANVAS_ATTRIBUTE_COMMANDS] = commands; return result; }
Json::Value SkDebugCanvas::toJSONBatchList(int n, SkCanvas* canvas) { this->drawAndCollectBatches(n, canvas); Json::Value parsedFromString; #if SK_SUPPORT_GPU GrAuditTrail* at = this->getAuditTrail(canvas); if (at) { GrAuditTrail::AutoManageBatchList enable(at); Json::Reader reader; SkAssertResult(reader.parse(at->toJson().c_str(), parsedFromString)); } #endif this->cleanupAuditTrail(canvas); return parsedFromString; }