0b5ec94
# HG changeset patch
0b5ec94
# User kaddepalli
0b5ec94
# Date 1517818481 -19800
0b5ec94
#      Mon Feb 05 13:44:41 2018 +0530
0b5ec94
# Node ID b77308735540644d4710244e3c88865067f2905a
0b5ec94
# Parent  39bfc94b1f4265b645c2970a58389acc779dafe9
0b5ec94
8171000, PR3542, RH1402819: Robot.createScreenCapture() crashes in wayland mode
0b5ec94
Reviewed-by: serb, mhalder
0b5ec94
0b5ec94
diff --git openjdk.orig/jdk/src/solaris/native/sun/awt/multiVis.c openjdk/jdk/src/solaris/native/sun/awt/multiVis.c
0b5ec94
--- openjdk.orig/jdk/src/solaris/native/sun/awt/multiVis.c
0b5ec94
+++ openjdk/jdk/src/solaris/native/sun/awt/multiVis.c
0b5ec94
@@ -394,77 +394,48 @@
0b5ec94
 XRectangle      bbox;           /* bounding box of grabbed area */
0b5ec94
 list_ptr regions;/* list of regions to read from */
0b5ec94
 {
0b5ec94
-    image_region_type   *reg;
0b5ec94
-    int32_t                     dst_x, dst_y;   /* where in pixmap to write (UL) */
0b5ec94
-    int32_t                     diff;
0b5ec94
-
0b5ec94
-    XImage              *reg_image,*ximage ;
0b5ec94
-    int32_t             srcRect_x,srcRect_y,srcRect_width,srcRect_height ;
0b5ec94
-    int32_t     rem ;
0b5ec94
-    int32_t     bytes_per_line;
0b5ec94
-    int32_t     bitmap_unit;
0b5ec94
-
0b5ec94
-    bitmap_unit = sizeof (long);
0b5ec94
-    if (format == ZPixmap)
0b5ec94
-       bytes_per_line = width*depth/8;
0b5ec94
-    else
0b5ec94
-       bytes_per_line = width/8;
0b5ec94
-
0b5ec94
-
0b5ec94
-    /* Find out how many more bytes are required for padding so that
0b5ec94
-    ** bytes per scan line will be multiples of bitmap_unit bits */
0b5ec94
-    if (format == ZPixmap) {
0b5ec94
-       rem = (bytes_per_line*8)%bitmap_unit;
0b5ec94
-    if (rem)
0b5ec94
-       bytes_per_line += (rem/8 + 1);
0b5ec94
-    }
0b5ec94
+    XImage              *ximage ;
0b5ec94
 
0b5ec94
     ximage = XCreateImage(disp,fakeVis,(uint32_t) depth,format,0,NULL,
0b5ec94
                           (uint32_t)width,(uint32_t)height,8,0);
0b5ec94
 
0b5ec94
-    bytes_per_line = ximage->bytes_per_line;
0b5ec94
-
0b5ec94
-    if (format == ZPixmap)
0b5ec94
-          ximage->data = malloc(height*bytes_per_line);
0b5ec94
-    else
0b5ec94
-        ximage->data = malloc(height*bytes_per_line*depth);
0b5ec94
-
0b5ec94
+    ximage->data = calloc(ximage->bytes_per_line*height*((format==ZPixmap)? 1 : depth), sizeof(char));
0b5ec94
     ximage->bits_per_pixel = depth; /** Valid only if format is ZPixmap ***/
0b5ec94
 
0b5ec94
-    for (reg = (image_region_type *) first_in_list( regions); reg;
0b5ec94
+    for (image_region_type* reg = (image_region_type *) first_in_list( regions); reg;
0b5ec94
          reg = (image_region_type *) next_in_list( regions))
0b5ec94
     {
0b5ec94
-                int32_t rect;
0b5ec94
-                struct my_XRegion *vis_reg;
0b5ec94
-                vis_reg = (struct my_XRegion *)(reg->visible_region);
0b5ec94
-                for (rect = 0;
0b5ec94
-                     rect < vis_reg->numRects;
0b5ec94
-                     rect++)
0b5ec94
+                struct my_XRegion *vis_reg = (struct my_XRegion *)(reg->visible_region);
0b5ec94
+                for (int32_t rect = 0; rect < vis_reg->numRects; rect++)
0b5ec94
                 {
0b5ec94
-                /** ------------------------------------------------------------------------
0b5ec94
-                        Intersect bbox with visible part of region giving src rect & output
0b5ec94
-                        location.  Width is the min right side minus the max left side.
0b5ec94
-                        Similar for height.  Offset src rect so x,y are relative to
0b5ec94
-                        origin of win, not the root-relative visible rect of win.
0b5ec94
-                    ------------------------------------------------------------------------ **/
0b5ec94
-                    srcRect_width  = MIN( vis_reg->rects[rect].x2, bbox.width + bbox.x)
0b5ec94
-             - MAX( vis_reg->rects[rect].x1, bbox.x);
0b5ec94
+                    /** ------------------------------------------------------------------------
0b5ec94
+                            Intersect bbox with visible part of region giving src rect & output
0b5ec94
+                            location.  Width is the min right side minus the max left side.
0b5ec94
+                            Similar for height.  Offset src rect so x,y are relative to
0b5ec94
+                            origin of win, not the root-relative visible rect of win.
0b5ec94
+                        ------------------------------------------------------------------------ **/
0b5ec94
+                        int32_t srcRect_width  = MIN( vis_reg->rects[rect].x2, bbox.width + bbox.x)
0b5ec94
+                                         - MAX( vis_reg->rects[rect].x1, bbox.x);
0b5ec94
+
0b5ec94
+                        int32_t srcRect_height = MIN( vis_reg->rects[rect].y2, bbox.height + bbox.y)
0b5ec94
+                                         - MAX( vis_reg->rects[rect].y1, bbox.y);
0b5ec94
 
0b5ec94
-                    srcRect_height = MIN( vis_reg->rects[rect].y2, bbox.height + bbox.y)
0b5ec94
-             - MAX( vis_reg->rects[rect].y1, bbox.y);
0b5ec94
+                        int32_t diff = bbox.x - vis_reg->rects[rect].x1;
0b5ec94
+                        int32_t srcRect_x = MAX( 0, diff)  + (vis_reg->rects[rect].x1 - reg->x_rootrel - reg->border);
0b5ec94
+                        int32_t dst_x     = MAX( 0, -diff) ;
0b5ec94
 
0b5ec94
-                    diff = bbox.x - vis_reg->rects[rect].x1;
0b5ec94
-                    srcRect_x = MAX( 0, diff)  + (vis_reg->rects[rect].x1 - reg->x_rootrel - reg->border);
0b5ec94
-                    dst_x     = MAX( 0, -diff) ;
0b5ec94
-                    diff = bbox.y - vis_reg->rects[rect].y1;
0b5ec94
-                    srcRect_y = MAX( 0, diff)  + (vis_reg->rects[rect].y1 - reg->y_rootrel - reg->border);
0b5ec94
-                    dst_y     = MAX( 0, -diff) ;
0b5ec94
-            reg_image = XGetImage(disp,reg->win,srcRect_x,srcRect_y,
0b5ec94
-             (uint32_t) srcRect_width, (uint32_t) srcRect_height,AllPlanes,format) ;
0b5ec94
-                    TransferImage(disp,reg_image,srcRect_width,
0b5ec94
-                                 srcRect_height,reg,ximage,dst_x,dst_y) ;
0b5ec94
-            XDestroyImage(reg_image);
0b5ec94
-            }
0b5ec94
+                        diff = bbox.y - vis_reg->rects[rect].y1;
0b5ec94
+                        int32_t srcRect_y = MAX( 0, diff)  + (vis_reg->rects[rect].y1 - reg->y_rootrel - reg->border);
0b5ec94
+                        int32_t dst_y     = MAX( 0, -diff) ;
0b5ec94
+                        XImage* reg_image = XGetImage(disp,reg->win,srcRect_x,srcRect_y,
0b5ec94
+                                            (uint32_t) srcRect_width, (uint32_t) srcRect_height,AllPlanes,format) ;
0b5ec94
+
0b5ec94
+                        if (reg_image) {
0b5ec94
+                            TransferImage(disp,reg_image,srcRect_width,
0b5ec94
+                                            srcRect_height,reg,ximage,dst_x,dst_y) ;
0b5ec94
+                            XDestroyImage(reg_image);
0b5ec94
+                        }
0b5ec94
+                }
0b5ec94
     }
0b5ec94
     return ximage ;
0b5ec94
 }