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 | |
raftias | 7c602de | 2016-10-13 10:45:44 -0700 | [diff] [blame^] | 8 | #include "SkColorSpace_Base.h" |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 9 | #include "SkCommonFlagsConfig.h" |
csmartdalton | 6270e55 | 2016-09-13 10:41:49 -0700 | [diff] [blame] | 10 | #include "SkImageInfo.h" |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 11 | |
| 12 | #include <stdlib.h> |
| 13 | |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 14 | #if SK_SUPPORT_GPU |
| 15 | using sk_gpu_test::GrContextFactory; |
| 16 | #endif |
| 17 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 18 | static const char defaultConfigs[] = |
mtklein | 896ddb7 | 2016-09-14 10:33:12 -0700 | [diff] [blame] | 19 | "8888 gpu nonrendering" |
bsalomon | 7c2213b | 2016-09-29 10:07:22 -0700 | [diff] [blame] | 20 | #if SK_ANGLE |
| 21 | #ifdef SK_BUILD_FOR_WIN |
| 22 | " angle" |
| 23 | #endif |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 24 | #endif |
| 25 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 26 | " hwui" |
| 27 | #endif |
| 28 | ; |
| 29 | |
brianosman | 37e2334 | 2016-09-20 08:06:30 -0700 | [diff] [blame] | 30 | static const struct { |
| 31 | const char* predefinedConfig; |
| 32 | const char* backend; |
| 33 | const char* options; |
| 34 | } gPredefinedConfigs[] ={ |
| 35 | #if SK_SUPPORT_GPU |
bsalomon | 7c2213b | 2016-09-29 10:07:22 -0700 | [diff] [blame] | 36 | { "gpu", "gpu", "" }, |
| 37 | { "gl", "gpu", "api=gl" }, |
| 38 | { "msaa4", "gpu", "samples=4" }, |
| 39 | { "glmsaa4", "gpu", "api=gl,samples=4" }, |
| 40 | { "msaa16", "gpu", "samples=16" }, |
| 41 | { "nvpr4", "gpu", "nvpr=true,samples=4" }, |
| 42 | { "glnvpr4", "gpu", "api=gl,nvpr=true,samples=4" }, |
| 43 | { "nvpr16", "gpu", "nvpr=true,samples=16" }, |
| 44 | { "nvprdit4", "gpu", "nvpr=true,samples=4,dit=true" }, |
| 45 | { "glnvprdit4", "gpu", "api=gl,nvpr=true,samples=4,dit=true" }, |
| 46 | { "nvprdit16", "gpu", "nvpr=true,samples=16,dit=true" }, |
| 47 | { "glinst", "gpu", "api=gl,inst=true" }, |
| 48 | { "glinst4", "gpu", "api=gl,inst=true,samples=4" }, |
| 49 | { "glinstdit4", "gpu", "api=gl,inst=true,samples=4,dit=true" }, |
| 50 | { "glinst16", "gpu", "api=gl,inst=true,samples=16" }, |
| 51 | { "glinstdit16", "gpu", "api=gl,inst=true,samples=16,dit=true" }, |
| 52 | { "esinst", "gpu", "api=gles,inst=true" }, |
| 53 | { "esinst4", "gpu", "api=gles,inst=true,samples=4" }, |
| 54 | { "esinstdit4", "gpu", "api=gles,inst=true,samples=4,dit=true" }, |
| 55 | { "gpuf16", "gpu", "color=f16" }, |
| 56 | { "gpusrgb", "gpu", "color=srgb" }, |
| 57 | { "glsrgb", "gpu", "api=gl,color=srgb" }, |
| 58 | { "glwide", "gpu", "api=gl,color=f16_wide" }, |
| 59 | { "gpudft", "gpu", "dit=true" }, |
| 60 | { "gpudebug", "gpu", "api=debug" }, |
| 61 | { "gpunull", "gpu", "api=null" }, |
| 62 | { "debug", "gpu", "api=debug" }, |
| 63 | { "nullgpu", "gpu", "api=null" } |
| 64 | #if SK_ANGLE |
| 65 | #ifdef SK_BUILD_FOR_WIN |
| 66 | ,{ "angle", "gpu", "api=angle" } |
| 67 | #endif |
| 68 | ,{ "angle-gl", "gpu", "api=angle-gl" } |
| 69 | #endif |
| 70 | ,{ "commandbuffer", "gpu", "api=commandbuffer" } |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 71 | #if SK_MESA |
bsalomon | 7c2213b | 2016-09-29 10:07:22 -0700 | [diff] [blame] | 72 | ,{ "mesa", "gpu", "api=mesa" } |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 73 | #endif |
brianosman | 37e2334 | 2016-09-20 08:06:30 -0700 | [diff] [blame] | 74 | #ifdef SK_VULKAN |
bsalomon | 7c2213b | 2016-09-29 10:07:22 -0700 | [diff] [blame] | 75 | ,{ "vk", "gpu", "api=vulkan" } |
| 76 | ,{ "vksrgb", "gpu", "api=vulkan,color=srgb" } |
| 77 | ,{ "vkwide", "gpu", "api=vulkan,color=f16_wide" } |
| 78 | ,{ "vkmsaa4", "gpu", "api=vulkan,samples=4" } |
| 79 | ,{ "vkmsaa16", "gpu", "api=vulkan,samples=16" } |
brianosman | 37e2334 | 2016-09-20 08:06:30 -0700 | [diff] [blame] | 80 | #endif |
| 81 | |
| 82 | #else |
| 83 | { "", "", "" } |
| 84 | #endif |
| 85 | }; |
| 86 | |
| 87 | static const char configHelp[] = |
| 88 | "Options: 565 8888 srgb f16 nonrendering null pdf pdfa skp pipe svg xps" |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 89 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 90 | " hwui" |
| 91 | #endif |
brianosman | 37e2334 | 2016-09-20 08:06:30 -0700 | [diff] [blame] | 92 | ; |
| 93 | |
| 94 | static const char* config_help_fn() { |
| 95 | static SkString helpString; |
| 96 | helpString.set(configHelp); |
| 97 | for (const auto& config : gPredefinedConfigs) { |
| 98 | helpString.appendf(" %s", config.predefinedConfig); |
| 99 | } |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 100 | helpString.append(" or use extended form 'backend[option=value,...]'.\n"); |
brianosman | 37e2334 | 2016-09-20 08:06:30 -0700 | [diff] [blame] | 101 | return helpString.c_str(); |
| 102 | } |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 103 | |
| 104 | static const char configExtendedHelp[] = |
| 105 | "Extended form: 'backend(option=value,...)'\n\n" |
| 106 | "Possible backends and options:\n" |
| 107 | #if SK_SUPPORT_GPU |
| 108 | "\n" |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 109 | "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] | 110 | "\tapi\ttype: string\tdefault: native.\n" |
| 111 | "\t Select graphics API to use with gpu backend.\n" |
| 112 | "\t Options:\n" |
| 113 | "\t\tnative\t\t\tUse platform default OpenGL or OpenGL ES backend.\n" |
| 114 | "\t\tgl \t\t\tUse OpenGL.\n" |
| 115 | "\t\tgles \t\t\tUse OpenGL ES.\n" |
| 116 | "\t\tdebug \t\t\tUse debug OpenGL.\n" |
| 117 | "\t\tnull \t\t\tUse null OpenGL.\n" |
bsalomon | 7c2213b | 2016-09-29 10:07:22 -0700 | [diff] [blame] | 118 | #if SK_ANGLE |
| 119 | #ifdef SK_BUILD_FOR_WIN |
| 120 | "\t\tangle\t\t\tUse ANGLE DirectX.\n" |
| 121 | #endif |
| 122 | "\t\tangle-gl\t\t\tUse ANGLE OpenGL.\n" |
| 123 | #endif |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 124 | "\t\tcommandbuffer\t\tUse command buffer.\n" |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 125 | #if SK_MESA |
| 126 | "\t\tmesa\t\t\tUse MESA.\n" |
| 127 | #endif |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 128 | #ifdef SK_VULKAN |
| 129 | "\t\tvulkan\t\t\tUse Vulkan.\n" |
| 130 | #endif |
brianosman | d93c120 | 2016-03-10 07:49:08 -0800 | [diff] [blame] | 131 | "\tcolor\ttype: string\tdefault: 8888.\n" |
| 132 | "\t Select framebuffer color format.\n" |
| 133 | "\t Options:\n" |
| 134 | "\t\t8888\t\t\tLinear 8888.\n" |
brianosman | 4562f6e | 2016-09-19 14:42:04 -0700 | [diff] [blame] | 135 | "\t\tf16{_gamut}\t\tLinear 16-bit floating point.\n" |
| 136 | "\t\tsrgb{_gamut}\t\tsRGB 8888.\n" |
| 137 | "\t gamut\ttype: string\tdefault: srgb.\n" |
| 138 | "\t Select color gamut for f16 or sRGB format buffers.\n" |
| 139 | "\t Options:\n" |
| 140 | "\t\tsrgb\t\t\tsRGB gamut.\n" |
| 141 | "\t\twide\t\t\tWide Gamut RGB.\n" |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 142 | "\tdit\ttype: bool\tdefault: false.\n" |
| 143 | "\t Use device independent text.\n" |
| 144 | "\tnvpr\ttype: bool\tdefault: false.\n" |
| 145 | "\t Use NV_path_rendering OpenGL and OpenGL ES extension.\n" |
| 146 | "\tsamples\ttype: int\tdefault: 0.\n" |
| 147 | "\t Use multisampling with N samples.\n" |
| 148 | "\n" |
| 149 | "Predefined configs:\n\n" |
brianosman | 37e2334 | 2016-09-20 08:06:30 -0700 | [diff] [blame] | 150 | // Help text for pre-defined configs is auto-generated from gPredefinedConfigs |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 151 | #endif |
| 152 | ; |
| 153 | |
brianosman | 37e2334 | 2016-09-20 08:06:30 -0700 | [diff] [blame] | 154 | static const char* config_extended_help_fn() { |
| 155 | static SkString helpString; |
| 156 | helpString.set(configExtendedHelp); |
| 157 | for (const auto& config : gPredefinedConfigs) { |
| 158 | helpString.appendf("\t%-10s\t= gpu(%s)\n", config.predefinedConfig, config.options); |
| 159 | } |
| 160 | return helpString.c_str(); |
| 161 | } |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 162 | |
brianosman | 37e2334 | 2016-09-20 08:06:30 -0700 | [diff] [blame] | 163 | DEFINE_extended_string(config, defaultConfigs, config_help_fn(), config_extended_help_fn()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 164 | |
| 165 | SkCommandLineConfig::SkCommandLineConfig(const SkString& tag, const SkString& backend, |
| 166 | const SkTArray<SkString>& viaParts) |
| 167 | : fTag(tag) |
| 168 | , fBackend(backend) |
| 169 | , fViaParts(viaParts) { |
| 170 | } |
| 171 | SkCommandLineConfig::~SkCommandLineConfig() { |
| 172 | } |
| 173 | |
| 174 | #if SK_SUPPORT_GPU |
| 175 | SkCommandLineConfigGpu::SkCommandLineConfigGpu( |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 176 | const SkString& tag, const SkTArray<SkString>& viaParts, ContextType contextType, bool useNVPR, |
| 177 | bool useInstanced, bool useDIText, int samples, SkColorType colorType, |
| 178 | sk_sp<SkColorSpace> colorSpace) |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 179 | : SkCommandLineConfig(tag, SkString("gpu"), viaParts) |
| 180 | , fContextType(contextType) |
csmartdalton | 6270e55 | 2016-09-13 10:41:49 -0700 | [diff] [blame] | 181 | , fContextOptions(ContextOptions::kNone) |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 182 | , fUseDIText(useDIText) |
brianosman | d93c120 | 2016-03-10 07:49:08 -0800 | [diff] [blame] | 183 | , fSamples(samples) |
| 184 | , fColorType(colorType) |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 185 | , fColorSpace(std::move(colorSpace)) { |
csmartdalton | 6270e55 | 2016-09-13 10:41:49 -0700 | [diff] [blame] | 186 | if (useNVPR) { |
| 187 | fContextOptions |= ContextOptions::kEnableNVPR; |
| 188 | } |
| 189 | if (useInstanced) { |
| 190 | fContextOptions |= ContextOptions::kUseInstanced; |
| 191 | } |
| 192 | if (SkColorAndColorSpaceAreGammaCorrect(colorType, colorSpace.get())) { |
| 193 | fContextOptions |= ContextOptions::kRequireSRGBSupport; |
| 194 | } |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 195 | } |
| 196 | static bool parse_option_int(const SkString& value, int* outInt) { |
| 197 | if (value.isEmpty()) { |
| 198 | return false; |
| 199 | } |
| 200 | char* endptr = nullptr; |
| 201 | long intValue = strtol(value.c_str(), &endptr, 10); |
| 202 | if (*endptr != '\0') { |
| 203 | return false; |
| 204 | } |
| 205 | *outInt = static_cast<int>(intValue); |
| 206 | return true; |
| 207 | } |
| 208 | static bool parse_option_bool(const SkString& value, bool* outBool) { |
| 209 | if (value.equals("true")) { |
| 210 | *outBool = true; |
| 211 | return true; |
| 212 | } |
| 213 | if (value.equals("false")) { |
| 214 | *outBool = false; |
| 215 | return true; |
| 216 | } |
| 217 | return false; |
| 218 | } |
| 219 | static bool parse_option_gpu_api(const SkString& value, |
| 220 | SkCommandLineConfigGpu::ContextType* outContextType) { |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 221 | if (value.equals("gl")) { |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 222 | *outContextType = GrContextFactory::kGL_ContextType; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 223 | return true; |
| 224 | } |
| 225 | if (value.equals("gles")) { |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 226 | *outContextType = GrContextFactory::kGLES_ContextType; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 227 | return true; |
| 228 | } |
| 229 | if (value.equals("debug")) { |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 230 | *outContextType = GrContextFactory::kDebugGL_ContextType; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 231 | return true; |
| 232 | } |
| 233 | if (value.equals("null")) { |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 234 | *outContextType = GrContextFactory::kNullGL_ContextType; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 235 | return true; |
| 236 | } |
bsalomon | 7c2213b | 2016-09-29 10:07:22 -0700 | [diff] [blame] | 237 | #if SK_ANGLE |
| 238 | #ifdef SK_BUILD_FOR_WIN |
| 239 | if (value.equals("angle")) { |
| 240 | *outContextType = GrContextFactory::kANGLE_ContextType; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 241 | return true; |
| 242 | } |
bsalomon | 7c2213b | 2016-09-29 10:07:22 -0700 | [diff] [blame] | 243 | #endif |
| 244 | if (value.equals("angle-gl")) { |
| 245 | *outContextType = GrContextFactory::kANGLE_GL_ContextType; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 246 | return true; |
| 247 | } |
bsalomon | 7c2213b | 2016-09-29 10:07:22 -0700 | [diff] [blame] | 248 | #endif |
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; |
raftias | 7c602de | 2016-10-13 10:45:44 -0700 | [diff] [blame^] | 307 | *outColorSpace = as_CSB(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 | } |
bsalomon | 7c2213b | 2016-09-29 10:07:22 -0700 | [diff] [blame] | 410 | // Note: no #if SK_ANGLE: this is a special rule in the via-tag grammar. |
| 411 | if (vias.count() && simpleBackend.equals("gl") && |
| 412 | vias[vias.count() - 1].equals("angle")) { |
| 413 | simpleBackend = "angle-gl"; |
| 414 | vias.pop_back(); |
| 415 | } |
| 416 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 417 | for (auto& predefinedConfig : gPredefinedConfigs) { |
| 418 | if (simpleBackend.equals(predefinedConfig.predefinedConfig)) { |
| 419 | extendedBackend = predefinedConfig.backend; |
| 420 | extendedOptions = predefinedConfig.options; |
| 421 | break; |
| 422 | } |
| 423 | } |
| 424 | } |
| 425 | SkCommandLineConfig* parsedConfig = nullptr; |
| 426 | #if SK_SUPPORT_GPU |
| 427 | if (extendedBackend.equals("gpu")) { |
| 428 | parsedConfig = parse_command_line_config_gpu(tag, vias, extendedOptions); |
| 429 | } |
| 430 | #endif |
| 431 | if (!parsedConfig) { |
| 432 | parsedConfig = new SkCommandLineConfig(tag, simpleBackend, vias); |
| 433 | } |
| 434 | outResult->emplace_back(parsedConfig); |
| 435 | } |
| 436 | } |