diff options
author | Alex Sakhartchouk <alexst@google.com> | 2012-02-15 16:21:46 -0800 |
---|---|---|
committer | Alex Sakhartchouk <alexst@google.com> | 2012-02-15 16:21:46 -0800 |
commit | 2123b46ba85adb2cfb78068f8368e830640118d3 (patch) | |
tree | a941f2bca3185b5ad067b0593e8a54f9a07497cb /graphics/jni | |
parent | a3f154324ae74bc8db8c7751e3c83b6be342eace (diff) | |
download | frameworks_base-2123b46ba85adb2cfb78068f8368e830640118d3.zip frameworks_base-2123b46ba85adb2cfb78068f8368e830640118d3.tar.gz frameworks_base-2123b46ba85adb2cfb78068f8368e830640118d3.tar.bz2 |
Piping texture names through shader builder.
Fixing uint size_t mismatch.
Change-Id: Ia7c8bd9f829deaa50e1cc381ccd50f29676bbdfb
Diffstat (limited to 'graphics/jni')
-rw-r--r-- | graphics/jni/android_renderscript_RenderScript.cpp | 94 |
1 files changed, 70 insertions, 24 deletions
diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp index 94f19b3..7986cf9 100644 --- a/graphics/jni/android_renderscript_RenderScript.cpp +++ b/graphics/jni/android_renderscript_RenderScript.cpp @@ -54,13 +54,11 @@ using namespace android; class AutoJavaStringToUTF8 { public: - AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) - { + AutoJavaStringToUTF8(JNIEnv* env, jstring str) : fEnv(env), fJStr(str) { fCStr = env->GetStringUTFChars(str, NULL); fLength = env->GetStringUTFLength(str); } - ~AutoJavaStringToUTF8() - { + ~AutoJavaStringToUTF8() { fEnv->ReleaseStringUTFChars(fJStr, fCStr); } const char* c_str() const { return fCStr; } @@ -73,6 +71,42 @@ private: jsize fLength; }; +class AutoJavaStringArrayToUTF8 { +public: + AutoJavaStringArrayToUTF8(JNIEnv* env, jobjectArray strings, jsize stringsLength) + : mEnv(env), mStrings(strings), mStringsLength(stringsLength) { + mCStrings = NULL; + mSizeArray = NULL; + 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); + mSizeArray[ct] = mEnv->GetStringUTFLength(s); + } + } + } + ~AutoJavaStringArrayToUTF8() { + for (jsize ct=0; ct < mStringsLength; ct++) { + jstring s = (jstring)mEnv->GetObjectArrayElement(mStrings, ct); + mEnv->ReleaseStringUTFChars(s, mCStrings[ct]); + } + free(mCStrings); + free(mSizeArray); + } + const char **c_str() const { return mCStrings; } + size_t *c_str_len() const { return mSizeArray; } + jsize length() const { return mStringsLength; } + +private: + JNIEnv *mEnv; + jobjectArray mStrings; + const char **mCStrings; + size_t *mSizeArray; + jsize mStringsLength; +}; + // --------------------------------------------------------------------------- static jfieldID gContextId = 0; @@ -322,33 +356,27 @@ nElementCreate(JNIEnv *_env, jobject _this, RsContext con, jint type, jint kind, } static jint -nElementCreate2(JNIEnv *_env, jobject _this, RsContext con, jintArray _ids, jobjectArray _names, jintArray _arraySizes) +nElementCreate2(JNIEnv *_env, jobject _this, RsContext con, + jintArray _ids, jobjectArray _names, jintArray _arraySizes) { int fieldCount = _env->GetArrayLength(_ids); LOG_API("nElementCreate2, con(%p)", con); jint *ids = _env->GetIntArrayElements(_ids, NULL); jint *arraySizes = _env->GetIntArrayElements(_arraySizes, NULL); - const char ** nameArray = (const char **)calloc(fieldCount, sizeof(char *)); - size_t* sizeArray = (size_t*)calloc(fieldCount, sizeof(size_t)); - for (int ct=0; ct < fieldCount; ct++) { - jstring s = (jstring)_env->GetObjectArrayElement(_names, ct); - nameArray[ct] = _env->GetStringUTFChars(s, NULL); - sizeArray[ct] = _env->GetStringUTFLength(s); - } + AutoJavaStringArrayToUTF8 names(_env, _names, fieldCount); + + const char **nameArray = names.c_str(); + size_t *sizeArray = names.c_str_len(); + jint id = (jint)rsElementCreate2(con, (RsElement *)ids, fieldCount, nameArray, fieldCount * sizeof(size_t), sizeArray, (const uint32_t *)arraySizes, fieldCount); - for (int ct=0; ct < fieldCount; ct++) { - jstring s = (jstring)_env->GetObjectArrayElement(_names, ct); - _env->ReleaseStringUTFChars(s, nameArray[ct]); - } + _env->ReleaseIntArrayElements(_ids, ids, JNI_ABORT); _env->ReleaseIntArrayElements(_arraySizes, arraySizes, JNI_ABORT); - free(nameArray); - free(sizeArray); return (jint)id; } @@ -1033,15 +1061,24 @@ nProgramBindSampler(JNIEnv *_env, jobject _this, RsContext con, jint vpf, jint s // --------------------------------------------------------------------------- static jint -nProgramFragmentCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader, jintArray params) +nProgramFragmentCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader, + jobjectArray texNames, jintArray params) { AutoJavaStringToUTF8 shaderUTF(_env, shader); jint *paramPtr = _env->GetIntArrayElements(params, NULL); jint paramLen = _env->GetArrayLength(params); + int texCount = _env->GetArrayLength(texNames); + AutoJavaStringArrayToUTF8 names(_env, texNames, texCount); + const char ** nameArray = names.c_str(); + size_t* sizeArray = names.c_str_len(); + LOG_API("nProgramFragmentCreate, con(%p), paramLen(%i)", con, paramLen); - jint ret = (jint)rsProgramFragmentCreate(con, shaderUTF.c_str(), shaderUTF.length(), (uint32_t *)paramPtr, paramLen); + jint ret = (jint)rsProgramFragmentCreate(con, shaderUTF.c_str(), shaderUTF.length(), + nameArray, texCount, sizeArray, + (uint32_t *)paramPtr, paramLen); + _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT); return ret; } @@ -1050,7 +1087,8 @@ nProgramFragmentCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shade // --------------------------------------------------------------------------- static jint -nProgramVertexCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader, jintArray params) +nProgramVertexCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader, + jobjectArray texNames, jintArray params) { AutoJavaStringToUTF8 shaderUTF(_env, shader); jint *paramPtr = _env->GetIntArrayElements(params, NULL); @@ -1058,7 +1096,15 @@ nProgramVertexCreate(JNIEnv *_env, jobject _this, RsContext con, jstring shader, LOG_API("nProgramVertexCreate, con(%p), paramLen(%i)", con, paramLen); - jint ret = (jint)rsProgramVertexCreate(con, shaderUTF.c_str(), shaderUTF.length(), (uint32_t *)paramPtr, paramLen); + int texCount = _env->GetArrayLength(texNames); + AutoJavaStringArrayToUTF8 names(_env, texNames, texCount); + const char ** nameArray = names.c_str(); + size_t* sizeArray = names.c_str_len(); + + jint ret = (jint)rsProgramVertexCreate(con, shaderUTF.c_str(), shaderUTF.length(), + nameArray, texCount, sizeArray, + (uint32_t *)paramPtr, paramLen); + _env->ReleaseIntArrayElements(params, paramPtr, JNI_ABORT); return ret; } @@ -1317,9 +1363,9 @@ static JNINativeMethod methods[] = { {"rsnProgramBindTexture", "(IIII)V", (void*)nProgramBindTexture }, {"rsnProgramBindSampler", "(IIII)V", (void*)nProgramBindSampler }, -{"rsnProgramFragmentCreate", "(ILjava/lang/String;[I)I", (void*)nProgramFragmentCreate }, +{"rsnProgramFragmentCreate", "(ILjava/lang/String;[Ljava/lang/String;[I)I", (void*)nProgramFragmentCreate }, {"rsnProgramRasterCreate", "(IZI)I", (void*)nProgramRasterCreate }, -{"rsnProgramVertexCreate", "(ILjava/lang/String;[I)I", (void*)nProgramVertexCreate }, +{"rsnProgramVertexCreate", "(ILjava/lang/String;[Ljava/lang/String;[I)I", (void*)nProgramVertexCreate }, {"rsnContextBindRootScript", "(II)V", (void*)nContextBindRootScript }, {"rsnContextBindProgramStore", "(II)V", (void*)nContextBindProgramStore }, |