Home | History | Annotate | Download | only in animator
      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 
      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);
     30     void track(SkDisplayable* displayable) {
     31         SkASSERT(fTrackDisplayable.find(displayable) < 0);
     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* );
     41     static bool Eval(const char* function, size_t len, SkTDArray<SkScriptValue>& params,
     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* );
     45     static bool EvalMember(const char* member, size_t len, void* object, void* eng,
     46         SkScriptValue* value);
     47     static bool EvalMemberCommon(SkScriptEngine* , const SkMemberInfo* info,
     48         SkDisplayable* displayable, SkScriptValue* value);
     49     static bool EvalMemberFunction(const char* member, size_t len, void* object,
     50         SkTDArray<SkScriptValue>& params, void* user, SkScriptValue* value);
     51     static bool EvalNamedColor(const char* token, size_t len, void* callBack, SkScriptValue* );
     52     static bool EvalRGB(const char* function, size_t len, SkTDArray<SkScriptValue>& params,
     53         void* callBack, SkScriptValue* );
     54     static const SkDisplayEnumMap& GetEnumValues(SkDisplayTypes type);
     55     static bool Infinity(const char* token, size_t len, void* callBack, SkScriptValue* );
     56     static bool IsFinite(const char* function, size_t len, SkTDArray<SkScriptValue>& params,
     57         void* callBack, SkScriptValue* );
     58     static bool IsNaN(const char* function, size_t len, SkTDArray<SkScriptValue>& params,
     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
     76 
     77