src/java.desktop/unix/native/libawt_xawt/awt/multiVis.c
author ihse
Sat, 03 Mar 2018 08:21:47 +0100
branchihse-warnings-cflags-branch
changeset 56230 489867818774
parent 49083 673be6f60323
permissions -rw-r--r--
No longer disable E_OLD_STYLE_FUNC_DEF.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21278
diff changeset
     2
 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
/* $XConsortium: multiVis.c /main/4 1996/10/14 15:04:08 swick $ */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/** ------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
        This file contains functions to create a list of regions which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
        tile a specified window.  Each region contains all visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
        portions of the window which are drawn with the same visual.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
        If the window consists of subwindows of two different visual types,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
        there will be two regions in the list.  The list can be traversed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
        to correctly pull an image of the window using XGetImage or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
        Image Library.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 This file is available under and governed by the GNU General Public
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 License version 2 only, as published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 However, the following notice accompanied the original version of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 file:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
Copyright (c) 1994 Hewlett-Packard Co.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
Copyright (c) 1996  X Consortium
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
Permission is hereby granted, free of charge, to any person obtaining
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
a copy of this software and associated documentation files (the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
"Software"), to deal in the Software without restriction, including
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
without limitation the rights to use, copy, modify, merge, publish,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
distribute, sublicense, and sell copies of the Software, and to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
permit persons to whom the Software is furnished to do so, subject to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
the following conditions:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
The above copyright notice and this permission notice shall be included
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
in all copies or substantial portions of the Software.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
OTHER DEALINGS IN THE SOFTWARE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
Except as contained in this notice, the name of the X Consortium shall
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
not be used in advertising or otherwise to promote the sale, use or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
other dealings in this Software without prior written authorization
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
from the X Consortium.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    ------------------------------------------------------------------------ **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
#include <X11/Xlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
#include <X11/Xutil.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
#include <X11/X.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
#include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
#include "list.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
#include "wsutils.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
#include "multiVis.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
#include "robot_common.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
static char *vis_class_str[] = { "StaticGray" , "GrayScale" , "StaticColor",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                                 "PseudoColor","TrueColor","DirectColor" } ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
/* These structures are copied from X11/region.h.  For some reason
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * they're invisible from the outside.*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
typedef struct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    short x1, x2, y1, y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
} myBox, myBOX, myBoxRec, *myBoxPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
typedef struct my_XRegion {    /* 64-bit: Region is supposed to be opaque    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    long size;                 /* but it is defined here anyway.  I'm going  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    long numRects;             /* to leave those longs alone.                */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    myBOX *rects;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    myBOX extents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
} myREGION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
/* Items in long list of windows that have some part in the grabbed area */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
typedef struct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    Window win;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    Visual *vis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    Colormap cmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    int32_t x_rootrel, y_rootrel;       /* root relative location of window */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    int32_t x_vis, y_vis;               /* rt rel x,y of vis part, not parent clipped */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    int32_t width, height;              /* width and height of visible part */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    int32_t border_width;               /* border width of the window */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    Window parent;              /* id of parent (for debugging) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
} image_win_type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
/*  Items in short list of regions that tile the grabbed area.  May have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    multiple windows in the region.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
typedef struct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    Window win;                 /* lowest window of this visual */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    Visual *vis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    Colormap cmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    int32_t x_rootrel, y_rootrel;       /* root relative location of bottom window */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    int32_t x_vis, y_vis;               /* rt rel x,y of vis part, not parent clipped */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    int32_t width, height;              /* w & h of visible rect of bottom window */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    int32_t border;                     /* border width of the window */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    Region visible_region;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
} image_region_type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
/** ------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        Returns TRUE if the two structs pointed to have the same "vis" &
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        "cmap" fields and s2 lies completely within s1.  s1 and s2 can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        point to structs of image_win_type or image_region_type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    ------------------------------------------------------------------------ **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
#define SAME_REGIONS( s1, s2)   \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        ((s1)->vis == (s2)->vis && (s1)->cmap == (s2)->cmap &&          \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
         (s1)->x_vis <= (s2)->x_vis &&                              \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
         (s1)->y_vis <= (s2)->y_vis &&                              \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
         (s1)->x_vis + (s1)->width  >= (s2)->x_vis + (s2)->width && \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
         (s1)->y_vis + (s1)->height >= (s2)->y_vis + (s2)->height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
#ifndef MIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
#define MIN( a, b)      ((a) < (b) ? a : b)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
#define MAX( a, b)      ((a) > (b) ? a : b)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
#define RED_SHIFT        16
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
#define GREEN_SHIFT       8
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
#define BLUE_SHIFT        0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
extern list_ptr new_list();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
extern list_ptr dup_list_head();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
extern void *   first_in_list();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
extern void *   next_in_list();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
extern int32_t  add_to_list();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
extern void     zero_list();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
extern void     delete_list();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
extern void     delete_list_destroying();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
extern uint32_t list_length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
/* Prototype Declarations for Static Functions */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
static void TransferImage(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
           Display *, XImage *,int32_t, int32_t , image_region_type*,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
           XImage *,int32_t ,int32_t
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
           );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
static XImage * ReadRegionsInList(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
           Display *, Visual *, int32_t ,int32_t ,int32_t ,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
           int32_t , XRectangle, list_ptr
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
           );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
static list_ptr make_region_list(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                  Display*, Window, XRectangle*,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                  int32_t*, int32_t, XVisualInfo**, int32_t     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
         );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
