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