os/graphics/windowing/windowserver/nonnga/SERVER/gc.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) 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 and Graphics functions
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <e32std.h>
sl@0
    19
#include <s32mem.h> 
sl@0
    20
#include "gc.h"
sl@0
    21
#include "backedupwindow.h"
sl@0
    22
#include "windowgroup.h"
sl@0
    23
#include "ScrDev.H"
sl@0
    24
#include "wstop.h"
sl@0
    25
#include "panics.h"
sl@0
    26
#include "Graphics/WSGRAPHICDRAWER.H"
sl@0
    27
#include "wsfont.h"
sl@0
    28
sl@0
    29
CFbsBitmap *CWsGc::iScratchBitmap=NULL;
sl@0
    30
CFbsBitmap *CWsGc::iScratchMaskBitmap=NULL;
sl@0
    31
sl@0
    32
GLREF_C TInt ExternalizeRegionL(RWriteStream& aWriteStream, const RWsRegion& aRegion);
sl@0
    33
sl@0
    34
/*CWsGc*/
sl@0
    35
sl@0
    36
CWsGc* CWsGc::NewL(CWsClient *aOwner)	
sl@0
    37
	{
sl@0
    38
	CWsGc* self = new(ELeave) CWsGc(aOwner);
sl@0
    39
	CleanupStack::PushL(self);
sl@0
    40
	self->ConstructL();
sl@0
    41
	CleanupStack::Pop(self);
sl@0
    42
	return self;
sl@0
    43
	}
sl@0
    44
sl@0
    45
void CWsGc::InitStaticsL()
sl@0
    46
	{
sl@0
    47
	iScratchBitmap=new(ELeave) CFbsBitmap();
sl@0
    48
	iScratchMaskBitmap=new(ELeave) CFbsBitmap();
sl@0
    49
	}
sl@0
    50
sl@0
    51
void CWsGc::DeleteStatics()
sl@0
    52
	{
sl@0
    53
	delete iScratchBitmap;
sl@0
    54
	delete iScratchMaskBitmap;
sl@0
    55
	}
sl@0
    56
sl@0
    57
CWsGc::CWsGc(CWsClient *owner) : CWsObject(owner,WS_HANDLE_GC)
sl@0
    58
	{
sl@0
    59
	__DECLARE_NAME(_S("CWsGc"));
sl@0
    60
	}
sl@0
    61
sl@0
    62
void CWsGc::ConstructL()
sl@0
    63
	{
sl@0
    64
	NewObjL();
sl@0
    65
	iGdi=CFbsBitGc::NewL();
sl@0
    66
	}
sl@0
    67
sl@0
    68
void CWsGc::Activate(CWsClientWindow *win)
sl@0
    69
	{
sl@0
    70
	if (iWin!=NULL)
sl@0
    71
		{
sl@0
    72
		if (CWsClient::iCurrentCommand.iOpcode==0)
sl@0
    73
			{
sl@0
    74
			WS_PANIC_ALWAYS(EWsPanicDrawCommandsInvalidState);
sl@0
    75
			}
sl@0
    76
		else
sl@0
    77
			{
sl@0
    78
			OwnerPanic(EWservPanicGcActive);
sl@0
    79
			}
sl@0
    80
		}
sl@0
    81
	iWin=win;
sl@0
    82
	iGdi->ActivateNoJustAutoUpdate(iWin->Redraw()->OutputDevice());
sl@0
    83
	iWin->GcActivated(this);
sl@0
    84
	iGdi->SetBrushColor(iWin->BackColor());
sl@0
    85
	iOrigin.SetXY(0,0);
sl@0
    86
	ResetClippingRect();
sl@0
    87
	if(iWsOwner)
sl@0
    88
		{
sl@0
    89
		CWsWindowGroup *winGp = iWin->WinGroup();
sl@0
    90
		if(!winGp->Device())
sl@0
    91
			OwnerPanic(EWservPanicGroupWinScreenDeviceDeleted);		
sl@0
    92
		SetReply(winGp->Device()->ClientDevicePointer());			
sl@0
    93
		}	
sl@0
    94
	}
sl@0
    95
sl@0
    96
void CWsGc::Activate(const TInt &aHandle)
sl@0
    97
	{
sl@0
    98
	CWsClientWindow *win;
sl@0
    99
	iWsOwner->HandleToClientWindow(aHandle,&win);
sl@0
   100
	if (!win->BaseParent())
sl@0
   101
		OwnerPanic(EWservPanicParentDeleted);
sl@0
   102
	Activate(win);
sl@0
   103
	}
sl@0
   104
sl@0
   105
void CWsGc::Reactivate()
sl@0
   106
	{
sl@0
   107
	WS_ASSERT_DEBUG(iWin != NULL, EWsPanicDrawCommandsInvalidState);
sl@0
   108
	iGdi->ActivateNoJustAutoUpdate(iWin->Redraw()->OutputDevice());
sl@0
   109
	}
sl@0
   110
sl@0
   111
CWsGc::~CWsGc()
sl@0
   112
	{
sl@0
   113
	if (iWin!=NULL)
sl@0
   114
		Deactivate();
sl@0
   115
	delete iGdi;
sl@0
   116
	delete iPolyPoints;
sl@0
   117
	}
sl@0
   118
sl@0
   119
void CWsGc::Deactivate()
sl@0
   120
	{
sl@0
   121
	if (iWin)	// Protect against deactivating an already deactivated GC, this is allowed to aid clean up code.
sl@0
   122
		{
sl@0
   123
		CWsFontCache::Instance()->ReleaseFont(iFont);
sl@0
   124
		iGdi->Reset();
sl@0
   125
		iWin->GcDeactivated(this);
sl@0
   126
		CancelClippingRegion();
sl@0
   127
		iWin->Redraw()->GcDeactivate(this);
sl@0
   128
		iWin=NULL;
sl@0
   129
		}
sl@0
   130
	}
sl@0
   131
sl@0
   132
void CWsGc::Reset()
sl@0
   133
	{
sl@0
   134
	iGdi->Reset();
sl@0
   135
	}
sl@0
   136
sl@0
   137
void CWsGc::SetClippingRect(const TRect &aRect)
sl@0
   138
	{
sl@0
   139
	iClippingRect=aRect;
sl@0
   140
	iClippingRect.Move(iOrigin);
sl@0
   141
	iClippingRectSet=ETrue;
sl@0
   142
	}
sl@0
   143
sl@0
   144
void CWsGc::ResetClippingRect()
sl@0
   145
	{
sl@0
   146
	iClippingRectSet=EFalse;
sl@0
   147
	}
sl@0
   148
sl@0
   149
void CWsGc::SetClippingRegionL(TInt aRegionCount)
sl@0
   150
	{
sl@0
   151
	RWsRegion *newRegion=GetRegionFromClientL(iWsOwner, aRegionCount);
sl@0
   152
	CancelClippingRegion();
sl@0
   153
	iUserDefinedClippingRegion=newRegion;
sl@0
   154
sl@0
   155
	if (iUserDefinedClippingRegion)
sl@0
   156
		{
sl@0
   157
		iUserDefinedClippingRegion->Offset(iOrigin);
sl@0
   158
		}
sl@0
   159
	}
sl@0
   160
sl@0
   161
void CWsGc::CancelClippingRegion()
sl@0
   162
	{
sl@0
   163
	if (iUserDefinedClippingRegion)
sl@0
   164
		{
sl@0
   165
		iUserDefinedClippingRegion->Destroy();
sl@0
   166
		iUserDefinedClippingRegion=NULL;
sl@0
   167
		}
sl@0
   168
	}
sl@0
   169
sl@0
   170
void CWsGc::CheckPolyData(const TAny* aDataPtr, TInt aHeaderSize, TInt aNumPoints)
sl@0
   171
	{
sl@0
   172
	TInt maxDataLen;
sl@0
   173
	if (CWsClient::iCurrentCommand.iOpcode>0)
sl@0
   174
		{
sl@0
   175
		maxDataLen=CWsClient::EndOfCommandBuffer()-static_cast<const TUint8*>(aDataPtr);
sl@0
   176
		}
sl@0
   177
	else	// Playing back from redraw store
sl@0
   178
		{
sl@0
   179
		maxDataLen=CWsClient::iCurrentCommand.iCmdLength;
sl@0
   180
		}
sl@0
   181
	const TInt dataSize=aHeaderSize+aNumPoints*sizeof(TPoint);
sl@0
   182
	if (dataSize>maxDataLen)
sl@0
   183
		GcOwnerPanic(EWservPanicBadPolyData);
sl@0
   184
	}
sl@0
   185
