os/graphics/graphicsdeviceinterface/directgdiadaptation/swsrc/swdirectgdidrawresource.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include "directgdiadapter.h"
sl@0
    17
#include "swdirectgdiengine.h"
sl@0
    18
#include "swdirectgdiimagesourceimpl.h"
sl@0
    19
#include "swdirectgdidriverimpl.h"
sl@0
    20
#include <bitdrawinterfaceid.h>
sl@0
    21
#include <e32cmn.h>
sl@0
    22
#include <bitdraw.h>
sl@0
    23
#include <bmalphablend.h>
sl@0
    24
#include <graphics/directgdidrawablesource.h>
sl@0
    25
#include <pixelformats.h>
sl@0
    26
#include "pixelutil.h"
sl@0
    27
sl@0
    28
/**
sl@0
    29
Helper class to deal with the case of blending 32-bit MAP source into 16-bit target which is not 
sl@0
    30
supported by screen driver CDrawSixteenBppBitmap implementation.
sl@0
    31
sl@0
    32
@publishedPartner
sl@0
    33
@prototype
sl@0
    34
@deprecated
sl@0
    35
*/
sl@0
    36
class TDrawDeviceWrapper
sl@0
    37
	{
sl@0
    38
public:
sl@0
    39
	TDrawDeviceWrapper(CFbsDrawDevice* aDrawDevice, CGraphicsContext::TDrawMode aDrawMode);
sl@0
    40
	inline void WriteLine(TInt aX, TInt aY, TInt aLength, TUint32* aBuffer, CGraphicsContext::TDrawMode aDrawMode);
sl@0
    41
private:
sl@0
    42
	inline TUint16 ConvertTo64K(TUint32 aColor);
sl@0
    43
	inline TUint16 Blend16MapTo64K(TUint16 aDest, TUint32 aSrc);
sl@0
    44
	void BlendLine16MapTo64K(TInt aX, TInt aY, TInt aLength, TUint32* aBuffer, CGraphicsContext::TDrawMode aDrawMode);
sl@0
    45
	void OriginalWriteLine(TInt aX, TInt aY, TInt aLength, TUint32* aBuffer, CGraphicsContext::TDrawMode aDrawMode);
sl@0
    46
sl@0
    47
private:
sl@0
    48
	CFbsDrawDevice* iDrawDevice;
sl@0
    49
	TUint32* iBits;
sl@0
    50
sl@0
    51
	typedef void (TDrawDeviceWrapper::*TWriteLineFunc)(TInt,TInt,TInt,TUint32*,CGraphicsContext::TDrawMode);
sl@0
    52
	TWriteLineFunc iWriteLineFunc;
sl@0
    53
	};
sl@0
    54
sl@0
    55
TDrawDeviceWrapper::TDrawDeviceWrapper(CFbsDrawDevice* aDrawDevice, CGraphicsContext::TDrawMode aDrawMode):
sl@0
    56
	iDrawDevice(aDrawDevice)
sl@0
    57
	{
sl@0
    58
	TAny* interface = NULL;
sl@0
    59
	TInt err = iDrawDevice->GetInterface(KFastBlit2InterfaceID, interface);
sl@0
    60
	// interface is guaranted to exist for 16-bit and 32-bit draw device
sl@0
    61
	GRAPHICS_ASSERT_DEBUG(err == KErrNone, EDirectGdiPanicUnexpectedError);
sl@0
    62
sl@0
    63
	iBits = (TUint32*) reinterpret_cast<MFastBlit2*>(interface)->Bits();
sl@0
    64
	
sl@0
    65
	// setup which funtion to call here rather tha making decision inside WriteLine which is usually called within
sl@0
    66
	// a tight scanline loop
sl@0
    67
	iWriteLineFunc = iDrawDevice->DisplayMode() == EColor64K && aDrawMode == CGraphicsContext::EDrawModePEN ? 
sl@0
    68
			&TDrawDeviceWrapper::BlendLine16MapTo64K : &TDrawDeviceWrapper::OriginalWriteLine;
sl@0
    69
	}
sl@0
    70
sl@0
    71
inline void TDrawDeviceWrapper::WriteLine(TInt aX, TInt aY, TInt aLength, TUint32* aBuffer, CGraphicsContext::TDrawMode aDrawMode)
sl@0
    72
	{
sl@0
    73
	// calling member functions via pointer to member functions i.e.
sl@0
    74
	// (object.*member_fn)(arg)
sl@0
    75
	//
sl@0
    76
	(this->*iWriteLineFunc)(aX, aY, aLength, aBuffer, aDrawMode);
sl@0
    77
	}
sl@0
    78
sl@0
    79
void TDrawDeviceWrapper::OriginalWriteLine(TInt aX, TInt aY, TInt aLength, TUint32* aBuffer, CGraphicsContext::TDrawMode aDrawMode)
sl@0
    80
	{
sl@0
    81
	iDrawDevice->WriteLine(aX, aY, aLength, aBuffer, aDrawMode);
sl@0
    82
	}
sl@0
    83
sl@0
    84
void TDrawDeviceWrapper::BlendLine16MapTo64K(TInt aX, TInt aY, TInt aLength, TUint32* aBuffer, CGraphicsContext::TDrawMode)
sl@0
    85
	{
sl@0
    86
	TUint16* pixelPtr = reinterpret_cast<TUint16*>(iBits);
sl@0
    87
	pixelPtr += (aY * iDrawDevice->LongWidth()) + aX;
sl@0
    88
	const TUint32* bufferPtr = aBuffer;
sl@0
    89
	const TUint32* bufferPtrLimit = bufferPtr + aLength;
sl@0
    90
sl@0
    91
	while (bufferPtr < bufferPtrLimit)
sl@0
    92
		{
sl@0
    93
		*pixelPtr = Blend16MapTo64K(*pixelPtr, *bufferPtr);
sl@0
    94
		++bufferPtr;
sl@0
    95
		++pixelPtr;
sl@0
    96
		}
sl@0
    97
	}
sl@0
    98
sl@0
    99
inline TUint16 TDrawDeviceWrapper::ConvertTo64K(TUint32 aSrc)
sl@0
   100
	{
sl@0
   101
	TInt col = (aSrc & 0x0000f8) >> 3;
sl@0
   102
	col |= (aSrc & 0x00fc00) >> 5;
sl@0
   103
	col |= (aSrc & 0xf80000) >> 8;
sl@0
   104
	
sl@0
   105
	return col;
sl@0
   106
	}
sl@0
   107
	
sl@0
   108
