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