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