* found in the LICENSE file.
*/
-#include <stdio.h>
-#include <stdlib.h>
+#include <cstdio>
+#include <cstdlib>
+#include <sstream>
#include <string>
#include "fiddle_main.h"
SkBitmap source;
sk_sp<SkImage> image;
-// Globals used by the local impl of SkDebugf.
-char formatbuffer[1024];
-std::string textoutput("");
+// Global used by the local impl of SkDebugf.
+std::ostringstream gTextOutput;
void SkDebugf(const char * fmt, ...) {
- int n;
va_list args;
va_start(args, fmt);
- n = vsnprintf(formatbuffer, sizeof(formatbuffer), fmt, args);
+ char formatbuffer[1024];
+ int n = vsnprintf(formatbuffer, sizeof(formatbuffer), fmt, args);
va_end(args);
if (n>=0 && n<=int(sizeof(formatbuffer))) {
- textoutput.append(formatbuffer);
- textoutput.append("\n");
+ gTextOutput.write(formatbuffer, n);
+ gTextOutput << '\n';
}
}
}
}
-static void dump_output(const sk_sp<SkData>& data,
- const char* name, bool last = true) {
- if (data) {
- printf("\t\"%s\": \"", name);
- encode_to_base64(data->data(), data->size(), stdout);
- fputs(last ? "\"\n" : "\",\n", stdout);
- }
-}
-static void dump_text(const std::string& s,
+static void dump_output(const void* data, size_t size,
const char* name, bool last = true) {
printf("\t\"%s\": \"", name);
- encode_to_base64(s.c_str(), s.length(), stdout);
+ encode_to_base64(data, size, stdout);
fputs(last ? "\"\n" : "\",\n", stdout);
}
+static void dump_output(const sk_sp<SkData>& data,
+ const char* name, bool last = true) {
+ if (data) {
+ dump_output(data->data(), data->size(), name, last);
+ }
+}
+
static SkData* encode_snapshot(const sk_sp<SkSurface>& surface) {
sk_sp<SkImage> img(surface->makeImageSnapshot());
return img ? img->encode() : nullptr;
dump_output(pdfData, "Pdf", !skpData);
dump_output(skpData, "Skp");
} else {
- dump_text(textoutput, "Text");
+ std::string textoutput = gTextOutput.str();
+ dump_output(textoutput.c_str(), textoutput.length(), "Text");
}
printf("}\n");