svgtopt/gfx2d/src/GfxRenderer/GfxPolygonRendererP.cpp
changeset 0 d46562c3d99d
equal deleted inserted replaced
-1:000000000000 0:d46562c3d99d
       
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Graphics Extension Library source file
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "GfxPolygonRendererP.h"
       
    20 #include "GfxPaint.h"
       
    21 #include "GfxColor.h"
       
    22 #include "GfxRendererInfoP.h"
       
    23 #include "GfxEdgeListP.h"
       
    24 
       
    25 
       
    26 // ---------------------------------------------------------------------------
       
    27 // Constructor
       
    28 // ---------------------------------------------------------------------------
       
    29 // --------------------------------------------------------------------------
       
    30 // TGfxPolygonRendererP::TGfxPolygonRendererP()
       
    31 // ---------------------------------------------------------------------------
       
    32 TGfxPolygonRendererP::TGfxPolygonRendererP()
       
    33     {
       
    34     }
       
    35 
       
    36 // --------------------------------------------------------------------------
       
    37 // void TGfxPolygonRendererP::InitializeP( CGfxEdgeListP* aEdgeList,
       
    38 // ---------------------------------------------------------------------------
       
    39 void TGfxPolygonRendererP::InitializeP( CGfxEdgeListP* aEdgeList,
       
    40                                         TGfxRendererInfoP* aRenderInfo,
       
    41                                         MGfxPaint* aPaint,
       
    42                                         TBool aWindingNoneZero )
       
    43     {
       
    44     iEdgeList = aEdgeList;
       
    45     iRenderInfo = aRenderInfo;
       
    46     iPaint = aPaint;
       
    47     iWindingNoneZero = aWindingNoneZero;
       
    48     }
       
    49 
       
    50 // --------------------------------------------------------------------------
       
    51 // void TGfxPolygonRendererP::RenderScanlineL( TInt aY, TUint32 /* aAlpha */ )
       
    52 // ---------------------------------------------------------------------------
       
    53 void TGfxPolygonRendererP::RenderScanlineL( TInt aY, TUint32 /* aAlpha */ )
       
    54     {
       
    55     if ( iRenderInfo->iClipMinY >= aY || aY > iRenderInfo->iClipMaxY )
       
    56         return;
       
    57 
       
    58     TInt edgeCount = iEdgeList->iEdgesCount;
       
    59     TGfxSegEdge dummyEdge;
       
    60     dummyEdge.iEnd = -1;    // less than 0
       
    61     dummyEdge.iSign = 100;  // neither -1, 0, or 1
       
    62 
       
    63     TUint16 flatColor;
       
    64     flatColor = TGfxColor( iPaint->FlatColor() ).ColorRgb();
       
    65 
       
    66     // ************ Buffer is 2 bytes per pixel **********
       
    67     TUint16* fb;
       
    68 
       
    69     fb = ( ( TUint16 * ) iRenderInfo->iDstBuf ) +
       
    70            aY * iRenderInfo->iWidth;
       
    71 
       
    72 
       
    73     TInt i, j;
       
    74 
       
    75     TInt edgeSignSum = 0;
       
    76     TBool fill = EFalse;
       
    77     TGfxSegEdge* lastEdge =& dummyEdge; // iEdgeList->EdgeList();
       
    78     TGfxSegEdge* currentEdge = iEdgeList->EdgeList();
       
    79     for ( i = 0; i < edgeCount; i++ )
       
    80         {
       
    81         // Fill between edges
       
    82         TInt32 fbXmin, fbXmax;
       
    83         if ( fill )
       
    84             {
       
    85             fbXmin = lastEdge->iStart + iEdgeList->iMinX;
       
    86             fbXmax = currentEdge->iEnd + iEdgeList->iMinX;
       
    87             if ( fbXmax >= iRenderInfo->iClipMinX &&
       
    88                            fbXmin < iRenderInfo->iClipMaxX )  // inside clipping
       
    89             {
       
    90                 if ( fbXmin < iRenderInfo->iClipMinX )
       
    91                     {
       
    92                     fbXmin = iRenderInfo->iClipMinX;
       
    93                     }
       
    94                 if ( iRenderInfo->iClipMaxX <= fbXmax )
       
    95                     {
       
    96                     fbXmax = iRenderInfo->iClipMaxX - 1;
       
    97                     }
       
    98                 TUint16* fbb =& fb[fbXmin];
       
    99 
       
   100                 TInt fbw = fbXmax - fbXmin;
       
   101                 if ( fbw > 10 )
       
   102                     {
       
   103                     DrawHLine( fbb, flatColor, fbXmin, fbw );
       
   104                     }
       
   105                 else
       
   106                     {
       
   107                     for ( j = fbXmin; j <= fbXmax ; j++ )
       
   108                         *fbb++ = flatColor;
       
   109                     }
       
   110                 }
       
   111             }   // end if (fill)
       
   112 
       
   113         // update sum of sign and determine fill/non-fill
       
   114 
       
   115         if ( iWindingNoneZero )
       
   116             {
       
   117             fill = ( edgeSignSum += currentEdge->iSign );  // Non-zero rule.
       
   118             }
       
   119         else
       
   120             {
       
   121             fill = ( ++edgeSignSum & 1 );       // Even/odd rule.
       
   122             }
       
   123 
       
   124         lastEdge = currentEdge;
       
   125         currentEdge = currentEdge->iNext;
       
   126         } // end for i (each edges)
       
   127     }
       
   128 
       
   129 
       
   130