os/graphics/fbs/fontandbitmapserver/sfbs/FBSBMP.CPP
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 1995-2010 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include <s32file.h>
sl@0
    17
#include <bitmap.h>
sl@0
    18
#include <graphicsaccelerator.h>
sl@0
    19
#include <fbs.h>
sl@0
    20
#include <graphics/bitmapuid.h>
sl@0
    21
#include "fbsdefs.h"
sl@0
    22
#include "UTILS.H"
sl@0
    23
#include "fbshelper.h"
sl@0
    24
#include "fbsrasterizer.h"
sl@0
    25
#include "BitwiseBitmap.inl"
sl@0
    26
#include "FbsMessage.H"
sl@0
    27
#include "bitmapconst.h"
sl@0
    28
#include "OstTraceDefinitions.h"
sl@0
    29
#include "fbstrace.h"
sl@0
    30
#ifdef OST_TRACE_COMPILER_IN_USE
sl@0
    31
#include "FBSBMPTraces.h"
sl@0
    32
#endif
sl@0
    33
sl@0
    34
const TInt KMaxPixelSize = KMaxTInt / 4; // Maximum pixel size to avoid some overflow problems
sl@0
    35
const TInt KMaxBitmapHandleBufferSize = KNumBytesPerBitmapHandle * 2000; 	// Maximum size of buffer to store all bitmap handles.
sl@0
    36
sl@0
    37
GLREF_C void Panic(TFbsPanic aPanic);
sl@0
    38
sl@0
    39
//If we have to handle RAM located file with an embedded ROM mbm file section - 
sl@0
    40
//KRomMBMInRamRSC should be ETrue.
sl@0
    41
//If it is not allowed to do that - KRomMBMInRamRSC should be EFalse.
sl@0
    42
//The same constant is defined into TDefect test app. It should be changed too.
sl@0
    43
#pragma warning(disable : 4127)   //conditional expression is constant
sl@0
    44
LOCAL_D const TBool KRomMBMInRamRSC = EFalse;
sl@0
    45
sl@0
    46
//Cleanup function used by CFbsBitmap::LoadShiftedRomBmpL(...)
sl@0
    47
LOCAL_D void FreeMem(TAny* aMem)
sl@0
    48
	{
sl@0
    49
	delete[] static_cast<TUint8*>(aMem);
sl@0
    50
	}
sl@0
    51
sl@0
    52
// Fbs style bitmap client class for font bitmap server
sl@0
    53
/** @publishedAll */
sl@0
    54
EXPORT_C CFbsBitmap::CFbsBitmap():
sl@0
    55
	CBase(),
sl@0
    56
	iFbs(RFbsSession::GetSession()),
sl@0
    57
	iAddressPointer(NULL),
sl@0
    58
	iFlags(0),
sl@0
    59
	iUseCount(0),
sl@0
    60
	iHandle(0),
sl@0
    61
	iServerHandle(0)
sl@0
    62
	{
sl@0
    63
	}
sl@0
    64
	
sl@0
    65
/** Destructor. Calls Reset().
sl@0
    66
@see Reset()
sl@0
    67
@publishedAll 
sl@0
    68
@released
sl@0
    69
*/
sl@0
    70
EXPORT_C CFbsBitmap::~CFbsBitmap()
sl@0
    71
	{
sl@0
    72
	Reset();
sl@0
    73
	}
sl@0
    74
	
sl@0
    75
/** Gets the physical length in bytes of a scanline in memory. 
sl@0
    76
This is aligned to a 4 byte (DWORD) boundary for performance reasons.
sl@0
    77
sl@0
    78
@param aLength The length of a scanline in pixels. 
sl@0
    79
@param aDispMode The display mode of the bitmap. 
sl@0
    80
@return Number of bytes in the scanline in memory. 
sl@0
    81
@publishedAll 
sl@0
    82
@released
sl@0
    83
*/
sl@0
    84
EXPORT_C TInt CFbsBitmap::ScanLineLength(TInt aLength,TDisplayMode aDispMode)
sl@0
    85
	{
sl@0
    86
	if (aDispMode == ERgb)
sl@0
    87
		return aLength * 4;
sl@0
    88
	else if (aDispMode == ENone)
sl@0
    89
		return 0;
sl@0
    90
sl@0
    91
	return CBitwiseBitmap::ByteWidth(aLength,aDispMode);
sl@0
    92
	}
sl@0
    93
sl@0
    94
/** Releases the bitmap's handle from the font and bitmap server and decrements 
sl@0
    95
its access count.
sl@0
    96
The server-side bitmap is only deleted when the access count for the bitmap 
sl@0
    97
decrements to zero. 
sl@0
    98
@publishedAll
sl@0
    99
@released
sl@0
   100
*/
sl@0
   101
EXPORT_C void CFbsBitmap::Reset()
sl@0
   102
	{
sl@0
   103
    FBS_OST(TInt ssh = (iFbs ? iFbs->ServerSessionHandle() : 0);)
sl@0
   104
    FBS_OST(OstTraceExt4( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_RESET_ENTRY, "> this=0x%08x; iH=0x%08x; iSH=0x%08x; iSSH=0x%08x", (TUint)this, iHandle, iServerHandle, ssh );)
sl@0
   105
	if (iHandle && !(iFlags & EIsRomBitmap))
sl@0
   106
		{
sl@0
   107
		iFbs->SendCommand(EFbsMessClose, iHandle, Handle());
sl@0
   108
		iFbs->iHelper->RemoveBitmap(*this);
sl@0
   109
		}
sl@0
   110
	if (KRomMBMInRamRSC && (iFlags & EIsRomBitmap))
sl@0
   111
		{
sl@0
   112
		// If it is a ROM bitmap, we have to check, is it a ROM bitmap located
sl@0
   113
		// in RAM? If yes, then we have to deallocate the bitmap memory.
sl@0
   114
		TBool isInRom = EFalse;
sl@0
   115
		TInt ret = User::IsRomAddress(isInRom, iAddressPointer);
sl@0
   116
		if (ret == KErrNone && !isInRom)
sl@0
   117
			delete[] reinterpret_cast<TUint8*>(iAddressPointer);
sl@0
   118
		}
sl@0
   119
	iAddressPointer = NULL;
sl@0
   120
	iFlags = 0;
sl@0
   121
	iUseCount = 0;
sl@0
   122
	iHandle = 0;
sl@0
   123
	iServerHandle = 0;
sl@0
   124
	FBS_OST(OstTrace1( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_RESET_EXIT, "< this=0x%08x", (TUint)this );)
sl@0
   125
	}
sl@0
   126
	
sl@0
   127
/** Tests whether or not the bitmap is read-only.
sl@0
   128
@return ETrue if the bitmap is read-only, EFalse otherwise.
sl@0
   129
@publishedAll
sl@0
   130
@released
sl@0
   131
*/
sl@0
   132
EXPORT_C TBool CFbsBitmap::IsRomBitmap() const
sl@0
   133
	{
sl@0
   134
	return (iFlags & EIsReadOnlyBitmapMask) > 0;
sl@0
   135
	}
sl@0
   136
sl@0
   137
/**  Sets the bitmap to use a bitmap image stored in ROM.
sl@0
   138
@param aRomBitmapPointer Pointer to a bitmap stored in ROM.
sl@0
   139
@param aBitmapSizeInBytes On return, indicates the size of 
sl@0
   140
the bitmap in bytes. 
sl@0
   141
@leave KErrUnknown aRomBitmapPointer is not in ROM, or has an invalid UID.
sl@0
   142
@publishedAll
sl@0
   143
@released
sl@0
   144
*/	
sl@0
   145
EXPORT_C void CFbsBitmap::SetRomBitmapL(CBitwiseBitmap* aRomBitmapPointer,TInt& aBitmapSizeInBytes)
sl@0
   146
    {
sl@0
   147
	TBool isInRom = EFalse;
sl@0
   148
	TInt ret = User::IsRomAddress(isInRom,(TAny*)aRomBitmapPointer);
sl@0
   149
	if (ret != KErrNone || !isInRom || aRomBitmapPointer->Uid() != KCBitwiseBitmapUid)
sl@0
   150
		User::Leave(KErrUnknown);
sl@0
   151
sl@0
   152
	Reset();
sl@0
   153
	iAddressPointer = aRomBitmapPointer;
sl@0
   154
	iFlags = EIsRomBitmap;
sl@0
   155
	iHandle = 1;
sl@0
   156
sl@0
   157
	User::LeaveIfError(iFbs->AllocScanLineBuffer(aRomBitmapPointer->iByteWidth + 4));
sl@0
   158
	aBitmapSizeInBytes = Align4(aRomBitmapPointer->iHeader.iBitmapSize + 28);
sl@0
   159
	}
sl@0
   160
sl@0
   161
CBitwiseBitmap* CFbsBitmap::Address() const
sl@0
   162
	{
sl@0
   163
	if (!iHandle)
sl@0
   164
		return NULL;
sl@0
   165
	return iAddressPointer;
sl@0
   166
	}
sl@0
   167
sl@0
   168
EXPORT_C CBitwiseBitmap* CFbsBitmap::CleanAddress() const
sl@0
   169
	{
sl@0
   170
	if (!iHandle)
sl@0
   171
		return NULL;
sl@0
   172
	// Don't try to clean a dirty bitmap between calls to BeginDataAccess() and EndDataAccess(), i.e. iUseCount > 0
sl@0
   173
	// ROM bitmaps can never be dirty
sl@0
   174
	if (!(iFlags & EIsReadOnlyBitmapMask) && iUseCount == 0 && iAddressPointer->iSettings.IsDirtyBitmap())
sl@0
   175
		{
sl@0
   176
		TPckgBuf<TBmpHandles> handlebuf;
sl@0
   177
		TIpcArgs args(iHandle, &handlebuf);
sl@0
   178
		if (iFbs->SendCommand(EFbsMessBitmapClean, args) == KErrNone)
sl@0
   179
			{
sl@0
   180
			const_cast<CFbsBitmap*>(this)->iHandle = handlebuf().iHandle;
sl@0
   181
			const_cast<CFbsBitmap*>(this)->iServerHandle = handlebuf().iServerHandle;
sl@0
   182
			const_cast<CFbsBitmap*>(this)->iAddressPointer = (CBitwiseBitmap*)(iFbs->HeapBase() + handlebuf().iAddressOffset);
sl@0
   183
			}
sl@0
   184
		}
sl@0
   185
	return iAddressPointer;
sl@0
   186
	}
sl@0
   187
sl@0
   188
inline CBitwiseBitmap* CFbsBitmap::BeginDataAccessAndGetCleanAddress(TUint32*& aDataAddress) const
sl@0
   189
	{
sl@0
   190
	BeginDataAccess();
sl@0
   191
	CBitwiseBitmap* bmp = Address();
sl@0
   192
	// aDataAddress should be consistent with bmp since after the call to BeginDataAccess()
sl@0
   193
	// the call to DataAddress() will not clean the bitmap again
sl@0
   194
	aDataAddress = DataAddress();
sl@0
   195
	return bmp;
sl@0
   196
	}
sl@0
   197
sl@0
   198
/** Gets the address of the first pixel in the bitmap. 
sl@0
   199
The first pixel is at the top-left. Access to the pixel data of a bitmap
sl@0
   200
should be surrounded by calls to BeginDataAccess() and EndDataAccess(),
sl@0
   201
otherwise performance may be degraded on certain platforms.
sl@0
   202
sl@0
   203
Note: Performing a Resize() or Compress() operation changes the value returned by this function.
sl@0
   204
@return The address of the first pixel of the bitmap.
sl@0
   205
@publishedAll
sl@0
   206
@released
sl@0
   207
@see CFbsBitmap::BeginDataAccess()
sl@0
   208
@see CFbsBitmap::EndDataAccess()
sl@0
   209
*/
sl@0
   210
EXPORT_C TUint32* CFbsBitmap::DataAddress() const
sl@0
   211
	{
sl@0
   212
	if(!iHandle) return(NULL);
sl@0
   213
	CBitwiseBitmap* bmp = CleanAddress();
sl@0
   214
sl@0
   215
	if (!(iFlags & EIsReadOnlyBitmapMask) && (iUseCount == 0))
sl@0
   216
		bmp->iSettings.SetVolatileBitmap();
sl@0
   217
		
sl@0
   218
	if(bmp->iUid.iUid==KCBitwiseBitmapHardwareUid.iUid)   // RHardwareBitmap
sl@0
   219
		{
sl@0
   220
		RHardwareBitmap hwb(bmp->iDataOffset);	// iDataOffset = handle for hardware bitmap
sl@0
   221
		TAcceleratedBitmapInfo info;
sl@0
   222
		const TInt ret = hwb.GetInfo(info);
sl@0
   223
		return ret!=KErrNone ? NULL : (reinterpret_cast<TUint32*>(info.iAddress));
sl@0
   224
		}
sl@0
   225
sl@0
   226
	if (bmp->iHeap == NULL)
sl@0
   227
		return(reinterpret_cast<TUint32*>((TUint8*)bmp+bmp->iDataOffset));
sl@0
   228
	return(reinterpret_cast<TUint32*>(iFbs->iLargeBitmapChunk.Base()+bmp->iDataOffset));
sl@0
   229
	}
sl@0
   230
sl@0
   231
/** Gets the length in bytes between scanlines in memory.
sl@0
   232
@return The length in bytes between scanlines in memory. 
sl@0
   233
@internalAll
sl@0
   234
@released
sl@0
   235
*/
sl@0
   236
EXPORT_C TInt CFbsBitmap::DataStride() const
sl@0
   237
	{
sl@0
   238
	if (!iHandle)
sl@0
   239
		{
sl@0
   240
		return 0;
sl@0
   241
		}
sl@0
   242
		
sl@0
   243
	CBitwiseBitmap* bmp = CleanAddress();
sl@0
   244
	if (bmp==NULL)
sl@0
   245
		{
sl@0
   246
		return 0;
sl@0
   247
		}
sl@0
   248
		
sl@0
   249
	return bmp->DataStride();	
sl@0
   250
	}
sl@0
   251
sl@0
   252
/** Creates a bitmap with the specified size and display mode. The bitmap is 
sl@0
   253
created on the font and bitmap server's shared heap.
sl@0
   254
@param aSizeInPixels The size of the bitmap to be created. 
sl@0
   255
@param aDispMode The display mode of the bitmap to be created. 
sl@0
   256
@return KErrNone if successful; KErrCouldNotConnect if no connection to the 
sl@0
   257
font and bitmap server could be made; KErrArgument if either the width or height specified 
sl@0
   258
in aSizeInPixels are negative or if the requested display mode is invalid; KErrTooBig 
sl@0
   259
if the requested size is too big. 
sl@0
   260
@publishedAll
sl@0
   261
@released
sl@0
   262
*/
sl@0
   263
EXPORT_C TInt CFbsBitmap::Create(const TSize& aSizeInPixels,TDisplayMode aDispMode)
sl@0
   264
	{
sl@0
   265
    FBS_OST(OstTraceExt4(GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_CREATE_ENTRY, "> this=0x%08x; w=%d; h=%d; dm=%d", (TUint)this, aSizeInPixels.iWidth, aSizeInPixels.iHeight, aDispMode); ) 
sl@0
   266
	TInt err = DoCreate(aSizeInPixels,aDispMode,KUidCFbsBitmapCreation);
sl@0
   267
    FBS_OST(TInt ssh = (iFbs ? iFbs->ServerSessionHandle() : 0);)
sl@0
   268
	FBS_OST(OstTraceExt5(GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_CREATE_EXIT, "< this=0x%08x; err=%d; iH=0x%08x; iSH=0x%08x; iSSH=0x%08x", (TUint)this, err, iHandle, iServerHandle, ssh); )
sl@0
   269
    return err;
sl@0
   270
	}
sl@0
   271
sl@0
   272
TInt CFbsBitmap::DoCreate(const TSize& aSizeInPixels, TDisplayMode aDispMode, TUid aUid, TInt aDataSize)
sl@0
   273
	{
sl@0
   274
	if(!iFbs) return(KErrCouldNotConnect);
sl@0
   275
	if (aDispMode <= ENone || aDispMode == ERgb || aDispMode >= EColorLast) return KErrArgument;
sl@0
   276
	if(aSizeInPixels.iWidth<0 || aSizeInPixels.iHeight<0) return(KErrArgument);
sl@0
   277
	if (aDataSize < 0) return KErrArgument;
sl@0
   278
	Reset();
sl@0
   279
	TBmpSpec bmpspec;
sl@0
   280
	bmpspec.iSizeInPixels=aSizeInPixels;
sl@0
   281
	bmpspec.iDispMode=aDispMode;
sl@0
   282
	bmpspec.iHandle = aUid.iUid;	// Use iHandle to pass UID
sl@0
   283
	bmpspec.iServerHandle = aDataSize;	// Use iServerHandle to pass data size
sl@0
   284
	TPckgBuf<TBmpSpec> b;
sl@0
   285
	b=bmpspec;
sl@0
   286
	TIpcArgs args(&b);
sl@0
   287
	TInt ret=iFbs->SendCommand(EFbsMessBitmapCreate,args);
sl@0
   288
	if(ret!=KErrNone) return(ret);
sl@0
   289
	iHandle=b().iHandle;
sl@0
   290
	iServerHandle=b().iServerHandle;
sl@0
   291
	iAddressPointer=(CBitwiseBitmap*)(iFbs->HeapBase()+b().iAddressOffset);
sl@0
   292
	if (aDataSize > 0) // explicitly specified data size means extended bitmap
sl@0
   293
		{
sl@0
   294
		iFlags = EIsExtendedBitmap;
sl@0
   295
		}
sl@0
   296
	ret = iFbs->iHelper->AddBitmap(*this);
sl@0
   297
	if (ret != KErrNone)
sl@0
   298
		return ret;
sl@0
   299
	return iFbs->AllocScanLineBuffer(CBitwiseBitmap::ByteWidth(aSizeInPixels.iWidth, aDispMode)+4);
sl@0
   300
	}
