summaryrefslogtreecommitdiffstats
path: root/libs/rs/java/Fountain
diff options
context:
space:
mode:
authorJason Sams <rjsams@android.com>2009-06-11 14:46:10 -0700
committerJason Sams <rjsams@android.com>2009-06-11 14:46:10 -0700
commit1fe9b8c3bdc55e624edc1a69c3f3f0b9e90af1e4 (patch)
tree42adcba1bf20cb1b27cf5a8d1026695f222627d2 /libs/rs/java/Fountain
parentd5680f9ba95ec7ce212e8025774914e79982a1ee (diff)
downloadframeworks_base-1fe9b8c3bdc55e624edc1a69c3f3f0b9e90af1e4.zip
frameworks_base-1fe9b8c3bdc55e624edc1a69c3f3f0b9e90af1e4.tar.gz
frameworks_base-1fe9b8c3bdc55e624edc1a69c3f3f0b9e90af1e4.tar.bz2
Split FountainView into View and RS parts. Beging adding ProgramVertex to the java api. It was already implemented in native.
Diffstat (limited to 'libs/rs/java/Fountain')
-rw-r--r--libs/rs/java/Fountain/res/raw/fountain.c1
-rw-r--r--libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java140
-rw-r--r--libs/rs/java/Fountain/src/com/android/fountain/FountainView.java112
3 files changed, 146 insertions, 107 deletions
diff --git a/libs/rs/java/Fountain/res/raw/fountain.c b/libs/rs/java/Fountain/res/raw/fountain.c
index e7920fd..3bd9496 100644
--- a/libs/rs/java/Fountain/res/raw/fountain.c
+++ b/libs/rs/java/Fountain/res/raw/fountain.c
@@ -35,7 +35,6 @@ int main(void* con, int ft, int launchID) {
}
}
- //contextBindProgramFragment(con, loadI32(con, 0, 7));
drawRect(con, 0, 256, 0, 512);
contextBindProgramFragment(con, NAMED_PgmFragParts);
diff --git a/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java b/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java
new file mode 100644
index 0000000..ceb94d1
--- /dev/null
+++ b/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java
@@ -0,0 +1,140 @@
+/*
+ * 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.fountain;
+
+import java.io.Writer;
+
+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.util.AttributeSet;
+import android.util.Log;
+
+public class FountainRS {
+
+ public FountainRS() {
+ }
+
+ public void init(RenderScript rs, Resources res, int width, int height) {
+ mRS = rs;
+ mRes = res;
+ initRS();
+ }
+
+ public void newTouchPosition(int x, int y) {
+ mParams[0] = 1;
+ mParams[1] = x;
+ mParams[2] = y;
+ mIntAlloc.subData1D(2, 3, mParams);
+ }
+
+
+ /////////////////////////////////////////
+
+ private Resources mRes;
+
+ private RenderScript mRS;
+ private RenderScript.Allocation mIntAlloc;
+ private RenderScript.Allocation mPartAlloc;
+ private RenderScript.Allocation mVertAlloc;
+ private RenderScript.Script mScript;
+ private RenderScript.ProgramFragmentStore mPFS;
+ private RenderScript.ProgramFragment mPF;
+ private RenderScript.ProgramFragment mPF2;
+ private RenderScript.Allocation mTexture;
+ private RenderScript.Sampler mSampler;
+
+ private Bitmap mBackground;
+
+ int mParams[] = new int[10];
+
+ private void initRS() {
+ int partCount = 1024;
+
+ mIntAlloc = mRS.allocationCreatePredefSized(RenderScript.ElementPredefined.USER_I32, 10);
+ mPartAlloc = mRS.allocationCreatePredefSized(RenderScript.ElementPredefined.USER_I32, partCount * 3 * 3);
+ mPartAlloc.setName("PartBuffer");
+ mVertAlloc = mRS.allocationCreatePredefSized(RenderScript.ElementPredefined.USER_I32, partCount * 5 + 1);
+
+ {
+ Drawable d = mRes.getDrawable(R.drawable.gadgets_clock_mp3);
+ BitmapDrawable bd = (BitmapDrawable)d;
+ Bitmap b = bd.getBitmap();
+ mTexture = mRS.allocationCreateFromBitmap(b,
+ RenderScript.ElementPredefined.RGB_565,
+ true);
+ mTexture.uploadToTexture(0);
+ }
+
+ mRS.programFragmentStoreBegin(null, null);
+ mRS.programFragmentStoreBlendFunc(RenderScript.BlendSrcFunc.SRC_ALPHA, RenderScript.BlendDstFunc.ONE);
+ mRS.programFragmentStoreDepthFunc(RenderScript.DepthFunc.ALWAYS);
+ mPFS = mRS.programFragmentStoreCreate();
+ mPFS.setName("MyBlend");
+ mRS.contextBindProgramFragmentStore(mPFS);
+
+ mRS.samplerBegin();
+ mRS.samplerSet(RenderScript.SamplerParam.FILTER_MAG, RenderScript.SamplerValue.LINEAR);
+ mRS.samplerSet(RenderScript.SamplerParam.FILTER_MIN, RenderScript.SamplerValue.LINEAR);
+ mSampler = mRS.samplerCreate();
+
+
+ mRS.programFragmentBegin(null, null);
+ mPF = mRS.programFragmentCreate();
+ mPF.setName("PgmFragParts");
+
+ mRS.programFragmentBegin(null, null);
+ mRS.programFragmentSetTexEnable(0, true);
+ mPF2 = mRS.programFragmentCreate();
+ mRS.contextBindProgramFragment(mPF2);
+ mPF2.bindTexture(mTexture, 0);
+ mPF2.bindSampler(mSampler, 0);
+ mPF2.setName("PgmFragBackground");
+
+ mParams[0] = 0;
+ mParams[1] = partCount;
+ mParams[2] = 0;
+ mParams[3] = 0;
+ mParams[4] = 0;
+ mIntAlloc.data(mParams);
+
+ int t2[] = new int[partCount * 4*3];
+ for (int ct=0; ct < t2.length; ct++) {
+ t2[ct] = 0;
+ }
+ mPartAlloc.data(t2);
+
+ mRS.scriptCBegin();
+ mRS.scriptCSetClearColor(0.0f, 0.0f, 0.0f, 1.0f);
+ mRS.scriptCSetScript(mRes, R.raw.fountain);
+ mRS.scriptCSetRoot(true);
+ mScript = mRS.scriptCCreate();
+
+ mScript.bindAllocation(mIntAlloc, 0);
+ mScript.bindAllocation(mPartAlloc, 1);
+ mScript.bindAllocation(mVertAlloc, 2);
+ mRS.contextBindRootScript(mScript);
+ }
+
+}
+
+
diff --git a/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java b/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java
index 46f6fca..be8b24e 100644
--- a/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java
+++ b/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java
@@ -47,126 +47,26 @@ public class FountainView extends RSSurfaceView {
}
private RenderScript mRS;
- private RenderScript.Allocation mIntAlloc;
- private RenderScript.Allocation mPartAlloc;
- private RenderScript.Allocation mVertAlloc;
- private RenderScript.Script mScript;
- private RenderScript.ProgramFragmentStore mPFS;
- private RenderScript.ProgramFragment mPF;
- private RenderScript.ProgramFragment mPF2;
- private RenderScript.Allocation mTexture;
- private RenderScript.Sampler mSampler;
-
- private Bitmap mBackground;
-
- int mParams[] = new int[10];
-
- private void initRS() {
- mRS = createRenderScript();
-
- int partCount = 1024;
-
- mIntAlloc = mRS.allocationCreatePredefSized(RenderScript.ElementPredefined.USER_I32, 10);
- mPartAlloc = mRS.allocationCreatePredefSized(RenderScript.ElementPredefined.USER_I32, partCount * 3 * 3);
- mPartAlloc.setName("PartBuffer");
- mVertAlloc = mRS.allocationCreatePredefSized(RenderScript.ElementPredefined.USER_I32, partCount * 5 + 1);
-
- {
- Resources res = getResources();
- Drawable d = res.getDrawable(R.drawable.gadgets_clock_mp3);
- BitmapDrawable bd = (BitmapDrawable)d;
- Bitmap b = bd.getBitmap();
- mTexture = mRS.allocationCreateFromBitmap(b,
- RenderScript.ElementPredefined.RGB_565,
- true);
- mTexture.uploadToTexture(0);
- }
-
- mRS.programFragmentStoreBegin(null, null);
- mRS.programFragmentStoreBlendFunc(RenderScript.BlendSrcFunc.SRC_ALPHA, RenderScript.BlendDstFunc.ONE);
- mRS.programFragmentStoreDepthFunc(RenderScript.DepthFunc.ALWAYS);
- mPFS = mRS.programFragmentStoreCreate();
- mPFS.setName("MyBlend");
- mRS.contextBindProgramFragmentStore(mPFS);
-
- mRS.samplerBegin();
- mRS.samplerSet(RenderScript.SamplerParam.FILTER_MAG, RenderScript.SamplerValue.LINEAR);
- mRS.samplerSet(RenderScript.SamplerParam.FILTER_MIN, RenderScript.SamplerValue.LINEAR);
- mSampler = mRS.samplerCreate();
-
-
- mRS.programFragmentBegin(null, null);
- mPF = mRS.programFragmentCreate();
- mPF.setName("PgmFragParts");
-
- mRS.programFragmentBegin(null, null);
- mRS.programFragmentSetTexEnable(0, true);
- mPF2 = mRS.programFragmentCreate();
- mRS.contextBindProgramFragment(mPF2);
- mPF2.bindTexture(mTexture, 0);
- mPF2.bindSampler(mSampler, 0);
- mPF2.setName("PgmFragBackground");
-
- mParams[0] = 0;
- mParams[1] = partCount;
- mParams[2] = 0;
- mParams[3] = 0;
- mParams[4] = 0;
- mParams[5] = mPartAlloc.getID();
- mIntAlloc.data(mParams);
-
- int t2[] = new int[partCount * 4*3];
- for (int ct=0; ct < t2.length; ct++) {
- t2[ct] = 0;
- }
- mPartAlloc.data(t2);
-
- mRS.scriptCBegin();
- mRS.scriptCSetClearColor(0.0f, 0.0f, 0.0f, 1.0f);
- mRS.scriptCSetScript(getResources(), R.raw.fountain);
- mRS.scriptCSetRoot(true);
- mScript = mRS.scriptCCreate();
-
- mScript.bindAllocation(mIntAlloc, 0);
- mScript.bindAllocation(mPartAlloc, 1);
- mScript.bindAllocation(mVertAlloc, 2);
- mRS.contextBindRootScript(mScript);
-
- }
+ private FountainRS mRender;
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
super.surfaceChanged(holder, format, w, h);
- initRS();
- }
-
- @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);
+ mRS = createRenderScript();
+ mRender = new FountainRS();
+ mRender.init(mRS, getResources(), w, h);
}
- int mTouchAction;
@Override
public boolean onTouchEvent(MotionEvent ev)
{
- //Log.e("FountainView", ev.toString());
boolean ret = true;
int act = ev.getAction();
- mParams[1] = (int)ev.getX();
- mParams[2] = (int)ev.getY();
-
- if (act == ev.ACTION_DOWN) {
- mParams[0] = 1;
- } else if (act == ev.ACTION_UP) {
- //mParams[0] = 0;
+ if (act == ev.ACTION_UP) {
ret = false;
}
- mIntAlloc.subData1D(2, 3, mParams);
-
+ mRender.newTouchPosition((int)ev.getX(), (int)ev.getY());
return ret;
}
}