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" |
brianosman | b6095ae | 2016-06-16 13:32:51 -0700 | [diff] [blame] | 9 | #include "SkColorSpace.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". |
| 34 | // Gpu config defaults work. |
| 35 | SkCommandLineFlags::StringArray config1 = make_string_array({"gpu"}); |
| 36 | SkCommandLineConfigArray configs; |
| 37 | ParseConfigs(config1, &configs); |
| 38 | |
| 39 | REPORTER_ASSERT(reporter, configs.count() == 1); |
| 40 | REPORTER_ASSERT(reporter, configs[0]->getTag().equals("gpu")); |
| 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() |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 45 | == GrContextFactory::kNativeGL_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); |
brianosman | d93c120 | 2016-03-10 07:49:08 -0800 | [diff] [blame] | 50 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getColorType() == kN32_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. |
| 57 | SkCommandLineFlags::StringArray config1 = make_string_array({"gpu"}); |
| 58 | SkCommandLineConfigArray configs; |
| 59 | ParseConfigs(config1, &configs); |
| 60 | REPORTER_ASSERT(reporter, configs.count() == 1); |
| 61 | REPORTER_ASSERT(reporter, configs[0]->getTag().equals("gpu")); |
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({ |
| 78 | "565", "8888", "debug", "gpu", "gpudebug", "gpudft", "gpunull", "msaa16", "msaa4", |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 79 | "nonrendering", "null", "nullgpu", "nvpr16", "nvpr4", "nvprdit16", "nvprdit4", "pdf", "skp", |
| 80 | "svg", "xps", "angle", "angle-gl", "commandbuffer", "mesa", "hwui", "gpuf16", "gpusrgb", |
| 81 | "gl", "glnvpr4", "glnvprdit4", "glsrgb", "glmsaa4", "vk", "glinst", "glinst4", "glinstdit4", |
brianosman | 4562f6e | 2016-09-19 14:42:04 -0700 | [diff] [blame^] | 82 | "glinst16", "glinstdit16", "esinst", "esinst4", "esinstdit4", "glwide" |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 83 | }); |
| 84 | |
| 85 | SkCommandLineConfigArray configs; |
| 86 | ParseConfigs(config1, &configs); |
| 87 | |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 88 | auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); |
| 89 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 90 | REPORTER_ASSERT(reporter, configs.count() == config1.count()); |
| 91 | for (int i = 0; i < config1.count(); ++i) { |
| 92 | REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i])); |
| 93 | REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == 0); |
| 94 | } |
| 95 | #if SK_SUPPORT_GPU |
| 96 | REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu()); |
| 97 | REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu()); |
| 98 | REPORTER_ASSERT(reporter, configs[2]->asConfigGpu()); |
| 99 | REPORTER_ASSERT(reporter, configs[3]->asConfigGpu()); |
| 100 | REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()); |
| 101 | REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getUseDIText()); |
| 102 | REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()); |
| 103 | REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 16); |
| 104 | REPORTER_ASSERT(reporter, configs[8]->asConfigGpu()->getSamples() == 4); |
| 105 | REPORTER_ASSERT(reporter, !configs[9]->asConfigGpu()); |
| 106 | REPORTER_ASSERT(reporter, !configs[10]->asConfigGpu()); |
| 107 | REPORTER_ASSERT(reporter, configs[11]->asConfigGpu()); |
| 108 | REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getSamples() == 16); |
| 109 | REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getUseNVPR()); |
cdalton | c28afdb | 2016-03-29 20:05:07 -0700 | [diff] [blame] | 110 | REPORTER_ASSERT(reporter, !configs[12]->asConfigGpu()->getUseDIText()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 111 | REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getSamples() == 4); |
| 112 | REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getUseNVPR()); |
cdalton | c28afdb | 2016-03-29 20:05:07 -0700 | [diff] [blame] | 113 | REPORTER_ASSERT(reporter, !configs[13]->asConfigGpu()->getUseDIText()); |
| 114 | REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getSamples() == 16); |
| 115 | REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getUseNVPR()); |
| 116 | REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getUseDIText()); |
| 117 | REPORTER_ASSERT(reporter, configs[15]->asConfigGpu()->getSamples() == 4); |
| 118 | REPORTER_ASSERT(reporter, configs[15]->asConfigGpu()->getUseNVPR()); |
| 119 | REPORTER_ASSERT(reporter, configs[15]->asConfigGpu()->getUseDIText()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 120 | REPORTER_ASSERT(reporter, !configs[16]->asConfigGpu()); |
| 121 | REPORTER_ASSERT(reporter, !configs[17]->asConfigGpu()); |
| 122 | REPORTER_ASSERT(reporter, !configs[18]->asConfigGpu()); |
cdalton | c28afdb | 2016-03-29 20:05:07 -0700 | [diff] [blame] | 123 | REPORTER_ASSERT(reporter, !configs[19]->asConfigGpu()); |
halcanary | 3c4521a | 2016-04-04 12:14:46 -0700 | [diff] [blame] | 124 | REPORTER_ASSERT(reporter, !configs[24]->asConfigGpu()); |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 125 | REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType); |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 126 | REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getColorSpace()); |
msarett | 600c737 | 2016-09-07 12:03:53 -0700 | [diff] [blame] | 127 | REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getColorSpace()->gammaIsLinear()); |
brianosman | 971cd49 | 2016-09-08 10:10:11 -0700 | [diff] [blame] | 128 | REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getColorSpace()->toXYZD50() == |
| 129 | srgbColorSpace->toXYZD50()); |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 130 | REPORTER_ASSERT(reporter, configs[26]->asConfigGpu()->getColorType() == kN32_SkColorType); |
| 131 | REPORTER_ASSERT(reporter, configs[26]->asConfigGpu()->getColorSpace() == srgbColorSpace.get()); |
brianosman | 4562f6e | 2016-09-19 14:42:04 -0700 | [diff] [blame^] | 132 | REPORTER_ASSERT(reporter, configs[41]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType); |
| 133 | REPORTER_ASSERT(reporter, configs[41]->asConfigGpu()->getColorSpace()); |
| 134 | REPORTER_ASSERT(reporter, configs[41]->asConfigGpu()->getColorSpace()->gammaIsLinear()); |
| 135 | REPORTER_ASSERT(reporter, configs[41]->asConfigGpu()->getColorSpace()->toXYZD50() != |
| 136 | srgbColorSpace->toXYZD50()); |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 137 | REPORTER_ASSERT(reporter, configs[33]->asConfigGpu()->getContextType() == |
| 138 | GrContextFactory::kGL_ContextType); |
| 139 | REPORTER_ASSERT(reporter, configs[33]->asConfigGpu()->getUseInstanced()); |
| 140 | REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getContextType() == |
| 141 | GrContextFactory::kGL_ContextType); |
| 142 | REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getUseInstanced()); |
| 143 | REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getSamples() == 4); |
| 144 | REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getContextType() == |
| 145 | GrContextFactory::kGL_ContextType); |
| 146 | REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getUseInstanced()); |
| 147 | REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getUseDIText()); |
| 148 | REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getSamples() == 4); |
| 149 | REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getContextType() == |
| 150 | GrContextFactory::kGL_ContextType); |
| 151 | REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getUseInstanced()); |
| 152 | REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getSamples() == 16); |
| 153 | REPORTER_ASSERT(reporter, configs[37]->asConfigGpu()->getContextType() == |
| 154 | GrContextFactory::kGL_ContextType); |
| 155 | REPORTER_ASSERT(reporter, configs[37]->asConfigGpu()->getUseInstanced()); |
| 156 | REPORTER_ASSERT(reporter, configs[37]->asConfigGpu()->getUseDIText()); |
| 157 | REPORTER_ASSERT(reporter, configs[37]->asConfigGpu()->getSamples() == 16); |
| 158 | REPORTER_ASSERT(reporter, configs[38]->asConfigGpu()->getContextType() == |
| 159 | GrContextFactory::kGLES_ContextType); |
| 160 | REPORTER_ASSERT(reporter, configs[38]->asConfigGpu()->getUseInstanced()); |
| 161 | REPORTER_ASSERT(reporter, configs[39]->asConfigGpu()->getContextType() == |
| 162 | GrContextFactory::kGLES_ContextType); |
| 163 | REPORTER_ASSERT(reporter, configs[39]->asConfigGpu()->getUseInstanced()); |
| 164 | REPORTER_ASSERT(reporter, configs[39]->asConfigGpu()->getSamples() == 4); |
| 165 | REPORTER_ASSERT(reporter, configs[40]->asConfigGpu()->getContextType() == |
| 166 | GrContextFactory::kGLES_ContextType); |
| 167 | REPORTER_ASSERT(reporter, configs[40]->asConfigGpu()->getUseInstanced()); |
| 168 | REPORTER_ASSERT(reporter, configs[40]->asConfigGpu()->getUseDIText()); |
| 169 | REPORTER_ASSERT(reporter, configs[40]->asConfigGpu()->getSamples() == 4); |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 170 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 171 | #if SK_ANGLE |
| 172 | #ifdef SK_BUILD_FOR_WIN |
halcanary | 3c4521a | 2016-04-04 12:14:46 -0700 | [diff] [blame] | 173 | REPORTER_ASSERT(reporter, configs[20]->asConfigGpu()); |
| 174 | #else |
| 175 | REPORTER_ASSERT(reporter, !configs[20]->asConfigGpu()); |
| 176 | #endif |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 177 | REPORTER_ASSERT(reporter, configs[21]->asConfigGpu()); |
| 178 | #else |
halcanary | 3c4521a | 2016-04-04 12:14:46 -0700 | [diff] [blame] | 179 | REPORTER_ASSERT(reporter, !configs[20]->asConfigGpu()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 180 | REPORTER_ASSERT(reporter, !configs[21]->asConfigGpu()); |
| 181 | #endif |
cdalton | c28afdb | 2016-03-29 20:05:07 -0700 | [diff] [blame] | 182 | #if SK_COMMAND_BUFFER |
halcanary | 3c4521a | 2016-04-04 12:14:46 -0700 | [diff] [blame] | 183 | REPORTER_ASSERT(reporter, configs[22]->asConfigGpu()); |
| 184 | #else |
| 185 | REPORTER_ASSERT(reporter, !configs[22]->asConfigGpu()); |
| 186 | #endif |
| 187 | #if SK_MESA |
cdalton | c28afdb | 2016-03-29 20:05:07 -0700 | [diff] [blame] | 188 | REPORTER_ASSERT(reporter, configs[23]->asConfigGpu()); |
| 189 | #else |
| 190 | REPORTER_ASSERT(reporter, !configs[23]->asConfigGpu()); |
| 191 | #endif |
bsalomon | b8797bb | 2016-04-05 08:49:38 -0700 | [diff] [blame] | 192 | REPORTER_ASSERT(reporter, configs[27]->asConfigGpu()); |
| 193 | REPORTER_ASSERT(reporter, configs[28]->asConfigGpu()); |
| 194 | REPORTER_ASSERT(reporter, configs[28]->asConfigGpu()->getSamples() == 4); |
| 195 | REPORTER_ASSERT(reporter, configs[28]->asConfigGpu()->getUseNVPR()); |
| 196 | REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()); |
| 197 | REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getSamples() == 4); |
| 198 | REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getUseNVPR()); |
| 199 | REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getUseDIText()); |
| 200 | REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()); |
| 201 | REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()->getColorType() == kN32_SkColorType); |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 202 | REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()->getColorSpace() == srgbColorSpace.get()); |
bsalomon | b8797bb | 2016-04-05 08:49:38 -0700 | [diff] [blame] | 203 | REPORTER_ASSERT(reporter, configs[31]->asConfigGpu()); |
| 204 | REPORTER_ASSERT(reporter, configs[31]->asConfigGpu()->getSamples() == 4); |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 205 | #ifdef SK_VULKAN |
| 206 | REPORTER_ASSERT(reporter, configs[32]->asConfigGpu()); |
| 207 | #endif |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 208 | #endif |
| 209 | } |
| 210 | |
| 211 | DEF_TEST(ParseConfigs_ExtendedGpuConfigsCorrect, reporter) { |
| 212 | SkCommandLineFlags::StringArray config1 = make_string_array({ |
kkinnunen | e3c2f80 | 2015-12-29 08:57:32 -0800 | [diff] [blame] | 213 | "gpu(nvpr=true,dit=false)", |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 214 | "gpu(api=angle)", |
| 215 | "gpu(api=angle-gl)", |
| 216 | "gpu(api=mesa,samples=77)", |
| 217 | "gpu(dit=true,api=commandbuffer)", |
| 218 | "gpu()", |
bsalomon | b8797bb | 2016-04-05 08:49:38 -0700 | [diff] [blame] | 219 | "gpu(api=gles)", |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 220 | "gpu(api=gl)", |
| 221 | "gpu(api=vulkan)", |
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() == |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 232 | GrContextFactory::kNativeGL_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()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 235 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSamples() == 0); |
| 236 | #if SK_ANGLE |
| 237 | #ifdef SK_BUILD_FOR_WIN |
| 238 | REPORTER_ASSERT(reporter, configs[1]->asConfigGpu()->getContextType() == |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 239 | GrContextFactory::kANGLE_ContextType); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 240 | #else |
| 241 | REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu()); |
| 242 | #endif |
| 243 | REPORTER_ASSERT(reporter, configs[2]->asConfigGpu()->getContextType() == |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 244 | GrContextFactory::kANGLE_GL_ContextType); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 245 | #else |
| 246 | REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu()); |
| 247 | REPORTER_ASSERT(reporter, !configs[2]->asConfigGpu()); |
| 248 | #endif |
| 249 | #if SK_MESA |
| 250 | REPORTER_ASSERT(reporter, configs[3]->asConfigGpu()->getContextType() == |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 251 | GrContextFactory::kMESA_ContextType); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 252 | #else |
| 253 | REPORTER_ASSERT(reporter, !configs[3]->asConfigGpu()); |
| 254 | #endif |
| 255 | #if SK_COMMAND_BUFFER |
| 256 | REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()->getContextType() == |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 257 | GrContextFactory::kCommandBuffer_ContextType); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 258 | |
| 259 | #else |
| 260 | REPORTER_ASSERT(reporter, !configs[4]->asConfigGpu()); |
| 261 | #endif |
| 262 | REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getContextType() == |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 263 | GrContextFactory::kNativeGL_ContextType); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 264 | REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseNVPR()); |
| 265 | REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseDIText()); |
| 266 | REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getSamples() == 0); |
| 267 | REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getContextType() == |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 268 | GrContextFactory::kGLES_ContextType); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 269 | REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseNVPR()); |
| 270 | REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseDIText()); |
| 271 | REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getSamples() == 0); |
bsalomon | b8797bb | 2016-04-05 08:49:38 -0700 | [diff] [blame] | 272 | REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getContextType() == |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 273 | GrContextFactory::kGL_ContextType); |
bsalomon | b8797bb | 2016-04-05 08:49:38 -0700 | [diff] [blame] | 274 | REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseNVPR()); |
| 275 | REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseDIText()); |
| 276 | REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 0); |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 277 | #ifdef SK_VULKAN |
| 278 | REPORTER_ASSERT(reporter, configs[8]->asConfigGpu()->getContextType() == |
| 279 | GrContextFactory::kVulkan_ContextType); |
| 280 | REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseNVPR()); |
| 281 | REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseDIText()); |
| 282 | REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 0); |
| 283 | #endif |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 284 | #endif |
| 285 | } |
| 286 | |
| 287 | DEF_TEST(ParseConfigs_ExtendedGpuConfigsIncorrect, reporter) { |
| 288 | SkCommandLineFlags::StringArray config1 = make_string_array({ |
| 289 | "gpu(nvpr=1)", // Number as bool. |
| 290 | "gpu(api=gl,)", // Trailing in comma. |
| 291 | "gpu(api=angle-glu)", // Unknown api. |
| 292 | "gpu(api=,samples=0)", // Empty api. |
| 293 | "gpu(samples=true)", // Value true as a number. |
| 294 | "gpu(samples=0,samples=0)", // Duplicate option key. |
| 295 | "gpu(,samples=0)", // Leading comma. |
| 296 | "gpu(samples=54", // Missing closing parenthesis. |
| 297 | ",,", |
| 298 | "gpu(", // Missing parenthesis. |
| 299 | "samples=54" // No backend. |
| 300 | "gpu(nvpr=true )", // Space. |
| 301 | }); |
| 302 | |
| 303 | SkCommandLineConfigArray configs; |
| 304 | ParseConfigs(config1, &configs); |
| 305 | REPORTER_ASSERT(reporter, configs.count() == config1.count()); |
| 306 | for (int i = 0; i < config1.count(); ++i) { |
| 307 | REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i])); |
| 308 | REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i])); |
| 309 | #if SK_SUPPORT_GPU |
| 310 | REPORTER_ASSERT(reporter, !configs[i]->asConfigGpu()); |
| 311 | #endif |
| 312 | } |
| 313 | } |
| 314 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 315 | DEF_TEST(ParseConfigs_ExtendedGpuConfigsSurprises, reporter) { |
| 316 | // These just list explicitly some properties of the system. |
| 317 | SkCommandLineFlags::StringArray config1 = make_string_array({ |
| 318 | // Options are not canonized -> two same configs have a different tag. |
| 319 | "gpu(nvpr=true,dit=true)", "gpu(dit=true,nvpr=true)", |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 320 | "gpu(api=debug)", "gpu(api=gl)", "gpu(api=gles)", "" |
| 321 | "gpu", "gpu()", "gpu(samples=0)", "gpu(api=gles,samples=0)" |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 322 | }); |
| 323 | SkCommandLineConfigArray configs; |
| 324 | ParseConfigs(config1, &configs); |
| 325 | REPORTER_ASSERT(reporter, configs.count() == config1.count()); |
| 326 | for (int i = 0; i < config1.count(); ++i) { |
| 327 | REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i])); |
| 328 | #if SK_SUPPORT_GPU |
| 329 | REPORTER_ASSERT(reporter, configs[i]->getBackend().equals("gpu")); |
| 330 | REPORTER_ASSERT(reporter, configs[i]->asConfigGpu()); |
| 331 | #else |
| 332 | REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i])); |
| 333 | #endif |
| 334 | } |
| 335 | } |
| 336 | DEF_TEST(ParseConfigs_ViaParsing, reporter) { |
| 337 | SkCommandLineFlags::StringArray config1 = make_string_array({ |
| 338 | "a-b-c-8888", |
| 339 | "zz-qq-gpu", |
| 340 | "a-angle-gl" |
| 341 | }); |
| 342 | |
| 343 | SkCommandLineConfigArray configs; |
| 344 | ParseConfigs(config1, &configs); |
| 345 | const struct { |
| 346 | const char* backend; |
| 347 | const char* vias[3]; |
| 348 | } expectedConfigs[] = { |
| 349 | {"8888", {"a", "b", "c"}}, |
| 350 | {"gpu", {"zz", "qq", nullptr}}, |
brianosman | 577e025 | 2016-07-27 09:21:51 -0700 | [diff] [blame] | 351 | #if SK_ANGLE |
| 352 | { "gpu",{ "a", nullptr, nullptr } } // With SK_ANGLE, angle-gl becomes gpu(api=angle-gl) |
| 353 | #else |
| 354 | { "angle-gl",{ "a", nullptr, nullptr } } // The angle-gl tag is only tag that contains |
| 355 | // hyphen. |
| 356 | #endif |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 357 | }; |
| 358 | for (int i = 0; i < config1.count(); ++i) { |
| 359 | REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i])); |
| 360 | REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend)); |
| 361 | for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) { |
| 362 | if (!expectedConfigs[i].vias[j]) { |
| 363 | REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == j); |
| 364 | break; |
| 365 | } |
| 366 | REPORTER_ASSERT(reporter, |
| 367 | configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j])); |
| 368 | } |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | DEF_TEST(ParseConfigs_ViaParsingExtendedForm, reporter) { |
| 373 | SkCommandLineFlags::StringArray config1 = make_string_array({ |
| 374 | "zz-qq-gpu(api=gles)", |
| 375 | "a-gpu(samples=1", |
| 376 | "abc-def-angle-gl(samples=1)", |
| 377 | }); |
| 378 | |
| 379 | SkCommandLineConfigArray configs; |
| 380 | ParseConfigs(config1, &configs); |
| 381 | const struct { |
| 382 | const char* backend; |
| 383 | const char* vias[3]; |
| 384 | } expectedConfigs[] = { |
| 385 | #if SK_SUPPORT_GPU |
| 386 | {"gpu", {"zz", "qq", nullptr}}, |
| 387 | #else |
| 388 | {"gpu(api=gles)", {"zz", "qq", nullptr}}, |
| 389 | #endif |
| 390 | {"gpu(samples=1", {"a", nullptr, nullptr}}, // This is not extended form, but via still |
| 391 | // works as expected. |
| 392 | {"gl(samples=1)", {"abc", "def", "angle"}} // This is not extended form. Also |
| 393 | // angle-gl is not a "backend" in this case. |
| 394 | }; |
| 395 | for (int i = 0; i < config1.count(); ++i) { |
| 396 | REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i])); |
| 397 | REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend)); |
| 398 | for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) { |
| 399 | if (!expectedConfigs[i].vias[j]) { |
| 400 | REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == |
| 401 | static_cast<int>(j)); |
| 402 | break; |
| 403 | } |
| 404 | REPORTER_ASSERT(reporter, |
| 405 | configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j])); |
| 406 | } |
| 407 | } |
| 408 | #if SK_SUPPORT_GPU |
| 409 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()); |
| 410 | REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu()); |
| 411 | REPORTER_ASSERT(reporter, !configs[2]->asConfigGpu()); |
| 412 | #endif |
| 413 | } |