diff options
Diffstat (limited to 'libs/rs/java/Rollo')
-rw-r--r-- | libs/rs/java/Rollo/Android.mk | 25 | ||||
-rw-r--r-- | libs/rs/java/Rollo/AndroidManifest.xml | 13 | ||||
-rw-r--r-- | libs/rs/java/Rollo/res/drawable/browser.png | bin | 0 -> 5772 bytes | |||
-rw-r--r-- | libs/rs/java/Rollo/res/drawable/market.png | bin | 0 -> 4810 bytes | |||
-rw-r--r-- | libs/rs/java/Rollo/res/drawable/photos.png | bin | 0 -> 4902 bytes | |||
-rw-r--r-- | libs/rs/java/Rollo/res/drawable/settings.png | bin | 0 -> 3764 bytes | |||
-rw-r--r-- | libs/rs/java/Rollo/res/raw/rollo.c | 60 | ||||
-rw-r--r-- | libs/rs/java/Rollo/src/com/android/rollo/Rollo.java | 90 | ||||
-rw-r--r-- | libs/rs/java/Rollo/src/com/android/rollo/RolloMesh.java | 90 | ||||
-rw-r--r-- | libs/rs/java/Rollo/src/com/android/rollo/RolloRS.java | 210 | ||||
-rw-r--r-- | libs/rs/java/Rollo/src/com/android/rollo/RolloView.java | 87 |
11 files changed, 575 insertions, 0 deletions
diff --git a/libs/rs/java/Rollo/Android.mk b/libs/rs/java/Rollo/Android.mk new file mode 100644 index 0000000..1c6dfdf --- /dev/null +++ b/libs/rs/java/Rollo/Android.mk @@ -0,0 +1,25 @@ +# +# Copyright (C) 2008 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := $(call all-java-files-under, src) +LOCAL_STATIC_JAVA_LIBRARIES := android.renderscript + +LOCAL_PACKAGE_NAME := Rollo + +include $(BUILD_PACKAGE) diff --git a/libs/rs/java/Rollo/AndroidManifest.xml b/libs/rs/java/Rollo/AndroidManifest.xml new file mode 100644 index 0000000..da160a3 --- /dev/null +++ b/libs/rs/java/Rollo/AndroidManifest.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.rollo"> + <application android:label="Rollo"> + <activity android:name="Rollo" + android:theme="@android:style/Theme.Black.NoTitleBar"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + </application> +</manifest> diff --git a/libs/rs/java/Rollo/res/drawable/browser.png b/libs/rs/java/Rollo/res/drawable/browser.png Binary files differnew file mode 100644 index 0000000..513f0be --- /dev/null +++ b/libs/rs/java/Rollo/res/drawable/browser.png diff --git a/libs/rs/java/Rollo/res/drawable/market.png b/libs/rs/java/Rollo/res/drawable/market.png Binary files differnew file mode 100644 index 0000000..83b6910 --- /dev/null +++ b/libs/rs/java/Rollo/res/drawable/market.png diff --git a/libs/rs/java/Rollo/res/drawable/photos.png b/libs/rs/java/Rollo/res/drawable/photos.png Binary files differnew file mode 100644 index 0000000..1ed8f1e --- /dev/null +++ b/libs/rs/java/Rollo/res/drawable/photos.png diff --git a/libs/rs/java/Rollo/res/drawable/settings.png b/libs/rs/java/Rollo/res/drawable/settings.png Binary files differnew file mode 100644 index 0000000..dd2cd95 --- /dev/null +++ b/libs/rs/java/Rollo/res/drawable/settings.png diff --git a/libs/rs/java/Rollo/res/raw/rollo.c b/libs/rs/java/Rollo/res/raw/rollo.c new file mode 100644 index 0000000..f181e49 --- /dev/null +++ b/libs/rs/java/Rollo/res/raw/rollo.c @@ -0,0 +1,60 @@ +#pragma version(1) +#pragma stateVertex(PV) +#pragma stateFragment(PF) +#pragma stateFragmentStore(PFS) + +int main(void* con, int ft, int launchID) +{ + int rowCount; + int x; + int y; + int row; + int col; + int imageID; + int tx1; + int ty1; + int tz1; + int tx2; + int ty2; + int tz2; + int rot; + int rotStep; + int tmpSin; + int tmpCos; + int iconCount; + int pressure; + + + rotStep = 20 * 0x10000; + pressure = loadI32(0, 2); + + rowCount = 4; + + iconCount = loadI32(0, 1); + rot = (-20 + loadI32(0, 0)) * 0x10000; + while (iconCount) { + tmpSin = sinx(rot); + tmpCos = cosx(rot); + + tx1 = tmpSin * 8 - tmpCos; + tx2 = tx1 + tmpCos * 2; + + tz1 = tmpCos * 8 + tmpSin + pressure; + tz2 = tz1 - tmpSin * 2; + + for (y = 0; (y < rowCount) && iconCount; y++) { + ty1 = (y * 0x30000) - 0x48000; + ty2 = ty1 + 0x20000; + pfBindTexture(NAMED_PF, 0, loadI32(1, y)); + drawQuad(tx1, ty1, tz1, + tx2, ty1, tz2, + tx2, ty2, tz2, + tx1, ty2, tz1); + iconCount--; + } + rot = rot + rotStep; + } + + return 0; +} + diff --git a/libs/rs/java/Rollo/src/com/android/rollo/Rollo.java b/libs/rs/java/Rollo/src/com/android/rollo/Rollo.java new file mode 100644 index 0000000..400d801 --- /dev/null +++ b/libs/rs/java/Rollo/src/com/android/rollo/Rollo.java @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rollo; + +import android.renderscript.RSSurfaceView; +import android.renderscript.RenderScript; + +import android.app.Activity; +import android.content.res.Configuration; +import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.os.Message; +import android.provider.Settings.System; +import android.util.Config; +import android.util.Log; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.view.Window; +import android.widget.Button; +import android.widget.ListView; + +import java.lang.Runtime; + +public class Rollo extends Activity { + //EventListener mListener = new EventListener(); + + private static final String LOG_TAG = "libRS_jni"; + private static final boolean DEBUG = false; + private static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV; + + private RolloView mView; + + // get the current looper (from your Activity UI thread for instance + + + + @Override + public void onCreate(Bundle icicle) { + super.onCreate(icicle); + + // Create our Preview view and set it as the content of our + // Activity + mView = new RolloView(this); + setContentView(mView); + } + + @Override + protected void onResume() { + // Ideally a game should implement onResume() and onPause() + // to take appropriate action when the activity looses focus + super.onResume(); + mView.onResume(); + } + + @Override + protected void onPause() { + // Ideally a game should implement onResume() and onPause() + // to take appropriate action when the activity looses focus + super.onPause(); + mView.onPause(); + + Runtime.getRuntime().exit(0); + } + + + static void log(String message) { + if (LOG_ENABLED) { + Log.v(LOG_TAG, message); + } + } + + +} + diff --git a/libs/rs/java/Rollo/src/com/android/rollo/RolloMesh.java b/libs/rs/java/Rollo/src/com/android/rollo/RolloMesh.java new file mode 100644 index 0000000..d7252fb --- /dev/null +++ b/libs/rs/java/Rollo/src/com/android/rollo/RolloMesh.java @@ -0,0 +1,90 @@ + /* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package com.android.rollo; + +import java.io.Writer; +import java.lang.Math; + +import android.renderscript.RenderScript; + + +class RolloMesh { + static public final float mCardHeight = 1.2f; + static public final float mCardWidth = 1.8f; + static public final float mTabHeight = 0.2f; + static public final float mTabs = 3; + static public final float mTabGap = 0.1f; + + static RenderScript.TriangleMesh createCard(RenderScript rs) { + RenderScript.Element vtx = rs.elementGetPredefined( + RenderScript.ElementPredefined.ST_XYZ_F32); + RenderScript.Element idx = rs.elementGetPredefined( + RenderScript.ElementPredefined.INDEX_16); + + float w = mCardWidth / 2; + float h = mCardHeight; + float z = 0; + + rs.triangleMeshBegin(vtx, idx); + rs.triangleMeshAddVertex_XYZ_ST(-w, 0, z, 0, 0); + rs.triangleMeshAddVertex_XYZ_ST(-w, h, z, 0, 1); + rs.triangleMeshAddVertex_XYZ_ST( w, h, z, 1, 1); + rs.triangleMeshAddVertex_XYZ_ST( w, 0, z, 1, 0); + rs.triangleMeshAddTriangle(0,1,2); + rs.triangleMeshAddTriangle(0,2,3); + return rs.triangleMeshCreate(); + } + + static RenderScript.TriangleMesh createTab(RenderScript rs) { + RenderScript.Element vtx = rs.elementGetPredefined( + RenderScript.ElementPredefined.ST_XYZ_F32); + RenderScript.Element idx = rs.elementGetPredefined( + RenderScript.ElementPredefined.INDEX_16); + + + float tabSlope = 0.1f; + float num = 0; + + float w = (mCardWidth - ((mTabs - 1) * mTabGap)) / mTabs; + float w1 = -(mCardWidth / 2) + ((w + mTabGap) * num); + float w2 = w1 + (w * tabSlope); + float w3 = w1 + w - (w * tabSlope); + float w4 = w1 + w; + float h1 = mCardHeight; + float h2 = h1 + mTabHeight; + float z = 0; + + float stScale = w / mTabHeight / 2; + float stScale2 = stScale * (tabSlope / w); + + + rs.triangleMeshBegin(vtx, idx); + rs.triangleMeshAddVertex_XYZ_ST(w1, h1, z, -stScale, 0); + rs.triangleMeshAddVertex_XYZ_ST(w2, h2, z, -stScale2, 1); + rs.triangleMeshAddVertex_XYZ_ST(w3, h2, z, stScale2, 1); + rs.triangleMeshAddVertex_XYZ_ST(w4, h1, z, stScale, 0); + rs.triangleMeshAddTriangle(0,1,2); + rs.triangleMeshAddTriangle(0,2,3); + return rs.triangleMeshCreate(); + } + + + +} + + diff --git a/libs/rs/java/Rollo/src/com/android/rollo/RolloRS.java b/libs/rs/java/Rollo/src/com/android/rollo/RolloRS.java new file mode 100644 index 0000000..91f25c2 --- /dev/null +++ b/libs/rs/java/Rollo/src/com/android/rollo/RolloRS.java @@ -0,0 +1,210 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rollo; + +import java.io.Writer; + +import android.renderscript.RenderScript; +import android.renderscript.ProgramVertexAlloc; + +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; +import android.os.Handler; +import android.os.Message; +import android.util.AttributeSet; +import android.util.Log; +import android.view.Surface; +import android.view.SurfaceHolder; +import android.view.SurfaceView; +import android.view.KeyEvent; +import android.view.MotionEvent; + +public class RolloRS { + + public RolloRS() { + } + + public void init(RenderScript rs, Resources res, int width, int height) { + mRS = rs; + mRes = res; + initNamed(); + initRS(); + } + + public void setPosition(float dx, float pressure) { + mAllocStateBuf[0] += (int)(dx); + mAllocStateBuf[2] = (int)(pressure * 0x40000); + mAllocState.data(mAllocStateBuf); + } + + + private Resources mRes; + private RenderScript mRS; + + + private RenderScript.Script mScript; + + private RenderScript.Sampler mSampler; + private RenderScript.ProgramFragmentStore mPFSBackground; + private RenderScript.ProgramFragmentStore mPFSImages; + private RenderScript.ProgramFragment mPFBackground; + private RenderScript.ProgramFragment mPFImages; + private RenderScript.ProgramVertex mPV; + private ProgramVertexAlloc mPVAlloc; + private RenderScript.Allocation[] mIcons; + private RenderScript.Allocation mIconPlate; + + private int[] mAllocStateBuf; + private RenderScript.Allocation mAllocState; + + private int[] mAllocIconIDBuf; + private RenderScript.Allocation mAllocIconID; + + private void initNamed() { + mRS.samplerBegin(); + mRS.samplerSet(RenderScript.SamplerParam.FILTER_MIN, + RenderScript.SamplerValue.LINEAR);//_MIP_LINEAR); + mRS.samplerSet(RenderScript.SamplerParam.FILTER_MAG, + RenderScript.SamplerValue.LINEAR); + mRS.samplerSet(RenderScript.SamplerParam.WRAP_MODE_S, + RenderScript.SamplerValue.CLAMP); + mRS.samplerSet(RenderScript.SamplerParam.WRAP_MODE_T, + RenderScript.SamplerValue.CLAMP); + mSampler = mRS.samplerCreate(); + + + mRS.programFragmentBegin(null, null); + mRS.programFragmentSetTexEnable(0, true); + //mRS.programFragmentSetTexEnable(1, true); + //mRS.programFragmentSetEnvMode(0, RS_TEX_ENV_MODE_REPLACE); + //mRS.programFragmentSetEnvMode(1, RS_TEX_ENV_MODE_MODULATE); + mPFImages = mRS.programFragmentCreate(); + mPFImages.setName("PF"); + mPFImages.bindSampler(mSampler, 0); + mPFImages.bindSampler(mSampler, 1); + + mRS.programFragmentStoreBegin(null, null); + mRS.programFragmentStoreDepthFunc(RenderScript.DepthFunc.ALWAYS); + mRS.programFragmentStoreDitherEnable(false); + mRS.programFragmentStoreDepthMask(false); + mRS.programFragmentStoreBlendFunc(RenderScript.BlendSrcFunc.ONE, + RenderScript.BlendDstFunc.ONE); + mPFSBackground = mRS.programFragmentStoreCreate(); + mPFSBackground.setName("PFS"); + + + mPVAlloc = new ProgramVertexAlloc(mRS); + mRS.programVertexBegin(null, null); + mRS.programVertexSetTextureMatrixEnable(true); + mPV = mRS.programVertexCreate(); + mPV.setName("PV"); + mPV.bindAllocation(0, mPVAlloc.mAlloc); + + + + mPVAlloc.setupProjectionNormalized(320, 480); + //mPVAlloc.setupOrthoNormalized(320, 480); + mRS.contextBindProgramVertex(mPV); + + + Log.e("rs", "Done loading named"); + + + { + mIcons = new RenderScript.Allocation[4]; + mAllocIconIDBuf = new int[mIcons.length]; + mAllocIconID = mRS.allocationCreatePredefSized( + RenderScript.ElementPredefined.USER_I32, mAllocIconIDBuf.length); + + + BitmapDrawable bd; + Bitmap b; + + bd = (BitmapDrawable)mRes.getDrawable(R.drawable.browser); + mIcons[0] = mRS.allocationCreateFromBitmap(bd.getBitmap(), RenderScript.ElementPredefined.RGB_565, true); + + bd = (BitmapDrawable)mRes.getDrawable(R.drawable.market); + mIcons[1] = mRS.allocationCreateFromBitmap(bd.getBitmap(), RenderScript.ElementPredefined.RGB_565, true); + + bd = (BitmapDrawable)mRes.getDrawable(R.drawable.photos); + mIcons[2] = mRS.allocationCreateFromBitmap(bd.getBitmap(), RenderScript.ElementPredefined.RGB_565, true); + + bd = (BitmapDrawable)mRes.getDrawable(R.drawable.settings); + mIcons[3] = mRS.allocationCreateFromBitmap(bd.getBitmap(), RenderScript.ElementPredefined.RGB_565, true); + + for(int ct=0; ct < mIcons.length; ct++) { + mIcons[ct].uploadToTexture(0); + mAllocIconIDBuf[ct] = mIcons[ct].getID(); + } + mAllocIconID.data(mAllocIconIDBuf); + + RenderScript.Element e = mRS.elementGetPredefined(RenderScript.ElementPredefined.RGB_565); + mRS.typeBegin(e); + mRS.typeAdd(RenderScript.Dimension.X, 64); + mRS.typeAdd(RenderScript.Dimension.Y, 64); + RenderScript.Type t = mRS.typeCreate(); + mIconPlate = mRS.allocationCreateTyped(t); + //t.destroy(); + //e.destroy(); + + int tmp[] = new int[64 * 32]; + for(int ct = 0; ct < (64*32); ct++) { + tmp[ct] = 7 | (13 << 5) | (7 << 11); + tmp[ct] = tmp[ct] | (tmp[ct] << 16); + } + for(int ct = 0; ct < 32; ct++) { + tmp[ct] = 0; + tmp[ct + (63*32)] = 0; + } + for(int ct = 0; ct < 64; ct++) { + tmp[ct * 32] = 0; + tmp[ct * 32 + 31] = 0; + } + mIconPlate.data(tmp); + Log.e("xx", "plate"); + mIconPlate.uploadToTexture(0); + mIconPlate.setName("Plate"); + mPFImages.bindTexture(mIconPlate, 0); + } + + } + + + + private void initRS() { + mRS.scriptCBegin(); + mRS.scriptCSetClearColor(0.0f, 0.0f, 0.1f, 1.0f); + mRS.scriptCSetScript(mRes, R.raw.rollo); + mRS.scriptCSetRoot(true); + mScript = mRS.scriptCCreate(); + + mAllocStateBuf = new int[] {0, 38, 0}; + mAllocState = mRS.allocationCreatePredefSized( + RenderScript.ElementPredefined.USER_I32, mAllocStateBuf.length); + mScript.bindAllocation(mAllocState, 0); + mScript.bindAllocation(mAllocIconID, 1); + setPosition(0, 0); + + mRS.contextBindRootScript(mScript); + } +} + + + diff --git a/libs/rs/java/Rollo/src/com/android/rollo/RolloView.java b/libs/rs/java/Rollo/src/com/android/rollo/RolloView.java new file mode 100644 index 0000000..27d2dd6 --- /dev/null +++ b/libs/rs/java/Rollo/src/com/android/rollo/RolloView.java @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.rollo; + +import java.io.Writer; +import java.util.ArrayList; +import java.util.concurrent.Semaphore; + +import android.renderscript.RSSurfaceView; +import android.renderscript.RenderScript; + +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; +import android.os.Handler; +import android.os.Message; +import android.util.AttributeSet; +import android.util.Log; +import android.view.Surface; +import android.view.SurfaceHolder; +import android.view.SurfaceView; +import android.view.KeyEvent; +import android.view.MotionEvent; + +public class RolloView extends RSSurfaceView { + + public RolloView(Context context) { + super(context); + + //setFocusable(true); + } + + private RenderScript mRS; + private RolloRS mRender; + + public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { + super.surfaceChanged(holder, format, w, h); + + mRS = createRenderScript(); + mRender = new RolloRS(); + mRender.init(mRS, getResources(), w, h); + } + + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) + { + // break point at here + // this method doesn't work when 'extends View' include 'extends ScrollView'. + return super.onKeyDown(keyCode, event); + } + + + @Override + public boolean onTouchEvent(MotionEvent ev) + { + boolean ret = true; + int act = ev.getAction(); + if (act == ev.ACTION_UP) { + ret = false; + } + float x = ev.getX(); + x = (x - 180) / 40; + //Log.e("rs", Float(x).toString()); + + mRender.setPosition(x, ev.getPressure()); + //mRender.newTouchPosition((int)ev.getX(), (int)ev.getY()); + return ret; + } +} + + |