Commit dcab063e authored by Nick Diego Yamane's avatar Nick Diego Yamane Committed by Commit Bot

[ozone/wayland]: Improve DataDevice initialization

This CL is intended to make the Wayland data device
initialization more robust, removing the assumption
that data device manager global object is advertised
before the wl_seat.

Additionally this patch does a minor code cleanup in
WaylandDataDeviceManager, removing the WaylandConnection
setter, injecting connection instance via its constructor
instead, as it is already being done in other classes, such
as WaylandDataSource, for example.

Bug: 578890
Change-Id: Ia700c164f18b2778b08047bfcb5ccf382e69328f
Reviewed-on: https://chromium-review.googlesource.com/c/1487853Reviewed-by: default avatarMaksim Sisov <msisov@igalia.com>
Reviewed-by: default avatarAntonio Gomes <tonikitoo@igalia.com>
Commit-Queue: Nick Diego Yamane <nickdiego@igalia.com>
Cr-Commit-Position: refs/heads/master@{#635489}
parent 5b9f6ef2
...@@ -405,6 +405,14 @@ void WaylandConnection::TerminateGpuProcess(std::string reason) { ...@@ -405,6 +405,14 @@ void WaylandConnection::TerminateGpuProcess(std::string reason) {
buffer_manager_->ClearState(); buffer_manager_->ClearState();
} }
void WaylandConnection::EnsureDataDevice() {
if (!data_device_manager_ || !seat_)
return;
DCHECK(!data_device_);
wl_data_device* data_device = data_device_manager_->GetDevice();
data_device_ = std::make_unique<WaylandDataDevice>(this, data_device);
}
// static // static
void WaylandConnection::Global(void* data, void WaylandConnection::Global(void* data,
wl_registry* registry, wl_registry* registry,
...@@ -448,19 +456,7 @@ void WaylandConnection::Global(void* data, ...@@ -448,19 +456,7 @@ void WaylandConnection::Global(void* data,
return; return;
} }
wl_seat_add_listener(connection->seat_.get(), &seat_listener, connection); wl_seat_add_listener(connection->seat_.get(), &seat_listener, connection);
connection->EnsureDataDevice();
// TODO(tonikitoo,msisov): The connection passed to WaylandInputDevice must
// have a valid data device manager. We should ideally be robust to the
// compositor advertising a wl_seat first. No known compositor does this,
// fortunately.
if (!connection->data_device_manager_) {
LOG(ERROR)
<< "No data device manager. Clipboard won't be fully functional";
return;
}
wl_data_device* data_device = connection->data_device_manager_->GetDevice();
connection->data_device_.reset(
new WaylandDataDevice(connection, data_device));
} else if (!connection->shell_v6_ && } else if (!connection->shell_v6_ &&
strcmp(interface, "zxdg_shell_v6") == 0) { strcmp(interface, "zxdg_shell_v6") == 0) {
// Check for zxdg_shell_v6 first. // Check for zxdg_shell_v6 first.
...@@ -514,9 +510,9 @@ void WaylandConnection::Global(void* data, ...@@ -514,9 +510,9 @@ void WaylandConnection::Global(void* data,
LOG(ERROR) << "Failed to bind to wl_data_device_manager global"; LOG(ERROR) << "Failed to bind to wl_data_device_manager global";
return; return;
} }
connection->data_device_manager_.reset( connection->data_device_manager_.reset(new WaylandDataDeviceManager(
new WaylandDataDeviceManager(data_device_manager.release())); data_device_manager.release(), connection));
connection->data_device_manager_->set_connection(connection); connection->EnsureDataDevice();
} else if (!connection->buffer_manager_ && } else if (!connection->buffer_manager_ &&
(strcmp(interface, "zwp_linux_dmabuf_v1") == 0)) { (strcmp(interface, "zwp_linux_dmabuf_v1") == 0)) {
wl::Object<zwp_linux_dmabuf_v1> zwp_linux_dmabuf = wl::Object<zwp_linux_dmabuf_v1> zwp_linux_dmabuf =
......
...@@ -199,6 +199,9 @@ class WaylandConnection : public PlatformEventSource, ...@@ -199,6 +199,9 @@ class WaylandConnection : public PlatformEventSource,
// Terminates the GPU process on invalid data received // Terminates the GPU process on invalid data received
void TerminateGpuProcess(std::string reason); void TerminateGpuProcess(std::string reason);
// Make sure data device is properly initialized
void EnsureDataDevice();
// wl_registry_listener // wl_registry_listener
static void Global(void* data, static void Global(void* data,
wl_registry* registry, wl_registry* registry,
......
...@@ -9,8 +9,12 @@ ...@@ -9,8 +9,12 @@
namespace ui { namespace ui {
WaylandDataDeviceManager::WaylandDataDeviceManager( WaylandDataDeviceManager::WaylandDataDeviceManager(
wl_data_device_manager* device_manager) wl_data_device_manager* device_manager,
: device_manager_(device_manager) {} WaylandConnection* connection)
: device_manager_(device_manager), connection_(connection) {
DCHECK(connection_);
DCHECK(device_manager_);
}
WaylandDataDeviceManager::~WaylandDataDeviceManager() = default; WaylandDataDeviceManager::~WaylandDataDeviceManager() = default;
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include <wayland-client.h> #include <wayland-client.h>
#include "base/logging.h"
#include "base/macros.h" #include "base/macros.h"
#include "ui/ozone/platform/wayland/wayland_object.h" #include "ui/ozone/platform/wayland/wayland_object.h"
...@@ -17,21 +16,17 @@ class WaylandConnection; ...@@ -17,21 +16,17 @@ class WaylandConnection;
class WaylandDataDeviceManager { class WaylandDataDeviceManager {
public: public:
explicit WaylandDataDeviceManager(wl_data_device_manager* device_manager); WaylandDataDeviceManager(wl_data_device_manager* device_manager,
WaylandConnection* connection);
~WaylandDataDeviceManager(); ~WaylandDataDeviceManager();
wl_data_device* GetDevice(); wl_data_device* GetDevice();
wl_data_source* CreateSource(); wl_data_source* CreateSource();
void set_connection(WaylandConnection* connection) {
DCHECK(connection);
connection_ = connection;
}
private: private:
wl::Object<wl_data_device_manager> device_manager_; wl::Object<wl_data_device_manager> device_manager_;
WaylandConnection* connection_ = nullptr; WaylandConnection* connection_;
DISALLOW_COPY_AND_ASSIGN(WaylandDataDeviceManager); DISALLOW_COPY_AND_ASSIGN(WaylandDataDeviceManager);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment