|
1 /* |
|
2 * Copyright (c) 2008 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: AlfEffectUtils contains small classes that enable layout switch and transition effects. |
|
15 * |
|
16 */ |
|
17 #include <e32cmn.h> |
|
18 #include <s32mem.h> |
|
19 #include "alfeffectutils.h" |
|
20 #include <akntransitionutils.h> |
|
21 |
|
22 |
|
23 const TInt KRosterFreezeEndTimeoutInMs = 400; |
|
24 const TInt KFirstTimeoutForApplicationEndFullScreenInMs = 50; |
|
25 |
|
26 // --------------------------------------------------------- |
|
27 // CAlfRosterFreezeEndTimer |
|
28 // --------------------------------------------------------- |
|
29 // |
|
30 CAlfRosterFreezeEndTimer::CAlfRosterFreezeEndTimer( CAlfBridge& aBridge ) |
|
31 :CTimer ( EPriorityStandard ), |
|
32 iBridge( aBridge ) |
|
33 { |
|
34 } |
|
35 |
|
36 void CAlfRosterFreezeEndTimer::ConstructL() |
|
37 { |
|
38 CTimer::ConstructL(); |
|
39 CActiveScheduler::Add( this ); |
|
40 } |
|
41 |
|
42 CAlfRosterFreezeEndTimer* CAlfRosterFreezeEndTimer::NewL( CAlfBridge& aBridge ) |
|
43 { |
|
44 CAlfRosterFreezeEndTimer* self = new ( ELeave ) CAlfRosterFreezeEndTimer( aBridge ); |
|
45 CleanupStack::PushL( self ); |
|
46 self->ConstructL(); |
|
47 CleanupStack::Pop( self ); |
|
48 return self; |
|
49 } |
|
50 |
|
51 CAlfRosterFreezeEndTimer::~CAlfRosterFreezeEndTimer() |
|
52 { |
|
53 Cancel(); |
|
54 } |
|
55 |
|
56 void CAlfRosterFreezeEndTimer::Start( TTimeIntervalMicroSeconds32 aPeriod ) |
|
57 { |
|
58 if (!IsActive()) |
|
59 { |
|
60 After( aPeriod ); |
|
61 } |
|
62 } |
|
63 |
|
64 void CAlfRosterFreezeEndTimer::RunL() |
|
65 { |
|
66 iBridge.iHuiEnv->Display(0).SetDirty(); |
|
67 TRAP_IGNORE(iBridge.iHuiEnv->Display(0).Roster().FreezeVisibleContentL(EFalse)); |
|
68 iBridge.SetVisualTreeVisibilityChanged(ETrue); |
|
69 } |
|
70 |
|
71 void CAlfRosterFreezeEndTimer::DoCancel() |
|
72 { |
|
73 CTimer::DoCancel(); |
|
74 } |
|
75 |
|
76 |
|
77 |
|
78 CAlfLayoutSwitchEffectCoordinator::CAlfLayoutSwitchEffectCoordinator( CAlfBridge& aBridge ) : |
|
79 iBridge( aBridge ), |
|
80 iLayoutSwitchEffectContext(AknTransEffect::ENone) |
|
81 { |
|
82 RThread me = RThread(); |
|
83 iOriginalPriority = me.Priority(); |
|
84 me.Close(); |
|
85 } |
|
86 |
|
87 CAlfLayoutSwitchEffectCoordinator::~CAlfLayoutSwitchEffectCoordinator() |
|
88 { |
|
89 } |
|
90 |
|
91 // --------------------------------------------------------- |
|
92 // CAlfLayoutSwitchEffectCoordinator::AlfGfxEffectEndCallBack |
|
93 // |
|
94 // This method is callback which gets called when layout |
|
95 // switch effect has ended. |
|
96 // --------------------------------------------------------- |
|
97 // |
|
98 void CAlfLayoutSwitchEffectCoordinator::AlfGfxEffectEndCallBack( TInt aHandle ) |
|
99 { |
|
100 //RDebug::Print(_L("CAlfLayoutSwitchEffectCoordinator::AlfGfxEffectEndCallBack")); |
|
101 if (iLayoutSwitchEffectContext == aHandle) |
|
102 { |
|
103 AknTransEffect::TContext nextContext = NextLayoutSwitchContext(); |
|
104 |
|
105 // Unfreeze visible content. This reveals real roster content (in new orientation). |
|
106 if (nextContext == AknTransEffect::ELayoutSwitchExit) |
|
107 { |
|
108 #ifdef HUI_DEBUG_TRACK_DRAWING |
|
109 RDebug::Print(_L("CAlfLayoutSwitchEffectCoordinator::AlfGfxEffectEndCallBack unfreezing roster content")); |
|
110 #endif |
|
111 iBridge.iHuiEnv->Display(0).SetDirty(); |
|
112 TRAP_IGNORE(iBridge.iHuiEnv->Display(0).Roster().FreezeVisibleContentL(EFalse)); |
|
113 iBridge.SetVisualTreeVisibilityChanged(ETrue); |
|
114 } |
|
115 |
|
116 // Set next effect |
|
117 SetLayoutSwitchEffect(nextContext); |
|
118 |
|
119 if (nextContext == AknTransEffect::ENone) |
|
120 { |
|
121 // Restore normal priority |
|
122 RThread me = RThread(); |
|
123 me.SetPriority(iOriginalPriority); |
|
124 me.Close(); |
|
125 |
|
126 // Just in case refresh everything |
|
127 iBridge.iHuiEnv->Display(0).SetDirty(); |
|
128 } |
|
129 } |
|
130 else |
|
131 { |
|
132 //RDebug::Print(_L("CAlfLayoutSwitchEffectCoordinator::AlfGfxEffectEndCallBack - got different handle (normal, dont worry...) - %i"), aHandle); |
|
133 } |
|
134 } |
|
135 |
|
136 // --------------------------------------------------------- |
|
137 // CAlfLayoutSwitchEffectCoordinator::Cancel |
|
138 // --------------------------------------------------------- |
|
139 // |
|
140 void CAlfLayoutSwitchEffectCoordinator::Cancel() |
|
141 { |
|
142 // Disable effect |
|
143 SetLayoutSwitchEffect( AknTransEffect::ENone ); |
|
144 |
|
145 // Unfreeze visible content |
|
146 if ( iRosterFreezeEndTimer ) |
|
147 { |
|
148 iRosterFreezeEndTimer->Cancel(); |
|
149 } |
|
150 |
|
151 iBridge.iHuiEnv->Display(0).SetDirty(); |
|
152 TRAP_IGNORE(iBridge.iHuiEnv->Display(0).Roster().FreezeVisibleContentL(EFalse)); |
|
153 iBridge.SetVisualTreeVisibilityChanged(ETrue); |
|
154 |
|
155 // Restore normal priority |
|
156 RThread me = RThread(); |
|
157 me.SetPriority(iOriginalPriority); |
|
158 me.Close(); |
|
159 } |
|
160 |
|
161 // --------------------------------------------------------- |
|
162 // CAlfLayoutSwitchEffectCoordinator::BeginLayoutSwitch |
|
163 // |
|
164 // This method starts the layout switch effect procedure. |
|
165 // --------------------------------------------------------- |
|
166 // |
|
167 void CAlfLayoutSwitchEffectCoordinator::BeginLayoutSwitch() |
|
168 { |
|
169 // Hm. what to do if earlier is already in progress ? |
|
170 //RDebug::Print(_L("CAlfLayoutSwitchEffectCoordinator::BeginLayoutSwitch")); |
|
171 if ( iBridge.iHuiEnv->MemoryLevel() <= EHuiMemoryLevelLowest ) |
|
172 { |
|
173 // No effects in low memory mode |
|
174 return; |
|
175 } |
|
176 |
|
177 if (!iLayoutSwitchEffectContext) |
|
178 { |
|
179 TBool tfxOn = CAknTransitionUtils::TransitionsEnabled(AknTransEffect::ELayoutswitchTransitionsOff ); |
|
180 TBool tfxExists = LayoutSwitchEffectsExist(); |
|
181 if (tfxOn && tfxExists) |
|
182 { |
|
183 // Boost priority so that we are able to draw more frames for the effect |
|
184 RThread me = RThread(); |
|
185 me.SetPriority(EPriorityAbsoluteHigh); |
|
186 me.Close(); |
|
187 |
|
188 // Freeze visual content |
|
189 //RDebug::Print(_L("CAlfLayoutSwitchEffectCoordinator::BeginLayoutSwitch freezing roster content")); |
|
190 iBridge.iHuiEnv->Display(0).SetDirty(); |
|
191 TRAP_IGNORE(iBridge.iHuiEnv->Display(0).Roster().FreezeVisibleContentL(ETrue)); |
|
192 |
|
193 // Remove all other effects |
|
194 iBridge.HandleGfxStopEvent( EFalse ); |
|
195 iBridge.RemoveAllTemporaryPresenterVisuals(); |
|
196 |
|
197 // Set first layout switch effect |
|
198 SetLayoutSwitchEffect(AknTransEffect::ELayoutSwitchStart); |
|
199 } |
|
200 else |
|
201 { |
|
202 if (!iRosterFreezeEndTimer) |
|
203 { |
|
204 TRAP_IGNORE(iRosterFreezeEndTimer = CAlfRosterFreezeEndTimer::NewL(iBridge)); |
|
205 } |
|
206 |
|
207 if (iRosterFreezeEndTimer) |
|
208 { |
|
209 iBridge.iHuiEnv->Display(0).SetDirty(); |
|
210 TRAP_IGNORE(iBridge.iHuiEnv->Display(0).Roster().FreezeVisibleContentL(ETrue)); |
|
211 |
|
212 // Remove all other effects |
|
213 iBridge.HandleGfxStopEvent( EFalse ); |
|
214 iBridge.RemoveAllTemporaryPresenterVisuals(); |
|
215 |
|
216 // Set remove freeze timer |
|
217 iRosterFreezeEndTimer->Start(KRosterFreezeEndTimeoutInMs*1000); |
|
218 } |
|
219 //RDebug::Print(_L("CAlfLayoutSwitchEffectCoordinator::BeginLayoutSwitch - tfx are set OFF -> I am not starting effect.")); |
|
220 } |
|
221 } |
|
222 else |
|
223 { |
|
224 //RDebug::Print(_L("CAlfLayoutSwitchEffectCoordinator::BeginLayoutSwitch - old effect exists - %i"), iLayoutSwitchEffectContext); |
|
225 } |
|
226 } |
|
227 |
|
228 // --------------------------------------------------------- |
|
229 // CAlfLayoutSwitchEffectCoordinator::NextLayoutSwitchContext |
|
230 // |
|
231 // This method automatically selects the next context in the |
|
232 // layout switch procedure. |
|
233 // |
|
234 // Contextes change in the following order during layout switch: |
|
235 // |
|
236 // 1. AknTransEffect::ENone |
|
237 // 2. AknTransEffect::ELayoutSwitchStart |
|
238 // 3. AknTransEffect::ELayoutSwitchExit |
|
239 // 4. AknTransEffect::ENone |
|
240 // |
|
241 // After new context is selected, appropriate effect is set |
|
242 // (and/or removed) from the roster. |
|
243 // |
|
244 // --------------------------------------------------------- |
|
245 // |
|
246 AknTransEffect::TContext CAlfLayoutSwitchEffectCoordinator::NextLayoutSwitchContext() |
|
247 { |
|
248 // Resolve next context based on current context |
|
249 AknTransEffect::TContext newContext = AknTransEffect::ENone; |
|
250 switch (iLayoutSwitchEffectContext) |
|
251 { |
|
252 case AknTransEffect::ENone: |
|
253 { |
|
254 newContext = AknTransEffect::ELayoutSwitchStart; |
|
255 break; |
|
256 } |
|
257 case AknTransEffect::ELayoutSwitchStart: |
|
258 { |
|
259 newContext = AknTransEffect::ELayoutSwitchExit; |
|
260 break; |
|
261 } |
|
262 case AknTransEffect::ELayoutSwitchExit: // fallthrough |
|
263 default: |
|
264 { |
|
265 newContext = AknTransEffect::ENone; |
|
266 break; |
|
267 } |
|
268 } |
|
269 |
|
270 //RDebug::Print(_L("CAlfLayoutSwitchEffectCoordinator::NextLayoutSwitchEffectL old ctx = %i, new ctx = %i"), iLayoutSwitchEffectContext, newContext); |
|
271 return newContext; |
|
272 } |
|
273 |
|
274 // --------------------------------------------------------- |
|
275 // CAlfLayoutSwitchEffectCoordinator::SetLayoutSwitchEffectL |
|
276 // |
|
277 // This method sets correct effect based on the given |
|
278 // layout switch context. |
|
279 // |
|
280 // --------------------------------------------------------- |
|
281 // |
|
282 void CAlfLayoutSwitchEffectCoordinator::SetLayoutSwitchEffect(AknTransEffect::TContext aContext) |
|
283 { |
|
284 MHuiEffectable* effectable = iBridge.iHuiEnv->Display(0).Roster().Effectable(); |
|
285 CHuiFxEffect* effect = NULL; |
|
286 CHuiFxEngine* engine = iBridge.iHuiEnv->EffectsEngine(); |
|
287 |
|
288 if (!effectable || !engine) |
|
289 { |
|
290 return; |
|
291 } |
|
292 |
|
293 // Update current context |
|
294 iLayoutSwitchEffectContext = aContext; |
|
295 |
|
296 if (aContext == AknTransEffect::ENone) |
|
297 { |
|
298 // Just remove effect |
|
299 //RDebug::Print(_L("CAlfLayoutSwitchEffectCoordinator::NextLayoutSwitchEffectL - removing effect")); |
|
300 effectable->EffectSetEffect(NULL); // This calls AlfGfxEffectEndCallBack |
|
301 } |
|
302 else |
|
303 { |
|
304 // Load correct effect |
|
305 for ( TInt i = 0; i<iBridge.iAlfRegisteredEffects.Count(); i++ ) |
|
306 { |
|
307 if ( iBridge.iAlfRegisteredEffects[i].iAction == aContext) |
|
308 { |
|
309 //RDebug::Print(_L("CAlfLayoutSwitchEffectCoordinator::SetLayoutSwitchEffectL - loading effect")); |
|
310 TRAP_IGNORE(engine->LoadEffectL(*iBridge.iAlfRegisteredEffects[i].iEffectFile, effect, effectable, NULL, this, iLayoutSwitchEffectContext, 0 ) ); |
|
311 break; |
|
312 } |
|
313 } |
|
314 } |
|
315 } |
|
316 |
|
317 TBool CAlfLayoutSwitchEffectCoordinator::LayoutSwitchEffectsExist() |
|
318 { |
|
319 TBool appearExists = EFalse; |
|
320 TBool disAppearExists = EFalse; |
|
321 |
|
322 for ( TInt i = 0; i<iBridge.iAlfRegisteredEffects.Count(); i++ ) |
|
323 { |
|
324 if ( iBridge.iAlfRegisteredEffects[i].iAction == AknTransEffect::ELayoutSwitchStart) |
|
325 { |
|
326 disAppearExists = ETrue; |
|
327 break; |
|
328 } |
|
329 else if ( iBridge.iAlfRegisteredEffects[i].iAction == AknTransEffect::ELayoutSwitchExit) |
|
330 { |
|
331 appearExists = ETrue; |
|
332 break; |
|
333 } |
|
334 } |
|
335 |
|
336 return (appearExists || disAppearExists); |
|
337 } |
|
338 |
|
339 // --------------------------------------------------------- |
|
340 // CAlfFinishTimer |
|
341 // --------------------------------------------------------- |
|
342 // |
|
343 CAlfEffectEndTimer::CAlfEffectEndTimer( CAlfBridge& aBridge ) |
|
344 :CTimer(EPriorityHigh), |
|
345 iBridge(aBridge) |
|
346 { |
|
347 } |
|
348 |
|
349 void CAlfEffectEndTimer::ConstructL() |
|
350 { |
|
351 CTimer::ConstructL(); |
|
352 CActiveScheduler::Add( this ); |
|
353 } |
|
354 |
|
355 CAlfEffectEndTimer* CAlfEffectEndTimer::NewL( CAlfBridge& aBridge ) |
|
356 { |
|
357 CAlfEffectEndTimer* self = new ( ELeave ) CAlfEffectEndTimer( aBridge ); |
|
358 CleanupStack::PushL( self ); |
|
359 self->ConstructL(); |
|
360 CleanupStack::Pop( self ); |
|
361 return self; |
|
362 } |
|
363 |
|
364 CAlfEffectEndTimer::~CAlfEffectEndTimer() |
|
365 { |
|
366 Cancel(); |
|
367 } |
|
368 |
|
369 void CAlfEffectEndTimer::Start( TTimeIntervalMicroSeconds32 aPeriod, TInt aHandle ) |
|
370 { |
|
371 iHandle = aHandle; |
|
372 After( aPeriod ); |
|
373 } |
|
374 |
|
375 void CAlfEffectEndTimer::RunL() |
|
376 { |
|
377 // |
|
378 // timer completes and control is returned to caller |
|
379 // |
|
380 iBridge.TransitionFinishedHandlerL( iHandle ); |
|
381 // We don't become active unless we are explicitly restarted |
|
382 } |
|
383 |
|
384 void CAlfEffectEndTimer::DoCancel() |
|
385 { |
|
386 CTimer::DoCancel(); |
|
387 } |
|
388 |
|
389 |
|
390 CEffectState::CEffectState() |
|
391 { |
|
392 // CBase clears all variables |
|
393 } |
|
394 |
|
395 CEffectState::~CEffectState() |
|
396 { |
|
397 delete iEffectName; |
|
398 } |
|
399 |
|
400 void CEffectState::ResolveFileNameL(RMemReadStream& aStream) |
|
401 { |
|
402 HBufC* effectDirectory = HBufC::NewLC(aStream, 256); |
|
403 HBufC* effectFile = HBufC::NewLC(aStream, 256); |
|
404 |
|
405 // Add one extra because we want to be able to append a number to the filename |
|
406 HBufC* effectFullName = HBufC::NewL(effectDirectory->Des().Length() |
|
407 + effectFile->Des().Length() + 1); |
|
408 CleanupStack::PushL(effectFullName); |
|
409 |
|
410 effectFullName->Des().Copy(*(effectDirectory)); |
|
411 effectFullName->Des().Append(*(effectFile)); |
|
412 delete iEffectName; |
|
413 iEffectName = effectFullName; // ownership transferred |
|
414 CleanupStack::Pop(effectFullName); |
|
415 CleanupStack::PopAndDestroy(2, effectDirectory); |
|
416 } |
|
417 |
|
418 |
|
419 CFullScreenEffectState::~CFullScreenEffectState() |
|
420 { |
|
421 iPaintedRegion.Close(); |
|
422 if (iDrawingCompleteTimer) |
|
423 { |
|
424 iDrawingCompleteTimer->Cancel(); |
|
425 delete iDrawingCompleteTimer; |
|
426 iDrawingCompleteTimer = NULL; |
|
427 } |
|
428 } |
|
429 |
|
430 |
|
431 void CFullScreenEffectState::ConstructL( |
|
432 TInt aAction, |
|
433 RMemReadStream& aStream) |
|
434 { |
|
435 iAction = aAction; |
|
436 |
|
437 iHandle = aStream.ReadInt32L(); |
|
438 |
|
439 iType = aStream.ReadInt32L(); |
|
440 iWg1 = aStream.ReadInt32L(); |
|
441 iWg2 = aStream.ReadInt32L(); |
|
442 iToAppId = aStream.ReadInt32L(); |
|
443 iFromAppId = aStream.ReadInt32L(); |
|
444 |
|
445 if (iType == AknTransEffect::EParameterType) |
|
446 { |
|
447 /*screen1 =*/aStream.ReadInt32L(); |
|
448 /*screen2 =*/aStream.ReadInt32L(); |
|
449 } |
|
450 /*TInt flags =*/ |
|
451 aStream.ReadInt32L(); |
|
452 iRect.iTl.iX = aStream.ReadInt32L(); |
|
453 iRect.iTl.iY = aStream.ReadInt32L(); |
|
454 iRect.iBr.iX = aStream.ReadInt32L(); |
|
455 iRect.iBr.iY = aStream.ReadInt32L(); |
|
456 |
|
457 ResolveFileNameL(aStream); |
|
458 |
|
459 iCompletionHandle = iHandle; |
|
460 } |
|
461 |
|
462 TInt doNotifyDrawingTimeout( TAny* aPtr ) |
|
463 { |
|
464 ((CFullScreenEffectState*)aPtr)->NotifyDrawingTimeout(); |
|
465 return 0; // must return something |
|
466 } |
|
467 |
|
468 TBool CFullScreenEffectState::ResetTimerL(CAlfBridge* aBridge) |
|
469 { |
|
470 iBridge = aBridge; |
|
471 if (!iDrawingCompleteTimer) |
|
472 { |
|
473 iDrawingCompleteTimer = CPeriodic::NewL( EPriorityNormal ); |
|
474 iDrawingCompleteTimer->Start( |
|
475 KFirstTimeoutForApplicationEndFullScreenInMs * 1000 , |
|
476 KFirstTimeoutForApplicationEndFullScreenInMs * 1000 , TCallBack( doNotifyDrawingTimeout, this )); |
|
477 return ETrue; |
|
478 } |
|
479 return EFalse; |
|
480 } |
|
481 |
|
482 void CFullScreenEffectState::NotifyDrawingTimeout() |
|
483 { |
|
484 TRect b = iPaintedRegion.BoundingRect(); |
|
485 if ( (b.Width() * b.Height()) > 0.75 * (iDisplaySize.iWidth * iDisplaySize.iHeight)) |
|
486 { |
|
487 iBridge->HandleGfxEndFullScreenTimeout(this); |
|
488 delete iDrawingCompleteTimer; |
|
489 iDrawingCompleteTimer = NULL; |
|
490 } |
|
491 } |
|
492 |
|
493 void CControlEffectState::ConstructL(TInt aAction, |
|
494 RMemReadStream& aStream) |
|
495 { |
|
496 iAction = aAction; |
|
497 TInt operation = aStream.ReadInt32L(); |
|
498 iHandle = aStream.ReadInt32L(); |
|
499 iClientHandle = aStream.ReadInt32L(); |
|
500 iClientGroupHandle = aStream.ReadInt32L(); |
|
501 TInt screenNumber = aStream.ReadInt32L(); // this has always value 0 |
|
502 // Are Symbian full filename+directory combinations still max 256 characters long? |
|
503 ResolveFileNameL(aStream); |
|
504 } |
|
505 |