uiacceltk/hitchcock/ServerCore/Src/alfeffectutils.cpp
changeset 14 83d2d132aa58
parent 13 8f67d927ea57
child 19 f5bac0badc7e
equal deleted inserted replaced
13:8f67d927ea57 14:83d2d132aa58
    16 */
    16 */
    17 #include <e32cmn.h>
    17 #include <e32cmn.h>
    18 #include <s32mem.h>
    18 #include <s32mem.h>
    19 #include "alfeffectutils.h"
    19 #include "alfeffectutils.h"
    20 #include <akntransitionutils.h>
    20 #include <akntransitionutils.h>
    21 
    21 #include <alflogger.h>
    22 
    22 
    23 const TInt KRosterFreezeEndTimeoutInMs = 400;
    23 const TInt KRosterFreezeEndTimeoutInMs = 100;
    24 const TInt KFirstTimeoutForApplicationEndFullScreenInMs = 50;
    24 const TInt KFirstTimeoutForApplicationEndFullScreenInMs = 20;
       
    25 const TReal KMinimumPaintedAreaBeforeForcedEffect = 0.75;
    25 
    26 
    26 // ---------------------------------------------------------
    27 // ---------------------------------------------------------
    27 // CAlfRosterFreezeEndTimer
    28 // CAlfRosterFreezeEndTimer
    28 // ---------------------------------------------------------
    29 // ---------------------------------------------------------
    29 //
    30 //
    51 CAlfRosterFreezeEndTimer::~CAlfRosterFreezeEndTimer()
    52 CAlfRosterFreezeEndTimer::~CAlfRosterFreezeEndTimer()
    52     {
    53     {
    53     Cancel();        
    54     Cancel();        
    54     }
    55     }
    55 
    56 
    56 void CAlfRosterFreezeEndTimer::Start( TTimeIntervalMicroSeconds32 aPeriod )
    57 void CAlfRosterFreezeEndTimer::Start( TTimeIntervalMicroSeconds32 aPeriod, TCallBack aCallBack  )
    57     {
    58     {
       
    59     iCallBack = aCallBack;
       
    60     __ALFLOGSTRING("CAlfRosterFreezeEndTimer::Start");
    58     if (!IsActive())
    61     if (!IsActive())
    59         {
    62         {
    60         After( aPeriod );
    63         After( aPeriod );
    61         }
    64         }
    62     }
    65     }
    63 
    66 
    64 void CAlfRosterFreezeEndTimer::RunL()
    67 void CAlfRosterFreezeEndTimer::RunL()
    65     {
    68     {
    66     iBridge.iHuiEnv->Display(0).SetDirty();
    69     __ALFLOGSTRING("CAlfRosterFreezeEndTimer::RunL");
    67     TRAP_IGNORE(iBridge.iHuiEnv->Display(0).Roster().FreezeVisibleContentL(EFalse));
    70 	
    68     iBridge.SetVisualTreeVisibilityChanged(ETrue);    
    71 	TBool timeout = EFalse;
       
    72 	
       
    73 	if (iSafeCounter >= 0)	
       
    74 	    {
       
    75 		iSafeCounter++;
       
    76 		if (iSafeCounter == 100) // can be lower, 100 should be visible enough to see, if heuristics fail
       
    77 			{
       
    78 			timeout = ETrue;
       
    79 			iSafeCounter = 0;
       
    80 			}
       
    81 		}
       
    82 
       
    83     if (!iBridge.IsFullScreenDrawn(0) && !timeout)
       
    84         {
       
    85         __ALFLOGSTRING("CAlfRosterFreezeEndTimer::RunL - Not ready in new orientation. waiting 50ms more");
       
    86         After( 50000 );
       
    87         return;
       
    88         }
       
    89     else
       
    90         {
       
    91         iCallBack.CallBack();
       
    92         }
    69     }
    93     }
    70 
    94 
    71 void CAlfRosterFreezeEndTimer::DoCancel()
    95 void CAlfRosterFreezeEndTimer::DoCancel()
    72     {
    96     {
    73     CTimer::DoCancel();
    97     CTimer::DoCancel();
    75 
    99 
    76 
   100 
    77 
   101 
    78 CAlfLayoutSwitchEffectCoordinator::CAlfLayoutSwitchEffectCoordinator( CAlfBridge& aBridge ) :
   102 CAlfLayoutSwitchEffectCoordinator::CAlfLayoutSwitchEffectCoordinator( CAlfBridge& aBridge ) :
    79     iBridge( aBridge ),
   103     iBridge( aBridge ),
    80     iLayoutSwitchEffectContext(AknTransEffect::ENone)    
   104     iLayoutSwitchEffectContext(AknTransEffect::ENone),
       
   105     iCurrentState( EStateIdle )
    81     {
   106     {
    82     RThread me = RThread();
   107     RThread me = RThread();
    83     iOriginalPriority = me.Priority();    
   108     iOriginalPriority = me.Priority();    
    84     me.Close();
   109     me.Close();
    85     }
   110     }
    87 CAlfLayoutSwitchEffectCoordinator::~CAlfLayoutSwitchEffectCoordinator()
   112 CAlfLayoutSwitchEffectCoordinator::~CAlfLayoutSwitchEffectCoordinator()
    88     {   
   113     {   
    89     }
   114     }
    90 
   115 
    91 // ---------------------------------------------------------
   116 // ---------------------------------------------------------
    92 // CAlfLayoutSwitchEffectCoordinator::AlfGfxEffectEndCallBack
   117 // CAlfLayoutSwitchEffectCoordinator::Blank
    93 //
   118 // ---------------------------------------------------------
    94 // This method is callback which gets called when layout 
   119 //
    95 // switch effect has ended.
   120 void CAlfLayoutSwitchEffectCoordinator::Blank(TBool aEnabled)
    96 // ---------------------------------------------------------
   121     {
    97 //
   122     __ALFLOGSTRING1("CAlfLayoutSwitchEffectCoordinator::Blank %d", aEnabled);
    98 void CAlfLayoutSwitchEffectCoordinator::AlfGfxEffectEndCallBack( TInt aHandle )
   123     iBlankEnabled = aEnabled;
    99     {
   124     Event( aEnabled ? EEventBlankOn : EEventBlankOff );
   100     //RDebug::Print(_L("CAlfLayoutSwitchEffectCoordinator::AlfGfxEffectEndCallBack"));
   125     }
   101     if (iLayoutSwitchEffectContext == aHandle)
   126     
   102         {
   127 // ---------------------------------------------------------
   103         AknTransEffect::TContext nextContext = NextLayoutSwitchContext();
   128 // CAlfLayoutSwitchEffectCoordinator::LowMemoryEvent
   104 
   129 // ---------------------------------------------------------
   105         // Unfreeze visible content. This reveals real roster content (in new orientation).
   130 //
   106         if (nextContext == AknTransEffect::ELayoutSwitchExit)
   131 void CAlfLayoutSwitchEffectCoordinator::LowMemoryEvent()
   107             {
   132     {
   108             #ifdef HUI_DEBUG_TRACK_DRAWING
   133     __ALFLOGSTRING("CAlfLayoutSwitchEffectCoordinator::LowMemory");
   109             RDebug::Print(_L("CAlfLayoutSwitchEffectCoordinator::AlfGfxEffectEndCallBack unfreezing roster content"));
   134     Event( EEventLowMemory );
   110             #endif
   135     }
   111             iBridge.iHuiEnv->Display(0).SetDirty();
   136     
   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 // ---------------------------------------------------------
   137 // ---------------------------------------------------------
   162 // CAlfLayoutSwitchEffectCoordinator::BeginLayoutSwitch
   138 // CAlfLayoutSwitchEffectCoordinator::BeginLayoutSwitch
   163 //
       
   164 // This method starts the layout switch effect procedure.
       
   165 // ---------------------------------------------------------
   139 // ---------------------------------------------------------
   166 //
   140 //
   167 void CAlfLayoutSwitchEffectCoordinator::BeginLayoutSwitch()
   141 void CAlfLayoutSwitchEffectCoordinator::BeginLayoutSwitch()
   168     {
   142     {
   169     // Hm. what to do if earlier is already in progress ?
   143     __ALFLOGSTRING("CAlfLayoutSwitchEffectCoordinator::BeginLayoutSwitch");
   170     //RDebug::Print(_L("CAlfLayoutSwitchEffectCoordinator::BeginLayoutSwitch"));
   144     Event( EEventLayoutSwitch );      
   171     if ( iBridge.iHuiEnv->MemoryLevel() <= EHuiMemoryLevelLowest )
   145     }
   172         {
   146 
   173         // No effects in low memory mode
   147 // ---------------------------------------------------------
   174         return;
   148 // CAlfLayoutSwitchEffectCoordinator::Event
   175         }
   149 // ---------------------------------------------------------
   176     
   150 //
   177     if (!iLayoutSwitchEffectContext)
   151 void CAlfLayoutSwitchEffectCoordinator::Event(TEvent aEvent)
   178         {
   152     {
   179         TBool tfxOn = CAknTransitionUtils::TransitionsEnabled(AknTransEffect::ELayoutswitchTransitionsOff );
   153     // States:
   180         TBool tfxExists = LayoutSwitchEffectsExist();
   154     // - EStateIdle - No layout switch effect ongoing
   181         if (tfxOn && tfxExists)
   155     // - EStateFreezeFx - Roster frozen, periodic fullscreen completeness checking
   182             {
   156     // - EStateBlankFx - Roster frozen, expecting client to say when ready to unfreeze
   183             // Boost priority so that we are able to draw more frames for the effect
   157     // - EStateThemeFx - Theme effect in use
   184             RThread me = RThread();
   158 
   185             me.SetPriority(EPriorityAbsoluteHigh);    
   159     // Events:
   186             me.Close();
   160     // - EEventBlankOn - Client requested blank on
       
   161     // - EEventBlankOff - Client requested blank off
       
   162     // - EEventLayoutSwitch - Layout switch noticed
       
   163     // - EEventLowMemory - Low memory indication
       
   164     // and implicit Finish - Effect finished
       
   165     
       
   166     // Transitions:
       
   167     // From EStateIdle:
       
   168     // - EEventBlankOn: EStateBlankFx
       
   169     // - EEventLayoutSwitch: If effect available, EStateThemeFx. Otherwise EStateFreezeFx.
       
   170     //
       
   171     // From EStateFreezeFx:
       
   172     // - EEventBlankOn: EStateBlankFx
       
   173     // - implicit Finish - EStateIdle
       
   174     //
       
   175     // From EStateBlankFx:
       
   176     // - EEventBlankOff: EStateFreezeFx (we use freeze to ensure that result is ok)
       
   177     // - EEventLayoutSwitch: If effect available, EStateThemeFx.
       
   178     //
       
   179     // From EStateThemeFx:
       
   180     // - EEventLowMemory: If blank still on, EStateBlankFx. Otherwise EStateFreezeFx.
       
   181     // - implicit Finish - EStateIdle
       
   182 
       
   183     TState nextState = EStateIdle;
       
   184     
       
   185     switch ( iCurrentState )
       
   186         {    
       
   187     case EStateFreezeFx:
       
   188         nextState = NextFreezeState(aEvent);
       
   189         break;
       
   190         
       
   191     case EStateBlankFx:
       
   192         nextState = NextBlankState(aEvent);
       
   193         break;
       
   194         
       
   195     case EStateThemeFx:
       
   196         nextState = NextThemeState(aEvent);
       
   197         break;
       
   198         
       
   199     case EStateIdle:
       
   200     default:
       
   201         nextState = NextIdleState(aEvent);   
       
   202         break;
       
   203         }
       
   204     
       
   205     if ( nextState != iCurrentState )
       
   206         {
       
   207         Transition( nextState, iCurrentState );
       
   208         }
       
   209     }
       
   210 
       
   211 // ---------------------------------------------------------
       
   212 // CAlfLayoutSwitchEffectCoordinator::Transition
       
   213 // ---------------------------------------------------------
       
   214 //
       
   215 void CAlfLayoutSwitchEffectCoordinator::Transition(
       
   216         TState aNewState, TState aPreviousState)
       
   217     {
       
   218     __ALFLOGSTRING2("CAlfLayoutSwitchEffectCoordinator::Transition from: %d to: %d", aNewState, aPreviousState);
       
   219     iCurrentState = aNewState;
       
   220         
       
   221     // Undo previous state - don't unfreeze roster.
       
   222     switch ( aPreviousState )
       
   223         {
       
   224     case EStateFreezeFx:
       
   225         if ( iRosterFreezeEndTimer )
       
   226             {
       
   227             iRosterFreezeEndTimer->Cancel();
       
   228             }
       
   229         break;
       
   230         
       
   231     case EStateBlankFx:        
       
   232         iBridge.iHuiEnv->iPauseDrawing = EFalse;
       
   233         break;
       
   234         
       
   235     case EStateThemeFx:
       
   236         {
       
   237         RThread me = RThread();
       
   238         me.SetPriority(iOriginalPriority);    
       
   239         me.Close();
       
   240 
       
   241         if ( iRosterFreezeEndTimer )
       
   242             {
       
   243             iRosterFreezeEndTimer->Cancel();
       
   244             }
       
   245 
       
   246         SetLayoutSwitchEffect( AknTransEffect::ENone );
       
   247         }
       
   248         break;
       
   249         
       
   250     case EStateIdle:
       
   251     default:    
       
   252         break;
       
   253         }
       
   254     
       
   255     // Do next state actions
       
   256     switch ( iCurrentState )
       
   257         {    
       
   258     case EStateFreezeFx:
       
   259         {
       
   260         if (!iRosterFreezeEndTimer)
       
   261             {
       
   262             TRAP_IGNORE(iRosterFreezeEndTimer = CAlfRosterFreezeEndTimer::NewL(iBridge));
       
   263             }
   187             
   264             
   188             // Freeze visual content
   265         if (iRosterFreezeEndTimer)
   189             //RDebug::Print(_L("CAlfLayoutSwitchEffectCoordinator::BeginLayoutSwitch freezing roster content"));
   266             {
   190             iBridge.iHuiEnv->Display(0).SetDirty();
   267             iRosterFreezeEndTimer->Cancel();
   191             TRAP_IGNORE(iBridge.iHuiEnv->Display(0).Roster().FreezeVisibleContentL(ETrue));
       
   192             
   268             
       
   269             FreezeRoster(ETrue);
       
   270                 
   193             // Remove all other effects
   271             // Remove all other effects
   194             iBridge.HandleGfxStopEvent( EFalse );
   272             iBridge.HandleGfxStopEvent( EFalse );
   195             iBridge.RemoveAllTemporaryPresenterVisuals();
   273             iBridge.RemoveAllTemporaryPresenterVisuals();
       
   274 
       
   275             // Set remove freeze timer
       
   276             __ALFLOGSTRING("CAlfLayoutSwitchEffectCoordinator::Transition - Freeze timer started");
       
   277             iRosterFreezeEndTimer->Start(KRosterFreezeEndTimeoutInMs*1000, TCallBack(DoFreezeFinished, this)); 
       
   278             }
       
   279         }
       
   280         break;
       
   281         
       
   282     case EStateBlankFx:
       
   283         {
       
   284         // Start blanker
       
   285         iBridge.iHuiEnv->iPauseDrawing = ETrue;
       
   286         FreezeRoster(ETrue);        
       
   287         }
       
   288         break;
       
   289         
       
   290     case EStateThemeFx:
       
   291         {
       
   292         // Boost priority so that we are able to draw more frames for the effect
       
   293         RThread me = RThread();
       
   294         me.SetPriority(EPriorityAbsoluteHigh);    
       
   295         me.Close();
   196             
   296             
   197             // Set first layout switch effect 
   297         // Freeze visual content
   198             SetLayoutSwitchEffect(AknTransEffect::ELayoutSwitchStart);
   298         iBridge.iHuiEnv->Display(0).SetDirty();
       
   299         FreezeRoster(ETrue);
       
   300             
       
   301         // Remove all other effects
       
   302         iBridge.HandleGfxStopEvent( EFalse );
       
   303         iBridge.RemoveAllTemporaryPresenterVisuals();
       
   304             
       
   305         // Set first layout switch effect 
       
   306         SetLayoutSwitchEffect(AknTransEffect::ELayoutSwitchStart);
       
   307         }
       
   308         break;
       
   309         
       
   310     case EStateIdle:
       
   311     default:
       
   312         {
       
   313         // Undo everything to be sure
       
   314         RThread me = RThread();
       
   315         me.SetPriority(iOriginalPriority);    
       
   316         me.Close();
       
   317         
       
   318         SetLayoutSwitchEffect( AknTransEffect::ENone );
       
   319         if ( iRosterFreezeEndTimer )
       
   320             {
       
   321             iRosterFreezeEndTimer->Cancel();
       
   322             }            
       
   323         
       
   324         iBridge.iHuiEnv->iPauseDrawing = EFalse;
       
   325         FreezeRoster(EFalse);
       
   326         iBridge.iHuiEnv->Display(0).SetDirty();
       
   327         iBridge.SetVisualTreeVisibilityChanged(ETrue);
       
   328         }
       
   329         break;
       
   330         }    
       
   331     
       
   332     // Inform bridge about layout switch actions
       
   333     if ( aNewState != EStateIdle && aPreviousState == EStateIdle )
       
   334         {
       
   335         iLayoutSwitchNotCompleted = ETrue;
       
   336         iBridge.LayoutSwitchStart();
       
   337         }
       
   338     if ( aNewState == EStateIdle && iLayoutSwitchNotCompleted )
       
   339         {
       
   340         iLayoutSwitchNotCompleted = EFalse;
       
   341         iBridge.LayoutSwitchComplete();
       
   342         }
       
   343     
       
   344     __ALFLOGSTRING("CAlfLayoutSwitchEffectCoordinator::Transition end");        
       
   345     }
       
   346 
       
   347 
       
   348 
       
   349 // ---------------------------------------------------------
       
   350 // CAlfLayoutSwitchEffectCoordinator::NextIdleState
       
   351 // ---------------------------------------------------------
       
   352 //
       
   353 CAlfLayoutSwitchEffectCoordinator::TState 
       
   354     CAlfLayoutSwitchEffectCoordinator::NextIdleState(
       
   355         TEvent aEvent)
       
   356     {
       
   357     TState state = EStateIdle;
       
   358     
       
   359     switch ( aEvent )
       
   360         {
       
   361     case EEventLayoutSwitch:
       
   362         if ( IsThemeEffectEnabled() )
       
   363             {
       
   364             state = EStateThemeFx;
   199             }
   365             }
   200         else
   366         else
   201             {
   367             {
   202             if (!iRosterFreezeEndTimer)
   368             state = EStateFreezeFx;
   203                 {
   369             }
   204                 TRAP_IGNORE(iRosterFreezeEndTimer = CAlfRosterFreezeEndTimer::NewL(iBridge));
   370         break;
   205                 }
   371         
       
   372     case EEventBlankOn:
       
   373         state = EStateBlankFx;
       
   374         break;
       
   375         
       
   376     case EEventBlankOff:
       
   377     case EEventLowMemory:
       
   378     default:
       
   379         break;     
       
   380         }
       
   381     
       
   382     return state;
       
   383     }
       
   384     
       
   385 // ---------------------------------------------------------
       
   386 // CAlfLayoutSwitchEffectCoordinator::NextFreezeState
       
   387 // ---------------------------------------------------------
       
   388 //
       
   389 CAlfLayoutSwitchEffectCoordinator::TState 
       
   390     CAlfLayoutSwitchEffectCoordinator::NextFreezeState(
       
   391         TEvent aEvent)
       
   392     {
       
   393     TState state = EStateFreezeFx;
       
   394     
       
   395     switch ( aEvent )
       
   396         {
       
   397     case EEventBlankOn:
       
   398         state = EStateBlankFx;
       
   399         break;
       
   400     
       
   401     case EEventLayoutSwitch:    
       
   402     case EEventBlankOff:
       
   403     case EEventLowMemory:
       
   404     default:
       
   405         break;     
       
   406         }
       
   407     
       
   408     return state;
       
   409     }
       
   410 
       
   411 // ---------------------------------------------------------
       
   412 // CAlfLayoutSwitchEffectCoordinator::NextBlankState
       
   413 // ---------------------------------------------------------
       
   414 //
       
   415 CAlfLayoutSwitchEffectCoordinator::TState 
       
   416     CAlfLayoutSwitchEffectCoordinator::NextBlankState(
       
   417         TEvent aEvent)
       
   418     {
       
   419     TState state = EStateBlankFx;
       
   420     
       
   421     switch ( aEvent )
       
   422         {
       
   423     case EEventLayoutSwitch:
       
   424         if ( IsThemeEffectEnabled() )
       
   425             {
       
   426             state = EStateThemeFx;
       
   427             }
       
   428         break;
       
   429     
       
   430     case EEventBlankOff:
       
   431         state = EStateFreezeFx;
       
   432         break;
       
   433         
       
   434     case EEventBlankOn:        
       
   435     case EEventLowMemory:
       
   436     default:
       
   437         break;     
       
   438         }
       
   439     
       
   440     return state;
       
   441     }
       
   442 
       
   443 // ---------------------------------------------------------
       
   444 // CAlfLayoutSwitchEffectCoordinator::NextThemeState
       
   445 // ---------------------------------------------------------
       
   446 //
       
   447 CAlfLayoutSwitchEffectCoordinator::TState 
       
   448     CAlfLayoutSwitchEffectCoordinator::NextThemeState(
       
   449         TEvent aEvent)       
       
   450     {
       
   451     TState state = EStateThemeFx;
       
   452     
       
   453     switch ( aEvent )
       
   454         {
       
   455     case EEventLowMemory:
       
   456         state = iBlankEnabled ? EStateBlankFx : EStateFreezeFx;
       
   457         break;
   206             
   458             
   207             if (iRosterFreezeEndTimer)
   459     case EEventLayoutSwitch:    
   208                 {
   460     case EEventBlankOn:
   209                 iBridge.iHuiEnv->Display(0).SetDirty();
   461     case EEventBlankOff:
   210                 TRAP_IGNORE(iBridge.iHuiEnv->Display(0).Roster().FreezeVisibleContentL(ETrue));
   462     default:
   211                 
   463         break;     
   212                 // Remove all other effects
   464         }
   213                 iBridge.HandleGfxStopEvent( EFalse );
   465     
   214                 iBridge.RemoveAllTemporaryPresenterVisuals();
   466     return state;
   215 
   467     }
   216                 // Set remove freeze timer
   468 
   217                 iRosterFreezeEndTimer->Start(KRosterFreezeEndTimeoutInMs*1000); 
   469 // ---------------------------------------------------------
   218                 }            
   470 // CAlfLayoutSwitchEffectCoordinator::FreezeFinished
   219             //RDebug::Print(_L("CAlfLayoutSwitchEffectCoordinator::BeginLayoutSwitch - tfx are set OFF -> I am not starting effect."));                        
   471 // ---------------------------------------------------------
   220             }
   472 //
   221         }
   473 void CAlfLayoutSwitchEffectCoordinator::FreezeFinished()
   222     else
   474     {
   223         {
   475     Transition(EStateIdle, iCurrentState);
   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     }
   476     }
   273 
   477 
   274 // ---------------------------------------------------------
   478 // ---------------------------------------------------------
   275 // CAlfLayoutSwitchEffectCoordinator::SetLayoutSwitchEffectL
   479 // CAlfLayoutSwitchEffectCoordinator::SetLayoutSwitchEffectL
   276 //
   480 //
   312                 }
   516                 }
   313             }
   517             }
   314         }    
   518         }    
   315     }
   519     }
   316 
   520 
   317 TBool CAlfLayoutSwitchEffectCoordinator::LayoutSwitchEffectsExist()
   521 // ---------------------------------------------------------
       
   522 // CAlfLayoutSwitchEffectCoordinator::AlfGfxEffectEndCallBack
       
   523 //
       
   524 // This method is callback which gets called when layout 
       
   525 // switch effect has ended.
       
   526 // ---------------------------------------------------------
       
   527 //
       
   528 void CAlfLayoutSwitchEffectCoordinator::AlfGfxEffectEndCallBack( TInt aHandle )
       
   529     {
       
   530     //RDebug::Print(_L("CAlfLayoutSwitchEffectCoordinator::AlfGfxEffectEndCallBack")); 
       
   531     // KErrNotFound indicates callback from DoNextLayoutSwitchContext
       
   532     if (iLayoutSwitchEffectContext == aHandle || aHandle == KErrNotFound)
       
   533         {
       
   534         AknTransEffect::TContext nextContext = NextLayoutSwitchContext();
       
   535 
       
   536         // Unfreeze visible content. This reveals real roster content (in new orientation).
       
   537         if (nextContext == AknTransEffect::ELayoutSwitchExit)
       
   538             {
       
   539             #ifdef HUI_DEBUG_TRACK_DRAWING
       
   540             RDebug::Print(_L("CAlfLayoutSwitchEffectCoordinator::AlfGfxEffectEndCallBack unfreezing roster content"));
       
   541             #endif
       
   542             iBridge.iHuiEnv->Display(0).SetDirty();
       
   543             FreezeRoster(EFalse);
       
   544             iBridge.SetVisualTreeVisibilityChanged(ETrue);
       
   545             if ( iLayoutSwitchNotCompleted )
       
   546                 {
       
   547                 iLayoutSwitchNotCompleted = EFalse;
       
   548                 iBridge.LayoutSwitchComplete();
       
   549                 }
       
   550             }
       
   551         
       
   552         // Set next effect
       
   553         SetLayoutSwitchEffect(nextContext);
       
   554         
       
   555         if (nextContext == AknTransEffect::ENone)
       
   556             {
       
   557             // Restore normal priority
       
   558             if ( iCurrentState == EStateThemeFx )
       
   559                 {
       
   560                 Transition(EStateIdle, iCurrentState);
       
   561                 }
       
   562             
       
   563             RThread me = RThread();
       
   564             me.SetPriority(iOriginalPriority);    
       
   565             me.Close();
       
   566 
       
   567             // Just in case refresh everything
       
   568             iBridge.iHuiEnv->Display(0).SetDirty();
       
   569             }        
       
   570         }
       
   571     else
       
   572         {
       
   573         //RDebug::Print(_L("CAlfLayoutSwitchEffectCoordinator::AlfGfxEffectEndCallBack - got different handle (normal, dont worry...) - %i"), aHandle);        
       
   574         }
       
   575     }
       
   576 
       
   577 // ---------------------------------------------------------
       
   578 // CAlfLayoutSwitchEffectCoordinator::NextLayoutSwitchContext
       
   579 //
       
   580 // This method automatically selects the next context in the 
       
   581 // layout switch procedure.
       
   582 //
       
   583 // Contextes change in the following order during layout switch:
       
   584 //
       
   585 // 1. AknTransEffect::ENone
       
   586 // 2. AknTransEffect::ELayoutSwitchStart
       
   587 // 3. AknTransEffect::ELayoutSwitchExit
       
   588 // 4. AknTransEffect::ENone
       
   589 //
       
   590 // After new context is selected, appropriate effect is set 
       
   591 // (and/or removed) from the roster.
       
   592 //
       
   593 // ---------------------------------------------------------
       
   594 //
       
   595 // todo: rename
       
   596 TInt DoNextLayoutSwitchContext(TAny* aLayoutSwitchCoordinator)
       
   597     {
       
   598     CAlfLayoutSwitchEffectCoordinator* coordinator = (CAlfLayoutSwitchEffectCoordinator*)aLayoutSwitchCoordinator;
       
   599     coordinator->AlfGfxEffectEndCallBack(KErrNotFound);
       
   600     return 0;
       
   601     }
       
   602 
       
   603 // ---------------------------------------------------------
       
   604 // CAlfLayoutSwitchEffectCoordinator::NextLayoutSwitchContext
       
   605 // ---------------------------------------------------------
       
   606 //
       
   607 AknTransEffect::TContext CAlfLayoutSwitchEffectCoordinator::NextLayoutSwitchContext()
       
   608     {
       
   609     // Resolve next context based on current context
       
   610     AknTransEffect::TContext newContext = AknTransEffect::ENone;    
       
   611     switch (iLayoutSwitchEffectContext)
       
   612         {
       
   613         case AknTransEffect::ENone:
       
   614             {
       
   615             newContext = AknTransEffect::ELayoutSwitchStart;            
       
   616             break;
       
   617             }
       
   618         case AknTransEffect::ELayoutSwitchStart:
       
   619             {
       
   620             newContext = AknTransEffect::ELayoutSwitch;
       
   621             if (!iRosterFreezeEndTimer)
       
   622                 {
       
   623                 TRAP_IGNORE(iRosterFreezeEndTimer = CAlfRosterFreezeEndTimer::NewL(iBridge));
       
   624                 }
       
   625             if (iRosterFreezeEndTimer)
       
   626                 {
       
   627                 iRosterFreezeEndTimer->Cancel();
       
   628                 iRosterFreezeEndTimer->Start(KRosterFreezeEndTimeoutInMs*1000, TCallBack(DoNextLayoutSwitchContext, this));
       
   629                 }
       
   630             else
       
   631                 {
       
   632                 newContext = AknTransEffect::ELayoutSwitchExit;
       
   633                 }
       
   634             break;
       
   635             }
       
   636         case AknTransEffect::ELayoutSwitch:
       
   637             {
       
   638             newContext = AknTransEffect::ELayoutSwitchExit;                    
       
   639             break;
       
   640             }
       
   641         case AknTransEffect::ELayoutSwitchExit: // fallthrough
       
   642         default:
       
   643             {
       
   644             newContext = AknTransEffect::ENone;            
       
   645             break;
       
   646             }              
       
   647         }
       
   648 
       
   649     //RDebug::Print(_L("CAlfLayoutSwitchEffectCoordinator::NextLayoutSwitchEffectL old ctx = %i, new ctx = %i"), iLayoutSwitchEffectContext, newContext);
       
   650     return newContext;
       
   651     }
       
   652 
       
   653 // ---------------------------------------------------------
       
   654 // CAlfLayoutSwitchEffectCoordinator::IsThemeEffectEnabled()
       
   655 // Returns true if layout switch theme effect may be used
       
   656 // ---------------------------------------------------------
       
   657 //
       
   658 TBool CAlfLayoutSwitchEffectCoordinator::IsThemeEffectEnabled() const
       
   659     {
       
   660     TBool memoryOk = !( iBridge.iHuiEnv->MemoryLevel() <= EHuiMemoryLevelLowest );
       
   661     TBool tfxOn = CAknTransitionUtils::TransitionsEnabled(AknTransEffect::ELayoutswitchTransitionsOff );
       
   662     TBool tfxExists = LayoutSwitchEffectsExist();
       
   663 
       
   664     return 
       
   665         memoryOk && tfxOn && tfxExists;
       
   666     }
       
   667 
       
   668 // ---------------------------------------------------------
       
   669 // CAlfLayoutSwitchEffectCoordinator::LayoutSwitchEffectsExist()
       
   670 // Returns true if layout switch effect exists
       
   671 // ---------------------------------------------------------
       
   672 //
       
   673 TBool CAlfLayoutSwitchEffectCoordinator::LayoutSwitchEffectsExist() const
   318     {
   674     {
   319     TBool appearExists = EFalse;
   675     TBool appearExists = EFalse;
   320     TBool disAppearExists = EFalse;
   676     TBool disAppearExists = EFalse;
   321     
   677     
   322     for ( TInt i = 0; i<iBridge.iAlfRegisteredEffects.Count(); i++ )
   678     for ( TInt i = 0; i<iBridge.iAlfRegisteredEffects.Count(); i++ )
   332             break;
   688             break;
   333             }
   689             }
   334         }
   690         }
   335     
   691     
   336     return (appearExists || disAppearExists);    
   692     return (appearExists || disAppearExists);    
       
   693     }
       
   694 
       
   695 // ---------------------------------------------------------
       
   696 // CAlfLayoutSwitchEffectCoordinator::FreezeRoster()
       
   697 // Freeze visible content in roster.
       
   698 // ---------------------------------------------------------
       
   699 //
       
   700 void CAlfLayoutSwitchEffectCoordinator::FreezeRoster(TBool aFrozen)
       
   701     {
       
   702     TRAP_IGNORE(iBridge.iHuiEnv->Display(0).Roster().FreezeVisibleContentL(aFrozen));
       
   703     }
       
   704 
       
   705 // ---------------------------------------------------------
       
   706 // CAlfLayoutSwitchEffectCoordinator::DoFreezeFinished()
       
   707 // ---------------------------------------------------------
       
   708 //
       
   709 TInt CAlfLayoutSwitchEffectCoordinator::DoFreezeFinished(TAny* aAny)
       
   710     {
       
   711     static_cast<CAlfLayoutSwitchEffectCoordinator*>(aAny)->FreezeFinished();
       
   712     return KErrNone;
   337     }
   713     }
   338 
   714 
   339 // ---------------------------------------------------------
   715 // ---------------------------------------------------------
   340 // CAlfFinishTimer
   716 // CAlfFinishTimer
   341 // ---------------------------------------------------------
   717 // ---------------------------------------------------------
   347     }
   723     }
   348 
   724 
   349 void CAlfEffectEndTimer::ConstructL()
   725 void CAlfEffectEndTimer::ConstructL()
   350     {
   726     {
   351     CTimer::ConstructL();
   727     CTimer::ConstructL();
       
   728     iHandles.ReserveL(5);
   352     CActiveScheduler::Add( this );
   729     CActiveScheduler::Add( this );
   353     }
   730     }
   354 
   731 
   355 CAlfEffectEndTimer* CAlfEffectEndTimer::NewL( CAlfBridge& aBridge )
   732 CAlfEffectEndTimer* CAlfEffectEndTimer::NewL( CAlfBridge& aBridge )
   356     {
   733     {
   361     return self;
   738     return self;
   362     }
   739     }
   363 
   740 
   364 CAlfEffectEndTimer::~CAlfEffectEndTimer()
   741 CAlfEffectEndTimer::~CAlfEffectEndTimer()
   365     {
   742     {
   366     Cancel();        
   743     Cancel();
   367     }
   744     iHandles.Close();
   368 
   745     }
   369 void CAlfEffectEndTimer::Start( TTimeIntervalMicroSeconds32 aPeriod, TInt aHandle )
   746 
   370     {
   747 void CAlfEffectEndTimer::Start( TTimeIntervalMicroSeconds32 aPeriod )
   371     iHandle = aHandle;
   748     {
   372     After( aPeriod );
   749     After( aPeriod );
       
   750     }
       
   751 
       
   752 void CAlfEffectEndTimer::AddFinishedHandleL(TInt aHandle)
       
   753     {
       
   754     iHandles.Append(aHandle);
   373     }
   755     }
   374 
   756 
   375 void CAlfEffectEndTimer::RunL()
   757 void CAlfEffectEndTimer::RunL()
   376     {
   758     {
   377     //
   759     //
   378     // timer completes and control is returned to caller
   760     // timer completes and control is returned to caller
   379     //
   761     //
   380     iBridge.TransitionFinishedHandlerL( iHandle );
   762     while(iHandles.Count())
       
   763         {
       
   764         iBridge.TransitionFinishedHandlerL( iHandles[0]);
       
   765         iHandles.Remove(0);
       
   766         }
   381     // We don't become active unless we are explicitly restarted
   767     // We don't become active unless we are explicitly restarted
   382     }
   768     }
   383 
   769 
   384 void CAlfEffectEndTimer::DoCancel()
   770 void CAlfEffectEndTimer::DoCancel()
   385     {
   771     {
   435     iAction = aAction;
   821     iAction = aAction;
   436 
   822 
   437     iHandle = aStream.ReadInt32L();
   823     iHandle = aStream.ReadInt32L();
   438 
   824 
   439     iType = aStream.ReadInt32L();
   825     iType = aStream.ReadInt32L();
   440     iWg1 = aStream.ReadInt32L();
   826     iToWg = aStream.ReadInt32L();
   441     iWg2 = aStream.ReadInt32L();
   827     iFromWg = aStream.ReadInt32L();
   442     iToAppId = aStream.ReadInt32L();
   828     iToAppId = aStream.ReadInt32L();
   443     iFromAppId = aStream.ReadInt32L();
   829     iFromAppId = aStream.ReadInt32L();
   444 
   830 
   445     if (iType == AknTransEffect::EParameterType)
   831     if (iType == AknTransEffect::EParameterType)
   446         {
   832         {
       
   833         iToSecureId = aStream.ReadInt32L();
       
   834         iFromSecureId = aStream.ReadInt32L();
   447         /*screen1 =*/aStream.ReadInt32L();
   835         /*screen1 =*/aStream.ReadInt32L();
   448         /*screen2 =*/aStream.ReadInt32L();
   836         /*screen2 =*/aStream.ReadInt32L();
   449         }
   837         }
   450     /*TInt flags =*/
   838     /*TInt flags =*/
   451     aStream.ReadInt32L();
   839     aStream.ReadInt32L();
   463     {
   851     {
   464     ((CFullScreenEffectState*)aPtr)->NotifyDrawingTimeout();
   852     ((CFullScreenEffectState*)aPtr)->NotifyDrawingTimeout();
   465     return 0; // must return something
   853     return 0; // must return something
   466     }
   854     }
   467 
   855 
   468 TBool CFullScreenEffectState::ResetTimerL(CAlfBridge* aBridge)
   856 TBool CFullScreenEffectState::InitDelayedEffectL(CAlfBridge* aBridge, TSize aDisplaySize)
   469     {
   857     {
   470     iBridge = aBridge;
   858     iBridge = aBridge;
       
   859     iDisplaySize = aDisplaySize;
   471     if (!iDrawingCompleteTimer)
   860     if (!iDrawingCompleteTimer)
   472         {
   861         {
   473         iDrawingCompleteTimer = CPeriodic::NewL( EPriorityNormal );
   862         iDrawingCompleteTimer = CPeriodic::NewL( EPriorityNormal );
   474         iDrawingCompleteTimer->Start( 
   863         iDrawingCompleteTimer->Start( 
   475                 KFirstTimeoutForApplicationEndFullScreenInMs * 1000 , 
   864                 KFirstTimeoutForApplicationEndFullScreenInMs * 1000 , 
   479     return EFalse;
   868     return EFalse;
   480     }
   869     }
   481 
   870 
   482 void CFullScreenEffectState::NotifyDrawingTimeout()
   871 void CFullScreenEffectState::NotifyDrawingTimeout()
   483     {
   872     {
   484     TRect b = iPaintedRegion.BoundingRect();
   873     
   485     if ( (b.Width() * b.Height()) > 0.75 * (iDisplaySize.iWidth * iDisplaySize.iHeight))
   874     iPaintedRegion.ClipRect(TRect(0,0, iDisplaySize.iWidth, iDisplaySize.iHeight));
       
   875     iPaintedRegion.Tidy(); // remove overlapping regions
       
   876     TInt size(0);
       
   877     for(TInt i=0; i< iPaintedRegion.Count();i++ )
       
   878         {
       
   879         size += iPaintedRegion[i].Width()*iPaintedRegion[i].Height();
       
   880         }
       
   881     // lets continue, if the covered area is more than 75% of the screen. This is usually enough.
       
   882     if ( size > KMinimumPaintedAreaBeforeForcedEffect  * (iDisplaySize.iWidth * iDisplaySize.iHeight))
   486         {
   883         {
   487         iBridge->HandleGfxEndFullScreenTimeout(this);
   884         iBridge->HandleGfxEndFullScreenTimeout(this);
   488         delete iDrawingCompleteTimer;
   885         delete iDrawingCompleteTimer;
   489         iDrawingCompleteTimer = NULL;
   886         iDrawingCompleteTimer = NULL;
   490         }
   887         }