Re-triangulate the spot shadow.

Fix the valid umbra detection.

This looks better b/c every vertex will have one ray shooting at it, such that
we don't miss the corner.

This performs better too, due to the polygon intersection is removed and less ray
intersection. 2x performance for rect and circle for spot shadow in test app.

    b/17288227
    b/15598793
    b/16712006

Change-Id: I4a5ee397b9e192e93c8e35e6260b499e3e38a6f4
diff --git a/libs/hwui/ShadowTessellator.cpp b/libs/hwui/ShadowTessellator.cpp
index 6cff815..c1ffa0a 100644
--- a/libs/hwui/ShadowTessellator.cpp
+++ b/libs/hwui/ShadowTessellator.cpp
@@ -252,5 +252,29 @@
     }
 }
 
+int ShadowTessellator::getExtraVertexNumber(const Vector2& vector1,
+        const Vector2& vector2, float divisor) {
+    // When there is no distance difference, there is no need for extra vertices.
+    if (vector1.lengthSquared() == 0 || vector2.lengthSquared() == 0) {
+        return 0;
+    }
+    // The formula is :
+    // extraNumber = floor(acos(dot(n1, n2)) / (M_PI / EXTRA_VERTEX_PER_PI))
+    // The value ranges for each step are:
+    // dot( ) --- [-1, 1]
+    // acos( )     --- [0, M_PI]
+    // floor(...)  --- [0, EXTRA_VERTEX_PER_PI]
+    float dotProduct = vector1.dot(vector2);
+    // TODO: Use look up table for the dotProduct to extraVerticesNumber
+    // computation, if needed.
+    float angle = acosf(dotProduct);
+    return (int) floor(angle / divisor);
+}
+
+void ShadowTessellator::checkOverflow(int used, int total, const char* bufferName) {
+    LOG_ALWAYS_FATAL_IF(used > total, "Error: %s overflow!!! used %d, total %d",
+            bufferName, used, total);
+}
+
 }; // namespace uirenderer
 }; // namespace android