| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkCommonFlagsConfig.h" | 8 #include "SkCommonFlagsConfig.h" |
| 9 | 9 |
| 10 #include <stdlib.h> | 10 #include <stdlib.h> |
| 11 | 11 |
| 12 static const char defaultConfigs[] = | 12 static const char defaultConfigs[] = |
| 13 "565 8888 gpu nonrendering" | 13 "565 8888 gpu nonrendering" |
| 14 #if SK_ANGLE | 14 #if SK_ANGLE |
| 15 #ifdef SK_BUILD_FOR_WIN | 15 #ifdef SK_BUILD_FOR_WIN |
| 16 " angle" | 16 " angle" |
| 17 #endif | 17 #endif |
| 18 #endif | 18 #endif |
| 19 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK | 19 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 20 " hwui" | 20 " hwui" |
| 21 #endif | 21 #endif |
| 22 ; | 22 ; |
| 23 | 23 |
| 24 static const char configHelp[] = | 24 static const char configHelp[] = |
| 25 "Options: 565 8888 debug gpu gpudebug gpudft gpunull " | 25 "Options: 565 8888 debug gpu gpudebug gpudft gpunull " |
| 26 "msaa16 msaa4 nonrendering null nullgpu nvprmsaa16 nvprmsaa4 " | 26 "msaa16 msaa4 gpuf16 gpusrgb nonrendering null nullgpu nvprmsaa16 nvprmsaa4
" |
| 27 "pdf pdf_poppler skp svg xps" | 27 "pdf pdf_poppler skp svg xps" |
| 28 #if SK_ANGLE | 28 #if SK_ANGLE |
| 29 #ifdef SK_BUILD_FOR_WIN | 29 #ifdef SK_BUILD_FOR_WIN |
| 30 " angle" | 30 " angle anglesrgb" |
| 31 #endif | 31 #endif |
| 32 " angle-gl" | 32 " angle-gl" |
| 33 #endif | 33 #endif |
| 34 #if SK_COMMAND_BUFFER | 34 #if SK_COMMAND_BUFFER |
| 35 " commandbuffer" | 35 " commandbuffer" |
| 36 #endif | 36 #endif |
| 37 #if SK_MESA | 37 #if SK_MESA |
| 38 " mesa" | 38 " mesa" |
| 39 #endif | 39 #endif |
| 40 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK | 40 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 41 " hwui" | 41 " hwui" |
| 42 #endif | 42 #endif |
| 43 " or use extended form 'backend(option=value,...)'.\n"; | 43 " or use extended form 'backend(option=value,...)'.\n"; |
| 44 | 44 |
| 45 static const char configExtendedHelp[] = | 45 static const char configExtendedHelp[] = |
| 46 "Extended form: 'backend(option=value,...)'\n\n" | 46 "Extended form: 'backend(option=value,...)'\n\n" |
| 47 "Possible backends and options:\n" | 47 "Possible backends and options:\n" |
| 48 #if SK_SUPPORT_GPU | 48 #if SK_SUPPORT_GPU |
| 49 "\n" | 49 "\n" |
| 50 "gpu(api=string,dit=bool,nvpr=bool,samples=int)\tGPU backend\n" | 50 "gpu(api=string,color=string,dit=bool,nvpr=bool,samples=int)\tGPU backend\n" |
| 51 "\tapi\ttype: string\tdefault: native.\n" | 51 "\tapi\ttype: string\tdefault: native.\n" |
| 52 "\t Select graphics API to use with gpu backend.\n" | 52 "\t Select graphics API to use with gpu backend.\n" |
| 53 "\t Options:\n" | 53 "\t Options:\n" |
| 54 "\t\tnative\t\t\tUse platform default OpenGL or OpenGL ES backend.\n" | 54 "\t\tnative\t\t\tUse platform default OpenGL or OpenGL ES backend.\n" |
| 55 "\t\tgl \t\t\tUse OpenGL.\n" | 55 "\t\tgl \t\t\tUse OpenGL.\n" |
| 56 "\t\tgles \t\t\tUse OpenGL ES.\n" | 56 "\t\tgles \t\t\tUse OpenGL ES.\n" |
| 57 "\t\tdebug \t\t\tUse debug OpenGL.\n" | 57 "\t\tdebug \t\t\tUse debug OpenGL.\n" |
| 58 "\t\tnull \t\t\tUse null OpenGL.\n" | 58 "\t\tnull \t\t\tUse null OpenGL.\n" |
| 59 #if SK_ANGLE | 59 #if SK_ANGLE |
| 60 #ifdef SK_BUILD_FOR_WIN | 60 #ifdef SK_BUILD_FOR_WIN |
| 61 "\t\tangle\t\t\tUse ANGLE DirectX.\n" | 61 "\t\tangle\t\t\tUse ANGLE DirectX.\n" |
| 62 #endif | 62 #endif |
| 63 "\t\tangle-gl\t\t\tUse ANGLE OpenGL.\n" | 63 "\t\tangle-gl\t\t\tUse ANGLE OpenGL.\n" |
| 64 #endif | 64 #endif |
| 65 #if SK_COMMAND_BUFFER | 65 #if SK_COMMAND_BUFFER |
| 66 "\t\tcommandbuffer\t\tUse command buffer.\n" | 66 "\t\tcommandbuffer\t\tUse command buffer.\n" |
| 67 "\t\tcommandbuffer3\t\tUse command buffer ES 3.0 (experimental).\n" | 67 "\t\tcommandbuffer3\t\tUse command buffer ES 3.0 (experimental).\n" |
| 68 #endif | 68 #endif |
| 69 #if SK_MESA | 69 #if SK_MESA |
| 70 "\t\tmesa\t\t\tUse MESA.\n" | 70 "\t\tmesa\t\t\tUse MESA.\n" |
| 71 #endif | 71 #endif |
| 72 "\tcolor\ttype: string\tdefault: 8888.\n" |
| 73 "\t Select framebuffer color format.\n" |
| 74 "\t Options:\n" |
| 75 "\t\t8888\t\t\tLinear 8888.\n" |
| 76 "\t\tf16 \t\t\tLinear 16-bit floating point.\n" |
| 77 "\t\tsrgb\t\t\tsRGB 8888.\n" |
| 72 "\tdit\ttype: bool\tdefault: false.\n" | 78 "\tdit\ttype: bool\tdefault: false.\n" |
| 73 "\t Use device independent text.\n" | 79 "\t Use device independent text.\n" |
| 74 "\tnvpr\ttype: bool\tdefault: false.\n" | 80 "\tnvpr\ttype: bool\tdefault: false.\n" |
| 75 "\t Use NV_path_rendering OpenGL and OpenGL ES extension.\n" | 81 "\t Use NV_path_rendering OpenGL and OpenGL ES extension.\n" |
| 76 "\tsamples\ttype: int\tdefault: 0.\n" | 82 "\tsamples\ttype: int\tdefault: 0.\n" |
| 77 "\t Use multisampling with N samples.\n" | 83 "\t Use multisampling with N samples.\n" |
| 78 "\n" | 84 "\n" |
| 79 "Predefined configs:\n\n" | 85 "Predefined configs:\n\n" |
| 80 "\tgpu \t= gpu()\n" | 86 "\tgpu \t= gpu()\n" |
| 81 "\tmsaa4 \t= gpu(samples=4)\n" | 87 "\tmsaa4 \t= gpu(samples=4)\n" |
| 82 "\tmsaa16 \t= gpu(samples=16)\n" | 88 "\tmsaa16 \t= gpu(samples=16)\n" |
| 83 "\tnvprmsaa4\t= gpu(nvpr=true,samples=4)\n" | 89 "\tnvprmsaa4\t= gpu(nvpr=true,samples=4)\n" |
| 84 "\tnvprmsaa16\t= gpu(nvpr=true,samples=16)\n" | 90 "\tnvprmsaa16\t= gpu(nvpr=true,samples=16)\n" |
| 91 "\tgpuf16 \t= gpu(color=f16)\n" |
| 92 "\tgpusrgb \t= gpu(color=srgb)\n" |
| 85 "\tgpudft \t= gpu(dit=true)\n" | 93 "\tgpudft \t= gpu(dit=true)\n" |
| 86 "\tgpudebug \t= gpu(api=debug)\n" | 94 "\tgpudebug \t= gpu(api=debug)\n" |
| 87 "\tgpunull \t= gpu(api=null)\n" | 95 "\tgpunull \t= gpu(api=null)\n" |
| 88 "\tdebug \t= gpu(api=debug)\n" | 96 "\tdebug \t= gpu(api=debug)\n" |
| 89 "\tnullgpu \t= gpu(api=null)\n" | 97 "\tnullgpu \t= gpu(api=null)\n" |
| 90 #if SK_ANGLE | 98 #if SK_ANGLE |
| 91 #ifdef SK_BUILD_FOR_WIN | 99 #ifdef SK_BUILD_FOR_WIN |
| 92 "\tangle \t= gpu(api=angle)\n" | 100 "\tangle \t= gpu(api=angle)\n" |
| 101 "\tanglesrgb \t= gpu(api=angle,color=srgb)\n" |
| 93 #endif | 102 #endif |
| 94 "\tangle-gl \t= gpu(api=angle-gl)\n" | 103 "\tangle-gl \t= gpu(api=angle-gl)\n" |
| 95 #endif | 104 #endif |
| 96 #if SK_COMMAND_BUFFER | 105 #if SK_COMMAND_BUFFER |
| 97 "\tcommandbuffer\t= gpu(api=commandbuffer)\n" | 106 "\tcommandbuffer\t= gpu(api=commandbuffer)\n" |
| 98 #endif | 107 #endif |
| 99 #if SK_MESA | 108 #if SK_MESA |
| 100 "\tmesa \t= gpu(api=mesa)\n" | 109 "\tmesa \t= gpu(api=mesa)\n" |
| 101 #endif | 110 #endif |
| 102 #endif | 111 #endif |
| 103 ; | 112 ; |
| 104 | 113 |
| 105 DEFINE_extended_string(config, defaultConfigs, configHelp, configExtendedHelp); | 114 DEFINE_extended_string(config, defaultConfigs, configHelp, configExtendedHelp); |
| 106 | 115 |
| 107 static const struct { | 116 static const struct { |
| 108 const char* predefinedConfig; | 117 const char* predefinedConfig; |
| 109 const char* backend; | 118 const char* backend; |
| 110 const char* options; | 119 const char* options; |
| 111 } gPredefinedConfigs[] = { | 120 } gPredefinedConfigs[] = { |
| 112 #if SK_SUPPORT_GPU | 121 #if SK_SUPPORT_GPU |
| 113 { "gpu", "gpu", "" }, | 122 { "gpu", "gpu", "" }, |
| 114 { "msaa4", "gpu", "samples=4" }, | 123 { "msaa4", "gpu", "samples=4" }, |
| 115 { "msaa16", "gpu", "samples=16" }, | 124 { "msaa16", "gpu", "samples=16" }, |
| 116 { "nvprmsaa4", "gpu", "nvpr=true,samples=4,dit=true" }, | 125 { "nvprmsaa4", "gpu", "nvpr=true,samples=4,dit=true" }, |
| 117 { "nvprmsaa16", "gpu", "nvpr=true,samples=16,dit=true" }, | 126 { "nvprmsaa16", "gpu", "nvpr=true,samples=16,dit=true" }, |
| 127 { "gpuf16", "gpu", "color=f16" }, |
| 128 { "gpusrgb", "gpu", "color=srgb" }, |
| 118 { "gpudft", "gpu", "dit=true" }, | 129 { "gpudft", "gpu", "dit=true" }, |
| 119 { "gpudebug", "gpu", "api=debug" }, | 130 { "gpudebug", "gpu", "api=debug" }, |
| 120 { "gpunull", "gpu", "api=null" }, | 131 { "gpunull", "gpu", "api=null" }, |
| 121 { "debug", "gpu", "api=debug" }, | 132 { "debug", "gpu", "api=debug" }, |
| 122 { "nullgpu", "gpu", "api=null" } | 133 { "nullgpu", "gpu", "api=null" } |
| 123 #if SK_ANGLE | 134 #if SK_ANGLE |
| 124 #ifdef SK_BUILD_FOR_WIN | 135 #ifdef SK_BUILD_FOR_WIN |
| 125 , { "angle", "gpu", "api=angle" } | 136 , { "angle", "gpu", "api=angle" } |
| 137 , { "anglesrgb", "gpu", "api=angle,color=srgb" } |
| 126 #endif | 138 #endif |
| 127 , { "angle-gl", "gpu", "api=angle-gl" } | 139 , { "angle-gl", "gpu", "api=angle-gl" } |
| 128 #endif | 140 #endif |
| 129 #if SK_COMMAND_BUFFER | 141 #if SK_COMMAND_BUFFER |
| 130 , { "commandbuffer", "gpu", "api=commandbuffer" } | 142 , { "commandbuffer", "gpu", "api=commandbuffer" } |
| 131 #endif | 143 #endif |
| 132 #if SK_MESA | 144 #if SK_MESA |
| 133 , { "mesa", "gpu", "api=mesa" } | 145 , { "mesa", "gpu", "api=mesa" } |
| 134 #endif | 146 #endif |
| 135 #else | 147 #else |
| 136 { "", "", "" } | 148 { "", "", "" } |
| 137 #endif | 149 #endif |
| 138 }; | 150 }; |
| 139 | 151 |
| 140 SkCommandLineConfig::SkCommandLineConfig(const SkString& tag, const SkString& ba
ckend, | 152 SkCommandLineConfig::SkCommandLineConfig(const SkString& tag, const SkString& ba
ckend, |
| 141 const SkTArray<SkString>& viaParts) | 153 const SkTArray<SkString>& viaParts) |
| 142 : fTag(tag) | 154 : fTag(tag) |
| 143 , fBackend(backend) | 155 , fBackend(backend) |
| 144 , fViaParts(viaParts) { | 156 , fViaParts(viaParts) { |
| 145 } | 157 } |
| 146 SkCommandLineConfig::~SkCommandLineConfig() { | 158 SkCommandLineConfig::~SkCommandLineConfig() { |
| 147 } | 159 } |
| 148 | 160 |
| 149 #if SK_SUPPORT_GPU | 161 #if SK_SUPPORT_GPU |
| 150 SkCommandLineConfigGpu::SkCommandLineConfigGpu( | 162 SkCommandLineConfigGpu::SkCommandLineConfigGpu( |
| 151 const SkString& tag, const SkTArray<SkString>& viaParts, | 163 const SkString& tag, const SkTArray<SkString>& viaParts, |
| 152 ContextType contextType, bool useNVPR, bool useDIText, int samples) | 164 ContextType contextType, bool useNVPR, bool useDIText, int samples, |
| 165 SkColorType colorType, SkColorProfileType profileType) |
| 153 : SkCommandLineConfig(tag, SkString("gpu"), viaParts) | 166 : SkCommandLineConfig(tag, SkString("gpu"), viaParts) |
| 154 , fContextType(contextType) | 167 , fContextType(contextType) |
| 155 , fUseNVPR(useNVPR) | 168 , fUseNVPR(useNVPR) |
| 156 , fUseDIText(useDIText) | 169 , fUseDIText(useDIText) |
| 157 , fSamples(samples) { | 170 , fSamples(samples) |
| 171 , fColorType(colorType) |
| 172 , fProfileType(profileType) { |
| 158 } | 173 } |
| 159 static bool parse_option_int(const SkString& value, int* outInt) { | 174 static bool parse_option_int(const SkString& value, int* outInt) { |
| 160 if (value.isEmpty()) { | 175 if (value.isEmpty()) { |
| 161 return false; | 176 return false; |
| 162 } | 177 } |
| 163 char* endptr = nullptr; | 178 char* endptr = nullptr; |
| 164 long intValue = strtol(value.c_str(), &endptr, 10); | 179 long intValue = strtol(value.c_str(), &endptr, 10); |
| 165 if (*endptr != '\0') { | 180 if (*endptr != '\0') { |
| 166 return false; | 181 return false; |
| 167 } | 182 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 } | 239 } |
| 225 #endif | 240 #endif |
| 226 #if SK_MESA | 241 #if SK_MESA |
| 227 if (value.equals("mesa")) { | 242 if (value.equals("mesa")) { |
| 228 *outContextType = GrContextFactory::kMESA_GLContextType; | 243 *outContextType = GrContextFactory::kMESA_GLContextType; |
| 229 return true; | 244 return true; |
| 230 } | 245 } |
| 231 #endif | 246 #endif |
| 232 return false; | 247 return false; |
| 233 } | 248 } |
| 249 static bool parse_option_gpu_color(const SkString& value, |
| 250 SkColorType* outColorType, |
| 251 SkColorProfileType* outProfileType) { |
| 252 if (value.equals("8888")) { |
| 253 *outColorType = kN32_SkColorType; |
| 254 *outProfileType = kLinear_SkColorProfileType; |
| 255 return true; |
| 256 } |
| 257 if (value.equals("f16")) { |
| 258 *outColorType = kRGBA_F16_SkColorType; |
| 259 *outProfileType = kLinear_SkColorProfileType; |
| 260 return true; |
| 261 } |
| 262 if (value.equals("srgb")) { |
| 263 *outColorType = kN32_SkColorType; |
| 264 *outProfileType = kSRGB_SkColorProfileType; |
| 265 return true; |
| 266 } |
| 267 return false; |
| 268 } |
| 234 | 269 |
| 235 SkCommandLineConfigGpu* parse_command_line_config_gpu(const SkString& tag, | 270 SkCommandLineConfigGpu* parse_command_line_config_gpu(const SkString& tag, |
| 236 const SkTArray<SkString>&
vias, | 271 const SkTArray<SkString>&
vias, |
| 237 const SkString& options) { | 272 const SkString& options) { |
| 238 // Defaults for GPU backend. | 273 // Defaults for GPU backend. |
| 239 bool seenAPI = false; | 274 bool seenAPI = false; |
| 240 SkCommandLineConfigGpu::ContextType contextType = GrContextFactory::kNative_
GLContextType; | 275 SkCommandLineConfigGpu::ContextType contextType = GrContextFactory::kNative_
GLContextType; |
| 241 bool seenUseNVPR = false; | 276 bool seenUseNVPR = false; |
| 242 bool useNVPR = false; | 277 bool useNVPR = false; |
| 243 bool seenUseDIText =false; | 278 bool seenUseDIText =false; |
| 244 bool useDIText = false; | 279 bool useDIText = false; |
| 245 bool seenSamples = false; | 280 bool seenSamples = false; |
| 246 int samples = 0; | 281 int samples = 0; |
| 282 bool seenColor = false; |
| 283 SkColorType colorType = kN32_SkColorType; |
| 284 SkColorProfileType profileType = kLinear_SkColorProfileType; |
| 247 | 285 |
| 248 SkTArray<SkString> optionParts; | 286 SkTArray<SkString> optionParts; |
| 249 SkStrSplit(options.c_str(), ",", kStrict_SkStrSplitMode, &optionParts); | 287 SkStrSplit(options.c_str(), ",", kStrict_SkStrSplitMode, &optionParts); |
| 250 for (int i = 0; i < optionParts.count(); ++i) { | 288 for (int i = 0; i < optionParts.count(); ++i) { |
| 251 SkTArray<SkString> keyValueParts; | 289 SkTArray<SkString> keyValueParts; |
| 252 SkStrSplit(optionParts[i].c_str(), "=", kStrict_SkStrSplitMode, &keyValu
eParts); | 290 SkStrSplit(optionParts[i].c_str(), "=", kStrict_SkStrSplitMode, &keyValu
eParts); |
| 253 if (keyValueParts.count() != 2) { | 291 if (keyValueParts.count() != 2) { |
| 254 return nullptr; | 292 return nullptr; |
| 255 } | 293 } |
| 256 const SkString& key = keyValueParts[0]; | 294 const SkString& key = keyValueParts[0]; |
| 257 const SkString& value = keyValueParts[1]; | 295 const SkString& value = keyValueParts[1]; |
| 258 bool valueOk = false; | 296 bool valueOk = false; |
| 259 if (key.equals("api") && !seenAPI) { | 297 if (key.equals("api") && !seenAPI) { |
| 260 valueOk = parse_option_gpu_api(value, &contextType); | 298 valueOk = parse_option_gpu_api(value, &contextType); |
| 261 seenAPI = true; | 299 seenAPI = true; |
| 262 } else if (key.equals("nvpr") && !seenUseNVPR) { | 300 } else if (key.equals("nvpr") && !seenUseNVPR) { |
| 263 valueOk = parse_option_bool(value, &useNVPR); | 301 valueOk = parse_option_bool(value, &useNVPR); |
| 264 seenUseNVPR = true; | 302 seenUseNVPR = true; |
| 265 } else if (key.equals("dit") && !seenUseDIText) { | 303 } else if (key.equals("dit") && !seenUseDIText) { |
| 266 valueOk = parse_option_bool(value, &useDIText); | 304 valueOk = parse_option_bool(value, &useDIText); |
| 267 seenUseDIText = true; | 305 seenUseDIText = true; |
| 268 } else if (key.equals("samples") && !seenSamples) { | 306 } else if (key.equals("samples") && !seenSamples) { |
| 269 valueOk = parse_option_int(value, &samples); | 307 valueOk = parse_option_int(value, &samples); |
| 270 seenSamples = true; | 308 seenSamples = true; |
| 309 } else if (key.equals("color") && !seenColor) { |
| 310 valueOk = parse_option_gpu_color(value, &colorType, &profileType); |
| 311 seenColor = true; |
| 271 } | 312 } |
| 272 if (!valueOk) { | 313 if (!valueOk) { |
| 273 return nullptr; | 314 return nullptr; |
| 274 } | 315 } |
| 275 } | 316 } |
| 276 return new SkCommandLineConfigGpu(tag, vias, contextType, useNVPR, useDIText
, samples); | 317 return new SkCommandLineConfigGpu(tag, vias, contextType, useNVPR, useDIText
, samples, |
| 318 colorType, profileType); |
| 277 } | 319 } |
| 278 #endif | 320 #endif |
| 279 | 321 |
| 280 void ParseConfigs(const SkCommandLineFlags::StringArray& configs, | 322 void ParseConfigs(const SkCommandLineFlags::StringArray& configs, |
| 281 SkCommandLineConfigArray* outResult) { | 323 SkCommandLineConfigArray* outResult) { |
| 282 outResult->reset(); | 324 outResult->reset(); |
| 283 for (int i = 0; i < configs.count(); ++i) { | 325 for (int i = 0; i < configs.count(); ++i) { |
| 284 SkString extendedBackend; | 326 SkString extendedBackend; |
| 285 SkString extendedOptions; | 327 SkString extendedOptions; |
| 286 SkString simpleBackend; | 328 SkString simpleBackend; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 if (extendedBackend.equals("gpu")) { | 374 if (extendedBackend.equals("gpu")) { |
| 333 parsedConfig = parse_command_line_config_gpu(tag, vias, extendedOpti
ons); | 375 parsedConfig = parse_command_line_config_gpu(tag, vias, extendedOpti
ons); |
| 334 } | 376 } |
| 335 #endif | 377 #endif |
| 336 if (!parsedConfig) { | 378 if (!parsedConfig) { |
| 337 parsedConfig = new SkCommandLineConfig(tag, simpleBackend, vias); | 379 parsedConfig = new SkCommandLineConfig(tag, simpleBackend, vias); |
| 338 } | 380 } |
| 339 outResult->emplace_back(parsedConfig); | 381 outResult->emplace_back(parsedConfig); |
| 340 } | 382 } |
| 341 } | 383 } |
| OLD | NEW |