uiacceltk/hitchcock/backgroundanim/src/bganimhost.cpp
branchRCL_3
changeset 22 7c5dd702d6d3
parent 17 3ac8bf5c5014
equal deleted inserted replaced
17:3ac8bf5c5014 22:7c5dd702d6d3
    39     {
    39     {
    40     iSkinSrv.Close();
    40     iSkinSrv.Close();
    41     delete iCurrentPluginDllName;
    41     delete iCurrentPluginDllName;
    42     delete iCurrentPluginAssetDir;
    42     delete iCurrentPluginAssetDir;
    43     delete iTimer;
    43     delete iTimer;
    44     if (iPlugin)
    44     delete iTheReaper;
    45         {
    45     delete iDoomBringer;
    46         iPlugin->destroy();
    46     
    47         free(iPlugin);
    47     ReleasePlugin();
    48         }
    48 
    49     iPluginLibrary.Close();
       
    50 #if !defined(SYMBIAN_GRAPHICS_WSERV_QT_EFFECTS)
    49 #if !defined(SYMBIAN_GRAPHICS_WSERV_QT_EFFECTS)
    51     delete iSCPropertyListener;
    50     delete iSCPropertyListener;
    52 #endif
    51 #endif
       
    52     delete iHSFgStatusPropertyListener;
    53     delete iThemeRepositoryListener;
    53     delete iThemeRepositoryListener;
    54     while (iSensorListeners.Count())
    54 
    55         {
       
    56         delete iSensorListeners[0];
       
    57         iSensorListeners.Remove(0);
       
    58         }
       
    59     iSensorListeners.Close();
    55     iSensorListeners.Close();
    60     delete CActiveScheduler::Current();
    56     delete CActiveScheduler::Current();
    61     CActiveScheduler::Install(NULL);
    57     CActiveScheduler::Install(NULL);
    62     ReleaseWindowSurface();
    58     ReleaseWindowSurface();
    63     ReleaseEGL();
    59     ReleaseEGL();
    80     iWsSession.EnableWindowSizeCacheL();
    76     iWsSession.EnableWindowSizeCacheL();
    81         
    77         
    82     CActiveScheduler *ac = new (ELeave) CActiveScheduler;
    78     CActiveScheduler *ac = new (ELeave) CActiveScheduler;
    83     CActiveScheduler::Install(ac);
    79     CActiveScheduler::Install(ac);
    84     iTimer = CHighResTimer::NewL(TCallBack(TimerFunc, this),CActive::EPriorityStandard);
    80     iTimer = CHighResTimer::NewL(TCallBack(TimerFunc, this),CActive::EPriorityStandard);
       
    81     iTheReaper = CHighResTimer::NewL(TCallBack(ReaperFunc, this),CActive::EPriorityStandard);
    85     iThemeRepositoryListener = CThemeRepositoryListener::NewL(&iRunning);
    82     iThemeRepositoryListener = CThemeRepositoryListener::NewL(&iRunning);
    86 #if !defined(SYMBIAN_GRAPHICS_WSERV_QT_EFFECTS)
    83 #if !defined(SYMBIAN_GRAPHICS_WSERV_QT_EFFECTS)
    87     iSCPropertyListener = CScreenSaverPropertyListener::NewL(TCallBack(ScreenSaverCallback, this));
    84     iSCPropertyListener = CScreenSaverPropertyListener::NewL(TCallBack(ScreenSaverCallback, this));
    88 #endif
    85 #endif
    89     
    86     iHSFgStatusPropertyListener = CFGAppPropertyListener::NewL(TCallBack(FgAppCallback, this));
    90     CreateWindowL();
    87     CreateWindowL();
    91 
    88 
    92     User::LeaveIfError(iSkinSrv.Connect());
    89     User::LeaveIfError(iSkinSrv.Connect());
    93     // load the initial plugin
    90     // load the initial plugin
    94     GetPluginConfigurationL();
    91     GetPluginConfigurationL();
    99     User::LeaveIfError(iPlugin->gpuresourcesavailable(1));
    96     User::LeaveIfError(iPlugin->gpuresourcesavailable(1));
   100     iThemeRepositoryListener->IssueRequest();
    97     iThemeRepositoryListener->IssueRequest();
   101 #if !defined(SYMBIAN_GRAPHICS_WSERV_QT_EFFECTS)    
    98 #if !defined(SYMBIAN_GRAPHICS_WSERV_QT_EFFECTS)    
   102     iSCPropertyListener->IssueRequest();
    99     iSCPropertyListener->IssueRequest();
   103 #endif
   100 #endif
       
   101     iHSFgStatusPropertyListener->IssueRequest();
   104     }
   102     }
   105     
   103     
   106 void CBgAnimHost::CreateWindowL()
   104 void CBgAnimHost::CreateWindowL()
   107     {
   105     {
   108     iScreenDevice = new (ELeave) CWsScreenDevice(iWsSession);
   106     iScreenDevice = new (ELeave) CWsScreenDevice(iWsSession);
   505         }
   503         }
   506     }
   504     }
   507     
   505     
   508 void CBgAnimHost::NewFrame()
   506 void CBgAnimHost::NewFrame()
   509     {
   507     {
   510     if (!iRunning)
   508     if (!iRunning && !iDoomBringer)
   511         {
   509         {
   512         // Stop and exit
   510         iDoomBringer = CHighResTimer::NewL(TCallBack(DoomBringerFunc, this),CActive::EPriorityStandard);
   513         CActiveScheduler::Stop();
   511         iDoomBringer->CallBack(5000);
   514         return;
   512         }
       
   513 		
       
   514     if (iRunning && iDoomBringer)
       
   515         {
       
   516         delete iDoomBringer;
       
   517         iDoomBringer = NULL;
   515         }
   518         }
   516     if (!iSurfaceInitialized)
   519     if (!iSurfaceInitialized)
   517         {
   520         {
   518         return;
   521         return;
   519         }
   522         }
   543     if (nextcallback < 1)
   546     if (nextcallback < 1)
   544         nextcallback = 1;
   547         nextcallback = 1;
   545     
   548     
   546     iTimer->CallBack(nextcallback);
   549     iTimer->CallBack(nextcallback);
   547     }
   550     }
   548     
   551 
       
   552 void CBgAnimHost::Kill()
       
   553     {
       
   554     if (!iRunning)
       
   555         {
       
   556         CActiveScheduler::Stop();
       
   557         }
       
   558     else
       
   559         {
       
   560         delete iDoomBringer;
       
   561         iDoomBringer = NULL;
       
   562         }
       
   563     
       
   564     return;
       
   565     }
       
   566     
       
   567 TInt CBgAnimHost::DoomBringerFunc(TAny* aPtr)
       
   568     {
       
   569     CBgAnimHost* me = (CBgAnimHost*)(aPtr);
       
   570     me->Kill();
       
   571     return ETrue;
       
   572     }
   549     
   573     
   550 TInt CBgAnimHost::TimerFunc(TAny* aPtr)
   574 TInt CBgAnimHost::TimerFunc(TAny* aPtr)
   551     {
   575     {
   552     CBgAnimHost* me = (CBgAnimHost*)(aPtr);
   576     CBgAnimHost* me = (CBgAnimHost*)(aPtr);
   553     me->NewFrame();
   577     me->NewFrame();
   554     return ETrue;
   578     return ETrue;
   555     }
   579     }
   556 
   580 
   557     
   581 TInt CBgAnimHost::ReaperFunc(TAny* aPtr)
       
   582     {
       
   583     CBgAnimHost* me = (CBgAnimHost*)(aPtr);
       
   584     me->CompositionTargetHidden();
       
   585     return ETrue;
       
   586     }
       
   587 
       
   588 
   558 void CBgAnimHost::ExecuteL() 
   589 void CBgAnimHost::ExecuteL() 
   559     {
   590     {
   560     // finally start our timer and scheduler...
   591     // finally start our timer and scheduler...
   561     iTimer->CallBack(100);
   592     iTimer->CallBack(100);
   562     iTimerRunning = ETrue;
   593     iTimerRunning = ETrue;
   604     StopSensors();
   635     StopSensors();
   605     }
   636     }
   606 
   637 
   607 void CBgAnimHost::CompositionTargetVisible()
   638 void CBgAnimHost::CompositionTargetVisible()
   608     {
   639     {
   609     if (iSurfaceInitialized || iHiddenDueSC)
   640     if (!iRunning && !iDoomBringer)
       
   641         {
       
   642         iDoomBringer = CHighResTimer::NewL(TCallBack(DoomBringerFunc, this),CActive::EPriorityStandard);
       
   643         iDoomBringer->CallBack(5000);
       
   644         }
       
   645 
       
   646     if (iSurfaceInitialized || iHiddenDueSC || iReaped)
   610         {
   647         {
   611         // don't bother if we are already in
   648         // don't bother if we are already in
   612         // a correct state, or if we are hidden by
   649         // a correct state, or if we are hidden by
   613         // the screensaver
   650         // the screensaver
   614         return;
   651         return;
   624     TRAPD(err,CreateWindowSurfaceL());
   661     TRAPD(err,CreateWindowSurfaceL());
   625     // reclaim gpu resources
   662     // reclaim gpu resources
   626     if (!err)
   663     if (!err)
   627         {
   664         {
   628         iPlugin->gpuresourcesavailable(1);
   665         iPlugin->gpuresourcesavailable(1);
       
   666         iPlugin->setfaded(iHSFgStatusPropertyListener->GetHSFGStatus());
   629         iTimer->CallBack(1);
   667         iTimer->CallBack(1);
   630         iTimerRunning = ETrue;
   668         iTimerRunning = ETrue;
   631         }
   669         }
   632     TRAP_IGNORE(StartSensorsL());
   670     TRAP_IGNORE(StartSensorsL());
   633     }
   671     }
   634 
   672 
   635 void CBgAnimHost::HandleScreenSaverEvent()
   673 void CBgAnimHost::HandleScreenSaverEvent()
   636     {
   674     {
   637 #if !defined(SYMBIAN_GRAPHICS_WSERV_QT_EFFECTS)
   675 #if !defined(SYMBIAN_GRAPHICS_WSERV_QT_EFFECTS)
   638     TInt scStatus = iSCPropertyListener->GetScreenSaverStatus();
   676     TInt scStatus = iSCPropertyListener->GetScreenSaverStatus();
       
   677     
   639     if (scStatus)
   678     if (scStatus)
   640         {
   679         {
   641         // screensaver is ON
   680         // screensaver is ON
   642         iHiddenDueSC = ETrue;
   681         iHiddenDueSC = ETrue;
   643         CompositionTargetHidden();
   682         CompositionTargetHidden();
   664     for (TInt count = 0; count < iSensorListeners.Count(); count++)
   703     for (TInt count = 0; count < iSensorListeners.Count(); count++)
   665         {
   704         {
   666         iSensorListeners[count]->StopListening();
   705         iSensorListeners[count]->StopListening();
   667         }
   706         }
   668     }
   707     }
       
   708 
       
   709 void CBgAnimHost::HandleFGAppEvent()
       
   710     {
       
   711     if (!iRunning && !iDoomBringer)
       
   712         {
       
   713         iDoomBringer = CHighResTimer::NewL(TCallBack(DoomBringerFunc, this),CActive::EPriorityStandard);
       
   714         iDoomBringer->CallBack(5000);
       
   715         }
       
   716 
       
   717     if (iPlugin && iPlugin->setfaded)
       
   718         {
       
   719         iPlugin->setfaded(iHSFgStatusPropertyListener->GetHSFGStatus());
       
   720         if (!iHSFgStatusPropertyListener->GetHSFGStatus())
       
   721             {
       
   722             // reap the anim in 5 seconds...
       
   723             // 5 seconds is probably just allright
       
   724             // to have enought time for the plugin to fade out...
       
   725             iReaped = ETrue;
       
   726             iTheReaper->CallBack(5000);
       
   727             }
       
   728         else
       
   729             {
       
   730             iReaped = EFalse;
       
   731             iTheReaper->Cancel();
       
   732             CompositionTargetVisible();
       
   733             }
       
   734         }
       
   735     }
       
   736 
   669 TInt CBgAnimHost::ScreenSaverCallback(TAny* aPtr)
   737 TInt CBgAnimHost::ScreenSaverCallback(TAny* aPtr)
   670     {
   738     {
   671     CBgAnimHost* me = (CBgAnimHost*) aPtr;
   739     CBgAnimHost* me = (CBgAnimHost*) aPtr;
   672     me->HandleScreenSaverEvent();
   740     me->HandleScreenSaverEvent();
       
   741     return EFalse;
       
   742     }
       
   743 
       
   744 TInt CBgAnimHost::FgAppCallback(TAny* aPtr)
       
   745     {
       
   746     CBgAnimHost* me = (CBgAnimHost*) aPtr;
       
   747     me->HandleFGAppEvent();
   673     return EFalse;
   748     return EFalse;
   674     }
   749     }
   675 
   750 
   676 void CBgAnimHost::DataReceived( CSensrvChannel& aChannel, TInt aCount, TInt aDataLost )
   751 void CBgAnimHost::DataReceived( CSensrvChannel& aChannel, TInt aCount, TInt aDataLost )
   677     {
   752     {