inline TUint16 TDrawDeviceWrapper::Blend16MapTo64K(TUint16 aDst, TUint32 aSrc)
sl@0
   109
	{
sl@0
   110
	const TInt alpha = aSrc >> 24;
sl@0
   111
sl@0
   112
	if(alpha == 0x00)
sl@0
   113
		{
sl@0
   114
		return aDst;
sl@0
   115
		}
sl@0
   116
sl@0
   117
	if (alpha == 0xff)
sl@0
   118
		{
sl@0
   119
		return ConvertTo64K(aSrc);
sl@0
   120
		}
sl@0
   121
sl@0
   122
	// extract source components from 16MAP
sl@0
   123
	const TInt src_rb = aSrc & 0x00ff00ff;
sl@0
   124
	const TInt src_g = aSrc & 0x0000ff00;
sl@0
   125
	const TInt oneMinusAlpha = 0x0100 - alpha;
sl@0
   126
sl@0
   127
	// extract destination components from 64K format
sl@0
   128
    TInt dr = (aDst & 0xf800) >> 8;
sl@0
   129
    dr += dr >> 5;
sl@0
   130
    TInt dg = (aDst & 0x07e0) >> 3;
sl@0
   131
    dg += dg >> 6;
sl@0
   132
    TInt db = (aDst & 0x001f) << 3;
sl@0
   133
    db += db >> 5;
sl@0
   134
sl@0
   135
	// combine red and blue components into a word to combine mult in one go
sl@0
   136
	TInt dst_rb = (dr << 16) | db;
sl@0
   137
	TInt dst_g = dg << 8;
sl@0
   138
sl@0
   139
	// dst and src are in pre-multiplied format (64K can be treated both as pre or non-pre)
sl@0
   140
	// dst = src + (1-alpha) * dst
sl@0
   141
	//
sl@0
   142
	dst_rb = (src_rb + ((oneMinusAlpha * dst_rb) >> 8)) & 0x00ff00ff;
sl@0
   143
	dst_g = (src_g + ((oneMinusAlpha * dst_g) >> 8)) & 0x0000ff00;
sl@0
   144
	
sl@0
   145
	const TUint32 argb = 0xff000000 | dst_rb | dst_g;
sl@0
   146
	return ConvertTo64K(argb);
sl@0
   147
	}
sl@0
   148
sl@0
   149
//
sl@0
   150
// implements MDirectGdiEngine interfaces
sl@0
   151
//
sl@0
   152
sl@0
   153
/**
sl@0
   154
@see MDirectGdiEngine::DrawResource(const TRect&,const RDirectGdiDrawableSource&,const TDesC8&)
sl@0
   155
*/
sl@0
   156
void CSwDirectGdiEngine::DrawResource(
sl@0
   157
		const TRect& aDestRect,
sl@0
   158
		const RDirectGdiDrawableSource& aSource,
sl@0
   159
		const TDesC8& /*aParam*/)
sl@0
   160
	{
sl@0
   161
	// DirectGDI reference implementation only support pixel based resource
sl@0
   162
	// see CSwDirectGdiDriverImpl::CreateDrawableSource()
sl@0
   163
	//
sl@0
   164
	CSwDirectGdiImageSourceImpl* imgSrc = NULL;
sl@0
   165
	TSize imgSize;
sl@0
   166
	if (CheckImageSource(aSource.Handle(), imgSrc, &imgSize) != KErrNone)
sl@0
   167
		{
sl@0
   168
		return;
sl@0
   169
		}
sl@0
   170
sl@0
   171
	// drawing resource unscaled with no rotation
sl@0
   172
	//
sl@0
   173
	DrawResourceCommon(aDestRect, imgSrc, TRect(TPoint(0,0), imgSize), DirectGdi::EGraphicsRotationNone);
sl@0
   174
	}
sl@0
   175
sl@0
   176
/**
sl@0
   177
@see MDirectGdiEngine::DrawResource(const TPoint&,const RDirectGdiDrawableSource&,DirectGdi::TGraphicsRotation)
sl@0
   178
*/
sl@0
   179
void CSwDirectGdiEngine::DrawResource(const TPoint& aPos,
sl@0
   180
		const RDirectGdiDrawableSource& aSource,
sl@0
   181
		DirectGdi::TGraphicsRotation aRotation)
sl@0
   182
	{
sl@0
   183
	CSwDirectGdiImageSourceImpl* imgSrc = NULL;
sl@0
   184
	TSize imgSize;
sl@0
   185
	if (CheckImageSource(aSource.Handle(), imgSrc, &imgSize) != KErrNone)
sl@0
   186
		{
sl@0
   187
		return;
sl@0
   188
		}
sl@0
   189
sl@0
   190
	// drawing resource unscaled
sl@0
   191
	//
sl@0
   192
	// rotation will be applied before scaling, we must create destination rectangle 
sl@0
   193
	// that match the size of rotated image
sl@0
   194
sl@0
   195
	TRect destRect(aPos, imgSize);
sl@0
   196
	if (aRotation==DirectGdi::EGraphicsRotation90 || aRotation==DirectGdi::EGraphicsRotation270)
sl@0
   197
		{
sl@0
   198
		// keep the top left corner in the same position but swap width and height
sl@0
   199
		destRect.SetWidth(imgSize.iHeight);
sl@0
   200
		destRect.SetHeight(imgSize.iWidth);
sl@0
   201
		}
sl@0
   202
sl@0
   203
	DrawResourceCommon(destRect, imgSrc, TRect(TPoint(0,0), imgSize), aRotation);
sl@0
   204
	}
sl@0
   205
sl@0
   206
/**
sl@0
   207
@see MDirectGdiEngine::DrawResource(const TRect&,const RDirectGdiDrawableSource&,DirectGdi::TGraphicsRotation)
sl@0
   208
*/
sl@0
   209
void CSwDirectGdiEngine::DrawResource(const TRect& aDestRect,
sl@0
   210
		const RDirectGdiDrawableSource& aSource,
sl@0
   211
		DirectGdi::TGraphicsRotation aRotation)
sl@0
   212
	{
sl@0
   213
	// aDestRect is not empty when we reach here
sl@0
   214
	//
sl@0
   215
	CSwDirectGdiImageSourceImpl* imgSrc = NULL;
sl@0
   216
	TSize imgSize;
sl@0
   217
	if (CheckImageSource(aSource.Handle(), imgSrc, &imgSize) != KErrNone)
sl@0
   218
		{
sl@0
   219
		return;
sl@0
   220
		}
sl@0
   221
sl@0
   222
	DrawResourceCommon(aDestRect, imgSrc, TRect(TPoint(0,0), imgSize), aRotation);
sl@0
   223
	}
sl@0
   224
sl@0
   225
/**
sl@0
   226
@see MDirectGdiEngine::DrawResource(const TRect&,const RDirectGdiDrawableSource&,const TRect&,DirectGdi::TGraphicsRotation)
sl@0
   227
*/
sl@0
   228
void CSwDirectGdiEngine::DrawResource(
sl@0
   229
		const TRect& aDestRect,				
sl@0
   230
		const RDirectGdiDrawableSource& aSource, 
sl@0
   231
		const TRect& aSrcRect,
sl@0
   232
		DirectGdi::TGraphicsRotation aRotation)
