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