Bring back the shadow strength tweak

bug:16712006

Change-Id: Ifc0ecca139d58140b45d7d227536a53069e1d480
diff --git a/libs/hwui/Caches.cpp b/libs/hwui/Caches.cpp
index 7bd0798..5689e17 100644
--- a/libs/hwui/Caches.cpp
+++ b/libs/hwui/Caches.cpp
@@ -703,6 +703,8 @@
     propertyLightPosY = -1.0f;
     propertyLightPosZ = -1.0f;
     propertyAmbientRatio = -1.0f;
+    propertyAmbientShadowStrength = -1;
+    propertySpotShadowStrength = -1;
 }
 
 void Caches::setTempProperty(const char* name, const char* value) {
@@ -723,6 +725,14 @@
         propertyLightPosZ = fmin(fmax(atof(value), 0.0), 3000.0);
         ALOGD("lightPos Z = %.2f", propertyLightPosZ);
         return;
+    } else if (!strcmp(name, "ambientShadowStrength")) {
+        propertyAmbientShadowStrength = atoi(value);
+        ALOGD("ambient shadow strength = 0x%x out of 0xff", propertyAmbientShadowStrength);
+        return;
+    } else if (!strcmp(name, "spotShadowStrength")) {
+        propertySpotShadowStrength = atoi(value);
+        ALOGD("spot shadow strength = 0x%x out of 0xff", propertySpotShadowStrength);
+        return;
     }
     ALOGD("    failed");
 }
diff --git a/libs/hwui/Caches.h b/libs/hwui/Caches.h
index e00cb0b..0482430 100644
--- a/libs/hwui/Caches.h
+++ b/libs/hwui/Caches.h
@@ -366,6 +366,9 @@
     float propertyLightPosY;
     float propertyLightPosZ;
     float propertyAmbientRatio;
+    int propertyAmbientShadowStrength;
+    int propertySpotShadowStrength;
+
 private:
     enum OverdrawColorSet {
         kColorSet_Default = 0,
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index d1522b6..3fcfbc1 100755
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -3166,13 +3166,22 @@
     SkPaint paint;
     paint.setAntiAlias(true); // want to use AlphaVertex
 
-    if (ambientShadowVertexBuffer && mAmbientShadowAlpha > 0) {
-        paint.setARGB(casterAlpha * mAmbientShadowAlpha, 0, 0, 0);
+    // The caller has made sure casterAlpha > 0.
+    float ambientShadowAlpha = mAmbientShadowAlpha;
+    if (CC_UNLIKELY(mCaches.propertyAmbientShadowStrength >= 0)) {
+        ambientShadowAlpha = mCaches.propertyAmbientShadowStrength;
+    }
+    if (ambientShadowVertexBuffer && ambientShadowAlpha > 0) {
+        paint.setARGB(casterAlpha * ambientShadowAlpha, 0, 0, 0);
         drawVertexBuffer(*ambientShadowVertexBuffer, &paint, kVertexBuffer_ShadowInterp);
     }
 
-    if (spotShadowVertexBuffer && mSpotShadowAlpha > 0) {
-        paint.setARGB(casterAlpha * mSpotShadowAlpha, 0, 0, 0);
+    float spotShadowAlpha = mSpotShadowAlpha;
+    if (CC_UNLIKELY(mCaches.propertySpotShadowStrength >= 0)) {
+        spotShadowAlpha = mCaches.propertySpotShadowStrength;
+    }
+    if (spotShadowVertexBuffer && spotShadowAlpha > 0) {
+        paint.setARGB(casterAlpha * spotShadowAlpha, 0, 0, 0);
         drawVertexBuffer(*spotShadowVertexBuffer, &paint, kVertexBuffer_ShadowInterp);
     }