os/graphics/windowing/windowserver/nonnga/SERVER/playbackgc.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1994-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
// GC.CPP
sl@0
    15
// GC and Graphics functions
sl@0
    16
// 
sl@0
    17
//
sl@0
    18
sl@0
    19
#include "playbackgc.h"
sl@0
    20
sl@0
    21
#include <e32std.h>
sl@0
    22
#include <s32mem.h> 
sl@0
    23
sl@0
    24
#include "backedupwindow.h"
sl@0
    25
#include "panics.h"
sl@0
    26
#include "ScrDev.H"
sl@0
    27
#include "windowgroup.h"
sl@0
    28
#include "wsfont.h"
sl@0
    29
#include "wstop.h"
sl@0
    30
#include "Graphics/WSGRAPHICDRAWER.H"
sl@0
    31
sl@0
    32
#if defined(__WINS__) && defined(_DEBUG)
sl@0
    33
#   include "offscreenbitmap.h"
sl@0
    34
#	define DEBUGOSB { CWsOffScreenBitmap * ofb = iWin->Screen()->OffScreenBitmap(); if (ofb) ofb->Update(); }
sl@0
    35
#else
sl@0
    36
#	define DEBUGOSB
sl@0
    37
#endif
sl@0
    38
sl@0
    39
CPlaybackGc * CPlaybackGc::iSelf=NULL;
sl@0
    40
sl@0
    41
GLREF_C RWsRegion* InternalizeRegionL(RReadStream& aReadStream);
sl@0
    42
sl@0
    43
/*CPlaybackGc*/
sl@0
    44
sl@0
    45
void CPlaybackGc::InitStaticsL()
sl@0
    46
	{
sl@0
    47
	iSelf=new(ELeave) CPlaybackGc();
sl@0
    48
	iSelf->ConstructL();
sl@0
    49
	}
sl@0
    50
sl@0
    51
void CPlaybackGc::DeleteStatics()
sl@0
    52
	{
sl@0
    53
	delete iSelf;
sl@0
    54
	iSelf = 0;
sl@0
    55
	}
sl@0
    56
sl@0
    57
CPlaybackGc::CPlaybackGc()
sl@0
    58
	{
sl@0
    59
	}
sl@0
    60
sl@0
    61
void CPlaybackGc::ConstructL()
sl@0
    62
	{
sl@0
    63
	iSelf->iScratchBitmap=new(ELeave) CFbsBitmap();
sl@0
    64
	iSelf->iScratchMaskBitmap=new(ELeave) CFbsBitmap();
sl@0
    65
	iGcBuf = CBufSeg::NewL(512);
sl@0
    66
	}
sl@0
    67
sl@0
    68
CPlaybackGc::~CPlaybackGc()
sl@0
    69
	{
sl@0
    70
	delete iPolyPoints;
sl@0
    71
	delete iGcBuf;
sl@0
    72
	iCurrentClippingRegion = NULL;
sl@0
    73
	delete iScratchBitmap;
sl@0
    74
	delete iScratchMaskBitmap;
sl@0
    75
	}
sl@0
    76
sl@0
    77
void CPlaybackGc::Activate(CWsClientWindow * aWin, CFbsBitGc * aGc, const TRegion * aRegion)
sl@0
    78
	{
sl@0
    79
	iWin = aWin;
sl@0
    80
	iGc = aGc;
sl@0
    81
	iTargetRegion = aRegion;
sl@0
    82
	
sl@0
    83
	iDrawRegion = iTargetRegion;
sl@0
    84
	iMasterOrigin = iWin->Origin();
sl@0
    85
	iOrigin.SetXY(0,0);
sl@0
    86
	iGc->SetBrushColor(iWin->BackColor());
sl@0
    87
	ResetClippingRect();
sl@0
    88
	}
sl@0
    89
	
sl@0
    90
void CPlaybackGc::Deactivate()
sl@0
    91
	{
sl@0
    92
	iWin = 0;
sl@0
    93
	iGc = 0;
sl@0
    94
	iTargetRegion = 0;
sl@0
    95
	iDrawRegion = 0;
sl@0
    96
	CancelUserClippingRegion();
sl@0
    97
	}
sl@0
    98
	
sl@0
    99
void CPlaybackGc::CancelUserClippingRegion()
sl@0
   100
	{
sl@0
   101
	if (iUserDefinedClippingRegion)
sl@0
   102
		{
sl@0
   103
		iUserDefinedClippingRegion->Destroy();
sl@0
   104
		iUserDefinedClippingRegion = 0;
sl@0
   105
		iDrawRegion = iTargetRegion;
sl@0
   106
		}
sl@0
   107
	}
sl@0
   108
	
sl@0
   109
void CPlaybackGc::SetClippingRect(const TRect &aRect)
sl@0
   110
	{
sl@0
   111
	iClippingRect=aRect;
sl@0
   112
	iClippingRect.Move(iOrigin);
sl@0
   113
	iClippingRectSet=ETrue;
sl@0
   114
	}
sl@0
   115
sl@0
   116
void CPlaybackGc::ResetClippingRect()
sl@0
   117
	{
sl@0
   118
	iClippingRectSet=EFalse;
sl@0
   119
	}
sl@0
   120
sl@0
   121
void CPlaybackGc::CheckPolyData(const TAny* aDataPtr, TInt aHeaderSize, TInt aNumPoints)
sl@0
   122
	{
sl@0
   123
	TInt maxDataLen;
sl@0
   124
	if (CWsClient::iCurrentCommand.iOpcode>0)
sl@0
   125
		{
sl@0
   126
		maxDataLen=CWsClient::EndOfCommandBuffer()-static_cast<const TUint8*>(aDataPtr);
sl@0
   127
		}
sl@0
   128
	else
sl@0
   129
		{
sl@0
   130
		maxDataLen=CWsClient::iCurrentCommand.iCmdLength;
sl@0
   131
		}
sl@0
   132
	const TInt dataSize=aHeaderSize+aNumPoints*sizeof(TPoint);
sl@0
   133
	if (dataSize>maxDataLen)
sl@0
   134
		GcOwnerPanic(EWservPanicBadPolyData);
sl@0
   135
	}
sl@0
   136
sl@0
   137
void CPlaybackGc::DoDrawPolygon(const TWsGcCmdDrawPolygon *aDrawPolygon)
sl@0
   138
	{
sl@0
   139
	CheckPolyData(aDrawPolygon, sizeof(TWsGcCmdDrawPolygon), aDrawPolygon->numPoints);
sl@0
   140
	iGc->DrawPolygon((TPoint *)(aDrawPolygon+1),aDrawPolygon->numPoints,aDrawPolygon->fillRule);
sl@0
   141
	}
sl@0
   142
sl@0
   143
void CPlaybackGc::StartSegmentedDrawPolygonL(const TWsGcCmdStartSegmentedDrawPolygon *aDrawPolygon)
sl@0
   144
	{
sl@0
   145
	// In case a Playback have been done before all the segment is in the RedrawStore
sl@0
   146
	// (This allocation is deleted only thanks to the EWsGcOpDrawSegmentedPolygon opcode
sl@0
   147
	//  which arrive after all the segments)
sl@0
   148
	delete iPolyPoints;
sl@0
   149
	iPolyPoints=NULL;	
sl@0
   150
sl@0
   151
	iPolyPoints=(TPoint *)User::AllocL(aDrawPolygon->totalNumPoints*sizeof(TPoint));
sl@0
   152
	iPolyPointListSize=aDrawPolygon->totalNumPoints;
sl@0
   153
	}
sl@0
   154
sl@0
   155
void CPlaybackGc::SegmentedDrawPolygonData(const TWsGcCmdSegmentedDrawPolygonData *aDrawPolygon)
sl@0
   156
	{
sl@0
   157
	if (aDrawPolygon->index<0 || (aDrawPolygon->index + aDrawPolygon->numPoints) > iPolyPointListSize)
sl@0
   158
		GcOwnerPanic(EWservPanicBadPolyData);
sl@0
   159
	Mem::Copy(iPolyPoints+aDrawPolygon->index,aDrawPolygon+1,aDrawPolygon->numPoints*sizeof(TPoint));
sl@0
   160
	}
sl@0
   161
sl@0
   162
