Expose GrContext::dump() when SK_ENABLE_DUMP_GPU is defined.
Change-Id: I499228454bc387de2c988b8f607320b7e5ea57b0
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/233557
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 0d24f41..8656107 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -497,3 +497,31 @@
fGpu->deleteBackendTexture(backendTex);
}
+#ifdef SK_ENABLE_DUMP_GPU
+#include "src/utils/SkJSONWriter.h"
+SkString GrContext::dump() const {
+ SkDynamicMemoryWStream stream;
+ SkJSONWriter writer(&stream, SkJSONWriter::Mode::kPretty);
+ writer.beginObject();
+
+ writer.appendString("backend", GrBackendApiToStr(this->backend()));
+
+ writer.appendName("caps");
+ this->caps()->dumpJSON(&writer);
+
+ writer.appendName("gpu");
+ this->fGpu->dumpJSON(&writer);
+
+ // Flush JSON to the memory stream
+ writer.endObject();
+ writer.flush();
+
+ // Null terminate the JSON data in the memory stream
+ stream.write8(0);
+
+ // Allocate a string big enough to hold all the data, then copy out of the stream
+ SkString result(stream.bytesWritten());
+ stream.copyToAndReset(result.writable_str());
+ return result;
+}
+#endif