Merge commit 'origin/gallium-0.1' into gallium-0.2
[mesa.git] / src / glx / x11 / glxcmds.c
1 /* -*- mode: c; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 3; coding: utf-8-unix -*- */
2 /*
3 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
4 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice including the dates of first publication and
14 * either this permission notice or a reference to
15 * http://oss.sgi.com/projects/FreeB/
16 * shall be included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
23 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
25 *
26 * Except as contained in this notice, the name of Silicon Graphics, Inc.
27 * shall not be used in advertising or otherwise to promote the sale, use or
28 * other dealings in this Software without prior written authorization from
29 * Silicon Graphics, Inc.
30 */
31
32 /**
33 * \file glxcmds.c
34 * Client-side GLX interface.
35 */
36
37 #include "glxclient.h"
38 #include "glapi.h"
39 #include "glxextensions.h"
40 #include "glcontextmodes.h"
41
42 #ifdef GLX_DIRECT_RENDERING
43 #include <sys/time.h>
44 #include <X11/extensions/xf86vmode.h>
45 #include "xf86dri.h"
46 #endif
47
48 static const char __glXGLXClientVendorName[] = "SGI";
49 static const char __glXGLXClientVersion[] = "1.4";
50
51
52 /****************************************************************************/
53
54 #ifdef GLX_DIRECT_RENDERING
55
56 static Bool windowExistsFlag;
57 static int windowExistsErrorHandler(Display *dpy, XErrorEvent *xerr)
58 {
59 if (xerr->error_code == BadWindow) {
60 windowExistsFlag = GL_FALSE;
61 }
62 return 0;
63 }
64
65 /**
66 * Find drawables in the local hash that have been destroyed on the
67 * server.
68 *
69 * \param dpy Display to destroy drawables for
70 * \param screen Screen number to destroy drawables for
71 */
72 static void GarbageCollectDRIDrawables(Display *dpy, __GLXscreenConfigs *sc)
73 {
74 XID draw;
75 __GLXDRIdrawable *pdraw;
76 XWindowAttributes xwa;
77 int (*oldXErrorHandler)(Display *, XErrorEvent *);
78
79 /* Set no-op error handler so Xlib doesn't bail out if the windows
80 * has alreay been destroyed on the server. */
81 XSync(dpy, GL_FALSE);
82 oldXErrorHandler = XSetErrorHandler(windowExistsErrorHandler);
83
84 if (__glxHashFirst(sc->drawHash, &draw, (void *)&pdraw) == 1) {
85 do {
86 windowExistsFlag = GL_TRUE;
87 XGetWindowAttributes(dpy, draw, &xwa); /* dummy request */
88 if (!windowExistsFlag) {
89 /* Destroy the local drawable data, if the drawable no
90 longer exists in the Xserver */
91 (*pdraw->destroyDrawable)(pdraw);
92 __glxHashDelete(sc->drawHash, draw);
93 }
94 } while (__glxHashNext(sc->drawHash, &draw, (void *)&pdraw) == 1);
95 }
96
97 XSync(dpy, GL_FALSE);
98 XSetErrorHandler(oldXErrorHandler);
99 }
100
101 extern __GLXDRIdrawable *
102 GetGLXDRIDrawable(Display *dpy, GLXDrawable drawable, int * const scrn_num);
103
104 /**
105 * Get the __DRIdrawable for the drawable associated with a GLXContext
106 *
107 * \param dpy The display associated with \c drawable.
108 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
109 * \param scrn_num If non-NULL, the drawables screen is stored there
110 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
111 * the drawable is not associated with a direct-rendering context.
112 */
113 _X_HIDDEN __GLXDRIdrawable *
114 GetGLXDRIDrawable(Display *dpy, GLXDrawable drawable, int * const scrn_num)
115 {
116 __GLXdisplayPrivate *priv = __glXInitialize(dpy);
117 __GLXDRIdrawable *pdraw;
118 const unsigned screen_count = ScreenCount(dpy);
119 unsigned i;
120 __GLXscreenConfigs *psc;
121
122 if (priv == NULL)
123 return NULL;
124
125 for (i = 0; i < screen_count; i++) {
126 psc = &priv->screenConfigs[i];
127 if (psc->drawHash == NULL)
128 continue;
129
130 if (__glxHashLookup(psc->drawHash, drawable, (void *) &pdraw) == 0) {
131 if (scrn_num != NULL)
132 *scrn_num = i;
133 return pdraw;
134 }
135 }
136
137 return NULL;
138 }
139
140 #endif
141
142
143 /**
144 * Get the GLX per-screen data structure associated with a GLX context.
145 *
146 * \param dpy Display for which the GLX per-screen information is to be
147 * retrieved.
148 * \param scrn Screen on \c dpy for which the GLX per-screen information is
149 * to be retrieved.
150 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
151 * specify a valid GLX screen, or NULL otherwise.
152 *
153 * \todo Should this function validate that \c scrn is within the screen
154 * number range for \c dpy?
155 */
156
157 static __GLXscreenConfigs *
158 GetGLXScreenConfigs(Display *dpy, int scrn)
159 {
160 __GLXdisplayPrivate * const priv = __glXInitialize(dpy);
161
162 return (priv->screenConfigs != NULL) ? &priv->screenConfigs[scrn] : NULL;
163 }
164
165
166 static int
167 GetGLXPrivScreenConfig( Display *dpy, int scrn, __GLXdisplayPrivate ** ppriv,
168 __GLXscreenConfigs ** ppsc )
169 {
170 /* Initialize the extension, if needed . This has the added value
171 * of initializing/allocating the display private
172 */
173
174 if ( dpy == NULL ) {
175 return GLX_NO_EXTENSION;
176 }
177
178 *ppriv = __glXInitialize(dpy);
179 if ( *ppriv == NULL ) {
180 return GLX_NO_EXTENSION;
181 }
182
183 /* Check screen number to see if its valid */
184 if ((scrn < 0) || (scrn >= ScreenCount(dpy))) {
185 return GLX_BAD_SCREEN;
186 }
187
188 /* Check to see if the GL is supported on this screen */
189 *ppsc = &((*ppriv)->screenConfigs[scrn]);
190 if ( (*ppsc)->configs == NULL ) {
191 /* No support for GL on this screen regardless of visual */
192 return GLX_BAD_VISUAL;
193 }
194
195 return Success;
196 }
197
198
199 /**
200 * Determine if a \c GLXFBConfig supplied by the application is valid.
201 *
202 * \param dpy Application supplied \c Display pointer.
203 * \param config Application supplied \c GLXFBConfig.
204 *
205 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
206 * \c __GLcontextModes structure is returned. Otherwise, \c NULL
207 * is returned.
208 */
209 static __GLcontextModes *
210 ValidateGLXFBConfig( Display * dpy, GLXFBConfig config )
211 {
212 __GLXdisplayPrivate * const priv = __glXInitialize(dpy);
213 const unsigned num_screens = ScreenCount(dpy);
214 unsigned i;
215 const __GLcontextModes * modes;
216
217
218 if ( priv != NULL ) {
219 for ( i = 0 ; i < num_screens ; i++ ) {
220 for ( modes = priv->screenConfigs[i].configs
221 ; modes != NULL
222 ; modes = modes->next ) {
223 if ( modes == (__GLcontextModes *) config ) {
224 return (__GLcontextModes *) config;
225 }
226 }
227 }
228 }
229
230 return NULL;
231 }
232
233
234 /**
235 * \todo It should be possible to move the allocate of \c client_state_private
236 * later in the function for direct-rendering contexts. Direct-rendering
237 * contexts don't need to track client state, so they don't need that memory
238 * at all.
239 *
240 * \todo Eliminate \c __glXInitVertexArrayState. Replace it with a new
241 * function called \c __glXAllocateClientState that allocates the memory and
242 * does all the initialization (including the pixel pack / unpack).
243 */
244 static
245 GLXContext AllocateGLXContext( Display *dpy )
246 {
247 GLXContext gc;
248 int bufSize;
249 CARD8 opcode;
250 __GLXattribute *state;
251
252 if (!dpy)
253 return NULL;
254
255 opcode = __glXSetupForCommand(dpy);
256 if (!opcode) {
257 return NULL;
258 }
259
260 /* Allocate our context record */
261 gc = (GLXContext) Xmalloc(sizeof(struct __GLXcontextRec));
262 if (!gc) {
263 /* Out of memory */
264 return NULL;
265 }
266 memset(gc, 0, sizeof(struct __GLXcontextRec));
267
268 state = Xmalloc(sizeof(struct __GLXattributeRec));
269 if (state == NULL) {
270 /* Out of memory */
271 Xfree(gc);
272 return NULL;
273 }
274 gc->client_state_private = state;
275 memset(gc->client_state_private, 0, sizeof(struct __GLXattributeRec));
276 state->NoDrawArraysProtocol = (getenv("LIBGL_NO_DRAWARRAYS") != NULL);
277
278 /*
279 ** Create a temporary buffer to hold GLX rendering commands. The size
280 ** of the buffer is selected so that the maximum number of GLX rendering
281 ** commands can fit in a single X packet and still have room in the X
282 ** packet for the GLXRenderReq header.
283 */
284
285 bufSize = (XMaxRequestSize(dpy) * 4) - sz_xGLXRenderReq;
286 gc->buf = (GLubyte *) Xmalloc(bufSize);
287 if (!gc->buf) {
288 Xfree(gc->client_state_private);
289 Xfree(gc);
290 return NULL;
291 }
292 gc->bufSize = bufSize;
293
294 /* Fill in the new context */
295 gc->renderMode = GL_RENDER;
296
297 state->storePack.alignment = 4;
298 state->storeUnpack.alignment = 4;
299
300 gc->attributes.stackPointer = &gc->attributes.stack[0];
301
302 /*
303 ** PERFORMANCE NOTE: A mode dependent fill image can speed things up.
304 ** Other code uses the fastImageUnpack bit, but it is never set
305 ** to GL_TRUE.
306 */
307 gc->fastImageUnpack = GL_FALSE;
308 gc->fillImage = __glFillImage;
309 gc->pc = gc->buf;
310 gc->bufEnd = gc->buf + bufSize;
311 gc->isDirect = GL_FALSE;
312 if (__glXDebug) {
313 /*
314 ** Set limit register so that there will be one command per packet
315 */
316 gc->limit = gc->buf;
317 } else {
318 gc->limit = gc->buf + bufSize - __GLX_BUFFER_LIMIT_SIZE;
319 }
320 gc->createDpy = dpy;
321 gc->majorOpcode = opcode;
322
323 /*
324 ** Constrain the maximum drawing command size allowed to be
325 ** transfered using the X_GLXRender protocol request. First
326 ** constrain by a software limit, then constrain by the protocl
327 ** limit.
328 */
329 if (bufSize > __GLX_RENDER_CMD_SIZE_LIMIT) {
330 bufSize = __GLX_RENDER_CMD_SIZE_LIMIT;
331 }
332 if (bufSize > __GLX_MAX_RENDER_CMD_SIZE) {
333 bufSize = __GLX_MAX_RENDER_CMD_SIZE;
334 }
335 gc->maxSmallRenderCommandSize = bufSize;
336 return gc;
337 }
338
339
340 /**
341 * Create a new context. Exactly one of \c vis and \c fbconfig should be
342 * non-NULL.
343 *
344 * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or
345 * SGIX_fbconfig protocol be used?
346 * \param renderType For FBConfigs, what is the rendering type?
347 */
348
349 static GLXContext
350 CreateContext(Display *dpy, XVisualInfo *vis,
351 const __GLcontextModes * const fbconfig,
352 GLXContext shareList,
353 Bool allowDirect, GLXContextID contextID,
354 Bool use_glx_1_3, int renderType)
355 {
356 GLXContext gc;
357 #ifdef GLX_DIRECT_RENDERING
358 int screen = (fbconfig == NULL) ? vis->screen : fbconfig->screen;
359 __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen);
360 #endif
361
362 if ( dpy == NULL )
363 return NULL;
364
365 gc = AllocateGLXContext(dpy);
366 if (!gc)
367 return NULL;
368
369 if (None == contextID) {
370 if ( (vis == NULL) && (fbconfig == NULL) )
371 return NULL;
372
373 #ifdef GLX_DIRECT_RENDERING
374 if (allowDirect && psc->driScreen) {
375 const __GLcontextModes * mode;
376
377 if (fbconfig == NULL) {
378 mode = _gl_context_modes_find_visual(psc->visuals, vis->visualid);
379 if (mode == NULL) {
380 xError error;
381
382 error.errorCode = BadValue;
383 error.resourceID = vis->visualid;
384 error.sequenceNumber = dpy->request;
385 error.type = X_Error;
386 error.majorCode = gc->majorOpcode;
387 error.minorCode = X_GLXCreateContext;
388 _XError(dpy, &error);
389 return None;
390 }
391 }
392 else {
393 mode = fbconfig;
394 }
395
396 gc->driContext = psc->driScreen->createContext(psc, mode, gc,
397 shareList,
398 renderType);
399 if (gc->driContext != NULL) {
400 gc->screen = mode->screen;
401 gc->psc = psc;
402 gc->mode = mode;
403 gc->isDirect = GL_TRUE;
404 }
405 }
406 #endif
407
408 LockDisplay(dpy);
409 if ( fbconfig == NULL ) {
410 xGLXCreateContextReq *req;
411
412 /* Send the glXCreateContext request */
413 GetReq(GLXCreateContext,req);
414 req->reqType = gc->majorOpcode;
415 req->glxCode = X_GLXCreateContext;
416 req->context = gc->xid = XAllocID(dpy);
417 req->visual = vis->visualid;
418 req->screen = vis->screen;
419 req->shareList = shareList ? shareList->xid : None;
420 #ifdef GLX_DIRECT_RENDERING
421 req->isDirect = gc->driContext != NULL;
422 #else
423 req->isDirect = 0;
424 #endif
425 }
426 else if ( use_glx_1_3 ) {
427 xGLXCreateNewContextReq *req;
428
429 /* Send the glXCreateNewContext request */
430 GetReq(GLXCreateNewContext,req);
431 req->reqType = gc->majorOpcode;
432 req->glxCode = X_GLXCreateNewContext;
433 req->context = gc->xid = XAllocID(dpy);
434 req->fbconfig = fbconfig->fbconfigID;
435 req->screen = fbconfig->screen;
436 req->renderType = renderType;
437 req->shareList = shareList ? shareList->xid : None;
438 #ifdef GLX_DIRECT_RENDERING
439 req->isDirect = gc->driContext != NULL;
440 #else
441 req->isDirect = 0;
442 #endif
443 }
444 else {
445 xGLXVendorPrivateWithReplyReq *vpreq;
446 xGLXCreateContextWithConfigSGIXReq *req;
447
448 /* Send the glXCreateNewContext request */
449 GetReqExtra(GLXVendorPrivateWithReply,
450 sz_xGLXCreateContextWithConfigSGIXReq-sz_xGLXVendorPrivateWithReplyReq,vpreq);
451 req = (xGLXCreateContextWithConfigSGIXReq *)vpreq;
452 req->reqType = gc->majorOpcode;
453 req->glxCode = X_GLXVendorPrivateWithReply;
454 req->vendorCode = X_GLXvop_CreateContextWithConfigSGIX;
455 req->context = gc->xid = XAllocID(dpy);
456 req->fbconfig = fbconfig->fbconfigID;
457 req->screen = fbconfig->screen;
458 req->renderType = renderType;
459 req->shareList = shareList ? shareList->xid : None;
460 #ifdef GLX_DIRECT_RENDERING
461 req->isDirect = gc->driContext != NULL;
462 #else
463 req->isDirect = 0;
464 #endif
465 }
466
467 UnlockDisplay(dpy);
468 SyncHandle();
469 gc->imported = GL_FALSE;
470 }
471 else {
472 gc->xid = contextID;
473 gc->imported = GL_TRUE;
474 }
475
476 return gc;
477 }
478
479 PUBLIC GLXContext glXCreateContext(Display *dpy, XVisualInfo *vis,
480 GLXContext shareList, Bool allowDirect)
481 {
482 return CreateContext(dpy, vis, NULL, shareList, allowDirect, None,
483 False, 0);
484 }
485
486 _X_HIDDEN void __glXFreeContext(__GLXcontext *gc)
487 {
488 if (gc->vendor) XFree((char *) gc->vendor);
489 if (gc->renderer) XFree((char *) gc->renderer);
490 if (gc->version) XFree((char *) gc->version);
491 if (gc->extensions) XFree((char *) gc->extensions);
492 __glFreeAttributeState(gc);
493 XFree((char *) gc->buf);
494 Xfree((char *) gc->client_state_private);
495 XFree((char *) gc);
496
497 }
498
499 /*
500 ** Destroy the named context
501 */
502 static void
503 DestroyContext(Display *dpy, GLXContext gc)
504 {
505 xGLXDestroyContextReq *req;
506 GLXContextID xid;
507 CARD8 opcode;
508 GLboolean imported;
509
510 opcode = __glXSetupForCommand(dpy);
511 if (!opcode || !gc) {
512 return;
513 }
514
515 __glXLock();
516 xid = gc->xid;
517 imported = gc->imported;
518 gc->xid = None;
519
520 #ifdef GLX_DIRECT_RENDERING
521 /* Destroy the direct rendering context */
522 if (gc->driContext) {
523 (*gc->driContext->destroyContext)(gc->driContext, gc->psc, dpy);
524 gc->driContext = NULL;
525 GarbageCollectDRIDrawables(dpy, gc->psc);
526 }
527 #endif
528
529 __glXFreeVertexArrayState(gc);
530
531 if (gc->currentDpy) {
532 /* Have to free later cuz it's in use now */
533 __glXUnlock();
534 } else {
535 /* Destroy the handle if not current to anybody */
536 __glXUnlock();
537 __glXFreeContext(gc);
538 }
539
540 if (!imported) {
541 /*
542 ** This dpy also created the server side part of the context.
543 ** Send the glXDestroyContext request.
544 */
545 LockDisplay(dpy);
546 GetReq(GLXDestroyContext,req);
547 req->reqType = opcode;
548 req->glxCode = X_GLXDestroyContext;
549 req->context = xid;
550 UnlockDisplay(dpy);
551 SyncHandle();
552 }
553 }
554
555 PUBLIC void glXDestroyContext(Display *dpy, GLXContext gc)
556 {
557 DestroyContext(dpy, gc);
558 }
559
560 /*
561 ** Return the major and minor version #s for the GLX extension
562 */
563 PUBLIC Bool glXQueryVersion(Display *dpy, int *major, int *minor)
564 {
565 __GLXdisplayPrivate *priv;
566
567 /* Init the extension. This fetches the major and minor version. */
568 priv = __glXInitialize(dpy);
569 if (!priv) return GL_FALSE;
570
571 if (major) *major = priv->majorVersion;
572 if (minor) *minor = priv->minorVersion;
573 return GL_TRUE;
574 }
575
576 /*
577 ** Query the existance of the GLX extension
578 */
579 PUBLIC Bool glXQueryExtension(Display *dpy, int *errorBase, int *eventBase)
580 {
581 int major_op, erb, evb;
582 Bool rv;
583
584 rv = XQueryExtension(dpy, GLX_EXTENSION_NAME, &major_op, &evb, &erb);
585 if (rv) {
586 if (errorBase) *errorBase = erb;
587 if (eventBase) *eventBase = evb;
588 }
589 return rv;
590 }
591
592 /*
593 ** Put a barrier in the token stream that forces the GL to finish its
594 ** work before X can proceed.
595 */
596 PUBLIC void glXWaitGL(void)
597 {
598 xGLXWaitGLReq *req;
599 GLXContext gc = __glXGetCurrentContext();
600 Display *dpy = gc->currentDpy;
601
602 if (!dpy) return;
603
604 /* Flush any pending commands out */
605 __glXFlushRenderBuffer(gc, gc->pc);
606
607 #ifdef GLX_DIRECT_RENDERING
608 if (gc->driContext) {
609 /* This bit of ugliness unwraps the glFinish function */
610 #ifdef glFinish
611 #undef glFinish
612 #endif
613 glFinish();
614 return;
615 }
616 #endif
617
618 /* Send the glXWaitGL request */
619 LockDisplay(dpy);
620 GetReq(GLXWaitGL,req);
621 req->reqType = gc->majorOpcode;
622 req->glxCode = X_GLXWaitGL;
623 req->contextTag = gc->currentContextTag;
624 UnlockDisplay(dpy);
625 SyncHandle();
626 }
627
628 /*
629 ** Put a barrier in the token stream that forces X to finish its
630 ** work before GL can proceed.
631 */
632 PUBLIC void glXWaitX(void)
633 {
634 xGLXWaitXReq *req;
635 GLXContext gc = __glXGetCurrentContext();
636 Display *dpy = gc->currentDpy;
637
638 if (!dpy) return;
639
640 /* Flush any pending commands out */
641 __glXFlushRenderBuffer(gc, gc->pc);
642
643 #ifdef GLX_DIRECT_RENDERING
644 if (gc->driContext) {
645 XSync(dpy, False);
646 return;
647 }
648 #endif
649
650 /*
651 ** Send the glXWaitX request.
652 */
653 LockDisplay(dpy);
654 GetReq(GLXWaitX,req);
655 req->reqType = gc->majorOpcode;
656 req->glxCode = X_GLXWaitX;
657 req->contextTag = gc->currentContextTag;
658 UnlockDisplay(dpy);
659 SyncHandle();
660 }
661
662 PUBLIC void glXUseXFont(Font font, int first, int count, int listBase)
663 {
664 xGLXUseXFontReq *req;
665 GLXContext gc = __glXGetCurrentContext();
666 Display *dpy = gc->currentDpy;
667
668 if (!dpy) return;
669
670 /* Flush any pending commands out */
671 (void) __glXFlushRenderBuffer(gc, gc->pc);
672
673 #ifdef GLX_DIRECT_RENDERING
674 if (gc->driContext) {
675 DRI_glXUseXFont(font, first, count, listBase);
676 return;
677 }
678 #endif
679
680 /* Send the glXUseFont request */
681 LockDisplay(dpy);
682 GetReq(GLXUseXFont,req);
683 req->reqType = gc->majorOpcode;
684 req->glxCode = X_GLXUseXFont;
685 req->contextTag = gc->currentContextTag;
686 req->font = font;
687 req->first = first;
688 req->count = count;
689 req->listBase = listBase;
690 UnlockDisplay(dpy);
691 SyncHandle();
692 }
693
694 /************************************************************************/
695
696 /*
697 ** Copy the source context to the destination context using the
698 ** attribute "mask".
699 */
700 PUBLIC void glXCopyContext(Display *dpy, GLXContext source,
701 GLXContext dest, unsigned long mask)
702 {
703 xGLXCopyContextReq *req;
704 GLXContext gc = __glXGetCurrentContext();
705 GLXContextTag tag;
706 CARD8 opcode;
707
708 opcode = __glXSetupForCommand(dpy);
709 if (!opcode) {
710 return;
711 }
712
713 #ifdef GLX_DIRECT_RENDERING
714 if (gc->driContext) {
715 /* NOT_DONE: This does not work yet */
716 }
717 #endif
718
719 /*
720 ** If the source is the current context, send its tag so that the context
721 ** can be flushed before the copy.
722 */
723 if (source == gc && dpy == gc->currentDpy) {
724 tag = gc->currentContextTag;
725 } else {
726 tag = 0;
727 }
728
729 /* Send the glXCopyContext request */
730 LockDisplay(dpy);
731 GetReq(GLXCopyContext,req);
732 req->reqType = opcode;
733 req->glxCode = X_GLXCopyContext;
734 req->source = source ? source->xid : None;
735 req->dest = dest ? dest->xid : None;
736 req->mask = mask;
737 req->contextTag = tag;
738 UnlockDisplay(dpy);
739 SyncHandle();
740 }
741
742
743 /**
744 * Determine if a context uses direct rendering.
745 *
746 * \param dpy Display where the context was created.
747 * \param contextID ID of the context to be tested.
748 *
749 * \returns \c GL_TRUE if the context is direct rendering or not.
750 */
751 static Bool __glXIsDirect(Display *dpy, GLXContextID contextID)
752 {
753 xGLXIsDirectReq *req;
754 xGLXIsDirectReply reply;
755 CARD8 opcode;
756
757 opcode = __glXSetupForCommand(dpy);
758 if (!opcode) {
759 return GL_FALSE;
760 }
761
762 /* Send the glXIsDirect request */
763 LockDisplay(dpy);
764 GetReq(GLXIsDirect,req);
765 req->reqType = opcode;
766 req->glxCode = X_GLXIsDirect;
767 req->context = contextID;
768 _XReply(dpy, (xReply*) &reply, 0, False);
769 UnlockDisplay(dpy);
770 SyncHandle();
771
772 return reply.isDirect;
773 }
774
775 /**
776 * \todo
777 * Shouldn't this function \b always return \c GL_FALSE when
778 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
779 * the GLX protocol here at all?
780 */
781 PUBLIC Bool glXIsDirect(Display *dpy, GLXContext gc)
782 {
783 if (!gc) {
784 return GL_FALSE;
785 #ifdef GLX_DIRECT_RENDERING
786 } else if (gc->driContext) {
787 return GL_TRUE;
788 #endif
789 }
790 return __glXIsDirect(dpy, gc->xid);
791 }
792
793 PUBLIC GLXPixmap glXCreateGLXPixmap(Display *dpy, XVisualInfo *vis,
794 Pixmap pixmap)
795 {
796 xGLXCreateGLXPixmapReq *req;
797 GLXPixmap xid;
798 CARD8 opcode;
799
800 opcode = __glXSetupForCommand(dpy);
801 if (!opcode) {
802 return None;
803 }
804
805 /* Send the glXCreateGLXPixmap request */
806 LockDisplay(dpy);
807 GetReq(GLXCreateGLXPixmap,req);
808 req->reqType = opcode;
809 req->glxCode = X_GLXCreateGLXPixmap;
810 req->screen = vis->screen;
811 req->visual = vis->visualid;
812 req->pixmap = pixmap;
813 req->glxpixmap = xid = XAllocID(dpy);
814 UnlockDisplay(dpy);
815 SyncHandle();
816 return xid;
817 }
818
819 /*
820 ** Destroy the named pixmap
821 */
822 PUBLIC void glXDestroyGLXPixmap(Display *dpy, GLXPixmap glxpixmap)
823 {
824 xGLXDestroyGLXPixmapReq *req;
825 CARD8 opcode;
826
827 opcode = __glXSetupForCommand(dpy);
828 if (!opcode) {
829 return;
830 }
831
832 /* Send the glXDestroyGLXPixmap request */
833 LockDisplay(dpy);
834 GetReq(GLXDestroyGLXPixmap,req);
835 req->reqType = opcode;
836 req->glxCode = X_GLXDestroyGLXPixmap;
837 req->glxpixmap = glxpixmap;
838 UnlockDisplay(dpy);
839 SyncHandle();
840 }
841
842 PUBLIC void glXSwapBuffers(Display *dpy, GLXDrawable drawable)
843 {
844 xGLXSwapBuffersReq *req;
845 GLXContext gc;
846 GLXContextTag tag;
847 CARD8 opcode;
848 #ifdef GLX_DIRECT_RENDERING
849 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, NULL);
850
851 if (pdraw != NULL) {
852 glFlush();
853 (*pdraw->psc->driScreen->swapBuffers)(pdraw);
854 return;
855 }
856 #endif
857
858 opcode = __glXSetupForCommand(dpy);
859 if (!opcode) {
860 return;
861 }
862
863 /*
864 ** The calling thread may or may not have a current context. If it
865 ** does, send the context tag so the server can do a flush.
866 */
867 gc = __glXGetCurrentContext();
868 if ((gc != NULL) && (dpy == gc->currentDpy) &&
869 ((drawable == gc->currentDrawable) || (drawable == gc->currentReadable)) ) {
870 tag = gc->currentContextTag;
871 } else {
872 tag = 0;
873 }
874
875 /* Send the glXSwapBuffers request */
876 LockDisplay(dpy);
877 GetReq(GLXSwapBuffers,req);
878 req->reqType = opcode;
879 req->glxCode = X_GLXSwapBuffers;
880 req->drawable = drawable;
881 req->contextTag = tag;
882 UnlockDisplay(dpy);
883 SyncHandle();
884 XFlush(dpy);
885 }
886
887
888 /*
889 ** Return configuration information for the given display, screen and
890 ** visual combination.
891 */
892 PUBLIC int glXGetConfig(Display *dpy, XVisualInfo *vis, int attribute,
893 int *value_return)
894 {
895 __GLXdisplayPrivate *priv;
896 __GLXscreenConfigs *psc;
897 __GLcontextModes *modes;
898 int status;
899
900 status = GetGLXPrivScreenConfig( dpy, vis->screen, & priv, & psc );
901 if ( status == Success ) {
902 modes = _gl_context_modes_find_visual(psc->visuals, vis->visualid);
903
904 /* Lookup attribute after first finding a match on the visual */
905 if ( modes != NULL ) {
906 return _gl_get_context_mode_data( modes, attribute, value_return );
907 }
908
909 status = GLX_BAD_VISUAL;
910 }
911
912 /*
913 ** If we can't find the config for this visual, this visual is not
914 ** supported by the OpenGL implementation on the server.
915 */
916 if ( (status == GLX_BAD_VISUAL) && (attribute == GLX_USE_GL) ) {
917 *value_return = GL_FALSE;
918 status = Success;
919 }
920
921 return status;
922 }
923
924 /************************************************************************/
925
926 static void
927 init_fbconfig_for_chooser( __GLcontextModes * config,
928 GLboolean fbconfig_style_tags )
929 {
930 memset( config, 0, sizeof( __GLcontextModes ) );
931 config->visualID = (XID) GLX_DONT_CARE;
932 config->visualType = GLX_DONT_CARE;
933
934 /* glXChooseFBConfig specifies different defaults for these two than
935 * glXChooseVisual.
936 */
937 if ( fbconfig_style_tags ) {
938 config->rgbMode = GL_TRUE;
939 config->doubleBufferMode = GLX_DONT_CARE;
940 }
941
942 config->visualRating = GLX_DONT_CARE;
943 config->transparentPixel = GLX_NONE;
944 config->transparentRed = GLX_DONT_CARE;
945 config->transparentGreen = GLX_DONT_CARE;
946 config->transparentBlue = GLX_DONT_CARE;
947 config->transparentAlpha = GLX_DONT_CARE;
948 config->transparentIndex = GLX_DONT_CARE;
949
950 config->drawableType = GLX_WINDOW_BIT;
951 config->renderType = (config->rgbMode) ? GLX_RGBA_BIT : GLX_COLOR_INDEX_BIT;
952 config->xRenderable = GLX_DONT_CARE;
953 config->fbconfigID = (GLXFBConfigID)(GLX_DONT_CARE);
954
955 config->swapMethod = GLX_DONT_CARE;
956 }
957
958 #define MATCH_DONT_CARE( param ) \
959 do { \
960 if ( (a-> param != GLX_DONT_CARE) \
961 && (a-> param != b-> param) ) { \
962 return False; \
963 } \
964 } while ( 0 )
965
966 #define MATCH_MINIMUM( param ) \
967 do { \
968 if ( (a-> param != GLX_DONT_CARE) \
969 && (a-> param > b-> param) ) { \
970 return False; \
971 } \
972 } while ( 0 )
973
974 #define MATCH_EXACT( param ) \
975 do { \
976 if ( a-> param != b-> param) { \
977 return False; \
978 } \
979 } while ( 0 )
980
981 /**
982 * Determine if two GLXFBConfigs are compatible.
983 *
984 * \param a Application specified config to test.
985 * \param b Server specified config to test against \c a.
986 */
987 static Bool
988 fbconfigs_compatible( const __GLcontextModes * const a,
989 const __GLcontextModes * const b )
990 {
991 MATCH_DONT_CARE( doubleBufferMode );
992 MATCH_DONT_CARE( visualType );
993 MATCH_DONT_CARE( visualRating );
994 MATCH_DONT_CARE( xRenderable );
995 MATCH_DONT_CARE( fbconfigID );
996 MATCH_DONT_CARE( swapMethod );
997
998 MATCH_MINIMUM( rgbBits );
999 MATCH_MINIMUM( numAuxBuffers );
1000 MATCH_MINIMUM( redBits );
1001 MATCH_MINIMUM( greenBits );
1002 MATCH_MINIMUM( blueBits );
1003 MATCH_MINIMUM( alphaBits );
1004 MATCH_MINIMUM( depthBits );
1005 MATCH_MINIMUM( stencilBits );
1006 MATCH_MINIMUM( accumRedBits );
1007 MATCH_MINIMUM( accumGreenBits );
1008 MATCH_MINIMUM( accumBlueBits );
1009 MATCH_MINIMUM( accumAlphaBits );
1010 MATCH_MINIMUM( sampleBuffers );
1011 MATCH_MINIMUM( maxPbufferWidth );
1012 MATCH_MINIMUM( maxPbufferHeight );
1013 MATCH_MINIMUM( maxPbufferPixels );
1014 MATCH_MINIMUM( samples );
1015
1016 MATCH_DONT_CARE( stereoMode );
1017 MATCH_EXACT( level );
1018
1019 if ( ((a->drawableType & b->drawableType) == 0)
1020 || ((a->renderType & b->renderType) == 0) ) {
1021 return False;
1022 }
1023
1024
1025 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1026 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1027 * Technically speaking, it is a bug in the DDX driver, but there is
1028 * enough of an installed base to work around the problem here. In any
1029 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1030 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1031 * 0 from the server to be a match to maintain backward compatibility with
1032 * the (broken) drivers.
1033 */
1034
1035 if ( a->transparentPixel != GLX_DONT_CARE
1036 && a->transparentPixel != 0 ) {
1037 if ( a->transparentPixel == GLX_NONE ) {
1038 if ( b->transparentPixel != GLX_NONE && b->transparentPixel != 0 )
1039 return False;
1040 } else {
1041 MATCH_EXACT( transparentPixel );
1042 }
1043
1044 switch ( a->transparentPixel ) {
1045 case GLX_TRANSPARENT_RGB:
1046 MATCH_DONT_CARE( transparentRed );
1047 MATCH_DONT_CARE( transparentGreen );
1048 MATCH_DONT_CARE( transparentBlue );
1049 MATCH_DONT_CARE( transparentAlpha );
1050 break;
1051
1052 case GLX_TRANSPARENT_INDEX:
1053 MATCH_DONT_CARE( transparentIndex );
1054 break;
1055
1056 default:
1057 break;
1058 }
1059 }
1060
1061 return True;
1062 }
1063
1064
1065 /* There's some trickly language in the GLX spec about how this is supposed
1066 * to work. Basically, if a given component size is either not specified
1067 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1068 * Well, that's really hard to do with the code as-is. This behavior is
1069 * closer to correct, but still not technically right.
1070 */
1071 #define PREFER_LARGER_OR_ZERO(comp) \
1072 do { \
1073 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1074 if ( ((*a)-> comp) == 0 ) { \
1075 return -1; \
1076 } \
1077 else if ( ((*b)-> comp) == 0 ) { \
1078 return 1; \
1079 } \
1080 else { \
1081 return ((*b)-> comp) - ((*a)-> comp) ; \
1082 } \
1083 } \
1084 } while( 0 )
1085
1086 #define PREFER_LARGER(comp) \
1087 do { \
1088 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1089 return ((*b)-> comp) - ((*a)-> comp) ; \
1090 } \
1091 } while( 0 )
1092
1093 #define PREFER_SMALLER(comp) \
1094 do { \
1095 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1096 return ((*a)-> comp) - ((*b)-> comp) ; \
1097 } \
1098 } while( 0 )
1099
1100 /**
1101 * Compare two GLXFBConfigs. This function is intended to be used as the
1102 * compare function passed in to qsort.
1103 *
1104 * \returns If \c a is a "better" config, according to the specification of
1105 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1106 * better, then a number greater than zero is return. If both are
1107 * equal, zero is returned.
1108 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1109 */
1110 static int
1111 fbconfig_compare( const __GLcontextModes * const * const a,
1112 const __GLcontextModes * const * const b )
1113 {
1114 /* The order of these comparisons must NOT change. It is defined by
1115 * the GLX 1.3 spec and ARB_multisample.
1116 */
1117
1118 PREFER_SMALLER( visualSelectGroup );
1119
1120 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1121 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1122 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1123 */
1124 PREFER_SMALLER( visualRating );
1125
1126 /* This isn't quite right. It is supposed to compare the sum of the
1127 * components the user specifically set minimums for.
1128 */
1129 PREFER_LARGER_OR_ZERO( redBits );
1130 PREFER_LARGER_OR_ZERO( greenBits );
1131 PREFER_LARGER_OR_ZERO( blueBits );
1132 PREFER_LARGER_OR_ZERO( alphaBits );
1133
1134 PREFER_SMALLER( rgbBits );
1135
1136 if ( ((*a)->doubleBufferMode != (*b)->doubleBufferMode) ) {
1137 /* Prefer single-buffer.
1138 */
1139 return ( !(*a)->doubleBufferMode ) ? -1 : 1;
1140 }
1141
1142 PREFER_SMALLER( numAuxBuffers );
1143
1144 PREFER_LARGER_OR_ZERO( depthBits );
1145 PREFER_SMALLER( stencilBits );
1146
1147 /* This isn't quite right. It is supposed to compare the sum of the
1148 * components the user specifically set minimums for.
1149 */
1150 PREFER_LARGER_OR_ZERO( accumRedBits );
1151 PREFER_LARGER_OR_ZERO( accumGreenBits );
1152 PREFER_LARGER_OR_ZERO( accumBlueBits );
1153 PREFER_LARGER_OR_ZERO( accumAlphaBits );
1154
1155 PREFER_SMALLER( visualType );
1156
1157 /* None of the multisample specs say where this comparison should happen,
1158 * so I put it near the end.
1159 */
1160 PREFER_SMALLER( sampleBuffers );
1161 PREFER_SMALLER( samples );
1162
1163 /* None of the pbuffer or fbconfig specs say that this comparison needs
1164 * to happen at all, but it seems like it should.
1165 */
1166 PREFER_LARGER( maxPbufferWidth );
1167 PREFER_LARGER( maxPbufferHeight );
1168 PREFER_LARGER( maxPbufferPixels );
1169
1170 return 0;
1171 }
1172
1173
1174 /**
1175 * Selects and sorts a subset of the supplied configs based on the attributes.
1176 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1177 * and \c glXChooseFBConfigSGIX.
1178 *
1179 * \param configs Array of pointers to possible configs. The elements of
1180 * this array that do not meet the criteria will be set to
1181 * NULL. The remaining elements will be sorted according to
1182 * the various visual / FBConfig selection rules.
1183 * \param num_configs Number of elements in the \c configs array.
1184 * \param attribList Attributes used select from \c configs. This array is
1185 * terminated by a \c None tag. The array can either take
1186 * the form expected by \c glXChooseVisual (where boolean
1187 * tags do not have a value) or by \c glXChooseFBConfig
1188 * (where every tag has a value).
1189 * \param fbconfig_style_tags Selects whether \c attribList is in
1190 * \c glXChooseVisual style or
1191 * \c glXChooseFBConfig style.
1192 * \returns The number of valid elements left in \c configs.
1193 *
1194 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1195 */
1196 static int
1197 choose_visual( __GLcontextModes ** configs, int num_configs,
1198 const int *attribList, GLboolean fbconfig_style_tags )
1199 {
1200 __GLcontextModes test_config;
1201 int base;
1202 int i;
1203
1204 /* This is a fairly direct implementation of the selection method
1205 * described by GLX_SGIX_fbconfig. Start by culling out all the
1206 * configs that are not compatible with the selected parameter
1207 * list.
1208 */
1209
1210 init_fbconfig_for_chooser( & test_config, fbconfig_style_tags );
1211 __glXInitializeVisualConfigFromTags( & test_config, 512,
1212 (const INT32 *) attribList,
1213 GL_TRUE, fbconfig_style_tags );
1214
1215 base = 0;
1216 for ( i = 0 ; i < num_configs ; i++ ) {
1217 if ( fbconfigs_compatible( & test_config, configs[i] ) ) {
1218 configs[ base ] = configs[ i ];
1219 base++;
1220 }
1221 }
1222
1223 if ( base == 0 ) {
1224 return 0;
1225 }
1226
1227 if ( base < num_configs ) {
1228 (void) memset( & configs[ base ], 0,
1229 sizeof( void * ) * (num_configs - base) );
1230 }
1231
1232 /* After the incompatible configs are removed, the resulting
1233 * list is sorted according to the rules set out in the various
1234 * specifications.
1235 */
1236
1237 qsort( configs, base, sizeof( __GLcontextModes * ),
1238 (int (*)(const void*, const void*)) fbconfig_compare );
1239 return base;
1240 }
1241
1242
1243
1244
1245 /*
1246 ** Return the visual that best matches the template. Return None if no
1247 ** visual matches the template.
1248 */
1249 PUBLIC XVisualInfo *glXChooseVisual(Display *dpy, int screen, int *attribList)
1250 {
1251 XVisualInfo *visualList = NULL;
1252 __GLXdisplayPrivate *priv;
1253 __GLXscreenConfigs *psc;
1254 __GLcontextModes test_config;
1255 __GLcontextModes *modes;
1256 const __GLcontextModes *best_config = NULL;
1257
1258 /*
1259 ** Get a list of all visuals, return if list is empty
1260 */
1261 if ( GetGLXPrivScreenConfig( dpy, screen, & priv, & psc ) != Success ) {
1262 return None;
1263 }
1264
1265
1266 /*
1267 ** Build a template from the defaults and the attribute list
1268 ** Free visual list and return if an unexpected token is encountered
1269 */
1270 init_fbconfig_for_chooser( & test_config, GL_FALSE );
1271 __glXInitializeVisualConfigFromTags( & test_config, 512,
1272 (const INT32 *) attribList,
1273 GL_TRUE, GL_FALSE );
1274
1275 /*
1276 ** Eliminate visuals that don't meet minimum requirements
1277 ** Compute a score for those that do
1278 ** Remember which visual, if any, got the highest score
1279 */
1280 for ( modes = psc->visuals ; modes != NULL ; modes = modes->next ) {
1281 if ( fbconfigs_compatible( & test_config, modes )
1282 && ((best_config == NULL)
1283 || (fbconfig_compare( (const __GLcontextModes * const * const)&modes, &best_config ) < 0)) ) {
1284 best_config = modes;
1285 }
1286 }
1287
1288 /*
1289 ** If no visual is acceptable, return None
1290 ** Otherwise, create an XVisualInfo list with just the selected X visual
1291 ** and return this.
1292 */
1293 if (best_config != NULL) {
1294 XVisualInfo visualTemplate;
1295 int i;
1296
1297 visualTemplate.screen = screen;
1298 visualTemplate.visualid = best_config->visualID;
1299 visualList = XGetVisualInfo( dpy, VisualScreenMask|VisualIDMask,
1300 &visualTemplate, &i );
1301 }
1302
1303 return visualList;
1304 }
1305
1306
1307 PUBLIC const char *glXQueryExtensionsString( Display *dpy, int screen )
1308 {
1309 __GLXscreenConfigs *psc;
1310 __GLXdisplayPrivate *priv;
1311
1312 if ( GetGLXPrivScreenConfig( dpy, screen, & priv, & psc ) != Success ) {
1313 return NULL;
1314 }
1315
1316 if (!psc->effectiveGLXexts) {
1317 if (!psc->serverGLXexts) {
1318 psc->serverGLXexts = __glXGetStringFromServer(dpy, priv->majorOpcode,
1319 X_GLXQueryServerString,
1320 screen, GLX_EXTENSIONS);
1321 }
1322
1323 __glXCalculateUsableExtensions(psc,
1324 #ifdef GLX_DIRECT_RENDERING
1325 (psc->driScreen != NULL),
1326 #else
1327 GL_FALSE,
1328 #endif
1329 priv->minorVersion);
1330 }
1331
1332 return psc->effectiveGLXexts;
1333 }
1334
1335 PUBLIC const char *glXGetClientString( Display *dpy, int name )
1336 {
1337 switch(name) {
1338 case GLX_VENDOR:
1339 return (__glXGLXClientVendorName);
1340 case GLX_VERSION:
1341 return (__glXGLXClientVersion);
1342 case GLX_EXTENSIONS:
1343 return (__glXGetClientExtensions());
1344 default:
1345 return NULL;
1346 }
1347 }
1348
1349 PUBLIC const char *glXQueryServerString( Display *dpy, int screen, int name )
1350 {
1351 __GLXscreenConfigs *psc;
1352 __GLXdisplayPrivate *priv;
1353 const char ** str;
1354
1355
1356 if ( GetGLXPrivScreenConfig( dpy, screen, & priv, & psc ) != Success ) {
1357 return NULL;
1358 }
1359
1360 switch(name) {
1361 case GLX_VENDOR:
1362 str = & priv->serverGLXvendor;
1363 break;
1364 case GLX_VERSION:
1365 str = & priv->serverGLXversion;
1366 break;
1367 case GLX_EXTENSIONS:
1368 str = & psc->serverGLXexts;
1369 break;
1370 default:
1371 return NULL;
1372 }
1373
1374 if ( *str == NULL ) {
1375 *str = __glXGetStringFromServer(dpy, priv->majorOpcode,
1376 X_GLXQueryServerString, screen, name);
1377 }
1378
1379 return *str;
1380 }
1381
1382 void __glXClientInfo ( Display *dpy, int opcode )
1383 {
1384 xGLXClientInfoReq *req;
1385 int size;
1386 char * ext_str = __glXGetClientGLExtensionString();
1387
1388 /* Send the glXClientInfo request */
1389 LockDisplay(dpy);
1390 GetReq(GLXClientInfo,req);
1391 req->reqType = opcode;
1392 req->glxCode = X_GLXClientInfo;
1393 req->major = GLX_MAJOR_VERSION;
1394 req->minor = GLX_MINOR_VERSION;
1395
1396 size = strlen( ext_str ) + 1;
1397 req->length += (size + 3) >> 2;
1398 req->numbytes = size;
1399 Data(dpy, ext_str, size);
1400
1401 UnlockDisplay(dpy);
1402 SyncHandle();
1403
1404 Xfree( ext_str );
1405 }
1406
1407
1408 /*
1409 ** EXT_import_context
1410 */
1411
1412 PUBLIC Display *glXGetCurrentDisplay(void)
1413 {
1414 GLXContext gc = __glXGetCurrentContext();
1415 if (NULL == gc) return NULL;
1416 return gc->currentDpy;
1417 }
1418
1419 PUBLIC GLX_ALIAS(Display *, glXGetCurrentDisplayEXT, (void), (),
1420 glXGetCurrentDisplay)
1421
1422 /**
1423 * Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests
1424 * to the X-server.
1425 *
1426 * \param dpy Display where \c ctx was created.
1427 * \param ctx Context to query.
1428 * \returns \c Success on success. \c GLX_BAD_CONTEXT if \c ctx is invalid,
1429 * or zero if the request failed due to internal problems (i.e.,
1430 * unable to allocate temporary memory, etc.)
1431 *
1432 * \note
1433 * This function dynamically determines whether to use the EXT_import_context
1434 * version of the protocol or the GLX 1.3 version of the protocol.
1435 */
1436 static int __glXQueryContextInfo(Display *dpy, GLXContext ctx)
1437 {
1438 __GLXdisplayPrivate *priv = __glXInitialize(dpy);
1439 xGLXQueryContextReply reply;
1440 CARD8 opcode;
1441 GLuint numValues;
1442 int retval;
1443
1444 if (ctx == NULL) {
1445 return GLX_BAD_CONTEXT;
1446 }
1447 opcode = __glXSetupForCommand(dpy);
1448 if (!opcode) {
1449 return 0;
1450 }
1451
1452 /* Send the glXQueryContextInfoEXT request */
1453 LockDisplay(dpy);
1454
1455 if ( (priv->majorVersion > 1) || (priv->minorVersion >= 3) ) {
1456 xGLXQueryContextReq *req;
1457
1458 GetReq(GLXQueryContext, req);
1459
1460 req->reqType = opcode;
1461 req->glxCode = X_GLXQueryContext;
1462 req->context = (unsigned int)(ctx->xid);
1463 }
1464 else {
1465 xGLXVendorPrivateReq *vpreq;
1466 xGLXQueryContextInfoEXTReq *req;
1467
1468 GetReqExtra( GLXVendorPrivate,
1469 sz_xGLXQueryContextInfoEXTReq - sz_xGLXVendorPrivateReq,
1470 vpreq );
1471 req = (xGLXQueryContextInfoEXTReq *)vpreq;
1472 req->reqType = opcode;
1473 req->glxCode = X_GLXVendorPrivateWithReply;
1474 req->vendorCode = X_GLXvop_QueryContextInfoEXT;
1475 req->context = (unsigned int)(ctx->xid);
1476 }
1477
1478 _XReply(dpy, (xReply*) &reply, 0, False);
1479
1480 numValues = reply.n;
1481 if (numValues == 0)
1482 retval = Success;
1483 else if (numValues > __GLX_MAX_CONTEXT_PROPS)
1484 retval = 0;
1485 else
1486 {
1487 int *propList, *pProp;
1488 int nPropListBytes;
1489 int i;
1490
1491 nPropListBytes = numValues << 3;
1492 propList = (int *) Xmalloc(nPropListBytes);
1493 if (NULL == propList) {
1494 retval = 0;
1495 } else {
1496 _XRead(dpy, (char *)propList, nPropListBytes);
1497 pProp = propList;
1498 for (i=0; i < numValues; i++) {
1499 switch (*pProp++) {
1500 case GLX_SHARE_CONTEXT_EXT:
1501 ctx->share_xid = *pProp++;
1502 break;
1503 case GLX_VISUAL_ID_EXT:
1504 ctx->mode =
1505 _gl_context_modes_find_visual(ctx->psc->visuals, *pProp++);
1506 break;
1507 case GLX_SCREEN:
1508 ctx->screen = *pProp++;
1509 break;
1510 case GLX_FBCONFIG_ID:
1511 ctx->mode =
1512 _gl_context_modes_find_fbconfig(ctx->psc->configs, *pProp++);
1513 break;
1514 case GLX_RENDER_TYPE:
1515 ctx->renderType = *pProp++;
1516 break;
1517 default:
1518 pProp++;
1519 continue;
1520 }
1521 }
1522 Xfree((char *)propList);
1523 retval = Success;
1524 }
1525 }
1526 UnlockDisplay(dpy);
1527 SyncHandle();
1528 return retval;
1529 }
1530
1531 PUBLIC int
1532 glXQueryContext(Display *dpy, GLXContext ctx, int attribute, int *value)
1533 {
1534 int retVal;
1535
1536 /* get the information from the server if we don't have it already */
1537 #ifdef GLX_DIRECT_RENDERING
1538 if (!ctx->driContext && (ctx->mode == NULL)) {
1539 #else
1540 if (ctx->mode == NULL) {
1541 #endif
1542 retVal = __glXQueryContextInfo(dpy, ctx);
1543 if (Success != retVal) return retVal;
1544 }
1545 switch (attribute) {
1546 case GLX_SHARE_CONTEXT_EXT:
1547 *value = (int)(ctx->share_xid);
1548 break;
1549 case GLX_VISUAL_ID_EXT:
1550 *value = ctx->mode ? ctx->mode->visualID : None;
1551 break;
1552 case GLX_SCREEN:
1553 *value = (int)(ctx->screen);
1554 break;
1555 case GLX_FBCONFIG_ID:
1556 *value = ctx->mode ? ctx->mode->fbconfigID : None;
1557 break;
1558 case GLX_RENDER_TYPE:
1559 *value = (int)(ctx->renderType);
1560 break;
1561 default:
1562 return GLX_BAD_ATTRIBUTE;
1563 }
1564 return Success;
1565 }
1566
1567 PUBLIC GLX_ALIAS( int, glXQueryContextInfoEXT,
1568 (Display *dpy, GLXContext ctx, int attribute, int *value),
1569 (dpy, ctx, attribute, value),
1570 glXQueryContext )
1571
1572 PUBLIC GLXContextID glXGetContextIDEXT(const GLXContext ctx)
1573 {
1574 return ctx->xid;
1575 }
1576
1577 PUBLIC GLXContext glXImportContextEXT(Display *dpy, GLXContextID contextID)
1578 {
1579 GLXContext ctx;
1580
1581 if (contextID == None) {
1582 return NULL;
1583 }
1584 if (__glXIsDirect(dpy, contextID)) {
1585 return NULL;
1586 }
1587
1588 ctx = CreateContext(dpy, NULL, NULL, NULL, False, contextID, False, 0);
1589 if (NULL != ctx) {
1590 if (Success != __glXQueryContextInfo(dpy, ctx)) {
1591 return NULL;
1592 }
1593 }
1594 return ctx;
1595 }
1596
1597 PUBLIC void glXFreeContextEXT(Display *dpy, GLXContext ctx)
1598 {
1599 DestroyContext(dpy, ctx);
1600 }
1601
1602
1603
1604 /*
1605 * GLX 1.3 functions - these are just stubs for now!
1606 */
1607
1608 PUBLIC GLXFBConfig *glXChooseFBConfig(Display *dpy, int screen,
1609 const int *attribList, int *nitems)
1610 {
1611 __GLcontextModes ** config_list;
1612 int list_size;
1613
1614
1615 config_list = (__GLcontextModes **)
1616 glXGetFBConfigs( dpy, screen, & list_size );
1617
1618 if ( (config_list != NULL) && (list_size > 0) && (attribList != NULL) ) {
1619 list_size = choose_visual( config_list, list_size, attribList,
1620 GL_TRUE );
1621 if ( list_size == 0 ) {
1622 XFree( config_list );
1623 config_list = NULL;
1624 }
1625 }
1626
1627 *nitems = list_size;
1628 return (GLXFBConfig *) config_list;
1629 }
1630
1631
1632 PUBLIC GLXContext glXCreateNewContext(Display *dpy, GLXFBConfig config,
1633 int renderType, GLXContext shareList,
1634 Bool allowDirect)
1635 {
1636 return CreateContext( dpy, NULL, (__GLcontextModes *) config, shareList,
1637 allowDirect, None, True, renderType );
1638 }
1639
1640
1641 PUBLIC GLXDrawable glXGetCurrentReadDrawable(void)
1642 {
1643 GLXContext gc = __glXGetCurrentContext();
1644 return gc->currentReadable;
1645 }
1646
1647
1648 PUBLIC GLXFBConfig *glXGetFBConfigs(Display *dpy, int screen, int *nelements)
1649 {
1650 __GLXdisplayPrivate *priv = __glXInitialize(dpy);
1651 __GLcontextModes ** config = NULL;
1652 int i;
1653
1654 *nelements = 0;
1655 if ( (priv->screenConfigs != NULL)
1656 && (screen >= 0) && (screen <= ScreenCount(dpy))
1657 && (priv->screenConfigs[screen].configs != NULL)
1658 && (priv->screenConfigs[screen].configs->fbconfigID != GLX_DONT_CARE) ) {
1659 unsigned num_configs = 0;
1660 __GLcontextModes * modes;
1661
1662
1663 for ( modes = priv->screenConfigs[screen].configs
1664 ; modes != NULL
1665 ; modes = modes->next ) {
1666 if ( modes->fbconfigID != GLX_DONT_CARE ) {
1667 num_configs++;
1668 }
1669 }
1670
1671 config = (__GLcontextModes **) Xmalloc( sizeof(__GLcontextModes *)
1672 * num_configs );
1673 if ( config != NULL ) {
1674 *nelements = num_configs;
1675 i = 0;
1676 for ( modes = priv->screenConfigs[screen].configs
1677 ; modes != NULL
1678 ; modes = modes->next ) {
1679 if ( modes->fbconfigID != GLX_DONT_CARE ) {
1680 config[i] = modes;
1681 i++;
1682 }
1683 }
1684 }
1685 }
1686 return (GLXFBConfig *) config;
1687 }
1688
1689
1690 PUBLIC int glXGetFBConfigAttrib(Display *dpy, GLXFBConfig config,
1691 int attribute, int *value)
1692 {
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
1701 PUBLIC XVisualInfo *glXGetVisualFromFBConfig(Display *dpy, GLXFBConfig config)
1702 {
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 /*
1716 ** GLX_SGI_swap_control
1717 */
1718 static int __glXSwapIntervalSGI(int interval)
1719 {
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
1734 #ifdef __DRI_SWAP_CONTROL
1735 if (gc->driContext) {
1736 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy,
1737 gc->screen );
1738 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(gc->currentDpy,
1739 gc->currentDrawable,
1740 NULL);
1741 if (psc->swapControl != NULL && pdraw != NULL) {
1742 psc->swapControl->setSwapInterval(pdraw->driDrawable, interval);
1743 return 0;
1744 }
1745 else {
1746 return GLX_BAD_CONTEXT;
1747 }
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
1764 interval_ptr = (CARD32 *) (req + 1);
1765 *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 */
1778 static int __glXSwapIntervalMESA(unsigned int interval)
1779 {
1780 #ifdef __DRI_SWAP_CONTROL
1781 GLXContext gc = __glXGetCurrentContext();
1782
1783 if ( interval < 0 ) {
1784 return GLX_BAD_VALUE;
1785 }
1786
1787 if (gc != NULL && gc->driContext) {
1788 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy,
1789 gc->screen );
1790
1791 if ( (psc != NULL) && (psc->driScreen != NULL) ) {
1792 __GLXDRIdrawable *pdraw =
1793 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL);
1794 if (psc->swapControl != NULL && pdraw != NULL) {
1795 psc->swapControl->setSwapInterval(pdraw->driDrawable, interval);
1796 return 0;
1797 }
1798 }
1799 }
1800 #else
1801 (void) interval;
1802 #endif
1803
1804 return GLX_BAD_CONTEXT;
1805 }
1806
1807
1808 static int __glXGetSwapIntervalMESA(void)
1809 {
1810 #ifdef __DRI_SWAP_CONTROL
1811 GLXContext gc = __glXGetCurrentContext();
1812
1813 if (gc != NULL && gc->driContext) {
1814 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy,
1815 gc->screen );
1816
1817 if ( (psc != NULL) && (psc->driScreen != NULL) ) {
1818 __GLXDRIdrawable *pdraw =
1819 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL);
1820 if (psc->swapControl != NULL && pdraw != NULL) {
1821 return psc->swapControl->getSwapInterval(pdraw->driDrawable);
1822 }
1823 }
1824 }
1825 #endif
1826
1827 return 0;
1828 }
1829
1830
1831 /*
1832 ** GLX_MESA_swap_frame_usage
1833 */
1834
1835 static GLint __glXBeginFrameTrackingMESA(Display *dpy, GLXDrawable drawable)
1836 {
1837 int status = GLX_BAD_CONTEXT;
1838 #ifdef __DRI_FRAME_TRACKING
1839 int screen;
1840 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen);
1841 __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen);
1842
1843 if (pdraw != NULL && psc->frameTracking != NULL)
1844 status = psc->frameTracking->frameTracking(pdraw->driDrawable, GL_TRUE);
1845 #else
1846 (void) dpy;
1847 (void) drawable;
1848 #endif
1849 return status;
1850 }
1851
1852
1853 static GLint __glXEndFrameTrackingMESA(Display *dpy, GLXDrawable drawable)
1854 {
1855 int status = GLX_BAD_CONTEXT;
1856 #ifdef __DRI_FRAME_TRACKING
1857 int screen;
1858 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, & screen);
1859 __GLXscreenConfigs *psc = GetGLXScreenConfigs(dpy, screen);
1860
1861 if (pdraw != NULL && psc->frameTracking != NULL)
1862 status = psc->frameTracking->frameTracking(pdraw->driDrawable,
1863 GL_FALSE);
1864 #else
1865 (void) dpy;
1866 (void) drawable;
1867 #endif
1868 return status;
1869 }
1870
1871
1872 static GLint __glXGetFrameUsageMESA(Display *dpy, GLXDrawable drawable,
1873 GLfloat *usage)
1874 {
1875 int status = GLX_BAD_CONTEXT;
1876 #ifdef __DRI_FRAME_TRACKING
1877 int screen;
1878 __GLXDRIdrawable * const pdraw = GetGLXDRIDrawable(dpy, drawable, & screen);
1879 __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen);
1880
1881 if (pdraw != NULL && psc->frameTracking != NULL) {
1882 int64_t sbc, missedFrames;
1883 float lastMissedUsage;
1884
1885 status = psc->frameTracking->queryFrameTracking(pdraw->driDrawable,
1886 &sbc,
1887 &missedFrames,
1888 &lastMissedUsage,
1889 usage);
1890 }
1891 #else
1892 (void) dpy;
1893 (void) drawable;
1894 (void) usage;
1895 #endif
1896 return status;
1897 }
1898
1899
1900 static GLint __glXQueryFrameTrackingMESA(Display *dpy, GLXDrawable drawable,
1901 int64_t *sbc, int64_t *missedFrames,
1902 GLfloat *lastMissedUsage)
1903 {
1904 int status = GLX_BAD_CONTEXT;
1905 #ifdef __DRI_FRAME_TRACKING
1906 int screen;
1907 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, & screen);
1908 __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen);
1909
1910 if (pdraw != NULL && psc->frameTracking != NULL) {
1911 float usage;
1912
1913 status = psc->frameTracking->queryFrameTracking(pdraw->driDrawable,
1914 sbc, missedFrames,
1915 lastMissedUsage, &usage);
1916 }
1917 #else
1918 (void) dpy;
1919 (void) drawable;
1920 (void) sbc;
1921 (void) missedFrames;
1922 (void) lastMissedUsage;
1923 #endif
1924 return status;
1925 }
1926
1927
1928 /*
1929 ** GLX_SGI_video_sync
1930 */
1931 static int __glXGetVideoSyncSGI(unsigned int *count)
1932 {
1933 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1934 * FIXME: there should be a GLX encoding for this call. I can find no
1935 * FIXME: documentation for the GLX encoding.
1936 */
1937 #ifdef __DRI_MEDIA_STREAM_COUNTER
1938 GLXContext gc = __glXGetCurrentContext();
1939
1940
1941 if (gc != NULL && gc->driContext) {
1942 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy,
1943 gc->screen );
1944 if ( psc->msc && psc->driScreen ) {
1945 __GLXDRIdrawable *pdraw =
1946 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL);
1947 int64_t temp;
1948 int ret;
1949
1950 ret = (*psc->msc->getDrawableMSC)(psc->__driScreen,
1951 pdraw->driDrawable, &temp);
1952 *count = (unsigned) temp;
1953
1954 return (ret == 0) ? 0 : GLX_BAD_CONTEXT;
1955 }
1956 }
1957 #else
1958 (void) count;
1959 #endif
1960 return GLX_BAD_CONTEXT;
1961 }
1962
1963 static int __glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
1964 {
1965 #ifdef __DRI_MEDIA_STREAM_COUNTER
1966 GLXContext gc = __glXGetCurrentContext();
1967
1968 if ( divisor <= 0 || remainder < 0 )
1969 return GLX_BAD_VALUE;
1970
1971 if (gc != NULL && gc->driContext) {
1972 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( gc->currentDpy,
1973 gc->screen );
1974 if (psc->msc != NULL && psc->driScreen ) {
1975 __GLXDRIdrawable *pdraw =
1976 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable, NULL);
1977 int ret;
1978 int64_t msc;
1979 int64_t sbc;
1980
1981 ret = (*psc->msc->waitForMSC)(pdraw->driDrawable, 0,
1982 divisor, remainder, &msc, &sbc);
1983 *count = (unsigned) msc;
1984 return (ret == 0) ? 0 : GLX_BAD_CONTEXT;
1985 }
1986 }
1987 #else
1988 (void) count;
1989 #endif
1990 return GLX_BAD_CONTEXT;
1991 }
1992
1993
1994 /*
1995 ** GLX_SGIX_fbconfig
1996 ** Many of these functions are aliased to GLX 1.3 entry points in the
1997 ** GLX_functions table.
1998 */
1999
2000 PUBLIC GLX_ALIAS(int, glXGetFBConfigAttribSGIX,
2001 (Display *dpy, GLXFBConfigSGIX config, int attribute, int *value),
2002 (dpy, config, attribute, value),
2003 glXGetFBConfigAttrib)
2004
2005 PUBLIC GLX_ALIAS(GLXFBConfigSGIX *, glXChooseFBConfigSGIX,
2006 (Display *dpy, int screen, int *attrib_list, int *nelements),
2007 (dpy, screen, attrib_list, nelements),
2008 glXChooseFBConfig)
2009
2010 PUBLIC GLX_ALIAS(XVisualInfo *, glXGetVisualFromFBConfigSGIX,
2011 (Display * dpy, GLXFBConfigSGIX config),
2012 (dpy, config),
2013 glXGetVisualFromFBConfig)
2014
2015 PUBLIC GLXPixmap glXCreateGLXPixmapWithConfigSGIX(Display *dpy,
2016 GLXFBConfigSGIX config, Pixmap pixmap)
2017 {
2018 xGLXVendorPrivateWithReplyReq *vpreq;
2019 xGLXCreateGLXPixmapWithConfigSGIXReq *req;
2020 GLXPixmap xid = None;
2021 CARD8 opcode;
2022 const __GLcontextModes * const fbconfig = (__GLcontextModes *) config;
2023 __GLXscreenConfigs * psc;
2024
2025
2026 if ( (dpy == NULL) || (config == NULL) ) {
2027 return None;
2028 }
2029
2030 psc = GetGLXScreenConfigs( dpy, fbconfig->screen );
2031 if ( (psc != NULL)
2032 && __glXExtensionBitIsEnabled( psc, SGIX_fbconfig_bit ) ) {
2033 opcode = __glXSetupForCommand(dpy);
2034 if (!opcode) {
2035 return None;
2036 }
2037
2038 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2039 LockDisplay(dpy);
2040 GetReqExtra(GLXVendorPrivateWithReply,
2041 sz_xGLXCreateGLXPixmapWithConfigSGIXReq-sz_xGLXVendorPrivateWithReplyReq,vpreq);
2042 req = (xGLXCreateGLXPixmapWithConfigSGIXReq *)vpreq;
2043 req->reqType = opcode;
2044 req->glxCode = X_GLXVendorPrivateWithReply;
2045 req->vendorCode = X_GLXvop_CreateGLXPixmapWithConfigSGIX;
2046 req->screen = fbconfig->screen;
2047 req->fbconfig = fbconfig->fbconfigID;
2048 req->pixmap = pixmap;
2049 req->glxpixmap = xid = XAllocID(dpy);
2050 UnlockDisplay(dpy);
2051 SyncHandle();
2052 }
2053
2054 return xid;
2055 }
2056
2057 PUBLIC GLXContext glXCreateContextWithConfigSGIX(Display *dpy,
2058 GLXFBConfigSGIX config, int renderType,
2059 GLXContext shareList, Bool allowDirect)
2060 {
2061 GLXContext gc = NULL;
2062 const __GLcontextModes * const fbconfig = (__GLcontextModes *) config;
2063 __GLXscreenConfigs * psc;
2064
2065
2066 if ( (dpy == NULL) || (config == NULL) ) {
2067 return None;
2068 }
2069
2070 psc = GetGLXScreenConfigs( dpy, fbconfig->screen );
2071 if ( (psc != NULL)
2072 && __glXExtensionBitIsEnabled( psc, SGIX_fbconfig_bit ) ) {
2073 gc = CreateContext( dpy, NULL, (__GLcontextModes *) config, shareList,
2074 allowDirect, None, False, renderType );
2075 }
2076
2077 return gc;
2078 }
2079
2080
2081 PUBLIC GLXFBConfigSGIX glXGetFBConfigFromVisualSGIX(Display *dpy,
2082 XVisualInfo *vis)
2083 {
2084 __GLXdisplayPrivate *priv;
2085 __GLXscreenConfigs *psc;
2086
2087 if ( (GetGLXPrivScreenConfig( dpy, vis->screen, & priv, & psc ) != Success)
2088 && __glXExtensionBitIsEnabled( psc, SGIX_fbconfig_bit )
2089 && (psc->configs->fbconfigID != GLX_DONT_CARE) ) {
2090 return (GLXFBConfigSGIX) _gl_context_modes_find_visual( psc->configs,
2091 vis->visualid );
2092 }
2093
2094 return NULL;
2095 }
2096
2097
2098 /*
2099 ** GLX_SGIX_swap_group
2100 */
2101 static void __glXJoinSwapGroupSGIX(Display *dpy, GLXDrawable drawable,
2102 GLXDrawable member)
2103 {
2104 (void) dpy;
2105 (void) drawable;
2106 (void) member;
2107 }
2108
2109
2110 /*
2111 ** GLX_SGIX_swap_barrier
2112 */
2113 static void __glXBindSwapBarrierSGIX(Display *dpy, GLXDrawable drawable,
2114 int barrier)
2115 {
2116 (void) dpy;
2117 (void) drawable;
2118 (void) barrier;
2119 }
2120
2121 static Bool __glXQueryMaxSwapBarriersSGIX(Display *dpy, int screen, int *max)
2122 {
2123 (void) dpy;
2124 (void) screen;
2125 (void) max;
2126 return False;
2127 }
2128
2129
2130 /*
2131 ** GLX_OML_sync_control
2132 */
2133 static Bool __glXGetSyncValuesOML(Display *dpy, GLXDrawable drawable,
2134 int64_t *ust, int64_t *msc, int64_t *sbc)
2135 {
2136 #if defined(__DRI_SWAP_BUFFER_COUNTER) && defined(__DRI_MEDIA_STREAM_COUNTER)
2137 __GLXdisplayPrivate * const priv = __glXInitialize(dpy);
2138
2139 if ( priv != NULL ) {
2140 int i;
2141 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &i);
2142 __GLXscreenConfigs * const psc = &priv->screenConfigs[i];
2143
2144 assert( (pdraw == NULL) || (i != -1) );
2145 return ( (pdraw && psc->sbc && psc->msc)
2146 && ((*psc->msc->getMSC)(psc->driScreen, msc) == 0)
2147 && ((*psc->sbc->getSBC)(pdraw->driDrawable, sbc) == 0)
2148 && (__glXGetUST(ust) == 0) );
2149 }
2150 #else
2151 (void) dpy;
2152 (void) drawable;
2153 (void) ust;
2154 (void) msc;
2155 (void) sbc;
2156 #endif
2157 return False;
2158 }
2159
2160 #ifdef GLX_DIRECT_RENDERING
2161 _X_HIDDEN GLboolean
2162 __driGetMscRateOML(__DRIdrawable *draw,
2163 int32_t *numerator, int32_t *denominator, void *private)
2164 {
2165 #ifdef XF86VIDMODE
2166 __GLXscreenConfigs *psc;
2167 XF86VidModeModeLine mode_line;
2168 int dot_clock;
2169 int i;
2170 __GLXDRIdrawable *glxDraw = private;
2171
2172 psc = glxDraw->psc;
2173 if (XF86VidModeQueryVersion(psc->dpy, &i, &i) &&
2174 XF86VidModeGetModeLine(psc->dpy, psc->scr, &dot_clock, &mode_line) ) {
2175 unsigned n = dot_clock * 1000;
2176 unsigned d = mode_line.vtotal * mode_line.htotal;
2177
2178 # define V_INTERLACE 0x010
2179 # define V_DBLSCAN 0x020
2180
2181 if (mode_line.flags & V_INTERLACE)
2182 n *= 2;
2183 else if (mode_line.flags & V_DBLSCAN)
2184 d *= 2;
2185
2186 /* The OML_sync_control spec requires that if the refresh rate is a
2187 * whole number, that the returned numerator be equal to the refresh
2188 * rate and the denominator be 1.
2189 */
2190
2191 if (n % d == 0) {
2192 n /= d;
2193 d = 1;
2194 }
2195 else {
2196 static const unsigned f[] = { 13, 11, 7, 5, 3, 2, 0 };
2197
2198 /* This is a poor man's way to reduce a fraction. It's far from
2199 * perfect, but it will work well enough for this situation.
2200 */
2201
2202 for (i = 0; f[i] != 0; i++) {
2203 while (n % f[i] == 0 && d % f[i] == 0) {
2204 d /= f[i];
2205 n /= f[i];
2206 }
2207 }
2208 }
2209
2210 *numerator = n;
2211 *denominator = d;
2212
2213 return True;
2214 }
2215 else
2216 return False;
2217 #else
2218 return False;
2219 #endif
2220 }
2221 #endif
2222
2223 /**
2224 * Determine the refresh rate of the specified drawable and display.
2225 *
2226 * \param dpy Display whose refresh rate is to be determined.
2227 * \param drawable Drawable whose refresh rate is to be determined.
2228 * \param numerator Numerator of the refresh rate.
2229 * \param demoninator Denominator of the refresh rate.
2230 * \return If the refresh rate for the specified display and drawable could
2231 * be calculated, True is returned. Otherwise False is returned.
2232 *
2233 * \note This function is implemented entirely client-side. A lot of other
2234 * functionality is required to export GLX_OML_sync_control, so on
2235 * XFree86 this function can be called for direct-rendering contexts
2236 * when GLX_OML_sync_control appears in the client extension string.
2237 */
2238
2239 _X_HIDDEN GLboolean __glXGetMscRateOML(Display * dpy, GLXDrawable drawable,
2240 int32_t * numerator,
2241 int32_t * denominator)
2242 {
2243 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2244 __GLXDRIdrawable *draw = GetGLXDRIDrawable(dpy, drawable, NULL);
2245
2246 if (draw == NULL)
2247 return False;
2248
2249 return __driGetMscRateOML(draw->driDrawable, numerator, denominator, draw);
2250 #else
2251 (void) dpy;
2252 (void) drawable;
2253 (void) numerator;
2254 (void) denominator;
2255 #endif
2256 return False;
2257 }
2258
2259
2260 static int64_t __glXSwapBuffersMscOML(Display *dpy, GLXDrawable drawable,
2261 int64_t target_msc, int64_t divisor,
2262 int64_t remainder)
2263 {
2264 #ifdef __DRI_SWAP_BUFFER_COUNTER
2265 int screen;
2266 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen);
2267 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen );
2268
2269 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2270 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2271 * of -1 if the function failed because of errors detected in the input
2272 * parameters"
2273 */
2274 if ( divisor < 0 || remainder < 0 || target_msc < 0 )
2275 return -1;
2276 if ( divisor > 0 && remainder >= divisor )
2277 return -1;
2278
2279 if (pdraw != NULL && psc->counters != NULL)
2280 return (*psc->sbc->swapBuffersMSC)(pdraw->driDrawable, target_msc,
2281 divisor, remainder);
2282
2283 #else
2284 (void) dpy;
2285 (void) drawable;
2286 (void) target_msc;
2287 (void) divisor;
2288 (void) remainder;
2289 #endif
2290 return 0;
2291 }
2292
2293
2294 static Bool __glXWaitForMscOML(Display * dpy, GLXDrawable drawable,
2295 int64_t target_msc, int64_t divisor,
2296 int64_t remainder, int64_t *ust,
2297 int64_t *msc, int64_t *sbc)
2298 {
2299 #ifdef __DRI_MEDIA_STREAM_COUNTER
2300 int screen;
2301 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen);
2302 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen );
2303 int ret;
2304
2305 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2306 * error", but the return type in the spec is Bool.
2307 */
2308 if ( divisor < 0 || remainder < 0 || target_msc < 0 )
2309 return False;
2310 if ( divisor > 0 && remainder >= divisor )
2311 return False;
2312
2313 if (pdraw != NULL && psc->msc != NULL) {
2314 ret = (*psc->msc->waitForMSC)(pdraw->driDrawable, target_msc,
2315 divisor, remainder, msc, sbc);
2316
2317 /* __glXGetUST returns zero on success and non-zero on failure.
2318 * This function returns True on success and False on failure.
2319 */
2320 return ( (ret == 0) && (__glXGetUST( ust ) == 0) );
2321 }
2322 #else
2323 (void) dpy;
2324 (void) drawable;
2325 (void) target_msc;
2326 (void) divisor;
2327 (void) remainder;
2328 (void) ust;
2329 (void) msc;
2330 (void) sbc;
2331 #endif
2332 return False;
2333 }
2334
2335
2336 static Bool __glXWaitForSbcOML(Display * dpy, GLXDrawable drawable,
2337 int64_t target_sbc, int64_t *ust,
2338 int64_t *msc, int64_t *sbc )
2339 {
2340 #ifdef __DRI_SWAP_BUFFER_COUNTER
2341 int screen;
2342 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen);
2343 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, screen );
2344 int ret;
2345
2346 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2347 * error", but the return type in the spec is Bool.
2348 */
2349 if ( target_sbc < 0 )
2350 return False;
2351
2352 if (pdraw != NULL && psc->sbc != NULL) {
2353 ret = (*psc->sbc->waitForSBC)(pdraw->driDrawable, target_sbc, msc, sbc);
2354
2355 /* __glXGetUST returns zero on success and non-zero on failure.
2356 * This function returns True on success and False on failure.
2357 */
2358 return( (ret == 0) && (__glXGetUST( ust ) == 0) );
2359 }
2360 #else
2361 (void) dpy;
2362 (void) drawable;
2363 (void) target_sbc;
2364 (void) ust;
2365 (void) msc;
2366 (void) sbc;
2367 #endif
2368 return False;
2369 }
2370
2371
2372 /**
2373 * GLX_MESA_allocate_memory
2374 */
2375 /*@{*/
2376
2377 PUBLIC void *glXAllocateMemoryMESA(Display *dpy, int scrn,
2378 size_t size, float readFreq,
2379 float writeFreq, float priority)
2380 {
2381 #ifdef __DRI_ALLOCATE
2382 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, scrn );
2383
2384 if (psc && psc->allocate)
2385 return (*psc->allocate->allocateMemory)(psc->__driScreen, size,
2386 readFreq, writeFreq, priority);
2387
2388 #else
2389 (void) dpy;
2390 (void) scrn;
2391 (void) size;
2392 (void) readFreq;
2393 (void) writeFreq;
2394 (void) priority;
2395 #endif /* GLX_DIRECT_RENDERING */
2396
2397 return NULL;
2398 }
2399
2400
2401 PUBLIC void glXFreeMemoryMESA(Display *dpy, int scrn, void *pointer)
2402 {
2403 #ifdef __DRI_ALLOCATE
2404 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, scrn );
2405
2406 if (psc && psc->allocate)
2407 (*psc->allocate->freeMemory)(psc->__driScreen, pointer);
2408
2409 #else
2410 (void) dpy;
2411 (void) scrn;
2412 (void) pointer;
2413 #endif /* GLX_DIRECT_RENDERING */
2414 }
2415
2416
2417 PUBLIC GLuint glXGetMemoryOffsetMESA( Display *dpy, int scrn,
2418 const void *pointer )
2419 {
2420 #ifdef __DRI_ALLOCATE
2421 __GLXscreenConfigs * const psc = GetGLXScreenConfigs( dpy, scrn );
2422
2423 if (psc && psc->allocate)
2424 return (*psc->allocate->memoryOffset)(psc->__driScreen, pointer);
2425
2426 #else
2427 (void) dpy;
2428 (void) scrn;
2429 (void) pointer;
2430 #endif /* GLX_DIRECT_RENDERING */
2431
2432 return ~0L;
2433 }
2434 /*@}*/
2435
2436
2437 /**
2438 * Mesa extension stubs. These will help reduce portability problems.
2439 */
2440 /*@{*/
2441
2442 /**
2443 * Release all buffers associated with the specified GLX drawable.
2444 *
2445 * \todo
2446 * This function was intended for stand-alone Mesa. The issue there is that
2447 * the library doesn't get any notification when a window is closed. In
2448 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2449 * supported, there are 3 different functions to destroy a drawable. It
2450 * should be possible to create GLX protocol (or have it determine which
2451 * protocol to use based on the type of the drawable) to have one function
2452 * do the work of 3. For the direct-rendering case, this function could
2453 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2454 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2455 * would need to be used. This really should be done as part of the new DRI
2456 * interface work.
2457 *
2458 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2459 * __driGarbageCollectDrawables
2460 * glXDestroyGLXPixmap
2461 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2462 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2463 */
2464 static Bool __glXReleaseBuffersMESA( Display *dpy, GLXDrawable d )
2465 {
2466 (void) dpy;
2467 (void) d;
2468 return False;
2469 }
2470
2471
2472 PUBLIC GLXPixmap glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visual,
2473 Pixmap pixmap, Colormap cmap )
2474 {
2475 (void) dpy;
2476 (void) visual;
2477 (void) pixmap;
2478 (void) cmap;
2479 return 0;
2480 }
2481 /*@}*/
2482
2483
2484 /**
2485 * GLX_MESA_copy_sub_buffer
2486 */
2487 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2488 static void __glXCopySubBufferMESA(Display *dpy, GLXDrawable drawable,
2489 int x, int y, int width, int height)
2490 {
2491 xGLXVendorPrivateReq *req;
2492 GLXContext gc;
2493 GLXContextTag tag;
2494 CARD32 *drawable_ptr;
2495 INT32 *x_ptr, *y_ptr, *w_ptr, *h_ptr;
2496 CARD8 opcode;
2497
2498 #ifdef __DRI_COPY_SUB_BUFFER
2499 int screen;
2500 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, &screen);
2501 if ( pdraw != NULL ) {
2502 __GLXscreenConfigs * const psc = GetGLXScreenConfigs(dpy, screen);
2503 if (psc->driScreen->copySubBuffer != NULL) {
2504 (*psc->driScreen->copySubBuffer)(pdraw, x, y, width, height);
2505 }
2506
2507 return;
2508 }
2509 #endif
2510
2511 opcode = __glXSetupForCommand(dpy);
2512 if (!opcode)
2513 return;
2514
2515 /*
2516 ** The calling thread may or may not have a current context. If it
2517 ** does, send the context tag so the server can do a flush.
2518 */
2519 gc = __glXGetCurrentContext();
2520 if ((gc != NULL) && (dpy == gc->currentDpy) &&
2521 ((drawable == gc->currentDrawable) ||
2522 (drawable == gc->currentReadable)) ) {
2523 tag = gc->currentContextTag;
2524 } else {
2525 tag = 0;
2526 }
2527
2528 LockDisplay(dpy);
2529 GetReqExtra(GLXVendorPrivate, sizeof(CARD32) + sizeof(INT32) * 4,req);
2530 req->reqType = opcode;
2531 req->glxCode = X_GLXVendorPrivate;
2532 req->vendorCode = X_GLXvop_CopySubBufferMESA;
2533 req->contextTag = tag;
2534
2535 drawable_ptr = (CARD32 *) (req + 1);
2536 x_ptr = (INT32 *) (drawable_ptr + 1);
2537 y_ptr = (INT32 *) (drawable_ptr + 2);
2538 w_ptr = (INT32 *) (drawable_ptr + 3);
2539 h_ptr = (INT32 *) (drawable_ptr + 4);
2540
2541 *drawable_ptr = drawable;
2542 *x_ptr = x;
2543 *y_ptr = y;
2544 *w_ptr = width;
2545 *h_ptr = height;
2546
2547 UnlockDisplay(dpy);
2548 SyncHandle();
2549 }
2550
2551
2552 /**
2553 * GLX_EXT_texture_from_pixmap
2554 */
2555 /*@{*/
2556 static void __glXBindTexImageEXT(Display *dpy,
2557 GLXDrawable drawable,
2558 int buffer,
2559 const int *attrib_list)
2560 {
2561 xGLXVendorPrivateReq *req;
2562 GLXContext gc = __glXGetCurrentContext();
2563 CARD32 *drawable_ptr;
2564 INT32 *buffer_ptr;
2565 CARD32 *num_attrib_ptr;
2566 CARD32 *attrib_ptr;
2567 CARD8 opcode;
2568 unsigned int i;
2569
2570 if (gc == NULL)
2571 return;
2572
2573 i = 0;
2574 if (attrib_list) {
2575 while (attrib_list[i * 2] != None)
2576 i++;
2577 }
2578
2579 #ifdef GLX_DIRECT_RENDERING
2580 if (gc->driContext) {
2581 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable, NULL);
2582
2583 if (pdraw != NULL)
2584 (*pdraw->psc->texBuffer->setTexBuffer)(gc->__driContext,
2585 pdraw->textureTarget,
2586 pdraw->driDrawable);
2587
2588 return;
2589 }
2590 #endif
2591
2592 opcode = __glXSetupForCommand(dpy);
2593 if (!opcode)
2594 return;
2595
2596 LockDisplay(dpy);
2597 GetReqExtra(GLXVendorPrivate, 12 + 8 * i,req);
2598 req->reqType = opcode;
2599 req->glxCode = X_GLXVendorPrivate;
2600 req->vendorCode = X_GLXvop_BindTexImageEXT;
2601 req->contextTag = gc->currentContextTag;
2602
2603 drawable_ptr = (CARD32 *) (req + 1);
2604 buffer_ptr = (INT32 *) (drawable_ptr + 1);
2605 num_attrib_ptr = (CARD32 *) (buffer_ptr + 1);
2606 attrib_ptr = (CARD32 *) (num_attrib_ptr + 1);
2607
2608 *drawable_ptr = drawable;
2609 *buffer_ptr = buffer;
2610 *num_attrib_ptr = (CARD32) i;
2611
2612 i = 0;
2613 if (attrib_list) {
2614 while (attrib_list[i * 2] != None)
2615 {
2616 *attrib_ptr++ = (CARD32) attrib_list[i * 2 + 0];
2617 *attrib_ptr++ = (CARD32) attrib_list[i * 2 + 1];
2618 i++;
2619 }
2620 }
2621
2622 UnlockDisplay(dpy);
2623 SyncHandle();
2624 }
2625
2626 static void __glXReleaseTexImageEXT(Display *dpy,
2627 GLXDrawable drawable,
2628 int buffer)
2629 {
2630 xGLXVendorPrivateReq *req;
2631 GLXContext gc = __glXGetCurrentContext();
2632 CARD32 *drawable_ptr;
2633 INT32 *buffer_ptr;
2634 CARD8 opcode;
2635
2636 if (gc == NULL)
2637 return;
2638
2639 #ifdef GLX_DIRECT_RENDERING
2640 if (gc->driContext)
2641 return;
2642 #endif
2643
2644 opcode = __glXSetupForCommand(dpy);
2645 if (!opcode)
2646 return;
2647
2648 LockDisplay(dpy);
2649 GetReqExtra(GLXVendorPrivate, sizeof(CARD32)+sizeof(INT32),req);
2650 req->reqType = opcode;
2651 req->glxCode = X_GLXVendorPrivate;
2652 req->vendorCode = X_GLXvop_ReleaseTexImageEXT;
2653 req->contextTag = gc->currentContextTag;
2654
2655 drawable_ptr = (CARD32 *) (req + 1);
2656 buffer_ptr = (INT32 *) (drawable_ptr + 1);
2657
2658 *drawable_ptr = drawable;
2659 *buffer_ptr = buffer;
2660
2661 UnlockDisplay(dpy);
2662 SyncHandle();
2663 }
2664 /*@}*/
2665
2666 /**
2667 * \c strdup is actually not a standard ANSI C or POSIX routine.
2668 * Irix will not define it if ANSI mode is in effect.
2669 *
2670 * \sa strdup
2671 */
2672 _X_HIDDEN char *
2673 __glXstrdup(const char *str)
2674 {
2675 char *copy;
2676 copy = (char *) Xmalloc(strlen(str) + 1);
2677 if (!copy)
2678 return NULL;
2679 strcpy(copy, str);
2680 return copy;
2681 }
2682
2683 /*
2684 ** glXGetProcAddress support
2685 */
2686
2687 struct name_address_pair {
2688 const char *Name;
2689 GLvoid *Address;
2690 };
2691
2692 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2693 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2694
2695 static const struct name_address_pair GLX_functions[] = {
2696 /*** GLX_VERSION_1_0 ***/
2697 GLX_FUNCTION( glXChooseVisual ),
2698 GLX_FUNCTION( glXCopyContext ),
2699 GLX_FUNCTION( glXCreateContext ),
2700 GLX_FUNCTION( glXCreateGLXPixmap ),
2701 GLX_FUNCTION( glXDestroyContext ),
2702 GLX_FUNCTION( glXDestroyGLXPixmap ),
2703 GLX_FUNCTION( glXGetConfig ),
2704 GLX_FUNCTION( glXGetCurrentContext ),
2705 GLX_FUNCTION( glXGetCurrentDrawable ),
2706 GLX_FUNCTION( glXIsDirect ),
2707 GLX_FUNCTION( glXMakeCurrent ),
2708 GLX_FUNCTION( glXQueryExtension ),
2709 GLX_FUNCTION( glXQueryVersion ),
2710 GLX_FUNCTION( glXSwapBuffers ),
2711 GLX_FUNCTION( glXUseXFont ),
2712 GLX_FUNCTION( glXWaitGL ),
2713 GLX_FUNCTION( glXWaitX ),
2714
2715 /*** GLX_VERSION_1_1 ***/
2716 GLX_FUNCTION( glXGetClientString ),
2717 GLX_FUNCTION( glXQueryExtensionsString ),
2718 GLX_FUNCTION( glXQueryServerString ),
2719
2720 /*** GLX_VERSION_1_2 ***/
2721 GLX_FUNCTION( glXGetCurrentDisplay ),
2722
2723 /*** GLX_VERSION_1_3 ***/
2724 GLX_FUNCTION( glXChooseFBConfig ),
2725 GLX_FUNCTION( glXCreateNewContext ),
2726 GLX_FUNCTION( glXCreatePbuffer ),
2727 GLX_FUNCTION( glXCreatePixmap ),
2728 GLX_FUNCTION( glXCreateWindow ),
2729 GLX_FUNCTION( glXDestroyPbuffer ),
2730 GLX_FUNCTION( glXDestroyPixmap ),
2731 GLX_FUNCTION( glXDestroyWindow ),
2732 GLX_FUNCTION( glXGetCurrentReadDrawable ),
2733 GLX_FUNCTION( glXGetFBConfigAttrib ),
2734 GLX_FUNCTION( glXGetFBConfigs ),
2735 GLX_FUNCTION( glXGetSelectedEvent ),
2736 GLX_FUNCTION( glXGetVisualFromFBConfig ),
2737 GLX_FUNCTION( glXMakeContextCurrent ),
2738 GLX_FUNCTION( glXQueryContext ),
2739 GLX_FUNCTION( glXQueryDrawable ),
2740 GLX_FUNCTION( glXSelectEvent ),
2741
2742 /*** GLX_SGI_swap_control ***/
2743 GLX_FUNCTION2( glXSwapIntervalSGI, __glXSwapIntervalSGI ),
2744
2745 /*** GLX_SGI_video_sync ***/
2746 GLX_FUNCTION2( glXGetVideoSyncSGI, __glXGetVideoSyncSGI ),
2747 GLX_FUNCTION2( glXWaitVideoSyncSGI, __glXWaitVideoSyncSGI ),
2748
2749 /*** GLX_SGI_make_current_read ***/
2750 GLX_FUNCTION2( glXMakeCurrentReadSGI, glXMakeContextCurrent ),
2751 GLX_FUNCTION2( glXGetCurrentReadDrawableSGI, glXGetCurrentReadDrawable ),
2752
2753 /*** GLX_EXT_import_context ***/
2754 GLX_FUNCTION( glXFreeContextEXT ),
2755 GLX_FUNCTION( glXGetContextIDEXT ),
2756 GLX_FUNCTION2( glXGetCurrentDisplayEXT, glXGetCurrentDisplay ),
2757 GLX_FUNCTION( glXImportContextEXT ),
2758 GLX_FUNCTION2( glXQueryContextInfoEXT, glXQueryContext ),
2759
2760 /*** GLX_SGIX_fbconfig ***/
2761 GLX_FUNCTION2( glXGetFBConfigAttribSGIX, glXGetFBConfigAttrib ),
2762 GLX_FUNCTION2( glXChooseFBConfigSGIX, glXChooseFBConfig ),
2763 GLX_FUNCTION( glXCreateGLXPixmapWithConfigSGIX ),
2764 GLX_FUNCTION( glXCreateContextWithConfigSGIX ),
2765 GLX_FUNCTION2( glXGetVisualFromFBConfigSGIX, glXGetVisualFromFBConfig ),
2766 GLX_FUNCTION( glXGetFBConfigFromVisualSGIX ),
2767
2768 /*** GLX_SGIX_pbuffer ***/
2769 GLX_FUNCTION( glXCreateGLXPbufferSGIX ),
2770 GLX_FUNCTION( glXDestroyGLXPbufferSGIX ),
2771 GLX_FUNCTION( glXQueryGLXPbufferSGIX ),
2772 GLX_FUNCTION( glXSelectEventSGIX ),
2773 GLX_FUNCTION( glXGetSelectedEventSGIX ),
2774
2775 /*** GLX_SGIX_swap_group ***/
2776 GLX_FUNCTION2( glXJoinSwapGroupSGIX, __glXJoinSwapGroupSGIX ),
2777
2778 /*** GLX_SGIX_swap_barrier ***/
2779 GLX_FUNCTION2( glXBindSwapBarrierSGIX, __glXBindSwapBarrierSGIX ),
2780 GLX_FUNCTION2( glXQueryMaxSwapBarriersSGIX, __glXQueryMaxSwapBarriersSGIX ),
2781
2782 /*** GLX_MESA_allocate_memory ***/
2783 GLX_FUNCTION( glXAllocateMemoryMESA ),
2784 GLX_FUNCTION( glXFreeMemoryMESA ),
2785 GLX_FUNCTION( glXGetMemoryOffsetMESA ),
2786
2787 /*** GLX_MESA_copy_sub_buffer ***/
2788 GLX_FUNCTION2( glXCopySubBufferMESA, __glXCopySubBufferMESA ),
2789
2790 /*** GLX_MESA_pixmap_colormap ***/
2791 GLX_FUNCTION( glXCreateGLXPixmapMESA ),
2792
2793 /*** GLX_MESA_release_buffers ***/
2794 GLX_FUNCTION2( glXReleaseBuffersMESA, __glXReleaseBuffersMESA ),
2795
2796 /*** GLX_MESA_swap_control ***/
2797 GLX_FUNCTION2( glXSwapIntervalMESA, __glXSwapIntervalMESA ),
2798 GLX_FUNCTION2( glXGetSwapIntervalMESA, __glXGetSwapIntervalMESA ),
2799
2800 /*** GLX_MESA_swap_frame_usage ***/
2801 GLX_FUNCTION2( glXBeginFrameTrackingMESA, __glXBeginFrameTrackingMESA ),
2802 GLX_FUNCTION2( glXEndFrameTrackingMESA, __glXEndFrameTrackingMESA ),
2803 GLX_FUNCTION2( glXGetFrameUsageMESA, __glXGetFrameUsageMESA ),
2804 GLX_FUNCTION2( glXQueryFrameTrackingMESA, __glXQueryFrameTrackingMESA ),
2805
2806 /*** GLX_ARB_get_proc_address ***/
2807 GLX_FUNCTION( glXGetProcAddressARB ),
2808
2809 /*** GLX 1.4 ***/
2810 GLX_FUNCTION2( glXGetProcAddress, glXGetProcAddressARB ),
2811
2812 /*** GLX_OML_sync_control ***/
2813 GLX_FUNCTION2( glXWaitForSbcOML, __glXWaitForSbcOML ),
2814 GLX_FUNCTION2( glXWaitForMscOML, __glXWaitForMscOML ),
2815 GLX_FUNCTION2( glXSwapBuffersMscOML, __glXSwapBuffersMscOML ),
2816 GLX_FUNCTION2( glXGetMscRateOML, __glXGetMscRateOML ),
2817 GLX_FUNCTION2( glXGetSyncValuesOML, __glXGetSyncValuesOML ),
2818
2819 /*** GLX_EXT_texture_from_pixmap ***/
2820 GLX_FUNCTION2( glXBindTexImageEXT, __glXBindTexImageEXT ),
2821 GLX_FUNCTION2( glXReleaseTexImageEXT, __glXReleaseTexImageEXT ),
2822
2823 #ifdef GLX_DIRECT_RENDERING
2824 /*** DRI configuration ***/
2825 GLX_FUNCTION( glXGetScreenDriver ),
2826 GLX_FUNCTION( glXGetDriverConfig ),
2827 #endif
2828
2829 { NULL, NULL } /* end of list */
2830 };
2831
2832
2833 static const GLvoid *
2834 get_glx_proc_address(const char *funcName)
2835 {
2836 GLuint i;
2837
2838 /* try static functions */
2839 for (i = 0; GLX_functions[i].Name; i++) {
2840 if (strcmp(GLX_functions[i].Name, funcName) == 0)
2841 return GLX_functions[i].Address;
2842 }
2843
2844 return NULL;
2845 }
2846
2847
2848 /**
2849 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2850 * \c glXGetProcAddress.
2851 *
2852 * \param procName Name of a GL or GLX function.
2853 * \returns A pointer to the named function
2854 *
2855 * \sa glXGetProcAddress
2856 */
2857 PUBLIC void (*glXGetProcAddressARB(const GLubyte *procName))( void )
2858 {
2859 typedef void (*gl_function)( void );
2860 gl_function f;
2861
2862
2863 /* Search the table of GLX and internal functions first. If that
2864 * fails and the supplied name could be a valid core GL name, try
2865 * searching the core GL function table. This check is done to prevent
2866 * DRI based drivers from searching the core GL function table for
2867 * internal API functions.
2868 */
2869
2870 f = (gl_function) get_glx_proc_address((const char *) procName);
2871 if ( (f == NULL) && (procName[0] == 'g') && (procName[1] == 'l')
2872 && (procName[2] != 'X') ) {
2873 f = (gl_function) _glapi_get_proc_address((const char *) procName);
2874 }
2875
2876 return f;
2877 }
2878
2879 /**
2880 * Get the address of a named GL function. This is the GLX 1.4 name for
2881 * \c glXGetProcAddressARB.
2882 *
2883 * \param procName Name of a GL or GLX function.
2884 * \returns A pointer to the named function
2885 *
2886 * \sa glXGetProcAddressARB
2887 */
2888 PUBLIC void (*glXGetProcAddress(const GLubyte *procName))( void )
2889 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2890 __attribute__ ((alias ("glXGetProcAddressARB")));
2891 #else
2892 {
2893 return glXGetProcAddressARB(procName);
2894 }
2895 #endif /* __GNUC__ */
2896
2897
2898 #ifdef GLX_DIRECT_RENDERING
2899 /**
2900 * Get the unadjusted system time (UST). Currently, the UST is measured in
2901 * microseconds since Epoc. The actual resolution of the UST may vary from
2902 * system to system, and the units may vary from release to release.
2903 * Drivers should not call this function directly. They should instead use
2904 * \c glXGetProcAddress to obtain a pointer to the function.
2905 *
2906 * \param ust Location to store the 64-bit UST
2907 * \returns Zero on success or a negative errno value on failure.
2908 *
2909 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2910 *
2911 * \since Internal API version 20030317.
2912 */
2913 _X_HIDDEN int __glXGetUST( int64_t * ust )
2914 {
2915 struct timeval tv;
2916
2917 if ( ust == NULL ) {
2918 return -EFAULT;
2919 }
2920
2921 if ( gettimeofday( & tv, NULL ) == 0 ) {
2922 ust[0] = (tv.tv_sec * 1000000) + tv.tv_usec;
2923 return 0;
2924 } else {
2925 return -errno;
2926 }
2927 }
2928 #endif /* GLX_DIRECT_RENDERING */