JDK-8269245 : [wayland] java.awt.Robot.createScreenCapture(r) produces black image
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 8,11,17,21,22
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux_debian_3.0
  • CPU: x86_64
  • Submitted: 2021-06-15
  • Updated: 2024-06-03
  • Resolved: 2024-06-03
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 21
21Resolved
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
Tried on Debian11 (bullseye) and Debian10 (buster) with default Gnome3 desktop
On Debian11 tried with these openjdk java versions:
- "17-ea" 2021-09-14
- "14.0.2" 2020-07-14
- "13.0.5.1" 2020-11-06
- "11.0.11" 2021-04-20


A DESCRIPTION OF THE PROBLEM :
When I try to take a screenshot using java.awt.Robot, then in any case this produces just a black image.
Same bad result using javafx.scene.robot.Robot.
Also getPixelColor​(x,y) always returns black.
But getPixelColor​(x,y) returns any wrong color, when this argument is set: -Dawt.robot.gtk=false

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Just try to take a screenshot on any Debian OS with Gnome3, it is always black.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
This function should return an Image containing the recorded screenshot.
ACTUAL -
Black image.

---------- BEGIN SOURCE ----------
public class Test
{
  public static void main (String args[]) throws Exception
  {
    java.awt.Robot robot = new java.awt.Robot();
    java.awt.Toolkit tk = java.awt.Toolkit.getDefaultToolkit();
    java.awt.Rectangle rect = new java.awt.Rectangle(tk.getScreenSize());
    java.awt.image.BufferedImage im = robot.createScreenCapture(rect);
    javax.imageio.ImageIO.write(im, "png", new java.io.File("/tmp/screen.png"));
  }
}
---------- END SOURCE ----------

FREQUENCY : always



Comments
If i run sun/java2d/DirectX/OnScreenRenderingResizeTest/OnScreenRenderingResizeTest.java in Ubuntu 22.04 VM where wayland is enabled by default i see that the test fails and Robot.createScreenCapture() returns black image. If i disable wayland, Robot captures content properly and test passes.
11-11-2022

I can observe same behavior on Wayland. Looks like the Debian10 is the first release where Wayland is used by default.
23-06-2021

Checked with attached test case in Windows 10 and Ubuntu 20.04.1, Issue could not be reproduced. Test Result ========= 8u291: Pass 11.0.11 Pass 16: Pass 17ea: Pass Checked with Debian OS, Issue is reproducible, captured screenshot is blank Test Result ========= 17ea: Fail 16:Fail 11.0.11:Fail 8u291:Fail
23-06-2021