blob: 8cc3df272fb265f74a728187ad91ffb4838f6c90 [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 Salomon6405e712017-03-20 08:54:16 -040078 "565", "8888", "debuggl", "gl", "gldft", "nullgl", "glmsaa16", "glmsaa4",
79 "nonrendering", "nullgl", "gles", "glnvpr16", "glnvpr4", "glnvprdit16", "glesnvprdit4",
Brian Salomon50f66d82017-03-17 14:32:05 -040080 "pdf", "skp", "svg", "xps", "angle_d3d11_es2", "angle_gl_es2", "commandbuffer", "mesa",
Brian Salomon6405e712017-03-20 08:54:16 -040081 "hwui", "glf16", "glessrgb", "gl", "glnvpr4", "glnvprdit4", "glsrgb", "glmsaa4", "vk",
Brian Salomon50f66d82017-03-17 14:32:05 -040082 "glinst", "glinst4", "glinstdit4", "glinst16", "glinstdit16", "glesinst", "glesinst4",
83 "glesinstdit4", "glwide", "glnarrow"
kkinnunen3e980c32015-12-23 01:33:00 -080084 });
85
86 SkCommandLineConfigArray configs;
87 ParseConfigs(config1, &configs);
88
Matt Sarett77a7a1b2017-02-07 13:56:11 -050089 auto srgbColorSpace = SkColorSpace::MakeSRGB();
brianosmanb109b8c2016-06-16 13:03:24 -070090
kkinnunen3e980c32015-12-23 01:33:00 -080091 REPORTER_ASSERT(reporter, configs.count() == config1.count());
92 for (int i = 0; i < config1.count(); ++i) {
93 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
94 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == 0);
95 }
96#if SK_SUPPORT_GPU
97 REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu());
98 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu());
99 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu());
100 REPORTER_ASSERT(reporter, configs[3]->asConfigGpu());
Brian Salomon6405e712017-03-20 08:54:16 -0400101 REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()->getUseDIText());
102 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu());
103 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getSamples() == 16);
104 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 4);
105 REPORTER_ASSERT(reporter, !configs[8]->asConfigGpu());
106 REPORTER_ASSERT(reporter, configs[9]->asConfigGpu());
107 REPORTER_ASSERT(reporter, configs[10]->asConfigGpu());
108 REPORTER_ASSERT(reporter, configs[11]->asConfigGpu()->getSamples() == 16);
109 REPORTER_ASSERT(reporter, configs[11]->asConfigGpu()->getUseNVPR());
110 REPORTER_ASSERT(reporter, !configs[11]->asConfigGpu()->getUseDIText());
111 REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getSamples() == 4);
kkinnunen3e980c32015-12-23 01:33:00 -0800112 REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getUseNVPR());
cdaltonc28afdb2016-03-29 20:05:07 -0700113 REPORTER_ASSERT(reporter, !configs[12]->asConfigGpu()->getUseDIText());
Brian Salomon6405e712017-03-20 08:54:16 -0400114 REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getSamples() == 16);
kkinnunen3e980c32015-12-23 01:33:00 -0800115 REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getUseNVPR());
Brian Salomon6405e712017-03-20 08:54:16 -0400116 REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getUseDIText());
117 REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getSamples() == 4);
cdaltonc28afdb2016-03-29 20:05:07 -0700118 REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getUseNVPR());
119 REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getUseDIText());
Brian Salomon6405e712017-03-20 08:54:16 -0400120 REPORTER_ASSERT(reporter, !configs[15]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800121 REPORTER_ASSERT(reporter, !configs[16]->asConfigGpu());
122 REPORTER_ASSERT(reporter, !configs[17]->asConfigGpu());
123 REPORTER_ASSERT(reporter, !configs[18]->asConfigGpu());
Brian Salomon6405e712017-03-20 08:54:16 -0400124 REPORTER_ASSERT(reporter, !configs[23]->asConfigGpu());
125 REPORTER_ASSERT(reporter, configs[24]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType);
126 REPORTER_ASSERT(reporter, configs[24]->asConfigGpu()->getColorSpace());
127 REPORTER_ASSERT(reporter, configs[24]->asConfigGpu()->getColorSpace()->gammaIsLinear());
raftias94888332016-10-18 10:02:51 -0700128 const SkMatrix44* srgbXYZ = as_CSB(srgbColorSpace)->toXYZD50();
129 SkASSERT(srgbXYZ);
130 const SkMatrix44* config25XYZ =
Brian Salomon6405e712017-03-20 08:54:16 -0400131 as_CSB(configs[24]->asConfigGpu()->getColorSpace())->toXYZD50();
raftias94888332016-10-18 10:02:51 -0700132 SkASSERT(config25XYZ);
133 REPORTER_ASSERT(reporter, *config25XYZ == *srgbXYZ);
Brian Salomon6405e712017-03-20 08:54:16 -0400134 REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getColorType() == kRGBA_8888_SkColorType);
135 REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getColorSpace() == srgbColorSpace.get());
136 REPORTER_ASSERT(reporter, configs[40]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType);
137 REPORTER_ASSERT(reporter, configs[40]->asConfigGpu()->getColorSpace());
138 REPORTER_ASSERT(reporter, configs[40]->asConfigGpu()->getColorSpace()->gammaIsLinear());
139 const SkMatrix44* config41XYZ =
140 as_CSB(configs[40]->asConfigGpu()->getColorSpace())->toXYZD50();
141 SkASSERT(config41XYZ);
142 REPORTER_ASSERT(reporter, *config41XYZ != *srgbXYZ);
143 REPORTER_ASSERT(reporter, configs[32]->asConfigGpu()->getContextType() ==
144 GrContextFactory::kGL_ContextType);
brianosman4562f6e2016-09-19 14:42:04 -0700145 REPORTER_ASSERT(reporter, configs[41]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType);
146 REPORTER_ASSERT(reporter, configs[41]->asConfigGpu()->getColorSpace());
147 REPORTER_ASSERT(reporter, configs[41]->asConfigGpu()->getColorSpace()->gammaIsLinear());
Brian Salomon6405e712017-03-20 08:54:16 -0400148 REPORTER_ASSERT(reporter, *as_CSB(configs[41]->asConfigGpu()->getColorSpace())->toXYZD50() !=
149 *as_CSB(srgbColorSpace)->toXYZD50());
150 REPORTER_ASSERT(reporter, configs[32]->asConfigGpu()->getUseInstanced());
raftias94888332016-10-18 10:02:51 -0700151 REPORTER_ASSERT(reporter, configs[33]->asConfigGpu()->getContextType() ==
152 GrContextFactory::kGL_ContextType);
csmartdaltone0d36292016-07-29 08:14:20 -0700153 REPORTER_ASSERT(reporter, configs[33]->asConfigGpu()->getUseInstanced());
Brian Salomon6405e712017-03-20 08:54:16 -0400154 REPORTER_ASSERT(reporter, configs[33]->asConfigGpu()->getSamples() == 4);
csmartdaltone0d36292016-07-29 08:14:20 -0700155 REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getContextType() ==
156 GrContextFactory::kGL_ContextType);
157 REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getUseInstanced());
Brian Salomon6405e712017-03-20 08:54:16 -0400158 REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getUseDIText());
csmartdaltone0d36292016-07-29 08:14:20 -0700159 REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getSamples() == 4);
160 REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getContextType() ==
161 GrContextFactory::kGL_ContextType);
162 REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getUseInstanced());
Brian Salomon6405e712017-03-20 08:54:16 -0400163 REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getSamples() == 16);
csmartdaltone0d36292016-07-29 08:14:20 -0700164 REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getContextType() ==
165 GrContextFactory::kGL_ContextType);
166 REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getUseInstanced());
Brian Salomon6405e712017-03-20 08:54:16 -0400167 REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getUseDIText());
csmartdaltone0d36292016-07-29 08:14:20 -0700168 REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getSamples() == 16);
169 REPORTER_ASSERT(reporter, configs[37]->asConfigGpu()->getContextType() ==
Brian Salomon6405e712017-03-20 08:54:16 -0400170 GrContextFactory::kGLES_ContextType);
csmartdaltone0d36292016-07-29 08:14:20 -0700171 REPORTER_ASSERT(reporter, configs[37]->asConfigGpu()->getUseInstanced());
csmartdaltone0d36292016-07-29 08:14:20 -0700172 REPORTER_ASSERT(reporter, configs[38]->asConfigGpu()->getContextType() ==
173 GrContextFactory::kGLES_ContextType);
174 REPORTER_ASSERT(reporter, configs[38]->asConfigGpu()->getUseInstanced());
Brian Salomon6405e712017-03-20 08:54:16 -0400175 REPORTER_ASSERT(reporter, configs[38]->asConfigGpu()->getSamples() == 4);
csmartdaltone0d36292016-07-29 08:14:20 -0700176 REPORTER_ASSERT(reporter, configs[39]->asConfigGpu()->getContextType() ==
177 GrContextFactory::kGLES_ContextType);
178 REPORTER_ASSERT(reporter, configs[39]->asConfigGpu()->getUseInstanced());
Brian Salomon6405e712017-03-20 08:54:16 -0400179 REPORTER_ASSERT(reporter, configs[39]->asConfigGpu()->getUseDIText());
csmartdaltone0d36292016-07-29 08:14:20 -0700180 REPORTER_ASSERT(reporter, configs[39]->asConfigGpu()->getSamples() == 4);
Brian Salomon6405e712017-03-20 08:54:16 -0400181 REPORTER_ASSERT(reporter, configs[19]->asConfigGpu());
halcanary3c4521a2016-04-04 12:14:46 -0700182 REPORTER_ASSERT(reporter, configs[20]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800183 REPORTER_ASSERT(reporter, configs[21]->asConfigGpu());
halcanary3c4521a2016-04-04 12:14:46 -0700184#if SK_MESA
cdaltonc28afdb2016-03-29 20:05:07 -0700185 REPORTER_ASSERT(reporter, configs[23]->asConfigGpu());
186#else
Brian Salomon6405e712017-03-20 08:54:16 -0400187 REPORTER_ASSERT(reporter, !configs[22]->asConfigGpu());
cdaltonc28afdb2016-03-29 20:05:07 -0700188#endif
Brian Salomon6405e712017-03-20 08:54:16 -0400189 REPORTER_ASSERT(reporter, configs[26]->asConfigGpu());
bsalomonb8797bb2016-04-05 08:49:38 -0700190 REPORTER_ASSERT(reporter, configs[27]->asConfigGpu());
Brian Salomon6405e712017-03-20 08:54:16 -0400191 REPORTER_ASSERT(reporter, configs[27]->asConfigGpu()->getSamples() == 4);
192 REPORTER_ASSERT(reporter, configs[27]->asConfigGpu()->getUseNVPR());
bsalomonb8797bb2016-04-05 08:49:38 -0700193 REPORTER_ASSERT(reporter, configs[28]->asConfigGpu());
194 REPORTER_ASSERT(reporter, configs[28]->asConfigGpu()->getSamples() == 4);
195 REPORTER_ASSERT(reporter, configs[28]->asConfigGpu()->getUseNVPR());
Brian Salomon6405e712017-03-20 08:54:16 -0400196 REPORTER_ASSERT(reporter, configs[28]->asConfigGpu()->getUseDIText());
bsalomonb8797bb2016-04-05 08:49:38 -0700197 REPORTER_ASSERT(reporter, configs[29]->asConfigGpu());
Brian Salomon6405e712017-03-20 08:54:16 -0400198 REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getColorType() == kRGBA_8888_SkColorType);
199 REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getColorSpace() == srgbColorSpace.get());
bsalomonb8797bb2016-04-05 08:49:38 -0700200 REPORTER_ASSERT(reporter, configs[30]->asConfigGpu());
Brian Salomon6405e712017-03-20 08:54:16 -0400201 REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()->getSamples() == 4);
bsalomondc0fcd42016-04-11 14:21:33 -0700202#ifdef SK_VULKAN
Brian Salomon6405e712017-03-20 08:54:16 -0400203 REPORTER_ASSERT(reporter, configs[31]->asConfigGpu());
bsalomondc0fcd42016-04-11 14:21:33 -0700204#endif
kkinnunen3e980c32015-12-23 01:33:00 -0800205#endif
206}
207
208DEF_TEST(ParseConfigs_ExtendedGpuConfigsCorrect, reporter) {
209 SkCommandLineFlags::StringArray config1 = make_string_array({
Brian Salomon6405e712017-03-20 08:54:16 -0400210 "gpu[api=gl,nvpr=true,dit=false]",
bsalomon11abd8d2016-10-14 08:13:48 -0700211 "gpu[api=angle_d3d9_es2]",
212 "gpu[api=angle_gl_es3]",
bsalomon808ecbb2016-09-28 12:40:22 -0700213 "gpu[api=mesa,samples=77]",
214 "gpu[dit=true,api=commandbuffer]",
bsalomon808ecbb2016-09-28 12:40:22 -0700215 "gpu[api=gles]",
216 "gpu[api=gl]",
217 "gpu[api=vulkan]",
kkinnunen3e980c32015-12-23 01:33:00 -0800218 });
219
220 SkCommandLineConfigArray configs;
221 ParseConfigs(config1, &configs);
222 REPORTER_ASSERT(reporter, configs.count() == config1.count());
223 for (int i = 0; i < config1.count(); ++i) {
224 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
225 }
226#if SK_SUPPORT_GPU
227 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getContextType() ==
Brian Salomon6405e712017-03-20 08:54:16 -0400228 GrContextFactory::kGL_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800229 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseNVPR());
kkinnunene3c2f802015-12-29 08:57:32 -0800230 REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu()->getUseDIText());
kkinnunen3e980c32015-12-23 01:33:00 -0800231 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSamples() == 0);
kkinnunen3e980c32015-12-23 01:33:00 -0800232 REPORTER_ASSERT(reporter, configs[1]->asConfigGpu()->getContextType() ==
bsalomon11abd8d2016-10-14 08:13:48 -0700233 GrContextFactory::kANGLE_D3D9_ES2_ContextType);
234 REPORTER_ASSERT(reporter, configs[1]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800235 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu()->getContextType() ==
bsalomon11abd8d2016-10-14 08:13:48 -0700236 GrContextFactory::kANGLE_GL_ES3_ContextType);
237 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800238#if SK_MESA
239 REPORTER_ASSERT(reporter, configs[3]->asConfigGpu()->getContextType() ==
bsalomon85b4b532016-04-05 11:06:27 -0700240 GrContextFactory::kMESA_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800241#else
242 REPORTER_ASSERT(reporter, !configs[3]->asConfigGpu());
243#endif
kkinnunen3e980c32015-12-23 01:33:00 -0800244 REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()->getContextType() ==
bsalomon85b4b532016-04-05 11:06:27 -0700245 GrContextFactory::kCommandBuffer_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800246 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getContextType() ==
Brian Salomon6405e712017-03-20 08:54:16 -0400247 GrContextFactory::kGLES_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800248 REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseNVPR());
249 REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseDIText());
250 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getSamples() == 0);
251 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getContextType() ==
Brian Salomon6405e712017-03-20 08:54:16 -0400252 GrContextFactory::kGL_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800253 REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseNVPR());
254 REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseDIText());
255 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getSamples() == 0);
bsalomondc0fcd42016-04-11 14:21:33 -0700256#ifdef SK_VULKAN
Brian Salomon6405e712017-03-20 08:54:16 -0400257 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getContextType() ==
bsalomondc0fcd42016-04-11 14:21:33 -0700258 GrContextFactory::kVulkan_ContextType);
259 REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseNVPR());
260 REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseDIText());
261 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 0);
262#endif
kkinnunen3e980c32015-12-23 01:33:00 -0800263#endif
264}
265
266DEF_TEST(ParseConfigs_ExtendedGpuConfigsIncorrect, reporter) {
267 SkCommandLineFlags::StringArray config1 = make_string_array({
Brian Salomon6405e712017-03-20 08:54:16 -0400268 "gpu[api=gl,nvpr=1]", // Number as bool.
bsalomon808ecbb2016-09-28 12:40:22 -0700269 "gpu[api=gl,]", // Trailing in comma.
bsalomon11abd8d2016-10-14 08:13:48 -0700270 "gpu[api=angle_glu]", // Unknown api.
bsalomon808ecbb2016-09-28 12:40:22 -0700271 "gpu[api=,samples=0]", // Empty api.
Brian Salomon6405e712017-03-20 08:54:16 -0400272 "gpu[api=gl,samples=true]", // Value true as a number.
273 "gpu[api=gl,samples=0,samples=0]", // Duplicate option key.
274 "gpu[,api=gl,samples=0]", // Leading comma.
bsalomon808ecbb2016-09-28 12:40:22 -0700275 "gpu[samples=54", // Missing closing parenthesis.
kkinnunen3e980c32015-12-23 01:33:00 -0800276 ",,",
Brian Salomon6405e712017-03-20 08:54:16 -0400277 "gpu[]", // Missing required api specifier
278 "gpu[samples=4]", // Missing required api specifier
bsalomon808ecbb2016-09-28 12:40:22 -0700279 "gpu[", // Missing bracket.
kkinnunen3e980c32015-12-23 01:33:00 -0800280 "samples=54" // No backend.
bsalomon808ecbb2016-09-28 12:40:22 -0700281 "gpu[nvpr=true ]", // Space.
kkinnunen3e980c32015-12-23 01:33:00 -0800282 });
283
284 SkCommandLineConfigArray configs;
285 ParseConfigs(config1, &configs);
286 REPORTER_ASSERT(reporter, configs.count() == config1.count());
287 for (int i = 0; i < config1.count(); ++i) {
288 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
289 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i]));
290#if SK_SUPPORT_GPU
291 REPORTER_ASSERT(reporter, !configs[i]->asConfigGpu());
292#endif
293 }
294}
295
kkinnunen3e980c32015-12-23 01:33:00 -0800296DEF_TEST(ParseConfigs_ExtendedGpuConfigsSurprises, reporter) {
297 // These just list explicitly some properties of the system.
298 SkCommandLineFlags::StringArray config1 = make_string_array({
299 // Options are not canonized -> two same configs have a different tag.
Brian Salomon6405e712017-03-20 08:54:16 -0400300 "gpu[api=gl,nvpr=true,dit=true]", "gpu[api=gl,dit=true,nvpr=true]",
301 "gpu[api=debuggl]", "gpu[api=gl]", "gpu[api=gles]", ""
302 "gpu[api=gl]", "gpu[api=gl,samples=0]", "gpu[api=gles,samples=0]"
kkinnunen3e980c32015-12-23 01:33:00 -0800303 });
304 SkCommandLineConfigArray configs;
305 ParseConfigs(config1, &configs);
306 REPORTER_ASSERT(reporter, configs.count() == config1.count());
307 for (int i = 0; i < config1.count(); ++i) {
308 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
309#if SK_SUPPORT_GPU
310 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals("gpu"));
311 REPORTER_ASSERT(reporter, configs[i]->asConfigGpu());
312#else
313 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i]));
314#endif
315 }
316}
317DEF_TEST(ParseConfigs_ViaParsing, reporter) {
318 SkCommandLineFlags::StringArray config1 = make_string_array({
319 "a-b-c-8888",
320 "zz-qq-gpu",
bsalomon11abd8d2016-10-14 08:13:48 -0700321 "a-angle_gl_es2"
kkinnunen3e980c32015-12-23 01:33:00 -0800322 });
323
324 SkCommandLineConfigArray configs;
325 ParseConfigs(config1, &configs);
326 const struct {
327 const char* backend;
328 const char* vias[3];
329 } expectedConfigs[] = {
330 {"8888", {"a", "b", "c"}},
331 {"gpu", {"zz", "qq", nullptr}},
bsalomon11abd8d2016-10-14 08:13:48 -0700332 {"gpu", { "a", nullptr, nullptr }}
kkinnunen3e980c32015-12-23 01:33:00 -0800333 };
334 for (int i = 0; i < config1.count(); ++i) {
335 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
336 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend));
337 for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) {
338 if (!expectedConfigs[i].vias[j]) {
339 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == j);
340 break;
341 }
342 REPORTER_ASSERT(reporter,
343 configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j]));
344 }
345 }
346}
347
348DEF_TEST(ParseConfigs_ViaParsingExtendedForm, reporter) {
349 SkCommandLineFlags::StringArray config1 = make_string_array({
bsalomon808ecbb2016-09-28 12:40:22 -0700350 "zz-qq-gpu[api=gles]",
bsalomon11abd8d2016-10-14 08:13:48 -0700351 "abc-nbc-cbs-gpu[api=angle_d3d9_es2,samples=1]",
Brian Salomon6405e712017-03-20 08:54:16 -0400352 "a-gpu[api=gl",
353 "abc-def-angle_gl_es2[api=gles]",
kkinnunen3e980c32015-12-23 01:33:00 -0800354 });
355
356 SkCommandLineConfigArray configs;
357 ParseConfigs(config1, &configs);
358 const struct {
359 const char* backend;
360 const char* vias[3];
361 } expectedConfigs[] = {
362#if SK_SUPPORT_GPU
363 {"gpu", {"zz", "qq", nullptr}},
bsalomon11abd8d2016-10-14 08:13:48 -0700364 {"gpu", {"abc", "nbc", "cbs"}},
kkinnunen3e980c32015-12-23 01:33:00 -0800365#else
bsalomon808ecbb2016-09-28 12:40:22 -0700366 {"gpu[api=gles]", {"zz", "qq", nullptr}},
bsalomon11abd8d2016-10-14 08:13:48 -0700367 {"gpu[api=angle_d3d9_es2,samples=1]", {"abc", "nbc", "cbs"}},
kkinnunen3e980c32015-12-23 01:33:00 -0800368#endif
Brian Salomon6405e712017-03-20 08:54:16 -0400369 {"gpu[api=gl", {"a", nullptr, nullptr}}, // Missing bracket makes this is not extended
370 // form but via still works as expected.
371 {"angle_gl_es2[api=gles]", {"abc", "def", nullptr}} // This is not extended form.
372 // angle_gl_es2 is an api type not a
373 // backend.
kkinnunen3e980c32015-12-23 01:33:00 -0800374 };
375 for (int i = 0; i < config1.count(); ++i) {
376 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
377 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend));
378 for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) {
379 if (!expectedConfigs[i].vias[j]) {
380 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() ==
381 static_cast<int>(j));
382 break;
383 }
384 REPORTER_ASSERT(reporter,
385 configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j]));
386 }
387 }
388#if SK_SUPPORT_GPU
389 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu());
bsalomon11abd8d2016-10-14 08:13:48 -0700390 REPORTER_ASSERT(reporter, configs[1]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800391 REPORTER_ASSERT(reporter, !configs[2]->asConfigGpu());
bsalomon11abd8d2016-10-14 08:13:48 -0700392 REPORTER_ASSERT(reporter, !configs[3]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800393#endif
394}