OLD | NEW |
(Empty) | |
| 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" |
| 9 |
| 10 #include <stdlib.h> |
| 11 |
| 12 DEFINE_extended_string( |
| 13 config, |
| 14 "565 8888 gpu nonrendering" |
| 15 #if SK_ANGLE |
| 16 " angle" |
| 17 #endif |
| 18 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 19 " hwui" |
| 20 #endif |
| 21 , "Options: 565 8888 debug gpu gpudebug gpudft gpunull " |
| 22 "msaa16 msaa4 nonrendering null nullgpu nvprmsaa16 nvprmsaa4 " |
| 23 "pdf pdf_poppler skp svg xps" |
| 24 #if SK_ANGLE |
| 25 " angle angle-gl" |
| 26 #endif |
| 27 #if SK_COMMAND_BUFFER |
| 28 " commandbuffer" |
| 29 #endif |
| 30 #if SK_MESA |
| 31 " mesa" |
| 32 #endif |
| 33 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 34 " hwui" |
| 35 #endif |
| 36 " or use extended form 'backend(option=value,...)'.\n", |
| 37 "Extended form: 'backend(option=value,...)'\n\n" |
| 38 "Possible backends and options:\n" |
| 39 #if SK_SUPPORT_GPU |
| 40 "\n" |
| 41 "gpu(api=string,dit=bool,nvpr=bool,samples=int)\tGPU backend\n" |
| 42 "\tapi\ttype: string\tdefault: native.\n" |
| 43 "\t Select graphics API to use with gpu backend.\n" |
| 44 "\t Options:\n" |
| 45 "\t\tnative\t\t\tUse platform default OpenGL or OpenGL ES backend.\n" |
| 46 "\t\tgl \t\t\tUse OpenGL.\n" |
| 47 "\t\tgles \t\t\tUse OpenGL ES.\n" |
| 48 "\t\tdebug \t\t\tUse debug OpenGL.\n" |
| 49 "\t\tnull \t\t\tUse null OpenGL.\n" |
| 50 #if SK_ANGLE |
| 51 "\t\tangle\t\t\tUse ANGLE DirectX.\n" |
| 52 "\t\tangle-gl\t\t\tUse ANGLE OpenGL.\n" |
| 53 #endif |
| 54 #if SK_COMMAND_BUFFER |
| 55 "\t\tcommandbuffer\t\tUse command buffer.\n" |
| 56 #endif |
| 57 #if SK_MESA |
| 58 "\t\tmesa\t\t\tUse MESA.\n" |
| 59 #endif |
| 60 "\tdit\ttype: bool\tdefault: false.\n" |
| 61 "\t Use device independent text.\n" |
| 62 "\tnvpr\ttype: bool\tdefault: false.\n" |
| 63 "\t Use NV_path_rendering OpenGL and OpenGL ES extension.\n" |
| 64 "\tsamples\ttype: int\tdefault: 0.\n" |
| 65 "\t Use multisampling with N samples.\n" |
| 66 "\n" |
| 67 "Predefined configs:\n\n" |
| 68 "\tgpu \t= gpu()\n" |
| 69 "\tmsaa4 \t= gpu(samples=4)\n" |
| 70 "\tmsaa16 \t= gpu(samples=16)\n" |
| 71 "\tnvprmsaa4\t= gpu(nvpr=true,samples=4)\n" |
| 72 "\tnvprmsaa16\t= gpu(nvpr=true,samples=16)\n" |
| 73 "\tgpudft \t= gpu(dit=true)\n" |
| 74 "\tgpudebug \t= gpu(api=debug)\n" |
| 75 "\tgpunull \t= gpu(api=null)\n" |
| 76 "\tdebug \t= gpu(api=debug)\n" |
| 77 "\tnull \t= gpu(api=null)\n" |
| 78 "\tnullgpu \t= gpu(api=null)\n" |
| 79 #if SK_ANGLE |
| 80 "\tangle \t= gpu(api=angle)\n" |
| 81 "\tangle-gl \t= gpu(api=angle-gl)\n" |
| 82 #endif |
| 83 #if SK_COMMAND_BUFFER |
| 84 "\tcommandbuffer\t= gpu(api=commandbuffer)\n" |
| 85 #endif |
| 86 #if SK_MESA |
| 87 "\tmesa \t= gpu(api=mesa)\n" |
| 88 #endif |
| 89 #endif |
| 90 ""); |
| 91 |
| 92 static const struct { |
| 93 const char* predefinedConfig; |
| 94 const char* backend; |
| 95 const char* options; |
| 96 } gPredefinedConfigs[] = { |
| 97 #if SK_SUPPORT_GPU |
| 98 "gpu", "gpu", "", |
| 99 "msaa4", "gpu", "samples=4", |
| 100 "msaa16", "gpu", "samples=16", |
| 101 "nvprmsaa4", "gpu", "nvpr=true,samples=4", |
| 102 "nvprmsaa16", "gpu", "nvpr=true,samples=16", |
| 103 "gpudft", "gpu", "dit=true", |
| 104 "gpudebug", "gpu", "api=debug", |
| 105 "gpunull", "gpu", "api=null", |
| 106 "debug", "gpu", "api=debug", |
| 107 "null", "gpu", "api=null", |
| 108 "nullgpu", "gpu", "api=null", |
| 109 #if SK_ANGLE |
| 110 "angle", "gpu", "api=angle", |
| 111 "angle-gl", "gpu", "api=angle-gl", |
| 112 #endif |
| 113 #if SK_COMMAND_BUFFER |
| 114 "commandbuffer", "gpu", "api=commandbuffer", |
| 115 #endif |
| 116 #if SK_MESA |
| 117 "mesa", "gpu", "api=mesa", |
| 118 #endif |
| 119 #else |
| 120 "", "", "" |
| 121 #endif |
| 122 }; |
| 123 |
| 124 SkCommandLineConfig::SkCommandLineConfig(const SkString& tag, const SkTArray<SkS
tring>& viaParts) |
| 125 : fTag(tag) |
| 126 , fViaParts(viaParts) { |
| 127 } |
| 128 SkCommandLineConfig::~SkCommandLineConfig() { |
| 129 } |
| 130 |
| 131 #if SK_SUPPORT_GPU |
| 132 SkCommandLineConfigGpu::SkCommandLineConfigGpu( |
| 133 const SkString& tag, const SkTArray<SkString>& viaParts, |
| 134 API api, bool useNVPR, bool useDIText, int samples) |
| 135 : SkCommandLineConfig(tag, viaParts) |
| 136 , fAPI(api) |
| 137 , fUseNVPR(useNVPR) |
| 138 , fUseDIText(useDIText) |
| 139 , fSamples(samples) { |
| 140 } |
| 141 static bool parse_option_int(const SkString& value, int* outInt) { |
| 142 if (value.isEmpty()) { |
| 143 return false; |
| 144 } |
| 145 char* endptr = nullptr; |
| 146 long intValue = strtol(value.c_str(), &endptr, 10); |
| 147 if (*endptr != '\0') { |
| 148 return false; |
| 149 } |
| 150 *outInt = static_cast<int>(intValue); |
| 151 return true; |
| 152 } |
| 153 static bool parse_option_bool(const SkString& value, bool* outBool) { |
| 154 if (value.equals("true")) { |
| 155 *outBool = true; |
| 156 return true; |
| 157 } else if (value.equals("false")) { |
| 158 *outBool = false; |
| 159 return true; |
| 160 } |
| 161 return false; |
| 162 } |
| 163 static bool parse_option_gpu_api(const SkString& value, SkCommandLineConfigGpu::
API* outAPI) { |
| 164 if (value.equals("native")) { |
| 165 *outAPI = SkCommandLineConfigGpu::kNative_API; |
| 166 return true; |
| 167 } else if (value.equals("gl")) { |
| 168 *outAPI = SkCommandLineConfigGpu::kGL_API; |
| 169 return true; |
| 170 } else if (value.equals("gles")) { |
| 171 *outAPI = SkCommandLineConfigGpu::kGLES_API; |
| 172 return true; |
| 173 } else if (value.equals("debug")) { |
| 174 *outAPI = SkCommandLineConfigGpu::kDebug_API; |
| 175 return true; |
| 176 } else if (value.equals("null")) { |
| 177 *outAPI = SkCommandLineConfigGpu::kNull_API; |
| 178 return true; |
| 179 } |
| 180 #if SK_ANGLE |
| 181 else if (value.equals("angle")) { |
| 182 *outAPI = SkCommandLineConfigGpu::kANGLE_API; |
| 183 return true; |
| 184 } |
| 185 else if (value.equals("angle-gl")) { |
| 186 *outAPI = SkCommandLineConfigGpu::kANGLE_GL_API; |
| 187 return true; |
| 188 } |
| 189 #endif |
| 190 #if SK_COMMAND_BUFFER |
| 191 else if (value.equals("commandbuffer")) { |
| 192 *outAPI = SkCommandLineConfigGpu::kCommandBuffer_API; |
| 193 return true; |
| 194 } |
| 195 #endif |
| 196 #if SK_MESA |
| 197 else if (value.equals("mesa")) { |
| 198 *outAPI = SkCommandLineConfigGpu::kMESA_API; |
| 199 return true; |
| 200 } |
| 201 #endif |
| 202 return false; |
| 203 } |
| 204 |
| 205 SkCommandLineConfigGpu* parse_command_line_config_gpu(const SkString& tag, const
SkTArray<SkString>& vias, const SkString& options) { |
| 206 // Defaults for GPU backend. |
| 207 bool seenAPI = false; |
| 208 SkCommandLineConfigGpu::API api = SkCommandLineConfigGpu::kNative_API; |
| 209 bool seenUseNVPR = false; |
| 210 bool useNVPR = false; |
| 211 bool seenUseDIText =false; |
| 212 bool useDIText = false; |
| 213 bool seenSamples = false; |
| 214 int samples = 0; |
| 215 |
| 216 if (options.endsWith(",") || options.startsWith(",")) { |
| 217 return nullptr; |
| 218 } |
| 219 SkTArray<SkString> optionParts; |
| 220 SkStrSplit(options.c_str(), ",", &optionParts); |
| 221 for (int i = 0; i < optionParts.count(); ++i) { |
| 222 SkTArray<SkString> keyValueParts; |
| 223 SkStrSplit(optionParts[i].c_str(), "=", &keyValueParts); |
| 224 if (keyValueParts.count() != 2) { |
| 225 return nullptr; |
| 226 } |
| 227 const SkString& key = keyValueParts[0]; |
| 228 const SkString& value = keyValueParts[1]; |
| 229 bool valueOk = false; |
| 230 if (key.equals("api") && !seenAPI) { |
| 231 valueOk = parse_option_gpu_api(value, &api); |
| 232 seenAPI = true; |
| 233 } else if (key.equals("nvpr") && !seenUseNVPR) { |
| 234 valueOk = parse_option_bool(value, &useNVPR); |
| 235 seenUseNVPR = true; |
| 236 } else if (key.equals("dit") && !seenUseDIText) { |
| 237 valueOk = parse_option_bool(value, &useDIText); |
| 238 seenUseDIText = true; |
| 239 } else if (key.equals("samples") && !seenSamples) { |
| 240 valueOk = parse_option_int(value, &samples); |
| 241 seenSamples = true; |
| 242 } |
| 243 if (!valueOk) { |
| 244 return nullptr; |
| 245 } |
| 246 } |
| 247 return new SkCommandLineConfigGpu(tag, vias, api, useNVPR, useDIText, sample
s); |
| 248 } |
| 249 #endif |
| 250 |
| 251 void ParseConfigs(const SkCommandLineFlags::StringArray& configs, SkCommandLineC
onfigArray* outResult) { |
| 252 outResult->reset(); |
| 253 for (int i = 0; i < configs.count(); ++i) { |
| 254 SkString extendedConfigBackend; |
| 255 SkString extendedConfigOptions; |
| 256 SkString tag(configs[i]); |
| 257 SkTArray<SkString> vias; |
| 258 |
| 259 SkTArray<SkString> parts; |
| 260 SkStrSplit(tag.c_str(), "(", &parts); |
| 261 if (parts.count() == 2) { |
| 262 SkTArray<SkString> parts2; |
| 263 SkStrSplit(parts[1].c_str(), ")", &parts2); |
| 264 if (parts[1].endsWith(")") && parts2.count() == 1) { |
| 265 SkStrSplit(parts[0].c_str(), "-", &vias); |
| 266 if (vias.count()) { |
| 267 extendedConfigBackend = vias[vias.count() - 1]; |
| 268 vias.pop_back(); |
| 269 } else { |
| 270 extendedConfigBackend = parts[0]; |
| 271 } |
| 272 extendedConfigOptions = parts2[0]; |
| 273 tag.printf("%s(%s)", extendedConfigBackend.c_str(), extendedConf
igOptions.c_str()); |
| 274 } |
| 275 } |
| 276 if (extendedConfigBackend.isEmpty()) { |
| 277 SkStrSplit(tag.c_str(), "-", &vias); |
| 278 if (vias.count()) { |
| 279 tag = vias[vias.count() - 1]; |
| 280 vias.pop_back(); |
| 281 } |
| 282 // Note: no #if SK_ANGLE: this is a special rule in the via-tag gram
mar. |
| 283 if (vias.count() && tag.equals("gl") && vias[vias.count() - 1].equal
s("angle")) { |
| 284 tag = "angle-gl"; |
| 285 vias.pop_back(); |
| 286 } |
| 287 } |
| 288 |
| 289 for (size_t j = 0; |
| 290 j < SK_ARRAY_COUNT(gPredefinedConfigs) && extendedConfigBackend.isE
mpty(); ++j) { |
| 291 if (tag.equals(gPredefinedConfigs[j].predefinedConfig)) { |
| 292 extendedConfigBackend = gPredefinedConfigs[j].backend; |
| 293 extendedConfigOptions = gPredefinedConfigs[j].options; |
| 294 } |
| 295 } |
| 296 |
| 297 SkCommandLineConfig* parsedConfig = nullptr; |
| 298 #if SK_SUPPORT_GPU |
| 299 if (extendedConfigBackend.equals("gpu")) { |
| 300 parsedConfig = parse_command_line_config_gpu(tag, vias, extendedConf
igOptions); |
| 301 } |
| 302 #endif |
| 303 if (!parsedConfig) { |
| 304 parsedConfig = new SkCommandLineConfig(tag, vias); |
| 305 } |
| 306 outResult->emplace_back(parsedConfig); |
| 307 } |
| 308 } |
OLD | NEW |