Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4502279

Tearing problem in J2SE 1.4 beta 2, fullscreen, multibuffer.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • None
    • 1.4.0
    • client-libs
    • 2d
    • x86
    • windows_2000



      Name: yyT116575 Date: 09/12/2001


      java version "1.4.0-beta2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta2-b77)
      Java HotSpot(TM) Client VM (build 1.4.0-beta2-b77, mixed mode)


      It seems that the BufferStrategy.show() method doesn't sync with screen refresh
      in Beta 2.

      The problem only occurs when the app has to swicth resolution. If I start
      MultiBufferTest from the same resolution that i'ts trying to use there's no
      problems. Not only must the display have the same resolution it must also have
      the same color depth and refersh rate.

      This works:
      640x480 32 bit 60 Hz -> 640x480 32 bit 60 Hz

      This doesn't:
      640x480 8 bit 60 Hz -> 640x480 32 bit 60 Hz
      640x480 16 bit 60 Hz -> 640x480 32 bit 60 Hz
      640x480 32 bit 75 Hz -> 640x480 32 bit 60 Hz
      800x600 32 bit 60 Hz -> 640x480 32 bit 60 Hz

      I've tested this on the two following environments:
      * Compaq Win98, Nvidia TNT 2, latest drivers, latest directx.
      * Compaq Win2K, ATI Rage, latest drivers, latest directx.

      I've also tried to change MultiBufferTest to use other resolutions and color
      depth with the same result. Same to same works. Otherwise the
      BufferStrategy.show() is out of sync.

      --- MultiBufferTest.java ----------------------------------------
      import java.awt.*;
      import java.awt.image.BufferStrategy;

      public class MultiBufferTest {
          
        private static Color[] COLORS = new Color[] {
          Color.red, Color.blue, Color.green, Color.white, Color.black,
          Color.yellow, Color.gray, Color.cyan, Color.pink, Color.lightGray,
          Color.magenta, Color.orange, Color.darkGray };
        private static DisplayMode[] BEST_DISPLAY_MODES = new DisplayMode[] {
          new DisplayMode(640, 480, 32, 0),
          new DisplayMode(640, 480, 16, 0),
          new DisplayMode(640, 480, 8, 0)
        };
          
        Frame mainFrame;
          
        public MultiBufferTest(int numBuffers, GraphicsDevice device) {
          try {
            GraphicsConfiguration gc = device.getDefaultConfiguration();
            mainFrame = new Frame(gc);
            mainFrame.setUndecorated(true);
            mainFrame.setIgnoreRepaint(true);
            device.setFullScreenWindow(mainFrame);
            if (device.isDisplayChangeSupported()) {
              chooseBestDisplayMode(device);
            }
            Rectangle bounds = mainFrame.getBounds();
            mainFrame.createBufferStrategy(numBuffers);
            BufferStrategy bufferStrategy = mainFrame.getBufferStrategy();
            for (float lag = 2000.0f; lag > 0.00000006f; lag = lag / 1.33f) {
              for (int i = 0; i < numBuffers; i++) {
                Graphics g = bufferStrategy.getDrawGraphics();
                if (!bufferStrategy.contentsLost()) {
                  g.setColor(COLORS[i]);
                  g.fillRect(0,0,bounds.width, bounds.height);
                  bufferStrategy.show();
                  g.dispose();
                }
                try {
                  Thread.sleep((int)lag);
                } catch (InterruptedException e) {}
                }
              }
            } catch (Exception e) {
              e.printStackTrace();
            } finally {
              device.setFullScreenWindow(null);
            }
        }
          
        private static DisplayMode getBestDisplayMode(GraphicsDevice device) {
          for (int x = 0; x < BEST_DISPLAY_MODES.length; x++) {
            DisplayMode[] modes = device.getDisplayModes();
            for (int i = 0; i < modes.length; i++) {
              if (modes[i].getWidth() == BEST_DISPLAY_MODES[x].getWidth()
                  && modes[i].getHeight() == BEST_DISPLAY_MODES[x].getHeight()
                  && modes[i].getBitDepth() == BEST_DISPLAY_MODES[x].getBitDepth()) {
                return BEST_DISPLAY_MODES[x];
              }
            }
          }
          return null;
        }
          
        public static void chooseBestDisplayMode(GraphicsDevice device) {
          DisplayMode best = getBestDisplayMode(device);
          if (best != null) {
            device.setDisplayMode(best);
          }
        }
          
        public static void main(String[] args) {
          try {
            GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
            GraphicsDevice device = env.getDefaultScreenDevice();
            MultiBufferTest test = new MultiBufferTest(2, device);
          } catch (Exception e) {
            e.printStackTrace();
          }
          System.exit(0);
        }
      }
      -----------------------------------------------------------------
      (Review ID: 131456)
      ======================================================================

      Name: jl125535 Date: 02/08/2002


      FULL PRODUCT VERSION :
      java version "1.4.0-rc"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.
      Java HotSpot(TM) Client VM (build 1.4.0-rc-b91, mixed mode)

      FULL OPERATING SYSTEM VERSION :
      Microsoft Windows 2000 [Version 5.00.2195]
      No service packs

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Graphics cards: GeForce2 MX card

      A DESCRIPTION OF THE PROBLEM :
      Bug 4502279 is still in 1.4 rc1.
      (Review ID: 139312)
      ======================================================================

            chaasesunw Chet Haase (Inactive)
            yyoungsunw Yung-ching Young (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: