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.
25 #include "glxclient.h"
26 #include "glx_error.h"
28 #include <X11/Xlib-xcb.h>
32 #if INT_MAX != 2147483647
33 #error This code requires sizeof(uint32_t) == sizeof(int).
36 /* debian stretch still has ancient headers and we're apparently still
37 * using that for gitlab ci. please delete me when that's fixed.
39 #ifndef X_GLXCreateContextAttribsARB
40 #warning Please update your GLX protocol headers
41 #define X_GLXCreateContextAttribsARB 34
45 glXCreateContextAttribsARB(Display
*dpy
, GLXFBConfig config
,
46 GLXContext share_context
, Bool direct
,
47 const int *attrib_list
)
49 xcb_connection_t
*const c
= XGetXCBConnection(dpy
);
50 struct glx_config
*const cfg
= (struct glx_config
*) config
;
51 struct glx_context
*const share
= (struct glx_context
*) share_context
;
52 struct glx_context
*gc
= NULL
;
53 unsigned num_attribs
= 0;
54 struct glx_screen
*psc
;
55 xcb_generic_error_t
*err
;
56 xcb_void_cookie_t cookie
;
57 unsigned dummy_err
= 0;
63 /* Count the number of attributes specified by the application. All
64 * attributes appear in pairs, except the terminating None.
66 if (attrib_list
!= NULL
) {
67 for (/* empty */; attrib_list
[num_attribs
* 2] != 0; num_attribs
++)
74 for (unsigned int i
= 0; i
< num_attribs
; i
++) {
75 if (attrib_list
[i
* 2] == GLX_SCREEN
)
76 screen
= attrib_list
[i
* 2 + 1];
79 __glXSendError(dpy
, BadValue
, 0, X_GLXCreateContextAttribsARB
, True
);
84 /* This means that either the caller passed the wrong display pointer or
85 * one of the internal GLX data structures (probably the fbconfig) has an
86 * error. There is nothing sensible to do, so return an error.
88 psc
= GetGLXScreenConfigs(dpy
, screen
);
92 assert(screen
== psc
->scr
);
94 if (direct
&& psc
->vtable
->create_context_attribs
) {
95 /* GLX drops the error returned by the driver. The expectation is that
96 * an error will also be returned by the server. The server's error
97 * will be delivered to the application.
99 gc
= psc
->vtable
->create_context_attribs(psc
, cfg
, share
, num_attribs
,
100 (const uint32_t *) attrib_list
,
105 #ifdef GLX_USE_APPLEGL
106 gc
= applegl_create_context(psc
, cfg
, share
, 0);
108 gc
= indirect_create_context_attribs(psc
, cfg
, share
, num_attribs
,
109 (const uint32_t *) attrib_list
,
114 gc
->xid
= xcb_generate_id(c
);
115 gc
->share_xid
= (share
!= NULL
) ? share
->xid
: 0;
117 /* The manual pages for glXCreateContext and glXCreateNewContext say:
119 * "NULL is returned if execution fails on the client side."
121 * If the server generates an error, the application is supposed to catch
122 * the protocol error and handle it. Part of handling the error is freeing
123 * the possibly non-NULL value returned by this function.
126 xcb_glx_create_context_attribs_arb_checked(c
,
128 cfg
? cfg
->fbconfigID
: 0,
135 err
= xcb_request_check(c
, cookie
);
137 gc
->vtable
->destroy(gc
);
140 __glXSendErrorForXcb(dpy
, err
);
144 return (GLXContext
) gc
;