blob: 91805a90f33502a0b580ef44bada6cd2704eb15b [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 Salomonce5ee602017-07-17 11:31:31 -040050 { "gl4444", "gpu", "api=gl,color=4444" },
51 { "gl565", "gpu", "api=gl,color=565" },
Brian Salomon6405e712017-03-20 08:54:16 -040052 { "glf16", "gpu", "api=gl,color=f16" },
53 { "glsrgb", "gpu", "api=gl,color=srgb" },
54 { "glsrgbnl", "gpu", "api=gl,color=srgbnl" },
55 { "glesf16", "gpu", "api=gles,color=f16" },
56 { "glessrgb", "gpu", "api=gles,color=srgb" },
57 { "glessrgbnl", "gpu", "api=gles,color=srgbnl" },
Brian Salomon002c1202016-10-18 11:28:20 -040058 { "glsrgb", "gpu", "api=gl,color=srgb" },
59 { "glwide", "gpu", "api=gl,color=f16_wide" },
60 { "glnarrow", "gpu", "api=gl,color=f16_narrow" },
Eric Karl5c779752017-05-08 12:02:07 -070061 { "glnostencils", "gpu", "api=gl,stencils=false" },
Brian Salomond1e61922018-01-24 17:25:03 -050062 { "gles4444", "gpu", "api=gles,color=4444" },
Brian Salomon50f66d82017-03-17 14:32:05 -040063 { "glessrgb", "gpu", "api=gles,color=srgb" },
64 { "gleswide", "gpu", "api=gles,color=f16_wide" },
65 { "glesnarrow", "gpu", "api=gles,color=f16_narrow" },
Brian Salomon50f66d82017-03-17 14:32:05 -040066 { "gldft", "gpu", "api=gl,dit=true" },
67 { "glesdft", "gpu", "api=gles,dit=true" },
Brian Osmanf9810662017-08-30 10:02:10 -040068 { "gltestthreading", "gpu", "api=gl,testThreading=true" },
Brian Salomon6405e712017-03-20 08:54:16 -040069 { "debuggl", "gpu", "api=debuggl" },
70 { "nullgl", "gpu", "api=nullgl" },
Brian Salomon002c1202016-10-18 11:28:20 -040071 { "angle_d3d11_es2", "gpu", "api=angle_d3d11_es2" },
Brian Osman21d742d2017-01-10 13:31:33 -050072 { "angle_d3d11_es3", "gpu", "api=angle_d3d11_es3" },
Brian Salomon002c1202016-10-18 11:28:20 -040073 { "angle_d3d9_es2", "gpu", "api=angle_d3d9_es2" },
74 { "angle_d3d11_es2_msaa4", "gpu", "api=angle_d3d11_es2,samples=4" },
Brian Salomon528ca9b2017-03-24 11:15:09 -040075 { "angle_d3d11_es2_msaa8", "gpu", "api=angle_d3d11_es2,samples=8" },
Brian Salomon8c865882017-06-22 09:56:24 -040076 { "angle_d3d11_es3_msaa4", "gpu", "api=angle_d3d11_es3,samples=4" },
77 { "angle_d3d11_es3_msaa8", "gpu", "api=angle_d3d11_es3,samples=8" },
Brian Salomon002c1202016-10-18 11:28:20 -040078 { "angle_gl_es2", "gpu", "api=angle_gl_es2" },
Brian Osman21d742d2017-01-10 13:31:33 -050079 { "angle_gl_es3", "gpu", "api=angle_gl_es3" },
Brian Salomon8fe24272017-07-07 12:56:11 -040080 { "commandbuffer", "gpu", "api=commandbuffer" },
81 { "mock", "gpu", "api=mock" }
brianosman37e23342016-09-20 08:06:30 -070082#ifdef SK_VULKAN
Brian Salomon002c1202016-10-18 11:28:20 -040083 ,{ "vk", "gpu", "api=vulkan" }
84 ,{ "vksrgb", "gpu", "api=vulkan,color=srgb" }
85 ,{ "vkwide", "gpu", "api=vulkan,color=f16_wide" }
86 ,{ "vkmsaa4", "gpu", "api=vulkan,samples=4" }
Brian Salomondcf0ab02017-03-20 11:10:21 -040087 ,{ "vkmsaa8", "gpu", "api=vulkan,samples=8" }
brianosman37e23342016-09-20 08:06:30 -070088#endif
Greg Daniel2811aa22017-07-13 15:34:56 -040089#ifdef SK_METAL
90 ,{ "mtl", "gpu", "api=metal" }
91 ,{ "mtlsrgb", "gpu", "api=metal,color=srgb" }
92 ,{ "mtlwide", "gpu", "api=metal,color=f16_wide" }
93 ,{ "mtlmsaa4", "gpu", "api=metal,samples=4" }
94 ,{ "mtlmsaa8", "gpu", "api=metal,samples=8" }
95#endif
brianosman37e23342016-09-20 08:06:30 -070096#else
Brian Salomon8fe24272017-07-07 12:56:11 -040097 { "", "", "" }
brianosman37e23342016-09-20 08:06:30 -070098#endif
99};
100
101static const char configHelp[] =
Derek Sollenbergerc65386a2017-01-05 09:50:22 -0500102 "Options: 565 8888 srgb f16 nonrendering null pdf pdfa skp pipe svg xps";
brianosman37e23342016-09-20 08:06:30 -0700103
104static const char* config_help_fn() {
105 static SkString helpString;
106 helpString.set(configHelp);
107 for (const auto& config : gPredefinedConfigs) {
108 helpString.appendf(" %s", config.predefinedConfig);
109 }
bsalomon808ecbb2016-09-28 12:40:22 -0700110 helpString.append(" or use extended form 'backend[option=value,...]'.\n");
brianosman37e23342016-09-20 08:06:30 -0700111 return helpString.c_str();
112}
kkinnunen3e980c32015-12-23 01:33:00 -0800113
114static const char configExtendedHelp[] =
115 "Extended form: 'backend(option=value,...)'\n\n"
116 "Possible backends and options:\n"
117#if SK_SUPPORT_GPU
118 "\n"
bsalomon808ecbb2016-09-28 12:40:22 -0700119 "gpu[api=string,color=string,dit=bool,nvpr=bool,inst=bool,samples=int]\n"
Brian Salomon6405e712017-03-20 08:54:16 -0400120 "\tapi\ttype: string\trequired\n"
kkinnunen3e980c32015-12-23 01:33:00 -0800121 "\t Select graphics API to use with gpu backend.\n"
122 "\t Options:\n"
kkinnunen3e980c32015-12-23 01:33:00 -0800123 "\t\tgl \t\t\tUse OpenGL.\n"
124 "\t\tgles \t\t\tUse OpenGL ES.\n"
Brian Salomon6405e712017-03-20 08:54:16 -0400125 "\t\tdebuggl \t\t\tUse debug OpenGL.\n"
126 "\t\tnullgl \t\t\tUse null OpenGL.\n"
bsalomon11abd8d2016-10-14 08:13:48 -0700127 "\t\tangle_d3d9_es2\t\t\tUse OpenGL ES2 on the ANGLE Direct3D9 backend.\n"
128 "\t\tangle_d3d11_es2\t\t\tUse OpenGL ES2 on the ANGLE Direct3D11 backend.\n"
129 "\t\tangle_d3d11_es3\t\t\tUse OpenGL ES3 on the ANGLE Direct3D11 backend.\n"
130 "\t\tangle_gl_es2\t\t\tUse OpenGL ES2 on the ANGLE OpenGL backend.\n"
131 "\t\tangle_gl_es3\t\t\tUse OpenGL ES3 on the ANGLE OpenGL backend.\n"
kkinnunen3e980c32015-12-23 01:33:00 -0800132 "\t\tcommandbuffer\t\tUse command buffer.\n"
Brian Salomon8fe24272017-07-07 12:56:11 -0400133 "\t\tmock\t\tUse mock context.\n"
bsalomondc0fcd42016-04-11 14:21:33 -0700134#ifdef SK_VULKAN
135 "\t\tvulkan\t\t\tUse Vulkan.\n"
136#endif
Greg Daniel2811aa22017-07-13 15:34:56 -0400137#ifdef SK_METAL
138 "\t\tmetal\t\t\tUse Metal.\n"
139#endif
brianosmand93c1202016-03-10 07:49:08 -0800140 "\tcolor\ttype: string\tdefault: 8888.\n"
141 "\t Select framebuffer color format.\n"
142 "\t Options:\n"
143 "\t\t8888\t\t\tLinear 8888.\n"
Brian Salomonce5ee602017-07-17 11:31:31 -0400144 "\t\t4444\t\t\tLinear 4444.\n"
145 "\t\t565\t\t\tLinear 565.\n"
brianosman4562f6e2016-09-19 14:42:04 -0700146 "\t\tf16{_gamut}\t\tLinear 16-bit floating point.\n"
147 "\t\tsrgb{_gamut}\t\tsRGB 8888.\n"
148 "\t gamut\ttype: string\tdefault: srgb.\n"
149 "\t Select color gamut for f16 or sRGB format buffers.\n"
150 "\t Options:\n"
151 "\t\tsrgb\t\t\tsRGB gamut.\n"
152 "\t\twide\t\t\tWide Gamut RGB.\n"
kkinnunen3e980c32015-12-23 01:33:00 -0800153 "\tdit\ttype: bool\tdefault: false.\n"
154 "\t Use device independent text.\n"
155 "\tnvpr\ttype: bool\tdefault: false.\n"
156 "\t Use NV_path_rendering OpenGL and OpenGL ES extension.\n"
157 "\tsamples\ttype: int\tdefault: 0.\n"
158 "\t Use multisampling with N samples.\n"
Eric Karl5c779752017-05-08 12:02:07 -0700159 "\tstencils\ttype: bool\tdefault: true.\n"
160 "\t Allow the use of stencil buffers.\n"
Brian Osmanf9810662017-08-30 10:02:10 -0400161 "\ttestThreading\ttype: bool\tdefault: false.\n"
162 "\t Run config with and without worker threads, check that results match.\n"
kkinnunen3e980c32015-12-23 01:33:00 -0800163 "\n"
164 "Predefined configs:\n\n"
brianosman37e23342016-09-20 08:06:30 -0700165 // Help text for pre-defined configs is auto-generated from gPredefinedConfigs
kkinnunen3e980c32015-12-23 01:33:00 -0800166#endif
167 ;
168
brianosman37e23342016-09-20 08:06:30 -0700169static const char* config_extended_help_fn() {
170 static SkString helpString;
171 helpString.set(configExtendedHelp);
172 for (const auto& config : gPredefinedConfigs) {
173 helpString.appendf("\t%-10s\t= gpu(%s)\n", config.predefinedConfig, config.options);
174 }
175 return helpString.c_str();
176}
kkinnunen3e980c32015-12-23 01:33:00 -0800177
brianosman37e23342016-09-20 08:06:30 -0700178DEFINE_extended_string(config, defaultConfigs, config_help_fn(), config_extended_help_fn());
kkinnunen3e980c32015-12-23 01:33:00 -0800179
180SkCommandLineConfig::SkCommandLineConfig(const SkString& tag, const SkString& backend,
181 const SkTArray<SkString>& viaParts)
182 : fTag(tag)
183 , fBackend(backend)
184 , fViaParts(viaParts) {
185}
186SkCommandLineConfig::~SkCommandLineConfig() {
187}
188
189#if SK_SUPPORT_GPU
190SkCommandLineConfigGpu::SkCommandLineConfigGpu(
csmartdaltone0d36292016-07-29 08:14:20 -0700191 const SkString& tag, const SkTArray<SkString>& viaParts, ContextType contextType, bool useNVPR,
Brian Salomonf06c3582017-12-07 14:34:36 -0500192 bool useDIText, int samples, SkColorType colorType, SkAlphaType alphaType,
Brian Osmanf9810662017-08-30 10:02:10 -0400193 sk_sp<SkColorSpace> colorSpace, bool useStencilBuffers, bool testThreading)
kkinnunen3e980c32015-12-23 01:33:00 -0800194 : SkCommandLineConfig(tag, SkString("gpu"), viaParts)
195 , fContextType(contextType)
csmartdaltone812d492017-02-21 12:36:05 -0700196 , fContextOverrides(ContextOverrides::kNone)
kkinnunen3e980c32015-12-23 01:33:00 -0800197 , fUseDIText(useDIText)
brianosmand93c1202016-03-10 07:49:08 -0800198 , fSamples(samples)
199 , fColorType(colorType)
Brian Salomonce5ee602017-07-17 11:31:31 -0400200 , fAlphaType(alphaType)
Brian Osmanf9810662017-08-30 10:02:10 -0400201 , fColorSpace(std::move(colorSpace))
202 , fTestThreading(testThreading) {
csmartdalton6270e552016-09-13 10:41:49 -0700203 if (useNVPR) {
csmartdaltone812d492017-02-21 12:36:05 -0700204 fContextOverrides |= ContextOverrides::kRequireNVPRSupport;
Brian Salomonf06c3582017-12-07 14:34:36 -0500205 } else {
csmartdaltone812d492017-02-21 12:36:05 -0700206 // We don't disable NVPR for instanced configs. Otherwise the caps wouldn't use mixed
207 // samples and we couldn't test the mixed samples backend for simple shapes.
208 fContextOverrides |= ContextOverrides::kDisableNVPR;
csmartdalton6270e552016-09-13 10:41:49 -0700209 }
brianosman20471892016-12-02 06:43:32 -0800210 // Subtle logic: If the config has a color space attached, we're going to be rendering to sRGB,
211 // so we need that capability. In addition, to get the widest test coverage, we DO NOT require
212 // that we can disable sRGB decode. (That's for rendering sRGB sources to legacy surfaces).
213 //
214 // If the config doesn't have a color space attached, we're going to be rendering in legacy
csmartdaltone812d492017-02-21 12:36:05 -0700215 // mode. In that case, we don't require sRGB capability and we defer to the client to decide on
216 // sRGB decode control.
Brian Osman7039f742016-11-01 15:56:16 -0400217 if (fColorSpace) {
csmartdaltone812d492017-02-21 12:36:05 -0700218 fContextOverrides |= ContextOverrides::kRequireSRGBSupport;
219 fContextOverrides |= ContextOverrides::kAllowSRGBWithoutDecodeControl;
csmartdalton6270e552016-09-13 10:41:49 -0700220 }
Eric Karl5c779752017-05-08 12:02:07 -0700221 if (!useStencilBuffers) {
222 fContextOverrides |= ContextOverrides::kAvoidStencilBuffers;
223 }
kkinnunen3e980c32015-12-23 01:33:00 -0800224}
225static bool parse_option_int(const SkString& value, int* outInt) {
226 if (value.isEmpty()) {
227 return false;
228 }
229 char* endptr = nullptr;
230 long intValue = strtol(value.c_str(), &endptr, 10);
231 if (*endptr != '\0') {
232 return false;
233 }
234 *outInt = static_cast<int>(intValue);
235 return true;
236}
237static bool parse_option_bool(const SkString& value, bool* outBool) {
238 if (value.equals("true")) {
239 *outBool = true;
240 return true;
241 }
242 if (value.equals("false")) {
243 *outBool = false;
244 return true;
245 }
246 return false;
247}
248static bool parse_option_gpu_api(const SkString& value,
249 SkCommandLineConfigGpu::ContextType* outContextType) {
kkinnunen3e980c32015-12-23 01:33:00 -0800250 if (value.equals("gl")) {
bsalomon85b4b532016-04-05 11:06:27 -0700251 *outContextType = GrContextFactory::kGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800252 return true;
253 }
254 if (value.equals("gles")) {
bsalomon85b4b532016-04-05 11:06:27 -0700255 *outContextType = GrContextFactory::kGLES_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800256 return true;
257 }
Brian Salomon6405e712017-03-20 08:54:16 -0400258 if (value.equals("debuggl")) {
bsalomon85b4b532016-04-05 11:06:27 -0700259 *outContextType = GrContextFactory::kDebugGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800260 return true;
261 }
Brian Salomon6405e712017-03-20 08:54:16 -0400262 if (value.equals("nullgl")) {
bsalomon85b4b532016-04-05 11:06:27 -0700263 *outContextType = GrContextFactory::kNullGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800264 return true;
265 }
bsalomon11abd8d2016-10-14 08:13:48 -0700266 if (value.equals("angle_d3d9_es2")) {
267 *outContextType = GrContextFactory::kANGLE_D3D9_ES2_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800268 return true;
269 }
bsalomon11abd8d2016-10-14 08:13:48 -0700270 if (value.equals("angle_d3d11_es2")) {
271 *outContextType = GrContextFactory::kANGLE_D3D11_ES2_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800272 return true;
273 }
bsalomon11abd8d2016-10-14 08:13:48 -0700274 if (value.equals("angle_d3d11_es3")) {
275 *outContextType = GrContextFactory::kANGLE_D3D11_ES3_ContextType;
276 return true;
277 }
278 if (value.equals("angle_gl_es2")) {
279 *outContextType = GrContextFactory::kANGLE_GL_ES2_ContextType;
280 return true;
281 }
282 if (value.equals("angle_gl_es3")) {
283 *outContextType = GrContextFactory::kANGLE_GL_ES3_ContextType;
284 return true;
285 }
kkinnunen3e980c32015-12-23 01:33:00 -0800286 if (value.equals("commandbuffer")) {
bsalomon85b4b532016-04-05 11:06:27 -0700287 *outContextType = GrContextFactory::kCommandBuffer_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800288 return true;
289 }
Brian Salomon8fe24272017-07-07 12:56:11 -0400290 if (value.equals("mock")) {
291 *outContextType = GrContextFactory::kMock_ContextType;
292 return true;
293 }
bsalomondc0fcd42016-04-11 14:21:33 -0700294#ifdef SK_VULKAN
295 if (value.equals("vulkan")) {
296 *outContextType = GrContextFactory::kVulkan_ContextType;
297 return true;
298 }
299#endif
Greg Daniel2811aa22017-07-13 15:34:56 -0400300#ifdef SK_METAL
301 if (value.equals("metal")) {
302 *outContextType = GrContextFactory::kMetal_ContextType;
303 return true;
304 }
305#endif
kkinnunen3e980c32015-12-23 01:33:00 -0800306 return false;
307}
brianosmand93c1202016-03-10 07:49:08 -0800308static bool parse_option_gpu_color(const SkString& value,
309 SkColorType* outColorType,
Brian Salomonce5ee602017-07-17 11:31:31 -0400310 SkAlphaType* alphaType,
brianosmanb109b8c2016-06-16 13:03:24 -0700311 sk_sp<SkColorSpace>* outColorSpace) {
Brian Salomonce5ee602017-07-17 11:31:31 -0400312 // We always use premul unless the color type is 565.
313 *alphaType = kPremul_SkAlphaType;
314
brianosmand93c1202016-03-10 07:49:08 -0800315 if (value.equals("8888")) {
bsalomon33069252016-09-28 08:49:53 -0700316 *outColorType = kRGBA_8888_SkColorType;
brianosmanb109b8c2016-06-16 13:03:24 -0700317 *outColorSpace = nullptr;
brianosmand93c1202016-03-10 07:49:08 -0800318 return true;
Brian Salomonce5ee602017-07-17 11:31:31 -0400319 } else if (value.equals("4444")) {
320 *outColorType = kARGB_4444_SkColorType;
321 *outColorSpace = nullptr;
322 return true;
323 } else if (value.equals("565")) {
324 *outColorType = kRGB_565_SkColorType;
325 *alphaType = kOpaque_SkAlphaType;
326 *outColorSpace = nullptr;
327 return true;
brianosmand93c1202016-03-10 07:49:08 -0800328 }
brianosman4562f6e2016-09-19 14:42:04 -0700329
330 SkTArray<SkString> commands;
331 SkStrSplit(value.c_str(), "_", &commands);
332 if (commands.count() < 1 || commands.count() > 2) {
333 return false;
334 }
335
raftias94888332016-10-18 10:02:51 -0700336 const bool linearGamma = commands[0].equals("f16");
Matt Sarettd2228302017-03-02 08:53:46 -0500337 SkColorSpace::Gamut gamut = SkColorSpace::kSRGB_Gamut;
338 SkColorSpace::RenderTargetGamma gamma = linearGamma ? SkColorSpace::kLinear_RenderTargetGamma
339 : SkColorSpace::kSRGB_RenderTargetGamma;
Matt Sarettf3880932017-03-24 10:06:03 -0400340 *outColorSpace = SkColorSpace::MakeRGB(gamma, gamut);
Matt Sarettd2228302017-03-02 08:53:46 -0500341
brianosman4562f6e2016-09-19 14:42:04 -0700342 if (commands.count() == 2) {
343 if (commands[1].equals("srgb")) {
344 // sRGB gamut (which is our default)
345 } else if (commands[1].equals("wide")) {
346 // WideGamut RGB
347 const float gWideGamutRGB_toXYZD50[]{
348 0.7161046f, 0.1009296f, 0.1471858f, // -> X
349 0.2581874f, 0.7249378f, 0.0168748f, // -> Y
350 0.0000000f, 0.0517813f, 0.7734287f, // -> Z
351 };
352 SkMatrix44 wideGamutRGBMatrix(SkMatrix44::kUninitialized_Constructor);
353 wideGamutRGBMatrix.set3x3RowMajorf(gWideGamutRGB_toXYZD50);
Matt Sarettf3880932017-03-24 10:06:03 -0400354 *outColorSpace = SkColorSpace::MakeRGB(gamma, wideGamutRGBMatrix);
Brian Osman4a6b28e2016-10-17 11:14:02 -0400355 } else if (commands[1].equals("narrow")) {
356 // NarrowGamut RGB (an artifically smaller than sRGB gamut)
357 SkColorSpacePrimaries primaries ={
358 0.54f, 0.33f, // Rx, Ry
359 0.33f, 0.50f, // Gx, Gy
360 0.25f, 0.20f, // Bx, By
361 0.3127f, 0.3290f, // Wx, Wy
362 };
363 SkMatrix44 narrowGamutRGBMatrix(SkMatrix44::kUninitialized_Constructor);
364 primaries.toXYZD50(&narrowGamutRGBMatrix);
Matt Sarettf3880932017-03-24 10:06:03 -0400365 *outColorSpace = SkColorSpace::MakeRGB(gamma, narrowGamutRGBMatrix);
brianosman4562f6e2016-09-19 14:42:04 -0700366 } else {
367 // Unknown color gamut
368 return false;
369 }
370 }
371
372 // Now pick a color type
373 if (commands[0].equals("f16")) {
brianosmand93c1202016-03-10 07:49:08 -0800374 *outColorType = kRGBA_F16_SkColorType;
brianosmand93c1202016-03-10 07:49:08 -0800375 return true;
376 }
Matt Sarettd2228302017-03-02 08:53:46 -0500377 if (commands[0].equals("srgb") || commands[0].equals("srgbnl")) {
bsalomon33069252016-09-28 08:49:53 -0700378 *outColorType = kRGBA_8888_SkColorType;
brianosmand93c1202016-03-10 07:49:08 -0800379 return true;
380 }
381 return false;
382}
kkinnunen3e980c32015-12-23 01:33:00 -0800383
384SkCommandLineConfigGpu* parse_command_line_config_gpu(const SkString& tag,
385 const SkTArray<SkString>& vias,
386 const SkString& options) {
387 // Defaults for GPU backend.
388 bool seenAPI = false;
Brian Salomon6405e712017-03-20 08:54:16 -0400389 SkCommandLineConfigGpu::ContextType contextType = GrContextFactory::kGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800390 bool seenUseNVPR = false;
391 bool useNVPR = false;
392 bool seenUseDIText =false;
393 bool useDIText = false;
394 bool seenSamples = false;
395 int samples = 0;
brianosmand93c1202016-03-10 07:49:08 -0800396 bool seenColor = false;
bsalomon33069252016-09-28 08:49:53 -0700397 SkColorType colorType = kRGBA_8888_SkColorType;
Brian Salomonce5ee602017-07-17 11:31:31 -0400398 SkAlphaType alphaType = kPremul_SkAlphaType;
brianosmanb109b8c2016-06-16 13:03:24 -0700399 sk_sp<SkColorSpace> colorSpace = nullptr;
Eric Karl5c779752017-05-08 12:02:07 -0700400 bool seenUseStencils = false;
401 bool useStencils = true;
Brian Osmanf9810662017-08-30 10:02:10 -0400402 bool seenTestThreading = false;
403 bool testThreading = false;
kkinnunen3e980c32015-12-23 01:33:00 -0800404
405 SkTArray<SkString> optionParts;
406 SkStrSplit(options.c_str(), ",", kStrict_SkStrSplitMode, &optionParts);
407 for (int i = 0; i < optionParts.count(); ++i) {
408 SkTArray<SkString> keyValueParts;
409 SkStrSplit(optionParts[i].c_str(), "=", kStrict_SkStrSplitMode, &keyValueParts);
410 if (keyValueParts.count() != 2) {
411 return nullptr;
412 }
413 const SkString& key = keyValueParts[0];
414 const SkString& value = keyValueParts[1];
415 bool valueOk = false;
416 if (key.equals("api") && !seenAPI) {
417 valueOk = parse_option_gpu_api(value, &contextType);
418 seenAPI = true;
419 } else if (key.equals("nvpr") && !seenUseNVPR) {
420 valueOk = parse_option_bool(value, &useNVPR);
421 seenUseNVPR = true;
422 } else if (key.equals("dit") && !seenUseDIText) {
423 valueOk = parse_option_bool(value, &useDIText);
424 seenUseDIText = true;
425 } else if (key.equals("samples") && !seenSamples) {
426 valueOk = parse_option_int(value, &samples);
427 seenSamples = true;
brianosmand93c1202016-03-10 07:49:08 -0800428 } else if (key.equals("color") && !seenColor) {
Brian Salomonce5ee602017-07-17 11:31:31 -0400429 valueOk = parse_option_gpu_color(value, &colorType, &alphaType, &colorSpace);
brianosmand93c1202016-03-10 07:49:08 -0800430 seenColor = true;
Eric Karl5c779752017-05-08 12:02:07 -0700431 } else if (key.equals("stencils") && !seenUseStencils) {
432 valueOk = parse_option_bool(value, &useStencils);
433 seenUseStencils = true;
Brian Osmanf9810662017-08-30 10:02:10 -0400434 } else if (key.equals("testThreading") && !seenTestThreading) {
435 valueOk = parse_option_bool(value, &testThreading);
436 seenTestThreading = true;
kkinnunen3e980c32015-12-23 01:33:00 -0800437 }
438 if (!valueOk) {
439 return nullptr;
440 }
441 }
Brian Salomon6405e712017-03-20 08:54:16 -0400442 if (!seenAPI) {
443 return nullptr;
444 }
Brian Salomonf06c3582017-12-07 14:34:36 -0500445 return new SkCommandLineConfigGpu(tag, vias, contextType, useNVPR, useDIText,
Brian Osmanf9810662017-08-30 10:02:10 -0400446 samples, colorType, alphaType, colorSpace, useStencils,
447 testThreading);
kkinnunen3e980c32015-12-23 01:33:00 -0800448}
449#endif
450
451void ParseConfigs(const SkCommandLineFlags::StringArray& configs,
452 SkCommandLineConfigArray* outResult) {
453 outResult->reset();
454 for (int i = 0; i < configs.count(); ++i) {
455 SkString extendedBackend;
456 SkString extendedOptions;
457 SkString simpleBackend;
458 SkTArray<SkString> vias;
459
460 SkString tag(configs[i]);
461 SkTArray<SkString> parts;
bsalomon808ecbb2016-09-28 12:40:22 -0700462 SkStrSplit(tag.c_str(), "[", kStrict_SkStrSplitMode, &parts);
kkinnunen3e980c32015-12-23 01:33:00 -0800463 if (parts.count() == 2) {
464 SkTArray<SkString> parts2;
bsalomon808ecbb2016-09-28 12:40:22 -0700465 SkStrSplit(parts[1].c_str(), "]", kStrict_SkStrSplitMode, &parts2);
kkinnunen3e980c32015-12-23 01:33:00 -0800466 if (parts2.count() == 2 && parts2[1].isEmpty()) {
467 SkStrSplit(parts[0].c_str(), "-", kStrict_SkStrSplitMode, &vias);
468 if (vias.count()) {
469 extendedBackend = vias[vias.count() - 1];
470 vias.pop_back();
471 } else {
472 extendedBackend = parts[0];
473 }
474 extendedOptions = parts2[0];
bsalomon808ecbb2016-09-28 12:40:22 -0700475 simpleBackend.printf("%s[%s]", extendedBackend.c_str(), extendedOptions.c_str());
kkinnunen3e980c32015-12-23 01:33:00 -0800476 }
477 }
478
479 if (extendedBackend.isEmpty()) {
480 simpleBackend = tag;
481 SkStrSplit(tag.c_str(), "-", kStrict_SkStrSplitMode, &vias);
482 if (vias.count()) {
483 simpleBackend = vias[vias.count() - 1];
484 vias.pop_back();
485 }
kkinnunen3e980c32015-12-23 01:33:00 -0800486 for (auto& predefinedConfig : gPredefinedConfigs) {
487 if (simpleBackend.equals(predefinedConfig.predefinedConfig)) {
488 extendedBackend = predefinedConfig.backend;
489 extendedOptions = predefinedConfig.options;
490 break;
491 }
492 }
493 }
494 SkCommandLineConfig* parsedConfig = nullptr;
495#if SK_SUPPORT_GPU
496 if (extendedBackend.equals("gpu")) {
497 parsedConfig = parse_command_line_config_gpu(tag, vias, extendedOptions);
498 }
499#endif
500 if (!parsedConfig) {
501 parsedConfig = new SkCommandLineConfig(tag, simpleBackend, vias);
502 }
503 outResult->emplace_back(parsedConfig);
504 }
505}