blob: fe9faaef1d71182fe9303a520a0bc1291617fc55 [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
raftias7c602de2016-10-13 10:45:44 -07008#include "SkColorSpace_Base.h"
kkinnunen3e980c32015-12-23 01:33:00 -08009#include "SkCommonFlagsConfig.h"
csmartdalton6270e552016-09-13 10:41:49 -070010#include "SkImageInfo.h"
kkinnunen3e980c32015-12-23 01:33:00 -080011
12#include <stdlib.h>
13
bsalomon3724e572016-03-30 18:56:19 -070014#if SK_SUPPORT_GPU
15using sk_gpu_test::GrContextFactory;
16#endif
17
Brian Salomon6405e712017-03-20 08:54:16 -040018#if defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_IOS)
19# define DEFAULT_GPU_CONFIG "gles"
20#else
21# define DEFAULT_GPU_CONFIG "gl"
22#endif
23
kkinnunen3e980c32015-12-23 01:33:00 -080024static const char defaultConfigs[] =
Brian Salomon6405e712017-03-20 08:54:16 -040025 "8888 " DEFAULT_GPU_CONFIG " nonrendering "
bsalomon11abd8d2016-10-14 08:13:48 -070026#if defined(SK_BUILD_FOR_WIN)
27 " angle_d3d11_es2"
kkinnunen3e980c32015-12-23 01:33:00 -080028#endif
kkinnunen3e980c32015-12-23 01:33:00 -080029 ;
30
Brian Salomon6405e712017-03-20 08:54:16 -040031#undef DEFAULT_GPU_CONFIG
32
brianosman37e23342016-09-20 08:06:30 -070033static const struct {
34 const char* predefinedConfig;
35 const char* backend;
36 const char* options;
37} gPredefinedConfigs[] ={
38#if SK_SUPPORT_GPU
Brian Salomon002c1202016-10-18 11:28:20 -040039 { "gl", "gpu", "api=gl" },
Brian Salomon50f66d82017-03-17 14:32:05 -040040 { "gles", "gpu", "api=gles" },
Brian Salomon002c1202016-10-18 11:28:20 -040041 { "glmsaa4", "gpu", "api=gl,samples=4" },
Brian Salomondcf0ab02017-03-20 11:10:21 -040042 { "glmsaa8" , "gpu", "api=gl,samples=8" },
Brian Salomon50f66d82017-03-17 14:32:05 -040043 { "glesmsaa4", "gpu", "api=gles,samples=4" },
Brian Salomon002c1202016-10-18 11:28:20 -040044 { "glnvpr4", "gpu", "api=gl,nvpr=true,samples=4" },
Brian Salomondcf0ab02017-03-20 11:10:21 -040045 { "glnvpr8" , "gpu", "api=gl,nvpr=true,samples=8" },
Brian Salomon002c1202016-10-18 11:28:20 -040046 { "glnvprdit4", "gpu", "api=gl,nvpr=true,samples=4,dit=true" },
Brian Salomondcf0ab02017-03-20 11:10:21 -040047 { "glnvprdit8" , "gpu", "api=gl,nvpr=true,samples=8,dit=true" },
Brian Salomon50f66d82017-03-17 14:32:05 -040048 { "glesnvpr4", "gpu", "api=gles,nvpr=true,samples=4" },
49 { "glesnvprdit4", "gpu", "api=gles,nvpr=true,samples=4,dit=true" },
Brian Salomon002c1202016-10-18 11:28:20 -040050 { "glinst", "gpu", "api=gl,inst=true" },
51 { "glinst4", "gpu", "api=gl,inst=true,samples=4" },
52 { "glinstdit4", "gpu", "api=gl,inst=true,samples=4,dit=true" },
Brian Salomondcf0ab02017-03-20 11:10:21 -040053 { "glinst8" , "gpu", "api=gl,inst=true,samples=8" },
54 { "glinstdit8" , "gpu", "api=gl,inst=true,samples=8,dit=true" },
Brian Salomon50f66d82017-03-17 14:32:05 -040055 { "glesinst", "gpu", "api=gles,inst=true" },
56 { "glesinst4", "gpu", "api=gles,inst=true,samples=4" },
57 { "glesinstdit4", "gpu", "api=gles,inst=true,samples=4,dit=true" },
Brian Salomonce5ee602017-07-17 11:31:31 -040058 { "gl4444", "gpu", "api=gl,color=4444" },
59 { "gl565", "gpu", "api=gl,color=565" },
Brian Salomon6405e712017-03-20 08:54:16 -040060 { "glf16", "gpu", "api=gl,color=f16" },
61 { "glsrgb", "gpu", "api=gl,color=srgb" },
62 { "glsrgbnl", "gpu", "api=gl,color=srgbnl" },
63 { "glesf16", "gpu", "api=gles,color=f16" },
64 { "glessrgb", "gpu", "api=gles,color=srgb" },
65 { "glessrgbnl", "gpu", "api=gles,color=srgbnl" },
Brian Salomon002c1202016-10-18 11:28:20 -040066 { "glsrgb", "gpu", "api=gl,color=srgb" },
67 { "glwide", "gpu", "api=gl,color=f16_wide" },
68 { "glnarrow", "gpu", "api=gl,color=f16_narrow" },
Eric Karl5c779752017-05-08 12:02:07 -070069 { "glnostencils", "gpu", "api=gl,stencils=false" },
Brian Salomon50f66d82017-03-17 14:32:05 -040070 { "glessrgb", "gpu", "api=gles,color=srgb" },
71 { "gleswide", "gpu", "api=gles,color=f16_wide" },
72 { "glesnarrow", "gpu", "api=gles,color=f16_narrow" },
Brian Salomon50f66d82017-03-17 14:32:05 -040073 { "gldft", "gpu", "api=gl,dit=true" },
74 { "glesdft", "gpu", "api=gles,dit=true" },
Brian Osmanf9810662017-08-30 10:02:10 -040075 { "gltestthreading", "gpu", "api=gl,testThreading=true" },
Brian Salomon6405e712017-03-20 08:54:16 -040076 { "debuggl", "gpu", "api=debuggl" },
77 { "nullgl", "gpu", "api=nullgl" },
Brian Salomon002c1202016-10-18 11:28:20 -040078 { "angle_d3d11_es2", "gpu", "api=angle_d3d11_es2" },
Brian Osman21d742d2017-01-10 13:31:33 -050079 { "angle_d3d11_es3", "gpu", "api=angle_d3d11_es3" },
Brian Salomon002c1202016-10-18 11:28:20 -040080 { "angle_d3d9_es2", "gpu", "api=angle_d3d9_es2" },
81 { "angle_d3d11_es2_msaa4", "gpu", "api=angle_d3d11_es2,samples=4" },
Brian Salomon528ca9b2017-03-24 11:15:09 -040082 { "angle_d3d11_es2_msaa8", "gpu", "api=angle_d3d11_es2,samples=8" },
Brian Salomon8c865882017-06-22 09:56:24 -040083 { "angle_d3d11_es3_msaa4", "gpu", "api=angle_d3d11_es3,samples=4" },
84 { "angle_d3d11_es3_msaa8", "gpu", "api=angle_d3d11_es3,samples=8" },
Brian Salomon002c1202016-10-18 11:28:20 -040085 { "angle_gl_es2", "gpu", "api=angle_gl_es2" },
Brian Osman21d742d2017-01-10 13:31:33 -050086 { "angle_gl_es3", "gpu", "api=angle_gl_es3" },
Brian Salomon8fe24272017-07-07 12:56:11 -040087 { "commandbuffer", "gpu", "api=commandbuffer" },
88 { "mock", "gpu", "api=mock" }
brianosman37e23342016-09-20 08:06:30 -070089#ifdef SK_VULKAN
Brian Salomon002c1202016-10-18 11:28:20 -040090 ,{ "vk", "gpu", "api=vulkan" }
91 ,{ "vksrgb", "gpu", "api=vulkan,color=srgb" }
92 ,{ "vkwide", "gpu", "api=vulkan,color=f16_wide" }
93 ,{ "vkmsaa4", "gpu", "api=vulkan,samples=4" }
Brian Salomondcf0ab02017-03-20 11:10:21 -040094 ,{ "vkmsaa8", "gpu", "api=vulkan,samples=8" }
brianosman37e23342016-09-20 08:06:30 -070095#endif
Greg Daniel2811aa22017-07-13 15:34:56 -040096#ifdef SK_METAL
97 ,{ "mtl", "gpu", "api=metal" }
98 ,{ "mtlsrgb", "gpu", "api=metal,color=srgb" }
99 ,{ "mtlwide", "gpu", "api=metal,color=f16_wide" }
100 ,{ "mtlmsaa4", "gpu", "api=metal,samples=4" }
101 ,{ "mtlmsaa8", "gpu", "api=metal,samples=8" }
102#endif
brianosman37e23342016-09-20 08:06:30 -0700103#else
Brian Salomon8fe24272017-07-07 12:56:11 -0400104 { "", "", "" }
brianosman37e23342016-09-20 08:06:30 -0700105#endif
106};
107
108static const char configHelp[] =
Derek Sollenbergerc65386a2017-01-05 09:50:22 -0500109 "Options: 565 8888 srgb f16 nonrendering null pdf pdfa skp pipe svg xps";
brianosman37e23342016-09-20 08:06:30 -0700110
111static const char* config_help_fn() {
112 static SkString helpString;
113 helpString.set(configHelp);
114 for (const auto& config : gPredefinedConfigs) {
115 helpString.appendf(" %s", config.predefinedConfig);
116 }
bsalomon808ecbb2016-09-28 12:40:22 -0700117 helpString.append(" or use extended form 'backend[option=value,...]'.\n");
brianosman37e23342016-09-20 08:06:30 -0700118 return helpString.c_str();
119}
kkinnunen3e980c32015-12-23 01:33:00 -0800120
121static const char configExtendedHelp[] =
122 "Extended form: 'backend(option=value,...)'\n\n"
123 "Possible backends and options:\n"
124#if SK_SUPPORT_GPU
125 "\n"
bsalomon808ecbb2016-09-28 12:40:22 -0700126 "gpu[api=string,color=string,dit=bool,nvpr=bool,inst=bool,samples=int]\n"
Brian Salomon6405e712017-03-20 08:54:16 -0400127 "\tapi\ttype: string\trequired\n"
kkinnunen3e980c32015-12-23 01:33:00 -0800128 "\t Select graphics API to use with gpu backend.\n"
129 "\t Options:\n"
kkinnunen3e980c32015-12-23 01:33:00 -0800130 "\t\tgl \t\t\tUse OpenGL.\n"
131 "\t\tgles \t\t\tUse OpenGL ES.\n"
Brian Salomon6405e712017-03-20 08:54:16 -0400132 "\t\tdebuggl \t\t\tUse debug OpenGL.\n"
133 "\t\tnullgl \t\t\tUse null OpenGL.\n"
bsalomon11abd8d2016-10-14 08:13:48 -0700134 "\t\tangle_d3d9_es2\t\t\tUse OpenGL ES2 on the ANGLE Direct3D9 backend.\n"
135 "\t\tangle_d3d11_es2\t\t\tUse OpenGL ES2 on the ANGLE Direct3D11 backend.\n"
136 "\t\tangle_d3d11_es3\t\t\tUse OpenGL ES3 on the ANGLE Direct3D11 backend.\n"
137 "\t\tangle_gl_es2\t\t\tUse OpenGL ES2 on the ANGLE OpenGL backend.\n"
138 "\t\tangle_gl_es3\t\t\tUse OpenGL ES3 on the ANGLE OpenGL backend.\n"
kkinnunen3e980c32015-12-23 01:33:00 -0800139 "\t\tcommandbuffer\t\tUse command buffer.\n"
Brian Salomon8fe24272017-07-07 12:56:11 -0400140 "\t\tmock\t\tUse mock context.\n"
bsalomondc0fcd42016-04-11 14:21:33 -0700141#ifdef SK_VULKAN
142 "\t\tvulkan\t\t\tUse Vulkan.\n"
143#endif
Greg Daniel2811aa22017-07-13 15:34:56 -0400144#ifdef SK_METAL
145 "\t\tmetal\t\t\tUse Metal.\n"
146#endif
brianosmand93c1202016-03-10 07:49:08 -0800147 "\tcolor\ttype: string\tdefault: 8888.\n"
148 "\t Select framebuffer color format.\n"
149 "\t Options:\n"
150 "\t\t8888\t\t\tLinear 8888.\n"
Brian Salomonce5ee602017-07-17 11:31:31 -0400151 "\t\t4444\t\t\tLinear 4444.\n"
152 "\t\t565\t\t\tLinear 565.\n"
brianosman4562f6e2016-09-19 14:42:04 -0700153 "\t\tf16{_gamut}\t\tLinear 16-bit floating point.\n"
154 "\t\tsrgb{_gamut}\t\tsRGB 8888.\n"
155 "\t gamut\ttype: string\tdefault: srgb.\n"
156 "\t Select color gamut for f16 or sRGB format buffers.\n"
157 "\t Options:\n"
158 "\t\tsrgb\t\t\tsRGB gamut.\n"
159 "\t\twide\t\t\tWide Gamut RGB.\n"
kkinnunen3e980c32015-12-23 01:33:00 -0800160 "\tdit\ttype: bool\tdefault: false.\n"
161 "\t Use device independent text.\n"
162 "\tnvpr\ttype: bool\tdefault: false.\n"
163 "\t Use NV_path_rendering OpenGL and OpenGL ES extension.\n"
164 "\tsamples\ttype: int\tdefault: 0.\n"
165 "\t Use multisampling with N samples.\n"
Eric Karl5c779752017-05-08 12:02:07 -0700166 "\tstencils\ttype: bool\tdefault: true.\n"
167 "\t Allow the use of stencil buffers.\n"
Brian Osmanf9810662017-08-30 10:02:10 -0400168 "\ttestThreading\ttype: bool\tdefault: false.\n"
169 "\t Run config with and without worker threads, check that results match.\n"
kkinnunen3e980c32015-12-23 01:33:00 -0800170 "\n"
171 "Predefined configs:\n\n"
brianosman37e23342016-09-20 08:06:30 -0700172 // Help text for pre-defined configs is auto-generated from gPredefinedConfigs
kkinnunen3e980c32015-12-23 01:33:00 -0800173#endif
174 ;
175
brianosman37e23342016-09-20 08:06:30 -0700176static const char* config_extended_help_fn() {
177 static SkString helpString;
178 helpString.set(configExtendedHelp);
179 for (const auto& config : gPredefinedConfigs) {
180 helpString.appendf("\t%-10s\t= gpu(%s)\n", config.predefinedConfig, config.options);
181 }
182 return helpString.c_str();
183}
kkinnunen3e980c32015-12-23 01:33:00 -0800184
brianosman37e23342016-09-20 08:06:30 -0700185DEFINE_extended_string(config, defaultConfigs, config_help_fn(), config_extended_help_fn());
kkinnunen3e980c32015-12-23 01:33:00 -0800186
187SkCommandLineConfig::SkCommandLineConfig(const SkString& tag, const SkString& backend,
188 const SkTArray<SkString>& viaParts)
189 : fTag(tag)
190 , fBackend(backend)
191 , fViaParts(viaParts) {
192}
193SkCommandLineConfig::~SkCommandLineConfig() {
194}
195
196#if SK_SUPPORT_GPU
197SkCommandLineConfigGpu::SkCommandLineConfigGpu(
csmartdaltone0d36292016-07-29 08:14:20 -0700198 const SkString& tag, const SkTArray<SkString>& viaParts, ContextType contextType, bool useNVPR,
Brian Salomonce5ee602017-07-17 11:31:31 -0400199 bool useInstanced, bool useDIText, int samples, SkColorType colorType, SkAlphaType alphaType,
Brian Osmanf9810662017-08-30 10:02:10 -0400200 sk_sp<SkColorSpace> colorSpace, bool useStencilBuffers, bool testThreading)
kkinnunen3e980c32015-12-23 01:33:00 -0800201 : SkCommandLineConfig(tag, SkString("gpu"), viaParts)
202 , fContextType(contextType)
csmartdaltone812d492017-02-21 12:36:05 -0700203 , fContextOverrides(ContextOverrides::kNone)
kkinnunen3e980c32015-12-23 01:33:00 -0800204 , fUseDIText(useDIText)
brianosmand93c1202016-03-10 07:49:08 -0800205 , fSamples(samples)
206 , fColorType(colorType)
Brian Salomonce5ee602017-07-17 11:31:31 -0400207 , fAlphaType(alphaType)
Brian Osmanf9810662017-08-30 10:02:10 -0400208 , fColorSpace(std::move(colorSpace))
209 , fTestThreading(testThreading) {
csmartdalton6270e552016-09-13 10:41:49 -0700210 if (useNVPR) {
csmartdaltone812d492017-02-21 12:36:05 -0700211 fContextOverrides |= ContextOverrides::kRequireNVPRSupport;
212 } else if (!useInstanced) {
213 // We don't disable NVPR for instanced configs. Otherwise the caps wouldn't use mixed
214 // samples and we couldn't test the mixed samples backend for simple shapes.
215 fContextOverrides |= ContextOverrides::kDisableNVPR;
csmartdalton6270e552016-09-13 10:41:49 -0700216 }
217 if (useInstanced) {
csmartdaltone812d492017-02-21 12:36:05 -0700218 fContextOverrides |= ContextOverrides::kUseInstanced;
csmartdalton6270e552016-09-13 10:41:49 -0700219 }
brianosman20471892016-12-02 06:43:32 -0800220 // Subtle logic: If the config has a color space attached, we're going to be rendering to sRGB,
221 // so we need that capability. In addition, to get the widest test coverage, we DO NOT require
222 // that we can disable sRGB decode. (That's for rendering sRGB sources to legacy surfaces).
223 //
224 // If the config doesn't have a color space attached, we're going to be rendering in legacy
csmartdaltone812d492017-02-21 12:36:05 -0700225 // mode. In that case, we don't require sRGB capability and we defer to the client to decide on
226 // sRGB decode control.
Brian Osman7039f742016-11-01 15:56:16 -0400227 if (fColorSpace) {
csmartdaltone812d492017-02-21 12:36:05 -0700228 fContextOverrides |= ContextOverrides::kRequireSRGBSupport;
229 fContextOverrides |= ContextOverrides::kAllowSRGBWithoutDecodeControl;
csmartdalton6270e552016-09-13 10:41:49 -0700230 }
Eric Karl5c779752017-05-08 12:02:07 -0700231 if (!useStencilBuffers) {
232 fContextOverrides |= ContextOverrides::kAvoidStencilBuffers;
233 }
kkinnunen3e980c32015-12-23 01:33:00 -0800234}
235static bool parse_option_int(const SkString& value, int* outInt) {
236 if (value.isEmpty()) {
237 return false;
238 }
239 char* endptr = nullptr;
240 long intValue = strtol(value.c_str(), &endptr, 10);
241 if (*endptr != '\0') {
242 return false;
243 }
244 *outInt = static_cast<int>(intValue);
245 return true;
246}
247static bool parse_option_bool(const SkString& value, bool* outBool) {
248 if (value.equals("true")) {
249 *outBool = true;
250 return true;
251 }
252 if (value.equals("false")) {
253 *outBool = false;
254 return true;
255 }
256 return false;
257}
258static bool parse_option_gpu_api(const SkString& value,
259 SkCommandLineConfigGpu::ContextType* outContextType) {
kkinnunen3e980c32015-12-23 01:33:00 -0800260 if (value.equals("gl")) {
bsalomon85b4b532016-04-05 11:06:27 -0700261 *outContextType = GrContextFactory::kGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800262 return true;
263 }
264 if (value.equals("gles")) {
bsalomon85b4b532016-04-05 11:06:27 -0700265 *outContextType = GrContextFactory::kGLES_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800266 return true;
267 }
Brian Salomon6405e712017-03-20 08:54:16 -0400268 if (value.equals("debuggl")) {
bsalomon85b4b532016-04-05 11:06:27 -0700269 *outContextType = GrContextFactory::kDebugGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800270 return true;
271 }
Brian Salomon6405e712017-03-20 08:54:16 -0400272 if (value.equals("nullgl")) {
bsalomon85b4b532016-04-05 11:06:27 -0700273 *outContextType = GrContextFactory::kNullGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800274 return true;
275 }
bsalomon11abd8d2016-10-14 08:13:48 -0700276 if (value.equals("angle_d3d9_es2")) {
277 *outContextType = GrContextFactory::kANGLE_D3D9_ES2_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800278 return true;
279 }
bsalomon11abd8d2016-10-14 08:13:48 -0700280 if (value.equals("angle_d3d11_es2")) {
281 *outContextType = GrContextFactory::kANGLE_D3D11_ES2_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800282 return true;
283 }
bsalomon11abd8d2016-10-14 08:13:48 -0700284 if (value.equals("angle_d3d11_es3")) {
285 *outContextType = GrContextFactory::kANGLE_D3D11_ES3_ContextType;
286 return true;
287 }
288 if (value.equals("angle_gl_es2")) {
289 *outContextType = GrContextFactory::kANGLE_GL_ES2_ContextType;
290 return true;
291 }
292 if (value.equals("angle_gl_es3")) {
293 *outContextType = GrContextFactory::kANGLE_GL_ES3_ContextType;
294 return true;
295 }
kkinnunen3e980c32015-12-23 01:33:00 -0800296 if (value.equals("commandbuffer")) {
bsalomon85b4b532016-04-05 11:06:27 -0700297 *outContextType = GrContextFactory::kCommandBuffer_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800298 return true;
299 }
Brian Salomon8fe24272017-07-07 12:56:11 -0400300 if (value.equals("mock")) {
301 *outContextType = GrContextFactory::kMock_ContextType;
302 return true;
303 }
bsalomondc0fcd42016-04-11 14:21:33 -0700304#ifdef SK_VULKAN
305 if (value.equals("vulkan")) {
306 *outContextType = GrContextFactory::kVulkan_ContextType;
307 return true;
308 }
309#endif
Greg Daniel2811aa22017-07-13 15:34:56 -0400310#ifdef SK_METAL
311 if (value.equals("metal")) {
312 *outContextType = GrContextFactory::kMetal_ContextType;
313 return true;
314 }
315#endif
kkinnunen3e980c32015-12-23 01:33:00 -0800316 return false;
317}
brianosmand93c1202016-03-10 07:49:08 -0800318static bool parse_option_gpu_color(const SkString& value,
319 SkColorType* outColorType,
Brian Salomonce5ee602017-07-17 11:31:31 -0400320 SkAlphaType* alphaType,
brianosmanb109b8c2016-06-16 13:03:24 -0700321 sk_sp<SkColorSpace>* outColorSpace) {
Brian Salomonce5ee602017-07-17 11:31:31 -0400322 // We always use premul unless the color type is 565.
323 *alphaType = kPremul_SkAlphaType;
324
brianosmand93c1202016-03-10 07:49:08 -0800325 if (value.equals("8888")) {
bsalomon33069252016-09-28 08:49:53 -0700326 *outColorType = kRGBA_8888_SkColorType;
brianosmanb109b8c2016-06-16 13:03:24 -0700327 *outColorSpace = nullptr;
brianosmand93c1202016-03-10 07:49:08 -0800328 return true;
Brian Salomonce5ee602017-07-17 11:31:31 -0400329 } else if (value.equals("4444")) {
330 *outColorType = kARGB_4444_SkColorType;
331 *outColorSpace = nullptr;
332 return true;
333 } else if (value.equals("565")) {
334 *outColorType = kRGB_565_SkColorType;
335 *alphaType = kOpaque_SkAlphaType;
336 *outColorSpace = nullptr;
337 return true;
brianosmand93c1202016-03-10 07:49:08 -0800338 }
brianosman4562f6e2016-09-19 14:42:04 -0700339
340 SkTArray<SkString> commands;
341 SkStrSplit(value.c_str(), "_", &commands);
342 if (commands.count() < 1 || commands.count() > 2) {
343 return false;
344 }
345
raftias94888332016-10-18 10:02:51 -0700346 const bool linearGamma = commands[0].equals("f16");
Matt Sarettd2228302017-03-02 08:53:46 -0500347 SkColorSpace::Gamut gamut = SkColorSpace::kSRGB_Gamut;
348 SkColorSpace::RenderTargetGamma gamma = linearGamma ? SkColorSpace::kLinear_RenderTargetGamma
349 : SkColorSpace::kSRGB_RenderTargetGamma;
Matt Sarettf3880932017-03-24 10:06:03 -0400350 *outColorSpace = SkColorSpace::MakeRGB(gamma, gamut);
Matt Sarettd2228302017-03-02 08:53:46 -0500351
brianosman4562f6e2016-09-19 14:42:04 -0700352 if (commands.count() == 2) {
353 if (commands[1].equals("srgb")) {
354 // sRGB gamut (which is our default)
355 } else if (commands[1].equals("wide")) {
356 // WideGamut RGB
357 const float gWideGamutRGB_toXYZD50[]{
358 0.7161046f, 0.1009296f, 0.1471858f, // -> X
359 0.2581874f, 0.7249378f, 0.0168748f, // -> Y
360 0.0000000f, 0.0517813f, 0.7734287f, // -> Z
361 };
362 SkMatrix44 wideGamutRGBMatrix(SkMatrix44::kUninitialized_Constructor);
363 wideGamutRGBMatrix.set3x3RowMajorf(gWideGamutRGB_toXYZD50);
Matt Sarettf3880932017-03-24 10:06:03 -0400364 *outColorSpace = SkColorSpace::MakeRGB(gamma, wideGamutRGBMatrix);
Brian Osman4a6b28e2016-10-17 11:14:02 -0400365 } else if (commands[1].equals("narrow")) {
366 // NarrowGamut RGB (an artifically smaller than sRGB gamut)
367 SkColorSpacePrimaries primaries ={
368 0.54f, 0.33f, // Rx, Ry
369 0.33f, 0.50f, // Gx, Gy
370 0.25f, 0.20f, // Bx, By
371 0.3127f, 0.3290f, // Wx, Wy
372 };
373 SkMatrix44 narrowGamutRGBMatrix(SkMatrix44::kUninitialized_Constructor);
374 primaries.toXYZD50(&narrowGamutRGBMatrix);
Matt Sarettf3880932017-03-24 10:06:03 -0400375 *outColorSpace = SkColorSpace::MakeRGB(gamma, narrowGamutRGBMatrix);
brianosman4562f6e2016-09-19 14:42:04 -0700376 } else {
377 // Unknown color gamut
378 return false;
379 }
380 }
381
382 // Now pick a color type
383 if (commands[0].equals("f16")) {
brianosmand93c1202016-03-10 07:49:08 -0800384 *outColorType = kRGBA_F16_SkColorType;
brianosmand93c1202016-03-10 07:49:08 -0800385 return true;
386 }
Matt Sarettd2228302017-03-02 08:53:46 -0500387 if (commands[0].equals("srgb") || commands[0].equals("srgbnl")) {
bsalomon33069252016-09-28 08:49:53 -0700388 *outColorType = kRGBA_8888_SkColorType;
brianosmand93c1202016-03-10 07:49:08 -0800389 return true;
390 }
391 return false;
392}
kkinnunen3e980c32015-12-23 01:33:00 -0800393
394SkCommandLineConfigGpu* parse_command_line_config_gpu(const SkString& tag,
395 const SkTArray<SkString>& vias,
396 const SkString& options) {
397 // Defaults for GPU backend.
398 bool seenAPI = false;
Brian Salomon6405e712017-03-20 08:54:16 -0400399 SkCommandLineConfigGpu::ContextType contextType = GrContextFactory::kGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800400 bool seenUseNVPR = false;
401 bool useNVPR = false;
csmartdaltone0d36292016-07-29 08:14:20 -0700402 bool seenUseInstanced = false;
403 bool useInstanced = false;
kkinnunen3e980c32015-12-23 01:33:00 -0800404 bool seenUseDIText =false;
405 bool useDIText = false;
406 bool seenSamples = false;
407 int samples = 0;
brianosmand93c1202016-03-10 07:49:08 -0800408 bool seenColor = false;
bsalomon33069252016-09-28 08:49:53 -0700409 SkColorType colorType = kRGBA_8888_SkColorType;
Brian Salomonce5ee602017-07-17 11:31:31 -0400410 SkAlphaType alphaType = kPremul_SkAlphaType;
brianosmanb109b8c2016-06-16 13:03:24 -0700411 sk_sp<SkColorSpace> colorSpace = nullptr;
Eric Karl5c779752017-05-08 12:02:07 -0700412 bool seenUseStencils = false;
413 bool useStencils = true;
Brian Osmanf9810662017-08-30 10:02:10 -0400414 bool seenTestThreading = false;
415 bool testThreading = false;
kkinnunen3e980c32015-12-23 01:33:00 -0800416
417 SkTArray<SkString> optionParts;
418 SkStrSplit(options.c_str(), ",", kStrict_SkStrSplitMode, &optionParts);
419 for (int i = 0; i < optionParts.count(); ++i) {
420 SkTArray<SkString> keyValueParts;
421 SkStrSplit(optionParts[i].c_str(), "=", kStrict_SkStrSplitMode, &keyValueParts);
422 if (keyValueParts.count() != 2) {
423 return nullptr;
424 }
425 const SkString& key = keyValueParts[0];
426 const SkString& value = keyValueParts[1];
427 bool valueOk = false;
428 if (key.equals("api") && !seenAPI) {
429 valueOk = parse_option_gpu_api(value, &contextType);
430 seenAPI = true;
431 } else if (key.equals("nvpr") && !seenUseNVPR) {
432 valueOk = parse_option_bool(value, &useNVPR);
433 seenUseNVPR = true;
csmartdaltone0d36292016-07-29 08:14:20 -0700434 } else if (key.equals("inst") && !seenUseInstanced) {
435 valueOk = parse_option_bool(value, &useInstanced);
436 seenUseInstanced = true;
kkinnunen3e980c32015-12-23 01:33:00 -0800437 } else if (key.equals("dit") && !seenUseDIText) {
438 valueOk = parse_option_bool(value, &useDIText);
439 seenUseDIText = true;
440 } else if (key.equals("samples") && !seenSamples) {
441 valueOk = parse_option_int(value, &samples);
442 seenSamples = true;
brianosmand93c1202016-03-10 07:49:08 -0800443 } else if (key.equals("color") && !seenColor) {
Brian Salomonce5ee602017-07-17 11:31:31 -0400444 valueOk = parse_option_gpu_color(value, &colorType, &alphaType, &colorSpace);
brianosmand93c1202016-03-10 07:49:08 -0800445 seenColor = true;
Eric Karl5c779752017-05-08 12:02:07 -0700446 } else if (key.equals("stencils") && !seenUseStencils) {
447 valueOk = parse_option_bool(value, &useStencils);
448 seenUseStencils = true;
Brian Osmanf9810662017-08-30 10:02:10 -0400449 } else if (key.equals("testThreading") && !seenTestThreading) {
450 valueOk = parse_option_bool(value, &testThreading);
451 seenTestThreading = true;
kkinnunen3e980c32015-12-23 01:33:00 -0800452 }
453 if (!valueOk) {
454 return nullptr;
455 }
456 }
Brian Salomon6405e712017-03-20 08:54:16 -0400457 if (!seenAPI) {
458 return nullptr;
459 }
csmartdaltone0d36292016-07-29 08:14:20 -0700460 return new SkCommandLineConfigGpu(tag, vias, contextType, useNVPR, useInstanced, useDIText,
Brian Osmanf9810662017-08-30 10:02:10 -0400461 samples, colorType, alphaType, colorSpace, useStencils,
462 testThreading);
kkinnunen3e980c32015-12-23 01:33:00 -0800463}
464#endif
465
466void ParseConfigs(const SkCommandLineFlags::StringArray& configs,
467 SkCommandLineConfigArray* outResult) {
468 outResult->reset();
469 for (int i = 0; i < configs.count(); ++i) {
470 SkString extendedBackend;
471 SkString extendedOptions;
472 SkString simpleBackend;
473 SkTArray<SkString> vias;
474
475 SkString tag(configs[i]);
476 SkTArray<SkString> parts;
bsalomon808ecbb2016-09-28 12:40:22 -0700477 SkStrSplit(tag.c_str(), "[", kStrict_SkStrSplitMode, &parts);
kkinnunen3e980c32015-12-23 01:33:00 -0800478 if (parts.count() == 2) {
479 SkTArray<SkString> parts2;
bsalomon808ecbb2016-09-28 12:40:22 -0700480 SkStrSplit(parts[1].c_str(), "]", kStrict_SkStrSplitMode, &parts2);
kkinnunen3e980c32015-12-23 01:33:00 -0800481 if (parts2.count() == 2 && parts2[1].isEmpty()) {
482 SkStrSplit(parts[0].c_str(), "-", kStrict_SkStrSplitMode, &vias);
483 if (vias.count()) {
484 extendedBackend = vias[vias.count() - 1];
485 vias.pop_back();
486 } else {
487 extendedBackend = parts[0];
488 }
489 extendedOptions = parts2[0];
bsalomon808ecbb2016-09-28 12:40:22 -0700490 simpleBackend.printf("%s[%s]", extendedBackend.c_str(), extendedOptions.c_str());
kkinnunen3e980c32015-12-23 01:33:00 -0800491 }
492 }
493
494 if (extendedBackend.isEmpty()) {
495 simpleBackend = tag;
496 SkStrSplit(tag.c_str(), "-", kStrict_SkStrSplitMode, &vias);
497 if (vias.count()) {
498 simpleBackend = vias[vias.count() - 1];
499 vias.pop_back();
500 }
kkinnunen3e980c32015-12-23 01:33:00 -0800501 for (auto& predefinedConfig : gPredefinedConfigs) {
502 if (simpleBackend.equals(predefinedConfig.predefinedConfig)) {
503 extendedBackend = predefinedConfig.backend;
504 extendedOptions = predefinedConfig.options;
505 break;
506 }
507 }
508 }
509 SkCommandLineConfig* parsedConfig = nullptr;
510#if SK_SUPPORT_GPU
511 if (extendedBackend.equals("gpu")) {
512 parsedConfig = parse_command_line_config_gpu(tag, vias, extendedOptions);
513 }
514#endif
515 if (!parsedConfig) {
516 parsedConfig = new SkCommandLineConfig(tag, simpleBackend, vias);
517 }
518 outResult->emplace_back(parsedConfig);
519 }
520}