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
diff --git a/libs/hwui/SpotShadow.cpp b/libs/hwui/SpotShadow.cpp
index 5fa0ba5..3ebe7b4 100644
--- a/libs/hwui/SpotShadow.cpp
+++ b/libs/hwui/SpotShadow.cpp
@@ -174,10 +174,10 @@
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,33 +407,12 @@
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
*
* @param polygon the polygon as a Vector2 array