summaryrefslogtreecommitdiffstats
path: root/core/jni/android
diff options
context:
space:
mode:
authorHiroshi Yamauchi <yamauchi@google.com>2015-05-07 19:14:17 -0700
committerHiroshi Yamauchi <yamauchi@google.com>2015-05-12 14:24:09 -0700
commit5b406cb7b548443b589f0acb235c8a7465ffb82b (patch)
tree5a43219d20660adf29b5ec18127d0cff601e2079 /core/jni/android
parentd74c31e253b1fdcfc62bf6343ac85b6bd5f08243 (diff)
downloadframeworks_base-5b406cb7b548443b589f0acb235c8a7465ffb82b.zip
frameworks_base-5b406cb7b548443b589f0acb235c8a7465ffb82b.tar.gz
frameworks_base-5b406cb7b548443b589f0acb235c8a7465ffb82b.tar.bz2
Replace JNI primitive array critical calls with non-critical ones.
The files generated by glgen + manually edited util.cpp. Bug: 19235243 Change-Id: Id48d39bafc21c27fbf667ed0f4e082dda3a37be3
Diffstat (limited to 'core/jni/android')
-rw-r--r--core/jni/android/opengl/util.cpp112
1 files changed, 105 insertions, 7 deletions
diff --git a/core/jni/android/opengl/util.cpp b/core/jni/android/opengl/util.cpp
index bce2b33..40029bb 100644
--- a/core/jni/android/opengl/util.cpp
+++ b/core/jni/android/opengl/util.cpp
@@ -150,7 +150,105 @@ int visibilityTest(float* pWS, float* pPositions, int positionsLength,
return result;
}
-template<class JArray, class T>
+class ByteArrayGetter {
+public:
+ static void* Get(JNIEnv* _env, jbyteArray array, jboolean* is_copy) {
+ return _env->GetByteArrayElements(array, is_copy);
+ }
+};
+class BooleanArrayGetter {
+public:
+ static void* Get(JNIEnv* _env, jbooleanArray array, jboolean* is_copy) {
+ return _env->GetBooleanArrayElements(array, is_copy);
+ }
+};
+class CharArrayGetter {
+public:
+ static void* Get(JNIEnv* _env, jcharArray array, jboolean* is_copy) {
+ return _env->GetCharArrayElements(array, is_copy);
+ }
+};
+class ShortArrayGetter {
+public:
+ static void* Get(JNIEnv* _env, jshortArray array, jboolean* is_copy) {
+ return _env->GetShortArrayElements(array, is_copy);
+ }
+};
+class IntArrayGetter {
+public:
+ static void* Get(JNIEnv* _env, jintArray array, jboolean* is_copy) {
+ return _env->GetIntArrayElements(array, is_copy);
+ }
+};
+class LongArrayGetter {
+public:
+ static void* Get(JNIEnv* _env, jlongArray array, jboolean* is_copy) {
+ return _env->GetLongArrayElements(array, is_copy);
+ }
+};
+class FloatArrayGetter {
+public:
+ static void* Get(JNIEnv* _env, jfloatArray array, jboolean* is_copy) {
+ return _env->GetFloatArrayElements(array, is_copy);
+ }
+};
+class DoubleArrayGetter {
+public:
+ static void* Get(JNIEnv* _env, jdoubleArray array, jboolean* is_copy) {
+ return _env->GetDoubleArrayElements(array, is_copy);
+ }
+};
+
+class ByteArrayReleaser {
+public:
+ static void Release(JNIEnv* _env, jbyteArray array, jbyte* data, jint mode) {
+ _env->ReleaseByteArrayElements(array, data, mode);
+ }
+};
+class BooleanArrayReleaser {
+public:
+ static void Release(JNIEnv* _env, jbooleanArray array, jboolean* data, jint mode) {
+ _env->ReleaseBooleanArrayElements(array, data, mode);
+ }
+};
+class CharArrayReleaser {
+public:
+ static void Release(JNIEnv* _env, jcharArray array, jchar* data, jint mode) {
+ _env->ReleaseCharArrayElements(array, data, mode);
+ }
+};
+class ShortArrayReleaser {
+public:
+ static void Release(JNIEnv* _env, jshortArray array, jshort* data, jint mode) {
+ _env->ReleaseShortArrayElements(array, data, mode);
+ }
+};
+class IntArrayReleaser {
+public:
+ static void Release(JNIEnv* _env, jintArray array, jint* data, jint mode) {
+ _env->ReleaseIntArrayElements(array, data, mode);
+ }
+};
+class LongArrayReleaser {
+public:
+ static void Release(JNIEnv* _env, jlongArray array, jlong* data, jint mode) {
+ _env->ReleaseLongArrayElements(array, data, mode);
+ }
+};
+class FloatArrayReleaser {
+public:
+ static void Release(JNIEnv* _env, jfloatArray array, jfloat* data, jint mode) {
+ _env->ReleaseFloatArrayElements(array, data, mode);
+ }
+};
+class DoubleArrayReleaser {
+public:
+ static void Release(JNIEnv* _env, jdoubleArray array, jdouble* data, jint mode) {
+ _env->ReleaseDoubleArrayElements(array, data, mode);
+ }
+};
+
+template<class JArray, class T, class ArrayGetter, class ArrayReleaser>
class ArrayHelper {
public:
ArrayHelper(JNIEnv* env, JArray ref, jint offset, jint minSize) {
@@ -164,7 +262,7 @@ public:
~ArrayHelper() {
if (mBase) {
- mEnv->ReleasePrimitiveArrayCritical(mRef, mBase, mReleaseParam);
+ ArrayReleaser::Release(mEnv, mRef, mBase, mReleaseParam);
}
}
@@ -195,7 +293,7 @@ public:
// Bind the array.
void bind() {
- mBase = (T*) mEnv->GetPrimitiveArrayCritical(mRef, (jboolean *) 0);
+ mBase = (T*) ArrayGetter::Get(mEnv, mRef, (jboolean *) 0);
mData = mBase + mOffset;
}
@@ -215,10 +313,10 @@ private:
int mReleaseParam;
};
-typedef ArrayHelper<jfloatArray, float> FloatArrayHelper;
-typedef ArrayHelper<jcharArray, unsigned short> UnsignedShortArrayHelper;
-typedef ArrayHelper<jintArray, int> IntArrayHelper;
-typedef ArrayHelper<jbyteArray, unsigned char> ByteArrayHelper;
+typedef ArrayHelper<jfloatArray, float, FloatArrayGetter, FloatArrayReleaser> FloatArrayHelper;
+typedef ArrayHelper<jcharArray, unsigned short, CharArrayGetter, CharArrayReleaser> UnsignedShortArrayHelper;
+typedef ArrayHelper<jintArray, int, IntArrayGetter, IntArrayReleaser> IntArrayHelper;
+typedef ArrayHelper<jbyteArray, unsigned char, ByteArrayGetter, ByteArrayReleaser> ByteArrayHelper;
inline float distance2(float x, float y, float z) {
return x * x + y * y + z * z;