sl@0
   301
sl@0
   302
/** Creates a hardware bitmap with a size and display mode.
sl@0
   303
@param aSizeInPixels The bitmap's width and height in pixels.
sl@0
   304
@param aDispMode The bitmap's display mode.
sl@0
   305
@param aCreatorUid The UID of the application calling this function. This is 
sl@0
   306
used to allow segregation of the memory used for hardware bitmaps. For instance, 
sl@0
   307
if a device has video memory attached to display and graphics accelerator 
sl@0
   308
hardware, this UID is used to determine whether any video memory is pre-allocated 
sl@0
   309
for that application's use.
sl@0
   310
@return KErrNone if successful, otherwise one of the system wide error codes. 
sl@0
   311
These include KErrCouldNotConnect if no connection has been made to the font 
sl@0
   312
and bitmap server, KErrArgument if either the width or height specified in 
sl@0
   313
aSizeInPixels are negative or if the requested display mode is invalid, or KErrNotSupported 
sl@0
   314
if hardware bitmaps are not supported on the device. 
sl@0
   315
@publishedAll
sl@0
   316
@released
sl@0
   317
*/
sl@0
   318
EXPORT_C TInt CFbsBitmap::CreateHardwareBitmap(const TSize& aSizeInPixels,TDisplayMode aDispMode,TUid aCreatorUid)
sl@0
   319
	{
sl@0
   320
    FBS_OST(OstTraceExt5( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_CREATEHARDWAREBITMAP_ENTRY, "> this=0x%08x; w=%d; h=%d; dm=%d; uid=0x%08x", (TUint)this, aSizeInPixels.iWidth, aSizeInPixels.iHeight, aDispMode, aCreatorUid.iUid);)
sl@0
   321
	TInt err = DoCreate(aSizeInPixels,aDispMode,aCreatorUid);
sl@0
   322
    FBS_OST(TInt ssh = (iFbs ? iFbs->ServerSessionHandle() : 0);)
sl@0
   323
	FBS_OST(OstTraceExt5( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_CREATEHARDWAREBITMAP_EXIT, "< this=0x%08x; err=%d; iH=0x%08x; iSH=0x%08x; iSSH=0x%08x", (TUint)this, err, iHandle, iServerHandle, ssh);)
sl@0
   324
	return err;
sl@0
   325
	}
sl@0
   326
sl@0
   327
/** Resets the pixel-size of the bitmap.
sl@0
   328
If the new size is bigger than the old, the original bitmap is still situated 
sl@0
   329
at (0,0), but pixels outside the range of the old pixel-size are set to zero.
sl@0
   330
@param aSizeInPixels The new size of the bitmap. 
sl@0
   331
@return KErrNone if successful; KErrArgument if the new size is illegal; 
sl@0
   332
KErrGeneral if the bitmap has not yet been created; KErrAccessDenied if the 
sl@0
   333
bitmap is in ROM or is an extended bitmap; otherwise another of the system-wide error codes. 
sl@0
   334
@publishedAll
sl@0
   335
@released
sl@0
   336
*/
sl@0
   337
EXPORT_C TInt CFbsBitmap::Resize(const TSize& aSizeInPixels)
sl@0
   338
	{
sl@0
   339
	if(aSizeInPixels.iWidth<0 || aSizeInPixels.iHeight<0) 
sl@0
   340
		return(KErrArgument);
sl@0
   341
	if(aSizeInPixels.iWidth>KMaxPixelSize || aSizeInPixels.iHeight>KMaxPixelSize)
sl@0
   342
		return(KErrTooBig);	
sl@0
   343
	if(!iHandle) 
sl@0
   344
		return(KErrGeneral);
sl@0
   345
	if (iFlags & EIsReadOnlyBitmapMask)
sl@0
   346
		return(KErrAccessDenied);	
sl@0
   347
	TPckgBuf<TBmpHandles> handlebuf;
sl@0
   348
	TIpcArgs args(iHandle, aSizeInPixels.iWidth, aSizeInPixels.iHeight, &handlebuf);
sl@0
   349
	TInt err = iFbs->SendCommand(EFbsMessBitmapResize, args);
sl@0
   350
	if (err != KErrNone)
sl@0
   351
		return (err);
sl@0
   352
	iHandle = handlebuf().iHandle;
sl@0
   353
	iServerHandle = handlebuf().iServerHandle;
sl@0
   354
	iAddressPointer = (CBitwiseBitmap*)(iFbs->HeapBase() + handlebuf().iAddressOffset);
sl@0
   355
	return iFbs->AllocScanLineBuffer(CBitwiseBitmap::ByteWidth(aSizeInPixels.iWidth, DisplayMode())+4);
sl@0
   356
	}
sl@0
   357
sl@0
   358
/** Gets the display mode of the bitmap.
sl@0
   359
@return The display mode of the bitmap. 
sl@0
   360
@publishedAll
sl@0
   361
@released
sl@0
   362
*/
sl@0
   363
EXPORT_C TDisplayMode CFbsBitmap::DisplayMode() const
sl@0
   364
	{
sl@0
   365
	if(iHandle==NULL) return(ENone);
sl@0
   366
	return CleanAddress()->DisplayMode();
sl@0
   367
	}
sl@0
   368
sl@0
   369
/** Returns the display mode that was used to create the bitmap.
sl@0
   370
@return The display mode used to create the bitmap.
sl@0
   371
@publishedAll
sl@0
   372
@released
sl@0
   373
*/
sl@0
   374
EXPORT_C TDisplayMode CFbsBitmap::InitialDisplayMode() const
sl@0
   375
	{
sl@0
   376
	if(iHandle == NULL) 
sl@0
   377
		{
sl@0
   378
		return ENone;
sl@0
   379
		}
sl@0
   380
	return CleanAddress()->InitialDisplayMode();
sl@0
   381
	}
sl@0
   382
sl@0
   383
/**
sl@0
   384
Changes the display mode of the bitmap.
sl@0
   385
The requested display mode cannot be greater (in bpp value) than the initial display mode.
sl@0
   386
This method cannot leave, for instance because of an out of memory condition. No 
sl@0
   387
additional memory is allocated or leaving methods called.
sl@0
   388
The bitmap's content is preserved when converting it to the requested display mode,
sl@0
   389
but there may be some loss of quality.
sl@0
   390
@publishedAll
sl@0
   391
@released
sl@0
   392
@param aDisplayMode The requested display mode.
sl@0
   393
@return KErrArgument if the requested mode is invalid, or has a greater bpp value 
sl@0
   394
than the initial mode. KErrNotSupported if the bitmap is compressed, or is a
sl@0
   395
ROM bitmap, an extended bitmap or a hardware bitmap. KErrGeneral if the bitmap
sl@0
   396
handle is NULL. KErrNone if the method call is successful.
sl@0
   397
@see CFbsBitmap::InitialDisplayMode()
sl@0
   398
*/
sl@0
   399
EXPORT_C TInt CFbsBitmap::SetDisplayMode(TDisplayMode aDisplayMode)
sl@0
   400
	{
sl@0
   401
	if(!iHandle) 
sl@0
   402
		{
sl@0
   403
		return KErrGeneral;
sl@0
   404
		}	
sl@0
   405
	TUint32* data;
sl@0
   406
	CBitwiseBitmap* bmp = BeginDataAccessAndGetCleanAddress(data);
sl@0
   407
	TInt err = bmp->SetDisplayMode(aDisplayMode, data);
sl@0
   408
	EndDataAccess(EFalse);
sl@0
   409
	return err;
sl@0
   410
	}
sl@0
   411
sl@0
   412
/** Duplicates a bitmap.
sl@0
   413
This function does not create a copy of the bitmap. It just assigns another 
sl@0
   414
handle to the bitmap in the font and bitmap server, and sets this object's 
sl@0
   415
handle to that. If the specified bitmap is in the ROM, it just assigns a pointer 
sl@0
   416
to it.
sl@0
   417
@param aHandle The handle to an existing bitmap.
sl@0
   418
@return KErrNone if successful; KErrCouldNotConnect if no connection to the 
sl@0
   419
font and bitmap server could be made; KErrUnknown if no bitmap could be found 
sl@0
   420
with the specified handle number.
sl@0
   421
@publishedAll
sl@0
   422
@released
sl@0
   423
@see CFbsBitmap::Handle()
sl@0
   424
*/
sl@0
   425
EXPORT_C TInt CFbsBitmap::Duplicate(TInt aBitmapHandle)	
sl@0
   426
    {
sl@0
   427
    TInt ret = KErrNone;
sl@0
   428
    FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_DUPLICATE_ENTRY, "> this=0x%08x; iH=0x%08x;", (TUint)this, aBitmapHandle);)
sl@0
   429
	if(!iFbs) 
sl@0
   430
		{
sl@0
   431
		ret = KErrCouldNotConnect;
sl@0
   432
		FBS_OST(OstTrace1( TRACE_ERROR, CFBSBITMAP_DUPLICATE_ERROR, "! this=0x%08x; !iFbs", (TUint)this);)
sl@0
   433
		}
sl@0
   434
	else if(!aBitmapHandle) 
sl@0
   435
		{
sl@0
   436
		ret = KErrUnknown;
sl@0
   437
		FBS_OST(OstTrace1( TRACE_ERROR, CFBSBITMAP_DUPLICATE_ERROR2, "! this=0x%08x; !aBitmapHandle", (TUint)this);)
sl@0
   438
		}
sl@0
   439
    else
sl@0
   440
        {
sl@0
   441
        TBool isinrom = EFalse;
sl@0
   442
        ret = User::IsRomAddress(isinrom, (TAny*)aBitmapHandle);
sl@0
   443
        if (ret == KErrNone)
sl@0
   444
            {
sl@0
   445
            if (isinrom)
sl@0
   446
                {
sl@0
   447
                ret = DuplicateInRom(aBitmapHandle);
sl@0
   448
                FBS_OST_IF(ret != KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_DUPLICATE_ERROR4, "! this=0x%08x; DuplicateInRom() returned %d;", (TUint)this, ret);)
sl@0
   449
                }
sl@0
   450
            else
sl@0
   451
                {
sl@0
   452
                ret = DuplicateInRam(aBitmapHandle);
sl@0
   453
                FBS_OST_IF(ret != KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_DUPLICATE_ERROR5, "! this=0x%08x; DuplicateInRam() returned %d;", (TUint)this, ret);)
sl@0
   454
                }
sl@0
   455
            }
sl@0
   456
        else 
sl@0
   457
            {
sl@0
   458
            FBS_OST(OstTraceExt2( TRACE_ERROR, CFBSBITMAP_DUPLICATE_ERROR3, "! this=0x%08x; IsRomAddress() returned %d", (TUint)this, ret);)
sl@0
   459
            ret = KErrUnknown;
sl@0
   460
            }
sl@0
   461
        }
sl@0
   462
    FBS_OST(TInt ssh = (iFbs ? iFbs->ServerSessionHandle() : 0);)
sl@0
   463
    FBS_OST(OstTraceExt5( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_DUPLICATE_EXIT, "< this=0x%08x; iH=0x%08x; iSH=0x%08x; ret=%d; iSSH=0x%08x", (TUint)this, iHandle, iServerHandle, ret, ssh);)
sl@0
   464
	return ret;
sl@0
   465
    }
sl@0
   466
sl@0
   467
/** Duplicates a bitmap where the bitmap handle refers to a rom bitmap.
sl@0
   468
@param aBitmapHandle A valid Rom bitmap handle.
sl@0
   469
@return KErrNone on success.
sl@0
   470
 */
sl@0
   471
TInt CFbsBitmap::DuplicateInRom(TInt aBitmapHandle)
sl@0
   472
    {
sl@0
   473
    TInt ret = KErrNone;
sl@0
   474
    Reset();
sl@0
   475
    TUid uid = ((CBitwiseBitmap*)aBitmapHandle)->Uid();
sl@0
   476
    if (uid != KCBitwiseBitmapUid)
sl@0
   477
        {
sl@0
   478
        FBS_OST(OstTraceExt2( TRACE_ERROR, CFBSBITMAP_DUPLICATEINROM_ERROR, "! this=0x%08x; 0x%08x != KCBitwiseBitmapUid", (TUint)this, (TUint)uid.iUid);)
sl@0
   479
        ret = KErrUnknown;
sl@0
   480
        }
sl@0
   481
    else
sl@0
   482
        {
sl@0
   483
        iAddressPointer = (CBitwiseBitmap*)aBitmapHandle;
sl@0
   484
        iFlags = EIsRomBitmap;
sl@0
   485
        iHandle=1;
sl@0
   486
        ret = iFbs->AllocScanLineBuffer(iAddressPointer->iByteWidth + 4);
sl@0
   487
        FBS_OST_IF(ret!=KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_DUPLICATEINROM_ERROR2, "! this=0x%08x; AllocScanLineBuffer() returned %d", (TUint)this, ret);)
sl@0
   488
        }
sl@0
   489
    return ret;
sl@0
   490
    }
sl@0
   491
sl@0
   492
/** Duplicates a bitmap where the bitmap handle refers to a ram bitmap
sl@0
   493
@param aBitmapHandle A valid Ram bitmap handle.
sl@0
   494
@return KErrNone on success.
sl@0
   495
 */
sl@0
   496
TInt CFbsBitmap::DuplicateInRam(TInt aBitmapHandle)
sl@0
   497
    {
sl@0
   498
    TInt ret = KErrNone;
sl@0
   499
    Reset();
sl@0
   500
     
sl@0
   501
    TPckgBuf<TBmpHandles> b;
sl@0
   502
    TIpcArgs args(aBitmapHandle,&b);
sl@0
   503
    ret=iFbs->SendCommand(EFbsMessBitmapDuplicate,args);
sl@0
   504
    FBS_OST_IF(ret!=KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_DUPLICATEINRAM_ERROR, "! this=0x%08x; SendCommand(EFbsMessBitmapDuplicate) returned %d", (TUint)this, ret);)
sl@0
   505
    if(ret==KErrNone) 
sl@0
   506
        {
sl@0
   507
        iHandle=b().iHandle;
sl@0
   508
        iServerHandle=b().iServerHandle;
sl@0
   509
        iAddressPointer=(CBitwiseBitmap*)(iFbs->HeapBase()+b().iAddressOffset);
sl@0
   510
        if (iAddressPointer->iUid.iUid != KCBitwiseBitmapUid.iUid && iAddressPointer->iUid.iUid != KCBitwiseBitmapHardwareUid.iUid)
sl@0
   511
            {
sl@0
   512
            iFlags = EIsExtendedBitmap;
sl@0
   513
            }
sl@0
   514
        ret = iFbs->iHelper->AddBitmap(*this);
sl@0
   515
        FBS_OST_IF(ret!=KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_DUPLICATEINRAM_ERROR2, "! this=0x%08x; AddBitmap() returned %d", (TUint)this, ret);)
sl@0
   516
        if (ret == KErrNone)
sl@0
   517
            {
sl@0
   518
            ret = iFbs->AllocScanLineBuffer(iAddressPointer->iByteWidth+4);
sl@0
   519
            FBS_OST_IF(ret!=KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_DUPLICATEINRAM_ERROR3, "! this=0x%08x; AllocScanLineBuffer() returned %d", (TUint)this, ret);)
sl@0
   520
            }
sl@0
   521
        }
sl@0
   522
    return ret;
sl@0
   523
    }
sl@0
   524
sl@0
   525
/** Loads a specific bitmap from a multi-bitmap file.
sl@0
   526
The bitmap may be shared by other font and bitmap server clients.
sl@0
   527
@param aFileName The filename of the multi-bitmap (.mbm) file. 
sl@0
   528
@param aId The bitmap identifier.
sl@0
   529
@param aShareIfLoaded Specifies whether or not the loaded bitmap will be made 
sl@0
   530
available for sharing between font and bitmap server clients. 
sl@0
   531
@return KErrNone if successful, otherwise another of the system error 
sl@0
   532
codes. 
sl@0
   533
@publishedAll
sl@0
   534
@released
sl@0
   535
*/	
sl@0
   536
EXPORT_C TInt CFbsBitmap::Load(const TDesC& aFileName,TInt32 aId,TBool aShareIfLoaded)
sl@0
   537
	{
sl@0
   538
    FBS_OST(OstTraceExt4( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOAD_ENTRY, "> this=0x%08x; file=%S, id=0x%08x; share=%d", (TUint)this, aFileName, aId, aShareIfLoaded);)
sl@0
   539
	TInt err = Load(aFileName,aId,aShareIfLoaded,0);
sl@0
   540
    FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOAD_EXIT, "< this=0x%08x; err=%d", (TUint)this, err);)
sl@0
   541
	return err; 
sl@0
   542
	}
sl@0
   543
sl@0
   544
/**  Loads a specific bitmap from a multi-bitmap file.
sl@0
   545
The bitmap may be shared by other font and bitmap server clients.
sl@0
   546
@param aFileName The filename of the multi-bitmap (.mbm) file.
sl@0
   547
@param aId The bitmap identifier.
sl@0
   548
@param aShareIfLoaded  Specifies whether or not the loaded bitmap will be made 
sl@0
   549
available for sharing between FBSERV clients.
sl@0
   550
@param aFileOffset Bitmap file section offset within the file.
sl@0
   551
@return KErrNone if successful, otherwise another of the system error codes.
sl@0
   552
@publishedAll
sl@0
   553
@released
sl@0
   554
*/	
sl@0
   555
