graphicsdeviceinterface/screendriver/sbit/BMDRAW32.CPP
changeset 0 5d03bc08d59c
child 70 5e51caaeeb72
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <graphics/lookuptable.h>
       
    17 #include <graphics/blendingalgorithms.h>
       
    18 #include "BMDRAW.H"
       
    19 #include "BitDrawInterfaceId.h"
       
    20 
       
    21 FORCEINLINE void BlendFromRBandG(TUint32 *aPixelPtr, TUint32 aSrcRB, TUint32 aSrcG, TUint32 aSrcAlpha, TUint32 aMaskX2)
       
    22 	{
       
    23 	const TUint32 d = *aPixelPtr;
       
    24 	const TUint32 d_rb = d & 0x00FF00FF;
       
    25 	const TUint32 rb = ((((aSrcAlpha * ((0x01000100 + aSrcRB) - d_rb)) >> 8) + d_rb) - aMaskX2) & 0x00FF00FF;
       
    26 
       
    27 	const TInt d_g = (d & 0xFF00) >> 8;
       
    28 	const TInt g = ((aSrcAlpha * (aSrcG - d_g)) >> 8) + d_g;
       
    29 
       
    30 	*aPixelPtr = rb | (g<<8) | 0xff000000;
       
    31 	}
       
    32 
       
    33 /**Initializes iSize, iDrawRect, iLongWidth, iScanLineBytes, iScanlineWords data members.
       
    34  It should be called every time when iSize is going to be changed - from Construct().
       
    35 
       
    36  @param aSize Physical screen size in pixels.
       
    37  @panic EScreenDriverPanicInvalidSize - Invalid aSize parameter. This might happen if the
       
    38  device is scaled and the scaling origin goes outside physical drawing rectangle. */
       
    39 void CDrawThirtyTwoBppBitmapCommon::SetSize(const TSize& aSize)
       
    40 	{
       
    41 	CDrawBitmap::SetSize(aSize);
       
    42 	__ASSERT_DEBUG(iSize == aSize, User::Invariant());
       
    43 	iLongWidth = iSize.iWidth;
       
    44 	iScanLineWords = iSize.iWidth;
       
    45 	}
       
    46 
       
    47 TInt CDrawThirtyTwoBppBitmapCommon::Construct(TSize aSize, TInt aStride)
       
    48 	{
       
    49 	iBits = NULL;
       
    50 	CDrawBitmap::SetSize(aSize);
       
    51 	__ASSERT_DEBUG(iSize == aSize, User::Invariant());
       
    52 	if (aStride & 3)
       
    53 		return KErrArgument;
       
    54 	iLongWidth = aStride >> 2;
       
    55 	if (iLongWidth < aSize.iWidth)
       
    56 		return KErrArgument;
       
    57 	iScanLineWords = iLongWidth;
       
    58 	TInt size = Max(aSize.iWidth,aSize.iHeight) << 2;
       
    59 	if(size < 0)
       
    60 		return KErrArgument;
       
    61 	iScanLineBuffer = (TUint32*)(User::Heap().Alloc(size));
       
    62 	if (iScanLineBuffer == NULL)
       
    63 		return KErrNoMemory;
       
    64 	return KErrNone;
       
    65 	}
       
    66 
       
    67 void CDrawThirtyTwoBppBitmapCommon::Shadow(TRgb& aColor)
       
    68 	{
       
    69 	TUint32 value = aColor.Internal();
       
    70 	const TInt alpha = value >> 24;
       
    71 
       
    72 	if (iShadowMode & EFade)
       
    73 		{
       
    74 #if defined(SYMBIAN_USE_FAST_FADING)
       
    75 		value = ((value >> 1) & ~0x00808080) + (SYMBIAN_USE_FAST_FADING);
       
    76 #else		
       
    77 		const TInt wordFadeMapOffset = ((iFadeMapOffset & 0xff) << 16) | (iFadeMapOffset & 0xff);		
       
    78 		const TInt rb = ((((value & 0x00ff00ff) * iFadeMapFactor) >> 8) + wordFadeMapOffset) & 0x00ff00ff;
       
    79 	  	const TInt g = ((((value & 0x0000ff00) * iFadeMapFactor) >> 16) + iFadeMapOffset) << 8;
       
    80 		value = rb | g;
       
    81 #endif		
       
    82 		}
       
    83 
       
    84 	if (iShadowMode & EShadow)
       
    85 		{
       
    86 		const TInt r = (value & 0x00c00000) ? ((value & 0x00ff0000)-0x00400000) : 0;
       
    87 		const TInt g = (value & 0x0000c000) ? ((value & 0x0000ff00)-0x00004000) : 0;
       
    88 		const TInt b = (value & 0x000000c0) ? ((value & 0x000000ff)-0x00000040) : 0;
       
    89 		value = r | g | b;
       
    90 		}
       
    91 
       
    92 	aColor = TRgb(value,alpha);
       
    93 	}
       
    94 
       
    95 void CDrawThirtyTwoBppBitmapCommon::Shadow(TUint32& aColor)
       
    96 	{
       
    97 	// aColor is in the format indicated by ScanLineDisplayMode(), which we
       
    98 	// assume is EColor16MAP here. If not, this function must be overridden.
       
    99 	const TInt alpha = (aColor >> 24) + 1;
       
   100 	TUint32 value = aColor & 0x00ffffff;
       
   101 	if (iShadowMode & EFade)
       
   102 		{
       
   103 #if defined(SYMBIAN_USE_FAST_FADING)
       
   104 		const TUint32 fast_fade_offset = NonPMA2PMAPixel((aColor & 0xff000000) | SYMBIAN_USE_FAST_FADING) & 0x00ffffff;
       
   105 		value = ((value >> 1) & ~0x00808080) + (fast_fade_offset);
       
   106 #else
       
   107 		const TInt fadeMapOffset = ((alpha * iFadeMapOffset) >> 8) & 0xff;
       
   108 		const TInt wordFadeMapOffset = ((fadeMapOffset) << 16) | (fadeMapOffset);
       
   109 		const TInt rb = ((((value & 0x00ff00ff) * iFadeMapFactor) >> 8) + wordFadeMapOffset) & 0x00ff00ff;
       
   110 	  	const TInt g = ((((value & 0x0000ff00) * iFadeMapFactor) >> 16) + fadeMapOffset) << 8;
       
   111 		value = rb | g;
       
   112 #endif
       
   113 		}
       
   114 
       
   115 	if (iShadowMode & EShadow)
       
   116 		{
       
   117 		const TInt uLimit = ((0x40) * alpha) >> 8;
       
   118 		TInt r = (value >> 16) & 0xff;
       
   119 		r = (r > uLimit) ? (r-uLimit) : 0;
       
   120 		TInt g = (value >> 8) & 0xff;
       
   121 		g = (g > uLimit) ? (g - uLimit) : 0;
       
   122 		TInt b = value & 0xff;
       
   123 		b = (b > uLimit) ? (b - uLimit) : 0;
       
   124 		value = (r << 16) | (g << 8) | b;
       
   125 		}
       
   126 	// alpha is unchanged.
       
   127 	aColor = (aColor & 0xff000000) | value;
       
   128 	}
       
   129 
       
   130 TUint8 CDrawThirtyTwoBppBitmapCommon::ShadowAndFade(TInt aComponent)
       
   131 	{
       
   132 	if (iShadowMode & EFade)
       
   133 		aComponent = FadeGray(aComponent);
       
   134 
       
   135 	if (iShadowMode & EShadow)
       
   136 		aComponent = ShadowComponent(aComponent);
       
   137 
       
   138 	return TUint8(aComponent);
       
   139 	}
       
   140 
       
   141 TUint8 CDrawThirtyTwoBppBitmapCommon::ShadowComponent(TInt aRgbComponent)
       
   142 	{
       
   143 	return TUint8(Max(0,aRgbComponent-0x40));
       
   144 	}
       
   145 
       
   146 void CDrawThirtyTwoBppBitmapCommon::InvertBuffer(TInt aLength,TUint32* aBuffer)
       
   147 	{
       
   148 	__ASSERT_DEBUG(aLength>0,Panic(EScreenDriverPanicOutOfBounds));
       
   149 	__ASSERT_DEBUG(aBuffer,Panic(EScreenDriverPanicNullPointer));
       
   150 
       
   151 	TUint32* limit = aBuffer + aLength;
       
   152 
       
   153 	while (aBuffer < limit)
       
   154 		{
       
   155 		*aBuffer++ ^= 0x00ffffff;
       
   156 		}
       
   157 	}
       
   158 
       
   159 void CDrawThirtyTwoBppBitmapCommon::ReadLine(TInt aX,TInt aY,TInt aLength,TAny* aBuffer) const
       
   160 	{
       
   161 	const TUint32* pixelPtr = PixelAddress(aX,aY);
       
   162 
       
   163 	if (iOrientation == EOrientationNormal)
       
   164 		Mem::Copy(aBuffer,pixelPtr,aLength << 2);
       
   165 	else
       
   166 		{
       
   167 		const TInt pixelPtrInc = PixelAddressIncrement();
       
   168 
       
   169 		TUint32* bufferPtr = static_cast <TUint32*> (aBuffer);
       
   170 		const TUint32* bufferPtrLimit = bufferPtr + aLength;
       
   171 
       
   172 		while (bufferPtr < bufferPtrLimit)
       
   173 			{
       
   174 			*bufferPtr++ = *pixelPtr;
       
   175 			pixelPtr += pixelPtrInc;
       
   176 			}
       
   177 		}
       
   178 	}
       
   179 
       
   180 TRgb CDrawThirtyTwoBppBitmapCommon::ReadRgbNormal(TInt aX,TInt aY) const
       
   181 	{
       
   182 	return RgbColor(*PixelAddress(aX,aY));
       
   183 	}
       
   184 
       
   185 void CDrawThirtyTwoBppBitmapCommon::ShadowArea(const TRect& aRect)
       
   186 	{
       
   187 	const TRect rect(DeOrientate(aRect));
       
   188 
       
   189 	__ASSERT_DEBUG(rect.iTl.iX>=0 && rect.iBr.iX<=iSize.iWidth,Panic(EScreenDriverPanicOutOfBounds));
       
   190 	__ASSERT_DEBUG(rect.iTl.iY>=0 && rect.iBr.iY<=iSize.iHeight,Panic(EScreenDriverPanicOutOfBounds));
       
   191 
       
   192 	TUint32* pixelPtr = PixelAddress(rect.iTl.iX,rect.iTl.iY);
       
   193 	TUint32* pixelRowPtrLimit = pixelPtr + (rect.Height() * iScanLineWords);
       
   194 
       
   195 	TUint32* pixelRowPtr = pixelPtr;
       
   196 	TUint32* pixelPtrLimit = pixelPtr + rect.Width();
       
   197 
       
   198 	if (iShadowMode & EFade)
       
   199 		{
       
   200 #if !defined(SYMBIAN_USE_FAST_FADING)		
       
   201 		const TInt wordFadeMapOffset = ((iFadeMapOffset & 0xff) << 16) | (iFadeMapOffset & 0xff);
       
   202 #endif
       
   203 		while (pixelRowPtr < pixelRowPtrLimit)
       
   204 			{
       
   205 			TUint32* tempPixelPtr = pixelRowPtr;
       
   206 
       
   207 			while (tempPixelPtr < pixelPtrLimit)
       
   208 				{
       
   209 #if defined(SYMBIAN_USE_FAST_FADING)
       
   210 				*tempPixelPtr++ = 0xff000000 | ((((*tempPixelPtr) >> 1) & ~0x00808080) + (SYMBIAN_USE_FAST_FADING));
       
   211 #else
       
   212 				const TUint32 color = *tempPixelPtr;
       
   213 				const TInt rb = ((((color & 0x00ff00ff) * iFadeMapFactor) >> 8) + wordFadeMapOffset) & 0x00ff00ff;
       
   214 	  			const TInt g = ((((color & 0x0000ff00) * iFadeMapFactor) >> 16) + iFadeMapOffset) << 8;
       
   215 				*tempPixelPtr++ = 0xff000000 | rb | g;
       
   216 #endif				
       
   217 				}
       
   218 				
       
   219 			pixelRowPtr += iScanLineWords;
       
   220 			pixelPtrLimit += iScanLineWords;
       
   221 			}
       
   222 		}
       
   223 
       
   224 	if (iShadowMode & EShadow)
       
   225 		{
       
   226 		pixelRowPtr = pixelPtr;
       
   227 		pixelPtrLimit = pixelPtr + rect.Width();		
       
   228 		while (pixelRowPtr < pixelRowPtrLimit)
       
   229 			{
       
   230 			TUint32* tempPixelPtr = pixelRowPtr;
       
   231 
       
   232 			while (tempPixelPtr < pixelPtrLimit)
       
   233 				{
       
   234 				const TUint32 color = *tempPixelPtr;
       
   235 				const TInt r = (color & 0x00c00000) ? ((color & 0x00ff0000)-0x00400000) : 0;
       
   236 				const TInt g = (color & 0x0000c000) ? ((color & 0x0000ff00)-0x00004000) : 0;
       
   237 				const TInt b = (color & 0x000000c0) ? ((color & 0x000000ff)-0x00000040) : 0;
       
   238 				*tempPixelPtr++	= 0xff000000 | r | g | b;
       
   239 				}
       
   240 
       
   241 			pixelRowPtr += iScanLineWords;
       
   242 			pixelPtrLimit += iScanLineWords;
       
   243 			}
       
   244 		}
       
   245 	}
       
   246 
       
   247 void CDrawThirtyTwoBppBitmapCommon::ShadowBuffer(TInt aLength,TUint32* aBuffer)
       
   248 	{
       
   249 	__ASSERT_DEBUG(aLength>0,Panic(EScreenDriverPanicZeroLength));
       
   250 	__ASSERT_DEBUG(aBuffer,Panic(EScreenDriverPanicNullPointer));
       
   251 
       
   252 	TUint32* limit = aBuffer + aLength;
       
   253 
       
   254 	while (aBuffer < limit)
       
   255 		Shadow(*aBuffer++);
       
   256 	}
       
   257 
       
   258 void CDrawThirtyTwoBppBitmapCommon::WriteRgb(TInt aX,TInt aY,TRgb aColor)
       
   259 	{
       
   260 	TUint8* componentPtr = reinterpret_cast <TUint8*> (PixelAddress(aX,aY));
       
   261 	const TInt sourceAlpha = aColor.Alpha();
       
   262 
       
   263 	if (sourceAlpha==0)
       
   264 		return;
       
   265 	if(sourceAlpha != 0xff)
       
   266 		{
       
   267 		aColor = AlphaBlend(aColor.Red(), aColor.Green(), aColor.Blue(), TRgb(componentPtr[2], componentPtr[1], componentPtr[0]), sourceAlpha);
       
   268 		}
       
   269 
       
   270 	componentPtr[0] = TUint8(aColor.Blue());
       
   271 	componentPtr[1] = TUint8(aColor.Green());
       
   272 	componentPtr[2] = TUint8(aColor.Red());
       
   273 	}
       
   274 
       
   275 void CDrawThirtyTwoBppBitmapCommon::WriteBinary(TInt aX,TInt aY,TUint32* aBuffer,TInt aLength,TInt aHeight,TRgb aColor)
       
   276 	{
       
   277 	const TInt sourceAlpha = aColor.Alpha();
       
   278 	if(sourceAlpha == 0)
       
   279 		return;
       
   280 	DeOrientate(aX,aY);
       
   281 
       
   282 	TInt pixelInc;
       
   283 	TInt rowInc;
       
   284 
       
   285 	switch(iOrientation)
       
   286 		{
       
   287 		case EOrientationNormal:
       
   288 			{
       
   289 			pixelInc = 1;
       
   290 			rowInc = iScanLineWords;
       
   291 			break;
       
   292 			}
       
   293 		case EOrientationRotated90:
       
   294 			{
       
   295 			pixelInc = iScanLineWords;
       
   296 			rowInc = -1;
       
   297 			break;
       
   298 			}
       
   299 		case EOrientationRotated180:
       
   300 			{
       
   301 			pixelInc = -1;
       
   302 			rowInc = -iScanLineWords;
       
   303 			break;
       
   304 			}
       
   305 		default: // EOrientationRotated270
       
   306 			{
       
   307 			pixelInc = -iScanLineWords;
       
   308 			rowInc = 1;
       
   309 			}
       
   310 		}
       
   311 
       
   312 	const TUint32* dataLimit = aBuffer + aHeight;
       
   313 	const TUint32 dataMaskLimit = (aLength < 32) ? 1 << aLength : 0;
       
   314 
       
   315 	TUint32* pixelPtr = PixelAddress(aX,aY);
       
   316 
       
   317 	if(sourceAlpha == 255) //we split code on two parts because of performance reasons
       
   318 		{
       
   319 		TInt color = Color(aColor);
       
   320 		while (aBuffer < dataLimit)
       
   321 			{
       
   322 			TUint32 dataWord = *aBuffer++;
       
   323 			TUint32 dataMask = 1;
       
   324 			TUint32* tempPixelPtr = pixelPtr;
       
   325 
       
   326 			while (dataMask != dataMaskLimit)
       
   327 				{
       
   328 				if(dataWord & dataMask)
       
   329 					{
       
   330 					*tempPixelPtr = color;
       
   331 					}
       
   332 
       
   333 				tempPixelPtr += pixelInc;
       
   334 				dataMask <<= 1;
       
   335 				}
       
   336 
       
   337 			pixelPtr += rowInc;
       
   338 			}
       
   339 		}
       
   340 	else //sourceAlpha != 255
       
   341 		{
       
   342 		const TUint32 sourceInternal=aColor.Internal();
       
   343 		const TUint32 s_rb = sourceInternal & 0x00FF00FF;
       
   344 		const TUint32 s_g = (sourceInternal & 0xFF00) >> 8;
       
   345 		const TUint32 mask2 = sourceAlpha | (sourceAlpha << 16);
       
   346 		while (aBuffer < dataLimit)
       
   347 			{
       
   348 			TUint32 dataWord = *aBuffer++;
       
   349 			TUint32 dataMask = 1;
       
   350 			TUint32* tempPixelPtr = pixelPtr;
       
   351 
       
   352 			while (dataMask != dataMaskLimit)
       
   353 				{
       
   354 				if (dataWord & dataMask)
       
   355 					{
       
   356 					BlendFromRBandG(tempPixelPtr,s_rb,s_g,sourceAlpha,mask2);
       
   357 					}
       
   358 
       
   359 				tempPixelPtr += pixelInc;
       
   360 				dataMask <<= 1;
       
   361 				}
       
   362 
       
   363 			pixelPtr += rowInc;
       
   364 			}
       
   365 		}
       
   366 	}
       
   367 
       
   368 void CDrawThirtyTwoBppBitmapCommon::WriteBinaryOp(TInt aX,TInt aY,TUint32* aBuffer,TInt aLength,TInt aHeight,TRgb aColor,CGraphicsContext::TDrawMode aDrawMode)
       
   369 	{
       
   370 	if (aLength <= 0)
       
   371 		return;
       
   372 
       
   373 	DeOrientate(aX,aY);
       
   374 	TUint32* pixelPtr = PixelAddress(aX,aY);
       
   375 
       
   376 	const TUint32* dataPtrLimit = aBuffer + aHeight;
       
   377 	const TUint32 dataMaskLimit = (aLength < 32) ? 1 << aLength : 0;
       
   378 
       
   379 	TInt pixelInc;
       
   380 	TInt rowInc;
       
   381 
       
   382 	if (iOrientation == EOrientationNormal)
       
   383 		{
       
   384 		pixelInc = 1;
       
   385 		rowInc = iScanLineWords;
       
   386 		}
       
   387 	else if (iOrientation == EOrientationRotated90)
       
   388 		{
       
   389 		pixelInc = iScanLineWords;
       
   390 		rowInc = -1;
       
   391 		}
       
   392 	else if (iOrientation == EOrientationRotated180)
       
   393 		{
       
   394 		pixelInc = -1;
       
   395 		rowInc = -iScanLineWords;
       
   396 		}
       
   397 	else // EOrientationRotated270
       
   398 		{
       
   399 		pixelInc = -iScanLineWords;
       
   400 		rowInc = 1;
       
   401 		}
       
   402 
       
   403 	TInt color = Color(aColor);// & 0x00FFFFFF;
       
   404 
       
   405 	if (color != 0)
       
   406 		{
       
   407 		while (aBuffer < dataPtrLimit)
       
   408 			{
       
   409 			TUint32 dataWord = *aBuffer++;
       
   410 			TUint32 dataMask = 1;
       
   411 			TUint32* tempPixelPtr = pixelPtr;
       
   412 
       
   413 			while (dataMask != dataMaskLimit)
       
   414 				{
       
   415 				if(dataWord & dataMask)
       
   416 					{
       
   417 					if(aDrawMode==CGraphicsContext::EDrawModeXOR)
       
   418 						{
       
   419 						*tempPixelPtr ^= color;
       
   420 						}
       
   421 					else if(aDrawMode==CGraphicsContext::EDrawModeAND)
       
   422 						{
       
   423 						*tempPixelPtr &= color;
       
   424 						}
       
   425 					else if(aDrawMode==CGraphicsContext::EDrawModeOR)
       
   426 						{
       
   427 						*tempPixelPtr |= color;
       
   428 						}
       
   429 					}
       
   430 
       
   431 				tempPixelPtr += pixelInc;
       
   432 				dataMask <<= 1;
       
   433 				}
       
   434 
       
   435 			pixelPtr += rowInc;
       
   436 			}
       
   437 		}
       
   438 	else if (aDrawMode == CGraphicsContext::EDrawModeAND)
       
   439 		{
       
   440 		while (aBuffer < dataPtrLimit)
       
   441 			{
       
   442 			TUint32 dataWord = *aBuffer++;
       
   443 			TUint32 dataMask = 1;
       
   444 			TUint32* tempPixelPtr = pixelPtr;
       
   445 
       
   446 			while (dataMask != dataMaskLimit)
       
   447 				{
       
   448 				if(dataWord & dataMask)
       
   449 					{
       
   450 					*tempPixelPtr = 0;
       
   451 					}
       
   452 
       
   453 				tempPixelPtr += pixelInc;
       
   454 				dataMask <<= 1;
       
   455 				}
       
   456 
       
   457 			pixelPtr += rowInc;
       
   458 			}
       
   459 		}
       
   460 	}
       
   461 
       
   462 void CDrawThirtyTwoBppBitmapCommon::WriteBinaryLineVertical(TInt aX,TInt aY,TUint32* aBuffer,TInt aHeight,TRgb aColor,TBool aUp)
       
   463 	{
       
   464 	const TInt sourceAlpha = aColor.Alpha();
       
   465 	if(sourceAlpha == 0)
       
   466 		return;
       
   467 	DeOrientate(aX,aY);
       
   468 
       
   469 	TInt scanlineWordLength;
       
   470 
       
   471 	if (iOrientation == EOrientationNormal)
       
   472 		scanlineWordLength = iScanLineWords;
       
   473 	else if (iOrientation == EOrientationRotated90)
       
   474 		scanlineWordLength = -1;
       
   475 	else if (iOrientation == EOrientationRotated180)
       
   476 		scanlineWordLength = -iScanLineWords;
       
   477 	else // EOrientationRotated270
       
   478 		scanlineWordLength = 1;
       
   479 
       
   480 	if (aUp)
       
   481 		scanlineWordLength = -scanlineWordLength;
       
   482 
       
   483 	TUint32* pixelPtr = PixelAddress(aX,aY);
       
   484 	const TUint32* pixelPtrLimit = pixelPtr + (aHeight * scanlineWordLength);
       
   485 	TUint32 dataWord = *aBuffer;
       
   486 	TUint32 dataMask = 1;
       
   487 
       
   488 	if(sourceAlpha == 255) //we split code on two parts because of performance reasons
       
   489 		{
       
   490 		TInt color = Color(aColor);
       
   491 		while(pixelPtr != pixelPtrLimit)
       
   492 			{
       
   493 			if(!dataMask)
       
   494 				{
       
   495 				dataMask = 1;
       
   496 				aBuffer++;
       
   497 				dataWord = *aBuffer;
       
   498 				}
       
   499 
       
   500 			if(dataWord & dataMask)
       
   501 				{
       
   502 				*pixelPtr = color;
       
   503 				}
       
   504 
       
   505 			dataMask <<= 1;
       
   506 			pixelPtr += scanlineWordLength;
       
   507 			}
       
   508 		}
       
   509 	else //sourceAlpha != 255
       
   510 		{
       
   511 		const TUint32 sourceInternal=aColor.Internal();
       
   512 		const TUint32 s_rb = sourceInternal & 0x00FF00FF;
       
   513 		const TUint32 s_g = (sourceInternal & 0xFF00) >> 8;
       
   514 		const TUint32 mask2 = sourceAlpha | (sourceAlpha << 16);
       
   515 		while(pixelPtr != pixelPtrLimit)
       
   516 			{
       
   517 			if(!dataMask)
       
   518 				{
       
   519 				dataMask = 1;
       
   520 				aBuffer++;
       
   521 				dataWord = *aBuffer;
       
   522 				}
       
   523 
       
   524 			if(dataWord & dataMask)
       
   525 				{
       
   526 				BlendFromRBandG(pixelPtr, s_rb, s_g, sourceAlpha, mask2);
       
   527 				}
       
   528 
       
   529 			dataMask <<= 1;
       
   530 			pixelPtr += scanlineWordLength;
       
   531 			}
       
   532 		}
       
   533 	}
       
   534 
       
   535 void CDrawThirtyTwoBppBitmapCommon::WriteLine(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer)
       
   536 	{
       
   537 	TUint32* pixelPtr = PixelAddress(aX,aY);
       
   538 
       
   539 	if (iOrientation == EOrientationNormal)
       
   540 		Mem::Copy(pixelPtr,aBuffer,aLength << 2);
       
   541 	else
       
   542 		{
       
   543 		const TInt pixelPtrInc = PixelAddressIncrement();
       
   544 
       
   545 		TUint32* bufferPtrLimit = aBuffer + aLength;
       
   546 
       
   547 		while (aBuffer < bufferPtrLimit)
       
   548 			{
       
   549 			*pixelPtr = *aBuffer++;
       
   550 			pixelPtr += pixelPtrInc;
       
   551 			}
       
   552 		}
       
   553 	}
       
   554 
       
   555 void CDrawThirtyTwoBppBitmapCommon::WriteLineXOR(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer)
       
   556 	{
       
   557 	TUint32* pixelPtr = PixelAddress(aX,aY);
       
   558 	const TInt pixelPtrInc = PixelAddressIncrement();
       
   559 
       
   560 	TUint32* bufferPtrLimit = aBuffer + aLength;
       
   561 
       
   562 	while (aBuffer < bufferPtrLimit)
       
   563 		{
       
   564 		*pixelPtr ^= *aBuffer++;
       
   565 		pixelPtr += pixelPtrInc;
       
   566 		}
       
   567 	}
       
   568 
       
   569 void CDrawThirtyTwoBppBitmapCommon::WriteLineAND(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer)
       
   570 	{
       
   571 	TUint32* pixelPtr = PixelAddress(aX,aY);
       
   572 	const TInt pixelPtrInc = PixelAddressIncrement();
       
   573 
       
   574 	TUint32* bufferPtrLimit = aBuffer + aLength;
       
   575 
       
   576 	while (aBuffer < bufferPtrLimit)
       
   577 		{
       
   578 		*pixelPtr &= *aBuffer++;
       
   579 		pixelPtr += pixelPtrInc;
       
   580 		}
       
   581 	}
       
   582 
       
   583 void CDrawThirtyTwoBppBitmapCommon::WriteLineOR(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer)
       
   584 	{
       
   585 	TUint32* pixelPtr = PixelAddress(aX,aY);
       
   586 	const TInt pixelPtrInc = PixelAddressIncrement();
       
   587 
       
   588 	TUint32* bufferPtrLimit = aBuffer + aLength;
       
   589 
       
   590 	while (aBuffer < bufferPtrLimit)
       
   591 		{
       
   592 		*pixelPtr |= *aBuffer++;
       
   593 		pixelPtr += pixelPtrInc;
       
   594 		}
       
   595 	}
       
   596 
       
   597 /**
       
   598 MAlphaBlend::WriteRgbAlphaLine() implementation.
       
   599 @see MAlphaBlend::WriteRgbAlphaLine()
       
   600 */
       
   601 void CDrawThirtyTwoBppBitmapCommon::WriteRgbAlphaLine(TInt aX, TInt aY, TInt aLength,
       
   602                                                   const TUint8* aRgbBuffer,
       
   603                                                   const TUint8* aMaskBuffer,
       
   604                                                   MAlphaBlend::TShadowing aShadowing,
       
   605                                                   CGraphicsContext::TDrawMode /*aDrawMode*/)
       
   606     {
       
   607 	DeOrientate(aX,aY);
       
   608 	TUint32* pixelPtr = PixelAddress(aX,aY);
       
   609 	const TInt pixelPtrInc = PixelAddressIncrement();
       
   610 	const TUint8* maskBufferPtrLimit = aMaskBuffer + aLength;
       
   611 
       
   612 	while (aMaskBuffer < maskBufferPtrLimit)
       
   613 		{
       
   614 		TRgb srcColor(aRgbBuffer[2],aRgbBuffer[1],aRgbBuffer[0]);// !! we don't have any alpha information for the source, so assume opaque
       
   615 		if(aMaskBuffer[0])
       
   616 			{
       
   617 			if(aShadowing == MAlphaBlend::EShdwBefore)
       
   618 				{
       
   619 				Shadow(srcColor);
       
   620 				}
       
   621 			TUint8* componentPtr = reinterpret_cast <TUint8*> (pixelPtr);
       
   622 			if(aMaskBuffer[0] != 0xff)
       
   623 				{
       
   624 				srcColor = AlphaBlend(srcColor.Red(), srcColor.Green(), srcColor.Blue(), TRgb(componentPtr[2], componentPtr[1], componentPtr[0]), aMaskBuffer[0]);
       
   625 				}
       
   626 			if(aShadowing == MAlphaBlend::EShdwAfter)
       
   627 				{
       
   628 				Shadow(srcColor);
       
   629 				}
       
   630 			MapColorToUserDisplayMode(srcColor);
       
   631 			componentPtr[0] = TUint8(srcColor.Blue());
       
   632 			componentPtr[1] = TUint8(srcColor.Green());
       
   633 			componentPtr[2] = TUint8(srcColor.Red());
       
   634 			}
       
   635 		pixelPtr += pixelPtrInc;
       
   636 		aRgbBuffer += 4;
       
   637 		aMaskBuffer++;
       
   638 		}
       
   639 	}
       
   640 
       
   641 void CDrawThirtyTwoBppBitmapCommon::WriteRgbMulti(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
       
   642 	{
       
   643 	TUint32* pixelPtr = PixelAddress(aX,aY);
       
   644 	TUint32* pixelRowPtrLimit = pixelPtr + (aHeight * iScanLineWords);
       
   645 
       
   646 	TInt color = Color(aColor);
       
   647 
       
   648 	while (pixelPtr < pixelRowPtrLimit)
       
   649 		{
       
   650 		MemFillTUint32(pixelPtr, aLength, color);
       
   651 		pixelPtr += iScanLineWords;
       
   652 		}
       
   653 	}
       
   654 
       
   655 void CDrawThirtyTwoBppBitmapCommon::WriteRgbMultiXOR(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
       
   656 	{
       
   657 	TUint32* pixelPtr = PixelAddress(aX,aY);
       
   658 	TUint32* pixelPtrLimit = pixelPtr + aLength;
       
   659 	TUint32* pixelRowPtrLimit = pixelPtr + (aHeight * iScanLineWords);
       
   660 	TInt color = Color(aColor);
       
   661 
       
   662 	while (pixelPtr < pixelRowPtrLimit)
       
   663 		{
       
   664 		for (TUint32* tempPixelPtr = pixelPtr; tempPixelPtr < pixelPtrLimit; tempPixelPtr++)
       
   665 			{
       
   666 			*tempPixelPtr ^= color;
       
   667 			}
       
   668 
       
   669 		pixelPtr += iScanLineWords;
       
   670 		pixelPtrLimit += iScanLineWords;
       
   671 		}
       
   672 	}
       
   673 
       
   674 void CDrawThirtyTwoBppBitmapCommon::WriteRgbMultiAND(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
       
   675 	{
       
   676 	TUint32* pixelPtr = PixelAddress(aX,aY);
       
   677 	TUint32* pixelPtrLimit = pixelPtr + aLength;
       
   678 	TUint32* pixelRowPtrLimit = pixelPtr + (aHeight * iScanLineWords);
       
   679 	TInt color = Color(aColor);
       
   680 
       
   681 	while (pixelPtr < pixelRowPtrLimit)
       
   682 		{
       
   683 		for (TUint32* tempPixelPtr = pixelPtr; tempPixelPtr < pixelPtrLimit; tempPixelPtr++)
       
   684 			{
       
   685 			*tempPixelPtr &= color;
       
   686 			}
       
   687 
       
   688 		pixelPtr += iScanLineWords;
       
   689 		pixelPtrLimit += iScanLineWords;
       
   690 		}
       
   691 	}
       
   692 
       
   693 void CDrawThirtyTwoBppBitmapCommon::WriteRgbMultiOR(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
       
   694 	{
       
   695 	TUint32* pixelPtr = PixelAddress(aX,aY);
       
   696 	TUint32* pixelPtrLimit = pixelPtr + aLength;
       
   697 	TUint32* pixelRowPtrLimit = pixelPtr + (aHeight * iScanLineWords);
       
   698 	TInt color = Color(aColor);
       
   699 
       
   700 	while (pixelPtr < pixelRowPtrLimit)
       
   701 		{
       
   702 		for (TUint32* tempPixelPtr = pixelPtr; tempPixelPtr < pixelPtrLimit; tempPixelPtr++)
       
   703 			{
       
   704 			*tempPixelPtr |= color;
       
   705 			}
       
   706 
       
   707 		pixelPtr += iScanLineWords;
       
   708 		pixelPtrLimit += iScanLineWords;
       
   709 		}
       
   710 	}
       
   711 
       
   712 inline TUint32 OptimizedBlend32(TInt aPrimaryRed,TInt aPrimaryGreen,TInt aPrimaryBlue,TUint32 aSecondary,TUint8 aAlphaValue)
       
   713 	{
       
   714  	__ASSERT_DEBUG(!(aPrimaryRed>>8) && !(aPrimaryGreen>>8) && !(aPrimaryBlue>>8) && !(aAlphaValue>>8),
       
   715 					Panic(EScreenDriverPanicAlphaBlendInvariant));
       
   716 
       
   717  	if(aAlphaValue == 0xff)
       
   718 		{
       
   719 		return (aPrimaryBlue + (aPrimaryGreen<<8) + (aPrimaryRed<<16)) | 0xff000000;
       
   720  		}
       
   721  	else
       
   722  		{
       
   723  		const TUint32 alphaValue = (aAlphaValue << 8) + aAlphaValue;
       
   724 
       
   725  		const TInt r2 = (aSecondary & 0x00ff0000) >> 16;
       
   726  		const TInt g2 = (aSecondary & 0x0000ff00) >> 8;
       
   727  		const TInt b2 = aSecondary & 0x000000ff;
       
   728 
       
   729  		const TInt r3 = ((alphaValue * (aPrimaryRed   - r2)) >> 16) + r2;
       
   730 		const TInt g3 = ((alphaValue * (aPrimaryGreen - g2)) >> 16) + g2;
       
   731 		const TInt b3 = ((alphaValue * (aPrimaryBlue  - b2)) >> 16) + b2;
       
   732 
       
   733 		return (b3 & 0xFF) | ((g3<<8) & 0xFF00) | ((r3<<16) & 0xFF0000) | 0xFF000000;
       
   734  		}
       
   735  	}
       
   736 
       
   737 void CDrawThirtyTwoBppBitmapCommon::WriteRgbAlphaMulti(TInt aX,TInt aY,TInt aLength,TRgb aColor,const TUint8* aMaskBuffer)
       
   738 	{
       
   739 	const TUint32 sourceAlpha = aColor.Alpha();
       
   740 	if (sourceAlpha==0 || aLength<=0)
       
   741 		return;
       
   742 	DeOrientate(aX,aY);
       
   743 	TUint32* pixelPtr = PixelAddress(aX,aY);
       
   744 	const TInt pixelPtrInc = PixelAddressIncrement();
       
   745 	const TUint8* maskBufferPtrLimit = aMaskBuffer + aLength;
       
   746 
       
   747 	if (iShadowMode)
       
   748 		Shadow(aColor);
       
   749 
       
   750 	const TUint32 sourceInternal=aColor.Internal();
       
   751 	const TUint32 s_rb = sourceInternal & 0x00FF00FF;
       
   752 	const TUint32 s_g = (sourceInternal & 0xFF00) >> 8;
       
   753 	if (sourceAlpha==0xFF)
       
   754 		{
       
   755 		while (aMaskBuffer < maskBufferPtrLimit)
       
   756 			{
       
   757 			const TUint32 maskAlpha=*aMaskBuffer;
       
   758 			if (maskAlpha)
       
   759 				{
       
   760 				if (maskAlpha==0xFF)
       
   761 					*pixelPtr = sourceInternal;
       
   762 				else
       
   763 					BlendFromRBandG(pixelPtr,s_rb,s_g,maskAlpha,maskAlpha|(maskAlpha<<16));
       
   764 				}
       
   765 			pixelPtr += pixelPtrInc;
       
   766 			aMaskBuffer++;
       
   767 			}
       
   768 		}
       
   769 	else
       
   770 		{
       
   771 		while (aMaskBuffer < maskBufferPtrLimit)
       
   772 			{
       
   773 			const TUint32 maskAlpha=*aMaskBuffer;
       
   774 			if (maskAlpha)
       
   775 				{
       
   776 				TUint blendAlpha = sourceAlpha;
       
   777 				if (maskAlpha!=0xFF)
       
   778 					blendAlpha=((maskAlpha+1) * sourceAlpha)>>8;
       
   779 				BlendFromRBandG(pixelPtr,s_rb,s_g,blendAlpha,blendAlpha|(blendAlpha<<16));
       
   780 				}
       
   781 			pixelPtr += pixelPtrInc;
       
   782 			aMaskBuffer++;
       
   783 			}
       
   784 		}
       
   785 	}
       
   786 
       
   787 void CDrawThirtyTwoBppBitmapCommon::MapColorToUserDisplayMode(TRgb& aColor)
       
   788 	{
       
   789 	const TInt alpha = aColor.Alpha();
       
   790 	switch (iUserDispMode)
       
   791 		{
       
   792 	case EGray2:
       
   793 		aColor = TRgb::_Gray2(aColor._Gray2());
       
   794 		break;
       
   795 	case EGray4:
       
   796 		aColor = TRgb::_Gray4(aColor._Gray4());
       
   797 		break;
       
   798 	case EGray16:
       
   799 		aColor = TRgb::_Gray16(aColor._Gray16());
       
   800 		break;
       
   801 	case EGray256:
       
   802 		aColor = TRgb::_Gray256(aColor._Gray256());
       
   803 		break;
       
   804 	case EColor16:
       
   805 		aColor = TRgb::Color16(aColor.Color16());
       
   806 		break;
       
   807 	case EColor256:
       
   808 		aColor = TRgb::Color256(aColor.Color256());
       
   809 		break;
       
   810 	case EColor4K:
       
   811 		aColor = TRgb::_Color4K(aColor._Color4K());
       
   812 		break;
       
   813 	case EColor64K:
       
   814 		aColor = TRgb::_Color64K(aColor._Color64K());
       
   815 		break;
       
   816 	default:
       
   817 		break;
       
   818 		}
       
   819 	aColor.SetAlpha(alpha);
       
   820 	}
       
   821 
       
   822 void CDrawThirtyTwoBppBitmapCommon::MapBufferToUserDisplayMode(TInt aLength,TUint32* aBuffer)
       
   823 	{
       
   824 	const TUint32* bufferLimit = aBuffer + aLength;
       
   825 	const TUint16* nTable = PtrTo16BitNormalisationTable();
       
   826 	TRgb color;
       
   827 
       
   828 	switch (iUserDispMode)
       
   829 		{
       
   830 	case EGray2:
       
   831 		while (aBuffer < bufferLimit)
       
   832 			{
       
   833 			color.SetInternal(PMA2NonPMAPixel(*aBuffer, nTable));
       
   834 			color = TRgb::_Gray2(color._Gray2());
       
   835 			*aBuffer++ = color.Internal();
       
   836 			}
       
   837 		break;
       
   838 	case EGray4:
       
   839 		while (aBuffer < bufferLimit)
       
   840 			{
       
   841 			color.SetInternal(PMA2NonPMAPixel(*aBuffer, nTable));
       
   842 			color = TRgb::_Gray4(color._Gray4());
       
   843 			*aBuffer++ = color.Internal();
       
   844 			}
       
   845 		break;
       
   846 	case EGray16:
       
   847 		while (aBuffer < bufferLimit)
       
   848 			{
       
   849 			color.SetInternal(PMA2NonPMAPixel(*aBuffer, nTable));
       
   850 			color = TRgb::_Gray16(color._Gray16());
       
   851 			*aBuffer++ = color.Internal();
       
   852 			}
       
   853 		break;
       
   854 	case EGray256:
       
   855 		while (aBuffer < bufferLimit)
       
   856 			{
       
   857 			color.SetInternal(PMA2NonPMAPixel(*aBuffer, nTable));
       
   858 			color = TRgb::_Gray256(color._Gray256());
       
   859 			*aBuffer++ = color.Internal();
       
   860 			}
       
   861 		break;
       
   862 	case EColor16:
       
   863 		while (aBuffer < bufferLimit)
       
   864 			{
       
   865 			color.SetInternal(PMA2NonPMAPixel(*aBuffer, nTable));
       
   866 			color = TRgb::Color16(color.Color16());
       
   867 			*aBuffer++ = color.Internal();
       
   868 			}
       
   869 		break;
       
   870 	case EColor256:
       
   871 		while (aBuffer < bufferLimit)
       
   872 			{
       
   873 			color.SetInternal(PMA2NonPMAPixel(*aBuffer, nTable));
       
   874 			color = TRgb::Color256(color.Color256());
       
   875 			*aBuffer++ = color.Internal();
       
   876 			}
       
   877 		break;
       
   878 	case EColor4K:
       
   879 		while (aBuffer < bufferLimit)
       
   880 			{
       
   881 			color.SetInternal(PMA2NonPMAPixel(*aBuffer, nTable));
       
   882 			color = TRgb::_Color4K(color._Color4K());
       
   883 			*aBuffer++ = color.Internal();
       
   884 			}
       
   885 		break;
       
   886 	case EColor64K:
       
   887 		while (aBuffer < bufferLimit)
       
   888 			{
       
   889 			color.SetInternal(PMA2NonPMAPixel(*aBuffer, nTable));
       
   890 			color = TRgb::_Color64K(color._Color64K());
       
   891 			*aBuffer++ = color.Internal();
       
   892 			}
       
   893 		break;
       
   894 	default:
       
   895 		break;
       
   896 		}
       
   897 	}
       
   898 
       
   899 /**
       
   900 Implementation for CFbsDrawDevice::GetInterface().
       
   901 Retrieves a pointer to a specified interface of CFbsDrawDevice implementation.
       
   902 @param aInterfaceId Interface identifier of the interface to be retrieved.
       
   903 @param aInterface Address of variable that retrieves the specified interface.
       
   904 @return KErrNone If the interface is supported, KErrNotSupported otherwise.
       
   905 */
       
   906 TInt CDrawThirtyTwoBppBitmapCommon::GetInterface(TInt aInterfaceId, TAny*& aInterface)
       
   907 	{
       
   908 	aInterface = NULL;
       
   909 	TInt ret = KErrNotSupported;
       
   910 	
       
   911 	if (aInterfaceId == KFastBlit2InterfaceID)
       
   912 		{
       
   913 		aInterface = static_cast<MFastBlit2*>(this);
       
   914 		ret = KErrNone;
       
   915 		}
       
   916 	else
       
   917 		return CDrawBitmap::GetInterface(aInterfaceId, aInterface);
       
   918 		
       
   919 	return ret;
       
   920 	}
       
   921 
       
   922 /**
       
   923 CDrawThirtyTwoBppBitmapCommon::WriteBitmapBlock() implementation.
       
   924 @internalTechnology
       
   925 @see MFastBlit2::WriteBitmapBlock()
       
   926 */
       
   927 TInt CDrawThirtyTwoBppBitmapCommon::WriteBitmapBlock(const TPoint& aDest,
       
   928 									CFbsDrawDevice* aSrcDrawDevice,
       
   929 									const TRect& aSrcRect)
       
   930 	{
       
   931 	__ASSERT_DEBUG(aSrcDrawDevice && ((aSrcDrawDevice->DisplayMode()==EColor16MU) || (aSrcDrawDevice->DisplayMode()==EColor16MA) ||(aSrcDrawDevice->DisplayMode()==EColor16MAP)), Panic(EScreenDriverPanicInvalidParameter));
       
   932 	
       
   933 	TAny* interface=NULL;
       
   934 	TInt ret = aSrcDrawDevice->GetInterface(KFastBlit2InterfaceID, interface);
       
   935 	if (ret != KErrNone)
       
   936 		{
       
   937 		return KErrNotSupported;
       
   938 		}
       
   939 
       
   940 	TAny* interface1=NULL;
       
   941 	ret = aSrcDrawDevice->GetInterface(KScalingSettingsInterfaceID, interface1);
       
   942 	if(ret != KErrNone || (interface1 && !reinterpret_cast<MScalingSettings*>(interface1)->IsScalingOff()))
       
   943 		{
       
   944 		return KErrNotSupported;
       
   945 		}
       
   946 
       
   947 	ret = aSrcDrawDevice->GetInterface(KOrientationInterfaceID, interface1);
       
   948 	if(ret != KErrNone || (interface1 && reinterpret_cast<MDrawDeviceOrientation*>(interface1)->Orientation() != 0))
       
   949 		{
       
   950 		return KErrNotSupported;
       
   951 		}
       
   952 
       
   953 	ret = aSrcDrawDevice->GetInterface(KDrawDeviceOriginInterfaceID, interface1);
       
   954 	if(ret != KErrNone)
       
   955 		{
       
   956 		return KErrNotSupported;
       
   957 		}
       
   958 	
       
   959 	if(interface1)
       
   960 		{
       
   961 	 	TPoint pt;
       
   962 	 	reinterpret_cast<MDrawDeviceOrigin*>(interface1)->Get(pt);
       
   963 	 	if(pt.iX != 0 || pt.iY != 0)
       
   964 	 		{
       
   965 			return KErrNotSupported;
       
   966 	 		}
       
   967 		}
       
   968 
       
   969 	const TUint32* srcBase = reinterpret_cast<MFastBlit2*>(interface)->Bits();
       
   970 	__ASSERT_DEBUG(srcBase!=NULL, Panic(EScreenDriverPanicInvalidParameter));
       
   971 	TInt srcStride = aSrcDrawDevice->ScanLineBytes();  
       
   972 	__ASSERT_DEBUG((srcStride&3)==0, Panic(EScreenDriverPanicInvalidParameter));  // stride is assumed to be a multiple of 4
       
   973 	TSize srcSize = aSrcDrawDevice->SizeInPixels();
       
   974 
       
   975 	return WriteBitmapBlock(aDest, srcBase, srcStride, srcSize, aSrcRect);
       
   976 	}
       
   977 									
       
   978 /**
       
   979 CDrawThirtyTwoBppBitmapCommon::WriteBitmapBlock() implementation.
       
   980 @internalTechnology
       
   981 @see MFastBlit2::WriteBitmapBlock()
       
   982 */													
       
   983 TInt CDrawThirtyTwoBppBitmapCommon::WriteBitmapBlock(const TPoint& aDest,
       
   984 									const TUint32* aSrcBase,
       
   985 									TInt aSrcStride,
       
   986 									const TSize& aSrcSize,
       
   987 									const TRect& aSrcRect)
       
   988 	{
       
   989 	__ASSERT_DEBUG(aSrcBase, Panic(EScreenDriverPanicInvalidParameter));
       
   990 	__ASSERT_DEBUG((aSrcStride&3)==0, Panic(EScreenDriverPanicInvalidParameter));
       
   991 	__ASSERT_DEBUG(iBits, Panic(EScreenDriverPanicInvalidPointer));
       
   992 
       
   993 	if (iShadowMode!=NULL ||
       
   994     	(iUserDispMode!=NULL && iUserDispMode!=iDispMode) ||
       
   995     	iOrientation!=EOrientationNormal ||
       
   996 		!IsScalingOff() ||
       
   997 		!iOriginIsZero)
       
   998 		{
       
   999 		return KErrNotSupported;
       
  1000 		}
       
  1001 	
       
  1002 	__ASSERT_DEBUG(aSrcRect.iTl.iX >= 0, Panic(EScreenDriverPanicOutOfBounds)); 
       
  1003 	__ASSERT_DEBUG(aSrcRect.iTl.iY >= 0, Panic(EScreenDriverPanicOutOfBounds));
       
  1004 	__ASSERT_DEBUG(aSrcRect.iBr.iX <= aSrcSize.iWidth,  Panic(EScreenDriverPanicOutOfBounds));
       
  1005 	__ASSERT_DEBUG(aSrcRect.iBr.iY <= aSrcSize.iHeight, Panic(EScreenDriverPanicOutOfBounds));
       
  1006 	__ASSERT_DEBUG(aDest.iX >= 0, Panic(EScreenDriverPanicOutOfBounds));
       
  1007 	__ASSERT_DEBUG(aDest.iY >= 0, Panic(EScreenDriverPanicOutOfBounds));
       
  1008 	__ASSERT_DEBUG((aDest.iX + aSrcRect.Width())  <= SizeInPixels().iWidth,  Panic(EScreenDriverPanicOutOfBounds));
       
  1009 	__ASSERT_DEBUG((aDest.iY + aSrcRect.Height()) <= SizeInPixels().iHeight, Panic(EScreenDriverPanicOutOfBounds));
       
  1010 	
       
  1011 	const TInt srcStrideWords=aSrcStride >> 2;
       
  1012 	const TInt dstStrideWords=iScanLineWords;
       
  1013 	
       
  1014 	if (aSrcSize.iWidth == aSrcRect.Width() &&
       
  1015 		aSrcSize.iWidth == SizeInPixels().iWidth &&
       
  1016 		srcStrideWords == dstStrideWords)
       
  1017 		{
       
  1018 		// Optimum case - one memcpy
       
  1019 		__ASSERT_DEBUG(aSrcRect.iTl.iX==0 && aDest.iX==0, Panic(EScreenDriverPanicInvalidParameter));  // this is implied by the above conditions
       
  1020 		const TUint32* srcPtr = aSrcBase + (iScanLineWords * aSrcRect.iTl.iY);
       
  1021 		TUint32* dstPtr       = iBits    + (iScanLineWords * aDest.iY);
       
  1022 		const TInt length = aSrcStride * aSrcRect.Height();
       
  1023 		Mem::Move(dstPtr, srcPtr, length);
       
  1024 		return KErrNone;
       
  1025 		}
       
  1026 		
       
  1027 	// Sub-optimal case - one memcpy per line
       
  1028 	const TUint32* srcPtr = aSrcBase + (srcStrideWords * aSrcRect.iTl.iY) + aSrcRect.iTl.iX;
       
  1029 	TUint32* dstPtr       = iBits    + (dstStrideWords * aDest.iY		) + aDest.iX;
       
  1030 	const TInt length = aSrcRect.Width() << 2;
       
  1031 	TInt lines = aSrcRect.Height();
       
  1032 	while (lines--)
       
  1033 		{
       
  1034 		Mem::Move(dstPtr, srcPtr, length);
       
  1035 		srcPtr+=srcStrideWords;
       
  1036 		dstPtr+=dstStrideWords;
       
  1037 		}
       
  1038 	return KErrNone;
       
  1039 	}
       
  1040 
       
  1041 /**
       
  1042 CDrawThirtyTwoBppBitmapCommon::Bits() implementation.
       
  1043 @internalTechnology
       
  1044 @see MFastBlit2::Bits()
       
  1045 */
       
  1046 const TUint32* CDrawThirtyTwoBppBitmapCommon::Bits() const
       
  1047 	{
       
  1048 	return iBits;
       
  1049 	}