Update contrib.
2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
22 #include <graphics/shapeimpl.h>
23 #include "ShaperCache.H"
25 //class COpenFontShaperCacheEntry;
26 COpenFontShaperCacheEntry* COpenFontShaperCacheEntry::New(RHeap* aHeap)
28 COpenFontShaperCacheEntry* entry = (COpenFontShaperCacheEntry*)aHeap->Alloc(sizeof(COpenFontShaperCacheEntry));
31 new(entry) COpenFontShaperCacheEntry();
35 COpenFontShaperCacheEntry* COpenFontShaperCacheEntry::New(RHeap* aHeap, CShaper::TInput aInput, TShapeHeader* aShapeHeader)
37 COpenFontShaperCacheEntry* entry = (COpenFontShaperCacheEntry*)aHeap->Alloc(sizeof(COpenFontShaperCacheEntry));
40 new(entry) COpenFontShaperCacheEntry(aHeap,aInput);
41 TInt ret=entry->Construct(aInput,aShapeHeader);
50 TInt COpenFontShaperCacheEntry::Construct(CShaper::TInput aInput,TShapeHeader* aShapeHeader)
52 // Get some memory for the shape header
53 iShapeHeader = (TShapeHeader*)( iHeap->Alloc(
54 sizeof(TShapeHeader) + (aShapeHeader->iGlyphCount * 10) + 4));
55 if (iShapeHeader==NULL)
59 Mem::Copy(iShapeHeader, aShapeHeader,sizeof(TShapeHeader) + (aShapeHeader->iGlyphCount * 10) + 4);
61 // Get some memory for the input text
62 iText = (TUint16*)(iHeap->Alloc(sizeof(TUint16)*aInput.iText->Length()));
65 iHeap->Free(iShapeHeader);
68 TUint16* inputText = (TUint16*)aInput.iText->Ptr();
69 Mem::Copy(iText, inputText, sizeof(TUint16)*aInput.iText->Length());
74 Utility function used to free memory taken up by an entry to the cache
77 void COpenFontShaperCacheEntry::Delete(RHeap* aHeap,COpenFontShaperCacheEntry* aCacheEntry)
79 if (!aCacheEntry->IsSentinel())
81 aHeap->Free(aCacheEntry->iShapeHeader);
82 aHeap->Free(aCacheEntry->iText);
83 //now free the THandleCount list
84 if (aCacheEntry->iHandleRefList)
86 THandleCount* ptr=aCacheEntry->iHandleRefList;
89 THandleCount* next=ptr->iNext;
93 aCacheEntry->iHandleRefList=NULL;
95 aHeap->Free(aCacheEntry);
99 //function to update the ref count for a particular session handle
100 TInt COpenFontShaperCacheEntry::IncRefCount(TInt aSessionHandle)
102 //get pointer to start of the linked list
103 THandleCount* ptr=iHandleRefList;
104 THandleCount* last=NULL;
105 //loop through existing entries first
108 if (ptr->iSessionHandle==aSessionHandle)
116 // now we have reached the end of the list or we start with empty list
117 THandleCount* handle=(THandleCount*)iHeap->Alloc(sizeof(THandleCount));
120 new (handle)THandleCount(aSessionHandle);
121 //if the list is initially empty
123 iHandleRefList=handle;
130 //function to decrement the ref count for a particular session handle
131 //aReset here is used to immediately reset the handleCount reference to zero
132 //and remove from the entry(this will be called in the case when a client session dies
133 //Note that once the ref count reaches zero the THandleCount entry is automatically
134 //removed from the list
135 TInt COpenFontShaperCacheEntry::DecRefCount(TInt aSessionHandle,TBool aReset)
137 //get pointer to start of the linked list
138 THandleCount* ptr=iHandleRefList;
139 THandleCount* last=NULL;
140 //loop through existing entries first
143 if (ptr->iSessionHandle==aSessionHandle)
145 if (aReset || ptr->iRefCount==1)
147 THandleCount* next=ptr->iNext;
148 //delete from first item