EXPORT_C TInt CFbsBitmap::Load(const TDesC& aFileName,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset)
sl@0
   556
	{
sl@0
   557
    TInt err = KErrNone;
sl@0
   558
    FBS_OST(OstTraceExt5( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOAD2_ENTRY, "> this=0x%08x; file=%S, id=0x%08x; share=%d; off=%d", (TUint)this, aFileName, aId, aShareIfLoaded, aFileOffset);)
sl@0
   559
	if(!iFbs)
sl@0
   560
		{
sl@0
   561
        FBS_OST(OstTrace1( TRACE_ERROR, CFBSBITMAP_LOAD2_ERROR, "! this=0x%08x; !iFbs", (TUint)this);)
sl@0
   562
		err = KErrCouldNotConnect;
sl@0
   563
		}
sl@0
   564
	else
sl@0
   565
	    {
sl@0
   566
        Reset();
sl@0
   567
        TUint32* rompointer = NULL;
sl@0
   568
        //access using filename has the advantage of using rom address lookup cache
sl@0
   569
        IsFileInRom(aFileName, rompointer);
sl@0
   570
        TBool romPointerValid;
sl@0
   571
        err = DoLoadFromRom(rompointer, aId, aFileOffset, romPointerValid);
sl@0
   572
        if(!romPointerValid)
sl@0
   573
            {
sl@0
   574
            _LIT(KResourcePath, "?:\\Resource\\*");
sl@0
   575
            TInt match = aFileName.MatchF(KResourcePath);
sl@0
   576
            //if the file is in the resource directory we don't need to check capabilities and the file can just be opened on the server side.
sl@0
   577
            if (match == 0)
sl@0
   578
                {
sl@0
   579
                err = DoLoad(aFileName,aId,aShareIfLoaded,aFileOffset);
sl@0
   580
                FBS_OST_IF(err!=KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_LOAD2_ERROR3, "! this=0x%08x; DoLoad returned %d", (TUint)this, err);)
sl@0
   581
                }
sl@0
   582
            else
sl@0
   583
                {
sl@0
   584
                RFile file;
sl@0
   585
                err = file.Open(iFbs->FileServer(),aFileName,EFileShareReadersOnly);
sl@0
   586
                if (err==KErrNone)
sl@0
   587
                    {
sl@0
   588
                    err = DoLoad(file,aId,aShareIfLoaded,aFileOffset);
sl@0
   589
                    FBS_OST_IF(err!=KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_LOAD2_ERROR4, "! this=0x%08x; DoLoad returned %d", (TUint)this, err);)
sl@0
   590
                    }
sl@0
   591
                file.Close();
sl@0
   592
                }
sl@0
   593
            }
sl@0
   594
	    }
sl@0
   595
    FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOAD2_EXIT, "< this=0x%08x; err=%d", (TUint)this, err);)
sl@0
   596
	return err;
sl@0
   597
	}
sl@0
   598
sl@0
   599
/** Loads and compresses a specific bitmap from a multi-bitmap file.
sl@0
   600
The bitmap may be shared by other font and bitmap server clients.
sl@0
   601
If the bitmap is loaded from ROM then compression is not allowed.
sl@0
   602
@param aFileName The filename of the multi-bitmap (.mbm) file.
sl@0
   603
@param aId The bitmap identifier.
sl@0
   604
@param aShareIfLoaded Specifies whether or not the loaded bitmap will be
sl@0
   605
made available for sharing between FBSERV clients.
sl@0
   606
@return KErrNone if successful, otherwise another of the system-wide error 
sl@0
   607
codes. 
sl@0
   608
@publishedAll 
sl@0
   609
@released
sl@0
   610
*/	
sl@0
   611
EXPORT_C TInt CFbsBitmap::LoadAndCompress(const TDesC& aFileName,TInt32 aId,TBool aShareIfLoaded)
sl@0
   612
    {	
sl@0
   613
    FBS_OST(OstTraceExt4( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOADANDCOMPRESS_ENTRY, "> this=0x%08x; file=%S; id=0x%08x; share=%d", (TUint)this, aFileName, aId, aShareIfLoaded);)
sl@0
   614
    TInt ret = LoadAndCompress(aFileName, aId, aShareIfLoaded, 0);
sl@0
   615
    FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOADANDCOMPRESS_EXIT, "< this=0x%08x; err=%d", (TUint)this, ret);)
sl@0
   616
    return ret;
sl@0
   617
	}
sl@0
   618
sl@0
   619
/** Loads and compresses a specific bitmap from a multi-bitmap file.
sl@0
   620
The bitmap may be shared by other font and bitmap server clients. If the 
sl@0
   621
bitmap is loaded from ROM then compression is not allowed.
sl@0
   622
@param aFileName The filename of the multi-bitmap (.mbm) file.
sl@0
   623
@param aId The bitmap identifier.
sl@0
   624
@param aShareIfLoaded Specifies whether or not the loaded bitmap will be made 
sl@0
   625
available for sharing between FBSERV clients.
sl@0
   626
@param aFileOffset Bitmap file section offset within the file.
sl@0
   627
@return KErrNone if successful, otherwise another of the system-wide error 
sl@0
   628
codes. 
sl@0
   629
@publishedAll 
sl@0
   630
@released
sl@0
   631
*/	
sl@0
   632
EXPORT_C TInt CFbsBitmap::LoadAndCompress(const TDesC& aFileName,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset)
sl@0
   633
    {
sl@0
   634
    FBS_OST(OstTraceExt5( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOADANDCOMPRESS2_ENTRY, "> this=0x%08x; file=%S, id=0x%08x; share=%d; off=%d", (TUint)this, aFileName, aId, aShareIfLoaded, aFileOffset);)
sl@0
   635
	TInt err = Load(aFileName,aId,aShareIfLoaded,aFileOffset);
sl@0
   636
	if (err == KErrNone)
sl@0
   637
		{
sl@0
   638
		err = !(iFlags & EIsRomBitmap) ? Compress() : KErrAccessDenied;
sl@0
   639
		FBS_OST_IF(err!=KErrNone, OstTraceExt3( TRACE_ERROR, CFBSBITMAP_LOADANDCOMPRESS2_ERROR, "! this=0x%08x; iFlags=0x%08x; err=%d", (TUint)this, (TUint)iFlags, err);)
sl@0
   640
		}
sl@0
   641
	FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOADANDCOMPRESS2_EXIT, "< this=0x%08x; err=%d", (TUint)this, err);)
sl@0
   642
	return err;
sl@0
   643
	}
sl@0
   644
sl@0
   645
/** Saves the bitmap as a direct file store.
sl@0
   646
The file store overwrites any existing file with the same name.
sl@0
   647
@param aFilename The name of the file. 
sl@0
   648
@return KErrNone if successful, KErrNotSupported if this CFbsBitmap is an 
sl@0
   649
extended bitmap, otherwise another of the system-wide error codes. 
sl@0
   650
@publishedAll 
sl@0
   651
@released
sl@0
   652
*/
sl@0
   653
EXPORT_C TInt CFbsBitmap::Save(const TDesC& aFilename)
sl@0
   654
	{
sl@0
   655
	if (!iHandle)
sl@0
   656
		{
sl@0
   657
		return(KErrGeneral);
sl@0
   658
		}
sl@0
   659
	RFile file;
sl@0
   660
	TInt ret=file.Replace(iFbs->FileServer(),aFilename,EFileWrite);
sl@0
   661
	if(ret!=KErrNone) return(ret);
sl@0
   662
	TRAP(ret,DoSaveL(file));
sl@0
   663
	file.Close();
sl@0
   664
	return(ret);
sl@0
   665
	}
sl@0
   666
sl@0
   667
/** Saves the bitmap as a direct file store using an opened file handle.
sl@0
   668
The file store overwrites any existing file with the same name.
sl@0
   669
@param aFile The opened file handle
sl@0
   670
@return KErrNone if successful, KErrNotSupported if this CFbsBitmap is an 
sl@0
   671
extended bitmap, otherwise another of the system-wide error codes. 
sl@0
   672
@publishedAll 
sl@0
   673
@released
sl@0
   674
*/
sl@0
   675
EXPORT_C TInt CFbsBitmap::Save(RFile& aFile)
sl@0
   676
	{
sl@0
   677
	if (!iHandle)
sl@0
   678
		{
sl@0
   679
		return KErrGeneral;
sl@0
   680
		}
sl@0
   681
	TRAPD(ret,DoSaveL(aFile));
sl@0
   682
	return ret;
sl@0
   683
	}
sl@0
   684
sl@0
   685
void CFbsBitmap::DoSaveL(RFile& aFile)
sl@0
   686
	{
sl@0
   687
	CDirectFileStore* filestore=CDirectFileStore::NewLC(aFile); // create from open file
sl@0
   688
	TUidType uidtype(KDirectFileStoreLayoutUid,KMultiBitmapFileImageUid);
sl@0
   689
	filestore->SetTypeL(uidtype);
sl@0
   690
	RStoreWriteStream bmpstream;
sl@0
   691
	TStreamId bmpstreamid=bmpstream.CreateLC(*filestore); // create bitmap stream
sl@0
   692
	ExternalizeL(bmpstream);
sl@0
   693
	bmpstream.CommitL();
sl@0
   694
	CleanupStack::PopAndDestroy(); // bitmap stream
sl@0
   695
	RStoreWriteStream rootstream;
sl@0
   696
	TStreamId rootstreamid=rootstream.CreateLC(*filestore); // create root stream
sl@0
   697
	rootstream.WriteInt32L(1); // number of bitmaps
sl@0
   698
	rootstream<<bmpstreamid; // stream id of bitmap
sl@0
   699
	rootstream.CommitL();
sl@0
   700
	CleanupStack::PopAndDestroy(); // root stream
sl@0
   701
	filestore->SetRootL(rootstreamid);
sl@0
   702
	filestore->CommitL();
sl@0
   703
	CleanupStack::PopAndDestroy(); // file store
sl@0
   704
	}
sl@0
   705
sl@0
   706
/** Constructs a multi-bitmap file.
sl@0
   707
@param aFilename The name of the multi-bitmap file to be created.
sl@0
   708
@param aNumSources The number of bitmaps to store in the file.
sl@0
   709
@param aSources  An array of pointers to bitmaps to be stored.
sl@0
   710
@param aSourceIds An array of identifiers for the bitmaps to be stored. 
sl@0
   711
@publishedAll
sl@0
   712
@released
sl@0
   713
*/	
sl@0
   714
EXPORT_C void CFbsBitmap::StoreL(const TDesC& aFilename,TInt aNumSources,const TDesC* aSources[],TInt32 aSourceIds[])
sl@0
   715
	{
sl@0
   716
	CFbsBitmap* bitmap = new(ELeave) CFbsBitmap;
sl@0
   717
	CleanupStack::PushL(bitmap);
sl@0
   718
	CDirectFileStore* filestore = CDirectFileStore::ReplaceLC(bitmap->iFbs->FileServer(),aFilename,EFileWrite);
sl@0
   719
	DoStoreL(filestore,bitmap,aNumSources,aSources,aSourceIds);
sl@0
   720
	CleanupStack::PopAndDestroy(2,bitmap);	
sl@0
   721
	}
sl@0
   722
sl@0
   723
/** Constructs a multi-bitmap file using an opened file handle.
sl@0
   724
@param aFile The opened file handle of multi-bitmap file
sl@0
   725
@param aNumSources The number of bitmaps to store in the file.
sl@0
   726
@param aSources  An array of pointers to bitmaps to be stored.
sl@0
   727
@param aSourceIds An array of identifiers for the bitmaps to be stored. 
sl@0
   728
@publishedAll
sl@0
   729
@released
sl@0
   730
*/	
sl@0
   731
EXPORT_C void CFbsBitmap::StoreL(RFile& aFile,TInt aNumSources,const TDesC* aSources[],TInt32 aSourceIds[])
sl@0
   732
	{
sl@0
   733
	CDirectFileStore* filestore = CDirectFileStore::NewLC(aFile);
sl@0
   734
	DoStoreL(filestore,NULL,aNumSources,aSources,aSourceIds);
sl@0
   735
	CleanupStack::PopAndDestroy(filestore);	
sl@0
   736
	}
sl@0
   737
sl@0
   738
/**
sl@0
   739
@internalComponent
sl@0
   740
*/
sl@0
   741
void CFbsBitmap::DoStoreL(CDirectFileStore* aFileStore,CFbsBitmap* aBitmap,TInt aNumSources,const TDesC* aSources[],TInt32 aSourceIds[])
sl@0
   742
	{
sl@0
   743
	if(aNumSources<1 || aSources==NULL) User::Leave(KErrArgument);
sl@0
   744
	TInt count=0;
sl@0
   745
	for(;count<aNumSources;count++)
sl@0
   746
		if(aSources[count]==NULL) User::Leave(KErrArgument);
sl@0
   747
	TStreamId* ids=new(ELeave) TStreamId[aNumSources];
sl@0
   748
	CleanupArrayDeletePushL(ids);
sl@0
   749
	TInt nPushed=1;
sl@0
   750
	if (!aBitmap)
sl@0
   751
		{
sl@0
   752
		aBitmap=new(ELeave) CFbsBitmap;
sl@0
   753
		CleanupStack::PushL(aBitmap);
sl@0
   754
		++nPushed;
sl@0
   755
		}
sl@0
   756
	TUidType uidtype(KDirectFileStoreLayoutUid,KMultiBitmapFileImageUid);
sl@0
   757
	aFileStore->SetTypeL(uidtype);
sl@0
   758
	for(count=0;count<aNumSources;count++)
sl@0
   759
		{
sl@0
   760
		User::LeaveIfError(aBitmap->Load(*aSources[count],aSourceIds[count]));
sl@0
   761
		RStoreWriteStream bmpstream;
sl@0
   762
		ids[count]=bmpstream.CreateLC(*aFileStore); // create bitmap stream
sl@0
   763
		aBitmap->ExternalizeL(bmpstream);
sl@0
   764
		bmpstream.Close();
sl@0
   765
		CleanupStack::Pop(); // bitmap stream
sl@0
   766
		}
sl@0
   767
	RStoreWriteStream rootstream;
sl@0
   768
	TStreamId rootstreamid=rootstream.CreateLC(*aFileStore); // create root stream
sl@0
   769
	rootstream.WriteInt32L(aNumSources); // number of bitmaps
sl@0
   770
	for(count=0;count<aNumSources;count++)
sl@0
   771
		rootstream<<ids[count]; // stream ids of bitmaps
sl@0
   772
	rootstream.Close();
sl@0
   773
	CleanupStack::Pop(); // root stream
sl@0
   774
	aFileStore->SetRootL(rootstreamid);
sl@0
   775
	CleanupStack::PopAndDestroy(nPushed); // ids [and bitmap]
sl@0
   776
	}
sl@0
   777
sl@0
   778
/** Gets the bitmap's scanline for the specified line starting from the 
sl@0
   779
specified point.
sl@0
   780
The dither offset of the bitmap is taken to be TPoint(0,0).
sl@0
   781
@param aBuf The buffer in which the scanline is returned. 
sl@0
   782
@param aPoint The start pixel. 
sl@0
   783
@param aLength The number of pixels to get. 
sl@0
   784
@param aDispMode Format to be used to write the data to the buffer. 
sl@0
   785
@publishedAll
sl@0
   786
@released
sl@0
   787
*/
sl@0
   788
EXPORT_C void CFbsBitmap::GetScanLine(TDes8& aBuf,const TPoint& aPoint,TInt aLength,TDisplayMode aDispMode) const
sl@0
   789
	{
sl@0
   790
	GetScanLine(aBuf,aPoint,aLength,TPoint(0,0),aDispMode);
sl@0
   791
	}
sl@0
   792
sl@0
   793
/** Gets the bitmap's scanline for the specified line starting from the specified 
sl@0
   794
point and using the specified dither offset.
sl@0
   795
@param aBuf The buffer in which the scanline is returned. 
sl@0
   796
@param aPixel The start pixel. 
sl@0
   797
@param aLength The number of pixels to get. 
sl@0
   798
@param aDitherOffset The dither offset of the bitmap. 
sl@0
   799
@param aDispMode Format to be used to write the data to the buffer. 
sl@0
   800
@publishedAll 
sl@0
   801
@released
sl@0
   802
*/
sl@0
   803
EXPORT_C void CFbsBitmap::GetScanLine(TDes8& aBuf,const TPoint& aPoint,TInt aLength,const TPoint& aDitherOffset,TDisplayMode aDispMode) const
sl@0
   804
	{
sl@0
   805
	if(!iHandle) return;
sl@0
   806
	TUint32* data;
sl@0
   807
	CBitwiseBitmap* bmp = BeginDataAccessAndGetCleanAddress(data);
sl@0
   808
	CFbsRasterizer* rasterizer = NULL;
sl@0
   809
	if ((iFlags & EIsExtendedBitmap) && iFbs)
sl@0
   810
		{
sl@0
   811
		rasterizer = iFbs->iHelper->Rasterizer();
sl@0
   812
		if (rasterizer)
sl@0
   813
			{
sl@0
   814
			CFbsRasterizer::TBitmapDesc desc;
sl@0
   815
			desc.iSizeInPixels = bmp->SizeInPixels();
sl@0
   816
			desc.iDispMode = bmp->DisplayMode();
sl@0
   817
			desc.iDataType = bmp->iUid;
sl@0
   818
			desc.iData = data;
sl@0
   819
			desc.iDataSize = bmp->iHeader.iBitmapSize - bmp->iHeader.iStructSize;
sl@0
   820
			rasterizer->BeginBitmap(bmp->Extra()->iSerialNumber, desc, NULL);
sl@0
   821
			}
sl@0
   822
		}
sl@0
   823
	bmp->GetScanLine(aBuf, aPoint, aLength, ETrue, aDitherOffset, aDispMode, data);
sl@0
   824
	if (rasterizer)
sl@0
   825
		{
sl@0
   826
		rasterizer->EndBitmap(bmp->Extra()->iSerialNumber);
sl@0
   827
		}
sl@0
   828
	EndDataAccess(ETrue);
sl@0
   829
	}
