gfx/skia/trunk/src/core/SkEdgeClipper.cpp

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

michael@0 1
michael@0 2 /*
michael@0 3 * Copyright 2009 The Android Open Source Project
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8
michael@0 9
michael@0 10 #include "SkEdgeClipper.h"
michael@0 11 #include "SkGeometry.h"
michael@0 12
michael@0 13 static bool quick_reject(const SkRect& bounds, const SkRect& clip) {
michael@0 14 return bounds.fTop >= clip.fBottom || bounds.fBottom <= clip.fTop;
michael@0 15 }
michael@0 16
michael@0 17 static inline void clamp_le(SkScalar& value, SkScalar max) {
michael@0 18 if (value > max) {
michael@0 19 value = max;
michael@0 20 }
michael@0 21 }
michael@0 22
michael@0 23 static inline void clamp_ge(SkScalar& value, SkScalar min) {
michael@0 24 if (value < min) {
michael@0 25 value = min;
michael@0 26 }
michael@0 27 }
michael@0 28
michael@0 29 /* src[] must be monotonic in Y. This routine copies src into dst, and sorts
michael@0 30 it to be increasing in Y. If it had to reverse the order of the points,
michael@0 31 it returns true, otherwise it returns false
michael@0 32 */
michael@0 33 static bool sort_increasing_Y(SkPoint dst[], const SkPoint src[], int count) {
michael@0 34 // we need the data to be monotonically increasing in Y
michael@0 35 if (src[0].fY > src[count - 1].fY) {
michael@0 36 for (int i = 0; i < count; i++) {
michael@0 37 dst[i] = src[count - i - 1];
michael@0 38 }
michael@0 39 return true;
michael@0 40 } else {
michael@0 41 memcpy(dst, src, count * sizeof(SkPoint));
michael@0 42 return false;
michael@0 43 }
michael@0 44 }
michael@0 45
michael@0 46 ///////////////////////////////////////////////////////////////////////////////
michael@0 47
michael@0 48 static bool chopMonoQuadAt(SkScalar c0, SkScalar c1, SkScalar c2,
michael@0 49 SkScalar target, SkScalar* t) {
michael@0 50 /* Solve F(t) = y where F(t) := [0](1-t)^2 + 2[1]t(1-t) + [2]t^2
michael@0 51 * We solve for t, using quadratic equation, hence we have to rearrange
michael@0 52 * our cooefficents to look like At^2 + Bt + C
michael@0 53 */
michael@0 54 SkScalar A = c0 - c1 - c1 + c2;
michael@0 55 SkScalar B = 2*(c1 - c0);
michael@0 56 SkScalar C = c0 - target;
michael@0 57
michael@0 58 SkScalar roots[2]; // we only expect one, but make room for 2 for safety
michael@0 59 int count = SkFindUnitQuadRoots(A, B, C, roots);
michael@0 60 if (count) {
michael@0 61 *t = roots[0];
michael@0 62 return true;
michael@0 63 }
michael@0 64 return false;
michael@0 65 }
michael@0 66
michael@0 67 static bool chopMonoQuadAtY(SkPoint pts[3], SkScalar y, SkScalar* t) {
michael@0 68 return chopMonoQuadAt(pts[0].fY, pts[1].fY, pts[2].fY, y, t);
michael@0 69 }
michael@0 70
michael@0 71 static bool chopMonoQuadAtX(SkPoint pts[3], SkScalar x, SkScalar* t) {
michael@0 72 return chopMonoQuadAt(pts[0].fX, pts[1].fX, pts[2].fX, x, t);
michael@0 73 }
michael@0 74
michael@0 75 // Modify pts[] in place so that it is clipped in Y to the clip rect
michael@0 76 static void chop_quad_in_Y(SkPoint pts[3], const SkRect& clip) {
michael@0 77 SkScalar t;
michael@0 78 SkPoint tmp[5]; // for SkChopQuadAt
michael@0 79
michael@0 80 // are we partially above
michael@0 81 if (pts[0].fY < clip.fTop) {
michael@0 82 if (chopMonoQuadAtY(pts, clip.fTop, &t)) {
michael@0 83 // take the 2nd chopped quad
michael@0 84 SkChopQuadAt(pts, tmp, t);
michael@0 85 // clamp to clean up imprecise numerics in the chop
michael@0 86 tmp[2].fY = clip.fTop;
michael@0 87 clamp_ge(tmp[3].fY, clip.fTop);
michael@0 88
michael@0 89 pts[0] = tmp[2];
michael@0 90 pts[1] = tmp[3];
michael@0 91 } else {
michael@0 92 // if chopMonoQuadAtY failed, then we may have hit inexact numerics
michael@0 93 // so we just clamp against the top
michael@0 94 for (int i = 0; i < 3; i++) {
michael@0 95 if (pts[i].fY < clip.fTop) {
michael@0 96 pts[i].fY = clip.fTop;
michael@0 97 }
michael@0 98 }
michael@0 99 }
michael@0 100 }
michael@0 101
michael@0 102 // are we partially below
michael@0 103 if (pts[2].fY > clip.fBottom) {
michael@0 104 if (chopMonoQuadAtY(pts, clip.fBottom, &t)) {
michael@0 105 SkChopQuadAt(pts, tmp, t);
michael@0 106 // clamp to clean up imprecise numerics in the chop
michael@0 107 clamp_le(tmp[1].fY, clip.fBottom);
michael@0 108 tmp[2].fY = clip.fBottom;
michael@0 109
michael@0 110 pts[1] = tmp[1];
michael@0 111 pts[2] = tmp[2];
michael@0 112 } else {
michael@0 113 // if chopMonoQuadAtY failed, then we may have hit inexact numerics
michael@0 114 // so we just clamp against the bottom
michael@0 115 for (int i = 0; i < 3; i++) {
michael@0 116 if (pts[i].fY > clip.fBottom) {
michael@0 117 pts[i].fY = clip.fBottom;
michael@0 118 }
michael@0 119 }
michael@0 120 }
michael@0 121 }
michael@0 122 }
michael@0 123
michael@0 124 // srcPts[] must be monotonic in X and Y
michael@0 125 void SkEdgeClipper::clipMonoQuad(const SkPoint srcPts[3], const SkRect& clip) {
michael@0 126 SkPoint pts[3];
michael@0 127 bool reverse = sort_increasing_Y(pts, srcPts, 3);
michael@0 128
michael@0 129 // are we completely above or below
michael@0 130 if (pts[2].fY <= clip.fTop || pts[0].fY >= clip.fBottom) {
michael@0 131 return;
michael@0 132 }
michael@0 133
michael@0 134 // Now chop so that pts is contained within clip in Y
michael@0 135 chop_quad_in_Y(pts, clip);
michael@0 136
michael@0 137 if (pts[0].fX > pts[2].fX) {
michael@0 138 SkTSwap<SkPoint>(pts[0], pts[2]);
michael@0 139 reverse = !reverse;
michael@0 140 }
michael@0 141 SkASSERT(pts[0].fX <= pts[1].fX);
michael@0 142 SkASSERT(pts[1].fX <= pts[2].fX);
michael@0 143
michael@0 144 // Now chop in X has needed, and record the segments
michael@0 145
michael@0 146 if (pts[2].fX <= clip.fLeft) { // wholly to the left
michael@0 147 this->appendVLine(clip.fLeft, pts[0].fY, pts[2].fY, reverse);
michael@0 148 return;
michael@0 149 }
michael@0 150 if (pts[0].fX >= clip.fRight) { // wholly to the right
michael@0 151 this->appendVLine(clip.fRight, pts[0].fY, pts[2].fY, reverse);
michael@0 152 return;
michael@0 153 }
michael@0 154
michael@0 155 SkScalar t;
michael@0 156 SkPoint tmp[5]; // for SkChopQuadAt
michael@0 157
michael@0 158 // are we partially to the left
michael@0 159 if (pts[0].fX < clip.fLeft) {
michael@0 160 if (chopMonoQuadAtX(pts, clip.fLeft, &t)) {
michael@0 161 SkChopQuadAt(pts, tmp, t);
michael@0 162 this->appendVLine(clip.fLeft, tmp[0].fY, tmp[2].fY, reverse);
michael@0 163 // clamp to clean up imprecise numerics in the chop
michael@0 164 tmp[2].fX = clip.fLeft;
michael@0 165 clamp_ge(tmp[3].fX, clip.fLeft);
michael@0 166
michael@0 167 pts[0] = tmp[2];
michael@0 168 pts[1] = tmp[3];
michael@0 169 } else {
michael@0 170 // if chopMonoQuadAtY failed, then we may have hit inexact numerics
michael@0 171 // so we just clamp against the left
michael@0 172 this->appendVLine(clip.fLeft, pts[0].fY, pts[2].fY, reverse);
michael@0 173 return;
michael@0 174 }
michael@0 175 }
michael@0 176
michael@0 177 // are we partially to the right
michael@0 178 if (pts[2].fX > clip.fRight) {
michael@0 179 if (chopMonoQuadAtX(pts, clip.fRight, &t)) {
michael@0 180 SkChopQuadAt(pts, tmp, t);
michael@0 181 // clamp to clean up imprecise numerics in the chop
michael@0 182 clamp_le(tmp[1].fX, clip.fRight);
michael@0 183 tmp[2].fX = clip.fRight;
michael@0 184
michael@0 185 this->appendQuad(tmp, reverse);
michael@0 186 this->appendVLine(clip.fRight, tmp[2].fY, tmp[4].fY, reverse);
michael@0 187 } else {
michael@0 188 // if chopMonoQuadAtY failed, then we may have hit inexact numerics
michael@0 189 // so we just clamp against the right
michael@0 190 this->appendVLine(clip.fRight, pts[0].fY, pts[2].fY, reverse);
michael@0 191 }
michael@0 192 } else { // wholly inside the clip
michael@0 193 this->appendQuad(pts, reverse);
michael@0 194 }
michael@0 195 }
michael@0 196
michael@0 197 bool SkEdgeClipper::clipQuad(const SkPoint srcPts[3], const SkRect& clip) {
michael@0 198 fCurrPoint = fPoints;
michael@0 199 fCurrVerb = fVerbs;
michael@0 200
michael@0 201 SkRect bounds;
michael@0 202 bounds.set(srcPts, 3);
michael@0 203
michael@0 204 if (!quick_reject(bounds, clip)) {
michael@0 205 SkPoint monoY[5];
michael@0 206 int countY = SkChopQuadAtYExtrema(srcPts, monoY);
michael@0 207 for (int y = 0; y <= countY; y++) {
michael@0 208 SkPoint monoX[5];
michael@0 209 int countX = SkChopQuadAtXExtrema(&monoY[y * 2], monoX);
michael@0 210 for (int x = 0; x <= countX; x++) {
michael@0 211 this->clipMonoQuad(&monoX[x * 2], clip);
michael@0 212 SkASSERT(fCurrVerb - fVerbs < kMaxVerbs);
michael@0 213 SkASSERT(fCurrPoint - fPoints <= kMaxPoints);
michael@0 214 }
michael@0 215 }
michael@0 216 }
michael@0 217
michael@0 218 *fCurrVerb = SkPath::kDone_Verb;
michael@0 219 fCurrPoint = fPoints;
michael@0 220 fCurrVerb = fVerbs;
michael@0 221 return SkPath::kDone_Verb != fVerbs[0];
michael@0 222 }
michael@0 223
michael@0 224 ///////////////////////////////////////////////////////////////////////////////
michael@0 225
michael@0 226 static SkScalar eval_cubic_coeff(SkScalar A, SkScalar B, SkScalar C,
michael@0 227 SkScalar D, SkScalar t) {
michael@0 228 return SkScalarMulAdd(SkScalarMulAdd(SkScalarMulAdd(A, t, B), t, C), t, D);
michael@0 229 }
michael@0 230
michael@0 231 /* Given 4 cubic points (either Xs or Ys), and a target X or Y, compute the
michael@0 232 t value such that cubic(t) = target
michael@0 233 */
michael@0 234 static bool chopMonoCubicAt(SkScalar c0, SkScalar c1, SkScalar c2, SkScalar c3,
michael@0 235 SkScalar target, SkScalar* t) {
michael@0 236 // SkASSERT(c0 <= c1 && c1 <= c2 && c2 <= c3);
michael@0 237 SkASSERT(c0 < target && target < c3);
michael@0 238
michael@0 239 SkScalar D = c0 - target;
michael@0 240 SkScalar A = c3 + 3*(c1 - c2) - c0;
michael@0 241 SkScalar B = 3*(c2 - c1 - c1 + c0);
michael@0 242 SkScalar C = 3*(c1 - c0);
michael@0 243
michael@0 244 const SkScalar TOLERANCE = SK_Scalar1 / 4096;
michael@0 245 SkScalar minT = 0;
michael@0 246 SkScalar maxT = SK_Scalar1;
michael@0 247 SkScalar mid;
michael@0 248
michael@0 249 // This is a lot of iterations. Is there a faster way?
michael@0 250 for (int i = 0; i < 24; i++) {
michael@0 251 mid = SkScalarAve(minT, maxT);
michael@0 252 SkScalar delta = eval_cubic_coeff(A, B, C, D, mid);
michael@0 253 if (delta < 0) {
michael@0 254 minT = mid;
michael@0 255 delta = -delta;
michael@0 256 } else {
michael@0 257 maxT = mid;
michael@0 258 }
michael@0 259 if (delta < TOLERANCE) {
michael@0 260 break;
michael@0 261 }
michael@0 262 }
michael@0 263 *t = mid;
michael@0 264 // SkDebugf("-- evalCubicAt %d delta %g\n", i, eval_cubic_coeff(A, B, C, D, *t));
michael@0 265 return true;
michael@0 266 }
michael@0 267
michael@0 268 static bool chopMonoCubicAtY(SkPoint pts[4], SkScalar y, SkScalar* t) {
michael@0 269 return chopMonoCubicAt(pts[0].fY, pts[1].fY, pts[2].fY, pts[3].fY, y, t);
michael@0 270 }
michael@0 271
michael@0 272 static bool chopMonoCubicAtX(SkPoint pts[4], SkScalar x, SkScalar* t) {
michael@0 273 return chopMonoCubicAt(pts[0].fX, pts[1].fX, pts[2].fX, pts[3].fX, x, t);
michael@0 274 }
michael@0 275
michael@0 276 // Modify pts[] in place so that it is clipped in Y to the clip rect
michael@0 277 static void chop_cubic_in_Y(SkPoint pts[4], const SkRect& clip) {
michael@0 278
michael@0 279 // are we partially above
michael@0 280 if (pts[0].fY < clip.fTop) {
michael@0 281 SkScalar t;
michael@0 282 if (chopMonoCubicAtY(pts, clip.fTop, &t)) {
michael@0 283 SkPoint tmp[7];
michael@0 284 SkChopCubicAt(pts, tmp, t);
michael@0 285
michael@0 286 // tmp[3, 4, 5].fY should all be to the below clip.fTop.
michael@0 287 // Since we can't trust the numerics of
michael@0 288 // the chopper, we force those conditions now
michael@0 289 tmp[3].fY = clip.fTop;
michael@0 290 clamp_ge(tmp[4].fY, clip.fTop);
michael@0 291 clamp_ge(tmp[5].fY, clip.fTop);
michael@0 292
michael@0 293 pts[0] = tmp[3];
michael@0 294 pts[1] = tmp[4];
michael@0 295 pts[2] = tmp[5];
michael@0 296 } else {
michael@0 297 // if chopMonoCubicAtY failed, then we may have hit inexact numerics
michael@0 298 // so we just clamp against the top
michael@0 299 for (int i = 0; i < 4; i++) {
michael@0 300 clamp_ge(pts[i].fY, clip.fTop);
michael@0 301 }
michael@0 302 }
michael@0 303 }
michael@0 304
michael@0 305 // are we partially below
michael@0 306 if (pts[3].fY > clip.fBottom) {
michael@0 307 SkScalar t;
michael@0 308 if (chopMonoCubicAtY(pts, clip.fBottom, &t)) {
michael@0 309 SkPoint tmp[7];
michael@0 310 SkChopCubicAt(pts, tmp, t);
michael@0 311 tmp[3].fY = clip.fBottom;
michael@0 312 clamp_le(tmp[2].fY, clip.fBottom);
michael@0 313
michael@0 314 pts[1] = tmp[1];
michael@0 315 pts[2] = tmp[2];
michael@0 316 pts[3] = tmp[3];
michael@0 317 } else {
michael@0 318 // if chopMonoCubicAtY failed, then we may have hit inexact numerics
michael@0 319 // so we just clamp against the bottom
michael@0 320 for (int i = 0; i < 4; i++) {
michael@0 321 clamp_le(pts[i].fY, clip.fBottom);
michael@0 322 }
michael@0 323 }
michael@0 324 }
michael@0 325 }
michael@0 326
michael@0 327 // srcPts[] must be monotonic in X and Y
michael@0 328 void SkEdgeClipper::clipMonoCubic(const SkPoint src[4], const SkRect& clip) {
michael@0 329 SkPoint pts[4];
michael@0 330 bool reverse = sort_increasing_Y(pts, src, 4);
michael@0 331
michael@0 332 // are we completely above or below
michael@0 333 if (pts[3].fY <= clip.fTop || pts[0].fY >= clip.fBottom) {
michael@0 334 return;
michael@0 335 }
michael@0 336
michael@0 337 // Now chop so that pts is contained within clip in Y
michael@0 338 chop_cubic_in_Y(pts, clip);
michael@0 339
michael@0 340 if (pts[0].fX > pts[3].fX) {
michael@0 341 SkTSwap<SkPoint>(pts[0], pts[3]);
michael@0 342 SkTSwap<SkPoint>(pts[1], pts[2]);
michael@0 343 reverse = !reverse;
michael@0 344 }
michael@0 345
michael@0 346 // Now chop in X has needed, and record the segments
michael@0 347
michael@0 348 if (pts[3].fX <= clip.fLeft) { // wholly to the left
michael@0 349 this->appendVLine(clip.fLeft, pts[0].fY, pts[3].fY, reverse);
michael@0 350 return;
michael@0 351 }
michael@0 352 if (pts[0].fX >= clip.fRight) { // wholly to the right
michael@0 353 this->appendVLine(clip.fRight, pts[0].fY, pts[3].fY, reverse);
michael@0 354 return;
michael@0 355 }
michael@0 356
michael@0 357 // are we partially to the left
michael@0 358 if (pts[0].fX < clip.fLeft) {
michael@0 359 SkScalar t;
michael@0 360 if (chopMonoCubicAtX(pts, clip.fLeft, &t)) {
michael@0 361 SkPoint tmp[7];
michael@0 362 SkChopCubicAt(pts, tmp, t);
michael@0 363 this->appendVLine(clip.fLeft, tmp[0].fY, tmp[3].fY, reverse);
michael@0 364
michael@0 365 // tmp[3, 4, 5].fX should all be to the right of clip.fLeft.
michael@0 366 // Since we can't trust the numerics of
michael@0 367 // the chopper, we force those conditions now
michael@0 368 tmp[3].fX = clip.fLeft;
michael@0 369 clamp_ge(tmp[4].fX, clip.fLeft);
michael@0 370 clamp_ge(tmp[5].fX, clip.fLeft);
michael@0 371
michael@0 372 pts[0] = tmp[3];
michael@0 373 pts[1] = tmp[4];
michael@0 374 pts[2] = tmp[5];
michael@0 375 } else {
michael@0 376 // if chopMonocubicAtY failed, then we may have hit inexact numerics
michael@0 377 // so we just clamp against the left
michael@0 378 this->appendVLine(clip.fLeft, pts[0].fY, pts[3].fY, reverse);
michael@0 379 return;
michael@0 380 }
michael@0 381 }
michael@0 382
michael@0 383 // are we partially to the right
michael@0 384 if (pts[3].fX > clip.fRight) {
michael@0 385 SkScalar t;
michael@0 386 if (chopMonoCubicAtX(pts, clip.fRight, &t)) {
michael@0 387 SkPoint tmp[7];
michael@0 388 SkChopCubicAt(pts, tmp, t);
michael@0 389 tmp[3].fX = clip.fRight;
michael@0 390 clamp_le(tmp[2].fX, clip.fRight);
michael@0 391 clamp_le(tmp[1].fX, clip.fRight);
michael@0 392
michael@0 393 this->appendCubic(tmp, reverse);
michael@0 394 this->appendVLine(clip.fRight, tmp[3].fY, tmp[6].fY, reverse);
michael@0 395 } else {
michael@0 396 // if chopMonoCubicAtX failed, then we may have hit inexact numerics
michael@0 397 // so we just clamp against the right
michael@0 398 this->appendVLine(clip.fRight, pts[0].fY, pts[3].fY, reverse);
michael@0 399 }
michael@0 400 } else { // wholly inside the clip
michael@0 401 this->appendCubic(pts, reverse);
michael@0 402 }
michael@0 403 }
michael@0 404
michael@0 405 bool SkEdgeClipper::clipCubic(const SkPoint srcPts[4], const SkRect& clip) {
michael@0 406 fCurrPoint = fPoints;
michael@0 407 fCurrVerb = fVerbs;
michael@0 408
michael@0 409 SkRect bounds;
michael@0 410 bounds.set(srcPts, 4);
michael@0 411
michael@0 412 if (!quick_reject(bounds, clip)) {
michael@0 413 SkPoint monoY[10];
michael@0 414 int countY = SkChopCubicAtYExtrema(srcPts, monoY);
michael@0 415 for (int y = 0; y <= countY; y++) {
michael@0 416 SkPoint monoX[10];
michael@0 417 int countX = SkChopCubicAtXExtrema(&monoY[y * 3], monoX);
michael@0 418 for (int x = 0; x <= countX; x++) {
michael@0 419 this->clipMonoCubic(&monoX[x * 3], clip);
michael@0 420 SkASSERT(fCurrVerb - fVerbs < kMaxVerbs);
michael@0 421 SkASSERT(fCurrPoint - fPoints <= kMaxPoints);
michael@0 422 }
michael@0 423 }
michael@0 424 }
michael@0 425
michael@0 426 *fCurrVerb = SkPath::kDone_Verb;
michael@0 427 fCurrPoint = fPoints;
michael@0 428 fCurrVerb = fVerbs;
michael@0 429 return SkPath::kDone_Verb != fVerbs[0];
michael@0 430 }
michael@0 431
michael@0 432 ///////////////////////////////////////////////////////////////////////////////
michael@0 433
michael@0 434 void SkEdgeClipper::appendVLine(SkScalar x, SkScalar y0, SkScalar y1,
michael@0 435 bool reverse) {
michael@0 436 *fCurrVerb++ = SkPath::kLine_Verb;
michael@0 437
michael@0 438 if (reverse) {
michael@0 439 SkTSwap<SkScalar>(y0, y1);
michael@0 440 }
michael@0 441 fCurrPoint[0].set(x, y0);
michael@0 442 fCurrPoint[1].set(x, y1);
michael@0 443 fCurrPoint += 2;
michael@0 444 }
michael@0 445
michael@0 446 void SkEdgeClipper::appendQuad(const SkPoint pts[3], bool reverse) {
michael@0 447 *fCurrVerb++ = SkPath::kQuad_Verb;
michael@0 448
michael@0 449 if (reverse) {
michael@0 450 fCurrPoint[0] = pts[2];
michael@0 451 fCurrPoint[2] = pts[0];
michael@0 452 } else {
michael@0 453 fCurrPoint[0] = pts[0];
michael@0 454 fCurrPoint[2] = pts[2];
michael@0 455 }
michael@0 456 fCurrPoint[1] = pts[1];
michael@0 457 fCurrPoint += 3;
michael@0 458 }
michael@0 459
michael@0 460 void SkEdgeClipper::appendCubic(const SkPoint pts[4], bool reverse) {
michael@0 461 *fCurrVerb++ = SkPath::kCubic_Verb;
michael@0 462
michael@0 463 if (reverse) {
michael@0 464 for (int i = 0; i < 4; i++) {
michael@0 465 fCurrPoint[i] = pts[3 - i];
michael@0 466 }
michael@0 467 } else {
michael@0 468 memcpy(fCurrPoint, pts, 4 * sizeof(SkPoint));
michael@0 469 }
michael@0 470 fCurrPoint += 4;
michael@0 471 }
michael@0 472
michael@0 473 SkPath::Verb SkEdgeClipper::next(SkPoint pts[]) {
michael@0 474 SkPath::Verb verb = *fCurrVerb;
michael@0 475
michael@0 476 switch (verb) {
michael@0 477 case SkPath::kLine_Verb:
michael@0 478 memcpy(pts, fCurrPoint, 2 * sizeof(SkPoint));
michael@0 479 fCurrPoint += 2;
michael@0 480 fCurrVerb += 1;
michael@0 481 break;
michael@0 482 case SkPath::kQuad_Verb:
michael@0 483 memcpy(pts, fCurrPoint, 3 * sizeof(SkPoint));
michael@0 484 fCurrPoint += 3;
michael@0 485 fCurrVerb += 1;
michael@0 486 break;
michael@0 487 case SkPath::kCubic_Verb:
michael@0 488 memcpy(pts, fCurrPoint, 4 * sizeof(SkPoint));
michael@0 489 fCurrPoint += 4;
michael@0 490 fCurrVerb += 1;
michael@0 491 break;
michael@0 492 case SkPath::kDone_Verb:
michael@0 493 break;
michael@0 494 default:
michael@0 495 SkDEBUGFAIL("unexpected verb in quadclippper2 iter");
michael@0 496 break;
michael@0 497 }
michael@0 498 return verb;
michael@0 499 }
michael@0 500
michael@0 501 ///////////////////////////////////////////////////////////////////////////////
michael@0 502
michael@0 503 #ifdef SK_DEBUG
michael@0 504 static void assert_monotonic(const SkScalar coord[], int count) {
michael@0 505 if (coord[0] > coord[(count - 1) * 2]) {
michael@0 506 for (int i = 1; i < count; i++) {
michael@0 507 SkASSERT(coord[2 * (i - 1)] >= coord[i * 2]);
michael@0 508 }
michael@0 509 } else if (coord[0] < coord[(count - 1) * 2]) {
michael@0 510 for (int i = 1; i < count; i++) {
michael@0 511 SkASSERT(coord[2 * (i - 1)] <= coord[i * 2]);
michael@0 512 }
michael@0 513 } else {
michael@0 514 for (int i = 1; i < count; i++) {
michael@0 515 SkASSERT(coord[2 * (i - 1)] == coord[i * 2]);
michael@0 516 }
michael@0 517 }
michael@0 518 }
michael@0 519
michael@0 520 void sk_assert_monotonic_y(const SkPoint pts[], int count) {
michael@0 521 if (count > 1) {
michael@0 522 assert_monotonic(&pts[0].fY, count);
michael@0 523 }
michael@0 524 }
michael@0 525
michael@0 526 void sk_assert_monotonic_x(const SkPoint pts[], int count) {
michael@0 527 if (count > 1) {
michael@0 528 assert_monotonic(&pts[0].fX, count);
michael@0 529 }
michael@0 530 }
michael@0 531 #endif

mercurial