180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/*
380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2006 The Android Open Source Project
480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *
580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be
680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file.
780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */
880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifndef SkAnimatorScript_DEFINED
1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SkAnimatorScript_DEFINED
1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkDisplayable.h"
1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkScript.h"
1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkTypedArray.h"
1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkAnimateMaker;
1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querustruct SkMemberInfo;
1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querustruct SkDisplayEnumMap {
2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkDisplayTypes fType;
2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    const char* fValues;
2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru};
2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkAnimatorScript : public SkScriptEngine {
2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querupublic:
2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkAnimatorScript(SkAnimateMaker& , SkDisplayable* , SkDisplayTypes type);
2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    ~SkAnimatorScript();
2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool evaluate(const char* script, SkScriptValue* , SkDisplayTypes type);
3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void track(SkDisplayable* displayable) {
3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        SkASSERT(fTrackDisplayable.find(displayable) < 0);
3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        *fTrackDisplayable.append() = displayable; }
3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static bool EvaluateDisplayable(SkAnimateMaker& , SkDisplayable* , const char* script, SkDisplayable** );
3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static bool EvaluateFloat(SkAnimateMaker& , SkDisplayable* , const char* script, SkScalar* );
3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static bool EvaluateInt(SkAnimateMaker& , SkDisplayable* , const char* script, int32_t* );
3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static bool EvaluateString(SkAnimateMaker& , SkDisplayable* , const char* script, SkString* );
3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static bool EvaluateString(SkAnimateMaker& , SkDisplayable* , SkDisplayable* parent, const char* script, SkString* );
3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static bool MapEnums(const char* ptr, const char* match, size_t len, int* value);
3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruprotected:
4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static bool Box(void* user, SkScriptValue* );
4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static bool Eval(const char* function, size_t len, SkTDArray<SkScriptValue>& params,
4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        void* callBack, SkScriptValue* );
4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static bool EvalEnum(const char* token, size_t len, void* callBack, SkScriptValue* );
4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static bool EvalID(const char* token, size_t len, void* callBack, SkScriptValue* );
4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static bool EvalMember(const char* member, size_t len, void* object, void* eng,
4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        SkScriptValue* value);
4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static bool EvalMemberCommon(SkScriptEngine* , const SkMemberInfo* info,
4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        SkDisplayable* displayable, SkScriptValue* value);
4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static bool EvalMemberFunction(const char* member, size_t len, void* object,
5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        SkTDArray<SkScriptValue>& params, void* user, SkScriptValue* value);
5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static bool EvalNamedColor(const char* token, size_t len, void* callBack, SkScriptValue* );
5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static bool EvalRGB(const char* function, size_t len, SkTDArray<SkScriptValue>& params,
5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        void* callBack, SkScriptValue* );
5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static const SkDisplayEnumMap& GetEnumValues(SkDisplayTypes type);
5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static bool Infinity(const char* token, size_t len, void* callBack, SkScriptValue* );
5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static bool IsFinite(const char* function, size_t len, SkTDArray<SkScriptValue>& params,
5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        void* callBack, SkScriptValue* );
5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static bool IsNaN(const char* function, size_t len, SkTDArray<SkScriptValue>& params,
5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        void* callBack, SkScriptValue* );
6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static bool NaN(const char* token, size_t len, void* callBack, SkScriptValue* );
6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static bool Unbox(void* , SkScriptValue* scriptValue);
6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkTDDisplayableArray fTrackDisplayable;
6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkAnimateMaker& fMaker;
6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkDisplayable* fParent;
6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkDisplayable* fWorking;
6680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruprivate:
6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    friend class SkDump;
6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    friend struct SkScriptNAnswer;
6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifdef SK_SUPPORT_UNITTEST
7080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querupublic:
7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    static void UnitTest();
7280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif
7380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru};
7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
7580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif // SkAnimatorScript_DEFINED
76