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 #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" |
100 "\tanglesrgb \t= gpu(api=angle,color=srgb)\n" | |
92 #endif | 101 #endif |
93 "\tangle-gl \t= gpu(api=angle-gl)\n" | 102 "\tangle-gl \t= gpu(api=angle-gl)\n" |
94 #endif | 103 #endif |
95 #if SK_COMMAND_BUFFER | 104 #if SK_COMMAND_BUFFER |
96 "\tcommandbuffer\t= gpu(api=commandbuffer)\n" | 105 "\tcommandbuffer\t= gpu(api=commandbuffer)\n" |
97 #endif | 106 #endif |
98 #if SK_MESA | 107 #if SK_MESA |
99 "\tmesa \t= gpu(api=mesa)\n" | 108 "\tmesa \t= gpu(api=mesa)\n" |
100 #endif | 109 #endif |
101 #endif | 110 #endif |
102 ; | 111 ; |
103 | 112 |
104 DEFINE_extended_string(config, defaultConfigs, configHelp, configExtendedHelp); | 113 DEFINE_extended_string(config, defaultConfigs, configHelp, configExtendedHelp); |
105 | 114 |
106 static const struct { | 115 static const struct { |
107 const char* predefinedConfig; | 116 const char* predefinedConfig; |
108 const char* backend; | 117 const char* backend; |
109 const char* options; | 118 const char* options; |
110 } gPredefinedConfigs[] = { | 119 } gPredefinedConfigs[] = { |
111 #if SK_SUPPORT_GPU | 120 #if SK_SUPPORT_GPU |
112 { "gpu", "gpu", "" }, | 121 { "gpu", "gpu", "" }, |
113 { "msaa4", "gpu", "samples=4" }, | 122 { "msaa4", "gpu", "samples=4" }, |
114 { "msaa16", "gpu", "samples=16" }, | 123 { "msaa16", "gpu", "samples=16" }, |
115 { "nvprmsaa4", "gpu", "nvpr=true,samples=4,dit=true" }, | 124 { "nvprmsaa4", "gpu", "nvpr=true,samples=4,dit=true" }, |
116 { "nvprmsaa16", "gpu", "nvpr=true,samples=16,dit=true" }, | 125 { "nvprmsaa16", "gpu", "nvpr=true,samples=16,dit=true" }, |
126 { "gpuf16", "gpu", "color=f16" }, | |
127 { "gpusrgb", "gpu", "color=srgb" }, | |
117 { "gpudft", "gpu", "dit=true" }, | 128 { "gpudft", "gpu", "dit=true" }, |
118 { "gpudebug", "gpu", "api=debug" }, | 129 { "gpudebug", "gpu", "api=debug" }, |
119 { "gpunull", "gpu", "api=null" }, | 130 { "gpunull", "gpu", "api=null" }, |
120 { "debug", "gpu", "api=debug" }, | 131 { "debug", "gpu", "api=debug" }, |
121 { "nullgpu", "gpu", "api=null" } | 132 { "nullgpu", "gpu", "api=null" } |
122 #if SK_ANGLE | 133 #if SK_ANGLE |
123 #ifdef SK_BUILD_FOR_WIN | 134 #ifdef SK_BUILD_FOR_WIN |
124 , { "angle", "gpu", "api=angle" } | 135 , { "angle", "gpu", "api=angle" } |
136 , { "anglesrgb", "gpu", "api=angle,color=srgb" } | |
125 #endif | 137 #endif |
126 , { "angle-gl", "gpu", "api=angle-gl" } | 138 , { "angle-gl", "gpu", "api=angle-gl" } |
127 #endif | 139 #endif |
128 #if SK_COMMAND_BUFFER | 140 #if SK_COMMAND_BUFFER |
129 , { "commandbuffer", "gpu", "api=commandbuffer" } | 141 , { "commandbuffer", "gpu", "api=commandbuffer" } |
130 #endif | 142 #endif |
131 #if SK_MESA | 143 #if SK_MESA |
132 , { "mesa", "gpu", "api=mesa" } | 144 , { "mesa", "gpu", "api=mesa" } |
133 #endif | 145 #endif |
134 #else | 146 #else |
135 { "", "", "" } | 147 { "", "", "" } |
136 #endif | 148 #endif |
137 }; | 149 }; |
138 | 150 |
139 SkCommandLineConfig::SkCommandLineConfig(const SkString& tag, const SkString& ba ckend, | 151 SkCommandLineConfig::SkCommandLineConfig(const SkString& tag, const SkString& ba ckend, |
140 const SkTArray<SkString>& viaParts) | 152 const SkTArray<SkString>& viaParts) |
141 : fTag(tag) | 153 : fTag(tag) |
142 , fBackend(backend) | 154 , fBackend(backend) |
143 , fViaParts(viaParts) { | 155 , fViaParts(viaParts) { |
144 } | 156 } |
145 SkCommandLineConfig::~SkCommandLineConfig() { | 157 SkCommandLineConfig::~SkCommandLineConfig() { |
146 } | 158 } |
147 | 159 |
148 #if SK_SUPPORT_GPU | 160 #if SK_SUPPORT_GPU |
149 SkCommandLineConfigGpu::SkCommandLineConfigGpu( | 161 SkCommandLineConfigGpu::SkCommandLineConfigGpu( |
150 const SkString& tag, const SkTArray<SkString>& viaParts, | 162 const SkString& tag, const SkTArray<SkString>& viaParts, |
151 ContextType contextType, bool useNVPR, bool useDIText, int samples) | 163 ContextType contextType, bool useNVPR, bool useDIText, int samples, |
164 SkColorType colorType, SkColorProfileType profileType) | |
152 : SkCommandLineConfig(tag, SkString("gpu"), viaParts) | 165 : SkCommandLineConfig(tag, SkString("gpu"), viaParts) |
153 , fContextType(contextType) | 166 , fContextType(contextType) |
154 , fUseNVPR(useNVPR) | 167 , fUseNVPR(useNVPR) |
155 , fUseDIText(useDIText) | 168 , fUseDIText(useDIText) |
156 , fSamples(samples) { | 169 , fSamples(samples) |
170 , fColorType(colorType) | |
171 , fProfileType(profileType) { | |
157 } | 172 } |
158 static bool parse_option_int(const SkString& value, int* outInt) { | 173 static bool parse_option_int(const SkString& value, int* outInt) { |
159 if (value.isEmpty()) { | 174 if (value.isEmpty()) { |
160 return false; | 175 return false; |
161 } | 176 } |
162 char* endptr = nullptr; | 177 char* endptr = nullptr; |
163 long intValue = strtol(value.c_str(), &endptr, 10); | 178 long intValue = strtol(value.c_str(), &endptr, 10); |
164 if (*endptr != '\0') { | 179 if (*endptr != '\0') { |
165 return false; | 180 return false; |
166 } | 181 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 } | 234 } |
220 #endif | 235 #endif |
221 #if SK_MESA | 236 #if SK_MESA |
222 if (value.equals("mesa")) { | 237 if (value.equals("mesa")) { |
223 *outContextType = GrContextFactory::kMESA_GLContextType; | 238 *outContextType = GrContextFactory::kMESA_GLContextType; |
224 return true; | 239 return true; |
225 } | 240 } |
226 #endif | 241 #endif |
227 return false; | 242 return false; |
228 } | 243 } |
244 static bool parse_option_gpu_color(const SkString& value, | |
245 SkColorType* outColorType, | |
246 SkColorProfileType* outProfileType) { | |
247 if (value.equals("8888")) { | |
248 *outColorType = kN32_SkColorType; | |
249 *outProfileType = kLinear_SkColorProfileType; | |
250 return true; | |
251 } | |
252 if (value.equals("f16")) { | |
253 *outColorType = kRGBA_F16_SkColorType; | |
254 *outProfileType = kLinear_SkColorProfileType; | |
255 return true; | |
256 } | |
257 if (value.equals("srgb")) { | |
258 *outColorType = kN32_SkColorType; | |
Brian Osman
2016/03/09 21:32:39
If we decide that sRGB implies RGBA, this is where
| |
259 *outProfileType = kSRGB_SkColorProfileType; | |
260 return true; | |
261 } | |
262 return false; | |
263 } | |
229 | 264 |
230 SkCommandLineConfigGpu* parse_command_line_config_gpu(const SkString& tag, | 265 SkCommandLineConfigGpu* parse_command_line_config_gpu(const SkString& tag, |
231 const SkTArray<SkString>& vias, | 266 const SkTArray<SkString>& vias, |
232 const SkString& options) { | 267 const SkString& options) { |
233 // Defaults for GPU backend. | 268 // Defaults for GPU backend. |
234 bool seenAPI = false; | 269 bool seenAPI = false; |
235 SkCommandLineConfigGpu::ContextType contextType = GrContextFactory::kNative_ GLContextType; | 270 SkCommandLineConfigGpu::ContextType contextType = GrContextFactory::kNative_ GLContextType; |
236 bool seenUseNVPR = false; | 271 bool seenUseNVPR = false; |
237 bool useNVPR = false; | 272 bool useNVPR = false; |
238 bool seenUseDIText =false; | 273 bool seenUseDIText =false; |
239 bool useDIText = false; | 274 bool useDIText = false; |
240 bool seenSamples = false; | 275 bool seenSamples = false; |
241 int samples = 0; | 276 int samples = 0; |
277 bool seenColor = false; | |
278 SkColorType colorType = kN32_SkColorType; | |
279 SkColorProfileType profileType = kLinear_SkColorProfileType; | |
242 | 280 |
243 SkTArray<SkString> optionParts; | 281 SkTArray<SkString> optionParts; |
244 SkStrSplit(options.c_str(), ",", kStrict_SkStrSplitMode, &optionParts); | 282 SkStrSplit(options.c_str(), ",", kStrict_SkStrSplitMode, &optionParts); |
245 for (int i = 0; i < optionParts.count(); ++i) { | 283 for (int i = 0; i < optionParts.count(); ++i) { |
246 SkTArray<SkString> keyValueParts; | 284 SkTArray<SkString> keyValueParts; |
247 SkStrSplit(optionParts[i].c_str(), "=", kStrict_SkStrSplitMode, &keyValu eParts); | 285 SkStrSplit(optionParts[i].c_str(), "=", kStrict_SkStrSplitMode, &keyValu eParts); |
248 if (keyValueParts.count() != 2) { | 286 if (keyValueParts.count() != 2) { |
249 return nullptr; | 287 return nullptr; |
250 } | 288 } |
251 const SkString& key = keyValueParts[0]; | 289 const SkString& key = keyValueParts[0]; |
252 const SkString& value = keyValueParts[1]; | 290 const SkString& value = keyValueParts[1]; |
253 bool valueOk = false; | 291 bool valueOk = false; |
254 if (key.equals("api") && !seenAPI) { | 292 if (key.equals("api") && !seenAPI) { |
255 valueOk = parse_option_gpu_api(value, &contextType); | 293 valueOk = parse_option_gpu_api(value, &contextType); |
256 seenAPI = true; | 294 seenAPI = true; |
257 } else if (key.equals("nvpr") && !seenUseNVPR) { | 295 } else if (key.equals("nvpr") && !seenUseNVPR) { |
258 valueOk = parse_option_bool(value, &useNVPR); | 296 valueOk = parse_option_bool(value, &useNVPR); |
259 seenUseNVPR = true; | 297 seenUseNVPR = true; |
260 } else if (key.equals("dit") && !seenUseDIText) { | 298 } else if (key.equals("dit") && !seenUseDIText) { |
261 valueOk = parse_option_bool(value, &useDIText); | 299 valueOk = parse_option_bool(value, &useDIText); |
262 seenUseDIText = true; | 300 seenUseDIText = true; |
263 } else if (key.equals("samples") && !seenSamples) { | 301 } else if (key.equals("samples") && !seenSamples) { |
264 valueOk = parse_option_int(value, &samples); | 302 valueOk = parse_option_int(value, &samples); |
265 seenSamples = true; | 303 seenSamples = true; |
304 } else if (key.equals("color") && !seenColor) { | |
305 valueOk = parse_option_gpu_color(value, &colorType, &profileType); | |
306 seenColor = true; | |
266 } | 307 } |
267 if (!valueOk) { | 308 if (!valueOk) { |
268 return nullptr; | 309 return nullptr; |
269 } | 310 } |
270 } | 311 } |
271 return new SkCommandLineConfigGpu(tag, vias, contextType, useNVPR, useDIText , samples); | 312 return new SkCommandLineConfigGpu(tag, vias, contextType, useNVPR, useDIText , samples, |
313 colorType, profileType); | |
272 } | 314 } |
273 #endif | 315 #endif |
274 | 316 |
275 void ParseConfigs(const SkCommandLineFlags::StringArray& configs, | 317 void ParseConfigs(const SkCommandLineFlags::StringArray& configs, |
276 SkCommandLineConfigArray* outResult) { | 318 SkCommandLineConfigArray* outResult) { |
277 outResult->reset(); | 319 outResult->reset(); |
278 for (int i = 0; i < configs.count(); ++i) { | 320 for (int i = 0; i < configs.count(); ++i) { |
279 SkString extendedBackend; | 321 SkString extendedBackend; |
280 SkString extendedOptions; | 322 SkString extendedOptions; |
281 SkString simpleBackend; | 323 SkString simpleBackend; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
327 if (extendedBackend.equals("gpu")) { | 369 if (extendedBackend.equals("gpu")) { |
328 parsedConfig = parse_command_line_config_gpu(tag, vias, extendedOpti ons); | 370 parsedConfig = parse_command_line_config_gpu(tag, vias, extendedOpti ons); |
329 } | 371 } |
330 #endif | 372 #endif |
331 if (!parsedConfig) { | 373 if (!parsedConfig) { |
332 parsedConfig = new SkCommandLineConfig(tag, simpleBackend, vias); | 374 parsedConfig = new SkCommandLineConfig(tag, simpleBackend, vias); |
333 } | 375 } |
334 outResult->emplace_back(parsedConfig); | 376 outResult->emplace_back(parsedConfig); |
335 } | 377 } |
336 } | 378 } |
OLD | NEW |