|
1 /* |
|
2 * Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: SVG Engine source file |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "SVGTimer.h" |
|
20 #include "SVGEngineImpl.h" |
|
21 #include "GfxAffineTransform.h" |
|
22 #include "GfxPoint2D.h" |
|
23 #include "SVGTimeContainer.h" |
|
24 |
|
25 // --------------------------------------------------------------------------- |
|
26 // Two phase constructor |
|
27 // --------------------------------------------------------------------------- |
|
28 CSvgTimer* CSvgTimer::NewLC( CSvgTimeContainer* aTimeContainer ) |
|
29 { |
|
30 CSvgTimer* self = new ( ELeave ) CSvgTimer( aTimeContainer ); |
|
31 CleanupStack::PushL( self ); |
|
32 self->ConstructL(); |
|
33 return self; |
|
34 } |
|
35 |
|
36 // |
|
37 // --------------------------------------------------------------------------- |
|
38 // Two phase constructor |
|
39 // --------------------------------------------------------------------------- |
|
40 CSvgTimer* CSvgTimer::NewL( CSvgTimeContainer* aTimeContainer ) |
|
41 { |
|
42 CSvgTimer* self = NewLC( aTimeContainer ); |
|
43 CleanupStack::Pop(); |
|
44 return self; |
|
45 } |
|
46 |
|
47 // --------------------------------------------------------------------------- |
|
48 // Private method that builds the heap objects or performs leavable actions |
|
49 // during object construction |
|
50 // --------------------------------------------------------------------------- |
|
51 void CSvgTimer::ConstructL() |
|
52 { |
|
53 // Call the base class ConstructL |
|
54 CTimer::ConstructL(); |
|
55 // Add to active scheduler |
|
56 CActiveScheduler::Add( this ); |
|
57 } |
|
58 |
|
59 // |
|
60 // --------------------------------------------------------------------------- |
|
61 // Constructor |
|
62 // Initialized with a pointer to the time container |
|
63 // --------------------------------------------------------------------------- |
|
64 CSvgTimer::CSvgTimer( CSvgTimeContainer* aTimeContainer ) : |
|
65 CTimer( CActive::EPriorityStandard ), |
|
66 iTimeContainer( aTimeContainer ) |
|
67 { |
|
68 ChangeFrameDuration( KMinFrameDelay ); |
|
69 SetStrictFrameDuration( EFalse ); |
|
70 ResetTime(); |
|
71 } |
|
72 |
|
73 // |
|
74 // --------------------------------------------------------------------------- |
|
75 // Destructor |
|
76 // --------------------------------------------------------------------------- |
|
77 CSvgTimer::~CSvgTimer() |
|
78 { |
|
79 Cancel(); |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // Reset the time |
|
84 // --------------------------------------------------------------------------- |
|
85 void CSvgTimer::ResetTime() |
|
86 { |
|
87 iTime = 0; |
|
88 iFrames = 0; |
|
89 iFirstFrameDrawn = EFalse; |
|
90 } |
|
91 |
|
92 // --------------------------------------------------------------------------- |
|
93 // Change the duration of the timer in milliseconds |
|
94 // --------------------------------------------------------------------------- |
|
95 void CSvgTimer::ChangeFrameDuration( TUint32 aFrameDuration ) |
|
96 { |
|
97 // If delay duration is less then minimum-delay, set to minimum-delay |
|
98 if ( aFrameDuration < KMinFrameDelay ) |
|
99 { |
|
100 aFrameDuration = KMinFrameDelay; |
|
101 } |
|
102 iFrameDuration = aFrameDuration; |
|
103 } |
|
104 |
|
105 // --------------------------------------------------------------------------- |
|
106 // Return the frames per 10-seconds |
|
107 // --------------------------------------------------------------------------- |
|
108 TUint CSvgTimer::Fps() |
|
109 { |
|
110 if ( iTime == 0 ) |
|
111 { |
|
112 return 0; |
|
113 } |
|
114 // iTime is in milliseconds |
|
115 return ( 10000 * iFrames ) / iTime ; |
|
116 } |
|
117 |
|
118 |
|
119 // --------------------------------------------------------------------------- |
|
120 // Standard Active Object DoCancel |
|
121 // --------------------------------------------------------------------------- |
|
122 void CSvgTimer::DoCancel() |
|
123 { |
|
124 CTimer::DoCancel(); |
|
125 } |
|
126 |
|
127 // --------------------------------------------------------------------------- |
|
128 // Standard Active Object RunL |
|
129 // --------------------------------------------------------------------------- |
|
130 void CSvgTimer::RunL() |
|
131 { |
|
132 // Check if timed entity not null |
|
133 if ( !iTimeContainer ) |
|
134 { |
|
135 return; |
|
136 } |
|
137 |
|
138 #if 0 |
|
139 // Check engine and document |
|
140 if ( !iSvgEngine || !iSvgEngine->Document() ) |
|
141 { |
|
142 return; |
|
143 } |
|
144 |
|
145 // wait for images to finish decoding |
|
146 if ( !iSvgEngine->ReadyToRender() ) |
|
147 { |
|
148 CActive::Deque(); |
|
149 CActiveScheduler::Add( this ); |
|
150 CTimer::After( 10 * 1000 ); |
|
151 return; |
|
152 } |
|
153 #endif |
|
154 /********************** Generate first frame ********************/ |
|
155 if ( !iFirstFrameDrawn ) |
|
156 { |
|
157 iFirstFrameDrawn = ETrue; |
|
158 } |
|
159 else |
|
160 { |
|
161 /********************** After first frame ********************/ |
|
162 TTime currentTime; |
|
163 currentTime.HomeTime(); |
|
164 TUint32 elapsedTime = GetElapsedMilliseconds( iPreviousFrameTime, currentTime ); |
|
165 |
|
166 // Cap elapsed time, if needed |
|
167 if ( iIsStrictFrameDuration && |
|
168 elapsedTime > iFrameDuration ) |
|
169 { |
|
170 elapsedTime = iFrameDuration; |
|
171 } |
|
172 |
|
173 // Generate frame |
|
174 iTime += elapsedTime; |
|
175 } |
|
176 |
|
177 // Mark time of new frame |
|
178 iPreviousFrameTime.HomeTime(); |
|
179 |
|
180 // Generate new frame |
|
181 TUint32 sleepTime = GenerateFrameL( iTime ); |
|
182 |
|
183 // Sleep to next frame |
|
184 if ( |
|
185 ( iTimeContainer->Document()->Engine()->SVGEngineState() == ESVGEngineRunning ) |
|
186 && ( iTimeContainer->GetCurTick().iParentTcTick < iTimeContainer->Document()->AnimationDuration() ) |
|
187 ) |
|
188 |
|
189 { |
|
190 // Dequeue to move this ActiveObject to the end of the list |
|
191 // to share processor with other AOs. |
|
192 CActive::Deque(); |
|
193 CActiveScheduler::Add( this ); |
|
194 CTimer::After( 1000 * sleepTime ); |
|
195 } |
|
196 } |
|
197 |
|
198 // -------------------------------------------------------------------------- |
|
199 // void CSvgTimer::SVGStop() |
|
200 // --------------------------------------------------------------------------- |
|
201 void CSvgTimer::SVGStop() |
|
202 { |
|
203 if ( IsActive() ) |
|
204 { |
|
205 Cancel(); // stop current timer |
|
206 } |
|
207 iFirstFrameDrawn = EFalse; |
|
208 } |
|
209 |
|
210 // -------------------------------------------------------------------------- |
|
211 // void CSvgTimer::SVGResume() |
|
212 // --------------------------------------------------------------------------- |
|
213 void CSvgTimer::SVGResume( TInt32 aTime ) |
|
214 { |
|
215 if ( !IsActive() ) |
|
216 { |
|
217 if ( aTime < 0 ) |
|
218 { |
|
219 // Error, ( negative time ) set to default |
|
220 aTime = 1000; |
|
221 } |
|
222 |
|
223 CTimer::After( aTime ); // invoke initial timer event |
|
224 } |
|
225 } |
|
226 |
|
227 // -------------------------------------------------------------------------- |
|
228 // void CSvgTimer::SetStartTime() |
|
229 // Reset animation time to zero |
|
230 // --------------------------------------------------------------------------- |
|
231 void CSvgTimer::SetStartTime() |
|
232 { |
|
233 SetSeekTime( 0 ); |
|
234 } |
|
235 |
|
236 // -------------------------------------------------------------------------- |
|
237 // void CSvgTimer::SetSeekTime( TUint32 aTime ) |
|
238 // --------------------------------------------------------------------------- |
|
239 void CSvgTimer::SetSeekTime( TUint32 aTime ) |
|
240 { |
|
241 // update the current time. |
|
242 iFirstFrameDrawn = EFalse; |
|
243 #if 0 |
|
244 // the current home time needs to be updated. |
|
245 if ( iSvgEngine && iSvgEngine->Document() && aTime != iTime ) |
|
246 { |
|
247 TSvgTimerEvent timeEvent( aTime ); |
|
248 iSvgEngine->Document()->Reset( &timeEvent ); |
|
249 } |
|
250 #endif |
|
251 iTime = aTime; |
|
252 |
|
253 if ( !IsActive() ) |
|
254 { |
|
255 CTimer::After( 1000 ); |
|
256 } |
|
257 |
|
258 } |
|
259 |
|
260 // -------------------------------------------------------------------------- |
|
261 // void CSvgTimer::SetStrictFrameDuration( TBool aKeepStrictFrameDuration ) |
|
262 // --------------------------------------------------------------------------- |
|
263 void CSvgTimer::SetStrictFrameDuration( TBool aKeepStrictFrameDuration ) |
|
264 { |
|
265 iIsStrictFrameDuration = aKeepStrictFrameDuration; |
|
266 } |
|
267 |
|
268 // -------------------------------------------------------------------------- |
|
269 // TUint32 CSvgTimer::GenerateFrameL( TUint32 aTime ) |
|
270 // --------------------------------------------------------------------------- |
|
271 TUint32 CSvgTimer::GenerateFrameL( TUint32 aTime ) |
|
272 { |
|
273 TTime startTime; |
|
274 startTime.HomeTime(); |
|
275 TSvgTick lTick; |
|
276 lTick.iRealTimeTick = aTime; |
|
277 lTick.iParentTcTick = 0; |
|
278 |
|
279 iTimeContainer->ParentTimeContainerTick( lTick ); |
|
280 |
|
281 #if 0 |
|
282 // Request to drawn frame at given time |
|
283 TSvgTimerEvent timeEvent( aTime ); |
|
284 iSvgEngine->ProcessEventL( iSvgEngine->Document(), &timeEvent ); |
|
285 #endif |
|
286 TTime endTime; |
|
287 endTime.HomeTime(); |
|
288 |
|
289 TUint32 elapsedTime = GetElapsedMilliseconds( startTime, endTime ); |
|
290 |
|
291 // Calculate sleep time to next frame |
|
292 TUint32 sleepTime = KMinSleepDuration; |
|
293 if ( elapsedTime < iFrameDuration ) |
|
294 { |
|
295 sleepTime = iFrameDuration - elapsedTime; |
|
296 if ( sleepTime < KMinSleepDuration ) |
|
297 { |
|
298 sleepTime = KMinSleepDuration; |
|
299 } |
|
300 } |
|
301 |
|
302 iFrames++; |
|
303 return sleepTime; |
|
304 } |
|
305 |
|
306 // -------------------------------------------------------------------------- |
|
307 // TUint32 CSvgTimer::GetElapsedMilliseconds( TTime& aStart, TTime& aEnd ) |
|
308 // --------------------------------------------------------------------------- |
|
309 TUint32 CSvgTimer::GetElapsedMilliseconds( TTime& aStart, TTime& aEnd ) |
|
310 { |
|
311 TTimeIntervalMicroSeconds interval64 = aEnd.MicroSecondsFrom( aStart ); |
|
312 // in milliseconds |
|
313 return I64INT( interval64.Int64() ) / 1000; |
|
314 } |