First import
[xorg_rtime.git] / xorg-server-1.4 / hw / dmx / glxProxy / glxscreens.c
blob0f9012d39d8dc04bc6572627d47813dcacabdf06
1 /*
2 ** License Applicability. Except to the extent portions of this file are
3 ** made subject to an alternative license as permitted in the SGI Free
4 ** Software License B, Version 1.1 (the "License"), the contents of this
5 ** file are subject only to the provisions of the License. You may not use
6 ** this file except in compliance with the License. You may obtain a copy
7 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
8 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
9 **
10 ** http://oss.sgi.com/projects/FreeB
11 **
12 ** Note that, as provided in the License, the Software is distributed on an
13 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
14 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
15 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
16 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
17 **
18 ** Original Code. The Original Code is: OpenGL Sample Implementation,
19 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
20 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
21 ** Copyright in any portions created by third parties is as indicated
22 ** elsewhere herein. All Rights Reserved.
23 **
24 ** Additional Notice Provisions: The application programming interfaces
25 ** established by SGI in conjunction with the Original Code are The
26 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
27 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
28 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
29 ** Window System(R) (Version 1.3), released October 19, 1998. This software
30 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
31 ** published by SGI, but has not been independently verified as being
32 ** compliant with the OpenGL(R) version 1.2.1 Specification.
36 #ifdef HAVE_DMX_CONFIG_H
37 #include <dmx-config.h>
38 #endif
40 #include "dmx.h"
41 #include "dmxlog.h"
43 #undef Xmalloc
44 #undef Xcalloc
45 #undef Xrealloc
46 #undef Xfree
48 #include "glxserver.h"
50 #include <windowstr.h>
52 #include "glxfbconfig.h"
54 #ifdef PANORAMIX
55 #include "panoramiXsrv.h"
56 #endif
58 __GLXscreenInfo *__glXActiveScreens;
59 GLint __glXNumActiveScreens;
61 __GLXFBConfig **__glXFBConfigs;
62 int __glXNumFBConfigs;
64 static char GLXServerVendorName[] = "SGI DMX/glxProxy";
65 static char GLXServerVersion[64];
66 static char GLXServerExtensions[] =
67 "GLX_EXT_visual_info "
68 "GLX_EXT_visual_rating "
69 "GLX_EXT_import_context "
70 "GLX_SGIX_fbconfig "
71 "GLX_SGI_make_current_read "
72 "GLX_SGI_swap_control "
75 static char ExtensionsString[1024];
77 static void CalcServerVersionAndExtensions( void )
79 int s;
80 xGLXQueryVersionReq *req;
81 xGLXQueryVersionReply reply;
82 char **be_extensions;
83 char *ext;
84 char *denied_extensions;
87 * set the server glx version to be the minimum version
88 * supported by all back-end servers
90 __glXVersionMajor = 0;
91 __glXVersionMinor = 0;
92 for (s=0; s<__glXNumActiveScreens; s++) {
93 DMXScreenInfo *dmxScreen = &dmxScreens[s];
94 Display *dpy = dmxScreen->beDisplay;
96 /* Send the glXQueryVersion request */
97 LockDisplay(dpy);
98 GetReq(GLXQueryVersion,req);
99 req->reqType = dmxScreen->glxMajorOpcode;
100 req->glxCode = X_GLXQueryVersion;
101 req->majorVersion = GLX_SERVER_MAJOR_VERSION;
102 req->minorVersion = GLX_SERVER_MINOR_VERSION;
103 _XReply(dpy, (xReply*) &reply, 0, False);
104 UnlockDisplay(dpy);
105 SyncHandle();
107 if (s == 0) {
108 __glXVersionMajor = reply.majorVersion;
109 __glXVersionMinor = reply.minorVersion;
111 else {
112 if (reply.majorVersion < __glXVersionMajor) {
113 __glXVersionMajor = reply.majorVersion;
114 __glXVersionMinor = reply.minorVersion;
116 else if ( (reply.majorVersion == __glXVersionMajor) &&
117 (reply.minorVersion < __glXVersionMinor) ) {
118 __glXVersionMinor = reply.minorVersion;
124 if (GLX_SERVER_MAJOR_VERSION < __glXVersionMajor) {
125 __glXVersionMajor = GLX_SERVER_MAJOR_VERSION;
126 __glXVersionMinor = GLX_SERVER_MINOR_VERSION;
128 else if ( (GLX_SERVER_MAJOR_VERSION == __glXVersionMajor) &&
129 (GLX_SERVER_MINOR_VERSION < __glXVersionMinor) ) {
130 __glXVersionMinor = GLX_SERVER_MINOR_VERSION;
133 sprintf(GLXServerVersion, "%d.%d DMX %d back-end server(s)",
134 __glXVersionMajor, __glXVersionMinor, __glXNumActiveScreens );
136 * set the ExtensionsString to the minimum extensions string
138 ExtensionsString[0] = '\0';
141 * read extensions strings of all back-end servers
143 be_extensions = (char **)Xalloc( __glXNumActiveScreens * sizeof(char *) );
144 if (!be_extensions)
145 return;
147 for (s=0; s<__glXNumActiveScreens; s++) {
148 DMXScreenInfo *dmxScreen = &dmxScreens[s];
149 Display *dpy = dmxScreen->beDisplay;
150 xGLXQueryServerStringReq *req;
151 xGLXQueryServerStringReply reply;
152 int length, numbytes, slop;
154 /* Send the glXQueryServerString request */
155 LockDisplay(dpy);
156 GetReq(GLXQueryServerString,req);
157 req->reqType = dmxScreen->glxMajorOpcode;
158 req->glxCode = X_GLXQueryServerString;
159 req->screen = DefaultScreen(dpy);
160 req->name = GLX_EXTENSIONS;
161 _XReply(dpy, (xReply*) &reply, 0, False);
163 length = (int)reply.length;
164 numbytes = (int)reply.n;
165 slop = numbytes * __GLX_SIZE_INT8 & 3;
166 be_extensions[s] = (char *)Xalloc(numbytes);
167 if (!be_extensions[s]) {
168 /* Throw data on the floor */
169 _XEatData(dpy, length);
170 } else {
171 _XRead(dpy, (char *)be_extensions[s], numbytes);
172 if (slop) _XEatData(dpy,4-slop);
174 UnlockDisplay(dpy);
175 SyncHandle();
179 * extensions string will include only extensions that our
180 * server supports as well as all back-end servers supports.
181 * extensions that are in the DMX_DENY_EXTENSIONS string will
182 * not be supported.
184 denied_extensions = getenv("DMX_DENY_GLX_EXTENSIONS");
185 ext = strtok(GLXServerExtensions, " ");
186 while( ext ) {
187 int supported = 1;
189 if (denied_extensions && strstr(denied_extensions, ext)) {
190 supported = 0;
192 else {
193 for (s=0; s<__glXNumActiveScreens && supported; s++) {
194 if ( !strstr(be_extensions[s], ext) ) {
195 supported = 0;
200 if (supported) {
201 strcat(ExtensionsString, ext);
202 strcat(ExtensionsString, " ");
205 ext = strtok(NULL, " ");
209 * release temporary storage
211 for (s=0; s<__glXNumActiveScreens; s++) {
212 if (be_extensions[s]) Xfree(be_extensions[s]);
214 Xfree( be_extensions );
216 if (dmxGLXSwapGroupSupport) {
217 if (!denied_extensions ||
218 !strstr(denied_extensions, "GLX_SGIX_swap_group")) {
219 strcat(ExtensionsString, "GLX_SGIX_swap_group");
220 if (!denied_extensions ||
221 !strstr(denied_extensions, "GLX_SGIX_swap_barrier")) {
222 strcat(ExtensionsString, " GLX_SGIX_swap_barrier");
229 void __glXScreenInit(GLint numscreens)
231 int s;
232 int c;
233 DMXScreenInfo *dmxScreen0 = &dmxScreens[0];
234 __glXNumActiveScreens = numscreens;
237 CalcServerVersionAndExtensions();
240 __glXFBConfigs = NULL;
241 __glXNumFBConfigs = 0;
243 if ( (__glXVersionMajor == 1 && __glXVersionMinor >= 3) ||
244 (__glXVersionMajor > 1) ||
245 ( strstr(ExtensionsString, "GLX_SGIX_fbconfig") ) ) {
248 // Initialize FBConfig info.
249 // find the set of FBConfigs that are present on all back-end
250 // servers - only those configs will be supported
252 __glXFBConfigs = (__GLXFBConfig **)Xalloc( dmxScreen0->numFBConfigs *
253 (numscreens+1) * sizeof(__GLXFBConfig *) );
254 __glXNumFBConfigs = 0;
256 for (c=0; c<dmxScreen0->numFBConfigs; c++) {
257 __GLXFBConfig *cfg = NULL;
259 if (numscreens > 1) {
260 for (s=1; s<numscreens; s++) {
261 DMXScreenInfo *dmxScreen = &dmxScreens[s];
262 __GLXscreenInfo *glxScreen = &__glXActiveScreens[s];
264 cfg = FindMatchingFBConfig( &dmxScreen0->fbconfigs[c],
265 dmxScreen->fbconfigs,
266 dmxScreen->numFBConfigs );
267 __glXFBConfigs[ __glXNumFBConfigs * (numscreens+1) + s + 1 ] = cfg;
268 if (!cfg) {
269 dmxLog(dmxInfo,"screen0 FBConfig 0x%x is missing on screen#%d\n", dmxScreen0->fbconfigs[c].id, s);
270 break;
272 else {
273 dmxLog(dmxInfo,"screen0 FBConfig 0x%x matched to 0x%x on screen#%d\n", dmxScreen0->fbconfigs[c].id, cfg->id, s);
277 else {
278 cfg = &dmxScreen0->fbconfigs[c];
281 if (cfg) {
283 /* filter out overlay visuals */
284 if (cfg->level == 0) {
285 __GLXFBConfig *proxy_cfg;
287 __glXFBConfigs[ __glXNumFBConfigs * (numscreens+1) + 1 ] =
288 &dmxScreen0->fbconfigs[c];
290 proxy_cfg = Xalloc( sizeof(__GLXFBConfig) );
291 memcpy( proxy_cfg, cfg, sizeof(__GLXFBConfig) );
292 proxy_cfg->id = FakeClientID(0);
293 /* visual will be associated later in __glXGetFBConfigs */
294 proxy_cfg->associatedVisualId = (unsigned int)-1;
296 __glXFBConfigs[ __glXNumFBConfigs * (numscreens+1) + 0 ] = proxy_cfg;
298 __glXNumFBConfigs++;
309 void __glXScreenReset(void)
311 __glXNumActiveScreens = 0;
314 char *__glXGetServerString( unsigned int name )
316 char *ret = NULL;
318 switch( name) {
320 case GLX_VENDOR:
321 ret = GLXServerVendorName;
322 break;
324 case GLX_VERSION:
325 ret = GLXServerVersion;
326 break;
328 case GLX_EXTENSIONS:
329 ret = ExtensionsString;
330 break;
332 default:
333 break;
336 return( ret );
341 __GLXFBConfig *glxLookupFBConfig( GLXFBConfigID id )
343 int i,j;
345 for (i=0, j=0; i<__glXNumFBConfigs; i++,j+=(__glXNumActiveScreens+1) ) {
346 if ( __glXFBConfigs[j]->id == id)
347 return( __glXFBConfigs[j] );
350 return(NULL);
353 __GLXFBConfig *glxLookupFBConfigByVID( VisualID vid )
355 int i,j;
357 for (i=0, j=0; i<__glXNumFBConfigs; i++,j+=(__glXNumActiveScreens+1) ) {
358 if ( __glXFBConfigs[j]->associatedVisualId == vid)
359 return( __glXFBConfigs[j] );
362 return(NULL);
365 __GLXFBConfig *glxLookupBackEndFBConfig( GLXFBConfigID id, int screen )
367 int i;
368 int j;
370 for (i=0, j=0; i<__glXNumFBConfigs; i++,j+=(__glXNumActiveScreens+1) ) {
371 if ( __glXFBConfigs[j]->id == id)
372 return( __glXFBConfigs[j+screen+1] );
375 return(NULL);
379 int glxIsExtensionSupported( char *ext )
381 return( strstr(ExtensionsString, ext) != NULL );