8225118: Robot.createScreenCapture() returns black image on HiDPI linux with gtk3
Reviewed-by: serb
This commit is contained in:
parent
427e1e28b1
commit
eb555dec77
@ -324,6 +324,8 @@ GtkApi* gtk3_load(JNIEnv *env, const char* lib_name)
|
|||||||
/* GDK */
|
/* GDK */
|
||||||
fp_gdk_get_default_root_window =
|
fp_gdk_get_default_root_window =
|
||||||
dl_symbol("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 */
|
/* Pixbuf */
|
||||||
fp_gdk_pixbuf_new = dl_symbol("gdk_pixbuf_new");
|
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;
|
jint *ary;
|
||||||
|
|
||||||
GdkWindow *root = (*fp_gdk_get_default_root_window)();
|
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) {
|
if (pixbuf && scale != 1) {
|
||||||
GdkPixbuf *scaledPixbuf;
|
GdkPixbuf *scaledPixbuf;
|
||||||
x /= scale;
|
x /= scale;
|
||||||
@ -2906,8 +2911,8 @@ static gboolean gtk3_get_drawable_data(JNIEnv *env, jintArray pixelArray,
|
|||||||
if (pixbuf) {
|
if (pixbuf) {
|
||||||
int nchan = (*fp_gdk_pixbuf_get_n_channels)(pixbuf);
|
int nchan = (*fp_gdk_pixbuf_get_n_channels)(pixbuf);
|
||||||
int stride = (*fp_gdk_pixbuf_get_rowstride)(pixbuf);
|
int stride = (*fp_gdk_pixbuf_get_rowstride)(pixbuf);
|
||||||
if ((*fp_gdk_pixbuf_get_width)(pixbuf) == width
|
if ((*fp_gdk_pixbuf_get_width)(pixbuf) >= width
|
||||||
&& (*fp_gdk_pixbuf_get_height)(pixbuf) == height
|
&& (*fp_gdk_pixbuf_get_height)(pixbuf) >= height
|
||||||
&& (*fp_gdk_pixbuf_get_bits_per_sample)(pixbuf) == 8
|
&& (*fp_gdk_pixbuf_get_bits_per_sample)(pixbuf) == 8
|
||||||
&& (*fp_gdk_pixbuf_get_colorspace)(pixbuf) == GDK_COLORSPACE_RGB
|
&& (*fp_gdk_pixbuf_get_colorspace)(pixbuf) == GDK_COLORSPACE_RGB
|
||||||
&& nchan >= 3
|
&& nchan >= 3
|
||||||
|
@ -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_free)(gpointer mem);
|
||||||
static void (*fp_g_object_unref)(gpointer object);
|
static void (*fp_g_object_unref)(gpointer object);
|
||||||
static GdkWindow *(*fp_gdk_get_default_root_window) (void);
|
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 int (*fp_gdk_pixbuf_get_bits_per_sample)(const GdkPixbuf *pixbuf);
|
||||||
static guchar *(*fp_gdk_pixbuf_get_pixels)(const GdkPixbuf *pixbuf);
|
static guchar *(*fp_gdk_pixbuf_get_pixels)(const GdkPixbuf *pixbuf);
|
||||||
|
@ -38,7 +38,7 @@ import javax.swing.UIManager;
|
|||||||
* @bug 8073320
|
* @bug 8073320
|
||||||
* @summary Windows HiDPI support
|
* @summary Windows HiDPI support
|
||||||
* @author Alexander Scherbatiy
|
* @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
|
* @run main/othervm -Dsun.java2d.win.uiScaleX=3 -Dsun.java2d.win.uiScaleY=2
|
||||||
* HiDPIRobotScreenCaptureTest
|
* HiDPIRobotScreenCaptureTest
|
||||||
*/
|
*/
|
||||||
@ -50,11 +50,13 @@ public class HiDPIRobotScreenCaptureTest {
|
|||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
|
||||||
try {
|
if (System.getProperty("os.name").toLowerCase().contains("win")) {
|
||||||
UIManager.setLookAndFeel(
|
try {
|
||||||
"com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
|
UIManager.setLookAndFeel(
|
||||||
} catch (Exception e) {
|
"com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
|
||||||
return;
|
} catch (Exception e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Frame frame = new Frame();
|
Frame frame = new Frame();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user