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

Side by Side Diff: tools/flags/SkCommandLineFlags.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
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 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 "SkCommandLineFlags.h" 8 #include "SkCommandLineFlags.h"
9 #include "SkTDArray.h" 9 #include "SkTDArray.h"
10 #include "SkTSort.h" 10 #include "SkTSort.h"
11 11
12 #include <stdlib.h> 12 #include <stdlib.h>
13 13
14 #if defined(GOOGLE3) && (defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_I OS)) 14 #if defined(GOOGLE3) && (defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_I OS))
15 // I don't know why, but this is defined by //base only for non-Linux. 15 // I don't know why, but this is defined by //base only for non-Linux.
16 DECLARE_bool(undefok) 16 DECLARE_bool(undefok)
17 #else 17 #else
18 DEFINE_bool(undefok, false, "Silently ignore unknown flags instead of crashi ng."); 18 DEFINE_bool(undefok, false, "Silently ignore unknown flags instead of crashi ng.");
19 #endif 19 #endif
20 20
21 template <typename T> static void ignore_result(const T&) {} 21 template <typename T> static void ignore_result(const T&) {}
22 22
23 bool SkFlagInfo::CreateStringFlag(const char* name, const char* shortName, 23 bool SkFlagInfo::CreateStringFlag(const char* name, const char* shortName,
24 SkCommandLineFlags::StringArray* pStrings, 24 SkCommandLineFlags::StringArray* pStrings,
25 const char* defaultValue, const char* helpStri ng) { 25 const char* defaultValue, const char* helpStri ng,
26 SkFlagInfo* info = new SkFlagInfo(name, shortName, kString_FlagType, helpStr ing); 26 const char* extendedHelpString) {
27 SkFlagInfo* info = new SkFlagInfo(name, shortName, kString_FlagType, helpStr ing, extendedHelpString);
scroggo 2015/12/03 19:02:58 100 chars.
Kimmo Kinnunen 2015/12/04 14:26:18 Done.
27 info->fDefaultString.set(defaultValue); 28 info->fDefaultString.set(defaultValue);
28 29
29 info->fStrings = pStrings; 30 info->fStrings = pStrings;
30 SetDefaultStrings(pStrings, defaultValue); 31 SetDefaultStrings(pStrings, defaultValue);
31 return true; 32 return true;
32 } 33 }
33 34
34 void SkFlagInfo::SetDefaultStrings(SkCommandLineFlags::StringArray* pStrings, 35 void SkFlagInfo::SetDefaultStrings(SkCommandLineFlags::StringArray* pStrings,
35 const char* defaultValue) { 36 const char* defaultValue) {
36 pStrings->reset(); 37 pStrings->reset();
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 SkFlagInfo* SkCommandLineFlags::gHead; 145 SkFlagInfo* SkCommandLineFlags::gHead;
145 SkString SkCommandLineFlags::gUsage; 146 SkString SkCommandLineFlags::gUsage;
146 147
147 void SkCommandLineFlags::SetUsage(const char* usage) { 148 void SkCommandLineFlags::SetUsage(const char* usage) {
148 gUsage.set(usage); 149 gUsage.set(usage);
149 } 150 }
150 151
151 // Maximum line length for the help message. 152 // Maximum line length for the help message.
152 #define LINE_LENGTH 72 153 #define LINE_LENGTH 72
153 154
154 static void print_help_for_flag(const SkFlagInfo* flag) { 155 static void print_indented(const SkString& text) {
155 SkDebugf(" --%s", flag->name().c_str()); 156 size_t length = text.size();
156 const SkString& shortName = flag->shortName(); 157 const char* currLine = text.c_str();
157 if (shortName.size() > 0) {
158 SkDebugf(" or -%s", shortName.c_str());
159 }
160 SkDebugf(":\ttype: %s", flag->typeAsString().c_str());
161 if (flag->defaultValue().size() > 0) {
162 SkDebugf("\tdefault: %s", flag->defaultValue().c_str());
163 }
164 SkDebugf("\n");
165 const SkString& help = flag->help();
166 size_t length = help.size();
167 const char* currLine = help.c_str();
168 const char* stop = currLine + length; 158 const char* stop = currLine + length;
169 while (currLine < stop) { 159 while (currLine < stop) {
170 if (strlen(currLine) < LINE_LENGTH) { 160 int lineBreak = SkStrFind(currLine, "\n");
161 if (lineBreak < 0) {
171 // Only one line length's worth of text left. 162 // Only one line length's worth of text left.
scroggo 2015/12/03 19:02:58 This comment no longer applies.
Kimmo Kinnunen 2015/12/04 14:26:18 Done.
172 SkDebugf(" %s\n", currLine); 163 lineBreak = strlen(currLine);
173 break;
174 } 164 }
175 int lineBreak = SkStrFind(currLine, "\n"); 165 if (lineBreak > LINE_LENGTH) {
176 if (lineBreak < 0 || lineBreak > LINE_LENGTH) {
177 // No line break within line length. Will need to insert one. 166 // No line break within line length. Will need to insert one.
178 // Find a space before the line break. 167 // Find a space before the line break.
179 int spaceIndex = LINE_LENGTH - 1; 168 int spaceIndex = LINE_LENGTH - 1;
180 while (spaceIndex > 0 && currLine[spaceIndex] != ' ') { 169 while (spaceIndex > 0 && currLine[spaceIndex] != ' ') {
181 spaceIndex--; 170 spaceIndex--;
182 } 171 }
183 int gap; 172 int gap;
184 if (0 == spaceIndex) { 173 if (0 == spaceIndex) {
185 // No spaces on the entire line. Go ahead and break mid word. 174 // No spaces on the entire line. Go ahead and break mid word.
186 spaceIndex = LINE_LENGTH; 175 spaceIndex = LINE_LENGTH;
187 gap = 0; 176 gap = 0;
188 } else { 177 } else {
189 // Skip the space on the next line 178 // Skip the space on the next line
190 gap = 1; 179 gap = 1;
191 } 180 }
192 SkDebugf(" %.*s\n", spaceIndex, currLine); 181 SkDebugf(" %.*s\n", spaceIndex, currLine);
193 currLine += spaceIndex + gap; 182 currLine += spaceIndex + gap;
194 } else { 183 } else {
195 // the line break is within the limit. Break there. 184 // the line break is within the limit. Break there.
196 lineBreak++; 185 lineBreak++;
197 SkDebugf(" %.*s", lineBreak, currLine); 186 SkDebugf(" %.*s", lineBreak, currLine);
198 currLine += lineBreak; 187 currLine += lineBreak;
199 } 188 }
200 } 189 }
190 }
191
192 static void print_help_for_flag(const SkFlagInfo* flag) {
193 SkDebugf(" --%s", flag->name().c_str());
194 const SkString& shortName = flag->shortName();
195 if (shortName.size() > 0) {
196 SkDebugf(" or -%s", shortName.c_str());
197 }
198 SkDebugf(":\ttype: %s", flag->typeAsString().c_str());
199 if (flag->defaultValue().size() > 0) {
200 SkDebugf("\tdefault: %s", flag->defaultValue().c_str());
201 }
202 SkDebugf("\n");
203 const SkString& help = flag->help();
204 print_indented(help);
205 SkDebugf("\n");
206 }
207 static void print_extended_help_for_flag(const SkFlagInfo* flag) {
208 print_help_for_flag(flag);
209 print_indented(flag->extendedHelp());
201 SkDebugf("\n"); 210 SkDebugf("\n");
202 } 211 }
203 212
204 namespace { 213 namespace {
205 struct CompareFlagsByName { 214 struct CompareFlagsByName {
206 bool operator()(SkFlagInfo* a, SkFlagInfo* b) const { 215 bool operator()(SkFlagInfo* a, SkFlagInfo* b) const {
207 return strcmp(a->name().c_str(), b->name().c_str()) < 0; 216 return strcmp(a->name().c_str(), b->name().c_str()) < 0;
208 } 217 }
209 }; 218 };
210 } // namespace 219 } // namespace
(...skipping 30 matching lines...) Expand all
241 // If no flags followed --help, print them all 250 // If no flags followed --help, print them all
242 SkTDArray<SkFlagInfo*> allFlags; 251 SkTDArray<SkFlagInfo*> allFlags;
243 for (SkFlagInfo* flag = SkCommandLineFlags::gHead; flag; 252 for (SkFlagInfo* flag = SkCommandLineFlags::gHead; flag;
244 flag = flag->next()) { 253 flag = flag->next()) {
245 allFlags.push(flag); 254 allFlags.push(flag);
246 } 255 }
247 SkTQSort(&allFlags[0], &allFlags[allFlags.count() - 1], 256 SkTQSort(&allFlags[0], &allFlags[allFlags.count() - 1],
248 CompareFlagsByName()); 257 CompareFlagsByName());
249 for (int i = 0; i < allFlags.count(); ++i) { 258 for (int i = 0; i < allFlags.count(); ++i) {
250 print_help_for_flag(allFlags[i]); 259 print_help_for_flag(allFlags[i]);
260 if (allFlags[i]->extendedHelp().size() > 0) {
261 SkDebugf(" Use '--help %s' for more information.\ n", allFlags[i]->name().c_str());
scroggo 2015/12/03 19:02:58 100 chars
Kimmo Kinnunen 2015/12/04 14:26:18 Done.
262 }
251 } 263 }
252 } else { 264 } else {
253 for (SkFlagInfo* flag = SkCommandLineFlags::gHead; flag; 265 for (SkFlagInfo* flag = SkCommandLineFlags::gHead; flag;
254 flag = flag->next()) { 266 flag = flag->next()) {
255 for (int k = 0; k < helpFlags.count(); k++) { 267 for (int k = 0; k < helpFlags.count(); k++) {
256 if (flag->name().equals(helpFlags[k]) || 268 if (flag->name().equals(helpFlags[k]) ||
257 flag->shortName().equals(helpFlags[k])) { 269 flag->shortName().equals(helpFlags[k])) {
258 print_help_for_flag(flag); 270 print_extended_help_for_flag(flag);
259 helpFlags.remove(k); 271 helpFlags.remove(k);
260 break; 272 break;
261 } 273 }
262 } 274 }
263 } 275 }
264 } 276 }
265 if (helpFlags.count() > 0) { 277 if (helpFlags.count() > 0) {
266 SkDebugf("Requested help for unrecognized flags:\n"); 278 SkDebugf("Requested help for unrecognized flags:\n");
267 for (int k = 0; k < helpFlags.count(); k++) { 279 for (int k = 0; k < helpFlags.count(); k++) {
268 SkDebugf(" --%s\n", helpFlags[k]); 280 SkDebugf(" --%s\n", helpFlags[k]);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 } 394 }
383 395
384 } // namespace 396 } // namespace
385 397
386 bool SkCommandLineFlags::ShouldSkip(const SkTDArray<const char*>& strings, const char* name) { 398 bool SkCommandLineFlags::ShouldSkip(const SkTDArray<const char*>& strings, const char* name) {
387 return ShouldSkipImpl(strings, name); 399 return ShouldSkipImpl(strings, name);
388 } 400 }
389 bool SkCommandLineFlags::ShouldSkip(const StringArray& strings, const char* name ) { 401 bool SkCommandLineFlags::ShouldSkip(const StringArray& strings, const char* name ) {
390 return ShouldSkipImpl(strings, name); 402 return ShouldSkipImpl(strings, name);
391 } 403 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698