sl@0: // Copyright (c) 2000-2009 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: sl@0: sl@0: /** sl@0: Constructor with a software or hardware bitmap. sl@0: Its type is initialised to EFbsBitmap or EHardwareBitmap accordingly. sl@0: sl@0: @param aBitmap The bitmap which the object will access. sl@0: */ sl@0: EXPORT_C TAcceleratedBitmapSpec::TAcceleratedBitmapSpec(CFbsBitmap* aBitmap) sl@0: { sl@0: RHardwareBitmap hwb(aBitmap->HardwareBitmapHandle()); sl@0: if(hwb.iHandle) sl@0: { sl@0: ::new (this) TAcceleratedBitmapSpec(hwb); sl@0: return; sl@0: } sl@0: iType = EFbsBitmap; sl@0: iHandle = REINTERPRET_CAST(TInt,aBitmap); sl@0: sl@0: iLockStatus = EBitmapNeedsLocking; sl@0: sl@0: iSpare1 = 0; sl@0: iSpare2 = 0; sl@0: } sl@0: sl@0: /** sl@0: Constructor with a hardware bitmap. Its type is initialised to EHardwareBitmap. sl@0: sl@0: @param aBitmap The bitmap which the object will access. sl@0: */ sl@0: EXPORT_C TAcceleratedBitmapSpec::TAcceleratedBitmapSpec(RHardwareBitmap aBitmap) sl@0: { sl@0: iType = EHardwareBitmap; sl@0: iHandle = aBitmap.iHandle; sl@0: iLockStatus = EBitmapIsStatic; sl@0: iSpare1 = 0; sl@0: iSpare2 = 0; sl@0: } sl@0: sl@0: /** sl@0: Fills a TAcceleratedBitmapInfo structure with data for the bitmap. sl@0: sl@0: This data is only valid for the duration of any processing between a Lock()/Unlock() sl@0: pair. sl@0: sl@0: For compressed bitmaps the line pitch has no meaning so it is set to the negation sl@0: of the compression type as defined by TBitmapfileCompression. sl@0: sl@0: @param aInfo On return, holds the information needed to directly access the sl@0: bitmap. sl@0: @return KErrNone if sucessful, otherwise one of the system error codes, including sl@0: KErrUnknown if the object's type is ENoBitmap. sl@0: */ sl@0: EXPORT_C TInt TAcceleratedBitmapSpec::GetInfo(TAcceleratedBitmapInfo& aInfo) const sl@0: { sl@0: switch(iType) sl@0: { sl@0: case EFbsBitmap: sl@0: { sl@0: CFbsBitmap* bmp = REINTERPRET_CAST(CFbsBitmap*,iHandle); sl@0: aInfo.iDisplayMode = bmp->DisplayMode(); sl@0: aInfo.iAddress = REINTERPRET_CAST(TUint8*,bmp->DataAddress()); sl@0: aInfo.iSize = bmp->SizeInPixels(); sl@0: SEpocBitmapHeader header = bmp->Header(); sl@0: if (header.iCompression != ENoBitmapCompression) sl@0: { sl@0: aInfo.iLinePitch = -header.iCompression; sl@0: } sl@0: else sl@0: { sl@0: aInfo.iLinePitch = bmp->ScanLineLength(aInfo.iSize.iWidth,aInfo.iDisplayMode); sl@0: } sl@0: TUid extendedType = bmp->ExtendedBitmapType(); sl@0: if (extendedType != KNullUid) sl@0: { sl@0: aInfo.iPixelShift = extendedType.iUid; sl@0: aInfo.iDataSize = bmp->DataSize(); sl@0: } sl@0: else sl@0: { sl@0: aInfo.iPhysicalAddress = NULL; sl@0: switch(aInfo.iDisplayMode) sl@0: { sl@0: case ENone: sl@0: aInfo.iPixelShift = -1; sl@0: break; sl@0: case EGray2: sl@0: aInfo.iPixelShift = 0; sl@0: break; sl@0: case EGray4: sl@0: aInfo.iPixelShift = 1; sl@0: break; sl@0: case EGray16: sl@0: case EColor16: sl@0: aInfo.iPixelShift = 2; sl@0: break; sl@0: case EGray256: sl@0: case EColor256: sl@0: aInfo.iPixelShift = 3; sl@0: break; sl@0: case EColor4K: sl@0: case EColor64K: sl@0: aInfo.iPixelShift = 4; sl@0: break; sl@0: case EColor16M: sl@0: case ERgb: sl@0: case EColor16MU: sl@0: case EColor16MA: sl@0: case EColor16MAP: sl@0: aInfo.iPixelShift = 5; sl@0: break; sl@0: default: sl@0: aInfo.iPixelShift = -1; sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: return KErrNone; sl@0: sl@0: case EHardwareBitmap: sl@0: return RHardwareBitmap(iHandle).GetInfo(aInfo); sl@0: sl@0: case ENoBitmap: sl@0: default: sl@0: Mem::FillZ(&aInfo,sizeof(aInfo)); sl@0: return KErrUnknown; sl@0: } sl@0: } sl@0: sl@0: /** Locks the bitmap, if required. sl@0: @param aCount Reference to a bitmap lock count object for nesting sl@0: (only the first instance does the locking). */ sl@0: EXPORT_C void TAcceleratedBitmapSpec::DoLock(TBitmapLockCount& aCount) sl@0: { sl@0: switch(iType) sl@0: { sl@0: case EFbsBitmap: sl@0: if(aCount.Inc()==0) sl@0: REINTERPRET_CAST(CFbsBitmap*,iHandle)->BeginDataAccess(); sl@0: break; sl@0: sl@0: case ENoBitmap: sl@0: case EHardwareBitmap: sl@0: default: sl@0: // Never needs locking sl@0: return; sl@0: } sl@0: } sl@0: sl@0: /** Locks the bitmap, if required, setting the accelerated sl@0: bitmap information address. sl@0: @param aCount Reference to a bitmap lock count object for nesting sl@0: (only the first instance does the locking). sl@0: @param aInfo Information structure to set the address in. */ sl@0: EXPORT_C void TAcceleratedBitmapSpec::DoLock(TBitmapLockCount& aCount,TAcceleratedBitmapInfo& aInfo) sl@0: { sl@0: switch(iType) sl@0: { sl@0: case EFbsBitmap: sl@0: { sl@0: if(aCount.Inc()==0) sl@0: REINTERPRET_CAST(CFbsBitmap*,iHandle)->BeginDataAccess(); sl@0: sl@0: CFbsBitmap* bmp = REINTERPRET_CAST(CFbsBitmap*,iHandle); sl@0: aInfo.iAddress = REINTERPRET_CAST(TUint8*,bmp->DataAddress()); sl@0: } sl@0: break; sl@0: sl@0: case ENoBitmap: sl@0: case EHardwareBitmap: sl@0: default: sl@0: // Never needs locking sl@0: return; sl@0: } sl@0: } sl@0: sl@0: /** Unlocks the bitmap, if required. sl@0: @param aCount Reference to a bitmap lock count object for nesting sl@0: (only the last instance does the unlocking). */ sl@0: EXPORT_C void TAcceleratedBitmapSpec::DoUnlock(TBitmapLockCount& aCount) sl@0: { sl@0: switch(iType) sl@0: { sl@0: case EFbsBitmap: sl@0: if(aCount.Dec()==0) sl@0: REINTERPRET_CAST(CFbsBitmap*,iHandle)->EndDataAccess(); sl@0: break; sl@0: sl@0: case ENoBitmap: sl@0: case EHardwareBitmap: sl@0: default: sl@0: // Never needs unlocking sl@0: return; sl@0: } sl@0: } sl@0: