uiacceltk/hitchcock/backgroundanim/src/bganimhost.cpp
branchRCL_3
changeset 8 10534483575f
parent 7 433cbbb6a04b
child 11 46927d61fef3
equal deleted inserted replaced
7:433cbbb6a04b 8:10534483575f
    14 * Description: 
    14 * Description: 
    15 *
    15 *
    16 */
    16 */
    17 #include <stdio.h>
    17 #include <stdio.h>
    18 #include <stdlib.h>
    18 #include <stdlib.h>
    19 #include <AknsSrvClient.h>
       
    20 #include <AknsSrvChunkLookup.h>
    19 #include <AknsSrvChunkLookup.h>
    21 #include <AknsConstants.h>
    20 #include <AknsConstants.h>
    22 #include <AknsItemDef.h>
    21 #include <AknsItemDef.h>
    23 
    22 
    24 #include "bganimhost.h"
    23 #include "bganimhost.h"
    36     {
    35     {
    37     }
    36     }
    38     
    37     
    39 CBgAnimHost::~CBgAnimHost() 
    38 CBgAnimHost::~CBgAnimHost() 
    40     {
    39     {
       
    40     iSkinSrv.Close();
       
    41     delete iCurrentPluginDllName;
       
    42     delete iCurrentPluginAssetDir;
    41     delete iTimer;
    43     delete iTimer;
    42     if (iPlugin)
    44     if (iPlugin)
    43         {
    45         {
    44         iPlugin->destroy();
    46         iPlugin->destroy();
    45         free(iPlugin);
    47         free(iPlugin);
    46         }
    48         }
    47     iPluginLibrary.Close();
    49     iPluginLibrary.Close();
       
    50 #if !defined(SYMBIAN_GRAPHICS_WSERV_QT_EFFECTS)
    48     delete iSCPropertyListener;
    51     delete iSCPropertyListener;
       
    52 #endif
    49     delete iThemeRepositoryListener;
    53     delete iThemeRepositoryListener;
    50     while (iSensorListeners.Count())
    54     while (iSensorListeners.Count())
    51         {
    55         {
    52         delete iSensorListeners[0];
    56         delete iSensorListeners[0];
    53         iSensorListeners.Remove(0);
    57         iSensorListeners.Remove(0);
    77         
    81         
    78     CActiveScheduler *ac = new (ELeave) CActiveScheduler;
    82     CActiveScheduler *ac = new (ELeave) CActiveScheduler;
    79     CActiveScheduler::Install(ac);
    83     CActiveScheduler::Install(ac);
    80     iTimer = CHighResTimer::NewL(TCallBack(TimerFunc, this),CActive::EPriorityStandard);
    84     iTimer = CHighResTimer::NewL(TCallBack(TimerFunc, this),CActive::EPriorityStandard);
    81     iThemeRepositoryListener = CThemeRepositoryListener::NewL(&iRunning);
    85     iThemeRepositoryListener = CThemeRepositoryListener::NewL(&iRunning);
       
    86 #if !defined(SYMBIAN_GRAPHICS_WSERV_QT_EFFECTS)
    82     iSCPropertyListener = CScreenSaverPropertyListener::NewL(TCallBack(ScreenSaverCallback, this));
    87     iSCPropertyListener = CScreenSaverPropertyListener::NewL(TCallBack(ScreenSaverCallback, this));
       
    88 #endif
    83     
    89     
    84     CreateWindowL();
    90     CreateWindowL();
    85 
    91 
       
    92     User::LeaveIfError(iSkinSrv.Connect());
    86     // load the initial plugin
    93     // load the initial plugin
       
    94     GetPluginConfigurationL();
    87     LoadPluginL();
    95     LoadPluginL();
    88     InitEGLL();
    96     InitEGLL();
    89     CreateWindowSurfaceL();
    97     CreateWindowSurfaceL();
    90     
    98     
    91     User::LeaveIfError(iPlugin->gpuresourcesavailable(1));
    99     User::LeaveIfError(iPlugin->gpuresourcesavailable(1));
    92     iThemeRepositoryListener->IssueRequest();
   100     iThemeRepositoryListener->IssueRequest();
       
   101 #if !defined(SYMBIAN_GRAPHICS_WSERV_QT_EFFECTS)    
    93     iSCPropertyListener->IssueRequest();
   102     iSCPropertyListener->IssueRequest();
       
   103 #endif
    94     }
   104     }
    95     
   105     
    96 void CBgAnimHost::CreateWindowL()
   106 void CBgAnimHost::CreateWindowL()
    97     {
   107     {
    98     iScreenDevice = new (ELeave) CWsScreenDevice(iWsSession);
   108     iScreenDevice = new (ELeave) CWsScreenDevice(iWsSession);
   183         eglMakeCurrent( iEGLDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );
   193         eglMakeCurrent( iEGLDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );
   184         iWsSession.Flush();
   194         iWsSession.Flush();
   185         
   195         
   186         iSurfaceInitialized = EFalse;
   196         iSurfaceInitialized = EFalse;
   187         
   197         
   188         if (aReleaseObserver)
   198         if (aReleaseObserver && iCompSource)
   189             {
   199             {
   190             iCompSource->RemoveObserver(*this);
   200             iCompSource->RemoveObserver(*this);
   191             delete iCompSource;
   201             delete iCompSource;
   192             iCompSource = NULL;
   202             iCompSource = NULL;
   193             }
   203             }
   383             iCompSource->SetExtent(TRect(TPoint(0,0),iRealDisplaySize),0);
   393             iCompSource->SetExtent(TRect(TPoint(0,0),iRealDisplaySize),0);
   384             break;
   394             break;
   385             }
   395             }
   386         else
   396         else
   387             {
   397             {
   388             User::After(5000000);
   398             User::After(1000000);
   389             }
   399             }
   390         }
   400         }
   391 
   401 
   392     iSurfaceInitialized = ETrue;
   402     iSurfaceInitialized = ETrue;
   393     
   403     
   394     }
   404     }
   395     
   405 
   396 void CBgAnimHost::LoadPluginL()
   406 TBool CBgAnimHost::GetPluginConfigurationL()
   397     {
   407     {
   398     // dig out the skin config from skin server
   408     // dig out the skin config from skin server
   399     HBufC* configstr = NULL;
   409     HBufC* configstr = NULL;
   400     RAknsSrvSession skinsrv;
   410     CAknsSrvChunkLookup* cl = iSkinSrv.CreateChunkLookupL();
   401     User::LeaveIfError(skinsrv.Connect());
       
   402     CleanupClosePushL(skinsrv);
       
   403     CAknsSrvChunkLookup* cl = skinsrv.CreateChunkLookupL();
       
   404     CleanupStack::PushL(cl);
   411     CleanupStack::PushL(cl);
   405     CAknsStringItemDef* configitem = static_cast<CAknsStringItemDef*>(cl->LookupAndCreateDefL( KAknsIIDPropertyAnimBgParam )); 
   412     CAknsStringItemDef* configitem = static_cast<CAknsStringItemDef*>(cl->LookupAndCreateDefL( KAknsIIDPropertyAnimBgParam )); 
   406     User::LeaveIfNull(configitem);
   413     User::LeaveIfNull(configitem);
   407     CleanupStack::PushL(configitem);
   414     CleanupStack::PushL(configitem);
   408     configstr = configitem->String().AllocL();
   415     configstr = configitem->String().AllocL();
   409     CleanupStack::PopAndDestroy(3); // skinsrv, cl, configitem
   416     CleanupStack::PopAndDestroy(2); // cl, configitem
   410     CleanupStack::PushL(configstr);
   417     CleanupStack::PushL(configstr);
   411     RDebug::Print(_L("----------------------"));
       
   412     RDebug::Print(_L("backgroundhost config:"));
       
   413     RDebug::Print(*configstr);
       
   414     RDebug::Print(_L("----------------------"));
       
   415     
   418     
   416     TLex lex(*configstr);
   419     TLex lex(*configstr);
   417     TPtrC dllname = lex.NextToken();
   420     HBufC* dllname = lex.NextToken().AllocL();
   418     if (!dllname.Length())
   421     CleanupStack::PushL(dllname);
       
   422     if (!dllname || !dllname->Length())
   419         {
   423         {
   420         User::Leave(KErrNotFound);
   424         User::Leave(KErrNotFound);
   421         }
   425         }
   422     
   426 
   423     User::LeaveIfError(iPluginLibrary.Load(dllname));
   427     HBufC* assetdir = lex.NextToken().AllocL();
       
   428     CleanupStack::PushL(assetdir);
       
   429     if (!assetdir || !assetdir->Length())
       
   430         {
       
   431         User::Leave(KErrNotFound);
       
   432         }
       
   433     
       
   434     TBool confchanged = EFalse;
       
   435     if (!iCurrentPluginDllName || !iCurrentPluginAssetDir || 
       
   436         (iCurrentPluginDllName && !iCurrentPluginDllName->CompareF(*dllname)) ||
       
   437         (iCurrentPluginAssetDir && !iCurrentPluginAssetDir->CompareF(*assetdir)) )
       
   438         
       
   439         {
       
   440         confchanged = ETrue;
       
   441         delete iCurrentPluginDllName;
       
   442         delete iCurrentPluginAssetDir;
       
   443         iCurrentPluginDllName = dllname;    
       
   444         iCurrentPluginAssetDir = assetdir;
       
   445         CleanupStack::Pop(2); // dllname, assetdir
       
   446         }
       
   447     else
       
   448         {
       
   449         CleanupStack::PopAndDestroy(2); // dllname, assetdir
       
   450         }
       
   451         
       
   452     CleanupStack::PopAndDestroy(); // configstr
       
   453     
       
   454     return confchanged;
       
   455     }
       
   456     
       
   457 void CBgAnimHost::LoadPluginL()
       
   458     {
       
   459     User::LeaveIfError(iPluginLibrary.Load(*iCurrentPluginDllName));
   424     plugingetinterfacefunc getif = (plugingetinterfacefunc)iPluginLibrary.Lookup(1);
   460     plugingetinterfacefunc getif = (plugingetinterfacefunc)iPluginLibrary.Lookup(1);
   425     if (!getif)
   461     if (!getif)
   426         {
   462         {
   427         iPluginLibrary.Close();
   463         iPluginLibrary.Close();
   428         User::Leave(KErrNotFound);
   464         User::Leave(KErrNotFound);
   429         }
   465         }
   430     
   466     
   431     iPlugin = (plugin_export_v1_t*) getif(1);
   467     iPlugin = (plugin_export_v1_t*) getif(1);
   432 
   468 
   433     TPtrC configpath = lex.NextToken();
       
   434     if (!configpath.Length())
       
   435         {
       
   436         User::Leave(KErrNotFound);
       
   437         }
       
   438     TBuf8<256> pluginpath;
   469     TBuf8<256> pluginpath;
   439     pluginpath.Copy(configpath);
   470     pluginpath.Copy(*iCurrentPluginAssetDir);
   440     User::LeaveIfError(iPlugin->initialize((const char*)pluginpath.PtrZ(), KMaxGPUMemUsage));
   471     User::LeaveIfError(iPlugin->initialize((const char*)pluginpath.PtrZ(), KMaxGPUMemUsage));
   441 
   472    
   442 //        }
       
   443 //    else
       
   444 //        {
       
   445 //        User::LeaveIfError(iPlugin->initialize("z:\\private\\200286D3", KMaxGPUMemUsage));
       
   446 //        }
       
   447 
       
   448     CleanupStack::PopAndDestroy(); // configstr
       
   449     
       
   450     iPlugin->setdisplaydimensions(iDisplaySize.iWidth, iDisplaySize.iHeight);
   473     iPlugin->setdisplaydimensions(iDisplaySize.iWidth, iDisplaySize.iHeight);
   451     if (iPlugin->desiredsensors && iPlugin->receivesensordata)
   474     if (iPlugin->desiredsensors && iPlugin->receivesensordata)
   452         {
   475         {
   453         const unsigned int* sensors = iPlugin->desiredsensors();
   476         const unsigned int* sensors = iPlugin->desiredsensors();
   454         while (*sensors)
   477         while (*sensors)
   458             if (!serr)
   481             if (!serr)
   459                 {
   482                 {
   460                 iSensorListeners.Append(listener);
   483                 iSensorListeners.Append(listener);
   461                 }
   484                 }
   462             }
   485             }
       
   486         }
       
   487     }
       
   488     
       
   489 void CBgAnimHost::ReleasePlugin()
       
   490     {
       
   491     if (iPlugin)
       
   492         {
       
   493         while (iSensorListeners.Count())
       
   494             {
       
   495             delete iSensorListeners[0];
       
   496             iSensorListeners.Remove(0);
       
   497             }
       
   498             
       
   499         iPlugin->gpuresourcesavailable(0);
       
   500         iPlugin->destroy();
       
   501         free(iPlugin);
       
   502         iPlugin = NULL;
       
   503         iPluginLibrary.Close();
   463         }
   504         }
   464     }
   505     }
   465     
   506     
   466 void CBgAnimHost::NewFrame()
   507 void CBgAnimHost::NewFrame()
   467     {
   508     {
   504     {
   545     {
   505     // finally start our timer and scheduler...
   546     // finally start our timer and scheduler...
   506     iTimer->CallBack(100);
   547     iTimer->CallBack(100);
   507     iTimerRunning = ETrue;
   548     iTimerRunning = ETrue;
   508     iRunning = ETrue;
   549     iRunning = ETrue;
       
   550     // we only want to receive skin change messages
       
   551     // after we have been properly initialized
       
   552     // and running, close the session without observer
       
   553     // and re-open with observer
       
   554     iSkinSrv.Close();
       
   555     User::LeaveIfError(iSkinSrv.Connect(this));
   509     CActiveScheduler::Start();
   556     CActiveScheduler::Start();
   510     }
   557     }
   511 
   558 
   512 void CBgAnimHost::FrameReady(TInt /*aScreenNumber*/)
   559 void CBgAnimHost::FrameReady(TInt /*aScreenNumber*/)
   513     {
   560     {
   533         // don't bother if we are already in
   580         // don't bother if we are already in
   534         // a correct state..
   581         // a correct state..
   535         return;
   582         return;
   536         }
   583         }
   537 
   584 
   538     RDebug::Print(_L("!!! - HIDDEN - !!!"));
       
   539     // release gpu resources...
   585     // release gpu resources...
   540     iTimer->Cancel();
   586     iTimer->Cancel();
   541     iTimerRunning = EFalse;
   587     iTimerRunning = EFalse;
   542     iPlugin->gpuresourcesavailable(0);
   588     iPlugin->gpuresourcesavailable(0);
   543     ReleaseWindowSurface(EFalse);
   589     ReleaseWindowSurface(EFalse);
   550         // don't bother if we are already in
   596         // don't bother if we are already in
   551         // a correct state..
   597         // a correct state..
   552         return;
   598         return;
   553         }
   599         }
   554 
   600 
   555     RDebug::Print(_L("!!! - VISIBLE - !!!"));
       
   556 
       
   557     if (!iSurfaceInitialized && iCompSource)
   601     if (!iSurfaceInitialized && iCompSource)
   558         {
   602         {
   559         iCompSource->RemoveObserver(*this);
   603         iCompSource->RemoveObserver(*this);
   560         delete iCompSource;
   604         delete iCompSource;
   561         iCompSource = NULL;            
   605         iCompSource = NULL;            
   571         }
   615         }
   572     }
   616     }
   573 
   617 
   574 void CBgAnimHost::HandleScreenSaverEvent()
   618 void CBgAnimHost::HandleScreenSaverEvent()
   575     {
   619     {
   576     RDebug::Print(_L("-----------------------------------"));
   620 #if !defined(SYMBIAN_GRAPHICS_WSERV_QT_EFFECTS)
   577     RDebug::Print(_L("CBgAnimHost::HandleScreenSaverEvent"));
       
   578     TInt scStatus = iSCPropertyListener->GetScreenSaverStatus();
   621     TInt scStatus = iSCPropertyListener->GetScreenSaverStatus();
   579     RDebug::Print(_L("status: %d, timerrunning %d, surfacecreated %d"),scStatus, iTimerRunning, iSurfaceInitialized);
       
   580     RDebug::Print(_L("-----------------------------------"));
       
   581     if (scStatus)
   622     if (scStatus)
   582         {
   623         {
   583         // screensaver is ON
   624         // screensaver is ON
   584         if (iTimerRunning)
   625         if (iTimerRunning)
   585             {
   626             {
   586             RDebug::Print(_L("--- screensaver on, stopping timer ---"));
       
   587             iTimer->Cancel();
   627             iTimer->Cancel();
   588             iTimerRunning = EFalse;
   628             iTimerRunning = EFalse;
   589             }
   629             }
   590         }
   630         }
   591     else
   631     else
   592         {
   632         {
   593         // screensaver is OFF
   633         // screensaver is OFF
   594         if (!iTimerRunning && iSurfaceInitialized)
   634         if (!iTimerRunning && iSurfaceInitialized)
   595             {
   635             {
   596             RDebug::Print(_L("--- screensaver off, starting timer ---"));
       
   597     
       
   598             iTimerRunning = ETrue;
   636             iTimerRunning = ETrue;
   599             iTimer->CallBack(1);
   637             iTimer->CallBack(1);
   600             }
   638             }
   601         }
   639         }
       
   640 #endif
   602     }
   641     }
   603 
   642 
   604 TInt CBgAnimHost::ScreenSaverCallback(TAny* aPtr)
   643 TInt CBgAnimHost::ScreenSaverCallback(TAny* aPtr)
   605     {
   644     {
   606     CBgAnimHost* me = (CBgAnimHost*) aPtr;
   645     CBgAnimHost* me = (CBgAnimHost*) aPtr;
   621     }
   660     }
   622 
   661 
   623 void CBgAnimHost::GetDataListenerInterfaceL( TUid aInterfaceUid, TAny*& aInterface)
   662 void CBgAnimHost::GetDataListenerInterfaceL( TUid aInterfaceUid, TAny*& aInterface)
   624     {
   663     {
   625     }
   664     }
       
   665 
       
   666 void CBgAnimHost::SkinContentChanged()
       
   667     {
       
   668     }
       
   669 
       
   670 void CBgAnimHost::SkinConfigurationChanged( const TAknsSkinStatusConfigurationChangeReason aReason )
       
   671     {
       
   672     if (aReason == EAknsSkinStatusConfigurationDeployed && iPlugin)
       
   673         {
       
   674         // okay, the skin has changed, let's check that should we load a different
       
   675         // animation plugin
       
   676         TBool changed = EFalse;
       
   677         TRAPD(err, changed = GetPluginConfigurationL());
       
   678         if (err || !changed)
       
   679             {
       
   680             // plugin configuration has not changed, or there is not animation
       
   681             // in the theme, just return
       
   682             return;
       
   683             }
       
   684 
       
   685         CompositionTargetHidden();
       
   686         ReleasePlugin();
       
   687                 
       
   688         TRAP_IGNORE(LoadPluginL());
       
   689         CompositionTargetVisible();
       
   690         }
       
   691     }
       
   692 
       
   693 void CBgAnimHost::SkinPackageChanged( const TAknsSkinStatusPackageChangeReason /*aReason*/ )
       
   694     {
       
   695     }