[debugger] Handle '\0' and such in json strings.

This allows mskps produced with Chromium to be displayed in the
debugger. Previously, the debugger would produce invalid json if any
string contained characters which needed to be escaped. The debugger
also treated all strings like NULL terminated strings, but json is
Unicode based and code point U+0000 is a perfectly good code point.

Change-Id: I28150bad666b02be9f1e4af4078a4ca1e65bf000
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/549098
Commit-Queue: Ben Wagner <bungeman@google.com>
Reviewed-by: Herb Derby <herb@google.com>
This commit is contained in:
Ben Wagner 2022-06-10 16:12:08 -04:00 committed by SkCQ
parent 3d6009ef26
commit f15f78c905
20 changed files with 210 additions and 159 deletions

View File

@ -1229,14 +1229,14 @@ public:
}
void fillCurrentOptions(NanoJSONResultsWriter& log) const {
log.appendString("source_type", fSourceType);
log.appendString("bench_type", fBenchType);
log.appendCString("source_type", fSourceType);
log.appendCString("bench_type", fBenchType);
if (0 == strcmp(fSourceType, "skp")) {
log.appendString("clip",
SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop,
fClip.fRight, fClip.fBottom).c_str());
fClip.fRight, fClip.fBottom));
SkASSERT_RELEASE(fCurrentScale < fScales.count()); // debugging paranoia
log.appendString("scale", SkStringPrintf("%.2g", fScales[fCurrentScale]).c_str());
log.appendString("scale", SkStringPrintf("%.2g", fScales[fCurrentScale]));
}
}
@ -1371,7 +1371,7 @@ int main(int argc, char** argv) {
return 1;
}
for (int i = 1; i < FLAGS_properties.count(); i += 2) {
log.appendString(FLAGS_properties[i-1], FLAGS_properties[i]);
log.appendCString(FLAGS_properties[i-1], FLAGS_properties[i]);
}
if (1 == FLAGS_key.count() % 2) {
@ -1381,7 +1381,7 @@ int main(int argc, char** argv) {
if (FLAGS_key.count()) {
log.beginObject("key");
for (int i = 1; i < FLAGS_key.count(); i += 2) {
log.appendString(FLAGS_key[i - 1], FLAGS_key[i]);
log.appendCString(FLAGS_key[i - 1], FLAGS_key[i]);
}
log.endObject(); // key
}
@ -1541,7 +1541,7 @@ int main(int argc, char** argv) {
log.beginObject(config);
log.beginObject("options");
log.appendString("name", bench->getName());
log.appendCString("name", bench->getName());
benchStream.fillCurrentOptions(log);
log.endObject(); // options

View File

@ -46,12 +46,12 @@ void JsonWriter::DumpJson(const char* dir,
writer.beginObject(); // root
for (int i = 1; i < properties.count(); i += 2) {
writer.appendString(properties[i-1], properties[i]);
writer.appendCString(properties[i-1], properties[i]);
}
writer.beginObject("key");
for (int i = 1; i < key.count(); i += 2) {
writer.appendString(key[i-1], key[i]);
writer.appendCString(key[i-1], key[i]);
}
writer.endObject();
@ -67,27 +67,27 @@ void JsonWriter::DumpJson(const char* dir,
writer.beginObject();
writer.beginObject("key");
writer.appendString("name" , gBitmapResults[i].name.c_str());
writer.appendString("config" , gBitmapResults[i].config.c_str());
writer.appendString("source_type", gBitmapResults[i].sourceType.c_str());
writer.appendString("name" , gBitmapResults[i].name);
writer.appendString("config" , gBitmapResults[i].config);
writer.appendString("source_type", gBitmapResults[i].sourceType);
// Source options only need to be part of the key if they exist.
// Source type by source type, we either always set options or never set options.
if (!gBitmapResults[i].sourceOptions.isEmpty()) {
writer.appendString("source_options", gBitmapResults[i].sourceOptions.c_str());
writer.appendString("source_options", gBitmapResults[i].sourceOptions);
}
writer.endObject(); // key
writer.beginObject("options");
writer.appendString("ext" , gBitmapResults[i].ext.c_str());
writer.appendString("gamut", gBitmapResults[i].gamut.c_str());
writer.appendString("transfer_fn", gBitmapResults[i].transferFn.c_str());
writer.appendString("color_type", gBitmapResults[i].colorType.c_str());
writer.appendString("alpha_type", gBitmapResults[i].alphaType.c_str());
writer.appendString("color_depth", gBitmapResults[i].colorDepth.c_str());
writer.appendString("ext" , gBitmapResults[i].ext);
writer.appendString("gamut", gBitmapResults[i].gamut);
writer.appendString("transfer_fn", gBitmapResults[i].transferFn);
writer.appendString("color_type", gBitmapResults[i].colorType);
writer.appendString("alpha_type", gBitmapResults[i].alphaType);
writer.appendString("color_depth", gBitmapResults[i].colorDepth);
writer.endObject(); // options
writer.appendString("md5", gBitmapResults[i].md5.c_str());
writer.appendString("md5", gBitmapResults[i].md5);
writer.endObject(); // 1 result
}

View File

@ -35,17 +35,17 @@ public:
SkStrSplit(s.c_str(), "\n", kStrict_SkStrSplitMode, &lines);
fWriter.beginArray(name);
for (const auto& line : lines) {
fWriter.appendString(line.c_str());
fWriter.appendString(line);
}
fWriter.endArray();
} else {
fWriter.appendString(name, s.c_str());
fWriter.appendString(name, s);
}
}
// Compound types
void visit(sk_sp<SkReflected>& e, const SkReflected::Type* baseType) override {
fWriter.appendString("Type", e ? e->getType()->fName : "Null");
fWriter.appendCString("Type", e ? e->getType()->fName : "Null");
}
void enterObject(const char* name) override { fWriter.beginObject(name); }

View File

@ -178,7 +178,7 @@ static void skrect_to_json(SkJSONWriter& writer, const char* name, const SkRect&
void GrAuditTrail::Op::toJson(SkJSONWriter& writer) const {
writer.beginObject();
writer.appendString("Name", fName.c_str());
writer.appendString("Name", fName);
writer.appendS32("ClientID", fClientID);
writer.appendS32("OpsTaskID", fOpsTaskID);
writer.appendS32("ChildID", fChildID);
@ -186,7 +186,7 @@ void GrAuditTrail::Op::toJson(SkJSONWriter& writer) const {
if (fStackTrace.count()) {
writer.beginArray("Stack");
for (int i = 0; i < fStackTrace.count(); i++) {
writer.appendString(fStackTrace[i].c_str());
writer.appendString(fStackTrace[i]);
}
writer.endArray();
}

View File

@ -266,9 +266,9 @@ void GrCaps::dumpJSON(SkJSONWriter* writer) const {
static_assert(2 == kAdvancedCoherent_BlendEquationSupport);
static_assert(SK_ARRAY_COUNT(kBlendEquationSupportNames) == kLast_BlendEquationSupport + 1);
writer->appendString("Blend Equation Support",
kBlendEquationSupportNames[fBlendEquationSupport]);
writer->appendString("Map Buffer Support", map_flags_to_string(fMapBufferFlags).c_str());
writer->appendCString("Blend Equation Support",
kBlendEquationSupportNames[fBlendEquationSupport]);
writer->appendString("Map Buffer Support", map_flags_to_string(fMapBufferFlags));
this->onDumpJSON(writer);

View File

@ -968,7 +968,7 @@ SkString GrDirectContext::dump() const {
SkJSONWriter writer(&stream, SkJSONWriter::Mode::kPretty);
writer.beginObject();
writer.appendString("backend", GrBackendApiToStr(this->backend()));
writer.appendCString("backend", GrBackendApiToStr(this->backend()));
writer.appendName("caps");
this->caps()->dumpJSON(&writer);

View File

@ -78,8 +78,8 @@ void GrShaderCaps::dumpJSON(SkJSONWriter* writer) const {
writer->appendBool("Use node pools", fUseNodePools);
writer->appendS32("Max FS Samplers", fMaxFragmentSamplers);
writer->appendString("Advanced blend equation interaction",
kAdvBlendEqInteractionStr[fAdvBlendEqInteraction]);
writer->appendCString("Advanced blend equation interaction",
kAdvBlendEqInteractionStr[fAdvBlendEqInteraction]);
writer->endObject();
}

View File

@ -1193,10 +1193,10 @@ void GrGLCaps::onDumpJSON(SkJSONWriter* writer) const {
static_assert(SK_ARRAY_COUNT(kMapBufferTypeStr) == kLast_MapBufferType + 1);
writer->appendBool("Core Profile", fIsCoreProfile);
writer->appendString("MSAA Type", kMSFBOExtStr[fMSFBOType]);
writer->appendString("Invalidate FB Type", kInvalidateFBTypeStr[fInvalidateFBType]);
writer->appendString("Map Buffer Type", kMapBufferTypeStr[fMapBufferType]);
writer->appendString("Multi Draw Type", multi_draw_type_name(fMultiDrawType));
writer->appendCString("MSAA Type", kMSFBOExtStr[fMSFBOType]);
writer->appendCString("Invalidate FB Type", kInvalidateFBTypeStr[fInvalidateFBType]);
writer->appendCString("Map Buffer Type", kMapBufferTypeStr[fMapBufferType]);
writer->appendCString("Multi Draw Type", multi_draw_type_name(fMultiDrawType));
writer->appendS32("Max FS Uniform Vectors", fMaxFragmentUniformVectors);
writer->appendBool("Pack Flip Y support", fPackFlipYSupport);

View File

@ -159,7 +159,7 @@ void GrGLExtensions::add(const char ext[]) {
void GrGLExtensions::dumpJSON(SkJSONWriter* writer) const {
writer->beginArray();
for (int i = 0; i < fStrings.count(); ++i) {
writer->appendString(fStrings[i].c_str());
writer->appendString(fStrings[i]);
}
writer->endArray();
}

View File

@ -4191,13 +4191,13 @@ void GrGLGpu::onDumpJSON(SkJSONWriter* writer) const {
const GrGLubyte* str;
GL_CALL_RET(str, GetString(GR_GL_VERSION));
writer->appendString("GL_VERSION", (const char*)(str));
writer->appendCString("GL_VERSION", (const char*)(str));
GL_CALL_RET(str, GetString(GR_GL_RENDERER));
writer->appendString("GL_RENDERER", (const char*)(str));
writer->appendCString("GL_RENDERER", (const char*)(str));
GL_CALL_RET(str, GetString(GR_GL_VENDOR));
writer->appendString("GL_VENDOR", (const char*)(str));
writer->appendCString("GL_VENDOR", (const char*)(str));
GL_CALL_RET(str, GetString(GR_GL_SHADING_LANGUAGE_VERSION));
writer->appendString("GL_SHADING_LANGUAGE_VERSION", (const char*)(str));
writer->appendCString("GL_SHADING_LANGUAGE_VERSION", (const char*)(str));
writer->appendName("extensions");
glInterface()->fExtensions.dumpJSON(writer);

View File

@ -1241,13 +1241,13 @@ void GrMtlCaps::onDumpJSON(SkJSONWriter* writer) const {
switch (fGPUFamily) {
case GPUFamily::kMac:
writer->appendString("GPU Family", "Mac");
writer->appendNString("GPU Family", "Mac");
break;
case GPUFamily::kApple:
writer->appendString("GPU Family", "Apple");
writer->appendNString("GPU Family", "Apple");
break;
default:
writer->appendString("GPU Family", "unknown");
writer->appendNString("GPU Family", "unknown");
break;
}
writer->appendS32("Family Group", fFamilyGroup);

View File

@ -1751,7 +1751,7 @@ void GrMtlGpu::onDumpJSON(SkJSONWriter* writer) const {
writer->beginObject("Metal GPU");
writer->beginObject("Device");
writer->appendString("name", fDevice.name.UTF8String);
writer->appendCString("name", fDevice.name.UTF8String);
#ifdef SK_BUILD_FOR_MAC
if (@available(macOS 10.11, *)) {
writer->appendBool("isHeadless", fDevice.isHeadless);
@ -1768,19 +1768,19 @@ void GrMtlGpu::onDumpJSON(SkJSONWriter* writer) const {
if (@available(macOS 10.15, *)) {
switch (fDevice.location) {
case MTLDeviceLocationBuiltIn:
writer->appendString("location", "builtIn");
writer->appendNString("location", "builtIn");
break;
case MTLDeviceLocationSlot:
writer->appendString("location", "slot");
writer->appendNString("location", "slot");
break;
case MTLDeviceLocationExternal:
writer->appendString("location", "external");
writer->appendNString("location", "external");
break;
case MTLDeviceLocationUnspecified:
writer->appendString("location", "unspecified");
writer->appendNString("location", "unspecified");
break;
default:
writer->appendString("location", "unknown");
writer->appendNString("location", "unknown");
break;
}
writer->appendU64("locationNumber", fDevice.locationNumber);
@ -1844,27 +1844,27 @@ void GrMtlGpu::onDumpJSON(SkJSONWriter* writer) const {
if (@available(macOS 10.13, iOS 11.0, *)) {
switch (fDevice.readWriteTextureSupport) {
case MTLReadWriteTextureTier1:
writer->appendString("readWriteTextureSupport", "tier1");
writer->appendNString("readWriteTextureSupport", "tier1");
break;
case MTLReadWriteTextureTier2:
writer->appendString("readWriteTextureSupport", "tier2");
writer->appendNString("readWriteTextureSupport", "tier2");
break;
case MTLReadWriteTextureTierNone:
writer->appendString("readWriteTextureSupport", "tierNone");
writer->appendNString("readWriteTextureSupport", "tierNone");
break;
default:
writer->appendString("readWriteTextureSupport", "unknown");
writer->appendNString("readWriteTextureSupport", "unknown");
break;
}
switch (fDevice.argumentBuffersSupport) {
case MTLArgumentBuffersTier1:
writer->appendString("argumentBuffersSupport", "tier1");
writer->appendNString("argumentBuffersSupport", "tier1");
break;
case MTLArgumentBuffersTier2:
writer->appendString("argumentBuffersSupport", "tier2");
writer->appendNString("argumentBuffersSupport", "tier2");
break;
default:
writer->appendString("argumentBuffersSupport", "unknown");
writer->appendNString("argumentBuffersSupport", "unknown");
break;
}
}
@ -1878,7 +1878,7 @@ void GrMtlGpu::onDumpJSON(SkJSONWriter* writer) const {
#endif
writer->endObject();
writer->appendString("queue", fQueue.label.UTF8String);
writer->appendCString("queue", fQueue.label.UTF8String);
writer->appendBool("disconnected", fDisconnected);
writer->endObject();

View File

@ -204,11 +204,11 @@ void SkVMDebugTrace::writeTrace(SkWStream* w) const {
SkJSONWriter json(w);
json.beginObject(); // root
json.appendString("version", kTraceVersion);
json.appendNString("version", kTraceVersion);
json.beginArray("source");
for (const std::string& line : fSource) {
json.appendString(line.c_str());
json.appendString(line);
}
json.endArray(); // code
@ -218,7 +218,7 @@ void SkVMDebugTrace::writeTrace(SkWStream* w) const {
const SkVMSlotInfo& info = fSlotInfo[index];
json.beginObject();
json.appendString("name", info.name.c_str());
json.appendString("name", info.name.data(), info.name.size());
json.appendS32("columns", info.columns);
json.appendS32("rows", info.rows);
json.appendS32("index", info.componentIndex);
@ -240,7 +240,7 @@ void SkVMDebugTrace::writeTrace(SkWStream* w) const {
const SkVMFunctionInfo& info = fFuncInfo[index];
json.beginObject();
json.appendString("name", info.name.c_str());
json.appendString("name", info.name);
json.endObject();
}

View File

@ -9,9 +9,11 @@
#define SkJSONWriter_DEFINED
#include "include/core/SkStream.h"
#include "include/core/SkString.h"
#include "include/core/SkTypes.h"
#include "include/private/SkNoncopyable.h"
#include "include/private/SkTArray.h"
#include "src/utils/SkUTF.h"
#include <string.h>
@ -168,12 +170,15 @@ public:
* - Between beginArray() and endArray() -or-
* - Between beginObject() and endObject(), after calling appendName()
*/
void appendString(const char* value) {
void appendString(const char* value, size_t size) {
this->beginValue();
this->write("\"", 1);
if (value) {
while (*value) {
switch (*value) {
char const * const end = value + size;
while (value < end) {
char const * next = value;
SkUnichar u = SkUTF::NextUTF8(&next, end);
switch (u) {
case '"': this->write("\\\"", 2); break;
case '\\': this->write("\\\\", 2); break;
case '\b': this->write("\\b", 2); break;
@ -181,13 +186,41 @@ public:
case '\n': this->write("\\n", 2); break;
case '\r': this->write("\\r", 2); break;
case '\t': this->write("\\t", 2); break;
default: this->write(value, 1); break;
default: {
if (u < 0) {
next = value + 1;
SkString s("\\u");
s.appendHex((unsigned char)*value, 4);
this->write(s.c_str(), s.size());
} else if (u < 0x20) {
SkString s("\\u");
s.appendHex(u, 4);
this->write(s.c_str(), s.size());
} else {
this->write(value, next - value);
}
} break;
}
value++;
value = next;
}
}
this->write("\"", 1);
}
void appendString(const SkString& value) {
this->appendString(value.c_str(), value.size());
}
// Avoid the non-explicit converting constructor from char*
template <class T, std::enable_if_t<std::is_same_v<T,std::string>,bool> = false>
void appendString(const T& value) {
this->appendString(value.data(), value.size());
}
template <size_t N> inline void appendNString(char const (&value)[N]) {
static_assert(N > 0);
this->appendString(value, N-1);
}
void appendCString(const char* value) {
this->appendString(value, value ? strlen(value) : 0);
}
void appendPointer(const void* value) { this->beginValue(); this->appendf("\"%p\"", value); }
void appendBool(bool value) {
@ -215,6 +248,29 @@ public:
void appendHexU32(uint32_t value) { this->beginValue(); this->appendf("\"0x%x\"", value); }
void appendHexU64(uint64_t value);
void appendString(const char* name, const char* value, size_t size) {
this->appendName(name);
this->appendString(value, size);
}
void appendString(const char* name, const SkString& value) {
this->appendName(name);
this->appendString(value.c_str(), value.size());
}
// Avoid the non-explicit converting constructor from char*
template <class T, std::enable_if_t<std::is_same_v<T,std::string>,bool> = false>
void appendString(const char* name, const T& value) {
this->appendName(name);
this->appendString(value.data(), value.size());
}
template <size_t N> inline void appendNString(const char* name, char const (&value)[N]) {
static_assert(N > 0);
this->appendName(name);
this->appendString(value, N-1);
}
void appendCString(const char* name, const char* value) {
this->appendName(name);
this->appendString(value, value ? strlen(value) : 0);
}
#define DEFINE_NAMED_APPEND(function, type) \
void function(const char* name, type value) { this->appendName(name); this->function(value); }
@ -222,7 +278,6 @@ public:
* Functions for adding named values of various types. These add a name field, so must be
* called between beginObject() and endObject().
*/
DEFINE_NAMED_APPEND(appendString, const char *)
DEFINE_NAMED_APPEND(appendPointer, const void *)
DEFINE_NAMED_APPEND(appendBool, bool)
DEFINE_NAMED_APPEND(appendS32, int32_t)

View File

@ -78,7 +78,7 @@ void SkShaperJSONWriter::commitRunBuffer(const SkShaper::RunHandler::RunInfo& in
// Font name
SkString fontName;
info.fFont.getTypeface()->getFamilyName(&fontName);
fJSONWriter->appendString("font name", fontName.c_str());
fJSONWriter->appendString("font name", fontName);
// Font size
fJSONWriter->appendFloat("font size", info.fFont.getSize());
@ -86,12 +86,12 @@ void SkShaperJSONWriter::commitRunBuffer(const SkShaper::RunHandler::RunInfo& in
if (info.fBidiLevel > 0) {
std::string bidiType = info.fBidiLevel % 2 == 0 ? "left-to-right" : "right-to-left";
std::string bidiOutput = bidiType + " lvl " + std::to_string(info.fBidiLevel);
fJSONWriter->appendString("BiDi", bidiOutput.c_str());
fJSONWriter->appendString("BiDi", bidiOutput);
}
if (is_one_to_one(fUTF8.c_str(), info.utf8Range.begin(), info.utf8Range.end(), fClusters)) {
std::string utf8{&fUTF8[info.utf8Range.begin()], info.utf8Range.size()};
fJSONWriter->appendString("UTF8", utf8.c_str());
fJSONWriter->appendString("UTF8", utf8);
fJSONWriter->beginArray("glyphs", false);
for (auto glyphID : fGlyphs) {
@ -233,7 +233,7 @@ void SkShaperJSONWriter::displayMToN(size_t codePointCount,
std::string clusterName = "cluster " + nString + " to " + mString;
fJSONWriter->beginObject(clusterName.c_str(), true);
std::string utf8String{utf8.data(), utf8.size()};
fJSONWriter->appendString("UTF", utf8String.c_str());
fJSONWriter->appendString("UTF", utf8String);
fJSONWriter->beginArray("glyphsIDs", false);
for (auto glyphID : glyphIDs) {
fJSONWriter->appendU32(glyphID);

View File

@ -276,7 +276,7 @@ const char* DrawCommand::GetCommandString(OpType type) {
}
void DrawCommand::toJSON(SkJSONWriter& writer, UrlDataManager& urlDataManager) const {
writer.appendString(DEBUGCANVAS_ATTRIBUTE_COMMAND, this->GetCommandString(fOpType));
writer.appendCString(DEBUGCANVAS_ATTRIBUTE_COMMAND, this->GetCommandString(fOpType));
writer.appendBool(DEBUGCANVAS_ATTRIBUTE_VISIBLE, this->isVisible());
}
@ -385,7 +385,7 @@ void render_shadow(SkCanvas* canvas, const SkPath& path, SkDrawShadowRec rec) {
void apply_paint_blend_mode(const SkPaint& paint, SkJSONWriter& writer) {
const auto mode = paint.getBlendMode_or(SkBlendMode::kSrcOver);
if (mode != SkBlendMode::kSrcOver) {
writer.appendString(DEBUGCANVAS_ATTRIBUTE_BLENDMODE, SkBlendMode_Name(mode));
writer.appendCString(DEBUGCANVAS_ATTRIBUTE_BLENDMODE, SkBlendMode_Name(mode));
}
}
@ -489,23 +489,23 @@ void DrawCommand::MakeJsonPath(SkJSONWriter& writer, const SkPath& path) {
SkDynamicMemoryWStream wstream;
path.dump(&wstream, false);
auto data = wstream.detachAsData();
SkString dumpString((char*)data->bytes(), data->size());
writer.appendString(DEBUGCANVAS_ATTRIBUTE_DUMP, dumpString.c_str());
writer.appendString(DEBUGCANVAS_ATTRIBUTE_DUMP,
static_cast<const char*>(data->data()), data->size());
switch (path.getFillType()) {
case SkPathFillType::kWinding:
writer.appendString(DEBUGCANVAS_ATTRIBUTE_FILLTYPE, DEBUGCANVAS_FILLTYPE_WINDING);
writer.appendNString(DEBUGCANVAS_ATTRIBUTE_FILLTYPE, DEBUGCANVAS_FILLTYPE_WINDING);
break;
case SkPathFillType::kEvenOdd:
writer.appendString(DEBUGCANVAS_ATTRIBUTE_FILLTYPE, DEBUGCANVAS_FILLTYPE_EVENODD);
writer.appendNString(DEBUGCANVAS_ATTRIBUTE_FILLTYPE, DEBUGCANVAS_FILLTYPE_EVENODD);
break;
case SkPathFillType::kInverseWinding:
writer.appendString(DEBUGCANVAS_ATTRIBUTE_FILLTYPE,
DEBUGCANVAS_FILLTYPE_INVERSEWINDING);
writer.appendNString(DEBUGCANVAS_ATTRIBUTE_FILLTYPE,
DEBUGCANVAS_FILLTYPE_INVERSEWINDING);
break;
case SkPathFillType::kInverseEvenOdd:
writer.appendString(DEBUGCANVAS_ATTRIBUTE_FILLTYPE,
DEBUGCANVAS_FILLTYPE_INVERSEEVENODD);
writer.appendNString(DEBUGCANVAS_ATTRIBUTE_FILLTYPE,
DEBUGCANVAS_FILLTYPE_INVERSEEVENODD);
break;
}
writer.beginArray(DEBUGCANVAS_ATTRIBUTE_VERBS);
@ -514,7 +514,7 @@ void DrawCommand::MakeJsonPath(SkJSONWriter& writer, const SkPath& path) {
SkPath::Verb verb;
while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
if (verb == SkPath::kClose_Verb) {
writer.appendString(DEBUGCANVAS_VERB_CLOSE);
writer.appendNString(DEBUGCANVAS_VERB_CLOSE);
continue;
}
writer.beginObject(); // verb
@ -630,8 +630,8 @@ void DrawCommand::flatten(const SkFlattenable* flattenable,
buffer.writeToMemory(data);
SkString url =
encode_data(data, buffer.bytesWritten(), "application/octet-stream", urlDataManager);
writer.appendString(DEBUGCANVAS_ATTRIBUTE_NAME, flattenable->getTypeName());
writer.appendString(DEBUGCANVAS_ATTRIBUTE_DATA, url.c_str());
writer.appendCString(DEBUGCANVAS_ATTRIBUTE_NAME, flattenable->getTypeName());
writer.appendString(DEBUGCANVAS_ATTRIBUTE_DATA, url);
writer.beginObject(DEBUGCANVAS_ATTRIBUTE_VALUES);
JsonWriteBuffer jsonBuffer(&writer, &urlDataManager);
@ -696,8 +696,8 @@ bool DrawCommand::flatten(const SkImage& image,
writer.endObject();
return false;
}
SkString url = encode_data(encoded->data(), encoded->size(), "image/png", urlDataManager);
writer.appendString(DEBUGCANVAS_ATTRIBUTE_DATA, url.c_str());
SkString url = encode_data(encoded->data(), encoded->size(), "image/png", urlDataManager);
writer.appendString(DEBUGCANVAS_ATTRIBUTE_DATA, url);
writer.endObject();
return true;
}
@ -727,8 +727,8 @@ bool DrawCommand::flatten(const SkBitmap& bitmap,
SkJSONWriter& writer,
UrlDataManager& urlDataManager) {
sk_sp<SkImage> image(bitmap.asImage());
writer.appendString(DEBUGCANVAS_ATTRIBUTE_COLOR, color_type_name(bitmap.colorType()));
writer.appendString(DEBUGCANVAS_ATTRIBUTE_ALPHA, alpha_type_name(bitmap.alphaType()));
writer.appendCString(DEBUGCANVAS_ATTRIBUTE_COLOR, color_type_name(bitmap.colorType()));
writer.appendCString(DEBUGCANVAS_ATTRIBUTE_ALPHA, alpha_type_name(bitmap.alphaType()));
// Image will appear to have no uses, TODO(nifong): provide the user with a useful explanation
bool success = flatten(*image, writer, urlDataManager);
return success;
@ -739,16 +739,16 @@ static void apply_font_hinting(const SkFont& font, SkJSONWriter& writer) {
if (hinting != SkPaintDefaults_Hinting) {
switch (hinting) {
case SkFontHinting::kNone:
writer.appendString(DEBUGCANVAS_ATTRIBUTE_HINTING, DEBUGCANVAS_HINTING_NONE);
writer.appendNString(DEBUGCANVAS_ATTRIBUTE_HINTING, DEBUGCANVAS_HINTING_NONE);
break;
case SkFontHinting::kSlight:
writer.appendString(DEBUGCANVAS_ATTRIBUTE_HINTING, DEBUGCANVAS_HINTING_SLIGHT);
writer.appendNString(DEBUGCANVAS_ATTRIBUTE_HINTING, DEBUGCANVAS_HINTING_SLIGHT);
break;
case SkFontHinting::kNormal:
writer.appendString(DEBUGCANVAS_ATTRIBUTE_HINTING, DEBUGCANVAS_HINTING_NORMAL);
writer.appendNString(DEBUGCANVAS_ATTRIBUTE_HINTING, DEBUGCANVAS_HINTING_NORMAL);
break;
case SkFontHinting::kFull:
writer.appendString(DEBUGCANVAS_ATTRIBUTE_HINTING, DEBUGCANVAS_HINTING_FULL);
writer.appendNString(DEBUGCANVAS_ATTRIBUTE_HINTING, DEBUGCANVAS_HINTING_FULL);
break;
}
}
@ -757,13 +757,14 @@ static void apply_font_hinting(const SkFont& font, SkJSONWriter& writer) {
static void apply_font_edging(const SkFont& font, SkJSONWriter& writer) {
switch (font.getEdging()) {
case SkFont::Edging::kAlias:
writer.appendString(DEBUGCANVAS_ATTRIBUTE_EDGING, DEBUGCANVAS_EDGING_ALIAS);
writer.appendNString(DEBUGCANVAS_ATTRIBUTE_EDGING, DEBUGCANVAS_EDGING_ALIAS);
break;
case SkFont::Edging::kAntiAlias:
writer.appendString(DEBUGCANVAS_ATTRIBUTE_EDGING, DEBUGCANVAS_EDGING_ANTIALIAS);
writer.appendNString(DEBUGCANVAS_ATTRIBUTE_EDGING, DEBUGCANVAS_EDGING_ANTIALIAS);
break;
case SkFont::Edging::kSubpixelAntiAlias:
writer.appendString(DEBUGCANVAS_ATTRIBUTE_EDGING, DEBUGCANVAS_EDGING_SUBPIXELANTIALIAS);
writer.appendNString(DEBUGCANVAS_ATTRIBUTE_EDGING,
DEBUGCANVAS_EDGING_SUBPIXELANTIALIAS);
break;
}
}
@ -781,11 +782,11 @@ static void apply_paint_style(const SkPaint& paint, SkJSONWriter& writer) {
if (style != SkPaint::kFill_Style) {
switch (style) {
case SkPaint::kStroke_Style: {
writer.appendString(DEBUGCANVAS_ATTRIBUTE_STYLE, DEBUGCANVAS_STYLE_STROKE);
writer.appendNString(DEBUGCANVAS_ATTRIBUTE_STYLE, DEBUGCANVAS_STYLE_STROKE);
break;
}
case SkPaint::kStrokeAndFill_Style: {
writer.appendString(DEBUGCANVAS_ATTRIBUTE_STYLE, DEBUGCANVAS_STYLE_STROKEANDFILL);
writer.appendNString(DEBUGCANVAS_ATTRIBUTE_STYLE, DEBUGCANVAS_STYLE_STROKEANDFILL);
break;
}
default: SkASSERT(false);
@ -798,13 +799,13 @@ static void apply_paint_cap(const SkPaint& paint, SkJSONWriter& writer) {
if (cap != SkPaint::kDefault_Cap) {
switch (cap) {
case SkPaint::kButt_Cap:
writer.appendString(DEBUGCANVAS_ATTRIBUTE_CAP, DEBUGCANVAS_CAP_BUTT);
writer.appendNString(DEBUGCANVAS_ATTRIBUTE_CAP, DEBUGCANVAS_CAP_BUTT);
break;
case SkPaint::kRound_Cap:
writer.appendString(DEBUGCANVAS_ATTRIBUTE_CAP, DEBUGCANVAS_CAP_ROUND);
writer.appendNString(DEBUGCANVAS_ATTRIBUTE_CAP, DEBUGCANVAS_CAP_ROUND);
break;
case SkPaint::kSquare_Cap:
writer.appendString(DEBUGCANVAS_ATTRIBUTE_CAP, DEBUGCANVAS_CAP_SQUARE);
writer.appendNString(DEBUGCANVAS_ATTRIBUTE_CAP, DEBUGCANVAS_CAP_SQUARE);
break;
default: SkASSERT(false);
}
@ -816,13 +817,13 @@ static void apply_paint_join(const SkPaint& paint, SkJSONWriter& writer) {
if (join != SkPaint::kDefault_Join) {
switch (join) {
case SkPaint::kMiter_Join:
writer.appendString(DEBUGCANVAS_ATTRIBUTE_STROKEJOIN, DEBUGCANVAS_MITER_JOIN);
writer.appendNString(DEBUGCANVAS_ATTRIBUTE_STROKEJOIN, DEBUGCANVAS_MITER_JOIN);
break;
case SkPaint::kRound_Join:
writer.appendString(DEBUGCANVAS_ATTRIBUTE_STROKEJOIN, DEBUGCANVAS_ROUND_JOIN);
writer.appendNString(DEBUGCANVAS_ATTRIBUTE_STROKEJOIN, DEBUGCANVAS_ROUND_JOIN);
break;
case SkPaint::kBevel_Join:
writer.appendString(DEBUGCANVAS_ATTRIBUTE_STROKEJOIN, DEBUGCANVAS_BEVEL_JOIN);
writer.appendNString(DEBUGCANVAS_ATTRIBUTE_STROKEJOIN, DEBUGCANVAS_BEVEL_JOIN);
break;
default: SkASSERT(false);
}
@ -840,16 +841,16 @@ static void apply_paint_maskfilter(const SkPaint& paint,
writer.appendFloat(DEBUGCANVAS_ATTRIBUTE_SIGMA, blurRec.fSigma);
switch (blurRec.fStyle) {
case SkBlurStyle::kNormal_SkBlurStyle:
writer.appendString(DEBUGCANVAS_ATTRIBUTE_STYLE, DEBUGCANVAS_BLURSTYLE_NORMAL);
writer.appendNString(DEBUGCANVAS_ATTRIBUTE_STYLE, DEBUGCANVAS_BLURSTYLE_NORMAL);
break;
case SkBlurStyle::kSolid_SkBlurStyle:
writer.appendString(DEBUGCANVAS_ATTRIBUTE_STYLE, DEBUGCANVAS_BLURSTYLE_SOLID);
writer.appendNString(DEBUGCANVAS_ATTRIBUTE_STYLE, DEBUGCANVAS_BLURSTYLE_SOLID);
break;
case SkBlurStyle::kOuter_SkBlurStyle:
writer.appendString(DEBUGCANVAS_ATTRIBUTE_STYLE, DEBUGCANVAS_BLURSTYLE_OUTER);
writer.appendNString(DEBUGCANVAS_ATTRIBUTE_STYLE, DEBUGCANVAS_BLURSTYLE_OUTER);
break;
case SkBlurStyle::kInner_SkBlurStyle:
writer.appendString(DEBUGCANVAS_ATTRIBUTE_STYLE, DEBUGCANVAS_BLURSTYLE_INNER);
writer.appendNString(DEBUGCANVAS_ATTRIBUTE_STYLE, DEBUGCANVAS_BLURSTYLE_INNER);
break;
default: SkASSERT(false);
}
@ -901,7 +902,7 @@ static void apply_font_typeface(const SkFont& font,
buffer.copyTo(data);
SkString url = encode_data(
data, buffer.bytesWritten(), "application/octet-stream", urlDataManager);
writer.appendString(DEBUGCANVAS_ATTRIBUTE_DATA, url.c_str());
writer.appendString(DEBUGCANVAS_ATTRIBUTE_DATA, url);
sk_free(data);
writer.endObject();
}
@ -1023,7 +1024,7 @@ void ClipPathCommand::toJSON(SkJSONWriter& writer, UrlDataManager& urlDataManage
INHERITED::toJSON(writer, urlDataManager);
writer.appendName(DEBUGCANVAS_ATTRIBUTE_PATH);
MakeJsonPath(writer, fPath);
writer.appendString(DEBUGCANVAS_ATTRIBUTE_REGIONOP, clipop_name(fOp));
writer.appendCString(DEBUGCANVAS_ATTRIBUTE_REGIONOP, clipop_name(fOp));
writer.appendBool(DEBUGCANVAS_ATTRIBUTE_ANTIALIAS, fDoAA);
}
@ -1039,7 +1040,7 @@ void ClipRegionCommand::toJSON(SkJSONWriter& writer, UrlDataManager& urlDataMana
INHERITED::toJSON(writer, urlDataManager);
writer.appendName(DEBUGCANVAS_ATTRIBUTE_REGION);
MakeJsonRegion(writer, fRegion);
writer.appendString(DEBUGCANVAS_ATTRIBUTE_REGIONOP, clipop_name(fOp));
writer.appendCString(DEBUGCANVAS_ATTRIBUTE_REGIONOP, clipop_name(fOp));
}
ClipRectCommand::ClipRectCommand(const SkRect& rect, SkClipOp op, bool doAA)
@ -1055,11 +1056,11 @@ void ClipRectCommand::toJSON(SkJSONWriter& writer, UrlDataManager& urlDataManage
INHERITED::toJSON(writer, urlDataManager);
writer.appendName(DEBUGCANVAS_ATTRIBUTE_COORDS);
MakeJsonRect(writer, fRect);
writer.appendString(DEBUGCANVAS_ATTRIBUTE_REGIONOP, clipop_name(fOp));
writer.appendCString(DEBUGCANVAS_ATTRIBUTE_REGIONOP, clipop_name(fOp));
writer.appendBool(DEBUGCANVAS_ATTRIBUTE_ANTIALIAS, fDoAA);
SkString desc;
writer.appendString(DEBUGCANVAS_ATTRIBUTE_SHORTDESC, str_append(&desc, fRect)->c_str());
writer.appendString(DEBUGCANVAS_ATTRIBUTE_SHORTDESC, *str_append(&desc, fRect));
}
ClipRRectCommand::ClipRRectCommand(const SkRRect& rrect, SkClipOp op, bool doAA)
@ -1080,7 +1081,7 @@ void ClipRRectCommand::toJSON(SkJSONWriter& writer, UrlDataManager& urlDataManag
INHERITED::toJSON(writer, urlDataManager);
writer.appendName(DEBUGCANVAS_ATTRIBUTE_COORDS);
make_json_rrect(writer, fRRect);
writer.appendString(DEBUGCANVAS_ATTRIBUTE_REGIONOP, clipop_name(fOp));
writer.appendCString(DEBUGCANVAS_ATTRIBUTE_REGIONOP, clipop_name(fOp));
writer.appendBool(DEBUGCANVAS_ATTRIBUTE_ANTIALIAS, fDoAA);
}
@ -1102,7 +1103,7 @@ bool ClipShaderCommand::render(SkCanvas* canvas) const {
void ClipShaderCommand::toJSON(SkJSONWriter& writer, UrlDataManager& urlDataManager) const {
INHERITED::toJSON(writer, urlDataManager);
apply_flattenable(DEBUGCANVAS_ATTRIBUTE_SHADER, fShader.get(), writer, urlDataManager);
writer.appendString(DEBUGCANVAS_ATTRIBUTE_REGIONOP, clipop_name(fOp));
writer.appendCString(DEBUGCANVAS_ATTRIBUTE_REGIONOP, clipop_name(fOp));
}
ResetClipCommand::ResetClipCommand() : INHERITED(kResetClip_OpType) {}
@ -1119,16 +1120,16 @@ namespace {
void writeMatrixType(SkJSONWriter& writer, const SkMatrix& m) {
switch (m.getType()) {
case SkMatrix::kTranslate_Mask:
writer.appendString(DEBUGCANVAS_ATTRIBUTE_SHORTDESC, " (translate)");
writer.appendNString(DEBUGCANVAS_ATTRIBUTE_SHORTDESC, " (translate)");
break;
case SkMatrix::kScale_Mask:
writer.appendString(DEBUGCANVAS_ATTRIBUTE_SHORTDESC, " (scale)");
writer.appendNString(DEBUGCANVAS_ATTRIBUTE_SHORTDESC, " (scale)");
break;
case SkMatrix::kAffine_Mask:
writer.appendString(DEBUGCANVAS_ATTRIBUTE_SHORTDESC, " (rotation or skew)");
writer.appendNString(DEBUGCANVAS_ATTRIBUTE_SHORTDESC, " (rotation or skew)");
break;
case SkMatrix::kPerspective_Mask:
writer.appendString(DEBUGCANVAS_ATTRIBUTE_SHORTDESC, " (perspective)");
writer.appendNString(DEBUGCANVAS_ATTRIBUTE_SHORTDESC, " (perspective)");
break;
default:
break;
@ -1171,16 +1172,14 @@ void DrawAnnotationCommand::toJSON(SkJSONWriter& writer, UrlDataManager& urlData
writer.appendName(DEBUGCANVAS_ATTRIBUTE_COORDS);
MakeJsonRect(writer, fRect);
writer.appendString("key", fKey.c_str());
writer.appendString("key", fKey);
if (fValue) {
writer.appendString("value", std::string(
static_cast<const char*>(fValue->data()), fValue->size()
).c_str());
writer.appendString("value", static_cast<const char*>(fValue->data()), fValue->size());
}
SkString desc;
str_append(&desc, fRect)->appendf(" %s", fKey.c_str());
writer.appendString(DEBUGCANVAS_ATTRIBUTE_SHORTDESC, desc.c_str());
writer.appendString(DEBUGCANVAS_ATTRIBUTE_SHORTDESC, desc);
}
////
@ -1234,16 +1233,16 @@ void DrawImageCommand::toJSON(SkJSONWriter& writer, UrlDataManager& urlDataManag
writer.appendS32(DEBUGCANVAS_ATTRIBUTE_HEIGHT, fImage->height());
switch (fImage->alphaType()) {
case kOpaque_SkAlphaType:
writer.appendString(DEBUGCANVAS_ATTRIBUTE_ALPHA, DEBUGCANVAS_ALPHATYPE_OPAQUE);
writer.appendNString(DEBUGCANVAS_ATTRIBUTE_ALPHA, DEBUGCANVAS_ALPHATYPE_OPAQUE);
break;
case kPremul_SkAlphaType:
writer.appendString(DEBUGCANVAS_ATTRIBUTE_ALPHA, DEBUGCANVAS_ALPHATYPE_PREMUL);
writer.appendNString(DEBUGCANVAS_ATTRIBUTE_ALPHA, DEBUGCANVAS_ALPHATYPE_PREMUL);
break;
case kUnpremul_SkAlphaType:
writer.appendString(DEBUGCANVAS_ATTRIBUTE_ALPHA, DEBUGCANVAS_ALPHATYPE_UNPREMUL);
writer.appendNString(DEBUGCANVAS_ATTRIBUTE_ALPHA, DEBUGCANVAS_ALPHATYPE_UNPREMUL);
break;
default:
writer.appendString(DEBUGCANVAS_ATTRIBUTE_ALPHA, DEBUGCANVAS_ALPHATYPE_UNKNOWN);
writer.appendNString(DEBUGCANVAS_ATTRIBUTE_ALPHA, DEBUGCANVAS_ALPHATYPE_UNKNOWN);
break;
}
}
@ -1291,7 +1290,7 @@ void DrawImageLatticeCommand::toJSON(SkJSONWriter& writer, UrlDataManager& urlDa
}
SkString desc;
writer.appendString(DEBUGCANVAS_ATTRIBUTE_SHORTDESC, str_append(&desc, fDst)->c_str());
writer.appendString(DEBUGCANVAS_ATTRIBUTE_SHORTDESC, *str_append(&desc, fDst));
}
DrawImageRectCommand::DrawImageRectCommand(const SkImage* image,
@ -1344,7 +1343,7 @@ void DrawImageRectCommand::toJSON(SkJSONWriter& writer, UrlDataManager& urlDataM
}
SkString desc;
writer.appendString(DEBUGCANVAS_ATTRIBUTE_SHORTDESC, str_append(&desc, fDst)->c_str());
writer.appendString(DEBUGCANVAS_ATTRIBUTE_SHORTDESC, *str_append(&desc, fDst));
}
DrawImageRectLayerCommand::DrawImageRectLayerCommand(DebugLayerManager* layerManager,
@ -1405,7 +1404,7 @@ void DrawImageRectLayerCommand::toJSON(SkJSONWriter& writer, UrlDataManager& url
}
SkString desc;
writer.appendString(DEBUGCANVAS_ATTRIBUTE_SHORTDESC, str_append(&desc, fDst)->c_str());
writer.appendString(DEBUGCANVAS_ATTRIBUTE_SHORTDESC, *str_append(&desc, fDst));
}
DrawOvalCommand::DrawOvalCommand(const SkRect& oval, const SkPaint& paint)
@ -1646,7 +1645,7 @@ bool DrawPointsCommand::render(SkCanvas* canvas) const {
void DrawPointsCommand::toJSON(SkJSONWriter& writer, UrlDataManager& urlDataManager) const {
INHERITED::toJSON(writer, urlDataManager);
writer.appendString(DEBUGCANVAS_ATTRIBUTE_MODE, pointmode_name(fMode));
writer.appendCString(DEBUGCANVAS_ATTRIBUTE_MODE, pointmode_name(fMode));
writer.beginArray(DEBUGCANVAS_ATTRIBUTE_POINTS);
for (int i = 0; i < fPts.count(); i++) {
MakeJsonPoint(writer, fPts[i]);
@ -1734,7 +1733,7 @@ void DrawTextBlobCommand::toJSON(SkJSONWriter& writer, UrlDataManager& urlDataMa
SkString desc;
// make the bounds local by applying the x,y
bounds.offset(fXPos, fYPos);
writer.appendString(DEBUGCANVAS_ATTRIBUTE_SHORTDESC, str_append(&desc, bounds)->c_str());
writer.appendString(DEBUGCANVAS_ATTRIBUTE_SHORTDESC, *str_append(&desc, bounds));
}
DrawPatchCommand::DrawPatchCommand(const SkPoint cubics[12],
@ -1803,7 +1802,7 @@ void DrawRectCommand::toJSON(SkJSONWriter& writer, UrlDataManager& urlDataManage
MakeJsonPaint(writer, fPaint, urlDataManager);
SkString desc;
writer.appendString(DEBUGCANVAS_ATTRIBUTE_SHORTDESC, str_append(&desc, fRect)->c_str());
writer.appendString(DEBUGCANVAS_ATTRIBUTE_SHORTDESC, *str_append(&desc, fRect));
}
DrawRRectCommand::DrawRRectCommand(const SkRRect& rrect, const SkPaint& paint)

View File

@ -35,7 +35,7 @@ void JsonWriteBuffer::writePad32(const void* data, size_t size) {
const uint8_t* bytes = reinterpret_cast<const uint8_t*>(data);
for (size_t i = 0; i < size; ++i) {
SkString hexByte = SkStringPrintf("%02x", bytes[i]);
fWriter->appendString(hexByte.c_str());
fWriter->appendString(hexByte);
}
fWriter->endArray();
}
@ -46,7 +46,7 @@ void JsonWriteBuffer::writeByteArray(const void* data, size_t size) {
const uint8_t* bytes = reinterpret_cast<const uint8_t*>(data);
for (size_t i = 0; i < size; ++i) {
SkString hexByte = SkStringPrintf("%02x", bytes[i]);
fWriter->appendString(hexByte.c_str());
fWriter->appendString(hexByte);
}
fWriter->endArray();
}
@ -91,7 +91,7 @@ void JsonWriteBuffer::writeUInt(uint32_t value) {
void JsonWriteBuffer::writeString(const char* value) {
this->append("string");
fWriter->appendString(value);
fWriter->appendCString(value);
}
void JsonWriteBuffer::writeFlattenable(const SkFlattenable* flattenable) {

View File

@ -229,7 +229,7 @@ sk_sp<SkData> Request::getJsonOps() {
SkJSONWriter writer(&stream, SkJSONWriter::Mode::kFast);
writer.beginObject(); // root
writer.appendString("mode", fGPUEnabled ? "gpu" : "cpu");
writer.appendCString("mode", fGPUEnabled ? "gpu" : "cpu");
writer.appendBool("drawGpuOpBounds", fDebugCanvas->getDrawGpuOpBounds());
writer.appendS32("colorMode", fColorMode);
fDebugCanvas->toJSON(writer, fUrlDataManager, canvas);

View File

@ -161,11 +161,11 @@ static void trace_value_to_json(SkJSONWriter* writer,
case TRACE_VALUE_TYPE_INT: writer->appendS64(value.as_int); break;
case TRACE_VALUE_TYPE_DOUBLE: writer->appendDouble(value.as_double); break;
case TRACE_VALUE_TYPE_POINTER: writer->appendPointer(value.as_pointer); break;
case TRACE_VALUE_TYPE_STRING: writer->appendString(value.as_string); break;
case TRACE_VALUE_TYPE_STRING: writer->appendCString(value.as_string); break;
case TRACE_VALUE_TYPE_COPY_STRING:
writer->appendString(stringTableBase + value.as_uint);
writer->appendCString(stringTableBase + value.as_uint);
break;
default: writer->appendString("<unknown type>"); break;
default: writer->appendNString("<unknown type>"); break;
}
}
@ -208,9 +208,8 @@ static void trace_event_to_json(SkJSONWriter* writer,
writer->beginObject();
char phaseString[2] = {traceEvent->fPhase, 0};
writer->appendString("ph", phaseString);
writer->appendString("name", traceEvent->fName);
writer->appendString("ph", &traceEvent->fPhase, 1);
writer->appendCString("name", traceEvent->fName);
if (0 != traceEvent->fID) {
// IDs are (almost) always pointers
writer->appendPointer("id", reinterpret_cast<void*>(traceEvent->fID));
@ -240,7 +239,7 @@ static void trace_event_to_json(SkJSONWriter* writer,
0 != strcmp(*baseTypeResolver->find(traceEvent->fID), traceEvent->fName)) {
// Special handling for snapshots where the name differs from creation.
writer->beginObject("snapshot");
writer->appendString("base_type", *baseTypeResolver->find(traceEvent->fID));
writer->appendCString("base_type", *baseTypeResolver->find(traceEvent->fID));
addedSnapshot = true;
}

View File

@ -2955,8 +2955,8 @@ static void WriteStateObject(SkJSONWriter& writer, const char* name, const char*
OptionsFunc&& optionsFunc) {
writer.beginObject();
{
writer.appendString(kName , name);
writer.appendString(kValue, value);
writer.appendCString(kName , name);
writer.appendCString(kValue, value);
writer.beginArray(kOptions);
{
@ -2984,7 +2984,7 @@ void Viewer::updateUIState() {
WriteStateObject(writer, kSlideStateName, fSlides[fCurrentSlide]->getName().c_str(),
[this](SkJSONWriter& writer) {
for(const auto& slide : fSlides) {
writer.appendString(slide->getName().c_str());
writer.appendString(slide->getName());
}
});
@ -2992,7 +2992,7 @@ void Viewer::updateUIState() {
WriteStateObject(writer, kBackendStateName, kBackendTypeStrings[fBackendType],
[](SkJSONWriter& writer) {
for (const auto& str : kBackendTypeStrings) {
writer.appendString(str);
writer.appendCString(str);
}
});
@ -3017,36 +3017,34 @@ void Viewer::updateUIState() {
[this](SkJSONWriter& writer) {
auto ctx = fWindow->directContext();
if (!ctx) {
writer.appendString("Software");
writer.appendNString("Software");
} else {
writer.appendString(gPathRendererNames[GpuPathRenderers::kDefault].c_str());
writer.appendString(gPathRendererNames[GpuPathRenderers::kDefault]);
#if SK_GPU_V1
if (fWindow->sampleCount() > 1 || FLAGS_dmsaa) {
const auto* caps = ctx->priv().caps();
if (skgpu::v1::AtlasPathRenderer::IsSupported(ctx)) {
writer.appendString(
gPathRendererNames[GpuPathRenderers::kAtlas].c_str());
writer.appendString(gPathRendererNames[GpuPathRenderers::kAtlas]);
}
if (skgpu::v1::TessellationPathRenderer::IsSupported(*caps)) {
writer.appendString(
gPathRendererNames[GpuPathRenderers::kTessellation].c_str());
writer.appendString(gPathRendererNames[GpuPathRenderers::kTessellation]);
}
}
#endif
if (1 == fWindow->sampleCount()) {
writer.appendString(gPathRendererNames[GpuPathRenderers::kSmall].c_str());
writer.appendString(gPathRendererNames[GpuPathRenderers::kSmall]);
}
writer.appendString(gPathRendererNames[GpuPathRenderers::kTriangulating].c_str());
writer.appendString(gPathRendererNames[GpuPathRenderers::kNone].c_str());
writer.appendString(gPathRendererNames[GpuPathRenderers::kTriangulating]);
writer.appendString(gPathRendererNames[GpuPathRenderers::kNone]);
}
});
// Softkey state
WriteStateObject(writer, kSoftkeyStateName, kSoftkeyHint,
[this](SkJSONWriter& writer) {
writer.appendString(kSoftkeyHint);
writer.appendNString(kSoftkeyHint);
for (const auto& softkey : fCommands.getCommandsAsSoftkeys()) {
writer.appendString(softkey.c_str());
writer.appendString(softkey);
}
});