< prev index next >

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

Print this page
rev 48355 : Fixed JDK-8171000: Robot.createScreenCapture() crashes in wayland mode. 
 Added null check after XCreateImage


 377          }
 378        }
 379        break;
 380     }
 381 
 382     /* Fix memory leak by freeing colors
 383      *  - robi.khan@eng 9/22/1999
 384      */
 385     free(colors);
 386 }
 387 
 388 static XImage *
 389 ReadRegionsInList(disp,fakeVis,depth,format,width,height,bbox,regions)
 390 Display *disp ;
 391 Visual *fakeVis ;
 392 int32_t depth , width , height ;
 393 int32_t format ;
 394 XRectangle      bbox;           /* bounding box of grabbed area */
 395 list_ptr regions;/* list of regions to read from */
 396 {
 397     image_region_type   *reg;
 398     int32_t                     dst_x, dst_y;   /* where in pixmap to write (UL) */
 399     int32_t                     diff;
 400 
 401     XImage              *reg_image,*ximage ;
 402     int32_t             srcRect_x,srcRect_y,srcRect_width,srcRect_height ;
 403     int32_t     rem ;
 404     int32_t     bytes_per_line;
 405     int32_t     bitmap_unit;
 406 
 407     bitmap_unit = sizeof (long);
 408     if (format == ZPixmap)
 409        bytes_per_line = width*depth/8;
 410     else
 411        bytes_per_line = width/8;
 412 
 413 
 414     /* Find out how many more bytes are required for padding so that
 415     ** bytes per scan line will be multiples of bitmap_unit bits */
 416     if (format == ZPixmap) {
 417        rem = (bytes_per_line*8)%bitmap_unit;
 418     if (rem)
 419        bytes_per_line += (rem/8 + 1);
 420     }
 421 
 422     ximage = XCreateImage(disp,fakeVis,(uint32_t) depth,format,0,NULL,
 423                           (uint32_t)width,(uint32_t)height,8,0);
 424 
 425     bytes_per_line = ximage->bytes_per_line;
 426 
 427     if (format == ZPixmap)
 428           ximage->data = malloc(height*bytes_per_line);
 429     else
 430         ximage->data = malloc(height*bytes_per_line*depth);
 431 
 432     ximage->bits_per_pixel = depth; /** Valid only if format is ZPixmap ***/
 433 
 434     for (reg = (image_region_type *) first_in_list( regions); reg;
 435          reg = (image_region_type *) next_in_list( regions))
 436     {
 437                 int32_t rect;
 438                 struct my_XRegion *vis_reg;
 439                 vis_reg = (struct my_XRegion *)(reg->visible_region);
 440                 for (rect = 0;
 441                      rect < vis_reg->numRects;
 442                      rect++)
 443                 {
 444                 /** ------------------------------------------------------------------------
 445                         Intersect bbox with visible part of region giving src rect & output
 446                         location.  Width is the min right side minus the max left side.
 447                         Similar for height.  Offset src rect so x,y are relative to
 448                         origin of win, not the root-relative visible rect of win.
 449                     ------------------------------------------------------------------------ **/
 450                     srcRect_width  = MIN( vis_reg->rects[rect].x2, bbox.width + bbox.x)
 451              - MAX( vis_reg->rects[rect].x1, bbox.x);
 452 
 453                     srcRect_height = MIN( vis_reg->rects[rect].y2, bbox.height + bbox.y)
 454              - MAX( vis_reg->rects[rect].y1, bbox.y);
 455 
 456                     diff = bbox.x - vis_reg->rects[rect].x1;
 457                     srcRect_x = MAX( 0, diff)  + (vis_reg->rects[rect].x1 - reg->x_rootrel - reg->border);
 458                     dst_x     = MAX( 0, -diff) ;

 459                     diff = bbox.y - vis_reg->rects[rect].y1;
 460                     srcRect_y = MAX( 0, diff)  + (vis_reg->rects[rect].y1 - reg->y_rootrel - reg->border);
 461                     dst_y     = MAX( 0, -diff) ;
 462             reg_image = XGetImage(disp,reg->win,srcRect_x,srcRect_y,
 463              (uint32_t) srcRect_width, (uint32_t) srcRect_height,AllPlanes,format) ;


 464                     TransferImage(disp,reg_image,srcRect_width,
 465                                  srcRect_height,reg,ximage,dst_x,dst_y) ;
 466             XDestroyImage(reg_image);
 467             }

 468     }
 469     return ximage ;
 470 }
 471 
 472 
 473 /** ------------------------------------------------------------------------
 474     ------------------------------------------------------------------------ **/
 475 
 476 XImage *ReadAreaToImage(disp, srcRootWinid, x, y, width, height,
 477     numVisuals,pVisuals,numOverlayVisuals,pOverlayVisuals,numImageVisuals,
 478     pImageVisuals,vis_regions,vis_image_regions,format,allImage)
 479     Display             *disp;
 480     Window              srcRootWinid;   /* root win on which grab was done */
 481     int32_t                     x;   /* root rel UL corner of bounding box of grab */
 482     int32_t                     y;
 483     uint32_t            width;  /* size of bounding box of grab */
 484     uint32_t            height;
 485     /** int32_t                 transparentOverlays; ***/
 486     int32_t                     numVisuals;
 487     XVisualInfo         *pVisuals;




 377          }
 378        }
 379        break;
 380     }
 381 
 382     /* Fix memory leak by freeing colors
 383      *  - robi.khan@eng 9/22/1999
 384      */
 385     free(colors);
 386 }
 387 
 388 static XImage *
 389 ReadRegionsInList(disp,fakeVis,depth,format,width,height,bbox,regions)
 390 Display *disp ;
 391 Visual *fakeVis ;
 392 int32_t depth , width , height ;
 393 int32_t format ;
 394 XRectangle      bbox;           /* bounding box of grabbed area */
 395 list_ptr regions;/* list of regions to read from */
 396 {
 397     XImage              *ximage ;























 398 
 399     ximage = XCreateImage(disp,fakeVis,(uint32_t) depth,format,0,NULL,
 400                           (uint32_t)width,(uint32_t)height,8,0);     
 401 
 402     ximage->data = calloc(ximage->bytes_per_line*height*((format==ZPixmap)? 1 : depth), sizeof(char));






 403     ximage->bits_per_pixel = depth; /** Valid only if format is ZPixmap ***/
 404 
 405     for (image_region_type* reg = (image_region_type *) first_in_list( regions); reg;
 406          reg = (image_region_type *) next_in_list( regions))
 407     {
 408                 struct my_XRegion *vis_reg = (struct my_XRegion *)(reg->visible_region);
 409                 for (int32_t rect = 0; rect < vis_reg->numRects; rect++)




 410                 {
 411                     /** ------------------------------------------------------------------------
 412                             Intersect bbox with visible part of region giving src rect & output
 413                             location.  Width is the min right side minus the max left side.
 414                             Similar for height.  Offset src rect so x,y are relative to
 415                             origin of win, not the root-relative visible rect of win.
 416                         ------------------------------------------------------------------------ **/
 417                         int32_t srcRect_width  = MIN( vis_reg->rects[rect].x2, bbox.width + bbox.x)
 418                                          - MAX( vis_reg->rects[rect].x1, bbox.x);
 419 
 420                         int32_t srcRect_height = MIN( vis_reg->rects[rect].y2, bbox.height + bbox.y)
 421                                          - MAX( vis_reg->rects[rect].y1, bbox.y);
 422 
 423                         int32_t diff = bbox.x - vis_reg->rects[rect].x1;
 424                         int32_t srcRect_x = MAX( 0, diff)  + (vis_reg->rects[rect].x1 - reg->x_rootrel - reg->border);
 425                         int32_t dst_x     = MAX( 0, -diff) ;
 426                         
 427                         diff = bbox.y - vis_reg->rects[rect].y1;
 428                         int32_t srcRect_y = MAX( 0, diff)  + (vis_reg->rects[rect].y1 - reg->y_rootrel - reg->border);
 429                         int32_t dst_y     = MAX( 0, -diff) ;
 430                         XImage* reg_image = XGetImage(disp,reg->win,srcRect_x,srcRect_y,
 431                                             (uint32_t) srcRect_width, (uint32_t) srcRect_height,AllPlanes,format) ;
 432 
 433                         if (reg_image) {
 434                             TransferImage(disp,reg_image,srcRect_width,
 435                                             srcRect_height,reg,ximage,dst_x,dst_y) ;
 436                             XDestroyImage(reg_image);
 437                         }
 438                 }
 439     }
 440     return ximage ;
 441 }
 442 
 443 
 444 /** ------------------------------------------------------------------------
 445     ------------------------------------------------------------------------ **/
 446 
 447 XImage *ReadAreaToImage(disp, srcRootWinid, x, y, width, height,
 448     numVisuals,pVisuals,numOverlayVisuals,pOverlayVisuals,numImageVisuals,
 449     pImageVisuals,vis_regions,vis_image_regions,format,allImage)
 450     Display             *disp;
 451     Window              srcRootWinid;   /* root win on which grab was done */
 452     int32_t                     x;   /* root rel UL corner of bounding box of grab */
 453     int32_t                     y;
 454     uint32_t            width;  /* size of bounding box of grab */
 455     uint32_t            height;
 456     /** int32_t                 transparentOverlays; ***/
 457     int32_t                     numVisuals;
 458     XVisualInfo         *pVisuals;


< prev index next >