fbs/fontandbitmapserver/sfbs/SERVER.H
changeset 0 5d03bc08d59c
child 36 01a6848ebfd7
child 163 bbf46f59e123
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 1995-2009 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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef __FBSERV_H__
       
    17 #define __FBSERV_H__
       
    18 
       
    19 #include <e32base.h>
       
    20 #include <f32file.h>
       
    21 #include <fbs.h>
       
    22 #include "UTILS.H"
       
    23 #include "FBSMBMC.H"
       
    24 #include "fbsmessage.h"
       
    25 
       
    26 class CFbTop;
       
    27 class CFbsBackgroundCompression;
       
    28 class CFbsBackgroundCompressionQueueElement;
       
    29 class TOpenFontGlyphData;
       
    30 
       
    31 NONSHARABLE_CLASS(CFontObject): public CObject
       
    32 /**
       
    33 @internalComponent
       
    34 */
       
    35 	{
       
    36 public:
       
    37 	CFontObject(CFontStore* aFontStore);
       
    38 	~CFontObject();
       
    39 public:
       
    40 	CBitmapFont* iAddressPointer;
       
    41 	CFontStore* iFontStore;
       
    42 	TInt iHeightInTwips;
       
    43 	};
       
    44 
       
    45 NONSHARABLE_CLASS(CBitmapObject): public CObject
       
    46 /**
       
    47 Provides reference counting facilities for bitmaps managed by CFbTop.
       
    48 @internalComponent
       
    49 */
       
    50 	{
       
    51 	friend class CFbsBackgroundCompression;
       
    52 	friend class CFbsBackgroundCompressionQueueElement;
       
    53 protected:
       
    54 	CBitmapObject(CFbTop& aFbTop, CBitwiseBitmap* aBmp);
       
    55 	void ConstructL(TBool aReplacement);
       
    56 public:
       
    57 	static CBitmapObject* NewL(CFbTop& aFbTop, CBitwiseBitmap* aBmp, TBool aReplacement);
       
    58 	~CBitmapObject();
       
    59 	inline CBitwiseBitmap* Address() const;
       
    60 	inline TInt Handle() const;
       
    61 	inline CBitmapObject* CleanBitmap() const;
       
    62 	inline TBool IsInCompressionQueue() const;
       
    63 	void SetCleanBitmap(CBitmapObject* aNewBmpObj);
       
    64 	virtual void Close();
       
    65 	static TInt Compare(const CBitmapObject& aBmpObj1, const CBitmapObject& aBmpObj2);
       
    66 	static TInt Compare(const TInt* aHandle, const CBitmapObject& aBmpObj);
       
    67 protected:
       
    68 	CFbTop* iFbTop;
       
    69 private:
       
    70 	CBitwiseBitmap* iAddressPointer;
       
    71 	TInt iHandle;
       
    72 	CBitmapObject* iCleanBitmap;
       
    73 	CFbsBackgroundCompressionQueueElement* iCompressionQueueElement;
       
    74 	};
       
    75 
       
    76 NONSHARABLE_CLASS(CSharedBitmapObject): public CBitmapObject
       
    77 /**
       
    78 Provides reference counting facilities for shared bitmaps managed by CFbTop.
       
    79 Shared bitmaps are only loaded once.  They are uniquely identified by the
       
    80 combination of the filename, bitmap ID and last modified time of the file.
       
    81 @internalComponent
       
    82 */
       
    83 	{
       
    84 friend class CHashMap;
       
    85 private:
       
    86 	CSharedBitmapObject(CFbTop& aFbTop, CBitwiseBitmap* aBmp, TDesC* aKey);
       
    87 	void ConstructL(TUint aHash);
       
    88 public:
       
    89 	static CSharedBitmapObject* NewL(CFbTop& aFbTop, CBitwiseBitmap* aBmp, TDesC* aKey, TUint aHash);
       
    90 	~CSharedBitmapObject();
       
    91 	static HBufC* KeyLC(const TDesC& aFileName, TInt aId, const TTime& aModTime);
       
    92 private:
       
    93 	TDesC* iKey;
       
    94 	mutable CSharedBitmapObject* iNext;    // Next object in a linked list
       
    95 	};
       
    96 
       
    97 NONSHARABLE_CLASS(CFontBitmapServer): public CPolicyServer
       
    98 /**
       
    99 @internalComponent
       
   100 */
       
   101 	{
       
   102 public:
       
   103 	CFontBitmapServer();
       
   104 	~CFontBitmapServer();
       
   105 	static CFontBitmapServer* NewL();
       
   106 	CSession2* NewSessionL(const TVersion& aVersion, const RMessage2& aMessage) const;
       
   107 	TInt Init();
       
   108 #ifdef _DEBUG
       
   109 	void ProcMessage(const RMessage2& aMessage, TInt aSession, TInt& aRet);
       
   110 #else	
       
   111 	void ProcMessage(const RMessage2& aMessage, TInt aSession);
       
   112 #endif	
       
   113 	CFbTop* TopLevelStore();
       
   114 
       
   115 private:
       
   116 	void GetHeapSizesL(const RMessage2& aMessage);
       
   117 	TInt HandleMesgTypefaceSupport(const RMessage2& aMessage, TBool& aClientPanicRequired);
       
   118 	TInt HandleMesgFontHeight(const RMessage2& aMessage, TBool aInTwips);
       
   119 
       
   120 protected:
       
   121 	TUint iConnectionId;
       
   122 	CFbTop* iTopLevelStore;
       
   123 	};
       
   124 
       
   125 class TFontFileIndex
       
   126 /**
       
   127 @internalComponent
       
   128 */
       
   129 	{
       
   130 public:
       
   131 	TUid iUid;
       
   132 	TInt iAccessCount;
       
   133 	};
       
   134 
       
   135 
       
   136 class CFbClient;
       
   137 
       
   138 NONSHARABLE_CLASS(TFbClientHelper): public TDblQueLink
       
   139 /**
       
   140 @internalComponent
       
   141 */
       
   142 	{
       
   143 public:
       
   144 	inline TFbClientHelper(CFbClient& aClient);
       
   145 
       
   146 public:
       
   147 	CFbClient& iClient;
       
   148 	RMessagePtr2 iMessage;
       
   149 	TBool iDirty;
       
   150 	};
       
   151 
       
   152 NONSHARABLE_CLASS(CFbClient): public CSession2
       
   153 /**
       
   154 @internalComponent
       
   155 */
       
   156 	{
       
   157 public:
       
   158 	static CFbClient* NewL(RHeap* aHeap);
       
   159 	~CFbClient();
       
   160 	void Init(TUint aConnectionHandle);
       
   161 	void CreateL();
       
   162 	CFontBitmapServer* FontBitmapServer();
       
   163 	CFbTop* TopLevelStore();
       
   164 	void CopyFontInfo(CFontObject* aFontObjPtr,TInt aHandle,TFontInfo& aFontInfo);
       
   165 	void ServiceL(const RMessage2& aMessage);
       
   166 	void ProcFontMessage(const RMessage2& aMessage);
       
   167 	void ProcBitmapMessage(const RMessage2& aMessage);
       
   168 	void NotifyDirtyBitmap(CBitmapObject& aBmpObj);
       
   169 	void AddFontFileIndexL(TUid aId);
       
   170 	void RemoveFontFileIndex(TUid aId);
       
   171 	void Disconnect(const RMessage2 &aMessage);
       
   172 #ifdef _DEBUG
       
   173 	void ProcMemMessage (const RMessage2& aMessage);
       
   174 #endif	
       
   175 private:
       
   176 	CFbClient(RHeap* aHeap);
       
   177 	TInt HandleMesgFontDuplicate(const RMessage2& aMessage, TBool& aPanicRequired);
       
   178 	TInt HandleMesgGetNearestFont(const RMessage2& aMessage, TBool& aPanicRequired);
       
   179 	TInt HandleMesgGetFontById(const RMessage2& aMessage, TBool& aPanicRequired);
       
   180 	TInt CopyFontInfoIntoReturnMessage(const RMessage2& aMessage, TBool& aPanicRequired, CFontObject* aFontObj, TInt iWritePosition);
       
   181 	TInt HandleMesgAddOrInstallFontFile(const RMessage2& aMessage, TBool& aPanicRequired);
       
   182 	TInt HandleMesgRemoveFontFile(const RMessage2& aMessage);
       
   183 	TInt HandleMesgRasterize(const RMessage2& aMessage, TBool& aPanicRequired);
       
   184 	TInt HandleMesgFaceAttrib(const RMessage2& aMessage, TBool& aPanicRequired);
       
   185 	TInt HandleMesgHasCharacter(const RMessage2& aMessage, TBool& aPanicRequired);
       
   186 	TInt HandleMesgShapeText(const RMessage2& aMessage, TBool& aPanicRequired);
       
   187 	TInt HandleMesgShapeDelete(const RMessage2& aMessage, TBool& aPanicRequired);
       
   188 
       
   189 protected:
       
   190 	TUint iConnectionHandle;
       
   191 	CObjectIx* iIx;
       
   192 	TInt iResourceCount;
       
   193 	CArrayFixFlat<TFontFileIndex>* iFontFileIndex;
       
   194 	RHeap* iHeap;							// the heap containing iOpenFontGlyphData
       
   195 	TOpenFontGlyphData* iOpenFontGlyphData;	// the metrics and bitmap, in shared memory, of the last character rasterized
       
   196 	TInt iSessionHandle;					// used to identify client-specific glyph caches for the new font system
       
   197 	TFbClientHelper* iHelper;				// used to notify client of any bitmap becoming dirty
       
   198 
       
   199 private:
       
   200 	RBuf16 iTextToShape;						// buffer used to hold incoming text that needs shaping
       
   201 #ifdef _DEBUG	
       
   202 	TBool iOwnHeapCheck; //for the process heap - current state
       
   203 	TBool iHeapCheck;	//for iHeap - current state
       
   204 	TBool iOwnHeapCheckFlip; //for the process heap - to switch the current state
       
   205 	TBool iHeapCheckFlip;	//for iHeap - used to switch the current state
       
   206 	TInt iOwnHeapFailNumber; //the number for the memory fail to be set to. -1: don't set.
       
   207 	TInt iSharedHeapFailNumber; //the number for the memory fail to be set to. -1 don't set
       
   208 	TInt iRet;
       
   209 	TInt iFontDuplicateToFail; //when this is set calls to HandleMesgFontDuplicate() fail for the class.
       
   210 #endif	
       
   211 	};
       
   212 
       
   213 NONSHARABLE_CLASS(CFbActiveScheduler): public CActiveScheduler
       
   214 /**
       
   215 @internalComponent
       
   216 */
       
   217 	{
       
   218 public:
       
   219 	CFbActiveScheduler();
       
   220 	virtual void Error(TInt anError) const;
       
   221 	};
       
   222 
       
   223 class CFontStore;
       
   224 
       
   225 NONSHARABLE_CLASS(CHashMap): public CBase
       
   226 /**
       
   227 A HashMap data structure for storing pointers to CSharedBitmapObjects.
       
   228 Provides fast insert/lookup/removal based on a key.
       
   229 @internalComponent
       
   230 */
       
   231 	{
       
   232 public:
       
   233 	CHashMap();
       
   234 	~CHashMap();
       
   235 
       
   236 	void Insert(CSharedBitmapObject& aBmpObj, TUint aHash);
       
   237 	CSharedBitmapObject* Lookup(const TDesC& aKey, TUint aHash) const;
       
   238 	TInt Remove(const CSharedBitmapObject& aBmpObj);
       
   239 	static TUint Hash(const TDesC16& aKey);
       
   240 
       
   241 private:
       
   242 	CSharedBitmapObject* iHashTable[1<<KFBSERVSharedBitmapHashTableSizeInBits]; // Array of pointers to singularly linked lists.  Linked list elements are CSharedBitmapObjects.
       
   243 	TInt iTableSize;
       
   244 	TInt iMask;
       
   245 	};
       
   246 
       
   247 
       
   248 IMPORT_C extern const TInt KFbServSharedHeapMaxSize;
       
   249 
       
   250 
       
   251 NONSHARABLE_CLASS(CFbTop): public CBase
       
   252 /**
       
   253 @internalComponent
       
   254 */
       
   255 	{
       
   256 	friend class CFontBitmapServer;
       
   257 	friend class CBitmapObject;
       
   258 	friend class CSharedBitmapObject;
       
   259 public:
       
   260 	~CFbTop();
       
   261 	static CFbTop* NewL();
       
   262 	TInt GetNearestFont(CFontObject*& aFontObjPtr, TFbsMessage aMessage, const TFontSpec& aFontSpec, TInt aMaxHeight = 0);
       
   263 	TInt GetFontById(CFontObject*& aFontObjPtr,TUid aUid,const TAlgStyle& aAlgStyle);
       
   264 	CBitmapObject* CreateBitmapL(const TSize& aSize, TDisplayMode aDispMode, TUid aUid, TBool aReplacement, TInt aDataSize = 0);
       
   265 	CBitmapObject* LoadBitmapL(const TDesC& aFilename, TInt32 aId, TUint aFileOffset,RFile* aFile, TInt aSessionHandle);
       
   266 	CSharedBitmapObject* ShareBitmapL(TDes& aFilename, TInt32 aId, TUint aFileOffset,RFile* aFile, TInt aSessionHandle);
       
   267 	TInt GetCleanBitmap(CBitmapObject*& aBmpObjPtr);
       
   268 	CBitmapObject* FindBitmap(TInt aHandle);
       
   269 	TBool ValidFontHandle(TInt aHandle);
       
   270 	TBool ValidBitmapFont(TInt aHandle);
       
   271 	CFontStore* FontStore() const;
       
   272 	RHeap* Heap() const;
       
   273 	CChunkPile* Pile() const;
       
   274 	TInt HeapBase() const;
       
   275 	void SetFontNameAliasL(const RMessage2& aMessage);
       
   276 	void SetDefaultLanguageForMetrics(const RMessage2& aMessage);
       
   277 	inline CFbsBackgroundCompression* BackgroundCompression() const;
       
   278 	void CloseFileStores(TInt aSessionHandle);
       
   279 	void SetSystemDefaultTypefaceName(const TDesC& aFontTypefaceName);
       
   280 	TInt GetAllBitmapHandles(const RMessage2& aMessage) const;
       
   281 	inline RFs& FileSession();
       
   282 	void AddClientHelper(TFbClientHelper& aHelper);
       
   283 	void NotifyDirtyBitmap(CBitmapObject& aBmpObj, CFbClient* aClient);
       
   284 	TInt BitmapConUniqueID() const;
       
   285 	TInt FontConUniqueID() const;
       
   286 private:
       
   287 	CFbTop();
       
   288 	void ConstructL();
       
   289 	CBitwiseBitmap* DoLoadBitmapLC(const TDesC& aFilename, TInt32 aId, TUint aFileOffset, RFile* aFile, TInt aSessionHandle);
       
   290 	void LoadOpenFontLibraries();
       
   291 	void SafeInstallOfRasterizerL(TUid aInterfaceImplUid);
       
   292 	TInt FindFontNameAlias(const TDesC& aAlias);
       
   293 	void LoadShaperFactories();
       
   294 	void SafeInstallOfShaperFactoryL(TUid aInterfaceImplUid);
       
   295 	TInt CreateFontObjectFromFont(CFontObject*& aFontObjPtr, CFont* aFont);
       
   296 	TInt GetNearestNonAliasedFont(CFont*& aFont, TFbsMessage aMessage, const TFontSpec&	aFontSpec, TInt	aMaxHeight);
       
   297 private:
       
   298 	RFs iFilesys;
       
   299 	CFontStore* iFontStore;
       
   300 	CObjectCon* iBitmapCon;
       
   301 	CObjectCon* iFontCon;
       
   302 	CObjectConIx* iConIx;
       
   303 	RHeap* iHeap;
       
   304 	RChunk iChunk;
       
   305 	RChunk iLargeBitmapChunk;
       
   306 	RMutex iDebugMutex; // used only in builds with SYMBIAN_DEBUG_FBS_LOCKHEAP defined
       
   307 	CChunkPile* iPile;
       
   308 	RPointerArray<HBufC> iFontNameAlias;
       
   309 	RPointerArray<CBitmapObject> iBitmapObjectIndex;
       
   310 	CHashMap iSharedBitmapObjectHashMap;
       
   311 	CFbTopStreamIdCache* iMBMCache;
       
   312 	TLanguage iDefaultLanguageForMetrics;
       
   313 	CFbsBackgroundCompression* iBackgroundCompression;
       
   314 	TBuf<KMaxTypefaceNameLength> iSystemDefaultFontTypefaceName;
       
   315 	TDblQue<TFbClientHelper> iClientHelpers;
       
   316 	TInt64 iNextAvailableSerialNumber;
       
   317 	};
       
   318 
       
   319 inline CBitwiseBitmap* CBitmapObject::Address() const
       
   320 	{
       
   321 	return iAddressPointer;
       
   322 	}
       
   323 
       
   324 inline TInt CBitmapObject::Handle() const
       
   325 	{
       
   326 	return iHandle;
       
   327 	}
       
   328 
       
   329 inline CBitmapObject* CBitmapObject::CleanBitmap() const
       
   330 	{
       
   331 	return iCleanBitmap;
       
   332 	}
       
   333 
       
   334 inline TBool CBitmapObject::IsInCompressionQueue() const
       
   335 	{
       
   336 	return iCompressionQueueElement != NULL;
       
   337 	}
       
   338 
       
   339 inline TFbClientHelper::TFbClientHelper(CFbClient& aClient)
       
   340 	: iClient(aClient), iDirty(EFalse)
       
   341 	{}
       
   342 
       
   343 inline CFbsBackgroundCompression* CFbTop::BackgroundCompression() const
       
   344 	{
       
   345 	__ASSERT_DEBUG(iBackgroundCompression != NULL, User::Invariant());
       
   346 	return iBackgroundCompression;
       
   347 	}
       
   348 
       
   349 /**
       
   350 It returns the file session handle.
       
   351 
       
   352 @internalComponent
       
   353 */
       
   354 inline RFs& CFbTop::FileSession()
       
   355 	{
       
   356 	return iFilesys;
       
   357 	}
       
   358 
       
   359 #endif
       
   360