Flutter Engine
The Flutter Engine
Classes | Macros | Functions | Variables
CommonFlagsConfig.cpp File Reference
#include "tools/flags/CommonFlagsConfig.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkSurfaceProps.h"
#include "src/core/SkColorSpacePriv.h"
#include "src/core/SkStringUtils.h"
#include "src/core/SkSurfacePriv.h"
#include "src/core/SkTHash.h"
#include <stdlib.h>
#include <string_view>
#include <unordered_map>

Go to the source code of this file.

Classes

class  ExtendedOptions
 

Macros

#define DEFAULT_GPU_CONFIG   "gl"
 

Functions

static const char * config_help_fn ()
 
static const char * config_extended_help_fn ()
 
 DEFINE_extended_string (config, defaultConfigs, config_help_fn(), config_extended_help_fn())
 
static bool parse_option_int (const SkString &value, int *outInt)
 
static bool parse_option_bool (const SkString &value, bool *outBool)
 
static bool parse_option_gpu_api (const SkString &value, SkCommandLineConfigGpu::ContextType *outContextType, bool *outFakeGLESVersion2)
 
static bool parse_option_gpu_color (const SkString &value, SkColorType *outColorType, SkAlphaType *alphaType)
 
static bool parse_option_gpu_surf_type (const SkString &value, SkCommandLineConfigGpu::SurfType *surfType)
 
SkCommandLineConfigGpuparse_command_line_config_gpu (const SkString &tag, const TArray< SkString > &vias, const SkString &options)
 
SkCommandLineConfigSvgparse_command_line_config_svg (const SkString &tag, const TArray< SkString > &vias, const SkString &options)
 
void ParseConfigs (const CommandLineFlags::StringArray &configs, SkCommandLineConfigArray *outResult)
 

Variables

static const char defaultConfigs []
 
struct {
   const char *   predefinedConfig
 
   const char *   backend
 
