/*1* Copyright © 2011 Intel Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER20* DEALINGS IN THE SOFTWARE.21*/2223#include <string.h>24#include <ctype.h>2526#include "glxclient.h"27#include <xcb/glx.h>28#include <X11/Xlib-xcb.h>2930_X_HIDDEN void31__glX_send_client_info(struct glx_display *glx_dpy)32{33const unsigned ext_length = strlen("GLX_ARB_create_context");34const unsigned prof_length = strlen("_profile");35char *gl_extension_string;36int gl_extension_length;37xcb_connection_t *c;38Bool any_screen_has_ARB_create_context = False;39Bool any_screen_has_ARB_create_context_profile = False;40unsigned i;41/* You need GLX_ARB_create_context_profile to get beyond 3.1 anyway */42static const uint32_t gl_versions[] = {432, 1,443, 0,453, 1,46};47/*48* This is weird, but it matches what NVIDIA does/expects. For big-GL49* below 3.2 there is no such thing as a "profile", so we name them all50* with no profile bits. Except we don't name anything lower than 2.1,51* since GLX_ARB_create_context_profile says:52*53* "Only the highest supported version below 3.0 should be sent, since54* OpenGL 2.1 is backwards compatible with all earlier versions."55*56* In order to also support GLES below 3.2, we name every possible GLES57* version with the ES2 bit set, which happens to just mean GLES generally58* and not a particular major version. 3.2 happens to be a legal version59* number for both big-GL and GLES, so it gets all three bits set.60* Everything 3.3 and above is big-GL only so gets the core and compat61* bits set.62*/63static const uint32_t gl_versions_profiles[] = {641, 0, GLX_CONTEXT_ES2_PROFILE_BIT_EXT,651, 1, GLX_CONTEXT_ES2_PROFILE_BIT_EXT,662, 0, GLX_CONTEXT_ES2_PROFILE_BIT_EXT,672, 1, 0x0,683, 0, 0x0,693, 0, GLX_CONTEXT_ES2_PROFILE_BIT_EXT,703, 1, 0x0,713, 1, GLX_CONTEXT_ES2_PROFILE_BIT_EXT,723, 2, GLX_CONTEXT_CORE_PROFILE_BIT_ARB |73GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB |74GLX_CONTEXT_ES2_PROFILE_BIT_EXT,753, 3, GLX_CONTEXT_CORE_PROFILE_BIT_ARB |76GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,774, 0, GLX_CONTEXT_CORE_PROFILE_BIT_ARB |78GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,794, 1, GLX_CONTEXT_CORE_PROFILE_BIT_ARB |80GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,814, 2, GLX_CONTEXT_CORE_PROFILE_BIT_ARB |82GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,834, 3, GLX_CONTEXT_CORE_PROFILE_BIT_ARB |84GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,854, 4, GLX_CONTEXT_CORE_PROFILE_BIT_ARB |86GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,874, 5, GLX_CONTEXT_CORE_PROFILE_BIT_ARB |88GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,894, 6, GLX_CONTEXT_CORE_PROFILE_BIT_ARB |90GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,91};92static const char glx_extensions[] =93"GLX_ARB_create_context GLX_ARB_create_context_profile";9495/* There are three possible flavors of the client info structure that the96* client could send to the server. The version sent depends on the97* combination of GLX versions and extensions supported by the client and98* the server. This client only supports GLX major version 1.99*100* Server supports Client sends101* ----------------------------------------------------------------------102* GLX version = 1.0 Nothing.103*104* GLX version >= 1.1 struct GLXClientInfo105*106* GLX version >= 1.4 and107* GLX_ARB_create_context struct glXSetClientInfoARB108*109* GLX version >= 1.4 and110* GLX_ARB_create_context_profile struct glXSetClientInfo2ARB111*112* GLX_ARB_create_context and GLX_ARB_create_context_profile use FBConfigs,113* and these only exist in GLX 1.4 or with GLX_SGIX_fbconfig. I can't114* imagine an implementation that supports GLX_SGIX_fbconfig and115* GLX_ARB_create_context but not GLX 1.4. Making GLX 1.4 a hard116* requirement in this case does not seem like a limitation.117*/118119if (glx_dpy->minorVersion == 0)120return;121122/* Determine whether any screen on the server supports either of the123* create-context extensions.124*/125for (i = 0; i < ScreenCount(glx_dpy->dpy); i++) {126struct glx_screen *src = glx_dpy->screens[i];127128const char *haystack = src->serverGLXexts;129while (haystack != NULL) {130char *match = strstr(haystack, "GLX_ARB_create_context");131132if (match == NULL)133break;134135match += ext_length;136137switch (match[0]) {138case '\0':139case ' ':140any_screen_has_ARB_create_context = True;141break;142143case '_':144if (strncmp(match, "_profile", prof_length) == 0145&& (match[prof_length] == '\0'146|| match[prof_length] == ' ')) {147any_screen_has_ARB_create_context_profile = True;148match += prof_length;149}150break;151}152153haystack = match;154}155}156157gl_extension_string = __glXGetClientGLExtensionString();158if (gl_extension_string == NULL) {159return;160}161162gl_extension_length = strlen(gl_extension_string) + 1;163164c = XGetXCBConnection(glx_dpy->dpy);165166/* Depending on the GLX verion and the available extensions on the server,167* send the correct "flavor" of protocol to the server.168*169* THE ORDER IS IMPORTANT. We want to send the most recent version of the170* protocol that the server can support.171*/172if (glx_dpy->minorVersion == 4173&& any_screen_has_ARB_create_context_profile) {174xcb_glx_set_client_info_2arb(c,175GLX_MAJOR_VERSION, GLX_MINOR_VERSION,176sizeof(gl_versions_profiles)177/ (3 * sizeof(gl_versions_profiles[0])),178gl_extension_length,179strlen(glx_extensions) + 1,180gl_versions_profiles,181gl_extension_string,182glx_extensions);183} else if (glx_dpy->minorVersion == 4184&& any_screen_has_ARB_create_context) {185xcb_glx_set_client_info_arb(c,186GLX_MAJOR_VERSION, GLX_MINOR_VERSION,187sizeof(gl_versions)188/ (2 * sizeof(gl_versions[0])),189gl_extension_length,190strlen(glx_extensions) + 1,191gl_versions,192gl_extension_string,193glx_extensions);194} else {195xcb_glx_client_info(c,196GLX_MAJOR_VERSION, GLX_MINOR_VERSION,197gl_extension_length,198gl_extension_string);199}200201free(gl_extension_string);202}203204205