sl@0
   830
sl@0
   831
/** Sets the bitmap's horizontal scanline at the specified y co-ordinate to the 
sl@0
   832
scanline contained in the buffer.
sl@0
   833
@param aBuf The new scanline to be written to the bitmap. 
sl@0
   834
@param aY The y co-ordinate of the scanline.
sl@0
   835
@panic FBSCLI 11 in debug builds if this is a compressed bitmap.
sl@0
   836
@panic FBSCLI 28 in debug builds if this is a read-only bitmap.
sl@0
   837
@publishedAll 
sl@0
   838
@released
sl@0
   839
*/
sl@0
   840
EXPORT_C void CFbsBitmap::SetScanLine(TDes8& aBuf,TInt aY) const
sl@0
   841
	{
sl@0
   842
	if (!iHandle)
sl@0
   843
		return;	
sl@0
   844
	if (iFlags & EIsReadOnlyBitmapMask)
sl@0
   845
		{
sl@0
   846
		__ASSERT_DEBUG(EFalse, ::Panic(EFbsPanicBitmapReadOnly));
sl@0
   847
		return;
sl@0
   848
		}
sl@0
   849
	TUint32* data;
sl@0
   850
	CBitwiseBitmap* bmp = BeginDataAccessAndGetCleanAddress(data);
sl@0
   851
	if (bmp->IsCompressed())
sl@0
   852
		{
sl@0
   853
		EndDataAccess(ETrue);
sl@0
   854
		__ASSERT_DEBUG(EFalse, ::Panic(EFbsBitmapInvalidCompression));
sl@0
   855
		return;
sl@0
   856
		}
sl@0
   857
	data = bmp->ScanLineAddress(data, aY);
sl@0
   858
	TInt bytewidth = bmp->iByteWidth;
sl@0
   859
	TInt bytelen=aBuf.Length();
sl@0
   860
	if(bytelen<bytewidth) bytewidth=bytelen;
sl@0
   861
	TInt wordlen=bytewidth>>2;
sl@0
   862
	TUint32* ptr=(TUint32*)aBuf.Ptr();
sl@0
   863
	TUint32* ptrlim=ptr+wordlen;
sl@0
   864
	while(ptr<ptrlim)
sl@0
   865
		*data++=*ptr++;
sl@0
   866
	TInt limit=wordlen<<2;
sl@0
   867
	if(limit<bytewidth)
sl@0
   868
		{
sl@0
   869
		TUint8* byteptr=(TUint8*)ptrlim;
sl@0
   870
		TUint8* databyte=(TUint8*)data;
sl@0
   871
		while(limit<bytewidth)
sl@0
   872
			{
sl@0
   873
			*databyte++=*byteptr++;
sl@0
   874
			limit++;
sl@0
   875
			}
sl@0
   876
		}
sl@0
   877
	EndDataAccess(EFalse);
sl@0
   878
	}
sl@0
   879
sl@0
   880
/** Gets the bitmap's vertical scanline starting at the specified x co-ordinate.
sl@0
   881
Note: The method only works for uncompressed bitmaps.
sl@0
   882
Note: The dither offset of the bitmap is taken to be TPoint(0,0).
sl@0
   883
@param aBuf The buffer in which the vertical scanline is returned. 
sl@0
   884
@param aX The x co-ordinate of the vertical scanline. 
sl@0
   885
@param aDispMode Format to be used to write the data to the buffer. 
sl@0
   886
@panic FBSCLI 11 in debug builds if this is not an ucompressed bitmap or an extended bitmap.
sl@0
   887
@publishedAll 
sl@0
   888
@released
sl@0
   889
*/
sl@0
   890
EXPORT_C void CFbsBitmap::GetVerticalScanLine(TDes8& aBuf,TInt aX,TDisplayMode aDispMode) const
sl@0
   891
	{
sl@0
   892
	GetVerticalScanLine(aBuf,aX,TPoint(0,0),aDispMode);
sl@0
   893
	}
sl@0
   894
sl@0
   895
/** Gets the bitmap's vertical scanline starting at the specified x co-ordinate 
sl@0
   896
and using the specified dither offset.
sl@0
   897
Note: The method only works for uncompressed bitmaps.
sl@0
   898
@param aBuf The buffer in which the vertical scanline will be returned. 
sl@0
   899
@param aX The x co-ordinate of the vertical scanline to get. 
sl@0
   900
@param aDitherOffset The dither offset of the bitmap. 
sl@0
   901
@param aDispMode Format to be used to write the data to the buffer. 
sl@0
   902
@panic FBSCLI 11 in debug builds if this is not an ucompressed bitmap or an extended bitmap.
sl@0
   903
@publishedAll 
sl@0
   904
@released
sl@0
   905
*/
sl@0
   906
EXPORT_C void CFbsBitmap::GetVerticalScanLine(TDes8& aBuf,TInt aX,const TPoint& aDitherOffset,TDisplayMode aDispMode) const
sl@0
   907
	{
sl@0
   908
	if(!iHandle) return;
sl@0
   909
	TUint32* data;
sl@0
   910
	CBitwiseBitmap* bmp = BeginDataAccessAndGetCleanAddress(data);
sl@0
   911
	CFbsRasterizer* rasterizer = NULL;
sl@0
   912
	if ((iFlags & EIsExtendedBitmap) && iFbs)
sl@0
   913
		{
sl@0
   914
		rasterizer = iFbs->iHelper->Rasterizer();
sl@0
   915
		if (rasterizer)
sl@0
   916
			{
sl@0
   917
			CFbsRasterizer::TBitmapDesc desc;
sl@0
   918
			desc.iSizeInPixels = bmp->SizeInPixels();
sl@0
   919
			desc.iDispMode = bmp->DisplayMode();
sl@0
   920
			desc.iDataType = bmp->iUid;
sl@0
   921
			desc.iData = data;
sl@0
   922
			desc.iDataSize = bmp->iHeader.iBitmapSize - bmp->iHeader.iStructSize;
sl@0
   923
			rasterizer->BeginBitmap(bmp->Extra()->iSerialNumber, desc, NULL);
sl@0
   924
			}
sl@0
   925
		}
sl@0
   926
	bmp->GetVerticalScanLine(aBuf, aX, ETrue, aDitherOffset, aDispMode, data, rasterizer);
sl@0
   927
	if (rasterizer)
sl@0
   928
		{
sl@0
   929
		rasterizer->EndBitmap(bmp->Extra()->iSerialNumber);
sl@0
   930
		}
sl@0
   931
	EndDataAccess(ETrue);
sl@0
   932
	}
sl@0
   933
sl@0
   934
/** Gets the handle number of the bitmap.
sl@0
   935
The returned value can be used to give another thread access to the bitmap.
sl@0
   936
@return The handle number of the bitmap. 
sl@0
   937
@publishedAll 
sl@0
   938
@released
sl@0
   939
@see CFbsBitmap::Duplicate()
sl@0
   940
*/
sl@0
   941
EXPORT_C TInt CFbsBitmap::Handle() const
sl@0
   942
	{
sl@0
   943
	if(!iHandle) 
sl@0
   944
		return(0);
sl@0
   945
	if (iFlags & EIsRomBitmap)
sl@0
   946
		return TInt(iAddressPointer);
sl@0
   947
	else
sl@0
   948
		return(iServerHandle);
sl@0
   949
	}
sl@0
   950
sl@0
   951
/** Creates a bitmap header.
sl@0
   952
This is used when streaming bitmaps to stores.
sl@0
   953
@return The bitmap header for the bitmap. 
sl@0
   954
@publishedAll 
sl@0
   955
@released
sl@0
   956
*/
sl@0
   957
EXPORT_C SEpocBitmapHeader CFbsBitmap::Header() const
sl@0
   958
	{
sl@0
   959
	if (iHandle)
sl@0
   960
		return CleanAddress()->iHeader;
sl@0
   961
	SEpocBitmapHeader header;
sl@0
   962
	return(header);
sl@0
   963
	}
sl@0
   964
sl@0
   965
/** Converts a horizontal dimension on the graphics device from pixels to twips.
sl@0
   966
@param aPixels A horizontal dimension on the graphics device in pixels. 
sl@0
   967
@return A horizontal dimension on the graphics device in twips. 
sl@0
   968
@publishedAll 
sl@0
   969
@released
sl@0
   970
*/
sl@0
   971
EXPORT_C TInt CFbsBitmap::HorizontalPixelsToTwips(TInt aPixels) const
sl@0
   972
	{
sl@0
   973
	if(iHandle==NULL) return(0);
sl@0
   974
	return CleanAddress()->HorizontalPixelsToTwips(aPixels);
sl@0
   975
	}
sl@0
   976
sl@0
   977
/** Converts a horizontal dimension on the graphics device from twips to pixels.
sl@0
   978
@param aTwips A horizontal dimension on the graphics device in twips. 
sl@0
   979
@return A horizontal dimension on the graphics device in pixels. 
sl@0
   980
@publishedAll 
sl@0
   981
@released
sl@0
   982
*/
sl@0
   983
EXPORT_C TInt CFbsBitmap::HorizontalTwipsToPixels(TInt aTwips) const
sl@0
   984
	{
sl@0
   985
	if(iHandle==NULL) return(0);
sl@0
   986
	return CleanAddress()->HorizontalTwipsToPixels(aTwips);
sl@0
   987
	}
sl@0
   988
sl@0
   989
/** Gets the RGB value of the specified pixel.
sl@0
   990
Note: The method only works for uncompressed bitmaps and extended bitmaps.
sl@0
   991
@param aColor On return, the RGB value of the specified pixel. 
sl@0
   992
@param aPixel The pixel whose colour is to be determined.
sl@0
   993
@panic FBSCLI 11 in debug builds if this is a compressed bitmap.
sl@0
   994
@publishedAll 
sl@0
   995
@released
sl@0
   996
*/
sl@0
   997
EXPORT_C void CFbsBitmap::GetPixel(TRgb& aColor,const TPoint& aPoint) const
sl@0
   998
	{
sl@0
   999
	if(!iHandle) 
sl@0
  1000
		{
sl@0
  1001
		return;
sl@0
  1002
		}	
sl@0
  1003
	
sl@0
  1004
	TUint32* data;
sl@0
  1005
	CBitwiseBitmap* bmp = BeginDataAccessAndGetCleanAddress(data);
sl@0
  1006
	CFbsRasterizer* rasterizer = NULL;
sl@0
  1007
	if ((iFlags & EIsExtendedBitmap) && iFbs)
sl@0
  1008
		{
sl@0
  1009
		rasterizer = iFbs->iHelper->Rasterizer();
sl@0
  1010
		if (rasterizer)
sl@0
  1011
			{
sl@0
  1012
			CFbsRasterizer::TBitmapDesc desc;
sl@0
  1013
			desc.iSizeInPixels = bmp->SizeInPixels();
sl@0
  1014
			desc.iDispMode = bmp->DisplayMode();
sl@0
  1015
			desc.iDataType = bmp->iUid;
sl@0
  1016
			desc.iData = data;
sl@0
  1017
			desc.iDataSize = bmp->iHeader.iBitmapSize - bmp->iHeader.iStructSize;
sl@0
  1018
			rasterizer->BeginBitmap(bmp->Extra()->iSerialNumber, desc, NULL);
sl@0
  1019
			}
sl@0
  1020
		}
sl@0
  1021
	bmp->GetPixel(aColor, aPoint, data, rasterizer);
sl@0
  1022
	if (rasterizer)
sl@0
  1023
		{
sl@0
  1024
		rasterizer->EndBitmap(bmp->Extra()->iSerialNumber);
sl@0
  1025
		}
sl@0
  1026
	EndDataAccess(ETrue);
sl@0
  1027
	}
sl@0
  1028
sl@0
  1029
/** Gets the pixel-size of the bitmap.
sl@0
  1030
@return The size of the bitmap, in pixels. 
sl@0
  1031
@publishedAll 
sl@0
  1032
@released
sl@0
  1033
*/
sl@0
  1034
EXPORT_C TSize CFbsBitmap::SizeInPixels() const
sl@0
  1035
	{
sl@0
  1036
    TSize zero;
sl@0
  1037
	if(!iHandle) return(zero);
sl@0
  1038
	return CleanAddress()->SizeInPixels();
sl@0
  1039
	}
sl@0
  1040
sl@0
  1041
/** Sets the twip-size of the bitmap by converting the bitmaps pixel-size from 
sl@0
  1042
pixels to twips, using the conversion functions in the specified graphics 
sl@0
  1043
device map.
sl@0
  1044
@param aMap The graphics device map to be used for providing pixel to twip 
sl@0
  1045
conversion. 
sl@0
  1046
@publishedAll 
sl@0
  1047
@released
sl@0
  1048
*/
sl@0
  1049
EXPORT_C void CFbsBitmap::SetSizeInTwips(const MGraphicsDeviceMap* aMap)
sl@0
  1050
	{
sl@0
  1051
	if (!iHandle || (iFlags & EIsRomBitmap) || aMap == NULL)
sl@0
  1052
		return;
sl@0
  1053
	TSize size=SizeInPixels();
sl@0
  1054
	size.iWidth=aMap->HorizontalPixelsToTwips(size.iWidth);
sl@0
  1055
	size.iHeight=aMap->VerticalPixelsToTwips(size.iHeight);
sl@0
  1056
	iFbs->SetCallBackPtr(&iServerHandle);
sl@0
  1057
	iFbs->CallBack();
sl@0
  1058
	// SizeInPixels() called CleanAddress() so call Address() now to make sure we don't clean the bitmap twice
sl@0
  1059
	Address()->iHeader.iSizeInTwips=size;
sl@0
  1060
	}
sl@0
  1061
sl@0
  1062
/** Sets the twip-size of the bitmap directly to the specified size.
sl@0
  1063
@param aSizeInTwips The new size of the bitmap, in twips. 
sl@0
  1064
@publishedAll 
sl@0
  1065
@released
sl@0
  1066
*/
sl@0
  1067
EXPORT_C void CFbsBitmap::SetSizeInTwips(const TSize& aSizeInTwips)
sl@0
  1068
	{
sl@0
  1069
	if (!iHandle || (iFlags & EIsRomBitmap))
sl@0
  1070
		return;
sl@0
  1071
	iFbs->SetCallBackPtr(&iServerHandle);
sl@0
  1072
	iFbs->CallBack();
sl@0
  1073
	CleanAddress()->iHeader.iSizeInTwips = aSizeInTwips;
sl@0
  1074
	}
sl@0
  1075
sl@0
  1076
/** Externalises the bitmap to the specified stream. Not supported for extended bitmaps.
sl@0
  1077
@param aStream The write stream. 
sl@0
  1078
@publishedAll 
sl@0
  1079
@released
sl@0
  1080
*/
sl@0
  1081
EXPORT_C void CFbsBitmap::ExternalizeL(RWriteStream& aStream) const
sl@0
  1082
	{
sl@0
  1083
	if (!iHandle)
sl@0
  1084
		User::Leave(KErrGeneral);
sl@0
  1085
	BeginDataAccess();
sl@0
  1086
	Address()->ExternalizeL(aStream, *this);	
sl@0
  1087
	EndDataAccess(ETrue);
sl@0
  1088
	}
sl@0
  1089
sl@0
  1090
/** Externalises that area of the bitmap contained within a specified 
sl@0
  1091
rectangular area. Not supported for extended bitmaps.
sl@0
  1092
@param aStream The write stream
sl@0
  1093
@param aRect The rectangular area of the bitmap to externalise. The bitmap 
sl@0
  1094
that is externalized will be of this size. 
sl@0
  1095
@publishedAll 
sl@0
  1096
@released
sl@0
  1097
*/
sl@0
  1098
EXPORT_C void CFbsBitmap::ExternalizeRectangleL(RWriteStream& aStream,const TRect& aRect) const
sl@0
  1099
	{
sl@0
  1100
	if (!iHandle)
sl@0
  1101
		User::Leave(KErrGeneral);
sl@0
  1102
	BeginDataAccess();
sl@0
  1103
	Address()->ExternalizeRectangleL(aStream, aRect, *this);
sl@0
  1104
	EndDataAccess(ETrue);
sl@0
  1105
	}
sl@0
  1106
sl@0
  1107
/** Internalises a CFbsBitmap from a stream.
sl@0
  1108
@param aStream The read stream.
sl@0
  1109
@publishedAll 
sl@0
  1110
@released
sl@0
  1111
*/
sl@0
  1112
EXPORT_C void CFbsBitmap::InternalizeL(RReadStream& aStream)
sl@0
  1113
	{
sl@0
  1114
	if(!iFbs) User::Leave(KErrCouldNotConnect);
sl@0
  1115
	Reset();
sl@0
  1116
	SEpocBitmapHeader header;
sl@0
  1117
	CBitwiseBitmap::InternalizeHeaderL(aStream,header);
sl@0
  1118
sl@0
  1119
	TDisplayMode dispmode = CBitwiseBitmap::DisplayMode(header.iBitsPerPixel,header.iColor);
sl@0
  1120
	User::LeaveIfError(Create(header.iSizeInPixels,dispmode));
sl@0
  1121
sl@0
  1122
	TUint32* data;
sl@0
  1123
	CBitwiseBitmap* bmp=BeginDataAccessAndGetCleanAddress(data);
sl@0
  1124
	bmp->iHeader=header;
sl@0
  1125
	TInt bytesize = header.iBitmapSize - header.iStructSize;
sl@0
  1126
	if (bytesize > 0)
sl@0
  1127
		{
sl@0
  1128
		bmp->DoInternalizeL(aStream, bytesize, data);
sl@0
  1129
		EndDataAccess(EFalse);
sl@0
  1130
		}
sl@0
  1131
	else
sl@0
  1132
		{
sl@0
  1133
		EndDataAccess(ETrue);
sl@0
  1134
		}
sl@0
  1135
	}
