blob: 22d79aa6dc117e2ad55c63fbf825b9cb3bdb56bb [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".
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);
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.
Brian Salomon6405e712017-03-20 08:54:16 -040057 SkCommandLineFlags::StringArray config1 = make_string_array({"gles"});
kkinnunen3e980c32015-12-23 01:33:00 -080058 SkCommandLineConfigArray configs;
59 ParseConfigs(config1, &configs);
60 REPORTER_ASSERT(reporter, configs.count() == 1);
Brian Salomon6405e712017-03-20 08:54:16 -040061 REPORTER_ASSERT(reporter, configs[0]->getTag().equals("gles"));
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({
Brian Salomon8fe24272017-07-07 12:56:11 -040078 "565",
79 "8888",
80 "debuggl",
81 "gl",
82 "gldft",
83 "nullgl",
84 "glmsaa8",
85 "glmsaa4",
86 "nonrendering",
87 "nullgl",
88 "gles",
89 "glnvpr8",
90 "glnvpr4",
91 "glnvprdit8",
92 "glesnvprdit4",
93 "pdf",
94 "skp",
95 "svg",
96 "xps",
97 "angle_d3d11_es2",
98 "angle_gl_es2",
99 "commandbuffer",
100 "mesa",
101 "hwui",
102 "glf16",
103 "glessrgb",
104 "gl",
105 "glnvpr4",
106 "glnvprdit4",
107 "glsrgb",
108 "glmsaa4",
109 "vk",
110 "glinst",
111 "glinst4",
112 "glinstdit4",
113 "glinst8",
114 "glinstdit8",
115 "glesinst",
116 "glesinst4",
117 "glesinstdit4",
118 "glwide",
119 "glnarrow",
120 "glnostencils",
Greg Daniel2811aa22017-07-13 15:34:56 -0400121 "mock",
Brian Salomonce5ee602017-07-17 11:31:31 -0400122 "mtl",
123 "gl4444",
Brian Osmanf9810662017-08-30 10:02:10 -0400124 "gl565",
125 "gltestthreading"
kkinnunen3e980c32015-12-23 01:33:00 -0800126 });
127
128 SkCommandLineConfigArray configs;
129 ParseConfigs(config1, &configs);
130
Matt Sarett77a7a1b2017-02-07 13:56:11 -0500131 auto srgbColorSpace = SkColorSpace::MakeSRGB();
brianosmanb109b8c2016-06-16 13:03:24 -0700132
kkinnunen3e980c32015-12-23 01:33:00 -0800133 REPORTER_ASSERT(reporter, configs.count() == config1.count());
134 for (int i = 0; i < config1.count(); ++i) {
135 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
136 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == 0);
137 }
138#if SK_SUPPORT_GPU
139 REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu());
140 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu());
141 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu());
142 REPORTER_ASSERT(reporter, configs[3]->asConfigGpu());
Brian Salomon6405e712017-03-20 08:54:16 -0400143 REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()->getUseDIText());
144 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu());
Brian Salomondcf0ab02017-03-20 11:10:21 -0400145 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getSamples() == 8);
Brian Salomon6405e712017-03-20 08:54:16 -0400146 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 4);
147 REPORTER_ASSERT(reporter, !configs[8]->asConfigGpu());
148 REPORTER_ASSERT(reporter, configs[9]->asConfigGpu());
149 REPORTER_ASSERT(reporter, configs[10]->asConfigGpu());
Brian Salomondcf0ab02017-03-20 11:10:21 -0400150 REPORTER_ASSERT(reporter, configs[11]->asConfigGpu()->getSamples() == 8);
Brian Salomon6405e712017-03-20 08:54:16 -0400151 REPORTER_ASSERT(reporter, configs[11]->asConfigGpu()->getUseNVPR());
152 REPORTER_ASSERT(reporter, !configs[11]->asConfigGpu()->getUseDIText());
153 REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getSamples() == 4);
kkinnunen3e980c32015-12-23 01:33:00 -0800154 REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getUseNVPR());
cdaltonc28afdb2016-03-29 20:05:07 -0700155 REPORTER_ASSERT(reporter, !configs[12]->asConfigGpu()->getUseDIText());
Brian Salomondcf0ab02017-03-20 11:10:21 -0400156 REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getSamples() == 8);
kkinnunen3e980c32015-12-23 01:33:00 -0800157 REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getUseNVPR());
Brian Salomon6405e712017-03-20 08:54:16 -0400158 REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getUseDIText());
159 REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getSamples() == 4);
cdaltonc28afdb2016-03-29 20:05:07 -0700160 REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getUseNVPR());
161 REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getUseDIText());
Brian Salomon6405e712017-03-20 08:54:16 -0400162 REPORTER_ASSERT(reporter, !configs[15]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800163 REPORTER_ASSERT(reporter, !configs[16]->asConfigGpu());
164 REPORTER_ASSERT(reporter, !configs[17]->asConfigGpu());
165 REPORTER_ASSERT(reporter, !configs[18]->asConfigGpu());
Brian Salomon6405e712017-03-20 08:54:16 -0400166 REPORTER_ASSERT(reporter, !configs[23]->asConfigGpu());
167 REPORTER_ASSERT(reporter, configs[24]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType);
168 REPORTER_ASSERT(reporter, configs[24]->asConfigGpu()->getColorSpace());
169 REPORTER_ASSERT(reporter, configs[24]->asConfigGpu()->getColorSpace()->gammaIsLinear());
raftias94888332016-10-18 10:02:51 -0700170 const SkMatrix44* srgbXYZ = as_CSB(srgbColorSpace)->toXYZD50();
171 SkASSERT(srgbXYZ);
172 const SkMatrix44* config25XYZ =
Brian Salomon6405e712017-03-20 08:54:16 -0400173 as_CSB(configs[24]->asConfigGpu()->getColorSpace())->toXYZD50();
raftias94888332016-10-18 10:02:51 -0700174 SkASSERT(config25XYZ);
175 REPORTER_ASSERT(reporter, *config25XYZ == *srgbXYZ);
Brian Salomon6405e712017-03-20 08:54:16 -0400176 REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getColorType() == kRGBA_8888_SkColorType);
177 REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getColorSpace() == srgbColorSpace.get());
178 REPORTER_ASSERT(reporter, configs[40]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType);
179 REPORTER_ASSERT(reporter, configs[40]->asConfigGpu()->getColorSpace());
180 REPORTER_ASSERT(reporter, configs[40]->asConfigGpu()->getColorSpace()->gammaIsLinear());
181 const SkMatrix44* config41XYZ =
182 as_CSB(configs[40]->asConfigGpu()->getColorSpace())->toXYZD50();
183 SkASSERT(config41XYZ);
184 REPORTER_ASSERT(reporter, *config41XYZ != *srgbXYZ);
185 REPORTER_ASSERT(reporter, configs[32]->asConfigGpu()->getContextType() ==
186 GrContextFactory::kGL_ContextType);
brianosman4562f6e2016-09-19 14:42:04 -0700187 REPORTER_ASSERT(reporter, configs[41]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType);
188 REPORTER_ASSERT(reporter, configs[41]->asConfigGpu()->getColorSpace());
189 REPORTER_ASSERT(reporter, configs[41]->asConfigGpu()->getColorSpace()->gammaIsLinear());
Brian Salomon6405e712017-03-20 08:54:16 -0400190 REPORTER_ASSERT(reporter, *as_CSB(configs[41]->asConfigGpu()->getColorSpace())->toXYZD50() !=
191 *as_CSB(srgbColorSpace)->toXYZD50());
Brian Salomon8fe24272017-07-07 12:56:11 -0400192 REPORTER_ASSERT(reporter, configs[42]->asConfigGpu()->getContextType() ==
193 GrContextFactory::kGL_ContextType);
194 REPORTER_ASSERT(reporter, SkToBool(configs[42]->asConfigGpu()->getContextOverrides() &
195 SkCommandLineConfigGpu::ContextOverrides::kAvoidStencilBuffers));
196 REPORTER_ASSERT(reporter, configs[43]->asConfigGpu()->getContextType() ==
197 GrContextFactory::kMock_ContextType);
Brian Salomon6405e712017-03-20 08:54:16 -0400198 REPORTER_ASSERT(reporter, configs[32]->asConfigGpu()->getUseInstanced());
raftias94888332016-10-18 10:02:51 -0700199 REPORTER_ASSERT(reporter, configs[33]->asConfigGpu()->getContextType() ==
200 GrContextFactory::kGL_ContextType);
csmartdaltone0d36292016-07-29 08:14:20 -0700201 REPORTER_ASSERT(reporter, configs[33]->asConfigGpu()->getUseInstanced());
Brian Salomon6405e712017-03-20 08:54:16 -0400202 REPORTER_ASSERT(reporter, configs[33]->asConfigGpu()->getSamples() == 4);
csmartdaltone0d36292016-07-29 08:14:20 -0700203 REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getContextType() ==
204 GrContextFactory::kGL_ContextType);
205 REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getUseInstanced());
Brian Salomon6405e712017-03-20 08:54:16 -0400206 REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getUseDIText());
csmartdaltone0d36292016-07-29 08:14:20 -0700207 REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getSamples() == 4);
208 REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getContextType() ==
209 GrContextFactory::kGL_ContextType);
210 REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getUseInstanced());
Brian Salomondcf0ab02017-03-20 11:10:21 -0400211 REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getSamples() == 8);
csmartdaltone0d36292016-07-29 08:14:20 -0700212 REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getContextType() ==
213 GrContextFactory::kGL_ContextType);
214 REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getUseInstanced());
Brian Salomon6405e712017-03-20 08:54:16 -0400215 REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getUseDIText());
Brian Salomondcf0ab02017-03-20 11:10:21 -0400216 REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getSamples() == 8);
csmartdaltone0d36292016-07-29 08:14:20 -0700217 REPORTER_ASSERT(reporter, configs[37]->asConfigGpu()->getContextType() ==
Brian Salomon6405e712017-03-20 08:54:16 -0400218 GrContextFactory::kGLES_ContextType);
csmartdaltone0d36292016-07-29 08:14:20 -0700219 REPORTER_ASSERT(reporter, configs[37]->asConfigGpu()->getUseInstanced());
csmartdaltone0d36292016-07-29 08:14:20 -0700220 REPORTER_ASSERT(reporter, configs[38]->asConfigGpu()->getContextType() ==
221 GrContextFactory::kGLES_ContextType);
222 REPORTER_ASSERT(reporter, configs[38]->asConfigGpu()->getUseInstanced());
Brian Salomon6405e712017-03-20 08:54:16 -0400223 REPORTER_ASSERT(reporter, configs[38]->asConfigGpu()->getSamples() == 4);
csmartdaltone0d36292016-07-29 08:14:20 -0700224 REPORTER_ASSERT(reporter, configs[39]->asConfigGpu()->getContextType() ==
225 GrContextFactory::kGLES_ContextType);
226 REPORTER_ASSERT(reporter, configs[39]->asConfigGpu()->getUseInstanced());
Brian Salomon6405e712017-03-20 08:54:16 -0400227 REPORTER_ASSERT(reporter, configs[39]->asConfigGpu()->getUseDIText());
csmartdaltone0d36292016-07-29 08:14:20 -0700228 REPORTER_ASSERT(reporter, configs[39]->asConfigGpu()->getSamples() == 4);
Brian Salomon6405e712017-03-20 08:54:16 -0400229 REPORTER_ASSERT(reporter, configs[19]->asConfigGpu());
halcanary3c4521a2016-04-04 12:14:46 -0700230 REPORTER_ASSERT(reporter, configs[20]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800231 REPORTER_ASSERT(reporter, configs[21]->asConfigGpu());
Brian Salomonce5ee602017-07-17 11:31:31 -0400232 REPORTER_ASSERT(reporter, configs[45]->asConfigGpu()->getContextType() ==
233 GrContextFactory::kGL_ContextType);
234 REPORTER_ASSERT(reporter, configs[45]->asConfigGpu()->getColorType() == kARGB_4444_SkColorType);
235 REPORTER_ASSERT(reporter, configs[45]->asConfigGpu()->getAlphaType() == kPremul_SkAlphaType);
236 REPORTER_ASSERT(reporter, configs[46]->asConfigGpu()->getContextType() ==
237 GrContextFactory::kGL_ContextType);
238 REPORTER_ASSERT(reporter, configs[46]->asConfigGpu()->getColorType() == kRGB_565_SkColorType);
239 REPORTER_ASSERT(reporter, configs[46]->asConfigGpu()->getAlphaType() == kOpaque_SkAlphaType);
Brian Salomon6405e712017-03-20 08:54:16 -0400240 REPORTER_ASSERT(reporter, !configs[22]->asConfigGpu());
Brian Salomon6405e712017-03-20 08:54:16 -0400241 REPORTER_ASSERT(reporter, configs[26]->asConfigGpu());
bsalomonb8797bb2016-04-05 08:49:38 -0700242 REPORTER_ASSERT(reporter, configs[27]->asConfigGpu());
Brian Salomon6405e712017-03-20 08:54:16 -0400243 REPORTER_ASSERT(reporter, configs[27]->asConfigGpu()->getSamples() == 4);
244 REPORTER_ASSERT(reporter, configs[27]->asConfigGpu()->getUseNVPR());
bsalomonb8797bb2016-04-05 08:49:38 -0700245 REPORTER_ASSERT(reporter, configs[28]->asConfigGpu());
246 REPORTER_ASSERT(reporter, configs[28]->asConfigGpu()->getSamples() == 4);
247 REPORTER_ASSERT(reporter, configs[28]->asConfigGpu()->getUseNVPR());
Brian Salomon6405e712017-03-20 08:54:16 -0400248 REPORTER_ASSERT(reporter, configs[28]->asConfigGpu()->getUseDIText());
bsalomonb8797bb2016-04-05 08:49:38 -0700249 REPORTER_ASSERT(reporter, configs[29]->asConfigGpu());
Brian Salomon6405e712017-03-20 08:54:16 -0400250 REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getColorType() == kRGBA_8888_SkColorType);
251 REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getColorSpace() == srgbColorSpace.get());
bsalomonb8797bb2016-04-05 08:49:38 -0700252 REPORTER_ASSERT(reporter, configs[30]->asConfigGpu());
Brian Salomon6405e712017-03-20 08:54:16 -0400253 REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()->getSamples() == 4);
Brian Osmanf9810662017-08-30 10:02:10 -0400254 REPORTER_ASSERT(reporter, configs[47]->asConfigGpu());
255 REPORTER_ASSERT(reporter, configs[47]->asConfigGpu()->getTestThreading());
bsalomondc0fcd42016-04-11 14:21:33 -0700256#ifdef SK_VULKAN
Brian Salomon6405e712017-03-20 08:54:16 -0400257 REPORTER_ASSERT(reporter, configs[31]->asConfigGpu());
bsalomondc0fcd42016-04-11 14:21:33 -0700258#endif
kkinnunen3e980c32015-12-23 01:33:00 -0800259#endif
260}
261
262DEF_TEST(ParseConfigs_ExtendedGpuConfigsCorrect, reporter) {
263 SkCommandLineFlags::StringArray config1 = make_string_array({
Brian Salomon6405e712017-03-20 08:54:16 -0400264 "gpu[api=gl,nvpr=true,dit=false]",
bsalomon11abd8d2016-10-14 08:13:48 -0700265 "gpu[api=angle_d3d9_es2]",
266 "gpu[api=angle_gl_es3]",
bsalomon808ecbb2016-09-28 12:40:22 -0700267 "gpu[api=mesa,samples=77]",
268 "gpu[dit=true,api=commandbuffer]",
bsalomon808ecbb2016-09-28 12:40:22 -0700269 "gpu[api=gles]",
270 "gpu[api=gl]",
271 "gpu[api=vulkan]",
Greg Daniel2811aa22017-07-13 15:34:56 -0400272 "gpu[api=metal]",
Brian Salomon8fe24272017-07-07 12:56:11 -0400273 "gpu[api=mock]",
kkinnunen3e980c32015-12-23 01:33:00 -0800274 });
275
276 SkCommandLineConfigArray configs;
277 ParseConfigs(config1, &configs);
278 REPORTER_ASSERT(reporter, configs.count() == config1.count());
279 for (int i = 0; i < config1.count(); ++i) {
280 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
281 }
282#if SK_SUPPORT_GPU
283 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getContextType() ==
Brian Salomon6405e712017-03-20 08:54:16 -0400284 GrContextFactory::kGL_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800285 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseNVPR());
kkinnunene3c2f802015-12-29 08:57:32 -0800286 REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu()->getUseDIText());
kkinnunen3e980c32015-12-23 01:33:00 -0800287 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSamples() == 0);
kkinnunen3e980c32015-12-23 01:33:00 -0800288 REPORTER_ASSERT(reporter, configs[1]->asConfigGpu()->getContextType() ==
bsalomon11abd8d2016-10-14 08:13:48 -0700289 GrContextFactory::kANGLE_D3D9_ES2_ContextType);
290 REPORTER_ASSERT(reporter, configs[1]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800291 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu()->getContextType() ==
bsalomon11abd8d2016-10-14 08:13:48 -0700292 GrContextFactory::kANGLE_GL_ES3_ContextType);
293 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800294 REPORTER_ASSERT(reporter, !configs[3]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800295 REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()->getContextType() ==
bsalomon85b4b532016-04-05 11:06:27 -0700296 GrContextFactory::kCommandBuffer_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800297 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getContextType() ==
Brian Salomon6405e712017-03-20 08:54:16 -0400298 GrContextFactory::kGLES_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800299 REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseNVPR());
300 REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseDIText());
301 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getSamples() == 0);
302 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getContextType() ==
Brian Salomon6405e712017-03-20 08:54:16 -0400303 GrContextFactory::kGL_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800304 REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseNVPR());
305 REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseDIText());
306 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getSamples() == 0);
bsalomondc0fcd42016-04-11 14:21:33 -0700307#ifdef SK_VULKAN
Brian Salomon6405e712017-03-20 08:54:16 -0400308 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getContextType() ==
bsalomondc0fcd42016-04-11 14:21:33 -0700309 GrContextFactory::kVulkan_ContextType);
310 REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseNVPR());
311 REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseDIText());
312 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 0);
313#endif
Greg Daniel2811aa22017-07-13 15:34:56 -0400314#ifdef SK_METAL
Brian Salomon8fe24272017-07-07 12:56:11 -0400315 REPORTER_ASSERT(reporter, configs[8]->asConfigGpu()->getContextType() ==
Greg Daniel2811aa22017-07-13 15:34:56 -0400316 GrContextFactory::kMetal_ContextType);
317 REPORTER_ASSERT(reporter, !configs[8]->asConfigGpu()->getUseNVPR());
318 REPORTER_ASSERT(reporter, !configs[8]->asConfigGpu()->getUseDIText());
319 REPORTER_ASSERT(reporter, configs[8]->asConfigGpu()->getSamples() == 0);
320#endif
321 REPORTER_ASSERT(reporter, configs[9]->asConfigGpu()->getContextType() ==
Brian Salomon8fe24272017-07-07 12:56:11 -0400322 GrContextFactory::kMock_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800323#endif
324}
325
326DEF_TEST(ParseConfigs_ExtendedGpuConfigsIncorrect, reporter) {
327 SkCommandLineFlags::StringArray config1 = make_string_array({
Brian Salomon6405e712017-03-20 08:54:16 -0400328 "gpu[api=gl,nvpr=1]", // Number as bool.
bsalomon808ecbb2016-09-28 12:40:22 -0700329 "gpu[api=gl,]", // Trailing in comma.
bsalomon11abd8d2016-10-14 08:13:48 -0700330 "gpu[api=angle_glu]", // Unknown api.
bsalomon808ecbb2016-09-28 12:40:22 -0700331 "gpu[api=,samples=0]", // Empty api.
Brian Salomon6405e712017-03-20 08:54:16 -0400332 "gpu[api=gl,samples=true]", // Value true as a number.
333 "gpu[api=gl,samples=0,samples=0]", // Duplicate option key.
334 "gpu[,api=gl,samples=0]", // Leading comma.
bsalomon808ecbb2016-09-28 12:40:22 -0700335 "gpu[samples=54", // Missing closing parenthesis.
kkinnunen3e980c32015-12-23 01:33:00 -0800336 ",,",
Brian Salomon6405e712017-03-20 08:54:16 -0400337 "gpu[]", // Missing required api specifier
338 "gpu[samples=4]", // Missing required api specifier
bsalomon808ecbb2016-09-28 12:40:22 -0700339 "gpu[", // Missing bracket.
kkinnunen3e980c32015-12-23 01:33:00 -0800340 "samples=54" // No backend.
bsalomon808ecbb2016-09-28 12:40:22 -0700341 "gpu[nvpr=true ]", // Space.
kkinnunen3e980c32015-12-23 01:33:00 -0800342 });
343
344 SkCommandLineConfigArray configs;
345 ParseConfigs(config1, &configs);
346 REPORTER_ASSERT(reporter, configs.count() == config1.count());
347 for (int i = 0; i < config1.count(); ++i) {
348 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
349 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i]));
350#if SK_SUPPORT_GPU
351 REPORTER_ASSERT(reporter, !configs[i]->asConfigGpu());
352#endif
353 }
354}
355
kkinnunen3e980c32015-12-23 01:33:00 -0800356DEF_TEST(ParseConfigs_ExtendedGpuConfigsSurprises, reporter) {
357 // These just list explicitly some properties of the system.
358 SkCommandLineFlags::StringArray config1 = make_string_array({
359 // Options are not canonized -> two same configs have a different tag.
Brian Salomon6405e712017-03-20 08:54:16 -0400360 "gpu[api=gl,nvpr=true,dit=true]", "gpu[api=gl,dit=true,nvpr=true]",
361 "gpu[api=debuggl]", "gpu[api=gl]", "gpu[api=gles]", ""
362 "gpu[api=gl]", "gpu[api=gl,samples=0]", "gpu[api=gles,samples=0]"
kkinnunen3e980c32015-12-23 01:33:00 -0800363 });
364 SkCommandLineConfigArray configs;
365 ParseConfigs(config1, &configs);
366 REPORTER_ASSERT(reporter, configs.count() == config1.count());
367 for (int i = 0; i < config1.count(); ++i) {
368 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
369#if SK_SUPPORT_GPU
370 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals("gpu"));
371 REPORTER_ASSERT(reporter, configs[i]->asConfigGpu());
372#else
373 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i]));
374#endif
375 }
376}
Mike Klein2af5d682017-04-13 12:24:53 -0400377
378#if SK_SUPPORT_GPU
kkinnunen3e980c32015-12-23 01:33:00 -0800379DEF_TEST(ParseConfigs_ViaParsing, reporter) {
380 SkCommandLineFlags::StringArray config1 = make_string_array({
381 "a-b-c-8888",
382 "zz-qq-gpu",
bsalomon11abd8d2016-10-14 08:13:48 -0700383 "a-angle_gl_es2"
kkinnunen3e980c32015-12-23 01:33:00 -0800384 });
385
386 SkCommandLineConfigArray configs;
387 ParseConfigs(config1, &configs);
388 const struct {
389 const char* backend;
390 const char* vias[3];
391 } expectedConfigs[] = {
392 {"8888", {"a", "b", "c"}},
393 {"gpu", {"zz", "qq", nullptr}},
bsalomon11abd8d2016-10-14 08:13:48 -0700394 {"gpu", { "a", nullptr, nullptr }}
kkinnunen3e980c32015-12-23 01:33:00 -0800395 };
396 for (int i = 0; i < config1.count(); ++i) {
397 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
398 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend));
399 for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) {
400 if (!expectedConfigs[i].vias[j]) {
401 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == j);
402 break;
403 }
404 REPORTER_ASSERT(reporter,
405 configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j]));
406 }
407 }
408}
Mike Klein2af5d682017-04-13 12:24:53 -0400409#endif
kkinnunen3e980c32015-12-23 01:33:00 -0800410
411DEF_TEST(ParseConfigs_ViaParsingExtendedForm, reporter) {
412 SkCommandLineFlags::StringArray config1 = make_string_array({
bsalomon808ecbb2016-09-28 12:40:22 -0700413 "zz-qq-gpu[api=gles]",
bsalomon11abd8d2016-10-14 08:13:48 -0700414 "abc-nbc-cbs-gpu[api=angle_d3d9_es2,samples=1]",
Brian Salomon6405e712017-03-20 08:54:16 -0400415 "a-gpu[api=gl",
416 "abc-def-angle_gl_es2[api=gles]",
kkinnunen3e980c32015-12-23 01:33:00 -0800417 });
418
419 SkCommandLineConfigArray configs;
420 ParseConfigs(config1, &configs);
421 const struct {
422 const char* backend;
423 const char* vias[3];
424 } expectedConfigs[] = {
425#if SK_SUPPORT_GPU
426 {"gpu", {"zz", "qq", nullptr}},
bsalomon11abd8d2016-10-14 08:13:48 -0700427 {"gpu", {"abc", "nbc", "cbs"}},
kkinnunen3e980c32015-12-23 01:33:00 -0800428#else
bsalomon808ecbb2016-09-28 12:40:22 -0700429 {"gpu[api=gles]", {"zz", "qq", nullptr}},
bsalomon11abd8d2016-10-14 08:13:48 -0700430 {"gpu[api=angle_d3d9_es2,samples=1]", {"abc", "nbc", "cbs"}},
kkinnunen3e980c32015-12-23 01:33:00 -0800431#endif
Brian Salomon6405e712017-03-20 08:54:16 -0400432 {"gpu[api=gl", {"a", nullptr, nullptr}}, // Missing bracket makes this is not extended
433 // form but via still works as expected.
434 {"angle_gl_es2[api=gles]", {"abc", "def", nullptr}} // This is not extended form.
435 // angle_gl_es2 is an api type not a
436 // backend.
kkinnunen3e980c32015-12-23 01:33:00 -0800437 };
438 for (int i = 0; i < config1.count(); ++i) {
439 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
440 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend));
441 for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) {
442 if (!expectedConfigs[i].vias[j]) {
443 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() ==
444 static_cast<int>(j));
445 break;
446 }
447 REPORTER_ASSERT(reporter,
448 configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j]));
449 }
450 }
451#if SK_SUPPORT_GPU
452 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu());
bsalomon11abd8d2016-10-14 08:13:48 -0700453 REPORTER_ASSERT(reporter, configs[1]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800454 REPORTER_ASSERT(reporter, !configs[2]->asConfigGpu());
bsalomon11abd8d2016-10-14 08:13:48 -0700455 REPORTER_ASSERT(reporter, !configs[3]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800456#endif
457}