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

SunGraphics2D.copyArea() does not properly work for scaled graphics in D3D

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 9
    • 9
    • client-libs
    • None
    • JDK 1.9.0-ea-fastdebug-b46

    • 2d
    • b114
    • windows

      Run the SwingSet2 sample on Windows with enabled d3d option (-Dsun.java2d.d3d=true) ui scale 2 (-Dsun.java2d.uiScale=2) and drag or scroll an internal frame. There are artifacts on the internal frame (see the attached screen shot).


      Below is a simple test case that allows to reproduce the issue:
      - Run the code on Windows with enabled d3d (option -Dsun.java2d.d3d=true)
      - The copied image is not properly shown (see the attached image):
      --------------------------------------------
      import java.awt.*;
      import java.awt.event.WindowAdapter;
      import java.awt.event.WindowEvent;
      import java.awt.image.VolatileImage;

      public class CopyImageTest extends Frame {

          private static final int W = 800;
          private static final int H = 800;
          private static final double scale = 1.3;

          private VolatileImage vImg;

          public CopyImageTest() throws HeadlessException {

              setSize(W, H);
              vImg = createVolatileImage();

              addWindowListener(new WindowAdapter() {

                  @Override
                  public void windowClosing(WindowEvent e) {
                      System.exit(0);
                  }
              });
          }

          VolatileImage createVolatileImage() {
              return getGraphicsConfiguration().createCompatibleVolatileImage(W, H);
          }

          // rendering to the image
          void renderOffscreen() {
              do {
                  if (vImg.validate(getGraphicsConfiguration()) == VolatileImage.IMAGE_INCOMPATIBLE) {
                      // old vImg doesn't work with new GraphicsConfig; re-create it
                      vImg = createVolatileImage();
                  }
                  Graphics2D g = vImg.createGraphics();
                  //
                  // miscellaneous rendering commands...
                  //
                  g.scale(scale, scale);

                  g.setColor(Color.YELLOW);
                  g.fillRect(0, 0, W, H);

                  g.setColor(Color.ORANGE);

                  g.fillRect(50, 50, 50, 50);
                  g.setColor(Color.BLUE);
                  int d = 3;
                  g.drawRect(50 + d, 50 + d, 50 - 2 * d, 50 - 2 * d);

                  int N = 2;
                  int s1 = 5;
                  int s2 = 3;

                  for (int i = 0; i < N; i++) {
                      g.copyArea(50 + i * s1, 50 + i * s2, 50, 50, s1, s2);

                  }
                  g.dispose();
              } while (vImg.contentsLost());
          }

          @Override
          public void paint(Graphics gScreen) {
              super.paint(gScreen); //To change body of generated methods, choose Tools | Templates.
              // copying from the image (here, gScreen is the Graphics
              // object for the onscreen window)
              do {
                  int returnCode = vImg.validate(getGraphicsConfiguration());
                  if (returnCode == VolatileImage.IMAGE_RESTORED) {
                      // Contents need to be restored
                      renderOffscreen(); // restore contents
                  } else if (returnCode == VolatileImage.IMAGE_INCOMPATIBLE) {
                      // old vImg doesn't work with new GraphicsConfig; re-create it
                      vImg = createVolatileImage();
                      renderOffscreen();
                  }
                  gScreen.drawImage(vImg, 0, 0, this);
              } while (vImg.contentsLost());
          }

          public static void main(String[] args) {
              new CopyImageTest().setVisible(true);
          }
      }
      --------------------------------------------

        1. buffered_image.png
          17 kB
          Alexandr Scherbatiy
        2. volitile_image.png
          16 kB
          Alexandr Scherbatiy
        3. windows-do-copy-blit.png
          29 kB
          Alexandr Scherbatiy

            alexsch Alexandr Scherbatiy
            alexsch Alexandr Scherbatiy
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: