sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "swdirectgdipolygon.h" sl@0: sl@0: /** sl@0: A utility class used to sort vertex lists based on y coordinates. sl@0: @see CSwDirectGdiPolygonFiller sl@0: @see TKey sl@0: sl@0: @internalComponent sl@0: */ sl@0: NONSHARABLE_CLASS(TCompareEdgesUpperY) : public TKey sl@0: { sl@0: public: sl@0: TCompareEdgesUpperY(const CSwDirectGdiPolygonFiller::SFastData& aFastData); sl@0: private: sl@0: virtual TInt Compare(TInt aLeft,TInt aRight) const; sl@0: private: sl@0: const CSwDirectGdiPolygonFiller::SFastData& iFastData; sl@0: }; sl@0: sl@0: TCompareEdgesUpperY::TCompareEdgesUpperY(const CSwDirectGdiPolygonFiller::SFastData& aFastData): sl@0: iFastData(aFastData) sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Compare edges based on their upper Y coordinate. sl@0: sl@0: @param aLeft Index corresponding to the "left" side of the comparison. sl@0: @param aRight Index corresponding to the "right" side of the comparison. sl@0: sl@0: @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: sl@0: @see TKey::Compare sl@0: */ sl@0: TInt TCompareEdgesUpperY::Compare(TInt aLeft,TInt aRight) const sl@0: { sl@0: const TInt leftUpperY=iFastData.vertexList[iFastData.edgeList[aLeft].upperVertex].iY; sl@0: const TInt rightUpperY=iFastData.vertexList[iFastData.edgeList[aRight].upperVertex].iY; sl@0: if (leftUpperYrightUpperY) sl@0: return 1; sl@0: return 0; sl@0: } sl@0: sl@0: /** sl@0: A utility class used to swap entries in edgeList arrays during sort operations. sl@0: @see CSwDirectGdiPolygonFiller sl@0: @see TSwap sl@0: sl@0: @internalComponent sl@0: */ sl@0: NONSHARABLE_CLASS(TSwapEdges) : public TSwap sl@0: { sl@0: public: sl@0: TSwapEdges(CSwDirectGdiPolygonFiller::SFastData& aFastData); sl@0: private: sl@0: virtual void Swap(TInt aLeft,TInt aRight) const; sl@0: private: sl@0: CSwDirectGdiPolygonFiller::SFastData& iFastData; sl@0: }; sl@0: sl@0: TSwapEdges::TSwapEdges(CSwDirectGdiPolygonFiller::SFastData& aFastData): sl@0: iFastData(aFastData) sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Swaps two elements of an edgeList array. sl@0: sl@0: @param aLeft The index of an array element participating in the swap. sl@0: @param aRight The index of an array element participating in the swap. sl@0: sl@0: @see TSwap::Swap sl@0: */ sl@0: void TSwapEdges::Swap(TInt aLeft,TInt aRight) const sl@0: { sl@0: CSwDirectGdiPolygonFiller::SFastEdge& leftEdge=iFastData.edgeList[aLeft]; sl@0: CSwDirectGdiPolygonFiller::SFastEdge& rightEdge=iFastData.edgeList[aRight]; sl@0: sl@0: const CSwDirectGdiPolygonFiller::SFastEdge temp(leftEdge); sl@0: leftEdge=rightEdge; sl@0: rightEdge=temp; sl@0: } sl@0: sl@0: /** sl@0: A utility class used to sort active edge lists based on the order of their vertexes. sl@0: @see CSwDirectGdiPolygonFiller sl@0: @see TKey sl@0: sl@0: @internalComponent sl@0: */ sl@0: NONSHARABLE_CLASS(TCompareActiveEdgesFirstVertex) : public TKey sl@0: { sl@0: public: sl@0: TCompareActiveEdgesFirstVertex(const CSwDirectGdiPolygonFiller::SFastData& aFastData); sl@0: private: sl@0: virtual TInt Compare(TInt aLeft,TInt aRight) const; sl@0: private: sl@0: const CSwDirectGdiPolygonFiller::SFastData& iFastData; sl@0: }; sl@0: sl@0: TCompareActiveEdgesFirstVertex::TCompareActiveEdgesFirstVertex(const CSwDirectGdiPolygonFiller::SFastData& aFastData): sl@0: iFastData(aFastData) sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Compare edges based on the order of their vertexes. sl@0: sl@0: @param aLeft Index corresponding to the "left" side of the comparison. sl@0: @param aRight Index corresponding to the "right" side of the comparison. sl@0: sl@0: @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: sl@0: @see TKey::Compare sl@0: */ sl@0: TInt TCompareActiveEdgesFirstVertex::Compare(TInt aLeft,TInt aRight) const sl@0: { sl@0: const TInt leftFirstVertex=iFastData.activeEdgeList[aLeft].edgePtr->firstVertex; sl@0: const TInt rightFirstVertex=iFastData.activeEdgeList[aRight].edgePtr->firstVertex; sl@0: if (leftFirstVertexrightFirstVertex) sl@0: return 1; sl@0: return 0; sl@0: } sl@0: sl@0: /** sl@0: A utility class used to swap entries in activeEdgeList arrays during sort operations. sl@0: @see CSwDirectGdiPolygonFiller sl@0: @see TSwap sl@0: sl@0: @internalComponent sl@0: */ sl@0: NONSHARABLE_CLASS(TSwapActiveEdges) : public TSwap sl@0: { sl@0: public: sl@0: TSwapActiveEdges(CSwDirectGdiPolygonFiller::SFastData& aFastData); sl@0: private: sl@0: virtual void Swap(TInt aLeft,TInt aRight) const; sl@0: private: sl@0: CSwDirectGdiPolygonFiller::SFastData& iFastData; sl@0: }; sl@0: sl@0: TSwapActiveEdges::TSwapActiveEdges(CSwDirectGdiPolygonFiller::SFastData& aFastData): sl@0: iFastData(aFastData) sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Swaps two elements of an activeEdgeList array. sl@0: @param aLeft The index of an array element participating in the swap. sl@0: @param aRight The index of an array element participating in the swap. sl@0: @see TSwap::Swap sl@0: */ sl@0: void TSwapActiveEdges::Swap(TInt aLeft,TInt aRight) const sl@0: { sl@0: CSwDirectGdiPolygonFiller::SFastActiveEdge& leftActiveEdge=iFastData.activeEdgeList[aLeft]; sl@0: CSwDirectGdiPolygonFiller::SFastActiveEdge& rightActiveEdge=iFastData.activeEdgeList[aRight]; sl@0: sl@0: const CSwDirectGdiPolygonFiller::SFastActiveEdge temp(leftActiveEdge); sl@0: leftActiveEdge=rightActiveEdge; sl@0: rightActiveEdge=temp; sl@0: sl@0: if (leftActiveEdge.scanLineIntersectionPtr!=NULL) sl@0: leftActiveEdge.scanLineIntersectionPtr->activeEdgePtr=&leftActiveEdge; sl@0: if (rightActiveEdge.scanLineIntersectionPtr!=NULL) sl@0: rightActiveEdge.scanLineIntersectionPtr->activeEdgePtr=&rightActiveEdge; sl@0: } sl@0: sl@0: /** sl@0: A utility class used to sort intersection lists based on the position of their first pixel. sl@0: @see CSwDirectGdiPolygonFiller sl@0: @see TKey sl@0: sl@0: @internalComponent sl@0: */ sl@0: NONSHARABLE_CLASS(TCompareScanLineIntersectionsFirstPixel) : public TKey sl@0: { sl@0: public: sl@0: TCompareScanLineIntersectionsFirstPixel(const CSwDirectGdiPolygonFiller::SFastData& aFastData); sl@0: private: sl@0: virtual TInt Compare(TInt aLeft,TInt aRight) const; sl@0: private: sl@0: const CSwDirectGdiPolygonFiller::SFastData& iFastData; sl@0: }; sl@0: sl@0: TCompareScanLineIntersectionsFirstPixel::TCompareScanLineIntersectionsFirstPixel(const CSwDirectGdiPolygonFiller::SFastData& aFastData): sl@0: iFastData(aFastData) sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Compare intersections based on the order of their first pixel. sl@0: sl@0: @param aLeft Index corresponding to the "left" side of the comparison. sl@0: @param aRight Index corresponding to the "right" side of the comparison. sl@0: sl@0: @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: sl@0: @see TKey::Compare sl@0: */ sl@0: TInt TCompareScanLineIntersectionsFirstPixel::Compare(TInt aLeft,TInt aRight) const sl@0: { sl@0: const TInt leftFirstPixel=iFastData.scanLineIntersectionList[aLeft].firstPixel; sl@0: const TInt rightFirstPixel=iFastData.scanLineIntersectionList[aRight].firstPixel; sl@0: if (leftFirstPixelrightFirstPixel) sl@0: return 1; sl@0: return 0; sl@0: } sl@0: sl@0: /** sl@0: A utility class used to swap entries in intersection list arrays during sort operations. sl@0: @see CSwDirectGdiPolygonFiller sl@0: @see TSwap sl@0: sl@0: @internalComponent sl@0: */ sl@0: NONSHARABLE_CLASS(TSwapScanLineIntersections) : public TSwap sl@0: { sl@0: public: sl@0: TSwapScanLineIntersections(CSwDirectGdiPolygonFiller::SFastData& aFastData); sl@0: private: sl@0: virtual void Swap(TInt aLeft,TInt aRight) const; sl@0: private: sl@0: CSwDirectGdiPolygonFiller::SFastData& iFastData; sl@0: }; sl@0: sl@0: TSwapScanLineIntersections::TSwapScanLineIntersections(CSwDirectGdiPolygonFiller::SFastData& aFastData): sl@0: iFastData(aFastData) sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Swaps two elements of a scanLineIntersectionList array. sl@0: @param aLeft The index of an array element participating in the swap. sl@0: @param aRight The index of an array element participating in the swap. sl@0: @see TSwap::Swap sl@0: */ sl@0: void TSwapScanLineIntersections::Swap(TInt aLeft,TInt aRight) const sl@0: { sl@0: CSwDirectGdiPolygonFiller::SFastScanLineIntersection& leftScanLineIntersection=iFastData.scanLineIntersectionList[aLeft]; sl@0: CSwDirectGdiPolygonFiller::SFastScanLineIntersection& rightScanLineIntersection=iFastData.scanLineIntersectionList[aRight]; sl@0: sl@0: const CSwDirectGdiPolygonFiller::SFastScanLineIntersection temp(leftScanLineIntersection); sl@0: leftScanLineIntersection=rightScanLineIntersection; sl@0: rightScanLineIntersection=temp; sl@0: sl@0: leftScanLineIntersection.activeEdgePtr->scanLineIntersectionPtr=&leftScanLineIntersection; sl@0: rightScanLineIntersection.activeEdgePtr->scanLineIntersectionPtr=&rightScanLineIntersection; sl@0: } sl@0: sl@0: /** sl@0: Sorts array elements sl@0: sl@0: @param aCount The number of elements in the array. sl@0: @param aKey A reference to a suitably initialised TKey derived object. sl@0: @param aSwap A reference to a suitably initialised TSwap derived object. sl@0: @panic DGDIAdapter 1015, if QuickSort failed. sl@0: sl@0: @internalComponent sl@0: */ sl@0: LOCAL_C void Sort(TInt aCount,const TKey& aKey,const TSwap& aSwap) sl@0: { sl@0: #if 1 // quick sort sl@0: const TInt error=User::QuickSort(aCount,aKey,aSwap); sl@0: GRAPHICS_ASSERT_ALWAYS(error==KErrNone, EDirectGdiPanicPolygonFiller); sl@0: #elif 0 // bubble sort sl@0: for (TInt i=1; i0; --j) sl@0: { sl@0: if (aKey.Compare(j-1,j)>0) sl@0: { sl@0: aSwap.Swap(j-1,j); sl@0: } sl@0: } sl@0: } sl@0: #else // heap sort sl@0: TInt startOfSortedPortion=aCount; sl@0: if (startOfSortedPortion>1) sl@0: { sl@0: TInt startOfHeap=startOfSortedPortion>>1; sl@0: FOREVER sl@0: { sl@0: GRAPHICS_ASSERT_DEBUG(startOfHeap>=0, EDirectGdiPanicPolygonFiller); sl@0: if (startOfHeap!=0) sl@0: { sl@0: --startOfHeap; sl@0: } sl@0: else sl@0: { sl@0: --startOfSortedPortion; sl@0: aSwap.Swap(startOfSortedPortion,0); sl@0: GRAPHICS_ASSERT_DEBUG(startOfSortedPortion>=1, EDirectGdiPanicPolygonFiller); sl@0: if (startOfSortedPortion==1) sl@0: { sl@0: break; sl@0: } sl@0: } sl@0: // put aArray[startOfHeap] into the correct place in the heap sl@0: TInt i=startOfHeap; sl@0: FOREVER sl@0: { sl@0: TInt j=(i+1)<<1; sl@0: if ((j>=startOfSortedPortion) || (aKey.Compare(j-1,j)>0)) sl@0: { sl@0: --j; sl@0: } sl@0: if ((j>=startOfSortedPortion) || (aKey.Compare(i,j)>=0)) sl@0: { sl@0: break; sl@0: } sl@0: aSwap.Swap(i,j); sl@0: i=j; sl@0: } sl@0: } sl@0: } sl@0: #endif sl@0: #if defined(_DEBUG) sl@0: { sl@0: for (TInt i=1; i* aPointArray, sl@0: DirectGdi::TFillRule aFillRule, TUsage aUsage) sl@0: { sl@0: GRAPHICS_ASSERT_ALWAYS(aPointArray!=NULL,EDirectGdiPanicPolygonFiller); sl@0: iPointArray=aPointArray; sl@0: iNumVertexes=iPointArray->Count(); sl@0: Construct(aFillRule,aUsage); sl@0: } sl@0: sl@0: /** sl@0: Builds up the internal meta-data needed to fill the polygon. sl@0: sl@0: @param aFillRule How filling should be achieved, as described by a DirectGdi::TFillRule object. sl@0: @param aUsage How the polygon should be used, see TUsage enumeration. sl@0: @panic DGDIAdapter 1015, if aFillRule is invalid, or aUsage is invalid. sl@0: */ sl@0: void CSwDirectGdiPolygonFiller::Construct(DirectGdi::TFillRule aFillRule, TUsage aUsage) sl@0: { sl@0: GRAPHICS_ASSERT_ALWAYS((aFillRule==DirectGdi::EAlternate) || (aFillRule==DirectGdi::EWinding), sl@0: EDirectGdiPanicPolygonFiller); sl@0: GRAPHICS_ASSERT_ALWAYS((aUsage==EGetAllPixelRunsSequentially) || (aUsage==EGetPixelRunsSequentiallyForSpecifiedScanLines), sl@0: EDirectGdiPanicPolygonFiller); sl@0: TInt i, j; sl@0: iFillRule=aFillRule; sl@0: iUseFastAlgorithm=(aUsage==EGetAllPixelRunsSequentially); sl@0: iToggler=EFalse; sl@0: iNestingLevel=0; sl@0: iScanLineIntersection=0; sl@0: iRightMostPixelOnScanLine=KMinTInt; sl@0: // find the first vertex and see if the polygon is all horizontal sl@0: iFirstVertex=0; // dummy default value sl@0: iPolygonIsAllHorizontal=ETrue; sl@0: sl@0: for (i=0; iy) sl@0: iFirstScanLine=y; sl@0: if (iLastScanLineiLastScanLine) sl@0: { sl@0: aExists=EFalse; sl@0: return; sl@0: } sl@0: sl@0: aExists=ETrue; sl@0: aScanLine=iCurrentScanLine; sl@0: sl@0: if (iPolygonIsAllHorizontal) sl@0: { sl@0: // set the start after the end sl@0: aStart=KMinTInt+1; sl@0: aEnd=KMinTInt; sl@0: ++iCurrentScanLine; sl@0: return; sl@0: } sl@0: sl@0: if (iUseFastAlgorithm) sl@0: { sl@0: TInt i, j; sl@0: sl@0: if (iScanLineIntersection==0) sl@0: { sl@0: // add any new edges to the active-edge-list sl@0: for (; (iFastData.nextEdgeToActivateupperVertex].iY!= sl@0: iFastData.vertexList[iFastData.activeEdgeList[i].edgePtr->lowerVertex].iY, EDirectGdiPanicPolygonFiller); sl@0: sl@0: if (iFastData.vertexList[iFastData.activeEdgeList[i].edgePtr->upperVertex].iY==iCurrentScanLine) sl@0: // the scan-line is intersecting active-edge i at its upper-vertex sl@0: FastHandleVertexIntersection(i, EFalse); sl@0: else if (iFastData.vertexList[iFastData.activeEdgeList[i].edgePtr->lowerVertex].iY==iCurrentScanLine) sl@0: // the scan-line is intersecting active-edge i at its lower-vertex sl@0: FastHandleVertexIntersection(i, ETrue); sl@0: else sl@0: // the scan-line is intersecting active-edge i at neither of its vertexes sl@0: SetFastIntersection(iFastData.activeEdgeList[i],*iFastData.activeEdgeList[i].scanLineIntersectionPtr); sl@0: } sl@0: sl@0: // N.B. iFastData.numScanLineIntersections is less than or equal to iFastData.numActiveEdges sl@0: sl@0: // sort the intersection-list into increasing order of first-pixel sl@0: Sort(iFastData.numScanLineIntersections,TCompareScanLineIntersectionsFirstPixel(iFastData),TSwapScanLineIntersections(iFastData)); sl@0: sl@0: GRAPHICS_ASSERT_DEBUG(iFastData.numScanLineIntersections>=2, EDirectGdiPanicPolygonFiller); sl@0: } sl@0: sl@0: // depending on the rule used, find the pixel-run sl@0: TBool doFill=EFalse; // dummy initialization to prevent compiler warning sl@0: if (iScanLineIntersectionedgePtr->lowerVertex].iY!= sl@0: iFastData.vertexList[iFastData.scanLineIntersectionList[iScanLineIntersection].activeEdgePtr->edgePtr->upperVertex].iY, sl@0: EDirectGdiPanicPolygonFiller); sl@0: sl@0: if (iFastData.scanLineIntersectionList[iScanLineIntersection].activeEdgePtr->edgePtr->lowerVertex== sl@0: (iFastData.scanLineIntersectionList[iScanLineIntersection].activeEdgePtr->edgePtr->upperVertex+1)%iNumVertexes) sl@0: ++iNestingLevel; sl@0: else sl@0: --iNestingLevel; sl@0: sl@0: doFill=(iNestingLevel!=0); sl@0: break; sl@0: } sl@0: sl@0: if (doFill) sl@0: { sl@0: aStart=Max(iRightMostPixelOnScanLine, iFastData.scanLineIntersectionList[iScanLineIntersection].lastPixel)+1; sl@0: aEnd=iFastData.scanLineIntersectionList[iScanLineIntersection+1].firstPixel-1; sl@0: } sl@0: else sl@0: { sl@0: // set the start after the end sl@0: aStart=KMinTInt+1; sl@0: aEnd=KMinTInt; sl@0: } sl@0: sl@0: if (iRightMostPixelOnScanLineedgePtr->lowerVertex].iY!= sl@0: iFastData.vertexList[iFastData.scanLineIntersectionList[iScanLineIntersection].activeEdgePtr->edgePtr->upperVertex].iY, sl@0: EDirectGdiPanicPolygonFiller); sl@0: sl@0: switch (iFillRule) sl@0: { sl@0: case DirectGdi::EAlternate: sl@0: iToggler=!iToggler; sl@0: GRAPHICS_ASSERT_DEBUG(iToggler==0, EDirectGdiPanicPolygonFiller); sl@0: break; sl@0: case DirectGdi::EWinding: sl@0: if (iFastData.scanLineIntersectionList[iScanLineIntersection].activeEdgePtr->edgePtr->lowerVertex== sl@0: (iFastData.scanLineIntersectionList[iScanLineIntersection].activeEdgePtr->edgePtr->upperVertex+1)%iNumVertexes) sl@0: ++iNestingLevel; sl@0: else sl@0: --iNestingLevel; sl@0: GRAPHICS_ASSERT_DEBUG((iNumVertexes==2) || (iNestingLevel==0), EDirectGdiPanicPolygonFiller); sl@0: break; sl@0: } sl@0: sl@0: // remove any scan-line-intersections associated with old active-edges sl@0: for (i=0; iedgePtr->lowerVertex].iY==iCurrentScanLine) sl@0: { sl@0: iFastData.scanLineIntersectionList[i].activeEdgePtr->scanLineIntersectionPtr=NULL; sl@0: sl@0: // ripple all the entries in the scan-line-intersection-list after this one back one place sl@0: for (j=i+1; jscanLineIntersectionPtr=&iFastData.scanLineIntersectionList[j-1]; sl@0: } sl@0: sl@0: iFastData.scanLineIntersectionList[j-1].activeEdgePtr=NULL; sl@0: --iFastData.numScanLineIntersections; sl@0: } sl@0: else sl@0: ++i; sl@0: sl@0: // remove any old edges from the active-edge-list sl@0: for (i=0; ilowerVertex].iY==iCurrentScanLine) sl@0: { sl@0: GRAPHICS_ASSERT_DEBUG(iFastData.activeEdgeList[i].scanLineIntersectionPtr==NULL, EDirectGdiPanicPolygonFiller); sl@0: sl@0: // ripple all the entries in the active-edge-list after this one back one place sl@0: for (j=i+1; jactiveEdgePtr=&iFastData.activeEdgeList[j-1]; sl@0: } sl@0: sl@0: iFastData.activeEdgeList[j-1].scanLineIntersectionPtr=NULL; sl@0: --iFastData.numActiveEdges; sl@0: } sl@0: else sl@0: ++i; sl@0: sl@0: #if defined(_DEBUG) sl@0: for (i=0; iactiveEdgePtr== sl@0: &iFastData.activeEdgeList[i], EDirectGdiPanicPolygonFiller); sl@0: } sl@0: sl@0: for (i=0; iscanLineIntersectionPtr== sl@0: &iFastData.scanLineIntersectionList[i], EDirectGdiPanicPolygonFiller); sl@0: } sl@0: #endif sl@0: sl@0: iScanLineIntersection=0; sl@0: ++iCurrentScanLine; sl@0: iRightMostPixelOnScanLine=KMinTInt; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: GetNextPixelRunOnSpecifiedScanLine(aExists, iCurrentScanLine, aStart, aEnd); sl@0: if (!aExists) sl@0: GetNextPixelRunOnSpecifiedScanLine(aExists, ++iCurrentScanLine, aStart, aEnd); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: Similar to GetNextPixelRun(aExists, aScanLine, aStart, aEnd) this method is used to draw the relevant sl@0: vertex intersections for a polygon but only for an individual specified scan line. The method sl@0: can use either the fast or slow polygon algorithm depending upon the state of aUsage. sl@0: sl@0: @param aExists Will be set to false if the line does not pass through the polygon or if sl@0: a polygon with no vertexes is specified, otherwise ETrue on return. sl@0: @param aScanLine The scan line to be drawn on. Used to set iScanline sl@0: @param aStart On return, contains the position on the scan line to start the run. sl@0: @param aEnd The position on the scan line to end the run, returned. sl@0: @panic DGDIAdapter 1015, if iUseFastAlgorithm is ETrue (debug only). sl@0: */ sl@0: void CSwDirectGdiPolygonFiller::GetNextPixelRunOnSpecifiedScanLine(TBool& aExists, sl@0: TInt aScanLine, sl@0: TInt& aStart, sl@0: TInt& aEnd) sl@0: { sl@0: TInt i, j, k; sl@0: sl@0: GRAPHICS_ASSERT_DEBUG(!iUseFastAlgorithm, EDirectGdiPanicPolygonFiller); sl@0: sl@0: if (aScanLineiLastScanLine) sl@0: { sl@0: aExists=EFalse; sl@0: return; sl@0: } sl@0: sl@0: aExists=ETrue; sl@0: iCurrentScanLine=aScanLine; sl@0: sl@0: if (iPolygonIsAllHorizontal) sl@0: { sl@0: // set the start after the end sl@0: aStart=KMinTInt+1; sl@0: aEnd=KMinTInt; sl@0: ++iCurrentScanLine; sl@0: return; sl@0: } sl@0: sl@0: if (iScanLineIntersection==0) sl@0: { sl@0: iSlowData.numIntersectionsWithSameFirstPixelMetThisTime=0; sl@0: iSlowData.numScanLineIntersections=0; sl@0: iSlowData.scanLineComplete=ETrue; sl@0: sl@0: // find the left-most iSlowData::EStoreSize number (or less) of intersections with this scan-line sl@0: for (i=iFirstVertex; ilower.iY) sl@0: { sl@0: TPoint temp=upper; sl@0: upper=lower; sl@0: lower=temp; sl@0: } sl@0: sl@0: if ((iCurrentScanLine>=upper.iY) && (iCurrentScanLine<=lower.iY)) sl@0: { sl@0: // check that the edge starting at vertex i%iNumVertexes is not horizontal sl@0: GRAPHICS_ASSERT_DEBUG(upper.iY!=lower.iY, EDirectGdiPanicPolygonFiller); sl@0: sl@0: // step through the line-generator until the current scan-line is reached sl@0: TPoint startPos, endPos; sl@0: JumpToCurrentScanLine(iSlowData.lineGenerator, upper, lower, startPos, endPos); sl@0: sl@0: // find the intersection start and end pixels sl@0: SSlowScanLineIntersection scanLineIntersection; sl@0: scanLineIntersection.firstPixel=Min(startPos.iX, endPos.iX); sl@0: scanLineIntersection.lastPixel=Max(startPos.iX, endPos.iX); sl@0: scanLineIntersection.firstVertexOfEdge=i%iNumVertexes; sl@0: sl@0: // handle horizontal runs and minima/maxima sl@0: if (upper.iY==iCurrentScanLine) sl@0: SlowHandleVertexIntersection(scanLineIntersection, i, EFalse); sl@0: else if (lower.iY==iCurrentScanLine) sl@0: SlowHandleVertexIntersection(scanLineIntersection, i, ETrue); sl@0: sl@0: // see if there have been other intersections with the same first-pixel sl@0: if (scanLineIntersection.firstPixel==iSlowData.firstPixelOfLastIntersectionInPrevBuffer) sl@0: ++iSlowData.numIntersectionsWithSameFirstPixelMetThisTime; sl@0: sl@0: // if the intersection has not already been included in a previous buffer-load sl@0: if ((scanLineIntersection.firstPixel>iSlowData.firstPixelOfLastIntersectionInPrevBuffer) || sl@0: ((scanLineIntersection.firstPixel==iSlowData.firstPixelOfLastIntersectionInPrevBuffer) && sl@0: (iSlowData.numIntersectionsWithSameFirstPixelMetThisTime>= sl@0: iSlowData.numIntersectionsWithSameFirstPixelPreviouslyMet))) sl@0: { sl@0: // put the intersection in the right place in the intersection list (if there is room) sl@0: for (j=0; jj; --k) sl@0: iSlowData.scanLineIntersectionList[k]=iSlowData.scanLineIntersectionList[k-1]; sl@0: iSlowData.scanLineIntersectionList[j]=scanLineIntersection; sl@0: break; sl@0: } sl@0: if (j==iSlowData.numScanLineIntersections) sl@0: { sl@0: if (iSlowData.numScanLineIntersections0) && (iSlowData.firstPixelOfLastIntersectionInPrevBuffer== sl@0: iSlowData.scanLineIntersectionList[i-1].firstPixel); --i) sl@0: ++iSlowData.numIntersectionsWithSameFirstPixelPreviouslyMet; sl@0: } sl@0: } sl@0: } sl@0: sl@0: // depending on the rule used, find the pixel-run sl@0: TBool doFill=EFalse; // dummy initialization to prevent compiler warning sl@0: if (iScanLineIntersection sl@0: Point((iSlowData.scanLineIntersectionList[iScanLineIntersection].firstVertexOfEdge+1)%iNumVertexes).iY) sl@0: ++iNestingLevel; sl@0: else sl@0: --iNestingLevel; sl@0: sl@0: doFill=(iNestingLevel!=0); sl@0: break; sl@0: } sl@0: sl@0: if (doFill) sl@0: { sl@0: aStart=Max(iRightMostPixelOnScanLine, iSlowData.scanLineIntersectionList[iScanLineIntersection].lastPixel)+1; sl@0: aEnd=iSlowData.scanLineIntersectionList[iScanLineIntersection+1].firstPixel-1; sl@0: } sl@0: else sl@0: { sl@0: // set the start after the end sl@0: aStart=KMinTInt+1; sl@0: aEnd=KMinTInt; sl@0: } sl@0: sl@0: if (iRightMostPixelOnScanLine sl@0: Point((iSlowData.scanLineIntersectionList[iScanLineIntersection].firstVertexOfEdge+1)%iNumVertexes).iY) sl@0: ++iNestingLevel; sl@0: else sl@0: --iNestingLevel; sl@0: sl@0: GRAPHICS_ASSERT_DEBUG((!iSlowData.scanLineComplete) || (iNumVertexes==2) || (iNestingLevel==0), EDirectGdiPanicPolygonFiller); sl@0: break; sl@0: } sl@0: } sl@0: sl@0: iScanLineIntersection=0; sl@0: if (iSlowData.scanLineComplete) sl@0: { sl@0: ++iCurrentScanLine; sl@0: iRightMostPixelOnScanLine=KMinTInt; sl@0: iSlowData.numIntersectionsWithSameFirstPixelPreviouslyMet=0; sl@0: iSlowData.scanLineComplete=EFalse; sl@0: iSlowData.firstPixelOfLastIntersectionInPrevBuffer=KMinTInt; sl@0: } sl@0: } sl@0: } sl@0: sl@0: /** sl@0: Builds up drawing meta-data in the case where a scanline intersects the active edge at a vertex using sl@0: fast algorithms. sl@0: sl@0: @param aCurrentActiveEdge Index of the current active edge sl@0: @param aIsLowerVertex If the vertex is the lower vertex ETrue otherwise EFalse. sl@0: @panic DGDIAdapter 1015, if iUseFastAlgorithm is EFalse. sl@0: sl@0: @see GetNextPixelRun() sl@0: */ sl@0: void CSwDirectGdiPolygonFiller::FastHandleVertexIntersection(TInt& aCurrentActiveEdge, sl@0: TBool aIsLowerVertex) sl@0: { sl@0: GRAPHICS_ASSERT_DEBUG(iUseFastAlgorithm, EDirectGdiPanicPolygonFiller); sl@0: sl@0: if (iFastData.vertexList[(iFastData.activeEdgeList[aCurrentActiveEdge].edgePtr->firstVertex+1)%iNumVertexes].iY==iCurrentScanLine) sl@0: // it is the second vertex of active-edge aCurrentActiveEdge that coincides with the current scan-line sl@0: { sl@0: TInt origActiveEdge=aCurrentActiveEdge; sl@0: SFastScanLineIntersection scanLineIntersection; sl@0: scanLineIntersection.activeEdgePtr=NULL; sl@0: SetFastIntersection(iFastData.activeEdgeList[origActiveEdge], scanLineIntersection); sl@0: sl@0: // walk through subsequent adjacent horizontal active-edges sl@0: FOREVER sl@0: { sl@0: // exit the loop if the vertex-run *is* a maximum or a minimum sl@0: const SFastEdge* tempEdgePtr=iFastData.activeEdgeList[(aCurrentActiveEdge+1)%iFastData.numActiveEdges].edgePtr; sl@0: TBool isMaxOrMin = EFalse; sl@0: sl@0: switch(aIsLowerVertex) sl@0: { sl@0: case EFalse: sl@0: isMaxOrMin = (iFastData.vertexList[tempEdgePtr->lowerVertex].iY > iCurrentScanLine); sl@0: break; sl@0: sl@0: case ETrue: sl@0: isMaxOrMin = (iFastData.vertexList[tempEdgePtr->upperVertex].iY < iCurrentScanLine); sl@0: break; sl@0: } sl@0: sl@0: if (isMaxOrMin) sl@0: // the vertex-run is a maximum or a minimum sl@0: { sl@0: if (aIsLowerVertex) sl@0: { sl@0: *iFastData.activeEdgeList[origActiveEdge].scanLineIntersectionPtr=scanLineIntersection; sl@0: iFastData.activeEdgeList[origActiveEdge].scanLineIntersectionPtr->activeEdgePtr=&iFastData.activeEdgeList[origActiveEdge]; sl@0: } sl@0: else sl@0: { sl@0: // add an intersection sl@0: iFastData.scanLineIntersectionList[iFastData.numScanLineIntersections]=scanLineIntersection; sl@0: iFastData.scanLineIntersectionList[iFastData.numScanLineIntersections].activeEdgePtr=&iFastData.activeEdgeList[origActiveEdge]; sl@0: iFastData.activeEdgeList[origActiveEdge].scanLineIntersectionPtr=&iFastData.scanLineIntersectionList[iFastData.numScanLineIntersections]; sl@0: ++iFastData.numScanLineIntersections; sl@0: } sl@0: break; sl@0: } sl@0: sl@0: // the active-edge is horizontal, or the vertex-run is not a maximum or a minimum sl@0: sl@0: ++aCurrentActiveEdge; sl@0: GRAPHICS_ASSERT_DEBUG(aCurrentActiveEdgeminX) sl@0: scanLineIntersection.firstPixel=minX; sl@0: if (scanLineIntersection.lastPixelupperVertex].iY < iCurrentScanLine); sl@0: break; sl@0: sl@0: case ETrue: sl@0: isNeitherMaxOrMin = (iFastData.vertexList[tempEdgePtr->lowerVertex].iY > iCurrentScanLine); sl@0: break; sl@0: } sl@0: sl@0: // exit the loop if the vertex-run is *not* a maximum or a minimum sl@0: if (isNeitherMaxOrMin) sl@0: { sl@0: TInt newActiveEdge; sl@0: TInt oldActiveEdge; sl@0: if (aIsLowerVertex) sl@0: { sl@0: newActiveEdge=aCurrentActiveEdge; sl@0: oldActiveEdge=origActiveEdge; sl@0: } sl@0: else sl@0: { sl@0: newActiveEdge=origActiveEdge; sl@0: oldActiveEdge=aCurrentActiveEdge; sl@0: } sl@0: iFastData.activeEdgeList[newActiveEdge].scanLineIntersectionPtr=iFastData.activeEdgeList[oldActiveEdge].scanLineIntersectionPtr; sl@0: iFastData.activeEdgeList[oldActiveEdge].scanLineIntersectionPtr=NULL; sl@0: *iFastData.activeEdgeList[newActiveEdge].scanLineIntersectionPtr=scanLineIntersection; sl@0: iFastData.activeEdgeList[newActiveEdge].scanLineIntersectionPtr->activeEdgePtr=&iFastData.activeEdgeList[newActiveEdge]; sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: else sl@0: // it is the first vertex of active-edge aCurrentActiveEdge that coincides with the current scan-line sl@0: { sl@0: #if defined(_DEBUG) sl@0: // check that the vertex we are at is a maximum or a minimum sl@0: TInt previousNotLevelVertex; sl@0: TInt SFastEdge::*vertex=(aIsLowerVertex)? &SFastEdge::lowerVertex: &SFastEdge::upperVertex; sl@0: for (previousNotLevelVertex=iFastData.activeEdgeList[aCurrentActiveEdge].edgePtr->*vertex; sl@0: iFastData.vertexList[iFastData.activeEdgeList[aCurrentActiveEdge].edgePtr->*vertex].iY==iFastData.vertexList[previousNotLevelVertex].iY; sl@0: previousNotLevelVertex=(previousNotLevelVertex+iNumVertexes-1)%iNumVertexes) sl@0: ; sl@0: TInt nextNotLevelVertex=(iFastData.activeEdgeList[aCurrentActiveEdge].edgePtr->*vertex+1)%iNumVertexes; sl@0: GRAPHICS_ASSERT_DEBUG((iFastData.vertexList[iFastData.activeEdgeList[aCurrentActiveEdge].edgePtr->*vertex].iY>iFastData.vertexList[previousNotLevelVertex].iY)== sl@0: (iFastData.vertexList[iFastData.activeEdgeList[aCurrentActiveEdge].edgePtr->*vertex].iY>iFastData.vertexList[nextNotLevelVertex].iY), sl@0: EDirectGdiPanicPolygonFiller); sl@0: #endif sl@0: sl@0: if (aIsLowerVertex) sl@0: SetFastIntersection(iFastData.activeEdgeList[aCurrentActiveEdge],*iFastData.activeEdgeList[aCurrentActiveEdge].scanLineIntersectionPtr); sl@0: else sl@0: { sl@0: // add an intersection sl@0: SetFastIntersection(iFastData.activeEdgeList[aCurrentActiveEdge], iFastData.scanLineIntersectionList[iFastData.numScanLineIntersections]); sl@0: iFastData.scanLineIntersectionList[iFastData.numScanLineIntersections].activeEdgePtr=&iFastData.activeEdgeList[aCurrentActiveEdge]; sl@0: iFastData.activeEdgeList[aCurrentActiveEdge].scanLineIntersectionPtr=&iFastData.scanLineIntersectionList[iFastData.numScanLineIntersections]; sl@0: ++iFastData.numScanLineIntersections; sl@0: } sl@0: } sl@0: } sl@0: sl@0: /** sl@0: Calculates the extent of the intersection for the current active edge. sl@0: sl@0: @param aActiveEdge The current active edge. sl@0: @param aScanLineIntersection On return, contains the intersection data. sl@0: */ sl@0: void CSwDirectGdiPolygonFiller::SetFastIntersection(SFastActiveEdge& aActiveEdge, SFastScanLineIntersection& aScanLineIntersection) sl@0: { sl@0: GRAPHICS_ASSERT_DEBUG(iUseFastAlgorithm, EDirectGdiPanicPolygonFiller); sl@0: sl@0: TPoint startPos, endPos; sl@0: sl@0: aActiveEdge.lineGenerator.SingleScanline(startPos, endPos); sl@0: aScanLineIntersection.firstPixel=Min(startPos.iX, endPos.iX); sl@0: aScanLineIntersection.lastPixel=Max(startPos.iX, endPos.iX); sl@0: } sl@0: sl@0: /** sl@0: Builds up drawing meta-data in the case where a scanline intersects the active edge at a vertex using sl@0: slow algorithms. sl@0: sl@0: @param aScanLineIntersection Reference to the current intersection data. sl@0: @param aVertexStartingCurrentEdge Current vertex. sl@0: @param aIsLowerVertex If the vertex is the lower vertex ETrue otherwise EFalse. sl@0: @see GetNextPixelRunOnSpecifiedScanLine() sl@0: */ sl@0: void CSwDirectGdiPolygonFiller::SlowHandleVertexIntersection(SSlowScanLineIntersection& aScanLineIntersection, sl@0: TInt& aVertexStartingCurrentEdge, sl@0: TBool aIsLowerVertex) sl@0: { sl@0: if (Point((aVertexStartingCurrentEdge+1)%iNumVertexes).iY==iCurrentScanLine) sl@0: // it is the second vertex of the edge starting at vertex aVertexStartingCurrentEdge%iNumVertexes sl@0: // that coincides with the current scan-line sl@0: { sl@0: // walk through subsequent adjacent horizontal active-edges sl@0: for (; ; ) sl@0: { sl@0: TPoint nextVertexButOne=Point((aVertexStartingCurrentEdge+2)%iNumVertexes); sl@0: TBool isMaxOrMin = EFalse; sl@0: sl@0: switch(aIsLowerVertex) sl@0: { sl@0: case EFalse: sl@0: isMaxOrMin = (nextVertexButOne.iY > iCurrentScanLine); sl@0: break; sl@0: sl@0: case ETrue: sl@0: isMaxOrMin = (nextVertexButOne.iY < iCurrentScanLine); sl@0: break; sl@0: } sl@0: sl@0: // exit the loop if the vertex-run *is* a maximum or a minimum sl@0: if (isMaxOrMin) sl@0: { sl@0: break; sl@0: } sl@0: sl@0: // the edge starting at vertex aVertexStartingCurrentEdge%iNumVertexes is horizontal, or the vertex-run is not a sl@0: // maximum or a minimum sl@0: sl@0: ++aVertexStartingCurrentEdge; sl@0: GRAPHICS_ASSERT_DEBUG(aVertexStartingCurrentEdge%iNumVertexes!=iFirstVertex, EDirectGdiPanicPolygonFiller); sl@0: sl@0: // step through the line-generator until the current scan-line is reached sl@0: TPoint upper=Point(aVertexStartingCurrentEdge%iNumVertexes); sl@0: TPoint lower=nextVertexButOne; sl@0: if (upper.iY>lower.iY) sl@0: { sl@0: TPoint temp=upper; sl@0: upper=lower; sl@0: lower=temp; sl@0: } sl@0: sl@0: TPoint startPos, endPos; sl@0: if (upper.iY!=lower.iY) sl@0: JumpToCurrentScanLine(iSlowData.lineGenerator, upper, lower, startPos, endPos); sl@0: else sl@0: { sl@0: // 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: startPos=upper; sl@0: endPos=lower; sl@0: } sl@0: sl@0: // expand the intersection, if necessary sl@0: TInt minX=Min(startPos.iX, endPos.iX); sl@0: TInt maxX=Max(startPos.iX, endPos.iX); sl@0: if (aScanLineIntersection.firstPixel>minX) sl@0: aScanLineIntersection.firstPixel=minX; sl@0: if (aScanLineIntersection.lastPixel iCurrentScanLine); sl@0: break; sl@0: } sl@0: sl@0: // exit the loop if the vertex-run is *not* a maximum or a minimum sl@0: if (isNeitherMaxOrMin) sl@0: { sl@0: if (aIsLowerVertex) sl@0: { sl@0: aScanLineIntersection.firstVertexOfEdge=aVertexStartingCurrentEdge%iNumVertexes; sl@0: } sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: else sl@0: // it is the first vertex of the edge starting at vertex aVertexStartingCurrentEdge%iNumVertexes sl@0: // that coincides with the current scan-line sl@0: { sl@0: #if defined(_DEBUG) sl@0: // check that the vertex we are at is a maximum or a minimum sl@0: TInt previousNotLevelVertex; sl@0: for (previousNotLevelVertex=aVertexStartingCurrentEdge%iNumVertexes; sl@0: Point(aVertexStartingCurrentEdge%iNumVertexes).iY== sl@0: Point(previousNotLevelVertex).iY; sl@0: previousNotLevelVertex=(previousNotLevelVertex+iNumVertexes-1)%iNumVertexes) sl@0: ; sl@0: TInt nextNotLevelVertex=(aVertexStartingCurrentEdge+1)%iNumVertexes; sl@0: TInt previousY=Point(previousNotLevelVertex).iY; sl@0: TInt currentY=Point(aVertexStartingCurrentEdge%iNumVertexes).iY; sl@0: TInt nextY=Point(nextNotLevelVertex).iY; sl@0: GRAPHICS_ASSERT_DEBUG((currentY>previousY) == (currentY>nextY), EDirectGdiPanicPolygonFiller); sl@0: #endif sl@0: } sl@0: } sl@0: sl@0: /** sl@0: For a given line between two given endpoints, calculate the right and leftmost pixels of the line segment sl@0: that fall on the current scanline. sl@0: sl@0: @param aLineGenerator Reference to class used to calculate the pixels on the line. sl@0: @param aUpper The upper endpoint of the line. sl@0: @param aLower The lower endpoint of the line. sl@0: @param aStartPos On return, contains the position of the line's leftmost pixel on the current scanline. sl@0: @param aEndPos On return, contains the position of the line's rightmost pixel on the current scanline. sl@0: */ sl@0: void CSwDirectGdiPolygonFiller::JumpToCurrentScanLine(TLinearDDA& aLineGenerator, sl@0: const TPoint& aUpper, sl@0: const TPoint& aLower, sl@0: TPoint& aStartPos, sl@0: TPoint& aEndPos) const sl@0: { sl@0: GRAPHICS_ASSERT_DEBUG(aUpper.iY<=aLower.iY, EDirectGdiPanicPolygonFiller); sl@0: aLineGenerator.Construct(aUpper, aLower); sl@0: if (aUpper.iY