os/graphics/graphicsdeviceinterface/directgdiadaptation/swsrc/swdirectgdipolygon.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200 (2014-06-10)
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
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
#include "swdirectgdipolygon.h"
sl@0
    17
sl@0
    18
/**
sl@0
    19
A utility class used to sort vertex lists based on y coordinates.
sl@0
    20
@see CSwDirectGdiPolygonFiller
sl@0
    21
@see TKey
sl@0
    22
sl@0
    23
@internalComponent
sl@0
    24
*/
sl@0
    25
NONSHARABLE_CLASS(TCompareEdgesUpperY) : public TKey
sl@0
    26
	{
sl@0
    27
public:
sl@0
    28
	TCompareEdgesUpperY(const CSwDirectGdiPolygonFiller::SFastData& aFastData);
sl@0
    29
private:
sl@0
    30
	virtual TInt Compare(TInt aLeft,TInt aRight) const;
sl@0
    31
private:
sl@0
    32
	const CSwDirectGdiPolygonFiller::SFastData& iFastData;
sl@0
    33
	};
sl@0
    34
sl@0
    35
TCompareEdgesUpperY::TCompareEdgesUpperY(const CSwDirectGdiPolygonFiller::SFastData& aFastData):
sl@0
    36
	iFastData(aFastData)
sl@0
    37
	{
sl@0
    38
	}
sl@0
    39
sl@0
    40
/**
sl@0
    41
Compare edges based on their upper Y coordinate.
sl@0
    42
sl@0
    43
@param aLeft Index corresponding to the "left" side of the comparison. 
sl@0
    44
@param aRight Index corresponding to the "right" side of the comparison.
sl@0
    45
sl@0
    46
@return Zero, if the two keys are equal; negative, if the left key is less than the right key; positive, if the left key is greater than the right key.
sl@0
    47
sl@0
    48
@see TKey::Compare
sl@0
    49
*/
sl@0
    50
TInt TCompareEdgesUpperY::Compare(TInt aLeft,TInt aRight) const
sl@0
    51
	{
sl@0
    52
	const TInt leftUpperY=iFastData.vertexList[iFastData.edgeList[aLeft].upperVertex].iY;
sl@0
    53
	const TInt rightUpperY=iFastData.vertexList[iFastData.edgeList[aRight].upperVertex].iY;
sl@0
    54
	if (leftUpperY<rightUpperY)
sl@0
    55
		return -1;
sl@0
    56
	if (leftUpperY>rightUpperY)
sl@0
    57
		return 1;
sl@0
    58
	return 0;
sl@0
    59
	}
sl@0
    60
sl@0
    61
/**
sl@0
    62
A utility class used to swap entries in edgeList arrays during sort operations.
sl@0
    63
@see CSwDirectGdiPolygonFiller
sl@0
    64
@see TSwap
sl@0
    65
sl@0
    66
@internalComponent
sl@0
    67
*/
sl@0
    68
NONSHARABLE_CLASS(TSwapEdges) : public TSwap
sl@0
    69
	{
sl@0
    70
public:
sl@0
    71
	TSwapEdges(CSwDirectGdiPolygonFiller::SFastData& aFastData);
sl@0
    72
private:
sl@0
    73
	virtual void Swap(TInt aLeft,TInt aRight) const;
sl@0
    74
private:
sl@0
    75
	CSwDirectGdiPolygonFiller::SFastData& iFastData;
sl@0
    76
	};
sl@0
    77
sl@0
    78
TSwapEdges::TSwapEdges(CSwDirectGdiPolygonFiller::SFastData& aFastData):
sl@0
    79
	iFastData(aFastData)
sl@0
    80
	{
sl@0
    81
	}
sl@0
    82
sl@0
    83
/**
sl@0
    84
Swaps two elements of an edgeList array. 
sl@0
    85
sl@0
    86
@param aLeft The index of an array element participating in the swap. 
sl@0
    87
@param aRight The index of an array element participating in the swap.
sl@0
    88
sl@0
    89
@see TSwap::Swap
sl@0
    90
*/
sl@0
    91
void TSwapEdges::Swap(TInt aLeft,TInt aRight) const
sl@0
    92
	{
sl@0
    93
	CSwDirectGdiPolygonFiller::SFastEdge& leftEdge=iFastData.edgeList[aLeft];
sl@0
    94
	CSwDirectGdiPolygonFiller::SFastEdge& rightEdge=iFastData.edgeList[aRight];
sl@0
    95
sl@0
    96
	const CSwDirectGdiPolygonFiller::SFastEdge temp(leftEdge);
sl@0
    97
	leftEdge=rightEdge;
sl@0
    98
	rightEdge=temp;
sl@0
    99
	}
sl@0
   100
sl@0
   101
/**
sl@0
   102
A utility class used to sort active edge lists based on the order of their vertexes.
sl@0
   103
@see CSwDirectGdiPolygonFiller
sl@0
   104
@see TKey
sl@0
   105
sl@0
   106
@internalComponent
sl@0
   107
*/
sl@0
   108
NONSHARABLE_CLASS(TCompareActiveEdgesFirstVertex) : public TKey
sl@0
   109
	{
sl@0
   110
public:
sl@0
   111
	TCompareActiveEdgesFirstVertex(const CSwDirectGdiPolygonFiller::SFastData& aFastData);
sl@0
   112
private:
sl@0
   113
	virtual TInt Compare(TInt aLeft,TInt aRight) const;
sl@0
   114
private:
sl@0
   115
	const CSwDirectGdiPolygonFiller::SFastData& iFastData;
sl@0
   116
	};
sl@0
   117
sl@0
   118
TCompareActiveEdgesFirstVertex::TCompareActiveEdgesFirstVertex(const CSwDirectGdiPolygonFiller::SFastData& aFastData):
sl@0
   119
	iFastData(aFastData)
sl@0
   120
	{
sl@0
   121
	}
sl@0
   122
sl@0
   123
/**
sl@0
   124
Compare edges based on the order of their vertexes.
sl@0
   125
sl@0
   126
@param aLeft Index corresponding to the "left" side of the comparison. 
sl@0
   127
@param aRight Index corresponding to the "right" side of the comparison.
sl@0
   128
sl@0
   129
@return Zero, if the two keys are equal; negative, if the left key is less than the right key; positive, if the left key is greater than the right key.
sl@0
   130
sl@0
   131
@see TKey::Compare
sl@0
   132
*/
sl@0
   133
TInt TCompareActiveEdgesFirstVertex::Compare(TInt aLeft,TInt aRight) const
sl@0
   134
	{
sl@0
   135
	const TInt leftFirstVertex=iFastData.activeEdgeList[aLeft].edgePtr->firstVertex;
sl@0
   136
	const TInt rightFirstVertex=iFastData.activeEdgeList[aRight].edgePtr->firstVertex;
sl@0
   137
	if (leftFirstVertex<rightFirstVertex)
sl@0
   138
		return -1;
sl@0
   139
	if (leftFirstVertex>rightFirstVertex)
sl@0
   140
		return 1;
sl@0
   141
	return 0;
sl@0
   142
	}
sl@0
   143
sl@0
   144
/**
sl@0
   145
A utility class used to swap entries in activeEdgeList arrays during sort operations.
sl@0
   146
@see CSwDirectGdiPolygonFiller
sl@0
   147
@see TSwap
sl@0
   148
sl@0
   149
@internalComponent
sl@0
   150
*/
sl@0
   151
NONSHARABLE_CLASS(TSwapActiveEdges) : public TSwap
sl@0
   152
	{
sl@0
   153
public:
sl@0
   154
	TSwapActiveEdges(CSwDirectGdiPolygonFiller::SFastData& aFastData);
sl@0
   155
private:
sl@0
   156
	virtual void Swap(TInt aLeft,TInt aRight) const;
sl@0
   157
private:
sl@0
   158
	CSwDirectGdiPolygonFiller::SFastData& iFastData;
sl@0
   159
	};
sl@0
   160
sl@0
   161
TSwapActiveEdges::TSwapActiveEdges(CSwDirectGdiPolygonFiller::SFastData& aFastData):
sl@0
   162
	iFastData(aFastData)
sl@0
   163
	{
sl@0
   164
	}
sl@0
   165
sl@0
   166
/**
sl@0
   167
Swaps two elements of an activeEdgeList array. 
sl@0
   168
@param aLeft The index of an array element participating in the swap. 
sl@0
   169
@param aRight The index of an array element participating in the swap.
sl@0
   170
@see TSwap::Swap
sl@0
   171
*/
sl@0
   172
void TSwapActiveEdges::Swap(TInt aLeft,TInt aRight) const
sl@0
   173
	{
sl@0
   174
	CSwDirectGdiPolygonFiller::SFastActiveEdge& leftActiveEdge=iFastData.activeEdgeList[aLeft];
sl@0
   175
	CSwDirectGdiPolygonFiller::SFastActiveEdge& rightActiveEdge=iFastData.activeEdgeList[aRight];
sl@0
   176
sl@0
   177
	const CSwDirectGdiPolygonFiller::SFastActiveEdge temp(leftActiveEdge);
sl@0
   178
	leftActiveEdge=rightActiveEdge;
sl@0
   179
	rightActiveEdge=temp;
sl@0
   180
sl@0
   181
	if (leftActiveEdge.scanLineIntersectionPtr!=NULL)
sl@0
   182
		leftActiveEdge.scanLineIntersectionPtr->activeEdgePtr=&leftActiveEdge;
sl@0
   183
	if (rightActiveEdge.scanLineIntersectionPtr!=NULL)
sl@0
   184
		rightActiveEdge.scanLineIntersectionPtr->activeEdgePtr=&rightActiveEdge;
sl@0
   185
	}
sl@0
   186
sl@0
   187
/**
sl@0
   188
A utility class used to sort intersection lists based on the position of their first pixel.
sl@0
   189
@see CSwDirectGdiPolygonFiller
sl@0
   190
@see TKey
sl@0
   191
sl@0
   192
@internalComponent
sl@0
   193
*/
sl@0
   194
NONSHARABLE_CLASS(TCompareScanLineIntersectionsFirstPixel) : public TKey
sl@0
   195
	{
sl@0
   196
public:
sl@0
   197
	TCompareScanLineIntersectionsFirstPixel(const CSwDirectGdiPolygonFiller::SFastData& aFastData);
sl@0
   198
private:
sl@0
   199
	virtual TInt Compare(TInt aLeft,TInt aRight) const;
sl@0
   200
private:
sl@0
   201
	const CSwDirectGdiPolygonFiller::SFastData& iFastData;
sl@0
   202
	};
