Loading graphics/java/android/renderscript/Allocation.java +62 −6 Original line number Diff line number Diff line Loading @@ -34,6 +34,18 @@ public class Allocation extends BaseObj { Type mType; Bitmap mBitmap; public enum CubemapLayout { VERTICAL_FACE_LIST (0), HORIZONTAL_FACE_LIST (1), VERTICAL_CROSS (2), HORIZONTAL_CROSS (3); int mID; CubemapLayout(int id) { mID = id; } } Allocation(int id, RenderScript rs, Type t) { super(id, rs); mType = t; Loading Loading @@ -355,18 +367,21 @@ public class Allocation extends BaseObj { throw new RSInvalidStateException("Bad bitmap type: " + bc); } static private Type typeFromBitmap(RenderScript rs, Bitmap b) { static private Type typeFromBitmap(RenderScript rs, Bitmap b, boolean mip) { Element e = elementFromBitmap(rs, b); Type.Builder tb = new Type.Builder(rs, e); tb.add(Dimension.X, b.getWidth()); tb.add(Dimension.Y, b.getHeight()); if (mip) { tb.add(Dimension.LOD, 1); } return tb.create(); } static public Allocation createFromBitmap(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips) { static public Allocation createFromBitmap(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips) { rs.validate(); Type t = typeFromBitmap(rs, b); Type t = typeFromBitmap(rs, b, genMips); int id = rs.nAllocationCreateFromBitmap(dstFmt.getID(), genMips, b); if(id == 0) { Loading @@ -375,10 +390,49 @@ public class Allocation extends BaseObj { return new Allocation(id, rs, t); } static public Allocation createCubemapFromBitmap(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips, CubemapLayout layout) { rs.validate(); int height = b.getHeight(); int width = b.getWidth(); if (layout != CubemapLayout.VERTICAL_FACE_LIST) { throw new RSIllegalArgumentException("Only vertical face list supported"); } if (height % 6 != 0) { throw new RSIllegalArgumentException("Cubemap height must be multiple of 6"); } if (height / 6 != width) { throw new RSIllegalArgumentException("Only square cobe map faces supported"); } boolean isPow2 = (width & (width - 1)) == 0; if (!isPow2) { throw new RSIllegalArgumentException("Only power of 2 cube faces supported"); } Element e = elementFromBitmap(rs, b); Type.Builder tb = new Type.Builder(rs, e); tb.add(Dimension.X, width); tb.add(Dimension.Y, width); tb.add(Dimension.FACE, 1); if (genMips) { tb.add(Dimension.LOD, 1); } Type t = tb.create(); int id = rs.nAllocationCubeCreateFromBitmap(dstFmt.getID(), genMips, b); if(id == 0) { throw new RSRuntimeException("Load failed for bitmap " + b + " element " + e); } return new Allocation(id, rs, t); } static public Allocation createBitmapRef(RenderScript rs, Bitmap b) { rs.validate(); Type t = typeFromBitmap(rs, b); Type t = typeFromBitmap(rs, b, false); int id = rs.nAllocationCreateBitmapRef(t.getID(), b); if(id == 0) { Loading @@ -404,7 +458,9 @@ public class Allocation extends BaseObj { if (aId == 0) { throw new RSRuntimeException("Load failed."); } return new Allocation(aId, rs, null); Allocation alloc = new Allocation(aId, rs, null); alloc.updateFromNative(); return alloc; } finally { if (is != null) { try { Loading graphics/java/android/renderscript/Program.java +50 −5 Original line number Diff line number Diff line Loading @@ -36,9 +36,32 @@ public class Program extends BaseObj { public static final int MAX_CONSTANT = 8; public static final int MAX_TEXTURE = 8; public enum TextureType { TEXTURE_2D (0), TEXTURE_CUBE (1); int mID; TextureType(int id) { mID = id; } } enum ProgramParam { INPUT (0), OUTPUT (1), CONSTANT (2), TEXTURE_TYPE (3); int mID; ProgramParam(int id) { mID = id; } }; Element mInputs[]; Element mOutputs[]; Type mConstants[]; TextureType mTextures[]; int mTextureCount; String mShader; Loading @@ -54,7 +77,8 @@ public class Program extends BaseObj { a.getType().getID() != mConstants[slot].getID()) { throw new IllegalArgumentException("Allocation type does not match slot type."); } mRS.nProgramBindConstants(getID(), slot, a.getID()); int id = a != null ? a.getID() : 0; mRS.nProgramBindConstants(getID(), slot, id); } public void bindTexture(Allocation va, int slot) Loading @@ -63,8 +87,13 @@ public class Program extends BaseObj { if ((slot < 0) || (slot >= mTextureCount)) { throw new IllegalArgumentException("Slot ID out of range."); } if (va != null && va.getType().getFaces() && mTextures[slot] != TextureType.TEXTURE_CUBE) { throw new IllegalArgumentException("Cannot bind cubemap to 2d texture slot"); } mRS.nProgramBindTexture(getID(), slot, va.getID()); int id = va != null ? va.getID() : 0; mRS.nProgramBindTexture(getID(), slot, id); } public void bindSampler(Sampler vs, int slot) Loading @@ -74,7 +103,8 @@ public class Program extends BaseObj { throw new IllegalArgumentException("Slot ID out of range."); } mRS.nProgramBindSampler(getID(), slot, vs.getID()); int id = vs != null ? vs.getID() : 0; mRS.nProgramBindSampler(getID(), slot, id); } Loading @@ -84,6 +114,7 @@ public class Program extends BaseObj { Element mOutputs[]; Type mConstants[]; Type mTextures[]; TextureType mTextureTypes[]; int mInputCount; int mOutputCount; int mConstantCount; Loading @@ -100,6 +131,7 @@ public class Program extends BaseObj { mOutputCount = 0; mConstantCount = 0; mTextureCount = 0; mTextureTypes = new TextureType[MAX_TEXTURE]; } public BaseProgramBuilder setShader(String s) { Loading Loading @@ -192,6 +224,17 @@ public class Program extends BaseObj { throw new IllegalArgumentException("Max texture count exceeded."); } mTextureCount = count; for (int i = 0; i < mTextureCount; i ++) { mTextureTypes[i] = TextureType.TEXTURE_2D; } return this; } public BaseProgramBuilder addTexture(TextureType texType) throws IllegalArgumentException { if(mTextureCount >= MAX_TEXTURE) { throw new IllegalArgumentException("Max texture count exceeded."); } mTextureTypes[mTextureCount ++] = texType; return this; } Loading @@ -203,6 +246,8 @@ public class Program extends BaseObj { p.mConstants = new Type[mConstantCount]; System.arraycopy(mConstants, 0, p.mConstants, 0, mConstantCount); p.mTextureCount = mTextureCount; p.mTextures = new TextureType[mTextureCount]; System.arraycopy(mTextureTypes, 0, p.mTextures, 0, mTextureCount); } } Loading graphics/java/android/renderscript/ProgramFragment.java +8 −6 Original line number Diff line number Diff line Loading @@ -37,23 +37,25 @@ public class ProgramFragment extends Program { public ProgramFragment create() { mRS.validate(); int[] tmp = new int[(mInputCount + mOutputCount + mConstantCount + 1) * 2]; int[] tmp = new int[(mInputCount + mOutputCount + mConstantCount + mTextureCount) * 2]; int idx = 0; for (int i=0; i < mInputCount; i++) { tmp[idx++] = 0; tmp[idx++] = ProgramParam.INPUT.mID; tmp[idx++] = mInputs[i].getID(); } for (int i=0; i < mOutputCount; i++) { tmp[idx++] = 1; tmp[idx++] = ProgramParam.OUTPUT.mID; tmp[idx++] = mOutputs[i].getID(); } for (int i=0; i < mConstantCount; i++) { tmp[idx++] = 2; tmp[idx++] = ProgramParam.CONSTANT.mID; tmp[idx++] = mConstants[i].getID(); } tmp[idx++] = 3; tmp[idx++] = mTextureCount; for (int i=0; i < mTextureCount; i++) { tmp[idx++] = ProgramParam.TEXTURE_TYPE.mID; tmp[idx++] = mTextureTypes[i].mID; } int id = mRS.nProgramFragmentCreate(mShader, tmp); ProgramFragment pf = new ProgramFragment(id, mRS); Loading graphics/java/android/renderscript/ProgramVertex.java +8 −6 Original line number Diff line number Diff line Loading @@ -46,23 +46,25 @@ public class ProgramVertex extends Program { public ProgramVertex create() { mRS.validate(); int[] tmp = new int[(mInputCount + mOutputCount + mConstantCount +1) * 2]; int[] tmp = new int[(mInputCount + mOutputCount + mConstantCount + mTextureCount) * 2]; int idx = 0; for (int i=0; i < mInputCount; i++) { tmp[idx++] = 0; tmp[idx++] = ProgramParam.INPUT.mID; tmp[idx++] = mInputs[i].getID(); } for (int i=0; i < mOutputCount; i++) { tmp[idx++] = 1; tmp[idx++] = ProgramParam.OUTPUT.mID; tmp[idx++] = mOutputs[i].getID(); } for (int i=0; i < mConstantCount; i++) { tmp[idx++] = 2; tmp[idx++] = ProgramParam.CONSTANT.mID; tmp[idx++] = mConstants[i].getID(); } tmp[idx++] = 3; tmp[idx++] = mTextureCount; for (int i=0; i < mTextureCount; i++) { tmp[idx++] = ProgramParam.TEXTURE_TYPE.mID; tmp[idx++] = mTextureTypes[i].mID; } int id = mRS.nProgramVertexCreate(mShader, tmp); ProgramVertex pv = new ProgramVertex(id, mRS); Loading graphics/java/android/renderscript/RenderScript.java +4 −0 Original line number Diff line number Diff line Loading @@ -204,6 +204,10 @@ public class RenderScript { synchronized int nAllocationCreateFromBitmap(int dstFmt, boolean genMips, Bitmap bmp) { return rsnAllocationCreateFromBitmap(mContext, dstFmt, genMips, bmp); } native int rsnAllocationCubeCreateFromBitmap(int con, int dstFmt, boolean genMips, Bitmap bmp); synchronized int nAllocationCubeCreateFromBitmap(int dstFmt, boolean genMips, Bitmap bmp) { return rsnAllocationCubeCreateFromBitmap(mContext, dstFmt, genMips, bmp); } native int rsnAllocationCreateBitmapRef(int con, int type, Bitmap bmp); synchronized int nAllocationCreateBitmapRef(int type, Bitmap bmp) { return rsnAllocationCreateBitmapRef(mContext, type, bmp); Loading Loading
graphics/java/android/renderscript/Allocation.java +62 −6 Original line number Diff line number Diff line Loading @@ -34,6 +34,18 @@ public class Allocation extends BaseObj { Type mType; Bitmap mBitmap; public enum CubemapLayout { VERTICAL_FACE_LIST (0), HORIZONTAL_FACE_LIST (1), VERTICAL_CROSS (2), HORIZONTAL_CROSS (3); int mID; CubemapLayout(int id) { mID = id; } } Allocation(int id, RenderScript rs, Type t) { super(id, rs); mType = t; Loading Loading @@ -355,18 +367,21 @@ public class Allocation extends BaseObj { throw new RSInvalidStateException("Bad bitmap type: " + bc); } static private Type typeFromBitmap(RenderScript rs, Bitmap b) { static private Type typeFromBitmap(RenderScript rs, Bitmap b, boolean mip) { Element e = elementFromBitmap(rs, b); Type.Builder tb = new Type.Builder(rs, e); tb.add(Dimension.X, b.getWidth()); tb.add(Dimension.Y, b.getHeight()); if (mip) { tb.add(Dimension.LOD, 1); } return tb.create(); } static public Allocation createFromBitmap(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips) { static public Allocation createFromBitmap(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips) { rs.validate(); Type t = typeFromBitmap(rs, b); Type t = typeFromBitmap(rs, b, genMips); int id = rs.nAllocationCreateFromBitmap(dstFmt.getID(), genMips, b); if(id == 0) { Loading @@ -375,10 +390,49 @@ public class Allocation extends BaseObj { return new Allocation(id, rs, t); } static public Allocation createCubemapFromBitmap(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips, CubemapLayout layout) { rs.validate(); int height = b.getHeight(); int width = b.getWidth(); if (layout != CubemapLayout.VERTICAL_FACE_LIST) { throw new RSIllegalArgumentException("Only vertical face list supported"); } if (height % 6 != 0) { throw new RSIllegalArgumentException("Cubemap height must be multiple of 6"); } if (height / 6 != width) { throw new RSIllegalArgumentException("Only square cobe map faces supported"); } boolean isPow2 = (width & (width - 1)) == 0; if (!isPow2) { throw new RSIllegalArgumentException("Only power of 2 cube faces supported"); } Element e = elementFromBitmap(rs, b); Type.Builder tb = new Type.Builder(rs, e); tb.add(Dimension.X, width); tb.add(Dimension.Y, width); tb.add(Dimension.FACE, 1); if (genMips) { tb.add(Dimension.LOD, 1); } Type t = tb.create(); int id = rs.nAllocationCubeCreateFromBitmap(dstFmt.getID(), genMips, b); if(id == 0) { throw new RSRuntimeException("Load failed for bitmap " + b + " element " + e); } return new Allocation(id, rs, t); } static public Allocation createBitmapRef(RenderScript rs, Bitmap b) { rs.validate(); Type t = typeFromBitmap(rs, b); Type t = typeFromBitmap(rs, b, false); int id = rs.nAllocationCreateBitmapRef(t.getID(), b); if(id == 0) { Loading @@ -404,7 +458,9 @@ public class Allocation extends BaseObj { if (aId == 0) { throw new RSRuntimeException("Load failed."); } return new Allocation(aId, rs, null); Allocation alloc = new Allocation(aId, rs, null); alloc.updateFromNative(); return alloc; } finally { if (is != null) { try { Loading
graphics/java/android/renderscript/Program.java +50 −5 Original line number Diff line number Diff line Loading @@ -36,9 +36,32 @@ public class Program extends BaseObj { public static final int MAX_CONSTANT = 8; public static final int MAX_TEXTURE = 8; public enum TextureType { TEXTURE_2D (0), TEXTURE_CUBE (1); int mID; TextureType(int id) { mID = id; } } enum ProgramParam { INPUT (0), OUTPUT (1), CONSTANT (2), TEXTURE_TYPE (3); int mID; ProgramParam(int id) { mID = id; } }; Element mInputs[]; Element mOutputs[]; Type mConstants[]; TextureType mTextures[]; int mTextureCount; String mShader; Loading @@ -54,7 +77,8 @@ public class Program extends BaseObj { a.getType().getID() != mConstants[slot].getID()) { throw new IllegalArgumentException("Allocation type does not match slot type."); } mRS.nProgramBindConstants(getID(), slot, a.getID()); int id = a != null ? a.getID() : 0; mRS.nProgramBindConstants(getID(), slot, id); } public void bindTexture(Allocation va, int slot) Loading @@ -63,8 +87,13 @@ public class Program extends BaseObj { if ((slot < 0) || (slot >= mTextureCount)) { throw new IllegalArgumentException("Slot ID out of range."); } if (va != null && va.getType().getFaces() && mTextures[slot] != TextureType.TEXTURE_CUBE) { throw new IllegalArgumentException("Cannot bind cubemap to 2d texture slot"); } mRS.nProgramBindTexture(getID(), slot, va.getID()); int id = va != null ? va.getID() : 0; mRS.nProgramBindTexture(getID(), slot, id); } public void bindSampler(Sampler vs, int slot) Loading @@ -74,7 +103,8 @@ public class Program extends BaseObj { throw new IllegalArgumentException("Slot ID out of range."); } mRS.nProgramBindSampler(getID(), slot, vs.getID()); int id = vs != null ? vs.getID() : 0; mRS.nProgramBindSampler(getID(), slot, id); } Loading @@ -84,6 +114,7 @@ public class Program extends BaseObj { Element mOutputs[]; Type mConstants[]; Type mTextures[]; TextureType mTextureTypes[]; int mInputCount; int mOutputCount; int mConstantCount; Loading @@ -100,6 +131,7 @@ public class Program extends BaseObj { mOutputCount = 0; mConstantCount = 0; mTextureCount = 0; mTextureTypes = new TextureType[MAX_TEXTURE]; } public BaseProgramBuilder setShader(String s) { Loading Loading @@ -192,6 +224,17 @@ public class Program extends BaseObj { throw new IllegalArgumentException("Max texture count exceeded."); } mTextureCount = count; for (int i = 0; i < mTextureCount; i ++) { mTextureTypes[i] = TextureType.TEXTURE_2D; } return this; } public BaseProgramBuilder addTexture(TextureType texType) throws IllegalArgumentException { if(mTextureCount >= MAX_TEXTURE) { throw new IllegalArgumentException("Max texture count exceeded."); } mTextureTypes[mTextureCount ++] = texType; return this; } Loading @@ -203,6 +246,8 @@ public class Program extends BaseObj { p.mConstants = new Type[mConstantCount]; System.arraycopy(mConstants, 0, p.mConstants, 0, mConstantCount); p.mTextureCount = mTextureCount; p.mTextures = new TextureType[mTextureCount]; System.arraycopy(mTextureTypes, 0, p.mTextures, 0, mTextureCount); } } Loading
graphics/java/android/renderscript/ProgramFragment.java +8 −6 Original line number Diff line number Diff line Loading @@ -37,23 +37,25 @@ public class ProgramFragment extends Program { public ProgramFragment create() { mRS.validate(); int[] tmp = new int[(mInputCount + mOutputCount + mConstantCount + 1) * 2]; int[] tmp = new int[(mInputCount + mOutputCount + mConstantCount + mTextureCount) * 2]; int idx = 0; for (int i=0; i < mInputCount; i++) { tmp[idx++] = 0; tmp[idx++] = ProgramParam.INPUT.mID; tmp[idx++] = mInputs[i].getID(); } for (int i=0; i < mOutputCount; i++) { tmp[idx++] = 1; tmp[idx++] = ProgramParam.OUTPUT.mID; tmp[idx++] = mOutputs[i].getID(); } for (int i=0; i < mConstantCount; i++) { tmp[idx++] = 2; tmp[idx++] = ProgramParam.CONSTANT.mID; tmp[idx++] = mConstants[i].getID(); } tmp[idx++] = 3; tmp[idx++] = mTextureCount; for (int i=0; i < mTextureCount; i++) { tmp[idx++] = ProgramParam.TEXTURE_TYPE.mID; tmp[idx++] = mTextureTypes[i].mID; } int id = mRS.nProgramFragmentCreate(mShader, tmp); ProgramFragment pf = new ProgramFragment(id, mRS); Loading
graphics/java/android/renderscript/ProgramVertex.java +8 −6 Original line number Diff line number Diff line Loading @@ -46,23 +46,25 @@ public class ProgramVertex extends Program { public ProgramVertex create() { mRS.validate(); int[] tmp = new int[(mInputCount + mOutputCount + mConstantCount +1) * 2]; int[] tmp = new int[(mInputCount + mOutputCount + mConstantCount + mTextureCount) * 2]; int idx = 0; for (int i=0; i < mInputCount; i++) { tmp[idx++] = 0; tmp[idx++] = ProgramParam.INPUT.mID; tmp[idx++] = mInputs[i].getID(); } for (int i=0; i < mOutputCount; i++) { tmp[idx++] = 1; tmp[idx++] = ProgramParam.OUTPUT.mID; tmp[idx++] = mOutputs[i].getID(); } for (int i=0; i < mConstantCount; i++) { tmp[idx++] = 2; tmp[idx++] = ProgramParam.CONSTANT.mID; tmp[idx++] = mConstants[i].getID(); } tmp[idx++] = 3; tmp[idx++] = mTextureCount; for (int i=0; i < mTextureCount; i++) { tmp[idx++] = ProgramParam.TEXTURE_TYPE.mID; tmp[idx++] = mTextureTypes[i].mID; } int id = mRS.nProgramVertexCreate(mShader, tmp); ProgramVertex pv = new ProgramVertex(id, mRS); Loading
graphics/java/android/renderscript/RenderScript.java +4 −0 Original line number Diff line number Diff line Loading @@ -204,6 +204,10 @@ public class RenderScript { synchronized int nAllocationCreateFromBitmap(int dstFmt, boolean genMips, Bitmap bmp) { return rsnAllocationCreateFromBitmap(mContext, dstFmt, genMips, bmp); } native int rsnAllocationCubeCreateFromBitmap(int con, int dstFmt, boolean genMips, Bitmap bmp); synchronized int nAllocationCubeCreateFromBitmap(int dstFmt, boolean genMips, Bitmap bmp) { return rsnAllocationCubeCreateFromBitmap(mContext, dstFmt, genMips, bmp); } native int rsnAllocationCreateBitmapRef(int con, int type, Bitmap bmp); synchronized int nAllocationCreateBitmapRef(int type, Bitmap bmp) { return rsnAllocationCreateBitmapRef(mContext, type, bmp); Loading