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