uiacceltk/hitchcock/coretoolkit/src/HuiFxEffect.cpp
branchRCL_3
changeset 17 c9d868f1e20c
parent 13 3a60ebea00d0
child 18 1801340c26a2
equal deleted inserted replaced
15:cd0ae4656946 17:c9d868f1e20c
    64     {
    64     {
    65     iRoot->SetVisual(aVisual);
    65     iRoot->SetVisual(aVisual);
    66     }
    66     }
    67 EXPORT_C void CHuiFxEffect::SetVisual( MHuiEffectable *aEffectable )
    67 EXPORT_C void CHuiFxEffect::SetVisual( MHuiEffectable *aEffectable )
    68     {
    68     {
       
    69     iEffectable = aEffectable;
    69     iRoot->SetVisual(aEffectable);
    70     iRoot->SetVisual(aEffectable);
    70     }
    71     }
    71 EXPORT_C void CHuiFxEffect::SetEngine( CHuiFxEngine *aEngine )
    72 EXPORT_C void CHuiFxEffect::SetEngine( CHuiFxEngine *aEngine )
    72     {
    73     {
    73     iEngine = aEngine;
    74     iEngine = aEngine;
   256         {
   257         {
   257         return EFalse;
   258         return EFalse;
   258         }
   259         }
   259     }
   260     }
   260 
   261 
       
   262 TBool CHuiFxEffect::PrepareDrawL(CHuiGc& aGc, const TRect& aDisplayRect)
       
   263     {
       
   264     if(!iEffectable || iEffectable->EffectReadyToDrawNextFrame() )
       
   265          {
       
   266          iFramesDrawn++;
       
   267          }
       
   268 
       
   269     // Prepare all layers
       
   270     TRect displayArea = aGc.DisplayArea();
       
   271     TRect targetArea = aDisplayRect;
       
   272     targetArea.Intersection(displayArea);
       
   273 
       
   274     if (targetArea.Width() <= 0 || targetArea.Height() <= 0)
       
   275         {
       
   276         // Not visible
       
   277         return ETrue;
       
   278         }
       
   279     
       
   280     if (!iEngine || !iRoot)
       
   281         {
       
   282         return EFalse;
       
   283         }
       
   284 
       
   285     if (iEngine->LowMemoryState())
       
   286         {
       
   287         // No memory, no effects.
       
   288         return EFalse;
       
   289         }
       
   290     
       
   291     // Check if margins are allowed to be used for this effect
       
   292     if (EffectFlags() & KHuiFxEffectDisableMarginsFlag)
       
   293         {
       
   294         iRoot->EnableMargin(EFalse);
       
   295         }
       
   296 
       
   297     
       
   298     iRoot->SetTargetRect(targetArea);
       
   299     iRoot->SetSourceRect(targetArea);        
       
   300     iRoot->SetDisplayArea(displayArea);
       
   301     
       
   302     TRAPD(err, iRoot->PrepareDrawL(*iEngine));
       
   303     
       
   304     if (err != KErrNone)
       
   305         {
       
   306         return EFalse;
       
   307         }
       
   308 
       
   309     return ETrue;
       
   310     }
       
   311 
   261 TBool CHuiFxEffect::CachedDraw(CHuiGc& aGc, const TRect& aDisplayRect, TBool aRefreshCachedRenderTarget, TBool aOpaque)
   312 TBool CHuiFxEffect::CachedDraw(CHuiGc& aGc, const TRect& aDisplayRect, TBool aRefreshCachedRenderTarget, TBool aOpaque)
   262     {
   313     {
   263     RRegion dummy;
   314     RRegion dummy;
   264     TBool ret = CachedDraw(aGc, aDisplayRect, aRefreshCachedRenderTarget, aOpaque, dummy,EFalse);
   315     TBool ret = CachedDraw(aGc, aDisplayRect, aRefreshCachedRenderTarget, aOpaque, dummy,EFalse);
   265     dummy.Close();
   316     dummy.Close();
   270 TBool CHuiFxEffect::CachedDraw(CHuiGc& aGc, const TRect& aDisplayRect, TBool aRefreshCachedRenderTarget, TBool aOpaque, const TRegion& aClipRegion, TBool aHasSurface, TInt aAlpha)
   321 TBool CHuiFxEffect::CachedDraw(CHuiGc& aGc, const TRect& aDisplayRect, TBool aRefreshCachedRenderTarget, TBool aOpaque, const TRegion& aClipRegion, TBool aHasSurface, TInt aAlpha)
   271     {
   322     {
   272 #ifdef HUIFX_TRACE    
   323 #ifdef HUIFX_TRACE    
   273     RDebug::Print(_L("CHuiFxEffect::CachedDraw - 0x%x"), this);
   324     RDebug::Print(_L("CHuiFxEffect::CachedDraw - 0x%x"), this);
   274 #endif    
   325 #endif    
   275     iFramesDrawn++;
   326 
   276     if (!CHuiStatic::Renderer().Allows(EHuiRenderPluginAllowVisualPBufferSurfaces))
   327     if (!CHuiStatic::Renderer().Allows(EHuiRenderPluginAllowVisualPBufferSurfaces))
   277         {
   328         {
   278         return EFalse;
   329         return EFalse;
   279         }
   330         }
   280             
       
   281     
   331     
   282     CHuiFxRenderbuffer* target = NULL;
   332     CHuiFxRenderbuffer* target = NULL;
   283     
   333     
   284     // Prepare all layers
   334     // Prepare all layers
   285     TRect displayArea = aGc.DisplayArea();
   335     TRect displayArea = aGc.DisplayArea();
   301         {
   351         {
   302         // No memory, no effects.
   352         // No memory, no effects.
   303         return EFalse;
   353         return EFalse;
   304         }
   354         }
   305     
   355     
   306     // Check if margins are allowed to be used for this effect
       
   307     if (EffectFlags() & KHuiFxEffectDisableMarginsFlag)
       
   308         {
       
   309         iRoot->EnableMargin(EFalse);
       
   310         }
       
   311 
       
   312     // Check if surface pixels are to be used for this effect in all layers.
   356     // Check if surface pixels are to be used for this effect in all layers.
   313     if (EffectFlags() & KHuiFxEnableBackgroundInAllLayers)
   357     if (EffectFlags() & KHuiFxEnableBackgroundInAllLayers)
   314         {
   358         {
   315         iRoot->SetAlwaysReadSurfacePixels(ETrue);
   359         iRoot->SetAlwaysReadSurfacePixels(ETrue);
   316         }
   360         } 
   317     
   361 
   318     iRoot->SetTargetRect(targetArea);
   362     iRoot->SetVisualContentState(aRefreshCachedRenderTarget, aOpaque);
   319     iRoot->SetSourceRect(targetArea);        
   363     
   320     iRoot->SetDisplayArea(displayArea);
       
   321     
       
   322     TRAPD(err, iRoot->PrepareDrawL(*iEngine));
       
   323     
       
   324     if (err != KErrNone)
       
   325         {
       
   326         return EFalse;
       
   327         }
       
   328 
       
   329     if (IsCachedRenderTargetSupported() && IsCachedRenderTargetPreferred())
   364     if (IsCachedRenderTargetSupported() && IsCachedRenderTargetPreferred())
   330         {
   365         {
   331         // Background needs to be captured from surface if effect uses background AND 
   366         // Background needs to be captured from surface if effect uses background AND 
   332         // Visual is transparent or margin is enabled AND
   367         // Visual is transparent or margin is enabled AND
   333         // Background has not been disabled with a effect specific flag
   368         // Background has not been disabled with a effect specific flag
   420             }
   455             }
   421         
   456         
   422         // Normal drawing
   457         // Normal drawing
   423         iRoot->Draw(*iEngine, aGc, *target, *target, aHasSurface);
   458         iRoot->Draw(*iEngine, aGc, *target, *target, aHasSurface);
   424         }
   459         }
   425                 
       
   426     return ETrue;    
   460     return ETrue;    
   427     }
   461     }
   428 
   462 
   429 EXPORT_C TBool CHuiFxEffect::Draw(CHuiGc& aGc, const TRect& aDisplayRect, TBool aHasSurface)
   463 EXPORT_C TBool CHuiFxEffect::Draw(CHuiGc& aGc, const TRect& aDisplayRect, TBool aHasSurface)
   430     {
   464     {
   431     // Prepare all layers
   465     // Prepare all layers
   432 #ifdef HUIFX_TRACE    
   466 #ifdef HUIFX_TRACE    
   433     RDebug::Print(_L("CHuiFxEffect::Draw - 0x%x"), this);
   467     RDebug::Print(_L("CHuiFxEffect::Draw - 0x%x"), this);
   434 #endif
   468 #endif
   435     iFramesDrawn++;
       
   436     if (!CHuiStatic::Renderer().Allows(EHuiRenderPluginAllowVisualPBufferSurfaces))
   469     if (!CHuiStatic::Renderer().Allows(EHuiRenderPluginAllowVisualPBufferSurfaces))
   437         {
   470         {
   438         return EFalse;
   471         return EFalse;
   439         }
   472         }
   440             
   473             
   482         {
   515         {
   483         return EFalse;
   516         return EFalse;
   484         }
   517         }
   485 
   518 
   486     iRoot->Draw(*iEngine, aGc, *target, *target, aHasSurface);
   519     iRoot->Draw(*iEngine, aGc, *target, *target, aHasSurface);
       
   520 
       
   521 
   487     return ETrue;
   522     return ETrue;
   488     }
   523     }
   489 
   524 
   490 EXPORT_C TBool CHuiFxEffect::VisualArea(TRect& aRect) const
   525 EXPORT_C TBool CHuiFxEffect::VisualArea(TRect& aRect) const
   491     {
   526     {
   563 #endif
   598 #endif
   564     // KHuiFxDelayRunUntilFirstFrameHasBeenDrawn flag is for giving effect chance to run
   599     // KHuiFxDelayRunUntilFirstFrameHasBeenDrawn flag is for giving effect chance to run
   565     // its whole timeline by starting the time only when first frame has been drawn.
   600     // its whole timeline by starting the time only when first frame has been drawn.
   566     if (iFlags & KHuiFxDelayRunUntilFirstFrameHasBeenDrawn)
   601     if (iFlags & KHuiFxDelayRunUntilFirstFrameHasBeenDrawn)
   567         {
   602         {
   568         // Sometimes the effect does not get any frames. Force the time to start, because
   603         // This is a backup timer. If effect won't start before this 10sec wait there must be something wrong
   569         // otherwise will jam itself and possible the group, where the effect is.
   604 		// Force effect to start after 10seconds
   570         if (iElapsedTime > 0.2 && iFramesDrawn == 0)
   605 		if (iElapsedTime > 10.0 && iFramesDrawn == 0)
   571             {
   606             {
   572             iFramesDrawn = 1;
   607             iFramesDrawn = 1;
   573 #ifdef HUIFX_TRACE            
   608 #ifdef HUIFX_TRACE            
   574             RDebug::Printf("CHuiFxEffect::AdvanceTime - Not drawn, but cannot wait. release 0x%x in time %f", this, iElapsedTime);
   609             RDebug::Printf("CHuiFxEffect::AdvanceTime - Not drawn in 10sec, FORCE start. There was something wrong. release 0x%x in time %f", this, iElapsedTime);
   575 #endif
   610 #endif
   576             }
   611             }
   577         
   612         
   578         if (iFramesDrawn)
   613         if (iFramesDrawn)
   579             { 
   614             {