Map shadow light position globally

Change-Id: Ic3201cecdf5d2a1dd628e7e40aee912ef516d3b2
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index 4f6da2b..8fb6e38 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -3201,8 +3201,8 @@
 
     VertexBuffer spotShadowVertexBuffer;
     ShadowTessellator::tessellateSpotShadow(width, height,
-            getWidth(), getHeight(), casterTransform,
-            spotShadowVertexBuffer);
+            *currentTransform(), getWidth(), getHeight(),
+            casterTransform, spotShadowVertexBuffer);
     drawVertexBuffer(spotShadowVertexBuffer, &paint);
 
     return DrawGlInfo::kStatusDrew;
diff --git a/libs/hwui/ShadowTessellator.cpp b/libs/hwui/ShadowTessellator.cpp
index 6385ef7..9d9ce46 100644
--- a/libs/hwui/ShadowTessellator.cpp
+++ b/libs/hwui/ShadowTessellator.cpp
@@ -90,7 +90,7 @@
 }
 
 void ShadowTessellator::tessellateSpotShadow(float width, float height,
-        int screenWidth, int screenHeight,
+        const mat4& receiverTransform, int screenWidth, int screenHeight,
         const mat4& casterTransform, VertexBuffer& shadowVertexBuffer) {
     const int vertexCount = 4;
     Vector3 polygon[vertexCount];
@@ -106,6 +106,13 @@
 #if DEBUG_SHADOW
     ALOGD("light center %f %f %f", lightCenter.x, lightCenter.y, lightCenter.z);
 #endif
+
+    // light position (because it's in local space) needs to compensate for receiver transform
+    // TODO: should apply to light orientation, not just position
+    Matrix4 reverseReceiverTransform;
+    reverseReceiverTransform.loadInverse(receiverTransform);
+    reverseReceiverTransform.mapPoint3d(lightCenter);
+
     const float lightSize = maximal / 8;
     const int lightVertexCount = 16;
 
diff --git a/libs/hwui/ShadowTessellator.h b/libs/hwui/ShadowTessellator.h
index fff00b1..44ac8c0 100644
--- a/libs/hwui/ShadowTessellator.h
+++ b/libs/hwui/ShadowTessellator.h
@@ -30,7 +30,7 @@
             const mat4& casterTransform, VertexBuffer& shadowVertexBuffer);
 
     static void tessellateSpotShadow(float width, float height,
-            int screenWidth, int screenHeight,
+            const mat4& receiverTransform, int screenWidth, int screenHeight,
             const mat4& casterTransform, VertexBuffer& shadowVertexBuffer);
 
 private: