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).
37 glXCreateContextAttribsARB(Display
*dpy
, GLXFBConfig config
,
38 GLXContext share_context
, Bool direct
,
39 const int *attrib_list
)
41 xcb_connection_t
*const c
= XGetXCBConnection(dpy
);
42 struct glx_config
*const cfg
= (struct glx_config
*) config
;
43 struct glx_context
*const share
= (struct glx_context
*) share_context
;
44 struct glx_context
*gc
= NULL
;
45 unsigned num_attribs
= 0;
46 struct glx_screen
*psc
;
47 xcb_generic_error_t
*err
;
48 xcb_void_cookie_t cookie
;
49 unsigned dummy_err
= 0;
52 if (dpy
== NULL
|| cfg
== NULL
)
55 /* This means that either the caller passed the wrong display pointer or
56 * one of the internal GLX data structures (probably the fbconfig) has an
57 * error. There is nothing sensible to do, so return an error.
59 psc
= GetGLXScreenConfigs(dpy
, cfg
->screen
);
63 assert(cfg
->screen
== psc
->scr
);
65 /* Count the number of attributes specified by the application. All
66 * attributes appear in pairs, except the terminating None.
68 if (attrib_list
!= NULL
) {
69 for (/* empty */; attrib_list
[num_attribs
* 2] != 0; num_attribs
++)
73 if (direct
&& psc
->vtable
->create_context_attribs
) {
74 /* GLX drops the error returned by the driver. The expectation is that
75 * an error will also be returned by the server. The server's error
76 * will be delivered to the application.
78 gc
= psc
->vtable
->create_context_attribs(psc
, cfg
, share
, num_attribs
,
79 (const uint32_t *) attrib_list
,
84 #ifdef GLX_USE_APPLEGL
85 gc
= applegl_create_context(psc
, cfg
, share
, 0);
87 gc
= indirect_create_context(psc
, cfg
, share
, 0);
91 gc
->xid
= xcb_generate_id(c
);
92 gc
->share_xid
= (share
!= NULL
) ? share
->xid
: 0;
94 /* The manual pages for glXCreateContext and glXCreateNewContext say:
96 * "NULL is returned if execution fails on the client side."
98 * If the server generates an error, the application is supposed to catch
99 * the protocol error and handle it. Part of handling the error is freeing
100 * the possibly non-NULL value returned by this function.
103 xcb_glx_create_context_attribs_arb_checked(c
,
112 err
= xcb_request_check(c
, cookie
);
114 gc
->vtable
->destroy(gc
);
117 __glXSendErrorForXcb(dpy
, err
);
121 return (GLXContext
) gc
;