void CPlaybackGc::EndSegmentedPolygon()
sl@0
   163
	{
sl@0
   164
	delete iPolyPoints;
sl@0
   165
	iPolyPoints=NULL;
sl@0
   166
	}
sl@0
   167
sl@0
   168
void CPlaybackGc::DoDrawPolyLine(const TWsGcCmdDrawPolyLine *aDrawPolyLine, TBool aContinued)
sl@0
   169
	{
sl@0
   170
	TInt numPoints=aDrawPolyLine->numPoints;
sl@0
   171
	CheckPolyData(aDrawPolyLine, sizeof(TWsGcCmdDrawPolyLine), numPoints);
sl@0
   172
	const TPoint *points=(TPoint *)(aDrawPolyLine+1);
sl@0
   173
	if (aContinued)
sl@0
   174
		{
sl@0
   175
		numPoints++;
sl@0
   176
		points=&aDrawPolyLine->last;
sl@0
   177
		}
sl@0
   178
	if (aDrawPolyLine->more)	// more to come so don't draw the end point
sl@0
   179
		iGc->DrawPolyLineNoEndPoint(points,numPoints);
sl@0
   180
	else
sl@0
   181
		iGc->DrawPolyLine(points,numPoints);
sl@0
   182
	}
sl@0
   183
sl@0
   184
void CPlaybackGc::GcOwnerPanic(TClientPanic aPanic)
sl@0
   185
	{
sl@0
   186
	iGc->SetClippingRegion(NULL);
sl@0
   187
	iCurrentClippingRegion = NULL;
sl@0
   188
	EndSegmentedPolygon();
sl@0
   189
	iWin->WsOwner()->PPanic(aPanic);
sl@0
   190
	}
sl@0
   191
sl@0
   192
// implementing MWsGc
sl@0
   193
sl@0
   194
MWsClient& CPlaybackGc::Client()
sl@0
   195
	{
sl@0
   196
	return *(iWin->WsOwner());
sl@0
   197
	}
sl@0
   198
sl@0
   199
MWsScreen& CPlaybackGc::Screen()
sl@0
   200
	{
sl@0
   201
	return *(iWin->Screen());
sl@0
   202
	}
sl@0
   203
sl@0
   204
TPoint CPlaybackGc::GcOrigin() const
sl@0
   205
	{
sl@0
   206
	return (iMasterOrigin + iOrigin);
sl@0
   207
	}
sl@0
   208
sl@0
   209
const TRegion& CPlaybackGc::ClippingRegion()
sl@0
   210
	{
sl@0
   211
	WS_ASSERT_ALWAYS(iCurrentClippingRegion,EWsPanicDrawCommandsInvalidState);
sl@0
   212
	return* iCurrentClippingRegion;
sl@0
   213
	}
sl@0
   214
sl@0
   215
CFbsBitGc& CPlaybackGc::BitGc()
sl@0
   216
	{
sl@0
   217
	return *iGc;
sl@0
   218
	}
sl@0
   219
	
sl@0
   220
TInt CPlaybackGc::PushBitGcSettings()
sl@0
   221
	{
sl@0
   222
	// the buf format is len+data where data is written by the GC's ExternalizeL()
sl@0
   223
	CBufBase& buf = *iGcBuf;
sl@0
   224
	const TInt start = buf.Size();
sl@0
   225
	RBufWriteStream out(buf,start);
sl@0
   226
	TRAPD(err,out.WriteInt32L(0));
sl@0
   227
	if(!err)
sl@0
   228
		{
sl@0
   229
		TRAP(err,iGc->ExternalizeL(out));
sl@0
   230
		}
sl@0
   231
	if(err) //rollback addition
sl@0
   232
		{
sl@0
   233
		buf.Delete(start,buf.Size()-start);
sl@0
   234
		}
sl@0
   235
	else //fixup len
sl@0
   236
		{
sl@0
   237
		TRAP_IGNORE(out.CommitL();) // can't see this failing
sl@0
   238
		TPckgBuf<TInt32> pckg(buf.Size()-sizeof(TInt32)-start);
sl@0
   239
		buf.Write(start,pckg);
sl@0
   240
		}
sl@0
   241
	return err;
sl@0
   242
	}
sl@0
   243
sl@0
   244
void CPlaybackGc::PopBitGcSettings()
sl@0
   245
	{
sl@0
   246
	CBufBase& buf = *iGcBuf;
sl@0
   247
	TInt ofs = 0;
sl@0
   248
	FOREVER
sl@0
   249
		{
sl@0
   250
		TInt chunk = 0;
sl@0
   251
		RBufReadStream in(buf,ofs);
sl@0
   252
		TRAPD(err,chunk = in.ReadInt32L());
sl@0
   253
		if(err)
sl@0
   254
			{
sl@0
   255
			WS_ASSERT_DEBUG(err != 0, EWsPanicWsGraphic);
sl@0
   256
			return;
sl@0
   257
			}
sl@0
   258
		if(ofs+sizeof(TInt32)+chunk >= buf.Size()) // the last chunk?
sl@0
   259
			{
sl@0
   260
			TRAP_IGNORE(iGc->InternalizeL(in));
sl@0
   261
			buf.Delete(ofs,buf.Size()-ofs);
sl@0
   262
			return;
sl@0
   263
			}
sl@0
   264
		ofs += chunk + sizeof(TInt32);
sl@0
   265
		}
sl@0
   266
	}
sl@0
   267
sl@0
   268
const TTime& CPlaybackGc::Now() const
sl@0
   269
	{
sl@0
   270
	return iWin->Screen()->Now();
sl@0
   271
	}
sl@0
   272
	
sl@0
   273
void CPlaybackGc::ScheduleAnimation(const TRect& aRect,const TTimeIntervalMicroSeconds& aFromNow)
sl@0
   274
	{
sl@0
   275
	ScheduleAnimation(aRect,aFromNow,0,0);
sl@0
   276
	}
sl@0
   277
sl@0
   278
void CPlaybackGc::ScheduleAnimation(const TRect& aRect,const TTimeIntervalMicroSeconds& aFromNow,const TTimeIntervalMicroSeconds& aFreq,const TTimeIntervalMicroSeconds& aStop)
sl@0
   279
	{
sl@0
   280
	// convert window rect to screen rect
sl@0
   281
	TRect rect(aRect);
sl@0
   282
	rect.Move(GcOrigin());
sl@0
   283
	// clip rect to window extent
sl@0
   284
	rect.Intersection(iWin->Abs());
sl@0
   285
	if (!rect.IsEmpty())
sl@0
   286
		{
sl@0
   287
		// and schedule it
sl@0
   288
		iWin->Screen()->ScheduleAnimation(rect,aFromNow,aFreq,aStop);
sl@0
   289
		}
sl@0
   290
	}
sl@0
   291
sl@0
   292
void CPlaybackGc::SetGcOrigin(const TPoint& aOrigin) 
sl@0
   293
	{ 
sl@0
   294
	iOrigin = aOrigin - iMasterOrigin; 
sl@0
   295
	} 
sl@0
   296
sl@0
   297
sl@0
   298
void CPlaybackGc::RemoteReadDataAndDrawL(const CWsGraphicDrawer* aGraphic, CWsClient* aOwner, const TWsGcCmdUnion &aData)
sl@0
   299
	{
sl@0
   300
	TPtrC8 data;
sl@0
   301
	HBufC8* dataBuf = NULL;
sl@0
   302
	const TInt len = aData.WsGraphic->iDataLen;
sl@0
   303
	
sl@0
   304
	if ((len >= KMaxTInt / 4) || (len < 0))
sl@0
   305
		{
sl@0
   306
		aOwner->PPanic(EWservPanicBuffer);	
sl@0
   307
		}	
sl@0
   308
	dataBuf = HBufC8::NewLC(len);
sl@0
   309
	TPtr8 des = dataBuf->Des();
sl@0
   310
	aOwner->RemoteRead(des, 0);
sl@0
   311
sl@0
   312
	if(des.Size() != len)
sl@0
   313
		{
sl@0
   314
		aOwner->PPanic(EWservPanicBuffer);
sl@0
   315
		}
sl@0
   316
	data.Set(des);																
sl@0
   317
	aGraphic->Draw(*this, aData.WsGraphic->iRect, data);
sl@0
   318
	CleanupStack::PopAndDestroy(dataBuf);		
sl@0
   319
	}
