2 * Copyright © 2008 Red Hat, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Soft-
6 * ware"), to deal in the Software without restriction, including without
7 * limitation the rights to use, copy, modify, merge, publish, distribute,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, provided that the above copyright
10 * notice(s) and this permission notice appear in all copies of the Soft-
11 * ware and that both the above copyright notice(s) and this permission
12 * notice appear in supporting documentation.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
16 * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY
17 * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN
18 * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE-
19 * QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR-
22 * MANCE OF THIS SOFTWARE.
24 * Except as contained in this notice, the name of a copyright holder shall
25 * not be used in advertising or otherwise to promote the sale, use or
26 * other dealings in this Software without prior written authorization of
27 * the copyright holder.
30 * Kristian Høgsberg (krh@redhat.com)
33 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
36 #include <X11/extensions/Xfixes.h>
37 #include <X11/extensions/Xdamage.h>
39 #include "glxclient.h"
40 #include <X11/extensions/dri2proto.h>
45 #include <sys/types.h>
49 #include "dri_common.h"
51 /* From xmlpool/options.h, user exposed so should be stable */
52 #define DRI_CONF_VBLANK_NEVER 0
53 #define DRI_CONF_VBLANK_DEF_INTERVAL_0 1
54 #define DRI_CONF_VBLANK_DEF_INTERVAL_1 2
55 #define DRI_CONF_VBLANK_ALWAYS_SYNC 3
65 ** XFree86-DRI version information
71 int invalidateAvailable;
73 __glxHashTable *dri2Hash;
75 const __DRIextension *loader_extensions[4];
79 __GLXscreenConfigs base;
81 __DRIscreen *driScreen;
82 __GLXDRIscreen vtable;
83 const __DRIdri2Extension *dri2;
84 const __DRIcoreExtension *core;
86 const __DRI2flushExtension *f;
87 const __DRI2configQueryExtension *config;
88 const __DRItexBufferExtension *texBuffer;
97 __DRIcontext *driContext;
98 __GLXscreenConfigs *psc;
103 __GLXDRIdrawable base;
104 __DRIdrawable *driDrawable;
105 __DRIbuffer buffers[5];
114 dri2DestroyContext(__GLXDRIcontext *context,
115 __GLXscreenConfigs *base, Display *dpy)
117 struct dri2_context *pcp = (struct dri2_context *) context;
118 struct dri2_screen *psc = (struct dri2_screen *) base;
120 (*psc->core->destroyContext) (pcp->driContext);
126 dri2BindContext(__GLXDRIcontext *context,
127 __GLXDRIdrawable *draw, __GLXDRIdrawable *read)
129 struct dri2_context *pcp = (struct dri2_context *) context;
130 struct dri2_screen *psc = (struct dri2_screen *) pcp->psc;
131 struct dri2_drawable *pdr = (struct dri2_drawable *) draw;
132 struct dri2_drawable *prd = (struct dri2_drawable *) read;
134 return (*psc->core->bindContext) (pcp->driContext,
135 pdr->driDrawable, prd->driDrawable);
139 dri2UnbindContext(__GLXDRIcontext *context)
141 struct dri2_context *pcp = (struct dri2_context *) context;
142 struct dri2_screen *psc = (struct dri2_screen *) pcp->psc;
144 (*psc->core->unbindContext) (pcp->driContext);
147 static __GLXDRIcontext *
148 dri2CreateContext(__GLXscreenConfigs *base,
149 const __GLcontextModes * mode,
150 GLXContext gc, GLXContext shareList, int renderType)
152 struct dri2_context *pcp, *pcp_shared;
153 struct dri2_screen *psc = (struct dri2_screen *) base;
154 __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) mode;
155 __DRIcontext *shared = NULL;
158 pcp_shared = (struct dri2_context *) shareList->driContext;
159 shared = pcp_shared->driContext;
162 pcp = Xmalloc(sizeof *pcp);
166 pcp->psc = &psc->base;
168 (*psc->dri2->createNewContext) (psc->driScreen,
169 config->driConfig, shared, pcp);
170 gc->__driContext = pcp->driContext;
172 if (pcp->driContext == NULL) {
177 pcp->base.destroyContext = dri2DestroyContext;
178 pcp->base.bindContext = dri2BindContext;
179 pcp->base.unbindContext = dri2UnbindContext;
185 dri2DestroyDrawable(__GLXDRIdrawable *base)
187 struct dri2_screen *psc = (struct dri2_screen *) base->psc;
188 struct dri2_drawable *pdraw = (struct dri2_drawable *) base;
189 __GLXdisplayPrivate *dpyPriv = psc->base.display;
190 struct dri2_display *pdp = (struct dri2_display *)dpyPriv->dri2Display;
192 __glxHashDelete(pdp->dri2Hash, pdraw->base.xDrawable);
193 (*psc->core->destroyDrawable) (pdraw->driDrawable);
194 DRI2DestroyDrawable(psc->base.dpy, pdraw->base.xDrawable);
198 static __GLXDRIdrawable *
199 dri2CreateDrawable(__GLXscreenConfigs *base, XID xDrawable,
200 GLXDrawable drawable, const __GLcontextModes * modes)
202 struct dri2_drawable *pdraw;
203 struct dri2_screen *psc = (struct dri2_screen *) base;
204 __GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) modes;
205 __GLXdisplayPrivate *dpyPriv;
206 struct dri2_display *pdp;
207 GLint vblank_mode = DRI_CONF_VBLANK_DEF_INTERVAL_1;
209 pdraw = Xmalloc(sizeof(*pdraw));
213 pdraw->base.destroyDrawable = dri2DestroyDrawable;
214 pdraw->base.xDrawable = xDrawable;
215 pdraw->base.drawable = drawable;
216 pdraw->base.psc = &psc->base;
217 pdraw->bufferCount = 0;
218 pdraw->swap_interval = 1; /* default may be overridden below */
219 pdraw->have_back = 0;
222 psc->config->configQueryi(psc->driScreen,
223 "vblank_mode", &vblank_mode);
225 switch (vblank_mode) {
226 case DRI_CONF_VBLANK_NEVER:
227 case DRI_CONF_VBLANK_DEF_INTERVAL_0:
228 pdraw->swap_interval = 0;
230 case DRI_CONF_VBLANK_DEF_INTERVAL_1:
231 case DRI_CONF_VBLANK_ALWAYS_SYNC:
233 pdraw->swap_interval = 1;
237 DRI2CreateDrawable(psc->base.dpy, xDrawable);
239 dpyPriv = __glXInitialize(psc->base.dpy);
240 pdp = (struct dri2_display *)dpyPriv->dri2Display;;
241 /* Create a new drawable */
243 (*psc->dri2->createNewDrawable) (psc->driScreen,
244 config->driConfig, pdraw);
246 if (!pdraw->driDrawable) {
247 DRI2DestroyDrawable(psc->base.dpy, xDrawable);
252 if (__glxHashInsert(pdp->dri2Hash, xDrawable, pdraw)) {
253 (*psc->core->destroyDrawable) (pdraw->driDrawable);
254 DRI2DestroyDrawable(psc->base.dpy, xDrawable);
260 #ifdef X_DRI2SwapInterval
262 * Make sure server has the same swap interval we do for the new
265 if (pdp->swapAvailable)
266 DRI2SwapInterval(psc->base.dpy, xDrawable, pdraw->swap_interval);
275 dri2DrawableGetMSC(__GLXscreenConfigs *psc, __GLXDRIdrawable *pdraw,
276 int64_t *ust, int64_t *msc, int64_t *sbc)
278 CARD64 dri2_ust, dri2_msc, dri2_sbc;
281 ret = DRI2GetMSC(psc->dpy, pdraw->xDrawable,
282 &dri2_ust, &dri2_msc, &dri2_sbc);
296 dri2WaitForMSC(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
297 int64_t remainder, int64_t *ust, int64_t *msc, int64_t *sbc)
299 CARD64 dri2_ust, dri2_msc, dri2_sbc;
302 ret = DRI2WaitMSC(pdraw->psc->dpy, pdraw->xDrawable, target_msc, divisor,
303 remainder, &dri2_ust, &dri2_msc, &dri2_sbc);
312 dri2WaitForSBC(__GLXDRIdrawable *pdraw, int64_t target_sbc, int64_t *ust,
313 int64_t *msc, int64_t *sbc)
315 CARD64 dri2_ust, dri2_msc, dri2_sbc;
318 ret = DRI2WaitSBC(pdraw->psc->dpy, pdraw->xDrawable,
319 target_sbc, &dri2_ust, &dri2_msc, &dri2_sbc);
327 #endif /* X_DRI2WaitMSC */
330 dri2CopySubBuffer(__GLXDRIdrawable *pdraw, int x, int y, int width, int height)
332 struct dri2_drawable *priv = (struct dri2_drawable *) pdraw;
333 struct dri2_screen *psc = (struct dri2_screen *) pdraw->psc;
335 XserverRegion region;
337 /* Check we have the right attachments */
338 if (!priv->have_back)
342 xrect.y = priv->height - y - height;
344 xrect.height = height;
348 (*psc->f->flush) (priv->driDrawable);
351 region = XFixesCreateRegion(psc->base.dpy, &xrect, 1);
352 DRI2CopyRegion(psc->base.dpy, pdraw->xDrawable, region,
353 DRI2BufferFrontLeft, DRI2BufferBackLeft);
354 XFixesDestroyRegion(psc->base.dpy, region);
356 /* Refresh the fake front (if present) after we just damaged the real
359 DRI2CopyRegion(psc->base.dpy, pdraw->xDrawable, region,
360 DRI2BufferFakeFrontLeft, DRI2BufferFrontLeft);
361 XFixesDestroyRegion(psc->base.dpy, region);
365 dri2_copy_drawable(struct dri2_drawable *priv, int dest, int src)
368 XserverRegion region;
369 struct dri2_screen *psc = (struct dri2_screen *) priv->base.psc;
373 xrect.width = priv->width;
374 xrect.height = priv->height;
378 (*psc->f->flush) (priv->driDrawable);
381 region = XFixesCreateRegion(psc->base.dpy, &xrect, 1);
382 DRI2CopyRegion(psc->base.dpy, priv->base.xDrawable, region, dest, src);
383 XFixesDestroyRegion(psc->base.dpy, region);
388 dri2WaitX(__GLXDRIdrawable *pdraw)
390 struct dri2_drawable *priv = (struct dri2_drawable *) pdraw;
392 if (!priv->have_fake_front)
395 dri2_copy_drawable(priv, DRI2BufferFakeFrontLeft, DRI2BufferFrontLeft);
399 dri2WaitGL(__GLXDRIdrawable * pdraw)
401 struct dri2_drawable *priv = (struct dri2_drawable *) pdraw;
403 if (!priv->have_fake_front)
406 dri2_copy_drawable(priv, DRI2BufferFrontLeft, DRI2BufferFakeFrontLeft);
410 dri2FlushFrontBuffer(__DRIdrawable *driDrawable, void *loaderPrivate)
412 struct dri2_drawable *pdraw = loaderPrivate;
413 __GLXdisplayPrivate *priv = __glXInitialize(pdraw->base.psc->dpy);
414 struct dri2_display *pdp = (struct dri2_display *)priv->dri2Display;
416 /* Old servers don't send invalidate events */
417 if (!pdp->invalidateAvailable)
418 dri2InvalidateBuffers(priv->dpy, pdraw->base.drawable);
420 dri2WaitGL(loaderPrivate);
425 dri2DestroyScreen(__GLXscreenConfigs *base)
427 struct dri2_screen *psc = (struct dri2_screen *) base;
429 /* Free the direct rendering per screen data */
430 (*psc->core->destroyScreen) (psc->driScreen);
436 * Process list of buffer received from the server
438 * Processes the list of buffers received in a reply from the server to either
439 * \c DRI2GetBuffers or \c DRI2GetBuffersWithFormat.
442 process_buffers(struct dri2_drawable * pdraw, DRI2Buffer * buffers,
447 pdraw->bufferCount = count;
448 pdraw->have_fake_front = 0;
449 pdraw->have_back = 0;
451 /* This assumes the DRI2 buffer attachment tokens matches the
452 * __DRIbuffer tokens. */
453 for (i = 0; i < count; i++) {
454 pdraw->buffers[i].attachment = buffers[i].attachment;
455 pdraw->buffers[i].name = buffers[i].name;
456 pdraw->buffers[i].pitch = buffers[i].pitch;
457 pdraw->buffers[i].cpp = buffers[i].cpp;
458 pdraw->buffers[i].flags = buffers[i].flags;
459 if (pdraw->buffers[i].attachment == __DRI_BUFFER_FAKE_FRONT_LEFT)
460 pdraw->have_fake_front = 1;
461 if (pdraw->buffers[i].attachment == __DRI_BUFFER_BACK_LEFT)
462 pdraw->have_back = 1;
468 dri2SwapBuffers(__GLXDRIdrawable *pdraw, int64_t target_msc, int64_t divisor,
471 struct dri2_drawable *priv = (struct dri2_drawable *) pdraw;
472 __GLXdisplayPrivate *dpyPriv = __glXInitialize(priv->base.psc->dpy);
473 struct dri2_screen *psc = (struct dri2_screen *) priv->base.psc;
474 struct dri2_display *pdp =
475 (struct dri2_display *)dpyPriv->dri2Display;
480 (*psc->f->flush)(priv->driDrawable);
483 /* Old servers don't send invalidate events */
484 if (!pdp->invalidateAvailable)
485 dri2InvalidateBuffers(dpyPriv->dpy, pdraw->drawable);
487 /* Old servers can't handle swapbuffers */
488 if (!pdp->swapAvailable) {
489 dri2CopySubBuffer(pdraw, 0, 0, priv->width, priv->height);
493 #ifdef X_DRI2SwapBuffers
494 DRI2SwapBuffers(psc->base.dpy, pdraw->xDrawable, target_msc, divisor,
502 dri2GetBuffers(__DRIdrawable * driDrawable,
503 int *width, int *height,
504 unsigned int *attachments, int count,
505 int *out_count, void *loaderPrivate)
507 struct dri2_drawable *pdraw = loaderPrivate;
510 buffers = DRI2GetBuffers(pdraw->base.psc->dpy, pdraw->base.xDrawable,
511 width, height, attachments, count, out_count);
515 pdraw->width = *width;
516 pdraw->height = *height;
517 process_buffers(pdraw, buffers, *out_count);
521 return pdraw->buffers;
525 dri2GetBuffersWithFormat(__DRIdrawable * driDrawable,
526 int *width, int *height,
527 unsigned int *attachments, int count,
528 int *out_count, void *loaderPrivate)
530 struct dri2_drawable *pdraw = loaderPrivate;
533 buffers = DRI2GetBuffersWithFormat(pdraw->base.psc->dpy,
534 pdraw->base.xDrawable,
535 width, height, attachments,
540 pdraw->width = *width;
541 pdraw->height = *height;
542 process_buffers(pdraw, buffers, *out_count);
546 return pdraw->buffers;
549 #ifdef X_DRI2SwapInterval
552 dri2SetSwapInterval(__GLXDRIdrawable *pdraw, int interval)
554 struct dri2_drawable *priv = (struct dri2_drawable *) pdraw;
555 GLint vblank_mode = DRI_CONF_VBLANK_DEF_INTERVAL_1;
556 struct dri2_screen *psc = (struct dri2_screen *) priv->base.psc;
559 psc->config->configQueryi(psc->driScreen,
560 "vblank_mode", &vblank_mode);
562 switch (vblank_mode) {
563 case DRI_CONF_VBLANK_NEVER:
564 return GLX_BAD_VALUE;
565 case DRI_CONF_VBLANK_ALWAYS_SYNC:
567 return GLX_BAD_VALUE;
573 DRI2SwapInterval(priv->base.psc->dpy, priv->base.xDrawable, interval);
574 priv->swap_interval = interval;
580 dri2GetSwapInterval(__GLXDRIdrawable *pdraw)
582 struct dri2_drawable *priv = (struct dri2_drawable *) pdraw;
584 return priv->swap_interval;
587 #endif /* X_DRI2SwapInterval */
589 static const __DRIdri2LoaderExtension dri2LoaderExtension = {
590 {__DRI_DRI2_LOADER, __DRI_DRI2_LOADER_VERSION},
592 dri2FlushFrontBuffer,
593 dri2GetBuffersWithFormat,
596 static const __DRIdri2LoaderExtension dri2LoaderExtension_old = {
597 {__DRI_DRI2_LOADER, __DRI_DRI2_LOADER_VERSION},
599 dri2FlushFrontBuffer,
603 #ifdef __DRI_USE_INVALIDATE
604 static const __DRIuseInvalidateExtension dri2UseInvalidate = {
605 { __DRI_USE_INVALIDATE, __DRI_USE_INVALIDATE_VERSION }
610 dri2InvalidateBuffers(Display *dpy, XID drawable)
612 __GLXDRIdrawable *pdraw =
613 dri2GetGlxDrawableFromXDrawableId(dpy, drawable);
614 struct dri2_screen *psc = (struct dri2_screen *) pdraw->psc;
615 struct dri2_drawable *pdp = (struct dri2_drawable *) pdraw;
617 #if __DRI2_FLUSH_VERSION >= 3
619 psc->f->invalidate(pdp->driDrawable);
624 dri2_bind_tex_image(Display * dpy,
625 GLXDrawable drawable,
626 int buffer, const int *attrib_list)
628 GLXContext gc = __glXGetCurrentContext();
629 __GLXDRIdrawable *base = GetGLXDRIDrawable(dpy, drawable, NULL);
630 __GLXdisplayPrivate *dpyPriv = __glXInitialize(dpy);
631 struct dri2_drawable *pdraw = (struct dri2_drawable *) base;
632 struct dri2_display *pdp =
633 (struct dri2_display *) dpyPriv->dri2Display;
634 struct dri2_screen *psc = (struct dri2_screen *) base->psc;
638 #if __DRI2_FLUSH_VERSION >= 3
639 if (!pdp->invalidateAvailable && psc->f)
640 psc->f->invalidate(pdraw->driDrawable);
643 if (psc->texBuffer->base.version >= 2 &&
644 psc->texBuffer->setTexBuffer2 != NULL) {
645 (*psc->texBuffer->setTexBuffer2) (gc->__driContext,
646 pdraw->base.textureTarget,
647 pdraw->base.textureFormat,
651 (*psc->texBuffer->setTexBuffer) (gc->__driContext,
652 pdraw->base.textureTarget,
659 dri2_release_tex_image(Display * dpy, GLXDrawable drawable, int buffer)
663 static const struct glx_context_vtable dri2_context_vtable = {
665 dri2_release_tex_image,
669 dri2BindExtensions(struct dri2_screen *psc, const __DRIextension **extensions)
673 __glXEnableDirectExtension(&psc->base, "GLX_SGI_video_sync");
674 __glXEnableDirectExtension(&psc->base, "GLX_SGI_swap_control");
675 __glXEnableDirectExtension(&psc->base, "GLX_MESA_swap_control");
677 /* FIXME: if DRI2 version supports it... */
678 __glXEnableDirectExtension(&psc->base, "INTEL_swap_event");
680 for (i = 0; extensions[i]; i++) {
681 if ((strcmp(extensions[i]->name, __DRI_TEX_BUFFER) == 0)) {
682 psc->texBuffer = (__DRItexBufferExtension *) extensions[i];
683 __glXEnableDirectExtension(&psc->base, "GLX_EXT_texture_from_pixmap");
686 if ((strcmp(extensions[i]->name, __DRI2_FLUSH) == 0)) {
687 psc->f = (__DRI2flushExtension *) extensions[i];
688 /* internal driver extension, no GL extension exposed */
691 if ((strcmp(extensions[i]->name, __DRI2_CONFIG_QUERY) == 0))
692 psc->config = (__DRI2configQueryExtension *) extensions[i];
697 static __GLXscreenConfigs *
698 dri2CreateScreen(int screen, __GLXdisplayPrivate * priv)
700 const __DRIconfig **driver_configs;
701 const __DRIextension **extensions;
702 const struct dri2_display *const pdp = (struct dri2_display *)
704 struct dri2_screen *psc;
706 char *driverName, *deviceName;
710 psc = Xmalloc(sizeof *psc);
714 memset(psc, 0, sizeof *psc);
715 if (!glx_screen_init(&psc->base, screen, priv))
718 if (!DRI2Connect(priv->dpy, RootWindow(priv->dpy, screen),
719 &driverName, &deviceName)) {
724 psc->driver = driOpenDriver(driverName);
725 if (psc->driver == NULL) {
726 ErrorMessageF("driver pointer missing\n");
730 extensions = dlsym(psc->driver, __DRI_DRIVER_EXTENSIONS);
731 if (extensions == NULL) {
732 ErrorMessageF("driver exports no extensions (%s)\n", dlerror());
736 for (i = 0; extensions[i]; i++) {
737 if (strcmp(extensions[i]->name, __DRI_CORE) == 0)
738 psc->core = (__DRIcoreExtension *) extensions[i];
739 if (strcmp(extensions[i]->name, __DRI_DRI2) == 0)
740 psc->dri2 = (__DRIdri2Extension *) extensions[i];
743 if (psc->core == NULL || psc->dri2 == NULL) {
744 ErrorMessageF("core dri or dri2 extension not found\n");
748 psc->fd = open(deviceName, O_RDWR);
750 ErrorMessageF("failed to open drm device: %s\n", strerror(errno));
754 if (drmGetMagic(psc->fd, &magic)) {
755 ErrorMessageF("failed to get magic\n");
759 if (!DRI2Authenticate(priv->dpy, RootWindow(priv->dpy, screen), magic)) {
760 ErrorMessageF("failed to authenticate magic %d\n", magic);
765 /* If the server does not support the protocol for
766 * DRI2GetBuffersWithFormat, don't supply that interface to the driver.
769 psc->dri2->createNewScreen(screen, psc->fd,
770 (const __DRIextension **)
771 &pdp->loader_extensions[0],
772 &driver_configs, psc);
774 if (psc->driScreen == NULL) {
775 ErrorMessageF("failed to create dri screen\n");
779 extensions = psc->core->getExtensions(psc->driScreen);
780 driBindCommonExtensions(&psc->base, extensions);
781 dri2BindExtensions(psc, extensions);
784 driConvertConfigs(psc->core, psc->base.configs, driver_configs);
786 driConvertConfigs(psc->core, psc->base.visuals, driver_configs);
788 psc->base.driver_configs = driver_configs;
791 psc->base.driScreen = psp;
792 psp->destroyScreen = dri2DestroyScreen;
793 psp->createContext = dri2CreateContext;
794 psp->createDrawable = dri2CreateDrawable;
795 psp->swapBuffers = dri2SwapBuffers;
796 psp->waitGL = dri2WaitGL;
797 psp->waitX = dri2WaitX;
798 psp->getDrawableMSC = NULL;
799 psp->waitForMSC = NULL;
800 psp->waitForSBC = NULL;
801 psp->setSwapInterval = NULL;
802 psp->getSwapInterval = NULL;
804 if (pdp->driMinor >= 2) {
806 psp->getDrawableMSC = dri2DrawableGetMSC;
809 psp->waitForMSC = dri2WaitForMSC;
810 psp->waitForSBC = dri2WaitForSBC;
812 #ifdef X_DRI2SwapInterval
813 psp->setSwapInterval = dri2SetSwapInterval;
814 psp->getSwapInterval = dri2GetSwapInterval;
816 #if defined(X_DRI2GetMSC) && defined(X_DRI2WaitMSC) && defined(X_DRI2SwapInterval)
817 __glXEnableDirectExtension(&psc->base, "GLX_OML_sync_control");
821 /* DRI2 suports SubBuffer through DRI2CopyRegion, so it's always
823 psp->copySubBuffer = dri2CopySubBuffer;
824 __glXEnableDirectExtension(&psc->base, "GLX_MESA_copy_sub_buffer");
826 psc->base.direct_context_vtable = &dri2_context_vtable;
838 /* FIXME: clean up here */
843 /* Called from __glXFreeDisplayPrivate.
846 dri2DestroyDisplay(__GLXDRIdisplay * dpy)
851 _X_HIDDEN __GLXDRIdrawable *
852 dri2GetGlxDrawableFromXDrawableId(Display *dpy, XID id)
854 __GLXdisplayPrivate *d = __glXInitialize(dpy);
855 struct dri2_display *pdp = (struct dri2_display *) d->dri2Display;
856 __GLXDRIdrawable *pdraw;
858 if (__glxHashLookup(pdp->dri2Hash, id, (void *) &pdraw) == 0)
865 * Allocate, initialize and return a __DRIdisplayPrivate object.
866 * This is called from __glXInitialize() when we are given a new
869 _X_HIDDEN __GLXDRIdisplay *
870 dri2CreateDisplay(Display * dpy)
872 struct dri2_display *pdp;
873 int eventBase, errorBase, i;
875 if (!DRI2QueryExtension(dpy, &eventBase, &errorBase))
878 pdp = Xmalloc(sizeof *pdp);
882 if (!DRI2QueryVersion(dpy, &pdp->driMajor, &pdp->driMinor)) {
888 pdp->swapAvailable = (pdp->driMinor >= 2);
889 pdp->invalidateAvailable = (pdp->driMinor >= 3);
891 pdp->base.destroyDisplay = dri2DestroyDisplay;
892 pdp->base.createScreen = dri2CreateScreen;
895 if (pdp->driMinor < 1)
896 pdp->loader_extensions[i++] = &dri2LoaderExtension_old.base;
898 pdp->loader_extensions[i++] = &dri2LoaderExtension.base;
900 pdp->loader_extensions[i++] = &systemTimeExtension.base;
902 #ifdef __DRI_USE_INVALIDATE
903 pdp->loader_extensions[i++] = &dri2UseInvalidate.base;
905 pdp->loader_extensions[i++] = NULL;
907 pdp->dri2Hash = __glxHashCreate();
908 if (pdp->dri2Hash == NULL) {
916 #endif /* GLX_DIRECT_RENDERING */