sl@0
   203
sl@0
   204
TCompareScanLineIntersectionsFirstPixel::TCompareScanLineIntersectionsFirstPixel(const CSwDirectGdiPolygonFiller::SFastData& aFastData):
sl@0
   205
	iFastData(aFastData)
sl@0
   206
	{
sl@0
   207
	}
sl@0
   208
sl@0
   209
/**
sl@0
   210
Compare intersections based on the order of their first pixel.
sl@0
   211
sl@0
   212
@param aLeft Index corresponding to the "left" side of the comparison. 
sl@0
   213
@param aRight Index corresponding to the "right" side of the comparison.
sl@0
   214
sl@0
   215
@return Zero, if the two keys are equal; negative, if the left key is less than the right key; positive, if the left key is greater than the right key.
sl@0
   216
sl@0
   217
@see TKey::Compare
sl@0
   218
*/
sl@0
   219
TInt TCompareScanLineIntersectionsFirstPixel::Compare(TInt aLeft,TInt aRight) const
sl@0
   220
	{
sl@0
   221
	const TInt leftFirstPixel=iFastData.scanLineIntersectionList[aLeft].firstPixel;
sl@0
   222
	const TInt rightFirstPixel=iFastData.scanLineIntersectionList[aRight].firstPixel;
sl@0
   223
	if (leftFirstPixel<rightFirstPixel)
sl@0
   224
		return -1;
sl@0
   225
	if (leftFirstPixel>rightFirstPixel)
sl@0
   226
		return 1;
sl@0
   227
	return 0;
sl@0
   228
	}
sl@0
   229
sl@0
   230
/**
sl@0
   231
A utility class used to swap entries in intersection list arrays during sort operations.
sl@0
   232
@see CSwDirectGdiPolygonFiller
sl@0
   233
@see TSwap
sl@0
   234
sl@0
   235
@internalComponent
sl@0
   236
*/
sl@0
   237
NONSHARABLE_CLASS(TSwapScanLineIntersections) : public TSwap
sl@0
   238
	{
sl@0
   239
public:
sl@0
   240
	TSwapScanLineIntersections(CSwDirectGdiPolygonFiller::SFastData& aFastData);
sl@0
   241
private:
sl@0
   242
	virtual void Swap(TInt aLeft,TInt aRight) const;
sl@0
   243
private:
sl@0
   244
	CSwDirectGdiPolygonFiller::SFastData& iFastData;
sl@0
   245
	};
sl@0
   246
sl@0
   247
TSwapScanLineIntersections::TSwapScanLineIntersections(CSwDirectGdiPolygonFiller::SFastData& aFastData):
sl@0
   248
	iFastData(aFastData)
sl@0
   249
	{
sl@0
   250
	}
sl@0
   251
sl@0
   252
/**
sl@0
   253
Swaps two elements of a scanLineIntersectionList array. 
sl@0
   254
@param aLeft The index of an array element participating in the swap. 
sl@0
   255
@param aRight The index of an array element participating in the swap.
sl@0
   256
@see TSwap::Swap
sl@0
   257
*/
sl@0
   258
void TSwapScanLineIntersections::Swap(TInt aLeft,TInt aRight) const
sl@0
   259
	{
sl@0
   260
	CSwDirectGdiPolygonFiller::SFastScanLineIntersection& leftScanLineIntersection=iFastData.scanLineIntersectionList[aLeft];
sl@0
   261
	CSwDirectGdiPolygonFiller::SFastScanLineIntersection& rightScanLineIntersection=iFastData.scanLineIntersectionList[aRight];
sl@0
   262
sl@0
   263
	const CSwDirectGdiPolygonFiller::SFastScanLineIntersection temp(leftScanLineIntersection);
sl@0
   264
	leftScanLineIntersection=rightScanLineIntersection;
sl@0
   265
	rightScanLineIntersection=temp;
sl@0
   266
sl@0
   267
	leftScanLineIntersection.activeEdgePtr->scanLineIntersectionPtr=&leftScanLineIntersection;
sl@0
   268
	rightScanLineIntersection.activeEdgePtr->scanLineIntersectionPtr=&rightScanLineIntersection;
sl@0
   269
	}
sl@0
   270
sl@0
   271
/**
sl@0
   272
Sorts array elements
sl@0
   273
sl@0
   274
@param aCount The number of elements in the array.
sl@0
   275
@param aKey A reference to a suitably initialised TKey derived object.
sl@0
   276
@param aSwap A reference to a suitably initialised TSwap derived object.
sl@0
   277
@panic DGDIAdapter 1015, if QuickSort failed.
sl@0
   278
sl@0
   279
@internalComponent
sl@0
   280
*/
sl@0
   281
LOCAL_C void Sort(TInt aCount,const TKey& aKey,const TSwap& aSwap)
sl@0
   282
	{
sl@0
   283
#if 1 // quick sort
sl@0
   284
	const TInt error=User::QuickSort(aCount,aKey,aSwap);
sl@0
   285
	GRAPHICS_ASSERT_ALWAYS(error==KErrNone, EDirectGdiPanicPolygonFiller);
sl@0
   286
#elif 0 // bubble sort
sl@0
   287
	for (TInt i=1; i<aCount; ++i)
sl@0
   288
		{
sl@0
   289
		for (TInt j=i; j>0; --j)
sl@0
   290
			{
sl@0
   291
			if (aKey.Compare(j-1,j)>0)
sl@0
   292
				{
sl@0
   293
				aSwap.Swap(j-1,j);
sl@0
   294
				}
sl@0
   295
			}
sl@0
   296
		}
sl@0
   297
#else // heap sort
sl@0
   298
	TInt startOfSortedPortion=aCount;
sl@0
   299
	if (startOfSortedPortion>1)
sl@0
   300
		{
sl@0
   301
		TInt startOfHeap=startOfSortedPortion>>1;
sl@0
   302
		FOREVER
sl@0
   303
			{
sl@0
   304
			GRAPHICS_ASSERT_DEBUG(startOfHeap>=0, EDirectGdiPanicPolygonFiller);
sl@0
   305
			if (startOfHeap!=0)
sl@0
   306
				{
sl@0
   307
				--startOfHeap;
sl@0
   308
				}
sl@0
   309
			else
sl@0
   310
				{
sl@0
   311
				--startOfSortedPortion;
sl@0
   312
				aSwap.Swap(startOfSortedPortion,0);
sl@0
   313
				GRAPHICS_ASSERT_DEBUG(startOfSortedPortion>=1, EDirectGdiPanicPolygonFiller);
sl@0
   314
				if (startOfSortedPortion==1)
sl@0
   315
					{
sl@0
   316
					break;
sl@0
   317
					}
sl@0
   318
				}
sl@0
   319
			// put aArray[startOfHeap] into the correct place in the heap
sl@0
   320
			TInt i=startOfHeap;
sl@0
   321
			FOREVER
sl@0
   322
				{
sl@0
   323
				TInt j=(i+1)<<1;
sl@0
   324
				if ((j>=startOfSortedPortion) || (aKey.Compare(j-1,j)>0))
sl@0
   325
					{
sl@0
   326
					--j;
sl@0
   327
					}
sl@0
   328
				if ((j>=startOfSortedPortion) || (aKey.Compare(i,j)>=0))
sl@0
   329
					{
sl@0
   330
					break;
sl@0
   331
					}
sl@0
   332
				aSwap.Swap(i,j);
sl@0
   333
				i=j;
sl@0
   334
				}
sl@0
   335
			}
sl@0
   336
		}
sl@0
   337
#endif
sl@0
   338
#if defined(_DEBUG)
sl@0
   339
	{
sl@0
   340
	for (TInt i=1; i<aCount; ++i)
sl@0
   341
		{
sl@0
   342
		GRAPHICS_ASSERT_DEBUG(aKey.Compare(i-1,i)<=0, EDirectGdiPanicPolygonFiller);
sl@0
   343
		}
sl@0
   344
	}
sl@0
   345
#endif
sl@0
   346
	}
sl@0
   347
sl@0
   348
/*
sl@0
   349
 CSwDirectGdiPolygonFiller
sl@0
   350
 */
sl@0
   351
 
sl@0
   352
/**
sl@0
   353
 Constructor which initialises all member data to zero, EFalse or null for 
sl@0
   354
 TInt, TBool pointers respectively.
sl@0
   355
 */
sl@0
   356
CSwDirectGdiPolygonFiller::CSwDirectGdiPolygonFiller():
sl@0
   357
	CBase(),
sl@0
   358
	iPointArray(NULL),
sl@0
   359
	iFillRule(DirectGdi::EAlternate),
sl@0
   360
	iUseFastAlgorithm(EFalse),
sl@0
   361
	iNumVertexes(0),
sl@0
   362
	iToggler(EFalse),
sl@0
   363
	iNestingLevel(0),
sl@0
   364
	iScanLineIntersection(0),
sl@0
   365
	iRightMostPixelOnScanLine(0),
sl@0
   366
	iFirstVertex(0),
sl@0
   367
	iPolygonIsAllHorizontal(EFalse),
sl@0
   368
	iFirstScanLine(0),
sl@0
   369
	iLastScanLine(0),
sl@0
   370
	iCurrentScanLine(0)
sl@0
   371
	{
sl@0
   372
	iFastData.vertexList=NULL;
sl@0
   373
	iFastData.edgeList=NULL;
sl@0
   374
	iFastData.activeEdgeList=NULL;
sl@0
   375
	iFastData.scanLineIntersectionList=NULL;
sl@0
   376
	iFastData.numActiveEdges=0;
sl@0
   377
	iFastData.numScanLineIntersections=0;
sl@0
   378
	iFastData.nextEdgeToActivate=0;
sl@0
   379
	iSlowData.numIntersectionsWithSameFirstPixelPreviouslyMet=0;
sl@0
   380
	iSlowData.numIntersectionsWithSameFirstPixelMetThisTime=0;
sl@0
   381
	iSlowData.numScanLineIntersections=0;
sl@0
   382
	iSlowData.scanLineComplete=EFalse;
sl@0
   383
	iSlowData.firstPixelOfLastIntersectionInPrevBuffer=0;
sl@0
   384
	}
sl@0
   385
sl@0
   386
