uigraphics/AknIcon/srvsrc/AknIconSrv.cpp
changeset 0 05e9090e2422
child 2 abcbdabaa4c5
equal deleted inserted replaced
-1:000000000000 0:05e9090e2422
       
     1 /*
       
     2 * Copyright (c) 2002 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 the License "Symbian Foundation License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation of class CAknIconSrv.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 #include <e32svr.h>
       
    23 #include <e32property.h>
       
    24 #include <fbs.h>
       
    25 #include <gdi.h>
       
    26 #include <bitdev.h>
       
    27 #include <mifconvdefs.h>
       
    28 
       
    29 #ifdef PRECACHELOG
       
    30 #include <flogger.h>
       
    31 #endif
       
    32 #include "AknIconSrv.h"
       
    33 #include "AknIconSrvScheduler.h"
       
    34 #include "AknIconSrvSession.h"
       
    35 #include "AknIconSrvDef.h"
       
    36 #include "AknIconSrvIconItem.h"
       
    37 #include "AknIconFormatHandler.h"
       
    38 #include "AknIconFormatHandlerFactory.h"
       
    39 #include "AknIconLoader.h"
       
    40 #include "AknIconSrvCache.h"
       
    41 #include "AknIconSrvPanic.h"
       
    42 #include "AknIconUtils.h"
       
    43 #include "AknIconDataPreserver.h"
       
    44 #include "AknIconDataItem.h"
       
    45 #include "AknIconSrvUtils.h"
       
    46 #include "AknIconFileNameCache.h"
       
    47 #include "akniconconfig.h"
       
    48 #include "AknIconTraces.h"
       
    49 
       
    50 #include "AknBitmap.h"
       
    51 #include <centralrepository.h>
       
    52 #include <UikonInternalPSKeys.h>    // KUikLayoutState
       
    53 #include <AvkonInternalCRKeys.h>    // KAknQwertyInputModeActive
       
    54 #include <avkondomainpskeys.h>      // KAknPowerMenuStatus
       
    55 #include <bitdev.h>
       
    56 // CONSTANTS
       
    57 
       
    58 const TUid KZiUdbProterty = {0x101F8614};
       
    59 const TInt KZiUdbPropertyKey = 1;
       
    60 const TUid KT9UdbProterty = {0x101F8615};
       
    61 const TInt KT9UdbPropertyKey = 1;
       
    62 
       
    63 const TInt KIconItemArrayGranularity = 4;
       
    64 
       
    65 // Value -1 is used to indicate 'automatic' layout ID detection.        
       
    66 const TInt KAvkonAutomaticLayoutDetectionValue = -1;
       
    67 
       
    68 _LIT( KAvkonIconFileName, "z:\\resource\\apps\\avkon2.mif" );
       
    69 _LIT( KAknIconServerStartupSemaphore, "AknIconSem" );
       
    70 
       
    71 // ================= MEMBER FUNCTIONS =======================
       
    72 
       
    73 CAknIconServer::CAknIconServer()
       
    74     : CServer2( CActive::EPriorityStandard ),
       
    75     iIconItems( KIconItemArrayGranularity )
       
    76     {
       
    77     }
       
    78 
       
    79 // Create and start a new server.
       
    80 CAknIconServer* CAknIconServer::NewL()
       
    81     {
       
    82     CAknIconServer* server = new( ELeave ) CAknIconServer;
       
    83     CleanupStack::PushL( server );
       
    84     server->ConstructL();
       
    85     CleanupStack::Pop();
       
    86     return server;
       
    87     }
       
    88 
       
    89 void CAknIconServer::ConstructL()
       
    90     {    
       
    91     User::LeaveIfError( iFsSession.Connect() );
       
    92     User::LeaveIfError( RFbsSession::Connect() );
       
    93     User::LeaveIfError( Start( KAknIconSrvName ) );
       
    94 
       
    95     iFileNameCache = CAknIconFileNameCache::NewL();
       
    96     iIconDataPreserver = CAknIconDataPreserver::NewL( *this );
       
    97 
       
    98     
       
    99     _LIT_SECURITY_POLICY_PASS(KPassReadPolicy);
       
   100     _LIT_SECURITY_POLICY_PASS(KPassWritePolicy);
       
   101 
       
   102     _LIT_SECURITY_POLICY_C1(KWriteDDPolicy, ECapabilityWriteDeviceData);
       
   103     _LIT_SECURITY_POLICY_C1(KWriteTUPolicy, ECapabilityTrustedUI);
       
   104     
       
   105     TInt err1  = RProperty::Define(KCRUidAvkon,       KAknQwertyInputModeActive, RProperty::EInt, KPassReadPolicy, KWriteDDPolicy);
       
   106     TInt err2  = RProperty::Define(KPSUidUikon,       KUikLayoutState,           RProperty::EInt, KPassReadPolicy, KWriteDDPolicy);
       
   107     TInt err3  = RProperty::Define(KPSUidUikon,       KUikOOMWatchdogStatus,     RProperty::EInt, KPassReadPolicy, KPassWritePolicy);
       
   108     TInt err4  = RProperty::Define(KPSUidUikon,       KUikVideoCallTopApp,       RProperty::EInt, KPassReadPolicy, KWriteDDPolicy);
       
   109     TInt err5  = RProperty::Define(KPSUidUikon,       KUikFFSFreeLevel,          RProperty::EInt, KPassReadPolicy, KWriteTUPolicy);
       
   110     TInt err6  = RProperty::Define(KPSUidUikon,       KUikMmcFFSFreeLevel,       RProperty::EInt, KPassReadPolicy, KWriteTUPolicy);
       
   111     TInt err7  = RProperty::Define(KPSUidUikon,       KUikGlobalNotesAllowed,    RProperty::EInt, KPassReadPolicy, KWriteDDPolicy);
       
   112     TInt err8  = RProperty::Define(KZiUdbProterty,    KZiUdbPropertyKey,         RProperty::EInt, KPassReadPolicy, KPassWritePolicy);
       
   113     TInt err9  = RProperty::Define(KT9UdbProterty,    KT9UdbPropertyKey,         RProperty::EInt, KPassReadPolicy, KPassWritePolicy);
       
   114     TInt err10 = RProperty::Define(KPSUidAvkonDomain, KAknPowerMenuStatus,       RProperty::EInt, KPassReadPolicy, KWriteDDPolicy);
       
   115     TInt err11 = RProperty::Define(KPSUidAvkonDomain, KAknEndKeyEvent,           RProperty::EInt, KPassReadPolicy, KWriteDDPolicy);         
       
   116 
       
   117 #ifdef _DEBUG
       
   118     RDebug::Print(_L("xxxx KAknQwertyInputModeActive err=%d"), err1);
       
   119     RDebug::Print(_L("xxxx KUikLayoutState           err=%d"), err2);
       
   120     RDebug::Print(_L("xxxx KUikOOMWatchdogStatus     err=%d"), err3);
       
   121     RDebug::Print(_L("xxxx KUikVideoCallTopApp       err=%d"), err4);
       
   122     RDebug::Print(_L("xxxx KUikFFSFreeLevel          err=%d"), err5);
       
   123     RDebug::Print(_L("xxxx KUikMmcFFSFreeLevel       err=%d"), err6);
       
   124     RDebug::Print(_L("xxxx KUikGlobalNotesAllowed    err=%d"), err7);
       
   125     RDebug::Print(_L("xxxx KZiUdbProterty            err=%d"), err8);
       
   126     RDebug::Print(_L("xxxx KT9UdbProterty            err=%d"), err9);
       
   127     RDebug::Print(_L("xxxx KAknPowerMenuStatus       err=%d"), err10);
       
   128     RDebug::Print(_L("xxxx KAknEndKeyEvent           err=%d"), err11);
       
   129 #endif
       
   130     
       
   131     CRepository* repository = NULL;
       
   132     TRAPD(ret, repository = CRepository::NewL(KCRUidAvkon));
       
   133     if (ret == KErrNone)
       
   134         {
       
   135         // Reset value of KAknLayoutId on the boot.
       
   136         // Return value ignored.
       
   137         ret = repository->Set(KAknLayoutId, KAvkonAutomaticLayoutDetectionValue); 
       
   138         }
       
   139     delete repository;
       
   140     repository = NULL;     
       
   141          
       
   142 #ifdef _NGATESTING
       
   143 
       
   144     do {
       
   145 
       
   146     iConfigIconType = -1;
       
   147 
       
   148     TRAPD(leaveError, LoadConfigurationL(iFsSession));
       
   149 
       
   150 		if(leaveError!=KErrNone)
       
   151 		{
       
   152 			#ifdef _DEBUG
       
   153 		RDebug::Print(_L("xxxx LoadConfigurationL err=%d"), leaveError);
       
   154 		#endif
       
   155 		}
       
   156 
       
   157     } while (0);
       
   158 
       
   159 #endif
       
   160     iThreadLaunchStatus = KRequestPending;
       
   161     // This launches SVG precache thread, if required.
       
   162 
       
   163     iCache = CAknIconSrvCache::NewL( *this );
       
   164     User::WaitForRequest( iThreadLaunchStatus );
       
   165     }
       
   166 
       
   167 CAknIconServer::~CAknIconServer()
       
   168     {
       
   169     iIconItems.ResetAndDestroy();
       
   170 
       
   171     delete iAvkonIconLoader;
       
   172     delete iOtherIconLoader;
       
   173     delete iCurrentIconFile;
       
   174     delete iCache;
       
   175     delete iIconDataPreserver;    
       
   176     delete iFileNameCache;
       
   177     
       
   178     iHandlerList.ResetAndDestroy();
       
   179     RFbsSession::Disconnect();
       
   180     iFsSession.Close();
       
   181     }
       
   182 
       
   183 // -----------------------------------------------------------------------------
       
   184 // CAknIconServer::NewSessionL()
       
   185 // -----------------------------------------------------------------------------
       
   186 
       
   187 CSession2* CAknIconServer::NewSessionL(
       
   188     const TVersion& /*aVersion*/, const RMessage2& /*aMessage*/) const
       
   189     {
       
   190     return new( ELeave ) CAknIconSrvSession( );
       
   191     }
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // CAknIconServer::RetrieveOrCreateSharedIconL
       
   195 // -----------------------------------------------------------------------------
       
   196 //
       
   197 const CAknIconSrvIconItem* CAknIconServer::RetrieveOrCreateSharedIconL()
       
   198     {
       
   199     #ifdef __AKNICON_TRACES
       
   200     RDebug::Print(_L("AKNICON start"));
       
   201     #endif
       
   202     
       
   203     TAknIconParams info;
       
   204     TPckg<TAknIconParams> infoPack( info );
       
   205     TRAPD( err, Message().ReadL( 0, infoPack ) );
       
   206 	if ( err != KErrNone ) 
       
   207     	{
       
   208     	((CAknIconSrvSession*)(Message().Session()))->SetClientPanicCode(EBadDescriptor);
       
   209     	User::Leave(KAknIconSrvCodePanicClient);
       
   210     	}
       
   211 	
       
   212     TAknIconSrvReturnData retData;
       
   213     TPckg<TAknIconSrvReturnData> dataPack( retData );
       
   214 
       
   215     CAknIconSrvIconItem* item = NULL;
       
   216 
       
   217 #ifdef __AKNICON_TRACES
       
   218     info.PrintInfo();
       
   219 #endif     
       
   220 #ifdef PRECACHE2
       
   221      // bitmap handles of precached icons need to be duplicated
       
   222      while(iNewPrecachedItems.Count())
       
   223         {
       
   224         #ifdef __AKNICON_TRACES
       
   225         RDebug::Printf("Precache add,%d",iNewPrecachedItems.Count());
       
   226         #endif
       
   227         
       
   228         CAknIconSrvIconItem* item = iNewPrecachedItems[0];
       
   229         CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
       
   230         CleanupStack::PushL(bitmap);
       
   231         TInt err1 = bitmap->Duplicate(item->iBitmap->Handle());
       
   232         iFreePrecacheBitmapHandles.AppendL(item->iBitmap);
       
   233         CleanupStack::Pop();
       
   234         
       
   235         item->iBitmap = bitmap;
       
   236         CFbsBitmap* mask = NULL;
       
   237         if (item->iMask)
       
   238             {
       
   239             mask = new (ELeave) CFbsBitmap;
       
   240             CleanupStack::PushL(mask);
       
   241             TInt err2 = mask->Duplicate(item->iMask->Handle());
       
   242             iFreePrecacheBitmapHandles.AppendL(item->iMask);
       
   243             CleanupStack::Pop();
       
   244             item->iMask = mask;
       
   245             }
       
   246 
       
   247             
       
   248         err1 = iIconItems.InsertInOrder( item, CAknIconSrvIconItem::LinearOrder );
       
   249         if (err1 == KErrAlreadyExists)
       
   250             {
       
   251             iNewPrecachedItems.Remove(0);
       
   252                     
       
   253             #ifdef __AKNICON_TRACES
       
   254             RDebug::Printf("precache warning, already exists!");
       
   255             #endif
       
   256             
       
   257             TInt index = iIconItems.FindInOrder(item, CAknIconSrvIconItem::LinearOrder );
       
   258             CAknIconSrvIconItem* foundItem = iIconItems[index];
       
   259             
       
   260             foundItem->iPrecacheItem = ETrue;
       
   261             
       
   262             //Set this item to be cached
       
   263             if(foundItem->IsExcludedFromCache())
       
   264                 {
       
   265                 foundItem->SetCached();
       
   266                 }
       
   267             
       
   268             //Item not in use and hence in Dynamic cache
       
   269             //Move item from dynamic cache to precache    
       
   270             if( foundItem->iUserCount == 0)
       
   271                 {
       
   272                 iCache->DynamicToPrecache( *foundItem);    
       
   273                 }
       
   274             else
       
   275                 {
       
   276                 }
       
   277             delete item;
       
   278             }
       
   279         else if (err1 == KErrNone)
       
   280             {
       
   281             iNewPrecachedItems.Remove(0);
       
   282             
       
   283             #ifdef __AKNICON_TRACES
       
   284             RDebug::Print(_L("precache load,%S,%d,%d,%d,%d,%d,%d,%d"),
       
   285                  item->iFileName,
       
   286                  item->iBitmapId,
       
   287                  item->iMaskId,
       
   288                  item->iSize.iWidth,
       
   289                  item->iSize.iHeight,
       
   290                  item->iModeAndFlags & 0xffff,
       
   291                  item->iRotationAngle,
       
   292                  item->iColor.Internal());
       
   293             #endif    
       
   294                  
       
   295             iCurrentIndex = iIconItems.FindInOrder(item, CAknIconSrvIconItem::LinearOrder );
       
   296             // delete icon, so it will be moved to icon cache
       
   297             if (DeleteOrCacheUnusedIcon(item) == EFalse)
       
   298                 {
       
   299                 AknIconConfig::CompressIfPreferred(bitmap, mask,iCompression);
       
   300                 }
       
   301             else
       
   302                 {
       
   303 	            #ifdef __AKNICON_TRACES
       
   304 	            RDebug::Printf("Did not insert into dynamic cache, deleting item");
       
   305 	            #endif
       
   306                 }
       
   307             }
       
   308         else
       
   309             {
       
   310             
       
   311             #ifdef __AKNICON_TRACES
       
   312             RDebug::Printf("precache warning, Unable to insert into iIconItems");
       
   313             #endif
       
   314             // No point continuing if one item insertion fails, as
       
   315             // following requests would result in same error.
       
   316             break;
       
   317             }
       
   318         }
       
   319         
       
   320      if (iPrecacheComplete)
       
   321         {
       
   322         iPreCacheThread.Resume();
       
   323         iPrecacheComplete = EFalse;
       
   324         }
       
   325 #endif
       
   326     TInt index = RetrieveIcon( info );
       
   327     if ( index >= 0 )
       
   328         {
       
   329         item = iIconItems[index];
       
   330 
       
   331         item->iUserCount++;
       
   332         if ( info.iMaskId >= 0 )
       
   333             {
       
   334             // Also mask increases user count.
       
   335             item->iUserCount++;
       
   336             }
       
   337 
       
   338 #ifdef __AKNICON_TRACES
       
   339     RDebug::Print( _L("AknIcon: %x CAknIconServer::RetrieveOrCreateSharedIconL: existing item=%x, info=%x"), this, item, &info);
       
   340 #endif   
       
   341             
       
   342         }
       
   343     // Not found in current icon item list
       
   344     else
       
   345         {
       
   346         // MBM icon case
       
   347         if ( info.IsMbmIcon() )
       
   348             {
       
   349             Message().ReadL( 1, dataPack );
       
   350             item = CreateMbmIconL( info, retData );
       
   351             }
       
   352 
       
   353         // MIF icon case
       
   354         else
       
   355             {
       
   356 
       
   357             item = iIconDataPreserver->CreateIconL( info );
       
   358 
       
   359             if ( !item )
       
   360                 {
       
   361                 item = CreateIconL( info );
       
   362                 }
       
   363             
       
   364              //PrecacheCache tool
       
   365             #ifdef PRECACHELOG                 
       
   366 
       
   367             
       
   368             _LIT( KFileLoggingDir, "AknIconPreCacher" );
       
   369             _LIT( KFileLog, "Traces.txt" );
       
   370                      
       
   371 
       
   372 
       
   373             _LIT(lMsg, "AKNICON load,%S,%d,%d,%d,%d,%d,%d,%d,%d");
       
   374             RFileLogger::WriteFormat(KFileLoggingDir, KFileLog, EFileLoggingModeAppend, lMsg,
       
   375             &info.iFileName,
       
   376                      info.iBitmapId,
       
   377                      info.iMaskId,
       
   378                      info.iSize.iWidth,
       
   379                      info.iSize.iHeight,
       
   380                      info.iMode,
       
   381                      info.iRotationAngle,
       
   382                      info.iColor.Internal(),
       
   383                      info.IsCompressionDisabled());                 
       
   384                      
       
   385                 
       
   386                
       
   387                     
       
   388             #endif
       
   389             //PrecacheCache tool
       
   390                 }
       
   391        
       
   392        
       
   393         if ( info.iAppIcon )
       
   394             {
       
   395             if ( info.IsMbmIcon() )
       
   396                 {
       
   397                 AknIconSrvUtils::EnsureValidSizeL(item->iBitmap, item->iMask);   
       
   398                 }
       
   399            #ifndef __NVG
       
   400 		else 
       
   401 		    {
       
   402 		    ReCreateSvgL(info,item);
       
   403 		    } 
       
   404            #endif /*__NVG*/
       
   405             }
       
   406        
       
   407 #ifdef __AKNICON_TRACES
       
   408     RDebug::Print( _L("AknIcon: %x CAknIconServer::RetrieveOrCreateSharedIconL: new item=%x, info=%x"), this, item, &info);
       
   409 #endif   
       
   410         CleanupStack::PushL( item );
       
   411 
       
   412         // Apply icon color here, if requested.
       
   413         ApplyIconColorL( item, info.iColor );
       
   414 
       
   415         // Call CompressIfPreferred if bitmap compression is not
       
   416         // disabled for the icon
       
   417         if (!item->IsCompressionDisabled())
       
   418             {
       
   419             AknIconConfig::CompressIfPreferred(item->iBitmap, item->iMask,iCompression);     
       
   420             }               
       
   421 
       
   422         User::LeaveIfError( 
       
   423             iIconItems.InsertInOrder( item, CAknIconSrvIconItem::LinearOrder ) );
       
   424 
       
   425         CleanupStack::Pop(); // item
       
   426         }
       
   427 
       
   428     // No leaving code allowed in the end of the function!
       
   429     // Otherwise icon item's user count is increased but never decreased,
       
   430     // because an error code is returned to the client.
       
   431 
       
   432     retData.iBitmapHandle = item->iBitmap->Handle();
       
   433     if ( item->iMask )
       
   434         {
       
   435         retData.iMaskHandle = item->iMask->Handle();
       
   436         }
       
   437 
       
   438     retData.iContentDimensions = item->iDimensions;
       
   439 
       
   440     // Remove item from cache because it is now used by someone.
       
   441     iCache->RemoveIfCached( *item );
       
   442     
       
   443     #ifdef __AKNICON_TRACES
       
   444     RDebug::Print(_L("AKNICON loaded,%S,%d,%d"),&info.iFileName,info.iBitmapId,item->iBitmap->Handle());
       
   445     #endif
       
   446     // Set if the icon will be cached dynamically after it is not used
       
   447     // Note that if the icon was excluded from cache earlier it will remain
       
   448     // excluded for its lifetime.
       
   449     if (info.IsExcludedFromCache())
       
   450         {
       
   451         item->ExcludeFromCache();    
       
   452         }
       
   453 
       
   454     // This does not leave as long as the descriptor is valid in the client side.
       
   455     Message().WriteL( 1, dataPack );
       
   456 
       
   457     return item;
       
   458     }
       
   459 
       
   460 // -----------------------------------------------------------------------------
       
   461 // CAknIconServer::FreeBitmapL
       
   462 //
       
   463 // Note: This function can only leave when an ASSERT fails. During normal 
       
   464 //       conditions it should never leave.
       
   465 // -----------------------------------------------------------------------------
       
   466 //
       
   467 const CAknIconSrvIconItem* CAknIconServer::FreeBitmapL()
       
   468     {
       
   469     TAknIconParams info;
       
   470     TPckg<TAknIconParams> paramPack( info );
       
   471     TRAPD( err, Message().ReadL( 0, paramPack ) );
       
   472 
       
   473     __ASSERT_ALWAYS( err == KErrNone, 
       
   474        (
       
   475        ((CAknIconSrvSession*)(Message().Session()))->SetClientPanicCode(EBadDescriptor),
       
   476        User::Leave( KAknIconSrvCodePanicClient ) // leave to prevent possible server crash
       
   477        ));
       
   478        
       
   479 
       
   480     iCurrentIndex = RetrieveIcon( info );
       
   481 
       
   482     __ASSERT_ALWAYS( iCurrentIndex >= 0, 
       
   483         (
       
   484         ((CAknIconSrvSession*)(Message().Session()))->SetClientPanicCode(EIconNotFound),
       
   485         User::Leave( KAknIconSrvCodePanicClient ) // leave to prevent possible server crash
       
   486         ));
       
   487 
       
   488     CAknIconSrvIconItem* item = iIconItems[iCurrentIndex];
       
   489 		  if (info.IsExcludedFromCache())
       
   490         {
       
   491         item->ExcludeFromCache();    
       
   492         }    
       
   493 
       
   494     item->iUserCount--;
       
   495     
       
   496 #ifdef __AKNICON_TRACES
       
   497     RDebug::Print( _L("AknIcon: %x CAknIconServer::FreeBitmapL: item=%x, user count=%d"), this, item, item->iUserCount);
       
   498 #endif 
       
   499     
       
   500     DeleteOrCacheUnusedIcon( item );
       
   501 
       
   502     // It is safe to return also a pointer to a deleted item.
       
   503     return item;
       
   504     }
       
   505 
       
   506 // -----------------------------------------------------------------------------
       
   507 // CAknIconServer::PreserveIconDataL
       
   508 // -----------------------------------------------------------------------------
       
   509 //
       
   510 const CAknIconDataItem* CAknIconServer::PreserveIconDataL()
       
   511     {
       
   512     TAknIconParams params;
       
   513     TPckg<TAknIconParams> paramsPack( params );
       
   514     TRAPD( err, Message().ReadL( 0, paramsPack ) );
       
   515 	if ( err != KErrNone ) 
       
   516     	{
       
   517     	((CAknIconSrvSession*)(Message().Session()))->SetClientPanicCode(EBadDescriptor);
       
   518     	User::Leave(KAknIconSrvCodePanicClient);
       
   519     	}
       
   520 
       
   521     return iIconDataPreserver->PreserveIconDataL( params );
       
   522     }
       
   523 
       
   524 // -----------------------------------------------------------------------------
       
   525 // CAknIconServer::UnpreserveIconDataL
       
   526 //
       
   527 // Note: This function can only leave when an ASSERT fails. During normal 
       
   528 //       conditions it should never leave.
       
   529 // -----------------------------------------------------------------------------
       
   530 //
       
   531 const CAknIconDataItem* CAknIconServer::UnpreserveIconDataL()
       
   532     {
       
   533     TAknIconParams params;
       
   534     TPckg<TAknIconParams> paramsPack( params );
       
   535 
       
   536     TRAPD( err, Message().ReadL( 0, paramsPack ) );
       
   537 	if ( err != KErrNone ) 
       
   538     	{
       
   539     	((CAknIconSrvSession*)(Message().Session()))->SetClientPanicCode(EBadDescriptor);
       
   540     	User::Leave(KAknIconSrvCodePanicClient);
       
   541     	}
       
   542     	
       
   543 
       
   544     return iIconDataPreserver->UnpreserveIconData( params, 1, Message());
       
   545     }
       
   546 
       
   547 // -----------------------------------------------------------------------------
       
   548 // CAknIconServer::GetContentDimensionsL
       
   549 // -----------------------------------------------------------------------------
       
   550 //
       
   551 void CAknIconServer::GetContentDimensionsL()
       
   552     {
       
   553     TAknIconParams params;
       
   554     TPckg<TAknIconParams> paramsPack( params );
       
   555     TRAPD( err, Message().ReadL( 0, paramsPack ) );
       
   556 	if ( err != KErrNone ) 
       
   557     	{
       
   558     	((CAknIconSrvSession*)(Message().Session()))->SetClientPanicCode(EBadDescriptor);
       
   559     	User::Leave(KAknIconSrvCodePanicClient);
       
   560     	}
       
   561 
       
   562     TAknContentDimensions dimensions;
       
   563 
       
   564     iIconDataPreserver->GetContentDimensionsL( params, dimensions );
       
   565 
       
   566     TPckg<TAknContentDimensions> dimensionsPack( dimensions );
       
   567     Message().WriteL( 1, dimensionsPack );
       
   568     }
       
   569 
       
   570 // -----------------------------------------------------------------------------
       
   571 // CAknIconServer::CleanupSessionIconItem
       
   572 // -----------------------------------------------------------------------------
       
   573 //
       
   574 void CAknIconServer::CleanupSessionIconItem( 
       
   575     const TAknIconSrvSessionIconItem& aItem )
       
   576     {
       
   577     TAknIconParams info;
       
   578     aItem.iIcon->GetInfo( info );
       
   579 
       
   580     iCurrentIndex = RetrieveIcon( info );
       
   581 
       
   582     // The icon must be found otherwise there is a coding error
       
   583     // in server side.
       
   584     __ASSERT_DEBUG( iCurrentIndex >= 0, 
       
   585         User::Panic( KAknIconPanicCategory, EIconNotFound ));
       
   586 
       
   587     if (iCurrentIndex >= 0)
       
   588         {
       
   589     CAknIconSrvIconItem* item = iIconItems[iCurrentIndex];
       
   590 
       
   591     item->iUserCount -= aItem.iUserCount; 
       
   592     DeleteOrCacheUnusedIcon( item );
       
   593         }
       
   594     }
       
   595 
       
   596 // -----------------------------------------------------------------------------
       
   597 // CAknIconServer::CleanupSessionPreservedItem
       
   598 // -----------------------------------------------------------------------------
       
   599 //
       
   600 void CAknIconServer::CleanupSessionPreservedItem( 
       
   601     const TAknIconSrvSessionPreservedItem& aItem )
       
   602     {
       
   603     TAknIconParams info;
       
   604     aItem.iDataItem->GetInfo( info );
       
   605     iIconDataPreserver->UnpreserveIconData( info, aItem.iUserCount, Message() );
       
   606     }
       
   607 
       
   608 // -----------------------------------------------------------------------------
       
   609 // CAknIconServer::RemoveCachedItem
       
   610 // -----------------------------------------------------------------------------
       
   611 //
       
   612 void CAknIconServer::RemoveCachedItem( const CAknIconSrvIconItem& aItem )
       
   613     {
       
   614     TInt index = iIconItems.FindInOrder(
       
   615         &aItem, CAknIconSrvIconItem::LinearOrder );
       
   616 
       
   617     __ASSERT_DEBUG( index >= 0,
       
   618         User::Panic( KAknIconSrvPanicCategory, ESrvPanicIconNotFound ) );
       
   619 
       
   620     __ASSERT_DEBUG( aItem.iUserCount == 0,
       
   621         User::Panic( KAknIconSrvPanicCategory, ESrvPanicCachedItemUserCountNonZero ) );
       
   622 
       
   623     __ASSERT_DEBUG( index != iCurrentIndex,
       
   624         User::Panic( KAknIconSrvPanicCategory, ESrvPanicCurrentIconItemDeleted ) );
       
   625 
       
   626     iIconItems.Remove( index );
       
   627     delete &aItem;
       
   628 
       
   629     // Array has changed, so have to keep iCurrentIndex valid. It is used in
       
   630     // another function, which calls this function.
       
   631     if ( index < iCurrentIndex )
       
   632         {
       
   633         iCurrentIndex--;
       
   634         }
       
   635     }
       
   636 
       
   637 
       
   638 
       
   639 // -----------------------------------------------------------------------------
       
   640 // CAknIconServer::InvalidateItemsCachedFromSkin
       
   641 // -----------------------------------------------------------------------------
       
   642 //
       
   643 void CAknIconServer::InvalidateItemsCachedFromSkin()
       
   644     {
       
   645     for ( TInt i = iIconItems.Count() - 1 ; i >= 0 ; i-- )
       
   646         {
       
   647         CAknIconSrvIconItem* item = iIconItems[i];
       
   648 
       
   649         if ( item->IsCachedFromSkin() )
       
   650             {
       
   651             item->ClearPermanentlyCached();
       
   652 
       
   653             if ( item->iUserCount == 0 )
       
   654                 {
       
   655                 iIconItems.Remove( i );
       
   656                 delete item;
       
   657                 }
       
   658             }
       
   659         }
       
   660     }
       
   661 
       
   662 
       
   663 
       
   664 // -----------------------------------------------------------------------------
       
   665 // CAknIconServer::ResetDynamicallyChangingAllocations
       
   666 // -----------------------------------------------------------------------------
       
   667 //
       
   668 void CAknIconServer::ResetDynamicallyChangingAllocations()
       
   669     {
       
   670 #ifdef _DEBUG
       
   671     // Reset dynamic cache
       
   672     iCurrentIndex = -1;
       
   673     iCache->ResetDynamicCache();
       
   674 
       
   675     // Reset dynamically changing icon loader
       
   676     delete iCurrentIconFile;
       
   677     iCurrentIconFile = NULL;
       
   678     delete iOtherIconLoader;
       
   679     iOtherIconLoader = NULL;
       
   680 
       
   681 #endif // _DEBUG
       
   682     }
       
   683 
       
   684 // -----------------------------------------------------------------------------
       
   685 // CAknIconServer::SetPreferredIconDisplayMode
       
   686 // -----------------------------------------------------------------------------
       
   687 //
       
   688 #ifdef _DEBUG
       
   689 void CAknIconServer::SetPreferredIconDisplayMode( TDisplayMode aMode )
       
   690     {
       
   691     iIconMode = aMode;
       
   692     }
       
   693 #else
       
   694 void CAknIconServer::SetPreferredIconDisplayMode( TDisplayMode /*aMode*/ )
       
   695     {
       
   696     }
       
   697 #endif
       
   698 
       
   699 // -----------------------------------------------------------------------------
       
   700 // CAknIconServer::GetInitData
       
   701 // -----------------------------------------------------------------------------
       
   702 //
       
   703 void CAknIconServer::GetInitData(
       
   704     TAknIconInitData& aData ) const
       
   705     {
       
   706     aData.iCompression = iCompression;
       
   707     aData.iIconMode = iIconMode;
       
   708     aData.iIconMaskMode = iIconMaskMode;
       
   709     aData.iPhotoMode = iPhotoMode;
       
   710     aData.iVideoMode = iVideoMode;
       
   711     aData.iOffscreenMode = iOffscreenMode;
       
   712     aData.iOffscreenMaskMode = iOffscreenMaskMode;
       
   713     }
       
   714 
       
   715 // -----------------------------------------------------------------------------
       
   716 // CAknIconServer::RetrieveIcon
       
   717 // -----------------------------------------------------------------------------
       
   718 //
       
   719 TInt CAknIconServer::RetrieveIcon( const TAknIconParams& aInfo )
       
   720     {
       
   721     // Can be constructed in stack with this constructor.
       
   722     CAknIconSrvIconItem compareItem( aInfo );
       
   723 
       
   724     return iIconItems.FindInOrder(
       
   725         &compareItem, CAknIconSrvIconItem::LinearOrder );
       
   726     }
       
   727 
       
   728 
       
   729 
       
   730 // -----------------------------------------------------------------------------
       
   731 // CAknIconServer::CreateIconL
       
   732 // -----------------------------------------------------------------------------
       
   733 //
       
   734 CAknIconSrvIconItem* CAknIconServer::CreateIconL(
       
   735     const TAknIconParams& aInfo )
       
   736     {
       
   737     CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
       
   738     CleanupStack::PushL( bitmap );
       
   739 
       
   740     CFbsBitmap* mask = NULL;
       
   741 
       
   742     if ( aInfo.iMaskId >= 0 )
       
   743         {
       
   744         mask = new (ELeave) CFbsBitmap;
       
   745         CleanupStack::PushL( mask );
       
   746         }
       
   747     MAknIconFormatHandler* handler = NULL;
       
   748     CAknIconLoader* loader = NULL;
       
   749 
       
   750     TInt handle;
       
   751 
       
   752     TDisplayMode bitmapDepth;    
       
   753 
       
   754     // Makes sure that the icon loader is released when required.
       
   755 
       
   756     CleanupStack::PushL( TCleanupItem( CleanupIconLoader, this ) );    
       
   757 
       
   758     TPtrC8 iconData = InitIconDataAndHandlerLC(aInfo, loader, handler);        
       
   759 
       
   760     bitmapDepth = (TDisplayMode)loader->IconDepthL( aInfo.iBitmapId );    
       
   761 
       
   762     handler->PrepareIconL( iconData, handle );
       
   763 
       
   764     // CleanupIconLoader, InitIconDataAndHandlerLC
       
   765     CleanupStack::PopAndDestroy( 2 ); 
       
   766 
       
   767     TAknContentDimensions dimensions;
       
   768 
       
   769     TRAPD( err,
       
   770         {
       
   771         handler->UsePreparedIconL( handle );
       
   772 
       
   773             dimensions = AknIconSrvUtils::RenderPreparedIconL(
       
   774 
       
   775                     *handler,
       
   776 
       
   777                     bitmap,
       
   778 
       
   779                     mask,
       
   780 
       
   781                     bitmapDepth,
       
   782 
       
   783                     iIconMode,
       
   784 
       
   785                     aInfo.iSize,
       
   786 
       
   787                     (TScaleMode)aInfo.iMode,
       
   788 
       
   789                     aInfo.iRotationAngle,
       
   790 
       
   791                     aInfo.iColor,
       
   792 
       
   793                     aInfo.iBitmapId,
       
   794 
       
   795                     aInfo.iMaskId,
       
   796 
       
   797                     aInfo.iAppIcon);
       
   798 
       
   799             } );
       
   800 
       
   801     
       
   802 
       
   803     // Below is the code to retrieve the actual rendering size of the icon as per normalizations done above in RenderPreparedIconL
       
   804 
       
   805     TSize iconSize(aInfo.iSize);
       
   806 
       
   807     if ( aInfo.iMode == EAspectRatioPreservedAndUnusedSpaceRemoved )
       
   808 
       
   809         {
       
   810 
       
   811         if ( iconSize.iWidth!=0 && iconSize.iHeight!=0 )
       
   812 
       
   813             {
       
   814 
       
   815             AknIconSrvUtils::GetAspectRatioPreservedSize( dimensions, iconSize );
       
   816 
       
   817             }
       
   818 
       
   819         }        
       
   820 
       
   821     
       
   822 
       
   823     handler->UnprepareIcon( handle );
       
   824 
       
   825     User::LeaveIfError( err );
       
   826 
       
   827     // Create item definition and insert in the array.
       
   828     CAknIconSrvIconItem* item = 
       
   829         CAknIconSrvIconItem::NewL( aInfo, bitmap, mask, dimensions, IconFileNameCache() );
       
   830 
       
   831     CleanupStack::Pop(); // bitmap
       
   832     if ( mask )
       
   833         {
       
   834         CleanupStack::Pop(); // mask
       
   835         }
       
   836 
       
   837     return item;
       
   838     }
       
   839 
       
   840 // -----------------------------------------------------------------------------
       
   841 // CAknIconServer::CreateMbmIconL
       
   842 // -----------------------------------------------------------------------------
       
   843 //
       
   844 CAknIconSrvIconItem* CAknIconServer::CreateMbmIconL( 
       
   845     const TAknIconParams& aInfo,
       
   846     const TAknIconSrvReturnData& aRetData )
       
   847     {
       
   848     // Create a new bitmap to be stretched to the given size.
       
   849     CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
       
   850     CleanupStack::PushL( bitmap );
       
   851 
       
   852     CFbsBitmap* loadedBitmap = new( ELeave ) CFbsBitmap;
       
   853     CleanupStack::PushL( loadedBitmap );
       
   854 
       
   855     // Duplicate the loaded bitmap in this thread.
       
   856     User::LeaveIfError( loadedBitmap->Duplicate( aRetData.iBitmapHandle ) );
       
   857 
       
   858     CFbsBitmap* mask = NULL;
       
   859     CFbsBitmap* loadedMask = NULL;
       
   860 
       
   861     if ( aInfo.iMaskId >= 0 )
       
   862         {
       
   863         // Create a new mask to be stretched to the given size.
       
   864         mask = new (ELeave) CFbsBitmap;
       
   865         CleanupStack::PushL( mask );
       
   866 
       
   867         loadedMask = new( ELeave ) CFbsBitmap;
       
   868         CleanupStack::PushL( loadedMask );
       
   869 
       
   870         User::LeaveIfError( loadedMask->Duplicate( aRetData.iMaskHandle ) );
       
   871         }
       
   872 
       
   873     // Perform scaling and color filling if required
       
   874     TBool colorIcon = AknIconSrvUtils::ScaleBitmapIconL(
       
   875         aInfo.iSize,
       
   876         (TScaleMode)aInfo.iMode,
       
   877         aInfo.iRotationAngle,
       
   878         aInfo.iColor,
       
   879         loadedBitmap,
       
   880         loadedMask,
       
   881         bitmap,
       
   882         mask );
       
   883 
       
   884     // Create item definition and insert in the array.
       
   885     // Content dimensions of bitmap icons are not stored in server side,
       
   886     // so use (-1,-1).
       
   887     CAknIconSrvIconItem* item = 
       
   888         CAknIconSrvIconItem::NewL( aInfo, 
       
   889                                    bitmap,
       
   890                                    mask,
       
   891                                    TAknContentDimensions( -1, -1 ),
       
   892                                    IconFileNameCache() );
       
   893 
       
   894     // Set information of the applied color.
       
   895     if ( colorIcon )
       
   896         {
       
   897         item->iColor = aInfo.iColor;
       
   898         }
       
   899 
       
   900     // Set info that this is an MBM icon. They are not cached the same
       
   901     // way SVG icons are.
       
   902     item->SetMbmIcon();
       
   903 
       
   904     CleanupStack::PopAndDestroy(); // loadedBitmap
       
   905     CleanupStack::Pop(); // bitmap
       
   906     if ( mask )
       
   907         {
       
   908         CleanupStack::PopAndDestroy(); // loadedMask
       
   909         CleanupStack::Pop(); // mask
       
   910         }
       
   911 
       
   912     return item;
       
   913     }
       
   914 
       
   915 // -----------------------------------------------------------------------------
       
   916 // CAknIconServer::ApplyIconColorL()
       
   917 // -----------------------------------------------------------------------------
       
   918 //
       
   919 void CAknIconServer::ApplyIconColorL(
       
   920     CAknIconSrvIconItem* aItem, const TRgb aColor )
       
   921     {
       
   922     // If a color is defined in given parameters,
       
   923     // create a new icon with that color, if not already done.
       
   924     if ( aColor != KColorNotDefined && 
       
   925          aColor != aItem->iColor )
       
   926         {
       
   927 #if 0        
       
   928         TSize size = aItem->iBitmap->SizeInPixels();
       
   929 
       
   930         CFbsBitmap* colorBitmap = new (ELeave) CFbsBitmap;
       
   931         CleanupStack::PushL( colorBitmap );
       
   932         User::LeaveIfError( colorBitmap->Create( size, EColor64K ) );
       
   933 
       
   934         CFbsBitmapDevice* dev = CFbsBitmapDevice::NewL( colorBitmap );
       
   935         CleanupStack::PushL( dev );
       
   936         CFbsBitGc* gc = NULL;
       
   937         User::LeaveIfError( dev->CreateContext( gc ) );
       
   938         CleanupStack::PushL( gc );
       
   939         
       
   940         gc->SetBrushColor( aColor );
       
   941         gc->SetPenStyle( CGraphicsContext::ENullPen );
       
   942         gc->SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   943         // Fill icon with the given color, mask defines the icon shape.
       
   944         gc->DrawRect( TRect( TPoint( 0, 0 ), size ) );
       
   945 
       
   946         CleanupStack::PopAndDestroy( 2 ); // dev, gc
       
   947 
       
   948         // Change color bitmap in item.
       
   949         delete aItem->iBitmap;
       
   950         aItem->iBitmap = colorBitmap;
       
   951         CleanupStack::Pop(); // colorBitmap
       
   952 
       
   953 #endif
       
   954         // Update information of the applied color in the item
       
   955         aItem->iColor = aColor;
       
   956         }
       
   957     }
       
   958     
       
   959 // -----------------------------------------------------------------------------
       
   960 // CAknIconServer::DeleteOrCacheUnusedIcon()
       
   961 //
       
   962 // Note: iCurrentIndex must be set to the index of aItem in array iIconItems
       
   963 //       before using this function.
       
   964 // -----------------------------------------------------------------------------
       
   965 //
       
   966 TBool CAknIconServer::DeleteOrCacheUnusedIcon(CAknIconSrvIconItem* aItem)
       
   967     {
       
   968 #ifdef __AKNICON_TRACES
       
   969     RDebug::Print( _L("AknIcon: %x CAknIconServer::DeleteOrCacheUnusedIcon: item=%x"), this, aItem);
       
   970 #endif       
       
   971     
       
   972     TBool ret = EFalse;
       
   973     if ( aItem->iUserCount == 0  && !aItem->IsPermanentlyCached() )
       
   974         {
       
   975         // Note, CacheUnusedIcon potentially changes iIconItems,
       
   976         // but it takes care of modifying iCurrentIndex accordingly.
       
   977         
       
   978         if ( aItem->IsExcludedFromCache() || // Do not cache if the icon is excluded from cache...
       
   979              aItem->IsMbmIcon() || // Do not cache bitmap icons...
       
   980              aItem->iRotationAngle != 0 || // Do not cache rotated icons...
       
   981              !iCache->CacheUnusedIcon( *aItem ) )
       
   982             {
       
   983             iIconItems.Remove( iCurrentIndex );
       
   984             delete aItem;
       
   985             ret = ETrue;
       
   986             }
       
   987         }
       
   988 #ifdef __AKNICON_TRACES
       
   989     RDebug::Print( _L("AknIcon: %x CAknIconServer::DeleteOrCacheUnusedIcon: item=%x, ret=%d"), this, aItem,ret);
       
   990 #endif       
       
   991         
       
   992     return ret;       
       
   993     }
       
   994 
       
   995 // -----------------------------------------------------------------------------
       
   996 // CAknIconServer::RetrieveFileHandleL()
       
   997 // -----------------------------------------------------------------------------
       
   998 //
       
   999 RFile& CAknIconServer::RetrieveFileHandleL()
       
  1000     {
       
  1001     CSession2* session = Message().Session();
       
  1002     return static_cast<CAknIconSrvSession*>( session )->AdoptedFileHandle(); 
       
  1003     }
       
  1004 
       
  1005 // -----------------------------------------------------------------------------
       
  1006 // CAknIconServer::ThreadStart()
       
  1007 // -----------------------------------------------------------------------------
       
  1008 
       
  1009 EXPORT_C TInt CAknIconServer::ThreadStart()
       
  1010     {
       
  1011     // Rename own thread
       
  1012 	User::RenameThread( KAknIconSrvName );
       
  1013 
       
  1014     CAknIconServer* server = NULL;
       
  1015 
       
  1016     CTrapCleanup* cleanup = CTrapCleanup::New();
       
  1017     CActiveScheduler* scheduler = new CAknIconSrvScheduler;
       
  1018 
       
  1019     TInt err = KErrNone;
       
  1020 
       
  1021     if ( cleanup && scheduler )
       
  1022         {
       
  1023         CActiveScheduler::Install( scheduler );
       
  1024         TRAP( err,
       
  1025             {
       
  1026             server = CAknIconServer::NewL(); // adds server in scheduler
       
  1027             } );
       
  1028         }
       
  1029     else
       
  1030         {
       
  1031         err = KErrNoMemory;
       
  1032         }
       
  1033 
       
  1034     if ( err != KErrNone )
       
  1035         {
       
  1036         delete cleanup;
       
  1037         delete scheduler;
       
  1038         }
       
  1039 
       
  1040     // signal that we've started
       
  1041     SignalClient();
       
  1042     
       
  1043     // start fielding requests from clients
       
  1044     if ( err == KErrNone )
       
  1045         {
       
  1046         CActiveScheduler::Start();
       
  1047 
       
  1048         // comes here if server gets shut down
       
  1049         delete scheduler;
       
  1050         delete cleanup;
       
  1051         delete server;
       
  1052         }
       
  1053 
       
  1054     // thread/process exit
       
  1055     return err;
       
  1056     }
       
  1057 
       
  1058 // -----------------------------------------------------------------------------
       
  1059 // CAknIconServer::InitIconLoaderL
       
  1060 // -----------------------------------------------------------------------------
       
  1061 //
       
  1062 CAknIconLoader* CAknIconServer::InitIconLoaderL(
       
  1063     const TDesC& aFileName, RFile* aFile )
       
  1064     {
       
  1065     CAknIconLoader* loader = NULL;
       
  1066 
       
  1067     if ( aFileName.CompareF( KAvkonIconFileName ) == 0 )
       
  1068         {
       
  1069         if ( !iAvkonIconLoader )
       
  1070             {
       
  1071             iAvkonIconLoader = CAknIconLoader::NewL( iFsSession, KAvkonIconFileName );
       
  1072 #ifdef _NGATESTING
       
  1073 
       
  1074             iAvkonIconLoader->SetIconTypeConfig(iConfigIconType, iNGADirectory);
       
  1075 
       
  1076 #endif
       
  1077             }
       
  1078         loader = iAvkonIconLoader;
       
  1079         }
       
  1080 
       
  1081     // If not Avkon icon file, check that we got the correct file open.
       
  1082     else if ( !iCurrentIconFile || iCurrentIconFile->CompareF( aFileName ) != 0 )
       
  1083         {
       
  1084         delete iCurrentIconFile;
       
  1085         iCurrentIconFile = NULL;
       
  1086 
       
  1087         delete iOtherIconLoader;
       
  1088         iOtherIconLoader = NULL;
       
  1089         
       
  1090         if ( aFile )
       
  1091             {
       
  1092             iOtherIconLoader = CAknIconLoader::NewL( *aFile );
       
  1093             }
       
  1094         else
       
  1095             {
       
  1096             iOtherIconLoader = CAknIconLoader::NewL( iFsSession, aFileName );
       
  1097             }
       
  1098 
       
  1099 #ifdef _NGATESTING
       
  1100 
       
  1101         iOtherIconLoader->SetIconTypeConfig(iConfigIconType, iNGADirectory);
       
  1102 
       
  1103 #endif
       
  1104         iCurrentIconFile = aFileName.AllocL();
       
  1105         loader = iOtherIconLoader;
       
  1106         }
       
  1107 
       
  1108     else
       
  1109         {
       
  1110         // Icon file loader exists.
       
  1111 
       
  1112         loader = iOtherIconLoader;
       
  1113         
       
  1114         // Re-open the file if it is not ROM based file
       
  1115         if (iCurrentIconFile->Left(KDriveLength).CompareF(KDriveZ))
       
  1116             {
       
  1117             if ( aFile )
       
  1118                 {
       
  1119                 loader->OpenFileL( *aFile );
       
  1120                 }
       
  1121             else
       
  1122                 {
       
  1123                 loader->OpenFileL( iFsSession, aFileName );
       
  1124                 }
       
  1125             }
       
  1126         }
       
  1127 
       
  1128     return loader;
       
  1129     }
       
  1130 
       
  1131 // -----------------------------------------------------------------------------
       
  1132 // CAknIconServer::IconLoaderUsed
       
  1133 // -----------------------------------------------------------------------------
       
  1134 //
       
  1135 void CAknIconServer::IconLoaderUsed()
       
  1136     {
       
  1137     // Close the file only if it is not ROM based file
       
  1138     if ( iOtherIconLoader && (!iCurrentIconFile ||
       
  1139          iCurrentIconFile->Left(KDriveLength).CompareF(KDriveZ)))
       
  1140         {
       
  1141         iOtherIconLoader->CloseFile();        
       
  1142         }
       
  1143     }   
       
  1144 
       
  1145 // -----------------------------------------------------------------------------
       
  1146 // CAknIconServer::CleanupIconLoader
       
  1147 // -----------------------------------------------------------------------------
       
  1148 //
       
  1149 void CAknIconServer::CleanupIconLoader( TAny* aServer )
       
  1150     {
       
  1151     static_cast<CAknIconServer*>( aServer )->IconLoaderUsed();
       
  1152     }
       
  1153 
       
  1154 // -----------------------------------------------------------------------------
       
  1155 // CAknIconServer::EnableCache
       
  1156 // -----------------------------------------------------------------------------
       
  1157 //
       
  1158 void CAknIconServer::EnableCache(TBool aEnable)
       
  1159 	{
       
  1160 #ifdef __AKNICON_TRACES
       
  1161     RDebug::Print( _L("AknIcon: %x CAknIconServer::EnableCache: %d"), this, aEnable);
       
  1162 #endif   
       
  1163 	
       
  1164     iCurrentIndex = -1;
       
  1165 	iCache->EnableCache(aEnable);
       
  1166 	}
       
  1167 
       
  1168 // -----------------------------------------------------------------------------
       
  1169 // CAknIconServer::InitIconDataAndHandlerLC
       
  1170 // -----------------------------------------------------------------------------
       
  1171 //
       
  1172 TPtrC8 CAknIconServer::InitIconDataAndHandlerLC(
       
  1173     const TAknIconParams& aParams,
       
  1174     CAknIconLoader*& aLoader,
       
  1175     MAknIconFormatHandler*& aHandler  )
       
  1176     {
       
  1177     TFileName filename;
       
  1178     if ( aParams.IsDefaultIconDirUsed() )
       
  1179         {
       
  1180         filename = KAknIconDefaultDir;
       
  1181         }
       
  1182 
       
  1183     filename.Append( aParams.iFileName );
       
  1184 
       
  1185     // Adopt file handle if supplied by client.    
       
  1186     RFile* filePtr = NULL;
       
  1187     RFile& file = RetrieveFileHandleL();
       
  1188     
       
  1189     if ( file.SubSessionHandle() )
       
  1190         {
       
  1191         filePtr = &file;
       
  1192         }
       
  1193     
       
  1194     aLoader = InitIconLoaderL( filename, filePtr );
       
  1195 
       
  1196     MAknIconFormatHandler* lHandler = NULL;
       
  1197     TPtrC8 iconData = AknIconSrvUtils::InitIconDataAndHandlerLC(
       
  1198         aLoader,
       
  1199         iHandlerList,
       
  1200         lHandler,
       
  1201             aParams,
       
  1202         EFalse );
       
  1203     aHandler = lHandler;
       
  1204     return iconData;
       
  1205     }
       
  1206 
       
  1207 
       
  1208 // -----------------------------------------------------------------------------
       
  1209 // ThreadFunction()
       
  1210 // Needed only in WINS build
       
  1211 // -----------------------------------------------------------------------------
       
  1212 
       
  1213 #if defined(__WINS__) && !defined(EKA2)
       
  1214 
       
  1215 GLDEF_C TInt ThreadFunction( TAny* /*aThreadParams*/ )
       
  1216     {
       
  1217     // increase dll's user count so it can't get unloaded when the client
       
  1218     // application terminates
       
  1219 
       
  1220     RLibrary lib;
       
  1221     lib.Load( KAknIconLibName );
       
  1222 
       
  1223     return CAknIconServer::ThreadStart();
       
  1224     }
       
  1225 
       
  1226 #endif
       
  1227 
       
  1228 // -----------------------------------------------------------------------------
       
  1229 // StartServer()
       
  1230 // Create the server thread/process
       
  1231 // -----------------------------------------------------------------------------
       
  1232 //
       
  1233 GLDEF_C TInt StartServer()
       
  1234     {
       
  1235     TInt ret = KErrNone;
       
  1236 
       
  1237     RSemaphore startupSemaphore;
       
  1238     ret = startupSemaphore.CreateGlobal( KAknIconServerStartupSemaphore, 0 );
       
  1239 
       
  1240     if ( ret == KErrAlreadyExists )
       
  1241         {
       
  1242         // The server is starting up, but has not yet started 
       
  1243         if ( startupSemaphore.OpenGlobal( KAknIconServerStartupSemaphore ) == 
       
  1244              KErrNone )
       
  1245             {
       
  1246             startupSemaphore.Wait(); // wait until the server has started up.
       
  1247             startupSemaphore.Close();
       
  1248             }
       
  1249 
       
  1250         // Return info to the client that the server was already started.
       
  1251         return ret;
       
  1252         }
       
  1253 
       
  1254     // launch server process
       
  1255     RProcess server;
       
  1256     ret = server.Create(
       
  1257         KAknIconSrvExe,
       
  1258         KNullDesC,
       
  1259         TUidType( KNullUid, KNullUid, KNullUid ),
       
  1260         EOwnerThread );
       
  1261 
       
  1262     if ( ret == KErrNone )
       
  1263         {        	    
       
  1264         server.Resume();
       
  1265         server.Close();
       
  1266 
       
  1267         startupSemaphore.Wait(); // wait until the server has started up.
       
  1268         }
       
  1269 
       
  1270     startupSemaphore.Close();
       
  1271     return ret;
       
  1272     }
       
  1273 
       
  1274 // -----------------------------------------------------------------------------
       
  1275 // SignalClient()
       
  1276 // -----------------------------------------------------------------------------
       
  1277 //
       
  1278 GLDEF_C void SignalClient()
       
  1279     {
       
  1280     RSemaphore startupSemaphore;
       
  1281     if ( startupSemaphore.OpenGlobal(
       
  1282          KAknIconServerStartupSemaphore ) == KErrNone )
       
  1283         {
       
  1284         //Signal the client:The server might have started up successfully or not
       
  1285         startupSemaphore.Signal();
       
  1286         startupSemaphore.Close();
       
  1287         }
       
  1288     else
       
  1289         {
       
  1290         // Something fundamentally wrong.
       
  1291         User::Invariant();
       
  1292         }
       
  1293     }
       
  1294 
       
  1295 	
       
  1296 
       
  1297 void CAknIconServer::ReCreateSvgL( TAknIconParams& aInfo, CAknIconSrvIconItem *& aItem)   	
       
  1298     {
       
  1299     
       
  1300     if ( !aItem )
       
  1301         {
       
  1302         return;
       
  1303         }
       
  1304     
       
  1305     CFbsBitmap* iBitmap = aItem->iBitmap;
       
  1306 	CFbsBitmap* iMask = NULL;
       
  1307 	if ( aItem->iMask )
       
  1308 	    {
       
  1309 	    iMask = aItem->iMask;
       
  1310 	    }
       
  1311 	TInt  validHeight;
       
  1312 	if(iMask != NULL)
       
  1313 		{
       
  1314 		SEpocBitmapHeader lBmpHeaderMask = iMask->Header();
       
  1315 		if ( lBmpHeaderMask.iBitsPerPixel != 8 ) 	
       
  1316 			{
       
  1317 			return;
       
  1318 		    }
       
  1319 		validHeight = AknIconSrvUtils::CheckMaskTransparencyL(iMask);
       
  1320 		}
       
  1321 	else
       
  1322 		{
       
  1323 		SEpocBitmapHeader lBmpHeaderBitmap = iBitmap->Header();
       
  1324 		if ( lBmpHeaderBitmap.iBitsPerPixel != 32 )
       
  1325 			{
       
  1326 			return;
       
  1327 			}
       
  1328 		validHeight = AknIconSrvUtils::CheckAlphaTransparencyL(iBitmap);
       
  1329 		}
       
  1330 	
       
  1331 	const TSize& size = iBitmap->SizeInPixels();
       
  1332 				
       
  1333 	if(validHeight == size.iHeight)
       
  1334 		return;
       
  1335 	
       
  1336 	const TInt KOffSet = 16;
       
  1337 	
       
  1338 	//scale image down, leaving margins on sides
       
  1339 	//then using fixed point math to get width
       
  1340 	const TInt hmul = (validHeight << KOffSet) / size.iHeight;
       
  1341 	const TInt validWidth =  (size.iWidth * hmul + (1 << (KOffSet - 1))) >> KOffSet;  // sz * mul + 0.5
       
  1342 	        
       
  1343     TSize lActual = aInfo.iSize;  // store the original size request by clien  
       
  1344 	const TSize sz(validHeight, validWidth);
       
  1345     aInfo.iSize = sz;    // valid size after doing transparency operations
       
  1346     
       
  1347  //   TRect rect(TPoint((size.iWidth - sz.iWidth) >> 1, 0), sz);
       
  1348     TRect rect(TPoint((size.iWidth - sz.iWidth) >> 1, (size.iHeight - sz.iHeight) >> 1), sz);
       
  1349 //	TRect rect(TPoint((size.iWidth - validWidth) >> 1, (size.iHeight - validHeight) >> 1), sz);
       
  1350 
       
  1351 	//it look better if even when centrified
       
  1352 	rect.iTl.iX &= ~1; 
       
  1353 	rect.iBr.iX |= 1;
       
  1354 	
       
  1355     CAknIconSrvIconItem *lItem = CreateIconL(aInfo); // recreate the svg bmp with valid size.
       
  1356     if ( !lItem )
       
  1357     	{
       
  1358     	return;
       
  1359     	}
       
  1360     CFbsBitmapDevice* dev = CFbsBitmapDevice::NewL(aItem->iBitmap);
       
  1361 	CleanupStack::PushL(dev);
       
  1362 	CFbsBitGc* con = NULL;
       
  1363 	dev->CreateContext(con);
       
  1364 	CleanupStack::PushL(con);
       
  1365 	con->SetBrushColor( 0 );
       
  1366 	con->Clear();
       
  1367 	con->SetPenStyle(CGraphicsContext::ESolidPen);
       
  1368 	con->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
  1369 	TUint32 lFillColor = 0xFF000000;
       
  1370 	con->SetPenColor(lFillColor);
       
  1371 	con->SetBrushColor(lFillColor);
       
  1372 	con->DrawRect(TRect(TPoint(0, 0), aItem->iBitmap->SizeInPixels()));
       
  1373 	con->BitBlt(rect.iTl, lItem->iBitmap);
       
  1374 	CleanupStack::PopAndDestroy(2);
       
  1375     
       
  1376     if ( lItem->iMask )
       
  1377     	{
       
  1378     	CFbsBitmapDevice* dev = CFbsBitmapDevice::NewL(aItem->iMask);
       
  1379 		CleanupStack::PushL(dev);
       
  1380 		CFbsBitGc* con = NULL;
       
  1381 		dev->CreateContext(con);
       
  1382 		CleanupStack::PushL(con);
       
  1383 		con->SetBrushColor( 0 );
       
  1384 		con->Clear();
       
  1385 		con->SetPenStyle(CGraphicsContext::ESolidPen);
       
  1386 		con->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
  1387 		lFillColor = lItem->iMask->DisplayMode() != EGray256 ? 0xFFFFFFFFF : 0x0;
       
  1388 		con->SetPenColor(lFillColor);
       
  1389 		con->SetBrushColor(lFillColor);			
       
  1390 		con->DrawRect(TRect(TPoint(0, 0), aItem->iMask->SizeInPixels()));
       
  1391 		con->BitBlt(rect.iTl, lItem->iMask);
       
  1392 		CleanupStack::PopAndDestroy(2);	
       
  1393     	}
       
  1394    
       
  1395     delete lItem;
       
  1396     lItem = NULL;
       
  1397     aItem->iSize = lActual; // store actual size requested by the client
       
  1398                                 // so that search can be done successfully.
       
  1399     }
       
  1400 
       
  1401 #ifdef _NGATESTING
       
  1402 
       
  1403 void CAknIconServer::LoadConfigurationL(RFs& aFs)
       
  1404     {
       
  1405     // if the icon type is svg, check if NGA enabled and set type as EIconFormatNGA
       
  1406 #ifdef __ONLYNGAICON
       
  1407     iConfigIconType = EIconFormatNGA;
       
  1408     (void)aFs;
       
  1409 #else
       
  1410     // check for the configuration files
       
  1411     _LIT(KICONTYPECONFIGFILE, "c:\\icontype.cfg"); // TODO: find appropriate place
       
  1412     /*
       
  1413      * sample configuration files is attached below
       
  1414      * 
       
  1415      * ICONTYPE=3
       
  1416      * NGAICONDIR=c:\Data\nvg_mif
       
  1417      */
       
  1418     RFile   lFile;
       
  1419     
       
  1420     if (lFile.Open(aFs, KICONTYPECONFIGFILE , EFileRead) == KErrNone)
       
  1421         {
       
  1422         CleanupClosePushL(lFile);
       
  1423         TInt sekpoint = 0;
       
  1424         lFile.Seek( ESeekStart, sekpoint );
       
  1425         TInt fileSize = 0;
       
  1426         User::LeaveIfError(lFile.Size( fileSize ));
       
  1427         
       
  1428         HBufC8 * lConfigData = HBufC8::NewLC( fileSize );
       
  1429         
       
  1430         TPtr8 lptr = lConfigData->Des();
       
  1431         lFile.Read(lptr, fileSize);
       
  1432         
       
  1433         TLex8 lLexObj(lptr);
       
  1434         lLexObj.SkipSpaceAndMark();
       
  1435         
       
  1436         TChar aChar;
       
  1437         
       
  1438         do
       
  1439             {
       
  1440             aChar = lLexObj.Get();
       
  1441             }
       
  1442         while ( aChar != '\n' &&
       
  1443                 aChar != ' '  &&
       
  1444                 aChar != '\r' &&
       
  1445                 aChar != '\t' &&
       
  1446                 aChar != '=');
       
  1447         
       
  1448         lLexObj.UnGet();
       
  1449         TPtrC8 kw1 = lLexObj.MarkedToken();
       
  1450         lLexObj.SkipSpace();
       
  1451         if (lLexObj.Get() != '=')
       
  1452             {
       
  1453             User::Leave(KErrCorrupt);
       
  1454             }
       
  1455         
       
  1456         lLexObj.SkipSpace();
       
  1457         lLexObj.Val(iConfigIconType);
       
  1458         
       
  1459         lLexObj.SkipSpaceAndMark();
       
  1460         do
       
  1461             {
       
  1462             aChar = lLexObj.Get();
       
  1463             }
       
  1464         while ( aChar != '\n' &&
       
  1465                 aChar != ' '  &&
       
  1466                 aChar != '\r' &&
       
  1467                 aChar != '\t' &&
       
  1468                 aChar != '=');
       
  1469         
       
  1470         lLexObj.UnGet();
       
  1471         TPtrC8 kw2 = lLexObj.MarkedToken();
       
  1472         lLexObj.SkipSpace();
       
  1473         if (lLexObj.Get() != '=')
       
  1474             {
       
  1475             User::Leave(KErrCorrupt);
       
  1476             }
       
  1477         lLexObj.SkipSpace();
       
  1478         
       
  1479         iNGADirectory.Copy(lLexObj.NextToken());
       
  1480         CleanupStack::PopAndDestroy();
       
  1481         CleanupStack::PopAndDestroy();
       
  1482         }
       
  1483     else
       
  1484         {
       
  1485         iConfigIconType = EIconFormatNGA;
       
  1486         }
       
  1487 #endif
       
  1488     }
       
  1489 #endif