diff options
author | Chris Craik <ccraik@google.com> | 2014-06-12 19:57:36 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-06-12 19:57:36 +0000 |
commit | 5b368b3d9f1f99a9b92971a0596ccb15f77017d2 (patch) | |
tree | be25e28eb0110438a8a88348d421658a47ab0d32 /libs | |
parent | a9b2639cbae881357c5543f1a66da252f98ebb08 (diff) | |
parent | 0adb6d6e5090fd08242e7015b2ffdc91e3a42307 (diff) | |
download | frameworks_base-5b368b3d9f1f99a9b92971a0596ccb15f77017d2.zip frameworks_base-5b368b3d9f1f99a9b92971a0596ccb15f77017d2.tar.gz frameworks_base-5b368b3d9f1f99a9b92971a0596ccb15f77017d2.tar.bz2 |
am 98b10e48: Merge "Limit path approximation recursion depth" into lmp-preview-dev
* commit '98b10e480279d331e54b9f28546629687244a01c':
Limit path approximation recursion depth
Diffstat (limited to 'libs')
-rw-r--r-- | libs/hwui/PathTessellator.cpp | 19 | ||||
-rw-r--r-- | libs/hwui/PathTessellator.h | 4 |
2 files changed, 13 insertions, 10 deletions
diff --git a/libs/hwui/PathTessellator.cpp b/libs/hwui/PathTessellator.cpp index c9921ba..59e15e1 100644 --- a/libs/hwui/PathTessellator.cpp +++ b/libs/hwui/PathTessellator.cpp @@ -975,11 +975,14 @@ bool PathTessellator::approximatePathOutlineVertices(const SkPath& path, bool fo // Bezier approximation /////////////////////////////////////////////////////////////////////////////// +// Depth at which recursion is aborted +#define ABORT_DEPTH 20 + void PathTessellator::recursiveCubicBezierVertices( float p1x, float p1y, float c1x, float c1y, float p2x, float p2y, float c2x, float c2y, float sqrInvScaleX, float sqrInvScaleY, float thresholdSquared, - Vector<Vertex>& outputVertices) { + Vector<Vertex>& outputVertices, int depth) { float dx = p2x - p1x; float dy = p2y - p1y; float d1 = fabs((c1x - p2x) * dy - (c1y - p2y) * dx); @@ -988,7 +991,7 @@ void PathTessellator::recursiveCubicBezierVertices( // multiplying by sqrInvScaleY/X equivalent to multiplying in dimensional scale factors - if (d * d < thresholdSquared * (dx * dx * sqrInvScaleY + dy * dy * sqrInvScaleX)) { + if (depth >= ABORT_DEPTH || d * d < thresholdSquared * (dx * dx * sqrInvScaleY + dy * dy * sqrInvScaleX)) { // below thresh, draw line by adding endpoint pushToVector(outputVertices, p2x, p2y); } else { @@ -1012,11 +1015,11 @@ void PathTessellator::recursiveCubicBezierVertices( recursiveCubicBezierVertices( p1x, p1y, p1c1x, p1c1y, mx, my, p1c1c2x, p1c1c2y, - sqrInvScaleX, sqrInvScaleY, thresholdSquared, outputVertices); + sqrInvScaleX, sqrInvScaleY, thresholdSquared, outputVertices, depth + 1); recursiveCubicBezierVertices( mx, my, p2c1c2x, p2c1c2y, p2x, p2y, p2c2x, p2c2y, - sqrInvScaleX, sqrInvScaleY, thresholdSquared, outputVertices); + sqrInvScaleX, sqrInvScaleY, thresholdSquared, outputVertices, depth + 1); } } @@ -1025,12 +1028,12 @@ void PathTessellator::recursiveQuadraticBezierVertices( float bx, float by, float cx, float cy, float sqrInvScaleX, float sqrInvScaleY, float thresholdSquared, - Vector<Vertex>& outputVertices) { + Vector<Vertex>& outputVertices, int depth) { float dx = bx - ax; float dy = by - ay; float d = (cx - bx) * dy - (cy - by) * dx; - if (d * d < thresholdSquared * (dx * dx * sqrInvScaleY + dy * dy * sqrInvScaleX)) { + if (depth >= ABORT_DEPTH || d * d < thresholdSquared * (dx * dx * sqrInvScaleY + dy * dy * sqrInvScaleX)) { // below thresh, draw line by adding endpoint pushToVector(outputVertices, bx, by); } else { @@ -1044,9 +1047,9 @@ void PathTessellator::recursiveQuadraticBezierVertices( float my = (acy + bcy) * 0.5f; recursiveQuadraticBezierVertices(ax, ay, mx, my, acx, acy, - sqrInvScaleX, sqrInvScaleY, thresholdSquared, outputVertices); + sqrInvScaleX, sqrInvScaleY, thresholdSquared, outputVertices, depth + 1); recursiveQuadraticBezierVertices(mx, my, bx, by, bcx, bcy, - sqrInvScaleX, sqrInvScaleY, thresholdSquared, outputVertices); + sqrInvScaleX, sqrInvScaleY, thresholdSquared, outputVertices, depth + 1); } } diff --git a/libs/hwui/PathTessellator.h b/libs/hwui/PathTessellator.h index f033470..8ac9a3b 100644 --- a/libs/hwui/PathTessellator.h +++ b/libs/hwui/PathTessellator.h @@ -105,7 +105,7 @@ private: float bx, float by, float cx, float cy, float sqrInvScaleX, float sqrInvScaleY, float thresholdSquared, - Vector<Vertex> &outputVertices); + Vector<Vertex> &outputVertices, int depth = 0); /* endpoints p1, p2 @@ -117,7 +117,7 @@ private: float p2x, float p2y, float c2x, float c2y, float sqrInvScaleX, float sqrInvScaleY, float thresholdSquared, - Vector<Vertex> &outputVertices); + Vector<Vertex> &outputVertices, int depth = 0); }; }; // namespace uirenderer |