/**
sl@0
   387
Destructor calls reset on the polygon.
sl@0
   388
*/
sl@0
   389
CSwDirectGdiPolygonFiller::~CSwDirectGdiPolygonFiller()
sl@0
   390
	{
sl@0
   391
	Reset();
sl@0
   392
	}
sl@0
   393
sl@0
   394
/**
sl@0
   395
An overloaded version of Construct which allows the list of points to be passed in as a point array.
sl@0
   396
Exactly the same behaviour and structure as above. This should not fail. This method does not require the 
sl@0
   397
number of nodes to be given as a parameter.
sl@0
   398
sl@0
   399
@param aPointArray A pointer to point array, as opposed to a pointer to a point list.
sl@0
   400
@param aFillRule How filling should be achieved, as described by a DirectGdi::TFillRule object.
sl@0
   401
@param aUsage How the polygon should be used.
sl@0
   402
@panic DGDIAdapter 1015, if aPointArray is NULL.
sl@0
   403
*/
sl@0
   404
void CSwDirectGdiPolygonFiller::Construct(const TArray<TPoint>* aPointArray, 
sl@0
   405
										DirectGdi::TFillRule aFillRule, TUsage aUsage)
sl@0
   406
	{
sl@0
   407
	GRAPHICS_ASSERT_ALWAYS(aPointArray!=NULL,EDirectGdiPanicPolygonFiller);
sl@0
   408
	iPointArray=aPointArray;
sl@0
   409
	iNumVertexes=iPointArray->Count();
sl@0
   410
	Construct(aFillRule,aUsage);
sl@0
   411
	}
sl@0
   412
sl@0
   413
/**
sl@0
   414
Builds up the internal meta-data needed to fill the polygon.
sl@0
   415
sl@0
   416
@param aFillRule How filling should be achieved, as described by a DirectGdi::TFillRule object.
sl@0
   417
@param aUsage How the polygon should be used, see TUsage enumeration.
sl@0
   418
@panic DGDIAdapter 1015, if aFillRule is invalid, or aUsage is invalid. 
sl@0
   419
*/
sl@0
   420
void CSwDirectGdiPolygonFiller::Construct(DirectGdi::TFillRule aFillRule, TUsage aUsage)
sl@0
   421
	{
sl@0
   422
	GRAPHICS_ASSERT_ALWAYS((aFillRule==DirectGdi::EAlternate) || (aFillRule==DirectGdi::EWinding),
sl@0
   423
																					EDirectGdiPanicPolygonFiller);
sl@0
   424
	GRAPHICS_ASSERT_ALWAYS((aUsage==EGetAllPixelRunsSequentially) || (aUsage==EGetPixelRunsSequentiallyForSpecifiedScanLines),
sl@0
   425
																					EDirectGdiPanicPolygonFiller);
sl@0
   426
	TInt i, j;
sl@0
   427
	iFillRule=aFillRule;
sl@0
   428
	iUseFastAlgorithm=(aUsage==EGetAllPixelRunsSequentially);
sl@0
   429
	iToggler=EFalse;
sl@0
   430
	iNestingLevel=0;
sl@0
   431
	iScanLineIntersection=0;
sl@0
   432
	iRightMostPixelOnScanLine=KMinTInt;
sl@0
   433
	// find the first vertex and see if the polygon is all horizontal
sl@0
   434
	iFirstVertex=0; // dummy default value
sl@0
   435
	iPolygonIsAllHorizontal=ETrue;
sl@0
   436
sl@0
   437
	for (i=0; i<iNumVertexes; ++i)
sl@0
   438
		if (Point(i).iY!=Point((i+1)%iNumVertexes).iY)
sl@0
   439
			{
sl@0
   440
			// i is now set to the vertex before the first non-horizontal edge
sl@0
   441
sl@0
   442
			// set j%iNumVertexes to the vertex before the next non-horizontal edge
sl@0
   443
			for (j=i+1; Point(j%iNumVertexes).iY==Point((j+1)%iNumVertexes).iY; ++j)
sl@0
   444
				;
sl@0
   445
			j%=iNumVertexes;
sl@0
   446
			TInt first=Point(i).iY;
sl@0
   447
			TInt middle=Point(j).iY;
sl@0
   448
			TInt last=Point((j+1)%iNumVertexes).iY;
sl@0
   449
sl@0
   450
			// if vertex j is a max or min point, set the first-vertex to be j
sl@0
   451
			if ((middle<first)==(middle<last))
sl@0
   452
				{
sl@0
   453
				iFirstVertex=j;
sl@0
   454
				iPolygonIsAllHorizontal=EFalse;
sl@0
   455
				break;
sl@0
   456
				}
sl@0
   457
			}
sl@0
   458
sl@0
   459
	if (iUseFastAlgorithm)
sl@0
   460
		{
sl@0
   461
		iFastData.vertexList=(TPoint*)User::Alloc(sizeof(TPoint)*iNumVertexes);
sl@0
   462
		iFastData.edgeList=(SFastEdge*)User::Alloc(sizeof(SFastEdge)*iNumVertexes);
sl@0
   463
		iFastData.activeEdgeList=(SFastActiveEdge*)User::Alloc(sizeof(SFastActiveEdge)*iNumVertexes);
sl@0
   464
		iFastData.scanLineIntersectionList=(SFastScanLineIntersection*)User::Alloc(sizeof(SFastScanLineIntersection)*iNumVertexes);
sl@0
   465
		if ((iFastData.vertexList==NULL) ||
sl@0
   466
			(iFastData.edgeList==NULL) ||
sl@0
   467
			(iFastData.activeEdgeList==NULL) ||
sl@0
   468
			(iFastData.scanLineIntersectionList==NULL))
sl@0
   469
			{
sl@0
   470
			Reset(); // sets iUseFastAlgorithm to EFalse among other things
sl@0
   471
			}
sl@0
   472
		}
sl@0
   473
	
sl@0
   474
	if (iUseFastAlgorithm)
sl@0
   475
		{
sl@0
   476
		for(TInt vertexcount=0;vertexcount<iNumVertexes;vertexcount++)
sl@0
   477
			new(&iFastData.activeEdgeList[vertexcount]) SFastActiveEdge;
sl@0
   478
		iFastData.numActiveEdges=0;
sl@0
   479
		iFastData.numScanLineIntersections=0;
sl@0
   480
		iFastData.nextEdgeToActivate=0;
sl@0
   481
sl@0
   482
		// put the points into the vertex-list
sl@0
   483
		// N.B. this array is used for speed since CArrayXxxs are slower for indexing into than built-in arrays
sl@0
   484
		for (i=0; i<iNumVertexes; ++i)
sl@0
   485
			{
sl@0
   486
			// If iFastData.vertexList is NULL this will never be run. iFastData.vertexList is checked 
sl@0
   487
			// above after which iUseFastAlgorithm is set to EFalse if it is NULL (in Reset())
sl@0
   488
			// coverity[var_deref_op]
sl@0
   489
			iFastData.vertexList[i]=Point((i+iFirstVertex)%iNumVertexes);
sl@0
   490
			}
sl@0
   491
sl@0
   492
		// create edge-list
sl@0
   493
		for (i=0; i<iNumVertexes; ++i)
sl@0
   494
			{
sl@0
   495
			// See preceding coverity comment
sl@0
   496
			// coverity[var_deref_op]
sl@0
   497
			if (iFastData.vertexList[i].iY<iFastData.vertexList[(i+1)%iNumVertexes].iY)
sl@0
   498
				{
sl@0
   499
				iFastData.edgeList[i].upperVertex=i;
sl@0
   500
				iFastData.edgeList[i].lowerVertex=(i+1)%iNumVertexes;
sl@0
   501
				}
sl@0
   502
			else
sl@0
   503
				{
sl@0
   504
				iFastData.edgeList[i].upperVertex=(i+1)%iNumVertexes;
sl@0
   505
				iFastData.edgeList[i].lowerVertex=i;
sl@0
   506
				}
sl@0
   507
			iFastData.edgeList[i].firstVertex=i;
sl@0
   508
			}
sl@0
   509
sl@0
   510
		// sort edge-list into order of increasing upper y-position
sl@0
   511
		Sort(iNumVertexes,TCompareEdgesUpperY(iFastData),TSwapEdges(iFastData));
sl@0
   512
sl@0
   513
		// find the first scan-line
sl@0
   514
		iFirstScanLine=iFastData.vertexList[iFastData.edgeList[0].upperVertex].iY;
sl@0
   515
sl@0
   516
		// find the last scan-line
sl@0
   517
		iLastScanLine=iFirstScanLine;
sl@0
   518
		for (i=0; i<iNumVertexes; ++i)
sl@0
   519
			if (iLastScanLine<iFastData.vertexList[i].iY)
sl@0
   520
				iLastScanLine=iFastData.vertexList[i].iY;
sl@0
   521
		}
sl@0
   522
	else
sl@0
   523
		{
sl@0
   524
		iSlowData.numIntersectionsWithSameFirstPixelPreviouslyMet=0;
sl@0
   525
		iSlowData.scanLineComplete=EFalse;
sl@0
   526
		iSlowData.firstPixelOfLastIntersectionInPrevBuffer=KMinTInt;
sl@0
   527
sl@0
   528
		// find the first and last scan-lines
sl@0
   529
		iFirstScanLine=KMaxTInt;
sl@0
   530
		iLastScanLine=KMinTInt;
sl@0
   531
		for (i=0; i<iNumVertexes; ++i)
sl@0
   532
			{
sl@0
   533
			TInt y=Point(i).iY;
sl@0
   534
			if (iFirstScanLine>y)
sl@0
   535
				iFirstScanLine=y;
sl@0
   536
			if (iLastScanLine<y)
sl@0
   537
				iLastScanLine=y;
sl@0
   538
			}
sl@0
   539
		}
sl@0
   540
sl@0
   541
	iCurrentScanLine=iFirstScanLine;
sl@0
   542
	}
sl@0
   543
sl@0
   544
/**
sl@0
   545
Frees any data held in the polygon’s lists of edges, vertexes and scan lines, and sets these values to NULL.
sl@0
   546
It also has the feature of setting iUseFastAlgorithm = EFalse.
sl@0
   547
*/
sl@0
   548
