diff options
author | Chris Craik <ccraik@google.com> | 2015-05-28 22:50:02 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-05-28 22:50:03 +0000 |
commit | da28c8681a6868d188431aed626abe9bd6da2502 (patch) | |
tree | 2f51f29fa4dd59a8f690ac67072827a57f421062 /libs | |
parent | b3af4f43d747d214c834ff824fd3116d4728b817 (diff) | |
parent | ff29b5a5b9b991868051f0fa065a4ac668e7fa0b (diff) | |
download | frameworks_base-da28c8681a6868d188431aed626abe9bd6da2502.zip frameworks_base-da28c8681a6868d188431aed626abe9bd6da2502.tar.gz frameworks_base-da28c8681a6868d188431aed626abe9bd6da2502.tar.bz2 |
Merge "Fix round cap approximation to understand scale" into mnc-dev
Diffstat (limited to 'libs')
-rw-r--r-- | libs/hwui/PathTessellator.cpp | 8 | ||||
-rw-r--r-- | libs/hwui/utils/MathUtils.h | 15 |
2 files changed, 18 insertions, 5 deletions
diff --git a/libs/hwui/PathTessellator.cpp b/libs/hwui/PathTessellator.cpp index 310da41..547c877 100644 --- a/libs/hwui/PathTessellator.cpp +++ b/libs/hwui/PathTessellator.cpp @@ -152,13 +152,11 @@ public: */ inline int capExtraDivisions() const { if (cap == SkPaint::kRound_Cap) { + // always use 2 points for hairline if (halfStrokeWidth == 0.0f) return 2; - // ROUND_CAP_THRESH is the maximum error for polygonal approximation of the round cap - const float errConst = (-ROUND_CAP_THRESH / halfStrokeWidth + 1); - const float targetCosVal = 2 * errConst * errConst - 1; - int neededDivisions = (int)(ceilf(PI / acos(targetCosVal)/2)) * 2; - return neededDivisions; + float threshold = MathUtils::min(inverseScaleX, inverseScaleY) * ROUND_CAP_THRESH; + return MathUtils::divisionsNeededToApproximateArc(halfStrokeWidth, PI, threshold); } return 0; } diff --git a/libs/hwui/utils/MathUtils.h b/libs/hwui/utils/MathUtils.h index d89859b..9c3787c 100644 --- a/libs/hwui/utils/MathUtils.h +++ b/libs/hwui/utils/MathUtils.h @@ -16,6 +16,8 @@ #ifndef MATHUTILS_H #define MATHUTILS_H +#include <math.h> + namespace android { namespace uirenderer { @@ -62,6 +64,19 @@ public: return scale; } + /** + * Returns the number of points (beyond two, the start and end) needed to form a polygonal + * approximation of an arc, with a given threshold value. + */ + inline static int divisionsNeededToApproximateArc(float radius, + float angleInRads, float threshold) { + const float errConst = (-threshold / radius + 1); + const float targetCosVal = 2 * errConst * errConst - 1; + + // needed divisions are rounded up from approximation + return (int)(ceilf(angleInRads / acos(targetCosVal)/2)) * 2; + } + inline static bool areEqual(float valueA, float valueB) { return isZero(valueA - valueB); } |