2 * Copyright © 2011 Intel Corporation
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:
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
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.
27 #include "glxclient.h"
29 #include <X11/Xlib-xcb.h>
32 __glX_send_client_info(struct glx_display
*glx_dpy
)
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
;
39 Bool any_screen_has_ARB_create_context
= False
;
40 Bool any_screen_has_ARB_create_context_profile
= False
;
42 #ifdef HAVE_XCB_GLX_CREATE_CONTEXT
43 static const uint32_t gl_versions
[] = {
46 static const uint32_t gl_versions_profiles
[] = {
49 static const char glx_extensions
[] =
50 "GLX_ARB_create_context GLX_ARB_create_context_profile";
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
58 * Server supports Client sends
59 * ----------------------------------------------------------------------
60 * GLX version = 1.0 Nothing.
62 * GLX version >= 1.1 struct GLXClientInfo
64 * GLX version >= 1.4 and
65 * GLX_ARB_create_context struct glXSetClientInfoARB
67 * GLX version >= 1.4 and
68 * GLX_ARB_create_context_profile struct glXSetClientInfo2ARB
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.
76 * This library currently only supports struct GLXClientInfo.
79 if (glx_dpy
->majorVersion
== 1 && glx_dpy
->minorVersion
== 0)
82 /* Determine whether any screen on the server supports either of the
83 * create-context extensions.
85 for (i
= 0; i
< ScreenCount(glx_dpy
->dpy
); i
++) {
86 struct glx_screen
*src
= glx_dpy
->screens
[i
];
88 const char *haystack
= src
->serverGLXexts
;
89 while (haystack
!= NULL
) {
90 char *match
= strstr(haystack
, "GLX_ARB_create_context");
100 any_screen_has_ARB_create_context
= True
;
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
;
117 gl_extension_string
= __glXGetClientGLExtensionString();
118 gl_extension_length
= strlen(gl_extension_string
) + 1;
120 c
= XGetXCBConnection(glx_dpy
->dpy
);
122 /* Depending on the GLX verion and the available extensions on the server,
123 * send the correct "flavor" of protocol to the server.
125 * THE ORDER IS IMPORTANT. We want to send the most recent version of the
126 * protocol that the server can support.
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])),
136 strlen(glx_extensions
) + 1,
137 gl_versions_profiles
,
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
,
145 / (2 * sizeof(gl_versions
[0])),
147 strlen(glx_extensions
) + 1,
154 xcb_glx_client_info(c
,
155 GLX_MAJOR_VERSION
, GLX_MINOR_VERSION
,
157 gl_extension_string
);
160 Xfree(gl_extension_string
);