From 9a4824e79bb9b2fef81d2c4fbe0cb533a731ccc5 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Fri, 21 Jan 2005 22:07:20 +0000 Subject: [PATCH] Mac OS X: Remove invokeAndWait stuff since AWT, unlike swing, is thread safe --- src/java/org/lwjgl/opengl/MacOSXDisplay.java | 13 ++- src/java/org/lwjgl/opengl/MacOSXFrame.java | 103 ++---------------- src/java/org/lwjgl/opengl/MacOSXGLCanvas.java | 22 ++-- 3 files changed, 29 insertions(+), 109 deletions(-) diff --git a/src/java/org/lwjgl/opengl/MacOSXDisplay.java b/src/java/org/lwjgl/opengl/MacOSXDisplay.java index b493eadd..098b502f 100644 --- a/src/java/org/lwjgl/opengl/MacOSXDisplay.java +++ b/src/java/org/lwjgl/opengl/MacOSXDisplay.java @@ -92,11 +92,12 @@ final class MacOSXDisplay implements DisplayImplementation { } public void destroyWindow() { - if (MacOSXFrame.getDevice().getFullScreenWindow() != null) - MacOSXFrame.getDevice().setFullScreenWindow(null); if (frame != null) { + if (MacOSXFrame.getDevice().getFullScreenWindow() == frame) + MacOSXFrame.getDevice().setFullScreenWindow(null); setView(null); - frame.syncDispose(); + if (frame.isDisplayable()) + frame.dispose(); frame = null; } hideUI(false); @@ -172,7 +173,7 @@ final class MacOSXDisplay implements DisplayImplementation { } public void setTitle(String title) { - frame.syncSetTitle(title); + frame.setTitle(title); } public boolean isCloseRequested() { @@ -238,7 +239,7 @@ final class MacOSXDisplay implements DisplayImplementation { public native void setVSyncEnabled(boolean sync); public void reshape(int x, int y, int width, int height) { - frame.syncReshape(x, y, width, height); + frame.resize(x, y, width, height); } /* Mouse */ @@ -307,7 +308,7 @@ final class MacOSXDisplay implements DisplayImplementation { public void setNativeCursor(Object handle) throws LWJGLException { Cursor awt_cursor = (Cursor)handle; - frame.syncSetCursor(awt_cursor); + frame.setCursor(awt_cursor); } public int getMinCursorSize() { diff --git a/src/java/org/lwjgl/opengl/MacOSXFrame.java b/src/java/org/lwjgl/opengl/MacOSXFrame.java index 85f1820c..e305613e 100644 --- a/src/java/org/lwjgl/opengl/MacOSXFrame.java +++ b/src/java/org/lwjgl/opengl/MacOSXFrame.java @@ -78,23 +78,25 @@ final class MacOSXFrame extends Frame implements WindowListener, ComponentListen /** For some strange reason, the display mode is sometimes silently capped even though the mode is reported as supported */ if ( requested_mode.getWidth() != real_mode.getWidth() || requested_mode.getHeight() != real_mode.getHeight() ) { getDevice().setFullScreenWindow(null); - syncDispose(); + if (isDisplayable()) + dispose(); throw new LWJGLException("AWT capped mode: requested mode = " + requested_mode.getWidth() + "x" + requested_mode.getHeight() + " but got " + real_mode.getWidth() + " " + real_mode.getHeight()); } } pack(); - syncReshape(x, y, mode.getWidth(), mode.getHeight()); - invokeAWT(new Runnable() { - public void run() { - setVisible(true); - requestFocus(); - canvas.requestFocus(); - canvas.initializeCanvas(); - } - }); + resize(x, y, mode.getWidth(), mode.getHeight()); + setVisible(true); + requestFocus(); + canvas.requestFocus(); + canvas.initializeCanvas(); } + public void resize(int x, int y, int width, int height) { + Insets insets = getInsets(); + setBounds(x, y, width + insets.left + insets.right, height + insets.top + insets.bottom); + } + public Rectangle syncGetBounds() { synchronized ( this ) { return bounds; @@ -164,32 +166,6 @@ final class MacOSXFrame extends Frame implements WindowListener, ComponentListen } } - public void syncDispose() { - invokeAWT(new Runnable() { - public void run() { - if ( isDisplayable() ) - dispose(); - } - }); - } - - private class TitleSetter implements Runnable { - - private final String title; - - TitleSetter(String title) { - this.title = title; - } - - public void run() { - setTitle(title); - } - } - - public void syncSetTitle(String title) { - invokeAWT(new TitleSetter(title)); - } - public boolean syncIsCloseRequested() { boolean result; synchronized ( this ) { @@ -223,59 +199,4 @@ final class MacOSXFrame extends Frame implements WindowListener, ComponentListen } return result; } - - private class Reshaper implements Runnable { - - private final int x; - private final int y; - private final int width; - private final int height; - - Reshaper(int x, int y, int width, int height) { - this.x = x; - this.y = y; - this.width = width; - this.height = height; - } - - public void run() { - Insets insets = getInsets(); - setBounds(x, y, width + insets.left + insets.right, height + insets.top + insets.bottom); - } - } - - private void invokeAWT(Runnable r) { - try { - if (java.awt.EventQueue.isDispatchThread()) { - r.run(); - } else { - java.awt.EventQueue.invokeAndWait(r); - } - } catch (InterruptedException e) { - // ignore - } catch (InvocationTargetException e) { - throw new RuntimeException(e); - } - } - - public void syncReshape(int x, int y, int width, int height) { - invokeAWT(new Reshaper(x, y, width, height)); - } - - private class CursorSetter implements Runnable { - - private final java.awt.Cursor awt_cursor; - - CursorSetter(java.awt.Cursor awt_cursor) { - this.awt_cursor = awt_cursor; - } - - public void run() { - canvas.setCursor(awt_cursor); - } - } - - public void syncSetCursor(java.awt.Cursor awt_cursor) { - invokeAWT(new CursorSetter(awt_cursor)); - } } diff --git a/src/java/org/lwjgl/opengl/MacOSXGLCanvas.java b/src/java/org/lwjgl/opengl/MacOSXGLCanvas.java index 17c690f2..d950710d 100644 --- a/src/java/org/lwjgl/opengl/MacOSXGLCanvas.java +++ b/src/java/org/lwjgl/opengl/MacOSXGLCanvas.java @@ -55,23 +55,21 @@ final class MacOSXGLCanvas extends Canvas implements ComponentListener { } public void paint(Graphics g) { - // Do nothing + synchronized ( this ) { + dirty = true; + } } /** - * This initializes the canvas and binds the context to it. Should only - * be called from the AWT dispatch thread. + * This initializes the canvas and binds the context to it. */ public void initializeCanvas() { - synchronized ( this ) { - dirty = true; - setFocusTraversalKeysEnabled(false); - /* Input methods are not enabled in fullscreen anyway, so disable always */ - enableInputMethods(false); - addComponentListener(this); - ((MacOSXDisplay)Display.getImplementation()).setView(this); - setUpdate(); - } + setFocusTraversalKeysEnabled(false); + /* Input methods are not enabled in fullscreen anyway, so disable always */ + enableInputMethods(false); + addComponentListener(this); + ((MacOSXDisplay)Display.getImplementation()).setView(this); + setUpdate(); } public boolean syncIsDirty() {