JNIEXPORT jstring JNICALL Java_org_lwjgl_opengl_LinuxDisplay_getErrorText(JNIEnv *env, jclass unused, jlong display_ptr, jlong error_code) {
	Display *disp = (Display *)(intptr_t)display_ptr;
	char err_msg_buffer[ERR_MSG_SIZE];
	XGetErrorText(disp, error_code, err_msg_buffer, ERR_MSG_SIZE);
	err_msg_buffer[ERR_MSG_SIZE - 1] = '\0';
	return NewStringNativeWithLength(env, err_msg_buffer, strlen(err_msg_buffer));
}
/*
 * Return a string containing the queried value, or NULL of the method fails.
 * In that case, a java exception is thrown.
 */
static jstring queryRegistrationKey(JNIEnv *env, HKEY root_key, LPCTSTR subkey, LPCTSTR value) {
	DWORD buf_size = 1;
	char *result;
	HKEY hKey;
	LONG lRet;
	jstring java_result;


	if(RegOpenKeyEx(root_key,
		TEXT(subkey),
		0,
		KEY_QUERY_VALUE,
		&hKey) != ERROR_SUCCESS) {
		throwException(env, "Failed to open registry key");
		return NULL;
	}

	result = (char *)malloc(buf_size);
	if (result == NULL) {
		RegCloseKey(hKey);
		throwException(env, "Failed to allocate buffer");
		return NULL;
	}

	while (1) {
		lRet = RegQueryValueEx(hKey,
						TEXT(value),
						NULL,
						NULL,
						(LPBYTE)result,
						&buf_size);
		if (lRet != ERROR_SUCCESS && lRet != ERROR_MORE_DATA) {
			RegCloseKey(hKey);
			free(result);
			throwException(env, "Failed query key value");
			return NULL;
		}
		if (lRet == ERROR_SUCCESS) {
			RegCloseKey(hKey);
			// make sure the result has a terminating null
			buf_size += 1;
			result = (char *)realloc(result, buf_size);
			if (result == NULL) {
				throwException(env, "Failed to resize buffer");
				return NULL;
			}
			result[buf_size - 1] = '\0';
			java_result = NewStringNativeWithLength(env, result, (jsize)strlen(result));
			free(result);
			return java_result;
		}
		result = (char *)realloc(result, buf_size);
		if (result == NULL) {
			RegCloseKey(hKey);
			throwException(env, "Failed to resize buffer");
			return NULL;
		}
	}
}
JNIEXPORT jstring JNICALL Java_org_lwjgl_opengles_EGL_neglQueryString(JNIEnv *env, jclass clazz, jlong dpy_ptr, jint name) {
    EGLDisplay dpy = (EGLDisplay)(intptr_t)dpy_ptr;
    const char * __result = eglQueryString(dpy, name);
   	if ( __result == NULL )
   		return NULL;

   	return NewStringNativeWithLength(env, __result, strlen(__result));
}
static void CL_CALLBACK printfCallback(cl_context context, cl_uint printf_data_len, char *printf_data_ptr, void *user_data) {
    JNIEnv *env = attachCurrentThread();

	if ( env != NULL && !(*env)->ExceptionOccurred(env) && printfCallbackJ != NULL ) {
        (*env)->CallVoidMethod(env, (jobject)user_data, printfCallbackJ,
            NewStringNativeWithLength(env, printf_data_ptr, printf_data_len)
        );
    }

    detachCurrentThread();
}
static void APIENTRY debugOutputCallbackAMD(GLuint id, GLenum category, GLenum severity, GLsizei length, const GLchar* message, GLvoid* userParam) {
    JNIEnv *env = attachCurrentThread();

    if ( env != NULL && !(*env)->ExceptionOccurred(env) && debugOutputCallbackAMDJ != NULL ) {
        (*env)->CallVoidMethod(env, (jobject)userParam, debugOutputCallbackAMDJ,
                               (jint)id,
                               (jint)category,
                               (jint)severity,
                               NewStringNativeWithLength(env, message, length)
                              );
    }

    detachCurrentThread();
}
static void CL_CALLBACK contextCallback(const char *errinfo, const void *private_info, size_t cb, void *user_data) {
    JNIEnv *env = attachCurrentThread();
    jobject private_info_buffer = NULL;

	if ( env != NULL && !(*env)->ExceptionOccurred(env) && contextCallbackJ != NULL ) {
        if ( private_info != NULL )
            private_info_buffer = NewReadOnlyDirectByteBuffer(env, private_info, cb);

        (*env)->CallVoidMethod(env, (jobject)user_data, contextCallbackJ,
            NewStringNativeWithLength(env, errinfo, (jsize)strlen(errinfo)),
            private_info_buffer
        );
    }

    detachCurrentThread();
}
Exemple #7
0
JNIEXPORT jstring JNICALL Java_org_lwjgl_WindowsSysImplementation_nGetClipboard
  (JNIEnv * env, jclass unused)
{
	// Check to see if there's text available in the clipboard
	BOOL textAvailable = IsClipboardFormatAvailable(CF_TEXT);
	BOOL unicodeAvailable = IsClipboardFormatAvailable(CF_UNICODETEXT);
	void *clipboard_data;
	jstring ret;
	HANDLE hglb;
	const wchar_t * str;

	if (unicodeAvailable) {
		if (!OpenClipboard(NULL))
			return NULL;
		hglb = GetClipboardData(CF_UNICODETEXT);
		if (hglb == NULL) {
			CloseClipboard();
			return NULL;
		}
		clipboard_data = GlobalLock(hglb);
		if (clipboard_data == NULL) {
			CloseClipboard();
			return NULL;
		}
		str = (const wchar_t *)clipboard_data;
		ret = (*env)->NewString(env, str, wcslen(str));
	} else if (textAvailable) {
		if (!OpenClipboard(NULL))
			return NULL;
		hglb = GetClipboardData(CF_TEXT);
		if (hglb == NULL) {
			CloseClipboard();
			return NULL;
		}
		clipboard_data = GlobalLock(hglb);
		if (clipboard_data == NULL) {
			CloseClipboard();
			return NULL;
		}
		ret = NewStringNativeWithLength(env, (const char *) clipboard_data, strlen(clipboard_data));
	} else {
		return NULL;
	}
	GlobalUnlock(hglb);
	CloseClipboard();
	return ret;
}
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
                );
			}
		}
	}
}