Use LUT for computing final shadow alpha

bug:27415250

Significantly reduces shadow fragment shader computation.

Change-Id: Ie9b3c712700754b3734d0ae9cda8751c298fc59e
diff --git a/libs/hwui/AmbientShadow.cpp b/libs/hwui/AmbientShadow.cpp
index 20ecda2..3982fa0 100644
--- a/libs/hwui/AmbientShadow.cpp
+++ b/libs/hwui/AmbientShadow.cpp
@@ -43,9 +43,7 @@
 /**
  * Other constants:
  */
-// For the edge of the penumbra, the opacity is 0. After transform (1 - alpha),
-// it is 1.
-#define TRANSFORMED_OUTER_OPACITY (1.0f)
+#define OUTER_ALPHA (0.0f)
 
 // Once the alpha difference is greater than this threshold, we will allocate extra
 // edge vertices.
@@ -81,17 +79,6 @@
     return 1.0 / (1 + std::max(factoredZ, 0.0f));
 }
 
-// The shader is using gaussian function e^-(1-x)*(1-x)*4, therefore, we transform
-// the alpha value to (1 - alpha)
-inline float getTransformedAlphaFromAlpha(float alpha) {
-    return 1.0f - alpha;
-}
-
-// The output is ranged from 0 to 1.
-inline float getTransformedAlphaFromFactoredZ(float factoredZ) {
-    return getTransformedAlphaFromAlpha(getAlphaFromFactoredZ(factoredZ));
-}
-
 inline int getEdgeExtraAndUpdateSpike(Vector2* currentSpike,
         const Vector3& secondVertex, const Vector3& centroid) {
     Vector2 secondSpike  = {secondVertex.x - centroid.x, secondVertex.y - centroid.y};
@@ -225,9 +212,9 @@
         if (!isCasterOpaque) {
             umbraVertices[umbraIndex++] = vertexBufferIndex;
         }
-        AlphaVertex::set(&shadowVertices[vertexBufferIndex++], casterVertices[i].x,
-                casterVertices[i].y,
-                getTransformedAlphaFromAlpha(currentAlpha));
+        AlphaVertex::set(&shadowVertices[vertexBufferIndex++],
+                casterVertices[i].x, casterVertices[i].y,
+                currentAlpha);
 
         const Vector3& innerStart = casterVertices[i];
 
@@ -249,7 +236,7 @@
             indexBuffer[indexBufferIndex++] = vertexBufferIndex;
             indexBuffer[indexBufferIndex++] = currentInnerVertexIndex;
             AlphaVertex::set(&shadowVertices[vertexBufferIndex++], outerVertex.x,
-                    outerVertex.y, TRANSFORMED_OUTER_OPACITY);
+                    outerVertex.y, OUTER_ALPHA);
 
             if (j == 0) {
                 outerStart = outerVertex;
@@ -285,7 +272,7 @@
                     (outerLast * startWeight + outerNext * k) / extraVerticesNumber;
                 indexBuffer[indexBufferIndex++] = vertexBufferIndex;
                 AlphaVertex::set(&shadowVertices[vertexBufferIndex++], currentOuter.x,
-                        currentOuter.y, TRANSFORMED_OUTER_OPACITY);
+                        currentOuter.y, OUTER_ALPHA);
 
                 if (!isCasterOpaque) {
                     umbraVertices[umbraIndex++] = vertexBufferIndex;
@@ -295,7 +282,7 @@
                 indexBuffer[indexBufferIndex++] = vertexBufferIndex;
                 AlphaVertex::set(&shadowVertices[vertexBufferIndex++], currentInner.x,
                         currentInner.y,
-                        getTransformedAlphaFromFactoredZ(currentInner.z * heightFactor));
+                        getAlphaFromFactoredZ(currentInner.z * heightFactor));
             }
         }
         currentAlpha = nextAlpha;
@@ -307,7 +294,7 @@
     if (!isCasterOpaque) {
         // Add the centroid as the last one in the vertex buffer.
         float centroidOpacity =
-            getTransformedAlphaFromFactoredZ(centroid3d.z * heightFactor);
+            getAlphaFromFactoredZ(centroid3d.z * heightFactor);
         int centroidIndex = vertexBufferIndex;
         AlphaVertex::set(&shadowVertices[vertexBufferIndex++], centroid3d.x,
                 centroid3d.y, centroidOpacity);