blob: 8589388e113e8ba8aa1ecc7e62e87f3305062163 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
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.com8a1c16f2008-12-17 15:59:43 +00009
10#ifndef SkAnimatorScript_DEFINED
11#define SkAnimatorScript_DEFINED
12
13#include "SkDisplayable.h"
14#include "SkScript.h"
15#include "SkTypedArray.h"
16
17class SkAnimateMaker;
18struct SkMemberInfo;
19
20struct SkDisplayEnumMap {
21 SkDisplayTypes fType;
22 const char* fValues;
23};
24
25class SkAnimatorScript : public SkScriptEngine {
26public:
27 SkAnimatorScript(SkAnimateMaker& , SkDisplayable* , SkDisplayTypes type);
28 ~SkAnimatorScript();
29 bool evaluate(const char* script, SkScriptValue* , SkDisplayTypes type);
rmistry@google.comd6176b02012-08-23 18:14:13 +000030 void track(SkDisplayable* displayable) {
31 SkASSERT(fTrackDisplayable.find(displayable) < 0);
reed@android.com8a1c16f2008-12-17 15:59:43 +000032 *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);
39protected:
40 static bool Box(void* user, SkScriptValue* );
rmistry@google.comd6176b02012-08-23 18:14:13 +000041 static bool Eval(const char* function, size_t len, SkTDArray<SkScriptValue>& params,
reed@android.com8a1c16f2008-12-17 15:59:43 +000042 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.comd6176b02012-08-23 18:14:13 +000045 static bool EvalMember(const char* member, size_t len, void* object, void* eng,
reed@android.com8a1c16f2008-12-17 15:59:43 +000046 SkScriptValue* value);
rmistry@google.comd6176b02012-08-23 18:14:13 +000047 static bool EvalMemberCommon(SkScriptEngine* , const SkMemberInfo* info,
reed@android.com8a1c16f2008-12-17 15:59:43 +000048 SkDisplayable* displayable, SkScriptValue* value);
rmistry@google.comd6176b02012-08-23 18:14:13 +000049 static bool EvalMemberFunction(const char* member, size_t len, void* object,
reed@android.com8a1c16f2008-12-17 15:59:43 +000050 SkTDArray<SkScriptValue>& params, void* user, SkScriptValue* value);
51 static bool EvalNamedColor(const char* token, size_t len, void* callBack, SkScriptValue* );
rmistry@google.comd6176b02012-08-23 18:14:13 +000052 static bool EvalRGB(const char* function, size_t len, SkTDArray<SkScriptValue>& params,
reed@android.com8a1c16f2008-12-17 15:59:43 +000053 void* callBack, SkScriptValue* );
rmistry@google.comd6176b02012-08-23 18:14:13 +000054 static const SkDisplayEnumMap& GetEnumValues(SkDisplayTypes type);
reed@android.com8a1c16f2008-12-17 15:59:43 +000055 static bool Infinity(const char* token, size_t len, void* callBack, SkScriptValue* );
rmistry@google.comd6176b02012-08-23 18:14:13 +000056 static bool IsFinite(const char* function, size_t len, SkTDArray<SkScriptValue>& params,
reed@android.com8a1c16f2008-12-17 15:59:43 +000057 void* callBack, SkScriptValue* );
rmistry@google.comd6176b02012-08-23 18:14:13 +000058 static bool IsNaN(const char* function, size_t len, SkTDArray<SkScriptValue>& params,
reed@android.com8a1c16f2008-12-17 15:59:43 +000059 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;
66private:
67 friend class SkDump;
68 friend struct SkScriptNAnswer;
69#ifdef SK_SUPPORT_UNITTEST
70public:
71 static void UnitTest();
72#endif
73};
74
75#endif // SkAnimatorScript_DEFINED