summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlex Sakhartchouk <alexst@google.com>2010-09-13 20:44:01 -0700
committerAlex Sakhartchouk <alexst@google.com>2010-09-13 20:44:01 -0700
commit95252b4cbde4ec9ebc60265bcc837d7a366b6101 (patch)
treee8946d0480b798f4461337e6e59373f34673e3f0 /src
parent201058d9c9866f3328291e495bcdfbeebe76d632 (diff)
downloadandroid_packages_apps_Trebuchet-95252b4cbde4ec9ebc60265bcc837d7a366b6101.tar.gz
android_packages_apps_Trebuchet-95252b4cbde4ec9ebc60265bcc837d7a366b6101.tar.bz2
android_packages_apps_Trebuchet-95252b4cbde4ec9ebc60265bcc837d7a366b6101.zip
Changing Launcher2 to use more generic shader param binding.
Change-Id: I5550a5ce88e5edc5ce11689e828001e28bb29e04
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher2/AllApps3D.java86
-rw-r--r--src/com/android/launcher2/allapps.rs7
2 files changed, 59 insertions, 34 deletions
diff --git a/src/com/android/launcher2/AllApps3D.java b/src/com/android/launcher2/AllApps3D.java
index d06624d25..14c42bd21 100644
--- a/src/com/android/launcher2/AllApps3D.java
+++ b/src/com/android/launcher2/AllApps3D.java
@@ -20,6 +20,8 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import com.android.launcher.R;
+
import android.content.ComponentName;
import android.content.Context;
import android.content.res.Resources;
@@ -27,17 +29,7 @@ import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.PixelFormat;
import android.graphics.Rect;
-import android.renderscript.Allocation;
-import android.renderscript.Element;
-import android.renderscript.ProgramFragment;
-import android.renderscript.ProgramStore;
-import android.renderscript.ProgramVertex;
-import android.renderscript.RSSurfaceView;
-import android.renderscript.RenderScript;
-import android.renderscript.RenderScriptGL;
-import android.renderscript.Sampler;
-import android.renderscript.Mesh;
-import android.renderscript.Type;
+import android.renderscript.*;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
@@ -50,8 +42,6 @@ import android.view.View;
import android.view.ViewConfiguration;
import android.view.accessibility.AccessibilityEvent;
-import com.android.launcher.R;
-
public class AllApps3D extends RSSurfaceView
implements AllAppsView, View.OnClickListener, View.OnLongClickListener, DragSource {
private static final String TAG = "Launcher.AllApps3D";
@@ -265,22 +255,6 @@ public class AllApps3D extends RSSurfaceView
sRS.mMessageCallback = mMessageProc = new AAMessage();
}
- if (sRollo.mUniformAlloc != null) {
- ScriptField_VpConsts.Item i = new ScriptField_VpConsts.Item();
- i.ScaleOffset.x = (2.f / 480.f);
- i.ScaleOffset.y = 0;
- i.ScaleOffset.z = -((float)w / 2) - 0.25f;
- i.ScaleOffset.w = -380.25f;
- i.BendPos.x = 120.f;
- i.BendPos.y = 680.f;
- if (w > h) {
- i.ScaleOffset.z = 40.f;
- i.ScaleOffset.w = h - 40.f;
- i.BendPos.y = 1.f;
- }
- sRollo.mUniformAlloc.set(i, 0, true);
- }
-
//long endTime = SystemClock.uptimeMillis();
//Log.d(TAG, "surfaceChanged took " + (endTime-startTime) + "ms");
}
@@ -1029,8 +1003,51 @@ public class AllApps3D extends RSSurfaceView
mScript.set_gSMCell(mMesh);
}
+ Matrix4f getProjectionMatrix(int w, int h) {
+ // range -1,1 in the narrow axis at z = 0.
+ Matrix4f m1 = new Matrix4f();
+ Matrix4f m2 = new Matrix4f();
+
+ if(w > h) {
+ float aspect = ((float)w) / h;
+ m1.loadFrustum(-aspect,aspect, -1,1, 1,100);
+ } else {
+ float aspect = ((float)h) / w;
+ m1.loadFrustum(-1,1, -aspect,aspect, 1,100);
+ }
+
+ m2.loadRotate(180, 0, 1, 0);
+ m1.loadMultiply(m1, m2);
+
+ m2.loadScale(-2, 2, 1);
+ m1.loadMultiply(m1, m2);
+
+ m2.loadTranslate(0, 0, 2);
+ m1.loadMultiply(m1, m2);
+ return m1;
+ }
+
void resize(int w, int h) {
- mPVA.setupProjectionNormalized(w, h);
+ Matrix4f proj = getProjectionMatrix(w, h);
+ mPVA.loadProjection(proj);
+
+ if (mUniformAlloc != null) {
+ ScriptField_VpConsts.Item i = new ScriptField_VpConsts.Item();
+ i.Proj = proj;
+ i.ScaleOffset.x = (2.f / 480.f);
+ i.ScaleOffset.y = 0;
+ i.ScaleOffset.z = -((float)w / 2) - 0.25f;
+ i.ScaleOffset.w = -380.25f;
+ i.BendPos.x = 120.f;
+ i.BendPos.y = 680.f;
+ if (w > h) {
+ i.ScaleOffset.z = 40.f;
+ i.ScaleOffset.w = h - 40.f;
+ i.BendPos.y = 1.f;
+ }
+ mUniformAlloc.set(i, 0, true);
+ }
+
mWidth = w;
mHeight = h;
}
@@ -1050,7 +1067,9 @@ public class AllApps3D extends RSSurfaceView
initMesh();
ProgramVertex.ShaderBuilder sb = new ProgramVertex.ShaderBuilder(sRS);
- String t = "void main() {\n" +
+ String t = "varying vec4 varColor;\n" +
+ "varying vec4 varTex0;\n" +
+ "void main() {\n" +
// Animation
" float ani = UNI_Position.z;\n" +
@@ -1100,7 +1119,7 @@ public class AllApps3D extends RSSurfaceView
" pos.z -= ani * 1.5;\n" +
" lum *= 1.0 - ani;\n" +
- " gl_Position = UNI_MVP * pos;\n" +
+ " gl_Position = UNI_Proj * pos;\n" +
" varColor.rgba = vec4(lum, lum, lum, 1.0);\n" +
" varTex0.xy = ATTRIB_position;\n" +
" varTex0.y = 1.0 - varTex0.y;\n" +
@@ -1110,8 +1129,7 @@ public class AllApps3D extends RSSurfaceView
sb.addConstant(mUniformAlloc.getType());
sb.addInput(mMesh.getVertexAllocation(0).getType().getElement());
ProgramVertex pvc = sb.create();
- pvc.bindAllocation(mPVA);
- pvc.bindConstants(mUniformAlloc.getAllocation(), 1);
+ pvc.bindConstants(mUniformAlloc.getAllocation(), 0);
mScript.set_gPVCurve(pvc);
}
diff --git a/src/com/android/launcher2/allapps.rs b/src/com/android/launcher2/allapps.rs
index b07e1fe8a..acee82bf0 100644
--- a/src/com/android/launcher2/allapps.rs
+++ b/src/com/android/launcher2/allapps.rs
@@ -28,6 +28,7 @@ rs_allocation *gIconIDs;
rs_allocation *gLabelIDs;
typedef struct VpConsts {
+ rs_matrix4x4 Proj;
float4 Position;
float4 ScaleOffset;
float2 BendPos;
@@ -65,6 +66,8 @@ static float g_MoveToOldPos = 0.f;
static int g_Cols;
static int g_Rows;
+rs_allocation g_VPConstAlloc;
+
// Drawing constants, should be parameters ======
#define VIEW_ANGLE 1.28700222f
@@ -300,6 +303,7 @@ static void drawFrontGrid(float rowOffset, float p)
vpConstants->ImgSize.y = rsAllocationGetDimY(gSelectedIconTexture);
vpConstants->Position.y = y - (rsAllocationGetDimY(gSelectedIconTexture)
- rsAllocationGetDimY(gIconIDs[iconNum])) * 0.5f;
+ rsAllocationMarkDirty(g_VPConstAlloc);
rsgDrawMesh(gSMCell);
}
@@ -307,6 +311,7 @@ static void drawFrontGrid(float rowOffset, float p)
vpConstants->ImgSize.x = rsAllocationGetDimX(gIconIDs[iconNum]);
vpConstants->ImgSize.y = rsAllocationGetDimY(gIconIDs[iconNum]);
vpConstants->Position.y = y - 0.2f;
+ rsAllocationMarkDirty(g_VPConstAlloc);
rsgBindTexture(gPFTexMip, 0, gIconIDs[iconNum]);
rsgDrawMesh(gSMCell);
@@ -314,6 +319,7 @@ static void drawFrontGrid(float rowOffset, float p)
vpConstants->ImgSize.x = rsAllocationGetDimX(gLabelIDs[iconNum]);
vpConstants->ImgSize.y = rsAllocationGetDimY(gLabelIDs[iconNum]);
vpConstants->Position.y = y - 64.f - 0.2f;
+ rsAllocationMarkDirty(g_VPConstAlloc);
rsgBindTexture(gPFTexMipAlpha, 0, gLabelIDs[iconNum]);
rsgDrawMesh(gSMCell);
}
@@ -328,6 +334,7 @@ int root()
// Compute dt in seconds.
// physics may break if DT is large.
g_DT = min(rsGetDt(), 0.1f);
+ g_VPConstAlloc = rsGetAllocation(vpConstants);
if (g_Zoom != gZoomTarget) {
float dz = g_DT * 1.7f;