2 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice including the dates of first publication and
13 * either this permission notice or a reference to
14 * http://oss.sgi.com/projects/FreeB/
15 * shall be included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * Except as contained in this notice, the name of Silicon Graphics, Inc.
26 * shall not be used in advertising or otherwise to promote the sale, use or
27 * other dealings in this Software without prior written authorization from
28 * Silicon Graphics, Inc.
31 #ifdef HAVE_DMX_CONFIG_H
32 #include <dmx-config.h>
38 #include "glxserver.h"
40 #include <windowstr.h>
42 #include "glxfbconfig.h"
45 #include "panoramiXsrv.h"
48 __GLXscreenInfo
*__glXActiveScreens
;
49 GLint __glXNumActiveScreens
;
51 __GLXFBConfig
**__glXFBConfigs
;
52 int __glXNumFBConfigs
;
54 static char GLXServerVendorName
[] = "SGI DMX/glxProxy";
55 static char GLXServerVersion
[64];
56 static char GLXServerExtensions
[] =
57 "GLX_EXT_visual_info "
58 "GLX_EXT_visual_rating "
59 "GLX_EXT_import_context "
60 "GLX_SGIX_fbconfig " "GLX_SGI_make_current_read " "GLX_SGI_swap_control ";
62 static char ExtensionsString
[1024];
65 CalcServerVersionAndExtensions(void)
68 xGLXQueryVersionReq
*req
;
69 xGLXQueryVersionReply reply
;
72 char *denied_extensions
;
75 * set the server glx version to be the minimum version
76 * supported by all back-end servers
78 __glXVersionMajor
= 0;
79 __glXVersionMinor
= 0;
80 for (s
= 0; s
< __glXNumActiveScreens
; s
++) {
81 DMXScreenInfo
*dmxScreen
= &dmxScreens
[s
];
82 Display
*dpy
= dmxScreen
->beDisplay
;
84 /* Send the glXQueryVersion request */
86 GetReq(GLXQueryVersion
, req
);
87 req
->reqType
= dmxScreen
->glxMajorOpcode
;
88 req
->glxCode
= X_GLXQueryVersion
;
89 req
->majorVersion
= GLX_SERVER_MAJOR_VERSION
;
90 req
->minorVersion
= GLX_SERVER_MINOR_VERSION
;
91 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
96 __glXVersionMajor
= reply
.majorVersion
;
97 __glXVersionMinor
= reply
.minorVersion
;
100 if (reply
.majorVersion
< __glXVersionMajor
) {
101 __glXVersionMajor
= reply
.majorVersion
;
102 __glXVersionMinor
= reply
.minorVersion
;
104 else if ((reply
.majorVersion
== __glXVersionMajor
) &&
105 (reply
.minorVersion
< __glXVersionMinor
)) {
106 __glXVersionMinor
= reply
.minorVersion
;
112 if (GLX_SERVER_MAJOR_VERSION
< __glXVersionMajor
) {
113 __glXVersionMajor
= GLX_SERVER_MAJOR_VERSION
;
114 __glXVersionMinor
= GLX_SERVER_MINOR_VERSION
;
116 else if ((GLX_SERVER_MAJOR_VERSION
== __glXVersionMajor
) &&
117 (GLX_SERVER_MINOR_VERSION
< __glXVersionMinor
)) {
118 __glXVersionMinor
= GLX_SERVER_MINOR_VERSION
;
121 snprintf(GLXServerVersion
, sizeof(GLXServerVersion
),
122 "%d.%d DMX %d back-end server(s)",
123 __glXVersionMajor
, __glXVersionMinor
, __glXNumActiveScreens
);
125 * set the ExtensionsString to the minimum extensions string
127 ExtensionsString
[0] = '\0';
130 * read extensions strings of all back-end servers
132 be_extensions
= (char **) malloc(__glXNumActiveScreens
* sizeof(char *));
136 for (s
= 0; s
< __glXNumActiveScreens
; s
++) {
137 DMXScreenInfo
*dmxScreen
= &dmxScreens
[s
];
138 Display
*dpy
= dmxScreen
->beDisplay
;
139 xGLXQueryServerStringReq
*req
;
140 xGLXQueryServerStringReply reply
;
141 int length
, numbytes
;
143 /* Send the glXQueryServerString request */
145 GetReq(GLXQueryServerString
, req
);
146 req
->reqType
= dmxScreen
->glxMajorOpcode
;
147 req
->glxCode
= X_GLXQueryServerString
;
148 req
->screen
= DefaultScreen(dpy
);
149 req
->name
= GLX_EXTENSIONS
;
150 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
152 length
= (int) reply
.length
;
153 numbytes
= (int) reply
.n
;
154 be_extensions
[s
] = (char *) malloc(numbytes
);
155 if (!be_extensions
[s
]) {
156 /* Throw data on the floor */
157 _XEatDataWords(dpy
, length
);
160 _XReadPad(dpy
, (char *) be_extensions
[s
], numbytes
);
167 * extensions string will include only extensions that our
168 * server supports as well as all back-end servers supports.
169 * extensions that are in the DMX_DENY_EXTENSIONS string will
172 denied_extensions
= getenv("DMX_DENY_GLX_EXTENSIONS");
173 ext
= strtok(GLXServerExtensions
, " ");
177 if (denied_extensions
&& strstr(denied_extensions
, ext
)) {
181 for (s
= 0; s
< __glXNumActiveScreens
&& supported
; s
++) {
182 if (!strstr(be_extensions
[s
], ext
)) {
189 strcat(ExtensionsString
, ext
);
190 strcat(ExtensionsString
, " ");
193 ext
= strtok(NULL
, " ");
197 * release temporary storage
199 for (s
= 0; s
< __glXNumActiveScreens
; s
++) {
200 free(be_extensions
[s
]);
204 if (dmxGLXSwapGroupSupport
) {
205 if (!denied_extensions
||
206 !strstr(denied_extensions
, "GLX_SGIX_swap_group")) {
207 strcat(ExtensionsString
, "GLX_SGIX_swap_group");
208 if (!denied_extensions
||
209 !strstr(denied_extensions
, "GLX_SGIX_swap_barrier")) {
210 strcat(ExtensionsString
, " GLX_SGIX_swap_barrier");
218 __glXScreenInit(GLint numscreens
)
222 DMXScreenInfo
*dmxScreen0
= &dmxScreens
[0];
224 __glXNumActiveScreens
= numscreens
;
226 CalcServerVersionAndExtensions();
228 __glXFBConfigs
= NULL
;
229 __glXNumFBConfigs
= 0;
231 if ((__glXVersionMajor
== 1 && __glXVersionMinor
>= 3) ||
232 (__glXVersionMajor
> 1) ||
233 (strstr(ExtensionsString
, "GLX_SGIX_fbconfig"))) {
236 // Initialize FBConfig info.
237 // find the set of FBConfigs that are present on all back-end
238 // servers - only those configs will be supported
240 __glXFBConfigs
= (__GLXFBConfig
**) malloc(dmxScreen0
->numFBConfigs
*
243 sizeof(__GLXFBConfig
*));
244 __glXNumFBConfigs
= 0;
246 for (c
= 0; c
< dmxScreen0
->numFBConfigs
; c
++) {
247 __GLXFBConfig
*cfg
= NULL
;
249 if (numscreens
> 1) {
250 for (s
= 1; s
< numscreens
; s
++) {
251 DMXScreenInfo
*dmxScreen
= &dmxScreens
[s
];
253 cfg
= FindMatchingFBConfig(&dmxScreen0
->fbconfigs
[c
],
254 dmxScreen
->fbconfigs
,
255 dmxScreen
->numFBConfigs
);
256 __glXFBConfigs
[__glXNumFBConfigs
* (numscreens
+ 1) + s
+
260 "screen0 FBConfig 0x%x is missing on screen#%d\n",
261 dmxScreen0
->fbconfigs
[c
].id
, s
);
266 "screen0 FBConfig 0x%x matched to 0x%x on screen#%d\n",
267 dmxScreen0
->fbconfigs
[c
].id
, cfg
->id
, s
);
272 cfg
= &dmxScreen0
->fbconfigs
[c
];
277 /* filter out overlay visuals */
278 if (cfg
->level
== 0) {
279 __GLXFBConfig
*proxy_cfg
;
281 __glXFBConfigs
[__glXNumFBConfigs
* (numscreens
+ 1) + 1] =
282 &dmxScreen0
->fbconfigs
[c
];
284 proxy_cfg
= malloc(sizeof(__GLXFBConfig
));
285 memcpy(proxy_cfg
, cfg
, sizeof(__GLXFBConfig
));
286 proxy_cfg
->id
= FakeClientID(0);
287 /* visual will be associated later in __glXGetFBConfigs */
288 proxy_cfg
->associatedVisualId
= (unsigned int) -1;
290 __glXFBConfigs
[__glXNumFBConfigs
* (numscreens
+ 1) + 0] =
305 __glXScreenReset(void)
307 __glXNumActiveScreens
= 0;
311 __glXGetServerString(unsigned int name
)
318 ret
= GLXServerVendorName
;
322 ret
= GLXServerVersion
;
326 ret
= ExtensionsString
;
338 glxIsExtensionSupported(char *ext
)
340 return (strstr(ExtensionsString
, ext
) != NULL
);