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