Re: Jogl Using Wrong (Generic) Graphics Adapter
Posted by Tobi Delbruck on Dec 11, 2014; 9:59pm
URL: https://forum.jogamp.org/Jogl-Using-Wrong-Generic-Graphics-Adapter-tp4033216p4033746.html
I finally tracked down the bug cause in jAER, or at least a contributing source.
jAER uses a WindowSaver class to store (on Runtime shutdown hook) and restore (via Toolkit window open event) active window sizes and locations. This WindowSaver restores the window position by being automagically called by the window opening event.
If this class is disabled by not registering the AWTEventListener, the dropback to GDI problem goes away along with the exceptions.
No idea why this might be occurring.
My listener install code:
final WindowSaver windowSaver = new WindowSaver(null, prefs);
Toolkit.getDefaultToolkit().addAWTEventListener(windowSaver, AWTEvent.WINDOW_EVENT_MASK); // adds windowSaver as JVM-wide event handler for window events
The WiindowSaver method loadSettings that positions and resizes the window that has just been opened, taking account of screen Insets (like the windows taskbar that typically is at bottom of screen)
/** The preferred settings are loaded based on window name.
* A windows which would be displayed partly off-screen is moved to originate at 0,0.
A window which would be too tall or wide is resized to screen size.
@param frame JFrame to load settings for
*/
public void loadSettings(JFrame frame) throws IOException {
boolean resize=false; // set true if window is too big for screen
String name=frame.getTitle().replaceAll(" ", "");
int x=preferences.getInt(name+".x", 0);
int y=preferences.getInt(name+".y", 0);
int w=preferences.getInt(name+".w", DEFAULT_WIDTH);
int h=preferences.getInt(name+".h", DEFAULT_HEIGHT);
if(w!=DEFAULT_WIDTH|h!=DEFAULT_HEIGHT) {
resize=true;
}
Dimension sd=Toolkit.getDefaultToolkit().getScreenSize();
// determine the height of the windows taskbar by this roundabout proceedure
// TODO tobi removed this because it was causing a runtime native code exception using NVIDIA 181.22 driver with win xp
// replaced by hardcoded lowerInset
// lowerInset=64;
GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gs=ge.getScreenDevices(); // TODO it could be that remote session doesn't show screen that used to be used. Should check that we are not offscreen. Otherwise registy edit is required to show window!
if(gs!=null&&gs.length>0) {
if(gs.length>1){
// log.info("There are "+gs.length+" GraphicsDevice's found; using first one which is "+gs[0].getIDstring());
}
GraphicsDevice gd=gs[0];
GraphicsConfiguration[] gc=gd.getConfigurations();
if(gc!=null&&gc.length>0) {
if(gc.length>1){
// log.info("There are "+gc.length+" GraphicsConfiguration's found; using first one which is "+gc[0].toString());
}
Insets insets=Toolkit.getDefaultToolkit().getScreenInsets(gc[0]);
lowerInset=insets.bottom;
}
}
if(x<0){
log.info("window x origin is <0, moving back to zero");
x=0;
}
if(y<lowerInset){
log.info("window y origin is < lowerInset, moving back to "+lowerInset);
y=lowerInset;
}
if(x+w>sd.width||y+h>sd.height) {
log.info("window extends over edge of screen, moving back to origin");
x=y=0;
}
if(h>sd.height-lowerInset) {
log.info("window height ("+h+") is bigger than screen height minus WINDOWS_TASK_BAR_HEIGHT ("+(sd.height-WINDOWS_TASK_BAR_HEIGHT)+"), resizing height");
h=sd.height-lowerInset;
resize=true;
}
if(w>sd.width) {
log.info("window width ("+w+") is bigger than screen width ("+(sd.width)+"), resizing height");
w=sd.width;
resize=true;
}
// check for last window with same name, if there is one, offset this one by OFFSET_FROM_SAME
if(framemap.containsKey(name)) { // we had a frame already with this name
int offset=lastframemap.containsKey(name)?lastframemap.get(name):0;
offset+=OFFSET_FROM_SAME;
// Insets insets=frame.getInsets();
x+=offset;//+insets.left;
y+=offset;//+insets.top;
lastframemap.put(name, offset);
}
frame.setLocation(x, y);
if(resize&&!(frame instanceof DontResize)) {
frame.setSize(new Dimension(w, h));
}
// log.info("loaded settings location for "+frame.getName());
framemap.put(name, frame);
frame.validate();
}
I will investigate some more, and should be able to make a test case.