Loading graphics/java/android/renderscript/Allocation.java +28 −7 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package android.renderscript; import java.lang.reflect.Field; import java.lang.reflect.Array; import java.io.IOException; import java.io.InputStream; Loading @@ -33,9 +35,12 @@ import android.util.Log; * **/ public class Allocation extends BaseObj { Allocation(int id, RenderScript rs) { Type mType; Allocation(int id, RenderScript rs, Type t) { super(rs); mID = id; mType = t; } public void uploadToTexture(int baseMipLevel) { Loading Loading @@ -82,6 +87,10 @@ public class Allocation extends BaseObj { mRS.nAllocationRead(mID, d); } public void data(Object o) { mRS.nAllocationDataFromObject(mID, mType, o); } public class Adapter1D extends BaseObj { Adapter1D(int id, RenderScript rs) { Loading Loading @@ -179,7 +188,7 @@ public class Allocation extends BaseObj { throw new IllegalStateException("Bad Type"); } int id = rs.nAllocationCreateTyped(type.mID); return new Allocation(id, rs); return new Allocation(id, rs, type); } static public Allocation createSized(RenderScript rs, Element e, int count) Loading @@ -194,7 +203,7 @@ public class Allocation extends BaseObj { throw new IllegalStateException("Bad element."); } } return new Allocation(id, rs); return new Allocation(id, rs, null); } static public Allocation createFromBitmap(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips) Loading @@ -204,7 +213,7 @@ public class Allocation extends BaseObj { } int id = rs.nAllocationCreateFromBitmap(dstFmt.mPredefinedID, genMips, b); return new Allocation(id, rs); return new Allocation(id, rs, null); } static public Allocation createFromBitmapBoxed(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips) Loading @@ -214,7 +223,7 @@ public class Allocation extends BaseObj { } int id = rs.nAllocationCreateFromBitmapBoxed(dstFmt.mPredefinedID, genMips, b); return new Allocation(id, rs); return new Allocation(id, rs, null); } static public Allocation createFromBitmapResource(RenderScript rs, Resources res, int id, Element dstFmt, boolean genMips) Loading @@ -230,8 +239,20 @@ public class Allocation extends BaseObj { Bitmap b = BitmapFactory.decodeResource(res, id, mBitmapOptions); return createFromBitmapBoxed(rs, b, dstFmt, genMips); } /* public static Allocation createFromObject(RenderScript rs, Object o) { Class c = o.getClass(); Type t; if(c.isArray()) { t = Type.createFromClass(rs, c, Array.getLength(o)); } else { t = Type.createFromClass(rs, c, 1); } Allocation alloc = createTyped(rs, t); t.destroy(); return alloc; } */ } graphics/java/android/renderscript/Element.java +33 −3 Original line number Diff line number Diff line Loading @@ -16,6 +16,10 @@ package android.renderscript; import android.util.Config; import android.util.Log; import java.lang.reflect.Field; /** * @hide Loading Loading @@ -144,7 +148,26 @@ public class Element extends BaseObj { mRS.nElementDestroy(mID); } public static Element createFromClass(RenderScript rs, Class c) { Field[] fields = c.getFields(); Builder b = new Builder(rs); for(Field f: fields) { Class fc = f.getType(); if(fc == int.class) { b.add(Element.DataType.SIGNED, Element.DataKind.USER, false, 32, f.getName()); } else if(fc == short.class) { b.add(Element.DataType.SIGNED, Element.DataKind.USER, false, 16, f.getName()); } else if(fc == byte.class) { b.add(Element.DataType.SIGNED, Element.DataKind.USER, false, 8, f.getName()); } else if(fc == float.class) { b.add(Element.DataType.FLOAT, Element.DataKind.USER, false, 32, f.getName()); } else { throw new IllegalArgumentException("Unkown field type"); } } return b.create(); } public static class Builder { Loading @@ -158,6 +181,7 @@ public class Element extends BaseObj { Element.DataKind mKind; boolean mIsNormalized; int mBits; String mName; } public Builder(RenderScript rs) { Loading Loading @@ -188,16 +212,22 @@ public class Element extends BaseObj { return this; } public Builder add(Element.DataType dt, Element.DataKind dk, boolean isNormalized, int bits) { public Builder add(Element.DataType dt, Element.DataKind dk, boolean isNormalized, int bits, String name) { Entry en = new Entry(); en.mType = dt; en.mKind = dk; en.mIsNormalized = isNormalized; en.mBits = bits; en.mName = name; addEntry(en); return this; } public Builder add(Element.DataType dt, Element.DataKind dk, boolean isNormalized, int bits) { add(dt, dk, isNormalized, bits, null); return this; } static synchronized Element internalCreate(RenderScript rs, Builder b) { rs.nElementBegin(); for (int ct=0; ct < b.mEntryCount; ct++) { Loading @@ -209,7 +239,7 @@ public class Element extends BaseObj { if (en.mIsNormalized) { norm = 1; } rs.nElementAdd(en.mKind.mID, en.mType.mID, norm, en.mBits); rs.nElementAdd(en.mKind.mID, en.mType.mID, norm, en.mBits, en.mName); } } int id = rs.nElementCreate(); Loading graphics/java/android/renderscript/RenderScript.java +6 −1 Original line number Diff line number Diff line Loading @@ -18,9 +18,11 @@ package android.renderscript; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Field; import android.content.res.Resources; import android.graphics.Bitmap; import android.renderscript.Type; import android.util.Config; import android.util.Log; import android.view.Surface; Loading Loading @@ -76,7 +78,7 @@ public class RenderScript { native void nElementBegin(); native void nElementAddPredefined(int predef); native void nElementAdd(int kind, int type, int norm, int bits); native void nElementAdd(int kind, int type, int norm, int bits, String s); native int nElementCreate(); native int nElementGetPredefined(int predef); native void nElementDestroy(int obj); Loading @@ -85,6 +87,8 @@ public class RenderScript { native void nTypeAdd(int dim, int val); native int nTypeCreate(); native void nTypeDestroy(int id); native void nTypeFinalDestroy(Type t); native void nTypeSetupFields(Type t, int[] types, int[] bits, Field[] IDs); native int nAllocationCreateTyped(int type); native int nAllocationCreatePredefSized(int predef, int count); Loading @@ -102,6 +106,7 @@ public class RenderScript { native void nAllocationSubData2D(int id, int xoff, int yoff, int w, int h, float[] d); native void nAllocationRead(int id, int[] d); native void nAllocationRead(int id, float[] d); native void nAllocationDataFromObject(int id, Type t, Object o); native void nTriangleMeshDestroy(int id); native void nTriangleMeshBegin(int vertex, int index); Loading graphics/java/android/renderscript/Script.java +21 −1 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ package android.renderscript; **/ public class Script extends BaseObj { boolean mIsRoot; Type[] mTypes; Script(int id, RenderScript rs) { super(rs); Loading Loading @@ -62,21 +63,40 @@ public class Script extends BaseObj { public static class Builder { RenderScript mRS; boolean mIsRoot = false; Type[] mTypes; int mTypeCount; Builder(RenderScript rs) { mRS = rs; mTypes = new Type[4]; mTypeCount = 0; } public void addType(Type t) { mRS.nScriptCAddType(t.mID); if(mTypeCount >= mTypes.length) { Type[] nt = new Type[mTypeCount * 2]; for(int ct=0; ct < mTypeCount; ct++) { nt[ct] = mTypes[ct]; } mTypes = nt; } mTypes[mTypeCount] = t; mTypeCount++; } void transferCreate() { mRS.nScriptCSetRoot(mIsRoot); for(int ct=0; ct < mTypeCount; ct++) { mRS.nScriptCAddType(mTypes[ct].mID); } } void transferObject(Script s) { s.mIsRoot = mIsRoot; s.mTypes = new Type[mTypeCount]; for(int ct=0; ct < mTypeCount; ct++) { s.mTypes[ct] = mTypes[ct]; } } public void setRoot(boolean r) { Loading graphics/java/android/renderscript/Type.java +53 −1 Original line number Diff line number Diff line Loading @@ -16,10 +16,12 @@ package android.renderscript; import java.lang.reflect.Field; import android.renderscript.Element; import android.util.Config; import android.util.Log; /** * @hide * Loading @@ -28,11 +30,22 @@ public class Type extends BaseObj { Dimension[] mDimensions; int[] mValues; Element mElement; private int mNativeCache; Class mJavaClass; Type(int id, RenderScript rs) { super(rs); mID = id; mNativeCache = 0; } protected void finalize() throws Throwable { if(mNativeCache) { mRS.nTypeFinalDestroy(this); mNativeCache = 0; } super.finalize(); } public void destroy() { Loading @@ -43,6 +56,45 @@ public class Type extends BaseObj { mRS.nTypeDestroy(mID); } public static Type createFromClass(RenderScript rs, Class c, int size, String scriptName) { Element e = Element.createFromClass(rs, c); Builder b = new Builder(rs, e); b.add(Dimension.X, size); Type t = b.create(); e.destroy(); // native fields { Field[] fields = c.getFields(); int[] arTypes = new int[fields.length]; int[] arBits = new int[fields.length]; for(int ct=0; ct < fields.length; ct++) { Field f = fields[ct]; Class fc = f.getType(); if(fc == int.class) { arTypes[ct] = Element.DataType.SIGNED.mID; arBits[ct] = 32; } else if(fc == short.class) { arTypes[ct] = Element.DataType.SIGNED.mID; arBits[ct] = 16; } else if(fc == byte.class) { arTypes[ct] = Element.DataType.SIGNED.mID; arBits[ct] = 8; } else if(fc == float.class) { arTypes[ct] = Element.DataType.FLOAT.mID; arBits[ct] = 32; } else { throw new IllegalArgumentException("Unkown field type"); } } rs.nTypeSetupFields(t, arTypes, arBits, fields); } t.mJavaClass = c; t.setName(scriptName); return t; } public static class Builder { RenderScript mRS; Entry[] mEntries; Loading Loading
graphics/java/android/renderscript/Allocation.java +28 −7 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package android.renderscript; import java.lang.reflect.Field; import java.lang.reflect.Array; import java.io.IOException; import java.io.InputStream; Loading @@ -33,9 +35,12 @@ import android.util.Log; * **/ public class Allocation extends BaseObj { Allocation(int id, RenderScript rs) { Type mType; Allocation(int id, RenderScript rs, Type t) { super(rs); mID = id; mType = t; } public void uploadToTexture(int baseMipLevel) { Loading Loading @@ -82,6 +87,10 @@ public class Allocation extends BaseObj { mRS.nAllocationRead(mID, d); } public void data(Object o) { mRS.nAllocationDataFromObject(mID, mType, o); } public class Adapter1D extends BaseObj { Adapter1D(int id, RenderScript rs) { Loading Loading @@ -179,7 +188,7 @@ public class Allocation extends BaseObj { throw new IllegalStateException("Bad Type"); } int id = rs.nAllocationCreateTyped(type.mID); return new Allocation(id, rs); return new Allocation(id, rs, type); } static public Allocation createSized(RenderScript rs, Element e, int count) Loading @@ -194,7 +203,7 @@ public class Allocation extends BaseObj { throw new IllegalStateException("Bad element."); } } return new Allocation(id, rs); return new Allocation(id, rs, null); } static public Allocation createFromBitmap(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips) Loading @@ -204,7 +213,7 @@ public class Allocation extends BaseObj { } int id = rs.nAllocationCreateFromBitmap(dstFmt.mPredefinedID, genMips, b); return new Allocation(id, rs); return new Allocation(id, rs, null); } static public Allocation createFromBitmapBoxed(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips) Loading @@ -214,7 +223,7 @@ public class Allocation extends BaseObj { } int id = rs.nAllocationCreateFromBitmapBoxed(dstFmt.mPredefinedID, genMips, b); return new Allocation(id, rs); return new Allocation(id, rs, null); } static public Allocation createFromBitmapResource(RenderScript rs, Resources res, int id, Element dstFmt, boolean genMips) Loading @@ -230,8 +239,20 @@ public class Allocation extends BaseObj { Bitmap b = BitmapFactory.decodeResource(res, id, mBitmapOptions); return createFromBitmapBoxed(rs, b, dstFmt, genMips); } /* public static Allocation createFromObject(RenderScript rs, Object o) { Class c = o.getClass(); Type t; if(c.isArray()) { t = Type.createFromClass(rs, c, Array.getLength(o)); } else { t = Type.createFromClass(rs, c, 1); } Allocation alloc = createTyped(rs, t); t.destroy(); return alloc; } */ }
graphics/java/android/renderscript/Element.java +33 −3 Original line number Diff line number Diff line Loading @@ -16,6 +16,10 @@ package android.renderscript; import android.util.Config; import android.util.Log; import java.lang.reflect.Field; /** * @hide Loading Loading @@ -144,7 +148,26 @@ public class Element extends BaseObj { mRS.nElementDestroy(mID); } public static Element createFromClass(RenderScript rs, Class c) { Field[] fields = c.getFields(); Builder b = new Builder(rs); for(Field f: fields) { Class fc = f.getType(); if(fc == int.class) { b.add(Element.DataType.SIGNED, Element.DataKind.USER, false, 32, f.getName()); } else if(fc == short.class) { b.add(Element.DataType.SIGNED, Element.DataKind.USER, false, 16, f.getName()); } else if(fc == byte.class) { b.add(Element.DataType.SIGNED, Element.DataKind.USER, false, 8, f.getName()); } else if(fc == float.class) { b.add(Element.DataType.FLOAT, Element.DataKind.USER, false, 32, f.getName()); } else { throw new IllegalArgumentException("Unkown field type"); } } return b.create(); } public static class Builder { Loading @@ -158,6 +181,7 @@ public class Element extends BaseObj { Element.DataKind mKind; boolean mIsNormalized; int mBits; String mName; } public Builder(RenderScript rs) { Loading Loading @@ -188,16 +212,22 @@ public class Element extends BaseObj { return this; } public Builder add(Element.DataType dt, Element.DataKind dk, boolean isNormalized, int bits) { public Builder add(Element.DataType dt, Element.DataKind dk, boolean isNormalized, int bits, String name) { Entry en = new Entry(); en.mType = dt; en.mKind = dk; en.mIsNormalized = isNormalized; en.mBits = bits; en.mName = name; addEntry(en); return this; } public Builder add(Element.DataType dt, Element.DataKind dk, boolean isNormalized, int bits) { add(dt, dk, isNormalized, bits, null); return this; } static synchronized Element internalCreate(RenderScript rs, Builder b) { rs.nElementBegin(); for (int ct=0; ct < b.mEntryCount; ct++) { Loading @@ -209,7 +239,7 @@ public class Element extends BaseObj { if (en.mIsNormalized) { norm = 1; } rs.nElementAdd(en.mKind.mID, en.mType.mID, norm, en.mBits); rs.nElementAdd(en.mKind.mID, en.mType.mID, norm, en.mBits, en.mName); } } int id = rs.nElementCreate(); Loading
graphics/java/android/renderscript/RenderScript.java +6 −1 Original line number Diff line number Diff line Loading @@ -18,9 +18,11 @@ package android.renderscript; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Field; import android.content.res.Resources; import android.graphics.Bitmap; import android.renderscript.Type; import android.util.Config; import android.util.Log; import android.view.Surface; Loading Loading @@ -76,7 +78,7 @@ public class RenderScript { native void nElementBegin(); native void nElementAddPredefined(int predef); native void nElementAdd(int kind, int type, int norm, int bits); native void nElementAdd(int kind, int type, int norm, int bits, String s); native int nElementCreate(); native int nElementGetPredefined(int predef); native void nElementDestroy(int obj); Loading @@ -85,6 +87,8 @@ public class RenderScript { native void nTypeAdd(int dim, int val); native int nTypeCreate(); native void nTypeDestroy(int id); native void nTypeFinalDestroy(Type t); native void nTypeSetupFields(Type t, int[] types, int[] bits, Field[] IDs); native int nAllocationCreateTyped(int type); native int nAllocationCreatePredefSized(int predef, int count); Loading @@ -102,6 +106,7 @@ public class RenderScript { native void nAllocationSubData2D(int id, int xoff, int yoff, int w, int h, float[] d); native void nAllocationRead(int id, int[] d); native void nAllocationRead(int id, float[] d); native void nAllocationDataFromObject(int id, Type t, Object o); native void nTriangleMeshDestroy(int id); native void nTriangleMeshBegin(int vertex, int index); Loading
graphics/java/android/renderscript/Script.java +21 −1 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ package android.renderscript; **/ public class Script extends BaseObj { boolean mIsRoot; Type[] mTypes; Script(int id, RenderScript rs) { super(rs); Loading Loading @@ -62,21 +63,40 @@ public class Script extends BaseObj { public static class Builder { RenderScript mRS; boolean mIsRoot = false; Type[] mTypes; int mTypeCount; Builder(RenderScript rs) { mRS = rs; mTypes = new Type[4]; mTypeCount = 0; } public void addType(Type t) { mRS.nScriptCAddType(t.mID); if(mTypeCount >= mTypes.length) { Type[] nt = new Type[mTypeCount * 2]; for(int ct=0; ct < mTypeCount; ct++) { nt[ct] = mTypes[ct]; } mTypes = nt; } mTypes[mTypeCount] = t; mTypeCount++; } void transferCreate() { mRS.nScriptCSetRoot(mIsRoot); for(int ct=0; ct < mTypeCount; ct++) { mRS.nScriptCAddType(mTypes[ct].mID); } } void transferObject(Script s) { s.mIsRoot = mIsRoot; s.mTypes = new Type[mTypeCount]; for(int ct=0; ct < mTypeCount; ct++) { s.mTypes[ct] = mTypes[ct]; } } public void setRoot(boolean r) { Loading
graphics/java/android/renderscript/Type.java +53 −1 Original line number Diff line number Diff line Loading @@ -16,10 +16,12 @@ package android.renderscript; import java.lang.reflect.Field; import android.renderscript.Element; import android.util.Config; import android.util.Log; /** * @hide * Loading @@ -28,11 +30,22 @@ public class Type extends BaseObj { Dimension[] mDimensions; int[] mValues; Element mElement; private int mNativeCache; Class mJavaClass; Type(int id, RenderScript rs) { super(rs); mID = id; mNativeCache = 0; } protected void finalize() throws Throwable { if(mNativeCache) { mRS.nTypeFinalDestroy(this); mNativeCache = 0; } super.finalize(); } public void destroy() { Loading @@ -43,6 +56,45 @@ public class Type extends BaseObj { mRS.nTypeDestroy(mID); } public static Type createFromClass(RenderScript rs, Class c, int size, String scriptName) { Element e = Element.createFromClass(rs, c); Builder b = new Builder(rs, e); b.add(Dimension.X, size); Type t = b.create(); e.destroy(); // native fields { Field[] fields = c.getFields(); int[] arTypes = new int[fields.length]; int[] arBits = new int[fields.length]; for(int ct=0; ct < fields.length; ct++) { Field f = fields[ct]; Class fc = f.getType(); if(fc == int.class) { arTypes[ct] = Element.DataType.SIGNED.mID; arBits[ct] = 32; } else if(fc == short.class) { arTypes[ct] = Element.DataType.SIGNED.mID; arBits[ct] = 16; } else if(fc == byte.class) { arTypes[ct] = Element.DataType.SIGNED.mID; arBits[ct] = 8; } else if(fc == float.class) { arTypes[ct] = Element.DataType.FLOAT.mID; arBits[ct] = 32; } else { throw new IllegalArgumentException("Unkown field type"); } } rs.nTypeSetupFields(t, arTypes, arBits, fields); } t.mJavaClass = c; t.setName(scriptName); return t; } public static class Builder { RenderScript mRS; Entry[] mEntries; Loading