Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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/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 114 of file fiddle_main.cpp.

115 {
116 if (data) {
117 dump_output(data->data(), data->size(), name, last);
118 }
119}
static void dump_output(const void *data, size_t size, const char *name, bool last=true)
const char * name
Definition fuchsia.cc:50
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41

◆ dump_output() [2/2]

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

Definition at line 107 of file fiddle_main.cpp.

108 {
109 printf("\t\"%s\": \"", name);
110 encode_to_base64(data, size, stdout);
111 fputs(last ? "\"\n" : "\",\n", stdout);
112}
static void encode_to_base64(const void *data, size_t size, FILE *out)
std::string printf(const char *fmt,...) SK_PRINTF_LIKE(1

◆ encode_snapshot()

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

Definition at line 121 of file fiddle_main.cpp.

121 {
122 sk_sp<SkImage> img(surface->makeImageSnapshot());
123 return SkPngEncoder::Encode(ctx, img.get(), {});
124}
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 73 of file fiddle_main.cpp.

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

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 239 of file fiddle_main.cpp.

239 {
240 CommandLineFlags::Parse(argc, argv);
241 duration = FLAGS_duration;
242 frame = FLAGS_frame;
244 // If textOnly then only do one type of image, otherwise the text
245 // output is duplicated for each type.
246 if (options.textOnly) {
247 options.raster = true;
248 options.gpu = false;
249 options.pdf = false;
250 options.skp = false;
251 }
252#if defined(SK_FONTMGR_FONTCONFIG_AVAILABLE)
254#else
256#endif
257 if (options.source) {
259 if (!data) {
260 perror(options.source);
261 return 1;
262 } else {
263 image = SkImages::DeferredFromEncodedData(std::move(data));
264 if (!image) {
265 perror("Unable to decode the source image.");
266 return 1;
267 }
269 }
270 }
271 sk_sp<SkData> rasterData, gpuData, pdfData, skpData;
272 SkColorType colorType = kN32_SkColorType;
273 sk_sp<SkColorSpace> colorSpace = nullptr;
274 if (options.f16) {
275 SkASSERT(options.srgb);
277 colorSpace = SkColorSpace::MakeSRGBLinear();
278 } else if (options.srgb) {
279 colorSpace = SkColorSpace::MakeSRGB();
280 }
281 SkImageInfo info = SkImageInfo::Make(options.size.width(), options.size.height(), colorType,
282 kPremul_SkAlphaType, colorSpace);
283 if (options.raster) {
284 auto rasterSurface = SkSurfaces::Raster(info);
285 srand(0);
286 draw(prepare_canvas(rasterSurface->getCanvas()));
287 rasterData = encode_snapshot(nullptr, rasterSurface);
288 }
289#ifdef SK_GL
290 if (options.gpu) {
291 std::unique_ptr<sk_gpu_test::GLTestContext> glContext;
293 if (!direct) {
294 fputs("Unable to get GrContext.\n", stderr);
295 } else {
296 if (!setup_backend_objects(direct.get(), source, options)) {
297 fputs("Unable to create backend objects.\n", stderr);
298 exit(1);
299 }
300
302 if (!surface) {
303 fputs("Unable to get render surface.\n", stderr);
304 exit(1);
305 }
306 srand(0);
307 draw(prepare_canvas(surface->getCanvas()));
308 gpuData = encode_snapshot(direct.get(), surface);
309 }
310 }
311#endif
312
313#ifdef SK_SUPPORT_PDF
314 if (options.pdf) {
315 SkDynamicMemoryWStream pdfStream;
316 auto document = SkPDF::MakeDocument(&pdfStream);
317 if (document) {
318 srand(0);
319 draw(prepare_canvas(document->beginPage(options.size.width(), options.size.height())));
320 document->close();
321 pdfData = pdfStream.detachAsData();
322 }
323 }
324#endif
325
326 if (options.skp) {
327 auto size = SkSize::Make(options.size);
328 SkPictureRecorder recorder;
329 srand(0);
330 draw(prepare_canvas(recorder.beginRecording(size.width(), size.height())));
331 auto picture = recorder.finishRecordingAsPicture();
332 SkDynamicMemoryWStream skpStream;
333 picture->serialize(&skpStream);
334 skpData = skpStream.detachAsData();
335 }
336
337 printf("{\n");
338 if (!options.textOnly) {
339 dump_output(rasterData, "Raster", false);
340 dump_output(gpuData, "Gpu", false);
341 dump_output(pdfData, "Pdf", false);
342 dump_output(skpData, "Skp", false);
343 } else {
344 std::string textoutput = gTextOutput.str();
345 dump_output(textoutput.c_str(), textoutput.length(), "Text", false);
346 }
347 std::string glinfo = gGLDriverInfo.str();
348 dump_output(glinfo.c_str(), glinfo.length(), "GLInfo", true);
349 printf("}\n");
350
351 return 0;
352}
const char * options
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
#define SkAssertResult(cond)
Definition SkAssert.h:123
#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()
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
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)
sk_sp< SkFontMgr > fontMgr
static sk_sp< SkData > encode_snapshot(GrDirectContext *ctx, const sk_sp< SkSurface > &surface)
static SkCanvas * prepare_canvas(SkCanvas *canvas)
sk_sp< SkImage > image
std::ostringstream gTextOutput
SkBitmap source
double duration
std::ostringstream gGLDriverInfo
double frame
SK_API sk_sp< SkImage > DeferredFromEncodedData(sk_sp< SkData > encoded, std::optional< SkAlphaType > alphaType=std::nullopt)
SK_API sk_sp< SkDocument > MakeDocument(SkWStream *stream, const Metadata &metadata)
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)
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 126 of file fiddle_main.cpp.

