os/graphics/graphicsdeviceinterface/directgdiadaptation/swsrc/swdirectgdiengine.h
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
#ifndef CSWDIRECTGDIENGINE_H
sl@0
    17
#define CSWDIRECTGDIENGINE_H
sl@0
    18
sl@0
    19
/**
sl@0
    20
@file
sl@0
    21
@internalComponent
sl@0
    22
*/
sl@0
    23
sl@0
    24
#include "directgdiadapter.h"
sl@0
    25
#include "swdirectgdibitmap.h"
sl@0
    26
#include <graphics/directgdiengine.h>
sl@0
    27
#include <e32base.h>
sl@0
    28
#include <bitdraw.h>
sl@0
    29
#include <bitdraworigin.h>
sl@0
    30
#include <bitmap.h>
sl@0
    31
sl@0
    32
// For use when testing the code, allows the fast blending to be disabled so back to back comparisons
sl@0
    33
// can done be to check either timing or exact output.
sl@0
    34
//#define __ALLOW_FAST_BLEND_DISABLE__
sl@0
    35
sl@0
    36
class RDirectGdiDrawableSource;
sl@0
    37
class CSwDirectGdiDriverImpl;
sl@0
    38
class CSwDirectGdiImageSourceImpl;
sl@0
    39
class CSwDirectGdiImageTargetImpl;
sl@0
    40
class CFbsDrawDevice;
sl@0
    41
class CBitwiseBitmap;
sl@0
    42
class MFastBlend;
sl@0
    43
sl@0
    44
/**
sl@0
    45
Concrete (reference) implementation of a MDirectGdi Engine. It is a
sl@0
    46
collection of drawing routines which implement the software adaptation of DirectGDI.
sl@0
    47
*/
sl@0
    48
