First public contribution.
1 // Copyright (c) 1995-2010 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
22 #include <sgresource/sgimage.h>
25 #include "FbsMessage.H"
26 #include "glyphatlas.h"
29 class CFbsBackgroundCompression;
30 class CFbsBackgroundCompressionQueueElement;
31 class TOpenFontGlyphData;
34 NONSHARABLE_CLASS(CFontObject): public CObject
40 CFontObject(CFontStore* aFontStore, CGlyphAtlas* aGlyphAtlas);
43 CBitmapFont* iAddressPointer;
44 CFontStore* iFontStore;
46 CGlyphAtlas* iGlyphAtlas;
49 NONSHARABLE_CLASS(CBitmapObject): public CObject
51 Provides reference counting facilities for bitmaps managed by CFbTop.
55 friend class CFbsBackgroundCompression;
56 friend class CFbsBackgroundCompressionQueueElement;
58 CBitmapObject(CFbTop& aFbTop, CBitwiseBitmap* aBmp);
59 void ConstructL(TBool aReplacement);
61 static CBitmapObject* NewL(CFbTop& aFbTop, CBitwiseBitmap* aBmp, TBool aReplacement);
63 inline CBitwiseBitmap* Address() const;
64 inline TInt Handle() const;
65 inline CBitmapObject* CleanBitmap() const;
66 inline TBool IsInCompressionQueue() const;
67 void SetCleanBitmap(CBitmapObject* aNewBmpObj);
69 static TInt Compare(const CBitmapObject& aBmpObj1, const CBitmapObject& aBmpObj2);
70 static TInt Compare(const TInt* aHandle, const CBitmapObject& aBmpObj);
74 CBitwiseBitmap* iAddressPointer;
76 CBitmapObject* iCleanBitmap;
77 CFbsBackgroundCompressionQueueElement* iCompressionQueueElement;
80 NONSHARABLE_CLASS(CSharedBitmapObject): public CBitmapObject
82 Provides reference counting facilities for shared bitmaps managed by CFbTop.
83 Shared bitmaps are only loaded once. They are uniquely identified by the
84 combination of the filename, bitmap ID and last modified time of the file.
88 friend class CHashMap;
90 CSharedBitmapObject(CFbTop& aFbTop, CBitwiseBitmap* aBmp, TDesC* aKey);
91 void ConstructL(TUint aHash);
93 static CSharedBitmapObject* NewL(CFbTop& aFbTop, CBitwiseBitmap* aBmp, TDesC* aKey, TUint aHash);
94 ~CSharedBitmapObject();
95 static HBufC* KeyLC(const TDesC& aFileName, TInt aId, const TTime& aModTime);
98 mutable CSharedBitmapObject* iNext; // Next object in a linked list
101 NONSHARABLE_CLASS(CFontBitmapServer): public CPolicyServer
108 ~CFontBitmapServer();
109 static CFontBitmapServer* NewL();
110 CSession2* NewSessionL(const TVersion& aVersion, const RMessage2& aMessage) const;
113 void ProcMessage(const RMessage2& aMessage, TInt aSession, TInt& aRet);
115 void ProcMessage(const RMessage2& aMessage, TInt aSession);
117 CFbTop* TopLevelStore();
121 void GetHeapSizesL(const RMessage2& aMessage);
122 TInt HandleMesgTypefaceSupport(const RMessage2& aMessage, TBool& aClientPanicRequired);
123 TInt HandleMesgFontHeight(const RMessage2& aMessage, TBool aInTwips);
127 CFbTop* iTopLevelStore;
143 NONSHARABLE_CLASS(TFbClientHelper): public TDblQueLink
149 inline TFbClientHelper(CFbClient& aClient);
153 RMessagePtr2 iMessage;
157 NONSHARABLE_CLASS(CFbClient): public CSession2
163 static CFbClient* NewL(RHeap* aHeap);
165 void Init(TUint aConnectionHandle);
167 CFontBitmapServer* FontBitmapServer();
168 CFbTop* TopLevelStore();
169 void CopyFontInfo(CFontObject* aFontObjPtr,TInt aHandle,TFontInfo& aFontInfo);
170 void ServiceL(const RMessage2& aMessage);
171 void ProcFontMessage(const RMessage2& aMessage);
172 void ProcBitmapMessage(const RMessage2& aMessage);
173 void NotifyDirtyBitmap(CBitmapObject& aBmpObj);
174 void AddFontFileIndexL(TUid aId);
175 void RemoveFontFileIndex(TUid aId);
176 void Disconnect(const RMessage2 &aMessage);
178 void ProcMemMessage (const RMessage2& aMessage);
179 void ProcAtlasMessage (const RMessage2& aMessage);
183 CFbClient(RHeap* aHeap);
184 TInt HandleMesgFontDuplicate(const RMessage2& aMessage, TBool& aPanicRequired);
185 TInt HandleMesgGetNearestFont(const RMessage2& aMessage, TBool& aPanicRequired);
186 TInt HandleMesgGetFontById(const RMessage2& aMessage, TBool& aPanicRequired);
187 TInt CopyFontInfoIntoReturnMessage(const RMessage2& aMessage, TBool& aPanicRequired, CFontObject* aFontObj, TInt iWritePosition);
188 TInt HandleMesgAddOrInstallFontFile(const RMessage2& aMessage, TBool& aPanicRequired);
189 TInt HandleMesgRemoveFontFile(const RMessage2& aMessage);
190 TInt HandleMesgRasterize(const RMessage2& aMessage, TBool& aPanicRequired);
191 TInt HandleMesgFaceAttrib(const RMessage2& aMessage, TBool& aPanicRequired);
192 TInt HandleMesgHasCharacter(const RMessage2& aMessage, TBool& aPanicRequired);
193 TInt HandleMesgShapeText(const RMessage2& aMessage, TBool& aPanicRequired);
194 TInt HandleMesgShapeDelete(const RMessage2& aMessage, TBool& aPanicRequired);
195 TInt HandleMesgGetFontTable(const RMessage2& aMessage, TBool& aPanicRequired);
196 TInt HandleMesgGetGlyphOutline(const RMessage2& aMessage, TBool& aPanicRequired);
197 TInt HandleMesgReleaseGlyphOutline(const RMessage2& aMessage, TBool& aPanicRequired);
198 TInt HandleMesgReleaseFontTable(const RMessage2& aMessage, TBool& aPanicRequired);
199 TInt HandleMesgGetGlyphs(const RMessage2& aMessage, TBool& aPanicRequired);
200 TInt HandleMesgGetGlyphMetrics(const RMessage2& aMessage, TBool& aPanicRequired);
201 TInt HandleMesgOogmStatus(const RMessage2& aMessage);
202 void HandleMesgGlyphCacheMetrics(const RMessage2& aMessage);
205 TUint iConnectionHandle;
208 CArrayFixFlat<TFontFileIndex>* iFontFileIndex;
209 RHeap* iHeap; // the heap containing iOpenFontGlyphData
210 TOpenFontGlyphData* iOpenFontGlyphData; // the metrics and bitmap, in shared memory, of the last character rasterized
211 TInt iSessionHandle; // used to identify client-specific glyph caches for the new font system
212 TFbClientHelper* iHelper; // used to notify client of any bitmap becoming dirty
215 RBuf16 iTextToShape; // buffer used to hold incoming text that needs shaping
216 RArray<RSgImage> iGlyphImagesInTransit; // last glyph images retrieved from glyph atlas
218 TBool iOwnHeapCheck; //for the process heap - current state
219 TBool iHeapCheck; //for iHeap - current state
220 TBool iOwnHeapCheckFlip; //for the process heap - to switch the current state
221 TBool iHeapCheckFlip; //for iHeap - used to switch the current state
222 TInt iOwnHeapFailNumber; //the number for the memory fail to be set to. -1: don't set.
223 TInt iSharedHeapFailNumber; //the number for the memory fail to be set to. -1 don't set
225 TInt iFontDuplicateToFail; //when this is set calls to HandleMesgFontDuplicate() fail for the class.
229 NONSHARABLE_CLASS(CFbActiveScheduler): public CActiveScheduler
235 CFbActiveScheduler();
236 virtual void Error(TInt anError) const;
241 NONSHARABLE_CLASS(CHashMap): public CBase
243 A HashMap data structure for storing pointers to CSharedBitmapObjects.
244 Provides fast insert/lookup/removal based on a key.
252 void Insert(CSharedBitmapObject& aBmpObj, TUint aHash);
253 CSharedBitmapObject* Lookup(const TDesC& aKey, TUint aHash) const;
254 TInt Remove(const CSharedBitmapObject& aBmpObj);
255 static TUint Hash(const TDesC16& aKey);
258 CSharedBitmapObject* iHashTable[1<<KFBSERVSharedBitmapHashTableSizeInBits]; // Array of pointers to singularly linked lists. Linked list elements are CSharedBitmapObjects.
264 IMPORT_C extern const TInt KFbServSharedHeapMaxSize;
265 IMPORT_C extern const TInt KFbServGlyphAtlasCacheLimit;
268 NONSHARABLE_CLASS(CFbTop): public CBase
273 friend class CFontBitmapServer;
274 friend class CBitmapObject;
275 friend class CSharedBitmapObject;
278 static CFbTop* NewL();
279 TInt GetNearestFont(CFontObject*& aFontObjPtr, TFbsMessage aMessage, const TFontSpec& aFontSpec, TInt aMaxHeight = 0);
280 TInt GetFontById(CFontObject*& aFontObjPtr,TUid aUid,const TAlgStyle& aAlgStyle);
281 CBitmapObject* CreateBitmapL(const TSize& aSize, TDisplayMode aDispMode, TUid aUid, TBool aReplacement, TInt aDataSize = 0);
282 CBitmapObject* LoadBitmapL(const TDesC& aFilename, TInt32 aId, TUint aFileOffset,RFile* aFile, TInt aSessionHandle);
283 CSharedBitmapObject* ShareBitmapL(TDes& aFilename, TInt32 aId, TUint aFileOffset,RFile* aFile, TInt aSessionHandle);
284 TInt GetCleanBitmap(CBitmapObject*& aBmpObjPtr);
285 CBitmapObject* FindBitmap(TInt aHandle);
286 TBool ValidFontHandle(TInt aHandle);
287 CFontStore* FontStore() const;
289 CChunkPile* Pile() const;
290 TInt HeapBase() const;
291 void SetFontNameAliasL(const RMessage2& aMessage);
292 void SetDefaultLanguageForMetrics(const RMessage2& aMessage);
293 inline CFbsBackgroundCompression* BackgroundCompression() const;
294 void CloseFileStores(TInt aSessionHandle);
295 void SetSystemDefaultTypefaceName(const TDesC& aFontTypefaceName);
296 TInt GetAllBitmapHandles(const RMessage2& aMessage) const;
297 inline RFs& FileSession();
298 void AddClientHelper(TFbClientHelper& aHelper);
299 void NotifyDirtyBitmap(CBitmapObject& aBmpObj, CFbClient* aClient);
300 TInt BitmapConUniqueID() const;
301 TInt FontConUniqueID() const;
302 CGlyphAtlas* GlyphAtlas() const;
306 CBitwiseBitmap* DoLoadBitmapLC(const TDesC& aFilename, TInt32 aId, TUint aFileOffset, RFile* aFile, TInt aSessionHandle);
307 void LoadOpenFontLibraries();
308 void SafeInstallOfRasterizerL(TUid aInterfaceImplUid);
309 TInt FindFontNameAlias(const TDesC& aAlias);
310 void LoadShaperFactories();
311 void SafeInstallOfShaperFactoryL(TUid aInterfaceImplUid);
312 TInt GetFontObjectFromFont(CFontObject*& aFontObjPtr, CFont* aFont);
313 TInt GetNearestNonAliasedFont(CFont*& aFont, TFbsMessage aMessage, const TFontSpec& aFontSpec, TInt aMaxHeight);
316 CFontStore* iFontStore;
317 CObjectCon* iBitmapCon;
318 CObjectCon* iFontCon;
319 CObjectConIx* iConIx;
322 RChunk iLargeBitmapChunk;
323 RMutex iDebugMutex; // used only in builds with SYMBIAN_DEBUG_FBS_LOCKHEAP defined
325 RPointerArray<HBufC> iFontNameAlias;
326 RPointerArray<CBitmapObject> iBitmapObjectIndex;
327 CHashMap iSharedBitmapObjectHashMap;
328 CFbTopStreamIdCache* iMBMCache;
329 TLanguage iDefaultLanguageForMetrics;
330 CFbsBackgroundCompression* iBackgroundCompression;
331 TBuf<KMaxTypefaceNameLength> iSystemDefaultFontTypefaceName;
332 TDblQue<TFbClientHelper> iClientHelpers;
333 TInt64 iNextAvailableSerialNumber;
334 CGlyphAtlas* iGlyphAtlas;
337 inline CBitwiseBitmap* CBitmapObject::Address() const
339 return iAddressPointer;
342 inline TInt CBitmapObject::Handle() const
347 inline CBitmapObject* CBitmapObject::CleanBitmap() const
352 inline TBool CBitmapObject::IsInCompressionQueue() const
354 return iCompressionQueueElement != NULL;
357 inline TFbClientHelper::TFbClientHelper(CFbClient& aClient)
358 : iClient(aClient), iDirty(EFalse)
361 inline CFbsBackgroundCompression* CFbTop::BackgroundCompression() const
363 __ASSERT_DEBUG(iBackgroundCompression != NULL, User::Invariant());
364 return iBackgroundCompression;
368 It returns the file session handle.
372 inline RFs& CFbTop::FileSession()