blob: df028153e2213900bd155c0f43b68386a093914b [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 "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 Osman10fc6fd2018-03-02 11:01:10 -0500113 "gltestthreading",
114 "gl1010102",
Brian Salomonf865b052018-03-09 09:01:53 -0500115 "glesbert"
kkinnunen3e980c32015-12-23 01:33:00 -0800116 });
117
118 SkCommandLineConfigArray configs;
119 ParseConfigs(config1, &configs);
120
Matt Sarett77a7a1b2017-02-07 13:56:11 -0500121 auto srgbColorSpace = SkColorSpace::MakeSRGB();
brianosmanb109b8c2016-06-16 13:03:24 -0700122
kkinnunen3e980c32015-12-23 01:33:00 -0800123 REPORTER_ASSERT(reporter, configs.count() == config1.count());
124 for (int i = 0; i < config1.count(); ++i) {
125 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
126 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == 0);
127 }
128#if SK_SUPPORT_GPU
129 REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu());
130 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu());
131 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu());
132 REPORTER_ASSERT(reporter, configs[3]->asConfigGpu());
Brian Salomon6405e712017-03-20 08:54:16 -0400133 REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()->getUseDIText());
134 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu());
Brian Salomondcf0ab02017-03-20 11:10:21 -0400135 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getSamples() == 8);
Brian Salomon6405e712017-03-20 08:54:16 -0400136 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 4);
137 REPORTER_ASSERT(reporter, !configs[8]->asConfigGpu());
138 REPORTER_ASSERT(reporter, configs[9]->asConfigGpu());
139 REPORTER_ASSERT(reporter, configs[10]->asConfigGpu());
Brian Salomondcf0ab02017-03-20 11:10:21 -0400140 REPORTER_ASSERT(reporter, configs[11]->asConfigGpu()->getSamples() == 8);
Brian Salomon6405e712017-03-20 08:54:16 -0400141 REPORTER_ASSERT(reporter, configs[11]->asConfigGpu()->getUseNVPR());
142 REPORTER_ASSERT(reporter, !configs[11]->asConfigGpu()->getUseDIText());
143 REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getSamples() == 4);
kkinnunen3e980c32015-12-23 01:33:00 -0800144 REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getUseNVPR());
cdaltonc28afdb2016-03-29 20:05:07 -0700145 REPORTER_ASSERT(reporter, !configs[12]->asConfigGpu()->getUseDIText());
Robert Phillips0b33cc42018-02-08 08:29:21 -0500146 REPORTER_ASSERT(reporter, !configs[13]->asConfigGpu());
147 REPORTER_ASSERT(reporter, !configs[14]->asConfigGpu());
Brian Salomon6405e712017-03-20 08:54:16 -0400148 REPORTER_ASSERT(reporter, !configs[15]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800149 REPORTER_ASSERT(reporter, !configs[16]->asConfigGpu());
Robert Phillips0b33cc42018-02-08 08:29:21 -0500150 REPORTER_ASSERT(reporter, configs[17]->asConfigGpu());
151 REPORTER_ASSERT(reporter, configs[18]->asConfigGpu());
152 REPORTER_ASSERT(reporter, configs[19]->asConfigGpu());
153 REPORTER_ASSERT(reporter, !configs[20]->asConfigGpu());
154 REPORTER_ASSERT(reporter, !configs[21]->asConfigGpu());
155 REPORTER_ASSERT(reporter, configs[22]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType);
156 REPORTER_ASSERT(reporter, configs[22]->asConfigGpu()->getColorSpace());
157 REPORTER_ASSERT(reporter, configs[22]->asConfigGpu()->getColorSpace()->gammaIsLinear());
Brian Osman36703d92017-12-12 14:09:31 -0500158 const SkMatrix44* srgbXYZ = srgbColorSpace->toXYZD50();
raftias94888332016-10-18 10:02:51 -0700159 SkASSERT(srgbXYZ);
Robert Phillips0b33cc42018-02-08 08:29:21 -0500160 const SkMatrix44* config25XYZ = configs[22]->asConfigGpu()->getColorSpace()->toXYZD50();
raftias94888332016-10-18 10:02:51 -0700161 SkASSERT(config25XYZ);
162 REPORTER_ASSERT(reporter, *config25XYZ == *srgbXYZ);
Robert Phillips0b33cc42018-02-08 08:29:21 -0500163 REPORTER_ASSERT(reporter, configs[23]->asConfigGpu()->getColorType() == kRGBA_8888_SkColorType);
164 REPORTER_ASSERT(reporter, configs[23]->asConfigGpu()->getColorSpace() == srgbColorSpace.get());
165 REPORTER_ASSERT(reporter, configs[24]->asConfigGpu());
166 REPORTER_ASSERT(reporter, configs[25]->asConfigGpu());
167 REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getSamples() == 4);
168 REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getUseNVPR());
Brian Salomon6405e712017-03-20 08:54:16 -0400169 REPORTER_ASSERT(reporter, configs[26]->asConfigGpu());
Robert Phillips0b33cc42018-02-08 08:29:21 -0500170 REPORTER_ASSERT(reporter, configs[26]->asConfigGpu()->getColorType() == kRGBA_8888_SkColorType);
171 REPORTER_ASSERT(reporter, configs[26]->asConfigGpu()->getColorSpace() == srgbColorSpace.get());
bsalomonb8797bb2016-04-05 08:49:38 -0700172 REPORTER_ASSERT(reporter, configs[27]->asConfigGpu());
Brian Salomon6405e712017-03-20 08:54:16 -0400173 REPORTER_ASSERT(reporter, configs[27]->asConfigGpu()->getSamples() == 4);
bsalomondc0fcd42016-04-11 14:21:33 -0700174#ifdef SK_VULKAN
Robert Phillips0b33cc42018-02-08 08:29:21 -0500175 REPORTER_ASSERT(reporter, configs[28]->asConfigGpu());
bsalomondc0fcd42016-04-11 14:21:33 -0700176#endif
Brian Osmana15cedb2018-05-30 15:36:38 -0400177 REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getContextType() ==
Robert Phillips0b33cc42018-02-08 08:29:21 -0500178 GrContextFactory::kGL_ContextType);
Brian Osmana15cedb2018-05-30 15:36:38 -0400179 REPORTER_ASSERT(reporter, SkToBool(configs[29]->asConfigGpu()->getContextOverrides() &
Robert Phillips0b33cc42018-02-08 08:29:21 -0500180 SkCommandLineConfigGpu::ContextOverrides::kAvoidStencilBuffers));
Brian Osmana15cedb2018-05-30 15:36:38 -0400181 REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()->getContextType() ==
Robert Phillips0b33cc42018-02-08 08:29:21 -0500182 GrContextFactory::kMock_ContextType);
183
Brian Osmana15cedb2018-05-30 15:36:38 -0400184 REPORTER_ASSERT(reporter, configs[32]->asConfigGpu()->getContextType() ==
Robert Phillips0b33cc42018-02-08 08:29:21 -0500185 GrContextFactory::kGL_ContextType);
Brian Osmana15cedb2018-05-30 15:36:38 -0400186 REPORTER_ASSERT(reporter, configs[32]->asConfigGpu()->getColorType() == kARGB_4444_SkColorType);
187 REPORTER_ASSERT(reporter, configs[32]->asConfigGpu()->getAlphaType() == kPremul_SkAlphaType);
188 REPORTER_ASSERT(reporter, configs[33]->asConfigGpu()->getContextType() ==
Robert Phillips0b33cc42018-02-08 08:29:21 -0500189 GrContextFactory::kGL_ContextType);
Brian Osmana15cedb2018-05-30 15:36:38 -0400190 REPORTER_ASSERT(reporter, configs[33]->asConfigGpu()->getColorType() == kRGB_565_SkColorType);
191 REPORTER_ASSERT(reporter, configs[33]->asConfigGpu()->getAlphaType() == kOpaque_SkAlphaType);
192 REPORTER_ASSERT(reporter, configs[34]->asConfigGpu());
193 REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getTestThreading());
194 REPORTER_ASSERT(reporter, configs[35]->asConfigGpu());
195 REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getColorType() ==
Brian Osman10fc6fd2018-03-02 11:01:10 -0500196 kRGBA_1010102_SkColorType);
Brian Osmana15cedb2018-05-30 15:36:38 -0400197 REPORTER_ASSERT(reporter, configs[36]->asConfigGpu());
198 REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getSurfType() ==
Brian Salomonf865b052018-03-09 09:01:53 -0500199 SkCommandLineConfigGpu::SurfType::kBackendRenderTarget);
kkinnunen3e980c32015-12-23 01:33:00 -0800200#endif
201}
202
203DEF_TEST(ParseConfigs_ExtendedGpuConfigsCorrect, reporter) {
204 SkCommandLineFlags::StringArray config1 = make_string_array({
Brian Salomon6405e712017-03-20 08:54:16 -0400205 "gpu[api=gl,nvpr=true,dit=false]",
bsalomon11abd8d2016-10-14 08:13:48 -0700206 "gpu[api=angle_d3d9_es2]",
207 "gpu[api=angle_gl_es3]",
bsalomon808ecbb2016-09-28 12:40:22 -0700208 "gpu[api=mesa,samples=77]",
209 "gpu[dit=true,api=commandbuffer]",
bsalomon808ecbb2016-09-28 12:40:22 -0700210 "gpu[api=gles]",
211 "gpu[api=gl]",
212 "gpu[api=vulkan]",
Greg Daniel2811aa22017-07-13 15:34:56 -0400213 "gpu[api=metal]",
Brian Salomonf865b052018-03-09 09:01:53 -0500214 "gpu[api=mock,surf=betex]",
kkinnunen3e980c32015-12-23 01:33:00 -0800215 });
216
217 SkCommandLineConfigArray configs;
218 ParseConfigs(config1, &configs);
219 REPORTER_ASSERT(reporter, configs.count() == config1.count());
220 for (int i = 0; i < config1.count(); ++i) {
221 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
222 }
223#if SK_SUPPORT_GPU
224 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getContextType() ==
Brian Salomon6405e712017-03-20 08:54:16 -0400225 GrContextFactory::kGL_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800226 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseNVPR());
kkinnunene3c2f802015-12-29 08:57:32 -0800227 REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu()->getUseDIText());
Brian Salomonbdecacf2018-02-02 20:32:49 -0500228 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSamples() == 1);
kkinnunen3e980c32015-12-23 01:33:00 -0800229 REPORTER_ASSERT(reporter, configs[1]->asConfigGpu()->getContextType() ==
bsalomon11abd8d2016-10-14 08:13:48 -0700230 GrContextFactory::kANGLE_D3D9_ES2_ContextType);
231 REPORTER_ASSERT(reporter, configs[1]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800232 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu()->getContextType() ==
bsalomon11abd8d2016-10-14 08:13:48 -0700233 GrContextFactory::kANGLE_GL_ES3_ContextType);
234 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800235 REPORTER_ASSERT(reporter, !configs[3]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800236 REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()->getContextType() ==
bsalomon85b4b532016-04-05 11:06:27 -0700237 GrContextFactory::kCommandBuffer_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800238 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getContextType() ==
Brian Salomon6405e712017-03-20 08:54:16 -0400239 GrContextFactory::kGLES_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800240 REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseNVPR());
241 REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseDIText());
Brian Salomonbdecacf2018-02-02 20:32:49 -0500242 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getSamples() == 1);
kkinnunen3e980c32015-12-23 01:33:00 -0800243 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getContextType() ==
Brian Salomon6405e712017-03-20 08:54:16 -0400244 GrContextFactory::kGL_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800245 REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseNVPR());
246 REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseDIText());
Brian Salomonbdecacf2018-02-02 20:32:49 -0500247 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getSamples() == 1);
bsalomondc0fcd42016-04-11 14:21:33 -0700248#ifdef SK_VULKAN
Brian Salomon6405e712017-03-20 08:54:16 -0400249 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getContextType() ==
bsalomondc0fcd42016-04-11 14:21:33 -0700250 GrContextFactory::kVulkan_ContextType);
251 REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseNVPR());
252 REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseDIText());
Brian Salomonbdecacf2018-02-02 20:32:49 -0500253 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 1);
bsalomondc0fcd42016-04-11 14:21:33 -0700254#endif
Greg Daniel2811aa22017-07-13 15:34:56 -0400255#ifdef SK_METAL
Brian Salomon8fe24272017-07-07 12:56:11 -0400256 REPORTER_ASSERT(reporter, configs[8]->asConfigGpu()->getContextType() ==
Greg Daniel2811aa22017-07-13 15:34:56 -0400257 GrContextFactory::kMetal_ContextType);
258 REPORTER_ASSERT(reporter, !configs[8]->asConfigGpu()->getUseNVPR());
259 REPORTER_ASSERT(reporter, !configs[8]->asConfigGpu()->getUseDIText());
260 REPORTER_ASSERT(reporter, configs[8]->asConfigGpu()->getSamples() == 0);
261#endif
262 REPORTER_ASSERT(reporter, configs[9]->asConfigGpu()->getContextType() ==
Brian Salomon8fe24272017-07-07 12:56:11 -0400263 GrContextFactory::kMock_ContextType);
Brian Salomonf865b052018-03-09 09:01:53 -0500264 REPORTER_ASSERT(reporter, configs[9]->asConfigGpu()->getSurfType() ==
265 SkCommandLineConfigGpu::SurfType::kBackendTexture);
kkinnunen3e980c32015-12-23 01:33:00 -0800266#endif
267}
268
269DEF_TEST(ParseConfigs_ExtendedGpuConfigsIncorrect, reporter) {
270 SkCommandLineFlags::StringArray config1 = make_string_array({
Brian Salomon6405e712017-03-20 08:54:16 -0400271 "gpu[api=gl,nvpr=1]", // Number as bool.
bsalomon808ecbb2016-09-28 12:40:22 -0700272 "gpu[api=gl,]", // Trailing in comma.
bsalomon11abd8d2016-10-14 08:13:48 -0700273 "gpu[api=angle_glu]", // Unknown api.
bsalomon808ecbb2016-09-28 12:40:22 -0700274 "gpu[api=,samples=0]", // Empty api.
Brian Salomon6405e712017-03-20 08:54:16 -0400275 "gpu[api=gl,samples=true]", // Value true as a number.
276 "gpu[api=gl,samples=0,samples=0]", // Duplicate option key.
277 "gpu[,api=gl,samples=0]", // Leading comma.
bsalomon808ecbb2016-09-28 12:40:22 -0700278 "gpu[samples=54", // Missing closing parenthesis.
kkinnunen3e980c32015-12-23 01:33:00 -0800279 ",,",
Brian Salomon6405e712017-03-20 08:54:16 -0400280 "gpu[]", // Missing required api specifier
281 "gpu[samples=4]", // Missing required api specifier
bsalomon808ecbb2016-09-28 12:40:22 -0700282 "gpu[", // Missing bracket.
kkinnunen3e980c32015-12-23 01:33:00 -0800283 "samples=54" // No backend.
bsalomon808ecbb2016-09-28 12:40:22 -0700284 "gpu[nvpr=true ]", // Space.
kkinnunen3e980c32015-12-23 01:33:00 -0800285 });
286
287 SkCommandLineConfigArray configs;
288 ParseConfigs(config1, &configs);
289 REPORTER_ASSERT(reporter, configs.count() == config1.count());
290 for (int i = 0; i < config1.count(); ++i) {
291 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
292 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i]));
293#if SK_SUPPORT_GPU
294 REPORTER_ASSERT(reporter, !configs[i]->asConfigGpu());
295#endif
296 }
297}
298
kkinnunen3e980c32015-12-23 01:33:00 -0800299DEF_TEST(ParseConfigs_ExtendedGpuConfigsSurprises, reporter) {
300 // These just list explicitly some properties of the system.
301 SkCommandLineFlags::StringArray config1 = make_string_array({
302 // Options are not canonized -> two same configs have a different tag.
Brian Salomon6405e712017-03-20 08:54:16 -0400303 "gpu[api=gl,nvpr=true,dit=true]", "gpu[api=gl,dit=true,nvpr=true]",
304 "gpu[api=debuggl]", "gpu[api=gl]", "gpu[api=gles]", ""
305 "gpu[api=gl]", "gpu[api=gl,samples=0]", "gpu[api=gles,samples=0]"
kkinnunen3e980c32015-12-23 01:33:00 -0800306 });
307 SkCommandLineConfigArray configs;
308 ParseConfigs(config1, &configs);
309 REPORTER_ASSERT(reporter, configs.count() == config1.count());
310 for (int i = 0; i < config1.count(); ++i) {
311 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
312#if SK_SUPPORT_GPU
313 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals("gpu"));
314 REPORTER_ASSERT(reporter, configs[i]->asConfigGpu());
315#else
316 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i]));
317#endif
318 }
319}
Mike Klein2af5d682017-04-13 12:24:53 -0400320
321#if SK_SUPPORT_GPU
kkinnunen3e980c32015-12-23 01:33:00 -0800322DEF_TEST(ParseConfigs_ViaParsing, reporter) {
323 SkCommandLineFlags::StringArray config1 = make_string_array({
324 "a-b-c-8888",
325 "zz-qq-gpu",
bsalomon11abd8d2016-10-14 08:13:48 -0700326 "a-angle_gl_es2"
kkinnunen3e980c32015-12-23 01:33:00 -0800327 });
328
329 SkCommandLineConfigArray configs;
330 ParseConfigs(config1, &configs);
331 const struct {
332 const char* backend;
333 const char* vias[3];
334 } expectedConfigs[] = {
335 {"8888", {"a", "b", "c"}},
336 {"gpu", {"zz", "qq", nullptr}},
bsalomon11abd8d2016-10-14 08:13:48 -0700337 {"gpu", { "a", nullptr, nullptr }}
kkinnunen3e980c32015-12-23 01:33:00 -0800338 };
339 for (int i = 0; i < config1.count(); ++i) {
340 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
341 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend));
342 for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) {
343 if (!expectedConfigs[i].vias[j]) {
344 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == j);
345 break;
346 }
347 REPORTER_ASSERT(reporter,
348 configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j]));
349 }
350 }
351}
Mike Klein2af5d682017-04-13 12:24:53 -0400352#endif
kkinnunen3e980c32015-12-23 01:33:00 -0800353
354DEF_TEST(ParseConfigs_ViaParsingExtendedForm, reporter) {
355 SkCommandLineFlags::StringArray config1 = make_string_array({
bsalomon808ecbb2016-09-28 12:40:22 -0700356 "zz-qq-gpu[api=gles]",
bsalomon11abd8d2016-10-14 08:13:48 -0700357 "abc-nbc-cbs-gpu[api=angle_d3d9_es2,samples=1]",
Brian Salomon6405e712017-03-20 08:54:16 -0400358 "a-gpu[api=gl",
359 "abc-def-angle_gl_es2[api=gles]",
kkinnunen3e980c32015-12-23 01:33:00 -0800360 });
361
362 SkCommandLineConfigArray configs;
363 ParseConfigs(config1, &configs);
364 const struct {
365 const char* backend;
366 const char* vias[3];
367 } expectedConfigs[] = {
368#if SK_SUPPORT_GPU
369 {"gpu", {"zz", "qq", nullptr}},
bsalomon11abd8d2016-10-14 08:13:48 -0700370 {"gpu", {"abc", "nbc", "cbs"}},
kkinnunen3e980c32015-12-23 01:33:00 -0800371#else
bsalomon808ecbb2016-09-28 12:40:22 -0700372 {"gpu[api=gles]", {"zz", "qq", nullptr}},
bsalomon11abd8d2016-10-14 08:13:48 -0700373 {"gpu[api=angle_d3d9_es2,samples=1]", {"abc", "nbc", "cbs"}},
kkinnunen3e980c32015-12-23 01:33:00 -0800374#endif
Brian Salomon6405e712017-03-20 08:54:16 -0400375 {"gpu[api=gl", {"a", nullptr, nullptr}}, // Missing bracket makes this is not extended
376 // form but via still works as expected.
377 {"angle_gl_es2[api=gles]", {"abc", "def", nullptr}} // This is not extended form.
378 // angle_gl_es2 is an api type not a
379 // backend.
kkinnunen3e980c32015-12-23 01:33:00 -0800380 };
381 for (int i = 0; i < config1.count(); ++i) {
382 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
383 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend));
384 for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) {
385 if (!expectedConfigs[i].vias[j]) {
386 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() ==
387 static_cast<int>(j));
388 break;
389 }
390 REPORTER_ASSERT(reporter,
391 configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j]));
392 }
393 }
394#if SK_SUPPORT_GPU
395 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu());
bsalomon11abd8d2016-10-14 08:13:48 -0700396 REPORTER_ASSERT(reporter, configs[1]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800397 REPORTER_ASSERT(reporter, !configs[2]->asConfigGpu());
bsalomon11abd8d2016-10-14 08:13:48 -0700398 REPORTER_ASSERT(reporter, !configs[3]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800399#endif
400}