blob: 00db61a2406c79ef9387c6458d0a1d18109ec431 [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 Salomonf06c3582017-12-07 14:34:36 -0500199 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;
Brian Salomonf06c3582017-12-07 14:34:36 -0500212 } else {
csmartdaltone812d492017-02-21 12:36:05 -0700213 // 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 }
brianosman20471892016-12-02 06:43:32 -0800217 // Subtle logic: If the config has a color space attached, we're going to be rendering to sRGB,
218 // so we need that capability. In addition, to get the widest test coverage, we DO NOT require
219 // that we can disable sRGB decode. (That's for rendering sRGB sources to legacy surfaces).
220 //
221 // If the config doesn't have a color space attached, we're going to be rendering in legacy
csmartdaltone812d492017-02-21 12:36:05 -0700222 // mode. In that case, we don't require sRGB capability and we defer to the client to decide on
223 // sRGB decode control.
Brian Osman7039f742016-11-01 15:56:16 -0400224 if (fColorSpace) {
csmartdaltone812d492017-02-21 12:36:05 -0700225 fContextOverrides |= ContextOverrides::kRequireSRGBSupport;
226 fContextOverrides |= ContextOverrides::kAllowSRGBWithoutDecodeControl;
csmartdalton6270e552016-09-13 10:41:49 -0700227 }
Eric Karl5c779752017-05-08 12:02:07 -0700228 if (!useStencilBuffers) {
229 fContextOverrides |= ContextOverrides::kAvoidStencilBuffers;
230 }
kkinnunen3e980c32015-12-23 01:33:00 -0800231}
232static bool parse_option_int(const SkString& value, int* outInt) {
233 if (value.isEmpty()) {
234 return false;
235 }
236 char* endptr = nullptr;
237 long intValue = strtol(value.c_str(), &endptr, 10);
238 if (*endptr != '\0') {
239 return false;
240 }
241 *outInt = static_cast<int>(intValue);
242 return true;
243}
244static bool parse_option_bool(const SkString& value, bool* outBool) {
245 if (value.equals("true")) {
246 *outBool = true;
247 return true;
248 }
249 if (value.equals("false")) {
250 *outBool = false;
251 return true;
252 }
253 return false;
254}
255static bool parse_option_gpu_api(const SkString& value,
256 SkCommandLineConfigGpu::ContextType* outContextType) {
kkinnunen3e980c32015-12-23 01:33:00 -0800257 if (value.equals("gl")) {
bsalomon85b4b532016-04-05 11:06:27 -0700258 *outContextType = GrContextFactory::kGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800259 return true;
260 }
261 if (value.equals("gles")) {
bsalomon85b4b532016-04-05 11:06:27 -0700262 *outContextType = GrContextFactory::kGLES_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800263 return true;
264 }
Brian Salomon6405e712017-03-20 08:54:16 -0400265 if (value.equals("debuggl")) {
bsalomon85b4b532016-04-05 11:06:27 -0700266 *outContextType = GrContextFactory::kDebugGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800267 return true;
268 }
Brian Salomon6405e712017-03-20 08:54:16 -0400269 if (value.equals("nullgl")) {
bsalomon85b4b532016-04-05 11:06:27 -0700270 *outContextType = GrContextFactory::kNullGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800271 return true;
272 }
bsalomon11abd8d2016-10-14 08:13:48 -0700273 if (value.equals("angle_d3d9_es2")) {
274 *outContextType = GrContextFactory::kANGLE_D3D9_ES2_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800275 return true;
276 }
bsalomon11abd8d2016-10-14 08:13:48 -0700277 if (value.equals("angle_d3d11_es2")) {
278 *outContextType = GrContextFactory::kANGLE_D3D11_ES2_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800279 return true;
280 }
bsalomon11abd8d2016-10-14 08:13:48 -0700281 if (value.equals("angle_d3d11_es3")) {
282 *outContextType = GrContextFactory::kANGLE_D3D11_ES3_ContextType;
283 return true;
284 }
285 if (value.equals("angle_gl_es2")) {
286 *outContextType = GrContextFactory::kANGLE_GL_ES2_ContextType;
287 return true;
288 }
289 if (value.equals("angle_gl_es3")) {
290 *outContextType = GrContextFactory::kANGLE_GL_ES3_ContextType;
291 return true;
292 }
kkinnunen3e980c32015-12-23 01:33:00 -0800293 if (value.equals("commandbuffer")) {
bsalomon85b4b532016-04-05 11:06:27 -0700294 *outContextType = GrContextFactory::kCommandBuffer_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800295 return true;
296 }
Brian Salomon8fe24272017-07-07 12:56:11 -0400297 if (value.equals("mock")) {
298 *outContextType = GrContextFactory::kMock_ContextType;
299 return true;
300 }
bsalomondc0fcd42016-04-11 14:21:33 -0700301#ifdef SK_VULKAN
302 if (value.equals("vulkan")) {
303 *outContextType = GrContextFactory::kVulkan_ContextType;
304 return true;
305 }
306#endif
Greg Daniel2811aa22017-07-13 15:34:56 -0400307#ifdef SK_METAL
308 if (value.equals("metal")) {
309 *outContextType = GrContextFactory::kMetal_ContextType;
310 return true;
311 }
312#endif
kkinnunen3e980c32015-12-23 01:33:00 -0800313 return false;
314}
brianosmand93c1202016-03-10 07:49:08 -0800315static bool parse_option_gpu_color(const SkString& value,
316 SkColorType* outColorType,
Brian Salomonce5ee602017-07-17 11:31:31 -0400317 SkAlphaType* alphaType,
brianosmanb109b8c2016-06-16 13:03:24 -0700318 sk_sp<SkColorSpace>* outColorSpace) {
Brian Salomonce5ee602017-07-17 11:31:31 -0400319 // We always use premul unless the color type is 565.
320 *alphaType = kPremul_SkAlphaType;
321
brianosmand93c1202016-03-10 07:49:08 -0800322 if (value.equals("8888")) {
bsalomon33069252016-09-28 08:49:53 -0700323 *outColorType = kRGBA_8888_SkColorType;
brianosmanb109b8c2016-06-16 13:03:24 -0700324 *outColorSpace = nullptr;
brianosmand93c1202016-03-10 07:49:08 -0800325 return true;
Brian Salomonce5ee602017-07-17 11:31:31 -0400326 } else if (value.equals("4444")) {
327 *outColorType = kARGB_4444_SkColorType;
328 *outColorSpace = nullptr;
329 return true;
330 } else if (value.equals("565")) {
331 *outColorType = kRGB_565_SkColorType;
332 *alphaType = kOpaque_SkAlphaType;
333 *outColorSpace = nullptr;
334 return true;
brianosmand93c1202016-03-10 07:49:08 -0800335 }
brianosman4562f6e2016-09-19 14:42:04 -0700336
337 SkTArray<SkString> commands;
338 SkStrSplit(value.c_str(), "_", &commands);
339 if (commands.count() < 1 || commands.count() > 2) {
340 return false;
341 }
342
raftias94888332016-10-18 10:02:51 -0700343 const bool linearGamma = commands[0].equals("f16");
Matt Sarettd2228302017-03-02 08:53:46 -0500344 SkColorSpace::Gamut gamut = SkColorSpace::kSRGB_Gamut;
345 SkColorSpace::RenderTargetGamma gamma = linearGamma ? SkColorSpace::kLinear_RenderTargetGamma
346 : SkColorSpace::kSRGB_RenderTargetGamma;
Matt Sarettf3880932017-03-24 10:06:03 -0400347 *outColorSpace = SkColorSpace::MakeRGB(gamma, gamut);
Matt Sarettd2228302017-03-02 08:53:46 -0500348
brianosman4562f6e2016-09-19 14:42:04 -0700349 if (commands.count() == 2) {
350 if (commands[1].equals("srgb")) {
351 // sRGB gamut (which is our default)
352 } else if (commands[1].equals("wide")) {
353 // WideGamut RGB
354 const float gWideGamutRGB_toXYZD50[]{
355 0.7161046f, 0.1009296f, 0.1471858f, // -> X
356 0.2581874f, 0.7249378f, 0.0168748f, // -> Y
357 0.0000000f, 0.0517813f, 0.7734287f, // -> Z
358 };
359 SkMatrix44 wideGamutRGBMatrix(SkMatrix44::kUninitialized_Constructor);
360 wideGamutRGBMatrix.set3x3RowMajorf(gWideGamutRGB_toXYZD50);
Matt Sarettf3880932017-03-24 10:06:03 -0400361 *outColorSpace = SkColorSpace::MakeRGB(gamma, wideGamutRGBMatrix);
Brian Osman4a6b28e2016-10-17 11:14:02 -0400362 } else if (commands[1].equals("narrow")) {
363 // NarrowGamut RGB (an artifically smaller than sRGB gamut)
364 SkColorSpacePrimaries primaries ={
365 0.54f, 0.33f, // Rx, Ry
366 0.33f, 0.50f, // Gx, Gy
367 0.25f, 0.20f, // Bx, By
368 0.3127f, 0.3290f, // Wx, Wy
369 };
370 SkMatrix44 narrowGamutRGBMatrix(SkMatrix44::kUninitialized_Constructor);
371 primaries.toXYZD50(&narrowGamutRGBMatrix);
Matt Sarettf3880932017-03-24 10:06:03 -0400372 *outColorSpace = SkColorSpace::MakeRGB(gamma, narrowGamutRGBMatrix);
brianosman4562f6e2016-09-19 14:42:04 -0700373 } else {
374 // Unknown color gamut
375 return false;
376 }
377 }
378
379 // Now pick a color type
380 if (commands[0].equals("f16")) {
brianosmand93c1202016-03-10 07:49:08 -0800381 *outColorType = kRGBA_F16_SkColorType;
brianosmand93c1202016-03-10 07:49:08 -0800382 return true;
383 }
Matt Sarettd2228302017-03-02 08:53:46 -0500384 if (commands[0].equals("srgb") || commands[0].equals("srgbnl")) {
bsalomon33069252016-09-28 08:49:53 -0700385 *outColorType = kRGBA_8888_SkColorType;
brianosmand93c1202016-03-10 07:49:08 -0800386 return true;
387 }
388 return false;
389}
kkinnunen3e980c32015-12-23 01:33:00 -0800390
391SkCommandLineConfigGpu* parse_command_line_config_gpu(const SkString& tag,
392 const SkTArray<SkString>& vias,
393 const SkString& options) {
394 // Defaults for GPU backend.
395 bool seenAPI = false;
Brian Salomon6405e712017-03-20 08:54:16 -0400396 SkCommandLineConfigGpu::ContextType contextType = GrContextFactory::kGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800397 bool seenUseNVPR = false;
398 bool useNVPR = false;
399 bool seenUseDIText =false;
400 bool useDIText = false;
401 bool seenSamples = false;
402 int samples = 0;
brianosmand93c1202016-03-10 07:49:08 -0800403 bool seenColor = false;
bsalomon33069252016-09-28 08:49:53 -0700404 SkColorType colorType = kRGBA_8888_SkColorType;
Brian Salomonce5ee602017-07-17 11:31:31 -0400405 SkAlphaType alphaType = kPremul_SkAlphaType;
brianosmanb109b8c2016-06-16 13:03:24 -0700406 sk_sp<SkColorSpace> colorSpace = nullptr;
Eric Karl5c779752017-05-08 12:02:07 -0700407 bool seenUseStencils = false;
408 bool useStencils = true;
Brian Osmanf9810662017-08-30 10:02:10 -0400409 bool seenTestThreading = false;
410 bool testThreading = false;
kkinnunen3e980c32015-12-23 01:33:00 -0800411
412 SkTArray<SkString> optionParts;
413 SkStrSplit(options.c_str(), ",", kStrict_SkStrSplitMode, &optionParts);
414 for (int i = 0; i < optionParts.count(); ++i) {
415 SkTArray<SkString> keyValueParts;
416 SkStrSplit(optionParts[i].c_str(), "=", kStrict_SkStrSplitMode, &keyValueParts);
417 if (keyValueParts.count() != 2) {
418 return nullptr;
419 }
420 const SkString& key = keyValueParts[0];
421 const SkString& value = keyValueParts[1];
422 bool valueOk = false;
423 if (key.equals("api") && !seenAPI) {
424 valueOk = parse_option_gpu_api(value, &contextType);
425 seenAPI = true;
426 } else if (key.equals("nvpr") && !seenUseNVPR) {
427 valueOk = parse_option_bool(value, &useNVPR);
428 seenUseNVPR = true;
429 } else if (key.equals("dit") && !seenUseDIText) {
430 valueOk = parse_option_bool(value, &useDIText);
431 seenUseDIText = true;
432 } else if (key.equals("samples") && !seenSamples) {
433 valueOk = parse_option_int(value, &samples);
434 seenSamples = true;
brianosmand93c1202016-03-10 07:49:08 -0800435 } else if (key.equals("color") && !seenColor) {
Brian Salomonce5ee602017-07-17 11:31:31 -0400436 valueOk = parse_option_gpu_color(value, &colorType, &alphaType, &colorSpace);
brianosmand93c1202016-03-10 07:49:08 -0800437 seenColor = true;
Eric Karl5c779752017-05-08 12:02:07 -0700438 } else if (key.equals("stencils") && !seenUseStencils) {
439 valueOk = parse_option_bool(value, &useStencils);
440 seenUseStencils = true;
Brian Osmanf9810662017-08-30 10:02:10 -0400441 } else if (key.equals("testThreading") && !seenTestThreading) {
442 valueOk = parse_option_bool(value, &testThreading);
443 seenTestThreading = true;
kkinnunen3e980c32015-12-23 01:33:00 -0800444 }
445 if (!valueOk) {
446 return nullptr;
447 }
448 }
Brian Salomon6405e712017-03-20 08:54:16 -0400449 if (!seenAPI) {
450 return nullptr;
451 }
Brian Salomonf06c3582017-12-07 14:34:36 -0500452 return new SkCommandLineConfigGpu(tag, vias, contextType, useNVPR, useDIText,
Brian Osmanf9810662017-08-30 10:02:10 -0400453 samples, colorType, alphaType, colorSpace, useStencils,
454 testThreading);
kkinnunen3e980c32015-12-23 01:33:00 -0800455}
456#endif
457
458void ParseConfigs(const SkCommandLineFlags::StringArray& configs,
459 SkCommandLineConfigArray* outResult) {
460 outResult->reset();
461 for (int i = 0; i < configs.count(); ++i) {
462 SkString extendedBackend;
463 SkString extendedOptions;
464 SkString simpleBackend;
465 SkTArray<SkString> vias;
466
467 SkString tag(configs[i]);
468 SkTArray<SkString> parts;
bsalomon808ecbb2016-09-28 12:40:22 -0700469 SkStrSplit(tag.c_str(), "[", kStrict_SkStrSplitMode, &parts);
kkinnunen3e980c32015-12-23 01:33:00 -0800470 if (parts.count() == 2) {
471 SkTArray<SkString> parts2;
bsalomon808ecbb2016-09-28 12:40:22 -0700472 SkStrSplit(parts[1].c_str(), "]", kStrict_SkStrSplitMode, &parts2);
kkinnunen3e980c32015-12-23 01:33:00 -0800473 if (parts2.count() == 2 && parts2[1].isEmpty()) {
474 SkStrSplit(parts[0].c_str(), "-", kStrict_SkStrSplitMode, &vias);
475 if (vias.count()) {
476 extendedBackend = vias[vias.count() - 1];
477 vias.pop_back();
478 } else {
479 extendedBackend = parts[0];
480 }
481 extendedOptions = parts2[0];
bsalomon808ecbb2016-09-28 12:40:22 -0700482 simpleBackend.printf("%s[%s]", extendedBackend.c_str(), extendedOptions.c_str());
kkinnunen3e980c32015-12-23 01:33:00 -0800483 }
484 }
485
486 if (extendedBackend.isEmpty()) {
487 simpleBackend = tag;
488 SkStrSplit(tag.c_str(), "-", kStrict_SkStrSplitMode, &vias);
489 if (vias.count()) {
490 simpleBackend = vias[vias.count() - 1];
491 vias.pop_back();
492 }
kkinnunen3e980c32015-12-23 01:33:00 -0800493 for (auto& predefinedConfig : gPredefinedConfigs) {
494 if (simpleBackend.equals(predefinedConfig.predefinedConfig)) {
495 extendedBackend = predefinedConfig.backend;
496 extendedOptions = predefinedConfig.options;
497 break;
498 }
499 }
500 }
501 SkCommandLineConfig* parsedConfig = nullptr;
502#if SK_SUPPORT_GPU
503 if (extendedBackend.equals("gpu")) {
504 parsedConfig = parse_command_line_config_gpu(tag, vias, extendedOptions);
505 }
506#endif
507 if (!parsedConfig) {
508 parsedConfig = new SkCommandLineConfig(tag, simpleBackend, vias);
509 }
510 outResult->emplace_back(parsedConfig);
511 }
512}