sl@0
   320
sl@0
   321
TPtrC CPlaybackGc::BufferTPtr(TText* aStart,TInt aLen, const TDesC8& aCmdData)
sl@0
   322
	{
sl@0
   323
	if ((reinterpret_cast<TUint8*>(aStart) < aCmdData.Ptr()
sl@0
   324
									|| reinterpret_cast<TUint8*>(aStart+aLen) > (aCmdData.Ptr() + aCmdData.Size()) ))
sl@0
   325
		{
sl@0
   326
		GcOwnerPanic(EWservPanicBufferPtr);
sl@0
   327
		}
sl@0
   328
	TPtrC gcPtr;
sl@0
   329
	gcPtr.Set(aStart,aLen);
sl@0
   330
	return(gcPtr);
sl@0
   331
	} 
sl@0
   332
sl@0
   333
void CPlaybackGc::DoDrawCommand(TWsGcOpcodes aOpcode, const TDesC8& aCmdData, const TRegion *aRegion)
sl@0
   334
	{
sl@0
   335
	TWsGcCmdUnion pData;
sl@0
   336
	pData.any=aCmdData.Ptr();
sl@0
   337
	
sl@0
   338
	if (aRegion)
sl@0
   339
		{
sl@0
   340
		WS_ASSERT_DEBUG(iWin,EWsPanicWindowNull);
sl@0
   341
		if (aRegion->Count()==0)
sl@0
   342
			return;
sl@0
   343
		iGc->SetClippingRegion(aRegion);
sl@0
   344
		WS_ASSERT_DEBUG(!iCurrentClippingRegion, EWsPanicDrawCommandsInvalidState);
sl@0
   345
		iCurrentClippingRegion = aRegion;
sl@0
   346
		}
sl@0
   347
	switch(aOpcode)
sl@0
   348
		{
sl@0
   349
		case EWsGcOpDrawWsGraphic:
sl@0
   350
		case EWsGcOpDrawWsGraphicPtr:
sl@0
   351
			{
sl@0
   352
			TRect screenRect(pData.WsGraphic->iRect);
sl@0
   353
			screenRect.Move(GcOrigin());
sl@0
   354
			if(iCurrentClippingRegion->Intersects(screenRect))
sl@0
   355
				{
sl@0
   356
				const TInt dataLen = pData.WsGraphic->iDataLen;
sl@0
   357
				TGraphicDrawerId id;
sl@0
   358
				id.iId = pData.WsGraphic->iId;
sl@0
   359
				id.iIsUid = (pData.WsGraphic->iFlags & EWsGraphicIdUid);
sl@0
   360
				CWsClient* owner = iWin->WsOwner();
sl@0
   361
				const CWsGraphicDrawer* graphic = owner->WindowServer().ResolveGraphic(id);
sl@0
   362
				if(graphic && graphic->IsSharedWith(owner->SecureId()))
sl@0
   363
					{
sl@0
   364
					if(aOpcode == EWsGcOpDrawWsGraphicPtr)
sl@0
   365
						{
sl@0
   366
						TRAPD(err, RemoteReadDataAndDrawL(graphic, owner, pData))
sl@0
   367
						if(err)
sl@0
   368
							WS_PANIC_DEBUG(EWsPanicWsGraphic);
sl@0
   369
						}
sl@0
   370
					else
sl@0
   371
						graphic->Draw(*this,pData.WsGraphic->iRect,CWsClient::BufferTPtr8((TUint8*)(pData.WsGraphic+1),dataLen));
sl@0
   372
	
sl@0
   373
					WS_ASSERT_DEBUG(!iGcBuf->Size(),EWsPanicWsGraphic);
sl@0
   374
					iGcBuf->Reset();
sl@0
   375
					}
sl@0
   376
				}
sl@0
   377
			break;
sl@0
   378
			}
sl@0
   379
		case EWsGcOpMapColorsLocal:
sl@0
   380
			iGc->MapColors(pData.MapColorsLocal->rect, pData.MapColorsLocal->colors,pData.MapColorsLocal->numPairs,pData.MapColorsLocal->mapForwards);
sl@0
   381
			break;
sl@0
   382
		case EWsGcOpDrawPolyLineLocalBufLen:
sl@0
   383
			iGc->DrawPolyLine(pData.DrawPolyLineLocalBufLen->points,pData.DrawPolyLineLocalBufLen->length);
sl@0
   384
			break;
sl@0
   385
		case EWsGcOpDrawPolyLineLocal:
sl@0
   386
			iGc->DrawPolyLine(pData.PointList);
sl@0
   387
			break;
sl@0
   388
		case EWsGcOpDrawPolygonLocalBufLen:
sl@0
   389
			iGc->DrawPolygon(pData.DrawPolygonLocalBufLen->points,pData.DrawPolygonLocalBufLen->length,pData.DrawPolygonLocalBufLen->fillRule);
sl@0
   390
			break;
sl@0
   391
		case EWsGcOpDrawPolygonLocal:
sl@0
   392
			iGc->DrawPolygon(pData.DrawPolygonLocal->pointList,pData.DrawPolygonLocal->fillRule);
sl@0
   393
			break;
sl@0
   394
		case EWsGcOpDrawBitmapLocal:
sl@0
   395
			iGc->DrawBitmap(pData.BitmapLocal->pos, pData.BitmapLocal->bitmap);
sl@0
   396
			break;
sl@0
   397
		case EWsGcOpDrawBitmap2Local:
sl@0
   398
			iGc->DrawBitmap(pData.Bitmap2Local->rect, pData.Bitmap2Local->bitmap);
sl@0
   399
			break;
sl@0
   400
		case EWsGcOpDrawBitmap3Local:
sl@0
   401
			iGc->DrawBitmap(pData.Bitmap3Local->rect, pData.Bitmap3Local->bitmap, pData.Bitmap3Local->srcRect);
sl@0
   402
			break;
sl@0
   403
		case EWsGcOpDrawBitmapMaskedLocal:
sl@0
   404
			iGc->DrawBitmapMasked(pData.iBitmapMaskedLocal->iRect, pData.iBitmapMaskedLocal->iBitmap, pData.iBitmapMaskedLocal->iSrcRect, pData.iBitmapMaskedLocal->iMaskBitmap,pData.iBitmapMaskedLocal->iInvertMask);
sl@0
   405
			break;
sl@0
   406
		case EWsGcOpAlphaBlendBitmapsLocal:
sl@0
   407
			iGc->AlphaBlendBitmaps(pData.AlphaBlendBitmapsLocal->point,pData.AlphaBlendBitmapsLocal->iBitmap,
sl@0
   408
						   			pData.AlphaBlendBitmapsLocal->source, pData.AlphaBlendBitmapsLocal->iAlpha,
sl@0
   409
									pData.AlphaBlendBitmapsLocal->alphaPoint);
sl@0
   410
sl@0
   411
			break;
sl@0
   412
		case EWsGcOpDrawText:
sl@0
   413
			iGc->DrawText(BufferTPtr((TText *)(pData.DrawText+1),pData.DrawText->length,aCmdData),pData.DrawText->pos);
sl@0
   414
			break;
sl@0
   415
		case EWsGcOpDrawBoxTextOptimised1:
sl@0
   416
			iGc->DrawText(BufferTPtr((TText *)(pData.BoxTextO1+1),pData.BoxTextO1->length,aCmdData),pData.BoxTextO1->box,
sl@0
   417
							pData.BoxTextO1->baselineOffset,CGraphicsContext::ELeft,0);
sl@0
   418
			break;
sl@0
   419
		case EWsGcOpDrawBoxTextOptimised2:
sl@0
   420
			iGc->DrawText(BufferTPtr((TText *)(pData.BoxTextO2+1),pData.BoxTextO2->length,aCmdData),pData.BoxTextO2->box,
sl@0
   421
							pData.BoxTextO2->baselineOffset,pData.BoxTextO2->horiz,pData.BoxTextO2->leftMrg);
sl@0
   422
			break;
sl@0
   423
		case EWsGcOpDrawTextPtr:
sl@0
   424
			iGc->DrawText(*pData.DrawTextPtr->text,pData.DrawTextPtr->pos);
sl@0
   425
			break;
sl@0
   426
		case EWsGcOpDrawTextPtr1:
sl@0
   427
		   	iGc->DrawText(*pData.DrawTextPtr->text);
sl@0
   428
			break;
sl@0
   429
		case EWsGcOpDrawBoxText:
sl@0
   430
			iGc->DrawText(BufferTPtr((TText *)(pData.BoxText+1),pData.BoxText->length,aCmdData),pData.BoxText->box,pData.BoxText->baselineOffset,pData.BoxText->width,pData.BoxText->horiz,pData.BoxText->leftMrg);
sl@0
   431
			break;
sl@0
   432
		case EWsGcOpDrawBoxTextPtr:
sl@0
   433
			iGc->DrawText(*pData.DrawBoxTextPtr->text,pData.DrawBoxTextPtr->box,pData.DrawBoxTextPtr->baselineOffset,pData.DrawBoxTextPtr->width,pData.DrawBoxTextPtr->horiz,pData.DrawBoxTextPtr->leftMrg);
sl@0
   434
			break;
sl@0
   435
		case EWsGcOpDrawBoxTextPtr1:
sl@0
   436
			iGc->DrawText(*pData.DrawBoxTextPtr->text,pData.DrawBoxTextPtr->box);
sl@0
   437
			break;
sl@0
   438
		case EWsGcOpDrawTextVertical:
sl@0
   439
			iGc->DrawTextVertical(BufferTPtr((TText *)(pData.DrawTextVertical+1),pData.DrawTextVertical->length,aCmdData),pData.DrawTextVertical->pos
sl@0
   440
							,pData.DrawTextVertical->up);
sl@0
   441
			break;
sl@0
   442
		case EWsGcOpDrawTextVerticalPtr:
sl@0
   443
			iGc->DrawTextVertical(*pData.DrawTextVerticalPtr->text,pData.DrawTextVerticalPtr->pos,pData.DrawTextVerticalPtr->up);
sl@0
   444
			break;
sl@0
   445
		case EWsGcOpDrawTextVerticalPtr1:
sl@0
   446
			iGc->DrawTextVertical(*pData.DrawTextVerticalPtr->text,pData.DrawTextVerticalPtr->up);
sl@0
   447
			break;
sl@0
   448
		case EWsGcOpDrawBoxTextVertical:
sl@0
   449
			iGc->DrawTextVertical(BufferTPtr((TText *)(pData.DrawBoxTextVertical+1),pData.DrawBoxTextVertical->length,aCmdData),
sl@0
   450
							pData.DrawBoxTextVertical->box,	pData.DrawBoxTextVertical->baselineOffset,
sl@0
   451
							pData.DrawBoxTextVertical->up,(CGraphicsContext::TTextAlign)pData.DrawBoxTextVertical->vert,pData.DrawBoxTextVertical->margin);
sl@0
   452
			break;
sl@0
   453
		case EWsGcOpDrawBoxTextVerticalPtr:
sl@0
   454
			iGc->DrawTextVertical(*pData.DrawBoxTextVerticalPtr->text,pData.DrawBoxTextVerticalPtr->box,pData.DrawBoxTextVerticalPtr->baselineOffset
sl@0
   455
							,pData.DrawBoxTextVerticalPtr->width,pData.DrawBoxTextVerticalPtr->up,pData.DrawBoxTextVerticalPtr->vert,pData.DrawBoxTextVerticalPtr->margin);
sl@0
   456
			break;
sl@0
   457
		case EWsGcOpDrawBoxTextVerticalPtr1:
sl@0
   458
			iGc->DrawTextVertical(*pData.DrawBoxTextVerticalPtr->text,pData.DrawBoxTextVerticalPtr->box,pData.DrawBoxTextVerticalPtr->up);
sl@0
   459
			break;
sl@0
   460
		case EWsGcOpDrawTextLocal:
sl@0
   461
			iGc->DrawText(*pData.DrawTextLocal->desc,pData.DrawTextLocal->pos);
sl@0
   462
			break;
sl@0
   463
		case EWsGcOpDrawBoxTextLocal:
sl@0
   464
			iGc->DrawText(*pData.BoxTextLocal->desc,pData.BoxTextLocal->box,pData.BoxTextLocal->baselineOffset,
sl@0
   465
							pData.BoxTextLocal->horiz,pData.BoxTextLocal->leftMrg);
sl@0
   466
			break;
sl@0
   467
		case EWsGcOpDrawLine:
sl@0
   468
			iGc->DrawLine(pData.DrawLine->pnt1,pData.DrawLine->pnt2);
sl@0
   469
			break;
sl@0
   470
		case EWsGcOpDrawTo:
sl@0
   471
			iGc->DrawLine(iLinePos,*pData.Point);
sl@0
   472
			break;
sl@0
   473
		case EWsGcOpDrawBy:
sl@0
   474
			iGc->DrawLine(iLinePos,iLinePos+(*pData.Point));
sl@0
   475
			break;
sl@0
   476
		case EWsGcOpPlot:
sl@0
   477
			iGc->Plot(*pData.Point);
sl@0
   478
			break;
sl@0
   479
		case EWsGcOpMoveTo:
sl@0
   480
		case EWsGcOpMoveBy:
sl@0
   481
			break;
sl@0
   482
		case EWsGcOpGdiBlt2Local:
sl@0
   483
			iGc->BitBlt(pData.GdiBlt2Local->pos,pData.GdiBlt2Local->bitmap);
sl@0
   484
			break;
sl@0
   485
		case EWsGcOpGdiBlt3Local:
sl@0
   486
			iGc->BitBlt(pData.GdiBlt3Local->pos,pData.GdiBlt3Local->bitmap, pData.GdiBlt3Local->rect);
sl@0
   487
			break;
sl@0
   488
		case EWsGcOpGdiBltMaskedLocal:
sl@0
   489
			iGc->BitBltMasked(pData.GdiBltMaskedLocal->pos,pData.GdiBltMaskedLocal->bitmap,
sl@0
   490
								pData.GdiBltMaskedLocal->rect,pData.GdiBltMaskedLocal->maskBitmap,
sl@0
   491
								pData.GdiBltMaskedLocal->invertMask);
sl@0
   492
			break;
sl@0
   493
		case EWsGcOpGdiWsBlt2:
sl@0
   494
		case EWsGcOpGdiWsBlt3:
sl@0
   495
		case EWsGcOpGdiWsBltMasked:
sl@0
   496
		case EWsGcOpGdiWsAlphaBlendBitmaps:
sl@0
   497
		case EWsGcOpWsDrawBitmapMasked:
sl@0
   498
			{
sl@0
   499
			// Andy - we continually duplicate bitmaps in here, and yet we already have them
sl@0
   500
			// somewhere as pointers so can't we both simplify and optimize this?
sl@0
   501
			CFbsBitmap* scratchBitmap=iScratchBitmap;
sl@0
   502
			CFbsBitmap* scratchMaskBimap=iScratchMaskBitmap;
sl@0
   503
			TInt maskHandle=0;
sl@0
   504
			TInt handle=WsBitmapHandle(aOpcode,pData, maskHandle);
sl@0
   505
			CWsClient* owner=iWin->WsOwner();
sl@0
   506
			if (owner!=NULL)
sl@0
   507
				{
sl@0
   508
				TInt wsBmpErr = KErrNone;
sl@0
   509
				DWsBitmap *bitmap=(DWsBitmap *)owner->HandleToObj(handle, WS_HANDLE_BITMAP);
sl@0
   510
				if (!bitmap)
sl@0
   511
					wsBmpErr = KErrNotFound;
sl@0
   512
				else
sl@0
   513
					scratchBitmap=bitmap->FbsBitmap();
sl@0
   514
				if (wsBmpErr == KErrNone)
sl@0
   515
					if (aOpcode==EWsGcOpGdiWsBltMasked || aOpcode==EWsGcOpGdiWsAlphaBlendBitmaps || aOpcode==EWsGcOpWsDrawBitmapMasked)
sl@0
   516
						{
sl@0
   517
						DWsBitmap *bitmap2=(DWsBitmap *)owner->HandleToObj(maskHandle, WS_HANDLE_BITMAP);
sl@0
   518
						if (!bitmap2)
sl@0
   519
							wsBmpErr = KErrNotFound;
sl@0
   520
						else
sl@0
   521
							scratchMaskBimap=bitmap2->FbsBitmap();
sl@0
   522
						}
sl@0
   523
				if (wsBmpErr == KErrNone)
sl@0
   524
					{
sl@0
   525
					switch(aOpcode)
sl@0
   526
						{
sl@0
   527
						case EWsGcOpGdiWsBlt2:
sl@0
   528
							iGc->BitBlt(pData.GdiBlt2->pos,scratchBitmap);
sl@0
   529
							break;
sl@0
   530
						case EWsGcOpGdiWsBlt3:
sl@0
   531
							iGc->BitBlt(pData.GdiBlt3->pos,scratchBitmap, pData.GdiBlt3->rect);
sl@0
   532
							break;
sl@0
   533
						case EWsGcOpGdiWsBltMasked:
sl@0
   534
							{
sl@0
   535
							iGc->BitBltMasked(pData.GdiBltMasked->destination,scratchBitmap,
sl@0
   536
											pData.GdiBltMasked->source, scratchMaskBimap,
sl@0
   537
											pData.GdiBltMasked->invertMask);
sl@0
   538
							}
sl@0
   539
							break;
sl@0
   540
						case EWsGcOpGdiWsAlphaBlendBitmaps:
sl@0
   541
							{
sl@0
   542
							iGc->AlphaBlendBitmaps(pData.AlphaBlendBitmaps->point,scratchBitmap,
sl@0
   543
											   pData.AlphaBlendBitmaps->source, scratchMaskBimap,
sl@0
   544
											   pData.AlphaBlendBitmaps->alphaPoint);
sl@0
   545
							}
sl@0
   546
							break;
sl@0
   547
						case EWsGcOpWsDrawBitmapMasked:
sl@0
   548
							{
sl@0
   549
							iGc->DrawBitmapMasked(pData.iBitmapMasked->iRect,scratchBitmap, 
sl@0
   550
												pData.iBitmapMasked->iSrcRect,scratchMaskBimap,
sl@0
   551
												pData.iBitmapMasked->iInvertMask);
sl@0
   552
							}
sl@0
   553
							break;
sl@0
   554
						}
sl@0
   555
					}
sl@0
   556
				}
sl@0
   557
			break;
sl@0
   558
			}
sl@0
   559
		case EWsGcOpGdiBlt2:
sl@0
   560
		case EWsGcOpGdiBlt3:
sl@0
   561
		case EWsGcOpGdiBltMasked:
sl@0
   562
		case EWsGcOpGdiAlphaBlendBitmaps:
sl@0
   563
		case EWsGcOpDrawBitmap:
sl@0
   564
		case EWsGcOpDrawBitmap2:
sl@0
   565
		case EWsGcOpDrawBitmap3:
sl@0
   566
		case EWsGcOpDrawBitmapMasked:
sl@0
   567
			{
sl@0
   568
			TInt maskHandle=0;
sl@0
   569
			TInt ret = iScratchBitmap->Duplicate(FbsBitmapHandle(aOpcode, pData,maskHandle));
sl@0
   570
			if (ret == KErrNone)
sl@0
   571
				{
sl@0
   572
				switch(aOpcode)
sl@0
   573
					{
sl@0
   574
					case EWsGcOpGdiBlt2:
sl@0
   575
						iGc->BitBlt(pData.GdiBlt2->pos,iScratchBitmap);
sl@0
   576
						break;
sl@0
   577
					case EWsGcOpGdiBlt3:
sl@0
   578
						iGc->BitBlt(pData.GdiBlt3->pos,iScratchBitmap, pData.GdiBlt3->rect);
sl@0
   579
						break;
sl@0
   580
					case EWsGcOpGdiBltMasked:
sl@0
   581
						{
sl@0
   582
						ret = iScratchMaskBitmap->Duplicate(pData.GdiBltMasked->maskHandle);
sl@0
   583
						if (ret == KErrNone)
sl@0
   584
							{
sl@0
   585
							iGc->BitBltMasked(pData.GdiBltMasked->destination,iScratchBitmap,
sl@0
   586
												pData.GdiBltMasked->source, iScratchMaskBitmap,
sl@0
   587
												pData.GdiBltMasked->invertMask);
sl@0
   588
							iScratchMaskBitmap->Reset();
sl@0
   589
							}
sl@0
   590
						}
sl@0
   591
						break;
sl@0
   592
					case EWsGcOpGdiAlphaBlendBitmaps:
sl@0
   593
						{
sl@0
   594
						ret = iScratchMaskBitmap->Duplicate(pData.AlphaBlendBitmaps->alphaHandle);
sl@0
   595
						if (ret == KErrNone)
sl@0
   596
							{
sl@0
   597
							iGc->AlphaBlendBitmaps(pData.AlphaBlendBitmaps->point, iScratchBitmap,
sl@0
   598
												pData.AlphaBlendBitmaps->source, iScratchMaskBitmap,
sl@0
   599
												pData.AlphaBlendBitmaps->alphaPoint);
sl@0
   600
							iScratchMaskBitmap->Reset();
sl@0
   601
							}
sl@0
   602
						break;
sl@0
   603
						}
sl@0
   604
					case EWsGcOpDrawBitmap:
sl@0
   605
						iGc->DrawBitmap(pData.Bitmap->pos, iScratchBitmap);
sl@0
   606
						break;
sl@0
   607
					case EWsGcOpDrawBitmap2:
sl@0
   608
						iGc->DrawBitmap(pData.Bitmap2->rect, iScratchBitmap);
sl@0
   609
						break;
sl@0
   610
					case EWsGcOpDrawBitmap3:
sl@0
   611
						iGc->DrawBitmap(pData.Bitmap3->rect, iScratchBitmap, pData.Bitmap3->srcRect);
sl@0
   612
						break;
sl@0
   613
					case EWsGcOpDrawBitmapMasked:
sl@0
   614
						{
sl@0
   615
						ret = iScratchMaskBitmap->Duplicate(pData.iBitmapMasked->iMaskHandle);
sl@0
   616
						if (ret == KErrNone)
sl@0
   617
							{
sl@0
   618
							iGc->DrawBitmapMasked(pData.iBitmapMasked->iRect, iScratchBitmap, 
sl@0
   619
												pData.iBitmapMasked->iSrcRect, iScratchMaskBitmap,
sl@0
   620
												pData.iBitmapMasked->iInvertMask);
sl@0
   621
							iScratchMaskBitmap->Reset();
sl@0
   622
							}
sl@0
   623
						}
sl@0
   624
						break;
sl@0
   625
					}
sl@0
   626
				iScratchBitmap->Reset();
sl@0
   627
				}
sl@0
   628
			break;
sl@0
   629
			}
sl@0
   630
		case EWsGcOpDrawSegmentedPolygon:
sl@0
   631
			iGc->DrawPolygon(iPolyPoints,iPolyPointListSize,pData.DrawSegmentedPolygon->fillRule);
sl@0
   632
			break;
sl@0
   633
		case EWsGcOpDrawPolygon:
sl@0
   634
			DoDrawPolygon(pData.Polygon);
sl@0
   635
			break;
sl@0
   636
		case EWsGcOpDrawPolyLine:
sl@0
   637
			DoDrawPolyLine(pData.PolyLine, EFalse);
sl@0
   638
			break;
sl@0
   639
		case EWsGcOpDrawPolyLineContinued:
sl@0
   640
			DoDrawPolyLine(pData.PolyLine, ETrue);
sl@0
   641
			break;
sl@0
   642
		case EWsGcOpClear:
sl@0
   643
			iGc->Clear(TRect(iWin->Size()));
sl@0
   644
			break;
sl@0
   645
		case EWsGcOpClearRect:
sl@0
   646
			iGc->Clear(*pData.Rect);
sl@0
   647
			break;
sl@0
   648
		case EWsGcOpDrawRect:
sl@0
   649
			iGc->DrawRect(*pData.Rect);
sl@0
   650
			break;
sl@0
   651
		case EWsGcOpDrawEllipse:
sl@0
   652
			iGc->DrawEllipse(*pData.Rect);
sl@0
   653
			break;
sl@0
   654
		case EWsGcOpDrawRoundRect:
sl@0
   655
			iGc->DrawRoundRect(*pData.Rect,pData.RoundRect->ellipse);
sl@0
   656
			break;
sl@0
   657
		case EWsGcOpDrawArc:
sl@0
   658
			iGc->DrawArc(*pData.Rect,pData.ArcOrPie->start,pData.ArcOrPie->end);
sl@0
   659
			break;
sl@0
   660
		case EWsGcOpDrawPie:
sl@0
   661
			iGc->DrawPie(*pData.Rect,pData.ArcOrPie->start,pData.ArcOrPie->end);
sl@0
   662
			break;
sl@0
   663
		case EWsGcOpCopyRect:
sl@0
   664
			iGc->CopyRect(pData.CopyRect->pos,*pData.Rect);
sl@0
   665
			break;
sl@0
   666
		case EWsGcOpMapColors:
sl@0
   667
			iGc->MapColors(pData.MapColors->rect,(TRgb *)(pData.MapColors+1),pData.MapColors->numPairs,pData.MapColors->mapForwards);
sl@0
   668
			break;
sl@0
   669
		default:
sl@0
   670
			TRAP_IGNORE(iWin->OwnerPanic(EWservPanicOpcode));
sl@0
   671
			break;
sl@0
   672
		}
sl@0
   673
	// DEBUGOSB // comment in for per-draw-command debug osb updates
sl@0
   674
	iGc->SetClippingRegion(NULL);
sl@0
   675
	iCurrentClippingRegion = NULL;
sl@0
   676
	}
