Add background bitmap to fountain test app for renderscript.
diff --git a/libs/rs/java/Fountain/res/drawable/gadgets_clock_mp3.png b/libs/rs/java/Fountain/res/drawable/gadgets_clock_mp3.png
new file mode 100755
index 0000000..e91bfb4
--- /dev/null
+++ b/libs/rs/java/Fountain/res/drawable/gadgets_clock_mp3.png
Binary files differ
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 eb848a5..c244d07 100644
--- a/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java
+++ b/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java
@@ -21,6 +21,10 @@
import java.util.concurrent.Semaphore;
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;
@@ -46,6 +50,10 @@
private RenderScript.Script mScript;
private RenderScript.ProgramFragmentStore mPFS;
private RenderScript.ProgramFragment mPF;
+ private RenderScript.ProgramFragment mPF2;
+ private RenderScript.Allocation mTexture;
+
+ private Bitmap mBackground;
int mParams[] = new int[10];
@@ -58,6 +66,17 @@
mPartAlloc = mRS.allocationCreatePredefSized(RenderScript.ElementPredefined.USER_I32, partCount * 3 * 3);
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);
@@ -66,7 +85,13 @@
mRS.programFragmentBegin(null, null);
mPF = mRS.programFragmentCreate();
- mRS.contextBindProgramFragment(mPF);
+ //mRS.contextBindProgramFragment(mPF);
+
+ mRS.programFragmentBegin(null, null);
+ mRS.programFragmentSetTexEnable(0, true);
+ mPF2 = mRS.programFragmentCreate();
+ mRS.contextBindProgramFragment(mPF2);
+ mPF2.bindTexture(mTexture, 0);
mParams[0] = 0;
mParams[1] = partCount;
@@ -74,6 +99,8 @@
mParams[3] = 0;
mParams[4] = 0;
mParams[5] = mPartAlloc.mID;
+ mParams[6] = mPF.mID;
+ mParams[7] = mPF2.mID;
mIntAlloc.data(mParams);
int t2[] = new int[partCount * 4*3];
diff --git a/libs/rs/jni/RenderScript_jni.cpp b/libs/rs/jni/RenderScript_jni.cpp
index 2a199c3..e1f14b5 100644
--- a/libs/rs/jni/RenderScript_jni.cpp
+++ b/libs/rs/jni/RenderScript_jni.cpp
@@ -78,6 +78,10 @@
" }\n"
" }\n"
"\n"
+ " contextBindProgramFragment(con, loadI32(con, 0, 7));\n"
+ " drawRect(con, 0, 256, 0, 512);\n"
+ " contextBindProgramFragment(con, loadI32(con, 0, 6));\n"
+ "\n"
" if (touch) {\n"
" newPart = loadI32(con, 2, 0);\n"
" for (ct2=0; ct2<rate; ct2++) {\n"