uiacceltk/hitchcock/coretoolkit/src/HuiFxEffect.cpp
branchRCL_3
changeset 8 46927d61fef3
parent 7 88b23e2e82e1
child 9 3ac8bf5c5014
equal deleted inserted replaced
7:88b23e2e82e1 8:46927d61fef3
    74 
    74 
    75 EXPORT_C CHuiFxEffect::~CHuiFxEffect()
    75 EXPORT_C CHuiFxEffect::~CHuiFxEffect()
    76     {
    76     {
    77     delete iRoot;
    77     delete iRoot;
    78     iRoot = NULL;
    78     iRoot = NULL;
    79     
       
    80     NotifyEffectEndObserver();
    79     NotifyEffectEndObserver();
    81     
    80     
    82     ReleaseCachedRenderTarget();
    81     ReleaseCachedRenderTarget();
    83     
    82     
    84     iEngine->RemoveEffect(this);
    83     iEngine->RemoveEffect(this);
    85     if (iEngine && iGroupId != KErrNotFound)
    84     if (iEngine && iGroupId != KErrNotFound && !iNotifiedEffectReady)
    86         {
    85         {
    87         // if effect was deleted before it was drawn, the group must be notified. If this was the last effect in the group
    86         // if effect was deleted before it was drawn, the group must be notified. If this was the last effect in the group
    88         // the group will be removed by the EffectReadyToStart
    87         // the group will be removed by the EffectReadyToStart
       
    88         // effect group does not not know, which effects have notified about themselves. thus iNotifiedEffectReady flag is used.
       
    89         iNotifiedEffectReady = ETrue;
    89         iEngine->NotifyEffectReady(iGroupId);
    90         iEngine->NotifyEffectReady(iGroupId);
    90         }
    91         }
    91     
    92     
    92 #ifdef HUIFX_TRACE    
    93 #ifdef HUIFX_TRACE    
    93     RDebug::Print(_L("CHuiFxEffect::~CHuiFxEffect - 0x%x"), this);
    94     RDebug::Print(_L("CHuiFxEffect::~CHuiFxEffect - 0x%x"), this);
    94 #endif
    95 #endif
    95     }
    96     }
    96 
    97 
    97 void CHuiFxEffect::NotifyEffectEndObserver()
    98 void CHuiFxEffect::NotifyEffectEndObserver()
    98     {
    99     {
    99     if ( iEffectEndObserver )
   100 	// fade effect should not have observers
       
   101     if (iFlags & KHuiFadeEffectFlag)
       
   102         {
       
   103         return;
       
   104         }
       
   105     if (iEffectEndObserver)
   100         {
   106         {
   101         // The callback can be called only once when the effect finishes
   107         // The callback can be called only once when the effect finishes
   102         iEffectEndObserver->AlfGfxEffectEndCallBack( iHandle );
   108         MAlfGfxEffectObserver* effectEndObserver = iEffectEndObserver;
   103         iEffectEndObserver = NULL;
   109         iEffectEndObserver = NULL;
   104         iHandle = 0;
   110         // Note: The call below may synchronously delete me (CHuiFxEffect instance)
       
   111         effectEndObserver->AlfGfxEffectEndCallBack( iHandle );
   105         }    
   112         }    
   106     }
   113     }
   107 
   114 
   108 EXPORT_C void CHuiFxEffect::AddLayerL(const CHuiFxLayer* aLayer)
   115 EXPORT_C void CHuiFxEffect::AddLayerL(const CHuiFxLayer* aLayer)
   109     {
   116     {
   441     }
   448     }
   442     
   449     
   443 EXPORT_C void CHuiFxEffect::SetEffectEndObserver( MAlfGfxEffectObserver* aEffectEndObserver, TInt aHandle )
   450 EXPORT_C void CHuiFxEffect::SetEffectEndObserver( MAlfGfxEffectObserver* aEffectEndObserver, TInt aHandle )
   444     {
   451     {
   445     iEffectEndObserver = aEffectEndObserver;
   452     iEffectEndObserver = aEffectEndObserver;
   446     iHandle = aHandle;
   453     
       
   454     if (aHandle != 0) // override handle only if someone is interested
       
   455         {
       
   456         iHandle = aHandle;
       
   457         }    
   447     }
   458     }
   448 
   459 
   449 EXPORT_C void CHuiFxEffect::SetEffectFlags( TInt aFlags )
   460 EXPORT_C void CHuiFxEffect::SetEffectFlags( TInt aFlags )
   450     {
   461     {
   451     iFlags = aFlags;
   462     iFlags = aFlags;
   452     }
   463     }
   453 
   464 
   454 void CHuiFxEffect::SetEffectFlag( TInt aFlag )
   465 void CHuiFxEffect::SetEffectFlag( TInt aFlag )
   455     {
   466     {
       
   467 #ifdef HUIFX_TRACE
       
   468     RDebug::Printf("CHuiFxEffect::SetEffectFlag - Setting flag 0x%x for 0x%x, before: iFlags: 0x%x", aFlag, this, iFlags);
       
   469 #endif
   456     iFlags |= aFlag;
   470     iFlags |= aFlag;
   457     }
   471     }
   458 
   472 
   459 void CHuiFxEffect::ClearEffectFlag( TInt aFlag )
   473 void CHuiFxEffect::ClearEffectFlag( TInt aFlag )
   460     {
   474     {
       
   475 #ifdef HUIFX_TRACE
       
   476     RDebug::Printf("CHuiFxEffect::ClearEffectFlag - Clearing flag 0x%x for 0x%x, before: iFlags: 0x%x", aFlag, this, iFlags);
       
   477 #endif    
   461     iFlags &= ~aFlag;
   478     iFlags &= ~aFlag;
   462     }
   479     }
   463 
   480 
   464 EXPORT_C void CHuiFxEffect::SetEffectGroup(TInt aGroupId)
   481 EXPORT_C void CHuiFxEffect::SetEffectGroup(TInt aGroupId)
   465     {
   482     {
   476     return iGroupId;
   493     return iGroupId;
   477     }
   494     }
   478 
   495 
   479 EXPORT_C void CHuiFxEffect::AdvanceTime(TReal32 aElapsedTime)
   496 EXPORT_C void CHuiFxEffect::AdvanceTime(TReal32 aElapsedTime)
   480     {
   497     {
       
   498 #ifdef HUIFX_TRACE
       
   499     RDebug::Printf("CHuiFxEffect::AdvanceTime 0x%x, aElapsed time: %f, Total elapsed time: %f, Frames drawn: %d, iFlags: 0x%x, iGroup %d, iHandle: %d", 
       
   500             this, 
       
   501             aElapsedTime, 
       
   502             iElapsedTime, 
       
   503             iFramesDrawn, 
       
   504             iFlags,
       
   505             iGroupId,
       
   506             iHandle);
       
   507 #endif
       
   508     // KHuiFxDelayRunUntilFirstFrameHasBeenDrawn flag is for giving effect chance to run
       
   509     // its whole timeline by starting the time only when first frame has been drawn.
       
   510     iElapsedTime += aElapsedTime;
   481     if (iFlags & KHuiFxDelayRunUntilFirstFrameHasBeenDrawn)
   511     if (iFlags & KHuiFxDelayRunUntilFirstFrameHasBeenDrawn)
   482         {
   512         {
       
   513         // Sometimes the effect does not get any frames. Force the time to start, because
       
   514         // otherwise will jam itself and possible the group, where the effect is.
       
   515         if (iElapsedTime > 0.2 && iFramesDrawn == 0)
       
   516             {
       
   517             iFramesDrawn = 1;
       
   518 #ifdef HUIFX_TRACE            
       
   519             RDebug::Printf("CHuiFxEffect::AdvanceTime - Not drawn, but cannot wait. release 0x%x in time %f", this, iElapsedTime);
       
   520 #endif
       
   521             }
       
   522         
   483         if (iFramesDrawn)
   523         if (iFramesDrawn)
   484             { 
   524             { 
   485             if (iFlags & KHuiFxReadyAndWaitingGroupToStartSyncronized)
   525             if (iFlags & KHuiFxReadyAndWaitingGroupToStartSyncronized)
   486                 {
   526                 {
   487 	            // this has drawn atleast once, but all the effect in this group have not drawn. Must hang on little more.
   527 	            // this has drawn atleast once, but all the effect in this group have not drawn. Must hang on little more.
   489                 }
   529                 }
   490         
   530         
   491             if (iFlags & KHuiFxWaitGroupToStartSyncronized)
   531             if (iFlags & KHuiFxWaitGroupToStartSyncronized)
   492                 {
   532                 {
   493 				// Group has been started, waiting the others in the group to be drawn
   533 				// Group has been started, waiting the others in the group to be drawn
       
   534                 ClearEffectFlag(KHuiFxWaitGroupToStartSyncronized);
   494                 SetEffectFlag(KHuiFxReadyAndWaitingGroupToStartSyncronized);
   535                 SetEffectFlag(KHuiFxReadyAndWaitingGroupToStartSyncronized);
   495                 ClearEffectFlag(KHuiFxWaitGroupToStartSyncronized);
       
   496 				// NotifyEffectReady will clear KHuiFxReadyAndWaitingGroupToStartSyncronized flag
   536 				// NotifyEffectReady will clear KHuiFxReadyAndWaitingGroupToStartSyncronized flag
   497 				// if all items in the group are ready.
   537 				// if all items in the group are ready.
   498                 iEngine->NotifyEffectReady(iGroupId);
   538                 iEngine->NotifyEffectReady(iGroupId);
       
   539                 iNotifiedEffectReady = ETrue;
   499                 return;
   540                 return;
   500                 }
   541                 }
   501 
   542 
   502             if (iFramesDrawn == 1)
   543             if (iFramesDrawn == 1)
   503                 {
   544                 {
   504                 aElapsedTime = 0;
   545                 aElapsedTime = 0;
   505                 iFramesDrawn++;
   546                 iFramesDrawn++;
   506                 }
   547                 }
   507             
       
   508                 iRoot->AdvanceTime(aElapsedTime);
   548                 iRoot->AdvanceTime(aElapsedTime);
   509             }
   549             }
   510         }
   550         }
   511     else
   551     else
   512         {
   552         {