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