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