void CSwDirectGdiPolygonFiller::Reset()
sl@0
   549
	{
sl@0
   550
	if(iUseFastAlgorithm)
sl@0
   551
		{
sl@0
   552
		if(iFastData.vertexList)
sl@0
   553
			{
sl@0
   554
			User::Free(iFastData.vertexList);
sl@0
   555
			iFastData.vertexList=NULL;
sl@0
   556
			}
sl@0
   557
		if(iFastData.edgeList)
sl@0
   558
			{
sl@0
   559
			User::Free(iFastData.edgeList);
sl@0
   560
			iFastData.edgeList=NULL;
sl@0
   561
			}
sl@0
   562
		if(iFastData.activeEdgeList)
sl@0
   563
			{
sl@0
   564
			User::Free(iFastData.activeEdgeList);
sl@0
   565
			iFastData.activeEdgeList=NULL;
sl@0
   566
			}
sl@0
   567
		if(iFastData.scanLineIntersectionList)
sl@0
   568
			{
sl@0
   569
			User::Free(iFastData.scanLineIntersectionList);
sl@0
   570
			iFastData.scanLineIntersectionList=NULL;
sl@0
   571
			}
sl@0
   572
		iUseFastAlgorithm=EFalse;
sl@0
   573
		}
sl@0
   574
	}
sl@0
   575
sl@0
   576
/**
sl@0
   577
Method is used to calculate the locations of vertex interactions between the polygon and scan lines. 
sl@0
   578
An initial scan line is required. It calculates the start and end positions on the line. The method
sl@0
   579
can use either the fast or slow polygon algorithm depending upon the state of aUsage. Polygon filling
sl@0
   580
is also addressed by this method.
sl@0
   581
sl@0
   582
@param aExists Will be set to EFalse if a polygon with no vertexes is passed in, otherwise ETrue on return.
sl@0
   583
@param aScanLine On return will contain iScanline at the beginning of the operation.
sl@0
   584
@param aStart On return, contains the position on the scan line to start the run.
sl@0
   585
@param aEnd On return, contains the position on the scan line to end the run.
sl@0
   586
@panic DGDIAdapter 1015 (debug only)
sl@0
   587
*/
sl@0
   588
void CSwDirectGdiPolygonFiller::GetNextPixelRun(TBool& aExists, TInt& aScanLine, TInt& aStart, 
sl@0
   589
											  TInt& aEnd)
sl@0
   590
	{
sl@0
   591
	if (iCurrentScanLine>iLastScanLine)
sl@0
   592
		{
sl@0
   593
		aExists=EFalse;
sl@0
   594
		return;
sl@0
   595
		}
sl@0
   596
sl@0
   597
	aExists=ETrue;
sl@0
   598
	aScanLine=iCurrentScanLine;
sl@0
   599
sl@0
   600
	if (iPolygonIsAllHorizontal)
sl@0
   601
		{
sl@0
   602
		// set the start after the end
sl@0
   603
		aStart=KMinTInt+1;
sl@0
   604
		aEnd=KMinTInt;
sl@0
   605
		++iCurrentScanLine;
sl@0
   606
		return;
sl@0
   607
		}
sl@0
   608
sl@0
   609
	if (iUseFastAlgorithm)
sl@0
   610
		{
sl@0
   611
		TInt i, j;
sl@0
   612
sl@0
   613
		if (iScanLineIntersection==0)
sl@0
   614
			{
sl@0
   615
			// add any new edges to the active-edge-list
sl@0
   616
			for (; (iFastData.nextEdgeToActivate<iNumVertexes) &&
sl@0
   617
					(iFastData.vertexList[iFastData.edgeList[iFastData.nextEdgeToActivate].upperVertex].iY==iCurrentScanLine);
sl@0
   618
					++iFastData.numActiveEdges, ++iFastData.nextEdgeToActivate)
sl@0
   619
				{
sl@0
   620
				iFastData.activeEdgeList[iFastData.numActiveEdges].edgePtr=&iFastData.edgeList[iFastData.nextEdgeToActivate];
sl@0
   621
				iFastData.activeEdgeList[iFastData.numActiveEdges].lineGenerator.Construct(
sl@0
   622
														iFastData.vertexList[iFastData.edgeList[iFastData.nextEdgeToActivate].upperVertex],
sl@0
   623
														iFastData.vertexList[iFastData.edgeList[iFastData.nextEdgeToActivate].lowerVertex]);
sl@0
   624
				iFastData.activeEdgeList[iFastData.numActiveEdges].scanLineIntersectionPtr=NULL;
sl@0
   625
				}
sl@0
   626
sl@0
   627
			// sort the active-edge-list into order of adjacent edges (if possible)
sl@0
   628
			Sort(iFastData.numActiveEdges,TCompareActiveEdgesFirstVertex(iFastData),TSwapActiveEdges(iFastData));
sl@0
   629
sl@0
   630
			// find the intersection of each active-edge with the current scan-line
sl@0
   631
			// for max/min vertex-runs (e.g. \/, \_/, \__/, etc.) add 2 intersections for each run
sl@0
   632
			// for other vertex-runs (e.g. /----/) add 1 intersection for each run
sl@0
   633
			for (i=0; i<iFastData.numActiveEdges; ++i)
sl@0
   634
				{
sl@0
   635
				// check that active-edge i is not horizontal
sl@0
   636
				GRAPHICS_ASSERT_DEBUG(iFastData.vertexList[iFastData.activeEdgeList[i].edgePtr->upperVertex].iY!=
sl@0
   637
							   iFastData.vertexList[iFastData.activeEdgeList[i].edgePtr->lowerVertex].iY, EDirectGdiPanicPolygonFiller);
sl@0
   638
sl@0
   639
				if (iFastData.vertexList[iFastData.activeEdgeList[i].edgePtr->upperVertex].iY==iCurrentScanLine)
sl@0
   640
					// the scan-line is intersecting active-edge i at its upper-vertex
sl@0
   641
					FastHandleVertexIntersection(i, EFalse);
sl@0
   642
				else if (iFastData.vertexList[iFastData.activeEdgeList[i].edgePtr->lowerVertex].iY==iCurrentScanLine)
sl@0
   643
					// the scan-line is intersecting active-edge i at its lower-vertex
sl@0
   644
					FastHandleVertexIntersection(i, ETrue);
sl@0
   645
				else
sl@0
   646
					// the scan-line is intersecting active-edge i at neither of its vertexes
sl@0
   647
					SetFastIntersection(iFastData.activeEdgeList[i],*iFastData.activeEdgeList[i].scanLineIntersectionPtr);
sl@0
   648
				}
sl@0
   649
sl@0
   650
			// N.B. iFastData.numScanLineIntersections is less than or equal to iFastData.numActiveEdges
sl@0
   651
sl@0
   652
			// sort the intersection-list into increasing order of first-pixel
sl@0
   653
			Sort(iFastData.numScanLineIntersections,TCompareScanLineIntersectionsFirstPixel(iFastData),TSwapScanLineIntersections(iFastData));
sl@0
   654
sl@0
   655
			GRAPHICS_ASSERT_DEBUG(iFastData.numScanLineIntersections>=2, EDirectGdiPanicPolygonFiller);
sl@0
   656
			}
sl@0
   657
sl@0
   658
		// depending on the rule used, find the pixel-run
sl@0
   659
		TBool doFill=EFalse; // dummy initialization to prevent compiler warning
sl@0
   660
		if (iScanLineIntersection<iFastData.numScanLineIntersections-1)
sl@0
   661
			{
sl@0
   662
			switch (iFillRule)
sl@0
   663
				{
sl@0
   664
			case DirectGdi::EAlternate:
sl@0
   665
				iToggler=!iToggler;
sl@0
   666
				doFill=iToggler;
sl@0
   667
				break;
sl@0
   668
			case DirectGdi::EWinding:
sl@0
   669
					GRAPHICS_ASSERT_DEBUG(iFastData.vertexList[iFastData.scanLineIntersectionList[iScanLineIntersection].activeEdgePtr->edgePtr->lowerVertex].iY!=
sl@0
   670
								   iFastData.vertexList[iFastData.scanLineIntersectionList[iScanLineIntersection].activeEdgePtr->edgePtr->upperVertex].iY,
sl@0
   671
																										EDirectGdiPanicPolygonFiller);
sl@0
   672
sl@0
   673
					if (iFastData.scanLineIntersectionList[iScanLineIntersection].activeEdgePtr->edgePtr->lowerVertex==
sl@0
   674
						(iFastData.scanLineIntersectionList[iScanLineIntersection].activeEdgePtr->edgePtr->upperVertex+1)%iNumVertexes)
sl@0
   675
						++iNestingLevel;
sl@0
   676
					else
sl@0
   677
						--iNestingLevel;
sl@0
   678
sl@0
   679
				doFill=(iNestingLevel!=0);
sl@0
   680
				break;
sl@0
   681
				}
sl@0
   682
sl@0
   683
			if (doFill)
sl@0
   684
				{
sl@0
   685
				aStart=Max(iRightMostPixelOnScanLine, iFastData.scanLineIntersectionList[iScanLineIntersection].lastPixel)+1;
sl@0
   686
				aEnd=iFastData.scanLineIntersectionList[iScanLineIntersection+1].firstPixel-1;
sl@0
   687
				}
sl@0
   688
			else
sl@0
   689
				{
sl@0
   690
				// set the start after the end
sl@0
   691
				aStart=KMinTInt+1;
sl@0
   692
				aEnd=KMinTInt;
sl@0
   693
				}
sl@0
   694
sl@0
   695
			if (iRightMostPixelOnScanLine<iFastData.scanLineIntersectionList[iScanLineIntersection].lastPixel)
sl@0
   696
				iRightMostPixelOnScanLine=iFastData.scanLineIntersectionList[iScanLineIntersection].lastPixel;
sl@0
   697
			++iScanLineIntersection;
sl@0
   698
			}
sl@0
   699
sl@0
   700
		if (iScanLineIntersection==iFastData.numScanLineIntersections-1)
sl@0
   701
			{
sl@0
   702
			GRAPHICS_ASSERT_DEBUG(iFastData.vertexList[iFastData.scanLineIntersectionList[iScanLineIntersection].activeEdgePtr->edgePtr->lowerVertex].iY!=
sl@0
   703
						   iFastData.vertexList[iFastData.scanLineIntersectionList[iScanLineIntersection].activeEdgePtr->edgePtr->upperVertex].iY,
sl@0
   704
																											EDirectGdiPanicPolygonFiller);
sl@0
   705
sl@0
   706
			switch (iFillRule)
sl@0
   707
				{
sl@0
   708
			case DirectGdi::EAlternate:
sl@0
   709
				iToggler=!iToggler;
sl@0
   710
				GRAPHICS_ASSERT_DEBUG(iToggler==0, EDirectGdiPanicPolygonFiller);
sl@0
   711
				break;
sl@0
   712
			case DirectGdi::EWinding:
sl@0
   713
				if (iFastData.scanLineIntersectionList[iScanLineIntersection].activeEdgePtr->edgePtr->lowerVertex==
sl@0
   714
					(iFastData.scanLineIntersectionList[iScanLineIntersection].activeEdgePtr->edgePtr->upperVertex+1)%iNumVertexes)
sl@0
   715
					++iNestingLevel;
sl@0
   716
				else
sl@0
   717
					--iNestingLevel;
sl@0
   718
				GRAPHICS_ASSERT_DEBUG((iNumVertexes==2) || (iNestingLevel==0), EDirectGdiPanicPolygonFiller);
sl@0
   719
				break;
sl@0
   720
				}
sl@0
   721
sl@0
   722
			// remove any scan-line-intersections associated with old active-edges
sl@0
   723
			for (i=0; i<iFastData.numScanLineIntersections; )
sl@0
   724
				if (iFastData.vertexList[iFastData.scanLineIntersectionList[i].activeEdgePtr->edgePtr->lowerVertex].iY==iCurrentScanLine)
sl@0
   725
					{
sl@0
   726
					iFastData.scanLineIntersectionList[i].activeEdgePtr->scanLineIntersectionPtr=NULL;
sl@0
   727
sl@0
   728
					// ripple all the entries in the scan-line-intersection-list after this one back one place
sl@0
   729
					for (j=i+1; j<iFastData.numScanLineIntersections; ++j)
sl@0
   730
						{
sl@0
   731
						iFastData.scanLineIntersectionList[j-1]=iFastData.scanLineIntersectionList[j];
sl@0
   732
						iFastData.scanLineIntersectionList[j-1].activeEdgePtr->scanLineIntersectionPtr=&iFastData.scanLineIntersectionList[j-1];
sl@0
   733
						}
sl@0
   734
sl@0
   735
					iFastData.scanLineIntersectionList[j-1].activeEdgePtr=NULL;
sl@0
   736
					--iFastData.numScanLineIntersections;
sl@0
   737
					}
sl@0
   738
				else
sl@0
   739
					++i;
sl@0
   740
sl@0
   741
			// remove any old edges from the active-edge-list
sl@0
   742
			for (i=0; i<iFastData.numActiveEdges; )
sl@0
   743
				if (iFastData.vertexList[iFastData.activeEdgeList[i].edgePtr->lowerVertex].iY==iCurrentScanLine)
sl@0
   744
					{
sl@0
   745
					GRAPHICS_ASSERT_DEBUG(iFastData.activeEdgeList[i].scanLineIntersectionPtr==NULL, EDirectGdiPanicPolygonFiller);
sl@0
   746
sl@0
   747
					// ripple all the entries in the active-edge-list after this one back one place
sl@0
   748
					for (j=i+1; j<iFastData.numActiveEdges; ++j)
sl@0
   749
						{
sl@0
   750
						iFastData.activeEdgeList[j-1]=iFastData.activeEdgeList[j];
sl@0
   751
						if (iFastData.activeEdgeList[j-1].scanLineIntersectionPtr)
sl@0
   752
							iFastData.activeEdgeList[j-1].scanLineIntersectionPtr->activeEdgePtr=&iFastData.activeEdgeList[j-1];
sl@0
   753
						}
sl@0
   754
sl@0
   755
					iFastData.activeEdgeList[j-1].scanLineIntersectionPtr=NULL;
sl@0
   756
					--iFastData.numActiveEdges;
sl@0
   757
					}
sl@0
   758
				else
sl@0
   759
					++i;
sl@0
   760
sl@0
   761
#if defined(_DEBUG)
sl@0
   762
			for (i=0; i<iFastData.numActiveEdges; ++i)
sl@0
   763
				{
sl@0
   764
				GRAPHICS_ASSERT_DEBUG(iFastData.activeEdgeList[i].scanLineIntersectionPtr->activeEdgePtr==
sl@0
   765
								&iFastData.activeEdgeList[i], EDirectGdiPanicPolygonFiller);
sl@0
   766
				}
sl@0
   767
sl@0
   768
			for (i=0; i<iFastData.numScanLineIntersections; ++i)
sl@0
   769
				{
sl@0
   770
				GRAPHICS_ASSERT_DEBUG(iFastData.scanLineIntersectionList[i].activeEdgePtr->scanLineIntersectionPtr==
sl@0
   771
								&iFastData.scanLineIntersectionList[i], EDirectGdiPanicPolygonFiller);
sl@0
   772
				}
sl@0
   773
#endif
sl@0
   774
sl@0
   775
			iScanLineIntersection=0;
sl@0
   776
			++iCurrentScanLine;
sl@0
   777
			iRightMostPixelOnScanLine=KMinTInt;
sl@0
   778
			}
sl@0
   779
		}
sl@0
   780
	else
sl@0
   781
		{
sl@0
   782
		GetNextPixelRunOnSpecifiedScanLine(aExists, iCurrentScanLine, aStart, aEnd);
sl@0
   783
		if (!aExists)
sl@0
   784
			GetNextPixelRunOnSpecifiedScanLine(aExists, ++iCurrentScanLine, aStart, aEnd);
sl@0
   785
		}
sl@0
   786
	}