sl@0
   233
	{
sl@0
   234
	// pre:
sl@0
   235
	// aDestRect and aSrcRect are not empty
sl@0
   236
	//
sl@0
   237
	CSwDirectGdiImageSourceImpl* imgSrc = NULL;
sl@0
   238
	TSize imgSize;
sl@0
   239
	if (CheckImageSource(aSource.Handle(), imgSrc, &imgSize) != KErrNone)
sl@0
   240
		{
sl@0
   241
		return;
sl@0
   242
		}
sl@0
   243
sl@0
   244
	// check source rectangle is fully contained within the image resource extent
sl@0
   245
	if (aSrcRect.iTl.iX < 0 ||
sl@0
   246
		aSrcRect.iTl.iY < 0 ||
sl@0
   247
		aSrcRect.iBr.iX > imgSize.iWidth ||
sl@0
   248
		aSrcRect.iBr.iY > imgSize.iHeight)
sl@0
   249
		{
sl@0
   250
		iDriver->SetError(KErrArgument);
sl@0
   251
		return;
sl@0
   252
		}   	
sl@0
   253
	
sl@0
   254
	DrawResourceCommon(aDestRect, imgSrc, aSrcRect, aRotation);
sl@0
   255
	}
sl@0
   256
sl@0
   257
//
sl@0
   258
// internal functions
sl@0
   259
//
sl@0
   260
/**
sl@0
   261
Checks image resource is fully constructed and registered with the driver.
sl@0
   262
sl@0
   263
@param  aHandle A valid handle to an image source.
sl@0
   264
@param  aImg On return, contains the image source.
sl@0
   265
@param  aSize If not NULL, will contain the dimensions of the image source.
sl@0
   266
@return KErrNone if successful, KErrBadHandle if aHandle is not a valid handle to an image source.
sl@0
   267
*/
sl@0
   268
TInt CSwDirectGdiEngine::CheckImageSource(TInt aHandle, CSwDirectGdiImageSourceImpl*& aImg, TSize* aSize)
sl@0
   269
	{
sl@0
   270
	// check image exist
sl@0
   271
	if (!iDriver->ValidImageSource(aHandle))
sl@0
   272
		{
sl@0
   273
		// replace KErrNotFound
sl@0
   274
		const TInt err = KErrBadHandle;
sl@0
   275
		iDriver->SetError(err);
sl@0
   276
		return err;
sl@0
   277
		}
sl@0
   278
	
sl@0
   279
	aImg = reinterpret_cast<CSwDirectGdiImageSourceImpl*>(aHandle);
sl@0
   280
sl@0
   281
	// RSgImage cannot be created with zero size, so there is no point in validating its size and
sl@0
   282
	// simply return image size if requested
sl@0
   283
	if (aSize)
sl@0
   284
		{		
sl@0
   285
		*aSize = aImg->Size();
sl@0
   286
		}
sl@0
   287
sl@0
   288
	return KErrNone;
sl@0
   289
	}
sl@0
   290
sl@0
   291
/**
sl@0
   292
Implements common DrawResource() functionality used by all DrawResource() variants.
sl@0
   293
*/
sl@0
   294
void CSwDirectGdiEngine::DrawResourceCommon(
sl@0
   295
		const TRect& aDestRect,
sl@0
   296
		const CSwDirectGdiImageSourceImpl* aImg,
sl@0
   297
		const TRect& aSrcRect,
sl@0
   298
		DirectGdi::TGraphicsRotation aRotation)
sl@0
   299
	{
sl@0
   300
	// pre:
sl@0
   301
	// aDestRect and aSrcRect are not empty
sl@0
   302
	// aSrcRect is within the image extent
sl@0
   303
	//
sl@0
   304
	// translate relative coord to target absolute coord system
sl@0
   305
	TRect destRectAbs(aDestRect);
sl@0
   306
	destRectAbs.Move(iOrigin);
sl@0
   307
sl@0
   308
	// check whether we need to blend or write
sl@0
   309
	const TBool opaqueSource = (!PixelFormatUtil::HasAlpha(aImg->PixelFormat())) && (iDrawMode == DirectGdi::EDrawModePEN);
sl@0
   310
	if (opaqueSource)
sl@0
   311
		{
sl@0
   312
		iDrawMode = DirectGdi::EDrawModeWriteAlpha;
sl@0
   313
		}
sl@0
   314
sl@0
   315
	// repeat drawing op for each rectangle in the clipping region
sl@0
   316
	const TInt numOfRects = iDefaultRegionPtr->Count();	
sl@0
   317
	for (TInt idx = 0; idx < numOfRects; ++idx)
sl@0
   318
		{
sl@0
   319
		TRect clipRectAbs = (*iDefaultRegionPtr)[idx];
sl@0
   320
		if (!clipRectAbs.Intersects(destRectAbs))
sl@0
   321
			{
sl@0
   322
			continue;
sl@0
   323
			}
sl@0
   324
sl@0
   325
		// intersect current clip rect with dest rect to get actual draw area
sl@0
   326
		clipRectAbs.Intersection(destRectAbs);
sl@0
   327
		DoDrawResource(destRectAbs, aImg, aSrcRect, aRotation, clipRectAbs);
sl@0
   328
sl@0
   329
		iDrawDevice->UpdateRegion(clipRectAbs);
sl@0
   330
		}
sl@0
   331
	
sl@0
   332
	if (opaqueSource)
sl@0
   333
		{
sl@0
   334
		iDrawMode = DirectGdi::EDrawModePEN;
sl@0
   335
		}	
sl@0
   336
	}
sl@0
   337
sl@0
   338
/**
sl@0
   339
Rotate a given rectangle 90 degree clockwise around the specified origin.
sl@0
   340
*/
sl@0
   341
void CSwDirectGdiEngine::Rotate90(TRect& aRect, const TPoint& aOrigin)
sl@0
   342
	{
sl@0
   343
	// rotated bottom-left become top-left of rotated rect
sl@0
   344
	//
sl@0
   345
	TPoint bl(aRect.iTl.iX, aRect.iBr.iY);
sl@0
   346
	const TInt w = aRect.Width();
sl@0
   347
	const TInt h = aRect.Height();
sl@0
   348
	
sl@0
   349
	const TPoint dbl = bl - aOrigin;
sl@0
   350
	bl.iX = aOrigin.iX - dbl.iY;
sl@0
   351
	bl.iY = aOrigin.iY + dbl.iX;
sl@0
   352
sl@0
   353
	aRect = TRect(bl, TSize(h,w));
sl@0
   354
	}
sl@0
   355
sl@0
   356
/**
sl@0
   357
Rotate a given rectangle 180 degree clockwise around the specified origin.
sl@0
   358
*/
sl@0
   359
