LCOV - code coverage report
Current view: directory - gfx/skia/src/core - SkScan_Path.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 374 0 0.0 %
Date: 2012-06-02 Functions: 33 0 0.0 %

       1                 : /*
       2                 :  * Copyright 2006 The Android Open Source Project
       3                 :  *
       4                 :  * Use of this source code is governed by a BSD-style license that can be
       5                 :  * found in the LICENSE file.
       6                 :  */
       7                 : 
       8                 : #include "SkScanPriv.h"
       9                 : #include "SkBlitter.h"
      10                 : #include "SkEdge.h"
      11                 : #include "SkEdgeBuilder.h"
      12                 : #include "SkGeometry.h"
      13                 : #include "SkPath.h"
      14                 : #include "SkQuadClipper.h"
      15                 : #include "SkRasterClip.h"
      16                 : #include "SkRegion.h"
      17                 : #include "SkTemplates.h"
      18                 : 
      19                 : #define kEDGE_HEAD_Y    SK_MinS32
      20                 : #define kEDGE_TAIL_Y    SK_MaxS32
      21                 : 
      22                 : #ifdef SK_DEBUG
      23               0 :     static void validate_sort(const SkEdge* edge) {
      24               0 :         int y = kEDGE_HEAD_Y;
      25                 : 
      26               0 :         while (edge->fFirstY != SK_MaxS32) {
      27               0 :             edge->validate();
      28               0 :             SkASSERT(y <= edge->fFirstY);
      29                 : 
      30               0 :             y = edge->fFirstY;
      31               0 :             edge = edge->fNext;
      32                 :         }
      33               0 :     }
      34                 : #else
      35                 :     #define validate_sort(edge)
      36                 : #endif
      37                 : 
      38               0 : static inline void remove_edge(SkEdge* edge) {
      39               0 :     edge->fPrev->fNext = edge->fNext;
      40               0 :     edge->fNext->fPrev = edge->fPrev;
      41               0 : }
      42                 : 
      43               0 : static inline void swap_edges(SkEdge* prev, SkEdge* next) {
      44               0 :     SkASSERT(prev->fNext == next && next->fPrev == prev);
      45                 : 
      46                 :     // remove prev from the list
      47               0 :     prev->fPrev->fNext = next;
      48               0 :     next->fPrev = prev->fPrev;
      49                 : 
      50                 :     // insert prev after next
      51               0 :     prev->fNext = next->fNext;
      52               0 :     next->fNext->fPrev = prev;
      53               0 :     next->fNext = prev;
      54               0 :     prev->fPrev = next;
      55               0 : }
      56                 : 
      57               0 : static void backward_insert_edge_based_on_x(SkEdge* edge SkDECLAREPARAM(int, curr_y)) {
      58               0 :     SkFixed x = edge->fX;
      59                 : 
      60               0 :     for (;;) {
      61               0 :         SkEdge* prev = edge->fPrev;
      62                 : 
      63                 :         // add 1 to curr_y since we may have added new edges (built from curves)
      64                 :         // that start on the next scanline
      65               0 :         SkASSERT(prev && prev->fFirstY <= curr_y + 1);
      66                 : 
      67               0 :         if (prev->fX <= x) {
      68                 :             break;
      69                 :         }
      70               0 :         swap_edges(prev, edge);
      71                 :     }
      72               0 : }
      73                 : 
      74               0 : static void insert_new_edges(SkEdge* newEdge, int curr_y) {
      75               0 :     SkASSERT(newEdge->fFirstY >= curr_y);
      76                 : 
      77               0 :     while (newEdge->fFirstY == curr_y) {
      78               0 :         SkEdge* next = newEdge->fNext;
      79               0 :         backward_insert_edge_based_on_x(newEdge  SkPARAM(curr_y));
      80               0 :         newEdge = next;
      81                 :     }
      82               0 : }
      83                 : 
      84                 : #ifdef SK_DEBUG
      85               0 : static void validate_edges_for_y(const SkEdge* edge, int curr_y) {
      86               0 :     while (edge->fFirstY <= curr_y) {
      87               0 :         SkASSERT(edge->fPrev && edge->fNext);
      88               0 :         SkASSERT(edge->fPrev->fNext == edge);
      89               0 :         SkASSERT(edge->fNext->fPrev == edge);
      90               0 :         SkASSERT(edge->fFirstY <= edge->fLastY);
      91                 : 
      92               0 :         SkASSERT(edge->fPrev->fX <= edge->fX);
      93               0 :         edge = edge->fNext;
      94                 :     }
      95               0 : }
      96                 : #else
      97                 :     #define validate_edges_for_y(edge, curr_y)
      98                 : #endif
      99                 : 
     100                 : #if defined _WIN32 && _MSC_VER >= 1300  // disable warning : local variable used without having been initialized
     101                 : #pragma warning ( push )
     102                 : #pragma warning ( disable : 4701 )
     103                 : #endif
     104                 : 
     105                 : typedef void (*PrePostProc)(SkBlitter* blitter, int y, bool isStartOfScanline);
     106                 : #define PREPOST_START   true
     107                 : #define PREPOST_END     false
     108                 : 
     109               0 : static void walk_edges(SkEdge* prevHead, SkPath::FillType fillType,
     110                 :                        SkBlitter* blitter, int start_y, int stop_y,
     111                 :                        PrePostProc proc) {
     112               0 :     validate_sort(prevHead->fNext);
     113                 : 
     114               0 :     int curr_y = start_y;
     115                 :     // returns 1 for evenodd, -1 for winding, regardless of inverse-ness
     116               0 :     int windingMask = (fillType & 1) ? 1 : -1;
     117                 : 
     118               0 :     for (;;) {
     119               0 :         int     w = 0;
     120               0 :         int     left SK_INIT_TO_AVOID_WARNING;
     121               0 :         bool    in_interval = false;
     122               0 :         SkEdge* currE = prevHead->fNext;
     123               0 :         SkFixed prevX = prevHead->fX;
     124                 : 
     125               0 :         validate_edges_for_y(currE, curr_y);
     126                 : 
     127               0 :         if (proc) {
     128               0 :             proc(blitter, curr_y, PREPOST_START);    // pre-proc
     129                 :         }
     130                 : 
     131               0 :         while (currE->fFirstY <= curr_y) {
     132               0 :             SkASSERT(currE->fLastY >= curr_y);
     133                 : 
     134               0 :             int x = (currE->fX + SK_Fixed1/2) >> 16;
     135               0 :             w += currE->fWinding;
     136               0 :             if ((w & windingMask) == 0) { // we finished an interval
     137               0 :                 SkASSERT(in_interval);
     138               0 :                 int width = x - left;
     139               0 :                 SkASSERT(width >= 0);
     140               0 :                 if (width)
     141               0 :                     blitter->blitH(left, curr_y, width);
     142               0 :                 in_interval = false;
     143               0 :             } else if (!in_interval) {
     144               0 :                 left = x;
     145               0 :                 in_interval = true;
     146                 :             }
     147                 : 
     148               0 :             SkEdge* next = currE->fNext;
     149                 :             SkFixed newX;
     150                 : 
     151               0 :             if (currE->fLastY == curr_y) {    // are we done with this edge?
     152               0 :                 if (currE->fCurveCount < 0) {
     153               0 :                     if (((SkCubicEdge*)currE)->updateCubic()) {
     154               0 :                         SkASSERT(currE->fFirstY == curr_y + 1);
     155                 : 
     156               0 :                         newX = currE->fX;
     157               0 :                         goto NEXT_X;
     158                 :                     }
     159               0 :                 } else if (currE->fCurveCount > 0) {
     160               0 :                     if (((SkQuadraticEdge*)currE)->updateQuadratic()) {
     161               0 :                         newX = currE->fX;
     162               0 :                         goto NEXT_X;
     163                 :                     }
     164                 :                 }
     165               0 :                 remove_edge(currE);
     166                 :             } else {
     167               0 :                 SkASSERT(currE->fLastY > curr_y);
     168               0 :                 newX = currE->fX + currE->fDX;
     169               0 :                 currE->fX = newX;
     170                 :             NEXT_X:
     171               0 :                 if (newX < prevX) { // ripple currE backwards until it is x-sorted
     172               0 :                     backward_insert_edge_based_on_x(currE  SkPARAM(curr_y));
     173                 :                 } else {
     174               0 :                     prevX = newX;
     175                 :                 }
     176                 :             }
     177               0 :             currE = next;
     178               0 :             SkASSERT(currE);
     179                 :         }
     180                 : 
     181               0 :         if (proc) {
     182               0 :             proc(blitter, curr_y, PREPOST_END);    // post-proc
     183                 :         }
     184                 : 
     185               0 :         curr_y += 1;
     186               0 :         if (curr_y >= stop_y) {
     187                 :             break;
     188                 :         }
     189                 :         // now currE points to the first edge with a Yint larger than curr_y
     190               0 :         insert_new_edges(currE, curr_y);
     191                 :     }
     192               0 : }
     193                 : 
     194                 : // return true if we're done with this edge
     195               0 : static bool update_edge(SkEdge* edge, int last_y) {
     196               0 :     SkASSERT(edge->fLastY >= last_y);
     197               0 :     if (last_y == edge->fLastY) {
     198               0 :         if (edge->fCurveCount < 0) {
     199               0 :             if (((SkCubicEdge*)edge)->updateCubic()) {
     200               0 :                 SkASSERT(edge->fFirstY == last_y + 1);
     201               0 :                 return false;
     202                 :             }
     203               0 :         } else if (edge->fCurveCount > 0) {
     204               0 :             if (((SkQuadraticEdge*)edge)->updateQuadratic()) {
     205               0 :                 SkASSERT(edge->fFirstY == last_y + 1);
     206               0 :                 return false;
     207                 :             }
     208                 :         }
     209               0 :         return true;
     210                 :     }
     211               0 :     return false;
     212                 : }
     213                 : 
     214               0 : static void walk_convex_edges(SkEdge* prevHead, SkPath::FillType,
     215                 :                               SkBlitter* blitter, int start_y, int stop_y,
     216                 :                               PrePostProc proc) {
     217                 :     static int gCalls;
     218               0 :     gCalls++;
     219                 :     
     220               0 :     validate_sort(prevHead->fNext);
     221                 :     
     222               0 :     SkEdge* leftE = prevHead->fNext;
     223               0 :     SkEdge* riteE = leftE->fNext;
     224               0 :     SkEdge* currE = riteE->fNext;
     225                 : 
     226                 : #if 0
     227                 :     int local_top = leftE->fFirstY;
     228                 :     SkASSERT(local_top == riteE->fFirstY);
     229                 : #else
     230                 :     // our edge choppers for curves can result in the initial edges
     231                 :     // not lining up, so we take the max.
     232               0 :     int local_top = SkMax32(leftE->fFirstY, riteE->fFirstY);
     233                 : #endif
     234               0 :     SkASSERT(local_top >= start_y);
     235                 :     
     236               0 :     int gLoops = 0;
     237               0 :     for (;;) {
     238               0 :         gLoops++;
     239                 : 
     240               0 :         SkASSERT(leftE->fFirstY <= stop_y);
     241               0 :         SkASSERT(riteE->fFirstY <= stop_y);
     242                 : 
     243               0 :         if (leftE->fX > riteE->fX || (leftE->fX == riteE->fX &&
     244                 :                                       leftE->fDX > riteE->fDX)) {
     245               0 :             SkTSwap(leftE, riteE);
     246                 :         }
     247                 :         
     248               0 :         int local_bot = SkMin32(leftE->fLastY, riteE->fLastY);
     249               0 :         local_bot = SkMin32(local_bot, stop_y - 1);
     250               0 :         SkASSERT(local_top <= local_bot);
     251                 :         
     252               0 :         SkFixed left = leftE->fX;
     253               0 :         SkFixed dLeft = leftE->fDX;
     254               0 :         SkFixed rite = riteE->fX;
     255               0 :         SkFixed dRite = riteE->fDX;
     256               0 :         int count = local_bot - local_top;
     257               0 :         SkASSERT(count >= 0);
     258               0 :         if (0 == (dLeft | dRite)) {
     259               0 :             int L = (left + SK_Fixed1/2) >> 16;
     260               0 :             int R = (rite + SK_Fixed1/2) >> 16;
     261               0 :             if (L < R) {
     262               0 :                 count += 1;
     263               0 :                 blitter->blitRect(L, local_top, R - L, count);
     264               0 :                 left += count * dLeft;
     265               0 :                 rite += count * dRite;
     266                 :             }
     267               0 :             local_top = local_bot + 1;
     268                 :         } else {
     269               0 :             do {
     270               0 :                 int L = (left + SK_Fixed1/2) >> 16;
     271               0 :                 int R = (rite + SK_Fixed1/2) >> 16;
     272               0 :                 if (L < R) {
     273               0 :                     blitter->blitH(L, local_top, R - L);
     274                 :                 }
     275               0 :                 left += dLeft;
     276               0 :                 rite += dRite;
     277               0 :                 local_top += 1;
     278                 :             } while (--count >= 0);
     279                 :         }
     280                 : 
     281               0 :         leftE->fX = left;
     282               0 :         riteE->fX = rite;
     283                 : 
     284               0 :         if (update_edge(leftE, local_bot)) {
     285               0 :             if (currE->fFirstY >= stop_y) {
     286               0 :                 break;
     287                 :             }
     288               0 :             leftE = currE;
     289               0 :             currE = currE->fNext;
     290                 :         }
     291               0 :         if (update_edge(riteE, local_bot)) {
     292               0 :             if (currE->fFirstY >= stop_y) {
     293               0 :                 break;
     294                 :             }
     295               0 :             riteE = currE;
     296               0 :             currE = currE->fNext;
     297                 :         }
     298                 :         
     299               0 :         SkASSERT(leftE);
     300               0 :         SkASSERT(riteE);
     301                 : 
     302                 :         // check our bottom clip
     303               0 :         SkASSERT(local_top == local_bot + 1);
     304               0 :         if (local_top >= stop_y) {
     305               0 :             break;
     306                 :         }
     307                 :     }
     308               0 : }
     309                 : 
     310                 : ///////////////////////////////////////////////////////////////////////////////
     311                 : 
     312                 : // this guy overrides blitH, and will call its proxy blitter with the inverse
     313                 : // of the spans it is given (clipped to the left/right of the cliprect)
     314                 : //
     315                 : // used to implement inverse filltypes on paths
     316                 : //
     317               0 : class InverseBlitter : public SkBlitter {
     318                 : public:
     319               0 :     void setBlitter(SkBlitter* blitter, const SkIRect& clip, int shift) {
     320               0 :         fBlitter = blitter;
     321               0 :         fFirstX = clip.fLeft << shift;
     322               0 :         fLastX = clip.fRight << shift;
     323               0 :     }
     324               0 :     void prepost(int y, bool isStart) {
     325               0 :         if (isStart) {
     326               0 :             fPrevX = fFirstX;
     327                 :         } else {
     328               0 :             int invWidth = fLastX - fPrevX;
     329               0 :             if (invWidth > 0) {
     330               0 :                 fBlitter->blitH(fPrevX, y, invWidth);
     331                 :             }
     332                 :         }
     333               0 :     }
     334                 : 
     335                 :     // overrides
     336               0 :     virtual void blitH(int x, int y, int width) {
     337               0 :         int invWidth = x - fPrevX;
     338               0 :         if (invWidth > 0) {
     339               0 :             fBlitter->blitH(fPrevX, y, invWidth);
     340                 :         }
     341               0 :         fPrevX = x + width;
     342               0 :     }
     343                 : 
     344                 :     // we do not expect to get called with these entrypoints
     345               0 :     virtual void blitAntiH(int, int, const SkAlpha[], const int16_t runs[]) {
     346               0 :         SkDEBUGFAIL("blitAntiH unexpected");
     347               0 :     }
     348               0 :     virtual void blitV(int x, int y, int height, SkAlpha alpha) {
     349               0 :         SkDEBUGFAIL("blitV unexpected");
     350               0 :     }
     351               0 :     virtual void blitRect(int x, int y, int width, int height) {
     352               0 :         SkDEBUGFAIL("blitRect unexpected");
     353               0 :     }
     354               0 :     virtual void blitMask(const SkMask&, const SkIRect& clip) {
     355               0 :         SkDEBUGFAIL("blitMask unexpected");
     356               0 :     }
     357               0 :     virtual const SkBitmap* justAnOpaqueColor(uint32_t* value) {
     358               0 :         SkDEBUGFAIL("justAnOpaqueColor unexpected");
     359               0 :         return NULL;
     360                 :     }
     361                 : 
     362                 : private:
     363                 :     SkBlitter*  fBlitter;
     364                 :     int         fFirstX, fLastX, fPrevX;
     365                 : };
     366                 : 
     367               0 : static void PrePostInverseBlitterProc(SkBlitter* blitter, int y, bool isStart) {
     368               0 :     ((InverseBlitter*)blitter)->prepost(y, isStart);
     369               0 : }
     370                 : 
     371                 : ///////////////////////////////////////////////////////////////////////////////
     372                 : 
     373                 : #if defined _WIN32 && _MSC_VER >= 1300
     374                 : #pragma warning ( pop )
     375                 : #endif
     376                 : 
     377                 : extern "C" {
     378               0 :     static int edge_compare(const void* a, const void* b) {
     379               0 :         const SkEdge* edgea = *(const SkEdge**)a;
     380               0 :         const SkEdge* edgeb = *(const SkEdge**)b;
     381                 : 
     382               0 :         int valuea = edgea->fFirstY;
     383               0 :         int valueb = edgeb->fFirstY;
     384                 : 
     385               0 :         if (valuea == valueb) {
     386               0 :             valuea = edgea->fX;
     387               0 :             valueb = edgeb->fX;
     388                 :         }
     389                 : 
     390                 :         // this overflows if valuea >>> valueb or vice-versa
     391                 :         //     return valuea - valueb;
     392                 :         // do perform the slower but safe compares
     393               0 :         return (valuea < valueb) ? -1 : (valuea > valueb);
     394                 :     }
     395                 : }
     396                 : 
     397               0 : static SkEdge* sort_edges(SkEdge* list[], int count, SkEdge** last) {
     398               0 :     qsort(list, count, sizeof(SkEdge*), edge_compare);
     399                 : 
     400                 :     // now make the edges linked in sorted order
     401               0 :     for (int i = 1; i < count; i++) {
     402               0 :         list[i - 1]->fNext = list[i];
     403               0 :         list[i]->fPrev = list[i - 1];
     404                 :     }
     405                 : 
     406               0 :     *last = list[count - 1];
     407               0 :     return list[0];
     408                 : }
     409                 : 
     410                 : // clipRect may be null, even though we always have a clip. This indicates that
     411                 : // the path is contained in the clip, and so we can ignore it during the blit
     412                 : //
     413                 : // clipRect (if no null) has already been shifted up
     414                 : //
     415               0 : void sk_fill_path(const SkPath& path, const SkIRect* clipRect, SkBlitter* blitter,
     416                 :                   int start_y, int stop_y, int shiftEdgesUp,
     417                 :                   const SkRegion& clipRgn) {
     418               0 :     SkASSERT(&path && blitter);
     419                 : 
     420               0 :     SkEdgeBuilder   builder;
     421                 : 
     422               0 :     int count = builder.build(path, clipRect, shiftEdgesUp);
     423               0 :     SkEdge**    list = builder.edgeList();
     424                 : 
     425               0 :     if (count < 2) {
     426               0 :         if (path.isInverseFillType()) {
     427               0 :             const SkIRect& clipRect = clipRgn.getBounds();
     428                 :             blitter->blitRect(clipRect.fLeft << shiftEdgesUp,
     429                 :                               clipRect.fTop << shiftEdgesUp,
     430               0 :                               clipRect.width() << shiftEdgesUp,
     431               0 :                               clipRect.height() << shiftEdgesUp);
     432                 :         }
     433                 : 
     434                 :         return;
     435                 :     }
     436                 : 
     437                 :     SkEdge headEdge, tailEdge, *last;
     438                 :     // this returns the first and last edge after they're sorted into a dlink list
     439               0 :     SkEdge* edge = sort_edges(list, count, &last);
     440                 : 
     441               0 :     headEdge.fPrev = NULL;
     442               0 :     headEdge.fNext = edge;
     443               0 :     headEdge.fFirstY = kEDGE_HEAD_Y;
     444               0 :     headEdge.fX = SK_MinS32;
     445               0 :     edge->fPrev = &headEdge;
     446                 : 
     447               0 :     tailEdge.fPrev = last;
     448               0 :     tailEdge.fNext = NULL;
     449               0 :     tailEdge.fFirstY = kEDGE_TAIL_Y;
     450               0 :     last->fNext = &tailEdge;
     451                 : 
     452                 :     // now edge is the head of the sorted linklist
     453                 : 
     454               0 :     start_y <<= shiftEdgesUp;
     455               0 :     stop_y <<= shiftEdgesUp;
     456               0 :     if (clipRect && start_y < clipRect->fTop) {
     457               0 :         start_y = clipRect->fTop;
     458                 :     }
     459               0 :     if (clipRect && stop_y > clipRect->fBottom) {
     460               0 :         stop_y = clipRect->fBottom;
     461                 :     }
     462                 : 
     463               0 :     InverseBlitter  ib;
     464               0 :     PrePostProc     proc = NULL;
     465                 : 
     466               0 :     if (path.isInverseFillType()) {
     467               0 :         ib.setBlitter(blitter, clipRgn.getBounds(), shiftEdgesUp);
     468               0 :         blitter = &ib;
     469               0 :         proc = PrePostInverseBlitterProc;
     470                 :     }
     471                 : 
     472               0 :     if (path.isConvex() && (NULL == proc)) {
     473               0 :         walk_convex_edges(&headEdge, path.getFillType(), blitter, start_y, stop_y, NULL);
     474                 :     } else {
     475               0 :         walk_edges(&headEdge, path.getFillType(), blitter, start_y, stop_y, proc);
     476                 :     }
     477                 : }
     478                 : 
     479               0 : void sk_blit_above(SkBlitter* blitter, const SkIRect& ir, const SkRegion& clip) {
     480               0 :     const SkIRect& cr = clip.getBounds();
     481                 :     SkIRect tmp;
     482                 : 
     483               0 :     tmp.fLeft = cr.fLeft;
     484               0 :     tmp.fRight = cr.fRight;
     485               0 :     tmp.fTop = cr.fTop;
     486               0 :     tmp.fBottom = ir.fTop;
     487               0 :     if (!tmp.isEmpty()) {
     488               0 :         blitter->blitRectRegion(tmp, clip);
     489                 :     }
     490               0 : }
     491                 : 
     492               0 : void sk_blit_below(SkBlitter* blitter, const SkIRect& ir, const SkRegion& clip) {
     493               0 :     const SkIRect& cr = clip.getBounds();
     494                 :     SkIRect tmp;
     495                 : 
     496               0 :     tmp.fLeft = cr.fLeft;
     497               0 :     tmp.fRight = cr.fRight;
     498               0 :     tmp.fTop = ir.fBottom;
     499               0 :     tmp.fBottom = cr.fBottom;
     500               0 :     if (!tmp.isEmpty()) {
     501               0 :         blitter->blitRectRegion(tmp, clip);
     502                 :     }
     503               0 : }
     504                 : 
     505                 : ///////////////////////////////////////////////////////////////////////////////
     506                 : 
     507               0 : SkScanClipper::SkScanClipper(SkBlitter* blitter, const SkRegion* clip,
     508               0 :                              const SkIRect& ir) {
     509               0 :     fBlitter = NULL;     // null means blit nothing
     510               0 :     fClipRect = NULL;
     511                 : 
     512               0 :     if (clip) {
     513               0 :         fClipRect = &clip->getBounds();
     514               0 :         if (!SkIRect::Intersects(*fClipRect, ir)) { // completely clipped out
     515               0 :             return;
     516                 :         }
     517                 : 
     518               0 :         if (clip->isRect()) {
     519               0 :             if (fClipRect->contains(ir)) {
     520               0 :                 fClipRect = NULL;
     521                 :             } else {
     522                 :                 // only need a wrapper blitter if we're horizontally clipped
     523               0 :                 if (fClipRect->fLeft > ir.fLeft || fClipRect->fRight < ir.fRight) {
     524               0 :                     fRectBlitter.init(blitter, *fClipRect);
     525               0 :                     blitter = &fRectBlitter;
     526                 :                 }
     527                 :             }
     528                 :         } else {
     529               0 :             fRgnBlitter.init(blitter, clip);
     530               0 :             blitter = &fRgnBlitter;
     531                 :         }
     532                 :     }
     533               0 :     fBlitter = blitter;
     534                 : }
     535                 : 
     536                 : ///////////////////////////////////////////////////////////////////////////////
     537                 : 
     538               0 : static bool clip_to_limit(const SkRegion& orig, SkRegion* reduced) {
     539               0 :     const int32_t limit = 32767;
     540                 : 
     541                 :     SkIRect limitR;
     542               0 :     limitR.set(-limit, -limit, limit, limit);
     543               0 :     if (limitR.contains(orig.getBounds())) {
     544               0 :         return false;
     545                 :     }
     546               0 :     reduced->op(orig, limitR, SkRegion::kIntersect_Op);
     547               0 :     return true;
     548                 : }
     549                 : 
     550               0 : void SkScan::FillPath(const SkPath& path, const SkRegion& origClip,
     551                 :                       SkBlitter* blitter) {
     552               0 :     if (origClip.isEmpty()) {
     553               0 :         return;
     554                 :     }
     555                 : 
     556                 :     // Our edges are fixed-point, and don't like the bounds of the clip to
     557                 :     // exceed that. Here we trim the clip just so we don't overflow later on
     558               0 :     const SkRegion* clipPtr = &origClip;
     559               0 :     SkRegion finiteClip;
     560               0 :     if (clip_to_limit(origClip, &finiteClip)) {
     561               0 :         if (finiteClip.isEmpty()) {
     562                 :             return;
     563                 :         }
     564               0 :         clipPtr = &finiteClip;
     565                 :     }
     566                 :         // don't reference "origClip" any more, just use clipPtr
     567                 : 
     568                 :     SkIRect ir;
     569               0 :     path.getBounds().round(&ir);
     570               0 :     if (ir.isEmpty()) {
     571               0 :         if (path.isInverseFillType()) {
     572               0 :             blitter->blitRegion(*clipPtr);
     573                 :         }
     574                 :         return;
     575                 :     }
     576                 : 
     577               0 :     SkScanClipper   clipper(blitter, clipPtr, ir);
     578                 : 
     579               0 :     blitter = clipper.getBlitter();
     580               0 :     if (blitter) {
     581                 :         // we have to keep our calls to blitter in sorted order, so we
     582                 :         // must blit the above section first, then the middle, then the bottom.
     583               0 :         if (path.isInverseFillType()) {
     584               0 :             sk_blit_above(blitter, ir, *clipPtr);
     585                 :         }
     586                 :         sk_fill_path(path, clipper.getClipRect(), blitter, ir.fTop, ir.fBottom,
     587               0 :                      0, *clipPtr);
     588               0 :         if (path.isInverseFillType()) {
     589               0 :             sk_blit_below(blitter, ir, *clipPtr);
     590                 :         }
     591                 :     } else {
     592                 :         // what does it mean to not have a blitter if path.isInverseFillType???
     593                 :     }
     594                 : }
     595                 : 
     596               0 : void SkScan::FillPath(const SkPath& path, const SkIRect& ir,
     597                 :                       SkBlitter* blitter) {
     598               0 :     SkRegion rgn(ir);
     599               0 :     FillPath(path, rgn, blitter);
     600               0 : }
     601                 : 
     602                 : ///////////////////////////////////////////////////////////////////////////////
     603                 : 
     604               0 : static int build_tri_edges(SkEdge edge[], const SkPoint pts[],
     605                 :                            const SkIRect* clipRect, SkEdge* list[]) {
     606               0 :     SkEdge** start = list;
     607                 : 
     608               0 :     if (edge->setLine(pts[0], pts[1], clipRect, 0)) {
     609               0 :         *list++ = edge;
     610               0 :         edge = (SkEdge*)((char*)edge + sizeof(SkEdge));
     611                 :     }
     612               0 :     if (edge->setLine(pts[1], pts[2], clipRect, 0)) {
     613               0 :         *list++ = edge;
     614               0 :         edge = (SkEdge*)((char*)edge + sizeof(SkEdge));
     615                 :     }
     616               0 :     if (edge->setLine(pts[2], pts[0], clipRect, 0)) {
     617               0 :         *list++ = edge;
     618                 :     }
     619               0 :     return (int)(list - start);
     620                 : }
     621                 : 
     622                 : 
     623               0 : static void sk_fill_triangle(const SkPoint pts[], const SkIRect* clipRect,
     624                 :                              SkBlitter* blitter, const SkIRect& ir) {
     625               0 :     SkASSERT(pts && blitter);
     626                 : 
     627                 :     SkEdge edgeStorage[3];
     628                 :     SkEdge* list[3];
     629                 : 
     630               0 :     int count = build_tri_edges(edgeStorage, pts, clipRect, list);
     631               0 :     if (count < 2) {
     632               0 :         return;
     633                 :     }
     634                 : 
     635                 :     SkEdge headEdge, tailEdge, *last;
     636                 : 
     637                 :     // this returns the first and last edge after they're sorted into a dlink list
     638               0 :     SkEdge* edge = sort_edges(list, count, &last);
     639                 : 
     640               0 :     headEdge.fPrev = NULL;
     641               0 :     headEdge.fNext = edge;
     642               0 :     headEdge.fFirstY = kEDGE_HEAD_Y;
     643               0 :     headEdge.fX = SK_MinS32;
     644               0 :     edge->fPrev = &headEdge;
     645                 : 
     646               0 :     tailEdge.fPrev = last;
     647               0 :     tailEdge.fNext = NULL;
     648               0 :     tailEdge.fFirstY = kEDGE_TAIL_Y;
     649               0 :     last->fNext = &tailEdge;
     650                 : 
     651                 :     // now edge is the head of the sorted linklist
     652               0 :     int stop_y = ir.fBottom;
     653               0 :     if (clipRect && stop_y > clipRect->fBottom) {
     654               0 :         stop_y = clipRect->fBottom;
     655                 :     }
     656               0 :     int start_y = ir.fTop;
     657               0 :     if (clipRect && start_y < clipRect->fTop) {
     658               0 :         start_y = clipRect->fTop;
     659                 :     }
     660               0 :     walk_convex_edges(&headEdge, SkPath::kEvenOdd_FillType, blitter, start_y, stop_y, NULL);
     661                 : //    walk_edges(&headEdge, SkPath::kEvenOdd_FillType, blitter, start_y, stop_y, NULL);
     662                 : }
     663                 : 
     664               0 : void SkScan::FillTriangle(const SkPoint pts[], const SkRasterClip& clip,
     665                 :                           SkBlitter* blitter) {
     666               0 :     if (clip.isEmpty()) {
     667               0 :         return;
     668                 :     }
     669                 : 
     670                 :     SkRect  r;
     671                 :     SkIRect ir;
     672               0 :     r.set(pts, 3);
     673               0 :     r.round(&ir);
     674               0 :     if (ir.isEmpty() || !SkIRect::Intersects(ir, clip.getBounds())) {
     675               0 :         return;
     676                 :     }
     677                 : 
     678               0 :     SkAAClipBlitterWrapper wrap;
     679                 :     const SkRegion* clipRgn;
     680               0 :     if (clip.isBW()) {
     681               0 :         clipRgn = &clip.bwRgn();
     682                 :     } else {
     683               0 :         wrap.init(clip, blitter);
     684               0 :         clipRgn = &wrap.getRgn();
     685               0 :         blitter = wrap.getBlitter();
     686                 :     }
     687                 : 
     688               0 :     SkScanClipper clipper(blitter, clipRgn, ir);
     689               0 :     blitter = clipper.getBlitter();
     690               0 :     if (NULL != blitter) {
     691               0 :         sk_fill_triangle(pts, clipper.getClipRect(), blitter, ir);
     692                 :     }
     693                 : }
     694                 : 

Generated by: LCOV version 1.7