sl@0
   787
sl@0
   788
/**
sl@0
   789
Similar to GetNextPixelRun(aExists, aScanLine, aStart, aEnd) this method is used to draw the relevant 
sl@0
   790
vertex intersections for a polygon but only for an individual specified scan line. The method
sl@0
   791
can use either the fast or slow polygon algorithm depending upon the state of aUsage.
sl@0
   792
sl@0
   793
@param aExists Will be set to false if the line does not pass through the polygon or if
sl@0
   794
a polygon with no vertexes is specified, otherwise ETrue on return.
sl@0
   795
@param aScanLine The scan line to be drawn on. Used to set iScanline
sl@0
   796
@param aStart On return, contains the position on the scan line to start the run.
sl@0
   797
@param aEnd The position on the scan line to end the run, returned.
sl@0
   798
@panic DGDIAdapter 1015, if iUseFastAlgorithm is ETrue (debug only).
sl@0
   799
*/
sl@0
   800
void CSwDirectGdiPolygonFiller::GetNextPixelRunOnSpecifiedScanLine(TBool& aExists, 
sl@0
   801
																 TInt aScanLine, 
sl@0
   802
																 TInt& aStart, 
sl@0
   803
																 TInt& aEnd)
sl@0
   804
	{
sl@0
   805
	TInt i, j, k;
sl@0
   806
sl@0
   807
	GRAPHICS_ASSERT_DEBUG(!iUseFastAlgorithm, EDirectGdiPanicPolygonFiller);
sl@0
   808
sl@0
   809
	if (aScanLine<iCurrentScanLine || aScanLine>iLastScanLine)
sl@0
   810
		{
sl@0
   811
		aExists=EFalse;
sl@0
   812
		return;
sl@0
   813
		}
sl@0
   814
sl@0
   815
	aExists=ETrue;
sl@0
   816
	iCurrentScanLine=aScanLine;
sl@0
   817
sl@0
   818
	if (iPolygonIsAllHorizontal)
sl@0
   819
		{
sl@0
   820
		// set the start after the end
sl@0
   821
		aStart=KMinTInt+1;
sl@0
   822
		aEnd=KMinTInt;
sl@0
   823
		++iCurrentScanLine;
sl@0
   824
		return;
sl@0
   825
		}
sl@0
   826
sl@0
   827
	if (iScanLineIntersection==0)
sl@0
   828
		{
sl@0
   829
		iSlowData.numIntersectionsWithSameFirstPixelMetThisTime=0;
sl@0
   830
		iSlowData.numScanLineIntersections=0;
sl@0
   831
		iSlowData.scanLineComplete=ETrue;
sl@0
   832
sl@0
   833
		// find the left-most iSlowData::EStoreSize number (or less) of intersections with this scan-line
sl@0
   834
		for (i=iFirstVertex; i<iNumVertexes+iFirstVertex; ++i)
sl@0
   835
			{
sl@0
   836
			TPoint upper=Point(i%iNumVertexes);
sl@0
   837
			TPoint lower=Point((i+1)%iNumVertexes);
sl@0
   838
			if (upper.iY>lower.iY)
sl@0
   839
				{
sl@0
   840
				TPoint temp=upper;
sl@0
   841
				upper=lower;
sl@0
   842
				lower=temp;
sl@0
   843
				}
sl@0
   844
sl@0
   845
			if ((iCurrentScanLine>=upper.iY) && (iCurrentScanLine<=lower.iY))
sl@0
   846
				{
sl@0
   847
				// check that the edge starting at vertex i%iNumVertexes is not horizontal
sl@0
   848
				GRAPHICS_ASSERT_DEBUG(upper.iY!=lower.iY, EDirectGdiPanicPolygonFiller);
sl@0
   849
sl@0
   850
				// step through the line-generator until the current scan-line is reached
sl@0
   851
				TPoint startPos, endPos;
sl@0
   852
				JumpToCurrentScanLine(iSlowData.lineGenerator, upper, lower, startPos, endPos);
sl@0
   853
sl@0
   854
				// find the intersection start and end pixels
sl@0
   855
				SSlowScanLineIntersection scanLineIntersection;
sl@0
   856
				scanLineIntersection.firstPixel=Min(startPos.iX, endPos.iX);
sl@0
   857
				scanLineIntersection.lastPixel=Max(startPos.iX, endPos.iX);
sl@0
   858
				scanLineIntersection.firstVertexOfEdge=i%iNumVertexes;
sl@0
   859
sl@0
   860
				// handle horizontal runs and minima/maxima
sl@0
   861
				if (upper.iY==iCurrentScanLine)
sl@0
   862
					SlowHandleVertexIntersection(scanLineIntersection, i, EFalse);
sl@0
   863
				else if (lower.iY==iCurrentScanLine)
sl@0
   864
					SlowHandleVertexIntersection(scanLineIntersection, i, ETrue);
sl@0
   865
sl@0
   866
				// see if there have been other intersections with the same first-pixel
sl@0
   867
				if (scanLineIntersection.firstPixel==iSlowData.firstPixelOfLastIntersectionInPrevBuffer)
sl@0
   868
					++iSlowData.numIntersectionsWithSameFirstPixelMetThisTime;
sl@0
   869
sl@0
   870
				// if the intersection has not already been included in a previous buffer-load
sl@0
   871
				if ((scanLineIntersection.firstPixel>iSlowData.firstPixelOfLastIntersectionInPrevBuffer) ||
sl@0
   872
					((scanLineIntersection.firstPixel==iSlowData.firstPixelOfLastIntersectionInPrevBuffer) &&
sl@0
   873
													(iSlowData.numIntersectionsWithSameFirstPixelMetThisTime>=
sl@0
   874
													iSlowData.numIntersectionsWithSameFirstPixelPreviouslyMet)))
sl@0
   875
					{
sl@0
   876
					// put the intersection in the right place in the intersection list (if there is room)
sl@0
   877
					for (j=0; j<iSlowData.numScanLineIntersections; ++j)
sl@0
   878
						if (scanLineIntersection.firstPixel<iSlowData.scanLineIntersectionList[j].firstPixel)
sl@0
   879
							{
sl@0
   880
							if (iSlowData.numScanLineIntersections<SSlowData::EStoreSize)
sl@0
   881
								++iSlowData.numScanLineIntersections;
sl@0
   882
							else
sl@0
   883
								iSlowData.scanLineComplete=EFalse;
sl@0
   884
sl@0
   885
							for (k=iSlowData.numScanLineIntersections-1; k>j; --k)
sl@0
   886
								iSlowData.scanLineIntersectionList[k]=iSlowData.scanLineIntersectionList[k-1];
sl@0
   887
							iSlowData.scanLineIntersectionList[j]=scanLineIntersection;
sl@0
   888
							break;
sl@0
   889
							}
sl@0
   890
					if (j==iSlowData.numScanLineIntersections)
sl@0
   891
						{
sl@0
   892
						if (iSlowData.numScanLineIntersections<SSlowData::EStoreSize)
sl@0
   893
							iSlowData.scanLineIntersectionList[iSlowData.numScanLineIntersections++]=scanLineIntersection;
sl@0
   894
						else
sl@0
   895
							iSlowData.scanLineComplete=EFalse;
sl@0
   896
						}
sl@0
   897
					}
sl@0
   898
				}
sl@0
   899
			}
sl@0
   900
sl@0
   901
		if (!iSlowData.scanLineComplete)
sl@0
   902
			{
sl@0
   903
			GRAPHICS_ASSERT_DEBUG(iSlowData.numScanLineIntersections==SSlowData::EStoreSize, EDirectGdiPanicPolygonFiller);
sl@0
   904
sl@0
   905
			if (iSlowData.firstPixelOfLastIntersectionInPrevBuffer==iSlowData.scanLineIntersectionList[SSlowData::EStoreSize-1].firstPixel)
sl@0
   906
				iSlowData.numIntersectionsWithSameFirstPixelPreviouslyMet+=SSlowData::EStoreSize-1;
sl@0
   907
			else
sl@0
   908
				{
sl@0
   909
				iSlowData.firstPixelOfLastIntersectionInPrevBuffer=iSlowData.scanLineIntersectionList[SSlowData::EStoreSize-1].firstPixel;
sl@0
   910
				iSlowData.numIntersectionsWithSameFirstPixelPreviouslyMet=1;
sl@0
   911
				for (i=SSlowData::EStoreSize-1; (i>0) && (iSlowData.firstPixelOfLastIntersectionInPrevBuffer==
sl@0
   912
															iSlowData.scanLineIntersectionList[i-1].firstPixel); --i)
sl@0
   913
					++iSlowData.numIntersectionsWithSameFirstPixelPreviouslyMet;
sl@0
   914
				}
sl@0
   915
			}
sl@0
   916
		}
sl@0
   917
sl@0
   918
	// depending on the rule used, find the pixel-run
sl@0
   919
	TBool doFill=EFalse; // dummy initialization to prevent compiler warning
sl@0
   920
	if (iScanLineIntersection<iSlowData.numScanLineIntersections-1)
sl@0
   921
		{
sl@0
   922
		switch (iFillRule)
sl@0
   923
			{
sl@0
   924
		case DirectGdi::EAlternate:
sl@0
   925
			iToggler=!iToggler;
sl@0
   926
			doFill=iToggler;
sl@0
   927
			break;
sl@0
   928
		case DirectGdi::EWinding:
sl@0
   929
				GRAPHICS_ASSERT_DEBUG(Point(iSlowData.scanLineIntersectionList[iScanLineIntersection].firstVertexOfEdge).iY!=
sl@0
   930
							   Point((iSlowData.scanLineIntersectionList[iScanLineIntersection].firstVertexOfEdge+1)%iNumVertexes).iY,
sl@0
   931
																										EDirectGdiPanicPolygonFiller);
sl@0
   932
sl@0
   933
				if (Point(iSlowData.scanLineIntersectionList[iScanLineIntersection].firstVertexOfEdge).iY>
sl@0
   934
					Point((iSlowData.scanLineIntersectionList[iScanLineIntersection].firstVertexOfEdge+1)%iNumVertexes).iY)
sl@0
   935
					++iNestingLevel;
sl@0
   936
				else
sl@0
   937
					--iNestingLevel;
sl@0
   938
sl@0
   939
			doFill=(iNestingLevel!=0);
sl@0
   940
			break;
sl@0
   941
			}
sl@0
   942
sl@0
   943
		if (doFill)
sl@0
   944
			{
sl@0
   945
			aStart=Max(iRightMostPixelOnScanLine, iSlowData.scanLineIntersectionList[iScanLineIntersection].lastPixel)+1;
sl@0
   946
			aEnd=iSlowData.scanLineIntersectionList[iScanLineIntersection+1].firstPixel-1;
sl@0
   947
			}
sl@0
   948
		else
sl@0
   949
			{
sl@0
   950
			// set the start after the end
sl@0
   951
			aStart=KMinTInt+1;
sl@0
   952
			aEnd=KMinTInt;
sl@0
   953
			}
sl@0
   954
sl@0
   955
		if (iRightMostPixelOnScanLine<iSlowData.scanLineIntersectionList[iScanLineIntersection].lastPixel)
sl@0
   956
			iRightMostPixelOnScanLine=iSlowData.scanLineIntersectionList[iScanLineIntersection].lastPixel;
sl@0
   957
		++iScanLineIntersection;
sl@0
   958
		}
sl@0
   959
sl@0
   960
	if (iScanLineIntersection==iSlowData.numScanLineIntersections-1)
sl@0
   961
		{
sl@0
   962
		if (iSlowData.scanLineComplete)
sl@0
   963
			{
sl@0
   964
			GRAPHICS_ASSERT_DEBUG(Point(iSlowData.scanLineIntersectionList[iScanLineIntersection].firstVertexOfEdge).iY!=
sl@0
   965
						   Point((iSlowData.scanLineIntersectionList[iScanLineIntersection].firstVertexOfEdge+1)%iNumVertexes).iY,
sl@0
   966
																											EDirectGdiPanicPolygonFiller);
sl@0
   967
sl@0
   968
			switch (iFillRule)
sl@0
   969
				{
sl@0
   970
			case DirectGdi::EAlternate:
sl@0
   971
				iToggler=!iToggler;
sl@0
   972
				GRAPHICS_ASSERT_DEBUG(iToggler==0, EDirectGdiPanicPolygonFiller);
sl@0
   973
				break;
sl@0
   974
			case DirectGdi::EWinding:
sl@0
   975
				if (Point(iSlowData.scanLineIntersectionList[iScanLineIntersection].firstVertexOfEdge).iY>
sl@0
   976
					Point((iSlowData.scanLineIntersectionList[iScanLineIntersection].firstVertexOfEdge+1)%iNumVertexes).iY)
sl@0
   977
					++iNestingLevel;
sl@0
   978
				else
sl@0
   979
					--iNestingLevel;
sl@0
   980
sl@0
   981
				GRAPHICS_ASSERT_DEBUG((!iSlowData.scanLineComplete) || (iNumVertexes==2) || (iNestingLevel==0), EDirectGdiPanicPolygonFiller);
sl@0
   982
				break;
sl@0
   983
				}
sl@0
   984
			}
sl@0
   985
sl@0
   986
		iScanLineIntersection=0;
sl@0
   987
		if (iSlowData.scanLineComplete)
sl@0
   988
			{
sl@0
   989
			++iCurrentScanLine;
sl@0
   990
			iRightMostPixelOnScanLine=KMinTInt;
sl@0
   991
			iSlowData.numIntersectionsWithSameFirstPixelPreviouslyMet=0;
sl@0
   992
			iSlowData.scanLineComplete=EFalse;
sl@0
   993
			iSlowData.firstPixelOfLastIntersectionInPrevBuffer=KMinTInt;
sl@0
   994
			}
sl@0
   995
		}
sl@0
   996
	}
