2 /* Copyright (c) Mark J. Kilgard, 1993, 1994. */
4 /* This program is freely distributable without licensing fees
5 and is provided without guarantee or warrantee expressed or
6 implied. This program is -not- in the public domain. */
8 /* Based on XLayerUtil.c: Revision: 1.5 */
12 #include "layerutil.h"
14 /* SGI optimization introduced in IRIX 6.3 to avoid X server
15 round trips for interning common X atoms. */
16 #if defined(_SGI_EXTRA_PREDEFINES) && !defined(NO_FAST_ATOMS)
17 #include <X11/SGIFastAtom.h>
19 #define XSGIFastInternAtom(dpy,string,fast_name,how) XInternAtom(dpy,string,how)
22 static Bool layersRead
= False
;
23 static OverlayInfo
**overlayInfoPerScreen
;
24 static unsigned long *numOverlaysPerScreen
;
27 findServerOverlayVisualsInfo(Display
* dpy
)
29 static Atom overlayVisualsAtom
;
32 unsigned long sizeData
, bytesLeft
;
34 int actualFormat
, numScreens
, i
;
36 if (layersRead
== False
) {
37 overlayVisualsAtom
= XSGIFastInternAtom(dpy
,
38 "SERVER_OVERLAY_VISUALS", SGI_XA_SERVER_OVERLAY_VISUALS
, True
);
39 if (overlayVisualsAtom
!= None
) {
40 numScreens
= ScreenCount(dpy
);
41 overlayInfoPerScreen
= (OverlayInfo
**)
42 malloc(numScreens
* sizeof(OverlayInfo
*));
43 numOverlaysPerScreen
= (unsigned long *)
44 malloc(numScreens
* sizeof(unsigned long));
45 if (overlayInfoPerScreen
!= NULL
&&
46 numOverlaysPerScreen
!= NULL
) {
47 for (i
= 0; i
< numScreens
; i
++) {
48 root
= RootWindow(dpy
, i
);
49 status
= XGetWindowProperty(dpy
, root
,
50 overlayVisualsAtom
, 0L, (long) 10000, False
,
51 overlayVisualsAtom
, &actualType
, &actualFormat
,
52 &sizeData
, &bytesLeft
,
53 (unsigned char **) &overlayInfoPerScreen
[i
]);
54 if (status
!= Success
||
55 actualType
!= overlayVisualsAtom
||
56 actualFormat
!= 32 || sizeData
< 4)
57 numOverlaysPerScreen
[i
] = 0;
59 /* Four 32-bit quantities per
60 SERVER_OVERLAY_VISUALS entry. */
61 numOverlaysPerScreen
[i
] = sizeData
/ 4;
65 if (overlayInfoPerScreen
!= NULL
)
66 free(overlayInfoPerScreen
);
67 if (numOverlaysPerScreen
!= NULL
)
68 free(numOverlaysPerScreen
);
75 __glutGetTransparentPixel(Display
* dpy
, XVisualInfo
* vinfo
)
77 int i
, screen
= vinfo
->screen
;
78 OverlayInfo
*overlayInfo
;
80 findServerOverlayVisualsInfo(dpy
);
82 for (i
= 0; i
< numOverlaysPerScreen
[screen
]; i
++) {
83 overlayInfo
= &overlayInfoPerScreen
[screen
][i
];
84 if (vinfo
->visualid
== overlayInfo
->overlay_visual
) {
85 if (overlayInfo
->transparent_type
== TransparentPixel
) {
86 return (int) overlayInfo
->value
;
97 __glutXGetLayerVisualInfo(Display
* dpy
, long lvinfo_mask
,
98 XLayerVisualInfo
* lvinfo_template
, int *nitems_return
)
101 XLayerVisualInfo
*layerInfo
;
102 int numVisuals
, count
, i
, j
;
104 vinfo
= XGetVisualInfo(dpy
, lvinfo_mask
& VisualAllMask
,
105 &lvinfo_template
->vinfo
, nitems_return
);
108 numVisuals
= *nitems_return
;
109 findServerOverlayVisualsInfo(dpy
);
110 layerInfo
= (XLayerVisualInfo
*)
111 malloc(numVisuals
* sizeof(XLayerVisualInfo
));
112 if (layerInfo
== NULL
) {
117 for (i
= 0; i
< numVisuals
; i
++) {
118 XVisualInfo
*pVinfo
= &vinfo
[i
];
119 int screen
= pVinfo
->screen
;
120 OverlayInfo
*overlayInfo
= NULL
;
124 for (j
= 0; j
< numOverlaysPerScreen
[screen
]; j
++)
125 if (pVinfo
->visualid
==
126 overlayInfoPerScreen
[screen
][j
].overlay_visual
) {
127 overlayInfo
= &overlayInfoPerScreen
[screen
][j
];
131 if (lvinfo_mask
& VisualLayerMask
) {
132 if (overlayInfo
== NULL
) {
133 if (lvinfo_template
->layer
!= 0)
135 } else if (lvinfo_template
->layer
!= overlayInfo
->layer
)
138 if (lvinfo_mask
& VisualTransparentType
) {
139 if (overlayInfo
== NULL
) {
140 if (lvinfo_template
->type
!= None
)
142 } else if (lvinfo_template
->type
!=
143 overlayInfo
->transparent_type
)
146 if (lvinfo_mask
& VisualTransparentValue
) {
147 if (overlayInfo
== NULL
)
148 /* Non-overlay visuals have no sense of
151 else if (lvinfo_template
->value
!= overlayInfo
->value
)
154 layerInfo
[count
].vinfo
= *pVinfo
;
155 if (overlayInfo
== NULL
) {
156 layerInfo
[count
].layer
= 0;
157 layerInfo
[count
].type
= None
;
158 layerInfo
[count
].value
= 0; /* meaningless */
160 layerInfo
[count
].layer
= overlayInfo
->layer
;
161 layerInfo
[count
].type
= overlayInfo
->transparent_type
;
162 layerInfo
[count
].value
= overlayInfo
->value
;
167 *nitems_return
= count
;
175 #if 0 /* Unused by GLUT. */
177 __glutXMatchLayerVisualInfo(Display
* dpy
, int screen
,
178 int depth
, int visualClass
, int layer
,
179 XLayerVisualInfo
* lvinfo_return
)
181 XLayerVisualInfo
*lvinfo
;
182 XLayerVisualInfo lvinfoTemplate
;
185 lvinfoTemplate
.vinfo
.screen
= screen
;
186 lvinfoTemplate
.vinfo
.depth
= depth
;
187 #if defined(__cplusplus) || defined(c_plusplus)
188 lvinfoTemplate
.vinfo
.c_class
= visualClass
;
190 lvinfoTemplate
.vinfo
.class = visualClass
;
192 lvinfoTemplate
.layer
= layer
;
193 lvinfo
= __glutXGetLayerVisualInfo(dpy
,
194 VisualScreenMask
| VisualDepthMask
|
195 VisualClassMask
| VisualLayerMask
,
196 &lvinfoTemplate
, &nitems
);
197 if (lvinfo
!= NULL
&& nitems
> 0) {
198 *lvinfo_return
= *lvinfo
;