sl@0
   186
void CWsGc::DoDrawPolygon(const TWsGcCmdDrawPolygon *aDrawPolygon)
sl@0
   187
	{
sl@0
   188
	CheckPolyData(aDrawPolygon,sizeof(TWsGcCmdDrawPolygon),aDrawPolygon->numPoints);
sl@0
   189
	iGdi->DrawPolygon((TPoint *)(aDrawPolygon+1),aDrawPolygon->numPoints,aDrawPolygon->fillRule);
sl@0
   190
	}
sl@0
   191
sl@0
   192
void CWsGc::StartSegmentedDrawPolygonL(const TWsGcCmdStartSegmentedDrawPolygon* aDrawPolygon)
sl@0
   193
	{
sl@0
   194
	if (iPolyPoints || !Rng(0, aDrawPolygon->totalNumPoints, KMaxTInt/2 - 1))	// Restarting without finishing old polygon or invalid size
sl@0
   195
		GcOwnerPanic(EWservPanicBadPolyData);
sl@0
   196
	iPolyPoints=(TPoint *)User::AllocL(aDrawPolygon->totalNumPoints*sizeof(TPoint));
sl@0
   197
	iPolyPointListSize=aDrawPolygon->totalNumPoints;
sl@0
   198
	}
sl@0
   199
sl@0
   200
void CWsGc::SegmentedDrawPolygonData(const TWsGcCmdSegmentedDrawPolygonData* aDrawPolygon)
sl@0
   201
	{
sl@0
   202
	if (aDrawPolygon->index<0 || (aDrawPolygon->index+aDrawPolygon->numPoints)>iPolyPointListSize)
sl@0
   203
		GcOwnerPanic(EWservPanicBadPolyData);
sl@0
   204
	Mem::Copy(iPolyPoints+aDrawPolygon->index,aDrawPolygon+1,aDrawPolygon->numPoints*sizeof(TPoint));
sl@0
   205
	}
sl@0
   206
sl@0
   207
void CWsGc::EndSegmentedPolygon()
sl@0
   208
	{
sl@0
   209
	delete iPolyPoints;
sl@0
   210
	iPolyPoints=NULL;
sl@0
   211
	iPolyPointListSize = 0;
sl@0
   212
	}
sl@0
   213
sl@0
   214
void CWsGc::DoDrawPolyLine(const TWsGcCmdDrawPolyLine *aDrawPolyLine, TBool aContinued)
sl@0
   215
	{
sl@0
   216
	TInt numPoints=aDrawPolyLine->numPoints;
sl@0
   217
	CheckPolyData(aDrawPolyLine,sizeof(TWsGcCmdDrawPolyLine),numPoints);
sl@0
   218
	const TPoint *points=(TPoint *)(aDrawPolyLine+1);
sl@0
   219
	if (aContinued)
sl@0
   220
		{
sl@0
   221
		numPoints++;
sl@0
   222
		points=&aDrawPolyLine->last;
sl@0
   223
		}
sl@0
   224
	if (aDrawPolyLine->more)	// more to come so don't draw the end point
sl@0
   225
		iGdi->DrawPolyLineNoEndPoint(points,numPoints);
sl@0
   226
	else
sl@0
   227
		iGdi->DrawPolyLine(points,numPoints);
sl@0
   228
	}
sl@0
   229
sl@0
   230
void CWsGc::GcOwnerPanic(TClientPanic aPanic)
sl@0
   231
	{
sl@0
   232
	iGdi->SetClippingRegion(NULL);
sl@0
   233
	EndSegmentedPolygon();
sl@0
   234
	iWin->WsOwner()->PPanic(aPanic);
sl@0
   235
	}
sl@0
   236
	
sl@0
   237
TPtrC CWsGc::BufferTPtr(TText* aStart,TInt aLen)
sl@0
   238
	{
sl@0
   239
	TPtrC gcPtr;
sl@0
   240
	if (!CWsClient::BufferTPtrGc(aStart,aLen,gcPtr))
sl@0
   241
		GcOwnerPanic(EWservPanicBufferPtr);
sl@0
   242
	return(gcPtr);
sl@0
   243
	}
sl@0
   244
sl@0
   245
