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

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: Comments fixed 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 SkEffectType 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, SkEffectType ty pe) {
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[], SkEffectType& type) {
mtklein 2013/10/16 18:54:09 Would prefer type to be a pointer to make it clear
sugoi1 2013/10/16 20:07:41 Done.
120 InitializeFlattenablesIfNeeded();
117 #ifdef SK_DEBUG 121 #ifdef SK_DEBUG
118 report_no_entries(__FUNCTION__); 122 report_no_entries(__FUNCTION__);
119 #endif 123 #endif
120 const Pair* pairs = gPairs; 124 const Entry* entries = gEntries;
121 for (int i = gCount - 1; i >= 0; --i) { 125 for (int i = gCount - 1; i >= 0; --i) {
122 if (pairs[i].fFactory == fact) { 126 if (strcmp(entries[i].fName, name) == 0) {
123 return pairs[i].fName; 127 type = entries[i].fType;
128 return true;
129 }
130 }
131 return false;
132 }
133
134 const char* SkFlattenable::FactoryToName(Factory fact) {
135 InitializeFlattenablesIfNeeded();
136 #ifdef SK_DEBUG
137 report_no_entries(__FUNCTION__);
138 #endif
139 const Entry* entries = gEntries;
140 for (int i = gCount - 1; i >= 0; --i) {
141 if (entries[i].fFactory == fact) {
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