sl@0
  1136
sl@0
  1137
EXPORT_C TInt CFbsBitmap::Compress()
sl@0
  1138
 	{
sl@0
  1139
	return Compress(ERLECompression);
sl@0
  1140
	}
sl@0
  1141
sl@0
  1142
/** Compresses bitmap in RAM.
sl@0
  1143
@param aScheme specifies preferred compression type ERLECompression or EPaletteCompression
sl@0
  1144
@return KErrNone on success, KErrGeneral if the bitmap handle is NULL, KErrAccessDenied if 
sl@0
  1145
the bitmap is in ROM or it is an extended bitmap, otherwise one of the system wide error codes. 
sl@0
  1146
@publishedAll 
sl@0
  1147
@released
sl@0
  1148
*/
sl@0
  1149
EXPORT_C TInt CFbsBitmap::Compress(TBitmapfileCompressionScheme aScheme)
sl@0
  1150
	{
sl@0
  1151
 	if (!iHandle)
sl@0
  1152
 		return KErrGeneral;
sl@0
  1153
 	if (iFlags & EIsReadOnlyBitmapMask)
sl@0
  1154
 		return KErrAccessDenied; 	
sl@0
  1155
	TPckgBuf<TBmpHandles> handlebuf;
sl@0
  1156
	TIpcArgs args(iHandle, aScheme, &handlebuf);
sl@0
  1157
	TInt err = iFbs->SendCommand(EFbsMessBitmapCompress, args);
sl@0
  1158
	if (err != KErrNone)
sl@0
  1159
		return err;
sl@0
  1160
	iHandle = handlebuf().iHandle;
sl@0
  1161
	iServerHandle = handlebuf().iServerHandle;
sl@0
  1162
	iAddressPointer = (CBitwiseBitmap*)(iFbs->HeapBase() + handlebuf().iAddressOffset);
sl@0
  1163
	return KErrNone;
sl@0
  1164
	}
sl@0
  1165
sl@0
  1166
/** Submits the bitmap for asynchronous background compression.
sl@0
  1167
@param aRequestStatus The request status which will be completed with the appropriate error code after the compression has finished
sl@0
  1168
The error code will be KErrNone on success, KErrGeneral if the bitmap handle is NULL, KErrAccessDenied if the
sl@0
  1169
bitmap is in ROM or it is an extended bitmap, otherwise one of the system wide error codes.
sl@0
  1170
@publishedAll 
sl@0
  1171
@released
sl@0
  1172
*/
sl@0
  1173
EXPORT_C void CFbsBitmap::CompressInBackground(TRequestStatus& aRequestStatus)
sl@0
  1174
	{
sl@0
  1175
	CompressInBackground(aRequestStatus, ERLECompression);
sl@0
  1176
	}
sl@0
  1177
sl@0
  1178
/** Submits the bitmap for asynchronous background compression. No notification will be provided when the compression has completed.
sl@0
  1179
@return KErrNone if the bitmap was successfully submitted to the background compression queue, KErrGeneral if the bitmap handle is NULL, 
sl@0
  1180
KErrAccessDenied if the bitmap is in ROM or it is an extended bitmap,  otherwise another of the system-wide error codes.
sl@0
  1181
@publishedAll 
sl@0
  1182
@released
sl@0
  1183
*/
sl@0
  1184
EXPORT_C TInt CFbsBitmap::CompressInBackground()
sl@0
  1185
	{
sl@0
  1186
	return CompressInBackground(ERLECompression);
sl@0
  1187
	}
sl@0
  1188
	
sl@0
  1189
/** Submits the bitmap for asynchronous background compression.
sl@0
  1190
@param aRequestStatus The request status which will be completed with the appropriate error code after the compression has finished.
sl@0
  1191
The error code will be KErrNone on success, KErrGeneral if the bitmap handle is NULL, KErrAccessDenied if the
sl@0
  1192
bitmap is in ROM or it is an extended bitmap, otherwise one of the system wide error codes.
sl@0
  1193
@param aScheme Specifies preferred compression type: ERLECompression or EPaletteCompression
sl@0
  1194
@publishedAll 
sl@0
  1195
@released
sl@0
  1196
*/
sl@0
  1197
EXPORT_C void CFbsBitmap::CompressInBackground(TRequestStatus& aRequestStatus, TBitmapfileCompressionScheme aScheme)
sl@0
  1198
	{
sl@0
  1199
	TRequestStatus* reqStat = &aRequestStatus;
sl@0
  1200
	aRequestStatus = KRequestPending;
sl@0
  1201
	if (!iHandle)
sl@0
  1202
		User::RequestComplete(reqStat, KErrGeneral);
sl@0
  1203
	else if (iFlags & EIsReadOnlyBitmapMask)
sl@0
  1204
		User::RequestComplete(reqStat, KErrAccessDenied);	
sl@0
  1205
	else
sl@0
  1206
		{
sl@0
  1207
		TIpcArgs args(iHandle, aScheme, ETrue);
sl@0
  1208
		iFbs->SendCommand(EFbsMessBitmapBgCompress, args, aRequestStatus);
sl@0
  1209
		}
sl@0
  1210
	}
sl@0
  1211
sl@0
  1212
/** Submits the bitmap for asynchronous background compression. No notification will be provided when the compression has completed.
sl@0
  1213
@return KErrNone if the bitmap was successfully submitted to the background compression queue, KErrGeneral if the bitmap handle is NULL, 
sl@0
  1214
KErrAccessDenied if the bitmap is in ROM or it is an extended bitmap, otherwise another of the system-wide error codes.
sl@0
  1215
@publishedAll 
sl@0
  1216
@released
sl@0
  1217
*/
sl@0
  1218
EXPORT_C TInt CFbsBitmap::CompressInBackground(TBitmapfileCompressionScheme aScheme)
sl@0
  1219
	{
sl@0
  1220
	if (!iHandle)
sl@0
  1221
		return KErrGeneral;
sl@0
  1222
	if (iFlags & EIsReadOnlyBitmapMask)
sl@0
  1223
		return KErrAccessDenied;	
sl@0
  1224
	TIpcArgs args(iHandle, aScheme, EFalse);
sl@0
  1225
	return iFbs->SendCommand(EFbsMessBitmapBgCompress, args);
sl@0
  1226
	}
sl@0
  1227
sl@0
  1228
/**Tests whether the bitmap located in RAM has been compressed.
sl@0
  1229
@return ETrue if the bitmap is compressed, EFalse otherwise.
sl@0
  1230
@publishedAll
sl@0
  1231
@released
sl@0
  1232
*/	
sl@0
  1233
EXPORT_C TBool CFbsBitmap::IsCompressedInRAM() const
sl@0
  1234
	{
sl@0
  1235
	CBitwiseBitmap* bitmap = CleanAddress();
sl@0
  1236
	if (bitmap==NULL)
sl@0
  1237
		{
sl@0
  1238
		return EFalse;
sl@0
  1239
		}	
sl@0
  1240
	return bitmap->IsCompressedInRAM();
sl@0
  1241
	}
sl@0
  1242
sl@0
  1243
/** Gets the twip-size of the bitmap.
sl@0
  1244
@return The size of the bitmap, in twips. 
sl@0
  1245
@publishedAll 
sl@0
  1246
@released
sl@0
  1247
*/
sl@0
  1248
EXPORT_C TSize CFbsBitmap::SizeInTwips() const
sl@0
  1249
	{
sl@0
  1250
    TSize zero;
sl@0
  1251
	if(iHandle==NULL) return(zero);
sl@0
  1252
	return CleanAddress()->SizeInTwips();
sl@0
  1253
	}
sl@0
  1254
sl@0
  1255
/** Converts a vertical dimension on the graphics device from pixels to twips.
sl@0
  1256
@param aPixels A vertical dimension on the graphics device in pixels. 
sl@0
  1257
@return A vertical dimension on the graphics device in twips. 
sl@0
  1258
@publishedAll 
sl@0
  1259
@released
sl@0
  1260
*/
sl@0
  1261
EXPORT_C TInt CFbsBitmap::VerticalPixelsToTwips(TInt aPixels) const
sl@0
  1262
	{
sl@0
  1263
	if(iHandle==NULL) return(0);
sl@0
  1264
	return CleanAddress()->VerticalPixelsToTwips(aPixels);
sl@0
  1265
	}
sl@0
  1266
sl@0
  1267
/** Converts a vertical dimension on the graphics device from twips to pixels.
sl@0
  1268
@param aTwips A vertical dimension on the graphics device in twips. 
sl@0
  1269
@return A vertical dimension on the graphics device in pixels. 
sl@0
  1270
@publishedAll 
sl@0
  1271
@released
sl@0
  1272
*/
sl@0
  1273
EXPORT_C TInt CFbsBitmap::VerticalTwipsToPixels(TInt aTwips) const
sl@0
  1274
	{
sl@0
  1275
	if(iHandle==NULL) return(0);
sl@0
  1276
	return CleanAddress()->VerticalTwipsToPixels(aTwips);
sl@0
  1277
	}
sl@0
  1278
sl@0
  1279
/** Tests whether or not the specified file is in ROM.
sl@0
  1280
@param aFilename The name of the file. 
sl@0
  1281
@param aWord On return, contains the address of the file in ROM. 
sl@0
  1282
@return ETrue if the file is in the ROM; EFalse otherwise. 
sl@0
  1283
@publishedAll 
sl@0
  1284
@released
sl@0
  1285
*/
sl@0
  1286
EXPORT_C TBool CFbsBitmap::IsFileInRom(const TDesC& aFilename,TUint32*& aWord)
sl@0
  1287
	{
sl@0
  1288
	RFbsSession* fbs=RFbsSession::GetSession();
sl@0
  1289
	__ASSERT_ALWAYS(fbs,Panic(EFbsPanicNoConnection));
sl@0
  1290
	return fbs->LookupBitmapInROM (aFilename, (TAny*&)aWord);
sl@0
  1291
	}
sl@0
  1292
sl@0
  1293
/** Tests whether or not the specified file is in ROM.
sl@0
  1294
@param aFile The file handle
sl@0
  1295
@param aWord On return, contains the address of the file in ROM. 
sl@0
  1296
@return ETrue if the file is in the ROM; EFalse otherwise. 
sl@0
  1297
@publishedAll 
sl@0
  1298
@released
sl@0
  1299
*/
sl@0
  1300
EXPORT_C TBool CFbsBitmap::IsFileInRom(RFile& aFile,TUint32*& aWord)
sl@0
  1301
	{
sl@0
  1302
	// cannot use rom lookup cache as filename is not available
sl@0
  1303
	// offset must be initialised to zero to indicate beginning of the file
sl@0
  1304
	aWord = 0;
sl@0
  1305
	return aFile.Seek(ESeekAddress,(TInt&)aWord)==KErrNone;
sl@0
  1306
	}
sl@0
  1307
	
sl@0
  1308
/** Tests whether or not the bitmap is monochrome.
sl@0
  1309
Monochrome bitmaps have a display-mode of 1 bit-per-pixel.
sl@0
  1310
@return ETrue if the bitmap is monochrome; EFalse otherwise. 
sl@0
  1311
@publishedAll 
sl@0
  1312
@released
sl@0
  1313
*/
sl@0
  1314
EXPORT_C TBool CFbsBitmap::IsMonochrome() const
sl@0
  1315
	{
sl@0
  1316
	if(!iHandle) return(EFalse);
sl@0
  1317
	TUint32* data;
sl@0
  1318
	CBitwiseBitmap* bmp = BeginDataAccessAndGetCleanAddress(data);
sl@0
  1319
	TBool isMonochrome = bmp->IsMonochrome(data);
sl@0
  1320
	EndDataAccess(ETrue);
sl@0
  1321
	return isMonochrome;
sl@0
  1322
	}
sl@0
  1323
sl@0
  1324
/** Marks the beginning of direct access to the bitmap data.
sl@0
  1325
This function prepares the bitmap for direct access to its pixel data
sl@0
  1326
and should be used before calling DataAddress(), otherwise performance
sl@0
  1327
may be degraded on certain platforms.
sl@0
  1328
Calls to BeginDataAccess() must be coupled with subsequent calls to EndDataAccess().
sl@0
  1329
sl@0
  1330
@publishedAll
sl@0
  1331
@released
sl@0
  1332
@see CFbsBitmap::DataAddress()
sl@0
  1333
@see CFbsBitmap::EndDataAccess()
sl@0
  1334
*/
sl@0
  1335
EXPORT_C void CFbsBitmap::BeginDataAccess() const
sl@0
  1336
	{
sl@0
  1337
    FBS_OST_VERBOSE(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_BEGINDATAACCESS_ENTRY, "> this=0x%08x;", (TUint)this););
sl@0
  1338
	FBS_OST_IF(!iHandle, OstTrace1(TRACE_ERROR, CFBSBITMAP_BEGINDATAACCESS_ERROR, "! this=0x%08x; !iHandle", (TUint)this););
sl@0
  1339
	
sl@0
  1340
	if (iHandle)
sl@0
  1341
	    {
sl@0
  1342
        (void)CleanAddress();	//called for side-effect to make sure bitmap reference is current. Should be low overhead.
sl@0
  1343
        const_cast<CFbsBitmap*>(this)->iUseCount++;
sl@0
  1344
	    }
sl@0
  1345
    
sl@0
  1346
	FBS_OST_VERBOSE(OstTraceExt2(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_BEGINDATAACCESS_EXIT, "< this=0x%08x; iUseCount=%d;", (TUint)this, const_cast<CFbsBitmap*>(this)->iUseCount);)
sl@0
  1347
	}
sl@0
  1348
sl@0
  1349
/** Marks the end of direct access to the bitmap data.
sl@0
  1350
Use this function after ending direct access to the bitmap data.
sl@0
  1351
Calls to EndDataAccess() must correspond to prior calls to BeginDataAccess().
sl@0
  1352
See BeginDataAccess() for more details.
sl@0
  1353
sl@0
  1354
@param aReadOnly Whether or not the bitmap data has only been read since
sl@0
  1355
                 the corresponding call to BeginDataAccess().
sl@0
  1356
sl@0
  1357
@publishedAll
sl@0
  1358
@released
sl@0
  1359
@param aReadOnly True if the bitmap data had only been read.  False if the data has been modified.
sl@0
  1360
@see CFbsBitmap::BeginDataAccess()
sl@0
  1361
*/
sl@0
  1362
EXPORT_C void CFbsBitmap::EndDataAccess(TBool aReadOnly) const
sl@0
  1363
	{
sl@0
  1364
    FBS_OST_VERBOSE(OstTraceExt2(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_ENDDATAACCESS_ENTRY, "> this=0x%08x; aReadOnly=%d;", (TUint)this, (TUint)aReadOnly);)
sl@0
  1365
    FBS_OST_IF(!iHandle, OstTrace1(TRACE_ERROR, CFBSBITMAP_ENDDATAACCESS_ERROR, "! this=0x%08x; !iHandle", (TUint)this););
sl@0
  1366
    if (iHandle)
sl@0
  1367
        {
sl@0
  1368
        const_cast<CFbsBitmap*>(this)->iUseCount--;
sl@0
  1369
        if (!aReadOnly && !(iFlags & EIsReadOnlyBitmapMask))
sl@0
  1370
            {
sl@0
  1371
            User::LockedInc(iAddressPointer->Extra()->iTouchCount);
sl@0
  1372
            }
sl@0
  1373
        }
sl@0
  1374
    FBS_OST_VERBOSE(OstTraceExt2(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_ENDDATAACCESS_EXIT, "< this=0x%08x; iUseCount=%d;", (TUint)this, const_cast<CFbsBitmap*>(this)->iUseCount);)
sl@0
  1375
	}
sl@0
  1376
sl@0
  1377
/** Locks the global bitmap heap.
sl@0
  1378
This function is deprecated, since it is no longer necessary to lock the global
sl@0
  1379
bitmap heap to prevent the pixel data from being moved in memory asynchronously,
sl@0
  1380
as the value returned by DataAddress() can now only change as a result of bitmap
sl@0
  1381
operations explicitly requested by clients of the Font and Bitmap Server.
sl@0
  1382
Calls to LockHeap() should be replaced by calls to BeginDataAccess().
sl@0
  1383
sl@0
  1384
Calls to LockHeap() must be coupled with subsequent calls to CFbsBitmap::UnlockHeap().
sl@0
  1385
Code called between a LockHeap() - UnlockHeap() pair must not include any other calls to
sl@0
  1386
CFbsBitmap methods, which internally may call CFbsBitmap::LockHeap(). Also, code must
sl@0
  1387
not leave between a LockHeap() - UnlockHeap() pair.
sl@0
  1388
@note	IMPORTANT: CFbsBitmap::LockHeap() cannot be used as a means of synchronization between
sl@0
  1389
threads concurrently accessing bitmap data.
sl@0
  1390
sl@0
  1391
@publishedAll 
sl@0
  1392
@deprecated
sl@0
  1393
@see CFbsBitmap::UnlockHeap()
sl@0
  1394
@see CFbsBitmap::BeginDataAccess()
sl@0
  1395
*/
sl@0
  1396
EXPORT_C void CFbsBitmap::LockHeap(TBool /*aAlways*/) const
sl@0
  1397
	{
sl@0
  1398
    FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_LOCKHEAP_ENTRY, "> this=0x%08x;", (TUint)this);)
sl@0
  1399
	BeginDataAccess();
sl@0
  1400
#ifdef SYMBIAN_DEBUG_FBS_LOCKHEAP
sl@0
  1401
	//These debug checks now refer to the cleaned data address
sl@0
  1402
    FBS_OST_IF(!iHandle, OstTrace1(TRACE_ERROR, CFBSBITMAP_LOCKHEAP_ERROR, "! this=0x%08x; !iHandle", (TUint)this););
