os/graphics/fbs/fontandbitmapserver/sfbs/FBSTOP.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/fbs/fontandbitmapserver/sfbs/FBSTOP.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,745 @@
     1.4 +// Copyright (c) 1995-2010 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include <hal.h>
    1.20 +#include <gdi.h>
    1.21 +#include <fntstore.h>
    1.22 +#include <bitmap.h>
    1.23 +#include <ecom/ecom.h>
    1.24 +#include <graphics/bitmapuid.h>
    1.25 +#include "SERVER.H"
    1.26 +#include "BackGroundCompression.h"
    1.27 +#include "BitwiseBitmap.inl"
    1.28 +#include "bitmapconst.h"
    1.29 +#include <graphics/openfontconstants.h>
    1.30 +#include <graphics/openfontrasterizer.h>
    1.31 +#include <graphics/gdi/glyphsample.h>
    1.32 +#include "glyphatlas.h"
    1.33 +#include "FbsMessage.H"
    1.34 +
    1.35 +// Local utility functions
    1.36 +void ListImplementationsWithRetry(TUid& aInterfaceUid, RImplInfoPtrArray &aImplementationArray, TBool aRomOnly);
    1.37 +
    1.38 +
    1.39 +CFbTop::CFbTop():
    1.40 +	iDefaultLanguageForMetrics(ELangNone)
    1.41 +	{
    1.42 +	}
    1.43 +
    1.44 +CFbTop::~CFbTop()
    1.45 +	{
    1.46 +	if (iConIx)
    1.47 +		{
    1.48 +		iConIx->Remove(iBitmapCon);
    1.49 +		iConIx->Remove(iFontCon);
    1.50 +		}
    1.51 +	// there are no bitmap objects left, so the background compression queue must be empty
    1.52 +	delete iBackgroundCompression;
    1.53 +	delete iMBMCache;
    1.54 +	delete iFontStore;
    1.55 +	iFilesys.Close();
    1.56 +	iHeap->Check();
    1.57 +	__RHEAP_MARKEND(iHeap);
    1.58 +	delete iPile;
    1.59 +	iHeap->Close();
    1.60 +	iChunk.Close();
    1.61 +	iLargeBitmapChunk.Close();
    1.62 +	delete iConIx;
    1.63 +#ifdef SYMBIAN_DEBUG_FBS_LOCKHEAP
    1.64 +	iDebugMutex.Close();
    1.65 +#endif
    1.66 +	iFontNameAlias.ResetAndDestroy();
    1.67 +	iBitmapObjectIndex.Reset();
    1.68 +	delete iGlyphAtlas;
    1.69 +	REComSession::FinalClose();
    1.70 +	}
    1.71 +
    1.72 +CFbTop* CFbTop::NewL()
    1.73 +	{
    1.74 +	CFbTop* pT=new(ELeave) CFbTop;
    1.75 +	CleanupStack::PushL(pT);
    1.76 +	pT->ConstructL();
    1.77 +	CleanupStack::Pop();
    1.78 +	return(pT);
    1.79 +	}
    1.80 +
    1.81 +void CFbTop::ConstructL()
    1.82 +	{
    1.83 +	TInt maxmem = 0;
    1.84 +	HAL::Get(HALData::EMemoryRAM, maxmem);
    1.85 +	ASSERT(maxmem > 0);
    1.86 +	TInt maxHeapSize = Min(maxmem, KFbServSharedHeapMaxSize);
    1.87 +	
    1.88 +	TChunkHeapCreateInfo sharedHeapCreateInfo(KFBSERVInitialHeapSize, maxHeapSize);
    1.89 +	sharedHeapCreateInfo.SetCreateChunk(&KFBSERVSharedChunkName);
    1.90 +	sharedHeapCreateInfo.SetSingleThread(EFalse);
    1.91 +	sharedHeapCreateInfo.SetAlignment(0);
    1.92 +	sharedHeapCreateInfo.SetGrowBy(KMinHeapGrowBy * KFBSERVHeapGrowByMultiplier);
    1.93 +
    1.94 +	if(KFbServWritableDataPagingMode == EFbsWdpPageBitmapDataAndSharedHeapChunksOnly)
    1.95 +		{
    1.96 +		//Request that the shared heap chunk is paged.
    1.97 +		sharedHeapCreateInfo.SetPaging(TChunkHeapCreateInfo::EPaged);
    1.98 +		}
    1.99 +	else
   1.100 +		{
   1.101 +		//Use the creating process's paging attributes.
   1.102 +		sharedHeapCreateInfo.SetPaging(TChunkHeapCreateInfo::EUnspecified);
   1.103 +		}
   1.104 +
   1.105 +	iHeap = UserHeap::ChunkHeap(sharedHeapCreateInfo);
   1.106 +	
   1.107 +	User::LeaveIfError(iChunk.OpenGlobal(KFBSERVSharedChunkName,ETrue));
   1.108 +	TInt virtualSize = CChunkPile::VirtualSize();
   1.109 +	
   1.110 +	TChunkCreateInfo createInfo;
   1.111 +	createInfo.SetDisconnected(0, 0, virtualSize);
   1.112 +	createInfo.SetGlobal(KFBSERVLargeChunkName);
   1.113 +	createInfo.SetOwner(EOwnerProcess);
   1.114 +	createInfo.SetClearByte(0xff); // clear to white on creation
   1.115 +
   1.116 +	if(KFbServWritableDataPagingMode == EFbsWdpPageBitmapDataChunkOnly || 
   1.117 +		KFbServWritableDataPagingMode == EFbsWdpPageBitmapDataAndSharedHeapChunksOnly)
   1.118 +		{
   1.119 +		//Request that large bitmap chunk is paged.
   1.120 +		createInfo.SetPaging(TChunkCreateInfo::EPaged);
   1.121 +		}
   1.122 +	else
   1.123 +		{
   1.124 +		//Use the creating process's paging attributes.
   1.125 +		createInfo.SetPaging(TChunkCreateInfo::EUnspecified);
   1.126 +		}
   1.127 +
   1.128 +	User::LeaveIfError(iLargeBitmapChunk.Create(createInfo));
   1.129 +	__RHEAP_MARK(iHeap);
   1.130 +	iConIx=CObjectConIx::NewL();
   1.131 +	iBitmapCon=iConIx->CreateL();
   1.132 +	iFontCon=iConIx->CreateL();
   1.133 +	User::LeaveIfError(iFilesys.Connect());
   1.134 +#ifdef SYMBIAN_DEBUG_FBS_LOCKHEAP
   1.135 +	User::LeaveIfError(iDebugMutex.CreateGlobal(KFBSERVDebugMutexName));
   1.136 +#endif
   1.137 +	iPile = CChunkPile::NewL(iLargeBitmapChunk);
   1.138 +	iFontStore=CFontStore::NewL(iHeap);
   1.139 +	//Constructing a cache to store the stream ids of the bitmaps from a mbm file.
   1.140 +	//The cache here will store maximum 30 bitmaps before  & maximum 30 after the 
   1.141 +	//current loaded bitmap.These values are chosen as to optimize the boottime performance
   1.142 +	//as we notice during the boottime logs,sequential loading of bitmaps never exceed 30 bitmaps.
   1.143 +	// The cache will also store maximum 5 mbm files. This number must be as low as possible
   1.144 +	// while trying to minimize flushing of the cache due to mbm file switching.
   1.145 +	iMBMCache=new (ELeave) CFbTopStreamIdCache(30,30,5);
   1.146 +
   1.147 +	LoadOpenFontLibraries();
   1.148 +	iFontStore->LoadFontsAtStartupL();
   1.149 +	LoadShaperFactories();
   1.150 +	TRAP_IGNORE(iGlyphAtlas = CGlyphAtlas::NewL(KFbServGlyphAtlasCacheLimit);)
   1.151 +#ifdef _DEBUG
   1.152 +	if (!iGlyphAtlas)
   1.153 +	    {
   1.154 +        RDebug::Printf("FBSERV failed to initialize Glyph Atlas");
   1.155 +	    }
   1.156 +#endif
   1.157 +
   1.158 +	// start a new thread for background compression after all the other objects have been created
   1.159 +	iBackgroundCompression = CFbsBackgroundCompression::NewL(*this);
   1.160 +	}
   1.161 +
   1.162 +
   1.163 +
   1.164 +
   1.165 +/*
   1.166 +Load all ECOM implemented rasterizer DLLs.
   1.167 +*/
   1.168 +
   1.169 +void CFbTop::LoadOpenFontLibraries()
   1.170 +	{
   1.171 +	RImplInfoPtrArray implementationArray;
   1.172 +	TUid uid = {KUidOpenFontRasterizerPlunginInterface};
   1.173 +
   1.174 +	// get implementation list
   1.175 +	ListImplementationsWithRetry(uid, implementationArray, EFalse);
   1.176 +
   1.177 +	const TInt availCount = implementationArray.Count();
   1.178 +	for (TInt count=0; count < availCount; ++count)
   1.179 +		{
   1.180 +		const CImplementationInformation* info = implementationArray[count];
   1.181 +		// Create & install a rasterizer
   1.182 +		// ignore Leaves, as any necessary cleanup will have already been done through the cleanup stack
   1.183 +		TRAP_IGNORE(SafeInstallOfRasterizerL(info->ImplementationUid()));
   1.184 +		}
   1.185 +	
   1.186 +	// free memory
   1.187 +	implementationArray.ResetAndDestroy();
   1.188 +	}
   1.189 +
   1.190 +
   1.191 +/*
   1.192 +Load all ECOM implemented shaper factory DLLs.
   1.193 +*/	
   1.194 +void CFbTop::LoadShaperFactories()
   1.195 +	{
   1.196 +	RImplInfoPtrArray implementationArray;
   1.197 +	TUid uid = {KUidShaperFactoryPlunginInterface};
   1.198 +
   1.199 +	// get implementation list
   1.200 +	ListImplementationsWithRetry(uid, implementationArray, ETrue);
   1.201 +
   1.202 +	const TInt availCount = implementationArray.Count();
   1.203 +	for (TInt count=0;count<availCount;++count)
   1.204 +		{
   1.205 +		const CImplementationInformation* info = implementationArray[count];
   1.206 +		// Create & install a shaper factory
   1.207 +		// ignore Leaves, as any necessary cleanup will have already been done through the cleanup stack
   1.208 +		TRAP_IGNORE(SafeInstallOfShaperFactoryL(info->ImplementationUid()));
   1.209 +		}
   1.210 +
   1.211 +	// free memory
   1.212 +	implementationArray.ResetAndDestroy();
   1.213 +	}
   1.214 +
   1.215 +
   1.216 +void ListImplementationsWithRetry(TUid& aInterfaceUid, RImplInfoPtrArray &aImplementationArray, TBool aRomOnly)
   1.217 +	{
   1.218 +	// Making sure that no race situation arises between FBserv and Ecom
   1.219 +	// If ECom is not ready, give it another chance and try again. if it still doesn't work 
   1.220 +	// after the third try, then it just carries on quietly and fails... 
   1.221 +	for (TInt ecomnotready =0; ecomnotready <3; ecomnotready++)
   1.222 +		{
   1.223 +		TInt ecomError = KErrNone;
   1.224 +		if (aRomOnly)
   1.225 +			{
   1.226 +			TEComResolverParams resParams;
   1.227 +			TRAP(ecomError, REComSession::ListImplementationsL(aInterfaceUid, resParams, KRomOnlyResolverUid, aImplementationArray));
   1.228 +			}
   1.229 +		else
   1.230 +			{ // default resolver
   1.231 +			TRAP(ecomError, REComSession::ListImplementationsL(aInterfaceUid, aImplementationArray));
   1.232 +			}
   1.233 +
   1.234 +		if (!ecomError)
   1.235 +			{
   1.236 +			return;
   1.237 +			}
   1.238 +		else
   1.239 +			{
   1.240 +			User::After(0);
   1.241 +			}
   1.242 +		}
   1.243 +	}
   1.244 +
   1.245 +// utility methods to transfer ownership, or destroy object on failure
   1.246 +void CFbTop::SafeInstallOfRasterizerL(TUid aInterfaceImplUid)
   1.247 +	{
   1.248 +	COpenFontRasterizer* rasterizer = COpenFontRasterizer::NewL(aInterfaceImplUid);
   1.249 +	CleanupStack::PushL(rasterizer);
   1.250 +	// Install it in the font store.
   1.251 +	iFontStore->InstallRasterizerL(rasterizer);
   1.252 +	CleanupStack::Pop(rasterizer);
   1.253 +	}
   1.254 +
   1.255 +
   1.256 +void CFbTop::SafeInstallOfShaperFactoryL(TUid aInterfaceImplUid)
   1.257 +	{
   1.258 +	CShaperFactory* shaperFactory = CShaperFactory::NewL(aInterfaceImplUid);
   1.259 +	CleanupStack::PushL(shaperFactory);
   1.260 +	// Install it in the font store.
   1.261 +	iFontStore->InstallShaperFactoryL(shaperFactory);
   1.262 +	CleanupStack::Pop(shaperFactory);
   1.263 +	}
   1.264 +
   1.265 +/**
   1.266 +Gets the nearest matching font for a given font specification. If the named font cannot be found 
   1.267 +font aliases are checked. 
   1.268 +
   1.269 +@param aFontObjPtr On success this contains the font object that is the closest match.
   1.270 +@param aMessage The font request message.
   1.271 +@param aFontSpec The font spec to match.
   1.272 +@param aMaxHeight The maximum height of the font to match.
   1.273 +@return KErrNone if successful, KErrNotFound if the font is not found, or one of the other System Error codes.
   1.274 + */
   1.275 +TInt CFbTop::GetNearestFont(
   1.276 +	CFontObject*&		aFontObjPtr,
   1.277 +	TFbsMessage			aMessage,
   1.278 +	const TFontSpec&	aFontSpec,
   1.279 +	TInt				aMaxHeight)
   1.280 +	{
   1.281 +#ifdef _DEBUG
   1.282 +	User::Heap().Check();
   1.283 +	iHeap->Check();
   1.284 +#endif
   1.285 +	aFontObjPtr = NULL;
   1.286 +
   1.287 +	TFontSpec fontSpec(aFontSpec);
   1.288 +
   1.289 +	// Check if the font typeface is empty and if so use the system default font if it is set
   1.290 +	if (fontSpec.iTypeface.iName.Length() == 0 && iSystemDefaultFontTypefaceName.Length() != 0)
   1.291 +		{
   1.292 +		fontSpec.iTypeface.iName = iSystemDefaultFontTypefaceName;
   1.293 +		}
   1.294 +
   1.295 +	if (GlyphSample::EScriptDefault == fontSpec.ScriptTypeForMetrics())
   1.296 +		{
   1.297 +		fontSpec.SetScriptTypeForMetrics(iDefaultLanguageForMetrics);
   1.298 +		}
   1.299 +
   1.300 +	// Find the requested font
   1.301 +	TBool familyNameExistsInTypefaceStore = iFontStore->HaveTypefaceFamilyName(fontSpec.iTypeface.iName);
   1.302 +	
   1.303 +	// If the font is not found try finding an alias font
   1.304 +	if (!familyNameExistsInTypefaceStore) 
   1.305 +		{
   1.306 +		TInt aliasIndex = FindFontNameAlias(fontSpec.iTypeface.iName);
   1.307 +		//KErrNotFound is the only error which can be returned
   1.308 +		if (aliasIndex != KErrNotFound)
   1.309 +			{
   1.310 +			fontSpec.iTypeface.iName = *iFontNameAlias[aliasIndex + 1];
   1.311 +			}
   1.312 +		}
   1.313 +
   1.314 +	CFont* font = NULL;
   1.315 +	TInt ret = GetNearestNonAliasedFont(font, aMessage, fontSpec, aMaxHeight);
   1.316 +
   1.317 +	if (ret != KErrNone)
   1.318 +		{
   1.319 +		return ret;
   1.320 +		}
   1.321 +	
   1.322 +	return GetFontObjectFromFont(aFontObjPtr, font);
   1.323 +	}
   1.324 +	
   1.325 +/**
   1.326 +Gets the nearest matching loaded font for a given font specification.
   1.327 +
   1.328 +@param aFont On success this contains the font object that is the closest match.
   1.329 +@param aMessage The font request message.
   1.330 +@param aFontSpec The font spec to match.
   1.331 +@param aMaxHeight The maximum height of the font to match.
   1.332 +@return KErrNone if successful, KErrNotFound if the font is not found, or one of the other System Error codes.
   1.333 +*/
   1.334 +TInt CFbTop::GetNearestNonAliasedFont(CFont*& aFont, TFbsMessage aMessage, const TFontSpec&	aFontSpec, TInt	aMaxHeight)
   1.335 +	{
   1.336 +	TInt ret = KErrNotSupported;
   1.337 +	switch (aMessage)
   1.338 +		{
   1.339 +		case EFbsMessGetNearestFontToDesignHeightInTwips:
   1.340 +			{
   1.341 +			ret = iFontStore->GetNearestFontToDesignHeightInTwips(aFont, aFontSpec);
   1.342 +			break;
   1.343 +			}
   1.344 +		case EFbsMessGetNearestFontToDesignHeightInPixels:
   1.345 +			{
   1.346 +			ret = iFontStore->GetNearestFontToDesignHeightInPixels(aFont, aFontSpec);
   1.347 +			break;
   1.348 +			}
   1.349 +		case EFbsMessGetNearestFontToMaxHeightInTwips:
   1.350 +			{
   1.351 +			ret = iFontStore->GetNearestFontToMaxHeightInTwips(aFont, aFontSpec, aMaxHeight);
   1.352 +			break;
   1.353 +			}
   1.354 +		case EFbsMessGetNearestFontToMaxHeightInPixels:
   1.355 +			{
   1.356 +			ret = iFontStore->GetNearestFontToMaxHeightInPixels(aFont, aFontSpec, aMaxHeight);
   1.357 +			break;
   1.358 +			}
   1.359 +		}
   1.360 +	return ret;
   1.361 +	}
   1.362 +
   1.363 +TInt CFbTop::GetFontObjectFromFont(CFontObject*& aFontObjPtr, CFont* aFont)
   1.364 +	{
   1.365 +	// First, check if a CFontObject exists for this CFont.
   1.366 +	// If so, increment its reference count and return it.
   1.367 +	for (TInt ii = iFontCon->Count() - 1; ii >= 0; --ii)
   1.368 +		{
   1.369 +		CFontObject* fontObjPtr = reinterpret_cast<CFontObject*>((*iFontCon)[ii]);
   1.370 +		if (fontObjPtr->iAddressPointer == reinterpret_cast<CBitmapFont*>(aFont))
   1.371 +			{
   1.372 +			aFontObjPtr = fontObjPtr;
   1.373 +			// The CFontObject instance keeps the reference count of the CBitmapFont, 
   1.374 +			// not the font store. There is only one CFontObject instance
   1.375 +			// per CBitmapFont, so to keep the reference count at 1 in the fontstore
   1.376 +			// call ReleaseFont(). 
   1.377 +			iFontStore->ReleaseFont(aFont);
   1.378 +			return fontObjPtr->Open();
   1.379 +			}
   1.380 +		}
   1.381 +	
   1.382 +	// Existing FontObject not found, so create new one.
   1.383 +	CFontObject* fontObjPtr = new CFontObject(iFontStore, iGlyphAtlas);
   1.384 +	if (!fontObjPtr)
   1.385 +		{
   1.386 +		iFontStore->ReleaseFont(aFont);
   1.387 +		return KErrNoMemory;
   1.388 +		}
   1.389 +	
   1.390 +	fontObjPtr->iAddressPointer = reinterpret_cast<CBitmapFont*>(aFont);
   1.391 +	fontObjPtr->iHeightInTwips = ((aFont->HeightInPixels() * iFontStore->iKPixelHeightInTwips) + 667) / 1000;
   1.392 +	TRAPD(ret, iFontCon->AddL(fontObjPtr));
   1.393 +	if (ret != KErrNone)
   1.394 +		{
   1.395 +		fontObjPtr->Close();
   1.396 +		}
   1.397 +	else
   1.398 +		{ // transfer ownership
   1.399 +		aFontObjPtr = fontObjPtr;
   1.400 +		}
   1.401 +	return ret;
   1.402 +	}
   1.403 +
   1.404 +
   1.405 +/** Create a Bitmap Font, from a UID and Algorithmic drawing Style see CFontStore::GetFontById()
   1.406 +@internalComponent
   1.407 +*/
   1.408 +TInt CFbTop::GetFontById(CFontObject*& aFontObjPtr,TUid aUid,const TAlgStyle& aAlgStyle)
   1.409 +	{
   1.410 +#ifdef _DEBUG
   1.411 +	User::Heap().Check();
   1.412 +	iHeap->Check();
   1.413 +#endif
   1.414 +	aFontObjPtr=NULL;
   1.415 +	CBitmapFont* font=NULL;
   1.416 +	TInt ret=iFontStore->GetFontById((CFont*&)font,aUid,(TAlgStyle&)aAlgStyle);
   1.417 +	if (ret != KErrNone)
   1.418 +		{
   1.419 +		return ret;
   1.420 +		}
   1.421 +	return GetFontObjectFromFont(aFontObjPtr, font);
   1.422 +	}
   1.423 +
   1.424 +
   1.425 +/** Create a bitmap with the given size, display mode and UID.
   1.426 +
   1.427 +@param aSize Size of the bitmap in pixels.
   1.428 +@param aDispMode Display mode of the bitmap.
   1.429 +@param aUid The UID to use for bitmap creation. This can be:
   1.430 +	- KUidCFbsBitmapCreation for standard bitmaps.
   1.431 +	- The application UID for hardware bitmaps.
   1.432 +	- The data type UID for extended bitmaps.
   1.433 +@param aReplacement If ETrue the bitmap is being created as a replacement
   1.434 +	for a bitmap being made dirty by a resize or compress operation.
   1.435 +@param aDataSize If different from zero, it indicates that the bitmap to create
   1.436 +	is an extended bitmap and specifies the size in bytes of the bitmap.
   1.437 +	If equal to zero, it indicates that the bitmap to create is a standard
   1.438 +	bitmap or a hardware bitmap, depending on the value of aUid, and the size
   1.439 +	in bytes is calculated from the size in pixels and the display mode.
   1.440 +@internalComponent
   1.441 +*/
   1.442 +CBitmapObject* CFbTop::CreateBitmapL(const TSize& aSize, TDisplayMode aDispMode, TUid aUid, TBool aReplacement, TInt aDataSize)
   1.443 +	{
   1.444 +#ifdef _DEBUG
   1.445 +	User::Heap().Check();
   1.446 +	iHeap->Check();
   1.447 +#endif
   1.448 +	CBitwiseBitmap* bmp=(CBitwiseBitmap*)iHeap->AllocL(sizeof(CBitwiseBitmap) + sizeof(CBitwiseBitmap::TExtra));
   1.449 +	new(bmp) CBitwiseBitmap(iHeap,iPile);
   1.450 +	CleanupDeletePushL(bmp);  // CBitwiseBitmap is not derived from CBase!
   1.451 +
   1.452 +	if (aDataSize == 0)
   1.453 +		User::LeaveIfError(bmp->Construct(aSize, aDispMode, aUid));
   1.454 +	else
   1.455 +		User::LeaveIfError(bmp->ConstructExtended(aSize, aDispMode, aUid, aDataSize));
   1.456 +	// bmp popped out of the clean-up stack by NewL
   1.457 +	CBitmapObject* bmpObj = CBitmapObject::NewL(*this, bmp, aReplacement);
   1.458 +	if (!aReplacement)
   1.459 +		{
   1.460 +		bmp->Extra()->iSerialNumber = iNextAvailableSerialNumber++;
   1.461 +		}
   1.462 +
   1.463 +	return bmpObj;
   1.464 +	}
   1.465 +
   1.466 +CBitmapObject* CFbTop::LoadBitmapL(const TDesC& aFilename, TInt32 aId, TUint aFileOffset, RFile* aFile, TInt aSessionHandle)
   1.467 +	{
   1.468 +	CBitwiseBitmap* bmp=DoLoadBitmapLC(aFilename, aId, aFileOffset, aFile, aSessionHandle);
   1.469 +	// bmp popped out of the clean-up stack by NewL
   1.470 +	CBitmapObject* bmpObj = CBitmapObject::NewL(*this, bmp, EFalse);
   1.471 +
   1.472 +	return bmpObj;
   1.473 +	}
   1.474 +
   1.475 +_LIT(KZDrive, "z:");
   1.476 +
   1.477 +CBitwiseBitmap* CFbTop::DoLoadBitmapLC(const TDesC& aFilename, TInt32 aId, TUint aFileOffset, RFile* aFile, TInt aSessionHandle)
   1.478 +	{
   1.479 +#ifdef _DEBUG
   1.480 +	User::Heap().Check();
   1.481 +	iHeap->Check();
   1.482 +#endif
   1.483 +	CBitwiseBitmap* bmp=(CBitwiseBitmap*)iHeap->AllocL(sizeof(CBitwiseBitmap) + sizeof(CBitwiseBitmap::TExtra));
   1.484 +	new(bmp) CBitwiseBitmap(iHeap,iPile);
   1.485 +	bmp->Extra()->iSerialNumber = iNextAvailableSerialNumber++;
   1.486 +	CleanupDeletePushL(bmp);  // CBitwiseBitmap is not derived from CBase!
   1.487 +
   1.488 +	if (NULL == aFile)
   1.489 +		{
   1.490 +		// In this case file should be in z: drive
   1.491 +		// so load the bitmap from the mbm cache
   1.492 +		TStreamId streamid(0);
   1.493 +		streamid=iMBMCache->GetStreamIdL(iFilesys,aFilename,aId,aFileOffset,aSessionHandle);
   1.494 +		bmp->ConstructL(iMBMCache->MruFileStore(),streamid);
   1.495 +		}
   1.496 +	else
   1.497 +		{
   1.498 +		//only use the cache when it is Rom File which is read only because when using
   1.499 +		//the cache the file store is always opened as read access until it is replaced by
   1.500 +		//another different file, Trying to write it(RAM file) will cause access violation
   1.501 +		//and therefore we have to split the implementation into two parts one for ROM
   1.502 +		//and one for RAM
   1.503 +		if (aFilename.Left(2).CompareF(KZDrive))
   1.504 +			{
   1.505 +			// File is not in ROFS
   1.506 +			bmp->ConstructL(*aFile,aId,aFileOffset);
   1.507 +			}
   1.508 +		else
   1.509 +			{
   1.510 +			// File is in ROFS
   1.511 +			TStreamId streamid(0);
   1.512 +			streamid=iMBMCache->GetStreamIdL(*aFile,aFilename,aId,aFileOffset,aSessionHandle);
   1.513 +
   1.514 +			bmp->ConstructL(iMBMCache->MruFileStore(),streamid);
   1.515 +			}
   1.516 +		}
   1.517 +	return bmp;
   1.518 +	}
   1.519 +
   1.520 +
   1.521 +/* Similar to LoadBitmap.
   1.522 +This function only performs a load the first time it is called for a
   1.523 +particular bitmap.  Subsequent calls increment a reference counting object.
   1.524 +
   1.525 +Upon return, aBmpObjPtr points to an object containing a pointer to the loaded bitmap.
   1.526 +*/
   1.527 +CSharedBitmapObject* CFbTop::ShareBitmapL(TDes& aFilename, TInt32 aId, TUint aFileOffset, RFile* aFile, TInt aSessionHandle)
   1.528 +	{
   1.529 +	TTime modtime(0);
   1.530 +	if (aFilename.Left(2).CompareF(KZDrive))// instead of Compare, CompareF is used to perform folding prior to Compare which is safe with Unicode.
   1.531 +		{
   1.532 +		// file is not in z: drive so it should not be null.
   1.533 +		__ASSERT_DEBUG(aFile != NULL, User::Panic(KFBSERVPanicCategory, KErrBadHandle));
   1.534 +		// File is not in ROM so ModTime is needed to identify it
   1.535 +		User::LeaveIfError(aFile->Modified(modtime));
   1.536 +		}
   1.537 +
   1.538 +	// Creation of the key is performed here so that it can potentially be
   1.539 +	// reused in both object lookup and object creation
   1.540 +	HBufC* key = CSharedBitmapObject::KeyLC(aFilename, aId, modtime);
   1.541 +
   1.542 +	// Calculation of the hash value is performed here so that it can 
   1.543 +	// potentially be reused in both object lookup and object insert.
   1.544 +	const TUint hash = iSharedBitmapObjectHashMap.Hash(*key);    
   1.545 +
   1.546 +	CSharedBitmapObject* bmpObj = iSharedBitmapObjectHashMap.Lookup(*key, hash);
   1.547 +	
   1.548 +	if (bmpObj)
   1.549 +		{
   1.550 +		// Bitmap already in memory
   1.551 +		CleanupStack::PopAndDestroy(key);      // key will not be needed
   1.552 +		User::LeaveIfError(bmpObj->Open());    // increase reference count
   1.553 +		}
   1.554 +	else
   1.555 +		{
   1.556 +		// Bitmap not in memory
   1.557 +		CBitwiseBitmap* bmp = DoLoadBitmapLC(aFilename, aId, aFileOffset, aFile, aSessionHandle);
   1.558 +		// bmp and key popped out of the clean-up stack by NewL
   1.559 +		bmpObj = CSharedBitmapObject::NewL(*this, bmp, key, hash);
   1.560 +		}
   1.561 +
   1.562 +	return bmpObj;
   1.563 +	}
   1.564 +
   1.565 +TInt CFbTop::GetCleanBitmap(CBitmapObject*& aBmpObjPtr)
   1.566 +	{
   1.567 +	while (aBmpObjPtr->CleanBitmap() != NULL)
   1.568 +		{
   1.569 +		aBmpObjPtr = aBmpObjPtr->CleanBitmap();
   1.570 +		}
   1.571 +	if (aBmpObjPtr->IsInCompressionQueue())
   1.572 +		return KErrInUse;
   1.573 +	return KErrNone;
   1.574 +	}
   1.575 +
   1.576 +CBitmapObject* CFbTop::FindBitmap(TInt aHandle)
   1.577 +	{
   1.578 +	TInt index = iBitmapObjectIndex.FindInOrder(aHandle, CBitmapObject::Compare);
   1.579 +	if (index != KErrNotFound)
   1.580 +		return iBitmapObjectIndex[index];
   1.581 +	return NULL;
   1.582 +	}
   1.583 +
   1.584 +TBool CFbTop::ValidFontHandle(TInt aHandle)
   1.585 +	{
   1.586 +	TInt limit=iFontCon->Count();
   1.587 +	for(TInt count=0;count<limit;count++)
   1.588 +		if(aHandle==(TInt)((*iFontCon)[count]))
   1.589 +			return(ETrue);
   1.590 +	return(EFalse);
   1.591 +	}
   1.592 +	
   1.593 +CFontStore* CFbTop::FontStore() const
   1.594 +	{
   1.595 +	return(iFontStore);
   1.596 +	}
   1.597 +
   1.598 +RHeap* CFbTop::Heap() const
   1.599 +	{
   1.600 +	return(iHeap);
   1.601 +	}
   1.602 +
   1.603 +CChunkPile* CFbTop::Pile() const
   1.604 +	{
   1.605 +	return(iPile);
   1.606 +	}
   1.607 +
   1.608 +TInt CFbTop::HeapBase() const
   1.609 +	{
   1.610 +	return(TInt(iChunk.Base()));
   1.611 +	}
   1.612 +
   1.613 +void CFbTop::SetFontNameAliasL(const RMessage2& aMessage)
   1.614 +	{
   1.615 +	const TInt aliasNameLength = aMessage.Int1();
   1.616 +	if (aliasNameLength <= 0)
   1.617 +		return; // No alias name to set
   1.618 +	
   1.619 +	if(aliasNameLength * sizeof(TText) * 2 >= KMaxTInt)
   1.620 +		{
   1.621 +		aMessage.Panic(KFBSERVPanicCategory,KErrArgument);
   1.622 +		return;
   1.623 +		}
   1.624 +		
   1.625 +	HBufC* aliasName = HBufC::NewMaxLC(aliasNameLength);
   1.626 +	TPtr aliasNamePtr(aliasName->Des());
   1.627 +	aMessage.ReadL(0,aliasNamePtr);
   1.628 +
   1.629 +	const TInt aliasIndex = FindFontNameAlias(*aliasName);
   1.630 +
   1.631 +	const TInt fontNameLength = aMessage.Int3();
   1.632 +
   1.633 +	if (fontNameLength > 0)
   1.634 +		{ // Set or change an alias
   1.635 +		HBufC* fontName = HBufC::NewMaxLC(fontNameLength);
   1.636 +		TPtr fontNamePtr(fontName->Des());
   1.637 +		aMessage.ReadL(2,fontNamePtr);
   1.638 +
   1.639 +		if (aliasIndex != KErrNotFound)
   1.640 +			{ // Change an existing alias
   1.641 +			delete iFontNameAlias[aliasIndex + 1];
   1.642 +			iFontNameAlias[aliasIndex + 1] = fontName;
   1.643 +
   1.644 +			CleanupStack::Pop(); // fontName
   1.645 +			CleanupStack::PopAndDestroy(); // aliasName
   1.646 +			}
   1.647 +		else
   1.648 +			{ // Set a new alias
   1.649 +			User::LeaveIfError(iFontNameAlias.Append(aliasName));
   1.650 +			TInt ret = iFontNameAlias.Append(fontName);
   1.651 +			if (ret != KErrNone)
   1.652 +				{
   1.653 +				iFontNameAlias.Remove(iFontNameAlias.Count() - 1);
   1.654 +				User::Leave(ret);
   1.655 +				}
   1.656 +
   1.657 +			CleanupStack::Pop(); // fontName
   1.658 +			CleanupStack::Pop(); // aliasName
   1.659 +			}
   1.660 +		}
   1.661 +	else
   1.662 +		{ // No fontName so delete the alias
   1.663 +		CleanupStack::PopAndDestroy(); // aliasName
   1.664 +		if (aliasIndex != KErrNotFound)
   1.665 +			{
   1.666 +			delete iFontNameAlias[aliasIndex];
   1.667 +			iFontNameAlias.Remove(aliasIndex);
   1.668 +			delete iFontNameAlias[aliasIndex];
   1.669 +			iFontNameAlias.Remove(aliasIndex);
   1.670 +			}
   1.671 +		}
   1.672 +	}
   1.673 +
   1.674 +TInt CFbTop::FindFontNameAlias(const TDesC& aAlias)
   1.675 +	{
   1.676 +	const TInt fontNameAliasCount = iFontNameAlias.Count();
   1.677 +
   1.678 +	for (TInt index = 0; index < fontNameAliasCount; index += 2)
   1.679 +		{
   1.680 +		if ((*iFontNameAlias[index]).CompareF(aAlias)==0)
   1.681 +			{
   1.682 +			return index;
   1.683 +			}
   1.684 +		}
   1.685 +
   1.686 +	return KErrNotFound;
   1.687 +	}
   1.688 +
   1.689 +void CFbTop::SetDefaultLanguageForMetrics(const RMessage2& aMessage)
   1.690 +	{
   1.691 +	iDefaultLanguageForMetrics = static_cast<TLanguage>(aMessage.Int0());
   1.692 +	}
   1.693 +
   1.694 +void CFbTop::CloseFileStores(TInt aSessionHandle)
   1.695 +	{
   1.696 +	iMBMCache->CloseFileStores(aSessionHandle);
   1.697 +	}
   1.698 +
   1.699 +void CFbTop::SetSystemDefaultTypefaceName(const TDesC& aFontTypefaceName)
   1.700 +	{
   1.701 +	iSystemDefaultFontTypefaceName = aFontTypefaceName;
   1.702 +	}
   1.703 +
   1.704 +TInt CFbTop::GetAllBitmapHandles(const RMessage2& aMessage) const
   1.705 +	{
   1.706 +	TPckgBuf<TInt> handleBuffer; // Use this buffer to store the bitmap handles to write to the message buffer
   1.707 +	const TInt numBitmaps = iBitmapObjectIndex.Count();
   1.708 +	TInt ret = KErrNone;
   1.709 +	for (TInt count=0; count<numBitmaps; ++count)
   1.710 +		{
   1.711 +		handleBuffer() = iBitmapObjectIndex[count]->Handle();
   1.712 +		ret = aMessage.Write(0, handleBuffer, KNumBytesPerBitmapHandle * count);
   1.713 +		if (ret!=KErrNone)
   1.714 +			break;
   1.715 +		}	
   1.716 +	return ret;
   1.717 +	}
   1.718 +
   1.719 +void CFbTop::AddClientHelper(TFbClientHelper& aHelper)
   1.720 +	{
   1.721 +	iClientHelpers.AddLast(aHelper);
   1.722 +	}
   1.723 +
   1.724 +void CFbTop::NotifyDirtyBitmap(CBitmapObject& aBmpObj, CFbClient* aClient)
   1.725 +	{
   1.726 +	TDblQueIter<TFbClientHelper> iterator(iClientHelpers);
   1.727 +	TFbClientHelper* helper;
   1.728 +	while ((helper = iterator++) != NULL)
   1.729 +		{
   1.730 +		if (aClient != &helper->iClient)
   1.731 +			helper->iClient.NotifyDirtyBitmap(aBmpObj);
   1.732 +		}
   1.733 +	}
   1.734 +
   1.735 +TInt CFbTop::BitmapConUniqueID() const
   1.736 +	{
   1.737 +	return iBitmapCon->UniqueID();
   1.738 +	}
   1.739 +
   1.740 +TInt CFbTop::FontConUniqueID() const
   1.741 +	{
   1.742 +	return iFontCon->UniqueID();
   1.743 +	}
   1.744 +
   1.745 +CGlyphAtlas* CFbTop::GlyphAtlas() const
   1.746 +	{
   1.747 +	return iGlyphAtlas;
   1.748 +	}