Flutter Engine
The Flutter Engine
Functions | Variables
fiddle_main.cpp File Reference
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <string>
#include "src/core/SkAutoPixmapStorage.h"
#include "src/core/SkMemset.h"
#include "src/core/SkMipmap.h"
#include "tools/flags/CommandLineFlags.h"
#include "tools/fiddle/fiddle_main.h"
#include "include/codec/SkCodec.h"
#include "include/codec/SkJpegDecoder.h"
#include "include/codec/SkPngDecoder.h"
#include "include/encode/SkPngEncoder.h"
#include "include/gpu/GrBackendSurface.h"
#include "include/gpu/ganesh/SkSurfaceGanesh.h"
#include "src/gpu/ganesh/GrDirectContextPriv.h"
#include "src/gpu/ganesh/GrGpu.h"
#include "src/gpu/ganesh/GrRenderTarget.h"
#include "src/gpu/ganesh/GrResourceProvider.h"
#include "src/gpu/ganesh/GrTexture.h"
#include "tools/gpu/ManagedBackendTexture.h"
#include "tools/gpu/gl/GLTestContext.h"

Go to the source code of this file.

Functions

static DEFINE_double (duration, 1.0, "The total duration, in seconds, of the animation we are drawing.")
 
static DEFINE_double (frame, 1.0, "A double value in [0, 1] that specifies the point in animation to draw.")
 
void SkDebugf (const char *fmt,...)
 
static void encode_to_base64 (const void *data, size_t size, FILE *out)
 
static void dump_output (const void *data, size_t size, const char *name, bool last=true)
 
static void dump_output (const sk_sp< SkData > &data, const char *name, bool last=true)
 
static sk_sp< SkDataencode_snapshot (GrDirectContext *ctx, const sk_sp< SkSurface > &surface)
 
static SkCanvasprepare_canvas (SkCanvas *canvas)
 
int main (int argc, char **argv)
 

Variables

GrBackendTexture backEndTexture
 
GrBackendRenderTarget backEndRenderTarget
 
GrBackendTexture backEndTextureRenderTarget
 
SkBitmap source
 
sk_sp< SkImageimage
 
double duration
 
double frame
 
sk_sp< SkFontMgrfontMgr
 
std::ostringstream gTextOutput
 
std::ostringstream gGLDriverInfo
 
sk_sp< sk_gpu_test::ManagedBackendTexture > managedBackendTextureRenderTarget
 
sk_sp< sk_gpu_test::ManagedBackendTexture > managedBackendTexture
 
sk_sp< GrRenderTargetbackingRenderTarget
 

Function Documentation

◆ DEFINE_double() [1/2]

static DEFINE_double ( duration  ,
1.  0,
"The total  duration,
in  seconds,
of the animation we are drawing."   
)
static

◆ DEFINE_double() [2/2]

static DEFINE_double ( frame  ,
1.  0,
"A double value in that specifies the point in animation to draw."  [0, 1] 
)
static

◆ dump_output() [1/2]

static void dump_output ( const sk_sp< SkData > &  data,
const char *  name,
bool  last = true 
)
static

Definition at line 117 of file fiddle_main.cpp.

118 {
119 if (data) {
120 dump_output(data->data(), data->size(), name, last);
121 }
122}
static void dump_output(const void *data, size_t size, const char *name, bool last=true)
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ dump_output() [2/2]

static void dump_output ( const void *  data,
size_t  size,
const char *  name,
bool  last = true 
)
static

Definition at line 110 of file fiddle_main.cpp.