sl@0
   677
sl@0
   678
TInt CPlaybackGc::WsBitmapHandle(TInt aOpcode, const TWsGcCmdUnion &pData, TInt& aMaskHandle) 
sl@0
   679
	{
sl@0
   680
	TInt handle=0;
sl@0
   681
	switch(aOpcode)
sl@0
   682
		{
sl@0
   683
		case EWsGcOpGdiWsBlt2:
sl@0
   684
			handle=pData.GdiBlt2->handle;
sl@0
   685
			break;
sl@0
   686
		case EWsGcOpGdiWsBlt3:
sl@0
   687
			handle=pData.GdiBlt3->handle;
sl@0
   688
			break;
sl@0
   689
		case EWsGcOpGdiWsBltMasked:
sl@0
   690
			handle=pData.GdiBltMasked->handle;
sl@0
   691
			aMaskHandle = pData.GdiBltMasked->maskHandle;
sl@0
   692
			break;
sl@0
   693
		case EWsGcOpGdiWsAlphaBlendBitmaps:
sl@0
   694
			handle=pData.AlphaBlendBitmaps->bitmapHandle;
sl@0
   695
			aMaskHandle = pData.AlphaBlendBitmaps->alphaHandle;
sl@0
   696
			break;
sl@0
   697
		case EWsGcOpWsDrawBitmapMasked:
sl@0
   698
			handle=pData.iBitmapMasked->iHandle;
sl@0
   699
			aMaskHandle=pData.iBitmapMasked->iMaskHandle;
sl@0
   700
			break;
sl@0
   701
		}
sl@0
   702
	return handle;
sl@0
   703
	}		
