From 8c1509249c5552270d8accc2c9512f499a8f5e2d Mon Sep 17 00:00:00 2001 From: Miao Wang Date: Mon, 26 Oct 2015 17:44:10 -0700 Subject: [PATCH] [RenderScript] Implement APIs for better multi-frame process support. Bug: 23535524 Two APIs added for multiframe processing: - createAllocations(...): To create an array of Allocations sharing the same Type and Usage. For USAGE_IO_INPUT Allocations, they also share the same BufferQueue. - getTimeStamp(): API to retrieve the time stamp associated with the most recent buffer. Change-Id: I6b7b35d7dca5e87ee2f3db2ee17cb9cf824bcfe1 --- rs/java/android/renderscript/Allocation.java | 155 ++++++++++++++++++++++++- rs/java/android/renderscript/RenderScript.java | 18 ++- rs/jni/android_renderscript_RenderScript.cpp | 30 ++++- 3 files changed, 188 insertions(+), 15 deletions(-) diff --git a/rs/java/android/renderscript/Allocation.java b/rs/java/android/renderscript/Allocation.java index a71ba6364ac8..4bda87e918de 100644 --- a/rs/java/android/renderscript/Allocation.java +++ b/rs/java/android/renderscript/Allocation.java @@ -55,12 +55,16 @@ import android.view.Surface; **/ public class Allocation extends BaseObj { + private static final int MAX_NUMBER_IO_INPUT_ALLOC = 16; + Type mType; Bitmap mBitmap; int mUsage; Allocation mAdaptedAllocation; int mSize; + MipmapControl mMipmapControl; + long mTimeStamp = -1; boolean mReadAllowed = true; boolean mWriteAllowed = true; boolean mAutoPadding = false; @@ -278,6 +282,17 @@ public class Allocation extends BaseObj { } /** + * @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. * By default: Diabled. * @@ -359,6 +374,11 @@ public class Allocation extends BaseObj { } } + Allocation(long id, RenderScript rs, Type t, int usage, MipmapControl mips) { + this(id, rs, t, usage); + mMipmapControl = mips; + } + protected void finalize() throws Throwable { RenderScript.registerNativeFree.invoke(RenderScript.sRuntime, mSize); super.finalize(); @@ -521,7 +541,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); } @@ -1890,7 +1910,7 @@ public class Allocation extends BaseObj { if (id == 0) { throw new RSRuntimeException("Allocation creation failed."); } - return new Allocation(id, rs, type, usage); + return new Allocation(id, rs, type, usage, mips); } finally { Trace.traceEnd(RenderScript.TRACE_TAG); } @@ -1948,7 +1968,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, usage, MipmapControl.MIPMAP_NONE); } finally { Trace.traceEnd(RenderScript.TRACE_TAG); } @@ -2037,7 +2057,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, usage, mips); alloc.setBitmap(b); return alloc; } @@ -2047,7 +2067,7 @@ 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, usage, mips); } finally { Trace.traceEnd(RenderScript.TRACE_TAG); } @@ -2090,6 +2110,108 @@ public class Allocation extends BaseObj { /** * @hide + * 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