void CWsGc::DoDrawCommand(TWsGcOpcodes aOpcode, const TWsGcCmdUnion &pData, const TRegion *aRegion)
sl@0
   246
	{
sl@0
   247
	if (aRegion)
sl@0
   248
		{
sl@0
   249
		WS_ASSERT_DEBUG(iWin,EWsPanicWindowNull);
sl@0
   250
		if (aRegion->Count()==0)
sl@0
   251
			return;
sl@0
   252
		if (aRegion->IsContainedBy(TRect(TPoint(0,0), iGdi->Device()->SizeInPixels())))
sl@0
   253
			{
sl@0
   254
			iGdi->SetClippingRegion(aRegion);
sl@0
   255
			}
sl@0
   256
		}
sl@0
   257
	switch(aOpcode)
sl@0
   258
		{
sl@0
   259
		case EWsGcOpDrawWsGraphic:
sl@0
   260
		case EWsGcOpDrawWsGraphicPtr:
sl@0
   261
			{
sl@0
   262
			// CWsGc doesn't support CRPs.  CPlaybackGc does.  This means backedup windows
sl@0
   263
			// don't get to play with them yet.
sl@0
   264
			break;
sl@0
   265
			}
sl@0
   266
		case EWsGcOpMapColorsLocal:
sl@0
   267
			iGdi->MapColors(pData.MapColorsLocal->rect, pData.MapColorsLocal->colors,pData.MapColorsLocal->numPairs,pData.MapColorsLocal->mapForwards);
sl@0
   268
			break;
sl@0
   269
		case EWsGcOpDrawPolyLineLocalBufLen:
sl@0
   270
			iGdi->DrawPolyLine(pData.DrawPolyLineLocalBufLen->points,pData.DrawPolyLineLocalBufLen->length);
sl@0
   271
			break;
sl@0
   272
		case EWsGcOpDrawPolyLineLocal:
sl@0
   273
			iGdi->DrawPolyLine(pData.PointList);
sl@0
   274
			break;
sl@0
   275
		case EWsGcOpDrawPolygonLocalBufLen:
sl@0
   276
			iGdi->DrawPolygon(pData.DrawPolygonLocalBufLen->points,pData.DrawPolygonLocalBufLen->length,pData.DrawPolygonLocalBufLen->fillRule);
sl@0
   277
			break;
sl@0
   278
		case EWsGcOpDrawPolygonLocal:
sl@0
   279
			iGdi->DrawPolygon(pData.DrawPolygonLocal->pointList,pData.DrawPolygonLocal->fillRule);
sl@0
   280
			break;
sl@0
   281
		case EWsGcOpDrawBitmapLocal:
sl@0
   282
			iGdi->DrawBitmap(pData.BitmapLocal->pos, pData.BitmapLocal->bitmap);
sl@0
   283
			break;
sl@0
   284
		case EWsGcOpDrawBitmap2Local:
sl@0
   285
			iGdi->DrawBitmap(pData.Bitmap2Local->rect, pData.Bitmap2Local->bitmap);
sl@0
   286
			break;
sl@0
   287
		case EWsGcOpDrawBitmap3Local:
sl@0
   288
			iGdi->DrawBitmap(pData.Bitmap3Local->rect, pData.Bitmap3Local->bitmap, pData.Bitmap3Local->srcRect);
sl@0
   289
			break;
sl@0
   290
		case EWsGcOpDrawBitmapMaskedLocal:
sl@0
   291
			iGdi->DrawBitmapMasked(pData.iBitmapMaskedLocal->iRect, pData.iBitmapMaskedLocal->iBitmap, pData.iBitmapMaskedLocal->iSrcRect, pData.iBitmapMaskedLocal->iMaskBitmap,pData.iBitmapMaskedLocal->iInvertMask);
sl@0
   292
			break;
sl@0
   293
		case EWsGcOpAlphaBlendBitmapsLocal:
sl@0
   294
			iGdi->AlphaBlendBitmaps(pData.AlphaBlendBitmapsLocal->point,pData.AlphaBlendBitmapsLocal->iBitmap,
sl@0
   295
						   			pData.AlphaBlendBitmapsLocal->source, pData.AlphaBlendBitmapsLocal->iAlpha,
sl@0
   296
									pData.AlphaBlendBitmapsLocal->alphaPoint);
sl@0
   297
sl@0
   298
			break;
sl@0
   299
		case EWsGcOpDrawText:
sl@0
   300
			iGdi->DrawText(BufferTPtr((TText *)(pData.DrawText+1),pData.DrawText->length),pData.DrawText->pos);
sl@0
   301
			break;
sl@0
   302
		case EWsGcOpDrawBoxTextOptimised1:
sl@0
   303
			iGdi->DrawText(BufferTPtr((TText *)(pData.BoxTextO1+1),pData.BoxTextO1->length),pData.BoxTextO1->box,
sl@0
   304
							pData.BoxTextO1->baselineOffset,CGraphicsContext::ELeft,0);
sl@0
   305
			break;
sl@0
   306
		case EWsGcOpDrawBoxTextOptimised2:
sl@0
   307
			iGdi->DrawText(BufferTPtr((TText *)(pData.BoxTextO2+1),pData.BoxTextO2->length),pData.BoxTextO2->box,
sl@0
   308
							pData.BoxTextO2->baselineOffset,pData.BoxTextO2->horiz,pData.BoxTextO2->leftMrg);
sl@0
   309
			break;
sl@0
   310
		case EWsGcOpDrawTextPtr:
sl@0
   311
			iGdi->DrawText(*pData.DrawTextPtr->text,pData.DrawTextPtr->pos);
sl@0
   312
			break;
sl@0
   313
		case EWsGcOpDrawTextPtr1:
sl@0
   314
		   	iGdi->DrawText(*pData.DrawTextPtr->text);
sl@0
   315
			break;
sl@0
   316
		case EWsGcOpDrawBoxText:
sl@0
   317
			iGdi->DrawText(BufferTPtr((TText *)(pData.BoxText+1),pData.BoxText->length),pData.BoxText->box,pData.BoxText->baselineOffset,pData.BoxText->width,pData.BoxText->horiz,pData.BoxText->leftMrg);
sl@0
   318
			break;
sl@0
   319
		case EWsGcOpDrawBoxTextPtr:
sl@0
   320
			iGdi->DrawText(*pData.DrawBoxTextPtr->text,pData.DrawBoxTextPtr->box,pData.DrawBoxTextPtr->baselineOffset,pData.DrawBoxTextPtr->width,pData.DrawBoxTextPtr->horiz,pData.DrawBoxTextPtr->leftMrg);
sl@0
   321
			break;
sl@0
   322
		case EWsGcOpDrawBoxTextPtr1:
sl@0
   323
			iGdi->DrawText(*pData.DrawBoxTextPtr->text,pData.DrawBoxTextPtr->box);
sl@0
   324
			break;
sl@0
   325
		case EWsGcOpDrawTextVertical:
sl@0
   326
			iGdi->DrawTextVertical(BufferTPtr((TText *)(pData.DrawTextVertical+1),pData.DrawTextVertical->length),pData.DrawTextVertical->pos
sl@0
   327
							,pData.DrawTextVertical->up);
sl@0
   328
			break;
sl@0
   329
		case EWsGcOpDrawTextVerticalPtr:
sl@0
   330
			iGdi->DrawTextVertical(*pData.DrawTextVerticalPtr->text,pData.DrawTextVerticalPtr->pos,pData.DrawTextVerticalPtr->up);
sl@0
   331
			break;
sl@0
   332
		case EWsGcOpDrawTextVerticalPtr1:
sl@0
   333
			iGdi->DrawTextVertical(*pData.DrawTextVerticalPtr->text,pData.DrawTextVerticalPtr->up);
sl@0
   334
			break;
sl@0
   335
		case EWsGcOpDrawBoxTextVertical:
sl@0
   336
			iGdi->DrawTextVertical(BufferTPtr((TText *)(pData.DrawBoxTextVertical+1),pData.DrawBoxTextVertical->length),
sl@0
   337
							pData.DrawBoxTextVertical->box,	pData.DrawBoxTextVertical->baselineOffset,
sl@0
   338
							pData.DrawBoxTextVertical->up,(CGraphicsContext::TTextAlign)pData.DrawBoxTextVertical->vert,pData.DrawBoxTextVertical->margin);
sl@0
   339
			break;
sl@0
   340
		case EWsGcOpDrawBoxTextVerticalPtr:
sl@0
   341
			iGdi->DrawTextVertical(*pData.DrawBoxTextVerticalPtr->text,pData.DrawBoxTextVerticalPtr->box,pData.DrawBoxTextVerticalPtr->baselineOffset
sl@0
   342
							,pData.DrawBoxTextVerticalPtr->width,pData.DrawBoxTextVerticalPtr->up,pData.DrawBoxTextVerticalPtr->vert,pData.DrawBoxTextVerticalPtr->margin);
sl@0
   343
			break;
sl@0
   344
		case EWsGcOpDrawBoxTextVerticalPtr1:
sl@0
   345
			iGdi->DrawTextVertical(*pData.DrawBoxTextVerticalPtr->text,pData.DrawBoxTextVerticalPtr->box,pData.DrawBoxTextVerticalPtr->up);
sl@0
   346
			break;
sl@0
   347
		case EWsGcOpDrawTextLocal:
sl@0
   348
			iGdi->DrawText(*pData.DrawTextLocal->desc,pData.DrawTextLocal->pos);
sl@0
   349
			break;
sl@0
   350
		case EWsGcOpDrawBoxTextLocal:
sl@0
   351
			iGdi->DrawText(*pData.BoxTextLocal->desc,pData.BoxTextLocal->box,pData.BoxTextLocal->baselineOffset,
sl@0
   352
							pData.BoxTextLocal->horiz,pData.BoxTextLocal->leftMrg);
sl@0
   353
			break;
sl@0
   354
		case EWsGcOpDrawLine:
sl@0
   355
			iGdi->DrawLine(pData.DrawLine->pnt1,pData.DrawLine->pnt2);
sl@0
   356
			break;
sl@0
   357
		case EWsGcOpDrawTo:
sl@0
   358
			iGdi->DrawLine(iLinePos,*pData.Point);
sl@0
   359
			break;
sl@0
   360
		case EWsGcOpDrawBy:
sl@0
   361
			iGdi->DrawLine(iLinePos,iLinePos+(*pData.Point));
sl@0
   362
			break;
sl@0
   363
		case EWsGcOpPlot:
sl@0
   364
			iGdi->Plot(*pData.Point);
sl@0
   365
			break;
sl@0
   366
		case EWsGcOpMoveTo:
sl@0
   367
		case EWsGcOpMoveBy:
sl@0
   368
			break;
sl@0
   369
		case EWsGcOpGdiBlt2Local:
sl@0
   370
			iGdi->BitBlt(pData.GdiBlt2Local->pos,pData.GdiBlt2Local->bitmap);
sl@0
   371
			break;
sl@0
   372
		case EWsGcOpGdiBlt3Local:
sl@0
   373
			iGdi->BitBlt(pData.GdiBlt3Local->pos,pData.GdiBlt3Local->bitmap, pData.GdiBlt3Local->rect);
sl@0
   374
			break;
sl@0
   375
		case EWsGcOpGdiBltMaskedLocal:
sl@0
   376
			iGdi->BitBltMasked(pData.GdiBltMaskedLocal->pos,pData.GdiBltMaskedLocal->bitmap,
sl@0
   377
								pData.GdiBltMaskedLocal->rect,pData.GdiBltMaskedLocal->maskBitmap,
sl@0
   378
								pData.GdiBltMaskedLocal->invertMask);
sl@0
   379
			break;
sl@0
   380
		case EWsGcOpGdiWsBlt2:
sl@0
   381
		case EWsGcOpGdiWsBlt3:
sl@0
   382
		case EWsGcOpGdiWsBltMasked:
sl@0
   383
		case EWsGcOpGdiWsAlphaBlendBitmaps:
sl@0
   384
		case EWsGcOpWsDrawBitmapMasked:
sl@0
   385
			{
sl@0
   386
			CFbsBitmap* scratchBimap=iScratchBitmap;
sl@0
   387
			CFbsBitmap* scratchMaskBimap=iScratchMaskBitmap;
sl@0
   388
			TInt maskHandle=0;
sl@0
   389
			TInt handle=WsBitmapHandle(aOpcode,pData, maskHandle);
sl@0
   390
			CWsClient* owner=iWin->WsOwner(); // We can't just use iWsOwner - it can be null for stored commands
sl@0
   391
			if (owner!=NULL)
sl@0
   392
				{
sl@0
   393
				DWsBitmap *bitmap=(DWsBitmap *)owner->HandleToObj(handle, WS_HANDLE_BITMAP);
sl@0
   394
				if (!bitmap)
sl@0
   395
					GcOwnerPanic(EWservPanicBitmap);
sl@0
   396
				scratchBimap=bitmap->FbsBitmap();
sl@0
   397
				if (aOpcode==EWsGcOpGdiWsBltMasked || aOpcode==EWsGcOpGdiWsAlphaBlendBitmaps || aOpcode==EWsGcOpWsDrawBitmapMasked)
sl@0
   398
					{
sl@0
   399
					DWsBitmap *bitmap2=(DWsBitmap *)owner->HandleToObj(maskHandle, WS_HANDLE_BITMAP);
sl@0
   400
					if (!bitmap2)
sl@0
   401
						GcOwnerPanic(EWservPanicBitmap);
sl@0
   402
					scratchMaskBimap=bitmap2->FbsBitmap();
sl@0
   403
					}
sl@0
   404
				}
sl@0
   405
			else 
sl@0
   406
				{
sl@0
   407
				GcOwnerPanic(EWservPanicBitmap);
sl@0
   408
				}
sl@0
   409
			switch(aOpcode)
sl@0
   410
				{
sl@0
   411
				case EWsGcOpGdiWsBlt2:
sl@0
   412
					iGdi->BitBlt(pData.GdiBlt2->pos,scratchBimap);
sl@0
   413
					break;
sl@0
   414
				case EWsGcOpGdiWsBlt3:
sl@0
   415
					iGdi->BitBlt(pData.GdiBlt3->pos,scratchBimap, pData.GdiBlt3->rect);
sl@0
   416
					break;
sl@0
   417
				case EWsGcOpGdiWsBltMasked:
sl@0
   418
					{
sl@0
   419
					iGdi->BitBltMasked(pData.GdiBltMasked->destination,scratchBimap,
sl@0
   420
									pData.GdiBltMasked->source, scratchMaskBimap,
sl@0
   421
									pData.GdiBltMasked->invertMask);
sl@0
   422
					}
sl@0
   423
					break;
sl@0
   424
				case EWsGcOpGdiWsAlphaBlendBitmaps:
sl@0
   425
					{
sl@0
   426
					iGdi->AlphaBlendBitmaps(pData.AlphaBlendBitmaps->point,scratchBimap,
sl@0
   427
									   pData.AlphaBlendBitmaps->source, scratchMaskBimap,
sl@0
   428
									   pData.AlphaBlendBitmaps->alphaPoint);
sl@0
   429
					}
sl@0
   430
					break;
sl@0
   431
				case EWsGcOpWsDrawBitmapMasked:
sl@0
   432
					{
sl@0
   433
					iGdi->DrawBitmapMasked(pData.iBitmapMasked->iRect,scratchBimap, 
sl@0
   434
										pData.iBitmapMasked->iSrcRect,scratchMaskBimap,
sl@0
   435
										pData.iBitmapMasked->iInvertMask);
sl@0
   436
					}
sl@0
   437
					break;
sl@0
   438
				}
sl@0
   439
			break;
sl@0
   440
			}
sl@0
   441
		case EWsGcOpGdiBlt2:
sl@0
   442
		case EWsGcOpGdiBlt3:
sl@0
   443
		case EWsGcOpGdiBltMasked:
sl@0
   444
		case EWsGcOpGdiAlphaBlendBitmaps:
sl@0
   445
		case EWsGcOpDrawBitmap:
sl@0
   446
		case EWsGcOpDrawBitmap2:
sl@0
   447
		case EWsGcOpDrawBitmap3:
sl@0
   448
		case EWsGcOpDrawBitmapMasked:
sl@0
   449
			{
sl@0
   450
			TInt maskHandle=0;
sl@0
   451
			TInt ret = iScratchBitmap->Duplicate(FbsBitmapHandle(aOpcode, pData,maskHandle));
sl@0
   452
			if(ret == KErrNoMemory)
sl@0
   453
				break;	
sl@0
   454
			if (ret !=KErrNone)
sl@0
   455
				GcOwnerPanic(EWservPanicBitmap);
sl@0
   456
			
sl@0
   457
			switch(aOpcode)
sl@0
   458
				{
sl@0
   459
				case EWsGcOpGdiBlt2:
sl@0
   460
					iGdi->BitBlt(pData.GdiBlt2->pos,iScratchBitmap);
sl@0
   461
					break;
sl@0
   462
				case EWsGcOpGdiBlt3:
sl@0
   463
					iGdi->BitBlt(pData.GdiBlt3->pos,iScratchBitmap, pData.GdiBlt3->rect);
sl@0
   464
					break;
sl@0
   465
				case EWsGcOpGdiBltMasked:
sl@0
   466
					{
sl@0
   467
					TInt ret = iScratchMaskBitmap->Duplicate(pData.GdiBltMasked->maskHandle);
sl@0
   468
					if(ret == KErrNoMemory)
sl@0
   469
						break;	
sl@0
   470
					if (ret !=KErrNone)
sl@0
   471
						GcOwnerPanic(EWservPanicBitmap);
sl@0
   472
			
sl@0
   473
					iGdi->BitBltMasked(pData.GdiBltMasked->destination,iScratchBitmap,
sl@0
   474
										pData.GdiBltMasked->source, iScratchMaskBitmap,
sl@0
   475
										 pData.GdiBltMasked->invertMask);
sl@0
   476
					iScratchMaskBitmap->Reset();
sl@0
   477
					}
sl@0
   478
					break;
sl@0
   479
				case EWsGcOpGdiAlphaBlendBitmaps:
sl@0
   480
					{
sl@0
   481
					TInt ret = iScratchMaskBitmap->Duplicate(pData.AlphaBlendBitmaps->alphaHandle);
sl@0
   482
					if (ret == KErrNoMemory)
sl@0
   483
						break;	
sl@0
   484
					if (ret != KErrNone)
sl@0
   485
						GcOwnerPanic(EWservPanicBitmap);
sl@0
   486
sl@0
   487
					iGdi->AlphaBlendBitmaps(pData.AlphaBlendBitmaps->point, iScratchBitmap,
sl@0
   488
									   pData.AlphaBlendBitmaps->source, iScratchMaskBitmap,
sl@0
   489
									   pData.AlphaBlendBitmaps->alphaPoint);
sl@0
   490
					iScratchMaskBitmap->Reset();
sl@0
   491
					break;
sl@0
   492
					}
sl@0
   493
				case EWsGcOpDrawBitmap:
sl@0
   494
					iGdi->DrawBitmap(pData.Bitmap->pos, iScratchBitmap);
sl@0
   495
					break;
sl@0
   496
				case EWsGcOpDrawBitmap2:
sl@0
   497
					iGdi->DrawBitmap(pData.Bitmap2->rect, iScratchBitmap);
sl@0
   498
					break;
sl@0
   499
				case EWsGcOpDrawBitmap3:
sl@0
   500
					iGdi->DrawBitmap(pData.Bitmap3->rect, iScratchBitmap, pData.Bitmap3->srcRect);
sl@0
   501
					break;
sl@0
   502
				case EWsGcOpDrawBitmapMasked:
sl@0
   503
					{
sl@0
   504
					TInt ret = iScratchMaskBitmap->Duplicate(pData.iBitmapMasked->iMaskHandle);
sl@0
   505
					if (ret == KErrNoMemory)
sl@0
   506
						break;	
sl@0
   507
					if (ret != KErrNone)
sl@0
   508
						GcOwnerPanic(EWservPanicBitmap);
sl@0
   509
sl@0
   510
					iGdi->DrawBitmapMasked(pData.iBitmapMasked->iRect, iScratchBitmap, 
sl@0
   511
										pData.iBitmapMasked->iSrcRect, iScratchMaskBitmap,
sl@0
   512
										pData.iBitmapMasked->iInvertMask);
sl@0
   513
					iScratchMaskBitmap->Reset();
sl@0
   514
					}
sl@0
   515
					break;
sl@0
   516
				}
sl@0
   517
			iScratchBitmap->Reset();
sl@0
   518
			break;
sl@0
   519
			}
sl@0
   520
		case EWsGcOpDrawSegmentedPolygon:
sl@0
   521
			iGdi->DrawPolygon(iPolyPoints,iPolyPointListSize,pData.DrawSegmentedPolygon->fillRule);
sl@0
   522
			break;
sl@0
   523
		case EWsGcOpDrawPolygon:
sl@0
   524
			DoDrawPolygon(pData.Polygon);
sl@0
   525
			break;
sl@0
   526
		case EWsGcOpDrawPolyLine:
sl@0
   527
			DoDrawPolyLine(pData.PolyLine, EFalse);
sl@0
   528
			break;
sl@0
   529
		case EWsGcOpDrawPolyLineContinued:
sl@0
   530
			DoDrawPolyLine(pData.PolyLine, ETrue);
sl@0
   531
			break;
sl@0
   532
		case EWsGcOpClear:
sl@0
   533
			iGdi->Clear(TRect(iWin->Size()));
sl@0
   534
			break;
sl@0
   535
		case EWsGcOpClearRect:
sl@0
   536
			iGdi->Clear(*pData.Rect);
sl@0
   537
			break;
sl@0
   538
		case EWsGcOpDrawRect:
sl@0
   539
			iGdi->DrawRect(*pData.Rect);
sl@0
   540
			break;
sl@0
   541
		case EWsGcOpDrawEllipse:
sl@0
   542
			iGdi->DrawEllipse(*pData.Rect);
sl@0
   543
			break;
sl@0
   544
		case EWsGcOpDrawRoundRect:
sl@0
   545
			iGdi->DrawRoundRect(*pData.Rect,pData.RoundRect->ellipse);
sl@0
   546
			break;
sl@0
   547
		case EWsGcOpDrawArc:
sl@0
   548
			iGdi->DrawArc(*pData.Rect,pData.ArcOrPie->start,pData.ArcOrPie->end);
sl@0
   549
			break;
sl@0
   550
		case EWsGcOpDrawPie:
sl@0
   551
			iGdi->DrawPie(*pData.Rect,pData.ArcOrPie->start,pData.ArcOrPie->end);
sl@0
   552
			break;
sl@0
   553
		case EWsGcOpCopyRect:
sl@0
   554
			iGdi->CopyRect(pData.CopyRect->pos,*pData.Rect);
sl@0
   555
			break;
sl@0
   556
		case EWsGcOpMapColors:
sl@0
   557
			iGdi->MapColors(pData.MapColors->rect,(TRgb *)(pData.MapColors+1),pData.MapColors->numPairs,pData.MapColors->mapForwards);
sl@0
   558
			break;
sl@0
   559
			
sl@0
   560
		default:
sl@0
   561
			GcOwnerPanic(EWservPanicOpcode);
sl@0
   562
		}
sl@0
   563
	iGdi->SetClippingRegion(NULL);
sl@0
   564
	}
