blob: c9ac767bdd8f369a3be1cbb5c7553851ee138d58 [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
kkinnunen3e980c32015-12-23 01:33:00 -080018static const char defaultConfigs[] =
mtklein896ddb72016-09-14 10:33:12 -070019 "8888 gpu nonrendering"
bsalomon11abd8d2016-10-14 08:13:48 -070020#if defined(SK_BUILD_FOR_WIN)
21 " angle_d3d11_es2"
kkinnunen3e980c32015-12-23 01:33:00 -080022#endif
kkinnunen3e980c32015-12-23 01:33:00 -080023 ;
24
brianosman37e23342016-09-20 08:06:30 -070025static const struct {
26 const char* predefinedConfig;
27 const char* backend;
28 const char* options;
29} gPredefinedConfigs[] ={
30#if SK_SUPPORT_GPU
Brian Salomon002c1202016-10-18 11:28:20 -040031 { "gpu", "gpu", "" },
32 { "gl", "gpu", "api=gl" },
33 { "msaa4", "gpu", "samples=4" },
34 { "glmsaa4", "gpu", "api=gl,samples=4" },
35 { "msaa16", "gpu", "samples=16" },
36 { "nvpr4", "gpu", "nvpr=true,samples=4" },
37 { "glnvpr4", "gpu", "api=gl,nvpr=true,samples=4" },
38 { "nvpr16", "gpu", "nvpr=true,samples=16" },
39 { "nvprdit4", "gpu", "nvpr=true,samples=4,dit=true" },
40 { "glnvprdit4", "gpu", "api=gl,nvpr=true,samples=4,dit=true" },
41 { "nvprdit16", "gpu", "nvpr=true,samples=16,dit=true" },
42 { "glinst", "gpu", "api=gl,inst=true" },
43 { "glinst4", "gpu", "api=gl,inst=true,samples=4" },
44 { "glinstdit4", "gpu", "api=gl,inst=true,samples=4,dit=true" },
45 { "glinst16", "gpu", "api=gl,inst=true,samples=16" },
46 { "glinstdit16", "gpu", "api=gl,inst=true,samples=16,dit=true" },
47 { "esinst", "gpu", "api=gles,inst=true" },
48 { "esinst4", "gpu", "api=gles,inst=true,samples=4" },
49 { "esinstdit4", "gpu", "api=gles,inst=true,samples=4,dit=true" },
50 { "gpuf16", "gpu", "color=f16" },
51 { "gpusrgb", "gpu", "color=srgb" },
Matt Sarettd2228302017-03-02 08:53:46 -050052 { "gpusrgbnl", "gpu", "color=srgbnl" },
Brian Salomon002c1202016-10-18 11:28:20 -040053 { "glsrgb", "gpu", "api=gl,color=srgb" },
54 { "glwide", "gpu", "api=gl,color=f16_wide" },
55 { "glnarrow", "gpu", "api=gl,color=f16_narrow" },
56 { "gpudft", "gpu", "dit=true" },
57 { "gpudebug", "gpu", "api=debug" },
58 { "gpunull", "gpu", "api=null" },
59 { "debug", "gpu", "api=debug" },
60 { "nullgpu", "gpu", "api=null" },
61 { "angle_d3d11_es2", "gpu", "api=angle_d3d11_es2" },
Brian Osman21d742d2017-01-10 13:31:33 -050062 { "angle_d3d11_es3", "gpu", "api=angle_d3d11_es3" },
Brian Salomon002c1202016-10-18 11:28:20 -040063 { "angle_d3d9_es2", "gpu", "api=angle_d3d9_es2" },
64 { "angle_d3d11_es2_msaa4", "gpu", "api=angle_d3d11_es2,samples=4" },
65 { "angle_gl_es2", "gpu", "api=angle_gl_es2" },
Brian Osman21d742d2017-01-10 13:31:33 -050066 { "angle_gl_es3", "gpu", "api=angle_gl_es3" },
Brian Salomon002c1202016-10-18 11:28:20 -040067 { "commandbuffer", "gpu", "api=commandbuffer" }
kkinnunen3e980c32015-12-23 01:33:00 -080068#if SK_MESA
Brian Salomon002c1202016-10-18 11:28:20 -040069 ,{ "mesa", "gpu", "api=mesa" }
kkinnunen3e980c32015-12-23 01:33:00 -080070#endif
brianosman37e23342016-09-20 08:06:30 -070071#ifdef SK_VULKAN
Brian Salomon002c1202016-10-18 11:28:20 -040072 ,{ "vk", "gpu", "api=vulkan" }
73 ,{ "vksrgb", "gpu", "api=vulkan,color=srgb" }
74 ,{ "vkwide", "gpu", "api=vulkan,color=f16_wide" }
75 ,{ "vkmsaa4", "gpu", "api=vulkan,samples=4" }
76 ,{ "vkmsaa16", "gpu", "api=vulkan,samples=16" }
brianosman37e23342016-09-20 08:06:30 -070077#endif
78
79#else
80{ "", "", "" }
81#endif
82};
83
84static const char configHelp[] =
Derek Sollenbergerc65386a2017-01-05 09:50:22 -050085 "Options: 565 8888 srgb f16 nonrendering null pdf pdfa skp pipe svg xps";
brianosman37e23342016-09-20 08:06:30 -070086
87static const char* config_help_fn() {
88 static SkString helpString;
89 helpString.set(configHelp);
90 for (const auto& config : gPredefinedConfigs) {
91 helpString.appendf(" %s", config.predefinedConfig);
92 }
bsalomon808ecbb2016-09-28 12:40:22 -070093 helpString.append(" or use extended form 'backend[option=value,...]'.\n");
brianosman37e23342016-09-20 08:06:30 -070094 return helpString.c_str();
95}
kkinnunen3e980c32015-12-23 01:33:00 -080096
97static const char configExtendedHelp[] =
98 "Extended form: 'backend(option=value,...)'\n\n"
99 "Possible backends and options:\n"
100#if SK_SUPPORT_GPU
101 "\n"
bsalomon808ecbb2016-09-28 12:40:22 -0700102 "gpu[api=string,color=string,dit=bool,nvpr=bool,inst=bool,samples=int]\n"
kkinnunen3e980c32015-12-23 01:33:00 -0800103 "\tapi\ttype: string\tdefault: native.\n"
104 "\t Select graphics API to use with gpu backend.\n"
105 "\t Options:\n"
106 "\t\tnative\t\t\tUse platform default OpenGL or OpenGL ES backend.\n"
107 "\t\tgl \t\t\tUse OpenGL.\n"
108 "\t\tgles \t\t\tUse OpenGL ES.\n"
109 "\t\tdebug \t\t\tUse debug OpenGL.\n"
110 "\t\tnull \t\t\tUse null OpenGL.\n"
bsalomon11abd8d2016-10-14 08:13:48 -0700111 "\t\tangle_d3d9_es2\t\t\tUse OpenGL ES2 on the ANGLE Direct3D9 backend.\n"
112 "\t\tangle_d3d11_es2\t\t\tUse OpenGL ES2 on the ANGLE Direct3D11 backend.\n"
113 "\t\tangle_d3d11_es3\t\t\tUse OpenGL ES3 on the ANGLE Direct3D11 backend.\n"
114 "\t\tangle_gl_es2\t\t\tUse OpenGL ES2 on the ANGLE OpenGL backend.\n"
115 "\t\tangle_gl_es3\t\t\tUse OpenGL ES3 on the ANGLE OpenGL backend.\n"
kkinnunen3e980c32015-12-23 01:33:00 -0800116 "\t\tcommandbuffer\t\tUse command buffer.\n"
kkinnunen3e980c32015-12-23 01:33:00 -0800117#if SK_MESA
118 "\t\tmesa\t\t\tUse MESA.\n"
119#endif
bsalomondc0fcd42016-04-11 14:21:33 -0700120#ifdef SK_VULKAN
121 "\t\tvulkan\t\t\tUse Vulkan.\n"
122#endif
brianosmand93c1202016-03-10 07:49:08 -0800123 "\tcolor\ttype: string\tdefault: 8888.\n"
124 "\t Select framebuffer color format.\n"
125 "\t Options:\n"
126 "\t\t8888\t\t\tLinear 8888.\n"
brianosman4562f6e2016-09-19 14:42:04 -0700127 "\t\tf16{_gamut}\t\tLinear 16-bit floating point.\n"
128 "\t\tsrgb{_gamut}\t\tsRGB 8888.\n"
129 "\t gamut\ttype: string\tdefault: srgb.\n"
130 "\t Select color gamut for f16 or sRGB format buffers.\n"
131 "\t Options:\n"
132 "\t\tsrgb\t\t\tsRGB gamut.\n"
133 "\t\twide\t\t\tWide Gamut RGB.\n"
kkinnunen3e980c32015-12-23 01:33:00 -0800134 "\tdit\ttype: bool\tdefault: false.\n"
135 "\t Use device independent text.\n"
136 "\tnvpr\ttype: bool\tdefault: false.\n"
137 "\t Use NV_path_rendering OpenGL and OpenGL ES extension.\n"
138 "\tsamples\ttype: int\tdefault: 0.\n"
139 "\t Use multisampling with N samples.\n"
140 "\n"
141 "Predefined configs:\n\n"
brianosman37e23342016-09-20 08:06:30 -0700142 // Help text for pre-defined configs is auto-generated from gPredefinedConfigs
kkinnunen3e980c32015-12-23 01:33:00 -0800143#endif
144 ;
145
brianosman37e23342016-09-20 08:06:30 -0700146static const char* config_extended_help_fn() {
147 static SkString helpString;
148 helpString.set(configExtendedHelp);
149 for (const auto& config : gPredefinedConfigs) {
150 helpString.appendf("\t%-10s\t= gpu(%s)\n", config.predefinedConfig, config.options);
151 }
152 return helpString.c_str();
153}
kkinnunen3e980c32015-12-23 01:33:00 -0800154
brianosman37e23342016-09-20 08:06:30 -0700155DEFINE_extended_string(config, defaultConfigs, config_help_fn(), config_extended_help_fn());
kkinnunen3e980c32015-12-23 01:33:00 -0800156
157SkCommandLineConfig::SkCommandLineConfig(const SkString& tag, const SkString& backend,
158 const SkTArray<SkString>& viaParts)
159 : fTag(tag)
160 , fBackend(backend)
161 , fViaParts(viaParts) {
162}
163SkCommandLineConfig::~SkCommandLineConfig() {
164}
165
166#if SK_SUPPORT_GPU
167SkCommandLineConfigGpu::SkCommandLineConfigGpu(
csmartdaltone0d36292016-07-29 08:14:20 -0700168 const SkString& tag, const SkTArray<SkString>& viaParts, ContextType contextType, bool useNVPR,
169 bool useInstanced, bool useDIText, int samples, SkColorType colorType,
170 sk_sp<SkColorSpace> colorSpace)
kkinnunen3e980c32015-12-23 01:33:00 -0800171 : SkCommandLineConfig(tag, SkString("gpu"), viaParts)
172 , fContextType(contextType)
csmartdaltone812d492017-02-21 12:36:05 -0700173 , fContextOverrides(ContextOverrides::kNone)
kkinnunen3e980c32015-12-23 01:33:00 -0800174 , fUseDIText(useDIText)
brianosmand93c1202016-03-10 07:49:08 -0800175 , fSamples(samples)
176 , fColorType(colorType)
brianosmanb109b8c2016-06-16 13:03:24 -0700177 , fColorSpace(std::move(colorSpace)) {
csmartdalton6270e552016-09-13 10:41:49 -0700178 if (useNVPR) {
csmartdaltone812d492017-02-21 12:36:05 -0700179 fContextOverrides |= ContextOverrides::kRequireNVPRSupport;
180 } else if (!useInstanced) {
181 // We don't disable NVPR for instanced configs. Otherwise the caps wouldn't use mixed
182 // samples and we couldn't test the mixed samples backend for simple shapes.
183 fContextOverrides |= ContextOverrides::kDisableNVPR;
csmartdalton6270e552016-09-13 10:41:49 -0700184 }
185 if (useInstanced) {
csmartdaltone812d492017-02-21 12:36:05 -0700186 fContextOverrides |= ContextOverrides::kUseInstanced;
csmartdalton6270e552016-09-13 10:41:49 -0700187 }
brianosman20471892016-12-02 06:43:32 -0800188 // Subtle logic: If the config has a color space attached, we're going to be rendering to sRGB,
189 // so we need that capability. In addition, to get the widest test coverage, we DO NOT require
190 // that we can disable sRGB decode. (That's for rendering sRGB sources to legacy surfaces).
191 //
192 // If the config doesn't have a color space attached, we're going to be rendering in legacy
csmartdaltone812d492017-02-21 12:36:05 -0700193 // mode. In that case, we don't require sRGB capability and we defer to the client to decide on
194 // sRGB decode control.
Brian Osman7039f742016-11-01 15:56:16 -0400195 if (fColorSpace) {
csmartdaltone812d492017-02-21 12:36:05 -0700196 fContextOverrides |= ContextOverrides::kRequireSRGBSupport;
197 fContextOverrides |= ContextOverrides::kAllowSRGBWithoutDecodeControl;
csmartdalton6270e552016-09-13 10:41:49 -0700198 }
kkinnunen3e980c32015-12-23 01:33:00 -0800199}
200static bool parse_option_int(const SkString& value, int* outInt) {
201 if (value.isEmpty()) {
202 return false;
203 }
204 char* endptr = nullptr;
205 long intValue = strtol(value.c_str(), &endptr, 10);
206 if (*endptr != '\0') {
207 return false;
208 }
209 *outInt = static_cast<int>(intValue);
210 return true;
211}
212static bool parse_option_bool(const SkString& value, bool* outBool) {
213 if (value.equals("true")) {
214 *outBool = true;
215 return true;
216 }
217 if (value.equals("false")) {
218 *outBool = false;
219 return true;
220 }
221 return false;
222}
223static bool parse_option_gpu_api(const SkString& value,
224 SkCommandLineConfigGpu::ContextType* outContextType) {
kkinnunen3e980c32015-12-23 01:33:00 -0800225 if (value.equals("gl")) {
bsalomon85b4b532016-04-05 11:06:27 -0700226 *outContextType = GrContextFactory::kGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800227 return true;
228 }
229 if (value.equals("gles")) {
bsalomon85b4b532016-04-05 11:06:27 -0700230 *outContextType = GrContextFactory::kGLES_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800231 return true;
232 }
233 if (value.equals("debug")) {
bsalomon85b4b532016-04-05 11:06:27 -0700234 *outContextType = GrContextFactory::kDebugGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800235 return true;
236 }
237 if (value.equals("null")) {
bsalomon85b4b532016-04-05 11:06:27 -0700238 *outContextType = GrContextFactory::kNullGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800239 return true;
240 }
bsalomon11abd8d2016-10-14 08:13:48 -0700241 if (value.equals("angle_d3d9_es2")) {
242 *outContextType = GrContextFactory::kANGLE_D3D9_ES2_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800243 return true;
244 }
bsalomon11abd8d2016-10-14 08:13:48 -0700245 if (value.equals("angle_d3d11_es2")) {
246 *outContextType = GrContextFactory::kANGLE_D3D11_ES2_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800247 return true;
248 }
bsalomon11abd8d2016-10-14 08:13:48 -0700249 if (value.equals("angle_d3d11_es3")) {
250 *outContextType = GrContextFactory::kANGLE_D3D11_ES3_ContextType;
251 return true;
252 }
253 if (value.equals("angle_gl_es2")) {
254 *outContextType = GrContextFactory::kANGLE_GL_ES2_ContextType;
255 return true;
256 }
257 if (value.equals("angle_gl_es3")) {
258 *outContextType = GrContextFactory::kANGLE_GL_ES3_ContextType;
259 return true;
260 }
kkinnunen3e980c32015-12-23 01:33:00 -0800261 if (value.equals("commandbuffer")) {
bsalomon85b4b532016-04-05 11:06:27 -0700262 *outContextType = GrContextFactory::kCommandBuffer_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800263 return true;
264 }
kkinnunen3e980c32015-12-23 01:33:00 -0800265#if SK_MESA
266 if (value.equals("mesa")) {
bsalomon85b4b532016-04-05 11:06:27 -0700267 *outContextType = GrContextFactory::kMESA_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800268 return true;
269 }
270#endif
bsalomondc0fcd42016-04-11 14:21:33 -0700271#ifdef SK_VULKAN
272 if (value.equals("vulkan")) {
273 *outContextType = GrContextFactory::kVulkan_ContextType;
274 return true;
275 }
276#endif
kkinnunen3e980c32015-12-23 01:33:00 -0800277 return false;
278}
brianosmand93c1202016-03-10 07:49:08 -0800279static bool parse_option_gpu_color(const SkString& value,
280 SkColorType* outColorType,
brianosmanb109b8c2016-06-16 13:03:24 -0700281 sk_sp<SkColorSpace>* outColorSpace) {
brianosmand93c1202016-03-10 07:49:08 -0800282 if (value.equals("8888")) {
bsalomon33069252016-09-28 08:49:53 -0700283 *outColorType = kRGBA_8888_SkColorType;
brianosmanb109b8c2016-06-16 13:03:24 -0700284 *outColorSpace = nullptr;
brianosmand93c1202016-03-10 07:49:08 -0800285 return true;
286 }
brianosman4562f6e2016-09-19 14:42:04 -0700287
288 SkTArray<SkString> commands;
289 SkStrSplit(value.c_str(), "_", &commands);
290 if (commands.count() < 1 || commands.count() > 2) {
291 return false;
292 }
293
raftias94888332016-10-18 10:02:51 -0700294 const bool linearGamma = commands[0].equals("f16");
Matt Sarettd2228302017-03-02 08:53:46 -0500295 const bool nonLinearBlending = commands[0].equals("srgbnl");
296 SkColorSpace::Gamut gamut = SkColorSpace::kSRGB_Gamut;
297 SkColorSpace::RenderTargetGamma gamma = linearGamma ? SkColorSpace::kLinear_RenderTargetGamma
298 : SkColorSpace::kSRGB_RenderTargetGamma;
299 SkColorSpace::ColorSpaceFlags flags =
300 nonLinearBlending ? SkColorSpace::kNonLinearBlending_ColorSpaceFlag
301 : (SkColorSpace::ColorSpaceFlags) 0;
302 *outColorSpace = SkColorSpace::MakeRGB(gamma, gamut, flags);
303
brianosman4562f6e2016-09-19 14:42:04 -0700304 if (commands.count() == 2) {
305 if (commands[1].equals("srgb")) {
306 // sRGB gamut (which is our default)
307 } else if (commands[1].equals("wide")) {
308 // WideGamut RGB
309 const float gWideGamutRGB_toXYZD50[]{
310 0.7161046f, 0.1009296f, 0.1471858f, // -> X
311 0.2581874f, 0.7249378f, 0.0168748f, // -> Y
312 0.0000000f, 0.0517813f, 0.7734287f, // -> Z
313 };
314 SkMatrix44 wideGamutRGBMatrix(SkMatrix44::kUninitialized_Constructor);
315 wideGamutRGBMatrix.set3x3RowMajorf(gWideGamutRGB_toXYZD50);
Matt Sarettd2228302017-03-02 08:53:46 -0500316 *outColorSpace = SkColorSpace::MakeRGB(gamma, wideGamutRGBMatrix, flags);
Brian Osman4a6b28e2016-10-17 11:14:02 -0400317 } else if (commands[1].equals("narrow")) {
318 // NarrowGamut RGB (an artifically smaller than sRGB gamut)
319 SkColorSpacePrimaries primaries ={
320 0.54f, 0.33f, // Rx, Ry
321 0.33f, 0.50f, // Gx, Gy
322 0.25f, 0.20f, // Bx, By
323 0.3127f, 0.3290f, // Wx, Wy
324 };
325 SkMatrix44 narrowGamutRGBMatrix(SkMatrix44::kUninitialized_Constructor);
326 primaries.toXYZD50(&narrowGamutRGBMatrix);
Matt Sarettd2228302017-03-02 08:53:46 -0500327 *outColorSpace = SkColorSpace::MakeRGB(gamma, narrowGamutRGBMatrix, flags);
brianosman4562f6e2016-09-19 14:42:04 -0700328 } else {
329 // Unknown color gamut
330 return false;
331 }
332 }
333
334 // Now pick a color type
335 if (commands[0].equals("f16")) {
brianosmand93c1202016-03-10 07:49:08 -0800336 *outColorType = kRGBA_F16_SkColorType;
brianosmand93c1202016-03-10 07:49:08 -0800337 return true;
338 }
Matt Sarettd2228302017-03-02 08:53:46 -0500339 if (commands[0].equals("srgb") || commands[0].equals("srgbnl")) {
bsalomon33069252016-09-28 08:49:53 -0700340 *outColorType = kRGBA_8888_SkColorType;
brianosmand93c1202016-03-10 07:49:08 -0800341 return true;
342 }
343 return false;
344}
kkinnunen3e980c32015-12-23 01:33:00 -0800345
346SkCommandLineConfigGpu* parse_command_line_config_gpu(const SkString& tag,
347 const SkTArray<SkString>& vias,
348 const SkString& options) {
349 // Defaults for GPU backend.
350 bool seenAPI = false;
bsalomon85b4b532016-04-05 11:06:27 -0700351 SkCommandLineConfigGpu::ContextType contextType = GrContextFactory::kNativeGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800352 bool seenUseNVPR = false;
353 bool useNVPR = false;
csmartdaltone0d36292016-07-29 08:14:20 -0700354 bool seenUseInstanced = false;
355 bool useInstanced = false;
kkinnunen3e980c32015-12-23 01:33:00 -0800356 bool seenUseDIText =false;
357 bool useDIText = false;
358 bool seenSamples = false;
359 int samples = 0;
brianosmand93c1202016-03-10 07:49:08 -0800360 bool seenColor = false;
bsalomon33069252016-09-28 08:49:53 -0700361 SkColorType colorType = kRGBA_8888_SkColorType;
brianosmanb109b8c2016-06-16 13:03:24 -0700362 sk_sp<SkColorSpace> colorSpace = nullptr;
kkinnunen3e980c32015-12-23 01:33:00 -0800363
364 SkTArray<SkString> optionParts;
365 SkStrSplit(options.c_str(), ",", kStrict_SkStrSplitMode, &optionParts);
366 for (int i = 0; i < optionParts.count(); ++i) {
367 SkTArray<SkString> keyValueParts;
368 SkStrSplit(optionParts[i].c_str(), "=", kStrict_SkStrSplitMode, &keyValueParts);
369 if (keyValueParts.count() != 2) {
370 return nullptr;
371 }
372 const SkString& key = keyValueParts[0];
373 const SkString& value = keyValueParts[1];
374 bool valueOk = false;
375 if (key.equals("api") && !seenAPI) {
376 valueOk = parse_option_gpu_api(value, &contextType);
377 seenAPI = true;
378 } else if (key.equals("nvpr") && !seenUseNVPR) {
379 valueOk = parse_option_bool(value, &useNVPR);
380 seenUseNVPR = true;
csmartdaltone0d36292016-07-29 08:14:20 -0700381 } else if (key.equals("inst") && !seenUseInstanced) {
382 valueOk = parse_option_bool(value, &useInstanced);
383 seenUseInstanced = true;
kkinnunen3e980c32015-12-23 01:33:00 -0800384 } else if (key.equals("dit") && !seenUseDIText) {
385 valueOk = parse_option_bool(value, &useDIText);
386 seenUseDIText = true;
387 } else if (key.equals("samples") && !seenSamples) {
388 valueOk = parse_option_int(value, &samples);
389 seenSamples = true;
brianosmand93c1202016-03-10 07:49:08 -0800390 } else if (key.equals("color") && !seenColor) {
brianosmanb109b8c2016-06-16 13:03:24 -0700391 valueOk = parse_option_gpu_color(value, &colorType, &colorSpace);
brianosmand93c1202016-03-10 07:49:08 -0800392 seenColor = true;
kkinnunen3e980c32015-12-23 01:33:00 -0800393 }
394 if (!valueOk) {
395 return nullptr;
396 }
397 }
csmartdaltone0d36292016-07-29 08:14:20 -0700398 return new SkCommandLineConfigGpu(tag, vias, contextType, useNVPR, useInstanced, useDIText,
399 samples, colorType, colorSpace);
kkinnunen3e980c32015-12-23 01:33:00 -0800400}
401#endif
402
403void ParseConfigs(const SkCommandLineFlags::StringArray& configs,
404 SkCommandLineConfigArray* outResult) {
405 outResult->reset();
406 for (int i = 0; i < configs.count(); ++i) {
407 SkString extendedBackend;
408 SkString extendedOptions;
409 SkString simpleBackend;
410 SkTArray<SkString> vias;
411
412 SkString tag(configs[i]);
413 SkTArray<SkString> parts;
bsalomon808ecbb2016-09-28 12:40:22 -0700414 SkStrSplit(tag.c_str(), "[", kStrict_SkStrSplitMode, &parts);
kkinnunen3e980c32015-12-23 01:33:00 -0800415 if (parts.count() == 2) {
416 SkTArray<SkString> parts2;
bsalomon808ecbb2016-09-28 12:40:22 -0700417 SkStrSplit(parts[1].c_str(), "]", kStrict_SkStrSplitMode, &parts2);
kkinnunen3e980c32015-12-23 01:33:00 -0800418 if (parts2.count() == 2 && parts2[1].isEmpty()) {
419 SkStrSplit(parts[0].c_str(), "-", kStrict_SkStrSplitMode, &vias);
420 if (vias.count()) {
421 extendedBackend = vias[vias.count() - 1];
422 vias.pop_back();
423 } else {
424 extendedBackend = parts[0];
425 }
426 extendedOptions = parts2[0];
bsalomon808ecbb2016-09-28 12:40:22 -0700427 simpleBackend.printf("%s[%s]", extendedBackend.c_str(), extendedOptions.c_str());
kkinnunen3e980c32015-12-23 01:33:00 -0800428 }
429 }
430
431 if (extendedBackend.isEmpty()) {
432 simpleBackend = tag;
433 SkStrSplit(tag.c_str(), "-", kStrict_SkStrSplitMode, &vias);
434 if (vias.count()) {
435 simpleBackend = vias[vias.count() - 1];
436 vias.pop_back();
437 }
kkinnunen3e980c32015-12-23 01:33:00 -0800438 for (auto& predefinedConfig : gPredefinedConfigs) {
439 if (simpleBackend.equals(predefinedConfig.predefinedConfig)) {
440 extendedBackend = predefinedConfig.backend;
441 extendedOptions = predefinedConfig.options;
442 break;
443 }
444 }
445 }
446 SkCommandLineConfig* parsedConfig = nullptr;
447#if SK_SUPPORT_GPU
448 if (extendedBackend.equals("gpu")) {
449 parsedConfig = parse_command_line_config_gpu(tag, vias, extendedOptions);
450 }
451#endif
452 if (!parsedConfig) {
453 parsedConfig = new SkCommandLineConfig(tag, simpleBackend, vias);
454 }
455 outResult->emplace_back(parsedConfig);
456 }
457}