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 | |
Mike Klein | 3338482 | 2018-01-26 13:58:24 -0500 | [diff] [blame] | 8 | #include "SkColorSpace.h" |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 9 | #include "SkCommonFlagsConfig.h" |
| 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); |
| 47 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseDIText() == false); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 48 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSamples() == 1); |
bsalomon | 3306925 | 2016-09-28 08:49:53 -0700 | [diff] [blame] | 49 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getColorType() == kRGBA_8888_SkColorType); |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 50 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getColorSpace() == nullptr); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 51 | #endif |
| 52 | } |
| 53 | |
| 54 | DEF_TEST(ParseConfigs_OutParam, reporter) { |
| 55 | // Clears the out parameter. |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 56 | SkCommandLineFlags::StringArray config1 = make_string_array({"gles"}); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 57 | SkCommandLineConfigArray configs; |
| 58 | ParseConfigs(config1, &configs); |
| 59 | REPORTER_ASSERT(reporter, configs.count() == 1); |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 60 | REPORTER_ASSERT(reporter, configs[0]->getTag().equals("gles")); |
bsalomon | b8797bb | 2016-04-05 08:49:38 -0700 | [diff] [blame] | 61 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 62 | SkCommandLineFlags::StringArray config2 = make_string_array({"8888"}); |
| 63 | ParseConfigs(config2, &configs); |
| 64 | REPORTER_ASSERT(reporter, configs.count() == 1); |
| 65 | REPORTER_ASSERT(reporter, configs[0]->getTag().equals("8888")); |
bsalomon | b8797bb | 2016-04-05 08:49:38 -0700 | [diff] [blame] | 66 | |
| 67 | SkCommandLineFlags::StringArray config3 = make_string_array({"gl"}); |
| 68 | ParseConfigs(config3, &configs); |
| 69 | REPORTER_ASSERT(reporter, configs.count() == 1); |
| 70 | REPORTER_ASSERT(reporter, configs[0]->getTag().equals("gl")); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | DEF_TEST(ParseConfigs_DefaultConfigs, reporter) { |
| 74 | // Parses all default configs and returns correct "tag". |
| 75 | |
| 76 | SkCommandLineFlags::StringArray config1 = make_string_array({ |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 77 | "565", |
| 78 | "8888", |
| 79 | "debuggl", |
| 80 | "gl", |
| 81 | "gldft", |
| 82 | "nullgl", |
| 83 | "glmsaa8", |
| 84 | "glmsaa4", |
| 85 | "nonrendering", |
| 86 | "nullgl", |
| 87 | "gles", |
| 88 | "glnvpr8", |
| 89 | "glnvpr4", |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 90 | "pdf", |
| 91 | "skp", |
| 92 | "svg", |
| 93 | "xps", |
| 94 | "angle_d3d11_es2", |
| 95 | "angle_gl_es2", |
| 96 | "commandbuffer", |
| 97 | "mesa", |
| 98 | "hwui", |
| 99 | "glf16", |
| 100 | "glessrgb", |
| 101 | "gl", |
| 102 | "glnvpr4", |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 103 | "glsrgb", |
| 104 | "glmsaa4", |
| 105 | "vk", |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 106 | "glwide", |
| 107 | "glnarrow", |
| 108 | "glnostencils", |
Greg Daniel | 2811aa2 | 2017-07-13 15:34:56 -0400 | [diff] [blame] | 109 | "mock", |
Brian Salomon | ce5ee60 | 2017-07-17 11:31:31 -0400 | [diff] [blame] | 110 | "mtl", |
| 111 | "gl4444", |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 112 | "gl565", |
Brian Osman | 44b6120 | 2018-03-01 10:49:26 -0500 | [diff] [blame] | 113 | "gltestthreading", |
| 114 | "gl1010102", |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 115 | }); |
| 116 | |
| 117 | SkCommandLineConfigArray configs; |
| 118 | ParseConfigs(config1, &configs); |
| 119 | |
Matt Sarett | 77a7a1b | 2017-02-07 13:56:11 -0500 | [diff] [blame] | 120 | auto srgbColorSpace = SkColorSpace::MakeSRGB(); |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 121 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 122 | REPORTER_ASSERT(reporter, configs.count() == config1.count()); |
| 123 | for (int i = 0; i < config1.count(); ++i) { |
| 124 | REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i])); |
| 125 | REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == 0); |
| 126 | } |
| 127 | #if SK_SUPPORT_GPU |
| 128 | REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu()); |
| 129 | REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu()); |
| 130 | REPORTER_ASSERT(reporter, configs[2]->asConfigGpu()); |
| 131 | REPORTER_ASSERT(reporter, configs[3]->asConfigGpu()); |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 132 | REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()->getUseDIText()); |
| 133 | REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()); |
Brian Salomon | dcf0ab0 | 2017-03-20 11:10:21 -0400 | [diff] [blame] | 134 | REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getSamples() == 8); |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 135 | REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 4); |
| 136 | REPORTER_ASSERT(reporter, !configs[8]->asConfigGpu()); |
| 137 | REPORTER_ASSERT(reporter, configs[9]->asConfigGpu()); |
| 138 | REPORTER_ASSERT(reporter, configs[10]->asConfigGpu()); |
Brian Salomon | dcf0ab0 | 2017-03-20 11:10:21 -0400 | [diff] [blame] | 139 | REPORTER_ASSERT(reporter, configs[11]->asConfigGpu()->getSamples() == 8); |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 140 | REPORTER_ASSERT(reporter, configs[11]->asConfigGpu()->getUseNVPR()); |
| 141 | REPORTER_ASSERT(reporter, !configs[11]->asConfigGpu()->getUseDIText()); |
| 142 | REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getSamples() == 4); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 143 | REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getUseNVPR()); |
cdalton | c28afdb | 2016-03-29 20:05:07 -0700 | [diff] [blame] | 144 | REPORTER_ASSERT(reporter, !configs[12]->asConfigGpu()->getUseDIText()); |
Robert Phillips | 0b33cc4 | 2018-02-08 08:29:21 -0500 | [diff] [blame] | 145 | REPORTER_ASSERT(reporter, !configs[13]->asConfigGpu()); |
| 146 | REPORTER_ASSERT(reporter, !configs[14]->asConfigGpu()); |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 147 | REPORTER_ASSERT(reporter, !configs[15]->asConfigGpu()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 148 | REPORTER_ASSERT(reporter, !configs[16]->asConfigGpu()); |
Robert Phillips | 0b33cc4 | 2018-02-08 08:29:21 -0500 | [diff] [blame] | 149 | REPORTER_ASSERT(reporter, configs[17]->asConfigGpu()); |
| 150 | REPORTER_ASSERT(reporter, configs[18]->asConfigGpu()); |
| 151 | REPORTER_ASSERT(reporter, configs[19]->asConfigGpu()); |
| 152 | REPORTER_ASSERT(reporter, !configs[20]->asConfigGpu()); |
| 153 | REPORTER_ASSERT(reporter, !configs[21]->asConfigGpu()); |
| 154 | REPORTER_ASSERT(reporter, configs[22]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType); |
| 155 | REPORTER_ASSERT(reporter, configs[22]->asConfigGpu()->getColorSpace()); |
| 156 | REPORTER_ASSERT(reporter, configs[22]->asConfigGpu()->getColorSpace()->gammaIsLinear()); |
Brian Osman | 36703d9 | 2017-12-12 14:09:31 -0500 | [diff] [blame] | 157 | const SkMatrix44* srgbXYZ = srgbColorSpace->toXYZD50(); |
raftias | 9488833 | 2016-10-18 10:02:51 -0700 | [diff] [blame] | 158 | SkASSERT(srgbXYZ); |
Robert Phillips | 0b33cc4 | 2018-02-08 08:29:21 -0500 | [diff] [blame] | 159 | const SkMatrix44* config25XYZ = configs[22]->asConfigGpu()->getColorSpace()->toXYZD50(); |
raftias | 9488833 | 2016-10-18 10:02:51 -0700 | [diff] [blame] | 160 | SkASSERT(config25XYZ); |
| 161 | REPORTER_ASSERT(reporter, *config25XYZ == *srgbXYZ); |
Robert Phillips | 0b33cc4 | 2018-02-08 08:29:21 -0500 | [diff] [blame] | 162 | REPORTER_ASSERT(reporter, configs[23]->asConfigGpu()->getColorType() == kRGBA_8888_SkColorType); |
| 163 | REPORTER_ASSERT(reporter, configs[23]->asConfigGpu()->getColorSpace() == srgbColorSpace.get()); |
| 164 | REPORTER_ASSERT(reporter, configs[24]->asConfigGpu()); |
| 165 | REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()); |
| 166 | REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getSamples() == 4); |
| 167 | REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getUseNVPR()); |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 168 | REPORTER_ASSERT(reporter, configs[26]->asConfigGpu()); |
Robert Phillips | 0b33cc4 | 2018-02-08 08:29:21 -0500 | [diff] [blame] | 169 | REPORTER_ASSERT(reporter, configs[26]->asConfigGpu()->getColorType() == kRGBA_8888_SkColorType); |
| 170 | REPORTER_ASSERT(reporter, configs[26]->asConfigGpu()->getColorSpace() == srgbColorSpace.get()); |
bsalomon | b8797bb | 2016-04-05 08:49:38 -0700 | [diff] [blame] | 171 | REPORTER_ASSERT(reporter, configs[27]->asConfigGpu()); |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 172 | REPORTER_ASSERT(reporter, configs[27]->asConfigGpu()->getSamples() == 4); |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 173 | #ifdef SK_VULKAN |
Robert Phillips | 0b33cc4 | 2018-02-08 08:29:21 -0500 | [diff] [blame] | 174 | REPORTER_ASSERT(reporter, configs[28]->asConfigGpu()); |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 175 | #endif |
Robert Phillips | 0b33cc4 | 2018-02-08 08:29:21 -0500 | [diff] [blame] | 176 | REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType); |
| 177 | REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getColorSpace()); |
| 178 | REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getColorSpace()->gammaIsLinear()); |
| 179 | const SkMatrix44* config41XYZ = configs[29]->asConfigGpu()->getColorSpace()->toXYZD50(); |
| 180 | SkASSERT(config41XYZ); |
| 181 | REPORTER_ASSERT(reporter, *config41XYZ != *srgbXYZ); |
| 182 | REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType); |
| 183 | REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()->getColorSpace()); |
| 184 | REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()->getColorSpace()->gammaIsLinear()); |
| 185 | REPORTER_ASSERT(reporter, *configs[30]->asConfigGpu()->getColorSpace()->toXYZD50() != |
| 186 | *srgbColorSpace->toXYZD50()); |
| 187 | REPORTER_ASSERT(reporter, configs[31]->asConfigGpu()->getContextType() == |
| 188 | GrContextFactory::kGL_ContextType); |
| 189 | REPORTER_ASSERT(reporter, SkToBool(configs[31]->asConfigGpu()->getContextOverrides() & |
| 190 | SkCommandLineConfigGpu::ContextOverrides::kAvoidStencilBuffers)); |
| 191 | REPORTER_ASSERT(reporter, configs[32]->asConfigGpu()->getContextType() == |
| 192 | GrContextFactory::kMock_ContextType); |
| 193 | |
| 194 | REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getContextType() == |
| 195 | GrContextFactory::kGL_ContextType); |
| 196 | REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getColorType() == kARGB_4444_SkColorType); |
| 197 | REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getAlphaType() == kPremul_SkAlphaType); |
| 198 | REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getContextType() == |
| 199 | GrContextFactory::kGL_ContextType); |
| 200 | REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getColorType() == kRGB_565_SkColorType); |
| 201 | REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getAlphaType() == kOpaque_SkAlphaType); |
| 202 | REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()); |
| 203 | REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getTestThreading()); |
Brian Osman | 44b6120 | 2018-03-01 10:49:26 -0500 | [diff] [blame] | 204 | REPORTER_ASSERT(reporter, configs[37]->asConfigGpu()); |
| 205 | REPORTER_ASSERT(reporter, configs[37]->asConfigGpu()->getColorType() == |
| 206 | kRGBA_1010102_SkColorType); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 207 | #endif |
| 208 | } |
| 209 | |
| 210 | DEF_TEST(ParseConfigs_ExtendedGpuConfigsCorrect, reporter) { |
| 211 | SkCommandLineFlags::StringArray config1 = make_string_array({ |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 212 | "gpu[api=gl,nvpr=true,dit=false]", |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 213 | "gpu[api=angle_d3d9_es2]", |
| 214 | "gpu[api=angle_gl_es3]", |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 215 | "gpu[api=mesa,samples=77]", |
| 216 | "gpu[dit=true,api=commandbuffer]", |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 217 | "gpu[api=gles]", |
| 218 | "gpu[api=gl]", |
| 219 | "gpu[api=vulkan]", |
Greg Daniel | 2811aa2 | 2017-07-13 15:34:56 -0400 | [diff] [blame] | 220 | "gpu[api=metal]", |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 221 | "gpu[api=mock]", |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 222 | }); |
| 223 | |
| 224 | SkCommandLineConfigArray configs; |
| 225 | ParseConfigs(config1, &configs); |
| 226 | REPORTER_ASSERT(reporter, configs.count() == config1.count()); |
| 227 | for (int i = 0; i < config1.count(); ++i) { |
| 228 | REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i])); |
| 229 | } |
| 230 | #if SK_SUPPORT_GPU |
| 231 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getContextType() == |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 232 | GrContextFactory::kGL_ContextType); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 233 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseNVPR()); |
kkinnunen | e3c2f80 | 2015-12-29 08:57:32 -0800 | [diff] [blame] | 234 | REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu()->getUseDIText()); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 235 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSamples() == 1); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 236 | REPORTER_ASSERT(reporter, configs[1]->asConfigGpu()->getContextType() == |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 237 | GrContextFactory::kANGLE_D3D9_ES2_ContextType); |
| 238 | REPORTER_ASSERT(reporter, configs[1]->asConfigGpu()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 239 | REPORTER_ASSERT(reporter, configs[2]->asConfigGpu()->getContextType() == |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 240 | GrContextFactory::kANGLE_GL_ES3_ContextType); |
| 241 | REPORTER_ASSERT(reporter, configs[2]->asConfigGpu()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 242 | REPORTER_ASSERT(reporter, !configs[3]->asConfigGpu()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 243 | REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()->getContextType() == |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 244 | GrContextFactory::kCommandBuffer_ContextType); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 245 | REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getContextType() == |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 246 | GrContextFactory::kGLES_ContextType); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 247 | REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseNVPR()); |
| 248 | REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseDIText()); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 249 | REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getSamples() == 1); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 250 | REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getContextType() == |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 251 | GrContextFactory::kGL_ContextType); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 252 | REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseNVPR()); |
| 253 | REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseDIText()); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 254 | REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getSamples() == 1); |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 255 | #ifdef SK_VULKAN |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 256 | REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getContextType() == |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 257 | GrContextFactory::kVulkan_ContextType); |
| 258 | REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseNVPR()); |
| 259 | REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseDIText()); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 260 | REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 1); |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 261 | #endif |
Greg Daniel | 2811aa2 | 2017-07-13 15:34:56 -0400 | [diff] [blame] | 262 | #ifdef SK_METAL |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 263 | REPORTER_ASSERT(reporter, configs[8]->asConfigGpu()->getContextType() == |
Greg Daniel | 2811aa2 | 2017-07-13 15:34:56 -0400 | [diff] [blame] | 264 | GrContextFactory::kMetal_ContextType); |
| 265 | REPORTER_ASSERT(reporter, !configs[8]->asConfigGpu()->getUseNVPR()); |
| 266 | REPORTER_ASSERT(reporter, !configs[8]->asConfigGpu()->getUseDIText()); |
| 267 | REPORTER_ASSERT(reporter, configs[8]->asConfigGpu()->getSamples() == 0); |
| 268 | #endif |
| 269 | REPORTER_ASSERT(reporter, configs[9]->asConfigGpu()->getContextType() == |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 270 | GrContextFactory::kMock_ContextType); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 271 | #endif |
| 272 | } |
| 273 | |
| 274 | DEF_TEST(ParseConfigs_ExtendedGpuConfigsIncorrect, reporter) { |
| 275 | SkCommandLineFlags::StringArray config1 = make_string_array({ |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 276 | "gpu[api=gl,nvpr=1]", // Number as bool. |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 277 | "gpu[api=gl,]", // Trailing in comma. |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 278 | "gpu[api=angle_glu]", // Unknown api. |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 279 | "gpu[api=,samples=0]", // Empty api. |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 280 | "gpu[api=gl,samples=true]", // Value true as a number. |
| 281 | "gpu[api=gl,samples=0,samples=0]", // Duplicate option key. |
| 282 | "gpu[,api=gl,samples=0]", // Leading comma. |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 283 | "gpu[samples=54", // Missing closing parenthesis. |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 284 | ",,", |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 285 | "gpu[]", // Missing required api specifier |
| 286 | "gpu[samples=4]", // Missing required api specifier |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 287 | "gpu[", // Missing bracket. |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 288 | "samples=54" // No backend. |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 289 | "gpu[nvpr=true ]", // Space. |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 290 | }); |
| 291 | |
| 292 | SkCommandLineConfigArray configs; |
| 293 | ParseConfigs(config1, &configs); |
| 294 | REPORTER_ASSERT(reporter, configs.count() == config1.count()); |
| 295 | for (int i = 0; i < config1.count(); ++i) { |
| 296 | REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i])); |
| 297 | REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i])); |
| 298 | #if SK_SUPPORT_GPU |
| 299 | REPORTER_ASSERT(reporter, !configs[i]->asConfigGpu()); |
| 300 | #endif |
| 301 | } |
| 302 | } |
| 303 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 304 | DEF_TEST(ParseConfigs_ExtendedGpuConfigsSurprises, reporter) { |
| 305 | // These just list explicitly some properties of the system. |
| 306 | SkCommandLineFlags::StringArray config1 = make_string_array({ |
| 307 | // Options are not canonized -> two same configs have a different tag. |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 308 | "gpu[api=gl,nvpr=true,dit=true]", "gpu[api=gl,dit=true,nvpr=true]", |
| 309 | "gpu[api=debuggl]", "gpu[api=gl]", "gpu[api=gles]", "" |
| 310 | "gpu[api=gl]", "gpu[api=gl,samples=0]", "gpu[api=gles,samples=0]" |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 311 | }); |
| 312 | SkCommandLineConfigArray configs; |
| 313 | ParseConfigs(config1, &configs); |
| 314 | REPORTER_ASSERT(reporter, configs.count() == config1.count()); |
| 315 | for (int i = 0; i < config1.count(); ++i) { |
| 316 | REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i])); |
| 317 | #if SK_SUPPORT_GPU |
| 318 | REPORTER_ASSERT(reporter, configs[i]->getBackend().equals("gpu")); |
| 319 | REPORTER_ASSERT(reporter, configs[i]->asConfigGpu()); |
| 320 | #else |
| 321 | REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i])); |
| 322 | #endif |
| 323 | } |
| 324 | } |
Mike Klein | 2af5d68 | 2017-04-13 12:24:53 -0400 | [diff] [blame] | 325 | |
| 326 | #if SK_SUPPORT_GPU |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 327 | DEF_TEST(ParseConfigs_ViaParsing, reporter) { |
| 328 | SkCommandLineFlags::StringArray config1 = make_string_array({ |
| 329 | "a-b-c-8888", |
| 330 | "zz-qq-gpu", |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 331 | "a-angle_gl_es2" |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 332 | }); |
| 333 | |
| 334 | SkCommandLineConfigArray configs; |
| 335 | ParseConfigs(config1, &configs); |
| 336 | const struct { |
| 337 | const char* backend; |
| 338 | const char* vias[3]; |
| 339 | } expectedConfigs[] = { |
| 340 | {"8888", {"a", "b", "c"}}, |
| 341 | {"gpu", {"zz", "qq", nullptr}}, |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 342 | {"gpu", { "a", nullptr, nullptr }} |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 343 | }; |
| 344 | for (int i = 0; i < config1.count(); ++i) { |
| 345 | REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i])); |
| 346 | REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend)); |
| 347 | for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) { |
| 348 | if (!expectedConfigs[i].vias[j]) { |
| 349 | REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == j); |
| 350 | break; |
| 351 | } |
| 352 | REPORTER_ASSERT(reporter, |
| 353 | configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j])); |
| 354 | } |
| 355 | } |
| 356 | } |
Mike Klein | 2af5d68 | 2017-04-13 12:24:53 -0400 | [diff] [blame] | 357 | #endif |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 358 | |
| 359 | DEF_TEST(ParseConfigs_ViaParsingExtendedForm, reporter) { |
| 360 | SkCommandLineFlags::StringArray config1 = make_string_array({ |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 361 | "zz-qq-gpu[api=gles]", |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 362 | "abc-nbc-cbs-gpu[api=angle_d3d9_es2,samples=1]", |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 363 | "a-gpu[api=gl", |
| 364 | "abc-def-angle_gl_es2[api=gles]", |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 365 | }); |
| 366 | |
| 367 | SkCommandLineConfigArray configs; |
| 368 | ParseConfigs(config1, &configs); |
| 369 | const struct { |
| 370 | const char* backend; |
| 371 | const char* vias[3]; |
| 372 | } expectedConfigs[] = { |
| 373 | #if SK_SUPPORT_GPU |
| 374 | {"gpu", {"zz", "qq", nullptr}}, |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 375 | {"gpu", {"abc", "nbc", "cbs"}}, |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 376 | #else |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 377 | {"gpu[api=gles]", {"zz", "qq", nullptr}}, |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 378 | {"gpu[api=angle_d3d9_es2,samples=1]", {"abc", "nbc", "cbs"}}, |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 379 | #endif |
Brian Salomon | 6405e71 | 2017-03-20 08:54:16 -0400 | [diff] [blame] | 380 | {"gpu[api=gl", {"a", nullptr, nullptr}}, // Missing bracket makes this is not extended |
| 381 | // form but via still works as expected. |
| 382 | {"angle_gl_es2[api=gles]", {"abc", "def", nullptr}} // This is not extended form. |
| 383 | // angle_gl_es2 is an api type not a |
| 384 | // backend. |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 385 | }; |
| 386 | for (int i = 0; i < config1.count(); ++i) { |
| 387 | REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i])); |
| 388 | REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend)); |
| 389 | for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) { |
| 390 | if (!expectedConfigs[i].vias[j]) { |
| 391 | REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == |
| 392 | static_cast<int>(j)); |
| 393 | break; |
| 394 | } |
| 395 | REPORTER_ASSERT(reporter, |
| 396 | configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j])); |
| 397 | } |
| 398 | } |
| 399 | #if SK_SUPPORT_GPU |
| 400 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()); |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 401 | REPORTER_ASSERT(reporter, configs[1]->asConfigGpu()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 402 | REPORTER_ASSERT(reporter, !configs[2]->asConfigGpu()); |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 403 | REPORTER_ASSERT(reporter, !configs[3]->asConfigGpu()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 404 | #endif |
| 405 | } |