Reland r8235 "Switch gm to use SkFlags."
This time, using #if guards for gpuCacheSize consistently.
Also fix some warnings.
BUG=https://code.google.com/p/skia/issues/detail?id=1094
Review URL: https://codereview.chromium.org/12440052
git-svn-id: http://skia.googlecode.com/svn/trunk@8254 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tools/SkFlags.h b/tools/SkFlags.h
index d40cdd0..79cc878 100644
--- a/tools/SkFlags.h
+++ b/tools/SkFlags.h
@@ -119,6 +119,17 @@
#define DEFINE_bool(name, defaultValue, helpString) \
bool FLAGS_##name; \
static bool unused_##name = SkFlagInfo::CreateBoolFlag(TO_STRING(name), \
+ NULL, \
+ &FLAGS_##name, \
+ defaultValue, \
+ helpString)
+
+// bool 2 allows specifying a short name. No check is done to ensure that shortName
+// is actually shorter than name.
+#define DEFINE_bool2(name, shortName, defaultValue, helpString) \
+bool FLAGS_##name; \
+static bool unused_##name = SkFlagInfo::CreateBoolFlag(TO_STRING(name), \
+ TO_STRING(shortName),\
&FLAGS_##name, \
defaultValue, \
helpString)
@@ -128,10 +139,21 @@
#define DEFINE_string(name, defaultValue, helpString) \
SkTDArray<const char*> FLAGS_##name; \
static bool unused_##name = SkFlagInfo::CreateStringFlag(TO_STRING(name), \
+ NULL, \
&FLAGS_##name, \
defaultValue, \
helpString)
+// string2 allows specifying a short name. No check is done to ensure that shortName
+// is actually shorter than name.
+#define DEFINE_string2(name, shortName, defaultValue, helpString) \
+SkTDArray<const char*> FLAGS_##name; \
+static bool unused_##name = SkFlagInfo::CreateStringFlag(TO_STRING(name), \
+ TO_STRING(shortName), \
+ &FLAGS_##name, \
+ defaultValue, \
+ helpString)
+
#define DECLARE_string(name) extern SkTDArray<const char*> FLAGS_##name;
#define DEFINE_int32(name, defaultValue, helpString) \
@@ -163,17 +185,20 @@
};
// Create flags of the desired type, and append to the list.
- static bool CreateBoolFlag(const char* name, bool* pBool,
+ static bool CreateBoolFlag(const char* name, const char* shortName, bool* pBool,
bool defaultValue, const char* helpString) {
SkFlagInfo* info = SkNEW_ARGS(SkFlagInfo, (name, kBool_FlagType, helpString));
+ info->fShortName.set(shortName);
info->fBoolValue = pBool;
*info->fBoolValue = info->fDefaultBool = defaultValue;
return true;
}
- static bool CreateStringFlag(const char* name, SkTDArray<const char*>* pStrings,
+ static bool CreateStringFlag(const char* name, const char* shortName,
+ SkTDArray<const char*>* pStrings,
const char* defaultValue, const char* helpString) {
SkFlagInfo* info = SkNEW_ARGS(SkFlagInfo, (name, kString_FlagType, helpString));
+ info->fShortName.set(shortName);
info->fDefaultString.set(defaultValue);
info->fStrings = pStrings;
@@ -206,27 +231,28 @@
* value, since a bool is specified as true or false by --name or --noname.
*/
bool match(const char* string) {
- if (SkStrStartsWith(string, '-')) {
+ if (SkStrStartsWith(string, '-') && strlen(string) > 1) {
string++;
// Allow one or two dashes
- if (SkStrStartsWith(string, '-')) {
+ if (SkStrStartsWith(string, '-') && strlen(string) > 1) {
string++;
}
if (kBool_FlagType == fFlagType) {
// In this case, go ahead and set the value.
- if (fName.equals(string)) {
+ if (fName.equals(string) || fShortName.equals(string)) {
*fBoolValue = true;
return true;
}
- SkString noname(fName);
- noname.prepend("no");
- if (noname.equals(string)) {
- *fBoolValue = false;
- return true;
+ if (SkStrStartsWith(string, "no") && strlen(string) > 2) {
+ string += 2;
+ if (fName.equals(string) || fShortName.equals(string)) {
+ *fBoolValue = false;
+ return true;
+ }
+ return false;
}
- return false;
}
- return fName.equals(string);
+ return fName.equals(string) || fShortName.equals(string);
} else {
// Has no dash
return false;
@@ -327,6 +353,7 @@
}
// Name of the flag, without initial dashes
SkString fName;
+ SkString fShortName;
FlagTypes fFlagType;
SkString fHelpString;
bool* fBoolValue;