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

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: Adapting code to sk_once changes Created 7 years, 1 month 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
« no previous file with comments | « src/core/SkBitmap.cpp ('k') | src/core/SkFlattenableBuffers.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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::Type fType;
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, SkFlattenable:: Type type) {
77 SkASSERT(name); 78 SkASSERT(name);
78 SkASSERT(factory); 79 SkASSERT(factory);
79 80
80 static bool gOnce; 81 static bool gOnce = false;
81 if (!gOnce) { 82 if (!gOnce) {
82 gCount = 0; 83 gCount = 0;
83 gOnce = true; 84 gOnce = true;
84 } 85 }
85 86
86 SkASSERT(gCount < MAX_PAIR_COUNT); 87 SkASSERT(gCount < MAX_ENTRY_COUNT);
87 88
88 gPairs[gCount].fName = name; 89 gEntries[gCount].fName = name;
89 gPairs[gCount].fFactory = factory; 90 gEntries[gCount].fFactory = factory;
91 gEntries[gCount].fType = type;
90 gCount += 1; 92 gCount += 1;
91 } 93 }
92 94
93 #ifdef SK_DEBUG 95 #ifdef SK_DEBUG
94 static void report_no_entries(const char* functionName) { 96 static void report_no_entries(const char* functionName) {
95 if (!gCount) { 97 if (!gCount) {
96 SkDebugf("%s has no registered name/factory pairs." 98 SkDebugf("%s has no registered name/factory/type entries."
97 " Call SkGraphics::Init() at process initialization time.", 99 " Call SkFlattenable::InitializeFlattenablesIfNeeded() before u sing gEntries",
98 functionName); 100 functionName);
99 } 101 }
100 } 102 }
101 #endif 103 #endif
102 104
103 SkFlattenable::Factory SkFlattenable::NameToFactory(const char name[]) { 105 SkFlattenable::Factory SkFlattenable::NameToFactory(const char name[]) {
106 InitializeFlattenablesIfNeeded();
104 #ifdef SK_DEBUG 107 #ifdef SK_DEBUG
105 report_no_entries(__FUNCTION__); 108 report_no_entries(__FUNCTION__);
106 #endif 109 #endif
107 const Pair* pairs = gPairs; 110 const Entry* entries = gEntries;
108 for (int i = gCount - 1; i >= 0; --i) { 111 for (int i = gCount - 1; i >= 0; --i) {
109 if (strcmp(pairs[i].fName, name) == 0) { 112 if (strcmp(entries[i].fName, name) == 0) {
110 return pairs[i].fFactory; 113 return entries[i].fFactory;
111 } 114 }
112 } 115 }
113 return NULL; 116 return NULL;
114 } 117 }
115 118
116 const char* SkFlattenable::FactoryToName(Factory fact) { 119 bool SkFlattenable::NameToType(const char name[], SkFlattenable::Type* type) {
120 SkASSERT(NULL != type);
121 InitializeFlattenablesIfNeeded();
117 #ifdef SK_DEBUG 122 #ifdef SK_DEBUG
118 report_no_entries(__FUNCTION__); 123 report_no_entries(__FUNCTION__);
119 #endif 124 #endif
120 const Pair* pairs = gPairs; 125 const Entry* entries = gEntries;
121 for (int i = gCount - 1; i >= 0; --i) { 126 for (int i = gCount - 1; i >= 0; --i) {
122 if (pairs[i].fFactory == fact) { 127 if (strcmp(entries[i].fName, name) == 0) {
123 return pairs[i].fName; 128 *type = entries[i].fType;
129 return true;
130 }
131 }
132 return false;
133 }
134
135 const char* SkFlattenable::FactoryToName(Factory fact) {
136 InitializeFlattenablesIfNeeded();
137 #ifdef SK_DEBUG
138 report_no_entries(__FUNCTION__);
139 #endif
140 const Entry* entries = gEntries;
141 for (int i = gCount - 1; i >= 0; --i) {
142 if (entries[i].fFactory == fact) {
143 return entries[i].fName;
124 } 144 }
125 } 145 }
126 return NULL; 146 return NULL;
127 } 147 }
OLDNEW
« no previous file with comments | « src/core/SkBitmap.cpp ('k') | src/core/SkFlattenableBuffers.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698