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