Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Side by Side Diff: tools/flags/SkCommonFlagsConfig.cpp

Issue 1490113005: Add config options to run different GPU APIs to dm and nanobench (Closed) Base URL: https://skia.googlesource.com/skia.git@commandbuffer-as-api-03-context-factory-glcontext-type
Patch Set: win angle Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 #if SK_BUILD_FOR_WIN
17 " angle"
18 #endif
19 #endif
20 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
21 " hwui"
22 #endif
23 , "Options: 565 8888 debug gpu gpudebug gpudft gpunull "
24 "msaa16 msaa4 nonrendering null nullgpu nvprmsaa16 nvprmsaa4 "
25 "pdf pdf_poppler skp svg xps"
26 #if SK_ANGLE
27 #if SK_BUILD_FOR_WIN
28 " angle"
29 #endif
30 " angle-gl"
31 #endif
32 #if SK_COMMAND_BUFFER
33 " commandbuffer"
34 #endif
35 #if SK_MESA
36 " mesa"
37 #endif
38 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
39 " hwui"
40 #endif
41 " or use extended form 'backend(option=value,...)'.\n",
scroggo 2015/12/03 19:02:58 This code looks hard to maintain, especially when
Kimmo Kinnunen 2015/12/04 14:26:19 In theory, yes, it can be nicer. It could be eithe
scroggo 2015/12/04 16:40:03 No, it's not a requirement to land the patch.
42 "Extended form: 'backend(option=value,...)'\n\n"
43 "Possible backends and options:\n"
44 #if SK_SUPPORT_GPU
45 "\n"
46 "gpu(api=string,dit=bool,nvpr=bool,samples=int)\tGPU backend\n"
47 "\tapi\ttype: string\tdefault: native.\n"
48 "\t Select graphics API to use with gpu backend.\n"
49 "\t Options:\n"
50 "\t\tnative\t\t\tUse platform default OpenGL or OpenGL ES backend.\n"
51 "\t\tgl \t\t\tUse OpenGL.\n"
52 "\t\tgles \t\t\tUse OpenGL ES.\n"
53 "\t\tdebug \t\t\tUse debug OpenGL.\n"
54 "\t\tnull \t\t\tUse null OpenGL.\n"
55 #if SK_ANGLE
56 #if SK_BUILD_FOR_WIN
57 "\t\tangle\t\t\tUse ANGLE DirectX.\n"
58 #endif
59 "\t\tangle-gl\t\t\tUse ANGLE OpenGL.\n"
60 #endif
61 #if SK_COMMAND_BUFFER
62 "\t\tcommandbuffer\t\tUse command buffer.\n"
63 #endif
64 #if SK_MESA
65 "\t\tmesa\t\t\tUse MESA.\n"
66 #endif
67 "\tdit\ttype: bool\tdefault: false.\n"
68 "\t Use device independent text.\n"
69 "\tnvpr\ttype: bool\tdefault: false.\n"
70 "\t Use NV_path_rendering OpenGL and OpenGL ES extension.\n"
71 "\tsamples\ttype: int\tdefault: 0.\n"
72 "\t Use multisampling with N samples.\n"
73 "\n"
74 "Predefined configs:\n\n"
75 "\tgpu \t= gpu()\n"
76 "\tmsaa4 \t= gpu(samples=4)\n"
77 "\tmsaa16 \t= gpu(samples=16)\n"
78 "\tnvprmsaa4\t= gpu(nvpr=true,samples=4)\n"
79 "\tnvprmsaa16\t= gpu(nvpr=true,samples=16)\n"
80 "\tgpudft \t= gpu(dit=true)\n"
81 "\tgpudebug \t= gpu(api=debug)\n"
82 "\tgpunull \t= gpu(api=null)\n"
83 "\tdebug \t= gpu(api=debug)\n"
84 "\tnullgpu \t= gpu(api=null)\n"
85 #if SK_ANGLE
86 #if SK_BUILD_FOR_WIN
87 "\tangle \t= gpu(api=angle)\n"
88 #endif
89 "\tangle-gl \t= gpu(api=angle-gl)\n"
90 #endif
91 #if SK_COMMAND_BUFFER
92 "\tcommandbuffer\t= gpu(api=commandbuffer)\n"
93 #endif
94 #if SK_MESA
95 "\tmesa \t= gpu(api=mesa)\n"
96 #endif
97 #endif
98 "");
99
100 static const struct {
101 const char* predefinedConfig;
102 const char* backend;
103 const char* options;
104 } gPredefinedConfigs[] = {
105 #if SK_SUPPORT_GPU
106 "gpu", "gpu", "",
107 "msaa4", "gpu", "samples=4",
108 "msaa16", "gpu", "samples=16",
109 "nvprmsaa4", "gpu", "nvpr=true,samples=4",
110 "nvprmsaa16", "gpu", "nvpr=true,samples=16",
111 "gpudft", "gpu", "dit=true",
112 "gpudebug", "gpu", "api=debug",
113 "gpunull", "gpu", "api=null",
114 "debug", "gpu", "api=debug",
115 "nullgpu", "gpu", "api=null",
116 #if SK_ANGLE
117 #if SK_BUILD_FOR_WIN
118 "angle", "gpu", "api=angle",
119 #endif
120 "angle-gl", "gpu", "api=angle-gl",
121 #endif
122 #if SK_COMMAND_BUFFER
123 "commandbuffer", "gpu", "api=commandbuffer",
124 #endif
125 #if SK_MESA
126 "mesa", "gpu", "api=mesa",
127 #endif
128 #else
129 "", "", ""
130 #endif
131 };
132
133 SkCommandLineConfig::SkCommandLineConfig(const SkString& tag, const SkTArray<SkS tring>& viaParts)
134 : fTag(tag)
135 , fViaParts(viaParts) {
136 }
137 SkCommandLineConfig::~SkCommandLineConfig() {
138 }
139
140 #if SK_SUPPORT_GPU
141 SkCommandLineConfigGpu::SkCommandLineConfigGpu(
142 const SkString& tag, const SkTArray<SkString>& viaParts,
143 API api, bool useNVPR, bool useDIText, int samples)
144 : SkCommandLineConfig(tag, viaParts)
145 , fAPI(api)
146 , fUseNVPR(useNVPR)
147 , fUseDIText(useDIText)
148 , fSamples(samples) {
149 }
150 static bool parse_option_int(const SkString& value, int* outInt) {
151 if (value.isEmpty()) {
152 return false;
153 }
154 char* endptr = nullptr;
155 long intValue = strtol(value.c_str(), &endptr, 10);
156 if (*endptr != '\0') {
157 return false;
158 }
159 *outInt = static_cast<int>(intValue);
160 return true;
161 }
162 static bool parse_option_bool(const SkString& value, bool* outBool) {
163 if (value.equals("true")) {
164 *outBool = true;
165 return true;
166 } else if (value.equals("false")) {
scroggo 2015/12/03 19:02:59 nit: Here and elsewhere - no need to use "else" if
Kimmo Kinnunen 2015/12/04 14:26:19 Done.
167 *outBool = false;
168 return true;
169 }
170 return false;
171 }
172 static bool parse_option_gpu_api(const SkString& value, SkCommandLineConfigGpu:: API* outAPI) {
173 if (value.equals("native")) {
174 *outAPI = SkCommandLineConfigGpu::kNative_API;
175 return true;
176 } else if (value.equals("gl")) {
177 *outAPI = SkCommandLineConfigGpu::kGL_API;
178 return true;
179 } else if (value.equals("gles")) {
180 *outAPI = SkCommandLineConfigGpu::kGLES_API;
181 return true;
182 } else if (value.equals("debug")) {
183 *outAPI = SkCommandLineConfigGpu::kDebug_API;
184 return true;
185 } else if (value.equals("null")) {
186 *outAPI = SkCommandLineConfigGpu::kNull_API;
187 return true;
188 }
189 #if SK_ANGLE
190 #if SK_BUILD_FOR_WIN
191 else if (value.equals("angle")) {
192 *outAPI = SkCommandLineConfigGpu::kANGLE_API;
193 return true;
194 }
195 #endif
196 else if (value.equals("angle-gl")) {
197 *outAPI = SkCommandLineConfigGpu::kANGLE_GL_API;
198 return true;
199 }
200 #endif
201 #if SK_COMMAND_BUFFER
202 else if (value.equals("commandbuffer")) {
203 *outAPI = SkCommandLineConfigGpu::kCommandBuffer_API;
204 return true;
205 }
206 #endif
207 #if SK_MESA
208 else if (value.equals("mesa")) {
209 *outAPI = SkCommandLineConfigGpu::kMESA_API;
210 return true;
211 }
212 #endif
213 return false;
214 }
215
216 SkCommandLineConfigGpu* parse_command_line_config_gpu(const SkString& tag, const SkTArray<SkString>& vias, const SkString& options) {
scroggo 2015/12/03 19:02:58 100 chars
Kimmo Kinnunen 2015/12/04 14:26:19 Done.
217 // Defaults for GPU backend.
218 bool seenAPI = false;
219 SkCommandLineConfigGpu::API api = SkCommandLineConfigGpu::kNative_API;
220 bool seenUseNVPR = false;
221 bool useNVPR = false;
222 bool seenUseDIText =false;
223 bool useDIText = false;
224 bool seenSamples = false;
225 int samples = 0;
226
227 if (options.endsWith(",") || options.startsWith(",")) {
scroggo 2015/12/03 19:02:59 Why this check?
Kimmo Kinnunen 2015/12/04 14:26:19 gpu(,api=gl) gpu(api=gl,) gpu(,,) These look unus
scroggo 2015/12/04 16:40:03 Maybe add a comment? If a user does enter one of
Kimmo Kinnunen 2015/12/07 09:26:48 Would it be clearer if I just fixed the root cause
scroggo 2015/12/07 13:27:51 sgtm
228 return nullptr;
229 }
230 SkTArray<SkString> optionParts;
231 SkStrSplit(options.c_str(), ",", &optionParts);
232 for (int i = 0; i < optionParts.count(); ++i) {
233 SkTArray<SkString> keyValueParts;
234 SkStrSplit(optionParts[i].c_str(), "=", &keyValueParts);
235 if (keyValueParts.count() != 2) {
236 return nullptr;
237 }
238 const SkString& key = keyValueParts[0];
239 const SkString& value = keyValueParts[1];
240 bool valueOk = false;
241 if (key.equals("api") && !seenAPI) {
242 valueOk = parse_option_gpu_api(value, &api);
243 seenAPI = true;
244 } else if (key.equals("nvpr") && !seenUseNVPR) {
245 valueOk = parse_option_bool(value, &useNVPR);
246 seenUseNVPR = true;
247 } else if (key.equals("dit") && !seenUseDIText) {
248 valueOk = parse_option_bool(value, &useDIText);
249 seenUseDIText = true;
250 } else if (key.equals("samples") && !seenSamples) {
251 valueOk = parse_option_int(value, &samples);
252 seenSamples = true;
253 }
254 if (!valueOk) {
255 return nullptr;
256 }
257 }
258 return new SkCommandLineConfigGpu(tag, vias, api, useNVPR, useDIText, sample s);
259 }
260 #endif
261
262 void ParseConfigs(const SkCommandLineFlags::StringArray& configs, SkCommandLineC onfigArray* outResult) {
scroggo 2015/12/03 19:02:59 100 chars
Kimmo Kinnunen 2015/12/04 14:26:19 Done.
263 outResult->reset();
264 for (int i = 0; i < configs.count(); ++i) {
265 SkString extendedConfigBackend;
266 SkString extendedConfigOptions;
267 SkString tag(configs[i]);
268 SkTArray<SkString> vias;
269
270 SkTArray<SkString> parts;
271 SkStrSplit(tag.c_str(), "(", &parts);
272 if (parts.count() == 2) {
273 SkTArray<SkString> parts2;
274 SkStrSplit(parts[1].c_str(), ")", &parts2);
275 if (parts[1].endsWith(")") && parts2.count() == 1) {
276 SkStrSplit(parts[0].c_str(), "-", &vias);
277 if (vias.count()) {
278 extendedConfigBackend = vias[vias.count() - 1];
279 vias.pop_back();
280 } else {
281 extendedConfigBackend = parts[0];
282 }
283 extendedConfigOptions = parts2[0];
284 tag.printf("%s(%s)", extendedConfigBackend.c_str(), extendedConf igOptions.c_str());
285 }
286 }
287 if (extendedConfigBackend.isEmpty()) {
288 SkStrSplit(tag.c_str(), "-", &vias);
289 if (vias.count()) {
290 tag = vias[vias.count() - 1];
291 vias.pop_back();
292 }
293 // Note: no #if SK_ANGLE: this is a special rule in the via-tag gram mar.
294 if (vias.count() && tag.equals("gl") && vias[vias.count() - 1].equal s("angle")) {
295 tag = "angle-gl";
296 vias.pop_back();
297 }
298 }
299
300 for (size_t j = 0;
scroggo 2015/12/03 19:02:59 why not: for (auto predefinedConfig : gPredefined
Kimmo Kinnunen 2015/12/04 14:26:19 Done.
301 j < SK_ARRAY_COUNT(gPredefinedConfigs) && extendedConfigBackend.isE mpty(); ++j) {
302 if (tag.equals(gPredefinedConfigs[j].predefinedConfig)) {
303 extendedConfigBackend = gPredefinedConfigs[j].backend;
304 extendedConfigOptions = gPredefinedConfigs[j].options;
305 }
306 }
307
308 SkCommandLineConfig* parsedConfig = nullptr;
309 #if SK_SUPPORT_GPU
310 if (extendedConfigBackend.equals("gpu")) {
311 parsedConfig = parse_command_line_config_gpu(tag, vias, extendedConf igOptions);
312 }
313 #endif
314 if (!parsedConfig) {
315 parsedConfig = new SkCommandLineConfig(tag, vias);
316 }
317 outResult->emplace_back(parsedConfig);
318 }
319 }
OLDNEW
« tools/flags/SkCommonFlagsConfig.h ('K') | « tools/flags/SkCommonFlagsConfig.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698