summaryrefslogtreecommitdiff
path: root/rs/jni/android_renderscript_RenderScript.cpp
diff options
context:
space:
mode:
authorMiao Wang <miaowang@google.com>2015-11-25 11:21:13 -0800
committerMiao Wang <miaowang@google.com>2016-01-25 16:12:37 -0800
commit0facf021ea1a0399d956372b9d3ad9025a9a04d2 (patch)
tree158e05cbc7e58d435a2b242503b4cf5430cc55eb /rs/jni/android_renderscript_RenderScript.cpp
parent9e892f53dd489c824b6a39c45028f838123daa85 (diff)
[RenderScript] Add API to map Allocation mallocptr to Java ByteBuffer
Bug: 25926361 Bug: 23535524 - Construct the ByteBuffer using the AllocationGetPointer. - Add an API to query the stride of the allocation. - Both ByteBuffer and Stride will be cached for normal Allocations. if using USAGE_IO, since after each ioReceive, the mallocPtr will change, getByteBuffer will always create a new one using the most up-to-date mallocPtr. Change-Id: I5e84b6690e83bb062c383043275524d0e51e46eb
Diffstat (limited to 'rs/jni/android_renderscript_RenderScript.cpp')
-rw-r--r--rs/jni/android_renderscript_RenderScript.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/rs/jni/android_renderscript_RenderScript.cpp b/rs/jni/android_renderscript_RenderScript.cpp
index 113241da4572..5b7cf7d04c60 100644
--- a/rs/jni/android_renderscript_RenderScript.cpp
+++ b/rs/jni/android_renderscript_RenderScript.cpp
@@ -2658,7 +2658,43 @@ nSystemGetPointerSize(JNIEnv *_env, jobject _this) {
return (jint)sizeof(void*);
}
+static jobject
+nAllocationGetByteBuffer(JNIEnv *_env, jobject _this, jlong con, jlong alloc,
+ jlongArray strideArr, jint xBytesSize,
+ jint dimY, jint dimZ) {
+ if (kLogApi) {
+ ALOGD("nAllocationGetByteBuffer, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
+ }
+
+ jlong *jStridePtr = _env->GetLongArrayElements(strideArr, nullptr);
+ if (jStridePtr == nullptr) {
+ ALOGE("Failed to get Java array elements: strideArr");
+ return 0;
+ }
+ size_t strideIn = xBytesSize;
+ void* ptr = nullptr;
+ if (alloc != 0) {
+ ptr = rsAllocationGetPointer((RsContext)con, (RsAllocation)alloc, 0,
+ RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X, 0, 0,
+ &strideIn, sizeof(size_t));
+ }
+
+ jobject byteBuffer = nullptr;
+ if (ptr != nullptr) {
+ size_t bufferSize = strideIn;
+ jStridePtr[0] = strideIn;
+ if (dimY > 0) {
+ bufferSize *= dimY;
+ }
+ if (dimZ > 0) {
+ bufferSize *= dimZ;
+ }
+ byteBuffer = _env->NewDirectByteBuffer(ptr, (jlong) bufferSize);
+ }
+ _env->ReleaseLongArrayElements(strideArr, jStridePtr, 0);
+ return byteBuffer;
+}
// ---------------------------------------------------------------------------
@@ -2814,6 +2850,7 @@ static const JNINativeMethod methods[] = {
{"rsnMeshGetIndices", "(JJ[J[II)V", (void*)nMeshGetIndices },
{"rsnSystemGetPointerSize", "()I", (void*)nSystemGetPointerSize },
+{"rsnAllocationGetByteBuffer", "(JJ[JIII)Ljava/nio/ByteBuffer;", (void*)nAllocationGetByteBuffer },
};
static int registerFuncs(JNIEnv *_env)