blob: 2b0403d37c9c06ab3bb31547ea1f05e3182cf933 [file] [log] [blame]
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001/* $XFree86: xc/lib/GL/glx/glxcmds.c,v 1.30 2004/01/30 20:33:06 alanh Exp $ */
2/*
3** License Applicability. Except to the extent portions of this file are
4** made subject to an alternative license as permitted in the SGI Free
5** Software License B, Version 1.1 (the "License"), the contents of this
6** file are subject only to the provisions of the License. You may not use
7** this file except in compliance with the License. You may obtain a copy
8** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
9** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
10**
11** http://oss.sgi.com/projects/FreeB
12**
13** Note that, as provided in the License, the Software is distributed on an
14** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
15** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
16** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
17** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
18**
19** Original Code. The Original Code is: OpenGL Sample Implementation,
20** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
21** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
22** Copyright in any portions created by third parties is as indicated
23** elsewhere herein. All Rights Reserved.
24**
25** Additional Notice Provisions: The application programming interfaces
26** established by SGI in conjunction with the Original Code are The
27** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
28** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
29** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
30** Window System(R) (Version 1.3), released October 19, 1998. This software
31** was created using the OpenGL(R) version 1.2.1 Sample Implementation
32** published by SGI, but has not been independently verified as being
33** compliant with the OpenGL(R) version 1.2.1 Specification.
34**
35*/
36
37/**
38 * \file glxcmds.c
39 * Client-side GLX interface.
40 */
41
42#include <inttypes.h>
43#include "glxclient.h"
Brian Paul82dfd4b2005-08-11 14:18:53 +000044#include <X11/extensions/extutil.h>
45#include <X11/extensions/Xext.h>
Adam Jacksoncb3610e2004-10-25 21:09:16 +000046#include <assert.h>
47#include <string.h>
48#include "glapi.h"
49#ifdef GLX_DIRECT_RENDERING
50#include "indirect_init.h"
Brian Paul82dfd4b2005-08-11 14:18:53 +000051#include <X11/extensions/xf86vmode.h>
Ian Romanick5f1ba3e2005-07-26 02:44:01 +000052#include "xf86dri.h"
Adam Jacksoncb3610e2004-10-25 21:09:16 +000053#endif
54#include "glxextensions.h"
55#include "glcontextmodes.h"
Adam Jackson489ccef2004-12-15 17:18:06 +000056#include "glheader.h"
Adam Jacksoncb3610e2004-10-25 21:09:16 +000057#include <sys/time.h>
58
Adam Jacksoncb3610e2004-10-25 21:09:16 +000059static const char __glXGLXClientVendorName[] = "SGI";
60static const char __glXGLXClientVersion[] = "1.4";
61
62
Adam Jacksoncb3610e2004-10-25 21:09:16 +000063/****************************************************************************/
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -050064
65#ifdef GLX_DIRECT_RENDERING
66
67static Bool windowExistsFlag;
68static int windowExistsErrorHandler(Display *dpy, XErrorEvent *xerr)
69{
70 if (xerr->error_code == BadWindow) {
71 windowExistsFlag = GL_FALSE;
72 }
73 return 0;
74}
75
76/**
77 * Find drawables in the local hash that have been destroyed on the
78 * server.
79 *
80 * \param dpy Display to destroy drawables for
81 * \param screen Screen number to destroy drawables for
82 */
Kristian Høgsberg9590ba92007-05-11 13:24:34 -040083static void GarbageCollectDRIDrawables(Display *dpy, __GLXscreenConfigs *sc)
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -050084{
Kristian Høgsbergfa720132007-05-11 13:54:44 -040085 XID draw;
Kristian Høgsberg4ff95e72007-05-10 17:14:38 -040086 __GLXdrawable *pdraw;
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -050087 XWindowAttributes xwa;
88 int (*oldXErrorHandler)(Display *, XErrorEvent *);
89
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -050090 /* Set no-op error handler so Xlib doesn't bail out if the windows
91 * has alreay been destroyed on the server. */
92 XSync(dpy, GL_FALSE);
93 oldXErrorHandler = XSetErrorHandler(windowExistsErrorHandler);
94
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -050095 if (__glxHashFirst(sc->drawHash, &draw, (void *)&pdraw) == 1) {
96 do {
97 windowExistsFlag = GL_TRUE;
98 XGetWindowAttributes(dpy, draw, &xwa); /* dummy request */
99 if (!windowExistsFlag) {
100 /* Destroy the local drawable data, if the drawable no
101 longer exists in the Xserver */
Kristian Høgsberg5987a032007-05-11 16:43:20 -0400102 (*pdraw->driDrawable.destroyDrawable)(&pdraw->driDrawable);
Kristian Høgsberg4ff95e72007-05-10 17:14:38 -0400103 XF86DRIDestroyDrawable(dpy, sc->scr, draw);
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -0500104 Xfree(pdraw);
105 }
106 } while (__glxHashNext(sc->drawHash, &draw, (void *)&pdraw) == 1);
107 }
108
109 XSetErrorHandler(oldXErrorHandler);
110}
111
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000112/**
113 * Get the __DRIdrawable for the drawable associated with a GLXContext
114 *
115 * \param dpy The display associated with \c drawable.
116 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -0500117 * \param scrn_num If non-NULL, the drawables screen is stored there
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000118 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
119 * the drawable is not associated with a direct-rendering context.
120 */
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000121static __DRIdrawable *
122GetDRIDrawable( Display *dpy, GLXDrawable drawable, int * const scrn_num )
123{
124 __GLXdisplayPrivate * const priv = __glXInitialize(dpy);
Kristian Høgsbergaceccda2007-05-10 15:52:22 -0400125 __GLXdrawable * const pdraw;
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -0500126 const unsigned screen_count = ScreenCount(dpy);
127 unsigned i;
128 __GLXscreenConfigs *sc;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000129
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -0500130 if (priv == NULL || priv->driDisplay.private == NULL)
131 return NULL;
132
133 for (i = 0; i < screen_count; i++) {
134 sc = &priv->screenConfigs[i];
135 if (__glxHashLookup(sc->drawHash, drawable, (void *) &pdraw) == 0) {
136 if (scrn_num != NULL)
137 *scrn_num = i;
Kristian Høgsbergaceccda2007-05-10 15:52:22 -0400138 return &pdraw->driDrawable;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000139 }
140 }
141
142 return NULL;
143}
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -0500144
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000145#endif
146
147
148/**
149 * Get the GLX per-screen data structure associated with a GLX context.
150 *
151 * \param dpy Display for which the GLX per-screen information is to be
152 * retrieved.
153 * \param scrn Screen on \c dpy for which the GLX per-screen information is
154 * to be retrieved.
155 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
156 * specify a valid GLX screen, or NULL otherwise.
157 *
158 * \todo Should this function validate that \c scrn is within the screen
159 * number range for \c dpy?
160 */
161
162static __GLXscreenConfigs *
163GetGLXScreenConfigs(Display *dpy, int scrn)
164{
165 __GLXdisplayPrivate * const priv = __glXInitialize(dpy);
166
167 return (priv->screenConfigs != NULL) ? &priv->screenConfigs[scrn] : NULL;
168}
169
170
171static int
172GetGLXPrivScreenConfig( Display *dpy, int scrn, __GLXdisplayPrivate ** ppriv,
173 __GLXscreenConfigs ** ppsc )
174{
175 /* Initialize the extension, if needed . This has the added value
176 * of initializing/allocating the display private
177 */
178
179 if ( dpy == NULL ) {
180 return GLX_NO_EXTENSION;
181 }
182
183 *ppriv = __glXInitialize(dpy);
184 if ( *ppriv == NULL ) {
185 return GLX_NO_EXTENSION;
186 }
187
188 /* Check screen number to see if its valid */
189 if ((scrn < 0) || (scrn >= ScreenCount(dpy))) {
190 return GLX_BAD_SCREEN;
191 }
192
193 /* Check to see if the GL is supported on this screen */
194 *ppsc = &((*ppriv)->screenConfigs[scrn]);
195 if ( (*ppsc)->configs == NULL ) {
196 /* No support for GL on this screen regardless of visual */
197 return GLX_BAD_VISUAL;
198 }
199
200 return Success;
201}
202
203
204/**
205 * Determine if a \c GLXFBConfig supplied by the application is valid.
206 *
207 * \param dpy Application supplied \c Display pointer.
208 * \param config Application supplied \c GLXFBConfig.
209 *
210 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
211 * \c __GLcontextModes structure is returned. Otherwise, \c NULL
212 * is returned.
213 */
214static __GLcontextModes *
215ValidateGLXFBConfig( Display * dpy, GLXFBConfig config )
216{
217 __GLXdisplayPrivate * const priv = __glXInitialize(dpy);
218 const unsigned num_screens = ScreenCount(dpy);
219 unsigned i;
220 const __GLcontextModes * modes;
221
222
223 if ( priv != NULL ) {
224 for ( i = 0 ; i < num_screens ; i++ ) {
225 for ( modes = priv->screenConfigs[i].configs
226 ; modes != NULL
227 ; modes = modes->next ) {
228 if ( modes == (__GLcontextModes *) config ) {
229 return (__GLcontextModes *) config;
230 }
231 }
232 }
233 }
234
235 return NULL;
236}
237
238
239/**
240 * \todo It should be possible to move the allocate of \c client_state_private
241 * later in the function for direct-rendering contexts. Direct-rendering
242 * contexts don't need to track client state, so they don't need that memory
243 * at all.
244 *
245 * \todo Eliminate \c __glXInitVertexArrayState. Replace it with a new
246 * function called \c __glXAllocateClientState that allocates the memory and
247 * does all the initialization (including the pixel pack / unpack).
248 */
249static
250GLXContext AllocateGLXContext( Display *dpy )
251{
252 GLXContext gc;
253 int bufSize;
254 CARD8 opcode;
255 __GLXattribute *state;
256
257 if (!dpy)
258 return NULL;
259
260 opcode = __glXSetupForCommand(dpy);
261 if (!opcode) {
262 return NULL;
263 }
264
265 /* Allocate our context record */
266 gc = (GLXContext) Xmalloc(sizeof(struct __GLXcontextRec));
267 if (!gc) {
268 /* Out of memory */
269 return NULL;
270 }
271 memset(gc, 0, sizeof(struct __GLXcontextRec));
272
273 state = Xmalloc(sizeof(struct __GLXattributeRec));
274 if (state == NULL) {
275 /* Out of memory */
276 Xfree(gc);
277 return NULL;
278 }
279 gc->client_state_private = state;
280 memset(gc->client_state_private, 0, sizeof(struct __GLXattributeRec));
281 state->NoDrawArraysProtocol = (getenv("LIBGL_NO_DRAWARRAYS") != NULL);
282
283 /*
284 ** Create a temporary buffer to hold GLX rendering commands. The size
285 ** of the buffer is selected so that the maximum number of GLX rendering
286 ** commands can fit in a single X packet and still have room in the X
287 ** packet for the GLXRenderReq header.
288 */
289
290 bufSize = (XMaxRequestSize(dpy) * 4) - sz_xGLXRenderReq;
291 gc->buf = (GLubyte *) Xmalloc(bufSize);
292 if (!gc->buf) {
293 Xfree(gc->client_state_private);
294 Xfree(gc);
295 return NULL;
296 }
297 gc->bufSize = bufSize;
298
299 /* Fill in the new context */
300 gc->renderMode = GL_RENDER;
301
302 state->storePack.alignment = 4;
303 state->storeUnpack.alignment = 4;
304
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000305 gc->attributes.stackPointer = &gc->attributes.stack[0];
306
307 /*
308 ** PERFORMANCE NOTE: A mode dependent fill image can speed things up.
309 ** Other code uses the fastImageUnpack bit, but it is never set
310 ** to GL_TRUE.
311 */
312 gc->fastImageUnpack = GL_FALSE;
313 gc->fillImage = __glFillImage;
314 gc->isDirect = GL_FALSE;
315 gc->pc = gc->buf;
316 gc->bufEnd = gc->buf + bufSize;
317 if (__glXDebug) {
318 /*
319 ** Set limit register so that there will be one command per packet
320 */
321 gc->limit = gc->buf;
322 } else {
323 gc->limit = gc->buf + bufSize - __GLX_BUFFER_LIMIT_SIZE;
324 }
325 gc->createDpy = dpy;
326 gc->majorOpcode = opcode;
327
328 /*
329 ** Constrain the maximum drawing command size allowed to be
330 ** transfered using the X_GLXRender protocol request. First
331 ** constrain by a software limit, then constrain by the protocl
332 ** limit.
333 */
334 if (bufSize > __GLX_RENDER_CMD_SIZE_LIMIT) {
335 bufSize = __GLX_RENDER_CMD_SIZE_LIMIT;
336 }
337 if (bufSize > __GLX_MAX_RENDER_CMD_SIZE) {
338 bufSize = __GLX_MAX_RENDER_CMD_SIZE;
339 }
340 gc->maxSmallRenderCommandSize = bufSize;
341 return gc;
342}
343
344
345/**
346 * Create a new context. Exactly one of \c vis and \c fbconfig should be
347 * non-NULL.
348 *
349 * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or
350 * SGIX_fbconfig protocol be used?
351 * \param renderType For FBConfigs, what is the rendering type?
352 */
353
354static GLXContext
355CreateContext(Display *dpy, XVisualInfo *vis,
356 const __GLcontextModes * const fbconfig,
357 GLXContext shareList,
358 Bool allowDirect, GLXContextID contextID,
359 Bool use_glx_1_3, int renderType)
360{
361 GLXContext gc;
362
363 if ( dpy == NULL )
364 return NULL;
365
366 gc = AllocateGLXContext(dpy);
367 if (!gc)
368 return NULL;
369
370 if (None == contextID) {
371 if ( (vis == NULL) && (fbconfig == NULL) )
372 return NULL;
373
374#ifdef GLX_DIRECT_RENDERING
375 if (allowDirect) {
376 int screen = (fbconfig == NULL) ? vis->screen : fbconfig->screen;
377 __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen);
378 const __GLcontextModes * mode;
Kristian Høgsberg8ed5c7c2007-05-10 18:38:49 -0400379 drm_context_t hwContext;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000380
381 /* The value of fbconfig cannot change because it is tested
382 * later in the function.
383 */
384 if ( fbconfig == NULL ) {
385 /* FIXME: Is it possible for the __GLcontextModes structure
386 * FIXME: to not be found?
387 */
388 mode = _gl_context_modes_find_visual( psc->configs,
389 vis->visualid );
390 assert( mode != NULL );
391 assert( mode->screen == screen );
392 }
393 else {
394 mode = fbconfig;
395 }
396
397 if (psc && psc->driScreen.private) {
398 void * const shared = (shareList != NULL)
399 ? shareList->driContext.private : NULL;
Kristian Høgsberg8ed5c7c2007-05-10 18:38:49 -0400400
401
402 if (!XF86DRICreateContextWithConfig(dpy, psc->scr,
403 mode->fbconfigID,
404 &gc->hwContextID, &hwContext))
405 /* gah, handle this better */
406 return NULL;
407
Ian Romanickc39bf5e2005-07-24 06:29:14 +0000408 gc->driContext.private =
Kristian Høgsbergaceccda2007-05-10 15:52:22 -0400409 (*psc->driScreen.createNewContext)( &psc->driScreen,
410 mode, renderType,
Ian Romanickc39bf5e2005-07-24 06:29:14 +0000411 shared,
Kristian Høgsberg8ed5c7c2007-05-10 18:38:49 -0400412 hwContext,
Ian Romanickc39bf5e2005-07-24 06:29:14 +0000413 &gc->driContext );
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000414 if (gc->driContext.private) {
415 gc->isDirect = GL_TRUE;
416 gc->screen = mode->screen;
Kristian Høgsbergaceccda2007-05-10 15:52:22 -0400417 gc->psc = psc;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000418 gc->vid = mode->visualID;
419 gc->fbconfigID = mode->fbconfigID;
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -0500420 gc->mode = mode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000421 }
Kristian Høgsberg8ed5c7c2007-05-10 18:38:49 -0400422 else {
423 XF86DRIDestroyContext(dpy, psc->scr, gc->hwContextID);
424 }
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000425 }
426 }
427#endif
428
429 LockDisplay(dpy);
430 if ( fbconfig == NULL ) {
431 xGLXCreateContextReq *req;
432
433 /* Send the glXCreateContext request */
434 GetReq(GLXCreateContext,req);
435 req->reqType = gc->majorOpcode;
436 req->glxCode = X_GLXCreateContext;
437 req->context = gc->xid = XAllocID(dpy);
438 req->visual = vis->visualid;
439 req->screen = vis->screen;
440 req->shareList = shareList ? shareList->xid : None;
441 req->isDirect = gc->isDirect;
442 }
443 else if ( use_glx_1_3 ) {
444 xGLXCreateNewContextReq *req;
445
446 /* Send the glXCreateNewContext request */
447 GetReq(GLXCreateNewContext,req);
448 req->reqType = gc->majorOpcode;
449 req->glxCode = X_GLXCreateNewContext;
450 req->context = gc->xid = XAllocID(dpy);
451 req->fbconfig = fbconfig->fbconfigID;
452 req->screen = fbconfig->screen;
453 req->renderType = renderType;
454 req->shareList = shareList ? shareList->xid : None;
455 req->isDirect = gc->isDirect;
456 }
457 else {
458 xGLXVendorPrivateWithReplyReq *vpreq;
459 xGLXCreateContextWithConfigSGIXReq *req;
460
461 /* Send the glXCreateNewContext request */
462 GetReqExtra(GLXVendorPrivateWithReply,
463 sz_xGLXCreateContextWithConfigSGIXReq-sz_xGLXVendorPrivateWithReplyReq,vpreq);
464 req = (xGLXCreateContextWithConfigSGIXReq *)vpreq;
465 req->reqType = gc->majorOpcode;
466 req->glxCode = X_GLXVendorPrivateWithReply;
467 req->vendorCode = X_GLXvop_CreateContextWithConfigSGIX;
468 req->context = gc->xid = XAllocID(dpy);
469 req->fbconfig = fbconfig->fbconfigID;
470 req->screen = fbconfig->screen;
471 req->renderType = renderType;
472 req->shareList = shareList ? shareList->xid : None;
473 req->isDirect = gc->isDirect;
474 }
475
476 UnlockDisplay(dpy);
477 SyncHandle();
478 gc->imported = GL_FALSE;
479 }
480 else {
481 gc->xid = contextID;
482 gc->imported = GL_TRUE;
483 }
484
485 return gc;
486}
487
Ian Romanickab7c6ff2005-07-26 22:53:38 +0000488PUBLIC GLXContext glXCreateContext(Display *dpy, XVisualInfo *vis,
489 GLXContext shareList, Bool allowDirect)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000490{
491 return CreateContext(dpy, vis, NULL, shareList, allowDirect, None,
492 False, 0);
493}
494
495void __glXFreeContext(__GLXcontext *gc)
496{
497 if (gc->vendor) XFree((char *) gc->vendor);
498 if (gc->renderer) XFree((char *) gc->renderer);
499 if (gc->version) XFree((char *) gc->version);
500 if (gc->extensions) XFree((char *) gc->extensions);
501 __glFreeAttributeState(gc);
502 XFree((char *) gc->buf);
503 Xfree((char *) gc->client_state_private);
504 XFree((char *) gc);
505
506}
507
508/*
509** Destroy the named context
510*/
511static void
512DestroyContext(Display *dpy, GLXContext gc)
513{
514 xGLXDestroyContextReq *req;
515 GLXContextID xid;
516 CARD8 opcode;
517 GLboolean imported;
518
519 opcode = __glXSetupForCommand(dpy);
520 if (!opcode || !gc) {
521 return;
522 }
523
524 __glXLock();
525 xid = gc->xid;
526 imported = gc->imported;
527 gc->xid = None;
528
529#ifdef GLX_DIRECT_RENDERING
530 /* Destroy the direct rendering context */
531 if (gc->isDirect) {
532 if (gc->driContext.private) {
Kristian Høgsberg5987a032007-05-11 16:43:20 -0400533 (*gc->driContext.destroyContext)(&gc->driContext);
Kristian Høgsberg8ed5c7c2007-05-10 18:38:49 -0400534 XF86DRIDestroyContext(dpy, gc->psc->scr, gc->hwContextID);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000535 gc->driContext.private = NULL;
536 }
Kristian Høgsberg9590ba92007-05-11 13:24:34 -0400537 GarbageCollectDRIDrawables(dpy, gc->psc);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000538 }
539#endif
540
541 if (gc->currentDpy) {
542 /* Have to free later cuz it's in use now */
543 __glXUnlock();
544 } else {
545 /* Destroy the handle if not current to anybody */
546 __glXUnlock();
547 __glXFreeContext(gc);
548 }
549
550 if (!imported) {
551 /*
552 ** This dpy also created the server side part of the context.
553 ** Send the glXDestroyContext request.
554 */
555 LockDisplay(dpy);
556 GetReq(GLXDestroyContext,req);
557 req->reqType = opcode;
558 req->glxCode = X_GLXDestroyContext;
559 req->context = xid;
560 UnlockDisplay(dpy);
561 SyncHandle();
562 }
563}
Adam Jackson489ccef2004-12-15 17:18:06 +0000564
Ian Romanickab7c6ff2005-07-26 22:53:38 +0000565PUBLIC void glXDestroyContext(Display *dpy, GLXContext gc)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000566{
567 DestroyContext(dpy, gc);
568}
569
570/*
571** Return the major and minor version #s for the GLX extension
572*/
Ian Romanickab7c6ff2005-07-26 22:53:38 +0000573PUBLIC Bool glXQueryVersion(Display *dpy, int *major, int *minor)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000574{
575 __GLXdisplayPrivate *priv;
576
577 /* Init the extension. This fetches the major and minor version. */
578 priv = __glXInitialize(dpy);
579 if (!priv) return GL_FALSE;
580
581 if (major) *major = priv->majorVersion;
582 if (minor) *minor = priv->minorVersion;
583 return GL_TRUE;
584}
585
586/*
587** Query the existance of the GLX extension
588*/
Ian Romanickab7c6ff2005-07-26 22:53:38 +0000589PUBLIC Bool glXQueryExtension(Display *dpy, int *errorBase, int *eventBase)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000590{
591 int major_op, erb, evb;
592 Bool rv;
593
594 rv = XQueryExtension(dpy, GLX_EXTENSION_NAME, &major_op, &evb, &erb);
595 if (rv) {
596 if (errorBase) *errorBase = erb;
597 if (eventBase) *eventBase = evb;
598 }
599 return rv;
600}
601
602/*
603** Put a barrier in the token stream that forces the GL to finish its
604** work before X can proceed.
605*/
Ian Romanickab7c6ff2005-07-26 22:53:38 +0000606PUBLIC void glXWaitGL(void)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000607{
608 xGLXWaitGLReq *req;
609 GLXContext gc = __glXGetCurrentContext();
610 Display *dpy = gc->currentDpy;
611
612 if (!dpy) return;
613
614 /* Flush any pending commands out */
615 __glXFlushRenderBuffer(gc, gc->pc);
616
617#ifdef GLX_DIRECT_RENDERING
618 if (gc->isDirect) {
619/* This bit of ugliness unwraps the glFinish function */
620#ifdef glFinish
621#undef glFinish
622#endif
623 glFinish();
624 return;
625 }
626#endif
627
628 /* Send the glXWaitGL request */
629 LockDisplay(dpy);
630 GetReq(GLXWaitGL,req);
631 req->reqType = gc->majorOpcode;
632 req->glxCode = X_GLXWaitGL;
633 req->contextTag = gc->currentContextTag;
634 UnlockDisplay(dpy);
635 SyncHandle();
636}
637
638/*
639** Put a barrier in the token stream that forces X to finish its
640** work before GL can proceed.
641*/
Ian Romanickab7c6ff2005-07-26 22:53:38 +0000642PUBLIC void glXWaitX(void)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000643{
644 xGLXWaitXReq *req;
645 GLXContext gc = __glXGetCurrentContext();
646 Display *dpy = gc->currentDpy;
647
648 if (!dpy) return;
649
650 /* Flush any pending commands out */
651 __glXFlushRenderBuffer(gc, gc->pc);
652
653#ifdef GLX_DIRECT_RENDERING
654 if (gc->isDirect) {
655 XSync(dpy, False);
656 return;
657 }
658#endif
659
660 /*
661 ** Send the glXWaitX request.
662 */
663 LockDisplay(dpy);
664 GetReq(GLXWaitX,req);
665 req->reqType = gc->majorOpcode;
666 req->glxCode = X_GLXWaitX;
667 req->contextTag = gc->currentContextTag;
668 UnlockDisplay(dpy);
669 SyncHandle();
670}
671
Ian Romanickab7c6ff2005-07-26 22:53:38 +0000672PUBLIC void glXUseXFont(Font font, int first, int count, int listBase)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000673{
674 xGLXUseXFontReq *req;
675 GLXContext gc = __glXGetCurrentContext();
676 Display *dpy = gc->currentDpy;
677
678 if (!dpy) return;
679
680 /* Flush any pending commands out */
681 (void) __glXFlushRenderBuffer(gc, gc->pc);
682
683#ifdef GLX_DIRECT_RENDERING
684 if (gc->isDirect) {
685 DRI_glXUseXFont(font, first, count, listBase);
686 return;
687 }
688#endif
689
690 /* Send the glXUseFont request */
691 LockDisplay(dpy);
692 GetReq(GLXUseXFont,req);
693 req->reqType = gc->majorOpcode;
694 req->glxCode = X_GLXUseXFont;
695 req->contextTag = gc->currentContextTag;
696 req->font = font;
697 req->first = first;
698 req->count = count;
699 req->listBase = listBase;
700 UnlockDisplay(dpy);
701 SyncHandle();
702}
703
704/************************************************************************/
705
706/*
707** Copy the source context to the destination context using the
708** attribute "mask".
709*/
Ian Romanickab7c6ff2005-07-26 22:53:38 +0000710PUBLIC void glXCopyContext(Display *dpy, GLXContext source,
711 GLXContext dest, unsigned long mask)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000712{
713 xGLXCopyContextReq *req;
714 GLXContext gc = __glXGetCurrentContext();
715 GLXContextTag tag;
716 CARD8 opcode;
717
718 opcode = __glXSetupForCommand(dpy);
719 if (!opcode) {
720 return;
721 }
722
723#ifdef GLX_DIRECT_RENDERING
724 if (gc->isDirect) {
725 /* NOT_DONE: This does not work yet */
726 }
727#endif
728
729 /*
730 ** If the source is the current context, send its tag so that the context
731 ** can be flushed before the copy.
732 */
733 if (source == gc && dpy == gc->currentDpy) {
734 tag = gc->currentContextTag;
735 } else {
736 tag = 0;
737 }
738
739 /* Send the glXCopyContext request */
740 LockDisplay(dpy);
741 GetReq(GLXCopyContext,req);
742 req->reqType = opcode;
743 req->glxCode = X_GLXCopyContext;
744 req->source = source ? source->xid : None;
745 req->dest = dest ? dest->xid : None;
746 req->mask = mask;
747 req->contextTag = tag;
748 UnlockDisplay(dpy);
749 SyncHandle();
750}
751
752
753/**
754 * Determine if a context uses direct rendering.
755 *
756 * \param dpy Display where the context was created.
757 * \param contextID ID of the context to be tested.
758 *
759 * \returns \c GL_TRUE if the context is direct rendering or not.
760 */
761static Bool __glXIsDirect(Display *dpy, GLXContextID contextID)
762{
763 xGLXIsDirectReq *req;
764 xGLXIsDirectReply reply;
765 CARD8 opcode;
766
767 opcode = __glXSetupForCommand(dpy);
768 if (!opcode) {
769 return GL_FALSE;
770 }
771
772 /* Send the glXIsDirect request */
773 LockDisplay(dpy);
774 GetReq(GLXIsDirect,req);
775 req->reqType = opcode;
776 req->glxCode = X_GLXIsDirect;
777 req->context = contextID;
778 _XReply(dpy, (xReply*) &reply, 0, False);
779 UnlockDisplay(dpy);
780 SyncHandle();
781
782 return reply.isDirect;
783}
784
Ian Romanickc39bf5e2005-07-24 06:29:14 +0000785/**
786 * \todo
787 * Shouldn't this function \b always return \c GL_FALSE when
788 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
789 * the GLX protocol here at all?
790 */
Ian Romanickab7c6ff2005-07-26 22:53:38 +0000791PUBLIC Bool glXIsDirect(Display *dpy, GLXContext gc)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000792{
793 if (!gc) {
794 return GL_FALSE;
795#ifdef GLX_DIRECT_RENDERING
796 } else if (gc->isDirect) {
797 return GL_TRUE;
798#endif
799 }
800 return __glXIsDirect(dpy, gc->xid);
801}
802
Ian Romanickab7c6ff2005-07-26 22:53:38 +0000803PUBLIC GLXPixmap glXCreateGLXPixmap(Display *dpy, XVisualInfo *vis,
804 Pixmap pixmap)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000805{
806 xGLXCreateGLXPixmapReq *req;
807 GLXPixmap xid;
808 CARD8 opcode;
809
810 opcode = __glXSetupForCommand(dpy);
811 if (!opcode) {
812 return None;
813 }
814
815 /* Send the glXCreateGLXPixmap request */
816 LockDisplay(dpy);
817 GetReq(GLXCreateGLXPixmap,req);
818 req->reqType = opcode;
819 req->glxCode = X_GLXCreateGLXPixmap;
820 req->screen = vis->screen;
821 req->visual = vis->visualid;
822 req->pixmap = pixmap;
823 req->glxpixmap = xid = XAllocID(dpy);
824 UnlockDisplay(dpy);
825 SyncHandle();
826 return xid;
827}
828
829/*
830** Destroy the named pixmap
831*/
Ian Romanickab7c6ff2005-07-26 22:53:38 +0000832PUBLIC void glXDestroyGLXPixmap(Display *dpy, GLXPixmap glxpixmap)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000833{
834 xGLXDestroyGLXPixmapReq *req;
835 CARD8 opcode;
836
837 opcode = __glXSetupForCommand(dpy);
838 if (!opcode) {
839 return;
840 }
841
842 /* Send the glXDestroyGLXPixmap request */
843 LockDisplay(dpy);
844 GetReq(GLXDestroyGLXPixmap,req);
845 req->reqType = opcode;
846 req->glxCode = X_GLXDestroyGLXPixmap;
847 req->glxpixmap = glxpixmap;
848 UnlockDisplay(dpy);
849 SyncHandle();
850}
851
Ian Romanickab7c6ff2005-07-26 22:53:38 +0000852PUBLIC void glXSwapBuffers(Display *dpy, GLXDrawable drawable)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000853{
854 xGLXSwapBuffersReq *req;
855 GLXContext gc;
856 GLXContextTag tag;
857 CARD8 opcode;
858#ifdef GLX_DIRECT_RENDERING
859 __DRIdrawable *pdraw = GetDRIDrawable( dpy, drawable, NULL );
860
861 if ( pdraw != NULL ) {
Kristian Høgsberg5987a032007-05-11 16:43:20 -0400862 (*pdraw->swapBuffers)(pdraw);
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000863 return;
864 }
865#endif
866
867 opcode = __glXSetupForCommand(dpy);
868 if (!opcode) {
869 return;
870 }
871
872 /*
873 ** The calling thread may or may not have a current context. If it
874 ** does, send the context tag so the server can do a flush.
875 */
876 gc = __glXGetCurrentContext();
877 if ((gc != NULL) && (dpy == gc->currentDpy) &&
878 ((drawable == gc->currentDrawable) || (drawable == gc->currentReadable)) ) {
879 tag = gc->currentContextTag;
880 } else {
881 tag = 0;
882 }
883
884 /* Send the glXSwapBuffers request */
885 LockDisplay(dpy);
886 GetReq(GLXSwapBuffers,req);
887 req->reqType = opcode;
888 req->glxCode = X_GLXSwapBuffers;
889 req->drawable = drawable;
890 req->contextTag = tag;
891 UnlockDisplay(dpy);
892 SyncHandle();
893 XFlush(dpy);
894}
895
896
897/*
898** Return configuration information for the given display, screen and
899** visual combination.
900*/
Ian Romanickab7c6ff2005-07-26 22:53:38 +0000901PUBLIC int glXGetConfig(Display *dpy, XVisualInfo *vis, int attribute,
902 int *value_return)
Adam Jacksoncb3610e2004-10-25 21:09:16 +0000903{
904 __GLXdisplayPrivate *priv;
905 __GLXscreenConfigs *psc;
906 int status;
907
908 status = GetGLXPrivScreenConfig( dpy, vis->screen, & priv, & psc );
909 if ( status == Success ) {
910 const __GLcontextModes * const modes = _gl_context_modes_find_visual(
911 psc->configs, vis->visualid );
912
913 /* Lookup attribute after first finding a match on the visual */
914 if ( modes != NULL ) {
915 return _gl_get_context_mode_data( modes, attribute, value_return );
916 }
917
918 status = GLX_BAD_VISUAL;
919 }
920
921 /*
922 ** If we can't find the config for this visual, this visual is not
923 ** supported by the OpenGL implementation on the server.
924 */
925 if ( (status == GLX_BAD_VISUAL) && (attribute == GLX_USE_GL) ) {
926 *value_return = GL_FALSE;
927 status = Success;
928 }
929
930 return status;
931}
932
933/************************************************************************/
934
935static void
936init_fbconfig_for_chooser( __GLcontextModes * config,
937 GLboolean fbconfig_style_tags )
938{
939 memset( config, 0, sizeof( __GLcontextModes ) );
940 config->visualID = (XID) GLX_DONT_CARE;
941 config->visualType = GLX_DONT_CARE;
942
943 /* glXChooseFBConfig specifies different defaults for these two than
944 * glXChooseVisual.
945 */
946 if ( fbconfig_style_tags ) {
947 config->rgbMode = GL_TRUE;
948 config->doubleBufferMode = GLX_DONT_CARE;
949 }
950
951 config->visualRating = GLX_DONT_CARE;
952 config->transparentPixel = GLX_NONE;
953 config->transparentRed = GLX_DONT_CARE;
954 config->transparentGreen = GLX_DONT_CARE;
955 config->transparentBlue = GLX_DONT_CARE;
956 config->transparentAlpha = GLX_DONT_CARE;
957 config->transparentIndex = GLX_DONT_CARE;
958
959 config->drawableType = GLX_WINDOW_BIT;
960 config->renderType = (config->rgbMode) ? GLX_RGBA_BIT : GLX_COLOR_INDEX_BIT;
961 config->xRenderable = GLX_DONT_CARE;
962 config->fbconfigID = (GLXFBConfigID)(GLX_DONT_CARE);
963
964 config->swapMethod = GLX_DONT_CARE;
965}
966
967#define MATCH_DONT_CARE( param ) \
968 do { \
969 if ( (a-> param != GLX_DONT_CARE) \
970 && (a-> param != b-> param) ) { \
971 return False; \
972 } \
973 } while ( 0 )
974
975#define MATCH_MINIMUM( param ) \
976 do { \
977 if ( (a-> param != GLX_DONT_CARE) \
978 && (a-> param > b-> param) ) { \
979 return False; \
980 } \
981 } while ( 0 )
982
983#define MATCH_EXACT( param ) \
984 do { \
985 if ( a-> param != b-> param) { \
986 return False; \
987 } \
988 } while ( 0 )
989
990/**
991 * Determine if two GLXFBConfigs are compatible.
992 *
993 * \param a Application specified config to test.
994 * \param b Server specified config to test against \c a.
995 */
996static Bool
997fbconfigs_compatible( const __GLcontextModes * const a,
998 const __GLcontextModes * const b )
999{
1000 MATCH_DONT_CARE( doubleBufferMode );
1001 MATCH_DONT_CARE( visualType );
1002 MATCH_DONT_CARE( visualRating );
1003 MATCH_DONT_CARE( xRenderable );
1004 MATCH_DONT_CARE( fbconfigID );
1005 MATCH_DONT_CARE( swapMethod );
1006
1007 MATCH_MINIMUM( rgbBits );
1008 MATCH_MINIMUM( numAuxBuffers );
1009 MATCH_MINIMUM( redBits );
1010 MATCH_MINIMUM( greenBits );
1011 MATCH_MINIMUM( blueBits );
1012 MATCH_MINIMUM( alphaBits );
1013 MATCH_MINIMUM( depthBits );
1014 MATCH_MINIMUM( stencilBits );
1015 MATCH_MINIMUM( accumRedBits );
1016 MATCH_MINIMUM( accumGreenBits );
1017 MATCH_MINIMUM( accumBlueBits );
1018 MATCH_MINIMUM( accumAlphaBits );
1019 MATCH_MINIMUM( sampleBuffers );
1020 MATCH_MINIMUM( maxPbufferWidth );
1021 MATCH_MINIMUM( maxPbufferHeight );
1022 MATCH_MINIMUM( maxPbufferPixels );
1023 MATCH_MINIMUM( samples );
1024
1025 MATCH_DONT_CARE( stereoMode );
1026 MATCH_EXACT( level );
1027
1028 if ( ((a->drawableType & b->drawableType) == 0)
1029 || ((a->renderType & b->renderType) == 0) ) {
1030 return False;
1031 }
1032
1033
1034 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1035 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1036 * Technically speaking, it is a bug in the DDX driver, but there is
1037 * enough of an installed base to work around the problem here. In any
1038 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1039 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1040 * 0 from the server to be a match to maintain backward compatibility with
1041 * the (broken) drivers.
1042 */
1043
1044 if ( a->transparentPixel != GLX_DONT_CARE
1045 && a->transparentPixel != 0 ) {
1046 if ( a->transparentPixel == GLX_NONE ) {
1047 if ( b->transparentPixel != GLX_NONE && b->transparentPixel != 0 )
1048 return False;
1049 } else {
1050 MATCH_EXACT( transparentPixel );
1051 }
1052
1053 switch ( a->transparentPixel ) {
1054 case GLX_TRANSPARENT_RGB:
1055 MATCH_DONT_CARE( transparentRed );
1056 MATCH_DONT_CARE( transparentGreen );
1057 MATCH_DONT_CARE( transparentBlue );
1058 MATCH_DONT_CARE( transparentAlpha );
1059 break;
1060
1061 case GLX_TRANSPARENT_INDEX:
1062 MATCH_DONT_CARE( transparentIndex );
1063 break;
1064
1065 default:
1066 break;
1067 }
1068 }
1069
1070 return True;
1071}
1072
1073
1074/* There's some trickly language in the GLX spec about how this is supposed
1075 * to work. Basically, if a given component size is either not specified
1076 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1077 * Well, that's really hard to do with the code as-is. This behavior is
1078 * closer to correct, but still not technically right.
1079 */
1080#define PREFER_LARGER_OR_ZERO(comp) \
1081 do { \
1082 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1083 if ( ((*a)-> comp) == 0 ) { \
1084 return -1; \
1085 } \
1086 else if ( ((*b)-> comp) == 0 ) { \
1087 return 1; \
1088 } \
1089 else { \
1090 return ((*b)-> comp) - ((*a)-> comp) ; \
1091 } \
1092 } \
1093 } while( 0 )
1094
1095#define PREFER_LARGER(comp) \
1096 do { \
1097 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1098 return ((*b)-> comp) - ((*a)-> comp) ; \
1099 } \
1100 } while( 0 )
1101
1102#define PREFER_SMALLER(comp) \
1103 do { \
1104 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1105 return ((*a)-> comp) - ((*b)-> comp) ; \
1106 } \
1107 } while( 0 )
1108
1109/**
1110 * Compare two GLXFBConfigs. This function is intended to be used as the
1111 * compare function passed in to qsort.
1112 *
1113 * \returns If \c a is a "better" config, according to the specification of
1114 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1115 * better, then a number greater than zero is return. If both are
1116 * equal, zero is returned.
1117 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1118 */
1119static int
1120fbconfig_compare( const __GLcontextModes * const * const a,
1121 const __GLcontextModes * const * const b )
1122{
1123 /* The order of these comparisons must NOT change. It is defined by
1124 * the GLX 1.3 spec and ARB_multisample.
1125 */
1126
1127 PREFER_SMALLER( visualSelectGroup );
1128
1129 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1130 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1131 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1132 */
1133 PREFER_SMALLER( visualRating );
1134
1135 /* This isn't quite right. It is supposed to compare the sum of the
1136 * components the user specifically set minimums for.
1137 */
1138 PREFER_LARGER_OR_ZERO( redBits );
1139 PREFER_LARGER_OR_ZERO( greenBits );
1140 PREFER_LARGER_OR_ZERO( blueBits );
1141 PREFER_LARGER_OR_ZERO( alphaBits );
1142
1143 PREFER_SMALLER( rgbBits );
1144
1145 if ( ((*a)->doubleBufferMode != (*b)->doubleBufferMode) ) {
1146 /* Prefer single-buffer.
1147 */
1148 return ( !(*a)->doubleBufferMode ) ? -1 : 1;
1149 }
1150
1151 PREFER_SMALLER( numAuxBuffers );
1152
1153 PREFER_LARGER_OR_ZERO( depthBits );
1154 PREFER_SMALLER( stencilBits );
1155
1156 /* This isn't quite right. It is supposed to compare the sum of the
1157 * components the user specifically set minimums for.
1158 */
1159 PREFER_LARGER_OR_ZERO( accumRedBits );
1160 PREFER_LARGER_OR_ZERO( accumGreenBits );
1161 PREFER_LARGER_OR_ZERO( accumBlueBits );
1162 PREFER_LARGER_OR_ZERO( accumAlphaBits );
1163
1164 PREFER_SMALLER( visualType );
1165
1166 /* None of the multisample specs say where this comparison should happen,
1167 * so I put it near the end.
1168 */
1169 PREFER_SMALLER( sampleBuffers );
1170 PREFER_SMALLER( samples );
1171
1172 /* None of the pbuffer or fbconfig specs say that this comparison needs
1173 * to happen at all, but it seems like it should.
1174 */
1175 PREFER_LARGER( maxPbufferWidth );
1176 PREFER_LARGER( maxPbufferHeight );
1177 PREFER_LARGER( maxPbufferPixels );
1178
1179 return 0;
1180}
1181
1182
1183/**
1184 * Selects and sorts a subset of the supplied configs based on the attributes.
1185 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1186 * and \c glXChooseFBConfigSGIX.
1187 *
1188 * \param configs Array of pointers to possible configs. The elements of
1189 * this array that do not meet the criteria will be set to
1190 * NULL. The remaining elements will be sorted according to
1191 * the various visual / FBConfig selection rules.
1192 * \param num_configs Number of elements in the \c configs array.
1193 * \param attribList Attributes used select from \c configs. This array is
1194 * terminated by a \c None tag. The array can either take
1195 * the form expected by \c glXChooseVisual (where boolean
1196 * tags do not have a value) or by \c glXChooseFBConfig
1197 * (where every tag has a value).
1198 * \param fbconfig_style_tags Selects whether \c attribList is in
1199 * \c glXChooseVisual style or
1200 * \c glXChooseFBConfig style.
1201 * \returns The number of valid elements left in \c configs.
1202 *
1203 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1204 */
1205static int
1206choose_visual( __GLcontextModes ** configs, int num_configs,
1207 const int *attribList, GLboolean fbconfig_style_tags )
1208{
1209 __GLcontextModes test_config;
1210 int base;
1211 int i;
1212
1213 /* This is a fairly direct implementation of the selection method
1214 * described by GLX_SGIX_fbconfig. Start by culling out all the
1215 * configs that are not compatible with the selected parameter
1216 * list.
1217 */
1218
1219 init_fbconfig_for_chooser( & test_config, fbconfig_style_tags );
1220 __glXInitializeVisualConfigFromTags( & test_config, 512,
1221 (const INT32 *) attribList,
1222 GL_TRUE, fbconfig_style_tags );
1223
1224 base = 0;
1225 for ( i = 0 ; i < num_configs ; i++ ) {
1226 if ( fbconfigs_compatible( & test_config, configs[i] ) ) {
1227 configs[ base ] = configs[ i ];
1228 base++;
1229 }
1230 }
1231
1232 if ( base == 0 ) {
1233 return 0;
1234 }
1235
1236 if ( base < num_configs ) {
1237 (void) memset( & configs[ base ], 0,
1238 sizeof( void * ) * (num_configs - base) );
1239 }
1240
1241 /* After the incompatible configs are removed, the resulting
1242 * list is sorted according to the rules set out in the various
1243 * specifications.
1244 */
1245
1246 qsort( configs, base, sizeof( __GLcontextModes * ),
1247 (int (*)(const void*, const void*)) fbconfig_compare );
1248 return base;
1249}
1250
1251
1252
1253
1254/*
1255** Return the visual that best matches the template. Return None if no
1256** visual matches the template.
1257*/
Ian Romanickab7c6ff2005-07-26 22:53:38 +00001258PUBLIC XVisualInfo *glXChooseVisual(Display *dpy, int screen, int *attribList)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001259{
1260 XVisualInfo *visualList = NULL;
1261 __GLXdisplayPrivate *priv;
1262 __GLXscreenConfigs *psc;
1263 __GLcontextModes test_config;
1264 __GLcontextModes *modes;
1265 const __GLcontextModes *best_config = NULL;
1266
1267 /*
1268 ** Get a list of all visuals, return if list is empty
1269 */
1270 if ( GetGLXPrivScreenConfig( dpy, screen, & priv, & psc ) != Success ) {
1271 return None;
1272 }
1273
1274
1275 /*
1276 ** Build a template from the defaults and the attribute list
1277 ** Free visual list and return if an unexpected token is encountered
1278 */
1279 init_fbconfig_for_chooser( & test_config, GL_FALSE );
1280 __glXInitializeVisualConfigFromTags( & test_config, 512,
1281 (const INT32 *) attribList,
1282 GL_TRUE, GL_FALSE );
1283
1284 /*
1285 ** Eliminate visuals that don't meet minimum requirements
1286 ** Compute a score for those that do
1287 ** Remember which visual, if any, got the highest score
1288 */
1289 for ( modes = psc->configs ; modes != NULL ; modes = modes->next ) {
1290 if ( fbconfigs_compatible( & test_config, modes )
1291 && ((best_config == NULL)
1292 || (fbconfig_compare( (const __GLcontextModes * const * const)&modes, &best_config ) < 0)) ) {
1293 best_config = modes;
1294 }
1295 }
1296
1297 /*
1298 ** If no visual is acceptable, return None
1299 ** Otherwise, create an XVisualInfo list with just the selected X visual
1300 ** and return this.
1301 */
1302 if (best_config != NULL) {
1303 XVisualInfo visualTemplate;
1304 int i;
1305
1306 visualTemplate.screen = screen;
1307 visualTemplate.visualid = best_config->visualID;
1308 visualList = XGetVisualInfo( dpy, VisualScreenMask|VisualIDMask,
1309 &visualTemplate, &i );
1310 }
1311
1312 return visualList;
1313}
1314
1315
Ian Romanickab7c6ff2005-07-26 22:53:38 +00001316PUBLIC const char *glXQueryExtensionsString( Display *dpy, int screen )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001317{
1318 __GLXscreenConfigs *psc;
1319 __GLXdisplayPrivate *priv;
1320
1321 if ( GetGLXPrivScreenConfig( dpy, screen, & priv, & psc ) != Success ) {
1322 return NULL;
1323 }
1324
1325 if (!psc->effectiveGLXexts) {
1326 if (!psc->serverGLXexts) {
1327 psc->serverGLXexts = __glXGetStringFromServer(dpy, priv->majorOpcode,
1328 X_GLXQueryServerString,
1329 screen, GLX_EXTENSIONS);
1330 }
1331
1332 __glXCalculateUsableExtensions(psc,
1333#ifdef GLX_DIRECT_RENDERING
Ian Romanick6bc24c52005-08-05 19:13:51 +00001334 (psc->driScreen.private != NULL),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001335#else
1336 GL_FALSE,
1337#endif
1338 priv->minorVersion);
1339 }
1340
1341 return psc->effectiveGLXexts;
1342}
1343
Ian Romanickab7c6ff2005-07-26 22:53:38 +00001344PUBLIC const char *glXGetClientString( Display *dpy, int name )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001345{
1346 switch(name) {
1347 case GLX_VENDOR:
1348 return (__glXGLXClientVendorName);
1349 case GLX_VERSION:
1350 return (__glXGLXClientVersion);
1351 case GLX_EXTENSIONS:
1352 return (__glXGetClientExtensions());
1353 default:
1354 return NULL;
1355 }
1356}
1357
Ian Romanickab7c6ff2005-07-26 22:53:38 +00001358PUBLIC const char *glXQueryServerString( Display *dpy, int screen, int name )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001359{
1360 __GLXscreenConfigs *psc;
1361 __GLXdisplayPrivate *priv;
1362 const char ** str;
1363
1364
1365 if ( GetGLXPrivScreenConfig( dpy, screen, & priv, & psc ) != Success ) {
1366 return NULL;
1367 }
1368
1369 switch(name) {
1370 case GLX_VENDOR:
1371 str = & priv->serverGLXvendor;
1372 break;
1373 case GLX_VERSION:
1374 str = & priv->serverGLXversion;
1375 break;
1376 case GLX_EXTENSIONS:
1377 str = & psc->serverGLXexts;
1378 break;
1379 default:
1380 return NULL;
1381 }
1382
1383 if ( *str == NULL ) {
1384 *str = __glXGetStringFromServer(dpy, priv->majorOpcode,
1385 X_GLXQueryServerString, screen, name);
1386 }
1387
1388 return *str;
1389}
1390
1391void __glXClientInfo ( Display *dpy, int opcode )
1392{
1393 xGLXClientInfoReq *req;
1394 int size;
1395 char * ext_str = __glXGetClientGLExtensionString();
1396
1397 /* Send the glXClientInfo request */
1398 LockDisplay(dpy);
1399 GetReq(GLXClientInfo,req);
1400 req->reqType = opcode;
1401 req->glxCode = X_GLXClientInfo;
1402 req->major = GLX_MAJOR_VERSION;
1403 req->minor = GLX_MINOR_VERSION;
1404
1405 size = strlen( ext_str ) + 1;
1406 req->length += (size + 3) >> 2;
1407 req->numbytes = size;
1408 Data(dpy, ext_str, size);
1409
1410 UnlockDisplay(dpy);
1411 SyncHandle();
1412
1413 Xfree( ext_str );
1414}
1415
1416
1417/*
1418** EXT_import_context
1419*/
1420
Adam Jackson489ccef2004-12-15 17:18:06 +00001421PUBLIC Display *glXGetCurrentDisplay(void)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001422{
1423 GLXContext gc = __glXGetCurrentContext();
1424 if (NULL == gc) return NULL;
1425 return gc->currentDpy;
1426}
1427
Adam Jackson489ccef2004-12-15 17:18:06 +00001428PUBLIC GLX_ALIAS(Display *, glXGetCurrentDisplayEXT, (void), (),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001429 glXGetCurrentDisplay)
1430
1431/**
1432 * Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests
1433 * to the X-server.
1434 *
1435 * \param dpy Display where \c ctx was created.
1436 * \param ctx Context to query.
1437 * \returns \c Success on success. \c GLX_BAD_CONTEXT if \c ctx is invalid,
1438 * or zero if the request failed due to internal problems (i.e.,
1439 * unable to allocate temporary memory, etc.)
1440 *
1441 * \note
1442 * This function dynamically determines whether to use the EXT_import_context
1443 * version of the protocol or the GLX 1.3 version of the protocol.
1444 */
1445static int __glXQueryContextInfo(Display *dpy, GLXContext ctx)
1446{
1447 __GLXdisplayPrivate *priv = __glXInitialize(dpy);
1448 xGLXQueryContextReply reply;
1449 CARD8 opcode;
1450 GLuint numValues;
1451 int retval;
1452
1453 if (ctx == NULL) {
1454 return GLX_BAD_CONTEXT;
1455 }
1456 opcode = __glXSetupForCommand(dpy);
1457 if (!opcode) {
1458 return 0;
1459 }
1460
1461 /* Send the glXQueryContextInfoEXT request */
1462 LockDisplay(dpy);
1463
1464 if ( (priv->majorVersion > 1) || (priv->minorVersion >= 3) ) {
1465 xGLXQueryContextReq *req;
1466
1467 GetReq(GLXQueryContext, req);
1468
1469 req->reqType = opcode;
1470 req->glxCode = X_GLXQueryContext;
1471 req->context = (unsigned int)(ctx->xid);
1472 }
1473 else {
1474 xGLXVendorPrivateReq *vpreq;
1475 xGLXQueryContextInfoEXTReq *req;
1476
1477 GetReqExtra( GLXVendorPrivate,
1478 sz_xGLXQueryContextInfoEXTReq - sz_xGLXVendorPrivateReq,
1479 vpreq );
1480 req = (xGLXQueryContextInfoEXTReq *)vpreq;
1481 req->reqType = opcode;
1482 req->glxCode = X_GLXVendorPrivateWithReply;
1483 req->vendorCode = X_GLXvop_QueryContextInfoEXT;
1484 req->context = (unsigned int)(ctx->xid);
1485 }
1486
1487 _XReply(dpy, (xReply*) &reply, 0, False);
1488
1489 numValues = reply.n;
1490 if (numValues == 0)
1491 retval = Success;
1492 else if (numValues > __GLX_MAX_CONTEXT_PROPS)
1493 retval = 0;
1494 else
1495 {
1496 int *propList, *pProp;
1497 int nPropListBytes;
1498 int i;
1499
1500 nPropListBytes = numValues << 3;
1501 propList = (int *) Xmalloc(nPropListBytes);
1502 if (NULL == propList) {
1503 retval = 0;
1504 } else {
1505 _XRead(dpy, (char *)propList, nPropListBytes);
1506 pProp = propList;
1507 for (i=0; i < numValues; i++) {
1508 switch (*pProp++) {
1509 case GLX_SHARE_CONTEXT_EXT:
1510 ctx->share_xid = *pProp++;
1511 break;
1512 case GLX_VISUAL_ID_EXT:
1513 ctx->vid = *pProp++;
1514 break;
1515 case GLX_SCREEN:
1516 ctx->screen = *pProp++;
1517 break;
1518 case GLX_FBCONFIG_ID:
1519 ctx->fbconfigID = *pProp++;
1520 break;
1521 case GLX_RENDER_TYPE:
1522 ctx->renderType = *pProp++;
1523 break;
1524 default:
1525 pProp++;
1526 continue;
1527 }
1528 }
1529 Xfree((char *)propList);
1530 retval = Success;
1531 }
1532 }
1533 UnlockDisplay(dpy);
1534 SyncHandle();
1535 return retval;
1536}
1537
Adam Jackson489ccef2004-12-15 17:18:06 +00001538PUBLIC int
Ian Romanickab7c6ff2005-07-26 22:53:38 +00001539glXQueryContext(Display *dpy, GLXContext ctx, int attribute, int *value)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001540{
1541 int retVal;
1542
1543 /* get the information from the server if we don't have it already */
1544 if (!ctx->isDirect && (ctx->vid == None)) {
1545 retVal = __glXQueryContextInfo(dpy, ctx);
1546 if (Success != retVal) return retVal;
1547 }
1548 switch (attribute) {
1549 case GLX_SHARE_CONTEXT_EXT:
1550 *value = (int)(ctx->share_xid);
1551 break;
1552 case GLX_VISUAL_ID_EXT:
1553 *value = (int)(ctx->vid);
1554 break;
1555 case GLX_SCREEN:
1556 *value = (int)(ctx->screen);
1557 break;
1558 case GLX_FBCONFIG_ID:
1559 *value = (int)(ctx->fbconfigID);
1560 break;
1561 case GLX_RENDER_TYPE:
1562 *value = (int)(ctx->renderType);
1563 break;
1564 default:
1565 return GLX_BAD_ATTRIBUTE;
1566 }
1567 return Success;
1568}
1569
Adam Jackson489ccef2004-12-15 17:18:06 +00001570PUBLIC GLX_ALIAS( int, glXQueryContextInfoEXT,
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001571 (Display *dpy, GLXContext ctx, int attribute, int *value),
1572 (dpy, ctx, attribute, value),
1573 glXQueryContext )
1574
Adam Jackson489ccef2004-12-15 17:18:06 +00001575PUBLIC GLXContextID glXGetContextIDEXT(const GLXContext ctx)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001576{
1577 return ctx->xid;
1578}
1579
Ian Romanickab7c6ff2005-07-26 22:53:38 +00001580PUBLIC GLXContext glXImportContextEXT(Display *dpy, GLXContextID contextID)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001581{
1582 GLXContext ctx;
1583
1584 if (contextID == None) {
1585 return NULL;
1586 }
1587 if (__glXIsDirect(dpy, contextID)) {
1588 return NULL;
1589 }
1590
1591 ctx = CreateContext(dpy, NULL, NULL, NULL, False, contextID, False, 0);
1592 if (NULL != ctx) {
1593 if (Success != __glXQueryContextInfo(dpy, ctx)) {
1594 return NULL;
1595 }
1596 }
1597 return ctx;
1598}
1599
Ian Romanickab7c6ff2005-07-26 22:53:38 +00001600PUBLIC void glXFreeContextEXT(Display *dpy, GLXContext ctx)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001601{
1602 DestroyContext(dpy, ctx);
1603}
1604
1605
1606
1607/*
1608 * GLX 1.3 functions - these are just stubs for now!
1609 */
1610
Ian Romanickab7c6ff2005-07-26 22:53:38 +00001611PUBLIC GLXFBConfig *glXChooseFBConfig(Display *dpy, int screen,
1612 const int *attribList, int *nitems)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001613{
1614 __GLcontextModes ** config_list;
1615 int list_size;
1616
1617
1618 config_list = (__GLcontextModes **)
Ian Romanickab7c6ff2005-07-26 22:53:38 +00001619 glXGetFBConfigs( dpy, screen, & list_size );
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001620
Ian Romanickc51ed8c2005-04-07 00:05:55 +00001621 if ( (config_list != NULL) && (list_size > 0) && (attribList != NULL) ) {
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001622 list_size = choose_visual( config_list, list_size, attribList,
1623 GL_TRUE );
1624 if ( list_size == 0 ) {
1625 XFree( config_list );
1626 config_list = NULL;
1627 }
1628 }
1629
1630 *nitems = list_size;
1631 return (GLXFBConfig *) config_list;
1632}
1633
1634
Ian Romanickab7c6ff2005-07-26 22:53:38 +00001635PUBLIC GLXContext glXCreateNewContext(Display *dpy, GLXFBConfig config,
1636 int renderType, GLXContext shareList,
1637 Bool allowDirect)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001638{
1639 return CreateContext( dpy, NULL, (__GLcontextModes *) config, shareList,
1640 allowDirect, None, True, renderType );
1641}
1642
1643
Ian Romanickab7c6ff2005-07-26 22:53:38 +00001644PUBLIC GLXDrawable glXGetCurrentReadDrawable(void)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001645{
1646 GLXContext gc = __glXGetCurrentContext();
1647 return gc->currentReadable;
1648}
1649
1650
Ian Romanickab7c6ff2005-07-26 22:53:38 +00001651PUBLIC GLXFBConfig *glXGetFBConfigs(Display *dpy, int screen, int *nelements)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001652{
1653 __GLXdisplayPrivate *priv = __glXInitialize(dpy);
1654 __GLcontextModes ** config = NULL;
1655 int i;
1656
1657 if ( (priv->screenConfigs != NULL)
1658 && (screen >= 0) && (screen <= ScreenCount(dpy))
1659 && (priv->screenConfigs[screen].configs != NULL)
1660 && (priv->screenConfigs[screen].configs->fbconfigID != GLX_DONT_CARE) ) {
1661 unsigned num_configs = 0;
1662 __GLcontextModes * modes;
1663
1664
1665 for ( modes = priv->screenConfigs[screen].configs
1666 ; modes != NULL
1667 ; modes = modes->next ) {
1668 if ( modes->fbconfigID != GLX_DONT_CARE ) {
1669 num_configs++;
1670 }
1671 }
1672
1673 config = (__GLcontextModes **) Xmalloc( sizeof(__GLcontextModes *)
1674 * num_configs );
1675 if ( config != NULL ) {
1676 *nelements = num_configs;
1677 i = 0;
1678 for ( modes = priv->screenConfigs[screen].configs
1679 ; modes != NULL
1680 ; modes = modes->next ) {
1681 config[i] = modes;
1682 i++;
1683 }
1684 }
1685 }
1686 return (GLXFBConfig *) config;
1687}
1688
1689
Ian Romanickab7c6ff2005-07-26 22:53:38 +00001690PUBLIC int glXGetFBConfigAttrib(Display *dpy, GLXFBConfig config,
1691 int attribute, int *value)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001692{
1693 __GLcontextModes * const modes = ValidateGLXFBConfig( dpy, config );
1694
1695 return (modes != NULL)
1696 ? _gl_get_context_mode_data( modes, attribute, value )
1697 : GLXBadFBConfig;
1698}
1699
1700
Ian Romanickab7c6ff2005-07-26 22:53:38 +00001701PUBLIC XVisualInfo *glXGetVisualFromFBConfig(Display *dpy, GLXFBConfig config)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001702{
1703 XVisualInfo visualTemplate;
1704 __GLcontextModes * fbconfig = (__GLcontextModes *) config;
1705 int count;
1706
1707 /*
1708 ** Get a list of all visuals, return if list is empty
1709 */
1710 visualTemplate.visualid = fbconfig->visualID;
1711 return XGetVisualInfo(dpy,VisualIDMask,&visualTemplate,&count);
1712}
1713
1714
1715/*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001716** GLX_SGI_swap_control
1717*/
Ian Romanickfc5b57b2006-08-29 15:38:19 +00001718static int __glXSwapIntervalSGI(int interval)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001719{
1720 xGLXVendorPrivateReq *req;
1721 GLXContext gc = __glXGetCurrentContext();
1722 Display * dpy;
1723 CARD32 * interval_ptr;
1724 CARD8 opcode;
1725
1726 if ( gc == NULL ) {
1727 return GLX_BAD_CONTEXT;
1728 }
1729
1730 if ( interval <= 0 ) {
1731 return GLX_BAD_VALUE;
1732 }
1733
Kristian Høgsbergefaf90b2007-05-15 16:09:44 -04001734#ifdef __DRI_SWAP_CONTROL
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001735 if ( gc->isDirect ) {
1736 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy,
1737 gc->screen );
1738 __DRIdrawable * const pdraw = GetDRIDrawable( gc->currentDpy,
1739 gc->currentDrawable,
1740 NULL );
Kristian Høgsbergefaf90b2007-05-15 16:09:44 -04001741 if (psc->swapControl != NULL && pdraw != NULL) {
1742 psc->swapControl->setSwapInterval(pdraw, interval);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001743 return 0;
1744 }
1745 else {
1746 return GLX_BAD_CONTEXT;
1747 }
1748 }
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);
1758 GetReqExtra(GLXVendorPrivate,sizeof(CARD32),req);
1759 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*/
Ian Romanickfc5b57b2006-08-29 15:38:19 +00001778static 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
1783 if ( interval < 0 ) {
1784 return GLX_BAD_VALUE;
1785 }
1786
1787 if ( (gc != NULL) && gc->isDirect ) {
1788 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy,
1789 gc->screen );
1790
Kristian Høgsbergefaf90b2007-05-15 16:09:44 -04001791 if ( (psc != NULL) && (psc->driScreen.private != NULL) ) {
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001792 __DRIdrawable * const pdraw =
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -05001793 GetDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL);
Kristian Høgsbergefaf90b2007-05-15 16:09:44 -04001794 if (psc->swapControl != NULL && pdraw != NULL) {
1795 psc->swapControl->setSwapInterval(pdraw, interval);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001796 return 0;
1797 }
1798 }
1799 }
1800#else
1801 (void) interval;
1802#endif
1803
1804 return GLX_BAD_CONTEXT;
1805}
1806
Brian Paul841a8232006-03-09 16:25:46 +00001807
Ian Romanickfc5b57b2006-08-29 15:38:19 +00001808static 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
1813 if ( (gc != NULL) && gc->isDirect ) {
1814 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy,
1815 gc->screen );
1816
Kristian Høgsbergefaf90b2007-05-15 16:09:44 -04001817 if ( (psc != NULL) && (psc->driScreen.private != NULL) ) {
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001818 __DRIdrawable * const pdraw =
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -05001819 GetDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL);
Kristian Høgsbergefaf90b2007-05-15 16:09:44 -04001820 if (psc->swapControl != NULL && pdraw != NULL) {
1821 return psc->swapControl->getSwapInterval(pdraw);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001822 }
1823 }
1824 }
1825#endif
1826
1827 return 0;
1828}
1829
1830
1831/*
1832** GLX_MESA_swap_frame_usage
1833*/
1834
Ian Romanickfc5b57b2006-08-29 15:38:19 +00001835static GLint __glXBeginFrameTrackingMESA(Display *dpy, GLXDrawable drawable)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001836{
1837 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;
1840 __DRIdrawable * const pdraw = GetDRIDrawable(dpy, drawable, & screen);
1841 __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen);
1842
Kristian Høgsberga7a0a2b2007-05-16 15:50:40 -04001843 if (pdraw != NULL && psc->frameTracking != NULL)
1844 status = psc->frameTracking->frameTracking(pdraw, GL_TRUE);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001845#else
1846 (void) dpy;
1847 (void) drawable;
1848#endif
1849 return status;
1850}
1851
1852
Ian Romanickfc5b57b2006-08-29 15:38:19 +00001853static GLint __glXEndFrameTrackingMESA(Display *dpy, GLXDrawable drawable)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001854{
1855 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;
1858 __DRIdrawable * const pdraw = GetDRIDrawable(dpy, drawable, & screen);
1859 __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen);
1860
Kristian Høgsberga7a0a2b2007-05-16 15:50:40 -04001861 if (pdraw != NULL && psc->frameTracking != NULL)
1862 status = psc->frameTracking->frameTracking(pdraw, GL_FALSE);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001863#else
1864 (void) dpy;
1865 (void) drawable;
1866#endif
1867 return status;
1868}
1869
1870
Ian Romanickfc5b57b2006-08-29 15:38:19 +00001871static GLint __glXGetFrameUsageMESA(Display *dpy, GLXDrawable drawable,
1872 GLfloat *usage)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001873{
1874 int status = GLX_BAD_CONTEXT;
Kristian Høgsberga7a0a2b2007-05-16 15:50:40 -04001875#ifdef __DRI_FRAME_TRACKING
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001876 int screen;
1877 __DRIdrawable * const pdraw = GetDRIDrawable(dpy, drawable, & screen);
1878 __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen);
1879
Kristian Høgsberga7a0a2b2007-05-16 15:50:40 -04001880 if (pdraw != NULL && psc->frameTracking != NULL) {
1881 int64_t sbc, missedFrames;
1882 float lastMissedUsage;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001883
Kristian Høgsberga7a0a2b2007-05-16 15:50:40 -04001884 status = psc->frameTracking->queryFrameTracking(pdraw, &sbc,
1885 &missedFrames,
1886 &lastMissedUsage,
1887 usage);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001888 }
1889#else
1890 (void) dpy;
1891 (void) drawable;
1892 (void) usage;
1893#endif
1894 return status;
1895}
1896
1897
Ian Romanickfc5b57b2006-08-29 15:38:19 +00001898static GLint __glXQueryFrameTrackingMESA(Display *dpy, GLXDrawable drawable,
1899 int64_t *sbc, int64_t *missedFrames,
1900 GLfloat *lastMissedUsage)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001901{
1902 int status = GLX_BAD_CONTEXT;
Kristian Høgsberga7a0a2b2007-05-16 15:50:40 -04001903#ifdef __DRI_FRAME_TRACKING
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001904 int screen;
1905 __DRIdrawable * const pdraw = GetDRIDrawable(dpy, drawable, & screen);
1906 __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen);
1907
Kristian Høgsberga7a0a2b2007-05-16 15:50:40 -04001908 if (pdraw != NULL && psc->frameTracking != NULL) {
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001909 float usage;
1910
Kristian Høgsberga7a0a2b2007-05-16 15:50:40 -04001911 status = psc->frameTracking->queryFrameTracking(pdraw, sbc, missedFrames,
1912 lastMissedUsage, &usage);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001913 }
1914#else
1915 (void) dpy;
1916 (void) drawable;
1917 (void) sbc;
1918 (void) missedFrames;
1919 (void) lastMissedUsage;
1920#endif
1921 return status;
1922}
1923
1924
1925/*
1926** GLX_SGI_video_sync
1927*/
Ian Romanickfc5b57b2006-08-29 15:38:19 +00001928static int __glXGetVideoSyncSGI(unsigned int *count)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001929{
1930 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1931 * FIXME: there should be a GLX encoding for this call. I can find no
1932 * FIXME: documentation for the GLX encoding.
1933 */
1934#ifdef GLX_DIRECT_RENDERING
1935 GLXContext gc = __glXGetCurrentContext();
1936
1937
1938 if ( (gc != NULL) && gc->isDirect ) {
1939 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy,
1940 gc->screen );
1941 if ( __glXExtensionBitIsEnabled( psc, SGI_video_sync_bit )
1942 && psc->driScreen.private && psc->driScreen.getMSC) {
1943 int ret;
1944 int64_t temp;
1945
Kristian Høgsberg5987a032007-05-11 16:43:20 -04001946 ret = psc->driScreen.getMSC(&psc->driScreen, &temp);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001947 *count = (unsigned) temp;
1948 return (ret == 0) ? 0 : GLX_BAD_CONTEXT;
1949 }
1950 }
1951#else
1952 (void) count;
1953#endif
1954 return GLX_BAD_CONTEXT;
1955}
1956
Ian Romanickfc5b57b2006-08-29 15:38:19 +00001957static int __glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001958{
1959#ifdef GLX_DIRECT_RENDERING
1960 GLXContext gc = __glXGetCurrentContext();
1961
1962 if ( divisor <= 0 || remainder < 0 )
1963 return GLX_BAD_VALUE;
1964
1965 if ( (gc != NULL) && gc->isDirect ) {
1966 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy,
1967 gc->screen );
1968 if ( __glXExtensionBitIsEnabled( psc, SGI_video_sync_bit )
1969 && psc->driScreen.private ) {
1970 __DRIdrawable * const pdraw =
Kristian Høgsberg4a22ae82007-01-07 08:12:01 -05001971 GetDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001972 if ( (pdraw != NULL) && (pdraw->waitForMSC != NULL) ) {
1973 int ret;
1974 int64_t msc;
1975 int64_t sbc;
1976
Kristian Høgsberg5987a032007-05-11 16:43:20 -04001977 ret = (*pdraw->waitForMSC)(pdraw, 0,
1978 divisor, remainder, &msc, &sbc);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001979 *count = (unsigned) msc;
1980 return (ret == 0) ? 0 : GLX_BAD_CONTEXT;
1981 }
1982 }
1983 }
1984#else
1985 (void) count;
1986#endif
1987 return GLX_BAD_CONTEXT;
1988}
1989
1990
1991/*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001992** GLX_SGIX_fbconfig
1993** Many of these functions are aliased to GLX 1.3 entry points in the
1994** GLX_functions table.
1995*/
1996
Adam Jackson489ccef2004-12-15 17:18:06 +00001997PUBLIC GLX_ALIAS(int, glXGetFBConfigAttribSGIX,
Adam Jacksoncb3610e2004-10-25 21:09:16 +00001998 (Display *dpy, GLXFBConfigSGIX config, int attribute, int *value),
1999 (dpy, config, attribute, value),
2000 glXGetFBConfigAttrib)
2001
Adam Jackson489ccef2004-12-15 17:18:06 +00002002PUBLIC GLX_ALIAS(GLXFBConfigSGIX *, glXChooseFBConfigSGIX,
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002003 (Display *dpy, int screen, int *attrib_list, int *nelements),
2004 (dpy, screen, attrib_list, nelements),
2005 glXChooseFBConfig)
2006
Adam Jackson489ccef2004-12-15 17:18:06 +00002007PUBLIC GLX_ALIAS(XVisualInfo *, glXGetVisualFromFBConfigSGIX,
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002008 (Display * dpy, GLXFBConfigSGIX config),
2009 (dpy, config),
2010 glXGetVisualFromFBConfig)
2011
Ian Romanickab7c6ff2005-07-26 22:53:38 +00002012PUBLIC GLXPixmap glXCreateGLXPixmapWithConfigSGIX(Display *dpy,
Adam Jackson489ccef2004-12-15 17:18:06 +00002013 GLXFBConfigSGIX config, Pixmap pixmap)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002014{
2015 xGLXVendorPrivateWithReplyReq *vpreq;
2016 xGLXCreateGLXPixmapWithConfigSGIXReq *req;
2017 GLXPixmap xid = None;
2018 CARD8 opcode;
2019 const __GLcontextModes * const fbconfig = (__GLcontextModes *) config;
2020 __GLXscreenConfigs * psc;
2021
2022
2023 if ( (dpy == NULL) || (config == NULL) ) {
2024 return None;
2025 }
2026
2027 psc = GetGLXScreenConfigs( dpy, fbconfig->screen );
2028 if ( (psc != NULL)
2029 && __glXExtensionBitIsEnabled( psc, SGIX_fbconfig_bit ) ) {
2030 opcode = __glXSetupForCommand(dpy);
2031 if (!opcode) {
2032 return None;
2033 }
2034
2035 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2036 LockDisplay(dpy);
2037 GetReqExtra(GLXVendorPrivateWithReply,
2038 sz_xGLXCreateGLXPixmapWithConfigSGIXReq-sz_xGLXVendorPrivateWithReplyReq,vpreq);
2039 req = (xGLXCreateGLXPixmapWithConfigSGIXReq *)vpreq;
2040 req->reqType = opcode;
2041 req->glxCode = X_GLXVendorPrivateWithReply;
2042 req->vendorCode = X_GLXvop_CreateGLXPixmapWithConfigSGIX;
2043 req->screen = fbconfig->screen;
2044 req->fbconfig = fbconfig->fbconfigID;
2045 req->pixmap = pixmap;
2046 req->glxpixmap = xid = XAllocID(dpy);
2047 UnlockDisplay(dpy);
2048 SyncHandle();
2049 }
2050
2051 return xid;
2052}
2053
Ian Romanickab7c6ff2005-07-26 22:53:38 +00002054PUBLIC GLXContext glXCreateContextWithConfigSGIX(Display *dpy,
Adam Jackson489ccef2004-12-15 17:18:06 +00002055 GLXFBConfigSGIX config, int renderType,
2056 GLXContext shareList, Bool allowDirect)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002057{
2058 GLXContext gc = NULL;
2059 const __GLcontextModes * const fbconfig = (__GLcontextModes *) config;
2060 __GLXscreenConfigs * psc;
2061
2062
2063 if ( (dpy == NULL) || (config == NULL) ) {
2064 return None;
2065 }
2066
2067 psc = GetGLXScreenConfigs( dpy, fbconfig->screen );
2068 if ( (psc != NULL)
2069 && __glXExtensionBitIsEnabled( psc, SGIX_fbconfig_bit ) ) {
2070 gc = CreateContext( dpy, NULL, (__GLcontextModes *) config, shareList,
2071 allowDirect, None, False, renderType );
2072 }
2073
2074 return gc;
2075}
2076
2077
Ian Romanickab7c6ff2005-07-26 22:53:38 +00002078PUBLIC GLXFBConfigSGIX glXGetFBConfigFromVisualSGIX(Display *dpy,
2079 XVisualInfo *vis)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002080{
2081 __GLXdisplayPrivate *priv;
2082 __GLXscreenConfigs *psc;
2083
2084 if ( (GetGLXPrivScreenConfig( dpy, vis->screen, & priv, & psc ) != Success)
2085 && __glXExtensionBitIsEnabled( psc, SGIX_fbconfig_bit )
2086 && (psc->configs->fbconfigID != GLX_DONT_CARE) ) {
2087 return (GLXFBConfigSGIX) _gl_context_modes_find_visual( psc->configs,
2088 vis->visualid );
2089 }
2090
2091 return NULL;
2092}
2093
2094
2095/*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002096** GLX_SGIX_swap_group
2097*/
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002098static void __glXJoinSwapGroupSGIX(Display *dpy, GLXDrawable drawable,
2099 GLXDrawable member)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002100{
2101 (void) dpy;
2102 (void) drawable;
2103 (void) member;
2104}
2105
2106
2107/*
2108** GLX_SGIX_swap_barrier
2109*/
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002110static void __glXBindSwapBarrierSGIX(Display *dpy, GLXDrawable drawable,
2111 int barrier)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002112{
2113 (void) dpy;
2114 (void) drawable;
2115 (void) barrier;
2116}
2117
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002118static Bool __glXQueryMaxSwapBarriersSGIX(Display *dpy, int screen, int *max)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002119{
2120 (void) dpy;
2121 (void) screen;
2122 (void) max;
2123 return False;
2124}
2125
2126
2127/*
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002128** GLX_OML_sync_control
2129*/
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002130static Bool __glXGetSyncValuesOML(Display *dpy, GLXDrawable drawable,
2131 int64_t *ust, int64_t *msc, int64_t *sbc)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002132{
2133#ifdef GLX_DIRECT_RENDERING
2134 __GLXdisplayPrivate * const priv = __glXInitialize(dpy);
2135
2136 if ( priv != NULL ) {
2137 int i;
2138 __DRIdrawable * const pdraw = GetDRIDrawable( dpy, drawable, & i );
2139 __GLXscreenConfigs * const psc = &priv->screenConfigs[i];
2140
2141 assert( (pdraw == NULL) || (i != -1) );
2142 return ( (pdraw && pdraw->getSBC && psc->driScreen.getMSC)
2143 && __glXExtensionBitIsEnabled( psc, OML_sync_control_bit )
Kristian Høgsberg5987a032007-05-11 16:43:20 -04002144 && ((*psc->driScreen.getMSC)(&psc->driScreen, msc) == 0)
2145 && ((*pdraw->getSBC)(pdraw, sbc ) == 0)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002146 && (__glXGetUST( ust ) == 0) );
2147 }
2148#else
2149 (void) dpy;
2150 (void) drawable;
2151 (void) ust;
2152 (void) msc;
2153 (void) sbc;
2154#endif
2155 return False;
2156}
2157
2158
2159/**
2160 * Determine the refresh rate of the specified drawable and display.
2161 *
2162 * \param dpy Display whose refresh rate is to be determined.
2163 * \param drawable Drawable whose refresh rate is to be determined.
2164 * \param numerator Numerator of the refresh rate.
2165 * \param demoninator Denominator of the refresh rate.
2166 * \return If the refresh rate for the specified display and drawable could
2167 * be calculated, True is returned. Otherwise False is returned.
2168 *
2169 * \note This function is implemented entirely client-side. A lot of other
2170 * functionality is required to export GLX_OML_sync_control, so on
2171 * XFree86 this function can be called for direct-rendering contexts
2172 * when GLX_OML_sync_control appears in the client extension string.
2173 */
2174
Kristian Høgsbergaceccda2007-05-10 15:52:22 -04002175GLboolean __glXGetMscRateOML(__DRIdrawable *draw,
2176 int32_t * numerator, int32_t * denominator)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002177{
2178#if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
Kristian Høgsbergaceccda2007-05-10 15:52:22 -04002179 __GLXdrawable *glxDraw =
2180 containerOf(draw, __GLXdrawable, driDrawable);
2181 __GLXscreenConfigs *psc = glxDraw->psc;
2182 Display *dpy = psc->dpy;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002183 __GLXdisplayPrivate * const priv = __glXInitialize(dpy);
2184
2185
2186 if ( priv != NULL ) {
2187 XF86VidModeModeLine mode_line;
2188 int dot_clock;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002189 int i;
2190
2191
Kristian Høgsbergaceccda2007-05-10 15:52:22 -04002192 if (XF86VidModeQueryVersion( dpy, & i, & i ) &&
2193 XF86VidModeGetModeLine(dpy, psc->scr, &dot_clock, &mode_line) ) {
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002194 unsigned n = dot_clock * 1000;
2195 unsigned d = mode_line.vtotal * mode_line.htotal;
2196
2197# define V_INTERLACE 0x010
2198# define V_DBLSCAN 0x020
2199
2200 if ( (mode_line.flags & V_INTERLACE) ) {
2201 n *= 2;
2202 }
2203 else if ( (mode_line.flags & V_DBLSCAN) ) {
2204 d *= 2;
2205 }
2206
2207 /* The OML_sync_control spec requires that if the refresh rate is a
2208 * whole number, that the returned numerator be equal to the refresh
2209 * rate and the denominator be 1.
2210 */
2211
2212 if ( (n % d) == 0 ) {
2213 n /= d;
2214 d = 1;
2215 }
2216 else {
2217 static const unsigned f[] = { 13, 11, 7, 5, 3, 2, 0 };
2218
2219
2220 /* This is a poor man's way to reduce a fraction. It's far from
2221 * perfect, but it will work well enough for this situation.
2222 */
2223
2224 for ( i = 0 ; f[i] != 0 ; i++ ) {
2225 while ( ((n % f[i]) == 0) && ((d % f[i]) == 0) ) {
2226 d /= f[i];
2227 n /= f[i];
2228 }
2229 }
2230 }
2231
2232 *numerator = n;
2233 *denominator = d;
2234
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002235 return True;
2236 }
2237 }
2238#else
Kristian Høgsbergaceccda2007-05-10 15:52:22 -04002239 (void) draw;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002240 (void) numerator;
2241 (void) denominator;
2242#endif
2243 return False;
2244}
2245
2246
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002247static int64_t __glXSwapBuffersMscOML(Display *dpy, GLXDrawable drawable,
2248 int64_t target_msc, int64_t divisor,
2249 int64_t remainder)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002250{
2251#ifdef GLX_DIRECT_RENDERING
2252 int screen;
2253 __DRIdrawable *pdraw = GetDRIDrawable( dpy, drawable, & screen );
2254 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen );
2255
2256 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2257 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2258 * of -1 if the function failed because of errors detected in the input
2259 * parameters"
2260 */
2261 if ( divisor < 0 || remainder < 0 || target_msc < 0 )
2262 return -1;
2263 if ( divisor > 0 && remainder >= divisor )
2264 return -1;
2265
2266 if ( (pdraw != NULL) && (pdraw->swapBuffersMSC != NULL)
2267 && __glXExtensionBitIsEnabled( psc, OML_sync_control_bit ) ) {
Kristian Høgsberg5987a032007-05-11 16:43:20 -04002268 return (*pdraw->swapBuffersMSC)(pdraw, target_msc, divisor, remainder);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002269 }
2270#else
2271 (void) dpy;
2272 (void) drawable;
2273 (void) target_msc;
2274 (void) divisor;
2275 (void) remainder;
2276#endif
2277 return 0;
2278}
2279
2280
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002281static Bool __glXWaitForMscOML(Display * dpy, GLXDrawable drawable,
2282 int64_t target_msc, int64_t divisor,
2283 int64_t remainder, int64_t *ust,
2284 int64_t *msc, int64_t *sbc)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002285{
2286#ifdef GLX_DIRECT_RENDERING
2287 int screen;
2288 __DRIdrawable *pdraw = GetDRIDrawable( dpy, drawable, & screen );
2289 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen );
2290 int ret;
2291
2292 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2293 * error", but the return type in the spec is Bool.
2294 */
2295 if ( divisor < 0 || remainder < 0 || target_msc < 0 )
2296 return False;
2297 if ( divisor > 0 && remainder >= divisor )
2298 return False;
2299
2300 if ( (pdraw != NULL) && (pdraw->waitForMSC != NULL)
2301 && __glXExtensionBitIsEnabled( psc, OML_sync_control_bit ) ) {
Kristian Høgsberg5987a032007-05-11 16:43:20 -04002302 ret = (*pdraw->waitForMSC)(pdraw, target_msc,
2303 divisor, remainder, msc, sbc);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002304
2305 /* __glXGetUST returns zero on success and non-zero on failure.
2306 * This function returns True on success and False on failure.
2307 */
2308 return ( (ret == 0) && (__glXGetUST( ust ) == 0) );
2309 }
2310#else
2311 (void) dpy;
2312 (void) drawable;
2313 (void) target_msc;
2314 (void) divisor;
2315 (void) remainder;
2316 (void) ust;
2317 (void) msc;
2318 (void) sbc;
2319#endif
2320 return False;
2321}
2322
2323
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002324static Bool __glXWaitForSbcOML(Display * dpy, GLXDrawable drawable,
2325 int64_t target_sbc, int64_t *ust,
2326 int64_t *msc, int64_t *sbc )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002327{
2328#ifdef GLX_DIRECT_RENDERING
2329 int screen;
2330 __DRIdrawable *pdraw = GetDRIDrawable( dpy, drawable, & screen );
2331 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen );
2332 int ret;
2333
2334 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2335 * error", but the return type in the spec is Bool.
2336 */
2337 if ( target_sbc < 0 )
2338 return False;
2339
2340 if ( (pdraw != NULL) && (pdraw->waitForSBC != NULL)
2341 && __glXExtensionBitIsEnabled( psc, OML_sync_control_bit )) {
Kristian Høgsberg5987a032007-05-11 16:43:20 -04002342 ret = (*pdraw->waitForSBC)(pdraw, target_sbc, msc, sbc);
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002343
2344 /* __glXGetUST returns zero on success and non-zero on failure.
2345 * This function returns True on success and False on failure.
2346 */
2347 return( (ret == 0) && (__glXGetUST( ust ) == 0) );
2348 }
2349#else
2350 (void) dpy;
2351 (void) drawable;
2352 (void) target_sbc;
2353 (void) ust;
2354 (void) msc;
2355 (void) sbc;
2356#endif
2357 return False;
2358}
2359
2360
2361/**
2362 * GLX_MESA_allocate_memory
2363 */
2364/*@{*/
2365
Ian Romanickab7c6ff2005-07-26 22:53:38 +00002366PUBLIC void *glXAllocateMemoryMESA(Display *dpy, int scrn,
2367 size_t size, float readFreq,
2368 float writeFreq, float priority)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002369{
Kristian Høgsberg78a6aa52007-05-16 14:10:29 -04002370#ifdef __DRI_ALLOCATE
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002371 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, scrn );
2372
Kristian Høgsberg78a6aa52007-05-16 14:10:29 -04002373 if (psc && psc->allocate)
2374 return (*psc->allocate->allocateMemory)( &psc->driScreen, size,
2375 readFreq, writeFreq,
2376 priority );
2377
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002378#else
2379 (void) dpy;
2380 (void) scrn;
2381 (void) size;
2382 (void) readFreq;
2383 (void) writeFreq;
2384 (void) priority;
2385#endif /* GLX_DIRECT_RENDERING */
2386
2387 return NULL;
2388}
2389
2390
Ian Romanickab7c6ff2005-07-26 22:53:38 +00002391PUBLIC void glXFreeMemoryMESA(Display *dpy, int scrn, void *pointer)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002392{
Kristian Høgsberg78a6aa52007-05-16 14:10:29 -04002393#ifdef __DRI_ALLOCATE
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002394 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, scrn );
2395
Kristian Høgsberg78a6aa52007-05-16 14:10:29 -04002396 if (psc && psc->allocate)
2397 (*psc->allocate->freeMemory)( &psc->driScreen, pointer );
2398
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002399#else
2400 (void) dpy;
2401 (void) scrn;
2402 (void) pointer;
2403#endif /* GLX_DIRECT_RENDERING */
2404}
2405
2406
Ian Romanickab7c6ff2005-07-26 22:53:38 +00002407PUBLIC GLuint glXGetMemoryOffsetMESA( Display *dpy, int scrn,
2408 const void *pointer )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002409{
Kristian Høgsberg78a6aa52007-05-16 14:10:29 -04002410#ifdef __DRI_ALLOCATE
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002411 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, scrn );
2412
Kristian Høgsberg78a6aa52007-05-16 14:10:29 -04002413 if (psc && psc->allocate)
2414 return (*psc->allocate->memoryOffset)( &psc->driScreen, pointer );
2415
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002416#else
2417 (void) dpy;
2418 (void) scrn;
2419 (void) pointer;
2420#endif /* GLX_DIRECT_RENDERING */
2421
2422 return ~0L;
2423}
2424/*@}*/
2425
2426
2427/**
2428 * Mesa extension stubs. These will help reduce portability problems.
2429 */
2430/*@{*/
2431
2432/**
2433 * Release all buffers associated with the specified GLX drawable.
2434 *
2435 * \todo
2436 * This function was intended for stand-alone Mesa. The issue there is that
2437 * the library doesn't get any notification when a window is closed. In
2438 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2439 * supported, there are 3 different functions to destroy a drawable. It
2440 * should be possible to create GLX protocol (or have it determine which
2441 * protocol to use based on the type of the drawable) to have one function
2442 * do the work of 3. For the direct-rendering case, this function could
2443 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2444 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2445 * would need to be used. This really should be done as part of the new DRI
2446 * interface work.
2447 *
2448 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2449 * __driGarbageCollectDrawables
2450 * glXDestroyGLXPixmap
2451 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2452 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2453 */
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002454static Bool __glXReleaseBuffersMESA( Display *dpy, GLXDrawable d )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002455{
2456 (void) dpy;
2457 (void) d;
2458 return False;
2459}
2460
2461
Ian Romanickab7c6ff2005-07-26 22:53:38 +00002462PUBLIC GLXPixmap glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visual,
2463 Pixmap pixmap, Colormap cmap )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002464{
2465 (void) dpy;
2466 (void) visual;
2467 (void) pixmap;
2468 (void) cmap;
2469 return 0;
2470}
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002471/*@}*/
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002472
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002473
2474/**
2475 * GLX_MESA_copy_sub_buffer
2476 */
Brian Paulf2ad1b62006-03-31 15:48:04 +00002477#define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002478static void __glXCopySubBufferMESA(Display *dpy, GLXDrawable drawable,
2479 int x, int y, int width, int height)
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002480{
Brian Paulf2ad1b62006-03-31 15:48:04 +00002481 xGLXVendorPrivateReq *req;
2482 GLXContext gc;
2483 GLXContextTag tag;
2484 CARD32 *drawable_ptr;
2485 INT32 *x_ptr, *y_ptr, *w_ptr, *h_ptr;
2486 CARD8 opcode;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002487
Kristian Høgsbergac3e8382007-05-15 15:17:30 -04002488#ifdef __DRI_COPY_SUB_BUFFER
Brian Paulf2ad1b62006-03-31 15:48:04 +00002489 int screen;
2490 __DRIdrawable *pdraw = GetDRIDrawable( dpy, drawable, & screen );
2491 if ( pdraw != NULL ) {
2492 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen );
Kristian Høgsbergac3e8382007-05-15 15:17:30 -04002493 if (psc->copySubBuffer != NULL) {
2494 (*psc->copySubBuffer->copySubBuffer)(pdraw, x, y, width, height);
Brian Paulf2ad1b62006-03-31 15:48:04 +00002495 }
2496
2497 return;
2498 }
2499#endif
2500
2501 opcode = __glXSetupForCommand(dpy);
2502 if (!opcode)
2503 return;
2504
2505 /*
2506 ** The calling thread may or may not have a current context. If it
2507 ** does, send the context tag so the server can do a flush.
2508 */
2509 gc = __glXGetCurrentContext();
2510 if ((gc != NULL) && (dpy == gc->currentDpy) &&
2511 ((drawable == gc->currentDrawable) ||
2512 (drawable == gc->currentReadable)) ) {
2513 tag = gc->currentContextTag;
2514 } else {
2515 tag = 0;
2516 }
2517
2518 LockDisplay(dpy);
2519 GetReqExtra(GLXVendorPrivate, sizeof(CARD32) + sizeof(INT32) * 4,req);
2520 req->reqType = opcode;
2521 req->glxCode = X_GLXVendorPrivate;
2522 req->vendorCode = X_GLXvop_CopySubBufferMESA;
2523 req->contextTag = tag;
2524
2525 drawable_ptr = (CARD32 *) (req + 1);
2526 x_ptr = (INT32 *) (drawable_ptr + 1);
2527 y_ptr = (INT32 *) (drawable_ptr + 2);
2528 w_ptr = (INT32 *) (drawable_ptr + 3);
2529 h_ptr = (INT32 *) (drawable_ptr + 4);
2530
2531 *drawable_ptr = drawable;
2532 *x_ptr = x;
2533 *y_ptr = y;
2534 *w_ptr = width;
2535 *h_ptr = height;
2536
2537 UnlockDisplay(dpy);
2538 SyncHandle();
2539}
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002540
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002541
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002542/**
2543 * GLX_EXT_texture_from_pixmap
2544 */
2545/*@{*/
2546static void __glXBindTexImageEXT(Display *dpy,
2547 GLXDrawable drawable,
2548 int buffer,
2549 const int *attrib_list)
Brian Paul42725d62006-02-07 00:39:56 +00002550{
2551 xGLXVendorPrivateReq *req;
2552 GLXContext gc = __glXGetCurrentContext();
2553 CARD32 *drawable_ptr;
2554 INT32 *buffer_ptr;
David Revemanc6f8ae12006-04-11 12:12:13 +00002555 CARD32 *num_attrib_ptr;
2556 CARD32 *attrib_ptr;
Brian Paul42725d62006-02-07 00:39:56 +00002557 CARD8 opcode;
David Revemanc6f8ae12006-04-11 12:12:13 +00002558 unsigned int i;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002559
Brian Paul42725d62006-02-07 00:39:56 +00002560 if (gc == NULL)
Adam Jackson01576242006-05-01 22:25:18 +00002561 return;
Brian Paul42725d62006-02-07 00:39:56 +00002562
David Revemanc6f8ae12006-04-11 12:12:13 +00002563 i = 0;
2564 if (attrib_list) {
2565 while (attrib_list[i * 2] != None)
2566 i++;
2567 }
2568
Brian Paul42725d62006-02-07 00:39:56 +00002569#ifdef GLX_DIRECT_RENDERING
2570 if (gc->isDirect)
Adam Jackson01576242006-05-01 22:25:18 +00002571 return;
Brian Paul42725d62006-02-07 00:39:56 +00002572#endif
2573
2574 opcode = __glXSetupForCommand(dpy);
2575 if (!opcode)
Adam Jackson01576242006-05-01 22:25:18 +00002576 return;
Brian Paul42725d62006-02-07 00:39:56 +00002577
2578 LockDisplay(dpy);
David Revemanc6f8ae12006-04-11 12:12:13 +00002579 GetReqExtra(GLXVendorPrivate, 12 + 8 * i,req);
Brian Paul42725d62006-02-07 00:39:56 +00002580 req->reqType = opcode;
2581 req->glxCode = X_GLXVendorPrivate;
2582 req->vendorCode = X_GLXvop_BindTexImageEXT;
2583 req->contextTag = gc->currentContextTag;
2584
2585 drawable_ptr = (CARD32 *) (req + 1);
2586 buffer_ptr = (INT32 *) (drawable_ptr + 1);
David Revemanc6f8ae12006-04-11 12:12:13 +00002587 num_attrib_ptr = (CARD32 *) (buffer_ptr + 1);
2588 attrib_ptr = (CARD32 *) (num_attrib_ptr + 1);
Brian Paul42725d62006-02-07 00:39:56 +00002589
2590 *drawable_ptr = drawable;
2591 *buffer_ptr = buffer;
David Revemanc6f8ae12006-04-11 12:12:13 +00002592 *num_attrib_ptr = (CARD32) i;
2593
2594 i = 0;
2595 if (attrib_list) {
2596 while (attrib_list[i * 2] != None)
2597 {
2598 *attrib_ptr++ = (CARD32) attrib_list[i * 2 + 0];
2599 *attrib_ptr++ = (CARD32) attrib_list[i * 2 + 1];
2600 i++;
2601 }
2602 }
Brian Paul42725d62006-02-07 00:39:56 +00002603
2604 UnlockDisplay(dpy);
2605 SyncHandle();
Brian Paul42725d62006-02-07 00:39:56 +00002606}
2607
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002608static void __glXReleaseTexImageEXT(Display *dpy,
2609 GLXDrawable drawable,
2610 int buffer)
Brian Paul42725d62006-02-07 00:39:56 +00002611{
2612 xGLXVendorPrivateReq *req;
2613 GLXContext gc = __glXGetCurrentContext();
2614 CARD32 *drawable_ptr;
2615 INT32 *buffer_ptr;
2616 CARD8 opcode;
2617
2618 if (gc == NULL)
Adam Jackson01576242006-05-01 22:25:18 +00002619 return;
Brian Paul42725d62006-02-07 00:39:56 +00002620
2621#ifdef GLX_DIRECT_RENDERING
2622 if (gc->isDirect)
Adam Jackson01576242006-05-01 22:25:18 +00002623 return;
Brian Paul42725d62006-02-07 00:39:56 +00002624#endif
2625
2626 opcode = __glXSetupForCommand(dpy);
2627 if (!opcode)
Adam Jackson01576242006-05-01 22:25:18 +00002628 return;
Brian Paul42725d62006-02-07 00:39:56 +00002629
2630 LockDisplay(dpy);
2631 GetReqExtra(GLXVendorPrivate, sizeof(CARD32)+sizeof(INT32),req);
2632 req->reqType = opcode;
2633 req->glxCode = X_GLXVendorPrivate;
2634 req->vendorCode = X_GLXvop_ReleaseTexImageEXT;
2635 req->contextTag = gc->currentContextTag;
2636
2637 drawable_ptr = (CARD32 *) (req + 1);
2638 buffer_ptr = (INT32 *) (drawable_ptr + 1);
2639
2640 *drawable_ptr = drawable;
2641 *buffer_ptr = buffer;
2642
2643 UnlockDisplay(dpy);
2644 SyncHandle();
Brian Paul42725d62006-02-07 00:39:56 +00002645}
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002646/*@}*/
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002647
2648/**
2649 * \c strdup is actually not a standard ANSI C or POSIX routine.
2650 * Irix will not define it if ANSI mode is in effect.
2651 *
2652 * \sa strdup
2653 */
2654char *
2655__glXstrdup(const char *str)
2656{
2657 char *copy;
2658 copy = (char *) Xmalloc(strlen(str) + 1);
2659 if (!copy)
2660 return NULL;
2661 strcpy(copy, str);
2662 return copy;
2663}
2664
2665/*
2666** glXGetProcAddress support
2667*/
2668
2669struct name_address_pair {
2670 const char *Name;
2671 GLvoid *Address;
2672};
2673
2674#define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2675#define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2676
2677static const struct name_address_pair GLX_functions[] = {
2678 /*** GLX_VERSION_1_0 ***/
2679 GLX_FUNCTION( glXChooseVisual ),
2680 GLX_FUNCTION( glXCopyContext ),
2681 GLX_FUNCTION( glXCreateContext ),
2682 GLX_FUNCTION( glXCreateGLXPixmap ),
2683 GLX_FUNCTION( glXDestroyContext ),
2684 GLX_FUNCTION( glXDestroyGLXPixmap ),
2685 GLX_FUNCTION( glXGetConfig ),
2686 GLX_FUNCTION( glXGetCurrentContext ),
2687 GLX_FUNCTION( glXGetCurrentDrawable ),
2688 GLX_FUNCTION( glXIsDirect ),
2689 GLX_FUNCTION( glXMakeCurrent ),
2690 GLX_FUNCTION( glXQueryExtension ),
2691 GLX_FUNCTION( glXQueryVersion ),
2692 GLX_FUNCTION( glXSwapBuffers ),
2693 GLX_FUNCTION( glXUseXFont ),
2694 GLX_FUNCTION( glXWaitGL ),
2695 GLX_FUNCTION( glXWaitX ),
2696
2697 /*** GLX_VERSION_1_1 ***/
2698 GLX_FUNCTION( glXGetClientString ),
2699 GLX_FUNCTION( glXQueryExtensionsString ),
2700 GLX_FUNCTION( glXQueryServerString ),
2701
2702 /*** GLX_VERSION_1_2 ***/
2703 GLX_FUNCTION( glXGetCurrentDisplay ),
2704
2705 /*** GLX_VERSION_1_3 ***/
2706 GLX_FUNCTION( glXChooseFBConfig ),
2707 GLX_FUNCTION( glXCreateNewContext ),
2708 GLX_FUNCTION( glXCreatePbuffer ),
2709 GLX_FUNCTION( glXCreatePixmap ),
2710 GLX_FUNCTION( glXCreateWindow ),
2711 GLX_FUNCTION( glXDestroyPbuffer ),
2712 GLX_FUNCTION( glXDestroyPixmap ),
2713 GLX_FUNCTION( glXDestroyWindow ),
2714 GLX_FUNCTION( glXGetCurrentReadDrawable ),
2715 GLX_FUNCTION( glXGetFBConfigAttrib ),
2716 GLX_FUNCTION( glXGetFBConfigs ),
2717 GLX_FUNCTION( glXGetSelectedEvent ),
2718 GLX_FUNCTION( glXGetVisualFromFBConfig ),
2719 GLX_FUNCTION( glXMakeContextCurrent ),
2720 GLX_FUNCTION( glXQueryContext ),
2721 GLX_FUNCTION( glXQueryDrawable ),
2722 GLX_FUNCTION( glXSelectEvent ),
2723
2724 /*** GLX_SGI_swap_control ***/
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002725 GLX_FUNCTION2( glXSwapIntervalSGI, __glXSwapIntervalSGI ),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002726
2727 /*** GLX_SGI_video_sync ***/
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002728 GLX_FUNCTION2( glXGetVideoSyncSGI, __glXGetVideoSyncSGI ),
2729 GLX_FUNCTION2( glXWaitVideoSyncSGI, __glXWaitVideoSyncSGI ),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002730
2731 /*** GLX_SGI_make_current_read ***/
2732 GLX_FUNCTION2( glXMakeCurrentReadSGI, glXMakeContextCurrent ),
2733 GLX_FUNCTION2( glXGetCurrentReadDrawableSGI, glXGetCurrentReadDrawable ),
2734
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002735 /*** GLX_EXT_import_context ***/
2736 GLX_FUNCTION( glXFreeContextEXT ),
2737 GLX_FUNCTION( glXGetContextIDEXT ),
2738 GLX_FUNCTION2( glXGetCurrentDisplayEXT, glXGetCurrentDisplay ),
2739 GLX_FUNCTION( glXImportContextEXT ),
2740 GLX_FUNCTION2( glXQueryContextInfoEXT, glXQueryContext ),
2741
2742 /*** GLX_SGIX_fbconfig ***/
2743 GLX_FUNCTION2( glXGetFBConfigAttribSGIX, glXGetFBConfigAttrib ),
2744 GLX_FUNCTION2( glXChooseFBConfigSGIX, glXChooseFBConfig ),
2745 GLX_FUNCTION( glXCreateGLXPixmapWithConfigSGIX ),
2746 GLX_FUNCTION( glXCreateContextWithConfigSGIX ),
2747 GLX_FUNCTION2( glXGetVisualFromFBConfigSGIX, glXGetVisualFromFBConfig ),
2748 GLX_FUNCTION( glXGetFBConfigFromVisualSGIX ),
2749
2750 /*** GLX_SGIX_pbuffer ***/
2751 GLX_FUNCTION( glXCreateGLXPbufferSGIX ),
2752 GLX_FUNCTION( glXDestroyGLXPbufferSGIX ),
2753 GLX_FUNCTION( glXQueryGLXPbufferSGIX ),
2754 GLX_FUNCTION( glXSelectEventSGIX ),
2755 GLX_FUNCTION( glXGetSelectedEventSGIX ),
2756
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002757 /*** GLX_SGIX_swap_group ***/
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002758 GLX_FUNCTION2( glXJoinSwapGroupSGIX, __glXJoinSwapGroupSGIX ),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002759
2760 /*** GLX_SGIX_swap_barrier ***/
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002761 GLX_FUNCTION2( glXBindSwapBarrierSGIX, __glXBindSwapBarrierSGIX ),
2762 GLX_FUNCTION2( glXQueryMaxSwapBarriersSGIX, __glXQueryMaxSwapBarriersSGIX ),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002763
2764 /*** GLX_MESA_allocate_memory ***/
2765 GLX_FUNCTION( glXAllocateMemoryMESA ),
2766 GLX_FUNCTION( glXFreeMemoryMESA ),
2767 GLX_FUNCTION( glXGetMemoryOffsetMESA ),
2768
2769 /*** GLX_MESA_copy_sub_buffer ***/
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002770 GLX_FUNCTION2( glXCopySubBufferMESA, __glXCopySubBufferMESA ),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002771
2772 /*** GLX_MESA_pixmap_colormap ***/
2773 GLX_FUNCTION( glXCreateGLXPixmapMESA ),
2774
2775 /*** GLX_MESA_release_buffers ***/
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002776 GLX_FUNCTION2( glXReleaseBuffersMESA, __glXReleaseBuffersMESA ),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002777
2778 /*** GLX_MESA_swap_control ***/
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002779 GLX_FUNCTION2( glXSwapIntervalMESA, __glXSwapIntervalMESA ),
2780 GLX_FUNCTION2( glXGetSwapIntervalMESA, __glXGetSwapIntervalMESA ),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002781
2782 /*** GLX_MESA_swap_frame_usage ***/
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002783 GLX_FUNCTION2( glXBeginFrameTrackingMESA, __glXBeginFrameTrackingMESA ),
2784 GLX_FUNCTION2( glXEndFrameTrackingMESA, __glXEndFrameTrackingMESA ),
2785 GLX_FUNCTION2( glXGetFrameUsageMESA, __glXGetFrameUsageMESA ),
2786 GLX_FUNCTION2( glXQueryFrameTrackingMESA, __glXQueryFrameTrackingMESA ),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002787
2788 /*** GLX_ARB_get_proc_address ***/
2789 GLX_FUNCTION( glXGetProcAddressARB ),
2790
2791 /*** GLX 1.4 ***/
2792 GLX_FUNCTION2( glXGetProcAddress, glXGetProcAddressARB ),
2793
2794 /*** GLX_OML_sync_control ***/
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002795 GLX_FUNCTION2( glXWaitForSbcOML, __glXWaitForSbcOML ),
2796 GLX_FUNCTION2( glXWaitForMscOML, __glXWaitForMscOML ),
2797 GLX_FUNCTION2( glXSwapBuffersMscOML, __glXSwapBuffersMscOML ),
2798 GLX_FUNCTION2( glXGetMscRateOML, __glXGetMscRateOML ),
2799 GLX_FUNCTION2( glXGetSyncValuesOML, __glXGetSyncValuesOML ),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002800
Brian Paul42725d62006-02-07 00:39:56 +00002801 /*** GLX_EXT_texture_from_pixmap ***/
Ian Romanickfc5b57b2006-08-29 15:38:19 +00002802 GLX_FUNCTION2( glXBindTexImageEXT, __glXBindTexImageEXT ),
2803 GLX_FUNCTION2( glXReleaseTexImageEXT, __glXReleaseTexImageEXT ),
Brian Paul42725d62006-02-07 00:39:56 +00002804
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002805#ifdef GLX_DIRECT_RENDERING
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002806 /*** DRI configuration ***/
2807 GLX_FUNCTION( glXGetScreenDriver ),
2808 GLX_FUNCTION( glXGetDriverConfig ),
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002809#endif
2810
2811 { NULL, NULL } /* end of list */
2812};
2813
2814
2815static const GLvoid *
2816get_glx_proc_address(const char *funcName)
2817{
2818 GLuint i;
2819
2820 /* try static functions */
2821 for (i = 0; GLX_functions[i].Name; i++) {
2822 if (strcmp(GLX_functions[i].Name, funcName) == 0)
2823 return GLX_functions[i].Address;
2824 }
2825
2826 return NULL;
2827}
2828
2829
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002830/**
2831 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2832 * \c glXGetProcAddress.
2833 *
2834 * \param procName Name of a GL or GLX function.
2835 * \returns A pointer to the named function
2836 *
2837 * \sa glXGetProcAddress
2838 */
Adam Jackson489ccef2004-12-15 17:18:06 +00002839PUBLIC void (*glXGetProcAddressARB(const GLubyte *procName))( void )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002840{
2841 typedef void (*gl_function)( void );
2842 gl_function f;
2843
2844
2845 /* Search the table of GLX and internal functions first. If that
2846 * fails and the supplied name could be a valid core GL name, try
2847 * searching the core GL function table. This check is done to prevent
2848 * DRI based drivers from searching the core GL function table for
2849 * internal API functions.
2850 */
2851
2852 f = (gl_function) get_glx_proc_address((const char *) procName);
2853 if ( (f == NULL) && (procName[0] == 'g') && (procName[1] == 'l')
2854 && (procName[2] != 'X') ) {
2855 f = (gl_function) _glapi_get_proc_address((const char *) procName);
2856 }
2857
2858 return f;
2859}
2860
2861/**
2862 * Get the address of a named GL function. This is the GLX 1.4 name for
2863 * \c glXGetProcAddressARB.
2864 *
2865 * \param procName Name of a GL or GLX function.
2866 * \returns A pointer to the named function
2867 *
2868 * \sa glXGetProcAddressARB
2869 */
Adam Jackson489ccef2004-12-15 17:18:06 +00002870PUBLIC void (*glXGetProcAddress(const GLubyte *procName))( void )
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002871#if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2872 __attribute__ ((alias ("glXGetProcAddressARB")));
2873#else
2874{
2875 return glXGetProcAddressARB(procName);
2876}
2877#endif /* __GNUC__ */
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002878
2879
2880#ifdef GLX_DIRECT_RENDERING
2881/**
2882 * Retrieves the verion of the internal libGL API in YYYYMMDD format. This
2883 * might be used by the DRI drivers to determine how new libGL is at runtime.
2884 * Drivers should not call this function directly. They should instead use
2885 * \c glXGetProcAddress to obtain a pointer to the function.
2886 *
2887 * \returns An 8-digit decimal number representing the internal libGL API in
2888 * YYYYMMDD format.
2889 *
2890 * \sa glXGetProcAddress, PFNGLXGETINTERNALVERSIONPROC
2891 *
2892 * \since Internal API version 20021121.
2893 */
2894int __glXGetInternalVersion(void)
2895{
2896 /* History:
2897 * 20021121 - Initial version
2898 * 20021128 - Added __glXWindowExists() function
2899 * 20021207 - Added support for dynamic GLX extensions,
2900 * GLX_SGI_swap_control, GLX_SGI_video_sync,
2901 * GLX_OML_sync_control, and GLX_MESA_swap_control.
2902 * Never officially released. Do NOT test against
2903 * this version. Use 20030317 instead.
2904 * 20030317 - Added support GLX_SGIX_fbconfig,
2905 * GLX_MESA_swap_frame_usage, GLX_OML_swap_method,
2906 * GLX_{ARB,SGIS}_multisample, and
2907 * GLX_SGIX_visual_select_group.
2908 * 20030606 - Added support for GLX_SGI_make_current_read.
2909 * 20030813 - Made support for dynamic extensions multi-head aware.
2910 * 20030818 - Added support for GLX_MESA_allocate_memory in place of the
2911 * deprecated GLX_NV_vertex_array_range & GLX_MESA_agp_offset
2912 * interfaces.
2913 * 20031201 - Added support for the first round of DRI interface changes.
2914 * Do NOT test against this version! It has binary
2915 * compatibility bugs, use 20040317 instead.
2916 * 20040317 - Added the 'mode' field to __DRIcontextRec.
2917 * 20040415 - Added support for bindContext3 and unbindContext3.
2918 * 20040602 - Add __glXGetDrawableInfo. I though that was there
2919 * months ago. :(
Ian Romanick1585c232005-07-28 00:29:51 +00002920 * 20050727 - Gut all the old interfaces. This breaks compatability with
Ian Romanickc39bf5e2005-07-24 06:29:14 +00002921 * any DRI driver built to any previous version.
Brian Paulf2ad1b62006-03-31 15:48:04 +00002922 * 20060314 - Added support for GLX_MESA_copy_sub_buffer.
Eric Anholtc2b185c2007-01-05 18:19:58 -08002923 * 20070105 - Added support for damage reporting.
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002924 */
Eric Anholtc2b185c2007-01-05 18:19:58 -08002925 return 20070105;
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002926}
2927
2928
Adam Jacksoncb3610e2004-10-25 21:09:16 +00002929/**
2930 * Get the unadjusted system time (UST). Currently, the UST is measured in
2931 * microseconds since Epoc. The actual resolution of the UST may vary from
2932 * system to system, and the units may vary from release to release.
2933 * Drivers should not call this function directly. They should instead use
2934 * \c glXGetProcAddress to obtain a pointer to the function.
2935 *
2936 * \param ust Location to store the 64-bit UST
2937 * \returns Zero on success or a negative errno value on failure.
2938 *
2939 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2940 *
2941 * \since Internal API version 20030317.
2942 */
2943int __glXGetUST( int64_t * ust )
2944{
2945 struct timeval tv;
2946
2947 if ( ust == NULL ) {
2948 return -EFAULT;
2949 }
2950
2951 if ( gettimeofday( & tv, NULL ) == 0 ) {
2952 ust[0] = (tv.tv_sec * 1000000) + tv.tv_usec;
2953 return 0;
2954 } else {
2955 return -errno;
2956 }
2957}
2958#endif /* GLX_DIRECT_RENDERING */