blob: 65ba372d7cc64fdb2086e9d42647d068f30056bc [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" },
52 { "glsrgb", "gpu", "api=gl,color=srgb" },
53 { "glwide", "gpu", "api=gl,color=f16_wide" },
54 { "glnarrow", "gpu", "api=gl,color=f16_narrow" },
55 { "gpudft", "gpu", "dit=true" },
56 { "gpudebug", "gpu", "api=debug" },
57 { "gpunull", "gpu", "api=null" },
58 { "debug", "gpu", "api=debug" },
59 { "nullgpu", "gpu", "api=null" },
60 { "angle_d3d11_es2", "gpu", "api=angle_d3d11_es2" },
Brian Osman21d742d2017-01-10 13:31:33 -050061 { "angle_d3d11_es3", "gpu", "api=angle_d3d11_es3" },
Brian Salomon002c1202016-10-18 11:28:20 -040062 { "angle_d3d9_es2", "gpu", "api=angle_d3d9_es2" },
63 { "angle_d3d11_es2_msaa4", "gpu", "api=angle_d3d11_es2,samples=4" },
64 { "angle_gl_es2", "gpu", "api=angle_gl_es2" },
Brian Osman21d742d2017-01-10 13:31:33 -050065 { "angle_gl_es3", "gpu", "api=angle_gl_es3" },
Brian Salomon002c1202016-10-18 11:28:20 -040066 { "commandbuffer", "gpu", "api=commandbuffer" }
kkinnunen3e980c32015-12-23 01:33:00 -080067#if SK_MESA
Brian Salomon002c1202016-10-18 11:28:20 -040068 ,{ "mesa", "gpu", "api=mesa" }
kkinnunen3e980c32015-12-23 01:33:00 -080069#endif
brianosman37e23342016-09-20 08:06:30 -070070#ifdef SK_VULKAN
Brian Salomon002c1202016-10-18 11:28:20 -040071 ,{ "vk", "gpu", "api=vulkan" }
72 ,{ "vksrgb", "gpu", "api=vulkan,color=srgb" }
73 ,{ "vkwide", "gpu", "api=vulkan,color=f16_wide" }
74 ,{ "vkmsaa4", "gpu", "api=vulkan,samples=4" }
75 ,{ "vkmsaa16", "gpu", "api=vulkan,samples=16" }
brianosman37e23342016-09-20 08:06:30 -070076#endif
77
78#else
79{ "", "", "" }
80#endif
81};
82
83static const char configHelp[] =
Derek Sollenbergerc65386a2017-01-05 09:50:22 -050084 "Options: 565 8888 srgb f16 nonrendering null pdf pdfa skp pipe svg xps";
brianosman37e23342016-09-20 08:06:30 -070085
86static const char* config_help_fn() {
87 static SkString helpString;
88 helpString.set(configHelp);
89 for (const auto& config : gPredefinedConfigs) {
90 helpString.appendf(" %s", config.predefinedConfig);
91 }
bsalomon808ecbb2016-09-28 12:40:22 -070092 helpString.append(" or use extended form 'backend[option=value,...]'.\n");
brianosman37e23342016-09-20 08:06:30 -070093 return helpString.c_str();
94}
kkinnunen3e980c32015-12-23 01:33:00 -080095
96static const char configExtendedHelp[] =
97 "Extended form: 'backend(option=value,...)'\n\n"
98 "Possible backends and options:\n"
99#if SK_SUPPORT_GPU
100 "\n"
bsalomon808ecbb2016-09-28 12:40:22 -0700101 "gpu[api=string,color=string,dit=bool,nvpr=bool,inst=bool,samples=int]\n"
kkinnunen3e980c32015-12-23 01:33:00 -0800102 "\tapi\ttype: string\tdefault: native.\n"
103 "\t Select graphics API to use with gpu backend.\n"
104 "\t Options:\n"
105 "\t\tnative\t\t\tUse platform default OpenGL or OpenGL ES backend.\n"
106 "\t\tgl \t\t\tUse OpenGL.\n"
107 "\t\tgles \t\t\tUse OpenGL ES.\n"
108 "\t\tdebug \t\t\tUse debug OpenGL.\n"
109 "\t\tnull \t\t\tUse null OpenGL.\n"
bsalomon11abd8d2016-10-14 08:13:48 -0700110 "\t\tangle_d3d9_es2\t\t\tUse OpenGL ES2 on the ANGLE Direct3D9 backend.\n"
111 "\t\tangle_d3d11_es2\t\t\tUse OpenGL ES2 on the ANGLE Direct3D11 backend.\n"
112 "\t\tangle_d3d11_es3\t\t\tUse OpenGL ES3 on the ANGLE Direct3D11 backend.\n"
113 "\t\tangle_gl_es2\t\t\tUse OpenGL ES2 on the ANGLE OpenGL backend.\n"
114 "\t\tangle_gl_es3\t\t\tUse OpenGL ES3 on the ANGLE OpenGL backend.\n"
kkinnunen3e980c32015-12-23 01:33:00 -0800115 "\t\tcommandbuffer\t\tUse command buffer.\n"
kkinnunen3e980c32015-12-23 01:33:00 -0800116#if SK_MESA
117 "\t\tmesa\t\t\tUse MESA.\n"
118#endif
bsalomondc0fcd42016-04-11 14:21:33 -0700119#ifdef SK_VULKAN
120 "\t\tvulkan\t\t\tUse Vulkan.\n"
121#endif
brianosmand93c1202016-03-10 07:49:08 -0800122 "\tcolor\ttype: string\tdefault: 8888.\n"
123 "\t Select framebuffer color format.\n"
124 "\t Options:\n"
125 "\t\t8888\t\t\tLinear 8888.\n"
brianosman4562f6e2016-09-19 14:42:04 -0700126 "\t\tf16{_gamut}\t\tLinear 16-bit floating point.\n"
127 "\t\tsrgb{_gamut}\t\tsRGB 8888.\n"
128 "\t gamut\ttype: string\tdefault: srgb.\n"
129 "\t Select color gamut for f16 or sRGB format buffers.\n"
130 "\t Options:\n"
131 "\t\tsrgb\t\t\tsRGB gamut.\n"
132 "\t\twide\t\t\tWide Gamut RGB.\n"
kkinnunen3e980c32015-12-23 01:33:00 -0800133 "\tdit\ttype: bool\tdefault: false.\n"
134 "\t Use device independent text.\n"
135 "\tnvpr\ttype: bool\tdefault: false.\n"
136 "\t Use NV_path_rendering OpenGL and OpenGL ES extension.\n"
137 "\tsamples\ttype: int\tdefault: 0.\n"
138 "\t Use multisampling with N samples.\n"
139 "\n"
140 "Predefined configs:\n\n"
brianosman37e23342016-09-20 08:06:30 -0700141 // Help text for pre-defined configs is auto-generated from gPredefinedConfigs
kkinnunen3e980c32015-12-23 01:33:00 -0800142#endif
143 ;
144
brianosman37e23342016-09-20 08:06:30 -0700145static const char* config_extended_help_fn() {
146 static SkString helpString;
147 helpString.set(configExtendedHelp);
148 for (const auto& config : gPredefinedConfigs) {
149 helpString.appendf("\t%-10s\t= gpu(%s)\n", config.predefinedConfig, config.options);
150 }
151 return helpString.c_str();
152}
kkinnunen3e980c32015-12-23 01:33:00 -0800153
brianosman37e23342016-09-20 08:06:30 -0700154DEFINE_extended_string(config, defaultConfigs, config_help_fn(), config_extended_help_fn());
kkinnunen3e980c32015-12-23 01:33:00 -0800155
156SkCommandLineConfig::SkCommandLineConfig(const SkString& tag, const SkString& backend,
157 const SkTArray<SkString>& viaParts)
158 : fTag(tag)
159 , fBackend(backend)
160 , fViaParts(viaParts) {
161}
162SkCommandLineConfig::~SkCommandLineConfig() {
163}
164
165#if SK_SUPPORT_GPU
166SkCommandLineConfigGpu::SkCommandLineConfigGpu(
csmartdaltone0d36292016-07-29 08:14:20 -0700167 const SkString& tag, const SkTArray<SkString>& viaParts, ContextType contextType, bool useNVPR,
168 bool useInstanced, bool useDIText, int samples, SkColorType colorType,
169 sk_sp<SkColorSpace> colorSpace)
kkinnunen3e980c32015-12-23 01:33:00 -0800170 : SkCommandLineConfig(tag, SkString("gpu"), viaParts)
171 , fContextType(contextType)
csmartdalton6270e552016-09-13 10:41:49 -0700172 , fContextOptions(ContextOptions::kNone)
kkinnunen3e980c32015-12-23 01:33:00 -0800173 , fUseDIText(useDIText)
brianosmand93c1202016-03-10 07:49:08 -0800174 , fSamples(samples)
175 , fColorType(colorType)
brianosmanb109b8c2016-06-16 13:03:24 -0700176 , fColorSpace(std::move(colorSpace)) {
csmartdalton6270e552016-09-13 10:41:49 -0700177 if (useNVPR) {
178 fContextOptions |= ContextOptions::kEnableNVPR;
179 }
180 if (useInstanced) {
181 fContextOptions |= ContextOptions::kUseInstanced;
182 }
brianosman20471892016-12-02 06:43:32 -0800183 // Subtle logic: If the config has a color space attached, we're going to be rendering to sRGB,
184 // so we need that capability. In addition, to get the widest test coverage, we DO NOT require
185 // that we can disable sRGB decode. (That's for rendering sRGB sources to legacy surfaces).
186 //
187 // If the config doesn't have a color space attached, we're going to be rendering in legacy
188 // mode. In that case, we can't allow a context to be created that has sRGB support without
189 // the ability to disable sRGB decode. Otherwise, all of our sRGB source resources will be
190 // treated as sRGB textures, but we will be unable to prevent the decode, causing them to be
191 // too dark.
Brian Osman7039f742016-11-01 15:56:16 -0400192 if (fColorSpace) {
csmartdalton6270e552016-09-13 10:41:49 -0700193 fContextOptions |= ContextOptions::kRequireSRGBSupport;
brianosman20471892016-12-02 06:43:32 -0800194 } else {
195 fContextOptions |= ContextOptions::kRequireSRGBDecodeDisableSupport;
csmartdalton6270e552016-09-13 10:41:49 -0700196 }
kkinnunen3e980c32015-12-23 01:33:00 -0800197}
198static bool parse_option_int(const SkString& value, int* outInt) {
199 if (value.isEmpty()) {
200 return false;
201 }
202 char* endptr = nullptr;
203 long intValue = strtol(value.c_str(), &endptr, 10);
204 if (*endptr != '\0') {
205 return false;
206 }
207 *outInt = static_cast<int>(intValue);
208 return true;
209}
210static bool parse_option_bool(const SkString& value, bool* outBool) {
211 if (value.equals("true")) {
212 *outBool = true;
213 return true;
214 }
215 if (value.equals("false")) {
216 *outBool = false;
217 return true;
218 }
219 return false;
220}
221static bool parse_option_gpu_api(const SkString& value,
222 SkCommandLineConfigGpu::ContextType* outContextType) {
kkinnunen3e980c32015-12-23 01:33:00 -0800223 if (value.equals("gl")) {
bsalomon85b4b532016-04-05 11:06:27 -0700224 *outContextType = GrContextFactory::kGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800225 return true;
226 }
227 if (value.equals("gles")) {
bsalomon85b4b532016-04-05 11:06:27 -0700228 *outContextType = GrContextFactory::kGLES_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800229 return true;
230 }
231 if (value.equals("debug")) {
bsalomon85b4b532016-04-05 11:06:27 -0700232 *outContextType = GrContextFactory::kDebugGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800233 return true;
234 }
235 if (value.equals("null")) {
bsalomon85b4b532016-04-05 11:06:27 -0700236 *outContextType = GrContextFactory::kNullGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800237 return true;
238 }
bsalomon11abd8d2016-10-14 08:13:48 -0700239 if (value.equals("angle_d3d9_es2")) {
240 *outContextType = GrContextFactory::kANGLE_D3D9_ES2_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800241 return true;
242 }
bsalomon11abd8d2016-10-14 08:13:48 -0700243 if (value.equals("angle_d3d11_es2")) {
244 *outContextType = GrContextFactory::kANGLE_D3D11_ES2_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800245 return true;
246 }
bsalomon11abd8d2016-10-14 08:13:48 -0700247 if (value.equals("angle_d3d11_es3")) {
248 *outContextType = GrContextFactory::kANGLE_D3D11_ES3_ContextType;
249 return true;
250 }
251 if (value.equals("angle_gl_es2")) {
252 *outContextType = GrContextFactory::kANGLE_GL_ES2_ContextType;
253 return true;
254 }
255 if (value.equals("angle_gl_es3")) {
256 *outContextType = GrContextFactory::kANGLE_GL_ES3_ContextType;
257 return true;
258 }
kkinnunen3e980c32015-12-23 01:33:00 -0800259 if (value.equals("commandbuffer")) {
bsalomon85b4b532016-04-05 11:06:27 -0700260 *outContextType = GrContextFactory::kCommandBuffer_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800261 return true;
262 }
kkinnunen3e980c32015-12-23 01:33:00 -0800263#if SK_MESA
264 if (value.equals("mesa")) {
bsalomon85b4b532016-04-05 11:06:27 -0700265 *outContextType = GrContextFactory::kMESA_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800266 return true;
267 }
268#endif
bsalomondc0fcd42016-04-11 14:21:33 -0700269#ifdef SK_VULKAN
270 if (value.equals("vulkan")) {
271 *outContextType = GrContextFactory::kVulkan_ContextType;
272 return true;
273 }
274#endif
kkinnunen3e980c32015-12-23 01:33:00 -0800275 return false;
276}
brianosmand93c1202016-03-10 07:49:08 -0800277static bool parse_option_gpu_color(const SkString& value,
278 SkColorType* outColorType,
brianosmanb109b8c2016-06-16 13:03:24 -0700279 sk_sp<SkColorSpace>* outColorSpace) {
brianosmand93c1202016-03-10 07:49:08 -0800280 if (value.equals("8888")) {
bsalomon33069252016-09-28 08:49:53 -0700281 *outColorType = kRGBA_8888_SkColorType;
brianosmanb109b8c2016-06-16 13:03:24 -0700282 *outColorSpace = nullptr;
brianosmand93c1202016-03-10 07:49:08 -0800283 return true;
284 }
brianosman4562f6e2016-09-19 14:42:04 -0700285
286 SkTArray<SkString> commands;
287 SkStrSplit(value.c_str(), "_", &commands);
288 if (commands.count() < 1 || commands.count() > 2) {
289 return false;
290 }
291
292 // First, figure out color gamut that we'll work in (default to sRGB)
raftias94888332016-10-18 10:02:51 -0700293 const bool linearGamma = commands[0].equals("f16");
Matt Sarett77a7a1b2017-02-07 13:56:11 -0500294 *outColorSpace = linearGamma ? SkColorSpace::MakeSRGBLinear()
295 : SkColorSpace::MakeSRGB();
brianosman4562f6e2016-09-19 14:42:04 -0700296 if (commands.count() == 2) {
297 if (commands[1].equals("srgb")) {
298 // sRGB gamut (which is our default)
299 } else if (commands[1].equals("wide")) {
300 // WideGamut RGB
301 const float gWideGamutRGB_toXYZD50[]{
302 0.7161046f, 0.1009296f, 0.1471858f, // -> X
303 0.2581874f, 0.7249378f, 0.0168748f, // -> Y
304 0.0000000f, 0.0517813f, 0.7734287f, // -> Z
305 };
306 SkMatrix44 wideGamutRGBMatrix(SkMatrix44::kUninitialized_Constructor);
307 wideGamutRGBMatrix.set3x3RowMajorf(gWideGamutRGB_toXYZD50);
Brian Osman526972e2016-10-24 09:24:02 -0400308 *outColorSpace = SkColorSpace::MakeRGB(linearGamma
raftias94888332016-10-18 10:02:51 -0700309 ? SkColorSpace::kLinear_RenderTargetGamma
310 : SkColorSpace::kSRGB_RenderTargetGamma,
Brian Osman526972e2016-10-24 09:24:02 -0400311 wideGamutRGBMatrix);
Brian Osman4a6b28e2016-10-17 11:14:02 -0400312 } else if (commands[1].equals("narrow")) {
313 // NarrowGamut RGB (an artifically smaller than sRGB gamut)
314 SkColorSpacePrimaries primaries ={
315 0.54f, 0.33f, // Rx, Ry
316 0.33f, 0.50f, // Gx, Gy
317 0.25f, 0.20f, // Bx, By
318 0.3127f, 0.3290f, // Wx, Wy
319 };
320 SkMatrix44 narrowGamutRGBMatrix(SkMatrix44::kUninitialized_Constructor);
321 primaries.toXYZD50(&narrowGamutRGBMatrix);
Brian Osman526972e2016-10-24 09:24:02 -0400322 *outColorSpace = SkColorSpace::MakeRGB(linearGamma
raftias94888332016-10-18 10:02:51 -0700323 ? SkColorSpace::kLinear_RenderTargetGamma
324 : SkColorSpace::kSRGB_RenderTargetGamma,
Brian Osman526972e2016-10-24 09:24:02 -0400325 narrowGamutRGBMatrix);
brianosman4562f6e2016-09-19 14:42:04 -0700326 } else {
327 // Unknown color gamut
328 return false;
329 }
330 }
331
332 // Now pick a color type
333 if (commands[0].equals("f16")) {
brianosmand93c1202016-03-10 07:49:08 -0800334 *outColorType = kRGBA_F16_SkColorType;
brianosmand93c1202016-03-10 07:49:08 -0800335 return true;
336 }
brianosman4562f6e2016-09-19 14:42:04 -0700337 if (commands[0].equals("srgb")) {
bsalomon33069252016-09-28 08:49:53 -0700338 *outColorType = kRGBA_8888_SkColorType;
brianosmand93c1202016-03-10 07:49:08 -0800339 return true;
340 }
341 return false;
342}
kkinnunen3e980c32015-12-23 01:33:00 -0800343
344SkCommandLineConfigGpu* parse_command_line_config_gpu(const SkString& tag,
345 const SkTArray<SkString>& vias,
346 const SkString& options) {
347 // Defaults for GPU backend.
348 bool seenAPI = false;
bsalomon85b4b532016-04-05 11:06:27 -0700349 SkCommandLineConfigGpu::ContextType contextType = GrContextFactory::kNativeGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800350 bool seenUseNVPR = false;
351 bool useNVPR = false;
csmartdaltone0d36292016-07-29 08:14:20 -0700352 bool seenUseInstanced = false;
353 bool useInstanced = false;
kkinnunen3e980c32015-12-23 01:33:00 -0800354 bool seenUseDIText =false;
355 bool useDIText = false;
356 bool seenSamples = false;
357 int samples = 0;
brianosmand93c1202016-03-10 07:49:08 -0800358 bool seenColor = false;
bsalomon33069252016-09-28 08:49:53 -0700359 SkColorType colorType = kRGBA_8888_SkColorType;
brianosmanb109b8c2016-06-16 13:03:24 -0700360 sk_sp<SkColorSpace> colorSpace = nullptr;
kkinnunen3e980c32015-12-23 01:33:00 -0800361
362 SkTArray<SkString> optionParts;
363 SkStrSplit(options.c_str(), ",", kStrict_SkStrSplitMode, &optionParts);
364 for (int i = 0; i < optionParts.count(); ++i) {
365 SkTArray<SkString> keyValueParts;
366 SkStrSplit(optionParts[i].c_str(), "=", kStrict_SkStrSplitMode, &keyValueParts);
367 if (keyValueParts.count() != 2) {
368 return nullptr;
369 }
370 const SkString& key = keyValueParts[0];
371 const SkString& value = keyValueParts[1];
372 bool valueOk = false;
373 if (key.equals("api") && !seenAPI) {
374 valueOk = parse_option_gpu_api(value, &contextType);
375 seenAPI = true;
376 } else if (key.equals("nvpr") && !seenUseNVPR) {
377 valueOk = parse_option_bool(value, &useNVPR);
378 seenUseNVPR = true;
csmartdaltone0d36292016-07-29 08:14:20 -0700379 } else if (key.equals("inst") && !seenUseInstanced) {
380 valueOk = parse_option_bool(value, &useInstanced);
381 seenUseInstanced = true;
kkinnunen3e980c32015-12-23 01:33:00 -0800382 } else if (key.equals("dit") && !seenUseDIText) {
383 valueOk = parse_option_bool(value, &useDIText);
384 seenUseDIText = true;
385 } else if (key.equals("samples") && !seenSamples) {
386 valueOk = parse_option_int(value, &samples);
387 seenSamples = true;
brianosmand93c1202016-03-10 07:49:08 -0800388 } else if (key.equals("color") && !seenColor) {
brianosmanb109b8c2016-06-16 13:03:24 -0700389 valueOk = parse_option_gpu_color(value, &colorType, &colorSpace);
brianosmand93c1202016-03-10 07:49:08 -0800390 seenColor = true;
kkinnunen3e980c32015-12-23 01:33:00 -0800391 }
392 if (!valueOk) {
393 return nullptr;
394 }
395 }
csmartdaltone0d36292016-07-29 08:14:20 -0700396 return new SkCommandLineConfigGpu(tag, vias, contextType, useNVPR, useInstanced, useDIText,
397 samples, colorType, colorSpace);
kkinnunen3e980c32015-12-23 01:33:00 -0800398}
399#endif
400
401void ParseConfigs(const SkCommandLineFlags::StringArray& configs,
402 SkCommandLineConfigArray* outResult) {
403 outResult->reset();
404 for (int i = 0; i < configs.count(); ++i) {
405 SkString extendedBackend;
406 SkString extendedOptions;
407 SkString simpleBackend;
408 SkTArray<SkString> vias;
409
410 SkString tag(configs[i]);
411 SkTArray<SkString> parts;
bsalomon808ecbb2016-09-28 12:40:22 -0700412 SkStrSplit(tag.c_str(), "[", kStrict_SkStrSplitMode, &parts);
kkinnunen3e980c32015-12-23 01:33:00 -0800413 if (parts.count() == 2) {
414 SkTArray<SkString> parts2;
bsalomon808ecbb2016-09-28 12:40:22 -0700415 SkStrSplit(parts[1].c_str(), "]", kStrict_SkStrSplitMode, &parts2);
kkinnunen3e980c32015-12-23 01:33:00 -0800416 if (parts2.count() == 2 && parts2[1].isEmpty()) {
417 SkStrSplit(parts[0].c_str(), "-", kStrict_SkStrSplitMode, &vias);
418 if (vias.count()) {
419 extendedBackend = vias[vias.count() - 1];
420 vias.pop_back();
421 } else {
422 extendedBackend = parts[0];
423 }
424 extendedOptions = parts2[0];
bsalomon808ecbb2016-09-28 12:40:22 -0700425 simpleBackend.printf("%s[%s]", extendedBackend.c_str(), extendedOptions.c_str());
kkinnunen3e980c32015-12-23 01:33:00 -0800426 }
427 }
428
429 if (extendedBackend.isEmpty()) {
430 simpleBackend = tag;
431 SkStrSplit(tag.c_str(), "-", kStrict_SkStrSplitMode, &vias);
432 if (vias.count()) {
433 simpleBackend = vias[vias.count() - 1];
434 vias.pop_back();
435 }
kkinnunen3e980c32015-12-23 01:33:00 -0800436 for (auto& predefinedConfig : gPredefinedConfigs) {
437 if (simpleBackend.equals(predefinedConfig.predefinedConfig)) {
438 extendedBackend = predefinedConfig.backend;
439 extendedOptions = predefinedConfig.options;
440 break;
441 }
442 }
443 }
444 SkCommandLineConfig* parsedConfig = nullptr;
445#if SK_SUPPORT_GPU
446 if (extendedBackend.equals("gpu")) {
447 parsedConfig = parse_command_line_config_gpu(tag, vias, extendedOptions);
448 }
449#endif
450 if (!parsedConfig) {
451 parsedConfig = new SkCommandLineConfig(tag, simpleBackend, vias);
452 }
453 outResult->emplace_back(parsedConfig);
454 }
455}