Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5b406cb7 authored by Hiroshi Yamauchi's avatar Hiroshi Yamauchi
Browse files

Replace JNI primitive array critical calls with non-critical ones.

The files generated by glgen + manually edited util.cpp.

Bug: 19235243

Change-Id: Id48d39bafc21c27fbf667ed0f4e082dda3a37be3
parent d74c31e2
Loading
Loading
Loading
Loading
+105 −7
Original line number Diff line number Diff line
@@ -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;
+26 −27
Original line number Diff line number Diff line
@@ -204,7 +204,7 @@ android_eglInitialize
        goto exit;
    }
    major_base = (EGLint *)
        _env->GetPrimitiveArrayCritical(major_ref, (jboolean *)0);
        _env->GetIntArrayElements(major_ref, (jboolean *)0);
    major = major_base + majorOffset;

    if (!minor_ref) {
@@ -227,7 +227,7 @@ android_eglInitialize
        goto exit;
    }
    minor_base = (EGLint *)
        _env->GetPrimitiveArrayCritical(minor_ref, (jboolean *)0);
        _env->GetIntArrayElements(minor_ref, (jboolean *)0);
    minor = minor_base + minorOffset;

    _returnValue = eglInitialize(
@@ -238,11 +238,11 @@ android_eglInitialize

exit:
    if (minor_base) {
        _env->ReleasePrimitiveArrayCritical(minor_ref, minor_base,
        _env->ReleaseIntArrayElements(minor_ref, (jint*)minor_base,
            _exception ? JNI_ABORT: 0);
    }
    if (major_base) {
        _env->ReleasePrimitiveArrayCritical(major_ref, major_base,
        _env->ReleaseIntArrayElements(major_ref, (jint*)major_base,
            _exception ? JNI_ABORT: 0);
    }
    if (_exception) {
@@ -324,7 +324,7 @@ android_eglGetConfigs
    }
    _num_configRemaining = _env->GetArrayLength(num_config_ref) - num_configOffset;
    num_config_base = (EGLint *)
        _env->GetPrimitiveArrayCritical(num_config_ref, (jboolean *)0);
        _env->GetIntArrayElements(num_config_ref, (jboolean *)0);
    num_config = num_config_base + num_configOffset;

    _returnValue = eglGetConfigs(
@@ -336,7 +336,7 @@ android_eglGetConfigs

exit:
    if (num_config_base) {
        _env->ReleasePrimitiveArrayCritical(num_config_ref, num_config_base,
        _env->ReleaseIntArrayElements(num_config_ref, (jint*)num_config_base,
            _exception ? JNI_ABORT: 0);
    }
    if (configs) {
@@ -385,7 +385,7 @@ android_eglChooseConfig
    }
    _attrib_listRemaining = _env->GetArrayLength(attrib_list_ref) - attrib_listOffset;
    attrib_list_base = (EGLint *)
        _env->GetPrimitiveArrayCritical(attrib_list_ref, (jboolean *)0);
        _env->GetIntArrayElements(attrib_list_ref, (jboolean *)0);
    attrib_list = attrib_list_base + attrib_listOffset;
    attrib_list_sentinel = false;
    for (int i = _attrib_listRemaining - 1; i >= 0; i--)  {
@@ -442,7 +442,7 @@ android_eglChooseConfig
        goto exit;
    }
    num_config_base = (EGLint *)
        _env->GetPrimitiveArrayCritical(num_config_ref, (jboolean *)0);
        _env->GetIntArrayElements(num_config_ref, (jboolean *)0);
    num_config = num_config_base + num_configOffset;

    _returnValue = eglChooseConfig(
@@ -455,11 +455,11 @@ android_eglChooseConfig

exit:
    if (num_config_base) {
        _env->ReleasePrimitiveArrayCritical(num_config_ref, num_config_base,
        _env->ReleaseIntArrayElements(num_config_ref, (jint*)num_config_base,
            _exception ? JNI_ABORT: 0);
    }
    if (attrib_list_base) {
        _env->ReleasePrimitiveArrayCritical(attrib_list_ref, attrib_list_base,
        _env->ReleaseIntArrayElements(attrib_list_ref, (jint*)attrib_list_base,
            JNI_ABORT);
    }
    if (configs) {
@@ -509,7 +509,7 @@ android_eglGetConfigAttrib
        goto exit;
    }
    value_base = (EGLint *)
        _env->GetPrimitiveArrayCritical(value_ref, (jboolean *)0);
        _env->GetIntArrayElements(value_ref, (jboolean *)0);
    value = value_base + offset;

    _returnValue = eglGetConfigAttrib(
@@ -521,7 +521,7 @@ android_eglGetConfigAttrib

exit:
    if (value_base) {
        _env->ReleasePrimitiveArrayCritical(value_ref, value_base,
        _env->ReleaseIntArrayElements(value_ref, (jint*)value_base,
            _exception ? JNI_ABORT: 0);
    }
    if (_exception) {
@@ -573,7 +573,7 @@ not_valid_surface:

    _remaining = _env->GetArrayLength(attrib_list_ref) - offset;
    attrib_list_base = (EGLint *)
        _env->GetPrimitiveArrayCritical(attrib_list_ref, (jboolean *)0);
        _env->GetIntArrayElements(attrib_list_ref, (jboolean *)0);
    attrib_list = attrib_list_base + offset;
    attrib_list_sentinel = 0;
    for (int i = _remaining - 1; i >= 0; i--)  {
@@ -598,7 +598,7 @@ not_valid_surface:

exit:
    if (attrib_list_base) {
        _env->ReleasePrimitiveArrayCritical(attrib_list_ref, attrib_list_base,
        _env->ReleaseIntArrayElements(attrib_list_ref, attrib_list_base,
            JNI_ABORT);
    }
    if (_exception) {
@@ -655,7 +655,7 @@ not_valid_surface:

    _remaining = _env->GetArrayLength(attrib_list_ref) - offset;
    attrib_list_base = (EGLint *)
        _env->GetPrimitiveArrayCritical(attrib_list_ref, (jboolean *)0);
        _env->GetIntArrayElements(attrib_list_ref, (jboolean *)0);
    attrib_list = attrib_list_base + offset;
    attrib_list_sentinel = 0;
    for (int i = _remaining - 1; i >= 0; i--)  {
@@ -680,7 +680,7 @@ not_valid_surface:

exit:
    if (attrib_list_base) {
        _env->ReleasePrimitiveArrayCritical(attrib_list_ref, attrib_list_base,
        _env->ReleaseIntArrayElements(attrib_list_ref, attrib_list_base,
            JNI_ABORT);
    }
    if (_exception) {
@@ -717,7 +717,7 @@ android_eglCreatePbufferSurface
    }
    _remaining = _env->GetArrayLength(attrib_list_ref) - offset;
    attrib_list_base = (EGLint *)
        _env->GetPrimitiveArrayCritical(attrib_list_ref, (jboolean *)0);
        _env->GetIntArrayElements(attrib_list_ref, (jboolean *)0);
    attrib_list = attrib_list_base + offset;
    attrib_list_sentinel = false;
    for (int i = _remaining - 1; i >= 0; i--)  {
@@ -741,7 +741,7 @@ android_eglCreatePbufferSurface

exit:
    if (attrib_list_base) {
        _env->ReleasePrimitiveArrayCritical(attrib_list_ref, attrib_list_base,
        _env->ReleaseIntArrayElements(attrib_list_ref, (jint*)attrib_list_base,
            JNI_ABORT);
    }
    if (_exception) {
@@ -808,7 +808,7 @@ android_eglQuerySurface
        goto exit;
    }
    value_base = (EGLint *)
        _env->GetPrimitiveArrayCritical(value_ref, (jboolean *)0);
        _env->GetIntArrayElements(value_ref, (jboolean *)0);
    value = value_base + offset;

    _returnValue = eglQuerySurface(
@@ -820,7 +820,7 @@ android_eglQuerySurface

exit:
    if (value_base) {
        _env->ReleasePrimitiveArrayCritical(value_ref, value_base,
        _env->ReleaseIntArrayElements(value_ref, (jint*)value_base,
            _exception ? JNI_ABORT: 0);
    }
    if (_exception) {
@@ -896,7 +896,7 @@ android_eglCreatePbufferFromClientBuffer
    }
    _remaining = _env->GetArrayLength(attrib_list_ref) - offset;
    attrib_list_base = (EGLint *)
        _env->GetPrimitiveArrayCritical(attrib_list_ref, (jboolean *)0);
        _env->GetIntArrayElements(attrib_list_ref, (jboolean *)0);
    attrib_list = attrib_list_base + offset;
    attrib_list_sentinel = false;
    for (int i = _remaining - 1; i >= 0; i--)  {
@@ -922,7 +922,7 @@ android_eglCreatePbufferFromClientBuffer

exit:
    if (attrib_list_base) {
        _env->ReleasePrimitiveArrayCritical(attrib_list_ref, attrib_list_base,
        _env->ReleaseIntArrayElements(attrib_list_ref, attrib_list_base,
            JNI_ABORT);
    }
    if (_exception) {
@@ -940,7 +940,6 @@ android_eglCreatePbufferFromClientBufferInt
    }
    return android_eglCreatePbufferFromClientBuffer(_env, _this, dpy, buftype, buffer, config, attrib_list_ref, offset);
}

/* EGLBoolean eglSurfaceAttrib ( EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value ) */
static jboolean
android_eglSurfaceAttrib
@@ -1034,7 +1033,7 @@ android_eglCreateContext
    }
    _remaining = _env->GetArrayLength(attrib_list_ref) - offset;
    attrib_list_base = (EGLint *)
        _env->GetPrimitiveArrayCritical(attrib_list_ref, (jboolean *)0);
        _env->GetIntArrayElements(attrib_list_ref, (jboolean *)0);
    attrib_list = attrib_list_base + offset;
    attrib_list_sentinel = false;
    for (int i = _remaining - 1; i >= 0; i--)  {
@@ -1059,7 +1058,7 @@ android_eglCreateContext

exit:
    if (attrib_list_base) {
        _env->ReleasePrimitiveArrayCritical(attrib_list_ref, attrib_list_base,
        _env->ReleaseIntArrayElements(attrib_list_ref, (jint*)attrib_list_base,
            JNI_ABORT);
    }
    if (_exception) {
@@ -1165,7 +1164,7 @@ android_eglQueryContext
        goto exit;
    }
    value_base = (EGLint *)
        _env->GetPrimitiveArrayCritical(value_ref, (jboolean *)0);
        _env->GetIntArrayElements(value_ref, (jboolean *)0);
    value = value_base + offset;

    _returnValue = eglQueryContext(
@@ -1177,7 +1176,7 @@ android_eglQueryContext

exit:
    if (value_base) {
        _env->ReleasePrimitiveArrayCritical(value_ref, value_base,
        _env->ReleaseIntArrayElements(value_ref, (jint*)value_base,
            _exception ? JNI_ABORT: 0);
    }
    if (_exception) {
Loading