os/graphics/graphicsdeviceinterface/directgdiadaptation/swsrc/swdirectgdimain.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include "directgdiadapter.h"
    17 #include "swdirectgdidriverimpl.h"
    18 #include "swdirectgdiimagetargetimpl.h"
    19 #include <graphics/directgdiimagetarget.h>
    20 
    21 // Use on every argument if a method is not implemented yet
    22 #define UNUSED(x) {(void)(x); User::Invariant();}
    23 
    24 /**
    25 Engine constructor.
    26 
    27 @param aDriver The driver implementation.
    28  */
    29 CSwDirectGdiEngine::CSwDirectGdiEngine(CSwDirectGdiDriverImpl* aDriver):
    30 	iBrushBitmap(),
    31 	iBrushColor(KRgbWhite),
    32 	iBrushOrigin(0,0),
    33 	iBrushStyle(DirectGdi::ENullBrush),
    34 	iDefaultRegion(),
    35 	iDefaultRegionPtr(NULL),
    36 	iDotLength(0),
    37 	iDotMask(0),
    38 	iDotParam(0),
    39 	iDotDirection(1),
    40 	iDrawDevice(NULL),
    41 	iDrawMode(DirectGdi::EDrawModePEN),
    42 	iDriver(aDriver),
    43 	iLinePosition(0,0),
    44 	iOrigin(0,0),
    45 	iPenArray(NULL),
    46 	iPenColor(KRgbBlack),
    47 	iTextShadowColor(KRgbGray),
    48 	iPenSize(1, 1),
    49 	iPenStyle(DirectGdi::ESolidPen)
    50 	{			
    51 	}
    52 
    53 CSwDirectGdiEngine::~CSwDirectGdiEngine()
    54 	{
    55 	Deactivate();
    56 	ResetPenArray();
    57 	iClippingRegion.Close();
    58 	iBrushBitmap.Reset();
    59 	}
    60 
    61 /**
    62 @see MDirectGdiEngine::Activate()
    63 
    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).
    68 */
    69 TInt CSwDirectGdiEngine::Activate(RDirectGdiImageTarget& aTarget) 
    70 	{
    71 	GRAPHICS_ASSERT_DEBUG(aTarget.Handle(), EDirectGdiPanicActivateWithNullHandle);
    72 	GRAPHICS_ASSERT_ALWAYS(iDriver->ValidImageTarget(aTarget.Handle()), EDirectGdiPanicResourceHandleNotFound);
    73 		
    74 	CSwDirectGdiImageTargetImpl* target = reinterpret_cast<CSwDirectGdiImageTargetImpl*>(aTarget.Handle());
    75 	if(iRenderingTarget == target)
    76 		{
    77 		return KErrNone;
    78 		}
    79 
    80 	Deactivate();
    81 	
    82 	iRenderingTarget = target;
    83 	target->Open();	
    84 	iDrawDevice = target->DrawDevice();
    85 	GRAPHICS_ASSERT_DEBUG(iDrawDevice, EDirectGdiPanicActivateWithNullDrawDevice);
    86 	TRect deviceRect;
    87 	iDrawDevice->GetDrawRect(deviceRect);
    88 	iDefaultRegion.Clear();
    89 	iDefaultRegion.AddRect(deviceRect);
    90 	iDefaultRegionPtr = &iDefaultRegion;	
    91 	
    92 	return KErrNone;
    93 	}
    94 
    95 /**
    96  Unbinds the drawing engine.
    97  */
    98 void CSwDirectGdiEngine::Deactivate()
    99 	{
   100 	if (iRenderingTarget)
   101 		{
   102 		iDriver->Deactivate(iRenderingTarget);
   103 		iDrawDevice = NULL;
   104 		}		
   105 	}
   106 
   107 /** 
   108 @see MDirectGdiEngine::ExternalizeL()
   109 */
   110 void CSwDirectGdiEngine::ExternalizeL(RWriteStream& aWriteStream)
   111 	{	
   112 	aWriteStream.WriteUint32L(iDotLength);
   113 	aWriteStream.WriteUint32L(iDotMask);
   114 	aWriteStream.WriteUint32L(iDotParam);
   115 	aWriteStream.WriteUint32L(iDotDirection); 
   116 	aWriteStream << iLinePosition;
   117 	}
   118 
   119 /** 
   120 @see MDirectGdiEngine::InternalizeL()
   121 */
   122 void CSwDirectGdiEngine::InternalizeL(RReadStream& aReadStream)
   123 	{	
   124 	iDotLength = aReadStream.ReadUint32L();
   125 	iDotMask = aReadStream.ReadUint32L();
   126 	iDotParam = aReadStream.ReadUint32L();
   127 	iDotDirection = aReadStream.ReadUint32L(); 
   128 	aReadStream >> iLinePosition;
   129 	}
   130 
   131 /**
   132 @see MDirectGdiEngine::ResetBrushPattern()
   133 */
   134 void CSwDirectGdiEngine::ResetBrushPattern()
   135 	{
   136 	iBrushBitmap.Reset();
   137 	}
   138 
   139 /** 
   140 @see MDirectGdiEngine::MoveTo()
   141 */
   142 void CSwDirectGdiEngine::MoveTo(const TPoint& aPoint)
   143 	{
   144 	iLinePosition = aPoint;
   145 	}
   146 
   147 /**
   148 @see MDirectGdiEngine::MoveBy()
   149 */
   150 void CSwDirectGdiEngine::MoveBy(const TPoint& aVector)
   151 	{
   152 	iLinePosition += aVector;
   153 	}
   154 
   155 /**
   156 @see MDirectGdiEngine::Reset()
   157 
   158 @pre Has been called by CDirectGdiContext::Reset()
   159 
   160 Most states are set by the context Reset(), only states that can't be set by the context need resetting here.
   161 */
   162 void CSwDirectGdiEngine::Reset()
   163 	{
   164 	iDotLength = 0;
   165 	iDotMask = 0;
   166 	iDotParam = 0;
   167 	iDotDirection = 1;	
   168 	ResetPenArray();
   169 	}
   170 
   171 /**
   172 @see MDirectGdiEngine::SetBrushOrigin()
   173 */
   174 void CSwDirectGdiEngine::SetBrushOrigin(const TPoint& aOrigin)
   175 	{
   176 	iBrushOrigin = aOrigin;
   177 	}
   178 
   179 /** 
   180 @see MDirectGdiEngine::SetBrushColor()
   181  */
   182 void CSwDirectGdiEngine::SetBrushColor(const TRgb& aColor)
   183 	{
   184 	iBrushColor = aColor;
   185 	}
   186 
   187 /**	
   188 @see MDirectGdiEngine::SetBrushStyle()
   189 @panic DGDIAdapter 12, if aStyle is EPatternedBrush but no valid brush bitmap has been set.
   190 */
   191 void CSwDirectGdiEngine::SetBrushStyle(DirectGdi::TBrushStyle aStyle)
   192 	{
   193 	if (aStyle == DirectGdi::EPatternedBrush)
   194 		{
   195 		GRAPHICS_ASSERT_ALWAYS(iBrushBitmap.Handle() != 0, EDirectGdiPanicPatternedBrushNotSet);
   196 		}
   197 	iBrushStyle = aStyle;
   198 	}
   199 
   200 /**
   201 @see MDirectGdiEngine::ResetClippingRegion()
   202  */
   203 void CSwDirectGdiEngine::ResetClippingRegion()
   204 	{
   205 	iDefaultRegionPtr = &iDefaultRegion;	
   206 	iClippingRegion.Clear();
   207 	}
   208 
   209 /**
   210 The error state is set to KErrNoMemory if the required memory could not be allocated.
   211 
   212 @see MDirectGdiEngine::SetClippingRegion()
   213 */
   214 void CSwDirectGdiEngine::SetClippingRegion(const TRegion& aRegion)
   215 	{
   216 	TRect boundingRect=iDefaultRegion.BoundingRect();
   217 	boundingRect.iTl-=iDrawOrigin;
   218 	boundingRect.iBr-=iDrawOrigin;
   219 	if (!aRegion.IsContainedBy(boundingRect))
   220 		{
   221 		iDriver->SetError(KErrArgument);
   222 		return;
   223 		}
   224 	
   225 	iClippingRegion.Copy(aRegion);
   226 	
   227 	if (iClippingRegion.CheckError())		
   228 		{
   229 		iDriver->SetError(KErrNoMemory);
   230 		return;
   231 		}
   232 	iClippingRegion.Offset(iDrawOrigin);
   233 	iDefaultRegionPtr = &iClippingRegion;
   234 	}
   235 
   236 /**
   237 @see MDirectGdiEngine::SetDrawMode()
   238 */
   239 void CSwDirectGdiEngine::SetDrawMode(DirectGdi::TDrawMode aDrawMode)
   240 	{
   241 	iDrawMode = aDrawMode;
   242 	}
   243 
   244 /** 
   245 @see MDirectGdiEngine::SetOrigin()
   246 */
   247 void CSwDirectGdiEngine::SetOrigin(const TPoint& aOrigin)
   248 	{
   249 	iOrigin = aOrigin+iDrawOrigin;
   250 	}
   251 
   252 /** 
   253 @see MDrawDeviceOrigin::Set()
   254 */
   255 TInt CSwDirectGdiEngine::Set(const TPoint& aDrawOrigin)
   256 	{
   257 	TPoint moveOrigin=aDrawOrigin;
   258 	moveOrigin-=iDrawOrigin;
   259 	iOrigin+=moveOrigin;
   260 	iClippingRegion.Offset(moveOrigin);
   261 	iDrawOrigin = aDrawOrigin;
   262 	return KErrNone;
   263 	}
   264 
   265 /** 
   266 @see MDrawDeviceOrigin::Get()
   267 */
   268 void CSwDirectGdiEngine::Get(TPoint& aDrawOrigin)
   269 	{
   270 	aDrawOrigin=iDrawOrigin;
   271 	}
   272 
   273 /** 
   274 @see MDirectGdiEngine::SetPenColor()
   275  */
   276 void CSwDirectGdiEngine::SetPenColor(const TRgb& aColor)
   277 	{
   278 	iPenColor = aColor;
   279 	}
   280 
   281 /** 
   282 @see MDirectGdiEngine::SetPenStyle()
   283 */
   284 void CSwDirectGdiEngine::SetPenStyle(DirectGdi::TPenStyle aStyle)
   285 	{
   286 	iPenStyle = aStyle;	
   287 	switch(iPenStyle)
   288 		{
   289 		case DirectGdi::ENullPen:
   290 			iDotMask=0;
   291 			iDotLength=0;
   292 			break;
   293 		case DirectGdi::EDottedPen:
   294 			iDotMask=1;
   295 			iDotLength=4;
   296 			break;
   297 		case DirectGdi::EDashedPen:
   298 			iDotMask=7;	
   299 			iDotLength=6;
   300 			break;
   301 		case DirectGdi::EDotDashPen:
   302 			iDotMask=113;
   303 			iDotLength=10;
   304 			break;
   305 		case DirectGdi::EDotDotDashPen:
   306 			iDotMask=1809;
   307 			iDotLength=14;
   308 			break;
   309 		case DirectGdi::ESolidPen:
   310 		default:
   311 			iDotMask=1;
   312 			iDotLength=1;
   313 			break;
   314 		};
   315 	iDotParam=0;
   316 	}
   317 
   318 /**
   319 The error state is set to KErrNoMemory if the required memory could not be allocated.
   320 
   321 @see MDirectGdiEngine::SetPenSize()
   322 
   323 @pre aSize is not the same as iPenSize.
   324 */
   325 void CSwDirectGdiEngine::SetPenSize(const TSize& aSize)
   326 	{
   327 	iPenSize = aSize;
   328 
   329 	if ((iPenSize.iWidth >= 1) || (iPenSize.iHeight >= 1))
   330 		{
   331 		TInt err = PenAllocate();
   332 		iDriver->SetError(err);
   333 		}
   334 	else
   335 		{
   336 		ResetPenArray();
   337 		}
   338 
   339 	iDotParam = 0;
   340 	}
   341 
   342 /** 
   343 @see MDirectGdiEngine::SetBrushPattern()
   344 
   345 @pre aPattern is a valid bitmap.
   346 */
   347 TInt CSwDirectGdiEngine::SetBrushPattern(const CFbsBitmap& aPattern)
   348 	{			
   349 	if (aPattern.ExtendedBitmapType() != KNullUid)
   350 		{
   351 		return KErrNotSupported; // Not supported for extended bitmaps		
   352 		}
   353 	
   354 	return iBrushBitmap.Duplicate(aPattern.Handle());
   355 	}
   356 
   357 
   358