NONSHARABLE_CLASS(CSwDirectGdiEngine) : public CBase, public MDirectGdiEngine, public MDrawDeviceOrigin
sl@0
    49
	{
sl@0
    50
public:
sl@0
    51
	CSwDirectGdiEngine(CSwDirectGdiDriverImpl*);
sl@0
    52
	virtual ~CSwDirectGdiEngine();
sl@0
    53
	
sl@0
    54
	// from MDirectGdiEngine
sl@0
    55
	TInt Activate(RDirectGdiImageTarget& aTarget);
sl@0
    56
	void Deactivate();
sl@0
    57
	void SetOrigin(const TPoint& aOrigin);
sl@0
    58
	void SetClippingRegion(const TRegion& aRegion);
sl@0
    59
	void ResetClippingRegion();
sl@0
    60
	void SetDrawMode(DirectGdi::TDrawMode aMode);
sl@0
    61
	void SetPenColor(const TRgb& aColor);
sl@0
    62
	void SetPenStyle(DirectGdi::TPenStyle aStyle);
sl@0
    63
	void SetPenSize(const TSize& aSize);
sl@0
    64
	void SetTextShadowColor(const TRgb& aColor);
sl@0
    65
	void SetBrushColor(const TRgb& aColor);
sl@0
    66
	void SetBrushStyle(DirectGdi::TBrushStyle aStyle);
sl@0
    67
	void SetBrushOrigin(const TPoint& aOrigin);
sl@0
    68
	TInt SetBrushPattern(const CFbsBitmap& aPattern);
sl@0
    69
	void ResetBrushPattern();
sl@0
    70
	void SetFont(TUint32 aFontId);
sl@0
    71
	void ResetFont();
sl@0
    72
	void Reset();
sl@0
    73
	void Clear(const TRect& aRect);
sl@0
    74
	void Clear();
sl@0
    75
	void MoveTo(const TPoint& aPoint);
sl@0
    76
	void MoveBy(const TPoint& aVector);
sl@0
    77
	void Plot(const TPoint& aPoint);
sl@0
    78
	void DrawLine(const TPoint& aStart, const TPoint& aEnd);
sl@0
    79
	void DrawLineTo(const TPoint& aPoint);
sl@0
    80
	void DrawLineBy(const TPoint& aVector);
sl@0
    81
	void DrawRect(const TRect& aRect);
sl@0
    82
	void DrawRoundRect(const TRect& aRect, const TSize& aCornerSize);
sl@0
    83
	void DrawPolyLine(const TArray<TPoint>& aPointList);
sl@0
    84
	void DrawPolyLineNoEndPoint(const TArray<TPoint>& aPointList);
sl@0
    85
	void DrawPolygon(const TArray<TPoint>& aPoints, DirectGdi::TFillRule aRule);
sl@0
    86
	void DrawArc(const TRect& aRect, const TPoint& aStart, const TPoint& aEnd);
sl@0
    87
	void DrawPie(const TRect& aRect, const TPoint& aStart, const TPoint& aEnd);
sl@0
    88
	void DrawEllipse(const TRect& aRect);
sl@0
    89
	void BitBlt(const TPoint& aDestPos, const CFbsBitmap& aBitmap, const TRect& aSrcRect);
sl@0
    90
	void BitBltMasked(const TPoint& aDestPos, const CFbsBitmap& aBitmap, const TRect& aSrcRect,				
sl@0
    91
			const CFbsBitmap& aMask, TBool aInvertMask);	
sl@0
    92
	void BitBltMasked(const TPoint& aDestPos, const CFbsBitmap& aBitmap, const TRect& aSrcRect,				
sl@0
    93
			const CFbsBitmap& aAlpha, const TPoint& aAlphaPos);
sl@0
    94
	void DrawBitmap(const TRect& aDestRect, const CFbsBitmap& aBitmap, const TRect& aSrcRect);	
sl@0
    95
	void DrawBitmapMasked(const TRect& aDestRect, const CFbsBitmap& aBitmap, const TRect& aSrcRect,				
sl@0
    96
			const CFbsBitmap& aMask, TBool aInvertMask);	
sl@0
    97
	void DrawResource(const TRect& aDestRect, const RDirectGdiDrawableSource& aSource, const TRect& aSrcRect,
sl@0
    98
			DirectGdi::TGraphicsRotation aRotation);
sl@0
    99
	void DrawResource(const TPoint& aPos, const RDirectGdiDrawableSource& aSource,
sl@0
   100
			DirectGdi::TGraphicsRotation aRotation);
sl@0
   101
	void DrawResource(const TRect& aDestRect, const RDirectGdiDrawableSource& aSource,
sl@0
   102
			DirectGdi::TGraphicsRotation aRotation);
sl@0
   103
	void DrawResource(const TRect& aDestRect, const RDirectGdiDrawableSource& aSource, const TDesC8& aParam);
sl@0
   104
	void DrawGlyph(const TPoint& aPos, const TChar aChar, const TUint8* aGlyphImage,
sl@0
   105
			const TGlyphBitmapType aGlyphBitmapType, const TSize& aGlyphImageSize, const TRect& aClipRect,
sl@0
   106
			const DirectGdi::TGraphicsRotation aRotation = DirectGdi::EGraphicsRotationNone);	
sl@0
   107
	void CopyRect(const TPoint& aOffset, const TRect& aRect);
sl@0
   108
	void ExternalizeL(RWriteStream& aWriteStream);
sl@0
   109
	void InternalizeL(RReadStream& aReadStream);
sl@0
   110
	TInt GetInterface(TUid aInterfaceId, TAny*& aInterface);	
sl@0
   111
	void BeginDrawGlyph();
sl@0
   112
	void EndDrawGlyph();
sl@0
   113
	
sl@0
   114
	//from MDrawDeviceOrigin 
sl@0
   115
	TInt Set(const TPoint& aDrawOrigin);
sl@0
   116
	void Get(TPoint& aDrawOrigin);
sl@0
   117
sl@0
   118
private:
sl@0
   119
	CSwDirectGdiEngine();
sl@0
   120
	TBool AnalyseEllipse(const TRect& rc,TPoint& srad,TPoint& erad, TInt& startq,TInt& endq,TBool* quads);
sl@0
   121
	TUint32* ClipBinaryArray(TUint32* aArray, TUint32* aArrayLimit, TInt& aDataWd, TInt& aDataHt, TPoint& aPos, const TRect& aClipRect);
sl@0
   122
	void ClipFillLine(TPoint aLeft,TPoint aRight, TRect aClipRect);
sl@0
   123
	void CopyCharLine(TUint32* aBinaryDataPtr, TInt aBufferWords, const TUint8* aData, TInt aBitShift, TInt aCharWidth);
sl@0
   124
	void DrawPolyLineNoEndPoint(const TPoint* aPointList, TInt aNumPoints);
sl@0
   125
	void DoBitBlt(const TPoint& aDest, CBitwiseBitmap* aSrce, TUint32* aBase, TInt aStride,
sl@0
   126
			const TRect& aSrceRect);
sl@0
   127
	void DoBitBltAlpha(const TPoint& aDest,CBitwiseBitmap* aSourceBitmap, TUint32* aSourceBase,
sl@0
   128
			const TRect& aSourceRect, CBitwiseBitmap* aMaskBitmap,TUint32* aMaskBase,
sl@0
   129
			const TPoint& aAlphaPoint, TBool aInvertMask);
sl@0
   130
	void DoBitBltMasked(const TPoint& aDest, CBitwiseBitmap* aSourceBitmap, 
sl@0
   131
			TUint32* aSourceBase, const TRect& aSourceRect, CBitwiseBitmap* aMaskBitmap,
sl@0
   132
			TUint32* aMaskBase, TBool aInvertMask);	
sl@0
   133
	void DoBitBltMaskedFlicker(const TPoint& aDest, CBitwiseBitmap* aSourceBitmap, TUint32* aSourceBase,
sl@0
   134
			  const TRect& aSourceRect, CBitwiseBitmap* aMaskBitmap, TUint32* aMaskBase, TBool aInvertMask);
sl@0
   135
	void DoCopyRect(const TPoint& aOffset, const TRect& rect);
sl@0
   136
	void DoDrawLine(TPoint aPt1,TPoint aPt2,TBool aDrawStartPoint);
sl@0
   137
	void DoPlot(const TPoint& aPoint);
sl@0
   138
	void DoDrawBitmap(const TRect& aDestRect, CBitwiseBitmap* aBitmap, TUint32* aBase, TInt aStride,
sl@0
   139
			 const TRect& aSrceRect, const TRect& aClipRect);
sl@0
   140
	void DoDrawBitmapMasked(const TRect& aDestRect, CBitwiseBitmap* aSourceBitmap, TUint32* aSourceBase,
sl@0
   141
			   const TRect& aSourceRect, CBitwiseBitmap* aMaskBitmap, TUint32* aMaskBase, TBool aInvertMask,
sl@0
   142
			   const TRect& aClipRect);
sl@0
   143
	TInt CheckImageSource(TInt aSourceHandle, CSwDirectGdiImageSourceImpl*& aImpl, TSize* aImgSize);
sl@0
   144
	void DrawResourceCommon(const TRect& aDestRect,	const CSwDirectGdiImageSourceImpl* aImpl,
sl@0
   145
			const TRect& aSrcRect, DirectGdi::TGraphicsRotation aRotation);		
sl@0
   146
	void DoDrawResource(const TRect& aDestRect, const CSwDirectGdiImageSourceImpl* aImpl,
sl@0
   147
			const TRect& aSrceRect, DirectGdi::TGraphicsRotation aRotation, const TRect& aClipRect);
sl@0
   148
	void DoBlitResource(const TPoint& aDest, const CSwDirectGdiImageSourceImpl* aImpl,
sl@0
   149
			const TRect& aSrceRect, DirectGdi::TGraphicsRotation aRotation);
sl@0
   150
	void DoScaledBlitResource(const TRect& aDestRect, const CSwDirectGdiImageSourceImpl* aImpl,
sl@0
   151
			const TRect& aSrceRect, DirectGdi::TGraphicsRotation aRotation, const TRect& aClipRect);
sl@0
   152
	void DoDrawDottedWideLine(const TPoint& aPt1, const TPoint& aPt2, TBool aDrawStartPoint,
sl@0
   153
			 const TRect& aScreenRect, TRect aClipRect);
sl@0
   154
	void DoDrawSolidWideLine(const TPoint& aPt1, const TPoint& aPt2, TBool aDrawStartPoint,
sl@0
   155
			 const TRect& aScreenRect, TRect aClipRect);
sl@0
   156
	void DrawBitmapGlyph(const TPoint& aPos, const TUint8* aGlyphImage,
sl@0
   157
						 const TSize& aGlyphImageSize, const TRect& aClipRect);
sl@0
   158
	void DrawLargeBitmapGlyph(const TPoint& aPos, const TUint8* aGlyphImage,
sl@0
   159
							  const TSize& aGlyphImageSize, const TRect& aClipRect);
sl@0
   160
	void DrawRotatedBitmapGlyph(const TPoint& aPos, const TUint8* aGlyphImage,
sl@0
   161
								const TSize& aGlyphImageSize, const TRect& aClipRect, const DirectGdi::TGraphicsRotation aRotation);
sl@0
   162
	void DrawAntiAliasedGlyph(const TPoint& aPos, const TUint8* aGlyphImage,
sl@0
   163
							  const TSize& aGlyphImageSize, const TRect& aClipRect);
sl@0
   164
	void DrawRotatedAntiAliasedGlyph(const TPoint& aPos, const TUint8* aGlyphImage,
sl@0
   165
									 const TSize& aGlyphImageSize, const TRect& aClipRect, const DirectGdi::TGraphicsRotation aRotation);
sl@0
   166
	void DrawFourColourGlyph(const TPoint& aPos, const TUint8* aGlyphImage,
sl@0
   167
							 const TSize& aGlyphImageSize, const TRect& aClipRect);
sl@0
   168
	void DrawRotatedFourColourGlyph(const TPoint& aPos, const TUint8* aGlyphImage,
sl@0
   169
									const TSize& aGlyphImageSize, const TRect& aClipRect, const DirectGdi::TGraphicsRotation aRotation);
sl@0
   170
	void EllipseFill(const TRect& aRect);
sl@0
   171
	void EllipseOutline(const TRect& aRect);
sl@0
   172
	void EllipseOutlineWide(const TRect& aRect);
sl@0
   173
	TUint32* GetScanLineOffsetPtr(CBitwiseBitmap* aSrce, TUint32*& aSlptr, TInt aLength, TPoint aPixel,
sl@0
   174
								  TUint32* aBase, TLineScanningPosition& aLineScanningPosition, TUint aXOffset);
sl@0
   175
	inline static TInt16 Load16(const TUint8* aPtr) { return TInt16(aPtr[0]+(aPtr[1]<<8)); }
sl@0
   176
	TUint MemoryOffsetForPixelPitch(TUint aX, TDisplayMode aDisplayMode) const;
sl@0
   177
	void OutputCharLineMultiplied(TPoint aPrintPos, TUint32* aBuffer, TInt aDataLength, TInt aNum, const TRect& aClipRect);
sl@0
   178
	void OutputCharLineVertical(TPoint aPrintPos, TUint32* aBuffer, TInt aDataLength, TInt aNum, TInt aDirection, const TRect& aClipRect);
sl@0
   179
	TInt PenAllocate();
sl@0
   180
	void PenDrawClipped(TPoint aPoint, const TRect& aClipRect);
sl@0
   181
	void PenDrawDeferred(TPoint aPoint,TInt* aArray,TInt aFirstElement);
sl@0
   182
	void PieArcOutline(const TRect& ellrect,const TPoint& startradius, const TPoint& endradius, TBool pie);
sl@0
   183
	void PieFill(const TRect& ellrect, const TPoint& aStartIntersect, const TPoint& aEndIntersect,
sl@0
   184
			TInt aStartQuadrant, TInt aEndQuadrant, const TBool* aQuadrants);
sl@0
   185
	void PieShell(const TRect& ellrect,const TPoint& startradius, const TPoint& endradius,
sl@0
   186
				  const TBool* quads, TInt startquad, TInt endquad, TRect aClipRect);
sl@0
   187
	void PieSliver(const TRect& ellrect,const TPoint& startradius, const TPoint& endradius,
sl@0
   188
				   TInt quad, TRect aClipRect);
sl@0
   189
	void PieTriangles(TBool aInside,const TPoint& aStart,const TPoint& aEnd, TRect aClipRect);
sl@0
   190
	void PolyFill(const TPoint* aPointList, TInt aNumPoints, DirectGdi::TFillRule aFillRule);
sl@0
   191
	void PolyFill(const TArray<TPoint>* aPointList, DirectGdi::TFillRule aFillRule);
sl@0
   192
	void PolyFillLarge(const TArray<TPoint>* aPointList, DirectGdi::TFillRule aFillRule);
sl@0
   193
	void PolyFillLarge(const TPoint* aPointList, TInt aNumPoints, DirectGdi::TFillRule aFillRule);
sl@0
   194
	void PolyOutline(const TArray<TPoint>* aPointList);
sl@0
   195
	void PolyOutline(const TPoint* aPointList,TInt aNumPoints);
sl@0
   196
	void RectFill(const TRect& aRect);
sl@0
   197
	void ResetPenArray();
sl@0
   198
	void RoundRectFill(const TRect& aRect, const TSize& aCornerSize);
sl@0
   199
	void RoundRectOutline(const TRect& aRect, const TSize& aCornerSize);
sl@0
   200
	void SetPenArray(TInt* aPenArray);
sl@0
   201
	void TruncateRect(TRect& aRect);
sl@0
   202
	void Rotate90(TRect& aRect, const TPoint& aOrig);
sl@0
   203
	void Rotate180(TRect& aRect, const TPoint& aOrig);
sl@0
   204
	void Rotate270(TRect& aRect, const TPoint& aOrig);
sl@0
   205
	TBool RotatedSizeMatch(const TRect& aDst, const TRect& aSrc, DirectGdi::TGraphicsRotation aRot);
sl@0
   206
	void TileScanLine(TPtr8& aScanLine, TInt aLengthInPixels, const TPoint& aSrcPt,
sl@0
   207
			const CBitwiseBitmap* aMaskBitmap, TLineScanningPosition& aScanLinePos, 
sl@0
   208
			TUint32* aMaskBase, TDisplayMode aDisplayMode);
sl@0
   209
	TInt FastBlendInterface(const CBitwiseBitmap* aSource, const CBitwiseBitmap* aMask, MFastBlend*& aFastBlend) const;
sl@0
   210
	inline CGraphicsContext::TDrawMode GcDrawMode(DirectGdi::TDrawMode aMode) const ;
sl@0
   211
	TDisplayMode ScanLineBufferDisplayMode(CFbsDrawDevice* aDrawDevice);
sl@0
   212
sl@0
   213
private:
sl@0
   214
	CSwDirectGdiBitmap iBrushBitmap;
sl@0
   215
	TRgb iBrushColor;
sl@0
   216
	TPoint iBrushOrigin;
sl@0
   217
	DirectGdi::TBrushStyle iBrushStyle;	
sl@0
   218
	TRegionFix<1> iDefaultRegion;
sl@0
   219
	const TRegion* iDefaultRegionPtr;
sl@0
   220
	TInt iDotLength;
sl@0
   221
	TInt iDotMask;
sl@0
   222
	TInt iDotParam;
sl@0
   223
	TInt iDotDirection;
sl@0
   224
	CFbsDrawDevice* iDrawDevice;
sl@0
   225
	DirectGdi::TDrawMode iDrawMode;
sl@0
   226
	CSwDirectGdiDriverImpl* iDriver;
sl@0
   227
	TPoint iLinePosition;
sl@0
   228
	TPoint iOrigin;
sl@0
   229
	TPoint iDrawOrigin;
sl@0
   230
	TInt* iPenArray;
sl@0
   231
	TRgb iPenColor;			/**< The current pen colour. The default pen colour is black. */
sl@0
   232
	TRgb iTextShadowColor;	/**< Colour for text shadows. */
sl@0
   233
	TSize iPenSize;
sl@0
   234
	DirectGdi::TPenStyle iPenStyle;	
sl@0
   235
	RRegion iClippingRegion;
sl@0
   236
    CSwDirectGdiImageTargetImpl* iRenderingTarget;
sl@0
   237
#if defined(__ALLOW_FAST_BLEND_DISABLE__)
sl@0
   238
    TBool iFastBlendDisabled;
sl@0
   239
#endif
sl@0
   240
sl@0
   241
	};
sl@0
   242
sl@0
   243
/**
sl@0
   244
Converts a draw-mode enum from the DirectGdi namespace to the CGraphicsContext namespace.
sl@0
   245
*/
sl@0
   246
inline CGraphicsContext::TDrawMode CSwDirectGdiEngine::GcDrawMode(DirectGdi::TDrawMode aMode) const
sl@0
   247
	{
sl@0
   248
	switch(aMode)
sl@0
   249
		{
sl@0
   250
		case DirectGdi::EDrawModePEN:
sl@0
   251
			return CGraphicsContext::EDrawModePEN;
sl@0
   252
		case DirectGdi::EDrawModeWriteAlpha:
sl@0
   253
			return CGraphicsContext::EDrawModeWriteAlpha;
sl@0
   254
		default:
sl@0
   255
			return CGraphicsContext::EDrawModePEN;
sl@0
   256
		}
sl@0
   257
	}
sl@0
   258
sl@0
   259
#endif /*CSWDIRECTGDIENGINE_H*/