uiacceltk/hitchcock/ServerCore/Src/alfsrvtranseffect.cpp
changeset 0 15bf7259bb7c
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2006 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:   Transition effect framework
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 #include "alflogger.h"
       
    23 #include "alf/alfappserver.h"
       
    24 #include "alf/alfappui.h"
       
    25 #include "alf/alfconstants.h"
       
    26 #include "alfsrvdisplaysubsession.h"
       
    27 #include "alfsrvcontrolgroupsubsession.h"
       
    28 #include "alfsrvsettingshandler.h"
       
    29 
       
    30 #include <coemain.h>
       
    31 #include <mm/mmcleanup.h>
       
    32 #include <pslninternalcrkeys.h>
       
    33 #include <centralrepository.h>
       
    34 #include <akntranseffect.h> 
       
    35 
       
    36 #include <uiacceltk/HuiControl.h>
       
    37 #include <uiacceltk/HuiControlGroup.h>
       
    38 #include <uiacceltk/HuiDisplay.h>
       
    39 #include <uiacceltk/HuiDisplayCoeControl.h>
       
    40 #include <uiacceltk/HuiEnv.h>
       
    41 #include <uiacceltk/HuiTextVisual.h>
       
    42 #include <uiacceltk/HuiTransformation.h>
       
    43 #include <uiacceltk/HuiBorderBrush.h>
       
    44 #include <uiacceltk/HuiImageVisual.h>
       
    45 #include <uiacceltk/HuiGridLayout.h>
       
    46 #include <uiacceltk/HuiTextureProcessor.h>
       
    47 #include <uiacceltk/HuiSegmentedTexture.h>
       
    48 
       
    49 
       
    50 #include "alfsrvtranseffect.h"
       
    51 
       
    52 
       
    53 // ============================ LOCAL CLASS ===============================
       
    54 
       
    55 /**
       
    56  * This helper class implements listener for any CenRep key. 
       
    57  *
       
    58  */
       
    59 NONSHARABLE_CLASS( CAlfCenRep ) : public CActive
       
    60     {
       
    61 public:  // New  
       
    62     static CAlfCenRep* NewL( TInt aPriority, const TUid& aRepository, TUint32 aKey );
       
    63     ~CAlfCenRep();
       
    64     
       
    65     /**
       
    66      * Gets the current stored value of the key.
       
    67      */
       
    68     TInt GetValue( TInt& aValue );
       
    69     
       
    70 private: // From CActive
       
    71     void RunL();
       
    72     void DoCancel();
       
    73     
       
    74 private: // New
       
    75     CAlfCenRep( TInt aPriority, const TUid& aRepository, TInt aKey );
       
    76     void ConstructL();
       
    77 
       
    78 private: // Data
       
    79 	CRepository *iCenRep;
       
    80     TUid iRepository;
       
    81     TInt iKey;
       
    82     TInt iValue;
       
    83     TInt iError;
       
    84     };
       
    85 
       
    86 
       
    87 // ============================ LOCAL CLASS MEMBER FUNCTIONS ================
       
    88 
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 CAlfCenRep::CAlfCenRep( TInt aPriority, const TUid& aRepository, TInt aKey ) :
       
    94     CActive( aPriority ),
       
    95     iRepository( aRepository ),
       
    96     iKey( aKey )
       
    97     {
       
    98     }
       
    99     
       
   100 // ---------------------------------------------------------------------------
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 void CAlfCenRep::ConstructL()
       
   104     {
       
   105     iCenRep = CRepository::NewL( iRepository );
       
   106     CActiveScheduler::Add( this );
       
   107     RunL();
       
   108     }
       
   109     
       
   110 // ---------------------------------------------------------------------------
       
   111 // ---------------------------------------------------------------------------
       
   112 //
       
   113 CAlfCenRep* CAlfCenRep::NewL( TInt aPriority, const TUid& aRepository, TUint32 aKey )
       
   114     {
       
   115     CAlfCenRep* self = new (ELeave) CAlfCenRep( aPriority, aRepository, aKey );
       
   116     CleanupStack::PushL( self );
       
   117     self->ConstructL();
       
   118     CleanupStack::Pop( self );
       
   119     return self;
       
   120     }
       
   121     
       
   122 // ---------------------------------------------------------------------------
       
   123 // ---------------------------------------------------------------------------
       
   124 //
       
   125 CAlfCenRep::~CAlfCenRep()
       
   126     {
       
   127     Cancel();
       
   128     delete iCenRep;
       
   129     }
       
   130     
       
   131 // ---------------------------------------------------------------------------
       
   132 // ---------------------------------------------------------------------------
       
   133 //
       
   134 void CAlfCenRep::RunL()
       
   135     {
       
   136     TInt value;
       
   137     iError = iCenRep->Get( iKey, value );
       
   138     if( iError == KErrNone )
       
   139     	{
       
   140     	iValue = value;
       
   141     	}
       
   142     iError = iCenRep->NotifyRequest( iKey, iStatus );
       
   143     
       
   144     if( iError == KErrNone )
       
   145     	{
       
   146     	SetActive();
       
   147     	}
       
   148     }
       
   149 // ---------------------------------------------------------------------------
       
   150 // ---------------------------------------------------------------------------
       
   151 //
       
   152 TInt CAlfCenRep::GetValue( TInt& aValue )
       
   153 	{
       
   154 	if(iError != KErrNone) //if we had an error eariler
       
   155 		{
       
   156 		TInt value;
       
   157 		iError = iCenRep->Get( iKey, value ); //try to get the value
       
   158 		if(iError == KErrNone)
       
   159 			{
       
   160 			iValue = value;
       
   161 			iError = iCenRep->NotifyRequest( iKey, iStatus ); //try to start request
       
   162 			if(iError == KErrNone)
       
   163 				{
       
   164 				SetActive();
       
   165 				}
       
   166 			}
       
   167 		}
       
   168 	aValue = iValue;
       
   169 	return iError;
       
   170 	}
       
   171 
       
   172 // ---------------------------------------------------------------------------
       
   173 // ---------------------------------------------------------------------------
       
   174 //
       
   175 void CAlfCenRep::DoCancel()
       
   176     {
       
   177     iCenRep->NotifyCancel( iKey );
       
   178     }
       
   179 
       
   180 
       
   181 
       
   182 // ======== MEMBER FUNCTIONS ========
       
   183 
       
   184 // ---------------------------------------------------------------------------
       
   185 // Constructors
       
   186 // ---------------------------------------------------------------------------
       
   187 //
       
   188 CAlfSrvTransEffect::CAlfSrvTransEffect()
       
   189     {
       
   190     }
       
   191 
       
   192 
       
   193 // ---------------------------------------------------------------------------
       
   194 // 
       
   195 // ---------------------------------------------------------------------------
       
   196 //
       
   197 CAlfSrvTransEffect* CAlfSrvTransEffect::NewL()
       
   198     {
       
   199     CAlfSrvTransEffect* me = new (ELeave) CAlfSrvTransEffect();
       
   200     CleanupStack::PushL(me);
       
   201     me->ConstructL();
       
   202     CleanupStack::Pop();
       
   203     return me;
       
   204     }
       
   205 
       
   206 
       
   207 // ---------------------------------------------------------------------------
       
   208 // 
       
   209 // ---------------------------------------------------------------------------
       
   210 //
       
   211 void CAlfSrvTransEffect::ConstructL()
       
   212     {    
       
   213     // Load transition effect plugins
       
   214 	PopulateEffectArrayL();
       
   215     
       
   216     if (iEffectPlugins.Count() > 0)
       
   217     	{
       
   218     	iIsEnabled = ETrue;
       
   219     	}
       
   220         
       
   221     // Start listening Avkon effect system state 
       
   222     iAvkonTfxStateListener = CAlfCenRep::NewL( 
       
   223     	EPriorityHigh, KCRUidThemes, KThemesTransitionEffects );   
       
   224     }
       
   225 
       
   226 
       
   227 // ---------------------------------------------------------------------------
       
   228 // Destructor
       
   229 // ---------------------------------------------------------------------------
       
   230 //
       
   231 CAlfSrvTransEffect::~CAlfSrvTransEffect()
       
   232     {
       
   233     delete iAvkonTfxStateListener;
       
   234     
       
   235 	iEffectPlugins.ResetAndDestroy();
       
   236 	
       
   237 	iEffectMap.Close();
       
   238     
       
   239    	REComSession::FinalClose(); 
       
   240     }
       
   241 
       
   242 
       
   243 // -----------------------------------------------------------------------------
       
   244 // Get a list of plugin implementations via ECom, construct the plugins and 
       
   245 // add them to the array.
       
   246 // -----------------------------------------------------------------------------
       
   247 //
       
   248 void CAlfSrvTransEffect::PopulateEffectArrayL()
       
   249 	{
       
   250 	// Get a list of all plugins from ECom
       
   251 	TEComResolverParams resolverParams;
       
   252 	resolverParams.SetDataType ( KAlfTransEffectPluginTypeStringDesc );
       
   253 	resolverParams.SetWildcardMatch ( EFalse );
       
   254 	RImplInfoPtrArray implInfoArray;
       
   255 	REComSession::ListImplementationsL( KAlfTransEffectPluginInterfaceUid, 
       
   256 		resolverParams, implInfoArray );
       
   257 	CleanupResetAndDestroyPushL( implInfoArray ); // Note: intentionally called only after ListImplementationsL()
       
   258     
       
   259 	__ALFLOGSTRING1("ALF: CAlfSrvTransEffect::PopulateExtensionArrayL(): extension count: %d",
       
   260 		implInfoArray.Count())
       
   261 	
       
   262 	// Create each plugin via ECom and add it to the list 
       
   263 	for ( TInt i = 0; i < implInfoArray.Count(); i++ )
       
   264 		{		
       
   265 		MAlfTransEffectPlugin* plugin = NULL;
       
   266 		
       
   267 		// Trap the construction as if one plugin fails to construct it 
       
   268 		// should not stop others from constructing
       
   269 		TRAPD( error, plugin = reinterpret_cast <MAlfTransEffectPlugin*> ( REComSession::CreateImplementationL( 
       
   270 			implInfoArray[i]->ImplementationUid(), _FOFF (MAlfTransEffectPlugin, iDtor_ID_Key) ) ) );
       
   271 	
       
   272 		TInt countAddedEffects = 0;
       
   273 		if ( !error && ( plugin != NULL ) )
       
   274 			{
       
   275 			RArray<TInt> effectIds;
       
   276 			CleanupClosePushL( effectIds );
       
   277 			
       
   278 			plugin->GetSupportedEffects( effectIds );
       
   279 			TInt count = effectIds.Count();
       
   280 			if ( count > 0 )
       
   281 				{
       
   282 				for ( TInt ii = 0; ii < count; ii++ )
       
   283 					{
       
   284 					TInt mapError = iEffectMap.InsertInSignedKeyOrder( CAlfSrvTransEffect::TEffectMapItem( effectIds[ii], plugin ) );
       
   285 					if ( mapError == KErrNone ) 
       
   286 						{
       
   287 						countAddedEffects++;
       
   288 						}
       
   289 					else // You cannot insert duplicate effects (with same effect ID)
       
   290 						{
       
   291 						__ALFLOGSTRING3("Alf: CAlfSrvTransEffect::PopulateExtensionArrayL. Cannot insert effect id to the map array. Imp.uid=%d, effect id=%d, error=%d", 						
       
   292 							implInfoArray[i]->ImplementationUid().iUid, effectIds[ii], error)
       
   293 						}
       
   294 					}
       
   295 				}
       
   296 			CleanupStack::PopAndDestroy( &effectIds );
       
   297 			}
       
   298 		
       
   299 		// Add plugin to the array if it has at least one effect that has been
       
   300 		// successfully registered.	
       
   301 		if ( !error && ( plugin != NULL ) && ( countAddedEffects > 0 ) )
       
   302 			{
       
   303 			iEffectPlugins.AppendL( plugin );
       
   304 			}
       
   305 		else
       
   306 			{
       
   307 			// If the plugin is failing we skip that.
       
   308 			__ALFLOGSTRING3("Alf: CAlfSrvTransEffect::PopulateExtensionArrayL. Cannot add plugin, uid=%d, error=%d, plugin=%d", 
       
   309 				implInfoArray[i]->ImplementationUid().iUid, error, plugin )
       
   310 			__ALFLOGSTRING1("                                                  countAddedEffects=%d", 
       
   311 				countAddedEffects )
       
   312 			delete( plugin );
       
   313 			}		
       
   314 		} // for
       
   315 
       
   316 	CleanupStack::PopAndDestroy( &implInfoArray );
       
   317 	}
       
   318 
       
   319 
       
   320 // ---------------------------------------------------------------------------
       
   321 // 
       
   322 // ---------------------------------------------------------------------------
       
   323 //
       
   324 TBool CAlfSrvTransEffect::IsEnabled()
       
   325 	{
       
   326 	TInt value;
       
   327 	iAvkonTfxStateListener->GetValue( value );
       
   328 	TBool isAvkonEffectsEnabled = ( value != KMaxTInt );
       
   329 	return( iIsEnabled &&  !isAvkonEffectsEnabled );
       
   330 	}    
       
   331     
       
   332 // ---------------------------------------------------------------------------
       
   333 // 
       
   334 // ---------------------------------------------------------------------------
       
   335 //
       
   336 TInt CAlfSrvTransEffect::StartPhase( 
       
   337     TInt aPhaseId, TInt aContext, 
       
   338     CAlfSrvEffectEnv& aEffectEnv, 
       
   339     TInt /*aUidValue*/, 
       
   340     TInt /*aKey*/, 
       
   341     TInt /*aUidValue2*/, 
       
   342     TInt /*aKey2*/, 
       
   343     const TDesC8* aParams)
       
   344 	{
       
   345 	if ( IsEnabled() )
       
   346 		{		
       
   347 		// Find the plugin which implements the effect related to this context and call it
       
   348 		MAlfTransEffectPlugin* plugin = NULL;
       
   349 		if ( FindPlugin( aContext,  &plugin ) == KErrNone )
       
   350 			{
       
   351 			// Update state
       
   352 			iCurrContext = aContext;
       
   353 			iCurrPhase = aPhaseId;
       
   354 			
       
   355 			// Call plugin
       
   356 			ASSERT( plugin != NULL );
       
   357 			plugin->StartPhase( aPhaseId, aContext, aEffectEnv, aParams );
       
   358 			}
       
   359 		}
       
   360 		
       
   361 	return KErrNone;	
       
   362 	}    
       
   363     
       
   364 // ---------------------------------------------------------------------------
       
   365 // 
       
   366 // ---------------------------------------------------------------------------
       
   367 //
       
   368 TInt CAlfSrvTransEffect::Abort( TInt /*aContext*/, TInt /*aUidValue*/, TInt /*aKey*/ )
       
   369 	{
       
   370 	return KErrNone;
       
   371 	}    
       
   372     
       
   373     
       
   374 // ---------------------------------------------------------------------------
       
   375 // 
       
   376 // ---------------------------------------------------------------------------
       
   377 //
       
   378 TInt CAlfSrvTransEffect::SetProperty( TInt /*aProperty*/, TInt /*aValue*/, TInt /*aUidValue*/, TInt /*aKey*/ )
       
   379 	{
       
   380 	return KErrNone;
       
   381 	}    
       
   382     
       
   383     
       
   384 // ---------------------------------------------------------------------------
       
   385 // 
       
   386 // ---------------------------------------------------------------------------
       
   387 //
       
   388 TInt CAlfSrvTransEffect::GetProperty( TInt /*aProperty*/, TInt& /*aValue*/, TInt /*aUidValue*/, TInt /*aKey*/ )
       
   389 	{
       
   390 	return KErrNone;
       
   391 	}    
       
   392     
       
   393     
       
   394 // ---------------------------------------------------------------------------
       
   395 // 
       
   396 // ---------------------------------------------------------------------------
       
   397 //
       
   398 TInt CAlfSrvTransEffect::AddEventObserver( MAlfTransEffectObserver* /*aObserver*/, TInt /*aEvents*/, const TDesC8* /*aParams*/ )
       
   399 	{
       
   400 	return KErrNone;
       
   401 	}    
       
   402     
       
   403     
       
   404 // ---------------------------------------------------------------------------
       
   405 // 
       
   406 // ---------------------------------------------------------------------------
       
   407 //
       
   408 TInt CAlfSrvTransEffect::RemoveEventObserver( MAlfTransEffectObserver* /*aObserver*/, TInt /*aEvents*/ )
       
   409 	{
       
   410 	return KErrNone;
       
   411 	}    
       
   412    
       
   413     
       
   414 // ---------------------------------------------------------------------------
       
   415 // 
       
   416 // ---------------------------------------------------------------------------
       
   417 //
       
   418 TInt CAlfSrvTransEffect::GetEventState( TInt /*aEvent*/, TInt* /*aState*/, TDes8* /*aParams*/ )
       
   419 	{
       
   420 	return KErrNotReady;
       
   421 	}    
       
   422     
       
   423 // ---------------------------------------------------------------------------
       
   424 // 
       
   425 // ---------------------------------------------------------------------------
       
   426 //
       
   427 TInt CAlfSrvTransEffect::FindPlugin( TInt aContext, MAlfTransEffectPlugin** aPlugin ) 
       
   428 	{
       
   429 	// Note: Now the context id is the same as effect id, but this can change in the future
       
   430 	CAlfSrvTransEffect::TEffectMapItem item( aContext, NULL );
       
   431 	TInt index;
       
   432 	if ( iEffectMap.FindInSignedKeyOrder( item, index ) == KErrNone )
       
   433 		{
       
   434 		*aPlugin = iEffectMap[index].iPluginPtr;
       
   435 		return KErrNone;
       
   436 		}
       
   437 	else
       
   438 		{
       
   439 		return KErrNotFound;
       
   440 		}
       
   441 	}    
       
   442     
       
   443     
       
   444 
       
   445 // End of file    
       
   446