< prev index next >

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

Print this page

        

@@ -208,10 +208,11 @@
                              jobject xgc,
                              jint jx,
                              jint jy,
                              jint jwidth,
                              jint jheight,
+                             jint scale,
                              jintArray pixelArray,
                              jboolean isGtkSupported) {
     XImage *image;
     jint *ary;               /* Array of jints for sending pixel values back
                               * to parent process.

@@ -229,43 +230,61 @@
     adata = (AwtGraphicsConfigDataPtr) JNU_GetLongFieldAsPtr(env, xgc, x11GraphicsConfigIDs.aData);
     DASSERT(adata != NULL);
 
     AWT_LOCK();
 
+    jint sx = jx * scale;
+    jint sy = jy * scale;
+    jint swidth = jwidth * scale;
+    jint sheight = jheight * scale;
+
     rootWindow = XRootWindow(awt_display, adata->awt_visInfo.screen);
 
     if (!XGetWindowAttributes(awt_display, rootWindow, &attr)
-            || jx + jwidth <= attr.x
-            || attr.x + attr.width <= jx
-            || jy + jheight <= attr.y
-            || attr.y + attr.height <= jy) {
+            || sx + swidth <= attr.x
+            || attr.x + attr.width <= sx
+            || sy + sheight <= attr.y
+            || attr.y + attr.height <= sy) {
 
         AWT_UNLOCK();
         return; // Does not intersect with root window
     }
 
     gboolean gtk_failed = TRUE;
     jint _x, _y;
 
-    jint x = MAX(jx, attr.x);
-    jint y = MAX(jy, attr.y);
-    jint width = MIN(jx + jwidth, attr.x + attr.width) - x;
-    jint height = MIN(jy + jheight, attr.y + attr.height) - y;
+    jint x = MAX(sx, attr.x);
+    jint y = MAX(sy, attr.y);
+    jint width = MIN(sx + swidth, attr.x + attr.width) - x;
+    jint height = MIN(sy + sheight, attr.y + attr.height) - y;
 
 
-    int dx = attr.x > jx ? attr.x - jx : 0;
-    int dy = attr.y > jy ? attr.y - jy : 0;
+    int dx = attr.x > sx ? attr.x - sx : 0;
+    int dy = attr.y > sy ? attr.y - sy : 0;
 
     int index;
 
     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;
+        }
 
         if (pixbuf) {
             int nchan = (*fp_gdk_pixbuf_get_n_channels)(pixbuf);
             int stride = (*fp_gdk_pixbuf_get_rowstride)(pixbuf);
 

@@ -310,24 +329,30 @@
         }
         (*fp_gdk_threads_leave)();
     }
 
     if (gtk_failed) {
-        image = getWindowImage(awt_display, rootWindow, x, y, width, height);
+        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, _y); /* Note ignore upper
+                jint pixel = (jint) XGetPixel(image, _x * scale, _y * scale);
+                                                              /* Note ignore upper
                                                                * 32-bits on 64-bit
                                                                * OSes.
                                                                */
                 pixel |= 0xff000000; /* alpha - full opacity */
 
< prev index next >