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 | } |
brianosman | 2047189 | 2016-12-02 06:43:32 -0800 | [diff] [blame] | 188 | // Subtle logic: If the config has a color space attached, we're going to be rendering to sRGB, |
| 189 | // so we need that capability. In addition, to get the widest test coverage, we DO NOT require |
| 190 | // that we can disable sRGB decode. (That's for rendering sRGB sources to legacy surfaces). |
| 191 | // |
| 192 | // If the config doesn't have a color space attached, we're going to be rendering in legacy |
| 193 | // mode. In that case, we can't allow a context to be created that has sRGB support without |
| 194 | // the ability to disable sRGB decode. Otherwise, all of our sRGB source resources will be |
| 195 | // treated as sRGB textures, but we will be unable to prevent the decode, causing them to be |
| 196 | // too dark. |
Brian Osman | 7039f74 | 2016-11-01 15:56:16 -0400 | [diff] [blame] | 197 | if (fColorSpace) { |
csmartdalton | 6270e55 | 2016-09-13 10:41:49 -0700 | [diff] [blame] | 198 | fContextOptions |= ContextOptions::kRequireSRGBSupport; |
brianosman | 2047189 | 2016-12-02 06:43:32 -0800 | [diff] [blame] | 199 | } else { |
| 200 | fContextOptions |= ContextOptions::kRequireSRGBDecodeDisableSupport; |
csmartdalton | 6270e55 | 2016-09-13 10:41:49 -0700 | [diff] [blame] | 201 | } |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 202 | } |
| 203 | static bool parse_option_int(const SkString& value, int* outInt) { |
| 204 | if (value.isEmpty()) { |
| 205 | return false; |
| 206 | } |
| 207 | char* endptr = nullptr; |
| 208 | long intValue = strtol(value.c_str(), &endptr, 10); |
| 209 | if (*endptr != '\0') { |
| 210 | return false; |
| 211 | } |
| 212 | *outInt = static_cast<int>(intValue); |
| 213 | return true; |
| 214 | } |
| 215 | static bool parse_option_bool(const SkString& value, bool* outBool) { |
| 216 | if (value.equals("true")) { |
| 217 | *outBool = true; |
| 218 | return true; |
| 219 | } |
| 220 | if (value.equals("false")) { |
| 221 | *outBool = false; |
| 222 | return true; |
| 223 | } |
| 224 | return false; |
| 225 | } |
| 226 | static bool parse_option_gpu_api(const SkString& value, |
| 227 | SkCommandLineConfigGpu::ContextType* outContextType) { |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 228 | if (value.equals("gl")) { |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 229 | *outContextType = GrContextFactory::kGL_ContextType; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 230 | return true; |
| 231 | } |
| 232 | if (value.equals("gles")) { |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 233 | *outContextType = GrContextFactory::kGLES_ContextType; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 234 | return true; |
| 235 | } |
| 236 | if (value.equals("debug")) { |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 237 | *outContextType = GrContextFactory::kDebugGL_ContextType; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 238 | return true; |
| 239 | } |
| 240 | if (value.equals("null")) { |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 241 | *outContextType = GrContextFactory::kNullGL_ContextType; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 242 | return true; |
| 243 | } |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 244 | if (value.equals("angle_d3d9_es2")) { |
| 245 | *outContextType = GrContextFactory::kANGLE_D3D9_ES2_ContextType; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 246 | return true; |
| 247 | } |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 248 | if (value.equals("angle_d3d11_es2")) { |
| 249 | *outContextType = GrContextFactory::kANGLE_D3D11_ES2_ContextType; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 250 | return true; |
| 251 | } |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 252 | if (value.equals("angle_d3d11_es3")) { |
| 253 | *outContextType = GrContextFactory::kANGLE_D3D11_ES3_ContextType; |
| 254 | return true; |
| 255 | } |
| 256 | if (value.equals("angle_gl_es2")) { |
| 257 | *outContextType = GrContextFactory::kANGLE_GL_ES2_ContextType; |
| 258 | return true; |
| 259 | } |
| 260 | if (value.equals("angle_gl_es3")) { |
| 261 | *outContextType = GrContextFactory::kANGLE_GL_ES3_ContextType; |
| 262 | return true; |
| 263 | } |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 264 | if (value.equals("commandbuffer")) { |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 265 | *outContextType = GrContextFactory::kCommandBuffer_ContextType; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 266 | return true; |
| 267 | } |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 268 | #if SK_MESA |
| 269 | if (value.equals("mesa")) { |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 270 | *outContextType = GrContextFactory::kMESA_ContextType; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 271 | return true; |
| 272 | } |
| 273 | #endif |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 274 | #ifdef SK_VULKAN |
| 275 | if (value.equals("vulkan")) { |
| 276 | *outContextType = GrContextFactory::kVulkan_ContextType; |
| 277 | return true; |
| 278 | } |
| 279 | #endif |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 280 | return false; |
| 281 | } |
brianosman | d93c120 | 2016-03-10 07:49:08 -0800 | [diff] [blame] | 282 | static bool parse_option_gpu_color(const SkString& value, |
| 283 | SkColorType* outColorType, |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 284 | sk_sp<SkColorSpace>* outColorSpace) { |
brianosman | d93c120 | 2016-03-10 07:49:08 -0800 | [diff] [blame] | 285 | if (value.equals("8888")) { |
bsalomon | 3306925 | 2016-09-28 08:49:53 -0700 | [diff] [blame] | 286 | *outColorType = kRGBA_8888_SkColorType; |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 287 | *outColorSpace = nullptr; |
brianosman | d93c120 | 2016-03-10 07:49:08 -0800 | [diff] [blame] | 288 | return true; |
| 289 | } |
brianosman | 4562f6e | 2016-09-19 14:42:04 -0700 | [diff] [blame] | 290 | |
| 291 | SkTArray<SkString> commands; |
| 292 | SkStrSplit(value.c_str(), "_", &commands); |
| 293 | if (commands.count() < 1 || commands.count() > 2) { |
| 294 | return false; |
| 295 | } |
| 296 | |
| 297 | // First, figure out color gamut that we'll work in (default to sRGB) |
raftias | 9488833 | 2016-10-18 10:02:51 -0700 | [diff] [blame] | 298 | const bool linearGamma = commands[0].equals("f16"); |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame] | 299 | *outColorSpace = SkColorSpace::MakeNamed(linearGamma ? SkColorSpace::kSRGBLinear_Named |
| 300 | : SkColorSpace::kSRGB_Named); |
brianosman | 4562f6e | 2016-09-19 14:42:04 -0700 | [diff] [blame] | 301 | if (commands.count() == 2) { |
| 302 | if (commands[1].equals("srgb")) { |
| 303 | // sRGB gamut (which is our default) |
| 304 | } else if (commands[1].equals("wide")) { |
| 305 | // WideGamut RGB |
| 306 | const float gWideGamutRGB_toXYZD50[]{ |
| 307 | 0.7161046f, 0.1009296f, 0.1471858f, // -> X |
| 308 | 0.2581874f, 0.7249378f, 0.0168748f, // -> Y |
| 309 | 0.0000000f, 0.0517813f, 0.7734287f, // -> Z |
| 310 | }; |
| 311 | SkMatrix44 wideGamutRGBMatrix(SkMatrix44::kUninitialized_Constructor); |
| 312 | wideGamutRGBMatrix.set3x3RowMajorf(gWideGamutRGB_toXYZD50); |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame] | 313 | *outColorSpace = SkColorSpace::MakeRGB(linearGamma |
raftias | 9488833 | 2016-10-18 10:02:51 -0700 | [diff] [blame] | 314 | ? SkColorSpace::kLinear_RenderTargetGamma |
| 315 | : SkColorSpace::kSRGB_RenderTargetGamma, |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame] | 316 | wideGamutRGBMatrix); |
Brian Osman | 4a6b28e | 2016-10-17 11:14:02 -0400 | [diff] [blame] | 317 | } else if (commands[1].equals("narrow")) { |
| 318 | // NarrowGamut RGB (an artifically smaller than sRGB gamut) |
| 319 | SkColorSpacePrimaries primaries ={ |
| 320 | 0.54f, 0.33f, // Rx, Ry |
| 321 | 0.33f, 0.50f, // Gx, Gy |
| 322 | 0.25f, 0.20f, // Bx, By |
| 323 | 0.3127f, 0.3290f, // Wx, Wy |
| 324 | }; |
| 325 | SkMatrix44 narrowGamutRGBMatrix(SkMatrix44::kUninitialized_Constructor); |
| 326 | primaries.toXYZD50(&narrowGamutRGBMatrix); |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame] | 327 | *outColorSpace = SkColorSpace::MakeRGB(linearGamma |
raftias | 9488833 | 2016-10-18 10:02:51 -0700 | [diff] [blame] | 328 | ? SkColorSpace::kLinear_RenderTargetGamma |
| 329 | : SkColorSpace::kSRGB_RenderTargetGamma, |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame] | 330 | narrowGamutRGBMatrix); |
brianosman | 4562f6e | 2016-09-19 14:42:04 -0700 | [diff] [blame] | 331 | } else { |
| 332 | // Unknown color gamut |
| 333 | return false; |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | // Now pick a color type |
| 338 | if (commands[0].equals("f16")) { |
brianosman | d93c120 | 2016-03-10 07:49:08 -0800 | [diff] [blame] | 339 | *outColorType = kRGBA_F16_SkColorType; |
brianosman | d93c120 | 2016-03-10 07:49:08 -0800 | [diff] [blame] | 340 | return true; |
| 341 | } |
brianosman | 4562f6e | 2016-09-19 14:42:04 -0700 | [diff] [blame] | 342 | if (commands[0].equals("srgb")) { |
bsalomon | 3306925 | 2016-09-28 08:49:53 -0700 | [diff] [blame] | 343 | *outColorType = kRGBA_8888_SkColorType; |
brianosman | d93c120 | 2016-03-10 07:49:08 -0800 | [diff] [blame] | 344 | return true; |
| 345 | } |
| 346 | return false; |
| 347 | } |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 348 | |
| 349 | SkCommandLineConfigGpu* parse_command_line_config_gpu(const SkString& tag, |
| 350 | const SkTArray<SkString>& vias, |
| 351 | const SkString& options) { |
| 352 | // Defaults for GPU backend. |
| 353 | bool seenAPI = false; |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 354 | SkCommandLineConfigGpu::ContextType contextType = GrContextFactory::kNativeGL_ContextType; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 355 | bool seenUseNVPR = false; |
| 356 | bool useNVPR = false; |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 357 | bool seenUseInstanced = false; |
| 358 | bool useInstanced = false; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 359 | bool seenUseDIText =false; |
| 360 | bool useDIText = false; |
| 361 | bool seenSamples = false; |
| 362 | int samples = 0; |
brianosman | d93c120 | 2016-03-10 07:49:08 -0800 | [diff] [blame] | 363 | bool seenColor = false; |
bsalomon | 3306925 | 2016-09-28 08:49:53 -0700 | [diff] [blame] | 364 | SkColorType colorType = kRGBA_8888_SkColorType; |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 365 | sk_sp<SkColorSpace> colorSpace = nullptr; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 366 | |
| 367 | SkTArray<SkString> optionParts; |
| 368 | SkStrSplit(options.c_str(), ",", kStrict_SkStrSplitMode, &optionParts); |
| 369 | for (int i = 0; i < optionParts.count(); ++i) { |
| 370 | SkTArray<SkString> keyValueParts; |
| 371 | SkStrSplit(optionParts[i].c_str(), "=", kStrict_SkStrSplitMode, &keyValueParts); |
| 372 | if (keyValueParts.count() != 2) { |
| 373 | return nullptr; |
| 374 | } |
| 375 | const SkString& key = keyValueParts[0]; |
| 376 | const SkString& value = keyValueParts[1]; |
| 377 | bool valueOk = false; |
| 378 | if (key.equals("api") && !seenAPI) { |
| 379 | valueOk = parse_option_gpu_api(value, &contextType); |
| 380 | seenAPI = true; |
| 381 | } else if (key.equals("nvpr") && !seenUseNVPR) { |
| 382 | valueOk = parse_option_bool(value, &useNVPR); |
| 383 | seenUseNVPR = true; |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 384 | } else if (key.equals("inst") && !seenUseInstanced) { |
| 385 | valueOk = parse_option_bool(value, &useInstanced); |
| 386 | seenUseInstanced = true; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 387 | } else if (key.equals("dit") && !seenUseDIText) { |
| 388 | valueOk = parse_option_bool(value, &useDIText); |
| 389 | seenUseDIText = true; |
| 390 | } else if (key.equals("samples") && !seenSamples) { |
| 391 | valueOk = parse_option_int(value, &samples); |
| 392 | seenSamples = true; |
brianosman | d93c120 | 2016-03-10 07:49:08 -0800 | [diff] [blame] | 393 | } else if (key.equals("color") && !seenColor) { |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 394 | valueOk = parse_option_gpu_color(value, &colorType, &colorSpace); |
brianosman | d93c120 | 2016-03-10 07:49:08 -0800 | [diff] [blame] | 395 | seenColor = true; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 396 | } |
| 397 | if (!valueOk) { |
| 398 | return nullptr; |
| 399 | } |
| 400 | } |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 401 | return new SkCommandLineConfigGpu(tag, vias, contextType, useNVPR, useInstanced, useDIText, |
| 402 | samples, colorType, colorSpace); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 403 | } |
| 404 | #endif |
| 405 | |
| 406 | void ParseConfigs(const SkCommandLineFlags::StringArray& configs, |
| 407 | SkCommandLineConfigArray* outResult) { |
| 408 | outResult->reset(); |
| 409 | for (int i = 0; i < configs.count(); ++i) { |
| 410 | SkString extendedBackend; |
| 411 | SkString extendedOptions; |
| 412 | SkString simpleBackend; |
| 413 | SkTArray<SkString> vias; |
| 414 | |
| 415 | SkString tag(configs[i]); |
| 416 | SkTArray<SkString> parts; |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 417 | SkStrSplit(tag.c_str(), "[", kStrict_SkStrSplitMode, &parts); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 418 | if (parts.count() == 2) { |
| 419 | SkTArray<SkString> parts2; |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 420 | SkStrSplit(parts[1].c_str(), "]", kStrict_SkStrSplitMode, &parts2); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 421 | if (parts2.count() == 2 && parts2[1].isEmpty()) { |
| 422 | SkStrSplit(parts[0].c_str(), "-", kStrict_SkStrSplitMode, &vias); |
| 423 | if (vias.count()) { |
| 424 | extendedBackend = vias[vias.count() - 1]; |
| 425 | vias.pop_back(); |
| 426 | } else { |
| 427 | extendedBackend = parts[0]; |
| 428 | } |
| 429 | extendedOptions = parts2[0]; |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 430 | simpleBackend.printf("%s[%s]", extendedBackend.c_str(), extendedOptions.c_str()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 431 | } |
| 432 | } |
| 433 | |
| 434 | if (extendedBackend.isEmpty()) { |
| 435 | simpleBackend = tag; |
| 436 | SkStrSplit(tag.c_str(), "-", kStrict_SkStrSplitMode, &vias); |
| 437 | if (vias.count()) { |
| 438 | simpleBackend = vias[vias.count() - 1]; |
| 439 | vias.pop_back(); |
| 440 | } |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 441 | for (auto& predefinedConfig : gPredefinedConfigs) { |
| 442 | if (simpleBackend.equals(predefinedConfig.predefinedConfig)) { |
| 443 | extendedBackend = predefinedConfig.backend; |
| 444 | extendedOptions = predefinedConfig.options; |
| 445 | break; |
| 446 | } |
| 447 | } |
| 448 | } |
| 449 | SkCommandLineConfig* parsedConfig = nullptr; |
| 450 | #if SK_SUPPORT_GPU |
| 451 | if (extendedBackend.equals("gpu")) { |
| 452 | parsedConfig = parse_command_line_config_gpu(tag, vias, extendedOptions); |
| 453 | } |
| 454 | #endif |
| 455 | if (!parsedConfig) { |
| 456 | parsedConfig = new SkCommandLineConfig(tag, simpleBackend, vias); |
| 457 | } |
| 458 | outResult->emplace_back(parsedConfig); |
| 459 | } |
| 460 | } |