Blame jdk8171000-pr3542-rh1402819-robot_createScreenCapture_crashes_in_wayland_mode.patch

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