sl@0
   997
sl@0
   998
/**
sl@0
   999
Builds up drawing meta-data in the case where a scanline intersects the active edge at a vertex using
sl@0
  1000
fast algorithms. 
sl@0
  1001
sl@0
  1002
@param aCurrentActiveEdge Index of the current active edge
sl@0
  1003
@param aIsLowerVertex If the vertex is the lower vertex ETrue otherwise EFalse.
sl@0
  1004
@panic DGDIAdapter 1015, if iUseFastAlgorithm is EFalse.
sl@0
  1005
sl@0
  1006
@see GetNextPixelRun()
sl@0
  1007
*/
sl@0
  1008
void CSwDirectGdiPolygonFiller::FastHandleVertexIntersection(TInt& aCurrentActiveEdge, 
sl@0
  1009
												  TBool aIsLowerVertex)
sl@0
  1010
	{
sl@0
  1011
	GRAPHICS_ASSERT_DEBUG(iUseFastAlgorithm, EDirectGdiPanicPolygonFiller);
sl@0
  1012
sl@0
  1013
	if (iFastData.vertexList[(iFastData.activeEdgeList[aCurrentActiveEdge].edgePtr->firstVertex+1)%iNumVertexes].iY==iCurrentScanLine)
sl@0
  1014
		// it is the second vertex of active-edge aCurrentActiveEdge that coincides with the current scan-line
sl@0
  1015
		{
sl@0
  1016
		TInt origActiveEdge=aCurrentActiveEdge;
sl@0
  1017
		SFastScanLineIntersection scanLineIntersection;
sl@0
  1018
		scanLineIntersection.activeEdgePtr=NULL;
sl@0
  1019
		SetFastIntersection(iFastData.activeEdgeList[origActiveEdge], scanLineIntersection);
sl@0
  1020
sl@0
  1021
		// walk through subsequent adjacent horizontal active-edges
sl@0
  1022
		FOREVER
sl@0
  1023
			{
sl@0
  1024
			// exit the loop if the vertex-run *is* a maximum or a minimum
sl@0
  1025
			const SFastEdge* tempEdgePtr=iFastData.activeEdgeList[(aCurrentActiveEdge+1)%iFastData.numActiveEdges].edgePtr;
sl@0
  1026
			TBool isMaxOrMin = EFalse;
sl@0
  1027
sl@0
  1028
			switch(aIsLowerVertex)
sl@0
  1029
				{
sl@0
  1030
				case EFalse:
sl@0
  1031
					isMaxOrMin = (iFastData.vertexList[tempEdgePtr->lowerVertex].iY > iCurrentScanLine);
sl@0
  1032
					break;
sl@0
  1033
sl@0
  1034
				case ETrue:
sl@0
  1035
					isMaxOrMin = (iFastData.vertexList[tempEdgePtr->upperVertex].iY < iCurrentScanLine);
sl@0
  1036
					break;
sl@0
  1037
				}
sl@0
  1038
sl@0
  1039
			if (isMaxOrMin)
sl@0
  1040
 				// the vertex-run is a maximum or a minimum
sl@0
  1041
				{
sl@0
  1042
				if (aIsLowerVertex)
sl@0
  1043
					{
sl@0
  1044
					*iFastData.activeEdgeList[origActiveEdge].scanLineIntersectionPtr=scanLineIntersection;
sl@0
  1045
					iFastData.activeEdgeList[origActiveEdge].scanLineIntersectionPtr->activeEdgePtr=&iFastData.activeEdgeList[origActiveEdge];
sl@0
  1046
					}
sl@0
  1047
				else
sl@0
  1048
					{
sl@0
  1049
					// add an intersection
sl@0
  1050
					iFastData.scanLineIntersectionList[iFastData.numScanLineIntersections]=scanLineIntersection;
sl@0
  1051
					iFastData.scanLineIntersectionList[iFastData.numScanLineIntersections].activeEdgePtr=&iFastData.activeEdgeList[origActiveEdge];
sl@0
  1052
					iFastData.activeEdgeList[origActiveEdge].scanLineIntersectionPtr=&iFastData.scanLineIntersectionList[iFastData.numScanLineIntersections];
sl@0
  1053
					++iFastData.numScanLineIntersections;
sl@0
  1054
					}
sl@0
  1055
				break;
sl@0
  1056
				}
sl@0
  1057
sl@0
  1058
			// the active-edge is horizontal, or the vertex-run is not a maximum or a minimum
sl@0
  1059
sl@0
  1060
			++aCurrentActiveEdge;
sl@0
  1061
			GRAPHICS_ASSERT_DEBUG(aCurrentActiveEdge<iFastData.numActiveEdges, EDirectGdiPanicPolygonFiller);
sl@0
  1062
sl@0
  1063
			// update scanLineIntersection
sl@0
  1064
			TPoint startPos, endPos;
sl@0
  1065
			TInt minX, maxX;
sl@0
  1066
			iFastData.activeEdgeList[aCurrentActiveEdge].lineGenerator.SingleScanline(startPos, endPos);
sl@0
  1067
			minX=Min(startPos.iX, endPos.iX);
sl@0
  1068
			maxX=Max(startPos.iX, endPos.iX);
sl@0
  1069
			if (scanLineIntersection.firstPixel>minX)
sl@0
  1070
				scanLineIntersection.firstPixel=minX;
sl@0
  1071
			if (scanLineIntersection.lastPixel<maxX)
sl@0
  1072
				scanLineIntersection.lastPixel=maxX;
sl@0
  1073
sl@0
  1074
			// exit the loop if the vertex-run is *not* a maximum or a minimum
sl@0
  1075
			tempEdgePtr=iFastData.activeEdgeList[aCurrentActiveEdge].edgePtr;
sl@0
  1076
			TBool isNeitherMaxOrMin = EFalse;
sl@0
  1077
sl@0
  1078
			switch(aIsLowerVertex)
sl@0
  1079
				{
sl@0
  1080
				case EFalse:
sl@0
  1081
					isNeitherMaxOrMin = (iFastData.vertexList[tempEdgePtr->upperVertex].iY < iCurrentScanLine);
sl@0
  1082
					break;
sl@0
  1083
sl@0
  1084
				case ETrue:
sl@0
  1085
					isNeitherMaxOrMin = (iFastData.vertexList[tempEdgePtr->lowerVertex].iY > iCurrentScanLine);
sl@0
  1086
					break;
sl@0
  1087
				}
sl@0
  1088
sl@0
  1089
 			// exit the loop if the vertex-run is *not* a maximum or a minimum
sl@0
  1090
			if (isNeitherMaxOrMin)
sl@0
  1091
				{
sl@0
  1092
				TInt newActiveEdge;
sl@0
  1093
				TInt oldActiveEdge;
sl@0
  1094
				if (aIsLowerVertex)
sl@0
  1095
					{
sl@0
  1096
					newActiveEdge=aCurrentActiveEdge;
sl@0
  1097
					oldActiveEdge=origActiveEdge;
sl@0
  1098
					}
sl@0
  1099
				else
sl@0
  1100
					{
sl@0
  1101
					newActiveEdge=origActiveEdge;
sl@0
  1102
					oldActiveEdge=aCurrentActiveEdge;
sl@0
  1103
					}
sl@0
  1104
				iFastData.activeEdgeList[newActiveEdge].scanLineIntersectionPtr=iFastData.activeEdgeList[oldActiveEdge].scanLineIntersectionPtr;
sl@0
  1105
				iFastData.activeEdgeList[oldActiveEdge].scanLineIntersectionPtr=NULL;
sl@0
  1106
				*iFastData.activeEdgeList[newActiveEdge].scanLineIntersectionPtr=scanLineIntersection;
sl@0
  1107
				iFastData.activeEdgeList[newActiveEdge].scanLineIntersectionPtr->activeEdgePtr=&iFastData.activeEdgeList[newActiveEdge];
sl@0
  1108
				break;
sl@0
  1109
				}
sl@0
  1110
			}
sl@0
  1111
		}
sl@0
  1112
	else
sl@0
  1113
		// it is the first vertex of active-edge aCurrentActiveEdge that coincides with the current scan-line
sl@0
  1114
		{
sl@0
  1115
#if defined(_DEBUG)
sl@0
  1116
		// check that the vertex we are at is a maximum or a minimum
sl@0
  1117
		TInt previousNotLevelVertex;
sl@0
  1118
		TInt SFastEdge::*vertex=(aIsLowerVertex)? &SFastEdge::lowerVertex: &SFastEdge::upperVertex;
sl@0
  1119
		for (previousNotLevelVertex=iFastData.activeEdgeList[aCurrentActiveEdge].edgePtr->*vertex;
sl@0
  1120
								iFastData.vertexList[iFastData.activeEdgeList[aCurrentActiveEdge].edgePtr->*vertex].iY==iFastData.vertexList[previousNotLevelVertex].iY;
sl@0
  1121
								previousNotLevelVertex=(previousNotLevelVertex+iNumVertexes-1)%iNumVertexes)
sl@0
  1122
			;
sl@0
  1123
		TInt nextNotLevelVertex=(iFastData.activeEdgeList[aCurrentActiveEdge].edgePtr->*vertex+1)%iNumVertexes;
sl@0
  1124
		GRAPHICS_ASSERT_DEBUG((iFastData.vertexList[iFastData.activeEdgeList[aCurrentActiveEdge].edgePtr->*vertex].iY>iFastData.vertexList[previousNotLevelVertex].iY)==
sl@0
  1125
					   (iFastData.vertexList[iFastData.activeEdgeList[aCurrentActiveEdge].edgePtr->*vertex].iY>iFastData.vertexList[nextNotLevelVertex].iY),
sl@0
  1126
																						EDirectGdiPanicPolygonFiller);
sl@0
  1127
#endif
sl@0
  1128
sl@0
  1129
		if (aIsLowerVertex)
sl@0
  1130
			SetFastIntersection(iFastData.activeEdgeList[aCurrentActiveEdge],*iFastData.activeEdgeList[aCurrentActiveEdge].scanLineIntersectionPtr);
sl@0
  1131
		else
sl@0
  1132
			{
sl@0
  1133
			// add an intersection
sl@0
  1134
			SetFastIntersection(iFastData.activeEdgeList[aCurrentActiveEdge], iFastData.scanLineIntersectionList[iFastData.numScanLineIntersections]);
sl@0
  1135
			iFastData.scanLineIntersectionList[iFastData.numScanLineIntersections].activeEdgePtr=&iFastData.activeEdgeList[aCurrentActiveEdge];
sl@0
  1136
			iFastData.activeEdgeList[aCurrentActiveEdge].scanLineIntersectionPtr=&iFastData.scanLineIntersectionList[iFastData.numScanLineIntersections];
sl@0
  1137
			++iFastData.numScanLineIntersections;
sl@0
  1138
			}
sl@0
  1139
		}
sl@0
  1140
	}
