blob: d38d70a1dc527b2b9c05313780608387265259a6 [file] [log] [blame]
kkinnunen3e980c32015-12-23 01:33:00 -08001/*
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
8#include "SkCommonFlagsConfig.h"
csmartdalton6270e552016-09-13 10:41:49 -07009#include "SkImageInfo.h"
kkinnunen3e980c32015-12-23 01:33:00 -080010
11#include <stdlib.h>
12
bsalomon3724e572016-03-30 18:56:19 -070013#if SK_SUPPORT_GPU
14using sk_gpu_test::GrContextFactory;
15#endif
16
Brian Salomon6405e712017-03-20 08:54:16 -040017#if defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_IOS)
18# define DEFAULT_GPU_CONFIG "gles"
19#else
20# define DEFAULT_GPU_CONFIG "gl"
21#endif
22
kkinnunen3e980c32015-12-23 01:33:00 -080023static const char defaultConfigs[] =
Brian Salomon6405e712017-03-20 08:54:16 -040024 "8888 " DEFAULT_GPU_CONFIG " nonrendering "
bsalomon11abd8d2016-10-14 08:13:48 -070025#if defined(SK_BUILD_FOR_WIN)
26 " angle_d3d11_es2"
kkinnunen3e980c32015-12-23 01:33:00 -080027#endif
kkinnunen3e980c32015-12-23 01:33:00 -080028 ;
29
Brian Salomon6405e712017-03-20 08:54:16 -040030#undef DEFAULT_GPU_CONFIG
31
brianosman37e23342016-09-20 08:06:30 -070032static const struct {
33 const char* predefinedConfig;
34 const char* backend;
35 const char* options;
36} gPredefinedConfigs[] ={
37#if SK_SUPPORT_GPU
Brian Salomon002c1202016-10-18 11:28:20 -040038 { "gl", "gpu", "api=gl" },
Brian Salomon50f66d82017-03-17 14:32:05 -040039 { "gles", "gpu", "api=gles" },
Brian Salomon002c1202016-10-18 11:28:20 -040040 { "glmsaa4", "gpu", "api=gl,samples=4" },
Brian Salomondcf0ab02017-03-20 11:10:21 -040041 { "glmsaa8" , "gpu", "api=gl,samples=8" },
Brian Salomon50f66d82017-03-17 14:32:05 -040042 { "glesmsaa4", "gpu", "api=gles,samples=4" },
Brian Salomon002c1202016-10-18 11:28:20 -040043 { "glnvpr4", "gpu", "api=gl,nvpr=true,samples=4" },
Brian Salomondcf0ab02017-03-20 11:10:21 -040044 { "glnvpr8" , "gpu", "api=gl,nvpr=true,samples=8" },
Brian Salomon002c1202016-10-18 11:28:20 -040045 { "glnvprdit4", "gpu", "api=gl,nvpr=true,samples=4,dit=true" },
Brian Salomondcf0ab02017-03-20 11:10:21 -040046 { "glnvprdit8" , "gpu", "api=gl,nvpr=true,samples=8,dit=true" },
Brian Salomon50f66d82017-03-17 14:32:05 -040047 { "glesnvpr4", "gpu", "api=gles,nvpr=true,samples=4" },
48 { "glesnvprdit4", "gpu", "api=gles,nvpr=true,samples=4,dit=true" },
Brian Salomonce5ee602017-07-17 11:31:31 -040049 { "gl4444", "gpu", "api=gl,color=4444" },
50 { "gl565", "gpu", "api=gl,color=565" },
Brian Salomon6405e712017-03-20 08:54:16 -040051 { "glf16", "gpu", "api=gl,color=f16" },
52 { "glsrgb", "gpu", "api=gl,color=srgb" },
53 { "glsrgbnl", "gpu", "api=gl,color=srgbnl" },
54 { "glesf16", "gpu", "api=gles,color=f16" },
55 { "glessrgb", "gpu", "api=gles,color=srgb" },
56 { "glessrgbnl", "gpu", "api=gles,color=srgbnl" },
Brian Salomon002c1202016-10-18 11:28:20 -040057 { "glsrgb", "gpu", "api=gl,color=srgb" },
58 { "glwide", "gpu", "api=gl,color=f16_wide" },
59 { "glnarrow", "gpu", "api=gl,color=f16_narrow" },
Eric Karl5c779752017-05-08 12:02:07 -070060 { "glnostencils", "gpu", "api=gl,stencils=false" },
Brian Salomond1e61922018-01-24 17:25:03 -050061 { "gles4444", "gpu", "api=gles,color=4444" },
Brian Salomon50f66d82017-03-17 14:32:05 -040062 { "glessrgb", "gpu", "api=gles,color=srgb" },
63 { "gleswide", "gpu", "api=gles,color=f16_wide" },
64 { "glesnarrow", "gpu", "api=gles,color=f16_narrow" },
Brian Salomon50f66d82017-03-17 14:32:05 -040065 { "gldft", "gpu", "api=gl,dit=true" },
66 { "glesdft", "gpu", "api=gles,dit=true" },
Brian Osmanf9810662017-08-30 10:02:10 -040067 { "gltestthreading", "gpu", "api=gl,testThreading=true" },
Brian Salomon6405e712017-03-20 08:54:16 -040068 { "debuggl", "gpu", "api=debuggl" },
69 { "nullgl", "gpu", "api=nullgl" },
Brian Salomon002c1202016-10-18 11:28:20 -040070 { "angle_d3d11_es2", "gpu", "api=angle_d3d11_es2" },
Brian Osman21d742d2017-01-10 13:31:33 -050071 { "angle_d3d11_es3", "gpu", "api=angle_d3d11_es3" },
Brian Salomon002c1202016-10-18 11:28:20 -040072 { "angle_d3d9_es2", "gpu", "api=angle_d3d9_es2" },
73 { "angle_d3d11_es2_msaa4", "gpu", "api=angle_d3d11_es2,samples=4" },
Brian Salomon528ca9b2017-03-24 11:15:09 -040074 { "angle_d3d11_es2_msaa8", "gpu", "api=angle_d3d11_es2,samples=8" },
Brian Salomon8c865882017-06-22 09:56:24 -040075 { "angle_d3d11_es3_msaa4", "gpu", "api=angle_d3d11_es3,samples=4" },
76 { "angle_d3d11_es3_msaa8", "gpu", "api=angle_d3d11_es3,samples=8" },
Brian Salomon002c1202016-10-18 11:28:20 -040077 { "angle_gl_es2", "gpu", "api=angle_gl_es2" },
Brian Osman21d742d2017-01-10 13:31:33 -050078 { "angle_gl_es3", "gpu", "api=angle_gl_es3" },
Brian Salomon8fe24272017-07-07 12:56:11 -040079 { "commandbuffer", "gpu", "api=commandbuffer" },
80 { "mock", "gpu", "api=mock" }
brianosman37e23342016-09-20 08:06:30 -070081#ifdef SK_VULKAN
Brian Salomon002c1202016-10-18 11:28:20 -040082 ,{ "vk", "gpu", "api=vulkan" }
83 ,{ "vksrgb", "gpu", "api=vulkan,color=srgb" }
84 ,{ "vkwide", "gpu", "api=vulkan,color=f16_wide" }
85 ,{ "vkmsaa4", "gpu", "api=vulkan,samples=4" }
Brian Salomondcf0ab02017-03-20 11:10:21 -040086 ,{ "vkmsaa8", "gpu", "api=vulkan,samples=8" }
brianosman37e23342016-09-20 08:06:30 -070087#endif
Greg Daniel2811aa22017-07-13 15:34:56 -040088#ifdef SK_METAL
89 ,{ "mtl", "gpu", "api=metal" }
90 ,{ "mtlsrgb", "gpu", "api=metal,color=srgb" }
91 ,{ "mtlwide", "gpu", "api=metal,color=f16_wide" }
92 ,{ "mtlmsaa4", "gpu", "api=metal,samples=4" }
93 ,{ "mtlmsaa8", "gpu", "api=metal,samples=8" }
94#endif
brianosman37e23342016-09-20 08:06:30 -070095#else
Brian Salomon8fe24272017-07-07 12:56:11 -040096 { "", "", "" }
brianosman37e23342016-09-20 08:06:30 -070097#endif
98};
99
100static const char configHelp[] =
Derek Sollenbergerc65386a2017-01-05 09:50:22 -0500101 "Options: 565 8888 srgb f16 nonrendering null pdf pdfa skp pipe svg xps";
brianosman37e23342016-09-20 08:06:30 -0700102
103static const char* config_help_fn() {
104 static SkString helpString;
105 helpString.set(configHelp);
106 for (const auto& config : gPredefinedConfigs) {
107 helpString.appendf(" %s", config.predefinedConfig);
108 }
bsalomon808ecbb2016-09-28 12:40:22 -0700109 helpString.append(" or use extended form 'backend[option=value,...]'.\n");
brianosman37e23342016-09-20 08:06:30 -0700110 return helpString.c_str();
111}
kkinnunen3e980c32015-12-23 01:33:00 -0800112
113static const char configExtendedHelp[] =
114 "Extended form: 'backend(option=value,...)'\n\n"
115 "Possible backends and options:\n"
116#if SK_SUPPORT_GPU
117 "\n"
bsalomon808ecbb2016-09-28 12:40:22 -0700118 "gpu[api=string,color=string,dit=bool,nvpr=bool,inst=bool,samples=int]\n"
Brian Salomon6405e712017-03-20 08:54:16 -0400119 "\tapi\ttype: string\trequired\n"
kkinnunen3e980c32015-12-23 01:33:00 -0800120 "\t Select graphics API to use with gpu backend.\n"
121 "\t Options:\n"
kkinnunen3e980c32015-12-23 01:33:00 -0800122 "\t\tgl \t\t\tUse OpenGL.\n"
123 "\t\tgles \t\t\tUse OpenGL ES.\n"
Brian Salomon6405e712017-03-20 08:54:16 -0400124 "\t\tdebuggl \t\t\tUse debug OpenGL.\n"
125 "\t\tnullgl \t\t\tUse null OpenGL.\n"
bsalomon11abd8d2016-10-14 08:13:48 -0700126 "\t\tangle_d3d9_es2\t\t\tUse OpenGL ES2 on the ANGLE Direct3D9 backend.\n"
127 "\t\tangle_d3d11_es2\t\t\tUse OpenGL ES2 on the ANGLE Direct3D11 backend.\n"
128 "\t\tangle_d3d11_es3\t\t\tUse OpenGL ES3 on the ANGLE Direct3D11 backend.\n"
129 "\t\tangle_gl_es2\t\t\tUse OpenGL ES2 on the ANGLE OpenGL backend.\n"
130 "\t\tangle_gl_es3\t\t\tUse OpenGL ES3 on the ANGLE OpenGL backend.\n"
kkinnunen3e980c32015-12-23 01:33:00 -0800131 "\t\tcommandbuffer\t\tUse command buffer.\n"
Brian Salomon8fe24272017-07-07 12:56:11 -0400132 "\t\tmock\t\tUse mock context.\n"
bsalomondc0fcd42016-04-11 14:21:33 -0700133#ifdef SK_VULKAN
134 "\t\tvulkan\t\t\tUse Vulkan.\n"
135#endif
Greg Daniel2811aa22017-07-13 15:34:56 -0400136#ifdef SK_METAL
137 "\t\tmetal\t\t\tUse Metal.\n"
138#endif
brianosmand93c1202016-03-10 07:49:08 -0800139 "\tcolor\ttype: string\tdefault: 8888.\n"
140 "\t Select framebuffer color format.\n"
141 "\t Options:\n"
142 "\t\t8888\t\t\tLinear 8888.\n"
Brian Salomonce5ee602017-07-17 11:31:31 -0400143 "\t\t4444\t\t\tLinear 4444.\n"
144 "\t\t565\t\t\tLinear 565.\n"
brianosman4562f6e2016-09-19 14:42:04 -0700145 "\t\tf16{_gamut}\t\tLinear 16-bit floating point.\n"
146 "\t\tsrgb{_gamut}\t\tsRGB 8888.\n"
147 "\t gamut\ttype: string\tdefault: srgb.\n"
148 "\t Select color gamut for f16 or sRGB format buffers.\n"
149 "\t Options:\n"
150 "\t\tsrgb\t\t\tsRGB gamut.\n"
151 "\t\twide\t\t\tWide Gamut RGB.\n"
kkinnunen3e980c32015-12-23 01:33:00 -0800152 "\tdit\ttype: bool\tdefault: false.\n"
153 "\t Use device independent text.\n"
154 "\tnvpr\ttype: bool\tdefault: false.\n"
155 "\t Use NV_path_rendering OpenGL and OpenGL ES extension.\n"
156 "\tsamples\ttype: int\tdefault: 0.\n"
157 "\t Use multisampling with N samples.\n"
Eric Karl5c779752017-05-08 12:02:07 -0700158 "\tstencils\ttype: bool\tdefault: true.\n"
159 "\t Allow the use of stencil buffers.\n"
Brian Osmanf9810662017-08-30 10:02:10 -0400160 "\ttestThreading\ttype: bool\tdefault: false.\n"
161 "\t Run config with and without worker threads, check that results match.\n"
kkinnunen3e980c32015-12-23 01:33:00 -0800162 "\n"
163 "Predefined configs:\n\n"
brianosman37e23342016-09-20 08:06:30 -0700164 // Help text for pre-defined configs is auto-generated from gPredefinedConfigs
kkinnunen3e980c32015-12-23 01:33:00 -0800165#endif
166 ;
167
brianosman37e23342016-09-20 08:06:30 -0700168static const char* config_extended_help_fn() {
169 static SkString helpString;
170 helpString.set(configExtendedHelp);
171 for (const auto& config : gPredefinedConfigs) {
172 helpString.appendf("\t%-10s\t= gpu(%s)\n", config.predefinedConfig, config.options);
173 }
174 return helpString.c_str();
175}
kkinnunen3e980c32015-12-23 01:33:00 -0800176
brianosman37e23342016-09-20 08:06:30 -0700177DEFINE_extended_string(config, defaultConfigs, config_help_fn(), config_extended_help_fn());
kkinnunen3e980c32015-12-23 01:33:00 -0800178
179SkCommandLineConfig::SkCommandLineConfig(const SkString& tag, const SkString& backend,
180 const SkTArray<SkString>& viaParts)
181 : fTag(tag)
182 , fBackend(backend)
183 , fViaParts(viaParts) {
184}
185SkCommandLineConfig::~SkCommandLineConfig() {
186}
187
188#if SK_SUPPORT_GPU
189SkCommandLineConfigGpu::SkCommandLineConfigGpu(
csmartdaltone0d36292016-07-29 08:14:20 -0700190 const SkString& tag, const SkTArray<SkString>& viaParts, ContextType contextType, bool useNVPR,
Brian Salomonf06c3582017-12-07 14:34:36 -0500191 bool useDIText, int samples, SkColorType colorType, SkAlphaType alphaType,
Brian Osmanf9810662017-08-30 10:02:10 -0400192 sk_sp<SkColorSpace> colorSpace, bool useStencilBuffers, bool testThreading)
kkinnunen3e980c32015-12-23 01:33:00 -0800193 : SkCommandLineConfig(tag, SkString("gpu"), viaParts)
194 , fContextType(contextType)
csmartdaltone812d492017-02-21 12:36:05 -0700195 , fContextOverrides(ContextOverrides::kNone)
kkinnunen3e980c32015-12-23 01:33:00 -0800196 , fUseDIText(useDIText)
brianosmand93c1202016-03-10 07:49:08 -0800197 , fSamples(samples)
198 , fColorType(colorType)
Brian Salomonce5ee602017-07-17 11:31:31 -0400199 , fAlphaType(alphaType)
Brian Osmanf9810662017-08-30 10:02:10 -0400200 , fColorSpace(std::move(colorSpace))
201 , fTestThreading(testThreading) {
csmartdalton6270e552016-09-13 10:41:49 -0700202 if (useNVPR) {
csmartdaltone812d492017-02-21 12:36:05 -0700203 fContextOverrides |= ContextOverrides::kRequireNVPRSupport;
Brian Salomonf06c3582017-12-07 14:34:36 -0500204 } else {
csmartdaltone812d492017-02-21 12:36:05 -0700205 // We don't disable NVPR for instanced configs. Otherwise the caps wouldn't use mixed
206 // samples and we couldn't test the mixed samples backend for simple shapes.
207 fContextOverrides |= ContextOverrides::kDisableNVPR;
csmartdalton6270e552016-09-13 10:41:49 -0700208 }
brianosman20471892016-12-02 06:43:32 -0800209 // Subtle logic: If the config has a color space attached, we're going to be rendering to sRGB,
210 // so we need that capability. In addition, to get the widest test coverage, we DO NOT require
211 // that we can disable sRGB decode. (That's for rendering sRGB sources to legacy surfaces).
212 //
213 // If the config doesn't have a color space attached, we're going to be rendering in legacy
csmartdaltone812d492017-02-21 12:36:05 -0700214 // mode. In that case, we don't require sRGB capability and we defer to the client to decide on
215 // sRGB decode control.
Brian Osman7039f742016-11-01 15:56:16 -0400216 if (fColorSpace) {
csmartdaltone812d492017-02-21 12:36:05 -0700217 fContextOverrides |= ContextOverrides::kRequireSRGBSupport;
218 fContextOverrides |= ContextOverrides::kAllowSRGBWithoutDecodeControl;
csmartdalton6270e552016-09-13 10:41:49 -0700219 }
Eric Karl5c779752017-05-08 12:02:07 -0700220 if (!useStencilBuffers) {
221 fContextOverrides |= ContextOverrides::kAvoidStencilBuffers;
222 }
kkinnunen3e980c32015-12-23 01:33:00 -0800223}
224static bool parse_option_int(const SkString& value, int* outInt) {
225 if (value.isEmpty()) {
226 return false;
227 }
228 char* endptr = nullptr;
229 long intValue = strtol(value.c_str(), &endptr, 10);
230 if (*endptr != '\0') {
231 return false;
232 }
233 *outInt = static_cast<int>(intValue);
234 return true;
235}
236static bool parse_option_bool(const SkString& value, bool* outBool) {
237 if (value.equals("true")) {
238 *outBool = true;
239 return true;
240 }
241 if (value.equals("false")) {
242 *outBool = false;
243 return true;
244 }
245 return false;
246}
247static bool parse_option_gpu_api(const SkString& value,
248 SkCommandLineConfigGpu::ContextType* outContextType) {
kkinnunen3e980c32015-12-23 01:33:00 -0800249 if (value.equals("gl")) {
bsalomon85b4b532016-04-05 11:06:27 -0700250 *outContextType = GrContextFactory::kGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800251 return true;
252 }
253 if (value.equals("gles")) {
bsalomon85b4b532016-04-05 11:06:27 -0700254 *outContextType = GrContextFactory::kGLES_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800255 return true;
256 }
Brian Salomon6405e712017-03-20 08:54:16 -0400257 if (value.equals("debuggl")) {
bsalomon85b4b532016-04-05 11:06:27 -0700258 *outContextType = GrContextFactory::kDebugGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800259 return true;
260 }
Brian Salomon6405e712017-03-20 08:54:16 -0400261 if (value.equals("nullgl")) {
bsalomon85b4b532016-04-05 11:06:27 -0700262 *outContextType = GrContextFactory::kNullGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800263 return true;
264 }
bsalomon11abd8d2016-10-14 08:13:48 -0700265 if (value.equals("angle_d3d9_es2")) {
266 *outContextType = GrContextFactory::kANGLE_D3D9_ES2_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800267 return true;
268 }
bsalomon11abd8d2016-10-14 08:13:48 -0700269 if (value.equals("angle_d3d11_es2")) {
270 *outContextType = GrContextFactory::kANGLE_D3D11_ES2_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800271 return true;
272 }
bsalomon11abd8d2016-10-14 08:13:48 -0700273 if (value.equals("angle_d3d11_es3")) {
274 *outContextType = GrContextFactory::kANGLE_D3D11_ES3_ContextType;
275 return true;
276 }
277 if (value.equals("angle_gl_es2")) {
278 *outContextType = GrContextFactory::kANGLE_GL_ES2_ContextType;
279 return true;
280 }
281 if (value.equals("angle_gl_es3")) {
282 *outContextType = GrContextFactory::kANGLE_GL_ES3_ContextType;
283 return true;
284 }
kkinnunen3e980c32015-12-23 01:33:00 -0800285 if (value.equals("commandbuffer")) {
bsalomon85b4b532016-04-05 11:06:27 -0700286 *outContextType = GrContextFactory::kCommandBuffer_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800287 return true;
288 }
Brian Salomon8fe24272017-07-07 12:56:11 -0400289 if (value.equals("mock")) {
290 *outContextType = GrContextFactory::kMock_ContextType;
291 return true;
292 }
bsalomondc0fcd42016-04-11 14:21:33 -0700293#ifdef SK_VULKAN
294 if (value.equals("vulkan")) {
295 *outContextType = GrContextFactory::kVulkan_ContextType;
296 return true;
297 }
298#endif
Greg Daniel2811aa22017-07-13 15:34:56 -0400299#ifdef SK_METAL
300 if (value.equals("metal")) {
301 *outContextType = GrContextFactory::kMetal_ContextType;
302 return true;
303 }
304#endif
kkinnunen3e980c32015-12-23 01:33:00 -0800305 return false;
306}
brianosmand93c1202016-03-10 07:49:08 -0800307static bool parse_option_gpu_color(const SkString& value,
308 SkColorType* outColorType,
Brian Salomonce5ee602017-07-17 11:31:31 -0400309 SkAlphaType* alphaType,
brianosmanb109b8c2016-06-16 13:03:24 -0700310 sk_sp<SkColorSpace>* outColorSpace) {
Brian Salomonce5ee602017-07-17 11:31:31 -0400311 // We always use premul unless the color type is 565.
312 *alphaType = kPremul_SkAlphaType;
313
brianosmand93c1202016-03-10 07:49:08 -0800314 if (value.equals("8888")) {
bsalomon33069252016-09-28 08:49:53 -0700315 *outColorType = kRGBA_8888_SkColorType;
brianosmanb109b8c2016-06-16 13:03:24 -0700316 *outColorSpace = nullptr;
brianosmand93c1202016-03-10 07:49:08 -0800317 return true;
Brian Salomonce5ee602017-07-17 11:31:31 -0400318 } else if (value.equals("4444")) {
319 *outColorType = kARGB_4444_SkColorType;
320 *outColorSpace = nullptr;
321 return true;
322 } else if (value.equals("565")) {
323 *outColorType = kRGB_565_SkColorType;
324 *alphaType = kOpaque_SkAlphaType;
325 *outColorSpace = nullptr;
326 return true;
brianosmand93c1202016-03-10 07:49:08 -0800327 }
brianosman4562f6e2016-09-19 14:42:04 -0700328
329 SkTArray<SkString> commands;
330 SkStrSplit(value.c_str(), "_", &commands);
331 if (commands.count() < 1 || commands.count() > 2) {
332 return false;
333 }
334
raftias94888332016-10-18 10:02:51 -0700335 const bool linearGamma = commands[0].equals("f16");
Matt Sarettd2228302017-03-02 08:53:46 -0500336 SkColorSpace::Gamut gamut = SkColorSpace::kSRGB_Gamut;
337 SkColorSpace::RenderTargetGamma gamma = linearGamma ? SkColorSpace::kLinear_RenderTargetGamma
338 : SkColorSpace::kSRGB_RenderTargetGamma;
Matt Sarettf3880932017-03-24 10:06:03 -0400339 *outColorSpace = SkColorSpace::MakeRGB(gamma, gamut);
Matt Sarettd2228302017-03-02 08:53:46 -0500340
brianosman4562f6e2016-09-19 14:42:04 -0700341 if (commands.count() == 2) {
342 if (commands[1].equals("srgb")) {
343 // sRGB gamut (which is our default)
344 } else if (commands[1].equals("wide")) {
345 // WideGamut RGB
346 const float gWideGamutRGB_toXYZD50[]{
347 0.7161046f, 0.1009296f, 0.1471858f, // -> X
348 0.2581874f, 0.7249378f, 0.0168748f, // -> Y
349 0.0000000f, 0.0517813f, 0.7734287f, // -> Z
350 };
351 SkMatrix44 wideGamutRGBMatrix(SkMatrix44::kUninitialized_Constructor);
352 wideGamutRGBMatrix.set3x3RowMajorf(gWideGamutRGB_toXYZD50);
Matt Sarettf3880932017-03-24 10:06:03 -0400353 *outColorSpace = SkColorSpace::MakeRGB(gamma, wideGamutRGBMatrix);
Brian Osman4a6b28e2016-10-17 11:14:02 -0400354 } else if (commands[1].equals("narrow")) {
355 // NarrowGamut RGB (an artifically smaller than sRGB gamut)
356 SkColorSpacePrimaries primaries ={
357 0.54f, 0.33f, // Rx, Ry
358 0.33f, 0.50f, // Gx, Gy
359 0.25f, 0.20f, // Bx, By
360 0.3127f, 0.3290f, // Wx, Wy
361 };
362 SkMatrix44 narrowGamutRGBMatrix(SkMatrix44::kUninitialized_Constructor);
363 primaries.toXYZD50(&narrowGamutRGBMatrix);
Matt Sarettf3880932017-03-24 10:06:03 -0400364 *outColorSpace = SkColorSpace::MakeRGB(gamma, narrowGamutRGBMatrix);
brianosman4562f6e2016-09-19 14:42:04 -0700365 } else {
366 // Unknown color gamut
367 return false;
368 }
369 }
370
371 // Now pick a color type
372 if (commands[0].equals("f16")) {
brianosmand93c1202016-03-10 07:49:08 -0800373 *outColorType = kRGBA_F16_SkColorType;
brianosmand93c1202016-03-10 07:49:08 -0800374 return true;
375 }
Matt Sarettd2228302017-03-02 08:53:46 -0500376 if (commands[0].equals("srgb") || commands[0].equals("srgbnl")) {
bsalomon33069252016-09-28 08:49:53 -0700377 *outColorType = kRGBA_8888_SkColorType;
brianosmand93c1202016-03-10 07:49:08 -0800378 return true;
379 }
380 return false;
381}
kkinnunen3e980c32015-12-23 01:33:00 -0800382
383SkCommandLineConfigGpu* parse_command_line_config_gpu(const SkString& tag,
384 const SkTArray<SkString>& vias,
385 const SkString& options) {
386 // Defaults for GPU backend.
387 bool seenAPI = false;
Brian Salomon6405e712017-03-20 08:54:16 -0400388 SkCommandLineConfigGpu::ContextType contextType = GrContextFactory::kGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800389 bool seenUseNVPR = false;
390 bool useNVPR = false;
391 bool seenUseDIText =false;
392 bool useDIText = false;
393 bool seenSamples = false;
Brian Salomon3a2cc2c2018-02-03 00:25:12 +0000394 int samples = 0;
brianosmand93c1202016-03-10 07:49:08 -0800395 bool seenColor = false;
bsalomon33069252016-09-28 08:49:53 -0700396 SkColorType colorType = kRGBA_8888_SkColorType;
Brian Salomonce5ee602017-07-17 11:31:31 -0400397 SkAlphaType alphaType = kPremul_SkAlphaType;
brianosmanb109b8c2016-06-16 13:03:24 -0700398 sk_sp<SkColorSpace> colorSpace = nullptr;
Eric Karl5c779752017-05-08 12:02:07 -0700399 bool seenUseStencils = false;
400 bool useStencils = true;
Brian Osmanf9810662017-08-30 10:02:10 -0400401 bool seenTestThreading = false;
402 bool testThreading = false;
kkinnunen3e980c32015-12-23 01:33:00 -0800403
404 SkTArray<SkString> optionParts;
405 SkStrSplit(options.c_str(), ",", kStrict_SkStrSplitMode, &optionParts);
406 for (int i = 0; i < optionParts.count(); ++i) {
407 SkTArray<SkString> keyValueParts;
408 SkStrSplit(optionParts[i].c_str(), "=", kStrict_SkStrSplitMode, &keyValueParts);
409 if (keyValueParts.count() != 2) {
410 return nullptr;
411 }
412 const SkString& key = keyValueParts[0];
413 const SkString& value = keyValueParts[1];
414 bool valueOk = false;
415 if (key.equals("api") && !seenAPI) {
416 valueOk = parse_option_gpu_api(value, &contextType);
417 seenAPI = true;
418 } else if (key.equals("nvpr") && !seenUseNVPR) {
419 valueOk = parse_option_bool(value, &useNVPR);
420 seenUseNVPR = true;
421 } else if (key.equals("dit") && !seenUseDIText) {
422 valueOk = parse_option_bool(value, &useDIText);
423 seenUseDIText = true;
424 } else if (key.equals("samples") && !seenSamples) {
425 valueOk = parse_option_int(value, &samples);
426 seenSamples = true;
brianosmand93c1202016-03-10 07:49:08 -0800427 } else if (key.equals("color") && !seenColor) {
Brian Salomonce5ee602017-07-17 11:31:31 -0400428 valueOk = parse_option_gpu_color(value, &colorType, &alphaType, &colorSpace);
brianosmand93c1202016-03-10 07:49:08 -0800429 seenColor = true;
Eric Karl5c779752017-05-08 12:02:07 -0700430 } else if (key.equals("stencils") && !seenUseStencils) {
431 valueOk = parse_option_bool(value, &useStencils);
432 seenUseStencils = true;
Brian Osmanf9810662017-08-30 10:02:10 -0400433 } else if (key.equals("testThreading") && !seenTestThreading) {
434 valueOk = parse_option_bool(value, &testThreading);
435 seenTestThreading = true;
kkinnunen3e980c32015-12-23 01:33:00 -0800436 }
437 if (!valueOk) {
438 return nullptr;
439 }
440 }
Brian Salomon6405e712017-03-20 08:54:16 -0400441 if (!seenAPI) {
442 return nullptr;
443 }
Brian Salomonf06c3582017-12-07 14:34:36 -0500444 return new SkCommandLineConfigGpu(tag, vias, contextType, useNVPR, useDIText,
Brian Osmanf9810662017-08-30 10:02:10 -0400445 samples, colorType, alphaType, colorSpace, useStencils,
446 testThreading);
kkinnunen3e980c32015-12-23 01:33:00 -0800447}
448#endif
449
450void ParseConfigs(const SkCommandLineFlags::StringArray& configs,
451 SkCommandLineConfigArray* outResult) {
452 outResult->reset();
453 for (int i = 0; i < configs.count(); ++i) {
454 SkString extendedBackend;
455 SkString extendedOptions;
456 SkString simpleBackend;
457 SkTArray<SkString> vias;
458
459 SkString tag(configs[i]);
460 SkTArray<SkString> parts;
bsalomon808ecbb2016-09-28 12:40:22 -0700461 SkStrSplit(tag.c_str(), "[", kStrict_SkStrSplitMode, &parts);
kkinnunen3e980c32015-12-23 01:33:00 -0800462 if (parts.count() == 2) {
463 SkTArray<SkString> parts2;
bsalomon808ecbb2016-09-28 12:40:22 -0700464 SkStrSplit(parts[1].c_str(), "]", kStrict_SkStrSplitMode, &parts2);
kkinnunen3e980c32015-12-23 01:33:00 -0800465 if (parts2.count() == 2 && parts2[1].isEmpty()) {
466 SkStrSplit(parts[0].c_str(), "-", kStrict_SkStrSplitMode, &vias);
467 if (vias.count()) {
468 extendedBackend = vias[vias.count() - 1];
469 vias.pop_back();
470 } else {
471 extendedBackend = parts[0];
472 }
473 extendedOptions = parts2[0];
bsalomon808ecbb2016-09-28 12:40:22 -0700474 simpleBackend.printf("%s[%s]", extendedBackend.c_str(), extendedOptions.c_str());
kkinnunen3e980c32015-12-23 01:33:00 -0800475 }
476 }
477
478 if (extendedBackend.isEmpty()) {
479 simpleBackend = tag;
480 SkStrSplit(tag.c_str(), "-", kStrict_SkStrSplitMode, &vias);
481 if (vias.count()) {
482 simpleBackend = vias[vias.count() - 1];
483 vias.pop_back();
484 }
kkinnunen3e980c32015-12-23 01:33:00 -0800485 for (auto& predefinedConfig : gPredefinedConfigs) {
486 if (simpleBackend.equals(predefinedConfig.predefinedConfig)) {
487 extendedBackend = predefinedConfig.backend;
488 extendedOptions = predefinedConfig.options;
489 break;
490 }
491 }
492 }
493 SkCommandLineConfig* parsedConfig = nullptr;
494#if SK_SUPPORT_GPU
495 if (extendedBackend.equals("gpu")) {
496 parsedConfig = parse_command_line_config_gpu(tag, vias, extendedOptions);
497 }
498#endif
499 if (!parsedConfig) {
500 parsedConfig = new SkCommandLineConfig(tag, simpleBackend, vias);
501 }
502 outResult->emplace_back(parsedConfig);
503 }
504}