os/textandloc/fontservices/fontstore/src/ShaperCache.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
#include <fntstore.h>
sl@0
    20
#include <gdi.h>
sl@0
    21
#include "FNTSTD.H"
sl@0
    22
#include <graphics/shapeimpl.h>
sl@0
    23
#include "ShaperCache.H"
sl@0
    24
sl@0
    25
//class COpenFontShaperCacheEntry;
sl@0
    26
COpenFontShaperCacheEntry* COpenFontShaperCacheEntry::New(RHeap* aHeap)
sl@0
    27
	{
sl@0
    28
	COpenFontShaperCacheEntry* entry = (COpenFontShaperCacheEntry*)aHeap->Alloc(sizeof(COpenFontShaperCacheEntry));
sl@0
    29
	if (!entry)
sl@0
    30
		return NULL;
sl@0
    31
	new(entry) COpenFontShaperCacheEntry();	
sl@0
    32
	return entry;
sl@0
    33
	}
sl@0
    34
	
sl@0
    35
COpenFontShaperCacheEntry* COpenFontShaperCacheEntry::New(RHeap* aHeap, CShaper::TInput aInput, TShapeHeader* aShapeHeader)
sl@0
    36
	{
sl@0
    37
	COpenFontShaperCacheEntry* entry = (COpenFontShaperCacheEntry*)aHeap->Alloc(sizeof(COpenFontShaperCacheEntry));
sl@0
    38
	if (!entry)
sl@0
    39
		return NULL;
sl@0
    40
	new(entry) COpenFontShaperCacheEntry(aHeap,aInput);
sl@0
    41
	TInt ret=entry->Construct(aInput,aShapeHeader);
sl@0
    42
	if (ret!=KErrNone)
sl@0
    43
		{
sl@0
    44
		aHeap->Free(entry);
sl@0
    45
		return NULL;
sl@0
    46
		}
sl@0
    47
	return entry;
sl@0
    48
	}
sl@0
    49
sl@0
    50
TInt COpenFontShaperCacheEntry::Construct(CShaper::TInput aInput,TShapeHeader* aShapeHeader)
sl@0
    51
	{
sl@0
    52
	// Get some memory for the shape header
sl@0
    53
	iShapeHeader = (TShapeHeader*)( iHeap->Alloc(
sl@0
    54
	sizeof(TShapeHeader) + (aShapeHeader->iGlyphCount * 10) + 4));
sl@0
    55
	if (iShapeHeader==NULL)
sl@0
    56
		{
sl@0
    57
		return KErrNoMemory;
sl@0
    58
		}
sl@0
    59
	Mem::Copy(iShapeHeader, aShapeHeader,sizeof(TShapeHeader) + (aShapeHeader->iGlyphCount * 10) + 4);
sl@0
    60
	
sl@0
    61
	// Get some memory for the input text
sl@0
    62
	iText = (TUint16*)(iHeap->Alloc(sizeof(TUint16)*aInput.iText->Length()));
sl@0
    63
	if (iText==NULL)
sl@0
    64
		{
sl@0
    65
		iHeap->Free(iShapeHeader);
sl@0
    66
		return KErrNoMemory;
sl@0
    67
		}
sl@0
    68
	TUint16* inputText = (TUint16*)aInput.iText->Ptr();
sl@0
    69
	Mem::Copy(iText, inputText, sizeof(TUint16)*aInput.iText->Length());
sl@0
    70
	return KErrNone;
sl@0
    71
	}
sl@0
    72
	
sl@0
    73
/**
sl@0
    74
Utility function used to free memory taken up by an entry to the cache
sl@0
    75
@internalTechnology
sl@0
    76
**/
sl@0
    77
