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