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

Side by Side Diff: src/core/SkFlattenable.cpp

Issue 23021015: Initial error handling code (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Fixing comments 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "SkFlattenable.h" 8 #include "SkFlattenable.h"
9 #include "SkPtrRecorder.h" 9 #include "SkPtrRecorder.h"
10 10
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 } 56 }
57 57
58 void SkRefCntSet::decPtr(void* ptr) { 58 void SkRefCntSet::decPtr(void* ptr) {
59 ((SkRefCnt*)ptr)->unref(); 59 ((SkRefCnt*)ptr)->unref();
60 } 60 }
61 61
62 /////////////////////////////////////////////////////////////////////////////// 62 ///////////////////////////////////////////////////////////////////////////////
63 /////////////////////////////////////////////////////////////////////////////// 63 ///////////////////////////////////////////////////////////////////////////////
64 /////////////////////////////////////////////////////////////////////////////// 64 ///////////////////////////////////////////////////////////////////////////////
65 65
66 #define MAX_PAIR_COUNT 1024 66 #define MAX_ENTRY_COUNT 1024
67 67
68 struct Pair { 68 struct Entry {
69 const char* fName; 69 const char* fName;
70 SkFlattenable::Factory fFactory; 70 SkFlattenable::Factory fFactory;
71 SkFlattenable::TypeCheck fTypeCheck;
71 }; 72 };
72 73
73 static int gCount; 74 static int gCount;
74 static Pair gPairs[MAX_PAIR_COUNT]; 75 static Entry gEntries[MAX_ENTRY_COUNT];
75 76
76 void SkFlattenable::Register(const char name[], Factory factory) { 77 void SkFlattenable::Register(const char name[], Factory factory, TypeCheck typeC heck) {
77 SkASSERT(name); 78 SkASSERT(name);
78 SkASSERT(factory); 79 SkASSERT(factory);
80 SkASSERT(typeCheck);
79 81
80 static bool gOnce; 82 static bool gOnce = false;
81 if (!gOnce) { 83 if (!gOnce) {
82 gCount = 0; 84 gCount = 0;
83 gOnce = true; 85 gOnce = true;
84 } 86 }
85 87
86 SkASSERT(gCount < MAX_PAIR_COUNT); 88 SkASSERT(gCount < MAX_ENTRY_COUNT);
87 89
88 gPairs[gCount].fName = name; 90 gEntries[gCount].fName = name;
89 gPairs[gCount].fFactory = factory; 91 gEntries[gCount].fFactory = factory;
92 gEntries[gCount].fTypeCheck = typeCheck;
90 gCount += 1; 93 gCount += 1;
91 } 94 }
92 95
93 #ifdef SK_DEBUG 96 #ifdef SK_DEBUG
94 static void report_no_entries(const char* functionName) { 97 static void report_no_entries(const char* functionName) {
95 if (!gCount) { 98 if (!gCount) {
96 SkDebugf("%s has no registered name/factory pairs." 99 SkDebugf("%s has no registered name/factory/type entries."
97 " Call SkGraphics::Init() at process initialization time.", 100 " Call SkFlattenable::InitializeFlattenablesIfNeeded() before u sing gEntries",
98 functionName); 101 functionName);
99 } 102 }
100 } 103 }
101 #endif 104 #endif
102 105
103 SkFlattenable::Factory SkFlattenable::NameToFactory(const char name[]) { 106 SkFlattenable::Factory SkFlattenable::NameToFactory(const char name[]) {
107 InitializeFlattenablesIfNeeded();
104 #ifdef SK_DEBUG 108 #ifdef SK_DEBUG
105 report_no_entries(__FUNCTION__); 109 report_no_entries(__FUNCTION__);
106 #endif 110 #endif
107 const Pair* pairs = gPairs; 111 const Entry* entries = gEntries;
108 for (int i = gCount - 1; i >= 0; --i) { 112 for (int i = gCount - 1; i >= 0; --i) {
109 if (strcmp(pairs[i].fName, name) == 0) { 113 if (strcmp(entries[i].fName, name) == 0) {
110 return pairs[i].fFactory; 114 return entries[i].fFactory;
115 }
116 }
117 return NULL;
118 }
119
120 SkFlattenable::TypeCheck SkFlattenable::NameToTypeCheck(const char name[]) {
121 InitializeFlattenablesIfNeeded();
122 #ifdef SK_DEBUG
123 report_no_entries(__FUNCTION__);
124 #endif
125 const Entry* entries = gEntries;
126 for (int i = gCount - 1; i >= 0; --i) {
127 if (strcmp(entries[i].fName, name) == 0) {
128 return entries[i].fTypeCheck;
111 } 129 }
112 } 130 }
113 return NULL; 131 return NULL;
114 } 132 }
115 133
116 const char* SkFlattenable::FactoryToName(Factory fact) { 134 const char* SkFlattenable::FactoryToName(Factory fact) {
135 InitializeFlattenablesIfNeeded();
117 #ifdef SK_DEBUG 136 #ifdef SK_DEBUG
118 report_no_entries(__FUNCTION__); 137 report_no_entries(__FUNCTION__);
119 #endif 138 #endif
120 const Pair* pairs = gPairs; 139 const Entry* entries = gEntries;
121 for (int i = gCount - 1; i >= 0; --i) { 140 for (int i = gCount - 1; i >= 0; --i) {
122 if (pairs[i].fFactory == fact) { 141 if (entries[i].fFactory == fact) {
123 return pairs[i].fName; 142 return entries[i].fName;
124 } 143 }
125 } 144 }
126 return NULL; 145 return NULL;
127 } 146 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698