Index: src/core/SkFlattenable.cpp |
diff --git a/src/core/SkFlattenable.cpp b/src/core/SkFlattenable.cpp |
index b4efe91004845cb3b00ebfc8b6d3d1131374fce7..6cebb225d3145385114441635b678a6bea8eb5aa 100644 |
--- a/src/core/SkFlattenable.cpp |
+++ b/src/core/SkFlattenable.cpp |
@@ -63,64 +63,84 @@ void SkRefCntSet::decPtr(void* ptr) { |
/////////////////////////////////////////////////////////////////////////////// |
/////////////////////////////////////////////////////////////////////////////// |
-#define MAX_PAIR_COUNT 1024 |
+#define MAX_ENTRY_COUNT 1024 |
-struct Pair { |
+struct Entry { |
const char* fName; |
SkFlattenable::Factory fFactory; |
+ SkFlattenable::Type fType; |
}; |
static int gCount; |
-static Pair gPairs[MAX_PAIR_COUNT]; |
+static Entry gEntries[MAX_ENTRY_COUNT]; |
-void SkFlattenable::Register(const char name[], Factory factory) { |
+void SkFlattenable::Register(const char name[], Factory factory, SkFlattenable::Type type) { |
SkASSERT(name); |
SkASSERT(factory); |
- static bool gOnce; |
+ static bool gOnce = false; |
if (!gOnce) { |
gCount = 0; |
gOnce = true; |
} |
- SkASSERT(gCount < MAX_PAIR_COUNT); |
+ SkASSERT(gCount < MAX_ENTRY_COUNT); |
- gPairs[gCount].fName = name; |
- gPairs[gCount].fFactory = factory; |
+ gEntries[gCount].fName = name; |
+ gEntries[gCount].fFactory = factory; |
+ gEntries[gCount].fType = type; |
gCount += 1; |
} |
#ifdef SK_DEBUG |
static void report_no_entries(const char* functionName) { |
if (!gCount) { |
- SkDebugf("%s has no registered name/factory pairs." |
- " Call SkGraphics::Init() at process initialization time.", |
+ SkDebugf("%s has no registered name/factory/type entries." |
+ " Call SkFlattenable::InitializeFlattenablesIfNeeded() before using gEntries", |
functionName); |
} |
} |
#endif |
SkFlattenable::Factory SkFlattenable::NameToFactory(const char name[]) { |
+ InitializeFlattenablesIfNeeded(); |
#ifdef SK_DEBUG |
report_no_entries(__FUNCTION__); |
#endif |
- const Pair* pairs = gPairs; |
+ const Entry* entries = gEntries; |
for (int i = gCount - 1; i >= 0; --i) { |
- if (strcmp(pairs[i].fName, name) == 0) { |
- return pairs[i].fFactory; |
+ if (strcmp(entries[i].fName, name) == 0) { |
+ return entries[i].fFactory; |
} |
} |
return NULL; |
} |
+bool SkFlattenable::NameToType(const char name[], SkFlattenable::Type* type) { |
+ SkASSERT(NULL != type); |
+ InitializeFlattenablesIfNeeded(); |
+#ifdef SK_DEBUG |
+ report_no_entries(__FUNCTION__); |
+#endif |
+ const Entry* entries = gEntries; |
+ for (int i = gCount - 1; i >= 0; --i) { |
+ if (strcmp(entries[i].fName, name) == 0) { |
+ *type = entries[i].fType; |
+ return true; |
+ } |
+ } |
+ return false; |
+} |
+ |
const char* SkFlattenable::FactoryToName(Factory fact) { |
+ InitializeFlattenablesIfNeeded(); |
#ifdef SK_DEBUG |
report_no_entries(__FUNCTION__); |
#endif |
- const Pair* pairs = gPairs; |
+ const Entry* entries = gEntries; |
for (int i = gCount - 1; i >= 0; --i) { |
- if (pairs[i].fFactory == fact) { |
- return pairs[i].fName; |
+ if (entries[i].fFactory == fact) { |
+ return entries[i].fName; |
} |
} |
return NULL; |