blob: 6a2607ab803521e8d885018c0e470be3825f0529 [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",
122 "mtl"
kkinnunen3e980c32015-12-23 01:33:00 -0800123 });
124
125 SkCommandLineConfigArray configs;
126 ParseConfigs(config1, &configs);
127
Matt Sarett77a7a1b2017-02-07 13:56:11 -0500128 auto srgbColorSpace = SkColorSpace::MakeSRGB();
brianosmanb109b8c2016-06-16 13:03:24 -0700129
kkinnunen3e980c32015-12-23 01:33:00 -0800130 REPORTER_ASSERT(reporter, configs.count() == config1.count());
131 for (int i = 0; i < config1.count(); ++i) {
132 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
133 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == 0);
134 }
135#if SK_SUPPORT_GPU
136 REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu());
137 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu());
138 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu());
139 REPORTER_ASSERT(reporter, configs[3]->asConfigGpu());
Brian Salomon6405e712017-03-20 08:54:16 -0400140 REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()->getUseDIText());
141 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu());
Brian Salomondcf0ab02017-03-20 11:10:21 -0400142 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getSamples() == 8);
Brian Salomon6405e712017-03-20 08:54:16 -0400143 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 4);
144 REPORTER_ASSERT(reporter, !configs[8]->asConfigGpu());
145 REPORTER_ASSERT(reporter, configs[9]->asConfigGpu());
146 REPORTER_ASSERT(reporter, configs[10]->asConfigGpu());
Brian Salomondcf0ab02017-03-20 11:10:21 -0400147 REPORTER_ASSERT(reporter, configs[11]->asConfigGpu()->getSamples() == 8);
Brian Salomon6405e712017-03-20 08:54:16 -0400148 REPORTER_ASSERT(reporter, configs[11]->asConfigGpu()->getUseNVPR());
149 REPORTER_ASSERT(reporter, !configs[11]->asConfigGpu()->getUseDIText());
150 REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getSamples() == 4);
kkinnunen3e980c32015-12-23 01:33:00 -0800151 REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getUseNVPR());
cdaltonc28afdb2016-03-29 20:05:07 -0700152 REPORTER_ASSERT(reporter, !configs[12]->asConfigGpu()->getUseDIText());
Brian Salomondcf0ab02017-03-20 11:10:21 -0400153 REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getSamples() == 8);
kkinnunen3e980c32015-12-23 01:33:00 -0800154 REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getUseNVPR());
Brian Salomon6405e712017-03-20 08:54:16 -0400155 REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getUseDIText());
156 REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getSamples() == 4);
cdaltonc28afdb2016-03-29 20:05:07 -0700157 REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getUseNVPR());
158 REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getUseDIText());
Brian Salomon6405e712017-03-20 08:54:16 -0400159 REPORTER_ASSERT(reporter, !configs[15]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800160 REPORTER_ASSERT(reporter, !configs[16]->asConfigGpu());
161 REPORTER_ASSERT(reporter, !configs[17]->asConfigGpu());
162 REPORTER_ASSERT(reporter, !configs[18]->asConfigGpu());
Brian Salomon6405e712017-03-20 08:54:16 -0400163 REPORTER_ASSERT(reporter, !configs[23]->asConfigGpu());
164 REPORTER_ASSERT(reporter, configs[24]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType);
165 REPORTER_ASSERT(reporter, configs[24]->asConfigGpu()->getColorSpace());
166 REPORTER_ASSERT(reporter, configs[24]->asConfigGpu()->getColorSpace()->gammaIsLinear());
raftias94888332016-10-18 10:02:51 -0700167 const SkMatrix44* srgbXYZ = as_CSB(srgbColorSpace)->toXYZD50();
168 SkASSERT(srgbXYZ);
169 const SkMatrix44* config25XYZ =
Brian Salomon6405e712017-03-20 08:54:16 -0400170 as_CSB(configs[24]->asConfigGpu()->getColorSpace())->toXYZD50();
raftias94888332016-10-18 10:02:51 -0700171 SkASSERT(config25XYZ);
172 REPORTER_ASSERT(reporter, *config25XYZ == *srgbXYZ);
Brian Salomon6405e712017-03-20 08:54:16 -0400173 REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getColorType() == kRGBA_8888_SkColorType);
174 REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getColorSpace() == srgbColorSpace.get());
175 REPORTER_ASSERT(reporter, configs[40]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType);
176 REPORTER_ASSERT(reporter, configs[40]->asConfigGpu()->getColorSpace());
177 REPORTER_ASSERT(reporter, configs[40]->asConfigGpu()->getColorSpace()->gammaIsLinear());
178 const SkMatrix44* config41XYZ =
179 as_CSB(configs[40]->asConfigGpu()->getColorSpace())->toXYZD50();
180 SkASSERT(config41XYZ);
181 REPORTER_ASSERT(reporter, *config41XYZ != *srgbXYZ);
182 REPORTER_ASSERT(reporter, configs[32]->asConfigGpu()->getContextType() ==
183 GrContextFactory::kGL_ContextType);
brianosman4562f6e2016-09-19 14:42:04 -0700184 REPORTER_ASSERT(reporter, configs[41]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType);
185 REPORTER_ASSERT(reporter, configs[41]->asConfigGpu()->getColorSpace());
186 REPORTER_ASSERT(reporter, configs[41]->asConfigGpu()->getColorSpace()->gammaIsLinear());
Brian Salomon6405e712017-03-20 08:54:16 -0400187 REPORTER_ASSERT(reporter, *as_CSB(configs[41]->asConfigGpu()->getColorSpace())->toXYZD50() !=
188 *as_CSB(srgbColorSpace)->toXYZD50());
Brian Salomon8fe24272017-07-07 12:56:11 -0400189 REPORTER_ASSERT(reporter, configs[42]->asConfigGpu()->getContextType() ==
190 GrContextFactory::kGL_ContextType);
191 REPORTER_ASSERT(reporter, SkToBool(configs[42]->asConfigGpu()->getContextOverrides() &
192 SkCommandLineConfigGpu::ContextOverrides::kAvoidStencilBuffers));
193 REPORTER_ASSERT(reporter, configs[43]->asConfigGpu()->getContextType() ==
194 GrContextFactory::kMock_ContextType);
Brian Salomon6405e712017-03-20 08:54:16 -0400195 REPORTER_ASSERT(reporter, configs[32]->asConfigGpu()->getUseInstanced());
raftias94888332016-10-18 10:02:51 -0700196 REPORTER_ASSERT(reporter, configs[33]->asConfigGpu()->getContextType() ==
197 GrContextFactory::kGL_ContextType);
csmartdaltone0d36292016-07-29 08:14:20 -0700198 REPORTER_ASSERT(reporter, configs[33]->asConfigGpu()->getUseInstanced());
Brian Salomon6405e712017-03-20 08:54:16 -0400199 REPORTER_ASSERT(reporter, configs[33]->asConfigGpu()->getSamples() == 4);
csmartdaltone0d36292016-07-29 08:14:20 -0700200 REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getContextType() ==
201 GrContextFactory::kGL_ContextType);
202 REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getUseInstanced());
Brian Salomon6405e712017-03-20 08:54:16 -0400203 REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getUseDIText());
csmartdaltone0d36292016-07-29 08:14:20 -0700204 REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getSamples() == 4);
205 REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getContextType() ==
206 GrContextFactory::kGL_ContextType);
207 REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getUseInstanced());
Brian Salomondcf0ab02017-03-20 11:10:21 -0400208 REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getSamples() == 8);
csmartdaltone0d36292016-07-29 08:14:20 -0700209 REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getContextType() ==
210 GrContextFactory::kGL_ContextType);
211 REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getUseInstanced());
Brian Salomon6405e712017-03-20 08:54:16 -0400212 REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getUseDIText());
Brian Salomondcf0ab02017-03-20 11:10:21 -0400213 REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getSamples() == 8);
csmartdaltone0d36292016-07-29 08:14:20 -0700214 REPORTER_ASSERT(reporter, configs[37]->asConfigGpu()->getContextType() ==
Brian Salomon6405e712017-03-20 08:54:16 -0400215 GrContextFactory::kGLES_ContextType);
csmartdaltone0d36292016-07-29 08:14:20 -0700216 REPORTER_ASSERT(reporter, configs[37]->asConfigGpu()->getUseInstanced());
csmartdaltone0d36292016-07-29 08:14:20 -0700217 REPORTER_ASSERT(reporter, configs[38]->asConfigGpu()->getContextType() ==
218 GrContextFactory::kGLES_ContextType);
219 REPORTER_ASSERT(reporter, configs[38]->asConfigGpu()->getUseInstanced());
Brian Salomon6405e712017-03-20 08:54:16 -0400220 REPORTER_ASSERT(reporter, configs[38]->asConfigGpu()->getSamples() == 4);
csmartdaltone0d36292016-07-29 08:14:20 -0700221 REPORTER_ASSERT(reporter, configs[39]->asConfigGpu()->getContextType() ==
222 GrContextFactory::kGLES_ContextType);
223 REPORTER_ASSERT(reporter, configs[39]->asConfigGpu()->getUseInstanced());
Brian Salomon6405e712017-03-20 08:54:16 -0400224 REPORTER_ASSERT(reporter, configs[39]->asConfigGpu()->getUseDIText());
csmartdaltone0d36292016-07-29 08:14:20 -0700225 REPORTER_ASSERT(reporter, configs[39]->asConfigGpu()->getSamples() == 4);
Brian Salomon6405e712017-03-20 08:54:16 -0400226 REPORTER_ASSERT(reporter, configs[19]->asConfigGpu());
halcanary3c4521a2016-04-04 12:14:46 -0700227 REPORTER_ASSERT(reporter, configs[20]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800228 REPORTER_ASSERT(reporter, configs[21]->asConfigGpu());
halcanary3c4521a2016-04-04 12:14:46 -0700229#if SK_MESA
cdaltonc28afdb2016-03-29 20:05:07 -0700230 REPORTER_ASSERT(reporter, configs[23]->asConfigGpu());
231#else
Brian Salomon6405e712017-03-20 08:54:16 -0400232 REPORTER_ASSERT(reporter, !configs[22]->asConfigGpu());
cdaltonc28afdb2016-03-29 20:05:07 -0700233#endif
Brian Salomon6405e712017-03-20 08:54:16 -0400234 REPORTER_ASSERT(reporter, configs[26]->asConfigGpu());
bsalomonb8797bb2016-04-05 08:49:38 -0700235 REPORTER_ASSERT(reporter, configs[27]->asConfigGpu());
Brian Salomon6405e712017-03-20 08:54:16 -0400236 REPORTER_ASSERT(reporter, configs[27]->asConfigGpu()->getSamples() == 4);
237 REPORTER_ASSERT(reporter, configs[27]->asConfigGpu()->getUseNVPR());
bsalomonb8797bb2016-04-05 08:49:38 -0700238 REPORTER_ASSERT(reporter, configs[28]->asConfigGpu());
239 REPORTER_ASSERT(reporter, configs[28]->asConfigGpu()->getSamples() == 4);
240 REPORTER_ASSERT(reporter, configs[28]->asConfigGpu()->getUseNVPR());
Brian Salomon6405e712017-03-20 08:54:16 -0400241 REPORTER_ASSERT(reporter, configs[28]->asConfigGpu()->getUseDIText());
bsalomonb8797bb2016-04-05 08:49:38 -0700242 REPORTER_ASSERT(reporter, configs[29]->asConfigGpu());
Brian Salomon6405e712017-03-20 08:54:16 -0400243 REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getColorType() == kRGBA_8888_SkColorType);
244 REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getColorSpace() == srgbColorSpace.get());
bsalomonb8797bb2016-04-05 08:49:38 -0700245 REPORTER_ASSERT(reporter, configs[30]->asConfigGpu());
Brian Salomon6405e712017-03-20 08:54:16 -0400246 REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()->getSamples() == 4);
bsalomondc0fcd42016-04-11 14:21:33 -0700247#ifdef SK_VULKAN
Brian Salomon6405e712017-03-20 08:54:16 -0400248 REPORTER_ASSERT(reporter, configs[31]->asConfigGpu());
bsalomondc0fcd42016-04-11 14:21:33 -0700249#endif
kkinnunen3e980c32015-12-23 01:33:00 -0800250#endif
251}
252
253DEF_TEST(ParseConfigs_ExtendedGpuConfigsCorrect, reporter) {
254 SkCommandLineFlags::StringArray config1 = make_string_array({
Brian Salomon6405e712017-03-20 08:54:16 -0400255 "gpu[api=gl,nvpr=true,dit=false]",
bsalomon11abd8d2016-10-14 08:13:48 -0700256 "gpu[api=angle_d3d9_es2]",
257 "gpu[api=angle_gl_es3]",
bsalomon808ecbb2016-09-28 12:40:22 -0700258 "gpu[api=mesa,samples=77]",
259 "gpu[dit=true,api=commandbuffer]",
bsalomon808ecbb2016-09-28 12:40:22 -0700260 "gpu[api=gles]",
261 "gpu[api=gl]",
262 "gpu[api=vulkan]",
Greg Daniel2811aa22017-07-13 15:34:56 -0400263 "gpu[api=metal]",
Brian Salomon8fe24272017-07-07 12:56:11 -0400264 "gpu[api=mock]",
kkinnunen3e980c32015-12-23 01:33:00 -0800265 });
266
267 SkCommandLineConfigArray configs;
268 ParseConfigs(config1, &configs);
269 REPORTER_ASSERT(reporter, configs.count() == config1.count());
270 for (int i = 0; i < config1.count(); ++i) {
271 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
272 }
273#if SK_SUPPORT_GPU
274 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getContextType() ==
Brian Salomon6405e712017-03-20 08:54:16 -0400275 GrContextFactory::kGL_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800276 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseNVPR());
kkinnunene3c2f802015-12-29 08:57:32 -0800277 REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu()->getUseDIText());
kkinnunen3e980c32015-12-23 01:33:00 -0800278 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSamples() == 0);
kkinnunen3e980c32015-12-23 01:33:00 -0800279 REPORTER_ASSERT(reporter, configs[1]->asConfigGpu()->getContextType() ==
bsalomon11abd8d2016-10-14 08:13:48 -0700280 GrContextFactory::kANGLE_D3D9_ES2_ContextType);
281 REPORTER_ASSERT(reporter, configs[1]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800282 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu()->getContextType() ==
bsalomon11abd8d2016-10-14 08:13:48 -0700283 GrContextFactory::kANGLE_GL_ES3_ContextType);
284 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800285#if SK_MESA
286 REPORTER_ASSERT(reporter, configs[3]->asConfigGpu()->getContextType() ==
bsalomon85b4b532016-04-05 11:06:27 -0700287 GrContextFactory::kMESA_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800288#else
289 REPORTER_ASSERT(reporter, !configs[3]->asConfigGpu());
290#endif
kkinnunen3e980c32015-12-23 01:33:00 -0800291 REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()->getContextType() ==
bsalomon85b4b532016-04-05 11:06:27 -0700292 GrContextFactory::kCommandBuffer_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800293 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getContextType() ==
Brian Salomon6405e712017-03-20 08:54:16 -0400294 GrContextFactory::kGLES_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800295 REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseNVPR());
296 REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseDIText());
297 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getSamples() == 0);
298 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getContextType() ==
Brian Salomon6405e712017-03-20 08:54:16 -0400299 GrContextFactory::kGL_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800300 REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseNVPR());
301 REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseDIText());
302 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getSamples() == 0);
bsalomondc0fcd42016-04-11 14:21:33 -0700303#ifdef SK_VULKAN
Brian Salomon6405e712017-03-20 08:54:16 -0400304 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getContextType() ==
bsalomondc0fcd42016-04-11 14:21:33 -0700305 GrContextFactory::kVulkan_ContextType);
306 REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseNVPR());
307 REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseDIText());
308 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 0);
309#endif
Greg Daniel2811aa22017-07-13 15:34:56 -0400310#ifdef SK_METAL
Brian Salomon8fe24272017-07-07 12:56:11 -0400311 REPORTER_ASSERT(reporter, configs[8]->asConfigGpu()->getContextType() ==
Greg Daniel2811aa22017-07-13 15:34:56 -0400312 GrContextFactory::kMetal_ContextType);
313 REPORTER_ASSERT(reporter, !configs[8]->asConfigGpu()->getUseNVPR());
314 REPORTER_ASSERT(reporter, !configs[8]->asConfigGpu()->getUseDIText());
315 REPORTER_ASSERT(reporter, configs[8]->asConfigGpu()->getSamples() == 0);
316#endif
317 REPORTER_ASSERT(reporter, configs[9]->asConfigGpu()->getContextType() ==
Brian Salomon8fe24272017-07-07 12:56:11 -0400318 GrContextFactory::kMock_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800319#endif
320}
321
322DEF_TEST(ParseConfigs_ExtendedGpuConfigsIncorrect, reporter) {
323 SkCommandLineFlags::StringArray config1 = make_string_array({
Brian Salomon6405e712017-03-20 08:54:16 -0400324 "gpu[api=gl,nvpr=1]", // Number as bool.
bsalomon808ecbb2016-09-28 12:40:22 -0700325 "gpu[api=gl,]", // Trailing in comma.
bsalomon11abd8d2016-10-14 08:13:48 -0700326 "gpu[api=angle_glu]", // Unknown api.
bsalomon808ecbb2016-09-28 12:40:22 -0700327 "gpu[api=,samples=0]", // Empty api.
Brian Salomon6405e712017-03-20 08:54:16 -0400328 "gpu[api=gl,samples=true]", // Value true as a number.
329 "gpu[api=gl,samples=0,samples=0]", // Duplicate option key.
330 "gpu[,api=gl,samples=0]", // Leading comma.
bsalomon808ecbb2016-09-28 12:40:22 -0700331 "gpu[samples=54", // Missing closing parenthesis.
kkinnunen3e980c32015-12-23 01:33:00 -0800332 ",,",
Brian Salomon6405e712017-03-20 08:54:16 -0400333 "gpu[]", // Missing required api specifier
334 "gpu[samples=4]", // Missing required api specifier
bsalomon808ecbb2016-09-28 12:40:22 -0700335 "gpu[", // Missing bracket.
kkinnunen3e980c32015-12-23 01:33:00 -0800336 "samples=54" // No backend.
bsalomon808ecbb2016-09-28 12:40:22 -0700337 "gpu[nvpr=true ]", // Space.
kkinnunen3e980c32015-12-23 01:33:00 -0800338 });
339
340 SkCommandLineConfigArray configs;
341 ParseConfigs(config1, &configs);
342 REPORTER_ASSERT(reporter, configs.count() == config1.count());
343 for (int i = 0; i < config1.count(); ++i) {
344 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
345 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i]));
346#if SK_SUPPORT_GPU
347 REPORTER_ASSERT(reporter, !configs[i]->asConfigGpu());
348#endif
349 }
350}
351
kkinnunen3e980c32015-12-23 01:33:00 -0800352DEF_TEST(ParseConfigs_ExtendedGpuConfigsSurprises, reporter) {
353 // These just list explicitly some properties of the system.
354 SkCommandLineFlags::StringArray config1 = make_string_array({
355 // Options are not canonized -> two same configs have a different tag.
Brian Salomon6405e712017-03-20 08:54:16 -0400356 "gpu[api=gl,nvpr=true,dit=true]", "gpu[api=gl,dit=true,nvpr=true]",
357 "gpu[api=debuggl]", "gpu[api=gl]", "gpu[api=gles]", ""
358 "gpu[api=gl]", "gpu[api=gl,samples=0]", "gpu[api=gles,samples=0]"
kkinnunen3e980c32015-12-23 01:33:00 -0800359 });
360 SkCommandLineConfigArray configs;
361 ParseConfigs(config1, &configs);
362 REPORTER_ASSERT(reporter, configs.count() == config1.count());
363 for (int i = 0; i < config1.count(); ++i) {
364 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
365#if SK_SUPPORT_GPU
366 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals("gpu"));
367 REPORTER_ASSERT(reporter, configs[i]->asConfigGpu());
368#else
369 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i]));
370#endif
371 }
372}
Mike Klein2af5d682017-04-13 12:24:53 -0400373
374#if SK_SUPPORT_GPU
kkinnunen3e980c32015-12-23 01:33:00 -0800375DEF_TEST(ParseConfigs_ViaParsing, reporter) {
376 SkCommandLineFlags::StringArray config1 = make_string_array({
377 "a-b-c-8888",
378 "zz-qq-gpu",
bsalomon11abd8d2016-10-14 08:13:48 -0700379 "a-angle_gl_es2"
kkinnunen3e980c32015-12-23 01:33:00 -0800380 });
381
382 SkCommandLineConfigArray configs;
383 ParseConfigs(config1, &configs);
384 const struct {
385 const char* backend;
386 const char* vias[3];
387 } expectedConfigs[] = {
388 {"8888", {"a", "b", "c"}},
389 {"gpu", {"zz", "qq", nullptr}},
bsalomon11abd8d2016-10-14 08:13:48 -0700390 {"gpu", { "a", nullptr, nullptr }}
kkinnunen3e980c32015-12-23 01:33:00 -0800391 };
392 for (int i = 0; i < config1.count(); ++i) {
393 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
394 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend));
395 for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) {
396 if (!expectedConfigs[i].vias[j]) {
397 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == j);
398 break;
399 }
400 REPORTER_ASSERT(reporter,
401 configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j]));
402 }
403 }
404}
Mike Klein2af5d682017-04-13 12:24:53 -0400405#endif
kkinnunen3e980c32015-12-23 01:33:00 -0800406
407DEF_TEST(ParseConfigs_ViaParsingExtendedForm, reporter) {
408 SkCommandLineFlags::StringArray config1 = make_string_array({
bsalomon808ecbb2016-09-28 12:40:22 -0700409 "zz-qq-gpu[api=gles]",
bsalomon11abd8d2016-10-14 08:13:48 -0700410 "abc-nbc-cbs-gpu[api=angle_d3d9_es2,samples=1]",
Brian Salomon6405e712017-03-20 08:54:16 -0400411 "a-gpu[api=gl",
412 "abc-def-angle_gl_es2[api=gles]",
kkinnunen3e980c32015-12-23 01:33:00 -0800413 });
414
415 SkCommandLineConfigArray configs;
416 ParseConfigs(config1, &configs);
417 const struct {
418 const char* backend;
419 const char* vias[3];
420 } expectedConfigs[] = {
421#if SK_SUPPORT_GPU
422 {"gpu", {"zz", "qq", nullptr}},
bsalomon11abd8d2016-10-14 08:13:48 -0700423 {"gpu", {"abc", "nbc", "cbs"}},
kkinnunen3e980c32015-12-23 01:33:00 -0800424#else
bsalomon808ecbb2016-09-28 12:40:22 -0700425 {"gpu[api=gles]", {"zz", "qq", nullptr}},
bsalomon11abd8d2016-10-14 08:13:48 -0700426 {"gpu[api=angle_d3d9_es2,samples=1]", {"abc", "nbc", "cbs"}},
kkinnunen3e980c32015-12-23 01:33:00 -0800427#endif
Brian Salomon6405e712017-03-20 08:54:16 -0400428 {"gpu[api=gl", {"a", nullptr, nullptr}}, // Missing bracket makes this is not extended
429 // form but via still works as expected.
430 {"angle_gl_es2[api=gles]", {"abc", "def", nullptr}} // This is not extended form.
431 // angle_gl_es2 is an api type not a
432 // backend.
kkinnunen3e980c32015-12-23 01:33:00 -0800433 };
434 for (int i = 0; i < config1.count(); ++i) {
435 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
436 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend));
437 for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) {
438 if (!expectedConfigs[i].vias[j]) {
439 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() ==
440 static_cast<int>(j));
441 break;
442 }
443 REPORTER_ASSERT(reporter,
444 configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j]));
445 }
446 }
447#if SK_SUPPORT_GPU
448 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu());
bsalomon11abd8d2016-10-14 08:13:48 -0700449 REPORTER_ASSERT(reporter, configs[1]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800450 REPORTER_ASSERT(reporter, !configs[2]->asConfigGpu());
bsalomon11abd8d2016-10-14 08:13:48 -0700451 REPORTER_ASSERT(reporter, !configs[3]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800452#endif
453}