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