Made Context.setVSync static. Added synchronization.

This commit is contained in:
Elias Naur 2005-02-23 12:12:47 +00:00
parent 2586270d03
commit 2e03a6426b
4 changed files with 50 additions and 43 deletions

View File

@ -208,7 +208,7 @@ final class Context {
* the monitor vertical refresh synchronization of the context, and is not guaranteed to be successful. * the monitor vertical refresh synchronization of the context, and is not guaranteed to be successful.
* @param sync true to synchronize; false to ignore synchronization * @param sync true to synchronize; false to ignore synchronization
*/ */
public synchronized void setVSync(boolean enable) { public static void setVSync(boolean enable) {
implementation.setVSync(enable); implementation.setVSync(enable);
} }

View File

@ -43,10 +43,6 @@ import org.lwjgl.BufferUtils;
* @version $Revision$ * @version $Revision$
*/ */
final class LinuxContextImplementation implements ContextImplementation { final class LinuxContextImplementation implements ContextImplementation {
private static PeerInfo getCurrentPeerInfo() {
return Context.getCurrentContext().getPeerInfo();
}
public ByteBuffer create(PeerInfo peer_info, ByteBuffer shared_context_handle) throws LWJGLException { public ByteBuffer create(PeerInfo peer_info, ByteBuffer shared_context_handle) throws LWJGLException {
LinuxDisplay.lockAWT(); LinuxDisplay.lockAWT();
try { try {
@ -64,37 +60,43 @@ final class LinuxContextImplementation implements ContextImplementation {
private static native ByteBuffer nCreate(ByteBuffer peer_handle, ByteBuffer shared_context_handle) throws LWJGLException; private static native ByteBuffer nCreate(ByteBuffer peer_handle, ByteBuffer shared_context_handle) throws LWJGLException;
public void swapBuffers() throws LWJGLException { public void swapBuffers() throws LWJGLException {
PeerInfo current_peer_info = getCurrentPeerInfo(); Context current_context = Context.getCurrentContext();
if (current_peer_info == null) if (current_context == null)
throw new IllegalStateException("No context is current"); throw new IllegalStateException("No context is current");
LinuxDisplay.lockAWT(); synchronized (current_context) {
try { PeerInfo current_peer_info = current_context.getPeerInfo();
ByteBuffer peer_handle = current_peer_info.lockAndGetHandle(); LinuxDisplay.lockAWT();
try { try {
nSwapBuffers(peer_handle); ByteBuffer peer_handle = current_peer_info.lockAndGetHandle();
try {
nSwapBuffers(peer_handle);
} finally {
current_peer_info.unlock();
}
} finally { } finally {
current_peer_info.unlock(); LinuxDisplay.unlockAWT();
} }
} finally {
LinuxDisplay.unlockAWT();
} }
} }
private static native void nSwapBuffers(ByteBuffer peer_info_handle) throws LWJGLException; private static native void nSwapBuffers(ByteBuffer peer_info_handle) throws LWJGLException;
public void releaseCurrentContext() throws LWJGLException { public void releaseCurrentContext() throws LWJGLException {
PeerInfo current_peer_info = getCurrentPeerInfo(); Context current_context = Context.getCurrentContext();
if (current_peer_info == null) if (current_context == null)
return; // No context is current throw new IllegalStateException("No context is current");
LinuxDisplay.lockAWT(); synchronized (current_context) {
try { PeerInfo current_peer_info = current_context.getPeerInfo();
ByteBuffer peer_handle = current_peer_info.lockAndGetHandle(); LinuxDisplay.lockAWT();
try { try {
nReleaseCurrentContext(peer_handle); ByteBuffer peer_handle = current_peer_info.lockAndGetHandle();
try {
nReleaseCurrentContext(peer_handle);
} finally {
current_peer_info.unlock();
}
} finally { } finally {
current_peer_info.unlock(); LinuxDisplay.unlockAWT();
} }
} finally {
LinuxDisplay.unlockAWT();
} }
} }
private static native void nReleaseCurrentContext(ByteBuffer peer_info_handle) throws LWJGLException; private static native void nReleaseCurrentContext(ByteBuffer peer_info_handle) throws LWJGLException;

View File

@ -43,10 +43,6 @@ import org.lwjgl.BufferUtils;
* @version $Revision$ * @version $Revision$
*/ */
final class MacOSXContextImplementation implements ContextImplementation { final class MacOSXContextImplementation implements ContextImplementation {
private static PeerInfo getCurrentPeerInfo() {
return Context.getCurrentContext().getPeerInfo();
}
public ByteBuffer create(PeerInfo peer_info, ByteBuffer shared_context_handle) throws LWJGLException { public ByteBuffer create(PeerInfo peer_info, ByteBuffer shared_context_handle) throws LWJGLException {
ByteBuffer peer_handle = peer_info.lockAndGetHandle(); ByteBuffer peer_handle = peer_info.lockAndGetHandle();
try { try {
@ -59,7 +55,11 @@ final class MacOSXContextImplementation implements ContextImplementation {
public void swapBuffers() throws LWJGLException { public void swapBuffers() throws LWJGLException {
Context current_context = Context.getCurrentContext(); Context current_context = Context.getCurrentContext();
nSwapBuffers(current_context.getHandle()); if (current_context == null)
throw new IllegalStateException("No context is current");
synchronized (current_context) {
nSwapBuffers(current_context.getHandle());
}
} }
private static native void nSwapBuffers(ByteBuffer context_handle) throws LWJGLException; private static native void nSwapBuffers(ByteBuffer context_handle) throws LWJGLException;
@ -70,8 +70,11 @@ final class MacOSXContextImplementation implements ContextImplementation {
public void releaseCurrentContext() throws LWJGLException { public void releaseCurrentContext() throws LWJGLException {
Context current_context = Context.getCurrentContext(); Context current_context = Context.getCurrentContext();
if (current_context != null) if (current_context != null) {
clearDrawable(current_context.getHandle()); synchronized (current_context) {
clearDrawable(current_context.getHandle());
}
}
nReleaseCurrentContext(); nReleaseCurrentContext();
} }
private static native void nReleaseCurrentContext() throws LWJGLException; private static native void nReleaseCurrentContext() throws LWJGLException;
@ -97,7 +100,10 @@ final class MacOSXContextImplementation implements ContextImplementation {
private static native boolean nIsCurrent(ByteBuffer context_handle) throws LWJGLException; private static native boolean nIsCurrent(ByteBuffer context_handle) throws LWJGLException;
public void setVSync(boolean enabled) { public void setVSync(boolean enabled) {
nSetVSync(Context.getCurrentContext().getHandle(), enabled); Context current_context = Context.getCurrentContext();
synchronized (current_context) {
nSetVSync(current_context.getHandle(), enabled);
}
} }
private static native void nSetVSync(ByteBuffer context_handle, boolean enabled); private static native void nSetVSync(ByteBuffer context_handle, boolean enabled);

View File

@ -43,10 +43,6 @@ import org.lwjgl.BufferUtils;
* @version $Revision$ * @version $Revision$
*/ */
final class Win32ContextImplementation implements ContextImplementation { final class Win32ContextImplementation implements ContextImplementation {
private static PeerInfo getCurrentPeerInfo() {
return Context.getCurrentContext().getPeerInfo();
}
public ByteBuffer create(PeerInfo peer_info, ByteBuffer shared_context_handle) throws LWJGLException { public ByteBuffer create(PeerInfo peer_info, ByteBuffer shared_context_handle) throws LWJGLException {
ByteBuffer peer_handle = peer_info.lockAndGetHandle(); ByteBuffer peer_handle = peer_info.lockAndGetHandle();
try { try {
@ -58,14 +54,17 @@ final class Win32ContextImplementation implements ContextImplementation {
private static native ByteBuffer nCreate(ByteBuffer peer_handle, ByteBuffer shared_context_handle) throws LWJGLException; private static native ByteBuffer nCreate(ByteBuffer peer_handle, ByteBuffer shared_context_handle) throws LWJGLException;
public void swapBuffers() throws LWJGLException { public void swapBuffers() throws LWJGLException {
PeerInfo current_peer_info = getCurrentPeerInfo(); Context current_context = Context.getCurrentContext();
if (current_peer_info == null) if (current_context == null)
throw new IllegalStateException("No context is current"); throw new IllegalStateException("No context is current");
ByteBuffer peer_handle = current_peer_info.lockAndGetHandle(); synchronized (current_context) {
try { PeerInfo current_peer_info = current_context.getPeerInfo();
nSwapBuffers(peer_handle); ByteBuffer peer_handle = current_peer_info.lockAndGetHandle();
} finally { try {
current_peer_info.unlock(); nSwapBuffers(peer_handle);
} finally {
current_peer_info.unlock();
}
} }
} }
private static native void nSwapBuffers(ByteBuffer peer_info_handle) throws LWJGLException; private static native void nSwapBuffers(ByteBuffer peer_info_handle) throws LWJGLException;