• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright 2006 The Android Open Source Project
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 
9 
10 #ifndef SkMemberInfo_DEFINED
11 #define SkMemberInfo_DEFINED
12 
13 #if defined SK_BUILD_CONDENSED
14     #define SK_USE_CONDENSED_INFO 0
15 #endif
16 
17 #include "SkDisplayType.h"
18 #include "SkScript.h"
19 #include "SkString.h"
20 #include "SkIntArray.h"
21 
22 class SkAnimateMaker;
23 class SkDisplayable;
24 class SkScriptEngine;
25 
26 // temporary hacks until name change is more complete
27 #define SkFloat SkScalar
28 #define SkInt SkS32
29 
30 struct SkMemberInfo {
31     //!!! alternative:
32     // if fCount == 0, record is member property
33     // then fType can be type, so caller doesn't have to check
34 #if SK_USE_CONDENSED_INFO == 0
35     const char* fName;  // may be NULL for anonymous functions
36     size_t fOffset; // if negative, is index into member pointer table (for properties and functions)
37     SkDisplayTypes fType;
38     int fCount;         // for properties, actual type (count is always assumed to be 1)
39 #else
40     unsigned char fName;
41     signed char fOffset;
42     unsigned char fType;
43     signed char fCount;
44 #endif
arrayTypeSkMemberInfo45     SkDisplayTypes arrayType() const {
46         SkASSERT(fType == SkType_Array);
47         return (SkDisplayTypes) fCount;  // hack, but worth it?
48     }
functionIndexSkMemberInfo49     int functionIndex() const {
50         SkASSERT(fType == SkType_MemberFunction);
51         return (signed) fOffset > 0 ? -1 + (int) fOffset : -1 - (int) fOffset;
52     }
53     bool getArrayValue(const SkDisplayable* displayable, int index, SkOperand* value) const;
getCountSkMemberInfo54     int getCount() const {
55         return fType == SkType_MemberProperty || fType == SkType_Array ||
56             fType == SkType_MemberFunction ? 1 : fCount;
57     }
58     const SkMemberInfo* getInherited() const;
59     size_t getSize(const SkDisplayable* ) const;
60     void getString(const SkDisplayable* , SkString** string) const;
getTypeSkMemberInfo61     SkDisplayTypes getType() const {
62         return fType == SkType_MemberProperty || fType == SkType_Array ||
63             fType == SkType_MemberFunction ? (SkDisplayTypes) fCount : (SkDisplayTypes) fType;
64     }
65     void getValue(const SkDisplayable* , SkOperand values[], int count) const;
66     bool isEnum() const;
67     const char* mapEnums(const char* match, int* value) const;
memberDataSkMemberInfo68     void* memberData(const SkDisplayable* displayable) const {
69         SkASSERT(fType != SkType_MemberProperty &&  fType != SkType_MemberFunction);
70         return (void*) ((const char*) displayable + fOffset);
71     }
propertyIndexSkMemberInfo72     int propertyIndex() const {
73         SkASSERT(fType == SkType_MemberProperty);
74         return (signed) fOffset > 0 ? -1 + (int) fOffset : -1 - (int) fOffset;
75     }
propertyTypeSkMemberInfo76     SkDisplayTypes propertyType() const {
77         SkASSERT(fType == SkType_MemberProperty || fType == SkType_Array);
78         return (SkDisplayTypes) fCount;  // hack, but worth it?
79     }
setMemberDataSkMemberInfo80     void setMemberData(SkDisplayable* displayable, const void* child, size_t size) const {
81         SkASSERT(fType != SkType_MemberProperty &&  fType != SkType_MemberFunction);
82         memcpy((char*) displayable + fOffset, child, size);
83     }
84     void setString(SkDisplayable* , SkString* ) const;
85     void setValue(SkDisplayable* , const SkOperand values[], int count) const;
86     bool setValue(SkAnimateMaker& , SkTDOperandArray* storage,
87         int storageOffset, int maxStorage, SkDisplayable* ,
88         SkDisplayTypes outType, const char value[], size_t len) const;
89     bool setValue(SkAnimateMaker& , SkTDOperandArray* storage,
90         int storageOffset, int maxStorage, SkDisplayable* ,
91         SkDisplayTypes outType, SkString& str) const;
92 //  void setValue(SkDisplayable* , const char value[], const char name[]) const;
93     bool writeValue(SkDisplayable* displayable, SkTDOperandArray* arrayStorage,
94         int storageOffset, int maxStorage, void* untypedStorage, SkDisplayTypes outType,
95         SkScriptValue& scriptValue) const;
96 #if SK_USE_CONDENSED_INFO == 0
97     static const SkMemberInfo* Find(const SkMemberInfo [], int count, int* index);
98     static const SkMemberInfo* Find(const SkMemberInfo [], int count, const char** name);
99 #else
100     static const SkMemberInfo* Find(SkDisplayTypes type, int* index);
101     static const SkMemberInfo* Find(SkDisplayTypes type, const char** name);
102 #endif
103     static size_t GetSize(SkDisplayTypes type); // size of simple types only
104 //  static bool SetValue(void* value, const char* name, SkDisplayTypes , int count);
105 };
106 
107 #define SK_MEMBER(_member, _type) \
108     { #_member, SK_OFFSETOF(BASE_CLASS, _member), SkType_##_type, \
109     sizeof(((BASE_CLASS*) 1)->_member) / sizeof(SkScalar) }
110 
111 #define SK_MEMBER_ALIAS(_member, _alias, _type) \
112     { #_member, SK_OFFSETOF(BASE_CLASS, _alias), SkType_##_type, \
113     sizeof(((BASE_CLASS*) 1)->_alias) / sizeof(SkScalar) }
114 
115 #define SK_MEMBER_ARRAY(_member, _type) \
116     { #_member, SK_OFFSETOF(BASE_CLASS, _member), SkType_Array, \
117     (int) SkType_##_type }
118 
119 #define SK_MEMBER_INHERITED \
120     { (const char*) INHERITED::fInfo, 0, SkType_BaseClassInfo, INHERITED::fInfoCount }
121 
122 // #define SK_MEMBER_KEY_TYPE(_member, _type)
123 //  {#_member, (size_t) -1, SkType_##_type, 0}
124 
125 #define SK_FUNCTION(_member) \
126     k_##_member##Function
127 
128 #define SK_PROPERTY(_member) \
129     k_##_member##Property
130 
131 #define SK_MEMBER_DYNAMIC_FUNCTION(_member, _type) \
132     {#_member, (size_t) (+1 + SK_FUNCTION(_member)), SkType_MemberFunction, \
133     (int) SkType_##_type }
134 
135 #define SK_MEMBER_DYNAMIC_PROPERTY(_member, _type) \
136     {#_member, (size_t) (1 + SK_PROPERTY(_member)), SkType_MemberProperty, \
137     (int) SkType_##_type }
138 
139 #define SK_MEMBER_FUNCTION(_member, _type) \
140     {#_member, (size_t) (-1 - SK_FUNCTION(_member)), SkType_MemberFunction, \
141     (int) SkType_##_type }
142 
143 #define SK_MEMBER_PROPERTY(_member, _type) \
144     {#_member, (size_t) (-1 - SK_PROPERTY(_member)), SkType_MemberProperty, \
145     (int) SkType_##_type }
146 
147 #if SK_USE_CONDENSED_INFO == 0
148 
149 #define DECLARE_PRIVATE_MEMBER_INFO(_type) \
150 public: \
151     static const SkMemberInfo fInfo[]; \
152     static const int fInfoCount; \
153     const SkMemberInfo* getMember(int index) override; \
154     const SkMemberInfo* getMember(const char name[]) override; \
155     typedef Sk##_type BASE_CLASS
156 
157 #define DECLARE_MEMBER_INFO(_type) \
158 public: \
159     static const SkMemberInfo fInfo[]; \
160     static const int fInfoCount; \
161     const SkMemberInfo* getMember(int index) override; \
162     const SkMemberInfo* getMember(const char name[]) override; \
163     SkDisplayTypes getType() const override { return SkType_##_type; } \
164     typedef Sk##_type BASE_CLASS
165 
166 #define DECLARE_DRAW_MEMBER_INFO(_type) \
167 public: \
168     static const SkMemberInfo fInfo[]; \
169     static const int fInfoCount; \
170     const SkMemberInfo* getMember(int index) override; \
171     const SkMemberInfo* getMember(const char name[]) override; \
172     SkDisplayTypes getType() const override { return SkType_##_type; } \
173     typedef SkDraw##_type BASE_CLASS
174 
175 #define DECLARE_DISPLAY_MEMBER_INFO(_type) \
176 public: \
177     static const SkMemberInfo fInfo[]; \
178     static const int fInfoCount; \
179     const SkMemberInfo* getMember(int index) override; \
180     const SkMemberInfo* getMember(const char name[]) override; \
181     SkDisplayTypes getType() const override { return SkType_##_type; } \
182     typedef SkDisplay##_type BASE_CLASS
183 
184 #define DECLARE_EMPTY_MEMBER_INFO(_type) \
185 public: \
186     SkDisplayTypes getType() const override { return SkType_##_type; }
187 
188 #define DECLARE_EXTRAS_MEMBER_INFO(_type) \
189 public: \
190     static const SkMemberInfo fInfo[]; \
191     static const int fInfoCount; \
192     const SkMemberInfo* getMember(int index) override; \
193     const SkMemberInfo* getMember(const char name[]) override; \
194     SkDisplayTypes fType; \
195     SkDisplayTypes getType() const override { return fType; } \
196     typedef _type BASE_CLASS
197 
198 #define DECLARE_NO_VIRTUALS_MEMBER_INFO(_type) \
199 public: \
200     static const SkMemberInfo fInfo[]; \
201     static const int fInfoCount; \
202     typedef Sk##_type BASE_CLASS
203 
204 #define DEFINE_GET_MEMBER(_class) \
205     const SkMemberInfo* _class::getMember(int index) { \
206         const SkMemberInfo* result = SkMemberInfo::Find(fInfo, SK_ARRAY_COUNT(fInfo), &index); \
207         return result; \
208     } \
209     const SkMemberInfo* _class::getMember(const char name[]) { \
210         const SkMemberInfo* result = SkMemberInfo::Find(fInfo, SK_ARRAY_COUNT(fInfo), &name); \
211         return result; \
212     } \
213     const int _class::fInfoCount = SK_ARRAY_COUNT(fInfo)
214 
215 #define DEFINE_NO_VIRTUALS_GET_MEMBER(_class) \
216     const int _class::fInfoCount = SK_ARRAY_COUNT(fInfo)
217 
218 #else
219 
220 #define DECLARE_PRIVATE_MEMBER_INFO(_type) \
221 public: \
222     typedef Sk##_type BASE_CLASS
223 
224 #define DECLARE_MEMBER_INFO(_type) \
225 public: \
226     virtual const SkMemberInfo* getMember(int index) { \
227         return SkDisplayType::GetMember(NULL, SkType_##_type, &index); } \
228     virtual const SkMemberInfo* getMember(const char name[]) { \
229         return SkDisplayType::GetMember(NULL, SkType_##_type, &name); } \
230     virtual SkDisplayTypes getType() const { return SkType_##_type; } \
231     typedef Sk##_type BASE_CLASS
232 
233 #define DECLARE_DRAW_MEMBER_INFO(_type) \
234 public: \
235     virtual const SkMemberInfo* getMember(int index) { \
236         return SkDisplayType::GetMember(NULL, SkType_##_type, &index); } \
237     virtual const SkMemberInfo* getMember(const char name[]) { \
238         return SkDisplayType::GetMember(NULL, SkType_##_type, &name); } \
239     virtual SkDisplayTypes getType() const { return SkType_##_type; } \
240     typedef SkDraw##_type BASE_CLASS
241 
242 #define DECLARE_DISPLAY_MEMBER_INFO(_type) \
243 public: \
244     virtual const SkMemberInfo* getMember(int index) { \
245         return SkDisplayType::GetMember(NULL, SkType_##_type, &index); } \
246     virtual const SkMemberInfo* getMember(const char name[]) { \
247         return SkDisplayType::GetMember(NULL, SkType_##_type, &name); } \
248     virtual SkDisplayTypes getType() const { return SkType_##_type; } \
249     typedef SkDisplay##_type BASE_CLASS
250 
251 #define DECLARE_EXTRAS_MEMBER_INFO(_type) \
252 public: \
253     virtual const SkMemberInfo* getMember(int index) { \
254         return SkDisplayType::GetMember(NULL, SkType_##_type, &index); } \
255     virtual const SkMemberInfo* getMember(const char name[]) { \
256         return SkDisplayType::GetMember(NULL, fType, &name); } \
257     SkDisplayTypes fType; \
258     virtual SkDisplayTypes getType() const { return fType; } \
259     typedef _type BASE_CLASS
260 
261 #define DECLARE_NO_VIRTUALS_MEMBER_INFO(_type) \
262 public: \
263     typedef Sk##_type BASE_CLASS
264 
265 #define DEFINE_GET_MEMBER(_class)
266 #define DEFINE_NO_VIRTUALS_GET_MEMBER(_class)
267 
268 #endif
269 
270 #endif // SkMemberInfo_DEFINED
271