uiacceltk/hitchcock/ServerCore/Src/alfappsrvsession.cpp
changeset 0 15bf7259bb7c
child 6 10534483575f
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:   Server session
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <flogger.h>
       
    20 #include "alfappsrvsession.h"
       
    21 #include "alf/alfappserver.h"
       
    22 #include "alf/alfappui.h"
       
    23 #include "alf/alfconstants.h"
       
    24 #include "alf/alfclientwindow.h"
       
    25 #include "alfsrvdisplaysubsession.h"
       
    26 #include "alfsrvcontrolgroupsubsession.h"
       
    27 #include "alfsrvsettingshandler.h"
       
    28 #include "alfsrvtranseffect.h"
       
    29 #include "alf/alfsrveffectenv.h"
       
    30 #include "alf/alfserverutils.h"
       
    31 #include "alflogger.h"
       
    32 #include "alfclientserver.h"
       
    33 #include "alfsrvtexturemanager.h"
       
    34 #include "alfsrvscreenbuffermanager.h"
       
    35 
       
    36 #include <coemain.h>
       
    37 
       
    38 #include <alf/alfroster.h>
       
    39 #include <alf/alftexture.h>
       
    40 
       
    41 #include <uiacceltk/HuiControl.h>
       
    42 #include <uiacceltk/HuiControlGroup.h>
       
    43 #include <uiacceltk/HuiDisplay.h>
       
    44 #include <uiacceltk/HuiDisplayCoeControl.h>
       
    45 #include <uiacceltk/HuiEnv.h>
       
    46 #include <uiacceltk/HuiTextVisual.h>
       
    47 #include <uiacceltk/HuiTransformation.h>
       
    48 #include <uiacceltk/HuiBorderBrush.h>
       
    49 #include <uiacceltk/HuiImageVisual.h>
       
    50 #include <uiacceltk/HuiGridLayout.h>
       
    51 #include <uiacceltk/HuiTextureProcessor.h>
       
    52 #include <uiacceltk/HuiSegmentedTexture.h>
       
    53 #include <uiacceltk/huitextstylemanager.h>
       
    54 #include <uiacceltk/huitextstyle.h>
       
    55 #include <uiacceltk/HuiFont.h>
       
    56 #include <uiacceltk/HuiTexture.h>
       
    57 #include <uiacceltk/HuiUtil.h>
       
    58 
       
    59 _LIT( KAlfFPSLogDir, "alf"); // remember to create the c:\logs\alf in order to enable logging
       
    60 _LIT( KAlfFPSLogFile, "alffpslog.txt");
       
    61     
       
    62 
       
    63 const TReal32 KAlfUseDefaultFrameRate = 0.f;
       
    64 
       
    65 TBool RealCompare( 
       
    66     TReal32 aCompare1, 
       
    67     TReal32 aCompare2, 
       
    68     TReal32 aEpsilon = 0.001f  )
       
    69     {
       
    70     if ( Abs(aCompare1 - aCompare2) < aEpsilon )
       
    71         {
       
    72         return ETrue;
       
    73         }
       
    74     return EFalse;
       
    75     }
       
    76 
       
    77 /**
       
    78  * Size of command batch buffer allocated from stack.
       
    79  * (This is used if all else fails)
       
    80  */
       
    81 const TInt KAlfStackBatchBufferSize = 128;
       
    82 
       
    83 // bitmap provider
       
    84 
       
    85 NONSHARABLE_CLASS(CSharedBitmapProvider) : public CBase, public MHuiBitmapProvider
       
    86 	{
       
    87 public:
       
    88 	CSharedBitmapProvider();
       
    89 	CSharedBitmapProvider(TInt aBitmapHandle, TInt aMaskHandle);
       
    90 	~CSharedBitmapProvider();
       
    91 	// from MHuiBitmapProvider	
       
    92 	void ProvideBitmapL(TInt aId, CFbsBitmap*& aBitmap, CFbsBitmap*& aMaskBitmap);				
       
    93 private:
       
    94 	TInt iBitmapHandle;
       
    95 	TInt iMaskHandle;
       
    96 	};
       
    97 
       
    98 CSharedBitmapProvider::CSharedBitmapProvider()
       
    99 	{
       
   100 		
       
   101 	}
       
   102 
       
   103 CSharedBitmapProvider::CSharedBitmapProvider(TInt aBitmapHandle, TInt aMaskHandle)
       
   104 	{
       
   105 	iBitmapHandle = aBitmapHandle;
       
   106 	iMaskHandle = aMaskHandle;	
       
   107 	}
       
   108 
       
   109 CSharedBitmapProvider::~CSharedBitmapProvider()
       
   110 	{
       
   111 	}
       
   112 
       
   113 void CSharedBitmapProvider::ProvideBitmapL(TInt /*aId*/, CFbsBitmap*& aBitmap, CFbsBitmap*& aBitmapMask)
       
   114 	{
       
   115 	CFbsBitmap* bitmap(0);
       
   116 	CFbsBitmap* mask(0);
       
   117 	
       
   118 	if (iBitmapHandle) // mandatory
       
   119 	    {
       
   120 	    bitmap = new (ELeave) CFbsBitmap;
       
   121 	    CleanupStack::PushL(bitmap);
       
   122 	    bitmap->Reset();
       
   123 	    User::LeaveIfError(bitmap->Duplicate(iBitmapHandle));
       
   124 	    }
       
   125 	else
       
   126 	    {
       
   127 	    User::Leave(KErrArgument);
       
   128 	    }
       
   129 	       
       
   130 	if ( iMaskHandle ) // optional
       
   131 	    {
       
   132      	mask = new (ELeave) CFbsBitmap;
       
   133 	    CleanupStack::PushL(mask);
       
   134 	    mask->Reset();
       
   135 	    User::LeaveIfError(mask->Duplicate(iMaskHandle));
       
   136 	    CleanupStack::Pop(); // mask
       
   137 	    }
       
   138 	
       
   139     CleanupStack::Pop(); // bitmap
       
   140     aBitmapMask = mask; 	
       
   141     aBitmap = bitmap; 	
       
   142     }
       
   143 
       
   144 
       
   145 
       
   146 // ======== MEMBER FUNCTIONS ========
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 // Constructor
       
   150 // ---------------------------------------------------------------------------
       
   151 //
       
   152 CAlfAppSrvSession::CAlfAppSrvSession(const CAlfAppServer* aServer)
       
   153     : CAlfAppSrvSessionBase(aServer),
       
   154       iExecutionFlags( 
       
   155         EAlfExecuteUsingDynamicBuffer + EAlfExecuteUsingCommonBuffer )
       
   156     {
       
   157     }
       
   158 
       
   159 CAlfAppSrvSession* CAlfAppSrvSession::NewL(const CAlfAppServer* aServer)
       
   160     {
       
   161     CAlfAppSrvSession* me = new (ELeave) CAlfAppSrvSession(aServer);
       
   162     CleanupStack::PushL(me);
       
   163     me->ConstructL();
       
   164     CleanupStack::Pop();
       
   165     return me;
       
   166     }
       
   167 
       
   168 void CAlfAppSrvSession::ConstructL()
       
   169     {
       
   170     BaseConstructL();
       
   171     
       
   172     AlfServer()->SetWindowChangeObserverL(this, TInt(this)); 
       
   173     
       
   174     iRefreshMode = EHuiRefreshModeAutomatic;
       
   175     iMaxFrameRate = KAlfUseDefaultFrameRate;
       
   176     iIdleThreshold = 10 * 1000; // 10 from HuiEnv as seconds
       
   177     iEffectEnv = CAlfSrvEffectEnv::NewL(*this);
       
   178     }
       
   179 
       
   180 // ---------------------------------------------------------------------------
       
   181 // Destructor
       
   182 // ---------------------------------------------------------------------------
       
   183 //
       
   184 CAlfAppSrvSession::~CAlfAppSrvSession()
       
   185     {
       
   186     iOwnershipItems.ResetAndDestroy();    
       
   187     
       
   188     if ( iTextureOwnedIdSet )
       
   189         {
       
   190         CAlfSrvTextureManager& manager = AlfTextureManager();
       
   191         TProcessId ownerId = TextureOwnerId();
       
   192         manager.DestroyDeletedTextureIds( ownerId );
       
   193         manager.RemoveClient( *this );
       
   194         }
       
   195     iTextures.ResetAndDestroy();        
       
   196     iAnimatedTextures.ResetAndDestroy();
       
   197     
       
   198     delete iEffectEnv;
       
   199     iEffectEnv = NULL;
       
   200     
       
   201     iTextureInfo.Close();
       
   202     
       
   203     iControlGroupOrder.Close();
       
   204     }
       
   205 
       
   206 
       
   207 TRect CAlfAppSrvSession::ClientDrawingArea() const
       
   208     {
       
   209     return iClientDisplayRect;
       
   210     }
       
   211     
       
   212 void CAlfAppSrvSession::SetClientDrawingArea( const TRect& aRect )
       
   213     {
       
   214     TRAP_IGNORE(SetClientDrawingAreaL(aRect))
       
   215     }
       
   216 
       
   217 void CAlfAppSrvSession::SetClientDrawingAreaL( const TRect& aRect )
       
   218     {
       
   219     iClientDisplayRect = aRect;
       
   220     
       
   221     // Update all the control groups
       
   222     RPointerArray<CAlfSrvSubSessionBase> groups;
       
   223     CleanupClosePushL( groups );
       
   224     GetSubsessionsByTypeL( groups, EHuiObjectTypeControlGroup );
       
   225     for ( TInt g = 0 ; g < groups.Count() ; g++ )
       
   226         {
       
   227         CHuiControlGroup* group = groups[g]->AsHuiControlCroup();
       
   228         ASSERT( group ); 
       
   229         CHuiLayout* hostContainer = group->Control(0).ContainerLayout( NULL );
       
   230         
       
   231         hostContainer->SetSize( iClientDisplayRect.Size() );
       
   232         hostContainer->SetPos( iClientDisplayRect.iTl );
       
   233         }
       
   234     CleanupStack::PopAndDestroy( &groups ); // groups.Close()
       
   235     }
       
   236     
       
   237 // ---------------------------------------------------------------------------
       
   238 // From class CAlfAppSrvSessionBase.
       
   239 // Called when client receives focus.
       
   240 // ---------------------------------------------------------------------------
       
   241 //   
       
   242 void CAlfAppSrvSession::FocusGainedL( TBool aDoTransitionEffect )
       
   243     {
       
   244     iFocused = ETrue;
       
   245     DeliverTextureInfo();
       
   246     
       
   247     // update frame rate
       
   248     if ( RealCompare( iMaxFrameRate, KAlfUseDefaultFrameRate ) )
       
   249         {
       
   250         SharedHuiEnv()->SetMaxFrameRate( 
       
   251             TReal32(AlfAppUi()->SettingsHandler().DefaultFramerate()) );
       
   252         }
       
   253     else
       
   254         {
       
   255         SharedHuiEnv()->SetMaxFrameRate( iMaxFrameRate );
       
   256         }
       
   257     
       
   258     // update refresh mode
       
   259     if ( SharedHuiEnv()->RefreshMode() != iRefreshMode )
       
   260         {
       
   261         SharedHuiEnv()->SetRefreshMode( iRefreshMode );
       
   262         }
       
   263 
       
   264     // update idle threshold
       
   265     SharedHuiEnv()->SetIdleThreshold( iIdleThreshold );
       
   266     
       
   267     // update display attributes for each display
       
   268     CHuiDisplay* display = NULL;
       
   269     RPointerArray<CAlfSrvSubSessionBase> displays;
       
   270     CleanupClosePushL( displays );
       
   271     GetSubsessionsByTypeL( displays, EHuiObjectTypeDisplay );
       
   272     for ( TInt d = 0 ; d < displays.Count() ; d++ )
       
   273         {
       
   274         CAlfSrvDisplaySubSession* displaySubSession = 
       
   275                 static_cast<CAlfSrvDisplaySubSession*>( displays[d] );     
       
   276         displaySubSession->SetSessionFocused();
       
   277         if ( !display && !displaySubSession->IsTvOut())
       
   278             {
       
   279             display = &displaySubSession->Display();
       
   280             }
       
   281         }     
       
   282     CleanupStack::PopAndDestroy( &displays ); // displays.Close()
       
   283     
       
   284     if ( !display )
       
   285         {
       
   286         return;
       
   287         }
       
   288     
       
   289     // Enable animated textures for the session
       
   290     for (TInt index = 0; index < iAnimatedTextures.Count(); index++)
       
   291         {
       
   292        	iAnimatedTextures.operator[](index)->EnableAnimation(ETrue);     
       
   293         }
       
   294 
       
   295     if ( aDoTransitionEffect && AlfServer()->TransitionEffects()->IsEnabled() &&
       
   296          (display->DisplayType() != CHuiDisplay::EDisplayOffScreenBuffer))        
       
   297         {
       
   298        	ASSERT(AlfServer()->TransitionEffects() != NULL);
       
   299        	AlfServer()->TransitionEffects()->StartPhase( MAlfTransEffectPlugin::EFirstPhase, 
       
   300        	    aDoTransitionEffect, *iEffectEnv );            
       
   301        	
       
   302        	iControlGroupOrder.Reset();
       
   303         }
       
   304     else
       
   305         {
       
   306         ShowControlGroupsInOrderL(*display);
       
   307         }    
       
   308 
       
   309 	// This is needed for Huitk BitBlit() to succeed 
       
   310     
       
   311 #ifdef SYMBIAN_BUILD_GCE
       
   312     SharedHuiEnv()->ContinueRefresh();
       
   313 #else
       
   314     AlfAppUi()->Container()->DrawNow();
       
   315 #endif
       
   316     }
       
   317     
       
   318 // ---------------------------------------------------------------------------
       
   319 // From class CAlfAppSrvSessionBase.
       
   320 // Called when client loses focus.
       
   321 // ---------------------------------------------------------------------------
       
   322 //
       
   323 TBool CAlfAppSrvSession::FocusLostL( TBool aDoTransitionEffect )
       
   324     {
       
   325     iFocused = EFalse;
       
   326 
       
   327     TBool didTransition = EFalse;
       
   328     
       
   329     if ( !SharedHuiEnv()->DisplayCount() )
       
   330         {
       
   331         return EFalse;
       
   332         }
       
   333 
       
   334     // Notify displays about losing focus so that tv out can be released
       
   335     CHuiDisplay* display = NULL;
       
   336     RPointerArray<CAlfSrvSubSessionBase> displays;
       
   337     CleanupClosePushL( displays );
       
   338     GetSubsessionsByTypeL( displays, EHuiObjectTypeDisplay );
       
   339     for ( TInt d = 0 ; d < displays.Count() ; d++ )
       
   340         {
       
   341         CAlfSrvDisplaySubSession* displaySubSession = 
       
   342                 static_cast<CAlfSrvDisplaySubSession*>( displays[d] );     
       
   343         displaySubSession->SetSessionFocused(EFalse);
       
   344         if ( !display && !displaySubSession->IsTvOut())
       
   345             {
       
   346             display = &displaySubSession->Display();
       
   347             }
       
   348             
       
   349         }     
       
   350     CleanupStack::PopAndDestroy( &displays ); // displays.Close()
       
   351 
       
   352     if ( !display )
       
   353         {
       
   354         return didTransition;
       
   355         }
       
   356 
       
   357 /*        
       
   358 #ifdef HUI_FX
       
   359 */
       
   360     if (display->DisplayType() != CHuiDisplay::EDisplayOffScreenBuffer) 
       
   361     	{
       
   362     	// Disable all animated textures for the session
       
   363     	for (TInt index = 0; index < iAnimatedTextures.Count(); index++)
       
   364         	{
       
   365       		iAnimatedTextures.operator[](index)->EnableAnimation(EFalse); 
       
   366         	}
       
   367        	
       
   368       	StoreControlGroupOrderL(*display, EFalse ); // do not hide  
       
   369        	// background must be drawn as long as the effect is displayed 
       
   370        	// as the background will be visible if the effect does not cover full screen
       
   371        	// or is partially transparent.
       
   372     	}
       
   373 /*    	
       
   374 #else
       
   375     // Do not hide or set transparency if this is off-screen buffer         
       
   376     if (display->DisplayType() != CHuiDisplay::EDisplayOffScreenBuffer) 
       
   377     	{
       
   378     	// Disable all animated textures for the session
       
   379     	for (TInt index = 0; index < iAnimatedTextures.Count(); index++)
       
   380         	{
       
   381       		iAnimatedTextures.operator[](index)->EnableAnimation(EFalse); 
       
   382         	}
       
   383 
       
   384      	if ( aDoTransitionEffect && AlfServer()->TransitionEffects()->IsEnabled() )
       
   385         	{
       
   386         	StoreControlGroupOrderL(*display, EFalse ); // do not hide  
       
   387         	ASSERT(AlfServer()->TransitionEffects() != NULL);
       
   388         	AlfServer()->TransitionEffects()->StartPhase( MAlfTransEffectPlugin::EFirstPhase, 
       
   389             	aDoTransitionEffect, *iEffectEnv );            
       
   390         	didTransition = ETrue;
       
   391         	}
       
   392     	// Hide control groups 
       
   393     	else 
       
   394         	{
       
   395         	StoreControlGroupOrderL(*display, ETrue ); // hide as well     
       
   396     		}
       
   397     		
       
   398 #ifdef SYMBIAN_BUILD_GCE
       
   399         // When alf application is not focused we dont draw background because it is
       
   400         // not visible as the alf application is not visible either (its controlgroups
       
   401         // were just hidden in the code above).
       
   402    	    display->SetClearBackgroundL(CHuiDisplay::EClearNone);
       
   403 #endif
       
   404     	}
       
   405 #endif    		
       
   406 */
       
   407     
       
   408     return didTransition;
       
   409     }
       
   410 
       
   411 void CAlfAppSrvSession::StoreControlGroupOrderL(CHuiDisplay& aDisplay, TBool aAlsoHide )
       
   412     {
       
   413     for ( TInt g = 0 ; g < aDisplay.Roster().Count() ; g++ )
       
   414         {
       
   415         // first append the bottom one
       
   416         CHuiControlGroup& group = aDisplay.Roster().ControlGroup( g );
       
   417         
       
   418         // make sure we only store control groups for this session
       
   419         if ( GetHandleFromInterface(EHuiObjectTypeControlGroup, &group) != KErrNotFound )
       
   420             {
       
   421             iControlGroupOrder.AppendL( &group );
       
   422             }
       
   423         }
       
   424     // at the end the lowest index the bottom most and the biggest index the top most.
       
   425     
       
   426     // hide at the end so it does not affect the order of the group in the roster
       
   427     if ( aAlsoHide )
       
   428         {
       
   429         for ( TInt i = 0 ; i < iControlGroupOrder.Count() ; i++ )
       
   430             {
       
   431             CHuiLayout* hostContainer = iControlGroupOrder[i]->Control(0).ContainerLayout( NULL );
       
   432             hostContainer->iOpacity.Set(0.f); 
       
   433             aDisplay.Roster().Hide( *iControlGroupOrder[i] );
       
   434             }
       
   435         }
       
   436     }
       
   437     
       
   438 void CAlfAppSrvSession::ShowControlGroupsInOrderL(CHuiDisplay& aDisplay)
       
   439     {
       
   440     while ( iControlGroupOrder.Count() )
       
   441         {
       
   442         CHuiControlGroup& group = *iControlGroupOrder[iControlGroupOrder.Count()-1];
       
   443         
       
   444         // make sure that the group still exists.
       
   445         if ( GetHandleFromInterface(EHuiObjectTypeControlGroup, &group) != KErrNotFound )
       
   446             {
       
   447             CHuiLayout* hostContainer = group.Control(0).ContainerLayout( NULL );
       
   448             hostContainer->iOpacity.Set(1.f); 
       
   449 #ifdef SYMBIAN_BUILD_GCE
       
   450             AlfAppUi()->ShowControlGroupL(aDisplay.Roster(), group, KAlfRosterShowAtBottom, 0); 
       
   451 #else    
       
   452             aDisplay.Roster().ShowL( group, KAlfRosterShowAtBottom );
       
   453 #endif
       
   454             iControlGroupOrder.Remove(iControlGroupOrder.Count()-1);
       
   455             }
       
   456         }
       
   457     iControlGroupOrder.Reset();
       
   458     }
       
   459     
       
   460 void CAlfAppSrvSession::ReOrderControlGroupSessionsL( RPointerArray<CAlfSrvSubSessionBase>& aGroupSessions )
       
   461     {
       
   462     if ( iControlGroupOrder.Count() && aGroupSessions.Count() > 1 )
       
   463         {
       
   464         // go through the items from bottom to top
       
   465         for ( TInt g = iControlGroupOrder.Count() -1 ; g >= 0 ; g-- ) 
       
   466             {
       
   467             CHuiControlGroup* nextGroupFromBottom = iControlGroupOrder[g];
       
   468             
       
   469             // Find the session and move it into first position
       
   470             for ( TInt s = 0 ; s < aGroupSessions.Count() ; s++ )
       
   471                 {
       
   472                 CAlfSrvControlGroupSubSession* controlGroupSubSession = static_cast<CAlfSrvControlGroupSubSession*>( aGroupSessions[s] );   
       
   473                 if ( &controlGroupSubSession->ControlGroup() == nextGroupFromBottom )
       
   474                     {
       
   475                     // move into g:th position
       
   476                     aGroupSessions.Remove( s );
       
   477                     User::LeaveIfError( aGroupSessions.Insert( controlGroupSubSession, 0 ) );
       
   478                     }
       
   479                 }
       
   480             }
       
   481         }
       
   482     }
       
   483 
       
   484 void CAlfAppSrvSession::SetBackgroundMaxFps( TBool aBackground )
       
   485     {
       
   486     
       
   487     TReal32 newMaxFrameRate = 0;
       
   488     
       
   489     // update frame rate
       
   490     if ( RealCompare( iMaxFrameRate, KAlfUseDefaultFrameRate ) )
       
   491         {
       
   492         newMaxFrameRate = TReal32( AlfAppUi()->SettingsHandler().DefaultFramerate() );
       
   493         SharedHuiEnv()->SetMaxFrameRate( 
       
   494             TReal32(AlfAppUi()->SettingsHandler().DefaultFramerate()) );
       
   495         }
       
   496     else
       
   497         {
       
   498         newMaxFrameRate = iMaxFrameRate;
       
   499         }    
       
   500     
       
   501     if( aBackground )
       
   502         {  
       
   503         newMaxFrameRate /= 2;
       
   504         }
       
   505     SharedHuiEnv()->SetMaxFrameRate( newMaxFrameRate );
       
   506     }
       
   507 
       
   508 
       
   509 // ---------------------------------------------------------------------------
       
   510 // Is client application focused?
       
   511 // ---------------------------------------------------------------------------
       
   512 //    
       
   513 TBool CAlfAppSrvSession::IsFocused() const
       
   514     {
       
   515     return iFocused;
       
   516     }
       
   517     
       
   518     
       
   519 // ---------------------------------------------------------------------------
       
   520 // From class MWindowVisibilityObserver.
       
   521 // Called when window becomes fully visible.
       
   522 // ---------------------------------------------------------------------------
       
   523 //
       
   524 void CAlfAppSrvSession::WindowFullyVisible()
       
   525     {
       
   526     iPartiallyVisible = ETrue;
       
   527     DeliverTextureInfo();
       
   528     }
       
   529    
       
   530 // ---------------------------------------------------------------------------
       
   531 // From class MWindowVisibilityObserver.
       
   532 // Called when window becomes partially visible.
       
   533 // ---------------------------------------------------------------------------
       
   534 // 
       
   535 void CAlfAppSrvSession::WindowPartiallyVisible()
       
   536     {
       
   537     iPartiallyVisible = ETrue;
       
   538     DeliverTextureInfo();
       
   539     }
       
   540     
       
   541 // ---------------------------------------------------------------------------
       
   542 // From class MWindowVisibilityObserver.
       
   543 // Called when window becomes fully invisible.
       
   544 // ---------------------------------------------------------------------------
       
   545 //
       
   546 void CAlfAppSrvSession::WindowNotVisible()
       
   547     {
       
   548     // already not shown...
       
   549     if ( !iPartiallyVisible )
       
   550         {
       
   551         return;
       
   552         }
       
   553     iPartiallyVisible = EFalse;
       
   554     }
       
   555 
       
   556 // ---------------------------------------------------------------------------
       
   557 // From class MWindowVisibilityObserver.
       
   558 // Returns window-owning control.
       
   559 // ---------------------------------------------------------------------------
       
   560 //
       
   561 CCoeControl* CAlfAppSrvSession::CoeControl()
       
   562     {
       
   563     return NULL;//iCoeDisplay;
       
   564     }
       
   565 
       
   566 CAlfAppServer::TAlfWGPostion CAlfAppSrvSession::PreferredWindowGroupPosition() const
       
   567     {
       
   568     if ( iUsesFullScreen )
       
   569         {
       
   570         return CAlfAppServer::EOnTopOfParent;
       
   571         }
       
   572     else
       
   573         {
       
   574         return CAlfAppServer::EBehindOfParent;
       
   575         }
       
   576     }
       
   577     
       
   578 THuiRefreshMode CAlfAppSrvSession::PreferredRefreshMode() const
       
   579     {
       
   580     return iRefreshMode;
       
   581     }
       
   582 
       
   583 
       
   584 // ---------------------------------------------------------------------------
       
   585 // From class CAlfAppSrvSessionBase.
       
   586 // Called when a message is received from the client.
       
   587 // ---------------------------------------------------------------------------
       
   588 //
       
   589 void CAlfAppSrvSession::DoHandleCommandL(const RMessage2& aMessage)
       
   590     {
       
   591     switch( aMessage.Function() )
       
   592         {
       
   593         case EAlfQtCommandBuffer:
       
   594             {
       
   595             PostQtCommandBufferL( aMessage );
       
   596             break;
       
   597             }
       
   598         
       
   599 		case EAlfEnvSetRefreshMode:
       
   600             {
       
   601             EnvSetRefreshModeL( aMessage );
       
   602             break;    
       
   603             }
       
   604             
       
   605         case EAlfEnvSetMaxFrameRate:
       
   606             {
       
   607             EnvSetMaxFrameRateL( aMessage );
       
   608             break;
       
   609             }
       
   610             
       
   611         case EAlfEnvContinueRefresh:
       
   612             {
       
   613             EnvContinueRefreshL( aMessage );
       
   614             break;
       
   615             }
       
   616             
       
   617         case EAlfEnvPauseRefresh:
       
   618             {
       
   619             EnvPauseRefreshL( aMessage );
       
   620             break;
       
   621             }
       
   622             
       
   623         case EAlfEnvRefreshCallBack:
       
   624             {
       
   625             EnvRefreshCallBackL( aMessage );
       
   626             break;
       
   627             }
       
   628             
       
   629         case EAlfEnvRenderer:
       
   630             {
       
   631             EnvRendererL( aMessage );
       
   632             break;
       
   633             }
       
   634         case EAlfEnvSetIdleThreshold:
       
   635             {
       
   636             EnvSetIdleThresholdL( aMessage );
       
   637             break;
       
   638             }
       
   639             
       
   640         case EAlfRosterShow:
       
   641             {
       
   642             
       
   643             // Parse parameters
       
   644             // 0: control group handle (in)
       
   645             const TInt cntrlGroupHandle = aMessage.Int0();
       
   646             CAlfSrvSubSessionBase& subSession1 = SubSession( cntrlGroupHandle );
       
   647             CAlfSrvControlGroupSubSession& controlGroupSubSession = 
       
   648                 static_cast<CAlfSrvControlGroupSubSession&>(subSession1);
       
   649             CHuiControlGroup& controlGroup = controlGroupSubSession.ControlGroup();
       
   650                 
       
   651             // 1: where (in)
       
   652             const TInt where = aMessage.Int1();
       
   653             // 2: display handle (in)
       
   654             const TInt displayHandle = aMessage.Int2();
       
   655             CAlfSrvSubSessionBase& subSession2 = SubSession( displayHandle );
       
   656             CAlfSrvDisplaySubSession& displaySubSession = 
       
   657                 static_cast<CAlfSrvDisplaySubSession&>(subSession2);
       
   658             CHuiDisplay& display = displaySubSession.Display();
       
   659 
       
   660             controlGroupSubSession.SetIsShown( ETrue );
       
   661             controlGroupSubSession.PreferredPos() = where;
       
   662             
       
   663             // Show only if session is focused, otherwise delay until focus is gained
       
   664             if (iFocused)
       
   665                 {
       
   666 #ifdef SYMBIAN_BUILD_GCE
       
   667                 AlfAppUi()->ShowControlGroupL(display.Roster(), controlGroup, where, 0); 
       
   668 #else    
       
   669                 display.Roster().ShowL(controlGroup, where);                                    
       
   670 #endif
       
   671                 AlfServer()->AdjustWindowGroupPositionL( 
       
   672                     *CHuiStatic::RootWin(), 
       
   673                     ClientWindowGroup(), 
       
   674                     PreferredWindowGroupPosition()  );
       
   675 
       
   676                 }
       
   677             else
       
   678                 {                
       
   679                 if (where == KHuiRosterShowAtTop)
       
   680                     {
       
   681                     if (iControlGroupOrder.Count())
       
   682                         {
       
   683                         iControlGroupOrder.InsertL(&controlGroup, 0);            
       
   684                         }
       
   685                     else
       
   686                         {
       
   687                         iControlGroupOrder.AppendL(&controlGroup);                
       
   688                         }    
       
   689                     }
       
   690                 else if (where == KHuiRosterShowAtBottom)
       
   691                     {
       
   692                     iControlGroupOrder.AppendL(&controlGroup);                
       
   693                     }
       
   694                 else
       
   695                     {
       
   696                     if (iControlGroupOrder.Count() < where)
       
   697                         {
       
   698                         iControlGroupOrder.AppendL(&controlGroup);                        
       
   699                         }
       
   700                     else
       
   701                         {
       
   702                         iControlGroupOrder.InsertL(&controlGroup, where);                                        
       
   703                         }                                                
       
   704                     }                                                        
       
   705                 }    
       
   706                         
       
   707             break;
       
   708             }
       
   709             
       
   710         case EAlfRosterHide:
       
   711             {
       
   712             RosterHideL(aMessage);
       
   713             break;
       
   714             }
       
   715             
       
   716         case EAlfRosterShowVisual:
       
   717             {
       
   718             RosterShowVisualL(aMessage);
       
   719             break;
       
   720             }
       
   721             
       
   722         case EAlfRosterHideVisual:
       
   723             {
       
   724             RosterHideVisualL(aMessage);
       
   725             break;
       
   726             }
       
   727         case EAlfRosterMoveVisualToFront:
       
   728             {
       
   729             RosterMoveVisualToFrontL(aMessage);
       
   730             break;
       
   731             }
       
   732         case EAlfRosterSetPointerEventFlags:
       
   733             {
       
   734             RosterSetPointerEventFlagsL(aMessage);
       
   735             break;
       
   736             }
       
   737         case EAlfRosterAddPointerEventObserver:
       
   738             {
       
   739             RosterAddPointerEventObserverL(aMessage);
       
   740             break;
       
   741             }
       
   742         case EAlfRosterRemovePointerEventObserver:
       
   743             {
       
   744             RosterRemovePointerEventObserverL(aMessage);
       
   745             break;
       
   746             }
       
   747         case EAlfRosterSetPointerDragTreshold:
       
   748             {
       
   749             RosterSetPointerDragTresholdL(aMessage);
       
   750             break;
       
   751             }
       
   752         case EAlfRosterDisableLongTapEventsWhenDragging:
       
   753             {
       
   754             RosterDisableLongTapEventWhenDraggingL(aMessage);
       
   755             break;
       
   756             }
       
   757         case EAlfTextureStopAnimation:
       
   758             {
       
   759             if ( RequireTextureOwnerId( aMessage ) )
       
   760                 {
       
   761                 TextureStopAnimation(aMessage);
       
   762                 }
       
   763             break;
       
   764             }
       
   765         case EAlfTextureStartAnimation:
       
   766             {
       
   767             if ( RequireTextureOwnerId( aMessage ) )
       
   768                 {
       
   769                 TextureStartAnimation(aMessage);
       
   770                 }
       
   771             break;
       
   772             }
       
   773         case EAlfTextureCreateAnimated:
       
   774             {
       
   775             if ( RequireTextureOwnerId( aMessage ) )
       
   776                 {
       
   777                 TextureCreateAnimatedL(aMessage);
       
   778                 }
       
   779             break;
       
   780             }
       
   781         case EAlfTextureCreate:
       
   782             {
       
   783             if ( RequireTextureOwnerId( aMessage ) )
       
   784                 {
       
   785                 TextureCreateL(aMessage);
       
   786                 }
       
   787             break;
       
   788             }
       
   789              
       
   790         case EAlfTextureUnload:
       
   791             {
       
   792             if ( RequireTextureOwnerId( aMessage ) )
       
   793                 {
       
   794                 TextureUnload(aMessage);
       
   795                 }
       
   796             break;
       
   797             }
       
   798         case EAlfTextureDelete:
       
   799             {
       
   800             if ( RequireTextureOwnerId( aMessage ) )
       
   801                 {
       
   802                 TextureDelete(aMessage);
       
   803                 }
       
   804             break;
       
   805             }
       
   806         case EAlfTextureRelease:
       
   807             {
       
   808             if ( RequireTextureOwnerId( aMessage ) )
       
   809                 {
       
   810                 TextureRelease(aMessage);
       
   811                 }
       
   812             break;
       
   813             }
       
   814         case EAlfTextureRestore:
       
   815             {
       
   816             if ( RequireTextureOwnerId( aMessage ) )
       
   817                 {
       
   818                 TextureRestore(aMessage);
       
   819                 }
       
   820             break;
       
   821             }
       
   822         case EAlfTextureNotifySkinChanged:
       
   823             {
       
   824         	if ( RequireTextureOwnerId( aMessage ) )
       
   825         	    {
       
   826         	    TextureNotifySkinChanged(aMessage);
       
   827         	    }
       
   828             break;
       
   829             }             
       
   830         case EAlfTextureLoad:
       
   831             {
       
   832             if ( RequireTextureOwnerId( aMessage ) )
       
   833                 {
       
   834                 TextureLoadL(aMessage);
       
   835                 }
       
   836             break;
       
   837             } 
       
   838         case EAlfTextureBlur:
       
   839             {
       
   840             if ( RequireTextureOwnerId( aMessage ) )
       
   841                 {
       
   842                 TextureBlurL(aMessage);
       
   843                 }
       
   844             break;
       
   845             } 
       
   846         case EAlfTextureHasContent:
       
   847             {
       
   848             if ( RequireTextureOwnerId( aMessage ) )
       
   849                 {
       
   850                 TextureHasContentL(aMessage);
       
   851                 }
       
   852             break;
       
   853             } 
       
   854         case EAlfTextureUpdateOwnerId:
       
   855             {
       
   856             UpdateTextureOwnerIdL( aMessage );    
       
   857             break;
       
   858             }
       
   859         case EAlfTextureSetAutoSizeParams:
       
   860             {
       
   861             if ( RequireTextureOwnerId( aMessage ) )
       
   862                 {
       
   863                 TextureSetAutoSizeParamsL( aMessage );    
       
   864                 }
       
   865             break;
       
   866             }
       
   867             
       
   868             
       
   869         case EAlfNotifyAppVisibility:
       
   870             {
       
   871             TBool foreground = aMessage.Int0();
       
   872           	if (ClientWindowGroup() != KErrNotFound) // if Alf client have not set wg, treat it like non-Alf app 
       
   873           		{	
       
   874             	if ( foreground )
       
   875                 	{         	
       
   876 #ifdef SYMBIAN_BUILD_GCE
       
   877                 	ActivateContainerLayoutL(ETrue);         	
       
   878 #endif
       
   879                 	AlfServer()->FocusedWindowGroupChangedL( this );
       
   880                 	AlfServer()->AppUi()->UpdateActiveSession(this);
       
   881                 
       
   882                 	// Make sure that Env will refresh the screen 
       
   883                 	// when we gain focus
       
   884                 	AlfServer()->AppUi()->HuiEnv().ContinueRefresh();          			
       
   885                 	}
       
   886             	else
       
   887                 	{
       
   888                 	// check if there is some other alf application on top of this one and set
       
   889                 	// that application's session as a activesession
       
   890                 	CAlfAppSrvSessionBase* newFocusSession = AlfServer()->UpMostClientAboveWg( ClientWindowGroup() );
       
   891  
       
   892             	    if( newFocusSession )
       
   893             	        {
       
   894                         AlfServer()->FocusedWindowGroupChangedL( newFocusSession );
       
   895             	        }
       
   896             	    else
       
   897             	        {
       
   898             	        // do the "event window" repositioning immediately
       
   899             	        AlfServer()->FocusedWindowGroupChangedL( NULL );
       
   900             	        }
       
   901             	    
       
   902             	    AlfServer()->AppUi()->UpdateActiveSession( newFocusSession );
       
   903 
       
   904                     // The following line removes the flickering (=drawing and empty frame)
       
   905                     // when non-alfred application is exited to appshell.
       
   906 #ifndef SYMBIAN_BUILD_GCE
       
   907                 	AlfServer()->AppUi()->Container()->DrawDeferred();
       
   908 #endif
       
   909                 	}    
       
   910           		}
       
   911             break;
       
   912             }
       
   913             
       
   914         case EAlfGetPointerEvent:
       
   915             {
       
   916             TriggerPointerEvent(&aMessage);
       
   917             return; // don't complete message here
       
   918             }
       
   919     
       
   920         case EAlfCancelPtrEvents:
       
   921             {
       
   922             CancelPointerEvents();
       
   923             break;
       
   924             }
       
   925 
       
   926         case EAlfGetSystemEvent:
       
   927             {
       
   928             GetSystemEvents(&aMessage);
       
   929             return; // don't complete message here
       
   930             }
       
   931     
       
   932         case EAlfCancelSystemEvents:
       
   933             {
       
   934             CancelSystemEvents();
       
   935             break;
       
   936             }
       
   937             
       
   938         case ESetFullScreenDrawing:
       
   939             {
       
   940             iUsesFullScreen = aMessage.Int0();
       
   941             break;
       
   942             }
       
   943         case EAlfLayoutMetricsTextStyleData:
       
   944             {
       
   945         	LayoutMetricsTextStyleDataL(aMessage);
       
   946             break;
       
   947             } 
       
   948 
       
   949         case EAlfSetWgParent:
       
   950             {
       
   951             SetParentWindowGroupId(aMessage.Int0());
       
   952             break;
       
   953             }
       
   954         case EAlfSBufAddObserver:
       
   955             {
       
   956             AlfServer()->ScreenBufferManager().AddScreenBufferObserver(this, aMessage);
       
   957             return; // message is completed in the method above
       
   958             } 
       
   959         case EAlfSBufRemoveObserver:
       
   960             {
       
   961             AlfServer()->ScreenBufferManager().RemoveScreenBufferObserver(this, aMessage);
       
   962             break;
       
   963             } 
       
   964         case EAlfSBufRequestNextBuffer:
       
   965             {
       
   966             AlfServer()->ScreenBufferManager().RequestNextBuffer(this, aMessage);
       
   967             return; // message is completed in the method above
       
   968             } 
       
   969         case EAlfSBufRequestBufferDraw:
       
   970             {
       
   971             AlfServer()->ScreenBufferManager().RequestBufferDraw(this, aMessage);
       
   972             return; // message is completed in the method above
       
   973             } 
       
   974         case EAlfSBufRequestEvent:
       
   975             {
       
   976             AlfServer()->ScreenBufferManager().RequestScreenBufferEvent(this, aMessage);
       
   977             return; // don't complete message here
       
   978             }          
       
   979             
       
   980         case EAlfDoSubSessionBatchCmd:
       
   981             {
       
   982             ExecuteBatchCommandsL(aMessage);
       
   983             break;
       
   984             }   
       
   985       
       
   986         case EAlfConfigureBatchCmd:
       
   987             {
       
   988             ConfigureBatchCommandExecutionL( aMessage );
       
   989             break;
       
   990             }
       
   991 
       
   992         case EAlfNotifyTextureInfo:
       
   993             {           
       
   994             NotifyTextureInfo( aMessage );            
       
   995             }
       
   996             return;
       
   997             
       
   998         case EAlfCancelNotifyTextureInfo:
       
   999             {
       
  1000             if ( !iTextureInfoEvent.IsNull() )
       
  1001                 {
       
  1002                 iTextureInfoEvent.Complete( KErrCancel );
       
  1003                 }
       
  1004             }
       
  1005             break;
       
  1006         case EAlfDirectClientFPSCounterOn:
       
  1007             {
       
  1008             ReportFrameRateBegin( aMessage );
       
  1009             break;
       
  1010             }
       
  1011         case EAlfDirectClientFPSCounterOff:
       
  1012             {
       
  1013             ReportFrameRateEnd( aMessage );
       
  1014             break;
       
  1015             }
       
  1016         case EAlfEnableLowMemoryState:
       
  1017             {
       
  1018             EnvEnableLowMemoryState( aMessage );
       
  1019             break;
       
  1020             }    
       
  1021             
       
  1022         case EAlfForceSwRendering:
       
  1023             {
       
  1024             EnvForceSwRendering( aMessage );
       
  1025             break;    
       
  1026             }
       
  1027             
       
  1028             
       
  1029         default:
       
  1030             User::Leave( KErrNotSupported );
       
  1031         }
       
  1032 
       
  1033     if ( !aMessage.IsNull() )
       
  1034         {
       
  1035         aMessage.Complete( KErrNone );
       
  1036         }
       
  1037     }
       
  1038   
       
  1039 // ---------------------------------------------------------------------------
       
  1040 // class    :   CHuiEnv
       
  1041 // function :   SetRefreshMode
       
  1042 // param 0  :   IN refresh mode in THuiRefreshMode
       
  1043 // ---------------------------------------------------------------------------
       
  1044 //    
       
  1045 void CAlfAppSrvSession::EnvSetRefreshModeL(const RMessage2& aMessage)
       
  1046     {
       
  1047     // 0: refresh mode (in)
       
  1048     const THuiRefreshMode newMode = static_cast<THuiRefreshMode>(aMessage.Int0());
       
  1049     
       
  1050     if ( iRefreshMode != newMode )
       
  1051         {
       
  1052         iRefreshMode = newMode;
       
  1053         
       
  1054         if ( iFocused )
       
  1055             {
       
  1056             SharedHuiEnv()->SetRefreshMode( iRefreshMode );
       
  1057             }
       
  1058         }
       
  1059     }
       
  1060   
       
  1061 // ---------------------------------------------------------------------------
       
  1062 // class    :   CHuiEnv
       
  1063 // function :   SetMaxFrameRate
       
  1064 // param 0  :   IN framerate in Int
       
  1065 // ---------------------------------------------------------------------------
       
  1066 //    
       
  1067 void CAlfAppSrvSession::EnvSetMaxFrameRateL(const RMessage2& aMessage)
       
  1068     {
       
  1069     // 0: max framerate in TPckgC (in)
       
  1070     TReal32 newRate = KAlfUseDefaultFrameRate;
       
  1071     TPckg<TReal32> frameRatePckg(newRate);
       
  1072     aMessage.Read(0,frameRatePckg);
       
  1073     
       
  1074     if ( !RealCompare( iMaxFrameRate, newRate ) )
       
  1075         {
       
  1076         iMaxFrameRate = newRate;
       
  1077         
       
  1078         if ( iFocused )
       
  1079             {
       
  1080             if ( RealCompare( iMaxFrameRate, KAlfUseDefaultFrameRate ) )
       
  1081                 {
       
  1082                 SharedHuiEnv()->SetMaxFrameRate( 
       
  1083                     TReal32(AlfAppUi()->SettingsHandler().DefaultFramerate() ) );
       
  1084                 }
       
  1085             else
       
  1086                 {
       
  1087                 SharedHuiEnv()->SetMaxFrameRate( iMaxFrameRate );
       
  1088                 }
       
  1089             }
       
  1090         }
       
  1091     }
       
  1092   
       
  1093 // ---------------------------------------------------------------------------
       
  1094 // class    :   CHuiEnv
       
  1095 // function :   ContinueRefresh
       
  1096 // ---------------------------------------------------------------------------
       
  1097 //    
       
  1098 void CAlfAppSrvSession::EnvContinueRefreshL(const RMessage2& /*aMessage*/)
       
  1099     {
       
  1100     SharedHuiEnv()->ContinueRefresh();
       
  1101     }
       
  1102 
       
  1103 // ---------------------------------------------------------------------------
       
  1104 // class    :   CHuiEnv
       
  1105 // function :   PauseRefresh
       
  1106 // ---------------------------------------------------------------------------
       
  1107 //    
       
  1108 void CAlfAppSrvSession::EnvPauseRefreshL(const RMessage2& /*aMessage*/)
       
  1109     {
       
  1110     SharedHuiEnv()->PauseRefresh();
       
  1111     }
       
  1112    
       
  1113 // ---------------------------------------------------------------------------
       
  1114 // class    :   CHuiEnv
       
  1115 // function :   RefreshCallBack
       
  1116 // ---------------------------------------------------------------------------
       
  1117 //   
       
  1118 void CAlfAppSrvSession::EnvRefreshCallBackL(const RMessage2& /*aMessage*/)
       
  1119     {
       
  1120     CHuiEnv::RefreshCallBack( SharedHuiEnv() );
       
  1121     }
       
  1122 
       
  1123 // ---------------------------------------------------------------------------
       
  1124 // class    :   CHuiEnv
       
  1125 // function :   SetIdleThreshold
       
  1126 // param 0  :   IN Idle threshold time in milliseconds
       
  1127 // ---------------------------------------------------------------------------
       
  1128 //    
       
  1129 void CAlfAppSrvSession::EnvSetIdleThresholdL(const RMessage2& aMessage)
       
  1130     {
       
  1131     // 0: time in milliseconds (in)
       
  1132     const TInt time = (TInt)aMessage.Int0();
       
  1133     
       
  1134     if ( iIdleThreshold != time )
       
  1135         {
       
  1136         iIdleThreshold = time;
       
  1137         
       
  1138         if ( iFocused )
       
  1139             {
       
  1140             SharedHuiEnv()->SetIdleThreshold( iIdleThreshold );
       
  1141             }
       
  1142         }
       
  1143     }
       
  1144     
       
  1145 // ---------------------------------------------------------------------------
       
  1146 // class    : CHuiEnv  
       
  1147 // function : Renderer  
       
  1148 // param 0  : IN/OUT renderer 
       
  1149 // ---------------------------------------------------------------------------
       
  1150 //  
       
  1151 void CAlfAppSrvSession::EnvRendererL(const RMessage2& aMessage)
       
  1152     {
       
  1153     // Parse parameters
       
  1154 
       
  1155     // 0: renderer (in/out)
       
  1156     TInt renderer = 0;
       
  1157     TPckg<TInt> rendererPckg(renderer);
       
  1158     aMessage.Read(0,rendererPckg);
       
  1159     renderer = SharedHuiEnv()->Renderer();    
       
  1160     aMessage.Write(0,rendererPckg);    
       
  1161     }  
       
  1162     
       
  1163 // ---------------------------------------------------------------------------
       
  1164 // class    :   CHuiRoster
       
  1165 // function :   Hide
       
  1166 // param 0  :   IN Handle to CHuiControlGroup object
       
  1167 // param 1  :   IN Handle to CHuiDisplay object
       
  1168 // ---------------------------------------------------------------------------
       
  1169 //    
       
  1170 void CAlfAppSrvSession::RosterHideL(const RMessage2& aMessage)
       
  1171     {
       
  1172     // Parse parameters
       
  1173     // 0: control group handle (in)
       
  1174     const TInt cntrlGroupHandle = aMessage.Int0();
       
  1175     CAlfSrvSubSessionBase& subSession1 = SubSession( cntrlGroupHandle );
       
  1176     CAlfSrvControlGroupSubSession& controlGroupSubSession = 
       
  1177         static_cast<CAlfSrvControlGroupSubSession&>(subSession1);
       
  1178     CHuiControlGroup& controlGroup = controlGroupSubSession.ControlGroup();
       
  1179                 
       
  1180     // 1: display handle (in)
       
  1181     const TInt displayHandle = aMessage.Int1();
       
  1182     CAlfSrvSubSessionBase& subSession2 = SubSession( displayHandle );
       
  1183     CAlfSrvDisplaySubSession& displaySubSession = 
       
  1184         static_cast<CAlfSrvDisplaySubSession&>(subSession2);
       
  1185     CHuiDisplay& display = displaySubSession.Display();
       
  1186 
       
  1187     // hide
       
  1188     controlGroupSubSession.SetIsShown( EFalse );
       
  1189   
       
  1190     // hide from the roster only if session is focused
       
  1191     if ( iFocused )
       
  1192         {
       
  1193         display.Roster().Hide(controlGroup);
       
  1194         }
       
  1195     else // otherwise remove from the iControlGroupOrder array
       
  1196         {
       
  1197          TInt index = iControlGroupOrder.Find( &controlGroup );
       
  1198          if(  index != KErrNotFound)
       
  1199              {
       
  1200              iControlGroupOrder.Remove( index );
       
  1201              }
       
  1202         }
       
  1203     }
       
  1204     
       
  1205 // ---------------------------------------------------------------------------
       
  1206 // class    :   CHuiRoster
       
  1207 // function :   ShowVisualL
       
  1208 // param 0  :   IN Handle to CHuiVisual object
       
  1209 // param 1  :   IN Handle to CHuiDisplay object
       
  1210 // ---------------------------------------------------------------------------
       
  1211 //     
       
  1212 void CAlfAppSrvSession::RosterShowVisualL(const RMessage2& aMessage)
       
  1213     {
       
  1214     // Parse parameters
       
  1215     // 0: visual handle (in)
       
  1216     TAny* huiVisualAnyPtr = GetInterfaceL( EHuiObjectTypeVisual, aMessage.Int0() );
       
  1217     CHuiVisual* huiVisual = static_cast<CHuiVisual*>(huiVisualAnyPtr);
       
  1218     
       
  1219     // 1: display handle (in)
       
  1220     const TInt displayHandle = aMessage.Int1();
       
  1221     CAlfSrvSubSessionBase& subSession2 = SubSession( displayHandle );
       
  1222     CAlfSrvDisplaySubSession& displaySubSession = 
       
  1223         static_cast<CAlfSrvDisplaySubSession&>(subSession2);
       
  1224     CHuiDisplay& display = displaySubSession.Display();
       
  1225     
       
  1226     // show visual
       
  1227     display.Roster().ShowVisualL(huiVisual);
       
  1228     }
       
  1229     
       
  1230 // ---------------------------------------------------------------------------
       
  1231 // class    :   CHuiRoster
       
  1232 // function :   HideVisual
       
  1233 // param 0  :   IN Handle to CHuiVisual object
       
  1234 // param 1  :   IN Handle to CHuiDisplay object
       
  1235 // ---------------------------------------------------------------------------
       
  1236 // 
       
  1237 void CAlfAppSrvSession::RosterHideVisualL(const RMessage2& aMessage)
       
  1238     {
       
  1239     // Parse parameters
       
  1240     // 0: visual handle (in)
       
  1241     TAny* huiVisualAnyPtr = GetInterfaceL( EHuiObjectTypeVisual, aMessage.Int0() );
       
  1242     CHuiVisual* huiVisual = static_cast<CHuiVisual*>(huiVisualAnyPtr);
       
  1243     
       
  1244     // 1: display handle (in)
       
  1245     const TInt displayHandle = aMessage.Int1();
       
  1246     CAlfSrvSubSessionBase& subSession2 = SubSession( displayHandle );
       
  1247     CAlfSrvDisplaySubSession& displaySubSession = 
       
  1248         static_cast<CAlfSrvDisplaySubSession&>(subSession2);
       
  1249     CHuiDisplay& display = displaySubSession.Display();
       
  1250     
       
  1251     // show visual
       
  1252     display.Roster().HideVisual(huiVisual);
       
  1253     }
       
  1254   
       
  1255 // ---------------------------------------------------------------------------
       
  1256 // class    :   CHuiRoster
       
  1257 // function :   MoveVisualToFront
       
  1258 // param 0  :   IN Handle to CHuiVisual object
       
  1259 // param 1  :   IN Handle to CHuiDisplay object
       
  1260 // ---------------------------------------------------------------------------
       
  1261 //   
       
  1262 void CAlfAppSrvSession::RosterMoveVisualToFrontL(const RMessage2& aMessage)
       
  1263     {
       
  1264     // Parse parameters
       
  1265     // 0: visual handle (in)
       
  1266     TAny* huiVisualAnyPtr = GetInterfaceL( EHuiObjectTypeVisual, aMessage.Int0() );
       
  1267     CHuiVisual* huiVisual = static_cast<CHuiVisual*>(huiVisualAnyPtr);
       
  1268     
       
  1269     // 1: display handle (in)
       
  1270     const TInt displayHandle = aMessage.Int1();
       
  1271     CAlfSrvSubSessionBase& subSession2 = SubSession( displayHandle );
       
  1272     CAlfSrvDisplaySubSession& displaySubSession = 
       
  1273         static_cast<CAlfSrvDisplaySubSession&>(subSession2);
       
  1274     CHuiDisplay& display = displaySubSession.Display();
       
  1275     
       
  1276     // move visual to front
       
  1277 #ifdef SYMBIAN_BUILD_GCE
       
  1278     TInt firstAlfPositionInRoster = AlfAppUi()->FirstAlfControlGroupIndex();
       
  1279     display.Roster().Move(huiVisual, firstAlfPositionInRoster); 
       
  1280 
       
  1281 #else    
       
  1282     display.Roster().MoveVisualToFront(huiVisual);
       
  1283 #endif
       
  1284     }
       
  1285 
       
  1286 // ---------------------------------------------------------------------------
       
  1287 // class    :   CHuiRoster
       
  1288 // function :   Observers().AppendIfNotFoundL, Observers.RemoveIfFound
       
  1289 // param 0  :   IN flags
       
  1290 // param 1  :   IN Handle to CHuiControl object
       
  1291 // param 2  :   IN Handle to CHuiDisplay object
       
  1292 // ---------------------------------------------------------------------------
       
  1293 //      
       
  1294 void CAlfAppSrvSession::RosterSetPointerEventFlagsL(const RMessage2& aMessage)
       
  1295     {
       
  1296     // 0: flags (in)
       
  1297     const TInt flags = aMessage.Int0();
       
  1298     
       
  1299     // 1: control handle (in)
       
  1300     TAny* huiControlAnyPtr = GetInterfaceL( EHuiObjectTypeControl, aMessage.Int1() );
       
  1301     CHuiControl* huiControl = static_cast<CHuiControl*>(huiControlAnyPtr);
       
  1302     
       
  1303     // 2: display handle (in)
       
  1304     const TInt displayHandle = aMessage.Int2();
       
  1305     CAlfSrvSubSessionBase& subSession2 = SubSession( displayHandle );
       
  1306     CAlfSrvDisplaySubSession& displaySubSession = 
       
  1307         static_cast<CAlfSrvDisplaySubSession&>(subSession2);
       
  1308     CHuiDisplay& display = displaySubSession.Display();
       
  1309     
       
  1310     if ( flags & EAlfPointerEventReportDrag )
       
  1311         {
       
  1312         display.Roster().Observers(EHuiInputPointerDrag).AppendIfNotFoundL(*huiControl);
       
  1313         }
       
  1314     else
       
  1315         {
       
  1316         display.Roster().Observers(EHuiInputPointerDrag).RemoveIfFound(*huiControl);
       
  1317         }
       
  1318         
       
  1319     if ( flags & EAlfPointerEventReportLongTap )
       
  1320         {
       
  1321         display.Roster().Observers(EHuiInputPointerLongTap).AppendIfNotFoundL(*huiControl);
       
  1322         }
       
  1323     else
       
  1324         {
       
  1325         display.Roster().Observers(EHuiInputPointerLongTap).RemoveIfFound(*huiControl);
       
  1326         }
       
  1327         
       
  1328     if ( flags & EAlfPointerEventReportUnhandled  )
       
  1329         {
       
  1330         display.Roster().Observers(EHuiInputPointerUnhandled).AppendIfNotFoundL(*huiControl);
       
  1331         }
       
  1332     else
       
  1333         {
       
  1334         display.Roster().Observers(EHuiInputPointerUnhandled).RemoveIfFound(*huiControl);
       
  1335         }
       
  1336     }
       
  1337     
       
  1338 // ---------------------------------------------------------------------------
       
  1339 // class    :   CHuiRoster
       
  1340 // function :   Observers().AppendIfNotFoundL
       
  1341 // param 0  :   IN TAlfPointerEventFlags
       
  1342 // param 1  :   IN Handle to CHuiControl object
       
  1343 // param 2  :   IN Handle to CHuiDisplay object
       
  1344 // ---------------------------------------------------------------------------
       
  1345 //      
       
  1346 void CAlfAppSrvSession::RosterAddPointerEventObserverL(const RMessage2& aMessage)
       
  1347     {
       
  1348     // 0: observer (in)
       
  1349     const TAlfPointerEventFlags observer = (TAlfPointerEventFlags)aMessage.Int0();
       
  1350     
       
  1351     // 1: control handle (in)
       
  1352     TAny* huiControlAnyPtr = GetInterfaceL( EHuiObjectTypeControl, aMessage.Int1() );
       
  1353     CHuiControl* huiControl = static_cast<CHuiControl*>(huiControlAnyPtr);
       
  1354     
       
  1355     // 2: display handle (in)
       
  1356     const TInt displayHandle = aMessage.Int2();
       
  1357     CAlfSrvSubSessionBase& subSession2 = SubSession( displayHandle );
       
  1358     CAlfSrvDisplaySubSession& displaySubSession = 
       
  1359         static_cast<CAlfSrvDisplaySubSession&>(subSession2);
       
  1360     CHuiDisplay& display = displaySubSession.Display();
       
  1361     
       
  1362     // add observer
       
  1363     THuiInputType huiType = EHuiInputPointerDrag;
       
  1364     switch ( observer )
       
  1365         {
       
  1366         case EAlfPointerEventReportDrag:
       
  1367             huiType = EHuiInputPointerDrag;
       
  1368             break;
       
  1369         case EAlfPointerEventReportLongTap:
       
  1370             huiType = EHuiInputPointerLongTap;
       
  1371             break;
       
  1372         case EAlfPointerEventReportUnhandled:
       
  1373             huiType = EHuiInputPointerUnhandled;
       
  1374             break;
       
  1375         default:
       
  1376             User::Leave( KErrNotSupported );
       
  1377         }
       
  1378         
       
  1379     display.Roster().Observers(huiType).AppendIfNotFoundL(*huiControl);
       
  1380     }
       
  1381     
       
  1382  // ---------------------------------------------------------------------------
       
  1383 // class    :   CHuiRoster
       
  1384 // function :   Observers.RemoveIfFound
       
  1385 // param 0  :   IN TAlfPointerEventFlags
       
  1386 // param 1  :   IN Handle to CHuiControl object
       
  1387 // param 2  :   IN Handle to CHuiDisplay object
       
  1388 // ---------------------------------------------------------------------------
       
  1389 //      
       
  1390 void CAlfAppSrvSession::RosterRemovePointerEventObserverL(const RMessage2& aMessage)
       
  1391     {
       
  1392     // 0: observer (in)
       
  1393     const TAlfPointerEventFlags observer = (TAlfPointerEventFlags)aMessage.Int0();
       
  1394     
       
  1395     // 1: control handle (in)
       
  1396     TAny* huiControlAnyPtr = GetInterfaceL( EHuiObjectTypeControl, aMessage.Int1() );
       
  1397     CHuiControl* huiControl = static_cast<CHuiControl*>(huiControlAnyPtr);
       
  1398     
       
  1399     // 2: display handle (in)
       
  1400     const TInt displayHandle = aMessage.Int2();
       
  1401     CAlfSrvSubSessionBase& subSession2 = SubSession( displayHandle );
       
  1402     CAlfSrvDisplaySubSession& displaySubSession = 
       
  1403         static_cast<CAlfSrvDisplaySubSession&>(subSession2);
       
  1404     CHuiDisplay& display = displaySubSession.Display();
       
  1405     
       
  1406     // remove observer
       
  1407     THuiInputType huiType = EHuiInputPointerDrag;
       
  1408     switch ( observer )
       
  1409         {
       
  1410         case EAlfPointerEventReportDrag:
       
  1411             huiType = EHuiInputPointerDrag;
       
  1412             break;
       
  1413         case EAlfPointerEventReportLongTap:
       
  1414             huiType = EHuiInputPointerLongTap;
       
  1415             break;
       
  1416         case EAlfPointerEventReportUnhandled:
       
  1417             huiType = EHuiInputPointerUnhandled;
       
  1418             break;
       
  1419         default:
       
  1420             User::Leave( KErrNotSupported );
       
  1421         }
       
  1422         
       
  1423     display.Roster().Observers(huiType).RemoveIfFound(*huiControl);
       
  1424     }
       
  1425 
       
  1426 // ---------------------------------------------------------------------------
       
  1427 // class    :   CHuiRoster
       
  1428 // function :   
       
  1429 // param 0  :   
       
  1430 // ---------------------------------------------------------------------------
       
  1431 //      
       
  1432 void CAlfAppSrvSession::RosterSetPointerDragTresholdL(const RMessage2& aMessage)
       
  1433     {
       
  1434 	// Parse parameters
       
  1435     TAlfPointerEventDragTreshold params;
       
  1436     TPckg<TAlfPointerEventDragTreshold> paramsPckg(params);
       
  1437     aMessage.Read(0,paramsPckg);
       
  1438     
       
  1439     // control handle 
       
  1440     TAny* huiControlAnyPtr = GetInterfaceL( EHuiObjectTypeControl, params.iControlHandle );
       
  1441     CHuiControl* huiControl = static_cast<CHuiControl*>(huiControlAnyPtr);
       
  1442     
       
  1443 	// display handle
       
  1444     CAlfSrvSubSessionBase& subSession2 = SubSession( params.iDisplayHandle );
       
  1445     CAlfSrvDisplaySubSession& displaySubSession = 
       
  1446         static_cast<CAlfSrvDisplaySubSession&>(subSession2);
       
  1447     CHuiDisplay& display = displaySubSession.Display();
       
  1448     
       
  1449 	THuiXYMetric huiXYMetric;
       
  1450     AlfXYMetricUtility::CopyMetric(params.iXYMetric, huiXYMetric);    
       
  1451     
       
  1452     display.Roster().SetPointerDragThresholdL(*huiControl, huiXYMetric );
       
  1453     
       
  1454     }
       
  1455 
       
  1456 // ---------------------------------------------------------------------------
       
  1457 // class    :   CHuiRoster
       
  1458 // function :   
       
  1459 // param 0  :   
       
  1460 // ---------------------------------------------------------------------------
       
  1461 //      
       
  1462 void CAlfAppSrvSession::RosterDisableLongTapEventWhenDraggingL(const RMessage2& aMessage)
       
  1463     {
       
  1464 	// Parse parameters
       
  1465     // control handle (in)
       
  1466     TAny* huiControlAnyPtr = GetInterfaceL( EHuiObjectTypeControl, aMessage.Int0() );
       
  1467     CHuiControl* huiControl = static_cast<CHuiControl*>(huiControlAnyPtr);
       
  1468 
       
  1469     // observer (in)
       
  1470     const TBool disable = (TBool)aMessage.Int1();
       
  1471     
       
  1472     // display handle (in)
       
  1473     const TInt displayHandle = aMessage.Int2();
       
  1474     CAlfSrvSubSessionBase& subSession2 = SubSession( displayHandle );
       
  1475     CAlfSrvDisplaySubSession& displaySubSession = 
       
  1476         static_cast<CAlfSrvDisplaySubSession&>(subSession2);
       
  1477     CHuiDisplay& display = displaySubSession.Display();
       
  1478     
       
  1479 	display.Roster().DisableLongTapEventsWhenDraggingL(*huiControl, disable);
       
  1480     }
       
  1481 
       
  1482 // ---------------------------------------------------------------------------
       
  1483 // class    :   
       
  1484 // function :   
       
  1485 // param 0  :   
       
  1486 // param 1  :   
       
  1487 // ---------------------------------------------------------------------------
       
  1488 //  
       
  1489 void CAlfAppSrvSession::TextureCreateL(const RMessage2& aMessage)
       
  1490     {
       
  1491     // Owner id is stored in UpdateTextureOwnerIdL via IPC command 
       
  1492     // EAlfTextureUpdateOwnerId.
       
  1493     
       
  1494     // Parse parameters
       
  1495 
       
  1496     // 0: handle (in/out)
       
  1497     TInt handle;
       
  1498     TPckg<TInt> handlePckg(handle);
       
  1499     aMessage.Read(0,handlePckg);
       
  1500 
       
  1501     // 1: TAlfTextureCreateParams (in)
       
  1502     TAlfCreateTextureParams params;
       
  1503     TPckg<TAlfCreateTextureParams> paramsPckg(params);
       
  1504     aMessage.Read(1,paramsPckg);
       
  1505 
       
  1506 
       
  1507     CHuiEnv* env = SharedHuiEnv();
       
  1508     if (params.iBitmapHandle && params.iId != 0) 
       
  1509         {            
       
  1510         const TInt bitmapHandle = params.iBitmapHandle;
       
  1511         const TInt maskHandle = params.iMaskBitmapHandle;
       
  1512     	const TInt flags = params.iFlags;
       
  1513         const TInt managerId = params.iManagerId;
       
  1514         const TInt id = 
       
  1515             AlfTextureManager().CreateTextureId(
       
  1516                 TextureOwnerId(),
       
  1517                 params.iId, 
       
  1518                 managerId, 
       
  1519                 ETrue );
       
  1520 
       
  1521     	CSharedBitmapProvider* provider = new (ELeave) CSharedBitmapProvider(bitmapHandle, maskHandle);
       
  1522         CleanupStack::PushL(provider);
       
  1523     	
       
  1524         // Convert the TAlfTextureFlags to THuiTextureUploadFlags
       
  1525         TInt inputFlags = flags;
       
  1526         inputFlags &= ~EAlfTextureFlagSkinContent;
       
  1527         inputFlags &= ~EAlfTextureFlagAutoSize;
       
  1528         inputFlags &= ~EAlfTextureFlagLoadAnimAsImage;
       
  1529         
       
  1530         TBool textureAlreadyExists = (env->TextureManager().Texture(id) != &env->TextureManager().BlankTexture());
       
  1531         
       
  1532         CHuiTexture& texture = env->TextureManager().CreateTextureL(id,
       
  1533                                      provider,
       
  1534                                      (THuiTextureUploadFlags)inputFlags);
       
  1535 
       
  1536         // If we are reusing deleted texture, remove it from "deleted" array
       
  1537         TInt index = iTextures.Find(&texture);
       
  1538         if (index != KErrNotFound)
       
  1539            {
       
  1540            iTextures.Remove(index);                
       
  1541            }                    
       
  1542 
       
  1543 
       
  1544         // Add texture to skin content
       
  1545         texture.SetSkinContent((flags & EAlfTextureFlagSkinContent) != 0);
       
  1546 
       
  1547         // Add texture to automatic dynamic size calculations
       
  1548         texture.EnableAutoSizeCalculation((flags & EAlfTextureFlagAutoSize) != 0);
       
  1549         
       
  1550         // Check if texture already existed, if yes then we need to update its content
       
  1551         // because 
       
  1552         if (textureAlreadyExists)
       
  1553             {
       
  1554             CFbsBitmap* bitmap = NULL;
       
  1555             CFbsBitmap* mask = NULL;
       
  1556             provider->ProvideBitmapL(0, bitmap, mask);
       
  1557             CleanupStack::PushL(bitmap);
       
  1558             CleanupStack::PushL(mask);
       
  1559             texture.EnableShadow((flags & EHuiTextureUploadFlagGenerateShadow) != 0);            
       
  1560             TSize bitmapSize = bitmap->SizeInPixels();
       
  1561             if (bitmapSize.iWidth != 0 && bitmapSize.iHeight != 0)
       
  1562                 {
       
  1563                 // This uses direct upload if possible and specified in the upload flags
       
  1564                 TRAPD(err, env->TextureManager().UpdateTextureFromBitmapL(id, provider))        
       
  1565                 
       
  1566                 if (err != KErrNone)
       
  1567                     {
       
  1568                     // We do this because texture may be in undetermined state (?)
       
  1569                     texture.Reset();    
       
  1570                     User::Leave(err);
       
  1571                     }
       
  1572                 }
       
  1573             texture.SetSize(bitmap->SizeInPixels());
       
  1574             CleanupStack::PopAndDestroy(2); // bitmap, mask
       
  1575             }  
       
  1576                                      
       
  1577         // We delete provider here, because the release/restore
       
  1578         // is supported in the client library. There is currently
       
  1579         // no need to restore textures in the server.
       
  1580         CleanupStack::PopAndDestroy(); // provider;
       
  1581 
       
  1582         // Write parameters
       
  1583         handle = TInt((MHuiTexture*)(&texture));
       
  1584         aMessage.Write(0,handlePckg);
       
  1585         }
       
  1586     else
       
  1587         {
       
  1588         CHuiTexture& texture = env->TextureManager().BlankTexture();    
       
  1589         // Write parameters
       
  1590         handle = TInt((MHuiTexture*)(&texture));
       
  1591         aMessage.Write(0,handlePckg);
       
  1592         }    
       
  1593     }
       
  1594 
       
  1595 void CAlfAppSrvSession::TextureCreateAnimatedL(const RMessage2& aMessage)
       
  1596     {
       
  1597     // Parse parameters
       
  1598 
       
  1599     // 0: handle (in/out)
       
  1600     TInt handle = 0;
       
  1601     TPckg<TInt> handlePckg(handle);
       
  1602     aMessage.Read(0,handlePckg);
       
  1603 
       
  1604     // 1: TAlfTextureCreateParams (in)
       
  1605     TAlfCreateTextureAnimatedParams params;
       
  1606     TPckg<TAlfCreateTextureAnimatedParams> paramsPckg(params);
       
  1607     aMessage.Read(1,paramsPckg);
       
  1608     CHuiEnv* env = SharedHuiEnv();
       
  1609     
       
  1610     CHuiGifAnimationTexture* animtext = CHuiGifAnimationTexture::NewL(params.iFilename,env->TextureManager(),params.iId, (THuiTextureUploadFlags)(params.iFlags));
       
  1611     //MHuiTexture* foo = dynamic_cast<MHuiTexture*>(animtext);
       
  1612     iAnimatedTextures.Append(animtext);
       
  1613     handle = TInt((MHuiTexture*)(animtext));
       
  1614     aMessage.Write(0,handlePckg);
       
  1615     }
       
  1616 
       
  1617 
       
  1618 
       
  1619 
       
  1620 // ---------------------------------------------------------------------------
       
  1621 // class    :   
       
  1622 // function :   
       
  1623 // param 0  :   
       
  1624 // param 1  :   
       
  1625 // ---------------------------------------------------------------------------
       
  1626 //  
       
  1627 void CAlfAppSrvSession::TextureLoadL(const RMessage2& aMessage)
       
  1628     {
       
  1629     // Owner id is stored in UpdateTextureOwnerIdL via IPC command 
       
  1630     // EAlfTextureUpdateOwnerId.
       
  1631 
       
  1632     // 0: handle (in/out)
       
  1633     TInt handle = 0;
       
  1634     TPckg<TInt> handlePckg(handle);
       
  1635     aMessage.Read(0,handlePckg);
       
  1636 
       
  1637     // 1: TAlfTextureLoadParams (in)
       
  1638     TAlfLoadTextureParams params;
       
  1639     TPckg<TAlfLoadTextureParams> paramsPckg(params);
       
  1640     aMessage.Read(1,paramsPckg);
       
  1641 
       
  1642     const TInt bitmapHandle = params.iBitmapHandle;
       
  1643     const TInt maskHandle = params.iMaskBitmapHandle;
       
  1644 	const TInt flags = params.iFlags;
       
  1645     const TInt managerId = params.iManagerId;
       
  1646     const TInt id = 
       
  1647         AlfTextureManager().CreateTextureId(
       
  1648             TextureOwnerId(),
       
  1649             params.iId, 
       
  1650             managerId, 
       
  1651             ETrue );
       
  1652 
       
  1653     CHuiEnv* env = SharedHuiEnv();
       
  1654     if (bitmapHandle && params.iId != 0)
       
  1655         {            
       
  1656     	CSharedBitmapProvider* provider = 
       
  1657     	    new (ELeave) CSharedBitmapProvider(bitmapHandle, maskHandle);
       
  1658         CleanupStack::PushL(provider);
       
  1659         
       
  1660         // Convert the TAlfTextureFlags to THuiTextureUploadFlags
       
  1661         TInt inputFlags = (THuiTextureUploadFlags)flags;
       
  1662         inputFlags &= ~EAlfTextureFlagSkinContent;
       
  1663         inputFlags &= ~EAlfTextureFlagAutoSize;
       
  1664         inputFlags &= ~EAlfTextureFlagLoadAnimAsImage;
       
  1665         
       
  1666         TBool textureAlreadyExists = (env->TextureManager().Texture(id) != &env->TextureManager().BlankTexture());
       
  1667 
       
  1668         // Make sure texture exists
       
  1669         CHuiTexture& textureRef = env->TextureManager().CreateTextureL(id, provider, THuiTextureUploadFlags(inputFlags));
       
  1670 
       
  1671         // If we are reusing deleted texture, remove it from "deleted" array
       
  1672         TInt index = iTextures.Find(&textureRef);
       
  1673         if (index != KErrNotFound)
       
  1674            {
       
  1675            iTextures.Remove(index);                
       
  1676            }                    
       
  1677         
       
  1678         // Add texture to skin content
       
  1679         textureRef.SetSkinContent((flags & EAlfTextureFlagSkinContent) != 0);
       
  1680 
       
  1681         // Add texture to automatic dynamic size calculations
       
  1682         textureRef.EnableAutoSizeCalculation((flags & EAlfTextureFlagAutoSize) != 0);
       
  1683     	    	
       
  1684         // Upload texture, this is needed because CreateTexture does not necessarely do anything if texture
       
  1685         // already exists.
       
  1686         if (textureAlreadyExists)
       
  1687             {                
       
  1688             CFbsBitmap* bitmap = NULL;
       
  1689             CFbsBitmap* mask = NULL;
       
  1690             provider->ProvideBitmapL(id, bitmap, mask);
       
  1691             CleanupStack::PushL(bitmap);
       
  1692             CleanupStack::PushL(mask);
       
  1693             textureRef.EnableShadow((flags & EHuiTextureUploadFlagGenerateShadow) != 0);            
       
  1694             TSize bitmapSize = bitmap->SizeInPixels();
       
  1695             if (bitmapSize.iWidth != 0 && bitmapSize.iHeight != 0)
       
  1696                 {
       
  1697                 // This uses direct upload if possible and specified in the upload flags
       
  1698                 TRAPD(err, env->TextureManager().UpdateTextureFromBitmapL(id, provider))        
       
  1699 
       
  1700                 if (err != KErrNone)
       
  1701                     {
       
  1702                     // We do this because texture may be in undetermined state (?)
       
  1703                     textureRef.Reset();    
       
  1704                     User::Leave(err);
       
  1705                     }
       
  1706                 }
       
  1707             textureRef.SetSize(bitmap->SizeInPixels());
       
  1708             CleanupStack::PopAndDestroy(2); // bitmap, mask
       
  1709             }
       
  1710         // We delete provider here, because the release/restore
       
  1711         // is supported in the client library. There is currently
       
  1712         // no need to restore textures in the server.
       
  1713         CleanupStack::PopAndDestroy( provider );
       
  1714 
       
  1715 
       
  1716         // Write parameters
       
  1717         handle = TInt((MHuiTexture*)(&textureRef));
       
  1718         aMessage.Write(0,handlePckg);        
       
  1719         }
       
  1720     else
       
  1721         {
       
  1722         CHuiTexture& texture = env->TextureManager().BlankTexture();    
       
  1723         // Write parameters
       
  1724         handle = TInt((MHuiTexture*)(&texture));
       
  1725         aMessage.Write(0,handlePckg);
       
  1726         }    
       
  1727         
       
  1728     }
       
  1729 
       
  1730 // ---------------------------------------------------------------------------
       
  1731 // class    : CHuiTextureManager  
       
  1732 // function : UnloadTexture  
       
  1733 // param 0  : IN Texture id  
       
  1734 // ---------------------------------------------------------------------------
       
  1735 //  
       
  1736 void CAlfAppSrvSession::TextureUnload(const RMessage2& aMessage)
       
  1737     {
       
  1738     // Parse parameters
       
  1739 
       
  1740     // 0: id (in)
       
  1741    	const TInt originalId = aMessage.Int0();
       
  1742    	const TInt managerId = aMessage.Int1();
       
  1743 
       
  1744 	if (originalId != 0)
       
  1745 	    {
       
  1746         const TInt id = 
       
  1747             AlfTextureManager().ExistingTextureId(
       
  1748                 TextureOwnerId(), originalId, managerId);
       
  1749         
       
  1750     	if ( id != 0 && 
       
  1751     	     AlfTextureManager().ReleaseTextureId( 
       
  1752     	        TextureOwnerId(), originalId, managerId ) == 0)
       
  1753     	    {
       
  1754             if ( !managerId )
       
  1755                 {
       
  1756                 RemoveTextureInfo( originalId );
       
  1757                 }
       
  1758 
       
  1759             CHuiEnv* env = SharedHuiEnv();    	
       
  1760            	env->TextureManager().UnloadTexture(id);                                         	            	        
       
  1761     	    }
       
  1762 	    }
       
  1763     }
       
  1764 
       
  1765 // ---------------------------------------------------------------------------
       
  1766 // class    : 
       
  1767 // function : 
       
  1768 // param 0  : IN Texture id  
       
  1769 // ---------------------------------------------------------------------------
       
  1770 //  
       
  1771 void CAlfAppSrvSession::TextureDelete(const RMessage2& aMessage)
       
  1772     {
       
  1773     // Parse parameters
       
  1774 
       
  1775     // 0: id (in)
       
  1776    	const TInt originalId = aMessage.Int0();
       
  1777    	const TInt managerId = aMessage.Int1();
       
  1778 
       
  1779 	if (originalId != 0)
       
  1780 	    {
       
  1781         const TInt id = 
       
  1782             AlfTextureManager().ExistingTextureId( 
       
  1783                 TextureOwnerId(), originalId, managerId );
       
  1784         
       
  1785     	if ( id != 0 && 
       
  1786     	     AlfTextureManager().ReleaseTextureId( 
       
  1787     	        TextureOwnerId(), originalId, managerId ) == 0)
       
  1788     	    {
       
  1789             CHuiEnv* env = SharedHuiEnv();
       
  1790            	env->TextureManager().UnloadTexture(id);
       
  1791            	
       
  1792             if ( !managerId )
       
  1793                 {
       
  1794                 RemoveTextureInfo( originalId );
       
  1795                 }
       
  1796            	
       
  1797             if ( AlfTextureManager().DeleteTextureId(
       
  1798                      TextureOwnerId(), originalId, managerId) == 0 )
       
  1799                 {
       
  1800         	    // For now just unload textures, actual deletion happens 
       
  1801         	    // when session is closed (for safety reasons).
       
  1802                 CHuiTexture* texture = env->TextureManager().Texture(id); 
       
  1803                 if (texture)
       
  1804                     {
       
  1805                     // We should set texture attributes to default values
       
  1806                     // here if we recycle hui-textures during this session.
       
  1807                     texture->SetAutoSizeParams(THuiTextureAutoSizeParams());
       
  1808                     texture->EnableShadow(EFalse);
       
  1809                     texture->SetSkinContent(EFalse);
       
  1810                     
       
  1811                     if (iTextures.Find(texture) == KErrNotFound)
       
  1812                         {
       
  1813                         iTextures.Append(texture);                
       
  1814                         }                    
       
  1815                     }                                
       
  1816                 }
       
  1817     	    }
       
  1818 	    }
       
  1819     }
       
  1820 
       
  1821 // ---------------------------------------------------------------------------
       
  1822 // class    : CHuiTextureManager  
       
  1823 // function :  
       
  1824 // param 0  : IN Texture id  
       
  1825 // ---------------------------------------------------------------------------
       
  1826 //  
       
  1827 void CAlfAppSrvSession::TextureRelease(const RMessage2& aMessage)
       
  1828     {
       
  1829     // Parse parameters
       
  1830 
       
  1831     // 0: id (in)
       
  1832    	const TInt originalId = aMessage.Int0();
       
  1833    	const TInt managerId = aMessage.Int1();
       
  1834 
       
  1835 	if (originalId != 0)
       
  1836 	    {
       
  1837 	    // Just release texture id
       
  1838         AlfTextureManager().ReleaseTextureId(
       
  1839             TextureOwnerId(), originalId, managerId );	    
       
  1840 	    }
       
  1841     }
       
  1842 
       
  1843 // ---------------------------------------------------------------------------
       
  1844 // class    : CHuiTextureManager  
       
  1845 // function :  
       
  1846 // param 0  : IN Texture id  
       
  1847 // ---------------------------------------------------------------------------
       
  1848 //  
       
  1849 void CAlfAppSrvSession::TextureRestore(const RMessage2& aMessage)
       
  1850     {
       
  1851     // Parse parameters
       
  1852 
       
  1853     // 0: id (in)
       
  1854    	const TInt originalId = aMessage.Int0();
       
  1855    	const TInt managerId = aMessage.Int1();
       
  1856 
       
  1857 	if (originalId != 0)
       
  1858 	    {
       
  1859 	    // Just restore texture id
       
  1860         AlfTextureManager().CreateTextureId(
       
  1861             TextureOwnerId(), originalId, managerId, EFalse );
       
  1862 	    }
       
  1863     }
       
  1864 
       
  1865 // ---------------------------------------------------------------------------
       
  1866 // class    : CHuiTextureManager  
       
  1867 // function :  
       
  1868 // param 0  : IN Texture id  
       
  1869 // ---------------------------------------------------------------------------
       
  1870 //  
       
  1871 void CAlfAppSrvSession::TextureNotifySkinChanged(const RMessage2& aMessage)
       
  1872     {
       
  1873     // Parse parameters
       
  1874 
       
  1875     // 0: id (in)
       
  1876    	const TInt originalId = aMessage.Int0();
       
  1877    	const TInt managerId = aMessage.Int1();
       
  1878 
       
  1879 	if (originalId != 0)
       
  1880 	    {
       
  1881         const TInt id = 
       
  1882             AlfTextureManager().ExistingTextureId( 
       
  1883                 TextureOwnerId(), originalId, managerId );
       
  1884         
       
  1885     	if ( id != 0 && 
       
  1886     	     AlfTextureManager().ValidateSkinForTextureId( 
       
  1887     	        TextureOwnerId(), originalId, managerId ) == 0)
       
  1888     	    {
       
  1889             CHuiEnv* env = SharedHuiEnv();    	
       
  1890            	env->TextureManager().UnloadTexture(id);                                         	            	        
       
  1891     	    }
       
  1892 	    }
       
  1893     }
       
  1894 
       
  1895 static CHuiTexture* CastTexture( MHuiTexture* aMHuiTexture )
       
  1896     {
       
  1897     CHuiTexture* resultCHuiTexture = NULL;
       
  1898     if ( aMHuiTexture )
       
  1899         {
       
  1900         // only CHuiTexture implements the MHuiShadowedTexture interface
       
  1901         MHuiShadowedTexture* shadowedTexture = aMHuiTexture->ShadowedTexture();
       
  1902         if ( shadowedTexture )
       
  1903             {
       
  1904             resultCHuiTexture = static_cast<CHuiTexture*>( shadowedTexture );
       
  1905             }
       
  1906         }
       
  1907             
       
  1908     return resultCHuiTexture;
       
  1909     }
       
  1910 
       
  1911 // ---------------------------------------------------------------------------
       
  1912 // class    :   
       
  1913 // function :   
       
  1914 // param 0  :   
       
  1915 // param 1  :   
       
  1916 // ---------------------------------------------------------------------------
       
  1917 //  
       
  1918 void CAlfAppSrvSession::TextureBlurL(const RMessage2& aMessage)
       
  1919     {
       
  1920     // Parse parameters
       
  1921 
       
  1922     // 0: TAlfBlurTextureParams (in)
       
  1923     TAlfBlurTextureParams params;
       
  1924     TPckg<TAlfBlurTextureParams> paramsPckg(params);
       
  1925     aMessage.Read(0,paramsPckg);
       
  1926 
       
  1927     CHuiEnv* env = SharedHuiEnv();
       
  1928     if (params.iServerSideSrcHandle && params.iServerSideDstHandle)
       
  1929         {
       
  1930         CHuiTexture* srcTexture = CastTexture(reinterpret_cast<MHuiTexture*>(params.iServerSideSrcHandle));
       
  1931         CHuiTexture* dstTexture = CastTexture(reinterpret_cast<MHuiTexture*>(params.iServerSideDstHandle));
       
  1932         
       
  1933         if (srcTexture && dstTexture)
       
  1934             {
       
  1935             
       
  1936             const THuiTextureHandle srcHandle = srcTexture->Handle();
       
  1937             THuiTextureHandle dstHandle = dstTexture->Handle();
       
  1938             const TSize size = params.iPreferredSize;
       
  1939                 
       
  1940             env->TextureManager().Processor().BlurL(srcHandle,
       
  1941                 dstHandle, 
       
  1942                 size,
       
  1943                 params.iFilterSize,
       
  1944                 params.iFlag);            
       
  1945             }
       
  1946         else
       
  1947             {
       
  1948             User::Leave(KErrArgument);
       
  1949             }
       
  1950         }
       
  1951     }
       
  1952 
       
  1953 // ---------------------------------------------------------------------------
       
  1954 // class    :   
       
  1955 // function :   
       
  1956 // param 0  :   
       
  1957 // param 1  :   
       
  1958 // ---------------------------------------------------------------------------
       
  1959 //  
       
  1960 void CAlfAppSrvSession::TextureHasContentL(const RMessage2& aMessage)
       
  1961     {
       
  1962 
       
  1963     // 0: ret val (in/out)
       
  1964     TBool retVal = EFalse;
       
  1965     TPckg<TBool> retValPckg(retVal);
       
  1966     aMessage.Read(0,retValPckg);
       
  1967 
       
  1968     // 1: id (in)
       
  1969    	const TInt originalId = aMessage.Int1();
       
  1970    	
       
  1971     // 2: manager id (in)
       
  1972    	const TInt managerId = aMessage.Int2();
       
  1973 
       
  1974 	if (originalId != 0)
       
  1975 	    {
       
  1976         const TInt id = 
       
  1977             AlfTextureManager().ExistingTextureId( 
       
  1978                 TextureOwnerId(), originalId, managerId, ETrue);
       
  1979         
       
  1980         if (id != 0)
       
  1981             {
       
  1982             CHuiEnv* env = SharedHuiEnv();    	
       
  1983             CHuiTexture* tex = env->TextureManager().Texture(id);                                         	            	        
       
  1984             if (tex)
       
  1985                 {
       
  1986                 retVal = tex->HasContent();               
       
  1987                 }                
       
  1988             }
       
  1989 	    }
       
  1990     aMessage.Write(0,retValPckg);        
       
  1991     }
       
  1992 
       
  1993 void CAlfAppSrvSession::TextureStartAnimation(const RMessage2& aMessage)
       
  1994     {
       
  1995     TInt id = aMessage.Int0();
       
  1996     CHuiGifAnimationTexture* tex = NULL;
       
  1997     for (TInt index = 0; index < iAnimatedTextures.Count(); index++)
       
  1998         {
       
  1999         tex = iAnimatedTextures.operator[](index);
       
  2000         if (tex->Id() == id)
       
  2001             {
       
  2002             tex->Start();
       
  2003             break;
       
  2004             }
       
  2005         }
       
  2006     }
       
  2007     
       
  2008 void CAlfAppSrvSession::TextureStopAnimation(const RMessage2& aMessage)
       
  2009     {
       
  2010     TInt id = aMessage.Int0();
       
  2011     CHuiGifAnimationTexture* tex = NULL;
       
  2012     for (TInt index = 0; index < iAnimatedTextures.Count(); index++)
       
  2013         {
       
  2014         tex = iAnimatedTextures.operator[](index);
       
  2015         if (tex->Id() == id)
       
  2016             {
       
  2017             tex->Stop();
       
  2018             break;
       
  2019             }
       
  2020         }
       
  2021     }
       
  2022 
       
  2023 // ---------------------------------------------------------------------------
       
  2024 // class    :   
       
  2025 // function :   
       
  2026 // param 0  :   
       
  2027 // param 1  :   
       
  2028 // ---------------------------------------------------------------------------
       
  2029 //  
       
  2030 void CAlfAppSrvSession::TextureSetAutoSizeParamsL(const RMessage2& aMessage)
       
  2031     {
       
  2032 
       
  2033     // 0: id (in)
       
  2034    	const TInt originalId = aMessage.Int0();
       
  2035    	
       
  2036     // 1: manager id (in)
       
  2037    	const TInt managerId = aMessage.Int1();
       
  2038 
       
  2039     // 2: params (in)
       
  2040     TAlfTextureAutoSizeParams params;
       
  2041     TPckg<TAlfTextureAutoSizeParams> paramPckg(params);
       
  2042     aMessage.Read(2,paramPckg);
       
  2043 
       
  2044 
       
  2045 	if (originalId != 0)
       
  2046 	    {
       
  2047         const TInt id = 
       
  2048             AlfTextureManager().ExistingTextureId( 
       
  2049                 TextureOwnerId(), originalId, managerId, ETrue);
       
  2050         
       
  2051         if (id != 0)
       
  2052             {
       
  2053             CHuiEnv* env = SharedHuiEnv();    	
       
  2054             CHuiTexture* tex = env->TextureManager().Texture(id);                                         	            	        
       
  2055             if (tex)
       
  2056                 {
       
  2057                 THuiTextureAutoSizeParams* huiparams = (THuiTextureAutoSizeParams*) &params;                
       
  2058                 tex->SetAutoSizeParams(*huiparams);               
       
  2059                 }                
       
  2060             }
       
  2061 	    }
       
  2062     }
       
  2063 
       
  2064 void CAlfAppSrvSession::LayoutMetricsTextStyleDataL(const RMessage2& aMessage)
       
  2065     {
       
  2066     // 0: ret val (in/out)
       
  2067     TInt retVal = 0;
       
  2068     TPckg<TInt> retValPckg(retVal);
       
  2069     aMessage.Read(0,retValPckg);
       
  2070 
       
  2071     // 1: textStyle (in)
       
  2072    	const TInt textStyle = aMessage.Int1();
       
  2073    	
       
  2074     CHuiEnv* env = SharedHuiEnv();
       
  2075     retVal = env->TextStyleManager().TextStyle(textStyle)->FontStyleId();    	   	
       
  2076     
       
  2077     aMessage.Write(0,retValPckg);                
       
  2078     }
       
  2079     
       
  2080 TBool CAlfAppSrvSession::RequireTextureOwnerId(const RMessage2& aMessage)
       
  2081     {
       
  2082     if ( !iTextureOwnedIdSet )
       
  2083         {
       
  2084         AlfPanicClient( aMessage, EAlfSrvTexturePanicTextureOwnerIdNotUpdated );        
       
  2085         }
       
  2086         
       
  2087     return iTextureOwnedIdSet;
       
  2088     }
       
  2089     
       
  2090 void CAlfAppSrvSession::UpdateTextureOwnerIdL(const RMessage2& aMessage)
       
  2091     {
       
  2092     if ( !iTextureOwnedIdSet )
       
  2093         {
       
  2094         // Open process, get id and then close.
       
  2095         RThread client;
       
  2096         User::LeaveIfError( aMessage.Client(client) );
       
  2097         CleanupClosePushL( client );
       
  2098         RProcess process;
       
  2099         User::LeaveIfError( client.Process( process ) );
       
  2100         TProcessId id = process.Id();
       
  2101         process.Close();
       
  2102         CleanupStack::PopAndDestroy( &client );
       
  2103         
       
  2104         // Register & then store owner id.
       
  2105         AlfTextureManager().AddClientL( id, *this );
       
  2106         iTextureOwnedIdSet = ETrue;
       
  2107         iTextureOwnerId = id;
       
  2108         }        
       
  2109     }
       
  2110     
       
  2111 inline TProcessId CAlfAppSrvSession::TextureOwnerId() const
       
  2112     {
       
  2113     __ASSERT_ALWAYS( iTextureOwnedIdSet, USER_INVARIANT() );
       
  2114     return iTextureOwnerId;
       
  2115     }
       
  2116 
       
  2117 void CAlfAppSrvSession::ConfigureBatchCommandExecutionL( 
       
  2118         const RMessage2& aMessage )
       
  2119     {
       
  2120     // This should be called only by unit tests. Anyway,
       
  2121     // this has impact on this session only, so it does
       
  2122     // not cause any problems.
       
  2123     __ALFLOGSTRING1( "ConfigureBatchCommandExecutionL: %x", aMessage.Int0() )
       
  2124     iExecutionFlags = aMessage.Int0();
       
  2125     }
       
  2126 
       
  2127 void CAlfAppSrvSession::ExecuteBatchCommandsL(const RMessage2& aMessage)
       
  2128     {
       
  2129     // First, let's try to execute using dynamic buffer..
       
  2130     if ( !AllowExecuteUsingDynamicBuffer() || 
       
  2131          !ExecuteBatchCommandsUsingDynamicBufferL( aMessage ) )
       
  2132         {
       
  2133         // If that fails, then try with fixed buffer.
       
  2134         ExecuteBatchCommandsUsingFixedBufferL( aMessage );
       
  2135         }
       
  2136     }
       
  2137 
       
  2138 TBool CAlfAppSrvSession::ExecuteBatchCommandsUsingDynamicBufferL( 
       
  2139         const RMessage2& aMessage )
       
  2140     {       
       
  2141     TBool result = EFalse;
       
  2142 
       
  2143     CAlfAppServer* server = AlfServer();
       
  2144 
       
  2145     const TInt commonBatchBufferLength = 
       
  2146         server->CommonCommandBatchBufferMaxLength();
       
  2147 
       
  2148     const TInt requiredBufferLength = aMessage.GetDesLengthL(0);
       
  2149 
       
  2150     TBool commonBatchBufferAcquired = EFalse;
       
  2151 
       
  2152     // This will finally hold reference to buffer to be used for
       
  2153     // reading message from client side.
       
  2154     TPtr8 ptrBuffer( 0, 0 );
       
  2155 
       
  2156     // First, try to acquire common command batch buffer
       
  2157     // (if it's not in use and it has sufficient space)
       
  2158     if ( AllowExecuteUsingCommonBuffer() &&
       
  2159          ( commonBatchBufferLength >= requiredBufferLength ) )
       
  2160         {
       
  2161         commonBatchBufferAcquired = 
       
  2162             server->AcquireCommonCommandBatchBuffer( ptrBuffer );
       
  2163         }
       
  2164 
       
  2165     // If common command batch buffer were not usable,
       
  2166     // let's try to allocate bigger buffer.
       
  2167     HBufC8* memoryBuffer = NULL;
       
  2168     if ( commonBatchBufferAcquired )
       
  2169         {
       
  2170         result = ETrue;
       
  2171         }
       
  2172     else
       
  2173         {
       
  2174         memoryBuffer = HBufC8::New( requiredBufferLength );
       
  2175         if ( memoryBuffer )
       
  2176             {
       
  2177             result = ETrue;
       
  2178             ptrBuffer.Set( memoryBuffer->Des() );
       
  2179             }
       
  2180         }
       
  2181 
       
  2182     if ( result )
       
  2183         {
       
  2184         TInt err = aMessage.Read( 0, ptrBuffer );
       
  2185 
       
  2186         if ( err != KErrNone )
       
  2187             {
       
  2188             // Release and then leave.
       
  2189             if ( memoryBuffer )
       
  2190                 {
       
  2191                 delete memoryBuffer;
       
  2192                 memoryBuffer = NULL;
       
  2193                 }
       
  2194             if ( commonBatchBufferAcquired )
       
  2195                 {
       
  2196                 server->ReleaseCommonCommandBatchBuffer();
       
  2197                 }
       
  2198             
       
  2199             User::Leave( err );
       
  2200             }
       
  2201 
       
  2202         TInt dummy;
       
  2203         TInt length = 0;
       
  2204 
       
  2205         // Note - this method is implemented so that this works even in OOM, that's
       
  2206         // why TRAP is used here intentionally.
       
  2207         TRAP( err, length = ExecuteCommandsFromDescriptorL( ptrBuffer, dummy ) );
       
  2208         const TInt ptrBufferLength = ptrBuffer.Length();
       
  2209 
       
  2210         // Release - note that buffer length must be fetched before deletion.
       
  2211         if ( memoryBuffer )
       
  2212             {
       
  2213             delete memoryBuffer;
       
  2214             memoryBuffer = NULL;
       
  2215             }
       
  2216         if ( commonBatchBufferAcquired )
       
  2217             {
       
  2218             server->ReleaseCommonCommandBatchBuffer();
       
  2219             }
       
  2220 
       
  2221 #ifdef _ALF_LOGGING
       
  2222         if ( err != KErrNone )
       
  2223             {
       
  2224             __ALFLOGSTRING3( 
       
  2225                 "ExecuteBatchCommandsUsingDynamicBufferL execution failed, err=%d (%d,%d)", 
       
  2226                 err, length, ptrBufferLength )
       
  2227             }
       
  2228 #endif // _ALF_LOGGING
       
  2229 
       
  2230         if ( !err && ( length != ptrBufferLength ) )
       
  2231             {
       
  2232             // All commands were not executed!
       
  2233             __ALFLOGSTRING2( 
       
  2234                 "ExecuteBatchCommandsUsingDynamicBufferL corrupted buffer (%d,%d)", 
       
  2235                 length, ptrBufferLength )
       
  2236             err = KErrCorrupt;
       
  2237             }
       
  2238 
       
  2239         User::LeaveIfError( err );
       
  2240         }
       
  2241 
       
  2242     return result;
       
  2243     }
       
  2244 
       
  2245 void CAlfAppSrvSession::ExecuteBatchCommandsUsingFixedBufferL( 
       
  2246         const RMessage2& aMessage )
       
  2247     {
       
  2248     CAlfAppServer* server = AlfServer();
       
  2249     const TInt messageLength = aMessage.GetDesLengthL(0);
       
  2250 
       
  2251     TBufC8< KAlfStackBatchBufferSize > stackBuffer;
       
  2252     TPtr8 ptrBuffer( stackBuffer.Des() );
       
  2253 
       
  2254     TBool commonBatchBufferAcquired = EFalse;
       
  2255     if ( AllowExecuteUsingCommonBuffer() )
       
  2256         {
       
  2257         commonBatchBufferAcquired = 
       
  2258             server->AcquireCommonCommandBatchBuffer( ptrBuffer );
       
  2259         }
       
  2260     
       
  2261     TInt length = 0;
       
  2262 
       
  2263     // Note - this method is implemented so that this works even in OOM, that's
       
  2264     // why TRAP is used here intentionally.
       
  2265     TRAPD( err, length = 
       
  2266         ExecuteBatchCommandsUsingBufferL( ptrBuffer, messageLength, aMessage ) );
       
  2267 
       
  2268     if ( commonBatchBufferAcquired )
       
  2269         {
       
  2270         server->ReleaseCommonCommandBatchBuffer();
       
  2271         }
       
  2272 
       
  2273 #ifdef _ALF_LOGGING
       
  2274     if ( err != KErrNone )
       
  2275         {
       
  2276         __ALFLOGSTRING3( 
       
  2277             "ExecuteBatchCommandsUsingFixedBufferL execution failed, err=%d (%d,%d)", 
       
  2278             err, length, messageLength )
       
  2279         }
       
  2280 #endif // _ALF_LOGGING
       
  2281 
       
  2282     if ( !err && ( length != messageLength ) )
       
  2283         {
       
  2284         // All commands were not executed!
       
  2285         __ALFLOGSTRING2( 
       
  2286             "ExecuteBatchCommandsUsingFixedBufferL corrupted buffer (%d,%d)", 
       
  2287             length, messageLength )
       
  2288 
       
  2289         err = KErrCorrupt;
       
  2290         }
       
  2291 
       
  2292     User::LeaveIfError( err );
       
  2293     }
       
  2294 
       
  2295 TInt CAlfAppSrvSession::ExecuteBatchCommandsUsingBufferL( 
       
  2296         TDes8& aBuffer, 
       
  2297         TInt aMessageLength,
       
  2298         const RMessage2& aMessage )
       
  2299     {
       
  2300     const TInt bufferMaxLength = aBuffer.MaxLength();
       
  2301     
       
  2302     // It is assumed that bufferMaxLength > command header length.
       
  2303     // If you check ExecuteBatchCommandsUsingFixedBufferL, you can see
       
  2304     // that this assumption holds.
       
  2305 
       
  2306     TInt offset = 0;
       
  2307     TBool failed = EFalse;
       
  2308 
       
  2309     while ( !failed && ( offset < aMessageLength ) ) 
       
  2310         {
       
  2311         aMessage.ReadL( 0, aBuffer, offset );
       
  2312 
       
  2313         TInt spaceNeeded = 0;
       
  2314         offset += ExecuteCommandsFromDescriptorL( aBuffer, spaceNeeded );
       
  2315 
       
  2316         if ( spaceNeeded > ( aMessageLength - offset ) )
       
  2317             {
       
  2318             // More space is needed than there is left in message.
       
  2319             failed = ETrue;
       
  2320             }
       
  2321         else if ( spaceNeeded > bufferMaxLength )
       
  2322             {
       
  2323             // Too bad, message does not fit to our fixed size buffer.
       
  2324             // Let's try to allocate buffer for this.
       
  2325 
       
  2326             HBufC8* buffer = HBufC8::NewLC( spaceNeeded );
       
  2327             TPtr8 bufferPtr = buffer->Des();
       
  2328 
       
  2329             aMessage.ReadL( 0, bufferPtr, offset );
       
  2330 
       
  2331             // Maximum length of buffer may be larger than spaceNeeded,
       
  2332             // thus bufferPtr may be larger as well. But to keep this
       
  2333             // simple, let's constraint to one message.
       
  2334             if ( bufferPtr.Length() > spaceNeeded )
       
  2335                 {
       
  2336                 bufferPtr.SetLength( spaceNeeded );
       
  2337                 }
       
  2338                 
       
  2339             if ( bufferPtr.Length() == spaceNeeded )
       
  2340                 {
       
  2341                 TInt dummy;
       
  2342                 TInt offsetDelta = 
       
  2343                     ExecuteCommandsFromDescriptorL( bufferPtr, dummy );
       
  2344 
       
  2345                 if ( offsetDelta == spaceNeeded )
       
  2346                     {
       
  2347                     // Move offset forward.
       
  2348                     offset += offsetDelta;    
       
  2349                     }
       
  2350                 else
       
  2351                     {
       
  2352                     // There was supposed to be exactly one message
       
  2353                     // in buffer, but now there is not.
       
  2354                     failed = ETrue;
       
  2355                     }
       
  2356                 }
       
  2357             else
       
  2358                 {
       
  2359                 // spaceNeeded amount of bytes were required for 
       
  2360                 // next message, but somehow we did not get that many bytes.
       
  2361                 failed = ETrue;
       
  2362                 }
       
  2363 
       
  2364             CleanupStack::PopAndDestroy( buffer );
       
  2365             }
       
  2366         else
       
  2367             {
       
  2368             // Do nothing - we can continue reading next part of buffer.
       
  2369             }
       
  2370         }
       
  2371 
       
  2372     return offset;
       
  2373     }
       
  2374 
       
  2375 TInt CAlfAppSrvSession::ExecuteCommandsFromDescriptorL( 
       
  2376         const TDesC8& aSource, 
       
  2377         TInt& aSpaceNeeded )
       
  2378     {
       
  2379     TPtrC8 unreadArea( aSource );
       
  2380     aSpaceNeeded = 0;
       
  2381 
       
  2382     while ( !aSpaceNeeded && ( unreadArea.Length() > 0 ) )
       
  2383         {
       
  2384         TInt3 params(0,0,0);
       
  2385         TPckg<TInt3> paramsPckg( params );
       
  2386 
       
  2387         // Check if there is complete parameter structure in unreadArea.
       
  2388         const TInt paddedParamsPckgMaxLength = 
       
  2389             AlfPaddedLength( paramsPckg.MaxLength() );
       
  2390         if ( paddedParamsPckgMaxLength > unreadArea.Length() )
       
  2391             {
       
  2392             // Bail out from while loop.
       
  2393             aSpaceNeeded = paddedParamsPckgMaxLength;
       
  2394             }
       
  2395         else
       
  2396             {
       
  2397             // Copy to local parameters.
       
  2398             paramsPckg.Copy( unreadArea.Left( paramsPckg.MaxLength() ) );
       
  2399 
       
  2400             // Read parameters
       
  2401             const TInt operation = params.iInt1;
       
  2402             const TInt subSessionHandle = params.iInt2;
       
  2403             const TInt inputBufferLength = params.iInt3;
       
  2404             
       
  2405             if ( inputBufferLength < 0 )
       
  2406                 {
       
  2407                 // Input buffer length must not be negative.
       
  2408                 __ALFLOGSTRING1( 
       
  2409                     "ExecuteCommandsFromDescriptorL corrupted: neg. length %d",
       
  2410                     inputBufferLength )
       
  2411                 User::Leave( KErrCorrupt );
       
  2412                 }
       
  2413                 
       
  2414             const TInt paddedInputBufferLength = 
       
  2415                 AlfPaddedLength( inputBufferLength );
       
  2416             
       
  2417             if ( paddedParamsPckgMaxLength + paddedInputBufferLength < 0 )
       
  2418                 {
       
  2419                 // There must NOT be overflow.
       
  2420                 __ALFLOGSTRING1( 
       
  2421                     "ExecuteCommandsFromDescriptorL corrupted: length %d",
       
  2422                     inputBufferLength )
       
  2423                 User::Leave( KErrCorrupt );
       
  2424                 }
       
  2425 
       
  2426             // Check if there is complete input buffer in unreadArea.
       
  2427             if ( paddedParamsPckgMaxLength + paddedInputBufferLength > 
       
  2428                  unreadArea.Length() )
       
  2429                 {
       
  2430                 // Bail out from while loop.
       
  2431                 aSpaceNeeded = paddedParamsPckgMaxLength + paddedInputBufferLength;
       
  2432                 }
       
  2433             else
       
  2434                 {                    
       
  2435                 // Now we know that all data is available. 
       
  2436                 // It's time to execute command.
       
  2437 
       
  2438                 // Skip over parameters (already read above)
       
  2439                 unreadArea.Set( unreadArea.Mid( paddedParamsPckgMaxLength ) );
       
  2440                
       
  2441                 // Read input buffer
       
  2442                 TPtrC8 inputbuffer = unreadArea.Left( inputBufferLength );
       
  2443                 unreadArea.Set( unreadArea.Mid( paddedInputBufferLength ) );
       
  2444         
       
  2445                 if ( !CAlfAppSrvSessionBase::HasSession( subSessionHandle ) )
       
  2446                     {
       
  2447                     // Subsession handle must exist.
       
  2448                     __ALFLOGSTRING1( 
       
  2449                         "ExecuteCommandsFromDescriptorL corrupted: handle %d",
       
  2450                         subSessionHandle )
       
  2451                     User::Leave( KErrCorrupt );
       
  2452                     }
       
  2453         
       
  2454                 // Execute command
       
  2455                 CAlfSrvSubSessionBase& subsession = 
       
  2456                     CAlfAppSrvSessionBase::SubSession( subSessionHandle );
       
  2457                 MAlfExtension* subsessionEx = subsession.AsCommandHandler();
       
  2458 
       
  2459                 if ( !subsessionEx )
       
  2460                     {
       
  2461                     // Instance implementing extension interface must exist.
       
  2462                     __ALFLOGSTRING1( 
       
  2463                         "ExecuteCommandsFromDescriptorL corrupted: no ext, handle %d",
       
  2464                         subSessionHandle )
       
  2465                     User::Leave( KErrCorrupt );
       
  2466                     }
       
  2467 
       
  2468                 TBuf8<1> dummy;
       
  2469 #ifdef _ALF_LOGGING
       
  2470                 TRAPD( err,
       
  2471                     subsessionEx->HandleCmdL( operation, inputbuffer, dummy ) );
       
  2472                 if ( err != KErrNone )
       
  2473                     {
       
  2474                     __ALFLOGSTRING3( 
       
  2475                         "ExecuteCommandsFromDescriptorL HandleCmdL fail %d (subsession %d, operation %d)", 
       
  2476                         err, subSessionHandle, operation )
       
  2477                     }
       
  2478                 User::LeaveIfError( err );
       
  2479 #else
       
  2480                 subsessionEx->HandleCmdL( operation, inputbuffer, dummy );
       
  2481 #endif // _ALF_LOGGING
       
  2482                 }
       
  2483             }
       
  2484         }
       
  2485     
       
  2486     return aSource.Length() - unreadArea.Length();
       
  2487     }
       
  2488 
       
  2489 inline TBool CAlfAppSrvSession::AllowExecuteUsingDynamicBuffer() const
       
  2490     {
       
  2491     return ( iExecutionFlags & EAlfExecuteUsingDynamicBuffer );
       
  2492     }
       
  2493 
       
  2494 inline TBool CAlfAppSrvSession::AllowExecuteUsingCommonBuffer() const
       
  2495     {
       
  2496     return ( iExecutionFlags & EAlfExecuteUsingCommonBuffer );
       
  2497     }
       
  2498 
       
  2499 inline CAlfSrvTextureManager& CAlfAppSrvSession::AlfTextureManager()
       
  2500     {
       
  2501     return AlfServer()->TextureManager();
       
  2502     }
       
  2503 
       
  2504 void CAlfAppSrvSession::NotifyTextureInfo( const RMessage2& aMessage )
       
  2505     {
       
  2506     if ( iTextureInfoEvent.IsNull() )
       
  2507         {
       
  2508         iTextureInfoEvent = aMessage;
       
  2509                 
       
  2510         // If there has been texture info updates, 
       
  2511         // complete immediately.
       
  2512         DeliverTextureInfo();
       
  2513         }
       
  2514     else
       
  2515         {
       
  2516         aMessage.Complete( KErrInUse );
       
  2517         }   
       
  2518     }
       
  2519 
       
  2520 inline TBool CAlfAppSrvSession::HasPendingTextureInfo() const
       
  2521     {
       
  2522     TBool found = EFalse;
       
  2523     
       
  2524     for ( TInt i = 0; i < iTextureInfo.Count(); i++ )
       
  2525         {
       
  2526         const TAlfTextureInfo& info = iTextureInfo[ i ];
       
  2527         if ( info.iFlags & TAlfTextureInfo::EAlfFlagTextureSizeChanged )
       
  2528             {
       
  2529             found = ETrue;
       
  2530             break;
       
  2531             }
       
  2532         }
       
  2533         
       
  2534     return found;
       
  2535     }
       
  2536       
       
  2537 void CAlfAppSrvSession::DeliverTextureInfo()
       
  2538     {
       
  2539     if ( !(iFocused || iPartiallyVisible) || 
       
  2540          iTextureInfoEvent.IsNull() || !HasPendingTextureInfo() )
       
  2541         {
       
  2542         // Events are not delivered if
       
  2543         // - application does not have focus not partially visible
       
  2544         // - there is no pending notification
       
  2545         // - there is no texture info events to be delivered.
       
  2546         return;
       
  2547         }
       
  2548         
       
  2549     const TInt maxLength = iTextureInfoEvent.GetDesMaxLength( 0 );
       
  2550     
       
  2551     TAlfTextureInfoEvent event;
       
  2552     TPckgC<TAlfTextureInfoEvent> eventPckg( event );
       
  2553     const TInt eventPckgLength = eventPckg.Length();
       
  2554     
       
  2555     if ( maxLength <= eventPckgLength )
       
  2556         {
       
  2557         // Max length is less than size of one event buffer.
       
  2558         // So bail out.
       
  2559         iTextureInfoEvent.Complete( KErrBadDescriptor );
       
  2560         }
       
  2561     else
       
  2562         {
       
  2563         HBufC8* buffer = HBufC8::New( maxLength );
       
  2564         if ( buffer )
       
  2565             {
       
  2566             TPtr8 ptr = buffer->Des();
       
  2567 
       
  2568             TInt priority = 0;
       
  2569             TInt foundTexturePos = 0;
       
  2570             
       
  2571             const TInt totalTextureInfo = iTextureInfo.Count();
       
  2572             
       
  2573             while ( ( foundTexturePos != KErrNotFound ) && 
       
  2574                     ( maxLength - ptr.Length() >= eventPckgLength ) )
       
  2575                 {
       
  2576                 // As long as there is space and another texture, 
       
  2577                 // append to buffer.
       
  2578                 
       
  2579                 // Find using current priority.
       
  2580                 foundTexturePos = 
       
  2581                     FindNextTextureInfoForDelivery( priority, foundTexturePos );
       
  2582                 if ( ( foundTexturePos == KErrNotFound ) && !priority )
       
  2583                     {
       
  2584                     // If not found and priority was high, try
       
  2585                     // with lower priority.
       
  2586                     priority++;
       
  2587                     foundTexturePos = 0;
       
  2588                     
       
  2589                     foundTexturePos = FindNextTextureInfoForDelivery( 
       
  2590                         priority, foundTexturePos );
       
  2591                     }
       
  2592                                 
       
  2593                 if ( foundTexturePos != KErrNotFound )
       
  2594                     {
       
  2595                     TAlfTextureInfo& current = iTextureInfo[ foundTexturePos ];
       
  2596                     current.iFlags |= 
       
  2597                         TAlfTextureInfo::EAlfFlagTextureDelivered;
       
  2598                     current.iFlags &= 
       
  2599                         ~TAlfTextureInfo::EAlfFlagTextureSizeChanged;
       
  2600                     
       
  2601                     // Append event data
       
  2602                     event.iTextureId = current.iTextureId;
       
  2603                     event.iTextureSize = current.iTextureSize;
       
  2604                     ptr.Append( eventPckg );
       
  2605                     
       
  2606                     foundTexturePos++; // this has been delivered, skip to next
       
  2607                     }
       
  2608                 }
       
  2609         
       
  2610             iTextureInfoEvent.Write( 0, ptr );
       
  2611             iTextureInfoEvent.Complete( KErrNone );
       
  2612             
       
  2613             delete buffer;
       
  2614             buffer = NULL;
       
  2615             }
       
  2616         else
       
  2617             {
       
  2618             // It is expected that maxLength is relatively small value.
       
  2619             // So it's better to try again a bit later.
       
  2620             }
       
  2621         }
       
  2622     }
       
  2623 
       
  2624 TInt CAlfAppSrvSession::FindNextTextureInfoForDelivery( 
       
  2625         TBool aPriority, TInt aStartPos ) const
       
  2626     {
       
  2627     const TInt count = iTextureInfo.Count();
       
  2628     TInt result = KErrNotFound;
       
  2629     
       
  2630     for ( TInt index = aStartPos; index < count; index++ )
       
  2631         {
       
  2632         const TAlfTextureInfo& current = iTextureInfo[ index ];
       
  2633 
       
  2634         if ( ( current.iFlags & TAlfTextureInfo::EAlfFlagTextureSizeChanged ) &&
       
  2635              ( current.iDeliveryPriority == aPriority ) )
       
  2636             {
       
  2637             result = index;
       
  2638             break;
       
  2639             }
       
  2640         }
       
  2641     
       
  2642     return result;    
       
  2643     }
       
  2644 
       
  2645 TInt CAlfAppSrvSession::FindTextureInfoById( TInt aTextureId ) const
       
  2646     {
       
  2647     const TInt count = iTextureInfo.Count();
       
  2648     
       
  2649     // Optimization to handle the case that this method is called
       
  2650     // several times using the same texture id.
       
  2651     if ( iPreviousTextureInfoIndex < count )
       
  2652         {
       
  2653         if ( iTextureInfo[ iPreviousTextureInfoIndex ].iTextureId == 
       
  2654              aTextureId )
       
  2655             {
       
  2656             return iPreviousTextureInfoIndex;
       
  2657             }
       
  2658         }
       
  2659          
       
  2660     
       
  2661     TInt pos = KErrNotFound;
       
  2662     
       
  2663     for ( TInt i = 0; i < count; i++ )
       
  2664         {
       
  2665         if ( aTextureId == iTextureInfo[ i ].iTextureId )
       
  2666             {
       
  2667             pos = i;
       
  2668             iPreviousTextureInfoIndex = pos;
       
  2669             break;
       
  2670             }
       
  2671         }
       
  2672     
       
  2673     return pos;
       
  2674     }
       
  2675 
       
  2676 void CAlfAppSrvSession::RemoveTextureInfo( TInt aTextureId )
       
  2677     {
       
  2678     const TInt pos = FindTextureInfoById( aTextureId );
       
  2679     if ( pos != KErrNotFound )
       
  2680         {
       
  2681         iTextureInfo.Remove( pos );
       
  2682         }
       
  2683     }
       
  2684 
       
  2685 TInt CAlfAppSrvSession::GetTextureSize( 
       
  2686         TInt aTextureId, 
       
  2687         TSize& aTextureSize,
       
  2688         TBool& aHasBeenDelivered )
       
  2689     {
       
  2690     TInt pos = FindTextureInfoById( aTextureId );
       
  2691     if ( pos != KErrNotFound )
       
  2692         {
       
  2693         // TAlfTextureInfo struct was found - pos >= 0
       
  2694         aTextureSize = iTextureInfo[ pos ].iTextureSize;
       
  2695         aHasBeenDelivered = iTextureInfo[ pos ].iFlags & 
       
  2696             TAlfTextureInfo::EAlfFlagTextureDelivered;
       
  2697         }
       
  2698         
       
  2699     return pos != KErrNotFound;
       
  2700     }
       
  2701     
       
  2702 void CAlfAppSrvSession::SetTextureSize(
       
  2703         TInt aTextureId,
       
  2704         const TSize& aTextureSize,
       
  2705         TInt aPriority )
       
  2706     {
       
  2707     const TBool highPriority = ( aPriority < 0 );
       
  2708     aPriority = Max( 0, aPriority );
       
  2709     aPriority = Min( 1, aPriority );
       
  2710 
       
  2711     TInt pos = FindTextureInfoById( aTextureId );
       
  2712     if ( pos != KErrNotFound )
       
  2713         {
       
  2714         // TAlfTextureInfo struct was found - pos >= 0
       
  2715         TAlfTextureInfo& info = iTextureInfo[ pos ];
       
  2716         info.iTextureSize = aTextureSize;
       
  2717         info.iFlags |= TAlfTextureInfo::EAlfFlagTextureSizeChanged;
       
  2718         info.iFlags &= ~TAlfTextureInfo::EAlfFlagTextureDelivered;
       
  2719         info.iDeliveryPriority = aPriority;
       
  2720         
       
  2721         if ( highPriority )
       
  2722             {
       
  2723             // Move to the beginning. After this, above info
       
  2724             // struct is invalid.
       
  2725             TAlfTextureInfo tmp = iTextureInfo[ pos ];
       
  2726             iTextureInfo.Remove( pos );
       
  2727             iTextureInfo.Insert( tmp, 0 );
       
  2728             }
       
  2729         }
       
  2730     else
       
  2731         {
       
  2732         // TAlfTextureInfo struct was not found - append a new one.
       
  2733         TAlfTextureInfo info;
       
  2734         info.iFlags = TAlfTextureInfo::EAlfFlagTextureSizeChanged;
       
  2735         info.iTextureId = aTextureId;
       
  2736         info.iTextureSize = aTextureSize;
       
  2737         info.iDeliveryPriority = aPriority;
       
  2738         
       
  2739         if ( highPriority )
       
  2740             {
       
  2741             iTextureInfo.Insert( info, 0 );
       
  2742             }
       
  2743         else
       
  2744             {
       
  2745             iTextureInfo.Append( info );
       
  2746             }
       
  2747         }
       
  2748     }
       
  2749     
       
  2750 void CAlfAppSrvSession::RemoveTextureSize( TInt aTextureId )
       
  2751     {
       
  2752     RemoveTextureInfo( aTextureId );
       
  2753     }
       
  2754     
       
  2755 void CAlfAppSrvSession::TextureSizeChangesCompleted()
       
  2756     {
       
  2757     DeliverTextureInfo();
       
  2758     }
       
  2759 
       
  2760 // ---------------------------------------------------------------------------
       
  2761 // PostQtCommandBufferL
       
  2762 // ---------------------------------------------------------------------------
       
  2763 //
       
  2764 void CAlfAppSrvSession::PostQtCommandBufferL( const RMessage2& aMessage )
       
  2765     {
       
  2766   	TAlfQtCommandBufferParams params;
       
  2767     TPckg<TAlfQtCommandBufferParams> paramsPckg(params);
       
  2768     aMessage.Read(0,paramsPckg);    
       
  2769 	AlfAppUi()->PostQTCommandBufferL( params );  
       
  2770 	}
       
  2771 
       
  2772 // ---------------------------------------------------------------------------
       
  2773 // ReportFrameRateBeginL
       
  2774 // ---------------------------------------------------------------------------
       
  2775 //
       
  2776 void CAlfAppSrvSession::ReportFrameRateBegin( const RMessage2& aMessage )
       
  2777     {
       
  2778     TInt32 id = aMessage.Int0();
       
  2779     TFrameStamp* stamp = iFPSMeasurementArray.Find( id );
       
  2780     // remove existing id, if any
       
  2781     if ( stamp )
       
  2782         {
       
  2783         iFPSMeasurementArray.Remove(id);
       
  2784         }
       
  2785     iFPSMeasurementArray.Insert( id, TFrameStamp( CHuiStatic::FrameCount() ));
       
  2786     }
       
  2787             
       
  2788 // ---------------------------------------------------------------------------
       
  2789 // ReportFrameRateEndL
       
  2790 // ---------------------------------------------------------------------------
       
  2791 //
       
  2792 void CAlfAppSrvSession::ReportFrameRateEnd( const RMessage2& aMessage )
       
  2793     {
       
  2794     TInt32 id = aMessage.Int0();
       
  2795     TFrameStamp FPSMeasurementEnd= TFrameStamp( CHuiStatic::FrameCount() );
       
  2796     TBuf<40> logText;
       
  2797             
       
  2798     TFrameStamp* begin = iFPSMeasurementArray.Find( id );
       
  2799     if ( begin )
       
  2800         {
       
  2801         TReal32 fps = FPSMeasurementEnd.FrameRate( *begin );
       
  2802         iFPSMeasurementArray.Remove(id);
       
  2803         
       
  2804         logText.Format( _L("%d\t%4.2f"), id, fps );    
       
  2805         RFileLogger::Write( KLogsDir, KAlfFPSLogFile, EFileLoggingModeAppend, logText );
       
  2806         }
       
  2807     else
       
  2808         {
       
  2809         logText.Format( _L("Id %d not found"), id );    
       
  2810         RFileLogger::Write( KAlfFPSLogDir, KAlfFPSLogFile, EFileLoggingModeAppend, logText );
       
  2811         }
       
  2812     RDebug::Print(_L("CAlfAppSrvSession::ReportFrameRateL - %S"), &logText );
       
  2813     }
       
  2814 
       
  2815 
       
  2816 // ---------------------------------------------------------------------------
       
  2817 // EnvEnableLowMemoryState
       
  2818 // ---------------------------------------------------------------------------
       
  2819 //    
       
  2820 void CAlfAppSrvSession::EnvEnableLowMemoryState(const RMessage2& aMessage)
       
  2821     {
       
  2822     TBool mode = aMessage.Int0();
       
  2823     AlfAppUi()->NotifyLowMemory(mode);
       
  2824     }
       
  2825 
       
  2826 // ---------------------------------------------------------------------------
       
  2827 // EnvForceSwRendering
       
  2828 // ---------------------------------------------------------------------------
       
  2829 //    
       
  2830 void CAlfAppSrvSession::EnvForceSwRendering(const RMessage2& aMessage)
       
  2831     {
       
  2832     TBool enabled = aMessage.Int0();
       
  2833     TInt err = AlfAppUi()->ForceSwRendering( enabled );
       
  2834     aMessage.Complete( err );
       
  2835     }
       
  2836 
       
  2837 // End of file