   const char *   options
 
gPredefinedConfigs []
 
static const char configHelp []
 
static const char configExtendedHelp []
 

Macro Definition Documentation

◆ DEFAULT_GPU_CONFIG

#define DEFAULT_GPU_CONFIG   "gl"

Definition at line 27 of file CommonFlagsConfig.cpp.

Function Documentation

◆ config_extended_help_fn()

static const char * config_extended_help_fn ( )
static

Definition at line 245 of file CommonFlagsConfig.cpp.

245 {
246 static SkString helpString;
247 helpString.set(configExtendedHelp);
248 for (const auto& config : gPredefinedConfigs) {
249 helpString.appendf("\t%-10s\t= gpu(%s)\n", config.predefinedConfig, config.options);
250 }
251 return helpString.c_str();
252}
static const struct @440 gPredefinedConfigs[]
static const char configExtendedHelp[]
void set(const SkString &src)
Definition: SkString.h:186
const char * c_str() const
Definition: SkString.h:133
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:550

◆ config_help_fn()

static const char * config_help_fn ( )
static

Definition at line 179 of file CommonFlagsConfig.cpp.

179 {
180 static SkString helpString;
181 helpString.set(configHelp);
182 for (const auto& config : gPredefinedConfigs) {
183 helpString.appendf(" %s", config.predefinedConfig);
184 }
185 helpString.append(" or use extended form 'backend[option=value,...]'.\n");
186 return helpString.c_str();
187}
static const char configHelp[]
void append(const char text[])
Definition: SkString.h:203

◆ DEFINE_extended_string()

DEFINE_extended_string ( config  ,
defaultConfigs  ,
config_help_fn()  ,
config_extended_help_fn()   
)

◆ parse_command_line_config_gpu()

SkCommandLineConfigGpu * parse_command_line_config_gpu ( const SkString tag,
const TArray< SkString > &  vias,
const SkString options 
)

Definition at line 612 of file CommonFlagsConfig.cpp.

614 {
615 // Defaults for GPU backend.
617 bool useDIText = false;
618 bool useDMSAA = false;
619 int samples = 1;
622 bool useStencils = true;
623 int testPersistentCache = 0;
624 bool testPrecompile = false;
625 bool useDDLs = false;
626 bool slug = false;
627 bool serializeSlug = false;
628 bool remoteSlug = false;
629 bool reducedShaders = false;
630 bool fakeGLESVersion2 = false;
632
633 bool parseSucceeded = false;
634 ExtendedOptions extendedOptions(options, &parseSucceeded);
635 if (!parseSucceeded) {
636 return nullptr;
637 }
638
639 bool validOptions =
640 extendedOptions.get_option_gpu_api("api", &contextType, &fakeGLESVersion2, false) &&
641 extendedOptions.get_option_bool("dit", &useDIText) &&
642 extendedOptions.get_option_int("samples", &samples) &&
643 extendedOptions.get_option_bool("dmsaa", &useDMSAA) &&
644 extendedOptions.get_option_gpu_color("color", &colorType, &alphaType) &&
645 extendedOptions.get_option_bool("stencils", &useStencils) &&
646 extendedOptions.get_option_int("testPersistentCache", &testPersistentCache) &&
647 extendedOptions.get_option_bool("testPrecompile", &testPrecompile) &&
648 extendedOptions.get_option_bool("useDDLSink", &useDDLs) &&
649 extendedOptions.get_option_bool("slug", &slug) &&
650 extendedOptions.get_option_bool("serializeSlug", &serializeSlug) &&
651 extendedOptions.get_option_bool("remoteSlug", &remoteSlug) &&
652 extendedOptions.get_option_bool("reducedShaders", &reducedShaders) &&
653 extendedOptions.get_option_gpu_surf_type("surf", &surfType);
654
655 if (!validOptions) {
656 return nullptr;
657 }
658
659 uint32_t surfaceFlags = 0;
660 if (useDIText) {
662 }
663 if (useDMSAA) {
664 surfaceFlags |= SkSurfaceProps::kDynamicMSAA_Flag;
665 }
666
667 return new SkCommandLineConfigGpu(tag,
668 vias,
669 contextType,
670 fakeGLESVersion2,
671 surfaceFlags,
672 samples,
673 colorType,
674 alphaType,
675 useStencils,
676 testPersistentCache,
677 testPrecompile,
678 useDDLs,
679 slug,
680 serializeSlug,
681 remoteSlug,
682 reducedShaders,
683 surfType);
684}
const char * options
SkAlphaType
Definition: SkAlphaType.h:26
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
SkColorType
Definition: SkColorType.h:19
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition: SkColorType.h:24
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
@ kUseDeviceIndependentFonts_Flag
ContextType
Definition: ContextType.h:19

◆ parse_command_line_config_svg()

SkCommandLineConfigSvg * parse_command_line_config_svg ( const SkString tag,
const TArray< SkString > &  vias,
const SkString options 
)

Definition at line 738 of file CommonFlagsConfig.cpp.

740 {
741 // Defaults for SVG backend.
742 int pageIndex = 0;
743
744 bool parseSucceeded = false;
745 ExtendedOptions extendedOptions(options, &parseSucceeded);
746 if (!parseSucceeded) {
747 return nullptr;
748 }
749
750 bool validOptions = extendedOptions.get_option_int("page", &pageIndex);
751
752 if (!validOptions) {
753 return nullptr;
754 }
755
756 return new SkCommandLineConfigSvg(tag, vias, pageIndex);
757}

◆ parse_option_bool()

static bool parse_option_bool ( const SkString value,
bool *  outBool 
)
static

Definition at line 302 of file CommonFlagsConfig.cpp.

302 {
303 if (value.equals("true")) {
304 *outBool = true;
305 return true;
306 }
307 if (value.equals("false")) {
308 *outBool = false;
309 return true;
310 }
311 return false;
312}
uint8_t value

◆ parse_option_gpu_api()

static bool parse_option_gpu_api ( const SkString value,
SkCommandLineConfigGpu::ContextType outContextType,
bool *  outFakeGLESVersion2 
)
static

Definition at line 313 of file CommonFlagsConfig.cpp.

315 {
316 *outFakeGLESVersion2 = false;
317 if (value.equals("gl")) {
318 *outContextType = skgpu::ContextType::kGL;
319 return true;
320 }
321 if (value.equals("gles")) {
322 *outContextType = skgpu::ContextType::kGLES;
323 return true;
324 }
325 if (value.equals("glesfakev2")) {
326 *outContextType = skgpu::ContextType::kGLES;
327 *outFakeGLESVersion2 = true;
328 return true;
329 }
330 if (value.equals("angle_d3d9_es2")) {
331 *outContextType = skgpu::ContextType::kANGLE_D3D9_ES2;
332 return true;
333 }
334 if (value.equals("angle_d3d11_es2")) {
335 *outContextType = skgpu::ContextType::kANGLE_D3D11_ES2;
336 return true;
337 }
338 if (value.equals("angle_d3d11_es3")) {
339 *outContextType = skgpu::ContextType::kANGLE_D3D11_ES3;
340 return true;
341 }
342 if (value.equals("angle_gl_es2")) {
343 *outContextType = skgpu::ContextType::kANGLE_GL_ES2;
344 return true;
345 }
346 if (value.equals("angle_gl_es3")) {
347 *outContextType = skgpu::ContextType::kANGLE_GL_ES3;
348 return true;
349 }
350 if (value.equals("angle_mtl_es2")) {
351 *outContextType = skgpu::ContextType::kANGLE_Metal_ES2;
352 return true;
353 }
354 if (value.equals("angle_mtl_es3")) {
355 *outContextType = skgpu::ContextType::kANGLE_Metal_ES3;
356 return true;
357 }
358 if (value.equals("mock")) {
359 *outContextType = skgpu::ContextType::kMock;
360 return true;
361 }
362#ifdef SK_VULKAN
363 if (value.equals("vulkan")) {
364 *outContextType = skgpu::ContextType::kVulkan;
365 return true;
366 }
367#endif
368#ifdef SK_METAL
369 if (value.equals("metal")) {
370 *outContextType = skgpu::ContextType::kMetal;
371 return true;
372 }
373#endif
374#ifdef SK_DIRECT3D
375 if (value.equals("direct3d")) {
376 *outContextType = skgpu::ContextType::kDirect3D;
377 return true;
378 }
379#endif
380 return false;
381}
@ kGLES
OpenGL context.
@ kANGLE_GL_ES2
ANGLE on Direct3D11 OpenGL ES 3 context.
@ kANGLE_GL_ES3
ANGLE on OpenGL OpenGL ES 2 context.
@ kANGLE_D3D11_ES2
ANGLE on Direct3D9 OpenGL ES 2 context.
@ kVulkan
ANGLE on Metal ES 3 context.
@ kANGLE_D3D11_ES3
ANGLE on Direct3D11 OpenGL ES 2 context.
@ kANGLE_D3D9_ES2
OpenGL ES context.
@ kANGLE_Metal_ES2
ANGLE on OpenGL OpenGL ES 3 context.
@ kANGLE_Metal_ES3
ANGLE on Metal ES 2 context.
@ kMock
Dawn on OpenGL ES.

◆ parse_option_gpu_color()

static bool parse_option_gpu_color ( const SkString value,
SkColorType outColorType,
SkAlphaType alphaType 
)
static

Definition at line 383 of file CommonFlagsConfig.cpp.

385 {
386 // We always use premul unless the color type is 565.
387 *alphaType = kPremul_SkAlphaType;
388
389 if (value.equals("8888")) {
390 *outColorType = kRGBA_8888_SkColorType;
391 } else if (value.equals("888x")) {
392 *outColorType = kRGB_888x_SkColorType;
393 } else if (value.equals("bgra8")) {
394 *outColorType = kBGRA_8888_SkColorType;
395 } else if (value.equals("4444")) {
396 *outColorType = kARGB_4444_SkColorType;
397 } else if (value.equals("565")) {
398 *outColorType = kRGB_565_SkColorType;
399 *alphaType = kOpaque_SkAlphaType;
400 } else if (value.equals("1010102")) {
401 *outColorType = kRGBA_1010102_SkColorType;
402 } else if (value.equals("f16")) {
403 *outColorType = kRGBA_F16_SkColorType;
404 } else if (value.equals("f16norm")) {
405 *outColorType = kRGBA_F16Norm_SkColorType;
406 } else if (value.equals("srgba")) {
407 *outColorType = kSRGBA_8888_SkColorType;
408 } else if (value.equals("r8")) {
409 *outColorType = kR8_unorm_SkColorType;
410 *alphaType = kOpaque_SkAlphaType;
411 } else {
412 return false;
413 }
414 return true;
415}
@ kOpaque_SkAlphaType
pixel is opaque
Definition: SkAlphaType.h:28
@ kR8_unorm_SkColorType
Definition: SkColorType.h:54
@ kARGB_4444_SkColorType
pixel with 4 bits for alpha, red, green, blue; in 16-bit word
Definition: SkColorType.h:23
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition: SkColorType.h:26
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
Definition: SkColorType.h:38
@ kSRGBA_8888_SkColorType
Definition: SkColorType.h:53
@ kRGB_565_SkColorType
pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
Definition: SkColorType.h:22
@ kRGB_888x_SkColorType
pixel with 8 bits each for red, green, blue; in 32-bit word
Definition: SkColorType.h:25
@ kRGBA_1010102_SkColorType
10 bits for red, green, blue; 2 bits for alpha; in 32-bit word
Definition: SkColorType.h:27
@ kRGBA_F16Norm_SkColorType
pixel with half floats in [0,1] for red, green, blue, alpha;
Definition: SkColorType.h:36

◆ parse_option_gpu_surf_type()

static bool parse_option_gpu_surf_type ( const SkString value,
SkCommandLineConfigGpu::SurfType surfType 
)
static

Definition at line 417 of file CommonFlagsConfig.cpp.

418 {
419 if (value.equals("default")) {
421 return true;
422 }
423 if (value.equals("betex")) {
425 return true;
426 }
427 if (value.equals("bert")) {
429 return true;
430 }
431 return false;
432}

◆ parse_option_int()

static bool parse_option_int ( const SkString value,
int outInt 
)
static

Definition at line 290 of file CommonFlagsConfig.cpp.

290 {
291 if (value.isEmpty()) {
292 return false;
293 }
294 char* endptr = nullptr;
295 long intValue = strtol(value.c_str(), &endptr, 10);
296 if (*endptr != '\0') {
297 return false;
298 }
299 *outInt = static_cast<int>(intValue);
300 return true;
301}

◆ ParseConfigs()

void ParseConfigs ( const CommandLineFlags::StringArray configs,
SkCommandLineConfigArray outResult 
)

Definition at line 759 of file CommonFlagsConfig.cpp.

760 {
761 outResult->clear();
762 for (int i = 0; i < configs.size(); ++i) {
763 SkString extendedBackend;
764 SkString extendedOptions;
765 SkString simpleBackend;
766 TArray<SkString> vias;
767
768 SkString tag(configs[i]);
770 SkStrSplit(tag.c_str(), "[", kStrict_SkStrSplitMode, &parts);
771 if (parts.size() == 2) {
772 TArray<SkString> parts2;
773 SkStrSplit(parts[1].c_str(), "]", kStrict_SkStrSplitMode, &parts2);
774 if (parts2.size() == 2 && parts2[1].isEmpty()) {
775 SkStrSplit(parts[0].c_str(), "-", kStrict_SkStrSplitMode, &vias);
776 if (vias.size()) {
777 extendedBackend = vias[vias.size() - 1];
778 vias.pop_back();
779 } else {
780 extendedBackend = parts[0];
781 }
782 extendedOptions = parts2[0];
783 simpleBackend.printf("%s[%s]", extendedBackend.c_str(), extendedOptions.c_str());
784 }
785 }
786
787 if (extendedBackend.isEmpty()) {
788 simpleBackend = tag;
789 SkStrSplit(tag.c_str(), "-", kStrict_SkStrSplitMode, &vias);
790 if (vias.size()) {
791 simpleBackend = vias[vias.size() - 1];
792 vias.pop_back();
793 }
795 if (simpleBackend.equals(predefinedConfig.predefinedConfig)) {
796 extendedBackend = predefinedConfig.backend;
797 extendedOptions = predefinedConfig.options;
798 break;
799 }
800 }
801 }
802 SkCommandLineConfig* parsedConfig = nullptr;
803 if (extendedBackend.equals("gpu")) {
804 parsedConfig = parse_command_line_config_gpu(tag, vias, extendedOptions);
805 }
806#if defined(SK_GRAPHITE)
807 if (extendedBackend.equals("graphite")) {
808 parsedConfig = parse_command_line_config_graphite(tag, vias, extendedOptions);
809 }
810#endif
811 if (extendedBackend.equals("svg")) {
812 parsedConfig = parse_command_line_config_svg(tag, vias, extendedOptions);
813 }
814 if (!parsedConfig) {
815 parsedConfig = new SkCommandLineConfig(tag, simpleBackend, vias);
816 }
817 outResult->emplace_back(parsedConfig);
818 }
819}
SkCommandLineConfigGpu * parse_command_line_config_gpu(const SkString &tag, const TArray< SkString > &vias, const SkString &options)
const char * predefinedConfig
SkCommandLineConfigSvg * parse_command_line_config_svg(const SkString &tag, const TArray< SkString > &vias, const SkString &options)
void SkStrSplit(const char *str, const char *delimiters, SkStrSplitMode splitMode, TArray< SkString > *out)
@ kStrict_SkStrSplitMode
Definition: SkStringUtils.h:47
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:534
bool equals(const SkString &) const
Definition: SkString.cpp:324
bool isEmpty() const
Definition: SkString.h:130
int size() const
Definition: SkTArray.h:421
T & emplace_back(Args &&... args)
Definition: SkTArray.h:248

Variable Documentation

◆ backend

const char* backend

Definition at line 42 of file CommonFlagsConfig.cpp.

◆ configExtendedHelp

const char configExtendedHelp[]
static

Definition at line 189 of file CommonFlagsConfig.cpp.

◆ configHelp

const char configHelp[]
static
Initial value:
=
"Options: 565 4444 8888 rgba bgra rgbx 1010102 101010x bgra1010102 bgr101010x f16 f16norm "
"f32 nonrendering null pdf pdfa pdf300 skp svg xps"

Definition at line 175 of file CommonFlagsConfig.cpp.

◆ defaultConfigs

const char defaultConfigs[]
static
Initial value:
" nonrendering "
#define DEFAULT_GPU_CONFIG

Definition at line 30 of file CommonFlagsConfig.cpp.

◆ 

const struct { ... } gPredefinedConfigs[]

◆ options

const char* options

Definition at line 43 of file CommonFlagsConfig.cpp.

◆ predefinedConfig

const char* predefinedConfig

Definition at line 41 of file CommonFlagsConfig.cpp.