sl@0
  1403
	if (iHandle && !(iFlags & EIsRomBitmap)) // can't do anything with ROM bitmaps
sl@0
  1404
		{
sl@0
  1405
		TThreadId threadId = RThread().Id();
sl@0
  1406
		iFbs->iHelper->iDebugMutex.Wait();
sl@0
  1407
		if (iAddressPointer->Extra()->iLockCount++ == 0)
sl@0
  1408
			{
sl@0
  1409
			__ASSERT_ALWAYS(iAddressPointer->Extra()->iThreadId == TThreadId(KNullThreadId), Panic(EFbsPanicBadHeapLock));
sl@0
  1410
			iAddressPointer->Extra()->iThreadId = threadId;
sl@0
  1411
			}
sl@0
  1412
		else
sl@0
  1413
			__ASSERT_ALWAYS(iAddressPointer->Extra()->iThreadId == threadId, Panic(EFbsPanicBadHeapLock));
sl@0
  1414
		iFbs->iHelper->iDebugMutex.Signal();
sl@0
  1415
		}
sl@0
  1416
#endif
sl@0
  1417
	FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_LOCKHEAP_EXIT, "< this=0x%08x;", (TUint)this);)
sl@0
  1418
	}
sl@0
  1419
sl@0
  1420
/** Unlocks the global heap. 
sl@0
  1421
This function is deprecated. See LockHeap() for more details.
sl@0
  1422
Calls to UnlockHeap() should be replaced by calls to EndDataAccess().
sl@0
  1423
Calls to UnlockHeap() must correspond to prior calls to LockHeap() or LockHeapLC().
sl@0
  1424
sl@0
  1425
@publishedAll 
sl@0
  1426
@deprecated
sl@0
  1427
@see CFbsBitmap::LockHeap()
sl@0
  1428
@see CFbsBitmap::EndDataAccess()
sl@0
  1429
*/
sl@0
  1430
EXPORT_C void CFbsBitmap::UnlockHeap(TBool /*aAlways*/) const
sl@0
  1431
	{
sl@0
  1432
    FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_UNLOCKHEAP_ENTRY, "> this=0x%08x;", (TUint)this);)
sl@0
  1433
    FBS_OST_IF(!iHandle, OstTrace1(TRACE_ERROR, CFBSBITMAP_UNLOCKHEAP_ERROR, "! this=0x%08x; !iHandle", (TUint)this););
sl@0
  1434
	if (iHandle)
sl@0
  1435
	    {
sl@0
  1436
#ifdef SYMBIAN_DEBUG_FBS_LOCKHEAP
sl@0
  1437
	    if (!(iFlags & EIsRomBitmap)) // can't do anything with ROM bitmaps
sl@0
  1438
            {
sl@0
  1439
            TThreadId threadId = RThread().Id();
sl@0
  1440
            iFbs->iHelper->iDebugMutex.Wait();
sl@0
  1441
            __ASSERT_ALWAYS(iAddressPointer->Extra()->iLockCount > 0, Panic(EFbsPanicBadHeapLock));
sl@0
  1442
            __ASSERT_ALWAYS(iAddressPointer->Extra()->iThreadId == threadId, Panic(EFbsPanicBadHeapLock));
sl@0
  1443
            if (--iAddressPointer->Extra()->iLockCount == 0)
sl@0
  1444
                iAddressPointer->Extra()->iThreadId = TThreadId(KNullThreadId);
sl@0
  1445
            iFbs->iHelper->iDebugMutex.Signal();
sl@0
  1446
            }
sl@0
  1447
#endif
sl@0
  1448
	    EndDataAccess();
sl@0
  1449
	    }
sl@0
  1450
	FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_UNLOCKHEAP_EXIT, "< this=0x%08x;", (TUint)this);)
sl@0
  1451
	}
sl@0
  1452
sl@0
  1453
/** Locks the global bitmap heap, leaving on the clean-up stack a pointer
sl@0
  1454
to a TCleanupItem that unlocks the heap on deletion.
sl@0
  1455
Use this function instead of LockHeap() if code may leave between the
sl@0
  1456
LockHeap() - UnlockHeap() pair. Calls to LockHeapLC() must be coupled with
sl@0
  1457
subsequent calls to CFbsBitmap::UnlockHeap() or CleanupStack::PopAndDestroy().
sl@0
  1458
This function is deprecated. See CFbsBitmap::LockHeap() for more details.
sl@0
  1459
sl@0
  1460
@publishedAll 
sl@0
  1461
@deprecated
sl@0
  1462
@see CFbsBitmap::LockHeap()
sl@0
  1463
*/
sl@0
  1464
EXPORT_C void CFbsBitmap::LockHeapLC(TBool /*aAlways*/) const
sl@0
  1465
	{
sl@0
  1466
    FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_LOCKHEAPLC_ENTRY, "> this=0x%08x;", (TUint)this);)
sl@0
  1467
    LockHeap();
sl@0
  1468
	TCleanupItem cleanitem(CFbsBitmap::UnlockHeap, (TAny*)this);
sl@0
  1469
	CleanupStack::PushL(cleanitem);
sl@0
  1470
	FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_LOCKHEAPLC_EXIT, "< this=0x%08x;", (TUint)this);)
sl@0
  1471
	}
sl@0
  1472
sl@0
  1473
EXPORT_C void CFbsBitmap::UnlockHeap(TAny* aFbsBitmap)
sl@0
  1474
	{
sl@0
  1475
    FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_UNLOCKHEAP2_ENTRY, "> bitmap=0x%08x;", (TUint)aFbsBitmap);)
sl@0
  1476
    ((CFbsBitmap*)aFbsBitmap)->UnlockHeap();
sl@0
  1477
    FBS_OST(OstTrace0(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_UNLOCKHEAP2_EXIT, "<");)
sl@0
  1478
	}
sl@0
  1479
sl@0
  1480
/** Tests whether the bitmap is volatile.
sl@0
  1481
A bitmap becomes volatile if CFbsBitmap::DataAdress() is called without
sl@0
  1482
CFbsBitmap::BeginDataAccess() having been called before and it can become non-volatile
sl@0
  1483
again if a resizing or compression is performed.
sl@0
  1484
sl@0
  1485
@internalTechnology
sl@0
  1486
@prototype
sl@0
  1487
*/
sl@0
  1488
EXPORT_C TBool CFbsBitmap::IsVolatile() const
sl@0
  1489
	{
sl@0
  1490
	if (!iHandle)
sl@0
  1491
		return EFalse;
sl@0
  1492
	return CleanAddress()->iSettings.IsVolatileBitmap();
sl@0
  1493
	}
sl@0
  1494
sl@0
  1495
/** Tests how many times the bitmap has been touched.
sl@0
  1496
A bitmap is touched whenever CFbsBitmap::EndDataAccess() is called with the parameter
sl@0
  1497
aReadOnly set to EFalse and also whenever a resizing or compression is performed.
sl@0
  1498
sl@0
  1499
@internalTechnology
sl@0
  1500
@prototype
sl@0
  1501
@return The number of times the bitmap has been touched.
sl@0
  1502
*/
sl@0
  1503
EXPORT_C TInt CFbsBitmap::TouchCount() const
sl@0
  1504
	{
sl@0
  1505
	if (!iHandle || (iFlags & EIsReadOnlyBitmapMask))
sl@0
  1506
		return 0; // A read-only bitmap can never be touched.
sl@0
  1507
	return CleanAddress()->Extra()->iTouchCount;
sl@0
  1508
	}
sl@0
  1509
sl@0
  1510
/** Returns the serial number of the bitmap
sl@0
  1511
The serial number is unique to this bitmap.
sl@0
  1512
The serial number is a signed 64-bit integer, with only the positive values being assigned.
sl@0
  1513
As ROM bitmaps do not have serial numbers, the serial number will use the negative range
sl@0
  1514
of values so that ROM bitmap's serial number cannot be the same as a RAM bitmap's.
sl@0
  1515
ROM bitmap's address pointers are unique to the ROM bitmap, so the serial number will just
sl@0
  1516
be negative value of the address pointer.
sl@0
  1517
sl@0
  1518
@internalTechnology
sl@0
  1519
@prototype
sl@0
  1520
@return The unique serial number for the bitmap
sl@0
  1521
*/
sl@0
  1522
EXPORT_C TInt64 CFbsBitmap::SerialNumber() const
sl@0
  1523
	{
sl@0
  1524
	if (!iHandle)
sl@0
  1525
		return 0;
sl@0
  1526
	if (iFlags & EIsRomBitmap)
sl@0
  1527
		return -TInt64(reinterpret_cast<TUint32>(iAddressPointer));
sl@0
  1528
	return CleanAddress()->Extra()->iSerialNumber;
sl@0
  1529
	}
sl@0
  1530
sl@0
  1531
/** Tests whether the bitmap is large.
sl@0
  1532
@return ETrue if the bitmap is large, EFalse if not. 
sl@0
  1533
@publishedAll 
sl@0
  1534
@released
sl@0
  1535
*/
sl@0
  1536
EXPORT_C TBool CFbsBitmap::IsLargeBitmap() const
sl@0
  1537
	{
sl@0
  1538
	CBitwiseBitmap* bitmap = CleanAddress();
sl@0
  1539
	if (!bitmap)
sl@0
  1540
		{
sl@0
  1541
		return EFalse;
sl@0
  1542
		}
sl@0
  1543
	return bitmap->IsLargeBitmap();
sl@0
  1544
	}
sl@0
  1545
sl@0
  1546
/** Returns the handle for the hardware bitmap which this CFbsBitmap is using.
sl@0
  1547
@return The handle to the hardware bitmap. The handle is NULL if it is not 
sl@0
  1548
a hardware bitmap. 
sl@0
  1549
@publishedAll 
sl@0
  1550
@released
sl@0
  1551
*/
sl@0
  1552
EXPORT_C TInt CFbsBitmap::HardwareBitmapHandle() const
sl@0
  1553
	{
sl@0
  1554
	CBitwiseBitmap* bitmap = CleanAddress();
sl@0
  1555
	if (!bitmap)
sl@0
  1556
		{
sl@0
  1557
		return 0;
sl@0
  1558
		}
sl@0
  1559
	return bitmap->HardwareBitmapHandle();
sl@0
  1560
	}
sl@0
  1561
sl@0
  1562
/** Gets the attributes of the bitmap's palette.
sl@0
  1563
This is not currently supported.
sl@0
  1564
@param aModifiable On return, whether or not the palette is modifiable. 
sl@0
  1565
@param aNumEntries On return, the number of entries in the palette. 
sl@0
  1566
@publishedAll 
sl@0
  1567
@released
sl@0
  1568
*/
sl@0
  1569
EXPORT_C void CFbsBitmap::PaletteAttributes(TBool& aModifiable,TInt& aNumEntries) const
sl@0
  1570
	{
sl@0
  1571
	aModifiable=EFalse;
sl@0
  1572
	aNumEntries=0;
sl@0
  1573
	}
sl@0
  1574
sl@0
  1575
/** Sets the bitmap's palette.
sl@0
  1576
This is not currently supported.
sl@0
  1577
@param aPalette Not used. 
sl@0
  1578
@publishedAll 
sl@0
  1579
@released
sl@0
  1580
*/
sl@0
  1581
EXPORT_C void CFbsBitmap::SetPalette(CPalette* /*aPalette*/)
sl@0
  1582
	{
sl@0
  1583
	}
sl@0
  1584
sl@0
  1585
/** Gets the bitmap's palette.
sl@0
  1586
This is not currently supported.
sl@0
  1587
@param aPalette Not used. 
sl@0
  1588
@return KErrNotSupported. 
sl@0
  1589
@publishedAll 
sl@0
  1590
@released
sl@0
  1591
*/
sl@0
  1592
EXPORT_C TInt CFbsBitmap::GetPalette(CPalette*& /*aPalette*/) const
sl@0
  1593
	{
sl@0
  1594
	return(KErrNotSupported);
sl@0
  1595
	}
sl@0
  1596
sl@0
  1597
/**
sl@0
  1598
@internalComponent
sl@0
  1599
This method loads a bitmap from an opened file handle.
sl@0
  1600
sl@0
  1601
@param  aFile mbm or rsc file handle (rsc file format: header + rsc
sl@0
  1602
	data section + mbm file section).
sl@0
  1603
@param  aId Bitmap ID - should be less than mbm file bitmaps count.
sl@0
  1604
@param  aShareIfLoaded Specifies whether or not the loaded bitmap will be
sl@0
  1605
    made available for sharing between FBSERV clients.
sl@0
  1606
@param  aFileOffset mbm file section offset into rsc file.
sl@0
  1607
@return KErrNone if successful, otherwise another
sl@0
  1608
            of the system-wide error codes.
sl@0
  1609
*/	
sl@0
  1610
TInt CFbsBitmap::DoLoad(RFile& aFile,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset)
sl@0
  1611
	{
sl@0
  1612
	TInt ret=KErrNone;
sl@0
  1613
	TPckgBuf<TBmpHandles> handlebuf;
sl@0
  1614
	TPckgBuf<TLoadBitmapArg> loadBitmapArg;
sl@0
  1615
	loadBitmapArg().iBitmapId = aId;
sl@0
  1616
	loadBitmapArg().iShareIfLoaded = TInt(aShareIfLoaded);
sl@0
  1617
	loadBitmapArg().iFileOffset = aFileOffset;
sl@0
  1618
	//Getting the RFs Handle(2) and RFile handle(3) into a TIpcArgs into 2nd and 3rd argument
sl@0
  1619
	TIpcArgs fileargs;
sl@0
  1620
	ret=aFile.TransferToServer(fileargs,2,3);
sl@0
  1621
	if (ret!=KErrNone)
sl@0
  1622
		return ret;	
sl@0
  1623
	fileargs.Set(0,&handlebuf);
sl@0
  1624
	fileargs.Set(1,&loadBitmapArg);
sl@0
  1625
	ret=iFbs->SendCommand(EFbsMessBitmapLoad,fileargs);
sl@0
  1626
	if(ret!=KErrNone) return(ret);
sl@0
  1627
	iHandle=handlebuf().iHandle;
sl@0
  1628
	iServerHandle=handlebuf().iServerHandle;
sl@0
  1629
	iAddressPointer=(CBitwiseBitmap*)(iFbs->HeapBase()+handlebuf().iAddressOffset);
sl@0
  1630
	ret = iFbs->iHelper->AddBitmap(*this);
sl@0
  1631
	if (ret != KErrNone)
sl@0
  1632
		return ret;
sl@0
  1633
	return iFbs->AllocScanLineBuffer(iAddressPointer->iByteWidth+4);
sl@0
  1634
	}
sl@0
  1635
sl@0
  1636
/**
sl@0
  1637
@internalComponent
sl@0
  1638
This method loads a bitmap from the mbm or rsc file specified by the filename.
sl@0
  1639
sl@0
  1640
@param  aFileName mbm or rsc file name (rsc file format: header + rsc
sl@0
  1641
	data section + mbm file section).
sl@0
  1642
@param  aId Bitmap ID - should be less than mbm file bitmaps count.
sl@0
  1643
@param  aShareIfLoaded Specifies whether or not the loaded bitmap will be
sl@0
  1644
    made available for sharing between FBSERV clients.
sl@0
  1645
@param  aFileOffset mbm file section offset into rsc file.
sl@0
  1646
@return KErrNone if successful, otherwise another
sl@0
  1647
            of the system-wide error codes.
sl@0
  1648
*/
sl@0
  1649
TInt CFbsBitmap::DoLoad(const TDesC& aFileName,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset)
sl@0
  1650
	{
sl@0
  1651
	TInt ret=KErrNone;
sl@0
  1652
	TPckgBuf<TBmpHandles> handlebuf;
sl@0
  1653
	TPckgBuf<TLoadBitmapArg> loadBitmapArg;
sl@0
  1654
	loadBitmapArg().iBitmapId = aId;
sl@0
  1655
	loadBitmapArg().iShareIfLoaded = TInt(aShareIfLoaded);
sl@0
  1656
	loadBitmapArg().iFileOffset = aFileOffset;
sl@0
  1657
	TIpcArgs fileargs;
sl@0
  1658
	fileargs.Set(0,&handlebuf);
sl@0
  1659
	fileargs.Set(1,&loadBitmapArg);
sl@0
  1660
	fileargs.Set(2,&aFileName);
sl@0
  1661
	ret=iFbs->SendCommand(EFbsMessBitmapLoadFast,fileargs);
sl@0
  1662
	if(ret!=KErrNone) return(ret);
sl@0
  1663
	iHandle=handlebuf().iHandle;
sl@0
  1664
	iServerHandle=handlebuf().iServerHandle;
sl@0
  1665
	iAddressPointer=(CBitwiseBitmap*)(iFbs->HeapBase()+handlebuf().iAddressOffset);
sl@0
  1666
	ret = iFbs->iHelper->AddBitmap(*this);
sl@0
  1667
	if (ret != KErrNone)
sl@0
  1668
		return ret;
sl@0
  1669
	return iFbs->AllocScanLineBuffer(iAddressPointer->iByteWidth+4);
sl@0
  1670
	}
sl@0
  1671
sl@0
  1672
