242 AWT_UNLOCK(); 243 return; // Does not intersect with root window 244 } 245 246 gboolean gtk_failed = TRUE; 247 jint _x, _y; 248 249 jint x = MAX(jx, attr.x); 250 jint y = MAX(jy, attr.y); 251 jint width = MIN(jx + jwidth, attr.x + attr.width) - x; 252 jint height = MIN(jy + jheight, attr.y + attr.height) - y; 253 254 255 int dx = attr.x > jx ? attr.x - jx : 0; 256 int dy = attr.y > jy ? attr.y - jy : 0; 257 258 int index; 259 260 if (isGtkSupported) { 261 GdkPixbuf *pixbuf; 262 GdkWindow *root = (*fp_gdk_get_default_root_window)(); 263 264 pixbuf = (*fp_gdk_pixbuf_get_from_drawable)(NULL, root, NULL, 265 x, y, 0, 0, width, height); 266 267 if (pixbuf) { 268 int nchan = (*fp_gdk_pixbuf_get_n_channels)(pixbuf); 269 int stride = (*fp_gdk_pixbuf_get_rowstride)(pixbuf); 270 271 if ((*fp_gdk_pixbuf_get_width)(pixbuf) == width 272 && (*fp_gdk_pixbuf_get_height)(pixbuf) == height 273 && (*fp_gdk_pixbuf_get_bits_per_sample)(pixbuf) == 8 274 && (*fp_gdk_pixbuf_get_colorspace)(pixbuf) == GDK_COLORSPACE_RGB 275 && nchan >= 3 276 ) { 277 guchar *p, *pix = (*fp_gdk_pixbuf_get_pixels)(pixbuf); 278 279 ary = (*env)->GetPrimitiveArrayCritical(env, pixelArray, NULL); 280 if (!ary) { 281 (*fp_g_object_unref)(pixbuf); 282 AWT_UNLOCK(); 283 return; 284 } 285 286 for (_y = 0; _y < height; _y++) { 287 for (_x = 0; _x < width; _x++) { 288 p = pix + _y * stride + _x * nchan; 289 290 index = (_y + dy) * jwidth + (_x + dx); 291 ary[index] = 0xff000000 292 | (p[0] << 16) 293 | (p[1] << 8) 294 | (p[2]); 295 296 } 297 } 298 (*env)->ReleasePrimitiveArrayCritical(env, pixelArray, ary, 0); 299 if ((*env)->ExceptionCheck(env)) { 300 (*fp_g_object_unref)(pixbuf); 301 AWT_UNLOCK(); 302 return; 303 } 304 gtk_failed = FALSE; 305 } 306 (*fp_g_object_unref)(pixbuf); 307 } 308 } 309 310 if (gtk_failed) { 311 image = getWindowImage(awt_display, rootWindow, x, y, width, height); 312 313 ary = (*env)->GetPrimitiveArrayCritical(env, pixelArray, NULL); 314 315 if (!ary) { 316 XDestroyImage(image); 317 AWT_UNLOCK(); 318 return; 319 } 320 321 /* convert to Java ARGB pixels */ 322 for (_y = 0; _y < height; _y++) { 323 for (_x = 0; _x < width; _x++) { 324 jint pixel = (jint) XGetPixel(image, _x, _y); /* Note ignore upper 325 * 32-bits on 64-bit 326 * OSes. 327 */ | 242 AWT_UNLOCK(); 243 return; // Does not intersect with root window 244 } 245 246 gboolean gtk_failed = TRUE; 247 jint _x, _y; 248 249 jint x = MAX(jx, attr.x); 250 jint y = MAX(jy, attr.y); 251 jint width = MIN(jx + jwidth, attr.x + attr.width) - x; 252 jint height = MIN(jy + jheight, attr.y + attr.height) - y; 253 254 255 int dx = attr.x > jx ? attr.x - jx : 0; 256 int dy = attr.y > jy ? attr.y - jy : 0; 257 258 int index; 259 260 if (isGtkSupported) { 261 GdkPixbuf *pixbuf; 262 (*fp_gdk_threads_enter)(); 263 GdkWindow *root = (*fp_gdk_get_default_root_window)(); 264 265 pixbuf = (*fp_gdk_pixbuf_get_from_drawable)(NULL, root, NULL, 266 x, y, 0, 0, width, height); 267 268 if (pixbuf) { 269 int nchan = (*fp_gdk_pixbuf_get_n_channels)(pixbuf); 270 int stride = (*fp_gdk_pixbuf_get_rowstride)(pixbuf); 271 272 if ((*fp_gdk_pixbuf_get_width)(pixbuf) == width 273 && (*fp_gdk_pixbuf_get_height)(pixbuf) == height 274 && (*fp_gdk_pixbuf_get_bits_per_sample)(pixbuf) == 8 275 && (*fp_gdk_pixbuf_get_colorspace)(pixbuf) == GDK_COLORSPACE_RGB 276 && nchan >= 3 277 ) { 278 guchar *p, *pix = (*fp_gdk_pixbuf_get_pixels)(pixbuf); 279 280 ary = (*env)->GetPrimitiveArrayCritical(env, pixelArray, NULL); 281 if (!ary) { 282 (*fp_g_object_unref)(pixbuf); 283 (*fp_gdk_threads_leave)(); 284 AWT_UNLOCK(); 285 return; 286 } 287 288 for (_y = 0; _y < height; _y++) { 289 for (_x = 0; _x < width; _x++) { 290 p = pix + _y * stride + _x * nchan; 291 292 index = (_y + dy) * jwidth + (_x + dx); 293 ary[index] = 0xff000000 294 | (p[0] << 16) 295 | (p[1] << 8) 296 | (p[2]); 297 298 } 299 } 300 (*env)->ReleasePrimitiveArrayCritical(env, pixelArray, ary, 0); 301 if ((*env)->ExceptionCheck(env)) { 302 (*fp_g_object_unref)(pixbuf); 303 (*fp_gdk_threads_leave)(); 304 AWT_UNLOCK(); 305 return; 306 } 307 gtk_failed = FALSE; 308 } 309 (*fp_g_object_unref)(pixbuf); 310 } 311 (*fp_gdk_threads_leave)(); 312 } 313 314 if (gtk_failed) { 315 image = getWindowImage(awt_display, rootWindow, x, y, width, height); 316 317 ary = (*env)->GetPrimitiveArrayCritical(env, pixelArray, NULL); 318 319 if (!ary) { 320 XDestroyImage(image); 321 AWT_UNLOCK(); 322 return; 323 } 324 325 /* convert to Java ARGB pixels */ 326 for (_y = 0; _y < height; _y++) { 327 for (_x = 0; _x < width; _x++) { 328 jint pixel = (jint) XGetPixel(image, _x, _y); /* Note ignore upper 329 * 32-bits on 64-bit 330 * OSes. 331 */ |