Skip to content

Commit

Permalink
Fixes Bug 615 - X11: Use proper screen index/name for shared resource…
Browse files Browse the repository at this point in the history
…s and device denominated 'mutable' surfaces (dummy, offscreen, ..)

Fix follows findings of Rob Hatcherson, but instead of parsing the display connection ourself
we use the X11 macro 'DefaultScreen(display)'

See <http://tronche.com/gui/x/xlib/display/opening.html#Display>

"The screen number specified in the display_name argument is returned by the DefaultScreen() macro
(or the XDefaultScreen() function)."

Since I currently have no two-head X11 setup here, only xinerama via virtualbox,
pls test / validate.

Note: One Display connection may span multiple screens, i.e.:
  display 'lala:0.1' may span from screen 1 - 3 (non xinerama mode)

Discussion:

[1] How to validate whether a screen number belongs to one display connection ?
We can query ScreenCount(display), however it is not clear what the range would be.

[2] With 1 display connection spanning multiple screens, what is/are the proper connection string[s] ?

[3] After all, it seems this ancient configuration really cannot beat a modern setup w/ XRandR
    having Xinerama enabled. The latter is the default anyways.
  • Loading branch information
sgothel committed Sep 17, 2012
1 parent 3704d15 commit c0cc74a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
6 changes: 3 additions & 3 deletions make/scripts/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function jrun() {
#D_ARGS="-Dnewt.test.Screen.disableScreenMode -Dnewt.debug.Screen"
#D_ARGS="-Djogl.debug.ExtensionAvailabilityCache -Djogl.debug=all -Dnativewindow.debug=all -Djogamp.debug.ProcAddressHelper=true -Djogamp.debug.NativeLibrary=true -Djogamp.debug.NativeLibrary.Lookup=true"
#D_ARGS="-Dnewt.debug.MainThread"
D_ARGS="-Dnewt.debug.Window"
#D_ARGS="-Dnewt.debug.Window"
#D_ARGS="-Dnativewindow.debug.GraphicsConfiguration -Dnativewindow.debug.NativeWindow"
#D_ARGS="-Djogl.debug.GLCanvas -Djogl.debug.Animator -Djogl.debug.GLDrawable -Djogl.debug.GLContext -Djogl.debug.GLContext.TraceSwitch"
#D_ARGS="-Djogl.debug.GLContext -Djogl.debug.ExtensionAvailabilityCache"
Expand Down Expand Up @@ -273,7 +273,7 @@ function testawtswt() {

#testnoawt com.jogamp.opengl.test.junit.jogl.glu.TestGluUnprojectFloatNOUI $*
#testnoawt com.jogamp.opengl.test.junit.newt.TestRemoteWindow01NEWT $*
#testnoawt com.jogamp.opengl.test.junit.newt.TestRemoteGLWindows01NEWT $*
testnoawt com.jogamp.opengl.test.junit.newt.TestRemoteGLWindows01NEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.demos.gl2.newt.TestGearsNEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es1.newt.TestGearsES1NEWT $*
#testawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT $*
Expand Down Expand Up @@ -350,7 +350,7 @@ function testawtswt() {
#testawt com.jogamp.opengl.test.junit.jogl.newt.TestSwingAWTRobotUsageBeforeJOGLInitBug411 $*
#testawt com.jogamp.opengl.test.junit.jogl.demos.gl2.newt.TestGearsNewtAWTWrapper $*
#testawt com.jogamp.opengl.test.junit.newt.TestEventSourceNotAWTBug
testawt com.jogamp.opengl.test.junit.newt.TestFocus01SwingAWTRobot $*
#testawt com.jogamp.opengl.test.junit.newt.TestFocus01SwingAWTRobot $*
#testawt com.jogamp.opengl.test.junit.newt.TestFocus02SwingAWTRobot $*
#testawt com.jogamp.opengl.test.junit.newt.TestListenerCom01AWT
#testawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting01aAWT $*
Expand Down
5 changes: 4 additions & 1 deletion make/stub_includes/x11/window-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ extern void XLockDisplay(Display *display);

extern void XUnlockDisplay(Display *display);

extern Window RootWindow(Display *display, int screen_number);
extern int DefaultScreen(Display *display);

extern int ScreenCount(Display *display);

extern Window RootWindow(Display *display, int screen_number);

extern XVisualInfo *XGetVisualInfo(
Display* /* display */,
long /* vinfo_mask */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public SharedResourceRunner.Resource createSharedResource(String connection) {
// NativeWindowFactory.getNullToolkitLock(), true); // own non-shared display connection, w/o locking
sharedDevice.lock();
try {
final X11GraphicsScreen sharedScreen = new X11GraphicsScreen(sharedDevice, 0);
final X11GraphicsScreen sharedScreen = new X11GraphicsScreen(sharedDevice, sharedDevice.getDefaultScreen());

if(!GLXUtil.isGLXAvailableOnServer(sharedDevice)) {
throw new GLException("GLX not available on device/server: "+sharedDevice);
Expand Down Expand Up @@ -514,7 +514,7 @@ protected final ProxySurface createMutableSurfaceImpl(AbstractGraphicsDevice dev
} else {
device = (X11GraphicsDevice)deviceReq;
}
final X11GraphicsScreen screen = new X11GraphicsScreen(device, 0);
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,34 @@ public X11GraphicsDevice(long display, int unitID, ToolkitLock locker, boolean o
handleOwner = owner;
}

private static int getDefaultScreenImpl(long dpy) {
return X11Lib.DefaultScreen(dpy);
}

/**
* Returns the default screen number as referenced by the display connection, i.e. 'somewhere:0.1' -> 1
* <p>
* Implementation uses the XLib macro <code>DefaultScreen(display)</code>.
* </p>
*/
public int getDefaultScreen() {
final long display = getHandle();
if(0==display) {
throw new NativeWindowException("null display");
}
final int ds = getDefaultScreenImpl(display);
if(DEBUG) {
System.err.println(Thread.currentThread().getName() + " - X11GraphicsDevice.getDefaultDisplay() of "+this+": "+ds+", count "+X11Lib.ScreenCount(display));
}
return ds;
}

public int getDefaultVisualID() {
// It still could be an AWT hold handle ..
final long display = getHandle();
final int scrnIdx = X11Lib.DefaultScreen(display);
return X11Lib.DefaultVisualID(display, scrnIdx);
if(0==display) {
throw new NativeWindowException("null display");
}
return X11Lib.DefaultVisualID(display, getDefaultScreenImpl(display));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

import org.junit.Assert;
import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.Test;

import javax.media.opengl.*;
Expand Down

0 comments on commit c0cc74a

Please sign in to comment.