Linux: More native code refactoring
This commit is contained in:
parent
7469d59dbf
commit
2bc0988c98
|
@ -95,7 +95,7 @@ final class LinuxDisplay implements DisplayImplementation {
|
||||||
if (isXF86VidModeSupported())
|
if (isXF86VidModeSupported())
|
||||||
return nGetCurrentGammaRamp();
|
return nGetCurrentGammaRamp();
|
||||||
else
|
else
|
||||||
return BufferUtils.createByteBuffer(0);
|
return null;
|
||||||
} finally {
|
} finally {
|
||||||
decDisplay();
|
decDisplay();
|
||||||
}
|
}
|
||||||
|
@ -105,12 +105,9 @@ final class LinuxDisplay implements DisplayImplementation {
|
||||||
}
|
}
|
||||||
private static native ByteBuffer nGetCurrentGammaRamp() throws LWJGLException;
|
private static native ByteBuffer nGetCurrentGammaRamp() throws LWJGLException;
|
||||||
|
|
||||||
private static int getBestDisplayModeExtension() throws LWJGLException {
|
private static int getBestDisplayModeExtension() {
|
||||||
lockAWT();
|
|
||||||
try {
|
|
||||||
incDisplay();
|
|
||||||
int result;
|
int result;
|
||||||
if (System.getenv("LWJGL_DISABLE_XRANDR") == null && isXrandrSupported()) {
|
if (isXrandrSupported()) {
|
||||||
LWJGLUtil.log("Using Xrandr for display mode switching");
|
LWJGLUtil.log("Using Xrandr for display mode switching");
|
||||||
result = XRANDR;
|
result = XRANDR;
|
||||||
} else if (isXF86VidModeSupported()) {
|
} else if (isXF86VidModeSupported()) {
|
||||||
|
@ -120,14 +117,46 @@ final class LinuxDisplay implements DisplayImplementation {
|
||||||
LWJGLUtil.log("No display mode extensions available");
|
LWJGLUtil.log("No display mode extensions available");
|
||||||
result = NONE;
|
result = NONE;
|
||||||
}
|
}
|
||||||
decDisplay();
|
|
||||||
return result;
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isXrandrSupported() {
|
||||||
|
if (System.getenv("LWJGL_DISABLE_XRANDR") != null)
|
||||||
|
return false;
|
||||||
|
lockAWT();
|
||||||
|
try {
|
||||||
|
incDisplay();
|
||||||
|
try {
|
||||||
|
return nIsXrandrSupported();
|
||||||
|
} finally {
|
||||||
|
decDisplay();
|
||||||
|
}
|
||||||
|
} catch (LWJGLException e) {
|
||||||
|
LWJGLUtil.log("Got exception while querying Xrandr support: " + e);
|
||||||
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
unlockAWT();
|
unlockAWT();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static native boolean isXrandrSupported();
|
private static native boolean nIsXrandrSupported() throws LWJGLException;
|
||||||
private static native boolean isXF86VidModeSupported();
|
|
||||||
|
private static boolean isXF86VidModeSupported() {
|
||||||
|
lockAWT();
|
||||||
|
try {
|
||||||
|
incDisplay();
|
||||||
|
try {
|
||||||
|
return nIsXF86VidModeSupported();
|
||||||
|
} finally {
|
||||||
|
decDisplay();
|
||||||
|
}
|
||||||
|
} catch (LWJGLException e) {
|
||||||
|
LWJGLUtil.log("Got exception while querying XF86VM support: " + e);
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
unlockAWT();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static native boolean nIsXF86VidModeSupported() throws LWJGLException;
|
||||||
|
|
||||||
private static boolean isNetWMFullscreenSupported() throws LWJGLException {
|
private static boolean isNetWMFullscreenSupported() throws LWJGLException {
|
||||||
if (System.getenv("LWJGL_DISABLE_NETWM") != null)
|
if (System.getenv("LWJGL_DISABLE_NETWM") != null)
|
||||||
|
@ -135,14 +164,19 @@ final class LinuxDisplay implements DisplayImplementation {
|
||||||
lockAWT();
|
lockAWT();
|
||||||
try {
|
try {
|
||||||
incDisplay();
|
incDisplay();
|
||||||
boolean supported = nIsNetWMFullscreenSupported();
|
try {
|
||||||
|
return nIsNetWMFullscreenSupported();
|
||||||
|
} finally {
|
||||||
decDisplay();
|
decDisplay();
|
||||||
return supported;
|
}
|
||||||
|
} catch (LWJGLException e) {
|
||||||
|
LWJGLUtil.log("Got exception while querying NetWM support: " + e);
|
||||||
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
unlockAWT();
|
unlockAWT();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static native boolean nIsNetWMFullscreenSupported();
|
private static native boolean nIsNetWMFullscreenSupported() throws LWJGLException;
|
||||||
|
|
||||||
/* Since Xlib is not guaranteed to be thread safe, we need a way to synchronize LWJGL
|
/* Since Xlib is not guaranteed to be thread safe, we need a way to synchronize LWJGL
|
||||||
* Xlib calls with AWT Xlib calls. Fortunately, JAWT implements Lock()/Unlock() to
|
* Xlib calls with AWT Xlib calls. Fortunately, JAWT implements Lock()/Unlock() to
|
||||||
|
@ -250,8 +284,8 @@ final class LinuxDisplay implements DisplayImplementation {
|
||||||
public void switchDisplayMode(DisplayMode mode) throws LWJGLException {
|
public void switchDisplayMode(DisplayMode mode) throws LWJGLException {
|
||||||
lockAWT();
|
lockAWT();
|
||||||
try {
|
try {
|
||||||
|
nSwitchDisplayMode(current_displaymode_extension, mode);
|
||||||
current_mode = mode;
|
current_mode = mode;
|
||||||
nSwitchDisplayMode(current_displaymode_extension, current_mode);
|
|
||||||
} finally {
|
} finally {
|
||||||
unlockAWT();
|
unlockAWT();
|
||||||
}
|
}
|
||||||
|
@ -261,27 +295,31 @@ final class LinuxDisplay implements DisplayImplementation {
|
||||||
public void resetDisplayMode() {
|
public void resetDisplayMode() {
|
||||||
lockAWT();
|
lockAWT();
|
||||||
try {
|
try {
|
||||||
nResetDisplayMode(current_displaymode_extension, saved_gamma, saved_mode);
|
switchDisplayMode(saved_mode);
|
||||||
|
if (isXF86VidModeSupported())
|
||||||
|
doSetGamma(saved_gamma);
|
||||||
} catch (LWJGLException e) {
|
} catch (LWJGLException e) {
|
||||||
LWJGLUtil.log("Caught exception while resetting mode: " + e);
|
LWJGLUtil.log("Caught exception while resetting mode: " + e);
|
||||||
} finally {
|
} finally {
|
||||||
unlockAWT();
|
unlockAWT();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static native void nResetDisplayMode(int extension, ByteBuffer gamma_ramp, DisplayMode saved_mode) throws LWJGLException;
|
|
||||||
|
|
||||||
public int getGammaRampLength() {
|
public int getGammaRampLength() {
|
||||||
|
if (!isXF86VidModeSupported())
|
||||||
|
return 0;
|
||||||
lockAWT();
|
lockAWT();
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
incDisplay();
|
incDisplay();
|
||||||
int length;
|
try {
|
||||||
if (isXF86VidModeSupported()) {
|
return nGetGammaRampLength();
|
||||||
length = nGetGammaRampLength();
|
} catch (LWJGLException e) {
|
||||||
} else
|
LWJGLUtil.log("Got exception while querying gamma length: " + e);
|
||||||
length = 0;
|
return 0;
|
||||||
|
} finally {
|
||||||
decDisplay();
|
decDisplay();
|
||||||
return length;
|
}
|
||||||
} catch (LWJGLException e) {
|
} catch (LWJGLException e) {
|
||||||
LWJGLUtil.log("Failed to get gamma ramp length: " + e);
|
LWJGLUtil.log("Failed to get gamma ramp length: " + e);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -290,18 +328,19 @@ final class LinuxDisplay implements DisplayImplementation {
|
||||||
unlockAWT();
|
unlockAWT();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static native int nGetGammaRampLength();
|
private static native int nGetGammaRampLength() throws LWJGLException;
|
||||||
|
|
||||||
public void setGammaRamp(FloatBuffer gammaRamp) throws LWJGLException {
|
public void setGammaRamp(FloatBuffer gammaRamp) throws LWJGLException {
|
||||||
|
if (!isXF86VidModeSupported())
|
||||||
|
throw new LWJGLException("No gamma ramp support (Missing XF86VM extension)");
|
||||||
|
doSetGamma(convertToNativeRamp(gammaRamp));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void doSetGamma(ByteBuffer native_gamma) throws LWJGLException {
|
||||||
lockAWT();
|
lockAWT();
|
||||||
try {
|
try {
|
||||||
incDisplay();
|
nSetGammaRamp(native_gamma);
|
||||||
boolean xf86_support = isXF86VidModeSupported();
|
current_gamma = native_gamma;
|
||||||
decDisplay();
|
|
||||||
if (!xf86_support)
|
|
||||||
throw new LWJGLException("No gamma ramp support (Missing XF86VM extension)");
|
|
||||||
current_gamma = convertToNativeRamp(gammaRamp);
|
|
||||||
nSetGammaRamp(current_gamma);
|
|
||||||
} finally {
|
} finally {
|
||||||
unlockAWT();
|
unlockAWT();
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,11 +68,11 @@ static bool getXF86VidModeVersion(JNIEnv *env, Display *disp, int *major, int *m
|
||||||
int event_base, error_base;
|
int event_base, error_base;
|
||||||
|
|
||||||
if (!XF86VidModeQueryExtension(disp, &event_base, &error_base)) {
|
if (!XF86VidModeQueryExtension(disp, &event_base, &error_base)) {
|
||||||
printfDebugJava(env, "XF86VidMode extension not available");
|
throwException(env, "XF86VidMode extension not available");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!XF86VidModeQueryVersion(disp, major, minor)) {
|
if (!XF86VidModeQueryVersion(disp, major, minor)) {
|
||||||
printfDebugJava(env, "Could not query XF86VidMode version");
|
throwException(env, "Could not query XF86VidMode version");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
printfDebugJava(env, "XF86VidMode extension version %i.%i", *major, *minor);
|
printfDebugJava(env, "XF86VidMode extension version %i.%i", *major, *minor);
|
||||||
|
@ -83,11 +83,11 @@ static bool getXrandrVersion(JNIEnv *env, Display *disp, int *major, int *minor)
|
||||||
int event_base, error_base;
|
int event_base, error_base;
|
||||||
|
|
||||||
if (!XRRQueryExtension(disp, &event_base, &error_base)) {
|
if (!XRRQueryExtension(disp, &event_base, &error_base)) {
|
||||||
printfDebugJava(env, "Xrandr extension not available");
|
throwException(env, "Xrandr extension not available");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!XRRQueryVersion(disp, major, minor)) {
|
if (!XRRQueryVersion(disp, major, minor)) {
|
||||||
printfDebugJava(env, "Could not query Xrandr version");
|
throwException(env, "Could not query Xrandr version");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
printfDebugJava(env, "Xrandr extension version %i.%i", *major, *minor);
|
printfDebugJava(env, "Xrandr extension version %i.%i", *major, *minor);
|
||||||
|
@ -108,12 +108,12 @@ static bool isXF86VidModeSupported(JNIEnv *env, Display *disp) {
|
||||||
return major_ver >= 2;
|
return major_ver >= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_LinuxDisplay_isXrandrSupported(JNIEnv *env, jclass unused) {
|
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nIsXrandrSupported(JNIEnv *env, jclass unused) {
|
||||||
jboolean result = isXrandrSupported(env, getDisplay()) ? JNI_TRUE : JNI_FALSE;
|
jboolean result = isXrandrSupported(env, getDisplay()) ? JNI_TRUE : JNI_FALSE;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_LinuxDisplay_isXF86VidModeSupported(JNIEnv *env, jclass unused) {
|
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nIsXF86VidModeSupported(JNIEnv *env, jclass unused) {
|
||||||
jboolean result = isXF86VidModeSupported(env, getDisplay()) ? JNI_TRUE : JNI_FALSE;
|
jboolean result = isXF86VidModeSupported(env, getDisplay()) ? JNI_TRUE : JNI_FALSE;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -262,7 +262,7 @@ static bool setMode(JNIEnv *env, Display *disp, int screen, jint extension, int
|
||||||
static int getGammaRampLengthOfDisplay(JNIEnv *env, Display *disp, int screen) {
|
static int getGammaRampLengthOfDisplay(JNIEnv *env, Display *disp, int screen) {
|
||||||
int ramp_size;
|
int ramp_size;
|
||||||
if (XF86VidModeGetGammaRampSize(disp, screen, &ramp_size) == False) {
|
if (XF86VidModeGetGammaRampSize(disp, screen, &ramp_size) == False) {
|
||||||
printfDebugJava(env, "XF86VidModeGetGammaRampSize call failed");
|
throwException(env, "XF86VidModeGetGammaRampSize call failed");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return ramp_size;
|
return ramp_size;
|
||||||
|
@ -304,6 +304,8 @@ JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetCurrentGammaRam
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setGamma(JNIEnv *env, Display *disp, int screen, jobject ramp_buffer) {
|
static void setGamma(JNIEnv *env, Display *disp, int screen, jobject ramp_buffer) {
|
||||||
|
if (ramp_buffer == NULL)
|
||||||
|
return;
|
||||||
unsigned short *ramp_ptr = (unsigned short *)(*env)->GetDirectBufferAddress(env, ramp_buffer);
|
unsigned short *ramp_ptr = (unsigned short *)(*env)->GetDirectBufferAddress(env, ramp_buffer);
|
||||||
jlong capacity = (*env)->GetDirectBufferCapacity(env, ramp_buffer);
|
jlong capacity = (*env)->GetDirectBufferCapacity(env, ramp_buffer);
|
||||||
int size = capacity/(sizeof(unsigned short)*3);
|
int size = capacity/(sizeof(unsigned short)*3);
|
||||||
|
@ -314,7 +316,7 @@ static void setGamma(JNIEnv *env, Display *disp, int screen, jobject ramp_buffer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setGammaRamp(JNIEnv *env, int screen, jobject gamma_ramp_buffer) {
|
void setGammaRamp(JNIEnv *env, int screen, jobject gamma_ramp_buffer) {
|
||||||
Display * disp = XOpenDisplay(NULL);
|
Display * disp = XOpenDisplay(NULL);
|
||||||
if (disp == NULL) {
|
if (disp == NULL) {
|
||||||
throwException(env, "Could not open display");
|
throwException(env, "Could not open display");
|
||||||
|
@ -324,7 +326,7 @@ static void setGammaRamp(JNIEnv *env, int screen, jobject gamma_ramp_buffer) {
|
||||||
XCloseDisplay(disp);
|
XCloseDisplay(disp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool switchDisplayMode(JNIEnv * env, int screen, jint extension, jobject mode) {
|
bool switchDisplayMode(JNIEnv * env, int screen, jint extension, jobject mode) {
|
||||||
if (mode == NULL) {
|
if (mode == NULL) {
|
||||||
throwException(env, "mode must be non-null");
|
throwException(env, "mode must be non-null");
|
||||||
return false;
|
return false;
|
||||||
|
@ -350,18 +352,6 @@ static bool switchDisplayMode(JNIEnv * env, int screen, jint extension, jobject
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void temporaryRestoreMode(JNIEnv *env, int screen, jint extension, jobject current_gamma_ramp, jobject current_mode) {
|
|
||||||
switchDisplayMode(env, screen, extension, current_mode);
|
|
||||||
// Don't propagate error to caller
|
|
||||||
setGammaRamp(env, screen, current_gamma_ramp);
|
|
||||||
}
|
|
||||||
|
|
||||||
void resetDisplayMode(JNIEnv *env, int screen, jint extension, jobject saved_gamma_ramp, jobject saved_mode) {
|
|
||||||
if (!switchDisplayMode(env, screen, extension, saved_mode))
|
|
||||||
return;
|
|
||||||
setGammaRamp(env, screen, saved_gamma_ramp);
|
|
||||||
}
|
|
||||||
|
|
||||||
static jobjectArray getAvailableDisplayModes(JNIEnv * env, Display *disp, int screen, jint extension) {
|
static jobjectArray getAvailableDisplayModes(JNIEnv * env, Display *disp, int screen, jint extension) {
|
||||||
int num_modes, i;
|
int num_modes, i;
|
||||||
mode_info *avail_modes;
|
mode_info *avail_modes;
|
||||||
|
@ -393,10 +383,6 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nSwitchDisplayMode(JNI
|
||||||
switchDisplayMode(env, getCurrentScreen(), extension, mode);
|
switchDisplayMode(env, getCurrentScreen(), extension, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nResetDisplayMode(JNIEnv *env, jclass clazz, jint extension, jobject gamma_ramp, jobject saved_mode) {
|
|
||||||
resetDisplayMode(env, getCurrentScreen(), extension, gamma_ramp, saved_mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetGammaRampLength(JNIEnv *env, jclass clazz) {
|
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetGammaRampLength(JNIEnv *env, jclass clazz) {
|
||||||
return (jint)getGammaRampLengthOfDisplay(env, getDisplay(), getCurrentScreen());
|
return (jint)getGammaRampLengthOfDisplay(env, getDisplay(), getCurrentScreen());
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
#include "common_tools.h"
|
#include "common_tools.h"
|
||||||
|
|
||||||
extern void resetDisplayMode(JNIEnv *env, int screen, jint extension, jobject gamma_ramp, jobject saved_mode);
|
extern bool switchDisplayMode(JNIEnv * env, int screen, jint extension, jobject mode);
|
||||||
extern void temporaryRestoreMode(JNIEnv *env, int screen, jint extension, jobject gamma_ramp, jobject saved_mode);
|
extern void setGammaRamp(JNIEnv *env, int screen, jobject gamma_ramp_buffer);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -190,7 +190,8 @@ static bool releaseInput(JNIEnv *env, jint extension, jint window_mode, jobject
|
||||||
updateInputGrab(window_mode);
|
updateInputGrab(window_mode);
|
||||||
if (window_mode == org_lwjgl_opengl_LinuxDisplay_FULLSCREEN_NETWM) {
|
if (window_mode == org_lwjgl_opengl_LinuxDisplay_FULLSCREEN_NETWM) {
|
||||||
XIconifyWindow(getDisplay(), getCurrentWindow(), getCurrentScreen());
|
XIconifyWindow(getDisplay(), getCurrentWindow(), getCurrentScreen());
|
||||||
resetDisplayMode(env, getCurrentScreen(), extension, gamma_ramp, saved_mode);
|
switchDisplayMode(env, getCurrentScreen(), extension, saved_mode);
|
||||||
|
setGammaRamp(env, getCurrentScreen(), gamma_ramp);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -202,7 +203,8 @@ static void acquireInput(JNIEnv *env, jint extension, jint window_mode, jobject
|
||||||
setRepeatMode(env, AutoRepeatModeOff);
|
setRepeatMode(env, AutoRepeatModeOff);
|
||||||
updateInputGrab(window_mode);
|
updateInputGrab(window_mode);
|
||||||
if (window_mode == org_lwjgl_opengl_LinuxDisplay_FULLSCREEN_NETWM) {
|
if (window_mode == org_lwjgl_opengl_LinuxDisplay_FULLSCREEN_NETWM) {
|
||||||
temporaryRestoreMode(env, getCurrentScreen(), extension, gamma_ramp, mode);
|
switchDisplayMode(env, getCurrentScreen(), extension, mode);
|
||||||
|
setGammaRamp(env, getCurrentScreen(), gamma_ramp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -345,7 +347,7 @@ static bool isNetWMFullscreenSupported(JNIEnv *env) {
|
||||||
Atom netwm_supported_atom = XInternAtom(getDisplay(), "_NET_SUPPORTED", False);
|
Atom netwm_supported_atom = XInternAtom(getDisplay(), "_NET_SUPPORTED", False);
|
||||||
int result = XGetWindowProperty(getDisplay(), RootWindow(getDisplay(), getCurrentScreen()), netwm_supported_atom, 0, 10000, False, AnyPropertyType, &actual_type, &actual_format, &nitems, &bytes_after, (void *)&supported_list);
|
int result = XGetWindowProperty(getDisplay(), RootWindow(getDisplay(), getCurrentScreen()), netwm_supported_atom, 0, 10000, False, AnyPropertyType, &actual_type, &actual_format, &nitems, &bytes_after, (void *)&supported_list);
|
||||||
if (result != Success) {
|
if (result != Success) {
|
||||||
printfDebugJava(env, "Unable to query _NET_SUPPORTED window property");
|
throwException(env, "Unable to query _NET_SUPPORTED window property");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Atom fullscreen_atom = XInternAtom(getDisplay(), "_NET_WM_STATE_FULLSCREEN", False);
|
Atom fullscreen_atom = XInternAtom(getDisplay(), "_NET_WM_STATE_FULLSCREEN", False);
|
||||||
|
|
Loading…
Reference in New Issue