blob: fae8cd8a149d79959820b1c7daf3d97355005c5d [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());
Brian Salomonf865b052018-03-09 09:01:53 -050044 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getContextType() ==
45 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);
Brian Salomonf865b052018-03-09 09:01:53 -050051 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSurfType() ==
52 SkCommandLineConfigGpu::SurfType::kDefault);
kkinnunen3e980c32015-12-23 01:33:00 -080053#endif
54}
55
56DEF_TEST(ParseConfigs_OutParam, reporter) {
57 // Clears the out parameter.
Brian Salomon6405e712017-03-20 08:54:16 -040058 SkCommandLineFlags::StringArray config1 = make_string_array({"gles"});
kkinnunen3e980c32015-12-23 01:33:00 -080059 SkCommandLineConfigArray configs;
60 ParseConfigs(config1, &configs);
61 REPORTER_ASSERT(reporter, configs.count() == 1);
Brian Salomon6405e712017-03-20 08:54:16 -040062 REPORTER_ASSERT(reporter, configs[0]->getTag().equals("gles"));
bsalomonb8797bb2016-04-05 08:49:38 -070063
kkinnunen3e980c32015-12-23 01:33:00 -080064 SkCommandLineFlags::StringArray config2 = make_string_array({"8888"});
65 ParseConfigs(config2, &configs);
66 REPORTER_ASSERT(reporter, configs.count() == 1);
67 REPORTER_ASSERT(reporter, configs[0]->getTag().equals("8888"));
bsalomonb8797bb2016-04-05 08:49:38 -070068
69 SkCommandLineFlags::StringArray config3 = make_string_array({"gl"});
70 ParseConfigs(config3, &configs);
71 REPORTER_ASSERT(reporter, configs.count() == 1);
72 REPORTER_ASSERT(reporter, configs[0]->getTag().equals("gl"));
kkinnunen3e980c32015-12-23 01:33:00 -080073}
74
75DEF_TEST(ParseConfigs_DefaultConfigs, reporter) {
76 // Parses all default configs and returns correct "tag".
77
78 SkCommandLineFlags::StringArray config1 = make_string_array({
Brian Salomon8fe24272017-07-07 12:56:11 -040079 "565",
80 "8888",
81 "debuggl",
82 "gl",
83 "gldft",
84 "nullgl",
85 "glmsaa8",
86 "glmsaa4",
87 "nonrendering",
88 "nullgl",
89 "gles",
90 "glnvpr8",
91 "glnvpr4",
Brian Salomon8fe24272017-07-07 12:56:11 -040092 "pdf",
93 "skp",
94 "svg",
95 "xps",
96 "angle_d3d11_es2",
97 "angle_gl_es2",
98 "commandbuffer",
99 "mesa",
100 "hwui",
101 "glf16",
102 "glessrgb",
103 "gl",
104 "glnvpr4",
Brian Salomon8fe24272017-07-07 12:56:11 -0400105 "glsrgb",
106 "glmsaa4",
107 "vk",
Brian Salomon8fe24272017-07-07 12:56:11 -0400108 "glwide",
109 "glnarrow",
110 "glnostencils",
Greg Daniel2811aa22017-07-13 15:34:56 -0400111 "mock",
Brian Salomonce5ee602017-07-17 11:31:31 -0400112 "mtl",
113 "gl4444",
Brian Osmanf9810662017-08-30 10:02:10 -0400114 "gl565",
Brian Osman10fc6fd2018-03-02 11:01:10 -0500115 "gltestthreading",
116 "gl1010102",
Brian Salomonf865b052018-03-09 09:01:53 -0500117 "glesbert"
kkinnunen3e980c32015-12-23 01:33:00 -0800118 });
119
120 SkCommandLineConfigArray configs;
121 ParseConfigs(config1, &configs);
122
Matt Sarett77a7a1b2017-02-07 13:56:11 -0500123 auto srgbColorSpace = SkColorSpace::MakeSRGB();
brianosmanb109b8c2016-06-16 13:03:24 -0700124
kkinnunen3e980c32015-12-23 01:33:00 -0800125 REPORTER_ASSERT(reporter, configs.count() == config1.count());
126 for (int i = 0; i < config1.count(); ++i) {
127 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
128 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == 0);
129 }
130#if SK_SUPPORT_GPU
131 REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu());
132 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu());
133 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu());
134 REPORTER_ASSERT(reporter, configs[3]->asConfigGpu());
Brian Salomon6405e712017-03-20 08:54:16 -0400135 REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()->getUseDIText());
136 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu());
Brian Salomondcf0ab02017-03-20 11:10:21 -0400137 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getSamples() == 8);
Brian Salomon6405e712017-03-20 08:54:16 -0400138 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 4);
139 REPORTER_ASSERT(reporter, !configs[8]->asConfigGpu());
140 REPORTER_ASSERT(reporter, configs[9]->asConfigGpu());
141 REPORTER_ASSERT(reporter, configs[10]->asConfigGpu());
Brian Salomondcf0ab02017-03-20 11:10:21 -0400142 REPORTER_ASSERT(reporter, configs[11]->asConfigGpu()->getSamples() == 8);
Brian Salomon6405e712017-03-20 08:54:16 -0400143 REPORTER_ASSERT(reporter, configs[11]->asConfigGpu()->getUseNVPR());
144 REPORTER_ASSERT(reporter, !configs[11]->asConfigGpu()->getUseDIText());
145 REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getSamples() == 4);
kkinnunen3e980c32015-12-23 01:33:00 -0800146 REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getUseNVPR());
cdaltonc28afdb2016-03-29 20:05:07 -0700147 REPORTER_ASSERT(reporter, !configs[12]->asConfigGpu()->getUseDIText());
Robert Phillips0b33cc42018-02-08 08:29:21 -0500148 REPORTER_ASSERT(reporter, !configs[13]->asConfigGpu());
149 REPORTER_ASSERT(reporter, !configs[14]->asConfigGpu());
Brian Salomon6405e712017-03-20 08:54:16 -0400150 REPORTER_ASSERT(reporter, !configs[15]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800151 REPORTER_ASSERT(reporter, !configs[16]->asConfigGpu());
Robert Phillips0b33cc42018-02-08 08:29:21 -0500152 REPORTER_ASSERT(reporter, configs[17]->asConfigGpu());
153 REPORTER_ASSERT(reporter, configs[18]->asConfigGpu());
154 REPORTER_ASSERT(reporter, configs[19]->asConfigGpu());
155 REPORTER_ASSERT(reporter, !configs[20]->asConfigGpu());
156 REPORTER_ASSERT(reporter, !configs[21]->asConfigGpu());
157 REPORTER_ASSERT(reporter, configs[22]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType);
158 REPORTER_ASSERT(reporter, configs[22]->asConfigGpu()->getColorSpace());
159 REPORTER_ASSERT(reporter, configs[22]->asConfigGpu()->getColorSpace()->gammaIsLinear());
Brian Osman36703d92017-12-12 14:09:31 -0500160 const SkMatrix44* srgbXYZ = srgbColorSpace->toXYZD50();
raftias94888332016-10-18 10:02:51 -0700161 SkASSERT(srgbXYZ);
Robert Phillips0b33cc42018-02-08 08:29:21 -0500162 const SkMatrix44* config25XYZ = configs[22]->asConfigGpu()->getColorSpace()->toXYZD50();
raftias94888332016-10-18 10:02:51 -0700163 SkASSERT(config25XYZ);
164 REPORTER_ASSERT(reporter, *config25XYZ == *srgbXYZ);
Robert Phillips0b33cc42018-02-08 08:29:21 -0500165 REPORTER_ASSERT(reporter, configs[23]->asConfigGpu()->getColorType() == kRGBA_8888_SkColorType);
166 REPORTER_ASSERT(reporter, configs[23]->asConfigGpu()->getColorSpace() == srgbColorSpace.get());
167 REPORTER_ASSERT(reporter, configs[24]->asConfigGpu());
168 REPORTER_ASSERT(reporter, configs[25]->asConfigGpu());
169 REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getSamples() == 4);
170 REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getUseNVPR());
Brian Salomon6405e712017-03-20 08:54:16 -0400171 REPORTER_ASSERT(reporter, configs[26]->asConfigGpu());
Robert Phillips0b33cc42018-02-08 08:29:21 -0500172 REPORTER_ASSERT(reporter, configs[26]->asConfigGpu()->getColorType() == kRGBA_8888_SkColorType);
173 REPORTER_ASSERT(reporter, configs[26]->asConfigGpu()->getColorSpace() == srgbColorSpace.get());
bsalomonb8797bb2016-04-05 08:49:38 -0700174 REPORTER_ASSERT(reporter, configs[27]->asConfigGpu());
Brian Salomon6405e712017-03-20 08:54:16 -0400175 REPORTER_ASSERT(reporter, configs[27]->asConfigGpu()->getSamples() == 4);
bsalomondc0fcd42016-04-11 14:21:33 -0700176#ifdef SK_VULKAN
Robert Phillips0b33cc42018-02-08 08:29:21 -0500177 REPORTER_ASSERT(reporter, configs[28]->asConfigGpu());
bsalomondc0fcd42016-04-11 14:21:33 -0700178#endif
Robert Phillips0b33cc42018-02-08 08:29:21 -0500179 REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType);
180 REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getColorSpace());
181 REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getColorSpace()->gammaIsLinear());
182 const SkMatrix44* config41XYZ = configs[29]->asConfigGpu()->getColorSpace()->toXYZD50();
183 SkASSERT(config41XYZ);
184 REPORTER_ASSERT(reporter, *config41XYZ != *srgbXYZ);
185 REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType);
186 REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()->getColorSpace());
187 REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()->getColorSpace()->gammaIsLinear());
188 REPORTER_ASSERT(reporter, *configs[30]->asConfigGpu()->getColorSpace()->toXYZD50() !=
189 *srgbColorSpace->toXYZD50());
190 REPORTER_ASSERT(reporter, configs[31]->asConfigGpu()->getContextType() ==
191 GrContextFactory::kGL_ContextType);
192 REPORTER_ASSERT(reporter, SkToBool(configs[31]->asConfigGpu()->getContextOverrides() &
193 SkCommandLineConfigGpu::ContextOverrides::kAvoidStencilBuffers));
194 REPORTER_ASSERT(reporter, configs[32]->asConfigGpu()->getContextType() ==
195 GrContextFactory::kMock_ContextType);
196
197 REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getContextType() ==
198 GrContextFactory::kGL_ContextType);
199 REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getColorType() == kARGB_4444_SkColorType);
200 REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getAlphaType() == kPremul_SkAlphaType);
201 REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getContextType() ==
202 GrContextFactory::kGL_ContextType);
203 REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getColorType() == kRGB_565_SkColorType);
204 REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getAlphaType() == kOpaque_SkAlphaType);
205 REPORTER_ASSERT(reporter, configs[36]->asConfigGpu());
206 REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getTestThreading());
Brian Osman10fc6fd2018-03-02 11:01:10 -0500207 REPORTER_ASSERT(reporter, configs[37]->asConfigGpu());
208 REPORTER_ASSERT(reporter, configs[37]->asConfigGpu()->getColorType() ==
209 kRGBA_1010102_SkColorType);
Brian Salomonf865b052018-03-09 09:01:53 -0500210 REPORTER_ASSERT(reporter, configs[38]->asConfigGpu());
211 REPORTER_ASSERT(reporter, configs[38]->asConfigGpu()->getSurfType() ==
212 SkCommandLineConfigGpu::SurfType::kBackendRenderTarget);
kkinnunen3e980c32015-12-23 01:33:00 -0800213#endif
214}
215
216DEF_TEST(ParseConfigs_ExtendedGpuConfigsCorrect, reporter) {
217 SkCommandLineFlags::StringArray config1 = make_string_array({
Brian Salomon6405e712017-03-20 08:54:16 -0400218 "gpu[api=gl,nvpr=true,dit=false]",
bsalomon11abd8d2016-10-14 08:13:48 -0700219 "gpu[api=angle_d3d9_es2]",
220 "gpu[api=angle_gl_es3]",
bsalomon808ecbb2016-09-28 12:40:22 -0700221 "gpu[api=mesa,samples=77]",
222 "gpu[dit=true,api=commandbuffer]",
bsalomon808ecbb2016-09-28 12:40:22 -0700223 "gpu[api=gles]",
224 "gpu[api=gl]",
225 "gpu[api=vulkan]",
Greg Daniel2811aa22017-07-13 15:34:56 -0400226 "gpu[api=metal]",
Brian Salomonf865b052018-03-09 09:01:53 -0500227 "gpu[api=mock,surf=betex]",
kkinnunen3e980c32015-12-23 01:33:00 -0800228 });
229
230 SkCommandLineConfigArray configs;
231 ParseConfigs(config1, &configs);
232 REPORTER_ASSERT(reporter, configs.count() == config1.count());
233 for (int i = 0; i < config1.count(); ++i) {
234 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
235 }
236#if SK_SUPPORT_GPU
237 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getContextType() ==
Brian Salomon6405e712017-03-20 08:54:16 -0400238 GrContextFactory::kGL_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800239 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseNVPR());
kkinnunene3c2f802015-12-29 08:57:32 -0800240 REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu()->getUseDIText());
Brian Salomonbdecacf2018-02-02 20:32:49 -0500241 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSamples() == 1);
kkinnunen3e980c32015-12-23 01:33:00 -0800242 REPORTER_ASSERT(reporter, configs[1]->asConfigGpu()->getContextType() ==
bsalomon11abd8d2016-10-14 08:13:48 -0700243 GrContextFactory::kANGLE_D3D9_ES2_ContextType);
244 REPORTER_ASSERT(reporter, configs[1]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800245 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu()->getContextType() ==
bsalomon11abd8d2016-10-14 08:13:48 -0700246 GrContextFactory::kANGLE_GL_ES3_ContextType);
247 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800248 REPORTER_ASSERT(reporter, !configs[3]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800249 REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()->getContextType() ==
bsalomon85b4b532016-04-05 11:06:27 -0700250 GrContextFactory::kCommandBuffer_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800251 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getContextType() ==
Brian Salomon6405e712017-03-20 08:54:16 -0400252 GrContextFactory::kGLES_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800253 REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseNVPR());
254 REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseDIText());
Brian Salomonbdecacf2018-02-02 20:32:49 -0500255 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getSamples() == 1);
kkinnunen3e980c32015-12-23 01:33:00 -0800256 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getContextType() ==
Brian Salomon6405e712017-03-20 08:54:16 -0400257 GrContextFactory::kGL_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800258 REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseNVPR());
259 REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseDIText());
Brian Salomonbdecacf2018-02-02 20:32:49 -0500260 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getSamples() == 1);
bsalomondc0fcd42016-04-11 14:21:33 -0700261#ifdef SK_VULKAN
Brian Salomon6405e712017-03-20 08:54:16 -0400262 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getContextType() ==
bsalomondc0fcd42016-04-11 14:21:33 -0700263 GrContextFactory::kVulkan_ContextType);
264 REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseNVPR());
265 REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseDIText());
Brian Salomonbdecacf2018-02-02 20:32:49 -0500266 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 1);
bsalomondc0fcd42016-04-11 14:21:33 -0700267#endif
Greg Daniel2811aa22017-07-13 15:34:56 -0400268#ifdef SK_METAL
Brian Salomon8fe24272017-07-07 12:56:11 -0400269 REPORTER_ASSERT(reporter, configs[8]->asConfigGpu()->getContextType() ==
Greg Daniel2811aa22017-07-13 15:34:56 -0400270 GrContextFactory::kMetal_ContextType);
271 REPORTER_ASSERT(reporter, !configs[8]->asConfigGpu()->getUseNVPR());
272 REPORTER_ASSERT(reporter, !configs[8]->asConfigGpu()->getUseDIText());
273 REPORTER_ASSERT(reporter, configs[8]->asConfigGpu()->getSamples() == 0);
274#endif
275 REPORTER_ASSERT(reporter, configs[9]->asConfigGpu()->getContextType() ==
Brian Salomon8fe24272017-07-07 12:56:11 -0400276 GrContextFactory::kMock_ContextType);
Brian Salomonf865b052018-03-09 09:01:53 -0500277 REPORTER_ASSERT(reporter, configs[9]->asConfigGpu()->getSurfType() ==
278 SkCommandLineConfigGpu::SurfType::kBackendTexture);
kkinnunen3e980c32015-12-23 01:33:00 -0800279#endif
280}
281
282DEF_TEST(ParseConfigs_ExtendedGpuConfigsIncorrect, reporter) {
283 SkCommandLineFlags::StringArray config1 = make_string_array({
Brian Salomon6405e712017-03-20 08:54:16 -0400284 "gpu[api=gl,nvpr=1]", // Number as bool.
bsalomon808ecbb2016-09-28 12:40:22 -0700285 "gpu[api=gl,]", // Trailing in comma.
bsalomon11abd8d2016-10-14 08:13:48 -0700286 "gpu[api=angle_glu]", // Unknown api.
bsalomon808ecbb2016-09-28 12:40:22 -0700287 "gpu[api=,samples=0]", // Empty api.
Brian Salomon6405e712017-03-20 08:54:16 -0400288 "gpu[api=gl,samples=true]", // Value true as a number.
289 "gpu[api=gl,samples=0,samples=0]", // Duplicate option key.
290 "gpu[,api=gl,samples=0]", // Leading comma.
bsalomon808ecbb2016-09-28 12:40:22 -0700291 "gpu[samples=54", // Missing closing parenthesis.
kkinnunen3e980c32015-12-23 01:33:00 -0800292 ",,",
Brian Salomon6405e712017-03-20 08:54:16 -0400293 "gpu[]", // Missing required api specifier
294 "gpu[samples=4]", // Missing required api specifier
bsalomon808ecbb2016-09-28 12:40:22 -0700295 "gpu[", // Missing bracket.
kkinnunen3e980c32015-12-23 01:33:00 -0800296 "samples=54" // No backend.
bsalomon808ecbb2016-09-28 12:40:22 -0700297 "gpu[nvpr=true ]", // Space.
kkinnunen3e980c32015-12-23 01:33:00 -0800298 });
299
300 SkCommandLineConfigArray configs;
301 ParseConfigs(config1, &configs);
302 REPORTER_ASSERT(reporter, configs.count() == config1.count());
303 for (int i = 0; i < config1.count(); ++i) {
304 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
305 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i]));
306#if SK_SUPPORT_GPU
307 REPORTER_ASSERT(reporter, !configs[i]->asConfigGpu());
308#endif
309 }
310}
311
kkinnunen3e980c32015-12-23 01:33:00 -0800312DEF_TEST(ParseConfigs_ExtendedGpuConfigsSurprises, reporter) {
313 // These just list explicitly some properties of the system.
314 SkCommandLineFlags::StringArray config1 = make_string_array({
315 // Options are not canonized -> two same configs have a different tag.
Brian Salomon6405e712017-03-20 08:54:16 -0400316 "gpu[api=gl,nvpr=true,dit=true]", "gpu[api=gl,dit=true,nvpr=true]",
317 "gpu[api=debuggl]", "gpu[api=gl]", "gpu[api=gles]", ""
318 "gpu[api=gl]", "gpu[api=gl,samples=0]", "gpu[api=gles,samples=0]"
kkinnunen3e980c32015-12-23 01:33:00 -0800319 });
320 SkCommandLineConfigArray configs;
321 ParseConfigs(config1, &configs);
322 REPORTER_ASSERT(reporter, configs.count() == config1.count());
323 for (int i = 0; i < config1.count(); ++i) {
324 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
325#if SK_SUPPORT_GPU
326 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals("gpu"));
327 REPORTER_ASSERT(reporter, configs[i]->asConfigGpu());
328#else
329 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i]));
330#endif
331 }
332}
Mike Klein2af5d682017-04-13 12:24:53 -0400333
334#if SK_SUPPORT_GPU
kkinnunen3e980c32015-12-23 01:33:00 -0800335DEF_TEST(ParseConfigs_ViaParsing, reporter) {
336 SkCommandLineFlags::StringArray config1 = make_string_array({
337 "a-b-c-8888",
338 "zz-qq-gpu",
bsalomon11abd8d2016-10-14 08:13:48 -0700339 "a-angle_gl_es2"
kkinnunen3e980c32015-12-23 01:33:00 -0800340 });
341
342 SkCommandLineConfigArray configs;
343 ParseConfigs(config1, &configs);
344 const struct {
345 const char* backend;
346 const char* vias[3];
347 } expectedConfigs[] = {
348 {"8888", {"a", "b", "c"}},
349 {"gpu", {"zz", "qq", nullptr}},
bsalomon11abd8d2016-10-14 08:13:48 -0700350 {"gpu", { "a", nullptr, nullptr }}
kkinnunen3e980c32015-12-23 01:33:00 -0800351 };
352 for (int i = 0; i < config1.count(); ++i) {
353 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
354 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend));
355 for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) {
356 if (!expectedConfigs[i].vias[j]) {
357 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == j);
358 break;
359 }
360 REPORTER_ASSERT(reporter,
361 configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j]));
362 }
363 }
364}
Mike Klein2af5d682017-04-13 12:24:53 -0400365#endif
kkinnunen3e980c32015-12-23 01:33:00 -0800366
367DEF_TEST(ParseConfigs_ViaParsingExtendedForm, reporter) {
368 SkCommandLineFlags::StringArray config1 = make_string_array({
bsalomon808ecbb2016-09-28 12:40:22 -0700369 "zz-qq-gpu[api=gles]",
bsalomon11abd8d2016-10-14 08:13:48 -0700370 "abc-nbc-cbs-gpu[api=angle_d3d9_es2,samples=1]",
Brian Salomon6405e712017-03-20 08:54:16 -0400371 "a-gpu[api=gl",
372 "abc-def-angle_gl_es2[api=gles]",
kkinnunen3e980c32015-12-23 01:33:00 -0800373 });
374
375 SkCommandLineConfigArray configs;
376 ParseConfigs(config1, &configs);
377 const struct {
378 const char* backend;
379 const char* vias[3];
380 } expectedConfigs[] = {
381#if SK_SUPPORT_GPU
382 {"gpu", {"zz", "qq", nullptr}},
bsalomon11abd8d2016-10-14 08:13:48 -0700383 {"gpu", {"abc", "nbc", "cbs"}},
kkinnunen3e980c32015-12-23 01:33:00 -0800384#else
bsalomon808ecbb2016-09-28 12:40:22 -0700385 {"gpu[api=gles]", {"zz", "qq", nullptr}},
bsalomon11abd8d2016-10-14 08:13:48 -0700386 {"gpu[api=angle_d3d9_es2,samples=1]", {"abc", "nbc", "cbs"}},
kkinnunen3e980c32015-12-23 01:33:00 -0800387#endif
Brian Salomon6405e712017-03-20 08:54:16 -0400388 {"gpu[api=gl", {"a", nullptr, nullptr}}, // Missing bracket makes this is not extended
389 // form but via still works as expected.
390 {"angle_gl_es2[api=gles]", {"abc", "def", nullptr}} // This is not extended form.
391 // angle_gl_es2 is an api type not a
392 // backend.
kkinnunen3e980c32015-12-23 01:33:00 -0800393 };
394 for (int i = 0; i < config1.count(); ++i) {
395 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
396 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend));
397 for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) {
398 if (!expectedConfigs[i].vias[j]) {
399 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() ==
400 static_cast<int>(j));
401 break;
402 }
403 REPORTER_ASSERT(reporter,
404 configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j]));
405 }
406 }
407#if SK_SUPPORT_GPU
408 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu());
bsalomon11abd8d2016-10-14 08:13:48 -0700409 REPORTER_ASSERT(reporter, configs[1]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800410 REPORTER_ASSERT(reporter, !configs[2]->asConfigGpu());
bsalomon11abd8d2016-10-14 08:13:48 -0700411 REPORTER_ASSERT(reporter, !configs[3]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800412#endif
413}