diff options
author | Jason Sams <rjsams@android.com> | 2012-02-15 12:04:24 -0800 |
---|---|---|
committer | Jason Sams <rjsams@android.com> | 2012-02-15 12:04:24 -0800 |
commit | 163766cbe798baf8e86eb8201bc6c3def931d59a (patch) | |
tree | e78c46b84146c0aec0948e65a016ea64dd437157 /graphics | |
parent | ea555e27407ad2a32d2682c08f423d2af71f2a91 (diff) | |
download | frameworks_base-163766cbe798baf8e86eb8201bc6c3def931d59a.zip frameworks_base-163766cbe798baf8e86eb8201bc6c3def931d59a.tar.gz frameworks_base-163766cbe798baf8e86eb8201bc6c3def931d59a.tar.bz2 |
Beging IO stream out from allocation to surface texture.
Change-Id: I4d6b7f7740a896d39b811d6fe7532bb00db62373
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/java/android/renderscript/Allocation.java | 95 | ||||
-rw-r--r-- | graphics/java/android/renderscript/RenderScript.java | 16 | ||||
-rw-r--r-- | graphics/jni/android_renderscript_RenderScript.cpp | 34 |
3 files changed, 129 insertions, 16 deletions
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java index 44401c8..37a270e 100644 --- a/graphics/java/android/renderscript/Allocation.java +++ b/graphics/java/android/renderscript/Allocation.java @@ -102,7 +102,7 @@ public class Allocation extends BaseObj { public static final int USAGE_SCRIPT = 0x0001; /** - * GRAPHICS_TEXTURE The allcation will be used as a texture + * GRAPHICS_TEXTURE The allocation will be used as a texture * source by one or more graphics programs. * */ @@ -124,34 +124,34 @@ public class Allocation extends BaseObj { public static final int USAGE_GRAPHICS_CONSTANTS = 0x0008; /** - * USAGE_GRAPHICS_RENDER_TARGET The allcation will be used as a + * USAGE_GRAPHICS_RENDER_TARGET The allocation will be used as a * target for offscreen rendering * */ public static final int USAGE_GRAPHICS_RENDER_TARGET = 0x0010; /** - * USAGE_GRAPHICS_SURFACE_TEXTURE_INPUT The allocation will be - * used with a SurfaceTexture object. This usage will cause the - * allocation to be created read only. + * USAGE_GRAPHICS_SURFACE_TEXTURE_INPUT_OPAQUE The allocation + * will be used as a SurfaceTexture graphics consumer. This + * usage may only be used with USAGE_GRAPHICS_TEXTURE. * * @hide */ public static final int USAGE_GRAPHICS_SURFACE_TEXTURE_INPUT_OPAQUE = 0x0020; /** - * USAGE_IO_INPUT The allocation will be - * used with a SurfaceTexture object. This usage will cause the - * allocation to be created read only. + * USAGE_IO_INPUT The allocation will be used as SurfaceTexture + * consumer. This usage will cause the allocation to be created + * read only. * * @hide */ public static final int USAGE_IO_INPUT = 0x0040; /** - * USAGE_IO_OUTPUT The allocation will be - * used with a SurfaceTexture object. This usage will cause the - * allocation to be created write only. + * USAGE_IO_OUTPUT The allocation will be used as a + * SurfaceTexture producer. The dimensions and format of the + * SurfaceTexture will be forced to those of the allocation. * * @hide */ @@ -323,6 +323,37 @@ public class Allocation extends BaseObj { mRS.nAllocationSyncAll(getIDSafe(), srcLocation); } + /** + * Send a buffer to the output stream. The contents of the + * Allocation will be undefined after this operation. + * + * @hide + * + */ + public void ioSendOutput() { + if ((mUsage & USAGE_IO_OUTPUT) == 0) { + throw new RSIllegalArgumentException( + "Can only send buffer if IO_OUTPUT usage specified."); + } + mRS.validate(); + mRS.nAllocationIoSend(getID()); + } + + /** + * Receive the latest input into the Allocation. + * + * @hide + * + */ + public void ioGetInput() { + if ((mUsage & USAGE_IO_INPUT) == 0) { + throw new RSIllegalArgumentException( + "Can only send buffer if IO_OUTPUT usage specified."); + } + mRS.validate(); + mRS.nAllocationIoReceive(getID()); + } + public void copyFrom(BaseObj[] d) { mRS.validate(); validateIsObject(); @@ -887,17 +918,37 @@ 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. + * + * @hide + * @param dimX The new size of the allocation. + * @param dimY The new size of the allocation. + */ public void resize(int dimX, int dimY) { - if ((mType.getZ() > 0) || mType.getFaces() || mType.getLOD()) { - throw new RSIllegalStateException("Resize only support for 2D allocations at this time."); + 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 RSIllegalStateException("Resize only support for 2D allocations at this time."); + throw new RSInvalidStateException( + "Resize only support for 2D allocations at this time."); } mRS.nAllocationResize2D(getID(), dimX, dimY); + mRS.finish(); // Necessary because resize is fifoed and update is async. + + int typeID = mRS.nAllocationGetType(getID()); + mType = new Type(typeID, mRS); + mType.updateFromNative(); + updateCacheInfo(mType); } - */ @@ -1090,6 +1141,18 @@ public class Allocation extends BaseObj { } + /** + * @hide + */ + public void setSurfaceTexture(SurfaceTexture sur) { + if ((mUsage & USAGE_IO_OUTPUT) == 0) { + throw new RSInvalidStateException("Allocation is not USAGE_IO_OUTPUT."); + } + + mRS.validate(); + mRS.nAllocationSetSurfaceTexture(getID(), sur); + } + /** * Creates a non-mipmapped renderscript allocation to use as a diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java index d3c801f..56303f7 100644 --- a/graphics/java/android/renderscript/RenderScript.java +++ b/graphics/java/android/renderscript/RenderScript.java @@ -274,6 +274,22 @@ public class RenderScript { validate(); return rsnAllocationGetSurfaceTextureID(mContext, alloc); } + native void rsnAllocationSetSurfaceTexture(int con, int alloc, SurfaceTexture sur); + synchronized void nAllocationSetSurfaceTexture(int alloc, SurfaceTexture sur) { + validate(); + rsnAllocationSetSurfaceTexture(mContext, alloc, sur); + } + native void rsnAllocationIoSend(int con, int alloc); + synchronized void nAllocationIoSend(int alloc) { + validate(); + rsnAllocationIoSend(mContext, alloc); + } + native void rsnAllocationIoReceive(int con, int alloc); + synchronized void nAllocationIoReceive(int alloc) { + validate(); + rsnAllocationIoReceive(mContext, alloc); + } + native void rsnAllocationGenerateMipmaps(int con, int alloc); synchronized void nAllocationGenerateMipmaps(int alloc) { diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp index 94f19b3..4d087b0 100644 --- a/graphics/jni/android_renderscript_RenderScript.cpp +++ b/graphics/jni/android_renderscript_RenderScript.cpp @@ -451,6 +451,37 @@ nAllocationGetSurfaceTextureID(JNIEnv *_env, jobject _this, RsContext con, jint } static void +nAllocationSetSurfaceTexture(JNIEnv *_env, jobject _this, RsContext con, + RsAllocation alloc, jobject sur) +{ + LOG_API("nAllocationSetSurfaceTexture, con(%p), alloc(%p), surface(%p)", + con, alloc, (Surface *)sur); + + sp<ANativeWindow> window; + if (sur != 0) { + sp<SurfaceTexture> st = SurfaceTexture_getSurfaceTexture(_env, sur); + window = new SurfaceTextureClient(st); + } + + rsAllocationSetSurface(con, alloc, window.get()); +} + +static void +nAllocationIoSend(JNIEnv *_env, jobject _this, RsContext con, RsAllocation alloc) +{ + LOG_API("nAllocationIoSend, con(%p), alloc(%p)", con, alloc); + rsAllocationIoSend(con, alloc); +} + +static void +nAllocationIoReceive(JNIEnv *_env, jobject _this, RsContext con, RsAllocation alloc) +{ + LOG_API("nAllocationIoReceive, con(%p), alloc(%p)", con, alloc); + rsAllocationIoReceive(con, alloc); +} + + +static void nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, RsContext con, jint alloc) { LOG_API("nAllocationGenerateMipmaps, con(%p), a(%p)", con, (RsAllocation)alloc); @@ -1277,6 +1308,9 @@ static JNINativeMethod methods[] = { {"rsnAllocationSyncAll", "(III)V", (void*)nAllocationSyncAll }, {"rsnAllocationGetSurfaceTextureID", "(II)I", (void*)nAllocationGetSurfaceTextureID }, +{"rsnAllocationSetSurfaceTexture", "(IILandroid/graphics/SurfaceTexture;)V", (void*)nAllocationSetSurfaceTexture }, +{"rsnAllocationIoSend", "(II)V", (void*)nAllocationIoSend }, +{"rsnAllocationIoReceive", "(II)V", (void*)nAllocationIoReceive }, {"rsnAllocationData1D", "(IIIII[II)V", (void*)nAllocationData1D_i }, {"rsnAllocationData1D", "(IIIII[SI)V", (void*)nAllocationData1D_s }, {"rsnAllocationData1D", "(IIIII[BI)V", (void*)nAllocationData1D_b }, |