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

Unified Diff: src/core/SkFlattenable.cpp

Issue 23021015: Initial error handling code (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Serialization with strings as ID Created 7 years, 2 months 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 side-by-side diff with in-line comments
Download patch
Index: src/core/SkFlattenable.cpp
diff --git a/src/core/SkFlattenable.cpp b/src/core/SkFlattenable.cpp
index b4efe91004845cb3b00ebfc8b6d3d1131374fce7..4a096ee060f5021b26e041ad2e2beac7c3e20caa 100644
--- a/src/core/SkFlattenable.cpp
+++ b/src/core/SkFlattenable.cpp
@@ -65,19 +65,25 @@ void SkRefCntSet::decPtr(void* ptr) {
#define MAX_PAIR_COUNT 1024
+struct FlattenableInfo {
+ SkFlattenable::Factory fFactory;
+ SkFlattenable::TypeCheck fTypeCheck;
+};
+
struct Pair {
- const char* fName;
- SkFlattenable::Factory fFactory;
+ const char* fName;
+ FlattenableInfo fInfo;
};
mtklein 2013/10/07 19:29:56 Why not merge this together? struct Entry { con
sugoi1 2013/10/08 20:23:10 Done.
static int gCount;
static Pair gPairs[MAX_PAIR_COUNT];
-void SkFlattenable::Register(const char name[], Factory factory) {
+void SkFlattenable::Register(const char name[], Factory factory, TypeCheck typeCheck) {
SkASSERT(name);
SkASSERT(factory);
+ SkASSERT(typeCheck);
- static bool gOnce;
+ static bool gOnce = false;
if (!gOnce) {
gCount = 0;
gOnce = true;
@@ -86,7 +92,8 @@ void SkFlattenable::Register(const char name[], Factory factory) {
SkASSERT(gCount < MAX_PAIR_COUNT);
gPairs[gCount].fName = name;
- gPairs[gCount].fFactory = factory;
+ gPairs[gCount].fInfo.fFactory = factory;
+ gPairs[gCount].fInfo.fTypeCheck = typeCheck;
gCount += 1;
}
@@ -101,25 +108,41 @@ static void report_no_entries(const char* functionName) {
#endif
SkFlattenable::Factory SkFlattenable::NameToFactory(const char name[]) {
+ InitializeFlattenables();
sugoi1 2013/10/07 15:54:08 Initialization is now "on demand", so any usage of
+#ifdef SK_DEBUG
+ report_no_entries(__FUNCTION__);
+#endif
+ const Pair* pairs = gPairs;
+ for (int i = gCount - 1; i >= 0; --i) {
+ if (strcmp(pairs[i].fName, name) == 0) {
+ return pairs[i].fInfo.fFactory;
+ }
+ }
+ return NULL;
+}
+
+SkFlattenable::TypeCheck SkFlattenable::NameToTypeCheck(const char name[]) {
+ InitializeFlattenables();
mtklein 2013/10/07 19:29:56 Shall we take the opportunity to rename it Initial
sugoi1 2013/10/08 20:23:10 Done.
#ifdef SK_DEBUG
report_no_entries(__FUNCTION__);
#endif
const Pair* pairs = gPairs;
for (int i = gCount - 1; i >= 0; --i) {
if (strcmp(pairs[i].fName, name) == 0) {
- return pairs[i].fFactory;
+ return pairs[i].fInfo.fTypeCheck;
}
}
return NULL;
}
const char* SkFlattenable::FactoryToName(Factory fact) {
+ InitializeFlattenables();
#ifdef SK_DEBUG
report_no_entries(__FUNCTION__);
#endif
const Pair* pairs = gPairs;
for (int i = gCount - 1; i >= 0; --i) {
- if (pairs[i].fFactory == fact) {
+ if (pairs[i].fInfo.fFactory == fact) {
return pairs[i].fName;
}
}

Powered by Google App Engine
This is Rietveld 408576698