sl@0
   704
sl@0
   705
TInt CPlaybackGc::FbsBitmapHandle(TInt aOpcode, const TWsGcCmdUnion &pData, TInt& aMaskHandle)
sl@0
   706
	{
sl@0
   707
	TInt handle=0;
sl@0
   708
	aMaskHandle=0;
sl@0
   709
	switch(aOpcode)
sl@0
   710
		{
sl@0
   711
		case EWsGcOpGdiWsBlt2:
sl@0
   712
		case EWsGcOpGdiWsBlt3:
sl@0
   713
		case EWsGcOpGdiWsBltMasked:
sl@0
   714
		case EWsGcOpGdiWsAlphaBlendBitmaps:
sl@0
   715
			{
sl@0
   716
			TInt maskHandle = 0;
sl@0
   717
			DWsBitmap *bitmap=(DWsBitmap *)iWin->WsOwner()->HandleToObj(WsBitmapHandle(aOpcode,pData, maskHandle), WS_HANDLE_BITMAP);
sl@0
   718
			WS_ASSERT_DEBUG(bitmap, EWsPanicDrawCommandsInvalidState);
sl@0
   719
			if (bitmap)
sl@0
   720
				handle=bitmap->FbsBitmap()->Handle();
sl@0
   721
			if (aOpcode==EWsGcOpGdiWsBltMasked || aOpcode==EWsGcOpGdiWsAlphaBlendBitmaps)
sl@0
   722
				{
sl@0
   723
				DWsBitmap *bitmap2=(DWsBitmap *)iWin->WsOwner()->HandleToObj(maskHandle, WS_HANDLE_BITMAP);
sl@0
   724
				WS_ASSERT_DEBUG(bitmap2, EWsPanicDrawCommandsInvalidState);
sl@0
   725
				if (bitmap2)
sl@0
   726
					aMaskHandle=bitmap2->FbsBitmap()->Handle();
sl@0
   727
				}
sl@0
   728
			break;
sl@0
   729
			}
sl@0
   730
		case EWsGcOpGdiBlt2:
sl@0
   731
			handle=pData.GdiBlt2->handle;
sl@0
   732
			break;
sl@0
   733
		case EWsGcOpGdiBlt3:
sl@0
   734
			handle=pData.GdiBlt3->handle;
sl@0
   735
			break;
sl@0
   736
		case EWsGcOpGdiBltMasked:
sl@0
   737
			handle=pData.GdiBltMasked->handle;
sl@0
   738
			aMaskHandle=pData.GdiBltMasked->maskHandle;
sl@0
   739
			break;
sl@0
   740
		case EWsGcOpGdiAlphaBlendBitmaps:
sl@0
   741
			handle=pData.AlphaBlendBitmaps->bitmapHandle;
sl@0
   742
			aMaskHandle=pData.AlphaBlendBitmaps->alphaHandle;
sl@0
   743
			break;
sl@0
   744
		case EWsGcOpDrawBitmap:
sl@0
   745
			handle=pData.Bitmap->handle;
sl@0
   746
			break;
sl@0
   747
		case EWsGcOpDrawBitmap2:
sl@0
   748
			handle=pData.Bitmap2->handle;
sl@0
   749
			break;
sl@0
   750
		case EWsGcOpDrawBitmap3:
sl@0
   751
			handle=pData.Bitmap3->handle;
sl@0
   752
			break;
sl@0
   753
		case EWsGcOpDrawBitmapMasked:
sl@0
   754
			handle=pData.iBitmapMasked->iHandle;
sl@0
   755
			aMaskHandle=pData.iBitmapMasked->iMaskHandle;
sl@0
   756
			break;
sl@0
   757
		}
sl@0
   758
	return handle;
sl@0
   759
	}
