CommonFlagsConfig.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. /*
  2. * Copyright 2015 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "include/core/SkImageInfo.h"
  8. #include "include/private/SkTHash.h"
  9. #include "src/core/SkColorSpacePriv.h"
  10. #include "tools/flags/CommonFlagsConfig.h"
  11. #include <stdlib.h>
  12. using sk_gpu_test::GrContextFactory;
  13. #if defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_IOS)
  14. #define DEFAULT_GPU_CONFIG "gles"
  15. #else
  16. #define DEFAULT_GPU_CONFIG "gl"
  17. #endif
  18. static const char defaultConfigs[] = "8888 " DEFAULT_GPU_CONFIG
  19. " nonrendering "
  20. #if SK_ANGLE && defined(SK_BUILD_FOR_WIN)
  21. " angle_d3d11_es2"
  22. #endif
  23. ;
  24. #undef DEFAULT_GPU_CONFIG
  25. // clang-format off
  26. static const struct {
  27. const char* predefinedConfig;
  28. const char* backend;
  29. const char* options;
  30. } gPredefinedConfigs[] = {
  31. { "gl", "gpu", "api=gl" },
  32. { "gles", "gpu", "api=gles" },
  33. { "glmsaa4", "gpu", "api=gl,samples=4" },
  34. { "glmsaa8" , "gpu", "api=gl,samples=8" },
  35. { "glesmsaa4", "gpu", "api=gles,samples=4" },
  36. { "glbetex", "gpu", "api=gl,surf=betex" },
  37. { "glesbetex", "gpu", "api=gles,surf=betex" },
  38. { "glbert", "gpu", "api=gl,surf=bert" },
  39. { "glesbert", "gpu", "api=gles,surf=bert" },
  40. { "gl4444", "gpu", "api=gl,color=4444" },
  41. { "gles4444", "gpu", "api=gles,color=4444" },
  42. { "gl565", "gpu", "api=gl,color=565" },
  43. { "gl888x", "gpu", "api=gl,color=888x" },
  44. { "gles888x", "gpu", "api=gles,color=888x" },
  45. { "gl1010102", "gpu", "api=gl,color=1010102" },
  46. { "gles1010102", "gpu", "api=gles,color=1010102" },
  47. { "glsrgb", "gpu", "api=gl,color=srgb" },
  48. { "glp3", "gpu", "api=gl,color=p3" },
  49. { "glesrgb", "gpu", "api=gl,color=esrgb" },
  50. { "glnarrow", "gpu", "api=gl,color=narrow" },
  51. { "glenarrow", "gpu", "api=gl,color=enarrow" },
  52. { "glf16", "gpu", "api=gl,color=f16" },
  53. { "glf16norm", "gpu", "api=gl,color=f16norm" },
  54. { "glessrgb", "gpu", "api=gles,color=srgb" },
  55. { "glesesrgb", "gpu", "api=gles,color=esrgb" },
  56. { "glesnarrow", "gpu", "api=gles,color=narrow" },
  57. { "glesenarrow", "gpu", "api=gles,color=enarrow" },
  58. { "glesf16", "gpu", "api=gles,color=f16" },
  59. { "glnostencils", "gpu", "api=gl,stencils=false" },
  60. { "gldft", "gpu", "api=gl,dit=true" },
  61. { "glesdft", "gpu", "api=gles,dit=true" },
  62. { "gltestthreading", "gpu", "api=gl,testThreading=true" },
  63. { "gltestpersistentcache", "gpu", "api=gl,testPersistentCache=1" },
  64. { "gltestglslcache", "gpu", "api=gl,testPersistentCache=2" },
  65. { "angle_d3d11_es2", "gpu", "api=angle_d3d11_es2" },
  66. { "angle_d3d11_es3", "gpu", "api=angle_d3d11_es3" },
  67. { "angle_d3d9_es2", "gpu", "api=angle_d3d9_es2" },
  68. { "angle_d3d11_es2_msaa4", "gpu", "api=angle_d3d11_es2,samples=4" },
  69. { "angle_d3d11_es2_msaa8", "gpu", "api=angle_d3d11_es2,samples=8" },
  70. { "angle_d3d11_es3_msaa4", "gpu", "api=angle_d3d11_es3,samples=4" },
  71. { "angle_d3d11_es3_msaa8", "gpu", "api=angle_d3d11_es3,samples=8" },
  72. { "angle_gl_es2", "gpu", "api=angle_gl_es2" },
  73. { "angle_gl_es3", "gpu", "api=angle_gl_es3" },
  74. { "angle_gl_es2_msaa8", "gpu", "api=angle_gl_es2,samples=8" },
  75. { "angle_gl_es3_msaa8", "gpu", "api=angle_gl_es3,samples=8" },
  76. { "commandbuffer", "gpu", "api=commandbuffer" },
  77. { "mock", "gpu", "api=mock" },
  78. #ifdef SK_DAWN
  79. { "dawn", "gpu", "api=dawn" },
  80. #endif
  81. #ifdef SK_VULKAN
  82. { "vk", "gpu", "api=vulkan" },
  83. { "vknostencils", "gpu", "api=vulkan,stencils=false" },
  84. { "vk1010102", "gpu", "api=vulkan,color=1010102" },
  85. { "vksrgb", "gpu", "api=vulkan,color=srgb" },
  86. { "vkesrgb", "gpu", "api=vulkan,color=esrgb" },
  87. { "vknarrow", "gpu", "api=vulkan,color=narrow" },
  88. { "vkenarrow", "gpu", "api=vulkan,color=enarrow" },
  89. { "vkf16", "gpu", "api=vulkan,color=f16" },
  90. { "vkmsaa4", "gpu", "api=vulkan,samples=4" },
  91. { "vkmsaa8", "gpu", "api=vulkan,samples=8" },
  92. { "vkbetex", "gpu", "api=vulkan,surf=betex" },
  93. { "vkbert", "gpu", "api=vulkan,surf=bert" },
  94. { "vktestpersistentcache", "gpu", "api=vulkan,testPersistentCache=1" },
  95. #endif
  96. #ifdef SK_METAL
  97. { "mtl", "gpu", "api=metal" },
  98. { "mtl1010102", "gpu", "api=metal,color=1010102" },
  99. { "mtlmsaa4", "gpu", "api=metal,samples=4" },
  100. { "mtlmsaa8", "gpu", "api=metal,samples=8" },
  101. #endif
  102. };
  103. // clang-format on
  104. static const char configHelp[] =
  105. "Options: 565 8888 srgb f16 nonrendering null pdf pdfa skp pipe svg xps";
  106. static const char* config_help_fn() {
  107. static SkString helpString;
  108. helpString.set(configHelp);
  109. for (const auto& config : gPredefinedConfigs) {
  110. helpString.appendf(" %s", config.predefinedConfig);
  111. }
  112. helpString.append(" or use extended form 'backend[option=value,...]'.\n");
  113. return helpString.c_str();
  114. }
  115. static const char configExtendedHelp[] =
  116. "Extended form: 'backend(option=value,...)'\n\n"
  117. "Possible backends and options:\n"
  118. "\n"
  119. "gpu[api=string,color=string,dit=bool,samples=int]\n"
  120. "\tapi\ttype: string\trequired\n"
  121. "\t Select graphics API to use with gpu backend.\n"
  122. "\t Options:\n"
  123. "\t\tgl \t\t\tUse OpenGL.\n"
  124. "\t\tgles \t\t\tUse OpenGL ES.\n"
  125. "\t\tnullgl \t\t\tUse null OpenGL.\n"
  126. "\t\tangle_d3d9_es2\t\tUse OpenGL ES2 on the ANGLE Direct3D9 backend.\n"
  127. "\t\tangle_d3d11_es2\t\tUse OpenGL ES2 on the ANGLE Direct3D11 backend.\n"
  128. "\t\tangle_d3d11_es3\t\tUse OpenGL ES3 on the ANGLE Direct3D11 backend.\n"
  129. "\t\tangle_gl_es2\t\tUse OpenGL ES2 on the ANGLE OpenGL backend.\n"
  130. "\t\tangle_gl_es3\t\tUse OpenGL ES3 on the ANGLE OpenGL backend.\n"
  131. "\t\tcommandbuffer\t\tUse command buffer.\n"
  132. "\t\tmock\t\t\tUse mock context.\n"
  133. #ifdef SK_VULKAN
  134. "\t\tvulkan\t\t\tUse Vulkan.\n"
  135. #endif
  136. #ifdef SK_METAL
  137. "\t\tmetal\t\t\tUse Metal.\n"
  138. #endif
  139. "\tcolor\ttype: string\tdefault: 8888.\n"
  140. "\t Select framebuffer color format.\n"
  141. "\t Options:\n"
  142. "\t\t8888\t\t\tLinear 8888.\n"
  143. "\t\t888x\t\t\tLinear 888x.\n"
  144. "\t\t4444\t\t\tLinear 4444.\n"
  145. "\t\t565\t\t\tLinear 565.\n"
  146. "\t\t1010102\t\t\tLinear 1010102.\n"
  147. "\t\tsrgb\t\t\tsRGB 8888.\n"
  148. "\t\tesrgb\t\t\tsRGB 16-bit floating point.\n"
  149. "\t\tnarrow\t\t\tNarrow gamut 8888.\n"
  150. "\t\tenarrow\t\t\tNarrow gamut 16-bit floating point.\n"
  151. "\t\tf16\t\t\tLinearly blended 16-bit floating point.\n"
  152. "\tdit\ttype: bool\tdefault: false.\n"
  153. "\t Use device independent text.\n"
  154. "\tsamples\ttype: int\tdefault: 0.\n"
  155. "\t Use multisampling with N samples.\n"
  156. "\tstencils\ttype: bool\tdefault: true.\n"
  157. "\t Allow the use of stencil buffers.\n"
  158. "\ttestThreading\ttype: bool\tdefault: false.\n"
  159. "\t Run with and without worker threads, check that results match.\n"
  160. "\ttestPersistentCache\ttype: int\tdefault: 0.\n"
  161. "\t 1: Run using a pre-warmed binary GrContextOptions::fPersistentCache.\n"
  162. "\t 2: Run using a pre-warmed GLSL GrContextOptions::fPersistentCache.\n"
  163. "\tsurf\ttype: string\tdefault: default.\n"
  164. "\t Controls the type of backing store for SkSurfaces.\n"
  165. "\t Options:\n"
  166. "\t\tdefault\t\t\tA renderable texture created in Skia's resource cache.\n"
  167. "\t\tbetex\t\t\tA wrapped backend texture.\n"
  168. "\t\tbert\t\t\tA wrapped backend render target\n"
  169. "\n"
  170. "Predefined configs:\n\n"
  171. // Help text for pre-defined configs is auto-generated from gPredefinedConfigs
  172. ;
  173. static const char* config_extended_help_fn() {
  174. static SkString helpString;
  175. helpString.set(configExtendedHelp);
  176. for (const auto& config : gPredefinedConfigs) {
  177. helpString.appendf("\t%-10s\t= gpu(%s)\n", config.predefinedConfig, config.options);
  178. }
  179. return helpString.c_str();
  180. }
  181. DEFINE_extended_string(config, defaultConfigs, config_help_fn(), config_extended_help_fn());
  182. SkCommandLineConfig::SkCommandLineConfig(const SkString& tag,
  183. const SkString& backend,
  184. const SkTArray<SkString>& viaParts)
  185. : fTag(tag), fBackend(backend), fViaParts(viaParts) {}
  186. SkCommandLineConfig::~SkCommandLineConfig() {}
  187. static bool parse_option_int(const SkString& value, int* outInt) {
  188. if (value.isEmpty()) {
  189. return false;
  190. }
  191. char* endptr = nullptr;
  192. long intValue = strtol(value.c_str(), &endptr, 10);
  193. if (*endptr != '\0') {
  194. return false;
  195. }
  196. *outInt = static_cast<int>(intValue);
  197. return true;
  198. }
  199. static bool parse_option_bool(const SkString& value, bool* outBool) {
  200. if (value.equals("true")) {
  201. *outBool = true;
  202. return true;
  203. }
  204. if (value.equals("false")) {
  205. *outBool = false;
  206. return true;
  207. }
  208. return false;
  209. }
  210. static bool parse_option_gpu_api(const SkString& value,
  211. SkCommandLineConfigGpu::ContextType* outContextType) {
  212. if (value.equals("gl")) {
  213. *outContextType = GrContextFactory::kGL_ContextType;
  214. return true;
  215. }
  216. if (value.equals("gles")) {
  217. *outContextType = GrContextFactory::kGLES_ContextType;
  218. return true;
  219. }
  220. if (value.equals("angle_d3d9_es2")) {
  221. *outContextType = GrContextFactory::kANGLE_D3D9_ES2_ContextType;
  222. return true;
  223. }
  224. if (value.equals("angle_d3d11_es2")) {
  225. *outContextType = GrContextFactory::kANGLE_D3D11_ES2_ContextType;
  226. return true;
  227. }
  228. if (value.equals("angle_d3d11_es3")) {
  229. *outContextType = GrContextFactory::kANGLE_D3D11_ES3_ContextType;
  230. return true;
  231. }
  232. if (value.equals("angle_gl_es2")) {
  233. *outContextType = GrContextFactory::kANGLE_GL_ES2_ContextType;
  234. return true;
  235. }
  236. if (value.equals("angle_gl_es3")) {
  237. *outContextType = GrContextFactory::kANGLE_GL_ES3_ContextType;
  238. return true;
  239. }
  240. if (value.equals("commandbuffer")) {
  241. *outContextType = GrContextFactory::kCommandBuffer_ContextType;
  242. return true;
  243. }
  244. if (value.equals("mock")) {
  245. *outContextType = GrContextFactory::kMock_ContextType;
  246. return true;
  247. }
  248. #ifdef SK_VULKAN
  249. if (value.equals("vulkan")) {
  250. *outContextType = GrContextFactory::kVulkan_ContextType;
  251. return true;
  252. }
  253. #endif
  254. #ifdef SK_METAL
  255. if (value.equals("metal")) {
  256. *outContextType = GrContextFactory::kMetal_ContextType;
  257. return true;
  258. }
  259. #endif
  260. #ifdef SK_DAWN
  261. if (value.equals("dawn")) {
  262. *outContextType = GrContextFactory::kDawn_ContextType;
  263. return true;
  264. }
  265. #endif
  266. return false;
  267. }
  268. static bool parse_option_gpu_color(const SkString& value,
  269. SkColorType* outColorType,
  270. SkAlphaType* alphaType,
  271. sk_sp<SkColorSpace>* outColorSpace) {
  272. // We always use premul unless the color type is 565.
  273. *alphaType = kPremul_SkAlphaType;
  274. if (value.equals("8888")) {
  275. *outColorType = kRGBA_8888_SkColorType;
  276. *outColorSpace = nullptr;
  277. } else if (value.equals("888x")) {
  278. *outColorType = kRGB_888x_SkColorType;
  279. *outColorSpace = nullptr;
  280. } else if (value.equals("8888s")) {
  281. *outColorType = kRGBA_8888_SkColorType;
  282. *outColorSpace = SkColorSpace::MakeSRGB();
  283. } else if (value.equals("bgra8")) {
  284. *outColorType = kBGRA_8888_SkColorType;
  285. *outColorSpace = nullptr;
  286. } else if (value.equals("bgra8s")) {
  287. *outColorType = kBGRA_8888_SkColorType;
  288. *outColorSpace = SkColorSpace::MakeSRGB();
  289. } else if (value.equals("4444")) {
  290. *outColorType = kARGB_4444_SkColorType;
  291. *outColorSpace = nullptr;
  292. } else if (value.equals("565")) {
  293. *outColorType = kRGB_565_SkColorType;
  294. *alphaType = kOpaque_SkAlphaType;
  295. *outColorSpace = nullptr;
  296. } else if (value.equals("1010102")) {
  297. *outColorType = kRGBA_1010102_SkColorType;
  298. *outColorSpace = nullptr;
  299. } else if (value.equals("srgb")) {
  300. *outColorType = kRGBA_8888_SkColorType;
  301. *outColorSpace = SkColorSpace::MakeSRGB();
  302. } else if (value.equals("p3")) {
  303. *outColorType = kRGBA_8888_SkColorType;
  304. *outColorSpace = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDCIP3);
  305. } else if (value.equals("esrgb")) {
  306. *outColorType = kRGBA_F16_SkColorType;
  307. *outColorSpace = SkColorSpace::MakeSRGB();
  308. } else if (value.equals("narrow") || value.equals("enarrow")) {
  309. *outColorType = value.equals("narrow") ? kRGBA_8888_SkColorType : kRGBA_F16_SkColorType;
  310. *outColorSpace = SkColorSpace::MakeRGB(SkNamedTransferFn::k2Dot2, gNarrow_toXYZD50);
  311. } else if (value.equals("f16")) {
  312. *outColorType = kRGBA_F16_SkColorType;
  313. *outColorSpace = SkColorSpace::MakeSRGBLinear();
  314. } else if (value.equals("f16norm")) {
  315. *outColorType = kRGBA_F16Norm_SkColorType;
  316. *outColorSpace = SkColorSpace::MakeSRGB();
  317. } else {
  318. return false;
  319. }
  320. return true;
  321. }
  322. static bool parse_option_gpu_surf_type(const SkString& value,
  323. SkCommandLineConfigGpu::SurfType* surfType) {
  324. if (value.equals("default")) {
  325. *surfType = SkCommandLineConfigGpu::SurfType::kDefault;
  326. return true;
  327. }
  328. if (value.equals("betex")) {
  329. *surfType = SkCommandLineConfigGpu::SurfType::kBackendTexture;
  330. return true;
  331. }
  332. if (value.equals("bert")) {
  333. *surfType = SkCommandLineConfigGpu::SurfType::kBackendRenderTarget;
  334. return true;
  335. }
  336. return false;
  337. }
  338. // Extended options take form --config item[key1=value1,key2=value2,...]
  339. // Example: --config gpu[api=gl,color=8888]
  340. class ExtendedOptions {
  341. public:
  342. ExtendedOptions(const SkString& optionsString, bool* outParseSucceeded) {
  343. SkTArray<SkString> optionParts;
  344. SkStrSplit(optionsString.c_str(), ",", kStrict_SkStrSplitMode, &optionParts);
  345. for (int i = 0; i < optionParts.count(); ++i) {
  346. SkTArray<SkString> keyValueParts;
  347. SkStrSplit(optionParts[i].c_str(), "=", kStrict_SkStrSplitMode, &keyValueParts);
  348. if (keyValueParts.count() != 2) {
  349. *outParseSucceeded = false;
  350. return;
  351. }
  352. const SkString& key = keyValueParts[0];
  353. const SkString& value = keyValueParts[1];
  354. if (fOptionsMap.find(key) == nullptr) {
  355. fOptionsMap.set(key, value);
  356. } else {
  357. // Duplicate values are not allowed.
  358. *outParseSucceeded = false;
  359. return;
  360. }
  361. }
  362. *outParseSucceeded = true;
  363. }
  364. bool get_option_gpu_color(const char* optionKey,
  365. SkColorType* outColorType,
  366. SkAlphaType* alphaType,
  367. sk_sp<SkColorSpace>* outColorSpace,
  368. bool optional = true) const {
  369. SkString* optionValue = fOptionsMap.find(SkString(optionKey));
  370. if (optionValue == nullptr) {
  371. return optional;
  372. }
  373. return parse_option_gpu_color(*optionValue, outColorType, alphaType, outColorSpace);
  374. }
  375. bool get_option_gpu_api(const char* optionKey,
  376. SkCommandLineConfigGpu::ContextType* outContextType,
  377. bool optional = true) const {
  378. SkString* optionValue = fOptionsMap.find(SkString(optionKey));
  379. if (optionValue == nullptr) {
  380. return optional;
  381. }
  382. return parse_option_gpu_api(*optionValue, outContextType);
  383. }
  384. bool get_option_gpu_surf_type(const char* optionKey,
  385. SkCommandLineConfigGpu::SurfType* outSurfType,
  386. bool optional = true) const {
  387. SkString* optionValue = fOptionsMap.find(SkString(optionKey));
  388. if (optionValue == nullptr) {
  389. return optional;
  390. }
  391. return parse_option_gpu_surf_type(*optionValue, outSurfType);
  392. }
  393. bool get_option_int(const char* optionKey, int* outInt, bool optional = true) const {
  394. SkString* optionValue = fOptionsMap.find(SkString(optionKey));
  395. if (optionValue == nullptr) {
  396. return optional;
  397. }
  398. return parse_option_int(*optionValue, outInt);
  399. }
  400. bool get_option_bool(const char* optionKey, bool* outBool, bool optional = true) const {
  401. SkString* optionValue = fOptionsMap.find(SkString(optionKey));
  402. if (optionValue == nullptr) {
  403. return optional;
  404. }
  405. return parse_option_bool(*optionValue, outBool);
  406. }
  407. private:
  408. SkTHashMap<SkString, SkString> fOptionsMap;
  409. };
  410. SkCommandLineConfigGpu::SkCommandLineConfigGpu(const SkString& tag,
  411. const SkTArray<SkString>& viaParts,
  412. ContextType contextType,
  413. bool useDIText,
  414. int samples,
  415. SkColorType colorType,
  416. SkAlphaType alphaType,
  417. sk_sp<SkColorSpace> colorSpace,
  418. bool useStencilBuffers,
  419. bool testThreading,
  420. int testPersistentCache,
  421. SurfType surfType)
  422. : SkCommandLineConfig(tag, SkString("gpu"), viaParts)
  423. , fContextType(contextType)
  424. , fContextOverrides(ContextOverrides::kNone)
  425. , fUseDIText(useDIText)
  426. , fSamples(samples)
  427. , fColorType(colorType)
  428. , fAlphaType(alphaType)
  429. , fColorSpace(std::move(colorSpace))
  430. , fTestThreading(testThreading)
  431. , fTestPersistentCache(testPersistentCache)
  432. , fSurfType(surfType) {
  433. if (!useStencilBuffers) {
  434. fContextOverrides |= ContextOverrides::kAvoidStencilBuffers;
  435. }
  436. }
  437. SkCommandLineConfigGpu* parse_command_line_config_gpu(const SkString& tag,
  438. const SkTArray<SkString>& vias,
  439. const SkString& options) {
  440. // Defaults for GPU backend.
  441. SkCommandLineConfigGpu::ContextType contextType = GrContextFactory::kGL_ContextType;
  442. bool useDIText = false;
  443. int samples = 1;
  444. SkColorType colorType = kRGBA_8888_SkColorType;
  445. SkAlphaType alphaType = kPremul_SkAlphaType;
  446. sk_sp<SkColorSpace> colorSpace = nullptr;
  447. bool useStencils = true;
  448. bool testThreading = false;
  449. int testPersistentCache = 0;
  450. SkCommandLineConfigGpu::SurfType surfType = SkCommandLineConfigGpu::SurfType::kDefault;
  451. bool parseSucceeded = false;
  452. ExtendedOptions extendedOptions(options, &parseSucceeded);
  453. if (!parseSucceeded) {
  454. return nullptr;
  455. }
  456. bool validOptions =
  457. extendedOptions.get_option_gpu_api("api", &contextType, false) &&
  458. extendedOptions.get_option_bool("dit", &useDIText) &&
  459. extendedOptions.get_option_int("samples", &samples) &&
  460. extendedOptions.get_option_gpu_color("color", &colorType, &alphaType, &colorSpace) &&
  461. extendedOptions.get_option_bool("stencils", &useStencils) &&
  462. extendedOptions.get_option_bool("testThreading", &testThreading) &&
  463. extendedOptions.get_option_int("testPersistentCache", &testPersistentCache) &&
  464. extendedOptions.get_option_gpu_surf_type("surf", &surfType);
  465. // testing threading and the persistent cache are mutually exclusive.
  466. if (!validOptions || (testThreading && (testPersistentCache != 0))) {
  467. return nullptr;
  468. }
  469. return new SkCommandLineConfigGpu(tag,
  470. vias,
  471. contextType,
  472. useDIText,
  473. samples,
  474. colorType,
  475. alphaType,
  476. colorSpace,
  477. useStencils,
  478. testThreading,
  479. testPersistentCache,
  480. surfType);
  481. }
  482. SkCommandLineConfigSvg::SkCommandLineConfigSvg(const SkString& tag,
  483. const SkTArray<SkString>& viaParts,
  484. int pageIndex)
  485. : SkCommandLineConfig(tag, SkString("svg"), viaParts), fPageIndex(pageIndex) {}
  486. SkCommandLineConfigSvg* parse_command_line_config_svg(const SkString& tag,
  487. const SkTArray<SkString>& vias,
  488. const SkString& options) {
  489. // Defaults for SVG backend.
  490. int pageIndex = 0;
  491. bool parseSucceeded = false;
  492. ExtendedOptions extendedOptions(options, &parseSucceeded);
  493. if (!parseSucceeded) {
  494. return nullptr;
  495. }
  496. bool validOptions = extendedOptions.get_option_int("page", &pageIndex);
  497. if (!validOptions) {
  498. return nullptr;
  499. }
  500. return new SkCommandLineConfigSvg(tag, vias, pageIndex);
  501. }
  502. void ParseConfigs(const CommandLineFlags::StringArray& configs,
  503. SkCommandLineConfigArray* outResult) {
  504. outResult->reset();
  505. for (int i = 0; i < configs.count(); ++i) {
  506. SkString extendedBackend;
  507. SkString extendedOptions;
  508. SkString simpleBackend;
  509. SkTArray<SkString> vias;
  510. SkString tag(configs[i]);
  511. SkTArray<SkString> parts;
  512. SkStrSplit(tag.c_str(), "[", kStrict_SkStrSplitMode, &parts);
  513. if (parts.count() == 2) {
  514. SkTArray<SkString> parts2;
  515. SkStrSplit(parts[1].c_str(), "]", kStrict_SkStrSplitMode, &parts2);
  516. if (parts2.count() == 2 && parts2[1].isEmpty()) {
  517. SkStrSplit(parts[0].c_str(), "-", kStrict_SkStrSplitMode, &vias);
  518. if (vias.count()) {
  519. extendedBackend = vias[vias.count() - 1];
  520. vias.pop_back();
  521. } else {
  522. extendedBackend = parts[0];
  523. }
  524. extendedOptions = parts2[0];
  525. simpleBackend.printf("%s[%s]", extendedBackend.c_str(), extendedOptions.c_str());
  526. }
  527. }
  528. if (extendedBackend.isEmpty()) {
  529. simpleBackend = tag;
  530. SkStrSplit(tag.c_str(), "-", kStrict_SkStrSplitMode, &vias);
  531. if (vias.count()) {
  532. simpleBackend = vias[vias.count() - 1];
  533. vias.pop_back();
  534. }
  535. for (auto& predefinedConfig : gPredefinedConfigs) {
  536. if (simpleBackend.equals(predefinedConfig.predefinedConfig)) {
  537. extendedBackend = predefinedConfig.backend;
  538. extendedOptions = predefinedConfig.options;
  539. break;
  540. }
  541. }
  542. }
  543. SkCommandLineConfig* parsedConfig = nullptr;
  544. if (extendedBackend.equals("gpu")) {
  545. parsedConfig = parse_command_line_config_gpu(tag, vias, extendedOptions);
  546. }
  547. if (extendedBackend.equals("svg")) {
  548. parsedConfig = parse_command_line_config_svg(tag, vias, extendedOptions);
  549. }
  550. if (!parsedConfig) {
  551. parsedConfig = new SkCommandLineConfig(tag, simpleBackend, vias);
  552. }
  553. outResult->emplace_back(parsedConfig);
  554. }
  555. }