Merge "Code cleanup possible with new reflected classes."

This commit is contained in:
Jason Sams 2010-06-21 17:44:53 -07:00 committed by Android (Google) Code Review
commit 1444e6e29c
5 changed files with 112 additions and 203 deletions

View File

@ -14,15 +14,10 @@ int ROWS_PER_PAGE_PORTRAIT;
int COLUMNS_PER_PAGE_LANDSCAPE;
int ROWS_PER_PAGE_LANDSCAPE;
float gNewPositionX;
int gNewTouchDown;
float gFlingVelocity;
int gIconCount;
int gSelectedIconIndex = -1;
rs_allocation gSelectedIconTexture;
float gZoomTarget;
rs_allocation gHomeButton;
float gTargetPos;
rs_program_fragment gPFTexNearest;
rs_program_fragment gPFTexMip;
@ -43,13 +38,8 @@ typedef struct VpConsts {
VpConsts_t *vpConstants;
#pragma rs export_var(COLUMNS_PER_PAGE_PORTRAIT, ROWS_PER_PAGE_PORTRAIT, COLUMNS_PER_PAGE_LANDSCAPE, ROWS_PER_PAGE_LANDSCAPE, gNewPositionX, gNewTouchDown, gFlingVelocity, gIconCount, gSelectedIconIndex, gSelectedIconTexture, gZoomTarget, gHomeButton, gTargetPos, gPFTexNearest, gPFTexMip, gPFTexMipAlpha, gPVCurve, gPS, gSMCell, gIconIDs, gLabelIDs, vpConstants)
#pragma rs export_func(resetHWWar, move, moveTo, setZoom, fling)
void debugAll()
{
}
#pragma rs export_var(COLUMNS_PER_PAGE_PORTRAIT, ROWS_PER_PAGE_PORTRAIT, COLUMNS_PER_PAGE_LANDSCAPE, ROWS_PER_PAGE_LANDSCAPE, gIconCount, gSelectedIconIndex, gSelectedIconTexture, gHomeButton, gTargetPos, gPFTexNearest, gPFTexMip, gPFTexMipAlpha, gPVCurve, gPS, gSMCell, gIconIDs, gLabelIDs, vpConstants)
#pragma rs export_func(move, moveTo, setZoom, fling)
// Attraction to center values from page edge to page center.
@ -57,10 +47,12 @@ static float g_AttractionTable[9] = {20.f, 20.f, 20.f, 10.f, -10.f, -20.f, -20.f
static float g_FrictionTable[9] = {10.f, 10.f, 11.f, 15.f, 15.f, 11.f, 10.f, 10.f, 10.f};
static float g_PhysicsTableSize = 7;
static float gZoomTarget;
static float gTargetPos;
static float g_PosPage = 0.f;
static float g_PosVelocity = 0.f;
static float g_LastPositionX = 0.f;
static int g_LastTouchDown = 0;
static bool g_LastTouchDown = false;
static float g_DT;
static int64_t g_LastTime;
static int g_PosMax;
@ -79,14 +71,6 @@ static int g_Rows;
// Drawing constants, should be parameters ======
#define VIEW_ANGLE 1.28700222f
static int g_DrawLastFrame;
static int lastFrame(int draw) {
// We draw one extra frame to work around the last frame post bug.
// We also need to track if we drew the last frame to deal with large DT
// in the physics.
g_DrawLastFrame = draw;
return draw;
}
static void updateReadback() {
if ((g_OldPosPage != g_PosPage) ||
@ -105,16 +89,12 @@ static void updateReadback() {
}
}
void setColor(float r, float g, float b, float a) {
}
void init() {
}
void resetHWWar() {
}
void move() {
void move(float newPos) {
if (g_LastTouchDown) {
float dx = -(gNewPositionX - g_LastPositionX);
float dx = -(newPos - g_LastPositionX);
g_PosVelocity = 0;
g_PosPage += dx * 5.2f;
@ -122,26 +102,34 @@ void move() {
float pmax = g_PosMax + 0.49f;
g_PosPage = clamp(g_PosPage, pmin, pmax);
}
g_LastTouchDown = gNewTouchDown;
g_LastPositionX = gNewPositionX;
g_LastTouchDown = true;
g_LastPositionX = newPos;
g_MoveToTime = 0;
}
void moveTo() {
void moveTo(float targetPos) {
gTargetPos = targetPos;
g_MoveToTime = g_MoveToTotalTime;
g_PosVelocity = 0;
g_MoveToOldPos = g_PosPage;
}
void setZoom() {
g_Zoom = gZoomTarget;
g_DrawLastFrame = 1;
void setZoom(float z, /*bool*/ int animate) {
gZoomTarget = z;
if (gZoomTarget < 0.001f) {
gZoomTarget = 0;
}
if (!animate) {
g_Zoom = gZoomTarget;
}
updateReadback();
}
void fling() {
g_LastTouchDown = 0;
g_PosVelocity = -gFlingVelocity * 4;
void fling(float newPos, float vel) {
move(newPos);
g_LastTouchDown = false;
g_PosVelocity = -vel * 4;
float av = fabs(g_PosVelocity);
float minVel = 3.5f;
@ -347,13 +335,8 @@ int root()
g_DT = (newTime - g_LastTime) * 0.001f;
g_LastTime = newTime;
if (!g_DrawLastFrame) {
// If we stopped rendering we cannot use DT.
// assume 30fps in this case.
g_DT = 0.033f;
}
// physics may break if DT is large.
g_DT = min(g_DT, 0.2f);
g_DT = min(g_DT, 0.1f);
if (g_Zoom != gZoomTarget) {
float dz = g_DT * 1.7f;
@ -376,7 +359,7 @@ int root()
if (!g_LastTouchDown) {
g_PosPage = 0;
}
return lastFrame(0);
return 0;
} else {
rsgClearColor(0.0f, 0.0f, 0.0f, g_Zoom);
}
@ -403,7 +386,7 @@ int root()
rsgBindProgramFragment(gPFTexNearest);
draw_home_button();
return lastFrame((g_PosVelocity != 0) || rsFrac(g_PosPage) || g_Zoom != gZoomTarget || (g_MoveToTime != 0));
return (g_PosVelocity != 0) || rsFrac(g_PosPage) || g_Zoom != gZoomTarget || (g_MoveToTime != 0);
}

Binary file not shown.

View File

@ -268,19 +268,19 @@ public class AllApps3D extends RSSurfaceView
}
if (sRollo.mUniformAlloc != null) {
float tf[] = new float[] {120.f, 120.f, 0.f, 0.f,
(2.f / 480.f), 0, -((float)w / 2) - 0.25f, -380.25f,
120.f, 680.f,
72.f, 72.f,};
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) {
tf[6] = 40.f;
tf[7] = h - 40.f;
tf[9] = 1.f;
tf[10] = -((float)w / 2) - 0.25f;
tf[11] = -((float)h / 2) - 0.25f;
i.ScaleOffset.z = 40.f;
i.ScaleOffset.w = h - 40.f;
i.BendPos.y = 1.f;
}
sRollo.mUniformAlloc.getAllocation().data(tf);
sRollo.mUniformAlloc.set(i, 0, true);
}
//long endTime = SystemClock.uptimeMillis();
@ -601,9 +601,6 @@ public class AllApps3D extends RSSurfaceView
mMotionDownRawX = (int)ev.getRawX();
mMotionDownRawY = (int)ev.getRawY();
sRollo.mScript.set_gNewPositionX(ev.getRawY() / getHeight());
sRollo.mScript.set_gNewTouchDown(1);
if (!sRollo.checkClickOK()) {
sRollo.clearSelectedIcon();
} else {
@ -614,7 +611,7 @@ public class AllApps3D extends RSSurfaceView
cancelLongPress();
}
}
sRollo.move();
sRollo.move(ev.getRawY() / getHeight());
mVelocityTracker = VelocityTracker.obtain();
mVelocityTracker.addMovement(ev);
mStartedScrolling = false;
@ -647,9 +644,7 @@ public class AllApps3D extends RSSurfaceView
cancelLongPress();
mCurrentIconIndex = -1;
}
sRollo.mScript.set_gNewPositionX(ev.getRawY() / getHeight());
sRollo.mScript.set_gNewTouchDown(1);
sRollo.move();
sRollo.move(ev.getRawY() / getHeight());
mStartedScrolling = true;
sRollo.clearSelectedIcon();
@ -670,14 +665,10 @@ public class AllApps3D extends RSSurfaceView
}
mCurrentIconIndex = -1;
} else if (mTouchTracking == TRACKING_FLING) {
sRollo.mScript.set_gNewTouchDown(0);
sRollo.mScript.set_gNewPositionX(ev.getRawY() / getHeight());
mVelocityTracker.computeCurrentVelocity(1000 /* px/sec */, mMaxFlingVelocity);
sRollo.mScript.set_gFlingVelocity(mVelocityTracker.getYVelocity() / getHeight());
sRollo.clearSelectedIcon();
sRollo.move();
sRollo.fling();
sRollo.fling(ev.getRawY() / getHeight(),
mVelocityTracker.getYVelocity() / getHeight());
if (mVelocityTracker != null) {
mVelocityTracker.recycle();
@ -923,17 +914,6 @@ public class AllApps3D extends RSSurfaceView
return -1;
}
/*
private static int countPages(int iconCount) {
int iconsPerPage = getColumnsCount() * Defines.ROWS_PER_PAGE_PORTRAIT;
int pages = iconCount / iconsPerPage;
if (pages*iconsPerPage != iconCount) {
pages++;
}
return pages;
}
*/
class AAMessage extends RenderScript.RSMessage {
public void run() {
sRollo.mScrollPos = ((float)mData[0]) / (1 << 16);
@ -967,12 +947,6 @@ public class AllApps3D extends RSSurfaceView
private Resources mRes;
ScriptC_Allapps mScript;
//private ProgramStore mPSIcons;
private ProgramFragment mPFTexMip;
private ProgramFragment mPFTexMipAlpha;
private ProgramFragment mPFTexNearest;
private ProgramVertex mPV;
private ProgramVertex mPVCurve;
private SimpleMesh mMesh;
private ProgramVertex.MatrixAllocation mPVA;
@ -989,7 +963,6 @@ public class AllApps3D extends RSSurfaceView
private Allocation[] mLabels;
private int[] mLabelIds;
private Allocation mAllocLabelIds;
private Allocation mSelectedIcon;
private Bitmap mSelectionBitmap;
private Canvas mSelectionCanvas;
@ -1074,8 +1047,9 @@ public class AllApps3D extends RSSurfaceView
ProgramVertex.Builder pvb = new ProgramVertex.Builder(sRS, null, null);
pvb.setTextureMatrixEnable(true);
mPV = pvb.create();
mPV.bindAllocation(mPVA);
ProgramVertex pv = pvb.create();
pv.bindAllocation(mPVA);
sRS.contextBindProgramVertex(pv);
mUniformAlloc = new ScriptField_VpConsts(sRS, 1);
mScript.bind_vpConstants(mUniformAlloc);
@ -1141,12 +1115,11 @@ public class AllApps3D extends RSSurfaceView
sb.setShader(t);
sb.addConstant(mUniformAlloc.getType());
sb.addInput(mMesh.getVertexType(0).getElement());
mPVCurve = sb.create();
mPVCurve.bindAllocation(mPVA);
mPVCurve.bindConstants(mUniformAlloc.getAllocation(), 1);
ProgramVertex pvc = sb.create();
pvc.bindAllocation(mPVA);
pvc.bindConstants(mUniformAlloc.getAllocation(), 1);
sRS.contextBindProgramVertex(mPV);
mScript.set_gPVCurve(mPVCurve);
mScript.set_gPVCurve(pvc);
}
private void initProgramFragment() {
@ -1164,20 +1137,20 @@ public class AllApps3D extends RSSurfaceView
ProgramFragment.Builder bf = new ProgramFragment.Builder(sRS);
bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
ProgramFragment.Builder.Format.RGBA, 0);
mPFTexMip = bf.create();
mPFTexMip.bindSampler(linear, 0);
ProgramFragment pfTexMip = bf.create();
pfTexMip.bindSampler(linear, 0);
mPFTexNearest = bf.create();
mPFTexNearest.bindSampler(nearest, 0);
ProgramFragment pfTexNearest = bf.create();
pfTexNearest.bindSampler(nearest, 0);
bf.setTexture(ProgramFragment.Builder.EnvMode.MODULATE,
ProgramFragment.Builder.Format.ALPHA, 0);
mPFTexMipAlpha = bf.create();
mPFTexMipAlpha.bindSampler(linear, 0);
ProgramFragment pfTexMipAlpha = bf.create();
pfTexMipAlpha.bindSampler(linear, 0);
mScript.set_gPFTexNearest(mPFTexNearest);
mScript.set_gPFTexMip(mPFTexMip);
mScript.set_gPFTexMipAlpha(mPFTexMipAlpha);
mScript.set_gPFTexNearest(pfTexNearest);
mScript.set_gPFTexMip(pfTexMip);
mScript.set_gPFTexMipAlpha(pfTexMipAlpha);
}
private void initProgramStore() {
@ -1258,14 +1231,7 @@ public class AllApps3D extends RSSurfaceView
sRollo.clearSelectedIcon();
sRollo.setHomeSelected(SELECTED_NONE);
}
if (zoom > 0.001f) {
sRollo.mScript.set_gZoomTarget(zoom);
} else {
sRollo.mScript.set_gZoomTarget(0);
}
if (!animate) {
sRollo.mScript.invoke_setZoom();
}
sRollo.mScript.invoke_setZoom(zoom, animate ? 1 : 0);
}
private void createAppIconAllocations(int index, ApplicationInfo item) {
@ -1367,17 +1333,16 @@ public class AllApps3D extends RSSurfaceView
}
}
void fling() {
mScript.invoke_fling();
void fling(float pos, float v) {
mScript.invoke_fling(pos, v);
}
void move() {
mScript.invoke_move();
void move(float pos) {
mScript.invoke_move(pos);
}
void moveTo(float row) {
mScript.set_gTargetPos(row);
mScript.invoke_moveTo();
mScript.invoke_moveTo(row);
}
/**
@ -1426,10 +1391,10 @@ public class AllApps3D extends RSSurfaceView
selectionBitmap.getWidth(), selectionBitmap.getHeight(),
pressed == SELECTED_PRESSED, info.iconBitmap);
mSelectedIcon = Allocation.createFromBitmap(sRS, selectionBitmap,
Allocation si = Allocation.createFromBitmap(sRS, selectionBitmap,
Element.RGBA_8888(sRS), false);
mSelectedIcon.uploadToTexture(0);
mScript.set_gSelectedIconTexture(mSelectedIcon);
si.uploadToTexture(0);
mScript.set_gSelectedIconTexture(si);
if (prev != index) {
if (info.title != null && info.title.length() > 0) {

View File

@ -70,40 +70,7 @@ public class ScriptC_Allapps extends ScriptC {
return mExportVar_ROWS_PER_PAGE_LANDSCAPE;
}
private final static int mExportVarIdx_gNewPositionX = 4;
private float mExportVar_gNewPositionX;
public void set_gNewPositionX(float v) {
mExportVar_gNewPositionX = v;
setVar(mExportVarIdx_gNewPositionX, v);
}
public float get_gNewPositionX() {
return mExportVar_gNewPositionX;
}
private final static int mExportVarIdx_gNewTouchDown = 5;
private int mExportVar_gNewTouchDown;
public void set_gNewTouchDown(int v) {
mExportVar_gNewTouchDown = v;
setVar(mExportVarIdx_gNewTouchDown, v);
}
public int get_gNewTouchDown() {
return mExportVar_gNewTouchDown;
}
private final static int mExportVarIdx_gFlingVelocity = 6;
private float mExportVar_gFlingVelocity;
public void set_gFlingVelocity(float v) {
mExportVar_gFlingVelocity = v;
setVar(mExportVarIdx_gFlingVelocity, v);
}
public float get_gFlingVelocity() {
return mExportVar_gFlingVelocity;
}
private final static int mExportVarIdx_gIconCount = 7;
private final static int mExportVarIdx_gIconCount = 4;
private int mExportVar_gIconCount;
public void set_gIconCount(int v) {
mExportVar_gIconCount = v;
@ -114,7 +81,7 @@ public class ScriptC_Allapps extends ScriptC {
return mExportVar_gIconCount;
}
private final static int mExportVarIdx_gSelectedIconIndex = 8;
private final static int mExportVarIdx_gSelectedIconIndex = 5;
private int mExportVar_gSelectedIconIndex;
public void set_gSelectedIconIndex(int v) {
mExportVar_gSelectedIconIndex = v;
@ -125,7 +92,7 @@ public class ScriptC_Allapps extends ScriptC {
return mExportVar_gSelectedIconIndex;
}
private final static int mExportVarIdx_gSelectedIconTexture = 9;
private final static int mExportVarIdx_gSelectedIconTexture = 6;
private Allocation mExportVar_gSelectedIconTexture;
public void set_gSelectedIconTexture(Allocation v) {
mExportVar_gSelectedIconTexture = v;
@ -136,18 +103,7 @@ public class ScriptC_Allapps extends ScriptC {
return mExportVar_gSelectedIconTexture;
}
private final static int mExportVarIdx_gZoomTarget = 10;
private float mExportVar_gZoomTarget;
public void set_gZoomTarget(float v) {
mExportVar_gZoomTarget = v;
setVar(mExportVarIdx_gZoomTarget, v);
}
public float get_gZoomTarget() {
return mExportVar_gZoomTarget;
}
private final static int mExportVarIdx_gHomeButton = 11;
private final static int mExportVarIdx_gHomeButton = 7;
private Allocation mExportVar_gHomeButton;
public void set_gHomeButton(Allocation v) {
mExportVar_gHomeButton = v;
@ -158,18 +114,7 @@ public class ScriptC_Allapps extends ScriptC {
return mExportVar_gHomeButton;
}
private final static int mExportVarIdx_gTargetPos = 12;
private float mExportVar_gTargetPos;
public void set_gTargetPos(float v) {
mExportVar_gTargetPos = v;
setVar(mExportVarIdx_gTargetPos, v);
}
public float get_gTargetPos() {
return mExportVar_gTargetPos;
}
private final static int mExportVarIdx_gPFTexNearest = 13;
private final static int mExportVarIdx_gPFTexNearest = 8;
private ProgramFragment mExportVar_gPFTexNearest;
public void set_gPFTexNearest(ProgramFragment v) {
mExportVar_gPFTexNearest = v;
@ -180,7 +125,7 @@ public class ScriptC_Allapps extends ScriptC {
return mExportVar_gPFTexNearest;
}
private final static int mExportVarIdx_gPFTexMip = 14;
private final static int mExportVarIdx_gPFTexMip = 9;
private ProgramFragment mExportVar_gPFTexMip;
public void set_gPFTexMip(ProgramFragment v) {
mExportVar_gPFTexMip = v;
@ -191,7 +136,7 @@ public class ScriptC_Allapps extends ScriptC {
return mExportVar_gPFTexMip;
}
private final static int mExportVarIdx_gPFTexMipAlpha = 15;
private final static int mExportVarIdx_gPFTexMipAlpha = 10;
private ProgramFragment mExportVar_gPFTexMipAlpha;
public void set_gPFTexMipAlpha(ProgramFragment v) {
mExportVar_gPFTexMipAlpha = v;
@ -202,7 +147,7 @@ public class ScriptC_Allapps extends ScriptC {
return mExportVar_gPFTexMipAlpha;
}
private final static int mExportVarIdx_gPVCurve = 16;
private final static int mExportVarIdx_gPVCurve = 11;
private ProgramVertex mExportVar_gPVCurve;
public void set_gPVCurve(ProgramVertex v) {
mExportVar_gPVCurve = v;
@ -213,7 +158,7 @@ public class ScriptC_Allapps extends ScriptC {
return mExportVar_gPVCurve;
}
private final static int mExportVarIdx_gPS = 17;
private final static int mExportVarIdx_gPS = 12;
private ProgramStore mExportVar_gPS;
public void set_gPS(ProgramStore v) {
mExportVar_gPS = v;
@ -224,7 +169,7 @@ public class ScriptC_Allapps extends ScriptC {
return mExportVar_gPS;
}
private final static int mExportVarIdx_gSMCell = 18;
private final static int mExportVarIdx_gSMCell = 13;
private SimpleMesh mExportVar_gSMCell;
public void set_gSMCell(SimpleMesh v) {
mExportVar_gSMCell = v;
@ -235,7 +180,7 @@ public class ScriptC_Allapps extends ScriptC {
return mExportVar_gSMCell;
}
private final static int mExportVarIdx_gIconIDs = 19;
private final static int mExportVarIdx_gIconIDs = 14;
private Allocation mExportVar_gIconIDs;
public void bind_gIconIDs(Allocation v) {
mExportVar_gIconIDs = v;
@ -247,7 +192,7 @@ public class ScriptC_Allapps extends ScriptC {
return mExportVar_gIconIDs;
}
private final static int mExportVarIdx_gLabelIDs = 20;
private final static int mExportVarIdx_gLabelIDs = 15;
private Allocation mExportVar_gLabelIDs;
public void bind_gLabelIDs(Allocation v) {
mExportVar_gLabelIDs = v;
@ -259,7 +204,7 @@ public class ScriptC_Allapps extends ScriptC {
return mExportVar_gLabelIDs;
}
private final static int mExportVarIdx_vpConstants = 21;
private final static int mExportVarIdx_vpConstants = 16;
private ScriptField_VpConsts mExportVar_vpConstants;
public void bind_vpConstants(ScriptField_VpConsts v) {
mExportVar_vpConstants = v;
@ -271,29 +216,45 @@ public class ScriptC_Allapps extends ScriptC {
return mExportVar_vpConstants;
}
private final static int mExportFuncIdx_resetHWWar = 0;
public void invoke_resetHWWar() {
invoke(mExportFuncIdx_resetHWWar);
private final static int mExportVarIdx_gTargetPos = 17;
private float mExportVar_gTargetPos;
public void set_gTargetPos(float v) {
mExportVar_gTargetPos = v;
setVar(mExportVarIdx_gTargetPos, v);
}
private final static int mExportFuncIdx_move = 1;
public void invoke_move() {
invoke(mExportFuncIdx_move);
public float get_gTargetPos() {
return mExportVar_gTargetPos;
}
private final static int mExportFuncIdx_moveTo = 2;
public void invoke_moveTo() {
invoke(mExportFuncIdx_moveTo);
private final static int mExportFuncIdx_move = 0;
public void invoke_move(float newPos) {
FieldPacker move_fp = new FieldPacker(4);
move_fp.addF32(newPos);
invoke(mExportFuncIdx_move, move_fp);
}
private final static int mExportFuncIdx_setZoom = 3;
public void invoke_setZoom() {
invoke(mExportFuncIdx_setZoom);
private final static int mExportFuncIdx_moveTo = 1;
public void invoke_moveTo(float targetPos) {
FieldPacker moveTo_fp = new FieldPacker(4);
moveTo_fp.addF32(targetPos);
invoke(mExportFuncIdx_moveTo, moveTo_fp);
}
private final static int mExportFuncIdx_fling = 4;
public void invoke_fling() {
invoke(mExportFuncIdx_fling);
private final static int mExportFuncIdx_setZoom = 2;
public void invoke_setZoom(float z, int animate) {
FieldPacker setZoom_fp = new FieldPacker(8);
setZoom_fp.addF32(z);
setZoom_fp.addI32(animate);
invoke(mExportFuncIdx_setZoom, setZoom_fp);
}
private final static int mExportFuncIdx_fling = 3;
public void invoke_fling(float newPos, float vel) {
FieldPacker fling_fp = new FieldPacker(8);
fling_fp.addF32(newPos);
fling_fp.addF32(vel);
invoke(mExportFuncIdx_fling, fling_fp);
}
}

View File

@ -69,7 +69,7 @@ public class ScriptField_VpConsts extends android.renderscript.Script.FieldBase
mItemArray[index] = i;
if (copyNow) {
copyToArray(i, index);
mAllocation.subData1D(index * Item.sizeof, Item.sizeof, mIOBuffer.getData());
mAllocation.subData1D(index /** Item.sizeof*/, 1/*Item.sizeof*/, mIOBuffer.getData());
}
}