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/Xlib-xcb.h>
40 #include "glxclient.h"
41 #include <X11/extensions/dri2proto.h>
45 #include <sys/types.h>
49 #include "dri_common.h"
50 #include "dri2_priv.h"
53 /* From xmlpool/options.h, user exposed so should be stable */
54 #define DRI_CONF_VBLANK_NEVER 0
55 #define DRI_CONF_VBLANK_DEF_INTERVAL_0 1
56 #define DRI_CONF_VBLANK_DEF_INTERVAL_1 2
57 #define DRI_CONF_VBLANK_ALWAYS_SYNC 3
67 ** XFree86-DRI version information
73 int invalidateAvailable
;
75 __glxHashTable
*dri2Hash
;
77 const __DRIextension
*loader_extensions
[5];
82 __GLXDRIdrawable base
;
83 __DRIdrawable
*driDrawable
;
84 __DRIbuffer buffers
[5];
91 uint64_t previous_time
;
95 static const struct glx_context_vtable dri2_context_vtable
;
97 /* For XCB's handling of ust/msc/sbc counters, we have to hand it the high and
98 * low halves separately. This helps you split them.
101 split_counter(uint64_t counter
, uint32_t *hi
, uint32_t *lo
)
103 *hi
= (counter
>> 32);
104 *lo
= counter
& 0xffffffff;
108 merge_counter(uint32_t hi
, uint32_t lo
)
110 return ((uint64_t)hi
<< 32) | lo
;
114 dri2_destroy_context(struct glx_context
*context
)
116 struct dri2_context
*pcp
= (struct dri2_context
*) context
;
117 struct dri2_screen
*psc
= (struct dri2_screen
*) context
->psc
;
119 driReleaseDrawables(&pcp
->base
);
121 free((char *) context
->extensions
);
123 (*psc
->core
->destroyContext
) (pcp
->driContext
);
129 dri2_bind_context(struct glx_context
*context
, struct glx_context
*old
,
130 GLXDrawable draw
, GLXDrawable read
)
132 struct dri2_context
*pcp
= (struct dri2_context
*) context
;
133 struct dri2_screen
*psc
= (struct dri2_screen
*) pcp
->base
.psc
;
134 struct dri2_drawable
*pdraw
, *pread
;
135 __DRIdrawable
*dri_draw
= NULL
, *dri_read
= NULL
;
136 struct glx_display
*dpyPriv
= psc
->base
.display
;
137 struct dri2_display
*pdp
;
139 pdraw
= (struct dri2_drawable
*) driFetchDrawable(context
, draw
);
140 pread
= (struct dri2_drawable
*) driFetchDrawable(context
, read
);
142 driReleaseDrawables(&pcp
->base
);
145 dri_draw
= pdraw
->driDrawable
;
146 else if (draw
!= None
)
147 return GLXBadDrawable
;
150 dri_read
= pread
->driDrawable
;
151 else if (read
!= None
)
152 return GLXBadDrawable
;
154 if (!(*psc
->core
->bindContext
) (pcp
->driContext
, dri_draw
, dri_read
))
155 return GLXBadContext
;
157 /* If the server doesn't send invalidate events, we may miss a
158 * resize before the rendering starts. Invalidate the buffers now
159 * so the driver will recheck before rendering starts. */
160 pdp
= (struct dri2_display
*) dpyPriv
->dri2Display
;
161 if (!pdp
->invalidateAvailable
&& pdraw
) {
162 dri2InvalidateBuffers(psc
->base
.dpy
, pdraw
->base
.xDrawable
);
163 if (pread
!= pdraw
&& pread
)
164 dri2InvalidateBuffers(psc
->base
.dpy
, pread
->base
.xDrawable
);
171 dri2_unbind_context(struct glx_context
*context
, struct glx_context
*new)
173 struct dri2_context
*pcp
= (struct dri2_context
*) context
;
174 struct dri2_screen
*psc
= (struct dri2_screen
*) pcp
->base
.psc
;
176 (*psc
->core
->unbindContext
) (pcp
->driContext
);
179 static struct glx_context
*
180 dri2_create_context(struct glx_screen
*base
,
181 struct glx_config
*config_base
,
182 struct glx_context
*shareList
, int renderType
)
184 struct dri2_context
*pcp
, *pcp_shared
;
185 struct dri2_screen
*psc
= (struct dri2_screen
*) base
;
186 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) config_base
;
187 __DRIcontext
*shared
= NULL
;
189 /* Check the renderType value */
190 if (!validate_renderType_against_config(config_base
, renderType
))
194 /* If the shareList context is not a DRI2 context, we cannot possibly
195 * create a DRI2 context that shares it.
197 if (shareList
->vtable
->destroy
!= dri2_destroy_context
) {
201 pcp_shared
= (struct dri2_context
*) shareList
;
202 shared
= pcp_shared
->driContext
;
205 pcp
= calloc(1, sizeof *pcp
);
209 if (!glx_context_init(&pcp
->base
, &psc
->base
, &config
->base
)) {
214 pcp
->base
.renderType
= renderType
;
217 (*psc
->dri2
->createNewContext
) (psc
->driScreen
,
218 config
->driConfig
, shared
, pcp
);
220 if (pcp
->driContext
== NULL
) {
225 pcp
->base
.vtable
= &dri2_context_vtable
;
230 static struct glx_context
*
231 dri2_create_context_attribs(struct glx_screen
*base
,
232 struct glx_config
*config_base
,
233 struct glx_context
*shareList
,
234 unsigned num_attribs
,
235 const uint32_t *attribs
,
238 struct dri2_context
*pcp
= NULL
;
239 struct dri2_context
*pcp_shared
= NULL
;
240 struct dri2_screen
*psc
= (struct dri2_screen
*) base
;
241 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) config_base
;
242 __DRIcontext
*shared
= NULL
;
251 uint32_t ctx_attribs
[2 * 6];
252 unsigned num_ctx_attribs
= 0;
254 if (psc
->dri2
->base
.version
< 3) {
255 *error
= __DRI_CTX_ERROR_NO_MEMORY
;
259 /* Remap the GLX tokens to DRI2 tokens.
261 if (!dri2_convert_glx_attribs(num_attribs
, attribs
,
262 &major_ver
, &minor_ver
, &renderType
, &flags
,
263 &api
, &reset
, &release
, error
))
266 if (!dri2_check_no_error(flags
, shareList
, major_ver
, error
)) {
270 /* Check the renderType value */
271 if (!validate_renderType_against_config(config_base
, renderType
))
275 pcp_shared
= (struct dri2_context
*) shareList
;
276 shared
= pcp_shared
->driContext
;
279 pcp
= calloc(1, sizeof *pcp
);
281 *error
= __DRI_CTX_ERROR_NO_MEMORY
;
285 if (!glx_context_init(&pcp
->base
, &psc
->base
, config_base
))
288 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_MAJOR_VERSION
;
289 ctx_attribs
[num_ctx_attribs
++] = major_ver
;
290 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_MINOR_VERSION
;
291 ctx_attribs
[num_ctx_attribs
++] = minor_ver
;
293 /* Only send a value when the non-default value is requested. By doing
294 * this we don't have to check the driver's DRI2 version before sending the
297 if (reset
!= __DRI_CTX_RESET_NO_NOTIFICATION
) {
298 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_RESET_STRATEGY
;
299 ctx_attribs
[num_ctx_attribs
++] = reset
;
302 if (release
!= __DRI_CTX_RELEASE_BEHAVIOR_FLUSH
) {
303 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_RELEASE_BEHAVIOR
;
304 ctx_attribs
[num_ctx_attribs
++] = release
;
308 ctx_attribs
[num_ctx_attribs
++] = __DRI_CTX_ATTRIB_FLAGS
;
310 /* The current __DRI_CTX_FLAG_* values are identical to the
311 * GLX_CONTEXT_*_BIT values.
313 ctx_attribs
[num_ctx_attribs
++] = flags
;
316 /* The renderType is retrieved from attribs, or set to default
319 pcp
->base
.renderType
= renderType
;
321 if (flags
& __DRI_CTX_FLAG_NO_ERROR
)
322 pcp
->base
.noError
= GL_TRUE
;
325 (*psc
->dri2
->createContextAttribs
) (psc
->driScreen
,
327 config
? config
->driConfig
: NULL
,
334 if (pcp
->driContext
== NULL
)
337 pcp
->base
.vtable
= &dri2_context_vtable
;
348 dri2DestroyDrawable(__GLXDRIdrawable
*base
)
350 struct dri2_screen
*psc
= (struct dri2_screen
*) base
->psc
;
351 struct dri2_drawable
*pdraw
= (struct dri2_drawable
*) base
;
352 struct glx_display
*dpyPriv
= psc
->base
.display
;
353 struct dri2_display
*pdp
= (struct dri2_display
*)dpyPriv
->dri2Display
;
355 __glxHashDelete(pdp
->dri2Hash
, pdraw
->base
.xDrawable
);
356 (*psc
->core
->destroyDrawable
) (pdraw
->driDrawable
);
358 /* If it's a GLX 1.3 drawables, we can destroy the DRI2 drawable
359 * now, as the application explicitly asked to destroy the GLX
360 * drawable. Otherwise, for legacy drawables, we let the DRI2
361 * drawable linger on the server, since there's no good way of
362 * knowing when the application is done with it. The server will
363 * destroy the DRI2 drawable when it destroys the X drawable or the
364 * client exits anyway. */
365 if (pdraw
->base
.xDrawable
!= pdraw
->base
.drawable
)
366 DRI2DestroyDrawable(psc
->base
.dpy
, pdraw
->base
.xDrawable
);
371 static __GLXDRIdrawable
*
372 dri2CreateDrawable(struct glx_screen
*base
, XID xDrawable
,
373 GLXDrawable drawable
, struct glx_config
*config_base
)
375 struct dri2_drawable
*pdraw
;
376 struct dri2_screen
*psc
= (struct dri2_screen
*) base
;
377 __GLXDRIconfigPrivate
*config
= (__GLXDRIconfigPrivate
*) config_base
;
378 struct glx_display
*dpyPriv
;
379 struct dri2_display
*pdp
;
380 GLint vblank_mode
= DRI_CONF_VBLANK_DEF_INTERVAL_1
;
382 dpyPriv
= __glXInitialize(psc
->base
.dpy
);
386 pdraw
= calloc(1, sizeof(*pdraw
));
390 pdraw
->base
.destroyDrawable
= dri2DestroyDrawable
;
391 pdraw
->base
.xDrawable
= xDrawable
;
392 pdraw
->base
.drawable
= drawable
;
393 pdraw
->base
.psc
= &psc
->base
;
394 pdraw
->bufferCount
= 0;
395 pdraw
->swap_interval
= 1; /* default may be overridden below */
396 pdraw
->have_back
= 0;
399 psc
->config
->configQueryi(psc
->driScreen
,
400 "vblank_mode", &vblank_mode
);
402 switch (vblank_mode
) {
403 case DRI_CONF_VBLANK_NEVER
:
404 case DRI_CONF_VBLANK_DEF_INTERVAL_0
:
405 pdraw
->swap_interval
= 0;
407 case DRI_CONF_VBLANK_DEF_INTERVAL_1
:
408 case DRI_CONF_VBLANK_ALWAYS_SYNC
:
410 pdraw
->swap_interval
= 1;
414 DRI2CreateDrawable(psc
->base
.dpy
, xDrawable
);
415 pdp
= (struct dri2_display
*)dpyPriv
->dri2Display
;
416 /* Create a new drawable */
418 (*psc
->dri2
->createNewDrawable
) (psc
->driScreen
,
419 config
->driConfig
, pdraw
);
421 if (!pdraw
->driDrawable
) {
422 DRI2DestroyDrawable(psc
->base
.dpy
, xDrawable
);
427 if (__glxHashInsert(pdp
->dri2Hash
, xDrawable
, pdraw
)) {
428 (*psc
->core
->destroyDrawable
) (pdraw
->driDrawable
);
429 DRI2DestroyDrawable(psc
->base
.dpy
, xDrawable
);
435 * Make sure server has the same swap interval we do for the new
438 if (psc
->vtable
.setSwapInterval
)
439 psc
->vtable
.setSwapInterval(&pdraw
->base
, pdraw
->swap_interval
);
445 dri2DrawableGetMSC(struct glx_screen
*psc
, __GLXDRIdrawable
*pdraw
,
446 int64_t *ust
, int64_t *msc
, int64_t *sbc
)
448 xcb_connection_t
*c
= XGetXCBConnection(pdraw
->psc
->dpy
);
449 xcb_dri2_get_msc_cookie_t get_msc_cookie
;
450 xcb_dri2_get_msc_reply_t
*get_msc_reply
;
452 get_msc_cookie
= xcb_dri2_get_msc_unchecked(c
, pdraw
->xDrawable
);
453 get_msc_reply
= xcb_dri2_get_msc_reply(c
, get_msc_cookie
, NULL
);
458 *ust
= merge_counter(get_msc_reply
->ust_hi
, get_msc_reply
->ust_lo
);
459 *msc
= merge_counter(get_msc_reply
->msc_hi
, get_msc_reply
->msc_lo
);
460 *sbc
= merge_counter(get_msc_reply
->sbc_hi
, get_msc_reply
->sbc_lo
);
467 dri2WaitForMSC(__GLXDRIdrawable
*pdraw
, int64_t target_msc
, int64_t divisor
,
468 int64_t remainder
, int64_t *ust
, int64_t *msc
, int64_t *sbc
)
470 xcb_connection_t
*c
= XGetXCBConnection(pdraw
->psc
->dpy
);
471 xcb_dri2_wait_msc_cookie_t wait_msc_cookie
;
472 xcb_dri2_wait_msc_reply_t
*wait_msc_reply
;
473 uint32_t target_msc_hi
, target_msc_lo
;
474 uint32_t divisor_hi
, divisor_lo
;
475 uint32_t remainder_hi
, remainder_lo
;
477 split_counter(target_msc
, &target_msc_hi
, &target_msc_lo
);
478 split_counter(divisor
, &divisor_hi
, &divisor_lo
);
479 split_counter(remainder
, &remainder_hi
, &remainder_lo
);
481 wait_msc_cookie
= xcb_dri2_wait_msc_unchecked(c
, pdraw
->xDrawable
,
482 target_msc_hi
, target_msc_lo
,
483 divisor_hi
, divisor_lo
,
484 remainder_hi
, remainder_lo
);
485 wait_msc_reply
= xcb_dri2_wait_msc_reply(c
, wait_msc_cookie
, NULL
);
490 *ust
= merge_counter(wait_msc_reply
->ust_hi
, wait_msc_reply
->ust_lo
);
491 *msc
= merge_counter(wait_msc_reply
->msc_hi
, wait_msc_reply
->msc_lo
);
492 *sbc
= merge_counter(wait_msc_reply
->sbc_hi
, wait_msc_reply
->sbc_lo
);
493 free(wait_msc_reply
);
499 dri2WaitForSBC(__GLXDRIdrawable
*pdraw
, int64_t target_sbc
, int64_t *ust
,
500 int64_t *msc
, int64_t *sbc
)
502 xcb_connection_t
*c
= XGetXCBConnection(pdraw
->psc
->dpy
);
503 xcb_dri2_wait_sbc_cookie_t wait_sbc_cookie
;
504 xcb_dri2_wait_sbc_reply_t
*wait_sbc_reply
;
505 uint32_t target_sbc_hi
, target_sbc_lo
;
507 split_counter(target_sbc
, &target_sbc_hi
, &target_sbc_lo
);
509 wait_sbc_cookie
= xcb_dri2_wait_sbc_unchecked(c
, pdraw
->xDrawable
,
510 target_sbc_hi
, target_sbc_lo
);
511 wait_sbc_reply
= xcb_dri2_wait_sbc_reply(c
, wait_sbc_cookie
, NULL
);
516 *ust
= merge_counter(wait_sbc_reply
->ust_hi
, wait_sbc_reply
->ust_lo
);
517 *msc
= merge_counter(wait_sbc_reply
->msc_hi
, wait_sbc_reply
->msc_lo
);
518 *sbc
= merge_counter(wait_sbc_reply
->sbc_hi
, wait_sbc_reply
->sbc_lo
);
519 free(wait_sbc_reply
);
524 static __DRIcontext
*
525 dri2GetCurrentContext()
527 struct glx_context
*gc
= __glXGetCurrentContext();
528 struct dri2_context
*dri2Ctx
= (struct dri2_context
*)gc
;
530 return (gc
!= &dummyContext
) ? dri2Ctx
->driContext
: NULL
;
534 * dri2Throttle - Request driver throttling
536 * This function uses the DRI2 throttle extension to give the
537 * driver the opportunity to throttle on flush front, copysubbuffer
541 dri2Throttle(struct dri2_screen
*psc
,
542 struct dri2_drawable
*draw
,
543 enum __DRI2throttleReason reason
)
546 __DRIcontext
*ctx
= dri2GetCurrentContext();
548 psc
->throttle
->throttle(ctx
, draw
->driDrawable
, reason
);
553 * Asks the driver to flush any queued work necessary for serializing with the
554 * X command stream, and optionally the slightly more strict requirement of
555 * glFlush() equivalence (which would require flushing even if nothing had
556 * been drawn to a window system framebuffer, for example).
559 dri2Flush(struct dri2_screen
*psc
,
561 struct dri2_drawable
*draw
,
563 enum __DRI2throttleReason throttle_reason
)
565 if (ctx
&& psc
->f
&& psc
->f
->base
.version
>= 4) {
566 psc
->f
->flush_with_flags(ctx
, draw
->driDrawable
, flags
, throttle_reason
);
568 if (flags
& __DRI2_FLUSH_CONTEXT
)
572 psc
->f
->flush(draw
->driDrawable
);
574 dri2Throttle(psc
, draw
, throttle_reason
);
579 __dri2CopySubBuffer(__GLXDRIdrawable
*pdraw
, int x
, int y
,
580 int width
, int height
,
581 enum __DRI2throttleReason reason
, Bool flush
)
583 struct dri2_drawable
*priv
= (struct dri2_drawable
*) pdraw
;
584 struct dri2_screen
*psc
= (struct dri2_screen
*) pdraw
->psc
;
586 XserverRegion region
;
587 __DRIcontext
*ctx
= dri2GetCurrentContext();
590 /* Check we have the right attachments */
591 if (!priv
->have_back
)
595 xrect
.y
= priv
->height
- y
- height
;
597 xrect
.height
= height
;
599 flags
= __DRI2_FLUSH_DRAWABLE
;
601 flags
|= __DRI2_FLUSH_CONTEXT
;
602 dri2Flush(psc
, ctx
, priv
, flags
, __DRI2_THROTTLE_SWAPBUFFER
);
604 region
= XFixesCreateRegion(psc
->base
.dpy
, &xrect
, 1);
605 DRI2CopyRegion(psc
->base
.dpy
, pdraw
->xDrawable
, region
,
606 DRI2BufferFrontLeft
, DRI2BufferBackLeft
);
608 /* Refresh the fake front (if present) after we just damaged the real
611 if (priv
->have_fake_front
)
612 DRI2CopyRegion(psc
->base
.dpy
, pdraw
->xDrawable
, region
,
613 DRI2BufferFakeFrontLeft
, DRI2BufferFrontLeft
);
615 XFixesDestroyRegion(psc
->base
.dpy
, region
);
619 dri2CopySubBuffer(__GLXDRIdrawable
*pdraw
, int x
, int y
,
620 int width
, int height
, Bool flush
)
622 __dri2CopySubBuffer(pdraw
, x
, y
, width
, height
,
623 __DRI2_THROTTLE_COPYSUBBUFFER
, flush
);
628 dri2_copy_drawable(struct dri2_drawable
*priv
, int dest
, int src
)
631 XserverRegion region
;
632 struct dri2_screen
*psc
= (struct dri2_screen
*) priv
->base
.psc
;
636 xrect
.width
= priv
->width
;
637 xrect
.height
= priv
->height
;
640 (*psc
->f
->flush
) (priv
->driDrawable
);
642 region
= XFixesCreateRegion(psc
->base
.dpy
, &xrect
, 1);
643 DRI2CopyRegion(psc
->base
.dpy
, priv
->base
.xDrawable
, region
, dest
, src
);
644 XFixesDestroyRegion(psc
->base
.dpy
, region
);
649 dri2_wait_x(struct glx_context
*gc
)
651 struct dri2_drawable
*priv
= (struct dri2_drawable
*)
652 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
654 if (priv
== NULL
|| !priv
->have_fake_front
)
657 dri2_copy_drawable(priv
, DRI2BufferFakeFrontLeft
, DRI2BufferFrontLeft
);
661 dri2_wait_gl(struct glx_context
*gc
)
663 struct dri2_drawable
*priv
= (struct dri2_drawable
*)
664 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
666 if (priv
== NULL
|| !priv
->have_fake_front
)
669 dri2_copy_drawable(priv
, DRI2BufferFrontLeft
, DRI2BufferFakeFrontLeft
);
673 * Called by the driver when it needs to update the real front buffer with the
674 * contents of its fake front buffer.
677 dri2FlushFrontBuffer(__DRIdrawable
*driDrawable
, void *loaderPrivate
)
679 struct glx_display
*priv
;
680 struct dri2_display
*pdp
;
681 struct glx_context
*gc
;
682 struct dri2_drawable
*pdraw
= loaderPrivate
;
683 struct dri2_screen
*psc
;
688 if (!pdraw
->base
.psc
)
691 psc
= (struct dri2_screen
*) pdraw
->base
.psc
;
693 priv
= __glXInitialize(psc
->base
.dpy
);
698 pdp
= (struct dri2_display
*) priv
->dri2Display
;
699 gc
= __glXGetCurrentContext();
701 dri2Throttle(psc
, pdraw
, __DRI2_THROTTLE_FLUSHFRONT
);
703 /* Old servers don't send invalidate events */
704 if (!pdp
->invalidateAvailable
)
705 dri2InvalidateBuffers(priv
->dpy
, pdraw
->base
.xDrawable
);
712 dri2DestroyScreen(struct glx_screen
*base
)
714 struct dri2_screen
*psc
= (struct dri2_screen
*) base
;
716 /* Free the direct rendering per screen data */
717 (*psc
->core
->destroyScreen
) (psc
->driScreen
);
718 driDestroyConfigs(psc
->driver_configs
);
724 * Process list of buffer received from the server
726 * Processes the list of buffers received in a reply from the server to either
727 * \c DRI2GetBuffers or \c DRI2GetBuffersWithFormat.
730 process_buffers(struct dri2_drawable
* pdraw
, DRI2Buffer
* buffers
,
735 pdraw
->bufferCount
= count
;
736 pdraw
->have_fake_front
= 0;
737 pdraw
->have_back
= 0;
739 /* This assumes the DRI2 buffer attachment tokens matches the
740 * __DRIbuffer tokens. */
741 for (i
= 0; i
< count
; i
++) {
742 pdraw
->buffers
[i
].attachment
= buffers
[i
].attachment
;
743 pdraw
->buffers
[i
].name
= buffers
[i
].name
;
744 pdraw
->buffers
[i
].pitch
= buffers
[i
].pitch
;
745 pdraw
->buffers
[i
].cpp
= buffers
[i
].cpp
;
746 pdraw
->buffers
[i
].flags
= buffers
[i
].flags
;
747 if (pdraw
->buffers
[i
].attachment
== __DRI_BUFFER_FAKE_FRONT_LEFT
)
748 pdraw
->have_fake_front
= 1;
749 if (pdraw
->buffers
[i
].attachment
== __DRI_BUFFER_BACK_LEFT
)
750 pdraw
->have_back
= 1;
755 unsigned dri2GetSwapEventType(Display
* dpy
, XID drawable
)
757 struct glx_display
*glx_dpy
= __glXInitialize(dpy
);
758 __GLXDRIdrawable
*pdraw
;
759 pdraw
= dri2GetGlxDrawableFromXDrawableId(dpy
, drawable
);
760 if (!pdraw
|| !(pdraw
->eventMask
& GLX_BUFFER_SWAP_COMPLETE_INTEL_MASK
))
762 return glx_dpy
->codes
->first_event
+ GLX_BufferSwapComplete
;
765 static void show_fps(struct dri2_drawable
*draw
)
768 ((struct dri2_screen
*) draw
->base
.psc
)->show_fps_interval
;
770 uint64_t current_time
;
772 gettimeofday(&tv
, 0);
773 current_time
= (uint64_t)tv
.tv_sec
*1000000 + (uint64_t)tv
.tv_usec
;
777 if (draw
->previous_time
+ interval
* 1000000 <= current_time
) {
778 if (draw
->previous_time
) {
779 fprintf(stderr
, "libGL: FPS = %.1f\n",
780 ((uint64_t)draw
->frames
* 1000000) /
781 (double)(current_time
- draw
->previous_time
));
784 draw
->previous_time
= current_time
;
789 dri2XcbSwapBuffers(Display
*dpy
,
790 __GLXDRIdrawable
*pdraw
,
795 xcb_dri2_swap_buffers_cookie_t swap_buffers_cookie
;
796 xcb_dri2_swap_buffers_reply_t
*swap_buffers_reply
;
797 uint32_t target_msc_hi
, target_msc_lo
;
798 uint32_t divisor_hi
, divisor_lo
;
799 uint32_t remainder_hi
, remainder_lo
;
801 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
803 split_counter(target_msc
, &target_msc_hi
, &target_msc_lo
);
804 split_counter(divisor
, &divisor_hi
, &divisor_lo
);
805 split_counter(remainder
, &remainder_hi
, &remainder_lo
);
807 swap_buffers_cookie
=
808 xcb_dri2_swap_buffers_unchecked(c
, pdraw
->xDrawable
,
809 target_msc_hi
, target_msc_lo
,
810 divisor_hi
, divisor_lo
,
811 remainder_hi
, remainder_lo
);
813 /* Immediately wait on the swapbuffers reply. If we didn't, we'd have
814 * to do so some time before reusing a (non-pageflipped) backbuffer.
815 * Otherwise, the new rendering could get ahead of the X Server's
816 * dispatch of the swapbuffer and you'd display garbage.
818 * We use XSync() first to reap the invalidate events through the event
819 * filter, to ensure that the next drawing doesn't use an invalidated
825 xcb_dri2_swap_buffers_reply(c
, swap_buffers_cookie
, NULL
);
826 if (swap_buffers_reply
) {
827 ret
= merge_counter(swap_buffers_reply
->swap_hi
,
828 swap_buffers_reply
->swap_lo
);
829 free(swap_buffers_reply
);
835 dri2SwapBuffers(__GLXDRIdrawable
*pdraw
, int64_t target_msc
, int64_t divisor
,
836 int64_t remainder
, Bool flush
)
838 struct dri2_drawable
*priv
= (struct dri2_drawable
*) pdraw
;
839 struct glx_display
*dpyPriv
= __glXInitialize(priv
->base
.psc
->dpy
);
840 struct dri2_screen
*psc
= (struct dri2_screen
*) priv
->base
.psc
;
841 struct dri2_display
*pdp
=
842 (struct dri2_display
*)dpyPriv
->dri2Display
;
845 /* Check we have the right attachments */
846 if (!priv
->have_back
)
849 /* Old servers can't handle swapbuffers */
850 if (!pdp
->swapAvailable
) {
851 __dri2CopySubBuffer(pdraw
, 0, 0, priv
->width
, priv
->height
,
852 __DRI2_THROTTLE_SWAPBUFFER
, flush
);
854 __DRIcontext
*ctx
= dri2GetCurrentContext();
855 unsigned flags
= __DRI2_FLUSH_DRAWABLE
;
857 flags
|= __DRI2_FLUSH_CONTEXT
;
858 dri2Flush(psc
, ctx
, priv
, flags
, __DRI2_THROTTLE_SWAPBUFFER
);
860 ret
= dri2XcbSwapBuffers(pdraw
->psc
->dpy
, pdraw
,
861 target_msc
, divisor
, remainder
);
864 if (psc
->show_fps_interval
) {
868 /* Old servers don't send invalidate events */
869 if (!pdp
->invalidateAvailable
)
870 dri2InvalidateBuffers(dpyPriv
->dpy
, pdraw
->xDrawable
);
876 dri2GetBuffers(__DRIdrawable
* driDrawable
,
877 int *width
, int *height
,
878 unsigned int *attachments
, int count
,
879 int *out_count
, void *loaderPrivate
)
881 struct dri2_drawable
*pdraw
= loaderPrivate
;
884 buffers
= DRI2GetBuffers(pdraw
->base
.psc
->dpy
, pdraw
->base
.xDrawable
,
885 width
, height
, attachments
, count
, out_count
);
889 pdraw
->width
= *width
;
890 pdraw
->height
= *height
;
891 process_buffers(pdraw
, buffers
, *out_count
);
895 return pdraw
->buffers
;
899 dri2GetBuffersWithFormat(__DRIdrawable
* driDrawable
,
900 int *width
, int *height
,
901 unsigned int *attachments
, int count
,
902 int *out_count
, void *loaderPrivate
)
904 struct dri2_drawable
*pdraw
= loaderPrivate
;
907 buffers
= DRI2GetBuffersWithFormat(pdraw
->base
.psc
->dpy
,
908 pdraw
->base
.xDrawable
,
909 width
, height
, attachments
,
914 pdraw
->width
= *width
;
915 pdraw
->height
= *height
;
916 process_buffers(pdraw
, buffers
, *out_count
);
920 return pdraw
->buffers
;
924 dri2SetSwapInterval(__GLXDRIdrawable
*pdraw
, int interval
)
926 xcb_connection_t
*c
= XGetXCBConnection(pdraw
->psc
->dpy
);
927 struct dri2_drawable
*priv
= (struct dri2_drawable
*) pdraw
;
928 GLint vblank_mode
= DRI_CONF_VBLANK_DEF_INTERVAL_1
;
929 struct dri2_screen
*psc
= (struct dri2_screen
*) priv
->base
.psc
;
932 psc
->config
->configQueryi(psc
->driScreen
,
933 "vblank_mode", &vblank_mode
);
935 switch (vblank_mode
) {
936 case DRI_CONF_VBLANK_NEVER
:
938 return GLX_BAD_VALUE
;
940 case DRI_CONF_VBLANK_ALWAYS_SYNC
:
942 return GLX_BAD_VALUE
;
948 xcb_dri2_swap_interval(c
, priv
->base
.xDrawable
, interval
);
949 priv
->swap_interval
= interval
;
955 dri2GetSwapInterval(__GLXDRIdrawable
*pdraw
)
957 struct dri2_drawable
*priv
= (struct dri2_drawable
*) pdraw
;
959 return priv
->swap_interval
;
963 driSetBackgroundContext(void *loaderPrivate
)
965 struct dri2_context
*pcp
= (struct dri2_context
*) loaderPrivate
;
966 __glXSetCurrentContext(&pcp
->base
);
970 driIsThreadSafe(void *loaderPrivate
)
972 struct dri2_context
*pcp
= (struct dri2_context
*) loaderPrivate
;
973 /* Check Xlib is running in thread safe mode
975 * 'lock_fns' is the XLockDisplay function pointer of the X11 display 'dpy'.
976 * It wll be NULL if XInitThreads wasn't called.
978 return pcp
->base
.psc
->dpy
->lock_fns
!= NULL
;
981 static const __DRIdri2LoaderExtension dri2LoaderExtension
= {
982 .base
= { __DRI_DRI2_LOADER
, 3 },
984 .getBuffers
= dri2GetBuffers
,
985 .flushFrontBuffer
= dri2FlushFrontBuffer
,
986 .getBuffersWithFormat
= dri2GetBuffersWithFormat
,
989 static const __DRIdri2LoaderExtension dri2LoaderExtension_old
= {
990 .base
= { __DRI_DRI2_LOADER
, 3 },
992 .getBuffers
= dri2GetBuffers
,
993 .flushFrontBuffer
= dri2FlushFrontBuffer
,
994 .getBuffersWithFormat
= NULL
,
997 static const __DRIuseInvalidateExtension dri2UseInvalidate
= {
998 .base
= { __DRI_USE_INVALIDATE
, 1 }
1001 static const __DRIbackgroundCallableExtension driBackgroundCallable
= {
1002 .base
= { __DRI_BACKGROUND_CALLABLE
, 2 },
1004 .setBackgroundContext
= driSetBackgroundContext
,
1005 .isThreadSafe
= driIsThreadSafe
,
1009 dri2InvalidateBuffers(Display
*dpy
, XID drawable
)
1011 __GLXDRIdrawable
*pdraw
=
1012 dri2GetGlxDrawableFromXDrawableId(dpy
, drawable
);
1013 struct dri2_screen
*psc
;
1014 struct dri2_drawable
*pdp
= (struct dri2_drawable
*) pdraw
;
1019 psc
= (struct dri2_screen
*) pdraw
->psc
;
1021 if (pdraw
&& psc
->f
&& psc
->f
->base
.version
>= 3 && psc
->f
->invalidate
)
1022 psc
->f
->invalidate(pdp
->driDrawable
);
1026 dri2_bind_tex_image(Display
* dpy
,
1027 GLXDrawable drawable
,
1028 int buffer
, const int *attrib_list
)
1030 struct glx_context
*gc
= __glXGetCurrentContext();
1031 struct dri2_context
*pcp
= (struct dri2_context
*) gc
;
1032 __GLXDRIdrawable
*base
= GetGLXDRIDrawable(dpy
, drawable
);
1033 struct glx_display
*dpyPriv
= __glXInitialize(dpy
);
1034 struct dri2_drawable
*pdraw
= (struct dri2_drawable
*) base
;
1035 struct dri2_display
*pdp
;
1036 struct dri2_screen
*psc
;
1038 if (dpyPriv
== NULL
)
1041 pdp
= (struct dri2_display
*) dpyPriv
->dri2Display
;
1043 if (pdraw
!= NULL
) {
1044 psc
= (struct dri2_screen
*) base
->psc
;
1046 if (!pdp
->invalidateAvailable
&& psc
->f
&&
1047 psc
->f
->base
.version
>= 3 && psc
->f
->invalidate
)
1048 psc
->f
->invalidate(pdraw
->driDrawable
);
1050 if (psc
->texBuffer
->base
.version
>= 2 &&
1051 psc
->texBuffer
->setTexBuffer2
!= NULL
) {
1052 (*psc
->texBuffer
->setTexBuffer2
) (pcp
->driContext
,
1053 pdraw
->base
.textureTarget
,
1054 pdraw
->base
.textureFormat
,
1055 pdraw
->driDrawable
);
1058 (*psc
->texBuffer
->setTexBuffer
) (pcp
->driContext
,
1059 pdraw
->base
.textureTarget
,
1060 pdraw
->driDrawable
);
1066 dri2_release_tex_image(Display
* dpy
, GLXDrawable drawable
, int buffer
)
1068 struct glx_context
*gc
= __glXGetCurrentContext();
1069 struct dri2_context
*pcp
= (struct dri2_context
*) gc
;
1070 __GLXDRIdrawable
*base
= GetGLXDRIDrawable(dpy
, drawable
);
1071 struct glx_display
*dpyPriv
= __glXInitialize(dpy
);
1072 struct dri2_drawable
*pdraw
= (struct dri2_drawable
*) base
;
1073 struct dri2_screen
*psc
;
1075 if (dpyPriv
!= NULL
&& pdraw
!= NULL
) {
1076 psc
= (struct dri2_screen
*) base
->psc
;
1078 if (psc
->texBuffer
->base
.version
>= 3 &&
1079 psc
->texBuffer
->releaseTexBuffer
!= NULL
) {
1080 (*psc
->texBuffer
->releaseTexBuffer
) (pcp
->driContext
,
1081 pdraw
->base
.textureTarget
,
1082 pdraw
->driDrawable
);
1087 static const struct glx_context_vtable dri2_context_vtable
= {
1088 .destroy
= dri2_destroy_context
,
1089 .bind
= dri2_bind_context
,
1090 .unbind
= dri2_unbind_context
,
1091 .wait_gl
= dri2_wait_gl
,
1092 .wait_x
= dri2_wait_x
,
1093 .use_x_font
= DRI_glXUseXFont
,
1094 .bind_tex_image
= dri2_bind_tex_image
,
1095 .release_tex_image
= dri2_release_tex_image
,
1096 .get_proc_address
= NULL
,
1097 .interop_query_device_info
= dri2_interop_query_device_info
,
1098 .interop_export_object
= dri2_interop_export_object
1102 dri2BindExtensions(struct dri2_screen
*psc
, struct glx_display
* priv
,
1103 const char *driverName
)
1105 const struct dri2_display
*const pdp
= (struct dri2_display
*)
1107 const __DRIextension
**extensions
;
1110 extensions
= psc
->core
->getExtensions(psc
->driScreen
);
1112 __glXEnableDirectExtension(&psc
->base
, "GLX_SGI_swap_control");
1113 __glXEnableDirectExtension(&psc
->base
, "GLX_MESA_swap_control");
1114 __glXEnableDirectExtension(&psc
->base
, "GLX_SGI_make_current_read");
1117 * GLX_INTEL_swap_event is broken on the server side, where it's
1118 * currently unconditionally enabled. This completely breaks
1119 * systems running on drivers which don't support that extension.
1120 * There's no way to test for its presence on this side, so instead
1121 * of disabling it unconditionally, just disable it for drivers
1122 * which are known to not support it, or for DDX drivers supporting
1123 * only an older (pre-ScheduleSwap) version of DRI2.
1125 * This is a hack which is required until:
1126 * http://lists.x.org/archives/xorg-devel/2013-February/035449.html
1127 * is merged and updated xserver makes it's way into distros:
1129 if (pdp
->swapAvailable
&& strcmp(driverName
, "vmwgfx") != 0) {
1130 __glXEnableDirectExtension(&psc
->base
, "GLX_INTEL_swap_event");
1133 if (psc
->dri2
->base
.version
>= 3) {
1134 const unsigned mask
= psc
->dri2
->getAPIMask(psc
->driScreen
);
1136 __glXEnableDirectExtension(&psc
->base
, "GLX_ARB_create_context");
1137 __glXEnableDirectExtension(&psc
->base
, "GLX_ARB_create_context_profile");
1139 if ((mask
& ((1 << __DRI_API_GLES
) |
1140 (1 << __DRI_API_GLES2
) |
1141 (1 << __DRI_API_GLES3
))) != 0) {
1142 __glXEnableDirectExtension(&psc
->base
,
1143 "GLX_EXT_create_context_es_profile");
1144 __glXEnableDirectExtension(&psc
->base
,
1145 "GLX_EXT_create_context_es2_profile");
1149 for (i
= 0; extensions
[i
]; i
++) {
1150 if ((strcmp(extensions
[i
]->name
, __DRI_TEX_BUFFER
) == 0)) {
1151 psc
->texBuffer
= (__DRItexBufferExtension
*) extensions
[i
];
1152 __glXEnableDirectExtension(&psc
->base
, "GLX_EXT_texture_from_pixmap");
1155 if ((strcmp(extensions
[i
]->name
, __DRI2_FLUSH
) == 0)) {
1156 psc
->f
= (__DRI2flushExtension
*) extensions
[i
];
1157 /* internal driver extension, no GL extension exposed */
1160 if ((strcmp(extensions
[i
]->name
, __DRI2_CONFIG_QUERY
) == 0))
1161 psc
->config
= (__DRI2configQueryExtension
*) extensions
[i
];
1163 if (((strcmp(extensions
[i
]->name
, __DRI2_THROTTLE
) == 0)))
1164 psc
->throttle
= (__DRI2throttleExtension
*) extensions
[i
];
1166 /* DRI2 version 3 is also required because
1167 * GLX_ARB_create_context_robustness requires GLX_ARB_create_context.
1169 if (psc
->dri2
->base
.version
>= 3
1170 && strcmp(extensions
[i
]->name
, __DRI2_ROBUSTNESS
) == 0)
1171 __glXEnableDirectExtension(&psc
->base
,
1172 "GLX_ARB_create_context_robustness");
1174 /* DRI2 version 3 is also required because
1175 * GLX_ARB_create_context_no_error requires GLX_ARB_create_context.
1177 if (psc
->dri2
->base
.version
>= 3
1178 && strcmp(extensions
[i
]->name
, __DRI2_NO_ERROR
) == 0)
1179 __glXEnableDirectExtension(&psc
->base
,
1180 "GLX_ARB_create_context_no_error");
1182 /* DRI2 version 3 is also required because GLX_MESA_query_renderer
1183 * requires GLX_ARB_create_context_profile.
1185 if (psc
->dri2
->base
.version
>= 3
1186 && strcmp(extensions
[i
]->name
, __DRI2_RENDERER_QUERY
) == 0) {
1187 psc
->rendererQuery
= (__DRI2rendererQueryExtension
*) extensions
[i
];
1188 __glXEnableDirectExtension(&psc
->base
, "GLX_MESA_query_renderer");
1191 if (strcmp(extensions
[i
]->name
, __DRI2_INTEROP
) == 0)
1192 psc
->interop
= (__DRI2interopExtension
*)extensions
[i
];
1194 /* DRI2 version 3 is also required because
1195 * GLX_ARB_control_flush_control requires GLX_ARB_create_context.
1197 if (psc
->dri2
->base
.version
>= 3
1198 && strcmp(extensions
[i
]->name
, __DRI2_FLUSH_CONTROL
) == 0)
1199 __glXEnableDirectExtension(&psc
->base
,
1200 "GLX_ARB_context_flush_control");
1204 static const struct glx_screen_vtable dri2_screen_vtable
= {
1205 .create_context
= dri2_create_context
,
1206 .create_context_attribs
= dri2_create_context_attribs
,
1207 .query_renderer_integer
= dri2_query_renderer_integer
,
1208 .query_renderer_string
= dri2_query_renderer_string
,
1211 static struct glx_screen
*
1212 dri2CreateScreen(int screen
, struct glx_display
* priv
)
1214 const __DRIconfig
**driver_configs
;
1215 const __DRIextension
**extensions
;
1216 const struct dri2_display
*const pdp
= (struct dri2_display
*)
1218 struct dri2_screen
*psc
;
1219 __GLXDRIscreen
*psp
;
1220 struct glx_config
*configs
= NULL
, *visuals
= NULL
;
1221 char *driverName
= NULL
, *loader_driverName
, *deviceName
, *tmp
;
1224 unsigned char disable
;
1226 psc
= calloc(1, sizeof *psc
);
1232 if (!glx_screen_init(&psc
->base
, screen
, priv
)) {
1237 if (!DRI2Connect(priv
->dpy
, RootWindow(priv
->dpy
, screen
),
1238 &driverName
, &deviceName
)) {
1239 glx_screen_cleanup(&psc
->base
);
1241 InfoMessageF("screen %d does not appear to be DRI2 capable\n", screen
);
1245 psc
->fd
= loader_open_device(deviceName
);
1247 ErrorMessageF("failed to open drm device: %s\n", strerror(errno
));
1251 if (drmGetMagic(psc
->fd
, &magic
)) {
1252 ErrorMessageF("failed to get magic\n");
1256 if (!DRI2Authenticate(priv
->dpy
, RootWindow(priv
->dpy
, screen
), magic
)) {
1257 ErrorMessageF("failed to authenticate magic %d\n", magic
);
1261 /* If Mesa knows about the appropriate driver for this fd, then trust it.
1262 * Otherwise, default to the server's value.
1264 loader_driverName
= loader_get_driver_for_fd(psc
->fd
);
1265 if (loader_driverName
) {
1267 driverName
= loader_driverName
;
1270 extensions
= driOpenDriver(driverName
, &psc
->driver
);
1271 if (extensions
== NULL
)
1274 for (i
= 0; extensions
[i
]; i
++) {
1275 if (strcmp(extensions
[i
]->name
, __DRI_CORE
) == 0)
1276 psc
->core
= (__DRIcoreExtension
*) extensions
[i
];
1277 if (strcmp(extensions
[i
]->name
, __DRI_DRI2
) == 0)
1278 psc
->dri2
= (__DRIdri2Extension
*) extensions
[i
];
1281 if (psc
->core
== NULL
|| psc
->dri2
== NULL
) {
1282 ErrorMessageF("core dri or dri2 extension not found\n");
1286 if (psc
->dri2
->base
.version
>= 4) {
1288 psc
->dri2
->createNewScreen2(screen
, psc
->fd
,
1289 (const __DRIextension
**)
1290 &pdp
->loader_extensions
[0],
1292 &driver_configs
, psc
);
1295 psc
->dri2
->createNewScreen(screen
, psc
->fd
,
1296 (const __DRIextension
**)
1297 &pdp
->loader_extensions
[0],
1298 &driver_configs
, psc
);
1301 if (psc
->driScreen
== NULL
) {
1302 ErrorMessageF("failed to create dri screen\n");
1306 dri2BindExtensions(psc
, priv
, driverName
);
1308 configs
= driConvertConfigs(psc
->core
, psc
->base
.configs
, driver_configs
);
1309 visuals
= driConvertConfigs(psc
->core
, psc
->base
.visuals
, driver_configs
);
1311 if (!configs
|| !visuals
) {
1312 ErrorMessageF("No matching fbConfigs or visuals found\n");
1316 glx_config_destroy_list(psc
->base
.configs
);
1317 psc
->base
.configs
= configs
;
1318 glx_config_destroy_list(psc
->base
.visuals
);
1319 psc
->base
.visuals
= visuals
;
1321 psc
->driver_configs
= driver_configs
;
1323 psc
->base
.vtable
= &dri2_screen_vtable
;
1325 psc
->base
.driScreen
= psp
;
1326 psp
->destroyScreen
= dri2DestroyScreen
;
1327 psp
->createDrawable
= dri2CreateDrawable
;
1328 psp
->swapBuffers
= dri2SwapBuffers
;
1329 psp
->getDrawableMSC
= NULL
;
1330 psp
->waitForMSC
= NULL
;
1331 psp
->waitForSBC
= NULL
;
1332 psp
->setSwapInterval
= NULL
;
1333 psp
->getSwapInterval
= NULL
;
1334 psp
->getBufferAge
= NULL
;
1336 if (pdp
->driMinor
>= 2) {
1337 psp
->getDrawableMSC
= dri2DrawableGetMSC
;
1338 psp
->waitForMSC
= dri2WaitForMSC
;
1339 psp
->waitForSBC
= dri2WaitForSBC
;
1340 psp
->setSwapInterval
= dri2SetSwapInterval
;
1341 psp
->getSwapInterval
= dri2GetSwapInterval
;
1342 if (psc
->config
->configQueryb(psc
->driScreen
,
1343 "glx_disable_oml_sync_control",
1344 &disable
) || !disable
)
1345 __glXEnableDirectExtension(&psc
->base
, "GLX_OML_sync_control");
1348 if (psc
->config
->configQueryb(psc
->driScreen
,
1349 "glx_disable_sgi_video_sync",
1350 &disable
) || !disable
)
1351 __glXEnableDirectExtension(&psc
->base
, "GLX_SGI_video_sync");
1353 /* DRI2 supports SubBuffer through DRI2CopyRegion, so it's always
1355 psp
->copySubBuffer
= dri2CopySubBuffer
;
1356 __glXEnableDirectExtension(&psc
->base
, "GLX_MESA_copy_sub_buffer");
1361 tmp
= getenv("LIBGL_SHOW_FPS");
1362 psc
->show_fps_interval
= (tmp
) ? atoi(tmp
) : 0;
1363 if (psc
->show_fps_interval
< 0)
1364 psc
->show_fps_interval
= 0;
1366 InfoMessageF("Using DRI2 for screen %d\n", screen
);
1371 CriticalErrorMessageF("failed to load driver: %s\n", driverName
);
1374 glx_config_destroy_list(configs
);
1376 glx_config_destroy_list(visuals
);
1378 psc
->core
->destroyScreen(psc
->driScreen
);
1379 psc
->driScreen
= NULL
;
1383 dlclose(psc
->driver
);
1387 glx_screen_cleanup(&psc
->base
);
1393 /* Called from __glXFreeDisplayPrivate.
1396 dri2DestroyDisplay(__GLXDRIdisplay
* dpy
)
1398 struct dri2_display
*pdp
= (struct dri2_display
*) dpy
;
1400 __glxHashDestroy(pdp
->dri2Hash
);
1404 _X_HIDDEN __GLXDRIdrawable
*
1405 dri2GetGlxDrawableFromXDrawableId(Display
*dpy
, XID id
)
1407 struct glx_display
*d
= __glXInitialize(dpy
);
1408 struct dri2_display
*pdp
= (struct dri2_display
*) d
->dri2Display
;
1409 __GLXDRIdrawable
*pdraw
;
1411 if (__glxHashLookup(pdp
->dri2Hash
, id
, (void *) &pdraw
) == 0)
1418 * Allocate, initialize and return a __DRIdisplayPrivate object.
1419 * This is called from __glXInitialize() when we are given a new
1422 _X_HIDDEN __GLXDRIdisplay
*
1423 dri2CreateDisplay(Display
* dpy
)
1425 struct dri2_display
*pdp
;
1426 int eventBase
, errorBase
, i
;
1428 if (!DRI2QueryExtension(dpy
, &eventBase
, &errorBase
))
1431 pdp
= malloc(sizeof *pdp
);
1435 if (!DRI2QueryVersion(dpy
, &pdp
->driMajor
, &pdp
->driMinor
)) {
1441 pdp
->swapAvailable
= (pdp
->driMinor
>= 2);
1442 pdp
->invalidateAvailable
= (pdp
->driMinor
>= 3);
1444 pdp
->base
.destroyDisplay
= dri2DestroyDisplay
;
1445 pdp
->base
.createScreen
= dri2CreateScreen
;
1448 if (pdp
->driMinor
< 1)
1449 pdp
->loader_extensions
[i
++] = &dri2LoaderExtension_old
.base
;
1451 pdp
->loader_extensions
[i
++] = &dri2LoaderExtension
.base
;
1453 pdp
->loader_extensions
[i
++] = &dri2UseInvalidate
.base
;
1455 pdp
->loader_extensions
[i
++] = &driBackgroundCallable
.base
;
1457 pdp
->loader_extensions
[i
++] = NULL
;
1459 pdp
->dri2Hash
= __glxHashCreate();
1460 if (pdp
->dri2Hash
== NULL
) {
1468 #endif /* GLX_DIRECT_RENDERING */