summaryrefslogtreecommitdiffstats
path: root/graphics/java/android/renderscript
diff options
context:
space:
mode:
authorTim Murray <timmurray@google.com>2013-04-10 16:21:40 -0700
committerTim Murray <timmurray@google.com>2013-04-11 16:25:29 -0700
commit7c4caadb939b1563328251c156262c179a685c70 (patch)
treead98bb41045c7273136478190546cb4279e29c98 /graphics/java/android/renderscript
parentb3a9872549137f6c3983609e48e5b2d4fc94a3d4 (diff)
downloadframeworks_base-7c4caadb939b1563328251c156262c179a685c70.zip
frameworks_base-7c4caadb939b1563328251c156262c179a685c70.tar.gz
frameworks_base-7c4caadb939b1563328251c156262c179a685c70.tar.bz2
Add support for synchronous get().
bug 8599910 Change-Id: I0e7c52350cc1abb14a5ed59bb92e8e0346209d53
Diffstat (limited to 'graphics/java/android/renderscript')
-rw-r--r--graphics/java/android/renderscript/Allocation.java20
-rw-r--r--graphics/java/android/renderscript/FieldPacker.java247
-rw-r--r--graphics/java/android/renderscript/RenderScript.java28
-rw-r--r--graphics/java/android/renderscript/Script.java21
4 files changed, 309 insertions, 7 deletions
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java
index 5751331..051b03f 100644
--- a/graphics/java/android/renderscript/Allocation.java
+++ b/graphics/java/android/renderscript/Allocation.java
@@ -273,14 +273,14 @@ public class Allocation extends BaseObj {
throw new RSIllegalArgumentException("Invalid usage combination.");
}
}
-
- // don't need to account for USAGE_SHARED Allocations
- if ((usage & USAGE_SHARED) == 0) {
- int numBytes = t.getCount() * t.getElement().getBytesSize();
- rs.addAllocSizeForGC(numBytes);
- mGCSize = numBytes;
+ if (t != null) {
+ // don't need to account for USAGE_SHARED Allocations
+ if ((usage & USAGE_SHARED) == 0) {
+ int numBytes = t.getCount() * t.getElement().getBytesSize();
+ rs.addAllocSizeForGC(numBytes);
+ mGCSize = numBytes;
+ }
}
-
mType = t;
mUsage = usage;
@@ -351,6 +351,12 @@ public class Allocation extends BaseObj {
mType.updateFromNative();
updateCacheInfo(mType);
}
+ // don't need to account for USAGE_SHARED Allocations
+ if ((mUsage & USAGE_SHARED) == 0) {
+ int numBytes = mType.getCount() * mType.getElement().getBytesSize();
+ mRS.addAllocSizeForGC(numBytes);
+ mGCSize = numBytes;
+ }
}
/**
diff --git a/graphics/java/android/renderscript/FieldPacker.java b/graphics/java/android/renderscript/FieldPacker.java
index 0a7e882..decd0c7 100644
--- a/graphics/java/android/renderscript/FieldPacker.java
+++ b/graphics/java/android/renderscript/FieldPacker.java
@@ -16,6 +16,8 @@
package android.renderscript;
+import android.util.Log;
+import java.util.BitSet;
/**
* Utility class for packing arguments and structures from Android system objects to
@@ -27,12 +29,14 @@ public class FieldPacker {
mPos = 0;
mLen = len;
mData = new byte[len];
+ mAlignment = new BitSet();
}
public FieldPacker(byte[] data) {
mPos = 0;
mLen = data.length;
mData = data;
+ mAlignment = new BitSet();
}
public void align(int v) {
@@ -41,10 +45,29 @@ public class FieldPacker {
}
while ((mPos & (v - 1)) != 0) {
+ mAlignment.flip(mPos);
mData[mPos++] = 0;
}
}
+ public void subalign(int v) {
+ if ((v & (v - 1)) != 0) {
+ throw new RSIllegalArgumentException("argument must be a non-negative non-zero power of 2: " + v);
+ }
+
+ while ((mPos & (v - 1)) != 0) {
+ mPos--;
+ }
+
+ if (mPos > 0) {
+ while (mAlignment.get(mPos - 1) == true) {
+ mPos--;
+ mAlignment.flip(mPos);
+ }
+ }
+
+ }
+
public void reset() {
mPos = 0;
}
@@ -67,12 +90,26 @@ public class FieldPacker {
mData[mPos++] = v;
}
+ public byte subI8() {
+ subalign(1);
+ return mData[--mPos];
+ }
+
public void addI16(short v) {
align(2);
mData[mPos++] = (byte)(v & 0xff);
mData[mPos++] = (byte)(v >> 8);
}
+ public short subI16() {
+ subalign(2);
+ short v = 0;
+ v = (short)((mData[--mPos] & 0xff) << 8);
+ v = (short)(v | (short)(mData[--mPos] & 0xff));
+ return v;
+ }
+
+
public void addI32(int v) {
align(4);
mData[mPos++] = (byte)(v & 0xff);
@@ -81,6 +118,17 @@ public class FieldPacker {
mData[mPos++] = (byte)((v >> 24) & 0xff);
}
+ public int subI32() {
+ subalign(4);
+ int v = 0;
+ v = ((mData[--mPos] & 0xff) << 24);
+ v = v | ((mData[--mPos] & 0xff) << 16);
+ v = v | ((mData[--mPos] & 0xff) << 8);
+ v = v | ((mData[--mPos] & 0xff));
+ return v;
+ }
+
+
public void addI64(long v) {
align(8);
mData[mPos++] = (byte)(v & 0xff);
@@ -93,6 +141,29 @@ public class FieldPacker {
mData[mPos++] = (byte)((v >> 56) & 0xff);
}
+ public long subI64() {
+ subalign(8);
+ long v = 0;
+ byte x = 0;
+ x = ((mData[--mPos]));
+ v = (long)(v | (((long)x) & 0xff) << 56l);
+ x = ((mData[--mPos]));
+ v = (long)(v | (((long)x) & 0xff) << 48l);
+ x = ((mData[--mPos]));
+ v = (long)(v | (((long)x) & 0xff) << 40l);
+ x = ((mData[--mPos]));
+ v = (long)(v | (((long)x) & 0xff) << 32l);
+ x = ((mData[--mPos]));
+ v = (long)(v | (((long)x) & 0xff) << 24l);
+ x = ((mData[--mPos]));
+ v = (long)(v | (((long)x) & 0xff) << 16l);
+ x = ((mData[--mPos]));
+ v = (long)(v | (((long)x) & 0xff) << 8l);
+ x = ((mData[--mPos]));
+ v = (long)(v | (((long)x) & 0xff));
+ return v;
+ }
+
public void addU8(short v) {
if ((v < 0) || (v > 0xff)) {
android.util.Log.e("rs", "FieldPacker.addU8( " + v + " )");
@@ -143,10 +214,18 @@ public class FieldPacker {
addI32(Float.floatToRawIntBits(v));
}
+ public float subF32() {
+ return Float.intBitsToFloat(subI32());
+ }
+
public void addF64(double v) {
addI64(Double.doubleToRawLongBits(v));
}
+ public double subF64() {
+ return Double.longBitsToDouble(subI64());
+ }
+
public void addObj(BaseObj obj) {
if (obj != null) {
addI32(obj.getID(null));
@@ -315,28 +394,195 @@ public class FieldPacker {
addU64(v.w);
}
+
+ public Float2 subFloat2() {
+ Float2 v = new Float2();
+ v.y = subF32();
+ v.x = subF32();
+ return v;
+ }
+ public Float3 subFloat3() {
+ Float3 v = new Float3();
+ v.z = subF32();
+ v.y = subF32();
+ v.x = subF32();
+ return v;
+ }
+ public Float4 subFloat4() {
+ Float4 v = new Float4();
+ v.w = subF32();
+ v.z = subF32();
+ v.y = subF32();
+ v.x = subF32();
+ return v;
+ }
+
+ public Double2 subDouble2() {
+ Double2 v = new Double2();
+ v.y = subF64();
+ v.x = subF64();
+ return v;
+ }
+ public Double3 subDouble3() {
+ Double3 v = new Double3();
+ v.z = subF64();
+ v.y = subF64();
+ v.x = subF64();
+ return v;
+ }
+ public Double4 subDouble4() {
+ Double4 v = new Double4();
+ v.w = subF64();
+ v.z = subF64();
+ v.y = subF64();
+ v.x = subF64();
+ return v;
+ }
+
+ public Byte2 subByte2() {
+ Byte2 v = new Byte2();
+ v.y = subI8();
+ v.x = subI8();
+ return v;
+ }
+ public Byte3 subByte3() {
+ Byte3 v = new Byte3();
+ v.z = subI8();
+ v.y = subI8();
+ v.x = subI8();
+ return v;
+ }
+ public Byte4 subByte4() {
+ Byte4 v = new Byte4();
+ v.w = subI8();
+ v.z = subI8();
+ v.y = subI8();
+ v.x = subI8();
+ return v;
+ }
+
+ public Short2 subShort2() {
+ Short2 v = new Short2();
+ v.y = subI16();
+ v.x = subI16();
+ return v;
+ }
+ public Short3 subShort3() {
+ Short3 v = new Short3();
+ v.z = subI16();
+ v.y = subI16();
+ v.x = subI16();
+ return v;
+ }
+ public Short4 subShort4() {
+ Short4 v = new Short4();
+ v.w = subI16();
+ v.z = subI16();
+ v.y = subI16();
+ v.x = subI16();
+ return v;
+ }
+
+ public Int2 subInt2() {
+ Int2 v = new Int2();
+ v.y = subI32();
+ v.x = subI32();
+ return v;
+ }
+ public Int3 subInt3() {
+ Int3 v = new Int3();
+ v.z = subI32();
+ v.y = subI32();
+ v.x = subI32();
+ return v;
+ }
+ public Int4 subInt4() {
+ Int4 v = new Int4();
+ v.w = subI32();
+ v.z = subI32();
+ v.y = subI32();
+ v.x = subI32();
+ return v;
+ }
+
+ public Long2 subLong2() {
+ Long2 v = new Long2();
+ v.y = subI64();
+ v.x = subI64();
+ return v;
+ }
+ public Long3 subLong3() {
+ Long3 v = new Long3();
+ v.z = subI64();
+ v.y = subI64();
+ v.x = subI64();
+ return v;
+ }
+ public Long4 subLong4() {
+ Long4 v = new Long4();
+ v.w = subI64();
+ v.z = subI64();
+ v.y = subI64();
+ v.x = subI64();
+ return v;
+ }
+
+
+
public void addMatrix(Matrix4f v) {
for (int i=0; i < v.mMat.length; i++) {
addF32(v.mMat[i]);
}
}
+ public Matrix4f subMatrix4f() {
+ Matrix4f v = new Matrix4f();
+ for (int i = v.mMat.length - 1; i >= 0; i--) {
+ v.mMat[i] = subF32();
+ }
+ return v;
+ }
+
public void addMatrix(Matrix3f v) {
for (int i=0; i < v.mMat.length; i++) {
addF32(v.mMat[i]);
}
}
+ public Matrix3f subMatrix3f() {
+ Matrix3f v = new Matrix3f();
+ for (int i = v.mMat.length - 1; i >= 0; i--) {
+ v.mMat[i] = subF32();
+ }
+ return v;
+ }
+
public void addMatrix(Matrix2f v) {
for (int i=0; i < v.mMat.length; i++) {
addF32(v.mMat[i]);
}
}
+ public Matrix2f subMatrix2f() {
+ Matrix2f v = new Matrix2f();
+ for (int i = v.mMat.length - 1; i >= 0; i--) {
+ v.mMat[i] = subF32();
+ }
+ return v;
+ }
+
public void addBoolean(boolean v) {
addI8((byte)(v ? 1 : 0));
}
+ public boolean subBoolean() {
+ byte v = subI8();
+ if (v == 1) {
+ return true;
+ }
+ return false;
+ }
+
public final byte[] getData() {
return mData;
}
@@ -344,6 +590,7 @@ public class FieldPacker {
private final byte mData[];
private int mPos;
private int mLen;
+ private BitSet mAlignment;
}
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index d5af276..7518689 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -580,31 +580,59 @@ public class RenderScript {
validate();
rsnScriptInvokeV(mContext, id, slot, params);
}
+
native void rsnScriptSetVarI(int con, int id, int slot, int val);
synchronized void nScriptSetVarI(int id, int slot, int val) {
validate();
rsnScriptSetVarI(mContext, id, slot, val);
}
+ native int rsnScriptGetVarI(int con, int id, int slot);
+ synchronized int nScriptGetVarI(int id, int slot) {
+ validate();
+ return rsnScriptGetVarI(mContext, id, slot);
+ }
+
native void rsnScriptSetVarJ(int con, int id, int slot, long val);
synchronized void nScriptSetVarJ(int id, int slot, long val) {
validate();
rsnScriptSetVarJ(mContext, id, slot, val);
}
+ native long rsnScriptGetVarJ(int con, int id, int slot);
+ synchronized long nScriptGetVarJ(int id, int slot) {
+ validate();
+ return rsnScriptGetVarJ(mContext, id, slot);
+ }
+
native void rsnScriptSetVarF(int con, int id, int slot, float val);
synchronized void nScriptSetVarF(int id, int slot, float val) {
validate();
rsnScriptSetVarF(mContext, id, slot, val);
}
+ native float rsnScriptGetVarF(int con, int id, int slot);
+ synchronized float nScriptGetVarF(int id, int slot) {
+ validate();
+ return rsnScriptGetVarF(mContext, id, slot);
+ }
native void rsnScriptSetVarD(int con, int id, int slot, double val);
synchronized void nScriptSetVarD(int id, int slot, double val) {
validate();
rsnScriptSetVarD(mContext, id, slot, val);
}
+ native double rsnScriptGetVarD(int con, int id, int slot);
+ synchronized double nScriptGetVarD(int id, int slot) {
+ validate();
+ return rsnScriptGetVarD(mContext, id, slot);
+ }
native void rsnScriptSetVarV(int con, int id, int slot, byte[] val);
synchronized void nScriptSetVarV(int id, int slot, byte[] val) {
validate();
rsnScriptSetVarV(mContext, id, slot, val);
}
+ native void rsnScriptGetVarV(int con, int id, int slot, byte[] val);
+ synchronized void nScriptGetVarV(int id, int slot, byte[] val) {
+ validate();
+ rsnScriptGetVarV(mContext, id, slot, val);
+ }
native void rsnScriptSetVarVE(int con, int id, int slot, byte[] val,
int e, int[] dims);
synchronized void nScriptSetVarVE(int id, int slot, byte[] val,
diff --git a/graphics/java/android/renderscript/Script.java b/graphics/java/android/renderscript/Script.java
index b405588..b4ba943 100644
--- a/graphics/java/android/renderscript/Script.java
+++ b/graphics/java/android/renderscript/Script.java
@@ -220,6 +220,9 @@ public class Script extends BaseObj {
public void setVar(int index, float v) {
mRS.nScriptSetVarF(getID(mRS), index, v);
}
+ public float getVarF(int index) {
+ return mRS.nScriptGetVarF(getID(mRS), index);
+ }
/**
* Only intended for use by generated reflected code.
@@ -230,6 +233,9 @@ public class Script extends BaseObj {
public void setVar(int index, double v) {
mRS.nScriptSetVarD(getID(mRS), index, v);
}
+ public double getVarD(int index) {
+ return mRS.nScriptGetVarD(getID(mRS), index);
+ }
/**
* Only intended for use by generated reflected code.
@@ -240,6 +246,10 @@ public class Script extends BaseObj {
public void setVar(int index, int v) {
mRS.nScriptSetVarI(getID(mRS), index, v);
}
+ public int getVarI(int index) {
+ return mRS.nScriptGetVarI(getID(mRS), index);
+ }
+
/**
* Only intended for use by generated reflected code.
@@ -250,6 +260,10 @@ public class Script extends BaseObj {
public void setVar(int index, long v) {
mRS.nScriptSetVarJ(getID(mRS), index, v);
}
+ public long getVarJ(int index) {
+ return mRS.nScriptGetVarJ(getID(mRS), index);
+ }
+
/**
* Only intended for use by generated reflected code.
@@ -260,6 +274,9 @@ public class Script extends BaseObj {
public void setVar(int index, boolean v) {
mRS.nScriptSetVarI(getID(mRS), index, v ? 1 : 0);
}
+ public boolean getVarB(int index) {
+ return mRS.nScriptGetVarI(getID(mRS), index) > 0 ? true : false;
+ }
/**
* Only intended for use by generated reflected code.
@@ -293,6 +310,10 @@ public class Script extends BaseObj {
mRS.nScriptSetVarVE(getID(mRS), index, v.getData(), e.getID(mRS), dims);
}
+ public void getVarV(int index, FieldPacker v) {
+ mRS.nScriptGetVarV(getID(mRS), index, v.getData());
+ }
+
public void setTimeZone(String timeZone) {
mRS.validate();
try {