OLD | NEW |
| (Empty) |
1 /* libs/graphics/animator/SkMemberInfo.h | |
2 ** | |
3 ** Copyright 2006, The Android Open Source Project | |
4 ** | |
5 ** Licensed under the Apache License, Version 2.0 (the "License"); | |
6 ** you may not use this file except in compliance with the License. | |
7 ** You may obtain a copy of the License at | |
8 ** | |
9 ** http://www.apache.org/licenses/LICENSE-2.0 | |
10 ** | |
11 ** Unless required by applicable law or agreed to in writing, software | |
12 ** distributed under the License is distributed on an "AS IS" BASIS, | |
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 ** See the License for the specific language governing permissions and | |
15 ** limitations under the License. | |
16 */ | |
17 | |
18 #ifndef SkMemberInfo_DEFINED | |
19 #define SkMemberInfo_DEFINED | |
20 | |
21 #if defined SK_BUILD_CONDENSED | |
22 #define SK_USE_CONDENSED_INFO 0 | |
23 #elif defined SK_BUILD_FOR_BREW | |
24 #define SK_USE_CONDENSED_INFO 1 /* required by BREW to handle its lack of wr
itable globals */ | |
25 #else | |
26 #define SK_USE_CONDENSED_INFO 0 /* optional, but usually 1 unless Cary is te
sting something */ | |
27 #endif | |
28 | |
29 #include "SkDisplayType.h" | |
30 #include "SkScript.h" | |
31 #include "SkString.h" | |
32 #include "SkIntArray.h" | |
33 | |
34 class SkAnimateMaker; | |
35 class SkDisplayable; | |
36 class SkScriptEngine; | |
37 | |
38 // temporary hacks until name change is more complete | |
39 #define SkFloat SkScalar | |
40 #define SkInt SkS32 | |
41 | |
42 struct SkMemberInfo { | |
43 //!!! alternative: | |
44 // if fCount == 0, record is member property | |
45 // then fType can be type, so caller doesn't have to check | |
46 #if SK_USE_CONDENSED_INFO == 0 | |
47 const char* fName; // may be NULL for anonymous functions | |
48 size_t fOffset; // if negative, is index into member pointer table (for prop
erties and functions) | |
49 SkDisplayTypes fType; | |
50 int fCount; // for properties, actual type (count is always assumed
to be 1) | |
51 #else | |
52 unsigned char fName; | |
53 signed char fOffset; | |
54 unsigned char fType; | |
55 signed char fCount; | |
56 #endif | |
57 SkDisplayTypes arrayType() const { | |
58 SkASSERT(fType == SkType_Array); | |
59 return (SkDisplayTypes) fCount; // hack, but worth it? | |
60 } | |
61 int functionIndex() const { | |
62 SkASSERT(fType == SkType_MemberFunction); | |
63 return (signed) fOffset > 0 ? -1 + (int) fOffset : -1 - (int) fOffset; | |
64 } | |
65 bool getArrayValue(const SkDisplayable* displayable, int index, SkOperand* v
alue) const; | |
66 int getCount() const { | |
67 return fType == SkType_MemberProperty || fType == SkType_Array || | |
68 fType == SkType_MemberFunction ? 1 : fCount; | |
69 } | |
70 const SkMemberInfo* getInherited() const; | |
71 size_t getSize(const SkDisplayable* ) const; | |
72 void getString(const SkDisplayable* , SkString** string) const; | |
73 SkDisplayTypes getType() const { | |
74 return fType == SkType_MemberProperty || fType == SkType_Array || | |
75 fType == SkType_MemberFunction ? (SkDisplayTypes) fCount : (SkDispla
yTypes) fType; | |
76 } | |
77 void getValue(const SkDisplayable* , SkOperand values[], int count) const; | |
78 bool isEnum() const; | |
79 const char* mapEnums(const char* match, int* value) const; | |
80 void* memberData(const SkDisplayable* displayable) const { | |
81 SkASSERT(fType != SkType_MemberProperty && fType != SkType_MemberFuncti
on); | |
82 return (void*) ((const char*) displayable + fOffset); | |
83 } | |
84 int propertyIndex() const { | |
85 SkASSERT(fType == SkType_MemberProperty); | |
86 return (signed) fOffset > 0 ? -1 + (int) fOffset : -1 - (int) fOffset; | |
87 } | |
88 SkDisplayTypes propertyType() const { | |
89 SkASSERT(fType == SkType_MemberProperty || fType == SkType_Array); | |
90 return (SkDisplayTypes) fCount; // hack, but worth it? | |
91 } | |
92 void setMemberData(SkDisplayable* displayable, const void* child, size_t siz
e) const { | |
93 SkASSERT(fType != SkType_MemberProperty && fType != SkType_MemberFuncti
on); | |
94 memcpy((char*) displayable + fOffset, child, size); | |
95 } | |
96 void setString(SkDisplayable* , SkString* ) const; | |
97 void setValue(SkDisplayable* , const SkOperand values[], int count) const; | |
98 bool setValue(SkAnimateMaker& , SkTDOperandArray* storage, | |
99 int storageOffset, int maxStorage, SkDisplayable* , | |
100 SkDisplayTypes outType, const char value[], size_t len) const; | |
101 bool setValue(SkAnimateMaker& , SkTDOperandArray* storage, | |
102 int storageOffset, int maxStorage, SkDisplayable* , | |
103 SkDisplayTypes outType, SkString& str) const; | |
104 // void setValue(SkDisplayable* , const char value[], const char name[]) const; | |
105 bool writeValue(SkDisplayable* displayable, SkTDOperandArray* arrayStorage, | |
106 int storageOffset, int maxStorage, void* untypedStorage, SkDisplayTypes
outType, | |
107 SkScriptValue& scriptValue) const; | |
108 #if SK_USE_CONDENSED_INFO == 0 | |
109 static const SkMemberInfo* Find(const SkMemberInfo [], int count, int* index
); | |
110 static const SkMemberInfo* Find(const SkMemberInfo [], int count, const char
** name); | |
111 #else | |
112 static const SkMemberInfo* Find(SkDisplayTypes type, int* index); | |
113 static const SkMemberInfo* Find(SkDisplayTypes type, const char** name); | |
114 #endif | |
115 static size_t GetSize(SkDisplayTypes type); // size of simple types only | |
116 // static bool SetValue(void* value, const char* name, SkDisplayTypes , int cou
nt); | |
117 }; | |
118 | |
119 #define SK_MEMBER(_member, _type) \ | |
120 { #_member, SK_OFFSETOF(BASE_CLASS, _member), SkType_##_type, \ | |
121 sizeof(((BASE_CLASS*) 1)->_member) / sizeof(SkScalar) } | |
122 | |
123 #define SK_MEMBER_ALIAS(_member, _alias, _type) \ | |
124 { #_member, SK_OFFSETOF(BASE_CLASS, _alias), SkType_##_type, \ | |
125 sizeof(((BASE_CLASS*) 1)->_alias) / sizeof(SkScalar) } | |
126 | |
127 #define SK_MEMBER_ARRAY(_member, _type) \ | |
128 { #_member, SK_OFFSETOF(BASE_CLASS, _member), SkType_Array, \ | |
129 (int) SkType_##_type } | |
130 | |
131 #define SK_MEMBER_INHERITED \ | |
132 { (const char*) INHERITED::fInfo, 0, SkType_BaseClassInfo, INHERITED::fInfoC
ount } | |
133 | |
134 // #define SK_MEMBER_KEY_TYPE(_member, _type) | |
135 // {#_member, (size_t) -1, SkType_##_type, 0} | |
136 | |
137 #define SK_FUNCTION(_member) \ | |
138 k_##_member##Function | |
139 | |
140 #define SK_PROPERTY(_member) \ | |
141 k_##_member##Property | |
142 | |
143 #define SK_MEMBER_DYNAMIC_FUNCTION(_member, _type) \ | |
144 {#_member, (size_t) (+1 + SK_FUNCTION(_member)), SkType_MemberFunction, \ | |
145 (int) SkType_##_type } | |
146 | |
147 #define SK_MEMBER_DYNAMIC_PROPERTY(_member, _type) \ | |
148 {#_member, (size_t) (1 + SK_PROPERTY(_member)), SkType_MemberProperty, \ | |
149 (int) SkType_##_type } | |
150 | |
151 #define SK_MEMBER_FUNCTION(_member, _type) \ | |
152 {#_member, (size_t) (-1 - SK_FUNCTION(_member)), SkType_MemberFunction, \ | |
153 (int) SkType_##_type } | |
154 | |
155 #define SK_MEMBER_PROPERTY(_member, _type) \ | |
156 {#_member, (size_t) (-1 - SK_PROPERTY(_member)), SkType_MemberProperty, \ | |
157 (int) SkType_##_type } | |
158 | |
159 #if SK_USE_CONDENSED_INFO == 0 | |
160 | |
161 #define DECLARE_PRIVATE_MEMBER_INFO(_type) \ | |
162 public: \ | |
163 static const SkMemberInfo fInfo[]; \ | |
164 static const int fInfoCount; \ | |
165 virtual const SkMemberInfo* getMember(int index); \ | |
166 virtual const SkMemberInfo* getMember(const char name[]); \ | |
167 typedef Sk##_type BASE_CLASS | |
168 | |
169 #define DECLARE_MEMBER_INFO(_type) \ | |
170 public: \ | |
171 static const SkMemberInfo fInfo[]; \ | |
172 static const int fInfoCount; \ | |
173 virtual const SkMemberInfo* getMember(int index); \ | |
174 virtual const SkMemberInfo* getMember(const char name[]); \ | |
175 virtual SkDisplayTypes getType() const { return SkType_##_type; } \ | |
176 typedef Sk##_type BASE_CLASS | |
177 | |
178 #define DECLARE_DRAW_MEMBER_INFO(_type) \ | |
179 public: \ | |
180 static const SkMemberInfo fInfo[]; \ | |
181 static const int fInfoCount; \ | |
182 virtual const SkMemberInfo* getMember(int index); \ | |
183 virtual const SkMemberInfo* getMember(const char name[]); \ | |
184 virtual SkDisplayTypes getType() const { return SkType_##_type; } \ | |
185 typedef SkDraw##_type BASE_CLASS | |
186 | |
187 #define DECLARE_DISPLAY_MEMBER_INFO(_type) \ | |
188 public: \ | |
189 static const SkMemberInfo fInfo[]; \ | |
190 static const int fInfoCount; \ | |
191 virtual const SkMemberInfo* getMember(int index); \ | |
192 virtual const SkMemberInfo* getMember(const char name[]); \ | |
193 virtual SkDisplayTypes getType() const { return SkType_##_type; } \ | |
194 typedef SkDisplay##_type BASE_CLASS | |
195 | |
196 #define DECLARE_EMPTY_MEMBER_INFO(_type) \ | |
197 public: \ | |
198 virtual SkDisplayTypes getType() const { return SkType_##_type; } | |
199 | |
200 #define DECLARE_EXTRAS_MEMBER_INFO(_type) \ | |
201 public: \ | |
202 static const SkMemberInfo fInfo[]; \ | |
203 static const int fInfoCount; \ | |
204 virtual const SkMemberInfo* getMember(int index); \ | |
205 virtual const SkMemberInfo* getMember(const char name[]); \ | |
206 SkDisplayTypes fType; \ | |
207 virtual SkDisplayTypes getType() const { return fType; } \ | |
208 typedef _type BASE_CLASS | |
209 | |
210 #define DECLARE_NO_VIRTUALS_MEMBER_INFO(_type) \ | |
211 public: \ | |
212 static const SkMemberInfo fInfo[]; \ | |
213 static const int fInfoCount; \ | |
214 typedef Sk##_type BASE_CLASS | |
215 | |
216 #define DEFINE_GET_MEMBER(_class) \ | |
217 const SkMemberInfo* _class::getMember(int index) { \ | |
218 const SkMemberInfo* result = SkMemberInfo::Find(fInfo, SK_ARRAY_COUNT(fI
nfo), &index); \ | |
219 return result; \ | |
220 } \ | |
221 const SkMemberInfo* _class::getMember(const char name[]) { \ | |
222 const SkMemberInfo* result = SkMemberInfo::Find(fInfo, SK_ARRAY_COUNT(fI
nfo), &name); \ | |
223 return result; \ | |
224 } \ | |
225 const int _class::fInfoCount = SK_ARRAY_COUNT(fInfo) | |
226 | |
227 #define DEFINE_NO_VIRTUALS_GET_MEMBER(_class) \ | |
228 const int _class::fInfoCount = SK_ARRAY_COUNT(fInfo) | |
229 | |
230 #else | |
231 | |
232 #define DECLARE_PRIVATE_MEMBER_INFO(_type) \ | |
233 public: \ | |
234 typedef Sk##_type BASE_CLASS | |
235 | |
236 #define DECLARE_MEMBER_INFO(_type) \ | |
237 public: \ | |
238 virtual const SkMemberInfo* getMember(int index) { \ | |
239 return SkDisplayType::GetMember(NULL, SkType_##_type, &index); } \ | |
240 virtual const SkMemberInfo* getMember(const char name[]) { \ | |
241 return SkDisplayType::GetMember(NULL, SkType_##_type, &name); } \ | |
242 virtual SkDisplayTypes getType() const { return SkType_##_type; } \ | |
243 typedef Sk##_type BASE_CLASS | |
244 | |
245 #define DECLARE_DRAW_MEMBER_INFO(_type) \ | |
246 public: \ | |
247 virtual const SkMemberInfo* getMember(int index) { \ | |
248 return SkDisplayType::GetMember(NULL, SkType_##_type, &index); } \ | |
249 virtual const SkMemberInfo* getMember(const char name[]) { \ | |
250 return SkDisplayType::GetMember(NULL, SkType_##_type, &name); } \ | |
251 virtual SkDisplayTypes getType() const { return SkType_##_type; } \ | |
252 typedef SkDraw##_type BASE_CLASS | |
253 | |
254 #define DECLARE_DISPLAY_MEMBER_INFO(_type) \ | |
255 public: \ | |
256 virtual const SkMemberInfo* getMember(int index) { \ | |
257 return SkDisplayType::GetMember(NULL, SkType_##_type, &index); } \ | |
258 virtual const SkMemberInfo* getMember(const char name[]) { \ | |
259 return SkDisplayType::GetMember(NULL, SkType_##_type, &name); } \ | |
260 virtual SkDisplayTypes getType() const { return SkType_##_type; } \ | |
261 typedef SkDisplay##_type BASE_CLASS | |
262 | |
263 #define DECLARE_EXTRAS_MEMBER_INFO(_type) \ | |
264 public: \ | |
265 virtual const SkMemberInfo* getMember(int index) { \ | |
266 return SkDisplayType::GetMember(NULL, SkType_##_type, &index); } \ | |
267 virtual const SkMemberInfo* getMember(const char name[]) { \ | |
268 return SkDisplayType::GetMember(NULL, fType, &name); } \ | |
269 SkDisplayTypes fType; \ | |
270 virtual SkDisplayTypes getType() const { return fType; } \ | |
271 typedef _type BASE_CLASS | |
272 | |
273 #define DECLARE_NO_VIRTUALS_MEMBER_INFO(_type) \ | |
274 public: \ | |
275 typedef Sk##_type BASE_CLASS | |
276 | |
277 #define DEFINE_GET_MEMBER(_class) | |
278 #define DEFINE_NO_VIRTUALS_GET_MEMBER(_class) | |
279 | |
280 #endif | |
281 | |
282 #endif // SkMemberInfo_DEFINED | |
283 | |
OLD | NEW |