diff options
Diffstat (limited to 'rs/jni/android_renderscript_RenderScript.cpp')
-rw-r--r-- | rs/jni/android_renderscript_RenderScript.cpp | 1365 |
1 files changed, 1017 insertions, 348 deletions
diff --git a/rs/jni/android_renderscript_RenderScript.cpp b/rs/jni/android_renderscript_RenderScript.cpp index 5f5b65e6b5af..6f6729bbaae0 100644 --- a/rs/jni/android_renderscript_RenderScript.cpp +++ b/rs/jni/android_renderscript_RenderScript.cpp @@ -22,6 +22,7 @@ #include <unistd.h> #include <math.h> #include <utils/misc.h> +#include <inttypes.h> #include <SkBitmap.h> @@ -39,21 +40,25 @@ #include <rsEnv.h> #include <gui/Surface.h> #include <gui/GLConsumer.h> -#include <gui/Surface.h> #include <android_runtime/android_graphics_SurfaceTexture.h> //#define LOG_API ALOGE -#define LOG_API(...) +static constexpr bool kLogApi = false; using namespace android; +template <typename... T> +void UNUSED(T... t) {} + #define PER_ARRAY_TYPE(flag, fnc, readonly, ...) { \ jint len = 0; \ - void *ptr = NULL; \ + void *ptr = nullptr; \ + void *srcPtr = nullptr; \ size_t typeBytes = 0; \ jint relFlag = 0; \ if (readonly) { \ /* The on-release mode should only be JNI_ABORT for read-only accesses. */ \ + /* readonly = true, also indicates we are copying to the allocation . */ \ relFlag = JNI_ABORT; \ } \ switch(dataType) { \ @@ -61,14 +66,50 @@ using namespace android; len = _env->GetArrayLength((jfloatArray)data); \ ptr = _env->GetFloatArrayElements((jfloatArray)data, flag); \ typeBytes = 4; \ - fnc(__VA_ARGS__); \ + if (usePadding) { \ + srcPtr = ptr; \ + len = len / 3 * 4; \ + if (count == 0) { \ + count = len / 4; \ + } \ + ptr = malloc (len * typeBytes); \ + if (readonly) { \ + copyWithPadding(ptr, srcPtr, mSize, count); \ + fnc(__VA_ARGS__); \ + } else { \ + fnc(__VA_ARGS__); \ + copyWithUnPadding(srcPtr, ptr, mSize, count); \ + } \ + free(ptr); \ + ptr = srcPtr; \ + } else { \ + fnc(__VA_ARGS__); \ + } \ _env->ReleaseFloatArrayElements((jfloatArray)data, (jfloat *)ptr, relFlag); \ return; \ case RS_TYPE_FLOAT_64: \ len = _env->GetArrayLength((jdoubleArray)data); \ ptr = _env->GetDoubleArrayElements((jdoubleArray)data, flag); \ typeBytes = 8; \ - fnc(__VA_ARGS__); \ + if (usePadding) { \ + srcPtr = ptr; \ + len = len / 3 * 4; \ + if (count == 0) { \ + count = len / 4; \ + } \ + ptr = malloc (len * typeBytes); \ + if (readonly) { \ + copyWithPadding(ptr, srcPtr, mSize, count); \ + fnc(__VA_ARGS__); \ + } else { \ + fnc(__VA_ARGS__); \ + copyWithUnPadding(srcPtr, ptr, mSize, count); \ + } \ + free(ptr); \ + ptr = srcPtr; \ + } else { \ + fnc(__VA_ARGS__); \ + } \ _env->ReleaseDoubleArrayElements((jdoubleArray)data, (jdouble *)ptr, relFlag); \ return; \ case RS_TYPE_SIGNED_8: \ @@ -76,7 +117,25 @@ using namespace android; len = _env->GetArrayLength((jbyteArray)data); \ ptr = _env->GetByteArrayElements((jbyteArray)data, flag); \ typeBytes = 1; \ - fnc(__VA_ARGS__); \ + if (usePadding) { \ + srcPtr = ptr; \ + len = len / 3 * 4; \ + if (count == 0) { \ + count = len / 4; \ + } \ + ptr = malloc (len * typeBytes); \ + if (readonly) { \ + copyWithPadding(ptr, srcPtr, mSize, count); \ + fnc(__VA_ARGS__); \ + } else { \ + fnc(__VA_ARGS__); \ + copyWithUnPadding(srcPtr, ptr, mSize, count); \ + } \ + free(ptr); \ + ptr = srcPtr; \ + } else { \ + fnc(__VA_ARGS__); \ + } \ _env->ReleaseByteArrayElements((jbyteArray)data, (jbyte*)ptr, relFlag); \ return; \ case RS_TYPE_SIGNED_16: \ @@ -84,7 +143,25 @@ using namespace android; len = _env->GetArrayLength((jshortArray)data); \ ptr = _env->GetShortArrayElements((jshortArray)data, flag); \ typeBytes = 2; \ - fnc(__VA_ARGS__); \ + if (usePadding) { \ + srcPtr = ptr; \ + len = len / 3 * 4; \ + if (count == 0) { \ + count = len / 4; \ + } \ + ptr = malloc (len * typeBytes); \ + if (readonly) { \ + copyWithPadding(ptr, srcPtr, mSize, count); \ + fnc(__VA_ARGS__); \ + } else { \ + fnc(__VA_ARGS__); \ + copyWithUnPadding(srcPtr, ptr, mSize, count); \ + } \ + free(ptr); \ + ptr = srcPtr; \ + } else { \ + fnc(__VA_ARGS__); \ + } \ _env->ReleaseShortArrayElements((jshortArray)data, (jshort *)ptr, relFlag); \ return; \ case RS_TYPE_SIGNED_32: \ @@ -92,7 +169,25 @@ using namespace android; len = _env->GetArrayLength((jintArray)data); \ ptr = _env->GetIntArrayElements((jintArray)data, flag); \ typeBytes = 4; \ - fnc(__VA_ARGS__); \ + if (usePadding) { \ + srcPtr = ptr; \ + len = len / 3 * 4; \ + if (count == 0) { \ + count = len / 4; \ + } \ + ptr = malloc (len * typeBytes); \ + if (readonly) { \ + copyWithPadding(ptr, srcPtr, mSize, count); \ + fnc(__VA_ARGS__); \ + } else { \ + fnc(__VA_ARGS__); \ + copyWithUnPadding(srcPtr, ptr, mSize, count); \ + } \ + free(ptr); \ + ptr = srcPtr; \ + } else { \ + fnc(__VA_ARGS__); \ + } \ _env->ReleaseIntArrayElements((jintArray)data, (jint *)ptr, relFlag); \ return; \ case RS_TYPE_SIGNED_64: \ @@ -100,19 +195,38 @@ using namespace android; len = _env->GetArrayLength((jlongArray)data); \ ptr = _env->GetLongArrayElements((jlongArray)data, flag); \ typeBytes = 8; \ - fnc(__VA_ARGS__); \ + if (usePadding) { \ + srcPtr = ptr; \ + len = len / 3 * 4; \ + if (count == 0) { \ + count = len / 4; \ + } \ + ptr = malloc (len * typeBytes); \ + if (readonly) { \ + copyWithPadding(ptr, srcPtr, mSize, count); \ + fnc(__VA_ARGS__); \ + } else { \ + fnc(__VA_ARGS__); \ + copyWithUnPadding(srcPtr, ptr, mSize, count); \ + } \ + free(ptr); \ + ptr = srcPtr; \ + } else { \ + fnc(__VA_ARGS__); \ + } \ _env->ReleaseLongArrayElements((jlongArray)data, (jlong *)ptr, relFlag); \ return; \ default: \ break; \ } \ + UNUSED(len, ptr, srcPtr, typeBytes, relFlag); \ } class AutoJavaStringToUTF8 { public: AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) { - fCStr = env->GetStringUTFChars(str, NULL); + fCStr = env->GetStringUTFChars(str, nullptr); fLength = env->GetStringUTFLength(str); } ~AutoJavaStringToUTF8() { @@ -132,14 +246,14 @@ class AutoJavaStringArrayToUTF8 { public: AutoJavaStringArrayToUTF8(JNIEnv* env, jobjectArray strings, jsize stringsLength) : mEnv(env), mStrings(strings), mStringsLength(stringsLength) { - mCStrings = NULL; - mSizeArray = NULL; + mCStrings = nullptr; + mSizeArray = nullptr; if (stringsLength > 0) { mCStrings = (const char **)calloc(stringsLength, sizeof(char *)); mSizeArray = (size_t*)calloc(stringsLength, sizeof(size_t)); for (jsize ct = 0; ct < stringsLength; ct ++) { jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct); - mCStrings[ct] = mEnv->GetStringUTFChars(s, NULL); + mCStrings[ct] = mEnv->GetStringUTFChars(s, nullptr); mSizeArray[ct] = mEnv->GetStringUTFLength(s); } } @@ -168,7 +282,6 @@ private: static jfieldID gContextId = 0; static jfieldID gNativeBitmapID = 0; -static jfieldID gTypeNativeCache = 0; static void _nInit(JNIEnv *_env, jclass _this) { @@ -180,17 +293,328 @@ static void _nInit(JNIEnv *_env, jclass _this) // --------------------------------------------------------------------------- +static void copyWithPadding(void* ptr, void* srcPtr, int mSize, int count) { + int sizeBytesPad = mSize * 4; + int sizeBytes = mSize * 3; + uint8_t *dst = static_cast<uint8_t *>(ptr); + uint8_t *src = static_cast<uint8_t *>(srcPtr); + for (int i = 0; i < count; i++) { + memcpy(dst, src, sizeBytes); + dst += sizeBytesPad; + src += sizeBytes; + } +} + +static void copyWithUnPadding(void* ptr, void* srcPtr, int mSize, int count) { + int sizeBytesPad = mSize * 4; + int sizeBytes = mSize * 3; + uint8_t *dst = static_cast<uint8_t *>(ptr); + uint8_t *src = static_cast<uint8_t *>(srcPtr); + for (int i = 0; i < count; i++) { + memcpy(dst, src, sizeBytes); + dst += sizeBytes; + src += sizeBytesPad; + } +} + + +// --------------------------------------------------------------------------- static void nContextFinish(JNIEnv *_env, jobject _this, jlong con) { - LOG_API("nContextFinish, con(%p)", (RsContext)con); + if (kLogApi) { + ALOGD("nContextFinish, con(%p)", (RsContext)con); + } rsContextFinish((RsContext)con); } +static jlong +nClosureCreate(JNIEnv *_env, jobject _this, jlong con, jlong kernelID, + jlong returnValue, jlongArray fieldIDArray, + jlongArray valueArray, jintArray sizeArray, + jlongArray depClosureArray, jlongArray depFieldIDArray) { + jlong* jFieldIDs = _env->GetLongArrayElements(fieldIDArray, nullptr); + jsize fieldIDs_length = _env->GetArrayLength(fieldIDArray); + RsScriptFieldID* fieldIDs = + (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * fieldIDs_length); + for (int i = 0; i< fieldIDs_length; i++) { + fieldIDs[i] = (RsScriptFieldID)jFieldIDs[i]; + } + + jlong* jValues = _env->GetLongArrayElements(valueArray, nullptr); + jsize values_length = _env->GetArrayLength(valueArray); + uintptr_t* values = (uintptr_t*)alloca(sizeof(uintptr_t) * values_length); + for (int i = 0; i < values_length; i++) { + values[i] = (uintptr_t)jValues[i]; + } + + jint* sizes = _env->GetIntArrayElements(sizeArray, nullptr); + jsize sizes_length = _env->GetArrayLength(sizeArray); + + jlong* jDepClosures = + _env->GetLongArrayElements(depClosureArray, nullptr); + jsize depClosures_length = _env->GetArrayLength(depClosureArray); + RsClosure* depClosures = + (RsClosure*)alloca(sizeof(RsClosure) * depClosures_length); + for (int i = 0; i < depClosures_length; i++) { + depClosures[i] = (RsClosure)jDepClosures[i]; + } + + jlong* jDepFieldIDs = + _env->GetLongArrayElements(depFieldIDArray, nullptr); + jsize depFieldIDs_length = _env->GetArrayLength(depFieldIDArray); + RsScriptFieldID* depFieldIDs = + (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * depFieldIDs_length); + for (int i = 0; i < depClosures_length; i++) { + depFieldIDs[i] = (RsClosure)jDepFieldIDs[i]; + } + + return (jlong)(uintptr_t)rsClosureCreate( + (RsContext)con, (RsScriptKernelID)kernelID, (RsAllocation)returnValue, + fieldIDs, (size_t)fieldIDs_length, values, (size_t)values_length, + (int*)sizes, (size_t)sizes_length, + depClosures, (size_t)depClosures_length, + depFieldIDs, (size_t)depFieldIDs_length); +} + +static jlong +nInvokeClosureCreate(JNIEnv *_env, jobject _this, jlong con, jlong invokeID, + jbyteArray paramArray, jlongArray fieldIDArray, jlongArray valueArray, + jintArray sizeArray) { + jbyte* jParams = _env->GetByteArrayElements(paramArray, nullptr); + jsize jParamLength = _env->GetArrayLength(paramArray); + + jlong* jFieldIDs = _env->GetLongArrayElements(fieldIDArray, nullptr); + jsize fieldIDs_length = _env->GetArrayLength(fieldIDArray); + RsScriptFieldID* fieldIDs = + (RsScriptFieldID*)alloca(sizeof(RsScriptFieldID) * fieldIDs_length); + for (int i = 0; i< fieldIDs_length; i++) { + fieldIDs[i] = (RsScriptFieldID)jFieldIDs[i]; + } + + jlong* jValues = _env->GetLongArrayElements(valueArray, nullptr); + jsize values_length = _env->GetArrayLength(valueArray); + uintptr_t* values = (uintptr_t*)alloca(sizeof(uintptr_t) * values_length); + for (int i = 0; i < values_length; i++) { + values[i] = (uintptr_t)jValues[i]; + } + + jint* sizes = _env->GetIntArrayElements(sizeArray, nullptr); + jsize sizes_length = _env->GetArrayLength(sizeArray); + + return (jlong)(uintptr_t)rsInvokeClosureCreate( + (RsContext)con, (RsScriptInvokeID)invokeID, jParams, jParamLength, + fieldIDs, (size_t)fieldIDs_length, values, (size_t)values_length, + (int*)sizes, (size_t)sizes_length); +} + +static void +nClosureSetArg(JNIEnv *_env, jobject _this, jlong con, jlong closureID, + jint index, jlong value, jint size) { + rsClosureSetArg((RsContext)con, (RsClosure)closureID, (uint32_t)index, + (uintptr_t)value, (size_t)size); +} + +static void +nClosureSetGlobal(JNIEnv *_env, jobject _this, jlong con, jlong closureID, + jlong fieldID, jlong value, jint size) { + rsClosureSetGlobal((RsContext)con, (RsClosure)closureID, + (RsScriptFieldID)fieldID, (uintptr_t)value, (size_t)size); +} + +static long +nScriptGroup2Create(JNIEnv *_env, jobject _this, jlong con, jstring name, + jstring cacheDir, jlongArray closureArray) { + AutoJavaStringToUTF8 nameUTF(_env, name); + AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir); + + jlong* jClosures = _env->GetLongArrayElements(closureArray, nullptr); + jsize numClosures = _env->GetArrayLength(closureArray); + RsClosure* closures = (RsClosure*)alloca(sizeof(RsClosure) * numClosures); + for (int i = 0; i < numClosures; i++) { + closures[i] = (RsClosure)jClosures[i]; + } + + return (jlong)(uintptr_t)rsScriptGroup2Create( + (RsContext)con, nameUTF.c_str(), nameUTF.length(), + cacheDirUTF.c_str(), cacheDirUTF.length(), + closures, numClosures); +} + +static void +nScriptGroup2Execute(JNIEnv *_env, jobject _this, jlong con, jlong groupID) { + rsScriptGroupExecute((RsContext)con, (RsScriptGroup2)groupID); +} + +static void +nScriptIntrinsicBLAS_Single(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA, + jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K, + jfloat alpha, jlong A, jlong B, jfloat beta, jlong C, jint incX, jint incY, + jint KL, jint KU) { + RsBlasCall call; + memset(&call, 0, sizeof(call)); + call.func = (RsBlasFunction)func; + call.transA = (RsBlasTranspose)TransA; + call.transB = (RsBlasTranspose)TransB; + call.side = (RsBlasSide)Side; + call.uplo = (RsBlasUplo)Uplo; + call.diag = (RsBlasDiag)Diag; + call.M = M; + call.N = N; + call.K = K; + call.alpha.f = alpha; + call.beta.f = beta; + call.incX = incX; + call.incY = incY; + call.KL = KL; + call.KU = KU; + + RsAllocation in_allocs[3]; + in_allocs[0] = (RsAllocation)A; + in_allocs[1] = (RsAllocation)B; + in_allocs[2] = (RsAllocation)C; + + rsScriptForEachMulti((RsContext)con, (RsScript)id, 0, + in_allocs, sizeof(in_allocs), nullptr, + &call, sizeof(call), nullptr, 0); +} + +static void +nScriptIntrinsicBLAS_Double(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA, + jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K, + jdouble alpha, jlong A, jlong B, jdouble beta, jlong C, jint incX, jint incY, + jint KL, jint KU) { + RsBlasCall call; + memset(&call, 0, sizeof(call)); + call.func = (RsBlasFunction)func; + call.transA = (RsBlasTranspose)TransA; + call.transB = (RsBlasTranspose)TransB; + call.side = (RsBlasSide)Side; + call.uplo = (RsBlasUplo)Uplo; + call.diag = (RsBlasDiag)Diag; + call.M = M; + call.N = N; + call.K = K; + call.alpha.d = alpha; + call.beta.d = beta; + call.incX = incX; + call.incY = incY; + call.KL = KL; + call.KU = KU; + + RsAllocation in_allocs[3]; + in_allocs[0] = (RsAllocation)A; + in_allocs[1] = (RsAllocation)B; + in_allocs[2] = (RsAllocation)C; + + rsScriptForEachMulti((RsContext)con, (RsScript)id, 0, + in_allocs, sizeof(in_allocs), nullptr, + &call, sizeof(call), nullptr, 0); +} + +static void +nScriptIntrinsicBLAS_Complex(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA, + jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K, + jfloat alphaX, jfloat alphaY, jlong A, jlong B, jfloat betaX, + jfloat betaY, jlong C, jint incX, jint incY, jint KL, jint KU) { + RsBlasCall call; + memset(&call, 0, sizeof(call)); + call.func = (RsBlasFunction)func; + call.transA = (RsBlasTranspose)TransA; + call.transB = (RsBlasTranspose)TransB; + call.side = (RsBlasSide)Side; + call.uplo = (RsBlasUplo)Uplo; + call.diag = (RsBlasDiag)Diag; + call.M = M; + call.N = N; + call.K = K; + call.alpha.c.r = alphaX; + call.alpha.c.i = alphaY; + call.beta.c.r = betaX; + call.beta.c.r = betaY; + call.incX = incX; + call.incY = incY; + call.KL = KL; + call.KU = KU; + + RsAllocation in_allocs[3]; + in_allocs[0] = (RsAllocation)A; + in_allocs[1] = (RsAllocation)B; + in_allocs[2] = (RsAllocation)C; + + rsScriptForEachMulti((RsContext)con, (RsScript)id, 0, + in_allocs, sizeof(in_allocs), nullptr, + &call, sizeof(call), nullptr, 0); +} + +static void +nScriptIntrinsicBLAS_Z(JNIEnv *_env, jobject _this, jlong con, jlong id, jint func, jint TransA, + jint TransB, jint Side, jint Uplo, jint Diag, jint M, jint N, jint K, + jdouble alphaX, jdouble alphaY, jlong A, jlong B, jdouble betaX, + jdouble betaY, jlong C, jint incX, jint incY, jint KL, jint KU) { + RsBlasCall call; + memset(&call, 0, sizeof(call)); + call.func = (RsBlasFunction)func; + call.transA = (RsBlasTranspose)TransA; + call.transB = (RsBlasTranspose)TransB; + call.side = (RsBlasSide)Side; + call.uplo = (RsBlasUplo)Uplo; + call.diag = (RsBlasDiag)Diag; + call.M = M; + call.N = N; + call.K = K; + call.alpha.z.r = alphaX; + call.alpha.z.i = alphaY; + call.beta.z.r = betaX; + call.beta.z.r = betaY; + call.incX = incX; + call.incY = incY; + call.KL = KL; + call.KU = KU; + + RsAllocation in_allocs[3]; + in_allocs[0] = (RsAllocation)A; + in_allocs[1] = (RsAllocation)B; + in_allocs[2] = (RsAllocation)C; + + rsScriptForEachMulti((RsContext)con, (RsScript)id, 0, + in_allocs, sizeof(in_allocs), nullptr, + &call, sizeof(call), nullptr, 0); +} + + +static void +nScriptIntrinsicBLAS_BNNM(JNIEnv *_env, jobject _this, jlong con, jlong id, jint M, jint N, jint K, + jlong A, jint a_offset, jlong B, jint b_offset, jlong C, jint c_offset, + jint c_mult_int) { + RsBlasCall call; + memset(&call, 0, sizeof(call)); + call.func = RsBlas_bnnm; + call.M = M; + call.N = N; + call.K = K; + call.a_offset = a_offset; + call.b_offset = b_offset; + call.c_offset = c_offset; + call.c_mult_int = c_mult_int; + + RsAllocation in_allocs[3]; + in_allocs[0] = (RsAllocation)A; + in_allocs[1] = (RsAllocation)B; + in_allocs[2] = (RsAllocation)C; + + rsScriptForEachMulti((RsContext)con, (RsScript)id, 0, + in_allocs, sizeof(in_allocs), nullptr, + &call, sizeof(call), nullptr, 0); +} + + static void nAssignName(JNIEnv *_env, jobject _this, jlong con, jlong obj, jbyteArray str) { - LOG_API("nAssignName, con(%p), obj(%p)", (RsContext)con, (void *)obj); + if (kLogApi) { + ALOGD("nAssignName, con(%p), obj(%p)", (RsContext)con, (void *)obj); + } jint len = _env->GetArrayLength(str); jbyte * cptr = (jbyte *) _env->GetPrimitiveArrayCritical(str, 0); rsAssignName((RsContext)con, (void *)obj, (const char *)cptr, len); @@ -200,11 +624,13 @@ nAssignName(JNIEnv *_env, jobject _this, jlong con, jlong obj, jbyteArray str) static jstring nGetName(JNIEnv *_env, jobject _this, jlong con, jlong obj) { - LOG_API("nGetName, con(%p), obj(%p)", (RsContext)con, (void *)obj); - const char *name = NULL; + if (kLogApi) { + ALOGD("nGetName, con(%p), obj(%p)", (RsContext)con, (void *)obj); + } + const char *name = nullptr; rsaGetName((RsContext)con, (void *)obj, &name); - if(name == NULL || strlen(name) == 0) { - return NULL; + if(name == nullptr || strlen(name) == 0) { + return nullptr; } return _env->NewStringUTF(name); } @@ -212,7 +638,9 @@ nGetName(JNIEnv *_env, jobject _this, jlong con, jlong obj) static void nObjDestroy(JNIEnv *_env, jobject _this, jlong con, jlong obj) { - LOG_API("nObjDestroy, con(%p) obj(%p)", (RsContext)con, (void *)obj); + if (kLogApi) { + ALOGD("nObjDestroy, con(%p) obj(%p)", (RsContext)con, (void *)obj); + } rsObjDestroy((RsContext)con, (void *)obj); } @@ -221,28 +649,36 @@ nObjDestroy(JNIEnv *_env, jobject _this, jlong con, jlong obj) static jlong nDeviceCreate(JNIEnv *_env, jobject _this) { - LOG_API("nDeviceCreate"); + if (kLogApi) { + ALOGD("nDeviceCreate"); + } return (jlong)(uintptr_t)rsDeviceCreate(); } static void nDeviceDestroy(JNIEnv *_env, jobject _this, jlong dev) { - LOG_API("nDeviceDestroy"); + if (kLogApi) { + ALOGD("nDeviceDestroy"); + } return rsDeviceDestroy((RsDevice)dev); } static void nDeviceSetConfig(JNIEnv *_env, jobject _this, jlong dev, jint p, jint value) { - LOG_API("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value); + if (kLogApi) { + ALOGD("nDeviceSetConfig dev(%p), param(%i), value(%i)", (void *)dev, p, value); + } return rsDeviceSetConfig((RsDevice)dev, (RsDeviceParam)p, value); } static jlong nContextCreate(JNIEnv *_env, jobject _this, jlong dev, jint flags, jint sdkVer, jint contextType) { - LOG_API("nContextCreate"); + if (kLogApi) { + ALOGD("nContextCreate"); + } return (jlong)(uintptr_t)rsContextCreate((RsDevice)dev, 0, sdkVer, (RsContextType)contextType, flags); } @@ -266,26 +702,44 @@ nContextCreateGL(JNIEnv *_env, jobject _this, jlong dev, jint ver, jint sdkVer, sc.samplesPref = samplesPref; sc.samplesQ = samplesQ; - LOG_API("nContextCreateGL"); + if (kLogApi) { + ALOGD("nContextCreateGL"); + } return (jlong)(uintptr_t)rsContextCreateGL((RsDevice)dev, ver, sdkVer, sc, dpi); } static void nContextSetPriority(JNIEnv *_env, jobject _this, jlong con, jint p) { - LOG_API("ContextSetPriority, con(%p), priority(%i)", (RsContext)con, p); + if (kLogApi) { + ALOGD("ContextSetPriority, con(%p), priority(%i)", (RsContext)con, p); + } rsContextSetPriority((RsContext)con, p); } +static void +nContextSetCacheDir(JNIEnv *_env, jobject _this, jlong con, jstring cacheDir) +{ + AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir); + + if (kLogApi) { + ALOGD("ContextSetCacheDir, con(%p), cacheDir(%s)", (RsContext)con, cacheDirUTF.c_str()); + } + rsContextSetCacheDir((RsContext)con, cacheDirUTF.c_str(), cacheDirUTF.length()); +} + static void nContextSetSurface(JNIEnv *_env, jobject _this, jlong con, jint width, jint height, jobject wnd) { - LOG_API("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", (RsContext)con, width, height, (Surface *)wnd); + if (kLogApi) { + ALOGD("nContextSetSurface, con(%p), width(%i), height(%i), surface(%p)", (RsContext)con, + width, height, (Surface *)wnd); + } - ANativeWindow * window = NULL; - if (wnd == NULL) { + ANativeWindow * window = nullptr; + if (wnd == nullptr) { } else { window = android_view_Surface_getNativeWindow(_env, wnd).get(); @@ -297,28 +751,36 @@ nContextSetSurface(JNIEnv *_env, jobject _this, jlong con, jint width, jint heig static void nContextDestroy(JNIEnv *_env, jobject _this, jlong con) { - LOG_API("nContextDestroy, con(%p)", (RsContext)con); + if (kLogApi) { + ALOGD("nContextDestroy, con(%p)", (RsContext)con); + } rsContextDestroy((RsContext)con); } static void nContextDump(JNIEnv *_env, jobject _this, jlong con, jint bits) { - LOG_API("nContextDump, con(%p) bits(%i)", (RsContext)con, bits); + if (kLogApi) { + ALOGD("nContextDump, con(%p) bits(%i)", (RsContext)con, bits); + } rsContextDump((RsContext)con, bits); } static void nContextPause(JNIEnv *_env, jobject _this, jlong con) { - LOG_API("nContextPause, con(%p)", (RsContext)con); + if (kLogApi) { + ALOGD("nContextPause, con(%p)", (RsContext)con); + } rsContextPause((RsContext)con); } static void nContextResume(JNIEnv *_env, jobject _this, jlong con) { - LOG_API("nContextResume, con(%p)", (RsContext)con); + if (kLogApi) { + ALOGD("nContextResume, con(%p)", (RsContext)con); + } rsContextResume((RsContext)con); } @@ -326,7 +788,9 @@ nContextResume(JNIEnv *_env, jobject _this, jlong con) static jstring nContextGetErrorMessage(JNIEnv *_env, jobject _this, jlong con) { - LOG_API("nContextGetErrorMessage, con(%p)", (RsContext)con); + if (kLogApi) { + ALOGD("nContextGetErrorMessage, con(%p)", (RsContext)con); + } char buf[1024]; size_t receiveLen; @@ -336,7 +800,7 @@ nContextGetErrorMessage(JNIEnv *_env, jobject _this, jlong con) &receiveLen, sizeof(receiveLen), &subID, sizeof(subID)); if (!id && receiveLen) { - ALOGV("message receive buffer too small. %i", receiveLen); + ALOGV("message receive buffer too small. %zu", receiveLen); } return _env->NewStringUTF(buf); } @@ -345,8 +809,10 @@ static jint nContextGetUserMessage(JNIEnv *_env, jobject _this, jlong con, jintArray data) { jint len = _env->GetArrayLength(data); - LOG_API("nContextGetMessage, con(%p), len(%i)", (RsContext)con, len); - jint *ptr = _env->GetIntArrayElements(data, NULL); + if (kLogApi) { + ALOGD("nContextGetMessage, con(%p), len(%i)", (RsContext)con, len); + } + jint *ptr = _env->GetIntArrayElements(data, nullptr); size_t receiveLen; uint32_t subID; int id = rsContextGetMessage((RsContext)con, @@ -354,7 +820,7 @@ nContextGetUserMessage(JNIEnv *_env, jobject _this, jlong con, jintArray data) &receiveLen, sizeof(receiveLen), &subID, sizeof(subID)); if (!id && receiveLen) { - ALOGV("message receive buffer too small. %i", receiveLen); + ALOGV("message receive buffer too small. %zu", receiveLen); } _env->ReleaseIntArrayElements(data, ptr, 0); return (jint)id; @@ -363,8 +829,10 @@ nContextGetUserMessage(JNIEnv *_env, jobject _this, jlong con, jintArray data) static jint nContextPeekMessage(JNIEnv *_env, jobject _this, jlong con, jintArray auxData) { - LOG_API("nContextPeekMessage, con(%p)", (RsContext)con); - jint *auxDataPtr = _env->GetIntArrayElements(auxData, NULL); + if (kLogApi) { + ALOGD("nContextPeekMessage, con(%p)", (RsContext)con); + } + jint *auxDataPtr = _env->GetIntArrayElements(auxData, nullptr); size_t receiveLen; uint32_t subID; int id = rsContextPeekMessage((RsContext)con, &receiveLen, sizeof(receiveLen), @@ -377,26 +845,32 @@ nContextPeekMessage(JNIEnv *_env, jobject _this, jlong con, jintArray auxData) static void nContextInitToClient(JNIEnv *_env, jobject _this, jlong con) { - LOG_API("nContextInitToClient, con(%p)", (RsContext)con); + if (kLogApi) { + ALOGD("nContextInitToClient, con(%p)", (RsContext)con); + } rsContextInitToClient((RsContext)con); } static void nContextDeinitToClient(JNIEnv *_env, jobject _this, jlong con) { - LOG_API("nContextDeinitToClient, con(%p)", (RsContext)con); + if (kLogApi) { + ALOGD("nContextDeinitToClient, con(%p)", (RsContext)con); + } rsContextDeinitToClient((RsContext)con); } static void nContextSendMessage(JNIEnv *_env, jobject _this, jlong con, jint id, jintArray data) { - jint *ptr = NULL; + jint *ptr = nullptr; jint len = 0; if (data) { len = _env->GetArrayLength(data); - ptr = _env->GetIntArrayElements(data, NULL); + ptr = _env->GetIntArrayElements(data, nullptr); + } + if (kLogApi) { + ALOGD("nContextSendMessage, con(%p), id(%i), len(%i)", (RsContext)con, id, len); } - LOG_API("nContextSendMessage, con(%p), id(%i), len(%i)", (RsContext)con, id, len); rsContextSendMessage((RsContext)con, id, (const uint8_t *)ptr, len * sizeof(int)); if (data) { _env->ReleaseIntArrayElements(data, ptr, JNI_ABORT); @@ -406,10 +880,15 @@ nContextSendMessage(JNIEnv *_env, jobject _this, jlong con, jint id, jintArray d static jlong -nElementCreate(JNIEnv *_env, jobject _this, jlong con, jlong type, jint kind, jboolean norm, jint size) +nElementCreate(JNIEnv *_env, jobject _this, jlong con, jlong type, jint kind, jboolean norm, + jint size) { - LOG_API("nElementCreate, con(%p), type(%i), kind(%i), norm(%i), size(%i)", (RsContext)con, type, kind, norm, size); - return (jlong)(uintptr_t)rsElementCreate((RsContext)con, (RsDataType)type, (RsDataKind)kind, norm, size); + if (kLogApi) { + ALOGD("nElementCreate, con(%p), type(%" PRId64 "), kind(%i), norm(%i), size(%i)", (RsContext)con, + type, kind, norm, size); + } + return (jlong)(uintptr_t)rsElementCreate((RsContext)con, (RsDataType)type, (RsDataKind)kind, + norm, size); } static jlong @@ -417,10 +896,12 @@ nElementCreate2(JNIEnv *_env, jobject _this, jlong con, jlongArray _ids, jobjectArray _names, jintArray _arraySizes) { int fieldCount = _env->GetArrayLength(_ids); - LOG_API("nElementCreate2, con(%p)", (RsContext)con); + if (kLogApi) { + ALOGD("nElementCreate2, con(%p)", (RsContext)con); + } - jlong *jIds = _env->GetLongArrayElements(_ids, NULL); - jint *jArraySizes = _env->GetIntArrayElements(_arraySizes, NULL); + jlong *jIds = _env->GetLongArrayElements(_ids, nullptr); + jint *jArraySizes = _env->GetIntArrayElements(_arraySizes, nullptr); RsElement *ids = (RsElement*)malloc(fieldCount * sizeof(RsElement)); uint32_t *arraySizes = (uint32_t *)malloc(fieldCount * sizeof(uint32_t)); @@ -452,7 +933,9 @@ static void nElementGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jintArray _elementData) { int dataSize = _env->GetArrayLength(_elementData); - LOG_API("nElementGetNativeData, con(%p)", (RsContext)con); + if (kLogApi) { + ALOGD("nElementGetNativeData, con(%p)", (RsContext)con); + } // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements assert(dataSize == 5); @@ -474,13 +957,16 @@ nElementGetSubElements(JNIEnv *_env, jobject _this, jlong con, jlong id, jintArray _arraySizes) { uint32_t dataSize = _env->GetArrayLength(_IDs); - LOG_API("nElementGetSubElements, con(%p)", (RsContext)con); + if (kLogApi) { + ALOGD("nElementGetSubElements, con(%p)", (RsContext)con); + } uintptr_t *ids = (uintptr_t*)malloc(dataSize * sizeof(uintptr_t)); const char **names = (const char **)malloc(dataSize * sizeof(const char *)); uint32_t *arraySizes = (uint32_t *)malloc(dataSize * sizeof(uint32_t)); - rsaElementGetSubElements((RsContext)con, (RsElement)id, ids, names, arraySizes, (uint32_t)dataSize); + rsaElementGetSubElements((RsContext)con, (RsElement)id, ids, names, arraySizes, + (uint32_t)dataSize); for(uint32_t i = 0; i < dataSize; i++) { const jlong id = (jlong)(uintptr_t)ids[i]; @@ -501,10 +987,13 @@ static jlong nTypeCreate(JNIEnv *_env, jobject _this, jlong con, jlong eid, jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces, jint yuv) { - LOG_API("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i), yuv(%i)", - (RsContext)con, eid, dimx, dimy, dimz, mips, faces, yuv); + if (kLogApi) { + ALOGD("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i), yuv(%i)", + (RsContext)con, (void*)eid, dimx, dimy, dimz, mips, faces, yuv); + } - return (jlong)(uintptr_t)rsTypeCreate((RsContext)con, (RsElement)eid, dimx, dimy, dimz, mips, faces, yuv); + return (jlong)(uintptr_t)rsTypeCreate((RsContext)con, (RsElement)eid, dimx, dimy, dimz, mips, + faces, yuv); } static void @@ -515,7 +1004,9 @@ nTypeGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jlongArray int elementCount = _env->GetArrayLength(_typeData); assert(elementCount == 6); - LOG_API("nTypeGetNativeData, con(%p)", (RsContext)con); + if (kLogApi) { + ALOGD("nTypeGetNativeData, con(%p)", (RsContext)con); + } uintptr_t typeData[6]; rsaTypeGetNativeData((RsContext)con, (RsType)id, typeData, 6); @@ -529,27 +1020,39 @@ nTypeGetNativeData(JNIEnv *_env, jobject _this, jlong con, jlong id, jlongArray // ----------------------------------- static jlong -nAllocationCreateTyped(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mips, jint usage, jlong pointer) +nAllocationCreateTyped(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mips, jint usage, + jlong pointer) { - LOG_API("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)", (RsContext)con, (RsElement)type, mips, usage, (void *)pointer); - return (jlong)(uintptr_t) rsAllocationCreateTyped((RsContext)con, (RsType)type, (RsAllocationMipmapControl)mips, (uint32_t)usage, (uintptr_t)pointer); + if (kLogApi) { + ALOGD("nAllocationCreateTyped, con(%p), type(%p), mip(%i), usage(%i), ptr(%p)", + (RsContext)con, (RsElement)type, mips, usage, (void *)pointer); + } + return (jlong)(uintptr_t) rsAllocationCreateTyped((RsContext)con, (RsType)type, + (RsAllocationMipmapControl)mips, + (uint32_t)usage, (uintptr_t)pointer); } static void nAllocationSyncAll(JNIEnv *_env, jobject _this, jlong con, jlong a, jint bits) { - LOG_API("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", (RsContext)con, (RsAllocation)a, bits); + if (kLogApi) { + ALOGD("nAllocationSyncAll, con(%p), a(%p), bits(0x%08x)", (RsContext)con, (RsAllocation)a, + bits); + } rsAllocationSyncAll((RsContext)con, (RsAllocation)a, (RsAllocationUsageType)bits); } static jobject nAllocationGetSurface(JNIEnv *_env, jobject _this, jlong con, jlong a) { - LOG_API("nAllocationGetSurface, con(%p), a(%p)", (RsContext)con, (RsAllocation)a); + if (kLogApi) { + ALOGD("nAllocationGetSurface, con(%p), a(%p)", (RsContext)con, (RsAllocation)a); + } - IGraphicBufferProducer *v = (IGraphicBufferProducer *)rsAllocationGetSurface((RsContext)con, (RsAllocation)a); + IGraphicBufferProducer *v = (IGraphicBufferProducer *)rsAllocationGetSurface((RsContext)con, + (RsAllocation)a); sp<IGraphicBufferProducer> bp = v; - v->decStrong(NULL); + v->decStrong(nullptr); jobject o = android_view_Surface_createFromIGraphicBufferProducer(_env, bp); return o; @@ -558,28 +1061,35 @@ nAllocationGetSurface(JNIEnv *_env, jobject _this, jlong con, jlong a) static void nAllocationSetSurface(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject sur) { - LOG_API("nAllocationSetSurface, con(%p), alloc(%p), surface(%p)", - (RsContext)con, (RsAllocation)alloc, (Surface *)sur); + if (kLogApi) { + ALOGD("nAllocationSetSurface, con(%p), alloc(%p), surface(%p)", (RsContext)con, + (RsAllocation)alloc, (Surface *)sur); + } sp<Surface> s; if (sur != 0) { s = android_view_Surface_getSurface(_env, sur); } - rsAllocationSetSurface((RsContext)con, (RsAllocation)alloc, static_cast<ANativeWindow *>(s.get())); + rsAllocationSetSurface((RsContext)con, (RsAllocation)alloc, + static_cast<ANativeWindow *>(s.get())); } static void nAllocationIoSend(JNIEnv *_env, jobject _this, jlong con, jlong alloc) { - LOG_API("nAllocationIoSend, con(%p), alloc(%p)", (RsContext)con, alloc); + if (kLogApi) { + ALOGD("nAllocationIoSend, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc); + } rsAllocationIoSend((RsContext)con, (RsAllocation)alloc); } static void nAllocationIoReceive(JNIEnv *_env, jobject _this, jlong con, jlong alloc) { - LOG_API("nAllocationIoReceive, con(%p), alloc(%p)", (RsContext)con, alloc); + if (kLogApi) { + ALOGD("nAllocationIoReceive, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc); + } rsAllocationIoReceive((RsContext)con, (RsAllocation)alloc); } @@ -587,12 +1097,15 @@ nAllocationIoReceive(JNIEnv *_env, jobject _this, jlong con, jlong alloc) static void nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, jlong con, jlong alloc) { - LOG_API("nAllocationGenerateMipmaps, con(%p), a(%p)", (RsContext)con, (RsAllocation)alloc); + if (kLogApi) { + ALOGD("nAllocationGenerateMipmaps, con(%p), a(%p)", (RsContext)con, (RsAllocation)alloc); + } rsAllocationGenerateMipmaps((RsContext)con, (RsAllocation)alloc); } static jlong -nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip, jobject jbitmap, jint usage) +nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip, + jobject jbitmap, jint usage) { SkBitmap const * nativeBitmap = (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID); @@ -608,7 +1121,8 @@ nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, } static jlong -nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip, jobject jbitmap, jint usage) +nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, jlong con, jlong type, + jint mip, jobject jbitmap, jint usage) { SkBitmap const * nativeBitmap = (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID); @@ -624,7 +1138,8 @@ nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, jlong con, } static jlong -nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip, jobject jbitmap, jint usage) +nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip, + jobject jbitmap, jint usage) { SkBitmap const * nativeBitmap = (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID); @@ -670,46 +1185,56 @@ nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, job bitmap.notifyPixelsChanged(); } -static void ReleaseBitmapCallback(void *bmp) -{ - SkBitmap const * nativeBitmap = (SkBitmap const *)bmp; - nativeBitmap->unlockPixels(); -} - - // Copies from the Java object data into the Allocation pointed to by _alloc. static void nAllocationData1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod, - jint count, jobject data, jint sizeBytes, jint dataType) + jint count, jobject data, jint sizeBytes, jint dataType, jint mSize, + jboolean usePadding) { RsAllocation *alloc = (RsAllocation *)_alloc; - LOG_API("nAllocation1DData, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), dataType(%i)", - (RsContext)con, (RsAllocation)alloc, offset, count, sizeBytes, dataType); - PER_ARRAY_TYPE(NULL, rsAllocation1DData, true, (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes); + if (kLogApi) { + ALOGD("nAllocation1DData, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), " + "dataType(%i)", (RsContext)con, (RsAllocation)alloc, offset, count, sizeBytes, + dataType); + } + PER_ARRAY_TYPE(nullptr, rsAllocation1DData, true, + (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes); } -// Copies from the Java array data into the Allocation pointed to by alloc. static void -// native void rsnAllocationElementData1D(long con, long id, int xoff, int compIdx, byte[] d, int sizeBytes); -nAllocationElementData1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint offset, jint lod, jint compIdx, jbyteArray data, jint sizeBytes) +nAllocationElementData(JNIEnv *_env, jobject _this, jlong con, jlong alloc, + jint xoff, jint yoff, jint zoff, + jint lod, jint compIdx, jbyteArray data, jint sizeBytes) { jint len = _env->GetArrayLength(data); - LOG_API("nAllocationElementData1D, con(%p), alloc(%p), offset(%i), comp(%i), len(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, offset, compIdx, len, sizeBytes); - jbyte *ptr = _env->GetByteArrayElements(data, NULL); - rsAllocation1DElementData((RsContext)con, (RsAllocation)alloc, offset, lod, ptr, sizeBytes, compIdx); + if (kLogApi) { + ALOGD("nAllocationElementData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), comp(%i), len(%i), " + "sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, compIdx, len, + sizeBytes); + } + jbyte *ptr = _env->GetByteArrayElements(data, nullptr); + rsAllocationElementData((RsContext)con, (RsAllocation)alloc, + xoff, yoff, zoff, + lod, ptr, sizeBytes, compIdx); _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); } + // Copies from the Java object data into the Allocation pointed to by _alloc. static void nAllocationData2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face, - jint w, jint h, jobject data, jint sizeBytes, jint dataType) + jint w, jint h, jobject data, jint sizeBytes, jint dataType, jint mSize, + jboolean usePadding) { RsAllocation *alloc = (RsAllocation *)_alloc; RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face; - LOG_API("nAllocation2DData, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) type(%i)", - (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType); - PER_ARRAY_TYPE(NULL, rsAllocation2DData, true, (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0); + if (kLogApi) { + ALOGD("nAllocation2DData, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) " + "type(%i)", (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType); + } + int count = w * h; + PER_ARRAY_TYPE(nullptr, rsAllocation2DData, true, + (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0); } // Copies from the Allocation pointed to by srcAlloc into the Allocation @@ -722,11 +1247,13 @@ nAllocationData2D_alloc(JNIEnv *_env, jobject _this, jlong con, jlong srcAlloc, jint srcXoff, jint srcYoff, jint srcMip, jint srcFace) { - LOG_API("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i)," - " dstMip(%i), dstFace(%i), width(%i), height(%i)," - " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)", - (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace, - width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace); + if (kLogApi) { + ALOGD("nAllocation2DData_s, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i)," + " dstMip(%i), dstFace(%i), width(%i), height(%i)," + " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i), srcFace(%i)", + (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, dstFace, + width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip, srcFace); + } rsAllocationCopy2DRange((RsContext)con, (RsAllocation)dstAlloc, @@ -741,12 +1268,18 @@ nAllocationData2D_alloc(JNIEnv *_env, jobject _this, jlong con, // Copies from the Java object data into the Allocation pointed to by _alloc. static void nAllocationData3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod, - jint w, jint h, jint d, jobject data, int sizeBytes, int dataType) + jint w, jint h, jint d, jobject data, jint sizeBytes, jint dataType, + jint mSize, jboolean usePadding) { RsAllocation *alloc = (RsAllocation *)_alloc; - LOG_API("nAllocation3DData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i), h(%i), d(%i), sizeBytes(%i)", - (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, lod, w, h, d, sizeBytes); - PER_ARRAY_TYPE(NULL, rsAllocation3DData, true, (RsContext)con, alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0); + if (kLogApi) { + ALOGD("nAllocation3DData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i)," + " h(%i), d(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, + lod, w, h, d, sizeBytes); + } + int count = w * h * d; + PER_ARRAY_TYPE(nullptr, rsAllocation3DData, true, + (RsContext)con, alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0); } // Copies from the Allocation pointed to by srcAlloc into the Allocation @@ -759,11 +1292,13 @@ nAllocationData3D_alloc(JNIEnv *_env, jobject _this, jlong con, jlong srcAlloc, jint srcXoff, jint srcYoff, jint srcZoff, jint srcMip) { - LOG_API("nAllocationData3D_alloc, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i)," - " dstMip(%i), width(%i), height(%i)," - " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i)", - (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, - width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip); + if (kLogApi) { + ALOGD("nAllocationData3D_alloc, con(%p), dstAlloc(%p), dstXoff(%i), dstYoff(%i)," + " dstMip(%i), width(%i), height(%i)," + " srcAlloc(%p), srcXoff(%i), srcYoff(%i), srcMip(%i)", + (RsContext)con, (RsAllocation)dstAlloc, dstXoff, dstYoff, dstMip, + width, height, (RsAllocation)srcAlloc, srcXoff, srcYoff, srcMip); + } rsAllocationCopy3DRange((RsContext)con, (RsAllocation)dstAlloc, @@ -776,50 +1311,136 @@ nAllocationData3D_alloc(JNIEnv *_env, jobject _this, jlong con, // Copies from the Allocation pointed to by _alloc into the Java object data. static void -nAllocationRead(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jobject data, int dataType) +nAllocationRead(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jobject data, jint dataType, + jint mSize, jboolean usePadding) { RsAllocation *alloc = (RsAllocation *)_alloc; - LOG_API("nAllocationRead, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc); - PER_ARRAY_TYPE(0, rsAllocationRead, false, (RsContext)con, alloc, ptr, len * typeBytes); + if (kLogApi) { + ALOGD("nAllocationRead, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc); + } + int count = 0; + PER_ARRAY_TYPE(0, rsAllocationRead, false, + (RsContext)con, alloc, ptr, len * typeBytes); } // Copies from the Allocation pointed to by _alloc into the Java object data. static void nAllocationRead1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod, - jint count, jobject data, int sizeBytes, int dataType) + jint count, jobject data, jint sizeBytes, jint dataType, + jint mSize, jboolean usePadding) { RsAllocation *alloc = (RsAllocation *)_alloc; - LOG_API("nAllocation1DRead, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), dataType(%i)", - (RsContext)con, alloc, offset, count, sizeBytes, dataType); - PER_ARRAY_TYPE(0, rsAllocation1DRead, false, (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes); + if (kLogApi) { + ALOGD("nAllocation1DRead, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), " + "dataType(%i)", (RsContext)con, alloc, offset, count, sizeBytes, dataType); + } + PER_ARRAY_TYPE(0, rsAllocation1DRead, false, + (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes); +} + +// Copies from the Element in the Allocation pointed to by _alloc into the Java array data. +static void +nAllocationElementRead(JNIEnv *_env, jobject _this, jlong con, jlong alloc, + jint xoff, jint yoff, jint zoff, + jint lod, jint compIdx, jbyteArray data, jint sizeBytes) +{ + jint len = _env->GetArrayLength(data); + if (kLogApi) { + ALOGD("nAllocationElementRead, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), comp(%i), len(%i), " + "sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, compIdx, len, + sizeBytes); + } + jbyte *ptr = _env->GetByteArrayElements(data, nullptr); + rsAllocationElementRead((RsContext)con, (RsAllocation)alloc, + xoff, yoff, zoff, + lod, ptr, sizeBytes, compIdx); + _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); } // Copies from the Allocation pointed to by _alloc into the Java object data. static void nAllocationRead2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face, - jint w, jint h, jobject data, int sizeBytes, int dataType) + jint w, jint h, jobject data, jint sizeBytes, jint dataType, + jint mSize, jboolean usePadding) { RsAllocation *alloc = (RsAllocation *)_alloc; RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face; - LOG_API("nAllocation2DRead, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) type(%i)", - (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType); - PER_ARRAY_TYPE(0, rsAllocation2DRead, false, (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0); + if (kLogApi) { + ALOGD("nAllocation2DRead, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) " + "type(%i)", (RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType); + } + int count = w * h; + PER_ARRAY_TYPE(0, rsAllocation2DRead, false, + (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0); +} + +// Copies from the Allocation pointed to by _alloc into the Java object data. +static void +nAllocationRead3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod, + jint w, jint h, jint d, jobject data, int sizeBytes, int dataType, + jint mSize, jboolean usePadding) +{ + RsAllocation *alloc = (RsAllocation *)_alloc; + if (kLogApi) { + ALOGD("nAllocation3DRead, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i)," + " h(%i), d(%i), sizeBytes(%i)", (RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, + lod, w, h, d, sizeBytes); + } + int count = w * h * d; + PER_ARRAY_TYPE(nullptr, rsAllocation3DRead, false, + (RsContext)con, alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0); } static jlong nAllocationGetType(JNIEnv *_env, jobject _this, jlong con, jlong a) { - LOG_API("nAllocationGetType, con(%p), a(%p)", (RsContext)con, (RsAllocation)a); + if (kLogApi) { + ALOGD("nAllocationGetType, con(%p), a(%p)", (RsContext)con, (RsAllocation)a); + } return (jlong)(uintptr_t) rsaAllocationGetType((RsContext)con, (RsAllocation)a); } static void nAllocationResize1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint dimX) { - LOG_API("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", (RsContext)con, (RsAllocation)alloc, dimX); + if (kLogApi) { + ALOGD("nAllocationResize1D, con(%p), alloc(%p), sizeX(%i)", (RsContext)con, + (RsAllocation)alloc, dimX); + } rsAllocationResize1D((RsContext)con, (RsAllocation)alloc, dimX); } + +static jlong +nAllocationAdapterCreate(JNIEnv *_env, jobject _this, jlong con, jlong basealloc, jlong type) +{ + if (kLogApi) { + ALOGD("nAllocationAdapterCreate, con(%p), base(%p), type(%p)", + (RsContext)con, (RsAllocation)basealloc, (RsElement)type); + } + return (jlong)(uintptr_t) rsAllocationAdapterCreate((RsContext)con, (RsType)type, + (RsAllocation)basealloc); + +} + +static void +nAllocationAdapterOffset(JNIEnv *_env, jobject _this, jlong con, jlong alloc, + jint x, jint y, jint z, jint face, jint lod, + jint a1, jint a2, jint a3, jint a4) +{ + uint32_t params[] = { + (uint32_t)x, (uint32_t)y, (uint32_t)z, (uint32_t)face, + (uint32_t)lod, (uint32_t)a1, (uint32_t)a2, (uint32_t)a3, (uint32_t)a4 + }; + if (kLogApi) { + ALOGD("nAllocationAdapterOffset, con(%p), alloc(%p), x(%i), y(%i), z(%i), face(%i), lod(%i), arrays(%i %i %i %i)", + (RsContext)con, (RsAllocation)alloc, x, y, z, face, lod, a1, a2, a3, a4); + } + rsAllocationAdapterOffset((RsContext)con, (RsAllocation)alloc, + params, sizeof(params)); +} + + // ----------------------------------- static jlong @@ -836,13 +1457,13 @@ static jlong nFileA3DCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jstring _path) { AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr); - if (mgr == NULL) { + if (mgr == nullptr) { return 0; } AutoJavaStringToUTF8 str(_env, _path); Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER); - if (asset == NULL) { + if (asset == nullptr) { return 0; } @@ -924,13 +1545,13 @@ nFontCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, jfloat fontSize, jint dpi) { AssetManager* mgr = assetManagerForJavaObject(_env, _assetMgr); - if (mgr == NULL) { + if (mgr == nullptr) { return 0; } AutoJavaStringToUTF8 str(_env, _path); Asset* asset = mgr->open(str.c_str(), Asset::ACCESS_BUFFER); - if (asset == NULL) { + if (asset == nullptr) { return 0; } @@ -947,21 +1568,29 @@ nFontCreateFromAsset(JNIEnv *_env, jobject _this, jlong con, jobject _assetMgr, static void nScriptBindAllocation(JNIEnv *_env, jobject _this, jlong con, jlong script, jlong alloc, jint slot) { - LOG_API("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", (RsContext)con, (RsScript)script, (RsAllocation)alloc, slot); + if (kLogApi) { + ALOGD("nScriptBindAllocation, con(%p), script(%p), alloc(%p), slot(%i)", (RsContext)con, + (RsScript)script, (RsAllocation)alloc, slot); + } rsScriptBindAllocation((RsContext)con, (RsScript)script, (RsAllocation)alloc, slot); } static void nScriptSetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jint val) { - LOG_API("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", (RsContext)con, (void *)script, slot, val); + if (kLogApi) { + ALOGD("nScriptSetVarI, con(%p), s(%p), slot(%i), val(%i)", (RsContext)con, (void *)script, + slot, val); + } rsScriptSetVarI((RsContext)con, (RsScript)script, slot, val); } static jint nScriptGetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot) { - LOG_API("nScriptGetVarI, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); + if (kLogApi) { + ALOGD("nScriptGetVarI, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); + } int value = 0; rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value)); return value; @@ -970,21 +1599,29 @@ nScriptGetVarI(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot) static void nScriptSetVarObj(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val) { - LOG_API("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%i)", (RsContext)con, (void *)script, slot, val); + if (kLogApi) { + ALOGD("nScriptSetVarObj, con(%p), s(%p), slot(%i), val(%" PRId64 ")", (RsContext)con, (void *)script, + slot, val); + } rsScriptSetVarObj((RsContext)con, (RsScript)script, slot, (RsObjectBase)val); } static void nScriptSetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jlong val) { - LOG_API("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%lli)", (RsContext)con, (void *)script, slot, val); + if (kLogApi) { + ALOGD("nScriptSetVarJ, con(%p), s(%p), slot(%i), val(%" PRId64 ")", (RsContext)con, (void *)script, + slot, val); + } rsScriptSetVarJ((RsContext)con, (RsScript)script, slot, val); } static jlong nScriptGetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot) { - LOG_API("nScriptGetVarJ, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); + if (kLogApi) { + ALOGD("nScriptGetVarJ, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); + } jlong value = 0; rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value)); return value; @@ -993,14 +1630,19 @@ nScriptGetVarJ(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot) static void nScriptSetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, float val) { - LOG_API("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", (RsContext)con, (void *)script, slot, val); + if (kLogApi) { + ALOGD("nScriptSetVarF, con(%p), s(%p), slot(%i), val(%f)", (RsContext)con, (void *)script, + slot, val); + } rsScriptSetVarF((RsContext)con, (RsScript)script, slot, val); } static jfloat nScriptGetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot) { - LOG_API("nScriptGetVarF, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); + if (kLogApi) { + ALOGD("nScriptGetVarF, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); + } jfloat value = 0; rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value)); return value; @@ -1009,14 +1651,19 @@ nScriptGetVarF(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot) static void nScriptSetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, double val) { - LOG_API("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", (RsContext)con, (void *)script, slot, val); + if (kLogApi) { + ALOGD("nScriptSetVarD, con(%p), s(%p), slot(%i), val(%lf)", (RsContext)con, (void *)script, + slot, val); + } rsScriptSetVarD((RsContext)con, (RsScript)script, slot, val); } static jdouble nScriptGetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot) { - LOG_API("nScriptGetVarD, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); + if (kLogApi) { + ALOGD("nScriptGetVarD, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); + } jdouble value = 0; rsScriptGetVarV((RsContext)con, (RsScript)script, slot, &value, sizeof(value)); return value; @@ -1025,9 +1672,11 @@ nScriptGetVarD(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot) static void nScriptSetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data) { - LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); + if (kLogApi) { + ALOGD("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); + } jint len = _env->GetArrayLength(data); - jbyte *ptr = _env->GetByteArrayElements(data, NULL); + jbyte *ptr = _env->GetByteArrayElements(data, nullptr); rsScriptSetVarV((RsContext)con, (RsScript)script, slot, ptr, len); _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); } @@ -1035,21 +1684,26 @@ nScriptSetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, static void nScriptGetVarV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data) { - LOG_API("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); + if (kLogApi) { + ALOGD("nScriptSetVarV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); + } jint len = _env->GetArrayLength(data); - jbyte *ptr = _env->GetByteArrayElements(data, NULL); + jbyte *ptr = _env->GetByteArrayElements(data, nullptr); rsScriptGetVarV((RsContext)con, (RsScript)script, slot, ptr, len); _env->ReleaseByteArrayElements(data, ptr, 0); } static void -nScriptSetVarVE(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data, jlong elem, jintArray dims) +nScriptSetVarVE(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data, + jlong elem, jintArray dims) { - LOG_API("nScriptSetVarVE, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); + if (kLogApi) { + ALOGD("nScriptSetVarVE, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); + } jint len = _env->GetArrayLength(data); - jbyte *ptr = _env->GetByteArrayElements(data, NULL); + jbyte *ptr = _env->GetByteArrayElements(data, nullptr); jint dimsLen = _env->GetArrayLength(dims) * sizeof(int); - jint *dimsPtr = _env->GetIntArrayElements(dims, NULL); + jint *dimsPtr = _env->GetIntArrayElements(dims, nullptr); rsScriptSetVarVE((RsContext)con, (RsScript)script, slot, ptr, len, (RsElement)elem, (const uint32_t*) dimsPtr, dimsLen); _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); @@ -1060,7 +1714,9 @@ nScriptSetVarVE(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, static void nScriptSetTimeZone(JNIEnv *_env, jobject _this, jlong con, jlong script, jbyteArray timeZone) { - LOG_API("nScriptCSetTimeZone, con(%p), s(%p)", (RsContext)con, (void *)script); + if (kLogApi) { + ALOGD("nScriptCSetTimeZone, con(%p), s(%p)", (RsContext)con, (void *)script); + } jint length = _env->GetArrayLength(timeZone); jbyte* timeZone_ptr; @@ -1076,174 +1732,111 @@ nScriptSetTimeZone(JNIEnv *_env, jobject _this, jlong con, jlong script, jbyteAr static void nScriptInvoke(JNIEnv *_env, jobject _this, jlong con, jlong obj, jint slot) { - LOG_API("nScriptInvoke, con(%p), script(%p)", (RsContext)con, (void *)obj); + if (kLogApi) { + ALOGD("nScriptInvoke, con(%p), script(%p)", (RsContext)con, (void *)obj); + } rsScriptInvoke((RsContext)con, (RsScript)obj, slot); } static void nScriptInvokeV(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, jbyteArray data) { - LOG_API("nScriptInvokeV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); + if (kLogApi) { + ALOGD("nScriptInvokeV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); + } jint len = _env->GetArrayLength(data); - jbyte *ptr = _env->GetByteArrayElements(data, NULL); + jbyte *ptr = _env->GetByteArrayElements(data, nullptr); rsScriptInvokeV((RsContext)con, (RsScript)script, slot, ptr, len); _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT); } static void -nScriptForEach(JNIEnv *_env, jobject _this, jlong con, - jlong script, jint slot, jlong ain, jlong aout) -{ - LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); - rsScriptForEach((RsContext)con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0, NULL, 0); -} -static void -nScriptForEachV(JNIEnv *_env, jobject _this, jlong con, - jlong script, jint slot, jlong ain, jlong aout, jbyteArray params) -{ - LOG_API("nScriptForEach, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); - jint len = _env->GetArrayLength(params); - jbyte *ptr = _env->GetByteArrayElements(params, NULL); - rsScriptForEach((RsContext)con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len, NULL, 0); - _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT); -} - -static void -nScriptForEachClipped(JNIEnv *_env, jobject _this, jlong con, - jlong script, jint slot, jlong ain, jlong aout, - jint xstart, jint xend, - jint ystart, jint yend, jint zstart, jint zend) -{ - LOG_API("nScriptForEachClipped, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); - RsScriptCall sc; - sc.xStart = xstart; - sc.xEnd = xend; - sc.yStart = ystart; - sc.yEnd = yend; - sc.zStart = zstart; - sc.zEnd = zend; - sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE; - sc.arrayStart = 0; - sc.arrayEnd = 0; - rsScriptForEach((RsContext)con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, NULL, 0, &sc, sizeof(sc)); -} - -static void -nScriptForEachClippedV(JNIEnv *_env, jobject _this, jlong con, - jlong script, jint slot, jlong ain, jlong aout, - jbyteArray params, jint xstart, jint xend, - jint ystart, jint yend, jint zstart, jint zend) +nScriptForEach(JNIEnv *_env, jobject _this, jlong con, jlong script, jint slot, + jlongArray ains, jlong aout, jbyteArray params, + jintArray limits) { - LOG_API("nScriptForEachClipped, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); - jint len = _env->GetArrayLength(params); - jbyte *ptr = _env->GetByteArrayElements(params, NULL); - RsScriptCall sc; - sc.xStart = xstart; - sc.xEnd = xend; - sc.yStart = ystart; - sc.yEnd = yend; - sc.zStart = zstart; - sc.zEnd = zend; - sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE; - sc.arrayStart = 0; - sc.arrayEnd = 0; - rsScriptForEach((RsContext)con, (RsScript)script, slot, (RsAllocation)ain, (RsAllocation)aout, ptr, len, &sc, sizeof(sc)); - _env->ReleaseByteArrayElements(params, ptr, JNI_ABORT); -} + if (kLogApi) { + ALOGD("nScriptForEach, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); + } -static void -nScriptForEachMultiClipped(JNIEnv *_env, jobject _this, jlong con, - jlong script, jint slot, jlongArray ains, jlong aout, - jint xstart, jint xend, - jint ystart, jint yend, jint zstart, jint zend) -{ - LOG_API("nScriptForEachMultiClipped, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); + jint in_len = 0; + jlong *in_ptr = nullptr; - jint in_len = _env->GetArrayLength(ains); - jlong* in_ptr = _env->GetLongArrayElements(ains, NULL); + RsAllocation *in_allocs = nullptr; - RsAllocation *in_allocs = NULL; + if (ains != nullptr) { + in_len = _env->GetArrayLength(ains); + in_ptr = _env->GetLongArrayElements(ains, nullptr); - if (sizeof(RsAllocation) == sizeof(jlong)) { - in_allocs = (RsAllocation*)in_ptr; + if (sizeof(RsAllocation) == sizeof(jlong)) { + in_allocs = (RsAllocation*)in_ptr; - } else { - // Convert from 64-bit jlong types to the native pointer type. + } else { + // Convert from 64-bit jlong types to the native pointer type. - in_allocs = new RsAllocation[in_len]; + in_allocs = (RsAllocation*)alloca(in_len * sizeof(RsAllocation)); - for (int index = in_len; --index >= 0;) { - in_allocs[index] = (RsAllocation)in_ptr[index]; - } + for (int index = in_len; --index >= 0;) { + in_allocs[index] = (RsAllocation)in_ptr[index]; + } + } } - RsScriptCall sc; - sc.xStart = xstart; - sc.xEnd = xend; - sc.yStart = ystart; - sc.yEnd = yend; - sc.zStart = zstart; - sc.zEnd = zend; - sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE; - sc.arrayStart = 0; - sc.arrayEnd = 0; - - rsScriptForEachMulti((RsContext)con, (RsScript)script, slot, in_allocs, in_len, (RsAllocation)aout, NULL, 0, &sc, sizeof(sc)); + jint param_len = 0; + jbyte *param_ptr = nullptr; - if (sizeof(RsAllocation) != sizeof(jlong)) { - delete[] in_allocs; + if (params != nullptr) { + param_len = _env->GetArrayLength(params); + param_ptr = _env->GetByteArrayElements(params, nullptr); } - _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT); -} - -static void -nScriptForEachMultiClippedV(JNIEnv *_env, jobject _this, jlong con, - jlong script, jint slot, jlongArray ains, jlong aout, - jbyteArray params, jint xstart, jint xend, - jint ystart, jint yend, jint zstart, jint zend) -{ - LOG_API("nScriptForEachMultiClippedV, con(%p), s(%p), slot(%i)", (RsContext)con, (void *)script, slot); - - jint in_len = _env->GetArrayLength(ains); - jlong* in_ptr = _env->GetLongArrayElements(ains, NULL); - - RsAllocation *in_allocs = NULL; - - if (sizeof(RsAllocation) == sizeof(jlong)) { - in_allocs = (RsAllocation*)in_ptr; - - } else { - // Convert from 64-bit jlong types to the native pointer type. - - in_allocs = new RsAllocation[in_len]; - - for (int index = in_len; --index >= 0;) { - in_allocs[index] = (RsAllocation)in_ptr[index]; - } + RsScriptCall sc, *sca = nullptr; + uint32_t sc_size = 0; + + jint limit_len = 0; + jint *limit_ptr = nullptr; + + if (limits != nullptr) { + limit_len = _env->GetArrayLength(limits); + limit_ptr = _env->GetIntArrayElements(limits, nullptr); + + assert(limit_len == 6); + UNUSED(limit_len); // As the assert might not be compiled. + + sc.xStart = limit_ptr[0]; + sc.xEnd = limit_ptr[1]; + sc.yStart = limit_ptr[2]; + sc.yEnd = limit_ptr[3]; + sc.zStart = limit_ptr[4]; + sc.zEnd = limit_ptr[5]; + sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE; + sc.arrayStart = 0; + sc.arrayEnd = 0; + sc.array2Start = 0; + sc.array2End = 0; + sc.array3Start = 0; + sc.array3End = 0; + sc.array4Start = 0; + sc.array4End = 0; + + sca = ≻ } - jint param_len = _env->GetArrayLength(params); - jbyte* param_ptr = _env->GetByteArrayElements(params, NULL); + rsScriptForEachMulti((RsContext)con, (RsScript)script, slot, + in_allocs, in_len, (RsAllocation)aout, + param_ptr, param_len, sca, sc_size); - RsScriptCall sc; - sc.xStart = xstart; - sc.xEnd = xend; - sc.yStart = ystart; - sc.yEnd = yend; - sc.zStart = zstart; - sc.zEnd = zend; - sc.strategy = RS_FOR_EACH_STRATEGY_DONT_CARE; - sc.arrayStart = 0; - sc.arrayEnd = 0; - rsScriptForEachMulti((RsContext)con, (RsScript)script, slot, in_allocs, in_len, (RsAllocation)aout, param_ptr, param_len, &sc, sizeof(sc)); + if (ains != nullptr) { + _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT); + } - if (sizeof(RsAllocation) != sizeof(jlong)) { - delete[] in_allocs; + if (params != nullptr) { + _env->ReleaseByteArrayElements(params, param_ptr, JNI_ABORT); } - _env->ReleaseLongArrayElements(ains, in_ptr, JNI_ABORT); - _env->ReleaseByteArrayElements(params, param_ptr, JNI_ABORT); + if (limits != nullptr) { + _env->ReleaseIntArrayElements(limits, limit_ptr, JNI_ABORT); + } } // ----------------------------------- @@ -1253,12 +1846,14 @@ nScriptCCreate(JNIEnv *_env, jobject _this, jlong con, jstring resName, jstring cacheDir, jbyteArray scriptRef, jint length) { - LOG_API("nScriptCCreate, con(%p)", (RsContext)con); + if (kLogApi) { + ALOGD("nScriptCCreate, con(%p)", (RsContext)con); + } AutoJavaStringToUTF8 resNameUTF(_env, resName); AutoJavaStringToUTF8 cacheDirUTF(_env, cacheDir); jlong ret = 0; - jbyte* script_ptr = NULL; + jbyte* script_ptr = nullptr; jint _exception = 0; jint remaining; if (!scriptRef) { @@ -1300,21 +1895,40 @@ exit: static jlong nScriptIntrinsicCreate(JNIEnv *_env, jobject _this, jlong con, jint id, jlong eid) { - LOG_API("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", (RsContext)con, id, (void *)eid); + if (kLogApi) { + ALOGD("nScriptIntrinsicCreate, con(%p) id(%i) element(%p)", (RsContext)con, id, + (void *)eid); + } return (jlong)(uintptr_t)rsScriptIntrinsicCreate((RsContext)con, id, (RsElement)eid); } static jlong nScriptKernelIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot, jint sig) { - LOG_API("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", (RsContext)con, (void *)sid, slot, sig); + if (kLogApi) { + ALOGD("nScriptKernelIDCreate, con(%p) script(%p), slot(%i), sig(%i)", (RsContext)con, + (void *)sid, slot, sig); + } return (jlong)(uintptr_t)rsScriptKernelIDCreate((RsContext)con, (RsScript)sid, slot, sig); } static jlong +nScriptInvokeIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot) +{ + if (kLogApi) { + ALOGD("nScriptInvokeIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con, + (void *)sid, slot); + } + return (jlong)(uintptr_t)rsScriptInvokeIDCreate((RsContext)con, (RsScript)sid, slot); +} + +static jlong nScriptFieldIDCreate(JNIEnv *_env, jobject _this, jlong con, jlong sid, jint slot) { - LOG_API("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con, (void *)sid, slot); + if (kLogApi) { + ALOGD("nScriptFieldIDCreate, con(%p) script(%p), slot(%i)", (RsContext)con, (void *)sid, + slot); + } return (jlong)(uintptr_t)rsScriptFieldIDCreate((RsContext)con, (RsScript)sid, slot); } @@ -1322,38 +1936,40 @@ static jlong nScriptGroupCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _kernels, jlongArray _src, jlongArray _dstk, jlongArray _dstf, jlongArray _types) { - LOG_API("nScriptGroupCreate, con(%p)", (RsContext)con); + if (kLogApi) { + ALOGD("nScriptGroupCreate, con(%p)", (RsContext)con); + } jint kernelsLen = _env->GetArrayLength(_kernels); - jlong *jKernelsPtr = _env->GetLongArrayElements(_kernels, NULL); + jlong *jKernelsPtr = _env->GetLongArrayElements(_kernels, nullptr); RsScriptKernelID* kernelsPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * kernelsLen); for(int i = 0; i < kernelsLen; ++i) { kernelsPtr[i] = (RsScriptKernelID)jKernelsPtr[i]; } jint srcLen = _env->GetArrayLength(_src); - jlong *jSrcPtr = _env->GetLongArrayElements(_src, NULL); + jlong *jSrcPtr = _env->GetLongArrayElements(_src, nullptr); RsScriptKernelID* srcPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * srcLen); for(int i = 0; i < srcLen; ++i) { srcPtr[i] = (RsScriptKernelID)jSrcPtr[i]; } jint dstkLen = _env->GetArrayLength(_dstk); - jlong *jDstkPtr = _env->GetLongArrayElements(_dstk, NULL); + jlong *jDstkPtr = _env->GetLongArrayElements(_dstk, nullptr); RsScriptKernelID* dstkPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstkLen); for(int i = 0; i < dstkLen; ++i) { dstkPtr[i] = (RsScriptKernelID)jDstkPtr[i]; } jint dstfLen = _env->GetArrayLength(_dstf); - jlong *jDstfPtr = _env->GetLongArrayElements(_dstf, NULL); + jlong *jDstfPtr = _env->GetLongArrayElements(_dstf, nullptr); RsScriptKernelID* dstfPtr = (RsScriptKernelID*) malloc(sizeof(RsScriptKernelID) * dstfLen); for(int i = 0; i < dstfLen; ++i) { dstfPtr[i] = (RsScriptKernelID)jDstfPtr[i]; } jint typesLen = _env->GetArrayLength(_types); - jlong *jTypesPtr = _env->GetLongArrayElements(_types, NULL); + jlong *jTypesPtr = _env->GetLongArrayElements(_types, nullptr); RsType* typesPtr = (RsType*) malloc(sizeof(RsType) * typesLen); for(int i = 0; i < typesLen; ++i) { typesPtr[i] = (RsType)jTypesPtr[i]; @@ -1382,23 +1998,29 @@ nScriptGroupCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _kernels, static void nScriptGroupSetInput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc) { - LOG_API("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con, - (void *)gid, (void *)kid, (void *)alloc); + if (kLogApi) { + ALOGD("nScriptGroupSetInput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con, + (void *)gid, (void *)kid, (void *)alloc); + } rsScriptGroupSetInput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc); } static void nScriptGroupSetOutput(JNIEnv *_env, jobject _this, jlong con, jlong gid, jlong kid, jlong alloc) { - LOG_API("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con, - (void *)gid, (void *)kid, (void *)alloc); + if (kLogApi) { + ALOGD("nScriptGroupSetOutput, con(%p) group(%p), kernelId(%p), alloc(%p)", (RsContext)con, + (void *)gid, (void *)kid, (void *)alloc); + } rsScriptGroupSetOutput((RsContext)con, (RsScriptGroup)gid, (RsScriptKernelID)kid, (RsAllocation)alloc); } static void nScriptGroupExecute(JNIEnv *_env, jobject _this, jlong con, jlong gid) { - LOG_API("nScriptGroupSetOutput, con(%p) group(%p)", (RsContext)con, (void *)gid); + if (kLogApi) { + ALOGD("nScriptGroupSetOutput, con(%p) group(%p)", (RsContext)con, (void *)gid); + } rsScriptGroupExecute((RsContext)con, (RsScriptGroup)gid); } @@ -1411,7 +2033,9 @@ nProgramStoreCreate(JNIEnv *_env, jobject _this, jlong con, jint srcFunc, jint destFunc, jint depthFunc) { - LOG_API("nProgramStoreCreate, con(%p)", (RsContext)con); + if (kLogApi) { + ALOGD("nProgramStoreCreate, con(%p)", (RsContext)con); + } return (jlong)(uintptr_t)rsProgramStoreCreate((RsContext)con, colorMaskR, colorMaskG, colorMaskB, colorMaskA, depthMask, ditherEnable, (RsBlendSrcFunc)srcFunc, (RsBlendDstFunc)destFunc, (RsDepthFunc)depthFunc); @@ -1422,21 +2046,30 @@ nProgramStoreCreate(JNIEnv *_env, jobject _this, jlong con, static void nProgramBindConstants(JNIEnv *_env, jobject _this, jlong con, jlong vpv, jint slot, jlong a) { - LOG_API("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", (RsContext)con, (RsProgramVertex)vpv, slot, (RsAllocation)a); + if (kLogApi) { + ALOGD("nProgramBindConstants, con(%p), vpf(%p), sloat(%i), a(%p)", (RsContext)con, + (RsProgramVertex)vpv, slot, (RsAllocation)a); + } rsProgramBindConstants((RsContext)con, (RsProgram)vpv, slot, (RsAllocation)a); } static void nProgramBindTexture(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a) { - LOG_API("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con, (RsProgramFragment)vpf, slot, (RsAllocation)a); + if (kLogApi) { + ALOGD("nProgramBindTexture, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con, + (RsProgramFragment)vpf, slot, (RsAllocation)a); + } rsProgramBindTexture((RsContext)con, (RsProgramFragment)vpf, slot, (RsAllocation)a); } static void nProgramBindSampler(JNIEnv *_env, jobject _this, jlong con, jlong vpf, jint slot, jlong a) { - LOG_API("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con, (RsProgramFragment)vpf, slot, (RsSampler)a); + if (kLogApi) { + ALOGD("nProgramBindSampler, con(%p), vpf(%p), slot(%i), a(%p)", (RsContext)con, + (RsProgramFragment)vpf, slot, (RsSampler)a); + } rsProgramBindSampler((RsContext)con, (RsProgramFragment)vpf, slot, (RsSampler)a); } @@ -1447,7 +2080,7 @@ nProgramFragmentCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader, jobjectArray texNames, jlongArray params) { AutoJavaStringToUTF8 shaderUTF(_env, shader); - jlong *jParamPtr = _env->GetLongArrayElements(params, NULL); + jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr); jint paramLen = _env->GetArrayLength(params); int texCount = _env->GetArrayLength(texNames); @@ -1455,7 +2088,9 @@ nProgramFragmentCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader, const char ** nameArray = names.c_str(); size_t* sizeArray = names.c_str_len(); - LOG_API("nProgramFragmentCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen); + if (kLogApi) { + ALOGD("nProgramFragmentCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen); + } uintptr_t * paramPtr = (uintptr_t*) malloc(sizeof(uintptr_t) * paramLen); for(int i = 0; i < paramLen; ++i) { @@ -1478,10 +2113,12 @@ nProgramVertexCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader, jobjectArray texNames, jlongArray params) { AutoJavaStringToUTF8 shaderUTF(_env, shader); - jlong *jParamPtr = _env->GetLongArrayElements(params, NULL); + jlong *jParamPtr = _env->GetLongArrayElements(params, nullptr); jint paramLen = _env->GetArrayLength(params); - LOG_API("nProgramVertexCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen); + if (kLogApi) { + ALOGD("nProgramVertexCreate, con(%p), paramLen(%i)", (RsContext)con, paramLen); + } int texCount = _env->GetArrayLength(texNames); AutoJavaStringArrayToUTF8 names(_env, texNames, texCount); @@ -1507,7 +2144,10 @@ nProgramVertexCreate(JNIEnv *_env, jobject _this, jlong con, jstring shader, static jlong nProgramRasterCreate(JNIEnv *_env, jobject _this, jlong con, jboolean pointSprite, jint cull) { - LOG_API("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", (RsContext)con, pointSprite, cull); + if (kLogApi) { + ALOGD("nProgramRasterCreate, con(%p), pointSprite(%i), cull(%i)", (RsContext)con, + pointSprite, cull); + } return (jlong)(uintptr_t)rsProgramRasterCreate((RsContext)con, pointSprite, (RsCullMode)cull); } @@ -1517,35 +2157,46 @@ nProgramRasterCreate(JNIEnv *_env, jobject _this, jlong con, jboolean pointSprit static void nContextBindRootScript(JNIEnv *_env, jobject _this, jlong con, jlong script) { - LOG_API("nContextBindRootScript, con(%p), script(%p)", (RsContext)con, (RsScript)script); + if (kLogApi) { + ALOGD("nContextBindRootScript, con(%p), script(%p)", (RsContext)con, (RsScript)script); + } rsContextBindRootScript((RsContext)con, (RsScript)script); } static void nContextBindProgramStore(JNIEnv *_env, jobject _this, jlong con, jlong pfs) { - LOG_API("nContextBindProgramStore, con(%p), pfs(%p)", (RsContext)con, (RsProgramStore)pfs); + if (kLogApi) { + ALOGD("nContextBindProgramStore, con(%p), pfs(%p)", (RsContext)con, (RsProgramStore)pfs); + } rsContextBindProgramStore((RsContext)con, (RsProgramStore)pfs); } static void nContextBindProgramFragment(JNIEnv *_env, jobject _this, jlong con, jlong pf) { - LOG_API("nContextBindProgramFragment, con(%p), pf(%p)", (RsContext)con, (RsProgramFragment)pf); + if (kLogApi) { + ALOGD("nContextBindProgramFragment, con(%p), pf(%p)", (RsContext)con, + (RsProgramFragment)pf); + } rsContextBindProgramFragment((RsContext)con, (RsProgramFragment)pf); } static void nContextBindProgramVertex(JNIEnv *_env, jobject _this, jlong con, jlong pf) { - LOG_API("nContextBindProgramVertex, con(%p), pf(%p)", (RsContext)con, (RsProgramVertex)pf); + if (kLogApi) { + ALOGD("nContextBindProgramVertex, con(%p), pf(%p)", (RsContext)con, (RsProgramVertex)pf); + } rsContextBindProgramVertex((RsContext)con, (RsProgramVertex)pf); } static void nContextBindProgramRaster(JNIEnv *_env, jobject _this, jlong con, jlong pf) { - LOG_API("nContextBindProgramRaster, con(%p), pf(%p)", (RsContext)con, (RsProgramRaster)pf); + if (kLogApi) { + ALOGD("nContextBindProgramRaster, con(%p), pf(%p)", (RsContext)con, (RsProgramRaster)pf); + } rsContextBindProgramRaster((RsContext)con, (RsProgramRaster)pf); } @@ -1556,7 +2207,9 @@ static jlong nSamplerCreate(JNIEnv *_env, jobject _this, jlong con, jint magFilter, jint minFilter, jint wrapS, jint wrapT, jint wrapR, jfloat aniso) { - LOG_API("nSamplerCreate, con(%p)", (RsContext)con); + if (kLogApi) { + ALOGD("nSamplerCreate, con(%p)", (RsContext)con); + } return (jlong)(uintptr_t)rsSamplerCreate((RsContext)con, (RsSamplerValue)magFilter, (RsSamplerValue)minFilter, @@ -1569,36 +2222,28 @@ nSamplerCreate(JNIEnv *_env, jobject _this, jlong con, jint magFilter, jint minF // --------------------------------------------------------------------------- static jlong -nPathCreate(JNIEnv *_env, jobject _this, jlong con, jint prim, jboolean isStatic, jlong _vtx, jlong _loop, jfloat q) { - LOG_API("nPathCreate, con(%p)", (RsContext)con); - - jlong id = (jlong)(uintptr_t)rsPathCreate((RsContext)con, (RsPathPrimitive)prim, isStatic, - (RsAllocation)_vtx, - (RsAllocation)_loop, q); - return id; -} - -static jlong nMeshCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _vtx, jlongArray _idx, jintArray _prim) { - LOG_API("nMeshCreate, con(%p)", (RsContext)con); + if (kLogApi) { + ALOGD("nMeshCreate, con(%p)", (RsContext)con); + } jint vtxLen = _env->GetArrayLength(_vtx); - jlong *jVtxPtr = _env->GetLongArrayElements(_vtx, NULL); + jlong *jVtxPtr = _env->GetLongArrayElements(_vtx, nullptr); RsAllocation* vtxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * vtxLen); for(int i = 0; i < vtxLen; ++i) { vtxPtr[i] = (RsAllocation)(uintptr_t)jVtxPtr[i]; } jint idxLen = _env->GetArrayLength(_idx); - jlong *jIdxPtr = _env->GetLongArrayElements(_idx, NULL); + jlong *jIdxPtr = _env->GetLongArrayElements(_idx, nullptr); RsAllocation* idxPtr = (RsAllocation*) malloc(sizeof(RsAllocation) * idxLen); for(int i = 0; i < idxLen; ++i) { idxPtr[i] = (RsAllocation)(uintptr_t)jIdxPtr[i]; } jint primLen = _env->GetArrayLength(_prim); - jint *primPtr = _env->GetIntArrayElements(_prim, NULL); + jint *primPtr = _env->GetIntArrayElements(_prim, nullptr); jlong id = (jlong)(uintptr_t)rsMeshCreate((RsContext)con, (RsAllocation *)vtxPtr, vtxLen, @@ -1616,7 +2261,9 @@ nMeshCreate(JNIEnv *_env, jobject _this, jlong con, jlongArray _vtx, jlongArray static jint nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh) { - LOG_API("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh); + if (kLogApi) { + ALOGD("nMeshGetVertexBufferCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh); + } jint vtxCount = 0; rsaMeshGetVertexBufferCount((RsContext)con, (RsMesh)mesh, &vtxCount); return vtxCount; @@ -1625,7 +2272,9 @@ nMeshGetVertexBufferCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh) static jint nMeshGetIndexCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh) { - LOG_API("nMeshGetIndexCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh); + if (kLogApi) { + ALOGD("nMeshGetIndexCount, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh); + } jint idxCount = 0; rsaMeshGetIndexCount((RsContext)con, (RsMesh)mesh, &idxCount); return idxCount; @@ -1634,7 +2283,9 @@ nMeshGetIndexCount(JNIEnv *_env, jobject _this, jlong con, jlong mesh) static void nMeshGetVertices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _ids, jint numVtxIDs) { - LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh); + if (kLogApi) { + ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh); + } RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numVtxIDs * sizeof(RsAllocation)); rsaMeshGetVertices((RsContext)con, (RsMesh)mesh, allocs, (uint32_t)numVtxIDs); @@ -1650,7 +2301,9 @@ nMeshGetVertices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray static void nMeshGetIndices(JNIEnv *_env, jobject _this, jlong con, jlong mesh, jlongArray _idxIds, jintArray _primitives, jint numIndices) { - LOG_API("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh); + if (kLogApi) { + ALOGD("nMeshGetVertices, con(%p), Mesh(%p)", (RsContext)con, (RsMesh)mesh); + } RsAllocation *allocs = (RsAllocation*)malloc((uint32_t)numIndices * sizeof(RsAllocation)); uint32_t *prims= (uint32_t*)malloc((uint32_t)numIndices * sizeof(uint32_t)); @@ -1698,12 +2351,17 @@ static JNINativeMethod methods[] = { {"rsnContextCreateGL", "(JIIIIIIIIIIIIFI)J", (void*)nContextCreateGL }, {"rsnContextFinish", "(J)V", (void*)nContextFinish }, {"rsnContextSetPriority", "(JI)V", (void*)nContextSetPriority }, +{"rsnContextSetCacheDir", "(JLjava/lang/String;)V", (void*)nContextSetCacheDir }, {"rsnContextSetSurface", "(JIILandroid/view/Surface;)V", (void*)nContextSetSurface }, {"rsnContextDestroy", "(J)V", (void*)nContextDestroy }, {"rsnContextDump", "(JI)V", (void*)nContextDump }, {"rsnContextPause", "(J)V", (void*)nContextPause }, {"rsnContextResume", "(J)V", (void*)nContextResume }, {"rsnContextSendMessage", "(JI[I)V", (void*)nContextSendMessage }, +{"rsnClosureCreate", "(JJJ[J[J[I[J[J)J", (void*)nClosureCreate }, +{"rsnInvokeClosureCreate", "(JJ[B[J[J[I)J", (void*)nInvokeClosureCreate }, +{"rsnClosureSetArg", "(JJIJI)V", (void*)nClosureSetArg }, +{"rsnClosureSetGlobal", "(JJJJI)V", (void*)nClosureSetGlobal }, {"rsnAssignName", "(JJ[B)V", (void*)nAssignName }, {"rsnGetName", "(JJ)Ljava/lang/String;", (void*)nGetName }, {"rsnObjDestroy", "(JJ)V", (void*)nObjDestroy }, @@ -1740,29 +2398,31 @@ static JNINativeMethod methods[] = { {"rsnAllocationSetSurface", "(JJLandroid/view/Surface;)V", (void*)nAllocationSetSurface }, {"rsnAllocationIoSend", "(JJ)V", (void*)nAllocationIoSend }, {"rsnAllocationIoReceive", "(JJ)V", (void*)nAllocationIoReceive }, -{"rsnAllocationData1D", "(JJIIILjava/lang/Object;II)V", (void*)nAllocationData1D }, -{"rsnAllocationElementData1D", "(JJIII[BI)V", (void*)nAllocationElementData1D }, -{"rsnAllocationData2D", "(JJIIIIIILjava/lang/Object;II)V", (void*)nAllocationData2D }, +{"rsnAllocationData1D", "(JJIIILjava/lang/Object;IIIZ)V", (void*)nAllocationData1D }, +{"rsnAllocationElementData", "(JJIIIII[BI)V", (void*)nAllocationElementData }, +{"rsnAllocationData2D", "(JJIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationData2D }, {"rsnAllocationData2D", "(JJIIIIIIJIIII)V", (void*)nAllocationData2D_alloc }, -{"rsnAllocationData3D", "(JJIIIIIIILjava/lang/Object;II)V", (void*)nAllocationData3D }, +{"rsnAllocationData3D", "(JJIIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationData3D }, {"rsnAllocationData3D", "(JJIIIIIIIJIIII)V", (void*)nAllocationData3D_alloc }, -{"rsnAllocationRead", "(JJLjava/lang/Object;I)V", (void*)nAllocationRead }, -{"rsnAllocationRead1D", "(JJIIILjava/lang/Object;II)V", (void*)nAllocationRead1D }, -{"rsnAllocationRead2D", "(JJIIIIIILjava/lang/Object;II)V", (void*)nAllocationRead2D }, +{"rsnAllocationRead", "(JJLjava/lang/Object;IIZ)V", (void*)nAllocationRead }, +{"rsnAllocationRead1D", "(JJIIILjava/lang/Object;IIIZ)V", (void*)nAllocationRead1D }, +{"rsnAllocationElementRead", "(JJIIIII[BI)V", (void*)nAllocationElementRead }, +{"rsnAllocationRead2D", "(JJIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationRead2D }, +{"rsnAllocationRead3D", "(JJIIIIIIILjava/lang/Object;IIIZ)V", (void*)nAllocationRead3D }, {"rsnAllocationGetType", "(JJ)J", (void*)nAllocationGetType}, {"rsnAllocationResize1D", "(JJI)V", (void*)nAllocationResize1D }, {"rsnAllocationGenerateMipmaps", "(JJ)V", (void*)nAllocationGenerateMipmaps }, +{"rsnAllocationAdapterCreate", "(JJJ)J", (void*)nAllocationAdapterCreate }, +{"rsnAllocationAdapterOffset", "(JJIIIIIIIII)V", (void*)nAllocationAdapterOffset }, + {"rsnScriptBindAllocation", "(JJJI)V", (void*)nScriptBindAllocation }, {"rsnScriptSetTimeZone", "(JJ[B)V", (void*)nScriptSetTimeZone }, {"rsnScriptInvoke", "(JJI)V", (void*)nScriptInvoke }, {"rsnScriptInvokeV", "(JJI[B)V", (void*)nScriptInvokeV }, -{"rsnScriptForEach", "(JJIJJ)V", (void*)nScriptForEach }, -{"rsnScriptForEach", "(JJIJJ[B)V", (void*)nScriptForEachV }, -{"rsnScriptForEachClipped", "(JJIJJIIIIII)V", (void*)nScriptForEachClipped }, -{"rsnScriptForEachClipped", "(JJIJJ[BIIIIII)V", (void*)nScriptForEachClippedV }, -{"rsnScriptForEachMultiClipped", "(JJI[JJIIIIII)V", (void*)nScriptForEachMultiClipped }, -{"rsnScriptForEachMultiClipped", "(JJI[JJ[BIIIIII)V", (void*)nScriptForEachMultiClippedV }, + +{"rsnScriptForEach", "(JJI[JJ[B[I)V", (void*)nScriptForEach }, + {"rsnScriptSetVarI", "(JJII)V", (void*)nScriptSetVarI }, {"rsnScriptGetVarI", "(JJI)I", (void*)nScriptGetVarI }, {"rsnScriptSetVarJ", "(JJIJ)V", (void*)nScriptSetVarJ }, @@ -1779,11 +2439,21 @@ static JNINativeMethod methods[] = { {"rsnScriptCCreate", "(JLjava/lang/String;Ljava/lang/String;[BI)J", (void*)nScriptCCreate }, {"rsnScriptIntrinsicCreate", "(JIJ)J", (void*)nScriptIntrinsicCreate }, {"rsnScriptKernelIDCreate", "(JJII)J", (void*)nScriptKernelIDCreate }, +{"rsnScriptInvokeIDCreate", "(JJI)J", (void*)nScriptInvokeIDCreate }, {"rsnScriptFieldIDCreate", "(JJI)J", (void*)nScriptFieldIDCreate }, {"rsnScriptGroupCreate", "(J[J[J[J[J[J)J", (void*)nScriptGroupCreate }, +{"rsnScriptGroup2Create", "(JLjava/lang/String;Ljava/lang/String;[J)J", (void*)nScriptGroup2Create }, {"rsnScriptGroupSetInput", "(JJJJ)V", (void*)nScriptGroupSetInput }, {"rsnScriptGroupSetOutput", "(JJJJ)V", (void*)nScriptGroupSetOutput }, {"rsnScriptGroupExecute", "(JJ)V", (void*)nScriptGroupExecute }, +{"rsnScriptGroup2Execute", "(JJ)V", (void*)nScriptGroup2Execute }, + +{"rsnScriptIntrinsicBLAS_Single", "(JJIIIIIIIIIFJJFJIIII)V", (void*)nScriptIntrinsicBLAS_Single }, +{"rsnScriptIntrinsicBLAS_Double", "(JJIIIIIIIIIDJJDJIIII)V", (void*)nScriptIntrinsicBLAS_Double }, +{"rsnScriptIntrinsicBLAS_Complex", "(JJIIIIIIIIIFFJJFFJIIII)V", (void*)nScriptIntrinsicBLAS_Complex }, +{"rsnScriptIntrinsicBLAS_Z", "(JJIIIIIIIIIDDJJDDJIIII)V", (void*)nScriptIntrinsicBLAS_Z }, + +{"rsnScriptIntrinsicBLAS_BNNM", "(JJIIIJIJIJII)V", (void*)nScriptIntrinsicBLAS_BNNM }, {"rsnProgramStoreCreate", "(JZZZZZZIII)J", (void*)nProgramStoreCreate }, @@ -1803,7 +2473,6 @@ static JNINativeMethod methods[] = { {"rsnSamplerCreate", "(JIIIIIF)J", (void*)nSamplerCreate }, -{"rsnPathCreate", "(JIZJJF)J", (void*)nPathCreate }, {"rsnMeshCreate", "(J[J[J[I)J", (void*)nMeshCreate }, {"rsnMeshGetVertexBufferCount", "(JJ)I", (void*)nMeshGetVertexBufferCount }, @@ -1824,14 +2493,14 @@ static int registerFuncs(JNIEnv *_env) jint JNI_OnLoad(JavaVM* vm, void* reserved) { - JNIEnv* env = NULL; + JNIEnv* env = nullptr; jint result = -1; if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { ALOGE("ERROR: GetEnv failed\n"); goto bail; } - assert(env != NULL); + assert(env != nullptr); if (registerFuncs(env) < 0) { ALOGE("ERROR: Renderscript native registration failed\n"); |