Add plumbing for text only fiddles.

BUG=skia:

Change-Id: If3967f868c482bbded7185a0ed7c6559cd2858c5
Reviewed-on: https://skia-review.googlesource.com/8334
Reviewed-by: Cary Clark <caryclark@google.com>
Commit-Queue: Joe Gregorio <jcgregorio@google.com>
This commit is contained in:
Joe Gregorio 2017-02-13 11:39:43 -05:00 committed by Skia Commit-Bot
parent ff590a1244
commit 1fd1823b47
3 changed files with 47 additions and 7 deletions

View File

@ -13,7 +13,7 @@
DrawOptions GetDrawOptions() {
// path *should* be absolute.
static const char path[] = "resources/color_wheel.png";
return DrawOptions(256, 256, true, true, true, true, true, false, path);
return DrawOptions(256, 256, true, true, true, true, true, false, false, path);
}
void draw(SkCanvas* canvas) {
canvas->clear(SK_ColorWHITE);
@ -25,4 +25,5 @@ void draw(SkCanvas* canvas) {
SkShader::kRepeat_TileMode,
&matrix));
canvas->drawPaint(paint);
SkDebugf("This is text output: %d", 2);
}

View File

@ -7,6 +7,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include "fiddle_main.h"
@ -14,6 +15,22 @@
SkBitmap source;
sk_sp<SkImage> image;
// Globals used by the local impl of SkDebugf.
char formatbuffer[1024];
std::string textoutput("");
void SkDebugf(const char * fmt, ...) {
int n;
va_list args;
va_start(args, fmt);
n = vsnprintf(formatbuffer, sizeof(formatbuffer), fmt, args);
va_end(args);
if (n>=0 && n<=int(sizeof(formatbuffer))) {
textoutput.append(formatbuffer);
textoutput.append("\n");
}
}
static void encode_to_base64(const void* data, size_t size, FILE* out) {
const uint8_t* input = reinterpret_cast<const uint8_t*>(data);
const uint8_t* end = &input[size];
@ -56,6 +73,13 @@ static void dump_output(const sk_sp<SkData>& data,
}
}
static void dump_text(const std::string& s,
const char* name, bool last = true) {
printf("\t\"%s\": \"", name);
encode_to_base64(s.c_str(), s.length(), stdout);
fputs(last ? "\"\n" : "\",\n", stdout);
}
static SkData* encode_snapshot(const sk_sp<SkSurface>& surface) {
sk_sp<SkImage> img(surface->makeImageSnapshot());
return img ? img->encode() : nullptr;
@ -87,8 +111,18 @@ static SkData* encode_snapshot(const sk_sp<SkSurface>& surface) {
static sk_sp<GrContext> create_grcontext() { return nullptr; }
#endif
int main() {
const DrawOptions options = GetDrawOptions();
DrawOptions options = GetDrawOptions();
// If textOnly then only do one type of image, otherwise the text
// output is duplicated for each type.
if (options.textOnly) {
options.raster = true;
options.gpu = false;
options.pdf = false;
options.skp = false;
}
if (options.source) {
sk_sp<SkData> data(SkData::MakeFromFileName(options.source));
if (!data) {
@ -158,12 +192,14 @@ int main() {
picture->serialize(&skpStream);
skpData = skpStream.detachAsData();
}
bool textOnly = options.textOnly;
printf("{\n");
dump_output(rasterData, "Raster", !gpuData && !pdfData && !skpData);
dump_output(gpuData, "Gpu", !pdfData && !skpData);
dump_output(pdfData, "Pdf", !skpData);
dump_output(skpData, "Skp");
dump_output(rasterData, "Raster", !gpuData && !pdfData && !skpData && !textOnly);
dump_output(gpuData, "Gpu", !pdfData && !skpData && !textOnly);
dump_output(pdfData, "Pdf", !skpData && !textOnly);
dump_output(skpData, "Skp", !textOnly);
dump_text(textoutput, "Text");
printf("}\n");
return 0;

View File

@ -24,7 +24,7 @@ extern SkBitmap source;
extern sk_sp<SkImage> image;
struct DrawOptions {
DrawOptions(int w, int h, bool r, bool g, bool p, bool k, bool srgb, bool f16, const char* s)
DrawOptions(int w, int h, bool r, bool g, bool p, bool k, bool srgb, bool f16, bool textOnly, const char* s)
: size(SkISize::Make(w, h))
, raster(r)
, gpu(g)
@ -32,6 +32,7 @@ struct DrawOptions {
, skp(k)
, srgb(srgb)
, f16(f16)
, textOnly(textOnly)
, source(s)
{
// F16 mode is only valid for color correct backends.
@ -44,10 +45,12 @@ struct DrawOptions {
bool skp;
bool srgb;
bool f16;
bool textOnly;
const char* source;
};
extern DrawOptions GetDrawOptions();
extern void SkDebugf(const char * format, ...);
extern void draw(SkCanvas*);
#endif // fiddle_main_DEFINED