< prev index next >

src/java.desktop/unix/native/libawt_xawt/awt/awt_Robot.c

Print this page




 259 
 260     AWT_LOCK();
 261     xtestAvailable = isXTestAvailable();
 262     DTRACE_PRINTLN1("RobotPeer: XTest available = %d", xtestAvailable);
 263     if (!xtestAvailable) {
 264         JNU_ThrowByName(env, "java/awt/AWTException", "java.awt.Robot requires your X server support the XTEST extension version 2.2");
 265     }
 266 
 267     AWT_UNLOCK();
 268 }
 269 
 270 
 271 JNIEXPORT void JNICALL
 272 Java_sun_awt_X11_XRobotPeer_getRGBPixelsImpl( JNIEnv *env,
 273                              jclass cls,
 274                              jobject xgc,
 275                              jint jx,
 276                              jint jy,
 277                              jint jwidth,
 278                              jint jheight,
 279                              jint scale,
 280                              jintArray pixelArray,
 281                              jboolean useGtk) {
 282     XImage *image;
 283     jint *ary;               /* Array of jints for sending pixel values back
 284                               * to parent process.
 285                               */
 286     Window rootWindow;
 287     XWindowAttributes attr;
 288     AwtGraphicsConfigDataPtr adata;
 289 
 290     DTRACE_PRINTLN6("RobotPeer: getRGBPixelsImpl(%lx, %d, %d, %d, %d, %x)", xgc, jx, jy, jwidth, jheight, pixelArray);
 291 
 292     if (jwidth <= 0 || jheight <= 0) {
 293         return;
 294     }
 295 
 296     adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, xgc, x11GraphicsConfigIDs.aData);
 297     DASSERT(adata != NULL);
 298 
 299     AWT_LOCK();
 300 
 301     jint sx = jx * scale;
 302     jint sy = jy * scale;
 303     jint swidth = jwidth * scale;
 304     jint sheight = jheight * scale;
 305 
 306     rootWindow = XRootWindow(awt_display, adata->awt_visInfo.screen);
 307 
 308     if (!useGtk) {
 309         if (hasXCompositeOverlayExtension(awt_display) &&
 310             isXCompositeDisplay(awt_display, adata->awt_visInfo.screen))
 311         {
 312             rootWindow = compositeGetOverlayWindow(awt_display, rootWindow);
 313         }
 314     }
 315 
 316     if (!XGetWindowAttributes(awt_display, rootWindow, &attr)
 317             || sx + swidth <= attr.x
 318             || attr.x + attr.width <= sx
 319             || sy + sheight <= attr.y
 320             || attr.y + attr.height <= sy) {
 321 
 322         AWT_UNLOCK();
 323         return; // Does not intersect with root window
 324     }
 325 
 326     gboolean gtk_failed = TRUE;
 327     jint _x, _y;
 328 
 329     jint x = MAX(sx, attr.x);
 330     jint y = MAX(sy, attr.y);
 331     jint width = MIN(sx + swidth, attr.x + attr.width) - x;
 332     jint height = MIN(sy + sheight, attr.y + attr.height) - y;
 333 
 334 
 335     int dx = attr.x > sx ? attr.x - sx : 0;
 336     int dy = attr.y > sy ? attr.y - sy : 0;
 337 
 338     int index;
 339 
 340     if (useGtk) {
 341         gtk->gdk_threads_enter();
 342         gtk_failed = gtk->get_drawable_data(env, pixelArray, x, y, width,
 343                                             height, jwidth, dx, dy, scale);
 344         gtk->gdk_threads_leave();
 345     }
 346 
 347     if (gtk_failed) {
 348         image = getWindowImage(awt_display, rootWindow, sx, sy, swidth, sheight);
 349 
 350         ary = (*env)->GetPrimitiveArrayCritical(env, pixelArray, NULL);
 351 
 352         if (!ary) {
 353             XDestroyImage(image);
 354             AWT_UNLOCK();
 355             return;
 356         }
 357 
 358         dx /= scale;
 359         dy /= scale;
 360         width /= scale;
 361         height /= scale;
 362 
 363         /* convert to Java ARGB pixels */
 364         for (_y = 0; _y < height; _y++) {
 365             for (_x = 0; _x < width; _x++) {
 366                 jint pixel = (jint) XGetPixel(image, _x * scale, _y * scale);
 367                                                               /* Note ignore upper
 368                                                                * 32-bits on 64-bit
 369                                                                * OSes.
 370                                                                */
 371                 pixel |= 0xff000000; /* alpha - full opacity */
 372 
 373                 index = (_y + dy) * jwidth + (_x + dx);
 374                 ary[index] = pixel;
 375             }
 376         }
 377 
 378         XDestroyImage(image);
 379         (*env)->ReleasePrimitiveArrayCritical(env, pixelArray, ary, 0);
 380     }
 381     AWT_UNLOCK();
 382 }
 383 
 384 JNIEXPORT void JNICALL
 385 Java_sun_awt_X11_XRobotPeer_keyPressImpl (JNIEnv *env,
 386                          jclass cls,




 259 
 260     AWT_LOCK();
 261     xtestAvailable = isXTestAvailable();
 262     DTRACE_PRINTLN1("RobotPeer: XTest available = %d", xtestAvailable);
 263     if (!xtestAvailable) {
 264         JNU_ThrowByName(env, "java/awt/AWTException", "java.awt.Robot requires your X server support the XTEST extension version 2.2");
 265     }
 266 
 267     AWT_UNLOCK();
 268 }
 269 
 270 
 271 JNIEXPORT void JNICALL
 272 Java_sun_awt_X11_XRobotPeer_getRGBPixelsImpl( JNIEnv *env,
 273                              jclass cls,
 274                              jobject xgc,
 275                              jint jx,
 276                              jint jy,
 277                              jint jwidth,
 278                              jint jheight,

 279                              jintArray pixelArray,
 280                              jboolean useGtk) {
 281     XImage *image;
 282     jint *ary;               /* Array of jints for sending pixel values back
 283                               * to parent process.
 284                               */
 285     Window rootWindow;
 286     XWindowAttributes attr;
 287     AwtGraphicsConfigDataPtr adata;
 288 
 289     DTRACE_PRINTLN6("RobotPeer: getRGBPixelsImpl(%lx, %d, %d, %d, %d, %x)", xgc, jx, jy, jwidth, jheight, pixelArray);
 290 
 291     if (jwidth <= 0 || jheight <= 0) {
 292         return;
 293     }
 294 
 295     adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, xgc, x11GraphicsConfigIDs.aData);
 296     DASSERT(adata != NULL);
 297 
 298     AWT_LOCK();
 299 





 300     rootWindow = XRootWindow(awt_display, adata->awt_visInfo.screen);
 301 
 302     if (!useGtk) {
 303         if (hasXCompositeOverlayExtension(awt_display) &&
 304             isXCompositeDisplay(awt_display, adata->awt_visInfo.screen))
 305         {
 306             rootWindow = compositeGetOverlayWindow(awt_display, rootWindow);
 307         }
 308     }
 309 
 310     if (!XGetWindowAttributes(awt_display, rootWindow, &attr)
 311             || jx + jwidth <= attr.x
 312             || attr.x + attr.width <= jx
 313             || jy + jheight <= attr.y
 314             || attr.y + attr.height <= jy) {
 315 
 316         AWT_UNLOCK();
 317         return; // Does not intersect with root window
 318     }
 319 
 320     gboolean gtk_failed = TRUE;
 321     jint _x, _y;
 322 
 323     jint x = MAX(jx, attr.x);
 324     jint y = MAX(jy, attr.y);
 325     jint width = MIN(jx + jwidth, attr.x + attr.width) - x;
 326     jint height = MIN(jy + jheight, attr.y + attr.height) - y;

 327 
 328     int dx = attr.x > jx ? attr.x - jx : 0;
 329     int dy = attr.y > jy ? attr.y - jy : 0;
 330 
 331     int index;
 332 
 333     if (useGtk) {
 334         gtk->gdk_threads_enter();
 335         gtk_failed = gtk->get_drawable_data(env, pixelArray, x, y, width,
 336                                             height, jwidth, dx, dy, 1);
 337         gtk->gdk_threads_leave();
 338     }
 339 
 340     if (gtk_failed) {
 341         image = getWindowImage(awt_display, rootWindow, x, y, width, height);
 342 
 343         ary = (*env)->GetPrimitiveArrayCritical(env, pixelArray, NULL);
 344 
 345         if (!ary) {
 346             XDestroyImage(image);
 347             AWT_UNLOCK();
 348             return;
 349         }
 350 





 351         /* convert to Java ARGB pixels */
 352         for (_y = 0; _y < height; _y++) {
 353             for (_x = 0; _x < width; _x++) {
 354                 jint pixel = (jint) XGetPixel(image, _x, _y);
 355                                                               /* Note ignore upper
 356                                                                * 32-bits on 64-bit
 357                                                                * OSes.
 358                                                                */
 359                 pixel |= 0xff000000; /* alpha - full opacity */
 360 
 361                 index = (_y + dy) * jwidth + (_x + dx);
 362                 ary[index] = pixel;
 363             }
 364         }
 365 
 366         XDestroyImage(image);
 367         (*env)->ReleasePrimitiveArrayCritical(env, pixelArray, ary, 0);
 368     }
 369     AWT_UNLOCK();
 370 }
 371 
 372 JNIEXPORT void JNICALL
 373 Java_sun_awt_X11_XRobotPeer_keyPressImpl (JNIEnv *env,
 374                          jclass cls,


< prev index next >