os/graphics/graphicsdeviceinterface/directgdiadaptation/hwsrc/vgengine.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
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
#ifndef VGENGINE_H_
sl@0
    17
#define VGENGINE_H_
sl@0
    18
sl@0
    19
/**
sl@0
    20
@file
sl@0
    21
@internalComponent Reference implementation of Open VG hardware accelerated DirectGDI adaptation.
sl@0
    22
*/
sl@0
    23
sl@0
    24
#include "directgdidriverimpl.h"
sl@0
    25
#include "directgdiadapter.h"
sl@0
    26
#include "clippingregionmanager.h"
sl@0
    27
#include <bitdraworigin.h>
sl@0
    28
#include <graphics/directgdiengine.h>
sl@0
    29
#include <graphics/sgimage.h>
sl@0
    30
#include <VG/openvg.h>
sl@0
    31
#include <VG/vgu.h>
sl@0
    32
#include <gdi.h>
sl@0
    33
sl@0
    34
class CDirectGdiDriverImpl;
sl@0
    35
sl@0
    36
#ifdef DRAWGLYPH_BUFFERED
sl@0
    37
const TInt KMaxGlyphs = 64;
sl@0
    38
typedef struct TDrawGlyphCommand_Tag
sl@0
    39
{
sl@0
    40
	TPoint pos;
sl@0
    41
	TChar aChar;
sl@0
    42
	TUint8* aGlyphImage;
sl@0
    43
	TGlyphBitmapType aGlyphBitmapType;
sl@0
    44
	TSize aGlyphImageSize;
sl@0
    45
	TRect aClipRect;
sl@0
    46
	DirectGdi::TGraphicsRotation aRotation;	
sl@0
    47
	
sl@0
    48
	TBool SameGlyph(const TDrawGlyphCommand_Tag aOther)
sl@0
    49
		{ 
sl@0
    50
		return aGlyphImage == aOther.aGlyphImage && 
sl@0
    51
				aChar == aOther.aChar && 
sl@0
    52
				aGlyphImage == aOther.aGlyphImage && 
sl@0
    53
				aGlyphBitmapType == aOther.aGlyphBitmapType && 
sl@0
    54
				aGlyphImageSize == aOther.aGlyphImageSize;
sl@0
    55
		}
sl@0
    56
} TDrawGlyphCommand;
sl@0
    57
#endif
sl@0
    58
sl@0
    59
/**
sl@0
    60
Concrete (reference) implementation of a MDirectGdiEngine.
sl@0
    61
sl@0
    62
This class implements the rendering mechanism for DirectGDI. In this case,
sl@0
    63
OpenVG is used to get things done, so hardware acceleration is used.
sl@0
    64
*/
sl@0
    65
