diff -r 000000000000 -r 5d03bc08d59c windowing/windowserver/nonnga/remotegc/RemoteGc.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/windowing/windowserver/nonnga/remotegc/RemoteGc.cpp Tue Feb 02 01:47:50 2010 +0200 @@ -0,0 +1,653 @@ +// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// + +#include "RemoteGc.h" +#include "RemoteGcUtils.h" +#include "CommandBuffer.h" +#include + +/** +Creates a new remotegc. + +@param aDevice The windowserver screendevice to use. +@param aCommandBufferObserver Pointer to a commandbufferobserver. +@return A pointer to a new instance of CRemoteGc. +*/ +EXPORT_C CRemoteGc* CRemoteGc::NewL(CWsScreenDevice* aDevice) + { + CRemoteGc* remoteGc = new (ELeave) CRemoteGc(aDevice); + CleanupStack::PushL(remoteGc); + remoteGc->ConstructL(); + CleanupStack::Pop(remoteGc); + return remoteGc; + } + +CRemoteGc::CRemoteGc(CWsScreenDevice* aDevice) : CWindowGc(aDevice), iCommandBufferObserver(NULL) + { + } + +EXPORT_C CRemoteGc::~CRemoteGc() + { + delete iCommandBuffer; + } + +void CRemoteGc::ConstructL() + { + User::LeaveIfError(CWindowGc::Construct()); + iCommandBuffer = CCommandBuffer::NewL(); + } + +EXPORT_C void CRemoteGc::SetCommandBufferObserver(MCommandBufferObserver* aCommandBufferObserver) + { + iCommandBufferObserver = aCommandBufferObserver; + } + +/** +Resets the commandbuffer. +*/ +EXPORT_C void CRemoteGc::ResetCommandBuffer() + { + iCommandBuffer->Reset(); + } + +/** +Externalizes commandbuffer sections into a format which makes it possible to send over IPC. +If ETrue is sent as a parameter to this method, the entire commandbuffer will be externalized, +otherwise only sections which has not been externalized before will be externalized. Note that if only +not externalized sections is asked for, the flag will be reset on that section so next call +to ExternalizeLC will not externalize that section. + +@param aMsgBuf A buffer used to externalize the commandbuffer to. +@param aEntireBuffer If ETrue, the entire commandbuffer will be externalized, otherwise only sections which has not been externalized before. +*/ +EXPORT_C void CRemoteGc::ExternalizeL(RWsGraphicMsgBuf& aMsgBuf, TBool aEntireBuffer) + { + return iCommandBuffer->ExternalizeL(aMsgBuf, aEntireBuffer); + } + +/** +Prepares the remotegc to be drawn to. + +@param aRect The rect to be drawn. +*/ +EXPORT_C void CRemoteGc::BeginDraw(const TRect& aRect) + { + iDrawRect = aRect; + iBoundingRect = TRect(); + iHasBitmapCommand = EFalse; + iCommandBuffer->Prepare(aRect); + } + +/** +Finishes the current redraw. +This method should be called when drawing to the remotegc is complete. +*/ +EXPORT_C void CRemoteGc::EndDraw() + { + iBoundingRect.Intersection(iDrawRect); + const TInt err = iCommandBuffer->Finish(iDrawRect, iBoundingRect, iHasBitmapCommand); + + if(iCommandBufferObserver && !err) + iCommandBufferObserver->CommandBufferUpdated(iDrawRect, iBoundingRect); + } + +void CRemoteGc::Activate(RDrawableWindow &aDevice) + { + BeginDraw(aDevice.GetDrawRect()); + CWindowGc::Activate(aDevice); + } + +void CRemoteGc::Deactivate() + { + CWindowGc::Deactivate(); + EndDraw(); + } + +void CRemoteGc::Clear() + { + iCommandBuffer->Write(ECommandClear); + iBoundingRect.BoundingRect(iDrawRect); + } + +void CRemoteGc::Clear(const TRect& aRect) + { + iCommandBuffer->Write(ECommandClearRect); + iCommandBuffer->Write(aRect); + iBoundingRect.BoundingRect(aRect); + } + +void CRemoteGc::CopyRect(const TPoint &anOffset, const TRect &aRect) + { + iCommandBuffer->Write(ECommandCopyRect); + iCommandBuffer->Write(anOffset); + iCommandBuffer->Write(aRect); + iBoundingRect.BoundingRect(iDrawRect); + } + +void CRemoteGc::BitBlt(const TPoint &aPoint, const CFbsBitmap *aBitmap) + { + __ASSERT_DEBUG(aBitmap, User::Invariant()); + if(aBitmap) + { + iCommandBuffer->Write(ECommandBitBlt1); + iCommandBuffer->Write(aPoint); + iCommandBuffer->Write(aBitmap->Handle()); + iBoundingRect.BoundingRect(TRect(aPoint, aBitmap->SizeInPixels())); + iHasBitmapCommand = ETrue; + } + } + +void CRemoteGc::BitBlt(const TPoint &aDestination, const CFbsBitmap *aBitmap, const TRect &aSource) + { + __ASSERT_DEBUG(aBitmap, User::Invariant()); + if(aBitmap) + { + iCommandBuffer->Write(ECommandBitBlt2); + iCommandBuffer->Write(aDestination); + iCommandBuffer->Write(aBitmap->Handle()); + iCommandBuffer->Write(aSource); + iBoundingRect.BoundingRect(TRect(aDestination, aSource.Size())); + iHasBitmapCommand = ETrue; + } + } + +void CRemoteGc::BitBltMasked(const TPoint& aPoint, const CFbsBitmap* aBitmap, const TRect& aSourceRect, const CFbsBitmap* aMaskBitmap, TBool aInvertMask) + { + __ASSERT_DEBUG(aBitmap && aMaskBitmap, User::Invariant()); + if(aBitmap && aMaskBitmap) + { + iCommandBuffer->Write(ECommandBitBltMasked); + iCommandBuffer->Write(aPoint); + iCommandBuffer->Write(aBitmap->Handle()); + iCommandBuffer->Write(aSourceRect); + iCommandBuffer->Write(aMaskBitmap->Handle()); + iCommandBuffer->Write(aInvertMask); + iBoundingRect.BoundingRect(TRect(aPoint, aSourceRect.Size())); + iHasBitmapCommand = ETrue; + } + } + +void CRemoteGc::BitBlt(const TPoint &aPoint, const CWsBitmap *aBitmap) + { + BitBlt(aPoint, reinterpret_cast(aBitmap)); + } + +void CRemoteGc::BitBlt(const TPoint &aDestination, const CWsBitmap *aBitmap, const TRect &aSource) + { + BitBlt(aDestination, reinterpret_cast(aBitmap), aSource); + } + +void CRemoteGc::BitBltMasked(const TPoint& aPoint, const CWsBitmap *aBitmap, const TRect& aSourceRect, const CWsBitmap *aMaskBitmap, TBool aInvertMask) + { + BitBltMasked(aPoint, reinterpret_cast(aBitmap), aSourceRect, reinterpret_cast(aMaskBitmap), aInvertMask); + } + +void CRemoteGc::SetFaded(TBool aFaded) + { + iCommandBuffer->Write(ECommandSetFaded); + iCommandBuffer->Write(aFaded); + } + +void CRemoteGc::SetFadingParameters(TUint8 aBlackMap,TUint8 aWhiteMap) + { + iCommandBuffer->Write(ECommandSetFadingParameters); + iCommandBuffer->Write(aBlackMap); + iCommandBuffer->Write(aWhiteMap); + } + +TInt CRemoteGc::AlphaBlendBitmaps(const TPoint& aDestPt, const CFbsBitmap* aSrcBmp, const TRect& aSrcRect, const CFbsBitmap* aAlphaBmp, const TPoint& aAlphaPt) + { + iCommandBuffer->Write(ECommandAlphaBlendBitmaps); + iCommandBuffer->Write(aDestPt); + iCommandBuffer->Write(aSrcBmp->Handle()); + iCommandBuffer->Write(aSrcRect); + iCommandBuffer->Write(aAlphaBmp->Handle()); + iCommandBuffer->Write(aAlphaPt); + iBoundingRect.BoundingRect(iDrawRect); + iHasBitmapCommand = ETrue; + return KErrNone; + } + +TInt CRemoteGc::AlphaBlendBitmaps(const TPoint& aDestPt, const CWsBitmap* aSrcBmp, const TRect& aSrcRect, const CWsBitmap* aAlphaBmp, const TPoint& aAlphaPt) + { + return AlphaBlendBitmaps(aDestPt, reinterpret_cast(aSrcBmp), aSrcRect, reinterpret_cast(aAlphaBmp), aAlphaPt); + } + +void CRemoteGc::SetOrigin(const TPoint &aPoint) + { + iCommandBuffer->Write(ECommandSetOrigin); + iCommandBuffer->Write(aPoint); + } + +void CRemoteGc::SetDrawMode(TDrawMode aDrawingMode) + { + iCommandBuffer->Write(ECommandSetDrawMode); + iCommandBuffer->Write(aDrawingMode); + } + +void CRemoteGc::SetClippingRect(const TRect& aRect) + { + iCommandBuffer->Write(ECommandSetClippingRect); + iCommandBuffer->Write(aRect); + } + +void CRemoteGc::CancelClippingRect() + { + iCommandBuffer->Write(ECommandCancelClippingRect); + } + +void CRemoteGc::Reset() + { + iCommandBuffer->Write(ECommandReset); + } + +void CRemoteGc::UseFont(const CFont *aFont) + { + iCommandBuffer->Write(ECommandUseFont); + iCommandBuffer->Write(((CFbsFont*)aFont)->Handle()); + } + +void CRemoteGc::DiscardFont() + { + iCommandBuffer->Write(ECommandDiscardFont); + } + +void CRemoteGc::SetUnderlineStyle(TFontUnderline aUnderlineStyle) + { + iCommandBuffer->Write(ECommandSetUnderlineStyle); + iCommandBuffer->Write(aUnderlineStyle); + } + +void CRemoteGc::SetStrikethroughStyle(TFontStrikethrough aStrikethroughStyle) + { + iCommandBuffer->Write(ECommandSetStrikethroughStyle); + iCommandBuffer->Write(aStrikethroughStyle); + } + +void CRemoteGc::SetWordJustification(TInt aExcessWidth, TInt aNumGaps) + { + iCommandBuffer->Write(ECommandSetWordJustification); + iCommandBuffer->Write(aExcessWidth); + iCommandBuffer->Write(aNumGaps); + } + +void CRemoteGc::SetCharJustification(TInt aExcessWidth, TInt aNumChars) + { + iCommandBuffer->Write(ECommandSetCharJustification); + iCommandBuffer->Write(aExcessWidth); + iCommandBuffer->Write(aNumChars); + } + +void CRemoteGc::SetPenColor(const TRgb &aColor) + { + iCommandBuffer->Write(ECommandSetPenColor); + iCommandBuffer->Write(aColor); + } + +void CRemoteGc::SetPenStyle(TPenStyle aPenStyle) + { + iCommandBuffer->Write(ECommandSetPenStyle); + iCommandBuffer->Write(aPenStyle); + } + +void CRemoteGc::SetPenSize(const TSize& aSize) + { + iCommandBuffer->Write(ECommandSetPenSize); + iCommandBuffer->Write(aSize); + } + +void CRemoteGc::SetBrushColor(const TRgb &aColor) + { + iCommandBuffer->Write(ECommandSetBrushColor); + iCommandBuffer->Write(aColor); + } + +void CRemoteGc::SetBrushStyle(TBrushStyle aBrushStyle) + { + iCommandBuffer->Write(ECommandSetBrushStyle); + iCommandBuffer->Write(aBrushStyle); + } + +void CRemoteGc::SetBrushOrigin(const TPoint &aOrigin) + { + iCommandBuffer->Write(ECommandSetBrushOrigin); + iCommandBuffer->Write(aOrigin); + } + +void CRemoteGc::UseBrushPattern(const CFbsBitmap *aDevice) + { + iCommandBuffer->Write(ECommandUseBrushPattern); + iCommandBuffer->Write(aDevice->Handle()); + } + +void CRemoteGc::DiscardBrushPattern() + { + iCommandBuffer->Write(ECommandDiscardBrushPattern); + } + +void CRemoteGc::MoveTo(const TPoint &aPoint) + { + iCommandBuffer->Write(ECommandMoveTo); + iCommandBuffer->Write(aPoint); + } + +void CRemoteGc::MoveBy(const TPoint &aPoint) + { + iCommandBuffer->Write(ECommandMoveBy); + iCommandBuffer->Write(aPoint); + } + +void CRemoteGc::Plot(const TPoint &aPoint) + { + iCommandBuffer->Write(ECommandPlot); + iCommandBuffer->Write(aPoint); + iBoundingRect.BoundingRect(iDrawRect); + } + +void CRemoteGc::DrawArc(const TRect &aRect,const TPoint &aStart,const TPoint &aEnd) + { + iCommandBuffer->Write(ECommandDrawArc); + iCommandBuffer->Write(aRect); + iCommandBuffer->Write(aStart); + iCommandBuffer->Write(aEnd); + iBoundingRect.BoundingRect(iDrawRect); + } + +void CRemoteGc::DrawLine(const TPoint &aPoint1,const TPoint &aPoint2) + { + iCommandBuffer->Write(ECommandDrawLine); + iCommandBuffer->Write(aPoint1); + iCommandBuffer->Write(aPoint2); + iBoundingRect.BoundingRect(iDrawRect); + } + +void CRemoteGc::DrawLineTo(const TPoint &aPoint) + { + iCommandBuffer->Write(ECommandDrawLineTo); + iCommandBuffer->Write(aPoint); + iBoundingRect.BoundingRect(iDrawRect); + } + +void CRemoteGc::DrawLineBy(const TPoint &aPoint) + { + iCommandBuffer->Write(ECommandDrawLineBy); + iCommandBuffer->Write(aPoint); + iBoundingRect.BoundingRect(iDrawRect); + } + +void CRemoteGc::DrawPolyLine(const CArrayFix *aPointList) + { + iCommandBuffer->Write(ECommandDrawPolyLine); + iCommandBuffer->Write(aPointList->Count()); // Write number of points + + const TInt count = aPointList->Count(); + for(TInt i = 0; i < count; i++) + { + iCommandBuffer->Write(aPointList->At(i)); + } + iBoundingRect.BoundingRect(iDrawRect); + } + +void CRemoteGc::DrawPolyLine(const TPoint* aPointList, TInt aNumPoints) + { + iCommandBuffer->Write(ECommandDrawPolyLine); + iCommandBuffer->Write(aNumPoints); // Write number of points + + for(TInt i = 0; i < aNumPoints; i++) + { + iCommandBuffer->Write(aPointList[i]); + } + iBoundingRect.BoundingRect(iDrawRect); + } + +void CRemoteGc::DrawPie(const TRect &aRect,const TPoint &aStart,const TPoint &aEnd) + { + iCommandBuffer->Write(ECommandDrawPie); + iCommandBuffer->Write(aRect); + iCommandBuffer->Write(aStart); + iCommandBuffer->Write(aEnd); + iBoundingRect.BoundingRect(iDrawRect); + } + +void CRemoteGc::DrawEllipse(const TRect &aRect) + { + iCommandBuffer->Write(ECommandDrawEllipse); + iCommandBuffer->Write(aRect); + iBoundingRect.BoundingRect(iDrawRect); + } + +void CRemoteGc::DrawRect(const TRect &aRect) + { + iCommandBuffer->Write(ECommandDrawRect); + iCommandBuffer->Write(aRect); + iBoundingRect.BoundingRect(iDrawRect); + } + +void CRemoteGc::DrawRoundRect(const TRect &aRect,const TSize &aEllipse) + { + iCommandBuffer->Write(ECommandDrawRoundRect); + iCommandBuffer->Write(aRect); + iCommandBuffer->Write(aEllipse); + iBoundingRect.BoundingRect(iDrawRect); + } + +TInt CRemoteGc::DrawPolygon(const CArrayFix *aPointList, TFillRule aFillRule) + { + iCommandBuffer->Write(ECommandDrawPolygon); + iCommandBuffer->Write(aPointList->Count()); // Write number of points + + for(TInt i = 0; i < aPointList->Count(); i++) + { + iCommandBuffer->Write(aPointList->At(i)); + } + + iCommandBuffer->Write(aFillRule); + iBoundingRect.BoundingRect(iDrawRect); + return KErrNone; + } + +TInt CRemoteGc::DrawPolygon(const TPoint* aPointList, TInt aNumPoints, TFillRule aFillRule) + { + iCommandBuffer->Write(ECommandDrawPolygon); + iCommandBuffer->Write(aNumPoints); // Write number of points + + for(TInt i = 0; i < aNumPoints; i++) + { + iCommandBuffer->Write(aPointList[i]); + } + + iCommandBuffer->Write(aFillRule); + iBoundingRect.BoundingRect(iDrawRect); + return KErrNone; + } + +void CRemoteGc::DrawBitmap(const TPoint &aTopLeft, const CFbsBitmap *aDevice) + { + iCommandBuffer->Write(ECommandDrawBitmap1); + iCommandBuffer->Write(aTopLeft); + iCommandBuffer->Write(aDevice->Handle()); + iBoundingRect.BoundingRect(TRect(aTopLeft, aDevice->SizeInPixels())); + iHasBitmapCommand = ETrue; + } + +void CRemoteGc::DrawBitmap(const TRect &aDestRect, const CFbsBitmap *aDevice) + { + iCommandBuffer->Write(ECommandDrawBitmap2); + iCommandBuffer->Write(aDestRect); + iCommandBuffer->Write(aDevice->Handle()); + iBoundingRect.BoundingRect(aDestRect); + iHasBitmapCommand = ETrue; + } + +void CRemoteGc::DrawBitmap(const TRect &aDestRect, const CFbsBitmap *aDevice, const TRect &aSourceRect) + { + iCommandBuffer->Write(ECommandDrawBitmap3); + iCommandBuffer->Write(aDestRect); + iCommandBuffer->Write(aDevice->Handle()); + iCommandBuffer->Write(aSourceRect); + iBoundingRect.BoundingRect(aDestRect); + iHasBitmapCommand = ETrue; + } + +void CRemoteGc::DrawBitmapMasked(const TRect& aDestRect, const CFbsBitmap* aBitmap, const TRect& aSourceRect, const CFbsBitmap* aMaskBitmap, TBool aInvertMask) + { + iCommandBuffer->Write(ECommandDrawBitmapMasked); + iCommandBuffer->Write(aDestRect); + iCommandBuffer->Write(aBitmap->Handle()); + iCommandBuffer->Write(aSourceRect); + iCommandBuffer->Write(aMaskBitmap->Handle()); + iCommandBuffer->Write(aInvertMask); + iBoundingRect.BoundingRect(aDestRect); + iHasBitmapCommand = ETrue; + } + +void CRemoteGc::DrawBitmapMasked(const TRect& aDestRect, const CWsBitmap* aBitmap, const TRect& aSourceRect, const CWsBitmap* aMaskBitmap, TBool aInvertMask) + { + DrawBitmapMasked(aDestRect, reinterpret_cast(aBitmap), aSourceRect, reinterpret_cast(aMaskBitmap), aInvertMask); + } + +void CRemoteGc::DrawText(const TDesC &aBuf,const TPoint &aPos) + { + iCommandBuffer->Write(ECommandDrawText1); + iCommandBuffer->WriteText(aBuf); + iCommandBuffer->Write(aPos); + iBoundingRect.BoundingRect(iDrawRect); + } + +void CRemoteGc::DrawText(const TDesC &aBuf, const TRect &aBox, TInt aBaselineOffset, TTextAlign aHoriz, TInt aLeftMrg) + { + iCommandBuffer->Write(ECommandDrawText2); + iCommandBuffer->WriteText(aBuf); + iCommandBuffer->Write(aBox); + iCommandBuffer->Write(aBaselineOffset); + iCommandBuffer->Write(aHoriz); + iCommandBuffer->Write(aLeftMrg); + iBoundingRect.BoundingRect(aBox); + } + +void CRemoteGc::DrawText(const TDesC& aText, const TPoint& aPosition, const TDrawTextParam& aParam) + { + iCommandBuffer->Write(ECommandDrawText3); + iCommandBuffer->WriteText(aText); + iCommandBuffer->Write(aPosition); + iCommandBuffer->Write(aParam); + iBoundingRect.BoundingRect(iDrawRect); + } + +void CRemoteGc::MapColors(const TRect& aRect, const TRgb* aColors, TInt aNumPairs, TBool aMapForwards) + { + iCommandBuffer->Write(ECommandMapColors); + iCommandBuffer->Write(aRect); + iCommandBuffer->Write(aNumPairs); + + for(TInt i = 0; i < aNumPairs; i++) + { + iCommandBuffer->Write(aColors[i]); + iCommandBuffer->Write(aColors[i+1]); + } + + iCommandBuffer->Write(aMapForwards); + } + +TInt CRemoteGc::SetClippingRegion(const TRegion &aRegion) + { + iCommandBuffer->Write(ECommandSetClippingRegion); + + const TInt count = aRegion.Count(); + iCommandBuffer->Write(count); + + for(TInt i = 0; i < count; i++) + { + iCommandBuffer->Write(aRegion.RectangleList()[i]); + } + + return KErrNone; + } + +void CRemoteGc::CancelClippingRegion() + { + iCommandBuffer->Write(ECommandCancelClippingRegion); + } + +void CRemoteGc::DrawTextVertical(const TDesC& aText, const TPoint& aPos, TBool aUp) + { + iCommandBuffer->Write(ECommandDrawTextVertical1); + iCommandBuffer->WriteText(aText); + iCommandBuffer->Write(aPos); + iCommandBuffer->Write(aUp); + iBoundingRect.BoundingRect(iDrawRect); + } + +void CRemoteGc::DrawTextVertical(const TDesC& aText, const TRect& aBox, TInt aBaselineOffset, TBool aUp, TTextAlign aVert, TInt aMargin) + { + iCommandBuffer->Write(ECommandDrawTextVertical2); + iCommandBuffer->WriteText(aText); + iCommandBuffer->Write(aBox); + iCommandBuffer->Write(aBaselineOffset); + iCommandBuffer->Write(aUp); + iCommandBuffer->Write(aVert); + iCommandBuffer->Write(aMargin); + iBoundingRect.BoundingRect(aBox); + } + +void CRemoteGc::DrawWsGraphic(const TWsGraphicId& aId,const TRect& aDestRect) + { + iCommandBuffer->Write(ECommandDrawWsGraphic1); + iCommandBuffer->Write(aId.IsUid()? aId.Uid().iUid: aId.Id()); + iCommandBuffer->Write(aId.IsUid()); + iCommandBuffer->Write(aDestRect); + iBoundingRect.BoundingRect(aDestRect); + } + +void CRemoteGc::DrawWsGraphic(const TWsGraphicId& aId,const TRect& aDestRect,const TDesC8& aData) + { + iCommandBuffer->Write(ECommandDrawWsGraphic2); + iCommandBuffer->Write(aId.IsUid()? aId.Uid().iUid: aId.Id()); + iCommandBuffer->Write(aId.IsUid()); + iCommandBuffer->Write(aDestRect); + iCommandBuffer->WriteText(aData); + iBoundingRect.BoundingRect(aDestRect); + } + +void CRemoteGc::SetDitherOrigin(const TPoint& /*aPoint*/) + { + // do nothing, does not apply to CBitmapContext which CCommandBuffer is using + } + +void CRemoteGc::SetOpaque(TBool /*aDrawOpaque*/) + { + // overrides to prevent calling CWindowGc::SetOpaque, it's specific to how wserv blends windows content + } + +TInt CRemoteGc::APIExtension(TUid aUid, TAny*& aOutput, TAny* aInput) + { + if (aUid == KSetShadowColor) + { + return APIExSetShadowColor(aInput); + } + /* Future cases may be placed here later.*/ + else + { + return CBitmapContext::APIExtension(aUid, aOutput, aInput); + } + } + +TInt CRemoteGc::APIExSetShadowColor(TAny* aShadowColor) + { + const TRgb shadowColor = *(reinterpret_cast (aShadowColor)); + iCommandBuffer->Write(ECommandSetShadowColor); + iCommandBuffer->Write(shadowColor); + return KErrNone; + }