void COpenFontShaperCacheEntry::Delete(RHeap* aHeap,COpenFontShaperCacheEntry* aCacheEntry)
sl@0
    78
	{
sl@0
    79
	if (!aCacheEntry->IsSentinel())
sl@0
    80
		{
sl@0
    81
		aHeap->Free(aCacheEntry->iShapeHeader);
sl@0
    82
		aHeap->Free(aCacheEntry->iText);
sl@0
    83
		//now free the THandleCount list
sl@0
    84
		if (aCacheEntry->iHandleRefList)
sl@0
    85
			{
sl@0
    86
			THandleCount* ptr=aCacheEntry->iHandleRefList;
sl@0
    87
			while (ptr)
sl@0
    88
				{
sl@0
    89
				THandleCount* next=ptr->iNext;
sl@0
    90
				aHeap->Free(ptr);
sl@0
    91
				ptr=next;
sl@0
    92
				}
sl@0
    93
			aCacheEntry->iHandleRefList=NULL;
sl@0
    94
			}
sl@0
    95
		aHeap->Free(aCacheEntry);
sl@0
    96
		}
sl@0
    97
	}
sl@0
    98
sl@0
    99
//function to update the ref count for a particular session handle	
sl@0
   100
TInt COpenFontShaperCacheEntry::IncRefCount(TInt aSessionHandle)
sl@0
   101
	{
sl@0
   102
	//get pointer to start of the linked list
sl@0
   103
	THandleCount* ptr=iHandleRefList;
sl@0
   104
	THandleCount* last=NULL;
sl@0
   105
	//loop through existing entries first
sl@0
   106
	while (ptr)
sl@0
   107
		{
sl@0
   108
		if (ptr->iSessionHandle==aSessionHandle)
sl@0
   109
			{
sl@0
   110
			ptr->iRefCount++;
sl@0
   111
			return KErrNone;			
sl@0
   112
			}
sl@0
   113
		last=ptr;
sl@0
   114
		ptr=ptr->iNext;
sl@0
   115
		}
sl@0
   116
	// now we have reached the end of the list or we start with empty list
sl@0
   117
	THandleCount* handle=(THandleCount*)iHeap->Alloc(sizeof(THandleCount));
sl@0
   118
	if (!handle)
sl@0
   119
		return KErrNoMemory;
sl@0
   120
	new (handle)THandleCount(aSessionHandle);
sl@0
   121
	//if the list is initially empty
sl@0
   122
	if (!last)
sl@0
   123
		iHandleRefList=handle;
sl@0
   124
	else
sl@0
   125
		last->iNext=handle;
sl@0
   126
	iHandleRefCount++;
sl@0
   127
	return KErrNone;	
sl@0
   128
	}
sl@0
   129
sl@0
   130
//function to decrement the ref count for a particular session handle
sl@0
   131
//aReset here is used to immediately reset the handleCount reference to zero
sl@0
   132
//and remove from the entry(this will be called in the case when a client session dies
sl@0
   133
//Note that once the ref count reaches zero the THandleCount entry is automatically
sl@0
   134
//removed from the list
sl@0
   135
TInt COpenFontShaperCacheEntry::DecRefCount(TInt aSessionHandle,TBool aReset)
sl@0
   136
	{
sl@0
   137
	//get pointer to start of the linked list
sl@0
   138
	THandleCount* ptr=iHandleRefList;
sl@0
   139
	THandleCount* last=NULL;
sl@0
   140
	//loop through existing entries first
sl@0
   141
	while (ptr)
sl@0
   142
		{
sl@0
   143
		if (ptr->iSessionHandle==aSessionHandle)
sl@0
   144
			{
sl@0
   145
			if (aReset || ptr->iRefCount==1)
sl@0
   146
				{
sl@0
   147
				THandleCount* next=ptr->iNext;
sl@0
   148
				//delete from first item
sl@0
   149
				if (last==NULL)
sl@0
   150
					iHandleRefList=next;
sl@0
   151
				else
sl@0
   152
					last->iNext=next;
sl@0
   153
				iHeap->Free(ptr);
sl@0
   154
				iHandleRefCount--;			
sl@0
   155
				return KErrNone;
sl@0
   156
				}
sl@0
   157
			ptr->iRefCount--;
sl@0
   158
			return KErrNone;			
sl@0
   159
			}
sl@0
   160
		last=ptr;	
sl@0
   161
		ptr=ptr->iNext;
sl@0
   162
		}
sl@0
   163
	return KErrNotFound;	
sl@0
   164
	}	
sl@0
   165