111 {
112 printf("\t\"%s\": \"", name);
113 encode_to_base64(data, size, stdout);
114 fputs(last ? "\"\n" : "\",\n", stdout);
115}
static void encode_to_base64(const void *data, size_t size, FILE *out)
Definition: fiddle_main.cpp:76
std::string printf(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: SkSLString.cpp:83
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259

◆ encode_snapshot()

static sk_sp< SkData > encode_snapshot ( GrDirectContext ctx,
const sk_sp< SkSurface > &  surface 
)
static

Definition at line 124 of file fiddle_main.cpp.

124 {
125 sk_sp<SkImage> img(surface->makeImageSnapshot());
126 return SkPngEncoder::Encode(ctx, img.get(), {});
127}
VkSurfaceKHR surface
Definition: main.cc:49
SK_API bool Encode(SkWStream *dst, const SkPixmap &src, const Options &options)

◆ encode_to_base64()

static void encode_to_base64 ( const void *  data,
size_t  size,
FILE *  out 
)
static

Definition at line 76 of file fiddle_main.cpp.

76 {
77 const uint8_t* input = reinterpret_cast<const uint8_t*>(data);
78 const uint8_t* end = &input[size];
79 static const char codes[] =
80 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
81 "abcdefghijklmnopqrstuvwxyz0123456789+/";
82 while (input != end) {
83 uint8_t b = (*input & 0xFC) >> 2;
84 fputc(codes[b], out);
85 b = (*input & 0x03) << 4;
86 ++input;
87 if (input == end) {
88 fputc(codes[b], out);
89 fputs("==", out);
90 return;
91 }
92 b |= (*input & 0xF0) >> 4;
93 fputc(codes[b], out);
94 b = (*input & 0x0F) << 2;
95 ++input;
96 if (input == end) {
97 fputc(codes[b], out);
98 fputc('=', out);
99 return;
100 }
101 b |= (*input & 0xC0) >> 6;
102 fputc(codes[b], out);
103 b = *input & 0x3F;
104 fputc(codes[b], out);
105 ++input;
106 }
107}
static bool b
glong glong end

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 242 of file fiddle_main.cpp.

242 {
244 duration = FLAGS_duration;
245 frame = FLAGS_frame;
247 // If textOnly then only do one type of image, otherwise the text
248 // output is duplicated for each type.
249 if (options.textOnly) {
250 options.raster = true;
251 options.gpu = false;
252 options.pdf = false;
253 options.skp = false;
254 }
255#if defined(SK_FONTMGR_FONTCONFIG_AVAILABLE)
257#else
259#endif
260 if (options.source) {
262 if (!data) {
263 perror(options.source);
264 return 1;
265 }
266 std::unique_ptr<SkCodec> codec = nullptr;
267 if (SkPngDecoder::IsPng(data->data(), data->size())) {
268 codec = SkPngDecoder::Decode(data, nullptr);
269 } else if (SkJpegDecoder::IsJpeg(data->data(), data->size())) {
270 codec = SkJpegDecoder::Decode(data, nullptr);
271 } else {
272 perror("Unsupported file format\n");
273 return 1;
274 }
275 if (!codec) {
276 perror("Corrupt source image file\n");
277 return 1;
278 }
279 image = std::get<0>(codec->getImage());
280 if (!image) {
281 perror("Unable to decode the source image.\n");
282 return 1;
283 }
285 }
286 sk_sp<SkData> rasterData, gpuData, pdfData, skpData;
287 SkColorType colorType = kN32_SkColorType;
288 sk_sp<SkColorSpace> colorSpace = nullptr;
289 if (options.f16) {
290 SkASSERT(options.srgb);
292 colorSpace = SkColorSpace::MakeSRGBLinear();
293 } else if (options.srgb) {
294 colorSpace = SkColorSpace::MakeSRGB();
295 }
296 SkImageInfo info = SkImageInfo::Make(options.size.width(), options.size.height(), colorType,
297 kPremul_SkAlphaType, colorSpace);
298 if (options.raster) {
299 auto rasterSurface = SkSurfaces::Raster(info);
300 srand(0);
301 draw(prepare_canvas(rasterSurface->getCanvas()));
302 rasterData = encode_snapshot(nullptr, rasterSurface);
303 }
304#ifdef SK_GL
305 if (options.gpu) {
306 std::unique_ptr<sk_gpu_test::GLTestContext> glContext;
308 if (!direct) {
309 fputs("Unable to get GrContext.\n", stderr);
310 } else {
311 if (!setup_backend_objects(direct.get(), source, options)) {
312 fputs("Unable to create backend objects.\n", stderr);
313 exit(1);
314 }
315
317 if (!surface) {
318 fputs("Unable to get render surface.\n", stderr);
319 exit(1);
320 }
321 srand(0);
322 draw(prepare_canvas(surface->getCanvas()));
323 gpuData = encode_snapshot(direct.get(), surface);
324 }
325 }
326#endif
327
328#ifdef SK_SUPPORT_PDF
329 if (options.pdf) {
330 SkDynamicMemoryWStream pdfStream;
331 auto document = SkPDF::MakeDocument(&pdfStream);
332 if (document) {
333 srand(0);
334 draw(prepare_canvas(document->beginPage(options.size.width(), options.size.height())));
335 document->close();
336 pdfData = pdfStream.detachAsData();
337 }
338 }
339#endif
340
341 if (options.skp) {
342 auto size = SkSize::Make(options.size);
343 SkPictureRecorder recorder;
344 srand(0);
345 draw(prepare_canvas(recorder.beginRecording(size.width(), size.height())));
346 auto picture = recorder.finishRecordingAsPicture();
347 SkDynamicMemoryWStream skpStream;
348 picture->serialize(&skpStream);
349 skpData = skpStream.detachAsData();
350 }
351
352 printf("{\n");
353 if (!options.textOnly) {
354 dump_output(rasterData, "Raster", false);
355 dump_output(gpuData, "Gpu", false);
356 dump_output(pdfData, "Pdf", false);
357 dump_output(skpData, "Skp", false);
358 } else {
359 std::string textoutput = gTextOutput.str();
360 dump_output(textoutput.c_str(), textoutput.length(), "Text", false);
361 }
362 std::string glinfo = gGLDriverInfo.str();
363 dump_output(glinfo.c_str(), glinfo.length(), "GLInfo", true);
364 printf("}\n");
365
366 return 0;
367}
const char * options
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkColorType
Definition: SkColorType.h:19
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
Definition: SkColorType.h:38
SK_API sk_sp< SkFontMgr > SkFontMgr_New_FontConfig(FcConfig *fc)
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition: aaclip.cpp:27
static void Parse(int argc, const char *const *argv)
static sk_sp< SkColorSpace > MakeSRGB()
static sk_sp< SkColorSpace > MakeSRGBLinear()
static sk_sp< SkData > MakeFromFileName(const char path[])
Definition: SkData.cpp:148
sk_sp< SkData > detachAsData()
Definition: SkStream.cpp:707
static sk_sp< SkFontMgr > RefEmpty()
Definition: SkFontMgr.cpp:154
bool asLegacyBitmap(SkBitmap *bitmap, LegacyBitmapMode legacyBitmapMode=kRO_LegacyBitmapMode) const
Definition: SkImage.cpp:233
SkCanvas * beginRecording(const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)
sk_sp< SkPicture > finishRecordingAsPicture()
sk_sp< SkData > serialize(const SkSerialProcs *procs=nullptr) const
Definition: SkPicture.cpp:249
T * get() const
Definition: SkRefCnt.h:303
DrawOptions GetDrawOptions()
Definition: draw.cpp:16
sk_sp< GrDirectContext > create_direct_context(std::ostringstream &driverinfo, std::unique_ptr< sk_gpu_test::GLTestContext > *glContext)
Definition: egl_context.cpp:20
sk_sp< SkFontMgr > fontMgr
Definition: fiddle_main.cpp:53
static sk_sp< SkData > encode_snapshot(GrDirectContext *ctx, const sk_sp< SkSurface > &surface)
static SkCanvas * prepare_canvas(SkCanvas *canvas)
sk_sp< SkImage > image
Definition: fiddle_main.cpp:50
std::ostringstream gTextOutput
Definition: fiddle_main.cpp:56
SkBitmap source
Definition: fiddle_main.cpp:49
double duration
Definition: fiddle_main.cpp:51
std::ostringstream gGLDriverInfo
Definition: fiddle_main.cpp:59
double frame
Definition: fiddle_main.cpp:52
char ** argv
Definition: library.h:9
SK_API bool IsJpeg(const void *, size_t)
SK_API std::unique_ptr< SkCodec > Decode(std::unique_ptr< SkStream >, SkCodec::Result *, SkCodecs::DecodeContext=nullptr)
SK_API sk_sp< SkDocument > MakeDocument(SkWStream *stream, const Metadata &metadata)
SK_API std::unique_ptr< SkCodec > Decode(std::unique_ptr< SkStream >, SkCodec::Result *, SkCodecs::DecodeContext=nullptr)
SK_API bool IsPng(const void *, size_t)
sk_sp< const SkPicture > picture
Definition: SkRecords.h:299
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
exit(kErrorExitCode)
const myers::Point & get< 0 >(const myers::Segment &s)
Definition: Myers.h:80
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
static constexpr SkSize Make(SkScalar w, SkScalar h)
Definition: SkSize.h:56

◆ prepare_canvas()

static SkCanvas * prepare_canvas ( SkCanvas canvas)
static

Definition at line 129 of file fiddle_main.cpp.

129 {
130 canvas->clear(SK_ColorWHITE);
131 return canvas;
132}
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
void clear(SkColor color)
Definition: SkCanvas.h:1199

◆ SkDebugf()

void SkDebugf ( const char *  fmt,
  ... 
)

Definition at line 65 of file fiddle_main.cpp.

65 {
66 va_list args;
68 char formatbuffer[1024];
69 int n = vsnprintf(formatbuffer, sizeof(formatbuffer), fmt, args);
70 va_end(args);
71 if (n>=0 && n<=int(sizeof(formatbuffer))) {
72 gTextOutput.write(formatbuffer, n);
73 }
74}
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
va_start(args, format)
va_end(args)
static SkString fmt(SkColor4f c)
Definition: p3.cpp:43

Variable Documentation

◆ backEndRenderTarget

GrBackendRenderTarget backEndRenderTarget

Definition at line 47 of file fiddle_main.cpp.

◆ backEndTexture

GrBackendTexture backEndTexture

Definition at line 46 of file fiddle_main.cpp.

◆ backEndTextureRenderTarget

GrBackendTexture backEndTextureRenderTarget

Definition at line 48 of file fiddle_main.cpp.

◆ backingRenderTarget

sk_sp<GrRenderTarget> backingRenderTarget

Definition at line 63 of file fiddle_main.cpp.

◆ duration

double duration

Definition at line 51 of file fiddle_main.cpp.

◆ fontMgr

sk_sp<SkFontMgr> fontMgr

Definition at line 53 of file fiddle_main.cpp.

◆ frame

double frame

Definition at line 52 of file fiddle_main.cpp.

◆ gGLDriverInfo

std::ostringstream gGLDriverInfo

Definition at line 59 of file fiddle_main.cpp.

◆ gTextOutput

std::ostringstream gTextOutput

Definition at line 56 of file fiddle_main.cpp.

◆ image

sk_sp<SkImage> image

Definition at line 50 of file fiddle_main.cpp.

◆ managedBackendTexture

sk_sp<sk_gpu_test::ManagedBackendTexture> managedBackendTexture

Definition at line 62 of file fiddle_main.cpp.

◆ managedBackendTextureRenderTarget

sk_sp<sk_gpu_test::ManagedBackendTexture> managedBackendTextureRenderTarget

Definition at line 61 of file fiddle_main.cpp.

◆ source

SkBitmap source

Definition at line 49 of file fiddle_main.cpp.