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