blob: 4b96b38c28fbaaf014e32b95a4859cc627601355 [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
Jon Turneyd512b352018-12-14 13:20:10 +000048#ifndef GLX_USE_WINDOWSGL
George Sapountzisdf04ffb2008-04-18 17:28:34 +030049#include <X11/extensions/xf86vmode.h>
Emil Velikova95ec132018-12-11 16:20:40 +000050#endif /* GLX_USE_WINDOWSGL */
Jon TURNEY2b9dac32010-04-21 12:58:54 +010051#endif
Jeremy Huddleston80b280d2010-04-02 01:35:19 -070052#endif
Adam Jacksonb8239ab2020-09-09 15:54:21 -040053#include <limits.h>
RALOVICH, Kristóf9c7aaa72008-11-04 10:59:39 +010054#include <X11/Xlib-xcb.h>
55#include <xcb/xcb.h>
56#include <xcb/glx.h>
Marek Olšák37d3a262016-03-03 18:43:53 +010057#include "GL/mesa_glinterop.h"
RALOVICH, Kristóf9c7aaa72008-11-04 10:59:39 +010058
Ian Romanick26d2ce02009-11-06 14:52:49 -080059static const char __glXGLXClientVendorName[] = "Mesa Project and SGI";
Adam Jacksoncb3610e2004-10-25 21:09:16 +000060static const char __glXGLXClientVersion[] = "1.4";
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -050061
Jeremy Huddleston80b280d2010-04-02 01:35:19 -070062#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -050063
Adam Jacksoncb3610e2004-10-25 21:09:16 +000064/**
65 * Get the __DRIdrawable for the drawable associated with a GLXContext
RALOVICH, Kristóf08962682009-08-12 12:41:22 +020066 *
Adam Jacksoncb3610e2004-10-25 21:09:16 +000067 * \param dpy The display associated with \c drawable.
68 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -050069 * \param scrn_num If non-NULL, the drawables screen is stored there
Adam Jacksoncb3610e2004-10-25 21:09:16 +000070 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
71 * the drawable is not associated with a direct-rendering context.
72 */
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -040073_X_HIDDEN __GLXDRIdrawable *
Kristian Høgsbergeeaab202010-07-22 22:36:37 -040074GetGLXDRIDrawable(Display * dpy, GLXDrawable drawable)
Adam Jacksoncb3610e2004-10-25 21:09:16 +000075{
Kristian Høgsbergc356f582010-07-28 11:16:00 -040076 struct glx_display *priv = __glXInitialize(dpy);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +020077 __GLXDRIdrawable *pdraw;
Adam Jacksoncb3610e2004-10-25 21:09:16 +000078
RALOVICH, Kristóf08962682009-08-12 12:41:22 +020079 if (priv == NULL)
80 return NULL;
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -040081
Kristian Høgsbergeeaab202010-07-22 22:36:37 -040082 if (__glxHashLookup(priv->drawHash, drawable, (void *) &pdraw) == 0)
Kristian Høgsberge3e81962010-07-19 21:15:50 -040083 return pdraw;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +020084
85 return NULL;
Adam Jacksoncb3610e2004-10-25 21:09:16 +000086}
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -050087
Adam Jacksoncb3610e2004-10-25 21:09:16 +000088#endif
89
Jesse Barnes4df13762011-05-06 10:31:24 -070090_X_HIDDEN struct glx_drawable *
91GetGLXDrawable(Display *dpy, GLXDrawable drawable)
92{
93 struct glx_display *priv = __glXInitialize(dpy);
94 struct glx_drawable *glxDraw;
95
96 if (priv == NULL)
97 return NULL;
98
99 if (__glxHashLookup(priv->glXDrawHash, drawable, (void *) &glxDraw) == 0)
100 return glxDraw;
101
102 return NULL;
103}
104
105_X_HIDDEN int
106InitGLXDrawable(Display *dpy, struct glx_drawable *glxDraw, XID xDrawable,
107 GLXDrawable drawable)
108{
109 struct glx_display *priv = __glXInitialize(dpy);
110
111 if (!priv)
112 return -1;
113
114 glxDraw->xDrawable = xDrawable;
115 glxDraw->drawable = drawable;
116 glxDraw->lastEventSbc = 0;
117 glxDraw->eventSbcWrap = 0;
118
119 return __glxHashInsert(priv->glXDrawHash, drawable, glxDraw);
120}
121
122_X_HIDDEN void
123DestroyGLXDrawable(Display *dpy, GLXDrawable drawable)
124{
125 struct glx_display *priv = __glXInitialize(dpy);
126 struct glx_drawable *glxDraw;
127
128 if (!priv)
129 return;
130
131 glxDraw = GetGLXDrawable(dpy, drawable);
132 __glxHashDelete(priv->glXDrawHash, drawable);
133 free(glxDraw);
134}
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000135
136/**
137 * Get the GLX per-screen data structure associated with a GLX context.
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200138 *
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000139 * \param dpy Display for which the GLX per-screen information is to be
140 * retrieved.
141 * \param scrn Screen on \c dpy for which the GLX per-screen information is
142 * to be retrieved.
143 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
144 * specify a valid GLX screen, or NULL otherwise.
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200145 *
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000146 * \todo Should this function validate that \c scrn is within the screen
147 * number range for \c dpy?
148 */
149
Ian Romanick588042a2011-11-30 10:33:37 -0800150_X_HIDDEN struct glx_screen *
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200151GetGLXScreenConfigs(Display * dpy, int scrn)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000152{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400153 struct glx_display *const priv = __glXInitialize(dpy);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000154
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200155 return (priv
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -0400156 && priv->screens !=
157 NULL) ? priv->screens[scrn] : NULL;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000158}
159
160
161static int
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400162GetGLXPrivScreenConfig(Display * dpy, int scrn, struct glx_display ** ppriv,
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -0400163 struct glx_screen ** ppsc)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000164{
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200165 /* Initialize the extension, if needed . This has the added value
166 * of initializing/allocating the display private
167 */
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000168
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200169 if (dpy == NULL) {
170 return GLX_NO_EXTENSION;
171 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000172
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200173 *ppriv = __glXInitialize(dpy);
174 if (*ppriv == NULL) {
175 return GLX_NO_EXTENSION;
176 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000177
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200178 /* Check screen number to see if its valid */
179 if ((scrn < 0) || (scrn >= ScreenCount(dpy))) {
180 return GLX_BAD_SCREEN;
181 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000182
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200183 /* Check to see if the GL is supported on this screen */
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -0400184 *ppsc = (*ppriv)->screens[scrn];
Dave Airlieb01a3a92013-11-18 17:34:52 +1000185 if ((*ppsc)->configs == NULL && (*ppsc)->visuals == NULL) {
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200186 /* No support for GL on this screen regardless of visual */
187 return GLX_BAD_VISUAL;
188 }
189
190 return Success;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000191}
192
193
194/**
195 * Determine if a \c GLXFBConfig supplied by the application is valid.
196 *
197 * \param dpy Application supplied \c Display pointer.
198 * \param config Application supplied \c GLXFBConfig.
199 *
200 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400201 * \c struct glx_config structure is returned. Otherwise, \c NULL
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000202 * is returned.
203 */
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400204static struct glx_config *
205ValidateGLXFBConfig(Display * dpy, GLXFBConfig fbconfig)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000206{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400207 struct glx_display *const priv = __glXInitialize(dpy);
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400208 int num_screens = ScreenCount(dpy);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200209 unsigned i;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400210 struct glx_config *config;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000211
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200212 if (priv != NULL) {
213 for (i = 0; i < num_screens; i++) {
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -0400214 for (config = priv->screens[i]->configs; config != NULL;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400215 config = config->next) {
216 if (config == (struct glx_config *) fbconfig) {
217 return config;
218 }
219 }
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200220 }
221 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000222
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200223 return NULL;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000224}
225
Tomasz Lis2eed9ff2013-07-18 14:19:38 -0700226/**
227 * Verifies context's GLX_RENDER_TYPE value with config.
228 *
229 * \param config GLX FBConfig which will support the returned renderType.
230 * \param renderType The context render type to be verified.
231 * \return True if the value of context renderType was approved, or 0 if no
232 * valid value was found.
233 */
234Bool
235validate_renderType_against_config(const struct glx_config *config,
236 int renderType)
237{
Adam Jackson74b701d2017-11-07 11:36:51 -0500238 /* GLX_EXT_no_config_context supports any render type */
239 if (!config)
Adam Jacksona14e3b42019-09-26 11:07:13 -0400240 return True;
Adam Jackson74b701d2017-11-07 11:36:51 -0500241
242 switch (renderType) {
243 case GLX_RGBA_TYPE:
244 return (config->renderType & GLX_RGBA_BIT) != 0;
245 case GLX_COLOR_INDEX_TYPE:
246 return (config->renderType & GLX_COLOR_INDEX_BIT) != 0;
247 case GLX_RGBA_FLOAT_TYPE_ARB:
248 return (config->renderType & GLX_RGBA_FLOAT_BIT_ARB) != 0;
249 case GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT:
250 return (config->renderType & GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT) != 0;
251 default:
252 break;
253 }
254 return 0;
Tomasz Lis2eed9ff2013-07-18 14:19:38 -0700255}
256
Kristian Høgsberg31819832010-07-22 21:24:14 -0400257_X_HIDDEN Bool
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400258glx_context_init(struct glx_context *gc,
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -0400259 struct glx_screen *psc, struct glx_config *config)
Kristian Høgsberg31819832010-07-22 21:24:14 -0400260{
261 gc->majorOpcode = __glXSetupForCommand(psc->display->dpy);
262 if (!gc->majorOpcode)
Brian Paul482c43a2013-06-26 13:42:51 -0600263 return False;
Kristian Høgsberg31819832010-07-22 21:24:14 -0400264
265 gc->screen = psc->scr;
266 gc->psc = psc;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400267 gc->config = config;
Kristian Høgsberg31819832010-07-22 21:24:14 -0400268 gc->isDirect = GL_TRUE;
Kristian Høgsbergc491e582010-07-28 15:33:09 -0400269 gc->currentContextTag = -1;
Kristian Høgsberg31819832010-07-22 21:24:14 -0400270
Brian Paul482c43a2013-06-26 13:42:51 -0600271 return True;
Kristian Høgsberg31819832010-07-22 21:24:14 -0400272}
273
Adam Jackson16f10232018-08-07 16:55:37 -0400274/**
275 * Determine if a context uses direct rendering.
276 *
277 * \param dpy Display where the context was created.
278 * \param contextID ID of the context to be tested.
279 * \param error Out parameter, set to True on error if not NULL
280 *
281 * \returns \c True if the context is direct rendering or not.
282 */
283static Bool
284__glXIsDirect(Display * dpy, GLXContextID contextID, Bool *error)
285{
286 CARD8 opcode;
287 xcb_connection_t *c;
288 xcb_generic_error_t *err;
289 xcb_glx_is_direct_reply_t *reply;
290 Bool is_direct;
291
292 opcode = __glXSetupForCommand(dpy);
293 if (!opcode) {
294 return False;
295 }
296
297 c = XGetXCBConnection(dpy);
298 reply = xcb_glx_is_direct_reply(c, xcb_glx_is_direct(c, contextID), &err);
299 is_direct = (reply != NULL && reply->is_direct) ? True : False;
300
301 if (err != NULL) {
302 if (error)
303 *error = True;
304 __glXSendErrorForXcb(dpy, err);
305 free(err);
306 }
307
308 free(reply);
309
310 return is_direct;
311}
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000312
313/**
Adam Jackson3869be72011-04-29 16:30:50 -0400314 * Create a new context.
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200315 *
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000316 * \param renderType For FBConfigs, what is the rendering type?
317 */
318
319static GLXContext
Adam Jackson3869be72011-04-29 16:30:50 -0400320CreateContext(Display *dpy, int generic_id, struct glx_config *config,
321 GLXContext shareList_user, Bool allowDirect,
Ian Romanick7bcfb662010-02-04 16:37:59 -0800322 unsigned code, int renderType, int screen)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000323{
nobledb5dc4072010-08-19 14:06:21 -0400324 struct glx_context *gc;
325 struct glx_screen *psc;
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400326 struct glx_context *shareList = (struct glx_context *) shareList_user;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200327 if (dpy == NULL)
328 return NULL;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000329
nobledb5dc4072010-08-19 14:06:21 -0400330 psc = GetGLXScreenConfigs(dpy, screen);
331 if (psc == NULL)
332 return NULL;
333
Ian Romanickd46d30f2010-02-04 17:06:18 -0800334 if (generic_id == None)
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200335 return NULL;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000336
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -0400337 gc = NULL;
Jeremy Huddleston1885cf22011-06-05 18:50:55 -0400338#ifdef GLX_USE_APPLEGL
339 gc = applegl_create_context(psc, config, shareList, renderType);
340#else
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -0400341 if (allowDirect && psc->vtable->create_context)
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400342 gc = psc->vtable->create_context(psc, config, shareList, renderType);
Kristian Høgsberg31819832010-07-22 21:24:14 -0400343 if (!gc)
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400344 gc = indirect_create_context(psc, config, shareList, renderType);
Jeremy Huddleston1885cf22011-06-05 18:50:55 -0400345#endif
Kristian Høgsberg31819832010-07-22 21:24:14 -0400346 if (!gc)
347 return NULL;
Kristian Høgsberg643b2af2010-05-21 10:36:56 -0400348
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800349 LockDisplay(dpy);
350 switch (code) {
351 case X_GLXCreateContext: {
352 xGLXCreateContextReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000353
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800354 /* Send the glXCreateContext request */
355 GetReq(GLXCreateContext, req);
356 req->reqType = gc->majorOpcode;
357 req->glxCode = X_GLXCreateContext;
358 req->context = gc->xid = XAllocID(dpy);
Ian Romanickd46d30f2010-02-04 17:06:18 -0800359 req->visual = generic_id;
Ian Romanickc3db1d62010-02-04 17:01:42 -0800360 req->screen = screen;
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800361 req->shareList = shareList ? shareList->xid : None;
Kristian Høgsbergc491e582010-07-28 15:33:09 -0400362 req->isDirect = gc->isDirect;
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800363 break;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200364 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000365
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800366 case X_GLXCreateNewContext: {
367 xGLXCreateNewContextReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000368
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800369 /* Send the glXCreateNewContext request */
370 GetReq(GLXCreateNewContext, req);
371 req->reqType = gc->majorOpcode;
372 req->glxCode = X_GLXCreateNewContext;
373 req->context = gc->xid = XAllocID(dpy);
Ian Romanickd46d30f2010-02-04 17:06:18 -0800374 req->fbconfig = generic_id;
Ian Romanickc3db1d62010-02-04 17:01:42 -0800375 req->screen = screen;
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800376 req->renderType = renderType;
377 req->shareList = shareList ? shareList->xid : None;
Kristian Høgsbergc491e582010-07-28 15:33:09 -0400378 req->isDirect = gc->isDirect;
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800379 break;
380 }
Ian Romanick8bffadb2010-02-04 16:28:52 -0800381
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800382 case X_GLXvop_CreateContextWithConfigSGIX: {
383 xGLXVendorPrivateWithReplyReq *vpreq;
384 xGLXCreateContextWithConfigSGIXReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000385
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800386 /* Send the glXCreateNewContext request */
387 GetReqExtra(GLXVendorPrivateWithReply,
388 sz_xGLXCreateContextWithConfigSGIXReq -
389 sz_xGLXVendorPrivateWithReplyReq, vpreq);
390 req = (xGLXCreateContextWithConfigSGIXReq *) vpreq;
391 req->reqType = gc->majorOpcode;
392 req->glxCode = X_GLXVendorPrivateWithReply;
393 req->vendorCode = X_GLXvop_CreateContextWithConfigSGIX;
394 req->context = gc->xid = XAllocID(dpy);
Ian Romanickd46d30f2010-02-04 17:06:18 -0800395 req->fbconfig = generic_id;
Ian Romanickc3db1d62010-02-04 17:01:42 -0800396 req->screen = screen;
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800397 req->renderType = renderType;
398 req->shareList = shareList ? shareList->xid : None;
Kristian Høgsbergc491e582010-07-28 15:33:09 -0400399 req->isDirect = gc->isDirect;
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800400 break;
401 }
Ian Romanick8bffadb2010-02-04 16:28:52 -0800402
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800403 default:
404 /* What to do here? This case is the sign of an internal error. It
405 * should never be reachable.
406 */
407 break;
408 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000409
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800410 UnlockDisplay(dpy);
411 SyncHandle();
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000412
Ian Romanicka832aa52011-12-08 15:03:19 -0800413 gc->share_xid = shareList ? shareList->xid : None;
Ian Romanickbc7b2f02010-02-04 16:46:46 -0800414 gc->imported = GL_FALSE;
Brian Paul521e4b92009-09-29 10:24:27 -0600415
Adam Jackson16f10232018-08-07 16:55:37 -0400416 /* Unlike most X resource creation requests, we're about to return a handle
417 * with client-side state, not just an XID. To simplify error handling
418 * elsewhere in libGL, force a round-trip here to ensure the CreateContext
419 * request above succeeded.
420 */
421 {
422 Bool error = False;
423 int isDirect = __glXIsDirect(dpy, gc->xid, &error);
424
425 if (error != False || isDirect != gc->isDirect) {
426 gc->vtable->destroy(gc);
427 gc = NULL;
428 }
429 }
430
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400431 return (GLXContext) gc;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000432}
433
Kyle Brenneman22a9e002016-05-11 14:01:53 -0400434_GLX_PUBLIC GLXContext
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200435glXCreateContext(Display * dpy, XVisualInfo * vis,
436 GLXContext shareList, Bool allowDirect)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000437{
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400438 struct glx_config *config = NULL;
Tomasz Lis36259a12013-07-17 13:49:14 +0200439 int renderType = GLX_RGBA_TYPE;
Ian Romanick52cf8db2010-02-04 16:59:10 -0800440
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700441#if defined(GLX_DIRECT_RENDERING) || defined(GLX_USE_APPLEGL)
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -0400442 struct glx_screen *const psc = GetGLXScreenConfigs(dpy, vis->screen);
Ian Romanick52cf8db2010-02-04 16:59:10 -0800443
Juha-Pekka Heikkilad28e92f2014-02-07 14:43:57 +0200444 if (psc)
445 config = glx_config_find_visual(psc->visuals, vis->visualid);
446
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400447 if (config == NULL) {
Adam Jackson75d5d222017-11-14 15:13:02 -0500448 __glXSendError(dpy, BadValue, vis->visualid, X_GLXCreateContext, True);
Ian Romanick52cf8db2010-02-04 16:59:10 -0800449 return None;
450 }
451
Tomasz Lis1c748df2013-07-17 13:49:17 +0200452 /* Choose the context render type based on DRI config values. It is
453 * unusual to set this type from config, but we have no other choice, as
454 * this old API does not provide renderType parameter.
455 */
456 if (config->renderType & GLX_RGBA_FLOAT_BIT_ARB) {
457 renderType = GLX_RGBA_FLOAT_TYPE_ARB;
458 } else if (config->renderType & GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT) {
459 renderType = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
460 } else if (config->renderType & GLX_RGBA_BIT) {
461 renderType = GLX_RGBA_TYPE;
462 } else if (config->renderType & GLX_COLOR_INDEX_BIT) {
463 renderType = GLX_COLOR_INDEX_TYPE;
Tomasz Lis1c748df2013-07-17 13:49:17 +0200464 }
Ian Romanick52cf8db2010-02-04 16:59:10 -0800465#endif
466
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400467 return CreateContext(dpy, vis->visualid, config, shareList, allowDirect,
Ian Romanick52cf8db2010-02-04 16:59:10 -0800468 X_GLXCreateContext, renderType, vis->screen);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000469}
470
Ian Romanick4dbd13c2011-12-07 13:31:27 -0800471static void
Kristian Høgsbergc796bb02010-07-22 23:45:18 -0400472glx_send_destroy_context(Display *dpy, XID xid)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000473{
Kristian Høgsbergc796bb02010-07-22 23:45:18 -0400474 CARD8 opcode = __glXSetupForCommand(dpy);
475 xGLXDestroyContextReq *req;
476
477 LockDisplay(dpy);
478 GetReq(GLXDestroyContext, req);
479 req->reqType = opcode;
480 req->glxCode = X_GLXDestroyContext;
481 req->context = xid;
482 UnlockDisplay(dpy);
483 SyncHandle();
484}
485
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000486/*
487** Destroy the named context
488*/
Adam Jackson9e2bc5d2011-06-02 16:29:59 -0400489
Kyle Brenneman22a9e002016-05-11 14:01:53 -0400490_GLX_PUBLIC void
Adam Jackson9e2bc5d2011-06-02 16:29:59 -0400491glXDestroyContext(Display * dpy, GLXContext ctx)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000492{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400493 struct glx_context *gc = (struct glx_context *) ctx;
494
Ian Romanick4dbd13c2011-12-07 13:31:27 -0800495 if (gc == NULL || gc->xid == None)
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200496 return;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000497
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200498 __glXLock();
Ian Romanick4dbd13c2011-12-07 13:31:27 -0800499 if (!gc->imported)
500 glx_send_destroy_context(dpy, gc->xid);
501
Brian Paul5e6a6a22009-10-22 18:19:01 -0600502 if (gc->currentDpy) {
503 /* This context is bound to some thread. According to the man page,
504 * we should not actually delete the context until it's unbound.
505 * Note that we set gc->xid = None above. In MakeContextCurrent()
506 * we check for that and delete the context there.
507 */
Kristian Høgsbergc796bb02010-07-22 23:45:18 -0400508 gc->xid = None;
Ian Romanick4dbd13c2011-12-07 13:31:27 -0800509 } else {
510 gc->vtable->destroy(gc);
Brian Paul5e6a6a22009-10-22 18:19:01 -0600511 }
Kristian Høgsbergc796bb02010-07-22 23:45:18 -0400512 __glXUnlock();
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000513}
Adam Jackson489ccef2004-12-15 17:18:06 +0000514
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000515/*
516** Return the major and minor version #s for the GLX extension
517*/
Kyle Brenneman22a9e002016-05-11 14:01:53 -0400518_GLX_PUBLIC Bool
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200519glXQueryVersion(Display * dpy, int *major, int *minor)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000520{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400521 struct glx_display *priv;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000522
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200523 /* Init the extension. This fetches the major and minor version. */
524 priv = __glXInitialize(dpy);
525 if (!priv)
Brian Paul482c43a2013-06-26 13:42:51 -0600526 return False;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000527
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200528 if (major)
529 *major = priv->majorVersion;
530 if (minor)
531 *minor = priv->minorVersion;
Brian Paul482c43a2013-06-26 13:42:51 -0600532 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000533}
534
535/*
Zoë Blade05e7f7f2015-04-22 11:33:17 +0100536** Query the existence of the GLX extension
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000537*/
Kyle Brenneman22a9e002016-05-11 14:01:53 -0400538_GLX_PUBLIC Bool
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200539glXQueryExtension(Display * dpy, int *errorBase, int *eventBase)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000540{
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200541 int major_op, erb, evb;
542 Bool rv;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000543
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200544 rv = XQueryExtension(dpy, GLX_EXTENSION_NAME, &major_op, &evb, &erb);
545 if (rv) {
546 if (errorBase)
547 *errorBase = erb;
548 if (eventBase)
549 *eventBase = evb;
550 }
551 return rv;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000552}
553
Kristian Høgsberg7b7845a2010-07-22 22:24:00 -0400554/*
555** Put a barrier in the token stream that forces the GL to finish its
556** work before X can proceed.
557*/
Kyle Brenneman22a9e002016-05-11 14:01:53 -0400558_GLX_PUBLIC void
Kristian Høgsberg7b7845a2010-07-22 22:24:00 -0400559glXWaitGL(void)
560{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400561 struct glx_context *gc = __glXGetCurrentContext();
Kristian Høgsberg7b7845a2010-07-22 22:24:00 -0400562
Adam Jacksonbcb15be2017-11-14 15:13:01 -0500563 if (gc->vtable->wait_gl)
Kristian Høgsberg7b7845a2010-07-22 22:24:00 -0400564 gc->vtable->wait_gl(gc);
565}
566
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000567/*
568** Put a barrier in the token stream that forces X to finish its
569** work before GL can proceed.
570*/
Kyle Brenneman22a9e002016-05-11 14:01:53 -0400571_GLX_PUBLIC void
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200572glXWaitX(void)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000573{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400574 struct glx_context *gc = __glXGetCurrentContext();
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000575
Adam Jacksonbcb15be2017-11-14 15:13:01 -0500576 if (gc->vtable->wait_x)
Kristian Høgsberg7b7845a2010-07-22 22:24:00 -0400577 gc->vtable->wait_x(gc);
578}
579
Kyle Brenneman22a9e002016-05-11 14:01:53 -0400580_GLX_PUBLIC void
Kristian Høgsberg7b7845a2010-07-22 22:24:00 -0400581glXUseXFont(Font font, int first, int count, int listBase)
582{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400583 struct glx_context *gc = __glXGetCurrentContext();
Kristian Høgsberg7b7845a2010-07-22 22:24:00 -0400584
Adam Jacksonbcb15be2017-11-14 15:13:01 -0500585 if (gc->vtable->use_x_font)
Kristian Høgsberg7b7845a2010-07-22 22:24:00 -0400586 gc->vtable->use_x_font(gc, font, first, count, listBase);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000587}
588
589/************************************************************************/
590
591/*
592** Copy the source context to the destination context using the
593** attribute "mask".
594*/
Kyle Brenneman22a9e002016-05-11 14:01:53 -0400595_GLX_PUBLIC void
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400596glXCopyContext(Display * dpy, GLXContext source_user,
597 GLXContext dest_user, unsigned long mask)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000598{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400599 struct glx_context *source = (struct glx_context *) source_user;
600 struct glx_context *dest = (struct glx_context *) dest_user;
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700601#ifdef GLX_USE_APPLEGL
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400602 struct glx_context *gc = __glXGetCurrentContext();
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700603 int errorcode;
604 bool x11error;
605
Jeremy Huddleston80b280d2010-04-02 01:35:19 -0700606 if(apple_glx_copy_context(gc->driContext, source->driContext, dest->driContext,
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700607 mask, &errorcode, &x11error)) {
608 __glXSendError(dpy, errorcode, 0, X_GLXCopyContext, x11error);
609 }
610
611#else
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200612 xGLXCopyContextReq *req;
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400613 struct glx_context *gc = __glXGetCurrentContext();
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200614 GLXContextTag tag;
615 CARD8 opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000616
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200617 opcode = __glXSetupForCommand(dpy);
618 if (!opcode) {
619 return;
620 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000621
Jeremy Huddleston80b280d2010-04-02 01:35:19 -0700622#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
Kristian Høgsbergc491e582010-07-28 15:33:09 -0400623 if (gc->isDirect) {
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200624 /* NOT_DONE: This does not work yet */
625 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000626#endif
627
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200628 /*
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000629 ** If the source is the current context, send its tag so that the context
630 ** can be flushed before the copy.
631 */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200632 if (source == gc && dpy == gc->currentDpy) {
633 tag = gc->currentContextTag;
634 }
635 else {
636 tag = 0;
637 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000638
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200639 /* Send the glXCopyContext request */
640 LockDisplay(dpy);
641 GetReq(GLXCopyContext, req);
642 req->reqType = opcode;
643 req->glxCode = X_GLXCopyContext;
644 req->source = source ? source->xid : None;
645 req->dest = dest ? dest->xid : None;
646 req->mask = mask;
647 req->contextTag = tag;
648 UnlockDisplay(dpy);
649 SyncHandle();
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700650#endif /* GLX_USE_APPLEGL */
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000651}
652
653
654/**
Ian Romanickc39bf5e2005-07-24 06:29:14 +0000655 * \todo
Brian Paul482c43a2013-06-26 13:42:51 -0600656 * Shouldn't this function \b always return \c False when
Ian Romanickc39bf5e2005-07-24 06:29:14 +0000657 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
658 * the GLX protocol here at all?
659 */
Kyle Brenneman22a9e002016-05-11 14:01:53 -0400660_GLX_PUBLIC Bool
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400661glXIsDirect(Display * dpy, GLXContext gc_user)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000662{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400663 struct glx_context *gc = (struct glx_context *) gc_user;
664
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200665 if (!gc) {
Brian Paul482c43a2013-06-26 13:42:51 -0600666 return False;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200667 }
Kristian Høgsbergc491e582010-07-28 15:33:09 -0400668 else if (gc->isDirect) {
Brian Paul482c43a2013-06-26 13:42:51 -0600669 return True;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200670 }
Jeremy Huddlestona18702f2010-05-01 13:59:30 -0700671#ifdef GLX_USE_APPLEGL /* TODO: indirect on darwin */
Brian Paul482c43a2013-06-26 13:42:51 -0600672 return False;
Jeremy Huddlestona18702f2010-05-01 13:59:30 -0700673#else
Adam Jackson16f10232018-08-07 16:55:37 -0400674 return __glXIsDirect(dpy, gc->xid, NULL);
Jeremy Huddlestona18702f2010-05-01 13:59:30 -0700675#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000676}
677
Kyle Brenneman22a9e002016-05-11 14:01:53 -0400678_GLX_PUBLIC GLXPixmap
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200679glXCreateGLXPixmap(Display * dpy, XVisualInfo * vis, Pixmap pixmap)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000680{
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700681#ifdef GLX_USE_APPLEGL
682 int screen = vis->screen;
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -0400683 struct glx_screen *const psc = GetGLXScreenConfigs(dpy, screen);
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400684 const struct glx_config *config;
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700685
Jeremy Huddlestonb7f0ed82011-06-05 18:19:59 -0400686 config = glx_config_find_visual(psc->visuals, vis->visualid);
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700687
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400688 if(apple_glx_pixmap_create(dpy, vis->screen, pixmap, config))
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700689 return None;
690
691 return pixmap;
692#else
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200693 xGLXCreateGLXPixmapReq *req;
Jesse Barnes4df13762011-05-06 10:31:24 -0700694 struct glx_drawable *glxDraw;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200695 GLXPixmap xid;
696 CARD8 opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000697
Juha-Pekka Heikkilad28e92f2014-02-07 14:43:57 +0200698#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
699 struct glx_display *const priv = __glXInitialize(dpy);
700
701 if (priv == NULL)
702 return None;
703#endif
704
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200705 opcode = __glXSetupForCommand(dpy);
706 if (!opcode) {
707 return None;
708 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000709
Matt Turner7c7b7b02012-09-04 22:52:36 -0700710 glxDraw = malloc(sizeof(*glxDraw));
Jesse Barnes4df13762011-05-06 10:31:24 -0700711 if (!glxDraw)
712 return None;
713
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200714 /* Send the glXCreateGLXPixmap request */
715 LockDisplay(dpy);
716 GetReq(GLXCreateGLXPixmap, req);
717 req->reqType = opcode;
718 req->glxCode = X_GLXCreateGLXPixmap;
719 req->screen = vis->screen;
720 req->visual = vis->visualid;
721 req->pixmap = pixmap;
722 req->glxpixmap = xid = XAllocID(dpy);
723 UnlockDisplay(dpy);
724 SyncHandle();
Michel Dänzeredb11782009-08-30 12:43:37 +0200725
Jesse Barnes4df13762011-05-06 10:31:24 -0700726 if (InitGLXDrawable(dpy, glxDraw, pixmap, req->glxpixmap)) {
727 free(glxDraw);
728 return None;
729 }
730
Jeremy Huddleston80b280d2010-04-02 01:35:19 -0700731#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
Michel Dänzer9053bb02009-08-30 13:06:18 +0200732 do {
733 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
734 * is actually bound to a context... */
Michel Dänzeredb11782009-08-30 12:43:37 +0200735
Michel Dänzer9053bb02009-08-30 13:06:18 +0200736 __GLXDRIdrawable *pdraw;
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -0400737 struct glx_screen *psc;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400738 struct glx_config *config;
Michel Dänzeredb11782009-08-30 12:43:37 +0200739
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -0400740 psc = priv->screens[vis->screen];
Michel Dänzer9053bb02009-08-30 13:06:18 +0200741 if (psc->driScreen == NULL)
Adam Jackson48331042011-03-31 20:43:57 +0000742 return xid;
743
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400744 config = glx_config_find_visual(psc->visuals, vis->visualid);
Adam Jackson776a2a52011-06-01 11:33:48 -0400745 pdraw = psc->driScreen->createDrawable(psc, pixmap, xid, config);
Michel Dänzer9053bb02009-08-30 13:06:18 +0200746 if (pdraw == NULL) {
747 fprintf(stderr, "failed to create pixmap\n");
Adam Jackson48331042011-03-31 20:43:57 +0000748 xid = None;
Michel Dänzer9053bb02009-08-30 13:06:18 +0200749 break;
750 }
Michel Dänzeredb11782009-08-30 12:43:37 +0200751
Adam Jackson776a2a52011-06-01 11:33:48 -0400752 if (__glxHashInsert(priv->drawHash, xid, pdraw)) {
Michel Dänzer9053bb02009-08-30 13:06:18 +0200753 (*pdraw->destroyDrawable) (pdraw);
Adam Jackson48331042011-03-31 20:43:57 +0000754 xid = None;
755 break;
Michel Dänzer9053bb02009-08-30 13:06:18 +0200756 }
757 } while (0);
Adam Jackson48331042011-03-31 20:43:57 +0000758
759 if (xid == None) {
760 xGLXDestroyGLXPixmapReq *dreq;
761 LockDisplay(dpy);
762 GetReq(GLXDestroyGLXPixmap, dreq);
763 dreq->reqType = opcode;
764 dreq->glxCode = X_GLXDestroyGLXPixmap;
765 dreq->glxpixmap = xid;
766 UnlockDisplay(dpy);
767 SyncHandle();
768 }
Michel Dänzeredb11782009-08-30 12:43:37 +0200769#endif
770
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200771 return xid;
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700772#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000773}
774
775/*
776** Destroy the named pixmap
777*/
Kyle Brenneman22a9e002016-05-11 14:01:53 -0400778_GLX_PUBLIC void
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200779glXDestroyGLXPixmap(Display * dpy, GLXPixmap glxpixmap)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000780{
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700781#ifdef GLX_USE_APPLEGL
782 if(apple_glx_pixmap_destroy(dpy, glxpixmap))
783 __glXSendError(dpy, GLXBadPixmap, glxpixmap, X_GLXDestroyPixmap, false);
784#else
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200785 xGLXDestroyGLXPixmapReq *req;
786 CARD8 opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000787
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200788 opcode = __glXSetupForCommand(dpy);
789 if (!opcode) {
790 return;
791 }
792
793 /* Send the glXDestroyGLXPixmap request */
794 LockDisplay(dpy);
795 GetReq(GLXDestroyGLXPixmap, req);
796 req->reqType = opcode;
797 req->glxCode = X_GLXDestroyGLXPixmap;
798 req->glxpixmap = glxpixmap;
799 UnlockDisplay(dpy);
800 SyncHandle();
Michel Dänzer9dfce362009-06-19 11:19:07 +0200801
Jesse Barnes4df13762011-05-06 10:31:24 -0700802 DestroyGLXDrawable(dpy, glxpixmap);
803
Jeremy Huddleston80b280d2010-04-02 01:35:19 -0700804#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200805 {
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400806 struct glx_display *const priv = __glXInitialize(dpy);
Kristian Høgsbergeeaab202010-07-22 22:36:37 -0400807 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, glxpixmap);
Michel Dänzer9dfce362009-06-19 11:19:07 +0200808
Juha-Pekka Heikkilad28e92f2014-02-07 14:43:57 +0200809 if (priv != NULL && pdraw != NULL) {
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200810 (*pdraw->destroyDrawable) (pdraw);
Kristian Høgsberge3e81962010-07-19 21:15:50 -0400811 __glxHashDelete(priv->drawHash, glxpixmap);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200812 }
813 }
Michel Dänzer9dfce362009-06-19 11:19:07 +0200814#endif
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700815#endif /* GLX_USE_APPLEGL */
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000816}
817
Kyle Brenneman22a9e002016-05-11 14:01:53 -0400818_GLX_PUBLIC void
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200819glXSwapBuffers(Display * dpy, GLXDrawable drawable)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000820{
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700821#ifdef GLX_USE_APPLEGL
Jeremy Huddleston279e4712011-06-05 18:22:47 -0400822 struct glx_context * gc = __glXGetCurrentContext();
Jeremy Huddleston Sequoiac1c4c182017-08-17 15:08:36 -0700823 if(gc != &dummyContext && apple_glx_is_current_drawable(dpy, gc->driContext, drawable)) {
Jeremy Huddleston80b280d2010-04-02 01:35:19 -0700824 apple_glx_swap_buffers(gc->driContext);
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700825 } else {
826 __glXSendError(dpy, GLXBadCurrentWindow, 0, X_GLXSwapBuffers, false);
827 }
828#else
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400829 struct glx_context *gc;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200830 GLXContextTag tag;
831 CARD8 opcode;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200832 xcb_connection_t *c;
Brian Paulb7f802e2009-01-18 09:59:07 -0700833
Eric Anholt4d01bea2011-02-14 18:38:33 -0800834 gc = __glXGetCurrentContext();
835
Jeremy Huddleston80b280d2010-04-02 01:35:19 -0700836#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
Brian Paule975e182011-08-19 08:36:22 -0600837 {
838 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000839
Brian Paule975e182011-08-19 08:36:22 -0600840 if (pdraw != NULL) {
Bernard Kilarski2e3f0672016-06-07 13:33:33 +0300841 Bool flush = gc != &dummyContext && drawable == gc->currentDrawable;
Brian Paule975e182011-08-19 08:36:22 -0600842
Eric Engestrome7e3fd52018-11-22 19:47:28 +0000843 pdraw->psc->driScreen->swapBuffers(pdraw, 0, 0, 0, flush);
Brian Paule975e182011-08-19 08:36:22 -0600844 return;
Eric Anholt4d01bea2011-02-14 18:38:33 -0800845 }
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200846 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000847#endif
848
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200849 opcode = __glXSetupForCommand(dpy);
850 if (!opcode) {
851 return;
852 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000853
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200854 /*
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000855 ** The calling thread may or may not have a current context. If it
856 ** does, send the context tag so the server can do a flush.
857 */
Bernard Kilarski2e3f0672016-06-07 13:33:33 +0300858 if ((gc != &dummyContext) && (dpy == gc->currentDpy) &&
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200859 ((drawable == gc->currentDrawable)
860 || (drawable == gc->currentReadable))) {
861 tag = gc->currentContextTag;
862 }
863 else {
864 tag = 0;
865 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000866
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200867 c = XGetXCBConnection(dpy);
868 xcb_glx_swap_buffers(c, tag, drawable);
869 xcb_flush(c);
Jeremy Huddlestonad503c42010-04-01 11:01:31 -0700870#endif /* GLX_USE_APPLEGL */
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000871}
872
873
874/*
875** Return configuration information for the given display, screen and
876** visual combination.
877*/
Kyle Brenneman22a9e002016-05-11 14:01:53 -0400878_GLX_PUBLIC int
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200879glXGetConfig(Display * dpy, XVisualInfo * vis, int attribute,
880 int *value_return)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000881{
Kristian Høgsbergc356f582010-07-28 11:16:00 -0400882 struct glx_display *priv;
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -0400883 struct glx_screen *psc;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400884 struct glx_config *config;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200885 int status;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000886
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200887 status = GetGLXPrivScreenConfig(dpy, vis->screen, &priv, &psc);
888 if (status == Success) {
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400889 config = glx_config_find_visual(psc->visuals, vis->visualid);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000890
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200891 /* Lookup attribute after first finding a match on the visual */
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400892 if (config != NULL) {
893 return glx_config_get(config, attribute, value_return);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200894 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000895
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200896 status = GLX_BAD_VISUAL;
897 }
898
899 /*
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000900 ** If we can't find the config for this visual, this visual is not
901 ** supported by the OpenGL implementation on the server.
902 */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200903 if ((status == GLX_BAD_VISUAL) && (attribute == GLX_USE_GL)) {
Brian Paul482c43a2013-06-26 13:42:51 -0600904 *value_return = False;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200905 status = Success;
906 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000907
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200908 return status;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000909}
910
911/************************************************************************/
912
913static void
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400914init_fbconfig_for_chooser(struct glx_config * config,
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200915 GLboolean fbconfig_style_tags)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000916{
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400917 memset(config, 0, sizeof(struct glx_config));
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200918 config->visualID = (XID) GLX_DONT_CARE;
919 config->visualType = GLX_DONT_CARE;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000920
Tomasz Lis4473af72013-07-17 13:49:20 +0200921 /* glXChooseFBConfig specifies different defaults for these properties than
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200922 * glXChooseVisual.
923 */
924 if (fbconfig_style_tags) {
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200925 config->doubleBufferMode = GLX_DONT_CARE;
Fredrik Höglundf41c2f62014-02-13 21:07:09 +0100926 config->renderType = GLX_RGBA_BIT;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200927 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000928
Fredrik Höglundf41c2f62014-02-13 21:07:09 +0100929 config->drawableType = GLX_WINDOW_BIT;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200930 config->visualRating = GLX_DONT_CARE;
931 config->transparentPixel = GLX_NONE;
932 config->transparentRed = GLX_DONT_CARE;
933 config->transparentGreen = GLX_DONT_CARE;
934 config->transparentBlue = GLX_DONT_CARE;
935 config->transparentAlpha = GLX_DONT_CARE;
936 config->transparentIndex = GLX_DONT_CARE;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000937
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200938 config->xRenderable = GLX_DONT_CARE;
939 config->fbconfigID = (GLXFBConfigID) (GLX_DONT_CARE);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000940
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200941 config->swapMethod = GLX_DONT_CARE;
Jon Turneyfaa29c02018-07-14 15:24:14 +0100942 config->sRGBCapable = GLX_DONT_CARE;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000943}
944
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200945#define MATCH_DONT_CARE( param ) \
946 do { \
Ian Romanick71a6fb12010-02-04 15:59:51 -0800947 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200948 && (a-> param != b-> param) ) { \
949 return False; \
950 } \
951 } while ( 0 )
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000952
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200953#define MATCH_MINIMUM( param ) \
954 do { \
Ian Romanick71a6fb12010-02-04 15:59:51 -0800955 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200956 && (a-> param > b-> param) ) { \
957 return False; \
958 } \
959 } while ( 0 )
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000960
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200961#define MATCH_EXACT( param ) \
962 do { \
963 if ( a-> param != b-> param) { \
964 return False; \
965 } \
966 } while ( 0 )
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000967
Kristian Høgsbergedb52532010-04-08 22:09:11 -0400968/* Test that all bits from a are contained in b */
969#define MATCH_MASK(param) \
970 do { \
Alexander Monakov9cda3562013-04-02 01:38:27 +0400971 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
972 && ((a->param & ~b->param) != 0) ) { \
Kristian Høgsbergedb52532010-04-08 22:09:11 -0400973 return False; \
Alexander Monakov9cda3562013-04-02 01:38:27 +0400974 } \
Kristian Høgsbergedb52532010-04-08 22:09:11 -0400975 } while (0);
976
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000977/**
978 * Determine if two GLXFBConfigs are compatible.
979 *
980 * \param a Application specified config to test.
981 * \param b Server specified config to test against \c a.
982 */
983static Bool
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -0400984fbconfigs_compatible(const struct glx_config * const a,
985 const struct glx_config * const b)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000986{
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200987 MATCH_DONT_CARE(doubleBufferMode);
988 MATCH_DONT_CARE(visualType);
989 MATCH_DONT_CARE(visualRating);
990 MATCH_DONT_CARE(xRenderable);
991 MATCH_DONT_CARE(fbconfigID);
992 MATCH_DONT_CARE(swapMethod);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000993
RALOVICH, Kristóf08962682009-08-12 12:41:22 +0200994 MATCH_MINIMUM(rgbBits);
995 MATCH_MINIMUM(numAuxBuffers);
996 MATCH_MINIMUM(redBits);
997 MATCH_MINIMUM(greenBits);
998 MATCH_MINIMUM(blueBits);
999 MATCH_MINIMUM(alphaBits);
1000 MATCH_MINIMUM(depthBits);
1001 MATCH_MINIMUM(stencilBits);
1002 MATCH_MINIMUM(accumRedBits);
1003 MATCH_MINIMUM(accumGreenBits);
1004 MATCH_MINIMUM(accumBlueBits);
1005 MATCH_MINIMUM(accumAlphaBits);
1006 MATCH_MINIMUM(sampleBuffers);
1007 MATCH_MINIMUM(maxPbufferWidth);
1008 MATCH_MINIMUM(maxPbufferHeight);
1009 MATCH_MINIMUM(maxPbufferPixels);
1010 MATCH_MINIMUM(samples);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001011
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001012 MATCH_DONT_CARE(stereoMode);
1013 MATCH_EXACT(level);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001014
Kristian Høgsbergedb52532010-04-08 22:09:11 -04001015 MATCH_MASK(drawableType);
1016 MATCH_MASK(renderType);
Neha Bhende6e06e282017-04-26 16:21:32 -07001017 MATCH_DONT_CARE(sRGBCapable);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001018
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001019 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1020 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1021 * Technically speaking, it is a bug in the DDX driver, but there is
1022 * enough of an installed base to work around the problem here. In any
1023 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1024 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1025 * 0 from the server to be a match to maintain backward compatibility with
1026 * the (broken) drivers.
1027 */
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001028
Ian Romanick71a6fb12010-02-04 15:59:51 -08001029 if (a->transparentPixel != (int) GLX_DONT_CARE && a->transparentPixel != 0) {
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001030 if (a->transparentPixel == GLX_NONE) {
1031 if (b->transparentPixel != GLX_NONE && b->transparentPixel != 0)
1032 return False;
1033 }
1034 else {
1035 MATCH_EXACT(transparentPixel);
1036 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001037
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001038 switch (a->transparentPixel) {
1039 case GLX_TRANSPARENT_RGB:
1040 MATCH_DONT_CARE(transparentRed);
1041 MATCH_DONT_CARE(transparentGreen);
1042 MATCH_DONT_CARE(transparentBlue);
1043 MATCH_DONT_CARE(transparentAlpha);
1044 break;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001045
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001046 case GLX_TRANSPARENT_INDEX:
1047 MATCH_DONT_CARE(transparentIndex);
1048 break;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001049
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001050 default:
1051 break;
1052 }
1053 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001054
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001055 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001056}
1057
1058
1059/* There's some trickly language in the GLX spec about how this is supposed
1060 * to work. Basically, if a given component size is either not specified
1061 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1062 * Well, that's really hard to do with the code as-is. This behavior is
1063 * closer to correct, but still not technically right.
1064 */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001065#define PREFER_LARGER_OR_ZERO(comp) \
1066 do { \
1067 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1068 if ( ((*a)-> comp) == 0 ) { \
1069 return -1; \
1070 } \
1071 else if ( ((*b)-> comp) == 0 ) { \
1072 return 1; \
1073 } \
1074 else { \
1075 return ((*b)-> comp) - ((*a)-> comp) ; \
1076 } \
1077 } \
1078 } while( 0 )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001079
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001080#define PREFER_LARGER(comp) \
1081 do { \
1082 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1083 return ((*b)-> comp) - ((*a)-> comp) ; \
1084 } \
1085 } while( 0 )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001086
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001087#define PREFER_SMALLER(comp) \
1088 do { \
1089 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1090 return ((*a)-> comp) - ((*b)-> comp) ; \
1091 } \
1092 } while( 0 )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001093
1094/**
1095 * Compare two GLXFBConfigs. This function is intended to be used as the
1096 * compare function passed in to qsort.
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001097 *
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001098 * \returns If \c a is a "better" config, according to the specification of
1099 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1100 * better, then a number greater than zero is return. If both are
1101 * equal, zero is returned.
1102 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1103 */
1104static int
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001105fbconfig_compare(struct glx_config **a, struct glx_config **b)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001106{
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001107 /* The order of these comparisons must NOT change. It is defined by
Fredrik Höglund3616e862014-02-15 18:48:40 +01001108 * the GLX 1.4 specification.
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001109 */
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001110
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001111 PREFER_SMALLER(visualSelectGroup);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001112
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001113 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1114 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1115 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1116 */
1117 PREFER_SMALLER(visualRating);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001118
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001119 /* This isn't quite right. It is supposed to compare the sum of the
1120 * components the user specifically set minimums for.
1121 */
1122 PREFER_LARGER_OR_ZERO(redBits);
1123 PREFER_LARGER_OR_ZERO(greenBits);
1124 PREFER_LARGER_OR_ZERO(blueBits);
1125 PREFER_LARGER_OR_ZERO(alphaBits);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001126
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001127 PREFER_SMALLER(rgbBits);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001128
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001129 if (((*a)->doubleBufferMode != (*b)->doubleBufferMode)) {
1130 /* Prefer single-buffer.
1131 */
1132 return (!(*a)->doubleBufferMode) ? -1 : 1;
1133 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001134
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001135 PREFER_SMALLER(numAuxBuffers);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001136
Fredrik Höglund3616e862014-02-15 18:48:40 +01001137 PREFER_SMALLER(sampleBuffers);
1138 PREFER_SMALLER(samples);
1139
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001140 PREFER_LARGER_OR_ZERO(depthBits);
1141 PREFER_SMALLER(stencilBits);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001142
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001143 /* This isn't quite right. It is supposed to compare the sum of the
1144 * components the user specifically set minimums for.
1145 */
1146 PREFER_LARGER_OR_ZERO(accumRedBits);
1147 PREFER_LARGER_OR_ZERO(accumGreenBits);
1148 PREFER_LARGER_OR_ZERO(accumBlueBits);
1149 PREFER_LARGER_OR_ZERO(accumAlphaBits);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001150
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001151 PREFER_SMALLER(visualType);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001152
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001153 /* None of the pbuffer or fbconfig specs say that this comparison needs
1154 * to happen at all, but it seems like it should.
1155 */
1156 PREFER_LARGER(maxPbufferWidth);
1157 PREFER_LARGER(maxPbufferHeight);
1158 PREFER_LARGER(maxPbufferPixels);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001159
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001160 return 0;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001161}
1162
1163
1164/**
1165 * Selects and sorts a subset of the supplied configs based on the attributes.
Emil Velikov78a74152016-09-30 11:01:28 +01001166 * This function forms to basis of \c glXChooseFBConfig and
1167 * \c glXChooseFBConfigSGIX.
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001168 *
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001169 * \param configs Array of pointers to possible configs. The elements of
1170 * this array that do not meet the criteria will be set to
1171 * NULL. The remaining elements will be sorted according to
1172 * the various visual / FBConfig selection rules.
1173 * \param num_configs Number of elements in the \c configs array.
1174 * \param attribList Attributes used select from \c configs. This array is
Emil Velikov78a74152016-09-30 11:01:28 +01001175 * terminated by a \c None tag. The array is of the form
1176 * expected by \c glXChooseFBConfig (where every tag has a
1177 * value).
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001178 * \returns The number of valid elements left in \c configs.
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001179 *
Emil Velikov78a74152016-09-30 11:01:28 +01001180 * \sa glXChooseFBConfig, glXChooseFBConfigSGIX
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001181 */
1182static int
Emil Velikov78a74152016-09-30 11:01:28 +01001183choose_fbconfig(struct glx_config ** configs, int num_configs,
1184 const int *attribList)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001185{
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001186 struct glx_config test_config;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001187 int base;
1188 int i;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001189
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001190 /* This is a fairly direct implementation of the selection method
1191 * described by GLX_SGIX_fbconfig. Start by culling out all the
1192 * configs that are not compatible with the selected parameter
1193 * list.
1194 */
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001195
Emil Velikov78a74152016-09-30 11:01:28 +01001196 init_fbconfig_for_chooser(&test_config, GL_TRUE);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001197 __glXInitializeVisualConfigFromTags(&test_config, 512,
1198 (const INT32 *) attribList,
Emil Velikov78a74152016-09-30 11:01:28 +01001199 GL_TRUE, GL_TRUE);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001200
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001201 base = 0;
1202 for (i = 0; i < num_configs; i++) {
1203 if (fbconfigs_compatible(&test_config, configs[i])) {
1204 configs[base] = configs[i];
1205 base++;
1206 }
1207 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001208
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001209 if (base == 0) {
1210 return 0;
1211 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001212
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001213 if (base < num_configs) {
1214 (void) memset(&configs[base], 0, sizeof(void *) * (num_configs - base));
1215 }
1216
1217 /* After the incompatible configs are removed, the resulting
1218 * list is sorted according to the rules set out in the various
1219 * specifications.
1220 */
1221
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001222 qsort(configs, base, sizeof(struct glx_config *),
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001223 (int (*)(const void *, const void *)) fbconfig_compare);
1224 return base;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001225}
1226
1227
1228
1229
1230/*
1231** Return the visual that best matches the template. Return None if no
1232** visual matches the template.
1233*/
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001234_GLX_PUBLIC XVisualInfo *
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001235glXChooseVisual(Display * dpy, int screen, int *attribList)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001236{
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001237 XVisualInfo *visualList = NULL;
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001238 struct glx_display *priv;
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001239 struct glx_screen *psc;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001240 struct glx_config test_config;
1241 struct glx_config *config;
1242 struct glx_config *best_config = NULL;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001243
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001244 /*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001245 ** Get a list of all visuals, return if list is empty
1246 */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001247 if (GetGLXPrivScreenConfig(dpy, screen, &priv, &psc) != Success) {
1248 return None;
1249 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001250
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001251
1252 /*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001253 ** Build a template from the defaults and the attribute list
1254 ** Free visual list and return if an unexpected token is encountered
1255 */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001256 init_fbconfig_for_chooser(&test_config, GL_FALSE);
1257 __glXInitializeVisualConfigFromTags(&test_config, 512,
1258 (const INT32 *) attribList,
1259 GL_TRUE, GL_FALSE);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001260
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001261 /*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001262 ** Eliminate visuals that don't meet minimum requirements
1263 ** Compute a score for those that do
1264 ** Remember which visual, if any, got the highest score
Michel Dänzer46b81b02009-05-12 08:01:22 +02001265 ** If no visual is acceptable, return None
1266 ** Otherwise, create an XVisualInfo list with just the selected X visual
1267 ** and return this.
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001268 */
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001269 for (config = psc->visuals; config != NULL; config = config->next) {
1270 if (fbconfigs_compatible(&test_config, config)
1271 && ((best_config == NULL) ||
1272 (fbconfig_compare (&config, &best_config) < 0))) {
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001273 XVisualInfo visualTemplate;
1274 XVisualInfo *newList;
1275 int i;
Michel Dänzer46b81b02009-05-12 08:01:22 +02001276
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001277 visualTemplate.screen = screen;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001278 visualTemplate.visualid = config->visualID;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001279 newList = XGetVisualInfo(dpy, VisualScreenMask | VisualIDMask,
1280 &visualTemplate, &i);
Michel Dänzer46b81b02009-05-12 08:01:22 +02001281
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001282 if (newList) {
Matt Turner7c7b7b02012-09-04 22:52:36 -07001283 free(visualList);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001284 visualList = newList;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001285 best_config = config;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001286 }
1287 }
1288 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001289
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07001290#ifdef GLX_USE_APPLEGL
Eric Engestrom3fdbc462017-09-08 11:56:02 +01001291 if(visualList && env_var_as_boolean("LIBGL_DUMP_VISUALID", false)) {
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07001292 printf("visualid 0x%lx\n", visualList[0].visualid);
1293 }
1294#endif
1295
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001296 return visualList;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001297}
1298
1299
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001300_GLX_PUBLIC const char *
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001301glXQueryExtensionsString(Display * dpy, int screen)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001302{
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001303 struct glx_screen *psc;
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001304 struct glx_display *priv;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001305
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001306 if (GetGLXPrivScreenConfig(dpy, screen, &priv, &psc) != Success) {
1307 return NULL;
1308 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001309
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001310 if (!psc->effectiveGLXexts) {
1311 if (!psc->serverGLXexts) {
1312 psc->serverGLXexts =
1313 __glXQueryServerString(dpy, priv->majorOpcode, screen,
1314 GLX_EXTENSIONS);
1315 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001316
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001317 __glXCalculateUsableExtensions(psc,
Jeremy Huddleston80b280d2010-04-02 01:35:19 -07001318#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001319 (psc->driScreen != NULL),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001320#else
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001321 GL_FALSE,
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001322#endif
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001323 priv->minorVersion);
1324 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001325
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001326 return psc->effectiveGLXexts;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001327}
1328
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001329_GLX_PUBLIC const char *
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001330glXGetClientString(Display * dpy, int name)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001331{
Ian Romanick26b2bee2010-02-04 15:47:54 -08001332 (void) dpy;
1333
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001334 switch (name) {
1335 case GLX_VENDOR:
1336 return (__glXGLXClientVendorName);
1337 case GLX_VERSION:
1338 return (__glXGLXClientVersion);
1339 case GLX_EXTENSIONS:
1340 return (__glXGetClientExtensions());
1341 default:
1342 return NULL;
1343 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001344}
1345
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001346_GLX_PUBLIC const char *
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001347glXQueryServerString(Display * dpy, int screen, int name)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001348{
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001349 struct glx_screen *psc;
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001350 struct glx_display *priv;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001351 const char **str;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001352
1353
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001354 if (GetGLXPrivScreenConfig(dpy, screen, &priv, &psc) != Success) {
1355 return NULL;
1356 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001357
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001358 switch (name) {
1359 case GLX_VENDOR:
1360 str = &priv->serverGLXvendor;
1361 break;
1362 case GLX_VERSION:
1363 str = &priv->serverGLXversion;
1364 break;
1365 case GLX_EXTENSIONS:
1366 str = &psc->serverGLXexts;
1367 break;
1368 default:
1369 return NULL;
1370 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001371
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001372 if (*str == NULL) {
1373 *str = __glXQueryServerString(dpy, priv->majorOpcode, screen, name);
1374 }
1375
1376 return *str;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001377}
1378
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001379
1380/*
1381** EXT_import_context
1382*/
1383
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001384_GLX_PUBLIC Display *
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001385glXGetCurrentDisplay(void)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001386{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001387 struct glx_context *gc = __glXGetCurrentContext();
Bernard Kilarski2e3f0672016-06-07 13:33:33 +03001388 if (gc == &dummyContext)
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001389 return NULL;
1390 return gc->currentDpy;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001391}
1392
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001393_GLX_PUBLIC
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001394GLX_ALIAS(Display *, glXGetCurrentDisplayEXT, (void), (),
1395 glXGetCurrentDisplay)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001396
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07001397#ifndef GLX_USE_APPLEGL
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001398_GLX_PUBLIC GLXContext
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001399glXImportContextEXT(Display *dpy, GLXContextID contextID)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001400{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001401 struct glx_display *priv = __glXInitialize(dpy);
Ian Romanick5a849e82011-12-07 11:15:14 -08001402 struct glx_screen *psc = NULL;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001403 xGLXQueryContextReply reply;
1404 CARD8 opcode;
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001405 struct glx_context *ctx;
Adam Jackson08521622017-09-26 16:38:31 -04001406 int i, renderType = GLX_RGBA_TYPE; /* By default, assume RGBA context */
1407 XID share = None;
1408 struct glx_config *mode = NULL;
Ian Romanick5a849e82011-12-07 11:15:14 -08001409 uint32_t fbconfigID = 0;
1410 uint32_t visualID = 0;
Brian Paul622b1fc2013-03-13 08:35:21 -06001411 uint32_t screen = 0;
Ian Romanick5a849e82011-12-07 11:15:14 -08001412 Bool got_screen = False;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001413
Juha-Pekka Heikkilad28e92f2014-02-07 14:43:57 +02001414 if (priv == NULL)
1415 return NULL;
1416
Ian Romanicked4a65c2011-12-07 16:13:02 -08001417 /* The GLX_EXT_import_context spec says:
1418 *
1419 * "If <contextID> does not refer to a valid context, then a BadContext
1420 * error is generated; if <contextID> refers to direct rendering
1421 * context then no error is generated but glXImportContextEXT returns
1422 * NULL."
1423 *
1424 * If contextID is None, generate BadContext on the client-side. Other
1425 * sorts of invalid contexts will be detected by the server in the
1426 * __glXIsDirect call.
1427 */
1428 if (contextID == None) {
1429 __glXSendError(dpy, GLXBadContext, contextID, X_GLXIsDirect, false);
1430 return NULL;
1431 }
1432
Adam Jackson16f10232018-08-07 16:55:37 -04001433 if (__glXIsDirect(dpy, contextID, NULL))
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001434 return NULL;
1435
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001436 opcode = __glXSetupForCommand(dpy);
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001437 if (!opcode)
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001438 return 0;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001439
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001440 /* Send the glXQueryContextInfoEXT request */
1441 LockDisplay(dpy);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001442
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001443 if (priv->majorVersion > 1 || priv->minorVersion >= 3) {
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001444 xGLXQueryContextReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001445
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001446 GetReq(GLXQueryContext, req);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001447
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001448 req->reqType = opcode;
1449 req->glxCode = X_GLXQueryContext;
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001450 req->context = contextID;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001451 }
1452 else {
1453 xGLXVendorPrivateReq *vpreq;
1454 xGLXQueryContextInfoEXTReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001455
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001456 GetReqExtra(GLXVendorPrivate,
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001457 sz_xGLXQueryContextInfoEXTReq - sz_xGLXVendorPrivateReq,
1458 vpreq);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001459 req = (xGLXQueryContextInfoEXTReq *) vpreq;
1460 req->reqType = opcode;
1461 req->glxCode = X_GLXVendorPrivateWithReply;
1462 req->vendorCode = X_GLXvop_QueryContextInfoEXT;
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001463 req->context = contextID;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001464 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001465
Adam Jackson08521622017-09-26 16:38:31 -04001466 if (_XReply(dpy, (xReply *) & reply, 0, False) &&
1467 reply.n < (INT32_MAX / 2)) {
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001468
Michel Dänzer6b8f3722018-06-01 18:59:36 +02001469 for (i = 0; i < reply.n; i++) {
Adam Jackson08521622017-09-26 16:38:31 -04001470 int prop[2];
1471
1472 _XRead(dpy, (char *)prop, sizeof(prop));
1473 switch (prop[0]) {
1474 case GLX_SCREEN:
1475 screen = prop[1];
1476 got_screen = True;
1477 break;
1478 case GLX_SHARE_CONTEXT_EXT:
1479 share = prop[1];
1480 break;
1481 case GLX_VISUAL_ID_EXT:
1482 visualID = prop[1];
1483 break;
1484 case GLX_FBCONFIG_ID:
1485 fbconfigID = prop[1];
1486 break;
1487 case GLX_RENDER_TYPE:
1488 renderType = prop[1];
1489 break;
1490 }
1491 }
1492 }
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001493 UnlockDisplay(dpy);
1494 SyncHandle();
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001495
Ian Romanick5a849e82011-12-07 11:15:14 -08001496 if (!got_screen)
1497 return NULL;
1498
1499 psc = GetGLXScreenConfigs(dpy, screen);
1500 if (psc == NULL)
1501 return NULL;
1502
1503 if (fbconfigID != 0) {
1504 mode = glx_config_find_fbconfig(psc->configs, fbconfigID);
1505 } else if (visualID != 0) {
1506 mode = glx_config_find_visual(psc->visuals, visualID);
1507 }
1508
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001509 if (mode == NULL)
1510 return NULL;
1511
1512 ctx = indirect_create_context(psc, mode, NULL, renderType);
1513 if (ctx == NULL)
1514 return NULL;
1515
1516 ctx->xid = contextID;
1517 ctx->imported = GL_TRUE;
1518 ctx->share_xid = share;
1519
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001520 return (GLXContext) ctx;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001521}
1522
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07001523#endif
1524
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001525_GLX_PUBLIC int
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001526glXQueryContext(Display * dpy, GLXContext ctx_user, int attribute, int *value)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001527{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001528 struct glx_context *ctx = (struct glx_context *) ctx_user;
1529
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001530 switch (attribute) {
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07001531 case GLX_SHARE_CONTEXT_EXT:
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001532 *value = ctx->share_xid;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001533 break;
1534 case GLX_VISUAL_ID_EXT:
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001535 *value = ctx->config ? ctx->config->visualID : None;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001536 break;
1537 case GLX_SCREEN:
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001538 *value = ctx->screen;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001539 break;
1540 case GLX_FBCONFIG_ID:
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001541 *value = ctx->config ? ctx->config->fbconfigID : None;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001542 break;
1543 case GLX_RENDER_TYPE:
Kristian Høgsberg6ec39db2010-07-23 16:15:31 -04001544 *value = ctx->renderType;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001545 break;
1546 default:
1547 return GLX_BAD_ATTRIBUTE;
1548 }
1549 return Success;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001550}
1551
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001552_GLX_PUBLIC
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001553GLX_ALIAS(int, glXQueryContextInfoEXT,
1554 (Display * dpy, GLXContext ctx, int attribute, int *value),
1555 (dpy, ctx, attribute, value), glXQueryContext)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001556
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001557_GLX_PUBLIC GLXContextID glXGetContextIDEXT(const GLXContext ctx_user)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001558{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001559 struct glx_context *ctx = (struct glx_context *) ctx_user;
1560
Ian Romanick3b9b4222011-12-07 11:37:01 -08001561 return (ctx == NULL) ? None : ctx->xid;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001562}
1563
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001564_GLX_PUBLIC void
Ian Romanick4dbd13c2011-12-07 13:31:27 -08001565glXFreeContextEXT(Display *dpy, GLXContext ctx)
1566{
1567 struct glx_context *gc = (struct glx_context *) ctx;
1568
1569 if (gc == NULL || gc->xid == None)
1570 return;
1571
1572 /* The GLX_EXT_import_context spec says:
1573 *
1574 * "glXFreeContext does not free the server-side context information or
1575 * the XID associated with the server-side context."
1576 *
1577 * Don't send any protocol. Just destroy the client-side tracking of the
1578 * context. Also, only release the context structure if it's not current.
1579 */
1580 __glXLock();
1581 if (gc->currentDpy) {
1582 gc->xid = None;
1583 } else {
1584 gc->vtable->destroy(gc);
1585 }
1586 __glXUnlock();
1587}
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001588
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001589_GLX_PUBLIC GLXFBConfig *
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001590glXChooseFBConfig(Display * dpy, int screen,
1591 const int *attribList, int *nitems)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001592{
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001593 struct glx_config **config_list;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001594 int list_size;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001595
1596
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001597 config_list = (struct glx_config **)
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001598 glXGetFBConfigs(dpy, screen, &list_size);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001599
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001600 if ((config_list != NULL) && (list_size > 0) && (attribList != NULL)) {
Emil Velikov78a74152016-09-30 11:01:28 +01001601 list_size = choose_fbconfig(config_list, list_size, attribList);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001602 if (list_size == 0) {
Matt Turner7c7b7b02012-09-04 22:52:36 -07001603 free(config_list);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001604 config_list = NULL;
1605 }
1606 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001607
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001608 *nitems = list_size;
1609 return (GLXFBConfig *) config_list;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001610}
1611
1612
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001613_GLX_PUBLIC GLXContext
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001614glXCreateNewContext(Display * dpy, GLXFBConfig fbconfig,
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001615 int renderType, GLXContext shareList, Bool allowDirect)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001616{
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001617 struct glx_config *config = (struct glx_config *) fbconfig;
Daniel Czarnowskicf804b42016-02-10 09:36:05 -08001618 struct glx_config **config_list;
1619 int list_size;
1620 unsigned i;
1621
1622 if (!config) {
1623 __glXSendError(dpy, GLXBadFBConfig, 0, X_GLXCreateNewContext, false);
1624 return NULL;
1625 }
1626
1627 config_list = (struct glx_config **)
Mario Kleiner0c94ed02016-10-11 20:42:03 +02001628 glXGetFBConfigs(dpy, config->screen, &list_size);
Daniel Czarnowskicf804b42016-02-10 09:36:05 -08001629
1630 for (i = 0; i < list_size; i++) {
1631 if (config_list[i] == config)
1632 break;
1633 }
1634 free(config_list);
1635
1636 if (i == list_size) {
1637 __glXSendError(dpy, GLXBadFBConfig, 0, X_GLXCreateNewContext, false);
1638 return NULL;
1639 }
Ian Romanick7bcfb662010-02-04 16:37:59 -08001640
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001641 return CreateContext(dpy, config->fbconfigID, config, shareList,
1642 allowDirect, X_GLXCreateNewContext, renderType,
1643 config->screen);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001644}
1645
1646
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001647_GLX_PUBLIC GLXDrawable
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001648glXGetCurrentReadDrawable(void)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001649{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001650 struct glx_context *gc = __glXGetCurrentContext();
1651
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001652 return gc->currentReadable;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001653}
1654
1655
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001656_GLX_PUBLIC GLXFBConfig *
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001657glXGetFBConfigs(Display * dpy, int screen, int *nelements)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001658{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001659 struct glx_display *priv = __glXInitialize(dpy);
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001660 struct glx_config **config_list = NULL;
1661 struct glx_config *config;
1662 unsigned num_configs = 0;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001663 int i;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001664
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001665 *nelements = 0;
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001666 if (priv && (priv->screens != NULL)
Jiri Slabya6ce91f2016-05-17 08:35:29 +02001667 && (screen >= 0) && (screen < ScreenCount(dpy))
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001668 && (priv->screens[screen]->configs != NULL)
1669 && (priv->screens[screen]->configs->fbconfigID
Ian Romanick71a6fb12010-02-04 15:59:51 -08001670 != (int) GLX_DONT_CARE)) {
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001671
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001672 for (config = priv->screens[screen]->configs; config != NULL;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001673 config = config->next) {
1674 if (config->fbconfigID != (int) GLX_DONT_CARE) {
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001675 num_configs++;
1676 }
1677 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001678
Matt Turner7c7b7b02012-09-04 22:52:36 -07001679 config_list = malloc(num_configs * sizeof *config_list);
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001680 if (config_list != NULL) {
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001681 *nelements = num_configs;
1682 i = 0;
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001683 for (config = priv->screens[screen]->configs; config != NULL;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001684 config = config->next) {
1685 if (config->fbconfigID != (int) GLX_DONT_CARE) {
1686 config_list[i] = config;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001687 i++;
1688 }
1689 }
1690 }
1691 }
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001692
1693 return (GLXFBConfig *) config_list;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001694}
1695
1696
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001697_GLX_PUBLIC int
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001698glXGetFBConfigAttrib(Display * dpy, GLXFBConfig fbconfig,
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001699 int attribute, int *value)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001700{
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001701 struct glx_config *config = ValidateGLXFBConfig(dpy, fbconfig);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001702
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001703 if (config == NULL)
1704 return GLXBadFBConfig;
1705
1706 return glx_config_get(config, attribute, value);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001707}
1708
1709
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001710_GLX_PUBLIC XVisualInfo *
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001711glXGetVisualFromFBConfig(Display * dpy, GLXFBConfig fbconfig)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001712{
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001713 XVisualInfo visualTemplate;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001714 struct glx_config *config = (struct glx_config *) fbconfig;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001715 int count;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001716
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001717 /*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001718 ** Get a list of all visuals, return if list is empty
1719 */
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001720 visualTemplate.visualid = config->visualID;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001721 return XGetVisualInfo(dpy, VisualIDMask, &visualTemplate, &count);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001722}
1723
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07001724#ifndef GLX_USE_APPLEGL
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001725/*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001726** GLX_SGI_swap_control
1727*/
Adam Jackson72a0f742020-09-09 12:40:19 -04001728_X_HIDDEN int
1729glXSwapIntervalSGI(int interval)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001730{
1731 xGLXVendorPrivateReq *req;
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001732 struct glx_context *gc = __glXGetCurrentContext();
Adam Jackson45d159c2020-07-16 17:29:26 -04001733#ifdef GLX_DIRECT_RENDERING
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001734 struct glx_screen *psc;
Adam Jackson45d159c2020-07-16 17:29:26 -04001735#endif
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001736 Display *dpy;
1737 CARD32 *interval_ptr;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001738 CARD8 opcode;
1739
Bernard Kilarski2e3f0672016-06-07 13:33:33 +03001740 if (gc == &dummyContext) {
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001741 return GLX_BAD_CONTEXT;
1742 }
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001743
1744 if (interval <= 0) {
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001745 return GLX_BAD_VALUE;
1746 }
1747
Adam Jackson45d159c2020-07-16 17:29:26 -04001748#ifdef GLX_DIRECT_RENDERING
Jesse Barnesefc82e72009-11-10 13:28:01 -08001749 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
1750
Juha-Pekka Heikkilad28e92f2014-02-07 14:43:57 +02001751 if (gc->isDirect && psc && psc->driScreen &&
1752 psc->driScreen->setSwapInterval) {
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04001753 __GLXDRIdrawable *pdraw =
1754 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
Nicolai Hähnlef446f3f2017-02-02 18:06:27 +01001755 /* Simply ignore the command if the GLX drawable has been destroyed but
1756 * the context is still bound.
1757 */
1758 if (pdraw)
1759 psc->driScreen->setSwapInterval(pdraw, interval);
Jesse Barnesefc82e72009-11-10 13:28:01 -08001760 return 0;
1761 }
Vinson Lee16f568a2010-04-01 00:10:28 -07001762#endif
Jesse Barnesefc82e72009-11-10 13:28:01 -08001763
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001764 dpy = gc->currentDpy;
1765 opcode = __glXSetupForCommand(dpy);
1766 if (!opcode) {
1767 return 0;
1768 }
1769
1770 /* Send the glXSwapIntervalSGI request */
1771 LockDisplay(dpy);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001772 GetReqExtra(GLXVendorPrivate, sizeof(CARD32), req);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001773 req->reqType = opcode;
1774 req->glxCode = X_GLXVendorPrivate;
1775 req->vendorCode = X_GLXvop_SwapIntervalSGI;
1776 req->contextTag = gc->currentContextTag;
1777
Ian Romanicka70d5642006-08-30 23:15:02 +00001778 interval_ptr = (CARD32 *) (req + 1);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001779 *interval_ptr = interval;
1780
1781 UnlockDisplay(dpy);
1782 SyncHandle();
1783 XFlush(dpy);
1784
1785 return 0;
1786}
1787
1788
1789/*
1790** GLX_MESA_swap_control
1791*/
Adam Jackson72a0f742020-09-09 12:40:19 -04001792_X_HIDDEN int
1793glXSwapIntervalMESA(unsigned int interval)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001794{
Kristian Høgsberg089fc372010-07-19 16:39:53 -04001795#ifdef GLX_DIRECT_RENDERING
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001796 struct glx_context *gc = __glXGetCurrentContext();
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001797
Adam Jacksonb8239ab2020-09-09 15:54:21 -04001798 if (interval > INT_MAX)
1799 return GLX_BAD_VALUE;
1800
Bernard Kilarski2e3f0672016-06-07 13:33:33 +03001801 if (gc != &dummyContext && gc->isDirect) {
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001802 struct glx_screen *psc;
Jesse Barnesefc82e72009-11-10 13:28:01 -08001803
1804 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
Juha-Pekka Heikkilad28e92f2014-02-07 14:43:57 +02001805 if (psc && psc->driScreen && psc->driScreen->setSwapInterval) {
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04001806 __GLXDRIdrawable *pdraw =
1807 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
Nicolai Hähnlef446f3f2017-02-02 18:06:27 +01001808
1809 /* Simply ignore the command if the GLX drawable has been destroyed but
1810 * the context is still bound.
1811 */
1812 if (!pdraw)
1813 return 0;
1814
1815 return psc->driScreen->setSwapInterval(pdraw, interval);
Jesse Barnesefc82e72009-11-10 13:28:01 -08001816 }
1817 }
Vinson Lee16f568a2010-04-01 00:10:28 -07001818#endif
Jesse Barnesefc82e72009-11-10 13:28:01 -08001819
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001820 return GLX_BAD_CONTEXT;
1821}
Brian Paul841a8232006-03-09 16:25:46 +00001822
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001823
Adam Jackson72a0f742020-09-09 12:40:19 -04001824_X_HIDDEN int
1825glXGetSwapIntervalMESA(void)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001826{
Kristian Høgsberg089fc372010-07-19 16:39:53 -04001827#ifdef GLX_DIRECT_RENDERING
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001828 struct glx_context *gc = __glXGetCurrentContext();
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001829
Bernard Kilarski2e3f0672016-06-07 13:33:33 +03001830 if (gc != &dummyContext && gc->isDirect) {
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001831 struct glx_screen *psc;
Jesse Barnesefc82e72009-11-10 13:28:01 -08001832
1833 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
Juha-Pekka Heikkilad28e92f2014-02-07 14:43:57 +02001834 if (psc && psc->driScreen && psc->driScreen->getSwapInterval) {
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04001835 __GLXDRIdrawable *pdraw =
1836 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
Nicolai Hähnlef446f3f2017-02-02 18:06:27 +01001837 if (pdraw)
1838 return psc->driScreen->getSwapInterval(pdraw);
Jesse Barnesefc82e72009-11-10 13:28:01 -08001839 }
1840 }
Vinson Lee67776f62010-04-02 00:12:59 -07001841#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001842
1843 return 0;
1844}
1845
1846
1847/*
Adam Jackson60ebeb42020-09-09 14:00:35 -04001848** GLX_EXT_swap_control
1849*/
1850_X_HIDDEN void
1851glXSwapIntervalEXT(Display *dpy, GLXDrawable drawable, int interval)
1852{
1853#ifdef GLX_DIRECT_RENDERING
1854 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
1855
1856 /*
1857 * Strictly, this should throw an error if drawable is not a Window or
1858 * GLXWindow. We don't actually track that, so, oh well.
1859 */
1860 if (!pdraw) {
1861 __glXSendError(dpy, BadWindow, drawable, 0, True);
1862 return;
1863 }
1864
Adam Jackson5e9e4572020-09-09 15:14:30 -04001865 if (interval < 0 &&
1866 !__glXExtensionBitIsEnabled(pdraw->psc, EXT_swap_control_tear_bit)) {
Adam Jackson60ebeb42020-09-09 14:00:35 -04001867 __glXSendError(dpy, BadValue, interval, 0, True);
1868 return;
1869 }
1870
1871 pdraw->psc->driScreen->setSwapInterval(pdraw, interval);
1872#endif
1873}
1874
1875
1876/*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001877** GLX_SGI_video_sync
1878*/
Adam Jackson72a0f742020-09-09 12:40:19 -04001879_X_HIDDEN int
1880glXGetVideoSyncSGI(unsigned int *count)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001881{
Adam Jackson45d159c2020-07-16 17:29:26 -04001882#ifdef GLX_DIRECT_RENDERING
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001883 int64_t ust, msc, sbc;
1884 int ret;
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001885 struct glx_context *gc = __glXGetCurrentContext();
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001886 struct glx_screen *psc;
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001887 __GLXDRIdrawable *pdraw;
1888
Bernard Kilarski2e3f0672016-06-07 13:33:33 +03001889 if (gc == &dummyContext)
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001890 return GLX_BAD_CONTEXT;
1891
Kristian Høgsbergc491e582010-07-28 15:33:09 -04001892 if (!gc->isDirect)
Vinson Lee16f568a2010-04-01 00:10:28 -07001893 return GLX_BAD_CONTEXT;
Vinson Lee16f568a2010-04-01 00:10:28 -07001894
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001895 psc = GetGLXScreenConfigs(gc->currentDpy, gc->screen);
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04001896 pdraw = GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001897
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001898 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1899 * FIXME: there should be a GLX encoding for this call. I can find no
1900 * FIXME: documentation for the GLX encoding.
1901 */
Juha-Pekka Heikkilad28e92f2014-02-07 14:43:57 +02001902 if (psc && psc->driScreen && psc->driScreen->getDrawableMSC) {
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001903 ret = psc->driScreen->getDrawableMSC(psc, pdraw, &ust, &msc, &sbc);
1904 *count = (unsigned) msc;
1905 return (ret == True) ? 0 : GLX_BAD_CONTEXT;
1906 }
Vinson Lee67776f62010-04-02 00:12:59 -07001907#endif
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001908
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001909 return GLX_BAD_CONTEXT;
1910}
1911
Adam Jackson72a0f742020-09-09 12:40:19 -04001912_X_HIDDEN int
1913glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001914{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04001915 struct glx_context *gc = __glXGetCurrentContext();
Vinson Lee67776f62010-04-02 00:12:59 -07001916#ifdef GLX_DIRECT_RENDERING
Adam Jackson45d159c2020-07-16 17:29:26 -04001917 struct glx_screen *psc;
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001918 __GLXDRIdrawable *pdraw;
1919 int64_t ust, msc, sbc;
1920 int ret;
Adam Jackson45d159c2020-07-16 17:29:26 -04001921#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001922
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001923 if (divisor <= 0 || remainder < 0)
1924 return GLX_BAD_VALUE;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001925
Bernard Kilarski2e3f0672016-06-07 13:33:33 +03001926 if (gc == &dummyContext)
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001927 return GLX_BAD_CONTEXT;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001928
Vinson Lee16f568a2010-04-01 00:10:28 -07001929#ifdef GLX_DIRECT_RENDERING
Kristian Høgsbergc491e582010-07-28 15:33:09 -04001930 if (!gc->isDirect)
Vinson Lee16f568a2010-04-01 00:10:28 -07001931 return GLX_BAD_CONTEXT;
Vinson Lee16f568a2010-04-01 00:10:28 -07001932
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001933 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04001934 pdraw = GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001935
Juha-Pekka Heikkilad28e92f2014-02-07 14:43:57 +02001936 if (psc && psc->driScreen && psc->driScreen->waitForMSC) {
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001937 ret = psc->driScreen->waitForMSC(pdraw, 0, divisor, remainder, &ust, &msc,
1938 &sbc);
1939 *count = (unsigned) msc;
1940 return (ret == True) ? 0 : GLX_BAD_CONTEXT;
1941 }
Vinson Lee67776f62010-04-02 00:12:59 -07001942#endif
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07001943
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001944 return GLX_BAD_CONTEXT;
1945}
1946
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07001947#endif /* GLX_USE_APPLEGL */
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001948
1949/*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001950** GLX_SGIX_fbconfig
1951** Many of these functions are aliased to GLX 1.3 entry points in the
1952** GLX_functions table.
1953*/
1954
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001955_GLX_PUBLIC
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001956GLX_ALIAS(int, glXGetFBConfigAttribSGIX,
1957 (Display * dpy, GLXFBConfigSGIX config, int attribute, int *value),
1958 (dpy, config, attribute, value), glXGetFBConfigAttrib)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001959
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001960_GLX_PUBLIC GLX_ALIAS(GLXFBConfigSGIX *, glXChooseFBConfigSGIX,
Brian Paulef9cd842009-09-29 09:58:47 -06001961 (Display * dpy, int screen, int *attrib_list,
1962 int *nelements), (dpy, screen, attrib_list, nelements),
1963 glXChooseFBConfig)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001964
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001965_GLX_PUBLIC GLX_ALIAS(XVisualInfo *, glXGetVisualFromFBConfigSGIX,
Brian Paulef9cd842009-09-29 09:58:47 -06001966 (Display * dpy, GLXFBConfigSGIX config),
1967 (dpy, config), glXGetVisualFromFBConfig)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001968
Kyle Brenneman22a9e002016-05-11 14:01:53 -04001969_GLX_PUBLIC GLXPixmap
Brian Paulef9cd842009-09-29 09:58:47 -06001970glXCreateGLXPixmapWithConfigSGIX(Display * dpy,
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001971 GLXFBConfigSGIX fbconfig,
Brian Paulef9cd842009-09-29 09:58:47 -06001972 Pixmap pixmap)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001973{
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07001974#ifndef GLX_USE_APPLEGL
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001975 xGLXVendorPrivateWithReplyReq *vpreq;
1976 xGLXCreateGLXPixmapWithConfigSGIXReq *req;
1977 GLXPixmap xid = None;
1978 CARD8 opcode;
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04001979 struct glx_screen *psc;
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07001980#endif
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001981 struct glx_config *config = (struct glx_config *) fbconfig;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001982
1983
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001984 if ((dpy == NULL) || (config == NULL)) {
1985 return None;
1986 }
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07001987#ifdef GLX_USE_APPLEGL
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001988 if(apple_glx_pixmap_create(dpy, config->screen, pixmap, config))
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07001989 return None;
1990 return pixmap;
1991#else
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001992
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04001993 psc = GetGLXScreenConfigs(dpy, config->screen);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02001994 if ((psc != NULL)
1995 && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)) {
1996 opcode = __glXSetupForCommand(dpy);
1997 if (!opcode) {
1998 return None;
1999 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002000
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002001 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2002 LockDisplay(dpy);
2003 GetReqExtra(GLXVendorPrivateWithReply,
2004 sz_xGLXCreateGLXPixmapWithConfigSGIXReq -
2005 sz_xGLXVendorPrivateWithReplyReq, vpreq);
2006 req = (xGLXCreateGLXPixmapWithConfigSGIXReq *) vpreq;
2007 req->reqType = opcode;
2008 req->glxCode = X_GLXVendorPrivateWithReply;
2009 req->vendorCode = X_GLXvop_CreateGLXPixmapWithConfigSGIX;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04002010 req->screen = config->screen;
2011 req->fbconfig = config->fbconfigID;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002012 req->pixmap = pixmap;
2013 req->glxpixmap = xid = XAllocID(dpy);
2014 UnlockDisplay(dpy);
2015 SyncHandle();
2016 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002017
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002018 return xid;
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07002019#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002020}
2021
Kyle Brenneman22a9e002016-05-11 14:01:53 -04002022_GLX_PUBLIC GLXContext
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002023glXCreateContextWithConfigSGIX(Display * dpy,
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04002024 GLXFBConfigSGIX fbconfig, int renderType,
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002025 GLXContext shareList, Bool allowDirect)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002026{
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002027 GLXContext gc = NULL;
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04002028 struct glx_config *config = (struct glx_config *) fbconfig;
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04002029 struct glx_screen *psc;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002030
2031
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002032 if ((dpy == NULL) || (config == NULL)) {
2033 return None;
2034 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002035
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04002036 psc = GetGLXScreenConfigs(dpy, config->screen);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002037 if ((psc != NULL)
2038 && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)) {
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04002039 gc = CreateContext(dpy, config->fbconfigID, config, shareList,
Ian Romanick22430292010-02-04 16:43:46 -08002040 allowDirect,
Ian Romanick7bcfb662010-02-04 16:37:59 -08002041 X_GLXvop_CreateContextWithConfigSGIX, renderType,
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04002042 config->screen);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002043 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002044
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002045 return gc;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002046}
2047
2048
Kyle Brenneman22a9e002016-05-11 14:01:53 -04002049_GLX_PUBLIC GLXFBConfigSGIX
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002050glXGetFBConfigFromVisualSGIX(Display * dpy, XVisualInfo * vis)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002051{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04002052 struct glx_display *priv;
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04002053 struct glx_screen *psc = NULL;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002054
Stéphane Marchesinfc48de42011-05-26 17:19:03 -07002055 if ((GetGLXPrivScreenConfig(dpy, vis->screen, &priv, &psc) == Success)
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002056 && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)
Ian Romanick71a6fb12010-02-04 15:59:51 -08002057 && (psc->configs->fbconfigID != (int) GLX_DONT_CARE)) {
Kristian Høgsberg6ddf66e2010-07-28 10:07:52 -04002058 return (GLXFBConfigSGIX) glx_config_find_visual(psc->configs,
2059 vis->visualid);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002060 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002061
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002062 return NULL;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002063}
2064
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07002065#ifndef GLX_USE_APPLEGL
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002066/*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002067** GLX_OML_sync_control
2068*/
Adam Jackson72a0f742020-09-09 12:40:19 -04002069_X_HIDDEN Bool
2070glXGetSyncValuesOML(Display *dpy, GLXDrawable drawable,
2071 int64_t *ust, int64_t *msc, int64_t *sbc)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002072{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04002073 struct glx_display * const priv = __glXInitialize(dpy);
Vinson Lee67776f62010-04-02 00:12:59 -07002074#ifdef GLX_DIRECT_RENDERING
Adam Jackson45d159c2020-07-16 17:29:26 -04002075 int ret;
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07002076 __GLXDRIdrawable *pdraw;
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04002077 struct glx_screen *psc;
Adam Jackson45d159c2020-07-16 17:29:26 -04002078#endif
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07002079
2080 if (!priv)
2081 return False;
2082
Vinson Lee67776f62010-04-02 00:12:59 -07002083#ifdef GLX_DIRECT_RENDERING
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04002084 pdraw = GetGLXDRIDrawable(dpy, drawable);
2085 psc = pdraw ? pdraw->psc : NULL;
2086 if (pdraw && psc->driScreen->getDrawableMSC) {
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07002087 ret = psc->driScreen->getDrawableMSC(psc, pdraw, ust, msc, sbc);
2088 return ret;
2089 }
Vinson Lee67776f62010-04-02 00:12:59 -07002090#endif
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07002091
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002092 return False;
2093}
2094
Jon Turneyd512b352018-12-14 13:20:10 +00002095#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
Kristian Høgsberg3d28a262008-03-08 22:28:01 -05002096_X_HIDDEN GLboolean
Lauri Kasanenfe2079c2013-12-15 12:37:55 +02002097__glxGetMscRate(struct glx_screen *psc,
Kristian Høgsberg7a66e542010-07-21 14:09:49 -04002098 int32_t * numerator, int32_t * denominator)
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002099{
Jon Turneyd512b352018-12-14 13:20:10 +00002100#if !defined(GLX_USE_WINDOWSGL)
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002101 XF86VidModeModeLine mode_line;
2102 int dot_clock;
2103 int i;
Ian Romanick26b2bee2010-02-04 15:47:54 -08002104
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002105 if (XF86VidModeQueryVersion(psc->dpy, &i, &i) &&
2106 XF86VidModeGetModeLine(psc->dpy, psc->scr, &dot_clock, &mode_line)) {
2107 unsigned n = dot_clock * 1000;
2108 unsigned d = mode_line.vtotal * mode_line.htotal;
2109
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002110# define V_INTERLACE 0x010
2111# define V_DBLSCAN 0x020
2112
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002113 if (mode_line.flags & V_INTERLACE)
2114 n *= 2;
2115 else if (mode_line.flags & V_DBLSCAN)
2116 d *= 2;
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002117
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002118 /* The OML_sync_control spec requires that if the refresh rate is a
2119 * whole number, that the returned numerator be equal to the refresh
2120 * rate and the denominator be 1.
2121 */
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002122
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002123 if (n % d == 0) {
2124 n /= d;
2125 d = 1;
2126 }
2127 else {
2128 static const unsigned f[] = { 13, 11, 7, 5, 3, 2, 0 };
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002129
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002130 /* This is a poor man's way to reduce a fraction. It's far from
2131 * perfect, but it will work well enough for this situation.
2132 */
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002133
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002134 for (i = 0; f[i] != 0; i++) {
2135 while (n % f[i] == 0 && d % f[i] == 0) {
2136 d /= f[i];
2137 n /= f[i];
2138 }
2139 }
2140 }
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002141
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002142 *numerator = n;
2143 *denominator = d;
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002144
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002145 return True;
2146 }
Jon Turneyd512b352018-12-14 13:20:10 +00002147#endif
Ian Romanick26b2bee2010-02-04 15:47:54 -08002148
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002149 return False;
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002150}
2151#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002152
2153/**
2154 * Determine the refresh rate of the specified drawable and display.
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002155 *
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002156 * \param dpy Display whose refresh rate is to be determined.
2157 * \param drawable Drawable whose refresh rate is to be determined.
2158 * \param numerator Numerator of the refresh rate.
2159 * \param demoninator Denominator of the refresh rate.
2160 * \return If the refresh rate for the specified display and drawable could
2161 * be calculated, True is returned. Otherwise False is returned.
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002162 *
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002163 * \note This function is implemented entirely client-side. A lot of other
2164 * functionality is required to export GLX_OML_sync_control, so on
2165 * XFree86 this function can be called for direct-rendering contexts
2166 * when GLX_OML_sync_control appears in the client extension string.
2167 */
2168
Adam Jackson72a0f742020-09-09 12:40:19 -04002169_X_HIDDEN Bool
2170glXGetMscRateOML(Display * dpy, GLXDrawable drawable,
2171 int32_t * numerator, int32_t * denominator)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002172{
Emil Velikova95ec132018-12-11 16:20:40 +00002173#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) && !defined(GLX_USE_WINDOWSGL)
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04002174 __GLXDRIdrawable *draw = GetGLXDRIDrawable(dpy, drawable);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002175
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002176 if (draw == NULL)
2177 return False;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002178
Lauri Kasanenfe2079c2013-12-15 12:37:55 +02002179 return __glxGetMscRate(draw->psc, numerator, denominator);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002180#else
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002181 (void) dpy;
2182 (void) drawable;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002183 (void) numerator;
2184 (void) denominator;
2185#endif
2186 return False;
2187}
2188
2189
Adam Jackson72a0f742020-09-09 12:40:19 -04002190_X_HIDDEN int64_t
2191glXSwapBuffersMscOML(Display *dpy, GLXDrawable drawable,
2192 int64_t target_msc, int64_t divisor, int64_t remainder)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002193{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04002194 struct glx_context *gc = __glXGetCurrentContext();
Vinson Lee67776f62010-04-02 00:12:59 -07002195#ifdef GLX_DIRECT_RENDERING
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04002196 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04002197 struct glx_screen *psc = pdraw ? pdraw->psc : NULL;
Vinson Lee67776f62010-04-02 00:12:59 -07002198#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002199
Bernard Kilarski2e3f0672016-06-07 13:33:33 +03002200 if (gc == &dummyContext) /* no GLX for this */
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07002201 return -1;
2202
Vinson Lee16f568a2010-04-01 00:10:28 -07002203#ifdef GLX_DIRECT_RENDERING
Kristian Høgsbergc491e582010-07-28 15:33:09 -04002204 if (!pdraw || !gc->isDirect)
Vinson Lee16f568a2010-04-01 00:10:28 -07002205 return -1;
2206#endif
2207
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002208 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2209 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2210 * of -1 if the function failed because of errors detected in the input
2211 * parameters"
2212 */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002213 if (divisor < 0 || remainder < 0 || target_msc < 0)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002214 return -1;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002215 if (divisor > 0 && remainder >= divisor)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002216 return -1;
2217
Jesse Barnes8f4f2a02010-03-22 16:39:11 -07002218 if (target_msc == 0 && divisor == 0 && remainder == 0)
2219 remainder = 1;
2220
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07002221#ifdef GLX_DIRECT_RENDERING
2222 if (psc->driScreen && psc->driScreen->swapBuffers)
2223 return (*psc->driScreen->swapBuffers)(pdraw, target_msc, divisor,
Marek Olšák5b7e9b72012-11-13 17:06:37 +01002224 remainder, False);
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07002225#endif
2226
2227 return -1;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002228}
2229
2230
Adam Jackson72a0f742020-09-09 12:40:19 -04002231_X_HIDDEN Bool
2232glXWaitForMscOML(Display *dpy, GLXDrawable drawable, int64_t target_msc,
2233 int64_t divisor, int64_t remainder, int64_t *ust,
2234 int64_t *msc, int64_t *sbc)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002235{
Vinson Lee67776f62010-04-02 00:12:59 -07002236#ifdef GLX_DIRECT_RENDERING
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04002237 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04002238 struct glx_screen *psc = pdraw ? pdraw->psc : NULL;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002239 int ret;
Jon TURNEYae9487c2010-08-09 14:47:26 +01002240#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002241
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07002242
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002243 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2244 * error", but the return type in the spec is Bool.
2245 */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002246 if (divisor < 0 || remainder < 0 || target_msc < 0)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002247 return False;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002248 if (divisor > 0 && remainder >= divisor)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002249 return False;
2250
Vinson Lee67776f62010-04-02 00:12:59 -07002251#ifdef GLX_DIRECT_RENDERING
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07002252 if (pdraw && psc->driScreen && psc->driScreen->waitForMSC) {
2253 ret = psc->driScreen->waitForMSC(pdraw, target_msc, divisor, remainder,
2254 ust, msc, sbc);
2255 return ret;
2256 }
Vinson Lee67776f62010-04-02 00:12:59 -07002257#endif
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07002258
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002259 return False;
2260}
2261
2262
Adam Jackson72a0f742020-09-09 12:40:19 -04002263_X_HIDDEN Bool
2264glXWaitForSbcOML(Display *dpy, GLXDrawable drawable, int64_t target_sbc,
2265 int64_t *ust, int64_t *msc, int64_t *sbc)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002266{
Vinson Lee67776f62010-04-02 00:12:59 -07002267#ifdef GLX_DIRECT_RENDERING
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04002268 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04002269 struct glx_screen *psc = pdraw ? pdraw->psc : NULL;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002270 int ret;
Jon TURNEYae9487c2010-08-09 14:47:26 +01002271#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002272
2273 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2274 * error", but the return type in the spec is Bool.
2275 */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002276 if (target_sbc < 0)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002277 return False;
Vinson Lee67776f62010-04-02 00:12:59 -07002278
2279#ifdef GLX_DIRECT_RENDERING
kleinerm251bf292010-02-19 12:28:26 -08002280 if (pdraw && psc->driScreen && psc->driScreen->waitForSBC) {
Jesse Barnesdaf7fe62009-09-15 23:23:09 -07002281 ret = psc->driScreen->waitForSBC(pdraw, target_sbc, ust, msc, sbc);
2282 return ret;
2283 }
Vinson Lee67776f62010-04-02 00:12:59 -07002284#endif
2285
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002286 return False;
2287}
2288
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002289/*@}*/
2290
2291
2292/**
2293 * Mesa extension stubs. These will help reduce portability problems.
2294 */
2295/*@{*/
2296
2297/**
2298 * Release all buffers associated with the specified GLX drawable.
2299 *
2300 * \todo
2301 * This function was intended for stand-alone Mesa. The issue there is that
2302 * the library doesn't get any notification when a window is closed. In
2303 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2304 * supported, there are 3 different functions to destroy a drawable. It
2305 * should be possible to create GLX protocol (or have it determine which
2306 * protocol to use based on the type of the drawable) to have one function
2307 * do the work of 3. For the direct-rendering case, this function could
2308 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2309 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2310 * would need to be used. This really should be done as part of the new DRI
2311 * interface work.
2312 *
2313 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2314 * __driGarbageCollectDrawables
2315 * glXDestroyGLXPixmap
2316 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2317 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2318 */
Adam Jackson72a0f742020-09-09 12:40:19 -04002319_X_HIDDEN Bool
2320glXReleaseBuffersMESA(Display * dpy, GLXDrawable d)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002321{
2322 (void) dpy;
2323 (void) d;
2324 return False;
2325}
2326
2327
Kyle Brenneman22a9e002016-05-11 14:01:53 -04002328_GLX_PUBLIC GLXPixmap
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002329glXCreateGLXPixmapMESA(Display * dpy, XVisualInfo * visual,
2330 Pixmap pixmap, Colormap cmap)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002331{
2332 (void) dpy;
2333 (void) visual;
2334 (void) pixmap;
2335 (void) cmap;
2336 return 0;
2337}
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002338
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002339/*@}*/
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002340
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002341
2342/**
2343 * GLX_MESA_copy_sub_buffer
2344 */
Brian Paulf2ad1b62006-03-31 15:48:04 +00002345#define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
Adam Jackson72a0f742020-09-09 12:40:19 -04002346_X_HIDDEN void
2347glXCopySubBufferMESA(Display * dpy, GLXDrawable drawable,
2348 int x, int y, int width, int height)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002349{
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002350 xGLXVendorPrivateReq *req;
Kristian Høgsbergc356f582010-07-28 11:16:00 -04002351 struct glx_context *gc;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002352 GLXContextTag tag;
2353 CARD32 *drawable_ptr;
2354 INT32 *x_ptr, *y_ptr, *w_ptr, *h_ptr;
2355 CARD8 opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002356
Kristian Høgsberg2235b1c2010-07-26 15:50:02 -04002357#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
Kristian Høgsbergeeaab202010-07-22 22:36:37 -04002358 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002359 if (pdraw != NULL) {
Kristian Høgsberg66fc35c2010-07-28 10:28:43 -04002360 struct glx_screen *psc = pdraw->psc;
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002361 if (psc->driScreen->copySubBuffer != NULL) {
Marek Olšák5b7e9b72012-11-13 17:06:37 +01002362 (*psc->driScreen->copySubBuffer) (pdraw, x, y, width, height, True);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002363 }
Brian Paulf2ad1b62006-03-31 15:48:04 +00002364
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002365 return;
2366 }
Brian Paulf2ad1b62006-03-31 15:48:04 +00002367#endif
2368
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002369 opcode = __glXSetupForCommand(dpy);
2370 if (!opcode)
2371 return;
Brian Paulf2ad1b62006-03-31 15:48:04 +00002372
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002373 /*
Brian Paulf2ad1b62006-03-31 15:48:04 +00002374 ** The calling thread may or may not have a current context. If it
2375 ** does, send the context tag so the server can do a flush.
2376 */
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002377 gc = __glXGetCurrentContext();
Bernard Kilarski2e3f0672016-06-07 13:33:33 +03002378 if ((gc != &dummyContext) && (dpy == gc->currentDpy) &&
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002379 ((drawable == gc->currentDrawable) ||
2380 (drawable == gc->currentReadable))) {
2381 tag = gc->currentContextTag;
2382 }
2383 else {
2384 tag = 0;
2385 }
Brian Paulf2ad1b62006-03-31 15:48:04 +00002386
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002387 LockDisplay(dpy);
2388 GetReqExtra(GLXVendorPrivate, sizeof(CARD32) + sizeof(INT32) * 4, req);
2389 req->reqType = opcode;
2390 req->glxCode = X_GLXVendorPrivate;
2391 req->vendorCode = X_GLXvop_CopySubBufferMESA;
2392 req->contextTag = tag;
Brian Paulf2ad1b62006-03-31 15:48:04 +00002393
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002394 drawable_ptr = (CARD32 *) (req + 1);
2395 x_ptr = (INT32 *) (drawable_ptr + 1);
2396 y_ptr = (INT32 *) (drawable_ptr + 2);
2397 w_ptr = (INT32 *) (drawable_ptr + 3);
2398 h_ptr = (INT32 *) (drawable_ptr + 4);
Brian Paulf2ad1b62006-03-31 15:48:04 +00002399
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002400 *drawable_ptr = drawable;
2401 *x_ptr = x;
2402 *y_ptr = y;
2403 *w_ptr = width;
2404 *h_ptr = height;
Brian Paulf2ad1b62006-03-31 15:48:04 +00002405
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002406 UnlockDisplay(dpy);
2407 SyncHandle();
Brian Paulf2ad1b62006-03-31 15:48:04 +00002408}
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002409
Kristian Høgsberg643b2af2010-05-21 10:36:56 -04002410/*@{*/
Adam Jackson72a0f742020-09-09 12:40:19 -04002411_X_HIDDEN void
2412glXBindTexImageEXT(Display *dpy, GLXDrawable drawable, int buffer,
2413 const int *attrib_list)
Kristian Høgsberg643b2af2010-05-21 10:36:56 -04002414{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04002415 struct glx_context *gc = __glXGetCurrentContext();
Kristian Høgsberg643b2af2010-05-21 10:36:56 -04002416
Adam Jacksonbcb15be2017-11-14 15:13:01 -05002417 if (gc->vtable->bind_tex_image == NULL)
Kristian Høgsberg643b2af2010-05-21 10:36:56 -04002418 return;
2419
2420 gc->vtable->bind_tex_image(dpy, drawable, buffer, attrib_list);
2421}
2422
Adam Jackson72a0f742020-09-09 12:40:19 -04002423_X_HIDDEN void
2424glXReleaseTexImageEXT(Display * dpy, GLXDrawable drawable, int buffer)
Kristian Høgsberg643b2af2010-05-21 10:36:56 -04002425{
Kristian Høgsbergc356f582010-07-28 11:16:00 -04002426 struct glx_context *gc = __glXGetCurrentContext();
Kristian Høgsberg643b2af2010-05-21 10:36:56 -04002427
Adam Jacksonbcb15be2017-11-14 15:13:01 -05002428 if (gc->vtable->release_tex_image == NULL)
Kristian Høgsberg643b2af2010-05-21 10:36:56 -04002429 return;
2430
2431 gc->vtable->release_tex_image(dpy, drawable, buffer);
2432}
2433
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002434/*@}*/
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002435
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07002436#endif /* GLX_USE_APPLEGL */
2437
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002438/*
2439** glXGetProcAddress support
2440*/
2441
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002442struct name_address_pair
2443{
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002444 const char *Name;
2445 GLvoid *Address;
2446};
2447
2448#define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2449#define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2450
2451static const struct name_address_pair GLX_functions[] = {
2452 /*** GLX_VERSION_1_0 ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002453 GLX_FUNCTION(glXChooseVisual),
2454 GLX_FUNCTION(glXCopyContext),
2455 GLX_FUNCTION(glXCreateContext),
2456 GLX_FUNCTION(glXCreateGLXPixmap),
2457 GLX_FUNCTION(glXDestroyContext),
2458 GLX_FUNCTION(glXDestroyGLXPixmap),
2459 GLX_FUNCTION(glXGetConfig),
2460 GLX_FUNCTION(glXGetCurrentContext),
2461 GLX_FUNCTION(glXGetCurrentDrawable),
2462 GLX_FUNCTION(glXIsDirect),
2463 GLX_FUNCTION(glXMakeCurrent),
2464 GLX_FUNCTION(glXQueryExtension),
2465 GLX_FUNCTION(glXQueryVersion),
2466 GLX_FUNCTION(glXSwapBuffers),
2467 GLX_FUNCTION(glXUseXFont),
2468 GLX_FUNCTION(glXWaitGL),
2469 GLX_FUNCTION(glXWaitX),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002470
2471 /*** GLX_VERSION_1_1 ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002472 GLX_FUNCTION(glXGetClientString),
2473 GLX_FUNCTION(glXQueryExtensionsString),
2474 GLX_FUNCTION(glXQueryServerString),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002475
2476 /*** GLX_VERSION_1_2 ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002477 GLX_FUNCTION(glXGetCurrentDisplay),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002478
2479 /*** GLX_VERSION_1_3 ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002480 GLX_FUNCTION(glXChooseFBConfig),
2481 GLX_FUNCTION(glXCreateNewContext),
2482 GLX_FUNCTION(glXCreatePbuffer),
2483 GLX_FUNCTION(glXCreatePixmap),
2484 GLX_FUNCTION(glXCreateWindow),
2485 GLX_FUNCTION(glXDestroyPbuffer),
2486 GLX_FUNCTION(glXDestroyPixmap),
2487 GLX_FUNCTION(glXDestroyWindow),
2488 GLX_FUNCTION(glXGetCurrentReadDrawable),
2489 GLX_FUNCTION(glXGetFBConfigAttrib),
2490 GLX_FUNCTION(glXGetFBConfigs),
2491 GLX_FUNCTION(glXGetSelectedEvent),
2492 GLX_FUNCTION(glXGetVisualFromFBConfig),
2493 GLX_FUNCTION(glXMakeContextCurrent),
2494 GLX_FUNCTION(glXQueryContext),
2495 GLX_FUNCTION(glXQueryDrawable),
2496 GLX_FUNCTION(glXSelectEvent),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002497
Adam Jacksone6484422020-09-09 13:28:02 -04002498 /*** GLX_SGIX_fbconfig ***/
2499 GLX_FUNCTION2(glXGetFBConfigAttribSGIX, glXGetFBConfigAttrib),
2500 GLX_FUNCTION2(glXChooseFBConfigSGIX, glXChooseFBConfig),
2501 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX),
2502 GLX_FUNCTION(glXCreateContextWithConfigSGIX),
2503 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX, glXGetVisualFromFBConfig),
2504 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX),
2505
2506 /*** GLX_ARB_get_proc_address ***/
2507 GLX_FUNCTION(glXGetProcAddressARB),
2508
2509 /*** GLX 1.4 ***/
2510 GLX_FUNCTION2(glXGetProcAddress, glXGetProcAddressARB),
2511
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07002512#ifndef GLX_USE_APPLEGL
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002513 /*** GLX_SGI_swap_control ***/
Adam Jackson72a0f742020-09-09 12:40:19 -04002514 GLX_FUNCTION(glXSwapIntervalSGI),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002515
2516 /*** GLX_SGI_video_sync ***/
Adam Jackson72a0f742020-09-09 12:40:19 -04002517 GLX_FUNCTION(glXGetVideoSyncSGI),
2518 GLX_FUNCTION(glXWaitVideoSyncSGI),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002519
2520 /*** GLX_SGI_make_current_read ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002521 GLX_FUNCTION2(glXMakeCurrentReadSGI, glXMakeContextCurrent),
2522 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI, glXGetCurrentReadDrawable),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002523
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002524 /*** GLX_EXT_import_context ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002525 GLX_FUNCTION(glXFreeContextEXT),
2526 GLX_FUNCTION(glXGetContextIDEXT),
2527 GLX_FUNCTION2(glXGetCurrentDisplayEXT, glXGetCurrentDisplay),
2528 GLX_FUNCTION(glXImportContextEXT),
2529 GLX_FUNCTION2(glXQueryContextInfoEXT, glXQueryContext),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002530
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002531 /*** GLX_SGIX_pbuffer ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002532 GLX_FUNCTION(glXCreateGLXPbufferSGIX),
2533 GLX_FUNCTION(glXDestroyGLXPbufferSGIX),
2534 GLX_FUNCTION(glXQueryGLXPbufferSGIX),
2535 GLX_FUNCTION(glXSelectEventSGIX),
2536 GLX_FUNCTION(glXGetSelectedEventSGIX),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002537
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002538 /*** GLX_MESA_copy_sub_buffer ***/
Adam Jackson72a0f742020-09-09 12:40:19 -04002539 GLX_FUNCTION(glXCopySubBufferMESA),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002540
2541 /*** GLX_MESA_pixmap_colormap ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002542 GLX_FUNCTION(glXCreateGLXPixmapMESA),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002543
2544 /*** GLX_MESA_release_buffers ***/
Adam Jackson72a0f742020-09-09 12:40:19 -04002545 GLX_FUNCTION(glXReleaseBuffersMESA),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002546
2547 /*** GLX_MESA_swap_control ***/
Adam Jackson72a0f742020-09-09 12:40:19 -04002548 GLX_FUNCTION(glXSwapIntervalMESA),
2549 GLX_FUNCTION(glXGetSwapIntervalMESA),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002550
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002551 /*** GLX_OML_sync_control ***/
Adam Jackson72a0f742020-09-09 12:40:19 -04002552 GLX_FUNCTION(glXWaitForSbcOML),
2553 GLX_FUNCTION(glXWaitForMscOML),
2554 GLX_FUNCTION(glXSwapBuffersMscOML),
2555 GLX_FUNCTION(glXGetMscRateOML),
2556 GLX_FUNCTION(glXGetSyncValuesOML),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002557
Brian Paul42725d62006-02-07 00:39:56 +00002558 /*** GLX_EXT_texture_from_pixmap ***/
Adam Jackson72a0f742020-09-09 12:40:19 -04002559 GLX_FUNCTION(glXBindTexImageEXT),
2560 GLX_FUNCTION(glXReleaseTexImageEXT),
Adam Jackson60ebeb42020-09-09 14:00:35 -04002561
2562 /*** GLX_EXT_swap_control ***/
2563 GLX_FUNCTION(glXSwapIntervalEXT),
Jeremy Huddlestonad503c42010-04-01 11:01:31 -07002564#endif
Brian Paul42725d62006-02-07 00:39:56 +00002565
Jon TURNEYf647a722014-06-02 18:52:15 +01002566#if defined(GLX_DIRECT_RENDERING) && defined(GLX_USE_DRM)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002567 /*** DRI configuration ***/
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002568 GLX_FUNCTION(glXGetScreenDriver),
2569 GLX_FUNCTION(glXGetDriverConfig),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002570#endif
2571
Ian Romanick78aa71a2011-11-30 11:12:49 -08002572 /*** GLX_ARB_create_context and GLX_ARB_create_context_profile ***/
2573 GLX_FUNCTION(glXCreateContextAttribsARB),
2574
Ian Romanick6c28c032013-02-15 22:35:24 -08002575 /*** GLX_MESA_query_renderer ***/
2576 GLX_FUNCTION(glXQueryRendererIntegerMESA),
2577 GLX_FUNCTION(glXQueryRendererStringMESA),
2578 GLX_FUNCTION(glXQueryCurrentRendererIntegerMESA),
2579 GLX_FUNCTION(glXQueryCurrentRendererStringMESA),
2580
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002581 {NULL, NULL} /* end of list */
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002582};
2583
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002584static const GLvoid *
2585get_glx_proc_address(const char *funcName)
2586{
2587 GLuint i;
2588
2589 /* try static functions */
2590 for (i = 0; GLX_functions[i].Name; i++) {
2591 if (strcmp(GLX_functions[i].Name, funcName) == 0)
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002592 return GLX_functions[i].Address;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002593 }
2594
2595 return NULL;
2596}
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002597
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002598/**
2599 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2600 * \c glXGetProcAddress.
2601 *
2602 * \param procName Name of a GL or GLX function.
2603 * \returns A pointer to the named function
2604 *
2605 * \sa glXGetProcAddress
2606 */
Kyle Brenneman22a9e002016-05-11 14:01:53 -04002607_GLX_PUBLIC void (*glXGetProcAddressARB(const GLubyte * procName)) (void)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002608{
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002609 typedef void (*gl_function) (void);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002610 gl_function f;
2611
2612
2613 /* Search the table of GLX and internal functions first. If that
2614 * fails and the supplied name could be a valid core GL name, try
2615 * searching the core GL function table. This check is done to prevent
2616 * DRI based drivers from searching the core GL function table for
2617 * internal API functions.
2618 */
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002619 f = (gl_function) get_glx_proc_address((const char *) procName);
RALOVICH, Kristóf08962682009-08-12 12:41:22 +02002620 if ((f == NULL) && (procName[0] == 'g') && (procName[1] == 'l')
2621 && (procName[2] != 'X')) {
Emil Velikov6177d602017-04-13 17:17:45 +01002622#ifdef GLX_INDIRECT_RENDERING
Chia-I Wue8c7d752010-12-26 18:24:13 +08002623 f = (gl_function) __indirect_get_proc_address((const char *) procName);
Matt Turner027ce0c2012-01-24 11:34:42 -05002624#endif
Chia-I Wue8c7d752010-12-26 18:24:13 +08002625 if (!f)
2626 f = (gl_function) _glapi_get_proc_address((const char *) procName);
Jeremy Huddleston559e4f82011-06-15 00:27:55 -07002627 if (!f) {
2628 struct glx_context *gc = __glXGetCurrentContext();
2629
2630 if (gc != NULL && gc->vtable->get_proc_address != NULL)
2631 f = gc->vtable->get_proc_address((const char *) procName);
2632 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002633 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002634 return f;
2635}
2636
2637/**
2638 * Get the address of a named GL function. This is the GLX 1.4 name for
2639 * \c glXGetProcAddressARB.
2640 *
2641 * \param procName Name of a GL or GLX function.
2642 * \returns A pointer to the named function
2643 *
2644 * \sa glXGetProcAddressARB
2645 */
Emil Velikov9898bcf2016-12-05 19:52:44 +00002646_GLX_PUBLIC
2647GLX_ALIAS(__GLXextFuncPtr, glXGetProcAddress,
2648 (const GLubyte * procName),
2649 (procName), glXGetProcAddressARB)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002650
Jeremy Huddleston80b280d2010-04-02 01:35:19 -07002651#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
Marek Olšák37d3a262016-03-03 18:43:53 +01002652
Marek Olšák64c25932016-11-02 18:59:22 +01002653PUBLIC int
Marek Olšák37d3a262016-03-03 18:43:53 +01002654MesaGLInteropGLXQueryDeviceInfo(Display *dpy, GLXContext context,
Emil Velikov13faddb2016-05-30 10:56:33 +01002655 struct mesa_glinterop_device_info *out)
Marek Olšák37d3a262016-03-03 18:43:53 +01002656{
2657 struct glx_context *gc = (struct glx_context*)context;
2658 int ret;
2659
2660 __glXLock();
2661
2662 if (!gc || gc->xid == None || !gc->isDirect) {
2663 __glXUnlock();
2664 return MESA_GLINTEROP_INVALID_CONTEXT;
2665 }
2666
2667 if (!gc->vtable->interop_query_device_info) {
2668 __glXUnlock();
2669 return MESA_GLINTEROP_UNSUPPORTED;
2670 }
2671
2672 ret = gc->vtable->interop_query_device_info(gc, out);
2673 __glXUnlock();
2674 return ret;
2675}
2676
Marek Olšák64c25932016-11-02 18:59:22 +01002677PUBLIC int
Marek Olšák37d3a262016-03-03 18:43:53 +01002678MesaGLInteropGLXExportObject(Display *dpy, GLXContext context,
Emil Velikov13faddb2016-05-30 10:56:33 +01002679 struct mesa_glinterop_export_in *in,
2680 struct mesa_glinterop_export_out *out)
Marek Olšák37d3a262016-03-03 18:43:53 +01002681{
2682 struct glx_context *gc = (struct glx_context*)context;
2683 int ret;
2684
2685 __glXLock();
2686
2687 if (!gc || gc->xid == None || !gc->isDirect) {
2688 __glXUnlock();
2689 return MESA_GLINTEROP_INVALID_CONTEXT;
2690 }
2691
2692 if (!gc->vtable->interop_export_object) {
2693 __glXUnlock();
2694 return MESA_GLINTEROP_UNSUPPORTED;
2695 }
2696
2697 ret = gc->vtable->interop_export_object(gc, in, out);
2698 __glXUnlock();
2699 return ret;
2700}
2701
2702#endif /* defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) */