blob: 72ab48929d3133fd7ade275f808090b2e3a2d3de [file] [log] [blame]
RALOVICH, Kristóf58b72102008-10-11 14:27:07 +02001/* -*- mode: c; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 3; coding: utf-8-unix -*- */
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002/*
Adam Jacksondc8058c2008-09-19 17:16:53 -04003 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
4 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice including the dates of first publication and
14 * either this permission notice or a reference to
15 * http://oss.sgi.com/projects/FreeB/
16 * shall be included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
23 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
25 *
26 * Except as contained in this notice, the name of Silicon Graphics, Inc.
27 * shall not be used in advertising or otherwise to promote the sale, use or
28 * other dealings in this Software without prior written authorization from
29 * Silicon Graphics, Inc.
30 */
Adam Jacksoncb3610e2004-10-25 21:09:16 +000031
32/**
33 * \file glxcmds.c
34 * Client-side GLX interface.
35 */
36
Adam Jacksoncb3610e2004-10-25 21:09:16 +000037#include "glxclient.h"
Adam Jacksoncb3610e2004-10-25 21:09:16 +000038#include "glapi.h"
Adam Jacksoncb3610e2004-10-25 21:09:16 +000039#include "glxextensions.h"
40#include "glcontextmodes.h"
George Sapountzisdf04ffb2008-04-18 17:28:34 +030041
42#ifdef GLX_DIRECT_RENDERING
Adam Jacksoncb3610e2004-10-25 21:09:16 +000043#include <sys/time.h>
George Sapountzisdf04ffb2008-04-18 17:28:34 +030044#include <X11/extensions/xf86vmode.h>
45#include "xf86dri.h"
46#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +000047
Adam Jacksoncb3610e2004-10-25 21:09:16 +000048static const char __glXGLXClientVendorName[] = "SGI";
49static const char __glXGLXClientVersion[] = "1.4";
50
51
Adam Jacksoncb3610e2004-10-25 21:09:16 +000052/****************************************************************************/
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -050053
54#ifdef GLX_DIRECT_RENDERING
55
56static Bool windowExistsFlag;
Kristian Høgsberg77c7f902008-10-14 23:07:42 -040057static int windowExistsErrorHandler(Display *dpy, XErrorEvent *xerr)
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -050058{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -040059 if (xerr->error_code == BadWindow) {
60 windowExistsFlag = GL_FALSE;
61 }
62 return 0;
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -050063}
64
65/**
66 * Find drawables in the local hash that have been destroyed on the
67 * server.
68 *
69 * \param dpy Display to destroy drawables for
70 * \param screen Screen number to destroy drawables for
71 */
Kristian Høgsberg77c7f902008-10-14 23:07:42 -040072static void GarbageCollectDRIDrawables(Display *dpy, __GLXscreenConfigs *sc)
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -050073{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -040074 XID draw;
75 __GLXDRIdrawable *pdraw;
76 XWindowAttributes xwa;
77 int (*oldXErrorHandler)(Display *, XErrorEvent *);
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -050078
Kristian Høgsberg77c7f902008-10-14 23:07:42 -040079 /* Set no-op error handler so Xlib doesn't bail out if the windows
80 * has alreay been destroyed on the server. */
81 XSync(dpy, GL_FALSE);
82 oldXErrorHandler = XSetErrorHandler(windowExistsErrorHandler);
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -050083
Kristian Høgsberg77c7f902008-10-14 23:07:42 -040084 if (__glxHashFirst(sc->drawHash, &draw, (void *)&pdraw) == 1) {
85 do {
86 windowExistsFlag = GL_TRUE;
87 XGetWindowAttributes(dpy, draw, &xwa); /* dummy request */
88 if (!windowExistsFlag) {
89 /* Destroy the local drawable data, if the drawable no
90 longer exists in the Xserver */
91 (*pdraw->destroyDrawable)(pdraw);
92 __glxHashDelete(sc->drawHash, draw);
93 }
94 } while (__glxHashNext(sc->drawHash, &draw, (void *)&pdraw) == 1);
95 }
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -050096
Kristian Høgsberg77c7f902008-10-14 23:07:42 -040097 XSync(dpy, GL_FALSE);
98 XSetErrorHandler(oldXErrorHandler);
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -050099}
100
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400101extern __GLXDRIdrawable *
102GetGLXDRIDrawable(Display *dpy, GLXDrawable drawable, int * const scrn_num);
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -0400103
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000104/**
105 * Get the __DRIdrawable for the drawable associated with a GLXContext
106 *
107 * \param dpy The display associated with \c drawable.
108 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -0500109 * \param scrn_num If non-NULL, the drawables screen is stored there
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000110 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
111 * the drawable is not associated with a direct-rendering context.
112 */
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -0400113_X_HIDDEN __GLXDRIdrawable *
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400114GetGLXDRIDrawable(Display *dpy, GLXDrawable drawable, int * const scrn_num)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000115{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400116 __GLXdisplayPrivate *priv = __glXInitialize(dpy);
117 __GLXDRIdrawable *pdraw;
118 const unsigned screen_count = ScreenCount(dpy);
119 unsigned i;
120 __GLXscreenConfigs *psc;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000121
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400122 if (priv == NULL)
123 return NULL;
124
125 for (i = 0; i < screen_count; i++) {
126 psc = &priv->screenConfigs[i];
127 if (psc->drawHash == NULL)
128 continue;
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -0400129
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400130 if (__glxHashLookup(psc->drawHash, drawable, (void *) &pdraw) == 0) {
131 if (scrn_num != NULL)
132 *scrn_num = i;
133 return pdraw;
134 }
135 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000136
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400137 return NULL;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000138}
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -0500139
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000140#endif
141
142
143/**
144 * Get the GLX per-screen data structure associated with a GLX context.
145 *
146 * \param dpy Display for which the GLX per-screen information is to be
147 * retrieved.
148 * \param scrn Screen on \c dpy for which the GLX per-screen information is
149 * to be retrieved.
150 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
151 * specify a valid GLX screen, or NULL otherwise.
152 *
153 * \todo Should this function validate that \c scrn is within the screen
154 * number range for \c dpy?
155 */
156
157static __GLXscreenConfigs *
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400158GetGLXScreenConfigs(Display *dpy, int scrn)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000159{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400160 __GLXdisplayPrivate * const priv = __glXInitialize(dpy);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000161
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400162 return (priv->screenConfigs != NULL) ? &priv->screenConfigs[scrn] : NULL;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000163}
164
165
166static int
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400167GetGLXPrivScreenConfig( Display *dpy, int scrn, __GLXdisplayPrivate ** ppriv,
168 __GLXscreenConfigs ** ppsc )
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000169{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400170 /* Initialize the extension, if needed . This has the added value
171 * of initializing/allocating the display private
172 */
173
174 if ( dpy == NULL ) {
175 return GLX_NO_EXTENSION;
176 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000177
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400178 *ppriv = __glXInitialize(dpy);
179 if ( *ppriv == NULL ) {
180 return GLX_NO_EXTENSION;
181 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000182
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400183 /* Check screen number to see if its valid */
184 if ((scrn < 0) || (scrn >= ScreenCount(dpy))) {
185 return GLX_BAD_SCREEN;
186 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000187
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400188 /* Check to see if the GL is supported on this screen */
189 *ppsc = &((*ppriv)->screenConfigs[scrn]);
190 if ( (*ppsc)->configs == NULL ) {
191 /* No support for GL on this screen regardless of visual */
192 return GLX_BAD_VISUAL;
193 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000194
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400195 return Success;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000196}
197
198
199/**
200 * Determine if a \c GLXFBConfig supplied by the application is valid.
201 *
202 * \param dpy Application supplied \c Display pointer.
203 * \param config Application supplied \c GLXFBConfig.
204 *
205 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
206 * \c __GLcontextModes structure is returned. Otherwise, \c NULL
207 * is returned.
208 */
209static __GLcontextModes *
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400210ValidateGLXFBConfig( Display * dpy, GLXFBConfig config )
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000211{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400212 __GLXdisplayPrivate * const priv = __glXInitialize(dpy);
213 const unsigned num_screens = ScreenCount(dpy);
214 unsigned i;
215 const __GLcontextModes * modes;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000216
217
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400218 if ( priv != NULL ) {
219 for ( i = 0 ; i < num_screens ; i++ ) {
220 for ( modes = priv->screenConfigs[i].configs
221 ; modes != NULL
222 ; modes = modes->next ) {
223 if ( modes == (__GLcontextModes *) config ) {
224 return (__GLcontextModes *) config;
225 }
226 }
227 }
228 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000229
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400230 return NULL;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000231}
232
233
234/**
235 * \todo It should be possible to move the allocate of \c client_state_private
236 * later in the function for direct-rendering contexts. Direct-rendering
237 * contexts don't need to track client state, so they don't need that memory
238 * at all.
239 *
240 * \todo Eliminate \c __glXInitVertexArrayState. Replace it with a new
241 * function called \c __glXAllocateClientState that allocates the memory and
242 * does all the initialization (including the pixel pack / unpack).
243 */
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400244static
245GLXContext AllocateGLXContext( Display *dpy )
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000246{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400247 GLXContext gc;
248 int bufSize;
249 CARD8 opcode;
250 __GLXattribute *state;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000251
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400252 if (!dpy)
253 return NULL;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000254
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400255 opcode = __glXSetupForCommand(dpy);
256 if (!opcode) {
257 return NULL;
258 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000259
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400260 /* Allocate our context record */
261 gc = (GLXContext) Xmalloc(sizeof(struct __GLXcontextRec));
262 if (!gc) {
263 /* Out of memory */
264 return NULL;
265 }
266 memset(gc, 0, sizeof(struct __GLXcontextRec));
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000267
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400268 state = Xmalloc(sizeof(struct __GLXattributeRec));
269 if (state == NULL) {
270 /* Out of memory */
271 Xfree(gc);
272 return NULL;
273 }
274 gc->client_state_private = state;
275 memset(gc->client_state_private, 0, sizeof(struct __GLXattributeRec));
276 state->NoDrawArraysProtocol = (getenv("LIBGL_NO_DRAWARRAYS") != NULL);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000277
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400278 /*
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000279 ** Create a temporary buffer to hold GLX rendering commands. The size
280 ** of the buffer is selected so that the maximum number of GLX rendering
281 ** commands can fit in a single X packet and still have room in the X
282 ** packet for the GLXRenderReq header.
283 */
284
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400285 bufSize = (XMaxRequestSize(dpy) * 4) - sz_xGLXRenderReq;
286 gc->buf = (GLubyte *) Xmalloc(bufSize);
287 if (!gc->buf) {
288 Xfree(gc->client_state_private);
289 Xfree(gc);
290 return NULL;
291 }
292 gc->bufSize = bufSize;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000293
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400294 /* Fill in the new context */
295 gc->renderMode = GL_RENDER;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000296
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400297 state->storePack.alignment = 4;
298 state->storeUnpack.alignment = 4;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000299
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400300 gc->attributes.stackPointer = &gc->attributes.stack[0];
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000301
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400302 /*
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000303 ** PERFORMANCE NOTE: A mode dependent fill image can speed things up.
304 ** Other code uses the fastImageUnpack bit, but it is never set
305 ** to GL_TRUE.
306 */
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400307 gc->fastImageUnpack = GL_FALSE;
308 gc->fillImage = __glFillImage;
309 gc->pc = gc->buf;
310 gc->bufEnd = gc->buf + bufSize;
311 gc->isDirect = GL_FALSE;
312 if (__glXDebug) {
313 /*
314 ** Set limit register so that there will be one command per packet
315 */
316 gc->limit = gc->buf;
317 } else {
318 gc->limit = gc->buf + bufSize - __GLX_BUFFER_LIMIT_SIZE;
319 }
320 gc->createDpy = dpy;
321 gc->majorOpcode = opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000322
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400323 /*
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000324 ** Constrain the maximum drawing command size allowed to be
325 ** transfered using the X_GLXRender protocol request. First
326 ** constrain by a software limit, then constrain by the protocl
327 ** limit.
328 */
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400329 if (bufSize > __GLX_RENDER_CMD_SIZE_LIMIT) {
330 bufSize = __GLX_RENDER_CMD_SIZE_LIMIT;
331 }
332 if (bufSize > __GLX_MAX_RENDER_CMD_SIZE) {
333 bufSize = __GLX_MAX_RENDER_CMD_SIZE;
334 }
335 gc->maxSmallRenderCommandSize = bufSize;
336 return gc;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000337}
338
339
340/**
341 * Create a new context. Exactly one of \c vis and \c fbconfig should be
342 * non-NULL.
343 *
344 * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or
345 * SGIX_fbconfig protocol be used?
346 * \param renderType For FBConfigs, what is the rendering type?
347 */
348
349static GLXContext
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400350CreateContext(Display *dpy, XVisualInfo *vis,
351 const __GLcontextModes * const fbconfig,
352 GLXContext shareList,
353 Bool allowDirect, GLXContextID contextID,
354 Bool use_glx_1_3, int renderType)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000355{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400356 GLXContext gc;
Kristian Høgsberg37311592008-03-10 17:59:46 -0400357#ifdef GLX_DIRECT_RENDERING
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400358 int screen = (fbconfig == NULL) ? vis->screen : fbconfig->screen;
359 __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen);
Kristian Høgsberg37311592008-03-10 17:59:46 -0400360#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000361
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400362 if ( dpy == NULL )
363 return NULL;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000364
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400365 gc = AllocateGLXContext(dpy);
366 if (!gc)
367 return NULL;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000368
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400369 if (None == contextID) {
370 if ( (vis == NULL) && (fbconfig == NULL) )
371 return NULL;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000372
373#ifdef GLX_DIRECT_RENDERING
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400374 if (allowDirect && psc->driScreen) {
375 const __GLcontextModes * mode;
Kristian Høgsberg8e66c3d2007-11-05 17:02:03 -0500376
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400377 if (fbconfig == NULL) {
378 mode = _gl_context_modes_find_visual(psc->visuals, vis->visualid);
379 if (mode == NULL) {
380 xError error;
Kristian Høgsberg8e66c3d2007-11-05 17:02:03 -0500381
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400382 error.errorCode = BadValue;
383 error.resourceID = vis->visualid;
384 error.sequenceNumber = dpy->request;
385 error.type = X_Error;
386 error.majorCode = gc->majorOpcode;
387 error.minorCode = X_GLXCreateContext;
388 _XError(dpy, &error);
389 return None;
390 }
391 }
392 else {
393 mode = fbconfig;
394 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000395
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400396 gc->driContext = psc->driScreen->createContext(psc, mode, gc,
397 shareList,
398 renderType);
399 if (gc->driContext != NULL) {
400 gc->screen = mode->screen;
401 gc->psc = psc;
402 gc->mode = mode;
403 gc->isDirect = GL_TRUE;
404 }
405 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000406#endif
407
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400408 LockDisplay(dpy);
409 if ( fbconfig == NULL ) {
410 xGLXCreateContextReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000411
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400412 /* Send the glXCreateContext request */
413 GetReq(GLXCreateContext,req);
414 req->reqType = gc->majorOpcode;
415 req->glxCode = X_GLXCreateContext;
416 req->context = gc->xid = XAllocID(dpy);
417 req->visual = vis->visualid;
418 req->screen = vis->screen;
419 req->shareList = shareList ? shareList->xid : None;
Jeremy Huddleston919ec222008-08-08 02:52:10 -0700420#ifdef GLX_DIRECT_RENDERING
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400421 req->isDirect = gc->driContext != NULL;
Jeremy Huddleston919ec222008-08-08 02:52:10 -0700422#else
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400423 req->isDirect = 0;
Jeremy Huddleston919ec222008-08-08 02:52:10 -0700424#endif
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400425 }
426 else if ( use_glx_1_3 ) {
427 xGLXCreateNewContextReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000428
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400429 /* Send the glXCreateNewContext request */
430 GetReq(GLXCreateNewContext,req);
431 req->reqType = gc->majorOpcode;
432 req->glxCode = X_GLXCreateNewContext;
433 req->context = gc->xid = XAllocID(dpy);
434 req->fbconfig = fbconfig->fbconfigID;
435 req->screen = fbconfig->screen;
436 req->renderType = renderType;
437 req->shareList = shareList ? shareList->xid : None;
Jeremy Huddleston919ec222008-08-08 02:52:10 -0700438#ifdef GLX_DIRECT_RENDERING
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400439 req->isDirect = gc->driContext != NULL;
Jeremy Huddleston919ec222008-08-08 02:52:10 -0700440#else
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400441 req->isDirect = 0;
Jeremy Huddleston919ec222008-08-08 02:52:10 -0700442#endif
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400443 }
444 else {
445 xGLXVendorPrivateWithReplyReq *vpreq;
446 xGLXCreateContextWithConfigSGIXReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000447
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400448 /* Send the glXCreateNewContext request */
449 GetReqExtra(GLXVendorPrivateWithReply,
450 sz_xGLXCreateContextWithConfigSGIXReq-sz_xGLXVendorPrivateWithReplyReq,vpreq);
451 req = (xGLXCreateContextWithConfigSGIXReq *)vpreq;
452 req->reqType = gc->majorOpcode;
453 req->glxCode = X_GLXVendorPrivateWithReply;
454 req->vendorCode = X_GLXvop_CreateContextWithConfigSGIX;
455 req->context = gc->xid = XAllocID(dpy);
456 req->fbconfig = fbconfig->fbconfigID;
457 req->screen = fbconfig->screen;
458 req->renderType = renderType;
459 req->shareList = shareList ? shareList->xid : None;
Jeremy Huddleston919ec222008-08-08 02:52:10 -0700460#ifdef GLX_DIRECT_RENDERING
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400461 req->isDirect = gc->driContext != NULL;
Jeremy Huddleston919ec222008-08-08 02:52:10 -0700462#else
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400463 req->isDirect = 0;
Jeremy Huddleston919ec222008-08-08 02:52:10 -0700464#endif
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400465 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000466
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400467 UnlockDisplay(dpy);
468 SyncHandle();
469 gc->imported = GL_FALSE;
470 }
471 else {
472 gc->xid = contextID;
473 gc->imported = GL_TRUE;
474 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000475
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400476 return gc;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000477}
478
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400479PUBLIC GLXContext glXCreateContext(Display *dpy, XVisualInfo *vis,
480 GLXContext shareList, Bool allowDirect)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000481{
482 return CreateContext(dpy, vis, NULL, shareList, allowDirect, None,
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400483 False, 0);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000484}
485
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400486_X_HIDDEN void __glXFreeContext(__GLXcontext *gc)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000487{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400488 if (gc->vendor) XFree((char *) gc->vendor);
489 if (gc->renderer) XFree((char *) gc->renderer);
490 if (gc->version) XFree((char *) gc->version);
491 if (gc->extensions) XFree((char *) gc->extensions);
492 __glFreeAttributeState(gc);
493 XFree((char *) gc->buf);
494 Xfree((char *) gc->client_state_private);
495 XFree((char *) gc);
496
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000497}
498
499/*
500** Destroy the named context
501*/
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400502static void
503DestroyContext(Display *dpy, GLXContext gc)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000504{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400505 xGLXDestroyContextReq *req;
506 GLXContextID xid;
507 CARD8 opcode;
508 GLboolean imported;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000509
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400510 opcode = __glXSetupForCommand(dpy);
511 if (!opcode || !gc) {
512 return;
513 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000514
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400515 __glXLock();
516 xid = gc->xid;
517 imported = gc->imported;
518 gc->xid = None;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000519
520#ifdef GLX_DIRECT_RENDERING
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400521 /* Destroy the direct rendering context */
522 if (gc->driContext) {
523 (*gc->driContext->destroyContext)(gc->driContext, gc->psc, dpy);
524 gc->driContext = NULL;
525 GarbageCollectDRIDrawables(dpy, gc->psc);
526 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000527#endif
528
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400529 __glXFreeVertexArrayState(gc);
Kristof Raloviche2060342008-08-20 15:18:38 -0600530
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400531 if (gc->currentDpy) {
532 /* Have to free later cuz it's in use now */
533 __glXUnlock();
534 } else {
535 /* Destroy the handle if not current to anybody */
536 __glXUnlock();
537 __glXFreeContext(gc);
538 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000539
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400540 if (!imported) {
541 /*
542 ** This dpy also created the server side part of the context.
543 ** Send the glXDestroyContext request.
544 */
545 LockDisplay(dpy);
546 GetReq(GLXDestroyContext,req);
547 req->reqType = opcode;
548 req->glxCode = X_GLXDestroyContext;
549 req->context = xid;
550 UnlockDisplay(dpy);
551 SyncHandle();
552 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000553}
Adam Jackson489ccef2004-12-15 17:18:06 +0000554
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400555PUBLIC void glXDestroyContext(Display *dpy, GLXContext gc)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000556{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400557 DestroyContext(dpy, gc);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000558}
559
560/*
561** Return the major and minor version #s for the GLX extension
562*/
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400563PUBLIC Bool glXQueryVersion(Display *dpy, int *major, int *minor)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000564{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400565 __GLXdisplayPrivate *priv;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000566
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400567 /* Init the extension. This fetches the major and minor version. */
568 priv = __glXInitialize(dpy);
569 if (!priv) return GL_FALSE;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000570
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400571 if (major) *major = priv->majorVersion;
572 if (minor) *minor = priv->minorVersion;
573 return GL_TRUE;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000574}
575
576/*
577** Query the existance of the GLX extension
578*/
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400579PUBLIC Bool glXQueryExtension(Display *dpy, int *errorBase, int *eventBase)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000580{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400581 int major_op, erb, evb;
582 Bool rv;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000583
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400584 rv = XQueryExtension(dpy, GLX_EXTENSION_NAME, &major_op, &evb, &erb);
585 if (rv) {
586 if (errorBase) *errorBase = erb;
587 if (eventBase) *eventBase = evb;
588 }
589 return rv;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000590}
591
592/*
593** Put a barrier in the token stream that forces the GL to finish its
594** work before X can proceed.
595*/
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400596PUBLIC void glXWaitGL(void)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000597{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400598 xGLXWaitGLReq *req;
599 GLXContext gc = __glXGetCurrentContext();
600 Display *dpy = gc->currentDpy;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000601
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400602 if (!dpy) return;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000603
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400604 /* Flush any pending commands out */
605 __glXFlushRenderBuffer(gc, gc->pc);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000606
607#ifdef GLX_DIRECT_RENDERING
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400608 if (gc->driContext) {
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000609/* This bit of ugliness unwraps the glFinish function */
610#ifdef glFinish
611#undef glFinish
612#endif
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400613 glFinish();
614 return;
615 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000616#endif
617
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400618 /* Send the glXWaitGL request */
619 LockDisplay(dpy);
620 GetReq(GLXWaitGL,req);
621 req->reqType = gc->majorOpcode;
622 req->glxCode = X_GLXWaitGL;
623 req->contextTag = gc->currentContextTag;
624 UnlockDisplay(dpy);
625 SyncHandle();
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000626}
627
628/*
629** Put a barrier in the token stream that forces X to finish its
630** work before GL can proceed.
631*/
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400632PUBLIC void glXWaitX(void)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000633{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400634 xGLXWaitXReq *req;
635 GLXContext gc = __glXGetCurrentContext();
636 Display *dpy = gc->currentDpy;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000637
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400638 if (!dpy) return;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000639
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400640 /* Flush any pending commands out */
641 __glXFlushRenderBuffer(gc, gc->pc);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000642
643#ifdef GLX_DIRECT_RENDERING
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400644 if (gc->driContext) {
645 XSync(dpy, False);
646 return;
647 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000648#endif
649
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400650 /*
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000651 ** Send the glXWaitX request.
652 */
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400653 LockDisplay(dpy);
654 GetReq(GLXWaitX,req);
655 req->reqType = gc->majorOpcode;
656 req->glxCode = X_GLXWaitX;
657 req->contextTag = gc->currentContextTag;
658 UnlockDisplay(dpy);
659 SyncHandle();
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000660}
661
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400662PUBLIC void glXUseXFont(Font font, int first, int count, int listBase)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000663{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400664 xGLXUseXFontReq *req;
665 GLXContext gc = __glXGetCurrentContext();
666 Display *dpy = gc->currentDpy;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000667
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400668 if (!dpy) return;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000669
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400670 /* Flush any pending commands out */
671 (void) __glXFlushRenderBuffer(gc, gc->pc);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000672
673#ifdef GLX_DIRECT_RENDERING
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400674 if (gc->driContext) {
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000675 DRI_glXUseXFont(font, first, count, listBase);
676 return;
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400677 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000678#endif
679
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400680 /* Send the glXUseFont request */
681 LockDisplay(dpy);
682 GetReq(GLXUseXFont,req);
683 req->reqType = gc->majorOpcode;
684 req->glxCode = X_GLXUseXFont;
685 req->contextTag = gc->currentContextTag;
686 req->font = font;
687 req->first = first;
688 req->count = count;
689 req->listBase = listBase;
690 UnlockDisplay(dpy);
691 SyncHandle();
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000692}
693
694/************************************************************************/
695
696/*
697** Copy the source context to the destination context using the
698** attribute "mask".
699*/
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400700PUBLIC void glXCopyContext(Display *dpy, GLXContext source,
701 GLXContext dest, unsigned long mask)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000702{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400703 xGLXCopyContextReq *req;
704 GLXContext gc = __glXGetCurrentContext();
705 GLXContextTag tag;
706 CARD8 opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000707
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400708 opcode = __glXSetupForCommand(dpy);
709 if (!opcode) {
710 return;
711 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000712
713#ifdef GLX_DIRECT_RENDERING
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400714 if (gc->driContext) {
715 /* NOT_DONE: This does not work yet */
716 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000717#endif
718
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400719 /*
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000720 ** If the source is the current context, send its tag so that the context
721 ** can be flushed before the copy.
722 */
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400723 if (source == gc && dpy == gc->currentDpy) {
724 tag = gc->currentContextTag;
725 } else {
726 tag = 0;
727 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000728
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400729 /* Send the glXCopyContext request */
730 LockDisplay(dpy);
731 GetReq(GLXCopyContext,req);
732 req->reqType = opcode;
733 req->glxCode = X_GLXCopyContext;
734 req->source = source ? source->xid : None;
735 req->dest = dest ? dest->xid : None;
736 req->mask = mask;
737 req->contextTag = tag;
738 UnlockDisplay(dpy);
739 SyncHandle();
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000740}
741
742
743/**
744 * Determine if a context uses direct rendering.
745 *
746 * \param dpy Display where the context was created.
747 * \param contextID ID of the context to be tested.
748 *
749 * \returns \c GL_TRUE if the context is direct rendering or not.
750 */
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400751static Bool __glXIsDirect(Display *dpy, GLXContextID contextID)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000752{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400753 xGLXIsDirectReq *req;
754 xGLXIsDirectReply reply;
755 CARD8 opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000756
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400757 opcode = __glXSetupForCommand(dpy);
758 if (!opcode) {
759 return GL_FALSE;
760 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000761
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400762 /* Send the glXIsDirect request */
763 LockDisplay(dpy);
764 GetReq(GLXIsDirect,req);
765 req->reqType = opcode;
766 req->glxCode = X_GLXIsDirect;
767 req->context = contextID;
768 _XReply(dpy, (xReply*) &reply, 0, False);
769 UnlockDisplay(dpy);
770 SyncHandle();
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000771
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400772 return reply.isDirect;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000773}
774
Ian Romanickc39bf5e2005-07-24 06:29:14 +0000775/**
776 * \todo
777 * Shouldn't this function \b always return \c GL_FALSE when
778 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
779 * the GLX protocol here at all?
780 */
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400781PUBLIC Bool glXIsDirect(Display *dpy, GLXContext gc)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000782{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400783 if (!gc) {
784 return GL_FALSE;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000785#ifdef GLX_DIRECT_RENDERING
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400786 } else if (gc->driContext) {
787 return GL_TRUE;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000788#endif
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400789 }
790 return __glXIsDirect(dpy, gc->xid);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000791}
792
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400793PUBLIC GLXPixmap glXCreateGLXPixmap(Display *dpy, XVisualInfo *vis,
794 Pixmap pixmap)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000795{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400796 xGLXCreateGLXPixmapReq *req;
797 GLXPixmap xid;
798 CARD8 opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000799
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400800 opcode = __glXSetupForCommand(dpy);
801 if (!opcode) {
802 return None;
803 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000804
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400805 /* Send the glXCreateGLXPixmap request */
806 LockDisplay(dpy);
807 GetReq(GLXCreateGLXPixmap,req);
808 req->reqType = opcode;
809 req->glxCode = X_GLXCreateGLXPixmap;
810 req->screen = vis->screen;
811 req->visual = vis->visualid;
812 req->pixmap = pixmap;
813 req->glxpixmap = xid = XAllocID(dpy);
814 UnlockDisplay(dpy);
815 SyncHandle();
816 return xid;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000817}
818
819/*
820** Destroy the named pixmap
821*/
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400822PUBLIC void glXDestroyGLXPixmap(Display *dpy, GLXPixmap glxpixmap)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000823{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400824 xGLXDestroyGLXPixmapReq *req;
825 CARD8 opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000826
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400827 opcode = __glXSetupForCommand(dpy);
828 if (!opcode) {
829 return;
830 }
831
832 /* Send the glXDestroyGLXPixmap request */
833 LockDisplay(dpy);
834 GetReq(GLXDestroyGLXPixmap,req);
835 req->reqType = opcode;
836 req->glxCode = X_GLXDestroyGLXPixmap;
837 req->glxpixmap = glxpixmap;
838 UnlockDisplay(dpy);
839 SyncHandle();
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000840}
841
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400842PUBLIC void glXSwapBuffers(Display *dpy, GLXDrawable drawable)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000843{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400844 xGLXSwapBuffersReq *req;
845 GLXContext gc;
846 GLXContextTag tag;
847 CARD8 opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000848#ifdef GLX_DIRECT_RENDERING
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400849 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, NULL);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000850
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400851 if (pdraw != NULL) {
852 glFlush();
853 (*pdraw->psc->driScreen->swapBuffers)(pdraw);
854 return;
855 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000856#endif
857
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400858 opcode = __glXSetupForCommand(dpy);
859 if (!opcode) {
860 return;
861 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000862
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400863 /*
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000864 ** The calling thread may or may not have a current context. If it
865 ** does, send the context tag so the server can do a flush.
866 */
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400867 gc = __glXGetCurrentContext();
868 if ((gc != NULL) && (dpy == gc->currentDpy) &&
869 ((drawable == gc->currentDrawable) || (drawable == gc->currentReadable)) ) {
870 tag = gc->currentContextTag;
871 } else {
872 tag = 0;
873 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000874
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400875 /* Send the glXSwapBuffers request */
876 LockDisplay(dpy);
877 GetReq(GLXSwapBuffers,req);
878 req->reqType = opcode;
879 req->glxCode = X_GLXSwapBuffers;
880 req->drawable = drawable;
881 req->contextTag = tag;
882 UnlockDisplay(dpy);
883 SyncHandle();
884 XFlush(dpy);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000885}
886
887
888/*
889** Return configuration information for the given display, screen and
890** visual combination.
891*/
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400892PUBLIC int glXGetConfig(Display *dpy, XVisualInfo *vis, int attribute,
893 int *value_return)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000894{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400895 __GLXdisplayPrivate *priv;
896 __GLXscreenConfigs *psc;
897 __GLcontextModes *modes;
898 int status;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000899
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400900 status = GetGLXPrivScreenConfig( dpy, vis->screen, & priv, & psc );
901 if ( status == Success ) {
902 modes = _gl_context_modes_find_visual(psc->visuals, vis->visualid);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000903
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400904 /* Lookup attribute after first finding a match on the visual */
905 if ( modes != NULL ) {
906 return _gl_get_context_mode_data( modes, attribute, value_return );
907 }
908
909 status = GLX_BAD_VISUAL;
910 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000911
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400912 /*
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000913 ** If we can't find the config for this visual, this visual is not
914 ** supported by the OpenGL implementation on the server.
915 */
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400916 if ( (status == GLX_BAD_VISUAL) && (attribute == GLX_USE_GL) ) {
917 *value_return = GL_FALSE;
918 status = Success;
919 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000920
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400921 return status;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000922}
923
924/************************************************************************/
925
926static void
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400927init_fbconfig_for_chooser( __GLcontextModes * config,
928 GLboolean fbconfig_style_tags )
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000929{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400930 memset( config, 0, sizeof( __GLcontextModes ) );
931 config->visualID = (XID) GLX_DONT_CARE;
932 config->visualType = GLX_DONT_CARE;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000933
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400934 /* glXChooseFBConfig specifies different defaults for these two than
935 * glXChooseVisual.
936 */
937 if ( fbconfig_style_tags ) {
938 config->rgbMode = GL_TRUE;
939 config->doubleBufferMode = GLX_DONT_CARE;
940 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000941
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400942 config->visualRating = GLX_DONT_CARE;
943 config->transparentPixel = GLX_NONE;
944 config->transparentRed = GLX_DONT_CARE;
945 config->transparentGreen = GLX_DONT_CARE;
946 config->transparentBlue = GLX_DONT_CARE;
947 config->transparentAlpha = GLX_DONT_CARE;
948 config->transparentIndex = GLX_DONT_CARE;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000949
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400950 config->drawableType = GLX_WINDOW_BIT;
951 config->renderType = (config->rgbMode) ? GLX_RGBA_BIT : GLX_COLOR_INDEX_BIT;
952 config->xRenderable = GLX_DONT_CARE;
953 config->fbconfigID = (GLXFBConfigID)(GLX_DONT_CARE);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000954
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400955 config->swapMethod = GLX_DONT_CARE;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000956}
957
958#define MATCH_DONT_CARE( param ) \
959 do { \
960 if ( (a-> param != GLX_DONT_CARE) \
961 && (a-> param != b-> param) ) { \
962 return False; \
963 } \
964 } while ( 0 )
965
966#define MATCH_MINIMUM( param ) \
967 do { \
968 if ( (a-> param != GLX_DONT_CARE) \
969 && (a-> param > b-> param) ) { \
970 return False; \
971 } \
972 } while ( 0 )
973
974#define MATCH_EXACT( param ) \
975 do { \
976 if ( a-> param != b-> param) { \
977 return False; \
978 } \
979 } while ( 0 )
980
981/**
982 * Determine if two GLXFBConfigs are compatible.
983 *
984 * \param a Application specified config to test.
985 * \param b Server specified config to test against \c a.
986 */
987static Bool
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400988fbconfigs_compatible( const __GLcontextModes * const a,
989 const __GLcontextModes * const b )
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000990{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400991 MATCH_DONT_CARE( doubleBufferMode );
992 MATCH_DONT_CARE( visualType );
993 MATCH_DONT_CARE( visualRating );
994 MATCH_DONT_CARE( xRenderable );
995 MATCH_DONT_CARE( fbconfigID );
996 MATCH_DONT_CARE( swapMethod );
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000997
Kristian Høgsberg77c7f902008-10-14 23:07:42 -0400998 MATCH_MINIMUM( rgbBits );
999 MATCH_MINIMUM( numAuxBuffers );
1000 MATCH_MINIMUM( redBits );
1001 MATCH_MINIMUM( greenBits );
1002 MATCH_MINIMUM( blueBits );
1003 MATCH_MINIMUM( alphaBits );
1004 MATCH_MINIMUM( depthBits );
1005 MATCH_MINIMUM( stencilBits );
1006 MATCH_MINIMUM( accumRedBits );
1007 MATCH_MINIMUM( accumGreenBits );
1008 MATCH_MINIMUM( accumBlueBits );
1009 MATCH_MINIMUM( accumAlphaBits );
1010 MATCH_MINIMUM( sampleBuffers );
1011 MATCH_MINIMUM( maxPbufferWidth );
1012 MATCH_MINIMUM( maxPbufferHeight );
1013 MATCH_MINIMUM( maxPbufferPixels );
1014 MATCH_MINIMUM( samples );
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001015
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001016 MATCH_DONT_CARE( stereoMode );
1017 MATCH_EXACT( level );
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001018
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001019 if ( ((a->drawableType & b->drawableType) == 0)
1020 || ((a->renderType & b->renderType) == 0) ) {
1021 return False;
1022 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001023
1024
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001025 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1026 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1027 * Technically speaking, it is a bug in the DDX driver, but there is
1028 * enough of an installed base to work around the problem here. In any
1029 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1030 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1031 * 0 from the server to be a match to maintain backward compatibility with
1032 * the (broken) drivers.
1033 */
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001034
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001035 if ( a->transparentPixel != GLX_DONT_CARE
1036 && a->transparentPixel != 0 ) {
1037 if ( a->transparentPixel == GLX_NONE ) {
1038 if ( b->transparentPixel != GLX_NONE && b->transparentPixel != 0 )
1039 return False;
1040 } else {
1041 MATCH_EXACT( transparentPixel );
1042 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001043
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001044 switch ( a->transparentPixel ) {
1045 case GLX_TRANSPARENT_RGB:
1046 MATCH_DONT_CARE( transparentRed );
1047 MATCH_DONT_CARE( transparentGreen );
1048 MATCH_DONT_CARE( transparentBlue );
1049 MATCH_DONT_CARE( transparentAlpha );
1050 break;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001051
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001052 case GLX_TRANSPARENT_INDEX:
1053 MATCH_DONT_CARE( transparentIndex );
1054 break;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001055
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001056 default:
1057 break;
1058 }
1059 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001060
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001061 return True;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001062}
1063
1064
1065/* There's some trickly language in the GLX spec about how this is supposed
1066 * to work. Basically, if a given component size is either not specified
1067 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1068 * Well, that's really hard to do with the code as-is. This behavior is
1069 * closer to correct, but still not technically right.
1070 */
1071#define PREFER_LARGER_OR_ZERO(comp) \
1072 do { \
1073 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1074 if ( ((*a)-> comp) == 0 ) { \
1075 return -1; \
1076 } \
1077 else if ( ((*b)-> comp) == 0 ) { \
1078 return 1; \
1079 } \
1080 else { \
1081 return ((*b)-> comp) - ((*a)-> comp) ; \
1082 } \
1083 } \
1084 } while( 0 )
1085
1086#define PREFER_LARGER(comp) \
1087 do { \
1088 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1089 return ((*b)-> comp) - ((*a)-> comp) ; \
1090 } \
1091 } while( 0 )
1092
1093#define PREFER_SMALLER(comp) \
1094 do { \
1095 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1096 return ((*a)-> comp) - ((*b)-> comp) ; \
1097 } \
1098 } while( 0 )
1099
1100/**
1101 * Compare two GLXFBConfigs. This function is intended to be used as the
1102 * compare function passed in to qsort.
1103 *
1104 * \returns If \c a is a "better" config, according to the specification of
1105 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1106 * better, then a number greater than zero is return. If both are
1107 * equal, zero is returned.
1108 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1109 */
1110static int
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001111fbconfig_compare( const __GLcontextModes * const * const a,
1112 const __GLcontextModes * const * const b )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001113{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001114 /* The order of these comparisons must NOT change. It is defined by
1115 * the GLX 1.3 spec and ARB_multisample.
1116 */
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001117
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001118 PREFER_SMALLER( visualSelectGroup );
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001119
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001120 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1121 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1122 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1123 */
1124 PREFER_SMALLER( visualRating );
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001125
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001126 /* This isn't quite right. It is supposed to compare the sum of the
1127 * components the user specifically set minimums for.
1128 */
1129 PREFER_LARGER_OR_ZERO( redBits );
1130 PREFER_LARGER_OR_ZERO( greenBits );
1131 PREFER_LARGER_OR_ZERO( blueBits );
1132 PREFER_LARGER_OR_ZERO( alphaBits );
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001133
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001134 PREFER_SMALLER( rgbBits );
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001135
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001136 if ( ((*a)->doubleBufferMode != (*b)->doubleBufferMode) ) {
1137 /* Prefer single-buffer.
1138 */
1139 return ( !(*a)->doubleBufferMode ) ? -1 : 1;
1140 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001141
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001142 PREFER_SMALLER( numAuxBuffers );
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001143
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001144 PREFER_LARGER_OR_ZERO( depthBits );
1145 PREFER_SMALLER( stencilBits );
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001146
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001147 /* This isn't quite right. It is supposed to compare the sum of the
1148 * components the user specifically set minimums for.
1149 */
1150 PREFER_LARGER_OR_ZERO( accumRedBits );
1151 PREFER_LARGER_OR_ZERO( accumGreenBits );
1152 PREFER_LARGER_OR_ZERO( accumBlueBits );
1153 PREFER_LARGER_OR_ZERO( accumAlphaBits );
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001154
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001155 PREFER_SMALLER( visualType );
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001156
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001157 /* None of the multisample specs say where this comparison should happen,
1158 * so I put it near the end.
1159 */
1160 PREFER_SMALLER( sampleBuffers );
1161 PREFER_SMALLER( samples );
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001162
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001163 /* None of the pbuffer or fbconfig specs say that this comparison needs
1164 * to happen at all, but it seems like it should.
1165 */
1166 PREFER_LARGER( maxPbufferWidth );
1167 PREFER_LARGER( maxPbufferHeight );
1168 PREFER_LARGER( maxPbufferPixels );
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001169
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001170 return 0;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001171}
1172
1173
1174/**
1175 * Selects and sorts a subset of the supplied configs based on the attributes.
1176 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1177 * and \c glXChooseFBConfigSGIX.
1178 *
1179 * \param configs Array of pointers to possible configs. The elements of
1180 * this array that do not meet the criteria will be set to
1181 * NULL. The remaining elements will be sorted according to
1182 * the various visual / FBConfig selection rules.
1183 * \param num_configs Number of elements in the \c configs array.
1184 * \param attribList Attributes used select from \c configs. This array is
1185 * terminated by a \c None tag. The array can either take
1186 * the form expected by \c glXChooseVisual (where boolean
1187 * tags do not have a value) or by \c glXChooseFBConfig
1188 * (where every tag has a value).
1189 * \param fbconfig_style_tags Selects whether \c attribList is in
1190 * \c glXChooseVisual style or
1191 * \c glXChooseFBConfig style.
1192 * \returns The number of valid elements left in \c configs.
1193 *
1194 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1195 */
1196static int
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001197choose_visual( __GLcontextModes ** configs, int num_configs,
1198 const int *attribList, GLboolean fbconfig_style_tags )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001199{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001200 __GLcontextModes test_config;
1201 int base;
1202 int i;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001203
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001204 /* This is a fairly direct implementation of the selection method
1205 * described by GLX_SGIX_fbconfig. Start by culling out all the
1206 * configs that are not compatible with the selected parameter
1207 * list.
1208 */
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001209
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001210 init_fbconfig_for_chooser( & test_config, fbconfig_style_tags );
1211 __glXInitializeVisualConfigFromTags( & test_config, 512,
1212 (const INT32 *) attribList,
1213 GL_TRUE, fbconfig_style_tags );
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001214
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001215 base = 0;
1216 for ( i = 0 ; i < num_configs ; i++ ) {
1217 if ( fbconfigs_compatible( & test_config, configs[i] ) ) {
1218 configs[ base ] = configs[ i ];
1219 base++;
1220 }
1221 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001222
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001223 if ( base == 0 ) {
1224 return 0;
1225 }
1226
1227 if ( base < num_configs ) {
1228 (void) memset( & configs[ base ], 0,
1229 sizeof( void * ) * (num_configs - base) );
1230 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001231
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001232 /* After the incompatible configs are removed, the resulting
1233 * list is sorted according to the rules set out in the various
1234 * specifications.
1235 */
1236
1237 qsort( configs, base, sizeof( __GLcontextModes * ),
1238 (int (*)(const void*, const void*)) fbconfig_compare );
1239 return base;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001240}
1241
1242
1243
1244
1245/*
1246** Return the visual that best matches the template. Return None if no
1247** visual matches the template.
1248*/
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001249PUBLIC XVisualInfo *glXChooseVisual(Display *dpy, int screen, int *attribList)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001250{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001251 XVisualInfo *visualList = NULL;
1252 __GLXdisplayPrivate *priv;
1253 __GLXscreenConfigs *psc;
1254 __GLcontextModes test_config;
1255 __GLcontextModes *modes;
1256 const __GLcontextModes *best_config = NULL;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001257
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001258 /*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001259 ** Get a list of all visuals, return if list is empty
1260 */
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001261 if ( GetGLXPrivScreenConfig( dpy, screen, & priv, & psc ) != Success ) {
1262 return None;
1263 }
1264
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001265
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001266 /*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001267 ** Build a template from the defaults and the attribute list
1268 ** Free visual list and return if an unexpected token is encountered
1269 */
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001270 init_fbconfig_for_chooser( & test_config, GL_FALSE );
1271 __glXInitializeVisualConfigFromTags( & test_config, 512,
1272 (const INT32 *) attribList,
1273 GL_TRUE, GL_FALSE );
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001274
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001275 /*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001276 ** Eliminate visuals that don't meet minimum requirements
1277 ** Compute a score for those that do
1278 ** Remember which visual, if any, got the highest score
1279 */
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001280 for ( modes = psc->visuals ; modes != NULL ; modes = modes->next ) {
1281 if ( fbconfigs_compatible( & test_config, modes )
1282 && ((best_config == NULL)
1283 || (fbconfig_compare( (const __GLcontextModes * const * const)&modes, &best_config ) < 0)) ) {
1284 best_config = modes;
1285 }
1286 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001287
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001288 /*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001289 ** If no visual is acceptable, return None
1290 ** Otherwise, create an XVisualInfo list with just the selected X visual
1291 ** and return this.
1292 */
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001293 if (best_config != NULL) {
1294 XVisualInfo visualTemplate;
1295 int i;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001296
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001297 visualTemplate.screen = screen;
1298 visualTemplate.visualid = best_config->visualID;
1299 visualList = XGetVisualInfo( dpy, VisualScreenMask|VisualIDMask,
1300 &visualTemplate, &i );
1301 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001302
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001303 return visualList;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001304}
1305
1306
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001307PUBLIC const char *glXQueryExtensionsString( Display *dpy, int screen )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001308{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001309 __GLXscreenConfigs *psc;
1310 __GLXdisplayPrivate *priv;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001311
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001312 if ( GetGLXPrivScreenConfig( dpy, screen, & priv, & psc ) != Success ) {
1313 return NULL;
1314 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001315
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001316 if (!psc->effectiveGLXexts) {
1317 if (!psc->serverGLXexts) {
1318 psc->serverGLXexts = __glXGetStringFromServer(dpy, priv->majorOpcode,
1319 X_GLXQueryServerString,
1320 screen, GLX_EXTENSIONS);
1321 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001322
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001323 __glXCalculateUsableExtensions(psc,
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001324#ifdef GLX_DIRECT_RENDERING
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001325 (psc->driScreen != NULL),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001326#else
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001327 GL_FALSE,
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001328#endif
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001329 priv->minorVersion);
1330 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001331
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001332 return psc->effectiveGLXexts;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001333}
1334
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001335PUBLIC const char *glXGetClientString( Display *dpy, int name )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001336{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001337 switch(name) {
1338 case GLX_VENDOR:
1339 return (__glXGLXClientVendorName);
1340 case GLX_VERSION:
1341 return (__glXGLXClientVersion);
1342 case GLX_EXTENSIONS:
1343 return (__glXGetClientExtensions());
1344 default:
1345 return NULL;
1346 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001347}
1348
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001349PUBLIC const char *glXQueryServerString( Display *dpy, int screen, int name )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001350{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001351 __GLXscreenConfigs *psc;
1352 __GLXdisplayPrivate *priv;
1353 const char ** str;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001354
1355
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001356 if ( GetGLXPrivScreenConfig( dpy, screen, & priv, & psc ) != Success ) {
1357 return NULL;
1358 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001359
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001360 switch(name) {
1361 case GLX_VENDOR:
1362 str = & priv->serverGLXvendor;
1363 break;
1364 case GLX_VERSION:
1365 str = & priv->serverGLXversion;
1366 break;
1367 case GLX_EXTENSIONS:
1368 str = & psc->serverGLXexts;
1369 break;
1370 default:
1371 return NULL;
1372 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001373
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001374 if ( *str == NULL ) {
1375 *str = __glXGetStringFromServer(dpy, priv->majorOpcode,
1376 X_GLXQueryServerString, screen, name);
1377 }
1378
1379 return *str;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001380}
1381
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001382void __glXClientInfo ( Display *dpy, int opcode )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001383{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001384 xGLXClientInfoReq *req;
1385 int size;
1386 char * ext_str = __glXGetClientGLExtensionString();
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001387
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001388 /* Send the glXClientInfo request */
1389 LockDisplay(dpy);
1390 GetReq(GLXClientInfo,req);
1391 req->reqType = opcode;
1392 req->glxCode = X_GLXClientInfo;
1393 req->major = GLX_MAJOR_VERSION;
1394 req->minor = GLX_MINOR_VERSION;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001395
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001396 size = strlen( ext_str ) + 1;
1397 req->length += (size + 3) >> 2;
1398 req->numbytes = size;
1399 Data(dpy, ext_str, size);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001400
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001401 UnlockDisplay(dpy);
1402 SyncHandle();
1403
1404 Xfree( ext_str );
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001405}
1406
1407
1408/*
1409** EXT_import_context
1410*/
1411
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001412PUBLIC Display *glXGetCurrentDisplay(void)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001413{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001414 GLXContext gc = __glXGetCurrentContext();
1415 if (NULL == gc) return NULL;
1416 return gc->currentDpy;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001417}
1418
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001419PUBLIC GLX_ALIAS(Display *, glXGetCurrentDisplayEXT, (void), (),
1420 glXGetCurrentDisplay)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001421
1422/**
1423 * Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests
1424 * to the X-server.
1425 *
1426 * \param dpy Display where \c ctx was created.
1427 * \param ctx Context to query.
1428 * \returns \c Success on success. \c GLX_BAD_CONTEXT if \c ctx is invalid,
1429 * or zero if the request failed due to internal problems (i.e.,
1430 * unable to allocate temporary memory, etc.)
1431 *
1432 * \note
1433 * This function dynamically determines whether to use the EXT_import_context
1434 * version of the protocol or the GLX 1.3 version of the protocol.
1435 */
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001436static int __glXQueryContextInfo(Display *dpy, GLXContext ctx)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001437{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001438 __GLXdisplayPrivate *priv = __glXInitialize(dpy);
1439 xGLXQueryContextReply reply;
1440 CARD8 opcode;
1441 GLuint numValues;
1442 int retval;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001443
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001444 if (ctx == NULL) {
1445 return GLX_BAD_CONTEXT;
1446 }
1447 opcode = __glXSetupForCommand(dpy);
1448 if (!opcode) {
1449 return 0;
1450 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001451
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001452 /* Send the glXQueryContextInfoEXT request */
1453 LockDisplay(dpy);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001454
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001455 if ( (priv->majorVersion > 1) || (priv->minorVersion >= 3) ) {
1456 xGLXQueryContextReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001457
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001458 GetReq(GLXQueryContext, req);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001459
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001460 req->reqType = opcode;
1461 req->glxCode = X_GLXQueryContext;
1462 req->context = (unsigned int)(ctx->xid);
1463 }
1464 else {
1465 xGLXVendorPrivateReq *vpreq;
1466 xGLXQueryContextInfoEXTReq *req;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001467
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001468 GetReqExtra( GLXVendorPrivate,
1469 sz_xGLXQueryContextInfoEXTReq - sz_xGLXVendorPrivateReq,
1470 vpreq );
1471 req = (xGLXQueryContextInfoEXTReq *)vpreq;
1472 req->reqType = opcode;
1473 req->glxCode = X_GLXVendorPrivateWithReply;
1474 req->vendorCode = X_GLXvop_QueryContextInfoEXT;
1475 req->context = (unsigned int)(ctx->xid);
1476 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001477
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001478 _XReply(dpy, (xReply*) &reply, 0, False);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001479
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001480 numValues = reply.n;
1481 if (numValues == 0)
1482 retval = Success;
1483 else if (numValues > __GLX_MAX_CONTEXT_PROPS)
1484 retval = 0;
1485 else
1486 {
1487 int *propList, *pProp;
1488 int nPropListBytes;
1489 int i;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001490
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001491 nPropListBytes = numValues << 3;
1492 propList = (int *) Xmalloc(nPropListBytes);
1493 if (NULL == propList) {
1494 retval = 0;
1495 } else {
1496 _XRead(dpy, (char *)propList, nPropListBytes);
1497 pProp = propList;
1498 for (i=0; i < numValues; i++) {
1499 switch (*pProp++) {
1500 case GLX_SHARE_CONTEXT_EXT:
1501 ctx->share_xid = *pProp++;
1502 break;
1503 case GLX_VISUAL_ID_EXT:
1504 ctx->mode =
1505 _gl_context_modes_find_visual(ctx->psc->visuals, *pProp++);
1506 break;
1507 case GLX_SCREEN:
1508 ctx->screen = *pProp++;
1509 break;
1510 case GLX_FBCONFIG_ID:
1511 ctx->mode =
1512 _gl_context_modes_find_fbconfig(ctx->psc->configs, *pProp++);
1513 break;
1514 case GLX_RENDER_TYPE:
1515 ctx->renderType = *pProp++;
1516 break;
1517 default:
1518 pProp++;
1519 continue;
1520 }
1521 }
1522 Xfree((char *)propList);
1523 retval = Success;
1524 }
1525 }
1526 UnlockDisplay(dpy);
1527 SyncHandle();
1528 return retval;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001529}
1530
Adam Jackson489ccef2004-12-15 17:18:06 +00001531PUBLIC int
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001532glXQueryContext(Display *dpy, GLXContext ctx, int attribute, int *value)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001533{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001534 int retVal;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001535
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001536 /* get the information from the server if we don't have it already */
Jeremy Huddleston919ec222008-08-08 02:52:10 -07001537#ifdef GLX_DIRECT_RENDERING
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001538 if (!ctx->driContext && (ctx->mode == NULL)) {
Jeremy Huddleston919ec222008-08-08 02:52:10 -07001539#else
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001540 if (ctx->mode == NULL) {
Jeremy Huddleston919ec222008-08-08 02:52:10 -07001541#endif
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001542 retVal = __glXQueryContextInfo(dpy, ctx);
1543 if (Success != retVal) return retVal;
1544 }
1545 switch (attribute) {
1546 case GLX_SHARE_CONTEXT_EXT:
1547 *value = (int)(ctx->share_xid);
1548 break;
1549 case GLX_VISUAL_ID_EXT:
1550 *value = ctx->mode ? ctx->mode->visualID : None;
1551 break;
1552 case GLX_SCREEN:
1553 *value = (int)(ctx->screen);
1554 break;
1555 case GLX_FBCONFIG_ID:
1556 *value = ctx->mode ? ctx->mode->fbconfigID : None;
1557 break;
1558 case GLX_RENDER_TYPE:
1559 *value = (int)(ctx->renderType);
1560 break;
1561 default:
1562 return GLX_BAD_ATTRIBUTE;
1563 }
1564 return Success;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001565}
1566
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001567PUBLIC GLX_ALIAS( int, glXQueryContextInfoEXT,
1568 (Display *dpy, GLXContext ctx, int attribute, int *value),
1569 (dpy, ctx, attribute, value),
1570 glXQueryContext )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001571
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001572PUBLIC GLXContextID glXGetContextIDEXT(const GLXContext ctx)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001573{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001574 return ctx->xid;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001575}
1576
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001577PUBLIC GLXContext glXImportContextEXT(Display *dpy, GLXContextID contextID)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001578{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001579 GLXContext ctx;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001580
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001581 if (contextID == None) {
1582 return NULL;
1583 }
1584 if (__glXIsDirect(dpy, contextID)) {
1585 return NULL;
1586 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001587
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001588 ctx = CreateContext(dpy, NULL, NULL, NULL, False, contextID, False, 0);
1589 if (NULL != ctx) {
1590 if (Success != __glXQueryContextInfo(dpy, ctx)) {
1591 return NULL;
1592 }
1593 }
1594 return ctx;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001595}
1596
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001597PUBLIC void glXFreeContextEXT(Display *dpy, GLXContext ctx)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001598{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001599 DestroyContext(dpy, ctx);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001600}
1601
1602
1603
1604/*
1605 * GLX 1.3 functions - these are just stubs for now!
1606 */
1607
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001608PUBLIC GLXFBConfig *glXChooseFBConfig(Display *dpy, int screen,
1609 const int *attribList, int *nitems)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001610{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001611 __GLcontextModes ** config_list;
1612 int list_size;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001613
1614
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001615 config_list = (__GLcontextModes **)
1616 glXGetFBConfigs( dpy, screen, & list_size );
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001617
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001618 if ( (config_list != NULL) && (list_size > 0) && (attribList != NULL) ) {
1619 list_size = choose_visual( config_list, list_size, attribList,
1620 GL_TRUE );
1621 if ( list_size == 0 ) {
1622 XFree( config_list );
1623 config_list = NULL;
1624 }
1625 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001626
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001627 *nitems = list_size;
1628 return (GLXFBConfig *) config_list;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001629}
1630
1631
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001632PUBLIC GLXContext glXCreateNewContext(Display *dpy, GLXFBConfig config,
1633 int renderType, GLXContext shareList,
1634 Bool allowDirect)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001635{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001636 return CreateContext( dpy, NULL, (__GLcontextModes *) config, shareList,
1637 allowDirect, None, True, renderType );
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001638}
1639
1640
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001641PUBLIC GLXDrawable glXGetCurrentReadDrawable(void)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001642{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001643 GLXContext gc = __glXGetCurrentContext();
1644 return gc->currentReadable;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001645}
1646
1647
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001648PUBLIC GLXFBConfig *glXGetFBConfigs(Display *dpy, int screen, int *nelements)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001649{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001650 __GLXdisplayPrivate *priv = __glXInitialize(dpy);
1651 __GLcontextModes ** config = NULL;
1652 int i;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001653
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001654 *nelements = 0;
1655 if ( (priv->screenConfigs != NULL)
1656 && (screen >= 0) && (screen <= ScreenCount(dpy))
1657 && (priv->screenConfigs[screen].configs != NULL)
1658 && (priv->screenConfigs[screen].configs->fbconfigID != GLX_DONT_CARE) ) {
1659 unsigned num_configs = 0;
1660 __GLcontextModes * modes;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001661
1662
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001663 for ( modes = priv->screenConfigs[screen].configs
1664 ; modes != NULL
1665 ; modes = modes->next ) {
1666 if ( modes->fbconfigID != GLX_DONT_CARE ) {
1667 num_configs++;
1668 }
1669 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001670
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001671 config = (__GLcontextModes **) Xmalloc( sizeof(__GLcontextModes *)
1672 * num_configs );
1673 if ( config != NULL ) {
1674 *nelements = num_configs;
1675 i = 0;
1676 for ( modes = priv->screenConfigs[screen].configs
1677 ; modes != NULL
1678 ; modes = modes->next ) {
1679 if ( modes->fbconfigID != GLX_DONT_CARE ) {
1680 config[i] = modes;
1681 i++;
1682 }
1683 }
1684 }
1685 }
1686 return (GLXFBConfig *) config;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001687}
1688
1689
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001690PUBLIC int glXGetFBConfigAttrib(Display *dpy, GLXFBConfig config,
1691 int attribute, int *value)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001692{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001693 __GLcontextModes * const modes = ValidateGLXFBConfig( dpy, config );
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001694
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001695 return (modes != NULL)
1696 ? _gl_get_context_mode_data( modes, attribute, value )
1697 : GLXBadFBConfig;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001698}
1699
1700
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001701PUBLIC XVisualInfo *glXGetVisualFromFBConfig(Display *dpy, GLXFBConfig config)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001702{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001703 XVisualInfo visualTemplate;
1704 __GLcontextModes * fbconfig = (__GLcontextModes *) config;
1705 int count;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001706
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001707 /*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001708 ** Get a list of all visuals, return if list is empty
1709 */
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001710 visualTemplate.visualid = fbconfig->visualID;
1711 return XGetVisualInfo(dpy,VisualIDMask,&visualTemplate,&count);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001712}
1713
1714
1715/*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001716** GLX_SGI_swap_control
1717*/
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001718static int __glXSwapIntervalSGI(int interval)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001719{
1720 xGLXVendorPrivateReq *req;
1721 GLXContext gc = __glXGetCurrentContext();
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001722 Display * dpy;
1723 CARD32 * interval_ptr;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001724 CARD8 opcode;
1725
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001726 if ( gc == NULL ) {
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001727 return GLX_BAD_CONTEXT;
1728 }
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001729
1730 if ( interval <= 0 ) {
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001731 return GLX_BAD_VALUE;
1732 }
1733
Kristian Høgsbergefaf90b2007-05-15 16:09:44 -04001734#ifdef __DRI_SWAP_CONTROL
Kristian Høgsberg020c64b2008-03-08 21:57:29 -05001735 if (gc->driContext) {
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001736 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy,
1737 gc->screen );
1738 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(gc->currentDpy,
1739 gc->currentDrawable,
1740 NULL);
1741 if (psc->swapControl != NULL && pdraw != NULL) {
1742 psc->swapControl->setSwapInterval(pdraw->driDrawable, interval);
1743 return 0;
1744 }
1745 else {
1746 return GLX_BAD_CONTEXT;
1747 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001748 }
1749#endif
1750 dpy = gc->currentDpy;
1751 opcode = __glXSetupForCommand(dpy);
1752 if (!opcode) {
1753 return 0;
1754 }
1755
1756 /* Send the glXSwapIntervalSGI request */
1757 LockDisplay(dpy);
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001758 GetReqExtra(GLXVendorPrivate,sizeof(CARD32),req);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001759 req->reqType = opcode;
1760 req->glxCode = X_GLXVendorPrivate;
1761 req->vendorCode = X_GLXvop_SwapIntervalSGI;
1762 req->contextTag = gc->currentContextTag;
1763
Ian Romanicka70d5642006-08-30 23:15:02 +00001764 interval_ptr = (CARD32 *) (req + 1);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001765 *interval_ptr = interval;
1766
1767 UnlockDisplay(dpy);
1768 SyncHandle();
1769 XFlush(dpy);
1770
1771 return 0;
1772}
1773
1774
1775/*
1776** GLX_MESA_swap_control
1777*/
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001778static int __glXSwapIntervalMESA(unsigned int interval)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001779{
Kristian Høgsbergefaf90b2007-05-15 16:09:44 -04001780#ifdef __DRI_SWAP_CONTROL
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001781 GLXContext gc = __glXGetCurrentContext();
1782
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001783 if ( interval < 0 ) {
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001784 return GLX_BAD_VALUE;
1785 }
1786
Kristian Høgsberg020c64b2008-03-08 21:57:29 -05001787 if (gc != NULL && gc->driContext) {
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001788 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy,
1789 gc->screen );
1790
1791 if ( (psc != NULL) && (psc->driScreen != NULL) ) {
1792 __GLXDRIdrawable *pdraw =
1793 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL);
1794 if (psc->swapControl != NULL && pdraw != NULL) {
1795 psc->swapControl->setSwapInterval(pdraw->driDrawable, interval);
1796 return 0;
1797 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001798 }
1799 }
1800#else
1801 (void) interval;
1802#endif
1803
1804 return GLX_BAD_CONTEXT;
1805}
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001806
Brian Paul841a8232006-03-09 16:25:46 +00001807
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001808static int __glXGetSwapIntervalMESA(void)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001809{
Kristian Høgsbergefaf90b2007-05-15 16:09:44 -04001810#ifdef __DRI_SWAP_CONTROL
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001811 GLXContext gc = __glXGetCurrentContext();
1812
Kristian Høgsberg020c64b2008-03-08 21:57:29 -05001813 if (gc != NULL && gc->driContext) {
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001814 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy,
1815 gc->screen );
1816
1817 if ( (psc != NULL) && (psc->driScreen != NULL) ) {
1818 __GLXDRIdrawable *pdraw =
1819 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL);
1820 if (psc->swapControl != NULL && pdraw != NULL) {
1821 return psc->swapControl->getSwapInterval(pdraw->driDrawable);
1822 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001823 }
1824 }
1825#endif
1826
1827 return 0;
1828}
1829
1830
1831/*
1832** GLX_MESA_swap_frame_usage
1833*/
1834
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001835static GLint __glXBeginFrameTrackingMESA(Display *dpy, GLXDrawable drawable)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001836{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001837 int status = GLX_BAD_CONTEXT;
Kristian Høgsberga7a0a2b2007-05-16 15:50:40 -04001838#ifdef __DRI_FRAME_TRACKING
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001839 int screen;
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -04001840 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen);
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001841 __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001842
Kristian Høgsberga7a0a2b2007-05-16 15:50:40 -04001843 if (pdraw != NULL && psc->frameTracking != NULL)
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001844 status = psc->frameTracking->frameTracking(pdraw->driDrawable, GL_TRUE);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001845#else
1846 (void) dpy;
1847 (void) drawable;
1848#endif
1849 return status;
1850}
1851
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001852
1853static GLint __glXEndFrameTrackingMESA(Display *dpy, GLXDrawable drawable)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001854{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001855 int status = GLX_BAD_CONTEXT;
Kristian Høgsberga7a0a2b2007-05-16 15:50:40 -04001856#ifdef __DRI_FRAME_TRACKING
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001857 int screen;
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001858 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, & screen);
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -04001859 __GLXscreenConfigs *psc = GetGLXScreenConfigs(dpy, screen);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001860
Kristian Høgsberga7a0a2b2007-05-16 15:50:40 -04001861 if (pdraw != NULL && psc->frameTracking != NULL)
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001862 status = psc->frameTracking->frameTracking(pdraw->driDrawable,
1863 GL_FALSE);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001864#else
1865 (void) dpy;
1866 (void) drawable;
1867#endif
1868 return status;
1869}
1870
1871
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001872static GLint __glXGetFrameUsageMESA(Display *dpy, GLXDrawable drawable,
1873 GLfloat *usage)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001874{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001875 int status = GLX_BAD_CONTEXT;
Kristian Høgsberga7a0a2b2007-05-16 15:50:40 -04001876#ifdef __DRI_FRAME_TRACKING
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001877 int screen;
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001878 __GLXDRIdrawable * const pdraw = GetGLXDRIDrawable(dpy, drawable, & screen);
1879 __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001880
Kristian Høgsberga7a0a2b2007-05-16 15:50:40 -04001881 if (pdraw != NULL && psc->frameTracking != NULL) {
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001882 int64_t sbc, missedFrames;
1883 float lastMissedUsage;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001884
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001885 status = psc->frameTracking->queryFrameTracking(pdraw->driDrawable,
1886 &sbc,
1887 &missedFrames,
1888 &lastMissedUsage,
1889 usage);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001890 }
1891#else
1892 (void) dpy;
1893 (void) drawable;
1894 (void) usage;
1895#endif
1896 return status;
1897}
1898
1899
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001900static GLint __glXQueryFrameTrackingMESA(Display *dpy, GLXDrawable drawable,
1901 int64_t *sbc, int64_t *missedFrames,
1902 GLfloat *lastMissedUsage)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001903{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001904 int status = GLX_BAD_CONTEXT;
Kristian Høgsberga7a0a2b2007-05-16 15:50:40 -04001905#ifdef __DRI_FRAME_TRACKING
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001906 int screen;
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001907 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, & screen);
1908 __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001909
Kristian Høgsberga7a0a2b2007-05-16 15:50:40 -04001910 if (pdraw != NULL && psc->frameTracking != NULL) {
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001911 float usage;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001912
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -04001913 status = psc->frameTracking->queryFrameTracking(pdraw->driDrawable,
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001914 sbc, missedFrames,
1915 lastMissedUsage, &usage);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001916 }
1917#else
1918 (void) dpy;
1919 (void) drawable;
1920 (void) sbc;
1921 (void) missedFrames;
1922 (void) lastMissedUsage;
1923#endif
1924 return status;
1925}
1926
1927
1928/*
1929** GLX_SGI_video_sync
1930*/
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001931static int __glXGetVideoSyncSGI(unsigned int *count)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001932{
1933 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1934 * FIXME: there should be a GLX encoding for this call. I can find no
1935 * FIXME: documentation for the GLX encoding.
1936 */
Kristian Høgsberg106a6f22007-05-16 18:13:41 -04001937#ifdef __DRI_MEDIA_STREAM_COUNTER
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001938 GLXContext gc = __glXGetCurrentContext();
1939
1940
Kristian Høgsberg020c64b2008-03-08 21:57:29 -05001941 if (gc != NULL && gc->driContext) {
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001942 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy,
1943 gc->screen );
1944 if ( psc->msc && psc->driScreen ) {
1945 __GLXDRIdrawable *pdraw =
1946 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL);
1947 int64_t temp;
1948 int ret;
1949
1950 ret = (*psc->msc->getDrawableMSC)(psc->__driScreen,
1951 pdraw->driDrawable, &temp);
1952 *count = (unsigned) temp;
Kristian Høgsberg6e8d21d2008-02-25 16:14:37 -05001953
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001954 return (ret == 0) ? 0 : GLX_BAD_CONTEXT;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001955 }
1956 }
1957#else
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001958 (void) count;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001959#endif
1960 return GLX_BAD_CONTEXT;
1961}
1962
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001963static int __glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001964{
Kristian Høgsberg106a6f22007-05-16 18:13:41 -04001965#ifdef __DRI_MEDIA_STREAM_COUNTER
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001966 GLXContext gc = __glXGetCurrentContext();
1967
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001968 if ( divisor <= 0 || remainder < 0 )
1969 return GLX_BAD_VALUE;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001970
Kristian Høgsberg020c64b2008-03-08 21:57:29 -05001971 if (gc != NULL && gc->driContext) {
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001972 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy,
1973 gc->screen );
1974 if (psc->msc != NULL && psc->driScreen ) {
1975 __GLXDRIdrawable *pdraw =
1976 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL);
1977 int ret;
1978 int64_t msc;
1979 int64_t sbc;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001980
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04001981 ret = (*psc->msc->waitForMSC)(pdraw->driDrawable, 0,
1982 divisor, remainder, &msc, &sbc);
1983 *count = (unsigned) msc;
1984 return (ret == 0) ? 0 : GLX_BAD_CONTEXT;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001985 }
1986 }
1987#else
1988 (void) count;
1989#endif
1990 return GLX_BAD_CONTEXT;
1991}
1992
1993
1994/*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001995** GLX_SGIX_fbconfig
1996** Many of these functions are aliased to GLX 1.3 entry points in the
1997** GLX_functions table.
1998*/
1999
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002000PUBLIC GLX_ALIAS(int, glXGetFBConfigAttribSGIX,
2001 (Display *dpy, GLXFBConfigSGIX config, int attribute, int *value),
2002 (dpy, config, attribute, value),
2003 glXGetFBConfigAttrib)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002004
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002005PUBLIC GLX_ALIAS(GLXFBConfigSGIX *, glXChooseFBConfigSGIX,
2006 (Display *dpy, int screen, int *attrib_list, int *nelements),
2007 (dpy, screen, attrib_list, nelements),
2008 glXChooseFBConfig)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002009
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002010PUBLIC GLX_ALIAS(XVisualInfo *, glXGetVisualFromFBConfigSGIX,
2011 (Display * dpy, GLXFBConfigSGIX config),
2012 (dpy, config),
2013 glXGetVisualFromFBConfig)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002014
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002015PUBLIC GLXPixmap glXCreateGLXPixmapWithConfigSGIX(Display *dpy,
2016 GLXFBConfigSGIX config, Pixmap pixmap)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002017{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002018 xGLXVendorPrivateWithReplyReq *vpreq;
2019 xGLXCreateGLXPixmapWithConfigSGIXReq *req;
2020 GLXPixmap xid = None;
2021 CARD8 opcode;
2022 const __GLcontextModes * const fbconfig = (__GLcontextModes *) config;
2023 __GLXscreenConfigs * psc;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002024
2025
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002026 if ( (dpy == NULL) || (config == NULL) ) {
2027 return None;
2028 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002029
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002030 psc = GetGLXScreenConfigs( dpy, fbconfig->screen );
2031 if ( (psc != NULL)
2032 && __glXExtensionBitIsEnabled( psc, SGIX_fbconfig_bit ) ) {
2033 opcode = __glXSetupForCommand(dpy);
2034 if (!opcode) {
2035 return None;
2036 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002037
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002038 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2039 LockDisplay(dpy);
2040 GetReqExtra(GLXVendorPrivateWithReply,
2041 sz_xGLXCreateGLXPixmapWithConfigSGIXReq-sz_xGLXVendorPrivateWithReplyReq,vpreq);
2042 req = (xGLXCreateGLXPixmapWithConfigSGIXReq *)vpreq;
2043 req->reqType = opcode;
2044 req->glxCode = X_GLXVendorPrivateWithReply;
2045 req->vendorCode = X_GLXvop_CreateGLXPixmapWithConfigSGIX;
2046 req->screen = fbconfig->screen;
2047 req->fbconfig = fbconfig->fbconfigID;
2048 req->pixmap = pixmap;
2049 req->glxpixmap = xid = XAllocID(dpy);
2050 UnlockDisplay(dpy);
2051 SyncHandle();
2052 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002053
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002054 return xid;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002055}
2056
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002057PUBLIC GLXContext glXCreateContextWithConfigSGIX(Display *dpy,
2058 GLXFBConfigSGIX config, int renderType,
2059 GLXContext shareList, Bool allowDirect)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002060{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002061 GLXContext gc = NULL;
2062 const __GLcontextModes * const fbconfig = (__GLcontextModes *) config;
2063 __GLXscreenConfigs * psc;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002064
2065
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002066 if ( (dpy == NULL) || (config == NULL) ) {
2067 return None;
2068 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002069
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002070 psc = GetGLXScreenConfigs( dpy, fbconfig->screen );
2071 if ( (psc != NULL)
2072 && __glXExtensionBitIsEnabled( psc, SGIX_fbconfig_bit ) ) {
2073 gc = CreateContext( dpy, NULL, (__GLcontextModes *) config, shareList,
2074 allowDirect, None, False, renderType );
2075 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002076
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002077 return gc;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002078}
2079
2080
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002081PUBLIC GLXFBConfigSGIX glXGetFBConfigFromVisualSGIX(Display *dpy,
2082 XVisualInfo *vis)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002083{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002084 __GLXdisplayPrivate *priv;
2085 __GLXscreenConfigs *psc;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002086
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002087 if ( (GetGLXPrivScreenConfig( dpy, vis->screen, & priv, & psc ) != Success)
2088 && __glXExtensionBitIsEnabled( psc, SGIX_fbconfig_bit )
2089 && (psc->configs->fbconfigID != GLX_DONT_CARE) ) {
2090 return (GLXFBConfigSGIX) _gl_context_modes_find_visual( psc->configs,
2091 vis->visualid );
2092 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002093
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002094 return NULL;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002095}
2096
2097
2098/*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002099** GLX_SGIX_swap_group
2100*/
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002101static void __glXJoinSwapGroupSGIX(Display *dpy, GLXDrawable drawable,
2102 GLXDrawable member)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002103{
2104 (void) dpy;
2105 (void) drawable;
2106 (void) member;
2107}
2108
2109
2110/*
2111** GLX_SGIX_swap_barrier
2112*/
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002113static void __glXBindSwapBarrierSGIX(Display *dpy, GLXDrawable drawable,
2114 int barrier)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002115{
2116 (void) dpy;
2117 (void) drawable;
2118 (void) barrier;
2119}
2120
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002121static Bool __glXQueryMaxSwapBarriersSGIX(Display *dpy, int screen, int *max)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002122{
2123 (void) dpy;
2124 (void) screen;
2125 (void) max;
2126 return False;
2127}
2128
2129
2130/*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002131** GLX_OML_sync_control
2132*/
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002133static Bool __glXGetSyncValuesOML(Display *dpy, GLXDrawable drawable,
2134 int64_t *ust, int64_t *msc, int64_t *sbc)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002135{
Kristian Høgsberg106a6f22007-05-16 18:13:41 -04002136#if defined(__DRI_SWAP_BUFFER_COUNTER) && defined(__DRI_MEDIA_STREAM_COUNTER)
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002137 __GLXdisplayPrivate * const priv = __glXInitialize(dpy);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002138
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002139 if ( priv != NULL ) {
2140 int i;
2141 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &i);
2142 __GLXscreenConfigs * const psc = &priv->screenConfigs[i];
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002143
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002144 assert( (pdraw == NULL) || (i != -1) );
2145 return ( (pdraw && psc->sbc && psc->msc)
2146 && ((*psc->msc->getMSC)(psc->driScreen, msc) == 0)
2147 && ((*psc->sbc->getSBC)(pdraw->driDrawable, sbc) == 0)
2148 && (__glXGetUST(ust) == 0) );
2149 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002150#else
2151 (void) dpy;
2152 (void) drawable;
2153 (void) ust;
2154 (void) msc;
2155 (void) sbc;
2156#endif
2157 return False;
2158}
2159
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002160#ifdef GLX_DIRECT_RENDERING
Kristian Høgsberg3d28a262008-03-08 22:28:01 -05002161_X_HIDDEN GLboolean
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002162__driGetMscRateOML(__DRIdrawable *draw,
2163 int32_t *numerator, int32_t *denominator, void *private)
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002164{
2165#ifdef XF86VIDMODE
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002166 __GLXscreenConfigs *psc;
2167 XF86VidModeModeLine mode_line;
2168 int dot_clock;
2169 int i;
2170 __GLXDRIdrawable *glxDraw = private;
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002171
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002172 psc = glxDraw->psc;
2173 if (XF86VidModeQueryVersion(psc->dpy, &i, &i) &&
2174 XF86VidModeGetModeLine(psc->dpy, psc->scr, &dot_clock, &mode_line) ) {
2175 unsigned n = dot_clock * 1000;
2176 unsigned d = mode_line.vtotal * mode_line.htotal;
2177
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002178# define V_INTERLACE 0x010
2179# define V_DBLSCAN 0x020
2180
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002181 if (mode_line.flags & V_INTERLACE)
2182 n *= 2;
2183 else if (mode_line.flags & V_DBLSCAN)
2184 d *= 2;
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002185
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002186 /* The OML_sync_control spec requires that if the refresh rate is a
2187 * whole number, that the returned numerator be equal to the refresh
2188 * rate and the denominator be 1.
2189 */
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002190
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002191 if (n % d == 0) {
2192 n /= d;
2193 d = 1;
2194 }
2195 else {
2196 static const unsigned f[] = { 13, 11, 7, 5, 3, 2, 0 };
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002197
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002198 /* This is a poor man's way to reduce a fraction. It's far from
2199 * perfect, but it will work well enough for this situation.
2200 */
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002201
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002202 for (i = 0; f[i] != 0; i++) {
2203 while (n % f[i] == 0 && d % f[i] == 0) {
2204 d /= f[i];
2205 n /= f[i];
2206 }
2207 }
2208 }
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002209
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002210 *numerator = n;
2211 *denominator = d;
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002212
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002213 return True;
2214 }
2215 else
2216 return False;
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002217#else
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002218 return False;
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002219#endif
2220}
2221#endif
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002222
2223/**
2224 * Determine the refresh rate of the specified drawable and display.
2225 *
2226 * \param dpy Display whose refresh rate is to be determined.
2227 * \param drawable Drawable whose refresh rate is to be determined.
2228 * \param numerator Numerator of the refresh rate.
2229 * \param demoninator Denominator of the refresh rate.
2230 * \return If the refresh rate for the specified display and drawable could
2231 * be calculated, True is returned. Otherwise False is returned.
2232 *
2233 * \note This function is implemented entirely client-side. A lot of other
2234 * functionality is required to export GLX_OML_sync_control, so on
2235 * XFree86 this function can be called for direct-rendering contexts
2236 * when GLX_OML_sync_control appears in the client extension string.
2237 */
2238
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002239_X_HIDDEN GLboolean __glXGetMscRateOML(Display * dpy, GLXDrawable drawable,
2240 int32_t * numerator,
2241 int32_t * denominator)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002242{
2243#if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002244 __GLXDRIdrawable *draw = GetGLXDRIDrawable(dpy, drawable, NULL);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002245
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002246 if (draw == NULL)
2247 return False;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002248
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002249 return __driGetMscRateOML(draw->driDrawable, numerator, denominator, draw);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002250#else
Kristian Høgsberg286ce272007-11-06 14:34:15 -05002251 (void) dpy;
2252 (void) drawable;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002253 (void) numerator;
2254 (void) denominator;
2255#endif
2256 return False;
2257}
2258
2259
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002260static int64_t __glXSwapBuffersMscOML(Display *dpy, GLXDrawable drawable,
2261 int64_t target_msc, int64_t divisor,
2262 int64_t remainder)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002263{
Kristian Høgsberg106a6f22007-05-16 18:13:41 -04002264#ifdef __DRI_SWAP_BUFFER_COUNTER
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002265 int screen;
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -04002266 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen);
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002267 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen );
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002268
2269 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2270 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2271 * of -1 if the function failed because of errors detected in the input
2272 * parameters"
2273 */
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002274 if ( divisor < 0 || remainder < 0 || target_msc < 0 )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002275 return -1;
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002276 if ( divisor > 0 && remainder >= divisor )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002277 return -1;
2278
Kristian Høgsberg106a6f22007-05-16 18:13:41 -04002279 if (pdraw != NULL && psc->counters != NULL)
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002280 return (*psc->sbc->swapBuffersMSC)(pdraw->driDrawable, target_msc,
2281 divisor, remainder);
Kristian Høgsberg106a6f22007-05-16 18:13:41 -04002282
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002283#else
2284 (void) dpy;
2285 (void) drawable;
2286 (void) target_msc;
2287 (void) divisor;
2288 (void) remainder;
2289#endif
2290 return 0;
2291}
2292
2293
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002294static Bool __glXWaitForMscOML(Display * dpy, GLXDrawable drawable,
2295 int64_t target_msc, int64_t divisor,
2296 int64_t remainder, int64_t *ust,
2297 int64_t *msc, int64_t *sbc)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002298{
Kristian Høgsberg106a6f22007-05-16 18:13:41 -04002299#ifdef __DRI_MEDIA_STREAM_COUNTER
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002300 int screen;
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -04002301 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen);
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002302 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen );
2303 int ret;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002304
2305 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2306 * error", but the return type in the spec is Bool.
2307 */
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002308 if ( divisor < 0 || remainder < 0 || target_msc < 0 )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002309 return False;
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002310 if ( divisor > 0 && remainder >= divisor )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002311 return False;
2312
Kristian Høgsberg106a6f22007-05-16 18:13:41 -04002313 if (pdraw != NULL && psc->msc != NULL) {
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002314 ret = (*psc->msc->waitForMSC)(pdraw->driDrawable, target_msc,
2315 divisor, remainder, msc, sbc);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002316
2317 /* __glXGetUST returns zero on success and non-zero on failure.
2318 * This function returns True on success and False on failure.
2319 */
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002320 return ( (ret == 0) && (__glXGetUST( ust ) == 0) );
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002321 }
2322#else
2323 (void) dpy;
2324 (void) drawable;
2325 (void) target_msc;
2326 (void) divisor;
2327 (void) remainder;
2328 (void) ust;
2329 (void) msc;
2330 (void) sbc;
2331#endif
2332 return False;
2333}
2334
2335
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002336static Bool __glXWaitForSbcOML(Display * dpy, GLXDrawable drawable,
2337 int64_t target_sbc, int64_t *ust,
2338 int64_t *msc, int64_t *sbc )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002339{
Kristian Høgsberg106a6f22007-05-16 18:13:41 -04002340#ifdef __DRI_SWAP_BUFFER_COUNTER
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002341 int screen;
Kristian Høgsberge82dd8c2008-03-26 19:26:59 -04002342 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen);
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002343 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen );
2344 int ret;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002345
2346 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2347 * error", but the return type in the spec is Bool.
2348 */
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002349 if ( target_sbc < 0 )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002350 return False;
2351
Kristian Høgsberg106a6f22007-05-16 18:13:41 -04002352 if (pdraw != NULL && psc->sbc != NULL) {
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002353 ret = (*psc->sbc->waitForSBC)(pdraw->driDrawable, target_sbc, msc, sbc);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002354
2355 /* __glXGetUST returns zero on success and non-zero on failure.
2356 * This function returns True on success and False on failure.
2357 */
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002358 return( (ret == 0) && (__glXGetUST( ust ) == 0) );
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002359 }
2360#else
2361 (void) dpy;
2362 (void) drawable;
2363 (void) target_sbc;
2364 (void) ust;
2365 (void) msc;
2366 (void) sbc;
2367#endif
2368 return False;
2369}
2370
2371
2372/**
2373 * GLX_MESA_allocate_memory
2374 */
2375/*@{*/
2376
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002377PUBLIC void *glXAllocateMemoryMESA(Display *dpy, int scrn,
2378 size_t size, float readFreq,
2379 float writeFreq, float priority)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002380{
Kristian Høgsberg78a6aa52007-05-16 14:10:29 -04002381#ifdef __DRI_ALLOCATE
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002382 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, scrn );
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002383
Kristian Høgsberg78a6aa52007-05-16 14:10:29 -04002384 if (psc && psc->allocate)
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002385 return (*psc->allocate->allocateMemory)(psc->__driScreen, size,
2386 readFreq, writeFreq, priority);
Kristian Høgsberg78a6aa52007-05-16 14:10:29 -04002387
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002388#else
2389 (void) dpy;
2390 (void) scrn;
2391 (void) size;
2392 (void) readFreq;
2393 (void) writeFreq;
2394 (void) priority;
2395#endif /* GLX_DIRECT_RENDERING */
2396
2397 return NULL;
2398}
2399
2400
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002401PUBLIC void glXFreeMemoryMESA(Display *dpy, int scrn, void *pointer)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002402{
Kristian Høgsberg78a6aa52007-05-16 14:10:29 -04002403#ifdef __DRI_ALLOCATE
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002404 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, scrn );
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002405
Kristian Høgsberg78a6aa52007-05-16 14:10:29 -04002406 if (psc && psc->allocate)
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002407 (*psc->allocate->freeMemory)(psc->__driScreen, pointer);
Kristian Høgsberg78a6aa52007-05-16 14:10:29 -04002408
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002409#else
2410 (void) dpy;
2411 (void) scrn;
2412 (void) pointer;
2413#endif /* GLX_DIRECT_RENDERING */
2414}
2415
2416
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002417PUBLIC GLuint glXGetMemoryOffsetMESA( Display *dpy, int scrn,
2418 const void *pointer )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002419{
Kristian Høgsberg78a6aa52007-05-16 14:10:29 -04002420#ifdef __DRI_ALLOCATE
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002421 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, scrn );
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002422
Kristian Høgsberg78a6aa52007-05-16 14:10:29 -04002423 if (psc && psc->allocate)
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002424 return (*psc->allocate->memoryOffset)(psc->__driScreen, pointer);
Kristian Høgsberg78a6aa52007-05-16 14:10:29 -04002425
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002426#else
2427 (void) dpy;
2428 (void) scrn;
2429 (void) pointer;
2430#endif /* GLX_DIRECT_RENDERING */
2431
2432 return ~0L;
2433}
2434/*@}*/
2435
2436
2437/**
2438 * Mesa extension stubs. These will help reduce portability problems.
2439 */
2440/*@{*/
2441
2442/**
2443 * Release all buffers associated with the specified GLX drawable.
2444 *
2445 * \todo
2446 * This function was intended for stand-alone Mesa. The issue there is that
2447 * the library doesn't get any notification when a window is closed. In
2448 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2449 * supported, there are 3 different functions to destroy a drawable. It
2450 * should be possible to create GLX protocol (or have it determine which
2451 * protocol to use based on the type of the drawable) to have one function
2452 * do the work of 3. For the direct-rendering case, this function could
2453 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2454 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2455 * would need to be used. This really should be done as part of the new DRI
2456 * interface work.
2457 *
2458 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2459 * __driGarbageCollectDrawables
2460 * glXDestroyGLXPixmap
2461 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2462 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2463 */
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002464static Bool __glXReleaseBuffersMESA( Display *dpy, GLXDrawable d )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002465{
2466 (void) dpy;
2467 (void) d;
2468 return False;
2469}
2470
2471
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002472PUBLIC GLXPixmap glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visual,
2473 Pixmap pixmap, Colormap cmap )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002474{
2475 (void) dpy;
2476 (void) visual;
2477 (void) pixmap;
2478 (void) cmap;
2479 return 0;
2480}
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002481/*@}*/
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002482
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002483
2484/**
2485 * GLX_MESA_copy_sub_buffer
2486 */
Brian Paulf2ad1b62006-03-31 15:48:04 +00002487#define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002488static void __glXCopySubBufferMESA(Display *dpy, GLXDrawable drawable,
2489 int x, int y, int width, int height)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002490{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002491 xGLXVendorPrivateReq *req;
2492 GLXContext gc;
2493 GLXContextTag tag;
2494 CARD32 *drawable_ptr;
2495 INT32 *x_ptr, *y_ptr, *w_ptr, *h_ptr;
2496 CARD8 opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002497
Kristian Høgsbergac3e8382007-05-15 15:17:30 -04002498#ifdef __DRI_COPY_SUB_BUFFER
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002499 int screen;
2500 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen);
2501 if ( pdraw != NULL ) {
2502 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen );
2503 if (psc->copySubBuffer != NULL) {
2504 (*psc->copySubBuffer->copySubBuffer)(pdraw->driDrawable,
2505 x, y, width, height);
2506 }
Brian Paulf2ad1b62006-03-31 15:48:04 +00002507
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002508 return;
2509 }
Brian Paulf2ad1b62006-03-31 15:48:04 +00002510#endif
2511
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002512 opcode = __glXSetupForCommand(dpy);
2513 if (!opcode)
2514 return;
Brian Paulf2ad1b62006-03-31 15:48:04 +00002515
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002516 /*
Brian Paulf2ad1b62006-03-31 15:48:04 +00002517 ** The calling thread may or may not have a current context. If it
2518 ** does, send the context tag so the server can do a flush.
2519 */
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002520 gc = __glXGetCurrentContext();
2521 if ((gc != NULL) && (dpy == gc->currentDpy) &&
2522 ((drawable == gc->currentDrawable) ||
2523 (drawable == gc->currentReadable)) ) {
2524 tag = gc->currentContextTag;
2525 } else {
2526 tag = 0;
2527 }
Brian Paulf2ad1b62006-03-31 15:48:04 +00002528
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002529 LockDisplay(dpy);
2530 GetReqExtra(GLXVendorPrivate, sizeof(CARD32) + sizeof(INT32) * 4,req);
2531 req->reqType = opcode;
2532 req->glxCode = X_GLXVendorPrivate;
2533 req->vendorCode = X_GLXvop_CopySubBufferMESA;
2534 req->contextTag = tag;
Brian Paulf2ad1b62006-03-31 15:48:04 +00002535
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002536 drawable_ptr = (CARD32 *) (req + 1);
2537 x_ptr = (INT32 *) (drawable_ptr + 1);
2538 y_ptr = (INT32 *) (drawable_ptr + 2);
2539 w_ptr = (INT32 *) (drawable_ptr + 3);
2540 h_ptr = (INT32 *) (drawable_ptr + 4);
Brian Paulf2ad1b62006-03-31 15:48:04 +00002541
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002542 *drawable_ptr = drawable;
2543 *x_ptr = x;
2544 *y_ptr = y;
2545 *w_ptr = width;
2546 *h_ptr = height;
Brian Paulf2ad1b62006-03-31 15:48:04 +00002547
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002548 UnlockDisplay(dpy);
2549 SyncHandle();
Brian Paulf2ad1b62006-03-31 15:48:04 +00002550}
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002551
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002552
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002553/**
2554 * GLX_EXT_texture_from_pixmap
2555 */
2556/*@{*/
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002557static void __glXBindTexImageEXT(Display *dpy,
2558 GLXDrawable drawable,
2559 int buffer,
2560 const int *attrib_list)
Brian Paul42725d62006-02-07 00:39:56 +00002561{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002562 xGLXVendorPrivateReq *req;
2563 GLXContext gc = __glXGetCurrentContext();
2564 CARD32 *drawable_ptr;
2565 INT32 *buffer_ptr;
2566 CARD32 *num_attrib_ptr;
2567 CARD32 *attrib_ptr;
2568 CARD8 opcode;
2569 unsigned int i;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002570
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002571 if (gc == NULL)
2572 return;
Brian Paul42725d62006-02-07 00:39:56 +00002573
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002574 i = 0;
2575 if (attrib_list) {
2576 while (attrib_list[i * 2] != None)
2577 i++;
2578 }
2579
Brian Paul42725d62006-02-07 00:39:56 +00002580#ifdef GLX_DIRECT_RENDERING
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002581 if (gc->driContext) {
2582 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, NULL);
RALOVICH, Kristóf12933562008-10-13 14:06:30 +02002583
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002584 if (pdraw != NULL)
2585 (*pdraw->psc->texBuffer->setTexBuffer)(gc->__driContext,
2586 pdraw->textureTarget,
2587 pdraw->driDrawable);
RALOVICH, Kristóf12933562008-10-13 14:06:30 +02002588
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002589 return;
2590 }
Brian Paul42725d62006-02-07 00:39:56 +00002591#endif
2592
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002593 opcode = __glXSetupForCommand(dpy);
2594 if (!opcode)
2595 return;
Brian Paul42725d62006-02-07 00:39:56 +00002596
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002597 LockDisplay(dpy);
2598 GetReqExtra(GLXVendorPrivate, 12 + 8 * i,req);
2599 req->reqType = opcode;
2600 req->glxCode = X_GLXVendorPrivate;
2601 req->vendorCode = X_GLXvop_BindTexImageEXT;
2602 req->contextTag = gc->currentContextTag;
Brian Paul42725d62006-02-07 00:39:56 +00002603
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002604 drawable_ptr = (CARD32 *) (req + 1);
2605 buffer_ptr = (INT32 *) (drawable_ptr + 1);
2606 num_attrib_ptr = (CARD32 *) (buffer_ptr + 1);
2607 attrib_ptr = (CARD32 *) (num_attrib_ptr + 1);
Brian Paul42725d62006-02-07 00:39:56 +00002608
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002609 *drawable_ptr = drawable;
2610 *buffer_ptr = buffer;
2611 *num_attrib_ptr = (CARD32) i;
Brian Paul42725d62006-02-07 00:39:56 +00002612
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002613 i = 0;
2614 if (attrib_list) {
2615 while (attrib_list[i * 2] != None)
2616 {
2617 *attrib_ptr++ = (CARD32) attrib_list[i * 2 + 0];
2618 *attrib_ptr++ = (CARD32) attrib_list[i * 2 + 1];
2619 i++;
2620 }
2621 }
RALOVICH, Kristóf12933562008-10-13 14:06:30 +02002622
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002623 UnlockDisplay(dpy);
2624 SyncHandle();
Brian Paul42725d62006-02-07 00:39:56 +00002625}
RALOVICH, Kristóf12933562008-10-13 14:06:30 +02002626
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002627static void __glXReleaseTexImageEXT(Display *dpy,
2628 GLXDrawable drawable,
2629 int buffer)
RALOVICH, Kristóf12933562008-10-13 14:06:30 +02002630{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002631 xGLXVendorPrivateReq *req;
2632 GLXContext gc = __glXGetCurrentContext();
2633 CARD32 *drawable_ptr;
2634 INT32 *buffer_ptr;
2635 CARD8 opcode;
RALOVICH, Kristóf12933562008-10-13 14:06:30 +02002636
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002637 if (gc == NULL)
2638 return;
RALOVICH, Kristóf12933562008-10-13 14:06:30 +02002639
2640#ifdef GLX_DIRECT_RENDERING
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002641 if (gc->driContext)
2642 return;
RALOVICH, Kristóf12933562008-10-13 14:06:30 +02002643#endif
2644
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002645 opcode = __glXSetupForCommand(dpy);
2646 if (!opcode)
2647 return;
RALOVICH, Kristóf12933562008-10-13 14:06:30 +02002648
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002649 LockDisplay(dpy);
2650 GetReqExtra(GLXVendorPrivate, sizeof(CARD32)+sizeof(INT32),req);
2651 req->reqType = opcode;
2652 req->glxCode = X_GLXVendorPrivate;
2653 req->vendorCode = X_GLXvop_ReleaseTexImageEXT;
2654 req->contextTag = gc->currentContextTag;
RALOVICH, Kristóf12933562008-10-13 14:06:30 +02002655
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002656 drawable_ptr = (CARD32 *) (req + 1);
2657 buffer_ptr = (INT32 *) (drawable_ptr + 1);
RALOVICH, Kristóf12933562008-10-13 14:06:30 +02002658
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002659 *drawable_ptr = drawable;
2660 *buffer_ptr = buffer;
RALOVICH, Kristóf12933562008-10-13 14:06:30 +02002661
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002662 UnlockDisplay(dpy);
2663 SyncHandle();
RALOVICH, Kristóf12933562008-10-13 14:06:30 +02002664}
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002665/*@}*/
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002666
2667/**
2668 * \c strdup is actually not a standard ANSI C or POSIX routine.
2669 * Irix will not define it if ANSI mode is in effect.
2670 *
2671 * \sa strdup
2672 */
Kristian Høgsberg3d28a262008-03-08 22:28:01 -05002673_X_HIDDEN char *
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002674__glXstrdup(const char *str)
2675{
2676 char *copy;
2677 copy = (char *) Xmalloc(strlen(str) + 1);
2678 if (!copy)
2679 return NULL;
2680 strcpy(copy, str);
2681 return copy;
2682}
2683
2684/*
2685** glXGetProcAddress support
2686*/
2687
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002688struct name_address_pair {
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002689 const char *Name;
2690 GLvoid *Address;
2691};
2692
2693#define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2694#define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2695
2696static const struct name_address_pair GLX_functions[] = {
2697 /*** GLX_VERSION_1_0 ***/
2698 GLX_FUNCTION( glXChooseVisual ),
2699 GLX_FUNCTION( glXCopyContext ),
2700 GLX_FUNCTION( glXCreateContext ),
2701 GLX_FUNCTION( glXCreateGLXPixmap ),
2702 GLX_FUNCTION( glXDestroyContext ),
2703 GLX_FUNCTION( glXDestroyGLXPixmap ),
2704 GLX_FUNCTION( glXGetConfig ),
2705 GLX_FUNCTION( glXGetCurrentContext ),
2706 GLX_FUNCTION( glXGetCurrentDrawable ),
2707 GLX_FUNCTION( glXIsDirect ),
2708 GLX_FUNCTION( glXMakeCurrent ),
2709 GLX_FUNCTION( glXQueryExtension ),
2710 GLX_FUNCTION( glXQueryVersion ),
2711 GLX_FUNCTION( glXSwapBuffers ),
2712 GLX_FUNCTION( glXUseXFont ),
2713 GLX_FUNCTION( glXWaitGL ),
2714 GLX_FUNCTION( glXWaitX ),
2715
2716 /*** GLX_VERSION_1_1 ***/
2717 GLX_FUNCTION( glXGetClientString ),
2718 GLX_FUNCTION( glXQueryExtensionsString ),
2719 GLX_FUNCTION( glXQueryServerString ),
2720
2721 /*** GLX_VERSION_1_2 ***/
2722 GLX_FUNCTION( glXGetCurrentDisplay ),
2723
2724 /*** GLX_VERSION_1_3 ***/
2725 GLX_FUNCTION( glXChooseFBConfig ),
2726 GLX_FUNCTION( glXCreateNewContext ),
2727 GLX_FUNCTION( glXCreatePbuffer ),
2728 GLX_FUNCTION( glXCreatePixmap ),
2729 GLX_FUNCTION( glXCreateWindow ),
2730 GLX_FUNCTION( glXDestroyPbuffer ),
2731 GLX_FUNCTION( glXDestroyPixmap ),
2732 GLX_FUNCTION( glXDestroyWindow ),
2733 GLX_FUNCTION( glXGetCurrentReadDrawable ),
2734 GLX_FUNCTION( glXGetFBConfigAttrib ),
2735 GLX_FUNCTION( glXGetFBConfigs ),
2736 GLX_FUNCTION( glXGetSelectedEvent ),
2737 GLX_FUNCTION( glXGetVisualFromFBConfig ),
2738 GLX_FUNCTION( glXMakeContextCurrent ),
2739 GLX_FUNCTION( glXQueryContext ),
2740 GLX_FUNCTION( glXQueryDrawable ),
2741 GLX_FUNCTION( glXSelectEvent ),
2742
2743 /*** GLX_SGI_swap_control ***/
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002744 GLX_FUNCTION2( glXSwapIntervalSGI, __glXSwapIntervalSGI ),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002745
2746 /*** GLX_SGI_video_sync ***/
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002747 GLX_FUNCTION2( glXGetVideoSyncSGI, __glXGetVideoSyncSGI ),
2748 GLX_FUNCTION2( glXWaitVideoSyncSGI, __glXWaitVideoSyncSGI ),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002749
2750 /*** GLX_SGI_make_current_read ***/
2751 GLX_FUNCTION2( glXMakeCurrentReadSGI, glXMakeContextCurrent ),
2752 GLX_FUNCTION2( glXGetCurrentReadDrawableSGI, glXGetCurrentReadDrawable ),
2753
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002754 /*** GLX_EXT_import_context ***/
2755 GLX_FUNCTION( glXFreeContextEXT ),
2756 GLX_FUNCTION( glXGetContextIDEXT ),
2757 GLX_FUNCTION2( glXGetCurrentDisplayEXT, glXGetCurrentDisplay ),
2758 GLX_FUNCTION( glXImportContextEXT ),
2759 GLX_FUNCTION2( glXQueryContextInfoEXT, glXQueryContext ),
2760
2761 /*** GLX_SGIX_fbconfig ***/
2762 GLX_FUNCTION2( glXGetFBConfigAttribSGIX, glXGetFBConfigAttrib ),
2763 GLX_FUNCTION2( glXChooseFBConfigSGIX, glXChooseFBConfig ),
2764 GLX_FUNCTION( glXCreateGLXPixmapWithConfigSGIX ),
2765 GLX_FUNCTION( glXCreateContextWithConfigSGIX ),
2766 GLX_FUNCTION2( glXGetVisualFromFBConfigSGIX, glXGetVisualFromFBConfig ),
2767 GLX_FUNCTION( glXGetFBConfigFromVisualSGIX ),
2768
2769 /*** GLX_SGIX_pbuffer ***/
2770 GLX_FUNCTION( glXCreateGLXPbufferSGIX ),
2771 GLX_FUNCTION( glXDestroyGLXPbufferSGIX ),
2772 GLX_FUNCTION( glXQueryGLXPbufferSGIX ),
2773 GLX_FUNCTION( glXSelectEventSGIX ),
2774 GLX_FUNCTION( glXGetSelectedEventSGIX ),
2775
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002776 /*** GLX_SGIX_swap_group ***/
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002777 GLX_FUNCTION2( glXJoinSwapGroupSGIX, __glXJoinSwapGroupSGIX ),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002778
2779 /*** GLX_SGIX_swap_barrier ***/
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002780 GLX_FUNCTION2( glXBindSwapBarrierSGIX, __glXBindSwapBarrierSGIX ),
2781 GLX_FUNCTION2( glXQueryMaxSwapBarriersSGIX, __glXQueryMaxSwapBarriersSGIX ),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002782
2783 /*** GLX_MESA_allocate_memory ***/
2784 GLX_FUNCTION( glXAllocateMemoryMESA ),
2785 GLX_FUNCTION( glXFreeMemoryMESA ),
2786 GLX_FUNCTION( glXGetMemoryOffsetMESA ),
2787
2788 /*** GLX_MESA_copy_sub_buffer ***/
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002789 GLX_FUNCTION2( glXCopySubBufferMESA, __glXCopySubBufferMESA ),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002790
2791 /*** GLX_MESA_pixmap_colormap ***/
2792 GLX_FUNCTION( glXCreateGLXPixmapMESA ),
2793
2794 /*** GLX_MESA_release_buffers ***/
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002795 GLX_FUNCTION2( glXReleaseBuffersMESA, __glXReleaseBuffersMESA ),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002796
2797 /*** GLX_MESA_swap_control ***/
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002798 GLX_FUNCTION2( glXSwapIntervalMESA, __glXSwapIntervalMESA ),
2799 GLX_FUNCTION2( glXGetSwapIntervalMESA, __glXGetSwapIntervalMESA ),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002800
2801 /*** GLX_MESA_swap_frame_usage ***/
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002802 GLX_FUNCTION2( glXBeginFrameTrackingMESA, __glXBeginFrameTrackingMESA ),
2803 GLX_FUNCTION2( glXEndFrameTrackingMESA, __glXEndFrameTrackingMESA ),
2804 GLX_FUNCTION2( glXGetFrameUsageMESA, __glXGetFrameUsageMESA ),
2805 GLX_FUNCTION2( glXQueryFrameTrackingMESA, __glXQueryFrameTrackingMESA ),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002806
2807 /*** GLX_ARB_get_proc_address ***/
2808 GLX_FUNCTION( glXGetProcAddressARB ),
2809
2810 /*** GLX 1.4 ***/
2811 GLX_FUNCTION2( glXGetProcAddress, glXGetProcAddressARB ),
2812
2813 /*** GLX_OML_sync_control ***/
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002814 GLX_FUNCTION2( glXWaitForSbcOML, __glXWaitForSbcOML ),
2815 GLX_FUNCTION2( glXWaitForMscOML, __glXWaitForMscOML ),
2816 GLX_FUNCTION2( glXSwapBuffersMscOML, __glXSwapBuffersMscOML ),
2817 GLX_FUNCTION2( glXGetMscRateOML, __glXGetMscRateOML ),
2818 GLX_FUNCTION2( glXGetSyncValuesOML, __glXGetSyncValuesOML ),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002819
Brian Paul42725d62006-02-07 00:39:56 +00002820 /*** GLX_EXT_texture_from_pixmap ***/
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002821 GLX_FUNCTION2( glXBindTexImageEXT, __glXBindTexImageEXT ),
2822 GLX_FUNCTION2( glXReleaseTexImageEXT, __glXReleaseTexImageEXT ),
Brian Paul42725d62006-02-07 00:39:56 +00002823
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002824#ifdef GLX_DIRECT_RENDERING
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002825 /*** DRI configuration ***/
2826 GLX_FUNCTION( glXGetScreenDriver ),
2827 GLX_FUNCTION( glXGetDriverConfig ),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002828#endif
2829
2830 { NULL, NULL } /* end of list */
2831};
2832
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002833
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002834static const GLvoid *
2835get_glx_proc_address(const char *funcName)
2836{
2837 GLuint i;
2838
2839 /* try static functions */
2840 for (i = 0; GLX_functions[i].Name; i++) {
2841 if (strcmp(GLX_functions[i].Name, funcName) == 0)
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002842 return GLX_functions[i].Address;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002843 }
2844
2845 return NULL;
2846}
2847
2848
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002849/**
2850 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2851 * \c glXGetProcAddress.
2852 *
2853 * \param procName Name of a GL or GLX function.
2854 * \returns A pointer to the named function
2855 *
2856 * \sa glXGetProcAddress
2857 */
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002858PUBLIC void (*glXGetProcAddressARB(const GLubyte *procName))( void )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002859{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002860 typedef void (*gl_function)( void );
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002861 gl_function f;
2862
2863
2864 /* Search the table of GLX and internal functions first. If that
2865 * fails and the supplied name could be a valid core GL name, try
2866 * searching the core GL function table. This check is done to prevent
2867 * DRI based drivers from searching the core GL function table for
2868 * internal API functions.
2869 */
2870
2871 f = (gl_function) get_glx_proc_address((const char *) procName);
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002872 if ( (f == NULL) && (procName[0] == 'g') && (procName[1] == 'l')
2873 && (procName[2] != 'X') ) {
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002874 f = (gl_function) _glapi_get_proc_address((const char *) procName);
2875 }
2876
2877 return f;
2878}
2879
2880/**
2881 * Get the address of a named GL function. This is the GLX 1.4 name for
2882 * \c glXGetProcAddressARB.
2883 *
2884 * \param procName Name of a GL or GLX function.
2885 * \returns A pointer to the named function
2886 *
2887 * \sa glXGetProcAddressARB
2888 */
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002889PUBLIC void (*glXGetProcAddress(const GLubyte *procName))( void )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002890#if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002891 __attribute__ ((alias ("glXGetProcAddressARB")));
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002892#else
2893{
2894 return glXGetProcAddressARB(procName);
2895}
2896#endif /* __GNUC__ */
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002897
2898
2899#ifdef GLX_DIRECT_RENDERING
2900/**
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002901 * Get the unadjusted system time (UST). Currently, the UST is measured in
2902 * microseconds since Epoc. The actual resolution of the UST may vary from
2903 * system to system, and the units may vary from release to release.
2904 * Drivers should not call this function directly. They should instead use
2905 * \c glXGetProcAddress to obtain a pointer to the function.
2906 *
2907 * \param ust Location to store the 64-bit UST
2908 * \returns Zero on success or a negative errno value on failure.
2909 *
2910 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2911 *
2912 * \since Internal API version 20030317.
2913 */
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002914_X_HIDDEN int __glXGetUST( int64_t * ust )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002915{
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002916 struct timeval tv;
2917
2918 if ( ust == NULL ) {
2919 return -EFAULT;
2920 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002921
Kristian Høgsberg77c7f902008-10-14 23:07:42 -04002922 if ( gettimeofday( & tv, NULL ) == 0 ) {
2923 ust[0] = (tv.tv_sec * 1000000) + tv.tv_usec;
2924 return 0;
2925 } else {
2926 return -errno;
2927 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002928}
2929#endif /* GLX_DIRECT_RENDERING */