os/graphics/graphicsdeviceinterface/screendriver/sbit/BMDRAW32.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicsdeviceinterface/screendriver/sbit/BMDRAW32.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,1049 @@
     1.4 +// Copyright (c) 2004-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 <graphics/lookuptable.h>
    1.20 +#include <graphics/blendingalgorithms.h>
    1.21 +#include "BMDRAW.H"
    1.22 +#include "BitDrawInterfaceId.h"
    1.23 +
    1.24 +FORCEINLINE void BlendFromRBandG(TUint32 *aPixelPtr, TUint32 aSrcRB, TUint32 aSrcG, TUint32 aSrcAlpha, TUint32 aMaskX2)
    1.25 +	{
    1.26 +	const TUint32 d = *aPixelPtr;
    1.27 +	const TUint32 d_rb = d & 0x00FF00FF;
    1.28 +	const TUint32 rb = ((((aSrcAlpha * ((0x01000100 + aSrcRB) - d_rb)) >> 8) + d_rb) - aMaskX2) & 0x00FF00FF;
    1.29 +
    1.30 +	const TInt d_g = (d & 0xFF00) >> 8;
    1.31 +	const TInt g = ((aSrcAlpha * (aSrcG - d_g)) >> 8) + d_g;
    1.32 +
    1.33 +	*aPixelPtr = rb | (g<<8) | 0xff000000;
    1.34 +	}
    1.35 +
    1.36 +/**Initializes iSize, iDrawRect, iLongWidth, iScanLineBytes, iScanlineWords data members.
    1.37 + It should be called every time when iSize is going to be changed - from Construct().
    1.38 +
    1.39 + @param aSize Physical screen size in pixels.
    1.40 + @panic EScreenDriverPanicInvalidSize - Invalid aSize parameter. This might happen if the
    1.41 + device is scaled and the scaling origin goes outside physical drawing rectangle. */
    1.42 +void CDrawThirtyTwoBppBitmapCommon::SetSize(const TSize& aSize)
    1.43 +	{
    1.44 +	CDrawBitmap::SetSize(aSize);
    1.45 +	__ASSERT_DEBUG(iSize == aSize, User::Invariant());
    1.46 +	iLongWidth = iSize.iWidth;
    1.47 +	iScanLineWords = iSize.iWidth;
    1.48 +	}
    1.49 +
    1.50 +TInt CDrawThirtyTwoBppBitmapCommon::Construct(TSize aSize, TInt aStride)
    1.51 +	{
    1.52 +	iBits = NULL;
    1.53 +	CDrawBitmap::SetSize(aSize);
    1.54 +	__ASSERT_DEBUG(iSize == aSize, User::Invariant());
    1.55 +	if (aStride & 3)
    1.56 +		return KErrArgument;
    1.57 +	iLongWidth = aStride >> 2;
    1.58 +	if (iLongWidth < aSize.iWidth)
    1.59 +		return KErrArgument;
    1.60 +	iScanLineWords = iLongWidth;
    1.61 +	TInt size = Max(aSize.iWidth,aSize.iHeight) << 2;
    1.62 +	if(size < 0)
    1.63 +		return KErrArgument;
    1.64 +	iScanLineBuffer = (TUint32*)(User::Heap().Alloc(size));
    1.65 +	if (iScanLineBuffer == NULL)
    1.66 +		return KErrNoMemory;
    1.67 +	return KErrNone;
    1.68 +	}
    1.69 +
    1.70 +void CDrawThirtyTwoBppBitmapCommon::Shadow(TRgb& aColor)
    1.71 +	{
    1.72 +	TUint32 value = aColor.Internal();
    1.73 +	const TInt alpha = value >> 24;
    1.74 +
    1.75 +	if (iShadowMode & EFade)
    1.76 +		{
    1.77 +#if defined(SYMBIAN_USE_FAST_FADING)
    1.78 +		value = ((value >> 1) & ~0x00808080) + (SYMBIAN_USE_FAST_FADING);
    1.79 +#else		
    1.80 +		const TInt wordFadeMapOffset = ((iFadeMapOffset & 0xff) << 16) | (iFadeMapOffset & 0xff);		
    1.81 +		const TInt rb = ((((value & 0x00ff00ff) * iFadeMapFactor) >> 8) + wordFadeMapOffset) & 0x00ff00ff;
    1.82 +	  	const TInt g = ((((value & 0x0000ff00) * iFadeMapFactor) >> 16) + iFadeMapOffset) << 8;
    1.83 +		value = rb | g;
    1.84 +#endif		
    1.85 +		}
    1.86 +
    1.87 +	if (iShadowMode & EShadow)
    1.88 +		{
    1.89 +		const TInt r = (value & 0x00c00000) ? ((value & 0x00ff0000)-0x00400000) : 0;
    1.90 +		const TInt g = (value & 0x0000c000) ? ((value & 0x0000ff00)-0x00004000) : 0;
    1.91 +		const TInt b = (value & 0x000000c0) ? ((value & 0x000000ff)-0x00000040) : 0;
    1.92 +		value = r | g | b;
    1.93 +		}
    1.94 +
    1.95 +	aColor = TRgb(value,alpha);
    1.96 +	}
    1.97 +
    1.98 +void CDrawThirtyTwoBppBitmapCommon::Shadow(TUint32& aColor)
    1.99 +	{
   1.100 +	// aColor is in the format indicated by ScanLineDisplayMode(), which we
   1.101 +	// assume is EColor16MAP here. If not, this function must be overridden.
   1.102 +	const TInt alpha = (aColor >> 24) + 1;
   1.103 +	TUint32 value = aColor & 0x00ffffff;
   1.104 +	if (iShadowMode & EFade)
   1.105 +		{
   1.106 +#if defined(SYMBIAN_USE_FAST_FADING)
   1.107 +		const TUint32 fast_fade_offset = NonPMA2PMAPixel((aColor & 0xff000000) | SYMBIAN_USE_FAST_FADING) & 0x00ffffff;
   1.108 +		value = ((value >> 1) & ~0x00808080) + (fast_fade_offset);
   1.109 +#else
   1.110 +		const TInt fadeMapOffset = ((alpha * iFadeMapOffset) >> 8) & 0xff;
   1.111 +		const TInt wordFadeMapOffset = ((fadeMapOffset) << 16) | (fadeMapOffset);
   1.112 +		const TInt rb = ((((value & 0x00ff00ff) * iFadeMapFactor) >> 8) + wordFadeMapOffset) & 0x00ff00ff;
   1.113 +	  	const TInt g = ((((value & 0x0000ff00) * iFadeMapFactor) >> 16) + fadeMapOffset) << 8;
   1.114 +		value = rb | g;
   1.115 +#endif
   1.116 +		}
   1.117 +
   1.118 +	if (iShadowMode & EShadow)
   1.119 +		{
   1.120 +		const TInt uLimit = ((0x40) * alpha) >> 8;
   1.121 +		TInt r = (value >> 16) & 0xff;
   1.122 +		r = (r > uLimit) ? (r-uLimit) : 0;
   1.123 +		TInt g = (value >> 8) & 0xff;
   1.124 +		g = (g > uLimit) ? (g - uLimit) : 0;
   1.125 +		TInt b = value & 0xff;
   1.126 +		b = (b > uLimit) ? (b - uLimit) : 0;
   1.127 +		value = (r << 16) | (g << 8) | b;
   1.128 +		}
   1.129 +	// alpha is unchanged.
   1.130 +	aColor = (aColor & 0xff000000) | value;
   1.131 +	}
   1.132 +
   1.133 +TUint8 CDrawThirtyTwoBppBitmapCommon::ShadowAndFade(TInt aComponent)
   1.134 +	{
   1.135 +	if (iShadowMode & EFade)
   1.136 +		aComponent = FadeGray(aComponent);
   1.137 +
   1.138 +	if (iShadowMode & EShadow)
   1.139 +		aComponent = ShadowComponent(aComponent);
   1.140 +
   1.141 +	return TUint8(aComponent);
   1.142 +	}
   1.143 +
   1.144 +TUint8 CDrawThirtyTwoBppBitmapCommon::ShadowComponent(TInt aRgbComponent)
   1.145 +	{
   1.146 +	return TUint8(Max(0,aRgbComponent-0x40));
   1.147 +	}
   1.148 +
   1.149 +void CDrawThirtyTwoBppBitmapCommon::InvertBuffer(TInt aLength,TUint32* aBuffer)
   1.150 +	{
   1.151 +	__ASSERT_DEBUG(aLength>0,Panic(EScreenDriverPanicOutOfBounds));
   1.152 +	__ASSERT_DEBUG(aBuffer,Panic(EScreenDriverPanicNullPointer));
   1.153 +
   1.154 +	TUint32* limit = aBuffer + aLength;
   1.155 +
   1.156 +	while (aBuffer < limit)
   1.157 +		{
   1.158 +		*aBuffer++ ^= 0x00ffffff;
   1.159 +		}
   1.160 +	}
   1.161 +
   1.162 +void CDrawThirtyTwoBppBitmapCommon::ReadLine(TInt aX,TInt aY,TInt aLength,TAny* aBuffer) const
   1.163 +	{
   1.164 +	const TUint32* pixelPtr = PixelAddress(aX,aY);
   1.165 +
   1.166 +	if (iOrientation == EOrientationNormal)
   1.167 +		Mem::Copy(aBuffer,pixelPtr,aLength << 2);
   1.168 +	else
   1.169 +		{
   1.170 +		const TInt pixelPtrInc = PixelAddressIncrement();
   1.171 +
   1.172 +		TUint32* bufferPtr = static_cast <TUint32*> (aBuffer);
   1.173 +		const TUint32* bufferPtrLimit = bufferPtr + aLength;
   1.174 +
   1.175 +		while (bufferPtr < bufferPtrLimit)
   1.176 +			{
   1.177 +			*bufferPtr++ = *pixelPtr;
   1.178 +			pixelPtr += pixelPtrInc;
   1.179 +			}
   1.180 +		}
   1.181 +	}
   1.182 +
   1.183 +TRgb CDrawThirtyTwoBppBitmapCommon::ReadRgbNormal(TInt aX,TInt aY) const
   1.184 +	{
   1.185 +	return RgbColor(*PixelAddress(aX,aY));
   1.186 +	}
   1.187 +
   1.188 +void CDrawThirtyTwoBppBitmapCommon::ShadowArea(const TRect& aRect)
   1.189 +	{
   1.190 +	const TRect rect(DeOrientate(aRect));
   1.191 +
   1.192 +	__ASSERT_DEBUG(rect.iTl.iX>=0 && rect.iBr.iX<=iSize.iWidth,Panic(EScreenDriverPanicOutOfBounds));
   1.193 +	__ASSERT_DEBUG(rect.iTl.iY>=0 && rect.iBr.iY<=iSize.iHeight,Panic(EScreenDriverPanicOutOfBounds));
   1.194 +
   1.195 +	TUint32* pixelPtr = PixelAddress(rect.iTl.iX,rect.iTl.iY);
   1.196 +	TUint32* pixelRowPtrLimit = pixelPtr + (rect.Height() * iScanLineWords);
   1.197 +
   1.198 +	TUint32* pixelRowPtr = pixelPtr;
   1.199 +	TUint32* pixelPtrLimit = pixelPtr + rect.Width();
   1.200 +
   1.201 +	if (iShadowMode & EFade)
   1.202 +		{
   1.203 +#if !defined(SYMBIAN_USE_FAST_FADING)		
   1.204 +		const TInt wordFadeMapOffset = ((iFadeMapOffset & 0xff) << 16) | (iFadeMapOffset & 0xff);
   1.205 +#endif
   1.206 +		while (pixelRowPtr < pixelRowPtrLimit)
   1.207 +			{
   1.208 +			TUint32* tempPixelPtr = pixelRowPtr;
   1.209 +
   1.210 +			while (tempPixelPtr < pixelPtrLimit)
   1.211 +				{
   1.212 +#if defined(SYMBIAN_USE_FAST_FADING)
   1.213 +				*tempPixelPtr++ = 0xff000000 | ((((*tempPixelPtr) >> 1) & ~0x00808080) + (SYMBIAN_USE_FAST_FADING));
   1.214 +#else
   1.215 +				const TUint32 color = *tempPixelPtr;
   1.216 +				const TInt rb = ((((color & 0x00ff00ff) * iFadeMapFactor) >> 8) + wordFadeMapOffset) & 0x00ff00ff;
   1.217 +	  			const TInt g = ((((color & 0x0000ff00) * iFadeMapFactor) >> 16) + iFadeMapOffset) << 8;
   1.218 +				*tempPixelPtr++ = 0xff000000 | rb | g;
   1.219 +#endif				
   1.220 +				}
   1.221 +				
   1.222 +			pixelRowPtr += iScanLineWords;
   1.223 +			pixelPtrLimit += iScanLineWords;
   1.224 +			}
   1.225 +		}
   1.226 +
   1.227 +	if (iShadowMode & EShadow)
   1.228 +		{
   1.229 +		pixelRowPtr = pixelPtr;
   1.230 +		pixelPtrLimit = pixelPtr + rect.Width();		
   1.231 +		while (pixelRowPtr < pixelRowPtrLimit)
   1.232 +			{
   1.233 +			TUint32* tempPixelPtr = pixelRowPtr;
   1.234 +
   1.235 +			while (tempPixelPtr < pixelPtrLimit)
   1.236 +				{
   1.237 +				const TUint32 color = *tempPixelPtr;
   1.238 +				const TInt r = (color & 0x00c00000) ? ((color & 0x00ff0000)-0x00400000) : 0;
   1.239 +				const TInt g = (color & 0x0000c000) ? ((color & 0x0000ff00)-0x00004000) : 0;
   1.240 +				const TInt b = (color & 0x000000c0) ? ((color & 0x000000ff)-0x00000040) : 0;
   1.241 +				*tempPixelPtr++	= 0xff000000 | r | g | b;
   1.242 +				}
   1.243 +
   1.244 +			pixelRowPtr += iScanLineWords;
   1.245 +			pixelPtrLimit += iScanLineWords;
   1.246 +			}
   1.247 +		}
   1.248 +	}
   1.249 +
   1.250 +void CDrawThirtyTwoBppBitmapCommon::ShadowBuffer(TInt aLength,TUint32* aBuffer)
   1.251 +	{
   1.252 +	__ASSERT_DEBUG(aLength>0,Panic(EScreenDriverPanicZeroLength));
   1.253 +	__ASSERT_DEBUG(aBuffer,Panic(EScreenDriverPanicNullPointer));
   1.254 +
   1.255 +	TUint32* limit = aBuffer + aLength;
   1.256 +
   1.257 +	while (aBuffer < limit)
   1.258 +		Shadow(*aBuffer++);
   1.259 +	}
   1.260 +
   1.261 +void CDrawThirtyTwoBppBitmapCommon::WriteRgb(TInt aX,TInt aY,TRgb aColor)
   1.262 +	{
   1.263 +	TUint8* componentPtr = reinterpret_cast <TUint8*> (PixelAddress(aX,aY));
   1.264 +	const TInt sourceAlpha = aColor.Alpha();
   1.265 +
   1.266 +	if (sourceAlpha==0)
   1.267 +		return;
   1.268 +	if(sourceAlpha != 0xff)
   1.269 +		{
   1.270 +		aColor = AlphaBlend(aColor.Red(), aColor.Green(), aColor.Blue(), TRgb(componentPtr[2], componentPtr[1], componentPtr[0]), sourceAlpha);
   1.271 +		}
   1.272 +
   1.273 +	componentPtr[0] = TUint8(aColor.Blue());
   1.274 +	componentPtr[1] = TUint8(aColor.Green());
   1.275 +	componentPtr[2] = TUint8(aColor.Red());
   1.276 +	}
   1.277 +
   1.278 +void CDrawThirtyTwoBppBitmapCommon::WriteBinary(TInt aX,TInt aY,TUint32* aBuffer,TInt aLength,TInt aHeight,TRgb aColor)
   1.279 +	{
   1.280 +	const TInt sourceAlpha = aColor.Alpha();
   1.281 +	if(sourceAlpha == 0)
   1.282 +		return;
   1.283 +	DeOrientate(aX,aY);
   1.284 +
   1.285 +	TInt pixelInc;
   1.286 +	TInt rowInc;
   1.287 +
   1.288 +	switch(iOrientation)
   1.289 +		{
   1.290 +		case EOrientationNormal:
   1.291 +			{
   1.292 +			pixelInc = 1;
   1.293 +			rowInc = iScanLineWords;
   1.294 +			break;
   1.295 +			}
   1.296 +		case EOrientationRotated90:
   1.297 +			{
   1.298 +			pixelInc = iScanLineWords;
   1.299 +			rowInc = -1;
   1.300 +			break;
   1.301 +			}
   1.302 +		case EOrientationRotated180:
   1.303 +			{
   1.304 +			pixelInc = -1;
   1.305 +			rowInc = -iScanLineWords;
   1.306 +			break;
   1.307 +			}
   1.308 +		default: // EOrientationRotated270
   1.309 +			{
   1.310 +			pixelInc = -iScanLineWords;
   1.311 +			rowInc = 1;
   1.312 +			}
   1.313 +		}
   1.314 +
   1.315 +	const TUint32* dataLimit = aBuffer + aHeight;
   1.316 +	const TUint32 dataMaskLimit = (aLength < 32) ? 1 << aLength : 0;
   1.317 +
   1.318 +	TUint32* pixelPtr = PixelAddress(aX,aY);
   1.319 +
   1.320 +	if(sourceAlpha == 255) //we split code on two parts because of performance reasons
   1.321 +		{
   1.322 +		TInt color = Color(aColor);
   1.323 +		while (aBuffer < dataLimit)
   1.324 +			{
   1.325 +			TUint32 dataWord = *aBuffer++;
   1.326 +			TUint32 dataMask = 1;
   1.327 +			TUint32* tempPixelPtr = pixelPtr;
   1.328 +
   1.329 +			while (dataMask != dataMaskLimit)
   1.330 +				{
   1.331 +				if(dataWord & dataMask)
   1.332 +					{
   1.333 +					*tempPixelPtr = color;
   1.334 +					}
   1.335 +
   1.336 +				tempPixelPtr += pixelInc;
   1.337 +				dataMask <<= 1;
   1.338 +				}
   1.339 +
   1.340 +			pixelPtr += rowInc;
   1.341 +			}
   1.342 +		}
   1.343 +	else //sourceAlpha != 255
   1.344 +		{
   1.345 +		const TUint32 sourceInternal=aColor.Internal();
   1.346 +		const TUint32 s_rb = sourceInternal & 0x00FF00FF;
   1.347 +		const TUint32 s_g = (sourceInternal & 0xFF00) >> 8;
   1.348 +		const TUint32 mask2 = sourceAlpha | (sourceAlpha << 16);
   1.349 +		while (aBuffer < dataLimit)
   1.350 +			{
   1.351 +			TUint32 dataWord = *aBuffer++;
   1.352 +			TUint32 dataMask = 1;
   1.353 +			TUint32* tempPixelPtr = pixelPtr;
   1.354 +
   1.355 +			while (dataMask != dataMaskLimit)
   1.356 +				{
   1.357 +				if (dataWord & dataMask)
   1.358 +					{
   1.359 +					BlendFromRBandG(tempPixelPtr,s_rb,s_g,sourceAlpha,mask2);
   1.360 +					}
   1.361 +
   1.362 +				tempPixelPtr += pixelInc;
   1.363 +				dataMask <<= 1;
   1.364 +				}
   1.365 +
   1.366 +			pixelPtr += rowInc;
   1.367 +			}
   1.368 +		}
   1.369 +	}
   1.370 +
   1.371 +void CDrawThirtyTwoBppBitmapCommon::WriteBinaryOp(TInt aX,TInt aY,TUint32* aBuffer,TInt aLength,TInt aHeight,TRgb aColor,CGraphicsContext::TDrawMode aDrawMode)
   1.372 +	{
   1.373 +	if (aLength <= 0)
   1.374 +		return;
   1.375 +
   1.376 +	DeOrientate(aX,aY);
   1.377 +	TUint32* pixelPtr = PixelAddress(aX,aY);
   1.378 +
   1.379 +	const TUint32* dataPtrLimit = aBuffer + aHeight;
   1.380 +	const TUint32 dataMaskLimit = (aLength < 32) ? 1 << aLength : 0;
   1.381 +
   1.382 +	TInt pixelInc;
   1.383 +	TInt rowInc;
   1.384 +
   1.385 +	if (iOrientation == EOrientationNormal)
   1.386 +		{
   1.387 +		pixelInc = 1;
   1.388 +		rowInc = iScanLineWords;
   1.389 +		}
   1.390 +	else if (iOrientation == EOrientationRotated90)
   1.391 +		{
   1.392 +		pixelInc = iScanLineWords;
   1.393 +		rowInc = -1;
   1.394 +		}
   1.395 +	else if (iOrientation == EOrientationRotated180)
   1.396 +		{
   1.397 +		pixelInc = -1;
   1.398 +		rowInc = -iScanLineWords;
   1.399 +		}
   1.400 +	else // EOrientationRotated270
   1.401 +		{
   1.402 +		pixelInc = -iScanLineWords;
   1.403 +		rowInc = 1;
   1.404 +		}
   1.405 +
   1.406 +	TInt color = Color(aColor);// & 0x00FFFFFF;
   1.407 +
   1.408 +	if (color != 0)
   1.409 +		{
   1.410 +		while (aBuffer < dataPtrLimit)
   1.411 +			{
   1.412 +			TUint32 dataWord = *aBuffer++;
   1.413 +			TUint32 dataMask = 1;
   1.414 +			TUint32* tempPixelPtr = pixelPtr;
   1.415 +
   1.416 +			while (dataMask != dataMaskLimit)
   1.417 +				{
   1.418 +				if(dataWord & dataMask)
   1.419 +					{
   1.420 +					if(aDrawMode==CGraphicsContext::EDrawModeXOR)
   1.421 +						{
   1.422 +						*tempPixelPtr ^= color;
   1.423 +						}
   1.424 +					else if(aDrawMode==CGraphicsContext::EDrawModeAND)
   1.425 +						{
   1.426 +						*tempPixelPtr &= color;
   1.427 +						}
   1.428 +					else if(aDrawMode==CGraphicsContext::EDrawModeOR)
   1.429 +						{
   1.430 +						*tempPixelPtr |= color;
   1.431 +						}
   1.432 +					}
   1.433 +
   1.434 +				tempPixelPtr += pixelInc;
   1.435 +				dataMask <<= 1;
   1.436 +				}
   1.437 +
   1.438 +			pixelPtr += rowInc;
   1.439 +			}
   1.440 +		}
   1.441 +	else if (aDrawMode == CGraphicsContext::EDrawModeAND)
   1.442 +		{
   1.443 +		while (aBuffer < dataPtrLimit)
   1.444 +			{
   1.445 +			TUint32 dataWord = *aBuffer++;
   1.446 +			TUint32 dataMask = 1;
   1.447 +			TUint32* tempPixelPtr = pixelPtr;
   1.448 +
   1.449 +			while (dataMask != dataMaskLimit)
   1.450 +				{
   1.451 +				if(dataWord & dataMask)
   1.452 +					{
   1.453 +					*tempPixelPtr = 0;
   1.454 +					}
   1.455 +
   1.456 +				tempPixelPtr += pixelInc;
   1.457 +				dataMask <<= 1;
   1.458 +				}
   1.459 +
   1.460 +			pixelPtr += rowInc;
   1.461 +			}
   1.462 +		}
   1.463 +	}
   1.464 +
   1.465 +void CDrawThirtyTwoBppBitmapCommon::WriteBinaryLineVertical(TInt aX,TInt aY,TUint32* aBuffer,TInt aHeight,TRgb aColor,TBool aUp)
   1.466 +	{
   1.467 +	const TInt sourceAlpha = aColor.Alpha();
   1.468 +	if(sourceAlpha == 0)
   1.469 +		return;
   1.470 +	DeOrientate(aX,aY);
   1.471 +
   1.472 +	TInt scanlineWordLength;
   1.473 +
   1.474 +	if (iOrientation == EOrientationNormal)
   1.475 +		scanlineWordLength = iScanLineWords;
   1.476 +	else if (iOrientation == EOrientationRotated90)
   1.477 +		scanlineWordLength = -1;
   1.478 +	else if (iOrientation == EOrientationRotated180)
   1.479 +		scanlineWordLength = -iScanLineWords;
   1.480 +	else // EOrientationRotated270
   1.481 +		scanlineWordLength = 1;
   1.482 +
   1.483 +	if (aUp)
   1.484 +		scanlineWordLength = -scanlineWordLength;
   1.485 +
   1.486 +	TUint32* pixelPtr = PixelAddress(aX,aY);
   1.487 +	const TUint32* pixelPtrLimit = pixelPtr + (aHeight * scanlineWordLength);
   1.488 +	TUint32 dataWord = *aBuffer;
   1.489 +	TUint32 dataMask = 1;
   1.490 +
   1.491 +	if(sourceAlpha == 255) //we split code on two parts because of performance reasons
   1.492 +		{
   1.493 +		TInt color = Color(aColor);
   1.494 +		while(pixelPtr != pixelPtrLimit)
   1.495 +			{
   1.496 +			if(!dataMask)
   1.497 +				{
   1.498 +				dataMask = 1;
   1.499 +				aBuffer++;
   1.500 +				dataWord = *aBuffer;
   1.501 +				}
   1.502 +
   1.503 +			if(dataWord & dataMask)
   1.504 +				{
   1.505 +				*pixelPtr = color;
   1.506 +				}
   1.507 +
   1.508 +			dataMask <<= 1;
   1.509 +			pixelPtr += scanlineWordLength;
   1.510 +			}
   1.511 +		}
   1.512 +	else //sourceAlpha != 255
   1.513 +		{
   1.514 +		const TUint32 sourceInternal=aColor.Internal();
   1.515 +		const TUint32 s_rb = sourceInternal & 0x00FF00FF;
   1.516 +		const TUint32 s_g = (sourceInternal & 0xFF00) >> 8;
   1.517 +		const TUint32 mask2 = sourceAlpha | (sourceAlpha << 16);
   1.518 +		while(pixelPtr != pixelPtrLimit)
   1.519 +			{
   1.520 +			if(!dataMask)
   1.521 +				{
   1.522 +				dataMask = 1;
   1.523 +				aBuffer++;
   1.524 +				dataWord = *aBuffer;
   1.525 +				}
   1.526 +
   1.527 +			if(dataWord & dataMask)
   1.528 +				{
   1.529 +				BlendFromRBandG(pixelPtr, s_rb, s_g, sourceAlpha, mask2);
   1.530 +				}
   1.531 +
   1.532 +			dataMask <<= 1;
   1.533 +			pixelPtr += scanlineWordLength;
   1.534 +			}
   1.535 +		}
   1.536 +	}
   1.537 +
   1.538 +void CDrawThirtyTwoBppBitmapCommon::WriteLine(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer)
   1.539 +	{
   1.540 +	TUint32* pixelPtr = PixelAddress(aX,aY);
   1.541 +
   1.542 +	if (iOrientation == EOrientationNormal)
   1.543 +		Mem::Copy(pixelPtr,aBuffer,aLength << 2);
   1.544 +	else
   1.545 +		{
   1.546 +		const TInt pixelPtrInc = PixelAddressIncrement();
   1.547 +
   1.548 +		TUint32* bufferPtrLimit = aBuffer + aLength;
   1.549 +
   1.550 +		while (aBuffer < bufferPtrLimit)
   1.551 +			{
   1.552 +			*pixelPtr = *aBuffer++;
   1.553 +			pixelPtr += pixelPtrInc;
   1.554 +			}
   1.555 +		}
   1.556 +	}
   1.557 +
   1.558 +void CDrawThirtyTwoBppBitmapCommon::WriteLineXOR(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer)
   1.559 +	{
   1.560 +	TUint32* pixelPtr = PixelAddress(aX,aY);
   1.561 +	const TInt pixelPtrInc = PixelAddressIncrement();
   1.562 +
   1.563 +	TUint32* bufferPtrLimit = aBuffer + aLength;
   1.564 +
   1.565 +	while (aBuffer < bufferPtrLimit)
   1.566 +		{
   1.567 +		*pixelPtr ^= *aBuffer++;
   1.568 +		pixelPtr += pixelPtrInc;
   1.569 +		}
   1.570 +	}
   1.571 +
   1.572 +void CDrawThirtyTwoBppBitmapCommon::WriteLineAND(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer)
   1.573 +	{
   1.574 +	TUint32* pixelPtr = PixelAddress(aX,aY);
   1.575 +	const TInt pixelPtrInc = PixelAddressIncrement();
   1.576 +
   1.577 +	TUint32* bufferPtrLimit = aBuffer + aLength;
   1.578 +
   1.579 +	while (aBuffer < bufferPtrLimit)
   1.580 +		{
   1.581 +		*pixelPtr &= *aBuffer++;
   1.582 +		pixelPtr += pixelPtrInc;
   1.583 +		}
   1.584 +	}
   1.585 +
   1.586 +void CDrawThirtyTwoBppBitmapCommon::WriteLineOR(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer)
   1.587 +	{
   1.588 +	TUint32* pixelPtr = PixelAddress(aX,aY);
   1.589 +	const TInt pixelPtrInc = PixelAddressIncrement();
   1.590 +
   1.591 +	TUint32* bufferPtrLimit = aBuffer + aLength;
   1.592 +
   1.593 +	while (aBuffer < bufferPtrLimit)
   1.594 +		{
   1.595 +		*pixelPtr |= *aBuffer++;
   1.596 +		pixelPtr += pixelPtrInc;
   1.597 +		}
   1.598 +	}
   1.599 +
   1.600 +/**
   1.601 +MAlphaBlend::WriteRgbAlphaLine() implementation.
   1.602 +@see MAlphaBlend::WriteRgbAlphaLine()
   1.603 +*/
   1.604 +void CDrawThirtyTwoBppBitmapCommon::WriteRgbAlphaLine(TInt aX, TInt aY, TInt aLength,
   1.605 +                                                  const TUint8* aRgbBuffer,
   1.606 +                                                  const TUint8* aMaskBuffer,
   1.607 +                                                  MAlphaBlend::TShadowing aShadowing,
   1.608 +                                                  CGraphicsContext::TDrawMode /*aDrawMode*/)
   1.609 +    {
   1.610 +	DeOrientate(aX,aY);
   1.611 +	TUint32* pixelPtr = PixelAddress(aX,aY);
   1.612 +	const TInt pixelPtrInc = PixelAddressIncrement();
   1.613 +	const TUint8* maskBufferPtrLimit = aMaskBuffer + aLength;
   1.614 +
   1.615 +	while (aMaskBuffer < maskBufferPtrLimit)
   1.616 +		{
   1.617 +		TRgb srcColor(aRgbBuffer[2],aRgbBuffer[1],aRgbBuffer[0]);// !! we don't have any alpha information for the source, so assume opaque
   1.618 +		if(aMaskBuffer[0])
   1.619 +			{
   1.620 +			if(aShadowing == MAlphaBlend::EShdwBefore)
   1.621 +				{
   1.622 +				Shadow(srcColor);
   1.623 +				}
   1.624 +			TUint8* componentPtr = reinterpret_cast <TUint8*> (pixelPtr);
   1.625 +			if(aMaskBuffer[0] != 0xff)
   1.626 +				{
   1.627 +				srcColor = AlphaBlend(srcColor.Red(), srcColor.Green(), srcColor.Blue(), TRgb(componentPtr[2], componentPtr[1], componentPtr[0]), aMaskBuffer[0]);
   1.628 +				}
   1.629 +			if(aShadowing == MAlphaBlend::EShdwAfter)
   1.630 +				{
   1.631 +				Shadow(srcColor);
   1.632 +				}
   1.633 +			MapColorToUserDisplayMode(srcColor);
   1.634 +			componentPtr[0] = TUint8(srcColor.Blue());
   1.635 +			componentPtr[1] = TUint8(srcColor.Green());
   1.636 +			componentPtr[2] = TUint8(srcColor.Red());
   1.637 +			}
   1.638 +		pixelPtr += pixelPtrInc;
   1.639 +		aRgbBuffer += 4;
   1.640 +		aMaskBuffer++;
   1.641 +		}
   1.642 +	}
   1.643 +
   1.644 +void CDrawThirtyTwoBppBitmapCommon::WriteRgbMulti(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
   1.645 +	{
   1.646 +	TUint32* pixelPtr = PixelAddress(aX,aY);
   1.647 +	TUint32* pixelRowPtrLimit = pixelPtr + (aHeight * iScanLineWords);
   1.648 +
   1.649 +	TInt color = Color(aColor);
   1.650 +
   1.651 +	while (pixelPtr < pixelRowPtrLimit)
   1.652 +		{
   1.653 +		MemFillTUint32(pixelPtr, aLength, color);
   1.654 +		pixelPtr += iScanLineWords;
   1.655 +		}
   1.656 +	}
   1.657 +
   1.658 +void CDrawThirtyTwoBppBitmapCommon::WriteRgbMultiXOR(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
   1.659 +	{
   1.660 +	TUint32* pixelPtr = PixelAddress(aX,aY);
   1.661 +	TUint32* pixelPtrLimit = pixelPtr + aLength;
   1.662 +	TUint32* pixelRowPtrLimit = pixelPtr + (aHeight * iScanLineWords);
   1.663 +	TInt color = Color(aColor);
   1.664 +
   1.665 +	while (pixelPtr < pixelRowPtrLimit)
   1.666 +		{
   1.667 +		for (TUint32* tempPixelPtr = pixelPtr; tempPixelPtr < pixelPtrLimit; tempPixelPtr++)
   1.668 +			{
   1.669 +			*tempPixelPtr ^= color;
   1.670 +			}
   1.671 +
   1.672 +		pixelPtr += iScanLineWords;
   1.673 +		pixelPtrLimit += iScanLineWords;
   1.674 +		}
   1.675 +	}
   1.676 +
   1.677 +void CDrawThirtyTwoBppBitmapCommon::WriteRgbMultiAND(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
   1.678 +	{
   1.679 +	TUint32* pixelPtr = PixelAddress(aX,aY);
   1.680 +	TUint32* pixelPtrLimit = pixelPtr + aLength;
   1.681 +	TUint32* pixelRowPtrLimit = pixelPtr + (aHeight * iScanLineWords);
   1.682 +	TInt color = Color(aColor);
   1.683 +
   1.684 +	while (pixelPtr < pixelRowPtrLimit)
   1.685 +		{
   1.686 +		for (TUint32* tempPixelPtr = pixelPtr; tempPixelPtr < pixelPtrLimit; tempPixelPtr++)
   1.687 +			{
   1.688 +			*tempPixelPtr &= color;
   1.689 +			}
   1.690 +
   1.691 +		pixelPtr += iScanLineWords;
   1.692 +		pixelPtrLimit += iScanLineWords;
   1.693 +		}
   1.694 +	}
   1.695 +
   1.696 +void CDrawThirtyTwoBppBitmapCommon::WriteRgbMultiOR(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
   1.697 +	{
   1.698 +	TUint32* pixelPtr = PixelAddress(aX,aY);
   1.699 +	TUint32* pixelPtrLimit = pixelPtr + aLength;
   1.700 +	TUint32* pixelRowPtrLimit = pixelPtr + (aHeight * iScanLineWords);
   1.701 +	TInt color = Color(aColor);
   1.702 +
   1.703 +	while (pixelPtr < pixelRowPtrLimit)
   1.704 +		{
   1.705 +		for (TUint32* tempPixelPtr = pixelPtr; tempPixelPtr < pixelPtrLimit; tempPixelPtr++)
   1.706 +			{
   1.707 +			*tempPixelPtr |= color;
   1.708 +			}
   1.709 +
   1.710 +		pixelPtr += iScanLineWords;
   1.711 +		pixelPtrLimit += iScanLineWords;
   1.712 +		}
   1.713 +	}
   1.714 +
   1.715 +inline TUint32 OptimizedBlend32(TInt aPrimaryRed,TInt aPrimaryGreen,TInt aPrimaryBlue,TUint32 aSecondary,TUint8 aAlphaValue)
   1.716 +	{
   1.717 + 	__ASSERT_DEBUG(!(aPrimaryRed>>8) && !(aPrimaryGreen>>8) && !(aPrimaryBlue>>8) && !(aAlphaValue>>8),
   1.718 +					Panic(EScreenDriverPanicAlphaBlendInvariant));
   1.719 +
   1.720 + 	if(aAlphaValue == 0xff)
   1.721 +		{
   1.722 +		return (aPrimaryBlue + (aPrimaryGreen<<8) + (aPrimaryRed<<16)) | 0xff000000;
   1.723 + 		}
   1.724 + 	else
   1.725 + 		{
   1.726 + 		const TUint32 alphaValue = (aAlphaValue << 8) + aAlphaValue;
   1.727 +
   1.728 + 		const TInt r2 = (aSecondary & 0x00ff0000) >> 16;
   1.729 + 		const TInt g2 = (aSecondary & 0x0000ff00) >> 8;
   1.730 + 		const TInt b2 = aSecondary & 0x000000ff;
   1.731 +
   1.732 + 		const TInt r3 = ((alphaValue * (aPrimaryRed   - r2)) >> 16) + r2;
   1.733 +		const TInt g3 = ((alphaValue * (aPrimaryGreen - g2)) >> 16) + g2;
   1.734 +		const TInt b3 = ((alphaValue * (aPrimaryBlue  - b2)) >> 16) + b2;
   1.735 +
   1.736 +		return (b3 & 0xFF) | ((g3<<8) & 0xFF00) | ((r3<<16) & 0xFF0000) | 0xFF000000;
   1.737 + 		}
   1.738 + 	}
   1.739 +
   1.740 +void CDrawThirtyTwoBppBitmapCommon::WriteRgbAlphaMulti(TInt aX,TInt aY,TInt aLength,TRgb aColor,const TUint8* aMaskBuffer)
   1.741 +	{
   1.742 +	const TUint32 sourceAlpha = aColor.Alpha();
   1.743 +	if (sourceAlpha==0 || aLength<=0)
   1.744 +		return;
   1.745 +	DeOrientate(aX,aY);
   1.746 +	TUint32* pixelPtr = PixelAddress(aX,aY);
   1.747 +	const TInt pixelPtrInc = PixelAddressIncrement();
   1.748 +	const TUint8* maskBufferPtrLimit = aMaskBuffer + aLength;
   1.749 +
   1.750 +	if (iShadowMode)
   1.751 +		Shadow(aColor);
   1.752 +
   1.753 +	const TUint32 sourceInternal=aColor.Internal();
   1.754 +	const TUint32 s_rb = sourceInternal & 0x00FF00FF;
   1.755 +	const TUint32 s_g = (sourceInternal & 0xFF00) >> 8;
   1.756 +	if (sourceAlpha==0xFF)
   1.757 +		{
   1.758 +		while (aMaskBuffer < maskBufferPtrLimit)
   1.759 +			{
   1.760 +			const TUint32 maskAlpha=*aMaskBuffer;
   1.761 +			if (maskAlpha)
   1.762 +				{
   1.763 +				if (maskAlpha==0xFF)
   1.764 +					*pixelPtr = sourceInternal;
   1.765 +				else
   1.766 +					BlendFromRBandG(pixelPtr,s_rb,s_g,maskAlpha,maskAlpha|(maskAlpha<<16));
   1.767 +				}
   1.768 +			pixelPtr += pixelPtrInc;
   1.769 +			aMaskBuffer++;
   1.770 +			}
   1.771 +		}
   1.772 +	else
   1.773 +		{
   1.774 +		while (aMaskBuffer < maskBufferPtrLimit)
   1.775 +			{
   1.776 +			const TUint32 maskAlpha=*aMaskBuffer;
   1.777 +			if (maskAlpha)
   1.778 +				{
   1.779 +				TUint blendAlpha = sourceAlpha;
   1.780 +				if (maskAlpha!=0xFF)
   1.781 +					blendAlpha=((maskAlpha+1) * sourceAlpha)>>8;
   1.782 +				BlendFromRBandG(pixelPtr,s_rb,s_g,blendAlpha,blendAlpha|(blendAlpha<<16));
   1.783 +				}
   1.784 +			pixelPtr += pixelPtrInc;
   1.785 +			aMaskBuffer++;
   1.786 +			}
   1.787 +		}
   1.788 +	}
   1.789 +
   1.790 +void CDrawThirtyTwoBppBitmapCommon::MapColorToUserDisplayMode(TRgb& aColor)
   1.791 +	{
   1.792 +	const TInt alpha = aColor.Alpha();
   1.793 +	switch (iUserDispMode)
   1.794 +		{
   1.795 +	case EGray2:
   1.796 +		aColor = TRgb::_Gray2(aColor._Gray2());
   1.797 +		break;
   1.798 +	case EGray4:
   1.799 +		aColor = TRgb::_Gray4(aColor._Gray4());
   1.800 +		break;
   1.801 +	case EGray16:
   1.802 +		aColor = TRgb::_Gray16(aColor._Gray16());
   1.803 +		break;
   1.804 +	case EGray256:
   1.805 +		aColor = TRgb::_Gray256(aColor._Gray256());
   1.806 +		break;
   1.807 +	case EColor16:
   1.808 +		aColor = TRgb::Color16(aColor.Color16());
   1.809 +		break;
   1.810 +	case EColor256:
   1.811 +		aColor = TRgb::Color256(aColor.Color256());
   1.812 +		break;
   1.813 +	case EColor4K:
   1.814 +		aColor = TRgb::_Color4K(aColor._Color4K());
   1.815 +		break;
   1.816 +	case EColor64K:
   1.817 +		aColor = TRgb::_Color64K(aColor._Color64K());
   1.818 +		break;
   1.819 +	default:
   1.820 +		break;
   1.821 +		}
   1.822 +	aColor.SetAlpha(alpha);
   1.823 +	}
   1.824 +
   1.825 +void CDrawThirtyTwoBppBitmapCommon::MapBufferToUserDisplayMode(TInt aLength,TUint32* aBuffer)
   1.826 +	{
   1.827 +	const TUint32* bufferLimit = aBuffer + aLength;
   1.828 +	const TUint16* nTable = PtrTo16BitNormalisationTable();
   1.829 +	TRgb color;
   1.830 +
   1.831 +	switch (iUserDispMode)
   1.832 +		{
   1.833 +	case EGray2:
   1.834 +		while (aBuffer < bufferLimit)
   1.835 +			{
   1.836 +			color.SetInternal(PMA2NonPMAPixel(*aBuffer, nTable));
   1.837 +			color = TRgb::_Gray2(color._Gray2());
   1.838 +			*aBuffer++ = color.Internal();
   1.839 +			}
   1.840 +		break;
   1.841 +	case EGray4:
   1.842 +		while (aBuffer < bufferLimit)
   1.843 +			{
   1.844 +			color.SetInternal(PMA2NonPMAPixel(*aBuffer, nTable));
   1.845 +			color = TRgb::_Gray4(color._Gray4());
   1.846 +			*aBuffer++ = color.Internal();
   1.847 +			}
   1.848 +		break;
   1.849 +	case EGray16:
   1.850 +		while (aBuffer < bufferLimit)
   1.851 +			{
   1.852 +			color.SetInternal(PMA2NonPMAPixel(*aBuffer, nTable));
   1.853 +			color = TRgb::_Gray16(color._Gray16());
   1.854 +			*aBuffer++ = color.Internal();
   1.855 +			}
   1.856 +		break;
   1.857 +	case EGray256:
   1.858 +		while (aBuffer < bufferLimit)
   1.859 +			{
   1.860 +			color.SetInternal(PMA2NonPMAPixel(*aBuffer, nTable));
   1.861 +			color = TRgb::_Gray256(color._Gray256());
   1.862 +			*aBuffer++ = color.Internal();
   1.863 +			}
   1.864 +		break;
   1.865 +	case EColor16:
   1.866 +		while (aBuffer < bufferLimit)
   1.867 +			{
   1.868 +			color.SetInternal(PMA2NonPMAPixel(*aBuffer, nTable));
   1.869 +			color = TRgb::Color16(color.Color16());
   1.870 +			*aBuffer++ = color.Internal();
   1.871 +			}
   1.872 +		break;
   1.873 +	case EColor256:
   1.874 +		while (aBuffer < bufferLimit)
   1.875 +			{
   1.876 +			color.SetInternal(PMA2NonPMAPixel(*aBuffer, nTable));
   1.877 +			color = TRgb::Color256(color.Color256());
   1.878 +			*aBuffer++ = color.Internal();
   1.879 +			}
   1.880 +		break;
   1.881 +	case EColor4K:
   1.882 +		while (aBuffer < bufferLimit)
   1.883 +			{
   1.884 +			color.SetInternal(PMA2NonPMAPixel(*aBuffer, nTable));
   1.885 +			color = TRgb::_Color4K(color._Color4K());
   1.886 +			*aBuffer++ = color.Internal();
   1.887 +			}
   1.888 +		break;
   1.889 +	case EColor64K:
   1.890 +		while (aBuffer < bufferLimit)
   1.891 +			{
   1.892 +			color.SetInternal(PMA2NonPMAPixel(*aBuffer, nTable));
   1.893 +			color = TRgb::_Color64K(color._Color64K());
   1.894 +			*aBuffer++ = color.Internal();
   1.895 +			}
   1.896 +		break;
   1.897 +	default:
   1.898 +		break;
   1.899 +		}
   1.900 +	}
   1.901 +
   1.902 +/**
   1.903 +Implementation for CFbsDrawDevice::GetInterface().
   1.904 +Retrieves a pointer to a specified interface of CFbsDrawDevice implementation.
   1.905 +@param aInterfaceId Interface identifier of the interface to be retrieved.
   1.906 +@param aInterface Address of variable that retrieves the specified interface.
   1.907 +@return KErrNone If the interface is supported, KErrNotSupported otherwise.
   1.908 +*/
   1.909 +TInt CDrawThirtyTwoBppBitmapCommon::GetInterface(TInt aInterfaceId, TAny*& aInterface)
   1.910 +	{
   1.911 +	aInterface = NULL;
   1.912 +	TInt ret = KErrNotSupported;
   1.913 +	
   1.914 +	if (aInterfaceId == KFastBlit2InterfaceID)
   1.915 +		{
   1.916 +		aInterface = static_cast<MFastBlit2*>(this);
   1.917 +		ret = KErrNone;
   1.918 +		}
   1.919 +	else
   1.920 +		return CDrawBitmap::GetInterface(aInterfaceId, aInterface);
   1.921 +		
   1.922 +	return ret;
   1.923 +	}
   1.924 +
   1.925 +/**
   1.926 +CDrawThirtyTwoBppBitmapCommon::WriteBitmapBlock() implementation.
   1.927 +@internalTechnology
   1.928 +@see MFastBlit2::WriteBitmapBlock()
   1.929 +*/
   1.930 +TInt CDrawThirtyTwoBppBitmapCommon::WriteBitmapBlock(const TPoint& aDest,
   1.931 +									CFbsDrawDevice* aSrcDrawDevice,
   1.932 +									const TRect& aSrcRect)
   1.933 +	{
   1.934 +	__ASSERT_DEBUG(aSrcDrawDevice && ((aSrcDrawDevice->DisplayMode()==EColor16MU) || (aSrcDrawDevice->DisplayMode()==EColor16MA) ||(aSrcDrawDevice->DisplayMode()==EColor16MAP)), Panic(EScreenDriverPanicInvalidParameter));
   1.935 +	
   1.936 +	TAny* interface=NULL;
   1.937 +	TInt ret = aSrcDrawDevice->GetInterface(KFastBlit2InterfaceID, interface);
   1.938 +	if (ret != KErrNone)
   1.939 +		{
   1.940 +		return KErrNotSupported;
   1.941 +		}
   1.942 +
   1.943 +	TAny* interface1=NULL;
   1.944 +	ret = aSrcDrawDevice->GetInterface(KScalingSettingsInterfaceID, interface1);
   1.945 +	if(ret != KErrNone || (interface1 && !reinterpret_cast<MScalingSettings*>(interface1)->IsScalingOff()))
   1.946 +		{
   1.947 +		return KErrNotSupported;
   1.948 +		}
   1.949 +
   1.950 +	ret = aSrcDrawDevice->GetInterface(KOrientationInterfaceID, interface1);
   1.951 +	if(ret != KErrNone || (interface1 && reinterpret_cast<MDrawDeviceOrientation*>(interface1)->Orientation() != 0))
   1.952 +		{
   1.953 +		return KErrNotSupported;
   1.954 +		}
   1.955 +
   1.956 +	ret = aSrcDrawDevice->GetInterface(KDrawDeviceOriginInterfaceID, interface1);
   1.957 +	if(ret != KErrNone)
   1.958 +		{
   1.959 +		return KErrNotSupported;
   1.960 +		}
   1.961 +	
   1.962 +	if(interface1)
   1.963 +		{
   1.964 +	 	TPoint pt;
   1.965 +	 	reinterpret_cast<MDrawDeviceOrigin*>(interface1)->Get(pt);
   1.966 +	 	if(pt.iX != 0 || pt.iY != 0)
   1.967 +	 		{
   1.968 +			return KErrNotSupported;
   1.969 +	 		}
   1.970 +		}
   1.971 +
   1.972 +	const TUint32* srcBase = reinterpret_cast<MFastBlit2*>(interface)->Bits();
   1.973 +	__ASSERT_DEBUG(srcBase!=NULL, Panic(EScreenDriverPanicInvalidParameter));
   1.974 +	TInt srcStride = aSrcDrawDevice->ScanLineBytes();  
   1.975 +	__ASSERT_DEBUG((srcStride&3)==0, Panic(EScreenDriverPanicInvalidParameter));  // stride is assumed to be a multiple of 4
   1.976 +	TSize srcSize = aSrcDrawDevice->SizeInPixels();
   1.977 +
   1.978 +	return WriteBitmapBlock(aDest, srcBase, srcStride, srcSize, aSrcRect);
   1.979 +	}
   1.980 +									
   1.981 +/**
   1.982 +CDrawThirtyTwoBppBitmapCommon::WriteBitmapBlock() implementation.
   1.983 +@internalTechnology
   1.984 +@see MFastBlit2::WriteBitmapBlock()
   1.985 +*/													
   1.986 +TInt CDrawThirtyTwoBppBitmapCommon::WriteBitmapBlock(const TPoint& aDest,
   1.987 +									const TUint32* aSrcBase,
   1.988 +									TInt aSrcStride,
   1.989 +									const TSize& aSrcSize,
   1.990 +									const TRect& aSrcRect)
   1.991 +	{
   1.992 +	__ASSERT_DEBUG(aSrcBase, Panic(EScreenDriverPanicInvalidParameter));
   1.993 +	__ASSERT_DEBUG((aSrcStride&3)==0, Panic(EScreenDriverPanicInvalidParameter));
   1.994 +	__ASSERT_DEBUG(iBits, Panic(EScreenDriverPanicInvalidPointer));
   1.995 +
   1.996 +	if (iShadowMode!=NULL ||
   1.997 +    	(iUserDispMode!=NULL && iUserDispMode!=iDispMode) ||
   1.998 +    	iOrientation!=EOrientationNormal ||
   1.999 +		!IsScalingOff() ||
  1.1000 +		!iOriginIsZero)
  1.1001 +		{
  1.1002 +		return KErrNotSupported;
  1.1003 +		}
  1.1004 +	
  1.1005 +	__ASSERT_DEBUG(aSrcRect.iTl.iX >= 0, Panic(EScreenDriverPanicOutOfBounds)); 
  1.1006 +	__ASSERT_DEBUG(aSrcRect.iTl.iY >= 0, Panic(EScreenDriverPanicOutOfBounds));
  1.1007 +	__ASSERT_DEBUG(aSrcRect.iBr.iX <= aSrcSize.iWidth,  Panic(EScreenDriverPanicOutOfBounds));
  1.1008 +	__ASSERT_DEBUG(aSrcRect.iBr.iY <= aSrcSize.iHeight, Panic(EScreenDriverPanicOutOfBounds));
  1.1009 +	__ASSERT_DEBUG(aDest.iX >= 0, Panic(EScreenDriverPanicOutOfBounds));
  1.1010 +	__ASSERT_DEBUG(aDest.iY >= 0, Panic(EScreenDriverPanicOutOfBounds));
  1.1011 +	__ASSERT_DEBUG((aDest.iX + aSrcRect.Width())  <= SizeInPixels().iWidth,  Panic(EScreenDriverPanicOutOfBounds));
  1.1012 +	__ASSERT_DEBUG((aDest.iY + aSrcRect.Height()) <= SizeInPixels().iHeight, Panic(EScreenDriverPanicOutOfBounds));
  1.1013 +	
  1.1014 +	const TInt srcStrideWords=aSrcStride >> 2;
  1.1015 +	const TInt dstStrideWords=iScanLineWords;
  1.1016 +	
  1.1017 +	if (aSrcSize.iWidth == aSrcRect.Width() &&
  1.1018 +		aSrcSize.iWidth == SizeInPixels().iWidth &&
  1.1019 +		srcStrideWords == dstStrideWords)
  1.1020 +		{
  1.1021 +		// Optimum case - one memcpy
  1.1022 +		__ASSERT_DEBUG(aSrcRect.iTl.iX==0 && aDest.iX==0, Panic(EScreenDriverPanicInvalidParameter));  // this is implied by the above conditions
  1.1023 +		const TUint32* srcPtr = aSrcBase + (iScanLineWords * aSrcRect.iTl.iY);
  1.1024 +		TUint32* dstPtr       = iBits    + (iScanLineWords * aDest.iY);
  1.1025 +		const TInt length = aSrcStride * aSrcRect.Height();
  1.1026 +		Mem::Move(dstPtr, srcPtr, length);
  1.1027 +		return KErrNone;
  1.1028 +		}
  1.1029 +		
  1.1030 +	// Sub-optimal case - one memcpy per line
  1.1031 +	const TUint32* srcPtr = aSrcBase + (srcStrideWords * aSrcRect.iTl.iY) + aSrcRect.iTl.iX;
  1.1032 +	TUint32* dstPtr       = iBits    + (dstStrideWords * aDest.iY		) + aDest.iX;
  1.1033 +	const TInt length = aSrcRect.Width() << 2;
  1.1034 +	TInt lines = aSrcRect.Height();
  1.1035 +	while (lines--)
  1.1036 +		{
  1.1037 +		Mem::Move(dstPtr, srcPtr, length);
  1.1038 +		srcPtr+=srcStrideWords;
  1.1039 +		dstPtr+=dstStrideWords;
  1.1040 +		}
  1.1041 +	return KErrNone;
  1.1042 +	}
  1.1043 +
  1.1044 +/**
  1.1045 +CDrawThirtyTwoBppBitmapCommon::Bits() implementation.
  1.1046 +@internalTechnology
  1.1047 +@see MFastBlit2::Bits()
  1.1048 +*/
  1.1049 +const TUint32* CDrawThirtyTwoBppBitmapCommon::Bits() const
  1.1050 +	{
  1.1051 +	return iBits;
  1.1052 +	}