sl@0
   760
sl@0
   761
sl@0
   762
void CPlaybackGc::UpdateJustification(TText* aText,TInt aLen, const TDesC8& aCmdData)
sl@0
   763
	{
sl@0
   764
	iGc->UpdateJustification(BufferTPtr(aText,aLen,aCmdData));
sl@0
   765
	}
sl@0
   766
sl@0
   767
void CPlaybackGc::DoDrawing(TWsGcOpcodes aOpcode, const TDesC8& aCmdData)
sl@0
   768
	{
sl@0
   769
	TWsGcCmdUnion pData;
sl@0
   770
	pData.any=aCmdData.Ptr();
sl@0
   771
	
sl@0
   772
	// Andy. We do this every time?  Shouldn't this be set up for us already by the render stage?
sl@0
   773
	// infact, aren't we breaking the render stage by doing it here?
sl@0
   774
	iGc->SetUserDisplayMode(iWin->DisplayMode());
sl@0
   775
	if (iClippingRectSet)
sl@0
   776
		{
sl@0
   777
		iGc->SetOrigin(iMasterOrigin);
sl@0
   778
		iGc->SetClippingRect(iClippingRect);
sl@0
   779
		}
sl@0
   780
	iGc->SetOrigin(iMasterOrigin + iOrigin);
sl@0
   781
	
sl@0
   782
	DoDrawCommand(aOpcode,aCmdData,iDrawRegion);
sl@0
   783
sl@0
   784
	iGc->CancelClippingRect();
sl@0
   785
	iGc->SetUserDisplayMode(ENone);
sl@0
   786
	switch(aOpcode)
sl@0
   787
		{
sl@0
   788
		case EWsGcOpDrawLine:
sl@0
   789
			iLinePos=pData.DrawLine->pnt2;
sl@0
   790
			break;
sl@0
   791
		case EWsGcOpDrawTo:
sl@0
   792
		case EWsGcOpMoveTo:
sl@0
   793
		case EWsGcOpPlot:
sl@0
   794
			iLinePos=(*pData.Point);
sl@0
   795
			break;
sl@0
   796
		case EWsGcOpDrawBy:
sl@0
   797
		case EWsGcOpMoveBy:
sl@0
   798
			iLinePos+=(*pData.Point);
sl@0
   799
			break;
sl@0
   800
		case EWsGcOpDrawSegmentedPolygon:
sl@0
   801
			EndSegmentedPolygon();
sl@0
   802
			break;
sl@0
   803
		case EWsGcOpDrawText:
sl@0
   804
			UpdateJustification((TText *)(pData.DrawText+1),pData.DrawText->length,aCmdData);
sl@0
   805
			break;
sl@0
   806
		case EWsGcOpDrawTextVertical:
sl@0
   807
			UpdateJustification((TText *)(pData.DrawTextVertical+1),pData.DrawTextVertical->length,aCmdData);
sl@0
   808
			break;
sl@0
   809
		case EWsGcOpDrawBoxText:
sl@0
   810
			UpdateJustification((TText *)(pData.BoxText+1),pData.BoxText->length,aCmdData);
sl@0
   811
			break;
sl@0
   812
		case EWsGcOpDrawBoxTextOptimised1:
sl@0
   813
			UpdateJustification((TText *)(pData.BoxTextO1+1),pData.BoxTextO1->length,aCmdData);
sl@0
   814
			break;
sl@0
   815
		case EWsGcOpDrawBoxTextOptimised2:
sl@0
   816
			UpdateJustification((TText *)(pData.BoxTextO2+1),pData.BoxTextO2->length,aCmdData);
sl@0
   817
			break;
sl@0
   818
		case EWsGcOpDrawBoxTextVertical:
sl@0
   819
			UpdateJustification((TText *)(pData.DrawBoxTextVertical+1),pData.DrawBoxTextVertical->length,aCmdData);
sl@0
   820
			break;
sl@0
   821
		case EWsGcOpDrawTextLocal:
sl@0
   822
			iGc->UpdateJustification(*pData.DrawTextLocal->desc);
sl@0
   823
			break;
sl@0
   824
		case EWsGcOpDrawBoxTextLocal:
sl@0
   825
			iGc->UpdateJustification(*pData.BoxTextLocal->desc);
sl@0
   826
			break;
sl@0
   827
		case EWsGcOpDrawTextPtr:
sl@0
   828
			iGc->UpdateJustification(*pData.DrawTextPtr->text);
sl@0
   829
			break;
sl@0
   830
		case EWsGcOpDrawTextVerticalPtr:
sl@0
   831
			iGc->UpdateJustification(*pData.DrawTextVerticalPtr->text);
sl@0
   832
			break;
sl@0
   833
		case EWsGcOpDrawBoxTextPtr:
sl@0
   834
			iGc->UpdateJustification(*pData.DrawBoxTextPtr->text);
sl@0
   835
			break;
sl@0
   836
		case EWsGcOpDrawBoxTextVerticalPtr:
sl@0
   837
			iGc->UpdateJustification(*pData.DrawBoxTextVerticalPtr->text);
sl@0
   838
			break;
sl@0
   839
		}
sl@0
   840
	}
