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 __GLXDRIscreen driScreen
;
82 const __DRIdri2Extension
*dri2
;
83 const __DRIcoreExtension
*core
;
91 __DRIcontext
*driContext
;
92 __GLXscreenConfigs
*psc
;
97 __GLXDRIdrawable base
;
98 __DRIbuffer buffers
[5];
107 dri2DestroyContext(__GLXDRIcontext
*context
,
108 __GLXscreenConfigs
*base
, Display
*dpy
)
110 struct dri2_context
*pcp
= (struct dri2_context
*) context
;
111 struct dri2_screen
*psc
= (struct dri2_screen
*) base
;
113 (*psc
->core
->destroyContext
) (pcp
->driContext
);
119 dri2BindContext(__GLXDRIcontext
*context
,
120 __GLXDRIdrawable
*draw
, __GLXDRIdrawable
*read
)
122 struct dri2_context
*pcp
= (struct dri2_context
*) context
;
123 struct dri2_screen
*psc
= (struct dri2_screen
*) pcp
->psc
;
125 return (*psc
->core
->bindContext
) (pcp
->driContext
,
126 draw
->driDrawable
, read
->driDrawable
);
130 dri2UnbindContext(__GLXDRIcontext
*context
)
132 struct dri2_context
*pcp
= (struct dri2_context
*) context
;
133 struct dri2_screen
*psc
= (struct dri2_screen
*) pcp
->psc
;
135 (*psc
->core
->unbindContext
) (pcp
->driContext
);
138 static __GLXDRIcontext
*
139 dri2CreateContext(__GLXscreenConfigs
*base
,
140 const __GLcontextModes
* mode
,
141 GLXContext gc
, GLXContext shareList
, int renderType
)
143 struct dri2_context
*pcp
, *pcp_shared
;
144 struct dri2_screen
*psc
= (struct dri2_screen
*) base
;
145 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) mode
;
146 __DRIcontext
*shared
= NULL
;
149 pcp_shared
= (struct dri2_context
*) shareList
->driContext
;
150 shared
= pcp_shared
->driContext
;
153 pcp
= Xmalloc(sizeof *pcp
);
157 pcp
->psc
= &psc
->base
;
159 (*psc
->dri2
->createNewContext
) (psc
->base
.__driScreen
,
160 config
->driConfig
, shared
, pcp
);
161 gc
->__driContext
= pcp
->driContext
;
163 if (pcp
->driContext
== NULL
) {
168 pcp
->base
.destroyContext
= dri2DestroyContext
;
169 pcp
->base
.bindContext
= dri2BindContext
;
170 pcp
->base
.unbindContext
= dri2UnbindContext
;
176 dri2DestroyDrawable(__GLXDRIdrawable
*pdraw
)
178 struct dri2_screen
*psc
= (struct dri2_screen
*) pdraw
->psc
;
179 __GLXdisplayPrivate
*dpyPriv
;
180 struct dri2_display
*pdp
;
182 dpyPriv
= __glXInitialize(pdraw
->psc
->dpy
);
183 pdp
= (struct dri2_display
*)dpyPriv
->dri2Display
;
185 __glxHashDelete(pdp
->dri2Hash
, pdraw
->xDrawable
);
186 (*psc
->core
->destroyDrawable
) (pdraw
->driDrawable
);
187 DRI2DestroyDrawable(psc
->base
.dpy
, pdraw
->xDrawable
);
191 static __GLXDRIdrawable
*
192 dri2CreateDrawable(__GLXscreenConfigs
*base
, XID xDrawable
,
193 GLXDrawable drawable
, const __GLcontextModes
* modes
)
195 struct dri2_drawable
*pdraw
;
196 struct dri2_screen
*psc
= (struct dri2_screen
*) base
;
197 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) modes
;
198 __GLXdisplayPrivate
*dpyPriv
;
199 struct dri2_display
*pdp
;
200 GLint vblank_mode
= DRI_CONF_VBLANK_DEF_INTERVAL_1
;
202 pdraw
= Xmalloc(sizeof(*pdraw
));
206 pdraw
->base
.destroyDrawable
= dri2DestroyDrawable
;
207 pdraw
->base
.xDrawable
= xDrawable
;
208 pdraw
->base
.drawable
= drawable
;
209 pdraw
->base
.psc
= &psc
->base
;
210 pdraw
->bufferCount
= 0;
211 pdraw
->swap_interval
= 1; /* default may be overridden below */
212 pdraw
->have_back
= 0;
214 if (psc
->base
.config
)
215 psc
->base
.config
->configQueryi(psc
->base
.__driScreen
,
216 "vblank_mode", &vblank_mode
);
218 switch (vblank_mode
) {
219 case DRI_CONF_VBLANK_NEVER
:
220 case DRI_CONF_VBLANK_DEF_INTERVAL_0
:
221 pdraw
->swap_interval
= 0;
223 case DRI_CONF_VBLANK_DEF_INTERVAL_1
:
224 case DRI_CONF_VBLANK_ALWAYS_SYNC
:
226 pdraw
->swap_interval
= 1;
230 DRI2CreateDrawable(psc
->base
.dpy
, xDrawable
);
232 dpyPriv
= __glXInitialize(psc
->base
.dpy
);
233 pdp
= (struct dri2_display
*)dpyPriv
->dri2Display
;;
234 /* Create a new drawable */
235 pdraw
->base
.driDrawable
=
236 (*psc
->dri2
->createNewDrawable
) (psc
->base
.__driScreen
,
237 config
->driConfig
, pdraw
);
239 if (!pdraw
->base
.driDrawable
) {
240 DRI2DestroyDrawable(psc
->base
.dpy
, xDrawable
);
245 if (__glxHashInsert(pdp
->dri2Hash
, xDrawable
, pdraw
)) {
246 (*psc
->core
->destroyDrawable
) (pdraw
->base
.driDrawable
);
247 DRI2DestroyDrawable(psc
->base
.dpy
, xDrawable
);
253 #ifdef X_DRI2SwapInterval
255 * Make sure server has the same swap interval we do for the new
258 if (pdp
->swapAvailable
)
259 DRI2SwapInterval(psc
->base
.dpy
, xDrawable
, pdraw
->swap_interval
);
268 dri2DrawableGetMSC(__GLXscreenConfigs
*psc
, __GLXDRIdrawable
*pdraw
,
269 int64_t *ust
, int64_t *msc
, int64_t *sbc
)
271 return DRI2GetMSC(psc
->dpy
, pdraw
->xDrawable
, ust
, msc
, sbc
);
280 dri2WaitForMSC(__GLXDRIdrawable
*pdraw
, int64_t target_msc
, int64_t divisor
,
281 int64_t remainder
, int64_t *ust
, int64_t *msc
, int64_t *sbc
)
283 return DRI2WaitMSC(pdraw
->psc
->dpy
, pdraw
->xDrawable
, target_msc
, divisor
,
284 remainder
, ust
, msc
, sbc
);
288 dri2WaitForSBC(__GLXDRIdrawable
*pdraw
, int64_t target_sbc
, int64_t *ust
,
289 int64_t *msc
, int64_t *sbc
)
291 return DRI2WaitSBC(pdraw
->psc
->dpy
, pdraw
->xDrawable
, target_sbc
, ust
, msc
,
295 #endif /* X_DRI2WaitMSC */
298 dri2CopySubBuffer(__GLXDRIdrawable
*pdraw
, int x
, int y
, int width
, int height
)
300 struct dri2_drawable
*priv
= (struct dri2_drawable
*) pdraw
;
302 XserverRegion region
;
304 /* Check we have the right attachments */
305 if (!priv
->have_back
)
309 xrect
.y
= priv
->height
- y
- height
;
311 xrect
.height
= height
;
315 (*pdraw
->psc
->f
->flush
) (pdraw
->driDrawable
);
318 region
= XFixesCreateRegion(pdraw
->psc
->dpy
, &xrect
, 1);
319 DRI2CopyRegion(pdraw
->psc
->dpy
, pdraw
->xDrawable
, region
,
320 DRI2BufferFrontLeft
, DRI2BufferBackLeft
);
321 XFixesDestroyRegion(pdraw
->psc
->dpy
, region
);
323 /* Refresh the fake front (if present) after we just damaged the real
326 DRI2CopyRegion(pdraw
->psc
->dpy
, pdraw
->xDrawable
, region
,
327 DRI2BufferFakeFrontLeft
, DRI2BufferFrontLeft
);
328 XFixesDestroyRegion(pdraw
->psc
->dpy
, region
);
332 dri2_copy_drawable(struct dri2_drawable
*priv
, int dest
, int src
)
335 XserverRegion region
;
336 __GLXscreenConfigs
*const psc
= priv
->base
.psc
;
340 xrect
.width
= priv
->width
;
341 xrect
.height
= priv
->height
;
345 (*psc
->f
->flush
) (priv
->base
.driDrawable
);
348 region
= XFixesCreateRegion(psc
->dpy
, &xrect
, 1);
349 DRI2CopyRegion(psc
->dpy
, priv
->base
.xDrawable
, region
, dest
, src
);
350 XFixesDestroyRegion(psc
->dpy
, region
);
355 dri2WaitX(__GLXDRIdrawable
*pdraw
)
357 struct dri2_drawable
*priv
= (struct dri2_drawable
*) pdraw
;
359 if (!priv
->have_fake_front
)
362 dri2_copy_drawable(priv
, DRI2BufferFakeFrontLeft
, DRI2BufferFrontLeft
);
366 dri2WaitGL(__GLXDRIdrawable
* pdraw
)
368 struct dri2_drawable
*priv
= (struct dri2_drawable
*) pdraw
;
370 if (!priv
->have_fake_front
)
373 dri2_copy_drawable(priv
, DRI2BufferFrontLeft
, DRI2BufferFakeFrontLeft
);
377 dri2FlushFrontBuffer(__DRIdrawable
*driDrawable
, void *loaderPrivate
)
379 struct dri2_drawable
*pdraw
= loaderPrivate
;
380 __GLXdisplayPrivate
*priv
= __glXInitialize(pdraw
->base
.psc
->dpy
);
381 struct dri2_display
*pdp
= (struct dri2_display
*)priv
->dri2Display
;
383 /* Old servers don't send invalidate events */
384 if (!pdp
->invalidateAvailable
)
385 dri2InvalidateBuffers(priv
->dpy
, pdraw
->base
.drawable
);
387 dri2WaitGL(loaderPrivate
);
392 dri2DestroyScreen(__GLXscreenConfigs
*base
)
394 struct dri2_screen
*psc
= (struct dri2_screen
*) base
;
396 /* Free the direct rendering per screen data */
397 (*psc
->core
->destroyScreen
) (psc
->base
.__driScreen
);
399 base
->__driScreen
= NULL
;
404 * Process list of buffer received from the server
406 * Processes the list of buffers received in a reply from the server to either
407 * \c DRI2GetBuffers or \c DRI2GetBuffersWithFormat.
410 process_buffers(struct dri2_drawable
* pdraw
, DRI2Buffer
* buffers
,
415 pdraw
->bufferCount
= count
;
416 pdraw
->have_fake_front
= 0;
417 pdraw
->have_back
= 0;
419 /* This assumes the DRI2 buffer attachment tokens matches the
420 * __DRIbuffer tokens. */
421 for (i
= 0; i
< count
; i
++) {
422 pdraw
->buffers
[i
].attachment
= buffers
[i
].attachment
;
423 pdraw
->buffers
[i
].name
= buffers
[i
].name
;
424 pdraw
->buffers
[i
].pitch
= buffers
[i
].pitch
;
425 pdraw
->buffers
[i
].cpp
= buffers
[i
].cpp
;
426 pdraw
->buffers
[i
].flags
= buffers
[i
].flags
;
427 if (pdraw
->buffers
[i
].attachment
== __DRI_BUFFER_FAKE_FRONT_LEFT
)
428 pdraw
->have_fake_front
= 1;
429 if (pdraw
->buffers
[i
].attachment
== __DRI_BUFFER_BACK_LEFT
)
430 pdraw
->have_back
= 1;
436 dri2SwapBuffers(__GLXDRIdrawable
*pdraw
, int64_t target_msc
, int64_t divisor
,
439 struct dri2_drawable
*priv
= (struct dri2_drawable
*) pdraw
;
440 __GLXdisplayPrivate
*dpyPriv
= __glXInitialize(priv
->base
.psc
->dpy
);
441 struct dri2_display
*pdp
=
442 (struct dri2_display
*)dpyPriv
->dri2Display
;
447 (*pdraw
->psc
->f
->flush
)(pdraw
->driDrawable
);
450 /* Old servers don't send invalidate events */
451 if (!pdp
->invalidateAvailable
)
452 dri2InvalidateBuffers(dpyPriv
->dpy
, pdraw
->drawable
);
454 /* Old servers can't handle swapbuffers */
455 if (!pdp
->swapAvailable
) {
456 dri2CopySubBuffer(pdraw
, 0, 0, priv
->width
, priv
->height
);
460 #ifdef X_DRI2SwapBuffers
461 DRI2SwapBuffers(pdraw
->psc
->dpy
, pdraw
->xDrawable
, target_msc
, divisor
,
469 dri2GetBuffers(__DRIdrawable
* driDrawable
,
470 int *width
, int *height
,
471 unsigned int *attachments
, int count
,
472 int *out_count
, void *loaderPrivate
)
474 struct dri2_drawable
*pdraw
= loaderPrivate
;
477 buffers
= DRI2GetBuffers(pdraw
->base
.psc
->dpy
, pdraw
->base
.xDrawable
,
478 width
, height
, attachments
, count
, out_count
);
482 pdraw
->width
= *width
;
483 pdraw
->height
= *height
;
484 process_buffers(pdraw
, buffers
, *out_count
);
488 return pdraw
->buffers
;
492 dri2GetBuffersWithFormat(__DRIdrawable
* driDrawable
,
493 int *width
, int *height
,
494 unsigned int *attachments
, int count
,
495 int *out_count
, void *loaderPrivate
)
497 struct dri2_drawable
*pdraw
= loaderPrivate
;
500 buffers
= DRI2GetBuffersWithFormat(pdraw
->base
.psc
->dpy
,
501 pdraw
->base
.xDrawable
,
502 width
, height
, attachments
,
507 pdraw
->width
= *width
;
508 pdraw
->height
= *height
;
509 process_buffers(pdraw
, buffers
, *out_count
);
513 return pdraw
->buffers
;
516 #ifdef X_DRI2SwapInterval
519 dri2SetSwapInterval(__GLXDRIdrawable
*pdraw
, int interval
)
521 __GLXscreenConfigs
*psc
= pdraw
->psc
;
522 struct dri2_drawable
*priv
= (struct dri2_drawable
*) pdraw
;
523 GLint vblank_mode
= DRI_CONF_VBLANK_DEF_INTERVAL_1
;
526 psc
->config
->configQueryi(psc
->__driScreen
, "vblank_mode", &vblank_mode
);
528 switch (vblank_mode
) {
529 case DRI_CONF_VBLANK_NEVER
:
531 case DRI_CONF_VBLANK_ALWAYS_SYNC
:
539 DRI2SwapInterval(priv
->base
.psc
->dpy
, pdraw
->xDrawable
, interval
);
540 priv
->swap_interval
= interval
;
544 dri2GetSwapInterval(__GLXDRIdrawable
*pdraw
)
546 struct dri2_drawable
*priv
= (struct dri2_drawable
*) pdraw
;
548 return priv
->swap_interval
;
551 #endif /* X_DRI2SwapInterval */
553 static const __DRIdri2LoaderExtension dri2LoaderExtension
= {
554 {__DRI_DRI2_LOADER
, __DRI_DRI2_LOADER_VERSION
},
556 dri2FlushFrontBuffer
,
557 dri2GetBuffersWithFormat
,
560 static const __DRIdri2LoaderExtension dri2LoaderExtension_old
= {
561 {__DRI_DRI2_LOADER
, __DRI_DRI2_LOADER_VERSION
},
563 dri2FlushFrontBuffer
,
567 #ifdef __DRI_USE_INVALIDATE
568 static const __DRIuseInvalidateExtension dri2UseInvalidate
= {
569 { __DRI_USE_INVALIDATE
, __DRI_USE_INVALIDATE_VERSION
}
574 dri2InvalidateBuffers(Display
*dpy
, XID drawable
)
576 __GLXDRIdrawable
*pdraw
=
577 dri2GetGlxDrawableFromXDrawableId(dpy
, drawable
);
579 #if __DRI2_FLUSH_VERSION >= 3
580 if (pdraw
&& pdraw
->psc
->f
)
581 pdraw
->psc
->f
->invalidate(pdraw
->driDrawable
);
586 dri2_bind_tex_image(Display
* dpy
,
587 GLXDrawable drawable
,
588 int buffer
, const int *attrib_list
)
590 GLXContext gc
= __glXGetCurrentContext();
591 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
592 __GLXdisplayPrivate
*dpyPriv
= __glXInitialize(dpy
);
593 struct dri2_display
*pdp
=
594 (struct dri2_display
*) dpyPriv
->dri2Display
;
598 #if __DRI2_FLUSH_VERSION >= 3
599 if (!pdp
->invalidateAvailable
&& pdraw
->psc
->f
)
600 pdraw
->psc
->f
->invalidate(pdraw
->driDrawable
);
603 if (pdraw
->psc
->texBuffer
->base
.version
>= 2 &&
604 pdraw
->psc
->texBuffer
->setTexBuffer2
!= NULL
) {
605 (*pdraw
->psc
->texBuffer
->setTexBuffer2
) (gc
->__driContext
,
606 pdraw
->textureTarget
,
607 pdraw
->textureFormat
,
611 (*pdraw
->psc
->texBuffer
->setTexBuffer
) (gc
->__driContext
,
612 pdraw
->textureTarget
,
619 dri2_release_tex_image(Display
* dpy
, GLXDrawable drawable
, int buffer
)
623 static const struct glx_context_vtable dri2_context_vtable
= {
625 dri2_release_tex_image
,
628 static __GLXscreenConfigs
*
629 dri2CreateScreen(int screen
, __GLXdisplayPrivate
* priv
)
631 const __DRIconfig
**driver_configs
;
632 const __DRIextension
**extensions
;
633 const struct dri2_display
*const pdp
= (struct dri2_display
*)
635 struct dri2_screen
*psc
;
637 char *driverName
, *deviceName
;
641 psc
= Xmalloc(sizeof *psc
);
645 memset(psc
, 0, sizeof *psc
);
646 if (!glx_screen_init(&psc
->base
, screen
, priv
))
649 if (!DRI2Connect(priv
->dpy
, RootWindow(priv
->dpy
, screen
),
650 &driverName
, &deviceName
)) {
655 psc
->driver
= driOpenDriver(driverName
);
656 if (psc
->driver
== NULL
) {
657 ErrorMessageF("driver pointer missing\n");
661 extensions
= dlsym(psc
->driver
, __DRI_DRIVER_EXTENSIONS
);
662 if (extensions
== NULL
) {
663 ErrorMessageF("driver exports no extensions (%s)\n", dlerror());
667 for (i
= 0; extensions
[i
]; i
++) {
668 if (strcmp(extensions
[i
]->name
, __DRI_CORE
) == 0)
669 psc
->core
= (__DRIcoreExtension
*) extensions
[i
];
670 if (strcmp(extensions
[i
]->name
, __DRI_DRI2
) == 0)
671 psc
->dri2
= (__DRIdri2Extension
*) extensions
[i
];
674 if (psc
->core
== NULL
|| psc
->dri2
== NULL
) {
675 ErrorMessageF("core dri or dri2 extension not found\n");
679 psc
->fd
= open(deviceName
, O_RDWR
);
681 ErrorMessageF("failed to open drm device: %s\n", strerror(errno
));
685 if (drmGetMagic(psc
->fd
, &magic
)) {
686 ErrorMessageF("failed to get magic\n");
690 if (!DRI2Authenticate(priv
->dpy
, RootWindow(priv
->dpy
, screen
), magic
)) {
691 ErrorMessageF("failed to authenticate magic %d\n", magic
);
696 /* If the server does not support the protocol for
697 * DRI2GetBuffersWithFormat, don't supply that interface to the driver.
699 psc
->base
.__driScreen
=
700 psc
->dri2
->createNewScreen(screen
, psc
->fd
,
701 (const __DRIextension
**)
702 &pdp
->loader_extensions
[0],
703 &driver_configs
, psc
);
705 if (psc
->base
.__driScreen
== NULL
) {
706 ErrorMessageF("failed to create dri screen\n");
710 extensions
= psc
->core
->getExtensions(psc
->base
.__driScreen
);
711 driBindCommonExtensions(&psc
->base
, extensions
);
712 dri2BindExtensions(&psc
->base
, extensions
);
715 driConvertConfigs(psc
->core
, psc
->base
.configs
, driver_configs
);
717 driConvertConfigs(psc
->core
, psc
->base
.visuals
, driver_configs
);
719 psc
->base
.driver_configs
= driver_configs
;
721 psp
= &psc
->driScreen
;
722 psc
->base
.driScreen
= psp
;
723 psp
->destroyScreen
= dri2DestroyScreen
;
724 psp
->createContext
= dri2CreateContext
;
725 psp
->createDrawable
= dri2CreateDrawable
;
726 psp
->swapBuffers
= dri2SwapBuffers
;
727 psp
->waitGL
= dri2WaitGL
;
728 psp
->waitX
= dri2WaitX
;
729 psp
->getDrawableMSC
= NULL
;
730 psp
->waitForMSC
= NULL
;
731 psp
->waitForSBC
= NULL
;
732 psp
->setSwapInterval
= NULL
;
733 psp
->getSwapInterval
= NULL
;
735 if (pdp
->driMinor
>= 2) {
737 psp
->getDrawableMSC
= dri2DrawableGetMSC
;
740 psp
->waitForMSC
= dri2WaitForMSC
;
741 psp
->waitForSBC
= dri2WaitForSBC
;
743 #ifdef X_DRI2SwapInterval
744 psp
->setSwapInterval
= dri2SetSwapInterval
;
745 psp
->getSwapInterval
= dri2GetSwapInterval
;
747 #if defined(X_DRI2GetMSC) && defined(X_DRI2WaitMSC) && defined(X_DRI2SwapInterval)
748 __glXEnableDirectExtension(&psc
->base
, "GLX_OML_sync_control");
752 /* DRI2 suports SubBuffer through DRI2CopyRegion, so it's always
754 psp
->copySubBuffer
= dri2CopySubBuffer
;
755 __glXEnableDirectExtension(&psc
->base
, "GLX_MESA_copy_sub_buffer");
757 psc
->base
.direct_context_vtable
= &dri2_context_vtable
;
769 /* FIXME: clean up here */
774 /* Called from __glXFreeDisplayPrivate.
777 dri2DestroyDisplay(__GLXDRIdisplay
* dpy
)
782 _X_HIDDEN __GLXDRIdrawable
*
783 dri2GetGlxDrawableFromXDrawableId(Display
*dpy
, XID id
)
785 __GLXdisplayPrivate
*d
= __glXInitialize(dpy
);
786 struct dri2_display
*pdp
= (struct dri2_display
*) d
->dri2Display
;
787 __GLXDRIdrawable
*pdraw
;
789 if (__glxHashLookup(pdp
->dri2Hash
, id
, (void *) &pdraw
) == 0)
796 * Allocate, initialize and return a __DRIdisplayPrivate object.
797 * This is called from __glXInitialize() when we are given a new
800 _X_HIDDEN __GLXDRIdisplay
*
801 dri2CreateDisplay(Display
* dpy
)
803 struct dri2_display
*pdp
;
804 int eventBase
, errorBase
, i
;
806 if (!DRI2QueryExtension(dpy
, &eventBase
, &errorBase
))
809 pdp
= Xmalloc(sizeof *pdp
);
813 if (!DRI2QueryVersion(dpy
, &pdp
->driMajor
, &pdp
->driMinor
)) {
819 pdp
->swapAvailable
= (pdp
->driMinor
>= 2);
820 pdp
->invalidateAvailable
= (pdp
->driMinor
>= 3);
822 pdp
->base
.destroyDisplay
= dri2DestroyDisplay
;
823 pdp
->base
.createScreen
= dri2CreateScreen
;
826 if (pdp
->driMinor
< 1)
827 pdp
->loader_extensions
[i
++] = &dri2LoaderExtension_old
.base
;
829 pdp
->loader_extensions
[i
++] = &dri2LoaderExtension
.base
;
831 pdp
->loader_extensions
[i
++] = &systemTimeExtension
.base
;
833 #ifdef __DRI_USE_INVALIDATE
834 pdp
->loader_extensions
[i
++] = &dri2UseInvalidate
.base
;
836 pdp
->loader_extensions
[i
++] = NULL
;
838 pdp
->dri2Hash
= __glxHashCreate();
839 if (pdp
->dri2Hash
== NULL
) {
847 #endif /* GLX_DIRECT_RENDERING */