From 4657edaf9f798863d16d94e61a3f467ee656e908 Mon Sep 17 00:00:00 2001 From: Adrian Perez de Castro Date: Sat, 10 Apr 2021 18:27:42 +0300 Subject: [PATCH 07/13] Revert "view backend: Properly unregister surfaces" This reverts commit 99bd04019800f84a722ae99bf1a352f225d93002. --- src/view-backend-private.cpp | 52 +++++++++++++----------------------- src/view-backend-private.h | 8 +++--- 2 files changed, 24 insertions(+), 36 deletions(-) diff --git a/src/view-backend-private.cpp b/src/view-backend-private.cpp index f04a57e..4920037 100644 --- a/src/view-backend-private.cpp +++ b/src/view-backend-private.cpp @@ -34,13 +34,12 @@ ViewBackend::ViewBackend(ClientBundle* clientBundle, struct wpe_view_backend* ba , m_backend(backend) { m_clientBundle->viewBackend = this; - - wl_list_init(&m_clientDestroy.link); } ViewBackend::~ViewBackend() { unregisterSurface(m_bridgeId); + if (m_clientFd != -1) close(m_clientFd); } @@ -96,39 +95,24 @@ void ViewBackend::dispatchFrameCallbacks() if (G_LIKELY(m_bridgeId)) WS::Instance::singleton().dispatchFrameCallbacks(m_bridgeId); + if (m_client.object) + wl_client_flush(m_client.object); wpe_view_backend_dispatch_frame_displayed(m_backend); } void ViewBackend::releaseBuffer(struct wl_resource* buffer_resource) { - if (G_UNLIKELY(!m_client)) - return; - wl_buffer_send_release(buffer_resource); - wl_client_flush(m_client); -} - -void ViewBackend::clientDestroyNotify(struct wl_listener* listener, void*) -{ - ViewBackend* self = wl_container_of(listener, self, m_clientDestroy); - - WS::Instance::singleton().unregisterViewBackend(self->m_bridgeId); - self->m_client = nullptr; - self->m_bridgeId = 0; - - wl_list_remove(&self->m_clientDestroy.link); + if (m_client.object) + wl_client_flush(m_client.object); } void ViewBackend::registerSurface(uint32_t bridgeId) { - if (m_bridgeId == bridgeId) - return; - - unregisterSurface(m_bridgeId); - m_bridgeId = bridgeId; - m_client = WS::Instance::singleton().registerViewBackend(m_bridgeId, *this); - wl_client_add_destroy_listener(m_client, &m_clientDestroy); + m_client.object = WS::Instance::singleton().registerViewBackend(m_bridgeId, *this); + m_client.destroyListener.notify = Client::destroyNotify; + wl_client_add_destroy_listener(m_client.object, &m_client.destroyListener); } void ViewBackend::unregisterSurface(uint32_t bridgeId) @@ -136,16 +120,10 @@ void ViewBackend::unregisterSurface(uint32_t bridgeId) if (!bridgeId || m_bridgeId != bridgeId) return; - // If the surfaceId is valid, we cannot have an invalid wl_client. - g_assert(m_client != nullptr); - - // Destroying the client triggers the m_clientDestroy callback, - // the rest of the teardown is done from there. - wl_client_destroy(m_client); + g_clear_pointer(&m_client.object, wl_client_destroy); - // After destroying the client, none of these can be valid. - g_assert(m_client == nullptr); - g_assert(m_bridgeId == 0); + WS::Instance::singleton().unregisterViewBackend(m_bridgeId); + m_bridgeId = 0; } void ViewBackend::didReceiveMessage(uint32_t messageId, uint32_t messageBody) @@ -161,3 +139,11 @@ void ViewBackend::didReceiveMessage(uint32_t messageId, uint32_t messageBody) assert(!"WPE fdo received an invalid IPC message"); } } + +void ViewBackend::Client::destroyNotify(struct wl_listener* listener, void*) +{ + Client* client; + client = wl_container_of(listener, client, destroyListener); + + client->object = nullptr; +} diff --git a/src/view-backend-private.h b/src/view-backend-private.h index a598dee..37eab08 100644 --- a/src/view-backend-private.h +++ b/src/view-backend-private.h @@ -79,10 +79,12 @@ private: static gboolean s_socketCallback(GSocket*, GIOCondition, gpointer); uint32_t m_bridgeId { 0 }; + struct Client { + struct wl_client* object { nullptr }; + struct wl_listener destroyListener; - static void clientDestroyNotify(struct wl_listener*, void*); - struct wl_listener m_clientDestroy { {}, clientDestroyNotify }; - struct wl_client* m_client { nullptr }; + static void destroyNotify(struct wl_listener*, void*); + } m_client; ClientBundle* m_clientBundle; struct wpe_view_backend* m_backend; -- 2.31.1