kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "SkCommonFlagsConfig.h" |
msarett | 7802c3d | 2016-09-28 11:15:27 -0700 | [diff] [blame] | 9 | #include "SkColorSpace_Base.h" |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 10 | #include "Test.h" |
| 11 | #include <initializer_list> |
| 12 | |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 13 | using sk_gpu_test::GrContextFactory; |
| 14 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 15 | namespace { |
| 16 | // The code |
| 17 | // SkCommandLineFlags::StringArray FLAGS_config1 = make_string_array({"a", "b"}) |
| 18 | // can be used to construct string array that one gets with command line flags. |
| 19 | // For example, the call above is equivalent of |
| 20 | // DEFINE_string(config1, "a b", ""); |
| 21 | // in cases where the default command line flag value ("a b") is used. |
| 22 | // make_string_array can be used to construct StringArray strings that have spaces in |
| 23 | // them. |
| 24 | SkCommandLineFlags::StringArray make_string_array(std::initializer_list<const char*> strings) { |
| 25 | SkTArray<SkString> array; |
| 26 | for (auto& s : strings) { |
| 27 | array.push_back(SkString(s)); |
| 28 | } |
| 29 | return SkCommandLineFlags::StringArray(array); |
| 30 | } |
| 31 | } |
| 32 | DEF_TEST(ParseConfigs_Gpu, reporter) { |
| 33 | // Parses a normal config and returns correct "tag". |
| 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); |
bsalomon | 3306925 | 2016-09-28 08:49:53 -0700 | [diff] [blame] | 50 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getColorType() == kRGBA_8888_SkColorType); |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 51 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getColorSpace() == nullptr); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 52 | #endif |
| 53 | } |
| 54 | |
| 55 | DEF_TEST(ParseConfigs_OutParam, reporter) { |
| 56 | // Clears the out parameter. |
| 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", |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 80 | "svg", "xps", "angle_d3d11_es2", "angle_gl_es2", "commandbuffer", "mesa", "hwui", "gpuf16", |
| 81 | "gpusrgb", "gl", "glnvpr4", "glnvprdit4", "glsrgb", "glmsaa4", "vk", "glinst", "glinst4", |
Brian Osman | 4a6b28e | 2016-10-17 11:14:02 -0400 | [diff] [blame] | 82 | "glinstdit4", "glinst16", "glinstdit16", "esinst", "esinst4", "esinstdit4", "glwide", |
| 83 | "glnarrow" |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 84 | }); |
| 85 | |
| 86 | SkCommandLineConfigArray configs; |
| 87 | ParseConfigs(config1, &configs); |
| 88 | |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame^] | 89 | auto srgbColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 90 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 91 | REPORTER_ASSERT(reporter, configs.count() == config1.count()); |
| 92 | for (int i = 0; i < config1.count(); ++i) { |
| 93 | REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i])); |
| 94 | REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == 0); |
| 95 | } |
| 96 | #if SK_SUPPORT_GPU |
| 97 | REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu()); |
| 98 | REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu()); |
| 99 | REPORTER_ASSERT(reporter, configs[2]->asConfigGpu()); |
| 100 | REPORTER_ASSERT(reporter, configs[3]->asConfigGpu()); |
| 101 | REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()); |
| 102 | REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getUseDIText()); |
| 103 | REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()); |
| 104 | REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 16); |
| 105 | REPORTER_ASSERT(reporter, configs[8]->asConfigGpu()->getSamples() == 4); |
| 106 | REPORTER_ASSERT(reporter, !configs[9]->asConfigGpu()); |
| 107 | REPORTER_ASSERT(reporter, !configs[10]->asConfigGpu()); |
| 108 | REPORTER_ASSERT(reporter, configs[11]->asConfigGpu()); |
| 109 | REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getSamples() == 16); |
| 110 | REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getUseNVPR()); |
cdalton | c28afdb | 2016-03-29 20:05:07 -0700 | [diff] [blame] | 111 | REPORTER_ASSERT(reporter, !configs[12]->asConfigGpu()->getUseDIText()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 112 | REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getSamples() == 4); |
| 113 | REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getUseNVPR()); |
cdalton | c28afdb | 2016-03-29 20:05:07 -0700 | [diff] [blame] | 114 | REPORTER_ASSERT(reporter, !configs[13]->asConfigGpu()->getUseDIText()); |
| 115 | REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getSamples() == 16); |
| 116 | REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getUseNVPR()); |
| 117 | REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getUseDIText()); |
| 118 | REPORTER_ASSERT(reporter, configs[15]->asConfigGpu()->getSamples() == 4); |
| 119 | REPORTER_ASSERT(reporter, configs[15]->asConfigGpu()->getUseNVPR()); |
| 120 | REPORTER_ASSERT(reporter, configs[15]->asConfigGpu()->getUseDIText()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 121 | REPORTER_ASSERT(reporter, !configs[16]->asConfigGpu()); |
| 122 | REPORTER_ASSERT(reporter, !configs[17]->asConfigGpu()); |
| 123 | REPORTER_ASSERT(reporter, !configs[18]->asConfigGpu()); |
cdalton | c28afdb | 2016-03-29 20:05:07 -0700 | [diff] [blame] | 124 | REPORTER_ASSERT(reporter, !configs[19]->asConfigGpu()); |
halcanary | 3c4521a | 2016-04-04 12:14:46 -0700 | [diff] [blame] | 125 | REPORTER_ASSERT(reporter, !configs[24]->asConfigGpu()); |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 126 | REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType); |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 127 | REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getColorSpace()); |
msarett | 600c737 | 2016-09-07 12:03:53 -0700 | [diff] [blame] | 128 | REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getColorSpace()->gammaIsLinear()); |
raftias | 9488833 | 2016-10-18 10:02:51 -0700 | [diff] [blame] | 129 | const SkMatrix44* srgbXYZ = as_CSB(srgbColorSpace)->toXYZD50(); |
| 130 | SkASSERT(srgbXYZ); |
| 131 | const SkMatrix44* config25XYZ = |
| 132 | as_CSB(configs[25]->asConfigGpu()->getColorSpace())->toXYZD50(); |
| 133 | SkASSERT(config25XYZ); |
| 134 | REPORTER_ASSERT(reporter, *config25XYZ == *srgbXYZ); |
bsalomon | 3306925 | 2016-09-28 08:49:53 -0700 | [diff] [blame] | 135 | REPORTER_ASSERT(reporter, configs[26]->asConfigGpu()->getColorType() == kRGBA_8888_SkColorType); |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 136 | REPORTER_ASSERT(reporter, configs[26]->asConfigGpu()->getColorSpace() == srgbColorSpace.get()); |
brianosman | 4562f6e | 2016-09-19 14:42:04 -0700 | [diff] [blame] | 137 | REPORTER_ASSERT(reporter, configs[41]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType); |
| 138 | REPORTER_ASSERT(reporter, configs[41]->asConfigGpu()->getColorSpace()); |
| 139 | REPORTER_ASSERT(reporter, configs[41]->asConfigGpu()->getColorSpace()->gammaIsLinear()); |
raftias | 9488833 | 2016-10-18 10:02:51 -0700 | [diff] [blame] | 140 | const SkMatrix44* config41XYZ = |
| 141 | as_CSB(configs[41]->asConfigGpu()->getColorSpace())->toXYZD50(); |
| 142 | SkASSERT(config41XYZ); |
| 143 | REPORTER_ASSERT(reporter, *config41XYZ != *srgbXYZ); |
| 144 | REPORTER_ASSERT(reporter, configs[33]->asConfigGpu()->getContextType() == |
| 145 | GrContextFactory::kGL_ContextType); |
Brian Osman | 4a6b28e | 2016-10-17 11:14:02 -0400 | [diff] [blame] | 146 | REPORTER_ASSERT(reporter, configs[42]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType); |
| 147 | REPORTER_ASSERT(reporter, configs[42]->asConfigGpu()->getColorSpace()); |
| 148 | REPORTER_ASSERT(reporter, configs[42]->asConfigGpu()->getColorSpace()->gammaIsLinear()); |
raftias | 9488833 | 2016-10-18 10:02:51 -0700 | [diff] [blame] | 149 | REPORTER_ASSERT(reporter, *as_CSB(configs[42]->asConfigGpu()->getColorSpace())->toXYZD50() != |
| 150 | *as_CSB(srgbColorSpace)->toXYZD50()); |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 151 | REPORTER_ASSERT(reporter, configs[33]->asConfigGpu()->getUseInstanced()); |
| 152 | REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getContextType() == |
| 153 | GrContextFactory::kGL_ContextType); |
| 154 | REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getUseInstanced()); |
| 155 | REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getSamples() == 4); |
| 156 | REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getContextType() == |
| 157 | GrContextFactory::kGL_ContextType); |
| 158 | REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getUseInstanced()); |
| 159 | REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getUseDIText()); |
| 160 | REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getSamples() == 4); |
| 161 | REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getContextType() == |
| 162 | GrContextFactory::kGL_ContextType); |
| 163 | REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getUseInstanced()); |
| 164 | REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getSamples() == 16); |
| 165 | REPORTER_ASSERT(reporter, configs[37]->asConfigGpu()->getContextType() == |
| 166 | GrContextFactory::kGL_ContextType); |
| 167 | REPORTER_ASSERT(reporter, configs[37]->asConfigGpu()->getUseInstanced()); |
| 168 | REPORTER_ASSERT(reporter, configs[37]->asConfigGpu()->getUseDIText()); |
| 169 | REPORTER_ASSERT(reporter, configs[37]->asConfigGpu()->getSamples() == 16); |
| 170 | REPORTER_ASSERT(reporter, configs[38]->asConfigGpu()->getContextType() == |
| 171 | GrContextFactory::kGLES_ContextType); |
| 172 | REPORTER_ASSERT(reporter, configs[38]->asConfigGpu()->getUseInstanced()); |
| 173 | REPORTER_ASSERT(reporter, configs[39]->asConfigGpu()->getContextType() == |
| 174 | GrContextFactory::kGLES_ContextType); |
| 175 | REPORTER_ASSERT(reporter, configs[39]->asConfigGpu()->getUseInstanced()); |
| 176 | REPORTER_ASSERT(reporter, configs[39]->asConfigGpu()->getSamples() == 4); |
| 177 | REPORTER_ASSERT(reporter, configs[40]->asConfigGpu()->getContextType() == |
| 178 | GrContextFactory::kGLES_ContextType); |
| 179 | REPORTER_ASSERT(reporter, configs[40]->asConfigGpu()->getUseInstanced()); |
| 180 | REPORTER_ASSERT(reporter, configs[40]->asConfigGpu()->getUseDIText()); |
| 181 | REPORTER_ASSERT(reporter, configs[40]->asConfigGpu()->getSamples() == 4); |
halcanary | 3c4521a | 2016-04-04 12:14:46 -0700 | [diff] [blame] | 182 | REPORTER_ASSERT(reporter, configs[20]->asConfigGpu()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 183 | REPORTER_ASSERT(reporter, configs[21]->asConfigGpu()); |
halcanary | 3c4521a | 2016-04-04 12:14:46 -0700 | [diff] [blame] | 184 | REPORTER_ASSERT(reporter, configs[22]->asConfigGpu()); |
halcanary | 3c4521a | 2016-04-04 12:14:46 -0700 | [diff] [blame] | 185 | #if SK_MESA |
cdalton | c28afdb | 2016-03-29 20:05:07 -0700 | [diff] [blame] | 186 | REPORTER_ASSERT(reporter, configs[23]->asConfigGpu()); |
| 187 | #else |
| 188 | REPORTER_ASSERT(reporter, !configs[23]->asConfigGpu()); |
| 189 | #endif |
bsalomon | b8797bb | 2016-04-05 08:49:38 -0700 | [diff] [blame] | 190 | REPORTER_ASSERT(reporter, configs[27]->asConfigGpu()); |
| 191 | REPORTER_ASSERT(reporter, configs[28]->asConfigGpu()); |
| 192 | REPORTER_ASSERT(reporter, configs[28]->asConfigGpu()->getSamples() == 4); |
| 193 | REPORTER_ASSERT(reporter, configs[28]->asConfigGpu()->getUseNVPR()); |
| 194 | REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()); |
| 195 | REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getSamples() == 4); |
| 196 | REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getUseNVPR()); |
| 197 | REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getUseDIText()); |
| 198 | REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()); |
bsalomon | 3306925 | 2016-09-28 08:49:53 -0700 | [diff] [blame] | 199 | REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()->getColorType() == kRGBA_8888_SkColorType); |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 200 | REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()->getColorSpace() == srgbColorSpace.get()); |
bsalomon | b8797bb | 2016-04-05 08:49:38 -0700 | [diff] [blame] | 201 | REPORTER_ASSERT(reporter, configs[31]->asConfigGpu()); |
| 202 | REPORTER_ASSERT(reporter, configs[31]->asConfigGpu()->getSamples() == 4); |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 203 | #ifdef SK_VULKAN |
| 204 | REPORTER_ASSERT(reporter, configs[32]->asConfigGpu()); |
| 205 | #endif |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 206 | #endif |
| 207 | } |
| 208 | |
| 209 | DEF_TEST(ParseConfigs_ExtendedGpuConfigsCorrect, reporter) { |
| 210 | SkCommandLineFlags::StringArray config1 = make_string_array({ |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 211 | "gpu[nvpr=true,dit=false]", |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 212 | "gpu[api=angle_d3d9_es2]", |
| 213 | "gpu[api=angle_gl_es3]", |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 214 | "gpu[api=mesa,samples=77]", |
| 215 | "gpu[dit=true,api=commandbuffer]", |
| 216 | "gpu[]", |
| 217 | "gpu[api=gles]", |
| 218 | "gpu[api=gl]", |
| 219 | "gpu[api=vulkan]", |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 220 | }); |
| 221 | |
| 222 | SkCommandLineConfigArray configs; |
| 223 | ParseConfigs(config1, &configs); |
| 224 | REPORTER_ASSERT(reporter, configs.count() == config1.count()); |
| 225 | for (int i = 0; i < config1.count(); ++i) { |
| 226 | REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i])); |
| 227 | } |
| 228 | #if SK_SUPPORT_GPU |
| 229 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getContextType() == |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 230 | GrContextFactory::kNativeGL_ContextType); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 231 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseNVPR()); |
kkinnunen | e3c2f80 | 2015-12-29 08:57:32 -0800 | [diff] [blame] | 232 | REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu()->getUseDIText()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 233 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSamples() == 0); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 234 | REPORTER_ASSERT(reporter, configs[1]->asConfigGpu()->getContextType() == |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 235 | GrContextFactory::kANGLE_D3D9_ES2_ContextType); |
| 236 | REPORTER_ASSERT(reporter, configs[1]->asConfigGpu()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 237 | REPORTER_ASSERT(reporter, configs[2]->asConfigGpu()->getContextType() == |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 238 | GrContextFactory::kANGLE_GL_ES3_ContextType); |
| 239 | REPORTER_ASSERT(reporter, configs[2]->asConfigGpu()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 240 | #if SK_MESA |
| 241 | REPORTER_ASSERT(reporter, configs[3]->asConfigGpu()->getContextType() == |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 242 | GrContextFactory::kMESA_ContextType); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 243 | #else |
| 244 | REPORTER_ASSERT(reporter, !configs[3]->asConfigGpu()); |
| 245 | #endif |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 246 | REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()->getContextType() == |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 247 | GrContextFactory::kCommandBuffer_ContextType); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 248 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 249 | REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getContextType() == |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 250 | GrContextFactory::kNativeGL_ContextType); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 251 | REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseNVPR()); |
| 252 | REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseDIText()); |
| 253 | REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getSamples() == 0); |
| 254 | REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getContextType() == |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 255 | GrContextFactory::kGLES_ContextType); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 256 | REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseNVPR()); |
| 257 | REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseDIText()); |
| 258 | REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getSamples() == 0); |
bsalomon | b8797bb | 2016-04-05 08:49:38 -0700 | [diff] [blame] | 259 | REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getContextType() == |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 260 | GrContextFactory::kGL_ContextType); |
bsalomon | b8797bb | 2016-04-05 08:49:38 -0700 | [diff] [blame] | 261 | REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseNVPR()); |
| 262 | REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseDIText()); |
| 263 | REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 0); |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 264 | #ifdef SK_VULKAN |
| 265 | REPORTER_ASSERT(reporter, configs[8]->asConfigGpu()->getContextType() == |
| 266 | GrContextFactory::kVulkan_ContextType); |
| 267 | REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseNVPR()); |
| 268 | REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseDIText()); |
| 269 | REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 0); |
| 270 | #endif |
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({ |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 276 | "gpu[nvpr=1]", // Number as bool. |
| 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. |
| 280 | "gpu[samples=true]", // Value true as a number. |
| 281 | "gpu[samples=0,samples=0]", // Duplicate option key. |
| 282 | "gpu[,samples=0]", // Leading comma. |
| 283 | "gpu[samples=54", // Missing closing parenthesis. |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 284 | ",,", |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 285 | "gpu[", // Missing bracket. |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 286 | "samples=54" // No backend. |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 287 | "gpu[nvpr=true ]", // Space. |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 288 | }); |
| 289 | |
| 290 | SkCommandLineConfigArray configs; |
| 291 | ParseConfigs(config1, &configs); |
| 292 | REPORTER_ASSERT(reporter, configs.count() == config1.count()); |
| 293 | for (int i = 0; i < config1.count(); ++i) { |
| 294 | REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i])); |
| 295 | REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i])); |
| 296 | #if SK_SUPPORT_GPU |
| 297 | REPORTER_ASSERT(reporter, !configs[i]->asConfigGpu()); |
| 298 | #endif |
| 299 | } |
| 300 | } |
| 301 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 302 | DEF_TEST(ParseConfigs_ExtendedGpuConfigsSurprises, reporter) { |
| 303 | // These just list explicitly some properties of the system. |
| 304 | SkCommandLineFlags::StringArray config1 = make_string_array({ |
| 305 | // Options are not canonized -> two same configs have a different tag. |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 306 | "gpu[nvpr=true,dit=true]", "gpu[dit=true,nvpr=true]", |
| 307 | "gpu[api=debug]", "gpu[api=gl]", "gpu[api=gles]", "" |
| 308 | "gpu", "gpu[]", "gpu[samples=0]", "gpu[api=gles,samples=0]" |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 309 | }); |
| 310 | SkCommandLineConfigArray configs; |
| 311 | ParseConfigs(config1, &configs); |
| 312 | REPORTER_ASSERT(reporter, configs.count() == config1.count()); |
| 313 | for (int i = 0; i < config1.count(); ++i) { |
| 314 | REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i])); |
| 315 | #if SK_SUPPORT_GPU |
| 316 | REPORTER_ASSERT(reporter, configs[i]->getBackend().equals("gpu")); |
| 317 | REPORTER_ASSERT(reporter, configs[i]->asConfigGpu()); |
| 318 | #else |
| 319 | REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i])); |
| 320 | #endif |
| 321 | } |
| 322 | } |
| 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 | } |
| 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]", |
bsalomon | 808ecbb | 2016-09-28 12:40:22 -0700 | [diff] [blame] | 358 | "a-gpu[samples=1", |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 359 | "abc-def-angle_gl_es2[samples=1]", |
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 |
bsalomon | 11abd8d | 2016-10-14 08:13:48 -0700 | [diff] [blame] | 375 | {"gpu[samples=1", {"a", nullptr, nullptr}}, // Missing bracket makes this is not extended |
| 376 | // form but via still works as expected. |
| 377 | {"angle_gl_es2[samples=1]", {"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 | } |