20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 #ifdef HEADLESS
27 #error This file should not be included in headless library
28 #endif
29
30 #include "awt_p.h"
31 #include "awt_GraphicsEnv.h"
32 #define XK_MISCELLANY
33 #include <X11/keysymdef.h>
34 #include <X11/Xutil.h>
35 #include <X11/Xmd.h>
36 #include <X11/extensions/xtestext1.h>
37 #include <X11/extensions/XTest.h>
38 #include <X11/extensions/XInput.h>
39 #include <X11/extensions/XI.h>
40 #include <jni.h>
41 #include <sizecalc.h>
42 #include "robot_common.h"
43 #include "canvas.h"
44 #include "wsutils.h"
45 #include "list.h"
46 #include "multiVis.h"
47 #include "gtk_interface.h"
48
49 #if defined(__linux__) || defined(MACOSX)
50 #include <sys/socket.h>
51 #endif
52
53 extern struct X11GraphicsConfigIDs x11GraphicsConfigIDs;
54
55 static jint * masks;
56 static jint num_buttons;
57
58 static int32_t isXTestAvailable() {
59 int32_t major_opcode, first_event, first_error;
72 if (majorp < 2 || (majorp == 2 && minorp < 2)) {
73 /* bad version*/
74 DTRACE_PRINTLN2("XRobotPeer: XTEST version is %d.%d \n", majorp, minorp);
75 if (majorp == 2 && minorp == 1) {
76 DTRACE_PRINTLN("XRobotPeer: XTEST is 2.1 - no grab is available\n");
77 } else {
78 isXTestAvailable = False;
79 }
80 } else {
81 /* allow XTest calls even if someone else has the grab; e.g. during
82 * a window resize operation. Works only with XTEST2.2*/
83 XTestGrabControl(awt_display, True);
84 }
85 } else {
86 DTRACE_PRINTLN("RobotPeer: XTEST extension is unavailable");
87 }
88
89 return isXTestAvailable;
90 }
91
92
93 static XImage *getWindowImage(Display * display, Window window,
94 int32_t x, int32_t y,
95 int32_t w, int32_t h) {
96 XImage *image;
97 int32_t transparentOverlays;
98 int32_t numVisuals;
99 XVisualInfo *pVisuals;
100 int32_t numOverlayVisuals;
101 OverlayInfo *pOverlayVisuals;
102 int32_t numImageVisuals;
103 XVisualInfo **pImageVisuals;
104 list_ptr vis_regions; /* list of regions to read from */
105 list_ptr vis_image_regions ;
106 int32_t allImage = 0 ;
107 int32_t format = ZPixmap;
108
109 /* prevent user from moving stuff around during the capture */
110 XGrabServer(display);
111
221 AwtGraphicsConfigDataPtr adata;
222
223 DTRACE_PRINTLN6("RobotPeer: getRGBPixelsImpl(%lx, %d, %d, %d, %d, %x)", xgc, jx, jy, jwidth, jheight, pixelArray);
224
225 if (jwidth <= 0 || jheight <= 0) {
226 return;
227 }
228
229 adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, xgc, x11GraphicsConfigIDs.aData);
230 DASSERT(adata != NULL);
231
232 AWT_LOCK();
233
234 jint sx = jx * scale;
235 jint sy = jy * scale;
236 jint swidth = jwidth * scale;
237 jint sheight = jheight * scale;
238
239 rootWindow = XRootWindow(awt_display, adata->awt_visInfo.screen);
240
241 if (!XGetWindowAttributes(awt_display, rootWindow, &attr)
242 || sx + swidth <= attr.x
243 || attr.x + attr.width <= sx
244 || sy + sheight <= attr.y
245 || attr.y + attr.height <= sy) {
246
247 AWT_UNLOCK();
248 return; // Does not intersect with root window
249 }
250
251 gboolean gtk_failed = TRUE;
252 jint _x, _y;
253
254 jint x = MAX(sx, attr.x);
255 jint y = MAX(sy, attr.y);
256 jint width = MIN(sx + swidth, attr.x + attr.width) - x;
257 jint height = MIN(sy + sheight, attr.y + attr.height) - y;
258
259
260 int dx = attr.x > sx ? attr.x - sx : 0;
|
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 #ifdef HEADLESS
27 #error This file should not be included in headless library
28 #endif
29
30 #include "awt_p.h"
31 #include "awt_GraphicsEnv.h"
32 #define XK_MISCELLANY
33 #include <X11/keysymdef.h>
34 #include <X11/Xutil.h>
35 #include <X11/Xmd.h>
36 #include <X11/extensions/xtestext1.h>
37 #include <X11/extensions/XTest.h>
38 #include <X11/extensions/XInput.h>
39 #include <X11/extensions/XI.h>
40 #include <X11/extensions/Xcomposite.h>
41 #include <jni.h>
42 #include <sizecalc.h>
43 #include "robot_common.h"
44 #include "canvas.h"
45 #include "wsutils.h"
46 #include "list.h"
47 #include "multiVis.h"
48 #include "gtk_interface.h"
49
50 #if defined(__linux__) || defined(MACOSX)
51 #include <sys/socket.h>
52 #endif
53
54 extern struct X11GraphicsConfigIDs x11GraphicsConfigIDs;
55
56 static jint * masks;
57 static jint num_buttons;
58
59 static int32_t isXTestAvailable() {
60 int32_t major_opcode, first_event, first_error;
73 if (majorp < 2 || (majorp == 2 && minorp < 2)) {
74 /* bad version*/
75 DTRACE_PRINTLN2("XRobotPeer: XTEST version is %d.%d \n", majorp, minorp);
76 if (majorp == 2 && minorp == 1) {
77 DTRACE_PRINTLN("XRobotPeer: XTEST is 2.1 - no grab is available\n");
78 } else {
79 isXTestAvailable = False;
80 }
81 } else {
82 /* allow XTest calls even if someone else has the grab; e.g. during
83 * a window resize operation. Works only with XTEST2.2*/
84 XTestGrabControl(awt_display, True);
85 }
86 } else {
87 DTRACE_PRINTLN("RobotPeer: XTEST extension is unavailable");
88 }
89
90 return isXTestAvailable;
91 }
92
93 static Bool hasXCompositeOverlayExtension(Display *display) {
94 int xoverlay = False;
95 int eventBase, errorBase;
96 if (XCompositeQueryExtension(display, &eventBase, &errorBase)) {
97 int major = 0;
98 int minor = 0;
99
100 XCompositeQueryVersion(display, &major, &minor);
101 if (major > 0 || minor >= 3) {
102 xoverlay = True;
103 }
104 }
105
106 return xoverlay;
107 }
108
109 static jboolean isXCompositeDisplay(Display *display, int screenNumber) {
110
111 char NET_WM_CM_Sn[25];
112 snprintf(NET_WM_CM_Sn, sizeof(NET_WM_CM_Sn), "_NET_WM_CM_S%d\0", screenNumber);
113
114 Atom managerSelection = XInternAtom(display, NET_WM_CM_Sn, 0);
115 Window owner = XGetSelectionOwner(display, managerSelection);
116
117 return owner != 0;
118 }
119
120 static XImage *getWindowImage(Display * display, Window window,
121 int32_t x, int32_t y,
122 int32_t w, int32_t h) {
123 XImage *image;
124 int32_t transparentOverlays;
125 int32_t numVisuals;
126 XVisualInfo *pVisuals;
127 int32_t numOverlayVisuals;
128 OverlayInfo *pOverlayVisuals;
129 int32_t numImageVisuals;
130 XVisualInfo **pImageVisuals;
131 list_ptr vis_regions; /* list of regions to read from */
132 list_ptr vis_image_regions ;
133 int32_t allImage = 0 ;
134 int32_t format = ZPixmap;
135
136 /* prevent user from moving stuff around during the capture */
137 XGrabServer(display);
138
248 AwtGraphicsConfigDataPtr adata;
249
250 DTRACE_PRINTLN6("RobotPeer: getRGBPixelsImpl(%lx, %d, %d, %d, %d, %x)", xgc, jx, jy, jwidth, jheight, pixelArray);
251
252 if (jwidth <= 0 || jheight <= 0) {
253 return;
254 }
255
256 adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, xgc, x11GraphicsConfigIDs.aData);
257 DASSERT(adata != NULL);
258
259 AWT_LOCK();
260
261 jint sx = jx * scale;
262 jint sy = jy * scale;
263 jint swidth = jwidth * scale;
264 jint sheight = jheight * scale;
265
266 rootWindow = XRootWindow(awt_display, adata->awt_visInfo.screen);
267
268 if (!isGtkSupported) {
269 if (isXCompositeDisplay(awt_display, adata->awt_visInfo.screen) &&
270 hasXCompositeOverlayExtension(awt_display))
271 {
272 rootWindow = XCompositeGetOverlayWindow(awt_display, rootWindow);
273 }
274 }
275
276 if (!XGetWindowAttributes(awt_display, rootWindow, &attr)
277 || sx + swidth <= attr.x
278 || attr.x + attr.width <= sx
279 || sy + sheight <= attr.y
280 || attr.y + attr.height <= sy) {
281
282 AWT_UNLOCK();
283 return; // Does not intersect with root window
284 }
285
286 gboolean gtk_failed = TRUE;
287 jint _x, _y;
288
289 jint x = MAX(sx, attr.x);
290 jint y = MAX(sy, attr.y);
291 jint width = MIN(sx + swidth, attr.x + attr.width) - x;
292 jint height = MIN(sy + sheight, attr.y + attr.height) - y;
293
294
295 int dx = attr.x > sx ? attr.x - sx : 0;
|