aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java10
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/AbstractGraphicsDevice.java2
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/DefaultGraphicsDevice.java48
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/NativeWindowFactory.java31
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/egl/EGLGraphicsDevice.java30
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/x11/X11GraphicsDevice.java36
6 files changed, 75 insertions, 82 deletions
diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java
index ec1230894..ab4924516 100644
--- a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java
+++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java
@@ -206,9 +206,13 @@ public class X11GLXContext extends GLContextImpl {
@Override
protected void destroyContextARBImpl(final long ctx) {
final long display = drawable.getNativeSurface().getDisplayHandle();
-
- glXReleaseContext(display);
- GLX.glXDestroyContext(display, ctx);
+ if( 0 != display ) {
+ glXReleaseContext(display);
+ GLX.glXDestroyContext(display, ctx);
+ } else {
+ final AbstractGraphicsDevice adev = drawable.getNativeSurface().getGraphicsConfiguration().getScreen().getDevice();
+ throw new GLException("null display handle from device "+adev);
+ }
}
private static final int ctx_arb_attribs_idx_major = 0;
private static final int ctx_arb_attribs_idx_minor = 2;
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/AbstractGraphicsDevice.java b/src/nativewindow/classes/com/jogamp/nativewindow/AbstractGraphicsDevice.java
index 3afb81d67..52c7779ad 100644
--- a/src/nativewindow/classes/com/jogamp/nativewindow/AbstractGraphicsDevice.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/AbstractGraphicsDevice.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2023 JogAmp Community. All rights reserved.
+ * Copyright (c) 2010-2024 JogAmp Community. All rights reserved.
* Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/DefaultGraphicsDevice.java b/src/nativewindow/classes/com/jogamp/nativewindow/DefaultGraphicsDevice.java
index 4210046d6..266efdf28 100644
--- a/src/nativewindow/classes/com/jogamp/nativewindow/DefaultGraphicsDevice.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/DefaultGraphicsDevice.java
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
- * Copyright (c) 2010 JogAmp Community. All rights reserved.
+ * Copyright (c) 2010-2024 JogAmp Community. All rights reserved.
+ * Copyright (c) 2008-2009 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -42,6 +42,7 @@ public class DefaultGraphicsDevice implements Cloneable, AbstractGraphicsDevice
protected final int unitID;
protected final String uniqueID;
protected long handle;
+ private Object handleOwner;
protected ToolkitLock toolkitLock;
/**
@@ -92,6 +93,7 @@ public class DefaultGraphicsDevice implements Cloneable, AbstractGraphicsDevice
this.unitID = unitID;
this.uniqueID = getUniqueID(type, connection, unitID);
this.handle = handle;
+ this.handleOwner = null;
this.toolkitLock = null != locker ? locker : NativeWindowFactoryImpl.getNullToolkitLock();
}
@@ -178,17 +180,19 @@ public class DefaultGraphicsDevice implements Cloneable, AbstractGraphicsDevice
}
@Override
- public boolean isHandleOwner() {
- return false;
+ public final boolean isHandleOwner() {
+ return null != handleOwner;
}
@Override
- public void clearHandleOwner() {
+ public final void clearHandleOwner() {
+ handleOwner = null;
}
@Override
public String toString() {
- return getClass().getSimpleName()+"[type "+getType()+", connection "+getConnection()+", unitID "+getUnitID()+", handle 0x"+Long.toHexString(getHandle())+", owner "+isHandleOwner()+", "+toolkitLock+"]";
+ return getClass().getSimpleName()+"[type "+getType()+", connection "+getConnection()+", unitID "+getUnitID()+
+ ", handle 0x"+Long.toHexString(getHandle())+", owner "+isHandleOwner()+", "+toolkitLock+", obj 0x"+Integer.toHexString(hashCode())+"]";
}
/**
@@ -201,29 +205,31 @@ public class DefaultGraphicsDevice implements Cloneable, AbstractGraphicsDevice
return oldHandle;
}
- protected Object getHandleOwnership() {
- return null;
+ protected final Object getHandleOwnership() {
+ return handleOwner;
}
- protected Object setHandleOwnership(final Object newOwnership) {
- return null;
+ protected final Object setHandleOwnership(final Object newOwnership) {
+ final Object old = handleOwner;
+ handleOwner = newOwnership;
+ return old;
}
- public static final void swapDeviceHandleAndOwnership(final DefaultGraphicsDevice aDevice1, final DefaultGraphicsDevice aDevice2) {
- aDevice1.lock();
+ public static final void swapHandleAndOwnership(final DefaultGraphicsDevice a, final DefaultGraphicsDevice b) {
+ a.lock();
try {
- aDevice2.lock();
+ b.lock();
try {
- final long aDevice1Handle = aDevice1.getHandle();
- final long aDevice2Handle = aDevice2.setHandle(aDevice1Handle);
- aDevice1.setHandle(aDevice2Handle);
- final Object aOwnership1 = aDevice1.getHandleOwnership();
- final Object aOwnership2 = aDevice2.setHandleOwnership(aOwnership1);
- aDevice1.setHandleOwnership(aOwnership2);
+ final long aHandle = a.getHandle();
+ final long bHandle = b.setHandle(aHandle);
+ a.setHandle(bHandle);
+ final Object aOwnership = a.getHandleOwnership();
+ final Object bOwnership = b.setHandleOwnership(aOwnership);
+ a.setHandleOwnership(bOwnership);
} finally {
- aDevice2.unlock();
+ b.unlock();
}
} finally {
- aDevice1.unlock();
+ a.unlock();
}
}
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/NativeWindowFactory.java b/src/nativewindow/classes/com/jogamp/nativewindow/NativeWindowFactory.java
index a7a022cda..d3382fb78 100644
--- a/src/nativewindow/classes/com/jogamp/nativewindow/NativeWindowFactory.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/NativeWindowFactory.java
@@ -711,27 +711,40 @@ public abstract class NativeWindowFactory {
* </p>
*/
public static AbstractGraphicsDevice createDevice(final String nwt, final String displayConnection, final boolean own) {
+ return createDevice(nwt, displayConnection, AbstractGraphicsDevice.DEFAULT_UNIT, own);
+ }
+
+ /**
+ * Creates a native device type, following the given {@link #getNativeWindowType(boolean) native-window-type}.
+ * <p>
+ * The device will be opened if <code>own</code> is true, otherwise no native handle will ever be acquired.
+ * </p>
+ * <p>
+ * FIXME: Bug 973 Needs service provider interface (SPI) for TK dependent implementation
+ * </p>
+ */
+ public static AbstractGraphicsDevice createDevice(final String nwt, final String displayConnection, final int unitID, final boolean own) {
if( NativeWindowFactory.TYPE_X11 == nwt ) {
if( own ) {
- return new com.jogamp.nativewindow.x11.X11GraphicsDevice(displayConnection, AbstractGraphicsDevice.DEFAULT_UNIT, null /* ToolkitLock */);
+ return new com.jogamp.nativewindow.x11.X11GraphicsDevice(displayConnection, unitID, null /* ToolkitLock */);
} else {
- return new com.jogamp.nativewindow.x11.X11GraphicsDevice(displayConnection, AbstractGraphicsDevice.DEFAULT_UNIT);
+ return new com.jogamp.nativewindow.x11.X11GraphicsDevice(displayConnection, unitID);
}
} else if( NativeWindowFactory.TYPE_WINDOWS == nwt ) {
- return new com.jogamp.nativewindow.windows.WindowsGraphicsDevice(AbstractGraphicsDevice.DEFAULT_UNIT);
+ return new com.jogamp.nativewindow.windows.WindowsGraphicsDevice(unitID);
} else if( NativeWindowFactory.TYPE_MACOSX == nwt ) {
- return new com.jogamp.nativewindow.macosx.MacOSXGraphicsDevice(AbstractGraphicsDevice.DEFAULT_UNIT);
+ return new com.jogamp.nativewindow.macosx.MacOSXGraphicsDevice(unitID);
} else if( NativeWindowFactory.TYPE_IOS == nwt ) {
- return new com.jogamp.nativewindow.ios.IOSGraphicsDevice(AbstractGraphicsDevice.DEFAULT_UNIT);
+ return new com.jogamp.nativewindow.ios.IOSGraphicsDevice(unitID);
} else if( NativeWindowFactory.TYPE_EGL == nwt ) {
final com.jogamp.nativewindow.egl.EGLGraphicsDevice device;
if( own ) {
Object odev = null;
try {
- // EGLDisplayUtil.eglCreateEGLGraphicsDevice(EGL.EGL_DEFAULT_DISPLAY, AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT);
+ // EGLDisplayUtil.eglCreateEGLGraphicsDevice(EGL.EGL_DEFAULT_DISPLAY, AbstractGraphicsDevice.DEFAULT_CONNECTION, unitID);
odev = ReflectionUtil.callStaticMethod("jogamp.opengl.egl.EGLDisplayUtil", "eglCreateEGLGraphicsDevice",
new Class<?>[] { Long.class, String.class, Integer.class},
- new Object[] { 0L /* EGL.EGL_DEFAULT_DISPLAY */, DefaultGraphicsDevice.getDefaultDisplayConnection(nwt), AbstractGraphicsDevice.DEFAULT_UNIT },
+ new Object[] { 0L /* EGL.EGL_DEFAULT_DISPLAY */, DefaultGraphicsDevice.getDefaultDisplayConnection(nwt), unitID },
NativeWindowFactory.class.getClassLoader());
} catch (final Exception e) {
throw new NativeWindowException("EGLDisplayUtil.eglCreateEGLGraphicsDevice failed", e);
@@ -743,13 +756,13 @@ public abstract class NativeWindowFactory {
throw new NativeWindowException("EGLDisplayUtil.eglCreateEGLGraphicsDevice failed");
}
} else {
- device = new com.jogamp.nativewindow.egl.EGLGraphicsDevice(0 /* EGL.EGL_DEFAULT_DISPLAY */, displayConnection, AbstractGraphicsDevice.DEFAULT_UNIT);
+ device = new com.jogamp.nativewindow.egl.EGLGraphicsDevice(0 /* EGL.EGL_DEFAULT_DISPLAY */, displayConnection, unitID);
}
return device;
} else if( NativeWindowFactory.TYPE_AWT == nwt ) {
throw new UnsupportedOperationException("n/a for windowing system: "+nwt);
} else {
- return new DefaultGraphicsDevice(nwt, displayConnection, AbstractGraphicsDevice.DEFAULT_UNIT);
+ return new DefaultGraphicsDevice(nwt, displayConnection, unitID);
}
}
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/egl/EGLGraphicsDevice.java b/src/nativewindow/classes/com/jogamp/nativewindow/egl/EGLGraphicsDevice.java
index fc58f4140..d9a7c8746 100644
--- a/src/nativewindow/classes/com/jogamp/nativewindow/egl/EGLGraphicsDevice.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/egl/EGLGraphicsDevice.java
@@ -49,7 +49,6 @@ public class EGLGraphicsDevice extends DefaultGraphicsDevice implements Cloneabl
public static final int EGL_NO_DISPLAY = 0;
private final long[] nativeDisplayID = new long[1];
- private /* final */ EGLDisplayLifecycleCallback eglLifecycleCallback;
private VersionNumber eglVersion = VersionNumber.zeroVersion;
/**
@@ -102,7 +101,7 @@ public class EGLGraphicsDevice extends DefaultGraphicsDevice implements Cloneabl
{
super(NativeWindowFactory.TYPE_EGL, connection, unitID, handle);
this.nativeDisplayID[0] = nativeDisplayID;
- this.eglLifecycleCallback = eglLifecycleCallback;
+ setHandleOwnership(eglLifecycleCallback);
}
/**
@@ -219,13 +218,13 @@ public class EGLGraphicsDevice extends DefaultGraphicsDevice implements Cloneabl
*/
@Override
public boolean open() {
- if(null != eglLifecycleCallback && 0 == handle) {
+ if(isHandleOwner() && 0 == handle) {
if(DEBUG) {
System.err.println(Thread.currentThread().getName() + " - EGLGraphicsDevice.open(): "+this);
}
final int[] major = { 0 };
final int[] minor = { 0 };
- handle = eglLifecycleCallback.eglGetAndInitDisplay(nativeDisplayID, major, minor);
+ handle = getEGLLifecycleCallback().eglGetAndInitDisplay(nativeDisplayID, major, minor);
if(0 == handle) {
eglVersion = VersionNumber.zeroVersion;
throw new NativeWindowException("EGLGraphicsDevice.open() failed: "+this);
@@ -245,32 +244,17 @@ public class EGLGraphicsDevice extends DefaultGraphicsDevice implements Cloneabl
*/
@Override
public boolean close() {
- if(null != eglLifecycleCallback && 0 != handle) {
+ if(isHandleOwner() && 0 != handle) {
if(DEBUG) {
System.err.println(Thread.currentThread().getName() + " - EGLGraphicsDevice.close(): "+this);
}
- eglLifecycleCallback.eglTerminate(handle);
+ getEGLLifecycleCallback().eglTerminate(handle);
}
return super.close();
}
- @Override
- public boolean isHandleOwner() {
- return null != eglLifecycleCallback;
- }
- @Override
- public void clearHandleOwner() {
- eglLifecycleCallback = null;
- }
- @Override
- protected Object getHandleOwnership() {
- return eglLifecycleCallback;
- }
- @Override
- protected Object setHandleOwnership(final Object newOwnership) {
- final EGLDisplayLifecycleCallback oldOwnership = eglLifecycleCallback;
- eglLifecycleCallback = (EGLDisplayLifecycleCallback) newOwnership;
- return oldOwnership;
+ private EGLDisplayLifecycleCallback getEGLLifecycleCallback() {
+ return (EGLDisplayLifecycleCallback) getHandleOwnership();
}
@Override
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/x11/X11GraphicsDevice.java b/src/nativewindow/classes/com/jogamp/nativewindow/x11/X11GraphicsDevice.java
index 29ed5e8fd..fe2852172 100644
--- a/src/nativewindow/classes/com/jogamp/nativewindow/x11/X11GraphicsDevice.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/x11/X11GraphicsDevice.java
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
- * Copyright (c) 2010 JogAmp Community. All rights reserved.
+ * Copyright (c) 2010-2024 JogAmp Community. All rights reserved.
+ * Copyright (c) 2008-2009 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -45,7 +45,6 @@ import com.jogamp.nativewindow.ToolkitLock;
*/
public class X11GraphicsDevice extends DefaultGraphicsDevice implements Cloneable {
- /* final */ boolean handleOwner;
final boolean isXineramaEnabled;
/** Constructs a new X11GraphicsDevice corresponding to the given connection and default
@@ -56,7 +55,7 @@ public class X11GraphicsDevice extends DefaultGraphicsDevice implements Cloneabl
*/
public X11GraphicsDevice(final String connection, final int unitID) {
super(NativeWindowFactory.TYPE_X11, connection, unitID);
- handleOwner = false;
+ setHandleOwnership(false);
isXineramaEnabled = false;
}
@@ -78,7 +77,7 @@ public class X11GraphicsDevice extends DefaultGraphicsDevice implements Cloneabl
if(0==display) {
throw new NativeWindowException("null display");
}
- handleOwner = owner;
+ setHandleOwnership(owner);
isXineramaEnabled = X11Util.XineramaIsEnabled(this);
}
@@ -93,7 +92,7 @@ public class X11GraphicsDevice extends DefaultGraphicsDevice implements Cloneabl
*/
public X11GraphicsDevice(final String displayConnection, final int unitID, final ToolkitLock locker) {
super(NativeWindowFactory.TYPE_X11, displayConnection, unitID, 0, locker);
- handleOwner = true;
+ setHandleOwnership(true);
open();
isXineramaEnabled = X11Util.XineramaIsEnabled(this);
}
@@ -139,7 +138,7 @@ public class X11GraphicsDevice extends DefaultGraphicsDevice implements Cloneabl
@Override
public boolean open() {
- if(handleOwner && 0 == handle) {
+ if(isHandleOwner() && 0 == handle) {
if(DEBUG) {
System.err.println(Thread.currentThread().getName() + " - X11GraphicsDevice.open(): "+this);
}
@@ -154,7 +153,7 @@ public class X11GraphicsDevice extends DefaultGraphicsDevice implements Cloneabl
@Override
public boolean close() {
- if(handleOwner && 0 != handle) {
+ if(isHandleOwner() && 0 != handle) {
if(DEBUG) {
System.err.println(Thread.currentThread().getName() + " - X11GraphicsDevice.close(): "+this);
}
@@ -163,22 +162,9 @@ public class X11GraphicsDevice extends DefaultGraphicsDevice implements Cloneabl
return super.close();
}
- @Override
- public boolean isHandleOwner() {
- return handleOwner;
- }
- @Override
- public void clearHandleOwner() {
- handleOwner = false;
- }
- @Override
- protected Object getHandleOwnership() {
- return Boolean.valueOf(handleOwner);
- }
- @Override
- protected Object setHandleOwnership(final Object newOwnership) {
- final Boolean oldOwnership = Boolean.valueOf(handleOwner);
- handleOwner = ((Boolean) newOwnership).booleanValue();
- return oldOwnership;
+ private boolean setHandleOwnership(final boolean v) {
+ final Boolean o = (Boolean)getHandleOwnership();
+ super.setHandleOwnership(v ? Boolean.valueOf(true) : null);
+ return null != o ? o.booleanValue() : false;
}
}