blob: 6ff1fd830fa16f7a22844c7c5c25842114a1b6bc [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",
Brian Osman44b61202018-03-01 10:49:26 -0500113 "gltestthreading",
114 "gl1010102",
kkinnunen3e980c32015-12-23 01:33:00 -0800115 });
116
117 SkCommandLineConfigArray configs;
118 ParseConfigs(config1, &configs);
119
Matt Sarett77a7a1b2017-02-07 13:56:11 -0500120 auto srgbColorSpace = SkColorSpace::MakeSRGB();
brianosmanb109b8c2016-06-16 13:03:24 -0700121
kkinnunen3e980c32015-12-23 01:33:00 -0800122 REPORTER_ASSERT(reporter, configs.count() == config1.count());
123 for (int i = 0; i < config1.count(); ++i) {
124 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
125 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == 0);
126 }
127#if SK_SUPPORT_GPU
128 REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu());
129 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu());
130 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu());
131 REPORTER_ASSERT(reporter, configs[3]->asConfigGpu());
Brian Salomon6405e712017-03-20 08:54:16 -0400132 REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()->getUseDIText());
133 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu());
Brian Salomondcf0ab02017-03-20 11:10:21 -0400134 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getSamples() == 8);
Brian Salomon6405e712017-03-20 08:54:16 -0400135 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 4);
136 REPORTER_ASSERT(reporter, !configs[8]->asConfigGpu());
137 REPORTER_ASSERT(reporter, configs[9]->asConfigGpu());
138 REPORTER_ASSERT(reporter, configs[10]->asConfigGpu());
Brian Salomondcf0ab02017-03-20 11:10:21 -0400139 REPORTER_ASSERT(reporter, configs[11]->asConfigGpu()->getSamples() == 8);
Brian Salomon6405e712017-03-20 08:54:16 -0400140 REPORTER_ASSERT(reporter, configs[11]->asConfigGpu()->getUseNVPR());
141 REPORTER_ASSERT(reporter, !configs[11]->asConfigGpu()->getUseDIText());
142 REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getSamples() == 4);
kkinnunen3e980c32015-12-23 01:33:00 -0800143 REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getUseNVPR());
cdaltonc28afdb2016-03-29 20:05:07 -0700144 REPORTER_ASSERT(reporter, !configs[12]->asConfigGpu()->getUseDIText());
Robert Phillips0b33cc42018-02-08 08:29:21 -0500145 REPORTER_ASSERT(reporter, !configs[13]->asConfigGpu());
146 REPORTER_ASSERT(reporter, !configs[14]->asConfigGpu());
Brian Salomon6405e712017-03-20 08:54:16 -0400147 REPORTER_ASSERT(reporter, !configs[15]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800148 REPORTER_ASSERT(reporter, !configs[16]->asConfigGpu());
Robert Phillips0b33cc42018-02-08 08:29:21 -0500149 REPORTER_ASSERT(reporter, configs[17]->asConfigGpu());
150 REPORTER_ASSERT(reporter, configs[18]->asConfigGpu());
151 REPORTER_ASSERT(reporter, configs[19]->asConfigGpu());
152 REPORTER_ASSERT(reporter, !configs[20]->asConfigGpu());
153 REPORTER_ASSERT(reporter, !configs[21]->asConfigGpu());
154 REPORTER_ASSERT(reporter, configs[22]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType);
155 REPORTER_ASSERT(reporter, configs[22]->asConfigGpu()->getColorSpace());
156 REPORTER_ASSERT(reporter, configs[22]->asConfigGpu()->getColorSpace()->gammaIsLinear());
Brian Osman36703d92017-12-12 14:09:31 -0500157 const SkMatrix44* srgbXYZ = srgbColorSpace->toXYZD50();
raftias94888332016-10-18 10:02:51 -0700158 SkASSERT(srgbXYZ);
Robert Phillips0b33cc42018-02-08 08:29:21 -0500159 const SkMatrix44* config25XYZ = configs[22]->asConfigGpu()->getColorSpace()->toXYZD50();
raftias94888332016-10-18 10:02:51 -0700160 SkASSERT(config25XYZ);
161 REPORTER_ASSERT(reporter, *config25XYZ == *srgbXYZ);
Robert Phillips0b33cc42018-02-08 08:29:21 -0500162 REPORTER_ASSERT(reporter, configs[23]->asConfigGpu()->getColorType() == kRGBA_8888_SkColorType);
163 REPORTER_ASSERT(reporter, configs[23]->asConfigGpu()->getColorSpace() == srgbColorSpace.get());
164 REPORTER_ASSERT(reporter, configs[24]->asConfigGpu());
165 REPORTER_ASSERT(reporter, configs[25]->asConfigGpu());
166 REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getSamples() == 4);
167 REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getUseNVPR());
Brian Salomon6405e712017-03-20 08:54:16 -0400168 REPORTER_ASSERT(reporter, configs[26]->asConfigGpu());
Robert Phillips0b33cc42018-02-08 08:29:21 -0500169 REPORTER_ASSERT(reporter, configs[26]->asConfigGpu()->getColorType() == kRGBA_8888_SkColorType);
170 REPORTER_ASSERT(reporter, configs[26]->asConfigGpu()->getColorSpace() == srgbColorSpace.get());
bsalomonb8797bb2016-04-05 08:49:38 -0700171 REPORTER_ASSERT(reporter, configs[27]->asConfigGpu());
Brian Salomon6405e712017-03-20 08:54:16 -0400172 REPORTER_ASSERT(reporter, configs[27]->asConfigGpu()->getSamples() == 4);
bsalomondc0fcd42016-04-11 14:21:33 -0700173#ifdef SK_VULKAN
Robert Phillips0b33cc42018-02-08 08:29:21 -0500174 REPORTER_ASSERT(reporter, configs[28]->asConfigGpu());
bsalomondc0fcd42016-04-11 14:21:33 -0700175#endif
Robert Phillips0b33cc42018-02-08 08:29:21 -0500176 REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType);
177 REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getColorSpace());
178 REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getColorSpace()->gammaIsLinear());
179 const SkMatrix44* config41XYZ = configs[29]->asConfigGpu()->getColorSpace()->toXYZD50();
180 SkASSERT(config41XYZ);
181 REPORTER_ASSERT(reporter, *config41XYZ != *srgbXYZ);
182 REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType);
183 REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()->getColorSpace());
184 REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()->getColorSpace()->gammaIsLinear());
185 REPORTER_ASSERT(reporter, *configs[30]->asConfigGpu()->getColorSpace()->toXYZD50() !=
186 *srgbColorSpace->toXYZD50());
187 REPORTER_ASSERT(reporter, configs[31]->asConfigGpu()->getContextType() ==
188 GrContextFactory::kGL_ContextType);
189 REPORTER_ASSERT(reporter, SkToBool(configs[31]->asConfigGpu()->getContextOverrides() &
190 SkCommandLineConfigGpu::ContextOverrides::kAvoidStencilBuffers));
191 REPORTER_ASSERT(reporter, configs[32]->asConfigGpu()->getContextType() ==
192 GrContextFactory::kMock_ContextType);
193
194 REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getContextType() ==
195 GrContextFactory::kGL_ContextType);
196 REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getColorType() == kARGB_4444_SkColorType);
197 REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getAlphaType() == kPremul_SkAlphaType);
198 REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getContextType() ==
199 GrContextFactory::kGL_ContextType);
200 REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getColorType() == kRGB_565_SkColorType);
201 REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getAlphaType() == kOpaque_SkAlphaType);
202 REPORTER_ASSERT(reporter, configs[36]->asConfigGpu());
203 REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getTestThreading());
Brian Osman44b61202018-03-01 10:49:26 -0500204 REPORTER_ASSERT(reporter, configs[37]->asConfigGpu());
205 REPORTER_ASSERT(reporter, configs[37]->asConfigGpu()->getColorType() ==
206 kRGBA_1010102_SkColorType);
kkinnunen3e980c32015-12-23 01:33:00 -0800207#endif
208}
209
210DEF_TEST(ParseConfigs_ExtendedGpuConfigsCorrect, reporter) {
211 SkCommandLineFlags::StringArray config1 = make_string_array({
Brian Salomon6405e712017-03-20 08:54:16 -0400212 "gpu[api=gl,nvpr=true,dit=false]",
bsalomon11abd8d2016-10-14 08:13:48 -0700213 "gpu[api=angle_d3d9_es2]",
214 "gpu[api=angle_gl_es3]",
bsalomon808ecbb2016-09-28 12:40:22 -0700215 "gpu[api=mesa,samples=77]",
216 "gpu[dit=true,api=commandbuffer]",
bsalomon808ecbb2016-09-28 12:40:22 -0700217 "gpu[api=gles]",
218 "gpu[api=gl]",
219 "gpu[api=vulkan]",
Greg Daniel2811aa22017-07-13 15:34:56 -0400220 "gpu[api=metal]",
Brian Salomon8fe24272017-07-07 12:56:11 -0400221 "gpu[api=mock]",
kkinnunen3e980c32015-12-23 01:33:00 -0800222 });
223
224 SkCommandLineConfigArray configs;
225 ParseConfigs(config1, &configs);
226 REPORTER_ASSERT(reporter, configs.count() == config1.count());
227 for (int i = 0; i < config1.count(); ++i) {
228 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
229 }
230#if SK_SUPPORT_GPU
231 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getContextType() ==
Brian Salomon6405e712017-03-20 08:54:16 -0400232 GrContextFactory::kGL_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800233 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseNVPR());
kkinnunene3c2f802015-12-29 08:57:32 -0800234 REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu()->getUseDIText());
Brian Salomonbdecacf2018-02-02 20:32:49 -0500235 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSamples() == 1);
kkinnunen3e980c32015-12-23 01:33:00 -0800236 REPORTER_ASSERT(reporter, configs[1]->asConfigGpu()->getContextType() ==
bsalomon11abd8d2016-10-14 08:13:48 -0700237 GrContextFactory::kANGLE_D3D9_ES2_ContextType);
238 REPORTER_ASSERT(reporter, configs[1]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800239 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu()->getContextType() ==
bsalomon11abd8d2016-10-14 08:13:48 -0700240 GrContextFactory::kANGLE_GL_ES3_ContextType);
241 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800242 REPORTER_ASSERT(reporter, !configs[3]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800243 REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()->getContextType() ==
bsalomon85b4b532016-04-05 11:06:27 -0700244 GrContextFactory::kCommandBuffer_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800245 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getContextType() ==
Brian Salomon6405e712017-03-20 08:54:16 -0400246 GrContextFactory::kGLES_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800247 REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseNVPR());
248 REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseDIText());
Brian Salomonbdecacf2018-02-02 20:32:49 -0500249 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getSamples() == 1);
kkinnunen3e980c32015-12-23 01:33:00 -0800250 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getContextType() ==
Brian Salomon6405e712017-03-20 08:54:16 -0400251 GrContextFactory::kGL_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800252 REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseNVPR());
253 REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseDIText());
Brian Salomonbdecacf2018-02-02 20:32:49 -0500254 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getSamples() == 1);
bsalomondc0fcd42016-04-11 14:21:33 -0700255#ifdef SK_VULKAN
Brian Salomon6405e712017-03-20 08:54:16 -0400256 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getContextType() ==
bsalomondc0fcd42016-04-11 14:21:33 -0700257 GrContextFactory::kVulkan_ContextType);
258 REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseNVPR());
259 REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseDIText());
Brian Salomonbdecacf2018-02-02 20:32:49 -0500260 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 1);
bsalomondc0fcd42016-04-11 14:21:33 -0700261#endif
Greg Daniel2811aa22017-07-13 15:34:56 -0400262#ifdef SK_METAL
Brian Salomon8fe24272017-07-07 12:56:11 -0400263 REPORTER_ASSERT(reporter, configs[8]->asConfigGpu()->getContextType() ==
Greg Daniel2811aa22017-07-13 15:34:56 -0400264 GrContextFactory::kMetal_ContextType);
265 REPORTER_ASSERT(reporter, !configs[8]->asConfigGpu()->getUseNVPR());
266 REPORTER_ASSERT(reporter, !configs[8]->asConfigGpu()->getUseDIText());
267 REPORTER_ASSERT(reporter, configs[8]->asConfigGpu()->getSamples() == 0);
268#endif
269 REPORTER_ASSERT(reporter, configs[9]->asConfigGpu()->getContextType() ==
Brian Salomon8fe24272017-07-07 12:56:11 -0400270 GrContextFactory::kMock_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800271#endif
272}
273
274DEF_TEST(ParseConfigs_ExtendedGpuConfigsIncorrect, reporter) {
275 SkCommandLineFlags::StringArray config1 = make_string_array({
Brian Salomon6405e712017-03-20 08:54:16 -0400276 "gpu[api=gl,nvpr=1]", // Number as bool.
bsalomon808ecbb2016-09-28 12:40:22 -0700277 "gpu[api=gl,]", // Trailing in comma.
bsalomon11abd8d2016-10-14 08:13:48 -0700278 "gpu[api=angle_glu]", // Unknown api.
bsalomon808ecbb2016-09-28 12:40:22 -0700279 "gpu[api=,samples=0]", // Empty api.
Brian Salomon6405e712017-03-20 08:54:16 -0400280 "gpu[api=gl,samples=true]", // Value true as a number.
281 "gpu[api=gl,samples=0,samples=0]", // Duplicate option key.
282 "gpu[,api=gl,samples=0]", // Leading comma.
bsalomon808ecbb2016-09-28 12:40:22 -0700283 "gpu[samples=54", // Missing closing parenthesis.
kkinnunen3e980c32015-12-23 01:33:00 -0800284 ",,",
Brian Salomon6405e712017-03-20 08:54:16 -0400285 "gpu[]", // Missing required api specifier
286 "gpu[samples=4]", // Missing required api specifier
bsalomon808ecbb2016-09-28 12:40:22 -0700287 "gpu[", // Missing bracket.
kkinnunen3e980c32015-12-23 01:33:00 -0800288 "samples=54" // No backend.
bsalomon808ecbb2016-09-28 12:40:22 -0700289 "gpu[nvpr=true ]", // Space.
kkinnunen3e980c32015-12-23 01:33:00 -0800290 });
291
292 SkCommandLineConfigArray configs;
293 ParseConfigs(config1, &configs);
294 REPORTER_ASSERT(reporter, configs.count() == config1.count());
295 for (int i = 0; i < config1.count(); ++i) {
296 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
297 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i]));
298#if SK_SUPPORT_GPU
299 REPORTER_ASSERT(reporter, !configs[i]->asConfigGpu());
300#endif
301 }
302}
303
kkinnunen3e980c32015-12-23 01:33:00 -0800304DEF_TEST(ParseConfigs_ExtendedGpuConfigsSurprises, reporter) {
305 // These just list explicitly some properties of the system.
306 SkCommandLineFlags::StringArray config1 = make_string_array({
307 // Options are not canonized -> two same configs have a different tag.
Brian Salomon6405e712017-03-20 08:54:16 -0400308 "gpu[api=gl,nvpr=true,dit=true]", "gpu[api=gl,dit=true,nvpr=true]",
309 "gpu[api=debuggl]", "gpu[api=gl]", "gpu[api=gles]", ""
310 "gpu[api=gl]", "gpu[api=gl,samples=0]", "gpu[api=gles,samples=0]"
kkinnunen3e980c32015-12-23 01:33:00 -0800311 });
312 SkCommandLineConfigArray configs;
313 ParseConfigs(config1, &configs);
314 REPORTER_ASSERT(reporter, configs.count() == config1.count());
315 for (int i = 0; i < config1.count(); ++i) {
316 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
317#if SK_SUPPORT_GPU
318 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals("gpu"));
319 REPORTER_ASSERT(reporter, configs[i]->asConfigGpu());
320#else
321 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i]));
322#endif
323 }
324}
Mike Klein2af5d682017-04-13 12:24:53 -0400325
326#if SK_SUPPORT_GPU
kkinnunen3e980c32015-12-23 01:33:00 -0800327DEF_TEST(ParseConfigs_ViaParsing, reporter) {
328 SkCommandLineFlags::StringArray config1 = make_string_array({
329 "a-b-c-8888",
330 "zz-qq-gpu",
bsalomon11abd8d2016-10-14 08:13:48 -0700331 "a-angle_gl_es2"
kkinnunen3e980c32015-12-23 01:33:00 -0800332 });
333
334 SkCommandLineConfigArray configs;
335 ParseConfigs(config1, &configs);
336 const struct {
337 const char* backend;
338 const char* vias[3];
339 } expectedConfigs[] = {
340 {"8888", {"a", "b", "c"}},
341 {"gpu", {"zz", "qq", nullptr}},
bsalomon11abd8d2016-10-14 08:13:48 -0700342 {"gpu", { "a", nullptr, nullptr }}
kkinnunen3e980c32015-12-23 01:33:00 -0800343 };
344 for (int i = 0; i < config1.count(); ++i) {
345 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
346 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend));
347 for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) {
348 if (!expectedConfigs[i].vias[j]) {
349 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == j);
350 break;
351 }
352 REPORTER_ASSERT(reporter,
353 configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j]));
354 }
355 }
356}
Mike Klein2af5d682017-04-13 12:24:53 -0400357#endif
kkinnunen3e980c32015-12-23 01:33:00 -0800358
359DEF_TEST(ParseConfigs_ViaParsingExtendedForm, reporter) {
360 SkCommandLineFlags::StringArray config1 = make_string_array({
bsalomon808ecbb2016-09-28 12:40:22 -0700361 "zz-qq-gpu[api=gles]",
bsalomon11abd8d2016-10-14 08:13:48 -0700362 "abc-nbc-cbs-gpu[api=angle_d3d9_es2,samples=1]",
Brian Salomon6405e712017-03-20 08:54:16 -0400363 "a-gpu[api=gl",
364 "abc-def-angle_gl_es2[api=gles]",
kkinnunen3e980c32015-12-23 01:33:00 -0800365 });
366
367 SkCommandLineConfigArray configs;
368 ParseConfigs(config1, &configs);
369 const struct {
370 const char* backend;
371 const char* vias[3];
372 } expectedConfigs[] = {
373#if SK_SUPPORT_GPU
374 {"gpu", {"zz", "qq", nullptr}},
bsalomon11abd8d2016-10-14 08:13:48 -0700375 {"gpu", {"abc", "nbc", "cbs"}},
kkinnunen3e980c32015-12-23 01:33:00 -0800376#else
bsalomon808ecbb2016-09-28 12:40:22 -0700377 {"gpu[api=gles]", {"zz", "qq", nullptr}},
bsalomon11abd8d2016-10-14 08:13:48 -0700378 {"gpu[api=angle_d3d9_es2,samples=1]", {"abc", "nbc", "cbs"}},
kkinnunen3e980c32015-12-23 01:33:00 -0800379#endif
Brian Salomon6405e712017-03-20 08:54:16 -0400380 {"gpu[api=gl", {"a", nullptr, nullptr}}, // Missing bracket makes this is not extended
381 // form but via still works as expected.
382 {"angle_gl_es2[api=gles]", {"abc", "def", nullptr}} // This is not extended form.
383 // angle_gl_es2 is an api type not a
384 // backend.
kkinnunen3e980c32015-12-23 01:33:00 -0800385 };
386 for (int i = 0; i < config1.count(); ++i) {
387 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
388 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend));
389 for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) {
390 if (!expectedConfigs[i].vias[j]) {
391 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() ==
392 static_cast<int>(j));
393 break;
394 }
395 REPORTER_ASSERT(reporter,
396 configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j]));
397 }
398 }
399#if SK_SUPPORT_GPU
400 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu());
bsalomon11abd8d2016-10-14 08:13:48 -0700401 REPORTER_ASSERT(reporter, configs[1]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800402 REPORTER_ASSERT(reporter, !configs[2]->asConfigGpu());
bsalomon11abd8d2016-10-14 08:13:48 -0700403 REPORTER_ASSERT(reporter, !configs[3]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800404#endif
405}