1 2 /* 3 * Copyright 2011 Google Inc. 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 #ifndef SkScriptCallBack_DEFINED 9 #define SkScriptCallBack_DEFINED 10 11 #include "SkOperand2.h" 12 #include "SkTDArray_Experimental.h" 13 14 class SkScriptCallBack { 15 public: 16 enum Type { 17 kBox, 18 kFunction, 19 kMember, 20 kMemberFunction, 21 kProperty, 22 kUnbox 23 }; 24 getReference(const char *,size_t len,SkScriptValue2 * result)25 virtual bool getReference(const char* , size_t len, SkScriptValue2* result) { return false; } getReturnType(size_t ref,SkOperand2 *)26 virtual SkOperand2::OpType getReturnType(size_t ref, SkOperand2*) { 27 return SkOperand2::kS32; } 28 virtual Type getType() const = 0; 29 }; 30 31 class SkScriptCallBackConvert : public SkScriptCallBack { 32 public: 33 virtual bool convert(SkOperand2::OpType type, SkOperand2* operand) = 0; 34 }; 35 36 class SkScriptCallBackFunction : public SkScriptCallBack { 37 public: 38 virtual void getParamTypes(SkIntArray(SkOperand2::OpType)* types) = 0; getType()39 virtual Type getType() const { return kFunction; } 40 virtual bool invoke(size_t ref, SkOpArray* params, SkOperand2* value) = 0; 41 }; 42 43 class SkScriptCallBackMember: public SkScriptCallBack { 44 public: 45 bool getMemberReference(const char* , size_t len, void* object, SkScriptValue2* ref); getType()46 virtual Type getType() const { return kMember; } 47 virtual bool invoke(size_t ref, void* object, SkOperand2* value) = 0; 48 }; 49 50 class SkScriptCallBackMemberFunction : public SkScriptCallBack { 51 public: 52 bool getMemberReference(const char* , size_t len, void* object, SkScriptValue2* ref); 53 virtual void getParamTypes(SkIntArray(SkOperand2::OpType)* types) = 0; getType()54 virtual Type getType() const { return kMemberFunction; } 55 virtual bool invoke(size_t ref, void* object, SkOpArray* params, SkOperand2* value) = 0; 56 }; 57 58 class SkScriptCallBackProperty : public SkScriptCallBack { 59 public: getConstValue(const char * name,size_t len,SkOperand2 * value)60 virtual bool getConstValue(const char* name, size_t len, SkOperand2* value) { return false; } getResult(size_t ref,SkOperand2 * answer)61 virtual bool getResult(size_t ref, SkOperand2* answer) { return false; } getType()62 virtual Type getType() const { return kProperty; } 63 }; 64 65 #endif // SkScriptCallBack_DEFINED 66