sl@0
   565
sl@0
   566
TInt CWsGc::WsBitmapHandle(TInt aOpcode, const TWsGcCmdUnion &pData, TInt& aMaskHandle) 
sl@0
   567
	{
sl@0
   568
	TInt handle=0;
sl@0
   569
	switch(aOpcode)
sl@0
   570
		{
sl@0
   571
		case EWsGcOpGdiWsBlt2:
sl@0
   572
			handle=pData.GdiBlt2->handle;
sl@0
   573
			break;
sl@0
   574
		case EWsGcOpGdiWsBlt3:
sl@0
   575
			handle=pData.GdiBlt3->handle;
sl@0
   576
			break;
sl@0
   577
		case EWsGcOpGdiWsBltMasked:
sl@0
   578
			handle=pData.GdiBltMasked->handle;
sl@0
   579
			aMaskHandle = pData.GdiBltMasked->maskHandle;
sl@0
   580
			break;
sl@0
   581
		case EWsGcOpGdiWsAlphaBlendBitmaps:
sl@0
   582
			handle=pData.AlphaBlendBitmaps->bitmapHandle;
sl@0
   583
			aMaskHandle = pData.AlphaBlendBitmaps->alphaHandle;
sl@0
   584
			break;
sl@0
   585
		case EWsGcOpWsDrawBitmapMasked:
sl@0
   586
			handle=pData.iBitmapMasked->iHandle;
sl@0
   587
			aMaskHandle=pData.iBitmapMasked->iMaskHandle;
sl@0
   588
			break;
sl@0
   589
		default:
sl@0
   590
			OwnerPanic(EWservPanicOpcode);
sl@0
   591
		}
sl@0
   592
	return handle;
sl@0
   593
	}		
