Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
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 the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
23 #include <fbsmessage.h>
26 Indicates version of the font and bitmap server without heap locking.
30 #define SYMBIAN_FBSERV_V2
35 const TUid KCFbsFontUid = { 268435518 };
39 const TUid KMultiBitmapRomImageUid = { 268435521 };
43 const TUint32 KFontBitmapServerUidValue = 0x10003a16;
47 const TUid KFontBitmapServerUid = { KFontBitmapServerUidValue };
51 IMPORT_C TInt FbsStartup();
54 Required to ensure BC between NGage and 7.0S platforms.
55 Function is exported at ordinal corresponding to where NGage platform
56 has extended this library and must not be moved.
59 IMPORT_C void DummyReserved1();
63 Character width and adjustment information.
70 /** The left adjust of the character. */
72 /** The right adjust of the character. */
74 /** The total width of the character, defined as iLeftAdjust + iWidth + iRightAdjust. */
76 /** The width of the character. */
81 class CFbsSessionHelper;
84 A session with the font and bitmap server.
88 class RFbsSession : protected RSessionBase
90 // Allow access to internals for test
93 friend class CTBitmap;
97 friend class CFbsBitmap;
98 friend class CFbsBitmapAsyncStreamer;
100 IMPORT_C RFbsSession();
101 IMPORT_C static TInt Connect();
102 IMPORT_C static TInt Connect(RFs& aFileServer);
103 IMPORT_C static void Disconnect();
104 IMPORT_C static RFbsSession* GetSession();
105 IMPORT_C void CallBack();
106 IMPORT_C void SetCallBack(TCallBack aCallBack);
107 IMPORT_C void ResetCallBack();
108 IMPORT_C TInt ResourceCount();
109 IMPORT_C TInt SendCommand(TInt aMessage,TInt aInt0=0,TInt aInt1=0,TInt aInt2=0,TInt aInt3=0) const;
110 TInt SendCommand(TInt aMessage, const TIpcArgs& aArgs) const;
111 void SendCommand(TInt aMessage, const TIpcArgs& aArgs, TRequestStatus &aStatus) const;
112 IMPORT_C TVersion Version();
113 IMPORT_C TUint8* HeapBase() const;
114 IMPORT_C TInt GetHeapSizes(TInt& aDefaultHeap, TInt& aSmallBmpHeap, TInt& aBigBmpChunk);
115 TInt SessionHandle() const { return Handle(); }
116 TInt AllocScanLineBuffer(TInt aSize);
117 HBufC8* GetScanLineBuffer();
118 void SetCallBackPtr(TInt* aBitmapHandle)const;
119 HBufC8* GetDecompressionBuffer(TInt aSize);
120 HBufC8* GetExtraBuffer(TInt aSize);
123 Used for testing server side out of memory failures
130 EHeapFailTypeServerMemory,
131 EHeapFailTypeHeapMemory,
134 TBool LookupBitmapInROM(const TDesC& aFilename, TAny*& aAddr);
135 RFs& FileServer() { return *((RFs*)iSpare); }
136 static TInt DoAlloc(RFbsSession*& aNewSession);
137 TInt DoConnect(RFs& aFileServer);
140 mutable TCallBack iCallBack;
142 CFbsSessionHelper* iHelper;
143 RChunk iLargeBitmapChunk;
145 CFbsRalCache* iRomFileAddrCache;
146 HBufC8* iDecompressionBuffer;
147 HBufC8* iScanLineBuffer;
152 Font managed by the font and bitmap server.
153 CFbsFont objects are used for screen and off-screen bitmap fonts. They are
154 usually obtained by calls to the CBitmapDevice::GetNearestFontInPixels() and
155 MGraphicsDeviceMap::GetNearestFontInTwips() functions.
156 The class implements a number of functions inherited from CFont.
157 @see CBitmapDevice::GetNearestFontInPixels()
158 @see MGraphicsDeviceMap::GetNearestFontInTwips()
162 class CFbsFont: public CFont
164 friend class CFbsTypefaceStore;
168 /** Gets the font's UID.
169 All CFbsFont objects have the constant UID KCFbsFontUid. It is safe to cast
170 from CFont* to CFbsFont* if CFont::TypeUid() returns KCFbsFontUid.
171 @return The font's UID. This should be KCFbsFontUid.
172 @see CFont::TypeUid() */
173 virtual TUid DoTypeUid() const { return KCFbsFontUid; }
174 IMPORT_C virtual TInt DoHeightInPixels() const;
175 IMPORT_C virtual TInt DoAscentInPixels() const;
176 IMPORT_C virtual TInt DoCharWidthInPixels(TChar aChar) const;
177 IMPORT_C virtual TInt DoTextWidthInPixels(const TDesC& aText) const;
178 IMPORT_C virtual TInt DoBaselineOffsetInPixels() const;
179 IMPORT_C virtual TInt DoTextCount(const TDesC& aText,TInt aWidthInPixels) const;
180 IMPORT_C virtual TInt DoTextCount(const TDesC& aText,TInt aWidthInPixels,TInt& aExcessWidthInPixels) const;
181 IMPORT_C virtual TInt DoMaxCharWidthInPixels() const;
182 IMPORT_C virtual TInt DoMaxNormalCharWidthInPixels() const;
183 IMPORT_C virtual TFontSpec DoFontSpecInTwips() const;
184 IMPORT_C virtual CFont::TCharacterDataAvailability DoGetCharacterData(TUint aCode, TOpenFontCharMetrics& aMetrics,
185 const TUint8*& aBitmap, TSize& aBitmapSize) const;
186 IMPORT_C virtual TInt DoExtendedFunction(TUid aFunctionId, TAny* aParam = NULL) const;
190 IMPORT_C TBool GetFontMetrics(TOpenFontMetrics& aMetrics) const;
191 IMPORT_C TInt TextWidthInPixels(const TDesC& aText) const;
192 IMPORT_C void TextWidthInPixels(const TDesC& aText,SCharWidth& aCharWidth) const;
193 IMPORT_C TInt Handle() const;
194 IMPORT_C TCharacterMetrics CharacterMetrics(TInt aCode,const TUint8*& aBytes) const;
195 IMPORT_C TInt RawTextWidthInPixels(const TDesC& aText) const;
196 IMPORT_C TBool GetFaceAttrib(TOpenFontFaceAttrib& aAttrib) const;
197 IMPORT_C TBool IsOpenFont() const;
198 IMPORT_C TBool HasCharacter(TInt aCode) const;
202 IMPORT_C ~CFbsFont();
203 IMPORT_C CFbsFont(const CFbsFont& aFont);
204 IMPORT_C CBitmapFont* Address() const;
205 IMPORT_C TInt Duplicate(TInt aHandle);
206 IMPORT_C void Reset();
209 void InsertCharacterInCache(TInt aCode, CLinkedFontInformation* &aInfo, CBitmapFont* &aBitmapFont) const;
212 TInt DoFontGetShaping(TFontShapeFunctionParameters* aParam) const;
213 TInt DoFontDeleteShaping(TFontShapeDeleteFunctionParameters* aParam) const;
217 CBitmapFont* iAddressPointer;
222 class CDirectFileStore;
225 Note that this class is not intended for user derivation.
226 A bitmap managed by the font and bitmap server.
227 The class also defines some palette functionality which is not yet
228 implemented, since none of the modes currently supported by screen
229 or bitmaps require variable palettes.
230 Note that the CFbsBitmap format is internal to Symbian, but the
231 Image Converter API can be used to convert such bitmaps to standard formats.
232 CFbsBitmap instances cannot be shared between different threads. They use some shared
233 thread local storage data. If you want to share a bitmap between threads, use Duplicate().
236 @see CFbsBitmap::Duplicate()
238 class CFbsBitmap : public CBase
240 friend class TBitmapUtil;
241 friend class CBitwiseBitmap;
242 friend class CFbsBitmapAsyncStreamer;
243 friend class CFbsSessionHelper;
245 IMPORT_C CFbsBitmap();
246 IMPORT_C ~CFbsBitmap();
247 IMPORT_C void Reset();
248 IMPORT_C static TInt ScanLineLength(TInt aLength,TDisplayMode aDispMode);
249 IMPORT_C TDisplayMode DisplayMode() const;
250 IMPORT_C TDisplayMode InitialDisplayMode() const;
251 IMPORT_C TInt SetDisplayMode(TDisplayMode aDisplayMode);
252 IMPORT_C TInt Create(const TSize& aSizeInPixels,TDisplayMode aDispMode);
253 IMPORT_C TInt Duplicate(TInt aHandle);
254 IMPORT_C TBool IsRomBitmap() const;
255 IMPORT_C void SetRomBitmapL(CBitwiseBitmap* aRomBitmapPointer,TInt& aBitmapSizeInBytes);
256 IMPORT_C TInt Load(const TDesC& aFileName,TInt32 aId=0,TBool aShareIfLoaded=ETrue);
257 IMPORT_C TInt Load(const TDesC& aFileName,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset);
258 IMPORT_C TInt LoadAndCompress(const TDesC& aFileName,TInt32 aId=0,TBool aShareIfLoaded=ETrue);
259 IMPORT_C TInt LoadAndCompress(const TDesC& aFileName,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset);
260 IMPORT_C TInt Load(RFile& aFile,TInt32 aId=0,TBool aShareIfLoaded=ETrue);
261 IMPORT_C TInt Load(RFile& aFile,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset);
262 IMPORT_C TInt LoadAndCompress(RFile& aFile,TInt32 aId=0,TBool aShareIfLoaded=ETrue);
263 IMPORT_C TInt LoadAndCompress(RFile& aFile,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset);
264 IMPORT_C TInt Save(const TDesC& aFilename);
265 IMPORT_C TInt Save(RFile& aFile);
266 IMPORT_C static void StoreL(const TDesC& aFilename,TInt aNumSources,const TDesC* aSources[],TInt32 aSourceIds[]);
267 IMPORT_C static void StoreL(RFile& aFile,TInt aNumSources,const TDesC* aSources[],TInt32 aSourceIds[]);
268 IMPORT_C void GetScanLine(TDes8& aBuf,const TPoint& aPixel,TInt aLength,TDisplayMode aDispMode) const;
269 IMPORT_C void SetScanLine(TDes8& aBuf,TInt aY) const;
270 IMPORT_C void GetVerticalScanLine(TDes8& aBuf,TInt aX,TDisplayMode aDispMode) const;
271 IMPORT_C void GetVerticalScanLine(TDes8& aBuf,TInt aX,const TPoint& aDitherOffset,TDisplayMode aDispMode) const;
272 IMPORT_C TInt Handle() const;
273 IMPORT_C SEpocBitmapHeader Header() const;
274 IMPORT_C TInt HorizontalPixelsToTwips(TInt aPixels) const;
275 IMPORT_C TInt HorizontalTwipsToPixels(TInt aTwips) const;
276 IMPORT_C void GetPixel(TRgb& aColor,const TPoint& aPixel) const;
277 IMPORT_C TInt Resize(const TSize& aSizeInPixels);
278 IMPORT_C TSize SizeInPixels() const;
279 IMPORT_C TSize SizeInTwips() const;
280 IMPORT_C void SetSizeInTwips(const MGraphicsDeviceMap* aMap);
281 IMPORT_C void SetSizeInTwips(const TSize& aSizeInTwips);
282 IMPORT_C void ExternalizeL(RWriteStream& aStream) const;
283 IMPORT_C void ExternalizeRectangleL(RWriteStream& aStream,const TRect& aRect) const;
284 IMPORT_C void InternalizeL(RReadStream& aStream);
285 IMPORT_C TInt Compress();
286 IMPORT_C TInt Compress(TBitmapfileCompressionScheme aScheme);
287 IMPORT_C void CompressInBackground(TRequestStatus& aRequestStatus);
288 IMPORT_C TInt CompressInBackground();
289 IMPORT_C void CompressInBackground(TRequestStatus& aRequestStatus, TBitmapfileCompressionScheme aScheme);
290 IMPORT_C TInt CompressInBackground(TBitmapfileCompressionScheme aScheme);
291 IMPORT_C TInt VerticalPixelsToTwips(TInt aPixels) const;
292 IMPORT_C TInt VerticalTwipsToPixels(TInt aTwips) const;
293 IMPORT_C static TBool IsFileInRom(const TDesC& aFilename,TUint32*& aWord);
294 IMPORT_C static TBool IsFileInRom(RFile& aFile,TUint32*& aWord);
295 IMPORT_C TBool IsMonochrome() const;
296 IMPORT_C TBool IsLargeBitmap() const;
297 IMPORT_C void PaletteAttributes(TBool& aModifiable,TInt& aNumEntries) const;
298 IMPORT_C void SetPalette(CPalette* aPalette);
299 IMPORT_C TInt GetPalette(CPalette*& aPalette) const;
300 IMPORT_C TUint32* DataAddress() const;
301 IMPORT_C TInt DataStride() const;
302 IMPORT_C TInt CreateHardwareBitmap(const TSize& aSizeInPixels,TDisplayMode aDispMode,TUid aCreatorUid);
303 IMPORT_C TInt HardwareBitmapHandle() const;
304 IMPORT_C void BeginDataAccess() const;
305 IMPORT_C void EndDataAccess(TBool aReadOnly=EFalse) const;
306 IMPORT_C void LockHeap(TBool aAlways=EFalse) const;
307 IMPORT_C void UnlockHeap(TBool aAlways=EFalse) const;
308 IMPORT_C void LockHeapLC(TBool aAlways=EFalse) const;
309 IMPORT_C static void UnlockHeap(TAny* aFbsBitmap);
310 IMPORT_C TBool IsCompressedInRAM() const;
311 IMPORT_C TInt SwapWidthAndHeight();
312 IMPORT_C static HBufC8* GetDecompressionBuffer(TInt aSize);
313 IMPORT_C TInt GetAllBitmapHandles(RArray<TInt>& aBitmapIdArray) const;
314 IMPORT_C static HBufC8* GetExtraBuffer(TInt aSize);
316 IMPORT_C void GetScanLine(TDes8& aBuf,const TPoint& aPixel,TInt aLength,const TPoint& aDitherOffset,TDisplayMode aDispMode) const;
317 CBitwiseBitmap* Address() const;
318 IMPORT_C CBitwiseBitmap* CleanAddress() const;
319 inline CBitwiseBitmap* CleanAddress(TUint32*& aDataAddress) const;
320 void DoSaveL(RFile& aFile);
321 TInt DoCreate(const TSize& aSizeInPixels,TDisplayMode aDispMode,TUid aCreatorUid);
323 TInt DoLoad(RFile& aFile,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset);
324 TInt DoLoad(const TDesC& aFileName,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset);
325 TInt DoLoadFromRom(TUint32* aRomPointer, TInt32 aId, TUint aFileOffset, TBool& aRomPointerValid);
326 TBool LoadShiftedRomBmpL(const TDesC& aFileName,TInt32 aId,TUint aFileOffset);
327 static void DoStoreL(CDirectFileStore* aFileStore,CFbsBitmap* aBitmap,TInt aNumSources,const TDesC* aSources[],TInt32 aSourceIds[]);
334 EIsRomBitmap = 0x0001
344 CBitwiseBitmap* iAddressPointer;
363 class CDirectFileStore;
369 class CFbsBitmapAsyncStreamer : public CBase
372 enum TMode {ELoad, ESave};
374 IMPORT_C ~CFbsBitmapAsyncStreamer();
375 IMPORT_C static CFbsBitmapAsyncStreamer* NewL(TMode aMode);
376 IMPORT_C TInt Load(const TDesC& aFilename,TInt32 aId,TInt& aScanLines);
377 IMPORT_C TBool LoadScanLinesL(TInt aNumberOfScanLines,CFbsBitmap*& aBitmap);
378 IMPORT_C TInt Save(const TDesC& aFilename,CFbsBitmap* aBitmap,TInt32& aId,TInt& aScanLines);
379 IMPORT_C TBool SaveScanLinesL(TInt aNumberOfScanLines);
381 CFbsBitmapAsyncStreamer(TMode aMode);
383 void DoLoadL(const TDesC& aFilename,TInt32 aId);
384 void DoSaveL(RFile& aFile);
387 RStoreReadStream iReadStream;
388 RStoreWriteStream iWriteStream;
390 CDirectFileStore* iStore;
391 TInt iCurrentScanLine;
392 TUint32* iScanLineBase;
394 SEpocBitmapHeader iHeader;
395 TDisplayMode iDispMode;
401 Provides fast read/write access to the pixel data of a bitmap.
403 Functionality includes getting and setting the individual pixels of a bitmap.
404 Common to this is the concept of the current pixel position. This is held
405 as member data and is changed by using various efficient functions. For example,
406 incrementing the position's x- or y co-ordinate is much quicker than setting
407 a completely new position. This efficiency issue is important as these functions
408 are used as part of the frequently used blitting DDA used for creating
409 stretched or compressed versions of bitmaps.
411 Calls to Begin() and End() must surround any calls to the other member functions.
412 Note that you should always ensure each Begin() is matched by an End() call
413 when using this class.
415 Note also that all display modes including EColor16M are supported, but the
416 TDisplayMode values ERgb and ENone are not considered to be display modes.
423 IMPORT_C void Begin(const TPoint& aPosition);
424 IMPORT_C void Begin(const TPoint& aPosition,const TBitmapUtil& aUtil);
426 IMPORT_C TBitmapUtil(CFbsBitmap* aBitmap);
427 IMPORT_C TUint32 GetPixel() const;
428 IMPORT_C void SetPixel(TUint32 aValue);
429 IMPORT_C void SetPixel(const TBitmapUtil& aSource);
430 IMPORT_C void SetPos(const TPoint& aPosition);
431 IMPORT_C void DecXPos();
432 IMPORT_C void DecYPos();
433 IMPORT_C void IncXPos();
434 IMPORT_C void IncYPos();
436 CFbsBitmap* iFbsBitmap;
438 TUint32* iMinWordPos;
439 TUint32* iMaxWordPos;
444 TInt iScanlineWordLength;
451 Font and bitmap server typeface store.
455 class CFbsTypefaceStore : public CTypefaceStore
457 friend class CWsScreenDevice;
459 IMPORT_C static CFbsTypefaceStore* NewL(CGraphicsDevice* aDevice);
460 IMPORT_C ~CFbsTypefaceStore();
461 IMPORT_C TInt AddFile(const TDesC& aName,TInt& aId);
462 IMPORT_C TInt InstallFile(const TDesC& aName,TInt& aId);
463 IMPORT_C void RemoveFile(TInt aId=0);
464 IMPORT_C virtual TInt GetNearestFontInTwips(CFont*& aFont, const TFontSpec& aFontSpec);
465 IMPORT_C TInt GetNearestFontInPixels(CFont*& aFont, const TFontSpec& aFontSpec);
466 IMPORT_C virtual TInt GetNearestFontToDesignHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec);
467 IMPORT_C TInt GetNearestFontToDesignHeightInPixels(CFont*& aFont, const TFontSpec& aFontSpec);
468 IMPORT_C virtual TInt GetNearestFontToMaxHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec, TInt aMaxHeight);
469 IMPORT_C TInt GetNearestFontToMaxHeightInPixels(CFont*& aFont, const TFontSpec& aFontSpec, TInt aMaxHeight);
470 IMPORT_C TInt GetFontById(CFont *&aFont,TUid aUid,const TAlgStyle& aAlgStyle);
471 IMPORT_C virtual TInt NumTypefaces() const;
472 IMPORT_C virtual void TypefaceSupport(TTypefaceSupport& aTypefaceSupport,TInt aTypefaceIndex) const;
473 IMPORT_C virtual TInt FontHeightInTwips(TInt aTypefaceIndex,TInt aHeightIndex) const;
474 IMPORT_C TInt FontHeightInPixels(TInt aTypefaceIndex,TInt aHeightIndex) const;
475 IMPORT_C TGlyphBitmapType DefaultBitmapType() const;
476 IMPORT_C void SetDefaultBitmapType(TGlyphBitmapType aType) const;
477 IMPORT_C void SetFontNameAliasL(const TDesC& aFontAlias,const TDesC& aFontName) const;
478 IMPORT_C void SetDefaultLanguageForMetrics(TLanguage aLanguage) const;
479 IMPORT_C static void RemoveFontFileLocksL();
480 IMPORT_C static void RemoveFontFileLocksL(const TDesC& aDrive, TBool aAllFonts);
481 IMPORT_C static void RemoveFontFileLocksL(const TDesC& aFileName);
482 IMPORT_C void ReleaseTwipsCache();
483 IMPORT_C void SetSystemDefaultTypefaceNameL(const TDesC& aFontTypefaceName);
484 IMPORT_C TInt RegisterLinkedTypeface(const CLinkedTypefaceSpecification& aLinkedTypefaceSpec, TInt& aId);
486 CFbsTypefaceStore(CGraphicsDevice* aDevice);
488 TInt CreateFont(CFont*& aFont,const TFontInfo& aFontInfo);
489 TBool IsFontLoaded(CFont*& aFont, const TFontInfo& aFontInfo) const;
490 TInt FontHeight(TInt aTypefaceIndex,TInt aHeightIndex,TInt aMessage) const;
491 TInt GetNearestFontInTwipsAndCreateFont(CFont*& aFont, TFbsMessage aFbsMessage, const TFontSpec& aFontSpec, TInt aMaxHeight = 0);
492 TInt SendGetNearestFontCommandNCreateFont(
493 CFont*& aFont, TFbsMessage aFbsMessage, const TFontSpec& aFontSpec, TInt aMaxHeight = 0);
494 void GetPixelSizeInTwips(TSize& aSize) const;
498 CGraphicsDevice* iDevice;
499 CFontCache* iTwipsCache;
502 class CDitherColor256;
505 Copies a bitmap in any display mode of at least 256 colours into a 256
506 colour bitmap, optionally using a user-defined palette.
510 class CFbsColor256BitmapUtil : public CBase
513 /** Indicates whether or not to use dithering. */
518 /** Use the Floyd-Steinberg dithering algorithm. */
523 IMPORT_C static CFbsColor256BitmapUtil* NewL(const CPalette* aPalette);
525 IMPORT_C TInt CopyBitmap(CFbsBitmap* aColor256Destination,CFbsBitmap* aSource,TDither aDither=ENoDither);
527 ~CFbsColor256BitmapUtil();
529 CFbsColor256BitmapUtil();
531 TColor256Util* iColor256Util;
532 CDitherColor256* iDither;