Update Script java classes and llvm samples.
Change-Id: I05c8d63fcca095d4fea6abb1ff5736ab9d78a3e6
diff --git a/graphics/java/android/renderscript/Script.java b/graphics/java/android/renderscript/Script.java
index 57ccfa3..0d21368 100644
--- a/graphics/java/android/renderscript/Script.java
+++ b/graphics/java/android/renderscript/Script.java
@@ -42,6 +42,10 @@
}
}
+ protected void invoke(int slot) {
+ mRS.nScriptInvoke(mID, slot);
+ }
+
Script(int id, RenderScript rs) {
super(rs);
mID = id;
@@ -145,5 +149,48 @@
}
+
+ public static class FieldBase {
+ protected Element mElement;
+ protected Type mType;
+ protected Allocation mAllocation;
+
+ protected void init(RenderScript rs, int dimx) {
+ mAllocation = Allocation.createSized(rs, mElement, dimx);
+ mType = mAllocation.getType();
+ }
+
+ protected FieldBase() {
+ }
+
+ public Element getElement() {
+ return mElement;
+ }
+
+ public Type getType() {
+ return mType;
+ }
+
+ public Allocation getAllocation() {
+ return mAllocation;
+ }
+
+ //@Override
+ public void updateAllocation() {
+ }
+
+
+ //
+ /*
+ public class ScriptField_UserField
+ extends android.renderscript.Script.FieldBase {
+
+ protected
+
+ }
+
+ */
+
+ }
}
diff --git a/graphics/java/android/renderscript/ScriptC.java b/graphics/java/android/renderscript/ScriptC.java
index bb99e23..f5d5b2f 100644
--- a/graphics/java/android/renderscript/ScriptC.java
+++ b/graphics/java/android/renderscript/ScriptC.java
@@ -37,6 +37,47 @@
super(id, rs);
}
+ protected ScriptC(RenderScript rs, Resources resources, int resourceID, boolean isRoot) {
+ super(0, rs);
+ mID = internalCreate(rs, resources, resourceID, isRoot);
+ }
+
+
+ private static synchronized int internalCreate(RenderScript rs, Resources resources, int resourceID, boolean isRoot) {
+ byte[] pgm;
+ int pgmLength;
+ InputStream is = resources.openRawResource(resourceID);
+ try {
+ try {
+ pgm = new byte[1024];
+ pgmLength = 0;
+ while(true) {
+ int bytesLeft = pgm.length - pgmLength;
+ if (bytesLeft == 0) {
+ byte[] buf2 = new byte[pgm.length * 2];
+ System.arraycopy(pgm, 0, buf2, 0, pgm.length);
+ pgm = buf2;
+ bytesLeft = pgm.length - pgmLength;
+ }
+ int bytesRead = is.read(pgm, pgmLength, bytesLeft);
+ if (bytesRead <= 0) {
+ break;
+ }
+ pgmLength += bytesRead;
+ }
+ } finally {
+ is.close();
+ }
+ } catch(IOException e) {
+ throw new Resources.NotFoundException();
+ }
+
+ rs.nScriptCBegin();
+ rs.nScriptCSetScript(pgm, 0, pgmLength);
+ rs.nScriptSetRoot(isRoot);
+ return rs.nScriptCCreate();
+ }
+
public static class Builder extends Script.Builder {
byte[] mProgram;
int mProgramLength;
diff --git a/libs/rs/java/Fountain/res/raw/fountain2.rs b/libs/rs/java/Fountain/res/raw/fountain2.rs
index 3301140..5d36e35 100644
--- a/libs/rs/java/Fountain/res/raw/fountain2.rs
+++ b/libs/rs/java/Fountain/res/raw/fountain2.rs
@@ -1,9 +1,9 @@
// Fountain test script
#pragma version(1)
-#include "rs_types.rsh"
-#include "rs_math.rsh"
-#include "rs_graphics.rsh"
+#include "../../../../scriptc/rs_types.rsh"
+#include "../../../../scriptc/rs_math.rsh"
+#include "../../../../scriptc/rs_graphics.rsh"
static int newPart = 0;
@@ -12,15 +12,15 @@
int rate;
int count;
float r, g, b;
- rs_allocation partBuffer;
rs_mesh partMesh;
+ rs_allocation partBuffer;
} Control_t;
Control_t *Control;
typedef struct Point_s{
float2 delta;
- float2 position;
- unsigned int color;
+ rs_position2 pos;
+ rs_color4u color;
} Point_t;
Point_t *point;
@@ -33,8 +33,6 @@
if (rate) {
float rMax = ((float)rate) * 0.005f;
- int x = Control->x;
- int y = Control->y;
int color = ((int)(Control->r * 255.f)) |
((int)(Control->g * 255.f)) << 8 |
((int)(Control->b * 255.f)) << 16 |
@@ -42,9 +40,11 @@
Point_t * np = &p[newPart];
while (rate--) {
- np->delta = vec2Rand(rMax);
- np->position.x = x;
- np->position.y = y;
+ np->delta.x = rand(rMax);
+ np->delta.y = rand(rMax);
+ //np->delta = vec2Rand(rMax);
+ np->pos.x = Control->x;
+ np->pos.y = Control->y;
np->color = color;
newPart++;
np++;
@@ -57,13 +57,13 @@
for (ct=0; ct < count; ct++) {
float dy = p->delta.y + 0.15f;
- float posy = p->position.y + dy;
+ float posy = p->pos.y + dy;
if ((posy > height) && (dy > 0)) {
dy *= -0.3f;
}
p->delta.y = dy;
- p->position.x += p->delta.x;
- p->position.y = posy;
+ p->pos.x += p->delta.x;
+ p->pos.y = posy;
p++;
}
diff --git a/libs/rs/java/ImageProcessing/res/raw/threshold2.rs b/libs/rs/java/ImageProcessing/res/raw/threshold2.rs
new file mode 100644
index 0000000..9f687b5
--- /dev/null
+++ b/libs/rs/java/ImageProcessing/res/raw/threshold2.rs
@@ -0,0 +1,49 @@
+#pragma version(1)
+
+#include "../../../../scriptc/rs_types.rsh"
+#include "../../../../scriptc/rs_math.rsh"
+#include "../../../../scriptc/rs_graphics.rsh"
+
+typedef struct Params_s{
+ int inHeight;
+ int inWidth;
+ int outHeight;
+ int outWidth;
+ float threshold;
+} Params_t;
+
+Params_t * Params;
+rs_color4u * InPixel;
+rs_color4u * OutPixel;
+
+
+int main() {
+ int t = uptimeMillis();
+
+ rs_color4u *in = InPixel;
+ rs_color4u *out = OutPixel;
+
+ int count = Params->inWidth * Params->inHeight;
+ int i;
+ float threshold = Params->threshold * 255.f;
+
+ for (i = 0; i < count; i++) {
+ float luminance = 0.2125f * in->x +
+ 0.7154f * in->y +
+ 0.0721f * in->z;
+ if (luminance > threshold) {
+ *out = *in;
+ } else {
+ *((int *)out) = *((int *)in) & 0xff000000;
+ }
+
+ in++;
+ out++;
+ }
+
+ t= uptimeMillis() - t;
+ debugI32("Filter time", t);
+
+ sendToClient(&count, 1, 4, 0);
+ return 0;
+}