blob: bde461b43a308a877b61efad1832b89026292d8a [file] [log] [blame]
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001/*
Adam Jacksondc8058c2008-09-19 17:16:53 -04002 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice including the dates of first publication and
13 * either this permission notice or a reference to
14 * http://oss.sgi.com/projects/FreeB/
15 * shall be included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 *
25 * Except as contained in this notice, the name of Silicon Graphics, Inc.
26 * shall not be used in advertising or otherwise to promote the sale, use or
27 * other dealings in this Software without prior written authorization from
28 * Silicon Graphics, Inc.
29 */
Adam Jacksoncb3610e2004-10-25 21:09:16 +000030
31/**
32 * \file glxcmds.c
33 * Client-side GLX interface.
34 */
35
Adam Jacksoncb3610e2004-10-25 21:09:16 +000036#include "glxclient.h"
Adam Jacksoncb3610e2004-10-25 21:09:16 +000037#include "glapi.h"
Adam Jacksoncb3610e2004-10-25 21:09:16 +000038#include "glxextensions.h"
Chia-I Wue8c7d752010-12-26 18:24:13 +080039#include "indirect.h"
Ian Romanicked4a65c2011-12-07 16:13:02 -080040#include "glx_error.h"
George Sapountzisdf04ffb2008-04-18 17:28:34 +030041
42#ifdef GLX_DIRECT_RENDERING
Jeremy Huddlestonad503c42010-04-01 11:01:31 -070043#ifdef GLX_USE_APPLEGL
Jon TURNEY5a459a02014-05-12 10:47:07 +010044#include "apple/apple_glx_context.h"
45#include "apple/apple_glx.h"
Jon Turneyb37b7b42017-12-02 17:05:43 +000046#include "util/debug.h"
Jeremy Huddlestonad503c42010-04-01 11:01:31 -070047#else
Adam Jacksoncb3610e2004-10-25 21:09:16 +000048#include <sys/time.h>
Jon Turneyd512b352018-12-14 13:20:10 +000049#ifndef GLX_USE_WINDOWSGL
George Sapountzisdf04ffb2008-04-18 17:28:34 +030050#include <X11/extensions/xf86vmode.h>
Emil Velikova95ec132018-12-11 16:20:40 +000051#endif /* GLX_USE_WINDOWSGL */
Jon TURNEY2b9dac32010-04-21 12:58:54 +010052#endif
Jeremy Huddleston80b280d2010-04-02 01:35:19 -070053#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +000054
RALOVICH, Kristóf9c7aaa72008-11-04 10:59:39 +010055#include <X11/Xlib-xcb.h>
56#include <xcb/xcb.h>
57#include <xcb/glx.h>
Marek Olšák37d3a262016-03-03 18:43:53 +010058#include "GL/mesa_glinterop.h"
RALOVICH, Kristóf9c7aaa72008-11-04 10:59:39 +010059
Ian Romanick26d2ce02009-11-06 14:52:49 -080060static const char __glXGLXClientVendorName[] = "Mesa Project and SGI";
Adam Jacksoncb3610e2004-10-25 21:09:16 +000061static const char __glXGLXClientVersion[] = "1.4";
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -050062
Jeremy Huddleston80b280d2010-04-02 01:35:19 -070063#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -050064
Adam Jacksoncb3610e2004-10-25 21:09:16 +000065/**
66 * Get the __DRIdrawable for the drawable associated with a GLXContext
RALOVICH, Kristóf08962682009-08-12 12:41:22 +020067 *
Adam Jacksoncb3610e2004-10-25 21:09:16 +000068 * \param dpy The display associated with \c drawable.
69 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -050070 * \param scrn_num If non-NULL, the drawables screen is stored there
Adam Jacksoncb3610e2004-10-25 21:09:16 +000071 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
72 * the drawable is not associated with a direct-rendering context.
73 */
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -040074_X_HIDDEN __GLXDRIdrawable *
Kristian Høgsbergeeaab202010-07-22 22:36:37 -040075GetGLXDRIDrawable(Display * dpy, GLXDrawable drawable)
Adam Jacksoncb3610e2004-10-25 21:09:16 +000076{
Kristian Høgsbergc356f582010-07-28 11:16:00 -040077 struct glx_display *priv = __glXInitialize(dpy);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +020078 __GLXDRIdrawable *pdraw;
Adam Jacksoncb3610e2004-10-25 21:09:16 +000079
RALOVICH, Kristóf08962682009-08-12 12:41:22 +020080 if (priv == NULL)
81 return NULL;
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -040082
Kristian Høgsbergeeaab202010-07-22 22:36:37 -040083 if (__glxHashLookup(priv->drawHash, drawable, (void *) &pdraw) == 0)
Kristian Høgsberge3e81962010-07-19 21:15:50 -040084 return pdraw;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +020085
86 return NULL;
Adam Jacksoncb3610e2004-10-25 21:09:16 +000087}
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -050088
Adam Jacksoncb3610e2004-10-25 21:09:16 +000089#endif
90
Jesse Barnes4df13762011-05-06 10:31:24 -070091_X_HIDDEN struct glx_drawable *
92GetGLXDrawable(Display *dpy, GLXDrawable drawable)
93{
94 struct glx_display *priv = __glXInitialize(dpy);
95 struct glx_drawable *glxDraw;
96
97 if (priv == NULL)
98 return NULL;
99
100 if (__glxHashLookup(priv->glXDrawHash, drawable, (void *) &glxDraw) == 0)
101 return glxDraw;
102
103 return NULL;
104}
105
106_X_HIDDEN int
107InitGLXDrawable(Display *dpy, struct glx_drawable *glxDraw, XID xDrawable,
108 GLXDrawable drawable)
109{
110 struct glx_display *priv = __glXInitialize(dpy);
111
112 if (!priv)
113 return -1;
114
115 glxDraw->xDrawable = xDrawable;
116 glxDraw->drawable = drawable;
117 glxDraw->lastEventSbc = 0;
118 glxDraw->eventSbcWrap = 0;
119
120 return __glxHashInsert(priv->glXDrawHash, drawable, glxDraw);
121}
122
123_X_HIDDEN void
124DestroyGLXDrawable(Display *dpy, GLXDrawable drawable)
125{
126 struct glx_display *priv = __glXInitialize(dpy);
127 struct glx_drawable *glxDraw;
128
129 if (!priv)
130 return;
131
132 glxDraw = GetGLXDrawable(dpy, drawable);
133 __glxHashDelete(priv->glXDrawHash, drawable);
134 free(glxDraw);
135}
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000136
137/**
138 * Get the GLX per-screen data structure associated with a GLX context.
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200139 *
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000140 * \param dpy Display for which the GLX per-screen information is to be
141 * retrieved.
142 * \param scrn Screen on \c dpy for which the GLX per-screen information is
143 * to be retrieved.
144 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
145 * specify a valid GLX screen, or NULL otherwise.
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200146 *
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000147 * \todo Should this function validate that \c scrn is within the screen
148 * number range for \c dpy?
149 */
150
Ian Romanick588042a2011-11-30 10:33:37 -0800151_X_HIDDEN struct glx_screen *
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200152GetGLXScreenConfigs(Display * dpy, int scrn)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000153{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400154 struct glx_display *const priv = __glXInitialize(dpy);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000155
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200156 return (priv
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -0400157 && priv->screens !=
158 NULL) ? priv->screens[scrn] : NULL;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000159}
160
161
162static int
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400163GetGLXPrivScreenConfig(Display * dpy, int scrn, struct glx_display ** ppriv,
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -0400164 struct glx_screen ** ppsc)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000165{
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200166 /* Initialize the extension, if needed . This has the added value
167 * of initializing/allocating the display private
168 */
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000169
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200170 if (dpy == NULL) {
171 return GLX_NO_EXTENSION;
172 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000173
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200174 *ppriv = __glXInitialize(dpy);
175 if (*ppriv == NULL) {
176 return GLX_NO_EXTENSION;
177 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000178
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200179 /* Check screen number to see if its valid */
180 if ((scrn < 0) || (scrn >= ScreenCount(dpy))) {
181 return GLX_BAD_SCREEN;
182 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000183
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200184 /* Check to see if the GL is supported on this screen */
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -0400185 *ppsc = (*ppriv)->screens[scrn];
Dave Airlieb01a3a92013-11-18 17:34:52 +1000186 if ((*ppsc)->configs == NULL && (*ppsc)->visuals == NULL) {
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200187 /* No support for GL on this screen regardless of visual */
188 return GLX_BAD_VISUAL;
189 }
190
191 return Success;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000192}
193
194
195/**
196 * Determine if a \c GLXFBConfig supplied by the application is valid.
197 *
198 * \param dpy Application supplied \c Display pointer.
199 * \param config Application supplied \c GLXFBConfig.
200 *
201 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400202 * \c struct glx_config structure is returned. Otherwise, \c NULL
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000203 * is returned.
204 */
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400205static struct glx_config *
206ValidateGLXFBConfig(Display * dpy, GLXFBConfig fbconfig)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000207{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400208 struct glx_display *const priv = __glXInitialize(dpy);
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400209 int num_screens = ScreenCount(dpy);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200210 unsigned i;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400211 struct glx_config *config;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000212
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200213 if (priv != NULL) {
214 for (i = 0; i < num_screens; i++) {
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -0400215 for (config = priv->screens[i]->configs; config != NULL;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400216 config = config->next) {
217 if (config == (struct glx_config *) fbconfig) {
218 return config;
219 }
220 }
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200221 }
222 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000223
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200224 return NULL;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000225}
226
Tomasz Lis2eed9ff2013-07-18 14:19:38 -0700227/**
228 * Verifies context's GLX_RENDER_TYPE value with config.
229 *
230 * \param config GLX FBConfig which will support the returned renderType.
231 * \param renderType The context render type to be verified.
232 * \return True if the value of context renderType was approved, or 0 if no
233 * valid value was found.
234 */
235Bool
236validate_renderType_against_config(const struct glx_config *config,
237 int renderType)
238{
Adam Jackson74b701d2017-11-07 11:36:51 -0500239 /* GLX_EXT_no_config_context supports any render type */
240 if (!config)
241 return True;
242
243 switch (renderType) {
244 case GLX_RGBA_TYPE:
245 return (config->renderType & GLX_RGBA_BIT) != 0;
246 case GLX_COLOR_INDEX_TYPE:
247 return (config->renderType & GLX_COLOR_INDEX_BIT) != 0;
248 case GLX_RGBA_FLOAT_TYPE_ARB:
249 return (config->renderType & GLX_RGBA_FLOAT_BIT_ARB) != 0;
250 case GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT:
251 return (config->renderType & GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT) != 0;
252 default:
253 break;
254 }
255 return 0;
Tomasz Lis2eed9ff2013-07-18 14:19:38 -0700256}
257
Kristian Høgsberg31819832010-07-22 21:24:14 -0400258_X_HIDDEN Bool
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400259glx_context_init(struct glx_context *gc,
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -0400260 struct glx_screen *psc, struct glx_config *config)
Kristian Høgsberg31819832010-07-22 21:24:14 -0400261{
262 gc->majorOpcode = __glXSetupForCommand(psc->display->dpy);
263 if (!gc->majorOpcode)
Brian Paul482c43a2013-06-26 13:42:51 -0600264 return False;
Kristian Høgsberg31819832010-07-22 21:24:14 -0400265
266 gc->screen = psc->scr;
267 gc->psc = psc;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400268 gc->config = config;
Kristian Høgsberg31819832010-07-22 21:24:14 -0400269 gc->isDirect = GL_TRUE;
Kristian Høgsbergc491e582010-07-28 15:33:09 -0400270 gc->currentContextTag = -1;
Kristian Høgsberg31819832010-07-22 21:24:14 -0400271
Brian Paul482c43a2013-06-26 13:42:51 -0600272 return True;
Kristian Høgsberg31819832010-07-22 21:24:14 -0400273}
274
Adam Jackson16f10232018-08-07 16:55:37 -0400275/**
276 * Determine if a context uses direct rendering.
277 *
278 * \param dpy Display where the context was created.
279 * \param contextID ID of the context to be tested.
280 * \param error Out parameter, set to True on error if not NULL
281 *
282 * \returns \c True if the context is direct rendering or not.
283 */
284static Bool
285__glXIsDirect(Display * dpy, GLXContextID contextID, Bool *error)
286{
287 CARD8 opcode;
288 xcb_connection_t *c;
289 xcb_generic_error_t *err;
290 xcb_glx_is_direct_reply_t *reply;
291 Bool is_direct;
292
293 opcode = __glXSetupForCommand(dpy);
294 if (!opcode) {
295 return False;
296 }
297
298 c = XGetXCBConnection(dpy);
299 reply = xcb_glx_is_direct_reply(c, xcb_glx_is_direct(c, contextID), &err);
300 is_direct = (reply != NULL && reply->is_direct) ? True : False;
301
302 if (err != NULL) {
303 if (error)
304 *error = True;
305 __glXSendErrorForXcb(dpy, err);
306 free(err);
307 }
308
309 free(reply);
310
311 return is_direct;
312}
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000313
314/**
Adam Jackson3869be72011-04-29 16:30:50 -0400315 * Create a new context.
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200316 *
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000317 * \param renderType For FBConfigs, what is the rendering type?
318 */
319
320static GLXContext
Adam Jackson3869be72011-04-29 16:30:50 -0400321CreateContext(Display *dpy, int generic_id, struct glx_config *config,
322 GLXContext shareList_user, Bool allowDirect,
Ian Romanick7bcfb662010-02-04 16:37:59 -0800323 unsigned code, int renderType, int screen)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000324{
nobledb5dc4072010-08-19 14:06:21 -0400325 struct glx_context *gc;
326 struct glx_screen *psc;
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400327 struct glx_context *shareList = (struct glx_context *) shareList_user;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200328 if (dpy == NULL)
329 return NULL;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000330
nobledb5dc4072010-08-19 14:06:21 -0400331 psc = GetGLXScreenConfigs(dpy, screen);
332 if (psc == NULL)
333 return NULL;
334
Ian Romanickd46d30f2010-02-04 17:06:18 -0800335 if (generic_id == None)
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200336 return NULL;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000337
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -0400338 gc = NULL;
Jeremy Huddleston1885cf22011-06-05 18:50:55 -0400339#ifdef GLX_USE_APPLEGL
340 gc = applegl_create_context(psc, config, shareList, renderType);
341#else
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -0400342 if (allowDirect && psc->vtable->create_context)
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400343 gc = psc->vtable->create_context(psc, config, shareList, renderType);
Kristian Høgsberg31819832010-07-22 21:24:14 -0400344 if (!gc)
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400345 gc = indirect_create_context(psc, config, shareList, renderType);
Jeremy Huddleston1885cf22011-06-05 18:50:55 -0400346#endif
Kristian Høgsberg31819832010-07-22 21:24:14 -0400347 if (!gc)
348 return NULL;
Kristian Høgsberg643b2af2010-05-21 10:36:56 -0400349
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800350 LockDisplay(dpy);
351 switch (code) {
352 case X_GLXCreateContext: {
353 xGLXCreateContextReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000354
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800355 /* Send the glXCreateContext request */
356 GetReq(GLXCreateContext, req);
357 req->reqType = gc->majorOpcode;
358 req->glxCode = X_GLXCreateContext;
359 req->context = gc->xid = XAllocID(dpy);
Ian Romanickd46d30f2010-02-04 17:06:18 -0800360 req->visual = generic_id;
Ian Romanickc3db1d62010-02-04 17:01:42 -0800361 req->screen = screen;
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800362 req->shareList = shareList ? shareList->xid : None;
Kristian Høgsbergc491e582010-07-28 15:33:09 -0400363 req->isDirect = gc->isDirect;
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800364 break;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200365 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000366
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800367 case X_GLXCreateNewContext: {
368 xGLXCreateNewContextReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000369
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800370 /* Send the glXCreateNewContext request */
371 GetReq(GLXCreateNewContext, req);
372 req->reqType = gc->majorOpcode;
373 req->glxCode = X_GLXCreateNewContext;
374 req->context = gc->xid = XAllocID(dpy);
Ian Romanickd46d30f2010-02-04 17:06:18 -0800375 req->fbconfig = generic_id;
Ian Romanickc3db1d62010-02-04 17:01:42 -0800376 req->screen = screen;
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800377 req->renderType = renderType;
378 req->shareList = shareList ? shareList->xid : None;
Kristian Høgsbergc491e582010-07-28 15:33:09 -0400379 req->isDirect = gc->isDirect;
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800380 break;
381 }
Ian Romanick8bffadb2010-02-04 16:28:52 -0800382
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800383 case X_GLXvop_CreateContextWithConfigSGIX: {
384 xGLXVendorPrivateWithReplyReq *vpreq;
385 xGLXCreateContextWithConfigSGIXReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000386
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800387 /* Send the glXCreateNewContext request */
388 GetReqExtra(GLXVendorPrivateWithReply,
389 sz_xGLXCreateContextWithConfigSGIXReq -
390 sz_xGLXVendorPrivateWithReplyReq, vpreq);
391 req = (xGLXCreateContextWithConfigSGIXReq *) vpreq;
392 req->reqType = gc->majorOpcode;
393 req->glxCode = X_GLXVendorPrivateWithReply;
394 req->vendorCode = X_GLXvop_CreateContextWithConfigSGIX;
395 req->context = gc->xid = XAllocID(dpy);
Ian Romanickd46d30f2010-02-04 17:06:18 -0800396 req->fbconfig = generic_id;
Ian Romanickc3db1d62010-02-04 17:01:42 -0800397 req->screen = screen;
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800398 req->renderType = renderType;
399 req->shareList = shareList ? shareList->xid : None;
Kristian Høgsbergc491e582010-07-28 15:33:09 -0400400 req->isDirect = gc->isDirect;
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800401 break;
402 }
Ian Romanick8bffadb2010-02-04 16:28:52 -0800403
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800404 default:
405 /* What to do here? This case is the sign of an internal error. It
406 * should never be reachable.
407 */
408 break;
409 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000410
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800411 UnlockDisplay(dpy);
412 SyncHandle();
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000413
Ian Romanicka832aa52011-12-08 15:03:19 -0800414 gc->share_xid = shareList ? shareList->xid : None;
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800415 gc->imported = GL_FALSE;
Brian Paul521e4b92009-09-29 10:24:27 -0600416
Adam Jackson16f10232018-08-07 16:55:37 -0400417 /* Unlike most X resource creation requests, we're about to return a handle
418 * with client-side state, not just an XID. To simplify error handling
419 * elsewhere in libGL, force a round-trip here to ensure the CreateContext
420 * request above succeeded.
421 */
422 {
423 Bool error = False;
424 int isDirect = __glXIsDirect(dpy, gc->xid, &error);
425
426 if (error != False || isDirect != gc->isDirect) {
427 gc->vtable->destroy(gc);
428 gc = NULL;
429 }
430 }
431
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400432 return (GLXContext) gc;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000433}
434
Kyle Brenneman22a9e002016-05-11 14:01:53 -0400435_GLX_PUBLIC GLXContext
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200436glXCreateContext(Display * dpy, XVisualInfo * vis,
437 GLXContext shareList, Bool allowDirect)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000438{
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400439 struct glx_config *config = NULL;
Tomasz Lis36259a12013-07-17 13:49:14 +0200440 int renderType = GLX_RGBA_TYPE;
Ian Romanick52cf8db2010-02-04 16:59:10 -0800441
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700442#if defined(GLX_DIRECT_RENDERING) || defined(GLX_USE_APPLEGL)
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -0400443 struct glx_screen *const psc = GetGLXScreenConfigs(dpy, vis->screen);
Ian Romanick52cf8db2010-02-04 16:59:10 -0800444
Juha-Pekka Heikkilad28e92f2014-02-07 14:43:57 +0200445 if (psc)
446 config = glx_config_find_visual(psc->visuals, vis->visualid);
447
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400448 if (config == NULL) {
Adam Jackson75d5d222017-11-14 15:13:02 -0500449 __glXSendError(dpy, BadValue, vis->visualid, X_GLXCreateContext, True);
Ian Romanick52cf8db2010-02-04 16:59:10 -0800450 return None;
451 }
452
Tomasz Lis1c748df2013-07-17 13:49:17 +0200453 /* Choose the context render type based on DRI config values. It is
454 * unusual to set this type from config, but we have no other choice, as
455 * this old API does not provide renderType parameter.
456 */
457 if (config->renderType & GLX_RGBA_FLOAT_BIT_ARB) {
458 renderType = GLX_RGBA_FLOAT_TYPE_ARB;
459 } else if (config->renderType & GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT) {
460 renderType = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
461 } else if (config->renderType & GLX_RGBA_BIT) {
462 renderType = GLX_RGBA_TYPE;
463 } else if (config->renderType & GLX_COLOR_INDEX_BIT) {
464 renderType = GLX_COLOR_INDEX_TYPE;
465 } else if (config->rgbMode) {
466 /* If we're here, then renderType is not set correctly. Let's use a
467 * safeguard - any TrueColor or DirectColor mode is RGB mode. Such
468 * default value is needed by old DRI drivers, which didn't set
469 * renderType correctly as the value was just ignored.
470 */
471 renderType = GLX_RGBA_TYPE;
472 } else {
473 /* Safeguard - only one option left, all non-RGB modes are indexed
474 * modes. Again, this allows drivers with invalid renderType to work
475 * properly.
476 */
477 renderType = GLX_COLOR_INDEX_TYPE;
478 }
Ian Romanick52cf8db2010-02-04 16:59:10 -0800479#endif
480
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400481 return CreateContext(dpy, vis->visualid, config, shareList, allowDirect,
Ian Romanick52cf8db2010-02-04 16:59:10 -0800482 X_GLXCreateContext, renderType, vis->screen);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000483}
484
Ian Romanick4dbd13c2011-12-07 13:31:27 -0800485static void
Kristian Høgsbergc796bb02010-07-22 23:45:18 -0400486glx_send_destroy_context(Display *dpy, XID xid)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000487{
Kristian Høgsbergc796bb02010-07-22 23:45:18 -0400488 CARD8 opcode = __glXSetupForCommand(dpy);
489 xGLXDestroyContextReq *req;
490
491 LockDisplay(dpy);
492 GetReq(GLXDestroyContext, req);
493 req->reqType = opcode;
494 req->glxCode = X_GLXDestroyContext;
495 req->context = xid;
496 UnlockDisplay(dpy);
497 SyncHandle();
498}
499
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000500/*
501** Destroy the named context
502*/
Adam Jackson9e2bc5d2011-06-02 16:29:59 -0400503
Kyle Brenneman22a9e002016-05-11 14:01:53 -0400504_GLX_PUBLIC void
Adam Jackson9e2bc5d2011-06-02 16:29:59 -0400505glXDestroyContext(Display * dpy, GLXContext ctx)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000506{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400507 struct glx_context *gc = (struct glx_context *) ctx;
508
Ian Romanick4dbd13c2011-12-07 13:31:27 -0800509 if (gc == NULL || gc->xid == None)
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200510 return;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000511
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200512 __glXLock();
Ian Romanick4dbd13c2011-12-07 13:31:27 -0800513 if (!gc->imported)
514 glx_send_destroy_context(dpy, gc->xid);
515
Brian Paul5e6a6a22009-10-22 18:19:01 -0600516 if (gc->currentDpy) {
517 /* This context is bound to some thread. According to the man page,
518 * we should not actually delete the context until it's unbound.
519 * Note that we set gc->xid = None above. In MakeContextCurrent()
520 * we check for that and delete the context there.
521 */
Kristian Høgsbergc796bb02010-07-22 23:45:18 -0400522 gc->xid = None;
Ian Romanick4dbd13c2011-12-07 13:31:27 -0800523 } else {
524 gc->vtable->destroy(gc);
Brian Paul5e6a6a22009-10-22 18:19:01 -0600525 }
Kristian Høgsbergc796bb02010-07-22 23:45:18 -0400526 __glXUnlock();
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000527}
Adam Jackson489ccef2004-12-15 17:18:06 +0000528
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000529/*
530** Return the major and minor version #s for the GLX extension
531*/
Kyle Brenneman22a9e002016-05-11 14:01:53 -0400532_GLX_PUBLIC Bool
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200533glXQueryVersion(Display * dpy, int *major, int *minor)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000534{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400535 struct glx_display *priv;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000536
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200537 /* Init the extension. This fetches the major and minor version. */
538 priv = __glXInitialize(dpy);
539 if (!priv)
Brian Paul482c43a2013-06-26 13:42:51 -0600540 return False;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000541
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200542 if (major)
543 *major = priv->majorVersion;
544 if (minor)
545 *minor = priv->minorVersion;
Brian Paul482c43a2013-06-26 13:42:51 -0600546 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000547}
548
549/*
Zoë Blade05e7f7f2015-04-22 11:33:17 +0100550** Query the existence of the GLX extension
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000551*/
Kyle Brenneman22a9e002016-05-11 14:01:53 -0400552_GLX_PUBLIC Bool
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200553glXQueryExtension(Display * dpy, int *errorBase, int *eventBase)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000554{
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200555 int major_op, erb, evb;
556 Bool rv;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000557
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200558 rv = XQueryExtension(dpy, GLX_EXTENSION_NAME, &major_op, &evb, &erb);
559 if (rv) {
560 if (errorBase)
561 *errorBase = erb;
562 if (eventBase)
563 *eventBase = evb;
564 }
565 return rv;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000566}
567
Kristian Høgsberg7b7845a2010-07-22 22:24:00 -0400568/*
569** Put a barrier in the token stream that forces the GL to finish its
570** work before X can proceed.
571*/
Kyle Brenneman22a9e002016-05-11 14:01:53 -0400572_GLX_PUBLIC void
Kristian Høgsberg7b7845a2010-07-22 22:24:00 -0400573glXWaitGL(void)
574{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400575 struct glx_context *gc = __glXGetCurrentContext();
Kristian Høgsberg7b7845a2010-07-22 22:24:00 -0400576
Adam Jacksonbcb15be2017-11-14 15:13:01 -0500577 if (gc->vtable->wait_gl)
Kristian Høgsberg7b7845a2010-07-22 22:24:00 -0400578 gc->vtable->wait_gl(gc);
579}
580
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000581/*
582** Put a barrier in the token stream that forces X to finish its
583** work before GL can proceed.
584*/
Kyle Brenneman22a9e002016-05-11 14:01:53 -0400585_GLX_PUBLIC void
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200586glXWaitX(void)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000587{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400588 struct glx_context *gc = __glXGetCurrentContext();
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000589
Adam Jacksonbcb15be2017-11-14 15:13:01 -0500590 if (gc->vtable->wait_x)
Kristian Høgsberg7b7845a2010-07-22 22:24:00 -0400591 gc->vtable->wait_x(gc);
592}
593
Kyle Brenneman22a9e002016-05-11 14:01:53 -0400594_GLX_PUBLIC void
Kristian Høgsberg7b7845a2010-07-22 22:24:00 -0400595glXUseXFont(Font font, int first, int count, int listBase)
596{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400597 struct glx_context *gc = __glXGetCurrentContext();
Kristian Høgsberg7b7845a2010-07-22 22:24:00 -0400598
Adam Jacksonbcb15be2017-11-14 15:13:01 -0500599 if (gc->vtable->use_x_font)
Kristian Høgsberg7b7845a2010-07-22 22:24:00 -0400600 gc->vtable->use_x_font(gc, font, first, count, listBase);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000601}
602
603/************************************************************************/
604
605/*
606** Copy the source context to the destination context using the
607** attribute "mask".
608*/
Kyle Brenneman22a9e002016-05-11 14:01:53 -0400609_GLX_PUBLIC void
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400610glXCopyContext(Display * dpy, GLXContext source_user,
611 GLXContext dest_user, unsigned long mask)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000612{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400613 struct glx_context *source = (struct glx_context *) source_user;
614 struct glx_context *dest = (struct glx_context *) dest_user;
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700615#ifdef GLX_USE_APPLEGL
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400616 struct glx_context *gc = __glXGetCurrentContext();
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700617 int errorcode;
618 bool x11error;
619
Jeremy Huddleston80b280d2010-04-02 01:35:19 -0700620 if(apple_glx_copy_context(gc->driContext, source->driContext, dest->driContext,
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700621 mask, &errorcode, &x11error)) {
622 __glXSendError(dpy, errorcode, 0, X_GLXCopyContext, x11error);
623 }
624
625#else
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200626 xGLXCopyContextReq *req;
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400627 struct glx_context *gc = __glXGetCurrentContext();
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200628 GLXContextTag tag;
629 CARD8 opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000630
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200631 opcode = __glXSetupForCommand(dpy);
632 if (!opcode) {
633 return;
634 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000635
Jeremy Huddleston80b280d2010-04-02 01:35:19 -0700636#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
Kristian Høgsbergc491e582010-07-28 15:33:09 -0400637 if (gc->isDirect) {
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200638 /* NOT_DONE: This does not work yet */
639 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000640#endif
641
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200642 /*
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000643 ** If the source is the current context, send its tag so that the context
644 ** can be flushed before the copy.
645 */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200646 if (source == gc && dpy == gc->currentDpy) {
647 tag = gc->currentContextTag;
648 }
649 else {
650 tag = 0;
651 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000652
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200653 /* Send the glXCopyContext request */
654 LockDisplay(dpy);
655 GetReq(GLXCopyContext, req);
656 req->reqType = opcode;
657 req->glxCode = X_GLXCopyContext;
658 req->source = source ? source->xid : None;
659 req->dest = dest ? dest->xid : None;
660 req->mask = mask;
661 req->contextTag = tag;
662 UnlockDisplay(dpy);
663 SyncHandle();
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700664#endif /* GLX_USE_APPLEGL */
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000665}
666
667
668/**
Ian Romanickc39bf5e2005-07-24 06:29:14 +0000669 * \todo
Brian Paul482c43a2013-06-26 13:42:51 -0600670 * Shouldn't this function \b always return \c False when
Ian Romanickc39bf5e2005-07-24 06:29:14 +0000671 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
672 * the GLX protocol here at all?
673 */
Kyle Brenneman22a9e002016-05-11 14:01:53 -0400674_GLX_PUBLIC Bool
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400675glXIsDirect(Display * dpy, GLXContext gc_user)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000676{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400677 struct glx_context *gc = (struct glx_context *) gc_user;
678
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200679 if (!gc) {
Brian Paul482c43a2013-06-26 13:42:51 -0600680 return False;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200681 }
Kristian Høgsbergc491e582010-07-28 15:33:09 -0400682 else if (gc->isDirect) {
Brian Paul482c43a2013-06-26 13:42:51 -0600683 return True;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200684 }
Jeremy Huddlestona18702f2010-05-01 13:59:30 -0700685#ifdef GLX_USE_APPLEGL /* TODO: indirect on darwin */
Brian Paul482c43a2013-06-26 13:42:51 -0600686 return False;
Jeremy Huddlestona18702f2010-05-01 13:59:30 -0700687#else
Adam Jackson16f10232018-08-07 16:55:37 -0400688 return __glXIsDirect(dpy, gc->xid, NULL);
Jeremy Huddlestona18702f2010-05-01 13:59:30 -0700689#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000690}
691
Kyle Brenneman22a9e002016-05-11 14:01:53 -0400692_GLX_PUBLIC GLXPixmap
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200693glXCreateGLXPixmap(Display * dpy, XVisualInfo * vis, Pixmap pixmap)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000694{
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700695#ifdef GLX_USE_APPLEGL
696 int screen = vis->screen;
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -0400697 struct glx_screen *const psc = GetGLXScreenConfigs(dpy, screen);
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400698 const struct glx_config *config;
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700699
Jeremy Huddlestonb7f0ed82011-06-05 18:19:59 -0400700 config = glx_config_find_visual(psc->visuals, vis->visualid);
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700701
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400702 if(apple_glx_pixmap_create(dpy, vis->screen, pixmap, config))
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700703 return None;
704
705 return pixmap;
706#else
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200707 xGLXCreateGLXPixmapReq *req;
Jesse Barnes4df13762011-05-06 10:31:24 -0700708 struct glx_drawable *glxDraw;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200709 GLXPixmap xid;
710 CARD8 opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000711
Juha-Pekka Heikkilad28e92f2014-02-07 14:43:57 +0200712#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
713 struct glx_display *const priv = __glXInitialize(dpy);
714
715 if (priv == NULL)
716 return None;
717#endif
718
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200719 opcode = __glXSetupForCommand(dpy);
720 if (!opcode) {
721 return None;
722 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000723
Matt Turner7c7b7b02012-09-04 22:52:36 -0700724 glxDraw = malloc(sizeof(*glxDraw));
Jesse Barnes4df13762011-05-06 10:31:24 -0700725 if (!glxDraw)
726 return None;
727
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200728 /* Send the glXCreateGLXPixmap request */
729 LockDisplay(dpy);
730 GetReq(GLXCreateGLXPixmap, req);
731 req->reqType = opcode;
732 req->glxCode = X_GLXCreateGLXPixmap;
733 req->screen = vis->screen;
734 req->visual = vis->visualid;
735 req->pixmap = pixmap;
736 req->glxpixmap = xid = XAllocID(dpy);
737 UnlockDisplay(dpy);
738 SyncHandle();
Michel Dänzeredb11782009-08-30 12:43:37 +0200739
Jesse Barnes4df13762011-05-06 10:31:24 -0700740 if (InitGLXDrawable(dpy, glxDraw, pixmap, req->glxpixmap)) {
741 free(glxDraw);
742 return None;
743 }
744
Jeremy Huddleston80b280d2010-04-02 01:35:19 -0700745#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
Michel Dänzer9053bb02009-08-30 13:06:18 +0200746 do {
747 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
748 * is actually bound to a context... */
Michel Dänzeredb11782009-08-30 12:43:37 +0200749
Michel Dänzer9053bb02009-08-30 13:06:18 +0200750 __GLXDRIdrawable *pdraw;
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -0400751 struct glx_screen *psc;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400752 struct glx_config *config;
Michel Dänzeredb11782009-08-30 12:43:37 +0200753
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -0400754 psc = priv->screens[vis->screen];
Michel Dänzer9053bb02009-08-30 13:06:18 +0200755 if (psc->driScreen == NULL)
Adam Jackson48331042011-03-31 20:43:57 +0000756 return xid;
757
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400758 config = glx_config_find_visual(psc->visuals, vis->visualid);
Adam Jackson776a2a52011-06-01 11:33:48 -0400759 pdraw = psc->driScreen->createDrawable(psc, pixmap, xid, config);
Michel Dänzer9053bb02009-08-30 13:06:18 +0200760 if (pdraw == NULL) {
761 fprintf(stderr, "failed to create pixmap\n");
Adam Jackson48331042011-03-31 20:43:57 +0000762 xid = None;
Michel Dänzer9053bb02009-08-30 13:06:18 +0200763 break;
764 }
Michel Dänzeredb11782009-08-30 12:43:37 +0200765
Adam Jackson776a2a52011-06-01 11:33:48 -0400766 if (__glxHashInsert(priv->drawHash, xid, pdraw)) {
Michel Dänzer9053bb02009-08-30 13:06:18 +0200767 (*pdraw->destroyDrawable) (pdraw);
Adam Jackson48331042011-03-31 20:43:57 +0000768 xid = None;
769 break;
Michel Dänzer9053bb02009-08-30 13:06:18 +0200770 }
771 } while (0);
Adam Jackson48331042011-03-31 20:43:57 +0000772
773 if (xid == None) {
774 xGLXDestroyGLXPixmapReq *dreq;
775 LockDisplay(dpy);
776 GetReq(GLXDestroyGLXPixmap, dreq);
777 dreq->reqType = opcode;
778 dreq->glxCode = X_GLXDestroyGLXPixmap;
779 dreq->glxpixmap = xid;
780 UnlockDisplay(dpy);
781 SyncHandle();
782 }
Michel Dänzeredb11782009-08-30 12:43:37 +0200783#endif
784
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200785 return xid;
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700786#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000787}
788
789/*
790** Destroy the named pixmap
791*/
Kyle Brenneman22a9e002016-05-11 14:01:53 -0400792_GLX_PUBLIC void
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200793glXDestroyGLXPixmap(Display * dpy, GLXPixmap glxpixmap)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000794{
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700795#ifdef GLX_USE_APPLEGL
796 if(apple_glx_pixmap_destroy(dpy, glxpixmap))
797 __glXSendError(dpy, GLXBadPixmap, glxpixmap, X_GLXDestroyPixmap, false);
798#else
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200799 xGLXDestroyGLXPixmapReq *req;
800 CARD8 opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000801
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200802 opcode = __glXSetupForCommand(dpy);
803 if (!opcode) {
804 return;
805 }
806
807 /* Send the glXDestroyGLXPixmap request */
808 LockDisplay(dpy);
809 GetReq(GLXDestroyGLXPixmap, req);
810 req->reqType = opcode;
811 req->glxCode = X_GLXDestroyGLXPixmap;
812 req->glxpixmap = glxpixmap;
813 UnlockDisplay(dpy);
814 SyncHandle();
Michel Dänzer9dfce362009-06-19 11:19:07 +0200815
Jesse Barnes4df13762011-05-06 10:31:24 -0700816 DestroyGLXDrawable(dpy, glxpixmap);
817
Jeremy Huddleston80b280d2010-04-02 01:35:19 -0700818#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200819 {
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400820 struct glx_display *const priv = __glXInitialize(dpy);
Kristian Høgsbergeeaab202010-07-22 22:36:37 -0400821 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, glxpixmap);
Michel Dänzer9dfce362009-06-19 11:19:07 +0200822
Juha-Pekka Heikkilad28e92f2014-02-07 14:43:57 +0200823 if (priv != NULL && pdraw != NULL) {
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200824 (*pdraw->destroyDrawable) (pdraw);
Kristian Høgsberge3e81962010-07-19 21:15:50 -0400825 __glxHashDelete(priv->drawHash, glxpixmap);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200826 }
827 }
Michel Dänzer9dfce362009-06-19 11:19:07 +0200828#endif
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700829#endif /* GLX_USE_APPLEGL */
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000830}
831
Kyle Brenneman22a9e002016-05-11 14:01:53 -0400832_GLX_PUBLIC void
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200833glXSwapBuffers(Display * dpy, GLXDrawable drawable)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000834{
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700835#ifdef GLX_USE_APPLEGL
Jeremy Huddleston279e4712011-06-05 18:22:47 -0400836 struct glx_context * gc = __glXGetCurrentContext();
Jeremy Huddleston Sequoiac1c4c182017-08-17 15:08:36 -0700837 if(gc != &dummyContext && apple_glx_is_current_drawable(dpy, gc->driContext, drawable)) {
Jeremy Huddleston80b280d2010-04-02 01:35:19 -0700838 apple_glx_swap_buffers(gc->driContext);
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700839 } else {
840 __glXSendError(dpy, GLXBadCurrentWindow, 0, X_GLXSwapBuffers, false);
841 }
842#else
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400843 struct glx_context *gc;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200844 GLXContextTag tag;
845 CARD8 opcode;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200846 xcb_connection_t *c;
Brian Paulb7f802e2009-01-18 09:59:07 -0700847
Eric Anholt4d01bea2011-02-14 18:38:33 -0800848 gc = __glXGetCurrentContext();
849
Jeremy Huddleston80b280d2010-04-02 01:35:19 -0700850#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
Brian Paule975e182011-08-19 08:36:22 -0600851 {
852 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000853
Brian Paule975e182011-08-19 08:36:22 -0600854 if (pdraw != NULL) {
Bernard Kilarski2e3f0672016-06-07 13:33:33 +0300855 Bool flush = gc != &dummyContext && drawable == gc->currentDrawable;
Brian Paule975e182011-08-19 08:36:22 -0600856
Marek Olšák5b7e9b72012-11-13 17:06:37 +0100857 (*pdraw->psc->driScreen->swapBuffers)(pdraw, 0, 0, 0, flush);
Brian Paule975e182011-08-19 08:36:22 -0600858 return;
Eric Anholt4d01bea2011-02-14 18:38:33 -0800859 }
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200860 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000861#endif
862
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200863 opcode = __glXSetupForCommand(dpy);
864 if (!opcode) {
865 return;
866 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000867
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200868 /*
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000869 ** The calling thread may or may not have a current context. If it
870 ** does, send the context tag so the server can do a flush.
871 */
Bernard Kilarski2e3f0672016-06-07 13:33:33 +0300872 if ((gc != &dummyContext) && (dpy == gc->currentDpy) &&
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200873 ((drawable == gc->currentDrawable)
874 || (drawable == gc->currentReadable))) {
875 tag = gc->currentContextTag;
876 }
877 else {
878 tag = 0;
879 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000880
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200881 c = XGetXCBConnection(dpy);
882 xcb_glx_swap_buffers(c, tag, drawable);
883 xcb_flush(c);
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700884#endif /* GLX_USE_APPLEGL */
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000885}
886
887
888/*
889** Return configuration information for the given display, screen and
890** visual combination.
891*/
Kyle Brenneman22a9e002016-05-11 14:01:53 -0400892_GLX_PUBLIC int
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200893glXGetConfig(Display * dpy, XVisualInfo * vis, int attribute,
894 int *value_return)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000895{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400896 struct glx_display *priv;
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -0400897 struct glx_screen *psc;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400898 struct glx_config *config;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200899 int status;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000900
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200901 status = GetGLXPrivScreenConfig(dpy, vis->screen, &priv, &psc);
902 if (status == Success) {
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400903 config = glx_config_find_visual(psc->visuals, vis->visualid);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000904
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200905 /* Lookup attribute after first finding a match on the visual */
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400906 if (config != NULL) {
907 return glx_config_get(config, attribute, value_return);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200908 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000909
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200910 status = GLX_BAD_VISUAL;
911 }
912
913 /*
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000914 ** If we can't find the config for this visual, this visual is not
915 ** supported by the OpenGL implementation on the server.
916 */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200917 if ((status == GLX_BAD_VISUAL) && (attribute == GLX_USE_GL)) {
Brian Paul482c43a2013-06-26 13:42:51 -0600918 *value_return = False;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200919 status = Success;
920 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000921
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200922 return status;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000923}
924
925/************************************************************************/
926
927static void
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400928init_fbconfig_for_chooser(struct glx_config * config,
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200929 GLboolean fbconfig_style_tags)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000930{
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400931 memset(config, 0, sizeof(struct glx_config));
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200932 config->visualID = (XID) GLX_DONT_CARE;
933 config->visualType = GLX_DONT_CARE;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000934
Tomasz Lis4473af72013-07-17 13:49:20 +0200935 /* glXChooseFBConfig specifies different defaults for these properties than
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200936 * glXChooseVisual.
937 */
938 if (fbconfig_style_tags) {
939 config->rgbMode = GL_TRUE;
940 config->doubleBufferMode = GLX_DONT_CARE;
Fredrik Höglundf41c2f62014-02-13 21:07:09 +0100941 config->renderType = GLX_RGBA_BIT;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200942 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000943
Fredrik Höglundf41c2f62014-02-13 21:07:09 +0100944 config->drawableType = GLX_WINDOW_BIT;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200945 config->visualRating = GLX_DONT_CARE;
946 config->transparentPixel = GLX_NONE;
947 config->transparentRed = GLX_DONT_CARE;
948 config->transparentGreen = GLX_DONT_CARE;
949 config->transparentBlue = GLX_DONT_CARE;
950 config->transparentAlpha = GLX_DONT_CARE;
951 config->transparentIndex = GLX_DONT_CARE;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000952
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200953 config->xRenderable = GLX_DONT_CARE;
954 config->fbconfigID = (GLXFBConfigID) (GLX_DONT_CARE);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000955
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200956 config->swapMethod = GLX_DONT_CARE;
Jon Turneyfaa29c02018-07-14 15:24:14 +0100957 config->sRGBCapable = GLX_DONT_CARE;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000958}
959
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200960#define MATCH_DONT_CARE( param ) \
961 do { \
Ian Romanick71a6fb12010-02-04 15:59:51 -0800962 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200963 && (a-> param != b-> param) ) { \
964 return False; \
965 } \
966 } while ( 0 )
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000967
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200968#define MATCH_MINIMUM( param ) \
969 do { \
Ian Romanick71a6fb12010-02-04 15:59:51 -0800970 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200971 && (a-> param > b-> param) ) { \
972 return False; \
973 } \
974 } while ( 0 )
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000975
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200976#define MATCH_EXACT( param ) \
977 do { \
978 if ( a-> param != b-> param) { \
979 return False; \
980 } \
981 } while ( 0 )
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000982
Kristian Høgsbergedb52532010-04-08 22:09:11 -0400983/* Test that all bits from a are contained in b */
984#define MATCH_MASK(param) \
985 do { \
Alexander Monakov9cda3562013-04-02 01:38:27 +0400986 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
987 && ((a->param & ~b->param) != 0) ) { \
Kristian Høgsbergedb52532010-04-08 22:09:11 -0400988 return False; \
Alexander Monakov9cda3562013-04-02 01:38:27 +0400989 } \
Kristian Høgsbergedb52532010-04-08 22:09:11 -0400990 } while (0);
991
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000992/**
993 * Determine if two GLXFBConfigs are compatible.
994 *
995 * \param a Application specified config to test.
996 * \param b Server specified config to test against \c a.
997 */
998static Bool
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400999fbconfigs_compatible(const struct glx_config * const a,
1000 const struct glx_config * const b)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001001{
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001002 MATCH_DONT_CARE(doubleBufferMode);
1003 MATCH_DONT_CARE(visualType);
1004 MATCH_DONT_CARE(visualRating);
1005 MATCH_DONT_CARE(xRenderable);
1006 MATCH_DONT_CARE(fbconfigID);
1007 MATCH_DONT_CARE(swapMethod);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001008
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001009 MATCH_MINIMUM(rgbBits);
1010 MATCH_MINIMUM(numAuxBuffers);
1011 MATCH_MINIMUM(redBits);
1012 MATCH_MINIMUM(greenBits);
1013 MATCH_MINIMUM(blueBits);
1014 MATCH_MINIMUM(alphaBits);
1015 MATCH_MINIMUM(depthBits);
1016 MATCH_MINIMUM(stencilBits);
1017 MATCH_MINIMUM(accumRedBits);
1018 MATCH_MINIMUM(accumGreenBits);
1019 MATCH_MINIMUM(accumBlueBits);
1020 MATCH_MINIMUM(accumAlphaBits);
1021 MATCH_MINIMUM(sampleBuffers);
1022 MATCH_MINIMUM(maxPbufferWidth);
1023 MATCH_MINIMUM(maxPbufferHeight);
1024 MATCH_MINIMUM(maxPbufferPixels);
1025 MATCH_MINIMUM(samples);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001026
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001027 MATCH_DONT_CARE(stereoMode);
1028 MATCH_EXACT(level);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001029
Kristian Høgsbergedb52532010-04-08 22:09:11 -04001030 MATCH_MASK(drawableType);
1031 MATCH_MASK(renderType);
Neha Bhende6e06e282017-04-26 16:21:32 -07001032 MATCH_DONT_CARE(sRGBCapable);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001033
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001034 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1035 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1036 * Technically speaking, it is a bug in the DDX driver, but there is
1037 * enough of an installed base to work around the problem here. In any
1038 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1039 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1040 * 0 from the server to be a match to maintain backward compatibility with
1041 * the (broken) drivers.
1042 */
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001043
Ian Romanick71a6fb12010-02-04 15:59:51 -08001044 if (a->transparentPixel != (int) GLX_DONT_CARE && a->transparentPixel != 0) {
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001045 if (a->transparentPixel == GLX_NONE) {
1046 if (b->transparentPixel != GLX_NONE && b->transparentPixel != 0)
1047 return False;
1048 }
1049 else {
1050 MATCH_EXACT(transparentPixel);
1051 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001052
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001053 switch (a->transparentPixel) {
1054 case GLX_TRANSPARENT_RGB:
1055 MATCH_DONT_CARE(transparentRed);
1056 MATCH_DONT_CARE(transparentGreen);
1057 MATCH_DONT_CARE(transparentBlue);
1058 MATCH_DONT_CARE(transparentAlpha);
1059 break;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001060
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001061 case GLX_TRANSPARENT_INDEX:
1062 MATCH_DONT_CARE(transparentIndex);
1063 break;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001064
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001065 default:
1066 break;
1067 }
1068 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001069
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001070 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001071}
1072
1073
1074/* There's some trickly language in the GLX spec about how this is supposed
1075 * to work. Basically, if a given component size is either not specified
1076 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1077 * Well, that's really hard to do with the code as-is. This behavior is
1078 * closer to correct, but still not technically right.
1079 */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001080#define PREFER_LARGER_OR_ZERO(comp) \
1081 do { \
1082 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1083 if ( ((*a)-> comp) == 0 ) { \
1084 return -1; \
1085 } \
1086 else if ( ((*b)-> comp) == 0 ) { \
1087 return 1; \
1088 } \
1089 else { \
1090 return ((*b)-> comp) - ((*a)-> comp) ; \
1091 } \
1092 } \
1093 } while( 0 )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001094
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001095#define PREFER_LARGER(comp) \
1096 do { \
1097 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1098 return ((*b)-> comp) - ((*a)-> comp) ; \
1099 } \
1100 } while( 0 )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001101
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001102#define PREFER_SMALLER(comp) \
1103 do { \
1104 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1105 return ((*a)-> comp) - ((*b)-> comp) ; \
1106 } \
1107 } while( 0 )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001108
1109/**
1110 * Compare two GLXFBConfigs. This function is intended to be used as the
1111 * compare function passed in to qsort.
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001112 *
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001113 * \returns If \c a is a "better" config, according to the specification of
1114 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1115 * better, then a number greater than zero is return. If both are
1116 * equal, zero is returned.
1117 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1118 */
1119static int
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001120fbconfig_compare(struct glx_config **a, struct glx_config **b)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001121{
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001122 /* The order of these comparisons must NOT change. It is defined by
Fredrik Höglund3616e862014-02-15 18:48:40 +01001123 * the GLX 1.4 specification.
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001124 */
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001125
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001126 PREFER_SMALLER(visualSelectGroup);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001127
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001128 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1129 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1130 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1131 */
1132 PREFER_SMALLER(visualRating);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001133
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001134 /* This isn't quite right. It is supposed to compare the sum of the
1135 * components the user specifically set minimums for.
1136 */
1137 PREFER_LARGER_OR_ZERO(redBits);
1138 PREFER_LARGER_OR_ZERO(greenBits);
1139 PREFER_LARGER_OR_ZERO(blueBits);
1140 PREFER_LARGER_OR_ZERO(alphaBits);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001141
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001142 PREFER_SMALLER(rgbBits);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001143
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001144 if (((*a)->doubleBufferMode != (*b)->doubleBufferMode)) {
1145 /* Prefer single-buffer.
1146 */
1147 return (!(*a)->doubleBufferMode) ? -1 : 1;
1148 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001149
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001150 PREFER_SMALLER(numAuxBuffers);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001151
Fredrik Höglund3616e862014-02-15 18:48:40 +01001152 PREFER_SMALLER(sampleBuffers);
1153 PREFER_SMALLER(samples);
1154
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001155 PREFER_LARGER_OR_ZERO(depthBits);
1156 PREFER_SMALLER(stencilBits);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001157
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001158 /* This isn't quite right. It is supposed to compare the sum of the
1159 * components the user specifically set minimums for.
1160 */
1161 PREFER_LARGER_OR_ZERO(accumRedBits);
1162 PREFER_LARGER_OR_ZERO(accumGreenBits);
1163 PREFER_LARGER_OR_ZERO(accumBlueBits);
1164 PREFER_LARGER_OR_ZERO(accumAlphaBits);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001165
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001166 PREFER_SMALLER(visualType);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001167
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001168 /* None of the pbuffer or fbconfig specs say that this comparison needs
1169 * to happen at all, but it seems like it should.
1170 */
1171 PREFER_LARGER(maxPbufferWidth);
1172 PREFER_LARGER(maxPbufferHeight);
1173 PREFER_LARGER(maxPbufferPixels);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001174
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001175 return 0;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001176}
1177
1178
1179/**
1180 * Selects and sorts a subset of the supplied configs based on the attributes.
Emil Velikov78a74152016-09-30 11:01:28 +01001181 * This function forms to basis of \c glXChooseFBConfig and
1182 * \c glXChooseFBConfigSGIX.
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001183 *
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001184 * \param configs Array of pointers to possible configs. The elements of
1185 * this array that do not meet the criteria will be set to
1186 * NULL. The remaining elements will be sorted according to
1187 * the various visual / FBConfig selection rules.
1188 * \param num_configs Number of elements in the \c configs array.
1189 * \param attribList Attributes used select from \c configs. This array is
Emil Velikov78a74152016-09-30 11:01:28 +01001190 * terminated by a \c None tag. The array is of the form
1191 * expected by \c glXChooseFBConfig (where every tag has a
1192 * value).
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001193 * \returns The number of valid elements left in \c configs.
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001194 *
Emil Velikov78a74152016-09-30 11:01:28 +01001195 * \sa glXChooseFBConfig, glXChooseFBConfigSGIX
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001196 */
1197static int
Emil Velikov78a74152016-09-30 11:01:28 +01001198choose_fbconfig(struct glx_config ** configs, int num_configs,
1199 const int *attribList)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001200{
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001201 struct glx_config test_config;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001202 int base;
1203 int i;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001204
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001205 /* This is a fairly direct implementation of the selection method
1206 * described by GLX_SGIX_fbconfig. Start by culling out all the
1207 * configs that are not compatible with the selected parameter
1208 * list.
1209 */
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001210
Emil Velikov78a74152016-09-30 11:01:28 +01001211 init_fbconfig_for_chooser(&test_config, GL_TRUE);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001212 __glXInitializeVisualConfigFromTags(&test_config, 512,
1213 (const INT32 *) attribList,
Emil Velikov78a74152016-09-30 11:01:28 +01001214 GL_TRUE, GL_TRUE);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001215
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001216 base = 0;
1217 for (i = 0; i < num_configs; i++) {
1218 if (fbconfigs_compatible(&test_config, configs[i])) {
1219 configs[base] = configs[i];
1220 base++;
1221 }
1222 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001223
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001224 if (base == 0) {
1225 return 0;
1226 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001227
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001228 if (base < num_configs) {
1229 (void) memset(&configs[base], 0, sizeof(void *) * (num_configs - base));
1230 }
1231
1232 /* After the incompatible configs are removed, the resulting
1233 * list is sorted according to the rules set out in the various
1234 * specifications.
1235 */
1236
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001237 qsort(configs, base, sizeof(struct glx_config *),
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001238 (int (*)(const void *, const void *)) fbconfig_compare);
1239 return base;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001240}
1241
1242
1243
1244
1245/*
1246** Return the visual that best matches the template. Return None if no
1247** visual matches the template.
1248*/
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001249_GLX_PUBLIC XVisualInfo *
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001250glXChooseVisual(Display * dpy, int screen, int *attribList)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001251{
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001252 XVisualInfo *visualList = NULL;
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001253 struct glx_display *priv;
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001254 struct glx_screen *psc;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001255 struct glx_config test_config;
1256 struct glx_config *config;
1257 struct glx_config *best_config = NULL;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001258
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001259 /*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001260 ** Get a list of all visuals, return if list is empty
1261 */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001262 if (GetGLXPrivScreenConfig(dpy, screen, &priv, &psc) != Success) {
1263 return None;
1264 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001265
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001266
1267 /*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001268 ** Build a template from the defaults and the attribute list
1269 ** Free visual list and return if an unexpected token is encountered
1270 */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001271 init_fbconfig_for_chooser(&test_config, GL_FALSE);
1272 __glXInitializeVisualConfigFromTags(&test_config, 512,
1273 (const INT32 *) attribList,
1274 GL_TRUE, GL_FALSE);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001275
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001276 /*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001277 ** Eliminate visuals that don't meet minimum requirements
1278 ** Compute a score for those that do
1279 ** Remember which visual, if any, got the highest score
Michel Dänzer46b81b02009-05-12 08:01:22 +02001280 ** If no visual is acceptable, return None
1281 ** Otherwise, create an XVisualInfo list with just the selected X visual
1282 ** and return this.
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001283 */
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001284 for (config = psc->visuals; config != NULL; config = config->next) {
1285 if (fbconfigs_compatible(&test_config, config)
1286 && ((best_config == NULL) ||
1287 (fbconfig_compare (&config, &best_config) < 0))) {
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001288 XVisualInfo visualTemplate;
1289 XVisualInfo *newList;
1290 int i;
Michel Dänzer46b81b02009-05-12 08:01:22 +02001291
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001292 visualTemplate.screen = screen;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001293 visualTemplate.visualid = config->visualID;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001294 newList = XGetVisualInfo(dpy, VisualScreenMask | VisualIDMask,
1295 &visualTemplate, &i);
Michel Dänzer46b81b02009-05-12 08:01:22 +02001296
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001297 if (newList) {
Matt Turner7c7b7b02012-09-04 22:52:36 -07001298 free(visualList);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001299 visualList = newList;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001300 best_config = config;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001301 }
1302 }
1303 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001304
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07001305#ifdef GLX_USE_APPLEGL
Eric Engestrom3fdbc462017-09-08 11:56:02 +01001306 if(visualList && env_var_as_boolean("LIBGL_DUMP_VISUALID", false)) {
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07001307 printf("visualid 0x%lx\n", visualList[0].visualid);
1308 }
1309#endif
1310
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001311 return visualList;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001312}
1313
1314
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001315_GLX_PUBLIC const char *
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001316glXQueryExtensionsString(Display * dpy, int screen)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001317{
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001318 struct glx_screen *psc;
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001319 struct glx_display *priv;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001320
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001321 if (GetGLXPrivScreenConfig(dpy, screen, &priv, &psc) != Success) {
1322 return NULL;
1323 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001324
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001325 if (!psc->effectiveGLXexts) {
1326 if (!psc->serverGLXexts) {
1327 psc->serverGLXexts =
1328 __glXQueryServerString(dpy, priv->majorOpcode, screen,
1329 GLX_EXTENSIONS);
1330 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001331
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001332 __glXCalculateUsableExtensions(psc,
Jeremy Huddleston80b280d2010-04-02 01:35:19 -07001333#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001334 (psc->driScreen != NULL),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001335#else
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001336 GL_FALSE,
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001337#endif
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001338 priv->minorVersion);
1339 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001340
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001341 return psc->effectiveGLXexts;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001342}
1343
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001344_GLX_PUBLIC const char *
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001345glXGetClientString(Display * dpy, int name)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001346{
Ian Romanick26b2bee2010-02-04 15:47:54 -08001347 (void) dpy;
1348
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001349 switch (name) {
1350 case GLX_VENDOR:
1351 return (__glXGLXClientVendorName);
1352 case GLX_VERSION:
1353 return (__glXGLXClientVersion);
1354 case GLX_EXTENSIONS:
1355 return (__glXGetClientExtensions());
1356 default:
1357 return NULL;
1358 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001359}
1360
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001361_GLX_PUBLIC const char *
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001362glXQueryServerString(Display * dpy, int screen, int name)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001363{
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001364 struct glx_screen *psc;
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001365 struct glx_display *priv;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001366 const char **str;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001367
1368
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001369 if (GetGLXPrivScreenConfig(dpy, screen, &priv, &psc) != Success) {
1370 return NULL;
1371 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001372
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001373 switch (name) {
1374 case GLX_VENDOR:
1375 str = &priv->serverGLXvendor;
1376 break;
1377 case GLX_VERSION:
1378 str = &priv->serverGLXversion;
1379 break;
1380 case GLX_EXTENSIONS:
1381 str = &psc->serverGLXexts;
1382 break;
1383 default:
1384 return NULL;
1385 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001386
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001387 if (*str == NULL) {
1388 *str = __glXQueryServerString(dpy, priv->majorOpcode, screen, name);
1389 }
1390
1391 return *str;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001392}
1393
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001394
1395/*
1396** EXT_import_context
1397*/
1398
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001399_GLX_PUBLIC Display *
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001400glXGetCurrentDisplay(void)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001401{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001402 struct glx_context *gc = __glXGetCurrentContext();
Bernard Kilarski2e3f0672016-06-07 13:33:33 +03001403 if (gc == &dummyContext)
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001404 return NULL;
1405 return gc->currentDpy;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001406}
1407
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001408_GLX_PUBLIC
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001409GLX_ALIAS(Display *, glXGetCurrentDisplayEXT, (void), (),
1410 glXGetCurrentDisplay)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001411
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07001412#ifndef GLX_USE_APPLEGL
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001413_GLX_PUBLIC GLXContext
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001414glXImportContextEXT(Display *dpy, GLXContextID contextID)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001415{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001416 struct glx_display *priv = __glXInitialize(dpy);
Ian Romanick5a849e82011-12-07 11:15:14 -08001417 struct glx_screen *psc = NULL;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001418 xGLXQueryContextReply reply;
1419 CARD8 opcode;
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001420 struct glx_context *ctx;
Adam Jackson08521622017-09-26 16:38:31 -04001421 int i, renderType = GLX_RGBA_TYPE; /* By default, assume RGBA context */
1422 XID share = None;
1423 struct glx_config *mode = NULL;
Ian Romanick5a849e82011-12-07 11:15:14 -08001424 uint32_t fbconfigID = 0;
1425 uint32_t visualID = 0;
Brian Paul622b1fc2013-03-13 08:35:21 -06001426 uint32_t screen = 0;
Ian Romanick5a849e82011-12-07 11:15:14 -08001427 Bool got_screen = False;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001428
Juha-Pekka Heikkilad28e92f2014-02-07 14:43:57 +02001429 if (priv == NULL)
1430 return NULL;
1431
Ian Romanicked4a65c2011-12-07 16:13:02 -08001432 /* The GLX_EXT_import_context spec says:
1433 *
1434 * "If <contextID> does not refer to a valid context, then a BadContext
1435 * error is generated; if <contextID> refers to direct rendering
1436 * context then no error is generated but glXImportContextEXT returns
1437 * NULL."
1438 *
1439 * If contextID is None, generate BadContext on the client-side. Other
1440 * sorts of invalid contexts will be detected by the server in the
1441 * __glXIsDirect call.
1442 */
1443 if (contextID == None) {
1444 __glXSendError(dpy, GLXBadContext, contextID, X_GLXIsDirect, false);
1445 return NULL;
1446 }
1447
Adam Jackson16f10232018-08-07 16:55:37 -04001448 if (__glXIsDirect(dpy, contextID, NULL))
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001449 return NULL;
1450
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001451 opcode = __glXSetupForCommand(dpy);
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001452 if (!opcode)
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001453 return 0;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001454
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001455 /* Send the glXQueryContextInfoEXT request */
1456 LockDisplay(dpy);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001457
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001458 if (priv->majorVersion > 1 || priv->minorVersion >= 3) {
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001459 xGLXQueryContextReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001460
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001461 GetReq(GLXQueryContext, req);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001462
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001463 req->reqType = opcode;
1464 req->glxCode = X_GLXQueryContext;
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001465 req->context = contextID;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001466 }
1467 else {
1468 xGLXVendorPrivateReq *vpreq;
1469 xGLXQueryContextInfoEXTReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001470
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001471 GetReqExtra(GLXVendorPrivate,
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001472 sz_xGLXQueryContextInfoEXTReq - sz_xGLXVendorPrivateReq,
1473 vpreq);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001474 req = (xGLXQueryContextInfoEXTReq *) vpreq;
1475 req->reqType = opcode;
1476 req->glxCode = X_GLXVendorPrivateWithReply;
1477 req->vendorCode = X_GLXvop_QueryContextInfoEXT;
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001478 req->context = contextID;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001479 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001480
Adam Jackson08521622017-09-26 16:38:31 -04001481 if (_XReply(dpy, (xReply *) & reply, 0, False) &&
1482 reply.n < (INT32_MAX / 2)) {
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001483
Michel Dänzer6b8f3722018-06-01 18:59:36 +02001484 for (i = 0; i < reply.n; i++) {
Adam Jackson08521622017-09-26 16:38:31 -04001485 int prop[2];
1486
1487 _XRead(dpy, (char *)prop, sizeof(prop));
1488 switch (prop[0]) {
1489 case GLX_SCREEN:
1490 screen = prop[1];
1491 got_screen = True;
1492 break;
1493 case GLX_SHARE_CONTEXT_EXT:
1494 share = prop[1];
1495 break;
1496 case GLX_VISUAL_ID_EXT:
1497 visualID = prop[1];
1498 break;
1499 case GLX_FBCONFIG_ID:
1500 fbconfigID = prop[1];
1501 break;
1502 case GLX_RENDER_TYPE:
1503 renderType = prop[1];
1504 break;
1505 }
1506 }
1507 }
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001508 UnlockDisplay(dpy);
1509 SyncHandle();
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001510
Ian Romanick5a849e82011-12-07 11:15:14 -08001511 if (!got_screen)
1512 return NULL;
1513
1514 psc = GetGLXScreenConfigs(dpy, screen);
1515 if (psc == NULL)
1516 return NULL;
1517
1518 if (fbconfigID != 0) {
1519 mode = glx_config_find_fbconfig(psc->configs, fbconfigID);
1520 } else if (visualID != 0) {
1521 mode = glx_config_find_visual(psc->visuals, visualID);
1522 }
1523
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001524 if (mode == NULL)
1525 return NULL;
1526
1527 ctx = indirect_create_context(psc, mode, NULL, renderType);
1528 if (ctx == NULL)
1529 return NULL;
1530
1531 ctx->xid = contextID;
1532 ctx->imported = GL_TRUE;
1533 ctx->share_xid = share;
1534
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001535 return (GLXContext) ctx;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001536}
1537
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07001538#endif
1539
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001540_GLX_PUBLIC int
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001541glXQueryContext(Display * dpy, GLXContext ctx_user, int attribute, int *value)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001542{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001543 struct glx_context *ctx = (struct glx_context *) ctx_user;
1544
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001545 switch (attribute) {
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07001546 case GLX_SHARE_CONTEXT_EXT:
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001547 *value = ctx->share_xid;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001548 break;
1549 case GLX_VISUAL_ID_EXT:
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001550 *value = ctx->config ? ctx->config->visualID : None;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001551 break;
1552 case GLX_SCREEN:
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001553 *value = ctx->screen;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001554 break;
1555 case GLX_FBCONFIG_ID:
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001556 *value = ctx->config ? ctx->config->fbconfigID : None;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001557 break;
1558 case GLX_RENDER_TYPE:
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001559 *value = ctx->renderType;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001560 break;
1561 default:
1562 return GLX_BAD_ATTRIBUTE;
1563 }
1564 return Success;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001565}
1566
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001567_GLX_PUBLIC
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001568GLX_ALIAS(int, glXQueryContextInfoEXT,
1569 (Display * dpy, GLXContext ctx, int attribute, int *value),
1570 (dpy, ctx, attribute, value), glXQueryContext)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001571
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001572_GLX_PUBLIC GLXContextID glXGetContextIDEXT(const GLXContext ctx_user)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001573{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001574 struct glx_context *ctx = (struct glx_context *) ctx_user;
1575
Ian Romanick3b9b4222011-12-07 11:37:01 -08001576 return (ctx == NULL) ? None : ctx->xid;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001577}
1578
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001579_GLX_PUBLIC void
Ian Romanick4dbd13c2011-12-07 13:31:27 -08001580glXFreeContextEXT(Display *dpy, GLXContext ctx)
1581{
1582 struct glx_context *gc = (struct glx_context *) ctx;
1583
1584 if (gc == NULL || gc->xid == None)
1585 return;
1586
1587 /* The GLX_EXT_import_context spec says:
1588 *
1589 * "glXFreeContext does not free the server-side context information or
1590 * the XID associated with the server-side context."
1591 *
1592 * Don't send any protocol. Just destroy the client-side tracking of the
1593 * context. Also, only release the context structure if it's not current.
1594 */
1595 __glXLock();
1596 if (gc->currentDpy) {
1597 gc->xid = None;
1598 } else {
1599 gc->vtable->destroy(gc);
1600 }
1601 __glXUnlock();
1602}
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001603
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001604_GLX_PUBLIC GLXFBConfig *
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001605glXChooseFBConfig(Display * dpy, int screen,
1606 const int *attribList, int *nitems)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001607{
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001608 struct glx_config **config_list;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001609 int list_size;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001610
1611
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001612 config_list = (struct glx_config **)
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001613 glXGetFBConfigs(dpy, screen, &list_size);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001614
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001615 if ((config_list != NULL) && (list_size > 0) && (attribList != NULL)) {
Emil Velikov78a74152016-09-30 11:01:28 +01001616 list_size = choose_fbconfig(config_list, list_size, attribList);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001617 if (list_size == 0) {
Matt Turner7c7b7b02012-09-04 22:52:36 -07001618 free(config_list);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001619 config_list = NULL;
1620 }
1621 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001622
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001623 *nitems = list_size;
1624 return (GLXFBConfig *) config_list;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001625}
1626
1627
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001628_GLX_PUBLIC GLXContext
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001629glXCreateNewContext(Display * dpy, GLXFBConfig fbconfig,
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001630 int renderType, GLXContext shareList, Bool allowDirect)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001631{
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001632 struct glx_config *config = (struct glx_config *) fbconfig;
Daniel Czarnowskicf804b42016-02-10 09:36:05 -08001633 struct glx_config **config_list;
1634 int list_size;
1635 unsigned i;
1636
1637 if (!config) {
1638 __glXSendError(dpy, GLXBadFBConfig, 0, X_GLXCreateNewContext, false);
1639 return NULL;
1640 }
1641
1642 config_list = (struct glx_config **)
Mario Kleiner0c94ed02016-10-11 20:42:03 +02001643 glXGetFBConfigs(dpy, config->screen, &list_size);
Daniel Czarnowskicf804b42016-02-10 09:36:05 -08001644
1645 for (i = 0; i < list_size; i++) {
1646 if (config_list[i] == config)
1647 break;
1648 }
1649 free(config_list);
1650
1651 if (i == list_size) {
1652 __glXSendError(dpy, GLXBadFBConfig, 0, X_GLXCreateNewContext, false);
1653 return NULL;
1654 }
Ian Romanick7bcfb662010-02-04 16:37:59 -08001655
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001656 return CreateContext(dpy, config->fbconfigID, config, shareList,
1657 allowDirect, X_GLXCreateNewContext, renderType,
1658 config->screen);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001659}
1660
1661
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001662_GLX_PUBLIC GLXDrawable
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001663glXGetCurrentReadDrawable(void)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001664{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001665 struct glx_context *gc = __glXGetCurrentContext();
1666
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001667 return gc->currentReadable;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001668}
1669
1670
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001671_GLX_PUBLIC GLXFBConfig *
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001672glXGetFBConfigs(Display * dpy, int screen, int *nelements)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001673{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001674 struct glx_display *priv = __glXInitialize(dpy);
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001675 struct glx_config **config_list = NULL;
1676 struct glx_config *config;
1677 unsigned num_configs = 0;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001678 int i;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001679
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001680 *nelements = 0;
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001681 if (priv && (priv->screens != NULL)
Jiri Slabya6ce91f2016-05-17 08:35:29 +02001682 && (screen >= 0) && (screen < ScreenCount(dpy))
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001683 && (priv->screens[screen]->configs != NULL)
1684 && (priv->screens[screen]->configs->fbconfigID
Ian Romanick71a6fb12010-02-04 15:59:51 -08001685 != (int) GLX_DONT_CARE)) {
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001686
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001687 for (config = priv->screens[screen]->configs; config != NULL;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001688 config = config->next) {
1689 if (config->fbconfigID != (int) GLX_DONT_CARE) {
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001690 num_configs++;
1691 }
1692 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001693
Matt Turner7c7b7b02012-09-04 22:52:36 -07001694 config_list = malloc(num_configs * sizeof *config_list);
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001695 if (config_list != NULL) {
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001696 *nelements = num_configs;
1697 i = 0;
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001698 for (config = priv->screens[screen]->configs; config != NULL;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001699 config = config->next) {
1700 if (config->fbconfigID != (int) GLX_DONT_CARE) {
1701 config_list[i] = config;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001702 i++;
1703 }
1704 }
1705 }
1706 }
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001707
1708 return (GLXFBConfig *) config_list;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001709}
1710
1711
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001712_GLX_PUBLIC int
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001713glXGetFBConfigAttrib(Display * dpy, GLXFBConfig fbconfig,
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001714 int attribute, int *value)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001715{
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001716 struct glx_config *config = ValidateGLXFBConfig(dpy, fbconfig);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001717
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001718 if (config == NULL)
1719 return GLXBadFBConfig;
1720
1721 return glx_config_get(config, attribute, value);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001722}
1723
1724
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001725_GLX_PUBLIC XVisualInfo *
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001726glXGetVisualFromFBConfig(Display * dpy, GLXFBConfig fbconfig)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001727{
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001728 XVisualInfo visualTemplate;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001729 struct glx_config *config = (struct glx_config *) fbconfig;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001730 int count;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001731
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001732 /*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001733 ** Get a list of all visuals, return if list is empty
1734 */
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001735 visualTemplate.visualid = config->visualID;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001736 return XGetVisualInfo(dpy, VisualIDMask, &visualTemplate, &count);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001737}
1738
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07001739#ifndef GLX_USE_APPLEGL
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001740/*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001741** GLX_SGI_swap_control
1742*/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001743static int
1744__glXSwapIntervalSGI(int interval)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001745{
1746 xGLXVendorPrivateReq *req;
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001747 struct glx_context *gc = __glXGetCurrentContext();
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001748 struct glx_screen *psc;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001749 Display *dpy;
1750 CARD32 *interval_ptr;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001751 CARD8 opcode;
1752
Bernard Kilarski2e3f0672016-06-07 13:33:33 +03001753 if (gc == &dummyContext) {
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001754 return GLX_BAD_CONTEXT;
1755 }
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001756
1757 if (interval <= 0) {
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001758 return GLX_BAD_VALUE;
1759 }
1760
Jesse Barnesefc82e72009-11-10 13:28:01 -08001761 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
1762
Vinson Lee16f568a2010-04-01 00:10:28 -07001763#ifdef GLX_DIRECT_RENDERING
Juha-Pekka Heikkilad28e92f2014-02-07 14:43:57 +02001764 if (gc->isDirect && psc && psc->driScreen &&
1765 psc->driScreen->setSwapInterval) {
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04001766 __GLXDRIdrawable *pdraw =
1767 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
Nicolai Hähnlef446f3f2017-02-02 18:06:27 +01001768 /* Simply ignore the command if the GLX drawable has been destroyed but
1769 * the context is still bound.
1770 */
1771 if (pdraw)
1772 psc->driScreen->setSwapInterval(pdraw, interval);
Jesse Barnesefc82e72009-11-10 13:28:01 -08001773 return 0;
1774 }
Vinson Lee16f568a2010-04-01 00:10:28 -07001775#endif
Jesse Barnesefc82e72009-11-10 13:28:01 -08001776
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001777 dpy = gc->currentDpy;
1778 opcode = __glXSetupForCommand(dpy);
1779 if (!opcode) {
1780 return 0;
1781 }
1782
1783 /* Send the glXSwapIntervalSGI request */
1784 LockDisplay(dpy);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001785 GetReqExtra(GLXVendorPrivate, sizeof(CARD32), req);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001786 req->reqType = opcode;
1787 req->glxCode = X_GLXVendorPrivate;
1788 req->vendorCode = X_GLXvop_SwapIntervalSGI;
1789 req->contextTag = gc->currentContextTag;
1790
Ian Romanicka70d5642006-08-30 23:15:02 +00001791 interval_ptr = (CARD32 *) (req + 1);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001792 *interval_ptr = interval;
1793
1794 UnlockDisplay(dpy);
1795 SyncHandle();
1796 XFlush(dpy);
1797
1798 return 0;
1799}
1800
1801
1802/*
1803** GLX_MESA_swap_control
1804*/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001805static int
1806__glXSwapIntervalMESA(unsigned int interval)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001807{
Kristian Høgsberg089fc372010-07-19 16:39:53 -04001808#ifdef GLX_DIRECT_RENDERING
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001809 struct glx_context *gc = __glXGetCurrentContext();
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001810
Bernard Kilarski2e3f0672016-06-07 13:33:33 +03001811 if (gc != &dummyContext && gc->isDirect) {
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001812 struct glx_screen *psc;
Jesse Barnesefc82e72009-11-10 13:28:01 -08001813
1814 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
Juha-Pekka Heikkilad28e92f2014-02-07 14:43:57 +02001815 if (psc && psc->driScreen && psc->driScreen->setSwapInterval) {
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04001816 __GLXDRIdrawable *pdraw =
1817 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
Nicolai Hähnlef446f3f2017-02-02 18:06:27 +01001818
1819 /* Simply ignore the command if the GLX drawable has been destroyed but
1820 * the context is still bound.
1821 */
1822 if (!pdraw)
1823 return 0;
1824
1825 return psc->driScreen->setSwapInterval(pdraw, interval);
Jesse Barnesefc82e72009-11-10 13:28:01 -08001826 }
1827 }
Vinson Lee16f568a2010-04-01 00:10:28 -07001828#endif
Jesse Barnesefc82e72009-11-10 13:28:01 -08001829
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001830 return GLX_BAD_CONTEXT;
1831}
Brian Paul841a8232006-03-09 16:25:46 +00001832
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001833
1834static int
1835__glXGetSwapIntervalMESA(void)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001836{
Kristian Høgsberg089fc372010-07-19 16:39:53 -04001837#ifdef GLX_DIRECT_RENDERING
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001838 struct glx_context *gc = __glXGetCurrentContext();
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001839
Bernard Kilarski2e3f0672016-06-07 13:33:33 +03001840 if (gc != &dummyContext && gc->isDirect) {
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001841 struct glx_screen *psc;
Jesse Barnesefc82e72009-11-10 13:28:01 -08001842
1843 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
Juha-Pekka Heikkilad28e92f2014-02-07 14:43:57 +02001844 if (psc && psc->driScreen && psc->driScreen->getSwapInterval) {
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04001845 __GLXDRIdrawable *pdraw =
1846 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
Nicolai Hähnlef446f3f2017-02-02 18:06:27 +01001847 if (pdraw)
1848 return psc->driScreen->getSwapInterval(pdraw);
Jesse Barnesefc82e72009-11-10 13:28:01 -08001849 }
1850 }
Vinson Lee67776f62010-04-02 00:12:59 -07001851#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001852
1853 return 0;
1854}
1855
1856
1857/*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001858** GLX_SGI_video_sync
1859*/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001860static int
1861__glXGetVideoSyncSGI(unsigned int *count)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001862{
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001863 int64_t ust, msc, sbc;
1864 int ret;
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001865 struct glx_context *gc = __glXGetCurrentContext();
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001866 struct glx_screen *psc;
Vinson Lee67776f62010-04-02 00:12:59 -07001867#ifdef GLX_DIRECT_RENDERING
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001868 __GLXDRIdrawable *pdraw;
Vinson Lee67776f62010-04-02 00:12:59 -07001869#endif
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001870
Bernard Kilarski2e3f0672016-06-07 13:33:33 +03001871 if (gc == &dummyContext)
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001872 return GLX_BAD_CONTEXT;
1873
Vinson Lee16f568a2010-04-01 00:10:28 -07001874#ifdef GLX_DIRECT_RENDERING
Kristian Høgsbergc491e582010-07-28 15:33:09 -04001875 if (!gc->isDirect)
Vinson Lee16f568a2010-04-01 00:10:28 -07001876 return GLX_BAD_CONTEXT;
1877#endif
1878
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001879 psc = GetGLXScreenConfigs(gc->currentDpy, gc->screen);
Vinson Lee67776f62010-04-02 00:12:59 -07001880#ifdef GLX_DIRECT_RENDERING
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04001881 pdraw = GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
Vinson Lee67776f62010-04-02 00:12:59 -07001882#endif
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001883
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001884 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1885 * FIXME: there should be a GLX encoding for this call. I can find no
1886 * FIXME: documentation for the GLX encoding.
1887 */
Vinson Lee67776f62010-04-02 00:12:59 -07001888#ifdef GLX_DIRECT_RENDERING
Juha-Pekka Heikkilad28e92f2014-02-07 14:43:57 +02001889 if (psc && psc->driScreen && psc->driScreen->getDrawableMSC) {
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001890 ret = psc->driScreen->getDrawableMSC(psc, pdraw, &ust, &msc, &sbc);
1891 *count = (unsigned) msc;
1892 return (ret == True) ? 0 : GLX_BAD_CONTEXT;
1893 }
Vinson Lee67776f62010-04-02 00:12:59 -07001894#endif
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001895
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001896 return GLX_BAD_CONTEXT;
1897}
1898
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001899static int
1900__glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001901{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001902 struct glx_context *gc = __glXGetCurrentContext();
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001903 struct glx_screen *psc;
Vinson Lee67776f62010-04-02 00:12:59 -07001904#ifdef GLX_DIRECT_RENDERING
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001905 __GLXDRIdrawable *pdraw;
Vinson Lee67776f62010-04-02 00:12:59 -07001906#endif
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001907 int64_t ust, msc, sbc;
1908 int ret;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001909
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001910 if (divisor <= 0 || remainder < 0)
1911 return GLX_BAD_VALUE;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001912
Bernard Kilarski2e3f0672016-06-07 13:33:33 +03001913 if (gc == &dummyContext)
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001914 return GLX_BAD_CONTEXT;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001915
Vinson Lee16f568a2010-04-01 00:10:28 -07001916#ifdef GLX_DIRECT_RENDERING
Kristian Høgsbergc491e582010-07-28 15:33:09 -04001917 if (!gc->isDirect)
Vinson Lee16f568a2010-04-01 00:10:28 -07001918 return GLX_BAD_CONTEXT;
1919#endif
1920
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001921 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
Vinson Lee67776f62010-04-02 00:12:59 -07001922#ifdef GLX_DIRECT_RENDERING
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04001923 pdraw = GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
Vinson Lee67776f62010-04-02 00:12:59 -07001924#endif
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001925
Vinson Lee67776f62010-04-02 00:12:59 -07001926#ifdef GLX_DIRECT_RENDERING
Juha-Pekka Heikkilad28e92f2014-02-07 14:43:57 +02001927 if (psc && psc->driScreen && psc->driScreen->waitForMSC) {
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001928 ret = psc->driScreen->waitForMSC(pdraw, 0, divisor, remainder, &ust, &msc,
1929 &sbc);
1930 *count = (unsigned) msc;
1931 return (ret == True) ? 0 : GLX_BAD_CONTEXT;
1932 }
Vinson Lee67776f62010-04-02 00:12:59 -07001933#endif
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001934
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001935 return GLX_BAD_CONTEXT;
1936}
1937
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07001938#endif /* GLX_USE_APPLEGL */
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001939
1940/*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001941** GLX_SGIX_fbconfig
1942** Many of these functions are aliased to GLX 1.3 entry points in the
1943** GLX_functions table.
1944*/
1945
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001946_GLX_PUBLIC
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001947GLX_ALIAS(int, glXGetFBConfigAttribSGIX,
1948 (Display * dpy, GLXFBConfigSGIX config, int attribute, int *value),
1949 (dpy, config, attribute, value), glXGetFBConfigAttrib)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001950
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001951_GLX_PUBLIC GLX_ALIAS(GLXFBConfigSGIX *, glXChooseFBConfigSGIX,
Brian Paulef9cd842009-09-29 09:58:47 -06001952 (Display * dpy, int screen, int *attrib_list,
1953 int *nelements), (dpy, screen, attrib_list, nelements),
1954 glXChooseFBConfig)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001955
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001956_GLX_PUBLIC GLX_ALIAS(XVisualInfo *, glXGetVisualFromFBConfigSGIX,
Brian Paulef9cd842009-09-29 09:58:47 -06001957 (Display * dpy, GLXFBConfigSGIX config),
1958 (dpy, config), glXGetVisualFromFBConfig)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001959
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001960_GLX_PUBLIC GLXPixmap
Brian Paulef9cd842009-09-29 09:58:47 -06001961glXCreateGLXPixmapWithConfigSGIX(Display * dpy,
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001962 GLXFBConfigSGIX fbconfig,
Brian Paulef9cd842009-09-29 09:58:47 -06001963 Pixmap pixmap)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001964{
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07001965#ifndef GLX_USE_APPLEGL
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001966 xGLXVendorPrivateWithReplyReq *vpreq;
1967 xGLXCreateGLXPixmapWithConfigSGIXReq *req;
1968 GLXPixmap xid = None;
1969 CARD8 opcode;
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001970 struct glx_screen *psc;
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07001971#endif
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001972 struct glx_config *config = (struct glx_config *) fbconfig;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001973
1974
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001975 if ((dpy == NULL) || (config == NULL)) {
1976 return None;
1977 }
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07001978#ifdef GLX_USE_APPLEGL
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001979 if(apple_glx_pixmap_create(dpy, config->screen, pixmap, config))
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07001980 return None;
1981 return pixmap;
1982#else
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001983
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001984 psc = GetGLXScreenConfigs(dpy, config->screen);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001985 if ((psc != NULL)
1986 && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)) {
1987 opcode = __glXSetupForCommand(dpy);
1988 if (!opcode) {
1989 return None;
1990 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001991
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001992 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
1993 LockDisplay(dpy);
1994 GetReqExtra(GLXVendorPrivateWithReply,
1995 sz_xGLXCreateGLXPixmapWithConfigSGIXReq -
1996 sz_xGLXVendorPrivateWithReplyReq, vpreq);
1997 req = (xGLXCreateGLXPixmapWithConfigSGIXReq *) vpreq;
1998 req->reqType = opcode;
1999 req->glxCode = X_GLXVendorPrivateWithReply;
2000 req->vendorCode = X_GLXvop_CreateGLXPixmapWithConfigSGIX;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04002001 req->screen = config->screen;
2002 req->fbconfig = config->fbconfigID;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002003 req->pixmap = pixmap;
2004 req->glxpixmap = xid = XAllocID(dpy);
2005 UnlockDisplay(dpy);
2006 SyncHandle();
2007 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002008
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002009 return xid;
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07002010#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002011}
2012
Kyle Brenneman22a9e002016-05-11 14:01:53 -04002013_GLX_PUBLIC GLXContext
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002014glXCreateContextWithConfigSGIX(Display * dpy,
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04002015 GLXFBConfigSGIX fbconfig, int renderType,
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002016 GLXContext shareList, Bool allowDirect)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002017{
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002018 GLXContext gc = NULL;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04002019 struct glx_config *config = (struct glx_config *) fbconfig;
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04002020 struct glx_screen *psc;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002021
2022
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002023 if ((dpy == NULL) || (config == NULL)) {
2024 return None;
2025 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002026
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04002027 psc = GetGLXScreenConfigs(dpy, config->screen);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002028 if ((psc != NULL)
2029 && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)) {
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04002030 gc = CreateContext(dpy, config->fbconfigID, config, shareList,
Ian Romanick22430292010-02-04 16:43:46 -08002031 allowDirect,
Ian Romanick7bcfb662010-02-04 16:37:59 -08002032 X_GLXvop_CreateContextWithConfigSGIX, renderType,
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04002033 config->screen);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002034 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002035
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002036 return gc;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002037}
2038
2039
Kyle Brenneman22a9e002016-05-11 14:01:53 -04002040_GLX_PUBLIC GLXFBConfigSGIX
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002041glXGetFBConfigFromVisualSGIX(Display * dpy, XVisualInfo * vis)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002042{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04002043 struct glx_display *priv;
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04002044 struct glx_screen *psc = NULL;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002045
Stéphane Marchesinfc48de42011-05-26 17:19:03 -07002046 if ((GetGLXPrivScreenConfig(dpy, vis->screen, &priv, &psc) == Success)
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002047 && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)
Ian Romanick71a6fb12010-02-04 15:59:51 -08002048 && (psc->configs->fbconfigID != (int) GLX_DONT_CARE)) {
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04002049 return (GLXFBConfigSGIX) glx_config_find_visual(psc->configs,
2050 vis->visualid);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002051 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002052
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002053 return NULL;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002054}
2055
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07002056#ifndef GLX_USE_APPLEGL
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002057/*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002058** GLX_OML_sync_control
2059*/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002060static Bool
2061__glXGetSyncValuesOML(Display * dpy, GLXDrawable drawable,
2062 int64_t * ust, int64_t * msc, int64_t * sbc)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002063{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04002064 struct glx_display * const priv = __glXInitialize(dpy);
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04002065 int ret;
Vinson Lee67776f62010-04-02 00:12:59 -07002066#ifdef GLX_DIRECT_RENDERING
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07002067 __GLXDRIdrawable *pdraw;
Vinson Lee67776f62010-04-02 00:12:59 -07002068#endif
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04002069 struct glx_screen *psc;
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07002070
2071 if (!priv)
2072 return False;
2073
Vinson Lee67776f62010-04-02 00:12:59 -07002074#ifdef GLX_DIRECT_RENDERING
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04002075 pdraw = GetGLXDRIDrawable(dpy, drawable);
2076 psc = pdraw ? pdraw->psc : NULL;
2077 if (pdraw && psc->driScreen->getDrawableMSC) {
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07002078 ret = psc->driScreen->getDrawableMSC(psc, pdraw, ust, msc, sbc);
2079 return ret;
2080 }
Vinson Lee67776f62010-04-02 00:12:59 -07002081#endif
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07002082
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002083 return False;
2084}
2085
Jon Turneyd512b352018-12-14 13:20:10 +00002086#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
Kristian Høgsberg3d28a262008-03-08 22:28:01 -05002087_X_HIDDEN GLboolean
Lauri Kasanenfe2079c2013-12-15 12:37:55 +02002088__glxGetMscRate(struct glx_screen *psc,
Kristian Høgsberg7a66e542010-07-21 14:09:49 -04002089 int32_t * numerator, int32_t * denominator)
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002090{
Jon Turneyd512b352018-12-14 13:20:10 +00002091#if !defined(GLX_USE_WINDOWSGL)
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002092 XF86VidModeModeLine mode_line;
2093 int dot_clock;
2094 int i;
Ian Romanick26b2bee2010-02-04 15:47:54 -08002095
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002096 if (XF86VidModeQueryVersion(psc->dpy, &i, &i) &&
2097 XF86VidModeGetModeLine(psc->dpy, psc->scr, &dot_clock, &mode_line)) {
2098 unsigned n = dot_clock * 1000;
2099 unsigned d = mode_line.vtotal * mode_line.htotal;
2100
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002101# define V_INTERLACE 0x010
2102# define V_DBLSCAN 0x020
2103
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002104 if (mode_line.flags & V_INTERLACE)
2105 n *= 2;
2106 else if (mode_line.flags & V_DBLSCAN)
2107 d *= 2;
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002108
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002109 /* The OML_sync_control spec requires that if the refresh rate is a
2110 * whole number, that the returned numerator be equal to the refresh
2111 * rate and the denominator be 1.
2112 */
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002113
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002114 if (n % d == 0) {
2115 n /= d;
2116 d = 1;
2117 }
2118 else {
2119 static const unsigned f[] = { 13, 11, 7, 5, 3, 2, 0 };
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002120
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002121 /* This is a poor man's way to reduce a fraction. It's far from
2122 * perfect, but it will work well enough for this situation.
2123 */
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002124
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002125 for (i = 0; f[i] != 0; i++) {
2126 while (n % f[i] == 0 && d % f[i] == 0) {
2127 d /= f[i];
2128 n /= f[i];
2129 }
2130 }
2131 }
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002132
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002133 *numerator = n;
2134 *denominator = d;
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002135
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002136 return True;
2137 }
Jon Turneyd512b352018-12-14 13:20:10 +00002138#endif
Ian Romanick26b2bee2010-02-04 15:47:54 -08002139
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002140 return False;
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002141}
2142#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002143
2144/**
2145 * Determine the refresh rate of the specified drawable and display.
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002146 *
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002147 * \param dpy Display whose refresh rate is to be determined.
2148 * \param drawable Drawable whose refresh rate is to be determined.
2149 * \param numerator Numerator of the refresh rate.
2150 * \param demoninator Denominator of the refresh rate.
2151 * \return If the refresh rate for the specified display and drawable could
2152 * be calculated, True is returned. Otherwise False is returned.
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002153 *
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002154 * \note This function is implemented entirely client-side. A lot of other
2155 * functionality is required to export GLX_OML_sync_control, so on
2156 * XFree86 this function can be called for direct-rendering contexts
2157 * when GLX_OML_sync_control appears in the client extension string.
2158 */
2159
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002160_X_HIDDEN GLboolean
2161__glXGetMscRateOML(Display * dpy, GLXDrawable drawable,
2162 int32_t * numerator, int32_t * denominator)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002163{
Emil Velikova95ec132018-12-11 16:20:40 +00002164#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) && !defined(GLX_USE_WINDOWSGL)
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04002165 __GLXDRIdrawable *draw = GetGLXDRIDrawable(dpy, drawable);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002166
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002167 if (draw == NULL)
2168 return False;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002169
Lauri Kasanenfe2079c2013-12-15 12:37:55 +02002170 return __glxGetMscRate(draw->psc, numerator, denominator);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002171#else
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002172 (void) dpy;
2173 (void) drawable;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002174 (void) numerator;
2175 (void) denominator;
2176#endif
2177 return False;
2178}
2179
2180
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002181static int64_t
2182__glXSwapBuffersMscOML(Display * dpy, GLXDrawable drawable,
2183 int64_t target_msc, int64_t divisor, int64_t remainder)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002184{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04002185 struct glx_context *gc = __glXGetCurrentContext();
Vinson Lee67776f62010-04-02 00:12:59 -07002186#ifdef GLX_DIRECT_RENDERING
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04002187 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04002188 struct glx_screen *psc = pdraw ? pdraw->psc : NULL;
Vinson Lee67776f62010-04-02 00:12:59 -07002189#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002190
Bernard Kilarski2e3f0672016-06-07 13:33:33 +03002191 if (gc == &dummyContext) /* no GLX for this */
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07002192 return -1;
2193
Vinson Lee16f568a2010-04-01 00:10:28 -07002194#ifdef GLX_DIRECT_RENDERING
Kristian Høgsbergc491e582010-07-28 15:33:09 -04002195 if (!pdraw || !gc->isDirect)
Vinson Lee16f568a2010-04-01 00:10:28 -07002196 return -1;
2197#endif
2198
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002199 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2200 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2201 * of -1 if the function failed because of errors detected in the input
2202 * parameters"
2203 */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002204 if (divisor < 0 || remainder < 0 || target_msc < 0)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002205 return -1;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002206 if (divisor > 0 && remainder >= divisor)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002207 return -1;
2208
Jesse Barnes8f4f2a02010-03-22 16:39:11 -07002209 if (target_msc == 0 && divisor == 0 && remainder == 0)
2210 remainder = 1;
2211
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07002212#ifdef GLX_DIRECT_RENDERING
2213 if (psc->driScreen && psc->driScreen->swapBuffers)
2214 return (*psc->driScreen->swapBuffers)(pdraw, target_msc, divisor,
Marek Olšák5b7e9b72012-11-13 17:06:37 +01002215 remainder, False);
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07002216#endif
2217
2218 return -1;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002219}
2220
2221
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002222static Bool
2223__glXWaitForMscOML(Display * dpy, GLXDrawable drawable,
2224 int64_t target_msc, int64_t divisor,
2225 int64_t remainder, int64_t * ust,
2226 int64_t * msc, int64_t * sbc)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002227{
Vinson Lee67776f62010-04-02 00:12:59 -07002228#ifdef GLX_DIRECT_RENDERING
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04002229 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04002230 struct glx_screen *psc = pdraw ? pdraw->psc : NULL;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002231 int ret;
Jon TURNEYae9487c2010-08-09 14:47:26 +01002232#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002233
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07002234
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002235 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2236 * error", but the return type in the spec is Bool.
2237 */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002238 if (divisor < 0 || remainder < 0 || target_msc < 0)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002239 return False;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002240 if (divisor > 0 && remainder >= divisor)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002241 return False;
2242
Vinson Lee67776f62010-04-02 00:12:59 -07002243#ifdef GLX_DIRECT_RENDERING
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07002244 if (pdraw && psc->driScreen && psc->driScreen->waitForMSC) {
2245 ret = psc->driScreen->waitForMSC(pdraw, target_msc, divisor, remainder,
2246 ust, msc, sbc);
2247 return ret;
2248 }
Vinson Lee67776f62010-04-02 00:12:59 -07002249#endif
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07002250
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002251 return False;
2252}
2253
2254
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002255static Bool
2256__glXWaitForSbcOML(Display * dpy, GLXDrawable drawable,
2257 int64_t target_sbc, int64_t * ust,
2258 int64_t * msc, int64_t * sbc)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002259{
Vinson Lee67776f62010-04-02 00:12:59 -07002260#ifdef GLX_DIRECT_RENDERING
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04002261 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04002262 struct glx_screen *psc = pdraw ? pdraw->psc : NULL;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002263 int ret;
Jon TURNEYae9487c2010-08-09 14:47:26 +01002264#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002265
2266 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2267 * error", but the return type in the spec is Bool.
2268 */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002269 if (target_sbc < 0)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002270 return False;
Vinson Lee67776f62010-04-02 00:12:59 -07002271
2272#ifdef GLX_DIRECT_RENDERING
kleinerm251bf292010-02-19 12:28:26 -08002273 if (pdraw && psc->driScreen && psc->driScreen->waitForSBC) {
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07002274 ret = psc->driScreen->waitForSBC(pdraw, target_sbc, ust, msc, sbc);
2275 return ret;
2276 }
Vinson Lee67776f62010-04-02 00:12:59 -07002277#endif
2278
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002279 return False;
2280}
2281
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002282/*@}*/
2283
2284
2285/**
2286 * Mesa extension stubs. These will help reduce portability problems.
2287 */
2288/*@{*/
2289
2290/**
2291 * Release all buffers associated with the specified GLX drawable.
2292 *
2293 * \todo
2294 * This function was intended for stand-alone Mesa. The issue there is that
2295 * the library doesn't get any notification when a window is closed. In
2296 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2297 * supported, there are 3 different functions to destroy a drawable. It
2298 * should be possible to create GLX protocol (or have it determine which
2299 * protocol to use based on the type of the drawable) to have one function
2300 * do the work of 3. For the direct-rendering case, this function could
2301 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2302 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2303 * would need to be used. This really should be done as part of the new DRI
2304 * interface work.
2305 *
2306 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2307 * __driGarbageCollectDrawables
2308 * glXDestroyGLXPixmap
2309 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2310 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2311 */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002312static Bool
2313__glXReleaseBuffersMESA(Display * dpy, GLXDrawable d)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002314{
2315 (void) dpy;
2316 (void) d;
2317 return False;
2318}
2319
2320
Kyle Brenneman22a9e002016-05-11 14:01:53 -04002321_GLX_PUBLIC GLXPixmap
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002322glXCreateGLXPixmapMESA(Display * dpy, XVisualInfo * visual,
2323 Pixmap pixmap, Colormap cmap)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002324{
2325 (void) dpy;
2326 (void) visual;
2327 (void) pixmap;
2328 (void) cmap;
2329 return 0;
2330}
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002331
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002332/*@}*/
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002333
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002334
2335/**
2336 * GLX_MESA_copy_sub_buffer
2337 */
Brian Paulf2ad1b62006-03-31 15:48:04 +00002338#define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002339static void
2340__glXCopySubBufferMESA(Display * dpy, GLXDrawable drawable,
2341 int x, int y, int width, int height)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002342{
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002343 xGLXVendorPrivateReq *req;
Kristian Høgsbergc356f582010-07-28 11:16:00 -04002344 struct glx_context *gc;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002345 GLXContextTag tag;
2346 CARD32 *drawable_ptr;
2347 INT32 *x_ptr, *y_ptr, *w_ptr, *h_ptr;
2348 CARD8 opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002349
Kristian Høgsberg2235b1c2010-07-26 15:50:02 -04002350#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04002351 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002352 if (pdraw != NULL) {
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04002353 struct glx_screen *psc = pdraw->psc;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002354 if (psc->driScreen->copySubBuffer != NULL) {
Marek Olšák5b7e9b72012-11-13 17:06:37 +01002355 (*psc->driScreen->copySubBuffer) (pdraw, x, y, width, height, True);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002356 }
Brian Paulf2ad1b62006-03-31 15:48:04 +00002357
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002358 return;
2359 }
Brian Paulf2ad1b62006-03-31 15:48:04 +00002360#endif
2361
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002362 opcode = __glXSetupForCommand(dpy);
2363 if (!opcode)
2364 return;
Brian Paulf2ad1b62006-03-31 15:48:04 +00002365
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002366 /*
Brian Paulf2ad1b62006-03-31 15:48:04 +00002367 ** The calling thread may or may not have a current context. If it
2368 ** does, send the context tag so the server can do a flush.
2369 */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002370 gc = __glXGetCurrentContext();
Bernard Kilarski2e3f0672016-06-07 13:33:33 +03002371 if ((gc != &dummyContext) && (dpy == gc->currentDpy) &&
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002372 ((drawable == gc->currentDrawable) ||
2373 (drawable == gc->currentReadable))) {
2374 tag = gc->currentContextTag;
2375 }
2376 else {
2377 tag = 0;
2378 }
Brian Paulf2ad1b62006-03-31 15:48:04 +00002379
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002380 LockDisplay(dpy);
2381 GetReqExtra(GLXVendorPrivate, sizeof(CARD32) + sizeof(INT32) * 4, req);
2382 req->reqType = opcode;
2383 req->glxCode = X_GLXVendorPrivate;
2384 req->vendorCode = X_GLXvop_CopySubBufferMESA;
2385 req->contextTag = tag;
Brian Paulf2ad1b62006-03-31 15:48:04 +00002386
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002387 drawable_ptr = (CARD32 *) (req + 1);
2388 x_ptr = (INT32 *) (drawable_ptr + 1);
2389 y_ptr = (INT32 *) (drawable_ptr + 2);
2390 w_ptr = (INT32 *) (drawable_ptr + 3);
2391 h_ptr = (INT32 *) (drawable_ptr + 4);
Brian Paulf2ad1b62006-03-31 15:48:04 +00002392
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002393 *drawable_ptr = drawable;
2394 *x_ptr = x;
2395 *y_ptr = y;
2396 *w_ptr = width;
2397 *h_ptr = height;
Brian Paulf2ad1b62006-03-31 15:48:04 +00002398
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002399 UnlockDisplay(dpy);
2400 SyncHandle();
Brian Paulf2ad1b62006-03-31 15:48:04 +00002401}
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002402
Kristian Høgsberg643b2af2010-05-21 10:36:56 -04002403/*@{*/
2404static void
2405__glXBindTexImageEXT(Display * dpy,
2406 GLXDrawable drawable, int buffer, const int *attrib_list)
2407{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04002408 struct glx_context *gc = __glXGetCurrentContext();
Kristian Høgsberg643b2af2010-05-21 10:36:56 -04002409
Adam Jacksonbcb15be2017-11-14 15:13:01 -05002410 if (gc->vtable->bind_tex_image == NULL)
Kristian Høgsberg643b2af2010-05-21 10:36:56 -04002411 return;
2412
2413 gc->vtable->bind_tex_image(dpy, drawable, buffer, attrib_list);
2414}
2415
2416static void
2417__glXReleaseTexImageEXT(Display * dpy, GLXDrawable drawable, int buffer)
2418{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04002419 struct glx_context *gc = __glXGetCurrentContext();
Kristian Høgsberg643b2af2010-05-21 10:36:56 -04002420
Adam Jacksonbcb15be2017-11-14 15:13:01 -05002421 if (gc->vtable->release_tex_image == NULL)
Kristian Høgsberg643b2af2010-05-21 10:36:56 -04002422 return;
2423
2424 gc->vtable->release_tex_image(dpy, drawable, buffer);
2425}
2426
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002427/*@}*/
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002428
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07002429#endif /* GLX_USE_APPLEGL */
2430
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002431/*
2432** glXGetProcAddress support
2433*/
2434
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002435struct name_address_pair
2436{
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002437 const char *Name;
2438 GLvoid *Address;
2439};
2440
2441#define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2442#define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2443
2444static const struct name_address_pair GLX_functions[] = {
2445 /*** GLX_VERSION_1_0 ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002446 GLX_FUNCTION(glXChooseVisual),
2447 GLX_FUNCTION(glXCopyContext),
2448 GLX_FUNCTION(glXCreateContext),
2449 GLX_FUNCTION(glXCreateGLXPixmap),
2450 GLX_FUNCTION(glXDestroyContext),
2451 GLX_FUNCTION(glXDestroyGLXPixmap),
2452 GLX_FUNCTION(glXGetConfig),
2453 GLX_FUNCTION(glXGetCurrentContext),
2454 GLX_FUNCTION(glXGetCurrentDrawable),
2455 GLX_FUNCTION(glXIsDirect),
2456 GLX_FUNCTION(glXMakeCurrent),
2457 GLX_FUNCTION(glXQueryExtension),
2458 GLX_FUNCTION(glXQueryVersion),
2459 GLX_FUNCTION(glXSwapBuffers),
2460 GLX_FUNCTION(glXUseXFont),
2461 GLX_FUNCTION(glXWaitGL),
2462 GLX_FUNCTION(glXWaitX),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002463
2464 /*** GLX_VERSION_1_1 ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002465 GLX_FUNCTION(glXGetClientString),
2466 GLX_FUNCTION(glXQueryExtensionsString),
2467 GLX_FUNCTION(glXQueryServerString),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002468
2469 /*** GLX_VERSION_1_2 ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002470 GLX_FUNCTION(glXGetCurrentDisplay),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002471
2472 /*** GLX_VERSION_1_3 ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002473 GLX_FUNCTION(glXChooseFBConfig),
2474 GLX_FUNCTION(glXCreateNewContext),
2475 GLX_FUNCTION(glXCreatePbuffer),
2476 GLX_FUNCTION(glXCreatePixmap),
2477 GLX_FUNCTION(glXCreateWindow),
2478 GLX_FUNCTION(glXDestroyPbuffer),
2479 GLX_FUNCTION(glXDestroyPixmap),
2480 GLX_FUNCTION(glXDestroyWindow),
2481 GLX_FUNCTION(glXGetCurrentReadDrawable),
2482 GLX_FUNCTION(glXGetFBConfigAttrib),
2483 GLX_FUNCTION(glXGetFBConfigs),
2484 GLX_FUNCTION(glXGetSelectedEvent),
2485 GLX_FUNCTION(glXGetVisualFromFBConfig),
2486 GLX_FUNCTION(glXMakeContextCurrent),
2487 GLX_FUNCTION(glXQueryContext),
2488 GLX_FUNCTION(glXQueryDrawable),
2489 GLX_FUNCTION(glXSelectEvent),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002490
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07002491#ifndef GLX_USE_APPLEGL
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002492 /*** GLX_SGI_swap_control ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002493 GLX_FUNCTION2(glXSwapIntervalSGI, __glXSwapIntervalSGI),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002494
2495 /*** GLX_SGI_video_sync ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002496 GLX_FUNCTION2(glXGetVideoSyncSGI, __glXGetVideoSyncSGI),
2497 GLX_FUNCTION2(glXWaitVideoSyncSGI, __glXWaitVideoSyncSGI),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002498
2499 /*** GLX_SGI_make_current_read ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002500 GLX_FUNCTION2(glXMakeCurrentReadSGI, glXMakeContextCurrent),
2501 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI, glXGetCurrentReadDrawable),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002502
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002503 /*** GLX_EXT_import_context ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002504 GLX_FUNCTION(glXFreeContextEXT),
2505 GLX_FUNCTION(glXGetContextIDEXT),
2506 GLX_FUNCTION2(glXGetCurrentDisplayEXT, glXGetCurrentDisplay),
2507 GLX_FUNCTION(glXImportContextEXT),
2508 GLX_FUNCTION2(glXQueryContextInfoEXT, glXQueryContext),
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07002509#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002510
2511 /*** GLX_SGIX_fbconfig ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002512 GLX_FUNCTION2(glXGetFBConfigAttribSGIX, glXGetFBConfigAttrib),
2513 GLX_FUNCTION2(glXChooseFBConfigSGIX, glXChooseFBConfig),
2514 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX),
2515 GLX_FUNCTION(glXCreateContextWithConfigSGIX),
2516 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX, glXGetVisualFromFBConfig),
2517 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002518
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07002519#ifndef GLX_USE_APPLEGL
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002520 /*** GLX_SGIX_pbuffer ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002521 GLX_FUNCTION(glXCreateGLXPbufferSGIX),
2522 GLX_FUNCTION(glXDestroyGLXPbufferSGIX),
2523 GLX_FUNCTION(glXQueryGLXPbufferSGIX),
2524 GLX_FUNCTION(glXSelectEventSGIX),
2525 GLX_FUNCTION(glXGetSelectedEventSGIX),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002526
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002527 /*** GLX_MESA_copy_sub_buffer ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002528 GLX_FUNCTION2(glXCopySubBufferMESA, __glXCopySubBufferMESA),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002529
2530 /*** GLX_MESA_pixmap_colormap ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002531 GLX_FUNCTION(glXCreateGLXPixmapMESA),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002532
2533 /*** GLX_MESA_release_buffers ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002534 GLX_FUNCTION2(glXReleaseBuffersMESA, __glXReleaseBuffersMESA),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002535
2536 /*** GLX_MESA_swap_control ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002537 GLX_FUNCTION2(glXSwapIntervalMESA, __glXSwapIntervalMESA),
2538 GLX_FUNCTION2(glXGetSwapIntervalMESA, __glXGetSwapIntervalMESA),
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07002539#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002540
2541 /*** GLX_ARB_get_proc_address ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002542 GLX_FUNCTION(glXGetProcAddressARB),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002543
2544 /*** GLX 1.4 ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002545 GLX_FUNCTION2(glXGetProcAddress, glXGetProcAddressARB),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002546
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07002547#ifndef GLX_USE_APPLEGL
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002548 /*** GLX_OML_sync_control ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002549 GLX_FUNCTION2(glXWaitForSbcOML, __glXWaitForSbcOML),
2550 GLX_FUNCTION2(glXWaitForMscOML, __glXWaitForMscOML),
2551 GLX_FUNCTION2(glXSwapBuffersMscOML, __glXSwapBuffersMscOML),
2552 GLX_FUNCTION2(glXGetMscRateOML, __glXGetMscRateOML),
2553 GLX_FUNCTION2(glXGetSyncValuesOML, __glXGetSyncValuesOML),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002554
Brian Paul42725d62006-02-07 00:39:56 +00002555 /*** GLX_EXT_texture_from_pixmap ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002556 GLX_FUNCTION2(glXBindTexImageEXT, __glXBindTexImageEXT),
2557 GLX_FUNCTION2(glXReleaseTexImageEXT, __glXReleaseTexImageEXT),
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07002558#endif
Brian Paul42725d62006-02-07 00:39:56 +00002559
Jon TURNEYf647a722014-06-02 18:52:15 +01002560#if defined(GLX_DIRECT_RENDERING) && defined(GLX_USE_DRM)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002561 /*** DRI configuration ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002562 GLX_FUNCTION(glXGetScreenDriver),
2563 GLX_FUNCTION(glXGetDriverConfig),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002564#endif
2565
Ian Romanick78aa71a2011-11-30 11:12:49 -08002566 /*** GLX_ARB_create_context and GLX_ARB_create_context_profile ***/
2567 GLX_FUNCTION(glXCreateContextAttribsARB),
2568
Ian Romanick6c28c032013-02-15 22:35:24 -08002569 /*** GLX_MESA_query_renderer ***/
2570 GLX_FUNCTION(glXQueryRendererIntegerMESA),
2571 GLX_FUNCTION(glXQueryRendererStringMESA),
2572 GLX_FUNCTION(glXQueryCurrentRendererIntegerMESA),
2573 GLX_FUNCTION(glXQueryCurrentRendererStringMESA),
2574
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002575 {NULL, NULL} /* end of list */
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002576};
2577
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002578static const GLvoid *
2579get_glx_proc_address(const char *funcName)
2580{
2581 GLuint i;
2582
2583 /* try static functions */
2584 for (i = 0; GLX_functions[i].Name; i++) {
2585 if (strcmp(GLX_functions[i].Name, funcName) == 0)
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002586 return GLX_functions[i].Address;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002587 }
2588
2589 return NULL;
2590}
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002591
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002592/**
2593 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2594 * \c glXGetProcAddress.
2595 *
2596 * \param procName Name of a GL or GLX function.
2597 * \returns A pointer to the named function
2598 *
2599 * \sa glXGetProcAddress
2600 */
Kyle Brenneman22a9e002016-05-11 14:01:53 -04002601_GLX_PUBLIC void (*glXGetProcAddressARB(const GLubyte * procName)) (void)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002602{
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002603 typedef void (*gl_function) (void);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002604 gl_function f;
2605
2606
2607 /* Search the table of GLX and internal functions first. If that
2608 * fails and the supplied name could be a valid core GL name, try
2609 * searching the core GL function table. This check is done to prevent
2610 * DRI based drivers from searching the core GL function table for
2611 * internal API functions.
2612 */
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002613 f = (gl_function) get_glx_proc_address((const char *) procName);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002614 if ((f == NULL) && (procName[0] == 'g') && (procName[1] == 'l')
2615 && (procName[2] != 'X')) {
Emil Velikov6177d602017-04-13 17:17:45 +01002616#ifdef GLX_INDIRECT_RENDERING
Chia-I Wue8c7d752010-12-26 18:24:13 +08002617 f = (gl_function) __indirect_get_proc_address((const char *) procName);
Matt Turner027ce0c2012-01-24 11:34:42 -05002618#endif
Chia-I Wue8c7d752010-12-26 18:24:13 +08002619 if (!f)
2620 f = (gl_function) _glapi_get_proc_address((const char *) procName);
Jeremy Huddleston559e4f82011-06-15 00:27:55 -07002621 if (!f) {
2622 struct glx_context *gc = __glXGetCurrentContext();
2623
2624 if (gc != NULL && gc->vtable->get_proc_address != NULL)
2625 f = gc->vtable->get_proc_address((const char *) procName);
2626 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002627 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002628 return f;
2629}
2630
2631/**
2632 * Get the address of a named GL function. This is the GLX 1.4 name for
2633 * \c glXGetProcAddressARB.
2634 *
2635 * \param procName Name of a GL or GLX function.
2636 * \returns A pointer to the named function
2637 *
2638 * \sa glXGetProcAddressARB
2639 */
Emil Velikov9898bcf2016-12-05 19:52:44 +00002640_GLX_PUBLIC
2641GLX_ALIAS(__GLXextFuncPtr, glXGetProcAddress,
2642 (const GLubyte * procName),
2643 (procName), glXGetProcAddressARB)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002644
Jeremy Huddleston80b280d2010-04-02 01:35:19 -07002645#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002646/**
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002647 * Get the unadjusted system time (UST). Currently, the UST is measured in
2648 * microseconds since Epoc. The actual resolution of the UST may vary from
2649 * system to system, and the units may vary from release to release.
2650 * Drivers should not call this function directly. They should instead use
2651 * \c glXGetProcAddress to obtain a pointer to the function.
2652 *
2653 * \param ust Location to store the 64-bit UST
2654 * \returns Zero on success or a negative errno value on failure.
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002655 *
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002656 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2657 *
2658 * \since Internal API version 20030317.
2659 */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002660_X_HIDDEN int
2661__glXGetUST(int64_t * ust)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002662{
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002663 struct timeval tv;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002664
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002665 if (ust == NULL) {
2666 return -EFAULT;
2667 }
2668
2669 if (gettimeofday(&tv, NULL) == 0) {
2670 ust[0] = (tv.tv_sec * 1000000) + tv.tv_usec;
2671 return 0;
2672 }
2673 else {
2674 return -errno;
2675 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002676}
2677#endif /* GLX_DIRECT_RENDERING */
Marek Olšák37d3a262016-03-03 18:43:53 +01002678
2679#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2680
Marek Olšák64c25932016-11-02 18:59:22 +01002681PUBLIC int
Marek Olšák37d3a262016-03-03 18:43:53 +01002682MesaGLInteropGLXQueryDeviceInfo(Display *dpy, GLXContext context,
Emil Velikov13faddb2016-05-30 10:56:33 +01002683 struct mesa_glinterop_device_info *out)
Marek Olšák37d3a262016-03-03 18:43:53 +01002684{
2685 struct glx_context *gc = (struct glx_context*)context;
2686 int ret;
2687
2688 __glXLock();
2689
2690 if (!gc || gc->xid == None || !gc->isDirect) {
2691 __glXUnlock();
2692 return MESA_GLINTEROP_INVALID_CONTEXT;
2693 }
2694
2695 if (!gc->vtable->interop_query_device_info) {
2696 __glXUnlock();
2697 return MESA_GLINTEROP_UNSUPPORTED;
2698 }
2699
2700 ret = gc->vtable->interop_query_device_info(gc, out);
2701 __glXUnlock();
2702 return ret;
2703}
2704
Marek Olšák64c25932016-11-02 18:59:22 +01002705PUBLIC int
Marek Olšák37d3a262016-03-03 18:43:53 +01002706MesaGLInteropGLXExportObject(Display *dpy, GLXContext context,
Emil Velikov13faddb2016-05-30 10:56:33 +01002707 struct mesa_glinterop_export_in *in,
2708 struct mesa_glinterop_export_out *out)
Marek Olšák37d3a262016-03-03 18:43:53 +01002709{
2710 struct glx_context *gc = (struct glx_context*)context;
2711 int ret;
2712
2713 __glXLock();
2714
2715 if (!gc || gc->xid == None || !gc->isDirect) {
2716 __glXUnlock();
2717 return MESA_GLINTEROP_INVALID_CONTEXT;
2718 }
2719
2720 if (!gc->vtable->interop_export_object) {
2721 __glXUnlock();
2722 return MESA_GLINTEROP_UNSUPPORTED;
2723 }
2724
2725 ret = gc->vtable->interop_export_object(gc, in, out);
2726 __glXUnlock();
2727 return ret;
2728}
2729
2730#endif /* defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) */