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