--- old/src/java.desktop/unix/native/libawt_xawt/awt/awt_Robot.c 2016-03-08 12:22:32.524977027 +0100 +++ new/src/java.desktop/unix/native/libawt_xawt/awt/awt_Robot.c 2016-03-08 12:22:32.438978437 +0100 @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include "robot_common.h" @@ -45,7 +46,6 @@ #include "wsutils.h" #include "list.h" #include "multiVis.h" -#include "gtk2_interface.h" #if defined(__linux__) || defined(MACOSX) #include @@ -90,6 +90,32 @@ return isXTestAvailable; } +static Bool hasXCompositeOverlayExtension(Display *display) { + int xoverlay = False; + int eventBase, errorBase; + if (XCompositeQueryExtension(display, &eventBase, &errorBase)) { + int major = 0; + int minor = 0; + + XCompositeQueryVersion(display, &major, &minor); + if (major > 0 || minor >= 3) { + xoverlay = True; + } + } + + return xoverlay; +} + +static jboolean isXCompositeDisplay(Display *display, int screenNumber) { + + char NET_WM_CM_Sn[25]; + snprintf(NET_WM_CM_Sn, sizeof(NET_WM_CM_Sn), "_NET_WM_CM_S%d\0", screenNumber); + + Atom managerSelection = XInternAtom(display, NET_WM_CM_Sn, 0); + Window owner = XGetSelectionOwner(display, managerSelection); + + return owner != 0; +} static XImage *getWindowImage(Display * display, Window window, int32_t x, int32_t y, @@ -211,8 +237,7 @@ jint jwidth, jint jheight, jint scale, - jintArray pixelArray, - jboolean isGtkSupported) { + jintArray pixelArray) { XImage *image; jint *ary; /* Array of jints for sending pixel values back * to parent process. @@ -238,7 +263,12 @@ jint sheight = jheight * scale; rootWindow = XRootWindow(awt_display, adata->awt_visInfo.screen); - + if (isXCompositeDisplay(awt_display, adata->awt_visInfo.screen) && + hasXCompositeOverlayExtension(awt_display)) + { + rootWindow = XCompositeGetOverlayWindow(awt_display, rootWindow); + } + if (!XGetWindowAttributes(awt_display, rootWindow, &attr) || sx + swidth <= attr.x || attr.x + attr.width <= sx @@ -249,7 +279,6 @@ return; // Does not intersect with root window } - gboolean gtk_failed = TRUE; jint _x, _y; jint x = MAX(sx, attr.x); @@ -262,108 +291,40 @@ int dy = attr.y > sy ? attr.y - sy : 0; int index; + + image = getWindowImage(awt_display, rootWindow, sx, sy, swidth, sheight); - if (isGtkSupported) { - GdkPixbuf *pixbuf; - (*fp_gdk_threads_enter)(); - GdkWindow *root = (*fp_gdk_get_default_root_window)(); - - pixbuf = (*fp_gdk_pixbuf_get_from_drawable)(NULL, root, NULL, - x, y, 0, 0, width, height); - if (pixbuf && scale != 1) { - GdkPixbuf *scaledPixbuf; - x /= scale; - y /= scale; - width /= scale; - height /= scale; - dx /= scale; - dy /= scale; - scaledPixbuf = (*fp_gdk_pixbuf_scale_simple)(pixbuf, width, height, - GDK_INTERP_BILINEAR); - (*fp_g_object_unref)(pixbuf); - pixbuf = scaledPixbuf; - } + ary = (*env)->GetPrimitiveArrayCritical(env, pixelArray, NULL); - 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 - && (*fp_gdk_pixbuf_get_bits_per_sample)(pixbuf) == 8 - && (*fp_gdk_pixbuf_get_colorspace)(pixbuf) == GDK_COLORSPACE_RGB - && nchan >= 3 - ) { - guchar *p, *pix = (*fp_gdk_pixbuf_get_pixels)(pixbuf); - - ary = (*env)->GetPrimitiveArrayCritical(env, pixelArray, NULL); - if (!ary) { - (*fp_g_object_unref)(pixbuf); - (*fp_gdk_threads_leave)(); - AWT_UNLOCK(); - return; - } - - for (_y = 0; _y < height; _y++) { - for (_x = 0; _x < width; _x++) { - p = pix + _y * stride + _x * nchan; - - index = (_y + dy) * jwidth + (_x + dx); - ary[index] = 0xff000000 - | (p[0] << 16) - | (p[1] << 8) - | (p[2]); - - } - } - (*env)->ReleasePrimitiveArrayCritical(env, pixelArray, ary, 0); - if ((*env)->ExceptionCheck(env)) { - (*fp_g_object_unref)(pixbuf); - (*fp_gdk_threads_leave)(); - AWT_UNLOCK(); - return; - } - gtk_failed = FALSE; - } - (*fp_g_object_unref)(pixbuf); - } - (*fp_gdk_threads_leave)(); + if (!ary) { + XDestroyImage(image); + AWT_UNLOCK(); + return; } - if (gtk_failed) { - image = getWindowImage(awt_display, rootWindow, sx, sy, swidth, sheight); - - ary = (*env)->GetPrimitiveArrayCritical(env, pixelArray, NULL); - - if (!ary) { - XDestroyImage(image); - AWT_UNLOCK(); - return; - } - - dx /= scale; - dy /= scale; - width /= scale; - height /= scale; - - /* convert to Java ARGB pixels */ - for (_y = 0; _y < height; _y++) { - for (_x = 0; _x < width; _x++) { - jint pixel = (jint) XGetPixel(image, _x * scale, _y * scale); - /* Note ignore upper - * 32-bits on 64-bit - * OSes. - */ - pixel |= 0xff000000; /* alpha - full opacity */ - - index = (_y + dy) * jwidth + (_x + dx); - ary[index] = pixel; - } - } - - XDestroyImage(image); - (*env)->ReleasePrimitiveArrayCritical(env, pixelArray, ary, 0); + dx /= scale; + dy /= scale; + width /= scale; + height /= scale; + + /* convert to Java ARGB pixels */ + for (_y = 0; _y < height; _y++) { + for (_x = 0; _x < width; _x++) { + jint pixel = (jint) XGetPixel(image, _x * scale, _y * scale); + /* Note ignore upper + * 32-bits on 64-bit + * OSes. + */ + pixel |= 0xff000000; /* alpha - full opacity */ + + index = (_y + dy) * jwidth + (_x + dx); + ary[index] = pixel; + } } + + XDestroyImage(image); + (*env)->ReleasePrimitiveArrayCritical(env, pixelArray, ary, 0); + AWT_UNLOCK(); }