sl@0
   594
sl@0
   595
TInt CWsGc::FbsBitmapHandle(TInt aOpcode, const TWsGcCmdUnion &pData, TInt& aMaskHandle)
sl@0
   596
	{
sl@0
   597
	TInt handle=0;
sl@0
   598
	aMaskHandle=0;
sl@0
   599
	switch(aOpcode)
sl@0
   600
		{
sl@0
   601
		case EWsGcOpGdiBlt2:
sl@0
   602
			handle=pData.GdiBlt2->handle;
sl@0
   603
			break;
sl@0
   604
		case EWsGcOpGdiBlt3:
sl@0
   605
			handle=pData.GdiBlt3->handle;
sl@0
   606
			break;
sl@0
   607
		case EWsGcOpGdiBltMasked:
sl@0
   608
			handle=pData.GdiBltMasked->handle;
sl@0
   609
			aMaskHandle=pData.GdiBltMasked->maskHandle;
sl@0
   610
			break;
sl@0
   611
		case EWsGcOpGdiAlphaBlendBitmaps:
sl@0
   612
			handle=pData.AlphaBlendBitmaps->bitmapHandle;
sl@0
   613
			aMaskHandle=pData.AlphaBlendBitmaps->alphaHandle;
sl@0
   614
			break;
sl@0
   615
		case EWsGcOpDrawBitmap:
sl@0
   616
			handle=pData.Bitmap->handle;
sl@0
   617
			break;
sl@0
   618
		case EWsGcOpDrawBitmap2:
sl@0
   619
			handle=pData.Bitmap2->handle;
sl@0
   620
			break;
sl@0
   621
		case EWsGcOpDrawBitmap3:
sl@0
   622
			handle=pData.Bitmap3->handle;
sl@0
   623
			break;
sl@0
   624
		case EWsGcOpDrawBitmapMasked:
sl@0
   625
			handle=pData.iBitmapMasked->iHandle;
sl@0
   626
			aMaskHandle=pData.iBitmapMasked->iMaskHandle;
sl@0
   627
			break;
sl@0
   628
		default:
sl@0
   629
			OwnerPanic(EWservPanicOpcode);
sl@0
   630
		}
sl@0
   631
	return handle;
sl@0
   632
	}
sl@0
   633
sl@0
   634
sl@0
   635
void CWsGc::UpdateJustification(TText* aText,TInt aLen)
sl@0
   636
	{
sl@0
   637
	iGdi->UpdateJustification(BufferTPtr(aText,aLen));
sl@0
   638
	}
sl@0
   639
sl@0
   640
void CWsGc::DoDrawing2(TWsGcOpcodes aOpcode, const TWsGcCmdUnion &pData)
sl@0
   641
	{
sl@0
   642
	iGdi->SetUserDisplayMode(iWin->DisplayMode());
sl@0
   643
	if (iClippingRectSet)
sl@0
   644
		{
sl@0
   645
		iGdi->SetOrigin(TPoint(0,0));
sl@0
   646
		iGdi->SetClippingRect(iClippingRect);
sl@0
   647
		}
sl@0
   648
	iGdi->SetOrigin(iOrigin);
sl@0
   649
	
sl@0
   650
	DoDrawCommand(aOpcode,pData,iUserDefinedClippingRegion);
sl@0
   651
sl@0
   652
	iGdi->SetUserDisplayMode(ENone);
sl@0
   653
	iGdi->CancelClippingRect();
sl@0
   654
	switch(aOpcode)
sl@0
   655
		{
sl@0
   656
		case EWsGcOpDrawLine:
sl@0
   657
			iLinePos=pData.DrawLine->pnt2;
sl@0
   658
			break;
sl@0
   659
		case EWsGcOpDrawTo:
sl@0
   660
		case EWsGcOpMoveTo:
sl@0
   661
		case EWsGcOpPlot:
sl@0
   662
			iLinePos=(*pData.Point);
sl@0
   663
			break;
sl@0
   664
		case EWsGcOpDrawBy:
sl@0
   665
		case EWsGcOpMoveBy:
sl@0
   666
			iLinePos+=(*pData.Point);
sl@0
   667
			break;
sl@0
   668
		case EWsGcOpDrawSegmentedPolygon:
sl@0
   669
			EndSegmentedPolygon();
sl@0
   670
			break;
sl@0
   671
		case EWsGcOpDrawText:
sl@0
   672
			UpdateJustification((TText *)(pData.DrawText+1),pData.DrawText->length);
sl@0
   673
			break;
sl@0
   674
		case EWsGcOpDrawTextVertical:
sl@0
   675
			UpdateJustification((TText *)(pData.DrawTextVertical+1),pData.DrawTextVertical->length);
sl@0
   676
			break;
sl@0
   677
		case EWsGcOpDrawBoxText:
sl@0
   678
			UpdateJustification((TText *)(pData.BoxText+1),pData.BoxText->length);
sl@0
   679
			break;
sl@0
   680
		case EWsGcOpDrawBoxTextOptimised1:
sl@0
   681
			UpdateJustification((TText *)(pData.BoxTextO1+1),pData.BoxTextO1->length);
sl@0
   682
			break;
sl@0
   683
		case EWsGcOpDrawBoxTextOptimised2:
sl@0
   684
			UpdateJustification((TText *)(pData.BoxTextO2+1),pData.BoxTextO2->length);
sl@0
   685
			break;
sl@0
   686
		case EWsGcOpDrawBoxTextVertical:
sl@0
   687
			UpdateJustification((TText *)(pData.DrawBoxTextVertical+1),pData.DrawBoxTextVertical->length);
sl@0
   688
			break;
sl@0
   689
		case EWsGcOpDrawTextLocal:
sl@0
   690
			iGdi->UpdateJustification(*pData.DrawTextLocal->desc);
sl@0
   691
			break;
sl@0
   692
		case EWsGcOpDrawBoxTextLocal:
sl@0
   693
			iGdi->UpdateJustification(*pData.BoxTextLocal->desc);
sl@0
   694
			break;
sl@0
   695
		case EWsGcOpDrawTextPtr:
sl@0
   696
			iGdi->UpdateJustification(*pData.DrawTextPtr->text);
sl@0
   697
			break;
sl@0
   698
		case EWsGcOpDrawTextVerticalPtr:
sl@0
   699
			iGdi->UpdateJustification(*pData.DrawTextVerticalPtr->text);
sl@0
   700
			break;
sl@0
   701
		case EWsGcOpDrawBoxTextPtr:
sl@0
   702
			iGdi->UpdateJustification(*pData.DrawBoxTextPtr->text);
sl@0
   703
			break;
sl@0
   704
		case EWsGcOpDrawBoxTextVerticalPtr:
sl@0
   705
			iGdi->UpdateJustification(*pData.DrawBoxTextVerticalPtr->text);
sl@0
   706
			break;
sl@0
   707
		}
sl@0
   708
	}
