Blame SOURCES/jdk8171000-pr3542-rh1402819-robot_createScreenCapture_crashes_in_wayland_mode.patch

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