[英]Why does my call to an EGL function change when running it in Java code through JNI?
I am doing some work in opengl and java/android. 我正在opengl和java / android中做一些工作。 I have some code in c++ and am using JNI to interface between the two.
我在c ++中有一些代码,并且正在使用JNI在两者之间进行接口。 I get the results:
我得到结果:
D/App ( 2966): eglGetCurrentDisplay() 1
D/App ( 2966): thread id from c++ 2920
D/dalvikvm( 2966): threadid=11: interp stack at 0x613c5000
D/dalvikvm( 2966): init ref table
D/dalvikvm( 2966): init mutex
D/dalvikvm( 2966): create JNI env
D/dalvikvm( 2966): create fake frame
D/dalvikvm( 2966): threadid=11: adding to list (attached)
D/dalvikvm( 2966): threadid=11: attached from native, name=(null)
D/App ( 2966): thread id 2920
D/App ( 2966): EGL.eglGetCurrentDisplay is com.google.android.gles_jni.EGLDisplayImpl@0
From the code below. 从下面的代码。 Which means the current display is changing when I go into JNI.
这意味着当我进入JNI时,当前显示正在改变。 Why does this happen?
为什么会这样? The thread is not changing and I believe thread local storage is where the driver will store this information.
线程没有改变,我相信驱动程序将在此存储线程本地存储信息。
c++ code: C ++代码:
printf("eglGetCurrentDisplay() %x\n", eglGetCurrentDisplay());
printf("thread id from c++ %d\n", (int)gettid());
int ret = Call_Java<int>("JNITest", "(I)I", 0 );
template<typename T>
T Call_Java(const char* sMethodName, const char* sMethodArgs, ...)
{
JavaVM *g_javaVMcached;
va_list argp;
jint res;
jobject obj;
getJavaCache(&obj, &g_javaVMcached);
assert(obj != 0);
JNIEnv * env = 0;
res = g_javaVMcached->AttachCurrentThread( &env, 0 );
assert( res == 0 && env != 0 )
jclass clazz = 0;
clazz = env->GetObjectClass( obj );
assert( clazz != 0 )
jmethodID methodID = env->GetMethodID( clazz, sMethodName, sMethodArgs ); // Name + Args
assert( methodID != 0 )
va_start(argp, sMethodArgs);
T result=0;
result = callJNIMethod<T>(obj, env, methodID, argp);
va_end(argp);
env->DeleteLocalRef( clazz );
return result;
}
template <>
int callJNIMethod(const jobject & obj, JNIEnv *env, jmethodID methodID, va_list args)
{
return env->CallIntMethodV(obj, methodID, args);
}
Java code: Java代码:
int JNITest(int test)
{
Log.d(TAG, "thread id " + (int)android.os.Process.myTid());
EGLDisplay disp = EGL.eglGetCurrentDisplay();
Log.d(TAG, "EGL.eglGetCurrentDisplay is " + disp);
return 0;
}
In C++ code, the EGL display is a simple integer. 在C ++代码中,EGL显示是一个简单的整数。 In Java code, the EGL display is an object.
在Java代码中,EGL显示是一个对象。 These happen to print differently.
这些碰巧以不同的方式打印。
Android currently only defines the default display. Android当前仅定义默认显示。
Aha! 啊哈! So I found the reason for this: I was linking against the EGL libraries in /vendor/lib/ instead of the libraries in /system/lib/.
因此,我找到了原因:我链接到/ vendor / lib /中的EGL库,而不是/ system / lib /中的库。
The indicator for this was that when I called eglInitialize() I was NOT getting the following log output: 对此的指示是,当我调用eglInitialize()时,没有得到以下日志输出:
D/libEGL ( 4599): loaded /vendor/lib/egl/libEGL...
D/libEGL ( 4599): loaded /vendor/lib/egl/libGLESv1...
D/libEGL ( 4599): loaded /vendor/lib/egl/libGLESv2...
Whereas a working version should have these lines in the log output. 而工作版本的日志输出中应包含这些行。 This now gives me a correct call to eglGetCurrentDisplay() that does not give EGL_NO_DISPLAY.
现在,这给了我对eglGetCurrentDisplay()的正确调用,但没有给出EGL_NO_DISPLAY。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.