void CSwDirectGdiEngine::Rotate180(TRect& aRect, const TPoint& aOrigin)
sl@0
   360
	{
sl@0
   361
	// rotated bottom-right become top-left of rotated rect
sl@0
   362
	//
sl@0
   363
	TPoint br(aRect.iBr);
sl@0
   364
	const TSize sz = aRect.Size();
sl@0
   365
sl@0
   366
	const TPoint dbr = br - aOrigin;
sl@0
   367
	br.iX = aOrigin.iX - dbr.iX;
sl@0
   368
	br.iY = aOrigin.iY - dbr.iY;
sl@0
   369
sl@0
   370
	aRect = TRect(br, sz);
sl@0
   371
	}
sl@0
   372
sl@0
   373
/**
sl@0
   374
Rotate a given rectangle 270 degree clockwise around the specified origin.
sl@0
   375
*/
sl@0
   376
void CSwDirectGdiEngine::Rotate270(TRect& aRect, const TPoint& aOrigin)
sl@0
   377
	{
sl@0
   378
	// rotated top-right become top-left of rotated rect
sl@0
   379
	//
sl@0
   380
	TPoint tr(aRect.iBr.iX, aRect.iTl.iY);
sl@0
   381
	const TInt w = aRect.Width();
sl@0
   382
	const TInt h = aRect.Height();
sl@0
   383
	
sl@0
   384
	const TPoint dtr = tr - aOrigin;
sl@0
   385
	tr.iX = aOrigin.iX + dtr.iY;
sl@0
   386
	tr.iY = aOrigin.iY - dtr.iX;
sl@0
   387
sl@0
   388
	aRect = TRect(tr, TSize(h,w));
sl@0
   389
	}
sl@0
   390
sl@0
   391
/**
sl@0
   392
Tests that the size of a given rotated rectangle match the image source extent.
sl@0
   393
*/
sl@0
   394
TBool CSwDirectGdiEngine::RotatedSizeMatch(const TRect& aDst, const TRect& aSrc, DirectGdi::TGraphicsRotation aRot)
sl@0
   395
	{
sl@0
   396
	if (aRot==DirectGdi::EGraphicsRotationNone || aRot==DirectGdi::EGraphicsRotation180)
sl@0
   397
		{
sl@0
   398
		return aDst.Size()==aSrc.Size();
sl@0
   399
		}
sl@0
   400
	else
sl@0
   401
		{
sl@0
   402
		return aDst.Width()==aSrc.Height() && aDst.Height()==aSrc.Width();
sl@0
   403
		}
sl@0
   404
	}
sl@0
   405
sl@0
   406
/**
sl@0
   407
Draws a rectangular area of resource and apply rotation and/or scaling if requested.
sl@0
   408
*/
sl@0
   409
void CSwDirectGdiEngine::DoDrawResource(
sl@0
   410
		const TRect& aDestRectAbs,
sl@0
   411
		const CSwDirectGdiImageSourceImpl* aImg,
sl@0
   412
		const TRect& aSrcRect,
sl@0
   413
		DirectGdi::TGraphicsRotation aRotation,
sl@0
   414
		const TRect& aClipRectAbs)
sl@0
   415
	{
sl@0
   416
	// pre:
sl@0
   417
	// SetClippingRegion() already check that clipping region is always contained
sl@0
   418
	// within device full extent.
sl@0
   419
sl@0
   420
	// check src rect match the size of rotated dest rect
sl@0
   421
	if (RotatedSizeMatch(aDestRectAbs, aSrcRect, aRotation))
sl@0
   422
		{
sl@0
   423
		// aClipRect is the effective drawing clipped area, it has been intersected with dest rect by the
sl@0
   424
		// calling function/DoDrawResourceCommon() and it is not empty when we reach here
sl@0
   425
sl@0
   426
		// image size has been checked at the top level DrawResource() no need to check it again
sl@0
   427
sl@0
   428
		// use aClipRect to determine how much area should be read from the image and transform
sl@0
   429
		// the effective read area into source rect depending on rotation parameter
sl@0
   430
		
sl@0
   431
		// start with aClipRect
sl@0
   432
		TRect xformSrcRect(aClipRectAbs);
sl@0
   433
		switch (aRotation)
sl@0
   434
			{
sl@0
   435
			case DirectGdi::EGraphicsRotationNone:
sl@0
   436
				// align top-left corner of dest rect with top-left corner of src rect
sl@0
   437
				xformSrcRect.Move(aSrcRect.iTl - aDestRectAbs.iTl);
sl@0
   438
				break;
sl@0
   439
			case DirectGdi::EGraphicsRotation90:
sl@0
   440
				{
sl@0
   441
				// align top-right corner of dest rect with top-left corner of src rect
sl@0
   442
				xformSrcRect.Move(aSrcRect.iTl - TPoint(aDestRectAbs.iBr.iX, aDestRectAbs.iTl.iY));
sl@0
   443
				// rotate 270 (-90) degree using top-left corner of src rect as pivot point
sl@0
   444
				Rotate270(xformSrcRect, aSrcRect.iTl);
sl@0
   445
				}
sl@0
   446
				break;
sl@0
   447
			case DirectGdi::EGraphicsRotation180:
sl@0
   448
				{
sl@0
   449
				// align bottom-right corner of dest rect with top-left corner of src rect
sl@0
   450
				xformSrcRect.Move(aSrcRect.iTl - aDestRectAbs.iBr);
sl@0
   451
				// rotate 180 (-180) degree using top-left corner of src rect as pivot point
sl@0
   452
				Rotate180(xformSrcRect, aSrcRect.iTl);
sl@0
   453
				}
sl@0
   454
				break;
sl@0
   455
			case DirectGdi::EGraphicsRotation270:
sl@0
   456
				{
sl@0
   457
				// align bottom-left corner of dest rect with top-left corner of src rect
sl@0
   458
				xformSrcRect.Move(aSrcRect.iTl - TPoint(aDestRectAbs.iTl.iX, aDestRectAbs.iBr.iY));
sl@0
   459
				// rotate 90 (-270) degree using top-left corner of src rect as pivot point
sl@0
   460
				Rotate90(xformSrcRect, aSrcRect.iTl);
sl@0
   461
				}
sl@0
   462
				break;
sl@0
   463
sl@0
   464
			// no need for extra check, aRotation has been checked at generic layer
sl@0
   465
			}
sl@0
   466
sl@0
   467
		DoBlitResource(aClipRectAbs.iTl, aImg, xformSrcRect, aRotation);
sl@0
   468
		return;
sl@0
   469
		}
sl@0
   470
sl@0
   471
	DoScaledBlitResource(aDestRectAbs, aImg, aSrcRect, aRotation, aClipRectAbs);
sl@0
   472
	}
sl@0
   473
sl@0
   474
/**
sl@0
   475
Draws a rectangular area of resource rotated with no scaling.
sl@0
   476
@panic DGDIAdapter 1009, if the pixel format of the draw device is unknown (debug only). 
sl@0
   477
*/
sl@0
   478
