protected static X11GLXGraphicsConfiguration createDefaultGraphicsConfiguration( AbstractGraphicsScreen absScreen, boolean onscreen, boolean usePBuffer) { if (absScreen == null) { throw new IllegalArgumentException("AbstractGraphicsScreen is null"); } if (!(absScreen instanceof X11GraphicsScreen)) { throw new IllegalArgumentException("Only X11GraphicsScreen are allowed here"); } X11GraphicsScreen x11Screen = (X11GraphicsScreen) absScreen; GLProfile glProfile = GLProfile.getDefault(); GLCapabilities caps = null; XVisualInfo xvis = null; long fbcfg = 0; int fbid = -1; // Utilizing FBConfig // GLCapabilities capsFB = null; long display = x11Screen.getDevice().getHandle(); try { NativeWindowFactory.getDefaultFactory().getToolkitLock().lock(); X11Lib.XLockDisplay(display); int screen = x11Screen.getIndex(); boolean isMultisampleAvailable = GLXUtil.isMultisampleAvailable(display); long visID = X11Lib.DefaultVisualID(display, x11Screen.getIndex()); xvis = X11GLXGraphicsConfiguration.XVisualID2XVisualInfo(display, visID); caps = X11GLXGraphicsConfiguration.XVisualInfo2GLCapabilities( glProfile, display, xvis, onscreen, usePBuffer, isMultisampleAvailable); int[] attribs = X11GLXGraphicsConfiguration.GLCapabilities2AttribList( caps, true, isMultisampleAvailable, display, screen); int[] count = {-1}; PointerBuffer fbcfgsL = GLX.glXChooseFBConfigCopied(display, screen, attribs, 0, count, 0); if (fbcfgsL == null || fbcfgsL.limit() < 1) { throw new Exception("Could not fetch FBConfig for " + caps); } fbcfg = fbcfgsL.get(0); capsFB = X11GLXGraphicsConfiguration.GLXFBConfig2GLCapabilities( glProfile, display, fbcfg, true, onscreen, usePBuffer, isMultisampleAvailable); fbid = X11GLXGraphicsConfiguration.glXFBConfig2FBConfigID(display, fbcfg); xvis = GLX.glXGetVisualFromFBConfigCopied(display, fbcfg); if (xvis == null) { throw new GLException("Error: Choosen FBConfig has no visual"); } } catch (Throwable t) { } finally { X11Lib.XUnlockDisplay(display); NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock(); } return new X11GLXGraphicsConfiguration( x11Screen, (null != capsFB) ? capsFB : caps, caps, null, xvis, fbcfg, fbid); }
public static boolean XineramaIsEnabled(long displayHandle) { if (0 == displayHandle) { throw new IllegalArgumentException("X11 Display handle is NULL"); } final String displayName = X11Lib.XDisplayString(displayHandle); synchronized (displayXineramaEnabledMap) { final Boolean b = displayXineramaEnabledMap.get(displayName); if (null != b) { return b.booleanValue(); } } final boolean res; if (!XineramaFetched) { // volatile: ok synchronized (X11Util.class) { if (!XineramaFetched) { XineramaLibHandle = X11Lib.XineramaGetLibHandle(); if (0 != XineramaLibHandle) { XineramaQueryFunc = X11Lib.XineramaGetQueryFunc(XineramaLibHandle); } XineramaFetched = true; } } } if (0 != XineramaQueryFunc) { res = X11Lib.XineramaIsEnabled(XineramaQueryFunc, displayHandle); } else { if (DEBUG) { System.err.println( "XineramaIsEnabled: Couldn't bind to Xinerama - lib 0x" + Long.toHexString(XineramaLibHandle) + "query 0x" + Long.toHexString(XineramaQueryFunc)); } res = false; } synchronized (displayXineramaEnabledMap) { if (DEBUG) { System.err.println( "XineramaIsEnabled Cache: Display " + displayName + " (0x" + Long.toHexString(displayHandle) + ") -> " + res); } displayXineramaEnabledMap.put(displayName, Boolean.valueOf(res)); } return res; }
/** * ***************************** * * Locked X11Lib wrapped functions * * ***************************** */ public static long XOpenDisplay(String arg0) { long handle = X11Lib.XOpenDisplay(arg0); if (XSYNC_ENABLED && 0 != handle) { X11Lib.XSynchronize(handle, true); } if (TRACE_DISPLAY_LIFECYCLE) { System.err.println( Thread.currentThread() + " - X11Util.XOpenDisplay(" + arg0 + ") 0x" + Long.toHexString(handle)); // Thread.dumpStack(); } return handle; }
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()); } } }
public static int XCloseDisplay(long display) { if (TRACE_DISPLAY_LIFECYCLE) { System.err.println( Thread.currentThread() + " - X11Util.XCloseDisplay() 0x" + Long.toHexString(display)); // Thread.dumpStack(); } int res = -1; try { res = X11Lib.XCloseDisplay(display); } catch (Exception ex) { System.err.println("X11Util: Catched Exception:"); ex.printStackTrace(); } return res; }
public static String validateDisplayName(String name, long handle) { if ((null == name || AbstractGraphicsDevice.DEFAULT_CONNECTION.equals(name)) && 0 != handle) { name = X11Lib.XDisplayString(handle); } return validateDisplayName(name); }
/** * Called by {@link NativeWindowFactory#initSingleton()} * * @see ToolkitProperties */ public static void initSingleton() { if (!isInit) { synchronized (X11Util.class) { if (!isInit) { isInit = true; if (DEBUG) { System.out.println("X11Util.initSingleton()"); } if (!NWJNILibLoader.loadNativeWindow("x11")) { throw new NativeWindowException("NativeWindow X11 native library load error."); } final boolean isInitOK = initialize0(XERROR_STACKDUMP); final boolean hasX11_EXTENSION_ATIFGLRXDRI, hasX11_EXTENSION_ATIFGLEXTENSION; final long dpy = X11Lib.XOpenDisplay( PropertyAccess.getProperty("nativewindow.x11.display.default", true)); if (0 != dpy) { if (XSYNC_ENABLED) { X11Lib.XSynchronize(dpy, true); } try { nullDisplayName = X11Lib.XDisplayString(dpy); hasX11_EXTENSION_ATIFGLRXDRI = X11Lib.QueryExtension(dpy, X11_EXTENSION_ATIFGLRXDRI); hasX11_EXTENSION_ATIFGLEXTENSION = X11Lib.QueryExtension(dpy, X11_EXTENSION_ATIFGLEXTENSION); } finally { X11Lib.XCloseDisplay(dpy); } } else { nullDisplayName = "nil"; hasX11_EXTENSION_ATIFGLRXDRI = false; hasX11_EXTENSION_ATIFGLEXTENSION = false; } final boolean isATIFGLRX = hasX11_EXTENSION_ATIFGLRXDRI || hasX11_EXTENSION_ATIFGLEXTENSION; hasThreadingIssues = ATI_HAS_MULTITHREADING_BUG && isATIFGLRX; if (!markAllDisplaysUnclosable) { markAllDisplaysUnclosable = (ATI_HAS_XCLOSEDISPLAY_BUG && isATIFGLRX) || HAS_XCLOSEDISPLAY_BUG; } if (DEBUG) { System.err.println( "X11Util.initSingleton(): OK " + isInitOK + "]" + ",\n\t X11 Display(NULL) <" + nullDisplayName + ">" + ",\n\t XSynchronize Enabled: " + XSYNC_ENABLED + ",\n\t X11_EXTENSION_ATIFGLRXDRI " + hasX11_EXTENSION_ATIFGLRXDRI + ",\n\t X11_EXTENSION_ATIFGLEXTENSION " + hasX11_EXTENSION_ATIFGLEXTENSION + ",\n\t requiresToolkitLock " + requiresToolkitLock() + ",\n\t hasThreadingIssues " + hasThreadingIssues() + ",\n\t markAllDisplaysUnclosable " + getMarkAllDisplaysUnclosable()); // Thread.dumpStack(); } } } } }
protected static X11GLXGraphicsConfiguration chooseGraphicsConfigurationXVisual( GLCapabilities capabilities, GLCapabilitiesChooser chooser, X11GraphicsScreen x11Screen) { if (chooser == null) { chooser = new DefaultGLCapabilitiesChooser(); } // Until we have a rock-solid visual selection algorithm written // in pure Java, we're going to provide the underlying window // system's selection to the chooser as a hint GLProfile glProfile = capabilities.getGLProfile(); boolean onscreen = capabilities.isOnscreen(); GLCapabilities[] caps = null; int recommendedIndex = -1; XVisualInfo retXVisualInfo = null; int chosen = -1; AbstractGraphicsDevice absDevice = x11Screen.getDevice(); long display = absDevice.getHandle(); try { NativeWindowFactory.getDefaultFactory().getToolkitLock().lock(); X11Lib.XLockDisplay(display); int screen = x11Screen.getIndex(); boolean isMultisampleAvailable = GLXUtil.isMultisampleAvailable(display); int[] attribs = X11GLXGraphicsConfiguration.GLCapabilities2AttribList( capabilities, false, isMultisampleAvailable, display, screen); XVisualInfo[] infos = null; XVisualInfo recommendedVis = GLX.glXChooseVisualCopied(display, screen, attribs, 0); if (DEBUG) { System.err.print("!!! glXChooseVisual recommended "); if (recommendedVis == null) { System.err.println("null visual"); } else { System.err.println("visual id 0x" + Long.toHexString(recommendedVis.getVisualid())); } } int[] count = new int[1]; XVisualInfo template = XVisualInfo.create(); template.setScreen(screen); infos = X11Lib.XGetVisualInfoCopied(display, X11Lib.VisualScreenMask, template, count, 0); if (infos == null || infos.length < 1) { throw new GLException("Error while enumerating available XVisualInfos"); } caps = new GLCapabilities[infos.length]; for (int i = 0; i < infos.length; i++) { caps[i] = X11GLXGraphicsConfiguration.XVisualInfo2GLCapabilities( glProfile, display, infos[i], onscreen, false, isMultisampleAvailable); // Attempt to find the visual chosen by glXChooseVisual if (recommendedVis != null && recommendedVis.getVisualid() == infos[i].getVisualid()) { recommendedIndex = i; } } try { chosen = chooser.chooseCapabilities(capabilities, caps, recommendedIndex); } catch (NativeWindowException e) { if (DEBUG) { e.printStackTrace(); } chosen = -1; } if (chosen < 0) { // keep on going .. if (DEBUG) { System.err.println( "X11GLXGraphicsConfiguration.chooseGraphicsConfigurationXVisual Failed .. unable to choose config, using first"); } chosen = 0; // default .. } else if (chosen >= caps.length) { throw new GLException( "GLCapabilitiesChooser specified invalid index (expected 0.." + (caps.length - 1) + ")"); } if (infos[chosen] == null) { throw new GLException("GLCapabilitiesChooser chose an invalid visual"); } retXVisualInfo = XVisualInfo.create(infos[chosen]); } finally { X11Lib.XUnlockDisplay(display); NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock(); } return new X11GLXGraphicsConfiguration( x11Screen, caps[chosen], capabilities, chooser, retXVisualInfo, 0, -1); }
protected static X11GLXGraphicsConfiguration chooseGraphicsConfigurationFBConfig( GLCapabilities capabilities, GLCapabilitiesChooser chooser, X11GraphicsScreen x11Screen) { int recommendedIndex = -1; GLCapabilities[] caps = null; PointerBuffer fbcfgsL = null; int chosen = -1; int retFBID = -1; XVisualInfo retXVisualInfo = null; GLProfile glProfile = capabilities.getGLProfile(); boolean onscreen = capabilities.isOnscreen(); boolean usePBuffer = capabilities.isPBuffer(); // Utilizing FBConfig // AbstractGraphicsDevice absDevice = x11Screen.getDevice(); long display = absDevice.getHandle(); try { NativeWindowFactory.getDefaultFactory().getToolkitLock().lock(); X11Lib.XLockDisplay(display); int screen = x11Screen.getIndex(); boolean isMultisampleAvailable = GLXUtil.isMultisampleAvailable(display); int[] attribs = X11GLXGraphicsConfiguration.GLCapabilities2AttribList( capabilities, true, isMultisampleAvailable, display, screen); int[] count = {-1}; fbcfgsL = GLX.glXChooseFBConfigCopied(display, screen, attribs, 0, count, 0); if (fbcfgsL == null || fbcfgsL.limit() < 1) { if (DEBUG) { System.err.println( "X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: Failed glXChooseFBConfig (" + x11Screen + "," + capabilities + "): " + fbcfgsL + ", " + count[0]); } return null; } if (!X11GLXGraphicsConfiguration.GLXFBConfigValid(display, fbcfgsL.get(0))) { if (DEBUG) { System.err.println( "X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: Failed - GLX FBConfig invalid: (" + x11Screen + "," + capabilities + "): " + fbcfgsL + ", fbcfg: 0x" + Long.toHexString(fbcfgsL.get(0))); } return null; } recommendedIndex = 0; // 1st match is always recommended .. caps = new GLCapabilities[fbcfgsL.limit()]; for (int i = 0; i < fbcfgsL.limit(); i++) { caps[i] = X11GLXGraphicsConfiguration.GLXFBConfig2GLCapabilities( glProfile, display, fbcfgsL.get(i), false, onscreen, usePBuffer, isMultisampleAvailable); } if (null == chooser) { chosen = recommendedIndex; } else { try { chosen = chooser.chooseCapabilities(capabilities, caps, recommendedIndex); } catch (NativeWindowException e) { if (DEBUG) { e.printStackTrace(); } chosen = -1; } } if (chosen < 0) { // keep on going .. if (DEBUG) { System.err.println( "X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig Failed .. unable to choose config, using first"); } chosen = 0; // default .. } else if (chosen >= caps.length) { throw new GLException( "GLCapabilitiesChooser specified invalid index (expected 0.." + (caps.length - 1) + ")"); } retFBID = X11GLXGraphicsConfiguration.glXFBConfig2FBConfigID(display, fbcfgsL.get(chosen)); retXVisualInfo = GLX.glXGetVisualFromFBConfigCopied(display, fbcfgsL.get(chosen)); if (retXVisualInfo == null) { if (DEBUG) { System.err.println( "X11GLXGraphicsConfiguration.chooseGraphicsConfigurationFBConfig: Failed glXGetVisualFromFBConfig (" + x11Screen + ", " + fbcfgsL.get(chosen) + " (Continue: " + (false == caps[chosen].isOnscreen()) + "):\n\t" + caps[chosen]); } if (caps[chosen].isOnscreen()) { // Onscreen drawables shall have a XVisual .. return null; } } } finally { X11Lib.XUnlockDisplay(display); NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock(); } return new X11GLXGraphicsConfiguration( x11Screen, caps[chosen], capabilities, chooser, retXVisualInfo, fbcfgsL.get(chosen), retFBID); }