sl@0
   709
sl@0
   710
void CWsGc::DoDrawing1(TWsGcOpcodes aOpcode, const TWsGcCmdUnion &pData)
sl@0
   711
	{
sl@0
   712
	TWsGcLargeStruct newData;
sl@0
   713
	TWsGcCmdUnion pNewData;
sl@0
   714
	TWsGcOpcodes opcode;
sl@0
   715
	TDesC **string;
sl@0
   716
	TInt toGo;
sl@0
   717
	pNewData.LargeStruct=&newData;
sl@0
   718
	switch (aOpcode)
sl@0
   719
		{
sl@0
   720
		case EWsGcOpDrawTextPtr:
sl@0
   721
			WS_ASSERT_DEBUG(sizeof(TWsGcLargeStruct)>=sizeof(TWsGcCmdDrawTextPtr), EWsPanicGcStructSizeError);
sl@0
   722
			opcode=EWsGcOpDrawTextPtr1;
sl@0
   723
			toGo=pData.DrawText->length;
sl@0
   724
			pNewData.DrawTextPtr->pos=pData.DrawText->pos;
sl@0
   725
			string=&(pNewData.DrawTextPtr->text);
sl@0
   726
			break;
sl@0
   727
		case EWsGcOpDrawTextVerticalPtr:
sl@0
   728
			WS_ASSERT_DEBUG(sizeof(TWsGcLargeStruct)>=sizeof(TWsGcCmdDrawTextVerticalPtr), EWsPanicGcStructSizeError);
sl@0
   729
			opcode=EWsGcOpDrawTextVerticalPtr1;
sl@0
   730
			toGo=pData.DrawTextVertical->length;
sl@0
   731
			pNewData.DrawTextVerticalPtr->pos=pData.DrawTextVertical->pos;
sl@0
   732
			pNewData.DrawTextVerticalPtr->up=pData.DrawTextVertical->up;
sl@0
   733
			string=&(pNewData.DrawTextVerticalPtr->text);
sl@0
   734
			break;
sl@0
   735
			
sl@0
   736
		case EWsGcOpDrawBoxTextPtr:
sl@0
   737
			WS_ASSERT_DEBUG(sizeof(TWsGcLargeStruct)>=sizeof(TWsGcCmdBoxTextPtr), EWsPanicGcStructSizeError);
sl@0
   738
			opcode=EWsGcOpDrawBoxTextPtr1;
sl@0
   739
			toGo=pData.BoxText->length;
sl@0
   740
			pNewData.DrawBoxTextPtr->box=pData.BoxText->box;
sl@0
   741
			pNewData.DrawBoxTextPtr->baselineOffset=pData.BoxText->baselineOffset;
sl@0
   742
			pNewData.DrawBoxTextPtr->horiz=pData.BoxText->horiz;
sl@0
   743
			pNewData.DrawBoxTextPtr->leftMrg=pData.BoxText->leftMrg;
sl@0
   744
			pNewData.DrawBoxTextPtr->width=pData.BoxText->width;
sl@0
   745
			string=&(pNewData.DrawBoxTextPtr->text);
sl@0
   746
			break;
sl@0
   747
			
sl@0
   748
		case EWsGcOpDrawBoxTextVerticalPtr:
sl@0
   749
			WS_ASSERT_DEBUG(sizeof(TWsGcLargeStruct)>=sizeof(TWsGcCmdBoxTextVerticalPtr), EWsPanicGcStructSizeError);
sl@0
   750
			opcode=EWsGcOpDrawBoxTextVerticalPtr1;
sl@0
   751
			toGo=pData.DrawBoxTextVertical->length;
sl@0
   752
			pNewData.DrawBoxTextVerticalPtr->box=pData.DrawBoxTextVertical->box;
sl@0
   753
			pNewData.DrawBoxTextVerticalPtr->baselineOffset=pData.DrawBoxTextVertical->baselineOffset;
sl@0
   754
			pNewData.DrawBoxTextVerticalPtr->up=pData.DrawBoxTextVertical->up;
sl@0
   755
			pNewData.DrawBoxTextVerticalPtr->vert=pData.DrawBoxTextVertical->vert;
sl@0
   756
			pNewData.DrawBoxTextVerticalPtr->margin=pData.DrawBoxTextVertical->margin;
sl@0
   757
			pNewData.DrawBoxTextVerticalPtr->width=pData.DrawBoxTextVertical->width;
sl@0
   758
			string=&(pNewData.DrawBoxTextVerticalPtr->text);
sl@0
   759
			break;
sl@0
   760
sl@0
   761
		default:
sl@0
   762
			DoDrawing2(aOpcode,pData);
sl@0
   763
			return;
sl@0
   764
		}
sl@0
   765
sl@0
   766
	TBuf<ETextPtrBufLen> buf;
sl@0
   767
	TInt len=ETextPtrBufLen;
sl@0
   768
	TInt bufOffset=0;
sl@0
   769
	*string=&buf;
sl@0
   770
	while(toGo>0)
sl@0
   771
		{
sl@0
   772
		if (len>toGo)
sl@0
   773
			len=toGo;
sl@0
   774
		iWsOwner->RemoteRead(buf,bufOffset);
sl@0
   775
		DoDrawing2(aOpcode,pNewData);
sl@0
   776
		aOpcode=opcode;
sl@0
   777
		bufOffset+=len;
sl@0
   778
		toGo-=len;
sl@0
   779
		}
sl@0
   780
	}
sl@0
   781
sl@0
   782
