blob: 3e5e9b9fffd32d660b9be25be6889c7010e78607 [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)
csmartdaltone812d492017-02-21 12:36:05 -0700172 , fContextOverrides(ContextOverrides::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) {
csmartdaltone812d492017-02-21 12:36:05 -0700178 fContextOverrides |= ContextOverrides::kRequireNVPRSupport;
179 } else if (!useInstanced) {
180 // We don't disable NVPR for instanced configs. Otherwise the caps wouldn't use mixed
181 // samples and we couldn't test the mixed samples backend for simple shapes.
182 fContextOverrides |= ContextOverrides::kDisableNVPR;
csmartdalton6270e552016-09-13 10:41:49 -0700183 }
184 if (useInstanced) {
csmartdaltone812d492017-02-21 12:36:05 -0700185 fContextOverrides |= ContextOverrides::kUseInstanced;
csmartdalton6270e552016-09-13 10:41:49 -0700186 }
brianosman20471892016-12-02 06:43:32 -0800187 // Subtle logic: If the config has a color space attached, we're going to be rendering to sRGB,
188 // so we need that capability. In addition, to get the widest test coverage, we DO NOT require
189 // that we can disable sRGB decode. (That's for rendering sRGB sources to legacy surfaces).
190 //
191 // If the config doesn't have a color space attached, we're going to be rendering in legacy
csmartdaltone812d492017-02-21 12:36:05 -0700192 // mode. In that case, we don't require sRGB capability and we defer to the client to decide on
193 // sRGB decode control.
Brian Osman7039f742016-11-01 15:56:16 -0400194 if (fColorSpace) {
csmartdaltone812d492017-02-21 12:36:05 -0700195 fContextOverrides |= ContextOverrides::kRequireSRGBSupport;
196 fContextOverrides |= ContextOverrides::kAllowSRGBWithoutDecodeControl;
csmartdalton6270e552016-09-13 10:41:49 -0700197 }
kkinnunen3e980c32015-12-23 01:33:00 -0800198}
199static bool parse_option_int(const SkString& value, int* outInt) {
200 if (value.isEmpty()) {
201 return false;
202 }
203 char* endptr = nullptr;
204 long intValue = strtol(value.c_str(), &endptr, 10);
205 if (*endptr != '\0') {
206 return false;
207 }
208 *outInt = static_cast<int>(intValue);
209 return true;
210}
211static bool parse_option_bool(const SkString& value, bool* outBool) {
212 if (value.equals("true")) {
213 *outBool = true;
214 return true;
215 }
216 if (value.equals("false")) {
217 *outBool = false;
218 return true;
219 }
220 return false;
221}
222static bool parse_option_gpu_api(const SkString& value,
223 SkCommandLineConfigGpu::ContextType* outContextType) {
kkinnunen3e980c32015-12-23 01:33:00 -0800224 if (value.equals("gl")) {
bsalomon85b4b532016-04-05 11:06:27 -0700225 *outContextType = GrContextFactory::kGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800226 return true;
227 }
228 if (value.equals("gles")) {
bsalomon85b4b532016-04-05 11:06:27 -0700229 *outContextType = GrContextFactory::kGLES_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800230 return true;
231 }
232 if (value.equals("debug")) {
bsalomon85b4b532016-04-05 11:06:27 -0700233 *outContextType = GrContextFactory::kDebugGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800234 return true;
235 }
236 if (value.equals("null")) {
bsalomon85b4b532016-04-05 11:06:27 -0700237 *outContextType = GrContextFactory::kNullGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800238 return true;
239 }
bsalomon11abd8d2016-10-14 08:13:48 -0700240 if (value.equals("angle_d3d9_es2")) {
241 *outContextType = GrContextFactory::kANGLE_D3D9_ES2_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800242 return true;
243 }
bsalomon11abd8d2016-10-14 08:13:48 -0700244 if (value.equals("angle_d3d11_es2")) {
245 *outContextType = GrContextFactory::kANGLE_D3D11_ES2_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800246 return true;
247 }
bsalomon11abd8d2016-10-14 08:13:48 -0700248 if (value.equals("angle_d3d11_es3")) {
249 *outContextType = GrContextFactory::kANGLE_D3D11_ES3_ContextType;
250 return true;
251 }
252 if (value.equals("angle_gl_es2")) {
253 *outContextType = GrContextFactory::kANGLE_GL_ES2_ContextType;
254 return true;
255 }
256 if (value.equals("angle_gl_es3")) {
257 *outContextType = GrContextFactory::kANGLE_GL_ES3_ContextType;
258 return true;
259 }
kkinnunen3e980c32015-12-23 01:33:00 -0800260 if (value.equals("commandbuffer")) {
bsalomon85b4b532016-04-05 11:06:27 -0700261 *outContextType = GrContextFactory::kCommandBuffer_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800262 return true;
263 }
kkinnunen3e980c32015-12-23 01:33:00 -0800264#if SK_MESA
265 if (value.equals("mesa")) {
bsalomon85b4b532016-04-05 11:06:27 -0700266 *outContextType = GrContextFactory::kMESA_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800267 return true;
268 }
269#endif
bsalomondc0fcd42016-04-11 14:21:33 -0700270#ifdef SK_VULKAN
271 if (value.equals("vulkan")) {
272 *outContextType = GrContextFactory::kVulkan_ContextType;
273 return true;
274 }
275#endif
kkinnunen3e980c32015-12-23 01:33:00 -0800276 return false;
277}
brianosmand93c1202016-03-10 07:49:08 -0800278static bool parse_option_gpu_color(const SkString& value,
279 SkColorType* outColorType,
brianosmanb109b8c2016-06-16 13:03:24 -0700280 sk_sp<SkColorSpace>* outColorSpace) {
brianosmand93c1202016-03-10 07:49:08 -0800281 if (value.equals("8888")) {
bsalomon33069252016-09-28 08:49:53 -0700282 *outColorType = kRGBA_8888_SkColorType;
brianosmanb109b8c2016-06-16 13:03:24 -0700283 *outColorSpace = nullptr;
brianosmand93c1202016-03-10 07:49:08 -0800284 return true;
285 }
brianosman4562f6e2016-09-19 14:42:04 -0700286
287 SkTArray<SkString> commands;
288 SkStrSplit(value.c_str(), "_", &commands);
289 if (commands.count() < 1 || commands.count() > 2) {
290 return false;
291 }
292
293 // First, figure out color gamut that we'll work in (default to sRGB)
raftias94888332016-10-18 10:02:51 -0700294 const bool linearGamma = commands[0].equals("f16");
Matt Sarett77a7a1b2017-02-07 13:56:11 -0500295 *outColorSpace = linearGamma ? SkColorSpace::MakeSRGBLinear()
296 : SkColorSpace::MakeSRGB();
brianosman4562f6e2016-09-19 14:42:04 -0700297 if (commands.count() == 2) {
298 if (commands[1].equals("srgb")) {
299 // sRGB gamut (which is our default)
300 } else if (commands[1].equals("wide")) {
301 // WideGamut RGB
302 const float gWideGamutRGB_toXYZD50[]{
303 0.7161046f, 0.1009296f, 0.1471858f, // -> X
304 0.2581874f, 0.7249378f, 0.0168748f, // -> Y
305 0.0000000f, 0.0517813f, 0.7734287f, // -> Z
306 };
307 SkMatrix44 wideGamutRGBMatrix(SkMatrix44::kUninitialized_Constructor);
308 wideGamutRGBMatrix.set3x3RowMajorf(gWideGamutRGB_toXYZD50);
Brian Osman526972e2016-10-24 09:24:02 -0400309 *outColorSpace = SkColorSpace::MakeRGB(linearGamma
raftias94888332016-10-18 10:02:51 -0700310 ? SkColorSpace::kLinear_RenderTargetGamma
311 : SkColorSpace::kSRGB_RenderTargetGamma,
Brian Osman526972e2016-10-24 09:24:02 -0400312 wideGamutRGBMatrix);
Brian Osman4a6b28e2016-10-17 11:14:02 -0400313 } else if (commands[1].equals("narrow")) {
314 // NarrowGamut RGB (an artifically smaller than sRGB gamut)
315 SkColorSpacePrimaries primaries ={
316 0.54f, 0.33f, // Rx, Ry
317 0.33f, 0.50f, // Gx, Gy
318 0.25f, 0.20f, // Bx, By
319 0.3127f, 0.3290f, // Wx, Wy
320 };
321 SkMatrix44 narrowGamutRGBMatrix(SkMatrix44::kUninitialized_Constructor);
322 primaries.toXYZD50(&narrowGamutRGBMatrix);
Brian Osman526972e2016-10-24 09:24:02 -0400323 *outColorSpace = SkColorSpace::MakeRGB(linearGamma
raftias94888332016-10-18 10:02:51 -0700324 ? SkColorSpace::kLinear_RenderTargetGamma
325 : SkColorSpace::kSRGB_RenderTargetGamma,
Brian Osman526972e2016-10-24 09:24:02 -0400326 narrowGamutRGBMatrix);
brianosman4562f6e2016-09-19 14:42:04 -0700327 } else {
328 // Unknown color gamut
329 return false;
330 }
331 }
332
333 // Now pick a color type
334 if (commands[0].equals("f16")) {
brianosmand93c1202016-03-10 07:49:08 -0800335 *outColorType = kRGBA_F16_SkColorType;
brianosmand93c1202016-03-10 07:49:08 -0800336 return true;
337 }
brianosman4562f6e2016-09-19 14:42:04 -0700338 if (commands[0].equals("srgb")) {
bsalomon33069252016-09-28 08:49:53 -0700339 *outColorType = kRGBA_8888_SkColorType;
brianosmand93c1202016-03-10 07:49:08 -0800340 return true;
341 }
342 return false;
343}
kkinnunen3e980c32015-12-23 01:33:00 -0800344
345SkCommandLineConfigGpu* parse_command_line_config_gpu(const SkString& tag,
346 const SkTArray<SkString>& vias,
347 const SkString& options) {
348 // Defaults for GPU backend.
349 bool seenAPI = false;
bsalomon85b4b532016-04-05 11:06:27 -0700350 SkCommandLineConfigGpu::ContextType contextType = GrContextFactory::kNativeGL_ContextType;
kkinnunen3e980c32015-12-23 01:33:00 -0800351 bool seenUseNVPR = false;
352 bool useNVPR = false;
csmartdaltone0d36292016-07-29 08:14:20 -0700353 bool seenUseInstanced = false;
354 bool useInstanced = false;
kkinnunen3e980c32015-12-23 01:33:00 -0800355 bool seenUseDIText =false;
356 bool useDIText = false;
357 bool seenSamples = false;
358 int samples = 0;
brianosmand93c1202016-03-10 07:49:08 -0800359 bool seenColor = false;
bsalomon33069252016-09-28 08:49:53 -0700360 SkColorType colorType = kRGBA_8888_SkColorType;
brianosmanb109b8c2016-06-16 13:03:24 -0700361 sk_sp<SkColorSpace> colorSpace = nullptr;
kkinnunen3e980c32015-12-23 01:33:00 -0800362
363 SkTArray<SkString> optionParts;
364 SkStrSplit(options.c_str(), ",", kStrict_SkStrSplitMode, &optionParts);
365 for (int i = 0; i < optionParts.count(); ++i) {
366 SkTArray<SkString> keyValueParts;
367 SkStrSplit(optionParts[i].c_str(), "=", kStrict_SkStrSplitMode, &keyValueParts);
368 if (keyValueParts.count() != 2) {
369 return nullptr;
370 }
371 const SkString& key = keyValueParts[0];
372 const SkString& value = keyValueParts[1];
373 bool valueOk = false;
374 if (key.equals("api") && !seenAPI) {
375 valueOk = parse_option_gpu_api(value, &contextType);
376 seenAPI = true;
377 } else if (key.equals("nvpr") && !seenUseNVPR) {
378 valueOk = parse_option_bool(value, &useNVPR);
379 seenUseNVPR = true;
csmartdaltone0d36292016-07-29 08:14:20 -0700380 } else if (key.equals("inst") && !seenUseInstanced) {
381 valueOk = parse_option_bool(value, &useInstanced);
382 seenUseInstanced = true;
kkinnunen3e980c32015-12-23 01:33:00 -0800383 } else if (key.equals("dit") && !seenUseDIText) {
384 valueOk = parse_option_bool(value, &useDIText);
385 seenUseDIText = true;
386 } else if (key.equals("samples") && !seenSamples) {
387 valueOk = parse_option_int(value, &samples);
388 seenSamples = true;
brianosmand93c1202016-03-10 07:49:08 -0800389 } else if (key.equals("color") && !seenColor) {
brianosmanb109b8c2016-06-16 13:03:24 -0700390 valueOk = parse_option_gpu_color(value, &colorType, &colorSpace);
brianosmand93c1202016-03-10 07:49:08 -0800391 seenColor = true;
kkinnunen3e980c32015-12-23 01:33:00 -0800392 }
393 if (!valueOk) {
394 return nullptr;
395 }
396 }
csmartdaltone0d36292016-07-29 08:14:20 -0700397 return new SkCommandLineConfigGpu(tag, vias, contextType, useNVPR, useInstanced, useDIText,
398 samples, colorType, colorSpace);
kkinnunen3e980c32015-12-23 01:33:00 -0800399}
400#endif
401
402void ParseConfigs(const SkCommandLineFlags::StringArray& configs,
403 SkCommandLineConfigArray* outResult) {
404 outResult->reset();
405 for (int i = 0; i < configs.count(); ++i) {
406 SkString extendedBackend;
407 SkString extendedOptions;
408 SkString simpleBackend;
409 SkTArray<SkString> vias;
410
411 SkString tag(configs[i]);
412 SkTArray<SkString> parts;
bsalomon808ecbb2016-09-28 12:40:22 -0700413 SkStrSplit(tag.c_str(), "[", kStrict_SkStrSplitMode, &parts);
kkinnunen3e980c32015-12-23 01:33:00 -0800414 if (parts.count() == 2) {
415 SkTArray<SkString> parts2;
bsalomon808ecbb2016-09-28 12:40:22 -0700416 SkStrSplit(parts[1].c_str(), "]", kStrict_SkStrSplitMode, &parts2);
kkinnunen3e980c32015-12-23 01:33:00 -0800417 if (parts2.count() == 2 && parts2[1].isEmpty()) {
418 SkStrSplit(parts[0].c_str(), "-", kStrict_SkStrSplitMode, &vias);
419 if (vias.count()) {
420 extendedBackend = vias[vias.count() - 1];
421 vias.pop_back();
422 } else {
423 extendedBackend = parts[0];
424 }
425 extendedOptions = parts2[0];
bsalomon808ecbb2016-09-28 12:40:22 -0700426 simpleBackend.printf("%s[%s]", extendedBackend.c_str(), extendedOptions.c_str());
kkinnunen3e980c32015-12-23 01:33:00 -0800427 }
428 }
429
430 if (extendedBackend.isEmpty()) {
431 simpleBackend = tag;
432 SkStrSplit(tag.c_str(), "-", kStrict_SkStrSplitMode, &vias);
433 if (vias.count()) {
434 simpleBackend = vias[vias.count() - 1];
435 vias.pop_back();
436 }
kkinnunen3e980c32015-12-23 01:33:00 -0800437 for (auto& predefinedConfig : gPredefinedConfigs) {
438 if (simpleBackend.equals(predefinedConfig.predefinedConfig)) {
439 extendedBackend = predefinedConfig.backend;
440 extendedOptions = predefinedConfig.options;
441 break;
442 }
443 }
444 }
445 SkCommandLineConfig* parsedConfig = nullptr;
446#if SK_SUPPORT_GPU
447 if (extendedBackend.equals("gpu")) {
448 parsedConfig = parse_command_line_config_gpu(tag, vias, extendedOptions);
449 }
450#endif
451 if (!parsedConfig) {
452 parsedConfig = new SkCommandLineConfig(tag, simpleBackend, vias);
453 }
454 outResult->emplace_back(parsedConfig);
455 }
456}