sl@0
  1141
sl@0
  1142
/**
sl@0
  1143
Calculates the extent of the intersection for the current active edge.
sl@0
  1144
sl@0
  1145
@param aActiveEdge The current active edge.
sl@0
  1146
@param aScanLineIntersection On return, contains the intersection data.
sl@0
  1147
*/
sl@0
  1148
void CSwDirectGdiPolygonFiller::SetFastIntersection(SFastActiveEdge& aActiveEdge, SFastScanLineIntersection& aScanLineIntersection)
sl@0
  1149
	{
sl@0
  1150
	GRAPHICS_ASSERT_DEBUG(iUseFastAlgorithm, EDirectGdiPanicPolygonFiller);
sl@0
  1151
sl@0
  1152
	TPoint startPos, endPos;
sl@0
  1153
sl@0
  1154
	aActiveEdge.lineGenerator.SingleScanline(startPos, endPos);
sl@0
  1155
	aScanLineIntersection.firstPixel=Min(startPos.iX, endPos.iX);
sl@0
  1156
	aScanLineIntersection.lastPixel=Max(startPos.iX, endPos.iX);
sl@0
  1157
	}
sl@0
  1158
sl@0
  1159
/**
sl@0
  1160
Builds up drawing meta-data in the case where a scanline intersects the active edge at a vertex using
sl@0
  1161
slow algorithms.
sl@0
  1162
sl@0
  1163
@param aScanLineIntersection Reference to the current intersection data.
sl@0
  1164
@param aVertexStartingCurrentEdge Current vertex.
sl@0
  1165
@param aIsLowerVertex If the vertex is the lower vertex ETrue otherwise EFalse.
sl@0
  1166
@see GetNextPixelRunOnSpecifiedScanLine()
sl@0
  1167
*/
sl@0
  1168
