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

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: fix errorneous config handling 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
« tests/StringTest.cpp ('K') | « tools/flags/SkCommonFlagsConfig.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifdef 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 #ifdef 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",
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 #ifdef 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 #ifdef 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 #ifdef 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 }
167 if (value.equals("false")) {
168 *outBool = false;
169 return true;
170 }
171 return false;
172 }
173 static bool parse_option_gpu_api(const SkString& value, SkCommandLineConfigGpu:: API* outAPI) {
174 if (value.equals("native")) {
175 *outAPI = SkCommandLineConfigGpu::kNative_API;
176 return true;
177 }
178 if (value.equals("gl")) {
179 *outAPI = SkCommandLineConfigGpu::kGL_API;
180 return true;
181 }
182 if (value.equals("gles")) {
183 *outAPI = SkCommandLineConfigGpu::kGLES_API;
184 return true;
185 }
186 if (value.equals("debug")) {
187 *outAPI = SkCommandLineConfigGpu::kDebug_API;
188 return true;
189 }
190 if (value.equals("null")) {
191 *outAPI = SkCommandLineConfigGpu::kNull_API;
192 return true;
193 }
194 #if SK_ANGLE
195 #ifdef SK_BUILD_FOR_WIN
196 if (value.equals("angle")) {
197 *outAPI = SkCommandLineConfigGpu::kANGLE_API;
198 return true;
199 }
200 #endif
201 if (value.equals("angle-gl")) {
202 *outAPI = SkCommandLineConfigGpu::kANGLE_GL_API;
203 return true;
204 }
205 #endif
206 #if SK_COMMAND_BUFFER
207 if (value.equals("commandbuffer")) {
208 *outAPI = SkCommandLineConfigGpu::kCommandBuffer_API;
209 return true;
210 }
211 #endif
212 #if SK_MESA
213 if (value.equals("mesa")) {
214 *outAPI = SkCommandLineConfigGpu::kMESA_API;
215 return true;
216 }
217 #endif
218 return false;
219 }
220
221 SkCommandLineConfigGpu* parse_command_line_config_gpu(const SkString& tag,
222 const SkTArray<SkString>& vias,
223 const SkString& options) {
224 // Defaults for GPU backend.
225 bool seenAPI = false;
226 SkCommandLineConfigGpu::API api = SkCommandLineConfigGpu::kNative_API;
227 bool seenUseNVPR = false;
228 bool useNVPR = false;
229 bool seenUseDIText =false;
230 bool useDIText = false;
231 bool seenSamples = false;
232 int samples = 0;
233
234 SkTArray<SkString> optionParts;
235 SkStrSplit(options.c_str(), ",", kAll_SkStrSplitResult, &optionParts);
236 for (int i = 0; i < optionParts.count(); ++i) {
237 SkTArray<SkString> keyValueParts;
238 SkStrSplit(optionParts[i].c_str(), "=", kAll_SkStrSplitResult, &keyValue Parts);
239 if (keyValueParts.count() != 2) {
240 return nullptr;
241 }
242 const SkString& key = keyValueParts[0];
243 const SkString& value = keyValueParts[1];
244 bool valueOk = false;
245 if (key.equals("api") && !seenAPI) {
246 valueOk = parse_option_gpu_api(value, &api);
247 seenAPI = true;
248 } else if (key.equals("nvpr") && !seenUseNVPR) {
249 valueOk = parse_option_bool(value, &useNVPR);
250 seenUseNVPR = true;
251 } else if (key.equals("dit") && !seenUseDIText) {
252 valueOk = parse_option_bool(value, &useDIText);
253 seenUseDIText = true;
254 } else if (key.equals("samples") && !seenSamples) {
255 valueOk = parse_option_int(value, &samples);
256 seenSamples = true;
257 }
258 if (!valueOk) {
259 return nullptr;
260 }
261 }
262 return new SkCommandLineConfigGpu(tag, vias, api, useNVPR, useDIText, sample s);
263 }
264 #endif
265
266 void ParseConfigs(const SkCommandLineFlags::StringArray& configs,
267 SkCommandLineConfigArray* outResult) {
268 outResult->reset();
269 for (int i = 0; i < configs.count(); ++i) {
270 SkString extendedConfigBackend;
271 SkString extendedConfigOptions;
272 SkString tag(configs[i]);
273 SkTArray<SkString> vias;
274
275 SkTArray<SkString> parts;
276 SkStrSplit(tag.c_str(), "(", kAll_SkStrSplitResult, &parts);
277 if (parts.count() == 2) {
278 SkTArray<SkString> parts2;
279 SkStrSplit(parts[1].c_str(), ")", kAll_SkStrSplitResult, &parts2);
280 if (parts2.count() == 2 && parts2[1].isEmpty()) {
281 SkStrSplit(parts[0].c_str(), "-", kAll_SkStrSplitResult, &vias);
282 if (vias.count()) {
283 extendedConfigBackend = vias[vias.count() - 1];
284 vias.pop_back();
285 } else {
286 extendedConfigBackend = parts[0];
287 }
288 extendedConfigOptions = parts2[0];
289 tag.printf("%s(%s)", extendedConfigBackend.c_str(), extendedConf igOptions.c_str());
290 }
291 }
292 if (extendedConfigBackend.isEmpty()) {
293 SkStrSplit(tag.c_str(), "-", kAll_SkStrSplitResult, &vias);
294 if (vias.count()) {
295 tag = vias[vias.count() - 1];
296 vias.pop_back();
297 }
298 // Note: no #if SK_ANGLE: this is a special rule in the via-tag gram mar.
299 if (vias.count() && tag.equals("gl") && vias[vias.count() - 1].equal s("angle")) {
300 tag = "angle-gl";
301 vias.pop_back();
302 }
303 }
304 if (extendedConfigBackend.isEmpty()) {
305 for (auto& predefinedConfig : gPredefinedConfigs) {
306 if (tag.equals(predefinedConfig.predefinedConfig)) {
307 extendedConfigBackend = predefinedConfig.backend;
308 extendedConfigOptions = predefinedConfig.options;
309 break;
310 }
311 }
312 }
313
314 SkCommandLineConfig* parsedConfig = nullptr;
315 #if SK_SUPPORT_GPU
316 if (extendedConfigBackend.equals("gpu")) {
317 parsedConfig = parse_command_line_config_gpu(tag, vias, extendedConf igOptions);
318 }
319 #endif
320 if (!parsedConfig) {
321 parsedConfig = new SkCommandLineConfig(tag, vias);
322 }
323 outResult->emplace_back(parsedConfig);
324 }
325 }
OLDNEW
« tests/StringTest.cpp ('K') | « tools/flags/SkCommonFlagsConfig.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698