os/graphics/graphicsdeviceinterface/directgdiadaptation/swsrc/swdirectgdimain.cpp
Update contrib.
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include "directgdiadapter.h"
17 #include "swdirectgdidriverimpl.h"
18 #include "swdirectgdiimagetargetimpl.h"
19 #include <graphics/directgdiimagetarget.h>
21 // Use on every argument if a method is not implemented yet
22 #define UNUSED(x) {(void)(x); User::Invariant();}
27 @param aDriver The driver implementation.
29 CSwDirectGdiEngine::CSwDirectGdiEngine(CSwDirectGdiDriverImpl* aDriver):
31 iBrushColor(KRgbWhite),
33 iBrushStyle(DirectGdi::ENullBrush),
35 iDefaultRegionPtr(NULL),
41 iDrawMode(DirectGdi::EDrawModePEN),
47 iTextShadowColor(KRgbGray),
49 iPenStyle(DirectGdi::ESolidPen)
53 CSwDirectGdiEngine::~CSwDirectGdiEngine()
57 iClippingRegion.Close();
62 @see MDirectGdiEngine::Activate()
64 @return KErrNone if successful, otherwise one of the the system-wide error codes.
65 @panic DGDIAdapter 32, if the handle of aTarget is not null, but is not associated with a valid target.
66 @panic DGDIAdapter 34, if the passed target has a NULL handle (debug only).
67 @panic DGDIAdapter 53, if the passed target has a NULL draw device (debug only).
69 TInt CSwDirectGdiEngine::Activate(RDirectGdiImageTarget& aTarget)
71 GRAPHICS_ASSERT_DEBUG(aTarget.Handle(), EDirectGdiPanicActivateWithNullHandle);
72 GRAPHICS_ASSERT_ALWAYS(iDriver->ValidImageTarget(aTarget.Handle()), EDirectGdiPanicResourceHandleNotFound);
74 CSwDirectGdiImageTargetImpl* target = reinterpret_cast<CSwDirectGdiImageTargetImpl*>(aTarget.Handle());
75 if(iRenderingTarget == target)
82 iRenderingTarget = target;
84 iDrawDevice = target->DrawDevice();
85 GRAPHICS_ASSERT_DEBUG(iDrawDevice, EDirectGdiPanicActivateWithNullDrawDevice);
87 iDrawDevice->GetDrawRect(deviceRect);
88 iDefaultRegion.Clear();
89 iDefaultRegion.AddRect(deviceRect);
90 iDefaultRegionPtr = &iDefaultRegion;
96 Unbinds the drawing engine.
98 void CSwDirectGdiEngine::Deactivate()
100 if (iRenderingTarget)
102 iDriver->Deactivate(iRenderingTarget);
108 @see MDirectGdiEngine::ExternalizeL()
110 void CSwDirectGdiEngine::ExternalizeL(RWriteStream& aWriteStream)
112 aWriteStream.WriteUint32L(iDotLength);
113 aWriteStream.WriteUint32L(iDotMask);
114 aWriteStream.WriteUint32L(iDotParam);
115 aWriteStream.WriteUint32L(iDotDirection);
116 aWriteStream << iLinePosition;
120 @see MDirectGdiEngine::InternalizeL()
122 void CSwDirectGdiEngine::InternalizeL(RReadStream& aReadStream)
124 iDotLength = aReadStream.ReadUint32L();
125 iDotMask = aReadStream.ReadUint32L();
126 iDotParam = aReadStream.ReadUint32L();
127 iDotDirection = aReadStream.ReadUint32L();
128 aReadStream >> iLinePosition;
132 @see MDirectGdiEngine::ResetBrushPattern()
134 void CSwDirectGdiEngine::ResetBrushPattern()
136 iBrushBitmap.Reset();
140 @see MDirectGdiEngine::MoveTo()
142 void CSwDirectGdiEngine::MoveTo(const TPoint& aPoint)
144 iLinePosition = aPoint;
148 @see MDirectGdiEngine::MoveBy()
150 void CSwDirectGdiEngine::MoveBy(const TPoint& aVector)
152 iLinePosition += aVector;
156 @see MDirectGdiEngine::Reset()
158 @pre Has been called by CDirectGdiContext::Reset()
160 Most states are set by the context Reset(), only states that can't be set by the context need resetting here.
162 void CSwDirectGdiEngine::Reset()
172 @see MDirectGdiEngine::SetBrushOrigin()
174 void CSwDirectGdiEngine::SetBrushOrigin(const TPoint& aOrigin)
176 iBrushOrigin = aOrigin;
180 @see MDirectGdiEngine::SetBrushColor()
182 void CSwDirectGdiEngine::SetBrushColor(const TRgb& aColor)
184 iBrushColor = aColor;
188 @see MDirectGdiEngine::SetBrushStyle()
189 @panic DGDIAdapter 12, if aStyle is EPatternedBrush but no valid brush bitmap has been set.
191 void CSwDirectGdiEngine::SetBrushStyle(DirectGdi::TBrushStyle aStyle)
193 if (aStyle == DirectGdi::EPatternedBrush)
195 GRAPHICS_ASSERT_ALWAYS(iBrushBitmap.Handle() != 0, EDirectGdiPanicPatternedBrushNotSet);
197 iBrushStyle = aStyle;
201 @see MDirectGdiEngine::ResetClippingRegion()
203 void CSwDirectGdiEngine::ResetClippingRegion()
205 iDefaultRegionPtr = &iDefaultRegion;
206 iClippingRegion.Clear();
210 The error state is set to KErrNoMemory if the required memory could not be allocated.
212 @see MDirectGdiEngine::SetClippingRegion()
214 void CSwDirectGdiEngine::SetClippingRegion(const TRegion& aRegion)
216 TRect boundingRect=iDefaultRegion.BoundingRect();
217 boundingRect.iTl-=iDrawOrigin;
218 boundingRect.iBr-=iDrawOrigin;
219 if (!aRegion.IsContainedBy(boundingRect))
221 iDriver->SetError(KErrArgument);
225 iClippingRegion.Copy(aRegion);
227 if (iClippingRegion.CheckError())
229 iDriver->SetError(KErrNoMemory);
232 iClippingRegion.Offset(iDrawOrigin);
233 iDefaultRegionPtr = &iClippingRegion;
237 @see MDirectGdiEngine::SetDrawMode()
239 void CSwDirectGdiEngine::SetDrawMode(DirectGdi::TDrawMode aDrawMode)
241 iDrawMode = aDrawMode;
245 @see MDirectGdiEngine::SetOrigin()
247 void CSwDirectGdiEngine::SetOrigin(const TPoint& aOrigin)
249 iOrigin = aOrigin+iDrawOrigin;
253 @see MDrawDeviceOrigin::Set()
255 TInt CSwDirectGdiEngine::Set(const TPoint& aDrawOrigin)
257 TPoint moveOrigin=aDrawOrigin;
258 moveOrigin-=iDrawOrigin;
260 iClippingRegion.Offset(moveOrigin);
261 iDrawOrigin = aDrawOrigin;
266 @see MDrawDeviceOrigin::Get()
268 void CSwDirectGdiEngine::Get(TPoint& aDrawOrigin)
270 aDrawOrigin=iDrawOrigin;
274 @see MDirectGdiEngine::SetPenColor()
276 void CSwDirectGdiEngine::SetPenColor(const TRgb& aColor)
282 @see MDirectGdiEngine::SetPenStyle()
284 void CSwDirectGdiEngine::SetPenStyle(DirectGdi::TPenStyle aStyle)
289 case DirectGdi::ENullPen:
293 case DirectGdi::EDottedPen:
297 case DirectGdi::EDashedPen:
301 case DirectGdi::EDotDashPen:
305 case DirectGdi::EDotDotDashPen:
309 case DirectGdi::ESolidPen:
319 The error state is set to KErrNoMemory if the required memory could not be allocated.
321 @see MDirectGdiEngine::SetPenSize()
323 @pre aSize is not the same as iPenSize.
325 void CSwDirectGdiEngine::SetPenSize(const TSize& aSize)
329 if ((iPenSize.iWidth >= 1) || (iPenSize.iHeight >= 1))
331 TInt err = PenAllocate();
332 iDriver->SetError(err);
343 @see MDirectGdiEngine::SetBrushPattern()
345 @pre aPattern is a valid bitmap.
347 TInt CSwDirectGdiEngine::SetBrushPattern(const CFbsBitmap& aPattern)
349 if (aPattern.ExtendedBitmapType() != KNullUid)
351 return KErrNotSupported; // Not supported for extended bitmaps
354 return iBrushBitmap.Duplicate(aPattern.Handle());