src/java.desktop/unix/native/libawt_xawt/awt/multiVis.c
changeset 49079 05077701f689
parent 47216 71c04702a3d5
child 49083 673be6f60323
equal deleted inserted replaced
48736:0454688cc319 49079:05077701f689
   392 int32_t depth , width , height ;
   392 int32_t depth , width , height ;
   393 int32_t format ;
   393 int32_t format ;
   394 XRectangle      bbox;           /* bounding box of grabbed area */
   394 XRectangle      bbox;           /* bounding box of grabbed area */
   395 list_ptr regions;/* list of regions to read from */
   395 list_ptr regions;/* list of regions to read from */
   396 {
   396 {
   397     image_region_type   *reg;
   397     XImage              *ximage ;
   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 
   398 
   422     ximage = XCreateImage(disp,fakeVis,(uint32_t) depth,format,0,NULL,
   399     ximage = XCreateImage(disp,fakeVis,(uint32_t) depth,format,0,NULL,
   423                           (uint32_t)width,(uint32_t)height,8,0);
   400                           (uint32_t)width,(uint32_t)height,8,0);
   424 
   401 
   425     bytes_per_line = ximage->bytes_per_line;
   402     ximage->data = calloc(ximage->bytes_per_line*height*((format==ZPixmap)? 1 : depth), sizeof(char));
   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 ***/
   403     ximage->bits_per_pixel = depth; /** Valid only if format is ZPixmap ***/
   433 
   404 
   434     for (reg = (image_region_type *) first_in_list( regions); reg;
   405     for (image_region_type* reg = (image_region_type *) first_in_list( regions); reg;
   435          reg = (image_region_type *) next_in_list( regions))
   406          reg = (image_region_type *) next_in_list( regions))
   436     {
   407     {
   437                 int32_t rect;
   408                 struct my_XRegion *vis_reg = (struct my_XRegion *)(reg->visible_region);
   438                 struct my_XRegion *vis_reg;
   409                 for (int32_t rect = 0; rect < vis_reg->numRects; rect++)
   439                 vis_reg = (struct my_XRegion *)(reg->visible_region);
       
   440                 for (rect = 0;
       
   441                      rect < vis_reg->numRects;
       
   442                      rect++)
       
   443                 {
   410                 {
   444                 /** ------------------------------------------------------------------------
   411                     /** ------------------------------------------------------------------------
   445                         Intersect bbox with visible part of region giving src rect & output
   412                             Intersect bbox with visible part of region giving src rect & output
   446                         location.  Width is the min right side minus the max left side.
   413                             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
   414                             Similar for height.  Offset src rect so x,y are relative to
   448                         origin of win, not the root-relative visible rect of win.
   415                             origin of win, not the root-relative visible rect of win.
   449                     ------------------------------------------------------------------------ **/
   416                         ------------------------------------------------------------------------ **/
   450                     srcRect_width  = MIN( vis_reg->rects[rect].x2, bbox.width + bbox.x)
   417                         int32_t srcRect_width  = MIN( vis_reg->rects[rect].x2, bbox.width + bbox.x)
   451              - MAX( vis_reg->rects[rect].x1, bbox.x);
   418                                          - MAX( vis_reg->rects[rect].x1, bbox.x);
   452 
   419 
   453                     srcRect_height = MIN( vis_reg->rects[rect].y2, bbox.height + bbox.y)
   420                         int32_t srcRect_height = MIN( vis_reg->rects[rect].y2, bbox.height + bbox.y)
   454              - MAX( vis_reg->rects[rect].y1, bbox.y);
   421                                          - MAX( vis_reg->rects[rect].y1, bbox.y);
   455 
   422 
   456                     diff = bbox.x - vis_reg->rects[rect].x1;
   423                         int32_t diff = bbox.x - vis_reg->rects[rect].x1;
   457                     srcRect_x = MAX( 0, diff)  + (vis_reg->rects[rect].x1 - reg->x_rootrel - reg->border);
   424                         int32_t srcRect_x = MAX( 0, diff)  + (vis_reg->rects[rect].x1 - reg->x_rootrel - reg->border);
   458                     dst_x     = MAX( 0, -diff) ;
   425                         int32_t dst_x     = MAX( 0, -diff) ;
   459                     diff = bbox.y - vis_reg->rects[rect].y1;
   426 
   460                     srcRect_y = MAX( 0, diff)  + (vis_reg->rects[rect].y1 - reg->y_rootrel - reg->border);
   427                         diff = bbox.y - vis_reg->rects[rect].y1;
   461                     dst_y     = MAX( 0, -diff) ;
   428                         int32_t srcRect_y = MAX( 0, diff)  + (vis_reg->rects[rect].y1 - reg->y_rootrel - reg->border);
   462             reg_image = XGetImage(disp,reg->win,srcRect_x,srcRect_y,
   429                         int32_t dst_y     = MAX( 0, -diff) ;
   463              (uint32_t) srcRect_width, (uint32_t) srcRect_height,AllPlanes,format) ;
   430                         XImage* reg_image = XGetImage(disp,reg->win,srcRect_x,srcRect_y,
   464                     TransferImage(disp,reg_image,srcRect_width,
   431                                             (uint32_t) srcRect_width, (uint32_t) srcRect_height,AllPlanes,format) ;
   465                                  srcRect_height,reg,ximage,dst_x,dst_y) ;
   432 
   466             XDestroyImage(reg_image);
   433                         if (reg_image) {
   467             }
   434                             TransferImage(disp,reg_image,srcRect_width,
       
   435                                             srcRect_height,reg,ximage,dst_x,dst_y) ;
       
   436                             XDestroyImage(reg_image);
       
   437                         }
       
   438                 }
   468     }
   439     }
   469     return ximage ;
   440     return ximage ;
   470 }
   441 }
   471 
   442 
   472 
   443