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 | |
| 8 | #include "SkCommonFlagsConfig.h" |
csmartdalton | 6270e55 | 2016-09-13 10:41:49 -0700 | [diff] [blame] | 9 | #include "SkImageInfo.h" |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 10 | |
| 11 | #include <stdlib.h> |
| 12 | |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 13 | #if SK_SUPPORT_GPU |
| 14 | using sk_gpu_test::GrContextFactory; |
| 15 | #endif |
| 16 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 17 | static const char defaultConfigs[] = |
mtklein | 896ddb7 | 2016-09-14 10:33:12 -0700 | [diff] [blame] | 18 | "8888 gpu nonrendering" |
bsalomon | 50094fb | 2016-09-29 09:49:06 -0700 | [diff] [blame^] | 19 | #if defined(SK_BUILD_FOR_WIN) |
| 20 | " angle_d3d11_es2" |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 21 | #endif |
| 22 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 23 | " hwui" |
| 24 | #endif |
| 25 | ; |
| 26 | |
brianosman | 37e2334 | 2016-09-20 08:06:30 -0700 | [diff] [blame] | 27 | static const struct { |
| 28 | const char* predefinedConfig; |
| 29 | const char* backend; |
| 30 | const char* options; |
| 31 | } gPredefinedConfigs[] ={ |
| 32 | #if SK_SUPPORT_GPU |
bsalomon | 50094fb | 2016-09-29 09:49:06 -0700 | [diff] [blame^] | 33 | { "gpu", "gpu", "" }, |
| 34 | { "gl", "gpu", "api=gl" }, |
| 35 | { "msaa4", "gpu", "samples=4" }, |
| 36 | { "glmsaa4", "gpu", "api=gl,samples=4" }, |
| 37 | { "msaa16", "gpu", "samples=16" }, |
| 38 | { "nvpr4", "gpu", "nvpr=true,samples=4" }, |
| 39 | { "glnvpr4", "gpu", "api=gl,nvpr=true,samples=4" }, |
| 40 | { "nvpr16", "gpu", "nvpr=true,samples=16" }, |
| 41 | { "nvprdit4", "gpu", "nvpr=true,samples=4,dit=true" }, |
| 42 | { "glnvprdit4", "gpu", "api=gl,nvpr=true,samples=4,dit=true" }, |
| 43 | { "nvprdit16", "gpu", "nvpr=true,samples=16,dit=true" }, |
| 44 | { "glinst", "gpu", "api=gl,inst=true" }, |
| 45 | { "glinst4", "gpu", "api=gl,inst=true,samples=4" }, |
| 46 | { "glinstdit4", "gpu", "api=gl,inst=true,samples=4,dit=true" }, |
| 47 | { "glinst16", "gpu", "api=gl,inst=true,samples=16" }, |
| 48 | { "glinstdit16", "gpu", "api=gl,inst=true,samples=16,dit=true" }, |
| 49 | { "esinst", "gpu", "api=gles,inst=true" }, |
| 50 | { "esinst4", "gpu", "api=gles,inst=true,samples=4" }, |
| 51 | { "esinstdit4", "gpu", "api=gles,inst=true,samples=4,dit=true" }, |
| 52 | { "gpuf16", "gpu", "color=f16" }, |
| 53 | { "gpusrgb", "gpu", "color=srgb" }, |
| 54 | { "glsrgb", "gpu", "api=gl,color=srgb" }, |
| 55 | { "glwide", "gpu", "api=gl,color=f16_wide" }, |
| 56 | { "gpudft", "gpu", "dit=true" }, |
| 57 | { "gpudebug", "gpu", "api=debug" }, |
| 58 | { "gpunull", "gpu", "api=null" }, |
| 59 | { "debug", "gpu", "api=debug" }, |
| 60 | { "nullgpu", "gpu", "api=null" }, |
| 61 | { "angle_d3d11_es2", "gpu", "api=angle_d3d11_es2" }, |
| 62 | { "angle_gl_es2", "gpu", "api=angle_gl_es2" }, |
| 63 | { "commandbuffer", "gpu", "api=commandbuffer" } |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 64 | #if SK_MESA |
bsalomon | 50094fb | 2016-09-29 09:49:06 -0700 | [diff] [blame^] | 65 | ,{ "mesa", "gpu", "api=mesa" } |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 66 | #endif |
brianosman | 37e2334 | 2016-09-20 08:06:30 -0700 | [diff] [blame] | 67 | #ifdef SK_VULKAN |
bsalomon | 50094fb | 2016-09-29 09:49:06 -0700 | [diff] [blame^] | 68 | ,{ "vk", "gpu", "api=vulkan" } |
| 69 | ,{ "vksrgb", "gpu", "api=vulkan,color=srgb" } |
| 70 | ,{ "vkwide", "gpu", "api=vulkan,color=f16_wide" } |
| 71 | ,{ "vkmsaa4", "gpu", "api=vulkan,samples=4" } |
| 72 | ,{ "vkmsaa16", "gpu", "api=vulkan,samples=16" } |
brianosman | 37e2334 | 2016-09-20 08:06:30 -0700 | [diff] [blame] | 73 | #endif |
| 74 | |
| 75 | #else |
| 76 | { "", "", "" } |
| 77 | #endif |
| 78 | }; |
| 79 | |
| 80 | static const char configHelp[] = |
| 81 | "Options: 565 8888 srgb f16 nonrendering null pdf pdfa skp pipe svg xps" |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 82 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 83 | " hwui" |
| 84 | #endif |
brianosman | 37e2334 | 2016-09-20 08:06:30 -0700 | [diff] [blame] | 85 | ; |
| 86 | |
| 87 | static const char* config_help_fn() { |
| 88 | static SkString helpString; |
| 89 | helpString.set(configHelp); |
| 90 | for (const auto& config : gPredefinedConfigs) { |
| 91 | helpString.appendf(" %s", config.predefinedConfig); |
| 92 | } |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 93 | helpString.append(" or use extended form 'backend[option=value,...]'.\n"); |
brianosman | 37e2334 | 2016-09-20 08:06:30 -0700 | [diff] [blame] | 94 | return helpString.c_str(); |
| 95 | } |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 96 | |
| 97 | static const char configExtendedHelp[] = |
| 98 | "Extended form: 'backend(option=value,...)'\n\n" |
| 99 | "Possible backends and options:\n" |
| 100 | #if SK_SUPPORT_GPU |
| 101 | "\n" |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 102 | "gpu[api=string,color=string,dit=bool,nvpr=bool,inst=bool,samples=int]\n" |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 103 | "\tapi\ttype: string\tdefault: native.\n" |
| 104 | "\t Select graphics API to use with gpu backend.\n" |
| 105 | "\t Options:\n" |
| 106 | "\t\tnative\t\t\tUse platform default OpenGL or OpenGL ES backend.\n" |
| 107 | "\t\tgl \t\t\tUse OpenGL.\n" |
| 108 | "\t\tgles \t\t\tUse OpenGL ES.\n" |
| 109 | "\t\tdebug \t\t\tUse debug OpenGL.\n" |
| 110 | "\t\tnull \t\t\tUse null OpenGL.\n" |
bsalomon | 50094fb | 2016-09-29 09:49:06 -0700 | [diff] [blame^] | 111 | "\t\tangle_d3d9_es2\t\t\tUse OpenGL ES2 on the ANGLE Direct3D9 backend.\n" |
| 112 | "\t\tangle_d3d11_es2\t\t\tUse OpenGL ES2 on the ANGLE Direct3D11 backend.\n" |
| 113 | "\t\tangle_d3d11_es3\t\t\tUse OpenGL ES3 on the ANGLE Direct3D11 backend.\n" |
| 114 | "\t\tangle_gl_es2\t\t\tUse OpenGL ES2 on the ANGLE OpenGL backend.\n" |
| 115 | "\t\tangle_gl_es3\t\t\tUse OpenGL ES3 on the ANGLE OpenGL backend.\n" |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 116 | "\t\tcommandbuffer\t\tUse command buffer.\n" |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 117 | #if SK_MESA |
| 118 | "\t\tmesa\t\t\tUse MESA.\n" |
| 119 | #endif |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 120 | #ifdef SK_VULKAN |
| 121 | "\t\tvulkan\t\t\tUse Vulkan.\n" |
| 122 | #endif |
brianosman | d93c120 | 2016-03-10 07:49:08 -0800 | [diff] [blame] | 123 | "\tcolor\ttype: string\tdefault: 8888.\n" |
| 124 | "\t Select framebuffer color format.\n" |
| 125 | "\t Options:\n" |
| 126 | "\t\t8888\t\t\tLinear 8888.\n" |
brianosman | 4562f6e | 2016-09-19 14:42:04 -0700 | [diff] [blame] | 127 | "\t\tf16{_gamut}\t\tLinear 16-bit floating point.\n" |
| 128 | "\t\tsrgb{_gamut}\t\tsRGB 8888.\n" |
| 129 | "\t gamut\ttype: string\tdefault: srgb.\n" |
| 130 | "\t Select color gamut for f16 or sRGB format buffers.\n" |
| 131 | "\t Options:\n" |
| 132 | "\t\tsrgb\t\t\tsRGB gamut.\n" |
| 133 | "\t\twide\t\t\tWide Gamut RGB.\n" |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 134 | "\tdit\ttype: bool\tdefault: false.\n" |
| 135 | "\t Use device independent text.\n" |
| 136 | "\tnvpr\ttype: bool\tdefault: false.\n" |
| 137 | "\t Use NV_path_rendering OpenGL and OpenGL ES extension.\n" |
| 138 | "\tsamples\ttype: int\tdefault: 0.\n" |
| 139 | "\t Use multisampling with N samples.\n" |
| 140 | "\n" |
| 141 | "Predefined configs:\n\n" |
brianosman | 37e2334 | 2016-09-20 08:06:30 -0700 | [diff] [blame] | 142 | // Help text for pre-defined configs is auto-generated from gPredefinedConfigs |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 143 | #endif |
| 144 | ; |
| 145 | |
brianosman | 37e2334 | 2016-09-20 08:06:30 -0700 | [diff] [blame] | 146 | static const char* config_extended_help_fn() { |
| 147 | static SkString helpString; |
| 148 | helpString.set(configExtendedHelp); |
| 149 | for (const auto& config : gPredefinedConfigs) { |
| 150 | helpString.appendf("\t%-10s\t= gpu(%s)\n", config.predefinedConfig, config.options); |
| 151 | } |
| 152 | return helpString.c_str(); |
| 153 | } |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 154 | |
brianosman | 37e2334 | 2016-09-20 08:06:30 -0700 | [diff] [blame] | 155 | DEFINE_extended_string(config, defaultConfigs, config_help_fn(), config_extended_help_fn()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 156 | |
| 157 | SkCommandLineConfig::SkCommandLineConfig(const SkString& tag, const SkString& backend, |
| 158 | const SkTArray<SkString>& viaParts) |
| 159 | : fTag(tag) |
| 160 | , fBackend(backend) |
| 161 | , fViaParts(viaParts) { |
| 162 | } |
| 163 | SkCommandLineConfig::~SkCommandLineConfig() { |
| 164 | } |
| 165 | |
| 166 | #if SK_SUPPORT_GPU |
| 167 | SkCommandLineConfigGpu::SkCommandLineConfigGpu( |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 168 | const SkString& tag, const SkTArray<SkString>& viaParts, ContextType contextType, bool useNVPR, |
| 169 | bool useInstanced, bool useDIText, int samples, SkColorType colorType, |
| 170 | sk_sp<SkColorSpace> colorSpace) |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 171 | : SkCommandLineConfig(tag, SkString("gpu"), viaParts) |
| 172 | , fContextType(contextType) |
csmartdalton | 6270e55 | 2016-09-13 10:41:49 -0700 | [diff] [blame] | 173 | , fContextOptions(ContextOptions::kNone) |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 174 | , fUseDIText(useDIText) |
brianosman | d93c120 | 2016-03-10 07:49:08 -0800 | [diff] [blame] | 175 | , fSamples(samples) |
| 176 | , fColorType(colorType) |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 177 | , fColorSpace(std::move(colorSpace)) { |
csmartdalton | 6270e55 | 2016-09-13 10:41:49 -0700 | [diff] [blame] | 178 | if (useNVPR) { |
| 179 | fContextOptions |= ContextOptions::kEnableNVPR; |
| 180 | } |
| 181 | if (useInstanced) { |
| 182 | fContextOptions |= ContextOptions::kUseInstanced; |
| 183 | } |
| 184 | if (SkColorAndColorSpaceAreGammaCorrect(colorType, colorSpace.get())) { |
| 185 | fContextOptions |= ContextOptions::kRequireSRGBSupport; |
| 186 | } |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 187 | } |
| 188 | static bool parse_option_int(const SkString& value, int* outInt) { |
| 189 | if (value.isEmpty()) { |
| 190 | return false; |
| 191 | } |
| 192 | char* endptr = nullptr; |
| 193 | long intValue = strtol(value.c_str(), &endptr, 10); |
| 194 | if (*endptr != '\0') { |
| 195 | return false; |
| 196 | } |
| 197 | *outInt = static_cast<int>(intValue); |
| 198 | return true; |
| 199 | } |
| 200 | static bool parse_option_bool(const SkString& value, bool* outBool) { |
| 201 | if (value.equals("true")) { |
| 202 | *outBool = true; |
| 203 | return true; |
| 204 | } |
| 205 | if (value.equals("false")) { |
| 206 | *outBool = false; |
| 207 | return true; |
| 208 | } |
| 209 | return false; |
| 210 | } |
| 211 | static bool parse_option_gpu_api(const SkString& value, |
| 212 | SkCommandLineConfigGpu::ContextType* outContextType) { |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 213 | if (value.equals("gl")) { |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 214 | *outContextType = GrContextFactory::kGL_ContextType; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 215 | return true; |
| 216 | } |
| 217 | if (value.equals("gles")) { |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 218 | *outContextType = GrContextFactory::kGLES_ContextType; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 219 | return true; |
| 220 | } |
| 221 | if (value.equals("debug")) { |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 222 | *outContextType = GrContextFactory::kDebugGL_ContextType; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 223 | return true; |
| 224 | } |
| 225 | if (value.equals("null")) { |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 226 | *outContextType = GrContextFactory::kNullGL_ContextType; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 227 | return true; |
| 228 | } |
bsalomon | 50094fb | 2016-09-29 09:49:06 -0700 | [diff] [blame^] | 229 | if (value.equals("angle_d3d9_es2")) { |
| 230 | *outContextType = GrContextFactory::kANGLE_D3D9_ES2_ContextType; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 231 | return true; |
| 232 | } |
bsalomon | 50094fb | 2016-09-29 09:49:06 -0700 | [diff] [blame^] | 233 | if (value.equals("angle_d3d11_es2")) { |
| 234 | *outContextType = GrContextFactory::kANGLE_D3D11_ES2_ContextType; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 235 | return true; |
| 236 | } |
bsalomon | 50094fb | 2016-09-29 09:49:06 -0700 | [diff] [blame^] | 237 | if (value.equals("angle_d3d11_es3")) { |
| 238 | *outContextType = GrContextFactory::kANGLE_D3D11_ES3_ContextType; |
| 239 | return true; |
| 240 | } |
| 241 | if (value.equals("angle_gl_es2")) { |
| 242 | *outContextType = GrContextFactory::kANGLE_GL_ES2_ContextType; |
| 243 | return true; |
| 244 | } |
| 245 | if (value.equals("angle_gl_es3")) { |
| 246 | *outContextType = GrContextFactory::kANGLE_GL_ES3_ContextType; |
| 247 | return true; |
| 248 | } |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 249 | if (value.equals("commandbuffer")) { |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 250 | *outContextType = GrContextFactory::kCommandBuffer_ContextType; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 251 | return true; |
| 252 | } |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 253 | #if SK_MESA |
| 254 | if (value.equals("mesa")) { |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 255 | *outContextType = GrContextFactory::kMESA_ContextType; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 256 | return true; |
| 257 | } |
| 258 | #endif |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 259 | #ifdef SK_VULKAN |
| 260 | if (value.equals("vulkan")) { |
| 261 | *outContextType = GrContextFactory::kVulkan_ContextType; |
| 262 | return true; |
| 263 | } |
| 264 | #endif |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 265 | return false; |
| 266 | } |
brianosman | d93c120 | 2016-03-10 07:49:08 -0800 | [diff] [blame] | 267 | static bool parse_option_gpu_color(const SkString& value, |
| 268 | SkColorType* outColorType, |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 269 | sk_sp<SkColorSpace>* outColorSpace) { |
brianosman | d93c120 | 2016-03-10 07:49:08 -0800 | [diff] [blame] | 270 | if (value.equals("8888")) { |
bsalomon | 3306925 | 2016-09-28 08:49:53 -0700 | [diff] [blame] | 271 | *outColorType = kRGBA_8888_SkColorType; |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 272 | *outColorSpace = nullptr; |
brianosman | d93c120 | 2016-03-10 07:49:08 -0800 | [diff] [blame] | 273 | return true; |
| 274 | } |
brianosman | 4562f6e | 2016-09-19 14:42:04 -0700 | [diff] [blame] | 275 | |
| 276 | SkTArray<SkString> commands; |
| 277 | SkStrSplit(value.c_str(), "_", &commands); |
| 278 | if (commands.count() < 1 || commands.count() > 2) { |
| 279 | return false; |
| 280 | } |
| 281 | |
| 282 | // First, figure out color gamut that we'll work in (default to sRGB) |
| 283 | sk_sp<SkColorSpace> colorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); |
| 284 | if (commands.count() == 2) { |
| 285 | if (commands[1].equals("srgb")) { |
| 286 | // sRGB gamut (which is our default) |
| 287 | } else if (commands[1].equals("wide")) { |
| 288 | // WideGamut RGB |
| 289 | const float gWideGamutRGB_toXYZD50[]{ |
| 290 | 0.7161046f, 0.1009296f, 0.1471858f, // -> X |
| 291 | 0.2581874f, 0.7249378f, 0.0168748f, // -> Y |
| 292 | 0.0000000f, 0.0517813f, 0.7734287f, // -> Z |
| 293 | }; |
| 294 | SkMatrix44 wideGamutRGBMatrix(SkMatrix44::kUninitialized_Constructor); |
| 295 | wideGamutRGBMatrix.set3x3RowMajorf(gWideGamutRGB_toXYZD50); |
| 296 | colorSpace = SkColorSpace::NewRGB(SkColorSpace::kSRGB_RenderTargetGamma, |
| 297 | wideGamutRGBMatrix); |
| 298 | } else { |
| 299 | // Unknown color gamut |
| 300 | return false; |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | // Now pick a color type |
| 305 | if (commands[0].equals("f16")) { |
brianosman | d93c120 | 2016-03-10 07:49:08 -0800 | [diff] [blame] | 306 | *outColorType = kRGBA_F16_SkColorType; |
brianosman | 4562f6e | 2016-09-19 14:42:04 -0700 | [diff] [blame] | 307 | *outColorSpace = colorSpace->makeLinearGamma(); |
brianosman | d93c120 | 2016-03-10 07:49:08 -0800 | [diff] [blame] | 308 | return true; |
| 309 | } |
brianosman | 4562f6e | 2016-09-19 14:42:04 -0700 | [diff] [blame] | 310 | if (commands[0].equals("srgb")) { |
bsalomon | 3306925 | 2016-09-28 08:49:53 -0700 | [diff] [blame] | 311 | *outColorType = kRGBA_8888_SkColorType; |
brianosman | 4562f6e | 2016-09-19 14:42:04 -0700 | [diff] [blame] | 312 | *outColorSpace = colorSpace; |
brianosman | d93c120 | 2016-03-10 07:49:08 -0800 | [diff] [blame] | 313 | return true; |
| 314 | } |
| 315 | return false; |
| 316 | } |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 317 | |
| 318 | SkCommandLineConfigGpu* parse_command_line_config_gpu(const SkString& tag, |
| 319 | const SkTArray<SkString>& vias, |
| 320 | const SkString& options) { |
| 321 | // Defaults for GPU backend. |
| 322 | bool seenAPI = false; |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 323 | SkCommandLineConfigGpu::ContextType contextType = GrContextFactory::kNativeGL_ContextType; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 324 | bool seenUseNVPR = false; |
| 325 | bool useNVPR = false; |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 326 | bool seenUseInstanced = false; |
| 327 | bool useInstanced = false; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 328 | bool seenUseDIText =false; |
| 329 | bool useDIText = false; |
| 330 | bool seenSamples = false; |
| 331 | int samples = 0; |
brianosman | d93c120 | 2016-03-10 07:49:08 -0800 | [diff] [blame] | 332 | bool seenColor = false; |
bsalomon | 3306925 | 2016-09-28 08:49:53 -0700 | [diff] [blame] | 333 | SkColorType colorType = kRGBA_8888_SkColorType; |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 334 | sk_sp<SkColorSpace> colorSpace = nullptr; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 335 | |
| 336 | SkTArray<SkString> optionParts; |
| 337 | SkStrSplit(options.c_str(), ",", kStrict_SkStrSplitMode, &optionParts); |
| 338 | for (int i = 0; i < optionParts.count(); ++i) { |
| 339 | SkTArray<SkString> keyValueParts; |
| 340 | SkStrSplit(optionParts[i].c_str(), "=", kStrict_SkStrSplitMode, &keyValueParts); |
| 341 | if (keyValueParts.count() != 2) { |
| 342 | return nullptr; |
| 343 | } |
| 344 | const SkString& key = keyValueParts[0]; |
| 345 | const SkString& value = keyValueParts[1]; |
| 346 | bool valueOk = false; |
| 347 | if (key.equals("api") && !seenAPI) { |
| 348 | valueOk = parse_option_gpu_api(value, &contextType); |
| 349 | seenAPI = true; |
| 350 | } else if (key.equals("nvpr") && !seenUseNVPR) { |
| 351 | valueOk = parse_option_bool(value, &useNVPR); |
| 352 | seenUseNVPR = true; |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 353 | } else if (key.equals("inst") && !seenUseInstanced) { |
| 354 | valueOk = parse_option_bool(value, &useInstanced); |
| 355 | seenUseInstanced = true; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 356 | } else if (key.equals("dit") && !seenUseDIText) { |
| 357 | valueOk = parse_option_bool(value, &useDIText); |
| 358 | seenUseDIText = true; |
| 359 | } else if (key.equals("samples") && !seenSamples) { |
| 360 | valueOk = parse_option_int(value, &samples); |
| 361 | seenSamples = true; |
brianosman | d93c120 | 2016-03-10 07:49:08 -0800 | [diff] [blame] | 362 | } else if (key.equals("color") && !seenColor) { |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 363 | valueOk = parse_option_gpu_color(value, &colorType, &colorSpace); |
brianosman | d93c120 | 2016-03-10 07:49:08 -0800 | [diff] [blame] | 364 | seenColor = true; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 365 | } |
| 366 | if (!valueOk) { |
| 367 | return nullptr; |
| 368 | } |
| 369 | } |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 370 | return new SkCommandLineConfigGpu(tag, vias, contextType, useNVPR, useInstanced, useDIText, |
| 371 | samples, colorType, colorSpace); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 372 | } |
| 373 | #endif |
| 374 | |
| 375 | void ParseConfigs(const SkCommandLineFlags::StringArray& configs, |
| 376 | SkCommandLineConfigArray* outResult) { |
| 377 | outResult->reset(); |
| 378 | for (int i = 0; i < configs.count(); ++i) { |
| 379 | SkString extendedBackend; |
| 380 | SkString extendedOptions; |
| 381 | SkString simpleBackend; |
| 382 | SkTArray<SkString> vias; |
| 383 | |
| 384 | SkString tag(configs[i]); |
| 385 | SkTArray<SkString> parts; |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 386 | SkStrSplit(tag.c_str(), "[", kStrict_SkStrSplitMode, &parts); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 387 | if (parts.count() == 2) { |
| 388 | SkTArray<SkString> parts2; |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 389 | SkStrSplit(parts[1].c_str(), "]", kStrict_SkStrSplitMode, &parts2); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 390 | if (parts2.count() == 2 && parts2[1].isEmpty()) { |
| 391 | SkStrSplit(parts[0].c_str(), "-", kStrict_SkStrSplitMode, &vias); |
| 392 | if (vias.count()) { |
| 393 | extendedBackend = vias[vias.count() - 1]; |
| 394 | vias.pop_back(); |
| 395 | } else { |
| 396 | extendedBackend = parts[0]; |
| 397 | } |
| 398 | extendedOptions = parts2[0]; |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 399 | simpleBackend.printf("%s[%s]", extendedBackend.c_str(), extendedOptions.c_str()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 400 | } |
| 401 | } |
| 402 | |
| 403 | if (extendedBackend.isEmpty()) { |
| 404 | simpleBackend = tag; |
| 405 | SkStrSplit(tag.c_str(), "-", kStrict_SkStrSplitMode, &vias); |
| 406 | if (vias.count()) { |
| 407 | simpleBackend = vias[vias.count() - 1]; |
| 408 | vias.pop_back(); |
| 409 | } |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 410 | for (auto& predefinedConfig : gPredefinedConfigs) { |
| 411 | if (simpleBackend.equals(predefinedConfig.predefinedConfig)) { |
| 412 | extendedBackend = predefinedConfig.backend; |
| 413 | extendedOptions = predefinedConfig.options; |
| 414 | break; |
| 415 | } |
| 416 | } |
| 417 | } |
| 418 | SkCommandLineConfig* parsedConfig = nullptr; |
| 419 | #if SK_SUPPORT_GPU |
| 420 | if (extendedBackend.equals("gpu")) { |
| 421 | parsedConfig = parse_command_line_config_gpu(tag, vias, extendedOptions); |
| 422 | } |
| 423 | #endif |
| 424 | if (!parsedConfig) { |
| 425 | parsedConfig = new SkCommandLineConfig(tag, simpleBackend, vias); |
| 426 | } |
| 427 | outResult->emplace_back(parsedConfig); |
| 428 | } |
| 429 | } |