/**
sl@0
  1673
@internalComponent
sl@0
  1674
This method handles very special case when the rsc file is in RAM, but it 
sl@0
  1675
contains ROM mbm file.  ROM mbm file format is different than RAM mbm file 
sl@0
  1676
format and ROM mbm file cannot be loaded into RAM using standard techniques 
sl@0
  1677
(used by CFbsBitmap::DoLoad()). We have to check it is really a ROM mbm file. 
sl@0
  1678
If it is - we have to allocate the right amount of RAM, read and copy 
sl@0
  1679
requested ROM bitmap to the allocated RAM.
sl@0
  1680
sl@0
  1681
@leave KErrNotSupported if this is a RAM rsc file with ROM mbm file section, 
sl@0
  1682
	or any of the RFile related error codes.
sl@0
  1683
@param aFileName rsc file name (rsc file format: header + rsc data section + 
sl@0
  1684
	mbm file section).
sl@0
  1685
@param  aId Bitmap ID - should be less than mbm file bitmaps count.
sl@0
  1686
@param aFileOffset mbm file section offset into rsc file.
sl@0
  1687
@return EFalse - this is not a ROM mbm file. ETrue - this is a ROM mbm file 
sl@0
  1688
			and	requested by aId bitmmap is loaded.
sl@0
  1689
*/	
sl@0
  1690
TBool CFbsBitmap::LoadShiftedRomBmpL(const TDesC& aFileName, TInt32 aId, TUint aFileOffset)
sl@0
  1691
	{
sl@0
  1692
	RFile mbm_file;
sl@0
  1693
	::CleanupClosePushL(mbm_file);
sl@0
  1694
	User::LeaveIfError(mbm_file.Open(iFbs->FileServer(), aFileName, EFileRead | EFileShareReadersOnly));
sl@0
  1695
	TInt pos = static_cast <TInt> (aFileOffset);
sl@0
  1696
	User::LeaveIfError(mbm_file.Seek(ESeekStart, pos));//move to the beginning of the mbm file section
sl@0
  1697
	TBuf8<sizeof(CBitwiseBitmap)> buf;
sl@0
  1698
	//Check if it is a ROM mbm file
sl@0
  1699
	User::LeaveIfError(mbm_file.Read(buf, sizeof(KMultiBitmapRomImageUid.iUid)));//Bitmap file UID - ROM or RAM
sl@0
  1700
	TInt32 mbm_uid = *(reinterpret_cast <const TInt32*> (buf.Ptr())); 
sl@0
  1701
	TBool loaded = EFalse;
sl@0
  1702
	if(mbm_uid == KMultiBitmapRomImageUid.iUid)
sl@0
  1703
		{
sl@0
  1704
		if(!KRomMBMInRamRSC)
sl@0
  1705
			{
sl@0
  1706
			User::Leave(KErrNotSupported);
sl@0
  1707
			}
sl@0
  1708
		else
sl@0
  1709
			{
sl@0
  1710
			User::LeaveIfError(mbm_file.Read(buf, sizeof(TInt32)));//Number of bitmaps
sl@0
  1711
			TInt32 bmp_cnt = *(reinterpret_cast <const TInt32*> (buf.Ptr()));  
sl@0
  1712
			if(aId >= bmp_cnt) 
sl@0
  1713
				{
sl@0
  1714
				User::Leave(KErrNotFound);
sl@0
  1715
				}
sl@0
  1716
			for(TInt i=0;i<aId;i++) //Read bitmap UIDs located before aId.
sl@0
  1717
				{
sl@0
  1718
				User::LeaveIfError(mbm_file.Read(buf, sizeof(aId)));
sl@0
  1719
				}
sl@0
  1720
			User::LeaveIfError(mbm_file.Read(buf, sizeof(TInt32)));//Read the offset of aId bitmap.
sl@0
  1721
			TInt bmp_offset = *(reinterpret_cast <const TInt32*> (buf.Ptr())) + TInt(aFileOffset); 
sl@0
  1722
			pos = static_cast <TInt> (bmp_offset);
sl@0
  1723
			User::LeaveIfError(mbm_file.Seek(ESeekStart, pos));//move the file pointer to the bitmap
sl@0
  1724
			User::LeaveIfError(mbm_file.Read(buf, sizeof(CBitwiseBitmap)));//Read CBitwiseBitmap data (without the bitmap data)
sl@0
  1725
			const CBitwiseBitmap* bmp = reinterpret_cast <const CBitwiseBitmap*> (buf.Ptr());
sl@0
  1726
			//Calculate bitmap data size, alocate enough memory for the bitmap, copy CBitwiseBitmap
sl@0
  1727
			//members first, read the bitmap data from the file, copy the data to the allocated memory,
sl@0
  1728
			//initialize iRomPointer.
sl@0
  1729
			//If sizeof(CBitwiseBitmap) != real size of CBitwiseBitmap then we could have problems,
sl@0
  1730
			//because bitmap data won't be copied at the right position.
sl@0
  1731
			TInt size = bmp->iHeader.iBitmapSize - sizeof(SEpocBitmapHeader) + sizeof(CBitwiseBitmap);
sl@0
  1732
			TUint8* bmp_mem = new (ELeave) TUint8[size];
sl@0
  1733
			//There is no need bmp_mem to be aligned, because it is a pointer to a RAM block of memory.
sl@0
  1734
			TCleanupItem cleanitem(FreeMem, bmp_mem);
sl@0
  1735
			CleanupStack::PushL(cleanitem);
sl@0
  1736
			Mem::Copy(bmp_mem, bmp, sizeof(CBitwiseBitmap));
sl@0
  1737
			TPtr8 pbmp(bmp_mem + sizeof(CBitwiseBitmap), size - sizeof(CBitwiseBitmap));
sl@0
  1738
			User::LeaveIfError(mbm_file.Read(pbmp, size - sizeof(CBitwiseBitmap)));//read the bitmap data. We've already read the CBitwiseBitmap data.
sl@0
  1739
			CleanupStack::Pop(bmp_mem);
sl@0
  1740
			iAddressPointer = reinterpret_cast<CBitwiseBitmap*>(bmp_mem);
sl@0
  1741
			iFlags = EIsRomBitmap;
sl@0
  1742
			iHandle = 1;
sl@0
  1743
			loaded = ETrue;
sl@0
  1744
			}//end of - if(!KRomMBMInRamRSC) - "else" part
sl@0
  1745
		}//end of - if(mbm_uid == KMultiBitmapRomImageUid.iUid)
sl@0
  1746
	CleanupStack::PopAndDestroy();//mbm_file
sl@0
  1747
	return loaded;
sl@0
  1748
	}
sl@0
  1749
sl@0
  1750
/**
sl@0
  1751
Swaps the bitmap's width and height.
sl@0
  1752
For example, if the bitmap's size is (40, 20), the new size will be (20, 40).
sl@0
  1753
Bitmap content is not preserved.
sl@0
  1754
@publishedAll
sl@0
  1755
@released
sl@0
  1756
@return KErrNone if the call was successful, KErrGeneral if the bitmap handle is 
sl@0
  1757
invalid, KErrAccessDenied if the bitmap is in ROM, KErrNotSupported if the bitmap
sl@0
  1758
is a hardware bitmap or an extended bitmap.
sl@0
  1759
*/
sl@0
  1760
EXPORT_C TInt CFbsBitmap::SwapWidthAndHeight()
sl@0
  1761
	{
sl@0
  1762
	if(!iHandle) 
sl@0
  1763
		{
sl@0
  1764
		return KErrGeneral;
sl@0
  1765
		}	
sl@0
  1766
	TUint32* data;
sl@0
  1767
	CBitwiseBitmap* bmp = BeginDataAccessAndGetCleanAddress(data);
sl@0
  1768
sl@0
  1769
	// Check the new bitmap size here then decide whether to swap the bitmap on the 
sl@0
  1770
	// client side or send it to be done on the server and reallocate memory for it.
sl@0
  1771
	TInt newWidthInBytes = CBitwiseBitmap::ByteWidth(bmp->iHeader.iSizeInPixels.iHeight, bmp->iSettings.CurrentDisplayMode());
sl@0
  1772
	TInt64 hugeDataSize = TInt64(bmp->iHeader.iSizeInPixels.iWidth) * TInt64(newWidthInBytes);
sl@0
  1773
sl@0
  1774
	TInt err = KErrNone;
sl@0
  1775
	// If the size of the new swapped bitmap is less than or equal its original size before the swap,
sl@0
  1776
	// then we do not need to reallocate memory. The swapping is straight forward.
sl@0
  1777
	if( I64HIGH(hugeDataSize) == 0 && I64LOW(hugeDataSize) <= TUint(bmp->iHeader.iBitmapSize - bmp->iHeader.iStructSize) )	
sl@0
  1778
		{
sl@0
  1779
		err = bmp->SwapWidthAndHeight(data);
sl@0
  1780
		// Even though used DataAddress() as read-only, need to increment touch count, so indicate that data has been written
sl@0
  1781
		EndDataAccess(EFalse);
sl@0
  1782
		}
sl@0
  1783
	// Otherwise we need to reallocate memory. We do this by using the already exisitng 
sl@0
  1784
	// Resize() function as a work around- Code Reusability!!
sl@0
  1785
	else
sl@0
  1786
		{
sl@0
  1787
		EndDataAccess(ETrue); // Used DataAddress() to read only.
sl@0
  1788
		// Resize will increase touch counter
sl@0
  1789
		err = Resize(TSize(bmp->iHeader.iSizeInPixels.iHeight, bmp->iHeader.iSizeInPixels.iWidth));
sl@0
  1790
		}
sl@0
  1791
	return err;
sl@0
  1792
	}
sl@0
  1793
	
sl@0
  1794
/** Gets a pointer to the decompression buffer owned by this thread's FBServ session.
sl@0
  1795
@param aSize The size in bytes of the scan lines to decompress.
sl@0
  1796
@return A pointer to the decompression buffer or NULL if there is no FBServ session.
sl@0
  1797
@internalTechnology
sl@0
  1798
@released
sl@0
  1799
*/
sl@0
  1800
EXPORT_C HBufC8* CFbsBitmap::GetDecompressionBuffer(TInt aSize)
sl@0
  1801
	{
sl@0
  1802
		RFbsSession* ses=RFbsSession::GetSession();
sl@0
  1803
		return ses? ses->GetDecompressionBuffer(aSize) : NULL;
sl@0
  1804
	}
sl@0
  1805
sl@0
  1806
/** Gets a pointer to the rasterizer for extended bitmaps if present.
sl@0
  1807
@return A pointer to the rasterizer owned by this thread's FBServ session.
sl@0
  1808
@return NULL if the rasterizer is not present.
sl@0
  1809
@internalTechnology
sl@0
  1810
@prototype
sl@0
  1811
*/
sl@0
  1812
EXPORT_C CFbsRasterizer* CFbsBitmap::Rasterizer()
sl@0
  1813
	{
sl@0
  1814
	RFbsSession* session = RFbsSession::GetSession();
sl@0
  1815
	return session ? session->iHelper->Rasterizer() : NULL;
sl@0
  1816
	}
sl@0
  1817
sl@0
  1818
/** Loads a specific bitmap from an opened multi-bitmap file handle.
sl@0
  1819
The bitmap may be shared by other font and bitmap server clients.
sl@0
  1820
@param aFile The handle of the multi-bitmap (.mbm) file. 
sl@0
  1821
@param aId The bitmap identifier.
sl@0
  1822
@param aShareIfLoaded Specifies whether or not the loaded bitmap will be made 
sl@0
  1823
available for sharing between font and bitmap server clients. 
sl@0
  1824
@return KErrNone if successful, otherwise another of the system error 
sl@0
  1825
codes. 
sl@0
  1826
@publishedAll
sl@0
  1827
@released
sl@0
  1828
*/	
sl@0
  1829
EXPORT_C TInt CFbsBitmap::Load(RFile& aFile,TInt32 aId/*=0*/,TBool aShareIfLoaded/*=ETrue*/)
sl@0
  1830
	{
sl@0
  1831
    FBS_OST(TFullName fileName;)
sl@0
  1832
    FBS_OST(aFile.FullName(fileName);)
sl@0
  1833
    FBS_OST(OstTraceExt4( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOAD3_ENTRY, "> this=0x%08x; file=%S; id=0x%08x; share=%d", (TUint)this, fileName, aId, aShareIfLoaded);)
sl@0
  1834
	TInt ret = Load(aFile,aId,aShareIfLoaded,0);
sl@0
  1835
    FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOAD3_EXIT, "< this=0x%08x, ret=%d", (TUint)this, ret);) 
sl@0
  1836
	return ret;
sl@0
  1837
	}
sl@0
  1838
sl@0
  1839
/** Loads a specific bitmap from an opened multi-bitmap file handle.
sl@0
  1840
The bitmap may be shared by other font and bitmap server clients.
sl@0
  1841
@param aFile The handle of the multi-bitmap (.mbm) file. 
sl@0
  1842
@param aId The bitmap identifier.
sl@0
  1843
@param aShareIfLoaded  Specifies whether or not the loaded bitmap will be made 
sl@0
  1844
available for sharing between FBSERV clients.
sl@0
  1845
@param aFileOffset Bitmap file section offset within the file.
sl@0
  1846
@return KErrNone if successful, otherwise another of the system error codes.
sl@0
  1847
@publishedAll
sl@0
  1848
@released
sl@0
  1849
*/	
sl@0
  1850
EXPORT_C TInt CFbsBitmap::Load(RFile& aFile,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset)
sl@0
  1851
	{
sl@0
  1852
    TInt err = KErrNone;
sl@0
  1853
    FBS_OST(TFullName fileName;)
sl@0
  1854
    FBS_OST(aFile.FullName(fileName);)
sl@0
  1855
    FBS_OST(OstTraceExt5( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOAD4_ENTRY, "> this=0x%08x; file=%S; id=0x%08x; share=%d; off=%d", (TUint)this, fileName, aId, aShareIfLoaded, aFileOffset);)
sl@0
  1856
	if (!iFbs)
sl@0
  1857
		{
sl@0
  1858
        FBS_OST(OstTrace1( TRACE_ERROR, CFBSBITMAP_LOAD4_ERROR, "! this=0x%08x; !iFbs", (TUint)this);)
sl@0
  1859
		err = KErrCouldNotConnect;
sl@0
  1860
		}
sl@0
  1861
	else
sl@0
  1862
	    {
sl@0
  1863
        Reset();
sl@0
  1864
        TUint32* rompointer;
sl@0
  1865
        IsFileInRom(aFile,rompointer);
sl@0
  1866
        TBool romPointerValid;
sl@0
  1867
        err = DoLoadFromRom(rompointer, aId, aFileOffset, romPointerValid);
sl@0
  1868
        if (!romPointerValid)
sl@0
  1869
            {
sl@0
  1870
            err = DoLoad(aFile,aId,aShareIfLoaded,aFileOffset);
sl@0
  1871
            FBS_OST_IF(err!=KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_LOAD4_ERROR2, "! this=0x%08x; DoLoad() returned %d", (TUint)this, err);)
sl@0
  1872
            }
sl@0
  1873
	    }
sl@0
  1874
	FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOAD4_EXIT, "< this=0x%08x; err=%d", (TUint)this, err);)
sl@0
  1875
	return err;
sl@0
  1876
	}
sl@0
  1877
sl@0
  1878
/** Loads and compresses a specific bitmap from an opened multi-bitmap file handle.
sl@0
  1879
The bitmap may be shared by other font and bitmap server clients.
sl@0
  1880
If the bitmap is loaded from ROM then compression is not allowed.
sl@0
  1881
@param aFile The handle of the multi-bitmap (.mbm) file. 
sl@0
  1882
@param aId The bitmap identifier.
sl@0
  1883
@param aShareIfLoaded Specifies whether or not the loaded bitmap will be
sl@0
  1884
made available for sharing between FBSERV clients.
sl@0
  1885
@return KErrNone if successful, otherwise another of the system-wide error 
sl@0
  1886
codes. 
sl@0
  1887
@publishedAll 
sl@0
  1888
@released
sl@0
  1889
*/	
sl@0
  1890
EXPORT_C TInt CFbsBitmap::LoadAndCompress(RFile& aFile,TInt32 aId/*=0*/,TBool aShareIfLoaded/*=ETrue*/)
sl@0
  1891
	{
sl@0
  1892
    FBS_OST(TFullName fileName;)
sl@0
  1893
    FBS_OST(aFile.FullName(fileName);)
sl@0
  1894
    FBS_OST(OstTraceExt4( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOADANDCOMPRESS3_ENTRY, "> this=0x%08x; file=%S; id=0x%08x; share=%d", (TUint)this, fileName, aId, aShareIfLoaded);)      
sl@0
  1895
	TInt ret = LoadAndCompress(aFile,aId,aShareIfLoaded,0);
sl@0
  1896
    FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOADANDCOMPRESS3_EXIT, "< this=0x%08x; ret=%d", (TUint)this, ret);)
sl@0
  1897
    return ret;
sl@0
  1898
	}
sl@0
  1899
sl@0
  1900
/** Loads and compresses a specific bitmap from an opened multi-bitmap file handle.
sl@0
  1901
The bitmap may be shared by other font and bitmap server clients. If the 
sl@0
  1902
bitmap is loaded from ROM then compression is not allowed.
sl@0
  1903
@param aFile The handle of the multi-bitmap (.mbm) file. 
sl@0
  1904
@param aId The bitmap identifier.
sl@0
  1905
@param aShareIfLoaded Specifies whether or not the loaded bitmap will be made 
sl@0
  1906
available for sharing between FBSERV clients.
sl@0
  1907
@param aFileOffset Bitmap file section offset within the file.
sl@0
  1908
@return KErrNone if successful, otherwise another of the system-wide error 
sl@0
  1909
codes. 
sl@0
  1910
@publishedAll 
sl@0
  1911
@released
sl@0
  1912
*/	
sl@0
  1913