sl@0
   841
sl@0
   842
void CPlaybackGc::CommandL(TWsGcOpcodes aOpcode, const TDesC8& aCmdData)
sl@0
   843
	{
sl@0
   844
	TWsGcCmdUnion pData;
sl@0
   845
	pData.any=aCmdData.Ptr();
sl@0
   846
	
sl@0
   847
	switch(aOpcode)
sl@0
   848
		{
sl@0
   849
	case EWsGcOpStartSegmentedDrawPolygon:
sl@0
   850
		StartSegmentedDrawPolygonL(pData.StartSegmentedDrawPolygon);
sl@0
   851
		break;
sl@0
   852
	case EWsGcOpSegmentedDrawPolygonData:
sl@0
   853
		SegmentedDrawPolygonData(pData.SegmentedDrawPolygonData);
sl@0
   854
		break;
sl@0
   855
	case EWsGcOpSetClippingRegion:
sl@0
   856
		WS_ASSERT_DEBUG(aOpcode != EWsGcOpSetClippingRegion, EWsPanicDrawCommandsInvalidState);
sl@0
   857
		break;
sl@0
   858
	case EWsGcOpSetClippingRect:
sl@0
   859
		SetClippingRect(*pData.Rect);
sl@0
   860
		break;
sl@0
   861
	case EWsGcOpCancelClippingRect:
sl@0
   862
		ResetClippingRect();
sl@0
   863
		break;
sl@0
   864
	case EWsGcOpCancelClippingRegion:
sl@0
   865
		CancelUserClippingRegion();
sl@0
   866
		break;
sl@0
   867
	case EWsGcOpSetFaded:
sl@0
   868
		iGc->SetFaded(*pData.Bool);
sl@0
   869
		break;
sl@0
   870
	case EWsGcOpSetFadeParams:
sl@0
   871
		iGc->SetFadingParameters(WservEncoding::ExtractFirst8BitValue(*pData.UInt),WservEncoding::ExtractSecond8BitValue(*pData.UInt));
sl@0
   872
		break;
sl@0
   873
	case EWsGcOpSetDrawMode:
sl@0
   874
		iGc->SetDrawMode((CGraphicsContext::TDrawMode)*pData.UInt);
sl@0
   875
		break;
sl@0
   876
	case EWsGcOpUseFont:
sl@0
   877
		if (CWsFontCache::Instance()->UseFont(iFont, *pData.UInt))
sl@0
   878
			iGc->UseFont(*pData.UInt);
sl@0
   879
		else
sl@0
   880
			iGc->UseFontNoDuplicate(iFont);
sl@0
   881
		break;
sl@0
   882
	case EWsGcOpDiscardFont:
sl@0
   883
		CWsFontCache::Instance()->ReleaseFont(iFont);
sl@0
   884
		iGc->DiscardFont();
sl@0
   885
		break;
sl@0
   886
	case EWsGcOpSetUnderlineStyle:
sl@0
   887
		iGc->SetUnderlineStyle(*pData.SetUnderlineStyle);
sl@0
   888
		break;
sl@0
   889
	case EWsGcOpSetStrikethroughStyle:
sl@0
   890
		iGc->SetStrikethroughStyle(*pData.SetStrikethroughStyle);
sl@0
   891
		break;
sl@0
   892
	case EWsGcOpUseBrushPattern:
sl@0
   893
		iGc->UseBrushPattern(*pData.handle);
sl@0
   894
		break;
sl@0
   895
	case EWsGcOpDiscardBrushPattern:
sl@0
   896
		iGc->DiscardBrushPattern();
sl@0
   897
		break;
sl@0
   898
	case EWsGcOpSetBrushColor:
sl@0
   899
		iGc->SetBrushColor(*pData.rgb);
sl@0
   900
		break;
sl@0
   901
	case EWsGcOpSetPenColor:
sl@0
   902
		iGc->SetPenColor(*pData.rgb);
sl@0
   903
		break;
sl@0
   904
	case EWsGcOpSetPenStyle:
sl@0
   905
		iGc->SetPenStyle((CGraphicsContext::TPenStyle)*pData.UInt);
sl@0
   906
		break;
sl@0
   907
	case EWsGcOpSetPenSize:
sl@0
   908
		iGc->SetPenSize(*pData.Size);
sl@0
   909
		break;
sl@0
   910
	case EWsGcOpSetBrushStyle:
sl@0
   911
		iGc->SetBrushStyle((CGraphicsContext::TBrushStyle)*pData.UInt);
sl@0
   912
		break;
sl@0
   913
	case EWsGcOpReset:
sl@0
   914
		CWsFontCache::Instance()->ReleaseFont(iFont);
sl@0
   915
		iGc->Reset();
sl@0
   916
		iOrigin.SetXY(0,0);
sl@0
   917
		ResetClippingRect();
sl@0
   918
		iGc->SetBrushColor(iWin->BackColor());
sl@0
   919
		break;
sl@0
   920
	case EWsGcOpSetBrushOrigin:
sl@0
   921
		iGc->SetBrushOrigin(*pData.Point);
sl@0
   922
		break;
sl@0
   923
	case EWsGcOpSetDitherOrigin:
sl@0
   924
		iGc->SetDitherOrigin(*pData.Point);
sl@0
   925
		break;
sl@0
   926
	case EWsGcOpSetWordJustification:
sl@0
   927
		iGc->SetWordJustification(pData.SetJustification->excessWidth, pData.SetJustification->numGaps);
sl@0
   928
		break;
sl@0
   929
	case EWsGcOpSetCharJustification:
sl@0
   930
		iGc->SetCharJustification(pData.SetJustification->excessWidth, pData.SetJustification->numGaps);
sl@0
   931
		break;
sl@0
   932
	case EWsGcOpSetOrigin:
sl@0
   933
		SetOrigin(*pData.Point);
sl@0
   934
		break;
sl@0
   935
	case EWsGcOpSetOpaque:
sl@0
   936
		// Andy - opaque drawing has not been implemented yet.
sl@0
   937
		//SetOpaque(*pData.Bool);
sl@0
   938
		break;
sl@0
   939
	case EWsGcOpSetShadowColor:
sl@0
   940
		iGc->SetShadowColor(*pData.rgb);
sl@0
   941
		break;
sl@0
   942
	default:	// Assume remaining functions will draw
sl@0
   943
		{
sl@0
   944
		DoDrawing(aOpcode,aCmdData);
sl@0
   945
		return;
sl@0
   946
		}
sl@0
   947
		}
sl@0
   948
	}
