os/graphics/fbs/fontandbitmapserver/sfbs/SERVER.H
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #ifndef SERVER_H
    17 #define SERVER_H
    18 
    19 #include <e32base.h>
    20 #include <f32file.h>
    21 #include <fbs.h>
    22 #include <sgresource/sgimage.h>
    23 #include "UTILS.H"
    24 #include "FBSMBMC.H"
    25 #include "FbsMessage.H"
    26 #include "glyphatlas.h"
    27 
    28 class CFbTop;
    29 class CFbsBackgroundCompression;
    30 class CFbsBackgroundCompressionQueueElement;
    31 class TOpenFontGlyphData;
    32 
    33 
    34 NONSHARABLE_CLASS(CFontObject): public CObject
    35 /**
    36 @internalComponent
    37 */
    38 	{
    39 public:
    40 	CFontObject(CFontStore* aFontStore, CGlyphAtlas* aGlyphAtlas);
    41 	~CFontObject();
    42 public:
    43 	CBitmapFont* iAddressPointer;
    44 	CFontStore* iFontStore;
    45 	TInt iHeightInTwips;
    46 	CGlyphAtlas* iGlyphAtlas;
    47 	};
    48 
    49 NONSHARABLE_CLASS(CBitmapObject): public CObject
    50 /**
    51 Provides reference counting facilities for bitmaps managed by CFbTop.
    52 @internalComponent
    53 */
    54 	{
    55 	friend class CFbsBackgroundCompression;
    56 	friend class CFbsBackgroundCompressionQueueElement;
    57 protected:
    58 	CBitmapObject(CFbTop& aFbTop, CBitwiseBitmap* aBmp);
    59 	void ConstructL(TBool aReplacement);
    60 public:
    61 	static CBitmapObject* NewL(CFbTop& aFbTop, CBitwiseBitmap* aBmp, TBool aReplacement);
    62 	~CBitmapObject();
    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);
    68 	virtual void Close();
    69 	static TInt Compare(const CBitmapObject& aBmpObj1, const CBitmapObject& aBmpObj2);
    70 	static TInt Compare(const TInt* aHandle, const CBitmapObject& aBmpObj);
    71 protected:
    72 	CFbTop* iFbTop;
    73 private:
    74 	CBitwiseBitmap* iAddressPointer;
    75 	TInt iHandle;
    76 	CBitmapObject* iCleanBitmap;
    77 	CFbsBackgroundCompressionQueueElement* iCompressionQueueElement;
    78 	};
    79 
    80 NONSHARABLE_CLASS(CSharedBitmapObject): public CBitmapObject
    81 /**
    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.
    85 @internalComponent
    86 */
    87 	{
    88 friend class CHashMap;
    89 private:
    90 	CSharedBitmapObject(CFbTop& aFbTop, CBitwiseBitmap* aBmp, TDesC* aKey);
    91 	void ConstructL(TUint aHash);
    92 public:
    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);
    96 private:
    97 	TDesC* iKey;
    98 	mutable CSharedBitmapObject* iNext;    // Next object in a linked list
    99 	};
   100 
   101 NONSHARABLE_CLASS(CFontBitmapServer): public CPolicyServer
   102 /**
   103 @internalComponent
   104 */
   105 	{
   106 public:
   107 	CFontBitmapServer();
   108 	~CFontBitmapServer();
   109 	static CFontBitmapServer* NewL();
   110 	CSession2* NewSessionL(const TVersion& aVersion, const RMessage2& aMessage) const;
   111 	TInt Init();
   112 #ifdef _DEBUG
   113 	void ProcMessage(const RMessage2& aMessage, TInt aSession, TInt& aRet);
   114 #else	
   115 	void ProcMessage(const RMessage2& aMessage, TInt aSession);
   116 #endif	
   117 	CFbTop* TopLevelStore();
   118 
   119 private:
   120 	void ConstructL();
   121 	void GetHeapSizesL(const RMessage2& aMessage);
   122 	TInt HandleMesgTypefaceSupport(const RMessage2& aMessage, TBool& aClientPanicRequired);
   123 	TInt HandleMesgFontHeight(const RMessage2& aMessage, TBool aInTwips);
   124 
   125 protected:
   126 	TUint iConnectionId;
   127 	CFbTop* iTopLevelStore;
   128 	};
   129 
   130 class TFontFileIndex
   131 /**
   132 @internalComponent
   133 */
   134 	{
   135 public:
   136 	TUid iUid;
   137 	TInt iAccessCount;
   138 	};
   139 
   140 
   141 class CFbClient;
   142 
   143 NONSHARABLE_CLASS(TFbClientHelper): public TDblQueLink
   144 /**
   145 @internalComponent
   146 */
   147 	{
   148 public:
   149 	inline TFbClientHelper(CFbClient& aClient);
   150 
   151 public:
   152 	CFbClient& iClient;
   153 	RMessagePtr2 iMessage;
   154 	TBool iDirty;
   155 	};
   156 
   157 NONSHARABLE_CLASS(CFbClient): public CSession2
   158 /**
   159 @internalComponent
   160 */
   161 	{
   162 public:
   163 	static CFbClient* NewL(RHeap* aHeap);
   164 	~CFbClient();
   165 	void Init(TUint aConnectionHandle);
   166 	void CreateL();
   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);
   177 #ifdef _DEBUG
   178 	void ProcMemMessage (const RMessage2& aMessage);
   179 	void ProcAtlasMessage (const RMessage2& aMessage);
   180 #endif	
   181 private:
   182 	void ConstructL();
   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);
   203 
   204 protected:
   205 	TUint iConnectionHandle;
   206 	CObjectIx* iIx;
   207 	TInt iResourceCount;
   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
   213 
   214 private:
   215 	RBuf16 iTextToShape;						// buffer used to hold incoming text that needs shaping
   216 	RArray<RSgImage> iGlyphImagesInTransit;	// last glyph images retrieved from glyph atlas
   217 #ifdef _DEBUG	
   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
   224 	TInt iRet;
   225 	TInt iFontDuplicateToFail; //when this is set calls to HandleMesgFontDuplicate() fail for the class.
   226 #endif	
   227 	};
   228 
   229 NONSHARABLE_CLASS(CFbActiveScheduler): public CActiveScheduler
   230 /**
   231 @internalComponent
   232 */
   233 	{
   234 public:
   235 	CFbActiveScheduler();
   236 	virtual void Error(TInt anError) const;
   237 	};
   238 
   239 class CFontStore;
   240 
   241 NONSHARABLE_CLASS(CHashMap): public CBase
   242 /**
   243 A HashMap data structure for storing pointers to CSharedBitmapObjects.
   244 Provides fast insert/lookup/removal based on a key.
   245 @internalComponent
   246 */
   247 	{
   248 public:
   249 	CHashMap();
   250 	~CHashMap();
   251 
   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);
   256 
   257 private:
   258 	CSharedBitmapObject* iHashTable[1<<KFBSERVSharedBitmapHashTableSizeInBits]; // Array of pointers to singularly linked lists.  Linked list elements are CSharedBitmapObjects.
   259 	TInt iTableSize;
   260 	TInt iMask;
   261 	};
   262 
   263 
   264 IMPORT_C extern const TInt KFbServSharedHeapMaxSize;
   265 IMPORT_C extern const TInt KFbServGlyphAtlasCacheLimit;
   266 
   267 
   268 NONSHARABLE_CLASS(CFbTop): public CBase
   269 /**
   270 @internalComponent
   271 */
   272 	{
   273 	friend class CFontBitmapServer;
   274 	friend class CBitmapObject;
   275 	friend class CSharedBitmapObject;
   276 public:
   277 	~CFbTop();
   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;
   288 	RHeap* Heap() 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;
   303 private:
   304 	CFbTop();
   305 	void ConstructL();
   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);
   314 private:
   315 	RFs iFilesys;
   316 	CFontStore* iFontStore;
   317 	CObjectCon* iBitmapCon;
   318 	CObjectCon* iFontCon;
   319 	CObjectConIx* iConIx;
   320 	RHeap* iHeap;
   321 	RChunk iChunk;
   322 	RChunk iLargeBitmapChunk;
   323 	RMutex iDebugMutex; // used only in builds with SYMBIAN_DEBUG_FBS_LOCKHEAP defined
   324 	CChunkPile* iPile;
   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;
   335 	};
   336 
   337 inline CBitwiseBitmap* CBitmapObject::Address() const
   338 	{
   339 	return iAddressPointer;
   340 	}
   341 
   342 inline TInt CBitmapObject::Handle() const
   343 	{
   344 	return iHandle;
   345 	}
   346 
   347 inline CBitmapObject* CBitmapObject::CleanBitmap() const
   348 	{
   349 	return iCleanBitmap;
   350 	}
   351 
   352 inline TBool CBitmapObject::IsInCompressionQueue() const
   353 	{
   354 	return iCompressionQueueElement != NULL;
   355 	}
   356 
   357 inline TFbClientHelper::TFbClientHelper(CFbClient& aClient)
   358 	: iClient(aClient), iDirty(EFalse)
   359 	{}
   360 
   361 inline CFbsBackgroundCompression* CFbTop::BackgroundCompression() const
   362 	{
   363 	__ASSERT_DEBUG(iBackgroundCompression != NULL, User::Invariant());
   364 	return iBackgroundCompression;
   365 	}
   366 
   367 /**
   368 It returns the file session handle.
   369 
   370 @internalComponent
   371 */
   372 inline RFs& CFbTop::FileSession()
   373 	{
   374 	return iFilesys;
   375 	}
   376 
   377 #endif // SERVER_H
   378