From 2e023f3827dfc0dfc1ed7c3dd54d02b4a993f0b4 Mon Sep 17 00:00:00 2001 From: ztenghui Date: Mon, 28 Apr 2014 16:43:13 -0700 Subject: Make sure the theta is correctly represented and incoming polygon is CW for shadow. Now the theta = 0 should be on +x axis. And cos(theta) should correctly represent x value. Without this fix, the poly theta (from atan2) can be wrongly rotated 90 degrees. Also, make sure the incoming polygon is CW for the shadow system. This fix visual artifacts in recent regression for spot shadows. bug:13553955 Change-Id: I9bbf54db094e7f133326da4dae4610962da849c1 --- libs/hwui/SpotShadow.cpp | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) (limited to 'libs/hwui/SpotShadow.cpp') diff --git a/libs/hwui/SpotShadow.cpp b/libs/hwui/SpotShadow.cpp index 5fa0ba59efac..3ebe7b4f34e7 100644 --- a/libs/hwui/SpotShadow.cpp +++ b/libs/hwui/SpotShadow.cpp @@ -174,10 +174,10 @@ bool SpotShadow::ccw(double ax, double ay, double bx, double by, int SpotShadow::intersection(const Vector2* poly1, int poly1Length, Vector2* poly2, int poly2Length) { #if DEBUG_SHADOW - if (!isClockwise(poly1, poly1Length)) { + if (!ShadowTessellator::isClockwise(poly1, poly1Length)) { ALOGW("Poly1 is not clockwise! Intersection is wrong!"); } - if (!isClockwise(poly2, poly2Length)) { + if (!ShadowTessellator::isClockwise(poly2, poly2Length)) { ALOGW("Poly2 is not clockwise! Intersection is wrong!"); } #endif @@ -407,32 +407,11 @@ void SpotShadow::makeClockwise(Vector2* polygon, int len) { if (polygon == 0 || len == 0) { return; } - if (!isClockwise(polygon, len)) { + if (!ShadowTessellator::isClockwise(polygon, len)) { reverse(polygon, len); } } -/** - * Test whether the polygon is order in clockwise. - * - * @param polygon the polygon as a Vector2 array - * @param len the number of points of the polygon - */ -bool SpotShadow::isClockwise(const Vector2* polygon, int len) { - double sum = 0; - double p1x = polygon[len - 1].x; - double p1y = polygon[len - 1].y; - for (int i = 0; i < len; i++) { - - double p2x = polygon[i].x; - double p2y = polygon[i].y; - sum += p1x * p2y - p2x * p1y; - p1x = p2x; - p1y = p2y; - } - return sum < 0; -} - /** * Reverse the polygon * -- cgit v1.2.3-59-g8ed1b