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(); }
SkData* Request::getJsonOps(int n) { SkCanvas* canvas = this->getCanvas(); Json::Value root = fDebugCanvas->toJSON(fUrlDataManager, n, canvas); root["mode"] = Json::Value(fGPUEnabled ? "gpu" : "cpu"); SkDynamicMemoryWStream stream; stream.writeText(Json::FastWriter().write(root).c_str()); return stream.copyToData(); }
SkData* Request::getJsonBatchList(int n) { SkCanvas* canvas = this->getCanvas(); SkASSERT(fGPUEnabled); Json::Value result = fDebugCanvas->toJSONBatchList(n, canvas); SkDynamicMemoryWStream stream; stream.writeText(Json::FastWriter().write(result).c_str()); return stream.copyToData(); }
sk_sp<SkData> Request::getJsonOps(int n) { SkCanvas* canvas = this->getCanvas(); Json::Value root = fDebugCanvas->toJSON(fUrlDataManager, n, canvas); root["mode"] = Json::Value(fGPUEnabled ? "gpu" : "cpu"); root["drawGpuBatchBounds"] = Json::Value(fDebugCanvas->getDrawGpuBatchBounds()); root["colorMode"] = Json::Value(fColorMode); SkDynamicMemoryWStream stream; stream.writeText(Json::FastWriter().write(root).c_str()); return stream.detachAsData(); }
static void TestPDFStream(skiatest::Reporter* reporter) { char streamBytes[] = "Test\nFoo\tBar"; SkAutoTDelete<SkMemoryStream> streamData(new SkMemoryStream( streamBytes, strlen(streamBytes), true)); SkAutoTUnref<SkPDFStream> stream(new SkPDFStream(streamData.get())); ASSERT_EMIT_EQ(reporter, *stream, "<</Length 12>> stream\nTest\nFoo\tBar\nendstream"); stream->insertInt("Attribute", 42); ASSERT_EMIT_EQ(reporter, *stream, "<</Length 12\n/Attribute 42>> stream\n" "Test\nFoo\tBar\nendstream"); { char streamBytes2[] = "This is a longer string, so that compression " "can do something with it. With shorter strings, " "the short circuit logic cuts in and we end up " "with an uncompressed string."; SkAutoDataUnref streamData2(SkData::NewWithCopy(streamBytes2, strlen(streamBytes2))); SkAutoTUnref<SkPDFStream> stream(new SkPDFStream(streamData2.get())); SkDynamicMemoryWStream compressedByteStream; SkDeflateWStream deflateWStream(&compressedByteStream); deflateWStream.write(streamBytes2, strlen(streamBytes2)); deflateWStream.finalize(); SkDynamicMemoryWStream expected; expected.writeText("<</Filter /FlateDecode\n/Length 116>> stream\n"); compressedByteStream.writeToStream(&expected); compressedByteStream.reset(); expected.writeText("\nendstream"); SkAutoDataUnref expectedResultData2(expected.copyToData()); SkString result = emit_to_string(*stream); ASSERT_EQL(reporter, result, (const char*)expectedResultData2->data(), expectedResultData2->size()); } }
DEF_TEST(DynamicMemoryWStream_detachAsData, r) { const char az[] = "abcdefghijklmnopqrstuvwxyz"; const unsigned N = 40000; SkDynamicMemoryWStream dmws; for (unsigned i = 0; i < N; ++i) { dmws.writeText(az); } REPORTER_ASSERT(r, dmws.bytesWritten() == N * strlen(az)); auto data = dmws.detachAsData(); REPORTER_ASSERT(r, data->size() == N * strlen(az)); const uint8_t* ptr = data->bytes(); for (unsigned i = 0; i < N; ++i) { if (0 != memcmp(ptr, az, strlen(az))) { ERRORF(r, "detachAsData() memcmp failed"); return; } ptr += strlen(az); } }