1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/*
3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project
4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com *
5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be
6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file.
7ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com */
8ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkAnimateMaker_DEFINED
118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkAnimateMaker_DEFINED
128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// #define SK_DEBUG_ANIMATION_TIMING
148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkAnimator.h"
168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkBitmap.h"
178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkIntArray.h"
188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDisplayEvents.h"
198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDisplayList.h"
208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDisplayScreenplay.h"
218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkDisplayXMLParser.h"
228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkScript.h"
238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkString.h"
248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkTDict.h"
258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com// not sure where this little helper macro should go
278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkActive;
308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkAnimate;
318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkCanvas;
328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkDisplayable;
33986ca61cf7be3ec590f8820e9b7ba042ac2948fereedclass SkADrawable;
348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkDump;
358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkEvent;
368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkEventSink;
378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkExtras;
388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkGroup;
398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkPaint;
408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkStream;
418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkAnimateMaker {
438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkAnimateMaker(SkAnimator* animator, SkCanvas* canvas, SkPaint* paint);
458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    ~SkAnimateMaker();
468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void appendActive(SkActive* );
478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void childrenAdd(SkDisplayable* child) { *fChildren.append() = child; }
488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void clearExtraPropertyCallBack(SkDisplayTypes type);
498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    bool computeID(SkDisplayable* displayable, SkDisplayable* parent, SkString* newID);
508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDisplayable* createInstance(const char name[], size_t len);
518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    bool decodeStream(SkStream* stream);
528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    bool decodeURI(const char uri[]);
538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void delayEnable(SkApply* apply, SkMSec time);
548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void doDelayedEvent();
558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    bool doEvent(const SkEvent& event);
568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_DUMP_ENABLED
578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void dump(const char* match);
588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    int dynamicProperty(SkString& nameStr, SkDisplayable**  );
60d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    bool find(const char* str, SkDisplayable** displayablePtr) const {
618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        return fIDs.find(str, displayablePtr);
628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
63d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    bool find(const char* str, size_t len, SkDisplayable** displayablePtr) const {
648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        return fIDs.find(str, len, displayablePtr);
658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    bool findKey(SkDisplayable* displayable, const char** string) const {
678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        return fIDs.findKey(displayable, string);
688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    }
69d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com//  bool find(SkString& string, SkDisplayable** displayablePtr) {
708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com//      return fIDs.find(string.c_str(), displayablePtr);
718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com//  }
728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkAnimator* getAnimator() { return fAnimator; }
738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkMSec getAppTime() const; // call caller to get current time
748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_DEBUG
758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkAnimator* getRoot();
768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkXMLParserError::ErrorCode getErrorCode() const { return fError.getErrorCode(); }
788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkMSec getInTime() { return fDisplayList.getTime(); }
798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    int getNativeCode() const { return fError.getNativeCode(); }
808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    bool hasError() { return fError.hasError(); }
818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void helperAdd(SkDisplayable* trackMe);
828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void helperRemove(SkDisplayable* alreadyTracked);
83d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com    void idsSet(const char* attrValue, size_t len, SkDisplayable* displayable) {
848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        fIDs.set(attrValue, len, displayable); }
858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com//  void loadMovies();
868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void notifyInval();
878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void notifyInvalTime(SkMSec time);
888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void postOnEnd(SkAnimateBase* animate, SkMSec end);
898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void removeActive(SkActive* );
908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void reset();
918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    bool resolveID(SkDisplayable* displayable, SkDisplayable* original);
928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void setEnableTime(SkMSec appTime, SkMSec expectedTime);
938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void setErrorCode(SkXMLParserError::ErrorCode err) { if (fError.hasError() == false) fError.INHERITED::setCode(err); }
948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void setErrorCode(SkDisplayXMLParserError::ErrorCode err) { if (fError.hasError() == false) fError.setCode(err); }
958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void setErrorNoun(const SkString& str) { if (fError.hasError() == false) fError.setNoun(str); }
968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void setErrorString();
978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void setExtraPropertyCallBack(SkDisplayTypes type, SkScriptEngine::_propertyCallBack , void* userStorage);
988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void setID(SkDisplayable* displayable, const SkString& newID);
998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void setInnerError(SkAnimateMaker* maker, const SkString& str) { fError.setInnerError(maker, str); }
1008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void setScriptError(const SkScriptEngine& );
1018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_DEBUG
1028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void validate() { fDisplayList.validate(); }
1038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#else
1048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void validate() {}
1058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
1068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDisplayEvent* fActiveEvent;
1078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkMSec fAdjustedStart;
1088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkCanvas* fCanvas;
1098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkMSec fEnableTime;
1108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    int fEndDepth;  // passed parameter to onEndElement
1118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkEvents fEvents;
1128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDisplayList fDisplayList;
1138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkEventSinkID fHostEventSinkID;
1148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkMSec fMinimumInterval;
1158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkPaint* fPaint;
1168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkAnimateMaker* fParentMaker;
1178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkString fPrefix;
1188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDisplayScreenplay fScreenplay;
1198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    const SkAnimator::Timeline* fTimeline;
1208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkBool8 fInInclude;
1218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkBool8 fInMovie;
1228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkBool8 fFirstScriptError;
1238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#if defined SK_DEBUG && defined SK_DEBUG_ANIMATION_TIMING
1248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkMSec fDebugTimeBase;
1258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
1268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_DUMP_ENABLED
1278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkString fDumpAnimated;
1288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkBool8 fDumpEvents;
1298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkBool8 fDumpGConditions;
1308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkBool8 fDumpPosts;
1318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
1328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate:
1338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void deleteMembers();
1348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    static bool GetStep(const char* token, size_t len, void* stepPtr, SkScriptValue* );
1358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkAnimateMaker& operator=(SkAnimateMaker& );
1368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkTDDisplayableArray fChildren;
1378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkTDDisplayableArray fDelayed; // SkApply that contain delayed enable events
1388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkDisplayXMLParserError fError;
1398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkString fErrorString;
1408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkTDArray<SkExtras*> fExtras;
1418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkString fFileName;
1428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkTDDisplayableArray fHelpers;  // helper displayables
1438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkBool8 fLoaded;
1448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkTDDisplayableArray fMovies;
1458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkTDict<SkDisplayable*> fIDs;
1468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkAnimator* fAnimator;
1478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    friend class SkAdd;
1488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    friend class SkAnimateBase;
1498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    friend class SkDisplayXMLParser;
1508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    friend class SkAnimator;
1518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    friend class SkAnimatorScript;
1528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    friend class SkApply;
1538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    friend class SkDisplayMovie;
1548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    friend class SkDisplayType;
1558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    friend class SkEvents;
1568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    friend class SkGroup;
1578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    friend struct SkMemberInfo;
1588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
1598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
1608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif // SkAnimateMaker_DEFINED
161