blob: 5763e4a6ca74f3c8fd0a2ae943d7e950766244b2 [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
23#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
24 " hwui"
25#endif
26 ;
27
brianosman37e23342016-09-20 08:06:30 -070028static const struct {
29 const char* predefinedConfig;
30 const char* backend;
31 const char* options;
32} gPredefinedConfigs[] ={
33#if SK_SUPPORT_GPU
Brian Salomon002c1202016-10-18 11:28:20 -040034 { "gpu", "gpu", "" },
35 { "gl", "gpu", "api=gl" },
36 { "msaa4", "gpu", "samples=4" },
37 { "glmsaa4", "gpu", "api=gl,samples=4" },
38 { "msaa16", "gpu", "samples=16" },
39 { "nvpr4", "gpu", "nvpr=true,samples=4" },
40 { "glnvpr4", "gpu", "api=gl,nvpr=true,samples=4" },
41 { "nvpr16", "gpu", "nvpr=true,samples=16" },
42 { "nvprdit4", "gpu", "nvpr=true,samples=4,dit=true" },
43 { "glnvprdit4", "gpu", "api=gl,nvpr=true,samples=4,dit=true" },
44 { "nvprdit16", "gpu", "nvpr=true,samples=16,dit=true" },
45 { "glinst", "gpu", "api=gl,inst=true" },
46 { "glinst4", "gpu", "api=gl,inst=true,samples=4" },
47 { "glinstdit4", "gpu", "api=gl,inst=true,samples=4,dit=true" },
48 { "glinst16", "gpu", "api=gl,inst=true,samples=16" },
49 { "glinstdit16", "gpu", "api=gl,inst=true,samples=16,dit=true" },
50 { "esinst", "gpu", "api=gles,inst=true" },
51 { "esinst4", "gpu", "api=gles,inst=true,samples=4" },
52 { "esinstdit4", "gpu", "api=gles,inst=true,samples=4,dit=true" },
53 { "gpuf16", "gpu", "color=f16" },
54 { "gpusrgb", "gpu", "color=srgb" },
55 { "glsrgb", "gpu", "api=gl,color=srgb" },
56 { "glwide", "gpu", "api=gl,color=f16_wide" },
57 { "glnarrow", "gpu", "api=gl,color=f16_narrow" },
58 { "gpudft", "gpu", "dit=true" },
59 { "gpudebug", "gpu", "api=debug" },
60 { "gpunull", "gpu", "api=null" },
61 { "debug", "gpu", "api=debug" },
62 { "nullgpu", "gpu", "api=null" },
63 { "angle_d3d11_es2", "gpu", "api=angle_d3d11_es2" },
64 { "angle_d3d9_es2", "gpu", "api=angle_d3d9_es2" },
65 { "angle_d3d11_es2_msaa4", "gpu", "api=angle_d3d11_es2,samples=4" },
66 { "angle_gl_es2", "gpu", "api=angle_gl_es2" },
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[] =
85 "Options: 565 8888 srgb f16 nonrendering null pdf pdfa skp pipe svg xps"
kkinnunen3e980c32015-12-23 01:33:00 -080086#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
87 " hwui"
88#endif
brianosman37e23342016-09-20 08:06:30 -070089 ;
90
91static const char* config_help_fn() {
92 static SkString helpString;
93 helpString.set(configHelp);
94 for (const auto& config : gPredefinedConfigs) {
95 helpString.appendf(" %s", config.predefinedConfig);
96 }
bsalomon808ecbb2016-09-28 12:40:22 -070097 helpString.append(" or use extended form 'backend[option=value,...]'.\n");
brianosman37e23342016-09-20 08:06:30 -070098 return helpString.c_str();
99}
kkinnunen3e980c32015-12-23 01:33:00 -0800100
101static const char configExtendedHelp[] =
102 "Extended form: 'backend(option=value,...)'\n\n"
103 "Possible backends and options:\n"
104#if SK_SUPPORT_GPU
105 "\n"
bsalomon808ecbb2016-09-28 12:40:22 -0700106 "gpu[api=string,color=string,dit=bool,nvpr=bool,inst=bool,samples=int]\n"
kkinnunen3e980c32015-12-23 01:33:00 -0800107 "\tapi\ttype: string\tdefault: native.\n"
108 "\t Select graphics API to use with gpu backend.\n"
109 "\t Options:\n"
110 "\t\tnative\t\t\tUse platform default OpenGL or OpenGL ES backend.\n"
111 "\t\tgl \t\t\tUse OpenGL.\n"
112 "\t\tgles \t\t\tUse OpenGL ES.\n"
113 "\t\tdebug \t\t\tUse debug OpenGL.\n"
114 "\t\tnull \t\t\tUse null OpenGL.\n"
bsalomon11abd8d2016-10-14 08:13:48 -0700115 "\t\tangle_d3d9_es2\t\t\tUse OpenGL ES2 on the ANGLE Direct3D9 backend.\n"
116 "\t\tangle_d3d11_es2\t\t\tUse OpenGL ES2 on the ANGLE Direct3D11 backend.\n"
117 "\t\tangle_d3d11_es3\t\t\tUse OpenGL ES3 on the ANGLE Direct3D11 backend.\n"
118 "\t\tangle_gl_es2\t\t\tUse OpenGL ES2 on the ANGLE OpenGL backend.\n"
119 "\t\tangle_gl_es3\t\t\tUse OpenGL ES3 on the ANGLE OpenGL backend.\n"
kkinnunen3e980c32015-12-23 01:33:00 -0800120 "\t\tcommandbuffer\t\tUse command buffer.\n"
kkinnunen3e980c32015-12-23 01:33:00 -0800121#if SK_MESA
122 "\t\tmesa\t\t\tUse MESA.\n"
123#endif
bsalomondc0fcd42016-04-11 14:21:33 -0700124#ifdef SK_VULKAN
125 "\t\tvulkan\t\t\tUse Vulkan.\n"
126#endif
brianosmand93c1202016-03-10 07:49:08 -0800127 "\tcolor\ttype: string\tdefault: 8888.\n"
128 "\t Select framebuffer color format.\n"
129 "\t Options:\n"
130 "\t\t8888\t\t\tLinear 8888.\n"
brianosman4562f6e2016-09-19 14:42:04 -0700131 "\t\tf16{_gamut}\t\tLinear 16-bit floating point.\n"
132 "\t\tsrgb{_gamut}\t\tsRGB 8888.\n"
133 "\t gamut\ttype: string\tdefault: srgb.\n"
134 "\t Select color gamut for f16 or sRGB format buffers.\n"
135 "\t Options:\n"
136 "\t\tsrgb\t\t\tsRGB gamut.\n"
137 "\t\twide\t\t\tWide Gamut RGB.\n"
kkinnunen3e980c32015-12-23 01:33:00 -0800138 "\tdit\ttype: bool\tdefault: false.\n"
139 "\t Use device independent text.\n"
140 "\tnvpr\ttype: bool\tdefault: false.\n"
141 "\t Use NV_path_rendering OpenGL and OpenGL ES extension.\n"
142 "\tsamples\ttype: int\tdefault: 0.\n"
143 "\t Use multisampling with N samples.\n"
144 "\n"
145 "Predefined configs:\n\n"
brianosman37e23342016-09-20 08:06:30 -0700146 // Help text for pre-defined configs is auto-generated from gPredefinedConfigs
kkinnunen3e980c32015-12-23 01:33:00 -0800147#endif
148 ;
149
brianosman37e23342016-09-20 08:06:30 -0700150static const char* config_extended_help_fn() {
151 static SkString helpString;
152 helpString.set(configExtendedHelp);
153 for (const auto& config : gPredefinedConfigs) {
154 helpString.appendf("\t%-10s\t= gpu(%s)\n", config.predefinedConfig, config.options);
155 }
156 return helpString.c_str();
157}
kkinnunen3e980c32015-12-23 01:33:00 -0800158
brianosman37e23342016-09-20 08:06:30 -0700159DEFINE_extended_string(config, defaultConfigs, config_help_fn(), config_extended_help_fn());
kkinnunen3e980c32015-12-23 01:33:00 -0800160
161SkCommandLineConfig::SkCommandLineConfig(const SkString& tag, const SkString& backend,
162 const SkTArray<SkString>& viaParts)
163 : fTag(tag)
164 , fBackend(backend)
165 , fViaParts(viaParts) {
166}
167SkCommandLineConfig::~SkCommandLineConfig() {
168}
169
170#if SK_SUPPORT_GPU
171SkCommandLineConfigGpu::SkCommandLineConfigGpu(
csmartdaltone0d36292016-07-29 08:14:20 -0700172 const SkString& tag, const SkTArray<SkString>& viaParts, ContextType contextType, bool useNVPR,
173 bool useInstanced, bool useDIText, int samples, SkColorType colorType,
174 sk_sp<SkColorSpace> colorSpace)
kkinnunen3e980c32015-12-23 01:33:00 -0800175 : SkCommandLineConfig(tag, SkString("gpu"), viaParts)
176 , fContextType(contextType)
csmartdalton6270e552016-09-13 10:41:49 -0700177 , fContextOptions(ContextOptions::kNone)
kkinnunen3e980c32015-12-23 01:33:00 -0800178 , fUseDIText(useDIText)
brianosmand93c1202016-03-10 07:49:08 -0800179 , fSamples(samples)
180 , fColorType(colorType)
brianosmanb109b8c2016-06-16 13:03:24 -0700181 , fColorSpace(std::move(colorSpace)) {
csmartdalton6270e552016-09-13 10:41:49 -0700182 if (useNVPR) {
183 fContextOptions |= ContextOptions::kEnableNVPR;
184 }
185 if (useInstanced) {
186 fContextOptions |= ContextOptions::kUseInstanced;
187 }
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
193 // mode. In that case, we can't allow a context to be created that has sRGB support without
194 // the ability to disable sRGB decode. Otherwise, all of our sRGB source resources will be
195 // treated as sRGB textures, but we will be unable to prevent the decode, causing them to be
196 // too dark.
Brian Osman7039f742016-11-01 15:56:16 -0400197 if (fColorSpace) {
csmartdalton6270e552016-09-13 10:41:49 -0700198 fContextOptions |= ContextOptions::kRequireSRGBSupport;
brianosman20471892016-12-02 06:43:32 -0800199 } else {
200 fContextOptions |= ContextOptions::kRequireSRGBDecodeDisableSupport;
csmartdalton6270e552016-09-13 10:41:49 -0700201 }
kkinnunen3e980c32015-12-23 01:33:00 -0800202}
203static bool parse_option_int(const SkString& value, int* outInt) {
204 if (value.isEmpty()) {
205 return false;
206 }
207 char* endptr = nullptr;
208 long intValue = strtol(value.c_str(), &endptr, 10);
209 if (*endptr != '\0') {
210 return false;
211 }
212 *outInt = static_cast<int>(intValue);
213 return true;
214}
215static bool parse_option_bool(const SkString& value, bool* outBool) {
216 if (value.equals("true")) {
217 *outBool = true;
218 return true;
219 }
220 if (value.equals("false")) {
221 *outBool = false;
222 return true;
223 }
224 return false;
225}
226static bool parse_option_gpu_api(const SkString& value,
227 SkCommandLineConfigGpu::ContextType* outContextType) {
kkinnunen3e980c32015-12-23 01:33:00 -0800228 if (value.equals("gl")) {
bsalomon85b4b532016-04-05 11:06:27 -0700229 *outContextType = GrContextFactory::kGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800230 return true;
231 }
232 if (value.equals("gles")) {
bsalomon85b4b532016-04-05 11:06:27 -0700233 *outContextType = GrContextFactory::kGLES_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800234 return true;
235 }
236 if (value.equals("debug")) {
bsalomon85b4b532016-04-05 11:06:27 -0700237 *outContextType = GrContextFactory::kDebugGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800238 return true;
239 }
240 if (value.equals("null")) {
bsalomon85b4b532016-04-05 11:06:27 -0700241 *outContextType = GrContextFactory::kNullGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800242 return true;
243 }
bsalomon11abd8d2016-10-14 08:13:48 -0700244 if (value.equals("angle_d3d9_es2")) {
245 *outContextType = GrContextFactory::kANGLE_D3D9_ES2_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800246 return true;
247 }
bsalomon11abd8d2016-10-14 08:13:48 -0700248 if (value.equals("angle_d3d11_es2")) {
249 *outContextType = GrContextFactory::kANGLE_D3D11_ES2_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800250 return true;
251 }
bsalomon11abd8d2016-10-14 08:13:48 -0700252 if (value.equals("angle_d3d11_es3")) {
253 *outContextType = GrContextFactory::kANGLE_D3D11_ES3_ContextType;
254 return true;
255 }
256 if (value.equals("angle_gl_es2")) {
257 *outContextType = GrContextFactory::kANGLE_GL_ES2_ContextType;
258 return true;
259 }
260 if (value.equals("angle_gl_es3")) {
261 *outContextType = GrContextFactory::kANGLE_GL_ES3_ContextType;
262 return true;
263 }
kkinnunen3e980c32015-12-23 01:33:00 -0800264 if (value.equals("commandbuffer")) {
bsalomon85b4b532016-04-05 11:06:27 -0700265 *outContextType = GrContextFactory::kCommandBuffer_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800266 return true;
267 }
kkinnunen3e980c32015-12-23 01:33:00 -0800268#if SK_MESA
269 if (value.equals("mesa")) {
bsalomon85b4b532016-04-05 11:06:27 -0700270 *outContextType = GrContextFactory::kMESA_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800271 return true;
272 }
273#endif
bsalomondc0fcd42016-04-11 14:21:33 -0700274#ifdef SK_VULKAN
275 if (value.equals("vulkan")) {
276 *outContextType = GrContextFactory::kVulkan_ContextType;
277 return true;
278 }
279#endif
kkinnunen3e980c32015-12-23 01:33:00 -0800280 return false;
281}
brianosmand93c1202016-03-10 07:49:08 -0800282static bool parse_option_gpu_color(const SkString& value,
283 SkColorType* outColorType,
brianosmanb109b8c2016-06-16 13:03:24 -0700284 sk_sp<SkColorSpace>* outColorSpace) {
brianosmand93c1202016-03-10 07:49:08 -0800285 if (value.equals("8888")) {
bsalomon33069252016-09-28 08:49:53 -0700286 *outColorType = kRGBA_8888_SkColorType;
brianosmanb109b8c2016-06-16 13:03:24 -0700287 *outColorSpace = nullptr;
brianosmand93c1202016-03-10 07:49:08 -0800288 return true;
289 }
brianosman4562f6e2016-09-19 14:42:04 -0700290
291 SkTArray<SkString> commands;
292 SkStrSplit(value.c_str(), "_", &commands);
293 if (commands.count() < 1 || commands.count() > 2) {
294 return false;
295 }
296
297 // First, figure out color gamut that we'll work in (default to sRGB)
raftias94888332016-10-18 10:02:51 -0700298 const bool linearGamma = commands[0].equals("f16");
Brian Osman526972e2016-10-24 09:24:02 -0400299 *outColorSpace = SkColorSpace::MakeNamed(linearGamma ? SkColorSpace::kSRGBLinear_Named
300 : SkColorSpace::kSRGB_Named);
brianosman4562f6e2016-09-19 14:42:04 -0700301 if (commands.count() == 2) {
302 if (commands[1].equals("srgb")) {
303 // sRGB gamut (which is our default)
304 } else if (commands[1].equals("wide")) {
305 // WideGamut RGB
306 const float gWideGamutRGB_toXYZD50[]{
307 0.7161046f, 0.1009296f, 0.1471858f, // -> X
308 0.2581874f, 0.7249378f, 0.0168748f, // -> Y
309 0.0000000f, 0.0517813f, 0.7734287f, // -> Z
310 };
311 SkMatrix44 wideGamutRGBMatrix(SkMatrix44::kUninitialized_Constructor);
312 wideGamutRGBMatrix.set3x3RowMajorf(gWideGamutRGB_toXYZD50);
Brian Osman526972e2016-10-24 09:24:02 -0400313 *outColorSpace = SkColorSpace::MakeRGB(linearGamma
raftias94888332016-10-18 10:02:51 -0700314 ? SkColorSpace::kLinear_RenderTargetGamma
315 : SkColorSpace::kSRGB_RenderTargetGamma,
Brian Osman526972e2016-10-24 09:24:02 -0400316 wideGamutRGBMatrix);
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);
Brian Osman526972e2016-10-24 09:24:02 -0400327 *outColorSpace = SkColorSpace::MakeRGB(linearGamma
raftias94888332016-10-18 10:02:51 -0700328 ? SkColorSpace::kLinear_RenderTargetGamma
329 : SkColorSpace::kSRGB_RenderTargetGamma,
Brian Osman526972e2016-10-24 09:24:02 -0400330 narrowGamutRGBMatrix);
brianosman4562f6e2016-09-19 14:42:04 -0700331 } else {
332 // Unknown color gamut
333 return false;
334 }
335 }
336
337 // Now pick a color type
338 if (commands[0].equals("f16")) {
brianosmand93c1202016-03-10 07:49:08 -0800339 *outColorType = kRGBA_F16_SkColorType;
brianosmand93c1202016-03-10 07:49:08 -0800340 return true;
341 }
brianosman4562f6e2016-09-19 14:42:04 -0700342 if (commands[0].equals("srgb")) {
bsalomon33069252016-09-28 08:49:53 -0700343 *outColorType = kRGBA_8888_SkColorType;
brianosmand93c1202016-03-10 07:49:08 -0800344 return true;
345 }
346 return false;
347}
kkinnunen3e980c32015-12-23 01:33:00 -0800348
349SkCommandLineConfigGpu* parse_command_line_config_gpu(const SkString& tag,
350 const SkTArray<SkString>& vias,
351 const SkString& options) {
352 // Defaults for GPU backend.
353 bool seenAPI = false;
bsalomon85b4b532016-04-05 11:06:27 -0700354 SkCommandLineConfigGpu::ContextType contextType = GrContextFactory::kNativeGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800355 bool seenUseNVPR = false;
356 bool useNVPR = false;
csmartdaltone0d36292016-07-29 08:14:20 -0700357 bool seenUseInstanced = false;
358 bool useInstanced = false;
kkinnunen3e980c32015-12-23 01:33:00 -0800359 bool seenUseDIText =false;
360 bool useDIText = false;
361 bool seenSamples = false;
362 int samples = 0;
brianosmand93c1202016-03-10 07:49:08 -0800363 bool seenColor = false;
bsalomon33069252016-09-28 08:49:53 -0700364 SkColorType colorType = kRGBA_8888_SkColorType;
brianosmanb109b8c2016-06-16 13:03:24 -0700365 sk_sp<SkColorSpace> colorSpace = nullptr;
kkinnunen3e980c32015-12-23 01:33:00 -0800366
367 SkTArray<SkString> optionParts;
368 SkStrSplit(options.c_str(), ",", kStrict_SkStrSplitMode, &optionParts);
369 for (int i = 0; i < optionParts.count(); ++i) {
370 SkTArray<SkString> keyValueParts;
371 SkStrSplit(optionParts[i].c_str(), "=", kStrict_SkStrSplitMode, &keyValueParts);
372 if (keyValueParts.count() != 2) {
373 return nullptr;
374 }
375 const SkString& key = keyValueParts[0];
376 const SkString& value = keyValueParts[1];
377 bool valueOk = false;
378 if (key.equals("api") && !seenAPI) {
379 valueOk = parse_option_gpu_api(value, &contextType);
380 seenAPI = true;
381 } else if (key.equals("nvpr") && !seenUseNVPR) {
382 valueOk = parse_option_bool(value, &useNVPR);
383 seenUseNVPR = true;
csmartdaltone0d36292016-07-29 08:14:20 -0700384 } else if (key.equals("inst") && !seenUseInstanced) {
385 valueOk = parse_option_bool(value, &useInstanced);
386 seenUseInstanced = true;
kkinnunen3e980c32015-12-23 01:33:00 -0800387 } else if (key.equals("dit") && !seenUseDIText) {
388 valueOk = parse_option_bool(value, &useDIText);
389 seenUseDIText = true;
390 } else if (key.equals("samples") && !seenSamples) {
391 valueOk = parse_option_int(value, &samples);
392 seenSamples = true;
brianosmand93c1202016-03-10 07:49:08 -0800393 } else if (key.equals("color") && !seenColor) {
brianosmanb109b8c2016-06-16 13:03:24 -0700394 valueOk = parse_option_gpu_color(value, &colorType, &colorSpace);
brianosmand93c1202016-03-10 07:49:08 -0800395 seenColor = true;
kkinnunen3e980c32015-12-23 01:33:00 -0800396 }
397 if (!valueOk) {
398 return nullptr;
399 }
400 }
csmartdaltone0d36292016-07-29 08:14:20 -0700401 return new SkCommandLineConfigGpu(tag, vias, contextType, useNVPR, useInstanced, useDIText,
402 samples, colorType, colorSpace);
kkinnunen3e980c32015-12-23 01:33:00 -0800403}
404#endif
405
406void ParseConfigs(const SkCommandLineFlags::StringArray& configs,
407 SkCommandLineConfigArray* outResult) {
408 outResult->reset();
409 for (int i = 0; i < configs.count(); ++i) {
410 SkString extendedBackend;
411 SkString extendedOptions;
412 SkString simpleBackend;
413 SkTArray<SkString> vias;
414
415 SkString tag(configs[i]);
416 SkTArray<SkString> parts;
bsalomon808ecbb2016-09-28 12:40:22 -0700417 SkStrSplit(tag.c_str(), "[", kStrict_SkStrSplitMode, &parts);
kkinnunen3e980c32015-12-23 01:33:00 -0800418 if (parts.count() == 2) {
419 SkTArray<SkString> parts2;
bsalomon808ecbb2016-09-28 12:40:22 -0700420 SkStrSplit(parts[1].c_str(), "]", kStrict_SkStrSplitMode, &parts2);
kkinnunen3e980c32015-12-23 01:33:00 -0800421 if (parts2.count() == 2 && parts2[1].isEmpty()) {
422 SkStrSplit(parts[0].c_str(), "-", kStrict_SkStrSplitMode, &vias);
423 if (vias.count()) {
424 extendedBackend = vias[vias.count() - 1];
425 vias.pop_back();
426 } else {
427 extendedBackend = parts[0];
428 }
429 extendedOptions = parts2[0];
bsalomon808ecbb2016-09-28 12:40:22 -0700430 simpleBackend.printf("%s[%s]", extendedBackend.c_str(), extendedOptions.c_str());
kkinnunen3e980c32015-12-23 01:33:00 -0800431 }
432 }
433
434 if (extendedBackend.isEmpty()) {
435 simpleBackend = tag;
436 SkStrSplit(tag.c_str(), "-", kStrict_SkStrSplitMode, &vias);
437 if (vias.count()) {
438 simpleBackend = vias[vias.count() - 1];
439 vias.pop_back();
440 }
kkinnunen3e980c32015-12-23 01:33:00 -0800441 for (auto& predefinedConfig : gPredefinedConfigs) {
442 if (simpleBackend.equals(predefinedConfig.predefinedConfig)) {
443 extendedBackend = predefinedConfig.backend;
444 extendedOptions = predefinedConfig.options;
445 break;
446 }
447 }
448 }
449 SkCommandLineConfig* parsedConfig = nullptr;
450#if SK_SUPPORT_GPU
451 if (extendedBackend.equals("gpu")) {
452 parsedConfig = parse_command_line_config_gpu(tag, vias, extendedOptions);
453 }
454#endif
455 if (!parsedConfig) {
456 parsedConfig = new SkCommandLineConfig(tag, simpleBackend, vias);
457 }
458 outResult->emplace_back(parsedConfig);
459 }
460}