Skip to content

Commit

Permalink
Keep list of bridgeIds associated with each ViewBackend
Browse files Browse the repository at this point in the history
As each ViewBackend (and hence web view) can get its contents rendered
by different WPEWebProcess due to PSON, keep around a list of all the
differen bridgeIds which have been associated with it in a std::vector.
Newly added elements are always pushed at the back, so the most recent
association (i.e. the "current" active one) is always the last element.
Keeping the list allows getting back to the previously used ones.

(cherry picked from commit 3af2f17)
  • Loading branch information
aperezdc committed May 12, 2021
1 parent b86b0db commit 007a285
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
23 changes: 13 additions & 10 deletions src/view-backend-private.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <cassert>
#include <sys/types.h>
#include <sys/socket.h>
#include <algorithm>

ViewBackend::ViewBackend(ClientBundle* clientBundle, struct wpe_view_backend* backend)
: m_clientBundle(clientBundle)
Expand All @@ -38,7 +39,8 @@ ViewBackend::ViewBackend(ClientBundle* clientBundle, struct wpe_view_backend* ba

ViewBackend::~ViewBackend()
{
unregisterSurface(m_bridgeId);
while (!m_bridgeIds.empty())
unregisterSurface(m_bridgeIds.front());

if (m_clientFd != -1)
close(m_clientFd);
Expand Down Expand Up @@ -92,10 +94,10 @@ void ViewBackend::exportEGLStreamProducer(struct wl_resource* bufferResource)

void ViewBackend::dispatchFrameCallbacks()
{
if (G_LIKELY(m_bridgeId))
WS::Instance::singleton().dispatchFrameCallbacks(m_bridgeId);

wpe_view_backend_dispatch_frame_displayed(m_backend);
if (G_LIKELY(!m_bridgeIds.empty())) {
WS::Instance::singleton().dispatchFrameCallbacks(m_bridgeIds.back());
wpe_view_backend_dispatch_frame_displayed(m_backend);
}
}

void ViewBackend::releaseBuffer(struct wl_resource* buffer_resource)
Expand All @@ -106,17 +108,18 @@ void ViewBackend::releaseBuffer(struct wl_resource* buffer_resource)

void ViewBackend::registerSurface(uint32_t bridgeId)
{
m_bridgeId = bridgeId;
WS::Instance::singleton().registerViewBackend(m_bridgeId, *this);
m_bridgeIds.push_back(bridgeId);
WS::Instance::singleton().registerViewBackend(m_bridgeIds.back(), *this);
}

void ViewBackend::unregisterSurface(uint32_t bridgeId)
{
if (!bridgeId || m_bridgeId != bridgeId)
auto it = std::find(m_bridgeIds.begin(), m_bridgeIds.end(), bridgeId);
if (it == m_bridgeIds.end())
return;

WS::Instance::singleton().unregisterViewBackend(m_bridgeId);
m_bridgeId = 0;
m_bridgeIds.erase(it);
WS::Instance::singleton().unregisterViewBackend(bridgeId);
}

void ViewBackend::didReceiveMessage(uint32_t messageId, uint32_t messageBody)
Expand Down
3 changes: 2 additions & 1 deletion src/view-backend-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include <gio/gio.h>
#include <wpe/wpe.h>
#include <vector>

class ViewBackend;

Expand Down Expand Up @@ -78,7 +79,7 @@ class ViewBackend final : public WS::APIClient, public FdoIPC::MessageReceiver {

static gboolean s_socketCallback(GSocket*, GIOCondition, gpointer);

uint32_t m_bridgeId { 0 };
std::vector<uint32_t> m_bridgeIds;

ClientBundle* m_clientBundle;
struct wpe_view_backend* m_backend;
Expand Down

0 comments on commit 007a285

Please sign in to comment.