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