blob: 4d7e5cad0e527f91480648019d8c9325a4d8d709 [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
8#include "SkCommonFlagsConfig.h"
msarett7802c3d2016-09-28 11:15:27 -07009#include "SkColorSpace_Base.h"
kkinnunen3e980c32015-12-23 01:33:00 -080010#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".
34 // Gpu config defaults work.
35 SkCommandLineFlags::StringArray config1 = make_string_array({"gpu"});
36 SkCommandLineConfigArray configs;
37 ParseConfigs(config1, &configs);
38
39 REPORTER_ASSERT(reporter, configs.count() == 1);
40 REPORTER_ASSERT(reporter, configs[0]->getTag().equals("gpu"));
41 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()
bsalomon85b4b532016-04-05 11:06:27 -070045 == GrContextFactory::kNativeGL_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -080046 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseNVPR() == false);
csmartdaltone0d36292016-07-29 08:14:20 -070047 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseInstanced() == false);
kkinnunen3e980c32015-12-23 01:33:00 -080048 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseDIText() == false);
49 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSamples() == 0);
bsalomon33069252016-09-28 08:49:53 -070050 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getColorType() == kRGBA_8888_SkColorType);
brianosmanb109b8c2016-06-16 13:03:24 -070051 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getColorSpace() == nullptr);
kkinnunen3e980c32015-12-23 01:33:00 -080052#endif
53}
54
55DEF_TEST(ParseConfigs_OutParam, reporter) {
56 // Clears the out parameter.
57 SkCommandLineFlags::StringArray config1 = make_string_array({"gpu"});
58 SkCommandLineConfigArray configs;
59 ParseConfigs(config1, &configs);
60 REPORTER_ASSERT(reporter, configs.count() == 1);
61 REPORTER_ASSERT(reporter, configs[0]->getTag().equals("gpu"));
bsalomonb8797bb2016-04-05 08:49:38 -070062
kkinnunen3e980c32015-12-23 01:33:00 -080063 SkCommandLineFlags::StringArray config2 = make_string_array({"8888"});
64 ParseConfigs(config2, &configs);
65 REPORTER_ASSERT(reporter, configs.count() == 1);
66 REPORTER_ASSERT(reporter, configs[0]->getTag().equals("8888"));
bsalomonb8797bb2016-04-05 08:49:38 -070067
68 SkCommandLineFlags::StringArray config3 = make_string_array({"gl"});
69 ParseConfigs(config3, &configs);
70 REPORTER_ASSERT(reporter, configs.count() == 1);
71 REPORTER_ASSERT(reporter, configs[0]->getTag().equals("gl"));
kkinnunen3e980c32015-12-23 01:33:00 -080072}
73
74DEF_TEST(ParseConfigs_DefaultConfigs, reporter) {
75 // Parses all default configs and returns correct "tag".
76
77 SkCommandLineFlags::StringArray config1 = make_string_array({
78 "565", "8888", "debug", "gpu", "gpudebug", "gpudft", "gpunull", "msaa16", "msaa4",
csmartdaltone0d36292016-07-29 08:14:20 -070079 "nonrendering", "null", "nullgpu", "nvpr16", "nvpr4", "nvprdit16", "nvprdit4", "pdf", "skp",
bsalomon11abd8d2016-10-14 08:13:48 -070080 "svg", "xps", "angle_d3d11_es2", "angle_gl_es2", "commandbuffer", "mesa", "hwui", "gpuf16",
81 "gpusrgb", "gl", "glnvpr4", "glnvprdit4", "glsrgb", "glmsaa4", "vk", "glinst", "glinst4",
82 "glinstdit4", "glinst16", "glinstdit16", "esinst", "esinst4", "esinstdit4", "glwide"
kkinnunen3e980c32015-12-23 01:33:00 -080083 });
84
85 SkCommandLineConfigArray configs;
86 ParseConfigs(config1, &configs);
87
brianosmanb109b8c2016-06-16 13:03:24 -070088 auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
89
kkinnunen3e980c32015-12-23 01:33:00 -080090 REPORTER_ASSERT(reporter, configs.count() == config1.count());
91 for (int i = 0; i < config1.count(); ++i) {
92 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
93 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == 0);
94 }
95#if SK_SUPPORT_GPU
96 REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu());
97 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu());
98 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu());
99 REPORTER_ASSERT(reporter, configs[3]->asConfigGpu());
100 REPORTER_ASSERT(reporter, configs[4]->asConfigGpu());
101 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getUseDIText());
102 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu());
103 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 16);
104 REPORTER_ASSERT(reporter, configs[8]->asConfigGpu()->getSamples() == 4);
105 REPORTER_ASSERT(reporter, !configs[9]->asConfigGpu());
106 REPORTER_ASSERT(reporter, !configs[10]->asConfigGpu());
107 REPORTER_ASSERT(reporter, configs[11]->asConfigGpu());
108 REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getSamples() == 16);
109 REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getUseNVPR());
cdaltonc28afdb2016-03-29 20:05:07 -0700110 REPORTER_ASSERT(reporter, !configs[12]->asConfigGpu()->getUseDIText());
kkinnunen3e980c32015-12-23 01:33:00 -0800111 REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getSamples() == 4);
112 REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getUseNVPR());
cdaltonc28afdb2016-03-29 20:05:07 -0700113 REPORTER_ASSERT(reporter, !configs[13]->asConfigGpu()->getUseDIText());
114 REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getSamples() == 16);
115 REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getUseNVPR());
116 REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getUseDIText());
117 REPORTER_ASSERT(reporter, configs[15]->asConfigGpu()->getSamples() == 4);
118 REPORTER_ASSERT(reporter, configs[15]->asConfigGpu()->getUseNVPR());
119 REPORTER_ASSERT(reporter, configs[15]->asConfigGpu()->getUseDIText());
kkinnunen3e980c32015-12-23 01:33:00 -0800120 REPORTER_ASSERT(reporter, !configs[16]->asConfigGpu());
121 REPORTER_ASSERT(reporter, !configs[17]->asConfigGpu());
122 REPORTER_ASSERT(reporter, !configs[18]->asConfigGpu());
cdaltonc28afdb2016-03-29 20:05:07 -0700123 REPORTER_ASSERT(reporter, !configs[19]->asConfigGpu());
halcanary3c4521a2016-04-04 12:14:46 -0700124 REPORTER_ASSERT(reporter, !configs[24]->asConfigGpu());
brianosmanb109b8c2016-06-16 13:03:24 -0700125 REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType);
brianosman0e22eb82016-08-30 07:07:59 -0700126 REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getColorSpace());
msarett600c7372016-09-07 12:03:53 -0700127 REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getColorSpace()->gammaIsLinear());
msarett7802c3d2016-09-28 11:15:27 -0700128 REPORTER_ASSERT(reporter, as_CSB(configs[25]->asConfigGpu()->getColorSpace())->toXYZD50() ==
129 as_CSB(srgbColorSpace)->toXYZD50());
bsalomon33069252016-09-28 08:49:53 -0700130 REPORTER_ASSERT(reporter, configs[26]->asConfigGpu()->getColorType() == kRGBA_8888_SkColorType);
brianosmanb109b8c2016-06-16 13:03:24 -0700131 REPORTER_ASSERT(reporter, configs[26]->asConfigGpu()->getColorSpace() == srgbColorSpace.get());
brianosman4562f6e2016-09-19 14:42:04 -0700132 REPORTER_ASSERT(reporter, configs[41]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType);
133 REPORTER_ASSERT(reporter, configs[41]->asConfigGpu()->getColorSpace());
134 REPORTER_ASSERT(reporter, configs[41]->asConfigGpu()->getColorSpace()->gammaIsLinear());
msarett7802c3d2016-09-28 11:15:27 -0700135 REPORTER_ASSERT(reporter, as_CSB(configs[41]->asConfigGpu()->getColorSpace())->toXYZD50() !=
136 as_CSB(srgbColorSpace)->toXYZD50());
csmartdaltone0d36292016-07-29 08:14:20 -0700137 REPORTER_ASSERT(reporter, configs[33]->asConfigGpu()->getContextType() ==
138 GrContextFactory::kGL_ContextType);
139 REPORTER_ASSERT(reporter, configs[33]->asConfigGpu()->getUseInstanced());
140 REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getContextType() ==
141 GrContextFactory::kGL_ContextType);
142 REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getUseInstanced());
143 REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getSamples() == 4);
144 REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getContextType() ==
145 GrContextFactory::kGL_ContextType);
146 REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getUseInstanced());
147 REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getUseDIText());
148 REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getSamples() == 4);
149 REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getContextType() ==
150 GrContextFactory::kGL_ContextType);
151 REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getUseInstanced());
152 REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getSamples() == 16);
153 REPORTER_ASSERT(reporter, configs[37]->asConfigGpu()->getContextType() ==
154 GrContextFactory::kGL_ContextType);
155 REPORTER_ASSERT(reporter, configs[37]->asConfigGpu()->getUseInstanced());
156 REPORTER_ASSERT(reporter, configs[37]->asConfigGpu()->getUseDIText());
157 REPORTER_ASSERT(reporter, configs[37]->asConfigGpu()->getSamples() == 16);
158 REPORTER_ASSERT(reporter, configs[38]->asConfigGpu()->getContextType() ==
159 GrContextFactory::kGLES_ContextType);
160 REPORTER_ASSERT(reporter, configs[38]->asConfigGpu()->getUseInstanced());
161 REPORTER_ASSERT(reporter, configs[39]->asConfigGpu()->getContextType() ==
162 GrContextFactory::kGLES_ContextType);
163 REPORTER_ASSERT(reporter, configs[39]->asConfigGpu()->getUseInstanced());
164 REPORTER_ASSERT(reporter, configs[39]->asConfigGpu()->getSamples() == 4);
165 REPORTER_ASSERT(reporter, configs[40]->asConfigGpu()->getContextType() ==
166 GrContextFactory::kGLES_ContextType);
167 REPORTER_ASSERT(reporter, configs[40]->asConfigGpu()->getUseInstanced());
168 REPORTER_ASSERT(reporter, configs[40]->asConfigGpu()->getUseDIText());
169 REPORTER_ASSERT(reporter, configs[40]->asConfigGpu()->getSamples() == 4);
halcanary3c4521a2016-04-04 12:14:46 -0700170 REPORTER_ASSERT(reporter, configs[20]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800171 REPORTER_ASSERT(reporter, configs[21]->asConfigGpu());
halcanary3c4521a2016-04-04 12:14:46 -0700172 REPORTER_ASSERT(reporter, configs[22]->asConfigGpu());
halcanary3c4521a2016-04-04 12:14:46 -0700173#if SK_MESA
cdaltonc28afdb2016-03-29 20:05:07 -0700174 REPORTER_ASSERT(reporter, configs[23]->asConfigGpu());
175#else
176 REPORTER_ASSERT(reporter, !configs[23]->asConfigGpu());
177#endif
bsalomonb8797bb2016-04-05 08:49:38 -0700178 REPORTER_ASSERT(reporter, configs[27]->asConfigGpu());
179 REPORTER_ASSERT(reporter, configs[28]->asConfigGpu());
180 REPORTER_ASSERT(reporter, configs[28]->asConfigGpu()->getSamples() == 4);
181 REPORTER_ASSERT(reporter, configs[28]->asConfigGpu()->getUseNVPR());
182 REPORTER_ASSERT(reporter, configs[29]->asConfigGpu());
183 REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getSamples() == 4);
184 REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getUseNVPR());
185 REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getUseDIText());
186 REPORTER_ASSERT(reporter, configs[30]->asConfigGpu());
bsalomon33069252016-09-28 08:49:53 -0700187 REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()->getColorType() == kRGBA_8888_SkColorType);
brianosmanb109b8c2016-06-16 13:03:24 -0700188 REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()->getColorSpace() == srgbColorSpace.get());
bsalomonb8797bb2016-04-05 08:49:38 -0700189 REPORTER_ASSERT(reporter, configs[31]->asConfigGpu());
190 REPORTER_ASSERT(reporter, configs[31]->asConfigGpu()->getSamples() == 4);
bsalomondc0fcd42016-04-11 14:21:33 -0700191#ifdef SK_VULKAN
192 REPORTER_ASSERT(reporter, configs[32]->asConfigGpu());
193#endif
kkinnunen3e980c32015-12-23 01:33:00 -0800194#endif
195}
196
197DEF_TEST(ParseConfigs_ExtendedGpuConfigsCorrect, reporter) {
198 SkCommandLineFlags::StringArray config1 = make_string_array({
bsalomon808ecbb2016-09-28 12:40:22 -0700199 "gpu[nvpr=true,dit=false]",
bsalomon11abd8d2016-10-14 08:13:48 -0700200 "gpu[api=angle_d3d9_es2]",
201 "gpu[api=angle_gl_es3]",
bsalomon808ecbb2016-09-28 12:40:22 -0700202 "gpu[api=mesa,samples=77]",
203 "gpu[dit=true,api=commandbuffer]",
204 "gpu[]",
205 "gpu[api=gles]",
206 "gpu[api=gl]",
207 "gpu[api=vulkan]",
kkinnunen3e980c32015-12-23 01:33:00 -0800208 });
209
210 SkCommandLineConfigArray configs;
211 ParseConfigs(config1, &configs);
212 REPORTER_ASSERT(reporter, configs.count() == config1.count());
213 for (int i = 0; i < config1.count(); ++i) {
214 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
215 }
216#if SK_SUPPORT_GPU
217 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getContextType() ==
bsalomon85b4b532016-04-05 11:06:27 -0700218 GrContextFactory::kNativeGL_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800219 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseNVPR());
kkinnunene3c2f802015-12-29 08:57:32 -0800220 REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu()->getUseDIText());
kkinnunen3e980c32015-12-23 01:33:00 -0800221 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSamples() == 0);
kkinnunen3e980c32015-12-23 01:33:00 -0800222 REPORTER_ASSERT(reporter, configs[1]->asConfigGpu()->getContextType() ==
bsalomon11abd8d2016-10-14 08:13:48 -0700223 GrContextFactory::kANGLE_D3D9_ES2_ContextType);
224 REPORTER_ASSERT(reporter, configs[1]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800225 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu()->getContextType() ==
bsalomon11abd8d2016-10-14 08:13:48 -0700226 GrContextFactory::kANGLE_GL_ES3_ContextType);
227 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800228#if SK_MESA
229 REPORTER_ASSERT(reporter, configs[3]->asConfigGpu()->getContextType() ==
bsalomon85b4b532016-04-05 11:06:27 -0700230 GrContextFactory::kMESA_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800231#else
232 REPORTER_ASSERT(reporter, !configs[3]->asConfigGpu());
233#endif
kkinnunen3e980c32015-12-23 01:33:00 -0800234 REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()->getContextType() ==
bsalomon85b4b532016-04-05 11:06:27 -0700235 GrContextFactory::kCommandBuffer_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800236
kkinnunen3e980c32015-12-23 01:33:00 -0800237 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getContextType() ==
bsalomon85b4b532016-04-05 11:06:27 -0700238 GrContextFactory::kNativeGL_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800239 REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseNVPR());
240 REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseDIText());
241 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getSamples() == 0);
242 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getContextType() ==
bsalomon85b4b532016-04-05 11:06:27 -0700243 GrContextFactory::kGLES_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800244 REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseNVPR());
245 REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseDIText());
246 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getSamples() == 0);
bsalomonb8797bb2016-04-05 08:49:38 -0700247 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getContextType() ==
bsalomon85b4b532016-04-05 11:06:27 -0700248 GrContextFactory::kGL_ContextType);
bsalomonb8797bb2016-04-05 08:49:38 -0700249 REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseNVPR());
250 REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseDIText());
251 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 0);
bsalomondc0fcd42016-04-11 14:21:33 -0700252#ifdef SK_VULKAN
253 REPORTER_ASSERT(reporter, configs[8]->asConfigGpu()->getContextType() ==
254 GrContextFactory::kVulkan_ContextType);
255 REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseNVPR());
256 REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseDIText());
257 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 0);
258#endif
kkinnunen3e980c32015-12-23 01:33:00 -0800259#endif
260}
261
262DEF_TEST(ParseConfigs_ExtendedGpuConfigsIncorrect, reporter) {
263 SkCommandLineFlags::StringArray config1 = make_string_array({
bsalomon808ecbb2016-09-28 12:40:22 -0700264 "gpu[nvpr=1]", // Number as bool.
265 "gpu[api=gl,]", // Trailing in comma.
bsalomon11abd8d2016-10-14 08:13:48 -0700266 "gpu[api=angle_glu]", // Unknown api.
bsalomon808ecbb2016-09-28 12:40:22 -0700267 "gpu[api=,samples=0]", // Empty api.
268 "gpu[samples=true]", // Value true as a number.
269 "gpu[samples=0,samples=0]", // Duplicate option key.
270 "gpu[,samples=0]", // Leading comma.
271 "gpu[samples=54", // Missing closing parenthesis.
kkinnunen3e980c32015-12-23 01:33:00 -0800272 ",,",
bsalomon808ecbb2016-09-28 12:40:22 -0700273 "gpu[", // Missing bracket.
kkinnunen3e980c32015-12-23 01:33:00 -0800274 "samples=54" // No backend.
bsalomon808ecbb2016-09-28 12:40:22 -0700275 "gpu[nvpr=true ]", // Space.
kkinnunen3e980c32015-12-23 01:33:00 -0800276 });
277
278 SkCommandLineConfigArray configs;
279 ParseConfigs(config1, &configs);
280 REPORTER_ASSERT(reporter, configs.count() == config1.count());
281 for (int i = 0; i < config1.count(); ++i) {
282 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
283 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i]));
284#if SK_SUPPORT_GPU
285 REPORTER_ASSERT(reporter, !configs[i]->asConfigGpu());
286#endif
287 }
288}
289
kkinnunen3e980c32015-12-23 01:33:00 -0800290DEF_TEST(ParseConfigs_ExtendedGpuConfigsSurprises, reporter) {
291 // These just list explicitly some properties of the system.
292 SkCommandLineFlags::StringArray config1 = make_string_array({
293 // Options are not canonized -> two same configs have a different tag.
bsalomon808ecbb2016-09-28 12:40:22 -0700294 "gpu[nvpr=true,dit=true]", "gpu[dit=true,nvpr=true]",
295 "gpu[api=debug]", "gpu[api=gl]", "gpu[api=gles]", ""
296 "gpu", "gpu[]", "gpu[samples=0]", "gpu[api=gles,samples=0]"
kkinnunen3e980c32015-12-23 01:33:00 -0800297 });
298 SkCommandLineConfigArray configs;
299 ParseConfigs(config1, &configs);
300 REPORTER_ASSERT(reporter, configs.count() == config1.count());
301 for (int i = 0; i < config1.count(); ++i) {
302 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
303#if SK_SUPPORT_GPU
304 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals("gpu"));
305 REPORTER_ASSERT(reporter, configs[i]->asConfigGpu());
306#else
307 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i]));
308#endif
309 }
310}
311DEF_TEST(ParseConfigs_ViaParsing, reporter) {
312 SkCommandLineFlags::StringArray config1 = make_string_array({
313 "a-b-c-8888",
314 "zz-qq-gpu",
bsalomon11abd8d2016-10-14 08:13:48 -0700315 "a-angle_gl_es2"
kkinnunen3e980c32015-12-23 01:33:00 -0800316 });
317
318 SkCommandLineConfigArray configs;
319 ParseConfigs(config1, &configs);
320 const struct {
321 const char* backend;
322 const char* vias[3];
323 } expectedConfigs[] = {
324 {"8888", {"a", "b", "c"}},
325 {"gpu", {"zz", "qq", nullptr}},
bsalomon11abd8d2016-10-14 08:13:48 -0700326 {"gpu", { "a", nullptr, nullptr }}
kkinnunen3e980c32015-12-23 01:33:00 -0800327 };
328 for (int i = 0; i < config1.count(); ++i) {
329 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
330 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend));
331 for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) {
332 if (!expectedConfigs[i].vias[j]) {
333 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == j);
334 break;
335 }
336 REPORTER_ASSERT(reporter,
337 configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j]));
338 }
339 }
340}
341
342DEF_TEST(ParseConfigs_ViaParsingExtendedForm, reporter) {
343 SkCommandLineFlags::StringArray config1 = make_string_array({
bsalomon808ecbb2016-09-28 12:40:22 -0700344 "zz-qq-gpu[api=gles]",
bsalomon11abd8d2016-10-14 08:13:48 -0700345 "abc-nbc-cbs-gpu[api=angle_d3d9_es2,samples=1]",
bsalomon808ecbb2016-09-28 12:40:22 -0700346 "a-gpu[samples=1",
bsalomon11abd8d2016-10-14 08:13:48 -0700347 "abc-def-angle_gl_es2[samples=1]",
kkinnunen3e980c32015-12-23 01:33:00 -0800348 });
349
350 SkCommandLineConfigArray configs;
351 ParseConfigs(config1, &configs);
352 const struct {
353 const char* backend;
354 const char* vias[3];
355 } expectedConfigs[] = {
356#if SK_SUPPORT_GPU
357 {"gpu", {"zz", "qq", nullptr}},
bsalomon11abd8d2016-10-14 08:13:48 -0700358 {"gpu", {"abc", "nbc", "cbs"}},
kkinnunen3e980c32015-12-23 01:33:00 -0800359#else
bsalomon808ecbb2016-09-28 12:40:22 -0700360 {"gpu[api=gles]", {"zz", "qq", nullptr}},
bsalomon11abd8d2016-10-14 08:13:48 -0700361 {"gpu[api=angle_d3d9_es2,samples=1]", {"abc", "nbc", "cbs"}},
kkinnunen3e980c32015-12-23 01:33:00 -0800362#endif
bsalomon11abd8d2016-10-14 08:13:48 -0700363 {"gpu[samples=1", {"a", nullptr, nullptr}}, // Missing bracket makes this is not extended
364 // form but via still works as expected.
365 {"angle_gl_es2[samples=1]", {"abc", "def", nullptr}} // This is not extended form.
366 // angle_gl_es2 is an api type not a
367 // backend.
kkinnunen3e980c32015-12-23 01:33:00 -0800368 };
369 for (int i = 0; i < config1.count(); ++i) {
370 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
371 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend));
372 for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) {
373 if (!expectedConfigs[i].vias[j]) {
374 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() ==
375 static_cast<int>(j));
376 break;
377 }
378 REPORTER_ASSERT(reporter,
379 configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j]));
380 }
381 }
382#if SK_SUPPORT_GPU
383 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu());
bsalomon11abd8d2016-10-14 08:13:48 -0700384 REPORTER_ASSERT(reporter, configs[1]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800385 REPORTER_ASSERT(reporter, !configs[2]->asConfigGpu());
bsalomon11abd8d2016-10-14 08:13:48 -0700386 REPORTER_ASSERT(reporter, !configs[3]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800387#endif
388}