1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicsdeviceinterface/bitgdi/sbit/BitmapSpec.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,213 @@
1.4 +// Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <graphicsaccelerator.h>
1.20 +#include <fbs.h>
1.21 +
1.22 +
1.23 +/**
1.24 +Constructor with a software or hardware bitmap.
1.25 +Its type is initialised to EFbsBitmap or EHardwareBitmap accordingly.
1.26 +
1.27 +@param aBitmap The bitmap which the object will access.
1.28 +*/
1.29 +EXPORT_C TAcceleratedBitmapSpec::TAcceleratedBitmapSpec(CFbsBitmap* aBitmap)
1.30 + {
1.31 + RHardwareBitmap hwb(aBitmap->HardwareBitmapHandle());
1.32 + if(hwb.iHandle)
1.33 + {
1.34 + ::new (this) TAcceleratedBitmapSpec(hwb);
1.35 + return;
1.36 + }
1.37 + iType = EFbsBitmap;
1.38 + iHandle = REINTERPRET_CAST(TInt,aBitmap);
1.39 +
1.40 + iLockStatus = EBitmapNeedsLocking;
1.41 +
1.42 + iSpare1 = 0;
1.43 + iSpare2 = 0;
1.44 + }
1.45 +
1.46 +/**
1.47 +Constructor with a hardware bitmap. Its type is initialised to EHardwareBitmap.
1.48 +
1.49 +@param aBitmap The bitmap which the object will access.
1.50 +*/
1.51 +EXPORT_C TAcceleratedBitmapSpec::TAcceleratedBitmapSpec(RHardwareBitmap aBitmap)
1.52 + {
1.53 + iType = EHardwareBitmap;
1.54 + iHandle = aBitmap.iHandle;
1.55 + iLockStatus = EBitmapIsStatic;
1.56 + iSpare1 = 0;
1.57 + iSpare2 = 0;
1.58 + }
1.59 +
1.60 +/**
1.61 +Fills a TAcceleratedBitmapInfo structure with data for the bitmap.
1.62 +
1.63 +This data is only valid for the duration of any processing between a Lock()/Unlock()
1.64 +pair.
1.65 +
1.66 +For compressed bitmaps the line pitch has no meaning so it is set to the negation
1.67 +of the compression type as defined by TBitmapfileCompression.
1.68 +
1.69 +@param aInfo On return, holds the information needed to directly access the
1.70 +bitmap.
1.71 +@return KErrNone if sucessful, otherwise one of the system error codes, including
1.72 +KErrUnknown if the object's type is ENoBitmap.
1.73 +*/
1.74 +EXPORT_C TInt TAcceleratedBitmapSpec::GetInfo(TAcceleratedBitmapInfo& aInfo) const
1.75 + {
1.76 + switch(iType)
1.77 + {
1.78 + case EFbsBitmap:
1.79 + {
1.80 + CFbsBitmap* bmp = REINTERPRET_CAST(CFbsBitmap*,iHandle);
1.81 + aInfo.iDisplayMode = bmp->DisplayMode();
1.82 + aInfo.iAddress = REINTERPRET_CAST(TUint8*,bmp->DataAddress());
1.83 + aInfo.iSize = bmp->SizeInPixels();
1.84 + SEpocBitmapHeader header = bmp->Header();
1.85 + if (header.iCompression != ENoBitmapCompression)
1.86 + {
1.87 + aInfo.iLinePitch = -header.iCompression;
1.88 + }
1.89 + else
1.90 + {
1.91 + aInfo.iLinePitch = bmp->ScanLineLength(aInfo.iSize.iWidth,aInfo.iDisplayMode);
1.92 + }
1.93 + TUid extendedType = bmp->ExtendedBitmapType();
1.94 + if (extendedType != KNullUid)
1.95 + {
1.96 + aInfo.iPixelShift = extendedType.iUid;
1.97 + aInfo.iDataSize = bmp->DataSize();
1.98 + }
1.99 + else
1.100 + {
1.101 + aInfo.iPhysicalAddress = NULL;
1.102 + switch(aInfo.iDisplayMode)
1.103 + {
1.104 + case ENone:
1.105 + aInfo.iPixelShift = -1;
1.106 + break;
1.107 + case EGray2:
1.108 + aInfo.iPixelShift = 0;
1.109 + break;
1.110 + case EGray4:
1.111 + aInfo.iPixelShift = 1;
1.112 + break;
1.113 + case EGray16:
1.114 + case EColor16:
1.115 + aInfo.iPixelShift = 2;
1.116 + break;
1.117 + case EGray256:
1.118 + case EColor256:
1.119 + aInfo.iPixelShift = 3;
1.120 + break;
1.121 + case EColor4K:
1.122 + case EColor64K:
1.123 + aInfo.iPixelShift = 4;
1.124 + break;
1.125 + case EColor16M:
1.126 + case ERgb:
1.127 + case EColor16MU:
1.128 + case EColor16MA:
1.129 + case EColor16MAP:
1.130 + aInfo.iPixelShift = 5;
1.131 + break;
1.132 + default:
1.133 + aInfo.iPixelShift = -1;
1.134 + break;
1.135 + }
1.136 + }
1.137 + }
1.138 + return KErrNone;
1.139 +
1.140 + case EHardwareBitmap:
1.141 + return RHardwareBitmap(iHandle).GetInfo(aInfo);
1.142 +
1.143 + case ENoBitmap:
1.144 + default:
1.145 + Mem::FillZ(&aInfo,sizeof(aInfo));
1.146 + return KErrUnknown;
1.147 + }
1.148 + }
1.149 +
1.150 +/** Locks the bitmap, if required.
1.151 +@param aCount Reference to a bitmap lock count object for nesting
1.152 +(only the first instance does the locking). */
1.153 +EXPORT_C void TAcceleratedBitmapSpec::DoLock(TBitmapLockCount& aCount)
1.154 + {
1.155 + switch(iType)
1.156 + {
1.157 + case EFbsBitmap:
1.158 + if(aCount.Inc()==0)
1.159 + REINTERPRET_CAST(CFbsBitmap*,iHandle)->BeginDataAccess();
1.160 + break;
1.161 +
1.162 + case ENoBitmap:
1.163 + case EHardwareBitmap:
1.164 + default:
1.165 + // Never needs locking
1.166 + return;
1.167 + }
1.168 + }
1.169 +
1.170 +/** Locks the bitmap, if required, setting the accelerated
1.171 +bitmap information address.
1.172 +@param aCount Reference to a bitmap lock count object for nesting
1.173 +(only the first instance does the locking).
1.174 +@param aInfo Information structure to set the address in. */
1.175 +EXPORT_C void TAcceleratedBitmapSpec::DoLock(TBitmapLockCount& aCount,TAcceleratedBitmapInfo& aInfo)
1.176 + {
1.177 + switch(iType)
1.178 + {
1.179 + case EFbsBitmap:
1.180 + {
1.181 + if(aCount.Inc()==0)
1.182 + REINTERPRET_CAST(CFbsBitmap*,iHandle)->BeginDataAccess();
1.183 +
1.184 + CFbsBitmap* bmp = REINTERPRET_CAST(CFbsBitmap*,iHandle);
1.185 + aInfo.iAddress = REINTERPRET_CAST(TUint8*,bmp->DataAddress());
1.186 + }
1.187 + break;
1.188 +
1.189 + case ENoBitmap:
1.190 + case EHardwareBitmap:
1.191 + default:
1.192 + // Never needs locking
1.193 + return;
1.194 + }
1.195 + }
1.196 +
1.197 +/** Unlocks the bitmap, if required.
1.198 +@param aCount Reference to a bitmap lock count object for nesting
1.199 +(only the last instance does the unlocking). */
1.200 +EXPORT_C void TAcceleratedBitmapSpec::DoUnlock(TBitmapLockCount& aCount)
1.201 + {
1.202 + switch(iType)
1.203 + {
1.204 + case EFbsBitmap:
1.205 + if(aCount.Dec()==0)
1.206 + REINTERPRET_CAST(CFbsBitmap*,iHandle)->EndDataAccess();
1.207 + break;
1.208 +
1.209 + case ENoBitmap:
1.210 + case EHardwareBitmap:
1.211 + default:
1.212 + // Never needs unlocking
1.213 + return;
1.214 + }
1.215 + }
1.216 +