diff --git a/src/loader/loader_dri3_helper.c b/src/loader/loader_dri3_helper.c index 2eef6e6..68febcc 100644 --- a/src/loader/loader_dri3_helper.c +++ b/src/loader/loader_dri3_helper.c @@ -32,7 +32,6 @@ #include -#include #include "loader_dri3_helper.h" /* From xmlpool/options.h, user exposed so should be stable */ @@ -261,6 +260,7 @@ loader_dri3_drawable_init(xcb_connection_t *conn, GLint vblank_mode = DRI_CONF_VBLANK_DEF_INTERVAL_1; int swap_interval; + mtx_init(&draw->mtx, mtx_recursive); draw->conn = conn; draw->ext = ext; draw->vtable = vtable; @@ -467,23 +467,30 @@ loader_dri3_wait_for_sbc(struct loader_dri3_drawable *draw, int64_t target_sbc, int64_t *ust, int64_t *msc, int64_t *sbc) { + + mtx_lock(&draw->mtx); + /* From the GLX_OML_sync_control spec: * * "If = 0, the function will block until all previous - * swaps requested with glXSwapBuffersMscOML for that window have + * swaps requested with glXSwapBuffersMscOML for thatq window have * completed." */ if (!target_sbc) target_sbc = draw->send_sbc; while (draw->recv_sbc < target_sbc) { - if (!dri3_wait_for_event(draw)) + if (!dri3_wait_for_event(draw)) { + mtx_unlock(&draw->mtx); return 0; + } } *ust = draw->ust; *msc = draw->msc; *sbc = draw->recv_sbc; + + mtx_unlock(&draw->mtx); return 1; } @@ -769,7 +776,9 @@ loader_dri3_swap_buffers_msc(struct loader_dri3_drawable *draw, int64_t ret = 0; uint32_t options = XCB_PRESENT_OPTION_NONE; int swap_interval; + uint64_t send_sbc; + mtx_lock(&draw->mtx); swap_interval = draw->vtable->get_swap_interval(draw); draw->vtable->flush_drawable(draw, flush_flags); @@ -816,10 +825,10 @@ loader_dri3_swap_buffers_msc(struct loader_dri3_drawable *draw, * request. target_msc=divisor=remainder=0 means "Use glXSwapBuffers() * semantic" */ - ++draw->send_sbc; + send_sbc = draw->send_sbc + 1; if (target_msc == 0 && divisor == 0 && remainder == 0) target_msc = draw->msc + swap_interval * - (draw->send_sbc - draw->recv_sbc); + (send_sbc - draw->recv_sbc); else if (divisor == 0 && remainder > 0) { /* From the GLX_OML_sync_control spec: * "If = 0, the swap will occur when MSC becomes @@ -853,11 +862,11 @@ loader_dri3_swap_buffers_msc(struct loader_dri3_drawable *draw, options |= XCB_PRESENT_OPTION_COPY; back->busy = 1; - back->last_swap = draw->send_sbc; + back->last_swap = send_sbc; xcb_present_pixmap(draw->conn, draw->drawable, back->pixmap, - (uint32_t) draw->send_sbc, + (uint32_t) send_sbc, 0, /* valid */ 0, /* update */ 0, /* x_off */ @@ -869,7 +878,7 @@ loader_dri3_swap_buffers_msc(struct loader_dri3_drawable *draw, target_msc, divisor, remainder, 0, NULL); - ret = (int64_t) draw->send_sbc; + ret = (int64_t) send_sbc; /* Schedule a server-side back-preserving blit if necessary. * This happens iff all conditions below are satisfied: @@ -892,12 +901,14 @@ loader_dri3_swap_buffers_msc(struct loader_dri3_drawable *draw, } xcb_flush(draw->conn); + draw->send_sbc = send_sbc; if (draw->stamp) ++(*draw->stamp); } draw->ext->flush->invalidate(draw->dri_drawable); + mtx_unlock(&draw->mtx); return ret; } diff --git a/src/loader/loader_dri3_helper.h b/src/loader/loader_dri3_helper.h index 7af94bd..ae4db86 100644 --- a/src/loader/loader_dri3_helper.h +++ b/src/loader/loader_dri3_helper.h @@ -33,6 +33,7 @@ #include #include +#include enum loader_dri3_buffer_type { loader_dri3_buffer_back = 0, @@ -161,6 +162,8 @@ struct loader_dri3_drawable { unsigned int swap_method; unsigned int back_format; + + mtx_t mtx; }; void