3

I use a customised renderer for rescaling the screen for my 8 bit computer emulators that works nicely in pre Java 9 environments. In Java 9, it creates triangular distortions on the main screen when the JVM automatically resizes the screen to accommodate for different resolutions. It is most noticeable when scan lines are enabled in the emulator. I'm suspecting it has something to do with this ==> http://openjdk.java.net/jeps/263 being delivered in Java 9.

As an example, the effect can be seen when executing the following program on a 4K monitor using Java 9 on Windows 10.

public static void main(String[] args){
    JFrame frame=new JFrame("Java version 9");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    BufferedImage image =new BufferedImage(800,600,BufferedImage.TYPE_INT_RGB);
    Graphics2D g=image.createGraphics();
    g.setColor(Color.WHITE);
    for(int y=0;y<image.getHeight();y+=2){
        g.drawLine(0,y,image.getWidth(),y);
    }
    g.dispose();
    ImageIcon imageIcon=new ImageIcon(image);
    JLabel label=new JLabel(imageIcon);
    frame.add(label);
    frame.pack();
    frame.setVisible(true);
}

Figure 1 enter image description here

The following is how the same program looks using JDK 1.8.0_144, which is the desired result.

Figure 2. enter image description here

Is there a way to disable the default automatic rescaling of screens in Java 9 that will be compatible with pre Java 9 environments as well?

2
  • Did you manually try to scale the image using RescaleOp?
    – Naman
    Commented Oct 14, 2017 at 8:29
  • No, I haven't. Do you have any example code using RescaleOp that can be applied to the code I provided that will make the screen display the exact same size regardless if it is executed in Java 8 or 9? Does RescaleOp have much overhead and does it override the JVM from adding it's own scaling? My emulators need to generate screens in real-time so I'm avoiding adding an extra layer of processing to generate the screens. FYI my emulators are here if you want to see the application. ==> z64k.com The version in development is this ==> z64k.com/resources/Z64KNewUI.jar Commented Oct 14, 2017 at 21:25

2 Answers 2

1

See https://bugs.openjdk.java.net/browse/JDK-8189416 It appears to be a bug in the Direct3D code in JDK.

Workaround is "-Dsun.java2d.d3d=false" on the command line.

2
  • I confirm this fixes the triangular distortions in the emulators when the Windows scale factor is greater than 100%. Setting the Windows scale factor to 100% fixes the problem as well. I still require the option to programmatically render by pixels for BufferedImages when the user sets their scale factor greater than 100% because the JDK9 automatic scaling from JEP 263 bleeds some of the colours and doesn't blend smoothly. It conflicts with the emulators rendering code which needs to factor in the emulated computers pixel ratios which is rarely a 1:1 ratio. eg. C64 PAL pixel ratio is .9365 Commented Oct 19, 2017 at 2:40
  • You can really notice the difference in quality when resizing any of the emulators available in the jar at the following link with scaling set at 100% vs a higher scaling factor using JDK 9. VIC20 and C128 are most notable with CRT emulation enabled. z64k.com/resources/Z64KNewUI.jar Commented Oct 19, 2017 at 2:56
1

Using the option -Dsun.java2d.uiScale=1.0 fixes the above issue with the emulators and the test program I provided. I got that answer from JFrame scaling in Java 9 . I would much prefer a programmatic solution and jdk 9 high dpi disable for specific panel seems to be exactly the same problem as my issue and the answer provided there looks promising.

1
  • 1
    System.setProperty("sun.java2d.uiScale", "1.0"); worked for me with Java 10, thanks!
    – NateS
    Commented Jun 23, 2018 at 1:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.