2 * Copyright © 2013 Keith Packard
3 * Copyright © 2015 Boyan Ding
5 * Permission to use, copy, modify, distribute, and sell this software and its
6 * documentation for any purpose is hereby granted without fee, provided that
7 * the above copyright notice appear in all copies and that both that copyright
8 * notice and this permission notice appear in supporting documentation, and
9 * that the name of the copyright holders not be used in advertising or
10 * publicity pertaining to distribution of the software without specific,
11 * written prior permission. The copyright holders make no representations
12 * about the suitability of this software for any purpose. It is provided "as
13 * is" without express or implied warranty.
15 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
19 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
28 #include <X11/xshmfence.h>
31 #include <xcb/present.h>
33 #include <X11/Xlib-xcb.h>
35 #include <c11/threads.h>
36 #include "loader_dri3_helper.h"
38 /* From xmlpool/options.h, user exposed so should be stable */
39 #define DRI_CONF_VBLANK_NEVER 0
40 #define DRI_CONF_VBLANK_DEF_INTERVAL_0 1
41 #define DRI_CONF_VBLANK_DEF_INTERVAL_1 2
42 #define DRI_CONF_VBLANK_ALWAYS_SYNC 3
45 * A cached blit context.
47 struct loader_dri3_blit_context
{
50 __DRIscreen
*cur_screen
;
51 const __DRIcoreExtension
*core
;
54 /* For simplicity we maintain the cache only for a single screen at a time */
55 static struct loader_dri3_blit_context blit_context
= {
56 _MTX_INITIALIZER_NP
, NULL
60 dri3_flush_present_events(struct loader_dri3_drawable
*draw
);
62 static struct loader_dri3_buffer
*
63 dri3_find_back_alloc(struct loader_dri3_drawable
*draw
);
66 * Do we have blit functionality in the image blit extension?
68 * \param draw[in] The drawable intended to blit from / to.
69 * \return true if we have blit functionality. false otherwise.
71 static bool loader_dri3_have_image_blit(const struct loader_dri3_drawable
*draw
)
73 return draw
->ext
->image
->base
.version
>= 9 &&
74 draw
->ext
->image
->blitImage
!= NULL
;
78 * Get and lock (for use with the current thread) a dri context associated
79 * with the drawable's dri screen. The context is intended to be used with
80 * the dri image extension's blitImage method.
82 * \param draw[in] Pointer to the drawable whose dri screen we want a
84 * \return A dri context or NULL if context creation failed.
86 * When the caller is done with the context (even if the context returned was
87 * NULL), the caller must call loader_dri3_blit_context_put.
90 loader_dri3_blit_context_get(struct loader_dri3_drawable
*draw
)
92 mtx_lock(&blit_context
.mtx
);
94 if (blit_context
.ctx
&& blit_context
.cur_screen
!= draw
->dri_screen
) {
95 blit_context
.core
->destroyContext(blit_context
.ctx
);
96 blit_context
.ctx
= NULL
;
99 if (!blit_context
.ctx
) {
100 blit_context
.ctx
= draw
->ext
->core
->createNewContext(draw
->dri_screen
,
102 blit_context
.cur_screen
= draw
->dri_screen
;
103 blit_context
.core
= draw
->ext
->core
;
106 return blit_context
.ctx
;
110 * Release (for use with other threads) a dri context previously obtained using
111 * loader_dri3_blit_context_get.
114 loader_dri3_blit_context_put(void)
116 mtx_unlock(&blit_context
.mtx
);
120 * Blit (parts of) the contents of a DRI image to another dri image
122 * \param draw[in] The drawable which owns the images.
123 * \param dst[in] The destination image.
124 * \param src[in] The source image.
125 * \param dstx0[in] Start destination coordinate.
126 * \param dsty0[in] Start destination coordinate.
127 * \param width[in] Blit width.
128 * \param height[in] Blit height.
129 * \param srcx0[in] Start source coordinate.
130 * \param srcy0[in] Start source coordinate.
131 * \param flush_flag[in] Image blit flush flag.
132 * \return true iff successful.
135 loader_dri3_blit_image(struct loader_dri3_drawable
*draw
,
136 __DRIimage
*dst
, __DRIimage
*src
,
137 int dstx0
, int dsty0
, int width
, int height
,
138 int srcx0
, int srcy0
, int flush_flag
)
140 __DRIcontext
*dri_context
;
141 bool use_blit_context
= false;
143 if (!loader_dri3_have_image_blit(draw
))
146 dri_context
= draw
->vtable
->get_dri_context(draw
);
148 if (!dri_context
|| !draw
->vtable
->in_current_context(draw
)) {
149 dri_context
= loader_dri3_blit_context_get(draw
);
150 use_blit_context
= true;
151 flush_flag
|= __BLIT_FLAG_FLUSH
;
155 draw
->ext
->image
->blitImage(dri_context
, dst
, src
, dstx0
, dsty0
,
156 width
, height
, srcx0
, srcy0
,
157 width
, height
, flush_flag
);
159 if (use_blit_context
)
160 loader_dri3_blit_context_put();
162 return dri_context
!= NULL
;
166 dri3_fence_reset(xcb_connection_t
*c
, struct loader_dri3_buffer
*buffer
)
168 xshmfence_reset(buffer
->shm_fence
);
172 dri3_fence_set(struct loader_dri3_buffer
*buffer
)
174 xshmfence_trigger(buffer
->shm_fence
);
178 dri3_fence_trigger(xcb_connection_t
*c
, struct loader_dri3_buffer
*buffer
)
180 xcb_sync_trigger_fence(c
, buffer
->sync_fence
);
184 dri3_fence_await(xcb_connection_t
*c
, struct loader_dri3_drawable
*draw
,
185 struct loader_dri3_buffer
*buffer
)
188 xshmfence_await(buffer
->shm_fence
);
190 dri3_flush_present_events(draw
);
194 dri3_update_num_back(struct loader_dri3_drawable
*draw
)
203 loader_dri3_set_swap_interval(struct loader_dri3_drawable
*draw
, int interval
)
205 draw
->swap_interval
= interval
;
206 dri3_update_num_back(draw
);
209 /** dri3_free_render_buffer
211 * Free everything associated with one render buffer including pixmap, fence
212 * stuff and the driver image
215 dri3_free_render_buffer(struct loader_dri3_drawable
*draw
,
216 struct loader_dri3_buffer
*buffer
)
218 if (buffer
->own_pixmap
)
219 xcb_free_pixmap(draw
->conn
, buffer
->pixmap
);
220 xcb_sync_destroy_fence(draw
->conn
, buffer
->sync_fence
);
221 xshmfence_unmap_shm(buffer
->shm_fence
);
222 draw
->ext
->image
->destroyImage(buffer
->image
);
223 if (buffer
->linear_buffer
)
224 draw
->ext
->image
->destroyImage(buffer
->linear_buffer
);
229 loader_dri3_drawable_fini(struct loader_dri3_drawable
*draw
)
233 draw
->ext
->core
->destroyDrawable(draw
->dri_drawable
);
235 for (i
= 0; i
< LOADER_DRI3_NUM_BUFFERS
; i
++) {
236 if (draw
->buffers
[i
])
237 dri3_free_render_buffer(draw
, draw
->buffers
[i
]);
240 if (draw
->special_event
) {
241 xcb_void_cookie_t cookie
=
242 xcb_present_select_input_checked(draw
->conn
, draw
->eid
, draw
->drawable
,
243 XCB_PRESENT_EVENT_MASK_NO_EVENT
);
245 xcb_discard_reply(draw
->conn
, cookie
.sequence
);
246 xcb_unregister_for_special_event(draw
->conn
, draw
->special_event
);
251 loader_dri3_drawable_init(xcb_connection_t
*conn
,
252 xcb_drawable_t drawable
,
253 __DRIscreen
*dri_screen
,
254 bool is_different_gpu
,
255 const __DRIconfig
*dri_config
,
256 struct loader_dri3_extensions
*ext
,
257 const struct loader_dri3_vtable
*vtable
,
258 struct loader_dri3_drawable
*draw
)
260 xcb_get_geometry_cookie_t cookie
;
261 xcb_get_geometry_reply_t
*reply
;
262 xcb_generic_error_t
*error
;
263 GLint vblank_mode
= DRI_CONF_VBLANK_DEF_INTERVAL_1
;
268 draw
->vtable
= vtable
;
269 draw
->drawable
= drawable
;
270 draw
->dri_screen
= dri_screen
;
271 draw
->is_different_gpu
= is_different_gpu
;
274 draw
->have_fake_front
= 0;
275 draw
->first_init
= true;
277 draw
->cur_blit_source
= -1;
278 draw
->back_format
= __DRI_IMAGE_FORMAT_NONE
;
280 if (draw
->ext
->config
)
281 draw
->ext
->config
->configQueryi(draw
->dri_screen
,
282 "vblank_mode", &vblank_mode
);
284 switch (vblank_mode
) {
285 case DRI_CONF_VBLANK_NEVER
:
286 case DRI_CONF_VBLANK_DEF_INTERVAL_0
:
289 case DRI_CONF_VBLANK_DEF_INTERVAL_1
:
290 case DRI_CONF_VBLANK_ALWAYS_SYNC
:
295 draw
->swap_interval
= swap_interval
;
297 dri3_update_num_back(draw
);
299 /* Create a new drawable */
301 draw
->ext
->image_driver
->createNewDrawable(dri_screen
,
305 if (!draw
->dri_drawable
)
308 cookie
= xcb_get_geometry(draw
->conn
, draw
->drawable
);
309 reply
= xcb_get_geometry_reply(draw
->conn
, cookie
, &error
);
310 if (reply
== NULL
|| error
!= NULL
) {
311 draw
->ext
->core
->destroyDrawable(draw
->dri_drawable
);
315 draw
->width
= reply
->width
;
316 draw
->height
= reply
->height
;
317 draw
->depth
= reply
->depth
;
318 draw
->vtable
->set_drawable_size(draw
, draw
->width
, draw
->height
);
321 draw
->swap_method
= __DRI_ATTRIB_SWAP_UNDEFINED
;
322 if (draw
->ext
->core
->base
.version
>= 2) {
323 (void )draw
->ext
->core
->getConfigAttrib(dri_config
,
324 __DRI_ATTRIB_SWAP_METHOD
,
329 * Make sure server has the same swap interval we do for the new
332 loader_dri3_set_swap_interval(draw
, swap_interval
);
338 * Process one Present event
341 dri3_handle_present_event(struct loader_dri3_drawable
*draw
,
342 xcb_present_generic_event_t
*ge
)
344 switch (ge
->evtype
) {
345 case XCB_PRESENT_CONFIGURE_NOTIFY
: {
346 xcb_present_configure_notify_event_t
*ce
= (void *) ge
;
348 draw
->width
= ce
->width
;
349 draw
->height
= ce
->height
;
350 draw
->vtable
->set_drawable_size(draw
, draw
->width
, draw
->height
);
351 draw
->ext
->flush
->invalidate(draw
->dri_drawable
);
354 case XCB_PRESENT_COMPLETE_NOTIFY
: {
355 xcb_present_complete_notify_event_t
*ce
= (void *) ge
;
357 /* Compute the processed SBC number from the received 32-bit serial number
358 * merged with the upper 32-bits of the sent 64-bit serial number while
361 if (ce
->kind
== XCB_PRESENT_COMPLETE_KIND_PIXMAP
) {
362 draw
->recv_sbc
= (draw
->send_sbc
& 0xffffffff00000000LL
) | ce
->serial
;
363 if (draw
->recv_sbc
> draw
->send_sbc
)
364 draw
->recv_sbc
-= 0x100000000;
366 case XCB_PRESENT_COMPLETE_MODE_FLIP
:
367 draw
->flipping
= true;
369 case XCB_PRESENT_COMPLETE_MODE_COPY
:
370 draw
->flipping
= false;
373 dri3_update_num_back(draw
);
375 if (draw
->vtable
->show_fps
)
376 draw
->vtable
->show_fps(draw
, ce
->ust
);
381 draw
->recv_msc_serial
= ce
->serial
;
382 draw
->notify_ust
= ce
->ust
;
383 draw
->notify_msc
= ce
->msc
;
387 case XCB_PRESENT_EVENT_IDLE_NOTIFY
: {
388 xcb_present_idle_notify_event_t
*ie
= (void *) ge
;
391 for (b
= 0; b
< sizeof(draw
->buffers
) / sizeof(draw
->buffers
[0]); b
++) {
392 struct loader_dri3_buffer
*buf
= draw
->buffers
[b
];
394 if (buf
&& buf
->pixmap
== ie
->pixmap
) {
396 if (draw
->num_back
<= b
&& b
< LOADER_DRI3_MAX_BACK
) {
397 dri3_free_render_buffer(draw
, buf
);
398 draw
->buffers
[b
] = NULL
;
410 dri3_wait_for_event(struct loader_dri3_drawable
*draw
)
412 xcb_generic_event_t
*ev
;
413 xcb_present_generic_event_t
*ge
;
415 xcb_flush(draw
->conn
);
416 ev
= xcb_wait_for_special_event(draw
->conn
, draw
->special_event
);
420 dri3_handle_present_event(draw
, ge
);
424 /** loader_dri3_wait_for_msc
426 * Get the X server to send an event when the target msc/divisor/remainder is
430 loader_dri3_wait_for_msc(struct loader_dri3_drawable
*draw
,
432 int64_t divisor
, int64_t remainder
,
433 int64_t *ust
, int64_t *msc
, int64_t *sbc
)
437 msc_serial
= ++draw
->send_msc_serial
;
438 xcb_present_notify_msc(draw
->conn
,
445 xcb_flush(draw
->conn
);
447 /* Wait for the event */
448 if (draw
->special_event
) {
449 while ((int32_t) (msc_serial
- draw
->recv_msc_serial
) > 0) {
450 if (!dri3_wait_for_event(draw
))
455 *ust
= draw
->notify_ust
;
456 *msc
= draw
->notify_msc
;
457 *sbc
= draw
->recv_sbc
;
462 /** loader_dri3_wait_for_sbc
464 * Wait for the completed swap buffer count to reach the specified
465 * target. Presumably the application knows that this will be reached with
466 * outstanding complete events, or we're going to be here awhile.
469 loader_dri3_wait_for_sbc(struct loader_dri3_drawable
*draw
,
470 int64_t target_sbc
, int64_t *ust
,
471 int64_t *msc
, int64_t *sbc
)
473 /* From the GLX_OML_sync_control spec:
475 * "If <target_sbc> = 0, the function will block until all previous
476 * swaps requested with glXSwapBuffersMscOML for that window have
480 target_sbc
= draw
->send_sbc
;
482 while (draw
->recv_sbc
< target_sbc
) {
483 if (!dri3_wait_for_event(draw
))
489 *sbc
= draw
->recv_sbc
;
493 /** loader_dri3_find_back
495 * Find an idle back buffer. If there isn't one, then
496 * wait for a present idle notify event from the X server
499 dri3_find_back(struct loader_dri3_drawable
*draw
)
502 xcb_generic_event_t
*ev
;
503 xcb_present_generic_event_t
*ge
;
504 int num_to_consider
= draw
->num_back
;
506 /* Increase the likelyhood of reusing current buffer */
507 dri3_flush_present_events(draw
);
509 /* Check whether we need to reuse the current back buffer as new back.
510 * In that case, wait until it's not busy anymore.
512 if (!loader_dri3_have_image_blit(draw
) && draw
->cur_blit_source
!= -1) {
514 draw
->cur_blit_source
= -1;
518 for (b
= 0; b
< num_to_consider
; b
++) {
519 int id
= LOADER_DRI3_BACK_ID((b
+ draw
->cur_back
) % draw
->num_back
);
520 struct loader_dri3_buffer
*buffer
= draw
->buffers
[id
];
522 if (!buffer
|| !buffer
->busy
) {
527 xcb_flush(draw
->conn
);
528 ev
= xcb_wait_for_special_event(draw
->conn
, draw
->special_event
);
532 dri3_handle_present_event(draw
, ge
);
536 static xcb_gcontext_t
537 dri3_drawable_gc(struct loader_dri3_drawable
*draw
)
541 xcb_create_gc(draw
->conn
,
542 (draw
->gc
= xcb_generate_id(draw
->conn
)),
544 XCB_GC_GRAPHICS_EXPOSURES
,
551 static struct loader_dri3_buffer
*
552 dri3_back_buffer(struct loader_dri3_drawable
*draw
)
554 return draw
->buffers
[LOADER_DRI3_BACK_ID(draw
->cur_back
)];
557 static struct loader_dri3_buffer
*
558 dri3_fake_front_buffer(struct loader_dri3_drawable
*draw
)
560 return draw
->buffers
[LOADER_DRI3_FRONT_ID
];
564 dri3_copy_area(xcb_connection_t
*c
,
565 xcb_drawable_t src_drawable
,
566 xcb_drawable_t dst_drawable
,
575 xcb_void_cookie_t cookie
;
577 cookie
= xcb_copy_area_checked(c
,
587 xcb_discard_reply(c
, cookie
.sequence
);
591 * Asks the driver to flush any queued work necessary for serializing with the
592 * X command stream, and optionally the slightly more strict requirement of
593 * glFlush() equivalence (which would require flushing even if nothing had
594 * been drawn to a window system framebuffer, for example).
597 loader_dri3_flush(struct loader_dri3_drawable
*draw
,
599 enum __DRI2throttleReason throttle_reason
)
601 /* NEED TO CHECK WHETHER CONTEXT IS NULL */
602 __DRIcontext
*dri_context
= draw
->vtable
->get_dri_context(draw
);
605 draw
->ext
->flush
->flush_with_flags(dri_context
, draw
->dri_drawable
,
606 flags
, throttle_reason
);
611 loader_dri3_copy_sub_buffer(struct loader_dri3_drawable
*draw
,
613 int width
, int height
,
616 struct loader_dri3_buffer
*back
;
617 unsigned flags
= __DRI2_FLUSH_DRAWABLE
;
619 /* Check we have the right attachments */
620 if (!draw
->have_back
|| draw
->is_pixmap
)
624 flags
|= __DRI2_FLUSH_CONTEXT
;
625 loader_dri3_flush(draw
, flags
, __DRI2_THROTTLE_SWAPBUFFER
);
627 back
= dri3_find_back_alloc(draw
);
631 y
= draw
->height
- y
- height
;
633 if (draw
->is_different_gpu
) {
634 /* Update the linear buffer part of the back buffer
635 * for the dri3_copy_area operation
637 (void) loader_dri3_blit_image(draw
,
640 0, 0, back
->width
, back
->height
,
641 0, 0, __BLIT_FLAG_FLUSH
);
644 loader_dri3_swapbuffer_barrier(draw
);
645 dri3_fence_reset(draw
->conn
, back
);
646 dri3_copy_area(draw
->conn
,
649 dri3_drawable_gc(draw
),
650 x
, y
, x
, y
, width
, height
);
651 dri3_fence_trigger(draw
->conn
, back
);
652 /* Refresh the fake front (if present) after we just damaged the real
655 if (draw
->have_fake_front
&&
656 !loader_dri3_blit_image(draw
,
657 dri3_fake_front_buffer(draw
)->image
,
660 x
, y
, __BLIT_FLAG_FLUSH
) &&
661 !draw
->is_different_gpu
) {
662 dri3_fence_reset(draw
->conn
, dri3_fake_front_buffer(draw
));
663 dri3_copy_area(draw
->conn
,
665 dri3_fake_front_buffer(draw
)->pixmap
,
666 dri3_drawable_gc(draw
),
667 x
, y
, x
, y
, width
, height
);
668 dri3_fence_trigger(draw
->conn
, dri3_fake_front_buffer(draw
));
669 dri3_fence_await(draw
->conn
, NULL
, dri3_fake_front_buffer(draw
));
671 dri3_fence_await(draw
->conn
, draw
, back
);
675 loader_dri3_copy_drawable(struct loader_dri3_drawable
*draw
,
679 loader_dri3_flush(draw
, __DRI2_FLUSH_DRAWABLE
, 0);
681 dri3_fence_reset(draw
->conn
, dri3_fake_front_buffer(draw
));
682 dri3_copy_area(draw
->conn
,
684 dri3_drawable_gc(draw
),
685 0, 0, 0, 0, draw
->width
, draw
->height
);
686 dri3_fence_trigger(draw
->conn
, dri3_fake_front_buffer(draw
));
687 dri3_fence_await(draw
->conn
, draw
, dri3_fake_front_buffer(draw
));
691 loader_dri3_wait_x(struct loader_dri3_drawable
*draw
)
693 struct loader_dri3_buffer
*front
;
695 if (draw
== NULL
|| !draw
->have_fake_front
)
698 front
= dri3_fake_front_buffer(draw
);
700 loader_dri3_copy_drawable(draw
, front
->pixmap
, draw
->drawable
);
702 /* In the psc->is_different_gpu case, the linear buffer has been updated,
703 * but not yet the tiled buffer.
704 * Copy back to the tiled buffer we use for rendering.
705 * Note that we don't need flushing.
707 if (draw
->is_different_gpu
)
708 (void) loader_dri3_blit_image(draw
,
710 front
->linear_buffer
,
711 0, 0, front
->width
, front
->height
,
716 loader_dri3_wait_gl(struct loader_dri3_drawable
*draw
)
718 struct loader_dri3_buffer
*front
;
720 if (draw
== NULL
|| !draw
->have_fake_front
)
723 front
= dri3_fake_front_buffer(draw
);
725 /* In the psc->is_different_gpu case, we update the linear_buffer
726 * before updating the real front.
728 if (draw
->is_different_gpu
)
729 (void) loader_dri3_blit_image(draw
,
730 front
->linear_buffer
,
732 0, 0, front
->width
, front
->height
,
733 0, 0, __BLIT_FLAG_FLUSH
);
734 loader_dri3_swapbuffer_barrier(draw
);
735 loader_dri3_copy_drawable(draw
, draw
->drawable
, front
->pixmap
);
738 /** dri3_flush_present_events
740 * Process any present events that have been received from the X server
743 dri3_flush_present_events(struct loader_dri3_drawable
*draw
)
745 /* Check to see if any configuration changes have occurred
746 * since we were last invoked
748 if (draw
->special_event
) {
749 xcb_generic_event_t
*ev
;
751 while ((ev
= xcb_poll_for_special_event(draw
->conn
,
752 draw
->special_event
)) != NULL
) {
753 xcb_present_generic_event_t
*ge
= (void *) ev
;
754 dri3_handle_present_event(draw
, ge
);
759 /** loader_dri3_swap_buffers_msc
761 * Make the current back buffer visible using the present extension
764 loader_dri3_swap_buffers_msc(struct loader_dri3_drawable
*draw
,
765 int64_t target_msc
, int64_t divisor
,
766 int64_t remainder
, unsigned flush_flags
,
769 struct loader_dri3_buffer
*back
;
771 uint32_t options
= XCB_PRESENT_OPTION_NONE
;
773 draw
->vtable
->flush_drawable(draw
, flush_flags
);
775 back
= dri3_find_back_alloc(draw
);
777 if (draw
->is_different_gpu
&& back
) {
778 /* Update the linear buffer before presenting the pixmap */
779 (void) loader_dri3_blit_image(draw
,
782 0, 0, back
->width
, back
->height
,
783 0, 0, __BLIT_FLAG_FLUSH
);
786 /* If we need to preload the new back buffer, remember the source.
787 * The force_copy parameter is used by EGL to attempt to preserve
788 * the back buffer across a call to this function.
790 if (draw
->swap_method
!= __DRI_ATTRIB_SWAP_UNDEFINED
|| force_copy
)
791 draw
->cur_blit_source
= LOADER_DRI3_BACK_ID(draw
->cur_back
);
793 /* Exchange the back and fake front. Even though the server knows about these
794 * buffers, it has no notion of back and fake front.
796 if (back
&& draw
->have_fake_front
) {
797 struct loader_dri3_buffer
*tmp
;
799 tmp
= dri3_fake_front_buffer(draw
);
800 draw
->buffers
[LOADER_DRI3_FRONT_ID
] = back
;
801 draw
->buffers
[LOADER_DRI3_BACK_ID(draw
->cur_back
)] = tmp
;
803 if (draw
->swap_method
== __DRI_ATTRIB_SWAP_COPY
|| force_copy
)
804 draw
->cur_blit_source
= LOADER_DRI3_FRONT_ID
;
807 dri3_flush_present_events(draw
);
809 if (back
&& !draw
->is_pixmap
) {
810 dri3_fence_reset(draw
->conn
, back
);
812 /* Compute when we want the frame shown by taking the last known
813 * successful MSC and adding in a swap interval for each outstanding swap
814 * request. target_msc=divisor=remainder=0 means "Use glXSwapBuffers()
818 if (target_msc
== 0 && divisor
== 0 && remainder
== 0)
819 target_msc
= draw
->msc
+ draw
->swap_interval
*
820 (draw
->send_sbc
- draw
->recv_sbc
);
821 else if (divisor
== 0 && remainder
> 0) {
822 /* From the GLX_OML_sync_control spec:
823 * "If <divisor> = 0, the swap will occur when MSC becomes
824 * greater than or equal to <target_msc>."
826 * Note that there's no mention of the remainder. The Present
827 * extension throws BadValue for remainder != 0 with divisor == 0, so
828 * just drop the passed in value.
833 /* From the GLX_EXT_swap_control spec
834 * and the EGL 1.4 spec (page 53):
836 * "If <interval> is set to a value of 0, buffer swaps are not
837 * synchronized to a video frame."
839 * Implementation note: It is possible to enable triple buffering
840 * behaviour by not using XCB_PRESENT_OPTION_ASYNC, but this should not be
843 if (draw
->swap_interval
== 0)
844 options
|= XCB_PRESENT_OPTION_ASYNC
;
846 /* If we need to populate the new back, but need to reuse the back
847 * buffer slot due to lack of local blit capabilities, make sure
848 * the server doesn't flip and we deadlock.
850 if (!loader_dri3_have_image_blit(draw
) && draw
->cur_blit_source
!= -1)
851 options
|= XCB_PRESENT_OPTION_COPY
;
854 back
->last_swap
= draw
->send_sbc
;
855 xcb_present_pixmap(draw
->conn
,
858 (uint32_t) draw
->send_sbc
,
863 None
, /* target_crtc */
870 ret
= (int64_t) draw
->send_sbc
;
872 /* Schedule a server-side back-preserving blit if necessary.
873 * This happens iff all conditions below are satisfied:
874 * a) We have a fake front,
875 * b) We need to preserve the back buffer,
876 * c) We don't have local blit capabilities.
878 if (!loader_dri3_have_image_blit(draw
) && draw
->cur_blit_source
!= -1 &&
879 draw
->cur_blit_source
!= LOADER_DRI3_BACK_ID(draw
->cur_back
)) {
880 struct loader_dri3_buffer
*new_back
= dri3_back_buffer(draw
);
881 struct loader_dri3_buffer
*src
= draw
->buffers
[draw
->cur_blit_source
];
883 dri3_fence_reset(draw
->conn
, new_back
);
884 dri3_copy_area(draw
->conn
, src
->pixmap
,
886 dri3_drawable_gc(draw
),
887 0, 0, 0, 0, draw
->width
, draw
->height
);
888 dri3_fence_trigger(draw
->conn
, new_back
);
889 new_back
->last_swap
= src
->last_swap
;
892 xcb_flush(draw
->conn
);
897 draw
->ext
->flush
->invalidate(draw
->dri_drawable
);
903 loader_dri3_query_buffer_age(struct loader_dri3_drawable
*draw
)
905 struct loader_dri3_buffer
*back
= dri3_find_back_alloc(draw
);
907 if (!back
|| back
->last_swap
== 0)
910 return draw
->send_sbc
- back
->last_swap
+ 1;
915 * Wrapper around xcb_dri3_open
918 loader_dri3_open(xcb_connection_t
*conn
,
922 xcb_dri3_open_cookie_t cookie
;
923 xcb_dri3_open_reply_t
*reply
;
926 cookie
= xcb_dri3_open(conn
,
930 reply
= xcb_dri3_open_reply(conn
, cookie
, NULL
);
934 if (reply
->nfd
!= 1) {
939 fd
= xcb_dri3_open_reply_fds(conn
, reply
)[0];
941 fcntl(fd
, F_SETFD
, fcntl(fd
, F_GETFD
) | FD_CLOEXEC
);
947 dri3_cpp_for_format(uint32_t format
) {
949 case __DRI_IMAGE_FORMAT_R8
:
951 case __DRI_IMAGE_FORMAT_RGB565
:
952 case __DRI_IMAGE_FORMAT_GR88
:
954 case __DRI_IMAGE_FORMAT_XRGB8888
:
955 case __DRI_IMAGE_FORMAT_ARGB8888
:
956 case __DRI_IMAGE_FORMAT_ABGR8888
:
957 case __DRI_IMAGE_FORMAT_XBGR8888
:
958 case __DRI_IMAGE_FORMAT_XRGB2101010
:
959 case __DRI_IMAGE_FORMAT_ARGB2101010
:
960 case __DRI_IMAGE_FORMAT_SARGB8
:
962 case __DRI_IMAGE_FORMAT_NONE
:
968 /* the DRIimage createImage function takes __DRI_IMAGE_FORMAT codes, while
969 * the createImageFromFds call takes __DRI_IMAGE_FOURCC codes. To avoid
970 * complete confusion, just deal in __DRI_IMAGE_FORMAT codes for now and
971 * translate to __DRI_IMAGE_FOURCC codes in the call to createImageFromFds
974 image_format_to_fourcc(int format
)
977 /* Convert from __DRI_IMAGE_FORMAT to __DRI_IMAGE_FOURCC (sigh) */
979 case __DRI_IMAGE_FORMAT_SARGB8
: return __DRI_IMAGE_FOURCC_SARGB8888
;
980 case __DRI_IMAGE_FORMAT_RGB565
: return __DRI_IMAGE_FOURCC_RGB565
;
981 case __DRI_IMAGE_FORMAT_XRGB8888
: return __DRI_IMAGE_FOURCC_XRGB8888
;
982 case __DRI_IMAGE_FORMAT_ARGB8888
: return __DRI_IMAGE_FOURCC_ARGB8888
;
983 case __DRI_IMAGE_FORMAT_ABGR8888
: return __DRI_IMAGE_FOURCC_ABGR8888
;
984 case __DRI_IMAGE_FORMAT_XBGR8888
: return __DRI_IMAGE_FOURCC_XBGR8888
;
989 /** loader_dri3_alloc_render_buffer
991 * Use the driver createImage function to construct a __DRIimage, then
992 * get a file descriptor for that and create an X pixmap from that
994 * Allocate an xshmfence for synchronization
996 static struct loader_dri3_buffer
*
997 dri3_alloc_render_buffer(struct loader_dri3_drawable
*draw
, unsigned int format
,
998 int width
, int height
, int depth
)
1000 struct loader_dri3_buffer
*buffer
;
1001 __DRIimage
*pixmap_buffer
;
1002 xcb_pixmap_t pixmap
;
1003 xcb_sync_fence_t sync_fence
;
1004 struct xshmfence
*shm_fence
;
1005 int buffer_fd
, fence_fd
;
1008 /* Create an xshmfence object and
1009 * prepare to send that to the X server
1012 fence_fd
= xshmfence_alloc_shm();
1016 shm_fence
= xshmfence_map_shm(fence_fd
);
1017 if (shm_fence
== NULL
)
1020 /* Allocate the image from the driver
1022 buffer
= calloc(1, sizeof *buffer
);
1026 buffer
->cpp
= dri3_cpp_for_format(format
);
1030 if (!draw
->is_different_gpu
) {
1031 buffer
->image
= draw
->ext
->image
->createImage(draw
->dri_screen
,
1034 __DRI_IMAGE_USE_SHARE
|
1035 __DRI_IMAGE_USE_SCANOUT
|
1036 __DRI_IMAGE_USE_BACKBUFFER
,
1038 pixmap_buffer
= buffer
->image
;
1043 buffer
->image
= draw
->ext
->image
->createImage(draw
->dri_screen
,
1052 buffer
->linear_buffer
=
1053 draw
->ext
->image
->createImage(draw
->dri_screen
,
1054 width
, height
, format
,
1055 __DRI_IMAGE_USE_SHARE
|
1056 __DRI_IMAGE_USE_LINEAR
|
1057 __DRI_IMAGE_USE_BACKBUFFER
,
1059 pixmap_buffer
= buffer
->linear_buffer
;
1061 if (!buffer
->linear_buffer
)
1062 goto no_linear_buffer
;
1065 /* X wants the stride, so ask the image for it
1067 if (!draw
->ext
->image
->queryImage(pixmap_buffer
, __DRI_IMAGE_ATTRIB_STRIDE
,
1069 goto no_buffer_attrib
;
1071 buffer
->pitch
= stride
;
1073 if (!draw
->ext
->image
->queryImage(pixmap_buffer
, __DRI_IMAGE_ATTRIB_FD
,
1075 goto no_buffer_attrib
;
1077 xcb_dri3_pixmap_from_buffer(draw
->conn
,
1078 (pixmap
= xcb_generate_id(draw
->conn
)),
1081 width
, height
, buffer
->pitch
,
1082 depth
, buffer
->cpp
* 8,
1085 xcb_dri3_fence_from_fd(draw
->conn
,
1087 (sync_fence
= xcb_generate_id(draw
->conn
)),
1091 buffer
->pixmap
= pixmap
;
1092 buffer
->own_pixmap
= true;
1093 buffer
->sync_fence
= sync_fence
;
1094 buffer
->shm_fence
= shm_fence
;
1095 buffer
->width
= width
;
1096 buffer
->height
= height
;
1098 /* Mark the buffer as idle
1100 dri3_fence_set(buffer
);
1105 draw
->ext
->image
->destroyImage(pixmap_buffer
);
1107 if (draw
->is_different_gpu
)
1108 draw
->ext
->image
->destroyImage(buffer
->image
);
1112 xshmfence_unmap_shm(shm_fence
);
1118 /** loader_dri3_update_drawable
1120 * Called the first time we use the drawable and then
1121 * after we receive present configure notify events to
1122 * track the geometry of the drawable
1125 dri3_update_drawable(__DRIdrawable
*driDrawable
,
1126 struct loader_dri3_drawable
*draw
)
1128 if (draw
->first_init
) {
1129 xcb_get_geometry_cookie_t geom_cookie
;
1130 xcb_get_geometry_reply_t
*geom_reply
;
1131 xcb_void_cookie_t cookie
;
1132 xcb_generic_error_t
*error
;
1133 xcb_present_query_capabilities_cookie_t present_capabilities_cookie
;
1134 xcb_present_query_capabilities_reply_t
*present_capabilities_reply
;
1136 draw
->first_init
= false;
1138 /* Try to select for input on the window.
1140 * If the drawable is a window, this will get our events
1143 * Otherwise, we'll get a BadWindow error back from this request which
1144 * will let us know that the drawable is a pixmap instead.
1147 draw
->eid
= xcb_generate_id(draw
->conn
);
1149 xcb_present_select_input_checked(draw
->conn
, draw
->eid
, draw
->drawable
,
1150 XCB_PRESENT_EVENT_MASK_CONFIGURE_NOTIFY
|
1151 XCB_PRESENT_EVENT_MASK_COMPLETE_NOTIFY
|
1152 XCB_PRESENT_EVENT_MASK_IDLE_NOTIFY
);
1154 present_capabilities_cookie
=
1155 xcb_present_query_capabilities(draw
->conn
, draw
->drawable
);
1157 /* Create an XCB event queue to hold present events outside of the usual
1158 * application event queue
1160 draw
->special_event
= xcb_register_for_special_xge(draw
->conn
,
1164 geom_cookie
= xcb_get_geometry(draw
->conn
, draw
->drawable
);
1166 geom_reply
= xcb_get_geometry_reply(draw
->conn
, geom_cookie
, NULL
);
1171 draw
->width
= geom_reply
->width
;
1172 draw
->height
= geom_reply
->height
;
1173 draw
->depth
= geom_reply
->depth
;
1174 draw
->vtable
->set_drawable_size(draw
, draw
->width
, draw
->height
);
1178 draw
->is_pixmap
= false;
1180 /* Check to see if our select input call failed. If it failed with a
1181 * BadWindow error, then assume the drawable is a pixmap. Destroy the
1182 * special event queue created above and mark the drawable as a pixmap
1185 error
= xcb_request_check(draw
->conn
, cookie
);
1187 present_capabilities_reply
=
1188 xcb_present_query_capabilities_reply(draw
->conn
,
1189 present_capabilities_cookie
,
1192 if (present_capabilities_reply
) {
1193 draw
->present_capabilities
= present_capabilities_reply
->capabilities
;
1194 free(present_capabilities_reply
);
1196 draw
->present_capabilities
= 0;
1199 if (error
->error_code
!= BadWindow
) {
1203 draw
->is_pixmap
= true;
1204 xcb_unregister_for_special_event(draw
->conn
, draw
->special_event
);
1205 draw
->special_event
= NULL
;
1208 dri3_flush_present_events(draw
);
1213 loader_dri3_create_image(xcb_connection_t
*c
,
1214 xcb_dri3_buffer_from_pixmap_reply_t
*bp_reply
,
1215 unsigned int format
,
1216 __DRIscreen
*dri_screen
,
1217 const __DRIimageExtension
*image
,
1218 void *loaderPrivate
)
1221 __DRIimage
*image_planar
, *ret
;
1224 /* Get an FD for the pixmap object
1226 fds
= xcb_dri3_buffer_from_pixmap_reply_fds(c
, bp_reply
);
1228 stride
= bp_reply
->stride
;
1231 /* createImageFromFds creates a wrapper __DRIimage structure which
1232 * can deal with multiple planes for things like Yuv images. So, once
1233 * we've gotten the planar wrapper, pull the single plane out of it and
1234 * discard the wrapper.
1236 image_planar
= image
->createImageFromFds(dri_screen
,
1239 image_format_to_fourcc(format
),
1241 &stride
, &offset
, loaderPrivate
);
1246 ret
= image
->fromPlanar(image_planar
, 0, loaderPrivate
);
1248 image
->destroyImage(image_planar
);
1253 /** dri3_get_pixmap_buffer
1255 * Get the DRM object for a pixmap from the X server and
1256 * wrap that with a __DRIimage structure using createImageFromFds
1258 static struct loader_dri3_buffer
*
1259 dri3_get_pixmap_buffer(__DRIdrawable
*driDrawable
, unsigned int format
,
1260 enum loader_dri3_buffer_type buffer_type
,
1261 struct loader_dri3_drawable
*draw
)
1263 int buf_id
= loader_dri3_pixmap_buf_id(buffer_type
);
1264 struct loader_dri3_buffer
*buffer
= draw
->buffers
[buf_id
];
1265 xcb_drawable_t pixmap
;
1266 xcb_dri3_buffer_from_pixmap_cookie_t bp_cookie
;
1267 xcb_dri3_buffer_from_pixmap_reply_t
*bp_reply
;
1268 xcb_sync_fence_t sync_fence
;
1269 struct xshmfence
*shm_fence
;
1275 pixmap
= draw
->drawable
;
1277 buffer
= calloc(1, sizeof *buffer
);
1281 fence_fd
= xshmfence_alloc_shm();
1284 shm_fence
= xshmfence_map_shm(fence_fd
);
1285 if (shm_fence
== NULL
) {
1290 xcb_dri3_fence_from_fd(draw
->conn
,
1292 (sync_fence
= xcb_generate_id(draw
->conn
)),
1296 bp_cookie
= xcb_dri3_buffer_from_pixmap(draw
->conn
, pixmap
);
1297 bp_reply
= xcb_dri3_buffer_from_pixmap_reply(draw
->conn
, bp_cookie
, NULL
);
1301 buffer
->image
= loader_dri3_create_image(draw
->conn
, bp_reply
, format
,
1302 draw
->dri_screen
, draw
->ext
->image
,
1307 buffer
->pixmap
= pixmap
;
1308 buffer
->own_pixmap
= false;
1309 buffer
->width
= bp_reply
->width
;
1310 buffer
->height
= bp_reply
->height
;
1311 buffer
->shm_fence
= shm_fence
;
1312 buffer
->sync_fence
= sync_fence
;
1314 draw
->buffers
[buf_id
] = buffer
;
1322 xcb_sync_destroy_fence(draw
->conn
, sync_fence
);
1323 xshmfence_unmap_shm(shm_fence
);
1332 * Find a front or back buffer, allocating new ones as necessary
1334 static struct loader_dri3_buffer
*
1335 dri3_get_buffer(__DRIdrawable
*driDrawable
,
1336 unsigned int format
,
1337 enum loader_dri3_buffer_type buffer_type
,
1338 struct loader_dri3_drawable
*draw
)
1340 struct loader_dri3_buffer
*buffer
;
1343 if (buffer_type
== loader_dri3_buffer_back
) {
1344 draw
->back_format
= format
;
1346 buf_id
= dri3_find_back(draw
);
1351 buf_id
= LOADER_DRI3_FRONT_ID
;
1354 buffer
= draw
->buffers
[buf_id
];
1356 /* Allocate a new buffer if there isn't an old one, or if that
1357 * old one is the wrong size
1359 if (!buffer
|| buffer
->width
!= draw
->width
||
1360 buffer
->height
!= draw
->height
) {
1361 struct loader_dri3_buffer
*new_buffer
;
1363 /* Allocate the new buffers
1365 new_buffer
= dri3_alloc_render_buffer(draw
,
1373 /* When resizing, copy the contents of the old buffer, waiting for that
1374 * copy to complete using our fences before proceeding
1376 switch (buffer_type
) {
1377 case loader_dri3_buffer_back
:
1379 if (!buffer
->linear_buffer
) {
1380 dri3_fence_reset(draw
->conn
, new_buffer
);
1381 dri3_fence_await(draw
->conn
, draw
, buffer
);
1382 dri3_copy_area(draw
->conn
,
1385 dri3_drawable_gc(draw
),
1387 draw
->width
, draw
->height
);
1388 dri3_fence_trigger(draw
->conn
, new_buffer
);
1389 } else if (draw
->vtable
->in_current_context(draw
)) {
1390 (void) loader_dri3_blit_image(draw
,
1393 0, 0, draw
->width
, draw
->height
,
1396 dri3_free_render_buffer(draw
, buffer
);
1399 case loader_dri3_buffer_front
:
1400 loader_dri3_swapbuffer_barrier(draw
);
1401 dri3_fence_reset(draw
->conn
, new_buffer
);
1402 dri3_copy_area(draw
->conn
,
1405 dri3_drawable_gc(draw
),
1407 draw
->width
, draw
->height
);
1408 dri3_fence_trigger(draw
->conn
, new_buffer
);
1410 if (new_buffer
->linear_buffer
&&
1411 draw
->vtable
->in_current_context(draw
)) {
1412 dri3_fence_await(draw
->conn
, draw
, new_buffer
);
1413 (void) loader_dri3_blit_image(draw
,
1415 new_buffer
->linear_buffer
,
1416 0, 0, draw
->width
, draw
->height
,
1421 buffer
= new_buffer
;
1422 draw
->buffers
[buf_id
] = buffer
;
1424 dri3_fence_await(draw
->conn
, draw
, buffer
);
1427 * Do we need to preserve the content of a previous buffer?
1429 * Note that this blit is needed only to avoid a wait for a buffer that
1430 * is currently in the flip chain or being scanned out from. That's really
1431 * a tradeoff. If we're ok with the wait we can reduce the number of back
1432 * buffers to 1 for SWAP_EXCHANGE, and 1 for SWAP_COPY,
1433 * but in the latter case we must disallow page-flipping.
1435 if (buffer_type
== loader_dri3_buffer_back
&&
1436 draw
->cur_blit_source
!= -1 &&
1437 draw
->buffers
[draw
->cur_blit_source
] &&
1438 buffer
!= draw
->buffers
[draw
->cur_blit_source
]) {
1440 struct loader_dri3_buffer
*source
= draw
->buffers
[draw
->cur_blit_source
];
1442 /* Avoid flushing here. Will propably do good for tiling hardware. */
1443 (void) loader_dri3_blit_image(draw
,
1446 0, 0, draw
->width
, draw
->height
,
1448 buffer
->last_swap
= source
->last_swap
;
1449 draw
->cur_blit_source
= -1;
1451 /* Return the requested buffer */
1455 /** dri3_free_buffers
1457 * Free the front bufffer or all of the back buffers. Used
1458 * when the application changes which buffers it needs
1461 dri3_free_buffers(__DRIdrawable
*driDrawable
,
1462 enum loader_dri3_buffer_type buffer_type
,
1463 struct loader_dri3_drawable
*draw
)
1465 struct loader_dri3_buffer
*buffer
;
1470 switch (buffer_type
) {
1471 case loader_dri3_buffer_back
:
1472 first_id
= LOADER_DRI3_BACK_ID(0);
1473 n_id
= LOADER_DRI3_MAX_BACK
;
1475 case loader_dri3_buffer_front
:
1476 first_id
= LOADER_DRI3_FRONT_ID
;
1480 for (buf_id
= first_id
; buf_id
< first_id
+ n_id
; buf_id
++) {
1481 buffer
= draw
->buffers
[buf_id
];
1483 dri3_free_render_buffer(draw
, buffer
);
1484 draw
->buffers
[buf_id
] = NULL
;
1489 /** loader_dri3_get_buffers
1491 * The published buffer allocation API.
1492 * Returns all of the necessary buffers, allocating
1496 loader_dri3_get_buffers(__DRIdrawable
*driDrawable
,
1497 unsigned int format
,
1499 void *loaderPrivate
,
1500 uint32_t buffer_mask
,
1501 struct __DRIimageList
*buffers
)
1503 struct loader_dri3_drawable
*draw
= loaderPrivate
;
1504 struct loader_dri3_buffer
*front
, *back
;
1506 buffers
->image_mask
= 0;
1507 buffers
->front
= NULL
;
1508 buffers
->back
= NULL
;
1513 if (!dri3_update_drawable(driDrawable
, draw
))
1516 /* pixmaps always have front buffers.
1517 * Exchange swaps also mandate fake front buffers.
1519 if (draw
->is_pixmap
|| draw
->swap_method
== __DRI_ATTRIB_SWAP_EXCHANGE
)
1520 buffer_mask
|= __DRI_IMAGE_BUFFER_FRONT
;
1522 if (buffer_mask
& __DRI_IMAGE_BUFFER_FRONT
) {
1523 /* All pixmaps are owned by the server gpu.
1524 * When we use a different gpu, we can't use the pixmap
1525 * as buffer since it is potentially tiled a way
1526 * our device can't understand. In this case, use
1527 * a fake front buffer. Hopefully the pixmap
1528 * content will get synced with the fake front
1531 if (draw
->is_pixmap
&& !draw
->is_different_gpu
)
1532 front
= dri3_get_pixmap_buffer(driDrawable
,
1534 loader_dri3_buffer_front
,
1537 front
= dri3_get_buffer(driDrawable
,
1539 loader_dri3_buffer_front
,
1545 dri3_free_buffers(driDrawable
, loader_dri3_buffer_front
, draw
);
1546 draw
->have_fake_front
= 0;
1549 if (buffer_mask
& __DRI_IMAGE_BUFFER_BACK
) {
1550 back
= dri3_get_buffer(driDrawable
,
1552 loader_dri3_buffer_back
,
1556 draw
->have_back
= 1;
1558 dri3_free_buffers(driDrawable
, loader_dri3_buffer_back
, draw
);
1559 draw
->have_back
= 0;
1563 buffers
->image_mask
|= __DRI_IMAGE_BUFFER_FRONT
;
1564 buffers
->front
= front
->image
;
1565 draw
->have_fake_front
= draw
->is_different_gpu
|| !draw
->is_pixmap
;
1569 buffers
->image_mask
|= __DRI_IMAGE_BUFFER_BACK
;
1570 buffers
->back
= back
->image
;
1573 draw
->stamp
= stamp
;
1578 /** loader_dri3_update_drawable_geometry
1580 * Get the current drawable geometry.
1583 loader_dri3_update_drawable_geometry(struct loader_dri3_drawable
*draw
)
1585 xcb_get_geometry_cookie_t geom_cookie
;
1586 xcb_get_geometry_reply_t
*geom_reply
;
1588 geom_cookie
= xcb_get_geometry(draw
->conn
, draw
->drawable
);
1590 geom_reply
= xcb_get_geometry_reply(draw
->conn
, geom_cookie
, NULL
);
1593 draw
->width
= geom_reply
->width
;
1594 draw
->height
= geom_reply
->height
;
1595 draw
->vtable
->set_drawable_size(draw
, draw
->width
, draw
->height
);
1596 draw
->ext
->flush
->invalidate(draw
->dri_drawable
);
1604 * Make sure the server has flushed all pending swap buffers to hardware
1605 * for this drawable. Ideally we'd want to send an X protocol request to
1606 * have the server block our connection until the swaps are complete. That
1607 * would avoid the potential round-trip here.
1610 loader_dri3_swapbuffer_barrier(struct loader_dri3_drawable
*draw
)
1612 int64_t ust
, msc
, sbc
;
1614 (void) loader_dri3_wait_for_sbc(draw
, 0, &ust
, &msc
, &sbc
);
1618 * Perform any cleanup associated with a close screen operation.
1619 * \param dri_screen[in,out] Pointer to __DRIscreen about to be closed.
1621 * This function destroys the screen's cached swap context if any.
1624 loader_dri3_close_screen(__DRIscreen
*dri_screen
)
1626 mtx_lock(&blit_context
.mtx
);
1627 if (blit_context
.ctx
&& blit_context
.cur_screen
== dri_screen
) {
1628 blit_context
.core
->destroyContext(blit_context
.ctx
);
1629 blit_context
.ctx
= NULL
;
1631 mtx_unlock(&blit_context
.mtx
);
1635 * Find a backbuffer slot - potentially allocating a back buffer
1637 * \param draw[in,out] Pointer to the drawable for which to find back.
1638 * \return Pointer to a new back buffer or NULL if allocation failed or was
1641 * Find a potentially new back buffer, and if it's not been allocated yet and
1642 * in addition needs initializing, then try to allocate and initialize it.
1644 static struct loader_dri3_buffer
*
1645 dri3_find_back_alloc(struct loader_dri3_drawable
*draw
)
1647 struct loader_dri3_buffer
*back
;
1650 id
= dri3_find_back(draw
);
1651 back
= (id
>= 0) ? draw
->buffers
[id
] : NULL
;
1653 if (back
|| (id
>= 0 && draw
->back_format
!= __DRI_IMAGE_FORMAT_NONE
)) {
1654 if (dri3_update_drawable(draw
->dri_drawable
, draw
)) {
1655 (void) dri3_get_buffer(draw
->dri_drawable
,
1657 loader_dri3_buffer_back
,
1659 back
= (id
>= 0) ? draw
->buffers
[id
] : NULL
;