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

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

Issue 1536963002: Revert of 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: 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
« no previous file with comments | « 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 static const char defaultConfigs[] =
13 "565 8888 gpu nonrendering"
14 #if SK_ANGLE
15 #ifdef SK_BUILD_FOR_WIN
16 " angle"
17 #endif
18 #endif
19 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
20 " hwui"
21 #endif
22 ;
23
24 static const char configHelp[] =
25 "Options: 565 8888 debug gpu gpudebug gpudft gpunull "
26 "msaa16 msaa4 nonrendering null nullgpu nvprmsaa16 nvprmsaa4 "
27 "pdf pdf_poppler skp svg xps"
28 #if SK_ANGLE
29 #ifdef SK_BUILD_FOR_WIN
30 " angle"
31 #endif
32 " angle-gl"
33 #endif
34 #if SK_COMMAND_BUFFER
35 " commandbuffer"
36 #endif
37 #if SK_MESA
38 " mesa"
39 #endif
40 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
41 " hwui"
42 #endif
43 " or use extended form 'backend(option=value,...)'.\n";
44
45 static const char configExtendedHelp[] =
46 "Extended form: 'backend(option=value,...)'\n\n"
47 "Possible backends and options:\n"
48 #if SK_SUPPORT_GPU
49 "\n"
50 "gpu(api=string,dit=bool,nvpr=bool,samples=int)\tGPU backend\n"
51 "\tapi\ttype: string\tdefault: native.\n"
52 "\t Select graphics API to use with gpu backend.\n"
53 "\t Options:\n"
54 "\t\tnative\t\t\tUse platform default OpenGL or OpenGL ES backend.\n"
55 "\t\tgl \t\t\tUse OpenGL.\n"
56 "\t\tgles \t\t\tUse OpenGL ES.\n"
57 "\t\tdebug \t\t\tUse debug OpenGL.\n"
58 "\t\tnull \t\t\tUse null OpenGL.\n"
59 #if SK_ANGLE
60 #ifdef SK_BUILD_FOR_WIN
61 "\t\tangle\t\t\tUse ANGLE DirectX.\n"
62 #endif
63 "\t\tangle-gl\t\t\tUse ANGLE OpenGL.\n"
64 #endif
65 #if SK_COMMAND_BUFFER
66 "\t\tcommandbuffer\t\tUse command buffer.\n"
67 #endif
68 #if SK_MESA
69 "\t\tmesa\t\t\tUse MESA.\n"
70 #endif
71 "\tdit\ttype: bool\tdefault: false.\n"
72 "\t Use device independent text.\n"
73 "\tnvpr\ttype: bool\tdefault: false.\n"
74 "\t Use NV_path_rendering OpenGL and OpenGL ES extension.\n"
75 "\tsamples\ttype: int\tdefault: 0.\n"
76 "\t Use multisampling with N samples.\n"
77 "\n"
78 "Predefined configs:\n\n"
79 "\tgpu \t= gpu()\n"
80 "\tmsaa4 \t= gpu(samples=4)\n"
81 "\tmsaa16 \t= gpu(samples=16)\n"
82 "\tnvprmsaa4\t= gpu(nvpr=true,samples=4)\n"
83 "\tnvprmsaa16\t= gpu(nvpr=true,samples=16)\n"
84 "\tgpudft \t= gpu(dit=true)\n"
85 "\tgpudebug \t= gpu(api=debug)\n"
86 "\tgpunull \t= gpu(api=null)\n"
87 "\tdebug \t= gpu(api=debug)\n"
88 "\tnullgpu \t= gpu(api=null)\n"
89 #if SK_ANGLE
90 #ifdef SK_BUILD_FOR_WIN
91 "\tangle \t= gpu(api=angle)\n"
92 #endif
93 "\tangle-gl \t= gpu(api=angle-gl)\n"
94 #endif
95 #if SK_COMMAND_BUFFER
96 "\tcommandbuffer\t= gpu(api=commandbuffer)\n"
97 #endif
98 #if SK_MESA
99 "\tmesa \t= gpu(api=mesa)\n"
100 #endif
101 #endif
102 ;
103
104 DEFINE_extended_string(config, defaultConfigs, configHelp, configExtendedHelp);
105
106 static const struct {
107 const char* predefinedConfig;
108 const char* backend;
109 const char* options;
110 } gPredefinedConfigs[] = {
111 #if SK_SUPPORT_GPU
112 { "gpu", "gpu", "" },
113 { "msaa4", "gpu", "samples=4" },
114 { "msaa16", "gpu", "samples=16" },
115 { "nvprmsaa4", "gpu", "nvpr=true,samples=4" },
116 { "nvprmsaa16", "gpu", "nvpr=true,samples=16" },
117 { "gpudft", "gpu", "dit=true" },
118 { "gpudebug", "gpu", "api=debug" },
119 { "gpunull", "gpu", "api=null" },
120 { "debug", "gpu", "api=debug" },
121 { "nullgpu", "gpu", "api=null" }
122 #if SK_ANGLE
123 #ifdef SK_BUILD_FOR_WIN
124 , { "angle", "gpu", "api=angle" }
125 #endif
126 , { "angle-gl", "gpu", "api=angle-gl" }
127 #endif
128 #if SK_COMMAND_BUFFER
129 , { "commandbuffer", "gpu", "api=commandbuffer" }
130 #endif
131 #if SK_MESA
132 , { "mesa", "gpu", "api=mesa" }
133 #endif
134 #else
135 { "", "", "" }
136 #endif
137 };
138
139 SkCommandLineConfig::SkCommandLineConfig(const SkString& tag, const SkTArray<SkS tring>& viaParts)
140 : fTag(tag)
141 , fViaParts(viaParts) {
142 }
143 SkCommandLineConfig::~SkCommandLineConfig() {
144 }
145
146 #if SK_SUPPORT_GPU
147 SkCommandLineConfigGpu::SkCommandLineConfigGpu(
148 const SkString& tag, const SkTArray<SkString>& viaParts,
149 ContextType contextType, bool useNVPR, bool useDIText, int samples)
150 : SkCommandLineConfig(tag, viaParts)
151 , fContextType(contextType)
152 , fUseNVPR(useNVPR)
153 , fUseDIText(useDIText)
154 , fSamples(samples) {
155 }
156 static bool parse_option_int(const SkString& value, int* outInt) {
157 if (value.isEmpty()) {
158 return false;
159 }
160 char* endptr = nullptr;
161 long intValue = strtol(value.c_str(), &endptr, 10);
162 if (*endptr != '\0') {
163 return false;
164 }
165 *outInt = static_cast<int>(intValue);
166 return true;
167 }
168 static bool parse_option_bool(const SkString& value, bool* outBool) {
169 if (value.equals("true")) {
170 *outBool = true;
171 return true;
172 }
173 if (value.equals("false")) {
174 *outBool = false;
175 return true;
176 }
177 return false;
178 }
179 static bool parse_option_gpu_api(const SkString& value,
180 SkCommandLineConfigGpu::ContextType* outContext Type) {
181 if (value.equals("native")) {
182 *outContextType = GrContextFactory::kNative_GLContextType;
183 return true;
184 }
185 if (value.equals("gl")) {
186 *outContextType = GrContextFactory::kGL_GLContextType;
187 return true;
188 }
189 if (value.equals("gles")) {
190 *outContextType = GrContextFactory::kGLES_GLContextType;
191 return true;
192 }
193 if (value.equals("debug")) {
194 *outContextType = GrContextFactory::kDebug_GLContextType;
195 return true;
196 }
197 if (value.equals("null")) {
198 *outContextType = GrContextFactory::kNull_GLContextType;
199 return true;
200 }
201 #if SK_ANGLE
202 #ifdef SK_BUILD_FOR_WIN
203 if (value.equals("angle")) {
204 *outContextType = GrContextFactory::kANGLE_GLContextType;
205 return true;
206 }
207 #endif
208 if (value.equals("angle-gl")) {
209 *outContextType = GrContextFactory::kANGLE_GL_GLContextType;
210 return true;
211 }
212 #endif
213 #if SK_COMMAND_BUFFER
214 if (value.equals("commandbuffer")) {
215 *outContextType = GrContextFactory::kCommandBuffer_GLContextType;
216 return true;
217 }
218 #endif
219 #if SK_MESA
220 if (value.equals("mesa")) {
221 *outContextType = GrContextFactory::kMESA_GLContextType;
222 return true;
223 }
224 #endif
225 return false;
226 }
227
228 SkCommandLineConfigGpu* parse_command_line_config_gpu(const SkString& tag,
229 const SkTArray<SkString>& vias,
230 const SkString& options) {
231 // Defaults for GPU backend.
232 bool seenAPI = false;
233 SkCommandLineConfigGpu::ContextType contextType = GrContextFactory::kNative_ GLContextType;
234 bool seenUseNVPR = false;
235 bool useNVPR = false;
236 bool seenUseDIText =false;
237 bool useDIText = false;
238 bool seenSamples = false;
239 int samples = 0;
240
241 SkTArray<SkString> optionParts;
242 SkStrSplit(options.c_str(), ",", kStrict_SkStrSplitMode, &optionParts);
243 for (int i = 0; i < optionParts.count(); ++i) {
244 SkTArray<SkString> keyValueParts;
245 SkStrSplit(optionParts[i].c_str(), "=", kStrict_SkStrSplitMode, &keyValu eParts);
246 if (keyValueParts.count() != 2) {
247 return nullptr;
248 }
249 const SkString& key = keyValueParts[0];
250 const SkString& value = keyValueParts[1];
251 bool valueOk = false;
252 if (key.equals("api") && !seenAPI) {
253 valueOk = parse_option_gpu_api(value, &contextType);
254 seenAPI = true;
255 } else if (key.equals("nvpr") && !seenUseNVPR) {
256 valueOk = parse_option_bool(value, &useNVPR);
257 seenUseNVPR = true;
258 } else if (key.equals("dit") && !seenUseDIText) {
259 valueOk = parse_option_bool(value, &useDIText);
260 seenUseDIText = true;
261 } else if (key.equals("samples") && !seenSamples) {
262 valueOk = parse_option_int(value, &samples);
263 seenSamples = true;
264 }
265 if (!valueOk) {
266 return nullptr;
267 }
268 }
269 return new SkCommandLineConfigGpu(tag, vias, contextType, useNVPR, useDIText , samples);
270 }
271 #endif
272
273 void ParseConfigs(const SkCommandLineFlags::StringArray& configs,
274 SkCommandLineConfigArray* outResult) {
275 outResult->reset();
276 for (int i = 0; i < configs.count(); ++i) {
277 SkString extendedConfigBackend;
278 SkString extendedConfigOptions;
279 SkString tag(configs[i]);
280 SkTArray<SkString> vias;
281
282 SkTArray<SkString> parts;
283 SkStrSplit(tag.c_str(), "(", kStrict_SkStrSplitMode, &parts);
284 if (parts.count() == 2) {
285 SkTArray<SkString> parts2;
286 SkStrSplit(parts[1].c_str(), ")", kStrict_SkStrSplitMode, &parts2);
287 if (parts2.count() == 2 && parts2[1].isEmpty()) {
288 SkStrSplit(parts[0].c_str(), "-", kStrict_SkStrSplitMode, &vias) ;
289 if (vias.count()) {
290 extendedConfigBackend = vias[vias.count() - 1];
291 vias.pop_back();
292 } else {
293 extendedConfigBackend = parts[0];
294 }
295 extendedConfigOptions = parts2[0];
296 tag.printf("%s(%s)", extendedConfigBackend.c_str(), extendedConf igOptions.c_str());
297 }
298 }
299 if (extendedConfigBackend.isEmpty()) {
300 SkStrSplit(tag.c_str(), "-", kStrict_SkStrSplitMode, &vias);
301 if (vias.count()) {
302 tag = vias[vias.count() - 1];
303 vias.pop_back();
304 }
305 // Note: no #if SK_ANGLE: this is a special rule in the via-tag gram mar.
306 if (vias.count() && tag.equals("gl") && vias[vias.count() - 1].equal s("angle")) {
307 tag = "angle-gl";
308 vias.pop_back();
309 }
310 }
311 if (extendedConfigBackend.isEmpty()) {
312 for (auto& predefinedConfig : gPredefinedConfigs) {
313 if (tag.equals(predefinedConfig.predefinedConfig)) {
314 extendedConfigBackend = predefinedConfig.backend;
315 extendedConfigOptions = predefinedConfig.options;
316 break;
317 }
318 }
319 }
320
321 SkCommandLineConfig* parsedConfig = nullptr;
322 #if SK_SUPPORT_GPU
323 if (extendedConfigBackend.equals("gpu")) {
324 parsedConfig = parse_command_line_config_gpu(tag, vias, extendedConf igOptions);
325 }
326 #endif
327 if (!parsedConfig) {
328 parsedConfig = new SkCommandLineConfig(tag, vias);
329 }
330 outResult->emplace_back(parsedConfig);
331 }
332 }
OLDNEW
« no previous file with comments | « tools/flags/SkCommonFlagsConfig.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698