From: Rémi Bernon <rbernon@codeweavers.com> Every other driver does it, it will make life easier. --- dlls/winewayland.drv/wayland.c | 1 + dlls/winewayland.drv/wayland_surface.c | 25 ++++++++++--------- dlls/winewayland.drv/waylanddrv.h | 2 +- dlls/winewayland.drv/window.c | 34 ++++++++++++-------------- 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/dlls/winewayland.drv/wayland.c b/dlls/winewayland.drv/wayland.c index 5b2b0c5b25b..c5d04b81fe5 100644 --- a/dlls/winewayland.drv/wayland.c +++ b/dlls/winewayland.drv/wayland.c @@ -117,6 +117,7 @@ static void registry_handle_global(void *data, struct wl_registry *registry, { process_wayland.wl_compositor = wl_registry_bind(registry, id, &wl_compositor_interface, 4); + wayland_window_init(); } else if (strcmp(interface, "xdg_wm_base") == 0) { diff --git a/dlls/winewayland.drv/wayland_surface.c b/dlls/winewayland.drv/wayland_surface.c index 0dae0922179..39064b61e62 100644 --- a/dlls/winewayland.drv/wayland_surface.c +++ b/dlls/winewayland.drv/wayland_surface.c @@ -766,9 +766,10 @@ static void wayland_surface_reconfigure_subsurface(struct wayland_surface *surfa struct wayland_win_data *owner_data; struct wayland_surface *owner_surface; - if (surface->processing.serial && surface->processing.processed && - (owner_data = wayland_win_data_get_nolock(surface->owner_hwnd)) && - (owner_surface = owner_data->wayland_surface)) + if (!surface->processing.serial || !surface->processing.processed) return; + if (!(owner_data = wayland_win_data_get(surface->owner_hwnd))) return; + + if ((owner_surface = owner_data->wayland_surface)) { RECT rect = surface->window.rect; @@ -786,6 +787,8 @@ static void wayland_surface_reconfigure_subsurface(struct wayland_surface *surfa memset(&surface->processing, 0, sizeof(surface->processing)); } + + wayland_win_data_release(owner_data); } /********************************************************************** @@ -1276,10 +1279,10 @@ void wayland_client_surface_attach(struct wayland_client_surface *client, HWND t return; } - if (!(toplevel_data = wayland_win_data_get_nolock(toplevel)) || !(surface = toplevel_data->wayland_surface)) + if (!(toplevel_data = wayland_win_data_get(toplevel)) || !(surface = toplevel_data->wayland_surface)) { - wayland_client_surface_attach(client, NULL); - return; + if (toplevel_data) wayland_win_data_release(toplevel_data); + return wayland_client_surface_attach(client, NULL); } if (client->toplevel != toplevel) @@ -1290,11 +1293,8 @@ void wayland_client_surface_attach(struct wayland_client_surface *client, HWND t wl_subcompositor_get_subsurface(process_wayland.wl_subcompositor, client->wl_surface, surface->wl_surface); - if (!client->wl_subsurface) - { - ERR("Failed to create client wl_subsurface\n"); - return; - } + if (!client->wl_subsurface) goto done; + /* Present contents independently of the parent surface. */ wl_subsurface_set_desync(client->wl_subsurface); @@ -1307,6 +1307,9 @@ void wayland_client_surface_attach(struct wayland_client_surface *client, HWND t wayland_surface_reconfigure_client(surface, client, &client_rect); /* Commit to apply subsurface positioning. */ wl_surface_commit(surface->wl_surface); + +done: + wayland_win_data_release(toplevel_data); } static void dummy_buffer_release(void *data, struct wl_buffer *buffer) diff --git a/dlls/winewayland.drv/waylanddrv.h b/dlls/winewayland.drv/waylanddrv.h index e0df8e56bb5..8df6fa5a986 100644 --- a/dlls/winewayland.drv/waylanddrv.h +++ b/dlls/winewayland.drv/waylanddrv.h @@ -385,7 +385,6 @@ struct wayland_win_data }; struct wayland_win_data *wayland_win_data_get(HWND hwnd); -struct wayland_win_data *wayland_win_data_get_nolock(HWND hwnd); void wayland_win_data_release(struct wayland_win_data *data); struct wayland_client_surface *get_client_surface(HWND hwnd); @@ -393,6 +392,7 @@ void set_client_surface(HWND hwnd, struct wayland_client_surface *client); BOOL set_window_surface_contents(HWND hwnd, struct wayland_shm_buffer *shm_buffer, HRGN damage_region); struct wayland_shm_buffer *get_window_surface_contents(HWND hwnd); void ensure_window_surface_contents(HWND hwnd); +void wayland_window_init(void); /********************************************************************** * Wayland Keyboard diff --git a/dlls/winewayland.drv/window.c b/dlls/winewayland.drv/window.c index afef743755b..de4188957bd 100644 --- a/dlls/winewayland.drv/window.c +++ b/dlls/winewayland.drv/window.c @@ -104,22 +104,6 @@ static void wayland_win_data_destroy(struct wayland_win_data *data) free(data); } -/*********************************************************************** - * wayland_win_data_get_nolock - * - * Return the data structure associated with a window. This function does - * not lock the win_data_mutex, so it must be externally synchronized. - */ -struct wayland_win_data *wayland_win_data_get_nolock(HWND hwnd) -{ - struct rb_entry *rb_entry; - - if ((rb_entry = rb_get(&win_data_rb, hwnd))) - return RB_ENTRY_VALUE(rb_entry, struct wayland_win_data, entry); - - return NULL; -} - /*********************************************************************** * wayland_win_data_get * @@ -127,10 +111,11 @@ struct wayland_win_data *wayland_win_data_get_nolock(HWND hwnd) */ struct wayland_win_data *wayland_win_data_get(HWND hwnd) { - struct wayland_win_data *data; + struct rb_entry *entry; pthread_mutex_lock(&win_data_mutex); - if ((data = wayland_win_data_get_nolock(hwnd))) return data; + if ((entry = rb_get(&win_data_rb, hwnd))) + return RB_ENTRY_VALUE(entry, struct wayland_win_data, entry); pthread_mutex_unlock(&win_data_mutex); return NULL; @@ -460,7 +445,7 @@ void WAYLAND_WindowPosChanged(HWND hwnd, HWND insert_after, HWND owner_hint, UIN if (!(managed = is_window_managed(hwnd, swp_flags, fullscreen)) && surface) owner = owner_hint; if (!(data = wayland_win_data_get(hwnd))) return; - owner_data = owner && owner != hwnd ? wayland_win_data_get_nolock(owner) : NULL; + owner_data = owner && owner != hwnd ? wayland_win_data_get(owner) : NULL; owner_surface = owner_data ? owner_data->wayland_surface : NULL; data->rects = *new_rects; @@ -489,6 +474,7 @@ void WAYLAND_WindowPosChanged(HWND hwnd, HWND insert_after, HWND owner_hint, UIN wayland_win_data_update_wayland_state(data); } + if (owner_data) wayland_win_data_release(owner_data); wayland_win_data_release(data); } @@ -924,3 +910,13 @@ void ensure_window_surface_contents(HWND hwnd) wayland_win_data_release(data); } + +void wayland_window_init(void) +{ + pthread_mutexattr_t attr; + + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutex_init(&win_data_mutex, &attr); + pthread_mutexattr_destroy(&attr); +} -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/11225