epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 9 | |
| 10 | #ifndef SkAnimatorScript_DEFINED |
| 11 | #define SkAnimatorScript_DEFINED |
| 12 | |
| 13 | #include "SkDisplayable.h" |
| 14 | #include "SkScript.h" |
| 15 | #include "SkTypedArray.h" |
| 16 | |
| 17 | class SkAnimateMaker; |
| 18 | struct SkMemberInfo; |
| 19 | |
| 20 | struct SkDisplayEnumMap { |
| 21 | SkDisplayTypes fType; |
| 22 | const char* fValues; |
| 23 | }; |
| 24 | |
| 25 | class SkAnimatorScript : public SkScriptEngine { |
| 26 | public: |
| 27 | SkAnimatorScript(SkAnimateMaker& , SkDisplayable* , SkDisplayTypes type); |
| 28 | ~SkAnimatorScript(); |
| 29 | bool evaluate(const char* script, SkScriptValue* , SkDisplayTypes type); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 30 | void track(SkDisplayable* displayable) { |
| 31 | SkASSERT(fTrackDisplayable.find(displayable) < 0); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 32 | *fTrackDisplayable.append() = displayable; } |
| 33 | static bool EvaluateDisplayable(SkAnimateMaker& , SkDisplayable* , const char* script, SkDisplayable** ); |
| 34 | static bool EvaluateFloat(SkAnimateMaker& , SkDisplayable* , const char* script, SkScalar* ); |
| 35 | static bool EvaluateInt(SkAnimateMaker& , SkDisplayable* , const char* script, int32_t* ); |
| 36 | static bool EvaluateString(SkAnimateMaker& , SkDisplayable* , const char* script, SkString* ); |
| 37 | static bool EvaluateString(SkAnimateMaker& , SkDisplayable* , SkDisplayable* parent, const char* script, SkString* ); |
| 38 | static bool MapEnums(const char* ptr, const char* match, size_t len, int* value); |
| 39 | protected: |
| 40 | static bool Box(void* user, SkScriptValue* ); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 41 | static bool Eval(const char* function, size_t len, SkTDArray<SkScriptValue>& params, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 42 | void* callBack, SkScriptValue* ); |
| 43 | static bool EvalEnum(const char* token, size_t len, void* callBack, SkScriptValue* ); |
| 44 | static bool EvalID(const char* token, size_t len, void* callBack, SkScriptValue* ); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 45 | static bool EvalMember(const char* member, size_t len, void* object, void* eng, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 46 | SkScriptValue* value); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 47 | static bool EvalMemberCommon(SkScriptEngine* , const SkMemberInfo* info, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 48 | SkDisplayable* displayable, SkScriptValue* value); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 49 | static bool EvalMemberFunction(const char* member, size_t len, void* object, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 50 | SkTDArray<SkScriptValue>& params, void* user, SkScriptValue* value); |
| 51 | static bool EvalNamedColor(const char* token, size_t len, void* callBack, SkScriptValue* ); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 52 | static bool EvalRGB(const char* function, size_t len, SkTDArray<SkScriptValue>& params, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 53 | void* callBack, SkScriptValue* ); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 54 | static const SkDisplayEnumMap& GetEnumValues(SkDisplayTypes type); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 55 | static bool Infinity(const char* token, size_t len, void* callBack, SkScriptValue* ); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 56 | static bool IsFinite(const char* function, size_t len, SkTDArray<SkScriptValue>& params, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 57 | void* callBack, SkScriptValue* ); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 58 | static bool IsNaN(const char* function, size_t len, SkTDArray<SkScriptValue>& params, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 59 | void* callBack, SkScriptValue* ); |
| 60 | static bool NaN(const char* token, size_t len, void* callBack, SkScriptValue* ); |
| 61 | static bool Unbox(void* , SkScriptValue* scriptValue); |
| 62 | SkTDDisplayableArray fTrackDisplayable; |
| 63 | SkAnimateMaker& fMaker; |
| 64 | SkDisplayable* fParent; |
| 65 | SkDisplayable* fWorking; |
| 66 | private: |
| 67 | friend class SkDump; |
| 68 | friend struct SkScriptNAnswer; |
| 69 | #ifdef SK_SUPPORT_UNITTEST |
| 70 | public: |
| 71 | static void UnitTest(); |
| 72 | #endif |
| 73 | }; |
| 74 | |
| 75 | #endif // SkAnimatorScript_DEFINED |