1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/textandloc/fontservices/fontstore/inc/openfontsprivate.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,430 @@
1.4 +/*
1.5 +* Copyright (c) 2006-2010 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 +#ifndef __OPENFONTS_PRIVATE_H__
1.23 +#define __OPENFONTS_PRIVATE_H__
1.24 +
1.25 +#include <hextree.h>
1.26 +#include <e32hashtab.h>
1.27 +
1.28 +class COpenFontShaperCacheEntry;
1.29 +
1.30 +/* MSB is set to indicate a glyph code rather than a unicode value
1.31 + This is used for extracting the code value */
1.32 +#define GLYPH_CODE(code) (code & 0x7fffffff)
1.33 +
1.34 +/** COpenFontFile owned container for extra data. May be extended without affecting Binary Compatibility.
1.35 +
1.36 + @internalComponent
1.37 + */
1.38 +
1.39 +class TOpenFontFileData
1.40 + {
1.41 +public:
1.42 + CFontStore* iFontStore; // pointer to the CFontStore instance that loaded the COpenFontFile
1.43 + };
1.44 +
1.45 +/**
1.46 + Note: this class must be self-contained, since instances are added to an RHexTree,
1.47 + that is, it must be possible to destroy instances simply with RHeap::Free().
1.48 + @internalComponent
1.49 + */
1.50 +class COpenFontGlyph
1.51 + {
1.52 +public:
1.53 + static COpenFontGlyph* New(RHeap* aHeap, TInt aCode, TInt aGlyphIndex,
1.54 + const TOpenFontCharMetrics& aMetrics, const TDesC8& aBitmap);
1.55 + inline static void Delete(RHeap* aHeap, COpenFontGlyph* aGlyph);
1.56 + inline const TUint8* Bitmap() const;
1.57 +
1.58 +protected:
1.59 + COpenFontGlyph(TInt aCode, TInt aGlyphIndex, const TOpenFontCharMetrics& aMetrics)
1.60 + : iCode(aCode), iGlyphIndex(aGlyphIndex), iMetrics(aMetrics), iBitmapOffset(0) {}
1.61 + ~COpenFontGlyph() {}
1.62 + void SetBitmap(const TAny* aBitmap);
1.63 +
1.64 +public:
1.65 + const TInt iCode; // the Unicode value of the character
1.66 + const TInt iGlyphIndex; // the glyph index
1.67 + const TOpenFontCharMetrics iMetrics; // the metrics
1.68 +
1.69 +private:
1.70 + // an offset from this COpenFontGlyph object to a pointer to the run-length-encoded bitmap,
1.71 + // calculated as (bitmapPointer)-(this)
1.72 + TInt iBitmapOffset;
1.73 + };
1.74 +
1.75 +/**
1.76 + * Template for offset implementation of pointer array
1.77 + @internalComponent
1.78 + */
1.79 +template<class T>
1.80 +class ROffsetArray
1.81 + {
1.82 +public:
1.83 + ROffsetArray();
1.84 + TInt Create(RHeap* aHeap, TInt aCount);
1.85 + void Close(RHeap* aHeap);
1.86 + TInt Count() const;
1.87 + T* operator[](TInt aIndex) const;
1.88 + void SetAt(TInt aIndex, T* aEntry);
1.89 +private:
1.90 + TInt iOffset;
1.91 + TInt iCount;
1.92 + };
1.93 +
1.94 +
1.95 +/**
1.96 + The per-font glyph cache. For now, just the members that used to be directly in
1.97 + COpenFont. Now it is a private class it can be elaborated to do character-to-glyph-index
1.98 + mapping when that is needed.
1.99 +
1.100 + @internalComponent
1.101 + */
1.102 +class COpenFontGlyphCache
1.103 + {
1.104 +public:
1.105 + COpenFontGlyphCache(RHeap* aHeap)
1.106 + : iGlyphTreeById(aHeap),
1.107 + iGlyphTreeByUnicode(aHeap),
1.108 + iGlyphCacheMemory(0),
1.109 + iShaperCacheSentinel(NULL),
1.110 + iShapingInfoCacheMemory(0),
1.111 + iNumberOfShaperCacheEntries(0)
1.112 + {}
1.113 + TShapeHeader* SearchShaperCache(TInt aSessionHandle, TFontShapeFunctionParameters*& aParams);
1.114 + TShapeHeader* Insert(TInt aSessionHandle, RHeap* aHeap, CShaper::TInput aInput, TShapeHeader* aShapeHeader, TInt& aAddedBytes);
1.115 + TInt DeleteLeastRecentlyUsedEntry(RHeap* aHeap);
1.116 + TBool ShaperCacheIsEmpty();
1.117 +
1.118 +public:
1.119 + RHexTree<COpenFontGlyph> iGlyphTreeById; // a hex tree of glyphs indexed by glyph ID
1.120 + RHexTree<COpenFontGlyph> iGlyphTreeByUnicode; // a hex tree of glyphs indexed by Unicode code point
1.121 + TInt iGlyphCacheMemory; // memory used by the glyph tree in bytes
1.122 + COpenFontShaperCacheEntry* iShaperCacheSentinel;
1.123 + TInt iShapingInfoCacheMemory;
1.124 + TInt iNumberOfShaperCacheEntries;
1.125 + };
1.126 +
1.127 +/**
1.128 + @internalComponent
1.129 + */
1.130 +class COpenFontSessionCacheEntry: public COpenFontGlyph
1.131 + {
1.132 +public:
1.133 + static COpenFontSessionCacheEntry* New(RHeap* aHeap, const COpenFont* aFont, TInt aCode, TInt aGlyphIndex,
1.134 + const TOpenFontCharMetrics& aMetrics, const TDesC8& aBitmap);
1.135 + inline static void Delete(RHeap* aHeap, COpenFontSessionCacheEntry* aEntry);
1.136 + inline const COpenFont* Font()const;
1.137 +
1.138 +private:
1.139 + inline COpenFontSessionCacheEntry(const COpenFont* aFont, TInt aCode, TInt aGlyphIndex, const TOpenFontCharMetrics& aMetrics);
1.140 + ~COpenFontSessionCacheEntry();
1.141 +
1.142 +private:
1.143 + TInt iFontOffset; // offset of the font that contains this glyph, (not owned by this class!)
1.144 + };
1.145 +
1.146 +/**
1.147 + A glyph cache for a particular session.
1.148 + Because session caches are not shared they can shrink as well as grow.
1.149 +
1.150 + @internalComponent
1.151 + */
1.152 +class COpenFontSessionCache
1.153 + {
1.154 + friend class COpenFontSessionCacheList;
1.155 +public:
1.156 + static COpenFontSessionCache* NewL(RHeap* aHeap, TInt aSessionHandle, TInt aEntries);
1.157 + void Delete(RHeap* aHeap);
1.158 +
1.159 + TInt SessionHandle() { return iSessionHandle; }
1.160 + const COpenFontGlyph* Glyph(const COpenFont* aFont, TInt aCode, TInt& aIndex) const;
1.161 + void Insert(RHeap* aHeap, COpenFontSessionCacheEntry* aEntry, TInt aIndex);
1.162 +
1.163 +private:
1.164 + COpenFontSessionCache(TInt aSessionHandle);
1.165 + ~COpenFontSessionCache();
1.166 +private:
1.167 + TInt iSessionHandle;
1.168 + TInt64 iRandomSeed;
1.169 + ROffsetArray<COpenFontSessionCacheEntry> iEntryArray;
1.170 + };
1.171 +
1.172 +
1.173 +class TFontTableGlyphOutlineCacheMemMonitor
1.174 + {
1.175 +public:
1.176 + TFontTableGlyphOutlineCacheMemMonitor();
1.177 + void Inc(TInt aBytes);
1.178 + void Dec(TInt aBytes);
1.179 + TInt GetMemUsage();
1.180 +private:
1.181 + TInt iBytes;
1.182 + };
1.183 +
1.184 +struct TCacheUserInfo {
1.185 + TInt iSessionHandle;
1.186 + TInt iRefCount;
1.187 + TCacheUserInfo(TInt aSessionHandle, TInt aRefCount = 0):
1.188 + iSessionHandle(aSessionHandle), iRefCount(aRefCount) { }
1.189 +};
1.190 +
1.191 +class CFontTableCache;
1.192 +
1.193 +class CFontTableCacheItem
1.194 + {
1.195 +friend class CFontTableCache ;
1.196 +
1.197 +public:
1.198 + CFontTableCacheItem(TUid &aFileUid, const TUint32 aTag,
1.199 + TInt aOffset, TInt aLength);
1.200 + ~CFontTableCacheItem();
1.201 +
1.202 + TInt DecRefCount(TInt aSessionHandle);
1.203 + TInt IncRefCount(TInt aSessionHandle);
1.204 +
1.205 + TBool HasOutstandingRefCount();
1.206 + TInt FindUser(TInt aSessionHandle, TInt *id);
1.207 +
1.208 +#ifdef _DEBUG
1.209 + void SetUser(RPointerArray<TCacheUserInfo> users)
1.210 + {
1.211 + TInt len = users.Count();
1.212 + for( TInt i = 0; i < len ; i++ )
1.213 + {
1.214 + iUsers.Append(users[i]);
1.215 + }
1.216 + }
1.217 +#endif
1.218 +
1.219 +private:
1.220 + CFontTableCacheItem(const CFontTableCacheItem &); // disallow copy construction.
1.221 + CFontTableCacheItem& operator =(const CFontTableCacheItem &); // disallow assignment.
1.222 +
1.223 + TUid iFileUid;
1.224 + TUint32 iTag;
1.225 +
1.226 +
1.227 + TInt iOffset;
1.228 + TInt iLength;
1.229 + RPointerArray<TCacheUserInfo> iUsers;
1.230 + };
1.231 +
1.232 +
1.233 +class CFontTableCache
1.234 + {
1.235 +public:
1.236 + CFontTableCache(RHeap* aHeap, TFontTableGlyphOutlineCacheMemMonitor& aMon);
1.237 + ~CFontTableCache();
1.238 + TInt Append(TUid aFileUid, TUint32 aTag,
1.239 + TAny*& aContent, TInt aLength);
1.240 + TInt Find(TUid aFileUid, TUint32 aTag, TAny*& aContent, TInt& aLength, TInt* id);
1.241 + TInt IncRefCount(TUid FileUid, TUint32 aTag, TInt aSessionHandle);
1.242 + TInt DecRefCount(TUid aFileUid, TUint32 aTag, TInt aSessionHandle);
1.243 + TBool HasOutstandingRefCount();
1.244 + TBool HasOutstandingRefCountWithUid(TUid aFileUid);
1.245 + void CleanupCacheOnFbsSessionTermination(TInt aSessionHandle);
1.246 + void CleanupCacheOnOpenFontFileRemoval(COpenFontFile*);
1.247 +#ifdef _DEBUG
1.248 + void SetFontItem(RPointerArray<CFontTableCacheItem> cacheItems)
1.249 + {
1.250 + TInt len = cacheItems.Count();
1.251 + for(TInt i = 0; i < len; i++)
1.252 + {
1.253 + iCacheItems.Append(cacheItems[i]);
1.254 + }
1.255 + }
1.256 +#endif
1.257 +
1.258 +private:
1.259 + CFontTableCache(const CFontTableCache &); // no copy construction.
1.260 + CFontTableCache& operator =(const CFontTableCache &); // no assignment.
1.261 +#ifdef _DEBUG
1.262 + TInt GetCacheState(const char *func);
1.263 +#endif
1.264 +
1.265 + TFontTableGlyphOutlineCacheMemMonitor &iCacheMemMon;
1.266 + RHeap *iHeap;
1.267 + RPointerArray<CFontTableCacheItem> iCacheItems;
1.268 + };
1.269 +
1.270 +
1.271 +class TUnhintedOutlineCache;
1.272 +
1.273 +class TUnhintedOutlineId
1.274 + {
1.275 +public:
1.276 + TUnhintedOutlineId(TUid aFileUid, TInt aFaceIndex, TUint aId);
1.277 + TUid iFileUid;
1.278 + TInt iFaceIndex;
1.279 + TUint iId;
1.280 + };
1.281 +
1.282 +class COutlineCacheItem {
1.283 +friend class CUnhintedOutlineCache;
1.284 +friend class CHintedOutlineCache;
1.285 +
1.286 +public:
1.287 + COutlineCacheItem(TInt aOffset, TInt aLength);
1.288 + ~COutlineCacheItem() ;
1.289 +
1.290 + TInt DecRefCount(TInt aSessionHandle);
1.291 + TInt IncRefCount(TInt aSessionHandle);
1.292 +#ifdef _DEBUG
1.293 + void SetUser(RPointerArray<TCacheUserInfo> users)
1.294 + {
1.295 + TInt len = users.Count();
1.296 + for( TInt i = 0; i < len ; i++ )
1.297 + {
1.298 + iUsers.Append(users[i]);
1.299 + }
1.300 + }
1.301 +#endif
1.302 +
1.303 +private:
1.304 + TInt FindUser(TInt aSessionHandle, TInt *id);
1.305 +
1.306 +
1.307 + TInt iOffset;
1.308 + TInt iLength;
1.309 + RPointerArray<TCacheUserInfo> iUsers;
1.310 +};
1.311 +
1.312 +class CUnhintedOutlineCache {
1.313 +public:
1.314 + CUnhintedOutlineCache(RHeap* aHeap, TFontTableGlyphOutlineCacheMemMonitor& aMon);
1.315 + TInt Find(const TUnhintedOutlineId &aOutlineId, TAny*& aData, TInt& aLength);
1.316 + TInt IncRefCount(const TUnhintedOutlineId& aOutlineId, TInt aSessionHandle);
1.317 + TInt DecRefCount(const TUnhintedOutlineId& aOutlineId, TInt aSessionHandle);
1.318 + TInt CacheUnhintedOutline(const TUnhintedOutlineId& aOutlineId,
1.319 + TAny * const aData, const TInt aLength, TAny*& aOutline, TInt &aLen);
1.320 + TInt CleanupCacheOnOpenFontFileRemoval(COpenFontFile* aFontFile);
1.321 + TInt CleanupCacheOnFbsSessionTermination(TInt aSessionHandle);
1.322 +#ifdef _DEBUG
1.323 + TInt GetCacheState(const char *func);
1.324 +#endif
1.325 + ~CUnhintedOutlineCache();
1.326 +
1.327 +#ifdef _DEBUG
1.328 + void SetUnHintedItem(TUnhintedOutlineId id, COutlineCacheItem* item)
1.329 + {
1.330 + iItemIdMap.Insert(id, item);
1.331 + }
1.332 +#endif
1.333 +
1.334 +private:
1.335 + // disallow assignment and copy-construction
1.336 + CUnhintedOutlineCache(const CUnhintedOutlineCache &);
1.337 + CUnhintedOutlineCache& operator =(const CUnhintedOutlineCache &);
1.338 +
1.339 + static TUint32 IdHash(const TUnhintedOutlineId& aOutlineId);
1.340 + static TBool IdIdentity(const TUnhintedOutlineId& id1, const TUnhintedOutlineId& id2);
1.341 +
1.342 + TFontTableGlyphOutlineCacheMemMonitor& iCacheMemMon;
1.343 + RHeap* iHeap;
1.344 + RHashMap<TUnhintedOutlineId, COutlineCacheItem*> iItemIdMap; // map the identity to an index in 'iCacheItems'.
1.345 +};
1.346 +
1.347 +class CHintedOutlineCache;
1.348 +
1.349 +class THintedOutlineId
1.350 + {
1.351 +public:
1.352 + THintedOutlineId(COpenFont* aFont, TUint aId);
1.353 + COpenFont *iFont;
1.354 + TUint iId;
1.355 + };
1.356 +
1.357 +
1.358 +class CHintedOutlineCache {
1.359 +public:
1.360 + CHintedOutlineCache(RHeap* aHeap, TFontTableGlyphOutlineCacheMemMonitor& aMon);
1.361 + TInt Find(const THintedOutlineId& aOutlineId, TAny*& aData, TInt& aLength);
1.362 + TInt IncRefCount(const THintedOutlineId& aOutlineId, TInt aSessionHandle);
1.363 + TInt DecRefCount(const THintedOutlineId& aOutlineId, TInt aSessionHandle);
1.364 + TInt CacheHintedOutline(const THintedOutlineId& aOutlineId,
1.365 + TAny* aData, TInt aLength, TAny*& aOutline, TInt& aLen);
1.366 + TInt CleanupCacheOnOpenFontRemoval(COpenFont* aFont);
1.367 + TInt CleanupCacheOnFbsSessionTermination(TInt aSessionHandle);
1.368 +#ifdef _DEBUG
1.369 + TInt GetCacheState(const char *func);
1.370 + void SetHintedItem(THintedOutlineId id, COutlineCacheItem* item)
1.371 + {
1.372 + iItemIdMap.Insert(id, item);
1.373 + }
1.374 + RHashMap<THintedOutlineId, COutlineCacheItem*> GetHintedMap()
1.375 + {
1.376 + return iItemIdMap;
1.377 + }
1.378 +#endif
1.379 +
1.380 +private:
1.381 + // disallow assignment and copy-construction
1.382 + CHintedOutlineCache(const CHintedOutlineCache &);
1.383 + CHintedOutlineCache& operator =(const CHintedOutlineCache &);
1.384 + static TUint32 IdHash(const THintedOutlineId& aOutlineId);
1.385 + static TBool IdIdentity(const THintedOutlineId& id1, const THintedOutlineId& id2);
1.386 +
1.387 + TFontTableGlyphOutlineCacheMemMonitor& iCacheMemMon;
1.388 + RHeap* iHeap;
1.389 + RHashMap<THintedOutlineId, COutlineCacheItem*> iItemIdMap; // map the identity to an index in 'iCacheItems'.
1.390 + };
1.391 +
1.392 +
1.393 +// inline functions
1.394 +
1.395 +inline void COpenFontGlyph::Delete(RHeap* aHeap, COpenFontGlyph* aGlyph)
1.396 + {
1.397 + aHeap->Free(aGlyph);
1.398 + }
1.399 +
1.400 +/**
1.401 +@return A pointer to the bitmap data stored with this glyph, or NULL
1.402 +if no bitmap has been stored with this glyph.
1.403 + */
1.404 +inline const TUint8* COpenFontGlyph::Bitmap() const
1.405 + {
1.406 + if (iBitmapOffset)
1.407 + {
1.408 + return reinterpret_cast<const TUint8*>(PtrAdd(this, iBitmapOffset));
1.409 + }
1.410 + return NULL;
1.411 + }
1.412 +
1.413 +inline COpenFontSessionCacheEntry::COpenFontSessionCacheEntry(const COpenFont* aFont, TInt aCode, TInt aGlyphIndex,const TOpenFontCharMetrics& aMetrics) :
1.414 + COpenFontGlyph(aCode, aGlyphIndex, aMetrics)
1.415 + {
1.416 + iFontOffset = aFont ? reinterpret_cast<TInt>(aFont) - reinterpret_cast<TInt>(this) : 0;
1.417 + }
1.418 +
1.419 +inline void COpenFontSessionCacheEntry::Delete(RHeap* aHeap, COpenFontSessionCacheEntry* aEntry)
1.420 + {
1.421 + COpenFontGlyph::Delete(aHeap, aEntry);
1.422 + }
1.423 +
1.424 +inline const COpenFont* COpenFontSessionCacheEntry::Font() const
1.425 + {
1.426 + if (iFontOffset)
1.427 + {
1.428 + return reinterpret_cast<const COpenFont*> (PtrAdd(this, iFontOffset));
1.429 + }
1.430 + return NULL;
1.431 + }
1.432 +
1.433 +#endif // __OPENFONTSPRIVATE_H__