summaryrefslogtreecommitdiffstats
path: root/graphics/java
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/java')
-rw-r--r--graphics/java/android/renderscript/Allocation.java25
-rw-r--r--graphics/java/android/renderscript/Element.java310
-rw-r--r--graphics/java/android/renderscript/RenderScript.java8
3 files changed, 207 insertions, 136 deletions
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java
index e6cb395..7749ad3 100644
--- a/graphics/java/android/renderscript/Allocation.java
+++ b/graphics/java/android/renderscript/Allocation.java
@@ -209,35 +209,24 @@ public class Allocation extends BaseObj {
static public Allocation createSized(RenderScript rs, Element e, int count)
throws IllegalArgumentException {
- int id;
- if(e.mIsPredefined) {
- id = rs.nAllocationCreatePredefSized(e.mPredefinedID, count);
- } else {
- id = rs.nAllocationCreateSized(e.mID, count);
- if(id == 0) {
- throw new IllegalStateException("Bad element.");
- }
+ int id = rs.nAllocationCreateSized(e.mID, count);
+ if(id == 0) {
+ throw new IllegalStateException("Bad element.");
}
return new Allocation(id, rs, null);
}
static public Allocation createFromBitmap(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips)
throws IllegalArgumentException {
- if(!dstFmt.mIsPredefined) {
- throw new IllegalStateException("Attempting to allocate a bitmap with a non-static element.");
- }
- int id = rs.nAllocationCreateFromBitmap(dstFmt.mPredefinedID, genMips, b);
+ int id = rs.nAllocationCreateFromBitmap(dstFmt.mID, genMips, b);
return new Allocation(id, rs, null);
}
static public Allocation createFromBitmapBoxed(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips)
throws IllegalArgumentException {
- if(!dstFmt.mIsPredefined) {
- throw new IllegalStateException("Attempting to allocate a bitmap with a non-static element.");
- }
- int id = rs.nAllocationCreateFromBitmapBoxed(dstFmt.mPredefinedID, genMips, b);
+ int id = rs.nAllocationCreateFromBitmapBoxed(dstFmt.mID, genMips, b);
return new Allocation(id, rs, null);
}
@@ -250,10 +239,10 @@ public class Allocation extends BaseObj {
is = res.openRawResource(id, value);
int asset = ((AssetManager.AssetInputStream) is).getAssetInt();
- int allocationId = rs.nAllocationCreateFromAssetStream(dstFmt.mPredefinedID, genMips,
+ int allocationId = rs.nAllocationCreateFromAssetStream(dstFmt.mID, genMips,
asset);
- return new Allocation(allocationId, rs, null);
+ return new Allocation(allocationId, rs, null);
} catch (Exception e) {
// Ignore
} finally {
diff --git a/graphics/java/android/renderscript/Element.java b/graphics/java/android/renderscript/Element.java
index 0b7e667..04c36fd 100644
--- a/graphics/java/android/renderscript/Element.java
+++ b/graphics/java/android/renderscript/Element.java
@@ -23,62 +23,171 @@ import java.lang.reflect.Field;
*
**/
public class Element extends BaseObj {
- final int mPredefinedID;
- final boolean mIsPredefined;
- final int mSize;
-
- public static final Element USER_U8 = new Element(0, 1);
- public static final Element USER_I8 = new Element(1, 1);
- public static final Element USER_U16 = new Element(2, 2);
- public static final Element USER_I16 = new Element(3, 2);
- public static final Element USER_U32 = new Element(4, 4);
- public static final Element USER_I32 = new Element(5, 4);
- public static final Element USER_FLOAT = new Element(6, 4);
-
- public static final Element A_8 = new Element(7, 1);
- public static final Element RGB_565 = new Element(8, 2);
- public static final Element RGB_888 = new Element(11, 2);
- public static final Element RGBA_5551 = new Element(9, 2);
- public static final Element RGBA_4444 = new Element(10, 2);
- public static final Element RGBA_8888 = new Element(12, 4);
-
- public static final Element INDEX_16 = new Element(13, 2);
- public static final Element INDEX_32 = new Element(14, 2);
- public static final Element XY_F32 = new Element(15, 8);
- public static final Element XYZ_F32 = new Element(16, 12);
- public static final Element ST_XY_F32 = new Element(17, 16);
- public static final Element ST_XYZ_F32 = new Element(18, 20);
- public static final Element NORM_XYZ_F32 = new Element(19, 24);
- public static final Element NORM_ST_XYZ_F32 = new Element(20, 32);
-
- void initPredef(RenderScript rs) {
- mID = rs.nElementGetPredefined(mPredefinedID);
+ int mSize;
+ Entry[] mEntries;
+
+ static class Entry {
+ Element mElement;
+ Element.DataType mType;
+ Element.DataKind mKind;
+ boolean mIsNormalized;
+ int mBits;
+ String mName;
+
+ Entry(Element e, int bits) {
+ mElement = e;
+ int mBits = bits;
+ }
+
+ Entry(DataType dt, DataKind dk, boolean isNorm, int bits, String name) {
+ mType = dt;
+ mKind = dk;
+ mIsNormalized = isNorm;
+ mBits = bits;
+ mName = name;
+ }
}
- static void init(RenderScript rs) {
- USER_U8.initPredef(rs);
- USER_I8.initPredef(rs);
- USER_U16.initPredef(rs);
- USER_I16.initPredef(rs);
- USER_U32.initPredef(rs);
- USER_I32.initPredef(rs);
- USER_FLOAT.initPredef(rs);
-
- A_8.initPredef(rs);
- RGB_565.initPredef(rs);
- RGB_888.initPredef(rs);
- RGBA_5551.initPredef(rs);
- RGBA_4444.initPredef(rs);
- RGBA_8888.initPredef(rs);
-
- INDEX_16.initPredef(rs);
- INDEX_32.initPredef(rs);
- XY_F32.initPredef(rs);
- XYZ_F32.initPredef(rs);
- ST_XY_F32.initPredef(rs);
- ST_XYZ_F32.initPredef(rs);
- NORM_XYZ_F32.initPredef(rs);
- NORM_ST_XYZ_F32.initPredef(rs);
+ public static final Element USER_U8 = new Element();
+ public static final Element USER_I8 = new Element();
+ public static final Element USER_U16 = new Element();
+ public static final Element USER_I16 = new Element();
+ public static final Element USER_U32 = new Element();
+ public static final Element USER_I32 = new Element();
+ public static final Element USER_FLOAT = new Element();
+
+ public static final Element A_8 = new Element();
+ public static final Element RGB_565 = new Element();
+ public static final Element RGB_888 = new Element();
+ public static final Element RGBA_5551 = new Element();
+ public static final Element RGBA_4444 = new Element();
+ public static final Element RGBA_8888 = new Element();
+
+ public static final Element INDEX_16 = new Element();
+ public static final Element XY_F32 = new Element();
+ public static final Element XYZ_F32 = new Element();
+ public static final Element ST_XY_F32 = new Element();
+ public static final Element ST_XYZ_F32 = new Element();
+ public static final Element NORM_XYZ_F32 = new Element();
+ public static final Element NORM_ST_XYZ_F32 = new Element();
+
+ static void initPredefined(RenderScript rs) {
+ USER_U8.mEntries = new Entry[1];
+ USER_U8.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.USER, false, 8, null);
+ USER_U8.init(rs);
+
+ USER_I8.mEntries = new Entry[1];
+ USER_I8.mEntries[0] = new Entry(DataType.SIGNED, DataKind.USER, false, 8, null);
+ USER_I8.init(rs);
+
+ USER_U16.mEntries = new Entry[1];
+ USER_U16.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.USER, false, 16, null);
+ USER_U16.init(rs);
+
+ USER_I16.mEntries = new Entry[1];
+ USER_I16.mEntries[0] = new Entry(DataType.SIGNED, DataKind.USER, false, 16, null);
+ USER_I16.init(rs);
+
+ USER_U32.mEntries = new Entry[1];
+ USER_U32.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.USER, false, 32, null);
+ USER_U32.init(rs);
+
+ USER_I32.mEntries = new Entry[1];
+ USER_I32.mEntries[0] = new Entry(DataType.SIGNED, DataKind.USER, false, 32, null);
+ USER_I32.init(rs);
+
+ USER_FLOAT.mEntries = new Entry[1];
+ USER_FLOAT.mEntries[0] = new Entry(DataType.FLOAT, DataKind.USER, false, 32, null);
+ USER_FLOAT.init(rs);
+
+ A_8.mEntries = new Entry[1];
+ A_8.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.ALPHA, true, 8, "a");
+ A_8.init(rs);
+
+ RGB_565.mEntries = new Entry[3];
+ RGB_565.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 5, "r");
+ RGB_565.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 6, "g");
+ RGB_565.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 5, "b");
+ RGB_565.init(rs);
+
+ RGB_888.mEntries = new Entry[3];
+ RGB_888.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 8, "r");
+ RGB_888.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 8, "g");
+ RGB_888.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 8, "b");
+ RGB_888.init(rs);
+
+ RGBA_5551.mEntries = new Entry[4];
+ RGBA_5551.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 5, "r");
+ RGBA_5551.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 5, "g");
+ RGBA_5551.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 5, "b");
+ RGBA_5551.mEntries[3] = new Entry(DataType.UNSIGNED, DataKind.ALPHA, true, 1, "a");
+ RGBA_5551.init(rs);
+
+ RGBA_4444.mEntries = new Entry[4];
+ RGBA_4444.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 4, "r");
+ RGBA_4444.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 4, "g");
+ RGBA_4444.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 4, "b");
+ RGBA_4444.mEntries[3] = new Entry(DataType.UNSIGNED, DataKind.ALPHA, true, 4, "a");
+ RGBA_4444.init(rs);
+
+ RGBA_8888.mEntries = new Entry[4];
+ RGBA_8888.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.RED, true, 8, "r");
+ RGBA_8888.mEntries[1] = new Entry(DataType.UNSIGNED, DataKind.GREEN, true, 8, "g");
+ RGBA_8888.mEntries[2] = new Entry(DataType.UNSIGNED, DataKind.BLUE, true, 8, "b");
+ RGBA_8888.mEntries[3] = new Entry(DataType.UNSIGNED, DataKind.ALPHA, true, 8, "a");
+ RGBA_8888.init(rs);
+
+ INDEX_16.mEntries = new Entry[1];
+ INDEX_16.mEntries[0] = new Entry(DataType.UNSIGNED, DataKind.INDEX, false, 16, "index");
+ INDEX_16.init(rs);
+
+ XY_F32.mEntries = new Entry[2];
+ XY_F32.mEntries[0] = new Entry(DataType.FLOAT, DataKind.X, false, 32, "x");
+ XY_F32.mEntries[1] = new Entry(DataType.FLOAT, DataKind.Y, false, 32, "y");
+ XY_F32.init(rs);
+
+ XYZ_F32.mEntries = new Entry[3];
+ XYZ_F32.mEntries[0] = new Entry(DataType.FLOAT, DataKind.X, false, 32, "x");
+ XYZ_F32.mEntries[1] = new Entry(DataType.FLOAT, DataKind.Y, false, 32, "y");
+ XYZ_F32.mEntries[2] = new Entry(DataType.FLOAT, DataKind.Z, false, 32, "z");
+ XYZ_F32.init(rs);
+
+ ST_XY_F32.mEntries = new Entry[4];
+ ST_XY_F32.mEntries[0] = new Entry(DataType.FLOAT, DataKind.S, false, 32, "s");
+ ST_XY_F32.mEntries[1] = new Entry(DataType.FLOAT, DataKind.T, false, 32, "t");
+ ST_XY_F32.mEntries[2] = new Entry(DataType.FLOAT, DataKind.X, false, 32, "x");
+ ST_XY_F32.mEntries[3] = new Entry(DataType.FLOAT, DataKind.Y, false, 32, "y");
+ ST_XY_F32.init(rs);
+
+ ST_XYZ_F32.mEntries = new Entry[5];
+ ST_XYZ_F32.mEntries[0] = new Entry(DataType.FLOAT, DataKind.S, false, 32, "s");
+ ST_XYZ_F32.mEntries[1] = new Entry(DataType.FLOAT, DataKind.T, false, 32, "t");
+ ST_XYZ_F32.mEntries[2] = new Entry(DataType.FLOAT, DataKind.X, false, 32, "x");
+ ST_XYZ_F32.mEntries[3] = new Entry(DataType.FLOAT, DataKind.Y, false, 32, "y");
+ ST_XYZ_F32.mEntries[4] = new Entry(DataType.FLOAT, DataKind.Z, false, 32, "z");
+ ST_XYZ_F32.init(rs);
+
+ NORM_XYZ_F32.mEntries = new Entry[6];
+ NORM_XYZ_F32.mEntries[0] = new Entry(DataType.FLOAT, DataKind.NX, false, 32, "nx");
+ NORM_XYZ_F32.mEntries[1] = new Entry(DataType.FLOAT, DataKind.NY, false, 32, "ny");
+ NORM_XYZ_F32.mEntries[2] = new Entry(DataType.FLOAT, DataKind.NZ, false, 32, "nz");
+ NORM_XYZ_F32.mEntries[3] = new Entry(DataType.FLOAT, DataKind.X, false, 32, "x");
+ NORM_XYZ_F32.mEntries[4] = new Entry(DataType.FLOAT, DataKind.Y, false, 32, "y");
+ NORM_XYZ_F32.mEntries[5] = new Entry(DataType.FLOAT, DataKind.Z, false, 32, "z");
+ NORM_XYZ_F32.init(rs);
+
+ NORM_ST_XYZ_F32.mEntries = new Entry[8];
+ NORM_ST_XYZ_F32.mEntries[0] = new Entry(DataType.FLOAT, DataKind.NX, false, 32, "nx");
+ NORM_ST_XYZ_F32.mEntries[1] = new Entry(DataType.FLOAT, DataKind.NY, false, 32, "ny");
+ NORM_ST_XYZ_F32.mEntries[2] = new Entry(DataType.FLOAT, DataKind.NZ, false, 32, "nz");
+ NORM_ST_XYZ_F32.mEntries[3] = new Entry(DataType.FLOAT, DataKind.S, false, 32, "s");
+ NORM_ST_XYZ_F32.mEntries[4] = new Entry(DataType.FLOAT, DataKind.T, false, 32, "t");
+ NORM_ST_XYZ_F32.mEntries[5] = new Entry(DataType.FLOAT, DataKind.X, false, 32, "x");
+ NORM_ST_XYZ_F32.mEntries[6] = new Entry(DataType.FLOAT, DataKind.Y, false, 32, "y");
+ NORM_ST_XYZ_F32.mEntries[7] = new Entry(DataType.FLOAT, DataKind.Z, false, 32, "z");
+ NORM_ST_XYZ_F32.init(rs);
+
+ rs.nInitElements(A_8.mID, RGBA_4444.mID, RGBA_8888.mID, RGB_565.mID);
}
@@ -121,27 +230,13 @@ public class Element extends BaseObj {
}
}
-
- Element(int predef, int size) {
+ Element() {
super(null);
mID = 0;
- mPredefinedID = predef;
- mIsPredefined = true;
- mSize = size;
- }
-
- Element(int id, RenderScript rs, int size) {
- super(rs);
- mID = id;
- mPredefinedID = 0;
- mIsPredefined = false;
- mSize = size;
+ mSize = 0;
}
public void destroy() throws IllegalStateException {
- if(mIsPredefined) {
- throw new IllegalStateException("Attempting to destroy a predefined Element.");
- }
super.destroy();
}
@@ -166,27 +261,41 @@ public class Element extends BaseObj {
return b.create();
}
+ static synchronized void internalCreate(RenderScript rs, Element e) {
+ rs.nElementBegin();
+ int bits = 0;
+ for (int ct=0; ct < e.mEntries.length; ct++) {
+ Entry en = e.mEntries[ct];
+ if(en.mElement != null) {
+ //rs.nElementAdd(en.mElement.mID);
+ } else {
+ int norm = 0;
+ if (en.mIsNormalized) {
+ norm = 1;
+ }
+ rs.nElementAdd(en.mKind.mID, en.mType.mID, norm, en.mBits, en.mName);
+ bits += en.mBits;
+ }
+ }
+ e.mID = rs.nElementCreate();
+ e.mSize = (bits + 7) >> 3;
+ }
+
+ void init(RenderScript rs) {
+ mRS = rs;
+ internalCreate(mRS, this);
+ }
+
public static class Builder {
RenderScript mRS;
Entry[] mEntries;
int mEntryCount;
- int mSizeBits;
-
- private class Entry {
- Element mElement;
- Element.DataType mType;
- Element.DataKind mKind;
- boolean mIsNormalized;
- int mBits;
- String mName;
- }
public Builder(RenderScript rs) {
mRS = rs;
mEntryCount = 0;
mEntries = new Entry[8];
- mSizeBits = 0;
}
void addEntry(Entry e) {
@@ -200,24 +309,13 @@ public class Element extends BaseObj {
}
public Builder add(Element e) throws IllegalArgumentException {
- if(!e.mIsPredefined) {
- throw new IllegalArgumentException("add requires a predefined Element.");
- }
- Entry en = new Entry();
- en.mElement = e;
+ Entry en = new Entry(e, e.mSize * 8);
addEntry(en);
- mSizeBits += e.mSize * 8;
return this;
}
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;
- mSizeBits += bits;
+ Entry en = new Entry(dt, dk, isNormalized, bits, name);
addEntry(en);
return this;
}
@@ -345,26 +443,12 @@ public class Element extends BaseObj {
return this;
}
- static synchronized Element internalCreate(RenderScript rs, Builder b) {
- rs.nElementBegin();
- for (int ct=0; ct < b.mEntryCount; ct++) {
- Entry en = b.mEntries[ct];
- if(en.mElement != null) {
- rs.nElementAddPredefined(en.mElement.mPredefinedID);
- } else {
- int norm = 0;
- if (en.mIsNormalized) {
- norm = 1;
- }
- rs.nElementAdd(en.mKind.mID, en.mType.mID, norm, en.mBits, en.mName);
- }
- }
- int id = rs.nElementCreate();
- return new Element(id, rs, (b.mSizeBits + 7) >> 3);
- }
-
public Element create() {
- return internalCreate(mRS, this);
+ Element e = new Element();
+ e.mEntries = new Entry[mEntryCount];
+ java.lang.System.arraycopy(mEntries, 0, e.mEntries, 0, mEntryCount);
+ e.init(mRS);
+ return e;
}
}
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index bd345e5..6f5b67e 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -57,6 +57,8 @@ public class RenderScript {
}
}
+ native void nInitElements(int a8, int rgba4444, int rgba8888, int rgb565);
+
native int nDeviceCreate();
native void nDeviceDestroy(int dev);
native int nContextCreate(int dev, Surface sur, int ver, boolean useDepth);
@@ -78,10 +80,8 @@ public class RenderScript {
native int nFileOpen(byte[] name);
native void nElementBegin();
- native void nElementAddPredefined(int predef);
native void nElementAdd(int kind, int type, int norm, int bits, String s);
native int nElementCreate();
- native int nElementGetPredefined(int predef);
native void nTypeBegin(int elementID);
native void nTypeAdd(int dim, int val);
@@ -90,7 +90,6 @@ public class RenderScript {
native void nTypeSetupFields(Type t, int[] types, int[] bits, Field[] IDs);
native int nAllocationCreateTyped(int type);
- native int nAllocationCreatePredefSized(int predef, int count);
native int nAllocationCreateSized(int elem, int count);
native int nAllocationCreateFromBitmap(int dstFmt, boolean genMips, Bitmap bmp);
native int nAllocationCreateFromBitmapBoxed(int dstFmt, boolean genMips, Bitmap bmp);
@@ -203,7 +202,7 @@ public class RenderScript {
// TODO: This should be protected by a lock
if(!mElementsInitialized) {
- Element.init(this);
+ Element.initPredefined(this);
mElementsInitialized = true;
}
}
@@ -227,7 +226,6 @@ public class RenderScript {
}
public void triangleMeshBegin(Element vertex, Element index) {
- Log.e("rs", "vtx " + vertex.toString() + " " + vertex.mID + " " + vertex.mPredefinedID);
nTriangleMeshBegin(vertex.mID, index.mID);
}