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" |
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 #endif | 67 #endif |
68 #if SK_MESA | 68 #if SK_MESA |
69 "\t\tmesa\t\t\tUse MESA.\n" | 69 "\t\tmesa\t\t\tUse MESA.\n" |
70 #endif | 70 #endif |
| 71 "\tcolor\ttype: string\tdefault: 8888.\n" |
| 72 "\t Select framebuffer color format.\n" |
| 73 "\t Options:\n" |
| 74 "\t\t8888\t\t\tLinear 8888.\n" |
| 75 "\t\tf16 \t\t\tLinear 16-bit floating point.\n" |
| 76 "\t\tsrgb\t\t\tsRGB 8888.\n" |
71 "\tdit\ttype: bool\tdefault: false.\n" | 77 "\tdit\ttype: bool\tdefault: false.\n" |
72 "\t Use device independent text.\n" | 78 "\t Use device independent text.\n" |
73 "\tnvpr\ttype: bool\tdefault: false.\n" | 79 "\tnvpr\ttype: bool\tdefault: false.\n" |
74 "\t Use NV_path_rendering OpenGL and OpenGL ES extension.\n" | 80 "\t Use NV_path_rendering OpenGL and OpenGL ES extension.\n" |
75 "\tsamples\ttype: int\tdefault: 0.\n" | 81 "\tsamples\ttype: int\tdefault: 0.\n" |
76 "\t Use multisampling with N samples.\n" | 82 "\t Use multisampling with N samples.\n" |
77 "\n" | 83 "\n" |
78 "Predefined configs:\n\n" | 84 "Predefined configs:\n\n" |
79 "\tgpu \t= gpu()\n" | 85 "\tgpu \t= gpu()\n" |
80 "\tmsaa4 \t= gpu(samples=4)\n" | 86 "\tmsaa4 \t= gpu(samples=4)\n" |
81 "\tmsaa16 \t= gpu(samples=16)\n" | 87 "\tmsaa16 \t= gpu(samples=16)\n" |
82 "\tnvprmsaa4\t= gpu(nvpr=true,samples=4)\n" | 88 "\tnvprmsaa4\t= gpu(nvpr=true,samples=4)\n" |
83 "\tnvprmsaa16\t= gpu(nvpr=true,samples=16)\n" | 89 "\tnvprmsaa16\t= gpu(nvpr=true,samples=16)\n" |
| 90 "\tgpuf16 \t= gpu(color=f16)\n" |
| 91 "\tgpusrgb \t= gpu(color=srgb)\n" |
84 "\tgpudft \t= gpu(dit=true)\n" | 92 "\tgpudft \t= gpu(dit=true)\n" |
85 "\tgpudebug \t= gpu(api=debug)\n" | 93 "\tgpudebug \t= gpu(api=debug)\n" |
86 "\tgpunull \t= gpu(api=null)\n" | 94 "\tgpunull \t= gpu(api=null)\n" |
87 "\tdebug \t= gpu(api=debug)\n" | 95 "\tdebug \t= gpu(api=debug)\n" |
88 "\tnullgpu \t= gpu(api=null)\n" | 96 "\tnullgpu \t= gpu(api=null)\n" |
89 #if SK_ANGLE | 97 #if SK_ANGLE |
90 #ifdef SK_BUILD_FOR_WIN | 98 #ifdef SK_BUILD_FOR_WIN |
91 "\tangle \t= gpu(api=angle)\n" | 99 "\tangle \t= gpu(api=angle)\n" |
92 #endif | 100 #endif |
93 "\tangle-gl \t= gpu(api=angle-gl)\n" | 101 "\tangle-gl \t= gpu(api=angle-gl)\n" |
(...skipping 13 matching lines...) Expand all Loading... |
107 const char* predefinedConfig; | 115 const char* predefinedConfig; |
108 const char* backend; | 116 const char* backend; |
109 const char* options; | 117 const char* options; |
110 } gPredefinedConfigs[] = { | 118 } gPredefinedConfigs[] = { |
111 #if SK_SUPPORT_GPU | 119 #if SK_SUPPORT_GPU |
112 { "gpu", "gpu", "" }, | 120 { "gpu", "gpu", "" }, |
113 { "msaa4", "gpu", "samples=4" }, | 121 { "msaa4", "gpu", "samples=4" }, |
114 { "msaa16", "gpu", "samples=16" }, | 122 { "msaa16", "gpu", "samples=16" }, |
115 { "nvprmsaa4", "gpu", "nvpr=true,samples=4,dit=true" }, | 123 { "nvprmsaa4", "gpu", "nvpr=true,samples=4,dit=true" }, |
116 { "nvprmsaa16", "gpu", "nvpr=true,samples=16,dit=true" }, | 124 { "nvprmsaa16", "gpu", "nvpr=true,samples=16,dit=true" }, |
| 125 { "gpuf16", "gpu", "color=f16" }, |
| 126 { "gpusrgb", "gpu", "color=srgb" }, |
117 { "gpudft", "gpu", "dit=true" }, | 127 { "gpudft", "gpu", "dit=true" }, |
118 { "gpudebug", "gpu", "api=debug" }, | 128 { "gpudebug", "gpu", "api=debug" }, |
119 { "gpunull", "gpu", "api=null" }, | 129 { "gpunull", "gpu", "api=null" }, |
120 { "debug", "gpu", "api=debug" }, | 130 { "debug", "gpu", "api=debug" }, |
121 { "nullgpu", "gpu", "api=null" } | 131 { "nullgpu", "gpu", "api=null" } |
122 #if SK_ANGLE | 132 #if SK_ANGLE |
123 #ifdef SK_BUILD_FOR_WIN | 133 #ifdef SK_BUILD_FOR_WIN |
124 , { "angle", "gpu", "api=angle" } | 134 , { "angle", "gpu", "api=angle" } |
125 #endif | 135 #endif |
126 , { "angle-gl", "gpu", "api=angle-gl" } | 136 , { "angle-gl", "gpu", "api=angle-gl" } |
(...skipping 14 matching lines...) Expand all Loading... |
141 : fTag(tag) | 151 : fTag(tag) |
142 , fBackend(backend) | 152 , fBackend(backend) |
143 , fViaParts(viaParts) { | 153 , fViaParts(viaParts) { |
144 } | 154 } |
145 SkCommandLineConfig::~SkCommandLineConfig() { | 155 SkCommandLineConfig::~SkCommandLineConfig() { |
146 } | 156 } |
147 | 157 |
148 #if SK_SUPPORT_GPU | 158 #if SK_SUPPORT_GPU |
149 SkCommandLineConfigGpu::SkCommandLineConfigGpu( | 159 SkCommandLineConfigGpu::SkCommandLineConfigGpu( |
150 const SkString& tag, const SkTArray<SkString>& viaParts, | 160 const SkString& tag, const SkTArray<SkString>& viaParts, |
151 ContextType contextType, bool useNVPR, bool useDIText, int samples) | 161 ContextType contextType, bool useNVPR, bool useDIText, int samples, |
| 162 SkColorType colorType, SkColorProfileType profileType) |
152 : SkCommandLineConfig(tag, SkString("gpu"), viaParts) | 163 : SkCommandLineConfig(tag, SkString("gpu"), viaParts) |
153 , fContextType(contextType) | 164 , fContextType(contextType) |
154 , fUseNVPR(useNVPR) | 165 , fUseNVPR(useNVPR) |
155 , fUseDIText(useDIText) | 166 , fUseDIText(useDIText) |
156 , fSamples(samples) { | 167 , fSamples(samples) |
| 168 , fColorType(colorType) |
| 169 , fProfileType(profileType) { |
157 } | 170 } |
158 static bool parse_option_int(const SkString& value, int* outInt) { | 171 static bool parse_option_int(const SkString& value, int* outInt) { |
159 if (value.isEmpty()) { | 172 if (value.isEmpty()) { |
160 return false; | 173 return false; |
161 } | 174 } |
162 char* endptr = nullptr; | 175 char* endptr = nullptr; |
163 long intValue = strtol(value.c_str(), &endptr, 10); | 176 long intValue = strtol(value.c_str(), &endptr, 10); |
164 if (*endptr != '\0') { | 177 if (*endptr != '\0') { |
165 return false; | 178 return false; |
166 } | 179 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 } | 232 } |
220 #endif | 233 #endif |
221 #if SK_MESA | 234 #if SK_MESA |
222 if (value.equals("mesa")) { | 235 if (value.equals("mesa")) { |
223 *outContextType = GrContextFactory::kMESA_GLContextType; | 236 *outContextType = GrContextFactory::kMESA_GLContextType; |
224 return true; | 237 return true; |
225 } | 238 } |
226 #endif | 239 #endif |
227 return false; | 240 return false; |
228 } | 241 } |
| 242 static bool parse_option_gpu_color(const SkString& value, |
| 243 SkColorType* outColorType, |
| 244 SkColorProfileType* outProfileType) { |
| 245 if (value.equals("8888")) { |
| 246 *outColorType = kN32_SkColorType; |
| 247 *outProfileType = kLinear_SkColorProfileType; |
| 248 return true; |
| 249 } |
| 250 if (value.equals("f16")) { |
| 251 *outColorType = kRGBA_F16_SkColorType; |
| 252 *outProfileType = kLinear_SkColorProfileType; |
| 253 return true; |
| 254 } |
| 255 if (value.equals("srgb")) { |
| 256 *outColorType = kN32_SkColorType; |
| 257 *outProfileType = kSRGB_SkColorProfileType; |
| 258 return true; |
| 259 } |
| 260 return false; |
| 261 } |
229 | 262 |
230 SkCommandLineConfigGpu* parse_command_line_config_gpu(const SkString& tag, | 263 SkCommandLineConfigGpu* parse_command_line_config_gpu(const SkString& tag, |
231 const SkTArray<SkString>&
vias, | 264 const SkTArray<SkString>&
vias, |
232 const SkString& options) { | 265 const SkString& options) { |
233 // Defaults for GPU backend. | 266 // Defaults for GPU backend. |
234 bool seenAPI = false; | 267 bool seenAPI = false; |
235 SkCommandLineConfigGpu::ContextType contextType = GrContextFactory::kNative_
GLContextType; | 268 SkCommandLineConfigGpu::ContextType contextType = GrContextFactory::kNative_
GLContextType; |
236 bool seenUseNVPR = false; | 269 bool seenUseNVPR = false; |
237 bool useNVPR = false; | 270 bool useNVPR = false; |
238 bool seenUseDIText =false; | 271 bool seenUseDIText =false; |
239 bool useDIText = false; | 272 bool useDIText = false; |
240 bool seenSamples = false; | 273 bool seenSamples = false; |
241 int samples = 0; | 274 int samples = 0; |
| 275 bool seenColor = false; |
| 276 SkColorType colorType = kN32_SkColorType; |
| 277 SkColorProfileType profileType = kLinear_SkColorProfileType; |
242 | 278 |
243 SkTArray<SkString> optionParts; | 279 SkTArray<SkString> optionParts; |
244 SkStrSplit(options.c_str(), ",", kStrict_SkStrSplitMode, &optionParts); | 280 SkStrSplit(options.c_str(), ",", kStrict_SkStrSplitMode, &optionParts); |
245 for (int i = 0; i < optionParts.count(); ++i) { | 281 for (int i = 0; i < optionParts.count(); ++i) { |
246 SkTArray<SkString> keyValueParts; | 282 SkTArray<SkString> keyValueParts; |
247 SkStrSplit(optionParts[i].c_str(), "=", kStrict_SkStrSplitMode, &keyValu
eParts); | 283 SkStrSplit(optionParts[i].c_str(), "=", kStrict_SkStrSplitMode, &keyValu
eParts); |
248 if (keyValueParts.count() != 2) { | 284 if (keyValueParts.count() != 2) { |
249 return nullptr; | 285 return nullptr; |
250 } | 286 } |
251 const SkString& key = keyValueParts[0]; | 287 const SkString& key = keyValueParts[0]; |
252 const SkString& value = keyValueParts[1]; | 288 const SkString& value = keyValueParts[1]; |
253 bool valueOk = false; | 289 bool valueOk = false; |
254 if (key.equals("api") && !seenAPI) { | 290 if (key.equals("api") && !seenAPI) { |
255 valueOk = parse_option_gpu_api(value, &contextType); | 291 valueOk = parse_option_gpu_api(value, &contextType); |
256 seenAPI = true; | 292 seenAPI = true; |
257 } else if (key.equals("nvpr") && !seenUseNVPR) { | 293 } else if (key.equals("nvpr") && !seenUseNVPR) { |
258 valueOk = parse_option_bool(value, &useNVPR); | 294 valueOk = parse_option_bool(value, &useNVPR); |
259 seenUseNVPR = true; | 295 seenUseNVPR = true; |
260 } else if (key.equals("dit") && !seenUseDIText) { | 296 } else if (key.equals("dit") && !seenUseDIText) { |
261 valueOk = parse_option_bool(value, &useDIText); | 297 valueOk = parse_option_bool(value, &useDIText); |
262 seenUseDIText = true; | 298 seenUseDIText = true; |
263 } else if (key.equals("samples") && !seenSamples) { | 299 } else if (key.equals("samples") && !seenSamples) { |
264 valueOk = parse_option_int(value, &samples); | 300 valueOk = parse_option_int(value, &samples); |
265 seenSamples = true; | 301 seenSamples = true; |
| 302 } else if (key.equals("color") && !seenColor) { |
| 303 valueOk = parse_option_gpu_color(value, &colorType, &profileType); |
| 304 seenColor = true; |
266 } | 305 } |
267 if (!valueOk) { | 306 if (!valueOk) { |
268 return nullptr; | 307 return nullptr; |
269 } | 308 } |
270 } | 309 } |
271 return new SkCommandLineConfigGpu(tag, vias, contextType, useNVPR, useDIText
, samples); | 310 return new SkCommandLineConfigGpu(tag, vias, contextType, useNVPR, useDIText
, samples, |
| 311 colorType, profileType); |
272 } | 312 } |
273 #endif | 313 #endif |
274 | 314 |
275 void ParseConfigs(const SkCommandLineFlags::StringArray& configs, | 315 void ParseConfigs(const SkCommandLineFlags::StringArray& configs, |
276 SkCommandLineConfigArray* outResult) { | 316 SkCommandLineConfigArray* outResult) { |
277 outResult->reset(); | 317 outResult->reset(); |
278 for (int i = 0; i < configs.count(); ++i) { | 318 for (int i = 0; i < configs.count(); ++i) { |
279 SkString extendedBackend; | 319 SkString extendedBackend; |
280 SkString extendedOptions; | 320 SkString extendedOptions; |
281 SkString simpleBackend; | 321 SkString simpleBackend; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 if (extendedBackend.equals("gpu")) { | 367 if (extendedBackend.equals("gpu")) { |
328 parsedConfig = parse_command_line_config_gpu(tag, vias, extendedOpti
ons); | 368 parsedConfig = parse_command_line_config_gpu(tag, vias, extendedOpti
ons); |
329 } | 369 } |
330 #endif | 370 #endif |
331 if (!parsedConfig) { | 371 if (!parsedConfig) { |
332 parsedConfig = new SkCommandLineConfig(tag, simpleBackend, vias); | 372 parsedConfig = new SkCommandLineConfig(tag, simpleBackend, vias); |
333 } | 373 } |
334 outResult->emplace_back(parsedConfig); | 374 outResult->emplace_back(parsedConfig); |
335 } | 375 } |
336 } | 376 } |
OLD | NEW |