uiacceltk/hitchcock/coretoolkit/src/HuiFxEngine.cpp
branchRCL_3
changeset 8 46927d61fef3
parent 7 88b23e2e82e1
child 9 3ac8bf5c5014
equal deleted inserted replaced
7:88b23e2e82e1 8:46927d61fef3
    14 * Description:   
    14 * Description:   
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 
       
    20 #include "HuiFxEngine.h"
    19 #include "HuiFxEngine.h"
    21 #include "HuiFxEffectParser.h"
    20 #include "HuiFxEffectParser.h"
    22 #include "HuiFxEffect.h"
    21 #include "HuiFxEffect.h"
    23 #include "HuiFxEffectCache.h"
    22 #include "HuiFxEffectCache.h"
    24 #include <uiacceltk/HuiEnv.h>
    23 #include <uiacceltk/HuiEnv.h>
   281 void CHuiFxEngine::NotifyEffectEndObservers()
   280 void CHuiFxEngine::NotifyEffectEndObservers()
   282     {
   281     {
   283     for ( TInt i = iActiveEffects.Count() - 1; i >= 0; i-- )
   282     for ( TInt i = iActiveEffects.Count() - 1; i >= 0; i-- )
   284         {
   283         {
   285         CHuiFxEffect* effect = iActiveEffects[i];
   284         CHuiFxEffect* effect = iActiveEffects[i];
   286         if (!effect->Changed())
   285         if (!(effect->EffectFlags() & KHuiFadeEffectFlag) && !effect->Changed())
   287             {
   286             {
       
   287 #ifdef HUIFX_TRACE
       
   288             RDebug::Printf("void CHuiFxEngine::NotifyEffectEndObservers() calling NotifyEffectEndObserver");
       
   289 #endif
   288             effect->NotifyEffectEndObserver();
   290             effect->NotifyEffectEndObserver();
   289             }
   291             }
   290         }    
   292         }    
   291     }
   293     }
   292 
   294 
   294     {
   296     {
   295     // TODO: Can we do anything about all this polling?
   297     // TODO: Can we do anything about all this polling?
   296     TInt i;
   298     TInt i;
   297     TBool refreshRequired = EFalse;
   299     TBool refreshRequired = EFalse;
   298 #ifdef HUIFX_TRACE    
   300 #ifdef HUIFX_TRACE    
   299     RDebug::Print(_L("CHuiFxEngine::AdvanceTime - 0x%x "), this);   
   301     RDebug::Print(_L("CHuiFxEngine::AdvanceTime - 0x%x, effect count: %d"), this, iActiveEffects.Count());   
   300 #endif
   302 #endif
   301     // Go through the list in reverse order.
   303     // Go through the list in reverse order.
   302 // If the effect has ended, and has the callback set,
   304 // If the effect has ended, and has the callback set,
   303 // the effect will be removed, and will no longer be part of iActiveEffects set.
   305 // the effect will be removed, and will no longer be part of iActiveEffects set.
   304 // We must check if the effect is still in our list, but the indices change
   306 // We must check if the effect is still in our list, but the indices change
   310         if (effect->Changed())
   312         if (effect->Changed())
   311             {
   313             {
   312             refreshRequired = ETrue;
   314             refreshRequired = ETrue;
   313             }
   315             }
   314         TInt flags = effect->EffectFlags();
   316         TInt flags = effect->EffectFlags();
   315         if ( !(flags & KHuiFxWaitGroupSyncronization) 
   317         if ( !(flags & KHuiFxWaitGroupSyncronization)
   316                 && (skipGroup == KErrNotFound || skipGroup != effect->GroupId()))
   318                 && !(flags & KHuiFadeEffectFlag) // fade is not animated. Note, if animated effect would be used, remove this!
       
   319                 && (skipGroup == KErrNotFound || skipGroup != effect->GroupId())
       
   320                )
   317             {
   321             {
   318             // The effect is still in its place, it did not go away yet
   322             // The effect is still in its place, it did not go away yet
   319             TBool waitingGroupBefore = flags & KHuiFxWaitGroupToStartSyncronized;
   323             TBool waitingGroupBefore = flags & KHuiFxWaitGroupToStartSyncronized;
   320             effect->AdvanceTime(aElapsedTime);
   324             effect->AdvanceTime(aElapsedTime);
   321             
   325             
   346 #ifdef HUIFX_TRACE        
   350 #ifdef HUIFX_TRACE        
   347     RDebug::Print(_L("CHuiFxEngine::AddEffectL - 0x%x "), aEffect);
   351     RDebug::Print(_L("CHuiFxEngine::AddEffectL - 0x%x "), aEffect);
   348 #endif // #ifdef HUIFX_TRACE    
   352 #endif // #ifdef HUIFX_TRACE    
   349 
   353 
   350     iActiveEffects.AppendL(aEffect);
   354     iActiveEffects.AppendL(aEffect);
       
   355     if (iEffectObserver)
       
   356         {
       
   357         iEffectObserver->EffectAdded(aEffect);    
       
   358         }
   351     }
   359     }
   352 
   360 
   353 EXPORT_C void CHuiFxEngine::RemoveEffect(CHuiFxEffect* aEffect)
   361 EXPORT_C void CHuiFxEngine::RemoveEffect(CHuiFxEffect* aEffect)
   354     {
   362     {
   355 #ifdef HUIFX_TRACE    
   363 #ifdef HUIFX_TRACE    
   357 #endif    
   365 #endif    
   358     TInt i = iActiveEffects.Find(aEffect);
   366     TInt i = iActiveEffects.Find(aEffect);
   359     if (i >= 0)
   367     if (i >= 0)
   360         {
   368         {
   361         iActiveEffects.Remove(i);
   369         iActiveEffects.Remove(i);
       
   370         if (iEffectObserver)
       
   371             {
       
   372             iEffectObserver->EffectComplete(aEffect);
       
   373             }
   362         }
   374         }
   363     }
   375     }
   364 
   376 
   365 EXPORT_C TReal32 CHuiFxEngine::GetReferenceValue(THuiFxReferencePoint aPoint)
   377 EXPORT_C TReal32 CHuiFxEngine::GetReferenceValue(THuiFxReferencePoint aPoint)
   366     {
   378     {
   503     RDebug::Print(_L("CHuiFxEngine::ReleaseRenderbuffer - buffer: 0x%x "), aBuffer);
   515     RDebug::Print(_L("CHuiFxEngine::ReleaseRenderbuffer - buffer: 0x%x "), aBuffer);
   504 #endif
   516 #endif
   505     ASSERT((aBuffer) && (iBuffersInUse > 0));
   517     ASSERT((aBuffer) && (iBuffersInUse > 0));
   506 
   518 
   507 #ifdef HUIFX_RBCACHE_ENABLED
   519 #ifdef HUIFX_RBCACHE_ENABLED
   508     if(iLowGraphicsMemoryMode || IsCacheFull())
   520     if(iLowGraphicsMemoryMode < EHuiMemoryLevelReduced || IsCacheFull())
   509         {
   521         {
   510 #ifdef HUIFX_TRACE            
   522 #ifdef HUIFX_TRACE            
   511         RDebug::Print(_L("CHuiFxEngine::ReleaseRenderbuffer() --- Renderbuffer cache full! Suspectible for memory fragmentation! Cache size is %d entries."), CACHE_SIZE);
   523         RDebug::Print(_L("CHuiFxEngine::ReleaseRenderbuffer() --- Renderbuffer cache full! Suspectible for memory fragmentation! Cache size is %d entries."), CACHE_SIZE);
   512 #endif
   524 #endif
   513 #endif        
   525 #endif        
   586     }
   598     }
   587     
   599     
   588 EXPORT_C void  CHuiFxEngine::SetMemoryLevel(THuiMemoryLevel aLevel)
   600 EXPORT_C void  CHuiFxEngine::SetMemoryLevel(THuiMemoryLevel aLevel)
   589     {
   601     {
   590     iLowGraphicsMemoryMode = aLevel;
   602     iLowGraphicsMemoryMode = aLevel;
   591     if(iLowGraphicsMemoryMode) // != Normal
   603     if(iLowGraphicsMemoryMode < EHuiMemoryLevelReduced)
   592         {
   604         {
   593         ClearCache();
   605         ClearCache();
   594         }
   606         }
   595     }
   607     }
   596 
   608 
   599     // Default implementation does nothing
   611     // Default implementation does nothing
   600     }
   612     }
   601 
   613 
   602 TInt CHuiFxEngine::LowMemoryState()
   614 TInt CHuiFxEngine::LowMemoryState()
   603     {
   615     {
   604     return iLowGraphicsMemoryMode;
   616     return iLowGraphicsMemoryMode < EHuiMemoryLevelReduced;
   605     }
   617     }
   606 
   618 
   607 TBool CHuiFxEngine::HasActiveEffects() const
   619 TBool CHuiFxEngine::HasActiveEffects() const
   608     {
   620     {
   609 	// Don't report active effects if in SW-rendering mode
   621 	// Don't report active effects if in SW-rendering mode
   610     if(iLowGraphicsMemoryMode) // != Normal
   622     if(iLowGraphicsMemoryMode < EHuiMemoryLevelReduced) 
   611         {
   623         {
   612         return EFalse;
   624         return EFalse;
   613         }
   625         }
   614     return iActiveEffects.Count() > 0;
   626     return iActiveEffects.Count() > 0;
       
   627     }
       
   628 
       
   629 TBool CHuiFxEngine::HasActiveFadeEffect() const
       
   630     {
       
   631     // Don't report active effects if in SW-rendering mode
       
   632     if(iLowGraphicsMemoryMode < EHuiMemoryLevelReduced) 
       
   633         {
       
   634         return EFalse;
       
   635         }
       
   636     TInt effectCount = iActiveEffects.Count();
       
   637     for (TInt count  = 0; count < effectCount; count++)
       
   638         {
       
   639         if (iActiveEffects[count]->EffectFlags() & KHuiFadeEffectFlag)
       
   640             {
       
   641             return ETrue;
       
   642             }
       
   643         }
       
   644     return EFalse;
   615     }
   645     }
   616 
   646 
   617 void CHuiFxEngine::ClearCache()
   647 void CHuiFxEngine::ClearCache()
   618     {
   648     {
   619     // Release cached render targets from effects
   649     // Release cached render targets from effects
   655     return KErrNotFound;
   685     return KErrNotFound;
   656     }
   686     }
   657 
   687 
   658 EXPORT_C void CHuiFxEngine::BeginGroupEffect(TInt aGroup)
   688 EXPORT_C void CHuiFxEngine::BeginGroupEffect(TInt aGroup)
   659 	{
   689 	{
       
   690 #ifdef HUIFX_TRACE   
       
   691 	RDebug::Printf("CHuiFxEngine::BeginGroupEffect(TInt aGroup %d) >>", aGroup);
       
   692 #endif
   660 	// Multiple grouped effects at the same time are not supported. 
   693 	// Multiple grouped effects at the same time are not supported. 
   661     // Same visual might participate different groups, which will mess up the effect
   694     // Same visual might participate different groups, which will mess up the effect
   662     if (iActiveEffectGroups.Count()>0)
   695     if (iActiveEffectGroups.Count()>0)
   663         {
   696         {
   664         // delete previous groups
   697         // delete previous groups
   715     if (index != KErrNotFound)
   748     if (index != KErrNotFound)
   716         {
   749         {
   717         // keep count of effects in this group. All must draw atleast once, before
   750         // keep count of effects in this group. All must draw atleast once, before
   718         // syncronized group effect may start
   751         // syncronized group effect may start
   719         iActiveEffectGroups[index].iWaiting++;
   752         iActiveEffectGroups[index].iWaiting++;
       
   753 #ifdef HUIFX_TRACE
       
   754         RDebug::Printf("CHuiFxEngine::AddEffectToGroup - %d, waiting in group: %d", aGroup, iActiveEffectGroups[index].iWaiting);
       
   755 #endif
   720         return ETrue;
   756         return ETrue;
   721         }
   757         }
   722     return EFalse;
   758     return EFalse;
   723     }
   759     }
   724 
   760 
   725 EXPORT_C void CHuiFxEngine::StartGroupEffect(TInt aGroup)
   761 EXPORT_C void CHuiFxEngine::StartGroupEffect(TInt aGroup)
   726 	{
   762 	{
       
   763 #ifdef HUIFX_TRACE
       
   764     RDebug::Printf("CHuiFxEngine::StartGroupEffect(TInt aGroup %d) >>", aGroup);
       
   765 #endif	    
   727 	TInt index = FindEffectGroup(aGroup);
   766 	TInt index = FindEffectGroup(aGroup);
   728 	if (index != KErrNotFound)
   767 	if (index != KErrNotFound)
   729 		{
   768 		{
   730 		iActiveEffectGroups[index].iEndCalled = ETrue; // this group will not take any more participants
   769 		iActiveEffectGroups[index].iEndCalled = ETrue; // this group will not take any more participants
   731 		for ( TInt i = iActiveEffects.Count() - 1; i >= 0; i-- )
   770 		for ( TInt i = iActiveEffects.Count() - 1; i >= 0; i-- )
   741 		}
   780 		}
   742 	}
   781 	}
   743 
   782 
   744 void CHuiFxEngine::NotifyEffectReady(TInt aGroupId)
   783 void CHuiFxEngine::NotifyEffectReady(TInt aGroupId)
   745     {
   784     {
       
   785 #ifdef HUIFX_TRACE    
       
   786     RDebug::Print(_L("CHuiFxEngine::NotifyEffectReady - %d"), aGroupId);
       
   787 #endif
   746     TInt index = FindEffectGroup(aGroupId);
   788     TInt index = FindEffectGroup(aGroupId);
   747     if (index != KErrNotFound)
   789     if (index != KErrNotFound)
   748         {
   790         {
   749         if (--iActiveEffectGroups[iActiveEffectGroups.Count()-1].iWaiting == 0)
   791         iActiveEffectGroups[index].iWaiting--;    
       
   792 #ifdef HUIFX_TRACE
       
   793         RDebug::Print(_L("CHuiFxEngine::NotifyEffectReady - waiting %d in group %d"), iActiveEffectGroups[index].iWaiting , aGroupId);
       
   794 #endif        
       
   795         if (iActiveEffectGroups[index].iWaiting == 0)
   750             {
   796             {
   751             // set in motion all effects in this group
   797             // set in motion all effects in this group
   752 	        iActiveEffectGroups.Remove(index);
   798 	        iActiveEffectGroups.Remove(index);
   753             for ( TInt i = iActiveEffects.Count() - 1; i >= 0; i-- )
   799             for ( TInt i = iActiveEffects.Count() - 1; i >= 0; i-- )
   754                 {
   800                 {
   755                 CHuiFxEffect* effect = iActiveEffects[i];
   801                 CHuiFxEffect* effect = iActiveEffects[i];
   756                 TInt flags = effect->EffectFlags();
   802                 TInt flags = effect->EffectFlags();
       
   803 #ifdef HUIFX_TRACE
       
   804                 RDebug::Print(_L("CHuiFxEngine::NotifyEffectReady - effect 0x%x, group: %d, flags 0x%x"), effect, effect->GroupId(), effect->EffectFlags());
       
   805 #endif                
   757                 if ((flags & KHuiFxReadyAndWaitingGroupToStartSyncronized) && (effect->GroupId() == aGroupId))
   806                 if ((flags & KHuiFxReadyAndWaitingGroupToStartSyncronized) && (effect->GroupId() == aGroupId))
   758                     {
   807                     {
   759                     effect->ClearEffectFlag(KHuiFxReadyAndWaitingGroupToStartSyncronized);
   808                     effect->ClearEffectFlag(KHuiFxReadyAndWaitingGroupToStartSyncronized);
   760                     }
   809                     }
   761                 }
   810                 }