void CWsGc::SetGcAttribute(TInt aOpcode, TWsGcCmdUnion pData)
sl@0
   783
	{
sl@0
   784
	switch(aOpcode)
sl@0
   785
		{
sl@0
   786
		case EWsGcOpSetDrawMode:
sl@0
   787
			iGdi->SetDrawMode((CGraphicsContext::TDrawMode)*pData.UInt);
sl@0
   788
			break;
sl@0
   789
		case EWsGcOpUseFont:
sl@0
   790
			if (CWsFontCache::Instance()->UseFont(iFont, *pData.UInt))
sl@0
   791
				{	// Couldn't cache it
sl@0
   792
				TInt ret = iGdi->UseFont(*pData.UInt);
sl@0
   793
				if (ret == KErrNoMemory)
sl@0
   794
					return;
sl@0
   795
				if (ret != KErrNone)
sl@0
   796
					OwnerPanic(EWservPanicFont);
sl@0
   797
				}
sl@0
   798
			else
sl@0
   799
				{
sl@0
   800
				if (iFont==NULL)
sl@0
   801
					OwnerPanic(EWservPanicFont);
sl@0
   802
				iGdi->UseFontNoDuplicate(iFont);
sl@0
   803
				}
sl@0
   804
			break;
sl@0
   805
		case EWsGcOpDiscardFont:
sl@0
   806
			CWsFontCache::Instance()->ReleaseFont(iFont);
sl@0
   807
			iGdi->DiscardFont();
sl@0
   808
			break;
sl@0
   809
		case EWsGcOpSetUnderlineStyle:
sl@0
   810
			iGdi->SetUnderlineStyle(*pData.SetUnderlineStyle);
sl@0
   811
			break;
sl@0
   812
		case EWsGcOpSetStrikethroughStyle:
sl@0
   813
			iGdi->SetStrikethroughStyle(*pData.SetStrikethroughStyle);
sl@0
   814
			break;
sl@0
   815
		case EWsGcOpUseBrushPattern:
sl@0
   816
			{
sl@0
   817
			TInt ret = iGdi->UseBrushPattern(*pData.handle);
sl@0
   818
			if (ret == KErrNoMemory)
sl@0
   819
				return;	
sl@0
   820
			if (ret != KErrNone)
sl@0
   821
				OwnerPanic(EWservPanicBitmap);
sl@0
   822
			}
sl@0
   823
			break;
sl@0
   824
		case EWsGcOpDiscardBrushPattern:
sl@0
   825
			iGdi->DiscardBrushPattern();
sl@0
   826
			break;
sl@0
   827
		case EWsGcOpSetBrushColor:
sl@0
   828
			iGdi->SetBrushColor(*pData.rgb);
sl@0
   829
			break;
sl@0
   830
		case EWsGcOpSetPenColor:
sl@0
   831
			iGdi->SetPenColor(*pData.rgb);
sl@0
   832
			break;
sl@0
   833
		case EWsGcOpSetPenStyle:
sl@0
   834
			iGdi->SetPenStyle((CGraphicsContext::TPenStyle)*pData.UInt);
sl@0
   835
			break;
sl@0
   836
		case EWsGcOpSetPenSize:
sl@0
   837
			iGdi->SetPenSize(*pData.Size);
sl@0
   838
			break;
sl@0
   839
		case EWsGcOpSetBrushStyle:
sl@0
   840
			if ((CGraphicsContext::TBrushStyle)*pData.UInt==CGraphicsContext::EPatternedBrush &&
sl@0
   841
				!iGdi->IsBrushPatternUsed())
sl@0
   842
				OwnerPanic(EWservPanicNoBrush);
sl@0
   843
			iGdi->SetBrushStyle((CGraphicsContext::TBrushStyle)*pData.UInt);
sl@0
   844
			break;
sl@0
   845
		case EWsGcOpReset:
sl@0
   846
			CWsFontCache::Instance()->ReleaseFont(iFont);
sl@0
   847
			iGdi->Reset();
sl@0
   848
			iOrigin.SetXY(0,0);
sl@0
   849
			ResetClippingRect();
sl@0
   850
			iGdi->SetBrushColor(iWin->BackColor());
sl@0
   851
			break;
sl@0
   852
		case EWsGcOpSetBrushOrigin:
sl@0
   853
			iGdi->SetBrushOrigin(*pData.Point);
sl@0
   854
			break;
sl@0
   855
		case EWsGcOpSetDitherOrigin:
sl@0
   856
			iGdi->SetDitherOrigin(*pData.Point);
sl@0
   857
			break;
sl@0
   858
		case EWsGcOpSetWordJustification:
sl@0
   859
			iGdi->SetWordJustification(pData.SetJustification->excessWidth, pData.SetJustification->numGaps);
sl@0
   860
			break;
sl@0
   861
		case EWsGcOpSetCharJustification:
sl@0
   862
			iGdi->SetCharJustification(pData.SetJustification->excessWidth, pData.SetJustification->numGaps);
sl@0
   863
			break;
sl@0
   864
		case EWsGcOpSetOrigin:
sl@0
   865
			SetOrigin(*pData.Point);
sl@0
   866
			break;
sl@0
   867
		case EWsGcOpSetOpaque:
sl@0
   868
			//SetOpaque(*pData.Bool);
sl@0
   869
			break;
sl@0
   870
		case EWsGcOpSetShadowColor:
sl@0
   871
			iGdi->SetShadowColor(*pData.rgb);
sl@0
   872
			break;
sl@0
   873
		}
sl@0
   874
	}
sl@0
   875
sl@0
   876
void CWsGc::DoDrawing0L(TWsGcOpcodes aOpcode, const TWsGcCmdUnion &pData)
sl@0
   877
	{
sl@0
   878
	if (iWin==NULL)
sl@0
   879
		{
sl@0
   880
		OwnerPanic(EWservPanicGcNotActive);
sl@0
   881
		return;
sl@0
   882
		}
sl@0
   883
			
sl@0
   884
	switch(aOpcode)
sl@0
   885
		{
sl@0
   886
	case EWsGcOpStartSegmentedDrawPolygon:
sl@0
   887
		// Andy - why are these two special cased like this?
sl@0
   888
		//tell Redraw Store about the drawing data, so that it is stored and CWsGc::ExternalizeL can be called if required
sl@0
   889
		if (iWin->Redraw()->DrawCommand(this,pData.any))
sl@0
   890
			StartSegmentedDrawPolygonL(pData.StartSegmentedDrawPolygon);
sl@0
   891
		return;
sl@0
   892
	case EWsGcOpSegmentedDrawPolygonData:
sl@0
   893
		//tell Redraw Store about the drawing data, so that it is stored and CWsGc::ExternalizeL can be called if required
sl@0
   894
		if (iWin->Redraw()->DrawCommand(this,pData.any))
sl@0
   895
				SegmentedDrawPolygonData(pData.SegmentedDrawPolygonData);
sl@0
   896
		return;
sl@0
   897
	case EWsGcOpSetClippingRegion:
sl@0
   898
		SetClippingRegionL(*pData.Int);
sl@0
   899
		break;
sl@0
   900
	case EWsGcOpSetClippingRect:
sl@0
   901
		SetClippingRect(*pData.Rect);
sl@0
   902
		break;
sl@0
   903
	case EWsGcOpCancelClippingRect:
sl@0
   904
		ResetClippingRect();
sl@0
   905
		break;
sl@0
   906
	case EWsGcOpCancelClippingRegion:
sl@0
   907
		CancelClippingRegion();
sl@0
   908
		break;
sl@0
   909
	case EWsGcOpSetFaded:
sl@0
   910
		iGdi->SetFaded(*pData.Bool);
sl@0
   911
		break;
sl@0
   912
	case EWsGcOpSetFadeParams:
sl@0
   913
		iGdi->SetFadingParameters(WservEncoding::ExtractFirst8BitValue(*pData.UInt),WservEncoding::ExtractSecond8BitValue(*pData.UInt));
sl@0
   914
		break;
sl@0
   915
	case EWsGcOpSetDrawMode:
sl@0
   916
	case EWsGcOpUseFont:
sl@0
   917
	case EWsGcOpDiscardFont:
sl@0
   918
	case EWsGcOpUseBrushPattern:
sl@0
   919
	case EWsGcOpDiscardBrushPattern:
sl@0
   920
	case EWsGcOpSetBrushColor:
sl@0
   921
	case EWsGcOpSetPenColor:
sl@0
   922
	case EWsGcOpSetPenStyle:
sl@0
   923
	case EWsGcOpSetPenSize:
sl@0
   924
	case EWsGcOpSetBrushStyle:
sl@0
   925
	case EWsGcOpReset:
sl@0
   926
	case EWsGcOpSetBrushOrigin:
sl@0
   927
	case EWsGcOpSetDitherOrigin:
sl@0
   928
	case EWsGcOpSetUnderlineStyle:
sl@0
   929
	case EWsGcOpSetStrikethroughStyle:
sl@0
   930
	case EWsGcOpSetWordJustification:
sl@0
   931
	case EWsGcOpSetCharJustification:
sl@0
   932
	case EWsGcOpSetOrigin:
sl@0
   933
	case EWsGcOpSetOpaque:
sl@0
   934
	case EWsGcOpSetShadowColor:
sl@0
   935
		{
sl@0
   936
		SetGcAttribute(aOpcode,pData);
sl@0
   937
		break;
sl@0
   938
		}
sl@0
   939
	case EWsGcOpDrawBoxText:	
sl@0
   940
	case EWsGcOpDrawBoxTextOptimised1:
sl@0
   941
	case EWsGcOpDrawBoxTextOptimised2:
sl@0
   942
	case EWsGcOpDrawBoxTextPtr:
sl@0
   943
	case EWsGcOpDrawBoxTextPtr1:
sl@0
   944
	case EWsGcOpDrawTextPtr:
sl@0
   945
	case EWsGcOpDrawTextPtr1:
sl@0
   946
	case EWsGcOpDrawText:
sl@0
   947
	case EWsGcOpDrawTextVertical:
sl@0
   948
	case EWsGcOpDrawTextVerticalPtr:
sl@0
   949
	case EWsGcOpDrawTextVerticalPtr1:
sl@0
   950
	case EWsGcOpDrawBoxTextVertical:
sl@0
   951
	case EWsGcOpDrawBoxTextVerticalPtr:
sl@0
   952
	case EWsGcOpDrawBoxTextVerticalPtr1:
sl@0
   953
	case EWsGcOpDrawTextLocal:
sl@0
   954
	case EWsGcOpDrawBoxTextLocal:
sl@0
   955
		{
sl@0
   956
		//Make sure a font is set before any text related opcodes are used.
sl@0
   957
		if (!iGdi->IsFontUsed())
sl@0
   958
			OwnerPanic(EWservPanicNoFont);
sl@0
   959
		//fall through
sl@0
   960
		}
sl@0
   961
	default:	// Assume remaining functions will draw
sl@0
   962
		{
sl@0
   963
		if (iWin->WinType()!=EWinTypeRoot)
sl@0
   964
			{
sl@0
   965
			if (!iWin->BaseParent())
sl@0
   966
				OwnerPanic(EWservPanicParentDeleted);
sl@0
   967
			if (iWin->WinType()!=EWinTypeClient)
sl@0
   968
				OwnerPanic(EWservPanicReadOnlyDrawable);
sl@0
   969
			}
sl@0
   970
		if (iWin->Redraw()->DrawCommand(this,pData.any))
sl@0
   971
			DoDrawing1(aOpcode,pData);
sl@0
   972
		return;
sl@0
   973
		}
sl@0
   974
		}
sl@0
   975
	iWin->Redraw()->GcAttributeChange(this,pData.any);
sl@0
   976
	}
