uiacceltk/hitchcock/coretoolkit/src/HuiFxEffect.cpp
branchRCL_3
changeset 19 e5af45d51884
parent 18 1801340c26a2
child 20 31fccae4f8a7
--- a/uiacceltk/hitchcock/coretoolkit/src/HuiFxEffect.cpp	Thu Aug 19 10:48:02 2010 +0300
+++ b/uiacceltk/hitchcock/coretoolkit/src/HuiFxEffect.cpp	Tue Aug 31 16:07:35 2010 +0300
@@ -66,7 +66,6 @@
     }
 EXPORT_C void CHuiFxEffect::SetVisual( MHuiEffectable *aEffectable )
     {
-    iEffectable = aEffectable;
     iRoot->SetVisual(aEffectable);
     }
 EXPORT_C void CHuiFxEffect::SetEngine( CHuiFxEngine *aEngine )
@@ -85,11 +84,12 @@
 
 EXPORT_C CHuiFxEffect::~CHuiFxEffect()
     {
-    ReleaseCachedRenderTarget();
-    
     delete iRoot;
     iRoot = NULL;
     NotifyEffectEndObserver();
+    
+    ReleaseCachedRenderTarget();
+    
     iEngine->RemoveEffect(this);
     if (iEngine && iGroupId != KErrNotFound && !(iFlags & KHuiReadyToDrawNotified))
         {
@@ -180,11 +180,6 @@
         iEngine->ReleaseRenderbuffer(iCachedRenderTarget);
         iCachedRenderTarget = NULL;
         }                
-    
-    if(iRoot)
-        {
-        iRoot->ReleaseAllCachedRenderTargets(*iEngine);
-        }
     }
 
 void CHuiFxEffect::PrepareCachedRenderTarget(const TPoint& aPosition, const TSize& aSize, TBool aClear, TBool aEnableBackground)
@@ -193,8 +188,7 @@
     if (iCachedRenderTarget && 
         iCachedRenderTarget->Size() != aSize)
         {
-        iEngine->ReleaseRenderbuffer(iCachedRenderTarget);
-        iCachedRenderTarget = NULL;
+        ReleaseCachedRenderTarget();
         }            
     
     // Accure new buffer
@@ -264,56 +258,6 @@
         }
     }
 
-TBool CHuiFxEffect::PrepareDrawL(CHuiGc& aGc, const TRect& aDisplayRect)
-    {
-    if(!iEffectable || iEffectable->EffectReadyToDrawNextFrame() )
-         {
-         iFramesDrawn++;
-         }
-
-    // Prepare all layers
-    TRect displayArea = aGc.DisplayArea();
-    TRect targetArea = aDisplayRect;
-    targetArea.Intersection(displayArea);
-
-    if (targetArea.Width() <= 0 || targetArea.Height() <= 0)
-        {
-        // Not visible
-        return ETrue;
-        }
-    
-    if (!iEngine || !iRoot)
-        {
-        return EFalse;
-        }
-
-    if (iEngine->LowMemoryState())
-        {
-        // No memory, no effects.
-        return EFalse;
-        }
-    
-    // Check if margins are allowed to be used for this effect
-    if (EffectFlags() & KHuiFxEffectDisableMarginsFlag)
-        {
-        iRoot->EnableMargin(EFalse);
-        }
-
-    
-    iRoot->SetTargetRect(targetArea);
-    iRoot->SetSourceRect(targetArea);        
-    iRoot->SetDisplayArea(displayArea);
-    
-    TRAPD(err, iRoot->PrepareDrawL(*iEngine));
-    
-    if (err != KErrNone)
-        {
-        return EFalse;
-        }
-
-    return ETrue;
-    }
-
 TBool CHuiFxEffect::CachedDraw(CHuiGc& aGc, const TRect& aDisplayRect, TBool aRefreshCachedRenderTarget, TBool aOpaque)
     {
     RRegion dummy;
@@ -328,11 +272,12 @@
 #ifdef HUIFX_TRACE    
     RDebug::Print(_L("CHuiFxEffect::CachedDraw - 0x%x"), this);
 #endif    
-
+    iFramesDrawn++;
     if (!CHuiStatic::Renderer().Allows(EHuiRenderPluginAllowVisualPBufferSurfaces))
         {
         return EFalse;
         }
+            
     
     CHuiFxRenderbuffer* target = NULL;
     
@@ -358,14 +303,29 @@
         return EFalse;
         }
     
+    // Check if margins are allowed to be used for this effect
+    if (EffectFlags() & KHuiFxEffectDisableMarginsFlag)
+        {
+        iRoot->EnableMargin(EFalse);
+        }
+
     // Check if surface pixels are to be used for this effect in all layers.
     if (EffectFlags() & KHuiFxEnableBackgroundInAllLayers)
         {
         iRoot->SetAlwaysReadSurfacePixels(ETrue);
-        } 
+        }
+    
+    iRoot->SetTargetRect(targetArea);
+    iRoot->SetSourceRect(targetArea);        
+    iRoot->SetDisplayArea(displayArea);
+    
+    TRAPD(err, iRoot->PrepareDrawL(*iEngine));
+    
+    if (err != KErrNone)
+        {
+        return EFalse;
+        }
 
-    iRoot->SetVisualContentState(aRefreshCachedRenderTarget, aOpaque);
-    
     if (IsCachedRenderTargetSupported() && IsCachedRenderTargetPreferred())
         {
         // Background needs to be captured from surface if effect uses background AND 
@@ -446,11 +406,7 @@
     else
         {
         // Release cached render target just in case it is reserved for some reason
-        if (iCachedRenderTarget)
-            {
-            iEngine->ReleaseRenderbuffer(iCachedRenderTarget);
-            iCachedRenderTarget = NULL;
-            }  
+        ReleaseCachedRenderTarget();
 
         // Use default onscreen render target
         if (!target)
@@ -466,6 +422,7 @@
         // Normal drawing
         iRoot->Draw(*iEngine, aGc, *target, *target, aHasSurface);
         }
+                
     return ETrue;    
     }
 
@@ -475,6 +432,7 @@
 #ifdef HUIFX_TRACE    
     RDebug::Print(_L("CHuiFxEffect::Draw - 0x%x"), this);
 #endif
+    iFramesDrawn++;
     if (!CHuiStatic::Renderer().Allows(EHuiRenderPluginAllowVisualPBufferSurfaces))
         {
         return EFalse;
@@ -526,8 +484,6 @@
         }
 
     iRoot->Draw(*iEngine, aGc, *target, *target, aHasSurface);
-
-
     return ETrue;
     }
 
@@ -609,13 +565,13 @@
     // its whole timeline by starting the time only when first frame has been drawn.
     if (iFlags & KHuiFxDelayRunUntilFirstFrameHasBeenDrawn)
         {
-        // This is a backup timer. If effect won't start before this 10sec wait there must be something wrong
-		// Force effect to start after 10seconds
-		if (iElapsedTime > 10.0 && iFramesDrawn == 0)
+        // 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 in 10sec, FORCE start. There was something wrong. release 0x%x in time %f", this, iElapsedTime);
+            RDebug::Printf("CHuiFxEffect::AdvanceTime - Not drawn, but cannot wait. release 0x%x in time %f", this, iElapsedTime);
 #endif
             }