blob: ec69235ccca23c921d9e1e0d8d2eadca49e8054d [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
Mike Klein33384822018-01-26 13:58:24 -05008#include "SkColorSpace.h"
kkinnunen3e980c32015-12-23 01:33:00 -08009#include "SkCommonFlagsConfig.h"
10#include "Test.h"
11#include <initializer_list>
12
bsalomon3724e572016-03-30 18:56:19 -070013using sk_gpu_test::GrContextFactory;
14
kkinnunen3e980c32015-12-23 01:33:00 -080015namespace {
16// The code
17// SkCommandLineFlags::StringArray FLAGS_config1 = make_string_array({"a", "b"})
18// can be used to construct string array that one gets with command line flags.
19// For example, the call above is equivalent of
20// DEFINE_string(config1, "a b", "");
21// in cases where the default command line flag value ("a b") is used.
22// make_string_array can be used to construct StringArray strings that have spaces in
23// them.
24SkCommandLineFlags::StringArray make_string_array(std::initializer_list<const char*> strings) {
25 SkTArray<SkString> array;
26 for (auto& s : strings) {
27 array.push_back(SkString(s));
28 }
29 return SkCommandLineFlags::StringArray(array);
30}
31}
32DEF_TEST(ParseConfigs_Gpu, reporter) {
33 // Parses a normal config and returns correct "tag".
Brian Salomon6405e712017-03-20 08:54:16 -040034 // Simple GL config works
35 SkCommandLineFlags::StringArray config1 = make_string_array({"gl"});
kkinnunen3e980c32015-12-23 01:33:00 -080036 SkCommandLineConfigArray configs;
37 ParseConfigs(config1, &configs);
38
39 REPORTER_ASSERT(reporter, configs.count() == 1);
Brian Salomon6405e712017-03-20 08:54:16 -040040 REPORTER_ASSERT(reporter, configs[0]->getTag().equals("gl"));
kkinnunen3e980c32015-12-23 01:33:00 -080041 REPORTER_ASSERT(reporter, configs[0]->getViaParts().count() == 0);
42#if SK_SUPPORT_GPU
43 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu());
44 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getContextType()
Brian Salomon6405e712017-03-20 08:54:16 -040045 == GrContextFactory::kGL_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -080046 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseNVPR() == false);
47 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseDIText() == false);
Brian Salomonbdecacf2018-02-02 20:32:49 -050048 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSamples() == 1);
bsalomon33069252016-09-28 08:49:53 -070049 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getColorType() == kRGBA_8888_SkColorType);
brianosmanb109b8c2016-06-16 13:03:24 -070050 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getColorSpace() == nullptr);
kkinnunen3e980c32015-12-23 01:33:00 -080051#endif
52}
53
54DEF_TEST(ParseConfigs_OutParam, reporter) {
55 // Clears the out parameter.
Brian Salomon6405e712017-03-20 08:54:16 -040056 SkCommandLineFlags::StringArray config1 = make_string_array({"gles"});
kkinnunen3e980c32015-12-23 01:33:00 -080057 SkCommandLineConfigArray configs;
58 ParseConfigs(config1, &configs);
59 REPORTER_ASSERT(reporter, configs.count() == 1);
Brian Salomon6405e712017-03-20 08:54:16 -040060 REPORTER_ASSERT(reporter, configs[0]->getTag().equals("gles"));
bsalomonb8797bb2016-04-05 08:49:38 -070061
kkinnunen3e980c32015-12-23 01:33:00 -080062 SkCommandLineFlags::StringArray config2 = make_string_array({"8888"});
63 ParseConfigs(config2, &configs);
64 REPORTER_ASSERT(reporter, configs.count() == 1);
65 REPORTER_ASSERT(reporter, configs[0]->getTag().equals("8888"));
bsalomonb8797bb2016-04-05 08:49:38 -070066
67 SkCommandLineFlags::StringArray config3 = make_string_array({"gl"});
68 ParseConfigs(config3, &configs);
69 REPORTER_ASSERT(reporter, configs.count() == 1);
70 REPORTER_ASSERT(reporter, configs[0]->getTag().equals("gl"));
kkinnunen3e980c32015-12-23 01:33:00 -080071}
72
73DEF_TEST(ParseConfigs_DefaultConfigs, reporter) {
74 // Parses all default configs and returns correct "tag".
75
76 SkCommandLineFlags::StringArray config1 = make_string_array({
Brian Salomon8fe24272017-07-07 12:56:11 -040077 "565",
78 "8888",
79 "debuggl",
80 "gl",
81 "gldft",
82 "nullgl",
83 "glmsaa8",
84 "glmsaa4",
85 "nonrendering",
86 "nullgl",
87 "gles",
88 "glnvpr8",
89 "glnvpr4",
Brian Salomon8fe24272017-07-07 12:56:11 -040090 "pdf",
91 "skp",
92 "svg",
93 "xps",
94 "angle_d3d11_es2",
95 "angle_gl_es2",
96 "commandbuffer",
97 "mesa",
98 "hwui",
99 "glf16",
100 "glessrgb",
101 "gl",
102 "glnvpr4",
Brian Salomon8fe24272017-07-07 12:56:11 -0400103 "glsrgb",
104 "glmsaa4",
105 "vk",
Brian Salomon8fe24272017-07-07 12:56:11 -0400106 "glwide",
107 "glnarrow",
108 "glnostencils",
Greg Daniel2811aa22017-07-13 15:34:56 -0400109 "mock",
Brian Salomonce5ee602017-07-17 11:31:31 -0400110 "mtl",
111 "gl4444",
Brian Osmanf9810662017-08-30 10:02:10 -0400112 "gl565",
113 "gltestthreading"
kkinnunen3e980c32015-12-23 01:33:00 -0800114 });
115
116 SkCommandLineConfigArray configs;
117 ParseConfigs(config1, &configs);
118
Matt Sarett77a7a1b2017-02-07 13:56:11 -0500119 auto srgbColorSpace = SkColorSpace::MakeSRGB();
brianosmanb109b8c2016-06-16 13:03:24 -0700120
kkinnunen3e980c32015-12-23 01:33:00 -0800121 REPORTER_ASSERT(reporter, configs.count() == config1.count());
122 for (int i = 0; i < config1.count(); ++i) {
123 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
124 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == 0);
125 }
126#if SK_SUPPORT_GPU
127 REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu());
128 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu());
129 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu());
130 REPORTER_ASSERT(reporter, configs[3]->asConfigGpu());
Brian Salomon6405e712017-03-20 08:54:16 -0400131 REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()->getUseDIText());
132 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu());
Brian Salomondcf0ab02017-03-20 11:10:21 -0400133 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getSamples() == 8);
Brian Salomon6405e712017-03-20 08:54:16 -0400134 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 4);
135 REPORTER_ASSERT(reporter, !configs[8]->asConfigGpu());
136 REPORTER_ASSERT(reporter, configs[9]->asConfigGpu());
137 REPORTER_ASSERT(reporter, configs[10]->asConfigGpu());
Brian Salomondcf0ab02017-03-20 11:10:21 -0400138 REPORTER_ASSERT(reporter, configs[11]->asConfigGpu()->getSamples() == 8);
Brian Salomon6405e712017-03-20 08:54:16 -0400139 REPORTER_ASSERT(reporter, configs[11]->asConfigGpu()->getUseNVPR());
140 REPORTER_ASSERT(reporter, !configs[11]->asConfigGpu()->getUseDIText());
141 REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getSamples() == 4);
kkinnunen3e980c32015-12-23 01:33:00 -0800142 REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getUseNVPR());
cdaltonc28afdb2016-03-29 20:05:07 -0700143 REPORTER_ASSERT(reporter, !configs[12]->asConfigGpu()->getUseDIText());
Robert Phillips0b33cc42018-02-08 08:29:21 -0500144 REPORTER_ASSERT(reporter, !configs[13]->asConfigGpu());
145 REPORTER_ASSERT(reporter, !configs[14]->asConfigGpu());
Brian Salomon6405e712017-03-20 08:54:16 -0400146 REPORTER_ASSERT(reporter, !configs[15]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800147 REPORTER_ASSERT(reporter, !configs[16]->asConfigGpu());
Robert Phillips0b33cc42018-02-08 08:29:21 -0500148 REPORTER_ASSERT(reporter, configs[17]->asConfigGpu());
149 REPORTER_ASSERT(reporter, configs[18]->asConfigGpu());
150 REPORTER_ASSERT(reporter, configs[19]->asConfigGpu());
151 REPORTER_ASSERT(reporter, !configs[20]->asConfigGpu());
152 REPORTER_ASSERT(reporter, !configs[21]->asConfigGpu());
153 REPORTER_ASSERT(reporter, configs[22]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType);
154 REPORTER_ASSERT(reporter, configs[22]->asConfigGpu()->getColorSpace());
155 REPORTER_ASSERT(reporter, configs[22]->asConfigGpu()->getColorSpace()->gammaIsLinear());
Brian Osman36703d92017-12-12 14:09:31 -0500156 const SkMatrix44* srgbXYZ = srgbColorSpace->toXYZD50();
raftias94888332016-10-18 10:02:51 -0700157 SkASSERT(srgbXYZ);
Robert Phillips0b33cc42018-02-08 08:29:21 -0500158 const SkMatrix44* config25XYZ = configs[22]->asConfigGpu()->getColorSpace()->toXYZD50();
raftias94888332016-10-18 10:02:51 -0700159 SkASSERT(config25XYZ);
160 REPORTER_ASSERT(reporter, *config25XYZ == *srgbXYZ);
Robert Phillips0b33cc42018-02-08 08:29:21 -0500161 REPORTER_ASSERT(reporter, configs[23]->asConfigGpu()->getColorType() == kRGBA_8888_SkColorType);
162 REPORTER_ASSERT(reporter, configs[23]->asConfigGpu()->getColorSpace() == srgbColorSpace.get());
163 REPORTER_ASSERT(reporter, configs[24]->asConfigGpu());
164 REPORTER_ASSERT(reporter, configs[25]->asConfigGpu());
165 REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getSamples() == 4);
166 REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getUseNVPR());
Brian Salomon6405e712017-03-20 08:54:16 -0400167 REPORTER_ASSERT(reporter, configs[26]->asConfigGpu());
Robert Phillips0b33cc42018-02-08 08:29:21 -0500168 REPORTER_ASSERT(reporter, configs[26]->asConfigGpu()->getColorType() == kRGBA_8888_SkColorType);
169 REPORTER_ASSERT(reporter, configs[26]->asConfigGpu()->getColorSpace() == srgbColorSpace.get());
bsalomonb8797bb2016-04-05 08:49:38 -0700170 REPORTER_ASSERT(reporter, configs[27]->asConfigGpu());
Brian Salomon6405e712017-03-20 08:54:16 -0400171 REPORTER_ASSERT(reporter, configs[27]->asConfigGpu()->getSamples() == 4);
bsalomondc0fcd42016-04-11 14:21:33 -0700172#ifdef SK_VULKAN
Robert Phillips0b33cc42018-02-08 08:29:21 -0500173 REPORTER_ASSERT(reporter, configs[28]->asConfigGpu());
bsalomondc0fcd42016-04-11 14:21:33 -0700174#endif
Robert Phillips0b33cc42018-02-08 08:29:21 -0500175 REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType);
176 REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getColorSpace());
177 REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getColorSpace()->gammaIsLinear());
178 const SkMatrix44* config41XYZ = configs[29]->asConfigGpu()->getColorSpace()->toXYZD50();
179 SkASSERT(config41XYZ);
180 REPORTER_ASSERT(reporter, *config41XYZ != *srgbXYZ);
181 REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType);
182 REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()->getColorSpace());
183 REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()->getColorSpace()->gammaIsLinear());
184 REPORTER_ASSERT(reporter, *configs[30]->asConfigGpu()->getColorSpace()->toXYZD50() !=
185 *srgbColorSpace->toXYZD50());
186 REPORTER_ASSERT(reporter, configs[31]->asConfigGpu()->getContextType() ==
187 GrContextFactory::kGL_ContextType);
188 REPORTER_ASSERT(reporter, SkToBool(configs[31]->asConfigGpu()->getContextOverrides() &
189 SkCommandLineConfigGpu::ContextOverrides::kAvoidStencilBuffers));
190 REPORTER_ASSERT(reporter, configs[32]->asConfigGpu()->getContextType() ==
191 GrContextFactory::kMock_ContextType);
192
193 REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getContextType() ==
194 GrContextFactory::kGL_ContextType);
195 REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getColorType() == kARGB_4444_SkColorType);
196 REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getAlphaType() == kPremul_SkAlphaType);
197 REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getContextType() ==
198 GrContextFactory::kGL_ContextType);
199 REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getColorType() == kRGB_565_SkColorType);
200 REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getAlphaType() == kOpaque_SkAlphaType);
201 REPORTER_ASSERT(reporter, configs[36]->asConfigGpu());
202 REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getTestThreading());
kkinnunen3e980c32015-12-23 01:33:00 -0800203#endif
204}
205
206DEF_TEST(ParseConfigs_ExtendedGpuConfigsCorrect, reporter) {
207 SkCommandLineFlags::StringArray config1 = make_string_array({
Brian Salomon6405e712017-03-20 08:54:16 -0400208 "gpu[api=gl,nvpr=true,dit=false]",
bsalomon11abd8d2016-10-14 08:13:48 -0700209 "gpu[api=angle_d3d9_es2]",
210 "gpu[api=angle_gl_es3]",
bsalomon808ecbb2016-09-28 12:40:22 -0700211 "gpu[api=mesa,samples=77]",
212 "gpu[dit=true,api=commandbuffer]",
bsalomon808ecbb2016-09-28 12:40:22 -0700213 "gpu[api=gles]",
214 "gpu[api=gl]",
215 "gpu[api=vulkan]",
Greg Daniel2811aa22017-07-13 15:34:56 -0400216 "gpu[api=metal]",
Brian Salomon8fe24272017-07-07 12:56:11 -0400217 "gpu[api=mock]",
kkinnunen3e980c32015-12-23 01:33:00 -0800218 });
219
220 SkCommandLineConfigArray configs;
221 ParseConfigs(config1, &configs);
222 REPORTER_ASSERT(reporter, configs.count() == config1.count());
223 for (int i = 0; i < config1.count(); ++i) {
224 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
225 }
226#if SK_SUPPORT_GPU
227 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getContextType() ==
Brian Salomon6405e712017-03-20 08:54:16 -0400228 GrContextFactory::kGL_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800229 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseNVPR());
kkinnunene3c2f802015-12-29 08:57:32 -0800230 REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu()->getUseDIText());
Brian Salomonbdecacf2018-02-02 20:32:49 -0500231 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSamples() == 1);
kkinnunen3e980c32015-12-23 01:33:00 -0800232 REPORTER_ASSERT(reporter, configs[1]->asConfigGpu()->getContextType() ==
bsalomon11abd8d2016-10-14 08:13:48 -0700233 GrContextFactory::kANGLE_D3D9_ES2_ContextType);
234 REPORTER_ASSERT(reporter, configs[1]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800235 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu()->getContextType() ==
bsalomon11abd8d2016-10-14 08:13:48 -0700236 GrContextFactory::kANGLE_GL_ES3_ContextType);
237 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800238 REPORTER_ASSERT(reporter, !configs[3]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800239 REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()->getContextType() ==
bsalomon85b4b532016-04-05 11:06:27 -0700240 GrContextFactory::kCommandBuffer_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800241 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getContextType() ==
Brian Salomon6405e712017-03-20 08:54:16 -0400242 GrContextFactory::kGLES_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800243 REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseNVPR());
244 REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseDIText());
Brian Salomonbdecacf2018-02-02 20:32:49 -0500245 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getSamples() == 1);
kkinnunen3e980c32015-12-23 01:33:00 -0800246 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getContextType() ==
Brian Salomon6405e712017-03-20 08:54:16 -0400247 GrContextFactory::kGL_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800248 REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseNVPR());
249 REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseDIText());
Brian Salomonbdecacf2018-02-02 20:32:49 -0500250 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getSamples() == 1);
bsalomondc0fcd42016-04-11 14:21:33 -0700251#ifdef SK_VULKAN
Brian Salomon6405e712017-03-20 08:54:16 -0400252 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getContextType() ==
bsalomondc0fcd42016-04-11 14:21:33 -0700253 GrContextFactory::kVulkan_ContextType);
254 REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseNVPR());
255 REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseDIText());
Brian Salomonbdecacf2018-02-02 20:32:49 -0500256 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 1);
bsalomondc0fcd42016-04-11 14:21:33 -0700257#endif
Greg Daniel2811aa22017-07-13 15:34:56 -0400258#ifdef SK_METAL
Brian Salomon8fe24272017-07-07 12:56:11 -0400259 REPORTER_ASSERT(reporter, configs[8]->asConfigGpu()->getContextType() ==
Greg Daniel2811aa22017-07-13 15:34:56 -0400260 GrContextFactory::kMetal_ContextType);
261 REPORTER_ASSERT(reporter, !configs[8]->asConfigGpu()->getUseNVPR());
262 REPORTER_ASSERT(reporter, !configs[8]->asConfigGpu()->getUseDIText());
263 REPORTER_ASSERT(reporter, configs[8]->asConfigGpu()->getSamples() == 0);
264#endif
265 REPORTER_ASSERT(reporter, configs[9]->asConfigGpu()->getContextType() ==
Brian Salomon8fe24272017-07-07 12:56:11 -0400266 GrContextFactory::kMock_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800267#endif
268}
269
270DEF_TEST(ParseConfigs_ExtendedGpuConfigsIncorrect, reporter) {
271 SkCommandLineFlags::StringArray config1 = make_string_array({
Brian Salomon6405e712017-03-20 08:54:16 -0400272 "gpu[api=gl,nvpr=1]", // Number as bool.
bsalomon808ecbb2016-09-28 12:40:22 -0700273 "gpu[api=gl,]", // Trailing in comma.
bsalomon11abd8d2016-10-14 08:13:48 -0700274 "gpu[api=angle_glu]", // Unknown api.
bsalomon808ecbb2016-09-28 12:40:22 -0700275 "gpu[api=,samples=0]", // Empty api.
Brian Salomon6405e712017-03-20 08:54:16 -0400276 "gpu[api=gl,samples=true]", // Value true as a number.
277 "gpu[api=gl,samples=0,samples=0]", // Duplicate option key.
278 "gpu[,api=gl,samples=0]", // Leading comma.
bsalomon808ecbb2016-09-28 12:40:22 -0700279 "gpu[samples=54", // Missing closing parenthesis.
kkinnunen3e980c32015-12-23 01:33:00 -0800280 ",,",
Brian Salomon6405e712017-03-20 08:54:16 -0400281 "gpu[]", // Missing required api specifier
282 "gpu[samples=4]", // Missing required api specifier
bsalomon808ecbb2016-09-28 12:40:22 -0700283 "gpu[", // Missing bracket.
kkinnunen3e980c32015-12-23 01:33:00 -0800284 "samples=54" // No backend.
bsalomon808ecbb2016-09-28 12:40:22 -0700285 "gpu[nvpr=true ]", // Space.
kkinnunen3e980c32015-12-23 01:33:00 -0800286 });
287
288 SkCommandLineConfigArray configs;
289 ParseConfigs(config1, &configs);
290 REPORTER_ASSERT(reporter, configs.count() == config1.count());
291 for (int i = 0; i < config1.count(); ++i) {
292 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
293 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i]));
294#if SK_SUPPORT_GPU
295 REPORTER_ASSERT(reporter, !configs[i]->asConfigGpu());
296#endif
297 }
298}
299
kkinnunen3e980c32015-12-23 01:33:00 -0800300DEF_TEST(ParseConfigs_ExtendedGpuConfigsSurprises, reporter) {
301 // These just list explicitly some properties of the system.
302 SkCommandLineFlags::StringArray config1 = make_string_array({
303 // Options are not canonized -> two same configs have a different tag.
Brian Salomon6405e712017-03-20 08:54:16 -0400304 "gpu[api=gl,nvpr=true,dit=true]", "gpu[api=gl,dit=true,nvpr=true]",
305 "gpu[api=debuggl]", "gpu[api=gl]", "gpu[api=gles]", ""
306 "gpu[api=gl]", "gpu[api=gl,samples=0]", "gpu[api=gles,samples=0]"
kkinnunen3e980c32015-12-23 01:33:00 -0800307 });
308 SkCommandLineConfigArray configs;
309 ParseConfigs(config1, &configs);
310 REPORTER_ASSERT(reporter, configs.count() == config1.count());
311 for (int i = 0; i < config1.count(); ++i) {
312 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
313#if SK_SUPPORT_GPU
314 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals("gpu"));
315 REPORTER_ASSERT(reporter, configs[i]->asConfigGpu());
316#else
317 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i]));
318#endif
319 }
320}
Mike Klein2af5d682017-04-13 12:24:53 -0400321
322#if SK_SUPPORT_GPU
kkinnunen3e980c32015-12-23 01:33:00 -0800323DEF_TEST(ParseConfigs_ViaParsing, reporter) {
324 SkCommandLineFlags::StringArray config1 = make_string_array({
325 "a-b-c-8888",
326 "zz-qq-gpu",
bsalomon11abd8d2016-10-14 08:13:48 -0700327 "a-angle_gl_es2"
kkinnunen3e980c32015-12-23 01:33:00 -0800328 });
329
330 SkCommandLineConfigArray configs;
331 ParseConfigs(config1, &configs);
332 const struct {
333 const char* backend;
334 const char* vias[3];
335 } expectedConfigs[] = {
336 {"8888", {"a", "b", "c"}},
337 {"gpu", {"zz", "qq", nullptr}},
bsalomon11abd8d2016-10-14 08:13:48 -0700338 {"gpu", { "a", nullptr, nullptr }}
kkinnunen3e980c32015-12-23 01:33:00 -0800339 };
340 for (int i = 0; i < config1.count(); ++i) {
341 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
342 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend));
343 for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) {
344 if (!expectedConfigs[i].vias[j]) {
345 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == j);
346 break;
347 }
348 REPORTER_ASSERT(reporter,
349 configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j]));
350 }
351 }
352}
Mike Klein2af5d682017-04-13 12:24:53 -0400353#endif
kkinnunen3e980c32015-12-23 01:33:00 -0800354
355DEF_TEST(ParseConfigs_ViaParsingExtendedForm, reporter) {
356 SkCommandLineFlags::StringArray config1 = make_string_array({
bsalomon808ecbb2016-09-28 12:40:22 -0700357 "zz-qq-gpu[api=gles]",
bsalomon11abd8d2016-10-14 08:13:48 -0700358 "abc-nbc-cbs-gpu[api=angle_d3d9_es2,samples=1]",
Brian Salomon6405e712017-03-20 08:54:16 -0400359 "a-gpu[api=gl",
360 "abc-def-angle_gl_es2[api=gles]",
kkinnunen3e980c32015-12-23 01:33:00 -0800361 });
362
363 SkCommandLineConfigArray configs;
364 ParseConfigs(config1, &configs);
365 const struct {
366 const char* backend;
367 const char* vias[3];
368 } expectedConfigs[] = {
369#if SK_SUPPORT_GPU
370 {"gpu", {"zz", "qq", nullptr}},
bsalomon11abd8d2016-10-14 08:13:48 -0700371 {"gpu", {"abc", "nbc", "cbs"}},
kkinnunen3e980c32015-12-23 01:33:00 -0800372#else
bsalomon808ecbb2016-09-28 12:40:22 -0700373 {"gpu[api=gles]", {"zz", "qq", nullptr}},
bsalomon11abd8d2016-10-14 08:13:48 -0700374 {"gpu[api=angle_d3d9_es2,samples=1]", {"abc", "nbc", "cbs"}},
kkinnunen3e980c32015-12-23 01:33:00 -0800375#endif
Brian Salomon6405e712017-03-20 08:54:16 -0400376 {"gpu[api=gl", {"a", nullptr, nullptr}}, // Missing bracket makes this is not extended
377 // form but via still works as expected.
378 {"angle_gl_es2[api=gles]", {"abc", "def", nullptr}} // This is not extended form.
379 // angle_gl_es2 is an api type not a
380 // backend.
kkinnunen3e980c32015-12-23 01:33:00 -0800381 };
382 for (int i = 0; i < config1.count(); ++i) {
383 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
384 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend));
385 for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) {
386 if (!expectedConfigs[i].vias[j]) {
387 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() ==
388 static_cast<int>(j));
389 break;
390 }
391 REPORTER_ASSERT(reporter,
392 configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j]));
393 }
394 }
395#if SK_SUPPORT_GPU
396 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu());
bsalomon11abd8d2016-10-14 08:13:48 -0700397 REPORTER_ASSERT(reporter, configs[1]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800398 REPORTER_ASSERT(reporter, !configs[2]->asConfigGpu());
bsalomon11abd8d2016-10-14 08:13:48 -0700399 REPORTER_ASSERT(reporter, !configs[3]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800400#endif
401}