os/graphics/fbs/fontandbitmapserver/sfbs/UTILS.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) 1998-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 __UTILS_H__
    17 #define __UTILS_H__
    18 
    19 #include <e32std.h>
    20 #include <gdi.h>
    21 #include <fntstore.h>
    22 #include <bitmap.h>
    23 #include <sgresource/sgimage.h>
    24 
    25 class RFbsSession;
    26 
    27 /**
    28 @internalComponent
    29 */ 
    30 _LIT(KFBSERVPanicCategory,"FBSERV");
    31 _LIT(KFBSERVGlobalThreadName,"!Fontbitmapserver");
    32 _LIT(KFBSERVSharedChunkName,"FbsSharedChunk");
    33 _LIT(KFBSERVLargeChunkName,"FbsLargeChunk");
    34 #ifdef SYMBIAN_DEBUG_FBS_LOCKHEAP
    35 _LIT(KFBSERVDebugMutexName,"FbsDebugMutex");
    36 #endif
    37 
    38 /**
    39 @internalComponent
    40 */
    41 const TUid KUidCFbsBitmapCreation={0x0009A2C};
    42 /**
    43 @internalComponent
    44 */
    45 enum TFbsPanic
    46 	{
    47 	EFbsPanicNoConnection = 1,
    48 	EFbsPanicBadConnection = 2,
    49 	EFbsPanicUnknownMessage = 3,
    50 	EFbsPanicActiveSchedulerError = 4,
    51 	EFbsPanicStartupFailed = 5,
    52 	EFbsTypefaceStoreError = 6,
    53 	EFbsFontCreateFailed = 7,
    54 	EFbsFontAddressViolation = 8,
    55 	EFbsBitmapInvalidFormat = 9,
    56 	EFbsBitmapInvalidMode = 10,
    57 	EFbsBitmapInvalidCompression = 11,
    58 	EFbsBitmapDecompressionError = 12,
    59 	EFbsPanicChunkError = 13,
    60 	EFbsColor256UtilError = 14,
    61 	EFbsHardwareBitmapError = 15,
    62 	EFbsNotSupportedForCompression = 16,
    63 	EFbsBitmapAlignment = 17,
    64 	EFbsBitmapInvalidScanLinePtr = 18,
    65 	EFbsBitmapInvalidMode2 = 19,
    66 	EFbsBitmapInvalidMode3 = 20,
    67 	EFbsBitmapSwappingImpossible = 21,
    68 	EFbsPanicBadHeapLock = 22,
    69 	EFbsShaperNotYetCalled = 23,
    70 	EFbsShaperInvalidArguments = 24,
    71 	EFbsInvalidCompressionThreshold = 25,
    72 	EFbsTypefaceIndexOutOfRange = 26,
    73 	EFbsPanicBitmapDataCopy = 27,
    74 	EFbsPanicBitmapReadOnly = 28,
    75 	EFbsPanicFontNullHandle = 29,
    76     EFbsPanicGlyphDataIteratorClosed = 31,
    77 	EFbsPanicGlyphMetricsArrayOutOfBounds = 32,
    78 	EFbsPanicGlyphDataIteratorIndexOutOfRange = 33,
    79 	EFbsPanicInvalidBitmapType = 35,
    80 	EFbsPanicGlyphAtlasInconsistentState = 36,
    81 	EFbsPanicGlyphDataIteratorFailedToOpenImage = 37,
    82 	EFbsPanicGlyphDataIteratorInvalidState = 39,
    83 	EFbsPanicGlyphMetricsArrayInvalidState = 40,
    84 	};
    85 
    86 class TScanLine
    87 /**
    88 @internalComponent
    89 */
    90 	{
    91 public:
    92 	TPoint iPoint;
    93 	TInt iLength;
    94 	TDisplayMode iDispMode;
    95 	};
    96 
    97 class TBmpSpec
    98 /**
    99 @internalComponent
   100 */
   101 	{
   102 public:
   103 	TSize iSizeInPixels;
   104 	TDisplayMode iDispMode;
   105 	TInt iHandle;
   106 	TInt iServerHandle;
   107 	TInt iAddressOffset;
   108 	};
   109 
   110 class TBmpHandles
   111 /**
   112 @internalComponent
   113 */
   114 	{
   115 public:
   116 	TInt iHandle;
   117 	TInt iServerHandle;
   118 	TInt iAddressOffset;
   119 	};
   120 
   121 class TFontInfo
   122 /**
   123 @internalComponent
   124 */
   125 	{
   126 public:
   127 	TInt iHandle;
   128 	TInt iAddressOffset;
   129 	TInt iServerHandle;
   130 	};
   131 
   132 class TSizeInfo
   133 /**
   134 @internalComponent
   135 */
   136 	{
   137 public:
   138 	TSizeInfo(){}
   139 	TSizeInfo(TInt aMaxHeight,TSize aDevSize):iMaxHeight(aMaxHeight),iDevSize(aDevSize) {}
   140 
   141 	TInt iMaxHeight;
   142 	TSize iDevSize;
   143 	};
   144 
   145 class TIntParcel
   146 /**
   147 @internalComponent
   148 */
   149 	{
   150 public:
   151 	TInt iInt;
   152 	};
   153 
   154 class TLoadBitmapArg
   155 /**
   156 @internalComponent
   157 */
   158 	{
   159 public:
   160 	TInt iBitmapId;
   161 	TInt iShareIfLoaded;
   162 	TInt iFileOffset;
   163 	};
   164 
   165 
   166 IMPORT_C extern const TInt KFbServLargeChunkGrowByShifter;
   167 IMPORT_C extern const TInt KFbServLargeChunkSizeShifter;
   168 IMPORT_C extern const TInt KFbServLargeChunkMinPhysicalSize;
   169 IMPORT_C extern const TInt KFbServLargeChunkMinVirtualSize;
   170 IMPORT_C extern const TInt KFbServLargeChunkMaxVirtualSize;
   171 
   172 
   173 class CChunkPile : public CBase
   174 /**
   175 @internalComponent
   176 */
   177 	{
   178 public:
   179 	IMPORT_C ~CChunkPile();
   180 	IMPORT_C static CChunkPile* NewL(const RChunk& aChunk);
   181 	IMPORT_C TUint8* Alloc(TInt aSize);
   182 	IMPORT_C void Free(TAny* aCell);
   183 	IMPORT_C TUint8* ChunkBase() const;
   184 	IMPORT_C static TInt VirtualSize();
   185 private:
   186 	CChunkPile(const RChunk& aChunk);
   187 	void ConstructL();
   188 	TInt DoAlloc(TUint8*& aCell, TInt aSize, RPointerArray<TUint8>& aCells, RArray<TInt>& aFreeCellLinks, TBool aLarge);
   189 	void DoFree(TUint8* aCell, RPointerArray<TUint8>& aCells, RArray<TInt>& aFreeCellLinks, TBool aLarge);
   190 	TInt GrowSmallSection(TInt aSize, TInt aLastFreeCell);
   191 	void ShrinkSmallSection(TInt aShrinkBy);
   192 private:
   193 	RChunk iChunk;
   194 	TInt iPageSize;
   195 	TInt iPageMask;
   196 	RPointerArray<TUint8> iSmallCells; // last address is not a cell but the top of the small section
   197 	RArray<TInt> iFreeSmallCellLinks; // index of Nth free small cell is element 0 + element 1 + ... + element N-1
   198 	TInt iLargeSectionBottom; // boundary between small & large sections
   199 	RPointerArray<TUint8> iLargeCells; // last address is not a cell but the top of the large section
   200 	RArray<TInt> iFreeLargeCellLinks; // index of Nth free large cell is element 0 + element 1 + ... + element N-1
   201 	RCriticalSection iLock;
   202 	};
   203 
   204 /**
   205 Used to pass sizes of FBServs default heap, heap for large bitmaps, and heap for small bitmaps.
   206 
   207 @internalComponent
   208 @test
   209 */
   210 struct THeapSizes
   211 	{
   212 	TInt iDefault;
   213 	TInt iBig;
   214 	TInt iSmall;
   215 	};
   216 
   217 /**
   218 Used when the EFbsMessRasterize message is sent from client to server. Allows pointers to items
   219 created on the shared FBServ heap to be passed from the server to the client as offsets from the
   220 heap base. Valid pointers are recreated client side using these offsets combined with the client's
   221 heap base.
   222 
   223 @internalComponent 
   224  */
   225 struct TRasterizeParams
   226 	{
   227 	TInt iMetricsOffset;
   228 	TInt iBitmapPointerOffset;
   229 	};
   230 
   231 IMPORT_C extern const TInt KFbServWritableDataPagingMode;
   232 
   233 /**
   234 Used to specify the writable data paging mode of fbserv.
   235 This may be set using the patchable constant KFbServWritableDataPagingMode at rom-build time via the definitions: 
   236 	SYMBIAN_GRAPHICS_FBSERV_PAGEDATA -request that fbserv writable data is paged.
   237 	SYMBIAN_GRAPHICS_FBSERV_UNPAGEDDATA -request that fbserv writable data is unpaged.
   238 	SYMBIAN_GRAPHICS_FBSERV_PAGE_BITMAP_DATA_ONLY -request that only bitmap data is paged.
   239 	SYMBIAN_GRAPHICS_FBSERV_PAGE_BITMAP_DATA_AND_SHARED_HEAP_ONLY -request that only bitmap data and shared heap are paged.
   240 @internalComponent
   241 */
   242 enum TFbsWritableDataPagingMode
   243 	{
   244 	EFbsWdpDefault=0x00, //No change to the rom-build writable data paging configuration (nothing was specified).
   245 	EFbsWdpPagedData=0x01, //SYMBIAN_GRAPHICS_FBSERV_PAGEDATA was specified.
   246 	EFbsWdpUnpagedData=0x02, //SYMBIAN_GRAPHICS_FBSERV_UNPAGEDDATA was specified.
   247 	EFbsWdpPageBitmapDataChunkOnly=0x03, //SYMBIAN_GRAPHICS_FBSERV_PAGE_BITMAP_DATA_ONLY was specified.
   248 	EFbsWdpPageBitmapDataAndSharedHeapChunksOnly=0x04, //SYMBIAN_GRAPHICS_FBSERV_PAGE_BITMAP_DATA_AND_SHARED_HEAP_ONLY was specified.
   249 	};
   250 
   251 
   252 /*
   253 Structure used to pass parameters from FBS client to FBS server.
   254 Used when opening/closing an outline iterator.
   255 @internalTechnology
   256 */
   257 class TFBSGlyphOutlineParam 
   258     {
   259 public:
   260     TInt iHandle;
   261     TInt iCount;
   262     TBool iHinted;
   263     };
   264 
   265 /*
   266 Structure used to pass font table/glyph outlines from FBS to FBS client.
   267 Used when opening an font table or an outline iterator.
   268 @internalTechnology
   269 */
   270 class TOffsetLen 
   271     {
   272 public:
   273     TInt iOffset;
   274     TInt iLen;
   275     };
   276 
   277 /**
   278 Maximum number of glyphs to be sent to server/received from client at a time, 
   279 when retrieval of glyphs is necessary for implementation of RFbsGlyphDataIterator.
   280 */
   281 const TInt KMaxGlyphBatchSize = 8;
   282 
   283 /**
   284 Maximum number of TOpenFontCharMetrics structures to be sent to server/received
   285 from client at a time, when retrieval of glyph metrics is necessary for
   286 implementation of RFbsGlyphMetricsArray.
   287 */
   288 const TInt KMaxMetricsBatchSize = 16;
   289 
   290 /**
   291 Used by RFbsGlyphDataIterator for client/server communication of glyph info.
   292 Contains all the data necessary to retrieve a glyph from server and recreate
   293 glyph in client process.
   294 @internalComponent 
   295  */
   296 class TGlyphImageInfo
   297     {
   298 public:
   299     inline TGlyphImageInfo() : iImageId(KSgNullDrawableId), iPosX(0), iPosY(0) {}
   300 public:
   301     TSgDrawableId iImageId;
   302     TInt16 iPosX;
   303     TInt16 iPosY;
   304     TOpenFontCharMetrics iMetrics;
   305     };
   306 
   307 /**
   308 Used by CGlyphDataIteratorImpl. It is a container to group the 
   309 metadata and the image data of an individual glyph recevied from the
   310 server, all together. A collection of these is stored in the font,
   311 received from the server in batches.
   312 @internalComponent 
   313 */
   314 struct TGlyphBatchItem
   315     {
   316     TSglQueLink iLink;
   317     RSgImage iImage;
   318     TGlyphImageInfo iInfo;
   319     };
   320 
   321 /**
   322 Implementor class of RFbsGlyphDataIterator. This class contains all
   323 state information and contains much of the implementation of the
   324 behaviour.
   325 @internalComponent 
   326  */
   327 NONSHARABLE_CLASS(CGlyphDataIteratorImpl) : public CBase
   328     {
   329 public:
   330     CGlyphDataIteratorImpl(TInt aFbsFontHandle, const TUint* aGlyphCodes, TInt aCount);
   331     ~CGlyphDataIteratorImpl();
   332     TInt Initialise();
   333     TInt Next();
   334     void UpdateGlyphRect();
   335     TInt UpdateGlyphBatch(TInt aIndex);
   336     
   337 public:    
   338     TSglQue<TGlyphBatchItem> iGlyphBatch;   // Linked-list of the current batch of received glyphs.
   339     const TUint* iGlyphDataIterCodes;       // An array of glyph codes
   340     TInt  iGlyphDataIterCodeCount;          // The number of glyph codes in the array
   341     TInt  iGlyphDataIterCodeIndex;          // The index of the current glyph code in the array
   342     TRect iGlyphDataIterRect;               // The current glyph rectangle.
   343     TInt  iFbsFontHandle;                   // The Font Handle the iterator was opened with  
   344     RFbsSession* iFbs;
   345     };
   346 
   347 #endif