sl@0: // Copyright (c) 1995-2010 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "fbsdefs.h" sl@0: #include "UTILS.H" sl@0: #include "fbshelper.h" sl@0: #include "fbsrasterizer.h" sl@0: #include "BitwiseBitmap.inl" sl@0: #include "FbsMessage.H" sl@0: #include "bitmapconst.h" sl@0: #include "OstTraceDefinitions.h" sl@0: #include "fbstrace.h" sl@0: #ifdef OST_TRACE_COMPILER_IN_USE sl@0: #include "FBSBMPTraces.h" sl@0: #endif sl@0: sl@0: const TInt KMaxPixelSize = KMaxTInt / 4; // Maximum pixel size to avoid some overflow problems sl@0: const TInt KMaxBitmapHandleBufferSize = KNumBytesPerBitmapHandle * 2000; // Maximum size of buffer to store all bitmap handles. sl@0: sl@0: GLREF_C void Panic(TFbsPanic aPanic); sl@0: sl@0: //If we have to handle RAM located file with an embedded ROM mbm file section - sl@0: //KRomMBMInRamRSC should be ETrue. sl@0: //If it is not allowed to do that - KRomMBMInRamRSC should be EFalse. sl@0: //The same constant is defined into TDefect test app. It should be changed too. sl@0: #pragma warning(disable : 4127) //conditional expression is constant sl@0: LOCAL_D const TBool KRomMBMInRamRSC = EFalse; sl@0: sl@0: //Cleanup function used by CFbsBitmap::LoadShiftedRomBmpL(...) sl@0: LOCAL_D void FreeMem(TAny* aMem) sl@0: { sl@0: delete[] static_cast(aMem); sl@0: } sl@0: sl@0: // Fbs style bitmap client class for font bitmap server sl@0: /** @publishedAll */ sl@0: EXPORT_C CFbsBitmap::CFbsBitmap(): sl@0: CBase(), sl@0: iFbs(RFbsSession::GetSession()), sl@0: iAddressPointer(NULL), sl@0: iFlags(0), sl@0: iUseCount(0), sl@0: iHandle(0), sl@0: iServerHandle(0) sl@0: { sl@0: } sl@0: sl@0: /** Destructor. Calls Reset(). sl@0: @see Reset() sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C CFbsBitmap::~CFbsBitmap() sl@0: { sl@0: Reset(); sl@0: } sl@0: sl@0: /** Gets the physical length in bytes of a scanline in memory. sl@0: This is aligned to a 4 byte (DWORD) boundary for performance reasons. sl@0: sl@0: @param aLength The length of a scanline in pixels. sl@0: @param aDispMode The display mode of the bitmap. sl@0: @return Number of bytes in the scanline in memory. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TInt CFbsBitmap::ScanLineLength(TInt aLength,TDisplayMode aDispMode) sl@0: { sl@0: if (aDispMode == ERgb) sl@0: return aLength * 4; sl@0: else if (aDispMode == ENone) sl@0: return 0; sl@0: sl@0: return CBitwiseBitmap::ByteWidth(aLength,aDispMode); sl@0: } sl@0: sl@0: /** Releases the bitmap's handle from the font and bitmap server and decrements sl@0: its access count. sl@0: The server-side bitmap is only deleted when the access count for the bitmap sl@0: decrements to zero. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C void CFbsBitmap::Reset() sl@0: { sl@0: FBS_OST(TInt ssh = (iFbs ? iFbs->ServerSessionHandle() : 0);) sl@0: 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: if (iHandle && !(iFlags & EIsRomBitmap)) sl@0: { sl@0: iFbs->SendCommand(EFbsMessClose, iHandle, Handle()); sl@0: iFbs->iHelper->RemoveBitmap(*this); sl@0: } sl@0: if (KRomMBMInRamRSC && (iFlags & EIsRomBitmap)) sl@0: { sl@0: // If it is a ROM bitmap, we have to check, is it a ROM bitmap located sl@0: // in RAM? If yes, then we have to deallocate the bitmap memory. sl@0: TBool isInRom = EFalse; sl@0: TInt ret = User::IsRomAddress(isInRom, iAddressPointer); sl@0: if (ret == KErrNone && !isInRom) sl@0: delete[] reinterpret_cast(iAddressPointer); sl@0: } sl@0: iAddressPointer = NULL; sl@0: iFlags = 0; sl@0: iUseCount = 0; sl@0: iHandle = 0; sl@0: iServerHandle = 0; sl@0: FBS_OST(OstTrace1( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_RESET_EXIT, "< this=0x%08x", (TUint)this );) sl@0: } sl@0: sl@0: /** Tests whether or not the bitmap is read-only. sl@0: @return ETrue if the bitmap is read-only, EFalse otherwise. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TBool CFbsBitmap::IsRomBitmap() const sl@0: { sl@0: return (iFlags & EIsReadOnlyBitmapMask) > 0; sl@0: } sl@0: sl@0: /** Sets the bitmap to use a bitmap image stored in ROM. sl@0: @param aRomBitmapPointer Pointer to a bitmap stored in ROM. sl@0: @param aBitmapSizeInBytes On return, indicates the size of sl@0: the bitmap in bytes. sl@0: @leave KErrUnknown aRomBitmapPointer is not in ROM, or has an invalid UID. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C void CFbsBitmap::SetRomBitmapL(CBitwiseBitmap* aRomBitmapPointer,TInt& aBitmapSizeInBytes) sl@0: { sl@0: TBool isInRom = EFalse; sl@0: TInt ret = User::IsRomAddress(isInRom,(TAny*)aRomBitmapPointer); sl@0: if (ret != KErrNone || !isInRom || aRomBitmapPointer->Uid() != KCBitwiseBitmapUid) sl@0: User::Leave(KErrUnknown); sl@0: sl@0: Reset(); sl@0: iAddressPointer = aRomBitmapPointer; sl@0: iFlags = EIsRomBitmap; sl@0: iHandle = 1; sl@0: sl@0: User::LeaveIfError(iFbs->AllocScanLineBuffer(aRomBitmapPointer->iByteWidth + 4)); sl@0: aBitmapSizeInBytes = Align4(aRomBitmapPointer->iHeader.iBitmapSize + 28); sl@0: } sl@0: sl@0: CBitwiseBitmap* CFbsBitmap::Address() const sl@0: { sl@0: if (!iHandle) sl@0: return NULL; sl@0: return iAddressPointer; sl@0: } sl@0: sl@0: EXPORT_C CBitwiseBitmap* CFbsBitmap::CleanAddress() const sl@0: { sl@0: if (!iHandle) sl@0: return NULL; sl@0: // Don't try to clean a dirty bitmap between calls to BeginDataAccess() and EndDataAccess(), i.e. iUseCount > 0 sl@0: // ROM bitmaps can never be dirty sl@0: if (!(iFlags & EIsReadOnlyBitmapMask) && iUseCount == 0 && iAddressPointer->iSettings.IsDirtyBitmap()) sl@0: { sl@0: TPckgBuf handlebuf; sl@0: TIpcArgs args(iHandle, &handlebuf); sl@0: if (iFbs->SendCommand(EFbsMessBitmapClean, args) == KErrNone) sl@0: { sl@0: const_cast(this)->iHandle = handlebuf().iHandle; sl@0: const_cast(this)->iServerHandle = handlebuf().iServerHandle; sl@0: const_cast(this)->iAddressPointer = (CBitwiseBitmap*)(iFbs->HeapBase() + handlebuf().iAddressOffset); sl@0: } sl@0: } sl@0: return iAddressPointer; sl@0: } sl@0: sl@0: inline CBitwiseBitmap* CFbsBitmap::BeginDataAccessAndGetCleanAddress(TUint32*& aDataAddress) const sl@0: { sl@0: BeginDataAccess(); sl@0: CBitwiseBitmap* bmp = Address(); sl@0: // aDataAddress should be consistent with bmp since after the call to BeginDataAccess() sl@0: // the call to DataAddress() will not clean the bitmap again sl@0: aDataAddress = DataAddress(); sl@0: return bmp; sl@0: } sl@0: sl@0: /** Gets the address of the first pixel in the bitmap. sl@0: The first pixel is at the top-left. Access to the pixel data of a bitmap sl@0: should be surrounded by calls to BeginDataAccess() and EndDataAccess(), sl@0: otherwise performance may be degraded on certain platforms. sl@0: sl@0: Note: Performing a Resize() or Compress() operation changes the value returned by this function. sl@0: @return The address of the first pixel of the bitmap. sl@0: @publishedAll sl@0: @released sl@0: @see CFbsBitmap::BeginDataAccess() sl@0: @see CFbsBitmap::EndDataAccess() sl@0: */ sl@0: EXPORT_C TUint32* CFbsBitmap::DataAddress() const sl@0: { sl@0: if(!iHandle) return(NULL); sl@0: CBitwiseBitmap* bmp = CleanAddress(); sl@0: sl@0: if (!(iFlags & EIsReadOnlyBitmapMask) && (iUseCount == 0)) sl@0: bmp->iSettings.SetVolatileBitmap(); sl@0: sl@0: if(bmp->iUid.iUid==KCBitwiseBitmapHardwareUid.iUid) // RHardwareBitmap sl@0: { sl@0: RHardwareBitmap hwb(bmp->iDataOffset); // iDataOffset = handle for hardware bitmap sl@0: TAcceleratedBitmapInfo info; sl@0: const TInt ret = hwb.GetInfo(info); sl@0: return ret!=KErrNone ? NULL : (reinterpret_cast(info.iAddress)); sl@0: } sl@0: sl@0: if (bmp->iHeap == NULL) sl@0: return(reinterpret_cast((TUint8*)bmp+bmp->iDataOffset)); sl@0: return(reinterpret_cast(iFbs->iLargeBitmapChunk.Base()+bmp->iDataOffset)); sl@0: } sl@0: sl@0: /** Gets the length in bytes between scanlines in memory. sl@0: @return The length in bytes between scanlines in memory. sl@0: @internalAll sl@0: @released sl@0: */ sl@0: EXPORT_C TInt CFbsBitmap::DataStride() const sl@0: { sl@0: if (!iHandle) sl@0: { sl@0: return 0; sl@0: } sl@0: sl@0: CBitwiseBitmap* bmp = CleanAddress(); sl@0: if (bmp==NULL) sl@0: { sl@0: return 0; sl@0: } sl@0: sl@0: return bmp->DataStride(); sl@0: } sl@0: sl@0: /** Creates a bitmap with the specified size and display mode. The bitmap is sl@0: created on the font and bitmap server's shared heap. sl@0: @param aSizeInPixels The size of the bitmap to be created. sl@0: @param aDispMode The display mode of the bitmap to be created. sl@0: @return KErrNone if successful; KErrCouldNotConnect if no connection to the sl@0: font and bitmap server could be made; KErrArgument if either the width or height specified sl@0: in aSizeInPixels are negative or if the requested display mode is invalid; KErrTooBig sl@0: if the requested size is too big. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TInt CFbsBitmap::Create(const TSize& aSizeInPixels,TDisplayMode aDispMode) sl@0: { sl@0: 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: TInt err = DoCreate(aSizeInPixels,aDispMode,KUidCFbsBitmapCreation); sl@0: FBS_OST(TInt ssh = (iFbs ? iFbs->ServerSessionHandle() : 0);) sl@0: 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: return err; sl@0: } sl@0: sl@0: TInt CFbsBitmap::DoCreate(const TSize& aSizeInPixels, TDisplayMode aDispMode, TUid aUid, TInt aDataSize) sl@0: { sl@0: if(!iFbs) return(KErrCouldNotConnect); sl@0: if (aDispMode <= ENone || aDispMode == ERgb || aDispMode >= EColorLast) return KErrArgument; sl@0: if(aSizeInPixels.iWidth<0 || aSizeInPixels.iHeight<0) return(KErrArgument); sl@0: if (aDataSize < 0) return KErrArgument; sl@0: Reset(); sl@0: TBmpSpec bmpspec; sl@0: bmpspec.iSizeInPixels=aSizeInPixels; sl@0: bmpspec.iDispMode=aDispMode; sl@0: bmpspec.iHandle = aUid.iUid; // Use iHandle to pass UID sl@0: bmpspec.iServerHandle = aDataSize; // Use iServerHandle to pass data size sl@0: TPckgBuf b; sl@0: b=bmpspec; sl@0: TIpcArgs args(&b); sl@0: TInt ret=iFbs->SendCommand(EFbsMessBitmapCreate,args); sl@0: if(ret!=KErrNone) return(ret); sl@0: iHandle=b().iHandle; sl@0: iServerHandle=b().iServerHandle; sl@0: iAddressPointer=(CBitwiseBitmap*)(iFbs->HeapBase()+b().iAddressOffset); sl@0: if (aDataSize > 0) // explicitly specified data size means extended bitmap sl@0: { sl@0: iFlags = EIsExtendedBitmap; sl@0: } sl@0: ret = iFbs->iHelper->AddBitmap(*this); sl@0: if (ret != KErrNone) sl@0: return ret; sl@0: return iFbs->AllocScanLineBuffer(CBitwiseBitmap::ByteWidth(aSizeInPixels.iWidth, aDispMode)+4); sl@0: } sl@0: sl@0: /** Creates a hardware bitmap with a size and display mode. sl@0: @param aSizeInPixels The bitmap's width and height in pixels. sl@0: @param aDispMode The bitmap's display mode. sl@0: @param aCreatorUid The UID of the application calling this function. This is sl@0: used to allow segregation of the memory used for hardware bitmaps. For instance, sl@0: if a device has video memory attached to display and graphics accelerator sl@0: hardware, this UID is used to determine whether any video memory is pre-allocated sl@0: for that application's use. sl@0: @return KErrNone if successful, otherwise one of the system wide error codes. sl@0: These include KErrCouldNotConnect if no connection has been made to the font sl@0: and bitmap server, KErrArgument if either the width or height specified in sl@0: aSizeInPixels are negative or if the requested display mode is invalid, or KErrNotSupported sl@0: if hardware bitmaps are not supported on the device. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TInt CFbsBitmap::CreateHardwareBitmap(const TSize& aSizeInPixels,TDisplayMode aDispMode,TUid aCreatorUid) sl@0: { sl@0: 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: TInt err = DoCreate(aSizeInPixels,aDispMode,aCreatorUid); sl@0: FBS_OST(TInt ssh = (iFbs ? iFbs->ServerSessionHandle() : 0);) sl@0: 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: return err; sl@0: } sl@0: sl@0: /** Resets the pixel-size of the bitmap. sl@0: If the new size is bigger than the old, the original bitmap is still situated sl@0: at (0,0), but pixels outside the range of the old pixel-size are set to zero. sl@0: @param aSizeInPixels The new size of the bitmap. sl@0: @return KErrNone if successful; KErrArgument if the new size is illegal; sl@0: KErrGeneral if the bitmap has not yet been created; KErrAccessDenied if the sl@0: bitmap is in ROM or is an extended bitmap; otherwise another of the system-wide error codes. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TInt CFbsBitmap::Resize(const TSize& aSizeInPixels) sl@0: { sl@0: if(aSizeInPixels.iWidth<0 || aSizeInPixels.iHeight<0) sl@0: return(KErrArgument); sl@0: if(aSizeInPixels.iWidth>KMaxPixelSize || aSizeInPixels.iHeight>KMaxPixelSize) sl@0: return(KErrTooBig); sl@0: if(!iHandle) sl@0: return(KErrGeneral); sl@0: if (iFlags & EIsReadOnlyBitmapMask) sl@0: return(KErrAccessDenied); sl@0: TPckgBuf handlebuf; sl@0: TIpcArgs args(iHandle, aSizeInPixels.iWidth, aSizeInPixels.iHeight, &handlebuf); sl@0: TInt err = iFbs->SendCommand(EFbsMessBitmapResize, args); sl@0: if (err != KErrNone) sl@0: return (err); sl@0: iHandle = handlebuf().iHandle; sl@0: iServerHandle = handlebuf().iServerHandle; sl@0: iAddressPointer = (CBitwiseBitmap*)(iFbs->HeapBase() + handlebuf().iAddressOffset); sl@0: return iFbs->AllocScanLineBuffer(CBitwiseBitmap::ByteWidth(aSizeInPixels.iWidth, DisplayMode())+4); sl@0: } sl@0: sl@0: /** Gets the display mode of the bitmap. sl@0: @return The display mode of the bitmap. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TDisplayMode CFbsBitmap::DisplayMode() const sl@0: { sl@0: if(iHandle==NULL) return(ENone); sl@0: return CleanAddress()->DisplayMode(); sl@0: } sl@0: sl@0: /** Returns the display mode that was used to create the bitmap. sl@0: @return The display mode used to create the bitmap. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TDisplayMode CFbsBitmap::InitialDisplayMode() const sl@0: { sl@0: if(iHandle == NULL) sl@0: { sl@0: return ENone; sl@0: } sl@0: return CleanAddress()->InitialDisplayMode(); sl@0: } sl@0: sl@0: /** sl@0: Changes the display mode of the bitmap. sl@0: The requested display mode cannot be greater (in bpp value) than the initial display mode. sl@0: This method cannot leave, for instance because of an out of memory condition. No sl@0: additional memory is allocated or leaving methods called. sl@0: The bitmap's content is preserved when converting it to the requested display mode, sl@0: but there may be some loss of quality. sl@0: @publishedAll sl@0: @released sl@0: @param aDisplayMode The requested display mode. sl@0: @return KErrArgument if the requested mode is invalid, or has a greater bpp value sl@0: than the initial mode. KErrNotSupported if the bitmap is compressed, or is a sl@0: ROM bitmap, an extended bitmap or a hardware bitmap. KErrGeneral if the bitmap sl@0: handle is NULL. KErrNone if the method call is successful. sl@0: @see CFbsBitmap::InitialDisplayMode() sl@0: */ sl@0: EXPORT_C TInt CFbsBitmap::SetDisplayMode(TDisplayMode aDisplayMode) sl@0: { sl@0: if(!iHandle) sl@0: { sl@0: return KErrGeneral; sl@0: } sl@0: TUint32* data; sl@0: CBitwiseBitmap* bmp = BeginDataAccessAndGetCleanAddress(data); sl@0: TInt err = bmp->SetDisplayMode(aDisplayMode, data); sl@0: EndDataAccess(EFalse); sl@0: return err; sl@0: } sl@0: sl@0: /** Duplicates a bitmap. sl@0: This function does not create a copy of the bitmap. It just assigns another sl@0: handle to the bitmap in the font and bitmap server, and sets this object's sl@0: handle to that. If the specified bitmap is in the ROM, it just assigns a pointer sl@0: to it. sl@0: @param aHandle The handle to an existing bitmap. sl@0: @return KErrNone if successful; KErrCouldNotConnect if no connection to the sl@0: font and bitmap server could be made; KErrUnknown if no bitmap could be found sl@0: with the specified handle number. sl@0: @publishedAll sl@0: @released sl@0: @see CFbsBitmap::Handle() sl@0: */ sl@0: EXPORT_C TInt CFbsBitmap::Duplicate(TInt aBitmapHandle) sl@0: { sl@0: TInt ret = KErrNone; sl@0: FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_DUPLICATE_ENTRY, "> this=0x%08x; iH=0x%08x;", (TUint)this, aBitmapHandle);) sl@0: if(!iFbs) sl@0: { sl@0: ret = KErrCouldNotConnect; sl@0: FBS_OST(OstTrace1( TRACE_ERROR, CFBSBITMAP_DUPLICATE_ERROR, "! this=0x%08x; !iFbs", (TUint)this);) sl@0: } sl@0: else if(!aBitmapHandle) sl@0: { sl@0: ret = KErrUnknown; sl@0: FBS_OST(OstTrace1( TRACE_ERROR, CFBSBITMAP_DUPLICATE_ERROR2, "! this=0x%08x; !aBitmapHandle", (TUint)this);) sl@0: } sl@0: else sl@0: { sl@0: TBool isinrom = EFalse; sl@0: ret = User::IsRomAddress(isinrom, (TAny*)aBitmapHandle); sl@0: if (ret == KErrNone) sl@0: { sl@0: if (isinrom) sl@0: { sl@0: ret = DuplicateInRom(aBitmapHandle); sl@0: FBS_OST_IF(ret != KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_DUPLICATE_ERROR4, "! this=0x%08x; DuplicateInRom() returned %d;", (TUint)this, ret);) sl@0: } sl@0: else sl@0: { sl@0: ret = DuplicateInRam(aBitmapHandle); sl@0: FBS_OST_IF(ret != KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_DUPLICATE_ERROR5, "! this=0x%08x; DuplicateInRam() returned %d;", (TUint)this, ret);) sl@0: } sl@0: } sl@0: else sl@0: { sl@0: FBS_OST(OstTraceExt2( TRACE_ERROR, CFBSBITMAP_DUPLICATE_ERROR3, "! this=0x%08x; IsRomAddress() returned %d", (TUint)this, ret);) sl@0: ret = KErrUnknown; sl@0: } sl@0: } sl@0: FBS_OST(TInt ssh = (iFbs ? iFbs->ServerSessionHandle() : 0);) sl@0: 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: return ret; sl@0: } sl@0: sl@0: /** Duplicates a bitmap where the bitmap handle refers to a rom bitmap. sl@0: @param aBitmapHandle A valid Rom bitmap handle. sl@0: @return KErrNone on success. sl@0: */ sl@0: TInt CFbsBitmap::DuplicateInRom(TInt aBitmapHandle) sl@0: { sl@0: TInt ret = KErrNone; sl@0: Reset(); sl@0: TUid uid = ((CBitwiseBitmap*)aBitmapHandle)->Uid(); sl@0: if (uid != KCBitwiseBitmapUid) sl@0: { sl@0: FBS_OST(OstTraceExt2( TRACE_ERROR, CFBSBITMAP_DUPLICATEINROM_ERROR, "! this=0x%08x; 0x%08x != KCBitwiseBitmapUid", (TUint)this, (TUint)uid.iUid);) sl@0: ret = KErrUnknown; sl@0: } sl@0: else sl@0: { sl@0: iAddressPointer = (CBitwiseBitmap*)aBitmapHandle; sl@0: iFlags = EIsRomBitmap; sl@0: iHandle=1; sl@0: ret = iFbs->AllocScanLineBuffer(iAddressPointer->iByteWidth + 4); sl@0: FBS_OST_IF(ret!=KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_DUPLICATEINROM_ERROR2, "! this=0x%08x; AllocScanLineBuffer() returned %d", (TUint)this, ret);) sl@0: } sl@0: return ret; sl@0: } sl@0: sl@0: /** Duplicates a bitmap where the bitmap handle refers to a ram bitmap sl@0: @param aBitmapHandle A valid Ram bitmap handle. sl@0: @return KErrNone on success. sl@0: */ sl@0: TInt CFbsBitmap::DuplicateInRam(TInt aBitmapHandle) sl@0: { sl@0: TInt ret = KErrNone; sl@0: Reset(); sl@0: sl@0: TPckgBuf b; sl@0: TIpcArgs args(aBitmapHandle,&b); sl@0: ret=iFbs->SendCommand(EFbsMessBitmapDuplicate,args); sl@0: FBS_OST_IF(ret!=KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_DUPLICATEINRAM_ERROR, "! this=0x%08x; SendCommand(EFbsMessBitmapDuplicate) returned %d", (TUint)this, ret);) sl@0: if(ret==KErrNone) sl@0: { sl@0: iHandle=b().iHandle; sl@0: iServerHandle=b().iServerHandle; sl@0: iAddressPointer=(CBitwiseBitmap*)(iFbs->HeapBase()+b().iAddressOffset); sl@0: if (iAddressPointer->iUid.iUid != KCBitwiseBitmapUid.iUid && iAddressPointer->iUid.iUid != KCBitwiseBitmapHardwareUid.iUid) sl@0: { sl@0: iFlags = EIsExtendedBitmap; sl@0: } sl@0: ret = iFbs->iHelper->AddBitmap(*this); sl@0: FBS_OST_IF(ret!=KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_DUPLICATEINRAM_ERROR2, "! this=0x%08x; AddBitmap() returned %d", (TUint)this, ret);) sl@0: if (ret == KErrNone) sl@0: { sl@0: ret = iFbs->AllocScanLineBuffer(iAddressPointer->iByteWidth+4); sl@0: FBS_OST_IF(ret!=KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_DUPLICATEINRAM_ERROR3, "! this=0x%08x; AllocScanLineBuffer() returned %d", (TUint)this, ret);) sl@0: } sl@0: } sl@0: return ret; sl@0: } sl@0: sl@0: /** Loads a specific bitmap from a multi-bitmap file. sl@0: The bitmap may be shared by other font and bitmap server clients. sl@0: @param aFileName The filename of the multi-bitmap (.mbm) file. sl@0: @param aId The bitmap identifier. sl@0: @param aShareIfLoaded Specifies whether or not the loaded bitmap will be made sl@0: available for sharing between font and bitmap server clients. sl@0: @return KErrNone if successful, otherwise another of the system error sl@0: codes. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TInt CFbsBitmap::Load(const TDesC& aFileName,TInt32 aId,TBool aShareIfLoaded) sl@0: { sl@0: 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: TInt err = Load(aFileName,aId,aShareIfLoaded,0); sl@0: FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOAD_EXIT, "< this=0x%08x; err=%d", (TUint)this, err);) sl@0: return err; sl@0: } sl@0: sl@0: /** Loads a specific bitmap from a multi-bitmap file. sl@0: The bitmap may be shared by other font and bitmap server clients. sl@0: @param aFileName The filename of the multi-bitmap (.mbm) file. sl@0: @param aId The bitmap identifier. sl@0: @param aShareIfLoaded Specifies whether or not the loaded bitmap will be made sl@0: available for sharing between FBSERV clients. sl@0: @param aFileOffset Bitmap file section offset within the file. sl@0: @return KErrNone if successful, otherwise another of the system error codes. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TInt CFbsBitmap::Load(const TDesC& aFileName,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset) sl@0: { sl@0: TInt err = KErrNone; sl@0: 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: if(!iFbs) sl@0: { sl@0: FBS_OST(OstTrace1( TRACE_ERROR, CFBSBITMAP_LOAD2_ERROR, "! this=0x%08x; !iFbs", (TUint)this);) sl@0: err = KErrCouldNotConnect; sl@0: } sl@0: else sl@0: { sl@0: Reset(); sl@0: TUint32* rompointer = NULL; sl@0: //access using filename has the advantage of using rom address lookup cache sl@0: IsFileInRom(aFileName, rompointer); sl@0: TBool romPointerValid; sl@0: err = DoLoadFromRom(rompointer, aId, aFileOffset, romPointerValid); sl@0: if(!romPointerValid) sl@0: { sl@0: _LIT(KResourcePath, "?:\\Resource\\*"); sl@0: TInt match = aFileName.MatchF(KResourcePath); sl@0: //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: if (match == 0) sl@0: { sl@0: err = DoLoad(aFileName,aId,aShareIfLoaded,aFileOffset); sl@0: FBS_OST_IF(err!=KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_LOAD2_ERROR3, "! this=0x%08x; DoLoad returned %d", (TUint)this, err);) sl@0: } sl@0: else sl@0: { sl@0: RFile file; sl@0: err = file.Open(iFbs->FileServer(),aFileName,EFileShareReadersOnly); sl@0: if (err==KErrNone) sl@0: { sl@0: err = DoLoad(file,aId,aShareIfLoaded,aFileOffset); sl@0: FBS_OST_IF(err!=KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_LOAD2_ERROR4, "! this=0x%08x; DoLoad returned %d", (TUint)this, err);) sl@0: } sl@0: file.Close(); sl@0: } sl@0: } sl@0: } sl@0: FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOAD2_EXIT, "< this=0x%08x; err=%d", (TUint)this, err);) sl@0: return err; sl@0: } sl@0: sl@0: /** Loads and compresses a specific bitmap from a multi-bitmap file. sl@0: The bitmap may be shared by other font and bitmap server clients. sl@0: If the bitmap is loaded from ROM then compression is not allowed. sl@0: @param aFileName The filename of the multi-bitmap (.mbm) file. sl@0: @param aId The bitmap identifier. sl@0: @param aShareIfLoaded Specifies whether or not the loaded bitmap will be sl@0: made available for sharing between FBSERV clients. sl@0: @return KErrNone if successful, otherwise another of the system-wide error sl@0: codes. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TInt CFbsBitmap::LoadAndCompress(const TDesC& aFileName,TInt32 aId,TBool aShareIfLoaded) sl@0: { sl@0: 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: TInt ret = LoadAndCompress(aFileName, aId, aShareIfLoaded, 0); sl@0: FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOADANDCOMPRESS_EXIT, "< this=0x%08x; err=%d", (TUint)this, ret);) sl@0: return ret; sl@0: } sl@0: sl@0: /** Loads and compresses a specific bitmap from a multi-bitmap file. sl@0: The bitmap may be shared by other font and bitmap server clients. If the sl@0: bitmap is loaded from ROM then compression is not allowed. sl@0: @param aFileName The filename of the multi-bitmap (.mbm) file. sl@0: @param aId The bitmap identifier. sl@0: @param aShareIfLoaded Specifies whether or not the loaded bitmap will be made sl@0: available for sharing between FBSERV clients. sl@0: @param aFileOffset Bitmap file section offset within the file. sl@0: @return KErrNone if successful, otherwise another of the system-wide error sl@0: codes. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TInt CFbsBitmap::LoadAndCompress(const TDesC& aFileName,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset) sl@0: { sl@0: 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: TInt err = Load(aFileName,aId,aShareIfLoaded,aFileOffset); sl@0: if (err == KErrNone) sl@0: { sl@0: err = !(iFlags & EIsRomBitmap) ? Compress() : KErrAccessDenied; sl@0: 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: } sl@0: FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOADANDCOMPRESS2_EXIT, "< this=0x%08x; err=%d", (TUint)this, err);) sl@0: return err; sl@0: } sl@0: sl@0: /** Saves the bitmap as a direct file store. sl@0: The file store overwrites any existing file with the same name. sl@0: @param aFilename The name of the file. sl@0: @return KErrNone if successful, KErrNotSupported if this CFbsBitmap is an sl@0: extended bitmap, otherwise another of the system-wide error codes. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TInt CFbsBitmap::Save(const TDesC& aFilename) sl@0: { sl@0: if (!iHandle) sl@0: { sl@0: return(KErrGeneral); sl@0: } sl@0: RFile file; sl@0: TInt ret=file.Replace(iFbs->FileServer(),aFilename,EFileWrite); sl@0: if(ret!=KErrNone) return(ret); sl@0: TRAP(ret,DoSaveL(file)); sl@0: file.Close(); sl@0: return(ret); sl@0: } sl@0: sl@0: /** Saves the bitmap as a direct file store using an opened file handle. sl@0: The file store overwrites any existing file with the same name. sl@0: @param aFile The opened file handle sl@0: @return KErrNone if successful, KErrNotSupported if this CFbsBitmap is an sl@0: extended bitmap, otherwise another of the system-wide error codes. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TInt CFbsBitmap::Save(RFile& aFile) sl@0: { sl@0: if (!iHandle) sl@0: { sl@0: return KErrGeneral; sl@0: } sl@0: TRAPD(ret,DoSaveL(aFile)); sl@0: return ret; sl@0: } sl@0: sl@0: void CFbsBitmap::DoSaveL(RFile& aFile) sl@0: { sl@0: CDirectFileStore* filestore=CDirectFileStore::NewLC(aFile); // create from open file sl@0: TUidType uidtype(KDirectFileStoreLayoutUid,KMultiBitmapFileImageUid); sl@0: filestore->SetTypeL(uidtype); sl@0: RStoreWriteStream bmpstream; sl@0: TStreamId bmpstreamid=bmpstream.CreateLC(*filestore); // create bitmap stream sl@0: ExternalizeL(bmpstream); sl@0: bmpstream.CommitL(); sl@0: CleanupStack::PopAndDestroy(); // bitmap stream sl@0: RStoreWriteStream rootstream; sl@0: TStreamId rootstreamid=rootstream.CreateLC(*filestore); // create root stream sl@0: rootstream.WriteInt32L(1); // number of bitmaps sl@0: rootstream<SetRootL(rootstreamid); sl@0: filestore->CommitL(); sl@0: CleanupStack::PopAndDestroy(); // file store sl@0: } sl@0: sl@0: /** Constructs a multi-bitmap file. sl@0: @param aFilename The name of the multi-bitmap file to be created. sl@0: @param aNumSources The number of bitmaps to store in the file. sl@0: @param aSources An array of pointers to bitmaps to be stored. sl@0: @param aSourceIds An array of identifiers for the bitmaps to be stored. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C void CFbsBitmap::StoreL(const TDesC& aFilename,TInt aNumSources,const TDesC* aSources[],TInt32 aSourceIds[]) sl@0: { sl@0: CFbsBitmap* bitmap = new(ELeave) CFbsBitmap; sl@0: CleanupStack::PushL(bitmap); sl@0: CDirectFileStore* filestore = CDirectFileStore::ReplaceLC(bitmap->iFbs->FileServer(),aFilename,EFileWrite); sl@0: DoStoreL(filestore,bitmap,aNumSources,aSources,aSourceIds); sl@0: CleanupStack::PopAndDestroy(2,bitmap); sl@0: } sl@0: sl@0: /** Constructs a multi-bitmap file using an opened file handle. sl@0: @param aFile The opened file handle of multi-bitmap file sl@0: @param aNumSources The number of bitmaps to store in the file. sl@0: @param aSources An array of pointers to bitmaps to be stored. sl@0: @param aSourceIds An array of identifiers for the bitmaps to be stored. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C void CFbsBitmap::StoreL(RFile& aFile,TInt aNumSources,const TDesC* aSources[],TInt32 aSourceIds[]) sl@0: { sl@0: CDirectFileStore* filestore = CDirectFileStore::NewLC(aFile); sl@0: DoStoreL(filestore,NULL,aNumSources,aSources,aSourceIds); sl@0: CleanupStack::PopAndDestroy(filestore); sl@0: } sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: void CFbsBitmap::DoStoreL(CDirectFileStore* aFileStore,CFbsBitmap* aBitmap,TInt aNumSources,const TDesC* aSources[],TInt32 aSourceIds[]) sl@0: { sl@0: if(aNumSources<1 || aSources==NULL) User::Leave(KErrArgument); sl@0: TInt count=0; sl@0: for(;countSetTypeL(uidtype); sl@0: for(count=0;countLoad(*aSources[count],aSourceIds[count])); sl@0: RStoreWriteStream bmpstream; sl@0: ids[count]=bmpstream.CreateLC(*aFileStore); // create bitmap stream sl@0: aBitmap->ExternalizeL(bmpstream); sl@0: bmpstream.Close(); sl@0: CleanupStack::Pop(); // bitmap stream sl@0: } sl@0: RStoreWriteStream rootstream; sl@0: TStreamId rootstreamid=rootstream.CreateLC(*aFileStore); // create root stream sl@0: rootstream.WriteInt32L(aNumSources); // number of bitmaps sl@0: for(count=0;countSetRootL(rootstreamid); sl@0: CleanupStack::PopAndDestroy(nPushed); // ids [and bitmap] sl@0: } sl@0: sl@0: /** Gets the bitmap's scanline for the specified line starting from the sl@0: specified point. sl@0: The dither offset of the bitmap is taken to be TPoint(0,0). sl@0: @param aBuf The buffer in which the scanline is returned. sl@0: @param aPoint The start pixel. sl@0: @param aLength The number of pixels to get. sl@0: @param aDispMode Format to be used to write the data to the buffer. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C void CFbsBitmap::GetScanLine(TDes8& aBuf,const TPoint& aPoint,TInt aLength,TDisplayMode aDispMode) const sl@0: { sl@0: GetScanLine(aBuf,aPoint,aLength,TPoint(0,0),aDispMode); sl@0: } sl@0: sl@0: /** Gets the bitmap's scanline for the specified line starting from the specified sl@0: point and using the specified dither offset. sl@0: @param aBuf The buffer in which the scanline is returned. sl@0: @param aPixel The start pixel. sl@0: @param aLength The number of pixels to get. sl@0: @param aDitherOffset The dither offset of the bitmap. sl@0: @param aDispMode Format to be used to write the data to the buffer. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C void CFbsBitmap::GetScanLine(TDes8& aBuf,const TPoint& aPoint,TInt aLength,const TPoint& aDitherOffset,TDisplayMode aDispMode) const sl@0: { sl@0: if(!iHandle) return; sl@0: TUint32* data; sl@0: CBitwiseBitmap* bmp = BeginDataAccessAndGetCleanAddress(data); sl@0: CFbsRasterizer* rasterizer = NULL; sl@0: if ((iFlags & EIsExtendedBitmap) && iFbs) sl@0: { sl@0: rasterizer = iFbs->iHelper->Rasterizer(); sl@0: if (rasterizer) sl@0: { sl@0: CFbsRasterizer::TBitmapDesc desc; sl@0: desc.iSizeInPixels = bmp->SizeInPixels(); sl@0: desc.iDispMode = bmp->DisplayMode(); sl@0: desc.iDataType = bmp->iUid; sl@0: desc.iData = data; sl@0: desc.iDataSize = bmp->iHeader.iBitmapSize - bmp->iHeader.iStructSize; sl@0: rasterizer->BeginBitmap(bmp->Extra()->iSerialNumber, desc, NULL); sl@0: } sl@0: } sl@0: bmp->GetScanLine(aBuf, aPoint, aLength, ETrue, aDitherOffset, aDispMode, data); sl@0: if (rasterizer) sl@0: { sl@0: rasterizer->EndBitmap(bmp->Extra()->iSerialNumber); sl@0: } sl@0: EndDataAccess(ETrue); sl@0: } sl@0: sl@0: /** Sets the bitmap's horizontal scanline at the specified y co-ordinate to the sl@0: scanline contained in the buffer. sl@0: @param aBuf The new scanline to be written to the bitmap. sl@0: @param aY The y co-ordinate of the scanline. sl@0: @panic FBSCLI 11 in debug builds if this is a compressed bitmap. sl@0: @panic FBSCLI 28 in debug builds if this is a read-only bitmap. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C void CFbsBitmap::SetScanLine(TDes8& aBuf,TInt aY) const sl@0: { sl@0: if (!iHandle) sl@0: return; sl@0: if (iFlags & EIsReadOnlyBitmapMask) sl@0: { sl@0: __ASSERT_DEBUG(EFalse, ::Panic(EFbsPanicBitmapReadOnly)); sl@0: return; sl@0: } sl@0: TUint32* data; sl@0: CBitwiseBitmap* bmp = BeginDataAccessAndGetCleanAddress(data); sl@0: if (bmp->IsCompressed()) sl@0: { sl@0: EndDataAccess(ETrue); sl@0: __ASSERT_DEBUG(EFalse, ::Panic(EFbsBitmapInvalidCompression)); sl@0: return; sl@0: } sl@0: data = bmp->ScanLineAddress(data, aY); sl@0: TInt bytewidth = bmp->iByteWidth; sl@0: TInt bytelen=aBuf.Length(); sl@0: if(bytelen>2; sl@0: TUint32* ptr=(TUint32*)aBuf.Ptr(); sl@0: TUint32* ptrlim=ptr+wordlen; sl@0: while(ptriHelper->Rasterizer(); sl@0: if (rasterizer) sl@0: { sl@0: CFbsRasterizer::TBitmapDesc desc; sl@0: desc.iSizeInPixels = bmp->SizeInPixels(); sl@0: desc.iDispMode = bmp->DisplayMode(); sl@0: desc.iDataType = bmp->iUid; sl@0: desc.iData = data; sl@0: desc.iDataSize = bmp->iHeader.iBitmapSize - bmp->iHeader.iStructSize; sl@0: rasterizer->BeginBitmap(bmp->Extra()->iSerialNumber, desc, NULL); sl@0: } sl@0: } sl@0: bmp->GetVerticalScanLine(aBuf, aX, ETrue, aDitherOffset, aDispMode, data, rasterizer); sl@0: if (rasterizer) sl@0: { sl@0: rasterizer->EndBitmap(bmp->Extra()->iSerialNumber); sl@0: } sl@0: EndDataAccess(ETrue); sl@0: } sl@0: sl@0: /** Gets the handle number of the bitmap. sl@0: The returned value can be used to give another thread access to the bitmap. sl@0: @return The handle number of the bitmap. sl@0: @publishedAll sl@0: @released sl@0: @see CFbsBitmap::Duplicate() sl@0: */ sl@0: EXPORT_C TInt CFbsBitmap::Handle() const sl@0: { sl@0: if(!iHandle) sl@0: return(0); sl@0: if (iFlags & EIsRomBitmap) sl@0: return TInt(iAddressPointer); sl@0: else sl@0: return(iServerHandle); sl@0: } sl@0: sl@0: /** Creates a bitmap header. sl@0: This is used when streaming bitmaps to stores. sl@0: @return The bitmap header for the bitmap. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C SEpocBitmapHeader CFbsBitmap::Header() const sl@0: { sl@0: if (iHandle) sl@0: return CleanAddress()->iHeader; sl@0: SEpocBitmapHeader header; sl@0: return(header); sl@0: } sl@0: sl@0: /** Converts a horizontal dimension on the graphics device from pixels to twips. sl@0: @param aPixels A horizontal dimension on the graphics device in pixels. sl@0: @return A horizontal dimension on the graphics device in twips. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TInt CFbsBitmap::HorizontalPixelsToTwips(TInt aPixels) const sl@0: { sl@0: if(iHandle==NULL) return(0); sl@0: return CleanAddress()->HorizontalPixelsToTwips(aPixels); sl@0: } sl@0: sl@0: /** Converts a horizontal dimension on the graphics device from twips to pixels. sl@0: @param aTwips A horizontal dimension on the graphics device in twips. sl@0: @return A horizontal dimension on the graphics device in pixels. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TInt CFbsBitmap::HorizontalTwipsToPixels(TInt aTwips) const sl@0: { sl@0: if(iHandle==NULL) return(0); sl@0: return CleanAddress()->HorizontalTwipsToPixels(aTwips); sl@0: } sl@0: sl@0: /** Gets the RGB value of the specified pixel. sl@0: Note: The method only works for uncompressed bitmaps and extended bitmaps. sl@0: @param aColor On return, the RGB value of the specified pixel. sl@0: @param aPixel The pixel whose colour is to be determined. sl@0: @panic FBSCLI 11 in debug builds if this is a compressed bitmap. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C void CFbsBitmap::GetPixel(TRgb& aColor,const TPoint& aPoint) const sl@0: { sl@0: if(!iHandle) sl@0: { sl@0: return; sl@0: } sl@0: sl@0: TUint32* data; sl@0: CBitwiseBitmap* bmp = BeginDataAccessAndGetCleanAddress(data); sl@0: CFbsRasterizer* rasterizer = NULL; sl@0: if ((iFlags & EIsExtendedBitmap) && iFbs) sl@0: { sl@0: rasterizer = iFbs->iHelper->Rasterizer(); sl@0: if (rasterizer) sl@0: { sl@0: CFbsRasterizer::TBitmapDesc desc; sl@0: desc.iSizeInPixels = bmp->SizeInPixels(); sl@0: desc.iDispMode = bmp->DisplayMode(); sl@0: desc.iDataType = bmp->iUid; sl@0: desc.iData = data; sl@0: desc.iDataSize = bmp->iHeader.iBitmapSize - bmp->iHeader.iStructSize; sl@0: rasterizer->BeginBitmap(bmp->Extra()->iSerialNumber, desc, NULL); sl@0: } sl@0: } sl@0: bmp->GetPixel(aColor, aPoint, data, rasterizer); sl@0: if (rasterizer) sl@0: { sl@0: rasterizer->EndBitmap(bmp->Extra()->iSerialNumber); sl@0: } sl@0: EndDataAccess(ETrue); sl@0: } sl@0: sl@0: /** Gets the pixel-size of the bitmap. sl@0: @return The size of the bitmap, in pixels. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TSize CFbsBitmap::SizeInPixels() const sl@0: { sl@0: TSize zero; sl@0: if(!iHandle) return(zero); sl@0: return CleanAddress()->SizeInPixels(); sl@0: } sl@0: sl@0: /** Sets the twip-size of the bitmap by converting the bitmaps pixel-size from sl@0: pixels to twips, using the conversion functions in the specified graphics sl@0: device map. sl@0: @param aMap The graphics device map to be used for providing pixel to twip sl@0: conversion. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C void CFbsBitmap::SetSizeInTwips(const MGraphicsDeviceMap* aMap) sl@0: { sl@0: if (!iHandle || (iFlags & EIsRomBitmap) || aMap == NULL) sl@0: return; sl@0: TSize size=SizeInPixels(); sl@0: size.iWidth=aMap->HorizontalPixelsToTwips(size.iWidth); sl@0: size.iHeight=aMap->VerticalPixelsToTwips(size.iHeight); sl@0: iFbs->SetCallBackPtr(&iServerHandle); sl@0: iFbs->CallBack(); sl@0: // SizeInPixels() called CleanAddress() so call Address() now to make sure we don't clean the bitmap twice sl@0: Address()->iHeader.iSizeInTwips=size; sl@0: } sl@0: sl@0: /** Sets the twip-size of the bitmap directly to the specified size. sl@0: @param aSizeInTwips The new size of the bitmap, in twips. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C void CFbsBitmap::SetSizeInTwips(const TSize& aSizeInTwips) sl@0: { sl@0: if (!iHandle || (iFlags & EIsRomBitmap)) sl@0: return; sl@0: iFbs->SetCallBackPtr(&iServerHandle); sl@0: iFbs->CallBack(); sl@0: CleanAddress()->iHeader.iSizeInTwips = aSizeInTwips; sl@0: } sl@0: sl@0: /** Externalises the bitmap to the specified stream. Not supported for extended bitmaps. sl@0: @param aStream The write stream. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C void CFbsBitmap::ExternalizeL(RWriteStream& aStream) const sl@0: { sl@0: if (!iHandle) sl@0: User::Leave(KErrGeneral); sl@0: BeginDataAccess(); sl@0: Address()->ExternalizeL(aStream, *this); sl@0: EndDataAccess(ETrue); sl@0: } sl@0: sl@0: /** Externalises that area of the bitmap contained within a specified sl@0: rectangular area. Not supported for extended bitmaps. sl@0: @param aStream The write stream sl@0: @param aRect The rectangular area of the bitmap to externalise. The bitmap sl@0: that is externalized will be of this size. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C void CFbsBitmap::ExternalizeRectangleL(RWriteStream& aStream,const TRect& aRect) const sl@0: { sl@0: if (!iHandle) sl@0: User::Leave(KErrGeneral); sl@0: BeginDataAccess(); sl@0: Address()->ExternalizeRectangleL(aStream, aRect, *this); sl@0: EndDataAccess(ETrue); sl@0: } sl@0: sl@0: /** Internalises a CFbsBitmap from a stream. sl@0: @param aStream The read stream. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C void CFbsBitmap::InternalizeL(RReadStream& aStream) sl@0: { sl@0: if(!iFbs) User::Leave(KErrCouldNotConnect); sl@0: Reset(); sl@0: SEpocBitmapHeader header; sl@0: CBitwiseBitmap::InternalizeHeaderL(aStream,header); sl@0: sl@0: TDisplayMode dispmode = CBitwiseBitmap::DisplayMode(header.iBitsPerPixel,header.iColor); sl@0: User::LeaveIfError(Create(header.iSizeInPixels,dispmode)); sl@0: sl@0: TUint32* data; sl@0: CBitwiseBitmap* bmp=BeginDataAccessAndGetCleanAddress(data); sl@0: bmp->iHeader=header; sl@0: TInt bytesize = header.iBitmapSize - header.iStructSize; sl@0: if (bytesize > 0) sl@0: { sl@0: bmp->DoInternalizeL(aStream, bytesize, data); sl@0: EndDataAccess(EFalse); sl@0: } sl@0: else sl@0: { sl@0: EndDataAccess(ETrue); sl@0: } sl@0: } sl@0: sl@0: EXPORT_C TInt CFbsBitmap::Compress() sl@0: { sl@0: return Compress(ERLECompression); sl@0: } sl@0: sl@0: /** Compresses bitmap in RAM. sl@0: @param aScheme specifies preferred compression type ERLECompression or EPaletteCompression sl@0: @return KErrNone on success, KErrGeneral if the bitmap handle is NULL, KErrAccessDenied if sl@0: the bitmap is in ROM or it is an extended bitmap, otherwise one of the system wide error codes. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TInt CFbsBitmap::Compress(TBitmapfileCompressionScheme aScheme) sl@0: { sl@0: if (!iHandle) sl@0: return KErrGeneral; sl@0: if (iFlags & EIsReadOnlyBitmapMask) sl@0: return KErrAccessDenied; sl@0: TPckgBuf handlebuf; sl@0: TIpcArgs args(iHandle, aScheme, &handlebuf); sl@0: TInt err = iFbs->SendCommand(EFbsMessBitmapCompress, args); sl@0: if (err != KErrNone) sl@0: return err; sl@0: iHandle = handlebuf().iHandle; sl@0: iServerHandle = handlebuf().iServerHandle; sl@0: iAddressPointer = (CBitwiseBitmap*)(iFbs->HeapBase() + handlebuf().iAddressOffset); sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** Submits the bitmap for asynchronous background compression. sl@0: @param aRequestStatus The request status which will be completed with the appropriate error code after the compression has finished sl@0: The error code will be KErrNone on success, KErrGeneral if the bitmap handle is NULL, KErrAccessDenied if the sl@0: bitmap is in ROM or it is an extended bitmap, otherwise one of the system wide error codes. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C void CFbsBitmap::CompressInBackground(TRequestStatus& aRequestStatus) sl@0: { sl@0: CompressInBackground(aRequestStatus, ERLECompression); sl@0: } sl@0: sl@0: /** Submits the bitmap for asynchronous background compression. No notification will be provided when the compression has completed. sl@0: @return KErrNone if the bitmap was successfully submitted to the background compression queue, KErrGeneral if the bitmap handle is NULL, sl@0: KErrAccessDenied if the bitmap is in ROM or it is an extended bitmap, otherwise another of the system-wide error codes. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TInt CFbsBitmap::CompressInBackground() sl@0: { sl@0: return CompressInBackground(ERLECompression); sl@0: } sl@0: sl@0: /** Submits the bitmap for asynchronous background compression. sl@0: @param aRequestStatus The request status which will be completed with the appropriate error code after the compression has finished. sl@0: The error code will be KErrNone on success, KErrGeneral if the bitmap handle is NULL, KErrAccessDenied if the sl@0: bitmap is in ROM or it is an extended bitmap, otherwise one of the system wide error codes. sl@0: @param aScheme Specifies preferred compression type: ERLECompression or EPaletteCompression sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C void CFbsBitmap::CompressInBackground(TRequestStatus& aRequestStatus, TBitmapfileCompressionScheme aScheme) sl@0: { sl@0: TRequestStatus* reqStat = &aRequestStatus; sl@0: aRequestStatus = KRequestPending; sl@0: if (!iHandle) sl@0: User::RequestComplete(reqStat, KErrGeneral); sl@0: else if (iFlags & EIsReadOnlyBitmapMask) sl@0: User::RequestComplete(reqStat, KErrAccessDenied); sl@0: else sl@0: { sl@0: TIpcArgs args(iHandle, aScheme, ETrue); sl@0: iFbs->SendCommand(EFbsMessBitmapBgCompress, args, aRequestStatus); sl@0: } sl@0: } sl@0: sl@0: /** Submits the bitmap for asynchronous background compression. No notification will be provided when the compression has completed. sl@0: @return KErrNone if the bitmap was successfully submitted to the background compression queue, KErrGeneral if the bitmap handle is NULL, sl@0: KErrAccessDenied if the bitmap is in ROM or it is an extended bitmap, otherwise another of the system-wide error codes. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TInt CFbsBitmap::CompressInBackground(TBitmapfileCompressionScheme aScheme) sl@0: { sl@0: if (!iHandle) sl@0: return KErrGeneral; sl@0: if (iFlags & EIsReadOnlyBitmapMask) sl@0: return KErrAccessDenied; sl@0: TIpcArgs args(iHandle, aScheme, EFalse); sl@0: return iFbs->SendCommand(EFbsMessBitmapBgCompress, args); sl@0: } sl@0: sl@0: /**Tests whether the bitmap located in RAM has been compressed. sl@0: @return ETrue if the bitmap is compressed, EFalse otherwise. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TBool CFbsBitmap::IsCompressedInRAM() const sl@0: { sl@0: CBitwiseBitmap* bitmap = CleanAddress(); sl@0: if (bitmap==NULL) sl@0: { sl@0: return EFalse; sl@0: } sl@0: return bitmap->IsCompressedInRAM(); sl@0: } sl@0: sl@0: /** Gets the twip-size of the bitmap. sl@0: @return The size of the bitmap, in twips. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TSize CFbsBitmap::SizeInTwips() const sl@0: { sl@0: TSize zero; sl@0: if(iHandle==NULL) return(zero); sl@0: return CleanAddress()->SizeInTwips(); sl@0: } sl@0: sl@0: /** Converts a vertical dimension on the graphics device from pixels to twips. sl@0: @param aPixels A vertical dimension on the graphics device in pixels. sl@0: @return A vertical dimension on the graphics device in twips. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TInt CFbsBitmap::VerticalPixelsToTwips(TInt aPixels) const sl@0: { sl@0: if(iHandle==NULL) return(0); sl@0: return CleanAddress()->VerticalPixelsToTwips(aPixels); sl@0: } sl@0: sl@0: /** Converts a vertical dimension on the graphics device from twips to pixels. sl@0: @param aTwips A vertical dimension on the graphics device in twips. sl@0: @return A vertical dimension on the graphics device in pixels. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TInt CFbsBitmap::VerticalTwipsToPixels(TInt aTwips) const sl@0: { sl@0: if(iHandle==NULL) return(0); sl@0: return CleanAddress()->VerticalTwipsToPixels(aTwips); sl@0: } sl@0: sl@0: /** Tests whether or not the specified file is in ROM. sl@0: @param aFilename The name of the file. sl@0: @param aWord On return, contains the address of the file in ROM. sl@0: @return ETrue if the file is in the ROM; EFalse otherwise. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TBool CFbsBitmap::IsFileInRom(const TDesC& aFilename,TUint32*& aWord) sl@0: { sl@0: RFbsSession* fbs=RFbsSession::GetSession(); sl@0: __ASSERT_ALWAYS(fbs,Panic(EFbsPanicNoConnection)); sl@0: return fbs->LookupBitmapInROM (aFilename, (TAny*&)aWord); sl@0: } sl@0: sl@0: /** Tests whether or not the specified file is in ROM. sl@0: @param aFile The file handle sl@0: @param aWord On return, contains the address of the file in ROM. sl@0: @return ETrue if the file is in the ROM; EFalse otherwise. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TBool CFbsBitmap::IsFileInRom(RFile& aFile,TUint32*& aWord) sl@0: { sl@0: // cannot use rom lookup cache as filename is not available sl@0: // offset must be initialised to zero to indicate beginning of the file sl@0: aWord = 0; sl@0: return aFile.Seek(ESeekAddress,(TInt&)aWord)==KErrNone; sl@0: } sl@0: sl@0: /** Tests whether or not the bitmap is monochrome. sl@0: Monochrome bitmaps have a display-mode of 1 bit-per-pixel. sl@0: @return ETrue if the bitmap is monochrome; EFalse otherwise. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TBool CFbsBitmap::IsMonochrome() const sl@0: { sl@0: if(!iHandle) return(EFalse); sl@0: TUint32* data; sl@0: CBitwiseBitmap* bmp = BeginDataAccessAndGetCleanAddress(data); sl@0: TBool isMonochrome = bmp->IsMonochrome(data); sl@0: EndDataAccess(ETrue); sl@0: return isMonochrome; sl@0: } sl@0: sl@0: /** Marks the beginning of direct access to the bitmap data. sl@0: This function prepares the bitmap for direct access to its pixel data sl@0: and should be used before calling DataAddress(), otherwise performance sl@0: may be degraded on certain platforms. sl@0: Calls to BeginDataAccess() must be coupled with subsequent calls to EndDataAccess(). sl@0: sl@0: @publishedAll sl@0: @released sl@0: @see CFbsBitmap::DataAddress() sl@0: @see CFbsBitmap::EndDataAccess() sl@0: */ sl@0: EXPORT_C void CFbsBitmap::BeginDataAccess() const sl@0: { sl@0: FBS_OST_VERBOSE(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_BEGINDATAACCESS_ENTRY, "> this=0x%08x;", (TUint)this);); sl@0: FBS_OST_IF(!iHandle, OstTrace1(TRACE_ERROR, CFBSBITMAP_BEGINDATAACCESS_ERROR, "! this=0x%08x; !iHandle", (TUint)this);); sl@0: sl@0: if (iHandle) sl@0: { sl@0: (void)CleanAddress(); //called for side-effect to make sure bitmap reference is current. Should be low overhead. sl@0: const_cast(this)->iUseCount++; sl@0: } sl@0: sl@0: FBS_OST_VERBOSE(OstTraceExt2(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_BEGINDATAACCESS_EXIT, "< this=0x%08x; iUseCount=%d;", (TUint)this, const_cast(this)->iUseCount);) sl@0: } sl@0: sl@0: /** Marks the end of direct access to the bitmap data. sl@0: Use this function after ending direct access to the bitmap data. sl@0: Calls to EndDataAccess() must correspond to prior calls to BeginDataAccess(). sl@0: See BeginDataAccess() for more details. sl@0: sl@0: @param aReadOnly Whether or not the bitmap data has only been read since sl@0: the corresponding call to BeginDataAccess(). sl@0: sl@0: @publishedAll sl@0: @released sl@0: @param aReadOnly True if the bitmap data had only been read. False if the data has been modified. sl@0: @see CFbsBitmap::BeginDataAccess() sl@0: */ sl@0: EXPORT_C void CFbsBitmap::EndDataAccess(TBool aReadOnly) const sl@0: { sl@0: FBS_OST_VERBOSE(OstTraceExt2(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_ENDDATAACCESS_ENTRY, "> this=0x%08x; aReadOnly=%d;", (TUint)this, (TUint)aReadOnly);) sl@0: FBS_OST_IF(!iHandle, OstTrace1(TRACE_ERROR, CFBSBITMAP_ENDDATAACCESS_ERROR, "! this=0x%08x; !iHandle", (TUint)this);); sl@0: if (iHandle) sl@0: { sl@0: const_cast(this)->iUseCount--; sl@0: if (!aReadOnly && !(iFlags & EIsReadOnlyBitmapMask)) sl@0: { sl@0: User::LockedInc(iAddressPointer->Extra()->iTouchCount); sl@0: } sl@0: } sl@0: FBS_OST_VERBOSE(OstTraceExt2(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_ENDDATAACCESS_EXIT, "< this=0x%08x; iUseCount=%d;", (TUint)this, const_cast(this)->iUseCount);) sl@0: } sl@0: sl@0: /** Locks the global bitmap heap. sl@0: This function is deprecated, since it is no longer necessary to lock the global sl@0: bitmap heap to prevent the pixel data from being moved in memory asynchronously, sl@0: as the value returned by DataAddress() can now only change as a result of bitmap sl@0: operations explicitly requested by clients of the Font and Bitmap Server. sl@0: Calls to LockHeap() should be replaced by calls to BeginDataAccess(). sl@0: sl@0: Calls to LockHeap() must be coupled with subsequent calls to CFbsBitmap::UnlockHeap(). sl@0: Code called between a LockHeap() - UnlockHeap() pair must not include any other calls to sl@0: CFbsBitmap methods, which internally may call CFbsBitmap::LockHeap(). Also, code must sl@0: not leave between a LockHeap() - UnlockHeap() pair. sl@0: @note IMPORTANT: CFbsBitmap::LockHeap() cannot be used as a means of synchronization between sl@0: threads concurrently accessing bitmap data. sl@0: sl@0: @publishedAll sl@0: @deprecated sl@0: @see CFbsBitmap::UnlockHeap() sl@0: @see CFbsBitmap::BeginDataAccess() sl@0: */ sl@0: EXPORT_C void CFbsBitmap::LockHeap(TBool /*aAlways*/) const sl@0: { sl@0: FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_LOCKHEAP_ENTRY, "> this=0x%08x;", (TUint)this);) sl@0: BeginDataAccess(); sl@0: #ifdef SYMBIAN_DEBUG_FBS_LOCKHEAP sl@0: //These debug checks now refer to the cleaned data address sl@0: FBS_OST_IF(!iHandle, OstTrace1(TRACE_ERROR, CFBSBITMAP_LOCKHEAP_ERROR, "! this=0x%08x; !iHandle", (TUint)this);); sl@0: if (iHandle && !(iFlags & EIsRomBitmap)) // can't do anything with ROM bitmaps sl@0: { sl@0: TThreadId threadId = RThread().Id(); sl@0: iFbs->iHelper->iDebugMutex.Wait(); sl@0: if (iAddressPointer->Extra()->iLockCount++ == 0) sl@0: { sl@0: __ASSERT_ALWAYS(iAddressPointer->Extra()->iThreadId == TThreadId(KNullThreadId), Panic(EFbsPanicBadHeapLock)); sl@0: iAddressPointer->Extra()->iThreadId = threadId; sl@0: } sl@0: else sl@0: __ASSERT_ALWAYS(iAddressPointer->Extra()->iThreadId == threadId, Panic(EFbsPanicBadHeapLock)); sl@0: iFbs->iHelper->iDebugMutex.Signal(); sl@0: } sl@0: #endif sl@0: FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_LOCKHEAP_EXIT, "< this=0x%08x;", (TUint)this);) sl@0: } sl@0: sl@0: /** Unlocks the global heap. sl@0: This function is deprecated. See LockHeap() for more details. sl@0: Calls to UnlockHeap() should be replaced by calls to EndDataAccess(). sl@0: Calls to UnlockHeap() must correspond to prior calls to LockHeap() or LockHeapLC(). sl@0: sl@0: @publishedAll sl@0: @deprecated sl@0: @see CFbsBitmap::LockHeap() sl@0: @see CFbsBitmap::EndDataAccess() sl@0: */ sl@0: EXPORT_C void CFbsBitmap::UnlockHeap(TBool /*aAlways*/) const sl@0: { sl@0: FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_UNLOCKHEAP_ENTRY, "> this=0x%08x;", (TUint)this);) sl@0: FBS_OST_IF(!iHandle, OstTrace1(TRACE_ERROR, CFBSBITMAP_UNLOCKHEAP_ERROR, "! this=0x%08x; !iHandle", (TUint)this);); sl@0: if (iHandle) sl@0: { sl@0: #ifdef SYMBIAN_DEBUG_FBS_LOCKHEAP sl@0: if (!(iFlags & EIsRomBitmap)) // can't do anything with ROM bitmaps sl@0: { sl@0: TThreadId threadId = RThread().Id(); sl@0: iFbs->iHelper->iDebugMutex.Wait(); sl@0: __ASSERT_ALWAYS(iAddressPointer->Extra()->iLockCount > 0, Panic(EFbsPanicBadHeapLock)); sl@0: __ASSERT_ALWAYS(iAddressPointer->Extra()->iThreadId == threadId, Panic(EFbsPanicBadHeapLock)); sl@0: if (--iAddressPointer->Extra()->iLockCount == 0) sl@0: iAddressPointer->Extra()->iThreadId = TThreadId(KNullThreadId); sl@0: iFbs->iHelper->iDebugMutex.Signal(); sl@0: } sl@0: #endif sl@0: EndDataAccess(); sl@0: } sl@0: FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_UNLOCKHEAP_EXIT, "< this=0x%08x;", (TUint)this);) sl@0: } sl@0: sl@0: /** Locks the global bitmap heap, leaving on the clean-up stack a pointer sl@0: to a TCleanupItem that unlocks the heap on deletion. sl@0: Use this function instead of LockHeap() if code may leave between the sl@0: LockHeap() - UnlockHeap() pair. Calls to LockHeapLC() must be coupled with sl@0: subsequent calls to CFbsBitmap::UnlockHeap() or CleanupStack::PopAndDestroy(). sl@0: This function is deprecated. See CFbsBitmap::LockHeap() for more details. sl@0: sl@0: @publishedAll sl@0: @deprecated sl@0: @see CFbsBitmap::LockHeap() sl@0: */ sl@0: EXPORT_C void CFbsBitmap::LockHeapLC(TBool /*aAlways*/) const sl@0: { sl@0: FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_LOCKHEAPLC_ENTRY, "> this=0x%08x;", (TUint)this);) sl@0: LockHeap(); sl@0: TCleanupItem cleanitem(CFbsBitmap::UnlockHeap, (TAny*)this); sl@0: CleanupStack::PushL(cleanitem); sl@0: FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_LOCKHEAPLC_EXIT, "< this=0x%08x;", (TUint)this);) sl@0: } sl@0: sl@0: EXPORT_C void CFbsBitmap::UnlockHeap(TAny* aFbsBitmap) sl@0: { sl@0: FBS_OST(OstTrace1(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_UNLOCKHEAP2_ENTRY, "> bitmap=0x%08x;", (TUint)aFbsBitmap);) sl@0: ((CFbsBitmap*)aFbsBitmap)->UnlockHeap(); sl@0: FBS_OST(OstTrace0(GRAPHICS_CONTROL_FUNCTIONS, CFBSBITMAP_UNLOCKHEAP2_EXIT, "<");) sl@0: } sl@0: sl@0: /** Tests whether the bitmap is volatile. sl@0: A bitmap becomes volatile if CFbsBitmap::DataAdress() is called without sl@0: CFbsBitmap::BeginDataAccess() having been called before and it can become non-volatile sl@0: again if a resizing or compression is performed. sl@0: sl@0: @internalTechnology sl@0: @prototype sl@0: */ sl@0: EXPORT_C TBool CFbsBitmap::IsVolatile() const sl@0: { sl@0: if (!iHandle) sl@0: return EFalse; sl@0: return CleanAddress()->iSettings.IsVolatileBitmap(); sl@0: } sl@0: sl@0: /** Tests how many times the bitmap has been touched. sl@0: A bitmap is touched whenever CFbsBitmap::EndDataAccess() is called with the parameter sl@0: aReadOnly set to EFalse and also whenever a resizing or compression is performed. sl@0: sl@0: @internalTechnology sl@0: @prototype sl@0: @return The number of times the bitmap has been touched. sl@0: */ sl@0: EXPORT_C TInt CFbsBitmap::TouchCount() const sl@0: { sl@0: if (!iHandle || (iFlags & EIsReadOnlyBitmapMask)) sl@0: return 0; // A read-only bitmap can never be touched. sl@0: return CleanAddress()->Extra()->iTouchCount; sl@0: } sl@0: sl@0: /** Returns the serial number of the bitmap sl@0: The serial number is unique to this bitmap. sl@0: The serial number is a signed 64-bit integer, with only the positive values being assigned. sl@0: As ROM bitmaps do not have serial numbers, the serial number will use the negative range sl@0: of values so that ROM bitmap's serial number cannot be the same as a RAM bitmap's. sl@0: ROM bitmap's address pointers are unique to the ROM bitmap, so the serial number will just sl@0: be negative value of the address pointer. sl@0: sl@0: @internalTechnology sl@0: @prototype sl@0: @return The unique serial number for the bitmap sl@0: */ sl@0: EXPORT_C TInt64 CFbsBitmap::SerialNumber() const sl@0: { sl@0: if (!iHandle) sl@0: return 0; sl@0: if (iFlags & EIsRomBitmap) sl@0: return -TInt64(reinterpret_cast(iAddressPointer)); sl@0: return CleanAddress()->Extra()->iSerialNumber; sl@0: } sl@0: sl@0: /** Tests whether the bitmap is large. sl@0: @return ETrue if the bitmap is large, EFalse if not. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TBool CFbsBitmap::IsLargeBitmap() const sl@0: { sl@0: CBitwiseBitmap* bitmap = CleanAddress(); sl@0: if (!bitmap) sl@0: { sl@0: return EFalse; sl@0: } sl@0: return bitmap->IsLargeBitmap(); sl@0: } sl@0: sl@0: /** Returns the handle for the hardware bitmap which this CFbsBitmap is using. sl@0: @return The handle to the hardware bitmap. The handle is NULL if it is not sl@0: a hardware bitmap. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TInt CFbsBitmap::HardwareBitmapHandle() const sl@0: { sl@0: CBitwiseBitmap* bitmap = CleanAddress(); sl@0: if (!bitmap) sl@0: { sl@0: return 0; sl@0: } sl@0: return bitmap->HardwareBitmapHandle(); sl@0: } sl@0: sl@0: /** Gets the attributes of the bitmap's palette. sl@0: This is not currently supported. sl@0: @param aModifiable On return, whether or not the palette is modifiable. sl@0: @param aNumEntries On return, the number of entries in the palette. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C void CFbsBitmap::PaletteAttributes(TBool& aModifiable,TInt& aNumEntries) const sl@0: { sl@0: aModifiable=EFalse; sl@0: aNumEntries=0; sl@0: } sl@0: sl@0: /** Sets the bitmap's palette. sl@0: This is not currently supported. sl@0: @param aPalette Not used. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C void CFbsBitmap::SetPalette(CPalette* /*aPalette*/) sl@0: { sl@0: } sl@0: sl@0: /** Gets the bitmap's palette. sl@0: This is not currently supported. sl@0: @param aPalette Not used. sl@0: @return KErrNotSupported. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TInt CFbsBitmap::GetPalette(CPalette*& /*aPalette*/) const sl@0: { sl@0: return(KErrNotSupported); sl@0: } sl@0: sl@0: /** sl@0: @internalComponent sl@0: This method loads a bitmap from an opened file handle. sl@0: sl@0: @param aFile mbm or rsc file handle (rsc file format: header + rsc sl@0: data section + mbm file section). sl@0: @param aId Bitmap ID - should be less than mbm file bitmaps count. sl@0: @param aShareIfLoaded Specifies whether or not the loaded bitmap will be sl@0: made available for sharing between FBSERV clients. sl@0: @param aFileOffset mbm file section offset into rsc file. sl@0: @return KErrNone if successful, otherwise another sl@0: of the system-wide error codes. sl@0: */ sl@0: TInt CFbsBitmap::DoLoad(RFile& aFile,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset) sl@0: { sl@0: TInt ret=KErrNone; sl@0: TPckgBuf handlebuf; sl@0: TPckgBuf loadBitmapArg; sl@0: loadBitmapArg().iBitmapId = aId; sl@0: loadBitmapArg().iShareIfLoaded = TInt(aShareIfLoaded); sl@0: loadBitmapArg().iFileOffset = aFileOffset; sl@0: //Getting the RFs Handle(2) and RFile handle(3) into a TIpcArgs into 2nd and 3rd argument sl@0: TIpcArgs fileargs; sl@0: ret=aFile.TransferToServer(fileargs,2,3); sl@0: if (ret!=KErrNone) sl@0: return ret; sl@0: fileargs.Set(0,&handlebuf); sl@0: fileargs.Set(1,&loadBitmapArg); sl@0: ret=iFbs->SendCommand(EFbsMessBitmapLoad,fileargs); sl@0: if(ret!=KErrNone) return(ret); sl@0: iHandle=handlebuf().iHandle; sl@0: iServerHandle=handlebuf().iServerHandle; sl@0: iAddressPointer=(CBitwiseBitmap*)(iFbs->HeapBase()+handlebuf().iAddressOffset); sl@0: ret = iFbs->iHelper->AddBitmap(*this); sl@0: if (ret != KErrNone) sl@0: return ret; sl@0: return iFbs->AllocScanLineBuffer(iAddressPointer->iByteWidth+4); sl@0: } sl@0: sl@0: /** sl@0: @internalComponent sl@0: This method loads a bitmap from the mbm or rsc file specified by the filename. sl@0: sl@0: @param aFileName mbm or rsc file name (rsc file format: header + rsc sl@0: data section + mbm file section). sl@0: @param aId Bitmap ID - should be less than mbm file bitmaps count. sl@0: @param aShareIfLoaded Specifies whether or not the loaded bitmap will be sl@0: made available for sharing between FBSERV clients. sl@0: @param aFileOffset mbm file section offset into rsc file. sl@0: @return KErrNone if successful, otherwise another sl@0: of the system-wide error codes. sl@0: */ sl@0: TInt CFbsBitmap::DoLoad(const TDesC& aFileName,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset) sl@0: { sl@0: TInt ret=KErrNone; sl@0: TPckgBuf handlebuf; sl@0: TPckgBuf loadBitmapArg; sl@0: loadBitmapArg().iBitmapId = aId; sl@0: loadBitmapArg().iShareIfLoaded = TInt(aShareIfLoaded); sl@0: loadBitmapArg().iFileOffset = aFileOffset; sl@0: TIpcArgs fileargs; sl@0: fileargs.Set(0,&handlebuf); sl@0: fileargs.Set(1,&loadBitmapArg); sl@0: fileargs.Set(2,&aFileName); sl@0: ret=iFbs->SendCommand(EFbsMessBitmapLoadFast,fileargs); sl@0: if(ret!=KErrNone) return(ret); sl@0: iHandle=handlebuf().iHandle; sl@0: iServerHandle=handlebuf().iServerHandle; sl@0: iAddressPointer=(CBitwiseBitmap*)(iFbs->HeapBase()+handlebuf().iAddressOffset); sl@0: ret = iFbs->iHelper->AddBitmap(*this); sl@0: if (ret != KErrNone) sl@0: return ret; sl@0: return iFbs->AllocScanLineBuffer(iAddressPointer->iByteWidth+4); sl@0: } sl@0: sl@0: /** sl@0: @internalComponent sl@0: This method handles very special case when the rsc file is in RAM, but it sl@0: contains ROM mbm file. ROM mbm file format is different than RAM mbm file sl@0: format and ROM mbm file cannot be loaded into RAM using standard techniques sl@0: (used by CFbsBitmap::DoLoad()). We have to check it is really a ROM mbm file. sl@0: If it is - we have to allocate the right amount of RAM, read and copy sl@0: requested ROM bitmap to the allocated RAM. sl@0: sl@0: @leave KErrNotSupported if this is a RAM rsc file with ROM mbm file section, sl@0: or any of the RFile related error codes. sl@0: @param aFileName rsc file name (rsc file format: header + rsc data section + sl@0: mbm file section). sl@0: @param aId Bitmap ID - should be less than mbm file bitmaps count. sl@0: @param aFileOffset mbm file section offset into rsc file. sl@0: @return EFalse - this is not a ROM mbm file. ETrue - this is a ROM mbm file sl@0: and requested by aId bitmmap is loaded. sl@0: */ sl@0: TBool CFbsBitmap::LoadShiftedRomBmpL(const TDesC& aFileName, TInt32 aId, TUint aFileOffset) sl@0: { sl@0: RFile mbm_file; sl@0: ::CleanupClosePushL(mbm_file); sl@0: User::LeaveIfError(mbm_file.Open(iFbs->FileServer(), aFileName, EFileRead | EFileShareReadersOnly)); sl@0: TInt pos = static_cast (aFileOffset); sl@0: User::LeaveIfError(mbm_file.Seek(ESeekStart, pos));//move to the beginning of the mbm file section sl@0: TBuf8 buf; sl@0: //Check if it is a ROM mbm file sl@0: User::LeaveIfError(mbm_file.Read(buf, sizeof(KMultiBitmapRomImageUid.iUid)));//Bitmap file UID - ROM or RAM sl@0: TInt32 mbm_uid = *(reinterpret_cast (buf.Ptr())); sl@0: TBool loaded = EFalse; sl@0: if(mbm_uid == KMultiBitmapRomImageUid.iUid) sl@0: { sl@0: if(!KRomMBMInRamRSC) sl@0: { sl@0: User::Leave(KErrNotSupported); sl@0: } sl@0: else sl@0: { sl@0: User::LeaveIfError(mbm_file.Read(buf, sizeof(TInt32)));//Number of bitmaps sl@0: TInt32 bmp_cnt = *(reinterpret_cast (buf.Ptr())); sl@0: if(aId >= bmp_cnt) sl@0: { sl@0: User::Leave(KErrNotFound); sl@0: } sl@0: for(TInt i=0;i (buf.Ptr())) + TInt(aFileOffset); sl@0: pos = static_cast (bmp_offset); sl@0: User::LeaveIfError(mbm_file.Seek(ESeekStart, pos));//move the file pointer to the bitmap sl@0: User::LeaveIfError(mbm_file.Read(buf, sizeof(CBitwiseBitmap)));//Read CBitwiseBitmap data (without the bitmap data) sl@0: const CBitwiseBitmap* bmp = reinterpret_cast (buf.Ptr()); sl@0: //Calculate bitmap data size, alocate enough memory for the bitmap, copy CBitwiseBitmap sl@0: //members first, read the bitmap data from the file, copy the data to the allocated memory, sl@0: //initialize iRomPointer. sl@0: //If sizeof(CBitwiseBitmap) != real size of CBitwiseBitmap then we could have problems, sl@0: //because bitmap data won't be copied at the right position. sl@0: TInt size = bmp->iHeader.iBitmapSize - sizeof(SEpocBitmapHeader) + sizeof(CBitwiseBitmap); sl@0: TUint8* bmp_mem = new (ELeave) TUint8[size]; sl@0: //There is no need bmp_mem to be aligned, because it is a pointer to a RAM block of memory. sl@0: TCleanupItem cleanitem(FreeMem, bmp_mem); sl@0: CleanupStack::PushL(cleanitem); sl@0: Mem::Copy(bmp_mem, bmp, sizeof(CBitwiseBitmap)); sl@0: TPtr8 pbmp(bmp_mem + sizeof(CBitwiseBitmap), size - sizeof(CBitwiseBitmap)); sl@0: User::LeaveIfError(mbm_file.Read(pbmp, size - sizeof(CBitwiseBitmap)));//read the bitmap data. We've already read the CBitwiseBitmap data. sl@0: CleanupStack::Pop(bmp_mem); sl@0: iAddressPointer = reinterpret_cast(bmp_mem); sl@0: iFlags = EIsRomBitmap; sl@0: iHandle = 1; sl@0: loaded = ETrue; sl@0: }//end of - if(!KRomMBMInRamRSC) - "else" part sl@0: }//end of - if(mbm_uid == KMultiBitmapRomImageUid.iUid) sl@0: CleanupStack::PopAndDestroy();//mbm_file sl@0: return loaded; sl@0: } sl@0: sl@0: /** sl@0: Swaps the bitmap's width and height. sl@0: For example, if the bitmap's size is (40, 20), the new size will be (20, 40). sl@0: Bitmap content is not preserved. sl@0: @publishedAll sl@0: @released sl@0: @return KErrNone if the call was successful, KErrGeneral if the bitmap handle is sl@0: invalid, KErrAccessDenied if the bitmap is in ROM, KErrNotSupported if the bitmap sl@0: is a hardware bitmap or an extended bitmap. sl@0: */ sl@0: EXPORT_C TInt CFbsBitmap::SwapWidthAndHeight() sl@0: { sl@0: if(!iHandle) sl@0: { sl@0: return KErrGeneral; sl@0: } sl@0: TUint32* data; sl@0: CBitwiseBitmap* bmp = BeginDataAccessAndGetCleanAddress(data); sl@0: sl@0: // Check the new bitmap size here then decide whether to swap the bitmap on the sl@0: // client side or send it to be done on the server and reallocate memory for it. sl@0: TInt newWidthInBytes = CBitwiseBitmap::ByteWidth(bmp->iHeader.iSizeInPixels.iHeight, bmp->iSettings.CurrentDisplayMode()); sl@0: TInt64 hugeDataSize = TInt64(bmp->iHeader.iSizeInPixels.iWidth) * TInt64(newWidthInBytes); sl@0: sl@0: TInt err = KErrNone; sl@0: // If the size of the new swapped bitmap is less than or equal its original size before the swap, sl@0: // then we do not need to reallocate memory. The swapping is straight forward. sl@0: if( I64HIGH(hugeDataSize) == 0 && I64LOW(hugeDataSize) <= TUint(bmp->iHeader.iBitmapSize - bmp->iHeader.iStructSize) ) sl@0: { sl@0: err = bmp->SwapWidthAndHeight(data); sl@0: // Even though used DataAddress() as read-only, need to increment touch count, so indicate that data has been written sl@0: EndDataAccess(EFalse); sl@0: } sl@0: // Otherwise we need to reallocate memory. We do this by using the already exisitng sl@0: // Resize() function as a work around- Code Reusability!! sl@0: else sl@0: { sl@0: EndDataAccess(ETrue); // Used DataAddress() to read only. sl@0: // Resize will increase touch counter sl@0: err = Resize(TSize(bmp->iHeader.iSizeInPixels.iHeight, bmp->iHeader.iSizeInPixels.iWidth)); sl@0: } sl@0: return err; sl@0: } sl@0: sl@0: /** Gets a pointer to the decompression buffer owned by this thread's FBServ session. sl@0: @param aSize The size in bytes of the scan lines to decompress. sl@0: @return A pointer to the decompression buffer or NULL if there is no FBServ session. sl@0: @internalTechnology sl@0: @released sl@0: */ sl@0: EXPORT_C HBufC8* CFbsBitmap::GetDecompressionBuffer(TInt aSize) sl@0: { sl@0: RFbsSession* ses=RFbsSession::GetSession(); sl@0: return ses? ses->GetDecompressionBuffer(aSize) : NULL; sl@0: } sl@0: sl@0: /** Gets a pointer to the rasterizer for extended bitmaps if present. sl@0: @return A pointer to the rasterizer owned by this thread's FBServ session. sl@0: @return NULL if the rasterizer is not present. sl@0: @internalTechnology sl@0: @prototype sl@0: */ sl@0: EXPORT_C CFbsRasterizer* CFbsBitmap::Rasterizer() sl@0: { sl@0: RFbsSession* session = RFbsSession::GetSession(); sl@0: return session ? session->iHelper->Rasterizer() : NULL; sl@0: } sl@0: sl@0: /** Loads a specific bitmap from an opened multi-bitmap file handle. sl@0: The bitmap may be shared by other font and bitmap server clients. sl@0: @param aFile The handle of the multi-bitmap (.mbm) file. sl@0: @param aId The bitmap identifier. sl@0: @param aShareIfLoaded Specifies whether or not the loaded bitmap will be made sl@0: available for sharing between font and bitmap server clients. sl@0: @return KErrNone if successful, otherwise another of the system error sl@0: codes. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TInt CFbsBitmap::Load(RFile& aFile,TInt32 aId/*=0*/,TBool aShareIfLoaded/*=ETrue*/) sl@0: { sl@0: FBS_OST(TFullName fileName;) sl@0: FBS_OST(aFile.FullName(fileName);) sl@0: 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: TInt ret = Load(aFile,aId,aShareIfLoaded,0); sl@0: FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOAD3_EXIT, "< this=0x%08x, ret=%d", (TUint)this, ret);) sl@0: return ret; sl@0: } sl@0: sl@0: /** Loads a specific bitmap from an opened multi-bitmap file handle. sl@0: The bitmap may be shared by other font and bitmap server clients. sl@0: @param aFile The handle of the multi-bitmap (.mbm) file. sl@0: @param aId The bitmap identifier. sl@0: @param aShareIfLoaded Specifies whether or not the loaded bitmap will be made sl@0: available for sharing between FBSERV clients. sl@0: @param aFileOffset Bitmap file section offset within the file. sl@0: @return KErrNone if successful, otherwise another of the system error codes. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TInt CFbsBitmap::Load(RFile& aFile,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset) sl@0: { sl@0: TInt err = KErrNone; sl@0: FBS_OST(TFullName fileName;) sl@0: FBS_OST(aFile.FullName(fileName);) sl@0: 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: if (!iFbs) sl@0: { sl@0: FBS_OST(OstTrace1( TRACE_ERROR, CFBSBITMAP_LOAD4_ERROR, "! this=0x%08x; !iFbs", (TUint)this);) sl@0: err = KErrCouldNotConnect; sl@0: } sl@0: else sl@0: { sl@0: Reset(); sl@0: TUint32* rompointer; sl@0: IsFileInRom(aFile,rompointer); sl@0: TBool romPointerValid; sl@0: err = DoLoadFromRom(rompointer, aId, aFileOffset, romPointerValid); sl@0: if (!romPointerValid) sl@0: { sl@0: err = DoLoad(aFile,aId,aShareIfLoaded,aFileOffset); sl@0: FBS_OST_IF(err!=KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_LOAD4_ERROR2, "! this=0x%08x; DoLoad() returned %d", (TUint)this, err);) sl@0: } sl@0: } sl@0: FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOAD4_EXIT, "< this=0x%08x; err=%d", (TUint)this, err);) sl@0: return err; sl@0: } sl@0: sl@0: /** Loads and compresses a specific bitmap from an opened multi-bitmap file handle. sl@0: The bitmap may be shared by other font and bitmap server clients. sl@0: If the bitmap is loaded from ROM then compression is not allowed. sl@0: @param aFile The handle of the multi-bitmap (.mbm) file. sl@0: @param aId The bitmap identifier. sl@0: @param aShareIfLoaded Specifies whether or not the loaded bitmap will be sl@0: made available for sharing between FBSERV clients. sl@0: @return KErrNone if successful, otherwise another of the system-wide error sl@0: codes. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TInt CFbsBitmap::LoadAndCompress(RFile& aFile,TInt32 aId/*=0*/,TBool aShareIfLoaded/*=ETrue*/) sl@0: { sl@0: FBS_OST(TFullName fileName;) sl@0: FBS_OST(aFile.FullName(fileName);) sl@0: 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: TInt ret = LoadAndCompress(aFile,aId,aShareIfLoaded,0); sl@0: FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOADANDCOMPRESS3_EXIT, "< this=0x%08x; ret=%d", (TUint)this, ret);) sl@0: return ret; sl@0: } sl@0: sl@0: /** Loads and compresses a specific bitmap from an opened multi-bitmap file handle. sl@0: The bitmap may be shared by other font and bitmap server clients. If the sl@0: bitmap is loaded from ROM then compression is not allowed. sl@0: @param aFile The handle of the multi-bitmap (.mbm) file. sl@0: @param aId The bitmap identifier. sl@0: @param aShareIfLoaded Specifies whether or not the loaded bitmap will be made sl@0: available for sharing between FBSERV clients. sl@0: @param aFileOffset Bitmap file section offset within the file. sl@0: @return KErrNone if successful, otherwise another of the system-wide error sl@0: codes. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TInt CFbsBitmap::LoadAndCompress(RFile& aFile,TInt32 aId,TBool aShareIfLoaded,TUint aFileOffset) sl@0: { sl@0: FBS_OST(TFullName fileName;) sl@0: FBS_OST(aFile.FullName(fileName);) sl@0: 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: TInt err = Load(aFile,aId,aShareIfLoaded,aFileOffset); sl@0: if (err == KErrNone) sl@0: { sl@0: if (!(iFlags & EIsRomBitmap)) sl@0: { sl@0: err = Compress(); sl@0: FBS_OST_IF(err!=KErrNone, OstTraceExt2( TRACE_ERROR, CFBSBITMAP_LOADANDCOMPRESS4_ERROR, "! this=0x%08x; Compress() returned %d", (TUint)this, err);) sl@0: } sl@0: else sl@0: { sl@0: err = KErrAccessDenied; sl@0: 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: } sl@0: } sl@0: FBS_OST(OstTraceExt2( GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS, CFBSBITMAP_LOADANDCOMPRESS4_EXIT, "< this=0x%08x; err=%d", (TUint)this, err);) sl@0: return err; sl@0: } sl@0: sl@0: /** Gets all the bitmap handles for all the bitmaps stored in the Font Bitmap Server. There is a limit of sl@0: the number of bitmaps that can be retrieved defined by KMaxBitmapHandleBufferSize. If this limit has been sl@0: reached then KErrOverflow will be returned. sl@0: @param aBitmapIdArray returns an array of all the bitmap handles sl@0: @return KErrNone if successful, KErrOverflow if the bitmapBuffer is not large enough to store sl@0: all the bitmap handles, otherwise another of the system-wide error codes. sl@0: @capability ReadDeviceData sl@0: @internalComponent sl@0: @released sl@0: */ sl@0: EXPORT_C TInt CFbsBitmap::GetAllBitmapHandles(RArray& aBitmapIdArray) const sl@0: { sl@0: RBuf8 bitmapBuffer; sl@0: TInt ret = bitmapBuffer.Create(KMaxBitmapHandleBufferSize); sl@0: if (ret==KErrNone) sl@0: { sl@0: TIpcArgs args(&bitmapBuffer); sl@0: ret=iFbs->SendCommand(EFbsGetAllBitmapHandles, args); sl@0: if (ret==KErrNone) sl@0: { sl@0: // Convert data returned from server and place into the RArray (aBitmapIdArray) sl@0: aBitmapIdArray.Reset(); sl@0: TInt* bitmapIdPtr = (TInt*)bitmapBuffer.Ptr(); sl@0: const TInt numBitmapIds = bitmapBuffer.Size() / KNumBytesPerBitmapHandle; // Divide by number of bytes per bitmap handle to get total number of bitmap IDs sl@0: for (TInt count=0; count (aRomPointer); sl@0: __ASSERT_DEBUG(!(TUint(temp) & 0x00000003),Panic(EFbsBitmapAlignment)); sl@0: temp += aFileOffset; sl@0: aRomPointer = reinterpret_cast (temp); sl@0: if(TInt32(*aRomPointer)==KMultiBitmapRomImageUid.iUid) sl@0: { sl@0: TInt numbitmaps = (TInt)*(aRomPointer+1); sl@0: if(aId>=numbitmaps) sl@0: { sl@0: return(KErrEof); sl@0: } sl@0: TInt offset = *(aRomPointer+aId+2); sl@0: iAddressPointer = (CBitwiseBitmap*)(((TUint8*)aRomPointer) + offset); sl@0: iFlags = EIsRomBitmap; sl@0: iHandle = 1; sl@0: return iFbs->AllocScanLineBuffer(iAddressPointer->iByteWidth + 4); sl@0: } sl@0: } sl@0: aRomPointerValid = EFalse; sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: /** sl@0: Creates an extended bitmap. Extended bitmaps are used to store immutable sl@0: data in a platform-specific format. They cannot be used as targets of sl@0: graphics contexts, and modification of their data via DataAddress() or sl@0: TBitmapUtil is not supported and results in undefined behaviour up to sl@0: and including process termination. sl@0: sl@0: Initialisation of the raw data of the new bitmap is carried out by copying sl@0: the data pointed to by the parameter aData. sl@0: sl@0: Read-only access to the raw data of an extended bitmap is provided by sl@0: DataAddress() and DataSize() in conjunction with BeginDataAccess() and sl@0: EndDataAccess(). sl@0: sl@0: Extended bitmaps have a conceptual size in pixels and a conceptual sl@0: display mode for compatibility purposes. The raw data can be independent sl@0: of these properties. sl@0: sl@0: @param aSizeInPixels The conceptual width and height of the new bitmap in pixels. sl@0: @param aDispMode The conceptual display mode of the new bitmap. sl@0: @param aType The UID identifying the data format of the new bitmap. Used by the sl@0: extended bitmap rasterizer to distinguish between different data types. sl@0: @param aData A pointer to the raw data to be stored in the new bitmap. sl@0: @param aDataSize The size in bytes of the raw data to be stored in the new bitmap. sl@0: @return KErrNone if successful; KErrArgument if the width or height specified in sl@0: aSizeInPixels is negative, aDispMode is an invalid display mode, aData is NULL, sl@0: aDataSize is negative or zero, or aDataType is a UID reserved for OS use; KErrTooBig sl@0: if the width or height specified in aSizeInPixels exceeds KMaxTInt/4, or aDataSize sl@0: exceeds KMaxTInt/2; otherwise another of the system-wide error codes. sl@0: @publishedPartner sl@0: @prototype sl@0: @see CFbsBitmap::DataAddress() sl@0: @see CFbsBitmap::DataSize() sl@0: @see CFbsBitmap::BeginDataAccess() sl@0: @see CFbsBitmap::EndDataAccess() sl@0: */ sl@0: EXPORT_C TInt CFbsBitmap::CreateExtendedBitmap(const TSize& aSizeInPixels, TDisplayMode aDispMode, TUid aType, const TAny* aData, TInt aDataSize) sl@0: { sl@0: TInt err; sl@0: 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: if (!aData || aDataSize == 0) sl@0: { sl@0: FBS_OST(OstTrace1( TRACE_ERROR, CFBSBITMAP_CREATEEXTENDEDBITMAP_ERROR, "! this=0x%08x; (!aData || aDataSize == 0)", (TUint)this);) sl@0: err = KErrArgument; sl@0: } sl@0: else sl@0: { sl@0: err = DoCreate(aSizeInPixels, aDispMode, aType, aDataSize); sl@0: if (err == KErrNone) sl@0: { sl@0: Mem::Copy(iFbs->iLargeBitmapChunk.Base() + iAddressPointer->iDataOffset, aData, aDataSize); sl@0: } sl@0: } sl@0: 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: return err; sl@0: } sl@0: sl@0: /** sl@0: Creates an extended bitmap. Extended bitmaps are used to store immutable sl@0: data in a platform-specific format. They cannot be used as targets of sl@0: graphics contexts, and modification of their data via DataAddress() or sl@0: TBitmapUtil is not supported and results in undefined behaviour up to sl@0: and including process termination. sl@0: sl@0: Initialisation of the raw data of the new bitmap is carried out by a sl@0: callback to the MFbsExtendedBitmapInitializer::InitExtendedBitmap() sl@0: function passed through the parameter aInitializer. sl@0: sl@0: Read-only access to the raw data of an extended bitmap is provided by sl@0: DataAddress() and DataSize() in conjunction with BeginDataAccess() and sl@0: EndDataAccess(). sl@0: sl@0: Extended bitmaps have a conceptual size in pixels and a conceptual sl@0: display mode for compatibility purposes. The raw data can be independent sl@0: of these properties. sl@0: sl@0: @param aSizeInPixels The conceptual width and height of the new bitmap in pixels. sl@0: @param aDispMode The conceptual display mode of the new bitmap. sl@0: @param aType The UID identifying the data format of the new bitmap. Used by the sl@0: extended bitmap rasterizer to distinguish between different data types. sl@0: @param aDataSize The size in bytes of the raw data to be stored in the new bitmap. sl@0: @param aInitializer A reference to the initializer of the raw data to be stored in the new bitmap. sl@0: @return KErrNone if successful; KErrArgument if the width or height specified in sl@0: aSizeInPixels is negative, aDispMode is an invalid display mode, aData is NULL, sl@0: aDataSize is negative or zero, or aDataType is a UID reserved for OS use; KErrTooBig sl@0: if the width or height specified in aSizeInPixels exceeds KMaxTInt/4, or aDataSize sl@0: exceeds KMaxTInt/2; otherwise another of the system-wide error codes. sl@0: @publishedPartner sl@0: @prototype sl@0: @see CFbsBitmap::DataAddress() sl@0: @see CFbsBitmap::DataSize() sl@0: @see CFbsBitmap::BeginDataAccess() sl@0: @see CFbsBitmap::EndDataAccess() sl@0: @see MFbsExtendedBitmapInitializer sl@0: */ sl@0: EXPORT_C TInt CFbsBitmap::CreateExtendedBitmap(const TSize& aSizeInPixels, TDisplayMode aDispMode, TUid aType, TInt aDataSize, MFbsExtendedBitmapInitializer& aInitializer) sl@0: { sl@0: TInt err; sl@0: 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: if (aDataSize == 0) sl@0: { sl@0: FBS_OST(OstTrace1( TRACE_ERROR, CFBSBITMAP_CREATEEXTENDEDBITMAP2_ERROR, "! this=0x%08x; aDataSize == 0", (TUint)this);) sl@0: err = KErrArgument; sl@0: } sl@0: else sl@0: { sl@0: err = DoCreate(aSizeInPixels, aDispMode, aType, aDataSize); sl@0: if (err == KErrNone) sl@0: { sl@0: err = aInitializer.InitExtendedBitmap(iFbs->iLargeBitmapChunk.Base() + iAddressPointer->iDataOffset, aDataSize); sl@0: if (err != KErrNone) sl@0: { sl@0: Reset(); sl@0: } sl@0: } sl@0: } sl@0: 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: return err; sl@0: } sl@0: sl@0: /** sl@0: Gets the UID identifying the data format of an extended bitmap. sl@0: @return The UID identifying the data format of the bitmap or sl@0: KNullUid if the bitmap is not an extended bitmap. sl@0: @publishedPartner sl@0: @prototype sl@0: */ sl@0: EXPORT_C TUid CFbsBitmap::ExtendedBitmapType() const sl@0: { sl@0: if (iHandle == 0) sl@0: { sl@0: return KNullUid; sl@0: } sl@0: TUid type = CleanAddress()->iUid; sl@0: if (type.iUid == KCBitwiseBitmapUid.iUid || type.iUid == KCBitwiseBitmapHardwareUid.iUid) sl@0: { sl@0: return KNullUid; sl@0: } sl@0: return type; sl@0: } sl@0: sl@0: /** sl@0: Gets the size in bytes of the bitmap data. sl@0: @return The size in bytes of the bitmap data. sl@0: @publishedPartner sl@0: @prototype sl@0: */ sl@0: EXPORT_C TInt CFbsBitmap::DataSize() const sl@0: { sl@0: if (iHandle == 0) sl@0: { sl@0: return 0; sl@0: } sl@0: CBitwiseBitmap* bmp = CleanAddress(); sl@0: return bmp->iHeader.iBitmapSize - bmp->iHeader.iStructSize; sl@0: } sl@0: sl@0: /** sl@0: Gets a pointer to an extra buffer for general use owned by this thread's FBServ session. sl@0: @param aSize The size of the buffer in bytes sl@0: @return A pointer to the extra buffer if successful or NULL if there is no FBServ session sl@0: @internalTechnology sl@0: @released sl@0: */ sl@0: EXPORT_C HBufC8* CFbsBitmap::GetExtraBuffer(TInt aSize) sl@0: { sl@0: RFbsSession* ses=RFbsSession::GetSession(); sl@0: return ses? ses->GetExtraBuffer(aSize) : NULL; sl@0: }