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/raw/rollo.c | 14 | ||||
-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 | 147 | ||||
-rw-r--r-- | libs/rs/java/Rollo/src/com/android/rollo/RolloView.java | 82 |
7 files changed, 461 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/raw/rollo.c b/libs/rs/java/Rollo/res/raw/rollo.c new file mode 100644 index 0000000..56ee425 --- /dev/null +++ b/libs/rs/java/Rollo/res/raw/rollo.c @@ -0,0 +1,14 @@ +#pragma version(1) +#pragma stateVertex(PV) +#pragma stateFragment(PF) +#pragma stateFragmentStore(PFSBackground) + +int main(void* con, int ft, int launchID) +{ + int x; + + renderTriangleMesh(con, NAMED_MeshCard); + renderTriangleMesh(con, NAMED_MeshTab); + return 1; +} + 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..da0b146 --- /dev/null +++ b/libs/rs/java/Rollo/src/com/android/rollo/RolloRS.java @@ -0,0 +1,147 @@ +/* + * 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(); + } + + + 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 mAllocEnv; + private RenderScript.Allocation mAllocPos; + private RenderScript.Allocation mAllocState; + //private RenderScript.Allocation mAllocPV; + private RenderScript.TriangleMesh mMeshCard; + private RenderScript.TriangleMesh mMeshTab; + + private float[] mBufferPos; + //private float[] mBufferPV; + + private void initNamed() { + mMeshTab = RolloMesh.createTab(mRS); + mMeshTab.setName("MeshTab"); + mMeshCard = RolloMesh.createCard(mRS); + mMeshCard.setName("MeshCard"); + Log.e("rs", "Done loading strips"); + + mRS.samplerBegin(); + mRS.samplerSet(RenderScript.SamplerParam.FILTER_MIN, + RenderScript.SamplerValue.LINEAR_MIP_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.programFragmentSetEnvMode(0, RS_TEX_ENV_MODE_REPLACE); + mPFImages = mRS.programFragmentCreate(); + mPFImages.setName("PF"); + mPFImages.bindSampler(mSampler, 0); + + mRS.programFragmentStoreBegin(null, null); + mRS.programFragmentStoreDepthFunc(RenderScript.DepthFunc.ALWAYS); + mRS.programFragmentStoreDitherEnable(true); + mPFSBackground = mRS.programFragmentStoreCreate(); + mPFSBackground.setName("PFSBackground"); + + /* + mRS.programFragmentStoreBegin(null, null); + mRS.programFragmentStoreDepthFunc(RenderScript.DepthFunc.EQUAL); + mRS.programFragmentStoreDitherEnable(false); + mRS.programFragmentStoreDepthMask(false); + mRS.programFragmentStoreBlendFunc(RenderScript.BlendSrcFunc.ONE, + RenderScript.BlendDstFunc.ONE); + mPFSImages = mRS.programFragmentStoreCreate(); + mPFSImages.setName("PFSImages"); +*/ + + + 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"); + } + + + private void initRS() { + mRS.scriptCBegin(); + mRS.scriptCSetClearColor(0.0f, 0.7f, 0.0f, 1.0f); + mRS.scriptCSetScript(mRes, R.raw.rollo); + mRS.scriptCSetRoot(true); + mScript = mRS.scriptCCreate(); + + + 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..9a30aed --- /dev/null +++ b/libs/rs/java/Rollo/src/com/android/rollo/RolloView.java @@ -0,0 +1,82 @@ +/* + * 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; + } + //mRender.newTouchPosition((int)ev.getX(), (int)ev.getY()); + return ret; + } +} + + |