void CSwDirectGdiEngine::DoBlitResource(
sl@0
   479
		const TPoint& aDest,
sl@0
   480
		const CSwDirectGdiImageSourceImpl* aImg,
sl@0
   481
		const TRect& aSrcRect,
sl@0
   482
		DirectGdi::TGraphicsRotation aRotation)
sl@0
   483
	{		
sl@0
   484
	// pre:
sl@0
   485
	// aDest is the top-left of clipped destination rectangle i.e. intersection of user destination
sl@0
   486
	// rectangle with current clipping rect
sl@0
   487
	// aSrcRect is rotated clipped read area i.e. effective read area with respect to original 
sl@0
   488
	// image orientation i.e.it no longer represents user specified source rect.
sl@0
   489
sl@0
   490
	// no need to do extra check on parameters here because:
sl@0
   491
	// aDest is guaranteed to be within device drawing area
sl@0
   492
	// aSrcRect is guaranteed to be within image source area
sl@0
   493
	
sl@0
   494
	const TUidPixelFormat devFormat = PixelFormatUtil::ConvertToPixelFormat(iDrawDevice->DisplayMode());
sl@0
   495
	GRAPHICS_ASSERT_DEBUG(devFormat != EUidPixelFormatUnknown, EDirectGdiPanicInvalidDisplayMode);
sl@0
   496
sl@0
   497
	const TUidPixelFormat imgFormat = aImg->PixelFormat();
sl@0
   498
	const TUint32* imgAddr = reinterpret_cast<TUint32*>(aImg->DataBuffer());
sl@0
   499
	const TInt imgStride = aImg->Stride();
sl@0
   500
	const TSize imgSize = aImg->Size();
sl@0
   501
	const CGraphicsContext::TDrawMode drawMode = GcDrawMode(iDrawMode);
sl@0
   502
	
sl@0
   503
	const TInt width = aSrcRect.Width();
sl@0
   504
	const TInt height = aSrcRect.Height();
sl@0
   505
	// write scanline starting from top dest row
sl@0
   506
	TInt destY = aDest.iY;
sl@0
   507
	// setup pixel reader toolkit
sl@0
   508
	TPixelBufferReader reader(imgAddr, imgSize, imgStride, imgFormat);
sl@0
   509
	TDrawDeviceWrapper writer(iDrawDevice, GcDrawMode(iDrawMode));
sl@0
   510
	
sl@0
   511
	//
sl@0
   512
	// special case when rotation is none
sl@0
   513
	//
sl@0
   514
	if (aRotation == DirectGdi::EGraphicsRotationNone)
sl@0
   515
		{
sl@0
   516
		TAny* interface = NULL;
sl@0
   517
	
sl@0
   518
		// source and destination format match and using write alpha mode i.e. reduce blit to memcpy
sl@0
   519
		if (iDrawMode == DirectGdi::EDrawModeWriteAlpha && devFormat == imgFormat)
sl@0
   520
			{
sl@0
   521
			TInt err = iDrawDevice->GetInterface(KFastBlit2InterfaceID, interface);
sl@0
   522
			if (err == KErrNone)
sl@0
   523
				{
sl@0
   524
				GRAPHICS_ASSERT_DEBUG(interface, EDirectGdiPanicInvalidPointer);
sl@0
   525
				MFastBlit2* fblit = static_cast<MFastBlit2*>(interface);
sl@0
   526
				err = fblit->WriteBitmapBlock(aDest, imgAddr, imgStride, imgSize, aSrcRect);
sl@0
   527
				if (err == KErrNone)
sl@0
   528
					{
sl@0
   529
					return;
sl@0
   530
					}
sl@0
   531
				}
sl@0
   532
			}
sl@0
   533
sl@0
   534
		// fallback from MFastBlit2  when source and destination format match. 
sl@0
   535
		// Note that there was previously an optimization added here that used MFlastBlend if 
sl@0
   536
		// available, however it did not work correctly for some cases using DrawResource so has been 
sl@0
   537
		// removed from this code. (A source drawn with OpenGLES on to a target in XRGB_8888 format
sl@0
   538
		// actually had alpha in the unused channel which was being drawn by MFastBlend)
sl@0
   539
		if (devFormat == imgFormat)
sl@0
   540
			{
sl@0
   541
			for (TInt row=aSrcRect.iTl.iY; row<aSrcRect.iBr.iY; ++row,++destY)
sl@0
   542
				{
sl@0
   543
				const TPoint pos(aSrcRect.iTl.iX, row);
sl@0
   544
				const TUint32* slptr = reader.GetPixelAddr(pos);
sl@0
   545
				writer.WriteLine(aDest.iX, destY, width, const_cast<TUint32*>(slptr), drawMode);
sl@0
   546
				}
sl@0
   547
			
sl@0
   548
			return;
sl@0
   549
			}
sl@0
   550
sl@0
   551
		// there is one additional case that can be optimised by eleminating copy when:
sl@0
   552
		// rotation : none
sl@0
   553
		// scaling 	: none
sl@0
   554
		// dst		: opaque
sl@0
   555
		// src		: has alpha and premultiplied
sl@0
   556
		// mode 	: PEN
sl@0
   557
		}
sl@0
   558
sl@0
   559
	//
sl@0
   560
	// generic cases
sl@0
   561
	//
sl@0
   562
	// copying is necessary either to convert pixel format or to read back buffer in reverse order 
sl@0
   563
	// to achieve rotation
sl@0
   564
	//
sl@0
   565
	const TInt scanLineBytes = iDrawDevice->ScanLineBytes();
sl@0
   566
	TUint32* scanLineBuffer = iDrawDevice->ScanLineBuffer();
sl@0
   567
	TPtr8 scanLineDes(reinterpret_cast<TUint8*>(scanLineBuffer),scanLineBytes,scanLineBytes);
sl@0
   568
sl@0
   569
	// if destination is opaque e.g. RGB_565, XRGB_8888 and the source has alpha, it shall blend
sl@0
   570
	// (because iDrawMode is set to WritePEN)
sl@0
   571
	// we treat opaque destination as in pre-multiplied format (with alpha value 1), and read the 
sl@0
   572
	// source in pre-multiplied format too, to enable optimum blending computation i.e.
sl@0
   573
	// "src + (1-alpha) * dst"
sl@0
   574
	const TUidPixelFormat readFormat = !PixelFormatUtil::HasAlpha(devFormat) &&
sl@0
   575
							iDrawMode == DirectGdi::EDrawModePEN ?
sl@0
   576
							EUidPixelFormatARGB_8888_PRE : devFormat;
sl@0
   577
sl@0
   578
	if (aRotation == DirectGdi::EGraphicsRotationNone)
sl@0
   579
		{
sl@0
   580
		// general fallback from FastBlendBitmap
sl@0
   581
		//
sl@0
   582
		const TInt readLen = width;
sl@0
   583
		// normal read scanline, left to right
sl@0
   584
		//
sl@0
   585
		for (TInt row=aSrcRect.iTl.iY; row<aSrcRect.iBr.iY; ++row,++destY)
sl@0
   586
			{
sl@0
   587
			const TPoint pos(aSrcRect.iTl.iX, row);
sl@0
   588
			reader.GetScanLine(scanLineDes,pos, readLen, readFormat, TPixelBufferReader::EReadHorizontal);
sl@0
   589
			writer.WriteLine(aDest.iX, destY, readLen, scanLineBuffer, drawMode);
sl@0
   590
			}
sl@0
   591
		}
sl@0
   592
	else if (aRotation == DirectGdi::EGraphicsRotation90)
sl@0
   593
		{
sl@0
   594
		const TInt readLen = height;
sl@0
   595
		// read scanline vertically from bottom to up, and from the lef-most column
sl@0
   596
		//
sl@0
   597
		for (TInt col=aSrcRect.iTl.iX; col<aSrcRect.iBr.iX; ++col,++destY)
sl@0
   598
			{
sl@0
   599
			const TPoint pos(col, aSrcRect.iBr.iY-1);
sl@0
   600
			reader.GetScanLine(scanLineDes, pos, readLen, readFormat, TPixelBufferReader::EReadVerticalReverse);
sl@0
   601
			writer.WriteLine(aDest.iX, destY, readLen, scanLineBuffer, drawMode);
sl@0
   602
			}
sl@0
   603
		}
sl@0
   604
	else if (aRotation == DirectGdi::EGraphicsRotation180)
sl@0
   605
		{
sl@0
   606
		const TInt readLen = width;
sl@0
   607
		// read scanline from right to left, starting from the most bottom scanline
sl@0
   608
		//
sl@0
   609
		for (TInt row=aSrcRect.iBr.iY-1; row>=aSrcRect.iTl.iY; --row,++destY)
sl@0
   610
			{
sl@0
   611
			const TPoint pos(aSrcRect.iBr.iX-1, row);
sl@0
   612
			reader.GetScanLine(scanLineDes, pos, readLen, readFormat, TPixelBufferReader::EReadHorizontalReverse);
sl@0
   613
			writer.WriteLine(aDest.iX, destY, readLen, scanLineBuffer, drawMode);
sl@0
   614
			}
sl@0
   615
		}
sl@0
   616
	else if (aRotation == DirectGdi::EGraphicsRotation270)
sl@0
   617
		{
sl@0
   618
		const TInt readLen = height;
sl@0
   619
		// read scanline vertically top to bottom, and from the right-most column
sl@0
   620
		//
sl@0
   621
		for (TInt col=aSrcRect.iBr.iX-1; col>=aSrcRect.iTl.iX; --col,++destY)
sl@0
   622
			{
sl@0
   623
			const TPoint pos(col, aSrcRect.iTl.iY);
sl@0
   624
			reader.GetScanLine(scanLineDes, pos, readLen, readFormat, TPixelBufferReader::EReadVertical);
sl@0
   625
			writer.WriteLine(aDest.iX, destY, readLen, scanLineBuffer, drawMode);
sl@0
   626
			}
sl@0
   627
		}
sl@0
   628
	}
