Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
18 #include <graphicsaccelerator.h>
20 #include <graphics/bitmapuid.h>
23 #include "fbshelper.h"
24 #include "fbsrasterizer.h"
25 #include "BitwiseBitmap.inl"
26 #include "FbsMessage.H"
27 #include "bitmapconst.h"
28 #include "OstTraceDefinitions.h"
30 #ifdef OST_TRACE_COMPILER_IN_USE
31 #include "FBSBMPTraces.h"
34 const TInt KMaxPixelSize = KMaxTInt / 4; // Maximum pixel size to avoid some overflow problems
35 const TInt KMaxBitmapHandleBufferSize = KNumBytesPerBitmapHandle * 2000; // Maximum size of buffer to store all bitmap handles.
37 GLREF_C void Panic(TFbsPanic aPanic);
39 //If we have to handle RAM located file with an embedded ROM mbm file section -
40 //KRomMBMInRamRSC should be ETrue.
41 //If it is not allowed to do that - KRomMBMInRamRSC should be EFalse.
42 //The same constant is defined into TDefect test app. It should be changed too.
43 #pragma warning(disable : 4127) //conditional expression is constant
44 LOCAL_D const TBool KRomMBMInRamRSC = EFalse;
46 //Cleanup function used by CFbsBitmap::LoadShiftedRomBmpL(...)
47 LOCAL_D void FreeMem(TAny* aMem)
49 delete[] static_cast<TUint8*>(aMem);
52 // Fbs style bitmap client class for font bitmap server
54 EXPORT_C CFbsBitmap::CFbsBitmap():
56 iFbs(RFbsSession::GetSession()),
57 iAddressPointer(NULL),
65 /** Destructor. Calls Reset().
70 EXPORT_C CFbsBitmap::~CFbsBitmap()
75 /** Gets the physical length in bytes of a scanline in memory.
76 This is aligned to a 4 byte (DWORD) boundary for performance reasons.
78 @param aLength The length of a scanline in pixels.
79 @param aDispMode The display mode of the bitmap.
80 @return Number of bytes in the scanline in memory.
84 EXPORT_C TInt CFbsBitmap::ScanLineLength(TInt aLength,TDisplayMode aDispMode)
86 if (aDispMode == ERgb)
88 else if (aDispMode == ENone)
91 return CBitwiseBitmap::ByteWidth(aLength,aDispMode);
94 /** Releases the bitmap's handle from the font and bitmap server and decrements
96 The server-side bitmap is only deleted when the access count for the bitmap
101 EXPORT_C void CFbsBitmap::Reset()
103 FBS_OST(TInt ssh = (iFbs ? iFbs->ServerSessionHandle() : 0);)
104 FBS_OST(OstTraceExt4( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_RESET_ENTRY, "> this=0x%08x; iH=0x%08x; iSH=0x%08x; iSSH=0x%08x", (TUint)this, iHandle, iServerHandle, ssh );)
105 if (iHandle && !(iFlags & EIsRomBitmap))
107 iFbs->SendCommand(EFbsMessClose, iHandle, Handle());
108 iFbs->iHelper->RemoveBitmap(*this);
110 if (KRomMBMInRamRSC && (iFlags & EIsRomBitmap))
112 // If it is a ROM bitmap, we have to check, is it a ROM bitmap located
113 // in RAM? If yes, then we have to deallocate the bitmap memory.
114 TBool isInRom = EFalse;
115 TInt ret = User::IsRomAddress(isInRom, iAddressPointer);
116 if (ret == KErrNone && !isInRom)
117 delete[] reinterpret_cast<TUint8*>(iAddressPointer);
119 iAddressPointer = NULL;
124 FBS_OST(OstTrace1( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_RESET_EXIT, "< this=0x%08x", (TUint)this );)
127 /** Tests whether or not the bitmap is read-only.
128 @return ETrue if the bitmap is read-only, EFalse otherwise.
132 EXPORT_C TBool CFbsBitmap::IsRomBitmap() const
134 return (iFlags & EIsReadOnlyBitmapMask) > 0;
137 /** Sets the bitmap to use a bitmap image stored in ROM.
138 @param aRomBitmapPointer Pointer to a bitmap stored in ROM.
139 @param aBitmapSizeInBytes On return, indicates the size of
141 @leave KErrUnknown aRomBitmapPointer is not in ROM, or has an invalid UID.
145 EXPORT_C void CFbsBitmap::SetRomBitmapL(CBitwiseBitmap* aRomBitmapPointer,TInt& aBitmapSizeInBytes)
147 TBool isInRom = EFalse;
148 TInt ret = User::IsRomAddress(isInRom,(TAny*)aRomBitmapPointer);
149 if (ret != KErrNone || !isInRom || aRomBitmapPointer->Uid() != KCBitwiseBitmapUid)
150 User::Leave(KErrUnknown);
153 iAddressPointer = aRomBitmapPointer;
154 iFlags = EIsRomBitmap;
157 User::LeaveIfError(iFbs->AllocScanLineBuffer(aRomBitmapPointer->iByteWidth + 4));
158 aBitmapSizeInBytes = Align4(aRomBitmapPointer->iHeader.iBitmapSize + 28);
161 CBitwiseBitmap* CFbsBitmap::Address() const
165 return iAddressPointer;
168 EXPORT_C CBitwiseBitmap* CFbsBitmap::CleanAddress() const
172 // Don't try to clean a dirty bitmap between calls to BeginDataAccess() and EndDataAccess(), i.e. iUseCount > 0
173 // ROM bitmaps can never be dirty
174 if (!(iFlags & EIsReadOnlyBitmapMask) && iUseCount == 0 && iAddressPointer->iSettings.IsDirtyBitmap())
176 TPckgBuf<TBmpHandles> handlebuf;
177 TIpcArgs args(iHandle, &handlebuf);
178 if (iFbs->SendCommand(EFbsMessBitmapClean, args) == KErrNone)
180 const_cast<CFbsBitmap*>(this)->iHandle = handlebuf().iHandle;
181 const_cast<CFbsBitmap*>(this)->iServerHandle = handlebuf().iServerHandle;
182 const_cast<CFbsBitmap*>(this)->iAddressPointer = (CBitwiseBitmap*)(iFbs->HeapBase() + handlebuf().iAddressOffset);
185 return iAddressPointer;
188 inline CBitwiseBitmap* CFbsBitmap::BeginDataAccessAndGetCleanAddress(TUint32*& aDataAddress) const
191 CBitwiseBitmap* bmp = Address();
192 // aDataAddress should be consistent with bmp since after the call to BeginDataAccess()
193 // the call to DataAddress() will not clean the bitmap again
194 aDataAddress = DataAddress();
198 /** Gets the address of the first pixel in the bitmap.
199 The first pixel is at the top-left. Access to the pixel data of a bitmap
200 should be surrounded by calls to BeginDataAccess() and EndDataAccess(),
201 otherwise performance may be degraded on certain platforms.
203 Note: Performing a Resize() or Compress() operation changes the value returned by this function.
204 @return The address of the first pixel of the bitmap.
207 @see CFbsBitmap::BeginDataAccess()
208 @see CFbsBitmap::EndDataAccess()
210 EXPORT_C TUint32* CFbsBitmap::DataAddress() const
212 if(!iHandle) return(NULL);
213 CBitwiseBitmap* bmp = CleanAddress();
215 if (!(iFlags & EIsReadOnlyBitmapMask) && (iUseCount == 0))
216 bmp->iSettings.SetVolatileBitmap();
218 if(bmp->iUid.iUid==KCBitwiseBitmapHardwareUid.iUid) // RHardwareBitmap
220 RHardwareBitmap hwb(bmp->iDataOffset); // iDataOffset = handle for hardware bitmap
221 TAcceleratedBitmapInfo info;
222 const TInt ret = hwb.GetInfo(info);
223 return ret!=KErrNone ? NULL : (reinterpret_cast<TUint32*>(info.iAddress));
226 if (bmp->iHeap == NULL)
227 return(reinterpret_cast<TUint32*>((TUint8*)bmp+bmp->iDataOffset));
228 return(reinterpret_cast<TUint32*>(iFbs->iLargeBitmapChunk.Base()+bmp->iDataOffset));
231 /** Gets the length in bytes between scanlines in memory.
232 @return The length in bytes between scanlines in memory.
236 EXPORT_C TInt CFbsBitmap::DataStride() const
243 CBitwiseBitmap* bmp = CleanAddress();
249 return bmp->DataStride();
252 /** Creates a bitmap with the specified size and display mode. The bitmap is
253 created on the font and bitmap server's shared heap.
254 @param aSizeInPixels The size of the bitmap to be created.
255 @param aDispMode The display mode of the bitmap to be created.
256 @return KErrNone if successful; KErrCouldNotConnect if no connection to the
257 font and bitmap server could be made; KErrArgument if either the width or height specified
258 in aSizeInPixels are negative or if the requested display mode is invalid; KErrTooBig
259 if the requested size is too big.
263 EXPORT_C TInt CFbsBitmap::Create(const TSize& aSizeInPixels,TDisplayMode aDispMode)
265 FBS_OST(OstTraceExt4(GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_CREATE_ENTRY, "> this=0x%08x; w=%d; h=%d; dm=%d", (TUint)this, aSizeInPixels.iWidth, aSizeInPixels.iHeight, aDispMode); )
266 TInt err = DoCreate(aSizeInPixels,aDispMode,KUidCFbsBitmapCreation);
267 FBS_OST(TInt ssh = (iFbs ? iFbs->ServerSessionHandle() : 0);)
268 FBS_OST(OstTraceExt5(GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_CREATE_EXIT, "< this=0x%08x; err=%d; iH=0x%08x; iSH=0x%08x; iSSH=0x%08x", (TUint)this, err, iHandle, iServerHandle, ssh); )
272 TInt CFbsBitmap::DoCreate(const TSize& aSizeInPixels, TDisplayMode aDispMode, TUid aUid, TInt aDataSize)
274 if(!iFbs) return(KErrCouldNotConnect);
275 if (aDispMode <= ENone || aDispMode == ERgb || aDispMode >= EColorLast) return KErrArgument;
276 if(aSizeInPixels.iWidth<0 || aSizeInPixels.iHeight<0) return(KErrArgument);
277 if (aDataSize < 0) return KErrArgument;
280 bmpspec.iSizeInPixels=aSizeInPixels;
281 bmpspec.iDispMode=aDispMode;
282 bmpspec.iHandle = aUid.iUid; // Use iHandle to pass UID
283 bmpspec.iServerHandle = aDataSize; // Use iServerHandle to pass data size
284 TPckgBuf<TBmpSpec> b;
287 TInt ret=iFbs->SendCommand(EFbsMessBitmapCreate,args);
288 if(ret!=KErrNone) return(ret);
290 iServerHandle=b().iServerHandle;
291 iAddressPointer=(CBitwiseBitmap*)(iFbs->HeapBase()+b().iAddressOffset);
292 if (aDataSize > 0) // explicitly specified data size means extended bitmap
294 iFlags = EIsExtendedBitmap;
296 ret = iFbs->iHelper->AddBitmap(*this);
299 return iFbs->AllocScanLineBuffer(CBitwiseBitmap::ByteWidth(aSizeInPixels.iWidth, aDispMode)+4);
302 /** Creates a hardware bitmap with a size and display mode.
303 @param aSizeInPixels The bitmap's width and height in pixels.
304 @param aDispMode The bitmap's display mode.
305 @param aCreatorUid The UID of the application calling this function. This is
306 used to allow segregation of the memory used for hardware bitmaps. For instance,
307 if a device has video memory attached to display and graphics accelerator
308 hardware, this UID is used to determine whether any video memory is pre-allocated
309 for that application's use.
310 @return KErrNone if successful, otherwise one of the system wide error codes.
311 These include KErrCouldNotConnect if no connection has been made to the font
312 and bitmap server, KErrArgument if either the width or height specified in
313 aSizeInPixels are negative or if the requested display mode is invalid, or KErrNotSupported
314 if hardware bitmaps are not supported on the device.
318 EXPORT_C TInt CFbsBitmap::CreateHardwareBitmap(const TSize& aSizeInPixels,TDisplayMode aDispMode,TUid aCreatorUid)
320 FBS_OST(OstTraceExt5( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_CREATEHARDWAREBITMAP_ENTRY, "> this=0x%08x; w=%d; h=%d; dm=%d; uid=0x%08x", (TUint)this, aSizeInPixels.iWidth, aSizeInPixels.iHeight, aDispMode, aCreatorUid.iUid);)
321 TInt err = DoCreate(aSizeInPixels,aDispMode,aCreatorUid);
322 FBS_OST(TInt ssh = (iFbs ? iFbs->ServerSessionHandle() : 0);)
323 FBS_OST(OstTraceExt5( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_CREATEHARDWAREBITMAP_EXIT, "< this=0x%08x; err=%d; iH=0x%08x; iSH=0x%08x; iSSH=0x%08x", (TUint)this, err, iHandle, iServerHandle, ssh);)
327 /** Resets the pixel-size of the bitmap.
328 If the new size is bigger than the old, the original bitmap is still situated
329 at (0,0), but pixels outside the range of the old pixel-size are set to zero.
330 @param aSizeInPixels The new size of the bitmap.
331 @return KErrNone if successful; KErrArgument if the new size is illegal;
332 KErrGeneral if the bitmap has not yet been created; KErrAccessDenied if the
333 bitmap is in ROM or is an extended bitmap; otherwise another of the system-wide error codes.
337 EXPORT_C TInt CFbsBitmap::Resize(const TSize& aSizeInPixels)
339 if(aSizeInPixels.iWidth<0 || aSizeInPixels.iHeight<0)
340 return(KErrArgument);
341 if(aSizeInPixels.iWidth>KMaxPixelSize || aSizeInPixels.iHeight>KMaxPixelSize)
345 if (iFlags & EIsReadOnlyBitmapMask)
346 return(KErrAccessDenied);
347 TPckgBuf<TBmpHandles> handlebuf;
348 TIpcArgs args(iHandle, aSizeInPixels.iWidth, aSizeInPixels.iHeight, &handlebuf);
349 TInt err = iFbs->SendCommand(EFbsMessBitmapResize, args);
352 iHandle = handlebuf().iHandle;
353 iServerHandle = handlebuf().iServerHandle;
354 iAddressPointer = (CBitwiseBitmap*)(iFbs->HeapBase() + handlebuf().iAddressOffset);
355 return iFbs->AllocScanLineBuffer(CBitwiseBitmap::ByteWidth(aSizeInPixels.iWidth, DisplayMode())+4);
358 /** Gets the display mode of the bitmap.
359 @return The display mode of the bitmap.
363 EXPORT_C TDisplayMode CFbsBitmap::DisplayMode() const
365 if(iHandle==NULL) return(ENone);
366 return CleanAddress()->DisplayMode();
369 /** Returns the display mode that was used to create the bitmap.
370 @return The display mode used to create the bitmap.
374 EXPORT_C TDisplayMode CFbsBitmap::InitialDisplayMode() const
380 return CleanAddress()->InitialDisplayMode();
384 Changes the display mode of the bitmap.
385 The requested display mode cannot be greater (in bpp value) than the initial display mode.
386 This method cannot leave, for instance because of an out of memory condition. No
387 additional memory is allocated or leaving methods called.
388 The bitmap's content is preserved when converting it to the requested display mode,
389 but there may be some loss of quality.
392 @param aDisplayMode The requested display mode.
393 @return KErrArgument if the requested mode is invalid, or has a greater bpp value
394 than the initial mode. KErrNotSupported if the bitmap is compressed, or is a
395 ROM bitmap, an extended bitmap or a hardware bitmap. KErrGeneral if the bitmap
396 handle is NULL. KErrNone if the method call is successful.
397 @see CFbsBitmap::InitialDisplayMode()
399 EXPORT_C TInt CFbsBitmap::SetDisplayMode(TDisplayMode aDisplayMode)
406 CBitwiseBitmap* bmp = BeginDataAccessAndGetCleanAddress(data);
407 TInt err = bmp->SetDisplayMode(aDisplayMode, data);
408 EndDataAccess(EFalse);
412 /** Duplicates a bitmap.
413 This function does not create a copy of the bitmap. It just assigns another
414 handle to the bitmap in the font and bitmap server, and sets this object's
415 handle to that. If the specified bitmap is in the ROM, it just assigns a pointer
417 @param aHandle The handle to an existing bitmap.
418 @return KErrNone if successful; KErrCouldNotConnect if no connection to the
419 font and bitmap server could be made; KErrUnknown if no bitmap could be found
420 with the specified handle number.
423 @see CFbsBitmap::Handle()
425 EXPORT_C TInt CFbsBitmap::Duplicate(TInt aBitmapHandle)
428 FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_DUPLICATE_ENTRY, "> this=0x%08x; iH=0x%08x;", (TUint)this, aBitmapHandle);)
431 ret = KErrCouldNotConnect;
432 FBS_OST(OstTrace1( TRACE_ERROR, CFBSBITMAP_DUPLICATE_ERROR, "! this=0x%08x; !iFbs", (TUint)this);)
434 else if(!aBitmapHandle)
437 FBS_OST(OstTrace1( TRACE_ERROR, CFBSBITMAP_DUPLICATE_ERROR2, "! this=0x%08x; !aBitmapHandle", (TUint)this);)
441 TBool isinrom = EFalse;
442 ret = User::IsRomAddress(isinrom, (TAny*)aBitmapHandle);
447 ret = DuplicateInRom(aBitmapHandle);
448 FBS_OST_IF(ret != KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_DUPLICATE_ERROR4, "! this=0x%08x; DuplicateInRom() returned %d;", (TUint)this, ret);)
452 ret = DuplicateInRam(aBitmapHandle);
453 FBS_OST_IF(ret != KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_DUPLICATE_ERROR5, "! this=0x%08x; DuplicateInRam() returned %d;", (TUint)this, ret);)
458 FBS_OST(OstTraceExt2( TRACE_ERROR, CFBSBITMAP_DUPLICATE_ERROR3, "! this=0x%08x; IsRomAddress() returned %d", (TUint)this, ret);)
462 FBS_OST(TInt ssh = (iFbs ? iFbs->ServerSessionHandle() : 0);)
463 FBS_OST(OstTraceExt5( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_DUPLICATE_EXIT, "< this=0x%08x; iH=0x%08x; iSH=0x%08x; ret=%d; iSSH=0x%08x", (TUint)this, iHandle, iServerHandle, ret, ssh);)
467 /** Duplicates a bitmap where the bitmap handle refers to a rom bitmap.
468 @param aBitmapHandle A valid Rom bitmap handle.
469 @return KErrNone on success.
471 TInt CFbsBitmap::DuplicateInRom(TInt aBitmapHandle)
475 TUid uid = ((CBitwiseBitmap*)aBitmapHandle)->Uid();
476 if (uid != KCBitwiseBitmapUid)
478 FBS_OST(OstTraceExt2( TRACE_ERROR, CFBSBITMAP_DUPLICATEINROM_ERROR, "! this=0x%08x; 0x%08x != KCBitwiseBitmapUid", (TUint)this, (TUint)uid.iUid);)
483 iAddressPointer = (CBitwiseBitmap*)aBitmapHandle;
484 iFlags = EIsRomBitmap;
486 ret = iFbs->AllocScanLineBuffer(iAddressPointer->iByteWidth + 4);
487 FBS_OST_IF(ret!=KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_DUPLICATEINROM_ERROR2, "! this=0x%08x; AllocScanLineBuffer() returned %d", (TUint)this, ret);)
492 /** Duplicates a bitmap where the bitmap handle refers to a ram bitmap
493 @param aBitmapHandle A valid Ram bitmap handle.
494 @return KErrNone on success.
496 TInt CFbsBitmap::DuplicateInRam(TInt aBitmapHandle)
501 TPckgBuf<TBmpHandles> b;
502 TIpcArgs args(aBitmapHandle,&b);
503 ret=iFbs->SendCommand(EFbsMessBitmapDuplicate,args);
504 FBS_OST_IF(ret!=KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_DUPLICATEINRAM_ERROR, "! this=0x%08x; SendCommand(EFbsMessBitmapDuplicate) returned %d", (TUint)this, ret);)
508 iServerHandle=b().iServerHandle;
509 iAddressPointer=(CBitwiseBitmap*)(iFbs->HeapBase()+b().iAddressOffset);
510 if (iAddressPointer->iUid.iUid != KCBitwiseBitmapUid.iUid && iAddressPointer->iUid.iUid != KCBitwiseBitmapHardwareUid.iUid)
512 iFlags = EIsExtendedBitmap;
514 ret = iFbs->iHelper->AddBitmap(*this);
515 FBS_OST_IF(ret!=KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_DUPLICATEINRAM_ERROR2, "! this=0x%08x; AddBitmap() returned %d", (TUint)this, ret);)
518 ret = iFbs->AllocScanLineBuffer(iAddressPointer->iByteWidth+4);
519 FBS_OST_IF(ret!=KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_DUPLICATEINRAM_ERROR3, "! this=0x%08x; AllocScanLineBuffer() returned %d", (TUint)this, ret);)
525 /** Loads a specific bitmap from a multi-bitmap file.
526 The bitmap may be shared by other font and bitmap server clients.
527 @param aFileName The filename of the multi-bitmap (.mbm) file.
528 @param aId The bitmap identifier.
529 @param aShareIfLoaded Specifies whether or not the loaded bitmap will be made
530 available for sharing between font and bitmap server clients.
531 @return KErrNone if successful, otherwise another of the system error
536 EXPORT_C TInt CFbsBitmap::Load(const TDesC& aFileName,TInt32 aId,TBool aShareIfLoaded)
538 FBS_OST(OstTraceExt4( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOAD_ENTRY, "> this=0x%08x; file=%S, id=0x%08x; share=%d", (TUint)this, aFileName, aId, aShareIfLoaded);)
539 TInt err = Load(aFileName,aId,aShareIfLoaded,0);
540 FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOAD_EXIT, "< this=0x%08x; err=%d", (TUint)this, err);)
544 /** Loads a specific bitmap from a multi-bitmap file.
545 The bitmap may be shared by other font and bitmap server clients.
546 @param aFileName The filename of the multi-bitmap (.mbm) file.
547 @param aId The bitmap identifier.
548 @param aShareIfLoaded Specifies whether or not the loaded bitmap will be made
549 available for sharing between FBSERV clients.
550 @param aFileOffset Bitmap file section offset within the file.
551 @return KErrNone if successful, otherwise another of the system error codes.
555 EXPORT_C TInt CFbsBitmap::Load(const TDesC& aFileName,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset)
558 FBS_OST(OstTraceExt5( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOAD2_ENTRY, "> this=0x%08x; file=%S, id=0x%08x; share=%d; off=%d", (TUint)this, aFileName, aId, aShareIfLoaded, aFileOffset);)
561 FBS_OST(OstTrace1( TRACE_ERROR, CFBSBITMAP_LOAD2_ERROR, "! this=0x%08x; !iFbs", (TUint)this);)
562 err = KErrCouldNotConnect;
567 TUint32* rompointer = NULL;
568 //access using filename has the advantage of using rom address lookup cache
569 IsFileInRom(aFileName, rompointer);
570 TBool romPointerValid;
571 err = DoLoadFromRom(rompointer, aId, aFileOffset, romPointerValid);
574 _LIT(KResourcePath, "?:\\Resource\\*");
575 TInt match = aFileName.MatchF(KResourcePath);
576 //if the file is in the resource directory we don't need to check capabilities and the file can just be opened on the server side.
579 err = DoLoad(aFileName,aId,aShareIfLoaded,aFileOffset);
580 FBS_OST_IF(err!=KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_LOAD2_ERROR3, "! this=0x%08x; DoLoad returned %d", (TUint)this, err);)
585 err = file.Open(iFbs->FileServer(),aFileName,EFileShareReadersOnly);
588 err = DoLoad(file,aId,aShareIfLoaded,aFileOffset);
589 FBS_OST_IF(err!=KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_LOAD2_ERROR4, "! this=0x%08x; DoLoad returned %d", (TUint)this, err);)
595 FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOAD2_EXIT, "< this=0x%08x; err=%d", (TUint)this, err);)
599 /** Loads and compresses a specific bitmap from a multi-bitmap file.
600 The bitmap may be shared by other font and bitmap server clients.
601 If the bitmap is loaded from ROM then compression is not allowed.
602 @param aFileName The filename of the multi-bitmap (.mbm) file.
603 @param aId The bitmap identifier.
604 @param aShareIfLoaded Specifies whether or not the loaded bitmap will be
605 made available for sharing between FBSERV clients.
606 @return KErrNone if successful, otherwise another of the system-wide error
611 EXPORT_C TInt CFbsBitmap::LoadAndCompress(const TDesC& aFileName,TInt32 aId,TBool aShareIfLoaded)
613 FBS_OST(OstTraceExt4( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOADANDCOMPRESS_ENTRY, "> this=0x%08x; file=%S; id=0x%08x; share=%d", (TUint)this, aFileName, aId, aShareIfLoaded);)
614 TInt ret = LoadAndCompress(aFileName, aId, aShareIfLoaded, 0);
615 FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOADANDCOMPRESS_EXIT, "< this=0x%08x; err=%d", (TUint)this, ret);)
619 /** Loads and compresses a specific bitmap from a multi-bitmap file.
620 The bitmap may be shared by other font and bitmap server clients. If the
621 bitmap is loaded from ROM then compression is not allowed.
622 @param aFileName The filename of the multi-bitmap (.mbm) file.
623 @param aId The bitmap identifier.
624 @param aShareIfLoaded Specifies whether or not the loaded bitmap will be made
625 available for sharing between FBSERV clients.
626 @param aFileOffset Bitmap file section offset within the file.
627 @return KErrNone if successful, otherwise another of the system-wide error
632 EXPORT_C TInt CFbsBitmap::LoadAndCompress(const TDesC& aFileName,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset)
634 FBS_OST(OstTraceExt5( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOADANDCOMPRESS2_ENTRY, "> this=0x%08x; file=%S, id=0x%08x; share=%d; off=%d", (TUint)this, aFileName, aId, aShareIfLoaded, aFileOffset);)
635 TInt err = Load(aFileName,aId,aShareIfLoaded,aFileOffset);
638 err = !(iFlags & EIsRomBitmap) ? Compress() : KErrAccessDenied;
639 FBS_OST_IF(err!=KErrNone, OstTraceExt3( TRACE_ERROR, CFBSBITMAP_LOADANDCOMPRESS2_ERROR, "! this=0x%08x; iFlags=0x%08x; err=%d", (TUint)this, (TUint)iFlags, err);)
641 FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOADANDCOMPRESS2_EXIT, "< this=0x%08x; err=%d", (TUint)this, err);)
645 /** Saves the bitmap as a direct file store.
646 The file store overwrites any existing file with the same name.
647 @param aFilename The name of the file.
648 @return KErrNone if successful, KErrNotSupported if this CFbsBitmap is an
649 extended bitmap, otherwise another of the system-wide error codes.
653 EXPORT_C TInt CFbsBitmap::Save(const TDesC& aFilename)
660 TInt ret=file.Replace(iFbs->FileServer(),aFilename,EFileWrite);
661 if(ret!=KErrNone) return(ret);
662 TRAP(ret,DoSaveL(file));
667 /** Saves the bitmap as a direct file store using an opened file handle.
668 The file store overwrites any existing file with the same name.
669 @param aFile The opened file handle
670 @return KErrNone if successful, KErrNotSupported if this CFbsBitmap is an
671 extended bitmap, otherwise another of the system-wide error codes.
675 EXPORT_C TInt CFbsBitmap::Save(RFile& aFile)
681 TRAPD(ret,DoSaveL(aFile));
685 void CFbsBitmap::DoSaveL(RFile& aFile)
687 CDirectFileStore* filestore=CDirectFileStore::NewLC(aFile); // create from open file
688 TUidType uidtype(KDirectFileStoreLayoutUid,KMultiBitmapFileImageUid);
689 filestore->SetTypeL(uidtype);
690 RStoreWriteStream bmpstream;
691 TStreamId bmpstreamid=bmpstream.CreateLC(*filestore); // create bitmap stream
692 ExternalizeL(bmpstream);
694 CleanupStack::PopAndDestroy(); // bitmap stream
695 RStoreWriteStream rootstream;
696 TStreamId rootstreamid=rootstream.CreateLC(*filestore); // create root stream
697 rootstream.WriteInt32L(1); // number of bitmaps
698 rootstream<<bmpstreamid; // stream id of bitmap
699 rootstream.CommitL();
700 CleanupStack::PopAndDestroy(); // root stream
701 filestore->SetRootL(rootstreamid);
702 filestore->CommitL();
703 CleanupStack::PopAndDestroy(); // file store
706 /** Constructs a multi-bitmap file.
707 @param aFilename The name of the multi-bitmap file to be created.
708 @param aNumSources The number of bitmaps to store in the file.
709 @param aSources An array of pointers to bitmaps to be stored.
710 @param aSourceIds An array of identifiers for the bitmaps to be stored.
714 EXPORT_C void CFbsBitmap::StoreL(const TDesC& aFilename,TInt aNumSources,const TDesC* aSources[],TInt32 aSourceIds[])
716 CFbsBitmap* bitmap = new(ELeave) CFbsBitmap;
717 CleanupStack::PushL(bitmap);
718 CDirectFileStore* filestore = CDirectFileStore::ReplaceLC(bitmap->iFbs->FileServer(),aFilename,EFileWrite);
719 DoStoreL(filestore,bitmap,aNumSources,aSources,aSourceIds);
720 CleanupStack::PopAndDestroy(2,bitmap);
723 /** Constructs a multi-bitmap file using an opened file handle.
724 @param aFile The opened file handle of multi-bitmap file
725 @param aNumSources The number of bitmaps to store in the file.
726 @param aSources An array of pointers to bitmaps to be stored.
727 @param aSourceIds An array of identifiers for the bitmaps to be stored.
731 EXPORT_C void CFbsBitmap::StoreL(RFile& aFile,TInt aNumSources,const TDesC* aSources[],TInt32 aSourceIds[])
733 CDirectFileStore* filestore = CDirectFileStore::NewLC(aFile);
734 DoStoreL(filestore,NULL,aNumSources,aSources,aSourceIds);
735 CleanupStack::PopAndDestroy(filestore);
741 void CFbsBitmap::DoStoreL(CDirectFileStore* aFileStore,CFbsBitmap* aBitmap,TInt aNumSources,const TDesC* aSources[],TInt32 aSourceIds[])
743 if(aNumSources<1 || aSources==NULL) User::Leave(KErrArgument);
745 for(;count<aNumSources;count++)
746 if(aSources[count]==NULL) User::Leave(KErrArgument);
747 TStreamId* ids=new(ELeave) TStreamId[aNumSources];
748 CleanupArrayDeletePushL(ids);
752 aBitmap=new(ELeave) CFbsBitmap;
753 CleanupStack::PushL(aBitmap);
756 TUidType uidtype(KDirectFileStoreLayoutUid,KMultiBitmapFileImageUid);
757 aFileStore->SetTypeL(uidtype);
758 for(count=0;count<aNumSources;count++)
760 User::LeaveIfError(aBitmap->Load(*aSources[count],aSourceIds[count]));
761 RStoreWriteStream bmpstream;
762 ids[count]=bmpstream.CreateLC(*aFileStore); // create bitmap stream
763 aBitmap->ExternalizeL(bmpstream);
765 CleanupStack::Pop(); // bitmap stream
767 RStoreWriteStream rootstream;
768 TStreamId rootstreamid=rootstream.CreateLC(*aFileStore); // create root stream
769 rootstream.WriteInt32L(aNumSources); // number of bitmaps
770 for(count=0;count<aNumSources;count++)
771 rootstream<<ids[count]; // stream ids of bitmaps
773 CleanupStack::Pop(); // root stream
774 aFileStore->SetRootL(rootstreamid);
775 CleanupStack::PopAndDestroy(nPushed); // ids [and bitmap]
778 /** Gets the bitmap's scanline for the specified line starting from the
780 The dither offset of the bitmap is taken to be TPoint(0,0).
781 @param aBuf The buffer in which the scanline is returned.
782 @param aPoint The start pixel.
783 @param aLength The number of pixels to get.
784 @param aDispMode Format to be used to write the data to the buffer.
788 EXPORT_C void CFbsBitmap::GetScanLine(TDes8& aBuf,const TPoint& aPoint,TInt aLength,TDisplayMode aDispMode) const
790 GetScanLine(aBuf,aPoint,aLength,TPoint(0,0),aDispMode);
793 /** Gets the bitmap's scanline for the specified line starting from the specified
794 point and using the specified dither offset.
795 @param aBuf The buffer in which the scanline is returned.
796 @param aPixel The start pixel.
797 @param aLength The number of pixels to get.
798 @param aDitherOffset The dither offset of the bitmap.
799 @param aDispMode Format to be used to write the data to the buffer.
803 EXPORT_C void CFbsBitmap::GetScanLine(TDes8& aBuf,const TPoint& aPoint,TInt aLength,const TPoint& aDitherOffset,TDisplayMode aDispMode) const
807 CBitwiseBitmap* bmp = BeginDataAccessAndGetCleanAddress(data);
808 CFbsRasterizer* rasterizer = NULL;
809 if ((iFlags & EIsExtendedBitmap) && iFbs)
811 rasterizer = iFbs->iHelper->Rasterizer();
814 CFbsRasterizer::TBitmapDesc desc;
815 desc.iSizeInPixels = bmp->SizeInPixels();
816 desc.iDispMode = bmp->DisplayMode();
817 desc.iDataType = bmp->iUid;
819 desc.iDataSize = bmp->iHeader.iBitmapSize - bmp->iHeader.iStructSize;
820 rasterizer->BeginBitmap(bmp->Extra()->iSerialNumber, desc, NULL);
823 bmp->GetScanLine(aBuf, aPoint, aLength, ETrue, aDitherOffset, aDispMode, data);
826 rasterizer->EndBitmap(bmp->Extra()->iSerialNumber);
828 EndDataAccess(ETrue);
831 /** Sets the bitmap's horizontal scanline at the specified y co-ordinate to the
832 scanline contained in the buffer.
833 @param aBuf The new scanline to be written to the bitmap.
834 @param aY The y co-ordinate of the scanline.
835 @panic FBSCLI 11 in debug builds if this is a compressed bitmap.
836 @panic FBSCLI 28 in debug builds if this is a read-only bitmap.
840 EXPORT_C void CFbsBitmap::SetScanLine(TDes8& aBuf,TInt aY) const
844 if (iFlags & EIsReadOnlyBitmapMask)
846 __ASSERT_DEBUG(EFalse, ::Panic(EFbsPanicBitmapReadOnly));
850 CBitwiseBitmap* bmp = BeginDataAccessAndGetCleanAddress(data);
851 if (bmp->IsCompressed())
853 EndDataAccess(ETrue);
854 __ASSERT_DEBUG(EFalse, ::Panic(EFbsBitmapInvalidCompression));
857 data = bmp->ScanLineAddress(data, aY);
858 TInt bytewidth = bmp->iByteWidth;
859 TInt bytelen=aBuf.Length();
860 if(bytelen<bytewidth) bytewidth=bytelen;
861 TInt wordlen=bytewidth>>2;
862 TUint32* ptr=(TUint32*)aBuf.Ptr();
863 TUint32* ptrlim=ptr+wordlen;
866 TInt limit=wordlen<<2;
869 TUint8* byteptr=(TUint8*)ptrlim;
870 TUint8* databyte=(TUint8*)data;
871 while(limit<bytewidth)
873 *databyte++=*byteptr++;
877 EndDataAccess(EFalse);
880 /** Gets the bitmap's vertical scanline starting at the specified x co-ordinate.
881 Note: The method only works for uncompressed bitmaps.
882 Note: The dither offset of the bitmap is taken to be TPoint(0,0).
883 @param aBuf The buffer in which the vertical scanline is returned.
884 @param aX The x co-ordinate of the vertical scanline.
885 @param aDispMode Format to be used to write the data to the buffer.
886 @panic FBSCLI 11 in debug builds if this is not an ucompressed bitmap or an extended bitmap.
890 EXPORT_C void CFbsBitmap::GetVerticalScanLine(TDes8& aBuf,TInt aX,TDisplayMode aDispMode) const
892 GetVerticalScanLine(aBuf,aX,TPoint(0,0),aDispMode);
895 /** Gets the bitmap's vertical scanline starting at the specified x co-ordinate
896 and using the specified dither offset.
897 Note: The method only works for uncompressed bitmaps.
898 @param aBuf The buffer in which the vertical scanline will be returned.
899 @param aX The x co-ordinate of the vertical scanline to get.
900 @param aDitherOffset The dither offset of the bitmap.
901 @param aDispMode Format to be used to write the data to the buffer.
902 @panic FBSCLI 11 in debug builds if this is not an ucompressed bitmap or an extended bitmap.
906 EXPORT_C void CFbsBitmap::GetVerticalScanLine(TDes8& aBuf,TInt aX,const TPoint& aDitherOffset,TDisplayMode aDispMode) const
910 CBitwiseBitmap* bmp = BeginDataAccessAndGetCleanAddress(data);
911 CFbsRasterizer* rasterizer = NULL;
912 if ((iFlags & EIsExtendedBitmap) && iFbs)
914 rasterizer = iFbs->iHelper->Rasterizer();
917 CFbsRasterizer::TBitmapDesc desc;
918 desc.iSizeInPixels = bmp->SizeInPixels();
919 desc.iDispMode = bmp->DisplayMode();
920 desc.iDataType = bmp->iUid;
922 desc.iDataSize = bmp->iHeader.iBitmapSize - bmp->iHeader.iStructSize;
923 rasterizer->BeginBitmap(bmp->Extra()->iSerialNumber, desc, NULL);
926 bmp->GetVerticalScanLine(aBuf, aX, ETrue, aDitherOffset, aDispMode, data, rasterizer);
929 rasterizer->EndBitmap(bmp->Extra()->iSerialNumber);
931 EndDataAccess(ETrue);
934 /** Gets the handle number of the bitmap.
935 The returned value can be used to give another thread access to the bitmap.
936 @return The handle number of the bitmap.
939 @see CFbsBitmap::Duplicate()
941 EXPORT_C TInt CFbsBitmap::Handle() const
945 if (iFlags & EIsRomBitmap)
946 return TInt(iAddressPointer);
948 return(iServerHandle);
951 /** Creates a bitmap header.
952 This is used when streaming bitmaps to stores.
953 @return The bitmap header for the bitmap.
957 EXPORT_C SEpocBitmapHeader CFbsBitmap::Header() const
960 return CleanAddress()->iHeader;
961 SEpocBitmapHeader header;
965 /** Converts a horizontal dimension on the graphics device from pixels to twips.
966 @param aPixels A horizontal dimension on the graphics device in pixels.
967 @return A horizontal dimension on the graphics device in twips.
971 EXPORT_C TInt CFbsBitmap::HorizontalPixelsToTwips(TInt aPixels) const
973 if(iHandle==NULL) return(0);
974 return CleanAddress()->HorizontalPixelsToTwips(aPixels);
977 /** Converts a horizontal dimension on the graphics device from twips to pixels.
978 @param aTwips A horizontal dimension on the graphics device in twips.
979 @return A horizontal dimension on the graphics device in pixels.
983 EXPORT_C TInt CFbsBitmap::HorizontalTwipsToPixels(TInt aTwips) const
985 if(iHandle==NULL) return(0);
986 return CleanAddress()->HorizontalTwipsToPixels(aTwips);
989 /** Gets the RGB value of the specified pixel.
990 Note: The method only works for uncompressed bitmaps and extended bitmaps.
991 @param aColor On return, the RGB value of the specified pixel.
992 @param aPixel The pixel whose colour is to be determined.
993 @panic FBSCLI 11 in debug builds if this is a compressed bitmap.
997 EXPORT_C void CFbsBitmap::GetPixel(TRgb& aColor,const TPoint& aPoint) const
1005 CBitwiseBitmap* bmp = BeginDataAccessAndGetCleanAddress(data);
1006 CFbsRasterizer* rasterizer = NULL;
1007 if ((iFlags & EIsExtendedBitmap) && iFbs)
1009 rasterizer = iFbs->iHelper->Rasterizer();
1012 CFbsRasterizer::TBitmapDesc desc;
1013 desc.iSizeInPixels = bmp->SizeInPixels();
1014 desc.iDispMode = bmp->DisplayMode();
1015 desc.iDataType = bmp->iUid;
1017 desc.iDataSize = bmp->iHeader.iBitmapSize - bmp->iHeader.iStructSize;
1018 rasterizer->BeginBitmap(bmp->Extra()->iSerialNumber, desc, NULL);
1021 bmp->GetPixel(aColor, aPoint, data, rasterizer);
1024 rasterizer->EndBitmap(bmp->Extra()->iSerialNumber);
1026 EndDataAccess(ETrue);
1029 /** Gets the pixel-size of the bitmap.
1030 @return The size of the bitmap, in pixels.
1034 EXPORT_C TSize CFbsBitmap::SizeInPixels() const
1037 if(!iHandle) return(zero);
1038 return CleanAddress()->SizeInPixels();
1041 /** Sets the twip-size of the bitmap by converting the bitmaps pixel-size from
1042 pixels to twips, using the conversion functions in the specified graphics
1044 @param aMap The graphics device map to be used for providing pixel to twip
1049 EXPORT_C void CFbsBitmap::SetSizeInTwips(const MGraphicsDeviceMap* aMap)
1051 if (!iHandle || (iFlags & EIsRomBitmap) || aMap == NULL)
1053 TSize size=SizeInPixels();
1054 size.iWidth=aMap->HorizontalPixelsToTwips(size.iWidth);
1055 size.iHeight=aMap->VerticalPixelsToTwips(size.iHeight);
1056 iFbs->SetCallBackPtr(&iServerHandle);
1058 // SizeInPixels() called CleanAddress() so call Address() now to make sure we don't clean the bitmap twice
1059 Address()->iHeader.iSizeInTwips=size;
1062 /** Sets the twip-size of the bitmap directly to the specified size.
1063 @param aSizeInTwips The new size of the bitmap, in twips.
1067 EXPORT_C void CFbsBitmap::SetSizeInTwips(const TSize& aSizeInTwips)
1069 if (!iHandle || (iFlags & EIsRomBitmap))
1071 iFbs->SetCallBackPtr(&iServerHandle);
1073 CleanAddress()->iHeader.iSizeInTwips = aSizeInTwips;
1076 /** Externalises the bitmap to the specified stream. Not supported for extended bitmaps.
1077 @param aStream The write stream.
1081 EXPORT_C void CFbsBitmap::ExternalizeL(RWriteStream& aStream) const
1084 User::Leave(KErrGeneral);
1086 Address()->ExternalizeL(aStream, *this);
1087 EndDataAccess(ETrue);
1090 /** Externalises that area of the bitmap contained within a specified
1091 rectangular area. Not supported for extended bitmaps.
1092 @param aStream The write stream
1093 @param aRect The rectangular area of the bitmap to externalise. The bitmap
1094 that is externalized will be of this size.
1098 EXPORT_C void CFbsBitmap::ExternalizeRectangleL(RWriteStream& aStream,const TRect& aRect) const
1101 User::Leave(KErrGeneral);
1103 Address()->ExternalizeRectangleL(aStream, aRect, *this);
1104 EndDataAccess(ETrue);
1107 /** Internalises a CFbsBitmap from a stream.
1108 @param aStream The read stream.
1112 EXPORT_C void CFbsBitmap::InternalizeL(RReadStream& aStream)
1114 if(!iFbs) User::Leave(KErrCouldNotConnect);
1116 SEpocBitmapHeader header;
1117 CBitwiseBitmap::InternalizeHeaderL(aStream,header);
1119 TDisplayMode dispmode = CBitwiseBitmap::DisplayMode(header.iBitsPerPixel,header.iColor);
1120 User::LeaveIfError(Create(header.iSizeInPixels,dispmode));
1123 CBitwiseBitmap* bmp=BeginDataAccessAndGetCleanAddress(data);
1124 bmp->iHeader=header;
1125 TInt bytesize = header.iBitmapSize - header.iStructSize;
1128 bmp->DoInternalizeL(aStream, bytesize, data);
1129 EndDataAccess(EFalse);
1133 EndDataAccess(ETrue);
1137 EXPORT_C TInt CFbsBitmap::Compress()
1139 return Compress(ERLECompression);
1142 /** Compresses bitmap in RAM.
1143 @param aScheme specifies preferred compression type ERLECompression or EPaletteCompression
1144 @return KErrNone on success, KErrGeneral if the bitmap handle is NULL, KErrAccessDenied if
1145 the bitmap is in ROM or it is an extended bitmap, otherwise one of the system wide error codes.
1149 EXPORT_C TInt CFbsBitmap::Compress(TBitmapfileCompressionScheme aScheme)
1153 if (iFlags & EIsReadOnlyBitmapMask)
1154 return KErrAccessDenied;
1155 TPckgBuf<TBmpHandles> handlebuf;
1156 TIpcArgs args(iHandle, aScheme, &handlebuf);
1157 TInt err = iFbs->SendCommand(EFbsMessBitmapCompress, args);
1158 if (err != KErrNone)
1160 iHandle = handlebuf().iHandle;
1161 iServerHandle = handlebuf().iServerHandle;
1162 iAddressPointer = (CBitwiseBitmap*)(iFbs->HeapBase() + handlebuf().iAddressOffset);
1166 /** Submits the bitmap for asynchronous background compression.
1167 @param aRequestStatus The request status which will be completed with the appropriate error code after the compression has finished
1168 The error code will be KErrNone on success, KErrGeneral if the bitmap handle is NULL, KErrAccessDenied if the
1169 bitmap is in ROM or it is an extended bitmap, otherwise one of the system wide error codes.
1173 EXPORT_C void CFbsBitmap::CompressInBackground(TRequestStatus& aRequestStatus)
1175 CompressInBackground(aRequestStatus, ERLECompression);
1178 /** Submits the bitmap for asynchronous background compression. No notification will be provided when the compression has completed.
1179 @return KErrNone if the bitmap was successfully submitted to the background compression queue, KErrGeneral if the bitmap handle is NULL,
1180 KErrAccessDenied if the bitmap is in ROM or it is an extended bitmap, otherwise another of the system-wide error codes.
1184 EXPORT_C TInt CFbsBitmap::CompressInBackground()
1186 return CompressInBackground(ERLECompression);
1189 /** Submits the bitmap for asynchronous background compression.
1190 @param aRequestStatus The request status which will be completed with the appropriate error code after the compression has finished.
1191 The error code will be KErrNone on success, KErrGeneral if the bitmap handle is NULL, KErrAccessDenied if the
1192 bitmap is in ROM or it is an extended bitmap, otherwise one of the system wide error codes.
1193 @param aScheme Specifies preferred compression type: ERLECompression or EPaletteCompression
1197 EXPORT_C void CFbsBitmap::CompressInBackground(TRequestStatus& aRequestStatus, TBitmapfileCompressionScheme aScheme)
1199 TRequestStatus* reqStat = &aRequestStatus;
1200 aRequestStatus = KRequestPending;
1202 User::RequestComplete(reqStat, KErrGeneral);
1203 else if (iFlags & EIsReadOnlyBitmapMask)
1204 User::RequestComplete(reqStat, KErrAccessDenied);
1207 TIpcArgs args(iHandle, aScheme, ETrue);
1208 iFbs->SendCommand(EFbsMessBitmapBgCompress, args, aRequestStatus);
1212 /** Submits the bitmap for asynchronous background compression. No notification will be provided when the compression has completed.
1213 @return KErrNone if the bitmap was successfully submitted to the background compression queue, KErrGeneral if the bitmap handle is NULL,
1214 KErrAccessDenied if the bitmap is in ROM or it is an extended bitmap, otherwise another of the system-wide error codes.
1218 EXPORT_C TInt CFbsBitmap::CompressInBackground(TBitmapfileCompressionScheme aScheme)
1222 if (iFlags & EIsReadOnlyBitmapMask)
1223 return KErrAccessDenied;
1224 TIpcArgs args(iHandle, aScheme, EFalse);
1225 return iFbs->SendCommand(EFbsMessBitmapBgCompress, args);
1228 /**Tests whether the bitmap located in RAM has been compressed.
1229 @return ETrue if the bitmap is compressed, EFalse otherwise.
1233 EXPORT_C TBool CFbsBitmap::IsCompressedInRAM() const
1235 CBitwiseBitmap* bitmap = CleanAddress();
1240 return bitmap->IsCompressedInRAM();
1243 /** Gets the twip-size of the bitmap.
1244 @return The size of the bitmap, in twips.
1248 EXPORT_C TSize CFbsBitmap::SizeInTwips() const
1251 if(iHandle==NULL) return(zero);
1252 return CleanAddress()->SizeInTwips();
1255 /** Converts a vertical dimension on the graphics device from pixels to twips.
1256 @param aPixels A vertical dimension on the graphics device in pixels.
1257 @return A vertical dimension on the graphics device in twips.
1261 EXPORT_C TInt CFbsBitmap::VerticalPixelsToTwips(TInt aPixels) const
1263 if(iHandle==NULL) return(0);
1264 return CleanAddress()->VerticalPixelsToTwips(aPixels);
1267 /** Converts a vertical dimension on the graphics device from twips to pixels.
1268 @param aTwips A vertical dimension on the graphics device in twips.
1269 @return A vertical dimension on the graphics device in pixels.
1273 EXPORT_C TInt CFbsBitmap::VerticalTwipsToPixels(TInt aTwips) const
1275 if(iHandle==NULL) return(0);
1276 return CleanAddress()->VerticalTwipsToPixels(aTwips);
1279 /** Tests whether or not the specified file is in ROM.
1280 @param aFilename The name of the file.
1281 @param aWord On return, contains the address of the file in ROM.
1282 @return ETrue if the file is in the ROM; EFalse otherwise.
1286 EXPORT_C TBool CFbsBitmap::IsFileInRom(const TDesC& aFilename,TUint32*& aWord)
1288 RFbsSession* fbs=RFbsSession::GetSession();
1289 __ASSERT_ALWAYS(fbs,Panic(EFbsPanicNoConnection));
1290 return fbs->LookupBitmapInROM (aFilename, (TAny*&)aWord);
1293 /** Tests whether or not the specified file is in ROM.
1294 @param aFile The file handle
1295 @param aWord On return, contains the address of the file in ROM.
1296 @return ETrue if the file is in the ROM; EFalse otherwise.
1300 EXPORT_C TBool CFbsBitmap::IsFileInRom(RFile& aFile,TUint32*& aWord)
1302 // cannot use rom lookup cache as filename is not available
1303 // offset must be initialised to zero to indicate beginning of the file
1305 return aFile.Seek(ESeekAddress,(TInt&)aWord)==KErrNone;
1308 /** Tests whether or not the bitmap is monochrome.
1309 Monochrome bitmaps have a display-mode of 1 bit-per-pixel.
1310 @return ETrue if the bitmap is monochrome; EFalse otherwise.
1314 EXPORT_C TBool CFbsBitmap::IsMonochrome() const
1316 if(!iHandle) return(EFalse);
1318 CBitwiseBitmap* bmp = BeginDataAccessAndGetCleanAddress(data);
1319 TBool isMonochrome = bmp->IsMonochrome(data);
1320 EndDataAccess(ETrue);
1321 return isMonochrome;
1324 /** Marks the beginning of direct access to the bitmap data.
1325 This function prepares the bitmap for direct access to its pixel data
1326 and should be used before calling DataAddress(), otherwise performance
1327 may be degraded on certain platforms.
1328 Calls to BeginDataAccess() must be coupled with subsequent calls to EndDataAccess().
1332 @see CFbsBitmap::DataAddress()
1333 @see CFbsBitmap::EndDataAccess()
1335 EXPORT_C void CFbsBitmap::BeginDataAccess() const
1337 FBS_OST_VERBOSE(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_BEGINDATAACCESS_ENTRY, "> this=0x%08x;", (TUint)this););
1338 FBS_OST_IF(!iHandle, OstTrace1(TRACE_ERROR, CFBSBITMAP_BEGINDATAACCESS_ERROR, "! this=0x%08x; !iHandle", (TUint)this););
1342 (void)CleanAddress(); //called for side-effect to make sure bitmap reference is current. Should be low overhead.
1343 const_cast<CFbsBitmap*>(this)->iUseCount++;
1346 FBS_OST_VERBOSE(OstTraceExt2(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_BEGINDATAACCESS_EXIT, "< this=0x%08x; iUseCount=%d;", (TUint)this, const_cast<CFbsBitmap*>(this)->iUseCount);)
1349 /** Marks the end of direct access to the bitmap data.
1350 Use this function after ending direct access to the bitmap data.
1351 Calls to EndDataAccess() must correspond to prior calls to BeginDataAccess().
1352 See BeginDataAccess() for more details.
1354 @param aReadOnly Whether or not the bitmap data has only been read since
1355 the corresponding call to BeginDataAccess().
1359 @param aReadOnly True if the bitmap data had only been read. False if the data has been modified.
1360 @see CFbsBitmap::BeginDataAccess()
1362 EXPORT_C void CFbsBitmap::EndDataAccess(TBool aReadOnly) const
1364 FBS_OST_VERBOSE(OstTraceExt2(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_ENDDATAACCESS_ENTRY, "> this=0x%08x; aReadOnly=%d;", (TUint)this, (TUint)aReadOnly);)
1365 FBS_OST_IF(!iHandle, OstTrace1(TRACE_ERROR, CFBSBITMAP_ENDDATAACCESS_ERROR, "! this=0x%08x; !iHandle", (TUint)this););
1368 const_cast<CFbsBitmap*>(this)->iUseCount--;
1369 if (!aReadOnly && !(iFlags & EIsReadOnlyBitmapMask))
1371 User::LockedInc(iAddressPointer->Extra()->iTouchCount);
1374 FBS_OST_VERBOSE(OstTraceExt2(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_ENDDATAACCESS_EXIT, "< this=0x%08x; iUseCount=%d;", (TUint)this, const_cast<CFbsBitmap*>(this)->iUseCount);)
1377 /** Locks the global bitmap heap.
1378 This function is deprecated, since it is no longer necessary to lock the global
1379 bitmap heap to prevent the pixel data from being moved in memory asynchronously,
1380 as the value returned by DataAddress() can now only change as a result of bitmap
1381 operations explicitly requested by clients of the Font and Bitmap Server.
1382 Calls to LockHeap() should be replaced by calls to BeginDataAccess().
1384 Calls to LockHeap() must be coupled with subsequent calls to CFbsBitmap::UnlockHeap().
1385 Code called between a LockHeap() - UnlockHeap() pair must not include any other calls to
1386 CFbsBitmap methods, which internally may call CFbsBitmap::LockHeap(). Also, code must
1387 not leave between a LockHeap() - UnlockHeap() pair.
1388 @note IMPORTANT: CFbsBitmap::LockHeap() cannot be used as a means of synchronization between
1389 threads concurrently accessing bitmap data.
1393 @see CFbsBitmap::UnlockHeap()
1394 @see CFbsBitmap::BeginDataAccess()
1396 EXPORT_C void CFbsBitmap::LockHeap(TBool /*aAlways*/) const
1398 FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_LOCKHEAP_ENTRY, "> this=0x%08x;", (TUint)this);)
1400 #ifdef SYMBIAN_DEBUG_FBS_LOCKHEAP
1401 //These debug checks now refer to the cleaned data address
1402 FBS_OST_IF(!iHandle, OstTrace1(TRACE_ERROR, CFBSBITMAP_LOCKHEAP_ERROR, "! this=0x%08x; !iHandle", (TUint)this););
1403 if (iHandle && !(iFlags & EIsRomBitmap)) // can't do anything with ROM bitmaps
1405 TThreadId threadId = RThread().Id();
1406 iFbs->iHelper->iDebugMutex.Wait();
1407 if (iAddressPointer->Extra()->iLockCount++ == 0)
1409 __ASSERT_ALWAYS(iAddressPointer->Extra()->iThreadId == TThreadId(KNullThreadId), Panic(EFbsPanicBadHeapLock));
1410 iAddressPointer->Extra()->iThreadId = threadId;
1413 __ASSERT_ALWAYS(iAddressPointer->Extra()->iThreadId == threadId, Panic(EFbsPanicBadHeapLock));
1414 iFbs->iHelper->iDebugMutex.Signal();
1417 FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_LOCKHEAP_EXIT, "< this=0x%08x;", (TUint)this);)
1420 /** Unlocks the global heap.
1421 This function is deprecated. See LockHeap() for more details.
1422 Calls to UnlockHeap() should be replaced by calls to EndDataAccess().
1423 Calls to UnlockHeap() must correspond to prior calls to LockHeap() or LockHeapLC().
1427 @see CFbsBitmap::LockHeap()
1428 @see CFbsBitmap::EndDataAccess()
1430 EXPORT_C void CFbsBitmap::UnlockHeap(TBool /*aAlways*/) const
1432 FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_UNLOCKHEAP_ENTRY, "> this=0x%08x;", (TUint)this);)
1433 FBS_OST_IF(!iHandle, OstTrace1(TRACE_ERROR, CFBSBITMAP_UNLOCKHEAP_ERROR, "! this=0x%08x; !iHandle", (TUint)this););
1436 #ifdef SYMBIAN_DEBUG_FBS_LOCKHEAP
1437 if (!(iFlags & EIsRomBitmap)) // can't do anything with ROM bitmaps
1439 TThreadId threadId = RThread().Id();
1440 iFbs->iHelper->iDebugMutex.Wait();
1441 __ASSERT_ALWAYS(iAddressPointer->Extra()->iLockCount > 0, Panic(EFbsPanicBadHeapLock));
1442 __ASSERT_ALWAYS(iAddressPointer->Extra()->iThreadId == threadId, Panic(EFbsPanicBadHeapLock));
1443 if (--iAddressPointer->Extra()->iLockCount == 0)
1444 iAddressPointer->Extra()->iThreadId = TThreadId(KNullThreadId);
1445 iFbs->iHelper->iDebugMutex.Signal();
1450 FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_UNLOCKHEAP_EXIT, "< this=0x%08x;", (TUint)this);)
1453 /** Locks the global bitmap heap, leaving on the clean-up stack a pointer
1454 to a TCleanupItem that unlocks the heap on deletion.
1455 Use this function instead of LockHeap() if code may leave between the
1456 LockHeap() - UnlockHeap() pair. Calls to LockHeapLC() must be coupled with
1457 subsequent calls to CFbsBitmap::UnlockHeap() or CleanupStack::PopAndDestroy().
1458 This function is deprecated. See CFbsBitmap::LockHeap() for more details.
1462 @see CFbsBitmap::LockHeap()
1464 EXPORT_C void CFbsBitmap::LockHeapLC(TBool /*aAlways*/) const
1466 FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_LOCKHEAPLC_ENTRY, "> this=0x%08x;", (TUint)this);)
1468 TCleanupItem cleanitem(CFbsBitmap::UnlockHeap, (TAny*)this);
1469 CleanupStack::PushL(cleanitem);
1470 FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_LOCKHEAPLC_EXIT, "< this=0x%08x;", (TUint)this);)
1473 EXPORT_C void CFbsBitmap::UnlockHeap(TAny* aFbsBitmap)
1475 FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_UNLOCKHEAP2_ENTRY, "> bitmap=0x%08x;", (TUint)aFbsBitmap);)
1476 ((CFbsBitmap*)aFbsBitmap)->UnlockHeap();
1477 FBS_OST(OstTrace0(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_UNLOCKHEAP2_EXIT, "<");)
1480 /** Tests whether the bitmap is volatile.
1481 A bitmap becomes volatile if CFbsBitmap::DataAdress() is called without
1482 CFbsBitmap::BeginDataAccess() having been called before and it can become non-volatile
1483 again if a resizing or compression is performed.
1488 EXPORT_C TBool CFbsBitmap::IsVolatile() const
1492 return CleanAddress()->iSettings.IsVolatileBitmap();
1495 /** Tests how many times the bitmap has been touched.
1496 A bitmap is touched whenever CFbsBitmap::EndDataAccess() is called with the parameter
1497 aReadOnly set to EFalse and also whenever a resizing or compression is performed.
1501 @return The number of times the bitmap has been touched.
1503 EXPORT_C TInt CFbsBitmap::TouchCount() const
1505 if (!iHandle || (iFlags & EIsReadOnlyBitmapMask))
1506 return 0; // A read-only bitmap can never be touched.
1507 return CleanAddress()->Extra()->iTouchCount;
1510 /** Returns the serial number of the bitmap
1511 The serial number is unique to this bitmap.
1512 The serial number is a signed 64-bit integer, with only the positive values being assigned.
1513 As ROM bitmaps do not have serial numbers, the serial number will use the negative range
1514 of values so that ROM bitmap's serial number cannot be the same as a RAM bitmap's.
1515 ROM bitmap's address pointers are unique to the ROM bitmap, so the serial number will just
1516 be negative value of the address pointer.
1520 @return The unique serial number for the bitmap
1522 EXPORT_C TInt64 CFbsBitmap::SerialNumber() const
1526 if (iFlags & EIsRomBitmap)
1527 return -TInt64(reinterpret_cast<TUint32>(iAddressPointer));
1528 return CleanAddress()->Extra()->iSerialNumber;
1531 /** Tests whether the bitmap is large.
1532 @return ETrue if the bitmap is large, EFalse if not.
1536 EXPORT_C TBool CFbsBitmap::IsLargeBitmap() const
1538 CBitwiseBitmap* bitmap = CleanAddress();
1543 return bitmap->IsLargeBitmap();
1546 /** Returns the handle for the hardware bitmap which this CFbsBitmap is using.
1547 @return The handle to the hardware bitmap. The handle is NULL if it is not
1552 EXPORT_C TInt CFbsBitmap::HardwareBitmapHandle() const
1554 CBitwiseBitmap* bitmap = CleanAddress();
1559 return bitmap->HardwareBitmapHandle();
1562 /** Gets the attributes of the bitmap's palette.
1563 This is not currently supported.
1564 @param aModifiable On return, whether or not the palette is modifiable.
1565 @param aNumEntries On return, the number of entries in the palette.
1569 EXPORT_C void CFbsBitmap::PaletteAttributes(TBool& aModifiable,TInt& aNumEntries) const
1575 /** Sets the bitmap's palette.
1576 This is not currently supported.
1577 @param aPalette Not used.
1581 EXPORT_C void CFbsBitmap::SetPalette(CPalette* /*aPalette*/)
1585 /** Gets the bitmap's palette.
1586 This is not currently supported.
1587 @param aPalette Not used.
1588 @return KErrNotSupported.
1592 EXPORT_C TInt CFbsBitmap::GetPalette(CPalette*& /*aPalette*/) const
1594 return(KErrNotSupported);
1599 This method loads a bitmap from an opened file handle.
1601 @param aFile mbm or rsc file handle (rsc file format: header + rsc
1602 data section + mbm file section).
1603 @param aId Bitmap ID - should be less than mbm file bitmaps count.
1604 @param aShareIfLoaded Specifies whether or not the loaded bitmap will be
1605 made available for sharing between FBSERV clients.
1606 @param aFileOffset mbm file section offset into rsc file.
1607 @return KErrNone if successful, otherwise another
1608 of the system-wide error codes.
1610 TInt CFbsBitmap::DoLoad(RFile& aFile,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset)
1613 TPckgBuf<TBmpHandles> handlebuf;
1614 TPckgBuf<TLoadBitmapArg> loadBitmapArg;
1615 loadBitmapArg().iBitmapId = aId;
1616 loadBitmapArg().iShareIfLoaded = TInt(aShareIfLoaded);
1617 loadBitmapArg().iFileOffset = aFileOffset;
1618 //Getting the RFs Handle(2) and RFile handle(3) into a TIpcArgs into 2nd and 3rd argument
1620 ret=aFile.TransferToServer(fileargs,2,3);
1623 fileargs.Set(0,&handlebuf);
1624 fileargs.Set(1,&loadBitmapArg);
1625 ret=iFbs->SendCommand(EFbsMessBitmapLoad,fileargs);
1626 if(ret!=KErrNone) return(ret);
1627 iHandle=handlebuf().iHandle;
1628 iServerHandle=handlebuf().iServerHandle;
1629 iAddressPointer=(CBitwiseBitmap*)(iFbs->HeapBase()+handlebuf().iAddressOffset);
1630 ret = iFbs->iHelper->AddBitmap(*this);
1631 if (ret != KErrNone)
1633 return iFbs->AllocScanLineBuffer(iAddressPointer->iByteWidth+4);
1638 This method loads a bitmap from the mbm or rsc file specified by the filename.
1640 @param aFileName mbm or rsc file name (rsc file format: header + rsc
1641 data section + mbm file section).
1642 @param aId Bitmap ID - should be less than mbm file bitmaps count.
1643 @param aShareIfLoaded Specifies whether or not the loaded bitmap will be
1644 made available for sharing between FBSERV clients.
1645 @param aFileOffset mbm file section offset into rsc file.
1646 @return KErrNone if successful, otherwise another
1647 of the system-wide error codes.
1649 TInt CFbsBitmap::DoLoad(const TDesC& aFileName,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset)
1652 TPckgBuf<TBmpHandles> handlebuf;
1653 TPckgBuf<TLoadBitmapArg> loadBitmapArg;
1654 loadBitmapArg().iBitmapId = aId;
1655 loadBitmapArg().iShareIfLoaded = TInt(aShareIfLoaded);
1656 loadBitmapArg().iFileOffset = aFileOffset;
1658 fileargs.Set(0,&handlebuf);
1659 fileargs.Set(1,&loadBitmapArg);
1660 fileargs.Set(2,&aFileName);
1661 ret=iFbs->SendCommand(EFbsMessBitmapLoadFast,fileargs);
1662 if(ret!=KErrNone) return(ret);
1663 iHandle=handlebuf().iHandle;
1664 iServerHandle=handlebuf().iServerHandle;
1665 iAddressPointer=(CBitwiseBitmap*)(iFbs->HeapBase()+handlebuf().iAddressOffset);
1666 ret = iFbs->iHelper->AddBitmap(*this);
1667 if (ret != KErrNone)
1669 return iFbs->AllocScanLineBuffer(iAddressPointer->iByteWidth+4);
1674 This method handles very special case when the rsc file is in RAM, but it
1675 contains ROM mbm file. ROM mbm file format is different than RAM mbm file
1676 format and ROM mbm file cannot be loaded into RAM using standard techniques
1677 (used by CFbsBitmap::DoLoad()). We have to check it is really a ROM mbm file.
1678 If it is - we have to allocate the right amount of RAM, read and copy
1679 requested ROM bitmap to the allocated RAM.
1681 @leave KErrNotSupported if this is a RAM rsc file with ROM mbm file section,
1682 or any of the RFile related error codes.
1683 @param aFileName rsc file name (rsc file format: header + rsc data section +
1685 @param aId Bitmap ID - should be less than mbm file bitmaps count.
1686 @param aFileOffset mbm file section offset into rsc file.
1687 @return EFalse - this is not a ROM mbm file. ETrue - this is a ROM mbm file
1688 and requested by aId bitmmap is loaded.
1690 TBool CFbsBitmap::LoadShiftedRomBmpL(const TDesC& aFileName, TInt32 aId, TUint aFileOffset)
1693 ::CleanupClosePushL(mbm_file);
1694 User::LeaveIfError(mbm_file.Open(iFbs->FileServer(), aFileName, EFileRead | EFileShareReadersOnly));
1695 TInt pos = static_cast <TInt> (aFileOffset);
1696 User::LeaveIfError(mbm_file.Seek(ESeekStart, pos));//move to the beginning of the mbm file section
1697 TBuf8<sizeof(CBitwiseBitmap)> buf;
1698 //Check if it is a ROM mbm file
1699 User::LeaveIfError(mbm_file.Read(buf, sizeof(KMultiBitmapRomImageUid.iUid)));//Bitmap file UID - ROM or RAM
1700 TInt32 mbm_uid = *(reinterpret_cast <const TInt32*> (buf.Ptr()));
1701 TBool loaded = EFalse;
1702 if(mbm_uid == KMultiBitmapRomImageUid.iUid)
1704 if(!KRomMBMInRamRSC)
1706 User::Leave(KErrNotSupported);
1710 User::LeaveIfError(mbm_file.Read(buf, sizeof(TInt32)));//Number of bitmaps
1711 TInt32 bmp_cnt = *(reinterpret_cast <const TInt32*> (buf.Ptr()));
1714 User::Leave(KErrNotFound);
1716 for(TInt i=0;i<aId;i++) //Read bitmap UIDs located before aId.
1718 User::LeaveIfError(mbm_file.Read(buf, sizeof(aId)));
1720 User::LeaveIfError(mbm_file.Read(buf, sizeof(TInt32)));//Read the offset of aId bitmap.
1721 TInt bmp_offset = *(reinterpret_cast <const TInt32*> (buf.Ptr())) + TInt(aFileOffset);
1722 pos = static_cast <TInt> (bmp_offset);
1723 User::LeaveIfError(mbm_file.Seek(ESeekStart, pos));//move the file pointer to the bitmap
1724 User::LeaveIfError(mbm_file.Read(buf, sizeof(CBitwiseBitmap)));//Read CBitwiseBitmap data (without the bitmap data)
1725 const CBitwiseBitmap* bmp = reinterpret_cast <const CBitwiseBitmap*> (buf.Ptr());
1726 //Calculate bitmap data size, alocate enough memory for the bitmap, copy CBitwiseBitmap
1727 //members first, read the bitmap data from the file, copy the data to the allocated memory,
1728 //initialize iRomPointer.
1729 //If sizeof(CBitwiseBitmap) != real size of CBitwiseBitmap then we could have problems,
1730 //because bitmap data won't be copied at the right position.
1731 TInt size = bmp->iHeader.iBitmapSize - sizeof(SEpocBitmapHeader) + sizeof(CBitwiseBitmap);
1732 TUint8* bmp_mem = new (ELeave) TUint8[size];
1733 //There is no need bmp_mem to be aligned, because it is a pointer to a RAM block of memory.
1734 TCleanupItem cleanitem(FreeMem, bmp_mem);
1735 CleanupStack::PushL(cleanitem);
1736 Mem::Copy(bmp_mem, bmp, sizeof(CBitwiseBitmap));
1737 TPtr8 pbmp(bmp_mem + sizeof(CBitwiseBitmap), size - sizeof(CBitwiseBitmap));
1738 User::LeaveIfError(mbm_file.Read(pbmp, size - sizeof(CBitwiseBitmap)));//read the bitmap data. We've already read the CBitwiseBitmap data.
1739 CleanupStack::Pop(bmp_mem);
1740 iAddressPointer = reinterpret_cast<CBitwiseBitmap*>(bmp_mem);
1741 iFlags = EIsRomBitmap;
1744 }//end of - if(!KRomMBMInRamRSC) - "else" part
1745 }//end of - if(mbm_uid == KMultiBitmapRomImageUid.iUid)
1746 CleanupStack::PopAndDestroy();//mbm_file
1751 Swaps the bitmap's width and height.
1752 For example, if the bitmap's size is (40, 20), the new size will be (20, 40).
1753 Bitmap content is not preserved.
1756 @return KErrNone if the call was successful, KErrGeneral if the bitmap handle is
1757 invalid, KErrAccessDenied if the bitmap is in ROM, KErrNotSupported if the bitmap
1758 is a hardware bitmap or an extended bitmap.
1760 EXPORT_C TInt CFbsBitmap::SwapWidthAndHeight()
1767 CBitwiseBitmap* bmp = BeginDataAccessAndGetCleanAddress(data);
1769 // Check the new bitmap size here then decide whether to swap the bitmap on the
1770 // client side or send it to be done on the server and reallocate memory for it.
1771 TInt newWidthInBytes = CBitwiseBitmap::ByteWidth(bmp->iHeader.iSizeInPixels.iHeight, bmp->iSettings.CurrentDisplayMode());
1772 TInt64 hugeDataSize = TInt64(bmp->iHeader.iSizeInPixels.iWidth) * TInt64(newWidthInBytes);
1774 TInt err = KErrNone;
1775 // If the size of the new swapped bitmap is less than or equal its original size before the swap,
1776 // then we do not need to reallocate memory. The swapping is straight forward.
1777 if( I64HIGH(hugeDataSize) == 0 && I64LOW(hugeDataSize) <= TUint(bmp->iHeader.iBitmapSize - bmp->iHeader.iStructSize) )
1779 err = bmp->SwapWidthAndHeight(data);
1780 // Even though used DataAddress() as read-only, need to increment touch count, so indicate that data has been written
1781 EndDataAccess(EFalse);
1783 // Otherwise we need to reallocate memory. We do this by using the already exisitng
1784 // Resize() function as a work around- Code Reusability!!
1787 EndDataAccess(ETrue); // Used DataAddress() to read only.
1788 // Resize will increase touch counter
1789 err = Resize(TSize(bmp->iHeader.iSizeInPixels.iHeight, bmp->iHeader.iSizeInPixels.iWidth));
1794 /** Gets a pointer to the decompression buffer owned by this thread's FBServ session.
1795 @param aSize The size in bytes of the scan lines to decompress.
1796 @return A pointer to the decompression buffer or NULL if there is no FBServ session.
1800 EXPORT_C HBufC8* CFbsBitmap::GetDecompressionBuffer(TInt aSize)
1802 RFbsSession* ses=RFbsSession::GetSession();
1803 return ses? ses->GetDecompressionBuffer(aSize) : NULL;
1806 /** Gets a pointer to the rasterizer for extended bitmaps if present.
1807 @return A pointer to the rasterizer owned by this thread's FBServ session.
1808 @return NULL if the rasterizer is not present.
1812 EXPORT_C CFbsRasterizer* CFbsBitmap::Rasterizer()
1814 RFbsSession* session = RFbsSession::GetSession();
1815 return session ? session->iHelper->Rasterizer() : NULL;
1818 /** Loads a specific bitmap from an opened multi-bitmap file handle.
1819 The bitmap may be shared by other font and bitmap server clients.
1820 @param aFile The handle of the multi-bitmap (.mbm) file.
1821 @param aId The bitmap identifier.
1822 @param aShareIfLoaded Specifies whether or not the loaded bitmap will be made
1823 available for sharing between font and bitmap server clients.
1824 @return KErrNone if successful, otherwise another of the system error
1829 EXPORT_C TInt CFbsBitmap::Load(RFile& aFile,TInt32 aId/*=0*/,TBool aShareIfLoaded/*=ETrue*/)
1831 FBS_OST(TFullName fileName;)
1832 FBS_OST(aFile.FullName(fileName);)
1833 FBS_OST(OstTraceExt4( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOAD3_ENTRY, "> this=0x%08x; file=%S; id=0x%08x; share=%d", (TUint)this, fileName, aId, aShareIfLoaded);)
1834 TInt ret = Load(aFile,aId,aShareIfLoaded,0);
1835 FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOAD3_EXIT, "< this=0x%08x, ret=%d", (TUint)this, ret);)
1839 /** Loads a specific bitmap from an opened multi-bitmap file handle.
1840 The bitmap may be shared by other font and bitmap server clients.
1841 @param aFile The handle of the multi-bitmap (.mbm) file.
1842 @param aId The bitmap identifier.
1843 @param aShareIfLoaded Specifies whether or not the loaded bitmap will be made
1844 available for sharing between FBSERV clients.
1845 @param aFileOffset Bitmap file section offset within the file.
1846 @return KErrNone if successful, otherwise another of the system error codes.
1850 EXPORT_C TInt CFbsBitmap::Load(RFile& aFile,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset)
1852 TInt err = KErrNone;
1853 FBS_OST(TFullName fileName;)
1854 FBS_OST(aFile.FullName(fileName);)
1855 FBS_OST(OstTraceExt5( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOAD4_ENTRY, "> this=0x%08x; file=%S; id=0x%08x; share=%d; off=%d", (TUint)this, fileName, aId, aShareIfLoaded, aFileOffset);)
1858 FBS_OST(OstTrace1( TRACE_ERROR, CFBSBITMAP_LOAD4_ERROR, "! this=0x%08x; !iFbs", (TUint)this);)
1859 err = KErrCouldNotConnect;
1864 TUint32* rompointer;
1865 IsFileInRom(aFile,rompointer);
1866 TBool romPointerValid;
1867 err = DoLoadFromRom(rompointer, aId, aFileOffset, romPointerValid);
1868 if (!romPointerValid)
1870 err = DoLoad(aFile,aId,aShareIfLoaded,aFileOffset);
1871 FBS_OST_IF(err!=KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_LOAD4_ERROR2, "! this=0x%08x; DoLoad() returned %d", (TUint)this, err);)
1874 FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOAD4_EXIT, "< this=0x%08x; err=%d", (TUint)this, err);)
1878 /** Loads and compresses a specific bitmap from an opened multi-bitmap file handle.
1879 The bitmap may be shared by other font and bitmap server clients.
1880 If the bitmap is loaded from ROM then compression is not allowed.
1881 @param aFile The handle of the multi-bitmap (.mbm) file.
1882 @param aId The bitmap identifier.
1883 @param aShareIfLoaded Specifies whether or not the loaded bitmap will be
1884 made available for sharing between FBSERV clients.
1885 @return KErrNone if successful, otherwise another of the system-wide error
1890 EXPORT_C TInt CFbsBitmap::LoadAndCompress(RFile& aFile,TInt32 aId/*=0*/,TBool aShareIfLoaded/*=ETrue*/)
1892 FBS_OST(TFullName fileName;)
1893 FBS_OST(aFile.FullName(fileName);)
1894 FBS_OST(OstTraceExt4( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOADANDCOMPRESS3_ENTRY, "> this=0x%08x; file=%S; id=0x%08x; share=%d", (TUint)this, fileName, aId, aShareIfLoaded);)
1895 TInt ret = LoadAndCompress(aFile,aId,aShareIfLoaded,0);
1896 FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOADANDCOMPRESS3_EXIT, "< this=0x%08x; ret=%d", (TUint)this, ret);)
1900 /** Loads and compresses a specific bitmap from an opened multi-bitmap file handle.
1901 The bitmap may be shared by other font and bitmap server clients. If the
1902 bitmap is loaded from ROM then compression is not allowed.
1903 @param aFile The handle of the multi-bitmap (.mbm) file.
1904 @param aId The bitmap identifier.
1905 @param aShareIfLoaded Specifies whether or not the loaded bitmap will be made
1906 available for sharing between FBSERV clients.
1907 @param aFileOffset Bitmap file section offset within the file.
1908 @return KErrNone if successful, otherwise another of the system-wide error
1913 EXPORT_C TInt CFbsBitmap::LoadAndCompress(RFile& aFile,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset)
1915 FBS_OST(TFullName fileName;)
1916 FBS_OST(aFile.FullName(fileName);)
1917 FBS_OST(OstTraceExt4( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOADANDCOMPRESS4_ENTRY, "> this=0x%08x; file=%S; id=0x%08x; share=%d", (TUint)this, fileName, aId, aShareIfLoaded);)
1918 TInt err = Load(aFile,aId,aShareIfLoaded,aFileOffset);
1919 if (err == KErrNone)
1921 if (!(iFlags & EIsRomBitmap))
1924 FBS_OST_IF(err!=KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_LOADANDCOMPRESS4_ERROR, "! this=0x%08x; Compress() returned %d", (TUint)this, err);)
1928 err = KErrAccessDenied;
1929 FBS_OST(OstTraceExt2( TRACE_ERROR, CFBSBITMAP_LOADANDCOMPRESS4_ERROR2, "! this=0x%08x; Cannot compress bitmap in ROM; iFlags=0x%08x", (TUint)this, (TUint)iFlags);)
1932 FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOADANDCOMPRESS4_EXIT, "< this=0x%08x; err=%d", (TUint)this, err);)
1936 /** Gets all the bitmap handles for all the bitmaps stored in the Font Bitmap Server. There is a limit of
1937 the number of bitmaps that can be retrieved defined by KMaxBitmapHandleBufferSize. If this limit has been
1938 reached then KErrOverflow will be returned.
1939 @param aBitmapIdArray returns an array of all the bitmap handles
1940 @return KErrNone if successful, KErrOverflow if the bitmapBuffer is not large enough to store
1941 all the bitmap handles, otherwise another of the system-wide error codes.
1942 @capability ReadDeviceData
1946 EXPORT_C TInt CFbsBitmap::GetAllBitmapHandles(RArray<TInt>& aBitmapIdArray) const
1949 TInt ret = bitmapBuffer.Create(KMaxBitmapHandleBufferSize);
1952 TIpcArgs args(&bitmapBuffer);
1953 ret=iFbs->SendCommand(EFbsGetAllBitmapHandles, args);
1956 // Convert data returned from server and place into the RArray (aBitmapIdArray)
1957 aBitmapIdArray.Reset();
1958 TInt* bitmapIdPtr = (TInt*)bitmapBuffer.Ptr();
1959 const TInt numBitmapIds = bitmapBuffer.Size() / KNumBytesPerBitmapHandle; // Divide by number of bytes per bitmap handle to get total number of bitmap IDs
1960 for (TInt count=0; count<numBitmapIds; ++count)
1962 TInt bitmapId = *bitmapIdPtr++;
1963 ret = aBitmapIdArray.Append(bitmapId);
1969 bitmapBuffer.Close();
1975 This method tries to load a bitmap if mbm or rsc file is in ROM.
1977 @param aRomPointer the address of the file in ROM
1978 @param aId a Bitmap ID which should be less than mbm file bitmaps count.
1979 @param aFileOffset mbm file section offset into rsc file.
1980 @param aRomPointerValid on output it is set to ETrue if aRomPointer points to a valid ROM file or EFalse otherwise.
1981 @return KErrNone if successful, otherwise another of the system-wide error codes.
1983 TInt CFbsBitmap::DoLoadFromRom(TUint32* aRomPointer, TInt32 aId, TUint aFileOffset, TBool& aRomPointerValid)
1985 aRomPointerValid = ETrue;
1988 TUint8* temp = reinterpret_cast <TUint8*> (aRomPointer);
1989 __ASSERT_DEBUG(!(TUint(temp) & 0x00000003),Panic(EFbsBitmapAlignment));
1990 temp += aFileOffset;
1991 aRomPointer = reinterpret_cast <TUint32*> (temp);
1992 if(TInt32(*aRomPointer)==KMultiBitmapRomImageUid.iUid)
1994 TInt numbitmaps = (TInt)*(aRomPointer+1);
1999 TInt offset = *(aRomPointer+aId+2);
2000 iAddressPointer = (CBitwiseBitmap*)(((TUint8*)aRomPointer) + offset);
2001 iFlags = EIsRomBitmap;
2003 return iFbs->AllocScanLineBuffer(iAddressPointer->iByteWidth + 4);
2006 aRomPointerValid = EFalse;
2012 Creates an extended bitmap. Extended bitmaps are used to store immutable
2013 data in a platform-specific format. They cannot be used as targets of
2014 graphics contexts, and modification of their data via DataAddress() or
2015 TBitmapUtil is not supported and results in undefined behaviour up to
2016 and including process termination.
2018 Initialisation of the raw data of the new bitmap is carried out by copying
2019 the data pointed to by the parameter aData.
2021 Read-only access to the raw data of an extended bitmap is provided by
2022 DataAddress() and DataSize() in conjunction with BeginDataAccess() and
2025 Extended bitmaps have a conceptual size in pixels and a conceptual
2026 display mode for compatibility purposes. The raw data can be independent
2027 of these properties.
2029 @param aSizeInPixels The conceptual width and height of the new bitmap in pixels.
2030 @param aDispMode The conceptual display mode of the new bitmap.
2031 @param aType The UID identifying the data format of the new bitmap. Used by the
2032 extended bitmap rasterizer to distinguish between different data types.
2033 @param aData A pointer to the raw data to be stored in the new bitmap.
2034 @param aDataSize The size in bytes of the raw data to be stored in the new bitmap.
2035 @return KErrNone if successful; KErrArgument if the width or height specified in
2036 aSizeInPixels is negative, aDispMode is an invalid display mode, aData is NULL,
2037 aDataSize is negative or zero, or aDataType is a UID reserved for OS use; KErrTooBig
2038 if the width or height specified in aSizeInPixels exceeds KMaxTInt/4, or aDataSize
2039 exceeds KMaxTInt/2; otherwise another of the system-wide error codes.
2042 @see CFbsBitmap::DataAddress()
2043 @see CFbsBitmap::DataSize()
2044 @see CFbsBitmap::BeginDataAccess()
2045 @see CFbsBitmap::EndDataAccess()
2047 EXPORT_C TInt CFbsBitmap::CreateExtendedBitmap(const TSize& aSizeInPixels, TDisplayMode aDispMode, TUid aType, const TAny* aData, TInt aDataSize)
2050 FBS_OST(OstTraceExt5( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_CREATEEXTENDEDBITMAP_ENTRY, "> this=0x%08x; w=%d; h=%d; dm=%d; type=0x%08x", (TUint)this, aSizeInPixels.iWidth, aSizeInPixels.iHeight, aDispMode, aType.iUid);)
2051 if (!aData || aDataSize == 0)
2053 FBS_OST(OstTrace1( TRACE_ERROR, CFBSBITMAP_CREATEEXTENDEDBITMAP_ERROR, "! this=0x%08x; (!aData || aDataSize == 0)", (TUint)this);)
2058 err = DoCreate(aSizeInPixels, aDispMode, aType, aDataSize);
2059 if (err == KErrNone)
2061 Mem::Copy(iFbs->iLargeBitmapChunk.Base() + iAddressPointer->iDataOffset, aData, aDataSize);
2064 FBS_OST(OstTraceExt4( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_CREATEEXTENDEDBITMAP_EXIT, "< this=0x%08x; err=%d; iH=0x%08x; iSH=0x%08x", (TUint)this, err, iHandle, iServerHandle);)
2069 Creates an extended bitmap. Extended bitmaps are used to store immutable
2070 data in a platform-specific format. They cannot be used as targets of
2071 graphics contexts, and modification of their data via DataAddress() or
2072 TBitmapUtil is not supported and results in undefined behaviour up to
2073 and including process termination.
2075 Initialisation of the raw data of the new bitmap is carried out by a
2076 callback to the MFbsExtendedBitmapInitializer::InitExtendedBitmap()
2077 function passed through the parameter aInitializer.
2079 Read-only access to the raw data of an extended bitmap is provided by
2080 DataAddress() and DataSize() in conjunction with BeginDataAccess() and
2083 Extended bitmaps have a conceptual size in pixels and a conceptual
2084 display mode for compatibility purposes. The raw data can be independent
2085 of these properties.
2087 @param aSizeInPixels The conceptual width and height of the new bitmap in pixels.
2088 @param aDispMode The conceptual display mode of the new bitmap.
2089 @param aType The UID identifying the data format of the new bitmap. Used by the
2090 extended bitmap rasterizer to distinguish between different data types.
2091 @param aDataSize The size in bytes of the raw data to be stored in the new bitmap.
2092 @param aInitializer A reference to the initializer of the raw data to be stored in the new bitmap.
2093 @return KErrNone if successful; KErrArgument if the width or height specified in
2094 aSizeInPixels is negative, aDispMode is an invalid display mode, aData is NULL,
2095 aDataSize is negative or zero, or aDataType is a UID reserved for OS use; KErrTooBig
2096 if the width or height specified in aSizeInPixels exceeds KMaxTInt/4, or aDataSize
2097 exceeds KMaxTInt/2; otherwise another of the system-wide error codes.
2100 @see CFbsBitmap::DataAddress()
2101 @see CFbsBitmap::DataSize()
2102 @see CFbsBitmap::BeginDataAccess()
2103 @see CFbsBitmap::EndDataAccess()
2104 @see MFbsExtendedBitmapInitializer
2106 EXPORT_C TInt CFbsBitmap::CreateExtendedBitmap(const TSize& aSizeInPixels, TDisplayMode aDispMode, TUid aType, TInt aDataSize, MFbsExtendedBitmapInitializer& aInitializer)
2109 FBS_OST(OstTraceExt5( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_CREATEEXTENDEDBITMAP2_ENTRY, "> this=0x%08x; w=%d; h=%d; dm=%d; type=0x%08x;", (TUint)this, aSizeInPixels.iWidth, aSizeInPixels.iHeight, aDispMode, aType.iUid);)
2112 FBS_OST(OstTrace1( TRACE_ERROR, CFBSBITMAP_CREATEEXTENDEDBITMAP2_ERROR, "! this=0x%08x; aDataSize == 0", (TUint)this);)
2117 err = DoCreate(aSizeInPixels, aDispMode, aType, aDataSize);
2118 if (err == KErrNone)
2120 err = aInitializer.InitExtendedBitmap(iFbs->iLargeBitmapChunk.Base() + iAddressPointer->iDataOffset, aDataSize);
2121 if (err != KErrNone)
2127 FBS_OST(OstTraceExt4( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_CREATEEXTENDEDBITMAP2_EXIT, "< this=0x%08x; err=%d; iH=0x%08x; iSH=0x%08x", (TUint)this, err, iHandle, iServerHandle);)
2132 Gets the UID identifying the data format of an extended bitmap.
2133 @return The UID identifying the data format of the bitmap or
2134 KNullUid if the bitmap is not an extended bitmap.
2138 EXPORT_C TUid CFbsBitmap::ExtendedBitmapType() const
2144 TUid type = CleanAddress()->iUid;
2145 if (type.iUid == KCBitwiseBitmapUid.iUid || type.iUid == KCBitwiseBitmapHardwareUid.iUid)
2153 Gets the size in bytes of the bitmap data.
2154 @return The size in bytes of the bitmap data.
2158 EXPORT_C TInt CFbsBitmap::DataSize() const
2164 CBitwiseBitmap* bmp = CleanAddress();
2165 return bmp->iHeader.iBitmapSize - bmp->iHeader.iStructSize;
2169 Gets a pointer to an extra buffer for general use owned by this thread's FBServ session.
2170 @param aSize The size of the buffer in bytes
2171 @return A pointer to the extra buffer if successful or NULL if there is no FBServ session
2175 EXPORT_C HBufC8* CFbsBitmap::GetExtraBuffer(TInt aSize)
2177 RFbsSession* ses=RFbsSession::GetSession();
2178 return ses? ses->GetExtraBuffer(aSize) : NULL;