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.
* @param sync true to synchronize; false to ignore synchronization
*/
public synchronized void setVSync(boolean enable) {
public static void setVSync(boolean enable) {
implementation.setVSync(enable);
}

View File

@ -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,9 +60,11 @@ 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");
synchronized (current_context) {
PeerInfo current_peer_info = current_context.getPeerInfo();
LinuxDisplay.lockAWT();
try {
ByteBuffer peer_handle = current_peer_info.lockAndGetHandle();
@ -79,12 +77,15 @@ final class LinuxContextImplementation implements ContextImplementation {
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
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 {
ByteBuffer peer_handle = current_peer_info.lockAndGetHandle();
@ -97,6 +98,7 @@ final class LinuxContextImplementation implements ContextImplementation {
LinuxDisplay.unlockAWT();
}
}
}
private static native void nReleaseCurrentContext(ByteBuffer peer_info_handle) throws LWJGLException;
public void update(ByteBuffer context_handle) {

View File

@ -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,8 +55,12 @@ final class MacOSXContextImplementation implements ContextImplementation {
public void swapBuffers() throws LWJGLException {
Context current_context = Context.getCurrentContext();
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;
public void update(ByteBuffer context_handle) {
@ -70,8 +70,11 @@ final class MacOSXContextImplementation implements ContextImplementation {
public void releaseCurrentContext() throws LWJGLException {
Context current_context = Context.getCurrentContext();
if (current_context != null)
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);

View File

@ -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,9 +54,11 @@ 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");
synchronized (current_context) {
PeerInfo current_peer_info = current_context.getPeerInfo();
ByteBuffer peer_handle = current_peer_info.lockAndGetHandle();
try {
nSwapBuffers(peer_handle);
@ -68,6 +66,7 @@ final class Win32ContextImplementation implements ContextImplementation {
current_peer_info.unlock();
}
}
}
private static native void nSwapBuffers(ByteBuffer peer_info_handle) throws LWJGLException;
public void update(ByteBuffer context_handle) {