sl@0
   949
sl@0
   950
void CPlaybackGc::SetOrigin(const TPoint &aOrigin)
sl@0
   951
	{
sl@0
   952
	iOrigin=aOrigin;
sl@0
   953
	}
sl@0
   954
	
sl@0
   955
/*------------------------------------------------------------------------------
sl@0
   956
  Description: Retrieves graphics context information back from a given buffer
sl@0
   957
               from a given start position.
sl@0
   958
 -----------------------------------------------------------------------------*/
sl@0
   959
void CPlaybackGc::InternalizeL(const CBufBase& aBuffer,TInt& aStartPos)
sl@0
   960
	{
sl@0
   961
	// Open the stream used for the input from the given start position
sl@0
   962
	// in the buffer.
sl@0
   963
	RBufReadStream bufReadStream;
sl@0
   964
	bufReadStream.Open(aBuffer,aStartPos);
sl@0
   965
	CleanupClosePushL(bufReadStream);
sl@0
   966
sl@0
   967
	// Read the font/bitmap server data
sl@0
   968
	iGc->InternalizeL(bufReadStream);
sl@0
   969
sl@0
   970
	iOrigin.iX = bufReadStream.ReadInt32L();
sl@0
   971
	iOrigin.iY = bufReadStream.ReadInt32L();
sl@0
   972
sl@0
   973
	iClippingRectSet=bufReadStream.ReadInt8L();
sl@0
   974
	
sl@0
   975
	// If there is a clipping rectangle data read it.
sl@0
   976
	if (iClippingRectSet)
sl@0
   977
		bufReadStream>>iClippingRect;
sl@0
   978
	
sl@0
   979
	// Force FbsBitGc to reset its user clipping rect in case orientation has changed.
sl@0
   980
	// The user clipping rect of FbsBitGc will be set to iClippingRect later before
sl@0
   981
	// drawing the command.
sl@0
   982
	iGc->CancelClippingRect();
sl@0
   983
	
sl@0
   984
	// Read the clipping region data
sl@0
   985
	InternalizeClippingRegionL(bufReadStream);
sl@0
   986
sl@0
   987
	// Read the Alpha values for Brush and Pen colors.
sl@0
   988
	InternalizeAlphaValueL(bufReadStream);
sl@0
   989
	
sl@0
   990
	CleanupStack::PopAndDestroy(&bufReadStream);
sl@0
   991
	}
sl@0
   992
sl@0
   993
/*------------------------------------------------------------------------------
sl@0
   994
  Description: Retrieves TRgb::alpha value information back from a given buffer
sl@0
   995
               and updates the Brushcolor with the same.
sl@0
   996
 -----------------------------------------------------------------------------*/
sl@0
   997
void CPlaybackGc::InternalizeAlphaValueL(RReadStream& aReadStream)
sl@0
   998
	{
sl@0
   999
	TRgb brushColor(iGc->BrushColor());
sl@0
  1000
	brushColor.SetAlpha(aReadStream.ReadUint8L());
sl@0
  1001
	iGc->SetBrushColor(brushColor);
sl@0
  1002
	TRgb penColor(iGc->PenColor());
sl@0
  1003
	penColor.SetAlpha(aReadStream.ReadUint8L());
sl@0
  1004
	iGc->SetPenColor(penColor);
sl@0
  1005
	}
sl@0
  1006
sl@0
  1007
/*------------------------------------------------------------------------------
sl@0
  1008
  Description: Helper method to retrieve clipping region data from a given
sl@0
  1009
               read stream.
sl@0
  1010
 -----------------------------------------------------------------------------*/
sl@0
  1011
void CPlaybackGc::InternalizeClippingRegionL(RReadStream& aReadStream)
sl@0
  1012
	{
sl@0
  1013
	WS_ASSERT_DEBUG(iTargetRegion, EWsPanicDrawCommandsInvalidState);
sl@0
  1014
	// Read flag to indicate if client had defined a clipping region
sl@0
  1015
	TBool clipRegion = aReadStream.ReadInt8L();
sl@0
  1016
	CancelUserClippingRegion();
sl@0
  1017
	if (clipRegion)
sl@0
  1018
		{
sl@0
  1019
		// Note that this clipping region is in window relative coordinates when
sl@0
  1020
		// received from the client (and being stored) but is in screen relative
sl@0
  1021
		// coordinates after being retrieved from the redraw store.
sl@0
  1022
		iUserDefinedClippingRegion = InternalizeRegionL(aReadStream);
sl@0
  1023
		iUserDefinedClippingRegion->Offset(iWin->Origin());
sl@0
  1024
		iUserDefinedClippingRegion->Intersect(*iTargetRegion);
sl@0
  1025
		if (iUserDefinedClippingRegion->CheckError()) // fallback to no user clipping region
sl@0
  1026
			{
sl@0
  1027
			CancelUserClippingRegion();
sl@0
  1028
			}
sl@0
  1029
		else
sl@0
  1030
			{
sl@0
  1031
			iDrawRegion = iUserDefinedClippingRegion;
sl@0
  1032
			}
sl@0
  1033
		}
sl@0
  1034
	}
sl@0
  1035
sl@0
  1036
/**
sl@0
  1037
This pretty much replaces the whole of what was TDrawDestination
sl@0
  1038
This can only be sensibly called from outside a sequence of drawing commands,
sl@0
  1039
since it negates any user defined clipping regions.
sl@0
  1040
*/
sl@0
  1041
void CPlaybackGc::SetTargetRegion(const TRegion* aRegion)
sl@0
  1042
	{
sl@0
  1043
	iTargetRegion = aRegion;
sl@0
  1044
	iDrawRegion = iTargetRegion;
sl@0
  1045
	CancelUserClippingRegion();
sl@0
  1046
	}
sl@0
  1047
	
sl@0
  1048
void CPlaybackGc::Reset()
sl@0
  1049
	{
sl@0
  1050
	iGc->Reset();
sl@0
  1051
	}
sl@0
  1052
sl@0
  1053
TAny * CPlaybackGc::ResolveObjectInterface(TUint aId)
sl@0
  1054
	{
sl@0
  1055
	switch (aId)
sl@0
  1056
		{
sl@0
  1057
		case MWsWindow::EWsObjectInterfaceId:
sl@0
  1058
			return dynamic_cast<MWsWindow *>(iWin);
sl@0
  1059
		case MWsFader::EWsObjectInterfaceId:
sl@0
  1060
		  	return iWin->Screen()->Fader();
sl@0
  1061
		}
sl@0
  1062
	return NULL;
sl@0
  1063
	}