sl@0
   629
sl@0
   630
/**
sl@0
   631
Draws a rectangular area of resource rotated and/or scaled up/down.
sl@0
   632
@panic DGDIAdapter 1009, if the pixel format of the draw device is unknown (debug only).
sl@0
   633
*/
sl@0
   634
void CSwDirectGdiEngine::DoScaledBlitResource(
sl@0
   635
		const TRect& aDestRectAbs,
sl@0
   636
		const CSwDirectGdiImageSourceImpl* aImg,
sl@0
   637
		const TRect& aSrcRect,
sl@0
   638
		DirectGdi::TGraphicsRotation aRotation,
sl@0
   639
		const TRect& aClipRectAbs)
sl@0
   640
	{
sl@0
   641
	// pre:
sl@0
   642
	// aDestRectAbs is the user specified dest rect that has been translated to target coord system. It may
sl@0
   643
	// be larger/outside the target drawing area. We must not modify this rect as it will be used to
sl@0
   644
	// determine the scaling factor.
sl@0
   645
	// aSrcRect is the user specified src rect, it is within the image extent.
sl@0
   646
	// aClipRectAbs is the intersection of current clipping rect and aDestRectAbs and is within the
sl@0
   647
	// target drawing area.
sl@0
   648
sl@0
   649
	const TUidPixelFormat devFormat = PixelFormatUtil::ConvertToPixelFormat(iDrawDevice->DisplayMode());
sl@0
   650
	GRAPHICS_ASSERT_DEBUG(devFormat != EUidPixelFormatUnknown, EDirectGdiPanicInvalidDisplayMode);
sl@0
   651
sl@0
   652
	const TUint32* imgAddr = reinterpret_cast<TUint32*>(aImg->DataBuffer());
sl@0
   653
	const TInt imgStride = aImg->Stride();
sl@0
   654
	const TSize imgSize = aImg->Size();
sl@0
   655
	const TUidPixelFormat imgFormat = aImg->PixelFormat();
sl@0
   656
	const CGraphicsContext::TDrawMode drawMode = GcDrawMode(iDrawMode);
sl@0
   657
sl@0
   658
	// if destination is opaque e.g. RGB_565, XRGB_8888 and the source has alpha, it shall blend
sl@0
   659
	// (because iDrawMode is set to WritePEN)
sl@0
   660
	// we treat opaque destination as in pre-multiplied format (with alpha value 1), and read the 
sl@0
   661
	// source in pre-multiplied format too, to enable optimum blending computation i.e.
sl@0
   662
	// "src + (1-alpha) * dst"
sl@0
   663
	const TUidPixelFormat readFormat = !PixelFormatUtil::HasAlpha(devFormat) &&
sl@0
   664
							iDrawMode == DirectGdi::EDrawModePEN ?
sl@0
   665
							EUidPixelFormatARGB_8888_PRE : devFormat;
sl@0
   666
sl@0
   667
	TUint32* scanLineBuffer = iDrawDevice->ScanLineBuffer();
sl@0
   668
	const TInt scanLineBytes = iDrawDevice->ScanLineBytes();
sl@0
   669
	TPtr8 scanLineDes(reinterpret_cast<TUint8*>(scanLineBuffer), scanLineBytes, scanLineBytes);
sl@0
   670
sl@0
   671
	// setup pixel reader toolkit
sl@0
   672
	//
sl@0
   673
	TPixelBufferReader reader(imgAddr, imgSize, imgStride, imgFormat);
sl@0
   674
	TDrawDeviceWrapper writer(iDrawDevice, GcDrawMode(iDrawMode));
sl@0
   675
sl@0
   676
	if (aRotation == DirectGdi::EGraphicsRotationNone)
sl@0
   677
		{		
sl@0
   678
		// Note that there was previously an optimization added here that used MFlastBlend if 
sl@0
   679
		// available, however it did not work correctly for some cases using DrawResource so has been 
sl@0
   680
		// removed from this code. (A source drawn with OpenGLES on to a target in XRGB_8888 format
sl@0
   681
		// actually had alpha in the unused channel which was being drawn by MFastBlend)
sl@0
   682
		//
sl@0
   683
		const TInt srcLen = aSrcRect.Width();
sl@0
   684
		const TInt destLen = aDestRectAbs.Width();
sl@0
   685
		const TInt clipLen = aClipRectAbs.Width();
sl@0
   686
		const TInt clipPos = aClipRectAbs.iTl.iX - aDestRectAbs.iTl.iX;
sl@0
   687
sl@0
   688
		// setup DDA for scaling in Y direction based on src rect and dst rect size
sl@0
   689
		// scaling in X direction will be done by GetScaledScanLine()
sl@0
   690
		//
sl@0
   691
		// setup Y scaler and start from top-left of src/dest to bottom-right of src/dest
sl@0
   692
		
sl@0
   693
		TLinearDDA yScaler;
sl@0
   694
		yScaler.Construct(
sl@0
   695
				TPoint(aSrcRect.iTl.iY, aDestRectAbs.iTl.iY),
sl@0
   696
				TPoint(aSrcRect.iBr.iY, aDestRectAbs.iBr.iY),
sl@0
   697
				TLinearDDA::ELeft);
sl@0
   698
sl@0
   699
		// move to position of current clip rect top row as the start of dest Y
sl@0
   700
		TInt srcY;	
sl@0
   701
		yScaler.JumpToYCoord2(srcY, aClipRectAbs.iTl.iY);
sl@0
   702
sl@0
   703
		// yPos contains mapping between src Y (TPoint.iX) and dest Y (TPoint.iY)
sl@0
   704
		TPoint yPos(srcY, aClipRectAbs.iTl.iY);
sl@0
   705
sl@0
   706
		// write to target from top to bottom
sl@0
   707
		//
sl@0
   708
		while (yPos.iY < aClipRectAbs.iBr.iY)
sl@0
   709
			{
sl@0
   710
			reader.GetScaledScanLine(scanLineDes,
sl@0
   711
									TPoint(aSrcRect.iTl.iX, yPos.iX),	// src X and Y
sl@0
   712
									clipPos,							// clipped dest X
sl@0
   713
									clipLen,
sl@0
   714
									destLen,
sl@0
   715
									srcLen,
sl@0
   716
									readFormat,
sl@0
   717
									TPixelBufferReader::EReadHorizontal);
sl@0
   718
			
sl@0
   719
			// use dest Y here
sl@0
   720
			writer.WriteLine(aClipRectAbs.iTl.iX, yPos.iY, clipLen, scanLineBuffer, drawMode);
sl@0
   721
sl@0
   722
			// move scaler one position
sl@0
   723
			yScaler.NextStep(yPos);
sl@0
   724
			};
sl@0
   725
		}
sl@0
   726
	else if (aRotation == DirectGdi::EGraphicsRotation90)
sl@0
   727
		{
sl@0
   728
		// we're going to read source vertically from bottom to up, swap relevant bits and pieces
sl@0
   729
		// dst-width corresponds to src-height
sl@0
   730
		// dst-height corresponds to src-width
sl@0
   731
		//
sl@0
   732
		const TInt srcLen = aSrcRect.Height();
sl@0
   733
		const TInt destLen = aDestRectAbs.Width();
sl@0
   734
sl@0
   735
		// the following doesn't change, the amount of pixel read (vertically) will be based on
sl@0
   736
		// the drawing area witdh i.e. clip width
sl@0
   737
		//
sl@0
   738
		const TInt clipLen = aClipRectAbs.Width();
sl@0
   739
sl@0
   740
		// offset into read area doesn't change either, it will be translated into some Y position
sl@0
   741
		// from bottom row of source image
sl@0
   742
		const TInt clipPos = aClipRectAbs.iTl.iX - aDestRectAbs.iTl.iX;
sl@0
   743
sl@0
   744
		// setup DDA for scaling in src X direction based on src rect and dst rect size
sl@0
   745
		// scaling in src Y direction will be done by GetScaledScanLine(EReadVerticalReverse)
sl@0
   746
		//
sl@0
   747
		// scaler map dest Y to src X because of 90 degre rotation
sl@0
   748
		// start from  top row dest, left-most column src to bottom row dest, right-most column src
sl@0
   749
		//
sl@0
   750
		TLinearDDA xScaler;
sl@0
   751
		xScaler.Construct(
sl@0
   752
				TPoint(aSrcRect.iTl.iX, aDestRectAbs.iTl.iY),
sl@0
   753
				TPoint(aSrcRect.iBr.iX, aDestRectAbs.iBr.iY),
sl@0
   754
				TLinearDDA::ELeft);
sl@0
   755
		
sl@0
   756
		// move to position of current clip rect top row as the start of src X
sl@0
   757
		TInt srcX;	
sl@0
   758
		xScaler.JumpToYCoord2(srcX, aClipRectAbs.iTl.iY);
sl@0
   759
sl@0
   760
		// xPos contains mapping between src X (TPoint.iX) and dest Y (TPoint.iY)
sl@0
   761
		TPoint xPos(srcX, aClipRectAbs.iTl.iY);
sl@0
   762
sl@0
   763
		// write to target from top to bottom
sl@0
   764
		//
sl@0
   765
		while (xPos.iY < aClipRectAbs.iBr.iY)
sl@0
   766
			{
sl@0
   767
			// read pixel vertically from left column to right
sl@0
   768
			reader.GetScaledScanLine(scanLineDes,
sl@0
   769
									TPoint(xPos.iX, aSrcRect.iBr.iY - 1),	// src X, src Y
sl@0
   770
									clipPos,								// distance from bottom source
sl@0
   771
									clipLen,
sl@0
   772
									destLen,
sl@0
   773
									srcLen,
sl@0
   774
									readFormat,
sl@0
   775
									TPixelBufferReader::EReadVerticalReverse);
sl@0
   776
			
sl@0
   777
			// use dest Y here
sl@0
   778
			writer.WriteLine(aClipRectAbs.iTl.iX, xPos.iY, clipLen, scanLineBuffer, drawMode);
sl@0
   779
sl@0
   780
			// move scaler one position
sl@0
   781
			xScaler.NextStep(xPos);
sl@0
   782
			}
sl@0
   783
		}
sl@0
   784
	else if (aRotation == DirectGdi::EGraphicsRotation180)
sl@0
   785
		{
sl@0
   786
		const TInt srcLen = aSrcRect.Width();
sl@0
   787
		const TInt destLen = aDestRectAbs.Width();
sl@0
   788
		const TInt clipLen = aClipRectAbs.Width();
sl@0
   789
sl@0
   790
		// clipPos doesn't need to be inverted (using iBr.iX) because the yScaler below
sl@0
   791
		// will do that for us (by stepping backward)
sl@0
   792
		//
sl@0
   793
		const TInt clipPos = aClipRectAbs.iTl.iX - aDestRectAbs.iTl.iX;
sl@0
   794
sl@0
   795
		// setup DDA for scaling in Y direction based on src rect and dst rect size
sl@0
   796
		// scaling in X direction will be done by GetScaledScanLine()
sl@0
   797
		//
sl@0
   798
		// setup Y scaler and start from bottom-right of src/dest to top-left of src/dest
sl@0
   799
		// to do backward stepping (src Y inversion)
sl@0
   800
sl@0
   801
		TLinearDDA yScaler;
sl@0
   802
		yScaler.Construct(
sl@0
   803
				// we starting from 1st pixel from bottom of source image, we need to
sl@0
   804
				// step back 1 position as bottom-row coord is beyond the last pixel in the source rect
sl@0
   805
				TPoint(aSrcRect.iBr.iY - 1, aDestRectAbs.iTl.iY),
sl@0
   806
				TPoint(aSrcRect.iTl.iY - 1, aDestRectAbs.iBr.iY),
sl@0
   807
				TLinearDDA::ELeft);
sl@0
   808
sl@0
   809
		// move to position of current clip rect top row as the start of dest Y
sl@0
   810
		// which will calculate inverted src Y distance from bottom of source rectangle
sl@0
   811
		TInt invSrcY;	
sl@0
   812
		yScaler.JumpToYCoord2(invSrcY, aClipRectAbs.iTl.iY);
sl@0
   813
sl@0
   814
		// yPos contains mapping between inverted src Y (TPoint.iX) and dest Y (TPoint.iY)
sl@0
   815
		TPoint yPos(invSrcY, aClipRectAbs.iTl.iY);
sl@0
   816
sl@0
   817
		// write to target from top to bottom
sl@0
   818
		//
sl@0
   819
		while (yPos.iY < aClipRectAbs.iBr.iY)
sl@0
   820
			{
sl@0
   821
			// read scanline from righ to left i.e. use aSrcRect.iBr.iX-1 (last column)
sl@0
   822
			// as starting src X value
sl@0
   823
			reader.GetScaledScanLine(scanLineDes,
sl@0
   824
									TPoint(aSrcRect.iBr.iX - 1, yPos.iX),	// src X and inverted src Y
sl@0
   825
									clipPos,								// clipped dest X
sl@0
   826
									clipLen,
sl@0
   827
									destLen,
sl@0
   828
									srcLen,
sl@0
   829
									readFormat,
sl@0
   830
									TPixelBufferReader::EReadHorizontalReverse);
sl@0
   831
			
sl@0
   832
			// use dest Y here
sl@0
   833
			writer.WriteLine(aClipRectAbs.iTl.iX, yPos.iY, clipLen, scanLineBuffer, drawMode);
sl@0
   834
sl@0
   835
			// move scaler one position
sl@0
   836
			yScaler.NextStep(yPos);
sl@0
   837
			}
sl@0
   838
		}
sl@0
   839
	else if(aRotation == DirectGdi::EGraphicsRotation270)
sl@0
   840
		{
sl@0
   841
		// we're going to read source vertically from top to bottom, swap relevant bits and pieces
sl@0
   842
		// dst-width corresponds to src-height
sl@0
   843
		// dst-height corresponds to src-width
sl@0
   844
		const TInt srcLen = aSrcRect.Height();
sl@0
   845
		const TInt destLen = aDestRectAbs.Width();
sl@0
   846
sl@0
   847
		// the following doesn't change, the amount of pixel read (vertically) will be based on
sl@0
   848
		// the drawing area witdh i.e. clip width
sl@0
   849
		const TInt clipLen = aClipRectAbs.Width();
sl@0
   850
sl@0
   851
		// offset into read area doesn't change either, it will be translated into some Y position
sl@0
   852
		// from top row of source image
sl@0
   853
		const TInt clipPos = aClipRectAbs.iTl.iX - aDestRectAbs.iTl.iX;
sl@0
   854
sl@0
   855
		// setup DDA for scaling in src X direction based on src rect and dst rect size
sl@0
   856
		// scaling in src Y direction will be done by GetScaledScanLine(EReadVertical)
sl@0
   857
		//
sl@0
   858
		// scaler map dest Y to src X because of 270 degre rotation
sl@0
   859
		// start from top row dest, right-most column src to bottom row dest, left-most column src
sl@0
   860
sl@0
   861
		TLinearDDA xScaler;
sl@0
   862
		xScaler.Construct(
sl@0
   863
				// decrement 1 pixel to get into last pixel within source
sl@0
   864
				TPoint(aSrcRect.iBr.iX - 1, aDestRectAbs.iTl.iY),
sl@0
   865
				TPoint(aSrcRect.iTl.iX - 1, aDestRectAbs.iBr.iY),
sl@0
   866
				TLinearDDA::ELeft);
sl@0
   867
sl@0
   868
		// move to position of current clip rect top row as the start of src X
sl@0
   869
		TInt srcX;	
sl@0
   870
		xScaler.JumpToYCoord2(srcX, aClipRectAbs.iTl.iY);
sl@0
   871
		// xPos contains mapping between src X (TPoint.iX) and dest Y (TPoint.iY)
sl@0
   872
		TPoint xPos(srcX, aClipRectAbs.iTl.iY);
sl@0
   873
sl@0
   874
		// write to target from top to bottom
sl@0
   875
		//
sl@0
   876
		while (xPos.iY < aClipRectAbs.iBr.iY)
sl@0
   877
			{
sl@0
   878
			// read pixel vertically from left column to right
sl@0
   879
			reader.GetScaledScanLine(scanLineDes,
sl@0
   880
									TPoint(xPos.iX, aSrcRect.iTl.iY),		// src X, src Y
sl@0
   881
									clipPos,								// distance from bottom source
sl@0
   882
									clipLen,
sl@0
   883
									destLen,
sl@0
   884
									srcLen,
sl@0
   885
									readFormat,
sl@0
   886
									TPixelBufferReader::EReadVertical);
sl@0
   887
			
sl@0
   888
			// use dest Y here
sl@0
   889
			writer.WriteLine(aClipRectAbs.iTl.iX, xPos.iY, clipLen, scanLineBuffer, drawMode);
sl@0
   890
sl@0
   891
			// move scaler one position
sl@0
   892
			xScaler.NextStep(xPos);
sl@0
   893
			}
sl@0
   894
		}
sl@0
   895
	}