NONSHARABLE_CLASS(CVgEngine): public CBase, public MDirectGdiEngine, public MDrawDeviceOrigin
sl@0
    66
	{
sl@0
    67
public:
sl@0
    68
	virtual ~CVgEngine();
sl@0
    69
	CVgEngine(CDirectGdiDriverImpl& aDriver);
sl@0
    70
sl@0
    71
	// from MDirectGdiEngine
sl@0
    72
	TInt Activate(RDirectGdiImageTarget& aTarget);
sl@0
    73
	void Deactivate();
sl@0
    74
	void SetOrigin(const TPoint& aOrigin);
sl@0
    75
	void SetClippingRegion(const TRegion& aRegion);
sl@0
    76
	void ResetClippingRegion();
sl@0
    77
	void SetDrawMode(DirectGdi::TDrawMode aMode);
sl@0
    78
	void SetPenColor(const TRgb& aColor);
sl@0
    79
	void SetPenStyle(DirectGdi::TPenStyle aStyle);
sl@0
    80
	void SetPenSize(const TSize& aSize);
sl@0
    81
	void SetTextShadowColor(const TRgb& aColor);
sl@0
    82
	void SetBrushColor(const TRgb& aColor);
sl@0
    83
	void SetBrushStyle(DirectGdi::TBrushStyle aStyle);
sl@0
    84
	void SetBrushOrigin(const TPoint& aOrigin);
sl@0
    85
	TInt SetBrushPattern(const CFbsBitmap& aPattern);
sl@0
    86
	void ResetBrushPattern();
sl@0
    87
	void SetFont(TUint32 aFontId);
sl@0
    88
	void ResetFont();
sl@0
    89
	void Reset();
sl@0
    90
	void Clear(const TRect& aRect);
sl@0
    91
	void Clear();
sl@0
    92
	void MoveTo(const TPoint& aPoint);
sl@0
    93
	void MoveBy(const TPoint& aVector);
sl@0
    94
	void Plot(const TPoint& aPoint);
sl@0
    95
	void DrawLine(const TPoint& aStart, const TPoint& aEnd);
sl@0
    96
	void DrawLineTo(const TPoint& aPoint);
sl@0
    97
	void DrawLineBy(const TPoint& aVector);
sl@0
    98
	void DrawRect(const TRect& aRect);
sl@0
    99
	void DrawRoundRect(const TRect& aRect, const TSize& aCornerSize);
sl@0
   100
	void DrawPolyLine(const TArray<TPoint>& aPointList);
sl@0
   101
	void DrawPolyLineNoEndPoint(const TArray<TPoint>& aPointList);
sl@0
   102
	void DrawPolygon(const TArray<TPoint>& aPoints,	DirectGdi::TFillRule aRule);
sl@0
   103
	void DrawArc(const TRect& aRect, const TPoint& aStart, const TPoint& aEnd);
sl@0
   104
	void DrawPie(const TRect& aRect, const TPoint& aStart, const TPoint& aEnd);
sl@0
   105
	void DrawEllipse(const TRect& aRect);
sl@0
   106
	void BitBlt(const TPoint& aDestPos, const CFbsBitmap& aSourceBitmap, const TRect& aSourceRect);
sl@0
   107
	void BitBltMasked(
sl@0
   108
			const TPoint& aDestPos,				
sl@0
   109
			const CFbsBitmap& aSourceBitmap,
sl@0
   110
			const TRect& aSourceRect,				
sl@0
   111
			const CFbsBitmap& aMaskBitmap, 
sl@0
   112
			TBool aInvertMask);
sl@0
   113
	void BitBltMasked(const TPoint& aDestPt,
sl@0
   114
			const CFbsBitmap& aSourceBitmap, const TRect& aSourceRect,				
sl@0
   115
			const CFbsBitmap& aMaskBitmap, const TPoint& aMaskPos);
sl@0
   116
	void DrawBitmap(const TRect& aDestRect, const CFbsBitmap& aSourceBitmap,
sl@0
   117
			const TRect& aSrcRect);
sl@0
   118
	void DrawBitmapMasked(const TRect& aDestRect,				
sl@0
   119
			const CFbsBitmap& aSourceBitmap,const TRect& aSourceRect,				
sl@0
   120
			const CFbsBitmap& aMaskBitmap, TBool aInvertMask);
sl@0
   121
	void DrawResource(const TPoint& aPos, 
sl@0
   122
			const RDirectGdiDrawableSource& aSource, 
sl@0
   123
			DirectGdi::TGraphicsRotation aRotation);	
sl@0
   124
	void DrawResource(const TRect& aDestRect,
sl@0
   125
			const RDirectGdiDrawableSource& aSource,
sl@0
   126
			DirectGdi::TGraphicsRotation aRotation);
sl@0
   127
	void DrawResource(const TRect& aDestRect,				
sl@0
   128
			const RDirectGdiDrawableSource& aSource, 
sl@0
   129
			const TRect& aSrcRect,
sl@0
   130
			DirectGdi::TGraphicsRotation aRotation);
sl@0
   131
	void DrawResource(
sl@0
   132
			const TRect& aDestRect,				
sl@0
   133
			const RDirectGdiDrawableSource& aSource,
sl@0
   134
			const TDesC8& aParam);
sl@0
   135
	void DrawGlyph(const TPoint& aPos, const TChar aChar, const TUint8* aGlyphImage,
sl@0
   136
			const TGlyphBitmapType aGlyphBitmapType, const TSize& aGlyphImageSize, const TRect& aClipRect,
sl@0
   137
			const DirectGdi::TGraphicsRotation aRotation = DirectGdi::EGraphicsRotationNone);
sl@0
   138
	void CopyRect(const TPoint& aOffset, const TRect& aRect);
sl@0
   139
	void ExternalizeL(RWriteStream& aWriteStream);
sl@0
   140
	void InternalizeL(RReadStream& aReadStream);
sl@0
   141
	TInt GetInterface(TUid aInterfaceId, TAny*& aInterface);
sl@0
   142
	
sl@0
   143
	void BeginDrawGlyph();
sl@0
   144
	void EndDrawGlyph();
sl@0
   145
	
sl@0
   146
	//from MDrawDeviceOrigin
sl@0
   147
	TInt Set(const TPoint& aDrawOrigin);
sl@0
   148
	void Get(TPoint& aDrawOrigin);
sl@0
   149
private:
sl@0
   150
	TRect SgMetricsToVgTRect (const TPoint& aCoord, const TInt width, const TInt height) const;
sl@0
   151
sl@0
   152
	const TPoint ConvertToVgCoords(const TPoint& aPoint);
sl@0
   153
	const TPoint ConvertToVgCoords(const TRect& aRect);
sl@0
   154
	void ResetVgMatrix();
sl@0
   155
	void ResetVgMatrix(const VGMatrixMode aMatrixMode);
sl@0
   156
sl@0
   157
	// Path (line) creation commands
sl@0
   158
	TBool PreparePath(VGPath& aPath, TInt aExpectedCommandCount);
sl@0
   159
	void AppendPathCommand(VGubyte aCommand);
sl@0
   160
	void AppendPathCommand(VGubyte aCommand, VGfloat aCoord);
sl@0
   161
	void AppendPathCommand(VGubyte aCommand, VGfloat aCoord1, VGfloat aCoord2);
sl@0
   162
	TInt PrepareForPathCommand(TInt aCommandCount, TInt aCoordCount);
sl@0
   163
	void FinishPath(VGPath aPath);	
sl@0
   164
	TInt AllocPathCommands(TInt aCommandCount);
sl@0
   165
	TInt AllocPathCoords(TInt aCoordCount);
sl@0
   166
	TBool ConvertBitmapToVgImage(const CFbsBitmap& aBitmap, VGImage& aImage, TBool aIsMask = EFalse, const TPoint& aOrigin = TPoint(0,0));
sl@0
   167
	VGImage CreateSourceVGImage(const CFbsBitmap& aSource, TBool aFlipY = EFalse, const TPoint& aOrigin = TPoint(0,0));	
sl@0
   168
	TInt CreateStandardBrush(TSize& aPatternSize, VGbyte* aBrushPattern);
sl@0
   169
	TBool NonZeroBrushPatternOrigin();
sl@0
   170
	TInt CopyCurrentBrushPatternForNonZeroOrigin();	
sl@0
   171
	inline VGfloat* Identity (void) {return iIdentityMatrix;}
sl@0
   172
	void SetVgState();
sl@0
   173
	void SetVguError(VGUErrorCode aErr);
sl@0
   174
	TBool GetCurrentBrushPattern(VGImage& aBrush, TSize& aSize, VGImageFormat& aFormat) const;
sl@0
   175
sl@0
   176
	TReal GetAngleFromXAxisAnticlockwise(const TReal aOriginX, const TReal aOriginY, const TReal aPointX, const TReal aPointY, const TReal aWidth, const TReal aHeight);
sl@0
   177
sl@0
   178
	void DoDrawArc(const TRect& aRect, const TPoint& aStart, const TPoint& aEnd, VGUArcType aArcType);
sl@0
   179
	void DoDrawPoly(const TArray<TPoint>& aPointList, TBool aClosed);
sl@0
   180
sl@0
   181
	TBool MakeEngineCurrent();
sl@0
   182
sl@0
   183
	void DoBitBltMasked (
sl@0
   184
		const TPoint& aDestPos,
sl@0
   185
		const CFbsBitmap& aSourceBitmap,
sl@0
   186
		const TRect& aSourceRect,
sl@0
   187
		const CFbsBitmap& aMaskBitmap,
sl@0
   188
		TBool aInvertMask,
sl@0
   189
		const TPoint& aMaskPos);
sl@0
   190
sl@0
   191
	void DoVgImageDraw (
sl@0
   192
		const TRect& aDestRect, 
sl@0
   193
		const CFbsBitmap& aSourceBitmap, 
sl@0
   194
		const TRect& aSourceRect);
sl@0
   195
sl@0
   196
	void DoVgMaskedImageDraw(
sl@0
   197
		const TPoint& aDestPos,
sl@0
   198
		VGImage aSourceImage,
sl@0
   199
		const TRect& aSourceImageSize,
sl@0
   200
		const TRect& aSourceRect,
sl@0
   201
		const VGImage aMaskImage,
sl@0
   202
		const TSize& srcMaskSize,
sl@0
   203
		const TSize& aDestSize,
sl@0
   204
		TBool aInvertMask);
sl@0
   205
sl@0
   206
	inline TBool IntersectsClippingRegion (const TRect& aRect);
sl@0
   207
sl@0
   208
	void DoDrawResource(const TRect& aDestRect, CDirectGdiImageSourceImpl* aSource, DirectGdi::TGraphicsRotation aRotation);	
sl@0
   209
	void DoDrawResource(const TRect& aDestRect, CDirectGdiImageSourceImpl* aSource, const TRect& aSrcRect, DirectGdi::TGraphicsRotation aRotation);
sl@0
   210
	
sl@0
   211
	VGImage DoVgCreateImage(VGImageFormat aFormat, VGint aWidth, VGint aHeight, VGbitfield aAllowedQuality);
sl@0
   212
	void SetVgPaintColor(VGPaint& aPaint, const TRgb& aColor);
sl@0
   213
	
sl@0
   214
private:	
sl@0
   215
	CDirectGdiDriverImpl& iDriver;
sl@0
   216
	RClippingRegionManager iRegionManager;
sl@0
   217
	CDirectGdiImageTargetImpl* iRenderingTarget;
sl@0
   218
	TRegionFix<1> iTargetRegion;	/**< The region which the rendering target occupies.*/
sl@0
   219
	TSize iSize;	/**< The size of the rendering target.*/
sl@0
   220
sl@0
   221
	TPoint iOrigin;		/**< The origin of the drawing engine coordinate system.*/
sl@0
   222
	TPoint iDrawOrigin; /**< The origin of all drawing, affected by app mode offset */
sl@0
   223
	VGPaint iPen;		/**< VGPaint object for all pen operations (Stroke operations in OpenVG).*/
sl@0
   224
	TSize iPenSize;		/**< The current pen size.*/
sl@0
   225
	TRgb iPenColor;		/**< The current pen colour.*/
sl@0
   226
	TRgb iTextShadowColor;	/**< The current colour for blending text shadow.*/
sl@0
   227
	DirectGdi::TPenStyle iPenStyle;	/**< The current pen style.*/
sl@0
   228
	VGPaint iBrush;		/**< VGPaint object for all brush operations (Fill operations in OpenVG).*/
sl@0
   229
	VGPaint iClearBrush;	/**< VGPaint object for Clear() operations only.*/
sl@0
   230
	TRgb iBrushColor;	/**< The current brush colour.*/
sl@0
   231
	VGPath iVgPath;		/**< OpenVG path used for all path drawing.*/
sl@0
   232
	TUint32 iFontId;	/**< The id of the current font.*/
sl@0
   233
	VGPaint iTextBrush; /**< VGPaint object used to draw text. */
sl@0
   234
sl@0
   235
	/**
sl@0
   236
	VGImage for holding the current user brush pattern (i.e when 
sl@0
   237
	DirectGdi::TBrushStyle::EPatternedBrush is selected).
sl@0
   238
	*/
sl@0
   239
	VGImage iBrushPatternUser;
sl@0
   240
sl@0
   241
	/**
sl@0
   242
	VGImage for holding the current standard brush pattern (i.e. when one of 
sl@0
   243
	DirectGdi::TBrushStyle::EVerticalHatchBrush to DirectGdi::TBrushStyle::EDiamondCrossHatchBrush
sl@0
   244
	brush styles are selected).
sl@0
   245
	*/
sl@0
   246
	VGImage iBrushPatternStandard;
sl@0
   247
sl@0
   248
	VGImage iBrushPatternStandardRegion; /**< VGImage for holding a sub-region of iBrushPatternStandard.*/
sl@0
   249
	TInt iBrushPatternStandardId;	/**< The id of the currently loaded standard brush pattern. This is initialised to -1 inside Activate().*/
sl@0
   250
	DirectGdi::TBrushStyle iBrushStyle;	/**< The current brush style.*/
sl@0
   251
	TPoint iBrushOrigin;	/**< The current brush origin.*/
sl@0
   252
sl@0
   253
	/**
sl@0
   254
	This VGImage should always hold the current brush pattern if iBrushOrigin is not (0,0).
sl@0
   255
	This could be a shifted version of either iBrushPatternUser or iBrushPatternStandard.
sl@0
   256
	*/
sl@0
   257
	VGImage iBrushPatternNonZeroOrigin;
sl@0
   258
sl@0
   259
	VGbitfield iPaintMode;	/**< The current paint mode.*/
sl@0
   260
sl@0
   261
	// The following members variables are used when drawing paths
sl@0
   262
	VGubyte* iPathCommands;	/**< Pointer to list of stored commands to be used in a VGPath.*/
sl@0
   263
	VGfloat* iPathCoords;	/**< Pointer to list of stored coordinates to be used in a VGPath.*/
sl@0
   264
	TInt iPathCommandCount; /**< The number of commands to be used in a VGPath.*/
sl@0
   265
	TInt iPathCoordCount;	/**< The number of coordinates to be used in a VGPath.*/
sl@0
   266
	TInt iCurrentMaxCommands;	/**< The current maximum number of commands which can be entered in a VGPath.*/
sl@0
   267
	TInt iCurrentMaxCoords;	/**< The current maximum number of coordinates which can be entered in a VGPath.*/
sl@0
   268
sl@0
   269
	TPoint iLinePos;	/**< The current line position. Can be changed using MoveTo(), MoveBy(), DrawLineTo(), DrawLineBy() and DrawPolyline().*/
sl@0
   270
	DirectGdi::TDrawMode iDrawMode;	/**< The current drawing mode.*/
sl@0
   271
	VGfloat iIdentityMatrix[9];	/**< The matrix used to convert coordinate systems.*/
sl@0
   272
sl@0
   273
	// Brush sizes. We'll remember them instead of doing potentially expensive vgGets
sl@0
   274
	TSize iBrushPatternStandardRegionSize;	/**< The size of the current sub-region of the standard brush pattern.*/
sl@0
   275
	TSize iBrushPatternStandardSize;	/**< The size of the current standard brush pattern.*/
sl@0
   276
	TSize iBrushPatternUserSize;	/**< The size of the curent  user brush pattern.*/
sl@0
   277
sl@0
   278
	TInt iBrushPatternUserBitmapHandle;	/**< Stores the bitmap handle to recreate the iBrushPatternUser VGImage.*/
sl@0
   279
sl@0
   280
	MFontGlyphImageStorage* iFontGlyphImageStorage;	/**< Interface which deals with glyph cache images.*/
sl@0
   281
sl@0
   282
#ifdef	DRAWGLYPH_BUFFERED
sl@0
   283
	TInt iDrawGlyphCount;
sl@0
   284
	TDrawGlyphCommand iDrawGlyphCommand[KMaxGlyphs];
sl@0
   285
	void FlushDrawGlyphs();
sl@0
   286
#endif
sl@0
   287
	};
