diff options
author | Elliott Hughes <enh@google.com> | 2011-04-07 19:17:57 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2011-04-07 19:17:57 -0700 |
commit | 8451b25a4422656bbd6657a5855e69c0f4d53c74 (patch) | |
tree | 522e51e0927ae75dbf893884699d86c50652a761 /core/jni/android/opengl | |
parent | 62c1a92dc512ef2af1bdf296f45132fa9fae7f6b (diff) | |
download | frameworks_base-8451b25a4422656bbd6657a5855e69c0f4d53c74.zip frameworks_base-8451b25a4422656bbd6657a5855e69c0f4d53c74.tar.gz frameworks_base-8451b25a4422656bbd6657a5855e69c0f4d53c74.tar.bz2 |
Use jniThrowException for exception throwing from native code.
I'll do media and the generated gl stuff separately. Otherwise, this
cleans up all direct calls of ThrowNew/Throw except the one in the
binder that needs to remain.
Change-Id: I8f95a5f020f53b25926ad31ac0c9477ddf85d04b
Diffstat (limited to 'core/jni/android/opengl')
-rw-r--r-- | core/jni/android/opengl/util.cpp | 79 |
1 files changed, 34 insertions, 45 deletions
diff --git a/core/jni/android/opengl/util.cpp b/core/jni/android/opengl/util.cpp index 589b255..6a049e0 100644 --- a/core/jni/android/opengl/util.cpp +++ b/core/jni/android/opengl/util.cpp @@ -14,7 +14,9 @@ ** limitations under the License. */ -#include <nativehelper/jni.h> +#include "jni.h" +#include "JNIHelp.h" + #include <math.h> #include <stdio.h> #include <stdlib.h> @@ -38,10 +40,6 @@ namespace android { -static jclass gIAEClass; -static jclass gUOEClass; -static jclass gAIOOBEClass; - static inline void mx4transform(float x, float y, float z, float w, const float* pM, float* pDest) { pDest[0] = pM[0 + 4 * 0] * x + pM[0 + 4 * 1] * y + pM[0 + 4 * 2] * z + pM[0 + 4 * 3] * w; @@ -151,6 +149,10 @@ int visibilityTest(float* pWS, float* pPositions, int positionsLength, return result; } +static void doThrowIAE(JNIEnv* env, const char* msg) { + jniThrowException(env, "java/lang/IllegalArgumentException", msg); +} + template<class JArray, class T> class ArrayHelper { public: @@ -178,16 +180,16 @@ public: bool check() { if ( ! mRef) { - mEnv->ThrowNew(gIAEClass, "array == null"); + doThrowIAE(mEnv, "array == null"); return false; } if ( mOffset < 0) { - mEnv->ThrowNew(gIAEClass, "offset < 0"); + doThrowIAE(mEnv, "offset < 0"); return false; } mLength = mEnv->GetArrayLength(mRef) - mOffset; if (mLength < mMinSize ) { - mEnv->ThrowNew(gIAEClass, "length - offset < n"); + doThrowIAE(mEnv, "length - offset < n"); return false; } return true; @@ -245,7 +247,7 @@ void util_computeBoundingSphere(JNIEnv *env, jclass clazz, sphere.bind(); if ( positionsCount < 1 ) { - env->ThrowNew(gIAEClass, "positionsCount < 1"); + doThrowIAE(env, "positionsCount < 1"); return; } @@ -450,8 +452,7 @@ int util_visibilityTest(JNIEnv *env, jclass clazz, } if (indices.mLength < indexCount) { - env->ThrowNew(gIAEClass, "length < offset + indexCount"); - // Return value will be ignored, because an exception has been thrown. + doThrowIAE(env, "length < offset + indexCount"); return -1; } @@ -784,11 +785,11 @@ public: if (mBuffer) { mData = getPointer(mEnv, mBuffer, &mRemaining); if (mData == NULL) { - mEnv->ThrowNew(gIAEClass, errorMessage); + doThrowIAE(mEnv, errorMessage); } return mData != NULL; } else { - mEnv->ThrowNew(gIAEClass, errorMessage); + doThrowIAE(mEnv, errorMessage); return false; } } @@ -824,16 +825,16 @@ private: static void etc1_encodeBlock(JNIEnv *env, jclass clazz, jobject in, jint validPixelMask, jobject out) { if (validPixelMask < 0 || validPixelMask > 15) { - env->ThrowNew(gIAEClass, "validPixelMask"); + doThrowIAE(env, "validPixelMask"); return; } BufferHelper inB(env, in); BufferHelper outB(env, out); if (inB.checkPointer("in") && outB.checkPointer("out")) { if (inB.remaining() < ETC1_DECODED_BLOCK_SIZE) { - env->ThrowNew(gIAEClass, "in's remaining data < DECODED_BLOCK_SIZE"); + doThrowIAE(env, "in's remaining data < DECODED_BLOCK_SIZE"); } else if (outB.remaining() < ETC1_ENCODED_BLOCK_SIZE) { - env->ThrowNew(gIAEClass, "out's remaining data < ENCODED_BLOCK_SIZE"); + doThrowIAE(env, "out's remaining data < ENCODED_BLOCK_SIZE"); } else { etc1_encode_block((etc1_byte*) inB.getData(), validPixelMask, (etc1_byte*) outB.getData()); @@ -856,9 +857,9 @@ static void etc1_decodeBlock(JNIEnv *env, jclass clazz, BufferHelper outB(env, out); if (inB.checkPointer("in") && outB.checkPointer("out")) { if (inB.remaining() < ETC1_ENCODED_BLOCK_SIZE) { - env->ThrowNew(gIAEClass, "in's remaining data < ENCODED_BLOCK_SIZE"); + doThrowIAE(env, "in's remaining data < ENCODED_BLOCK_SIZE"); } else if (outB.remaining() < ETC1_DECODED_BLOCK_SIZE) { - env->ThrowNew(gIAEClass, "out's remaining data < DECODED_BLOCK_SIZE"); + doThrowIAE(env, "out's remaining data < DECODED_BLOCK_SIZE"); } else { etc1_decode_block((etc1_byte*) inB.getData(), (etc1_byte*) outB.getData()); @@ -884,7 +885,7 @@ static void etc1_encodeImage(JNIEnv *env, jclass clazz, jobject in, jint width, jint height, jint pixelSize, jint stride, jobject out) { if (pixelSize < 2 || pixelSize > 3) { - env->ThrowNew(gIAEClass, "pixelSize must be 2 or 3"); + doThrowIAE(env, "pixelSize must be 2 or 3"); return; } BufferHelper inB(env, in); @@ -893,9 +894,9 @@ static void etc1_encodeImage(JNIEnv *env, jclass clazz, jint imageSize = stride * height; jint encodedImageSize = etc1_get_encoded_data_size(width, height); if (inB.remaining() < imageSize) { - env->ThrowNew(gIAEClass, "in's remaining data < image size"); + doThrowIAE(env, "in's remaining data < image size"); } else if (outB.remaining() < encodedImageSize) { - env->ThrowNew(gIAEClass, "out's remaining data < encoded image size"); + doThrowIAE(env, "out's remaining data < encoded image size"); } else { int result = etc1_encode_image((etc1_byte*) inB.getData(), width, height, pixelSize, @@ -917,7 +918,7 @@ static void etc1_decodeImage(JNIEnv *env, jclass clazz, jint width, jint height, jint pixelSize, jint stride) { if (pixelSize < 2 || pixelSize > 3) { - env->ThrowNew(gIAEClass, "pixelSize must be 2 or 3"); + doThrowIAE(env, "pixelSize must be 2 or 3"); return; } BufferHelper inB(env, in); @@ -926,9 +927,9 @@ static void etc1_decodeImage(JNIEnv *env, jclass clazz, jint imageSize = stride * height; jint encodedImageSize = etc1_get_encoded_data_size(width, height); if (inB.remaining() < encodedImageSize) { - env->ThrowNew(gIAEClass, "in's remaining data < encoded image size"); + doThrowIAE(env, "in's remaining data < encoded image size"); } else if (outB.remaining() < imageSize) { - env->ThrowNew(gIAEClass, "out's remaining data < image size"); + doThrowIAE(env, "out's remaining data < image size"); } else { int result = etc1_decode_image((etc1_byte*) inB.getData(), (etc1_byte*) outB.getData(), @@ -946,7 +947,7 @@ static void etc1_formatHeader(JNIEnv *env, jclass clazz, BufferHelper headerB(env, header); if (headerB.checkPointer("header") ){ if (headerB.remaining() < ETC_PKM_HEADER_SIZE) { - env->ThrowNew(gIAEClass, "header's remaining data < ETC_PKM_HEADER_SIZE"); + doThrowIAE(env, "header's remaining data < ETC_PKM_HEADER_SIZE"); } else { etc1_pkm_format_header((etc1_byte*) headerB.getData(), width, height); } @@ -962,7 +963,7 @@ static jboolean etc1_isValid(JNIEnv *env, jclass clazz, BufferHelper headerB(env, header); if (headerB.checkPointer("header") ){ if (headerB.remaining() < ETC_PKM_HEADER_SIZE) { - env->ThrowNew(gIAEClass, "header's remaining data < ETC_PKM_HEADER_SIZE"); + doThrowIAE(env, "header's remaining data < ETC_PKM_HEADER_SIZE"); } else { result = etc1_pkm_is_valid((etc1_byte*) headerB.getData()); } @@ -979,7 +980,7 @@ static jint etc1_getWidth(JNIEnv *env, jclass clazz, BufferHelper headerB(env, header); if (headerB.checkPointer("header") ){ if (headerB.remaining() < ETC_PKM_HEADER_SIZE) { - env->ThrowNew(gIAEClass, "header's remaining data < ETC_PKM_HEADER_SIZE"); + doThrowIAE(env, "header's remaining data < ETC_PKM_HEADER_SIZE"); } else { result = etc1_pkm_get_width((etc1_byte*) headerB.getData()); } @@ -996,7 +997,7 @@ static int etc1_getHeight(JNIEnv *env, jclass clazz, BufferHelper headerB(env, header); if (headerB.checkPointer("header") ){ if (headerB.remaining() < ETC_PKM_HEADER_SIZE) { - env->ThrowNew(gIAEClass, "header's remaining data < ETC_PKM_HEADER_SIZE"); + doThrowIAE(env, "header's remaining data < ETC_PKM_HEADER_SIZE"); } else { result = etc1_pkm_get_height((etc1_byte*) headerB.getData()); } @@ -1008,22 +1009,12 @@ static int etc1_getHeight(JNIEnv *env, jclass clazz, * JNI registration */ -static void -lookupClasses(JNIEnv* env) { - gIAEClass = (jclass) env->NewGlobalRef( - env->FindClass("java/lang/IllegalArgumentException")); - gUOEClass = (jclass) env->NewGlobalRef( - env->FindClass("java/lang/UnsupportedOperationException")); - gAIOOBEClass = (jclass) env->NewGlobalRef( - env->FindClass("java/lang/ArrayIndexOutOfBoundsException")); -} - static JNINativeMethod gMatrixMethods[] = { { "multiplyMM", "([FI[FI[FI)V", (void*)util_multiplyMM }, { "multiplyMV", "([FI[FI[FI)V", (void*)util_multiplyMV }, }; -static JNINativeMethod gVisiblityMethods[] = { +static JNINativeMethod gVisibilityMethods[] = { { "computeBoundingSphere", "([FII[FI)V", (void*)util_computeBoundingSphere }, { "frustumCullSpheres", "([FI[FII[III)I", (void*)util_frustumCullSpheres }, { "visibilityTest", "([FI[FI[CII)I", (void*)util_visibilityTest }, @@ -1056,15 +1047,14 @@ typedef struct _ClassRegistrationInfo { } ClassRegistrationInfo; static ClassRegistrationInfo gClasses[] = { - {"android/opengl/Matrix", gMatrixMethods, NELEM(gMatrixMethods)}, - {"android/opengl/Visibility", gVisiblityMethods, NELEM(gVisiblityMethods)}, - {"android/opengl/GLUtils", gUtilsMethods, NELEM(gUtilsMethods)}, - {"android/opengl/ETC1", gEtc1Methods, NELEM(gEtc1Methods)}, + {"android/opengl/Matrix", gMatrixMethods, NELEM(gMatrixMethods)}, + {"android/opengl/Visibility", gVisibilityMethods, NELEM(gVisibilityMethods)}, + {"android/opengl/GLUtils", gUtilsMethods, NELEM(gUtilsMethods)}, + {"android/opengl/ETC1", gEtc1Methods, NELEM(gEtc1Methods)}, }; int register_android_opengl_classes(JNIEnv* env) { - lookupClasses(env); nativeClassInitBuffer(env); int result = 0; for (int i = 0; i < NELEM(gClasses); i++) { @@ -1080,4 +1070,3 @@ int register_android_opengl_classes(JNIEnv* env) } } // namespace android - |