blob: dae8caff2f9726d4877faf09272da61afc5de601 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/* libs/graphics/animator/SkAnimateMaker.h
2**
3** Copyright 2006, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#ifndef SkAnimateMaker_DEFINED
19#define SkAnimateMaker_DEFINED
20
21// #define SK_DEBUG_ANIMATION_TIMING
22
23#include "SkAnimator.h"
24#include "SkBitmap.h"
25#include "SkIntArray.h"
26#include "SkDisplayEvents.h"
27#include "SkDisplayList.h"
28#include "SkDisplayScreenplay.h"
29#include "SkDisplayXMLParser.h"
30#include "SkScript.h"
31#include "SkString.h"
32#include "SkTDict.h"
33
34// not sure where this little helper macro should go
35
36
37class SkActive;
38class SkAnimate;
39class SkCanvas;
40class SkDisplayable;
41class SkDrawable;
42class SkDump;
43class SkEvent;
44class SkEventSink;
45class SkExtras;
46class SkGroup;
47class SkPaint;
48class SkStream;
49
50class SkAnimateMaker {
51public:
52 SkAnimateMaker(SkAnimator* animator, SkCanvas* canvas, SkPaint* paint);
53 ~SkAnimateMaker();
54 void appendActive(SkActive* );
55 void childrenAdd(SkDisplayable* child) { *fChildren.append() = child; }
56 void clearExtraPropertyCallBack(SkDisplayTypes type);
57 bool computeID(SkDisplayable* displayable, SkDisplayable* parent, SkString* newID);
58 SkDisplayable* createInstance(const char name[], size_t len);
59 bool decodeStream(SkStream* stream);
60 bool decodeURI(const char uri[]);
61 void delayEnable(SkApply* apply, SkMSec time);
62 void doDelayedEvent();
63 bool doEvent(const SkEvent& event);
64#ifdef SK_DUMP_ENABLED
65 void dump(const char* match);
66#endif
67 int dynamicProperty(SkString& nameStr, SkDisplayable** );
68 bool find(const char* str, SkDisplayable** displayablePtr) const {
69 return fIDs.find(str, displayablePtr);
70 }
71 bool find(const char* str, size_t len, SkDisplayable** displayablePtr) const {
72 return fIDs.find(str, len, displayablePtr);
73 }
74 bool findKey(SkDisplayable* displayable, const char** string) const {
75 return fIDs.findKey(displayable, string);
76 }
77// bool find(SkString& string, SkDisplayable** displayablePtr) {
78// return fIDs.find(string.c_str(), displayablePtr);
79// }
80 SkAnimator* getAnimator() { return fAnimator; }
81 SkMSec getAppTime() const; // call caller to get current time
82#ifdef SK_DEBUG
83 SkAnimator* getRoot();
84#endif
85 SkXMLParserError::ErrorCode getErrorCode() const { return fError.getErrorCode(); }
86 SkMSec getInTime() { return fDisplayList.getTime(); }
87 int getNativeCode() const { return fError.getNativeCode(); }
88 bool hasError() { return fError.hasError(); }
89 void helperAdd(SkDisplayable* trackMe);
90 void helperRemove(SkDisplayable* alreadyTracked);
91 void idsSet(const char* attrValue, size_t len, SkDisplayable* displayable) {
92 fIDs.set(attrValue, len, displayable); }
93// void loadMovies();
94 void notifyInval();
95 void notifyInvalTime(SkMSec time);
96 void postOnEnd(SkAnimateBase* animate, SkMSec end);
97 void removeActive(SkActive* );
98 void reset();
99 bool resolveID(SkDisplayable* displayable, SkDisplayable* original);
100 void setEnableTime(SkMSec appTime, SkMSec expectedTime);
101 void setErrorCode(SkXMLParserError::ErrorCode err) { if (fError.hasError() == false) fError.INHERITED::setCode(err); }
102 void setErrorCode(SkDisplayXMLParserError::ErrorCode err) { if (fError.hasError() == false) fError.setCode(err); }
103 void setErrorNoun(const SkString& str) { if (fError.hasError() == false) fError.setNoun(str); }
104 void setErrorString();
105 void setExtraPropertyCallBack(SkDisplayTypes type, SkScriptEngine::_propertyCallBack , void* userStorage);
106 void setID(SkDisplayable* displayable, const SkString& newID);
107 void setInnerError(SkAnimateMaker* maker, const SkString& str) { fError.setInnerError(maker, str); }
108 void setScriptError(const SkScriptEngine& );
109#ifdef SK_DEBUG
110 void validate() { fDisplayList.validate(); }
111#else
112 void validate() {}
113#endif
114 SkDisplayEvent* fActiveEvent;
115 SkMSec fAdjustedStart;
116 SkCanvas* fCanvas;
117 SkMSec fEnableTime;
118 int fEndDepth; // passed parameter to onEndElement
119 SkEvents fEvents;
120 SkDisplayList fDisplayList;
121 SkEventSinkID fHostEventSinkID;
122 SkMSec fMinimumInterval;
123 SkPaint* fPaint;
124 SkAnimateMaker* fParentMaker;
125 SkString fPrefix;
126 SkDisplayScreenplay fScreenplay;
127 const SkAnimator::Timeline* fTimeline;
128 SkBool8 fInInclude;
129 SkBool8 fInMovie;
130 SkBool8 fFirstScriptError;
131#if defined SK_DEBUG && defined SK_DEBUG_ANIMATION_TIMING
132 SkMSec fDebugTimeBase;
133#endif
134#ifdef SK_DUMP_ENABLED
135 SkString fDumpAnimated;
136 SkBool8 fDumpEvents;
137 SkBool8 fDumpGConditions;
138 SkBool8 fDumpPosts;
139#endif
140private:
141 void deleteMembers();
142 static bool GetStep(const char* token, size_t len, void* stepPtr, SkScriptValue* );
143 SkAnimateMaker& operator=(SkAnimateMaker& );
144 SkTDDisplayableArray fChildren;
145 SkTDDisplayableArray fDelayed; // SkApply that contain delayed enable events
146 SkDisplayXMLParserError fError;
147 SkString fErrorString;
148 SkTDArray<SkExtras*> fExtras;
149 SkString fFileName;
150 SkTDDisplayableArray fHelpers; // helper displayables
151 SkBool8 fLoaded;
152 SkTDDisplayableArray fMovies;
153 SkTDict<SkDisplayable*> fIDs;
154 SkAnimator* fAnimator;
155 friend class SkAdd;
156 friend class SkAnimateBase;
157 friend class SkDisplayXMLParser;
158 friend class SkAnimator;
159 friend class SkAnimatorScript;
160 friend class SkApply;
161 friend class SkDisplayMovie;
162 friend class SkDisplayType;
163 friend class SkEvents;
164 friend class SkGroup;
165 friend struct SkMemberInfo;
166};
167
168#endif // SkAnimateMaker_DEFINED
169