kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1 | /* |
| 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" |
msarett | 7802c3d | 2016-09-28 11:15:27 -0700 | [diff] [blame] | 9 | #include "SkColorSpace_Base.h" |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 10 | #include "Test.h" |
| 11 | #include <initializer_list> |
| 12 | |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 13 | using sk_gpu_test::GrContextFactory; |
| 14 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 15 | namespace { |
| 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. |
| 24 | SkCommandLineFlags::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 | } |
| 32 | DEF_TEST(ParseConfigs_Gpu, reporter) { |
| 33 | // Parses a normal config and returns correct "tag". |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 34 | // Simple GL config works |
| 35 | SkCommandLineFlags::StringArray config1 = make_string_array({"gl"}); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 36 | SkCommandLineConfigArray configs; |
| 37 | ParseConfigs(config1, &configs); |
| 38 | |
| 39 | REPORTER_ASSERT(reporter, configs.count() == 1); |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 40 | REPORTER_ASSERT(reporter, configs[0]->getTag().equals("gl")); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 41 | REPORTER_ASSERT(reporter, configs[0]->getViaParts().count() == 0); |
| 42 | #if SK_SUPPORT_GPU |
| 43 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()); |
| 44 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getContextType() |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 45 | == GrContextFactory::kGL_ContextType); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 46 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseNVPR() == false); |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 47 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseInstanced() == false); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 48 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseDIText() == false); |
| 49 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSamples() == 0); |
bsalomon | 3306925 | 2016-09-28 08:49:53 -0700 | [diff] [blame] | 50 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getColorType() == kRGBA_8888_SkColorType); |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 51 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getColorSpace() == nullptr); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 52 | #endif |
| 53 | } |
| 54 | |
| 55 | DEF_TEST(ParseConfigs_OutParam, reporter) { |
| 56 | // Clears the out parameter. |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 57 | SkCommandLineFlags::StringArray config1 = make_string_array({"gles"}); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 58 | SkCommandLineConfigArray configs; |
| 59 | ParseConfigs(config1, &configs); |
| 60 | REPORTER_ASSERT(reporter, configs.count() == 1); |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 61 | REPORTER_ASSERT(reporter, configs[0]->getTag().equals("gles")); |
bsalomon | b8797bb | 2016-04-05 08:49:38 -0700 | [diff] [blame] | 62 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 63 | 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")); |
bsalomon | b8797bb | 2016-04-05 08:49:38 -0700 | [diff] [blame] | 67 | |
| 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")); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | DEF_TEST(ParseConfigs_DefaultConfigs, reporter) { |
| 75 | // Parses all default configs and returns correct "tag". |
| 76 | |
| 77 | SkCommandLineFlags::StringArray config1 = make_string_array({ |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 78 | "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 Daniel | 2811aa2 | 2017-07-13 15:34:56 -0400 | [diff] [blame] | 121 | "mock", |
Brian Salomon | ce5ee60 | 2017-07-17 11:31:31 -0400 | [diff] [blame] | 122 | "mtl", |
| 123 | "gl4444", |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 124 | "gl565", |
| 125 | "gltestthreading" |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 126 | }); |
| 127 | |
| 128 | SkCommandLineConfigArray configs; |
| 129 | ParseConfigs(config1, &configs); |
| 130 | |
Matt Sarett | 77a7a1b | 2017-02-07 13:56:11 -0500 | [diff] [blame] | 131 | auto srgbColorSpace = SkColorSpace::MakeSRGB(); |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 132 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 133 | 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 Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 143 | REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()->getUseDIText()); |
| 144 | REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()); |
Brian Salomon | dcf0ab0 | 2017-03-20 11:10:21 -0400 | [diff] [blame] | 145 | REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getSamples() == 8); |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 146 | 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 Salomon | dcf0ab0 | 2017-03-20 11:10:21 -0400 | [diff] [blame] | 150 | REPORTER_ASSERT(reporter, configs[11]->asConfigGpu()->getSamples() == 8); |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 151 | REPORTER_ASSERT(reporter, configs[11]->asConfigGpu()->getUseNVPR()); |
| 152 | REPORTER_ASSERT(reporter, !configs[11]->asConfigGpu()->getUseDIText()); |
| 153 | REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getSamples() == 4); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 154 | REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getUseNVPR()); |
cdalton | c28afdb | 2016-03-29 20:05:07 -0700 | [diff] [blame] | 155 | REPORTER_ASSERT(reporter, !configs[12]->asConfigGpu()->getUseDIText()); |
Brian Salomon | dcf0ab0 | 2017-03-20 11:10:21 -0400 | [diff] [blame] | 156 | REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getSamples() == 8); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 157 | REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getUseNVPR()); |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 158 | REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getUseDIText()); |
| 159 | REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getSamples() == 4); |
cdalton | c28afdb | 2016-03-29 20:05:07 -0700 | [diff] [blame] | 160 | REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getUseNVPR()); |
| 161 | REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getUseDIText()); |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 162 | REPORTER_ASSERT(reporter, !configs[15]->asConfigGpu()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 163 | REPORTER_ASSERT(reporter, !configs[16]->asConfigGpu()); |
| 164 | REPORTER_ASSERT(reporter, !configs[17]->asConfigGpu()); |
| 165 | REPORTER_ASSERT(reporter, !configs[18]->asConfigGpu()); |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 166 | 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()); |
raftias | 9488833 | 2016-10-18 10:02:51 -0700 | [diff] [blame] | 170 | const SkMatrix44* srgbXYZ = as_CSB(srgbColorSpace)->toXYZD50(); |
| 171 | SkASSERT(srgbXYZ); |
| 172 | const SkMatrix44* config25XYZ = |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 173 | as_CSB(configs[24]->asConfigGpu()->getColorSpace())->toXYZD50(); |
raftias | 9488833 | 2016-10-18 10:02:51 -0700 | [diff] [blame] | 174 | SkASSERT(config25XYZ); |
| 175 | REPORTER_ASSERT(reporter, *config25XYZ == *srgbXYZ); |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 176 | 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); |
brianosman | 4562f6e | 2016-09-19 14:42:04 -0700 | [diff] [blame] | 187 | 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 Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 190 | REPORTER_ASSERT(reporter, *as_CSB(configs[41]->asConfigGpu()->getColorSpace())->toXYZD50() != |
| 191 | *as_CSB(srgbColorSpace)->toXYZD50()); |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 192 | 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 Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 198 | REPORTER_ASSERT(reporter, configs[32]->asConfigGpu()->getUseInstanced()); |
raftias | 9488833 | 2016-10-18 10:02:51 -0700 | [diff] [blame] | 199 | REPORTER_ASSERT(reporter, configs[33]->asConfigGpu()->getContextType() == |
| 200 | GrContextFactory::kGL_ContextType); |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 201 | REPORTER_ASSERT(reporter, configs[33]->asConfigGpu()->getUseInstanced()); |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 202 | REPORTER_ASSERT(reporter, configs[33]->asConfigGpu()->getSamples() == 4); |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 203 | REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getContextType() == |
| 204 | GrContextFactory::kGL_ContextType); |
| 205 | REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getUseInstanced()); |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 206 | REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getUseDIText()); |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 207 | 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 Salomon | dcf0ab0 | 2017-03-20 11:10:21 -0400 | [diff] [blame] | 211 | REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getSamples() == 8); |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 212 | REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getContextType() == |
| 213 | GrContextFactory::kGL_ContextType); |
| 214 | REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getUseInstanced()); |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 215 | REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getUseDIText()); |
Brian Salomon | dcf0ab0 | 2017-03-20 11:10:21 -0400 | [diff] [blame] | 216 | REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getSamples() == 8); |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 217 | REPORTER_ASSERT(reporter, configs[37]->asConfigGpu()->getContextType() == |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 218 | GrContextFactory::kGLES_ContextType); |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 219 | REPORTER_ASSERT(reporter, configs[37]->asConfigGpu()->getUseInstanced()); |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 220 | REPORTER_ASSERT(reporter, configs[38]->asConfigGpu()->getContextType() == |
| 221 | GrContextFactory::kGLES_ContextType); |
| 222 | REPORTER_ASSERT(reporter, configs[38]->asConfigGpu()->getUseInstanced()); |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 223 | REPORTER_ASSERT(reporter, configs[38]->asConfigGpu()->getSamples() == 4); |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 224 | REPORTER_ASSERT(reporter, configs[39]->asConfigGpu()->getContextType() == |
| 225 | GrContextFactory::kGLES_ContextType); |
| 226 | REPORTER_ASSERT(reporter, configs[39]->asConfigGpu()->getUseInstanced()); |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 227 | REPORTER_ASSERT(reporter, configs[39]->asConfigGpu()->getUseDIText()); |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 228 | REPORTER_ASSERT(reporter, configs[39]->asConfigGpu()->getSamples() == 4); |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 229 | REPORTER_ASSERT(reporter, configs[19]->asConfigGpu()); |
halcanary | 3c4521a | 2016-04-04 12:14:46 -0700 | [diff] [blame] | 230 | REPORTER_ASSERT(reporter, configs[20]->asConfigGpu()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 231 | REPORTER_ASSERT(reporter, configs[21]->asConfigGpu()); |
Brian Salomon | ce5ee60 | 2017-07-17 11:31:31 -0400 | [diff] [blame] | 232 | 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); |
halcanary | 3c4521a | 2016-04-04 12:14:46 -0700 | [diff] [blame] | 240 | #if SK_MESA |
cdalton | c28afdb | 2016-03-29 20:05:07 -0700 | [diff] [blame] | 241 | REPORTER_ASSERT(reporter, configs[23]->asConfigGpu()); |
| 242 | #else |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 243 | REPORTER_ASSERT(reporter, !configs[22]->asConfigGpu()); |
cdalton | c28afdb | 2016-03-29 20:05:07 -0700 | [diff] [blame] | 244 | #endif |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 245 | REPORTER_ASSERT(reporter, configs[26]->asConfigGpu()); |
bsalomon | b8797bb | 2016-04-05 08:49:38 -0700 | [diff] [blame] | 246 | REPORTER_ASSERT(reporter, configs[27]->asConfigGpu()); |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 247 | REPORTER_ASSERT(reporter, configs[27]->asConfigGpu()->getSamples() == 4); |
| 248 | REPORTER_ASSERT(reporter, configs[27]->asConfigGpu()->getUseNVPR()); |
bsalomon | b8797bb | 2016-04-05 08:49:38 -0700 | [diff] [blame] | 249 | REPORTER_ASSERT(reporter, configs[28]->asConfigGpu()); |
| 250 | REPORTER_ASSERT(reporter, configs[28]->asConfigGpu()->getSamples() == 4); |
| 251 | REPORTER_ASSERT(reporter, configs[28]->asConfigGpu()->getUseNVPR()); |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 252 | REPORTER_ASSERT(reporter, configs[28]->asConfigGpu()->getUseDIText()); |
bsalomon | b8797bb | 2016-04-05 08:49:38 -0700 | [diff] [blame] | 253 | REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()); |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 254 | REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getColorType() == kRGBA_8888_SkColorType); |
| 255 | REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getColorSpace() == srgbColorSpace.get()); |
bsalomon | b8797bb | 2016-04-05 08:49:38 -0700 | [diff] [blame] | 256 | REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()); |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 257 | REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()->getSamples() == 4); |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 258 | REPORTER_ASSERT(reporter, configs[47]->asConfigGpu()); |
| 259 | REPORTER_ASSERT(reporter, configs[47]->asConfigGpu()->getTestThreading()); |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 260 | #ifdef SK_VULKAN |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 261 | REPORTER_ASSERT(reporter, configs[31]->asConfigGpu()); |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 262 | #endif |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 263 | #endif |
| 264 | } |
| 265 | |
| 266 | DEF_TEST(ParseConfigs_ExtendedGpuConfigsCorrect, reporter) { |
| 267 | SkCommandLineFlags::StringArray config1 = make_string_array({ |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 268 | "gpu[api=gl,nvpr=true,dit=false]", |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 269 | "gpu[api=angle_d3d9_es2]", |
| 270 | "gpu[api=angle_gl_es3]", |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 271 | "gpu[api=mesa,samples=77]", |
| 272 | "gpu[dit=true,api=commandbuffer]", |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 273 | "gpu[api=gles]", |
| 274 | "gpu[api=gl]", |
| 275 | "gpu[api=vulkan]", |
Greg Daniel | 2811aa2 | 2017-07-13 15:34:56 -0400 | [diff] [blame] | 276 | "gpu[api=metal]", |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 277 | "gpu[api=mock]", |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 278 | }); |
| 279 | |
| 280 | SkCommandLineConfigArray configs; |
| 281 | ParseConfigs(config1, &configs); |
| 282 | REPORTER_ASSERT(reporter, configs.count() == config1.count()); |
| 283 | for (int i = 0; i < config1.count(); ++i) { |
| 284 | REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i])); |
| 285 | } |
| 286 | #if SK_SUPPORT_GPU |
| 287 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getContextType() == |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 288 | GrContextFactory::kGL_ContextType); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 289 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseNVPR()); |
kkinnunen | e3c2f80 | 2015-12-29 08:57:32 -0800 | [diff] [blame] | 290 | REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu()->getUseDIText()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 291 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSamples() == 0); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 292 | REPORTER_ASSERT(reporter, configs[1]->asConfigGpu()->getContextType() == |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 293 | GrContextFactory::kANGLE_D3D9_ES2_ContextType); |
| 294 | REPORTER_ASSERT(reporter, configs[1]->asConfigGpu()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 295 | REPORTER_ASSERT(reporter, configs[2]->asConfigGpu()->getContextType() == |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 296 | GrContextFactory::kANGLE_GL_ES3_ContextType); |
| 297 | REPORTER_ASSERT(reporter, configs[2]->asConfigGpu()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 298 | #if SK_MESA |
| 299 | REPORTER_ASSERT(reporter, configs[3]->asConfigGpu()->getContextType() == |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 300 | GrContextFactory::kMESA_ContextType); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 301 | #else |
| 302 | REPORTER_ASSERT(reporter, !configs[3]->asConfigGpu()); |
| 303 | #endif |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 304 | REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()->getContextType() == |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 305 | GrContextFactory::kCommandBuffer_ContextType); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 306 | REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getContextType() == |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 307 | GrContextFactory::kGLES_ContextType); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 308 | REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseNVPR()); |
| 309 | REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseDIText()); |
| 310 | REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getSamples() == 0); |
| 311 | REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getContextType() == |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 312 | GrContextFactory::kGL_ContextType); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 313 | REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseNVPR()); |
| 314 | REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseDIText()); |
| 315 | REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getSamples() == 0); |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 316 | #ifdef SK_VULKAN |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 317 | REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getContextType() == |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 318 | GrContextFactory::kVulkan_ContextType); |
| 319 | REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseNVPR()); |
| 320 | REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseDIText()); |
| 321 | REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 0); |
| 322 | #endif |
Greg Daniel | 2811aa2 | 2017-07-13 15:34:56 -0400 | [diff] [blame] | 323 | #ifdef SK_METAL |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 324 | REPORTER_ASSERT(reporter, configs[8]->asConfigGpu()->getContextType() == |
Greg Daniel | 2811aa2 | 2017-07-13 15:34:56 -0400 | [diff] [blame] | 325 | GrContextFactory::kMetal_ContextType); |
| 326 | REPORTER_ASSERT(reporter, !configs[8]->asConfigGpu()->getUseNVPR()); |
| 327 | REPORTER_ASSERT(reporter, !configs[8]->asConfigGpu()->getUseDIText()); |
| 328 | REPORTER_ASSERT(reporter, configs[8]->asConfigGpu()->getSamples() == 0); |
| 329 | #endif |
| 330 | REPORTER_ASSERT(reporter, configs[9]->asConfigGpu()->getContextType() == |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 331 | GrContextFactory::kMock_ContextType); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 332 | #endif |
| 333 | } |
| 334 | |
| 335 | DEF_TEST(ParseConfigs_ExtendedGpuConfigsIncorrect, reporter) { |
| 336 | SkCommandLineFlags::StringArray config1 = make_string_array({ |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 337 | "gpu[api=gl,nvpr=1]", // Number as bool. |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 338 | "gpu[api=gl,]", // Trailing in comma. |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 339 | "gpu[api=angle_glu]", // Unknown api. |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 340 | "gpu[api=,samples=0]", // Empty api. |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 341 | "gpu[api=gl,samples=true]", // Value true as a number. |
| 342 | "gpu[api=gl,samples=0,samples=0]", // Duplicate option key. |
| 343 | "gpu[,api=gl,samples=0]", // Leading comma. |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 344 | "gpu[samples=54", // Missing closing parenthesis. |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 345 | ",,", |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 346 | "gpu[]", // Missing required api specifier |
| 347 | "gpu[samples=4]", // Missing required api specifier |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 348 | "gpu[", // Missing bracket. |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 349 | "samples=54" // No backend. |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 350 | "gpu[nvpr=true ]", // Space. |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 351 | }); |
| 352 | |
| 353 | SkCommandLineConfigArray configs; |
| 354 | ParseConfigs(config1, &configs); |
| 355 | REPORTER_ASSERT(reporter, configs.count() == config1.count()); |
| 356 | for (int i = 0; i < config1.count(); ++i) { |
| 357 | REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i])); |
| 358 | REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i])); |
| 359 | #if SK_SUPPORT_GPU |
| 360 | REPORTER_ASSERT(reporter, !configs[i]->asConfigGpu()); |
| 361 | #endif |
| 362 | } |
| 363 | } |
| 364 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 365 | DEF_TEST(ParseConfigs_ExtendedGpuConfigsSurprises, reporter) { |
| 366 | // These just list explicitly some properties of the system. |
| 367 | SkCommandLineFlags::StringArray config1 = make_string_array({ |
| 368 | // Options are not canonized -> two same configs have a different tag. |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 369 | "gpu[api=gl,nvpr=true,dit=true]", "gpu[api=gl,dit=true,nvpr=true]", |
| 370 | "gpu[api=debuggl]", "gpu[api=gl]", "gpu[api=gles]", "" |
| 371 | "gpu[api=gl]", "gpu[api=gl,samples=0]", "gpu[api=gles,samples=0]" |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 372 | }); |
| 373 | SkCommandLineConfigArray configs; |
| 374 | ParseConfigs(config1, &configs); |
| 375 | REPORTER_ASSERT(reporter, configs.count() == config1.count()); |
| 376 | for (int i = 0; i < config1.count(); ++i) { |
| 377 | REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i])); |
| 378 | #if SK_SUPPORT_GPU |
| 379 | REPORTER_ASSERT(reporter, configs[i]->getBackend().equals("gpu")); |
| 380 | REPORTER_ASSERT(reporter, configs[i]->asConfigGpu()); |
| 381 | #else |
| 382 | REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i])); |
| 383 | #endif |
| 384 | } |
| 385 | } |
Mike Klein | 2af5d68 | 2017-04-13 12:24:53 -0400 | [diff] [blame] | 386 | |
| 387 | #if SK_SUPPORT_GPU |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 388 | DEF_TEST(ParseConfigs_ViaParsing, reporter) { |
| 389 | SkCommandLineFlags::StringArray config1 = make_string_array({ |
| 390 | "a-b-c-8888", |
| 391 | "zz-qq-gpu", |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 392 | "a-angle_gl_es2" |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 393 | }); |
| 394 | |
| 395 | SkCommandLineConfigArray configs; |
| 396 | ParseConfigs(config1, &configs); |
| 397 | const struct { |
| 398 | const char* backend; |
| 399 | const char* vias[3]; |
| 400 | } expectedConfigs[] = { |
| 401 | {"8888", {"a", "b", "c"}}, |
| 402 | {"gpu", {"zz", "qq", nullptr}}, |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 403 | {"gpu", { "a", nullptr, nullptr }} |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 404 | }; |
| 405 | for (int i = 0; i < config1.count(); ++i) { |
| 406 | REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i])); |
| 407 | REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend)); |
| 408 | for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) { |
| 409 | if (!expectedConfigs[i].vias[j]) { |
| 410 | REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == j); |
| 411 | break; |
| 412 | } |
| 413 | REPORTER_ASSERT(reporter, |
| 414 | configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j])); |
| 415 | } |
| 416 | } |
| 417 | } |
Mike Klein | 2af5d68 | 2017-04-13 12:24:53 -0400 | [diff] [blame] | 418 | #endif |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 419 | |
| 420 | DEF_TEST(ParseConfigs_ViaParsingExtendedForm, reporter) { |
| 421 | SkCommandLineFlags::StringArray config1 = make_string_array({ |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 422 | "zz-qq-gpu[api=gles]", |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 423 | "abc-nbc-cbs-gpu[api=angle_d3d9_es2,samples=1]", |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 424 | "a-gpu[api=gl", |
| 425 | "abc-def-angle_gl_es2[api=gles]", |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 426 | }); |
| 427 | |
| 428 | SkCommandLineConfigArray configs; |
| 429 | ParseConfigs(config1, &configs); |
| 430 | const struct { |
| 431 | const char* backend; |
| 432 | const char* vias[3]; |
| 433 | } expectedConfigs[] = { |
| 434 | #if SK_SUPPORT_GPU |
| 435 | {"gpu", {"zz", "qq", nullptr}}, |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 436 | {"gpu", {"abc", "nbc", "cbs"}}, |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 437 | #else |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 438 | {"gpu[api=gles]", {"zz", "qq", nullptr}}, |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 439 | {"gpu[api=angle_d3d9_es2,samples=1]", {"abc", "nbc", "cbs"}}, |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 440 | #endif |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 441 | {"gpu[api=gl", {"a", nullptr, nullptr}}, // Missing bracket makes this is not extended |
| 442 | // form but via still works as expected. |
| 443 | {"angle_gl_es2[api=gles]", {"abc", "def", nullptr}} // This is not extended form. |
| 444 | // angle_gl_es2 is an api type not a |
| 445 | // backend. |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 446 | }; |
| 447 | for (int i = 0; i < config1.count(); ++i) { |
| 448 | REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i])); |
| 449 | REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend)); |
| 450 | for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) { |
| 451 | if (!expectedConfigs[i].vias[j]) { |
| 452 | REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == |
| 453 | static_cast<int>(j)); |
| 454 | break; |
| 455 | } |
| 456 | REPORTER_ASSERT(reporter, |
| 457 | configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j])); |
| 458 | } |
| 459 | } |
| 460 | #if SK_SUPPORT_GPU |
| 461 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()); |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 462 | REPORTER_ASSERT(reporter, configs[1]->asConfigGpu()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 463 | REPORTER_ASSERT(reporter, !configs[2]->asConfigGpu()); |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 464 | REPORTER_ASSERT(reporter, !configs[3]->asConfigGpu()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 465 | #endif |
| 466 | } |