fontservices/fontstore/inc/openfontsprivate.h
branchRCL_3
changeset 11 6971d1c87c9a
parent 5 e96e8a131979
child 15 9a2be90ac9a2
equal deleted inserted replaced
5:e96e8a131979 11:6971d1c87c9a
    17 
    17 
    18 
    18 
    19 #ifndef __OPENFONTS_PRIVATE_H__
    19 #ifndef __OPENFONTS_PRIVATE_H__
    20 #define __OPENFONTS_PRIVATE_H__
    20 #define __OPENFONTS_PRIVATE_H__
    21 
    21 
    22 #include <e32hashtab.h>
       
    23 class COpenFontShaperCacheEntry;
    22 class COpenFontShaperCacheEntry;
    24 
    23 
    25 /* MSB is set to indicate a glyph code rather than a unicode value
    24 /* MSB is set to indicate a glyph code rather than a unicode value
    26    This is used for extracting the code value */
    25    This is used for extracting the code value */
    27 #define GLYPH_CODE(code) (code & 0x7fffffff)
    26 #define GLYPH_CODE(code) (code & 0x7fffffff)
   209 private:
   208 private:
   210 	TInt iNextOffset;
   209 	TInt iNextOffset;
   211 	TInt iCacheOffset;
   210 	TInt iCacheOffset;
   212 	};
   211 	};
   213 
   212 
   214 class TFontTableGlyphOutlineCacheMemMonitor
       
   215     {
       
   216 public:
       
   217     TFontTableGlyphOutlineCacheMemMonitor();
       
   218     void Inc(TInt aBytes);
       
   219     void Dec(TInt aBytes);
       
   220     TInt GetMemUsage();
       
   221 private:
       
   222     TInt iBytes;
       
   223     };
       
   224 
       
   225 struct TCacheUserInfo {
       
   226     TInt iSessionHandle;
       
   227     TInt iRefCount;
       
   228     TCacheUserInfo(TInt aSessionHandle, TInt aRefCount = 0): 
       
   229             iSessionHandle(aSessionHandle), iRefCount(aRefCount) { } 
       
   230 };
       
   231 
       
   232 class CFontTableCache;
       
   233 
       
   234 class CFontTableCacheItem
       
   235     {
       
   236 friend class CFontTableCache ;
       
   237 
       
   238 public:
       
   239     CFontTableCacheItem(TUid &aFileUid, const TUint32 aTag, 
       
   240             TInt aOffset, TInt aLength);
       
   241     ~CFontTableCacheItem(); 
       
   242 
       
   243     TInt DecRefCount(TInt aSessionHandle);
       
   244     TInt IncRefCount(TInt aSessionHandle);
       
   245 
       
   246     TBool HasOutstandingRefCount();
       
   247     TInt FindUser(TInt aSessionHandle, TInt *id);
       
   248     
       
   249 #ifdef _DEBUG
       
   250     void SetUser(RPointerArray<TCacheUserInfo> users)
       
   251         {
       
   252         TInt len = users.Count();
       
   253         for( TInt i = 0; i < len ; i++ )
       
   254             {
       
   255             iUsers.Append(users[i]);
       
   256             }
       
   257         }    
       
   258 #endif
       
   259     
       
   260 private:
       
   261     CFontTableCacheItem(const CFontTableCacheItem &); // disallow copy construction.
       
   262     CFontTableCacheItem& operator =(const CFontTableCacheItem &); // disallow assignment.
       
   263     
       
   264     TUid iFileUid; 
       
   265     TUint32 iTag; 
       
   266  
       
   267 
       
   268     TInt iOffset;
       
   269     TInt iLength; 
       
   270     RPointerArray<TCacheUserInfo> iUsers;
       
   271     }; 
       
   272 
       
   273 
       
   274 class CFontTableCache 
       
   275     {
       
   276 public:
       
   277     CFontTableCache(RHeap* aHeap, TFontTableGlyphOutlineCacheMemMonitor& aMon);
       
   278     ~CFontTableCache();
       
   279     TInt Append(TUid aFileUid, TUint32 aTag, 
       
   280             TAny*& aContent, TInt aLength);
       
   281     TInt Find(TUid aFileUid, TUint32 aTag, TAny*& aContent, TInt& aLength, TInt* id);
       
   282     TInt IncRefCount(TUid FileUid, TUint32 aTag, TInt aSessionHandle);
       
   283     TInt DecRefCount(TUid aFileUid, TUint32 aTag, TInt aSessionHandle);
       
   284     TBool HasOutstandingRefCount();
       
   285     TBool HasOutstandingRefCountWithUid(TUid aFileUid);  
       
   286     void CleanupCacheOnFbsSessionTermination(TInt aSessionHandle);
       
   287     void CleanupCacheOnOpenFontFileRemoval(COpenFontFile*);
       
   288 #ifdef _DEBUG    
       
   289     void SetFontItem(RPointerArray<CFontTableCacheItem> cacheItems)
       
   290         {
       
   291         TInt len = cacheItems.Count();
       
   292         for(TInt i = 0; i < len; i++)
       
   293             {
       
   294             iCacheItems.Append(cacheItems[i]);
       
   295             }
       
   296         }
       
   297 #endif   
       
   298     
       
   299 private:
       
   300     CFontTableCache(const CFontTableCache &); // no copy construction.
       
   301     CFontTableCache& operator =(const CFontTableCache &); // no assignment.
       
   302 #ifdef _DEBUG
       
   303     TInt GetCacheState(const char *func);
       
   304 #endif
       
   305     
       
   306     TFontTableGlyphOutlineCacheMemMonitor &iCacheMemMon;
       
   307     RHeap *iHeap;
       
   308     RPointerArray<CFontTableCacheItem> iCacheItems;
       
   309     };
       
   310 
       
   311 
       
   312 class TUnhintedOutlineCache;
       
   313 
       
   314 class TUnhintedOutlineId 
       
   315     {
       
   316 public:
       
   317     TUnhintedOutlineId(TUid aFileUid, TInt aFaceIndex, TUint aId);
       
   318     TUid iFileUid;
       
   319     TInt iFaceIndex;
       
   320     TUint iId;
       
   321     };
       
   322 
       
   323 class COutlineCacheItem {
       
   324 friend class CUnhintedOutlineCache;
       
   325 friend class CHintedOutlineCache;
       
   326     
       
   327 public:
       
   328     COutlineCacheItem(TInt aOffset, TInt aLength);
       
   329     ~COutlineCacheItem() ;
       
   330 
       
   331     TInt DecRefCount(TInt aSessionHandle);
       
   332     TInt IncRefCount(TInt aSessionHandle);
       
   333 #ifdef _DEBUG
       
   334     void SetUser(RPointerArray<TCacheUserInfo> users)
       
   335         {
       
   336         TInt len = users.Count();
       
   337         for( TInt i = 0; i < len ; i++ )
       
   338             {
       
   339             iUsers.Append(users[i]);
       
   340             }
       
   341         }    
       
   342 #endif
       
   343  
       
   344 private:
       
   345     TInt FindUser(TInt aSessionHandle, TInt *id);
       
   346         
       
   347 
       
   348     TInt iOffset;
       
   349     TInt iLength;
       
   350     RPointerArray<TCacheUserInfo> iUsers;
       
   351 };    
       
   352 
       
   353 class CUnhintedOutlineCache {
       
   354 public:
       
   355     CUnhintedOutlineCache(RHeap* aHeap, TFontTableGlyphOutlineCacheMemMonitor& aMon);
       
   356     TInt Find(const TUnhintedOutlineId &aOutlineId, TAny*& aData, TInt& aLength);
       
   357     TInt IncRefCount(const TUnhintedOutlineId& aOutlineId, TInt aSessionHandle);
       
   358     TInt DecRefCount(const TUnhintedOutlineId& aOutlineId, TInt aSessionHandle);
       
   359     TInt CacheUnhintedOutline(const TUnhintedOutlineId& aOutlineId, 
       
   360             TAny * const aData, const TInt aLength, TAny*& aOutline, TInt &aLen);
       
   361     TInt CleanupCacheOnOpenFontFileRemoval(COpenFontFile* aFontFile);
       
   362     TInt CleanupCacheOnFbsSessionTermination(TInt aSessionHandle);
       
   363 #ifdef _DEBUG
       
   364     TInt GetCacheState(const char *func);
       
   365 #endif
       
   366     ~CUnhintedOutlineCache();
       
   367     
       
   368 #ifdef _DEBUG
       
   369     void SetUnHintedItem(TUnhintedOutlineId id, COutlineCacheItem* item)
       
   370         {
       
   371         iItemIdMap.Insert(id, item);
       
   372         }
       
   373 #endif
       
   374     
       
   375 private:
       
   376     // disallow assignment and copy-construction
       
   377     CUnhintedOutlineCache(const CUnhintedOutlineCache &); 
       
   378     CUnhintedOutlineCache& operator =(const CUnhintedOutlineCache &);
       
   379     
       
   380     static TUint32 IdHash(const TUnhintedOutlineId& aOutlineId);
       
   381     static TBool IdIdentity(const TUnhintedOutlineId& id1, const TUnhintedOutlineId& id2);
       
   382     
       
   383     TFontTableGlyphOutlineCacheMemMonitor& iCacheMemMon;
       
   384     RHeap* iHeap; 
       
   385     RHashMap<TUnhintedOutlineId, COutlineCacheItem*> iItemIdMap; // map the identity to an index in 'iCacheItems'.
       
   386 };
       
   387 
       
   388 class CHintedOutlineCache;
       
   389 
       
   390 class THintedOutlineId 
       
   391     {
       
   392 public:
       
   393     THintedOutlineId(COpenFont* aFont, TUint aId);
       
   394     COpenFont *iFont;
       
   395     TUint iId;
       
   396     };
       
   397 
       
   398 
       
   399 class CHintedOutlineCache {
       
   400 public:
       
   401     CHintedOutlineCache(RHeap* aHeap, TFontTableGlyphOutlineCacheMemMonitor& aMon);
       
   402     TInt Find(const THintedOutlineId& aOutlineId, TAny*& aData, TInt& aLength);
       
   403     TInt IncRefCount(const THintedOutlineId& aOutlineId, TInt aSessionHandle);
       
   404     TInt DecRefCount(const THintedOutlineId& aOutlineId, TInt aSessionHandle);
       
   405     TInt CacheHintedOutline(const THintedOutlineId& aOutlineId, 
       
   406             TAny* aData, TInt aLength, TAny*& aOutline, TInt& aLen);
       
   407     TInt CleanupCacheOnOpenFontRemoval(COpenFont* aFont);
       
   408     TInt CleanupCacheOnFbsSessionTermination(TInt aSessionHandle);
       
   409 #ifdef _DEBUG
       
   410     TInt GetCacheState(const char *func);
       
   411     void SetHintedItem(THintedOutlineId id, COutlineCacheItem* item)
       
   412         {
       
   413         iItemIdMap.Insert(id, item);
       
   414         }
       
   415     RHashMap<THintedOutlineId, COutlineCacheItem*> GetHintedMap()
       
   416     {
       
   417     return iItemIdMap;
       
   418     }
       
   419 #endif
       
   420     
       
   421 private:
       
   422     // disallow assignment and copy-construction
       
   423     CHintedOutlineCache(const CHintedOutlineCache &); 
       
   424     CHintedOutlineCache& operator =(const CHintedOutlineCache &);
       
   425     static TUint32 IdHash(const THintedOutlineId& aOutlineId);
       
   426     static TBool IdIdentity(const THintedOutlineId& id1, const THintedOutlineId& id2);
       
   427         
       
   428     TFontTableGlyphOutlineCacheMemMonitor& iCacheMemMon;
       
   429     RHeap* iHeap; 
       
   430     RHashMap<THintedOutlineId, COutlineCacheItem*> iItemIdMap; // map the identity to an index in 'iCacheItems'.
       
   431     };
       
   432 
       
   433 
   213 
   434 // inline functions
   214 // inline functions
   435 inline COpenFontSessionCacheEntry::COpenFontSessionCacheEntry(const COpenFont* aFont, TInt aCode, TInt aGlyphIndex,const TOpenFontCharMetrics& aMetrics) :
   215 inline COpenFontSessionCacheEntry::COpenFontSessionCacheEntry(const COpenFont* aFont, TInt aCode, TInt aGlyphIndex,const TOpenFontCharMetrics& aMetrics) :
   436     COpenFontGlyph(aCode, aGlyphIndex, aMetrics)
   216     COpenFontGlyph(aCode, aGlyphIndex, aMetrics)
   437     {
   217     {