1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/fbs/fontandbitmapserver/sfbs/FBSBMP.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,2179 @@
1.4 +// Copyright (c) 1995-2010 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <s32file.h>
1.20 +#include <bitmap.h>
1.21 +#include <graphicsaccelerator.h>
1.22 +#include <fbs.h>
1.23 +#include <graphics/bitmapuid.h>
1.24 +#include "fbsdefs.h"
1.25 +#include "UTILS.H"
1.26 +#include "fbshelper.h"
1.27 +#include "fbsrasterizer.h"
1.28 +#include "BitwiseBitmap.inl"
1.29 +#include "FbsMessage.H"
1.30 +#include "bitmapconst.h"
1.31 +#include "OstTraceDefinitions.h"
1.32 +#include "fbstrace.h"
1.33 +#ifdef OST_TRACE_COMPILER_IN_USE
1.34 +#include "FBSBMPTraces.h"
1.35 +#endif
1.36 +
1.37 +const TInt KMaxPixelSize = KMaxTInt / 4; // Maximum pixel size to avoid some overflow problems
1.38 +const TInt KMaxBitmapHandleBufferSize = KNumBytesPerBitmapHandle * 2000; // Maximum size of buffer to store all bitmap handles.
1.39 +
1.40 +GLREF_C void Panic(TFbsPanic aPanic);
1.41 +
1.42 +//If we have to handle RAM located file with an embedded ROM mbm file section -
1.43 +//KRomMBMInRamRSC should be ETrue.
1.44 +//If it is not allowed to do that - KRomMBMInRamRSC should be EFalse.
1.45 +//The same constant is defined into TDefect test app. It should be changed too.
1.46 +#pragma warning(disable : 4127) //conditional expression is constant
1.47 +LOCAL_D const TBool KRomMBMInRamRSC = EFalse;
1.48 +
1.49 +//Cleanup function used by CFbsBitmap::LoadShiftedRomBmpL(...)
1.50 +LOCAL_D void FreeMem(TAny* aMem)
1.51 + {
1.52 + delete[] static_cast<TUint8*>(aMem);
1.53 + }
1.54 +
1.55 +// Fbs style bitmap client class for font bitmap server
1.56 +/** @publishedAll */
1.57 +EXPORT_C CFbsBitmap::CFbsBitmap():
1.58 + CBase(),
1.59 + iFbs(RFbsSession::GetSession()),
1.60 + iAddressPointer(NULL),
1.61 + iFlags(0),
1.62 + iUseCount(0),
1.63 + iHandle(0),
1.64 + iServerHandle(0)
1.65 + {
1.66 + }
1.67 +
1.68 +/** Destructor. Calls Reset().
1.69 +@see Reset()
1.70 +@publishedAll
1.71 +@released
1.72 +*/
1.73 +EXPORT_C CFbsBitmap::~CFbsBitmap()
1.74 + {
1.75 + Reset();
1.76 + }
1.77 +
1.78 +/** Gets the physical length in bytes of a scanline in memory.
1.79 +This is aligned to a 4 byte (DWORD) boundary for performance reasons.
1.80 +
1.81 +@param aLength The length of a scanline in pixels.
1.82 +@param aDispMode The display mode of the bitmap.
1.83 +@return Number of bytes in the scanline in memory.
1.84 +@publishedAll
1.85 +@released
1.86 +*/
1.87 +EXPORT_C TInt CFbsBitmap::ScanLineLength(TInt aLength,TDisplayMode aDispMode)
1.88 + {
1.89 + if (aDispMode == ERgb)
1.90 + return aLength * 4;
1.91 + else if (aDispMode == ENone)
1.92 + return 0;
1.93 +
1.94 + return CBitwiseBitmap::ByteWidth(aLength,aDispMode);
1.95 + }
1.96 +
1.97 +/** Releases the bitmap's handle from the font and bitmap server and decrements
1.98 +its access count.
1.99 +The server-side bitmap is only deleted when the access count for the bitmap
1.100 +decrements to zero.
1.101 +@publishedAll
1.102 +@released
1.103 +*/
1.104 +EXPORT_C void CFbsBitmap::Reset()
1.105 + {
1.106 + FBS_OST(TInt ssh = (iFbs ? iFbs->ServerSessionHandle() : 0);)
1.107 + 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 );)
1.108 + if (iHandle && !(iFlags & EIsRomBitmap))
1.109 + {
1.110 + iFbs->SendCommand(EFbsMessClose, iHandle, Handle());
1.111 + iFbs->iHelper->RemoveBitmap(*this);
1.112 + }
1.113 + if (KRomMBMInRamRSC && (iFlags & EIsRomBitmap))
1.114 + {
1.115 + // If it is a ROM bitmap, we have to check, is it a ROM bitmap located
1.116 + // in RAM? If yes, then we have to deallocate the bitmap memory.
1.117 + TBool isInRom = EFalse;
1.118 + TInt ret = User::IsRomAddress(isInRom, iAddressPointer);
1.119 + if (ret == KErrNone && !isInRom)
1.120 + delete[] reinterpret_cast<TUint8*>(iAddressPointer);
1.121 + }
1.122 + iAddressPointer = NULL;
1.123 + iFlags = 0;
1.124 + iUseCount = 0;
1.125 + iHandle = 0;
1.126 + iServerHandle = 0;
1.127 + FBS_OST(OstTrace1( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_RESET_EXIT, "< this=0x%08x", (TUint)this );)
1.128 + }
1.129 +
1.130 +/** Tests whether or not the bitmap is read-only.
1.131 +@return ETrue if the bitmap is read-only, EFalse otherwise.
1.132 +@publishedAll
1.133 +@released
1.134 +*/
1.135 +EXPORT_C TBool CFbsBitmap::IsRomBitmap() const
1.136 + {
1.137 + return (iFlags & EIsReadOnlyBitmapMask) > 0;
1.138 + }
1.139 +
1.140 +/** Sets the bitmap to use a bitmap image stored in ROM.
1.141 +@param aRomBitmapPointer Pointer to a bitmap stored in ROM.
1.142 +@param aBitmapSizeInBytes On return, indicates the size of
1.143 +the bitmap in bytes.
1.144 +@leave KErrUnknown aRomBitmapPointer is not in ROM, or has an invalid UID.
1.145 +@publishedAll
1.146 +@released
1.147 +*/
1.148 +EXPORT_C void CFbsBitmap::SetRomBitmapL(CBitwiseBitmap* aRomBitmapPointer,TInt& aBitmapSizeInBytes)
1.149 + {
1.150 + TBool isInRom = EFalse;
1.151 + TInt ret = User::IsRomAddress(isInRom,(TAny*)aRomBitmapPointer);
1.152 + if (ret != KErrNone || !isInRom || aRomBitmapPointer->Uid() != KCBitwiseBitmapUid)
1.153 + User::Leave(KErrUnknown);
1.154 +
1.155 + Reset();
1.156 + iAddressPointer = aRomBitmapPointer;
1.157 + iFlags = EIsRomBitmap;
1.158 + iHandle = 1;
1.159 +
1.160 + User::LeaveIfError(iFbs->AllocScanLineBuffer(aRomBitmapPointer->iByteWidth + 4));
1.161 + aBitmapSizeInBytes = Align4(aRomBitmapPointer->iHeader.iBitmapSize + 28);
1.162 + }
1.163 +
1.164 +CBitwiseBitmap* CFbsBitmap::Address() const
1.165 + {
1.166 + if (!iHandle)
1.167 + return NULL;
1.168 + return iAddressPointer;
1.169 + }
1.170 +
1.171 +EXPORT_C CBitwiseBitmap* CFbsBitmap::CleanAddress() const
1.172 + {
1.173 + if (!iHandle)
1.174 + return NULL;
1.175 + // Don't try to clean a dirty bitmap between calls to BeginDataAccess() and EndDataAccess(), i.e. iUseCount > 0
1.176 + // ROM bitmaps can never be dirty
1.177 + if (!(iFlags & EIsReadOnlyBitmapMask) && iUseCount == 0 && iAddressPointer->iSettings.IsDirtyBitmap())
1.178 + {
1.179 + TPckgBuf<TBmpHandles> handlebuf;
1.180 + TIpcArgs args(iHandle, &handlebuf);
1.181 + if (iFbs->SendCommand(EFbsMessBitmapClean, args) == KErrNone)
1.182 + {
1.183 + const_cast<CFbsBitmap*>(this)->iHandle = handlebuf().iHandle;
1.184 + const_cast<CFbsBitmap*>(this)->iServerHandle = handlebuf().iServerHandle;
1.185 + const_cast<CFbsBitmap*>(this)->iAddressPointer = (CBitwiseBitmap*)(iFbs->HeapBase() + handlebuf().iAddressOffset);
1.186 + }
1.187 + }
1.188 + return iAddressPointer;
1.189 + }
1.190 +
1.191 +inline CBitwiseBitmap* CFbsBitmap::BeginDataAccessAndGetCleanAddress(TUint32*& aDataAddress) const
1.192 + {
1.193 + BeginDataAccess();
1.194 + CBitwiseBitmap* bmp = Address();
1.195 + // aDataAddress should be consistent with bmp since after the call to BeginDataAccess()
1.196 + // the call to DataAddress() will not clean the bitmap again
1.197 + aDataAddress = DataAddress();
1.198 + return bmp;
1.199 + }
1.200 +
1.201 +/** Gets the address of the first pixel in the bitmap.
1.202 +The first pixel is at the top-left. Access to the pixel data of a bitmap
1.203 +should be surrounded by calls to BeginDataAccess() and EndDataAccess(),
1.204 +otherwise performance may be degraded on certain platforms.
1.205 +
1.206 +Note: Performing a Resize() or Compress() operation changes the value returned by this function.
1.207 +@return The address of the first pixel of the bitmap.
1.208 +@publishedAll
1.209 +@released
1.210 +@see CFbsBitmap::BeginDataAccess()
1.211 +@see CFbsBitmap::EndDataAccess()
1.212 +*/
1.213 +EXPORT_C TUint32* CFbsBitmap::DataAddress() const
1.214 + {
1.215 + if(!iHandle) return(NULL);
1.216 + CBitwiseBitmap* bmp = CleanAddress();
1.217 +
1.218 + if (!(iFlags & EIsReadOnlyBitmapMask) && (iUseCount == 0))
1.219 + bmp->iSettings.SetVolatileBitmap();
1.220 +
1.221 + if(bmp->iUid.iUid==KCBitwiseBitmapHardwareUid.iUid) // RHardwareBitmap
1.222 + {
1.223 + RHardwareBitmap hwb(bmp->iDataOffset); // iDataOffset = handle for hardware bitmap
1.224 + TAcceleratedBitmapInfo info;
1.225 + const TInt ret = hwb.GetInfo(info);
1.226 + return ret!=KErrNone ? NULL : (reinterpret_cast<TUint32*>(info.iAddress));
1.227 + }
1.228 +
1.229 + if (bmp->iHeap == NULL)
1.230 + return(reinterpret_cast<TUint32*>((TUint8*)bmp+bmp->iDataOffset));
1.231 + return(reinterpret_cast<TUint32*>(iFbs->iLargeBitmapChunk.Base()+bmp->iDataOffset));
1.232 + }
1.233 +
1.234 +/** Gets the length in bytes between scanlines in memory.
1.235 +@return The length in bytes between scanlines in memory.
1.236 +@internalAll
1.237 +@released
1.238 +*/
1.239 +EXPORT_C TInt CFbsBitmap::DataStride() const
1.240 + {
1.241 + if (!iHandle)
1.242 + {
1.243 + return 0;
1.244 + }
1.245 +
1.246 + CBitwiseBitmap* bmp = CleanAddress();
1.247 + if (bmp==NULL)
1.248 + {
1.249 + return 0;
1.250 + }
1.251 +
1.252 + return bmp->DataStride();
1.253 + }
1.254 +
1.255 +/** Creates a bitmap with the specified size and display mode. The bitmap is
1.256 +created on the font and bitmap server's shared heap.
1.257 +@param aSizeInPixels The size of the bitmap to be created.
1.258 +@param aDispMode The display mode of the bitmap to be created.
1.259 +@return KErrNone if successful; KErrCouldNotConnect if no connection to the
1.260 +font and bitmap server could be made; KErrArgument if either the width or height specified
1.261 +in aSizeInPixels are negative or if the requested display mode is invalid; KErrTooBig
1.262 +if the requested size is too big.
1.263 +@publishedAll
1.264 +@released
1.265 +*/
1.266 +EXPORT_C TInt CFbsBitmap::Create(const TSize& aSizeInPixels,TDisplayMode aDispMode)
1.267 + {
1.268 + 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); )
1.269 + TInt err = DoCreate(aSizeInPixels,aDispMode,KUidCFbsBitmapCreation);
1.270 + FBS_OST(TInt ssh = (iFbs ? iFbs->ServerSessionHandle() : 0);)
1.271 + 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); )
1.272 + return err;
1.273 + }
1.274 +
1.275 +TInt CFbsBitmap::DoCreate(const TSize& aSizeInPixels, TDisplayMode aDispMode, TUid aUid, TInt aDataSize)
1.276 + {
1.277 + if(!iFbs) return(KErrCouldNotConnect);
1.278 + if (aDispMode <= ENone || aDispMode == ERgb || aDispMode >= EColorLast) return KErrArgument;
1.279 + if(aSizeInPixels.iWidth<0 || aSizeInPixels.iHeight<0) return(KErrArgument);
1.280 + if (aDataSize < 0) return KErrArgument;
1.281 + Reset();
1.282 + TBmpSpec bmpspec;
1.283 + bmpspec.iSizeInPixels=aSizeInPixels;
1.284 + bmpspec.iDispMode=aDispMode;
1.285 + bmpspec.iHandle = aUid.iUid; // Use iHandle to pass UID
1.286 + bmpspec.iServerHandle = aDataSize; // Use iServerHandle to pass data size
1.287 + TPckgBuf<TBmpSpec> b;
1.288 + b=bmpspec;
1.289 + TIpcArgs args(&b);
1.290 + TInt ret=iFbs->SendCommand(EFbsMessBitmapCreate,args);
1.291 + if(ret!=KErrNone) return(ret);
1.292 + iHandle=b().iHandle;
1.293 + iServerHandle=b().iServerHandle;
1.294 + iAddressPointer=(CBitwiseBitmap*)(iFbs->HeapBase()+b().iAddressOffset);
1.295 + if (aDataSize > 0) // explicitly specified data size means extended bitmap
1.296 + {
1.297 + iFlags = EIsExtendedBitmap;
1.298 + }
1.299 + ret = iFbs->iHelper->AddBitmap(*this);
1.300 + if (ret != KErrNone)
1.301 + return ret;
1.302 + return iFbs->AllocScanLineBuffer(CBitwiseBitmap::ByteWidth(aSizeInPixels.iWidth, aDispMode)+4);
1.303 + }
1.304 +
1.305 +/** Creates a hardware bitmap with a size and display mode.
1.306 +@param aSizeInPixels The bitmap's width and height in pixels.
1.307 +@param aDispMode The bitmap's display mode.
1.308 +@param aCreatorUid The UID of the application calling this function. This is
1.309 +used to allow segregation of the memory used for hardware bitmaps. For instance,
1.310 +if a device has video memory attached to display and graphics accelerator
1.311 +hardware, this UID is used to determine whether any video memory is pre-allocated
1.312 +for that application's use.
1.313 +@return KErrNone if successful, otherwise one of the system wide error codes.
1.314 +These include KErrCouldNotConnect if no connection has been made to the font
1.315 +and bitmap server, KErrArgument if either the width or height specified in
1.316 +aSizeInPixels are negative or if the requested display mode is invalid, or KErrNotSupported
1.317 +if hardware bitmaps are not supported on the device.
1.318 +@publishedAll
1.319 +@released
1.320 +*/
1.321 +EXPORT_C TInt CFbsBitmap::CreateHardwareBitmap(const TSize& aSizeInPixels,TDisplayMode aDispMode,TUid aCreatorUid)
1.322 + {
1.323 + 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);)
1.324 + TInt err = DoCreate(aSizeInPixels,aDispMode,aCreatorUid);
1.325 + FBS_OST(TInt ssh = (iFbs ? iFbs->ServerSessionHandle() : 0);)
1.326 + 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);)
1.327 + return err;
1.328 + }
1.329 +
1.330 +/** Resets the pixel-size of the bitmap.
1.331 +If the new size is bigger than the old, the original bitmap is still situated
1.332 +at (0,0), but pixels outside the range of the old pixel-size are set to zero.
1.333 +@param aSizeInPixels The new size of the bitmap.
1.334 +@return KErrNone if successful; KErrArgument if the new size is illegal;
1.335 +KErrGeneral if the bitmap has not yet been created; KErrAccessDenied if the
1.336 +bitmap is in ROM or is an extended bitmap; otherwise another of the system-wide error codes.
1.337 +@publishedAll
1.338 +@released
1.339 +*/
1.340 +EXPORT_C TInt CFbsBitmap::Resize(const TSize& aSizeInPixels)
1.341 + {
1.342 + if(aSizeInPixels.iWidth<0 || aSizeInPixels.iHeight<0)
1.343 + return(KErrArgument);
1.344 + if(aSizeInPixels.iWidth>KMaxPixelSize || aSizeInPixels.iHeight>KMaxPixelSize)
1.345 + return(KErrTooBig);
1.346 + if(!iHandle)
1.347 + return(KErrGeneral);
1.348 + if (iFlags & EIsReadOnlyBitmapMask)
1.349 + return(KErrAccessDenied);
1.350 + TPckgBuf<TBmpHandles> handlebuf;
1.351 + TIpcArgs args(iHandle, aSizeInPixels.iWidth, aSizeInPixels.iHeight, &handlebuf);
1.352 + TInt err = iFbs->SendCommand(EFbsMessBitmapResize, args);
1.353 + if (err != KErrNone)
1.354 + return (err);
1.355 + iHandle = handlebuf().iHandle;
1.356 + iServerHandle = handlebuf().iServerHandle;
1.357 + iAddressPointer = (CBitwiseBitmap*)(iFbs->HeapBase() + handlebuf().iAddressOffset);
1.358 + return iFbs->AllocScanLineBuffer(CBitwiseBitmap::ByteWidth(aSizeInPixels.iWidth, DisplayMode())+4);
1.359 + }
1.360 +
1.361 +/** Gets the display mode of the bitmap.
1.362 +@return The display mode of the bitmap.
1.363 +@publishedAll
1.364 +@released
1.365 +*/
1.366 +EXPORT_C TDisplayMode CFbsBitmap::DisplayMode() const
1.367 + {
1.368 + if(iHandle==NULL) return(ENone);
1.369 + return CleanAddress()->DisplayMode();
1.370 + }
1.371 +
1.372 +/** Returns the display mode that was used to create the bitmap.
1.373 +@return The display mode used to create the bitmap.
1.374 +@publishedAll
1.375 +@released
1.376 +*/
1.377 +EXPORT_C TDisplayMode CFbsBitmap::InitialDisplayMode() const
1.378 + {
1.379 + if(iHandle == NULL)
1.380 + {
1.381 + return ENone;
1.382 + }
1.383 + return CleanAddress()->InitialDisplayMode();
1.384 + }
1.385 +
1.386 +/**
1.387 +Changes the display mode of the bitmap.
1.388 +The requested display mode cannot be greater (in bpp value) than the initial display mode.
1.389 +This method cannot leave, for instance because of an out of memory condition. No
1.390 +additional memory is allocated or leaving methods called.
1.391 +The bitmap's content is preserved when converting it to the requested display mode,
1.392 +but there may be some loss of quality.
1.393 +@publishedAll
1.394 +@released
1.395 +@param aDisplayMode The requested display mode.
1.396 +@return KErrArgument if the requested mode is invalid, or has a greater bpp value
1.397 +than the initial mode. KErrNotSupported if the bitmap is compressed, or is a
1.398 +ROM bitmap, an extended bitmap or a hardware bitmap. KErrGeneral if the bitmap
1.399 +handle is NULL. KErrNone if the method call is successful.
1.400 +@see CFbsBitmap::InitialDisplayMode()
1.401 +*/
1.402 +EXPORT_C TInt CFbsBitmap::SetDisplayMode(TDisplayMode aDisplayMode)
1.403 + {
1.404 + if(!iHandle)
1.405 + {
1.406 + return KErrGeneral;
1.407 + }
1.408 + TUint32* data;
1.409 + CBitwiseBitmap* bmp = BeginDataAccessAndGetCleanAddress(data);
1.410 + TInt err = bmp->SetDisplayMode(aDisplayMode, data);
1.411 + EndDataAccess(EFalse);
1.412 + return err;
1.413 + }
1.414 +
1.415 +/** Duplicates a bitmap.
1.416 +This function does not create a copy of the bitmap. It just assigns another
1.417 +handle to the bitmap in the font and bitmap server, and sets this object's
1.418 +handle to that. If the specified bitmap is in the ROM, it just assigns a pointer
1.419 +to it.
1.420 +@param aHandle The handle to an existing bitmap.
1.421 +@return KErrNone if successful; KErrCouldNotConnect if no connection to the
1.422 +font and bitmap server could be made; KErrUnknown if no bitmap could be found
1.423 +with the specified handle number.
1.424 +@publishedAll
1.425 +@released
1.426 +@see CFbsBitmap::Handle()
1.427 +*/
1.428 +EXPORT_C TInt CFbsBitmap::Duplicate(TInt aBitmapHandle)
1.429 + {
1.430 + TInt ret = KErrNone;
1.431 + FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_DUPLICATE_ENTRY, "> this=0x%08x; iH=0x%08x;", (TUint)this, aBitmapHandle);)
1.432 + if(!iFbs)
1.433 + {
1.434 + ret = KErrCouldNotConnect;
1.435 + FBS_OST(OstTrace1( TRACE_ERROR, CFBSBITMAP_DUPLICATE_ERROR, "! this=0x%08x; !iFbs", (TUint)this);)
1.436 + }
1.437 + else if(!aBitmapHandle)
1.438 + {
1.439 + ret = KErrUnknown;
1.440 + FBS_OST(OstTrace1( TRACE_ERROR, CFBSBITMAP_DUPLICATE_ERROR2, "! this=0x%08x; !aBitmapHandle", (TUint)this);)
1.441 + }
1.442 + else
1.443 + {
1.444 + TBool isinrom = EFalse;
1.445 + ret = User::IsRomAddress(isinrom, (TAny*)aBitmapHandle);
1.446 + if (ret == KErrNone)
1.447 + {
1.448 + if (isinrom)
1.449 + {
1.450 + ret = DuplicateInRom(aBitmapHandle);
1.451 + FBS_OST_IF(ret != KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_DUPLICATE_ERROR4, "! this=0x%08x; DuplicateInRom() returned %d;", (TUint)this, ret);)
1.452 + }
1.453 + else
1.454 + {
1.455 + ret = DuplicateInRam(aBitmapHandle);
1.456 + FBS_OST_IF(ret != KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_DUPLICATE_ERROR5, "! this=0x%08x; DuplicateInRam() returned %d;", (TUint)this, ret);)
1.457 + }
1.458 + }
1.459 + else
1.460 + {
1.461 + FBS_OST(OstTraceExt2( TRACE_ERROR, CFBSBITMAP_DUPLICATE_ERROR3, "! this=0x%08x; IsRomAddress() returned %d", (TUint)this, ret);)
1.462 + ret = KErrUnknown;
1.463 + }
1.464 + }
1.465 + FBS_OST(TInt ssh = (iFbs ? iFbs->ServerSessionHandle() : 0);)
1.466 + 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);)
1.467 + return ret;
1.468 + }
1.469 +
1.470 +/** Duplicates a bitmap where the bitmap handle refers to a rom bitmap.
1.471 +@param aBitmapHandle A valid Rom bitmap handle.
1.472 +@return KErrNone on success.
1.473 + */
1.474 +TInt CFbsBitmap::DuplicateInRom(TInt aBitmapHandle)
1.475 + {
1.476 + TInt ret = KErrNone;
1.477 + Reset();
1.478 + TUid uid = ((CBitwiseBitmap*)aBitmapHandle)->Uid();
1.479 + if (uid != KCBitwiseBitmapUid)
1.480 + {
1.481 + FBS_OST(OstTraceExt2( TRACE_ERROR, CFBSBITMAP_DUPLICATEINROM_ERROR, "! this=0x%08x; 0x%08x != KCBitwiseBitmapUid", (TUint)this, (TUint)uid.iUid);)
1.482 + ret = KErrUnknown;
1.483 + }
1.484 + else
1.485 + {
1.486 + iAddressPointer = (CBitwiseBitmap*)aBitmapHandle;
1.487 + iFlags = EIsRomBitmap;
1.488 + iHandle=1;
1.489 + ret = iFbs->AllocScanLineBuffer(iAddressPointer->iByteWidth + 4);
1.490 + FBS_OST_IF(ret!=KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_DUPLICATEINROM_ERROR2, "! this=0x%08x; AllocScanLineBuffer() returned %d", (TUint)this, ret);)
1.491 + }
1.492 + return ret;
1.493 + }
1.494 +
1.495 +/** Duplicates a bitmap where the bitmap handle refers to a ram bitmap
1.496 +@param aBitmapHandle A valid Ram bitmap handle.
1.497 +@return KErrNone on success.
1.498 + */
1.499 +TInt CFbsBitmap::DuplicateInRam(TInt aBitmapHandle)
1.500 + {
1.501 + TInt ret = KErrNone;
1.502 + Reset();
1.503 +
1.504 + TPckgBuf<TBmpHandles> b;
1.505 + TIpcArgs args(aBitmapHandle,&b);
1.506 + ret=iFbs->SendCommand(EFbsMessBitmapDuplicate,args);
1.507 + FBS_OST_IF(ret!=KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_DUPLICATEINRAM_ERROR, "! this=0x%08x; SendCommand(EFbsMessBitmapDuplicate) returned %d", (TUint)this, ret);)
1.508 + if(ret==KErrNone)
1.509 + {
1.510 + iHandle=b().iHandle;
1.511 + iServerHandle=b().iServerHandle;
1.512 + iAddressPointer=(CBitwiseBitmap*)(iFbs->HeapBase()+b().iAddressOffset);
1.513 + if (iAddressPointer->iUid.iUid != KCBitwiseBitmapUid.iUid && iAddressPointer->iUid.iUid != KCBitwiseBitmapHardwareUid.iUid)
1.514 + {
1.515 + iFlags = EIsExtendedBitmap;
1.516 + }
1.517 + ret = iFbs->iHelper->AddBitmap(*this);
1.518 + FBS_OST_IF(ret!=KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_DUPLICATEINRAM_ERROR2, "! this=0x%08x; AddBitmap() returned %d", (TUint)this, ret);)
1.519 + if (ret == KErrNone)
1.520 + {
1.521 + ret = iFbs->AllocScanLineBuffer(iAddressPointer->iByteWidth+4);
1.522 + FBS_OST_IF(ret!=KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_DUPLICATEINRAM_ERROR3, "! this=0x%08x; AllocScanLineBuffer() returned %d", (TUint)this, ret);)
1.523 + }
1.524 + }
1.525 + return ret;
1.526 + }
1.527 +
1.528 +/** Loads a specific bitmap from a multi-bitmap file.
1.529 +The bitmap may be shared by other font and bitmap server clients.
1.530 +@param aFileName The filename of the multi-bitmap (.mbm) file.
1.531 +@param aId The bitmap identifier.
1.532 +@param aShareIfLoaded Specifies whether or not the loaded bitmap will be made
1.533 +available for sharing between font and bitmap server clients.
1.534 +@return KErrNone if successful, otherwise another of the system error
1.535 +codes.
1.536 +@publishedAll
1.537 +@released
1.538 +*/
1.539 +EXPORT_C TInt CFbsBitmap::Load(const TDesC& aFileName,TInt32 aId,TBool aShareIfLoaded)
1.540 + {
1.541 + 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);)
1.542 + TInt err = Load(aFileName,aId,aShareIfLoaded,0);
1.543 + FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOAD_EXIT, "< this=0x%08x; err=%d", (TUint)this, err);)
1.544 + return err;
1.545 + }
1.546 +
1.547 +/** Loads a specific bitmap from a multi-bitmap file.
1.548 +The bitmap may be shared by other font and bitmap server clients.
1.549 +@param aFileName The filename of the multi-bitmap (.mbm) file.
1.550 +@param aId The bitmap identifier.
1.551 +@param aShareIfLoaded Specifies whether or not the loaded bitmap will be made
1.552 +available for sharing between FBSERV clients.
1.553 +@param aFileOffset Bitmap file section offset within the file.
1.554 +@return KErrNone if successful, otherwise another of the system error codes.
1.555 +@publishedAll
1.556 +@released
1.557 +*/
1.558 +EXPORT_C TInt CFbsBitmap::Load(const TDesC& aFileName,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset)
1.559 + {
1.560 + TInt err = KErrNone;
1.561 + 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);)
1.562 + if(!iFbs)
1.563 + {
1.564 + FBS_OST(OstTrace1( TRACE_ERROR, CFBSBITMAP_LOAD2_ERROR, "! this=0x%08x; !iFbs", (TUint)this);)
1.565 + err = KErrCouldNotConnect;
1.566 + }
1.567 + else
1.568 + {
1.569 + Reset();
1.570 + TUint32* rompointer = NULL;
1.571 + //access using filename has the advantage of using rom address lookup cache
1.572 + IsFileInRom(aFileName, rompointer);
1.573 + TBool romPointerValid;
1.574 + err = DoLoadFromRom(rompointer, aId, aFileOffset, romPointerValid);
1.575 + if(!romPointerValid)
1.576 + {
1.577 + _LIT(KResourcePath, "?:\\Resource\\*");
1.578 + TInt match = aFileName.MatchF(KResourcePath);
1.579 + //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.
1.580 + if (match == 0)
1.581 + {
1.582 + err = DoLoad(aFileName,aId,aShareIfLoaded,aFileOffset);
1.583 + FBS_OST_IF(err!=KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_LOAD2_ERROR3, "! this=0x%08x; DoLoad returned %d", (TUint)this, err);)
1.584 + }
1.585 + else
1.586 + {
1.587 + RFile file;
1.588 + err = file.Open(iFbs->FileServer(),aFileName,EFileShareReadersOnly);
1.589 + if (err==KErrNone)
1.590 + {
1.591 + err = DoLoad(file,aId,aShareIfLoaded,aFileOffset);
1.592 + FBS_OST_IF(err!=KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_LOAD2_ERROR4, "! this=0x%08x; DoLoad returned %d", (TUint)this, err);)
1.593 + }
1.594 + file.Close();
1.595 + }
1.596 + }
1.597 + }
1.598 + FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOAD2_EXIT, "< this=0x%08x; err=%d", (TUint)this, err);)
1.599 + return err;
1.600 + }
1.601 +
1.602 +/** Loads and compresses a specific bitmap from a multi-bitmap file.
1.603 +The bitmap may be shared by other font and bitmap server clients.
1.604 +If the bitmap is loaded from ROM then compression is not allowed.
1.605 +@param aFileName The filename of the multi-bitmap (.mbm) file.
1.606 +@param aId The bitmap identifier.
1.607 +@param aShareIfLoaded Specifies whether or not the loaded bitmap will be
1.608 +made available for sharing between FBSERV clients.
1.609 +@return KErrNone if successful, otherwise another of the system-wide error
1.610 +codes.
1.611 +@publishedAll
1.612 +@released
1.613 +*/
1.614 +EXPORT_C TInt CFbsBitmap::LoadAndCompress(const TDesC& aFileName,TInt32 aId,TBool aShareIfLoaded)
1.615 + {
1.616 + 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);)
1.617 + TInt ret = LoadAndCompress(aFileName, aId, aShareIfLoaded, 0);
1.618 + FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOADANDCOMPRESS_EXIT, "< this=0x%08x; err=%d", (TUint)this, ret);)
1.619 + return ret;
1.620 + }
1.621 +
1.622 +/** Loads and compresses a specific bitmap from a multi-bitmap file.
1.623 +The bitmap may be shared by other font and bitmap server clients. If the
1.624 +bitmap is loaded from ROM then compression is not allowed.
1.625 +@param aFileName The filename of the multi-bitmap (.mbm) file.
1.626 +@param aId The bitmap identifier.
1.627 +@param aShareIfLoaded Specifies whether or not the loaded bitmap will be made
1.628 +available for sharing between FBSERV clients.
1.629 +@param aFileOffset Bitmap file section offset within the file.
1.630 +@return KErrNone if successful, otherwise another of the system-wide error
1.631 +codes.
1.632 +@publishedAll
1.633 +@released
1.634 +*/
1.635 +EXPORT_C TInt CFbsBitmap::LoadAndCompress(const TDesC& aFileName,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset)
1.636 + {
1.637 + 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);)
1.638 + TInt err = Load(aFileName,aId,aShareIfLoaded,aFileOffset);
1.639 + if (err == KErrNone)
1.640 + {
1.641 + err = !(iFlags & EIsRomBitmap) ? Compress() : KErrAccessDenied;
1.642 + FBS_OST_IF(err!=KErrNone, OstTraceExt3( TRACE_ERROR, CFBSBITMAP_LOADANDCOMPRESS2_ERROR, "! this=0x%08x; iFlags=0x%08x; err=%d", (TUint)this, (TUint)iFlags, err);)
1.643 + }
1.644 + FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOADANDCOMPRESS2_EXIT, "< this=0x%08x; err=%d", (TUint)this, err);)
1.645 + return err;
1.646 + }
1.647 +
1.648 +/** Saves the bitmap as a direct file store.
1.649 +The file store overwrites any existing file with the same name.
1.650 +@param aFilename The name of the file.
1.651 +@return KErrNone if successful, KErrNotSupported if this CFbsBitmap is an
1.652 +extended bitmap, otherwise another of the system-wide error codes.
1.653 +@publishedAll
1.654 +@released
1.655 +*/
1.656 +EXPORT_C TInt CFbsBitmap::Save(const TDesC& aFilename)
1.657 + {
1.658 + if (!iHandle)
1.659 + {
1.660 + return(KErrGeneral);
1.661 + }
1.662 + RFile file;
1.663 + TInt ret=file.Replace(iFbs->FileServer(),aFilename,EFileWrite);
1.664 + if(ret!=KErrNone) return(ret);
1.665 + TRAP(ret,DoSaveL(file));
1.666 + file.Close();
1.667 + return(ret);
1.668 + }
1.669 +
1.670 +/** Saves the bitmap as a direct file store using an opened file handle.
1.671 +The file store overwrites any existing file with the same name.
1.672 +@param aFile The opened file handle
1.673 +@return KErrNone if successful, KErrNotSupported if this CFbsBitmap is an
1.674 +extended bitmap, otherwise another of the system-wide error codes.
1.675 +@publishedAll
1.676 +@released
1.677 +*/
1.678 +EXPORT_C TInt CFbsBitmap::Save(RFile& aFile)
1.679 + {
1.680 + if (!iHandle)
1.681 + {
1.682 + return KErrGeneral;
1.683 + }
1.684 + TRAPD(ret,DoSaveL(aFile));
1.685 + return ret;
1.686 + }
1.687 +
1.688 +void CFbsBitmap::DoSaveL(RFile& aFile)
1.689 + {
1.690 + CDirectFileStore* filestore=CDirectFileStore::NewLC(aFile); // create from open file
1.691 + TUidType uidtype(KDirectFileStoreLayoutUid,KMultiBitmapFileImageUid);
1.692 + filestore->SetTypeL(uidtype);
1.693 + RStoreWriteStream bmpstream;
1.694 + TStreamId bmpstreamid=bmpstream.CreateLC(*filestore); // create bitmap stream
1.695 + ExternalizeL(bmpstream);
1.696 + bmpstream.CommitL();
1.697 + CleanupStack::PopAndDestroy(); // bitmap stream
1.698 + RStoreWriteStream rootstream;
1.699 + TStreamId rootstreamid=rootstream.CreateLC(*filestore); // create root stream
1.700 + rootstream.WriteInt32L(1); // number of bitmaps
1.701 + rootstream<<bmpstreamid; // stream id of bitmap
1.702 + rootstream.CommitL();
1.703 + CleanupStack::PopAndDestroy(); // root stream
1.704 + filestore->SetRootL(rootstreamid);
1.705 + filestore->CommitL();
1.706 + CleanupStack::PopAndDestroy(); // file store
1.707 + }
1.708 +
1.709 +/** Constructs a multi-bitmap file.
1.710 +@param aFilename The name of the multi-bitmap file to be created.
1.711 +@param aNumSources The number of bitmaps to store in the file.
1.712 +@param aSources An array of pointers to bitmaps to be stored.
1.713 +@param aSourceIds An array of identifiers for the bitmaps to be stored.
1.714 +@publishedAll
1.715 +@released
1.716 +*/
1.717 +EXPORT_C void CFbsBitmap::StoreL(const TDesC& aFilename,TInt aNumSources,const TDesC* aSources[],TInt32 aSourceIds[])
1.718 + {
1.719 + CFbsBitmap* bitmap = new(ELeave) CFbsBitmap;
1.720 + CleanupStack::PushL(bitmap);
1.721 + CDirectFileStore* filestore = CDirectFileStore::ReplaceLC(bitmap->iFbs->FileServer(),aFilename,EFileWrite);
1.722 + DoStoreL(filestore,bitmap,aNumSources,aSources,aSourceIds);
1.723 + CleanupStack::PopAndDestroy(2,bitmap);
1.724 + }
1.725 +
1.726 +/** Constructs a multi-bitmap file using an opened file handle.
1.727 +@param aFile The opened file handle of multi-bitmap file
1.728 +@param aNumSources The number of bitmaps to store in the file.
1.729 +@param aSources An array of pointers to bitmaps to be stored.
1.730 +@param aSourceIds An array of identifiers for the bitmaps to be stored.
1.731 +@publishedAll
1.732 +@released
1.733 +*/
1.734 +EXPORT_C void CFbsBitmap::StoreL(RFile& aFile,TInt aNumSources,const TDesC* aSources[],TInt32 aSourceIds[])
1.735 + {
1.736 + CDirectFileStore* filestore = CDirectFileStore::NewLC(aFile);
1.737 + DoStoreL(filestore,NULL,aNumSources,aSources,aSourceIds);
1.738 + CleanupStack::PopAndDestroy(filestore);
1.739 + }
1.740 +
1.741 +/**
1.742 +@internalComponent
1.743 +*/
1.744 +void CFbsBitmap::DoStoreL(CDirectFileStore* aFileStore,CFbsBitmap* aBitmap,TInt aNumSources,const TDesC* aSources[],TInt32 aSourceIds[])
1.745 + {
1.746 + if(aNumSources<1 || aSources==NULL) User::Leave(KErrArgument);
1.747 + TInt count=0;
1.748 + for(;count<aNumSources;count++)
1.749 + if(aSources[count]==NULL) User::Leave(KErrArgument);
1.750 + TStreamId* ids=new(ELeave) TStreamId[aNumSources];
1.751 + CleanupArrayDeletePushL(ids);
1.752 + TInt nPushed=1;
1.753 + if (!aBitmap)
1.754 + {
1.755 + aBitmap=new(ELeave) CFbsBitmap;
1.756 + CleanupStack::PushL(aBitmap);
1.757 + ++nPushed;
1.758 + }
1.759 + TUidType uidtype(KDirectFileStoreLayoutUid,KMultiBitmapFileImageUid);
1.760 + aFileStore->SetTypeL(uidtype);
1.761 + for(count=0;count<aNumSources;count++)
1.762 + {
1.763 + User::LeaveIfError(aBitmap->Load(*aSources[count],aSourceIds[count]));
1.764 + RStoreWriteStream bmpstream;
1.765 + ids[count]=bmpstream.CreateLC(*aFileStore); // create bitmap stream
1.766 + aBitmap->ExternalizeL(bmpstream);
1.767 + bmpstream.Close();
1.768 + CleanupStack::Pop(); // bitmap stream
1.769 + }
1.770 + RStoreWriteStream rootstream;
1.771 + TStreamId rootstreamid=rootstream.CreateLC(*aFileStore); // create root stream
1.772 + rootstream.WriteInt32L(aNumSources); // number of bitmaps
1.773 + for(count=0;count<aNumSources;count++)
1.774 + rootstream<<ids[count]; // stream ids of bitmaps
1.775 + rootstream.Close();
1.776 + CleanupStack::Pop(); // root stream
1.777 + aFileStore->SetRootL(rootstreamid);
1.778 + CleanupStack::PopAndDestroy(nPushed); // ids [and bitmap]
1.779 + }
1.780 +
1.781 +/** Gets the bitmap's scanline for the specified line starting from the
1.782 +specified point.
1.783 +The dither offset of the bitmap is taken to be TPoint(0,0).
1.784 +@param aBuf The buffer in which the scanline is returned.
1.785 +@param aPoint The start pixel.
1.786 +@param aLength The number of pixels to get.
1.787 +@param aDispMode Format to be used to write the data to the buffer.
1.788 +@publishedAll
1.789 +@released
1.790 +*/
1.791 +EXPORT_C void CFbsBitmap::GetScanLine(TDes8& aBuf,const TPoint& aPoint,TInt aLength,TDisplayMode aDispMode) const
1.792 + {
1.793 + GetScanLine(aBuf,aPoint,aLength,TPoint(0,0),aDispMode);
1.794 + }
1.795 +
1.796 +/** Gets the bitmap's scanline for the specified line starting from the specified
1.797 +point and using the specified dither offset.
1.798 +@param aBuf The buffer in which the scanline is returned.
1.799 +@param aPixel The start pixel.
1.800 +@param aLength The number of pixels to get.
1.801 +@param aDitherOffset The dither offset of the bitmap.
1.802 +@param aDispMode Format to be used to write the data to the buffer.
1.803 +@publishedAll
1.804 +@released
1.805 +*/
1.806 +EXPORT_C void CFbsBitmap::GetScanLine(TDes8& aBuf,const TPoint& aPoint,TInt aLength,const TPoint& aDitherOffset,TDisplayMode aDispMode) const
1.807 + {
1.808 + if(!iHandle) return;
1.809 + TUint32* data;
1.810 + CBitwiseBitmap* bmp = BeginDataAccessAndGetCleanAddress(data);
1.811 + CFbsRasterizer* rasterizer = NULL;
1.812 + if ((iFlags & EIsExtendedBitmap) && iFbs)
1.813 + {
1.814 + rasterizer = iFbs->iHelper->Rasterizer();
1.815 + if (rasterizer)
1.816 + {
1.817 + CFbsRasterizer::TBitmapDesc desc;
1.818 + desc.iSizeInPixels = bmp->SizeInPixels();
1.819 + desc.iDispMode = bmp->DisplayMode();
1.820 + desc.iDataType = bmp->iUid;
1.821 + desc.iData = data;
1.822 + desc.iDataSize = bmp->iHeader.iBitmapSize - bmp->iHeader.iStructSize;
1.823 + rasterizer->BeginBitmap(bmp->Extra()->iSerialNumber, desc, NULL);
1.824 + }
1.825 + }
1.826 + bmp->GetScanLine(aBuf, aPoint, aLength, ETrue, aDitherOffset, aDispMode, data);
1.827 + if (rasterizer)
1.828 + {
1.829 + rasterizer->EndBitmap(bmp->Extra()->iSerialNumber);
1.830 + }
1.831 + EndDataAccess(ETrue);
1.832 + }
1.833 +
1.834 +/** Sets the bitmap's horizontal scanline at the specified y co-ordinate to the
1.835 +scanline contained in the buffer.
1.836 +@param aBuf The new scanline to be written to the bitmap.
1.837 +@param aY The y co-ordinate of the scanline.
1.838 +@panic FBSCLI 11 in debug builds if this is a compressed bitmap.
1.839 +@panic FBSCLI 28 in debug builds if this is a read-only bitmap.
1.840 +@publishedAll
1.841 +@released
1.842 +*/
1.843 +EXPORT_C void CFbsBitmap::SetScanLine(TDes8& aBuf,TInt aY) const
1.844 + {
1.845 + if (!iHandle)
1.846 + return;
1.847 + if (iFlags & EIsReadOnlyBitmapMask)
1.848 + {
1.849 + __ASSERT_DEBUG(EFalse, ::Panic(EFbsPanicBitmapReadOnly));
1.850 + return;
1.851 + }
1.852 + TUint32* data;
1.853 + CBitwiseBitmap* bmp = BeginDataAccessAndGetCleanAddress(data);
1.854 + if (bmp->IsCompressed())
1.855 + {
1.856 + EndDataAccess(ETrue);
1.857 + __ASSERT_DEBUG(EFalse, ::Panic(EFbsBitmapInvalidCompression));
1.858 + return;
1.859 + }
1.860 + data = bmp->ScanLineAddress(data, aY);
1.861 + TInt bytewidth = bmp->iByteWidth;
1.862 + TInt bytelen=aBuf.Length();
1.863 + if(bytelen<bytewidth) bytewidth=bytelen;
1.864 + TInt wordlen=bytewidth>>2;
1.865 + TUint32* ptr=(TUint32*)aBuf.Ptr();
1.866 + TUint32* ptrlim=ptr+wordlen;
1.867 + while(ptr<ptrlim)
1.868 + *data++=*ptr++;
1.869 + TInt limit=wordlen<<2;
1.870 + if(limit<bytewidth)
1.871 + {
1.872 + TUint8* byteptr=(TUint8*)ptrlim;
1.873 + TUint8* databyte=(TUint8*)data;
1.874 + while(limit<bytewidth)
1.875 + {
1.876 + *databyte++=*byteptr++;
1.877 + limit++;
1.878 + }
1.879 + }
1.880 + EndDataAccess(EFalse);
1.881 + }
1.882 +
1.883 +/** Gets the bitmap's vertical scanline starting at the specified x co-ordinate.
1.884 +Note: The method only works for uncompressed bitmaps.
1.885 +Note: The dither offset of the bitmap is taken to be TPoint(0,0).
1.886 +@param aBuf The buffer in which the vertical scanline is returned.
1.887 +@param aX The x co-ordinate of the vertical scanline.
1.888 +@param aDispMode Format to be used to write the data to the buffer.
1.889 +@panic FBSCLI 11 in debug builds if this is not an ucompressed bitmap or an extended bitmap.
1.890 +@publishedAll
1.891 +@released
1.892 +*/
1.893 +EXPORT_C void CFbsBitmap::GetVerticalScanLine(TDes8& aBuf,TInt aX,TDisplayMode aDispMode) const
1.894 + {
1.895 + GetVerticalScanLine(aBuf,aX,TPoint(0,0),aDispMode);
1.896 + }
1.897 +
1.898 +/** Gets the bitmap's vertical scanline starting at the specified x co-ordinate
1.899 +and using the specified dither offset.
1.900 +Note: The method only works for uncompressed bitmaps.
1.901 +@param aBuf The buffer in which the vertical scanline will be returned.
1.902 +@param aX The x co-ordinate of the vertical scanline to get.
1.903 +@param aDitherOffset The dither offset of the bitmap.
1.904 +@param aDispMode Format to be used to write the data to the buffer.
1.905 +@panic FBSCLI 11 in debug builds if this is not an ucompressed bitmap or an extended bitmap.
1.906 +@publishedAll
1.907 +@released
1.908 +*/
1.909 +EXPORT_C void CFbsBitmap::GetVerticalScanLine(TDes8& aBuf,TInt aX,const TPoint& aDitherOffset,TDisplayMode aDispMode) const
1.910 + {
1.911 + if(!iHandle) return;
1.912 + TUint32* data;
1.913 + CBitwiseBitmap* bmp = BeginDataAccessAndGetCleanAddress(data);
1.914 + CFbsRasterizer* rasterizer = NULL;
1.915 + if ((iFlags & EIsExtendedBitmap) && iFbs)
1.916 + {
1.917 + rasterizer = iFbs->iHelper->Rasterizer();
1.918 + if (rasterizer)
1.919 + {
1.920 + CFbsRasterizer::TBitmapDesc desc;
1.921 + desc.iSizeInPixels = bmp->SizeInPixels();
1.922 + desc.iDispMode = bmp->DisplayMode();
1.923 + desc.iDataType = bmp->iUid;
1.924 + desc.iData = data;
1.925 + desc.iDataSize = bmp->iHeader.iBitmapSize - bmp->iHeader.iStructSize;
1.926 + rasterizer->BeginBitmap(bmp->Extra()->iSerialNumber, desc, NULL);
1.927 + }
1.928 + }
1.929 + bmp->GetVerticalScanLine(aBuf, aX, ETrue, aDitherOffset, aDispMode, data, rasterizer);
1.930 + if (rasterizer)
1.931 + {
1.932 + rasterizer->EndBitmap(bmp->Extra()->iSerialNumber);
1.933 + }
1.934 + EndDataAccess(ETrue);
1.935 + }
1.936 +
1.937 +/** Gets the handle number of the bitmap.
1.938 +The returned value can be used to give another thread access to the bitmap.
1.939 +@return The handle number of the bitmap.
1.940 +@publishedAll
1.941 +@released
1.942 +@see CFbsBitmap::Duplicate()
1.943 +*/
1.944 +EXPORT_C TInt CFbsBitmap::Handle() const
1.945 + {
1.946 + if(!iHandle)
1.947 + return(0);
1.948 + if (iFlags & EIsRomBitmap)
1.949 + return TInt(iAddressPointer);
1.950 + else
1.951 + return(iServerHandle);
1.952 + }
1.953 +
1.954 +/** Creates a bitmap header.
1.955 +This is used when streaming bitmaps to stores.
1.956 +@return The bitmap header for the bitmap.
1.957 +@publishedAll
1.958 +@released
1.959 +*/
1.960 +EXPORT_C SEpocBitmapHeader CFbsBitmap::Header() const
1.961 + {
1.962 + if (iHandle)
1.963 + return CleanAddress()->iHeader;
1.964 + SEpocBitmapHeader header;
1.965 + return(header);
1.966 + }
1.967 +
1.968 +/** Converts a horizontal dimension on the graphics device from pixels to twips.
1.969 +@param aPixels A horizontal dimension on the graphics device in pixels.
1.970 +@return A horizontal dimension on the graphics device in twips.
1.971 +@publishedAll
1.972 +@released
1.973 +*/
1.974 +EXPORT_C TInt CFbsBitmap::HorizontalPixelsToTwips(TInt aPixels) const
1.975 + {
1.976 + if(iHandle==NULL) return(0);
1.977 + return CleanAddress()->HorizontalPixelsToTwips(aPixels);
1.978 + }
1.979 +
1.980 +/** Converts a horizontal dimension on the graphics device from twips to pixels.
1.981 +@param aTwips A horizontal dimension on the graphics device in twips.
1.982 +@return A horizontal dimension on the graphics device in pixels.
1.983 +@publishedAll
1.984 +@released
1.985 +*/
1.986 +EXPORT_C TInt CFbsBitmap::HorizontalTwipsToPixels(TInt aTwips) const
1.987 + {
1.988 + if(iHandle==NULL) return(0);
1.989 + return CleanAddress()->HorizontalTwipsToPixels(aTwips);
1.990 + }
1.991 +
1.992 +/** Gets the RGB value of the specified pixel.
1.993 +Note: The method only works for uncompressed bitmaps and extended bitmaps.
1.994 +@param aColor On return, the RGB value of the specified pixel.
1.995 +@param aPixel The pixel whose colour is to be determined.
1.996 +@panic FBSCLI 11 in debug builds if this is a compressed bitmap.
1.997 +@publishedAll
1.998 +@released
1.999 +*/
1.1000 +EXPORT_C void CFbsBitmap::GetPixel(TRgb& aColor,const TPoint& aPoint) const
1.1001 + {
1.1002 + if(!iHandle)
1.1003 + {
1.1004 + return;
1.1005 + }
1.1006 +
1.1007 + TUint32* data;
1.1008 + CBitwiseBitmap* bmp = BeginDataAccessAndGetCleanAddress(data);
1.1009 + CFbsRasterizer* rasterizer = NULL;
1.1010 + if ((iFlags & EIsExtendedBitmap) && iFbs)
1.1011 + {
1.1012 + rasterizer = iFbs->iHelper->Rasterizer();
1.1013 + if (rasterizer)
1.1014 + {
1.1015 + CFbsRasterizer::TBitmapDesc desc;
1.1016 + desc.iSizeInPixels = bmp->SizeInPixels();
1.1017 + desc.iDispMode = bmp->DisplayMode();
1.1018 + desc.iDataType = bmp->iUid;
1.1019 + desc.iData = data;
1.1020 + desc.iDataSize = bmp->iHeader.iBitmapSize - bmp->iHeader.iStructSize;
1.1021 + rasterizer->BeginBitmap(bmp->Extra()->iSerialNumber, desc, NULL);
1.1022 + }
1.1023 + }
1.1024 + bmp->GetPixel(aColor, aPoint, data, rasterizer);
1.1025 + if (rasterizer)
1.1026 + {
1.1027 + rasterizer->EndBitmap(bmp->Extra()->iSerialNumber);
1.1028 + }
1.1029 + EndDataAccess(ETrue);
1.1030 + }
1.1031 +
1.1032 +/** Gets the pixel-size of the bitmap.
1.1033 +@return The size of the bitmap, in pixels.
1.1034 +@publishedAll
1.1035 +@released
1.1036 +*/
1.1037 +EXPORT_C TSize CFbsBitmap::SizeInPixels() const
1.1038 + {
1.1039 + TSize zero;
1.1040 + if(!iHandle) return(zero);
1.1041 + return CleanAddress()->SizeInPixels();
1.1042 + }
1.1043 +
1.1044 +/** Sets the twip-size of the bitmap by converting the bitmaps pixel-size from
1.1045 +pixels to twips, using the conversion functions in the specified graphics
1.1046 +device map.
1.1047 +@param aMap The graphics device map to be used for providing pixel to twip
1.1048 +conversion.
1.1049 +@publishedAll
1.1050 +@released
1.1051 +*/
1.1052 +EXPORT_C void CFbsBitmap::SetSizeInTwips(const MGraphicsDeviceMap* aMap)
1.1053 + {
1.1054 + if (!iHandle || (iFlags & EIsRomBitmap) || aMap == NULL)
1.1055 + return;
1.1056 + TSize size=SizeInPixels();
1.1057 + size.iWidth=aMap->HorizontalPixelsToTwips(size.iWidth);
1.1058 + size.iHeight=aMap->VerticalPixelsToTwips(size.iHeight);
1.1059 + iFbs->SetCallBackPtr(&iServerHandle);
1.1060 + iFbs->CallBack();
1.1061 + // SizeInPixels() called CleanAddress() so call Address() now to make sure we don't clean the bitmap twice
1.1062 + Address()->iHeader.iSizeInTwips=size;
1.1063 + }
1.1064 +
1.1065 +/** Sets the twip-size of the bitmap directly to the specified size.
1.1066 +@param aSizeInTwips The new size of the bitmap, in twips.
1.1067 +@publishedAll
1.1068 +@released
1.1069 +*/
1.1070 +EXPORT_C void CFbsBitmap::SetSizeInTwips(const TSize& aSizeInTwips)
1.1071 + {
1.1072 + if (!iHandle || (iFlags & EIsRomBitmap))
1.1073 + return;
1.1074 + iFbs->SetCallBackPtr(&iServerHandle);
1.1075 + iFbs->CallBack();
1.1076 + CleanAddress()->iHeader.iSizeInTwips = aSizeInTwips;
1.1077 + }
1.1078 +
1.1079 +/** Externalises the bitmap to the specified stream. Not supported for extended bitmaps.
1.1080 +@param aStream The write stream.
1.1081 +@publishedAll
1.1082 +@released
1.1083 +*/
1.1084 +EXPORT_C void CFbsBitmap::ExternalizeL(RWriteStream& aStream) const
1.1085 + {
1.1086 + if (!iHandle)
1.1087 + User::Leave(KErrGeneral);
1.1088 + BeginDataAccess();
1.1089 + Address()->ExternalizeL(aStream, *this);
1.1090 + EndDataAccess(ETrue);
1.1091 + }
1.1092 +
1.1093 +/** Externalises that area of the bitmap contained within a specified
1.1094 +rectangular area. Not supported for extended bitmaps.
1.1095 +@param aStream The write stream
1.1096 +@param aRect The rectangular area of the bitmap to externalise. The bitmap
1.1097 +that is externalized will be of this size.
1.1098 +@publishedAll
1.1099 +@released
1.1100 +*/
1.1101 +EXPORT_C void CFbsBitmap::ExternalizeRectangleL(RWriteStream& aStream,const TRect& aRect) const
1.1102 + {
1.1103 + if (!iHandle)
1.1104 + User::Leave(KErrGeneral);
1.1105 + BeginDataAccess();
1.1106 + Address()->ExternalizeRectangleL(aStream, aRect, *this);
1.1107 + EndDataAccess(ETrue);
1.1108 + }
1.1109 +
1.1110 +/** Internalises a CFbsBitmap from a stream.
1.1111 +@param aStream The read stream.
1.1112 +@publishedAll
1.1113 +@released
1.1114 +*/
1.1115 +EXPORT_C void CFbsBitmap::InternalizeL(RReadStream& aStream)
1.1116 + {
1.1117 + if(!iFbs) User::Leave(KErrCouldNotConnect);
1.1118 + Reset();
1.1119 + SEpocBitmapHeader header;
1.1120 + CBitwiseBitmap::InternalizeHeaderL(aStream,header);
1.1121 +
1.1122 + TDisplayMode dispmode = CBitwiseBitmap::DisplayMode(header.iBitsPerPixel,header.iColor);
1.1123 + User::LeaveIfError(Create(header.iSizeInPixels,dispmode));
1.1124 +
1.1125 + TUint32* data;
1.1126 + CBitwiseBitmap* bmp=BeginDataAccessAndGetCleanAddress(data);
1.1127 + bmp->iHeader=header;
1.1128 + TInt bytesize = header.iBitmapSize - header.iStructSize;
1.1129 + if (bytesize > 0)
1.1130 + {
1.1131 + bmp->DoInternalizeL(aStream, bytesize, data);
1.1132 + EndDataAccess(EFalse);
1.1133 + }
1.1134 + else
1.1135 + {
1.1136 + EndDataAccess(ETrue);
1.1137 + }
1.1138 + }
1.1139 +
1.1140 +EXPORT_C TInt CFbsBitmap::Compress()
1.1141 + {
1.1142 + return Compress(ERLECompression);
1.1143 + }
1.1144 +
1.1145 +/** Compresses bitmap in RAM.
1.1146 +@param aScheme specifies preferred compression type ERLECompression or EPaletteCompression
1.1147 +@return KErrNone on success, KErrGeneral if the bitmap handle is NULL, KErrAccessDenied if
1.1148 +the bitmap is in ROM or it is an extended bitmap, otherwise one of the system wide error codes.
1.1149 +@publishedAll
1.1150 +@released
1.1151 +*/
1.1152 +EXPORT_C TInt CFbsBitmap::Compress(TBitmapfileCompressionScheme aScheme)
1.1153 + {
1.1154 + if (!iHandle)
1.1155 + return KErrGeneral;
1.1156 + if (iFlags & EIsReadOnlyBitmapMask)
1.1157 + return KErrAccessDenied;
1.1158 + TPckgBuf<TBmpHandles> handlebuf;
1.1159 + TIpcArgs args(iHandle, aScheme, &handlebuf);
1.1160 + TInt err = iFbs->SendCommand(EFbsMessBitmapCompress, args);
1.1161 + if (err != KErrNone)
1.1162 + return err;
1.1163 + iHandle = handlebuf().iHandle;
1.1164 + iServerHandle = handlebuf().iServerHandle;
1.1165 + iAddressPointer = (CBitwiseBitmap*)(iFbs->HeapBase() + handlebuf().iAddressOffset);
1.1166 + return KErrNone;
1.1167 + }
1.1168 +
1.1169 +/** Submits the bitmap for asynchronous background compression.
1.1170 +@param aRequestStatus The request status which will be completed with the appropriate error code after the compression has finished
1.1171 +The error code will be KErrNone on success, KErrGeneral if the bitmap handle is NULL, KErrAccessDenied if the
1.1172 +bitmap is in ROM or it is an extended bitmap, otherwise one of the system wide error codes.
1.1173 +@publishedAll
1.1174 +@released
1.1175 +*/
1.1176 +EXPORT_C void CFbsBitmap::CompressInBackground(TRequestStatus& aRequestStatus)
1.1177 + {
1.1178 + CompressInBackground(aRequestStatus, ERLECompression);
1.1179 + }
1.1180 +
1.1181 +/** Submits the bitmap for asynchronous background compression. No notification will be provided when the compression has completed.
1.1182 +@return KErrNone if the bitmap was successfully submitted to the background compression queue, KErrGeneral if the bitmap handle is NULL,
1.1183 +KErrAccessDenied if the bitmap is in ROM or it is an extended bitmap, otherwise another of the system-wide error codes.
1.1184 +@publishedAll
1.1185 +@released
1.1186 +*/
1.1187 +EXPORT_C TInt CFbsBitmap::CompressInBackground()
1.1188 + {
1.1189 + return CompressInBackground(ERLECompression);
1.1190 + }
1.1191 +
1.1192 +/** Submits the bitmap for asynchronous background compression.
1.1193 +@param aRequestStatus The request status which will be completed with the appropriate error code after the compression has finished.
1.1194 +The error code will be KErrNone on success, KErrGeneral if the bitmap handle is NULL, KErrAccessDenied if the
1.1195 +bitmap is in ROM or it is an extended bitmap, otherwise one of the system wide error codes.
1.1196 +@param aScheme Specifies preferred compression type: ERLECompression or EPaletteCompression
1.1197 +@publishedAll
1.1198 +@released
1.1199 +*/
1.1200 +EXPORT_C void CFbsBitmap::CompressInBackground(TRequestStatus& aRequestStatus, TBitmapfileCompressionScheme aScheme)
1.1201 + {
1.1202 + TRequestStatus* reqStat = &aRequestStatus;
1.1203 + aRequestStatus = KRequestPending;
1.1204 + if (!iHandle)
1.1205 + User::RequestComplete(reqStat, KErrGeneral);
1.1206 + else if (iFlags & EIsReadOnlyBitmapMask)
1.1207 + User::RequestComplete(reqStat, KErrAccessDenied);
1.1208 + else
1.1209 + {
1.1210 + TIpcArgs args(iHandle, aScheme, ETrue);
1.1211 + iFbs->SendCommand(EFbsMessBitmapBgCompress, args, aRequestStatus);
1.1212 + }
1.1213 + }
1.1214 +
1.1215 +/** Submits the bitmap for asynchronous background compression. No notification will be provided when the compression has completed.
1.1216 +@return KErrNone if the bitmap was successfully submitted to the background compression queue, KErrGeneral if the bitmap handle is NULL,
1.1217 +KErrAccessDenied if the bitmap is in ROM or it is an extended bitmap, otherwise another of the system-wide error codes.
1.1218 +@publishedAll
1.1219 +@released
1.1220 +*/
1.1221 +EXPORT_C TInt CFbsBitmap::CompressInBackground(TBitmapfileCompressionScheme aScheme)
1.1222 + {
1.1223 + if (!iHandle)
1.1224 + return KErrGeneral;
1.1225 + if (iFlags & EIsReadOnlyBitmapMask)
1.1226 + return KErrAccessDenied;
1.1227 + TIpcArgs args(iHandle, aScheme, EFalse);
1.1228 + return iFbs->SendCommand(EFbsMessBitmapBgCompress, args);
1.1229 + }
1.1230 +
1.1231 +/**Tests whether the bitmap located in RAM has been compressed.
1.1232 +@return ETrue if the bitmap is compressed, EFalse otherwise.
1.1233 +@publishedAll
1.1234 +@released
1.1235 +*/
1.1236 +EXPORT_C TBool CFbsBitmap::IsCompressedInRAM() const
1.1237 + {
1.1238 + CBitwiseBitmap* bitmap = CleanAddress();
1.1239 + if (bitmap==NULL)
1.1240 + {
1.1241 + return EFalse;
1.1242 + }
1.1243 + return bitmap->IsCompressedInRAM();
1.1244 + }
1.1245 +
1.1246 +/** Gets the twip-size of the bitmap.
1.1247 +@return The size of the bitmap, in twips.
1.1248 +@publishedAll
1.1249 +@released
1.1250 +*/
1.1251 +EXPORT_C TSize CFbsBitmap::SizeInTwips() const
1.1252 + {
1.1253 + TSize zero;
1.1254 + if(iHandle==NULL) return(zero);
1.1255 + return CleanAddress()->SizeInTwips();
1.1256 + }
1.1257 +
1.1258 +/** Converts a vertical dimension on the graphics device from pixels to twips.
1.1259 +@param aPixels A vertical dimension on the graphics device in pixels.
1.1260 +@return A vertical dimension on the graphics device in twips.
1.1261 +@publishedAll
1.1262 +@released
1.1263 +*/
1.1264 +EXPORT_C TInt CFbsBitmap::VerticalPixelsToTwips(TInt aPixels) const
1.1265 + {
1.1266 + if(iHandle==NULL) return(0);
1.1267 + return CleanAddress()->VerticalPixelsToTwips(aPixels);
1.1268 + }
1.1269 +
1.1270 +/** Converts a vertical dimension on the graphics device from twips to pixels.
1.1271 +@param aTwips A vertical dimension on the graphics device in twips.
1.1272 +@return A vertical dimension on the graphics device in pixels.
1.1273 +@publishedAll
1.1274 +@released
1.1275 +*/
1.1276 +EXPORT_C TInt CFbsBitmap::VerticalTwipsToPixels(TInt aTwips) const
1.1277 + {
1.1278 + if(iHandle==NULL) return(0);
1.1279 + return CleanAddress()->VerticalTwipsToPixels(aTwips);
1.1280 + }
1.1281 +
1.1282 +/** Tests whether or not the specified file is in ROM.
1.1283 +@param aFilename The name of the file.
1.1284 +@param aWord On return, contains the address of the file in ROM.
1.1285 +@return ETrue if the file is in the ROM; EFalse otherwise.
1.1286 +@publishedAll
1.1287 +@released
1.1288 +*/
1.1289 +EXPORT_C TBool CFbsBitmap::IsFileInRom(const TDesC& aFilename,TUint32*& aWord)
1.1290 + {
1.1291 + RFbsSession* fbs=RFbsSession::GetSession();
1.1292 + __ASSERT_ALWAYS(fbs,Panic(EFbsPanicNoConnection));
1.1293 + return fbs->LookupBitmapInROM (aFilename, (TAny*&)aWord);
1.1294 + }
1.1295 +
1.1296 +/** Tests whether or not the specified file is in ROM.
1.1297 +@param aFile The file handle
1.1298 +@param aWord On return, contains the address of the file in ROM.
1.1299 +@return ETrue if the file is in the ROM; EFalse otherwise.
1.1300 +@publishedAll
1.1301 +@released
1.1302 +*/
1.1303 +EXPORT_C TBool CFbsBitmap::IsFileInRom(RFile& aFile,TUint32*& aWord)
1.1304 + {
1.1305 + // cannot use rom lookup cache as filename is not available
1.1306 + // offset must be initialised to zero to indicate beginning of the file
1.1307 + aWord = 0;
1.1308 + return aFile.Seek(ESeekAddress,(TInt&)aWord)==KErrNone;
1.1309 + }
1.1310 +
1.1311 +/** Tests whether or not the bitmap is monochrome.
1.1312 +Monochrome bitmaps have a display-mode of 1 bit-per-pixel.
1.1313 +@return ETrue if the bitmap is monochrome; EFalse otherwise.
1.1314 +@publishedAll
1.1315 +@released
1.1316 +*/
1.1317 +EXPORT_C TBool CFbsBitmap::IsMonochrome() const
1.1318 + {
1.1319 + if(!iHandle) return(EFalse);
1.1320 + TUint32* data;
1.1321 + CBitwiseBitmap* bmp = BeginDataAccessAndGetCleanAddress(data);
1.1322 + TBool isMonochrome = bmp->IsMonochrome(data);
1.1323 + EndDataAccess(ETrue);
1.1324 + return isMonochrome;
1.1325 + }
1.1326 +
1.1327 +/** Marks the beginning of direct access to the bitmap data.
1.1328 +This function prepares the bitmap for direct access to its pixel data
1.1329 +and should be used before calling DataAddress(), otherwise performance
1.1330 +may be degraded on certain platforms.
1.1331 +Calls to BeginDataAccess() must be coupled with subsequent calls to EndDataAccess().
1.1332 +
1.1333 +@publishedAll
1.1334 +@released
1.1335 +@see CFbsBitmap::DataAddress()
1.1336 +@see CFbsBitmap::EndDataAccess()
1.1337 +*/
1.1338 +EXPORT_C void CFbsBitmap::BeginDataAccess() const
1.1339 + {
1.1340 + FBS_OST_VERBOSE(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_BEGINDATAACCESS_ENTRY, "> this=0x%08x;", (TUint)this););
1.1341 + FBS_OST_IF(!iHandle, OstTrace1(TRACE_ERROR, CFBSBITMAP_BEGINDATAACCESS_ERROR, "! this=0x%08x; !iHandle", (TUint)this););
1.1342 +
1.1343 + if (iHandle)
1.1344 + {
1.1345 + (void)CleanAddress(); //called for side-effect to make sure bitmap reference is current. Should be low overhead.
1.1346 + const_cast<CFbsBitmap*>(this)->iUseCount++;
1.1347 + }
1.1348 +
1.1349 + FBS_OST_VERBOSE(OstTraceExt2(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_BEGINDATAACCESS_EXIT, "< this=0x%08x; iUseCount=%d;", (TUint)this, const_cast<CFbsBitmap*>(this)->iUseCount);)
1.1350 + }
1.1351 +
1.1352 +/** Marks the end of direct access to the bitmap data.
1.1353 +Use this function after ending direct access to the bitmap data.
1.1354 +Calls to EndDataAccess() must correspond to prior calls to BeginDataAccess().
1.1355 +See BeginDataAccess() for more details.
1.1356 +
1.1357 +@param aReadOnly Whether or not the bitmap data has only been read since
1.1358 + the corresponding call to BeginDataAccess().
1.1359 +
1.1360 +@publishedAll
1.1361 +@released
1.1362 +@param aReadOnly True if the bitmap data had only been read. False if the data has been modified.
1.1363 +@see CFbsBitmap::BeginDataAccess()
1.1364 +*/
1.1365 +EXPORT_C void CFbsBitmap::EndDataAccess(TBool aReadOnly) const
1.1366 + {
1.1367 + FBS_OST_VERBOSE(OstTraceExt2(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_ENDDATAACCESS_ENTRY, "> this=0x%08x; aReadOnly=%d;", (TUint)this, (TUint)aReadOnly);)
1.1368 + FBS_OST_IF(!iHandle, OstTrace1(TRACE_ERROR, CFBSBITMAP_ENDDATAACCESS_ERROR, "! this=0x%08x; !iHandle", (TUint)this););
1.1369 + if (iHandle)
1.1370 + {
1.1371 + const_cast<CFbsBitmap*>(this)->iUseCount--;
1.1372 + if (!aReadOnly && !(iFlags & EIsReadOnlyBitmapMask))
1.1373 + {
1.1374 + User::LockedInc(iAddressPointer->Extra()->iTouchCount);
1.1375 + }
1.1376 + }
1.1377 + FBS_OST_VERBOSE(OstTraceExt2(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_ENDDATAACCESS_EXIT, "< this=0x%08x; iUseCount=%d;", (TUint)this, const_cast<CFbsBitmap*>(this)->iUseCount);)
1.1378 + }
1.1379 +
1.1380 +/** Locks the global bitmap heap.
1.1381 +This function is deprecated, since it is no longer necessary to lock the global
1.1382 +bitmap heap to prevent the pixel data from being moved in memory asynchronously,
1.1383 +as the value returned by DataAddress() can now only change as a result of bitmap
1.1384 +operations explicitly requested by clients of the Font and Bitmap Server.
1.1385 +Calls to LockHeap() should be replaced by calls to BeginDataAccess().
1.1386 +
1.1387 +Calls to LockHeap() must be coupled with subsequent calls to CFbsBitmap::UnlockHeap().
1.1388 +Code called between a LockHeap() - UnlockHeap() pair must not include any other calls to
1.1389 +CFbsBitmap methods, which internally may call CFbsBitmap::LockHeap(). Also, code must
1.1390 +not leave between a LockHeap() - UnlockHeap() pair.
1.1391 +@note IMPORTANT: CFbsBitmap::LockHeap() cannot be used as a means of synchronization between
1.1392 +threads concurrently accessing bitmap data.
1.1393 +
1.1394 +@publishedAll
1.1395 +@deprecated
1.1396 +@see CFbsBitmap::UnlockHeap()
1.1397 +@see CFbsBitmap::BeginDataAccess()
1.1398 +*/
1.1399 +EXPORT_C void CFbsBitmap::LockHeap(TBool /*aAlways*/) const
1.1400 + {
1.1401 + FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_LOCKHEAP_ENTRY, "> this=0x%08x;", (TUint)this);)
1.1402 + BeginDataAccess();
1.1403 +#ifdef SYMBIAN_DEBUG_FBS_LOCKHEAP
1.1404 + //These debug checks now refer to the cleaned data address
1.1405 + FBS_OST_IF(!iHandle, OstTrace1(TRACE_ERROR, CFBSBITMAP_LOCKHEAP_ERROR, "! this=0x%08x; !iHandle", (TUint)this););
1.1406 + if (iHandle && !(iFlags & EIsRomBitmap)) // can't do anything with ROM bitmaps
1.1407 + {
1.1408 + TThreadId threadId = RThread().Id();
1.1409 + iFbs->iHelper->iDebugMutex.Wait();
1.1410 + if (iAddressPointer->Extra()->iLockCount++ == 0)
1.1411 + {
1.1412 + __ASSERT_ALWAYS(iAddressPointer->Extra()->iThreadId == TThreadId(KNullThreadId), Panic(EFbsPanicBadHeapLock));
1.1413 + iAddressPointer->Extra()->iThreadId = threadId;
1.1414 + }
1.1415 + else
1.1416 + __ASSERT_ALWAYS(iAddressPointer->Extra()->iThreadId == threadId, Panic(EFbsPanicBadHeapLock));
1.1417 + iFbs->iHelper->iDebugMutex.Signal();
1.1418 + }
1.1419 +#endif
1.1420 + FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_LOCKHEAP_EXIT, "< this=0x%08x;", (TUint)this);)
1.1421 + }
1.1422 +
1.1423 +/** Unlocks the global heap.
1.1424 +This function is deprecated. See LockHeap() for more details.
1.1425 +Calls to UnlockHeap() should be replaced by calls to EndDataAccess().
1.1426 +Calls to UnlockHeap() must correspond to prior calls to LockHeap() or LockHeapLC().
1.1427 +
1.1428 +@publishedAll
1.1429 +@deprecated
1.1430 +@see CFbsBitmap::LockHeap()
1.1431 +@see CFbsBitmap::EndDataAccess()
1.1432 +*/
1.1433 +EXPORT_C void CFbsBitmap::UnlockHeap(TBool /*aAlways*/) const
1.1434 + {
1.1435 + FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_UNLOCKHEAP_ENTRY, "> this=0x%08x;", (TUint)this);)
1.1436 + FBS_OST_IF(!iHandle, OstTrace1(TRACE_ERROR, CFBSBITMAP_UNLOCKHEAP_ERROR, "! this=0x%08x; !iHandle", (TUint)this););
1.1437 + if (iHandle)
1.1438 + {
1.1439 +#ifdef SYMBIAN_DEBUG_FBS_LOCKHEAP
1.1440 + if (!(iFlags & EIsRomBitmap)) // can't do anything with ROM bitmaps
1.1441 + {
1.1442 + TThreadId threadId = RThread().Id();
1.1443 + iFbs->iHelper->iDebugMutex.Wait();
1.1444 + __ASSERT_ALWAYS(iAddressPointer->Extra()->iLockCount > 0, Panic(EFbsPanicBadHeapLock));
1.1445 + __ASSERT_ALWAYS(iAddressPointer->Extra()->iThreadId == threadId, Panic(EFbsPanicBadHeapLock));
1.1446 + if (--iAddressPointer->Extra()->iLockCount == 0)
1.1447 + iAddressPointer->Extra()->iThreadId = TThreadId(KNullThreadId);
1.1448 + iFbs->iHelper->iDebugMutex.Signal();
1.1449 + }
1.1450 +#endif
1.1451 + EndDataAccess();
1.1452 + }
1.1453 + FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_UNLOCKHEAP_EXIT, "< this=0x%08x;", (TUint)this);)
1.1454 + }
1.1455 +
1.1456 +/** Locks the global bitmap heap, leaving on the clean-up stack a pointer
1.1457 +to a TCleanupItem that unlocks the heap on deletion.
1.1458 +Use this function instead of LockHeap() if code may leave between the
1.1459 +LockHeap() - UnlockHeap() pair. Calls to LockHeapLC() must be coupled with
1.1460 +subsequent calls to CFbsBitmap::UnlockHeap() or CleanupStack::PopAndDestroy().
1.1461 +This function is deprecated. See CFbsBitmap::LockHeap() for more details.
1.1462 +
1.1463 +@publishedAll
1.1464 +@deprecated
1.1465 +@see CFbsBitmap::LockHeap()
1.1466 +*/
1.1467 +EXPORT_C void CFbsBitmap::LockHeapLC(TBool /*aAlways*/) const
1.1468 + {
1.1469 + FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_LOCKHEAPLC_ENTRY, "> this=0x%08x;", (TUint)this);)
1.1470 + LockHeap();
1.1471 + TCleanupItem cleanitem(CFbsBitmap::UnlockHeap, (TAny*)this);
1.1472 + CleanupStack::PushL(cleanitem);
1.1473 + FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_LOCKHEAPLC_EXIT, "< this=0x%08x;", (TUint)this);)
1.1474 + }
1.1475 +
1.1476 +EXPORT_C void CFbsBitmap::UnlockHeap(TAny* aFbsBitmap)
1.1477 + {
1.1478 + FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_UNLOCKHEAP2_ENTRY, "> bitmap=0x%08x;", (TUint)aFbsBitmap);)
1.1479 + ((CFbsBitmap*)aFbsBitmap)->UnlockHeap();
1.1480 + FBS_OST(OstTrace0(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_UNLOCKHEAP2_EXIT, "<");)
1.1481 + }
1.1482 +
1.1483 +/** Tests whether the bitmap is volatile.
1.1484 +A bitmap becomes volatile if CFbsBitmap::DataAdress() is called without
1.1485 +CFbsBitmap::BeginDataAccess() having been called before and it can become non-volatile
1.1486 +again if a resizing or compression is performed.
1.1487 +
1.1488 +@internalTechnology
1.1489 +@prototype
1.1490 +*/
1.1491 +EXPORT_C TBool CFbsBitmap::IsVolatile() const
1.1492 + {
1.1493 + if (!iHandle)
1.1494 + return EFalse;
1.1495 + return CleanAddress()->iSettings.IsVolatileBitmap();
1.1496 + }
1.1497 +
1.1498 +/** Tests how many times the bitmap has been touched.
1.1499 +A bitmap is touched whenever CFbsBitmap::EndDataAccess() is called with the parameter
1.1500 +aReadOnly set to EFalse and also whenever a resizing or compression is performed.
1.1501 +
1.1502 +@internalTechnology
1.1503 +@prototype
1.1504 +@return The number of times the bitmap has been touched.
1.1505 +*/
1.1506 +EXPORT_C TInt CFbsBitmap::TouchCount() const
1.1507 + {
1.1508 + if (!iHandle || (iFlags & EIsReadOnlyBitmapMask))
1.1509 + return 0; // A read-only bitmap can never be touched.
1.1510 + return CleanAddress()->Extra()->iTouchCount;
1.1511 + }
1.1512 +
1.1513 +/** Returns the serial number of the bitmap
1.1514 +The serial number is unique to this bitmap.
1.1515 +The serial number is a signed 64-bit integer, with only the positive values being assigned.
1.1516 +As ROM bitmaps do not have serial numbers, the serial number will use the negative range
1.1517 +of values so that ROM bitmap's serial number cannot be the same as a RAM bitmap's.
1.1518 +ROM bitmap's address pointers are unique to the ROM bitmap, so the serial number will just
1.1519 +be negative value of the address pointer.
1.1520 +
1.1521 +@internalTechnology
1.1522 +@prototype
1.1523 +@return The unique serial number for the bitmap
1.1524 +*/
1.1525 +EXPORT_C TInt64 CFbsBitmap::SerialNumber() const
1.1526 + {
1.1527 + if (!iHandle)
1.1528 + return 0;
1.1529 + if (iFlags & EIsRomBitmap)
1.1530 + return -TInt64(reinterpret_cast<TUint32>(iAddressPointer));
1.1531 + return CleanAddress()->Extra()->iSerialNumber;
1.1532 + }
1.1533 +
1.1534 +/** Tests whether the bitmap is large.
1.1535 +@return ETrue if the bitmap is large, EFalse if not.
1.1536 +@publishedAll
1.1537 +@released
1.1538 +*/
1.1539 +EXPORT_C TBool CFbsBitmap::IsLargeBitmap() const
1.1540 + {
1.1541 + CBitwiseBitmap* bitmap = CleanAddress();
1.1542 + if (!bitmap)
1.1543 + {
1.1544 + return EFalse;
1.1545 + }
1.1546 + return bitmap->IsLargeBitmap();
1.1547 + }
1.1548 +
1.1549 +/** Returns the handle for the hardware bitmap which this CFbsBitmap is using.
1.1550 +@return The handle to the hardware bitmap. The handle is NULL if it is not
1.1551 +a hardware bitmap.
1.1552 +@publishedAll
1.1553 +@released
1.1554 +*/
1.1555 +EXPORT_C TInt CFbsBitmap::HardwareBitmapHandle() const
1.1556 + {
1.1557 + CBitwiseBitmap* bitmap = CleanAddress();
1.1558 + if (!bitmap)
1.1559 + {
1.1560 + return 0;
1.1561 + }
1.1562 + return bitmap->HardwareBitmapHandle();
1.1563 + }
1.1564 +
1.1565 +/** Gets the attributes of the bitmap's palette.
1.1566 +This is not currently supported.
1.1567 +@param aModifiable On return, whether or not the palette is modifiable.
1.1568 +@param aNumEntries On return, the number of entries in the palette.
1.1569 +@publishedAll
1.1570 +@released
1.1571 +*/
1.1572 +EXPORT_C void CFbsBitmap::PaletteAttributes(TBool& aModifiable,TInt& aNumEntries) const
1.1573 + {
1.1574 + aModifiable=EFalse;
1.1575 + aNumEntries=0;
1.1576 + }
1.1577 +
1.1578 +/** Sets the bitmap's palette.
1.1579 +This is not currently supported.
1.1580 +@param aPalette Not used.
1.1581 +@publishedAll
1.1582 +@released
1.1583 +*/
1.1584 +EXPORT_C void CFbsBitmap::SetPalette(CPalette* /*aPalette*/)
1.1585 + {
1.1586 + }
1.1587 +
1.1588 +/** Gets the bitmap's palette.
1.1589 +This is not currently supported.
1.1590 +@param aPalette Not used.
1.1591 +@return KErrNotSupported.
1.1592 +@publishedAll
1.1593 +@released
1.1594 +*/
1.1595 +EXPORT_C TInt CFbsBitmap::GetPalette(CPalette*& /*aPalette*/) const
1.1596 + {
1.1597 + return(KErrNotSupported);
1.1598 + }
1.1599 +
1.1600 +/**
1.1601 +@internalComponent
1.1602 +This method loads a bitmap from an opened file handle.
1.1603 +
1.1604 +@param aFile mbm or rsc file handle (rsc file format: header + rsc
1.1605 + data section + mbm file section).
1.1606 +@param aId Bitmap ID - should be less than mbm file bitmaps count.
1.1607 +@param aShareIfLoaded Specifies whether or not the loaded bitmap will be
1.1608 + made available for sharing between FBSERV clients.
1.1609 +@param aFileOffset mbm file section offset into rsc file.
1.1610 +@return KErrNone if successful, otherwise another
1.1611 + of the system-wide error codes.
1.1612 +*/
1.1613 +TInt CFbsBitmap::DoLoad(RFile& aFile,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset)
1.1614 + {
1.1615 + TInt ret=KErrNone;
1.1616 + TPckgBuf<TBmpHandles> handlebuf;
1.1617 + TPckgBuf<TLoadBitmapArg> loadBitmapArg;
1.1618 + loadBitmapArg().iBitmapId = aId;
1.1619 + loadBitmapArg().iShareIfLoaded = TInt(aShareIfLoaded);
1.1620 + loadBitmapArg().iFileOffset = aFileOffset;
1.1621 + //Getting the RFs Handle(2) and RFile handle(3) into a TIpcArgs into 2nd and 3rd argument
1.1622 + TIpcArgs fileargs;
1.1623 + ret=aFile.TransferToServer(fileargs,2,3);
1.1624 + if (ret!=KErrNone)
1.1625 + return ret;
1.1626 + fileargs.Set(0,&handlebuf);
1.1627 + fileargs.Set(1,&loadBitmapArg);
1.1628 + ret=iFbs->SendCommand(EFbsMessBitmapLoad,fileargs);
1.1629 + if(ret!=KErrNone) return(ret);
1.1630 + iHandle=handlebuf().iHandle;
1.1631 + iServerHandle=handlebuf().iServerHandle;
1.1632 + iAddressPointer=(CBitwiseBitmap*)(iFbs->HeapBase()+handlebuf().iAddressOffset);
1.1633 + ret = iFbs->iHelper->AddBitmap(*this);
1.1634 + if (ret != KErrNone)
1.1635 + return ret;
1.1636 + return iFbs->AllocScanLineBuffer(iAddressPointer->iByteWidth+4);
1.1637 + }
1.1638 +
1.1639 +/**
1.1640 +@internalComponent
1.1641 +This method loads a bitmap from the mbm or rsc file specified by the filename.
1.1642 +
1.1643 +@param aFileName mbm or rsc file name (rsc file format: header + rsc
1.1644 + data section + mbm file section).
1.1645 +@param aId Bitmap ID - should be less than mbm file bitmaps count.
1.1646 +@param aShareIfLoaded Specifies whether or not the loaded bitmap will be
1.1647 + made available for sharing between FBSERV clients.
1.1648 +@param aFileOffset mbm file section offset into rsc file.
1.1649 +@return KErrNone if successful, otherwise another
1.1650 + of the system-wide error codes.
1.1651 +*/
1.1652 +TInt CFbsBitmap::DoLoad(const TDesC& aFileName,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset)
1.1653 + {
1.1654 + TInt ret=KErrNone;
1.1655 + TPckgBuf<TBmpHandles> handlebuf;
1.1656 + TPckgBuf<TLoadBitmapArg> loadBitmapArg;
1.1657 + loadBitmapArg().iBitmapId = aId;
1.1658 + loadBitmapArg().iShareIfLoaded = TInt(aShareIfLoaded);
1.1659 + loadBitmapArg().iFileOffset = aFileOffset;
1.1660 + TIpcArgs fileargs;
1.1661 + fileargs.Set(0,&handlebuf);
1.1662 + fileargs.Set(1,&loadBitmapArg);
1.1663 + fileargs.Set(2,&aFileName);
1.1664 + ret=iFbs->SendCommand(EFbsMessBitmapLoadFast,fileargs);
1.1665 + if(ret!=KErrNone) return(ret);
1.1666 + iHandle=handlebuf().iHandle;
1.1667 + iServerHandle=handlebuf().iServerHandle;
1.1668 + iAddressPointer=(CBitwiseBitmap*)(iFbs->HeapBase()+handlebuf().iAddressOffset);
1.1669 + ret = iFbs->iHelper->AddBitmap(*this);
1.1670 + if (ret != KErrNone)
1.1671 + return ret;
1.1672 + return iFbs->AllocScanLineBuffer(iAddressPointer->iByteWidth+4);
1.1673 + }
1.1674 +
1.1675 +/**
1.1676 +@internalComponent
1.1677 +This method handles very special case when the rsc file is in RAM, but it
1.1678 +contains ROM mbm file. ROM mbm file format is different than RAM mbm file
1.1679 +format and ROM mbm file cannot be loaded into RAM using standard techniques
1.1680 +(used by CFbsBitmap::DoLoad()). We have to check it is really a ROM mbm file.
1.1681 +If it is - we have to allocate the right amount of RAM, read and copy
1.1682 +requested ROM bitmap to the allocated RAM.
1.1683 +
1.1684 +@leave KErrNotSupported if this is a RAM rsc file with ROM mbm file section,
1.1685 + or any of the RFile related error codes.
1.1686 +@param aFileName rsc file name (rsc file format: header + rsc data section +
1.1687 + mbm file section).
1.1688 +@param aId Bitmap ID - should be less than mbm file bitmaps count.
1.1689 +@param aFileOffset mbm file section offset into rsc file.
1.1690 +@return EFalse - this is not a ROM mbm file. ETrue - this is a ROM mbm file
1.1691 + and requested by aId bitmmap is loaded.
1.1692 +*/
1.1693 +TBool CFbsBitmap::LoadShiftedRomBmpL(const TDesC& aFileName, TInt32 aId, TUint aFileOffset)
1.1694 + {
1.1695 + RFile mbm_file;
1.1696 + ::CleanupClosePushL(mbm_file);
1.1697 + User::LeaveIfError(mbm_file.Open(iFbs->FileServer(), aFileName, EFileRead | EFileShareReadersOnly));
1.1698 + TInt pos = static_cast <TInt> (aFileOffset);
1.1699 + User::LeaveIfError(mbm_file.Seek(ESeekStart, pos));//move to the beginning of the mbm file section
1.1700 + TBuf8<sizeof(CBitwiseBitmap)> buf;
1.1701 + //Check if it is a ROM mbm file
1.1702 + User::LeaveIfError(mbm_file.Read(buf, sizeof(KMultiBitmapRomImageUid.iUid)));//Bitmap file UID - ROM or RAM
1.1703 + TInt32 mbm_uid = *(reinterpret_cast <const TInt32*> (buf.Ptr()));
1.1704 + TBool loaded = EFalse;
1.1705 + if(mbm_uid == KMultiBitmapRomImageUid.iUid)
1.1706 + {
1.1707 + if(!KRomMBMInRamRSC)
1.1708 + {
1.1709 + User::Leave(KErrNotSupported);
1.1710 + }
1.1711 + else
1.1712 + {
1.1713 + User::LeaveIfError(mbm_file.Read(buf, sizeof(TInt32)));//Number of bitmaps
1.1714 + TInt32 bmp_cnt = *(reinterpret_cast <const TInt32*> (buf.Ptr()));
1.1715 + if(aId >= bmp_cnt)
1.1716 + {
1.1717 + User::Leave(KErrNotFound);
1.1718 + }
1.1719 + for(TInt i=0;i<aId;i++) //Read bitmap UIDs located before aId.
1.1720 + {
1.1721 + User::LeaveIfError(mbm_file.Read(buf, sizeof(aId)));
1.1722 + }
1.1723 + User::LeaveIfError(mbm_file.Read(buf, sizeof(TInt32)));//Read the offset of aId bitmap.
1.1724 + TInt bmp_offset = *(reinterpret_cast <const TInt32*> (buf.Ptr())) + TInt(aFileOffset);
1.1725 + pos = static_cast <TInt> (bmp_offset);
1.1726 + User::LeaveIfError(mbm_file.Seek(ESeekStart, pos));//move the file pointer to the bitmap
1.1727 + User::LeaveIfError(mbm_file.Read(buf, sizeof(CBitwiseBitmap)));//Read CBitwiseBitmap data (without the bitmap data)
1.1728 + const CBitwiseBitmap* bmp = reinterpret_cast <const CBitwiseBitmap*> (buf.Ptr());
1.1729 + //Calculate bitmap data size, alocate enough memory for the bitmap, copy CBitwiseBitmap
1.1730 + //members first, read the bitmap data from the file, copy the data to the allocated memory,
1.1731 + //initialize iRomPointer.
1.1732 + //If sizeof(CBitwiseBitmap) != real size of CBitwiseBitmap then we could have problems,
1.1733 + //because bitmap data won't be copied at the right position.
1.1734 + TInt size = bmp->iHeader.iBitmapSize - sizeof(SEpocBitmapHeader) + sizeof(CBitwiseBitmap);
1.1735 + TUint8* bmp_mem = new (ELeave) TUint8[size];
1.1736 + //There is no need bmp_mem to be aligned, because it is a pointer to a RAM block of memory.
1.1737 + TCleanupItem cleanitem(FreeMem, bmp_mem);
1.1738 + CleanupStack::PushL(cleanitem);
1.1739 + Mem::Copy(bmp_mem, bmp, sizeof(CBitwiseBitmap));
1.1740 + TPtr8 pbmp(bmp_mem + sizeof(CBitwiseBitmap), size - sizeof(CBitwiseBitmap));
1.1741 + User::LeaveIfError(mbm_file.Read(pbmp, size - sizeof(CBitwiseBitmap)));//read the bitmap data. We've already read the CBitwiseBitmap data.
1.1742 + CleanupStack::Pop(bmp_mem);
1.1743 + iAddressPointer = reinterpret_cast<CBitwiseBitmap*>(bmp_mem);
1.1744 + iFlags = EIsRomBitmap;
1.1745 + iHandle = 1;
1.1746 + loaded = ETrue;
1.1747 + }//end of - if(!KRomMBMInRamRSC) - "else" part
1.1748 + }//end of - if(mbm_uid == KMultiBitmapRomImageUid.iUid)
1.1749 + CleanupStack::PopAndDestroy();//mbm_file
1.1750 + return loaded;
1.1751 + }
1.1752 +
1.1753 +/**
1.1754 +Swaps the bitmap's width and height.
1.1755 +For example, if the bitmap's size is (40, 20), the new size will be (20, 40).
1.1756 +Bitmap content is not preserved.
1.1757 +@publishedAll
1.1758 +@released
1.1759 +@return KErrNone if the call was successful, KErrGeneral if the bitmap handle is
1.1760 +invalid, KErrAccessDenied if the bitmap is in ROM, KErrNotSupported if the bitmap
1.1761 +is a hardware bitmap or an extended bitmap.
1.1762 +*/
1.1763 +EXPORT_C TInt CFbsBitmap::SwapWidthAndHeight()
1.1764 + {
1.1765 + if(!iHandle)
1.1766 + {
1.1767 + return KErrGeneral;
1.1768 + }
1.1769 + TUint32* data;
1.1770 + CBitwiseBitmap* bmp = BeginDataAccessAndGetCleanAddress(data);
1.1771 +
1.1772 + // Check the new bitmap size here then decide whether to swap the bitmap on the
1.1773 + // client side or send it to be done on the server and reallocate memory for it.
1.1774 + TInt newWidthInBytes = CBitwiseBitmap::ByteWidth(bmp->iHeader.iSizeInPixels.iHeight, bmp->iSettings.CurrentDisplayMode());
1.1775 + TInt64 hugeDataSize = TInt64(bmp->iHeader.iSizeInPixels.iWidth) * TInt64(newWidthInBytes);
1.1776 +
1.1777 + TInt err = KErrNone;
1.1778 + // If the size of the new swapped bitmap is less than or equal its original size before the swap,
1.1779 + // then we do not need to reallocate memory. The swapping is straight forward.
1.1780 + if( I64HIGH(hugeDataSize) == 0 && I64LOW(hugeDataSize) <= TUint(bmp->iHeader.iBitmapSize - bmp->iHeader.iStructSize) )
1.1781 + {
1.1782 + err = bmp->SwapWidthAndHeight(data);
1.1783 + // Even though used DataAddress() as read-only, need to increment touch count, so indicate that data has been written
1.1784 + EndDataAccess(EFalse);
1.1785 + }
1.1786 + // Otherwise we need to reallocate memory. We do this by using the already exisitng
1.1787 + // Resize() function as a work around- Code Reusability!!
1.1788 + else
1.1789 + {
1.1790 + EndDataAccess(ETrue); // Used DataAddress() to read only.
1.1791 + // Resize will increase touch counter
1.1792 + err = Resize(TSize(bmp->iHeader.iSizeInPixels.iHeight, bmp->iHeader.iSizeInPixels.iWidth));
1.1793 + }
1.1794 + return err;
1.1795 + }
1.1796 +
1.1797 +/** Gets a pointer to the decompression buffer owned by this thread's FBServ session.
1.1798 +@param aSize The size in bytes of the scan lines to decompress.
1.1799 +@return A pointer to the decompression buffer or NULL if there is no FBServ session.
1.1800 +@internalTechnology
1.1801 +@released
1.1802 +*/
1.1803 +EXPORT_C HBufC8* CFbsBitmap::GetDecompressionBuffer(TInt aSize)
1.1804 + {
1.1805 + RFbsSession* ses=RFbsSession::GetSession();
1.1806 + return ses? ses->GetDecompressionBuffer(aSize) : NULL;
1.1807 + }
1.1808 +
1.1809 +/** Gets a pointer to the rasterizer for extended bitmaps if present.
1.1810 +@return A pointer to the rasterizer owned by this thread's FBServ session.
1.1811 +@return NULL if the rasterizer is not present.
1.1812 +@internalTechnology
1.1813 +@prototype
1.1814 +*/
1.1815 +EXPORT_C CFbsRasterizer* CFbsBitmap::Rasterizer()
1.1816 + {
1.1817 + RFbsSession* session = RFbsSession::GetSession();
1.1818 + return session ? session->iHelper->Rasterizer() : NULL;
1.1819 + }
1.1820 +
1.1821 +/** Loads a specific bitmap from an opened multi-bitmap file handle.
1.1822 +The bitmap may be shared by other font and bitmap server clients.
1.1823 +@param aFile The handle of the multi-bitmap (.mbm) file.
1.1824 +@param aId The bitmap identifier.
1.1825 +@param aShareIfLoaded Specifies whether or not the loaded bitmap will be made
1.1826 +available for sharing between font and bitmap server clients.
1.1827 +@return KErrNone if successful, otherwise another of the system error
1.1828 +codes.
1.1829 +@publishedAll
1.1830 +@released
1.1831 +*/
1.1832 +EXPORT_C TInt CFbsBitmap::Load(RFile& aFile,TInt32 aId/*=0*/,TBool aShareIfLoaded/*=ETrue*/)
1.1833 + {
1.1834 + FBS_OST(TFullName fileName;)
1.1835 + FBS_OST(aFile.FullName(fileName);)
1.1836 + 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);)
1.1837 + TInt ret = Load(aFile,aId,aShareIfLoaded,0);
1.1838 + FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOAD3_EXIT, "< this=0x%08x, ret=%d", (TUint)this, ret);)
1.1839 + return ret;
1.1840 + }
1.1841 +
1.1842 +/** Loads a specific bitmap from an opened multi-bitmap file handle.
1.1843 +The bitmap may be shared by other font and bitmap server clients.
1.1844 +@param aFile The handle of the multi-bitmap (.mbm) file.
1.1845 +@param aId The bitmap identifier.
1.1846 +@param aShareIfLoaded Specifies whether or not the loaded bitmap will be made
1.1847 +available for sharing between FBSERV clients.
1.1848 +@param aFileOffset Bitmap file section offset within the file.
1.1849 +@return KErrNone if successful, otherwise another of the system error codes.
1.1850 +@publishedAll
1.1851 +@released
1.1852 +*/
1.1853 +EXPORT_C TInt CFbsBitmap::Load(RFile& aFile,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset)
1.1854 + {
1.1855 + TInt err = KErrNone;
1.1856 + FBS_OST(TFullName fileName;)
1.1857 + FBS_OST(aFile.FullName(fileName);)
1.1858 + 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);)
1.1859 + if (!iFbs)
1.1860 + {
1.1861 + FBS_OST(OstTrace1( TRACE_ERROR, CFBSBITMAP_LOAD4_ERROR, "! this=0x%08x; !iFbs", (TUint)this);)
1.1862 + err = KErrCouldNotConnect;
1.1863 + }
1.1864 + else
1.1865 + {
1.1866 + Reset();
1.1867 + TUint32* rompointer;
1.1868 + IsFileInRom(aFile,rompointer);
1.1869 + TBool romPointerValid;
1.1870 + err = DoLoadFromRom(rompointer, aId, aFileOffset, romPointerValid);
1.1871 + if (!romPointerValid)
1.1872 + {
1.1873 + err = DoLoad(aFile,aId,aShareIfLoaded,aFileOffset);
1.1874 + FBS_OST_IF(err!=KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_LOAD4_ERROR2, "! this=0x%08x; DoLoad() returned %d", (TUint)this, err);)
1.1875 + }
1.1876 + }
1.1877 + FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOAD4_EXIT, "< this=0x%08x; err=%d", (TUint)this, err);)
1.1878 + return err;
1.1879 + }
1.1880 +
1.1881 +/** Loads and compresses a specific bitmap from an opened multi-bitmap file handle.
1.1882 +The bitmap may be shared by other font and bitmap server clients.
1.1883 +If the bitmap is loaded from ROM then compression is not allowed.
1.1884 +@param aFile The handle of the multi-bitmap (.mbm) file.
1.1885 +@param aId The bitmap identifier.
1.1886 +@param aShareIfLoaded Specifies whether or not the loaded bitmap will be
1.1887 +made available for sharing between FBSERV clients.
1.1888 +@return KErrNone if successful, otherwise another of the system-wide error
1.1889 +codes.
1.1890 +@publishedAll
1.1891 +@released
1.1892 +*/
1.1893 +EXPORT_C TInt CFbsBitmap::LoadAndCompress(RFile& aFile,TInt32 aId/*=0*/,TBool aShareIfLoaded/*=ETrue*/)
1.1894 + {
1.1895 + FBS_OST(TFullName fileName;)
1.1896 + FBS_OST(aFile.FullName(fileName);)
1.1897 + 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);)
1.1898 + TInt ret = LoadAndCompress(aFile,aId,aShareIfLoaded,0);
1.1899 + FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOADANDCOMPRESS3_EXIT, "< this=0x%08x; ret=%d", (TUint)this, ret);)
1.1900 + return ret;
1.1901 + }
1.1902 +
1.1903 +/** Loads and compresses a specific bitmap from an opened multi-bitmap file handle.
1.1904 +The bitmap may be shared by other font and bitmap server clients. If the
1.1905 +bitmap is loaded from ROM then compression is not allowed.
1.1906 +@param aFile The handle of the multi-bitmap (.mbm) file.
1.1907 +@param aId The bitmap identifier.
1.1908 +@param aShareIfLoaded Specifies whether or not the loaded bitmap will be made
1.1909 +available for sharing between FBSERV clients.
1.1910 +@param aFileOffset Bitmap file section offset within the file.
1.1911 +@return KErrNone if successful, otherwise another of the system-wide error
1.1912 +codes.
1.1913 +@publishedAll
1.1914 +@released
1.1915 +*/
1.1916 +EXPORT_C TInt CFbsBitmap::LoadAndCompress(RFile& aFile,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset)
1.1917 + {
1.1918 + FBS_OST(TFullName fileName;)
1.1919 + FBS_OST(aFile.FullName(fileName);)
1.1920 + 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);)
1.1921 + TInt err = Load(aFile,aId,aShareIfLoaded,aFileOffset);
1.1922 + if (err == KErrNone)
1.1923 + {
1.1924 + if (!(iFlags & EIsRomBitmap))
1.1925 + {
1.1926 + err = Compress();
1.1927 + FBS_OST_IF(err!=KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_LOADANDCOMPRESS4_ERROR, "! this=0x%08x; Compress() returned %d", (TUint)this, err);)
1.1928 + }
1.1929 + else
1.1930 + {
1.1931 + err = KErrAccessDenied;
1.1932 + FBS_OST(OstTraceExt2( TRACE_ERROR, CFBSBITMAP_LOADANDCOMPRESS4_ERROR2, "! this=0x%08x; Cannot compress bitmap in ROM; iFlags=0x%08x", (TUint)this, (TUint)iFlags);)
1.1933 + }
1.1934 + }
1.1935 + FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOADANDCOMPRESS4_EXIT, "< this=0x%08x; err=%d", (TUint)this, err);)
1.1936 + return err;
1.1937 + }
1.1938 +
1.1939 +/** Gets all the bitmap handles for all the bitmaps stored in the Font Bitmap Server. There is a limit of
1.1940 +the number of bitmaps that can be retrieved defined by KMaxBitmapHandleBufferSize. If this limit has been
1.1941 +reached then KErrOverflow will be returned.
1.1942 +@param aBitmapIdArray returns an array of all the bitmap handles
1.1943 +@return KErrNone if successful, KErrOverflow if the bitmapBuffer is not large enough to store
1.1944 +all the bitmap handles, otherwise another of the system-wide error codes.
1.1945 +@capability ReadDeviceData
1.1946 +@internalComponent
1.1947 +@released
1.1948 +*/
1.1949 +EXPORT_C TInt CFbsBitmap::GetAllBitmapHandles(RArray<TInt>& aBitmapIdArray) const
1.1950 + {
1.1951 + RBuf8 bitmapBuffer;
1.1952 + TInt ret = bitmapBuffer.Create(KMaxBitmapHandleBufferSize);
1.1953 + if (ret==KErrNone)
1.1954 + {
1.1955 + TIpcArgs args(&bitmapBuffer);
1.1956 + ret=iFbs->SendCommand(EFbsGetAllBitmapHandles, args);
1.1957 + if (ret==KErrNone)
1.1958 + {
1.1959 + // Convert data returned from server and place into the RArray (aBitmapIdArray)
1.1960 + aBitmapIdArray.Reset();
1.1961 + TInt* bitmapIdPtr = (TInt*)bitmapBuffer.Ptr();
1.1962 + const TInt numBitmapIds = bitmapBuffer.Size() / KNumBytesPerBitmapHandle; // Divide by number of bytes per bitmap handle to get total number of bitmap IDs
1.1963 + for (TInt count=0; count<numBitmapIds; ++count)
1.1964 + {
1.1965 + TInt bitmapId = *bitmapIdPtr++;
1.1966 + ret = aBitmapIdArray.Append(bitmapId);
1.1967 + if (ret!=KErrNone)
1.1968 + break;
1.1969 + }
1.1970 + }
1.1971 + }
1.1972 + bitmapBuffer.Close();
1.1973 + return ret;
1.1974 + }
1.1975 +
1.1976 +/**
1.1977 +@internalComponent
1.1978 +This method tries to load a bitmap if mbm or rsc file is in ROM.
1.1979 +
1.1980 +@param aRomPointer the address of the file in ROM
1.1981 +@param aId a Bitmap ID which should be less than mbm file bitmaps count.
1.1982 +@param aFileOffset mbm file section offset into rsc file.
1.1983 +@param aRomPointerValid on output it is set to ETrue if aRomPointer points to a valid ROM file or EFalse otherwise.
1.1984 +@return KErrNone if successful, otherwise another of the system-wide error codes.
1.1985 +*/
1.1986 +TInt CFbsBitmap::DoLoadFromRom(TUint32* aRomPointer, TInt32 aId, TUint aFileOffset, TBool& aRomPointerValid)
1.1987 + {
1.1988 + aRomPointerValid = ETrue;
1.1989 + if(aRomPointer)
1.1990 + {
1.1991 + TUint8* temp = reinterpret_cast <TUint8*> (aRomPointer);
1.1992 + __ASSERT_DEBUG(!(TUint(temp) & 0x00000003),Panic(EFbsBitmapAlignment));
1.1993 + temp += aFileOffset;
1.1994 + aRomPointer = reinterpret_cast <TUint32*> (temp);
1.1995 + if(TInt32(*aRomPointer)==KMultiBitmapRomImageUid.iUid)
1.1996 + {
1.1997 + TInt numbitmaps = (TInt)*(aRomPointer+1);
1.1998 + if(aId>=numbitmaps)
1.1999 + {
1.2000 + return(KErrEof);
1.2001 + }
1.2002 + TInt offset = *(aRomPointer+aId+2);
1.2003 + iAddressPointer = (CBitwiseBitmap*)(((TUint8*)aRomPointer) + offset);
1.2004 + iFlags = EIsRomBitmap;
1.2005 + iHandle = 1;
1.2006 + return iFbs->AllocScanLineBuffer(iAddressPointer->iByteWidth + 4);
1.2007 + }
1.2008 + }
1.2009 + aRomPointerValid = EFalse;
1.2010 + return KErrNone;
1.2011 + }
1.2012 +
1.2013 +
1.2014 +/**
1.2015 +Creates an extended bitmap. Extended bitmaps are used to store immutable
1.2016 +data in a platform-specific format. They cannot be used as targets of
1.2017 +graphics contexts, and modification of their data via DataAddress() or
1.2018 +TBitmapUtil is not supported and results in undefined behaviour up to
1.2019 +and including process termination.
1.2020 +
1.2021 +Initialisation of the raw data of the new bitmap is carried out by copying
1.2022 +the data pointed to by the parameter aData.
1.2023 +
1.2024 +Read-only access to the raw data of an extended bitmap is provided by
1.2025 +DataAddress() and DataSize() in conjunction with BeginDataAccess() and
1.2026 +EndDataAccess().
1.2027 +
1.2028 +Extended bitmaps have a conceptual size in pixels and a conceptual
1.2029 +display mode for compatibility purposes. The raw data can be independent
1.2030 +of these properties.
1.2031 +
1.2032 +@param aSizeInPixels The conceptual width and height of the new bitmap in pixels.
1.2033 +@param aDispMode The conceptual display mode of the new bitmap.
1.2034 +@param aType The UID identifying the data format of the new bitmap. Used by the
1.2035 + extended bitmap rasterizer to distinguish between different data types.
1.2036 +@param aData A pointer to the raw data to be stored in the new bitmap.
1.2037 +@param aDataSize The size in bytes of the raw data to be stored in the new bitmap.
1.2038 +@return KErrNone if successful; KErrArgument if the width or height specified in
1.2039 +aSizeInPixels is negative, aDispMode is an invalid display mode, aData is NULL,
1.2040 +aDataSize is negative or zero, or aDataType is a UID reserved for OS use; KErrTooBig
1.2041 +if the width or height specified in aSizeInPixels exceeds KMaxTInt/4, or aDataSize
1.2042 +exceeds KMaxTInt/2; otherwise another of the system-wide error codes.
1.2043 +@publishedPartner
1.2044 +@prototype
1.2045 +@see CFbsBitmap::DataAddress()
1.2046 +@see CFbsBitmap::DataSize()
1.2047 +@see CFbsBitmap::BeginDataAccess()
1.2048 +@see CFbsBitmap::EndDataAccess()
1.2049 +*/
1.2050 +EXPORT_C TInt CFbsBitmap::CreateExtendedBitmap(const TSize& aSizeInPixels, TDisplayMode aDispMode, TUid aType, const TAny* aData, TInt aDataSize)
1.2051 + {
1.2052 + TInt err;
1.2053 + 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);)
1.2054 + if (!aData || aDataSize == 0)
1.2055 + {
1.2056 + FBS_OST(OstTrace1( TRACE_ERROR, CFBSBITMAP_CREATEEXTENDEDBITMAP_ERROR, "! this=0x%08x; (!aData || aDataSize == 0)", (TUint)this);)
1.2057 + err = KErrArgument;
1.2058 + }
1.2059 + else
1.2060 + {
1.2061 + err = DoCreate(aSizeInPixels, aDispMode, aType, aDataSize);
1.2062 + if (err == KErrNone)
1.2063 + {
1.2064 + Mem::Copy(iFbs->iLargeBitmapChunk.Base() + iAddressPointer->iDataOffset, aData, aDataSize);
1.2065 + }
1.2066 + }
1.2067 + 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);)
1.2068 + return err;
1.2069 + }
1.2070 +
1.2071 +/**
1.2072 +Creates an extended bitmap. Extended bitmaps are used to store immutable
1.2073 +data in a platform-specific format. They cannot be used as targets of
1.2074 +graphics contexts, and modification of their data via DataAddress() or
1.2075 +TBitmapUtil is not supported and results in undefined behaviour up to
1.2076 +and including process termination.
1.2077 +
1.2078 +Initialisation of the raw data of the new bitmap is carried out by a
1.2079 +callback to the MFbsExtendedBitmapInitializer::InitExtendedBitmap()
1.2080 +function passed through the parameter aInitializer.
1.2081 +
1.2082 +Read-only access to the raw data of an extended bitmap is provided by
1.2083 +DataAddress() and DataSize() in conjunction with BeginDataAccess() and
1.2084 +EndDataAccess().
1.2085 +
1.2086 +Extended bitmaps have a conceptual size in pixels and a conceptual
1.2087 +display mode for compatibility purposes. The raw data can be independent
1.2088 +of these properties.
1.2089 +
1.2090 +@param aSizeInPixels The conceptual width and height of the new bitmap in pixels.
1.2091 +@param aDispMode The conceptual display mode of the new bitmap.
1.2092 +@param aType The UID identifying the data format of the new bitmap. Used by the
1.2093 + extended bitmap rasterizer to distinguish between different data types.
1.2094 +@param aDataSize The size in bytes of the raw data to be stored in the new bitmap.
1.2095 +@param aInitializer A reference to the initializer of the raw data to be stored in the new bitmap.
1.2096 +@return KErrNone if successful; KErrArgument if the width or height specified in
1.2097 +aSizeInPixels is negative, aDispMode is an invalid display mode, aData is NULL,
1.2098 +aDataSize is negative or zero, or aDataType is a UID reserved for OS use; KErrTooBig
1.2099 +if the width or height specified in aSizeInPixels exceeds KMaxTInt/4, or aDataSize
1.2100 +exceeds KMaxTInt/2; otherwise another of the system-wide error codes.
1.2101 +@publishedPartner
1.2102 +@prototype
1.2103 +@see CFbsBitmap::DataAddress()
1.2104 +@see CFbsBitmap::DataSize()
1.2105 +@see CFbsBitmap::BeginDataAccess()
1.2106 +@see CFbsBitmap::EndDataAccess()
1.2107 +@see MFbsExtendedBitmapInitializer
1.2108 +*/
1.2109 +EXPORT_C TInt CFbsBitmap::CreateExtendedBitmap(const TSize& aSizeInPixels, TDisplayMode aDispMode, TUid aType, TInt aDataSize, MFbsExtendedBitmapInitializer& aInitializer)
1.2110 + {
1.2111 + TInt err;
1.2112 + 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);)
1.2113 + if (aDataSize == 0)
1.2114 + {
1.2115 + FBS_OST(OstTrace1( TRACE_ERROR, CFBSBITMAP_CREATEEXTENDEDBITMAP2_ERROR, "! this=0x%08x; aDataSize == 0", (TUint)this);)
1.2116 + err = KErrArgument;
1.2117 + }
1.2118 + else
1.2119 + {
1.2120 + err = DoCreate(aSizeInPixels, aDispMode, aType, aDataSize);
1.2121 + if (err == KErrNone)
1.2122 + {
1.2123 + err = aInitializer.InitExtendedBitmap(iFbs->iLargeBitmapChunk.Base() + iAddressPointer->iDataOffset, aDataSize);
1.2124 + if (err != KErrNone)
1.2125 + {
1.2126 + Reset();
1.2127 + }
1.2128 + }
1.2129 + }
1.2130 + 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);)
1.2131 + return err;
1.2132 + }
1.2133 +
1.2134 +/**
1.2135 +Gets the UID identifying the data format of an extended bitmap.
1.2136 +@return The UID identifying the data format of the bitmap or
1.2137 + KNullUid if the bitmap is not an extended bitmap.
1.2138 +@publishedPartner
1.2139 +@prototype
1.2140 +*/
1.2141 +EXPORT_C TUid CFbsBitmap::ExtendedBitmapType() const
1.2142 + {
1.2143 + if (iHandle == 0)
1.2144 + {
1.2145 + return KNullUid;
1.2146 + }
1.2147 + TUid type = CleanAddress()->iUid;
1.2148 + if (type.iUid == KCBitwiseBitmapUid.iUid || type.iUid == KCBitwiseBitmapHardwareUid.iUid)
1.2149 + {
1.2150 + return KNullUid;
1.2151 + }
1.2152 + return type;
1.2153 + }
1.2154 +
1.2155 +/**
1.2156 +Gets the size in bytes of the bitmap data.
1.2157 +@return The size in bytes of the bitmap data.
1.2158 +@publishedPartner
1.2159 +@prototype
1.2160 +*/
1.2161 +EXPORT_C TInt CFbsBitmap::DataSize() const
1.2162 + {
1.2163 + if (iHandle == 0)
1.2164 + {
1.2165 + return 0;
1.2166 + }
1.2167 + CBitwiseBitmap* bmp = CleanAddress();
1.2168 + return bmp->iHeader.iBitmapSize - bmp->iHeader.iStructSize;
1.2169 + }
1.2170 +
1.2171 +/**
1.2172 +Gets a pointer to an extra buffer for general use owned by this thread's FBServ session.
1.2173 +@param aSize The size of the buffer in bytes
1.2174 +@return A pointer to the extra buffer if successful or NULL if there is no FBServ session
1.2175 +@internalTechnology
1.2176 +@released
1.2177 +*/
1.2178 +EXPORT_C HBufC8* CFbsBitmap::GetExtraBuffer(TInt aSize)
1.2179 + {
1.2180 + RFbsSession* ses=RFbsSession::GetSession();
1.2181 + return ses? ses->GetExtraBuffer(aSize) : NULL;
1.2182 + }