/** * Cleanup resources. * * <p>Called by {@link NativeWindowFactory#shutdown()} * * @see ToolkitProperties */ public static void shutdown() { if (isInit) { synchronized (X11Util.class) { if (isInit) { final boolean isJVMShuttingDown = NativeWindowFactory.isJVMShuttingDown(); if (DEBUG || ((openDisplayMap.size() > 0 || reusableDisplayList.size() > 0 || pendingDisplayList.size() > 0) && (reusableDisplayList.size() != pendingDisplayList.size() || !markAllDisplaysUnclosable))) { System.err.println( "X11Util.Display: Shutdown (JVM shutdown: " + isJVMShuttingDown + ", open (no close attempt): " + openDisplayMap.size() + "/" + openDisplayList.size() + ", reusable (open, marked uncloseable): " + reusableDisplayList.size() + ", pending (open in creation order): " + pendingDisplayList.size() + ")"); if (DEBUG) { Thread.dumpStack(); } if (openDisplayList.size() > 0) { X11Util.dumpOpenDisplayConnections(); } if (DEBUG) { if (reusableDisplayList.size() > 0 || pendingDisplayList.size() > 0) { X11Util.dumpPendingDisplayConnections(); } } } // Only at JVM shutdown time, since AWT impl. seems to // dislike closing of X11 Display's (w/ ATI driver). if (isJVMShuttingDown) { synchronized (globalLock) { isInit = false; closePendingDisplayConnections(); openDisplayList.clear(); reusableDisplayList.clear(); pendingDisplayList.clear(); openDisplayMap.clear(); displayXineramaEnabledMap.clear(); shutdown0(); } } } } } }
public static void closeDisplay(long handle) { synchronized (globalLock) { final NamedDisplay namedDpy = (NamedDisplay) openDisplayMap.remove(handle); if (null == namedDpy) { X11Util.dumpPendingDisplayConnections(); throw new RuntimeException( "X11Util.Display: Display(0x" + Long.toHexString(handle) + ") with given handle is not mapped. Thread " + Thread.currentThread().getName()); } if (namedDpy.getHandle() != handle) { X11Util.dumpPendingDisplayConnections(); throw new RuntimeException( "X11Util.Display: Display(0x" + Long.toHexString(handle) + ") Mapping error: " + namedDpy + ". Thread " + Thread.currentThread().getName()); } namedDpy.removeRef(); if (!openDisplayList.remove(namedDpy)) { throw new RuntimeException("Internal: " + namedDpy); } if (markAllDisplaysUnclosable) { // if set-mark 'slipped' this one .. just to be safe! namedDpy.setUncloseable(true); } if (!namedDpy.isUncloseable()) { XCloseDisplay(namedDpy.getHandle()); pendingDisplayList.remove(namedDpy); } else { // for reuse X11Lib.XSync(namedDpy.getHandle(), true); // flush output buffer and discard all events reusableDisplayList.add(namedDpy); } if (DEBUG) { System.err.println( "X11Util.Display: Closed (real: " + (!namedDpy.isUncloseable()) + ") " + namedDpy + ". Thread " + Thread.currentThread().getName()); } } }
/** * {@inheritDoc} * * <p>We use a private non-shared X11 Display instance for EDT window operations and one for * exposed animation, eg. OpenGL. */ protected void createNativeImpl() { X11Util.setX11ErrorHandler(true, DEBUG ? false : true); // make sure X11 error handler is set long handle = X11Util.openDisplay(name); if (0 == handle) { throw new RuntimeException("Error creating display(Win): " + name); } aDevice = new X11GraphicsDevice(handle, AbstractGraphicsDevice.DEFAULT_UNIT, true /* owner */); try { CompleteDisplay0(aDevice.getHandle()); } catch (RuntimeException e) { closeNativeImpl(); throw e; } }
@Override protected final ProxySurface createMutableSurfaceImpl( AbstractGraphicsDevice deviceReq, boolean createNewDevice, GLCapabilitiesImmutable capsChosen, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser, UpstreamSurfaceHook upstreamHook) { final X11GraphicsDevice device; if (createNewDevice || !(deviceReq instanceof X11GraphicsDevice)) { device = new X11GraphicsDevice( X11Util.openDisplay(deviceReq.getConnection()), deviceReq.getUnitID(), true /* owner */); } else { device = (X11GraphicsDevice) deviceReq; } final X11GraphicsScreen screen = new X11GraphicsScreen(device, device.getDefaultScreen()); final X11GLXGraphicsConfiguration config = X11GLXGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic( capsChosen, capsRequested, chooser, screen, VisualIDHolder.VID_UNDEFINED); if (null == config) { throw new GLException( "Choosing GraphicsConfiguration failed w/ " + capsChosen + " on " + screen); } return new WrappedSurface(config, 0, upstreamHook, createNewDevice); }
@Override protected final void resetGammaRamp( final DeviceScreenID deviceScreenID, final Buffer originalGammaRamp) { if (originalGammaRamp == null) { return; // getGammaRamp failed originally } final long display = X11Util.openDisplay(deviceScreenID.deviceConnection); if (0 == display) { return; } try { resetGammaRamp(display, deviceScreenID.screenIdx, originalGammaRamp); } finally { X11Util.closeDisplay(display); } }
/** * Constructs a new X11GraphicsDevice corresponding to the given native display handle and default * {@link javax.media.nativewindow.ToolkitLock} via {@link * NativeWindowFactory#createDefaultToolkitLock(java.lang.String, long)}. */ public X11GraphicsDevice(long display, int unitID) { // FIXME: derive unitID from connection could be buggy, one DISPLAY for all screens for // example.. super(NativeWindowFactory.TYPE_X11, X11Util.XDisplayString(display), unitID, display); if (0 == display) { throw new NativeWindowException("null display"); } }
public boolean close() { // FIXME: shall we respect the unitID ? if (closeDisplay && 0 != handle) { if (DEBUG) { System.err.println( Thread.currentThread().getName() + " - X11GraphicsDevice.close(): " + this); } X11Util.closeDisplay(handle); handle = 0; return true; } return false; }
public X11GLXDrawableFactory() { super(); synchronized (X11GLXDrawableFactory.class) { if (null == x11GLXDynamicLookupHelper) { x11GLXDynamicLookupHelper = AccessController.doPrivileged( new PrivilegedAction<DesktopGLDynamicLookupHelper>() { @Override public DesktopGLDynamicLookupHelper run() { DesktopGLDynamicLookupHelper tmp; try { tmp = new DesktopGLDynamicLookupHelper(new X11GLXDynamicLibraryBundleInfo()); if (null != tmp && tmp.isLibComplete()) { GLX.getGLXProcAddressTable().reset(tmp); } } catch (final Exception ex) { tmp = null; if (DEBUG) { ex.printStackTrace(); } } return tmp; } }); } } defaultDevice = new X11GraphicsDevice(X11Util.getNullDisplayName(), AbstractGraphicsDevice.DEFAULT_UNIT); if (null != x11GLXDynamicLookupHelper) { // Register our GraphicsConfigurationFactory implementations // The act of constructing them causes them to be registered X11GLXGraphicsConfigurationFactory.registerFactory(); sharedMap = new HashMap<String, SharedResourceRunner.Resource>(); // Init shared resources off thread // Will be released via ShutdownHook sharedResourceRunner = new SharedResourceRunner(new SharedResourceImplementation()); sharedResourceRunner.start(); } }
@Override public boolean isDeviceSupported(final AbstractGraphicsDevice device) { final boolean res; final X11GraphicsDevice x11Device = new X11GraphicsDevice( X11Util.openDisplay(device.getConnection()), device.getUnitID(), true /* owner */); x11Device.lock(); try { res = GLXUtil.isGLXAvailableOnServer(x11Device); } finally { x11Device.unlock(); x11Device.close(); } if (DEBUG) { System.err.println( "GLX " + (res ? "is" : "not") + " available on device/server: " + x11Device); } return res; }
@Override protected final ProxySurface createProxySurfaceImpl( AbstractGraphicsDevice deviceReq, int screenIdx, long windowHandle, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser, UpstreamSurfaceHook upstream) { final X11GraphicsDevice device = new X11GraphicsDevice( X11Util.openDisplay(deviceReq.getConnection()), deviceReq.getUnitID(), true /* owner */); final X11GraphicsScreen screen = new X11GraphicsScreen(device, screenIdx); final int xvisualID = X11Lib.GetVisualIDFromWindow(device.getHandle(), windowHandle); if (VisualIDHolder.VID_UNDEFINED == xvisualID) { throw new GLException( "Undefined VisualID of window 0x" + Long.toHexString(windowHandle) + ", window probably invalid"); } if (DEBUG) { System.err.println( "X11GLXDrawableFactory.createProxySurfaceImpl 0x" + Long.toHexString(windowHandle) + ": visualID 0x" + Integer.toHexString(xvisualID)); } final X11GLXGraphicsConfiguration cfg = X11GLXGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic( capsRequested, capsRequested, chooser, screen, xvisualID); if (DEBUG) { System.err.println( "X11GLXDrawableFactory.createProxySurfaceImpl 0x" + Long.toHexString(windowHandle) + ": " + cfg); } return new WrappedSurface(cfg, windowHandle, upstream, true); }
@Override public SharedResourceRunner.Resource createSharedResource(String connection) { final X11GraphicsDevice sharedDevice = new X11GraphicsDevice( X11Util.openDisplay(connection), AbstractGraphicsDevice.DEFAULT_UNIT, true /* owner */); sharedDevice.lock(); try { final X11GraphicsScreen sharedScreen = new X11GraphicsScreen(sharedDevice, sharedDevice.getDefaultScreen()); GLXUtil.initGLXClientDataSingleton(sharedDevice); final String glXServerVendorName = GLX.glXQueryServerString(sharedDevice.getHandle(), 0, GLX.GLX_VENDOR); final boolean glXServerMultisampleAvailable = GLXUtil.isMultisampleAvailable( GLX.glXQueryServerString(sharedDevice.getHandle(), 0, GLX.GLX_EXTENSIONS)); final GLProfile glp = GLProfile.get(sharedDevice, GLProfile.GL_PROFILE_LIST_MIN_DESKTOP, false); if (null == glp) { throw new GLException("Couldn't get default GLProfile for device: " + sharedDevice); } final GLCapabilitiesImmutable caps = new GLCapabilities(glp); final GLDrawableImpl sharedDrawable = createOnscreenDrawableImpl( createDummySurfaceImpl(sharedDevice, false, caps, caps, null, 64, 64)); sharedDrawable.setRealized(true); final X11GLCapabilities chosenCaps = (X11GLCapabilities) sharedDrawable.getChosenGLCapabilities(); final boolean glxForcedOneOne = !chosenCaps.hasFBConfig(); final VersionNumber glXServerVersion; if (glxForcedOneOne) { glXServerVersion = versionOneOne; } else { glXServerVersion = GLXUtil.getGLXServerVersionNumber(sharedDevice); } final GLContextImpl sharedContext = (GLContextImpl) sharedDrawable.createContext(null); if (null == sharedContext) { throw new GLException("Couldn't create shared context for drawable: " + sharedDrawable); } boolean madeCurrent = false; sharedContext.makeCurrent(); try { madeCurrent = sharedContext.isCurrent(); } finally { sharedContext.release(); } if (sharedContext.hasRendererQuirk(GLRendererQuirks.DontCloseX11Display)) { X11Util.markAllDisplaysUnclosable(); } if (DEBUG) { System.err.println("SharedDevice: " + sharedDevice); System.err.println("SharedScreen: " + sharedScreen); System.err.println("SharedContext: " + sharedContext + ", madeCurrent " + madeCurrent); System.err.println("GLX Server Vendor: " + glXServerVendorName); System.err.println( "GLX Server Version: " + glXServerVersion + ", forced " + glxForcedOneOne); System.err.println("GLX Server Multisample: " + glXServerMultisampleAvailable); System.err.println("GLX Client Vendor: " + GLXUtil.getClientVendorName()); System.err.println("GLX Client Version: " + GLXUtil.getClientVersionNumber()); System.err.println("GLX Client Multisample: " + GLXUtil.isClientMultisampleAvailable()); } return new SharedResource( sharedDevice, sharedScreen, sharedDrawable, sharedContext, glXServerVersion, glXServerVendorName, glXServerMultisampleAvailable && GLXUtil.isClientMultisampleAvailable()); } catch (Throwable t) { throw new GLException( "X11GLXDrawableFactory - Could not initialize shared resources for " + connection, t); } finally { sharedDevice.unlock(); } }
public String validateDisplayName(String name, long handle) { return X11Util.validateDisplayName(name, handle); }
/** * @param display the Display connection * @param locker custom {@link javax.media.nativewindow.ToolkitLock}, eg to force null locking in * NEWT */ public X11GraphicsDevice(long display, int unitID, ToolkitLock locker) { super(NativeWindowFactory.TYPE_X11, X11Util.XDisplayString(display), unitID, display, locker); if (0 == display) { throw new NativeWindowException("null display"); } }
protected void createNativeImpl() { final ScreenDriver screen = (ScreenDriver) getScreen(); final DisplayDriver display = (DisplayDriver) screen.getDisplay(); final AbstractGraphicsDevice edtDevice = display.getGraphicsDevice(); // Decoupled X11 Device/Screen allowing X11 display lock-free off-thread rendering final long renderDeviceHandle = X11Util.openDisplay(edtDevice.getConnection()); if (0 == renderDeviceHandle) { throw new RuntimeException("Error creating display(EDT): " + edtDevice.getConnection()); } renderDevice = new X11GraphicsDevice( renderDeviceHandle, AbstractGraphicsDevice.DEFAULT_UNIT, true /* owner */); final AbstractGraphicsScreen renderScreen = new X11GraphicsScreen(renderDevice, screen.getIndex()); final GraphicsConfigurationFactory factory = GraphicsConfigurationFactory.getFactory(display.getGraphicsDevice(), capsRequested); final AbstractGraphicsConfiguration cfg = factory.chooseGraphicsConfiguration( capsRequested, capsRequested, capabilitiesChooser, renderScreen, VisualIDHolder.VID_UNDEFINED); if (DEBUG_IMPLEMENTATION) { System.err.println( "X11Window.createNativeImpl() factory: " + factory + ", chosen config: " + cfg); } if (null == cfg) { throw new NativeWindowException( "Error choosing GraphicsConfiguration creating window: " + this); } final int visualID = cfg.getVisualID(VIDType.NATIVE); if (VisualIDHolder.VID_UNDEFINED == visualID) { throw new NativeWindowException("Chosen Configuration w/o native visual ID: " + cfg); } setGraphicsConfiguration(cfg); final int flags = getReconfigureFlags(0, true) & (FLAG_IS_ALWAYSONTOP | FLAG_IS_UNDECORATED); edtDevice.lock(); try { setWindowHandle( CreateWindow0( getParentWindowHandle(), edtDevice.getHandle(), screen.getIndex(), visualID, display.getJavaObjectAtom(), display.getWindowDeleteAtom(), getX(), getY(), getWidth(), getHeight(), autoPosition(), flags)); } finally { edtDevice.unlock(); } windowHandleClose = getWindowHandle(); if (0 == windowHandleClose) { throw new NativeWindowException("Error creating window"); } }
private void handleDontCloseX11DisplayQuirk(GLRendererQuirks quirks) { if (null != quirks && quirks.exist(GLRendererQuirks.DontCloseX11Display)) { jogamp.nativewindow.x11.X11Util.markAllDisplaysUnclosable(); } }
@Override public SharedResourceRunner.Resource createSharedResource( final AbstractGraphicsDevice adevice) { final X11GraphicsDevice device = new X11GraphicsDevice( X11Util.openDisplay(adevice.getConnection()), adevice.getUnitID(), true /* owner */); GLContextImpl context = null; boolean contextIsCurrent = false; device.lock(); try { final X11GraphicsScreen screen = new X11GraphicsScreen(device, device.getDefaultScreen()); GLXUtil.initGLXClientDataSingleton(device); final String glXServerVendorName = GLX.glXQueryServerString(device.getHandle(), 0, GLX.GLX_VENDOR); final boolean glXServerMultisampleAvailable = GLXUtil.isMultisampleAvailable( GLX.glXQueryServerString(device.getHandle(), 0, GLX.GLX_EXTENSIONS)); final GLProfile glp = GLProfile.get(device, GLProfile.GL_PROFILE_LIST_MIN_DESKTOP, false); if (null == glp) { throw new GLException("Couldn't get default GLProfile for device: " + device); } final GLCapabilitiesImmutable caps = new GLCapabilities(glp); final GLDrawableImpl drawable = createOnscreenDrawableImpl( createDummySurfaceImpl(device, false, caps, caps, null, 64, 64)); drawable.setRealized(true); final X11GLCapabilities chosenCaps = (X11GLCapabilities) drawable.getChosenGLCapabilities(); final boolean glxForcedOneOne = !chosenCaps.hasFBConfig(); final VersionNumber glXServerVersion; if (glxForcedOneOne) { glXServerVersion = versionOneOne; } else { glXServerVersion = GLXUtil.getGLXServerVersionNumber(device); } context = (GLContextImpl) drawable.createContext(null); if (null == context) { throw new GLException("Couldn't create shared context for drawable: " + drawable); } contextIsCurrent = GLContext.CONTEXT_NOT_CURRENT != context.makeCurrent(); final boolean allowsSurfacelessCtx; if (contextIsCurrent && context.getGLVersionNumber().compareTo(GLContext.Version3_0) >= 0) { allowsSurfacelessCtx = probeSurfacelessCtx(context, true /* restoreDrawable */); } else { setNoSurfacelessCtxQuirk(context); allowsSurfacelessCtx = false; } if (context.hasRendererQuirk(GLRendererQuirks.DontCloseX11Display)) { X11Util.markAllDisplaysUnclosable(); } if (DEBUG_SHAREDCTX) { System.err.println("SharedDevice: " + device); System.err.println("SharedScreen: " + screen); System.err.println("SharedContext: " + context + ", madeCurrent " + contextIsCurrent); System.err.println(" allowsSurfacelessCtx " + allowsSurfacelessCtx); System.err.println("GLX Server Vendor: " + glXServerVendorName); System.err.println( "GLX Server Version: " + glXServerVersion + ", forced " + glxForcedOneOne); System.err.println("GLX Server Multisample: " + glXServerMultisampleAvailable); System.err.println("GLX Client Vendor: " + GLXUtil.getClientVendorName()); System.err.println("GLX Client Version: " + GLXUtil.getClientVersionNumber()); System.err.println("GLX Client Multisample: " + GLXUtil.isClientMultisampleAvailable()); } return new SharedResource( device, screen, drawable, context, glXServerVersion, glXServerVendorName, glXServerMultisampleAvailable && GLXUtil.isClientMultisampleAvailable()); } catch (final Throwable t) { throw new GLException( "X11GLXDrawableFactory - Could not initialize shared resources for " + adevice, t); } finally { if (contextIsCurrent) { context.release(); } device.unlock(); } }