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