OLD | NEW |
---|---|
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 Loading... | |
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 SkEffectType SkFlattenable::NameToType(const char name[]) { |
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 return entries[i].fType; |
128 } | |
129 } | |
130 return kInvalid_SkEffectType; | |
sugoi1
2013/10/16 15:05:32
I added the Invalid type to have something to retu
| |
131 } | |
132 | |
133 const char* SkFlattenable::FactoryToName(Factory fact) { | |
134 InitializeFlattenablesIfNeeded(); | |
135 #ifdef SK_DEBUG | |
136 report_no_entries(__FUNCTION__); | |
137 #endif | |
138 const Entry* entries = gEntries; | |
139 for (int i = gCount - 1; i >= 0; --i) { | |
140 if (entries[i].fFactory == fact) { | |
141 return entries[i].fName; | |
124 } | 142 } |
125 } | 143 } |
126 return NULL; | 144 return NULL; |
127 } | 145 } |
OLD | NEW |