fontservices/fontstore/inc/openfontsprivate.h
branchRCL_3
changeset 17 336bee5c2d35
parent 16 748ec5531811
child 18 dd58c6eee052
equal deleted inserted replaced
16:748ec5531811 17:336bee5c2d35
    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 <hextree.h>
    22 #include <hextree.h>
    23 #include <e32hashtab.h>
       
    24 
    23 
    25 class COpenFontShaperCacheEntry;
    24 class COpenFontShaperCacheEntry;
    26 
    25 
    27 /* MSB is set to indicate a glyph code rather than a unicode value
    26 /* MSB is set to indicate a glyph code rather than a unicode value
    28    This is used for extracting the code value */
    27    This is used for extracting the code value */
    85     void SetAt(TInt aIndex, T* aEntry);
    84     void SetAt(TInt aIndex, T* aEntry);
    86 private:
    85 private:
    87     TInt iOffset;
    86     TInt iOffset;
    88     TInt iCount;
    87     TInt iCount;
    89     };
    88     };
    90 
       
    91 
    89 
    92 /**
    90 /**
    93  The per-font glyph cache. For now, just the members that used to be directly in
    91  The per-font glyph cache. For now, just the members that used to be directly in
    94  COpenFont. Now it is a private class it can be elaborated to do character-to-glyph-index
    92  COpenFont. Now it is a private class it can be elaborated to do character-to-glyph-index
    95  mapping when that is needed.
    93  mapping when that is needed.
   133 	inline const COpenFont* Font()const;
   131 	inline const COpenFont* Font()const;
   134 
   132 
   135 private:
   133 private:
   136 	inline COpenFontSessionCacheEntry(const COpenFont* aFont, TInt aCode, TInt aGlyphIndex, const TOpenFontCharMetrics& aMetrics);
   134 	inline COpenFontSessionCacheEntry(const COpenFont* aFont, TInt aCode, TInt aGlyphIndex, const TOpenFontCharMetrics& aMetrics);
   137 	~COpenFontSessionCacheEntry();
   135 	~COpenFontSessionCacheEntry();
       
   136 public:
       
   137     TInt iLastAccess;               // serial number of the last access to the glyph
   138 
   138 
   139 private: 
   139 private: 
   140     TInt iFontOffset;          // offset of the font that contains this glyph, (not owned by this class!)    
   140     TInt iFontOffset;          // offset of the font that contains this glyph, (not owned by this class!)    
   141 	};
   141 	};
   142 
   142 
   146 
   146 
   147  @internalComponent
   147  @internalComponent
   148  */
   148  */
   149 class COpenFontSessionCache
   149 class COpenFontSessionCache
   150     {
   150     {
   151 	friend class COpenFontSessionCacheList;
       
   152 public:
   151 public:
   153     static COpenFontSessionCache* NewL(RHeap* aHeap, TInt aSessionHandle, TInt aEntries);
   152     static COpenFontSessionCache* NewL(RHeap* aHeap, TInt aSessionHandle, TInt aEntries);
   154     void Delete(RHeap* aHeap);
   153     void Delete(RHeap* aHeap);
   155     
   154     
   156     TInt SessionHandle() { return iSessionHandle; }
   155     TInt SessionHandle() { return iSessionHandle; }
   157     const COpenFontGlyph* Glyph(const COpenFont* aFont, TInt aCode, TInt& aIndex) const;
   156     const COpenFontGlyph* Glyph(const COpenFont* aFont, TInt aCode, TInt& aIndex);
   158     void Insert(RHeap* aHeap, COpenFontSessionCacheEntry* aEntry, TInt aIndex);
   157     void Insert(RHeap* aHeap, COpenFontSessionCacheEntry* aEntry, TInt aIndex);
   159     
   158     
   160 private:
   159 private:
   161     COpenFontSessionCache(TInt aSessionHandle);
   160     COpenFontSessionCache(TInt aSessionHandle);
   162     ~COpenFontSessionCache();
   161     ~COpenFontSessionCache();
   163 private:
   162 public:
   164     TInt iSessionHandle;
   163     TInt iSessionHandle;    
   165     TInt64 iRandomSeed;
   164     TInt iLastAccess;
   166     ROffsetArray<COpenFontSessionCacheEntry> iEntryArray;
   165     ROffsetArray<COpenFontSessionCacheEntry> iEntryArray;
   167     };
       
   168 
       
   169 
       
   170 class TFontTableGlyphOutlineCacheMemMonitor
       
   171     {
       
   172 public:
       
   173     TFontTableGlyphOutlineCacheMemMonitor();
       
   174     void Inc(TInt aBytes);
       
   175     void Dec(TInt aBytes);
       
   176     TInt GetMemUsage();
       
   177 private:
       
   178     TInt iBytes;
       
   179     };
       
   180 
       
   181 struct TCacheUserInfo {
       
   182     TInt iSessionHandle;
       
   183     TInt iRefCount;
       
   184     TCacheUserInfo(TInt aSessionHandle, TInt aRefCount = 0): 
       
   185             iSessionHandle(aSessionHandle), iRefCount(aRefCount) { } 
       
   186 };
       
   187 
       
   188 class CFontTableCache;
       
   189 
       
   190 class CFontTableCacheItem
       
   191     {
       
   192 friend class CFontTableCache ;
       
   193 
       
   194 public:
       
   195     CFontTableCacheItem(TUid &aFileUid, const TUint32 aTag, 
       
   196             TInt aOffset, TInt aLength);
       
   197     ~CFontTableCacheItem(); 
       
   198 
       
   199     TInt DecRefCount(TInt aSessionHandle);
       
   200     TInt IncRefCount(TInt aSessionHandle);
       
   201 
       
   202     TBool HasOutstandingRefCount();
       
   203     TInt FindUser(TInt aSessionHandle, TInt *id);
       
   204     
       
   205 #ifdef _DEBUG
       
   206     void SetUser(RPointerArray<TCacheUserInfo> users)
       
   207         {
       
   208         TInt len = users.Count();
       
   209         for( TInt i = 0; i < len ; i++ )
       
   210             {
       
   211             iUsers.Append(users[i]);
       
   212             }
       
   213         }    
       
   214 #endif
       
   215     
       
   216 private:
       
   217     CFontTableCacheItem(const CFontTableCacheItem &); // disallow copy construction.
       
   218     CFontTableCacheItem& operator =(const CFontTableCacheItem &); // disallow assignment.
       
   219     
       
   220     TUid iFileUid; 
       
   221     TUint32 iTag; 
       
   222  
       
   223 
       
   224     TInt iOffset;
       
   225     TInt iLength; 
       
   226     RPointerArray<TCacheUserInfo> iUsers;
       
   227     }; 
       
   228 
       
   229 
       
   230 class CFontTableCache 
       
   231     {
       
   232 public:
       
   233     CFontTableCache(RHeap* aHeap, TFontTableGlyphOutlineCacheMemMonitor& aMon);
       
   234     ~CFontTableCache();
       
   235     TInt Append(TUid aFileUid, TUint32 aTag, 
       
   236             TAny*& aContent, TInt aLength);
       
   237     TInt Find(TUid aFileUid, TUint32 aTag, TAny*& aContent, TInt& aLength, TInt* id);
       
   238     TInt IncRefCount(TUid FileUid, TUint32 aTag, TInt aSessionHandle);
       
   239     TInt DecRefCount(TUid aFileUid, TUint32 aTag, TInt aSessionHandle);
       
   240     TBool HasOutstandingRefCount();
       
   241     TBool HasOutstandingRefCountWithUid(TUid aFileUid);  
       
   242     void CleanupCacheOnFbsSessionTermination(TInt aSessionHandle);
       
   243     void CleanupCacheOnOpenFontFileRemoval(COpenFontFile*);
       
   244 #ifdef _DEBUG    
       
   245     void SetFontItem(RPointerArray<CFontTableCacheItem> cacheItems)
       
   246         {
       
   247         TInt len = cacheItems.Count();
       
   248         for(TInt i = 0; i < len; i++)
       
   249             {
       
   250             iCacheItems.Append(cacheItems[i]);
       
   251             }
       
   252         }
       
   253 #endif   
       
   254     
       
   255 private:
       
   256     CFontTableCache(const CFontTableCache &); // no copy construction.
       
   257     CFontTableCache& operator =(const CFontTableCache &); // no assignment.
       
   258 #ifdef _DEBUG
       
   259     TInt GetCacheState(const char *func);
       
   260 #endif
       
   261     
       
   262     TFontTableGlyphOutlineCacheMemMonitor &iCacheMemMon;
       
   263     RHeap *iHeap;
       
   264     RPointerArray<CFontTableCacheItem> iCacheItems;
       
   265     };
       
   266 
       
   267 
       
   268 class TUnhintedOutlineCache;
       
   269 
       
   270 class TUnhintedOutlineId 
       
   271     {
       
   272 public:
       
   273     TUnhintedOutlineId(TUid aFileUid, TInt aFaceIndex, TUint aId);
       
   274     TUid iFileUid;
       
   275     TInt iFaceIndex;
       
   276     TUint iId;
       
   277     };
       
   278 
       
   279 class COutlineCacheItem {
       
   280 friend class CUnhintedOutlineCache;
       
   281 friend class CHintedOutlineCache;
       
   282     
       
   283 public:
       
   284     COutlineCacheItem(TInt aOffset, TInt aLength);
       
   285     ~COutlineCacheItem() ;
       
   286 
       
   287     TInt DecRefCount(TInt aSessionHandle);
       
   288     TInt IncRefCount(TInt aSessionHandle);
       
   289 #ifdef _DEBUG
       
   290     void SetUser(RPointerArray<TCacheUserInfo> users)
       
   291         {
       
   292         TInt len = users.Count();
       
   293         for( TInt i = 0; i < len ; i++ )
       
   294             {
       
   295             iUsers.Append(users[i]);
       
   296             }
       
   297         }    
       
   298 #endif
       
   299  
       
   300 private:
       
   301     TInt FindUser(TInt aSessionHandle, TInt *id);
       
   302         
       
   303 
       
   304     TInt iOffset;
       
   305     TInt iLength;
       
   306     RPointerArray<TCacheUserInfo> iUsers;
       
   307 };    
       
   308 
       
   309 class CUnhintedOutlineCache {
       
   310 public:
       
   311     CUnhintedOutlineCache(RHeap* aHeap, TFontTableGlyphOutlineCacheMemMonitor& aMon);
       
   312     TInt Find(const TUnhintedOutlineId &aOutlineId, TAny*& aData, TInt& aLength);
       
   313     TInt IncRefCount(const TUnhintedOutlineId& aOutlineId, TInt aSessionHandle);
       
   314     TInt DecRefCount(const TUnhintedOutlineId& aOutlineId, TInt aSessionHandle);
       
   315     TInt CacheUnhintedOutline(const TUnhintedOutlineId& aOutlineId, 
       
   316             TAny * const aData, const TInt aLength, TAny*& aOutline, TInt &aLen);
       
   317     TInt CleanupCacheOnOpenFontFileRemoval(COpenFontFile* aFontFile);
       
   318     TInt CleanupCacheOnFbsSessionTermination(TInt aSessionHandle);
       
   319 #ifdef _DEBUG
       
   320     TInt GetCacheState(const char *func);
       
   321 #endif
       
   322     ~CUnhintedOutlineCache();
       
   323     
       
   324 #ifdef _DEBUG
       
   325     void SetUnHintedItem(TUnhintedOutlineId id, COutlineCacheItem* item)
       
   326         {
       
   327         iItemIdMap.Insert(id, item);
       
   328         }
       
   329 #endif
       
   330     
       
   331 private:
       
   332     // disallow assignment and copy-construction
       
   333     CUnhintedOutlineCache(const CUnhintedOutlineCache &); 
       
   334     CUnhintedOutlineCache& operator =(const CUnhintedOutlineCache &);
       
   335     
       
   336     static TUint32 IdHash(const TUnhintedOutlineId& aOutlineId);
       
   337     static TBool IdIdentity(const TUnhintedOutlineId& id1, const TUnhintedOutlineId& id2);
       
   338     
       
   339     TFontTableGlyphOutlineCacheMemMonitor& iCacheMemMon;
       
   340     RHeap* iHeap; 
       
   341     RHashMap<TUnhintedOutlineId, COutlineCacheItem*> iItemIdMap; // map the identity to an index in 'iCacheItems'.
       
   342 };
       
   343 
       
   344 class CHintedOutlineCache;
       
   345 
       
   346 class THintedOutlineId 
       
   347     {
       
   348 public:
       
   349     THintedOutlineId(COpenFont* aFont, TUint aId);
       
   350     COpenFont *iFont;
       
   351     TUint iId;
       
   352     };
       
   353 
       
   354 
       
   355 class CHintedOutlineCache {
       
   356 public:
       
   357     CHintedOutlineCache(RHeap* aHeap, TFontTableGlyphOutlineCacheMemMonitor& aMon);
       
   358     TInt Find(const THintedOutlineId& aOutlineId, TAny*& aData, TInt& aLength);
       
   359     TInt IncRefCount(const THintedOutlineId& aOutlineId, TInt aSessionHandle);
       
   360     TInt DecRefCount(const THintedOutlineId& aOutlineId, TInt aSessionHandle);
       
   361     TInt CacheHintedOutline(const THintedOutlineId& aOutlineId, 
       
   362             TAny* aData, TInt aLength, TAny*& aOutline, TInt& aLen);
       
   363     TInt CleanupCacheOnOpenFontRemoval(COpenFont* aFont);
       
   364     TInt CleanupCacheOnFbsSessionTermination(TInt aSessionHandle);
       
   365 #ifdef _DEBUG
       
   366     TInt GetCacheState(const char *func);
       
   367     void SetHintedItem(THintedOutlineId id, COutlineCacheItem* item)
       
   368         {
       
   369         iItemIdMap.Insert(id, item);
       
   370         }
       
   371     RHashMap<THintedOutlineId, COutlineCacheItem*> GetHintedMap()
       
   372     {
       
   373     return iItemIdMap;
       
   374     }
       
   375 #endif
       
   376     
       
   377 private:
       
   378     // disallow assignment and copy-construction
       
   379     CHintedOutlineCache(const CHintedOutlineCache &); 
       
   380     CHintedOutlineCache& operator =(const CHintedOutlineCache &);
       
   381     static TUint32 IdHash(const THintedOutlineId& aOutlineId);
       
   382     static TBool IdIdentity(const THintedOutlineId& id1, const THintedOutlineId& id2);
       
   383         
       
   384     TFontTableGlyphOutlineCacheMemMonitor& iCacheMemMon;
       
   385     RHeap* iHeap; 
       
   386     RHashMap<THintedOutlineId, COutlineCacheItem*> iItemIdMap; // map the identity to an index in 'iCacheItems'.
       
   387     };
   166     };
   388 
   167 
   389 
   168 
   390 // inline functions
   169 // inline functions
   391 
   170