glx: fix compile warnings
[mesa.git] / src / glx / clientinfo.c
1 /*
2 * Copyright © 2011 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 #include <string.h>
25 #include <ctype.h>
26
27 #include "glxclient.h"
28 #include <xcb/glx.h>
29 #include <X11/Xlib-xcb.h>
30
31 _X_HIDDEN void
32 __glX_send_client_info(struct glx_display *glx_dpy)
33 {
34 const unsigned ext_length = strlen("GLX_ARB_create_context");
35 const unsigned prof_length = strlen("_profile");
36 char *gl_extension_string;
37 int gl_extension_length;
38 xcb_connection_t *c;
39 Bool any_screen_has_ARB_create_context = False;
40 Bool any_screen_has_ARB_create_context_profile = False;
41 unsigned i;
42 #ifdef HAVE_XCB_GLX_CREATE_CONTEXT
43 static const uint32_t gl_versions[] = {
44 1, 4,
45 };
46 static const uint32_t gl_versions_profiles[] = {
47 1, 4, 0x00000000,
48 };
49 static const char glx_extensions[] =
50 "GLX_ARB_create_context GLX_ARB_create_context_profile";
51 #endif
52
53 /* There are three possible flavors of the client info structure that the
54 * client could send to the server. The version sent depends on the
55 * combination of GLX versions and extensions supported by the client and
56 * the server.
57 *
58 * Server supports Client sends
59 * ----------------------------------------------------------------------
60 * GLX version = 1.0 Nothing.
61 *
62 * GLX version >= 1.1 struct GLXClientInfo
63 *
64 * GLX version >= 1.4 and
65 * GLX_ARB_create_context struct glXSetClientInfoARB
66 *
67 * GLX version >= 1.4 and
68 * GLX_ARB_create_context_profile struct glXSetClientInfo2ARB
69 *
70 * GLX_ARB_create_context and GLX_ARB_create_context_profile use FBConfigs,
71 * and these only exist in GLX 1.4 or with GLX_SGIX_fbconfig. I can't
72 * imagine an implementation that supports GLX_SGIX_fbconfig and
73 * GLX_ARB_create_context but not GLX 1.4. Making GLX 1.4 a hard
74 * requirement in this case does not seem like a limitation.
75 *
76 * This library currently only supports struct GLXClientInfo.
77 */
78
79 if (glx_dpy->majorVersion == 1 && glx_dpy->minorVersion == 0)
80 return;
81
82 /* Determine whether any screen on the server supports either of the
83 * create-context extensions.
84 */
85 for (i = 0; i < ScreenCount(glx_dpy->dpy); i++) {
86 struct glx_screen *src = glx_dpy->screens[i];
87
88 const char *haystack = src->serverGLXexts;
89 while (haystack != NULL) {
90 char *match = strstr(haystack, "GLX_ARB_create_context");
91
92 if (match == NULL)
93 break;
94
95 match += ext_length;
96
97 switch (match[0]) {
98 case '\0':
99 case ' ':
100 any_screen_has_ARB_create_context = True;
101 break;
102
103 case '_':
104 if (strncmp(match, "_profile", prof_length) == 0
105 && (match[prof_length] == '\0'
106 || match[prof_length] == ' ')) {
107 any_screen_has_ARB_create_context_profile = True;
108 match += prof_length;
109 }
110 break;
111 }
112
113 haystack = match;
114 }
115 }
116
117 gl_extension_string = __glXGetClientGLExtensionString();
118 gl_extension_length = strlen(gl_extension_string) + 1;
119
120 c = XGetXCBConnection(glx_dpy->dpy);
121
122 /* Depending on the GLX verion and the available extensions on the server,
123 * send the correct "flavor" of protocol to the server.
124 *
125 * THE ORDER IS IMPORTANT. We want to send the most recent version of the
126 * protocol that the server can support.
127 */
128 #ifdef HAVE_XCB_GLX_CREATE_CONTEXT
129 if (glx_dpy->majorVersion == 1 && glx_dpy->minorVersion == 4
130 && any_screen_has_ARB_create_context_profile) {
131 xcb_glx_set_client_info_2arb(c,
132 GLX_MAJOR_VERSION, GLX_MINOR_VERSION,
133 sizeof(gl_versions_profiles)
134 / (3 * sizeof(gl_versions_profiles[0])),
135 gl_extension_length,
136 strlen(glx_extensions) + 1,
137 gl_versions_profiles,
138 gl_extension_string,
139 glx_extensions);
140 } else if (glx_dpy->majorVersion == 1 && glx_dpy->minorVersion == 4
141 && any_screen_has_ARB_create_context) {
142 xcb_glx_set_client_info_arb(c,
143 GLX_MAJOR_VERSION, GLX_MINOR_VERSION,
144 sizeof(gl_versions)
145 / (2 * sizeof(gl_versions[0])),
146 gl_extension_length,
147 strlen(glx_extensions) + 1,
148 gl_versions,
149 gl_extension_string,
150 glx_extensions);
151 } else
152 #endif
153 {
154 xcb_glx_client_info(c,
155 GLX_MAJOR_VERSION, GLX_MINOR_VERSION,
156 gl_extension_length,
157 gl_extension_string);
158 }
159
160 Xfree(gl_extension_string);
161 }