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 SkAnimateMaker_DEFINED
     11 #define SkAnimateMaker_DEFINED
     12 
     13 // #define SK_DEBUG_ANIMATION_TIMING
     14 
     15 #include "SkAnimator.h"
     16 #include "SkBitmap.h"
     17 #include "SkIntArray.h"
     18 #include "SkDisplayEvents.h"
     19 #include "SkDisplayList.h"
     20 #include "SkDisplayScreenplay.h"
     21 #include "SkDisplayXMLParser.h"
     22 #include "SkScript.h"
     23 #include "SkString.h"
     24 #include "SkTDict.h"
     25 
     26 // not sure where this little helper macro should go
     27 
     28 
     29 class SkActive;
     30 class SkAnimate;
     31 class SkCanvas;
     32 class SkDisplayable;
     33 class SkADrawable;
     34 class SkDump;
     35 class SkEvent;
     36 class SkEventSink;
     37 class SkExtras;
     38 class SkGroup;
     39 class SkPaint;
     40 class SkStream;
     41 
     42 class SkAnimateMaker {
     43 public:
     44     SkAnimateMaker(SkAnimator* animator, SkCanvas* canvas, SkPaint* paint);
     45     ~SkAnimateMaker();
     46     void appendActive(SkActive* );
     47     void childrenAdd(SkDisplayable* child) { *fChildren.append() = child; }
     48     void clearExtraPropertyCallBack(SkDisplayTypes type);
     49     bool computeID(SkDisplayable* displayable, SkDisplayable* parent, SkString* newID);
     50     SkDisplayable* createInstance(const char name[], size_t len);
     51     bool decodeStream(SkStream* stream);
     52     bool decodeURI(const char uri[]);
     53     void delayEnable(SkApply* apply, SkMSec time);
     54     void doDelayedEvent();
     55     bool doEvent(const SkEvent& event);
     56 #ifdef SK_DUMP_ENABLED
     57     void dump(const char* match);
     58 #endif
     59     int dynamicProperty(SkString& nameStr, SkDisplayable**  );
     60     bool find(const char* str, SkDisplayable** displayablePtr) const {
     61         return fIDs.find(str, displayablePtr);
     62     }
     63     bool find(const char* str, size_t len, SkDisplayable** displayablePtr) const {
     64         return fIDs.find(str, len, displayablePtr);
     65     }
     66     bool findKey(SkDisplayable* displayable, const char** string) const {
     67         return fIDs.findKey(displayable, string);
     68     }
     69 //  bool find(SkString& string, SkDisplayable** displayablePtr) {
     70 //      return fIDs.find(string.c_str(), displayablePtr);
     71 //  }
     72     SkAnimator* getAnimator() { return fAnimator; }
     73     SkMSec getAppTime() const; // call caller to get current time
     74 #ifdef SK_DEBUG
     75     SkAnimator* getRoot();
     76 #endif
     77     SkXMLParserError::ErrorCode getErrorCode() const { return fError.getErrorCode(); }
     78     SkMSec getInTime() { return fDisplayList.getTime(); }
     79     int getNativeCode() const { return fError.getNativeCode(); }
     80     bool hasError() { return fError.hasError(); }
     81     void helperAdd(SkDisplayable* trackMe);
     82     void helperRemove(SkDisplayable* alreadyTracked);
     83     void idsSet(const char* attrValue, size_t len, SkDisplayable* displayable) {
     84         fIDs.set(attrValue, len, displayable); }
     85 //  void loadMovies();
     86     void notifyInval();
     87     void notifyInvalTime(SkMSec time);
     88     void postOnEnd(SkAnimateBase* animate, SkMSec end);
     89     void removeActive(SkActive* );
     90     void reset();
     91     bool resolveID(SkDisplayable* displayable, SkDisplayable* original);
     92     void setEnableTime(SkMSec appTime, SkMSec expectedTime);
     93     void setErrorCode(SkXMLParserError::ErrorCode err) { if (fError.hasError() == false) fError.INHERITED::setCode(err); }
     94     void setErrorCode(SkDisplayXMLParserError::ErrorCode err) { if (fError.hasError() == false) fError.setCode(err); }
     95     void setErrorNoun(const SkString& str) { if (fError.hasError() == false) fError.setNoun(str); }
     96     void setErrorString();
     97     void setExtraPropertyCallBack(SkDisplayTypes type, SkScriptEngine::_propertyCallBack , void* userStorage);
     98     void setID(SkDisplayable* displayable, const SkString& newID);
     99     void setInnerError(SkAnimateMaker* maker, const SkString& str) { fError.setInnerError(maker, str); }
    100     void setScriptError(const SkScriptEngine& );
    101 #ifdef SK_DEBUG
    102     void validate() { fDisplayList.validate(); }
    103 #else
    104     void validate() {}
    105 #endif
    106     SkDisplayEvent* fActiveEvent;
    107     SkMSec fAdjustedStart;
    108     SkCanvas* fCanvas;
    109     SkMSec fEnableTime;
    110     int fEndDepth;  // passed parameter to onEndElement
    111     SkEvents fEvents;
    112     SkDisplayList fDisplayList;
    113     SkEventSinkID fHostEventSinkID;
    114     SkMSec fMinimumInterval;
    115     SkPaint* fPaint;
    116     SkAnimateMaker* fParentMaker;
    117     SkString fPrefix;
    118     SkDisplayScreenplay fScreenplay;
    119     const SkAnimator::Timeline* fTimeline;
    120     SkBool8 fInInclude;
    121     SkBool8 fInMovie;
    122     SkBool8 fFirstScriptError;
    123 #if defined SK_DEBUG && defined SK_DEBUG_ANIMATION_TIMING
    124     SkMSec fDebugTimeBase;
    125 #endif
    126 #ifdef SK_DUMP_ENABLED
    127     SkString fDumpAnimated;
    128     SkBool8 fDumpEvents;
    129     SkBool8 fDumpGConditions;
    130     SkBool8 fDumpPosts;
    131 #endif
    132 private:
    133     void deleteMembers();
    134     static bool GetStep(const char* token, size_t len, void* stepPtr, SkScriptValue* );
    135     SkAnimateMaker& operator=(SkAnimateMaker& );
    136     SkTDDisplayableArray fChildren;
    137     SkTDDisplayableArray fDelayed; // SkApply that contain delayed enable events
    138     SkDisplayXMLParserError fError;
    139     SkString fErrorString;
    140     SkTDArray<SkExtras*> fExtras;
    141     SkString fFileName;
    142     SkTDDisplayableArray fHelpers;  // helper displayables
    143     SkBool8 fLoaded;
    144     SkTDDisplayableArray fMovies;
    145     SkTDict<SkDisplayable*> fIDs;
    146     SkAnimator* fAnimator;
    147     friend class SkAdd;
    148     friend class SkAnimateBase;
    149     friend class SkDisplayXMLParser;
    150     friend class SkAnimator;
    151     friend class SkAnimatorScript;
    152     friend class SkApply;
    153     friend class SkDisplayMovie;
    154     friend class SkDisplayType;
    155     friend class SkEvents;
    156     friend class SkGroup;
    157     friend struct SkMemberInfo;
    158 };
    159 
    160 #endif // SkAnimateMaker_DEFINED
    161