summaryrefslogtreecommitdiffstats
path: root/src/nativewindow
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2010-09-10 05:33:17 +0200
committerSven Gothel <[email protected]>2010-09-10 05:33:17 +0200
commit63be4a40aa6ecfe9fbc6585acccbc6f6f6689377 (patch)
tree41bcd52797e1602ffa409079b7d1744a399f77b8 /src/nativewindow
parent340b1ceb07907be113e33c54d084e53ddc93e368 (diff)
NEWT: Changed Lifecycle of Display/Screen
Display/Screen: - Removed Display reusage by unique TLS key: type + name, instead use user-responsibility or Destroy-When-Unused (usage reference count). - Removed X11 Display TLS pool usage - Display creation means i, incl the later native one (X11). - Added reference counting as follows: - Display's refCount: number it is referenced by Screen: display.addReference()/display.removeReference() - Screen's refCount: number it is referenced by Window: screen.addReference()/screen.removeReference() - Lazy creation using refcount 0 -> 1 All resources are created when they are needed. This also removes redundant native Display/Screen objects, ie in case of [AWT] reparenting. - Default lifecycle is user-responsibility, ie no Destroy-When-Unused, where Window may be destroyed unrecoverable, which removes the Screen reference only. - If using optional Destroy-When-Unused a Window may be destroyed unrecoverable, which removes the Screen reference: Screen.removeReference(); IF Screen.refCount == 0 THEN Screen.destroy(); Display.removeReference(); IF Display.refCount == 0 THEN Display.destroy(); - Use Destroy-When-Unused lifecycle for all automatic created Display/Screen instances (GLWindow, NewtCanvasAWT,..) - Display/Screen destroy/create cycles valid, ie you can reuse destroyed Display/Screen's - EDTUtil: - Created right away. - Started always via invoke, if not running. - DefaultEDTUtil: - Simplified locking a bit locking on: - edtLock for start/stop - edtTasks for tasks queue - invoke-wait doubles check shouldStop - invoke-wait 'waiting' outside of edtLock +++ NEWT: Cleanup - Window.destroy/invalidate: deep -> unrecoverable - Window.isNativeWindowValid() -> Window.isNativeValid() to unify with Display/Screen - Window.isDestroyed() -> Window.isValid() to unify and simplify logic. Returns false if destroy(true) has been called. - NewtFactory.wrapDisplay(.. handle) -> NewtFactory.createDisplay(.. handle), since it actually creates a compatible display. +++ NativeWindow X11Util: Added non TLS createDisplay()/closeDisplay() +++ TODO: - Stabilize (many tests fail) - OSX
Diffstat (limited to 'src/nativewindow')
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java
index 924185210..a0936de15 100644
--- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/x11/X11Util.java
@@ -277,6 +277,44 @@ public class X11Util {
**
*******************************/
+ /** Returns this created named display. */
+ public static long createDisplay(String name) {
+ name = validateDisplayName(name);
+ long dpy = X11Lib.XOpenDisplay(name);
+ if(0==dpy) {
+ throw new NativeWindowException("X11Util.Display: Unable to create a display("+name+") connection. Thread "+Thread.currentThread().getName());
+ }
+ // if you like to debug and synchronize X11 commands ..
+ // setSynchronizeDisplay(dpy, true);
+ NamedDisplay namedDpy = new NamedDisplay(name, dpy);
+ synchronized(globalLock) {
+ globalNamedDisplayMap.put(dpy, namedDpy);
+ }
+ if(DEBUG) {
+ Exception e = new Exception("X11Util.Display: Created new global "+namedDpy+". Thread "+Thread.currentThread().getName());
+ e.printStackTrace();
+ }
+ return namedDpy.getHandle();
+ }
+
+ public static void closeDisplay(long handle) {
+ NamedDisplay namedDpy;
+
+ synchronized(globalLock) {
+ namedDpy = (NamedDisplay) globalNamedDisplayMap.remove(handle);
+ }
+ if(null==namedDpy) {
+ throw new RuntimeException("X11Util.Display: Display(0x"+Long.toHexString(handle)+") with given handle is not mapped. Thread "+Thread.currentThread().getName());
+ }
+ if(namedDpy.getHandle()!=handle) {
+ throw new RuntimeException("X11Util.Display: Display(0x"+Long.toHexString(handle)+") Mapping error: "+namedDpy+". Thread "+Thread.currentThread().getName());
+ }
+
+ if(!namedDpy.isUncloseable()) {
+ X11Lib.XCloseDisplay(namedDpy.getHandle());
+ }
+ }
+
/**
* @return If name is null, it returns the previous queried NULL display name,
* otherwise the name. */