diff options
Diffstat (limited to 'graphics/java/android')
4 files changed, 38 insertions, 56 deletions
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java index 97d513a..b937721 100644 --- a/graphics/java/android/renderscript/Allocation.java +++ b/graphics/java/android/renderscript/Allocation.java @@ -55,13 +55,13 @@ public class Allocation extends BaseObj { } } - public enum MipmapGenerationControl { + public enum MipmapControl { MIPMAP_NONE(0), MIPMAP_FULL(1), MIPMAP_ON_SYNC_TO_TEXTURE(2); int mID; - MipmapGenerationControl(int id) { + MipmapControl(int id) { mID = id; } } @@ -131,6 +131,14 @@ public class Allocation extends BaseObj { subData1D(0, mType.getCount(), i); } + private void validateBitmap(Bitmap b) { + mRS.validate(); + if(mType.getX() != b.getWidth() || + mType.getY() != b.getHeight()) { + throw new RSIllegalArgumentException("Cannot update allocation from bitmap, sizes mismatch"); + } + } + public void copyFrom(int[] d) { mRS.validate(); subData1D(0, mType.getCount(), d); @@ -147,18 +155,17 @@ public class Allocation extends BaseObj { mRS.validate(); subData1D(0, mType.getCount(), d); } - public void copyFrom(Bitmap b) { + validateBitmap(b); + mRS.nAllocationCopyFromBitmap(getID(), b); + } - mRS.validate(); - if(mType.getX() != b.getWidth() || - mType.getY() != b.getHeight()) { - throw new RSIllegalArgumentException("Cannot update allocation from bitmap, sizes mismatch"); - } - - mRS.nAllocationUpdateFromBitmap(getID(), b); + public void copyTo(Bitmap b) { + validateBitmap(b); + mRS.nAllocationCopyToBitmap(getID(), b); } + public void subData(int xoff, FieldPacker fp) { int eSize = mType.mElement.getSizeBytes(); final byte[] data = fp.getData(); @@ -423,17 +430,17 @@ public class Allocation extends BaseObj { } static private Type typeFromBitmap(RenderScript rs, Bitmap b, - MipmapGenerationControl mip) { + MipmapControl mip) { Element e = elementFromBitmap(rs, b); Type.Builder tb = new Type.Builder(rs, e); tb.setX(b.getWidth()); tb.setY(b.getHeight()); - tb.setMipmaps(mip == MipmapGenerationControl.MIPMAP_FULL); + tb.setMipmaps(mip == MipmapControl.MIPMAP_FULL); return tb.create(); } static public Allocation createFromBitmap(RenderScript rs, Bitmap b, - MipmapGenerationControl mips, + MipmapControl mips, int usage) { rs.validate(); Type t = typeFromBitmap(rs, b, mips); @@ -447,15 +454,15 @@ public class Allocation extends BaseObj { static public Allocation createFromBitmap(RenderScript rs, Bitmap b, Element dstFmt, boolean genMips) { - MipmapGenerationControl mc = MipmapGenerationControl.MIPMAP_NONE; + MipmapControl mc = MipmapControl.MIPMAP_NONE; if (genMips) { - mc = MipmapGenerationControl.MIPMAP_ON_SYNC_TO_TEXTURE; + mc = MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE; } return createFromBitmap(rs, b, mc, USAGE_ALL); } static public Allocation createCubemapFromBitmap(RenderScript rs, Bitmap b, - MipmapGenerationControl mips, + MipmapControl mips, CubemapLayout layout, int usage) { rs.validate(); @@ -482,7 +489,7 @@ public class Allocation extends BaseObj { tb.setX(width); tb.setY(width); tb.setFaces(true); - tb.setMipmaps(mips == MipmapGenerationControl.MIPMAP_FULL); + tb.setMipmaps(mips == MipmapControl.MIPMAP_FULL); Type t = tb.create(); int id = rs.nAllocationCubeCreateFromBitmap(t.getID(), mips.mID, b, usage); @@ -496,33 +503,17 @@ public class Allocation extends BaseObj { Element dstFmt, boolean genMips, CubemapLayout layout) { - MipmapGenerationControl mc = MipmapGenerationControl.MIPMAP_NONE; + MipmapControl mc = MipmapControl.MIPMAP_NONE; if (genMips) { - mc = MipmapGenerationControl.MIPMAP_ON_SYNC_TO_TEXTURE; + mc = MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE; } return createCubemapFromBitmap(rs, b, mc, layout, USAGE_ALL); } - - static public Allocation createBitmapRef(RenderScript rs, Bitmap b) { - - rs.validate(); - Type t = typeFromBitmap(rs, b, MipmapGenerationControl.MIPMAP_NONE); - - int id = rs.nAllocationCreateBitmapRef(t.getID(), b); - if(id == 0) { - throw new RSRuntimeException("Load failed."); - } - - Allocation a = new Allocation(id, rs, t, USAGE_SCRIPT); - a.mBitmap = b; - return a; - } - static public Allocation createFromBitmapResource(RenderScript rs, Resources res, int id, - MipmapGenerationControl mips, + MipmapControl mips, int usage) { rs.validate(); @@ -537,9 +528,9 @@ public class Allocation extends BaseObj { int id, Element dstFmt, boolean genMips) { - MipmapGenerationControl mc = MipmapGenerationControl.MIPMAP_NONE; + MipmapControl mc = MipmapControl.MIPMAP_NONE; if (genMips) { - mc = MipmapGenerationControl.MIPMAP_ON_SYNC_TO_TEXTURE; + mc = MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE; } return createFromBitmapResource(rs, res, id, mc, USAGE_ALL); } diff --git a/graphics/java/android/renderscript/Element.java b/graphics/java/android/renderscript/Element.java index 7e89a56..7616316 100644 --- a/graphics/java/android/renderscript/Element.java +++ b/graphics/java/android/renderscript/Element.java @@ -654,17 +654,5 @@ public class Element extends BaseObj { return new Element(id, mRS, ein, sin, asin); } } - - static void initPredefined(RenderScript rs) { - int a8 = rs.nElementCreate(DataType.UNSIGNED_8.mID, - DataKind.PIXEL_A.mID, true, 1); - int rgba4444 = rs.nElementCreate(DataType.UNSIGNED_4_4_4_4.mID, - DataKind.PIXEL_RGBA.mID, true, 4); - int rgba8888 = rs.nElementCreate(DataType.UNSIGNED_8.mID, - DataKind.PIXEL_RGBA.mID, true, 4); - int rgb565 = rs.nElementCreate(DataType.UNSIGNED_5_6_5.mID, - DataKind.PIXEL_RGB.mID, true, 3); - rs.nInitElements(a8, rgba4444, rgba8888, rgb565); - } } diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java index e3a9a67..3fa9965 100644 --- a/graphics/java/android/renderscript/RenderScript.java +++ b/graphics/java/android/renderscript/RenderScript.java @@ -65,7 +65,6 @@ public class RenderScript { } // Non-threadsafe functions. - native void nInitElements(int a8, int rgba4444, int rgba8888, int rgb565); native int nDeviceCreate(); native void nDeviceDestroy(int dev); native void nDeviceSetConfig(int dev, int param, int value); @@ -213,13 +212,19 @@ public class RenderScript { return rsnAllocationCreateFromAssetStream(mContext, mips, assetStream, usage); } + native void rsnAllocationCopyToBitmap(int con, int alloc, Bitmap bmp); + synchronized void nAllocationCopyToBitmap(int alloc, Bitmap bmp) { + rsnAllocationCopyToBitmap(mContext, alloc, bmp); + } + + native void rsnAllocationSyncAll(int con, int alloc, int src); synchronized void nAllocationSyncAll(int alloc, int src) { rsnAllocationSyncAll(mContext, alloc, src); } - native void rsnAllocationUpdateFromBitmap(int con, int alloc, Bitmap bmp); - synchronized void nAllocationUpdateFromBitmap(int alloc, Bitmap bmp) { - rsnAllocationUpdateFromBitmap(mContext, alloc, bmp); + native void rsnAllocationCopyFromBitmap(int con, int alloc, Bitmap bmp); + synchronized void nAllocationCopyFromBitmap(int alloc, Bitmap bmp) { + rsnAllocationCopyFromBitmap(mContext, alloc, bmp); } native void rsnAllocationUploadToTexture(int con, int alloc, boolean genMips, int baseMioLevel); @@ -787,7 +792,6 @@ public class RenderScript { rs.mContext = rs.nContextCreate(rs.mDev, 0); rs.mMessageThread = new MessageThread(rs); rs.mMessageThread.start(); - Element.initPredefined(rs); return rs; } diff --git a/graphics/java/android/renderscript/RenderScriptGL.java b/graphics/java/android/renderscript/RenderScriptGL.java index 4a1c40a..0886db4 100644 --- a/graphics/java/android/renderscript/RenderScriptGL.java +++ b/graphics/java/android/renderscript/RenderScriptGL.java @@ -190,7 +190,6 @@ public class RenderScriptGL extends RenderScript { } mMessageThread = new MessageThread(this); mMessageThread.start(); - Element.initPredefined(this); } /** |