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