Use rs support for object loading.
diff --git a/res/raw/rollo.c b/res/raw/rollo.c
index d7df6b9..5ff3308 100644
--- a/res/raw/rollo.c
+++ b/res/raw/rollo.c
@@ -5,40 +5,15 @@
#define PI 3.14159f
-// Variables from java ======
-
-// Parameters ======
-#define PARAM_BUBBLE_WIDTH 0
-#define PARAM_BUBBLE_HEIGHT 1
-#define PARAM_BUBBLE_BITMAP_WIDTH 2
-#define PARAM_BUBBLE_BITMAP_HEIGHT 3
-#define PARAM_SCROLL_HANDLE_ID 4
-#define PARAM_SCROLL_HANDLE_TEX_WIDTH 5
-#define PARAM_SCROLL_HANDLE_TEX_HEIGHT 6
-
-// State ======
-#define STATE_ICON_COUNT 0
-#define STATE_SCROLL_X 1
-#define STATE_FLING_TIME 2
-#define STATE_FLING_VELOCITY_X 3
-#define STATE_ADJUSTED_DECELERATION 4
-
-/* with fling offset applied */
-#define STATE_CURRENT_SCROLL_X 5
-
-#define STATE_FLING_DURATION 6
-#define STATE_FLING_END_POS 7
-
-#define STATE_START_SCROLL_X 8
-#define STATE_SELECTED_ICON_INDEX 9
-#define STATE_SELECTED_ICON_TEXTURE 10
-
-#define STATE_VISIBLE 11
-#define STATE_ZOOM 12
+float deceleration;
// Drawing constants, should be parameters ======
#define VIEW_ANGLE 1.28700222f
+void init() {
+ deceleration = 0;
+}
+
int g_lastFrameTime = 0;
void print_frame_rate()
{
@@ -78,7 +53,7 @@
int row;
int col;
- float scale = 1.0f - loadI32(ALLOC_STATE, STATE_ZOOM)/100000.0f;
+ float scale = 1.0f - state->zoom;
float iconTextureWidth = ICON_WIDTH_PX / (float)ICON_TEXTURE_WIDTH_PX;
float iconTextureHeight = ICON_HEIGHT_PX / (float)ICON_TEXTURE_HEIGHT_PX;
@@ -91,16 +66,11 @@
float farIconTextureSize = far_size(2 * ICON_TEXTURE_WIDTH_PX / (float)SCREEN_WIDTH_PX);
- float labelWidthPx = loadI32(ALLOC_PARAMS, PARAM_BUBBLE_WIDTH);
- float labelHeightPx = loadI32(ALLOC_PARAMS, PARAM_BUBBLE_HEIGHT);
-
- float normalizedLabelWidth = 2 * labelWidthPx / (float)SCREEN_WIDTH_PX;
+ float normalizedLabelWidth = 2 * params->bubbleWidth / (float)SCREEN_WIDTH_PX;
float farLabelWidth = far_size(normalizedLabelWidth);
- float farLabelHeight = far_size(labelHeightPx * (normalizedLabelWidth / labelWidthPx));
- float labelTextureWidth = labelWidthPx / loadI32(ALLOC_PARAMS, PARAM_BUBBLE_BITMAP_WIDTH);
- float labelTextureHeight = labelHeightPx / loadI32(ALLOC_PARAMS, PARAM_BUBBLE_BITMAP_HEIGHT);
-
- int selectedIconIndex = loadI32(ALLOC_STATE, STATE_SELECTED_ICON_INDEX);
+ float farLabelHeight = far_size(params->bubbleHeight * (normalizedLabelWidth / params->bubbleWidth));
+ float labelTextureWidth = (float)params->bubbleWidth / params->bubbleBitmapWidth;
+ float labelTextureHeight = (float)params->bubbleHeight / params->bubbleBitmapHeight;
for (row=0; row<ROWS_PER_PAGE && icon<=lastIcon; row++) {
float angle = centerAngle;
@@ -131,8 +101,8 @@
float iconLeftZ = centerZ + (sine * farIconTextureSize * .5);
float iconRightZ = centerZ - (sine * farIconTextureSize * .5);
- if (selectedIconIndex == icon) {
- bindTexture(NAMED_PF, 0, loadI32(ALLOC_STATE, STATE_SELECTED_ICON_TEXTURE));
+ if (state->selectedIconIndex == icon) {
+ bindTexture(NAMED_PF, 0, state->selectedIconTexture);
drawQuadTexCoords(
iconLeftX, iconTextureTop, iconLeftZ, 0.0f, 0.0f,
iconRightX, iconTextureTop, iconRightZ, 1.0f, 0.0f,
@@ -173,15 +143,15 @@
pfClearColor(0.0f, 0.0f, 0.0f, 0.0f);
// If we're not supposed to be showing, don't do anything.
- if (!loadI32(ALLOC_STATE, STATE_VISIBLE)) {
+ if (!state->visible) {
return 0;
}
// icons & labels
- int iconCount = loadI32(ALLOC_STATE, STATE_ICON_COUNT);
+ int iconCount = state->iconCount;
int pageCount = count_pages(iconCount);
- float scrollXPx = loadI32(ALLOC_STATE, STATE_SCROLL_X);
+ float scrollXPx = state->scrollX;
float maxScrollXPx = -(pageCount-1) * SCREEN_WIDTH_PX;
int done = 0;
@@ -194,11 +164,10 @@
}
// If we've been given a velocity, start a fling
- float flingVelocityPxMs = loadI32(ALLOC_STATE, STATE_FLING_VELOCITY_X);
+ float flingVelocityPxMs = state->flingVelocityX;
if (flingVelocityPxMs != 0) {
// how many screens will this velocity do? TODO: use long
// G * ppi * friction // why G? // friction = 0.015
- float deceleration = loadF(ALLOC_STATE, STATE_ADJUSTED_DECELERATION);
float flingDurationMs;
if (deceleration == 0) {
// On the first frame, calculate which animation we're going to do. If it's
@@ -264,18 +233,16 @@
endPos = scrollXPx + (flingVelocityPxMs*flingDurationMs)
+ ((deceleration*flingDurationMs*flingDurationMs)/2);
- storeF(ALLOC_STATE, STATE_ADJUSTED_DECELERATION, deceleration);
- storeF(ALLOC_STATE, STATE_FLING_DURATION, flingDurationMs);
- storeF(ALLOC_STATE, STATE_FLING_END_POS, endPos);
+ state->flingDuration = flingDurationMs;
+ state->flingEndPos = endPos;
} else {
- flingDurationMs = loadF(ALLOC_STATE, STATE_FLING_DURATION);
+ flingDurationMs = state->flingDuration;
}
// adjust the deceleration so we always hit a page boundary
- int flingTime = loadI32(ALLOC_STATE, STATE_FLING_TIME);
int now = uptimeMillis();
- float elapsedTime = (now - flingTime) / 1000.0f;
+ float elapsedTime = (now - state->flingTimeMs) / 1000.0f;
int animEndTime = -flingVelocityPxMs / deceleration;
int flingOffsetPx = (flingVelocityPxMs * elapsedTime)
@@ -283,7 +250,7 @@
scrollXPx += flingOffsetPx;
if (elapsedTime > flingDurationMs) {
- scrollXPx = loadF(ALLOC_STATE, STATE_FLING_END_POS);
+ scrollXPx = state->flingEndPos;
done = 1;
}
} else {
@@ -297,12 +264,12 @@
if (scrollXPx < maxScrollXPx) {
scrollXPx = maxScrollXPx;
}
-
- storeI32(ALLOC_STATE, STATE_CURRENT_SCROLL_X, scrollXPx);
+
+ state->currentScrollX = scrollXPx;
if (done) {
- storeI32(ALLOC_STATE, STATE_SCROLL_X, scrollXPx);
- storeI32(ALLOC_STATE, STATE_FLING_VELOCITY_X, 0);
- storeF(ALLOC_STATE, STATE_ADJUSTED_DECELERATION, 0);
+ state->scrollX = scrollXPx;
+ state->flingVelocityX = 0;
+ deceleration = 0.f;
}
// Draw the icons ========================================
@@ -324,7 +291,7 @@
draw_page(icon, lastIcon, -VIEW_ANGLE*currentPagePosition);
draw_page(icon+iconsPerPage, lastIcon, (-VIEW_ANGLE*currentPagePosition)+VIEW_ANGLE);
-
+
// Draw the border lines for debugging ========================================
/*
bindProgramVertex(NAMED_PVOrtho);
diff --git a/src/com/android/launcher2/AllAppsView.java b/src/com/android/launcher2/AllAppsView.java
index 2199432..7c7de15 100644
--- a/src/com/android/launcher2/AllAppsView.java
+++ b/src/com/android/launcher2/AllAppsView.java
@@ -28,6 +28,7 @@
import android.renderscript.ProgramVertex;
import android.renderscript.Element;
import android.renderscript.Allocation;
+import android.renderscript.Type;
import android.renderscript.Script;
import android.renderscript.ScriptC;
import android.renderscript.ProgramFragment;
@@ -104,7 +105,7 @@
public static final int COLUMNS_PER_PAGE = 4;
public static final int ROWS_PER_PAGE = 4;
-
+
public static final float RADIUS = 4.0f;
public static final int SCREEN_WIDTH_PX = 480;
@@ -199,7 +200,6 @@
(-mRollo.mState.startScrollX / Defines.SCREEN_WIDTH_PX));
}
mRollo.mState.flingVelocityX = 0;
- mRollo.mState.adjustedDeceleration = 0;
mRollo.mState.save();
mVelocity = VelocityTracker.obtain();
mVelocity.addMovement(ev);
@@ -282,15 +282,13 @@
public void onDropCompleted(View target, boolean success) {
}
- private static final int SCALE_SCALE = 100000;
-
public void setScale(float amount) {
cancelLongPress();
mRollo.mState.read();
mRollo.clearSelectedIcon();
if (amount > 0.001f) {
mRollo.mState.visible = 1;
- mRollo.mState.zoom = (int)(SCALE_SCALE*amount);
+ mRollo.mState.zoom = amount;
} else {
mRollo.mState.visible = 0;
mRollo.mState.zoom = 0;
@@ -390,36 +388,53 @@
Params mParams;
State mState;
- class Params extends IntAllocation {
- Params(RenderScript rs) {
- super(rs);
+ class BaseAlloc {
+ Allocation mAlloc;
+ Type mType;
+
+ void save() {
+ mAlloc.data(this);
}
- @AllocationIndex(0) public int bubbleWidth;
- @AllocationIndex(1) public int bubbleHeight;
- @AllocationIndex(2) public int bubbleBitmapWidth;
- @AllocationIndex(3) public int bubbleBitmapHeight;
- @AllocationIndex(4) public int scrollHandleId;
- @AllocationIndex(5) public int scrollHandleTextureWidth;
- @AllocationIndex(6) public int scrollHandleTextureHeight;
+
+ void read() {
+ mAlloc.read(this);
+ }
}
- class State extends IntAllocation {
- State(RenderScript rs) {
- super(rs);
+ class Params extends BaseAlloc {
+ Params() {
+ mType = Type.createFromClass(mRS, Params.class, 1, "ParamsClass");
+ mAlloc = Allocation.createTyped(mRS, mType);
+ save();
}
- @AllocationIndex(0) public int iconCount;
- @AllocationIndex(1) public int scrollX;
- @AllocationIndex(2) public int flingTimeMs;
- @AllocationIndex(3) public int flingVelocityX;
- @AllocationIndex(4) public int adjustedDeceleration;
- @AllocationIndex(5) public int currentScrollX;
- @AllocationIndex(6) public int flingDuration;
- @AllocationIndex(7) public int flingEndPos;
- @AllocationIndex(8) public int startScrollX;
- @AllocationIndex(9) public int selectedIconIndex = -1;
- @AllocationIndex(10) public int selectedIconTexture;
- @AllocationIndex(11) public int visible;
- @AllocationIndex(12) public int zoom;
+ public int bubbleWidth;
+ public int bubbleHeight;
+ public int bubbleBitmapWidth;
+ public int bubbleBitmapHeight;
+ public int scrollHandleId;
+ public int scrollHandleTextureWidth;
+ public int scrollHandleTextureHeight;
+ }
+
+ class State extends BaseAlloc {
+ public int iconCount;
+ public int scrollX;
+ public int flingTimeMs;
+ public float flingVelocityX;
+ public int currentScrollX;
+ public int flingDuration;
+ public int flingEndPos;
+ public int startScrollX;
+ public int selectedIconIndex = -1;
+ public int selectedIconTexture;
+ public int visible;
+ public float zoom;
+
+ State() {
+ mType = Type.createFromClass(mRS, State.class, 1, "StateClass");
+ mAlloc = Allocation.createTyped(mRS, mType);
+ save();
+ }
}
public RolloRS() {
@@ -510,10 +525,10 @@
Log.e("rs", "Done loading named");
}
-
+
private void initData() {
- mParams = new Params(mRS);
- mState = new State(mRS);
+ mParams = new Params();
+ mState = new State();
final Utilities.BubbleText bubble = new Utilities.BubbleText(getContext());
@@ -547,11 +562,13 @@
sb.setScript(mRes, R.raw.rollo);
sb.setRoot(true);
sb.addDefines(Defines.class);
+ sb.setType(mParams.mType, "params", Defines.ALLOC_PARAMS);
+ sb.setType(mState.mType, "state", Defines.ALLOC_STATE);
mScript = sb.create();
mScript.setClearColor(0.0f, 0.0f, 0.0f, 0.0f);
- mScript.bindAllocation(mParams.getAllocation(), Defines.ALLOC_PARAMS);
- mScript.bindAllocation(mState.getAllocation(), Defines.ALLOC_STATE);
+ mScript.bindAllocation(mParams.mAlloc, Defines.ALLOC_PARAMS);
+ mScript.bindAllocation(mState.mAlloc, Defines.ALLOC_STATE);
mScript.bindAllocation(mAllocIconID, Defines.ALLOC_ICON_IDS);
mScript.bindAllocation(mAllocLabelID, Defines.ALLOC_LABEL_IDS);
mScript.bindAllocation(mAllocTouchXBorders, Defines.ALLOC_X_BORDERS);
@@ -628,7 +645,7 @@
mTouchYBorders[4] = centerY + (int)(2.4f * cellHeight);
mAllocTouchYBorders.data(mTouchYBorders);
-
+
int centerX = (width / 2);
mTouchXBorders[0] = centerX - (2 * cellWidth);
mTouchXBorders[1] = centerX - (int)(0.83f * cellWidth);;
@@ -660,7 +677,7 @@
return -1;
}
- return (currentPage * Defines.ROWS_PER_PAGE * Defines.COLUMNS_PER_PAGE)
+ return (currentPage * Defines.ROWS_PER_PAGE * Defines.COLUMNS_PER_PAGE)
+ (row * Defines.ROWS_PER_PAGE) + col;
}