EXPORT_C TInt CFbsBitmap::LoadAndCompress(RFile& aFile,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset)
sl@0
  1914
	{
sl@0
  1915
    FBS_OST(TFullName fileName;)
sl@0
  1916
    FBS_OST(aFile.FullName(fileName);)
sl@0
  1917
    FBS_OST(OstTraceExt4( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOADANDCOMPRESS4_ENTRY, "> this=0x%08x; file=%S; id=0x%08x; share=%d", (TUint)this, fileName, aId, aShareIfLoaded);)
sl@0
  1918
	TInt err = Load(aFile,aId,aShareIfLoaded,aFileOffset);
sl@0
  1919
	if (err == KErrNone)
sl@0
  1920
		{
sl@0
  1921
        if (!(iFlags & EIsRomBitmap))
sl@0
  1922
            {
sl@0
  1923
            err = Compress();
sl@0
  1924
            FBS_OST_IF(err!=KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_LOADANDCOMPRESS4_ERROR, "! this=0x%08x; Compress() returned %d", (TUint)this, err);)
sl@0
  1925
            }
sl@0
  1926
        else
sl@0
  1927
            {
sl@0
  1928
            err = KErrAccessDenied;
sl@0
  1929
            FBS_OST(OstTraceExt2( TRACE_ERROR, CFBSBITMAP_LOADANDCOMPRESS4_ERROR2, "! this=0x%08x; Cannot compress bitmap in ROM; iFlags=0x%08x", (TUint)this, (TUint)iFlags);)
sl@0
  1930
            }
sl@0
  1931
		}
sl@0
  1932
	FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOADANDCOMPRESS4_EXIT, "< this=0x%08x; err=%d", (TUint)this, err);)
sl@0
  1933
	return err;
sl@0
  1934
	}
sl@0
  1935
sl@0
  1936
/** Gets all the bitmap handles for all the bitmaps stored in the Font Bitmap Server. There is a limit of
sl@0
  1937
the number of bitmaps that can be retrieved defined by KMaxBitmapHandleBufferSize. If this limit has been
sl@0
  1938
reached then KErrOverflow will be returned.
sl@0
  1939
@param aBitmapIdArray returns an array of all the bitmap handles
sl@0
  1940
@return KErrNone if successful, KErrOverflow if the bitmapBuffer is not large enough to store 
sl@0
  1941
all the bitmap handles, otherwise another of the system-wide error codes. 
sl@0
  1942
@capability ReadDeviceData
sl@0
  1943
@internalComponent
sl@0
  1944
@released
sl@0
  1945
*/	
sl@0
  1946
EXPORT_C TInt CFbsBitmap::GetAllBitmapHandles(RArray<TInt>& aBitmapIdArray) const
sl@0
  1947
	{
sl@0
  1948
	RBuf8 bitmapBuffer;
sl@0
  1949
	TInt ret = bitmapBuffer.Create(KMaxBitmapHandleBufferSize);
sl@0
  1950
	if (ret==KErrNone)
sl@0
  1951
		{
sl@0
  1952
		TIpcArgs args(&bitmapBuffer);
sl@0
  1953
		ret=iFbs->SendCommand(EFbsGetAllBitmapHandles, args);
sl@0
  1954
		if (ret==KErrNone)
sl@0
  1955
			{
sl@0
  1956
			// Convert data returned from server and place into the RArray (aBitmapIdArray)
sl@0
  1957
			aBitmapIdArray.Reset();
sl@0
  1958
			TInt* bitmapIdPtr = (TInt*)bitmapBuffer.Ptr();
sl@0
  1959
			const TInt numBitmapIds = bitmapBuffer.Size() / KNumBytesPerBitmapHandle; // Divide by number of bytes per bitmap handle to get total number of bitmap IDs
sl@0
  1960
			for (TInt count=0; count<numBitmapIds; ++count)
sl@0
  1961
				{
sl@0
  1962
				TInt bitmapId = *bitmapIdPtr++;
sl@0
  1963
				ret = aBitmapIdArray.Append(bitmapId);
sl@0
  1964
				if (ret!=KErrNone)
sl@0
  1965
					break;
sl@0
  1966
				}
sl@0
  1967
			}
sl@0
  1968
		}
sl@0
  1969
	bitmapBuffer.Close();
sl@0
  1970
	return ret;
sl@0
  1971
	}
sl@0
  1972
sl@0
  1973
/**
sl@0
  1974
@internalComponent
sl@0
  1975
This method tries to load a bitmap if mbm or rsc file is in ROM.
sl@0
  1976
sl@0
  1977
@param  aRomPointer the address of the file in ROM
sl@0
  1978
@param  aId a Bitmap ID which should be less than mbm file bitmaps count.
sl@0
  1979
@param  aFileOffset mbm file section offset into rsc file.
sl@0
  1980
@param  aRomPointerValid on output it is set to ETrue if aRomPointer points to a valid ROM file or EFalse otherwise.
sl@0
  1981
@return KErrNone if successful, otherwise another of the system-wide error codes.
sl@0
  1982
*/
sl@0
  1983
TInt CFbsBitmap::DoLoadFromRom(TUint32* aRomPointer, TInt32 aId, TUint aFileOffset, TBool& aRomPointerValid)
sl@0
  1984
	{
sl@0
  1985
	aRomPointerValid = ETrue;
sl@0
  1986
	if(aRomPointer)
sl@0
  1987
		{
sl@0
  1988
		TUint8* temp = reinterpret_cast <TUint8*> (aRomPointer);
sl@0
  1989
		__ASSERT_DEBUG(!(TUint(temp) & 0x00000003),Panic(EFbsBitmapAlignment));
sl@0
  1990
		temp += aFileOffset;
sl@0
  1991
		aRomPointer = reinterpret_cast <TUint32*> (temp);
sl@0
  1992
		if(TInt32(*aRomPointer)==KMultiBitmapRomImageUid.iUid)
sl@0
  1993
			{
sl@0
  1994
			TInt numbitmaps = (TInt)*(aRomPointer+1);
sl@0
  1995
			if(aId>=numbitmaps)
sl@0
  1996
				{
sl@0
  1997
				return(KErrEof);
sl@0
  1998
				}
sl@0
  1999
			TInt offset = *(aRomPointer+aId+2);
sl@0
  2000
			iAddressPointer = (CBitwiseBitmap*)(((TUint8*)aRomPointer) + offset);
sl@0
  2001
			iFlags = EIsRomBitmap;
sl@0
  2002
			iHandle = 1;
sl@0
  2003
			return iFbs->AllocScanLineBuffer(iAddressPointer->iByteWidth + 4);
sl@0
  2004
			}
sl@0
  2005
		}
sl@0
  2006
	aRomPointerValid = EFalse;
sl@0
  2007
	return KErrNone;
sl@0
  2008
	}
sl@0
  2009
sl@0
  2010
sl@0
  2011
/**
sl@0
  2012
Creates an extended bitmap. Extended bitmaps are used to store immutable
sl@0
  2013
data in a platform-specific format. They cannot be used as targets of
sl@0
  2014
graphics contexts, and modification of their data via DataAddress() or
sl@0
  2015
TBitmapUtil is not supported and results in undefined behaviour up to
sl@0
  2016
and including process termination.
sl@0
  2017
sl@0
  2018
Initialisation of the raw data of the new bitmap is carried out by copying 
sl@0
  2019
the data pointed to by the parameter aData.
sl@0
  2020
sl@0
  2021
Read-only access to the raw data of an extended bitmap is provided by
sl@0
  2022
DataAddress() and DataSize() in conjunction with BeginDataAccess() and
sl@0
  2023
EndDataAccess().
sl@0
  2024
sl@0
  2025
Extended bitmaps have a conceptual size in pixels and a conceptual
sl@0
  2026
display mode for compatibility purposes. The raw data can be independent
sl@0
  2027
of these properties.
sl@0
  2028
sl@0
  2029
@param aSizeInPixels The conceptual width and height of the new bitmap in pixels.
sl@0
  2030
@param aDispMode The conceptual display mode of the new bitmap.
sl@0
  2031
@param aType The UID identifying the data format of the new bitmap. Used by the
sl@0
  2032
             extended bitmap rasterizer to distinguish between different data types.
sl@0
  2033
@param aData A pointer to the raw data to be stored in the new bitmap.
sl@0
  2034
@param aDataSize The size in bytes of the raw data to be stored in the new bitmap.
sl@0
  2035
@return KErrNone if successful; KErrArgument if the width or height specified in
sl@0
  2036
aSizeInPixels is negative, aDispMode is an invalid display mode, aData is NULL,
sl@0
  2037
aDataSize is negative or zero, or aDataType is a UID reserved for OS use; KErrTooBig
sl@0
  2038
if the width or height specified in aSizeInPixels exceeds KMaxTInt/4, or aDataSize
sl@0
  2039
exceeds KMaxTInt/2; otherwise another of the system-wide error codes.
sl@0
  2040
@publishedPartner
sl@0
  2041
@prototype
sl@0
  2042
@see CFbsBitmap::DataAddress()
sl@0
  2043
@see CFbsBitmap::DataSize()
sl@0
  2044
@see CFbsBitmap::BeginDataAccess()
sl@0
  2045
@see CFbsBitmap::EndDataAccess()
sl@0
  2046
*/
sl@0
  2047
EXPORT_C TInt CFbsBitmap::CreateExtendedBitmap(const TSize& aSizeInPixels, TDisplayMode aDispMode, TUid aType, const TAny* aData, TInt aDataSize)
sl@0
  2048
	{
sl@0
  2049
    TInt err;
sl@0
  2050
    FBS_OST(OstTraceExt5( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_CREATEEXTENDEDBITMAP_ENTRY, "> this=0x%08x; w=%d; h=%d; dm=%d; type=0x%08x", (TUint)this, aSizeInPixels.iWidth, aSizeInPixels.iHeight, aDispMode, aType.iUid);)
sl@0
  2051
	if (!aData || aDataSize == 0)
sl@0
  2052
		{
sl@0
  2053
        FBS_OST(OstTrace1( TRACE_ERROR, CFBSBITMAP_CREATEEXTENDEDBITMAP_ERROR, "! this=0x%08x; (!aData || aDataSize == 0)", (TUint)this);)
sl@0
  2054
		err = KErrArgument;
sl@0
  2055
		}
sl@0
  2056
	else
sl@0
  2057
	    {
sl@0
  2058
        err = DoCreate(aSizeInPixels, aDispMode, aType, aDataSize);
sl@0
  2059
        if (err == KErrNone)
sl@0
  2060
            {
sl@0
  2061
            Mem::Copy(iFbs->iLargeBitmapChunk.Base() + iAddressPointer->iDataOffset, aData, aDataSize);
sl@0
  2062
            }
sl@0
  2063
	    }
sl@0
  2064
	FBS_OST(OstTraceExt4( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_CREATEEXTENDEDBITMAP_EXIT, "< this=0x%08x; err=%d; iH=0x%08x; iSH=0x%08x", (TUint)this, err, iHandle, iServerHandle);)
sl@0
  2065
	return err;
sl@0
  2066
	}
sl@0
  2067
sl@0
  2068
/**
sl@0
  2069
Creates an extended bitmap. Extended bitmaps are used to store immutable
sl@0
  2070
data in a platform-specific format. They cannot be used as targets of
sl@0
  2071
graphics contexts, and modification of their data via DataAddress() or
sl@0
  2072
TBitmapUtil is not supported and results in undefined behaviour up to
sl@0
  2073
and including process termination.
sl@0
  2074
sl@0
  2075
Initialisation of the raw data of the new bitmap is carried out by a 
sl@0
  2076
callback to the MFbsExtendedBitmapInitializer::InitExtendedBitmap() 
sl@0
  2077
function passed through the parameter aInitializer.
sl@0
  2078
sl@0
  2079
Read-only access to the raw data of an extended bitmap is provided by
sl@0
  2080
DataAddress() and DataSize() in conjunction with BeginDataAccess() and
sl@0
  2081
EndDataAccess().
sl@0
  2082
sl@0
  2083
Extended bitmaps have a conceptual size in pixels and a conceptual
sl@0
  2084
display mode for compatibility purposes. The raw data can be independent
sl@0
  2085
of these properties.
sl@0
  2086
sl@0
  2087
@param aSizeInPixels The conceptual width and height of the new bitmap in pixels.
sl@0
  2088
@param aDispMode The conceptual display mode of the new bitmap.
sl@0
  2089
@param aType The UID identifying the data format of the new bitmap. Used by the
sl@0
  2090
             extended bitmap rasterizer to distinguish between different data types.
sl@0
  2091
@param aDataSize The size in bytes of the raw data to be stored in the new bitmap.
sl@0
  2092
@param aInitializer A reference to the initializer of the raw data to be stored in the new bitmap.
sl@0
  2093
@return KErrNone if successful; KErrArgument if the width or height specified in
sl@0
  2094
aSizeInPixels is negative, aDispMode is an invalid display mode, aData is NULL,
sl@0
  2095
aDataSize is negative or zero, or aDataType is a UID reserved for OS use; KErrTooBig
sl@0
  2096
if the width or height specified in aSizeInPixels exceeds KMaxTInt/4, or aDataSize
sl@0
  2097
exceeds KMaxTInt/2; otherwise another of the system-wide error codes.
sl@0
  2098
@publishedPartner
sl@0
  2099
@prototype
sl@0
  2100
@see CFbsBitmap::DataAddress()
sl@0
  2101
@see CFbsBitmap::DataSize()
sl@0
  2102
@see CFbsBitmap::BeginDataAccess()
sl@0
  2103
@see CFbsBitmap::EndDataAccess()
sl@0
  2104
@see MFbsExtendedBitmapInitializer
sl@0
  2105
*/
sl@0
  2106
EXPORT_C TInt CFbsBitmap::CreateExtendedBitmap(const TSize& aSizeInPixels, TDisplayMode aDispMode, TUid aType, TInt aDataSize, MFbsExtendedBitmapInitializer& aInitializer)
sl@0
  2107
	{
sl@0
  2108
    TInt err; 
sl@0
  2109
    FBS_OST(OstTraceExt5( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_CREATEEXTENDEDBITMAP2_ENTRY, "> this=0x%08x; w=%d; h=%d; dm=%d; type=0x%08x;", (TUint)this, aSizeInPixels.iWidth, aSizeInPixels.iHeight, aDispMode, aType.iUid);)
sl@0
  2110
	if (aDataSize == 0)
sl@0
  2111
		{
sl@0
  2112
        FBS_OST(OstTrace1( TRACE_ERROR, CFBSBITMAP_CREATEEXTENDEDBITMAP2_ERROR, "! this=0x%08x; aDataSize == 0", (TUint)this);)
sl@0
  2113
		err = KErrArgument;
sl@0
  2114
		}
sl@0
  2115
	else
sl@0
  2116
	    {
sl@0
  2117
        err = DoCreate(aSizeInPixels, aDispMode, aType, aDataSize);
sl@0
  2118
        if (err == KErrNone)
sl@0
  2119
            {
sl@0
  2120
            err = aInitializer.InitExtendedBitmap(iFbs->iLargeBitmapChunk.Base() + iAddressPointer->iDataOffset, aDataSize);
sl@0
  2121
            if (err != KErrNone)
sl@0
  2122
                {
sl@0
  2123
                Reset();
sl@0
  2124
                }
sl@0
  2125
            }
sl@0
  2126
	    }
sl@0
  2127
	FBS_OST(OstTraceExt4( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_CREATEEXTENDEDBITMAP2_EXIT, "< this=0x%08x; err=%d; iH=0x%08x; iSH=0x%08x", (TUint)this, err, iHandle, iServerHandle);)
sl@0
  2128
	return err;
sl@0
  2129
	}
sl@0
  2130
sl@0
  2131
/**
sl@0
  2132
Gets the UID identifying the data format of an extended bitmap.
sl@0
  2133
@return The UID identifying the data format of the bitmap or
sl@0
  2134
        KNullUid if the bitmap is not an extended bitmap.
sl@0
  2135
@publishedPartner
sl@0
  2136
@prototype
sl@0
  2137
*/
sl@0
  2138
EXPORT_C TUid CFbsBitmap::ExtendedBitmapType() const
sl@0
  2139
	{
sl@0
  2140
	if (iHandle == 0)
sl@0
  2141
		{
sl@0
  2142
		return KNullUid;
sl@0
  2143
		}
sl@0
  2144
	TUid type = CleanAddress()->iUid;
sl@0
  2145
	if (type.iUid == KCBitwiseBitmapUid.iUid || type.iUid == KCBitwiseBitmapHardwareUid.iUid)
sl@0
  2146
		{
sl@0
  2147
		return KNullUid;
sl@0
  2148
		}
sl@0
  2149
	return type;
sl@0
  2150
	}
sl@0
  2151
sl@0
  2152
/**
sl@0
  2153
Gets the size in bytes of the bitmap data.
sl@0
  2154
@return The size in bytes of the bitmap data.
sl@0
  2155
@publishedPartner
sl@0
  2156
@prototype
sl@0
  2157
*/
sl@0
  2158
EXPORT_C TInt CFbsBitmap::DataSize() const
sl@0
  2159
	{
sl@0
  2160
	if (iHandle == 0)
sl@0
  2161
		{
sl@0
  2162
		return 0;
sl@0
  2163
		}
sl@0
  2164
	CBitwiseBitmap* bmp = CleanAddress();
sl@0
  2165
	return bmp->iHeader.iBitmapSize - bmp->iHeader.iStructSize;
sl@0
  2166
	}
sl@0
  2167
sl@0
  2168
/**
sl@0
  2169
Gets a pointer to an extra buffer for general use owned by this thread's FBServ session.
sl@0
  2170
@param aSize The size of the buffer in bytes
sl@0
  2171
@return A pointer to the extra buffer if successful or NULL if there is no FBServ session
sl@0
  2172
@internalTechnology
sl@0
  2173
@released
sl@0
  2174
*/
sl@0
  2175
EXPORT_C HBufC8* CFbsBitmap::GetExtraBuffer(TInt aSize)
sl@0
  2176
	{
sl@0
  2177
		RFbsSession* ses=RFbsSession::GetSession();
sl@0
  2178
		return ses? ses->GetExtraBuffer(aSize) : NULL;
sl@0
  2179
	}