Exemple #1
0
static void invokeJavaCallback(jmethodID method, ...) {
	JNIEnv *env = getThreadEnv();
	va_list args;
	va_start(args, method);
	(*env)->CallStaticVoidMethodV(env, nativeGamepadClass, method, args);
	va_end(args);
}
static void CL_CALLBACK CLContextCallbackFunction(
	const char *errinfo,
	const void *private_info,
	size_t cb,
	void *user_data
) {
	jobject callback;

	JNIEnv *env = getThreadEnv();
	jboolean async = env == NULL;
	if ( async ) {
        env = attachCurrentThread();
        if ( env == NULL )
            return;
	}

	// user_data is a weak global reference
	callback = (*env)->NewLocalRef(env, (jweak)user_data);
	if ( callback != NULL ) {
	    (*env)->CallVoidMethod(env, callback, CLContextCallbackMethod,
	        (jlong)(intptr_t)errinfo,
	        (jlong)(intptr_t)private_info,
	        (jlong)cb
	    );
	    (*env)->DeleteLocalRef(env, callback);
    }

	if ( async )
        detachCurrentThread();
}
Exemple #3
0
	JNIEnv* envTLSGet(void) {
		JNIEnv* env = getThreadEnv();
    	if ( env == NULL )
            env = attachCurrentThreadAsDaemon();

    	pthread_setspecific(envTLS, env);
    	return env;
	}
Exemple #4
0
	JNIEnv* envTLSGet(void) {
		JNIEnv* env = getThreadEnv();
    	if ( env == NULL )
    	    env = attachCurrentThreadAsDaemon();

		TlsSetValue(envTLS, (LPVOID)env);
		return env;
	}
static int global_error_handler(Display *disp, XErrorEvent *error) {
	JNIEnv *env = getThreadEnv();
	if (env != NULL) {
		jclass org_lwjgl_LinuxDisplay_class = (*env)->FindClass(env, "org/lwjgl/opengl/LinuxDisplay");
		if (org_lwjgl_LinuxDisplay_class == NULL) {
			// Don't propagate error
			(*env)->ExceptionClear(env);
			return 0;
		}
		jmethodID handler_method = (*env)->GetStaticMethodID(env, org_lwjgl_LinuxDisplay_class, "globalErrorHandler", "(JJJJJJJ)I");
		if (handler_method == NULL)
			return 0;
		return (*env)->CallStaticIntMethod(env, org_lwjgl_LinuxDisplay_class, handler_method, (jlong)(intptr_t)disp, (jlong)(intptr_t)error,
				(jlong)(intptr_t)error->display, (jlong)error->serial, (jlong)error->error_code, (jlong)error->request_code, (jlong)error->minor_code);
	} else
		return 0;
}
/*
 *	WindowProc for the GL window.
 */
static LRESULT CALLBACK lwjglWindowProc(HWND hWnd,
							     UINT msg,
							     WPARAM wParam,
							     LPARAM lParam)
{
	jclass display_class;
	jclass display_class_global;
	jmethodID handleMessage_method;
	LONG message_time;
	JNIEnv *env = getThreadEnv();
	if (env != NULL && !(*env)->ExceptionOccurred(env)) {
		/*
		 * We'll cache a global reference to the WindowsDisplay class in the window's user data.
		 * This is not so much to avoid lookup overhead as it is to avoid problems
		 * with AWT. Specifically, awt code can indirectly call this message handler
		 * when it does a SendMessage on the main thread to the currently focused window,
		 * which could be a LWJGL window. The FindClass will then fail because the calling
		 * internal awt class is using the system class loader, not the application loader
		 * where lwjgl is found.
		 *
		 * The very first message sent to this handler is sent when
		 * a window is created, where we are sure that the calling class' classloader has
		 * LWJGL classes in it.
		 */
		display_class_global = (jclass)(LONG_PTR)GetWindowLongPtr(hWnd, GWLP_USERDATA);
		if (display_class_global == NULL) {
			display_class = (*env)->FindClass(env, "org/lwjgl/opengl/WindowsDisplay");
			if (display_class != NULL) {
				display_class_global = (*env)->NewGlobalRef(env, display_class);
				if (display_class_global != NULL)
					SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)display_class_global);
			}
		}
		if (display_class_global != NULL) {
			message_time = GetMessageTime();
			handleMessage_method = (*env)->GetStaticMethodID(env, display_class_global, "handleMessage", "(JIJJJ)I");
			if (handleMessage_method != NULL)
				return (*env)->CallStaticIntMethod(env, display_class_global, handleMessage_method, (jlong)(intptr_t)hWnd, (jint)msg, (jlong)wParam, (jlong)lParam, (jlong)message_time);
		}
	}
	return DefWindowProc(hWnd, msg, wParam, lParam);
}
static void APIENTRY debugOutputCallback(GLuint id, GLenum category, GLenum severity, GLsizei length, const GLchar* message, GLvoid* userParam) {
    jclass callback_class;
	jmethodID callback_method;
	JNIEnv *env = getThreadEnv();
	if (env != NULL && !(*env)->ExceptionOccurred(env)) {
		callback_class = (*env)->FindClass(env, "org/lwjgl/opengl/AMDDebugOutputUtil");
		if ( callback_class != NULL ) {
			callback_method = (*env)->GetStaticMethodID(env, callback_class, "messageCallback", "(IIILjava/lang/String;Ljava/nio/ByteBuffer;)V");
			if ( callback_method != NULL ) {
				(*env)->CallStaticVoidMethod(env, callback_class, callback_method,
                            (jint)id,
				            (jint)category,
				            (jint)severity,
                            NewStringNativeWithLength(env, message, length),
				            NULL
                );
			}
		}
	}
}
static void APIENTRY DEBUGPROCAMDFunction(GLuint id, GLenum category, GLenum severity, GLsizei length, const GLchar* message, GLvoid* userParam) {
	JNIEnv *env = (getThreadEnv());
	jboolean async = (env == NULL);
	if ( async ) {
        env = attachCurrentThread();
        if ( env == NULL )
            return;
	}

    (*env)->CallVoidMethod(env, (jobject)userParam, DEBUGPROCAMDMethod,
        (jint)id,
        (jint)category,
        (jint)severity,
        (jint)length,
        (jlong)(intptr_t)message
    );

	if ( async )
        detachCurrentThread();
}