static void destroy_region_list(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            list_ptr
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            ) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
static void subtr_rect_from_image_region(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
           image_region_type *, int32_t , int32_t , int32_t , int32_t
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
static void add_rect_to_image_region(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
           image_region_type *,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
           int32_t , int32_t , int32_t , int32_t
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
static int32_t src_in_region_list(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    image_win_type *, list_ptr
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
static void add_window_to_list(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    list_ptr, Window, int32_t, int32_t ,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    int32_t     , int32_t , int32_t , int32_t, int32_t,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    Visual*, Colormap, Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
static int32_t src_in_image(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    image_win_type      *, int32_t      , XVisualInfo**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
static int32_t src_in_overlay(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    image_region_type *, int32_t, OverlayInfo *, int32_t*, int32_t*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
/* End of Prototype Declarations */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   195
void initFakeVisual(Visual *Vis)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    Vis->ext_data=NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    Vis->class = DirectColor ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    Vis->red_mask =   0x00FF0000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    Vis->green_mask = 0x0000FF00 ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    Vis->blue_mask  = 0x000000FF ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    Vis->map_entries = 256 ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    Vis->bits_per_rgb = 8 ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
/* QueryColorMap has been moved into robot_common.c so it can be used by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
 * awt_DataTransferer.c as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   210
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   211
/*
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   212
 * srcRootWinid: root win on which grab was done
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   213
 * x, y: root rel UL corner of bounding box of grab
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   214
 * width, height: size of bounding box of grab
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   215
 * vis_regions: list of regions to read from
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   216
 */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
int32_t
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   218
GetMultiVisualRegions(
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   219
    Display             *disp,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   220
    Window              srcRootWinid,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   221
    int32_t             x,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   222
    int32_t             y,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   223
    uint32_t            width,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   224
    uint32_t            height,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   225
    int32_t             *transparentOverlays,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   226
    int32_t             *numVisuals,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   227
    XVisualInfo         **pVisuals,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   228
    int32_t             *numOverlayVisuals,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   229
    OverlayInfo         **pOverlayVisuals,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   230
    int32_t             *numImageVisuals,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   231
    XVisualInfo         ***pImageVisuals,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   232
    list_ptr            *vis_regions,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   233
    list_ptr            *vis_image_regions,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   234
    int32_t             *allImage
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   235
)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    int32_t             hasNonDefault;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    XRectangle          bbox;           /* bounding box of grabbed area */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    /* Java uses 32-bit ints for coordinates, but XRectangles use 16-bit shorts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * Hope nobody passes in too big a coordinate */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    bbox.x = (short) x;                 /* init X rect for bounding box */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    bbox.y = (short) y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    bbox.width = (unsigned short) width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    bbox.height = (unsigned short) height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    GetXVisualInfo(disp,DefaultScreen(disp),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                    transparentOverlays,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                    numVisuals, pVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                    numOverlayVisuals, pOverlayVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                    numImageVisuals, pImageVisuals);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    *vis_regions = *vis_image_regions = NULL ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    if ((*vis_regions = make_region_list( disp, srcRootWinid, &bbox,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                                         &hasNonDefault, *numImageVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                                         *pImageVisuals, allImage)) == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        return 0 ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    if (*transparentOverlays)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        *allImage = 1; /* until proven otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                         this flags that it to be an image only list */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        *vis_image_regions =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                make_region_list( disp, srcRootWinid, &bbox, &hasNonDefault,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                                        *numImageVisuals, *pImageVisuals, allImage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    /* if there is a second region in any of the two lists return 1 **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    if ( ( *vis_regions && (*vis_regions)->next && (*vis_regions)->next->next ) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
         ( *vis_image_regions && (*vis_image_regions)->next &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
           (*vis_image_regions)->next->next ) ) return 1 ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    else return 0 ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   278
static void TransferImage(
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   279
    Display *disp, XImage *reg_image,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   280
    int32_t srcw, int32_t srch,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   281
    image_region_type *reg, XImage *target_image,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   282
    int32_t dst_x, int32_t dst_y)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    int32_t ncolors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    int32_t i,j,old_pixel,new_pixel,red_ind,green_ind,blue_ind ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    XColor *colors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    int32_t rShift,gShift,bShift;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    int32_t targetBytesPerLine ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    ncolors = QueryColorMap(disp,reg->cmap,reg->vis,&colors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
         &rShift,&gShift,&bShift) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    targetBytesPerLine = target_image->bytes_per_line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    switch (reg->vis->class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    case TrueColor :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
       for(i=0 ; i < srch ; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
       {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
         for(j=0 ; j < srcw ;  j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
           old_pixel = (int32_t) XGetPixel(reg_image,j,i) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
/* commented out since not using server RGB masks in all true color modes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
 * causes the R and B values to be swapped around on some X servers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
 *    - robi.khan@eng 9/7/1999
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
 *           if( reg->vis->map_entries == 16) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
             red_ind   = (old_pixel & reg->vis->red_mask) >> rShift ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                 green_ind = (old_pixel & reg->vis->green_mask) >> gShift ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                 blue_ind  = (old_pixel & reg->vis->blue_mask) >> bShift ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                 new_pixel = (
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                              ((colors[red_ind].red >> 8) << RED_SHIFT)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                              |((colors[green_ind].green >> 8) << GREEN_SHIFT)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                              |((colors[blue_ind].blue >> 8) << BLUE_SHIFT)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                             );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
/*         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
 *  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
 *    new_pixel = old_pixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
           XPutPixel(target_image,dst_x+j, dst_y+i,new_pixel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
       break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    case DirectColor :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
       for(i=0 ; i < srch ; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
       {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
         for(j=0 ; j < srcw ;  j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
           old_pixel = (int32_t) XGetPixel(reg_image,j,i) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
           red_ind   = (old_pixel & reg->vis->red_mask) >> rShift ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
               green_ind = (old_pixel & reg->vis->green_mask) >> gShift ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
               blue_ind  = (old_pixel & reg->vis->blue_mask) >> bShift ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
               new_pixel = (
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                         ((colors[red_ind].red >> 8) << RED_SHIFT)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                        |((colors[green_ind].green >> 8) << GREEN_SHIFT)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                        |((colors[blue_ind].blue >> 8) << BLUE_SHIFT)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                       );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
           XPutPixel(target_image,dst_x+j, dst_y+i,new_pixel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
       break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    default :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
       for(i=0 ; i < srch ; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
       {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
         for(j=0 ; j < srcw ;  j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
         {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
               old_pixel = (int32_t) XGetPixel(reg_image,j,i) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
               new_pixel = (
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                         ((colors[old_pixel].red >> 8) << RED_SHIFT)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                        |((colors[old_pixel].green >> 8) << GREEN_SHIFT)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                        |((colors[old_pixel].blue >> 8) << BLUE_SHIFT)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                       );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
           XPutPixel(target_image,dst_x+j, dst_y+i,new_pixel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
       break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    /* Fix memory leak by freeing colors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     *  - robi.khan@eng 9/22/1999
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    free(colors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   372
/*
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   373
 * bbox: bounding box of grabbed area
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   374
 * regions: list of regions to read from
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   375
 */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
static XImage *
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   377
ReadRegionsInList(
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   378
    Display *disp,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   379
    Visual *fakeVis,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   380
    int32_t depth,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   381
    int32_t format,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   382
    int32_t width, int32_t height,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   383
    XRectangle bbox,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   384
    list_ptr regions
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   385
)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
{
49079
05077701f689 8171000: Robot.createScreenCapture() crashes in wayland mode
kaddepalli
parents: 47216
diff changeset
   387
    XImage              *ximage ;
49083
673be6f60323 8197546: Fix for 8171000 breaks Solaris + Linux builds
prr
parents: 49079
diff changeset
   388
    image_region_type* reg;
673be6f60323 8197546: Fix for 8171000 breaks Solaris + Linux builds
prr
parents: 49079
diff changeset
   389
    int32_t rect;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    ximage = XCreateImage(disp,fakeVis,(uint32_t) depth,format,0,NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                          (uint32_t)width,(uint32_t)height,8,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
49079
05077701f689 8171000: Robot.createScreenCapture() crashes in wayland mode
kaddepalli
parents: 47216
diff changeset
   394
    ximage->data = calloc(ximage->bytes_per_line*height*((format==ZPixmap)? 1 : depth), sizeof(char));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    ximage->bits_per_pixel = depth; /** Valid only if format is ZPixmap ***/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
49083
673be6f60323 8197546: Fix for 8171000 breaks Solaris + Linux builds
prr
parents: 49079
diff changeset
   397
    for (reg = (image_region_type *) first_in_list( regions); reg;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
         reg = (image_region_type *) next_in_list( regions))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    {
49079
05077701f689 8171000: Robot.createScreenCapture() crashes in wayland mode
kaddepalli
parents: 47216
diff changeset
   400
                struct my_XRegion *vis_reg = (struct my_XRegion *)(reg->visible_region);
49083
673be6f60323 8197546: Fix for 8171000 breaks Solaris + Linux builds
prr
parents: 49079
diff changeset
   401
                for (rect = 0; rect < vis_reg->numRects; rect++)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                {
49079
05077701f689 8171000: Robot.createScreenCapture() crashes in wayland mode
kaddepalli
parents: 47216
diff changeset
   403
                    /** ------------------------------------------------------------------------
05077701f689 8171000: Robot.createScreenCapture() crashes in wayland mode
kaddepalli
parents: 47216
diff changeset
   404
                            Intersect bbox with visible part of region giving src rect & output
05077701f689 8171000: Robot.createScreenCapture() crashes in wayland mode
kaddepalli
parents: 47216
diff changeset
   405
                            location.  Width is the min right side minus the max left side.
05077701f689 8171000: Robot.createScreenCapture() crashes in wayland mode
kaddepalli
parents: 47216
diff changeset
   406
                            Similar for height.  Offset src rect so x,y are relative to
05077701f689 8171000: Robot.createScreenCapture() crashes in wayland mode
kaddepalli
parents: 47216
diff changeset
   407
                            origin of win, not the root-relative visible rect of win.
05077701f689 8171000: Robot.createScreenCapture() crashes in wayland mode
kaddepalli
parents: 47216
diff changeset
   408
                        ------------------------------------------------------------------------ **/
05077701f689 8171000: Robot.createScreenCapture() crashes in wayland mode
kaddepalli
parents: 47216
diff changeset
   409
                        int32_t srcRect_width  = MIN( vis_reg->rects[rect].x2, bbox.width + bbox.x)
05077701f689 8171000: Robot.createScreenCapture() crashes in wayland mode
kaddepalli
parents: 47216
diff changeset
   410
                                         - MAX( vis_reg->rects[rect].x1, bbox.x);
05077701f689 8171000: Robot.createScreenCapture() crashes in wayland mode
kaddepalli
parents: 47216
diff changeset
   411
05077701f689 8171000: Robot.createScreenCapture() crashes in wayland mode
kaddepalli
parents: 47216
diff changeset
   412
                        int32_t srcRect_height = MIN( vis_reg->rects[rect].y2, bbox.height + bbox.y)
05077701f689 8171000: Robot.createScreenCapture() crashes in wayland mode
kaddepalli
parents: 47216
diff changeset
   413
                                         - MAX( vis_reg->rects[rect].y1, bbox.y);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
49079
05077701f689 8171000: Robot.createScreenCapture() crashes in wayland mode
kaddepalli
parents: 47216
diff changeset
   415
                        int32_t diff = bbox.x - vis_reg->rects[rect].x1;
05077701f689 8171000: Robot.createScreenCapture() crashes in wayland mode
kaddepalli
parents: 47216
diff changeset
   416
                        int32_t srcRect_x = MAX( 0, diff)  + (vis_reg->rects[rect].x1 - reg->x_rootrel - reg->border);
05077701f689 8171000: Robot.createScreenCapture() crashes in wayland mode
kaddepalli
parents: 47216
diff changeset
   417
                        int32_t dst_x     = MAX( 0, -diff) ;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
49079
05077701f689 8171000: Robot.createScreenCapture() crashes in wayland mode
kaddepalli
parents: 47216
diff changeset
   419
                        diff = bbox.y - vis_reg->rects[rect].y1;
05077701f689 8171000: Robot.createScreenCapture() crashes in wayland mode
kaddepalli
parents: 47216
diff changeset
   420
                        int32_t srcRect_y = MAX( 0, diff)  + (vis_reg->rects[rect].y1 - reg->y_rootrel - reg->border);
05077701f689 8171000: Robot.createScreenCapture() crashes in wayland mode
kaddepalli
parents: 47216
diff changeset
   421
                        int32_t dst_y     = MAX( 0, -diff) ;
05077701f689 8171000: Robot.createScreenCapture() crashes in wayland mode
kaddepalli
parents: 47216
diff changeset
   422
                        XImage* reg_image = XGetImage(disp,reg->win,srcRect_x,srcRect_y,
05077701f689 8171000: Robot.createScreenCapture() crashes in wayland mode
kaddepalli
parents: 47216
diff changeset
   423
                                            (uint32_t) srcRect_width, (uint32_t) srcRect_height,AllPlanes,format) ;
05077701f689 8171000: Robot.createScreenCapture() crashes in wayland mode
kaddepalli
parents: 47216
diff changeset
   424
05077701f689 8171000: Robot.createScreenCapture() crashes in wayland mode
kaddepalli
parents: 47216
diff changeset
   425
                        if (reg_image) {
05077701f689 8171000: Robot.createScreenCapture() crashes in wayland mode
kaddepalli
parents: 47216
diff changeset
   426
                            TransferImage(disp,reg_image,srcRect_width,
05077701f689 8171000: Robot.createScreenCapture() crashes in wayland mode
kaddepalli
parents: 47216
diff changeset
   427
                                            srcRect_height,reg,ximage,dst_x,dst_y) ;
05077701f689 8171000: Robot.createScreenCapture() crashes in wayland mode
kaddepalli
parents: 47216
diff changeset
   428
                            XDestroyImage(reg_image);
05077701f689 8171000: Robot.createScreenCapture() crashes in wayland mode
kaddepalli
parents: 47216
diff changeset
   429
                        }
05077701f689 8171000: Robot.createScreenCapture() crashes in wayland mode
kaddepalli
parents: 47216
diff changeset
   430
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    return ximage ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
/** ------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    ------------------------------------------------------------------------ **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   439
/*
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   440
 *   srcRootWinid:    root win on which grab was done
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   441
 *   x, y:    root rel UL corner of bounding box of grab
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   442
 *   width, height:   size of bounding box of grab
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   443
 *   vis_regions:     list of regions to read from
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   444
 *   vis_image_regions: list of regions to read from
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   445
 */
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   446
XImage *ReadAreaToImage(
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   447
    Display             *disp,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   448
    Window              srcRootWinid,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   449
    int32_t             x,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   450
    int32_t             y,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   451
    uint32_t            width,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   452
    uint32_t            height,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   453
    int32_t             numVisuals,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   454
    XVisualInfo         *pVisuals,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   455
    int32_t             numOverlayVisuals,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   456
    OverlayInfo         *pOverlayVisuals,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   457
    int32_t             numImageVisuals,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   458
    XVisualInfo         **pImageVisuals,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   459
    list_ptr            vis_regions,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   460
    list_ptr            vis_image_regions ,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   461
    int32_t             format,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   462
    int32_t             allImage
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   463
)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    image_region_type   *reg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    XRectangle          bbox;           /* bounding box of grabbed area */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    int32_t             depth ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    XImage              *ximage, *ximage_ipm ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    Visual              fakeVis ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    int32_t     x1, y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    XImage      *image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    unsigned char       *pmData ,  *ipmData ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    int32_t                 transparentColor, transparentType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    int32_t                     srcRect_x,srcRect_y,srcRect_width,srcRect_height ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    int32_t                     diff ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    int32_t                     dst_x, dst_y;   /* where in pixmap to write (UL) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    int32_t                     pixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    bbox.x = (short) x;                 /* init X rect for bounding box */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    bbox.y = (short) y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    bbox.width = (unsigned short) width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    bbox.height = (unsigned short) height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    ximage_ipm = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    initFakeVisual(&fakeVis) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    depth = 24 ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    ximage = ReadRegionsInList(disp,&fakeVis,depth,format,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
             (int32_t) width, (int32_t) height, bbox,vis_regions) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    pmData = (unsigned char *)ximage -> data ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
/* if transparency possible do it again, but this time for image planes only */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    if (vis_image_regions && (vis_image_regions->next) && !allImage)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            ximage_ipm = ReadRegionsInList(disp,&fakeVis,depth,format,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                         (int32_t) width, (int32_t) height,bbox,vis_image_regions) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        ipmData = (unsigned char *)ximage_ipm -> data ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
/* Now tranverse the overlay visual windows and test for transparency index.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
/* If you find one, subsitute the value from the matching image plane pixmap. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    for (reg = (image_region_type *) first_in_list( vis_regions); reg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
         reg = (image_region_type *) next_in_list( vis_regions))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        if (src_in_overlay( reg, numOverlayVisuals, pOverlayVisuals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                                 &transparentColor, &transparentType))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
         int32_t test = 0 ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
             srcRect_width  = MIN( reg->width + reg->x_vis, bbox.width + bbox.x)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                                 - MAX( reg->x_vis, bbox.x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
             srcRect_height = MIN( reg->height + reg->y_vis, bbox.height
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                                 + bbox.y) - MAX( reg->y_vis, bbox.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
         diff = bbox.x - reg->x_vis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
         srcRect_x = MAX( 0, diff) + (reg->x_vis - reg->x_rootrel - reg->border);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
         dst_x     = MAX( 0, -diff) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
             diff = bbox.y - reg->y_vis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
             srcRect_y = MAX( 0, diff)  + (reg->y_vis - reg->y_rootrel - reg->border);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
             dst_y     = MAX( 0, -diff) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        /* let's test some pixels for transparency */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
         image = XGetImage(disp, reg->win, srcRect_x, srcRect_y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                           (uint32_t) srcRect_width, (uint32_t) srcRect_height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                           0xffffffff, ZPixmap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        /* let's assume byte per pixel for overlay image for now */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
             if ((image->depth == 8) && (transparentType == TransparentPixel))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
             {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                 unsigned char *pixel_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                 unsigned char *start_of_line = (unsigned char *) image->data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                 for (y1 = 0; y1 < srcRect_height; y1++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                    pixel_ptr = start_of_line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                    for (x1 = 0; x1 < srcRect_width; x1++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                        if (*pixel_ptr++ == transparentColor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                            *pmData++ = *ipmData++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                            *pmData++ = *ipmData++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                            *pmData++ = *ipmData++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                        pixel = (int32_t) XGetPixel(ximage_ipm,dst_x+x1,dst_y+y1) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                    XPutPixel(ximage,dst_x+x1, dst_y+y1,(unsigned long)pixel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                        if(!test){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                           test = 1 ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                            pmData +=3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                            ipmData +=3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                    start_of_line += image->bytes_per_line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                if (transparentType == TransparentPixel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                for (y1 = 0; y1 < srcRect_height; y1++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                      for (x1 = 0; x1 < srcRect_width; x1++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                            int32_t pixel_value = (int32_t) XGetPixel(image, x1, y1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                            if (pixel_value == transparentColor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                                *pmData++ = *ipmData++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                                *pmData++ = *ipmData++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                                *pmData++ = *ipmData++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                            */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                        pixel = (int32_t) XGetPixel(ximage_ipm,dst_x+x1,dst_y+y1) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                    XPutPixel(ximage,dst_x+x1, dst_y+y1,(unsigned long)pixel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                        if(!test){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                           test = 1 ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                                pmData +=3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                                ipmData +=3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                            */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                    for (y1 = 0; y1 < srcRect_height; y1++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                        for (x1 = 0; x1 < srcRect_width; x1++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                            int32_t pixel_value = (int32_t) XGetPixel(image, x1, y1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                            if (pixel_value & transparentColor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                                *pmData++ = *ipmData++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                                *pmData++ = *ipmData++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                                *pmData++ = *ipmData++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                            */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                     pixel = (int32_t) XGetPixel(ximage_ipm,dst_x+x1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                                    dst_y+y1) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                     XPutPixel(ximage,dst_x+x1, dst_y+y1,(unsigned long)pixel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                        if(!test){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                           test = 1 ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                                pmData +=3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                                ipmData +=3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                            */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        XDestroyImage (image);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
      } /* end of src_in_overlay */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    } /** end transparency **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    if (ximage_ipm != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        XDestroyImage(ximage_ipm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    destroy_region_list( vis_regions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    if (vis_image_regions) destroy_region_list( vis_image_regions );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    FreeXVisualInfo(pVisuals, pOverlayVisuals, pImageVisuals);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
    XSync(disp, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    return ximage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
/** ------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        Creates a list of the subwindows of a given window which have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        different visual than their parents.  The function is recursive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        This list is used in make_region_list(), which coalesces the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        windows with the same visual into a region.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        image_wins must point to an existing list struct that's already
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        been zeroed (zero_list()).
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   637
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   638
        bbox: bnding box of area we want
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   639
        x_rootrel, y_rootrel: pos of curr WRT root
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   640
        pclip: visible part of curr, not obscurred by ancestors
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    ------------------------------------------------------------------------ **/
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   642
static void make_src_list(
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   643
    Display             *disp,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   644
    list_ptr            image_wins,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   645
    XRectangle          *bbox,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   646
    Window              curr,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   647
    int32_t             x_rootrel,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   648
    int32_t             y_rootrel,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   649
    XWindowAttributes   *curr_attrs,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   650
    XRectangle          *pclip
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   651
)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    XWindowAttributes child_attrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    Window root, parent, *child;        /* variables for XQueryTree() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    Window *save_child_list;            /* variables for XQueryTree() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    uint32_t nchild;            /* variables for XQueryTree() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    XRectangle child_clip;              /* vis part of child */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    int32_t curr_clipX, curr_clipY, curr_clipRt, curr_clipBt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    /* check that win is mapped & not outside bounding box */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    if (curr_attrs->map_state == IsViewable &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        curr_attrs->class == InputOutput &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        !( pclip->x >= (bbox->x + bbox->width)  ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
           pclip->y >= (bbox->y + bbox->height) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
           (pclip->x + pclip->width)  <= bbox->x        ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
           (pclip->y + pclip->height) <= bbox->y)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        XQueryTree( disp, curr, &root, &parent, &child, &nchild );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        save_child_list = child;      /* so we can free list when we're done */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        add_window_to_list( image_wins, curr, x_rootrel, y_rootrel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                            (int32_t) pclip->x, (int32_t) pclip->y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                            (int32_t) pclip->width, (int32_t) pclip->height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                            curr_attrs->border_width,curr_attrs->visual,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                            curr_attrs->colormap, parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
/** ------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        set RR coords of right (Rt), left (X), bottom (Bt) and top (Y)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        of rect we clip all children by.  This is our own clip rect (pclip)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        inflicted on us by our parent plus our own borders.  Within the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        child loop, we figure the clip rect for each child by adding in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        it's rectangle (not taking into account the child's borders).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    ------------------------------------------------------------------------ **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        curr_clipX = MAX( pclip->x, x_rootrel + curr_attrs->border_width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        curr_clipY = MAX( pclip->y, y_rootrel + curr_attrs->border_width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        curr_clipRt = MIN(pclip->x + pclip->width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                                  x_rootrel + curr_attrs->width + 2 * curr_attrs->border_width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        curr_clipBt = MIN(pclip->y + pclip->height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                                  y_rootrel + curr_attrs->height + 2 * curr_attrs->border_width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        while (nchild--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            int32_t new_width, new_height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            int32_t child_xrr, child_yrr;       /* root relative x & y of child */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            XGetWindowAttributes( disp, *child, &child_attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            /* intersect parent & child clip rects */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            child_xrr = x_rootrel + child_attrs.x + curr_attrs->border_width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            child_clip.x = (short) MAX( curr_clipX, child_xrr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            new_width = MIN(curr_clipRt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                        child_xrr + child_attrs.width +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                         2 * child_attrs.border_width) - child_clip.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            if (new_width >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                child_clip.width = (unsigned short) new_width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                child_yrr = y_rootrel + child_attrs.y +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                            curr_attrs->border_width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                child_clip.y = (short) MAX( curr_clipY, child_yrr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                new_height = MIN(curr_clipBt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                                         child_yrr + (int32_t) child_attrs.height +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                                         2 * child_attrs.border_width) - child_clip.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                if (new_height >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                    child_clip.height = (unsigned short) new_height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                    make_src_list( disp, image_wins, bbox, *child,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                                   child_xrr, child_yrr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                                   &child_attrs, &child_clip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            child++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        XFree( save_child_list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
/** ------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        This function creates a list of regions which tile a specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        window.  Each region contains all visible portions of the window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        which are drawn with the same visual.  For example, if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        window consists of subwindows of two different visual types,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        there will be two regions in the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        Returns a pointer to the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    ------------------------------------------------------------------------ **/
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   738
static list_ptr make_region_list(
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   739
    Display             *disp,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   740
    Window              win,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   741
    XRectangle          *bbox,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   742
    int32_t             *hasNonDefault,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   743
    int32_t             numImageVisuals,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   744
    XVisualInfo         **pImageVisuals,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   745
    int32_t             *allImage
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   746
)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    XWindowAttributes   win_attrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    list                image_wins;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    list_ptr            image_regions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    list_ptr            srcs_left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    image_region_type   *new_reg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    image_win_type      *base_src, *src;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    Region              bbox_region = XCreateRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    XRectangle          clip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    int32_t                     image_only;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
    int32_t                 count=0 ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    *hasNonDefault = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    XUnionRectWithRegion( bbox, bbox_region, bbox_region);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
    XGetWindowAttributes( disp, win, &win_attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    zero_list( &image_wins);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    clip.x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    clip.y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    clip.width  = (unsigned short) win_attrs.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    clip.height = (unsigned short) win_attrs.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
    make_src_list( disp, &image_wins, bbox, win,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                   0 /* x_rootrel */, 0 /* y_rootrel */, &win_attrs, &clip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    image_regions = new_list();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    image_only = (*allImage) ? True:False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    for (base_src = (image_win_type *) first_in_list( &image_wins); base_src;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
         base_src = (image_win_type *) next_in_list( &image_wins))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        /* test for image visual */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        if (!image_only || src_in_image(base_src, numImageVisuals, pImageVisuals))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            /* find a window whose visual hasn't been put in list yet */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
            if (!src_in_region_list( base_src, image_regions))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                if (! (new_reg = (image_region_type *)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                                        malloc( sizeof( image_region_type)))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                    return (list_ptr) NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                new_reg->visible_region = XCreateRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                new_reg->win            = base_src->win;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                new_reg->vis            = base_src->vis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                new_reg->cmap           = base_src->cmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                new_reg->x_rootrel      = base_src->x_rootrel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                new_reg->y_rootrel      = base_src->y_rootrel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                new_reg->x_vis          = base_src->x_vis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                new_reg->y_vis          = base_src->y_vis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                new_reg->width          = base_src->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                new_reg->height         = base_src->height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                new_reg->border         = base_src->border_width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                srcs_left = (list_ptr) dup_list_head( &image_wins, START_AT_CURR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                for (src = (image_win_type *) first_in_list( srcs_left); src;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                     src = (image_win_type *) next_in_list( srcs_left)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                    if (SAME_REGIONS( base_src, src)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                        add_rect_to_image_region( new_reg, src->x_vis, src->y_vis,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                                                  src->width, src->height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                        if (!image_only || src_in_image(src, numImageVisuals, pImageVisuals))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                            subtr_rect_from_image_region( new_reg, src->x_vis,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                                          src->y_vis, src->width, src->height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                XIntersectRegion( bbox_region, new_reg->visible_region,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                                  new_reg->visible_region);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                if (! XEmptyRegion( new_reg->visible_region)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                    add_to_list( image_regions, new_reg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                    if (new_reg->vis != DefaultVisualOfScreen( win_attrs.screen) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                        new_reg->cmap != DefaultColormapOfScreen(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
                                                            win_attrs.screen)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                        *hasNonDefault = True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                    XDestroyRegion( new_reg->visible_region);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
                    free( (void *) new_reg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        } else *allImage = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    delete_list( &image_wins, True);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    XDestroyRegion( bbox_region);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    return image_regions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
/** ------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        Destructor called from destroy_region_list().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    ------------------------------------------------------------------------ **/
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   841
void destroy_image_region(image_region_type *image_region)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    XDestroyRegion( image_region->visible_region);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
    free( (void *) image_region);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
/** ------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        Destroys the region list, destroying all the regions contained in it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    ------------------------------------------------------------------------ **/
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   850
static void destroy_region_list(list_ptr rlist)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
    delete_list_destroying( rlist, (DESTRUCT_FUNC_PTR)destroy_image_region);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
/** ------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        Subtracts the specified rectangle from the region in image_region.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        First converts the rectangle to a region of its own, since X
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        only provides a way to subtract one region from another, not a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        rectangle from a region.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
    ------------------------------------------------------------------------ **/
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   862
static void subtr_rect_from_image_region(
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   863
    image_region_type *image_region,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   864
    int32_t x,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   865
    int32_t y,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   866
    int32_t width,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   867
    int32_t height
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   868
)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
    XRectangle rect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    Region rect_region;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
    rect_region = XCreateRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
    rect.x = (short)x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
    rect.y = (short)y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
    rect.width = (unsigned short)width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
    rect.height = (unsigned short)height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
    XUnionRectWithRegion( &rect, rect_region, rect_region);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
    XSubtractRegion( image_region->visible_region, rect_region,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
                     image_region->visible_region);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
    XDestroyRegion( rect_region);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
/** ------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        Adds the specified rectangle to the region in image_region.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
    ------------------------------------------------------------------------ **/
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   888
static void add_rect_to_image_region(
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   889
    image_region_type *image_region,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   890
    int32_t x,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   891
    int32_t y,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   892
    int32_t width,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   893
    int32_t height
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   894
)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
    XRectangle rect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
    rect.x = (short) x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
    rect.y = (short) y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
    rect.width = (unsigned short) width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    rect.height = (unsigned short) height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
    XUnionRectWithRegion( &rect, image_region->visible_region,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
                          image_region->visible_region);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
/** ------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        Returns TRUE if the given src's visual is already represented in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        the image_regions list, FALSE otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    ------------------------------------------------------------------------ **/
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   911
static int32_t src_in_region_list(image_win_type *src, list_ptr image_regions)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
    image_region_type   *ir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
    for (ir = (image_region_type *) first_in_list( image_regions); ir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
         ir = (image_region_type *) next_in_list( image_regions)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        if (SAME_REGIONS( ir, src)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
/** ------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        Makes a new entry in image_wins with the given fields filled in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    ------------------------------------------------------------------------ **/
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   930
static void add_window_to_list(
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   931
    list_ptr    image_wins,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   932
    Window      w,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   933
    int32_t     xrr,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   934
    int32_t     yrr,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   935
    int32_t     x_vis,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   936
    int32_t     y_vis,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   937
    int32_t     width,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   938
    int32_t     height,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   939
    int32_t     border_width,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   940
    Visual      *vis,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   941
    Colormap    cmap,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   942
    Window      parent
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   943
)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
    image_win_type      *new_src;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
    if ((new_src = (image_win_type *) malloc( sizeof( image_win_type))) == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
    new_src->win = w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
    new_src->x_rootrel = xrr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
    new_src->y_rootrel = yrr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
    new_src->x_vis = x_vis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
    new_src->y_vis = y_vis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
    new_src->width = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
    new_src->height = height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
    new_src->border_width = border_width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
    new_src->vis = vis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
    new_src->cmap = cmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
    new_src->parent = parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
    add_to_list( image_wins, new_src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
/** ------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        Returns TRUE if the given src's visual is in the image planes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        FALSE otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
    ------------------------------------------------------------------------ **/
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   969
static int32_t src_in_image(
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   970
    image_win_type      *src,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   971
    int32_t             numImageVisuals,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   972
    XVisualInfo         **pImageVisuals
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   973
)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
    int32_t             i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
    for (i = 0 ; i < numImageVisuals ; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        if (pImageVisuals[i]->visual == src->vis)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
/** ------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        Returns TRUE if the given src's visual is in the overlay planes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        and transparency is possible, FALSE otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    ------------------------------------------------------------------------ **/
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   990
static int32_t src_in_overlay(
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   991
    image_region_type   *src,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   992
    int32_t             numOverlayVisuals,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   993
    OverlayInfo         *pOverlayVisuals,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   994
    int32_t             *transparentColor,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   995
    int32_t             *transparentType
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
   996
)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
    int32_t             i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
    for (i = 0 ; i < numOverlayVisuals ; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
        if (((pOverlayVisuals[i].pOverlayVisualInfo)->visual == src->vis)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                && (pOverlayVisuals[i].transparentType != None))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
            *transparentColor = pOverlayVisuals[i].value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
            *transparentType = pOverlayVisuals[i].transparentType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
/********************** from wsutils.c ******************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
/******************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
 * This file contains a set of example utility procedures; procedures that can
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
 * help a "window-smart" Starbase or PHIGS program determine information about
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
 * a device, and create image and overlay plane windows.  To use these
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
 * utilities, #include "wsutils.h" and compile this file and link the results
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
 * with your program.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
 ******************************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
#define STATIC_GRAY     0x01
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
#define GRAY_SCALE      0x02
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
#define PSEUDO_COLOR    0x04
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
#define TRUE_COLOR      0x10
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
#define DIRECT_COLOR    0x11
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
static int32_t  weCreateServerOverlayVisualsProperty = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
/******************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
 * GetXVisualInfo()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
 * This routine takes an X11 Display, screen number, and returns whether the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
 * screen supports transparent overlays and three arrays:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
 *      1) All of the XVisualInfo struct's for the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
 *      2) All of the OverlayInfo struct's for the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
 *      3) An array of pointers to the screen's image plane XVisualInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
 *         structs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
 * The code below obtains the array of all the screen's visuals, and obtains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
 * the array of all the screen's overlay visual information.  It then processes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
 * the array of the screen's visuals, determining whether the visual is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
 * overlay or image visual.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
 * If the routine sucessfully obtained the visual information, it returns zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
 * If the routine didn't obtain the visual information, it returns non-zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
 *
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
  1062
 *  display:             Which X server (aka "display").
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
  1063
 *  screen:              Which screen of the "display".
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
  1064
 *  transparentOverlays: Non-zero if there's at least one overlay visual and if
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
  1065
 *      at least one of those supports a transparent pixel.
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
  1066
 *  numVisuals:          Number of XVisualInfo struct's pointed to by pVisuals.
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
  1067
 *  pVisuals:            All of the device's visuals.
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
  1068
 *  numOverlayVisuals:   Number of OverlayInfo's pointed to by pOverlayVisuals.
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
  1069
 *      If this number is zero, the device does not have overlay planes.
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
  1070
 *  pOverlayVisuals:     The device's overlay plane visual information.
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
  1071
 *  numImageVisuals:     Number of XVisualInfo's pointed to by pImageVisuals.
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
  1072
 *  pImageVisuals:       The device's image visuals.
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
  1073
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
 ******************************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
  1076
int32_t GetXVisualInfo(
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
  1077
    Display     *display,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
  1078
    int32_t     screen,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
  1079
    int32_t     *transparentOverlays,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
  1080
    int32_t     *numVisuals,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
  1081
    XVisualInfo **pVisuals,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
  1082
    int32_t     *numOverlayVisuals,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
  1083
    OverlayInfo **pOverlayVisuals,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
  1084
    int32_t     *numImageVisuals,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
  1085
    XVisualInfo ***pImageVisuals
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
  1086
)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
{
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 5506
diff changeset
  1088
    XVisualInfo getVisInfo;             /* Parameters of XGetVisualInfo */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
    int32_t             mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
    XVisualInfo *pVis, **pIVis;         /* Faster, local copies */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
    OverlayInfo *pOVis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
    OverlayVisualPropertyRec    *pOOldVis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
    int32_t             nVisuals, nOVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
    Atom        overlayVisualsAtom;     /* Parameters for XGetWindowProperty */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
    Atom        actualType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
    unsigned long numLongs, bytesAfter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
    int32_t             actualFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
    int32_t             nImageVisualsAlloced;   /* Values to process the XVisualInfo */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
    int32_t             imageVisual;            /* array */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
    /* First, get the list of visuals for this screen. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
    getVisInfo.screen = screen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
    mask = VisualScreenMask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
    *pVisuals = XGetVisualInfo(display, mask, &getVisInfo, numVisuals);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
    if ((nVisuals = *numVisuals) <= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
        /* Return that the information wasn't sucessfully obtained: */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
        return(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
    pVis = *pVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
    /* Now, get the overlay visual information for this screen.  To obtain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
     * this information, get the SERVER_OVERLAY_VISUALS property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
    overlayVisualsAtom = XInternAtom(display, "SERVER_OVERLAY_VISUALS", True);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
    if (overlayVisualsAtom != None)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        /* Since the Atom exists, we can request the property's contents.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
         * do-while loop makes sure we get the entire list from the X server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        bytesAfter = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        numLongs = sizeof(OverlayVisualPropertyRec) / 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        do
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
            numLongs += bytesAfter * 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
            XGetWindowProperty(display, RootWindow(display, screen),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
                               overlayVisualsAtom, 0, numLongs, False,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
                               overlayVisualsAtom, &actualType, &actualFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
                               &numLongs, &bytesAfter, (unsigned char**) pOverlayVisuals);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        } while (bytesAfter > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        /* Calculate the number of overlay visuals in the list. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        /* *numOverlayVisuals = numLongs / (sizeof(OverlayVisualPropertyRec) / 4); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
        *numOverlayVisuals = numLongs / (sizeof(OverlayVisualPropertyRec) / sizeof(long));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
        /* This screen doesn't have overlay planes. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
        *numOverlayVisuals = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        *pOverlayVisuals = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        *transparentOverlays = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
    /* Process the pVisuals array. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
    *numImageVisuals = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
    nImageVisualsAlloced = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
    pIVis = *pImageVisuals = (XVisualInfo **) malloc(sizeof(XVisualInfo *));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
    while (--nVisuals >= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        nOVisuals = *numOverlayVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
        pOVis = *pOverlayVisuals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
        imageVisual = True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
        while (--nOVisuals >= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
            pOOldVis = (OverlayVisualPropertyRec *) pOVis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
            if (pVis->visualid == pOOldVis->visualID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
                imageVisual = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
                pOVis->pOverlayVisualInfo = pVis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
                if (pOVis->transparentType == TransparentPixel)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
                    *transparentOverlays = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
            pOVis++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
        if (imageVisual)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
            if ((*numImageVisuals += 1) > nImageVisualsAlloced)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
                nImageVisualsAlloced++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
                *pImageVisuals = (XVisualInfo **)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
                    realloc(*pImageVisuals, (nImageVisualsAlloced * sizeof(XVisualInfo *)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
                pIVis = *pImageVisuals + (*numImageVisuals - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
            *pIVis++ = pVis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
        pVis++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
    /* Return that the information was sucessfully obtained: */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
    return(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
} /* GetXVisualInfo() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
/******************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
 * FreeXVisualInfo()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
 * This routine frees the data that was allocated by GetXVisualInfo().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
 ******************************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
56230
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
  1199
void FreeXVisualInfo(
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
  1200
    XVisualInfo *pVisuals,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
  1201
    OverlayInfo *pOverlayVisuals,
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
  1202
    XVisualInfo **pImageVisuals
489867818774 No longer disable E_OLD_STYLE_FUNC_DEF.
ihse
parents: 49083
diff changeset
  1203
)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
    XFree(pVisuals);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
    if (weCreateServerOverlayVisualsProperty)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        free(pOverlayVisuals);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
        XFree(pOverlayVisuals);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
    free(pImageVisuals);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
} /* FreeXVisualInfo() */