diff options
| -rw-r--r-- | graphics/java/android/renderscript/Allocation.java | 64 | ||||
| -rw-r--r-- | graphics/java/android/renderscript/RenderScript.java | 6 | ||||
| -rw-r--r-- | graphics/jni/android_renderscript_RenderScript.cpp | 8 | ||||
| -rw-r--r-- | libs/rs/RenderScriptDefines.h | 5 | ||||
| -rw-r--r-- | libs/rs/driver/rsdAllocation.cpp | 13 | ||||
| -rw-r--r-- | libs/rs/driver/rsdAllocation.h | 2 | ||||
| -rw-r--r-- | libs/rs/driver/rsdCore.cpp | 1 | ||||
| -rw-r--r-- | libs/rs/driver/rsdShader.cpp | 7 | ||||
| -rw-r--r-- | libs/rs/driver/rsdShaderCache.h | 6 | ||||
| -rw-r--r-- | libs/rs/rs.spec | 5 | ||||
| -rw-r--r-- | libs/rs/rsAllocation.cpp | 11 | ||||
| -rw-r--r-- | libs/rs/rsAllocation.h | 3 | ||||
| -rw-r--r-- | libs/rs/rs_hal.h | 1 |
13 files changed, 128 insertions, 4 deletions
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java index 11c242759d91..509b9726e326 100644 --- a/graphics/java/android/renderscript/Allocation.java +++ b/graphics/java/android/renderscript/Allocation.java @@ -22,6 +22,7 @@ import android.content.res.Resources; import android.content.res.AssetManager; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.graphics.SurfaceTexture; import android.util.Log; import android.util.TypedValue; @@ -78,6 +79,8 @@ public class Allocation extends BaseObj { boolean mConstrainedFace; boolean mConstrainedY; boolean mConstrainedZ; + boolean mReadAllowed = true; + boolean mWriteAllowed = true; int mSelectedY; int mSelectedZ; int mSelectedLOD; @@ -127,6 +130,32 @@ public class Allocation extends BaseObj { */ public static final int USAGE_GRAPHICS_RENDER_TARGET = 0x0010; + /** + * USAGE_GRAPHICS_SURFACE_TEXTURE_INPUT The allcation will be + * used with a SurfaceTexture object. This usage will cause the + * allocation to be created read only. + * + * @hide + */ + public static final int USAGE_GRAPHICS_SURFACE_TEXTURE_INPUT_OPAQUE = 0x0020; + + /** + * USAGE_GRAPHICS_SURFACE_TEXTURE_INPUT The allcation will be + * used with a SurfaceTexture object. This usage will cause the + * allocation to be created read only. + * + * @hide + */ + + public static final int USAGE_IO_INPUT = 0x0040; + /** + * USAGE_GRAPHICS_SURFACE_TEXTURE_INPUT The allcation will be + * used with a SurfaceTexture object. This usage will cause the + * allocation to be created read only. + * + * @hide + */ + public static final int USAGE_IO_OUTPUT = 0x0080; /** * Controls mipmap behavior when using the bitmap creation and @@ -187,10 +216,26 @@ public class Allocation extends BaseObj { USAGE_GRAPHICS_TEXTURE | USAGE_GRAPHICS_VERTEX | USAGE_GRAPHICS_CONSTANTS | - USAGE_GRAPHICS_RENDER_TARGET)) != 0) { + USAGE_GRAPHICS_RENDER_TARGET | + USAGE_GRAPHICS_SURFACE_TEXTURE_INPUT_OPAQUE | + USAGE_IO_INPUT | + USAGE_IO_OUTPUT)) != 0) { throw new RSIllegalArgumentException("Unknown usage specified."); } + + if ((usage & (USAGE_GRAPHICS_SURFACE_TEXTURE_INPUT_OPAQUE | USAGE_IO_INPUT)) != 0) { + mWriteAllowed = false; + + if ((usage & ~(USAGE_GRAPHICS_SURFACE_TEXTURE_INPUT_OPAQUE | + USAGE_IO_INPUT | + USAGE_GRAPHICS_TEXTURE | + USAGE_SCRIPT)) != 0) { + throw new RSIllegalArgumentException("Invalid usage combination."); + } + } + mType = t; + mUsage = usage; if (t != null) { updateCacheInfo(t); @@ -1006,6 +1051,23 @@ public class Allocation extends BaseObj { } /** + * + * + * @hide + * + */ + public SurfaceTexture getSurfaceTexture() { + if ((mUsage & USAGE_GRAPHICS_SURFACE_TEXTURE_INPUT_OPAQUE) == 0) { + throw new RSInvalidStateException("Allocation is not a surface texture."); + } + + int id = mRS.nAllocationGetSurfaceTextureID(getID()); + return new SurfaceTexture(id); + + } + + + /** * Creates a non-mipmapped renderscript allocation to use as a * graphics texture * diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java index bfe412c72185..3f3033b44a0f 100644 --- a/graphics/java/android/renderscript/RenderScript.java +++ b/graphics/java/android/renderscript/RenderScript.java @@ -269,6 +269,12 @@ public class RenderScript { validate(); rsnAllocationSyncAll(mContext, alloc, src); } + native int rsnAllocationGetSurfaceTextureID(int con, int alloc); + synchronized int nAllocationGetSurfaceTextureID(int alloc) { + validate(); + return rsnAllocationGetSurfaceTextureID(mContext, alloc); + } + native void rsnAllocationGenerateMipmaps(int con, int alloc); synchronized void nAllocationGenerateMipmaps(int alloc) { validate(); diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp index 9622bd244f89..a9f0f1fa1f5a 100644 --- a/graphics/jni/android_renderscript_RenderScript.cpp +++ b/graphics/jni/android_renderscript_RenderScript.cpp @@ -443,6 +443,13 @@ nAllocationSyncAll(JNIEnv *_env, jobject _this, RsContext con, jint a, jint bits rsAllocationSyncAll(con, (RsAllocation)a, (RsAllocationUsageType)bits); } +static jint +nAllocationGetSurfaceTextureID(JNIEnv *_env, jobject _this, RsContext con, jint a) +{ + LOG_API("nAllocationGetSurfaceTextureID, con(%p), a(%p)", con, (RsAllocation)a); + return rsAllocationGetSurfaceTextureID(con, (RsAllocation)a); +} + static void nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, RsContext con, jint alloc) { @@ -1258,6 +1265,7 @@ static JNINativeMethod methods[] = { {"rsnAllocationCopyToBitmap", "(IILandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap }, {"rsnAllocationSyncAll", "(III)V", (void*)nAllocationSyncAll }, +{"rsnAllocationGetSurfaceTextureID", "(II)I", (void*)nAllocationGetSurfaceTextureID }, {"rsnAllocationData1D", "(IIIII[II)V", (void*)nAllocationData1D_i }, {"rsnAllocationData1D", "(IIIII[SI)V", (void*)nAllocationData1D_s }, {"rsnAllocationData1D", "(IIIII[BI)V", (void*)nAllocationData1D_b }, diff --git a/libs/rs/RenderScriptDefines.h b/libs/rs/RenderScriptDefines.h index d092520feb81..5b0a3daaf045 100644 --- a/libs/rs/RenderScriptDefines.h +++ b/libs/rs/RenderScriptDefines.h @@ -99,8 +99,11 @@ enum RsAllocationUsageType { RS_ALLOCATION_USAGE_GRAPHICS_VERTEX = 0x0004, RS_ALLOCATION_USAGE_GRAPHICS_CONSTANTS = 0x0008, RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET = 0x0010, + RS_ALLOCATION_USAGE_GRAPHICS_SURFACE_TEXTURE_INPUT_OPAQUE = 0x0020, + RS_ALLOCATION_USAGE_IO_INPUT = 0x0040, + RS_ALLOCATION_USAGE_IO_OUTPUT = 0x0080, - RS_ALLOCATION_USAGE_ALL = 0x000F + RS_ALLOCATION_USAGE_ALL = 0x00FF }; enum RsAllocationMipmapControl { diff --git a/libs/rs/driver/rsdAllocation.cpp b/libs/rs/driver/rsdAllocation.cpp index 1f70e660f720..fac40f2567cd 100644 --- a/libs/rs/driver/rsdAllocation.cpp +++ b/libs/rs/driver/rsdAllocation.cpp @@ -134,6 +134,13 @@ static void Upload2DTexture(const Context *rsc, const Allocation *alloc, bool is static void UploadToTexture(const Context *rsc, const Allocation *alloc) { DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv; + if (alloc->mHal.state.usageFlags & RS_ALLOCATION_USAGE_GRAPHICS_SURFACE_TEXTURE_INPUT_OPAQUE) { + if (!drv->textureID) { + RSD_CALL_GL(glGenTextures, 1, &drv->textureID); + } + return; + } + if (!drv->glType || !drv->glFormat) { return; } @@ -370,6 +377,12 @@ void rsdAllocationMarkDirty(const Context *rsc, const Allocation *alloc) { drv->uploadDeferred = true; } +int32_t rsdAllocationInitSurfaceTexture(const Context *rsc, const Allocation *alloc) { + DrvAllocation *drv = (DrvAllocation *)alloc->mHal.drv; + UploadToTexture(rsc, alloc); + return drv->textureID; +} + void rsdAllocationData1D(const Context *rsc, const Allocation *alloc, uint32_t xoff, uint32_t lod, uint32_t count, const void *data, uint32_t sizeBytes) { diff --git a/libs/rs/driver/rsdAllocation.h b/libs/rs/driver/rsdAllocation.h index 4fc4419f4420..230804b53ae8 100644 --- a/libs/rs/driver/rsdAllocation.h +++ b/libs/rs/driver/rsdAllocation.h @@ -67,6 +67,8 @@ void rsdAllocationSyncAll(const android::renderscript::Context *rsc, RsAllocationUsageType src); void rsdAllocationMarkDirty(const android::renderscript::Context *rsc, const android::renderscript::Allocation *alloc); +int32_t rsdAllocationInitSurfaceTexture(const android::renderscript::Context *rsc, + const android::renderscript::Allocation *alloc); void rsdAllocationData1D(const android::renderscript::Context *rsc, const android::renderscript::Allocation *alloc, diff --git a/libs/rs/driver/rsdCore.cpp b/libs/rs/driver/rsdCore.cpp index 1a535d0a97f1..998702785abb 100644 --- a/libs/rs/driver/rsdCore.cpp +++ b/libs/rs/driver/rsdCore.cpp @@ -72,6 +72,7 @@ static RsdHalFunctions FunctionTable = { rsdAllocationResize, rsdAllocationSyncAll, rsdAllocationMarkDirty, + rsdAllocationInitSurfaceTexture, rsdAllocationData1D, rsdAllocationData2D, rsdAllocationData3D, diff --git a/libs/rs/driver/rsdShader.cpp b/libs/rs/driver/rsdShader.cpp index c70193aead19..482f3b8bfc9a 100644 --- a/libs/rs/driver/rsdShader.cpp +++ b/libs/rs/driver/rsdShader.cpp @@ -143,7 +143,12 @@ void RsdShader::appendTextures() { char buf[256]; for (uint32_t ct=0; ct < mRSProgram->mHal.state.texturesCount; ct++) { if (mRSProgram->mHal.state.textureTargets[ct] == RS_TEXTURE_2D) { - snprintf(buf, sizeof(buf), "uniform sampler2D UNI_Tex%i;\n", ct); + Allocation *a = mRSProgram->mHal.state.textures[ct]; + if (a && a->mHal.state.surfaceTextureID) { + snprintf(buf, sizeof(buf), "uniform samplerExternalOES UNI_Tex%i;\n", ct); + } else { + snprintf(buf, sizeof(buf), "uniform sampler2D UNI_Tex%i;\n", ct); + } mTextureTargets[ct] = GL_TEXTURE_2D; } else { snprintf(buf, sizeof(buf), "uniform samplerCube UNI_Tex%i;\n", ct); diff --git a/libs/rs/driver/rsdShaderCache.h b/libs/rs/driver/rsdShaderCache.h index 17ee3e83769f..d64780bdde2c 100644 --- a/libs/rs/driver/rsdShaderCache.h +++ b/libs/rs/driver/rsdShaderCache.h @@ -108,6 +108,7 @@ protected: } if (numFragUnis) { fragUniforms = new UniformData[numFragUnis]; + fragUniformIsSTO = new bool[numFragUnis]; } } ~ProgramEntry() { @@ -123,6 +124,10 @@ protected: delete[] fragUniforms; fragUniforms = NULL; } + if (fragUniformIsSTO) { + delete[] fragUniformIsSTO; + fragUniformIsSTO = NULL; + } } uint32_t vtx; uint32_t frag; @@ -131,6 +136,7 @@ protected: AttrData *vtxAttrs; UniformData *vtxUniforms; UniformData *fragUniforms; + bool *fragUniformIsSTO; }; android::Vector<ProgramEntry*> mEntries; ProgramEntry *mCurrent; diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec index ffb119692efd..09a29863f30b 100644 --- a/libs/rs/rs.spec +++ b/libs/rs/rs.spec @@ -63,7 +63,10 @@ AllocationCubeCreateFromBitmap { ret RsAllocation } - +AllocationGetSurfaceTextureID { + param RsAllocation alloc + ret int32_t +} ContextFinish { sync diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp index fd85b077a493..5f45abff2b9c 100644 --- a/libs/rs/rsAllocation.cpp +++ b/libs/rs/rsAllocation.cpp @@ -413,6 +413,12 @@ void Allocation::resize2D(Context *rsc, uint32_t dimX, uint32_t dimY) { ALOGE("not implemented"); } +int32_t Allocation::getSurfaceTextureID(const Context *rsc) { + int32_t id = rsc->mHal.funcs.allocation.initSurfaceTexture(rsc, this); + mHal.state.surfaceTextureID = id; + return id; +} + ///////////////// // @@ -658,6 +664,11 @@ void rsi_AllocationCopy2DRange(Context *rsc, (RsAllocationCubemapFace)srcFace); } +int32_t rsi_AllocationGetSurfaceTextureID(Context *rsc, RsAllocation valloc) { + Allocation *alloc = static_cast<Allocation *>(valloc); + return alloc->getSurfaceTextureID(rsc); +} + } } diff --git a/libs/rs/rsAllocation.h b/libs/rs/rsAllocation.h index 20201ca793ea..a26d8355bc2f 100644 --- a/libs/rs/rsAllocation.h +++ b/libs/rs/rsAllocation.h @@ -55,6 +55,8 @@ public: bool hasMipmaps; bool hasFaces; bool hasReferences; + void * usrPtr; + int32_t surfaceTextureID; }; State state; @@ -123,6 +125,7 @@ public: return mHal.state.mipmapControl != RS_ALLOCATION_MIPMAP_NONE; } + int32_t getSurfaceTextureID(const Context *rsc); protected: Vector<const Program *> mToDirtyList; diff --git a/libs/rs/rs_hal.h b/libs/rs/rs_hal.h index b8d735147804..0afc94b99e9b 100644 --- a/libs/rs/rs_hal.h +++ b/libs/rs/rs_hal.h @@ -114,6 +114,7 @@ typedef struct { bool zeroNew); void (*syncAll)(const Context *rsc, const Allocation *alloc, RsAllocationUsageType src); void (*markDirty)(const Context *rsc, const Allocation *alloc); + int32_t (*initSurfaceTexture)(const Context *rsc, const Allocation *alloc); void (*data1D)(const Context *rsc, const Allocation *alloc, uint32_t xoff, uint32_t lod, uint32_t count, |