sl@0: // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: // All rights reserved.
sl@0: // This component and the accompanying materials are made available
sl@0: // under the terms of "Eclipse Public License v1.0"
sl@0: // which accompanies this distribution, and is available
sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: //
sl@0: // Initial Contributors:
sl@0: // Nokia Corporation - initial contribution.
sl@0: //
sl@0: // Contributors:
sl@0: //
sl@0: // Description:
sl@0: //
sl@0: 
sl@0: #include <graphics/remotegc.h>
sl@0: #include <graphics/commandbuffer.h>
sl@0: #include <graphics/wsdrawresource.h>
sl@0: #include <graphics/gdi/gdiconsts.h>
sl@0: #include <graphics/gdi/gdistructs.h>
sl@0: #include "graphics/windowserverconstants.h"
sl@0: 
sl@0: #define KDefaultShadowColor KRgbGray
sl@0: 
sl@0: class CRemoteGc::CPimpl : public CBase, public MWsDrawResource
sl@0: 	{
sl@0: public:
sl@0: 	CPimpl(CRemoteGc& aGc) : iGc(aGc) {}
sl@0: public: //from MWsDrawResource
sl@0: 	void DrawResource(const TPoint& aPos, const RWsDrawableSource& aSource, CWindowGc::TGraphicsRotation aRotation=CWindowGc::EGraphicsRotationNone)
sl@0: 		{
sl@0: 		iGc.DrawResource(aPos, aSource, aRotation);
sl@0: 		}
sl@0: 	void DrawResource(const TRect& aDestRect, const RWsDrawableSource& aSource, CWindowGc::TGraphicsRotation aRotation=CWindowGc::EGraphicsRotationNone)
sl@0: 		{
sl@0: 		iGc.DrawResource(aDestRect, aSource, aRotation);
sl@0: 		}
sl@0: 	void DrawResource(const TRect& aDestRect, const RWsDrawableSource& aSource, const TRect& aSrcRect, CWindowGc::TGraphicsRotation aRotation=CWindowGc::EGraphicsRotationNone)
sl@0: 		{
sl@0: 		iGc.DrawResource(aDestRect, aSource, aSrcRect, aRotation);
sl@0: 		}
sl@0: 	void DrawResource(const TRect& aDestRect, const RWsDrawableSource& aSource, const TDesC8& aParam)
sl@0: 		{
sl@0: 		iGc.DrawResource(aDestRect, aSource, aParam);
sl@0: 		}
sl@0: private:
sl@0: 	CRemoteGc& iGc;
sl@0: 	};
sl@0: 
sl@0: /**
sl@0: Creates a new remotegc.
sl@0: 
sl@0: @param aDevice The windowserver screendevice to use.
sl@0: @param aCommandBufferObserver Pointer to a commandbufferobserver.
sl@0: @return A pointer to a new instance of CRemoteGc.
sl@0: */
sl@0: EXPORT_C CRemoteGc* CRemoteGc::NewL(CWsScreenDevice* aDevice)
sl@0: 	{
sl@0: 	CRemoteGc* remoteGc = new (ELeave) CRemoteGc(aDevice);
sl@0: 	CleanupStack::PushL(remoteGc);
sl@0: 	remoteGc->ConstructL();
sl@0: 	CleanupStack::Pop(remoteGc);
sl@0: 	return remoteGc;
sl@0: 	}
sl@0: 
sl@0: CRemoteGc::CRemoteGc(CWsScreenDevice* aDevice) : CWindowGc(aDevice), iCommandBufferObserver(NULL), iFont(NULL), iShadowColor(KDefaultShadowColor)
sl@0: 	{	
sl@0: 	}
sl@0: 	
sl@0: EXPORT_C CRemoteGc::~CRemoteGc()
sl@0: 	{
sl@0: 	delete iCommandBuffer;
sl@0: 	delete iRemoteGcPimpl;
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::ConstructL()
sl@0: 	{
sl@0: 	User::LeaveIfError(CWindowGc::Construct());
sl@0: 	iCommandBuffer = CCommandBuffer::NewL();
sl@0: 	iRemoteGcPimpl = new(ELeave) CPimpl(*this);
sl@0: 	}
sl@0: 	
sl@0: EXPORT_C void CRemoteGc::SetCommandBufferObserver(MCommandBufferObserver* aCommandBufferObserver)
sl@0: 	{
sl@0: 	iCommandBufferObserver = aCommandBufferObserver;
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: Resets the commandbuffer.
sl@0: */
sl@0: EXPORT_C void CRemoteGc::ResetCommandBuffer()
sl@0: 	{
sl@0: 	iCommandBuffer->Reset();
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: Externalizes commandbuffer sections into a format which makes it possible to send over IPC.
sl@0: If ETrue is sent as a parameter to this method, the entire commandbuffer will be externalized,
sl@0: otherwise only sections which has not been externalized before will be externalized. Note that if only
sl@0: not externalized sections is asked for, the flag will be reset on that section so next call
sl@0: to ExternalizeLC will not externalize that section.
sl@0: 
sl@0: @param aMsgBuf A buffer used to externalize the commandbuffer to.
sl@0: @param aEntireBuffer If ETrue, the entire commandbuffer will be externalized, otherwise only sections which has not been externalized before.
sl@0: */	
sl@0: EXPORT_C void CRemoteGc::ExternalizeL(RWsGraphicMsgBuf& aMsgBuf, TBool aEntireBuffer)
sl@0: 	{
sl@0: 	return iCommandBuffer->ExternalizeL(aMsgBuf, aEntireBuffer);
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: Prepares the remotegc to be drawn to.
sl@0: 
sl@0: @param aRect The rect to be drawn.
sl@0: */
sl@0: EXPORT_C void CRemoteGc::BeginDraw(const TRect& aRect)
sl@0: 	{
sl@0: 	iDrawRect = aRect;
sl@0: 	iBoundingRect = TRect();
sl@0: 	iHasBitmapCommand = EFalse;
sl@0: 	iCommandBuffer->Prepare(aRect);
sl@0: 	}
sl@0:  
sl@0: /**
sl@0: Finishes the current redraw.
sl@0: This method should be called when drawing to the remotegc is complete.
sl@0: */
sl@0: EXPORT_C void CRemoteGc::EndDraw()
sl@0: 	{
sl@0: 	iBoundingRect.Intersection(iDrawRect);
sl@0: 	const TInt err = iCommandBuffer->Finish(iDrawRect, iBoundingRect, iHasBitmapCommand);
sl@0: 
sl@0: 	if(iCommandBufferObserver && !err)
sl@0: 		iCommandBufferObserver->CommandBufferUpdated(iDrawRect, iBoundingRect); 
sl@0:  	}
sl@0: 
sl@0: void CRemoteGc::Activate(RDrawableWindow &aDevice)
sl@0: 	{
sl@0: 	BeginDraw(aDevice.GetDrawRect());
sl@0: 	CWindowGc::Activate(aDevice);
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::Deactivate()
sl@0: 	{	
sl@0: 	CWindowGc::Deactivate();
sl@0: 	iFont = NULL;
sl@0: 	iShadowColor = KDefaultShadowColor;
sl@0: 	EndDraw();
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::Clear()
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandClear);
sl@0: 	iBoundingRect.BoundingRect(iDrawRect);
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::Clear(const TRect& aRect)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandClearRect);
sl@0: 	iCommandBuffer->Write<TRect>(aRect);
sl@0: 	iBoundingRect.BoundingRect(aRect);
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::CopyRect(const TPoint &anOffset, const TRect &aRect)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandCopyRect);
sl@0: 	iCommandBuffer->Write<TPoint>(anOffset);
sl@0: 	iCommandBuffer->Write<TRect>(aRect);
sl@0: 	iBoundingRect.BoundingRect(iDrawRect);
sl@0: 	}
sl@0: 
sl@0: void CRemoteGc::BitBlt(const TPoint &aPoint, const CFbsBitmap *aBitmap)
sl@0: 	{
sl@0: 	__ASSERT_DEBUG(aBitmap, User::Invariant());
sl@0: 	if(aBitmap)
sl@0: 		{
sl@0: 		iCommandBuffer->Write<TDrawCode>(ECommandBitBlt1);
sl@0: 		iCommandBuffer->Write<TPoint>(aPoint);
sl@0: 		iCommandBuffer->Write<TInt>(aBitmap->Handle());
sl@0: 		iBoundingRect.BoundingRect(TRect(aPoint, aBitmap->SizeInPixels()));
sl@0: 		iHasBitmapCommand = ETrue;
sl@0: 		}
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::BitBlt(const TPoint &aDestination, const CFbsBitmap *aBitmap, const TRect &aSource)
sl@0: 	{
sl@0: 	__ASSERT_DEBUG(aBitmap, User::Invariant());
sl@0: 	if(aBitmap)
sl@0: 		{	
sl@0: 		iCommandBuffer->Write<TDrawCode>(ECommandBitBlt2);
sl@0: 		iCommandBuffer->Write<TPoint>(aDestination);
sl@0: 		iCommandBuffer->Write<TInt>(aBitmap->Handle());
sl@0: 		iCommandBuffer->Write<TRect>(aSource);
sl@0: 		iBoundingRect.BoundingRect(TRect(aDestination, aSource.Size()));
sl@0: 		iHasBitmapCommand = ETrue;
sl@0: 		}
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::BitBltMasked(const TPoint& aPoint, const CFbsBitmap* aBitmap, const TRect& aSourceRect, const CFbsBitmap* aMaskBitmap, TBool aInvertMask)
sl@0: 	{
sl@0: 	__ASSERT_DEBUG(aBitmap && aMaskBitmap, User::Invariant());
sl@0: 	if(aBitmap && aMaskBitmap)
sl@0: 		{
sl@0: 		iCommandBuffer->Write<TDrawCode>(ECommandBitBltMasked);
sl@0: 		iCommandBuffer->Write<TPoint>(aPoint);
sl@0: 		iCommandBuffer->Write<TInt>(aBitmap->Handle());
sl@0: 		iCommandBuffer->Write<TRect>(aSourceRect);
sl@0: 		iCommandBuffer->Write<TInt>(aMaskBitmap->Handle());
sl@0: 		iCommandBuffer->Write<TBool>(aInvertMask);
sl@0: 		iBoundingRect.BoundingRect(TRect(aPoint, aSourceRect.Size()));
sl@0: 		iHasBitmapCommand = ETrue;
sl@0: 		}
sl@0: 	}
sl@0: 
sl@0: void CRemoteGc::BitBlt(const TPoint &aPoint, const CWsBitmap *aBitmap)
sl@0: 	{
sl@0: 	BitBlt(aPoint, reinterpret_cast<const CFbsBitmap*>(aBitmap));		
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::BitBlt(const TPoint &aDestination, const CWsBitmap *aBitmap, const TRect &aSource)
sl@0: 	{
sl@0: 	BitBlt(aDestination, reinterpret_cast<const CFbsBitmap*>(aBitmap), aSource);
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::BitBltMasked(const TPoint& aPoint, const CWsBitmap *aBitmap, const TRect& aSourceRect, const CWsBitmap *aMaskBitmap, TBool aInvertMask)
sl@0: 	{		
sl@0: 	BitBltMasked(aPoint, reinterpret_cast<const CFbsBitmap*>(aBitmap), aSourceRect, reinterpret_cast<const CFbsBitmap*>(aMaskBitmap), aInvertMask);
sl@0: 	}
sl@0: 
sl@0: void CRemoteGc::SetFaded(TBool /*aFaded*/)
sl@0: 	{
sl@0: 	// deprecated
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::SetFadingParameters(TUint8 /*aBlackMap*/,TUint8 /*aWhiteMap*/)
sl@0: 	{
sl@0: 	// deprecated
sl@0: 	}
sl@0: 	
sl@0: TInt CRemoteGc::AlphaBlendBitmaps(const TPoint& aDestPt, const CFbsBitmap* aSrcBmp, const TRect& aSrcRect, const CFbsBitmap* aAlphaBmp, const TPoint& aAlphaPt)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandAlphaBlendBitmaps);
sl@0: 	iCommandBuffer->Write<TPoint>(aDestPt);
sl@0: 	iCommandBuffer->Write<TInt>(aSrcBmp->Handle());
sl@0: 	iCommandBuffer->Write<TRect>(aSrcRect);
sl@0: 	iCommandBuffer->Write<TInt>(aAlphaBmp->Handle());
sl@0: 	iCommandBuffer->Write<TPoint>(aAlphaPt);
sl@0: 	iBoundingRect.BoundingRect(iDrawRect);
sl@0: 	iHasBitmapCommand = ETrue;
sl@0: 	return KErrNone;
sl@0: 	}
sl@0: 	
sl@0: TInt CRemoteGc::AlphaBlendBitmaps(const TPoint& aDestPt, const CWsBitmap* aSrcBmp, const TRect& aSrcRect, const CWsBitmap* aAlphaBmp, const TPoint& aAlphaPt)
sl@0: 	{
sl@0: 	return AlphaBlendBitmaps(aDestPt, reinterpret_cast<const CFbsBitmap*>(aSrcBmp), aSrcRect, reinterpret_cast<const CFbsBitmap*>(aAlphaBmp), aAlphaPt);
sl@0: 	}
sl@0: 
sl@0: void CRemoteGc::SetOrigin(const TPoint &aPoint)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandSetOrigin);
sl@0: 	iCommandBuffer->Write<TPoint>(aPoint);
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::SetDrawMode(TDrawMode aDrawingMode)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandSetDrawMode);
sl@0: 	iCommandBuffer->Write<TDrawMode>(aDrawingMode);		
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::SetClippingRect(const TRect& aRect)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandSetClippingRect);
sl@0: 	iCommandBuffer->Write<TRect>(aRect);		
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::CancelClippingRect()
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandCancelClippingRect);		
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::Reset()
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandReset);
sl@0: 	iFont = NULL;
sl@0: 	iShadowColor = KDefaultShadowColor;
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::UseFont(const CFont *aFont)
sl@0: 	{
sl@0: 	if (iFont!=(CFbsFont *)aFont)
sl@0: 		{
sl@0: 		iFont=(CFbsFont *)aFont;
sl@0: 		iCommandBuffer->Write<TDrawCode>(ECommandUseFont);
sl@0: 		iCommandBuffer->Write<TInt>(((CFbsFont*)aFont)->Handle());
sl@0: 		}
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::DiscardFont()
sl@0: 	{
sl@0: 	iFont = NULL;
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandDiscardFont);
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::SetUnderlineStyle(TFontUnderline aUnderlineStyle)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandSetUnderlineStyle);
sl@0: 	iCommandBuffer->Write<TFontUnderline>(aUnderlineStyle);
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::SetStrikethroughStyle(TFontStrikethrough aStrikethroughStyle)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandSetStrikethroughStyle);
sl@0: 	iCommandBuffer->Write<TFontStrikethrough>(aStrikethroughStyle);
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::SetWordJustification(TInt aExcessWidth, TInt aNumGaps)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandSetWordJustification);
sl@0: 	iCommandBuffer->Write<TInt>(aExcessWidth);
sl@0: 	iCommandBuffer->Write<TInt>(aNumGaps);
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::SetCharJustification(TInt aExcessWidth, TInt aNumChars)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandSetCharJustification);
sl@0: 	iCommandBuffer->Write<TInt>(aExcessWidth);
sl@0: 	iCommandBuffer->Write<TInt>(aNumChars);	
sl@0: 	}
sl@0: 
sl@0: void CRemoteGc::SetPenColor(const TRgb &aColor)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandSetPenColor);
sl@0: 	iCommandBuffer->Write<TRgb>(aColor);		
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::SetPenStyle(TPenStyle aPenStyle)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandSetPenStyle);
sl@0: 	iCommandBuffer->Write<TPenStyle>(aPenStyle);			
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::SetPenSize(const TSize& aSize)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandSetPenSize);
sl@0: 	iCommandBuffer->Write<TSize>(aSize);			
sl@0: 	}
sl@0: 
sl@0: void CRemoteGc::SetBrushColor(const TRgb &aColor)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandSetBrushColor);
sl@0: 	iCommandBuffer->Write<TRgb>(aColor);
sl@0: 	}
sl@0: 
sl@0: void CRemoteGc::SetBrushStyle(TBrushStyle aBrushStyle)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandSetBrushStyle);
sl@0: 	iCommandBuffer->Write<TBrushStyle>(aBrushStyle);		
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::SetBrushOrigin(const TPoint &aOrigin)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandSetBrushOrigin);
sl@0: 	iCommandBuffer->Write<TPoint>(aOrigin);			
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::UseBrushPattern(const CFbsBitmap *aDevice)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandUseBrushPattern);
sl@0: 	iCommandBuffer->Write<TInt>(aDevice->Handle());		
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::DiscardBrushPattern()
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandDiscardBrushPattern);	
sl@0: 	}
sl@0: 
sl@0: void CRemoteGc::MoveTo(const TPoint &aPoint)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandMoveTo);
sl@0: 	iCommandBuffer->Write<TPoint>(aPoint);
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::MoveBy(const TPoint &aPoint)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandMoveBy);
sl@0: 	iCommandBuffer->Write<TPoint>(aPoint);
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::Plot(const TPoint &aPoint)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandPlot);
sl@0: 	iCommandBuffer->Write<TPoint>(aPoint);
sl@0: 	iBoundingRect.BoundingRect(iDrawRect);
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::DrawArc(const TRect &aRect,const TPoint &aStart,const TPoint &aEnd)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandDrawArc);
sl@0: 	iCommandBuffer->Write<TRect>(aRect);
sl@0: 	iCommandBuffer->Write<TPoint>(aStart);
sl@0: 	iCommandBuffer->Write<TPoint>(aEnd);
sl@0: 	iBoundingRect.BoundingRect(iDrawRect);
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::DrawLine(const TPoint &aPoint1,const TPoint &aPoint2)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandDrawLine);
sl@0: 	iCommandBuffer->Write<TPoint>(aPoint1);
sl@0: 	iCommandBuffer->Write<TPoint>(aPoint2);
sl@0: 	iBoundingRect.BoundingRect(iDrawRect);
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::DrawLineTo(const TPoint &aPoint)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandDrawLineTo);
sl@0: 	iCommandBuffer->Write<TPoint>(aPoint);
sl@0: 	iBoundingRect.BoundingRect(iDrawRect);
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::DrawLineBy(const TPoint &aPoint)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandDrawLineBy);
sl@0: 	iCommandBuffer->Write<TPoint>(aPoint);
sl@0: 	iBoundingRect.BoundingRect(iDrawRect);
sl@0: 	}
sl@0: 
sl@0: void CRemoteGc::DrawPolyLine(const CArrayFix<TPoint> *aPointList)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandDrawPolyLine);
sl@0: 	iCommandBuffer->Write<TInt>(aPointList->Count()); // Write number of points
sl@0: 	
sl@0: 	const TInt count = aPointList->Count();
sl@0: 	for(TInt i = 0; i < count; i++)	
sl@0: 		{
sl@0: 		iCommandBuffer->Write<TPoint>(aPointList->At(i));
sl@0: 		}
sl@0: 	iBoundingRect.BoundingRect(iDrawRect);
sl@0: 	}
sl@0: 
sl@0: void CRemoteGc::DrawPolyLine(const TPoint* aPointList, TInt aNumPoints)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandDrawPolyLine);
sl@0: 	iCommandBuffer->Write<TInt>(aNumPoints); // Write number of points
sl@0: 	
sl@0: 	for(TInt i = 0; i < aNumPoints; i++)	
sl@0: 		{
sl@0: 		iCommandBuffer->Write<TPoint>(aPointList[i]);
sl@0: 		}
sl@0: 	iBoundingRect.BoundingRect(iDrawRect);
sl@0: 	}
sl@0: 
sl@0: void CRemoteGc::DrawPie(const TRect &aRect,const TPoint &aStart,const TPoint &aEnd)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandDrawPie);
sl@0: 	iCommandBuffer->Write<TRect>(aRect);
sl@0: 	iCommandBuffer->Write<TPoint>(aStart);
sl@0: 	iCommandBuffer->Write<TPoint>(aEnd);
sl@0: 	iBoundingRect.BoundingRect(iDrawRect);
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::DrawEllipse(const TRect &aRect)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandDrawEllipse);
sl@0: 	iCommandBuffer->Write<TRect>(aRect);
sl@0: 	iBoundingRect.BoundingRect(iDrawRect);
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::DrawRect(const TRect &aRect)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandDrawRect);
sl@0: 	iCommandBuffer->Write<TRect>(aRect);
sl@0: 	iBoundingRect.BoundingRect(iDrawRect);
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::DrawRoundRect(const TRect &aRect,const TSize &aEllipse)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandDrawRoundRect);
sl@0: 	iCommandBuffer->Write<TRect>(aRect);
sl@0: 	iCommandBuffer->Write<TSize>(aEllipse);
sl@0: 	iBoundingRect.BoundingRect(iDrawRect);
sl@0: 	}
sl@0: 
sl@0: TInt CRemoteGc::DrawPolygon(const CArrayFix<TPoint> *aPointList, TFillRule aFillRule)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandDrawPolygon);
sl@0: 	iCommandBuffer->Write<TInt>(aPointList->Count()); // Write number of points
sl@0: 	
sl@0: 	for(TInt i = 0; i < aPointList->Count(); i++)	
sl@0: 		{
sl@0: 		iCommandBuffer->Write<TPoint>(aPointList->At(i));
sl@0: 		}
sl@0: 		
sl@0: 	iCommandBuffer->Write<TFillRule>(aFillRule);
sl@0: 	iBoundingRect.BoundingRect(iDrawRect);
sl@0: 	return KErrNone;
sl@0: 	}
sl@0: 	
sl@0: TInt CRemoteGc::DrawPolygon(const TPoint* aPointList, TInt aNumPoints, TFillRule aFillRule)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandDrawPolygon);
sl@0: 	iCommandBuffer->Write<TInt>(aNumPoints); // Write number of points
sl@0: 	
sl@0: 	for(TInt i = 0; i < aNumPoints; i++)	
sl@0: 		{
sl@0: 		iCommandBuffer->Write<TPoint>(aPointList[i]);
sl@0: 		}
sl@0: 		
sl@0: 	iCommandBuffer->Write<TFillRule>(aFillRule);
sl@0: 	iBoundingRect.BoundingRect(iDrawRect);
sl@0: 	return KErrNone;
sl@0: 	}
sl@0: 
sl@0: void CRemoteGc::DrawBitmap(const TPoint &aTopLeft, const CFbsBitmap *aDevice)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandDrawBitmap1);
sl@0: 	iCommandBuffer->Write<TPoint>(aTopLeft);
sl@0: 	iCommandBuffer->Write<TInt>(aDevice->Handle());
sl@0: 	iBoundingRect.BoundingRect(TRect(aTopLeft, aDevice->SizeInPixels()));
sl@0: 	iHasBitmapCommand = ETrue;
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::DrawBitmap(const TRect &aDestRect, const CFbsBitmap *aDevice)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandDrawBitmap2);
sl@0: 	iCommandBuffer->Write<TRect>(aDestRect);
sl@0: 	iCommandBuffer->Write<TInt>(aDevice->Handle());
sl@0: 	iBoundingRect.BoundingRect(aDestRect);
sl@0: 	iHasBitmapCommand = ETrue;
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::DrawBitmap(const TRect &aDestRect, const CFbsBitmap *aDevice, const TRect &aSourceRect)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandDrawBitmap3);
sl@0: 	iCommandBuffer->Write<TRect>(aDestRect);
sl@0: 	iCommandBuffer->Write<TInt>(aDevice->Handle());
sl@0: 	iCommandBuffer->Write<TRect>(aSourceRect);
sl@0: 	iBoundingRect.BoundingRect(aDestRect);
sl@0: 	iHasBitmapCommand = ETrue;
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::DrawBitmapMasked(const TRect& aDestRect, const CFbsBitmap* aBitmap, const TRect& aSourceRect, const CFbsBitmap* aMaskBitmap, TBool aInvertMask)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandDrawBitmapMasked);
sl@0: 	iCommandBuffer->Write<TRect>(aDestRect);
sl@0: 	iCommandBuffer->Write<TInt>(aBitmap->Handle());
sl@0: 	iCommandBuffer->Write<TRect>(aSourceRect);
sl@0: 	iCommandBuffer->Write<TInt>(aMaskBitmap->Handle());
sl@0: 	iCommandBuffer->Write<TBool>(aInvertMask);
sl@0: 	iBoundingRect.BoundingRect(aDestRect);
sl@0: 	iHasBitmapCommand = ETrue;
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::DrawBitmapMasked(const TRect& aDestRect, const CWsBitmap* aBitmap, const TRect& aSourceRect, const CWsBitmap* aMaskBitmap, TBool aInvertMask)
sl@0: 	{
sl@0: 	DrawBitmapMasked(aDestRect, reinterpret_cast<const CFbsBitmap*>(aBitmap), aSourceRect, reinterpret_cast<const CFbsBitmap*>(aMaskBitmap), aInvertMask);
sl@0: 	}
sl@0: 
sl@0: void CRemoteGc::DrawText(const TDesC &aBuf,const TPoint &aPos)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandDrawText1);
sl@0: 	iCommandBuffer->WriteText(aBuf);
sl@0: 	iCommandBuffer->Write<TPoint>(aPos);
sl@0: 	iBoundingRect.BoundingRect(iDrawRect);
sl@0: 	}
sl@0: 
sl@0: void CRemoteGc::DrawText(const TDesC &aBuf, const TRect &aBox, TInt aBaselineOffset, TTextAlign aHoriz, TInt aLeftMrg)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandDrawText2);
sl@0: 	iCommandBuffer->WriteText(aBuf);
sl@0: 	iCommandBuffer->Write<TRect>(aBox);
sl@0: 	iCommandBuffer->Write<TInt>(aBaselineOffset);
sl@0: 	iCommandBuffer->Write<TTextAlign>(aHoriz);
sl@0: 	iCommandBuffer->Write<TInt>(aLeftMrg);
sl@0: 	iBoundingRect.BoundingRect(aBox);
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::DrawText(const TDesC& aText, const TPoint& aPosition, const TDrawTextParam& aParam)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandDrawText3);
sl@0: 	iCommandBuffer->WriteText(aText);
sl@0: 	iCommandBuffer->Write<TPoint>(aPosition);
sl@0: 	iCommandBuffer->Write<TDrawTextParam>(aParam);
sl@0: 	iBoundingRect.BoundingRect(iDrawRect);
sl@0: 	}
sl@0: 
sl@0: void CRemoteGc::MapColors(const TRect& /*aRect*/, const TRgb* /*aColors*/, TInt /*aNumPairs*/, TBool /*aMapForwards*/)
sl@0: 	{
sl@0: 	//deprecated
sl@0: 	}
sl@0: 
sl@0: TInt CRemoteGc::SetClippingRegion(const TRegion &aRegion)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandSetClippingRegion);
sl@0: 	
sl@0: 	const TInt count = aRegion.Count();
sl@0: 	iCommandBuffer->Write<TInt>(count);
sl@0: 	
sl@0: 	for(TInt i = 0; i < count; i++)	
sl@0: 		{
sl@0: 		iCommandBuffer->Write<TRect>(aRegion.RectangleList()[i]);
sl@0: 		}
sl@0: 		
sl@0: 	return KErrNone;
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::CancelClippingRegion()
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandCancelClippingRegion);
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::DrawTextVertical(const TDesC& aText, const TPoint& aPos, TBool aUp)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandDrawTextVertical1);
sl@0: 	iCommandBuffer->WriteText(aText);
sl@0: 	iCommandBuffer->Write<TPoint>(aPos);	
sl@0: 	iCommandBuffer->Write<TBool>(aUp);
sl@0: 	iBoundingRect.BoundingRect(iDrawRect);
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::DrawTextVertical(const TDesC& aText, const TRect& aBox, TInt aBaselineOffset, TBool aUp, TTextAlign aVert, TInt aMargin)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandDrawTextVertical2);
sl@0: 	iCommandBuffer->WriteText(aText);
sl@0: 	iCommandBuffer->Write<TRect>(aBox);
sl@0: 	iCommandBuffer->Write<TInt>(aBaselineOffset);
sl@0: 	iCommandBuffer->Write<TBool>(aUp);
sl@0: 	iCommandBuffer->Write<TTextAlign>(aVert);
sl@0: 	iCommandBuffer->Write<TInt>(aMargin);
sl@0: 	iBoundingRect.BoundingRect(aBox);
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::DrawWsGraphic(const TWsGraphicId& aId,const TRect& aDestRect)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandDrawWsGraphic1);
sl@0: 	iCommandBuffer->Write<TInt>(aId.IsUid()? aId.Uid().iUid: aId.Id());
sl@0: 	iCommandBuffer->Write<TBool>(aId.IsUid());
sl@0: 	iCommandBuffer->Write<TRect>(aDestRect);
sl@0: 	iBoundingRect.BoundingRect(aDestRect);
sl@0: 	}
sl@0: 	
sl@0: void CRemoteGc::DrawWsGraphic(const TWsGraphicId& aId,const TRect& aDestRect,const TDesC8& aData)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandDrawWsGraphic2);
sl@0: 	iCommandBuffer->Write<TInt>(aId.IsUid()? aId.Uid().iUid: aId.Id());
sl@0: 	iCommandBuffer->Write<TBool>(aId.IsUid());
sl@0: 	iCommandBuffer->Write<TRect>(aDestRect);
sl@0: 	iCommandBuffer->WriteText(aData);
sl@0: 	iBoundingRect.BoundingRect(aDestRect);
sl@0: 	}
sl@0: 
sl@0: void CRemoteGc::SetDitherOrigin(const TPoint& /*aPoint*/) //deprecated
sl@0: 	{
sl@0: 	// do nothing, does not apply to CBitmapContext which CCommandBuffer is using
sl@0: 	}
sl@0: 
sl@0: void CRemoteGc::SetOpaque(TBool /*aDrawOpaque*/)	// deprecated
sl@0: 	{
sl@0: 	// overrides to prevent calling CWindowGc::SetOpaque, it's specific to how wserv blends windows content
sl@0: 	}
sl@0: 
sl@0: TInt CRemoteGc::APIExtension(TUid aUid, TAny*& aOutput, TAny* aInput)
sl@0: 	{
sl@0: 	if (aUid == KGetUnderlineMetrics)
sl@0: 		{		
sl@0: 		return APIExGetUnderlineMetrics(aOutput);	
sl@0: 		}
sl@0: 	else if (aUid == KSetShadowColor)
sl@0: 		{
sl@0: 		return APIExSetShadowColor(aInput);
sl@0: 		}
sl@0: 	else if (aUid == KDrawTextInContextUid)
sl@0: 		{
sl@0: 		TDrawTextInContextInternal* contextParam = (TDrawTextInContextInternal*)aInput;
sl@0: 		return APIExDrawText(contextParam->iText, &contextParam->iParam, contextParam->iPosition);
sl@0: 		}
sl@0: 	else if (aUid == KDrawBoxTextInContextUid)
sl@0: 		{
sl@0: 		TDrawTextInContextInternal* contextParam = (TDrawTextInContextInternal*)aInput;
sl@0: 		return APIExDrawText(contextParam->iText,&contextParam->iParam,contextParam->iBox,contextParam->iBaselineOffset,contextParam->iAlign,contextParam->iMargin);
sl@0: 		}
sl@0: 	else if (aUid == KDrawTextInContextVerticalUid)
sl@0: 		{
sl@0: 		TDrawTextInContextInternal* contextParam = (TDrawTextInContextInternal*)aInput;
sl@0: 		return APIExDrawTextVertical(contextParam->iText, &contextParam->iParam, contextParam->iPosition,contextParam->iUp);
sl@0: 		}
sl@0: 	else if (aUid == KDrawBoxTextInContextVerticalUid)
sl@0: 		{
sl@0: 		TDrawTextInContextInternal* contextParam = (TDrawTextInContextInternal*)aInput;
sl@0: 		return APIExDrawTextVertical(contextParam->iText,&contextParam->iParam,contextParam->iBox,contextParam->iBaselineOffset,contextParam->iUp,contextParam->iAlign,contextParam->iMargin);
sl@0: 		}
sl@0: 	else if (aUid == KApiExtensionInterfaceUid)
sl@0: 		{
sl@0: 		return APIExInterface(aOutput, *static_cast<TUid*>(aInput));
sl@0: 		}
sl@0: 	/* Future cases may be placed here later.*/
sl@0: 	else
sl@0: 		{
sl@0: 		return CBitmapContext::APIExtension(aUid, aOutput, aInput);
sl@0: 		}
sl@0: 	}
sl@0: 
sl@0: TInt CRemoteGc::APIExGetUnderlineMetrics(TAny*& aOutput)
sl@0: 	{
sl@0: 	const TInt width = Max(iFont->HeightInPixels() / 10,1);
sl@0: 	TTwoTInt* ptr = (TTwoTInt*)aOutput;
sl@0: 	ptr->iTop = 1 + width / 2;
sl@0: 	ptr->iBottom = (ptr->iTop) + width;
sl@0: 	return KErrNone;
sl@0: 	}
sl@0: 
sl@0: TInt CRemoteGc::APIExSetShadowColor(TAny* aShadowColor)
sl@0: 	{
sl@0: 	const TRgb shadowColor = *(reinterpret_cast<TRgb*> (aShadowColor));
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandSetShadowColor);
sl@0: 	iCommandBuffer->Write<TRgb>(shadowColor);
sl@0: 	iShadowColor = shadowColor;
sl@0: 	return KErrNone;
sl@0: 	}
sl@0: 
sl@0: TInt CRemoteGc::APIExGetShadowColor(TAny*& aOutput)
sl@0: 	{
sl@0: 	TRgb* ptr = (TRgb*)aOutput;
sl@0: 	ptr->SetInternal(iShadowColor.Internal());
sl@0: 	return KErrNone;
sl@0: 	}
sl@0: 
sl@0: TInt CRemoteGc::APIExDrawText(const TDesC &aBuf,const TTextParameters* aParam,const TPoint &aPos)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandDrawText4);
sl@0: 	iCommandBuffer->WriteText(aBuf);
sl@0: 	iCommandBuffer->Write<TTextParameters>(*aParam);
sl@0: 	iCommandBuffer->Write<TPoint>(aPos);
sl@0: 	iBoundingRect.BoundingRect(iDrawRect);
sl@0: 	return KErrNone;
sl@0: 	}
sl@0: 
sl@0: TInt CRemoteGc::APIExDrawText(const TDesC &aBuf,const TTextParameters* aParam,const TRect &aBox,TInt aBaselineOffset,TTextAlign aHoriz,TInt aLeftMrg)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandDrawText5);
sl@0: 	iCommandBuffer->WriteText(aBuf);
sl@0: 	iCommandBuffer->Write<TTextParameters>(*aParam);
sl@0: 	iCommandBuffer->Write<TRect>(aBox);
sl@0: 	iCommandBuffer->Write<TInt>(aBaselineOffset);
sl@0: 	iCommandBuffer->Write<TTextAlign>(aHoriz);
sl@0: 	iCommandBuffer->Write<TInt>(aLeftMrg);
sl@0: 	iBoundingRect.BoundingRect(aBox);
sl@0: 	return KErrNone;
sl@0: 	}
sl@0: 
sl@0: TInt CRemoteGc::APIExDrawTextVertical(const TDesC& aText,const TTextParameters* aParam,const TPoint& aPos,TBool aUp)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandDrawTextVertical3);
sl@0: 	iCommandBuffer->WriteText(aText);
sl@0: 	iCommandBuffer->Write<TTextParameters>(*aParam);
sl@0: 	iCommandBuffer->Write<TPoint>(aPos);	
sl@0: 	iCommandBuffer->Write<TBool>(aUp);
sl@0: 	iBoundingRect.BoundingRect(iDrawRect);
sl@0: 	return KErrNone;
sl@0: 	}
sl@0: 
sl@0: TInt CRemoteGc::APIExDrawTextVertical(const TDesC& aText,const TTextParameters* aParam,const TRect& aBox,TInt aBaselineOffset,TBool aUp,TTextAlign aVert,TInt aMargin)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandDrawTextVertical4);
sl@0: 	iCommandBuffer->WriteText(aText);
sl@0: 	iCommandBuffer->Write<TTextParameters>(*aParam);
sl@0: 	iCommandBuffer->Write<TRect>(aBox);
sl@0: 	iCommandBuffer->Write<TInt>(aBaselineOffset);
sl@0: 	iCommandBuffer->Write<TBool>(aUp);
sl@0: 	iCommandBuffer->Write<TTextAlign>(aVert);
sl@0: 	iCommandBuffer->Write<TInt>(aMargin);
sl@0: 	iBoundingRect.BoundingRect(aBox);
sl@0: 	return KErrNone;
sl@0: 	}
sl@0: 
sl@0: TInt CRemoteGc::APIExInterface(TAny*& aInterface, TUid aInterfaceId)
sl@0: 	{
sl@0: 	if(aInterfaceId == KMWsDrawResourceInterfaceUid)
sl@0: 		{
sl@0: 		aInterface = static_cast<MWsDrawResource*>(iRemoteGcPimpl);
sl@0: 		return KErrNone;
sl@0: 		}
sl@0: 	return KErrNotSupported;
sl@0: 	}
sl@0: 
sl@0: void CRemoteGc::DrawResource(const TPoint& aPos, const RWsDrawableSource& aSource, CWindowGc::TGraphicsRotation aRotation)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandDrawResourceToPos);
sl@0: 	iCommandBuffer->Write<TSgDrawableId>(aSource.DrawableId());
sl@0: 	iCommandBuffer->Write<TInt>(aSource.ScreenNumber());
sl@0: 	iCommandBuffer->Write<TPoint>(aPos);
sl@0: 	iCommandBuffer->Write<CWindowGc::TGraphicsRotation>(aRotation);
sl@0: 	iBoundingRect.BoundingRect(iDrawRect);
sl@0: 	iHasBitmapCommand = ETrue;
sl@0: 	}
sl@0: 
sl@0: void CRemoteGc::DrawResource(const TRect& aDestRect, const RWsDrawableSource& aSource, CWindowGc::TGraphicsRotation aRotation)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandDrawResourceToRect);
sl@0: 	iCommandBuffer->Write<TSgDrawableId>(aSource.DrawableId());
sl@0: 	iCommandBuffer->Write<TInt>(aSource.ScreenNumber());
sl@0: 	iCommandBuffer->Write<TRect>(aDestRect);
sl@0: 	iCommandBuffer->Write<CWindowGc::TGraphicsRotation>(aRotation);
sl@0: 	iBoundingRect.BoundingRect(aDestRect);
sl@0: 	iHasBitmapCommand = ETrue;
sl@0: 	}
sl@0: 
sl@0: void CRemoteGc::DrawResource(const TRect& aDestRect, const RWsDrawableSource& aSource, const TRect& aSrcRect, CWindowGc::TGraphicsRotation aRotation)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandDrawResourceFromRectToRect);
sl@0: 	iCommandBuffer->Write<TSgDrawableId>(aSource.DrawableId());
sl@0: 	iCommandBuffer->Write<TInt>(aSource.ScreenNumber());
sl@0: 	iCommandBuffer->Write<TRect>(aDestRect);
sl@0: 	iCommandBuffer->Write<TRect>(aSrcRect);
sl@0: 	iCommandBuffer->Write<CWindowGc::TGraphicsRotation>(aRotation);
sl@0: 	iBoundingRect.BoundingRect(aDestRect);
sl@0: 	iHasBitmapCommand = ETrue;
sl@0: 	}
sl@0: 
sl@0: void CRemoteGc::DrawResource(const TRect& aDestRect, const RWsDrawableSource& aSource, const TDesC8& aParam)
sl@0: 	{
sl@0: 	iCommandBuffer->Write<TDrawCode>(ECommandDrawResourceWithData);
sl@0: 	iCommandBuffer->Write<TSgDrawableId>(aSource.DrawableId());
sl@0: 	iCommandBuffer->Write<TInt>(aSource.ScreenNumber());
sl@0: 	iCommandBuffer->Write<TRect>(aDestRect);
sl@0: 	iCommandBuffer->WriteText(aParam);
sl@0: 	iBoundingRect.BoundingRect(aDestRect);
sl@0: 	iHasBitmapCommand = ETrue;
sl@0: 	}
sl@0: