diff --git a/.gitignore b/.gitignore
index 19efae5c..d25c0223 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,6 +6,5 @@
/src/native/common/Release
/src/native/windows/Debug
/src/native/windows/Release
-/src/native/*/org_lwjgl_*.h
-/src/native/*/*/org_lwjgl_*.h
+/src/native/**/*.h
/src/native/linux/org_lwjgl_opengl_Display.c
diff --git a/.tool-versions b/.tool-versions
index ab6a3328..6e8b53ee 100644
--- a/.tool-versions
+++ b/.tool-versions
@@ -1 +1 @@
-java adoptopenjdk-8.0.322+6
+java temurin-17.0.3+7
diff --git a/build.xml b/build.xml
index 04cc7176..5083b6b6 100644
--- a/build.xml
+++ b/build.xml
@@ -16,6 +16,8 @@
+
+
@@ -25,8 +27,6 @@
-
-
-
@@ -76,21 +75,11 @@
-
-
-
-
-
-
-
-
-
-
@@ -108,7 +97,7 @@
-
+
@@ -117,13 +106,13 @@
-
+
-
+
@@ -175,144 +164,202 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -452,35 +499,23 @@
-
-
-
-
-
-
-
-
-
-
-
-
@@ -488,16 +523,12 @@
-
-
-
-
@@ -516,17 +547,11 @@
-
-
-
-
-
-
diff --git a/platform_build/build-definitions.xml b/platform_build/build-definitions.xml
index ce34c328..97829d93 100644
--- a/platform_build/build-definitions.xml
+++ b/platform_build/build-definitions.xml
@@ -2,23 +2,31 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/platform_build/build-generator.xml b/platform_build/build-generator.xml
index 430e76fe..01441891 100644
--- a/platform_build/build-generator.xml
+++ b/platform_build/build-generator.xml
@@ -3,7 +3,7 @@
-
+
@@ -35,17 +35,19 @@
-
+
+
+
+
-
+
-
-
+
@@ -83,13 +85,14 @@
+
+
-
+
-
-
+
@@ -105,8 +108,10 @@
+
+
-
+
@@ -121,8 +126,10 @@
+
+
-
+
@@ -160,13 +167,14 @@
+
+
-
+
-
-
+
@@ -182,8 +190,10 @@
+
+
-
+
@@ -228,13 +238,14 @@
+
+
-
+
-
-
+
@@ -250,8 +261,10 @@
+
+
-
+
diff --git a/platform_build/linux_ant/build.xml b/platform_build/linux_ant/build.xml
index bde9a127..344d4e3d 100644
--- a/platform_build/linux_ant/build.xml
+++ b/platform_build/linux_ant/build.xml
@@ -3,8 +3,8 @@
-
-
+
+
@@ -52,7 +52,7 @@
-
+
@@ -72,19 +72,19 @@
-
+
-
+
-
+
@@ -104,13 +104,13 @@
-
+
-
-
+
+
diff --git a/platform_build/linux_ant/build_es.xml b/platform_build/linux_ant/build_es.xml
index b50f170f..73dde1dc 100644
--- a/platform_build/linux_ant/build_es.xml
+++ b/platform_build/linux_ant/build_es.xml
@@ -5,8 +5,8 @@
-
-
+
+
diff --git a/platform_build/macosx_ant/build.xml b/platform_build/macosx_ant/build.xml
index da69903b..3f49d651 100644
--- a/platform_build/macosx_ant/build.xml
+++ b/platform_build/macosx_ant/build.xml
@@ -95,7 +95,7 @@
-
+
@@ -117,12 +117,12 @@
-
-
+
+
-
+
@@ -173,7 +173,7 @@
-
+
@@ -198,12 +198,12 @@
-
+
-
-
+
+
diff --git a/src/java/org/lwjgl/LWJGLUtil.java b/src/java/org/lwjgl/LWJGLUtil.java
index 0ab810e0..697399f6 100644
--- a/src/java/org/lwjgl/LWJGLUtil.java
+++ b/src/java/org/lwjgl/LWJGLUtil.java
@@ -268,6 +268,32 @@ public class LWJGLUtil {
private static final int PLATFORM;
+ private static StupidSimpleLogger logger = msg -> {
+ //if (DEBUG) {
+ System.err.println("[LWJGL] " + msg);
+ //}
+ };
+
+ public static StupidSimpleLogger logger() {
+ return logger;
+ }
+
+ public static void logger(StupidSimpleLogger newLogger) {
+ logger = newLogger;
+ }
+
+ /**
+ * Logs the given message.
+ *
+ * @param msg Message to print
+ *
+ * @deprecated Use {@link #logger} instead.
+ */
+ @Deprecated
+ public static void log(CharSequence msg) {
+ logger().log(() -> msg.toString());
+ }
+
static {
final String osName = getPrivilegedProperty("os.name");
if ( osName.startsWith("Windows") )
@@ -504,17 +530,6 @@ public class LWJGLUtil {
});
}
- /**
- * Prints the given message to System.err if DEBUG is true.
- *
- * @param msg Message to print
- */
- public static void log(CharSequence msg) {
- if (DEBUG) {
- System.err.println("[LWJGL] " + msg);
- }
- }
-
/**
* Method to determine if the current system is running a version of
* Mac OS X better than the given version. This is only useful for Mac OS X
diff --git a/src/java/org/lwjgl/MemoryUtilSun.java b/src/java/org/lwjgl/MemoryUtilSun.java
index 683f372b..f5829c78 100644
--- a/src/java/org/lwjgl/MemoryUtilSun.java
+++ b/src/java/org/lwjgl/MemoryUtilSun.java
@@ -31,13 +31,14 @@
*/
package org.lwjgl;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.nio.Buffer;
import sun.misc.Unsafe;
-import sun.reflect.FieldAccessor;
/**
* MemoryUtil.Accessor implementations that depend on sun.misc.
@@ -103,33 +104,35 @@ final class MemoryUtilSun {
}
- /** Implementation using reflection on ByteBuffer, FieldAccessor is used directly. */
+ /** Implementation using {@link java.lang.MethodHandle}s on ByteBuffer. Reflection is used to acquire the handle. */
private static class AccessorReflectFast implements MemoryUtil.Accessor {
- private final FieldAccessor addressAccessor;
+ private final MethodHandle addressAccessor;
AccessorReflectFast() {
- Field address;
+ Field addressField;
try {
- address = MemoryUtil.getAddressField();
+ addressField = MemoryUtil.getAddressField();
} catch (NoSuchFieldException e) {
throw new UnsupportedOperationException(e);
}
- address.setAccessible(true);
+ addressField.setAccessible(true);
try {
- Method m = Field.class.getDeclaredMethod("acquireFieldAccessor", boolean.class);
- m.setAccessible(true);
- addressAccessor = (FieldAccessor)m.invoke(address, true);
- } catch (Exception e) {
+ addressAccessor = MethodHandles.lookup().unreflectGetter(addressField);
+ } catch (ReflectiveOperationException e) {
throw new UnsupportedOperationException(e);
}
}
public long getAddress(final Buffer buffer) {
- return addressAccessor.getLong(buffer);
+ try {
+ return (long) addressAccessor.invokeExact(buffer);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
}
}
-}
\ No newline at end of file
+}
diff --git a/src/java/org/lwjgl/StupidSimpleLogger.java b/src/java/org/lwjgl/StupidSimpleLogger.java
new file mode 100644
index 00000000..1e7b5c7f
--- /dev/null
+++ b/src/java/org/lwjgl/StupidSimpleLogger.java
@@ -0,0 +1,58 @@
+package org.lwjgl;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.function.Supplier;
+
+/**
+ * A (mostly) stupidly simple logger.
+ */
+@FunctionalInterface
+public interface StupidSimpleLogger {
+ /**
+ * Logs a message provided lazily.
+ */
+ void log(Supplier message);
+
+ /**
+ * Logs a message.
+ */
+ default void log(String message) {
+ log(() -> message);
+ }
+
+ /**
+ * Logs a message provided lazily and an error.
+ */
+ default void log(Supplier message, Throwable throwable) {
+ log(() -> {
+ StringWriter buf = new StringWriter().append(message.get()).append('\n');
+ throwable.printStackTrace(new PrintWriter(buf));
+ return buf.toString();
+ });
+ }
+
+ /**
+ * Logs a message and an error.
+ */
+ default void log(String message, Throwable throwable) {
+ log(() -> message, throwable);
+ }
+
+ /**
+ * A No-Op implementation of the logger. All default forwarding methods are overidden with No-Op implementations.
+ */
+ public static final StupidSimpleLogger NOOP = new StupidSimpleLogger() {
+ @Override
+ public void log(Supplier message) {}
+
+ @Override
+ public void log(String message) {}
+
+ @Override
+ public void log(Supplier message, Throwable throwable) {}
+
+ @Override
+ public void log(String message, Throwable throwable) {}
+ };
+}
diff --git a/src/java/org/lwjgl/opengl/AWTGLCanvas.java b/src/java/org/lwjgl/opengl/AWTGLCanvas.java
index bf7ab1ba..ca784a5f 100644
--- a/src/java/org/lwjgl/opengl/AWTGLCanvas.java
+++ b/src/java/org/lwjgl/opengl/AWTGLCanvas.java
@@ -216,7 +216,7 @@ public class AWTGLCanvas extends Canvas implements DrawableLWJGL, ComponentListe
}
/** Set swap interval. */
- public void setSwapInterval(int swap_interval) {
+ public void setSwapInterval(int swap_interval) throws LWJGLException {
synchronized ( SYNC_LOCK ) {
if ( context == null )
throw new IllegalStateException("Canvas not yet displayable");
@@ -225,7 +225,7 @@ public class AWTGLCanvas extends Canvas implements DrawableLWJGL, ComponentListe
}
/** Enable vsync */
- public void setVSyncEnabled(boolean enabled) {
+ public void setVSyncEnabled(boolean enabled) throws LWJGLException {
setSwapInterval(enabled ? 1 : 0);
}
@@ -411,4 +411,4 @@ public class AWTGLCanvas extends Canvas implements DrawableLWJGL, ComponentListe
setUpdate();
}
-}
\ No newline at end of file
+}
diff --git a/src/java/org/lwjgl/opengl/ContextGL.java b/src/java/org/lwjgl/opengl/ContextGL.java
index b5738537..22ecb45a 100644
--- a/src/java/org/lwjgl/opengl/ContextGL.java
+++ b/src/java/org/lwjgl/opengl/ContextGL.java
@@ -228,7 +228,7 @@ final class ContextGL implements Context {
*
* A video frame period is the time required to display a full frame of video data.
*/
- public static void setSwapInterval(int value) {
+ public static void setSwapInterval(int value) throws LWJGLException {
implementation.setSwapInterval(value);
}
@@ -296,4 +296,4 @@ final class ContextGL implements Context {
}
}
-}
\ No newline at end of file
+}
diff --git a/src/java/org/lwjgl/opengl/ContextImplementation.java b/src/java/org/lwjgl/opengl/ContextImplementation.java
index 62a828d9..8db3525f 100644
--- a/src/java/org/lwjgl/opengl/ContextImplementation.java
+++ b/src/java/org/lwjgl/opengl/ContextImplementation.java
@@ -81,7 +81,7 @@ interface ContextImplementation {
*/
boolean isCurrent(ByteBuffer handle) throws LWJGLException;
- void setSwapInterval(int value);
+ void setSwapInterval(int value) throws LWJGLException;
/**
* Destroys the Context.
diff --git a/src/java/org/lwjgl/opengl/Display.java b/src/java/org/lwjgl/opengl/Display.java
index 8b0a55f1..b367cfca 100644
--- a/src/java/org/lwjgl/opengl/Display.java
+++ b/src/java/org/lwjgl/opengl/Display.java
@@ -328,7 +328,7 @@ public final class Display {
context.releaseDrawable();
}
} catch (LWJGLException e) {
- LWJGLUtil.log("Exception occurred while trying to release context: " + e);
+ LWJGLUtil.logger().log("Exception occurred while trying to release context", e);
}
}
@@ -413,16 +413,12 @@ public final class Display {
/** @return the title of the window */
public static String getTitle() {
- synchronized ( GlobalLock.lock ) {
- return title;
- }
+ return title;
}
/** Return the last parent set with setParent(). */
public static Canvas getParent() {
- synchronized ( GlobalLock.lock ) {
- return parent;
- }
+ return parent;
}
/**
@@ -521,9 +517,7 @@ public final class Display {
/** @return whether the Display is in fullscreen mode */
public static boolean isFullscreen() {
- synchronized ( GlobalLock.lock ) {
- return fullscreen && current_mode.isFullscreenCapable();
- }
+ return fullscreen && current_mode.isFullscreenCapable();
}
/**
@@ -1026,7 +1020,7 @@ public final class Display {
try {
drawable.checkGLError();
} catch (OpenGLException e) {
- LWJGLUtil.log("OpenGL error during context creation: " + e.getMessage());
+ LWJGLUtil.logger().log("OpenGL error during context creation", e);
}
setSwapInterval(swap_interval);
}
@@ -1042,20 +1036,19 @@ public final class Display {
/** Gets a boolean property as a privileged action. */
static boolean getPrivilegedBoolean(final String property_name) {
- return AccessController.doPrivileged(new PrivilegedAction() {
- public Boolean run() {
- return Boolean.getBoolean(property_name);
+ String s = getPrivilegedString(property_name);
+ if (s == null || s.equals("false")) return false;
+ if (LWJGLUtil.DEBUG) {
+ if (!s.equals("true")) {
+ LWJGLUtil.logger().log(() -> "Value of boolean property " + property_name + " is not one of [true, false]: " + s);
}
- });
+ }
+ return true;
}
/** Gets a string property as a privileged action. */
static String getPrivilegedString(final String property_name) {
- return AccessController.doPrivileged(new PrivilegedAction() {
- public String run() {
- return System.getProperty(property_name);
- }
- });
+ return AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty(property_name));
}
private static void initControls() {
@@ -1065,22 +1058,14 @@ public final class Display {
try {
Mouse.create();
} catch (LWJGLException e) {
- if ( LWJGLUtil.DEBUG ) {
- e.printStackTrace(System.err);
- } else {
- LWJGLUtil.log("Failed to create Mouse: " + e);
- }
+ LWJGLUtil.logger().log("Failed to create Mouse", e);
}
}
if ( !Keyboard.isCreated() && !getPrivilegedBoolean("org.lwjgl.opengl.Display.nokeyboard") ) {
try {
Keyboard.create();
} catch (LWJGLException e) {
- if ( LWJGLUtil.DEBUG ) {
- e.printStackTrace(System.err);
- } else {
- LWJGLUtil.log("Failed to create Keyboard: " + e);
- }
+ LWJGLUtil.logger().log("Failed to create Keyboard", e);
}
}
}
@@ -1091,7 +1076,7 @@ public final class Display {
* regardless of whether the Display was the current rendering context.
*/
public static void destroy() {
- if(isCreated()) {
+ if (isCreated()) {
drawable.destroy();
}
}
@@ -1108,9 +1093,7 @@ public final class Display {
/** @return true if the window's native peer has been created */
public static boolean isCreated() {
- synchronized ( GlobalLock.lock ) {
- return window_created;
- }
+ return window_created;
}
/**
@@ -1122,7 +1105,7 @@ public final class Display {
*
* @param value The swap interval in frames, 0 to disable
*/
- public static void setSwapInterval(int value) {
+ public static void setSwapInterval(int value) throws LWJGLException {
synchronized ( GlobalLock.lock ) {
swap_interval = value;
if ( isCreated() )
@@ -1137,10 +1120,8 @@ public final class Display {
*
* @param sync true to synchronize; false to ignore synchronization
*/
- public static void setVSyncEnabled(boolean sync) {
- synchronized ( GlobalLock.lock ) {
- setSwapInterval(sync ? 1 : 0);
- }
+ public static void setVSyncEnabled(boolean sync) throws LWJGLException {
+ setSwapInterval(sync ? 1 : 0);
}
/**
@@ -1178,9 +1159,7 @@ public final class Display {
* @return a String
*/
public static String getAdapter() {
- synchronized ( GlobalLock.lock ) {
- return display_impl.getAdapter();
- }
+ return display_impl.getAdapter();
}
/**
@@ -1190,9 +1169,7 @@ public final class Display {
* @return a String
*/
public static String getVersion() {
- synchronized ( GlobalLock.lock ) {
- return display_impl.getVersion();
- }
+ return display_impl.getVersion();
}
/**
diff --git a/src/java/org/lwjgl/opengl/DrawableGL.java b/src/java/org/lwjgl/opengl/DrawableGL.java
index b1b767c9..886df156 100644
--- a/src/java/org/lwjgl/opengl/DrawableGL.java
+++ b/src/java/org/lwjgl/opengl/DrawableGL.java
@@ -82,7 +82,7 @@ abstract class DrawableGL implements DrawableLWJGL {
Util.checkGLError();
}
- public void setSwapInterval(final int swap_interval) {
+ public void setSwapInterval(final int swap_interval) throws LWJGLException {
ContextGL.setSwapInterval(swap_interval);
}
diff --git a/src/java/org/lwjgl/opengl/DrawableLWJGL.java b/src/java/org/lwjgl/opengl/DrawableLWJGL.java
index e4d989df..af46cbd2 100644
--- a/src/java/org/lwjgl/opengl/DrawableLWJGL.java
+++ b/src/java/org/lwjgl/opengl/DrawableLWJGL.java
@@ -62,10 +62,10 @@ interface DrawableLWJGL extends Drawable {
void checkGLError();
- void setSwapInterval(int swap_interval);
+ void setSwapInterval(int swap_interval) throws LWJGLException;
void swapBuffers() throws LWJGLException;
void initContext(final float r, final float g, final float b);
-}
\ No newline at end of file
+}
diff --git a/src/java/org/lwjgl/opengl/LinuxCanvasImplementation.java b/src/java/org/lwjgl/opengl/LinuxCanvasImplementation.java
index e84d4000..0672413f 100644
--- a/src/java/org/lwjgl/opengl/LinuxCanvasImplementation.java
+++ b/src/java/org/lwjgl/opengl/LinuxCanvasImplementation.java
@@ -102,8 +102,7 @@ final class LinuxCanvasImplementation implements AWTCanvasImplementation {
}
private static int findVisualIDFromFormat(int screen, PixelFormat pixel_format) throws LWJGLException {
- try {
- LinuxDisplay.lockAWT();
+ try (LinuxDisplay.AWTLock _lock = LinuxDisplay.awtLock()) {
try {
GLContext.loadOpenGLLibrary();
try {
@@ -115,8 +114,6 @@ final class LinuxCanvasImplementation implements AWTCanvasImplementation {
} finally {
GLContext.unloadOpenGLLibrary();
}
- } finally {
- LinuxDisplay.unlockAWT();
}
}
private static native int nFindVisualIDFromFormat(long display, int screen, PixelFormat pixel_format) throws LWJGLException;
diff --git a/src/java/org/lwjgl/opengl/LinuxContextImplementation.java b/src/java/org/lwjgl/opengl/LinuxContextImplementation.java
index 753a45e7..046fda1a 100644
--- a/src/java/org/lwjgl/opengl/LinuxContextImplementation.java
+++ b/src/java/org/lwjgl/opengl/LinuxContextImplementation.java
@@ -44,16 +44,13 @@ import java.nio.IntBuffer;
final class LinuxContextImplementation implements ContextImplementation {
public ByteBuffer create(PeerInfo peer_info, IntBuffer attribs, ByteBuffer shared_context_handle) throws LWJGLException {
- LinuxDisplay.lockAWT();
- try {
+ try (LinuxDisplay.AWTLock _lock = LinuxDisplay.awtLock()) {
ByteBuffer peer_handle = peer_info.lockAndGetHandle();
try {
return nCreate(peer_handle, attribs, shared_context_handle);
} finally {
peer_info.unlock();
}
- } finally {
- LinuxDisplay.unlockAWT();
}
}
@@ -72,16 +69,13 @@ final class LinuxContextImplementation implements ContextImplementation {
throw new IllegalStateException("No context is current");
synchronized ( current_context ) {
PeerInfo current_peer_info = current_context.getPeerInfo();
- LinuxDisplay.lockAWT();
- try {
+ try (LinuxDisplay.AWTLock _lock = LinuxDisplay.awtLock()) {
ByteBuffer peer_handle = current_peer_info.lockAndGetHandle();
try {
nSwapBuffers(peer_handle);
} finally {
current_peer_info.unlock();
}
- } finally {
- LinuxDisplay.unlockAWT();
}
}
}
@@ -94,16 +88,13 @@ final class LinuxContextImplementation implements ContextImplementation {
throw new IllegalStateException("No context is current");
synchronized ( current_context ) {
PeerInfo current_peer_info = current_context.getPeerInfo();
- LinuxDisplay.lockAWT();
- try {
+ try (LinuxDisplay.AWTLock _lock = LinuxDisplay.awtLock()) {
ByteBuffer peer_handle = current_peer_info.lockAndGetHandle();
try {
nReleaseCurrentContext(peer_handle);
} finally {
current_peer_info.unlock();
}
- } finally {
- LinuxDisplay.unlockAWT();
}
}
}
@@ -114,34 +105,29 @@ final class LinuxContextImplementation implements ContextImplementation {
}
public void makeCurrent(PeerInfo peer_info, ByteBuffer handle) throws LWJGLException {
- LinuxDisplay.lockAWT();
- try {
+ try (LinuxDisplay.AWTLock _lock = LinuxDisplay.awtLock()) {
ByteBuffer peer_handle = peer_info.lockAndGetHandle();
try {
nMakeCurrent(peer_handle, handle);
} finally {
peer_info.unlock();
}
- } finally {
- LinuxDisplay.unlockAWT();
}
}
private static native void nMakeCurrent(ByteBuffer peer_handle, ByteBuffer context_handle) throws LWJGLException;
public boolean isCurrent(ByteBuffer handle) throws LWJGLException {
- LinuxDisplay.lockAWT();
- try {
+ try (LinuxDisplay.AWTLock _lock = LinuxDisplay.awtLock()) {
boolean result = nIsCurrent(handle);
return result;
- } finally {
- LinuxDisplay.unlockAWT();
}
}
private static native boolean nIsCurrent(ByteBuffer context_handle) throws LWJGLException;
- public void setSwapInterval(int value) {
+ @Override
+ public void setSwapInterval(int value) throws LWJGLException {
ContextGL current_context = ContextGL.getCurrentContext();
if ( current_context == null )
@@ -150,19 +136,13 @@ final class LinuxContextImplementation implements ContextImplementation {
PeerInfo peer_info = current_context.getPeerInfo();
synchronized ( current_context ) {
- LinuxDisplay.lockAWT();
- try {
+ try (LinuxDisplay.AWTLock _lock = LinuxDisplay.awtLock()) {
ByteBuffer peer_handle = peer_info.lockAndGetHandle();
try {
nSetSwapInterval(peer_handle, current_context.getHandle(), value);
} finally {
peer_info.unlock();
}
- } catch (LWJGLException e) {
- // API CHANGE - this methods should throw LWJGLException
- e.printStackTrace();
- } finally {
- LinuxDisplay.unlockAWT();
}
}
}
@@ -170,16 +150,13 @@ final class LinuxContextImplementation implements ContextImplementation {
private static native void nSetSwapInterval(ByteBuffer peer_handle, ByteBuffer context_handle, int value);
public void destroy(PeerInfo peer_info, ByteBuffer handle) throws LWJGLException {
- LinuxDisplay.lockAWT();
- try {
+ try (LinuxDisplay.AWTLock _lock = LinuxDisplay.awtLock()) {
ByteBuffer peer_handle = peer_info.lockAndGetHandle();
try {
nDestroy(peer_handle, handle);
} finally {
peer_info.unlock();
}
- } finally {
- LinuxDisplay.unlockAWT();
}
}
diff --git a/src/java/org/lwjgl/opengl/LinuxDisplay.java b/src/java/org/lwjgl/opengl/LinuxDisplay.java
index 30728fa3..71e08936 100644
--- a/src/java/org/lwjgl/opengl/LinuxDisplay.java
+++ b/src/java/org/lwjgl/opengl/LinuxDisplay.java
@@ -178,8 +178,7 @@ final class LinuxDisplay implements DisplayImplementation {
};
private static ByteBuffer getCurrentGammaRamp() throws LWJGLException {
- lockAWT();
- try {
+ try (LinuxDisplay.AWTLock _lock = awtLock()) {
incDisplay();
try {
if (isXF86VidModeSupported())
@@ -189,8 +188,6 @@ final class LinuxDisplay implements DisplayImplementation {
} finally {
decDisplay();
}
- } finally {
- unlockAWT();
}
}
private static native ByteBuffer nGetCurrentGammaRamp(long display, int screen) throws LWJGLException;
@@ -213,8 +210,7 @@ final class LinuxDisplay implements DisplayImplementation {
private static boolean isXrandrSupported() {
if (Display.getPrivilegedBoolean("LWJGL_DISABLE_XRANDR"))
return false;
- lockAWT();
- try {
+ try (LinuxDisplay.AWTLock _lock = awtLock()) {
incDisplay();
try {
return nIsXrandrSupported(getDisplay());
@@ -224,15 +220,12 @@ final class LinuxDisplay implements DisplayImplementation {
} catch (LWJGLException e) {
LWJGLUtil.log("Got exception while querying Xrandr support: " + e);
return false;
- } finally {
- unlockAWT();
}
}
private static native boolean nIsXrandrSupported(long display) throws LWJGLException;
private static boolean isXF86VidModeSupported() {
- lockAWT();
- try {
+ try (LinuxDisplay.AWTLock _lock = awtLock()) {
incDisplay();
try {
return nIsXF86VidModeSupported(getDisplay());
@@ -242,8 +235,6 @@ final class LinuxDisplay implements DisplayImplementation {
} catch (LWJGLException e) {
LWJGLUtil.log("Got exception while querying XF86VM support: " + e);
return false;
- } finally {
- unlockAWT();
}
}
private static native boolean nIsXF86VidModeSupported(long display) throws LWJGLException;
@@ -251,8 +242,7 @@ final class LinuxDisplay implements DisplayImplementation {
private static boolean isNetWMFullscreenSupported() throws LWJGLException {
if (Display.getPrivilegedBoolean("LWJGL_DISABLE_NETWM"))
return false;
- lockAWT();
- try {
+ try (LinuxDisplay.AWTLock _lock = awtLock()) {
incDisplay();
try {
return nIsNetWMFullscreenSupported(getDisplay(), getDefaultScreen());
@@ -262,32 +252,38 @@ final class LinuxDisplay implements DisplayImplementation {
} catch (LWJGLException e) {
LWJGLUtil.log("Got exception while querying NetWM support: " + e);
return false;
- } finally {
- unlockAWT();
}
}
private static native boolean nIsNetWMFullscreenSupported(long display, int screen) throws LWJGLException;
+ public static final class AWTLock implements AutoCloseable {
+ private static final AWTLock INSTANCE = new AWTLock();
+
+ @Override
+ public void close() {
+ try {
+ nUnlockAWT();
+ } catch (LWJGLException e) {
+ LWJGLUtil.log("Caught exception while unlocking AWT: " + e);
+ }
+ }
+ }
+
/* 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
* do just that.
*/
- static void lockAWT() {
+ static AWTLock awtLock() {
try {
nLockAWT();
} catch (LWJGLException e) {
LWJGLUtil.log("Caught exception while locking AWT: " + e);
}
+ return AWTLock.INSTANCE;
}
+
private static native void nLockAWT() throws LWJGLException;
- static void unlockAWT() {
- try {
- nUnlockAWT();
- } catch (LWJGLException e) {
- LWJGLUtil.log("Caught exception while unlocking AWT: " + e);
- }
- }
private static native void nUnlockAWT() throws LWJGLException;
/**
@@ -452,8 +448,7 @@ final class LinuxDisplay implements DisplayImplementation {
}
public void createWindow(final DrawableLWJGL drawable, DisplayMode mode, Canvas parent, int x, int y) throws LWJGLException {
- lockAWT();
- try {
+ try (LinuxDisplay.AWTLock _lock = awtLock()) {
incDisplay();
try {
if ( drawable instanceof DrawableGLES )
@@ -527,8 +522,6 @@ final class LinuxDisplay implements DisplayImplementation {
decDisplay();
throw e;
}
- } finally {
- unlockAWT();
}
}
private static native long nCreateWindow(long display, int screen, ByteBuffer peer_info_handle, DisplayMode mode, int window_mode, int x, int y, boolean undecorated, long parent_handle, boolean resizable) throws LWJGLException;
@@ -576,8 +569,7 @@ final class LinuxDisplay implements DisplayImplementation {
}
public void destroyWindow() {
- lockAWT();
- try {
+ try (LinuxDisplay.AWTLock _lock = awtLock()) {
if (parent != null) {
parent.removeFocusListener(focus_listener);
}
@@ -594,19 +586,14 @@ final class LinuxDisplay implements DisplayImplementation {
if ( current_window_mode != WINDOWED )
Compiz.setLegacyFullscreenSupport(false);
- } finally {
- unlockAWT();
}
}
static native void nDestroyWindow(long display, long window);
public void switchDisplayMode(DisplayMode mode) throws LWJGLException {
- lockAWT();
- try {
+ try (LinuxDisplay.AWTLock _lock = awtLock()) {
switchDisplayModeOnTmpDisplay(mode);
current_mode = mode;
- } finally {
- unlockAWT();
}
}
@@ -636,8 +623,7 @@ final class LinuxDisplay implements DisplayImplementation {
static native long nInternAtom(long display, String atom_name, boolean only_if_exists);
public void resetDisplayMode() {
- lockAWT();
- try {
+ try (LinuxDisplay.AWTLock _lock = awtLock()) {
if( current_displaymode_extension == XRANDR )
{
AccessController.doPrivileged(new PrivilegedAction