blob: 6e5581029f5f906d0883c34cb078cbdc263d4d92 [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 Salomon6405e712017-03-20 08:54:16 -040058 { "glf16", "gpu", "api=gl,color=f16" },
59 { "glsrgb", "gpu", "api=gl,color=srgb" },
60 { "glsrgbnl", "gpu", "api=gl,color=srgbnl" },
61 { "glesf16", "gpu", "api=gles,color=f16" },
62 { "glessrgb", "gpu", "api=gles,color=srgb" },
63 { "glessrgbnl", "gpu", "api=gles,color=srgbnl" },
Brian Salomon002c1202016-10-18 11:28:20 -040064 { "glsrgb", "gpu", "api=gl,color=srgb" },
65 { "glwide", "gpu", "api=gl,color=f16_wide" },
66 { "glnarrow", "gpu", "api=gl,color=f16_narrow" },
Eric Karl5c779752017-05-08 12:02:07 -070067 { "glnostencils", "gpu", "api=gl,stencils=false" },
Brian Salomon50f66d82017-03-17 14:32:05 -040068 { "glessrgb", "gpu", "api=gles,color=srgb" },
69 { "gleswide", "gpu", "api=gles,color=f16_wide" },
70 { "glesnarrow", "gpu", "api=gles,color=f16_narrow" },
Brian Salomon50f66d82017-03-17 14:32:05 -040071 { "gldft", "gpu", "api=gl,dit=true" },
72 { "glesdft", "gpu", "api=gles,dit=true" },
Brian Salomon6405e712017-03-20 08:54:16 -040073 { "debuggl", "gpu", "api=debuggl" },
74 { "nullgl", "gpu", "api=nullgl" },
Brian Salomon002c1202016-10-18 11:28:20 -040075 { "angle_d3d11_es2", "gpu", "api=angle_d3d11_es2" },
Brian Osman21d742d2017-01-10 13:31:33 -050076 { "angle_d3d11_es3", "gpu", "api=angle_d3d11_es3" },
Brian Salomon002c1202016-10-18 11:28:20 -040077 { "angle_d3d9_es2", "gpu", "api=angle_d3d9_es2" },
78 { "angle_d3d11_es2_msaa4", "gpu", "api=angle_d3d11_es2,samples=4" },
Brian Salomon528ca9b2017-03-24 11:15:09 -040079 { "angle_d3d11_es2_msaa8", "gpu", "api=angle_d3d11_es2,samples=8" },
Brian Salomon8c865882017-06-22 09:56:24 -040080 { "angle_d3d11_es3_msaa4", "gpu", "api=angle_d3d11_es3,samples=4" },
81 { "angle_d3d11_es3_msaa8", "gpu", "api=angle_d3d11_es3,samples=8" },
Brian Salomon002c1202016-10-18 11:28:20 -040082 { "angle_gl_es2", "gpu", "api=angle_gl_es2" },
Brian Osman21d742d2017-01-10 13:31:33 -050083 { "angle_gl_es3", "gpu", "api=angle_gl_es3" },
Brian Salomon002c1202016-10-18 11:28:20 -040084 { "commandbuffer", "gpu", "api=commandbuffer" }
kkinnunen3e980c32015-12-23 01:33:00 -080085#if SK_MESA
Brian Salomon002c1202016-10-18 11:28:20 -040086 ,{ "mesa", "gpu", "api=mesa" }
kkinnunen3e980c32015-12-23 01:33:00 -080087#endif
brianosman37e23342016-09-20 08:06:30 -070088#ifdef SK_VULKAN
Brian Salomon002c1202016-10-18 11:28:20 -040089 ,{ "vk", "gpu", "api=vulkan" }
90 ,{ "vksrgb", "gpu", "api=vulkan,color=srgb" }
91 ,{ "vkwide", "gpu", "api=vulkan,color=f16_wide" }
92 ,{ "vkmsaa4", "gpu", "api=vulkan,samples=4" }
Brian Salomondcf0ab02017-03-20 11:10:21 -040093 ,{ "vkmsaa8", "gpu", "api=vulkan,samples=8" }
brianosman37e23342016-09-20 08:06:30 -070094#endif
95
96#else
97{ "", "", "" }
98#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"
123 "\t\tnative\t\t\tUse platform default OpenGL or OpenGL ES backend.\n"
124 "\t\tgl \t\t\tUse OpenGL.\n"
125 "\t\tgles \t\t\tUse OpenGL ES.\n"
Brian Salomon6405e712017-03-20 08:54:16 -0400126 "\t\tdebuggl \t\t\tUse debug OpenGL.\n"
127 "\t\tnullgl \t\t\tUse null OpenGL.\n"
bsalomon11abd8d2016-10-14 08:13:48 -0700128 "\t\tangle_d3d9_es2\t\t\tUse OpenGL ES2 on the ANGLE Direct3D9 backend.\n"
129 "\t\tangle_d3d11_es2\t\t\tUse OpenGL ES2 on the ANGLE Direct3D11 backend.\n"
130 "\t\tangle_d3d11_es3\t\t\tUse OpenGL ES3 on the ANGLE Direct3D11 backend.\n"
131 "\t\tangle_gl_es2\t\t\tUse OpenGL ES2 on the ANGLE OpenGL backend.\n"
132 "\t\tangle_gl_es3\t\t\tUse OpenGL ES3 on the ANGLE OpenGL backend.\n"
kkinnunen3e980c32015-12-23 01:33:00 -0800133 "\t\tcommandbuffer\t\tUse command buffer.\n"
kkinnunen3e980c32015-12-23 01:33:00 -0800134#if SK_MESA
135 "\t\tmesa\t\t\tUse MESA.\n"
136#endif
bsalomondc0fcd42016-04-11 14:21:33 -0700137#ifdef SK_VULKAN
138 "\t\tvulkan\t\t\tUse Vulkan.\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"
brianosman4562f6e2016-09-19 14:42:04 -0700144 "\t\tf16{_gamut}\t\tLinear 16-bit floating point.\n"
145 "\t\tsrgb{_gamut}\t\tsRGB 8888.\n"
146 "\t gamut\ttype: string\tdefault: srgb.\n"
147 "\t Select color gamut for f16 or sRGB format buffers.\n"
148 "\t Options:\n"
149 "\t\tsrgb\t\t\tsRGB gamut.\n"
150 "\t\twide\t\t\tWide Gamut RGB.\n"
kkinnunen3e980c32015-12-23 01:33:00 -0800151 "\tdit\ttype: bool\tdefault: false.\n"
152 "\t Use device independent text.\n"
153 "\tnvpr\ttype: bool\tdefault: false.\n"
154 "\t Use NV_path_rendering OpenGL and OpenGL ES extension.\n"
155 "\tsamples\ttype: int\tdefault: 0.\n"
156 "\t Use multisampling with N samples.\n"
Eric Karl5c779752017-05-08 12:02:07 -0700157 "\tstencils\ttype: bool\tdefault: true.\n"
158 "\t Allow the use of stencil buffers.\n"
kkinnunen3e980c32015-12-23 01:33:00 -0800159 "\n"
160 "Predefined configs:\n\n"
brianosman37e23342016-09-20 08:06:30 -0700161 // Help text for pre-defined configs is auto-generated from gPredefinedConfigs
kkinnunen3e980c32015-12-23 01:33:00 -0800162#endif
163 ;
164
brianosman37e23342016-09-20 08:06:30 -0700165static const char* config_extended_help_fn() {
166 static SkString helpString;
167 helpString.set(configExtendedHelp);
168 for (const auto& config : gPredefinedConfigs) {
169 helpString.appendf("\t%-10s\t= gpu(%s)\n", config.predefinedConfig, config.options);
170 }
171 return helpString.c_str();
172}
kkinnunen3e980c32015-12-23 01:33:00 -0800173
brianosman37e23342016-09-20 08:06:30 -0700174DEFINE_extended_string(config, defaultConfigs, config_help_fn(), config_extended_help_fn());
kkinnunen3e980c32015-12-23 01:33:00 -0800175
176SkCommandLineConfig::SkCommandLineConfig(const SkString& tag, const SkString& backend,
177 const SkTArray<SkString>& viaParts)
178 : fTag(tag)
179 , fBackend(backend)
180 , fViaParts(viaParts) {
181}
182SkCommandLineConfig::~SkCommandLineConfig() {
183}
184
185#if SK_SUPPORT_GPU
186SkCommandLineConfigGpu::SkCommandLineConfigGpu(
csmartdaltone0d36292016-07-29 08:14:20 -0700187 const SkString& tag, const SkTArray<SkString>& viaParts, ContextType contextType, bool useNVPR,
188 bool useInstanced, bool useDIText, int samples, SkColorType colorType,
Eric Karl5c779752017-05-08 12:02:07 -0700189 sk_sp<SkColorSpace> colorSpace, bool useStencilBuffers)
kkinnunen3e980c32015-12-23 01:33:00 -0800190 : SkCommandLineConfig(tag, SkString("gpu"), viaParts)
191 , fContextType(contextType)
csmartdaltone812d492017-02-21 12:36:05 -0700192 , fContextOverrides(ContextOverrides::kNone)
kkinnunen3e980c32015-12-23 01:33:00 -0800193 , fUseDIText(useDIText)
brianosmand93c1202016-03-10 07:49:08 -0800194 , fSamples(samples)
195 , fColorType(colorType)
brianosmanb109b8c2016-06-16 13:03:24 -0700196 , fColorSpace(std::move(colorSpace)) {
csmartdalton6270e552016-09-13 10:41:49 -0700197 if (useNVPR) {
csmartdaltone812d492017-02-21 12:36:05 -0700198 fContextOverrides |= ContextOverrides::kRequireNVPRSupport;
199 } else if (!useInstanced) {
200 // We don't disable NVPR for instanced configs. Otherwise the caps wouldn't use mixed
201 // samples and we couldn't test the mixed samples backend for simple shapes.
202 fContextOverrides |= ContextOverrides::kDisableNVPR;
csmartdalton6270e552016-09-13 10:41:49 -0700203 }
204 if (useInstanced) {
csmartdaltone812d492017-02-21 12:36:05 -0700205 fContextOverrides |= ContextOverrides::kUseInstanced;
csmartdalton6270e552016-09-13 10:41:49 -0700206 }
brianosman20471892016-12-02 06:43:32 -0800207 // Subtle logic: If the config has a color space attached, we're going to be rendering to sRGB,
208 // so we need that capability. In addition, to get the widest test coverage, we DO NOT require
209 // that we can disable sRGB decode. (That's for rendering sRGB sources to legacy surfaces).
210 //
211 // If the config doesn't have a color space attached, we're going to be rendering in legacy
csmartdaltone812d492017-02-21 12:36:05 -0700212 // mode. In that case, we don't require sRGB capability and we defer to the client to decide on
213 // sRGB decode control.
Brian Osman7039f742016-11-01 15:56:16 -0400214 if (fColorSpace) {
csmartdaltone812d492017-02-21 12:36:05 -0700215 fContextOverrides |= ContextOverrides::kRequireSRGBSupport;
216 fContextOverrides |= ContextOverrides::kAllowSRGBWithoutDecodeControl;
csmartdalton6270e552016-09-13 10:41:49 -0700217 }
Eric Karl5c779752017-05-08 12:02:07 -0700218 if (!useStencilBuffers) {
219 fContextOverrides |= ContextOverrides::kAvoidStencilBuffers;
220 }
kkinnunen3e980c32015-12-23 01:33:00 -0800221}
222static bool parse_option_int(const SkString& value, int* outInt) {
223 if (value.isEmpty()) {
224 return false;
225 }
226 char* endptr = nullptr;
227 long intValue = strtol(value.c_str(), &endptr, 10);
228 if (*endptr != '\0') {
229 return false;
230 }
231 *outInt = static_cast<int>(intValue);
232 return true;
233}
234static bool parse_option_bool(const SkString& value, bool* outBool) {
235 if (value.equals("true")) {
236 *outBool = true;
237 return true;
238 }
239 if (value.equals("false")) {
240 *outBool = false;
241 return true;
242 }
243 return false;
244}
245static bool parse_option_gpu_api(const SkString& value,
246 SkCommandLineConfigGpu::ContextType* outContextType) {
kkinnunen3e980c32015-12-23 01:33:00 -0800247 if (value.equals("gl")) {
bsalomon85b4b532016-04-05 11:06:27 -0700248 *outContextType = GrContextFactory::kGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800249 return true;
250 }
251 if (value.equals("gles")) {
bsalomon85b4b532016-04-05 11:06:27 -0700252 *outContextType = GrContextFactory::kGLES_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800253 return true;
254 }
Brian Salomon6405e712017-03-20 08:54:16 -0400255 if (value.equals("debuggl")) {
bsalomon85b4b532016-04-05 11:06:27 -0700256 *outContextType = GrContextFactory::kDebugGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800257 return true;
258 }
Brian Salomon6405e712017-03-20 08:54:16 -0400259 if (value.equals("nullgl")) {
bsalomon85b4b532016-04-05 11:06:27 -0700260 *outContextType = GrContextFactory::kNullGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800261 return true;
262 }
bsalomon11abd8d2016-10-14 08:13:48 -0700263 if (value.equals("angle_d3d9_es2")) {
264 *outContextType = GrContextFactory::kANGLE_D3D9_ES2_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800265 return true;
266 }
bsalomon11abd8d2016-10-14 08:13:48 -0700267 if (value.equals("angle_d3d11_es2")) {
268 *outContextType = GrContextFactory::kANGLE_D3D11_ES2_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800269 return true;
270 }
bsalomon11abd8d2016-10-14 08:13:48 -0700271 if (value.equals("angle_d3d11_es3")) {
272 *outContextType = GrContextFactory::kANGLE_D3D11_ES3_ContextType;
273 return true;
274 }
275 if (value.equals("angle_gl_es2")) {
276 *outContextType = GrContextFactory::kANGLE_GL_ES2_ContextType;
277 return true;
278 }
279 if (value.equals("angle_gl_es3")) {
280 *outContextType = GrContextFactory::kANGLE_GL_ES3_ContextType;
281 return true;
282 }
kkinnunen3e980c32015-12-23 01:33:00 -0800283 if (value.equals("commandbuffer")) {
bsalomon85b4b532016-04-05 11:06:27 -0700284 *outContextType = GrContextFactory::kCommandBuffer_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800285 return true;
286 }
kkinnunen3e980c32015-12-23 01:33:00 -0800287#if SK_MESA
288 if (value.equals("mesa")) {
bsalomon85b4b532016-04-05 11:06:27 -0700289 *outContextType = GrContextFactory::kMESA_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800290 return true;
291 }
292#endif
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
kkinnunen3e980c32015-12-23 01:33:00 -0800299 return false;
300}
brianosmand93c1202016-03-10 07:49:08 -0800301static bool parse_option_gpu_color(const SkString& value,
302 SkColorType* outColorType,
brianosmanb109b8c2016-06-16 13:03:24 -0700303 sk_sp<SkColorSpace>* outColorSpace) {
brianosmand93c1202016-03-10 07:49:08 -0800304 if (value.equals("8888")) {
bsalomon33069252016-09-28 08:49:53 -0700305 *outColorType = kRGBA_8888_SkColorType;
brianosmanb109b8c2016-06-16 13:03:24 -0700306 *outColorSpace = nullptr;
brianosmand93c1202016-03-10 07:49:08 -0800307 return true;
308 }
brianosman4562f6e2016-09-19 14:42:04 -0700309
310 SkTArray<SkString> commands;
311 SkStrSplit(value.c_str(), "_", &commands);
312 if (commands.count() < 1 || commands.count() > 2) {
313 return false;
314 }
315
raftias94888332016-10-18 10:02:51 -0700316 const bool linearGamma = commands[0].equals("f16");
Matt Sarettd2228302017-03-02 08:53:46 -0500317 SkColorSpace::Gamut gamut = SkColorSpace::kSRGB_Gamut;
318 SkColorSpace::RenderTargetGamma gamma = linearGamma ? SkColorSpace::kLinear_RenderTargetGamma
319 : SkColorSpace::kSRGB_RenderTargetGamma;
Matt Sarettf3880932017-03-24 10:06:03 -0400320 *outColorSpace = SkColorSpace::MakeRGB(gamma, gamut);
Matt Sarettd2228302017-03-02 08:53:46 -0500321
brianosman4562f6e2016-09-19 14:42:04 -0700322 if (commands.count() == 2) {
323 if (commands[1].equals("srgb")) {
324 // sRGB gamut (which is our default)
325 } else if (commands[1].equals("wide")) {
326 // WideGamut RGB
327 const float gWideGamutRGB_toXYZD50[]{
328 0.7161046f, 0.1009296f, 0.1471858f, // -> X
329 0.2581874f, 0.7249378f, 0.0168748f, // -> Y
330 0.0000000f, 0.0517813f, 0.7734287f, // -> Z
331 };
332 SkMatrix44 wideGamutRGBMatrix(SkMatrix44::kUninitialized_Constructor);
333 wideGamutRGBMatrix.set3x3RowMajorf(gWideGamutRGB_toXYZD50);
Matt Sarettf3880932017-03-24 10:06:03 -0400334 *outColorSpace = SkColorSpace::MakeRGB(gamma, wideGamutRGBMatrix);
Brian Osman4a6b28e2016-10-17 11:14:02 -0400335 } else if (commands[1].equals("narrow")) {
336 // NarrowGamut RGB (an artifically smaller than sRGB gamut)
337 SkColorSpacePrimaries primaries ={
338 0.54f, 0.33f, // Rx, Ry
339 0.33f, 0.50f, // Gx, Gy
340 0.25f, 0.20f, // Bx, By
341 0.3127f, 0.3290f, // Wx, Wy
342 };
343 SkMatrix44 narrowGamutRGBMatrix(SkMatrix44::kUninitialized_Constructor);
344 primaries.toXYZD50(&narrowGamutRGBMatrix);
Matt Sarettf3880932017-03-24 10:06:03 -0400345 *outColorSpace = SkColorSpace::MakeRGB(gamma, narrowGamutRGBMatrix);
brianosman4562f6e2016-09-19 14:42:04 -0700346 } else {
347 // Unknown color gamut
348 return false;
349 }
350 }
351
352 // Now pick a color type
353 if (commands[0].equals("f16")) {
brianosmand93c1202016-03-10 07:49:08 -0800354 *outColorType = kRGBA_F16_SkColorType;
brianosmand93c1202016-03-10 07:49:08 -0800355 return true;
356 }
Matt Sarettd2228302017-03-02 08:53:46 -0500357 if (commands[0].equals("srgb") || commands[0].equals("srgbnl")) {
bsalomon33069252016-09-28 08:49:53 -0700358 *outColorType = kRGBA_8888_SkColorType;
brianosmand93c1202016-03-10 07:49:08 -0800359 return true;
360 }
361 return false;
362}
kkinnunen3e980c32015-12-23 01:33:00 -0800363
364SkCommandLineConfigGpu* parse_command_line_config_gpu(const SkString& tag,
365 const SkTArray<SkString>& vias,
366 const SkString& options) {
367 // Defaults for GPU backend.
368 bool seenAPI = false;
Brian Salomon6405e712017-03-20 08:54:16 -0400369 SkCommandLineConfigGpu::ContextType contextType = GrContextFactory::kGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800370 bool seenUseNVPR = false;
371 bool useNVPR = false;
csmartdaltone0d36292016-07-29 08:14:20 -0700372 bool seenUseInstanced = false;
373 bool useInstanced = false;
kkinnunen3e980c32015-12-23 01:33:00 -0800374 bool seenUseDIText =false;
375 bool useDIText = false;
376 bool seenSamples = false;
377 int samples = 0;
brianosmand93c1202016-03-10 07:49:08 -0800378 bool seenColor = false;
bsalomon33069252016-09-28 08:49:53 -0700379 SkColorType colorType = kRGBA_8888_SkColorType;
brianosmanb109b8c2016-06-16 13:03:24 -0700380 sk_sp<SkColorSpace> colorSpace = nullptr;
Eric Karl5c779752017-05-08 12:02:07 -0700381 bool seenUseStencils = false;
382 bool useStencils = true;
kkinnunen3e980c32015-12-23 01:33:00 -0800383
384 SkTArray<SkString> optionParts;
385 SkStrSplit(options.c_str(), ",", kStrict_SkStrSplitMode, &optionParts);
386 for (int i = 0; i < optionParts.count(); ++i) {
387 SkTArray<SkString> keyValueParts;
388 SkStrSplit(optionParts[i].c_str(), "=", kStrict_SkStrSplitMode, &keyValueParts);
389 if (keyValueParts.count() != 2) {
390 return nullptr;
391 }
392 const SkString& key = keyValueParts[0];
393 const SkString& value = keyValueParts[1];
394 bool valueOk = false;
395 if (key.equals("api") && !seenAPI) {
396 valueOk = parse_option_gpu_api(value, &contextType);
397 seenAPI = true;
398 } else if (key.equals("nvpr") && !seenUseNVPR) {
399 valueOk = parse_option_bool(value, &useNVPR);
400 seenUseNVPR = true;
csmartdaltone0d36292016-07-29 08:14:20 -0700401 } else if (key.equals("inst") && !seenUseInstanced) {
402 valueOk = parse_option_bool(value, &useInstanced);
403 seenUseInstanced = true;
kkinnunen3e980c32015-12-23 01:33:00 -0800404 } else if (key.equals("dit") && !seenUseDIText) {
405 valueOk = parse_option_bool(value, &useDIText);
406 seenUseDIText = true;
407 } else if (key.equals("samples") && !seenSamples) {
408 valueOk = parse_option_int(value, &samples);
409 seenSamples = true;
brianosmand93c1202016-03-10 07:49:08 -0800410 } else if (key.equals("color") && !seenColor) {
brianosmanb109b8c2016-06-16 13:03:24 -0700411 valueOk = parse_option_gpu_color(value, &colorType, &colorSpace);
brianosmand93c1202016-03-10 07:49:08 -0800412 seenColor = true;
Eric Karl5c779752017-05-08 12:02:07 -0700413 } else if (key.equals("stencils") && !seenUseStencils) {
414 valueOk = parse_option_bool(value, &useStencils);
415 seenUseStencils = true;
kkinnunen3e980c32015-12-23 01:33:00 -0800416 }
417 if (!valueOk) {
418 return nullptr;
419 }
420 }
Brian Salomon6405e712017-03-20 08:54:16 -0400421 if (!seenAPI) {
422 return nullptr;
423 }
csmartdaltone0d36292016-07-29 08:14:20 -0700424 return new SkCommandLineConfigGpu(tag, vias, contextType, useNVPR, useInstanced, useDIText,
Eric Karl5c779752017-05-08 12:02:07 -0700425 samples, colorType, colorSpace, useStencils);
kkinnunen3e980c32015-12-23 01:33:00 -0800426}
427#endif
428
429void ParseConfigs(const SkCommandLineFlags::StringArray& configs,
430 SkCommandLineConfigArray* outResult) {
431 outResult->reset();
432 for (int i = 0; i < configs.count(); ++i) {
433 SkString extendedBackend;
434 SkString extendedOptions;
435 SkString simpleBackend;
436 SkTArray<SkString> vias;
437
438 SkString tag(configs[i]);
439 SkTArray<SkString> parts;
bsalomon808ecbb2016-09-28 12:40:22 -0700440 SkStrSplit(tag.c_str(), "[", kStrict_SkStrSplitMode, &parts);
kkinnunen3e980c32015-12-23 01:33:00 -0800441 if (parts.count() == 2) {
442 SkTArray<SkString> parts2;
bsalomon808ecbb2016-09-28 12:40:22 -0700443 SkStrSplit(parts[1].c_str(), "]", kStrict_SkStrSplitMode, &parts2);
kkinnunen3e980c32015-12-23 01:33:00 -0800444 if (parts2.count() == 2 && parts2[1].isEmpty()) {
445 SkStrSplit(parts[0].c_str(), "-", kStrict_SkStrSplitMode, &vias);
446 if (vias.count()) {
447 extendedBackend = vias[vias.count() - 1];
448 vias.pop_back();
449 } else {
450 extendedBackend = parts[0];
451 }
452 extendedOptions = parts2[0];
bsalomon808ecbb2016-09-28 12:40:22 -0700453 simpleBackend.printf("%s[%s]", extendedBackend.c_str(), extendedOptions.c_str());
kkinnunen3e980c32015-12-23 01:33:00 -0800454 }
455 }
456
457 if (extendedBackend.isEmpty()) {
458 simpleBackend = tag;
459 SkStrSplit(tag.c_str(), "-", kStrict_SkStrSplitMode, &vias);
460 if (vias.count()) {
461 simpleBackend = vias[vias.count() - 1];
462 vias.pop_back();
463 }
kkinnunen3e980c32015-12-23 01:33:00 -0800464 for (auto& predefinedConfig : gPredefinedConfigs) {
465 if (simpleBackend.equals(predefinedConfig.predefinedConfig)) {
466 extendedBackend = predefinedConfig.backend;
467 extendedOptions = predefinedConfig.options;
468 break;
469 }
470 }
471 }
472 SkCommandLineConfig* parsedConfig = nullptr;
473#if SK_SUPPORT_GPU
474 if (extendedBackend.equals("gpu")) {
475 parsedConfig = parse_command_line_config_gpu(tag, vias, extendedOptions);
476 }
477#endif
478 if (!parsedConfig) {
479 parsedConfig = new SkCommandLineConfig(tag, simpleBackend, vias);
480 }
481 outResult->emplace_back(parsedConfig);
482 }
483}