diff options
author | Tim Murray <timmurray@google.com> | 2013-04-12 20:03:51 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-04-12 20:03:52 +0000 |
commit | d6b8a035337e096f8d313b70f2178f4ec54ba2e4 (patch) | |
tree | 9275ec57b60fe83045159dcf4efd2a50fe6bd71c /graphics | |
parent | 3016244ffb0ee59a191b294839468a81b45a01f1 (diff) | |
parent | 7c4caadb939b1563328251c156262c179a685c70 (diff) | |
download | frameworks_base-d6b8a035337e096f8d313b70f2178f4ec54ba2e4.zip frameworks_base-d6b8a035337e096f8d313b70f2178f4ec54ba2e4.tar.gz frameworks_base-d6b8a035337e096f8d313b70f2178f4ec54ba2e4.tar.bz2 |
Merge "Add support for synchronous get()." into jb-mr2-dev
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/java/android/renderscript/Allocation.java | 20 | ||||
-rw-r--r-- | graphics/java/android/renderscript/FieldPacker.java | 247 | ||||
-rw-r--r-- | graphics/java/android/renderscript/RenderScript.java | 28 | ||||
-rw-r--r-- | graphics/java/android/renderscript/Script.java | 21 | ||||
-rw-r--r-- | graphics/jni/android_renderscript_RenderScript.cpp | 51 |
5 files changed, 360 insertions, 7 deletions
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java index acc6b99..ea29b7d 100644 --- a/graphics/java/android/renderscript/Allocation.java +++ b/graphics/java/android/renderscript/Allocation.java @@ -277,14 +277,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; @@ -355,6 +355,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 a49070e..7163151 100644 --- a/graphics/java/android/renderscript/RenderScript.java +++ b/graphics/java/android/renderscript/RenderScript.java @@ -582,31 +582,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 { diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp index 460a516..b9f8713 100644 --- a/graphics/jni/android_renderscript_RenderScript.cpp +++ b/graphics/jni/android_renderscript_RenderScript.cpp @@ -987,6 +987,15 @@ nScriptSetVarI(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slo rsScriptSetVarI(con, (RsScript)script, slot, val); } +static jint +nScriptGetVarI(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot) +{ + LOG_API("nScriptGetVarI, con(%p), s(%p), slot(%i)", con, (void *)script, slot); + int value = 0; + rsScriptGetVarV(con, (RsScript)script, slot, &value, sizeof(value)); + return value; +} + static void nScriptSetVarObj(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jint val) { @@ -1001,6 +1010,15 @@ nScriptSetVarJ(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slo rsScriptSetVarJ(con, (RsScript)script, slot, val); } +static jlong +nScriptGetVarJ(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot) +{ + LOG_API("nScriptGetVarJ, con(%p), s(%p), slot(%i)", con, (void *)script, slot); + jlong value = 0; + rsScriptGetVarV(con, (RsScript)script, slot, &value, sizeof(value)); + return value; +} + static void nScriptSetVarF(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, float val) { @@ -1008,6 +1026,15 @@ nScriptSetVarF(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slo rsScriptSetVarF(con, (RsScript)script, slot, val); } +static jfloat +nScriptGetVarF(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot) +{ + LOG_API("nScriptGetVarF, con(%p), s(%p), slot(%i)", con, (void *)script, slot); + jfloat value = 0; + rsScriptGetVarV(con, (RsScript)script, slot, &value, sizeof(value)); + return value; +} + static void nScriptSetVarD(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, double val) { @@ -1015,6 +1042,15 @@ nScriptSetVarD(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slo rsScriptSetVarD(con, (RsScript)script, slot, val); } +static jdouble +nScriptGetVarD(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot) +{ + LOG_API("nScriptGetVarD, con(%p), s(%p), slot(%i)", con, (void *)script, slot); + jdouble value = 0; + rsScriptGetVarV(con, (RsScript)script, slot, &value, sizeof(value)); + return value; +} + static void nScriptSetVarV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data) { @@ -1026,6 +1062,16 @@ nScriptSetVarV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slo } static void +nScriptGetVarV(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data) +{ + LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", con, (void *)script, slot); + jint len = _env->GetArrayLength(data); + jbyte *ptr = _env->GetByteArrayElements(data, NULL); + rsScriptGetVarV(con, (RsScript)script, slot, ptr, len); + _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); +} + +static void nScriptSetVarVE(JNIEnv *_env, jobject _this, RsContext con, jint script, jint slot, jbyteArray data, jint elem, jintArray dims) { LOG_API("nScriptSetVarVE, con(%p), s(%p), slot(%i)", con, (void *)script, slot); @@ -1600,10 +1646,15 @@ static JNINativeMethod methods[] = { {"rsnScriptForEachClipped", "(IIIIIIIIIII)V", (void*)nScriptForEachClipped }, {"rsnScriptForEachClipped", "(IIIII[BIIIIII)V", (void*)nScriptForEachClippedV }, {"rsnScriptSetVarI", "(IIII)V", (void*)nScriptSetVarI }, +{"rsnScriptGetVarI", "(III)I", (void*)nScriptGetVarI }, {"rsnScriptSetVarJ", "(IIIJ)V", (void*)nScriptSetVarJ }, +{"rsnScriptGetVarJ", "(III)J", (void*)nScriptGetVarJ }, {"rsnScriptSetVarF", "(IIIF)V", (void*)nScriptSetVarF }, +{"rsnScriptGetVarF", "(III)F", (void*)nScriptGetVarF }, {"rsnScriptSetVarD", "(IIID)V", (void*)nScriptSetVarD }, +{"rsnScriptGetVarD", "(III)D", (void*)nScriptGetVarD }, {"rsnScriptSetVarV", "(III[B)V", (void*)nScriptSetVarV }, +{"rsnScriptGetVarV", "(III[B)V", (void*)nScriptGetVarV }, {"rsnScriptSetVarVE", "(III[BI[I)V", (void*)nScriptSetVarVE }, {"rsnScriptSetVarObj", "(IIII)V", (void*)nScriptSetVarObj }, |