os/graphics/graphicsdeviceinterface/directgdiadaptation/swsrc/swdirectgdipolygon.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 SWDIRECTGDIPOLYGON_H
    17 #define SWDIRECTGDIPOLYGON_H
    18 
    19 /**
    20 @file
    21 @internalComponent
    22 */
    23 
    24 #include "directgdiadapter.h"
    25 #include <gdi.h>
    26 #include <e32base.h>
    27 
    28 /**
    29 A utility class to efficiently fill polygons.
    30 @see CSwDirectGdiEngine::PolyFill
    31 @see CSwDirectGdiEngine::PolyFillLarge
    32 */
    33 NONSHARABLE_CLASS(CSwDirectGdiPolygonFiller) : public CBase
    34 	{
    35 public:
    36 
    37 	/**
    38 	Describes how pixels are to be displayed in the polygon. aUsage should be set to
    39 	one of these values before CSwDirectGdiPolygonFiller::Construct is used.
    40 	*/
    41 	enum TUsage
    42 		{
    43 		/**
    44 		A request for all pixel runs in sequential order.
    45 		*/
    46 		EGetAllPixelRunsSequentially,
    47 		/**
    48 		A request for all pixel runs in sequential order but only for specified lines.
    49 		*/
    50 		EGetPixelRunsSequentiallyForSpecifiedScanLines
    51 		};
    52 public:
    53 	CSwDirectGdiPolygonFiller();
    54 	~CSwDirectGdiPolygonFiller();
    55 	void Construct(const TArray<TPoint>* aPointArray, DirectGdi::TFillRule aFillRule,TUsage aUsage=EGetAllPixelRunsSequentially); // N.B. this cannot fail
    56 	void Construct(const TPoint* aPointList,TInt aNumPoints, DirectGdi::TFillRule aFillRule, TUsage aUsage=EGetAllPixelRunsSequentially); // N.B. this cannot fail
    57 	void Reset();
    58 	void GetNextPixelRun(TBool& aExists, TInt& aScanLine, TInt& aStart, TInt& aEnd);
    59 	void GetNextPixelRunOnSpecifiedScanLine(TBool& aExists, TInt aScanLine, TInt& aStart, TInt& aEnd);
    60 private: // data-types for the fast algorithm
    61 	struct SFastEdge
    62 		{
    63 		TInt upperVertex;
    64 		TInt lowerVertex;
    65 		TInt firstVertex;
    66 		};
    67 	struct SFastScanLineIntersection;
    68 	struct SFastActiveEdge
    69 		{
    70 		SFastEdge* edgePtr;
    71 		TLinearDDA lineGenerator;
    72 		SFastScanLineIntersection* scanLineIntersectionPtr;
    73 		};
    74 	struct SFastScanLineIntersection
    75 		{
    76 		TInt firstPixel;
    77 		TInt lastPixel;
    78 		SFastActiveEdge* activeEdgePtr;
    79 		};
    80 private: // data-types for the slow algorithm
    81 	struct SSlowScanLineIntersection
    82 		{
    83 		TInt firstPixel;
    84 		TInt lastPixel;
    85 		TInt firstVertexOfEdge;
    86 		};
    87 private: // data-types for both algorithms
    88 	struct SFastData
    89 		{
    90 		TPoint* vertexList;
    91 		SFastEdge* edgeList;
    92 		SFastActiveEdge* activeEdgeList;
    93 		SFastScanLineIntersection* scanLineIntersectionList;
    94 		TInt numActiveEdges;
    95 		TInt numScanLineIntersections;
    96 		TInt nextEdgeToActivate;
    97 		};
    98 	struct SSlowData
    99 		{
   100 		enum {EStoreSize=8};
   101 		TLinearDDA lineGenerator;
   102 		SSlowScanLineIntersection scanLineIntersectionList[EStoreSize];
   103 		TInt numIntersectionsWithSameFirstPixelPreviouslyMet;
   104 		TInt numIntersectionsWithSameFirstPixelMetThisTime;
   105 		TInt numScanLineIntersections;
   106 		TBool scanLineComplete;
   107 		TInt firstPixelOfLastIntersectionInPrevBuffer;
   108 		};
   109 private:
   110 	void Construct(DirectGdi::TFillRule aFillRule, TUsage aUsage);
   111 	void FastHandleVertexIntersection(TInt& aCurrentActiveEdge, TBool aIsLowerVertex);
   112 	void SetFastIntersection(SFastActiveEdge& aActiveEdge, SFastScanLineIntersection& aScanLineIntersection);
   113 	void SlowHandleVertexIntersection(SSlowScanLineIntersection& aScanLineIntersection, TInt& aVertexStartingCurrentEdge,TBool aIsLowerVertex);
   114 	void JumpToCurrentScanLine(TLinearDDA& aLineGenerator, const TPoint& aUpper, const TPoint& aLower,TPoint& aStartPos, TPoint& aEndPos) const;
   115 	const TPoint& Point(TInt aIndex);
   116 private:
   117 	const TArray<TPoint>* iPointArray; // not owned by the class
   118 	DirectGdi::TFillRule iFillRule;
   119 	TBool iUseFastAlgorithm;
   120 	TInt iNumVertexes;
   121 	TBool iToggler; // used by EAlternate fill-rule
   122 	TInt iNestingLevel; // used by EWinding fill-rule
   123 	TInt iScanLineIntersection;
   124 	TInt iRightMostPixelOnScanLine;
   125 	TInt iFirstVertex;
   126 	TBool iPolygonIsAllHorizontal;
   127 	TInt iFirstScanLine;
   128 	TInt iLastScanLine;
   129 	TInt iCurrentScanLine;
   130 	SFastData iFastData;
   131 	SSlowData iSlowData;
   132 private:
   133 	friend class TCompareEdgesUpperY;
   134 	friend class TCompareActiveEdgesFirstVertex;
   135 	friend class TCompareScanLineIntersectionsFirstPixel;
   136 	friend class TSwapEdges;
   137 	friend class TSwapActiveEdges;
   138 	friend class TSwapScanLineIntersections;
   139 	};
   140 
   141 #endif /*SWDIRECTGDIPOLYGON_H*/
   142