Alt + Tab decreases frames per second for full screen exclusive mode...
I encountered a weird situation the other day with a 2D app im creating. When the app starts up and runs (in full screen exclusive mode) it runs at about 55 to 60 fps, however if i alt + tab to another application, then alt + tab back to the app the fps are around 35 - 30 and it stays there. I would post the code but its actually in many different files. Has anyone else encountered this problem or have any ideas of what i should check to make sure im not doing something wrong?
[488 byte] By [
Clabina] at [2007-11-26 14:00:57]

# 1
Hello,which java version are you using? Could you try with jdk6?I've seen this problem in some cases - basically the hardware acceleration may have been disabled on an alt+tab event.Thanks, DmitriJava2D Team
# 2
I'm using the latest version of JDK 5. I will test on JDK 6 asap. What cases caused the problem? Are there any things you can think of that i should avoid. I also meant to say that I'm using active rendering and double buffering.Thanks for reply
# 3
I tested it on JRE 1.6 and it performs kind of strangely. When i alt + tab to another application after the java application is running and then alt + tab back the screen is black for a second then the frame rate is random and then it goes back to the normal (which is good). However, when switching back and forth from applications after that it shows a black screen for a second each time. Also when i terminate the application it also shows this black screen.
Is there a way to fix the frame rate problem in 1.5? also how do i avoid the black screen thing in 1.6? Thanks again for the reply!
# 4
The behavior on 1.6 is expected, unfortunately I don't believe here's a way to fix it. Hopefully users don't change back and too often.
Regarding 1.5 . Are you using BufferStrategy or VolatileImage for double-buffering? Could you try this: both BS and VI have getCapabilities methods, can you check what they return when your framerate goes slow (whether or not the image/front/back buffer is accelerated)?
Thanks,
Dmitri
# 5
Im using buffer strategy.However now that im going back to JRE 1.5.0_10 and JRE 1.5.0_04 i cant replicate my first issue. Now with both update 10 and update 4 it randomly works and randomly does wierd things (black screen, grey screen, black screen that allows other apps to come up, black screen that only shows the taskbar, etc.). I couldnt find any other updates to download and test. The next chance i get i will see what JRE version im running at home.What should i do now...?
Maybe its so random because of the way im using it?
heres some code that might be helpful:
public void setFullScreen(DisplayMode displayMode) {
final JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setUndecorated(true);
frame.setIgnoreRepaint(true);
frame.setResizable(false);
GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = environment.getDefaultScreenDevice();
device.setFullScreenWindow(frame);
this.resetDisplayMode(displayMode);
try {
EventQueue.invokeAndWait(new Runnable() {
public void run() {
frame.createBufferStrategy(2);
}
});
should i put that same evenqueue call in my main method that eventually calls the above method?
Thanks again for the help!
# 6
A couple of suggestions:
- move all of setFullScreen() to EDT - you're working with swing components on a random thread, a no-no
- try not setting resizeable to false (I don't think it's related to this problem, but it may help avoiding other issues)
Another thing: you can listen to window events and halt your rendering until the window is re-activated.
Thanks,
Dmitri
# 7
Just to give you some more information, i was running JRE version 1.5.0_08 at home where i first experienced the problem. I switched to JRE 1.5.0_10 and its fixed. I could replicate the problem using JRE 1.5.0_08 after alt + tabing a couple of times. Checking for acceleration on both the back and front buffers always yeilded true, even when the frame rate dropped.
What you mean by move the setFullScreen to EDT (Event Dispatcher Thread right?) is to not invoke it on another thread right? The EDT is what is used to launch just regular java apps too right?
I will incorporate your suggestions asap and post back the results.
Thanks again for the help!
Message was edited by:
Clabin
# 8
could this also be part of the problem,
Window window = device.getFullScreenWindow();
if (window != null) {
BufferStrategy strategy = window.getBufferStrategy();
if (!strategy.contentsLost()) {
strategy.show();
}
}
// could this sync() call be a problem, what is the purpose of it?
Toolkit.getDefaultToolkit().sync();
Also i take back what i said about JRE1.5.0_10, after a couple of alt + tabs the frame rate drops to 30 and stays there, while the buffer capabilities for both the front and back buffers never say that its not accelerated.