Loading libs/hwui/PathTessellator.cpp +3 −5 Original line number Original line Diff line number Diff line Loading @@ -152,13 +152,11 @@ public: */ */ inline int capExtraDivisions() const { inline int capExtraDivisions() const { if (cap == SkPaint::kRound_Cap) { if (cap == SkPaint::kRound_Cap) { // always use 2 points for hairline if (halfStrokeWidth == 0.0f) return 2; if (halfStrokeWidth == 0.0f) return 2; // ROUND_CAP_THRESH is the maximum error for polygonal approximation of the round cap float threshold = MathUtils::min(inverseScaleX, inverseScaleY) * ROUND_CAP_THRESH; const float errConst = (-ROUND_CAP_THRESH / halfStrokeWidth + 1); return MathUtils::divisionsNeededToApproximateArc(halfStrokeWidth, PI, threshold); const float targetCosVal = 2 * errConst * errConst - 1; int neededDivisions = (int)(ceilf(PI / acos(targetCosVal)/2)) * 2; return neededDivisions; } } return 0; return 0; } } Loading libs/hwui/utils/MathUtils.h +15 −0 Original line number Original line Diff line number Diff line Loading @@ -16,6 +16,8 @@ #ifndef MATHUTILS_H #ifndef MATHUTILS_H #define MATHUTILS_H #define MATHUTILS_H #include <math.h> namespace android { namespace android { namespace uirenderer { namespace uirenderer { Loading Loading @@ -62,6 +64,19 @@ public: return scale; 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) { inline static bool areEqual(float valueA, float valueB) { return isZero(valueA - valueB); return isZero(valueA - valueB); } } Loading Loading
libs/hwui/PathTessellator.cpp +3 −5 Original line number Original line Diff line number Diff line Loading @@ -152,13 +152,11 @@ public: */ */ inline int capExtraDivisions() const { inline int capExtraDivisions() const { if (cap == SkPaint::kRound_Cap) { if (cap == SkPaint::kRound_Cap) { // always use 2 points for hairline if (halfStrokeWidth == 0.0f) return 2; if (halfStrokeWidth == 0.0f) return 2; // ROUND_CAP_THRESH is the maximum error for polygonal approximation of the round cap float threshold = MathUtils::min(inverseScaleX, inverseScaleY) * ROUND_CAP_THRESH; const float errConst = (-ROUND_CAP_THRESH / halfStrokeWidth + 1); return MathUtils::divisionsNeededToApproximateArc(halfStrokeWidth, PI, threshold); const float targetCosVal = 2 * errConst * errConst - 1; int neededDivisions = (int)(ceilf(PI / acos(targetCosVal)/2)) * 2; return neededDivisions; } } return 0; return 0; } } Loading
libs/hwui/utils/MathUtils.h +15 −0 Original line number Original line Diff line number Diff line Loading @@ -16,6 +16,8 @@ #ifndef MATHUTILS_H #ifndef MATHUTILS_H #define MATHUTILS_H #define MATHUTILS_H #include <math.h> namespace android { namespace android { namespace uirenderer { namespace uirenderer { Loading Loading @@ -62,6 +64,19 @@ public: return scale; 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) { inline static bool areEqual(float valueA, float valueB) { return isZero(valueA - valueB); return isZero(valueA - valueB); } } Loading