sl@0
   977
sl@0
   978
void CWsGc::CommandL(TInt aOpcode, const TAny *aCmdData)
sl@0
   979
	{
sl@0
   980
	TWsGcOpcodes opcode = static_cast<TWsGcOpcodes>(aOpcode);
sl@0
   981
sl@0
   982
	TWsGcCmdUnion pData;
sl@0
   983
	pData.any=aCmdData;
sl@0
   984
	switch(opcode)
sl@0
   985
		{
sl@0
   986
		case EWsGcOpActivate:
sl@0
   987
			Activate(*pData.handle);
sl@0
   988
			break;
sl@0
   989
		case EWsGcOpDeactivate:
sl@0
   990
			Deactivate();
sl@0
   991
			break;
sl@0
   992
		case EWsGcOpFree:
sl@0
   993
			delete this;
sl@0
   994
			break;
sl@0
   995
		case EWsGcOpTestInvariant:
sl@0
   996
			break;
sl@0
   997
		default:
sl@0
   998
			DoDrawing0L(opcode,pData);
sl@0
   999
			break;
sl@0
  1000
		}
sl@0
  1001
	}
sl@0
  1002
sl@0
  1003
void CWsGc::SetOrigin(const TPoint &aOrigin)
sl@0
  1004
	{
sl@0
  1005
	iOrigin=aOrigin;
sl@0
  1006
	}
sl@0
  1007
	
sl@0
  1008
sl@0
  1009
void CWsGc::SetOpaque(TBool /*aDrawOpaque*/)
sl@0
  1010
	{
sl@0
  1011
	}
sl@0
  1012
sl@0
  1013
/*------------------------------------------------------------------------------
sl@0
  1014
  Description: Saves graphics context information into a given buffer from a
sl@0
  1015
               given start position rather than just streaming data to the end.
sl@0
  1016
               This variant allows for buffers that are not fully utilised.
sl@0
  1017
 -----------------------------------------------------------------------------*/
sl@0
  1018
TInt CWsGc::ExternalizeL(CBufBase& aBuffer, TInt aStartPos)
sl@0
  1019
	{
sl@0
  1020
	WS_ASSERT_DEBUG(!IsPolyPointData(), EWsPanicDrawCommandsInvalidState);
sl@0
  1021
sl@0
  1022
	// Open the stream used for the output from the given start position
sl@0
  1023
	// in the buffer.
sl@0
  1024
	RBufWriteStream bufWriteStream;
sl@0
  1025
	bufWriteStream.Open(aBuffer, aStartPos);
sl@0
  1026
	CleanupClosePushL(bufWriteStream);
sl@0
  1027
sl@0
  1028
	// Font/Bitmap Server data is serialised below in a call to 
sl@0
  1029
	// CFbsBitGc::ExternalizeL(). As this method does not return the amount of
sl@0
  1030
	// the data externalised we use methods in the underlying stream to 
sl@0
  1031
	// calculate it. We do this because we need to return an accurate count of
sl@0
  1032
	// data serialised from this method so that the caller can update its 
sl@0
  1033
	// buffer write counter.
sl@0
  1034
	MStreamBuf* ptrToRawStream = bufWriteStream.Sink();	// This is the real stream
sl@0
  1035
sl@0
  1036
	// Position of read seek pointer before externalise
sl@0
  1037
	TStreamPos size1 = ptrToRawStream->TellL(MStreamBuf::EWrite); 
sl@0
  1038
sl@0
  1039
	// Save the font/bitmap server data
sl@0
  1040
	iGdi->ExternalizeL(bufWriteStream);
sl@0
  1041
sl@0
  1042
	bufWriteStream.WriteInt32L(iOrigin.iX);
sl@0
  1043
	bufWriteStream.WriteInt32L(iOrigin.iY);
sl@0
  1044
sl@0
  1045
	bufWriteStream.WriteInt8L(iClippingRectSet);
sl@0
  1046
sl@0
  1047
	// If there is a clipping rectangle output that too.
sl@0
  1048
	if (iClippingRectSet)
sl@0
  1049
		{
sl@0
  1050
		bufWriteStream << iClippingRect;
sl@0
  1051
		}
sl@0
  1052
		
sl@0
  1053
	// Save clipping region data.
sl@0
  1054
	ExternalizeClippingRegionL(bufWriteStream);
sl@0
  1055
sl@0
  1056
	// Save the Alpha values for Brush and Pen colors.
sl@0
  1057
	ExternalizeAlphaValueL(bufWriteStream);
sl@0
  1058
sl@0
  1059
	// Position of read seek pointer after externalise
sl@0
  1060
	TStreamPos size2 = ptrToRawStream->TellL(MStreamBuf::EWrite);
sl@0
  1061
	CleanupStack::PopAndDestroy(&bufWriteStream);
sl@0
  1062
sl@0
  1063
	// Return actual size of data serialized
sl@0
  1064
	return (size2 - size1);
sl@0
  1065
	}
sl@0
  1066
sl@0
  1067
/*------------------------------------------------------------------------------
sl@0
  1068
  Description: Saves TRgb::alpha value information into a given buffer.
sl@0
  1069
  ----------------------------------------------------------------------------*/
sl@0
  1070
void CWsGc::ExternalizeAlphaValueL(RWriteStream& aWriteStream)
sl@0
  1071
	{
sl@0
  1072
	aWriteStream.WriteUint8L(iGdi->BrushColor().Alpha());
sl@0
  1073
	aWriteStream.WriteUint8L(iGdi->PenColor().Alpha());
sl@0
  1074
	}
sl@0
  1075
sl@0
  1076
/*------------------------------------------------------------------------------
sl@0
  1077
  Description: Helper method to store clipping region data to a given
sl@0
  1078
               write stream.
sl@0
  1079
 -----------------------------------------------------------------------------*/
sl@0
  1080
TInt CWsGc::ExternalizeClippingRegionL(RWriteStream& aWriteStream)
sl@0
  1081
	{
sl@0
  1082
	TBool clipRegion = (iUserDefinedClippingRegion != NULL);
sl@0
  1083
	// Store flag to indicate if client has defined a clipping region
sl@0
  1084
	aWriteStream.WriteInt8L(clipRegion);
sl@0
  1085
	// Store client clipping region data if it exists
sl@0
  1086
	if (clipRegion)
sl@0
  1087
		{
sl@0
  1088
		return ExternalizeRegionL(aWriteStream, *iUserDefinedClippingRegion) + sizeof(TInt8);
sl@0
  1089
		}
sl@0
  1090
	return sizeof(TInt8);
sl@0
  1091
	}
sl@0
  1092