uiacceltk/hitchcock/coretoolkit/src/HuiFxEffect.cpp
branchRCL_3
changeset 11 46927d61fef3
parent 10 88b23e2e82e1
child 17 3ac8bf5c5014
--- a/uiacceltk/hitchcock/coretoolkit/src/HuiFxEffect.cpp	Wed Mar 31 23:03:58 2010 +0300
+++ b/uiacceltk/hitchcock/coretoolkit/src/HuiFxEffect.cpp	Wed Apr 14 16:53:50 2010 +0300
@@ -76,16 +76,17 @@
     {
     delete iRoot;
     iRoot = NULL;
-    
     NotifyEffectEndObserver();
     
     ReleaseCachedRenderTarget();
     
     iEngine->RemoveEffect(this);
-    if (iEngine && iGroupId != KErrNotFound)
+    if (iEngine && iGroupId != KErrNotFound && !iNotifiedEffectReady)
         {
         // if effect was deleted before it was drawn, the group must be notified. If this was the last effect in the group
         // the group will be removed by the EffectReadyToStart
+        // effect group does not not know, which effects have notified about themselves. thus iNotifiedEffectReady flag is used.
+        iNotifiedEffectReady = ETrue;
         iEngine->NotifyEffectReady(iGroupId);
         }
     
@@ -96,12 +97,18 @@
 
 void CHuiFxEffect::NotifyEffectEndObserver()
     {
-    if ( iEffectEndObserver )
+	// fade effect should not have observers
+    if (iFlags & KHuiFadeEffectFlag)
+        {
+        return;
+        }
+    if (iEffectEndObserver)
         {
         // The callback can be called only once when the effect finishes
-        iEffectEndObserver->AlfGfxEffectEndCallBack( iHandle );
+        MAlfGfxEffectObserver* effectEndObserver = iEffectEndObserver;
         iEffectEndObserver = NULL;
-        iHandle = 0;
+        // Note: The call below may synchronously delete me (CHuiFxEffect instance)
+        effectEndObserver->AlfGfxEffectEndCallBack( iHandle );
         }    
     }
 
@@ -443,7 +450,11 @@
 EXPORT_C void CHuiFxEffect::SetEffectEndObserver( MAlfGfxEffectObserver* aEffectEndObserver, TInt aHandle )
     {
     iEffectEndObserver = aEffectEndObserver;
-    iHandle = aHandle;
+    
+    if (aHandle != 0) // override handle only if someone is interested
+        {
+        iHandle = aHandle;
+        }    
     }
 
 EXPORT_C void CHuiFxEffect::SetEffectFlags( TInt aFlags )
@@ -453,11 +464,17 @@
 
 void CHuiFxEffect::SetEffectFlag( TInt aFlag )
     {
+#ifdef HUIFX_TRACE
+    RDebug::Printf("CHuiFxEffect::SetEffectFlag - Setting flag 0x%x for 0x%x, before: iFlags: 0x%x", aFlag, this, iFlags);
+#endif
     iFlags |= aFlag;
     }
 
 void CHuiFxEffect::ClearEffectFlag( TInt aFlag )
     {
+#ifdef HUIFX_TRACE
+    RDebug::Printf("CHuiFxEffect::ClearEffectFlag - Clearing flag 0x%x for 0x%x, before: iFlags: 0x%x", aFlag, this, iFlags);
+#endif    
     iFlags &= ~aFlag;
     }
 
@@ -478,8 +495,31 @@
 
 EXPORT_C void CHuiFxEffect::AdvanceTime(TReal32 aElapsedTime)
     {
+#ifdef HUIFX_TRACE
+    RDebug::Printf("CHuiFxEffect::AdvanceTime 0x%x, aElapsed time: %f, Total elapsed time: %f, Frames drawn: %d, iFlags: 0x%x, iGroup %d, iHandle: %d", 
+            this, 
+            aElapsedTime, 
+            iElapsedTime, 
+            iFramesDrawn, 
+            iFlags,
+            iGroupId,
+            iHandle);
+#endif
+    // KHuiFxDelayRunUntilFirstFrameHasBeenDrawn flag is for giving effect chance to run
+    // its whole timeline by starting the time only when first frame has been drawn.
+    iElapsedTime += aElapsedTime;
     if (iFlags & KHuiFxDelayRunUntilFirstFrameHasBeenDrawn)
         {
+        // Sometimes the effect does not get any frames. Force the time to start, because
+        // otherwise will jam itself and possible the group, where the effect is.
+        if (iElapsedTime > 0.2 && iFramesDrawn == 0)
+            {
+            iFramesDrawn = 1;
+#ifdef HUIFX_TRACE            
+            RDebug::Printf("CHuiFxEffect::AdvanceTime - Not drawn, but cannot wait. release 0x%x in time %f", this, iElapsedTime);
+#endif
+            }
+        
         if (iFramesDrawn)
             { 
             if (iFlags & KHuiFxReadyAndWaitingGroupToStartSyncronized)
@@ -491,11 +531,12 @@
             if (iFlags & KHuiFxWaitGroupToStartSyncronized)
                 {
 				// Group has been started, waiting the others in the group to be drawn
+                ClearEffectFlag(KHuiFxWaitGroupToStartSyncronized);
                 SetEffectFlag(KHuiFxReadyAndWaitingGroupToStartSyncronized);
-                ClearEffectFlag(KHuiFxWaitGroupToStartSyncronized);
 				// NotifyEffectReady will clear KHuiFxReadyAndWaitingGroupToStartSyncronized flag
 				// if all items in the group are ready.
                 iEngine->NotifyEffectReady(iGroupId);
+                iNotifiedEffectReady = ETrue;
                 return;
                 }
 
@@ -504,7 +545,6 @@
                 aElapsedTime = 0;
                 iFramesDrawn++;
                 }
-            
                 iRoot->AdvanceTime(aElapsedTime);
             }
         }