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