diff options
Diffstat (limited to 'rs/java')
-rw-r--r-- | rs/java/android/renderscript/Allocation.java | 260 | ||||
-rw-r--r-- | rs/java/android/renderscript/BaseObj.java | 13 | ||||
-rw-r--r-- | rs/java/android/renderscript/Element.java | 529 | ||||
-rw-r--r-- | rs/java/android/renderscript/FileA3D.java | 1 | ||||
-rw-r--r-- | rs/java/android/renderscript/Font.java | 1 | ||||
-rw-r--r-- | rs/java/android/renderscript/Mesh.java | 1 | ||||
-rw-r--r-- | rs/java/android/renderscript/Program.java | 1 | ||||
-rw-r--r-- | rs/java/android/renderscript/RenderScript.java | 278 | ||||
-rw-r--r-- | rs/java/android/renderscript/RenderScriptGL.java | 4 | ||||
-rw-r--r-- | rs/java/android/renderscript/Sampler.java | 163 | ||||
-rw-r--r-- | rs/java/android/renderscript/Script.java | 113 | ||||
-rw-r--r-- | rs/java/android/renderscript/ScriptC.java | 25 | ||||
-rw-r--r-- | rs/java/android/renderscript/ScriptGroup.java | 46 | ||||
-rw-r--r-- | rs/java/android/renderscript/ScriptIntrinsicBlend.java | 2 | ||||
-rw-r--r-- | rs/java/android/renderscript/ScriptIntrinsicConvolve3x3.java | 9 | ||||
-rw-r--r-- | rs/java/android/renderscript/ScriptIntrinsicConvolve5x5.java | 8 | ||||
-rw-r--r-- | rs/java/android/renderscript/Type.java | 1 |
17 files changed, 1074 insertions, 381 deletions
diff --git a/rs/java/android/renderscript/Allocation.java b/rs/java/android/renderscript/Allocation.java index 0a5059390449..c0ea1324602b 100644 --- a/rs/java/android/renderscript/Allocation.java +++ b/rs/java/android/renderscript/Allocation.java @@ -16,14 +16,16 @@ package android.renderscript; +import java.nio.ByteBuffer; import java.util.HashMap; + import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; -import android.view.Surface; -import android.util.Log; import android.graphics.Canvas; import android.os.Trace; +import android.util.Log; +import android.view.Surface; /** * <p> This class provides the primary method through which data is passed to @@ -53,12 +55,17 @@ import android.os.Trace; **/ public class Allocation extends BaseObj { + private static final int MAX_NUMBER_IO_INPUT_ALLOC = 16; + Type mType; + boolean mOwningType = false; Bitmap mBitmap; int mUsage; Allocation mAdaptedAllocation; int mSize; + MipmapControl mMipmapControl; + long mTimeStamp = -1; boolean mReadAllowed = true; boolean mWriteAllowed = true; boolean mAutoPadding = false; @@ -78,6 +85,8 @@ public class Allocation extends BaseObj { OnBufferAvailableListener mBufferNotifier; private Surface mGetSurfaceSurface = null; + private ByteBuffer mByteBuffer = null; + private long mByteBufferStride = -1; private Element.DataType validateObjectIsPrimitiveArray(Object d, boolean checkType) { final Class c = d.getClass(); @@ -107,7 +116,7 @@ public class Allocation extends BaseObj { if (cmp == Short.TYPE) { if (checkType) { - validateIsInt16(); + validateIsInt16OrFloat16(); return mType.mElement.mType; } return Element.DataType.SIGNED_16; @@ -134,7 +143,10 @@ public class Allocation extends BaseObj { } return Element.DataType.FLOAT_64; } - return null; + + throw new RSIllegalArgumentException("Parameter of type " + cmp.getSimpleName() + + "[] is not compatible with data type " + mType.mElement.mType.name() + + " of allocation"); } @@ -274,8 +286,24 @@ public class Allocation extends BaseObj { } /** - * Enable/Disable AutoPadding for Vec3 elements. - * By default: Diabled. + * @hide + * Get the Mipmap control flag of the Allocation. + * + * @return the Mipmap control flag of the Allocation + * + */ + public MipmapControl getMipmap() { + return mMipmapControl; + } + + /** + * Enable/Disable AutoPadding for Vec3 Elements. + * + * <p> Vec3 Elements, such as {@link Element#U8_3} are treated as Vec4 Elements + * with the fourth vector element used as padding. Enabling the AutoPadding feature + * will automatically add/remove the padding when you copy to/from an Allocation + * with a Vec3 Element. + * <p> By default: Disabled. * * @param useAutoPadding True: enable AutoPadding; False: disable AutoPadding * @@ -353,6 +381,13 @@ public class Allocation extends BaseObj { Log.e(RenderScript.LOG_TAG, "Couldn't invoke registerNativeAllocation:" + e); throw new RSRuntimeException("Couldn't invoke registerNativeAllocation:" + e); } + guard.open("destroy"); + } + + Allocation(long id, RenderScript rs, Type t, boolean owningType, int usage, MipmapControl mips) { + this(id, rs, t, usage); + mOwningType = owningType; + mMipmapControl = mips; } protected void finalize() throws Throwable { @@ -378,9 +413,10 @@ public class Allocation extends BaseObj { "32 bit integer source does not match allocation type " + mType.mElement.mType); } - private void validateIsInt16() { + private void validateIsInt16OrFloat16() { if ((mType.mElement.mType == Element.DataType.SIGNED_16) || - (mType.mElement.mType == Element.DataType.UNSIGNED_16)) { + (mType.mElement.mType == Element.DataType.UNSIGNED_16) || + (mType.mElement.mType == Element.DataType.FLOAT_16)) { return; } throw new RSIllegalArgumentException( @@ -517,7 +553,7 @@ public class Allocation extends BaseObj { "Can only receive if IO_INPUT usage specified."); } mRS.validate(); - mRS.nAllocationIoReceive(getID(mRS)); + mTimeStamp = mRS.nAllocationIoReceive(getID(mRS)); } finally { Trace.traceEnd(RenderScript.TRACE_TAG); } @@ -727,7 +763,7 @@ public class Allocation extends BaseObj { * @param d the source data array */ public void copyFrom(short[] d) { - validateIsInt16(); + validateIsInt16OrFloat16(); copyFromUnchecked(d, Element.DataType.SIGNED_16, d.length); } @@ -1036,7 +1072,7 @@ public class Allocation extends BaseObj { * @param d the source data array */ public void copy1DRangeFrom(int off, int count, short[] d) { - validateIsInt16(); + validateIsInt16OrFloat16(); copy1DRangeFromUnchecked(off, count, d, Element.DataType.SIGNED_16, d.length); } @@ -1180,7 +1216,7 @@ public class Allocation extends BaseObj { * @param data to be placed into the Allocation */ public void copy2DRangeFrom(int xoff, int yoff, int w, int h, short[] data) { - validateIsInt16(); + validateIsInt16OrFloat16(); copy2DRangeFromUnchecked(xoff, yoff, w, h, data, Element.DataType.SIGNED_16, data.length); } @@ -1449,7 +1485,7 @@ public class Allocation extends BaseObj { * @param d The array to be set from the Allocation. */ public void copyTo(short[] d) { - validateIsInt16(); + validateIsInt16OrFloat16(); copyTo(d, Element.DataType.SIGNED_16, d.length); } @@ -1505,7 +1541,7 @@ public class Allocation extends BaseObj { } final byte[] data = fp.getData(); - int data_length = fp.getPos(); + int data_length = data.length; int eSize = mType.mElement.mElements[component_number].getBytesSize(); eSize *= mType.mElement.mArraySizes[component_number]; @@ -1544,6 +1580,9 @@ public class Allocation extends BaseObj { mRS.finish(); // Necessary because resize is fifoed and update is async. long typeID = mRS.nAllocationGetType(getID(mRS)); + // Sets zero the mID so that the finalizer of the old mType value won't + // destroy the native object that is being reused. + mType.setID(0); mType = new Type(typeID, mRS); mType.updateFromNative(); updateCacheInfo(mType); @@ -1669,7 +1708,7 @@ public class Allocation extends BaseObj { * @param d the source data array */ public void copy1DRangeTo(int off, int count, short[] d) { - validateIsInt16(); + validateIsInt16OrFloat16(); copy1DRangeToUnchecked(off, count, d, Element.DataType.SIGNED_16, d.length); } @@ -1770,7 +1809,7 @@ public class Allocation extends BaseObj { * @param data Dest Array to be copied into */ public void copy2DRangeTo(int xoff, int yoff, int w, int h, short[] data) { - validateIsInt16(); + validateIsInt16OrFloat16(); copy2DRangeToUnchecked(xoff, yoff, w, h, data, Element.DataType.SIGNED_16, data.length); } @@ -1882,11 +1921,12 @@ public class Allocation extends BaseObj { if (type.getID(rs) == 0) { throw new RSInvalidStateException("Bad Type"); } + // TODO: What if there is an exception after this? The native allocation would leak. long id = rs.nAllocationCreateTyped(type.getID(rs), mips.mID, usage, 0); if (id == 0) { throw new RSRuntimeException("Allocation creation failed."); } - return new Allocation(id, rs, type, usage); + return new Allocation(id, rs, type, false, usage, mips); } finally { Trace.traceEnd(RenderScript.TRACE_TAG); } @@ -1944,7 +1984,7 @@ public class Allocation extends BaseObj { if (id == 0) { throw new RSRuntimeException("Allocation creation failed."); } - return new Allocation(id, rs, t, usage); + return new Allocation(id, rs, t, true, usage, MipmapControl.MIPMAP_NONE); } finally { Trace.traceEnd(RenderScript.TRACE_TAG); } @@ -2033,7 +2073,7 @@ public class Allocation extends BaseObj { } // keep a reference to the Bitmap around to prevent GC - Allocation alloc = new Allocation(id, rs, t, usage); + Allocation alloc = new Allocation(id, rs, t, true, usage, mips); alloc.setBitmap(b); return alloc; } @@ -2043,13 +2083,185 @@ public class Allocation extends BaseObj { if (id == 0) { throw new RSRuntimeException("Load failed."); } - return new Allocation(id, rs, t, usage); + return new Allocation(id, rs, t, true, usage, mips); + } finally { + Trace.traceEnd(RenderScript.TRACE_TAG); + } + } + + /** + * Gets or creates a ByteBuffer that contains the raw data of the current Allocation. + * If the Allocation is created with USAGE_IO_INPUT, the returned ByteBuffer + * would contain the up-to-date data as READ ONLY. + * For a 2D or 3D Allocation, the raw data maybe padded so that each row of + * the Allocation has certain alignment. The size of each row including padding, + * called stride, can be queried using the {@link #getStride()} method. + * + * Note: Operating on the ByteBuffer of a destroyed Allocation will triger errors. + * + * @return ByteBuffer The ByteBuffer associated with raw data pointer of the Allocation. + */ + public ByteBuffer getByteBuffer() { + // Create a new ByteBuffer if it is not initialized or using IO_INPUT. + if (mType.hasFaces()) { + throw new RSInvalidStateException("Cubemap is not supported for getByteBuffer()."); + } + if (mType.getYuv() == android.graphics.ImageFormat.NV21 || + mType.getYuv() == android.graphics.ImageFormat.YV12 || + mType.getYuv() == android.graphics.ImageFormat.YUV_420_888 ) { + throw new RSInvalidStateException("YUV format is not supported for getByteBuffer()."); + } + if (mByteBuffer == null || (mUsage & USAGE_IO_INPUT) != 0) { + int xBytesSize = mType.getX() * mType.getElement().getBytesSize(); + long[] stride = new long[1]; + mByteBuffer = mRS.nAllocationGetByteBuffer(getID(mRS), stride, xBytesSize, mType.getY(), mType.getZ()); + mByteBufferStride = stride[0]; + } + if ((mUsage & USAGE_IO_INPUT) != 0) { + return mByteBuffer.asReadOnlyBuffer(); + } + return mByteBuffer; + } + + /** + * Creates a new Allocation Array with the given {@link + * android.renderscript.Type}, and usage flags. + * Note: If the input allocation is of usage: USAGE_IO_INPUT, + * the created Allocation will be sharing the same BufferQueue. + * + * @param rs RenderScript context + * @param t RenderScript type describing data layout + * @param usage bit field specifying how the Allocation is + * utilized + * @param numAlloc Number of Allocations in the array. + * @return Allocation[] + */ + public static Allocation[] createAllocations(RenderScript rs, Type t, int usage, int numAlloc) { + try { + Trace.traceBegin(RenderScript.TRACE_TAG, "createAllocations"); + rs.validate(); + if (t.getID(rs) == 0) { + throw new RSInvalidStateException("Bad Type"); + } + + Allocation[] mAllocationArray = new Allocation[numAlloc]; + mAllocationArray[0] = createTyped(rs, t, usage); + if ((usage & USAGE_IO_INPUT) != 0) { + if (numAlloc > MAX_NUMBER_IO_INPUT_ALLOC) { + throw new RSIllegalArgumentException("Exceeds the max number of Allocations allowed: " + + MAX_NUMBER_IO_INPUT_ALLOC); + } + mAllocationArray[0].setupBufferQueue(numAlloc);; + } + + for (int i=1; i<numAlloc; i++) { + mAllocationArray[i] = createFromAllocation(rs, mAllocationArray[0]); + } + return mAllocationArray; + } finally { + Trace.traceEnd(RenderScript.TRACE_TAG); + } + } + + /** + * Creates a new Allocation with the given {@link + * android.renderscript.Allocation}. The same data layout of + * the input Allocation will be applied. + * If the input allocation is of usage: USAGE_IO_INPUT, the created + * Allocation will be sharing the same BufferQueue. + * + * @param rs Context to which the allocation will belong. + * @param alloc RenderScript Allocation describing data layout. + * @return Allocation sharing the same data structure. + */ + static Allocation createFromAllocation(RenderScript rs, Allocation alloc) { + try { + Trace.traceBegin(RenderScript.TRACE_TAG, "createFromAllcation"); + rs.validate(); + if (alloc.getID(rs) == 0) { + throw new RSInvalidStateException("Bad input Allocation"); + } + + Type type = alloc.getType(); + int usage = alloc.getUsage(); + MipmapControl mips = alloc.getMipmap(); + long id = rs.nAllocationCreateTyped(type.getID(rs), mips.mID, usage, 0); + if (id == 0) { + throw new RSRuntimeException("Allocation creation failed."); + } + Allocation outAlloc = new Allocation(id, rs, type, false, usage, mips); + if ((usage & USAGE_IO_INPUT) != 0) { + outAlloc.shareBufferQueue(alloc); + } + return outAlloc; } finally { Trace.traceEnd(RenderScript.TRACE_TAG); } } /** + * Initialize BufferQueue with specified max number of buffers. + */ + void setupBufferQueue(int numAlloc) { + mRS.validate(); + if ((mUsage & USAGE_IO_INPUT) == 0) { + throw new RSInvalidStateException("Allocation is not USAGE_IO_INPUT."); + } + mRS.nAllocationSetupBufferQueue(getID(mRS), numAlloc); + } + + /** + * Share the BufferQueue with another {@link #USAGE_IO_INPUT} Allocation. + * + * @param alloc Allocation to associate with allocation + */ + void shareBufferQueue(Allocation alloc) { + mRS.validate(); + if ((mUsage & USAGE_IO_INPUT) == 0) { + throw new RSInvalidStateException("Allocation is not USAGE_IO_INPUT."); + } + mGetSurfaceSurface = alloc.getSurface(); + mRS.nAllocationShareBufferQueue(getID(mRS), alloc.getID(mRS)); + } + + /** + * Gets the stride of the Allocation. + * For a 2D or 3D Allocation, the raw data maybe padded so that each row of + * the Allocation has certain alignment. The size of each row including such + * padding is called stride. + * + * @return the stride. For 1D Allocation, the stride will be the number of + * bytes of this Allocation. For 2D and 3D Allocations, the stride + * will be the stride in X dimension measuring in bytes. + */ + public long getStride() { + if (mByteBufferStride == -1) { + getByteBuffer(); + } + return mByteBufferStride; + } + + /** + * Get the timestamp for the most recent buffer held by this Allocation. + * The timestamp is guaranteed to be unique and monotonically increasing. + * Default value: -1. The timestamp will be updated after each {@link + * #ioReceive ioReceive()} call. + * + * It can be used to identify the images by comparing the unique timestamps + * when used with {@link android.hardware.camera2} APIs. + * Example steps: + * 1. Save {@link android.hardware.camera2.TotalCaptureResult} when the + * capture is completed. + * 2. Get the timestamp after {@link #ioReceive ioReceive()} call. + * 3. Comparing totalCaptureResult.get(CaptureResult.SENSOR_TIMESTAMP) with + * alloc.getTimeStamp(). + * @return long Timestamp associated with the buffer held by the Allocation. + */ + public long getTimeStamp() { + return mTimeStamp; + } + + /** * Returns the handle to a raw buffer that is being managed by the screen * compositor. This operation is only valid for Allocations with {@link * #USAGE_IO_INPUT}. @@ -2153,7 +2365,7 @@ public class Allocation extends BaseObj { if(id == 0) { throw new RSRuntimeException("Load failed for bitmap " + b + " element " + e); } - return new Allocation(id, rs, t, usage); + return new Allocation(id, rs, t, true, usage, mips); } /** @@ -2398,6 +2610,12 @@ public class Allocation extends BaseObj { if((mUsage & USAGE_IO_OUTPUT) != 0) { setSurface(null); } + + if (mType != null && mOwningType) { + mType.destroy(); + } + super.destroy(); } + } diff --git a/rs/java/android/renderscript/BaseObj.java b/rs/java/android/renderscript/BaseObj.java index 1372ab79e264..f95af1673730 100644 --- a/rs/java/android/renderscript/BaseObj.java +++ b/rs/java/android/renderscript/BaseObj.java @@ -16,6 +16,7 @@ package android.renderscript; +import dalvik.system.CloseGuard; import java.util.concurrent.locks.ReentrantReadWriteLock; /** @@ -69,6 +70,7 @@ public class BaseObj { } private long mID; + final CloseGuard guard = CloseGuard.get(); private boolean mDestroyed; private String mName; RenderScript mRS; @@ -119,6 +121,7 @@ public class BaseObj { } if (shouldDestroy) { + guard.close(); // must include nObjDestroy in the critical section ReentrantReadWriteLock.ReadLock rlock = mRS.mRWLock.readLock(); rlock.lock(); @@ -133,8 +136,14 @@ public class BaseObj { } protected void finalize() throws Throwable { - helpDestroy(); - super.finalize(); + try { + if (guard != null) { + guard.warnIfOpen(); + } + helpDestroy(); + } finally { + super.finalize(); + } } /** diff --git a/rs/java/android/renderscript/Element.java b/rs/java/android/renderscript/Element.java index 6efb6d6a5735..9d2f75080bb6 100644 --- a/rs/java/android/renderscript/Element.java +++ b/rs/java/android/renderscript/Element.java @@ -311,8 +311,12 @@ public class Element extends BaseObj { * @return Element */ public static Element BOOLEAN(RenderScript rs) { - if(rs.mElement_BOOLEAN == null) { - rs.mElement_BOOLEAN = createUser(rs, DataType.BOOLEAN); + if (rs.mElement_BOOLEAN == null) { + synchronized (rs) { + if (rs.mElement_BOOLEAN == null) { + rs.mElement_BOOLEAN = createUser(rs, DataType.BOOLEAN); + } + } } return rs.mElement_BOOLEAN; } @@ -325,8 +329,12 @@ public class Element extends BaseObj { * @return Element */ public static Element U8(RenderScript rs) { - if(rs.mElement_U8 == null) { - rs.mElement_U8 = createUser(rs, DataType.UNSIGNED_8); + if (rs.mElement_U8 == null) { + synchronized (rs) { + if (rs.mElement_U8 == null) { + rs.mElement_U8 = createUser(rs, DataType.UNSIGNED_8); + } + } } return rs.mElement_U8; } @@ -339,436 +347,683 @@ public class Element extends BaseObj { * @return Element */ public static Element I8(RenderScript rs) { - if(rs.mElement_I8 == null) { - rs.mElement_I8 = createUser(rs, DataType.SIGNED_8); + if (rs.mElement_I8 == null) { + synchronized (rs) { + if (rs.mElement_I8 == null) { + rs.mElement_I8 = createUser(rs, DataType.SIGNED_8); + } + } } return rs.mElement_I8; } public static Element U16(RenderScript rs) { - if(rs.mElement_U16 == null) { - rs.mElement_U16 = createUser(rs, DataType.UNSIGNED_16); + if (rs.mElement_U16 == null) { + synchronized (rs) { + if (rs.mElement_U16 == null) { + rs.mElement_U16 = createUser(rs, DataType.UNSIGNED_16); + } + } } return rs.mElement_U16; } public static Element I16(RenderScript rs) { - if(rs.mElement_I16 == null) { - rs.mElement_I16 = createUser(rs, DataType.SIGNED_16); + if (rs.mElement_I16 == null) { + synchronized (rs) { + if (rs.mElement_I16 == null) { + rs.mElement_I16 = createUser(rs, DataType.SIGNED_16); + } + } } return rs.mElement_I16; } public static Element U32(RenderScript rs) { - if(rs.mElement_U32 == null) { - rs.mElement_U32 = createUser(rs, DataType.UNSIGNED_32); + if (rs.mElement_U32 == null) { + synchronized (rs) { + if (rs.mElement_U32 == null) { + rs.mElement_U32 = createUser(rs, DataType.UNSIGNED_32); + } + } } return rs.mElement_U32; } public static Element I32(RenderScript rs) { - if(rs.mElement_I32 == null) { - rs.mElement_I32 = createUser(rs, DataType.SIGNED_32); + if (rs.mElement_I32 == null) { + synchronized (rs) { + if (rs.mElement_I32 == null) { + rs.mElement_I32 = createUser(rs, DataType.SIGNED_32); + } + } } return rs.mElement_I32; } public static Element U64(RenderScript rs) { - if(rs.mElement_U64 == null) { - rs.mElement_U64 = createUser(rs, DataType.UNSIGNED_64); + if (rs.mElement_U64 == null) { + synchronized (rs) { + if (rs.mElement_U64 == null) { + rs.mElement_U64 = createUser(rs, DataType.UNSIGNED_64); + } + } } return rs.mElement_U64; } public static Element I64(RenderScript rs) { - if(rs.mElement_I64 == null) { - rs.mElement_I64 = createUser(rs, DataType.SIGNED_64); + if (rs.mElement_I64 == null) { + synchronized (rs) { + if (rs.mElement_I64 == null) { + rs.mElement_I64 = createUser(rs, DataType.SIGNED_64); + } + } } return rs.mElement_I64; } public static Element F16(RenderScript rs) { - if(rs.mElement_F16 == null) { - rs.mElement_F16 = createUser(rs, DataType.FLOAT_16); + if (rs.mElement_F16 == null) { + synchronized (rs) { + if (rs.mElement_F16 == null) { + rs.mElement_F16 = createUser(rs, DataType.FLOAT_16); + } + } } return rs.mElement_F16; } public static Element F32(RenderScript rs) { - if(rs.mElement_F32 == null) { - rs.mElement_F32 = createUser(rs, DataType.FLOAT_32); + if (rs.mElement_F32 == null) { + synchronized (rs) { + if (rs.mElement_F32 == null) { + rs.mElement_F32 = createUser(rs, DataType.FLOAT_32); + } + } } return rs.mElement_F32; } public static Element F64(RenderScript rs) { - if(rs.mElement_F64 == null) { - rs.mElement_F64 = createUser(rs, DataType.FLOAT_64); + if (rs.mElement_F64 == null) { + synchronized (rs) { + if (rs.mElement_F64 == null) { + rs.mElement_F64 = createUser(rs, DataType.FLOAT_64); + } + } } return rs.mElement_F64; } public static Element ELEMENT(RenderScript rs) { - if(rs.mElement_ELEMENT == null) { - rs.mElement_ELEMENT = createUser(rs, DataType.RS_ELEMENT); + if (rs.mElement_ELEMENT == null) { + synchronized (rs) { + if (rs.mElement_ELEMENT == null) { + rs.mElement_ELEMENT = createUser(rs, DataType.RS_ELEMENT); + } + } } return rs.mElement_ELEMENT; } public static Element TYPE(RenderScript rs) { - if(rs.mElement_TYPE == null) { - rs.mElement_TYPE = createUser(rs, DataType.RS_TYPE); + if (rs.mElement_TYPE == null) { + synchronized (rs) { + if (rs.mElement_TYPE == null) { + rs.mElement_TYPE = createUser(rs, DataType.RS_TYPE); + } + } } return rs.mElement_TYPE; } public static Element ALLOCATION(RenderScript rs) { - if(rs.mElement_ALLOCATION == null) { - rs.mElement_ALLOCATION = createUser(rs, DataType.RS_ALLOCATION); + if (rs.mElement_ALLOCATION == null) { + synchronized (rs) { + if (rs.mElement_ALLOCATION == null) { + rs.mElement_ALLOCATION = createUser(rs, DataType.RS_ALLOCATION); + } + } } return rs.mElement_ALLOCATION; } public static Element SAMPLER(RenderScript rs) { - if(rs.mElement_SAMPLER == null) { - rs.mElement_SAMPLER = createUser(rs, DataType.RS_SAMPLER); + if (rs.mElement_SAMPLER == null) { + synchronized (rs) { + if (rs.mElement_SAMPLER == null) { + rs.mElement_SAMPLER = createUser(rs, DataType.RS_SAMPLER); + } + } } return rs.mElement_SAMPLER; } public static Element SCRIPT(RenderScript rs) { - if(rs.mElement_SCRIPT == null) { - rs.mElement_SCRIPT = createUser(rs, DataType.RS_SCRIPT); + if (rs.mElement_SCRIPT == null) { + synchronized (rs) { + if (rs.mElement_SCRIPT == null) { + rs.mElement_SCRIPT = createUser(rs, DataType.RS_SCRIPT); + } + } } return rs.mElement_SCRIPT; } public static Element MESH(RenderScript rs) { - if(rs.mElement_MESH == null) { - rs.mElement_MESH = createUser(rs, DataType.RS_MESH); + if (rs.mElement_MESH == null) { + synchronized (rs) { + if (rs.mElement_MESH == null) { + rs.mElement_MESH = createUser(rs, DataType.RS_MESH); + } + } } return rs.mElement_MESH; } public static Element PROGRAM_FRAGMENT(RenderScript rs) { - if(rs.mElement_PROGRAM_FRAGMENT == null) { - rs.mElement_PROGRAM_FRAGMENT = createUser(rs, DataType.RS_PROGRAM_FRAGMENT); + if (rs.mElement_PROGRAM_FRAGMENT == null) { + synchronized (rs) { + if (rs.mElement_PROGRAM_FRAGMENT == null) { + rs.mElement_PROGRAM_FRAGMENT = createUser(rs, DataType.RS_PROGRAM_FRAGMENT); + } + } } return rs.mElement_PROGRAM_FRAGMENT; } public static Element PROGRAM_VERTEX(RenderScript rs) { - if(rs.mElement_PROGRAM_VERTEX == null) { - rs.mElement_PROGRAM_VERTEX = createUser(rs, DataType.RS_PROGRAM_VERTEX); + if (rs.mElement_PROGRAM_VERTEX == null) { + synchronized (rs) { + if (rs.mElement_PROGRAM_VERTEX == null) { + rs.mElement_PROGRAM_VERTEX = createUser(rs, DataType.RS_PROGRAM_VERTEX); + } + } } return rs.mElement_PROGRAM_VERTEX; } public static Element PROGRAM_RASTER(RenderScript rs) { - if(rs.mElement_PROGRAM_RASTER == null) { - rs.mElement_PROGRAM_RASTER = createUser(rs, DataType.RS_PROGRAM_RASTER); + if (rs.mElement_PROGRAM_RASTER == null) { + synchronized (rs) { + if (rs.mElement_PROGRAM_RASTER == null) { + rs.mElement_PROGRAM_RASTER = createUser(rs, DataType.RS_PROGRAM_RASTER); + } + } } return rs.mElement_PROGRAM_RASTER; } public static Element PROGRAM_STORE(RenderScript rs) { - if(rs.mElement_PROGRAM_STORE == null) { - rs.mElement_PROGRAM_STORE = createUser(rs, DataType.RS_PROGRAM_STORE); + if (rs.mElement_PROGRAM_STORE == null) { + synchronized (rs) { + if (rs.mElement_PROGRAM_STORE == null) { + rs.mElement_PROGRAM_STORE = createUser(rs, DataType.RS_PROGRAM_STORE); + } + } } return rs.mElement_PROGRAM_STORE; } public static Element FONT(RenderScript rs) { - if(rs.mElement_FONT == null) { - rs.mElement_FONT = createUser(rs, DataType.RS_FONT); + if (rs.mElement_FONT == null) { + synchronized (rs) { + if (rs.mElement_FONT == null) { + rs.mElement_FONT = createUser(rs, DataType.RS_FONT); + } + } } return rs.mElement_FONT; } - public static Element A_8(RenderScript rs) { - if(rs.mElement_A_8 == null) { - rs.mElement_A_8 = createPixel(rs, DataType.UNSIGNED_8, DataKind.PIXEL_A); + if (rs.mElement_A_8 == null) { + synchronized (rs) { + if (rs.mElement_A_8 == null) { + rs.mElement_A_8 = createPixel(rs, DataType.UNSIGNED_8, DataKind.PIXEL_A); + } + } } return rs.mElement_A_8; } public static Element RGB_565(RenderScript rs) { - if(rs.mElement_RGB_565 == null) { - rs.mElement_RGB_565 = createPixel(rs, DataType.UNSIGNED_5_6_5, DataKind.PIXEL_RGB); + if (rs.mElement_RGB_565 == null) { + synchronized (rs) { + if (rs.mElement_RGB_565 == null) { + rs.mElement_RGB_565 = createPixel(rs, DataType.UNSIGNED_5_6_5, DataKind.PIXEL_RGB); + } + } } return rs.mElement_RGB_565; } public static Element RGB_888(RenderScript rs) { - if(rs.mElement_RGB_888 == null) { - rs.mElement_RGB_888 = createPixel(rs, DataType.UNSIGNED_8, DataKind.PIXEL_RGB); + if (rs.mElement_RGB_888 == null) { + synchronized (rs) { + if (rs.mElement_RGB_888 == null) { + rs.mElement_RGB_888 = createPixel(rs, DataType.UNSIGNED_8, DataKind.PIXEL_RGB); + } + } } return rs.mElement_RGB_888; } public static Element RGBA_5551(RenderScript rs) { - if(rs.mElement_RGBA_5551 == null) { - rs.mElement_RGBA_5551 = createPixel(rs, DataType.UNSIGNED_5_5_5_1, DataKind.PIXEL_RGBA); + if (rs.mElement_RGBA_5551 == null) { + synchronized (rs) { + if (rs.mElement_RGBA_5551 == null) { + rs.mElement_RGBA_5551 = createPixel(rs, DataType.UNSIGNED_5_5_5_1, DataKind.PIXEL_RGBA); + } + } } return rs.mElement_RGBA_5551; } public static Element RGBA_4444(RenderScript rs) { - if(rs.mElement_RGBA_4444 == null) { - rs.mElement_RGBA_4444 = createPixel(rs, DataType.UNSIGNED_4_4_4_4, DataKind.PIXEL_RGBA); + if (rs.mElement_RGBA_4444 == null) { + synchronized (rs) { + if (rs.mElement_RGBA_4444 == null) { + rs.mElement_RGBA_4444 = createPixel(rs, DataType.UNSIGNED_4_4_4_4, DataKind.PIXEL_RGBA); + } + } } return rs.mElement_RGBA_4444; } public static Element RGBA_8888(RenderScript rs) { - if(rs.mElement_RGBA_8888 == null) { - rs.mElement_RGBA_8888 = createPixel(rs, DataType.UNSIGNED_8, DataKind.PIXEL_RGBA); + if (rs.mElement_RGBA_8888 == null) { + synchronized (rs) { + if (rs.mElement_RGBA_8888 == null) { + rs.mElement_RGBA_8888 = createPixel(rs, DataType.UNSIGNED_8, DataKind.PIXEL_RGBA); + } + } } return rs.mElement_RGBA_8888; } public static Element F16_2(RenderScript rs) { - if(rs.mElement_HALF_2 == null) { - rs.mElement_HALF_2 = createVector(rs, DataType.FLOAT_16, 2); + if (rs.mElement_HALF_2 == null) { + synchronized (rs) { + if (rs.mElement_HALF_2 == null) { + rs.mElement_HALF_2 = createVector(rs, DataType.FLOAT_16, 2); + } + } } return rs.mElement_HALF_2; } public static Element F16_3(RenderScript rs) { - if(rs.mElement_HALF_3 == null) { - rs.mElement_HALF_3 = createVector(rs, DataType.FLOAT_16, 3); + if (rs.mElement_HALF_3 == null) { + synchronized (rs) { + if (rs.mElement_HALF_3 == null) { + rs.mElement_HALF_3 = createVector(rs, DataType.FLOAT_16, 3); + } + } } return rs.mElement_HALF_3; } public static Element F16_4(RenderScript rs) { - if(rs.mElement_HALF_4 == null) { - rs.mElement_HALF_4 = createVector(rs, DataType.FLOAT_16, 4); + if (rs.mElement_HALF_4 == null) { + synchronized (rs) { + if (rs.mElement_HALF_4 == null) { + rs.mElement_HALF_4 = createVector(rs, DataType.FLOAT_16, 4); + } + } } return rs.mElement_HALF_4; } public static Element F32_2(RenderScript rs) { - if(rs.mElement_FLOAT_2 == null) { - rs.mElement_FLOAT_2 = createVector(rs, DataType.FLOAT_32, 2); + if (rs.mElement_FLOAT_2 == null) { + synchronized (rs) { + if (rs.mElement_FLOAT_2 == null) { + rs.mElement_FLOAT_2 = createVector(rs, DataType.FLOAT_32, 2); + } + } } return rs.mElement_FLOAT_2; } public static Element F32_3(RenderScript rs) { - if(rs.mElement_FLOAT_3 == null) { - rs.mElement_FLOAT_3 = createVector(rs, DataType.FLOAT_32, 3); + if (rs.mElement_FLOAT_3 == null) { + synchronized (rs) { + if (rs.mElement_FLOAT_3 == null) { + rs.mElement_FLOAT_3 = createVector(rs, DataType.FLOAT_32, 3); + } + } } return rs.mElement_FLOAT_3; } public static Element F32_4(RenderScript rs) { - if(rs.mElement_FLOAT_4 == null) { - rs.mElement_FLOAT_4 = createVector(rs, DataType.FLOAT_32, 4); + if (rs.mElement_FLOAT_4 == null) { + synchronized (rs) { + if (rs.mElement_FLOAT_4 == null) { + rs.mElement_FLOAT_4 = createVector(rs, DataType.FLOAT_32, 4); + } + } } return rs.mElement_FLOAT_4; } public static Element F64_2(RenderScript rs) { - if(rs.mElement_DOUBLE_2 == null) { - rs.mElement_DOUBLE_2 = createVector(rs, DataType.FLOAT_64, 2); + if (rs.mElement_DOUBLE_2 == null) { + synchronized (rs) { + if (rs.mElement_DOUBLE_2 == null) { + rs.mElement_DOUBLE_2 = createVector(rs, DataType.FLOAT_64, 2); + } + } } return rs.mElement_DOUBLE_2; } public static Element F64_3(RenderScript rs) { - if(rs.mElement_DOUBLE_3 == null) { - rs.mElement_DOUBLE_3 = createVector(rs, DataType.FLOAT_64, 3); + if (rs.mElement_DOUBLE_3 == null) { + synchronized (rs) { + if (rs.mElement_DOUBLE_3 == null) { + rs.mElement_DOUBLE_3 = createVector(rs, DataType.FLOAT_64, 3); + } + } } return rs.mElement_DOUBLE_3; } public static Element F64_4(RenderScript rs) { - if(rs.mElement_DOUBLE_4 == null) { - rs.mElement_DOUBLE_4 = createVector(rs, DataType.FLOAT_64, 4); + if (rs.mElement_DOUBLE_4 == null) { + synchronized (rs) { + if (rs.mElement_DOUBLE_4 == null) { + rs.mElement_DOUBLE_4 = createVector(rs, DataType.FLOAT_64, 4); + } + } } return rs.mElement_DOUBLE_4; } public static Element U8_2(RenderScript rs) { - if(rs.mElement_UCHAR_2 == null) { - rs.mElement_UCHAR_2 = createVector(rs, DataType.UNSIGNED_8, 2); + if (rs.mElement_UCHAR_2 == null) { + synchronized (rs) { + if (rs.mElement_UCHAR_2 == null) { + rs.mElement_UCHAR_2 = createVector(rs, DataType.UNSIGNED_8, 2); + } + } } return rs.mElement_UCHAR_2; } public static Element U8_3(RenderScript rs) { - if(rs.mElement_UCHAR_3 == null) { - rs.mElement_UCHAR_3 = createVector(rs, DataType.UNSIGNED_8, 3); + if (rs.mElement_UCHAR_3 == null) { + synchronized (rs) { + if (rs.mElement_UCHAR_3 == null) { + rs.mElement_UCHAR_3 = createVector(rs, DataType.UNSIGNED_8, 3); + } + } } return rs.mElement_UCHAR_3; } public static Element U8_4(RenderScript rs) { - if(rs.mElement_UCHAR_4 == null) { - rs.mElement_UCHAR_4 = createVector(rs, DataType.UNSIGNED_8, 4); + if (rs.mElement_UCHAR_4 == null) { + synchronized (rs) { + if (rs.mElement_UCHAR_4 == null) { + rs.mElement_UCHAR_4 = createVector(rs, DataType.UNSIGNED_8, 4); + } + } } return rs.mElement_UCHAR_4; } public static Element I8_2(RenderScript rs) { - if(rs.mElement_CHAR_2 == null) { - rs.mElement_CHAR_2 = createVector(rs, DataType.SIGNED_8, 2); + if (rs.mElement_CHAR_2 == null) { + synchronized (rs) { + if (rs.mElement_CHAR_2 == null) { + rs.mElement_CHAR_2 = createVector(rs, DataType.SIGNED_8, 2); + } + } } return rs.mElement_CHAR_2; } public static Element I8_3(RenderScript rs) { - if(rs.mElement_CHAR_3 == null) { - rs.mElement_CHAR_3 = createVector(rs, DataType.SIGNED_8, 3); + if (rs.mElement_CHAR_3 == null) { + synchronized (rs) { + if (rs.mElement_CHAR_3 == null) { + rs.mElement_CHAR_3 = createVector(rs, DataType.SIGNED_8, 3); + } + } } return rs.mElement_CHAR_3; } public static Element I8_4(RenderScript rs) { - if(rs.mElement_CHAR_4 == null) { - rs.mElement_CHAR_4 = createVector(rs, DataType.SIGNED_8, 4); + if (rs.mElement_CHAR_4 == null) { + synchronized (rs) { + if (rs.mElement_CHAR_4 == null) { + rs.mElement_CHAR_4 = createVector(rs, DataType.SIGNED_8, 4); + } + } } return rs.mElement_CHAR_4; } public static Element U16_2(RenderScript rs) { - if(rs.mElement_USHORT_2 == null) { - rs.mElement_USHORT_2 = createVector(rs, DataType.UNSIGNED_16, 2); + if (rs.mElement_USHORT_2 == null) { + synchronized (rs) { + if (rs.mElement_USHORT_2 == null) { + rs.mElement_USHORT_2 = createVector(rs, DataType.UNSIGNED_16, 2); + } + } } return rs.mElement_USHORT_2; } public static Element U16_3(RenderScript rs) { - if(rs.mElement_USHORT_3 == null) { - rs.mElement_USHORT_3 = createVector(rs, DataType.UNSIGNED_16, 3); + if (rs.mElement_USHORT_3 == null) { + synchronized (rs) { + if (rs.mElement_USHORT_3 == null) { + rs.mElement_USHORT_3 = createVector(rs, DataType.UNSIGNED_16, 3); + } + } } return rs.mElement_USHORT_3; } public static Element U16_4(RenderScript rs) { - if(rs.mElement_USHORT_4 == null) { - rs.mElement_USHORT_4 = createVector(rs, DataType.UNSIGNED_16, 4); + if (rs.mElement_USHORT_4 == null) { + synchronized (rs) { + if (rs.mElement_USHORT_4 == null) { + rs.mElement_USHORT_4 = createVector(rs, DataType.UNSIGNED_16, 4); + } + } } return rs.mElement_USHORT_4; } public static Element I16_2(RenderScript rs) { - if(rs.mElement_SHORT_2 == null) { - rs.mElement_SHORT_2 = createVector(rs, DataType.SIGNED_16, 2); + if (rs.mElement_SHORT_2 == null) { + synchronized (rs) { + if (rs.mElement_SHORT_2 == null) { + rs.mElement_SHORT_2 = createVector(rs, DataType.SIGNED_16, 2); + } + } } return rs.mElement_SHORT_2; } public static Element I16_3(RenderScript rs) { - if(rs.mElement_SHORT_3 == null) { - rs.mElement_SHORT_3 = createVector(rs, DataType.SIGNED_16, 3); + if (rs.mElement_SHORT_3 == null) { + synchronized (rs) { + if (rs.mElement_SHORT_3 == null) { + rs.mElement_SHORT_3 = createVector(rs, DataType.SIGNED_16, 3); + } + } } return rs.mElement_SHORT_3; } public static Element I16_4(RenderScript rs) { - if(rs.mElement_SHORT_4 == null) { - rs.mElement_SHORT_4 = createVector(rs, DataType.SIGNED_16, 4); + if (rs.mElement_SHORT_4 == null) { + synchronized (rs) { + if (rs.mElement_SHORT_4 == null) { + rs.mElement_SHORT_4 = createVector(rs, DataType.SIGNED_16, 4); + } + } } return rs.mElement_SHORT_4; } public static Element U32_2(RenderScript rs) { - if(rs.mElement_UINT_2 == null) { - rs.mElement_UINT_2 = createVector(rs, DataType.UNSIGNED_32, 2); + if (rs.mElement_UINT_2 == null) { + synchronized (rs) { + if (rs.mElement_UINT_2 == null) { + rs.mElement_UINT_2 = createVector(rs, DataType.UNSIGNED_32, 2); + } + } } return rs.mElement_UINT_2; } public static Element U32_3(RenderScript rs) { - if(rs.mElement_UINT_3 == null) { - rs.mElement_UINT_3 = createVector(rs, DataType.UNSIGNED_32, 3); + if (rs.mElement_UINT_3 == null) { + synchronized (rs) { + if (rs.mElement_UINT_3 == null) { + rs.mElement_UINT_3 = createVector(rs, DataType.UNSIGNED_32, 3); + } + } } return rs.mElement_UINT_3; } public static Element U32_4(RenderScript rs) { - if(rs.mElement_UINT_4 == null) { - rs.mElement_UINT_4 = createVector(rs, DataType.UNSIGNED_32, 4); + if (rs.mElement_UINT_4 == null) { + synchronized (rs) { + if (rs.mElement_UINT_4 == null) { + rs.mElement_UINT_4 = createVector(rs, DataType.UNSIGNED_32, 4); + } + } } return rs.mElement_UINT_4; } public static Element I32_2(RenderScript rs) { - if(rs.mElement_INT_2 == null) { - rs.mElement_INT_2 = createVector(rs, DataType.SIGNED_32, 2); + if (rs.mElement_INT_2 == null) { + synchronized (rs) { + if (rs.mElement_INT_2 == null) { + rs.mElement_INT_2 = createVector(rs, DataType.SIGNED_32, 2); + } + } } return rs.mElement_INT_2; } public static Element I32_3(RenderScript rs) { - if(rs.mElement_INT_3 == null) { - rs.mElement_INT_3 = createVector(rs, DataType.SIGNED_32, 3); + if (rs.mElement_INT_3 == null) { + synchronized (rs) { + if (rs.mElement_INT_3 == null) { + rs.mElement_INT_3 = createVector(rs, DataType.SIGNED_32, 3); + } + } } return rs.mElement_INT_3; } public static Element I32_4(RenderScript rs) { - if(rs.mElement_INT_4 == null) { - rs.mElement_INT_4 = createVector(rs, DataType.SIGNED_32, 4); + if (rs.mElement_INT_4 == null) { + synchronized (rs) { + if (rs.mElement_INT_4 == null) { + rs.mElement_INT_4 = createVector(rs, DataType.SIGNED_32, 4); + } + } } return rs.mElement_INT_4; } public static Element U64_2(RenderScript rs) { - if(rs.mElement_ULONG_2 == null) { - rs.mElement_ULONG_2 = createVector(rs, DataType.UNSIGNED_64, 2); + if (rs.mElement_ULONG_2 == null) { + synchronized (rs) { + if (rs.mElement_ULONG_2 == null) { + rs.mElement_ULONG_2 = createVector(rs, DataType.UNSIGNED_64, 2); + } + } } return rs.mElement_ULONG_2; } public static Element U64_3(RenderScript rs) { - if(rs.mElement_ULONG_3 == null) { - rs.mElement_ULONG_3 = createVector(rs, DataType.UNSIGNED_64, 3); + if (rs.mElement_ULONG_3 == null) { + synchronized (rs) { + if (rs.mElement_ULONG_3 == null) { + rs.mElement_ULONG_3 = createVector(rs, DataType.UNSIGNED_64, 3); + } + } } return rs.mElement_ULONG_3; } public static Element U64_4(RenderScript rs) { - if(rs.mElement_ULONG_4 == null) { - rs.mElement_ULONG_4 = createVector(rs, DataType.UNSIGNED_64, 4); + if (rs.mElement_ULONG_4 == null) { + synchronized (rs) { + if (rs.mElement_ULONG_4 == null) { + rs.mElement_ULONG_4 = createVector(rs, DataType.UNSIGNED_64, 4); + } + } } return rs.mElement_ULONG_4; } public static Element I64_2(RenderScript rs) { - if(rs.mElement_LONG_2 == null) { - rs.mElement_LONG_2 = createVector(rs, DataType.SIGNED_64, 2); + if (rs.mElement_LONG_2 == null) { + synchronized (rs) { + if (rs.mElement_LONG_2 == null) { + rs.mElement_LONG_2 = createVector(rs, DataType.SIGNED_64, 2); + } + } } return rs.mElement_LONG_2; } public static Element I64_3(RenderScript rs) { - if(rs.mElement_LONG_3 == null) { - rs.mElement_LONG_3 = createVector(rs, DataType.SIGNED_64, 3); + if (rs.mElement_LONG_3 == null) { + synchronized (rs) { + if (rs.mElement_LONG_3 == null) { + rs.mElement_LONG_3 = createVector(rs, DataType.SIGNED_64, 3); + } + } } return rs.mElement_LONG_3; } public static Element I64_4(RenderScript rs) { - if(rs.mElement_LONG_4 == null) { - rs.mElement_LONG_4 = createVector(rs, DataType.SIGNED_64, 4); + if (rs.mElement_LONG_4 == null) { + synchronized (rs) { + if (rs.mElement_LONG_4 == null) { + rs.mElement_LONG_4 = createVector(rs, DataType.SIGNED_64, 4); + } + } } return rs.mElement_LONG_4; } public static Element YUV(RenderScript rs) { if (rs.mElement_YUV == null) { - rs.mElement_YUV = createPixel(rs, DataType.UNSIGNED_8, DataKind.PIXEL_YUV); + synchronized (rs) { + if (rs.mElement_YUV == null) { + rs.mElement_YUV = createPixel(rs, DataType.UNSIGNED_8, DataKind.PIXEL_YUV); + } + } } return rs.mElement_YUV; } public static Element MATRIX_4X4(RenderScript rs) { - if(rs.mElement_MATRIX_4X4 == null) { - rs.mElement_MATRIX_4X4 = createUser(rs, DataType.MATRIX_4X4); + if (rs.mElement_MATRIX_4X4 == null) { + synchronized (rs) { + if (rs.mElement_MATRIX_4X4 == null) { + rs.mElement_MATRIX_4X4 = createUser(rs, DataType.MATRIX_4X4); + } + } } return rs.mElement_MATRIX_4X4; } @@ -780,15 +1035,23 @@ public class Element extends BaseObj { } public static Element MATRIX_3X3(RenderScript rs) { - if(rs.mElement_MATRIX_3X3 == null) { - rs.mElement_MATRIX_3X3 = createUser(rs, DataType.MATRIX_3X3); + if (rs.mElement_MATRIX_3X3 == null) { + synchronized (rs) { + if (rs.mElement_MATRIX_3X3 == null) { + rs.mElement_MATRIX_3X3 = createUser(rs, DataType.MATRIX_3X3); + } + } } return rs.mElement_MATRIX_3X3; } public static Element MATRIX_2X2(RenderScript rs) { - if(rs.mElement_MATRIX_2X2 == null) { - rs.mElement_MATRIX_2X2 = createUser(rs, DataType.MATRIX_2X2); + if (rs.mElement_MATRIX_2X2 == null) { + synchronized (rs) { + if (rs.mElement_MATRIX_2X2 == null) { + rs.mElement_MATRIX_2X2 = createUser(rs, DataType.MATRIX_2X2); + } + } } return rs.mElement_MATRIX_2X2; } @@ -808,6 +1071,7 @@ public class Element extends BaseObj { mSize += mElements[ct].mSize * mArraySizes[ct]; } updateVisibleSubElements(); + guard.open("destroy"); } Element(long id, RenderScript rs, DataType dt, DataKind dk, boolean norm, int size) { @@ -827,6 +1091,7 @@ public class Element extends BaseObj { mKind = dk; mNormalized = norm; mVectorSize = size; + guard.open("destroy"); } Element(long id, RenderScript rs) { diff --git a/rs/java/android/renderscript/FileA3D.java b/rs/java/android/renderscript/FileA3D.java index 9d8f1624a051..278d309c74f7 100644 --- a/rs/java/android/renderscript/FileA3D.java +++ b/rs/java/android/renderscript/FileA3D.java @@ -170,6 +170,7 @@ public class FileA3D extends BaseObj { FileA3D(long id, RenderScript rs, InputStream stream) { super(id, rs); mInputStream = stream; + guard.open("destroy"); } private void initEntries() { diff --git a/rs/java/android/renderscript/Font.java b/rs/java/android/renderscript/Font.java index 4318b9d4d21c..d5ca31e93418 100644 --- a/rs/java/android/renderscript/Font.java +++ b/rs/java/android/renderscript/Font.java @@ -150,6 +150,7 @@ public class Font extends BaseObj { Font(long id, RenderScript rs) { super(id, rs); + guard.open("destroy"); } /** diff --git a/rs/java/android/renderscript/Mesh.java b/rs/java/android/renderscript/Mesh.java index 13c8e1c91052..9e4f90573ae9 100644 --- a/rs/java/android/renderscript/Mesh.java +++ b/rs/java/android/renderscript/Mesh.java @@ -91,6 +91,7 @@ public class Mesh extends BaseObj { Mesh(long id, RenderScript rs) { super(id, rs); + guard.open("destroy"); } /** diff --git a/rs/java/android/renderscript/Program.java b/rs/java/android/renderscript/Program.java index 3eb9b7590f45..772021c7815c 100644 --- a/rs/java/android/renderscript/Program.java +++ b/rs/java/android/renderscript/Program.java @@ -76,6 +76,7 @@ public class Program extends BaseObj { Program(long id, RenderScript rs) { super(id, rs); + guard.open("destroy"); } /** diff --git a/rs/java/android/renderscript/RenderScript.java b/rs/java/android/renderscript/RenderScript.java index 4440417333f8..3d1370a52ae3 100644 --- a/rs/java/android/renderscript/RenderScript.java +++ b/rs/java/android/renderscript/RenderScript.java @@ -18,17 +18,20 @@ package android.renderscript; import java.io.File; import java.lang.reflect.Method; +import java.nio.ByteBuffer; +import java.util.ArrayList; import java.util.concurrent.locks.ReentrantReadWriteLock; import android.content.Context; import android.content.res.AssetManager; import android.graphics.Bitmap; import android.graphics.SurfaceTexture; -import android.util.Log; -import android.view.Surface; import android.os.SystemProperties; import android.os.Trace; -import java.util.ArrayList; +import android.util.Log; +import android.view.Surface; + +// TODO: Clean up the whitespace that separates methods in this class. /** * This class provides access to a RenderScript context, which controls RenderScript @@ -88,6 +91,14 @@ public class RenderScript { */ public static final int CREATE_FLAG_LOW_POWER = 0x0004; + /** + * @hide + * Context creation flag which instructs the implementation to wait for + * a debugger to be attached before continuing execution. + */ + public static final int CREATE_FLAG_WAIT_FOR_ATTACH = 0x0008; + + /* * Detect the bitness of the VM to allow FieldPacker to do the right thing. */ @@ -466,12 +477,28 @@ public class RenderScript { rsnAllocationCopyToBitmap(mContext, alloc, bmp); } - native void rsnAllocationSyncAll(long con, long alloc, int src); synchronized void nAllocationSyncAll(long alloc, int src) { validate(); rsnAllocationSyncAll(mContext, alloc, src); } + + native ByteBuffer rsnAllocationGetByteBuffer(long con, long alloc, long[] stride, int xBytesSize, int dimY, int dimZ); + synchronized ByteBuffer nAllocationGetByteBuffer(long alloc, long[] stride, int xBytesSize, int dimY, int dimZ) { + validate(); + return rsnAllocationGetByteBuffer(mContext, alloc, stride, xBytesSize, dimY, dimZ); + } + + native void rsnAllocationSetupBufferQueue(long con, long alloc, int numAlloc); + synchronized void nAllocationSetupBufferQueue(long alloc, int numAlloc) { + validate(); + rsnAllocationSetupBufferQueue(mContext, alloc, numAlloc); + } + native void rsnAllocationShareBufferQueue(long con, long alloc1, long alloc2); + synchronized void nAllocationShareBufferQueue(long alloc1, long alloc2) { + validate(); + rsnAllocationShareBufferQueue(mContext, alloc1, alloc2); + } native Surface rsnAllocationGetSurface(long con, long alloc); synchronized Surface nAllocationGetSurface(long alloc) { validate(); @@ -487,13 +514,12 @@ public class RenderScript { validate(); rsnAllocationIoSend(mContext, alloc); } - native void rsnAllocationIoReceive(long con, long alloc); - synchronized void nAllocationIoReceive(long alloc) { + native long rsnAllocationIoReceive(long con, long alloc); + synchronized long nAllocationIoReceive(long alloc) { validate(); - rsnAllocationIoReceive(mContext, alloc); + return rsnAllocationIoReceive(mContext, alloc); } - native void rsnAllocationGenerateMipmaps(long con, long alloc); synchronized void nAllocationGenerateMipmaps(long alloc) { validate(); @@ -726,6 +752,22 @@ public class RenderScript { rsnScriptForEach(mContext, id, slot, ains, aout, params, limits); } + native void rsnScriptReduce(long con, long id, int slot, long ain, + long aout, int[] limits); + synchronized void nScriptReduce(long id, int slot, long ain, long aout, + int[] limits) { + validate(); + rsnScriptReduce(mContext, id, slot, ain, aout, limits); + } + + native void rsnScriptReduceNew(long con, long id, int slot, long[] ains, + long aout, int[] limits); + synchronized void nScriptReduceNew(long id, int slot, long ains[], long aout, + int[] limits) { + validate(); + rsnScriptReduceNew(mContext, id, slot, ains, aout, limits); + } + native void rsnScriptInvokeV(long con, long id, int slot, byte[] params); synchronized void nScriptInvokeV(long id, int slot, byte[] params) { validate(); @@ -989,104 +1031,103 @@ public class RenderScript { - long mDev; long mContext; private boolean mDestroyed = false; @SuppressWarnings({"FieldCanBeLocal"}) MessageThread mMessageThread; - Element mElement_U8; - Element mElement_I8; - Element mElement_U16; - Element mElement_I16; - Element mElement_U32; - Element mElement_I32; - Element mElement_U64; - Element mElement_I64; - Element mElement_F16; - Element mElement_F32; - Element mElement_F64; - Element mElement_BOOLEAN; - - Element mElement_ELEMENT; - Element mElement_TYPE; - Element mElement_ALLOCATION; - Element mElement_SAMPLER; - Element mElement_SCRIPT; - Element mElement_MESH; - Element mElement_PROGRAM_FRAGMENT; - Element mElement_PROGRAM_VERTEX; - Element mElement_PROGRAM_RASTER; - Element mElement_PROGRAM_STORE; - Element mElement_FONT; - - Element mElement_A_8; - Element mElement_RGB_565; - Element mElement_RGB_888; - Element mElement_RGBA_5551; - Element mElement_RGBA_4444; - Element mElement_RGBA_8888; - - Element mElement_HALF_2; - Element mElement_HALF_3; - Element mElement_HALF_4; - - Element mElement_FLOAT_2; - Element mElement_FLOAT_3; - Element mElement_FLOAT_4; - - Element mElement_DOUBLE_2; - Element mElement_DOUBLE_3; - Element mElement_DOUBLE_4; - - Element mElement_UCHAR_2; - Element mElement_UCHAR_3; - Element mElement_UCHAR_4; - - Element mElement_CHAR_2; - Element mElement_CHAR_3; - Element mElement_CHAR_4; - - Element mElement_USHORT_2; - Element mElement_USHORT_3; - Element mElement_USHORT_4; - - Element mElement_SHORT_2; - Element mElement_SHORT_3; - Element mElement_SHORT_4; - - Element mElement_UINT_2; - Element mElement_UINT_3; - Element mElement_UINT_4; - - Element mElement_INT_2; - Element mElement_INT_3; - Element mElement_INT_4; - - Element mElement_ULONG_2; - Element mElement_ULONG_3; - Element mElement_ULONG_4; - - Element mElement_LONG_2; - Element mElement_LONG_3; - Element mElement_LONG_4; - - Element mElement_YUV; - - Element mElement_MATRIX_4X4; - Element mElement_MATRIX_3X3; - Element mElement_MATRIX_2X2; - - Sampler mSampler_CLAMP_NEAREST; - Sampler mSampler_CLAMP_LINEAR; - Sampler mSampler_CLAMP_LINEAR_MIP_LINEAR; - Sampler mSampler_WRAP_NEAREST; - Sampler mSampler_WRAP_LINEAR; - Sampler mSampler_WRAP_LINEAR_MIP_LINEAR; - Sampler mSampler_MIRRORED_REPEAT_NEAREST; - Sampler mSampler_MIRRORED_REPEAT_LINEAR; - Sampler mSampler_MIRRORED_REPEAT_LINEAR_MIP_LINEAR; + volatile Element mElement_U8; + volatile Element mElement_I8; + volatile Element mElement_U16; + volatile Element mElement_I16; + volatile Element mElement_U32; + volatile Element mElement_I32; + volatile Element mElement_U64; + volatile Element mElement_I64; + volatile Element mElement_F16; + volatile Element mElement_F32; + volatile Element mElement_F64; + volatile Element mElement_BOOLEAN; + + volatile Element mElement_ELEMENT; + volatile Element mElement_TYPE; + volatile Element mElement_ALLOCATION; + volatile Element mElement_SAMPLER; + volatile Element mElement_SCRIPT; + volatile Element mElement_MESH; + volatile Element mElement_PROGRAM_FRAGMENT; + volatile Element mElement_PROGRAM_VERTEX; + volatile Element mElement_PROGRAM_RASTER; + volatile Element mElement_PROGRAM_STORE; + volatile Element mElement_FONT; + + volatile Element mElement_A_8; + volatile Element mElement_RGB_565; + volatile Element mElement_RGB_888; + volatile Element mElement_RGBA_5551; + volatile Element mElement_RGBA_4444; + volatile Element mElement_RGBA_8888; + + volatile Element mElement_HALF_2; + volatile Element mElement_HALF_3; + volatile Element mElement_HALF_4; + + volatile Element mElement_FLOAT_2; + volatile Element mElement_FLOAT_3; + volatile Element mElement_FLOAT_4; + + volatile Element mElement_DOUBLE_2; + volatile Element mElement_DOUBLE_3; + volatile Element mElement_DOUBLE_4; + + volatile Element mElement_UCHAR_2; + volatile Element mElement_UCHAR_3; + volatile Element mElement_UCHAR_4; + + volatile Element mElement_CHAR_2; + volatile Element mElement_CHAR_3; + volatile Element mElement_CHAR_4; + + volatile Element mElement_USHORT_2; + volatile Element mElement_USHORT_3; + volatile Element mElement_USHORT_4; + + volatile Element mElement_SHORT_2; + volatile Element mElement_SHORT_3; + volatile Element mElement_SHORT_4; + + volatile Element mElement_UINT_2; + volatile Element mElement_UINT_3; + volatile Element mElement_UINT_4; + + volatile Element mElement_INT_2; + volatile Element mElement_INT_3; + volatile Element mElement_INT_4; + + volatile Element mElement_ULONG_2; + volatile Element mElement_ULONG_3; + volatile Element mElement_ULONG_4; + + volatile Element mElement_LONG_2; + volatile Element mElement_LONG_3; + volatile Element mElement_LONG_4; + + volatile Element mElement_YUV; + + volatile Element mElement_MATRIX_4X4; + volatile Element mElement_MATRIX_3X3; + volatile Element mElement_MATRIX_2X2; + + volatile Sampler mSampler_CLAMP_NEAREST; + volatile Sampler mSampler_CLAMP_LINEAR; + volatile Sampler mSampler_CLAMP_LINEAR_MIP_LINEAR; + volatile Sampler mSampler_WRAP_NEAREST; + volatile Sampler mSampler_WRAP_LINEAR; + volatile Sampler mSampler_WRAP_LINEAR_MIP_LINEAR; + volatile Sampler mSampler_MIRRORED_REPEAT_NEAREST; + volatile Sampler mSampler_MIRRORED_REPEAT_LINEAR; + volatile Sampler mSampler_MIRRORED_REPEAT_LINEAR_MIP_LINEAR; ProgramStore mProgramStore_BLEND_NONE_DEPTH_TEST; ProgramStore mProgramStore_BLEND_NONE_DEPTH_NO_DEPTH; @@ -1345,6 +1386,27 @@ public class RenderScript { } /** + * Name of the file that holds the object cache. + */ + private static String mCachePath; + + /** + * Gets the path to the code cache. + */ + static synchronized String getCachePath() { + if (mCachePath == null) { + final String CACHE_PATH = "com.android.renderscript.cache"; + if (RenderScriptCacheDir.mCacheDir == null) { + throw new RSRuntimeException("RenderScript code cache directory uninitialized."); + } + File f = new File(RenderScriptCacheDir.mCacheDir, CACHE_PATH); + mCachePath = f.getAbsolutePath(); + f.mkdirs(); + } + return mCachePath; + } + + /** * Create a RenderScript context. * * @param ctx The context. @@ -1356,14 +1418,15 @@ public class RenderScript { return null; } - if ((flags & ~(CREATE_FLAG_LOW_LATENCY | CREATE_FLAG_LOW_POWER)) != 0) { + if ((flags & ~(CREATE_FLAG_LOW_LATENCY | CREATE_FLAG_LOW_POWER | + CREATE_FLAG_WAIT_FOR_ATTACH)) != 0) { throw new RSIllegalArgumentException("Invalid flags passed."); } RenderScript rs = new RenderScript(ctx); - rs.mDev = rs.nDeviceCreate(); - rs.mContext = rs.nContextCreate(rs.mDev, flags, sdkVersion, ct.mID); + long device = rs.nDeviceCreate(); + rs.mContext = rs.nContextCreate(device, flags, sdkVersion, ct.mID); rs.mContextType = ct; rs.mContextFlags = flags; rs.mContextSdkVersion = sdkVersion; @@ -1372,11 +1435,7 @@ public class RenderScript { } // set up cache directory for entire context - final String CACHE_PATH = "com.android.renderscript.cache"; - File f = new File(RenderScriptCacheDir.mCacheDir, CACHE_PATH); - String mCachePath = f.getAbsolutePath(); - f.mkdirs(); - rs.nContextSetCacheDir(mCachePath); + rs.nContextSetCacheDir(RenderScript.getCachePath()); rs.mMessageThread = new MessageThread(rs); rs.mMessageThread.start(); @@ -1575,9 +1634,6 @@ public class RenderScript { } nContextDestroy(); - - nDeviceDestroy(mDev); - mDev = 0; } } diff --git a/rs/java/android/renderscript/RenderScriptGL.java b/rs/java/android/renderscript/RenderScriptGL.java index 6178994cfbe3..be1f899bd08b 100644 --- a/rs/java/android/renderscript/RenderScriptGL.java +++ b/rs/java/android/renderscript/RenderScriptGL.java @@ -177,9 +177,9 @@ public class RenderScriptGL extends RenderScript { mWidth = 0; mHeight = 0; - mDev = nDeviceCreate(); + long device = nDeviceCreate(); int dpi = ctx.getResources().getDisplayMetrics().densityDpi; - mContext = nContextCreateGL(mDev, 0, sdkVersion, + mContext = nContextCreateGL(device, 0, sdkVersion, mSurfaceConfig.mColorMin, mSurfaceConfig.mColorPref, mSurfaceConfig.mAlphaMin, mSurfaceConfig.mAlphaPref, mSurfaceConfig.mDepthMin, mSurfaceConfig.mDepthPref, diff --git a/rs/java/android/renderscript/Sampler.java b/rs/java/android/renderscript/Sampler.java index a4edbb50ac10..70e88bc51f79 100644 --- a/rs/java/android/renderscript/Sampler.java +++ b/rs/java/android/renderscript/Sampler.java @@ -51,6 +51,7 @@ public class Sampler extends BaseObj { Sampler(long id, RenderScript rs) { super(id, rs); + guard.open("destroy"); } /** @@ -97,13 +98,17 @@ public class Sampler extends BaseObj { * @return Sampler */ public static Sampler CLAMP_NEAREST(RenderScript rs) { - if(rs.mSampler_CLAMP_NEAREST == null) { - Builder b = new Builder(rs); - b.setMinification(Value.NEAREST); - b.setMagnification(Value.NEAREST); - b.setWrapS(Value.CLAMP); - b.setWrapT(Value.CLAMP); - rs.mSampler_CLAMP_NEAREST = b.create(); + if (rs.mSampler_CLAMP_NEAREST == null) { + synchronized (rs) { + if (rs.mSampler_CLAMP_NEAREST == null) { + Builder b = new Builder(rs); + b.setMinification(Value.NEAREST); + b.setMagnification(Value.NEAREST); + b.setWrapS(Value.CLAMP); + b.setWrapT(Value.CLAMP); + rs.mSampler_CLAMP_NEAREST = b.create(); + } + } } return rs.mSampler_CLAMP_NEAREST; } @@ -117,13 +122,17 @@ public class Sampler extends BaseObj { * @return Sampler */ public static Sampler CLAMP_LINEAR(RenderScript rs) { - if(rs.mSampler_CLAMP_LINEAR == null) { - Builder b = new Builder(rs); - b.setMinification(Value.LINEAR); - b.setMagnification(Value.LINEAR); - b.setWrapS(Value.CLAMP); - b.setWrapT(Value.CLAMP); - rs.mSampler_CLAMP_LINEAR = b.create(); + if (rs.mSampler_CLAMP_LINEAR == null) { + synchronized (rs) { + if (rs.mSampler_CLAMP_LINEAR == null) { + Builder b = new Builder(rs); + b.setMinification(Value.LINEAR); + b.setMagnification(Value.LINEAR); + b.setWrapS(Value.CLAMP); + b.setWrapT(Value.CLAMP); + rs.mSampler_CLAMP_LINEAR = b.create(); + } + } } return rs.mSampler_CLAMP_LINEAR; } @@ -137,13 +146,17 @@ public class Sampler extends BaseObj { * @return Sampler */ public static Sampler CLAMP_LINEAR_MIP_LINEAR(RenderScript rs) { - if(rs.mSampler_CLAMP_LINEAR_MIP_LINEAR == null) { - Builder b = new Builder(rs); - b.setMinification(Value.LINEAR_MIP_LINEAR); - b.setMagnification(Value.LINEAR); - b.setWrapS(Value.CLAMP); - b.setWrapT(Value.CLAMP); - rs.mSampler_CLAMP_LINEAR_MIP_LINEAR = b.create(); + if (rs.mSampler_CLAMP_LINEAR_MIP_LINEAR == null) { + synchronized (rs) { + if (rs.mSampler_CLAMP_LINEAR_MIP_LINEAR == null) { + Builder b = new Builder(rs); + b.setMinification(Value.LINEAR_MIP_LINEAR); + b.setMagnification(Value.LINEAR); + b.setWrapS(Value.CLAMP); + b.setWrapT(Value.CLAMP); + rs.mSampler_CLAMP_LINEAR_MIP_LINEAR = b.create(); + } + } } return rs.mSampler_CLAMP_LINEAR_MIP_LINEAR; } @@ -157,13 +170,17 @@ public class Sampler extends BaseObj { * @return Sampler */ public static Sampler WRAP_NEAREST(RenderScript rs) { - if(rs.mSampler_WRAP_NEAREST == null) { - Builder b = new Builder(rs); - b.setMinification(Value.NEAREST); - b.setMagnification(Value.NEAREST); - b.setWrapS(Value.WRAP); - b.setWrapT(Value.WRAP); - rs.mSampler_WRAP_NEAREST = b.create(); + if (rs.mSampler_WRAP_NEAREST == null) { + synchronized (rs) { + if (rs.mSampler_WRAP_NEAREST == null) { + Builder b = new Builder(rs); + b.setMinification(Value.NEAREST); + b.setMagnification(Value.NEAREST); + b.setWrapS(Value.WRAP); + b.setWrapT(Value.WRAP); + rs.mSampler_WRAP_NEAREST = b.create(); + } + } } return rs.mSampler_WRAP_NEAREST; } @@ -177,13 +194,17 @@ public class Sampler extends BaseObj { * @return Sampler */ public static Sampler WRAP_LINEAR(RenderScript rs) { - if(rs.mSampler_WRAP_LINEAR == null) { - Builder b = new Builder(rs); - b.setMinification(Value.LINEAR); - b.setMagnification(Value.LINEAR); - b.setWrapS(Value.WRAP); - b.setWrapT(Value.WRAP); - rs.mSampler_WRAP_LINEAR = b.create(); + if (rs.mSampler_WRAP_LINEAR == null) { + synchronized (rs) { + if (rs.mSampler_WRAP_LINEAR == null) { + Builder b = new Builder(rs); + b.setMinification(Value.LINEAR); + b.setMagnification(Value.LINEAR); + b.setWrapS(Value.WRAP); + b.setWrapT(Value.WRAP); + rs.mSampler_WRAP_LINEAR = b.create(); + } + } } return rs.mSampler_WRAP_LINEAR; } @@ -197,13 +218,17 @@ public class Sampler extends BaseObj { * @return Sampler */ public static Sampler WRAP_LINEAR_MIP_LINEAR(RenderScript rs) { - if(rs.mSampler_WRAP_LINEAR_MIP_LINEAR == null) { - Builder b = new Builder(rs); - b.setMinification(Value.LINEAR_MIP_LINEAR); - b.setMagnification(Value.LINEAR); - b.setWrapS(Value.WRAP); - b.setWrapT(Value.WRAP); - rs.mSampler_WRAP_LINEAR_MIP_LINEAR = b.create(); + if (rs.mSampler_WRAP_LINEAR_MIP_LINEAR == null) { + synchronized (rs) { + if (rs.mSampler_WRAP_LINEAR_MIP_LINEAR == null) { + Builder b = new Builder(rs); + b.setMinification(Value.LINEAR_MIP_LINEAR); + b.setMagnification(Value.LINEAR); + b.setWrapS(Value.WRAP); + b.setWrapT(Value.WRAP); + rs.mSampler_WRAP_LINEAR_MIP_LINEAR = b.create(); + } + } } return rs.mSampler_WRAP_LINEAR_MIP_LINEAR; } @@ -217,13 +242,17 @@ public class Sampler extends BaseObj { * @return Sampler */ public static Sampler MIRRORED_REPEAT_NEAREST(RenderScript rs) { - if(rs.mSampler_MIRRORED_REPEAT_NEAREST == null) { - Builder b = new Builder(rs); - b.setMinification(Value.NEAREST); - b.setMagnification(Value.NEAREST); - b.setWrapS(Value.MIRRORED_REPEAT); - b.setWrapT(Value.MIRRORED_REPEAT); - rs.mSampler_MIRRORED_REPEAT_NEAREST = b.create(); + if (rs.mSampler_MIRRORED_REPEAT_NEAREST == null) { + synchronized (rs) { + if (rs.mSampler_MIRRORED_REPEAT_NEAREST == null) { + Builder b = new Builder(rs); + b.setMinification(Value.NEAREST); + b.setMagnification(Value.NEAREST); + b.setWrapS(Value.MIRRORED_REPEAT); + b.setWrapT(Value.MIRRORED_REPEAT); + rs.mSampler_MIRRORED_REPEAT_NEAREST = b.create(); + } + } } return rs.mSampler_MIRRORED_REPEAT_NEAREST; } @@ -237,13 +266,17 @@ public class Sampler extends BaseObj { * @return Sampler */ public static Sampler MIRRORED_REPEAT_LINEAR(RenderScript rs) { - if(rs.mSampler_MIRRORED_REPEAT_LINEAR == null) { - Builder b = new Builder(rs); - b.setMinification(Value.LINEAR); - b.setMagnification(Value.LINEAR); - b.setWrapS(Value.MIRRORED_REPEAT); - b.setWrapT(Value.MIRRORED_REPEAT); - rs.mSampler_MIRRORED_REPEAT_LINEAR = b.create(); + if (rs.mSampler_MIRRORED_REPEAT_LINEAR == null) { + synchronized (rs) { + if (rs.mSampler_MIRRORED_REPEAT_LINEAR == null) { + Builder b = new Builder(rs); + b.setMinification(Value.LINEAR); + b.setMagnification(Value.LINEAR); + b.setWrapS(Value.MIRRORED_REPEAT); + b.setWrapT(Value.MIRRORED_REPEAT); + rs.mSampler_MIRRORED_REPEAT_LINEAR = b.create(); + } + } } return rs.mSampler_MIRRORED_REPEAT_LINEAR; } @@ -257,13 +290,17 @@ public class Sampler extends BaseObj { * @return Sampler */ public static Sampler MIRRORED_REPEAT_LINEAR_MIP_LINEAR(RenderScript rs) { - if(rs.mSampler_MIRRORED_REPEAT_LINEAR_MIP_LINEAR == null) { - Builder b = new Builder(rs); - b.setMinification(Value.LINEAR_MIP_LINEAR); - b.setMagnification(Value.LINEAR); - b.setWrapS(Value.MIRRORED_REPEAT); - b.setWrapT(Value.MIRRORED_REPEAT); - rs.mSampler_MIRRORED_REPEAT_LINEAR_MIP_LINEAR = b.create(); + if (rs.mSampler_MIRRORED_REPEAT_LINEAR_MIP_LINEAR == null) { + synchronized (rs) { + if (rs.mSampler_MIRRORED_REPEAT_LINEAR_MIP_LINEAR == null) { + Builder b = new Builder(rs); + b.setMinification(Value.LINEAR_MIP_LINEAR); + b.setMagnification(Value.LINEAR); + b.setWrapS(Value.MIRRORED_REPEAT); + b.setWrapT(Value.MIRRORED_REPEAT); + rs.mSampler_MIRRORED_REPEAT_LINEAR_MIP_LINEAR = b.create(); + } + } } return rs.mSampler_MIRRORED_REPEAT_LINEAR_MIP_LINEAR; } diff --git a/rs/java/android/renderscript/Script.java b/rs/java/android/renderscript/Script.java index 7cd6d09e2812..fc3280be3ac7 100644 --- a/rs/java/android/renderscript/Script.java +++ b/rs/java/android/renderscript/Script.java @@ -41,6 +41,7 @@ public class Script extends BaseObj { mScript = s; mSlot = slot; mSig = sig; + guard.open("destroy"); } } @@ -118,6 +119,7 @@ public class Script extends BaseObj { super(id, rs); mScript = s; mSlot = slot; + guard.open("destroy"); } } @@ -283,14 +285,94 @@ public class Script extends BaseObj { mRS.nScriptForEach(getID(mRS), slot, in_ids, out_id, params, limits); } + /** + * Only intended for use by generated reflected code. (Simple reduction) + * + * @hide + */ + protected void reduce(int slot, Allocation ain, Allocation aout, LaunchOptions sc) { + mRS.validate(); + mRS.validateObject(ain); + mRS.validateObject(aout); + + if (ain == null || aout == null) { + throw new RSIllegalArgumentException( + "Both ain and aout are required to be non-null."); + } + + long in_id = ain.getID(mRS); + long out_id = aout.getID(mRS); + + int[] limits = null; + if (sc != null) { + limits = new int[2]; + + limits[0] = sc.xstart; + limits[1] = sc.xend; + } + + mRS.nScriptReduce(getID(mRS), slot, in_id, out_id, limits); + } + + /** + * Only intended for use by generated reflected code. (General reduction) + * + */ + protected void reduce(int slot, Allocation[] ains, Allocation aout, LaunchOptions sc) { + mRS.validate(); + if (ains == null || ains.length < 1) { + throw new RSIllegalArgumentException( + "At least one input is required."); + } + if (aout == null) { + throw new RSIllegalArgumentException( + "aout is required to be non-null."); + } + for (Allocation ain : ains) { + mRS.validateObject(ain); + } + + long[] in_ids = new long[ains.length]; + for (int index = 0; index < ains.length; ++index) { + in_ids[index] = ains[index].getID(mRS); + } + long out_id = aout.getID(mRS); + + int[] limits = null; + if (sc != null) { + limits = new int[6]; + + limits[0] = sc.xstart; + limits[1] = sc.xend; + limits[2] = sc.ystart; + limits[3] = sc.yend; + limits[4] = sc.zstart; + limits[5] = sc.zend; + } + + mRS.nScriptReduceNew(getID(mRS), slot, in_ids, out_id, limits); + } + long[] mInIdsBuffer; Script(long id, RenderScript rs) { super(id, rs); mInIdsBuffer = new long[1]; - } + /* The constructors for the derived classes (including ScriptIntrinsic + * derived classes and ScriptC derived classes generated by Slang + * reflection) seem to be simple enough, so we just put the guard.open() + * call here, rather than in the end of the constructor for the derived + * class. This, of course, assumes the derived constructor would not + * throw any exception after calling this constructor. + * + * If new derived classes are added with more complicated constructors + * that throw exceptions, this call has to be (duplicated and) moved + * to the end of each derived class constructor. + */ + guard.open("destroy"); + } /** * Only intended for use by generated reflected code. @@ -474,21 +556,22 @@ public class Script extends BaseObj { /** * Class for specifying the specifics about how a kernel will be - * launched + * launched. * * This class can specify a potential range of cells on which to * run a kernel. If no set is called for a dimension then this * class will have no impact on that dimension when the kernel * is executed. * - * The forEach launch will operate over the intersection of the - * dimensions. + * The forEach kernel launch will operate over the intersection of + * the dimensions. * * Example: * LaunchOptions with setX(5, 15) * Allocation with dimension X=10, Y=10 - * The resulting forEach run would execute over x = 5 to 10 and - * y = 0 to 10. + * The resulting forEach run would execute over: + * x = 5 to 9 (inclusive) and + * y = 0 to 9 (inclusive). * * */ @@ -502,11 +585,11 @@ public class Script extends BaseObj { private int strategy; /** - * Set the X range. If the end value is set to 0 the X dimension is not - * clipped. + * Set the X range. xstartArg is the lowest coordinate of the range, + * and xendArg-1 is the highest coordinate of the range. * * @param xstartArg Must be >= 0 - * @param xendArg Must be >= xstartArg + * @param xendArg Must be > xstartArg * * @return LaunchOptions */ @@ -520,11 +603,11 @@ public class Script extends BaseObj { } /** - * Set the Y range. If the end value is set to 0 the Y dimension is not - * clipped. + * Set the Y range. ystartArg is the lowest coordinate of the range, + * and yendArg-1 is the highest coordinate of the range. * * @param ystartArg Must be >= 0 - * @param yendArg Must be >= ystartArg + * @param yendArg Must be > ystartArg * * @return LaunchOptions */ @@ -538,11 +621,11 @@ public class Script extends BaseObj { } /** - * Set the Z range. If the end value is set to 0 the Z dimension is not - * clipped. + * Set the Z range. zstartArg is the lowest coordinate of the range, + * and zendArg-1 is the highest coordinate of the range. * * @param zstartArg Must be >= 0 - * @param zendArg Must be >= zstartArg + * @param zendArg Must be > zstartArg * * @return LaunchOptions */ diff --git a/rs/java/android/renderscript/ScriptC.java b/rs/java/android/renderscript/ScriptC.java index bf706c131e85..00ebe5756589 100644 --- a/rs/java/android/renderscript/ScriptC.java +++ b/rs/java/android/renderscript/ScriptC.java @@ -84,13 +84,6 @@ 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 long internalCreate(RenderScript rs, Resources resources, int resourceID) { byte[] pgm; int pgmLength; @@ -122,26 +115,12 @@ 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(RenderScriptCacheDir.mCacheDir, CACHE_PATH); - mCachePath = f.getAbsolutePath(); - f.mkdirs(); - } // Log.v(TAG, "Create script for resource = " + resName); - return rs.nScriptCCreate(resName, mCachePath, pgm, pgmLength); + return rs.nScriptCCreate(resName, RenderScript.getCachePath(), pgm, pgmLength); } private static synchronized long internalStringCreate(RenderScript rs, String resName, byte[] bitcode) { - // Create the RS cache path if we haven't done so already. - if (mCachePath == null) { - File f = new File(RenderScriptCacheDir.mCacheDir, CACHE_PATH); - mCachePath = f.getAbsolutePath(); - f.mkdirs(); - } // Log.v(TAG, "Create script for resource = " + resName); - return rs.nScriptCCreate(resName, mCachePath, bitcode, bitcode.length); + return rs.nScriptCCreate(resName, RenderScript.getCachePath(), bitcode, bitcode.length); } - - } diff --git a/rs/java/android/renderscript/ScriptGroup.java b/rs/java/android/renderscript/ScriptGroup.java index 54180f447c36..e0bdbfcdfed5 100644 --- a/rs/java/android/renderscript/ScriptGroup.java +++ b/rs/java/android/renderscript/ScriptGroup.java @@ -148,6 +148,8 @@ public final class ScriptGroup extends BaseObj { fieldIDs, values, sizes, depClosures, depFieldIDs); setID(id); + + guard.open("destroy"); } Closure(RenderScript rs, Script.InvokeID invokeID, @@ -181,6 +183,25 @@ public final class ScriptGroup extends BaseObj { values, sizes); setID(id); + + guard.open("destroy"); + } + + /** + * Destroys this Closure and the Allocation for its return value + */ + public void destroy() { + super.destroy(); + if (mReturnValue != null) { + mReturnValue.destroy(); + } + } + + protected void finalize() throws Throwable { + // Set null mReturnValue to avoid double-destroying it, in case its + // finalizer races ahead. + mReturnValue = null; + super.finalize(); } private void retrieveValueAndDependenceInfo(RenderScript rs, @@ -278,6 +299,8 @@ public final class ScriptGroup extends BaseObj { public ValueAndSize(RenderScript rs, Object obj) { if (obj instanceof Allocation) { value = ((Allocation)obj).getID(rs); + // Special value for size to tell the runtime and driver that + // the value is an Allocation size = -1; } else if (obj instanceof Boolean) { value = ((Boolean)obj).booleanValue() ? 1 : 0; @@ -289,10 +312,10 @@ public final class ScriptGroup extends BaseObj { value = ((Long)obj).longValue(); size = 8; } else if (obj instanceof Float) { - value = ((Float)obj).longValue(); + value = Float.floatToRawIntBits(((Float)obj).floatValue()); size = 4; } else if (obj instanceof Double) { - value = ((Double)obj).longValue(); + value = Double.doubleToRawLongBits(((Double)obj).doubleValue()); size = 8; } } @@ -380,6 +403,7 @@ public final class ScriptGroup extends BaseObj { ScriptGroup(long id, RenderScript rs) { super(id, rs); + guard.open("destroy"); } ScriptGroup(RenderScript rs, String name, List<Closure> closures, @@ -394,8 +418,9 @@ public final class ScriptGroup extends BaseObj { for (int i = 0; i < closureIDs.length; i++) { closureIDs[i] = closures.get(i).getID(rs); } - long id = rs.nScriptGroup2Create(name, ScriptC.mCachePath, closureIDs); + long id = rs.nScriptGroup2Create(name, RenderScript.getCachePath(), closureIDs); setID(id); + guard.open("destroy"); } /** @@ -1007,6 +1032,8 @@ public final class ScriptGroup extends BaseObj { throw new RSIllegalArgumentException("invalid script group name"); } ScriptGroup ret = new ScriptGroup(mRS, name, mClosures, mInputs, outputs); + mClosures = new ArrayList<Closure>(); + mInputs = new ArrayList<Input>(); return ret; } @@ -1034,4 +1061,17 @@ public final class ScriptGroup extends BaseObj { } + /** + * Destroy this ScriptGroup and all Closures in it + */ + public void destroy() { + super.destroy(); + // ScriptGroup created using the old Builder class does not + // initialize the field mClosures + if (mClosures != null) { + for (Closure c : mClosures) { + c.destroy(); + } + } + } } diff --git a/rs/java/android/renderscript/ScriptIntrinsicBlend.java b/rs/java/android/renderscript/ScriptIntrinsicBlend.java index 6b09bb7a7741..fdcd61b04eca 100644 --- a/rs/java/android/renderscript/ScriptIntrinsicBlend.java +++ b/rs/java/android/renderscript/ScriptIntrinsicBlend.java @@ -406,6 +406,8 @@ public class ScriptIntrinsicBlend extends ScriptIntrinsic { /** * Sets dst = {src.r ^ dst.r, src.g ^ dst.g, src.b ^ dst.b, src.a ^ dst.a} * + * <b>Note:</b> this is NOT the Porter/Duff XOR mode; this is a bitwise xor. + * * @param ain The source buffer * @param aout The destination buffer * @param opt LaunchOptions for clipping diff --git a/rs/java/android/renderscript/ScriptIntrinsicConvolve3x3.java b/rs/java/android/renderscript/ScriptIntrinsicConvolve3x3.java index 76da781004d8..339e0e9dc975 100644 --- a/rs/java/android/renderscript/ScriptIntrinsicConvolve3x3.java +++ b/rs/java/android/renderscript/ScriptIntrinsicConvolve3x3.java @@ -32,10 +32,9 @@ public final class ScriptIntrinsicConvolve3x3 extends ScriptIntrinsic { * Supported elements types are {@link Element#U8}, {@link * Element#U8_2}, {@link Element#U8_3}, {@link Element#U8_4}, * {@link Element#F32}, {@link Element#F32_2}, {@link - * Element#F32_3}, and {@link Element#F32_4} - * - * The default coefficients are. + * Element#F32_3}, and {@link Element#F32_4}. * + * <p> The default coefficients are: * <code> * <p> [ 0, 0, 0 ] * <p> [ 0, 1, 0 ] @@ -67,7 +66,7 @@ public final class ScriptIntrinsicConvolve3x3 extends ScriptIntrinsic { } /** - * Set the input of the blur. + * Set the input of the 3x3 convolve. * Must match the element type supplied during create. * * @param ain The input allocation. @@ -80,7 +79,7 @@ public final class ScriptIntrinsicConvolve3x3 extends ScriptIntrinsic { /** * Set the coefficients for the convolve. * - * The convolve layout is + * <p> The convolve layout is: * <code> * <p> [ 0, 1, 2 ] * <p> [ 3, 4, 5 ] diff --git a/rs/java/android/renderscript/ScriptIntrinsicConvolve5x5.java b/rs/java/android/renderscript/ScriptIntrinsicConvolve5x5.java index 2d37600dc492..a288cee407f0 100644 --- a/rs/java/android/renderscript/ScriptIntrinsicConvolve5x5.java +++ b/rs/java/android/renderscript/ScriptIntrinsicConvolve5x5.java @@ -32,9 +32,9 @@ public final class ScriptIntrinsicConvolve5x5 extends ScriptIntrinsic { * Supported elements types are {@link Element#U8}, {@link * Element#U8_2}, {@link Element#U8_3}, {@link Element#U8_4}, * {@link Element#F32}, {@link Element#F32_2}, {@link - * Element#F32_3}, and {@link Element#F32_4} + * Element#F32_3}, and {@link Element#F32_4}. * - * The default coefficients are. + * <p> The default coefficients are: * <code> * <p> [ 0, 0, 0, 0, 0 ] * <p> [ 0, 0, 0, 0, 0 ] @@ -66,7 +66,7 @@ public final class ScriptIntrinsicConvolve5x5 extends ScriptIntrinsic { } /** - * Set the input of the blur. + * Set the input of the 5x5 convolve. * Must match the element type supplied during create. * * @param ain The input allocation. @@ -79,7 +79,7 @@ public final class ScriptIntrinsicConvolve5x5 extends ScriptIntrinsic { /** * Set the coefficients for the convolve. * - * The convolve layout is + * <p> The convolve layout is: * <code> * <p> [ 0, 1, 2, 3, 4 ] * <p> [ 5, 6, 7, 8, 9 ] diff --git a/rs/java/android/renderscript/Type.java b/rs/java/android/renderscript/Type.java index dc2378596d00..9252898781f4 100644 --- a/rs/java/android/renderscript/Type.java +++ b/rs/java/android/renderscript/Type.java @@ -227,6 +227,7 @@ public class Type extends BaseObj { Type(long id, RenderScript rs) { super(id, rs); + guard.open("destroy"); } @Override |