os/textandloc/fontservices/fontstore/src/ShaperCache.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/fontservices/fontstore/src/ShaperCache.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,165 @@
     1.4 +/*
     1.5 +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include <fntstore.h>
    1.23 +#include <gdi.h>
    1.24 +#include "FNTSTD.H"
    1.25 +#include <graphics/shapeimpl.h>
    1.26 +#include "ShaperCache.H"
    1.27 +
    1.28 +//class COpenFontShaperCacheEntry;
    1.29 +COpenFontShaperCacheEntry* COpenFontShaperCacheEntry::New(RHeap* aHeap)
    1.30 +	{
    1.31 +	COpenFontShaperCacheEntry* entry = (COpenFontShaperCacheEntry*)aHeap->Alloc(sizeof(COpenFontShaperCacheEntry));
    1.32 +	if (!entry)
    1.33 +		return NULL;
    1.34 +	new(entry) COpenFontShaperCacheEntry();	
    1.35 +	return entry;
    1.36 +	}
    1.37 +	
    1.38 +COpenFontShaperCacheEntry* COpenFontShaperCacheEntry::New(RHeap* aHeap, CShaper::TInput aInput, TShapeHeader* aShapeHeader)
    1.39 +	{
    1.40 +	COpenFontShaperCacheEntry* entry = (COpenFontShaperCacheEntry*)aHeap->Alloc(sizeof(COpenFontShaperCacheEntry));
    1.41 +	if (!entry)
    1.42 +		return NULL;
    1.43 +	new(entry) COpenFontShaperCacheEntry(aHeap,aInput);
    1.44 +	TInt ret=entry->Construct(aInput,aShapeHeader);
    1.45 +	if (ret!=KErrNone)
    1.46 +		{
    1.47 +		aHeap->Free(entry);
    1.48 +		return NULL;
    1.49 +		}
    1.50 +	return entry;
    1.51 +	}
    1.52 +
    1.53 +TInt COpenFontShaperCacheEntry::Construct(CShaper::TInput aInput,TShapeHeader* aShapeHeader)
    1.54 +	{
    1.55 +	// Get some memory for the shape header
    1.56 +	iShapeHeader = (TShapeHeader*)( iHeap->Alloc(
    1.57 +	sizeof(TShapeHeader) + (aShapeHeader->iGlyphCount * 10) + 4));
    1.58 +	if (iShapeHeader==NULL)
    1.59 +		{
    1.60 +		return KErrNoMemory;
    1.61 +		}
    1.62 +	Mem::Copy(iShapeHeader, aShapeHeader,sizeof(TShapeHeader) + (aShapeHeader->iGlyphCount * 10) + 4);
    1.63 +	
    1.64 +	// Get some memory for the input text
    1.65 +	iText = (TUint16*)(iHeap->Alloc(sizeof(TUint16)*aInput.iText->Length()));
    1.66 +	if (iText==NULL)
    1.67 +		{
    1.68 +		iHeap->Free(iShapeHeader);
    1.69 +		return KErrNoMemory;
    1.70 +		}
    1.71 +	TUint16* inputText = (TUint16*)aInput.iText->Ptr();
    1.72 +	Mem::Copy(iText, inputText, sizeof(TUint16)*aInput.iText->Length());
    1.73 +	return KErrNone;
    1.74 +	}
    1.75 +	
    1.76 +/**
    1.77 +Utility function used to free memory taken up by an entry to the cache
    1.78 +@internalTechnology
    1.79 +**/
    1.80 +void COpenFontShaperCacheEntry::Delete(RHeap* aHeap,COpenFontShaperCacheEntry* aCacheEntry)
    1.81 +	{
    1.82 +	if (!aCacheEntry->IsSentinel())
    1.83 +		{
    1.84 +		aHeap->Free(aCacheEntry->iShapeHeader);
    1.85 +		aHeap->Free(aCacheEntry->iText);
    1.86 +		//now free the THandleCount list
    1.87 +		if (aCacheEntry->iHandleRefList)
    1.88 +			{
    1.89 +			THandleCount* ptr=aCacheEntry->iHandleRefList;
    1.90 +			while (ptr)
    1.91 +				{
    1.92 +				THandleCount* next=ptr->iNext;
    1.93 +				aHeap->Free(ptr);
    1.94 +				ptr=next;
    1.95 +				}
    1.96 +			aCacheEntry->iHandleRefList=NULL;
    1.97 +			}
    1.98 +		aHeap->Free(aCacheEntry);
    1.99 +		}
   1.100 +	}
   1.101 +
   1.102 +//function to update the ref count for a particular session handle	
   1.103 +TInt COpenFontShaperCacheEntry::IncRefCount(TInt aSessionHandle)
   1.104 +	{
   1.105 +	//get pointer to start of the linked list
   1.106 +	THandleCount* ptr=iHandleRefList;
   1.107 +	THandleCount* last=NULL;
   1.108 +	//loop through existing entries first
   1.109 +	while (ptr)
   1.110 +		{
   1.111 +		if (ptr->iSessionHandle==aSessionHandle)
   1.112 +			{
   1.113 +			ptr->iRefCount++;
   1.114 +			return KErrNone;			
   1.115 +			}
   1.116 +		last=ptr;
   1.117 +		ptr=ptr->iNext;
   1.118 +		}
   1.119 +	// now we have reached the end of the list or we start with empty list
   1.120 +	THandleCount* handle=(THandleCount*)iHeap->Alloc(sizeof(THandleCount));
   1.121 +	if (!handle)
   1.122 +		return KErrNoMemory;
   1.123 +	new (handle)THandleCount(aSessionHandle);
   1.124 +	//if the list is initially empty
   1.125 +	if (!last)
   1.126 +		iHandleRefList=handle;
   1.127 +	else
   1.128 +		last->iNext=handle;
   1.129 +	iHandleRefCount++;
   1.130 +	return KErrNone;	
   1.131 +	}
   1.132 +
   1.133 +//function to decrement the ref count for a particular session handle
   1.134 +//aReset here is used to immediately reset the handleCount reference to zero
   1.135 +//and remove from the entry(this will be called in the case when a client session dies
   1.136 +//Note that once the ref count reaches zero the THandleCount entry is automatically
   1.137 +//removed from the list
   1.138 +TInt COpenFontShaperCacheEntry::DecRefCount(TInt aSessionHandle,TBool aReset)
   1.139 +	{
   1.140 +	//get pointer to start of the linked list
   1.141 +	THandleCount* ptr=iHandleRefList;
   1.142 +	THandleCount* last=NULL;
   1.143 +	//loop through existing entries first
   1.144 +	while (ptr)
   1.145 +		{
   1.146 +		if (ptr->iSessionHandle==aSessionHandle)
   1.147 +			{
   1.148 +			if (aReset || ptr->iRefCount==1)
   1.149 +				{
   1.150 +				THandleCount* next=ptr->iNext;
   1.151 +				//delete from first item
   1.152 +				if (last==NULL)
   1.153 +					iHandleRefList=next;
   1.154 +				else
   1.155 +					last->iNext=next;
   1.156 +				iHeap->Free(ptr);
   1.157 +				iHandleRefCount--;			
   1.158 +				return KErrNone;
   1.159 +				}
   1.160 +			ptr->iRefCount--;
   1.161 +			return KErrNone;			
   1.162 +			}
   1.163 +		last=ptr;	
   1.164 +		ptr=ptr->iNext;
   1.165 +		}
   1.166 +	return KErrNotFound;	
   1.167 +	}	
   1.168 +