void CSwDirectGdiPolygonFiller::SlowHandleVertexIntersection(SSlowScanLineIntersection& aScanLineIntersection, 
sl@0
  1169
												  TInt& aVertexStartingCurrentEdge,
sl@0
  1170
												  TBool aIsLowerVertex)
sl@0
  1171
	{
sl@0
  1172
	if (Point((aVertexStartingCurrentEdge+1)%iNumVertexes).iY==iCurrentScanLine)
sl@0
  1173
		// it is the second vertex of the edge starting at vertex aVertexStartingCurrentEdge%iNumVertexes
sl@0
  1174
		// that coincides with the current scan-line
sl@0
  1175
		{
sl@0
  1176
		// walk through subsequent adjacent horizontal active-edges
sl@0
  1177
		for (; ; )
sl@0
  1178
			{
sl@0
  1179
			TPoint nextVertexButOne=Point((aVertexStartingCurrentEdge+2)%iNumVertexes);
sl@0
  1180
			TBool isMaxOrMin = EFalse;
sl@0
  1181
sl@0
  1182
			switch(aIsLowerVertex)
sl@0
  1183
				{
sl@0
  1184
				case EFalse:
sl@0
  1185
					isMaxOrMin = (nextVertexButOne.iY > iCurrentScanLine);
sl@0
  1186
					break;
sl@0
  1187
sl@0
  1188
				case ETrue:
sl@0
  1189
					isMaxOrMin = (nextVertexButOne.iY < iCurrentScanLine);
sl@0
  1190
					break;
sl@0
  1191
				}
sl@0
  1192
sl@0
  1193
			// exit the loop if the vertex-run *is* a maximum or a minimum
sl@0
  1194
			if (isMaxOrMin)
sl@0
  1195
				{
sl@0
  1196
				break;
sl@0
  1197
				}
sl@0
  1198
sl@0
  1199
			// the edge starting at vertex aVertexStartingCurrentEdge%iNumVertexes is horizontal, or the vertex-run is not a
sl@0
  1200
			// maximum or a minimum
sl@0
  1201
sl@0
  1202
			++aVertexStartingCurrentEdge;
sl@0
  1203
			GRAPHICS_ASSERT_DEBUG(aVertexStartingCurrentEdge%iNumVertexes!=iFirstVertex, EDirectGdiPanicPolygonFiller);
sl@0
  1204
sl@0
  1205
			// step through the line-generator until the current scan-line is reached
sl@0
  1206
			TPoint upper=Point(aVertexStartingCurrentEdge%iNumVertexes);
sl@0
  1207
			TPoint lower=nextVertexButOne;
sl@0
  1208
			if (upper.iY>lower.iY)
sl@0
  1209
				{
sl@0
  1210
				TPoint temp=upper;
sl@0
  1211
				upper=lower;
sl@0
  1212
				lower=temp;
sl@0
  1213
				}
sl@0
  1214
sl@0
  1215
			TPoint startPos, endPos;
sl@0
  1216
			if (upper.iY!=lower.iY)
sl@0
  1217
				JumpToCurrentScanLine(iSlowData.lineGenerator, upper, lower, startPos, endPos);
sl@0
  1218
			else
sl@0
  1219
				{
sl@0
  1220
				// N.B. which is set to which doesn't matter, as long as startPos is set to either upper or lower, and endPos is set to the other
sl@0
  1221
				startPos=upper;
sl@0
  1222
				endPos=lower;
sl@0
  1223
				}
sl@0
  1224
sl@0
  1225
			// expand the intersection, if necessary
sl@0
  1226
			TInt minX=Min(startPos.iX, endPos.iX);
sl@0
  1227
			TInt maxX=Max(startPos.iX, endPos.iX);
sl@0
  1228
			if (aScanLineIntersection.firstPixel>minX)
sl@0
  1229
				aScanLineIntersection.firstPixel=minX;
sl@0
  1230
			if (aScanLineIntersection.lastPixel<maxX)
sl@0
  1231
				aScanLineIntersection.lastPixel=maxX;
sl@0
  1232
sl@0
  1233
			TBool isNeitherMaxOrMin = EFalse;
sl@0
  1234
sl@0
  1235
			switch(aIsLowerVertex)
sl@0
  1236
				{
sl@0
  1237
				case EFalse:
sl@0
  1238
					isNeitherMaxOrMin = (nextVertexButOne.iY < iCurrentScanLine);
sl@0
  1239
					break;
sl@0
  1240
sl@0
  1241
				case ETrue:
sl@0
  1242
					isNeitherMaxOrMin = (nextVertexButOne.iY > iCurrentScanLine);
sl@0
  1243
					break;
sl@0
  1244
				}
sl@0
  1245
							  
sl@0
  1246
			// exit the loop if the vertex-run is *not* a maximum or a minimum					   
sl@0
  1247
			if (isNeitherMaxOrMin)
sl@0
  1248
				{
sl@0
  1249
				if (aIsLowerVertex)
sl@0
  1250
					{
sl@0
  1251
					aScanLineIntersection.firstVertexOfEdge=aVertexStartingCurrentEdge%iNumVertexes;
sl@0
  1252
					}
sl@0
  1253
				break;
sl@0
  1254
				}
sl@0
  1255
			}
sl@0
  1256
		}
sl@0
  1257
	else
sl@0
  1258
		// it is the first vertex of the edge starting at vertex aVertexStartingCurrentEdge%iNumVertexes
sl@0
  1259
		// that coincides with the current scan-line
sl@0
  1260
		{
sl@0
  1261
#if defined(_DEBUG)
sl@0
  1262
		// check that the vertex we are at is a maximum or a minimum
sl@0
  1263
		TInt previousNotLevelVertex;
sl@0
  1264
		for (previousNotLevelVertex=aVertexStartingCurrentEdge%iNumVertexes;
sl@0
  1265
														Point(aVertexStartingCurrentEdge%iNumVertexes).iY==
sl@0
  1266
														Point(previousNotLevelVertex).iY;
sl@0
  1267
														previousNotLevelVertex=(previousNotLevelVertex+iNumVertexes-1)%iNumVertexes)
sl@0
  1268
			;
sl@0
  1269
		TInt nextNotLevelVertex=(aVertexStartingCurrentEdge+1)%iNumVertexes;
sl@0
  1270
		TInt previousY=Point(previousNotLevelVertex).iY;
sl@0
  1271
		TInt currentY=Point(aVertexStartingCurrentEdge%iNumVertexes).iY;
sl@0
  1272
		TInt nextY=Point(nextNotLevelVertex).iY;
sl@0
  1273
		GRAPHICS_ASSERT_DEBUG((currentY>previousY) == (currentY>nextY), EDirectGdiPanicPolygonFiller);
sl@0
  1274
#endif
sl@0
  1275
		}
sl@0
  1276
	}
sl@0
  1277
sl@0
  1278
/**
sl@0
  1279
For a given line between two given endpoints, calculate the right and leftmost pixels of the line segment 
sl@0
  1280
that fall on the current scanline.
sl@0
  1281
sl@0
  1282
@param aLineGenerator Reference to class used to calculate the pixels on the line. 
sl@0
  1283
@param aUpper The upper endpoint of the line.
sl@0
  1284
@param aLower The lower endpoint of the line.
sl@0
  1285
@param aStartPos On return, contains the position of the line's leftmost pixel on the current scanline. 
sl@0
  1286
@param aEndPos On return, contains the position of the line's rightmost pixel on the current scanline.
sl@0
  1287
*/
sl@0
  1288
void CSwDirectGdiPolygonFiller::JumpToCurrentScanLine(TLinearDDA& aLineGenerator, 
sl@0
  1289
										   const TPoint& aUpper, 
sl@0
  1290
										   const TPoint& aLower,
sl@0
  1291
										   TPoint& aStartPos, 
sl@0
  1292
										   TPoint& aEndPos) const
sl@0
  1293
	{
sl@0
  1294
	GRAPHICS_ASSERT_DEBUG(aUpper.iY<=aLower.iY, EDirectGdiPanicPolygonFiller);
sl@0
  1295
	aLineGenerator.Construct(aUpper, aLower);
sl@0
  1296
	if (aUpper.iY<iCurrentScanLine)
sl@0
  1297
		{
sl@0
  1298
		TInt notUsed;
sl@0
  1299
		aLineGenerator.JumpToYCoord(notUsed, iCurrentScanLine-2);
sl@0
  1300
		}
sl@0
  1301
	do
sl@0
  1302
		aLineGenerator.SingleScanline(aStartPos, aEndPos);
sl@0
  1303
	while (aStartPos.iY!=iCurrentScanLine);
sl@0
  1304
	GRAPHICS_ASSERT_DEBUG(aStartPos.iY==iCurrentScanLine, EDirectGdiPanicPolygonFiller);
sl@0
  1305
	GRAPHICS_ASSERT_DEBUG(aEndPos.iY==iCurrentScanLine, EDirectGdiPanicPolygonFiller);
sl@0
  1306
	}
sl@0
  1307
sl@0
  1308
/**
sl@0
  1309
Returns the point data for a given index.
sl@0
  1310
sl@0
  1311
@param aIndex The index.
sl@0
  1312
@return The point data.
sl@0
  1313
*/
sl@0
  1314
const TPoint& CSwDirectGdiPolygonFiller::Point(TInt aIndex)
sl@0
  1315
	{
sl@0
  1316
	GRAPHICS_ASSERT_DEBUG(iPointArray,EDirectGdiPanicPolygonFiller);
sl@0
  1317
	return((*iPointArray)[aIndex]);
sl@0
  1318
	}
sl@0
  1319