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

EmptyClipRenderingTest.java subtest Fails in WinXPpro

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 7
    • 6
    • client-libs
    • 2d
    • b03
    • x86
    • windows_xp
    • Verified

      JDK Version: mustang b82 and tiger 1.5.0-b64

      Platforms: WindowsXPpro with sp2, apus.sfbay

      Problems:
      A regression test EmptyClipRenderingTest.java fails in winXPpro since tiger,
      it also fails in Mustang recent builds, include nightly builds, but it passes
      in solaris.

      One of the test case fails in winXP:
      Errors as followings:

      Total number of test rects: 133
      java.lang.RuntimeException: Dest: Screen was rendered to at x=395 y=12
      pixel=fff f0000
              at
      EmptyClipRenderingTest.testResult(EmptyClipRenderingTest.java:221)
              at EmptyClipRenderingTest.<init>(EmptyClipRenderingTest.java:48)
              at EmptyClipRenderingTest.main(EmptyClipRenderingTest.java:238)
      Exception in thread "main" java.lang.RuntimeException: Test FAILED: 1
      subtest failures.
              at EmptyClipRenderingTest.<init>(EmptyClipRenderingTest.java:84)
              at EmptyClipRenderingTest.main(EmptyClipRenderingTest.java:238)

      How to Reproduce the problem:

      1. Compile the attached test or get test from:
      /java/re/jdk/1.6.0/promoted/latest/ws/j2se/test/sun/java2d/SunGraphics2D/
      2.run the test in winXP, you will get the exceptions.

      In the test case, it mentioned bug 6335200 which is fix delivered in mustang b59.

      /**
       * @test @(#)EmptyClipRenderingTest.java 1.1 05/11/01
       * @bug 6335200
       * @summary Tests that we don't render anything if specific empty clip is set
       * @author ###@###.###: area=Graphics
       * @run main EmptyClipRenderingTest
       * @run main/othervm -Dsun.java2d.pmoffscreen=true EmptyClipRenderingTest
       * @run main/othervm -Dsun.java2d.opengl=true EmptyClipRenderingTest
       */

      import java.awt.AWTException;
      import java.awt.Color;
      import java.awt.Component;
      import java.awt.Dimension;
      import java.awt.Frame;
      import java.awt.Graphics;
      import java.awt.Graphics2D;
      import java.awt.GraphicsConfiguration;
      import java.awt.GraphicsEnvironment;
      import java.awt.HeadlessException;
      import java.awt.Rectangle;
      import java.awt.Robot;
      import java.awt.Toolkit;
      import java.awt.image.BufferedImage;
      import java.awt.image.VolatileImage;
      import java.util.HashSet;
      import sun.awt.ConstrainableGraphics;
      import sun.java2d.SunGraphics2D;

      public class EmptyClipRenderingTest {
          static final int IMG_W = 400;
          static final int IMG_H = 400;

          // generated rectangles
          static HashSet<Rectangle> rects;
          
          boolean onscreenTestCompleted = false;
          private static boolean showErrors = false;
          
          public EmptyClipRenderingTest() {
              // initialize clip/render region rectangles
              initClips();
              
              HashSet<RuntimeException> errors = new HashSet<RuntimeException>();
              
              BufferedImage screenResult = testOnscreen();
              try {
                  testResult(screenResult, "Screen");
              } catch (RuntimeException e) {
                  errors.add(e);
              }
              
              BufferedImage destBI =
                  new BufferedImage(IMG_W, IMG_H, BufferedImage.TYPE_INT_RGB);
              runTest((Graphics2D)destBI.getGraphics());
              try {
                  testResult(destBI, "BufferedImage");
              } catch (RuntimeException e) {
                  errors.add(e);
              }
              
              GraphicsConfiguration gc =
                      GraphicsEnvironment.getLocalGraphicsEnvironment().
                      getDefaultScreenDevice().getDefaultConfiguration();
              VolatileImage destVI = gc.createCompatibleVolatileImage(IMG_W, IMG_H);
              destVI.validate(gc);
              runTest((Graphics2D)destVI.getGraphics());
              try {
                  testResult(destVI.getSnapshot(), "VolatileImage");
              } catch (RuntimeException e) {
                  errors.add(e);
              }

              if (errors.isEmpty()) {
                  System.err.println("Test PASSED.");
              } else {
                  for (RuntimeException re : errors) {
                      re.printStackTrace();
                  }
                  if (showErrors) {
                      System.err.println("Test FAILED: "+ errors.size() +
                                         " subtest failures.");
                  } else {
                      throw new RuntimeException("Test FAILED: "+ errors.size() +
                                                 " subtest failures.");
                  }
              }
          }
          
          /**
           * Recursively adds 4 new rectangles: two vertical and two horizontal
           * based on the passed rectangle area. The area is then shrunk and the
           * process repeated for smaller area.
           */
          private static void add4Rects(HashSet<Rectangle> rects, Rectangle area) {
              if (area.width < 10 || area.height < 10) {
                  rects.add(area);
                  return;
              }
              // two vertical rects
              rects.add(new Rectangle(area.x, area.y, 5, area.height));
              rects.add(new Rectangle(area.x + area.width - 5, area.y, 5, area.height));
              // two horizontal rects
              int width = area.width - 2*(5 + 1);
              rects.add(new Rectangle(area.x+6, area.y, width, 5));
              rects.add(new Rectangle(area.x+6, area.y + area.height - 5, width, 5));
              // reduce the area and repeat
              area.grow(-6, -6);
              add4Rects(rects, area);
          }
          
          /**
           * Generate a bunch of non-intersecting rectangles
           */
          private static void initClips() {
              rects = new HashSet<Rectangle>();
              add4Rects(rects, new Rectangle(0, 0, IMG_W, IMG_H));
              System.err.println("Total number of test rects: " + rects.size());
          }

          /**
           * Render the pattern to the screen, capture the output with robot and
           * return it.
           */
          private BufferedImage testOnscreen() throws HeadlessException {
              final Component destComponent;
              final Object lock = new Object();
              Frame f = new Frame("Test Frame");
              f.add(destComponent = new Component() {
                  public void paint(Graphics g) {
                      runTest((Graphics2D)getGraphics());
                      synchronized (lock) {
                          onscreenTestCompleted = true;
                          lock.notify();
                      }
                      return;
                  }
                  public Dimension getPreferredSize() {
                      return new Dimension(IMG_W, IMG_H);
                  }
              });
              f.pack();
              f.setVisible(true);
              synchronized(lock) {
                  while (!onscreenTestCompleted) {
                      try {
                          lock.wait(100);
                      } catch (InterruptedException ex) {
                          ex.printStackTrace();
                      }
                  }
              }
              Robot r = null;
              try {
                  r = new Robot();
              } catch (AWTException ex) {
                  throw new RuntimeException("Can't create Robot");
              }
              Toolkit.getDefaultToolkit().sync();
              BufferedImage bi = r.createScreenCapture(
                  new Rectangle(destComponent.getLocationOnScreen().x,
                                destComponent.getLocationOnScreen().y,
                                destComponent.getWidth(),
                                destComponent.getHeight()));
              f.setVisible(false);
              f.dispose();
              return bi;
          }
          
          /**
           * Run the test: cycle through all the rectangles, use one as clip and
           * another as the area to render to.
           * Set the clip in the same way Swing does it when repainting:
           * first constrain the graphics to the damaged area, and repaint everything
           */
          void runTest(Graphics2D destGraphics) {
              destGraphics.setColor(Color.black);
              destGraphics.fillRect(0, 0, IMG_W, IMG_H);

              destGraphics.setColor(Color.red);
              for (Rectangle clip : rects) {
                  Graphics2D g2d = (Graphics2D)destGraphics.create();
                  g2d.setColor(Color.red);
                  // mimic what swing does in BufferStrategyPaintManager
                  if (g2d instanceof ConstrainableGraphics) {
                      ((ConstrainableGraphics)g2d).constrain(clip.x, clip.y,
                                                             clip.width, clip.height);
                  }
                  g2d.setClip(clip);
                  
                  for (Rectangle renderRegion : rects) {
                      if (renderRegion != clip) {
                          // from CellRendererPane's paintComponent
                          Graphics2D rG = (Graphics2D)
                              g2d.create(renderRegion.x, renderRegion.y,
                                         renderRegion.width, renderRegion.height);
                          rG.fillRect(0,0, renderRegion.width, renderRegion.height);
                      }
                  }
              }
          }
          
          void testResult(final BufferedImage bi, final String desc) {
              for (int y = 0; y < bi.getHeight(); y++) {
                  for (int x = 0; x < bi.getWidth(); x++) {
                      if (bi.getRGB(x, y) != Color.black.getRGB()) {
                          if (showErrors) {
                              Frame f = new Frame("Error: " + desc);
                              f.add(new Component() {
                                  public void paint(Graphics g) {
                                      g.drawImage(bi, 0, 0, null);
                                  }
                                  public Dimension getPreferredSize() {
                                      return new Dimension(bi.getWidth(),
                                                           bi.getHeight());
                                  }
                              });
                              f.pack();
                              f.setVisible(true);
                          }
                          throw new RuntimeException("Dest: "+desc+
                              " was rendered to at x="+
                              x + " y=" + y +
                              " pixel="+Integer.toHexString(bi.getRGB(x,y)));
                      }
                  }
              }
          }
          
          public static void main(String argv[]) {
              for (String arg : argv) {
                  if (arg.equals("-show")) {
                      showErrors = true;
                  } else {
                      usage("Incorrect argument:" + arg);
                  }
              }
              new EmptyClipRenderingTest();
          }

          private static void usage(String string) {
              System.out.println(string);
              System.out.println("Usage: EmptyClipRenderingTest [-show]");
          }
      }

            serb Sergey Bylokhov
            ttzhang Tao Zhang
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: