uiacceltk/hitchcock/coretoolkit/src/HuiFxEffect.cpp
branchRCL_3
changeset 52 31fccae4f8a7
parent 51 e5af45d51884
equal deleted inserted replaced
51:e5af45d51884 52:31fccae4f8a7
    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;
    82 #endif
    83 #endif
    83     }
    84     }
    84 
    85 
    85 EXPORT_C CHuiFxEffect::~CHuiFxEffect()
    86 EXPORT_C CHuiFxEffect::~CHuiFxEffect()
    86     {
    87     {
       
    88     ReleaseCachedRenderTarget();
       
    89     
    87     delete iRoot;
    90     delete iRoot;
    88     iRoot = NULL;
    91     iRoot = NULL;
    89     NotifyEffectEndObserver();
    92     NotifyEffectEndObserver();
    90     
       
    91     ReleaseCachedRenderTarget();
       
    92     
       
    93     iEngine->RemoveEffect(this);
    93     iEngine->RemoveEffect(this);
    94     if (iEngine && iGroupId != KErrNotFound && !(iFlags & KHuiReadyToDrawNotified))
    94     if (iEngine && iGroupId != KErrNotFound && !(iFlags & KHuiReadyToDrawNotified))
    95         {
    95         {
    96         // if effect was deleted before it was drawn, the group must be notified. If this was the last effect in the group
    96         // if effect was deleted before it was drawn, the group must be notified. If this was the last effect in the group
    97         // the group will be removed by the EffectReadyToStart
    97         // the group will be removed by the EffectReadyToStart
   178     if (iCachedRenderTarget)
   178     if (iCachedRenderTarget)
   179         {
   179         {
   180         iEngine->ReleaseRenderbuffer(iCachedRenderTarget);
   180         iEngine->ReleaseRenderbuffer(iCachedRenderTarget);
   181         iCachedRenderTarget = NULL;
   181         iCachedRenderTarget = NULL;
   182         }                
   182         }                
       
   183     
       
   184     if(iRoot)
       
   185         {
       
   186         iRoot->ReleaseAllCachedRenderTargets(*iEngine);
       
   187         }
   183     }
   188     }
   184 
   189 
   185 void CHuiFxEffect::PrepareCachedRenderTarget(const TPoint& aPosition, const TSize& aSize, TBool aClear, TBool aEnableBackground)
   190 void CHuiFxEffect::PrepareCachedRenderTarget(const TPoint& aPosition, const TSize& aSize, TBool aClear, TBool aEnableBackground)
   186     {
   191     {
   187     // If size has chnaged, we must delete old one
   192     // If size has chnaged, we must delete old one
   188     if (iCachedRenderTarget && 
   193     if (iCachedRenderTarget && 
   189         iCachedRenderTarget->Size() != aSize)
   194         iCachedRenderTarget->Size() != aSize)
   190         {
   195         {
   191         ReleaseCachedRenderTarget();
   196         iEngine->ReleaseRenderbuffer(iCachedRenderTarget);
       
   197         iCachedRenderTarget = NULL;
   192         }            
   198         }            
   193     
   199     
   194     // Accure new buffer
   200     // Accure new buffer
   195     if (!iCachedRenderTarget)
   201     if (!iCachedRenderTarget)
   196         {
   202         {
   256         {
   262         {
   257         return EFalse;
   263         return EFalse;
   258         }
   264         }
   259     }
   265     }
   260 
   266 
       
   267 TBool CHuiFxEffect::PrepareDrawL(CHuiGc& aGc, const TRect& aDisplayRect)
       
   268     {
       
   269     if(!iEffectable || iEffectable->EffectReadyToDrawNextFrame() )
       
   270          {
       
   271          iFramesDrawn++;
       
   272          }
       
   273 
       
   274     // Prepare all layers
       
   275     TRect displayArea = aGc.DisplayArea();
       
   276     TRect targetArea = aDisplayRect;
       
   277     targetArea.Intersection(displayArea);
       
   278 
       
   279     if (targetArea.Width() <= 0 || targetArea.Height() <= 0)
       
   280         {
       
   281         // Not visible
       
   282         return ETrue;
       
   283         }
       
   284     
       
   285     if (!iEngine || !iRoot)
       
   286         {
       
   287         return EFalse;
       
   288         }
       
   289 
       
   290     if (iEngine->LowMemoryState())
       
   291         {
       
   292         // No memory, no effects.
       
   293         return EFalse;
       
   294         }
       
   295     
       
   296     // Check if margins are allowed to be used for this effect
       
   297     if (EffectFlags() & KHuiFxEffectDisableMarginsFlag)
       
   298         {
       
   299         iRoot->EnableMargin(EFalse);
       
   300         }
       
   301 
       
   302     
       
   303     iRoot->SetTargetRect(targetArea);
       
   304     iRoot->SetSourceRect(targetArea);        
       
   305     iRoot->SetDisplayArea(displayArea);
       
   306     
       
   307     TRAPD(err, iRoot->PrepareDrawL(*iEngine));
       
   308     
       
   309     if (err != KErrNone)
       
   310         {
       
   311         return EFalse;
       
   312         }
       
   313 
       
   314     return ETrue;
       
   315     }
       
   316 
   261 TBool CHuiFxEffect::CachedDraw(CHuiGc& aGc, const TRect& aDisplayRect, TBool aRefreshCachedRenderTarget, TBool aOpaque)
   317 TBool CHuiFxEffect::CachedDraw(CHuiGc& aGc, const TRect& aDisplayRect, TBool aRefreshCachedRenderTarget, TBool aOpaque)
   262     {
   318     {
   263     RRegion dummy;
   319     RRegion dummy;
   264     TBool ret = CachedDraw(aGc, aDisplayRect, aRefreshCachedRenderTarget, aOpaque, dummy,EFalse);
   320     TBool ret = CachedDraw(aGc, aDisplayRect, aRefreshCachedRenderTarget, aOpaque, dummy,EFalse);
   265     dummy.Close();
   321     dummy.Close();
   270 TBool CHuiFxEffect::CachedDraw(CHuiGc& aGc, const TRect& aDisplayRect, TBool aRefreshCachedRenderTarget, TBool aOpaque, const TRegion& aClipRegion, TBool aHasSurface, TInt aAlpha)
   326 TBool CHuiFxEffect::CachedDraw(CHuiGc& aGc, const TRect& aDisplayRect, TBool aRefreshCachedRenderTarget, TBool aOpaque, const TRegion& aClipRegion, TBool aHasSurface, TInt aAlpha)
   271     {
   327     {
   272 #ifdef HUIFX_TRACE    
   328 #ifdef HUIFX_TRACE    
   273     RDebug::Print(_L("CHuiFxEffect::CachedDraw - 0x%x"), this);
   329     RDebug::Print(_L("CHuiFxEffect::CachedDraw - 0x%x"), this);
   274 #endif    
   330 #endif    
   275     iFramesDrawn++;
   331 
   276     if (!CHuiStatic::Renderer().Allows(EHuiRenderPluginAllowVisualPBufferSurfaces))
   332     if (!CHuiStatic::Renderer().Allows(EHuiRenderPluginAllowVisualPBufferSurfaces))
   277         {
   333         {
   278         return EFalse;
   334         return EFalse;
   279         }
   335         }
   280             
       
   281     
   336     
   282     CHuiFxRenderbuffer* target = NULL;
   337     CHuiFxRenderbuffer* target = NULL;
   283     
   338     
   284     // Prepare all layers
   339     // Prepare all layers
   285     TRect displayArea = aGc.DisplayArea();
   340     TRect displayArea = aGc.DisplayArea();
   301         {
   356         {
   302         // No memory, no effects.
   357         // No memory, no effects.
   303         return EFalse;
   358         return EFalse;
   304         }
   359         }
   305     
   360     
   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.
   361     // Check if surface pixels are to be used for this effect in all layers.
   313     if (EffectFlags() & KHuiFxEnableBackgroundInAllLayers)
   362     if (EffectFlags() & KHuiFxEnableBackgroundInAllLayers)
   314         {
   363         {
   315         iRoot->SetAlwaysReadSurfacePixels(ETrue);
   364         iRoot->SetAlwaysReadSurfacePixels(ETrue);
   316         }
   365         } 
   317     
   366 
   318     iRoot->SetTargetRect(targetArea);
   367     iRoot->SetVisualContentState(aRefreshCachedRenderTarget, aOpaque);
   319     iRoot->SetSourceRect(targetArea);        
   368     
   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())
   369     if (IsCachedRenderTargetSupported() && IsCachedRenderTargetPreferred())
   330         {
   370         {
   331         // Background needs to be captured from surface if effect uses background AND 
   371         // Background needs to be captured from surface if effect uses background AND 
   332         // Visual is transparent or margin is enabled AND
   372         // Visual is transparent or margin is enabled AND
   333         // Background has not been disabled with a effect specific flag
   373         // Background has not been disabled with a effect specific flag
   404             }
   444             }
   405         }
   445         }
   406     else
   446     else
   407         {
   447         {
   408         // Release cached render target just in case it is reserved for some reason
   448         // Release cached render target just in case it is reserved for some reason
   409         ReleaseCachedRenderTarget();
   449         if (iCachedRenderTarget)
       
   450             {
       
   451             iEngine->ReleaseRenderbuffer(iCachedRenderTarget);
       
   452             iCachedRenderTarget = NULL;
       
   453             }  
   410 
   454 
   411         // Use default onscreen render target
   455         // Use default onscreen render target
   412         if (!target)
   456         if (!target)
   413             {
   457             {
   414             target = iEngine->DefaultRenderbuffer();
   458             target = iEngine->DefaultRenderbuffer();
   420             }
   464             }
   421         
   465         
   422         // Normal drawing
   466         // Normal drawing
   423         iRoot->Draw(*iEngine, aGc, *target, *target, aHasSurface);
   467         iRoot->Draw(*iEngine, aGc, *target, *target, aHasSurface);
   424         }
   468         }
   425                 
       
   426     return ETrue;    
   469     return ETrue;    
   427     }
   470     }
   428 
   471 
   429 EXPORT_C TBool CHuiFxEffect::Draw(CHuiGc& aGc, const TRect& aDisplayRect, TBool aHasSurface)
   472 EXPORT_C TBool CHuiFxEffect::Draw(CHuiGc& aGc, const TRect& aDisplayRect, TBool aHasSurface)
   430     {
   473     {
   431     // Prepare all layers
   474     // Prepare all layers
   432 #ifdef HUIFX_TRACE    
   475 #ifdef HUIFX_TRACE    
   433     RDebug::Print(_L("CHuiFxEffect::Draw - 0x%x"), this);
   476     RDebug::Print(_L("CHuiFxEffect::Draw - 0x%x"), this);
   434 #endif
   477 #endif
   435     iFramesDrawn++;
       
   436     if (!CHuiStatic::Renderer().Allows(EHuiRenderPluginAllowVisualPBufferSurfaces))
   478     if (!CHuiStatic::Renderer().Allows(EHuiRenderPluginAllowVisualPBufferSurfaces))
   437         {
   479         {
   438         return EFalse;
   480         return EFalse;
   439         }
   481         }
   440             
   482             
   482         {
   524         {
   483         return EFalse;
   525         return EFalse;
   484         }
   526         }
   485 
   527 
   486     iRoot->Draw(*iEngine, aGc, *target, *target, aHasSurface);
   528     iRoot->Draw(*iEngine, aGc, *target, *target, aHasSurface);
       
   529 
       
   530 
   487     return ETrue;
   531     return ETrue;
   488     }
   532     }
   489 
   533 
   490 EXPORT_C TBool CHuiFxEffect::VisualArea(TRect& aRect) const
   534 EXPORT_C TBool CHuiFxEffect::VisualArea(TRect& aRect) const
   491     {
   535     {
   563 #endif
   607 #endif
   564     // KHuiFxDelayRunUntilFirstFrameHasBeenDrawn flag is for giving effect chance to run
   608     // KHuiFxDelayRunUntilFirstFrameHasBeenDrawn flag is for giving effect chance to run
   565     // its whole timeline by starting the time only when first frame has been drawn.
   609     // its whole timeline by starting the time only when first frame has been drawn.
   566     if (iFlags & KHuiFxDelayRunUntilFirstFrameHasBeenDrawn)
   610     if (iFlags & KHuiFxDelayRunUntilFirstFrameHasBeenDrawn)
   567         {
   611         {
   568         // Sometimes the effect does not get any frames. Force the time to start, because
   612         // 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.
   613 		// Force effect to start after 10seconds
   570         if (iElapsedTime > 0.2 && iFramesDrawn == 0)
   614 		if (iElapsedTime > 10.0 && iFramesDrawn == 0)
   571             {
   615             {
   572             iFramesDrawn = 1;
   616             iFramesDrawn = 1;
   573 #ifdef HUIFX_TRACE            
   617 #ifdef HUIFX_TRACE            
   574             RDebug::Printf("CHuiFxEffect::AdvanceTime - Not drawn, but cannot wait. release 0x%x in time %f", this, iElapsedTime);
   618             RDebug::Printf("CHuiFxEffect::AdvanceTime - Not drawn in 10sec, FORCE start. There was something wrong. release 0x%x in time %f", this, iElapsedTime);
   575 #endif
   619 #endif
   576             }
   620             }
   577         
   621         
   578         if (iFramesDrawn)
   622         if (iFramesDrawn)
   579             { 
   623             {