126 {
127 canvas->clear(SK_ColorWHITE);
128 return canvas;
129}
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 62 of file fiddle_main.cpp.

62 {
63 va_list args;
65 char formatbuffer[1024];
66 int n = vsnprintf(formatbuffer, sizeof(formatbuffer), fmt, args);
67 va_end(args);
68 if (n>=0 && n<=int(sizeof(formatbuffer))) {
69 gTextOutput.write(formatbuffer, n);
70 }
71}
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 44 of file fiddle_main.cpp.

◆ backEndTexture

GrBackendTexture backEndTexture

Definition at line 43 of file fiddle_main.cpp.

◆ backEndTextureRenderTarget

GrBackendTexture backEndTextureRenderTarget

Definition at line 45 of file fiddle_main.cpp.

◆ backingRenderTarget

sk_sp<GrRenderTarget> backingRenderTarget

Definition at line 60 of file fiddle_main.cpp.

◆ duration

double duration

Definition at line 48 of file fiddle_main.cpp.

◆ fontMgr

sk_sp<SkFontMgr> fontMgr

Definition at line 50 of file fiddle_main.cpp.

◆ frame

double frame

Definition at line 49 of file fiddle_main.cpp.

◆ gGLDriverInfo

std::ostringstream gGLDriverInfo

Definition at line 56 of file fiddle_main.cpp.

◆ gTextOutput

std::ostringstream gTextOutput

Definition at line 53 of file fiddle_main.cpp.

◆ image

sk_sp<SkImage> image

Definition at line 47 of file fiddle_main.cpp.

◆ managedBackendTexture

sk_sp<sk_gpu_test::ManagedBackendTexture> managedBackendTexture

Definition at line 59 of file fiddle_main.cpp.

◆ managedBackendTextureRenderTarget

sk_sp<sk_gpu_test::ManagedBackendTexture> managedBackendTextureRenderTarget

Definition at line 58 of file fiddle_main.cpp.

◆ source

SkBitmap source

Definition at line 46 of file fiddle_main.cpp.