photosgallery/slideshow/engine/effectsrc/shwdefaulteffectmanager.cpp
changeset 0 4e91876724a2
child 18 bcb43dc84c44
equal deleted inserted replaced
-1:000000000000 0:4e91876724a2
       
     1 /*
       
     2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:    Default effect order manager
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 //  Include Files
       
    22 #include "shwdefaulteffectmanager.h"
       
    23 
       
    24 #include <e32math.h>
       
    25 
       
    26 #include <glxlog.h>
       
    27 #include <glxtracer.h>
       
    28 
       
    29 #include "shweffect.h"
       
    30 #include "shwconstants.h"
       
    31 #include "shwslideshowenginepanic.h"
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // C++ Constructor. Save a few bits of rom with inlining
       
    35 // -----------------------------------------------------------------------------
       
    36 inline CShwDefaultEffectManager::CShwDefaultEffectManager()
       
    37 	: iEffectOrder( MShwEffectManager::EEffectOrderLinear )	// default order
       
    38 	{
       
    39 	TRACER("CShwDefaultEffectManager::CShwDefaultEffectManager()");
       
    40 	GLX_LOG_INFO( "CShwDefaultEffectManager::CShwDefaultEffectManager()" );
       
    41 	// no implementation required
       
    42 	}
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // NewL. Static construction
       
    46 // -----------------------------------------------------------------------------
       
    47 CShwDefaultEffectManager* CShwDefaultEffectManager::NewL()
       
    48 	{
       
    49 	TRACER("CShwDefaultEffectManager::NewL()");
       
    50 	GLX_LOG_INFO( "CShwDefaultEffectManager::NewL" );
       
    51 	CShwDefaultEffectManager* self = new( ELeave ) CShwDefaultEffectManager;
       
    52 	return self;
       
    53 	}
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // Destructor.
       
    57 // -----------------------------------------------------------------------------
       
    58 CShwDefaultEffectManager::~CShwDefaultEffectManager()
       
    59 	{
       
    60 	TRACER("CShwDefaultEffectManager::~CShwDefaultEffectManager");
       
    61 	GLX_LOG_INFO( "CShwDefaultEffectManager::~CShwDefaultEffectManager" );
       
    62 
       
    63 	// Delete the effect objects
       
    64 	ResetAndDestroyEffects( iAvailableEffects );
       
    65 	iAvailableEffects.Close();
       
    66 	
       
    67 	// Close the "working" effects array
       
    68 	// Note that iEffects just references the same elements as iAvailableEffects
       
    69 	// so don't delete them again.
       
    70 	iEffects.Close();
       
    71 	}
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // AddEffectL.
       
    75 // -----------------------------------------------------------------------------
       
    76 void CShwDefaultEffectManager::AddEffectL( MShwEffect* aEffect )
       
    77 	{
       
    78 	TRACER("CShwDefaultEffectManager::AddEffectL");
       
    79     GLX_LOG_INFO( "CShwDefaultEffectManager::AddEffectL" );
       
    80     // dont add NULLs to the array
       
    81     if( aEffect )
       
    82     	{
       
    83 		iAvailableEffects.AppendL( aEffect );
       
    84     	}
       
    85 	}
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CurrentEffect.
       
    89 // -----------------------------------------------------------------------------
       
    90 MShwEffect* CShwDefaultEffectManager::CurrentEffect()
       
    91 	{
       
    92 	TRACER("CShwDefaultEffectManager::CurrentEffect");
       
    93 	GLX_LOG_INFO( "CShwDefaultEffectManager::CurrentEffect" );
       
    94 	// check that we have something in iEffects
       
    95 	__ASSERT_DEBUG( iEffects.Count() > 0 && iEffects.Count() > iCurrentEffect,
       
    96 		NShwEngine::Panic( NShwEngine::EIncorrectEffectIndex ) );
       
    97 	
       
    98 	return iEffects[ iCurrentEffect ];
       
    99 	}
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // Effect
       
   103 // -----------------------------------------------------------------------------
       
   104 MShwEffect* CShwDefaultEffectManager::Effect( TInt aDirection )
       
   105 	{
       
   106 	TRACER("CShwDefaultEffectManager::Effect");
       
   107 	GLX_LOG_INFO1( "CShwDefaultEffectManager::Effect, direction %d",
       
   108 		aDirection );
       
   109 	// check that we have something in iEffects
       
   110 	__ASSERT_DEBUG( iEffects.Count() > 0 && iEffects.Count() > iCurrentEffect,
       
   111 		NShwEngine::Panic( NShwEngine::EIncorrectEffectIndex ) );
       
   112 
       
   113 	TInt nextEffectIndex = CalculateNextEffectIndex( aDirection );
       
   114 	return iEffects[ nextEffectIndex ];
       
   115 	}
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // ProceedToEffect.
       
   119 // -----------------------------------------------------------------------------
       
   120 void CShwDefaultEffectManager::ProceedToEffect( TInt aDirection )
       
   121 	{
       
   122 	TRACER("CShwDefaultEffectManager::ProceedToEffect");
       
   123 	GLX_LOG_INFO1( "CShwDefaultEffectManager::ProceedToEffect,\
       
   124 		direction %d", aDirection );
       
   125 	// calculate new effects
       
   126 	CalculateEffects( aDirection );
       
   127 	}
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // SetEffectOrder.
       
   131 // -----------------------------------------------------------------------------
       
   132 void CShwDefaultEffectManager::SetEffectOrder(MShwEffectManager::TShwEffectOrder
       
   133 	aOrder)
       
   134     {
       
   135     TRACER("CShwDefaultEffectManager::SetEffectOrder");
       
   136     GLX_LOG_INFO("CShwDefaultEffectManager::SetEffectOrder");
       
   137     iEffectOrder = aOrder;
       
   138     /// @todo implement the rest for increment 7
       
   139     }
       
   140 
       
   141 // -----------------------------------------------------------------------------
       
   142 // EffectOrder.
       
   143 // -----------------------------------------------------------------------------
       
   144 MShwEffectManager::TShwEffectOrder CShwDefaultEffectManager::EffectOrder()
       
   145     {
       
   146     TRACER("CShwDefaultEffectManager::EffectOrder");
       
   147     GLX_LOG_INFO("CShwDefaultEffectManager::EffectOrder");
       
   148     return iEffectOrder;
       
   149     }
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // SetProgrammedEffects.
       
   153 // -----------------------------------------------------------------------------  
       
   154 void CShwDefaultEffectManager::SetProgrammedEffects( 
       
   155 	RArray<TShwEffectInfo>& /*aEffects*/ )
       
   156     {
       
   157     TRACER("CShwDefaultEffectManager::SetProgrammedEffects");
       
   158     GLX_LOG_INFO("CShwDefaultEffectManager::SetProgrammedEffects");
       
   159     /// @todo implement for increment 7
       
   160     }
       
   161 
       
   162 // -----------------------------------------------------------------------------
       
   163 // SetDefaultEffect.
       
   164 // -----------------------------------------------------------------------------
       
   165 void CShwDefaultEffectManager::SetDefaultEffectL( TShwEffectInfo aInfo )
       
   166     {
       
   167     TRACER("CShwDefaultEffectManager::SetDefaultEffectL");
       
   168 	GLX_LOG_INFO( "CShwDefaultEffectManager::SetDefaultEffectL" );
       
   169 
       
   170 	// Loop through the effects to find the one with matching info
       
   171 	TInt index = iAvailableEffects.Count();
       
   172 	MShwEffect* effect = NULL;
       
   173 	while( index-- > 0 )
       
   174 		{
       
   175 		// get effect
       
   176 		effect = iAvailableEffects[ index ];
       
   177 		// get its info
       
   178 		TShwEffectInfo info = effect->EffectInfo();
       
   179 		// check if we got a match
       
   180 		if( info == aInfo )
       
   181 			{
       
   182 			break;
       
   183 			}
       
   184 		}
       
   185 	// if no effect or no match
       
   186 	if( !effect || index < 0 )
       
   187 		{
       
   188 		// effect not found
       
   189     	User::Leave( KErrArgument );
       
   190 		}
       
   191 
       
   192 	// Need to clone the effect as in current release
       
   193 	// we have once single effect at a time and one effect instance can only
       
   194 	// handle one visual
       
   195 	/// @todo fix this so that once the effect order is solved, the effects
       
   196 	/// are cloned as needed
       
   197 	MShwEffect* clone = effect->CloneLC();
       
   198 	iAvailableEffects.AppendL( clone );
       
   199 	CleanupStack::Pop();
       
   200 
       
   201     iEffects.Append( effect );
       
   202     iEffects.Append( clone );
       
   203 
       
   204 	// calculate the effects    
       
   205     CalculateEffects( 1 );
       
   206     }
       
   207 
       
   208 // -----------------------------------------------------------------------------
       
   209 // GetActiveEffectsL
       
   210 // -----------------------------------------------------------------------------
       
   211 void CShwDefaultEffectManager::GetActiveEffectsL( 
       
   212 	RPointerArray< MShwEffect >& aEffects )
       
   213     {
       
   214     TRACER("CShwDefaultEffectManager::GetActiveEffectsL");
       
   215     GLX_LOG_INFO( "CShwDefaultEffectManager::GetActiveEffectsL" );
       
   216     // Retrieve each effect
       
   217     for( TInt i = 0; i < iEffects.Count(); ++i )
       
   218         {
       
   219         // append the effect pointer to the given array
       
   220         aEffects.AppendL( iEffects[i] );  
       
   221         }
       
   222     }
       
   223 
       
   224 // -----------------------------------------------------------------------------
       
   225 // CalculateEffects.
       
   226 // -----------------------------------------------------------------------------
       
   227 void CShwDefaultEffectManager::CalculateEffects( TInt aDirection )
       
   228     {
       
   229     TRACER("CShwDefaultEffectManager::CalculateEffects");
       
   230 	GLX_LOG_INFO1( "CShwDefaultEffectManager::CalculateEffects,\
       
   231 		direction %d", aDirection );
       
   232     // This method updates both the current and next indices for the given
       
   233     // direction.  If we're proceeding forwards, temporarily store the
       
   234     // "next" index to set it as "current" after the new "next" value has 
       
   235     // been determined (as the next value is determined from the current value).
       
   236     if ( aDirection > 0 )
       
   237     	{
       
   238     	// Next effect is "forward"
       
   239     	iCurrentEffect = iNextEffect;
       
   240     	}
       
   241     else
       
   242     	{
       
   243     	// moving "backwards"
       
   244     	iNextEffect = iCurrentEffect;
       
   245     	}
       
   246     	
       
   247     if( iEffectOrder == MShwEffectManager::EEffectOrderLinear )
       
   248         {
       
   249         // As iAvailableEffects is used to store the effects it can be 
       
   250         // walked directly and the order will always be correct
       
   251         //
       
   252         TInt nextEffect = CalculateNextEffectIndex( aDirection );
       
   253         if ( aDirection > 0 )
       
   254         	{
       
   255         	// moving forwards
       
   256 			iNextEffect = nextEffect;
       
   257         	}
       
   258         else
       
   259         	{
       
   260         	// moving backwards
       
   261         	iCurrentEffect = nextEffect;
       
   262         	}
       
   263 		}
       
   264     }
       
   265 
       
   266 // -----------------------------------------------------------------------------
       
   267 // ResetAndDestroyEffects.
       
   268 // -----------------------------------------------------------------------------
       
   269 void CShwDefaultEffectManager::ResetAndDestroyEffects(RArray< MShwEffect* >&
       
   270 	aArray)
       
   271     {
       
   272     TRACER("CShwDefaultEffectManager::ResetAndDestroyEffects");
       
   273     // get the count
       
   274     TInt count = aArray.Count();
       
   275 	GLX_LOG_INFO1( 
       
   276 		"CShwDefaultEffectManager::ResetAndDestroyEffects %d", count );
       
   277 
       
   278     // Delete the effect objects
       
   279 	for( TInt i = 0; i < count; i++ )
       
   280 		{
       
   281 		// call the destructor
       
   282 		delete aArray[ i ];
       
   283 		}
       
   284 	aArray.Reset();
       
   285     }
       
   286     
       
   287 // -----------------------------------------------------------------------------
       
   288 // CalculateNextEffectIndex.
       
   289 // -----------------------------------------------------------------------------
       
   290 TInt CShwDefaultEffectManager::CalculateNextEffectIndex( TInt aDirection )
       
   291 	{
       
   292 	TRACER("CShwDefaultEffectManager::CalculateNextEffectIndex");
       
   293 	GLX_LOG_INFO1( 
       
   294 	        "CShwDefaultEffectManager::CalculateNextEffectIndex %d", aDirection);
       
   295 	TInt effectsCount = iEffects.Count();	
       
   296 	// Guard against direction exceeding the number of effects
       
   297 	TInt direction = aDirection % effectsCount;	
       
   298 	TInt nextEffect = iCurrentEffect + direction;
       
   299 	
       
   300 	// ensure index is still in bounds
       
   301 	if ( nextEffect < 0 )
       
   302 		{
       
   303 		// -ve index: wrap around to the last element
       
   304 		nextEffect = effectsCount - 1;
       
   305 		}
       
   306 	else if ( nextEffect >= effectsCount )
       
   307 		{
       
   308 		// passed the end so return to the start.
       
   309 		nextEffect = 0;
       
   310 		}
       
   311 	return nextEffect;
       
   312 	}