Commit 20b378e3 authored by Nick Diego Yamane's avatar Nick Diego Yamane Committed by Commit Bot

ozone/wayland: Make surface ownership transferrable

This is required to be able to transfer WaylandWindow's surface
ownership over to WindowDragController in case it gets destroyed in the
middle of a window/tab dragging DnD session. Refer to [1] and [2] for
more details.

Bug: 896640

[1] https://chromium-review.googlesource.com/c/chromium/src/+/2267637
[2] https://docs.google.com/document/d/1s6OwTi_WC-pS21WLGQYI39yw2m42ZlVolUXBclljXB4/edit?usp=sharing

R=msisov@igalia.com

Change-Id: I69360ab208e8754625b5fcd37614530589f0d5c4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2267618
Commit-Queue: Nick Yamane <nickdiego@igalia.com>
Reviewed-by: default avatarMaksim Sisov <msisov@igalia.com>
Cr-Commit-Position: refs/heads/master@{#782992}
parent 65620838
...@@ -4,11 +4,15 @@ ...@@ -4,11 +4,15 @@
#include "ui/ozone/platform/wayland/host/wayland_surface.h" #include "ui/ozone/platform/wayland/host/wayland_surface.h"
#include "ui/ozone/platform/wayland/host/wayland_connection.h"
#include "ui/ozone/platform/wayland/host/wayland_window.h" #include "ui/ozone/platform/wayland/host/wayland_window.h"
namespace ui { namespace ui {
WaylandSurface::WaylandSurface() = default; WaylandSurface::WaylandSurface(WaylandConnection* connection,
WaylandWindow* root_window)
: root_window_(root_window), surface_(connection->CreateSurface()) {}
WaylandSurface::~WaylandSurface() = default; WaylandSurface::~WaylandSurface() = default;
gfx::AcceleratedWidget WaylandSurface::GetWidget() const { gfx::AcceleratedWidget WaylandSurface::GetWidget() const {
......
...@@ -5,17 +5,20 @@ ...@@ -5,17 +5,20 @@
#ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_SURFACE_H_ #ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_SURFACE_H_
#define UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_SURFACE_H_ #define UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_SURFACE_H_
#include <cstdint>
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
#include "ui/ozone/platform/wayland/common/wayland_object.h" #include "ui/ozone/platform/wayland/common/wayland_object.h"
namespace ui { namespace ui {
class WaylandConnection;
class WaylandWindow; class WaylandWindow;
// Wrapper of a wl_surface, owned by a WaylandWindow or a WlSubsurface. // Wrapper of a wl_surface, owned by a WaylandWindow or a WlSubsurface.
class WaylandSurface { class WaylandSurface {
public: public:
WaylandSurface(); WaylandSurface(WaylandConnection* connection, WaylandWindow* root_window);
WaylandSurface(const WaylandSurface&) = delete; WaylandSurface(const WaylandSurface&) = delete;
WaylandSurface& operator=(const WaylandSurface&) = delete; WaylandSurface& operator=(const WaylandSurface&) = delete;
~WaylandSurface(); ~WaylandSurface();
...@@ -23,6 +26,7 @@ class WaylandSurface { ...@@ -23,6 +26,7 @@ class WaylandSurface {
WaylandWindow* root_window() const { return root_window_; } WaylandWindow* root_window() const { return root_window_; }
wl_surface* surface() const { return surface_.get(); } wl_surface* surface() const { return surface_.get(); }
int32_t buffer_scale() const { return buffer_scale_; } int32_t buffer_scale() const { return buffer_scale_; }
void set_buffer_scale(int32_t scale) { buffer_scale_ = scale; }
// gfx::AcceleratedWidget identifies a wl_surface or a ui::WaylandWindow. Note // gfx::AcceleratedWidget identifies a wl_surface or a ui::WaylandWindow. Note
// that GetWidget() and GetRootWidget() do not necessarily return the same // that GetWidget() and GetRootWidget() do not necessarily return the same
...@@ -33,10 +37,10 @@ class WaylandSurface { ...@@ -33,10 +37,10 @@ class WaylandSurface {
private: private:
WaylandWindow* root_window_ = nullptr; WaylandWindow* root_window_ = nullptr;
wl::Object<wl_surface> surface_; wl::Object<wl_surface> surface_;
// Wayland's scale factor for the output that this window currently belongs // Wayland's scale factor for the output that this window currently belongs
// to. // to.
int32_t buffer_scale_ = 1; int32_t buffer_scale_ = 1;
friend class WaylandWindow;
}; };
} // namespace ui } // namespace ui
......
...@@ -80,7 +80,8 @@ void WaylandWindow::UpdateBufferScale(bool update_bounds) { ...@@ -80,7 +80,8 @@ void WaylandWindow::UpdateBufferScale(bool update_bounds) {
} }
gfx::AcceleratedWidget WaylandWindow::GetWidget() const { gfx::AcceleratedWidget WaylandWindow::GetWidget() const {
return wayland_surface_.GetWidget(); DCHECK(wayland_surface_);
return wayland_surface_->GetWidget();
} }
void WaylandWindow::SetPointerFocus(bool focus) { void WaylandWindow::SetPointerFocus(bool focus) {
has_pointer_focus_ = focus; has_pointer_focus_ = focus;
...@@ -316,6 +317,12 @@ void WaylandWindow::SetBoundsDip(const gfx::Rect& bounds_dip) { ...@@ -316,6 +317,12 @@ void WaylandWindow::SetBoundsDip(const gfx::Rect& bounds_dip) {
} }
bool WaylandWindow::Initialize(PlatformWindowInitProperties properties) { bool WaylandWindow::Initialize(PlatformWindowInitProperties properties) {
wayland_surface_ = std::make_unique<WaylandSurface>(connection_, this);
if (!surface()) {
LOG(ERROR) << "Failed to create wl_surface";
return false;
}
// Properties contain DIP bounds but the buffer scale is initially 1 so it's // Properties contain DIP bounds but the buffer scale is initially 1 so it's
// OK to assign. The bounds will be recalculated when the buffer scale // OK to assign. The bounds will be recalculated when the buffer scale
// changes. // changes.
...@@ -324,12 +331,6 @@ bool WaylandWindow::Initialize(PlatformWindowInitProperties properties) { ...@@ -324,12 +331,6 @@ bool WaylandWindow::Initialize(PlatformWindowInitProperties properties) {
opacity_ = properties.opacity; opacity_ = properties.opacity;
type_ = properties.type; type_ = properties.type;
wayland_surface_.surface_ = connection_->CreateSurface();
wayland_surface_.root_window_ = this;
if (!surface()) {
LOG(ERROR) << "Failed to create wl_surface";
return false;
}
wl_surface_set_user_data(surface(), this); wl_surface_set_user_data(surface(), this);
AddSurfaceListener(); AddSurfaceListener();
...@@ -352,12 +353,13 @@ bool WaylandWindow::Initialize(PlatformWindowInitProperties properties) { ...@@ -352,12 +353,13 @@ bool WaylandWindow::Initialize(PlatformWindowInitProperties properties) {
void WaylandWindow::SetBufferScale(int32_t new_scale, bool update_bounds) { void WaylandWindow::SetBufferScale(int32_t new_scale, bool update_bounds) {
DCHECK_GT(new_scale, 0); DCHECK_GT(new_scale, 0);
DCHECK(wayland_surface_);
if (new_scale == buffer_scale()) if (new_scale == buffer_scale())
return; return;
auto old_scale = buffer_scale(); auto old_scale = buffer_scale();
wayland_surface_.buffer_scale_ = new_scale; wayland_surface_->set_buffer_scale(new_scale);
if (update_bounds) if (update_bounds)
SetBoundsDip(gfx::ScaleToRoundedRect(bounds_px_, 1.0 / old_scale)); SetBoundsDip(gfx::ScaleToRoundedRect(bounds_px_, 1.0 / old_scale));
......
...@@ -54,8 +54,8 @@ class WaylandWindow : public PlatformWindow, public PlatformEventDispatcher { ...@@ -54,8 +54,8 @@ class WaylandWindow : public PlatformWindow, public PlatformEventDispatcher {
// to do so (this is not needed upon window initialization). // to do so (this is not needed upon window initialization).
void UpdateBufferScale(bool update_bounds); void UpdateBufferScale(bool update_bounds);
WaylandSurface* wayland_surface() { return &wayland_surface_; } WaylandSurface* wayland_surface() { return wayland_surface_.get(); }
wl_surface* surface() const { return wayland_surface_.surface(); } wl_surface* surface() const { return wayland_surface_->surface(); }
void set_parent_window(WaylandWindow* parent_window) { void set_parent_window(WaylandWindow* parent_window) {
parent_window_ = parent_window; parent_window_ = parent_window;
...@@ -82,7 +82,7 @@ class WaylandWindow : public PlatformWindow, public PlatformEventDispatcher { ...@@ -82,7 +82,7 @@ class WaylandWindow : public PlatformWindow, public PlatformEventDispatcher {
void set_child_window(WaylandWindow* window) { child_window_ = window; } void set_child_window(WaylandWindow* window) { child_window_ = window; }
WaylandWindow* child_window() const { return child_window_; } WaylandWindow* child_window() const { return child_window_; }
int32_t buffer_scale() const { return wayland_surface_.buffer_scale(); } int32_t buffer_scale() const { return wayland_surface_->buffer_scale(); }
int32_t ui_scale() const { return ui_scale_; } int32_t ui_scale() const { return ui_scale_; }
const base::flat_set<uint32_t>& entered_outputs_ids() const { const base::flat_set<uint32_t>& entered_outputs_ids() const {
...@@ -216,7 +216,7 @@ class WaylandWindow : public PlatformWindow, public PlatformEventDispatcher { ...@@ -216,7 +216,7 @@ class WaylandWindow : public PlatformWindow, public PlatformEventDispatcher {
WaylandWindow* parent_window_ = nullptr; WaylandWindow* parent_window_ = nullptr;
WaylandWindow* child_window_ = nullptr; WaylandWindow* child_window_ = nullptr;
WaylandSurface wayland_surface_; std::unique_ptr<WaylandSurface> wayland_surface_;
// The current cursor bitmap (immutable). // The current cursor bitmap (immutable).
scoped_refptr<BitmapCursorOzone> bitmap_; scoped_refptr<BitmapCursorOzone> bitmap_;
......
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