Revert "Revert "GrContext::dump that produces JSON formatted output""

This reverts commit 0f450acd76fd58a2f7464f99869ed6afbfac303c.

Bug: skia:
Change-Id: I97428fbbc6d82bf8b186ec5fdbf1a939c00e4126
Reviewed-on: https://skia-review.googlesource.com/32726
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/src/utils/SkJSONWriter.cpp b/src/utils/SkJSONWriter.cpp
new file mode 100644
index 0000000..3b92aa4
--- /dev/null
+++ b/src/utils/SkJSONWriter.cpp
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+// Make sure that the PRI format string macros are defined
+#define __STDC_FORMAT_MACROS
+#include <inttypes.h>
+#include <stdarg.h>
+
+#include "SkJSONWriter.h"
+
+void SkJSONWriter::appendS64(int64_t value) {
+    this->beginValue();
+    this->appendf("%" PRId64, value);
+}
+
+void SkJSONWriter::appendU64(uint64_t value) {
+    this->beginValue();
+    this->appendf("%" PRIu64, value);
+}
+
+void SkJSONWriter::appendHexU64(uint64_t value) {
+    this->beginValue();
+    this->appendf("\"0x%" PRIx64 "\"", value);
+}
+
+void SkJSONWriter::appendf(const char* fmt, ...) {
+    const int kBufferSize = 1024;
+    char buffer[kBufferSize];
+    va_list argp;
+    va_start(argp, fmt);
+#ifdef SK_BUILD_FOR_WIN
+    int length = _vsnprintf_s(buffer, kBufferSize, _TRUNCATE, fmt, argp);
+#else
+    int length = vsnprintf(buffer, kBufferSize, fmt, argp);
+#endif
+    SkASSERT(length >= 0 && length < kBufferSize);
+    va_end(argp);
+    this->write(buffer, length);
+}