1 /*
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
8 #include "SkColorSpacePriv.h"
9 #include "SkCommonFlagsConfig.h"
10 #include "SkImageInfo.h"
11 #include "SkTHash.h"
12
13 #include <stdlib.h>
14
15 using sk_gpu_test::GrContextFactory;
16
17 #if defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_IOS)
18 # define DEFAULT_GPU_CONFIG "gles"
19 #else
20 # define DEFAULT_GPU_CONFIG "gl"
21 #endif
22
23 static const char defaultConfigs[] =
24 "8888 " DEFAULT_GPU_CONFIG " nonrendering "
25 #if defined(SK_BUILD_FOR_WIN)
26 " angle_d3d11_es2"
27 #endif
28 ;
29
30 #undef DEFAULT_GPU_CONFIG
31
32 // clang-format off
33 static const struct {
34 const char* predefinedConfig;
35 const char* backend;
36 const char* options;
37 } gPredefinedConfigs[] = {
38 { "gl", "gpu", "api=gl" },
39 { "gles", "gpu", "api=gles" },
40 { "glmsaa4", "gpu", "api=gl,samples=4" },
41 { "glmsaa8" , "gpu", "api=gl,samples=8" },
42 { "glesmsaa4", "gpu", "api=gles,samples=4" },
43 { "glnvpr4", "gpu", "api=gl,nvpr=true,samples=4" },
44 { "glnvpr8" , "gpu", "api=gl,nvpr=true,samples=8" },
45 { "glesnvpr4", "gpu", "api=gles,nvpr=true,samples=4" },
46 { "glbetex", "gpu", "api=gl,surf=betex" },
47 { "glesbetex", "gpu", "api=gles,surf=betex" },
48 { "glbert", "gpu", "api=gl,surf=bert" },
49 { "glesbert", "gpu", "api=gles,surf=bert" },
50 { "gl4444", "gpu", "api=gl,color=4444" },
51 { "gles4444", "gpu", "api=gles,color=4444" },
52 { "gl565", "gpu", "api=gl,color=565" },
53 { "gl888x", "gpu", "api=gl,color=888x" },
54 { "gles888x", "gpu", "api=gles,color=888x" },
55 { "gl1010102", "gpu", "api=gl,color=1010102" },
56 { "gles1010102", "gpu", "api=gles,color=1010102" },
57 { "glsrgb", "gpu", "api=gl,color=srgb" },
58 { "glp3", "gpu", "api=gl,color=p3" },
59 { "glesrgb", "gpu", "api=gl,color=esrgb" },
60 { "glnarrow", "gpu", "api=gl,color=narrow" },
61 { "glenarrow", "gpu", "api=gl,color=enarrow" },
62 { "glf16", "gpu", "api=gl,color=f16" },
63 { "glf16norm", "gpu", "api=gl,color=f16norm" },
64 { "glessrgb", "gpu", "api=gles,color=srgb" },
65 { "glesesrgb", "gpu", "api=gles,color=esrgb" },
66 { "glesnarrow", "gpu", "api=gles,color=narrow" },
67 { "glesenarrow", "gpu", "api=gles,color=enarrow" },
68 { "glesf16", "gpu", "api=gles,color=f16" },
69 { "glnostencils", "gpu", "api=gl,stencils=false" },
70 { "gldft", "gpu", "api=gl,dit=true" },
71 { "glesdft", "gpu", "api=gles,dit=true" },
72 { "gltestthreading", "gpu", "api=gl,testThreading=true" },
73 { "gltestpersistentcache", "gpu", "api=gl,testPersistentCache=true" },
74 { "nullgl", "gpu", "api=nullgl" },
75 { "angle_d3d11_es2", "gpu", "api=angle_d3d11_es2" },
76 { "angle_d3d11_es3", "gpu", "api=angle_d3d11_es3" },
77 { "angle_d3d9_es2", "gpu", "api=angle_d3d9_es2" },
78 { "angle_d3d11_es2_msaa4", "gpu", "api=angle_d3d11_es2,samples=4" },
79 { "angle_d3d11_es2_msaa8", "gpu", "api=angle_d3d11_es2,samples=8" },
80 { "angle_d3d11_es3_msaa4", "gpu", "api=angle_d3d11_es3,samples=4" },
81 { "angle_d3d11_es3_msaa8", "gpu", "api=angle_d3d11_es3,samples=8" },
82 { "angle_gl_es2", "gpu", "api=angle_gl_es2" },
83 { "angle_gl_es3", "gpu", "api=angle_gl_es3" },
84 { "angle_gl_es2_msaa8", "gpu", "api=angle_gl_es2,samples=8" },
85 { "angle_gl_es3_msaa8", "gpu", "api=angle_gl_es3,samples=8" },
86 { "commandbuffer", "gpu", "api=commandbuffer" },
87 { "mock", "gpu", "api=mock" },
88 #ifdef SK_VULKAN
89 { "vk", "gpu", "api=vulkan" },
90 { "vknostencils", "gpu", "api=vulkan,stencils=false" },
91 { "vk1010102", "gpu", "api=vulkan,color=1010102" },
92 { "vksrgb", "gpu", "api=vulkan,color=srgb" },
93 { "vkesrgb", "gpu", "api=vulkan,color=esrgb" },
94 { "vknarrow", "gpu", "api=vulkan,color=narrow" },
95 { "vkenarrow", "gpu", "api=vulkan,color=enarrow" },
96 { "vkf16", "gpu", "api=vulkan,color=f16" },
97 { "vkmsaa4", "gpu", "api=vulkan,samples=4" },
98 { "vkmsaa8", "gpu", "api=vulkan,samples=8" },
99 { "vkbetex", "gpu", "api=vulkan,surf=betex" },
100 { "vkbert", "gpu", "api=vulkan,surf=bert" },
101 { "vktestpersistentcache", "gpu", "api=vulkan,testPersistentCache=true" },
102 #endif
103 #ifdef SK_METAL
104 { "mtl", "gpu", "api=metal" },
105 { "mtl1010102", "gpu", "api=metal,color=1010102" },
106 { "mtlmsaa4", "gpu", "api=metal,samples=4" },
107 { "mtlmsaa8", "gpu", "api=metal,samples=8" },
108 #endif
109 };
110 // clang-format on
111
112 static const char configHelp[] =
113 "Options: 565 8888 srgb f16 nonrendering null pdf pdfa skp pipe svg xps";
114
config_help_fn()115 static const char* config_help_fn() {
116 static SkString helpString;
117 helpString.set(configHelp);
118 for (const auto& config : gPredefinedConfigs) {
119 helpString.appendf(" %s", config.predefinedConfig);
120 }
121 helpString.append(" or use extended form 'backend[option=value,...]'.\n");
122 return helpString.c_str();
123 }
124
125 static const char configExtendedHelp[] =
126 "Extended form: 'backend(option=value,...)'\n\n"
127 "Possible backends and options:\n"
128 "\n"
129 "gpu[api=string,color=string,dit=bool,nvpr=bool,inst=bool,samples=int]\n"
130 "\tapi\ttype: string\trequired\n"
131 "\t Select graphics API to use with gpu backend.\n"
132 "\t Options:\n"
133 "\t\tgl \t\t\tUse OpenGL.\n"
134 "\t\tgles \t\t\tUse OpenGL ES.\n"
135 "\t\tnullgl \t\t\tUse null OpenGL.\n"
136 "\t\tangle_d3d9_es2\t\tUse OpenGL ES2 on the ANGLE Direct3D9 backend.\n"
137 "\t\tangle_d3d11_es2\t\tUse OpenGL ES2 on the ANGLE Direct3D11 backend.\n"
138 "\t\tangle_d3d11_es3\t\tUse OpenGL ES3 on the ANGLE Direct3D11 backend.\n"
139 "\t\tangle_gl_es2\t\tUse OpenGL ES2 on the ANGLE OpenGL backend.\n"
140 "\t\tangle_gl_es3\t\tUse OpenGL ES3 on the ANGLE OpenGL backend.\n"
141 "\t\tcommandbuffer\t\tUse command buffer.\n"
142 "\t\tmock\t\t\tUse mock context.\n"
143 #ifdef SK_VULKAN
144 "\t\tvulkan\t\t\tUse Vulkan.\n"
145 #endif
146 #ifdef SK_METAL
147 "\t\tmetal\t\t\tUse Metal.\n"
148 #endif
149 "\tcolor\ttype: string\tdefault: 8888.\n"
150 "\t Select framebuffer color format.\n"
151 "\t Options:\n"
152 "\t\t8888\t\t\tLinear 8888.\n"
153 "\t\t888x\t\t\tLinear 888x.\n"
154 "\t\t4444\t\t\tLinear 4444.\n"
155 "\t\t565\t\t\tLinear 565.\n"
156 "\t\t1010102\t\t\tLinear 1010102.\n"
157 "\t\tsrgb\t\t\tsRGB 8888.\n"
158 "\t\tesrgb\t\t\tsRGB 16-bit floating point.\n"
159 "\t\tnarrow\t\t\tNarrow gamut 8888.\n"
160 "\t\tenarrow\t\t\tNarrow gamut 16-bit floating point.\n"
161 "\t\tf16\t\t\tLinearly blended 16-bit floating point.\n"
162 "\tdit\ttype: bool\tdefault: false.\n"
163 "\t Use device independent text.\n"
164 "\tnvpr\ttype: bool\tdefault: false.\n"
165 "\t Use NV_path_rendering OpenGL and OpenGL ES extension.\n"
166 "\tsamples\ttype: int\tdefault: 0.\n"
167 "\t Use multisampling with N samples.\n"
168 "\tstencils\ttype: bool\tdefault: true.\n"
169 "\t Allow the use of stencil buffers.\n"
170 "\ttestThreading\ttype: bool\tdefault: false.\n"
171 "\t Run with and without worker threads, check that results match.\n"
172 "\ttestPersistentCache\ttype: bool\tdefault: false.\n"
173 "\t Run using a pre-warmed GrContextOption::fPersistentCache.\n"
174 "\tsurf\ttype: string\tdefault: default.\n"
175 "\t Controls the type of backing store for SkSurfaces.\n"
176 "\t Options:\n"
177 "\t\tdefault\t\t\tA renderable texture created in Skia's resource cache.\n"
178 "\t\tbetex\t\t\tA wrapped backend texture.\n"
179 "\t\tbert\t\t\tA wrapped backend render target\n"
180 "\n"
181 "Predefined configs:\n\n"
182 // Help text for pre-defined configs is auto-generated from gPredefinedConfigs
183 ;
184
config_extended_help_fn()185 static const char* config_extended_help_fn() {
186 static SkString helpString;
187 helpString.set(configExtendedHelp);
188 for (const auto& config : gPredefinedConfigs) {
189 helpString.appendf("\t%-10s\t= gpu(%s)\n", config.predefinedConfig, config.options);
190 }
191 return helpString.c_str();
192 }
193
194 DEFINE_extended_string(config, defaultConfigs, config_help_fn(), config_extended_help_fn());
195
SkCommandLineConfig(const SkString & tag,const SkString & backend,const SkTArray<SkString> & viaParts)196 SkCommandLineConfig::SkCommandLineConfig(const SkString& tag, const SkString& backend,
197 const SkTArray<SkString>& viaParts)
198 : fTag(tag)
199 , fBackend(backend)
200 , fViaParts(viaParts) {
201 }
~SkCommandLineConfig()202 SkCommandLineConfig::~SkCommandLineConfig() {
203 }
204
parse_option_int(const SkString & value,int * outInt)205 static bool parse_option_int(const SkString& value, int* outInt) {
206 if (value.isEmpty()) {
207 return false;
208 }
209 char* endptr = nullptr;
210 long intValue = strtol(value.c_str(), &endptr, 10);
211 if (*endptr != '\0') {
212 return false;
213 }
214 *outInt = static_cast<int>(intValue);
215 return true;
216 }
parse_option_bool(const SkString & value,bool * outBool)217 static bool parse_option_bool(const SkString& value, bool* outBool) {
218 if (value.equals("true")) {
219 *outBool = true;
220 return true;
221 }
222 if (value.equals("false")) {
223 *outBool = false;
224 return true;
225 }
226 return false;
227 }
parse_option_gpu_api(const SkString & value,SkCommandLineConfigGpu::ContextType * outContextType)228 static bool parse_option_gpu_api(const SkString& value,
229 SkCommandLineConfigGpu::ContextType* outContextType) {
230 if (value.equals("gl")) {
231 *outContextType = GrContextFactory::kGL_ContextType;
232 return true;
233 }
234 if (value.equals("gles")) {
235 *outContextType = GrContextFactory::kGLES_ContextType;
236 return true;
237 }
238 if (value.equals("nullgl")) {
239 *outContextType = GrContextFactory::kNullGL_ContextType;
240 return true;
241 }
242 if (value.equals("angle_d3d9_es2")) {
243 *outContextType = GrContextFactory::kANGLE_D3D9_ES2_ContextType;
244 return true;
245 }
246 if (value.equals("angle_d3d11_es2")) {
247 *outContextType = GrContextFactory::kANGLE_D3D11_ES2_ContextType;
248 return true;
249 }
250 if (value.equals("angle_d3d11_es3")) {
251 *outContextType = GrContextFactory::kANGLE_D3D11_ES3_ContextType;
252 return true;
253 }
254 if (value.equals("angle_gl_es2")) {
255 *outContextType = GrContextFactory::kANGLE_GL_ES2_ContextType;
256 return true;
257 }
258 if (value.equals("angle_gl_es3")) {
259 *outContextType = GrContextFactory::kANGLE_GL_ES3_ContextType;
260 return true;
261 }
262 if (value.equals("commandbuffer")) {
263 *outContextType = GrContextFactory::kCommandBuffer_ContextType;
264 return true;
265 }
266 if (value.equals("mock")) {
267 *outContextType = GrContextFactory::kMock_ContextType;
268 return true;
269 }
270 #ifdef SK_VULKAN
271 if (value.equals("vulkan")) {
272 *outContextType = GrContextFactory::kVulkan_ContextType;
273 return true;
274 }
275 #endif
276 #ifdef SK_METAL
277 if (value.equals("metal")) {
278 *outContextType = GrContextFactory::kMetal_ContextType;
279 return true;
280 }
281 #endif
282 return false;
283 }
284
parse_option_gpu_color(const SkString & value,SkColorType * outColorType,SkAlphaType * alphaType,sk_sp<SkColorSpace> * outColorSpace)285 static bool parse_option_gpu_color(const SkString& value,
286 SkColorType* outColorType,
287 SkAlphaType* alphaType,
288 sk_sp<SkColorSpace>* outColorSpace) {
289 // We always use premul unless the color type is 565.
290 *alphaType = kPremul_SkAlphaType;
291
292 if (value.equals("8888")) {
293 *outColorType = kRGBA_8888_SkColorType;
294 *outColorSpace = nullptr;
295 } else if (value.equals("888x")) {
296 *outColorType = kRGB_888x_SkColorType;
297 *outColorSpace = nullptr;
298 } else if (value.equals("4444")) {
299 *outColorType = kARGB_4444_SkColorType;
300 *outColorSpace = nullptr;
301 } else if (value.equals("565")) {
302 *outColorType = kRGB_565_SkColorType;
303 *alphaType = kOpaque_SkAlphaType;
304 *outColorSpace = nullptr;
305 } else if (value.equals("1010102")) {
306 *outColorType = kRGBA_1010102_SkColorType;
307 *outColorSpace = nullptr;
308 } else if (value.equals("srgb")) {
309 *outColorType = kRGBA_8888_SkColorType;
310 *outColorSpace = SkColorSpace::MakeSRGB();
311 } else if (value.equals("p3")) {
312 *outColorType = kRGBA_8888_SkColorType;
313 *outColorSpace = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDCIP3);
314 } else if (value.equals("esrgb")) {
315 *outColorType = kRGBA_F16_SkColorType;
316 *outColorSpace = SkColorSpace::MakeSRGB();
317 } else if (value.equals("narrow") || value.equals("enarrow")) {
318 *outColorType = value.equals("narrow") ? kRGBA_8888_SkColorType : kRGBA_F16_SkColorType;
319 *outColorSpace = SkColorSpace::MakeRGB(SkNamedTransferFn::k2Dot2, gNarrow_toXYZD50);
320 } else if (value.equals("f16")) {
321 *outColorType = kRGBA_F16_SkColorType;
322 *outColorSpace = SkColorSpace::MakeSRGBLinear();
323 } else if (value.equals("f16norm")) {
324 *outColorType = kRGBA_F16Norm_SkColorType;
325 *outColorSpace = SkColorSpace::MakeSRGB();
326 } else {
327 return false;
328 }
329 return true;
330 }
331
parse_option_gpu_surf_type(const SkString & value,SkCommandLineConfigGpu::SurfType * surfType)332 static bool parse_option_gpu_surf_type(const SkString& value,
333 SkCommandLineConfigGpu::SurfType* surfType) {
334 if (value.equals("default")) {
335 *surfType = SkCommandLineConfigGpu::SurfType::kDefault;
336 return true;
337 }
338 if (value.equals("betex")) {
339 *surfType = SkCommandLineConfigGpu::SurfType::kBackendTexture;
340 return true;
341 }
342 if (value.equals("bert")) {
343 *surfType = SkCommandLineConfigGpu::SurfType::kBackendRenderTarget;
344 return true;
345 }
346 return false;
347 }
348
349 // Extended options take form --config item[key1=value1,key2=value2,...]
350 // Example: --config gpu[api=gl,color=8888]
351 class ExtendedOptions {
352 public:
ExtendedOptions(const SkString & optionsString,bool * outParseSucceeded)353 ExtendedOptions(const SkString& optionsString, bool* outParseSucceeded) {
354 SkTArray<SkString> optionParts;
355 SkStrSplit(optionsString.c_str(), ",", kStrict_SkStrSplitMode, &optionParts);
356 for (int i = 0; i < optionParts.count(); ++i) {
357 SkTArray<SkString> keyValueParts;
358 SkStrSplit(optionParts[i].c_str(), "=", kStrict_SkStrSplitMode, &keyValueParts);
359 if (keyValueParts.count() != 2) {
360 *outParseSucceeded = false;
361 return;
362 }
363 const SkString& key = keyValueParts[0];
364 const SkString& value = keyValueParts[1];
365 if (fOptionsMap.find(key) == nullptr) {
366 fOptionsMap.set(key, value);
367 } else {
368 // Duplicate values are not allowed.
369 *outParseSucceeded = false;
370 return;
371 }
372 }
373 *outParseSucceeded = true;
374 }
375
get_option_gpu_color(const char * optionKey,SkColorType * outColorType,SkAlphaType * alphaType,sk_sp<SkColorSpace> * outColorSpace,bool optional=true) const376 bool get_option_gpu_color(const char* optionKey,
377 SkColorType* outColorType,
378 SkAlphaType* alphaType,
379 sk_sp<SkColorSpace>* outColorSpace,
380 bool optional = true) const {
381 SkString* optionValue = fOptionsMap.find(SkString(optionKey));
382 if (optionValue == nullptr) {
383 return optional;
384 }
385 return parse_option_gpu_color(*optionValue, outColorType, alphaType, outColorSpace);
386 }
387
get_option_gpu_api(const char * optionKey,SkCommandLineConfigGpu::ContextType * outContextType,bool optional=true) const388 bool get_option_gpu_api(const char* optionKey,
389 SkCommandLineConfigGpu::ContextType* outContextType,
390 bool optional = true) const {
391 SkString* optionValue = fOptionsMap.find(SkString(optionKey));
392 if (optionValue == nullptr) {
393 return optional;
394 }
395 return parse_option_gpu_api(*optionValue, outContextType);
396 }
397
get_option_gpu_surf_type(const char * optionKey,SkCommandLineConfigGpu::SurfType * outSurfType,bool optional=true) const398 bool get_option_gpu_surf_type(const char* optionKey,
399 SkCommandLineConfigGpu::SurfType* outSurfType,
400 bool optional = true) const {
401 SkString* optionValue = fOptionsMap.find(SkString(optionKey));
402 if (optionValue == nullptr) {
403 return optional;
404 }
405 return parse_option_gpu_surf_type(*optionValue, outSurfType);
406 }
407
get_option_int(const char * optionKey,int * outInt,bool optional=true) const408 bool get_option_int(const char* optionKey, int* outInt, bool optional = true) const {
409 SkString* optionValue = fOptionsMap.find(SkString(optionKey));
410 if (optionValue == nullptr) {
411 return optional;
412 }
413 return parse_option_int(*optionValue, outInt);
414 }
415
get_option_bool(const char * optionKey,bool * outBool,bool optional=true) const416 bool get_option_bool(const char* optionKey, bool* outBool, bool optional = true) const {
417 SkString* optionValue = fOptionsMap.find(SkString(optionKey));
418 if (optionValue == nullptr) {
419 return optional;
420 }
421 return parse_option_bool(*optionValue, outBool);
422 }
423
424 private:
425 SkTHashMap<SkString, SkString> fOptionsMap;
426 };
427
SkCommandLineConfigGpu(const SkString & tag,const SkTArray<SkString> & viaParts,ContextType contextType,bool useNVPR,bool useDIText,int samples,SkColorType colorType,SkAlphaType alphaType,sk_sp<SkColorSpace> colorSpace,bool useStencilBuffers,bool testThreading,bool testPersistentCache,SurfType surfType)428 SkCommandLineConfigGpu::SkCommandLineConfigGpu(
429 const SkString& tag, const SkTArray<SkString>& viaParts, ContextType contextType,
430 bool useNVPR, bool useDIText, int samples, SkColorType colorType, SkAlphaType alphaType,
431 sk_sp<SkColorSpace> colorSpace, bool useStencilBuffers, bool testThreading,
432 bool testPersistentCache, SurfType surfType)
433 : SkCommandLineConfig(tag, SkString("gpu"), viaParts)
434 , fContextType(contextType)
435 , fContextOverrides(ContextOverrides::kNone)
436 , fUseDIText(useDIText)
437 , fSamples(samples)
438 , fColorType(colorType)
439 , fAlphaType(alphaType)
440 , fColorSpace(std::move(colorSpace))
441 , fTestThreading(testThreading)
442 , fTestPersistentCache(testPersistentCache)
443 , fSurfType(surfType) {
444 if (useNVPR) {
445 fContextOverrides |= ContextOverrides::kRequireNVPRSupport;
446 } else {
447 // We don't disable NVPR for instanced configs. Otherwise the caps wouldn't use mixed
448 // samples and we couldn't test the mixed samples backend for simple shapes.
449 fContextOverrides |= ContextOverrides::kDisableNVPR;
450 }
451 if (!useStencilBuffers) {
452 fContextOverrides |= ContextOverrides::kAvoidStencilBuffers;
453 }
454 }
455
parse_command_line_config_gpu(const SkString & tag,const SkTArray<SkString> & vias,const SkString & options)456 SkCommandLineConfigGpu* parse_command_line_config_gpu(const SkString& tag,
457 const SkTArray<SkString>& vias,
458 const SkString& options) {
459 // Defaults for GPU backend.
460 SkCommandLineConfigGpu::ContextType contextType = GrContextFactory::kGL_ContextType;
461 bool useNVPR = false;
462 bool useDIText = false;
463 int samples = 1;
464 SkColorType colorType = kRGBA_8888_SkColorType;
465 SkAlphaType alphaType = kPremul_SkAlphaType;
466 sk_sp<SkColorSpace> colorSpace = nullptr;
467 bool useStencils = true;
468 bool testThreading = false;
469 bool testPersistentCache = false;
470 SkCommandLineConfigGpu::SurfType surfType = SkCommandLineConfigGpu::SurfType::kDefault;
471
472 bool parseSucceeded = false;
473 ExtendedOptions extendedOptions(options, &parseSucceeded);
474 if (!parseSucceeded) {
475 return nullptr;
476 }
477
478 bool validOptions =
479 extendedOptions.get_option_gpu_api("api", &contextType, false) &&
480 extendedOptions.get_option_bool("nvpr", &useNVPR) &&
481 extendedOptions.get_option_bool("dit", &useDIText) &&
482 extendedOptions.get_option_int("samples", &samples) &&
483 extendedOptions.get_option_gpu_color("color", &colorType, &alphaType, &colorSpace) &&
484 extendedOptions.get_option_bool("stencils", &useStencils) &&
485 extendedOptions.get_option_bool("testThreading", &testThreading) &&
486 extendedOptions.get_option_bool("testPersistentCache", &testPersistentCache) &&
487 extendedOptions.get_option_gpu_surf_type("surf", &surfType);
488
489 // testing threading and the persistent cache are mutually exclusive.
490 if (!validOptions || (testThreading && testPersistentCache)) {
491 return nullptr;
492 }
493
494 return new SkCommandLineConfigGpu(tag, vias, contextType, useNVPR, useDIText, samples,
495 colorType, alphaType, colorSpace, useStencils, testThreading,
496 testPersistentCache, surfType);
497 }
498
SkCommandLineConfigSvg(const SkString & tag,const SkTArray<SkString> & viaParts,int pageIndex)499 SkCommandLineConfigSvg::SkCommandLineConfigSvg(const SkString& tag,
500 const SkTArray<SkString>& viaParts, int pageIndex)
501 : SkCommandLineConfig(tag, SkString("svg"), viaParts), fPageIndex(pageIndex) {}
502
parse_command_line_config_svg(const SkString & tag,const SkTArray<SkString> & vias,const SkString & options)503 SkCommandLineConfigSvg* parse_command_line_config_svg(const SkString& tag,
504 const SkTArray<SkString>& vias,
505 const SkString& options) {
506 // Defaults for SVG backend.
507 int pageIndex = 0;
508
509 bool parseSucceeded = false;
510 ExtendedOptions extendedOptions(options, &parseSucceeded);
511 if (!parseSucceeded) {
512 return nullptr;
513 }
514
515 bool validOptions = extendedOptions.get_option_int("page", &pageIndex);
516
517 if (!validOptions) {
518 return nullptr;
519 }
520
521 return new SkCommandLineConfigSvg(tag, vias, pageIndex);
522 }
523
ParseConfigs(const SkCommandLineFlags::StringArray & configs,SkCommandLineConfigArray * outResult)524 void ParseConfigs(const SkCommandLineFlags::StringArray& configs,
525 SkCommandLineConfigArray* outResult) {
526 outResult->reset();
527 for (int i = 0; i < configs.count(); ++i) {
528 SkString extendedBackend;
529 SkString extendedOptions;
530 SkString simpleBackend;
531 SkTArray<SkString> vias;
532
533 SkString tag(configs[i]);
534 SkTArray<SkString> parts;
535 SkStrSplit(tag.c_str(), "[", kStrict_SkStrSplitMode, &parts);
536 if (parts.count() == 2) {
537 SkTArray<SkString> parts2;
538 SkStrSplit(parts[1].c_str(), "]", kStrict_SkStrSplitMode, &parts2);
539 if (parts2.count() == 2 && parts2[1].isEmpty()) {
540 SkStrSplit(parts[0].c_str(), "-", kStrict_SkStrSplitMode, &vias);
541 if (vias.count()) {
542 extendedBackend = vias[vias.count() - 1];
543 vias.pop_back();
544 } else {
545 extendedBackend = parts[0];
546 }
547 extendedOptions = parts2[0];
548 simpleBackend.printf("%s[%s]", extendedBackend.c_str(), extendedOptions.c_str());
549 }
550 }
551
552 if (extendedBackend.isEmpty()) {
553 simpleBackend = tag;
554 SkStrSplit(tag.c_str(), "-", kStrict_SkStrSplitMode, &vias);
555 if (vias.count()) {
556 simpleBackend = vias[vias.count() - 1];
557 vias.pop_back();
558 }
559 for (auto& predefinedConfig : gPredefinedConfigs) {
560 if (simpleBackend.equals(predefinedConfig.predefinedConfig)) {
561 extendedBackend = predefinedConfig.backend;
562 extendedOptions = predefinedConfig.options;
563 break;
564 }
565 }
566 }
567 SkCommandLineConfig* parsedConfig = nullptr;
568 if (extendedBackend.equals("gpu")) {
569 parsedConfig = parse_command_line_config_gpu(tag, vias, extendedOptions);
570 }
571 if (extendedBackend.equals("svg")) {
572 parsedConfig = parse_command_line_config_svg(tag, vias, extendedOptions);
573 }
574 if (!parsedConfig) {
575 parsedConfig = new SkCommandLineConfig(tag, simpleBackend, vias);
576 }
577 outResult->emplace_back(parsedConfig);
578 }
579 }
580