title: Java Efficiency: Fullscreen Exclusive Mode
body: <p>Recently I came across the fullscreen exclusive mode for Java. As I tried it myself, I encountered something: Rendering the exactly same content in a JFrame or Frame in fullscreen mode takes significantly longer (40 fps), than in an undecorated and maximized window (150-200 fps).
  My screen is set to 50 fps, that's 20ms per frame and I can't see, where this time is lost. My only idea is, that Jave - for some reason - decides to use my onboard graphicscard while in fullscreen.</p>
  
  <pre><code>GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
  if(gd.isFullScreenSupported()) {
      try {
          gd.setFullScreenWindow(window);
      } finally {
          gd.setFullScreenWindow(null);
      }
  } else {
      this.fullscreen = false;
  }
  </code></pre>
  
  <p>I manage repainting with a frame, that trys to hold the frame rate on a certain level by pausing a calculated time.</p>
  
  <pre><code>int delta = (int) (System.currentTimeMillis() - timestamp); //timestamp: start of this round
  if(animated - delta &gt; 0)
      pause(animated - delta);
  </code></pre>
  
  <p>And finally I draw on the frame using double buffering:</p>
  
  <pre><code>public void render(Graphics2D a) { //window graphics are passed
      Graphics2D g = (Graphics2D) backBuffer.getGraphics();
      //Adjusting some rendering hints here...
      //Then drawing some stuff...
      g.dispose();
      a.drawImage(backBuffer, 0, 0, null);
  }
  </code></pre>
  
  <p>That's basically it, and still: the so-called efficient fullscreen mode is damn slow.</p>