os/graphics/graphicsdeviceinterface/directgdiadaptation/swsrc/swdirectgdiengine.h
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicsdeviceinterface/directgdiadaptation/swsrc/swdirectgdiengine.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,259 @@
1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#ifndef CSWDIRECTGDIENGINE_H
1.20 +#define CSWDIRECTGDIENGINE_H
1.21 +
1.22 +/**
1.23 +@file
1.24 +@internalComponent
1.25 +*/
1.26 +
1.27 +#include "directgdiadapter.h"
1.28 +#include "swdirectgdibitmap.h"
1.29 +#include <graphics/directgdiengine.h>
1.30 +#include <e32base.h>
1.31 +#include <bitdraw.h>
1.32 +#include <bitdraworigin.h>
1.33 +#include <bitmap.h>
1.34 +
1.35 +// For use when testing the code, allows the fast blending to be disabled so back to back comparisons
1.36 +// can done be to check either timing or exact output.
1.37 +//#define __ALLOW_FAST_BLEND_DISABLE__
1.38 +
1.39 +class RDirectGdiDrawableSource;
1.40 +class CSwDirectGdiDriverImpl;
1.41 +class CSwDirectGdiImageSourceImpl;
1.42 +class CSwDirectGdiImageTargetImpl;
1.43 +class CFbsDrawDevice;
1.44 +class CBitwiseBitmap;
1.45 +class MFastBlend;
1.46 +
1.47 +/**
1.48 +Concrete (reference) implementation of a MDirectGdi Engine. It is a
1.49 +collection of drawing routines which implement the software adaptation of DirectGDI.
1.50 +*/
1.51 +NONSHARABLE_CLASS(CSwDirectGdiEngine) : public CBase, public MDirectGdiEngine, public MDrawDeviceOrigin
1.52 + {
1.53 +public:
1.54 + CSwDirectGdiEngine(CSwDirectGdiDriverImpl*);
1.55 + virtual ~CSwDirectGdiEngine();
1.56 +
1.57 + // from MDirectGdiEngine
1.58 + TInt Activate(RDirectGdiImageTarget& aTarget);
1.59 + void Deactivate();
1.60 + void SetOrigin(const TPoint& aOrigin);
1.61 + void SetClippingRegion(const TRegion& aRegion);
1.62 + void ResetClippingRegion();
1.63 + void SetDrawMode(DirectGdi::TDrawMode aMode);
1.64 + void SetPenColor(const TRgb& aColor);
1.65 + void SetPenStyle(DirectGdi::TPenStyle aStyle);
1.66 + void SetPenSize(const TSize& aSize);
1.67 + void SetTextShadowColor(const TRgb& aColor);
1.68 + void SetBrushColor(const TRgb& aColor);
1.69 + void SetBrushStyle(DirectGdi::TBrushStyle aStyle);
1.70 + void SetBrushOrigin(const TPoint& aOrigin);
1.71 + TInt SetBrushPattern(const CFbsBitmap& aPattern);
1.72 + void ResetBrushPattern();
1.73 + void SetFont(TUint32 aFontId);
1.74 + void ResetFont();
1.75 + void Reset();
1.76 + void Clear(const TRect& aRect);
1.77 + void Clear();
1.78 + void MoveTo(const TPoint& aPoint);
1.79 + void MoveBy(const TPoint& aVector);
1.80 + void Plot(const TPoint& aPoint);
1.81 + void DrawLine(const TPoint& aStart, const TPoint& aEnd);
1.82 + void DrawLineTo(const TPoint& aPoint);
1.83 + void DrawLineBy(const TPoint& aVector);
1.84 + void DrawRect(const TRect& aRect);
1.85 + void DrawRoundRect(const TRect& aRect, const TSize& aCornerSize);
1.86 + void DrawPolyLine(const TArray<TPoint>& aPointList);
1.87 + void DrawPolyLineNoEndPoint(const TArray<TPoint>& aPointList);
1.88 + void DrawPolygon(const TArray<TPoint>& aPoints, DirectGdi::TFillRule aRule);
1.89 + void DrawArc(const TRect& aRect, const TPoint& aStart, const TPoint& aEnd);
1.90 + void DrawPie(const TRect& aRect, const TPoint& aStart, const TPoint& aEnd);
1.91 + void DrawEllipse(const TRect& aRect);
1.92 + void BitBlt(const TPoint& aDestPos, const CFbsBitmap& aBitmap, const TRect& aSrcRect);
1.93 + void BitBltMasked(const TPoint& aDestPos, const CFbsBitmap& aBitmap, const TRect& aSrcRect,
1.94 + const CFbsBitmap& aMask, TBool aInvertMask);
1.95 + void BitBltMasked(const TPoint& aDestPos, const CFbsBitmap& aBitmap, const TRect& aSrcRect,
1.96 + const CFbsBitmap& aAlpha, const TPoint& aAlphaPos);
1.97 + void DrawBitmap(const TRect& aDestRect, const CFbsBitmap& aBitmap, const TRect& aSrcRect);
1.98 + void DrawBitmapMasked(const TRect& aDestRect, const CFbsBitmap& aBitmap, const TRect& aSrcRect,
1.99 + const CFbsBitmap& aMask, TBool aInvertMask);
1.100 + void DrawResource(const TRect& aDestRect, const RDirectGdiDrawableSource& aSource, const TRect& aSrcRect,
1.101 + DirectGdi::TGraphicsRotation aRotation);
1.102 + void DrawResource(const TPoint& aPos, const RDirectGdiDrawableSource& aSource,
1.103 + DirectGdi::TGraphicsRotation aRotation);
1.104 + void DrawResource(const TRect& aDestRect, const RDirectGdiDrawableSource& aSource,
1.105 + DirectGdi::TGraphicsRotation aRotation);
1.106 + void DrawResource(const TRect& aDestRect, const RDirectGdiDrawableSource& aSource, const TDesC8& aParam);
1.107 + void DrawGlyph(const TPoint& aPos, const TChar aChar, const TUint8* aGlyphImage,
1.108 + const TGlyphBitmapType aGlyphBitmapType, const TSize& aGlyphImageSize, const TRect& aClipRect,
1.109 + const DirectGdi::TGraphicsRotation aRotation = DirectGdi::EGraphicsRotationNone);
1.110 + void CopyRect(const TPoint& aOffset, const TRect& aRect);
1.111 + void ExternalizeL(RWriteStream& aWriteStream);
1.112 + void InternalizeL(RReadStream& aReadStream);
1.113 + TInt GetInterface(TUid aInterfaceId, TAny*& aInterface);
1.114 + void BeginDrawGlyph();
1.115 + void EndDrawGlyph();
1.116 +
1.117 + //from MDrawDeviceOrigin
1.118 + TInt Set(const TPoint& aDrawOrigin);
1.119 + void Get(TPoint& aDrawOrigin);
1.120 +
1.121 +private:
1.122 + CSwDirectGdiEngine();
1.123 + TBool AnalyseEllipse(const TRect& rc,TPoint& srad,TPoint& erad, TInt& startq,TInt& endq,TBool* quads);
1.124 + TUint32* ClipBinaryArray(TUint32* aArray, TUint32* aArrayLimit, TInt& aDataWd, TInt& aDataHt, TPoint& aPos, const TRect& aClipRect);
1.125 + void ClipFillLine(TPoint aLeft,TPoint aRight, TRect aClipRect);
1.126 + void CopyCharLine(TUint32* aBinaryDataPtr, TInt aBufferWords, const TUint8* aData, TInt aBitShift, TInt aCharWidth);
1.127 + void DrawPolyLineNoEndPoint(const TPoint* aPointList, TInt aNumPoints);
1.128 + void DoBitBlt(const TPoint& aDest, CBitwiseBitmap* aSrce, TUint32* aBase, TInt aStride,
1.129 + const TRect& aSrceRect);
1.130 + void DoBitBltAlpha(const TPoint& aDest,CBitwiseBitmap* aSourceBitmap, TUint32* aSourceBase,
1.131 + const TRect& aSourceRect, CBitwiseBitmap* aMaskBitmap,TUint32* aMaskBase,
1.132 + const TPoint& aAlphaPoint, TBool aInvertMask);
1.133 + void DoBitBltMasked(const TPoint& aDest, CBitwiseBitmap* aSourceBitmap,
1.134 + TUint32* aSourceBase, const TRect& aSourceRect, CBitwiseBitmap* aMaskBitmap,
1.135 + TUint32* aMaskBase, TBool aInvertMask);
1.136 + void DoBitBltMaskedFlicker(const TPoint& aDest, CBitwiseBitmap* aSourceBitmap, TUint32* aSourceBase,
1.137 + const TRect& aSourceRect, CBitwiseBitmap* aMaskBitmap, TUint32* aMaskBase, TBool aInvertMask);
1.138 + void DoCopyRect(const TPoint& aOffset, const TRect& rect);
1.139 + void DoDrawLine(TPoint aPt1,TPoint aPt2,TBool aDrawStartPoint);
1.140 + void DoPlot(const TPoint& aPoint);
1.141 + void DoDrawBitmap(const TRect& aDestRect, CBitwiseBitmap* aBitmap, TUint32* aBase, TInt aStride,
1.142 + const TRect& aSrceRect, const TRect& aClipRect);
1.143 + void DoDrawBitmapMasked(const TRect& aDestRect, CBitwiseBitmap* aSourceBitmap, TUint32* aSourceBase,
1.144 + const TRect& aSourceRect, CBitwiseBitmap* aMaskBitmap, TUint32* aMaskBase, TBool aInvertMask,
1.145 + const TRect& aClipRect);
1.146 + TInt CheckImageSource(TInt aSourceHandle, CSwDirectGdiImageSourceImpl*& aImpl, TSize* aImgSize);
1.147 + void DrawResourceCommon(const TRect& aDestRect, const CSwDirectGdiImageSourceImpl* aImpl,
1.148 + const TRect& aSrcRect, DirectGdi::TGraphicsRotation aRotation);
1.149 + void DoDrawResource(const TRect& aDestRect, const CSwDirectGdiImageSourceImpl* aImpl,
1.150 + const TRect& aSrceRect, DirectGdi::TGraphicsRotation aRotation, const TRect& aClipRect);
1.151 + void DoBlitResource(const TPoint& aDest, const CSwDirectGdiImageSourceImpl* aImpl,
1.152 + const TRect& aSrceRect, DirectGdi::TGraphicsRotation aRotation);
1.153 + void DoScaledBlitResource(const TRect& aDestRect, const CSwDirectGdiImageSourceImpl* aImpl,
1.154 + const TRect& aSrceRect, DirectGdi::TGraphicsRotation aRotation, const TRect& aClipRect);
1.155 + void DoDrawDottedWideLine(const TPoint& aPt1, const TPoint& aPt2, TBool aDrawStartPoint,
1.156 + const TRect& aScreenRect, TRect aClipRect);
1.157 + void DoDrawSolidWideLine(const TPoint& aPt1, const TPoint& aPt2, TBool aDrawStartPoint,
1.158 + const TRect& aScreenRect, TRect aClipRect);
1.159 + void DrawBitmapGlyph(const TPoint& aPos, const TUint8* aGlyphImage,
1.160 + const TSize& aGlyphImageSize, const TRect& aClipRect);
1.161 + void DrawLargeBitmapGlyph(const TPoint& aPos, const TUint8* aGlyphImage,
1.162 + const TSize& aGlyphImageSize, const TRect& aClipRect);
1.163 + void DrawRotatedBitmapGlyph(const TPoint& aPos, const TUint8* aGlyphImage,
1.164 + const TSize& aGlyphImageSize, const TRect& aClipRect, const DirectGdi::TGraphicsRotation aRotation);
1.165 + void DrawAntiAliasedGlyph(const TPoint& aPos, const TUint8* aGlyphImage,
1.166 + const TSize& aGlyphImageSize, const TRect& aClipRect);
1.167 + void DrawRotatedAntiAliasedGlyph(const TPoint& aPos, const TUint8* aGlyphImage,
1.168 + const TSize& aGlyphImageSize, const TRect& aClipRect, const DirectGdi::TGraphicsRotation aRotation);
1.169 + void DrawFourColourGlyph(const TPoint& aPos, const TUint8* aGlyphImage,
1.170 + const TSize& aGlyphImageSize, const TRect& aClipRect);
1.171 + void DrawRotatedFourColourGlyph(const TPoint& aPos, const TUint8* aGlyphImage,
1.172 + const TSize& aGlyphImageSize, const TRect& aClipRect, const DirectGdi::TGraphicsRotation aRotation);
1.173 + void EllipseFill(const TRect& aRect);
1.174 + void EllipseOutline(const TRect& aRect);
1.175 + void EllipseOutlineWide(const TRect& aRect);
1.176 + TUint32* GetScanLineOffsetPtr(CBitwiseBitmap* aSrce, TUint32*& aSlptr, TInt aLength, TPoint aPixel,
1.177 + TUint32* aBase, TLineScanningPosition& aLineScanningPosition, TUint aXOffset);
1.178 + inline static TInt16 Load16(const TUint8* aPtr) { return TInt16(aPtr[0]+(aPtr[1]<<8)); }
1.179 + TUint MemoryOffsetForPixelPitch(TUint aX, TDisplayMode aDisplayMode) const;
1.180 + void OutputCharLineMultiplied(TPoint aPrintPos, TUint32* aBuffer, TInt aDataLength, TInt aNum, const TRect& aClipRect);
1.181 + void OutputCharLineVertical(TPoint aPrintPos, TUint32* aBuffer, TInt aDataLength, TInt aNum, TInt aDirection, const TRect& aClipRect);
1.182 + TInt PenAllocate();
1.183 + void PenDrawClipped(TPoint aPoint, const TRect& aClipRect);
1.184 + void PenDrawDeferred(TPoint aPoint,TInt* aArray,TInt aFirstElement);
1.185 + void PieArcOutline(const TRect& ellrect,const TPoint& startradius, const TPoint& endradius, TBool pie);
1.186 + void PieFill(const TRect& ellrect, const TPoint& aStartIntersect, const TPoint& aEndIntersect,
1.187 + TInt aStartQuadrant, TInt aEndQuadrant, const TBool* aQuadrants);
1.188 + void PieShell(const TRect& ellrect,const TPoint& startradius, const TPoint& endradius,
1.189 + const TBool* quads, TInt startquad, TInt endquad, TRect aClipRect);
1.190 + void PieSliver(const TRect& ellrect,const TPoint& startradius, const TPoint& endradius,
1.191 + TInt quad, TRect aClipRect);
1.192 + void PieTriangles(TBool aInside,const TPoint& aStart,const TPoint& aEnd, TRect aClipRect);
1.193 + void PolyFill(const TPoint* aPointList, TInt aNumPoints, DirectGdi::TFillRule aFillRule);
1.194 + void PolyFill(const TArray<TPoint>* aPointList, DirectGdi::TFillRule aFillRule);
1.195 + void PolyFillLarge(const TArray<TPoint>* aPointList, DirectGdi::TFillRule aFillRule);
1.196 + void PolyFillLarge(const TPoint* aPointList, TInt aNumPoints, DirectGdi::TFillRule aFillRule);
1.197 + void PolyOutline(const TArray<TPoint>* aPointList);
1.198 + void PolyOutline(const TPoint* aPointList,TInt aNumPoints);
1.199 + void RectFill(const TRect& aRect);
1.200 + void ResetPenArray();
1.201 + void RoundRectFill(const TRect& aRect, const TSize& aCornerSize);
1.202 + void RoundRectOutline(const TRect& aRect, const TSize& aCornerSize);
1.203 + void SetPenArray(TInt* aPenArray);
1.204 + void TruncateRect(TRect& aRect);
1.205 + void Rotate90(TRect& aRect, const TPoint& aOrig);
1.206 + void Rotate180(TRect& aRect, const TPoint& aOrig);
1.207 + void Rotate270(TRect& aRect, const TPoint& aOrig);
1.208 + TBool RotatedSizeMatch(const TRect& aDst, const TRect& aSrc, DirectGdi::TGraphicsRotation aRot);
1.209 + void TileScanLine(TPtr8& aScanLine, TInt aLengthInPixels, const TPoint& aSrcPt,
1.210 + const CBitwiseBitmap* aMaskBitmap, TLineScanningPosition& aScanLinePos,
1.211 + TUint32* aMaskBase, TDisplayMode aDisplayMode);
1.212 + TInt FastBlendInterface(const CBitwiseBitmap* aSource, const CBitwiseBitmap* aMask, MFastBlend*& aFastBlend) const;
1.213 + inline CGraphicsContext::TDrawMode GcDrawMode(DirectGdi::TDrawMode aMode) const ;
1.214 + TDisplayMode ScanLineBufferDisplayMode(CFbsDrawDevice* aDrawDevice);
1.215 +
1.216 +private:
1.217 + CSwDirectGdiBitmap iBrushBitmap;
1.218 + TRgb iBrushColor;
1.219 + TPoint iBrushOrigin;
1.220 + DirectGdi::TBrushStyle iBrushStyle;
1.221 + TRegionFix<1> iDefaultRegion;
1.222 + const TRegion* iDefaultRegionPtr;
1.223 + TInt iDotLength;
1.224 + TInt iDotMask;
1.225 + TInt iDotParam;
1.226 + TInt iDotDirection;
1.227 + CFbsDrawDevice* iDrawDevice;
1.228 + DirectGdi::TDrawMode iDrawMode;
1.229 + CSwDirectGdiDriverImpl* iDriver;
1.230 + TPoint iLinePosition;
1.231 + TPoint iOrigin;
1.232 + TPoint iDrawOrigin;
1.233 + TInt* iPenArray;
1.234 + TRgb iPenColor; /**< The current pen colour. The default pen colour is black. */
1.235 + TRgb iTextShadowColor; /**< Colour for text shadows. */
1.236 + TSize iPenSize;
1.237 + DirectGdi::TPenStyle iPenStyle;
1.238 + RRegion iClippingRegion;
1.239 + CSwDirectGdiImageTargetImpl* iRenderingTarget;
1.240 +#if defined(__ALLOW_FAST_BLEND_DISABLE__)
1.241 + TBool iFastBlendDisabled;
1.242 +#endif
1.243 +
1.244 + };
1.245 +
1.246 +/**
1.247 +Converts a draw-mode enum from the DirectGdi namespace to the CGraphicsContext namespace.
1.248 +*/
1.249 +inline CGraphicsContext::TDrawMode CSwDirectGdiEngine::GcDrawMode(DirectGdi::TDrawMode aMode) const
1.250 + {
1.251 + switch(aMode)
1.252 + {
1.253 + case DirectGdi::EDrawModePEN:
1.254 + return CGraphicsContext::EDrawModePEN;
1.255 + case DirectGdi::EDrawModeWriteAlpha:
1.256 + return CGraphicsContext::EDrawModeWriteAlpha;
1.257 + default:
1.258 + return CGraphicsContext::EDrawModePEN;
1.259 + }
1.260 + }
1.261 +
1.262 +#endif /*CSWDIRECTGDIENGINE_H*/