0N/A/*
2362N/A * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A/* $XConsortium: multiVis.c /main/4 1996/10/14 15:04:08 swick $ */
0N/A/** ------------------------------------------------------------------------
0N/A This file contains functions to create a list of regions which
0N/A tile a specified window. Each region contains all visible
0N/A portions of the window which are drawn with the same visual.
0N/A If the window consists of subwindows of two different visual types,
0N/A there will be two regions in the list. The list can be traversed
0N/A to correctly pull an image of the window using XGetImage or the
0N/A Image Library.
0N/A
0N/A This file is available under and governed by the GNU General Public
0N/A License version 2 only, as published by the Free Software Foundation.
0N/A However, the following notice accompanied the original version of this
0N/A file:
0N/A
0N/ACopyright (c) 1994 Hewlett-Packard Co.
0N/ACopyright (c) 1996 X Consortium
0N/A
0N/APermission is hereby granted, free of charge, to any person obtaining
0N/Aa copy of this software and associated documentation files (the
0N/A"Software"), to deal in the Software without restriction, including
0N/Awithout limitation the rights to use, copy, modify, merge, publish,
0N/Adistribute, sublicense, and sell copies of the Software, and to
0N/Apermit persons to whom the Software is furnished to do so, subject to
0N/Athe following conditions:
0N/A
0N/AThe above copyright notice and this permission notice shall be included
0N/Ain all copies or substantial portions of the Software.
0N/A
0N/ATHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
0N/AOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0N/AMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
0N/AIN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
0N/AOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0N/AARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0N/AOTHER DEALINGS IN THE SOFTWARE.
0N/A
0N/AExcept as contained in this notice, the name of the X Consortium shall
0N/Anot be used in advertising or otherwise to promote the sale, use or
0N/Aother dealings in this Software without prior written authorization
0N/Afrom the X Consortium.
0N/A
0N/A ------------------------------------------------------------------------ **/
0N/A#include <stdlib.h>
0N/A#include <X11/Xlib.h>
0N/A#include <X11/Xutil.h>
0N/A#include <X11/X.h>
0N/A#include <stdio.h>
0N/A#include "list.h"
0N/A#include "wsutils.h"
0N/A#include "multiVis.h"
0N/A#include "robot_common.h"
0N/A
0N/Astatic char *vis_class_str[] = { "StaticGray" , "GrayScale" , "StaticColor",
0N/A "PseudoColor","TrueColor","DirectColor" } ;
0N/A/* These structures are copied from X11/region.h. For some reason
0N/A * they're invisible from the outside.*/
0N/A
0N/Atypedef struct {
0N/A short x1, x2, y1, y2;
0N/A} myBox, myBOX, myBoxRec, *myBoxPtr;
0N/A
0N/Atypedef struct my_XRegion { /* 64-bit: Region is supposed to be opaque */
0N/A long size; /* but it is defined here anyway. I'm going */
0N/A long numRects; /* to leave those longs alone. */
0N/A myBOX *rects;
0N/A myBOX extents;
0N/A} myREGION;
0N/A
0N/A/* Items in long list of windows that have some part in the grabbed area */
0N/Atypedef struct {
0N/A Window win;
0N/A Visual *vis;
0N/A Colormap cmap;
0N/A int32_t x_rootrel, y_rootrel; /* root relative location of window */
0N/A int32_t x_vis, y_vis; /* rt rel x,y of vis part, not parent clipped */
0N/A int32_t width, height; /* width and height of visible part */
0N/A int32_t border_width; /* border width of the window */
0N/A Window parent; /* id of parent (for debugging) */
0N/A} image_win_type;
0N/A
0N/A/* Items in short list of regions that tile the grabbed area. May have
0N/A multiple windows in the region.
0N/A*/
0N/Atypedef struct {
0N/A Window win; /* lowest window of this visual */
0N/A Visual *vis;
0N/A Colormap cmap;
0N/A int32_t x_rootrel, y_rootrel; /* root relative location of bottom window */
0N/A int32_t x_vis, y_vis; /* rt rel x,y of vis part, not parent clipped */
0N/A int32_t width, height; /* w & h of visible rect of bottom window */
0N/A int32_t border; /* border width of the window */
0N/A Region visible_region;
0N/A} image_region_type;
0N/A
0N/A/** ------------------------------------------------------------------------
0N/A Returns TRUE if the two structs pointed to have the same "vis" &
0N/A "cmap" fields and s2 lies completely within s1. s1 and s2 can
0N/A point to structs of image_win_type or image_region_type.
0N/A ------------------------------------------------------------------------ **/
0N/A#define SAME_REGIONS( s1, s2) \
0N/A ((s1)->vis == (s2)->vis && (s1)->cmap == (s2)->cmap && \
0N/A (s1)->x_vis <= (s2)->x_vis && \
0N/A (s1)->y_vis <= (s2)->y_vis && \
0N/A (s1)->x_vis + (s1)->width >= (s2)->x_vis + (s2)->width && \
0N/A (s1)->y_vis + (s1)->height >= (s2)->y_vis + (s2)->height)
0N/A
0N/A#ifndef MIN
0N/A#define MIN( a, b) ((a) < (b) ? a : b)
0N/A#define MAX( a, b) ((a) > (b) ? a : b)
0N/A#endif
0N/A
0N/A#define RED_SHIFT 16
0N/A#define GREEN_SHIFT 8
0N/A#define BLUE_SHIFT 0
0N/A
0N/A/*
0N/Aextern list_ptr new_list();
0N/Aextern list_ptr dup_list_head();
0N/Aextern void * first_in_list();
0N/Aextern void * next_in_list();
0N/Aextern int32_t add_to_list();
0N/Aextern void zero_list();
0N/Aextern void delete_list();
0N/Aextern void delete_list_destroying();
0N/Aextern uint32_t list_length();
0N/A*/
0N/A
0N/A/* Prototype Declarations for Static Functions */
0N/Astatic void TransferImage(
0N/A#if NeedFunctionPrototypes
0N/A Display *, XImage *,int32_t, int32_t , image_region_type*,
0N/A XImage *,int32_t ,int32_t
0N/A#endif
0N/A );
0N/Astatic XImage * ReadRegionsInList(
0N/A#if NeedFunctionPrototypes
0N/A Display *, Visual *, int32_t ,int32_t ,int32_t ,
0N/A int32_t , XRectangle, list_ptr
0N/A#endif
0N/A );
0N/A
0N/Astatic list_ptr make_region_list(
0N/A#if NeedFunctionPrototypes
0N/A Display*, Window, XRectangle*,
0N/A int32_t*, int32_t, XVisualInfo**, int32_t *
0N/A#endif
0N/A );
0N/A
0N/Astatic void destroy_region_list(
0N/A#if NeedFunctionPrototypes
0N/A list_ptr
0N/A#endif
0N/A ) ;
0N/Astatic void subtr_rect_from_image_region(
0N/A#if NeedFunctionPrototypes
0N/A image_region_type *, int32_t , int32_t , int32_t , int32_t
0N/A#endif
0N/A );
0N/Astatic void add_rect_to_image_region(
0N/A#if NeedFunctionPrototypes
0N/A image_region_type *,
0N/A int32_t , int32_t , int32_t , int32_t
0N/A#endif
0N/A );
0N/Astatic int32_t src_in_region_list(
0N/A#if NeedFunctionPrototypes
0N/A image_win_type *, list_ptr
0N/A#endif
0N/A );
0N/Astatic void add_window_to_list(
0N/A#if NeedFunctionPrototypes
0N/A list_ptr, Window, int32_t, int32_t ,
0N/A int32_t , int32_t , int32_t , int32_t, int32_t,
0N/A Visual*, Colormap, Window
0N/A#endif
0N/A );
0N/Astatic int32_t src_in_image(
0N/A#if NeedFunctionPrototypes
0N/A image_win_type *, int32_t , XVisualInfo**
0N/A#endif
0N/A );
0N/Astatic int32_t src_in_overlay(
0N/A#if NeedFunctionPrototypes
0N/A image_region_type *, int32_t, OverlayInfo *, int32_t*, int32_t*
0N/A#endif
0N/A );
0N/A
0N/A/* End of Prototype Declarations */
0N/A
0N/Avoid initFakeVisual(Vis)
0N/AVisual *Vis ;
0N/A{
0N/A Vis->ext_data=NULL;
0N/A Vis->class = DirectColor ;
0N/A Vis->red_mask = 0x00FF0000;
0N/A Vis->green_mask = 0x0000FF00 ;
0N/A Vis->blue_mask = 0x000000FF ;
0N/A Vis->map_entries = 256 ;
0N/A Vis->bits_per_rgb = 8 ;
0N/A}
0N/A
0N/A/* QueryColorMap has been moved into robot_common.c so it can be used by
0N/A * awt_DataTransferer.c as well.
0N/A */
0N/A
0N/Aint32_t
0N/AGetMultiVisualRegions(disp,srcRootWinid, x, y, width, height,
0N/A transparentOverlays,numVisuals, pVisuals,numOverlayVisuals, pOverlayVisuals,
0N/A numImageVisuals, pImageVisuals,vis_regions,vis_image_regions,allImage)
0N/A Display *disp;
0N/A Window srcRootWinid; /* root win on which grab was done */
0N/A int32_t x; /* root rel UL corner of bounding box of grab */
0N/A int32_t y;
0N/A uint32_t width; /* size of bounding box of grab */
0N/A uint32_t height;
0N/A int32_t *transparentOverlays ;
0N/A int32_t *numVisuals;
0N/A XVisualInfo **pVisuals;
0N/A int32_t *numOverlayVisuals;
0N/A OverlayInfo **pOverlayVisuals;
0N/A int32_t *numImageVisuals;
0N/A XVisualInfo ***pImageVisuals;
0N/A list_ptr *vis_regions; /* list of regions to read from */
0N/A list_ptr *vis_image_regions ;
0N/A int32_t *allImage ;
0N/A{
0N/A int32_t hasNonDefault;
0N/A XRectangle bbox; /* bounding box of grabbed area */
0N/A
0N/A
0N/A /* Java uses 32-bit ints for coordinates, but XRectangles use 16-bit shorts.
0N/A * Hope nobody passes in too big a coordinate */
0N/A
0N/A bbox.x = (short) x; /* init X rect for bounding box */
0N/A bbox.y = (short) y;
0N/A bbox.width = (unsigned short) width;
0N/A bbox.height = (unsigned short) height;
0N/A
0N/A GetXVisualInfo(disp,DefaultScreen(disp),
0N/A transparentOverlays,
0N/A numVisuals, pVisuals,
0N/A numOverlayVisuals, pOverlayVisuals,
0N/A numImageVisuals, pImageVisuals);
0N/A
0N/A *vis_regions = *vis_image_regions = NULL ;
0N/A if ((*vis_regions = make_region_list( disp, srcRootWinid, &bbox,
0N/A &hasNonDefault, *numImageVisuals,
0N/A *pImageVisuals, allImage)) == NULL)
0N/A return 0 ;
0N/A
0N/A if (*transparentOverlays)
0N/A {
0N/A *allImage = 1; /* until proven otherwise,
0N/A this flags that it to be an image only list */
0N/A *vis_image_regions =
0N/A make_region_list( disp, srcRootWinid, &bbox, &hasNonDefault,
0N/A *numImageVisuals, *pImageVisuals, allImage);
0N/A }
0N/A
0N/A /* if there is a second region in any of the two lists return 1 **/
0N/A if ( ( *vis_regions && (*vis_regions)->next && (*vis_regions)->next->next ) ||
0N/A ( *vis_image_regions && (*vis_image_regions)->next &&
0N/A (*vis_image_regions)->next->next ) ) return 1 ;
0N/A else return 0 ;
0N/A
0N/A}
0N/A
0N/Astatic void TransferImage(disp,reg_image,srcw,srch,reg,
0N/A target_image,dst_x,dst_y)
0N/ADisplay *disp;
0N/AXImage *reg_image,*target_image ;
0N/Aimage_region_type *reg;
0N/Aint32_t srcw,srch,dst_x , dst_y ;
0N/A{
0N/A int32_t ncolors;
0N/A int32_t i,j,old_pixel,new_pixel,red_ind,green_ind,blue_ind ;
0N/A XColor *colors;
0N/A int32_t rShift,gShift,bShift;
0N/A int32_t targetBytesPerLine ;
0N/A
0N/A ncolors = QueryColorMap(disp,reg->cmap,reg->vis,&colors,
0N/A &rShift,&gShift,&bShift) ;
0N/A
0N/A targetBytesPerLine = target_image->bytes_per_line;
0N/A
0N/A switch (reg->vis->class) {
0N/A case TrueColor :
0N/A for(i=0 ; i < srch ; i++)
0N/A {
0N/A for(j=0 ; j < srcw ; j++)
0N/A {
0N/A old_pixel = (int32_t) XGetPixel(reg_image,j,i) ;
0N/A
0N/A/* commented out since not using server RGB masks in all true color modes
0N/A * causes the R and B values to be swapped around on some X servers
0N/A * - robi.khan@eng 9/7/1999
0N/A * if( reg->vis->map_entries == 16) {
0N/A */
0N/A red_ind = (old_pixel & reg->vis->red_mask) >> rShift ;
0N/A green_ind = (old_pixel & reg->vis->green_mask) >> gShift ;
0N/A blue_ind = (old_pixel & reg->vis->blue_mask) >> bShift ;
0N/A
0N/A new_pixel = (
0N/A ((colors[red_ind].red >> 8) << RED_SHIFT)
0N/A |((colors[green_ind].green >> 8) << GREEN_SHIFT)
0N/A |((colors[blue_ind].blue >> 8) << BLUE_SHIFT)
0N/A );
0N/A/* }
0N/A * else
0N/A * new_pixel = old_pixel;
0N/A */
0N/A
0N/A XPutPixel(target_image,dst_x+j, dst_y+i,new_pixel);
0N/A
0N/A }
0N/A }
0N/A break;
0N/A case DirectColor :
0N/A for(i=0 ; i < srch ; i++)
0N/A {
0N/A for(j=0 ; j < srcw ; j++)
0N/A {
0N/A old_pixel = (int32_t) XGetPixel(reg_image,j,i) ;
0N/A red_ind = (old_pixel & reg->vis->red_mask) >> rShift ;
0N/A green_ind = (old_pixel & reg->vis->green_mask) >> gShift ;
0N/A blue_ind = (old_pixel & reg->vis->blue_mask) >> bShift ;
0N/A
0N/A new_pixel = (
0N/A ((colors[red_ind].red >> 8) << RED_SHIFT)
0N/A |((colors[green_ind].green >> 8) << GREEN_SHIFT)
0N/A |((colors[blue_ind].blue >> 8) << BLUE_SHIFT)
0N/A );
0N/A XPutPixel(target_image,dst_x+j, dst_y+i,new_pixel);
0N/A
0N/A }
0N/A }
0N/A break;
0N/A default :
0N/A for(i=0 ; i < srch ; i++)
0N/A {
0N/A for(j=0 ; j < srcw ; j++)
0N/A {
0N/A old_pixel = (int32_t) XGetPixel(reg_image,j,i) ;
0N/A
0N/A new_pixel = (
0N/A ((colors[old_pixel].red >> 8) << RED_SHIFT)
0N/A |((colors[old_pixel].green >> 8) << GREEN_SHIFT)
0N/A |((colors[old_pixel].blue >> 8) << BLUE_SHIFT)
0N/A );
0N/A XPutPixel(target_image,dst_x+j, dst_y+i,new_pixel);
0N/A
0N/A }
0N/A }
0N/A break;
0N/A }
0N/A
0N/A /* Fix memory leak by freeing colors
0N/A * - robi.khan@eng 9/22/1999
0N/A */
0N/A free(colors);
0N/A}
0N/A
0N/Astatic XImage *
0N/AReadRegionsInList(disp,fakeVis,depth,format,width,height,bbox,regions)
0N/ADisplay *disp ;
0N/AVisual *fakeVis ;
0N/Aint32_t depth , width , height ;
0N/Aint32_t format ;
0N/AXRectangle bbox; /* bounding box of grabbed area */
0N/Alist_ptr regions;/* list of regions to read from */
0N/A{
0N/A image_region_type *reg;
0N/A int32_t dst_x, dst_y; /* where in pixmap to write (UL) */
0N/A int32_t diff;
0N/A
0N/A XImage *reg_image,*ximage ;
0N/A int32_t srcRect_x,srcRect_y,srcRect_width,srcRect_height ;
0N/A int32_t rem ;
0N/A int32_t bytes_per_line;
0N/A int32_t bitmap_unit;
0N/A
0N/A bitmap_unit = sizeof (long);
0N/A if (format == ZPixmap)
0N/A bytes_per_line = width*depth/8;
0N/A else
0N/A bytes_per_line = width/8;
0N/A
0N/A
0N/A /* Find out how many more bytes are required for padding so that
0N/A ** bytes per scan line will be multiples of bitmap_unit bits */
0N/A if (format == ZPixmap) {
0N/A rem = (bytes_per_line*8)%bitmap_unit;
0N/A if (rem)
0N/A bytes_per_line += (rem/8 + 1);
0N/A }
0N/A
0N/A ximage = XCreateImage(disp,fakeVis,(uint32_t) depth,format,0,NULL,
0N/A (uint32_t)width,(uint32_t)height,8,0);
0N/A
0N/A bytes_per_line = ximage->bytes_per_line;
0N/A
0N/A if (format == ZPixmap)
0N/A ximage->data = malloc(height*bytes_per_line);
0N/A else
0N/A ximage->data = malloc(height*bytes_per_line*depth);
0N/A
0N/A ximage->bits_per_pixel = depth; /** Valid only if format is ZPixmap ***/
0N/A
0N/A for (reg = (image_region_type *) first_in_list( regions); reg;
0N/A reg = (image_region_type *) next_in_list( regions))
0N/A {
0N/A int32_t rect;
0N/A struct my_XRegion *vis_reg;
0N/A vis_reg = (struct my_XRegion *)(reg->visible_region);
0N/A for (rect = 0;
0N/A rect < vis_reg->numRects;
0N/A rect++)
0N/A {
0N/A /** ------------------------------------------------------------------------
0N/A Intersect bbox with visible part of region giving src rect & output
0N/A location. Width is the min right side minus the max left side.
0N/A Similar for height. Offset src rect so x,y are relative to
0N/A origin of win, not the root-relative visible rect of win.
0N/A ------------------------------------------------------------------------ **/
0N/A srcRect_width = MIN( vis_reg->rects[rect].x2, bbox.width + bbox.x)
0N/A - MAX( vis_reg->rects[rect].x1, bbox.x);
0N/A
0N/A srcRect_height = MIN( vis_reg->rects[rect].y2, bbox.height + bbox.y)
0N/A - MAX( vis_reg->rects[rect].y1, bbox.y);
0N/A
0N/A diff = bbox.x - vis_reg->rects[rect].x1;
0N/A srcRect_x = MAX( 0, diff) + (vis_reg->rects[rect].x1 - reg->x_rootrel - reg->border);
0N/A dst_x = MAX( 0, -diff) ;
0N/A diff = bbox.y - vis_reg->rects[rect].y1;
0N/A srcRect_y = MAX( 0, diff) + (vis_reg->rects[rect].y1 - reg->y_rootrel - reg->border);
0N/A dst_y = MAX( 0, -diff) ;
0N/A reg_image = XGetImage(disp,reg->win,srcRect_x,srcRect_y,
0N/A (uint32_t) srcRect_width, (uint32_t) srcRect_height,AllPlanes,format) ;
0N/A TransferImage(disp,reg_image,srcRect_width,
0N/A srcRect_height,reg,ximage,dst_x,dst_y) ;
0N/A XDestroyImage(reg_image);
0N/A }
0N/A }
0N/A return ximage ;
0N/A}
0N/A
0N/A
0N/A/** ------------------------------------------------------------------------
0N/A ------------------------------------------------------------------------ **/
0N/A
0N/AXImage *ReadAreaToImage(disp, srcRootWinid, x, y, width, height,
0N/A numVisuals,pVisuals,numOverlayVisuals,pOverlayVisuals,numImageVisuals,
0N/A pImageVisuals,vis_regions,vis_image_regions,format,allImage)
0N/A Display *disp;
0N/A Window srcRootWinid; /* root win on which grab was done */
0N/A int32_t x; /* root rel UL corner of bounding box of grab */
0N/A int32_t y;
0N/A uint32_t width; /* size of bounding box of grab */
0N/A uint32_t height;
0N/A /** int32_t transparentOverlays; ***/
0N/A int32_t numVisuals;
0N/A XVisualInfo *pVisuals;
0N/A int32_t numOverlayVisuals;
0N/A OverlayInfo *pOverlayVisuals;
0N/A int32_t numImageVisuals;
0N/A XVisualInfo **pImageVisuals;
0N/A list_ptr vis_regions; /* list of regions to read from */
0N/A list_ptr vis_image_regions ;/* list of regions to read from */
0N/A int32_t format;
0N/A int32_t allImage ;
0N/A{
0N/A image_region_type *reg;
0N/A XRectangle bbox; /* bounding box of grabbed area */
0N/A int32_t depth ;
0N/A XImage *ximage, *ximage_ipm ;
0N/A Visual fakeVis ;
0N/A int32_t x1, y1;
0N/A XImage *image;
0N/A unsigned char *pmData , *ipmData ;
0N/A int32_t transparentColor, transparentType;
0N/A int32_t srcRect_x,srcRect_y,srcRect_width,srcRect_height ;
0N/A int32_t diff ;
0N/A int32_t dst_x, dst_y; /* where in pixmap to write (UL) */
0N/A int32_t pixel;
0N/A
0N/A bbox.x = (short) x; /* init X rect for bounding box */
0N/A bbox.y = (short) y;
0N/A bbox.width = (unsigned short) width;
0N/A bbox.height = (unsigned short) height;
0N/A ximage_ipm = NULL;
0N/A
0N/A
0N/A initFakeVisual(&fakeVis) ;
0N/A
0N/A depth = 24 ;
0N/A ximage = ReadRegionsInList(disp,&fakeVis,depth,format,
0N/A (int32_t) width, (int32_t) height, bbox,vis_regions) ;
0N/A
0N/A pmData = (unsigned char *)ximage -> data ;
0N/A
0N/A/* if transparency possible do it again, but this time for image planes only */
0N/A if (vis_image_regions && (vis_image_regions->next) && !allImage)
0N/A {
0N/A ximage_ipm = ReadRegionsInList(disp,&fakeVis,depth,format,
0N/A (int32_t) width, (int32_t) height,bbox,vis_image_regions) ;
0N/A ipmData = (unsigned char *)ximage_ipm -> data ;
0N/A }
0N/A/* Now tranverse the overlay visual windows and test for transparency index. */
0N/A/* If you find one, subsitute the value from the matching image plane pixmap. */
0N/A
0N/A for (reg = (image_region_type *) first_in_list( vis_regions); reg;
0N/A reg = (image_region_type *) next_in_list( vis_regions))
0N/A {
0N/A
0N/A if (src_in_overlay( reg, numOverlayVisuals, pOverlayVisuals,
0N/A &transparentColor, &transparentType))
0N/A {
0N/A int32_t test = 0 ;
0N/A srcRect_width = MIN( reg->width + reg->x_vis, bbox.width + bbox.x)
0N/A - MAX( reg->x_vis, bbox.x);
0N/A srcRect_height = MIN( reg->height + reg->y_vis, bbox.height
0N/A + bbox.y) - MAX( reg->y_vis, bbox.y);
0N/A diff = bbox.x - reg->x_vis;
0N/A srcRect_x = MAX( 0, diff) + (reg->x_vis - reg->x_rootrel - reg->border);
0N/A dst_x = MAX( 0, -diff) ;
0N/A diff = bbox.y - reg->y_vis;
0N/A srcRect_y = MAX( 0, diff) + (reg->y_vis - reg->y_rootrel - reg->border);
0N/A dst_y = MAX( 0, -diff) ;
0N/A /* let's test some pixels for transparency */
0N/A image = XGetImage(disp, reg->win, srcRect_x, srcRect_y,
0N/A (uint32_t) srcRect_width, (uint32_t) srcRect_height,
0N/A 0xffffffff, ZPixmap);
0N/A
0N/A /* let's assume byte per pixel for overlay image for now */
0N/A if ((image->depth == 8) && (transparentType == TransparentPixel))
0N/A {
0N/A unsigned char *pixel_ptr;
0N/A unsigned char *start_of_line = (unsigned char *) image->data;
0N/A
0N/A for (y1 = 0; y1 < srcRect_height; y1++) {
0N/A pixel_ptr = start_of_line;
0N/A for (x1 = 0; x1 < srcRect_width; x1++)
0N/A {
0N/A if (*pixel_ptr++ == transparentColor)
0N/A {
0N/A /*
0N/A *pmData++ = *ipmData++;
0N/A *pmData++ = *ipmData++;
0N/A *pmData++ = *ipmData++;
0N/A */
0N/A pixel = (int32_t) XGetPixel(ximage_ipm,dst_x+x1,dst_y+y1) ;
0N/A XPutPixel(ximage,dst_x+x1, dst_y+y1,(unsigned long)pixel);
0N/A
0N/A if(!test){
0N/A test = 1 ;
0N/A }
0N/A }
0N/A /*
0N/A else {
0N/A pmData +=3;
0N/A ipmData +=3;
0N/A }
0N/A */
0N/A }
0N/A start_of_line += image->bytes_per_line;
0N/A }
0N/A } else {
0N/A if (transparentType == TransparentPixel) {
0N/A for (y1 = 0; y1 < srcRect_height; y1++) {
0N/A for (x1 = 0; x1 < srcRect_width; x1++)
0N/A {
0N/A int32_t pixel_value = (int32_t) XGetPixel(image, x1, y1);
0N/A if (pixel_value == transparentColor)
0N/A {
0N/A /*
0N/A *pmData++ = *ipmData++;
0N/A *pmData++ = *ipmData++;
0N/A *pmData++ = *ipmData++;
0N/A */
0N/A pixel = (int32_t) XGetPixel(ximage_ipm,dst_x+x1,dst_y+y1) ;
0N/A XPutPixel(ximage,dst_x+x1, dst_y+y1,(unsigned long)pixel);
0N/A if(!test){
0N/A test = 1 ;
0N/A }
0N/A }
0N/A /*
0N/A else {
0N/A pmData +=3;
0N/A ipmData +=3;
0N/A }
0N/A */
0N/A }
0N/A }
0N/A } else {
0N/A for (y1 = 0; y1 < srcRect_height; y1++) {
0N/A for (x1 = 0; x1 < srcRect_width; x1++)
0N/A {
0N/A int32_t pixel_value = (int32_t) XGetPixel(image, x1, y1);
0N/A if (pixel_value & transparentColor)
0N/A {
0N/A /*
0N/A *pmData++ = *ipmData++;
0N/A *pmData++ = *ipmData++;
0N/A *pmData++ = *ipmData++;
0N/A */
0N/A pixel = (int32_t) XGetPixel(ximage_ipm,dst_x+x1,
0N/A dst_y+y1) ;
0N/A XPutPixel(ximage,dst_x+x1, dst_y+y1,(unsigned long)pixel);
0N/A if(!test){
0N/A test = 1 ;
0N/A }
0N/A }
0N/A /*
0N/A else {
0N/A pmData +=3;
0N/A ipmData +=3;
0N/A }
0N/A */
0N/A }
0N/A }
0N/A }
0N/A }
0N/A XDestroyImage (image);
0N/A } /* end of src_in_overlay */
0N/A } /** end transparency **/
0N/A if (ximage_ipm != NULL) {
0N/A XDestroyImage(ximage_ipm);
0N/A }
0N/A destroy_region_list( vis_regions);
0N/A if (vis_image_regions) destroy_region_list( vis_image_regions );
0N/A FreeXVisualInfo(pVisuals, pOverlayVisuals, pImageVisuals);
0N/A XSync(disp, 0);
0N/A
0N/A return ximage;
0N/A}
0N/A
0N/A/** ------------------------------------------------------------------------
0N/A Creates a list of the subwindows of a given window which have a
0N/A different visual than their parents. The function is recursive.
0N/A This list is used in make_region_list(), which coalesces the
0N/A windows with the same visual into a region.
0N/A image_wins must point to an existing list struct that's already
0N/A been zeroed (zero_list()).
0N/A ------------------------------------------------------------------------ **/
0N/Astatic void make_src_list( disp, image_wins, bbox, curr, x_rootrel, y_rootrel,
0N/A curr_attrs, pclip)
0N/A Display *disp;
0N/A list_ptr image_wins;
0N/A XRectangle *bbox; /* bnding box of area we want */
0N/A Window curr;
0N/A int32_t x_rootrel; /* pos of curr WRT root */
0N/A int32_t y_rootrel;
0N/A XWindowAttributes *curr_attrs;
0N/A XRectangle *pclip; /* visible part of curr, not */
0N/A /* obscurred by ancestors */
0N/A{
0N/A XWindowAttributes child_attrs;
0N/A Window root, parent, *child; /* variables for XQueryTree() */
0N/A Window *save_child_list; /* variables for XQueryTree() */
0N/A uint32_t nchild; /* variables for XQueryTree() */
0N/A XRectangle child_clip; /* vis part of child */
0N/A int32_t curr_clipX, curr_clipY, curr_clipRt, curr_clipBt;
0N/A
0N/A /* check that win is mapped & not outside bounding box */
0N/A if (curr_attrs->map_state == IsViewable &&
0N/A curr_attrs->class == InputOutput &&
0N/A !( pclip->x >= (bbox->x + bbox->width) ||
0N/A pclip->y >= (bbox->y + bbox->height) ||
0N/A (pclip->x + pclip->width) <= bbox->x ||
0N/A (pclip->y + pclip->height) <= bbox->y)) {
0N/A
0N/A XQueryTree( disp, curr, &root, &parent, &child, &nchild );
0N/A save_child_list = child; /* so we can free list when we're done */
0N/A add_window_to_list( image_wins, curr, x_rootrel, y_rootrel,
0N/A (int32_t) pclip->x, (int32_t) pclip->y,
0N/A (int32_t) pclip->width, (int32_t) pclip->height,
0N/A curr_attrs->border_width,curr_attrs->visual,
0N/A curr_attrs->colormap, parent);
0N/A
0N/A
0N/A/** ------------------------------------------------------------------------
0N/A set RR coords of right (Rt), left (X), bottom (Bt) and top (Y)
0N/A of rect we clip all children by. This is our own clip rect (pclip)
0N/A inflicted on us by our parent plus our own borders. Within the
0N/A child loop, we figure the clip rect for each child by adding in
0N/A it's rectangle (not taking into account the child's borders).
0N/A ------------------------------------------------------------------------ **/
0N/A curr_clipX = MAX( pclip->x, x_rootrel + curr_attrs->border_width);
0N/A curr_clipY = MAX( pclip->y, y_rootrel + curr_attrs->border_width);
0N/A curr_clipRt = MIN(pclip->x + pclip->width,
0N/A x_rootrel + curr_attrs->width + 2 * curr_attrs->border_width);
0N/A
0N/A curr_clipBt = MIN(pclip->y + pclip->height,
0N/A y_rootrel + curr_attrs->height + 2 * curr_attrs->border_width);
0N/A
0N/A
0N/A while (nchild--) {
0N/A int32_t new_width, new_height;
0N/A int32_t child_xrr, child_yrr; /* root relative x & y of child */
0N/A
0N/A XGetWindowAttributes( disp, *child, &child_attrs);
0N/A
0N/A /* intersect parent & child clip rects */
0N/A child_xrr = x_rootrel + child_attrs.x + curr_attrs->border_width;
0N/A child_clip.x = (short) MAX( curr_clipX, child_xrr);
0N/A new_width = MIN(curr_clipRt,
0N/A child_xrr + child_attrs.width +
0N/A 2 * child_attrs.border_width) - child_clip.x;
0N/A
0N/A if (new_width >= 0) {
0N/A child_clip.width = (unsigned short) new_width;
0N/A
0N/A child_yrr = y_rootrel + child_attrs.y +
0N/A curr_attrs->border_width;
0N/A child_clip.y = (short) MAX( curr_clipY, child_yrr);
0N/A new_height = MIN(curr_clipBt,
0N/A child_yrr + (int32_t) child_attrs.height +
0N/A 2 * child_attrs.border_width) - child_clip.y;
0N/A
0N/A if (new_height >= 0) {
0N/A child_clip.height = (unsigned short) new_height;
0N/A make_src_list( disp, image_wins, bbox, *child,
0N/A child_xrr, child_yrr,
0N/A &child_attrs, &child_clip);
0N/A }
0N/A }
0N/A child++;
0N/A }
0N/A XFree( save_child_list);
0N/A }
0N/A}
0N/A
0N/A
0N/A/** ------------------------------------------------------------------------
0N/A This function creates a list of regions which tile a specified
0N/A window. Each region contains all visible portions of the window
0N/A which are drawn with the same visual. For example, if the
0N/A window consists of subwindows of two different visual types,
0N/A there will be two regions in the list.
0N/A Returns a pointer to the list.
0N/A ------------------------------------------------------------------------ **/
0N/Astatic list_ptr make_region_list( disp, win, bbox, hasNonDefault,
0N/A numImageVisuals, pImageVisuals, allImage)
0N/A Display *disp;
0N/A Window win;
0N/A XRectangle *bbox;
0N/A int32_t *hasNonDefault;
0N/A int32_t numImageVisuals;
0N/A XVisualInfo **pImageVisuals;
0N/A int32_t *allImage;
0N/A{
0N/A XWindowAttributes win_attrs;
0N/A list image_wins;
0N/A list_ptr image_regions;
0N/A list_ptr srcs_left;
0N/A image_region_type *new_reg;
0N/A image_win_type *base_src, *src;
0N/A Region bbox_region = XCreateRegion();
0N/A XRectangle clip;
0N/A int32_t image_only;
0N/A
0N/A int32_t count=0 ;
0N/A
0N/A *hasNonDefault = False;
0N/A XUnionRectWithRegion( bbox, bbox_region, bbox_region);
0N/A XGetWindowAttributes( disp, win, &win_attrs);
0N/A
0N/A zero_list( &image_wins);
0N/A clip.x = 0;
0N/A clip.y = 0;
0N/A clip.width = (unsigned short) win_attrs.width;
0N/A clip.height = (unsigned short) win_attrs.height;
0N/A make_src_list( disp, &image_wins, bbox, win,
0N/A 0 /* x_rootrel */, 0 /* y_rootrel */, &win_attrs, &clip);
0N/A
0N/A image_regions = new_list();
0N/A image_only = (*allImage) ? True:False;
0N/A
0N/A for (base_src = (image_win_type *) first_in_list( &image_wins); base_src;
0N/A base_src = (image_win_type *) next_in_list( &image_wins))
0N/A {
0N/A /* test for image visual */
0N/A if (!image_only || src_in_image(base_src, numImageVisuals, pImageVisuals))
0N/A {
0N/A /* find a window whose visual hasn't been put in list yet */
0N/A if (!src_in_region_list( base_src, image_regions))
0N/A {
0N/A if (! (new_reg = (image_region_type *)
0N/A malloc( sizeof( image_region_type)))) {
0N/A return (list_ptr) NULL;
0N/A }
0N/A count++;
0N/A
0N/A new_reg->visible_region = XCreateRegion();
0N/A new_reg->win = base_src->win;
0N/A new_reg->vis = base_src->vis;
0N/A new_reg->cmap = base_src->cmap;
0N/A new_reg->x_rootrel = base_src->x_rootrel;
0N/A new_reg->y_rootrel = base_src->y_rootrel;
0N/A new_reg->x_vis = base_src->x_vis;
0N/A new_reg->y_vis = base_src->y_vis;
0N/A new_reg->width = base_src->width;
0N/A new_reg->height = base_src->height;
0N/A new_reg->border = base_src->border_width;
0N/A
0N/A srcs_left = (list_ptr) dup_list_head( &image_wins, START_AT_CURR);
0N/A for (src = (image_win_type *) first_in_list( srcs_left); src;
0N/A src = (image_win_type *) next_in_list( srcs_left)) {
0N/A if (SAME_REGIONS( base_src, src)) {
0N/A add_rect_to_image_region( new_reg, src->x_vis, src->y_vis,
0N/A src->width, src->height);
0N/A }
0N/A else {
0N/A if (!image_only || src_in_image(src, numImageVisuals, pImageVisuals))
0N/A {
0N/A subtr_rect_from_image_region( new_reg, src->x_vis,
0N/A src->y_vis, src->width, src->height);
0N/A }
0N/A }
0N/A }
0N/A XIntersectRegion( bbox_region, new_reg->visible_region,
0N/A new_reg->visible_region);
0N/A if (! XEmptyRegion( new_reg->visible_region)) {
0N/A add_to_list( image_regions, new_reg);
0N/A if (new_reg->vis != DefaultVisualOfScreen( win_attrs.screen) ||
0N/A new_reg->cmap != DefaultColormapOfScreen(
0N/A win_attrs.screen)) {
0N/A *hasNonDefault = True;
0N/A }
0N/A }
0N/A else {
0N/A XDestroyRegion( new_reg->visible_region);
0N/A free( (void *) new_reg);
0N/A }
0N/A }
0N/A } else *allImage = 0;
0N/A }
0N/A delete_list( &image_wins, True);
0N/A XDestroyRegion( bbox_region);
0N/A return image_regions;
0N/A}
0N/A/** ------------------------------------------------------------------------
0N/A Destructor called from destroy_region_list().
0N/A ------------------------------------------------------------------------ **/
0N/Avoid destroy_image_region( image_region)
0N/A image_region_type *image_region;
0N/A{
0N/A XDestroyRegion( image_region->visible_region);
0N/A free( (void *) image_region);
0N/A}
0N/A
0N/A/** ------------------------------------------------------------------------
0N/A Destroys the region list, destroying all the regions contained in it.
0N/A ------------------------------------------------------------------------ **/
0N/Astatic void destroy_region_list( rlist)
0N/A list_ptr rlist;
0N/A{
0N/A delete_list_destroying( rlist, (DESTRUCT_FUNC_PTR)destroy_image_region);
0N/A}
0N/A
0N/A
0N/A/** ------------------------------------------------------------------------
0N/A Subtracts the specified rectangle from the region in image_region.
0N/A First converts the rectangle to a region of its own, since X
0N/A only provides a way to subtract one region from another, not a
0N/A rectangle from a region.
0N/A ------------------------------------------------------------------------ **/
0N/Astatic void subtr_rect_from_image_region( image_region, x, y, width, height)
0N/A image_region_type *image_region;
0N/A int32_t x;
0N/A int32_t y;
0N/A int32_t width;
0N/A int32_t height;
0N/A{
0N/A XRectangle rect;
0N/A Region rect_region;
0N/A
0N/A rect_region = XCreateRegion();
0N/A rect.x = (short)x;
0N/A rect.y = (short)y;
0N/A rect.width = (unsigned short)width;
0N/A rect.height = (unsigned short)height;
0N/A XUnionRectWithRegion( &rect, rect_region, rect_region);
0N/A XSubtractRegion( image_region->visible_region, rect_region,
0N/A image_region->visible_region);
0N/A XDestroyRegion( rect_region);
0N/A}
0N/A
0N/A
0N/A/** ------------------------------------------------------------------------
0N/A Adds the specified rectangle to the region in image_region.
0N/A ------------------------------------------------------------------------ **/
0N/Astatic void add_rect_to_image_region( image_region, x, y, width, height)
0N/A image_region_type *image_region;
0N/A int32_t x;
0N/A int32_t y;
0N/A int32_t width;
0N/A int32_t height;
0N/A{
0N/A XRectangle rect;
0N/A
0N/A rect.x = (short) x;
0N/A rect.y = (short) y;
0N/A rect.width = (unsigned short) width;
0N/A rect.height = (unsigned short) height;
0N/A XUnionRectWithRegion( &rect, image_region->visible_region,
0N/A image_region->visible_region);
0N/A}
0N/A
0N/A
0N/A/** ------------------------------------------------------------------------
0N/A Returns TRUE if the given src's visual is already represented in
0N/A the image_regions list, FALSE otherwise.
0N/A ------------------------------------------------------------------------ **/
0N/Astatic int32_t src_in_region_list( src, image_regions)
0N/A image_win_type *src;
0N/A list_ptr image_regions;
0N/A{
0N/A image_region_type *ir;
0N/A
0N/A for (ir = (image_region_type *) first_in_list( image_regions); ir;
0N/A ir = (image_region_type *) next_in_list( image_regions)) {
0N/A if (SAME_REGIONS( ir, src)) {
0N/A
0N/A return 1;
0N/A }
0N/A }
0N/A
0N/A return 0;
0N/A}
0N/A
0N/A
0N/A/** ------------------------------------------------------------------------
0N/A Makes a new entry in image_wins with the given fields filled in.
0N/A ------------------------------------------------------------------------ **/
0N/Astatic void add_window_to_list( image_wins, w, xrr, yrr, x_vis, y_vis,
0N/A width, height, border_width,vis, cmap, parent)
0N/A list_ptr image_wins;
0N/A Window w;
0N/A int32_t xrr;
0N/A int32_t yrr;
0N/A int32_t x_vis;
0N/A int32_t y_vis;
0N/A int32_t width;
0N/A int32_t height;
0N/A int32_t border_width;
0N/A Visual *vis;
0N/A Colormap cmap;
0N/A Window parent;
0N/A{
0N/A image_win_type *new_src;
0N/A
0N/A if ((new_src = (image_win_type *) malloc( sizeof( image_win_type))) == NULL)
0N/A
0N/A return;
0N/A
0N/A new_src->win = w;
0N/A new_src->x_rootrel = xrr;
0N/A new_src->y_rootrel = yrr;
0N/A new_src->x_vis = x_vis;
0N/A new_src->y_vis = y_vis;
0N/A new_src->width = width;
0N/A new_src->height = height;
0N/A new_src->border_width = border_width;
0N/A new_src->vis = vis;
0N/A new_src->cmap = cmap;
0N/A new_src->parent = parent;
0N/A add_to_list( image_wins, new_src);
0N/A}
0N/A
0N/A/** ------------------------------------------------------------------------
0N/A Returns TRUE if the given src's visual is in the image planes,
0N/A FALSE otherwise.
0N/A ------------------------------------------------------------------------ **/
0N/Astatic int32_t src_in_image( src, numImageVisuals, pImageVisuals)
0N/A image_win_type *src;
0N/A int32_t numImageVisuals;
0N/A XVisualInfo **pImageVisuals;
0N/A{
0N/A int32_t i;
0N/A
0N/A for (i = 0 ; i < numImageVisuals ; i++)
0N/A {
0N/A if (pImageVisuals[i]->visual == src->vis)
0N/A return 1;
0N/A }
0N/A return 0;
0N/A}
0N/A
0N/A
0N/A/** ------------------------------------------------------------------------
0N/A Returns TRUE if the given src's visual is in the overlay planes
0N/A and transparency is possible, FALSE otherwise.
0N/A ------------------------------------------------------------------------ **/
0N/Astatic int32_t src_in_overlay( src, numOverlayVisuals, pOverlayVisuals,
0N/A transparentColor, transparentType)
0N/A image_region_type *src;
0N/A int32_t numOverlayVisuals;
0N/A OverlayInfo *pOverlayVisuals;
0N/A int32_t *transparentColor;
0N/A int32_t *transparentType;
0N/A{
0N/A int32_t i;
0N/A
0N/A for (i = 0 ; i < numOverlayVisuals ; i++)
0N/A {
0N/A if (((pOverlayVisuals[i].pOverlayVisualInfo)->visual == src->vis)
0N/A && (pOverlayVisuals[i].transparentType != None))
0N/A {
0N/A *transparentColor = pOverlayVisuals[i].value;
0N/A *transparentType = pOverlayVisuals[i].transparentType;
0N/A return 1;
0N/A }
0N/A
0N/A else {
0N/A }
0N/A
0N/A }
0N/A return 0;
0N/A}
0N/A
0N/A
0N/A/********************** from wsutils.c ******************************/
0N/A
0N/A/******************************************************************************
0N/A *
0N/A * This file contains a set of example utility procedures; procedures that can
0N/A * help a "window-smart" Starbase or PHIGS program determine information about
0N/A * a device, and create image and overlay plane windows. To use these
0N/A * utilities, #include "wsutils.h" and compile this file and link the results
0N/A * with your program.
0N/A *
0N/A ******************************************************************************/
0N/A
0N/A
0N/A
0N/A#define STATIC_GRAY 0x01
0N/A#define GRAY_SCALE 0x02
0N/A#define PSEUDO_COLOR 0x04
0N/A#define TRUE_COLOR 0x10
0N/A#define DIRECT_COLOR 0x11
0N/A
0N/A
0N/Astatic int32_t weCreateServerOverlayVisualsProperty = False;
0N/A
0N/A
0N/A/******************************************************************************
0N/A *
0N/A * GetXVisualInfo()
0N/A *
0N/A * This routine takes an X11 Display, screen number, and returns whether the
0N/A * screen supports transparent overlays and three arrays:
0N/A *
0N/A * 1) All of the XVisualInfo struct's for the screen.
0N/A * 2) All of the OverlayInfo struct's for the screen.
0N/A * 3) An array of pointers to the screen's image plane XVisualInfo
0N/A * structs.
0N/A *
0N/A * The code below obtains the array of all the screen's visuals, and obtains
0N/A * the array of all the screen's overlay visual information. It then processes
0N/A * the array of the screen's visuals, determining whether the visual is an
0N/A * overlay or image visual.
0N/A *
0N/A * If the routine sucessfully obtained the visual information, it returns zero.
0N/A * If the routine didn't obtain the visual information, it returns non-zero.
0N/A *
0N/A ******************************************************************************/
0N/A
0N/Aint32_t GetXVisualInfo(display, screen, transparentOverlays,
0N/A numVisuals, pVisuals,
0N/A numOverlayVisuals, pOverlayVisuals,
0N/A numImageVisuals, pImageVisuals)
0N/A
0N/A Display *display; /* Which X server (aka "display"). */
0N/A int32_t screen; /* Which screen of the "display". */
0N/A int32_t *transparentOverlays; /* Non-zero if there's at least one
0N/A * overlay visual and if at least one
0N/A * of those supports a transparent
0N/A * pixel. */
0N/A int32_t *numVisuals; /* Number of XVisualInfo struct's
0N/A * pointed to to by pVisuals. */
0N/A XVisualInfo **pVisuals; /* All of the device's visuals. */
0N/A int32_t *numOverlayVisuals; /* Number of OverlayInfo's pointed
0N/A * to by pOverlayVisuals. If this
0N/A * number is zero, the device does
0N/A * not have overlay planes. */
0N/A OverlayInfo **pOverlayVisuals; /* The device's overlay plane visual
0N/A * information. */
0N/A int32_t *numImageVisuals; /* Number of XVisualInfo's pointed
0N/A * to by pImageVisuals. */
0N/A XVisualInfo ***pImageVisuals; /* The device's image visuals. */
0N/A{
0N/A XVisualInfo getVisInfo; /* Paramters of XGetVisualInfo */
0N/A int32_t mask;
0N/A XVisualInfo *pVis, **pIVis; /* Faster, local copies */
0N/A OverlayInfo *pOVis;
0N/A OverlayVisualPropertyRec *pOOldVis;
0N/A int32_t nVisuals, nOVisuals;
0N/A Atom overlayVisualsAtom; /* Parameters for XGetWindowProperty */
0N/A Atom actualType;
0N/A unsigned long numLongs, bytesAfter;
0N/A int32_t actualFormat;
0N/A int32_t nImageVisualsAlloced; /* Values to process the XVisualInfo */
0N/A int32_t imageVisual; /* array */
0N/A
0N/A
0N/A /* First, get the list of visuals for this screen. */
0N/A getVisInfo.screen = screen;
0N/A mask = VisualScreenMask;
0N/A
0N/A *pVisuals = XGetVisualInfo(display, mask, &getVisInfo, numVisuals);
0N/A if ((nVisuals = *numVisuals) <= 0)
0N/A {
0N/A /* Return that the information wasn't sucessfully obtained: */
0N/A return(1);
0N/A }
0N/A pVis = *pVisuals;
0N/A
0N/A
0N/A /* Now, get the overlay visual information for this screen. To obtain
0N/A * this information, get the SERVER_OVERLAY_VISUALS property.
0N/A */
0N/A overlayVisualsAtom = XInternAtom(display, "SERVER_OVERLAY_VISUALS", True);
0N/A if (overlayVisualsAtom != None)
0N/A {
0N/A /* Since the Atom exists, we can request the property's contents. The
0N/A * do-while loop makes sure we get the entire list from the X server.
0N/A */
0N/A bytesAfter = 0;
0N/A numLongs = sizeof(OverlayVisualPropertyRec) / 4;
0N/A do
0N/A {
0N/A numLongs += bytesAfter * 4;
0N/A XGetWindowProperty(display, RootWindow(display, screen),
0N/A overlayVisualsAtom, 0, numLongs, False,
0N/A overlayVisualsAtom, &actualType, &actualFormat,
0N/A &numLongs, &bytesAfter, (unsigned char**) pOverlayVisuals);
0N/A } while (bytesAfter > 0);
0N/A
0N/A
0N/A /* Calculate the number of overlay visuals in the list. */
0N/A /* *numOverlayVisuals = numLongs / (sizeof(OverlayVisualPropertyRec) / 4); */
0N/A *numOverlayVisuals = numLongs / (sizeof(OverlayVisualPropertyRec) / sizeof(long));
0N/A }
0N/A else
0N/A {
0N/A /* This screen doesn't have overlay planes. */
0N/A *numOverlayVisuals = 0;
0N/A *pOverlayVisuals = NULL;
0N/A *transparentOverlays = 0;
0N/A }
0N/A
0N/A
0N/A /* Process the pVisuals array. */
0N/A *numImageVisuals = 0;
0N/A nImageVisualsAlloced = 1;
0N/A pIVis = *pImageVisuals = (XVisualInfo **) malloc(sizeof(XVisualInfo *));
0N/A while (--nVisuals >= 0)
0N/A {
0N/A nOVisuals = *numOverlayVisuals;
0N/A pOVis = *pOverlayVisuals;
0N/A imageVisual = True;
0N/A while (--nOVisuals >= 0)
0N/A {
0N/A pOOldVis = (OverlayVisualPropertyRec *) pOVis;
0N/A if (pVis->visualid == pOOldVis->visualID)
0N/A {
0N/A imageVisual = False;
0N/A pOVis->pOverlayVisualInfo = pVis;
0N/A if (pOVis->transparentType == TransparentPixel)
0N/A *transparentOverlays = 1;
0N/A }
0N/A pOVis++;
0N/A }
0N/A if (imageVisual)
0N/A {
0N/A if ((*numImageVisuals += 1) > nImageVisualsAlloced)
0N/A {
0N/A nImageVisualsAlloced++;
0N/A *pImageVisuals = (XVisualInfo **)
0N/A realloc(*pImageVisuals, (nImageVisualsAlloced * sizeof(XVisualInfo *)));
0N/A pIVis = *pImageVisuals + (*numImageVisuals - 1);
0N/A }
0N/A *pIVis++ = pVis;
0N/A }
0N/A pVis++;
0N/A }
0N/A
0N/A
0N/A /* Return that the information was sucessfully obtained: */
0N/A return(0);
0N/A
0N/A} /* GetXVisualInfo() */
0N/A
0N/A
0N/A/******************************************************************************
0N/A *
0N/A * FreeXVisualInfo()
0N/A *
0N/A * This routine frees the data that was allocated by GetXVisualInfo().
0N/A *
0N/A ******************************************************************************/
0N/A
0N/Avoid FreeXVisualInfo(pVisuals, pOverlayVisuals, pImageVisuals)
0N/A
0N/A XVisualInfo *pVisuals;
0N/A OverlayInfo *pOverlayVisuals;
0N/A XVisualInfo **pImageVisuals;
0N/A{
0N/A XFree(pVisuals);
0N/A if (weCreateServerOverlayVisualsProperty)
0N/A free(pOverlayVisuals);
0N/A else
0N/A XFree(pOverlayVisuals);
0N/A free(pImageVisuals);
0N/A
0N/A} /* FreeXVisualInfo() */