am 5384b5bb: Merge "Nexus: Rescale the scene on wallpaper resize"

* commit '5384b5bbdeefe574e269ed3c2835aeb6f09949b7':
  Nexus: Rescale the scene on wallpaper resize
diff --git a/src/com/android/wallpaper/nexus/NexusRS.java b/src/com/android/wallpaper/nexus/NexusRS.java
index 20b7dd3..50dab9d 100644
--- a/src/com/android/wallpaper/nexus/NexusRS.java
+++ b/src/com/android/wallpaper/nexus/NexusRS.java
@@ -44,12 +44,21 @@
 
     private ProgramVertexFixedFunction.Constants mPvOrthoAlloc;
 
+    private int mInitialWidth;
+    private int mInitialHeight;
+    private float mWorldScaleX;
+    private float mWorldScaleY;
     private float mXOffset;
     private ScriptC_nexus mScript;
 
     public NexusRS(int width, int height) {
         super(width, height);
 
+        mInitialWidth = width;
+        mInitialHeight = height;
+        mWorldScaleX = 1.0f;
+        mWorldScaleY = 1.0f;
+
         mOptionsARGB.inScaled = false;
         mOptionsARGB.inPreferredConfig = Bitmap.Config.ARGB_8888;
     }
@@ -70,6 +79,11 @@
         super.resize(width, height); // updates mWidth, mHeight
 
         // android.util.Log.d("NexusRS", String.format("resize(%d, %d)", width, height));
+
+        mWorldScaleX = (float)mInitialWidth / width;
+        mWorldScaleY = (float)mInitialHeight / height;
+        mScript.set_gWorldScaleX(mWorldScaleX);
+        mScript.set_gWorldScaleY(mWorldScaleY);
     }
 
     @Override
@@ -100,6 +114,8 @@
         mScript.set_gIsPreview(isPreview() ? 1 : 0);
         mScript.set_gMode(mode);
         mScript.set_gXOffset(0.f);
+        mScript.set_gWorldScaleX(mWorldScaleX);
+        mScript.set_gWorldScaleY(mWorldScaleY);
     }
 
     private Allocation loadTexture(int id) {
@@ -161,7 +177,7 @@
 
         if (mWidth < mHeight) {
             // nexus.rs ignores the xOffset when rotated; we shall endeavor to do so as well
-            x = (int) (x + mXOffset * mWidth);
+            x = (int) (x + mXOffset * mWidth / mWorldScaleX);
         }
 
         // android.util.Log.d("NexusRS", String.format(
diff --git a/src/com/android/wallpaper/nexus/nexus.rs b/src/com/android/wallpaper/nexus/nexus.rs
index 2db8d52..ef1788e 100644
--- a/src/com/android/wallpaper/nexus/nexus.rs
+++ b/src/com/android/wallpaper/nexus/nexus.rs
@@ -52,6 +52,8 @@
 static int gHeight;
 static int gRotate;
 
+float gWorldScaleX;
+float gWorldScaleY;
 float gXOffset;
 int gIsPreview;
 int gMode;
@@ -168,7 +170,7 @@
             } else {
                  rsMatrixTranslate(&modelMatrix, -(gXOffset * gWidth), 0, 0);
             }
-            rsMatrixScale(&modelMatrix, p->scale, p->scale, 1.0f);
+            rsMatrixScale(&modelMatrix, p->scale * gWorldScaleX, p->scale * gWorldScaleY, 1.0f);
             rsgProgramVertexLoadModelMatrix(&modelMatrix);
 
            float x = p->originX + (p->dx * SPEED * delta);
@@ -305,6 +307,7 @@
 
     rs_matrix4x4 matrix;
     rsMatrixLoadIdentity(&matrix);
+    rsMatrixScale(&matrix, gWorldScaleX, gWorldScaleY, 1.0f);
 
     if (gRotate) {
         //matrixLoadRotate(matrix, 90.0f, 0.0f, 0.0f, 1.0f);