diff options
Diffstat (limited to 'graphics/java/android/renderscript')
21 files changed, 630 insertions, 152 deletions
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java index b8564b6..5d1990a 100644 --- a/graphics/java/android/renderscript/Allocation.java +++ b/graphics/java/android/renderscript/Allocation.java @@ -18,6 +18,7 @@ package android.renderscript; import java.io.IOException; import java.io.InputStream; +import java.util.HashMap; import android.content.res.Resources; import android.content.res.AssetManager; import android.graphics.Bitmap; @@ -92,6 +93,9 @@ public class Allocation extends BaseObj { int mCurrentDimY; int mCurrentDimZ; int mCurrentCount; + static HashMap<Integer, Allocation> mAllocationMap = + new HashMap<Integer, Allocation>(); + IoInputNotifier mBufferNotifier; /** @@ -362,11 +366,20 @@ public class Allocation extends BaseObj { */ public void syncAll(int srcLocation) { switch (srcLocation) { + case USAGE_GRAPHICS_TEXTURE: case USAGE_SCRIPT: + if ((mUsage & USAGE_SHARED) != 0) { + copyFrom(mBitmap); + } + break; case USAGE_GRAPHICS_CONSTANTS: - case USAGE_GRAPHICS_TEXTURE: case USAGE_GRAPHICS_VERTEX: break; + case USAGE_SHARED: + if ((mUsage & USAGE_SHARED) != 0) { + copyTo(mBitmap); + } + break; default: throw new RSIllegalArgumentException("Source must be exactly one usage type."); } @@ -492,7 +505,9 @@ public class Allocation extends BaseObj { */ public void copyFromUnchecked(int[] d) { mRS.validate(); - if (mCurrentDimY > 0) { + if (mCurrentDimZ > 0) { + copy3DRangeFromUnchecked(0, 0, 0, mCurrentDimX, mCurrentDimY, mCurrentDimZ, d); + } else if (mCurrentDimY > 0) { copy2DRangeFromUnchecked(0, 0, mCurrentDimX, mCurrentDimY, d); } else { copy1DRangeFromUnchecked(0, mCurrentCount, d); @@ -507,7 +522,9 @@ public class Allocation extends BaseObj { */ public void copyFromUnchecked(short[] d) { mRS.validate(); - if (mCurrentDimY > 0) { + if (mCurrentDimZ > 0) { + copy3DRangeFromUnchecked(0, 0, 0, mCurrentDimX, mCurrentDimY, mCurrentDimZ, d); + } else if (mCurrentDimY > 0) { copy2DRangeFromUnchecked(0, 0, mCurrentDimX, mCurrentDimY, d); } else { copy1DRangeFromUnchecked(0, mCurrentCount, d); @@ -522,7 +539,9 @@ public class Allocation extends BaseObj { */ public void copyFromUnchecked(byte[] d) { mRS.validate(); - if (mCurrentDimY > 0) { + if (mCurrentDimZ > 0) { + copy3DRangeFromUnchecked(0, 0, 0, mCurrentDimX, mCurrentDimY, mCurrentDimZ, d); + } else if (mCurrentDimY > 0) { copy2DRangeFromUnchecked(0, 0, mCurrentDimX, mCurrentDimY, d); } else { copy1DRangeFromUnchecked(0, mCurrentCount, d); @@ -537,7 +556,9 @@ public class Allocation extends BaseObj { */ public void copyFromUnchecked(float[] d) { mRS.validate(); - if (mCurrentDimY > 0) { + if (mCurrentDimZ > 0) { + copy3DRangeFromUnchecked(0, 0, 0, mCurrentDimX, mCurrentDimY, mCurrentDimZ, d); + } else if (mCurrentDimY > 0) { copy2DRangeFromUnchecked(0, 0, mCurrentDimX, mCurrentDimY, d); } else { copy1DRangeFromUnchecked(0, mCurrentCount, d); @@ -553,7 +574,9 @@ public class Allocation extends BaseObj { */ public void copyFrom(int[] d) { mRS.validate(); - if (mCurrentDimY > 0) { + if (mCurrentDimZ > 0) { + copy3DRangeFrom(0, 0, 0, mCurrentDimX, mCurrentDimY, mCurrentDimZ, d); + } else if (mCurrentDimY > 0) { copy2DRangeFrom(0, 0, mCurrentDimX, mCurrentDimY, d); } else { copy1DRangeFrom(0, mCurrentCount, d); @@ -569,7 +592,9 @@ public class Allocation extends BaseObj { */ public void copyFrom(short[] d) { mRS.validate(); - if (mCurrentDimY > 0) { + if (mCurrentDimZ > 0) { + copy3DRangeFrom(0, 0, 0, mCurrentDimX, mCurrentDimY, mCurrentDimZ, d); + } else if (mCurrentDimY > 0) { copy2DRangeFrom(0, 0, mCurrentDimX, mCurrentDimY, d); } else { copy1DRangeFrom(0, mCurrentCount, d); @@ -585,7 +610,9 @@ public class Allocation extends BaseObj { */ public void copyFrom(byte[] d) { mRS.validate(); - if (mCurrentDimY > 0) { + if (mCurrentDimZ > 0) { + copy3DRangeFrom(0, 0, 0, mCurrentDimX, mCurrentDimY, mCurrentDimZ, d); + } else if (mCurrentDimY > 0) { copy2DRangeFrom(0, 0, mCurrentDimX, mCurrentDimY, d); } else { copy1DRangeFrom(0, mCurrentCount, d); @@ -601,7 +628,9 @@ public class Allocation extends BaseObj { */ public void copyFrom(float[] d) { mRS.validate(); - if (mCurrentDimY > 0) { + if (mCurrentDimZ > 0) { + copy3DRangeFrom(0, 0, 0, mCurrentDimX, mCurrentDimY, mCurrentDimZ, d); + } else if (mCurrentDimY > 0) { copy2DRangeFrom(0, 0, mCurrentDimX, mCurrentDimY, d); } else { copy1DRangeFrom(0, mCurrentCount, d); @@ -967,12 +996,144 @@ public class Allocation extends BaseObj { Canvas c = new Canvas(newBitmap); c.drawBitmap(data, 0, 0, null); copy2DRangeFrom(xoff, yoff, newBitmap); + return; } validateBitmapFormat(data); validate2DRange(xoff, yoff, data.getWidth(), data.getHeight()); mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, data); } + private void validate3DRange(int xoff, int yoff, int zoff, int w, int h, int d) { + if (mAdaptedAllocation != null) { + + } else { + + if (xoff < 0 || yoff < 0 || zoff < 0) { + throw new RSIllegalArgumentException("Offset cannot be negative."); + } + if (h < 0 || w < 0 || d < 0) { + throw new RSIllegalArgumentException("Height or width cannot be negative."); + } + if (((xoff + w) > mCurrentDimX) || ((yoff + h) > mCurrentDimY) || ((zoff + d) > mCurrentDimZ)) { + throw new RSIllegalArgumentException("Updated region larger than allocation."); + } + } + } + + /** + * @hide + * + */ + void copy3DRangeFromUnchecked(int xoff, int yoff, int zoff, int w, int h, int d, byte[] data) { + mRS.validate(); + validate3DRange(xoff, yoff, zoff, w, h, d); + mRS.nAllocationData3D(getIDSafe(), xoff, yoff, zoff, mSelectedLOD, + w, h, d, data, data.length); + } + + /** + * @hide + * + */ + void copy3DRangeFromUnchecked(int xoff, int yoff, int zoff, int w, int h, int d, short[] data) { + mRS.validate(); + validate3DRange(xoff, yoff, zoff, w, h, d); + mRS.nAllocationData3D(getIDSafe(), xoff, yoff, zoff, mSelectedLOD, + w, h, d, data, data.length * 2); + } + + /** + * @hide + * + */ + void copy3DRangeFromUnchecked(int xoff, int yoff, int zoff, int w, int h, int d, int[] data) { + mRS.validate(); + validate3DRange(xoff, yoff, zoff, w, h, d); + mRS.nAllocationData3D(getIDSafe(), xoff, yoff, zoff, mSelectedLOD, + w, h, d, data, data.length * 4); + } + + /** + * @hide + * + */ + void copy3DRangeFromUnchecked(int xoff, int yoff, int zoff, int w, int h, int d, float[] data) { + mRS.validate(); + validate3DRange(xoff, yoff, zoff, w, h, d); + mRS.nAllocationData3D(getIDSafe(), xoff, yoff, zoff, mSelectedLOD, + w, h, d, data, data.length * 4); + } + + + /** + * @hide + * Copy a rectangular region from the array into the allocation. + * The incoming array is assumed to be tightly packed. + * + * @param xoff X offset of the region to update + * @param yoff Y offset of the region to update + * @param zoff Z offset of the region to update + * @param w Width of the incoming region to update + * @param h Height of the incoming region to update + * @param d Depth of the incoming region to update + * @param data to be placed into the allocation + */ + public void copy3DRangeFrom(int xoff, int yoff, int zoff, int w, int h, int d, byte[] data) { + validateIsInt8(); + copy3DRangeFromUnchecked(xoff, yoff, zoff, w, h, d, data); + } + + /** + * @hide + * + */ + public void copy3DRangeFrom(int xoff, int yoff, int zoff, int w, int h, int d, short[] data) { + validateIsInt16(); + copy3DRangeFromUnchecked(xoff, yoff, zoff, w, h, d, data); + } + + /** + * @hide + * + */ + public void copy3DRangeFrom(int xoff, int yoff, int zoff, int w, int h, int d, int[] data) { + validateIsInt32(); + copy3DRangeFromUnchecked(xoff, yoff, zoff, w, h, d, data); + } + + /** + * @hide + * + */ + public void copy3DRangeFrom(int xoff, int yoff, int zoff, int w, int h, int d, float[] data) { + validateIsFloat32(); + copy3DRangeFromUnchecked(xoff, yoff, zoff, w, h, d, data); + } + + /** + * @hide + * Copy a rectangular region into the allocation from another + * allocation. + * + * @param xoff X offset of the region to update. + * @param yoff Y offset of the region to update. + * @param w Width of the incoming region to update. + * @param h Height of the incoming region to update. + * @param d Depth of the incoming region to update. + * @param data source allocation. + * @param dataXoff X offset in data of the region to update. + * @param dataYoff Y offset in data of the region to update. + * @param dataZoff Z offset in data of the region to update + */ + public void copy3DRangeFrom(int xoff, int yoff, int zoff, int w, int h, int d, + Allocation data, int dataXoff, int dataYoff, int dataZoff) { + mRS.validate(); + validate3DRange(xoff, yoff, zoff, w, h, d); + mRS.nAllocationData3D(getIDSafe(), xoff, yoff, zoff, mSelectedLOD, + w, h, d, data.getID(mRS), dataXoff, dataYoff, dataZoff, + data.mSelectedLOD); + } + /** * Copy from the Allocation into a Bitmap. The bitmap must @@ -1050,6 +1211,10 @@ public class Allocation extends BaseObj { * A new type will be created with the new dimension. * * @param dimX The new size of the allocation. + * + * @deprecated Renderscript objects should be immutable once + * created. The replacement is to create a new allocation and copy the + * contents. */ public synchronized void resize(int dimX) { if ((mType.getY() > 0)|| (mType.getZ() > 0) || mType.hasFaces() || mType.hasMipmaps()) { @@ -1064,38 +1229,6 @@ public class Allocation extends BaseObj { updateCacheInfo(mType); } - /** - * Resize a 2D allocation. The contents of the allocation are - * preserved. If new elements are allocated objects are created - * with null contents and the new region is otherwise undefined. - * - * If the new region is smaller the references of any objects - * outside the new region will be released. - * - * A new type will be created with the new dimension. - * - * @param dimX The new size of the allocation. - * @param dimY The new size of the allocation. - */ - public synchronized void resize(int dimX, int dimY) { - if ((mType.getZ() > 0) || mType.hasFaces() || mType.hasMipmaps()) { - throw new RSInvalidStateException( - "Resize only support for 2D allocations at this time."); - } - if (mType.getY() == 0) { - throw new RSInvalidStateException( - "Resize only support for 2D allocations at this time."); - } - mRS.nAllocationResize2D(getID(mRS), dimX, dimY); - mRS.finish(); // Necessary because resize is fifoed and update is async. - - int typeID = mRS.nAllocationGetType(getID(mRS)); - mType = new Type(typeID, mRS); - mType.updateFromNative(); - updateCacheInfo(mType); - } - - // creation @@ -1254,7 +1387,7 @@ public class Allocation extends BaseObj { // enable optimized bitmap path only with no mipmap and script-only usage if (mips == MipmapControl.MIPMAP_NONE && t.getElement().isCompatible(Element.RGBA_8888(rs)) && - usage == (USAGE_SHARED | USAGE_SCRIPT)) { + usage == (USAGE_SHARED | USAGE_SCRIPT | USAGE_GRAPHICS_TEXTURE)) { int id = rs.nAllocationCreateBitmapBackedAllocation(t.getID(rs), mips.mID, b, usage); if (id == 0) { throw new RSRuntimeException("Load failed."); @@ -1326,7 +1459,7 @@ public class Allocation extends BaseObj { static public Allocation createFromBitmap(RenderScript rs, Bitmap b) { if (rs.getApplicationContext().getApplicationInfo().targetSdkVersion >= 18) { return createFromBitmap(rs, b, MipmapControl.MIPMAP_NONE, - USAGE_SHARED | USAGE_SCRIPT); + USAGE_SHARED | USAGE_SCRIPT | USAGE_GRAPHICS_TEXTURE); } return createFromBitmap(rs, b, MipmapControl.MIPMAP_NONE, USAGE_GRAPHICS_TEXTURE); @@ -1544,7 +1677,7 @@ public class Allocation extends BaseObj { if (rs.getApplicationContext().getApplicationInfo().targetSdkVersion >= 18) { return createFromBitmapResource(rs, res, id, MipmapControl.MIPMAP_NONE, - USAGE_SHARED | USAGE_SCRIPT); + USAGE_SHARED | USAGE_SCRIPT | USAGE_GRAPHICS_TEXTURE); } return createFromBitmapResource(rs, res, id, MipmapControl.MIPMAP_NONE, @@ -1576,6 +1709,41 @@ public class Allocation extends BaseObj { throw new RSRuntimeException("Could not convert string to utf-8."); } } + + /** + * Interface to handle notification when new buffers are + * available via USAGE_IO_INPUT. An application will receive + * one notification when a buffer is available. Additional + * buffers will not trigger new notifications until a buffer is + * processed. + */ + public interface IoInputNotifier { + public void onBufferAvailable(Allocation a); + } + + /** + * Set a notification handler for USAGE_IO_INPUT + * + * @param callback instance of the IoInputNotifier class to be called + * when buffer arrive. + */ + public void setIoInputNotificationHandler(IoInputNotifier callback) { + synchronized(mAllocationMap) { + mAllocationMap.put(new Integer(getID(mRS)), this); + mBufferNotifier = callback; + } + } + + static void sendBufferNotification(int id) { + synchronized(mAllocationMap) { + Allocation a = mAllocationMap.get(new Integer(id)); + + if ((a != null) && (a.mBufferNotifier != null)) { + a.mBufferNotifier.onBufferAvailable(a); + } + } + } + } 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/FileA3D.java b/graphics/java/android/renderscript/FileA3D.java index 42b508b..8b0222a 100644 --- a/graphics/java/android/renderscript/FileA3D.java +++ b/graphics/java/android/renderscript/FileA3D.java @@ -28,6 +28,7 @@ import android.util.Log; import android.util.TypedValue; /** + * @hide * @deprecated in API 16 * FileA3D allows users to load Renderscript objects from files * or resources stored on disk. It could be used to load items diff --git a/graphics/java/android/renderscript/Font.java b/graphics/java/android/renderscript/Font.java index 8a49abb..1a8d5bf 100644 --- a/graphics/java/android/renderscript/Font.java +++ b/graphics/java/android/renderscript/Font.java @@ -30,8 +30,9 @@ import android.util.Log; import android.util.TypedValue; /** + * @hide * @deprecated in API 16 - * <p>This class gives users a simple way to draw hardware accelerated text. + * <p>This class gives users a simple way to draw hardware accelerated text. * Internally, the glyphs are rendered using the Freetype library and an internal cache of * rendered glyph bitmaps is maintained. Each font object represents a combination of a typeface, * and point size. You can create multiple font objects to represent styles such as bold or italic text, @@ -43,7 +44,7 @@ import android.util.TypedValue; * render large batches of text in sequence. It is also more efficient to render multiple * characters at once instead of one by one to improve draw call batching.</p> * <p>Font color and transparency are not part of the font object and you can freely modify - * them in the script to suit the user's rendering needs. Font colors work as a state machine. + * them in the script to suit the user's rendering needs. Font colors work as a state machine. * Every new call to draw text uses the last color set in the script.</p> **/ public class Font extends BaseObj { diff --git a/graphics/java/android/renderscript/Mesh.java b/graphics/java/android/renderscript/Mesh.java index 7210513..d0d383d 100644 --- a/graphics/java/android/renderscript/Mesh.java +++ b/graphics/java/android/renderscript/Mesh.java @@ -21,6 +21,7 @@ import java.util.Vector; import android.util.Log; /** + * @hide * @deprecated in API 16 * <p>This class is a container for geometric data displayed with * Renderscript. Internally, a mesh is a collection of allocations that diff --git a/graphics/java/android/renderscript/Program.java b/graphics/java/android/renderscript/Program.java index d9f64c6..9bd103e 100644 --- a/graphics/java/android/renderscript/Program.java +++ b/graphics/java/android/renderscript/Program.java @@ -26,6 +26,7 @@ import android.util.Log; /** + * @hide * * Program is a base class for all the objects that modify * various stages of the graphics pipeline diff --git a/graphics/java/android/renderscript/ProgramFragment.java b/graphics/java/android/renderscript/ProgramFragment.java index 69968ac..dd0f9f5 100644 --- a/graphics/java/android/renderscript/ProgramFragment.java +++ b/graphics/java/android/renderscript/ProgramFragment.java @@ -21,6 +21,7 @@ import android.util.Log; /** + * @hide * @deprecated in API 16 * <p>The Renderscript fragment program, also known as fragment shader is responsible * for manipulating pixel data in a user defined way. It's constructed from a GLSL diff --git a/graphics/java/android/renderscript/ProgramFragmentFixedFunction.java b/graphics/java/android/renderscript/ProgramFragmentFixedFunction.java index 848c5a3..8ae1777 100644 --- a/graphics/java/android/renderscript/ProgramFragmentFixedFunction.java +++ b/graphics/java/android/renderscript/ProgramFragmentFixedFunction.java @@ -21,6 +21,7 @@ import android.util.Log; /** + * @hide * @deprecated in API 16 * <p>ProgramFragmentFixedFunction is a helper class that provides * a way to make a simple fragment shader without writing any diff --git a/graphics/java/android/renderscript/ProgramRaster.java b/graphics/java/android/renderscript/ProgramRaster.java index c44521b..216cb4e 100644 --- a/graphics/java/android/renderscript/ProgramRaster.java +++ b/graphics/java/android/renderscript/ProgramRaster.java @@ -21,6 +21,7 @@ import android.util.Log; /** + * @hide * @deprecated in API 16 * Program raster is primarily used to specify whether point sprites are enabled and to control * the culling mode. By default, back faces are culled. diff --git a/graphics/java/android/renderscript/ProgramStore.java b/graphics/java/android/renderscript/ProgramStore.java index d0fd6e5..dac9e76 100644 --- a/graphics/java/android/renderscript/ProgramStore.java +++ b/graphics/java/android/renderscript/ProgramStore.java @@ -21,6 +21,7 @@ import android.util.Log; /** + * @hide * <p>ProgramStore contains a set of parameters that control how * the graphics hardware handles writes to the framebuffer. * It could be used to:</p> diff --git a/graphics/java/android/renderscript/ProgramVertex.java b/graphics/java/android/renderscript/ProgramVertex.java index 2bd5124..50e32f6 100644 --- a/graphics/java/android/renderscript/ProgramVertex.java +++ b/graphics/java/android/renderscript/ProgramVertex.java @@ -14,7 +14,8 @@ * limitations under the License. */ - /** +/** + * @hide * <p>The Renderscript vertex program, also known as a vertex shader, describes a stage in * the graphics pipeline responsible for manipulating geometric data in a user-defined way. * The object is constructed by providing the Renderscript system with the following data:</p> @@ -43,6 +44,7 @@ import android.util.Log; /** + * @hide * @deprecated in API 16 * ProgramVertex, also know as a vertex shader, describes a * stage in the graphics pipeline responsible for manipulating @@ -76,14 +78,15 @@ public class ProgramVertex extends Program { } /** - * @deprecated in API 16 - * Builder class for creating ProgramVertex objects. - * The builder starts empty and the user must minimally provide - * the GLSL shader code, and the varying inputs. Constant, or - * uniform parameters to the shader may optionally be provided as - * well. - * - **/ + * @hide + * @deprecated in API 16 + * Builder class for creating ProgramVertex objects. + * The builder starts empty and the user must minimally provide + * the GLSL shader code, and the varying inputs. Constant, or + * uniform parameters to the shader may optionally be provided as + * well. + * + **/ public static class Builder extends BaseProgramBuilder { /** * @deprecated in API 16 diff --git a/graphics/java/android/renderscript/ProgramVertexFixedFunction.java b/graphics/java/android/renderscript/ProgramVertexFixedFunction.java index 88cade4..ad486f3 100644 --- a/graphics/java/android/renderscript/ProgramVertexFixedFunction.java +++ b/graphics/java/android/renderscript/ProgramVertexFixedFunction.java @@ -22,6 +22,7 @@ import android.util.Log; /** + * @hide * @deprecated in API 16 * ProgramVertexFixedFunction is a helper class that provides a * simple way to create a fixed function emulation vertex shader diff --git a/graphics/java/android/renderscript/RSSurfaceView.java b/graphics/java/android/renderscript/RSSurfaceView.java index 82ed95c..3c6c720 100644 --- a/graphics/java/android/renderscript/RSSurfaceView.java +++ b/graphics/java/android/renderscript/RSSurfaceView.java @@ -30,6 +30,7 @@ import android.view.SurfaceHolder; import android.view.SurfaceView; /** + * @hide * @deprecated in API 16 * The Surface View for a graphics renderscript (RenderScriptGL) to draw on. * diff --git a/graphics/java/android/renderscript/RSTextureView.java b/graphics/java/android/renderscript/RSTextureView.java index ed04000..7eeeeae 100644 --- a/graphics/java/android/renderscript/RSTextureView.java +++ b/graphics/java/android/renderscript/RSTextureView.java @@ -29,6 +29,7 @@ import android.util.Log; import android.view.TextureView; /** + * @hide * @deprecated in API 16 * The Texture View for a graphics renderscript (RenderScriptGL) * to draw on. diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java index bef28aa..6f614c3 100644 --- a/graphics/java/android/renderscript/RenderScript.java +++ b/graphics/java/android/renderscript/RenderScript.java @@ -83,11 +83,7 @@ public class RenderScript { native void nContextInitToClient(int con); native void nContextDeinitToClient(int con); - /** - * Name of the file that holds the object cache. - */ - private static final String CACHE_PATH = "com.android.renderscript.cache"; - static String mCachePath; + static File mCacheDir; /** * Sets the directory to use as a persistent storage for the @@ -97,14 +93,33 @@ public class RenderScript { * @param cacheDir A directory the current process can write to */ public static void setupDiskCache(File cacheDir) { - File f = new File(cacheDir, CACHE_PATH); - mCachePath = f.getAbsolutePath(); - f.mkdirs(); + // Defer creation of cache path to nScriptCCreate(). + mCacheDir = cacheDir; } + /** + * ContextType specifies the specific type of context to be created. + * + */ public enum ContextType { + /** + * NORMAL context, this is the default and what shipping apps should + * use. + */ NORMAL (0), + + /** + * DEBUG context, perform extra runtime checks to validate the + * kernels and APIs are being used as intended. Get and SetElementAt + * will be bounds checked in this mode. + */ DEBUG (1), + + /** + * PROFILE context, Intended to be used once the first time an + * application is run on a new device. This mode allows the runtime to + * do additional testing and performance tuning. + */ PROFILE (2); int mID; @@ -420,6 +435,46 @@ public class RenderScript { rsnAllocationData2D(mContext, id, xoff, yoff, mip, face, b); } + native void rsnAllocationData3D(int con, + int dstAlloc, int dstXoff, int dstYoff, int dstZoff, + int dstMip, + int width, int height, int depth, + int srcAlloc, int srcXoff, int srcYoff, int srcZoff, + int srcMip); + synchronized void nAllocationData3D(int dstAlloc, int dstXoff, int dstYoff, int dstZoff, + int dstMip, + int width, int height, int depth, + int srcAlloc, int srcXoff, int srcYoff, int srcZoff, + int srcMip) { + validate(); + rsnAllocationData3D(mContext, + dstAlloc, dstXoff, dstYoff, dstZoff, + dstMip, width, height, depth, + srcAlloc, srcXoff, srcYoff, srcZoff, srcMip); + } + + native void rsnAllocationData3D(int con, int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, byte[] d, int sizeBytes); + synchronized void nAllocationData3D(int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, byte[] d, int sizeBytes) { + validate(); + rsnAllocationData3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes); + } + native void rsnAllocationData3D(int con, int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, short[] d, int sizeBytes); + synchronized void nAllocationData3D(int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, short[] d, int sizeBytes) { + validate(); + rsnAllocationData3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes); + } + native void rsnAllocationData3D(int con, int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, int[] d, int sizeBytes); + synchronized void nAllocationData3D(int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, int[] d, int sizeBytes) { + validate(); + rsnAllocationData3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes); + } + native void rsnAllocationData3D(int con, int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, float[] d, int sizeBytes); + synchronized void nAllocationData3D(int id, int xoff, int yoff, int zoff, int mip, int w, int h, int depth, float[] d, int sizeBytes) { + validate(); + rsnAllocationData3D(mContext, id, xoff, yoff, zoff, mip, w, h, depth, d, sizeBytes); + } + + native void rsnAllocationRead(int con, int id, byte[] d); synchronized void nAllocationRead(int id, byte[] d) { validate(); @@ -451,11 +506,6 @@ public class RenderScript { validate(); rsnAllocationResize1D(mContext, id, dimX); } - native void rsnAllocationResize2D(int con, int id, int dimX, int dimY); - synchronized void nAllocationResize2D(int id, int dimX, int dimY) { - validate(); - rsnAllocationResize2D(mContext, id, dimX, dimY); - } native int rsnFileA3DCreateFromAssetStream(int con, int assetStream); synchronized int nFileA3DCreateFromAssetStream(int assetStream) { @@ -550,31 +600,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, @@ -853,7 +931,8 @@ public class RenderScript { } /** - * @hide + * Place a message into the message queue to be sent back to the message + * handler once all previous commands have been executed. * * @param id * @param data @@ -934,6 +1013,7 @@ public class RenderScript { static final int RS_MESSAGE_TO_CLIENT_RESIZE = 2; static final int RS_MESSAGE_TO_CLIENT_ERROR = 3; static final int RS_MESSAGE_TO_CLIENT_USER = 4; + static final int RS_MESSAGE_TO_CLIENT_NEW_BUFFER = 5; static final int RS_ERROR_FATAL_UNKNOWN = 0x1000; @@ -993,6 +1073,11 @@ public class RenderScript { continue; } + if (msg == RS_MESSAGE_TO_CLIENT_NEW_BUFFER) { + Allocation.sendBufferNotification(subID); + continue; + } + // 2: teardown. // But we want to avoid starving other threads during // teardown by yielding until the next line in the destructor @@ -1061,9 +1146,9 @@ public class RenderScript { /** * Create a basic RenderScript context. * - * @hide * * @param ctx The context. + * @param ct The type of context to be created. * @return RenderScript */ public static RenderScript create(Context ctx, ContextType ct) { diff --git a/graphics/java/android/renderscript/RenderScriptGL.java b/graphics/java/android/renderscript/RenderScriptGL.java index 5269405..52034b1 100644 --- a/graphics/java/android/renderscript/RenderScriptGL.java +++ b/graphics/java/android/renderscript/RenderScriptGL.java @@ -29,6 +29,7 @@ import android.view.SurfaceHolder; import android.view.SurfaceView; /** + * @hide * @deprecated in API 16 * The Graphics derivitive of Renderscript. Extends the basic context to add a * root script which is the display window for graphical output. When the 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/java/android/renderscript/ScriptC.java b/graphics/java/android/renderscript/ScriptC.java index 108b230..221f760 100644 --- a/graphics/java/android/renderscript/ScriptC.java +++ b/graphics/java/android/renderscript/ScriptC.java @@ -62,6 +62,12 @@ public class ScriptC extends Script { setID(id); } + /** + * Name of the file that holds the object cache. + */ + private static final String CACHE_PATH = "com.android.renderscript.cache"; + + static String mCachePath; private static synchronized int internalCreate(RenderScript rs, Resources resources, int resourceID) { byte[] pgm; @@ -94,7 +100,13 @@ public class ScriptC extends Script { String resName = resources.getResourceEntryName(resourceID); + // Create the RS cache path if we haven't done so already. + if (mCachePath == null) { + File f = new File(rs.mCacheDir, CACHE_PATH); + mCachePath = f.getAbsolutePath(); + f.mkdirs(); + } Log.v(TAG, "Create script for resource = " + resName); - return rs.nScriptCCreate(resName, rs.mCachePath, pgm, pgmLength); + return rs.nScriptCCreate(resName, mCachePath, pgm, pgmLength); } } diff --git a/graphics/java/android/renderscript/ScriptIntrinsic3DLUT.java b/graphics/java/android/renderscript/ScriptIntrinsic3DLUT.java index 3e58b87..86f37d8 100644 --- a/graphics/java/android/renderscript/ScriptIntrinsic3DLUT.java +++ b/graphics/java/android/renderscript/ScriptIntrinsic3DLUT.java @@ -20,7 +20,11 @@ import android.util.Log; /** * - * @hide + * Intrinsic for converting RGB to RGBA by using a 3D lookup table. The + * incoming r,g,b values are use as normalized x,y,z coordinates into a 3D + * allocation. The 8 nearest values are sampled and linearly interpolated. The + * result is placed in the output. + * **/ public final class ScriptIntrinsic3DLUT extends ScriptIntrinsic { private Allocation mLUT; diff --git a/graphics/java/android/renderscript/Type.java b/graphics/java/android/renderscript/Type.java index d7c8255..a5e24ce 100644 --- a/graphics/java/android/renderscript/Type.java +++ b/graphics/java/android/renderscript/Type.java @@ -112,7 +112,7 @@ public class Type extends BaseObj { /** * Get the YUV format * - * @hide + * * @return int */ public int getYuv() { @@ -277,7 +277,9 @@ public class Type extends BaseObj { } /** - * @hide + * Set the YUV layout for a Type. This controls how the memory is + * interpreted. Generally and application should not need to call this + * function and it would be set by the Camera. * * only NV21, YV12. Enums from ImageFormat */ diff --git a/graphics/java/android/renderscript/package.html b/graphics/java/android/renderscript/package.html index 5eab23c..eb178c1 100644 --- a/graphics/java/android/renderscript/package.html +++ b/graphics/java/android/renderscript/package.html @@ -1,86 +1,10 @@ <HTML> <BODY> -<p>The Renderscript rendering and computational APIs offer a low-level, high performance means of -carrying out mathematical calculations and 3D graphics rendering.</p> +<p>RenderScript provides support for high-performance computation across heterogeneous processors.</p> <p>For more information, see the -<a href="{@docRoot}guide/topics/renderscript/index.html">Renderscript</a> developer guide.</p> +<a href="{@docRoot}guide/topics/renderscript/index.html">RenderScript</a> developer guide.</p> {@more} -<p>An example of Renderscript in applications include the 3D carousel view that is present in -Android 3.0 applications such as the Books and YouTube applications. This API is intended for -developers who are comfortable working with native code and want to maximize their performance -critical applications.</p> - -<p>Renderscript adopts a control and slave architecture where the low-level native code is controlled by the -higher level Android system that runs in the virtual machine (VM). The VM code handles resource -allocation and lifecycle management of the Renderscript enabled application and calls the Renderscript -code through high level entry points. The Android build tools generate these entry points through reflection on -the native Renderscript code, which you write in C (C99 standard). The Renderscript code -does the intensive computation and returns the result back to the Android VM.</p> - -<p>You can find the Renderscript native -APIs in the <code><sdk_root>/platforms/android-11/renderscript</code> directory. -The Android system APIs are broken into a few main groups:</p> - -<h4>Core</h4> -<p>These classes are used internally by the system for memory allocation. They are used by the classes that -are generated by the build tools:</p> -<ul> - <li>Allocation</li> - <li>Element</li> - <li>Type</li> - <li>Script</li> -</ul> - - -<h4>Data Types</h4> -<p>These data types are used by the classes that are generated -by the build tools. They are the reflected counterparts of the native data types that -are defined by the native Renderscript APIs and used by your Renderscript code. The -classes include:</p> -<ul> - <li>Byte2, Byte3, and Byte4</li> - <li>Float2, Float3, Float4</li> - <li>Int2, Int3, Int4</li> - <li>Long2, Long3, Long4</li> - <li>Matrix2f, Matrix3f, Matrix4f</li> - <li>Short2, Short3, Short4</li> -</ul> - -<p>For example, if you declared the following struct in your .rs Renderscript file:</p> - -<pre>struct Hello { float3 position; rs_matrix4x4 transform; }</pre> - -<p>The build tools generate a class through reflection that looks like the following:</p> -<pre> -class Hello { - static public class Item { - Float4 position; - Matrix4f transform; - } -Element createElement(RenderScript rs) { - Element.Builder eb = new Element.Builder(rs); - eb.add(Element.F32_3(rs), "position"); - eb.add(Element.MATRIX_4X4(rs), "transform"); - return eb.create(); - } -} -</pre> - -<h4>Graphics</h4> -<p>These classes are specific to graphics Renderscripts and support a typical rendering -pipeline.</p> -<ul> -<li>Mesh</li> -<li>ProgramFragment</li> -<li>ProgramRaster</li> -<li>ProgramStore</li> -<li>ProgramVertex</li> -<li>RSSurfaceView</li> -<li>Sampler</li> -</ul> - -</p> </BODY> </HTML> |