Made Context.setVSync static. Added synchronization.
This commit is contained in:
parent
2586270d03
commit
2e03a6426b
|
@ -208,7 +208,7 @@ final class Context {
|
|||
* the monitor vertical refresh synchronization of the context, and is not guaranteed to be successful.
|
||||
* @param sync true to synchronize; false to ignore synchronization
|
||||
*/
|
||||
public synchronized void setVSync(boolean enable) {
|
||||
public static void setVSync(boolean enable) {
|
||||
implementation.setVSync(enable);
|
||||
}
|
||||
|
||||
|
|
|
@ -43,10 +43,6 @@ import org.lwjgl.BufferUtils;
|
|||
* @version $Revision$
|
||||
*/
|
||||
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 {
|
||||
LinuxDisplay.lockAWT();
|
||||
try {
|
||||
|
@ -64,37 +60,43 @@ final class LinuxContextImplementation implements ContextImplementation {
|
|||
private static native ByteBuffer nCreate(ByteBuffer peer_handle, ByteBuffer shared_context_handle) throws LWJGLException;
|
||||
|
||||
public void swapBuffers() throws LWJGLException {
|
||||
PeerInfo current_peer_info = getCurrentPeerInfo();
|
||||
if (current_peer_info == null)
|
||||
Context current_context = Context.getCurrentContext();
|
||||
if (current_context == null)
|
||||
throw new IllegalStateException("No context is current");
|
||||
LinuxDisplay.lockAWT();
|
||||
try {
|
||||
ByteBuffer peer_handle = current_peer_info.lockAndGetHandle();
|
||||
synchronized (current_context) {
|
||||
PeerInfo current_peer_info = current_context.getPeerInfo();
|
||||
LinuxDisplay.lockAWT();
|
||||
try {
|
||||
nSwapBuffers(peer_handle);
|
||||
ByteBuffer peer_handle = current_peer_info.lockAndGetHandle();
|
||||
try {
|
||||
nSwapBuffers(peer_handle);
|
||||
} finally {
|
||||
current_peer_info.unlock();
|
||||
}
|
||||
} finally {
|
||||
current_peer_info.unlock();
|
||||
LinuxDisplay.unlockAWT();
|
||||
}
|
||||
} finally {
|
||||
LinuxDisplay.unlockAWT();
|
||||
}
|
||||
}
|
||||
private static native void nSwapBuffers(ByteBuffer peer_info_handle) throws LWJGLException;
|
||||
|
||||
public void releaseCurrentContext() throws LWJGLException {
|
||||
PeerInfo current_peer_info = getCurrentPeerInfo();
|
||||
if (current_peer_info == null)
|
||||
return; // No context is current
|
||||
LinuxDisplay.lockAWT();
|
||||
try {
|
||||
ByteBuffer peer_handle = current_peer_info.lockAndGetHandle();
|
||||
Context current_context = Context.getCurrentContext();
|
||||
if (current_context == null)
|
||||
throw new IllegalStateException("No context is current");
|
||||
synchronized (current_context) {
|
||||
PeerInfo current_peer_info = current_context.getPeerInfo();
|
||||
LinuxDisplay.lockAWT();
|
||||
try {
|
||||
nReleaseCurrentContext(peer_handle);
|
||||
ByteBuffer peer_handle = current_peer_info.lockAndGetHandle();
|
||||
try {
|
||||
nReleaseCurrentContext(peer_handle);
|
||||
} finally {
|
||||
current_peer_info.unlock();
|
||||
}
|
||||
} finally {
|
||||
current_peer_info.unlock();
|
||||
LinuxDisplay.unlockAWT();
|
||||
}
|
||||
} finally {
|
||||
LinuxDisplay.unlockAWT();
|
||||
}
|
||||
}
|
||||
private static native void nReleaseCurrentContext(ByteBuffer peer_info_handle) throws LWJGLException;
|
||||
|
|
|
@ -43,10 +43,6 @@ import org.lwjgl.BufferUtils;
|
|||
* @version $Revision$
|
||||
*/
|
||||
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 {
|
||||
ByteBuffer peer_handle = peer_info.lockAndGetHandle();
|
||||
try {
|
||||
|
@ -59,7 +55,11 @@ final class MacOSXContextImplementation implements ContextImplementation {
|
|||
|
||||
public void swapBuffers() throws LWJGLException {
|
||||
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;
|
||||
|
||||
|
@ -70,8 +70,11 @@ final class MacOSXContextImplementation implements ContextImplementation {
|
|||
|
||||
public void releaseCurrentContext() throws LWJGLException {
|
||||
Context current_context = Context.getCurrentContext();
|
||||
if (current_context != null)
|
||||
clearDrawable(current_context.getHandle());
|
||||
if (current_context != null) {
|
||||
synchronized (current_context) {
|
||||
clearDrawable(current_context.getHandle());
|
||||
}
|
||||
}
|
||||
nReleaseCurrentContext();
|
||||
}
|
||||
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;
|
||||
|
||||
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);
|
||||
|
||||
|
|
|
@ -43,10 +43,6 @@ import org.lwjgl.BufferUtils;
|
|||
* @version $Revision$
|
||||
*/
|
||||
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 {
|
||||
ByteBuffer peer_handle = peer_info.lockAndGetHandle();
|
||||
try {
|
||||
|
@ -58,14 +54,17 @@ final class Win32ContextImplementation implements ContextImplementation {
|
|||
private static native ByteBuffer nCreate(ByteBuffer peer_handle, ByteBuffer shared_context_handle) throws LWJGLException;
|
||||
|
||||
public void swapBuffers() throws LWJGLException {
|
||||
PeerInfo current_peer_info = getCurrentPeerInfo();
|
||||
if (current_peer_info == null)
|
||||
Context current_context = Context.getCurrentContext();
|
||||
if (current_context == null)
|
||||
throw new IllegalStateException("No context is current");
|
||||
ByteBuffer peer_handle = current_peer_info.lockAndGetHandle();
|
||||
try {
|
||||
nSwapBuffers(peer_handle);
|
||||
} finally {
|
||||
current_peer_info.unlock();
|
||||
synchronized (current_context) {
|
||||
PeerInfo current_peer_info = current_context.getPeerInfo();
|
||||
ByteBuffer peer_handle = current_peer_info.lockAndGetHandle();
|
||||
try {
|
||||
nSwapBuffers(peer_handle);
|
||||
} finally {
|
||||
current_peer_info.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native void nSwapBuffers(ByteBuffer peer_info_handle) throws LWJGLException;
|
||||
|
|
Loading…
Reference in New Issue