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