OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkGeometry.h" | 8 #include "SkGeometry.h" |
9 #include "SkMatrix.h" | 9 #include "SkMatrix.h" |
10 | 10 |
(...skipping 1420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1431 | 1431 |
1432 void SkConic::computeAsQuadError(SkVector* err) const { | 1432 void SkConic::computeAsQuadError(SkVector* err) const { |
1433 AS_QUAD_ERROR_SETUP | 1433 AS_QUAD_ERROR_SETUP |
1434 err->set(x, y); | 1434 err->set(x, y); |
1435 } | 1435 } |
1436 | 1436 |
1437 bool SkConic::asQuadTol(SkScalar tol) const { | 1437 bool SkConic::asQuadTol(SkScalar tol) const { |
1438 AS_QUAD_ERROR_SETUP | 1438 AS_QUAD_ERROR_SETUP |
1439 return (x * x + y * y) <= tol * tol; | 1439 return (x * x + y * y) <= tol * tol; |
1440 } | 1440 } |
1441 | 1441 |
robertphillips
2015/02/11 20:01:09
suggested?
| |
1442 // Limit the number of suggested quads to approximate a conic | |
1443 #define kMaxConicToQuadPOW2 4 | |
1444 | |
1442 int SkConic::computeQuadPOW2(SkScalar tol) const { | 1445 int SkConic::computeQuadPOW2(SkScalar tol) const { |
1446 if (tol < 0 || !SkScalarIsFinite(tol)) { | |
1447 return 0; | |
1448 } | |
1449 | |
1443 AS_QUAD_ERROR_SETUP | 1450 AS_QUAD_ERROR_SETUP |
1451 | |
robertphillips
2015/02/11 20:01:54
Don't you want to put this in a gypi somewhere?
| |
1452 #ifdef SK_SUPPORT_LEGACY_CONIC_COMPUTE_QUAD_POW2 | |
1444 SkScalar error = SkScalarSqrt(x * x + y * y) - tol; | 1453 SkScalar error = SkScalarSqrt(x * x + y * y) - tol; |
1445 | 1454 |
1446 if (error <= 0) { | 1455 if (error <= 0) { |
1447 return 0; | 1456 return 0; |
1448 } | 1457 } |
1449 uint32_t ierr = (uint32_t)error; | 1458 uint32_t ierr = (uint32_t)error; |
1450 return (34 - SkCLZ(ierr)) >> 1; | 1459 return (34 - SkCLZ(ierr)) >> 1; |
1460 #else | |
1461 SkScalar error = SkScalarSqrt(x * x + y * y); | |
1462 int pow2; | |
1463 for (pow2 = 0; pow2 < kMaxConicToQuadPOW2; ++pow2) { | |
1464 if (error <= tol) { | |
1465 break; | |
1466 } | |
1467 error *= 0.25f; | |
1468 } | |
1469 return pow2; | |
1470 #endif | |
1451 } | 1471 } |
1452 | 1472 |
1453 static SkPoint* subdivide(const SkConic& src, SkPoint pts[], int level) { | 1473 static SkPoint* subdivide(const SkConic& src, SkPoint pts[], int level) { |
1454 SkASSERT(level >= 0); | 1474 SkASSERT(level >= 0); |
1455 | 1475 |
1456 if (0 == level) { | 1476 if (0 == level) { |
1457 memcpy(pts, &src.fPts[1], 2 * sizeof(SkPoint)); | 1477 memcpy(pts, &src.fPts[1], 2 * sizeof(SkPoint)); |
1458 return pts + 2; | 1478 return pts + 2; |
1459 } else { | 1479 } else { |
1460 SkConic dst[2]; | 1480 SkConic dst[2]; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1634 matrix.preScale(SK_Scalar1, -SK_Scalar1); | 1654 matrix.preScale(SK_Scalar1, -SK_Scalar1); |
1635 } | 1655 } |
1636 if (userMatrix) { | 1656 if (userMatrix) { |
1637 matrix.postConcat(*userMatrix); | 1657 matrix.postConcat(*userMatrix); |
1638 } | 1658 } |
1639 for (int i = 0; i < conicCount; ++i) { | 1659 for (int i = 0; i < conicCount; ++i) { |
1640 matrix.mapPoints(dst[i].fPts, 3); | 1660 matrix.mapPoints(dst[i].fPts, 3); |
1641 } | 1661 } |
1642 return conicCount; | 1662 return conicCount; |
1643 } | 1663 } |
OLD | NEW |