sl@0
   288
sl@0
   289
inline TBool CVgEngine::NonZeroBrushPatternOrigin()
sl@0
   290
	{
sl@0
   291
	return ((iBrushOrigin.iX != 0) || (iBrushOrigin.iY != 0));
sl@0
   292
	}
sl@0
   293
sl@0
   294
/**
sl@0
   295
Helper method to determine if a specified rectangle intersects with the current clipping region.
sl@0
   296
If the current clipping region is a null pointer then intersection is assumed.
sl@0
   297
sl@0
   298
@param 	aRect Rectangle to check for intersection with clipping region.
sl@0
   299
sl@0
   300
@return ETrue if aRect intersects with clipping region, else EFalse.
sl@0
   301
 */
sl@0
   302
inline TBool CVgEngine::IntersectsClippingRegion (const TRect& aRect)
sl@0
   303
	{
sl@0
   304
	if(iRegionManager.ClippingRegion().IsEmpty())
sl@0
   305
		{
sl@0
   306
		return (aRect.Intersects(iTargetRegion.BoundingRect()));
sl@0
   307
		}
sl@0
   308
	else 
sl@0
   309
		{
sl@0
   310
		return (iRegionManager.ClippingRegion().Intersects(aRect));
sl@0
   311
		}
sl@0
   312
	}
sl@0
   313
sl@0
   314
#endif /*VGENGINE_H_*/