8225118: Robot.createScreenCapture() returns black image on HiDPI linux with gtk3

Reviewed-by: serb
This commit is contained in:
Anton Tarasov 2019-06-06 15:46:36 +03:00
parent 427e1e28b1
commit eb555dec77
3 changed files with 17 additions and 9 deletions

View File

@ -324,6 +324,8 @@ GtkApi* gtk3_load(JNIEnv *env, const char* lib_name)
/* GDK */
fp_gdk_get_default_root_window =
dl_symbol("gdk_get_default_root_window");
fp_gdk_window_get_scale_factor =
dl_symbol("gdk_window_get_scale_factor");
/* Pixbuf */
fp_gdk_pixbuf_new = dl_symbol("gdk_pixbuf_new");
@ -2888,7 +2890,10 @@ static gboolean gtk3_get_drawable_data(JNIEnv *env, jintArray pixelArray,
jint *ary;
GdkWindow *root = (*fp_gdk_get_default_root_window)();
pixbuf = (*fp_gdk_pixbuf_get_from_drawable)(root, x, y, width, height);
int win_scale = (*fp_gdk_window_get_scale_factor)(root);
pixbuf = (*fp_gdk_pixbuf_get_from_drawable)(
root, x, y, (int)(width / (float)win_scale + 0.5), (int)(height / (float)win_scale + 0.5));
if (pixbuf && scale != 1) {
GdkPixbuf *scaledPixbuf;
x /= scale;
@ -2906,8 +2911,8 @@ static gboolean gtk3_get_drawable_data(JNIEnv *env, jintArray pixelArray,
if (pixbuf) {
int nchan = (*fp_gdk_pixbuf_get_n_channels)(pixbuf);
int stride = (*fp_gdk_pixbuf_get_rowstride)(pixbuf);
if ((*fp_gdk_pixbuf_get_width)(pixbuf) == width
&& (*fp_gdk_pixbuf_get_height)(pixbuf) == height
if ((*fp_gdk_pixbuf_get_width)(pixbuf) >= width
&& (*fp_gdk_pixbuf_get_height)(pixbuf) >= height
&& (*fp_gdk_pixbuf_get_bits_per_sample)(pixbuf) == 8
&& (*fp_gdk_pixbuf_get_colorspace)(pixbuf) == GDK_COLORSPACE_RGB
&& nchan >= 3

View File

@ -253,6 +253,7 @@ static gchar* (*fp_gtk_check_version)(guint required_major, guint
static void (*fp_g_free)(gpointer mem);
static void (*fp_g_object_unref)(gpointer object);
static GdkWindow *(*fp_gdk_get_default_root_window) (void);
static int (*fp_gdk_window_get_scale_factor) (GdkWindow *window);
static int (*fp_gdk_pixbuf_get_bits_per_sample)(const GdkPixbuf *pixbuf);
static guchar *(*fp_gdk_pixbuf_get_pixels)(const GdkPixbuf *pixbuf);

View File

@ -38,7 +38,7 @@ import javax.swing.UIManager;
* @bug 8073320
* @summary Windows HiDPI support
* @author Alexander Scherbatiy
* @requires (os.family == "windows")
* @requires (os.family == "linux" | os.family == "windows")
* @run main/othervm -Dsun.java2d.win.uiScaleX=3 -Dsun.java2d.win.uiScaleY=2
* HiDPIRobotScreenCaptureTest
*/
@ -50,11 +50,13 @@ public class HiDPIRobotScreenCaptureTest {
public static void main(String[] args) throws Exception {
try {
UIManager.setLookAndFeel(
"com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (Exception e) {
return;
if (System.getProperty("os.name").toLowerCase().contains("win")) {
try {
UIManager.setLookAndFeel(
"com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (Exception e) {
return;
}
}
Frame frame = new Frame();