Revert "wayland: dispatch and wait for compositor events in uninit"

This ended up being a bad idea. The problem is that it introduces
ordering when destroying events (something we weren't worried about
before) and Lynne pointed out a problem with the callback not also being
destroyed before the surface in IRC. Just undo this and go with a
different approach (next commit). P.S. the wayland_dispatch_events name
change is kept though because I like that better.

This reverts commit aa8ddfcdf3.
This commit is contained in:
Dudemanguy 2023-01-13 22:03:00 -06:00
parent 73581d8fe6
commit f32c5586d6
2 changed files with 27 additions and 22 deletions

View File

@ -1022,8 +1022,13 @@ static void feedback_presented(void *data, struct wp_presentation_feedback *fbac
{
struct vo_wayland_state *wl = data;
if (fback)
// NULL is needed to prevent a dangling pointer since presentation_feedback
// is created in the frame_callback and not in any of the actual presentation
// events.
if (fback) {
wp_presentation_feedback_destroy(fback);
wl->feedback = NULL;
}
wl->refresh_interval = (int64_t)refresh_nsec / 1000;
@ -1044,8 +1049,13 @@ static void feedback_presented(void *data, struct wp_presentation_feedback *fbac
static void feedback_discarded(void *data, struct wp_presentation_feedback *fback)
{
if (fback)
struct vo_wayland_state *wl = data;
// Same logic in feedback_presented applies here.
if (fback) {
wp_presentation_feedback_destroy(fback);
wl->feedback = NULL;
}
}
static const struct wp_presentation_feedback_listener feedback_listener = {
@ -1063,15 +1073,12 @@ static void frame_callback(void *data, struct wl_callback *callback, uint32_t ti
if (callback)
wl_callback_destroy(callback);
if (!wl->surface)
return;
wl->frame_callback = wl_surface_frame(wl->surface);
wl_callback_add_listener(wl->frame_callback, &frame_listener, wl);
if (wl->use_present) {
struct wp_presentation_feedback *fback = wp_presentation_feedback(wl->presentation, wl->surface);
wp_presentation_feedback_add_listener(fback, &feedback_listener, wl);
wl->feedback = wp_presentation_feedback(wl->presentation, wl->surface);
wp_presentation_feedback_add_listener(wl->feedback, &feedback_listener, wl);
}
wl->frame_wait = false;
@ -2124,21 +2131,6 @@ void vo_wayland_uninit(struct vo *vo)
if (!wl)
return;
// Destroy wl_surface and its roles first
// to trigger any discard events.
if (wl->xdg_toplevel)
xdg_toplevel_destroy(wl->xdg_toplevel);
if (wl->xdg_surface)
xdg_surface_destroy(wl->xdg_surface);
if (wl->surface)
wl_surface_destroy(wl->surface);
// Process any final events.
if (wl->display && wl_display_roundtrip(wl->display))
wayland_dispatch_events(wl, 1, 50); //TODO: make timeout 0
mp_input_put_key(wl->vo->input_ctx, MP_INPUT_RELEASE_ALL);
if (wl->compositor)
@ -2173,6 +2165,9 @@ void vo_wayland_uninit(struct vo *vo)
if (wl->dnd_offer)
wl_data_offer_destroy(wl->dnd_offer);
if (wl->feedback)
wp_presentation_feedback_destroy(wl->feedback);
if (wl->frame_callback)
wl_callback_destroy(wl->frame_callback);
@ -2222,6 +2217,9 @@ void vo_wayland_uninit(struct vo *vo)
wp_single_pixel_buffer_manager_v1_destroy(wl->single_pixel_manager);
#endif
if (wl->surface)
wl_surface_destroy(wl->surface);
if (wl->video_surface)
wl_surface_destroy(wl->video_surface);
@ -2234,9 +2232,15 @@ void vo_wayland_uninit(struct vo *vo)
if (wl->xdg_decoration_manager)
zxdg_decoration_manager_v1_destroy(wl->xdg_decoration_manager);
if (wl->xdg_toplevel)
xdg_toplevel_destroy(wl->xdg_toplevel);
if (wl->xdg_toplevel_decoration)
zxdg_toplevel_decoration_v1_destroy(wl->xdg_toplevel_decoration);
if (wl->xdg_surface)
xdg_surface_destroy(wl->xdg_surface);
if (wl->xkb_context)
xkb_context_unref(wl->xkb_context);

View File

@ -97,6 +97,7 @@ struct vo_wayland_state {
/* presentation-time */
struct wp_presentation *presentation;
struct wp_presentation_feedback *feedback;
struct mp_present *present;
int64_t refresh_interval;
bool use_present;