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 1431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1442 // Limit the number of suggested quads to approximate a conic | 1442 // Limit the number of suggested quads to approximate a conic |
1443 #define kMaxConicToQuadPOW2 5 | 1443 #define kMaxConicToQuadPOW2 5 |
1444 | 1444 |
1445 int SkConic::computeQuadPOW2(SkScalar tol) const { | 1445 int SkConic::computeQuadPOW2(SkScalar tol) const { |
1446 if (tol < 0 || !SkScalarIsFinite(tol)) { | 1446 if (tol < 0 || !SkScalarIsFinite(tol)) { |
1447 return 0; | 1447 return 0; |
1448 } | 1448 } |
1449 | 1449 |
1450 AS_QUAD_ERROR_SETUP | 1450 AS_QUAD_ERROR_SETUP |
1451 | 1451 |
1452 #ifdef SK_SUPPORT_LEGACY_CONIC_COMPUTE_QUAD_POW2 | |
1453 SkScalar error = SkScalarSqrt(x * x + y * y) - tol; | |
1454 | |
1455 if (error <= 0) { | |
1456 return 0; | |
1457 } | |
1458 uint32_t ierr = (uint32_t)error; | |
1459 return (34 - SkCLZ(ierr)) >> 1; | |
1460 #else | |
1461 SkScalar error = SkScalarSqrt(x * x + y * y); | 1452 SkScalar error = SkScalarSqrt(x * x + y * y); |
1462 int pow2; | 1453 int pow2; |
1463 for (pow2 = 0; pow2 < kMaxConicToQuadPOW2; ++pow2) { | 1454 for (pow2 = 0; pow2 < kMaxConicToQuadPOW2; ++pow2) { |
1464 if (error <= tol) { | 1455 if (error <= tol) { |
1465 break; | 1456 break; |
1466 } | 1457 } |
1467 error *= 0.25f; | 1458 error *= 0.25f; |
1468 } | 1459 } |
1469 // float version -- using ceil gives the same results as the above. | 1460 // float version -- using ceil gives the same results as the above. |
1470 if (false) { | 1461 if (false) { |
1471 SkScalar err = SkScalarSqrt(x * x + y * y); | 1462 SkScalar err = SkScalarSqrt(x * x + y * y); |
1472 if (err <= tol) { | 1463 if (err <= tol) { |
1473 return 0; | 1464 return 0; |
1474 } | 1465 } |
1475 SkScalar tol2 = tol * tol; | 1466 SkScalar tol2 = tol * tol; |
1476 if (tol2 == 0) { | 1467 if (tol2 == 0) { |
1477 return kMaxConicToQuadPOW2; | 1468 return kMaxConicToQuadPOW2; |
1478 } | 1469 } |
1479 SkScalar fpow2 = SkScalarLog2((x * x + y * y) / tol2) * 0.25f; | 1470 SkScalar fpow2 = SkScalarLog2((x * x + y * y) / tol2) * 0.25f; |
1480 int altPow2 = SkScalarCeilToInt(fpow2); | 1471 int altPow2 = SkScalarCeilToInt(fpow2); |
1481 if (altPow2 != pow2) { | 1472 if (altPow2 != pow2) { |
1482 SkDebugf("pow2 %d altPow2 %d fbits %g err %g tol %g\n", pow2, altPow
2, fpow2, err, tol); | 1473 SkDebugf("pow2 %d altPow2 %d fbits %g err %g tol %g\n", pow2, altPow
2, fpow2, err, tol); |
1483 } | 1474 } |
1484 pow2 = altPow2; | 1475 pow2 = altPow2; |
1485 } | 1476 } |
1486 return pow2; | 1477 return pow2; |
1487 #endif | |
1488 } | 1478 } |
1489 | 1479 |
1490 static SkPoint* subdivide(const SkConic& src, SkPoint pts[], int level) { | 1480 static SkPoint* subdivide(const SkConic& src, SkPoint pts[], int level) { |
1491 SkASSERT(level >= 0); | 1481 SkASSERT(level >= 0); |
1492 | 1482 |
1493 if (0 == level) { | 1483 if (0 == level) { |
1494 memcpy(pts, &src.fPts[1], 2 * sizeof(SkPoint)); | 1484 memcpy(pts, &src.fPts[1], 2 * sizeof(SkPoint)); |
1495 return pts + 2; | 1485 return pts + 2; |
1496 } else { | 1486 } else { |
1497 SkConic dst[2]; | 1487 SkConic dst[2]; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1671 matrix.preScale(SK_Scalar1, -SK_Scalar1); | 1661 matrix.preScale(SK_Scalar1, -SK_Scalar1); |
1672 } | 1662 } |
1673 if (userMatrix) { | 1663 if (userMatrix) { |
1674 matrix.postConcat(*userMatrix); | 1664 matrix.postConcat(*userMatrix); |
1675 } | 1665 } |
1676 for (int i = 0; i < conicCount; ++i) { | 1666 for (int i = 0; i < conicCount; ++i) { |
1677 matrix.mapPoints(dst[i].fPts, 3); | 1667 matrix.mapPoints(dst[i].fPts, 3); |
1678 } | 1668 } |
1679 return conicCount; | 1669 return conicCount; |
1680 } | 1670 } |
OLD | NEW |