Commit 21cbdffe authored by Kramer Ge's avatar Kramer Ge Committed by Commit Bot

[ozone/wayland]Move wl_surface and related fields out of WaylandWindow

Currently a wl_surface is in a 1:1 relationship with WaylandWindow. To
get wayland subsurface forwarding, fields that are 1:1 to wl_surface
should be grouped and moved out of WaylandWindow. In the future,
WaylandWindow can have 1 to many relationship with wl_surfaces, some of
which are assigned wl_subsurface role.

A new WaylandSurface class is created. Original WaylandSurface is now
renamed to WaylandToplevelWindow.

Bug: 1063865
Change-Id: I23feed2a98329e3c0cc5067065af6e7dd1b2e4b4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2261252Reviewed-by: default avatarMaksim Sisov <msisov@igalia.com>
Commit-Queue: Kramer Ge <fangzhoug@chromium.org>
Cr-Commit-Position: refs/heads/master@{#782022}
parent 5c42a704
...@@ -105,6 +105,8 @@ source_set("wayland") { ...@@ -105,6 +105,8 @@ source_set("wayland") {
"host/wayland_subsurface.h", "host/wayland_subsurface.h",
"host/wayland_surface.cc", "host/wayland_surface.cc",
"host/wayland_surface.h", "host/wayland_surface.h",
"host/wayland_toplevel_window.cc",
"host/wayland_toplevel_window.h",
"host/wayland_touch.cc", "host/wayland_touch.cc",
"host/wayland_touch.h", "host/wayland_touch.h",
"host/wayland_window.cc", "host/wayland_window.cc",
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "ui/ozone/platform/wayland/host/wayland_connection.h" #include "ui/ozone/platform/wayland/host/wayland_connection.h"
#include "ui/ozone/platform/wayland/host/wayland_drm.h" #include "ui/ozone/platform/wayland/host/wayland_drm.h"
#include "ui/ozone/platform/wayland/host/wayland_shm.h" #include "ui/ozone/platform/wayland/host/wayland_shm.h"
#include "ui/ozone/platform/wayland/host/wayland_surface.h"
#include "ui/ozone/platform/wayland/host/wayland_window.h" #include "ui/ozone/platform/wayland/host/wayland_window.h"
#include "ui/ozone/platform/wayland/host/wayland_zwp_linux_dmabuf.h" #include "ui/ozone/platform/wayland/host/wayland_zwp_linux_dmabuf.h"
...@@ -55,10 +56,10 @@ std::string NumberToString(uint32_t number) { ...@@ -55,10 +56,10 @@ std::string NumberToString(uint32_t number) {
class WaylandBufferManagerHost::Surface { class WaylandBufferManagerHost::Surface {
public: public:
Surface(WaylandWindow* window, Surface(WaylandSurface* wayland_surface,
WaylandConnection* connection, WaylandConnection* connection,
WaylandBufferManagerHost* buffer_manager) WaylandBufferManagerHost* buffer_manager)
: window_(window), : wayland_surface_(wayland_surface),
connection_(connection), connection_(connection),
buffer_manager_(buffer_manager) {} buffer_manager_(buffer_manager) {}
~Surface() = default; ~Surface() = default;
...@@ -67,7 +68,7 @@ class WaylandBufferManagerHost::Surface { ...@@ -67,7 +68,7 @@ class WaylandBufferManagerHost::Surface {
DCHECK(!pending_buffer_); DCHECK(!pending_buffer_);
// The window has already been destroyed. // The window has already been destroyed.
if (!window_) if (!wayland_surface_)
return true; return true;
WaylandBuffer* buffer = GetBuffer(buffer_id); WaylandBuffer* buffer = GetBuffer(buffer_id);
...@@ -126,7 +127,7 @@ class WaylandBufferManagerHost::Surface { ...@@ -126,7 +127,7 @@ class WaylandBufferManagerHost::Surface {
// the client about successful swap. // the client about successful swap.
// If the window has already been destroyed, no need to complete the // If the window has already been destroyed, no need to complete the
// submission. // submission.
if (buffer && !buffer->released && submitted_buffer_ && window_) if (buffer && !buffer->released && submitted_buffer_ && wayland_surface_)
CompleteSubmission(); CompleteSubmission();
if (prev_submitted_buffer_ == buffer) if (prev_submitted_buffer_ == buffer)
...@@ -172,11 +173,11 @@ class WaylandBufferManagerHost::Surface { ...@@ -172,11 +173,11 @@ class WaylandBufferManagerHost::Surface {
} }
void ResetSurfaceContents() { void ResetSurfaceContents() {
if (!window_) if (!wayland_surface_)
return; return;
wl_surface_attach(window_->surface(), nullptr, 0, 0); wl_surface_attach(wayland_surface_->surface(), nullptr, 0, 0);
wl_surface_commit(window_->surface()); wl_surface_commit(wayland_surface_->surface());
// We cannot reset |prev_submitted_buffer_| here as long as the surface // We cannot reset |prev_submitted_buffer_| here as long as the surface
// might have attached a new buffer and is about to receive a release // might have attached a new buffer and is about to receive a release
...@@ -199,8 +200,8 @@ class WaylandBufferManagerHost::Surface { ...@@ -199,8 +200,8 @@ class WaylandBufferManagerHost::Surface {
bool HasBuffers() const { return !buffers_.empty(); } bool HasBuffers() const { return !buffers_.empty(); }
void OnWindowRemoved() { window_ = nullptr; } void OnWindowRemoved() { wayland_surface_ = nullptr; }
bool HasWindow() const { return !!window_; } bool HasWindow() const { return !!wayland_surface_; }
void OnWindowConfigured() { void OnWindowConfigured() {
if (configured_) if (configured_)
...@@ -226,7 +227,7 @@ class WaylandBufferManagerHost::Surface { ...@@ -226,7 +227,7 @@ class WaylandBufferManagerHost::Surface {
using PresentationFeedbackQueue = std::vector<FeedbackInfo>; using PresentationFeedbackQueue = std::vector<FeedbackInfo>;
bool CommitBufferInternal(WaylandBuffer* buffer) { bool CommitBufferInternal(WaylandBuffer* buffer) {
DCHECK(buffer && window_); DCHECK(buffer && wayland_surface_);
DCHECK(!pending_buffer_); DCHECK(!pending_buffer_);
DCHECK(!submitted_buffer_); DCHECK(!submitted_buffer_);
...@@ -274,7 +275,7 @@ class WaylandBufferManagerHost::Surface { ...@@ -274,7 +275,7 @@ class WaylandBufferManagerHost::Surface {
} }
void DamageBuffer(WaylandBuffer* buffer) { void DamageBuffer(WaylandBuffer* buffer) {
DCHECK(window_); DCHECK(wayland_surface_);
gfx::Rect pending_damage_region = std::move(buffer->damage_region); gfx::Rect pending_damage_region = std::move(buffer->damage_region);
// If the size of the damage region is empty, wl_surface_damage must be // If the size of the damage region is empty, wl_surface_damage must be
...@@ -290,10 +291,10 @@ class WaylandBufferManagerHost::Surface { ...@@ -290,10 +291,10 @@ class WaylandBufferManagerHost::Surface {
// https://bit.ly/2u00lv6 for details. // https://bit.ly/2u00lv6 for details.
// We don't need to apply any scaling because pending_damage_region is // We don't need to apply any scaling because pending_damage_region is
// already in buffer coordinates. // already in buffer coordinates.
wl_surface_damage_buffer(window_->surface(), pending_damage_region.x(), wl_surface_damage_buffer(
pending_damage_region.y(), wayland_surface_->surface(), pending_damage_region.x(),
pending_damage_region.width(), pending_damage_region.y(), pending_damage_region.width(),
pending_damage_region.height()); pending_damage_region.height());
} else { } else {
// The calculation for damage region relies on two assumptions: // The calculation for damage region relies on two assumptions:
// 1) The buffer is always attached at surface location (0, 0) // 1) The buffer is always attached at surface location (0, 0)
...@@ -304,8 +305,9 @@ class WaylandBufferManagerHost::Surface { ...@@ -304,8 +305,9 @@ class WaylandBufferManagerHost::Surface {
// Note: The damage region may not be an integer multiple of scale. To // Note: The damage region may not be an integer multiple of scale. To
// keep the implementation simple, the x() and y() coordinates round down, // keep the implementation simple, the x() and y() coordinates round down,
// and the width() and height() calculations always add an extra pixel. // and the width() and height() calculations always add an extra pixel.
int scale = window_->buffer_scale(); int scale = wayland_surface_->buffer_scale();
wl_surface_damage(window_->surface(), pending_damage_region.x() / scale, wl_surface_damage(wayland_surface_->surface(),
pending_damage_region.x() / scale,
pending_damage_region.y() / scale, pending_damage_region.y() / scale,
pending_damage_region.width() / scale + 1, pending_damage_region.width() / scale + 1,
pending_damage_region.height() / scale + 1); pending_damage_region.height() / scale + 1);
...@@ -313,31 +315,32 @@ class WaylandBufferManagerHost::Surface { ...@@ -313,31 +315,32 @@ class WaylandBufferManagerHost::Surface {
} }
void AttachBuffer(WaylandBuffer* buffer) { void AttachBuffer(WaylandBuffer* buffer) {
DCHECK(window_ && configured_); DCHECK(wayland_surface_ && configured_);
// The logic in DamageBuffer currently relies on attachment coordinates of // The logic in DamageBuffer currently relies on attachment coordinates of
// (0, 0). If this changes, then the calculation in DamageBuffer will also // (0, 0). If this changes, then the calculation in DamageBuffer will also
// need to be updated. // need to be updated.
wl_surface_attach(window_->surface(), buffer->wl_buffer.get(), 0, 0); wl_surface_attach(wayland_surface_->surface(), buffer->wl_buffer.get(), 0,
0);
} }
void CommitSurface() { void CommitSurface() {
DCHECK(window_); DCHECK(wayland_surface_);
wl_surface_commit(window_->surface()); wl_surface_commit(wayland_surface_->surface());
} }
void SetupFrameCallback() { void SetupFrameCallback() {
DCHECK(window_); DCHECK(wayland_surface_);
static const wl_callback_listener frame_listener = { static const wl_callback_listener frame_listener = {
&Surface::FrameCallbackDone}; &Surface::FrameCallbackDone};
DCHECK(!wl_frame_callback_); DCHECK(!wl_frame_callback_);
wl_frame_callback_.reset(wl_surface_frame(window_->surface())); wl_frame_callback_.reset(wl_surface_frame(wayland_surface_->surface()));
wl_callback_add_listener(wl_frame_callback_.get(), &frame_listener, this); wl_callback_add_listener(wl_frame_callback_.get(), &frame_listener, this);
} }
void SetupPresentationFeedback(uint32_t buffer_id) { void SetupPresentationFeedback(uint32_t buffer_id) {
DCHECK(window_); DCHECK(wayland_surface_);
// Set up presentation feedback. // Set up presentation feedback.
if (!connection_->presentation()) if (!connection_->presentation())
return; return;
...@@ -348,7 +351,7 @@ class WaylandBufferManagerHost::Surface { ...@@ -348,7 +351,7 @@ class WaylandBufferManagerHost::Surface {
feedback_queue_.push_back( feedback_queue_.push_back(
{wl::Object<struct wp_presentation_feedback>(wp_presentation_feedback( {wl::Object<struct wp_presentation_feedback>(wp_presentation_feedback(
connection_->presentation(), window_->surface())), connection_->presentation(), wayland_surface_->surface())),
buffer_id, /*feedback=*/base::nullopt, buffer_id, /*feedback=*/base::nullopt,
/*submission_completed=*/false}); /*submission_completed=*/false});
wp_presentation_feedback_add_listener( wp_presentation_feedback_add_listener(
...@@ -438,13 +441,13 @@ class WaylandBufferManagerHost::Surface { ...@@ -438,13 +441,13 @@ class WaylandBufferManagerHost::Surface {
prev_submitted_buffer_ = submitted_buffer_; prev_submitted_buffer_ = submitted_buffer_;
submitted_buffer_ = nullptr; submitted_buffer_ = nullptr;
if (!window_) if (!wayland_surface_)
return; return;
// We can now complete the latest submission. We had to wait for this // We can now complete the latest submission. We had to wait for this
// release because SwapCompletionCallback indicates to the client that the // release because SwapCompletionCallback indicates to the client that the
// previous buffer is available for reuse. // previous buffer is available for reuse.
buffer_manager_->OnSubmission(window_->GetWidget(), id, buffer_manager_->OnSubmission(wayland_surface_->GetRootWidget(), id,
gfx::SwapResult::SWAP_ACK); gfx::SwapResult::SWAP_ACK);
// If presentation feedback is not supported, use a fake feedback. This // If presentation feedback is not supported, use a fake feedback. This
...@@ -452,7 +455,7 @@ class WaylandBufferManagerHost::Surface { ...@@ -452,7 +455,7 @@ class WaylandBufferManagerHost::Surface {
if (!connection_->presentation()) { if (!connection_->presentation()) {
DCHECK(feedback_queue_.empty()); DCHECK(feedback_queue_.empty());
buffer_manager_->OnPresentation( buffer_manager_->OnPresentation(
window_->GetWidget(), id, wayland_surface_->GetWidget(), id,
gfx::PresentationFeedback(base::TimeTicks::Now(), base::TimeDelta(), gfx::PresentationFeedback(base::TimeTicks::Now(), base::TimeDelta(),
GetPresentationKindFlags(0))); GetPresentationKindFlags(0)));
} else { } else {
...@@ -506,15 +509,15 @@ class WaylandBufferManagerHost::Surface { ...@@ -506,15 +509,15 @@ class WaylandBufferManagerHost::Surface {
// This function ensures that we send OnPresentation for each buffer that // This function ensures that we send OnPresentation for each buffer that
// already has had OnSubmission called for it (condition #2). // already has had OnSubmission called for it (condition #2).
void ProcessPresentationFeedbacks() { void ProcessPresentationFeedbacks() {
if (!window_) if (!wayland_surface_)
return; return;
while (!feedback_queue_.empty()) { while (!feedback_queue_.empty()) {
const auto& info = feedback_queue_.front(); const auto& info = feedback_queue_.front();
if (!info.submission_completed || !info.feedback.has_value()) if (!info.submission_completed || !info.feedback.has_value())
break; break;
buffer_manager_->OnPresentation(window_->GetWidget(), info.buffer_id, buffer_manager_->OnPresentation(wayland_surface_->GetWidget(),
*info.feedback); info.buffer_id, *info.feedback);
feedback_queue_.erase(feedback_queue_.begin()); feedback_queue_.erase(feedback_queue_.begin());
} }
// This queue should be small - if not it's likely a bug. // This queue should be small - if not it's likely a bug.
...@@ -560,7 +563,7 @@ class WaylandBufferManagerHost::Surface { ...@@ -560,7 +563,7 @@ class WaylandBufferManagerHost::Surface {
void MaybeProcessPendingBuffer() { void MaybeProcessPendingBuffer() {
// There is nothing to process if there is no pending buffer or the window // There is nothing to process if there is no pending buffer or the window
// has been destroyed. // has been destroyed.
if (!pending_buffer_ || !window_) if (!pending_buffer_ || !wayland_surface_)
return; return;
// This request may come earlier than the Wayland compositor has imported a // This request may come earlier than the Wayland compositor has imported a
...@@ -589,7 +592,7 @@ class WaylandBufferManagerHost::Surface { ...@@ -589,7 +592,7 @@ class WaylandBufferManagerHost::Surface {
// WaylandWindow. // WaylandWindow.
// Non-owned. The window this helper surface stores and submits buffers for. // Non-owned. The window this helper surface stores and submits buffers for.
const WaylandWindow* window_; const WaylandSurface* wayland_surface_;
// Non-owned pointer to the connection. // Non-owned pointer to the connection.
WaylandConnection* const connection_; WaylandConnection* const connection_;
...@@ -651,7 +654,7 @@ WaylandBufferManagerHost::~WaylandBufferManagerHost() { ...@@ -651,7 +654,7 @@ WaylandBufferManagerHost::~WaylandBufferManagerHost() {
void WaylandBufferManagerHost::OnWindowAdded(WaylandWindow* window) { void WaylandBufferManagerHost::OnWindowAdded(WaylandWindow* window) {
DCHECK(window); DCHECK(window);
surfaces_[window->GetWidget()] = surfaces_[window->GetWidget()] =
std::make_unique<Surface>(window, connection_, this); std::make_unique<Surface>(window->wayland_surface(), connection_, this);
} }
void WaylandBufferManagerHost::OnWindowRemoved(WaylandWindow* window) { void WaylandBufferManagerHost::OnWindowRemoved(WaylandWindow* window) {
......
...@@ -5,119 +5,38 @@ ...@@ -5,119 +5,38 @@
#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 "ui/ozone/platform/wayland/host/wayland_window.h" #include "ui/gfx/native_widget_types.h"
#include "ui/ozone/platform/wayland/common/wayland_object.h"
#include "ui/platform_window/platform_window_handler/wm_drag_handler.h"
#include "ui/platform_window/platform_window_handler/wm_move_resize_handler.h"
namespace ui { namespace ui {
class ShellSurfaceWrapper; class WaylandWindow;
class WaylandSurface : public WaylandWindow, // Wrapper of a wl_surface, owned by a WaylandWindow or a WlSubsurface.
public WmMoveResizeHandler, class WaylandSurface {
public WmDragHandler {
public: public:
WaylandSurface(PlatformWindowDelegate* delegate, WaylandSurface();
WaylandConnection* connection); WaylandSurface(const WaylandSurface&) = delete;
~WaylandSurface() override; WaylandSurface& operator=(const WaylandSurface&) = delete;
~WaylandSurface();
ShellSurfaceWrapper* shell_surface() const { return shell_surface_.get(); }
// Apply the bounds specified in the most recent configure event. This should
// be called after processing all pending events in the wayland connection.
void ApplyPendingBounds();
// WmMoveResizeHandler WaylandWindow* root_window() const { return root_window_; }
void DispatchHostWindowDragMovement( wl_surface* surface() const { return surface_.get(); }
int hittest, int32_t buffer_scale() const { return buffer_scale_; }
const gfx::Point& pointer_location_in_px) override;
// WmDragHandler // gfx::AcceleratedWidget identifies a wl_surface or a ui::WaylandWindow. Note
void StartDrag(const ui::OSExchangeData& data, // that GetWidget() and GetRootWidget() do not necessarily return the same
int operation, // result.
gfx::NativeCursor cursor, gfx::AcceleratedWidget GetWidget() const;
WmDragHandler::Delegate* delegate) override; gfx::AcceleratedWidget GetRootWidget() const;
// PlatformWindow
void Show(bool inactive) override;
void Hide() override;
bool IsVisible() const override;
void SetTitle(const base::string16& title) override;
void ToggleFullscreen() override;
void Maximize() override;
void Minimize() override;
void Restore() override;
PlatformWindowState GetPlatformWindowState() const override;
void SizeConstraintsChanged() override;
private: private:
// WaylandWindow overrides: WaylandWindow* root_window_ = nullptr;
void HandleSurfaceConfigure(int32_t widht, wl::Object<wl_surface> surface_;
int32_t height, // Wayland's scale factor for the output that this window currently belongs
bool is_maximized, // to.
bool is_fullscreen, int32_t buffer_scale_ = 1;
bool is_activated) override; friend class WaylandWindow;
void OnDragEnter(const gfx::PointF& point,
std::unique_ptr<OSExchangeData> data,
int operation) override;
int OnDragMotion(const gfx::PointF& point, int operation) override;
void OnDragDrop(std::unique_ptr<OSExchangeData> data) override;
void OnDragLeave() override;
void OnDragSessionClose(uint32_t dnd_action) override;
bool OnInitialize(PlatformWindowInitProperties properties) override;
void TriggerStateChanges();
void SetWindowState(PlatformWindowState state);
// Creates a surface window, which is visible as a main window.
bool CreateShellSurface();
WmMoveResizeHandler* AsWmMoveResizeHandler();
// Propagates the |min_size_| and |max_size_| to the ShellSurface.
void SetSizeConstraints();
void SetOrResetRestoredBounds();
// Wrappers around shell surface.
std::unique_ptr<ShellSurfaceWrapper> shell_surface_;
WmDragHandler::Delegate* drag_handler_delegate_ = nullptr;
// These bounds attributes below have suffices that indicate units used.
// Wayland operates in DIP but the platform operates in physical pixels so
// our WaylandSurface is the link that has to translate the units. See also
// comments in the implementation.
//
// Bounds that will be applied when the window state is finalized. The window
// may get several configuration events that update the pending bounds, and
// only upon finalizing the state is the latest value stored as the current
// bounds via |ApplyPendingBounds|. Measured in DIP because updated in the
// handler that receives DIP from Wayland.
gfx::Rect pending_bounds_dip_;
// Contains the current state of the window.
PlatformWindowState state_;
// Contains the previous state of the window.
PlatformWindowState previous_state_;
bool is_active_ = false;
// Id of the chromium app passed through
// PlatformWindowInitProperties::wm_class_class. This is used by Wayland
// compositor to identify the app, unite it's windows into the same stack of
// windows and find *.desktop file to set various preferences including icons.
std::string app_id_;
// Title of the ShellSurface.
base::string16 window_title_;
// Max and min sizes of the WaylandSurface window.
base::Optional<gfx::Size> min_size_;
base::Optional<gfx::Size> max_size_;
DISALLOW_COPY_AND_ASSIGN(WaylandSurface);
}; };
} // namespace ui } // namespace ui
......
This diff is collapsed.
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_TOPLEVEL_WINDOW_H_
#define UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_TOPLEVEL_WINDOW_H_
#include "ui/ozone/platform/wayland/host/wayland_window.h"
#include "ui/platform_window/platform_window_handler/wm_drag_handler.h"
#include "ui/platform_window/platform_window_handler/wm_move_resize_handler.h"
namespace ui {
class ShellSurfaceWrapper;
class WaylandToplevelWindow : public WaylandWindow,
public WmMoveResizeHandler,
public WmDragHandler {
public:
WaylandToplevelWindow(PlatformWindowDelegate* delegate,
WaylandConnection* connection);
WaylandToplevelWindow(const WaylandToplevelWindow&) = delete;
WaylandToplevelWindow& operator=(const WaylandToplevelWindow&) = delete;
~WaylandToplevelWindow() override;
ShellSurfaceWrapper* shell_surface() const { return shell_surface_.get(); }
// Apply the bounds specified in the most recent configure event. This should
// be called after processing all pending events in the wayland connection.
void ApplyPendingBounds();
// WmMoveResizeHandler
void DispatchHostWindowDragMovement(
int hittest,
const gfx::Point& pointer_location_in_px) override;
// WmDragHandler
void StartDrag(const ui::OSExchangeData& data,
int operation,
gfx::NativeCursor cursor,
WmDragHandler::Delegate* delegate) override;
// PlatformWindow
void Show(bool inactive) override;
void Hide() override;
bool IsVisible() const override;
void SetTitle(const base::string16& title) override;
void ToggleFullscreen() override;
void Maximize() override;
void Minimize() override;
void Restore() override;
PlatformWindowState GetPlatformWindowState() const override;
void SizeConstraintsChanged() override;
private:
// WaylandWindow overrides:
void HandleSurfaceConfigure(int32_t widht,
int32_t height,
bool is_maximized,
bool is_fullscreen,
bool is_activated) override;
void OnDragEnter(const gfx::PointF& point,
std::unique_ptr<OSExchangeData> data,
int operation) override;
int OnDragMotion(const gfx::PointF& point, int operation) override;
void OnDragDrop(std::unique_ptr<OSExchangeData> data) override;
void OnDragLeave() override;
void OnDragSessionClose(uint32_t dnd_action) override;
bool OnInitialize(PlatformWindowInitProperties properties) override;
void TriggerStateChanges();
void SetWindowState(PlatformWindowState state);
// Creates a surface window, which is visible as a main window.
bool CreateShellSurface();
WmMoveResizeHandler* AsWmMoveResizeHandler();
// Propagates the |min_size_| and |max_size_| to the ShellSurface.
void SetSizeConstraints();
void SetOrResetRestoredBounds();
// Wrappers around shell surface.
std::unique_ptr<ShellSurfaceWrapper> shell_surface_;
WmDragHandler::Delegate* drag_handler_delegate_ = nullptr;
// These bounds attributes below have suffices that indicate units used.
// Wayland operates in DIP but the platform operates in physical pixels so
// our WaylandToplevelWindow is the link that has to translate the units. See
// also comments in the implementation.
//
// Bounds that will be applied when the window state is finalized. The window
// may get several configuration events that update the pending bounds, and
// only upon finalizing the state is the latest value stored as the current
// bounds via |ApplyPendingBounds|. Measured in DIP because updated in the
// handler that receives DIP from Wayland.
gfx::Rect pending_bounds_dip_;
// Contains the current state of the window.
PlatformWindowState state_;
// Contains the previous state of the window.
PlatformWindowState previous_state_;
bool is_active_ = false;
// Id of the chromium app passed through
// PlatformWindowInitProperties::wm_class_class. This is used by Wayland
// compositor to identify the app, unite it's windows into the same stack of
// windows and find *.desktop file to set various preferences including icons.
std::string app_id_;
// Title of the ShellSurface.
base::string16 window_title_;
// Max and min sizes of the WaylandToplevelWindow window.
base::Optional<gfx::Size> min_size_;
base::Optional<gfx::Size> max_size_;
};
} // namespace ui
#endif // UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_TOPLEVEL_WINDOW_H_
...@@ -30,7 +30,7 @@ WaylandWindow::WaylandWindow(PlatformWindowDelegate* delegate, ...@@ -30,7 +30,7 @@ WaylandWindow::WaylandWindow(PlatformWindowDelegate* delegate,
WaylandWindow::~WaylandWindow() { WaylandWindow::~WaylandWindow() {
PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this); PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this);
if (surface_) if (surface())
connection_->wayland_window_manager()->RemoveWindow(GetWidget()); connection_->wayland_window_manager()->RemoveWindow(GetWidget());
if (parent_window_) if (parent_window_)
...@@ -61,7 +61,7 @@ void WaylandWindow::UpdateBufferScale(bool update_bounds) { ...@@ -61,7 +61,7 @@ void WaylandWindow::UpdateBufferScale(bool update_bounds) {
int32_t new_scale = 0; int32_t new_scale = 0;
if (parent_window_) { if (parent_window_) {
new_scale = parent_window_->buffer_scale_; new_scale = parent_window_->buffer_scale();
ui_scale_ = parent_window_->ui_scale_; ui_scale_ = parent_window_->ui_scale_;
} else { } else {
const auto display = (widget == gfx::kNullAcceleratedWidget) const auto display = (widget == gfx::kNullAcceleratedWidget)
...@@ -80,9 +80,7 @@ void WaylandWindow::UpdateBufferScale(bool update_bounds) { ...@@ -80,9 +80,7 @@ void WaylandWindow::UpdateBufferScale(bool update_bounds) {
} }
gfx::AcceleratedWidget WaylandWindow::GetWidget() const { gfx::AcceleratedWidget WaylandWindow::GetWidget() const {
if (!surface_) return wayland_surface_.GetWidget();
return gfx::kNullAcceleratedWidget;
return surface_.id();
} }
void WaylandWindow::SetPointerFocus(bool focus) { void WaylandWindow::SetPointerFocus(bool focus) {
has_pointer_focus_ = focus; has_pointer_focus_ = focus;
...@@ -163,7 +161,7 @@ void WaylandWindow::Restore() {} ...@@ -163,7 +161,7 @@ void WaylandWindow::Restore() {}
PlatformWindowState WaylandWindow::GetPlatformWindowState() const { PlatformWindowState WaylandWindow::GetPlatformWindowState() const {
// Remove normal state for all the other types of windows as it's only the // Remove normal state for all the other types of windows as it's only the
// WaylandSurface that supports state changes. // WaylandToplevelWindow that supports state changes.
return PlatformWindowState::kNormal; return PlatformWindowState::kNormal;
} }
...@@ -254,7 +252,7 @@ uint32_t WaylandWindow::DispatchEvent(const PlatformEvent& native_event) { ...@@ -254,7 +252,7 @@ uint32_t WaylandWindow::DispatchEvent(const PlatformEvent& native_event) {
// Wayland sends locations in DIP so they need to be translated to // Wayland sends locations in DIP so they need to be translated to
// physical pixels. // physical pixels.
event->AsLocatedEvent()->set_location_f(gfx::ScalePoint( event->AsLocatedEvent()->set_location_f(gfx::ScalePoint(
event->AsLocatedEvent()->location_f(), buffer_scale_, buffer_scale_)); event->AsLocatedEvent()->location_f(), buffer_scale(), buffer_scale()));
// We must reroute the events to the event grabber iff these windows belong // We must reroute the events to the event grabber iff these windows belong
// to the same root parent window. For example, there are 2 top level // to the same root parent window. For example, there are 2 top level
...@@ -314,24 +312,26 @@ void WaylandWindow::OnDragLeave() {} ...@@ -314,24 +312,26 @@ void WaylandWindow::OnDragLeave() {}
void WaylandWindow::OnDragSessionClose(uint32_t dnd_action) {} void WaylandWindow::OnDragSessionClose(uint32_t dnd_action) {}
void WaylandWindow::SetBoundsDip(const gfx::Rect& bounds_dip) { void WaylandWindow::SetBoundsDip(const gfx::Rect& bounds_dip) {
SetBounds(gfx::ScaleToRoundedRect(bounds_dip, buffer_scale_)); SetBounds(gfx::ScaleToRoundedRect(bounds_dip, buffer_scale()));
} }
bool WaylandWindow::Initialize(PlatformWindowInitProperties properties) { bool WaylandWindow::Initialize(PlatformWindowInitProperties properties) {
// 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.
DCHECK_EQ(buffer_scale_, 1); DCHECK_EQ(buffer_scale(), 1);
bounds_px_ = properties.bounds; bounds_px_ = properties.bounds;
opacity_ = properties.opacity; opacity_ = properties.opacity;
type_ = properties.type; type_ = properties.type;
surface_.reset(wl_compositor_create_surface(connection_->compositor())); wayland_surface_.surface_.reset(
if (!surface_) { wl_compositor_create_surface(connection_->compositor()));
wayland_surface_.root_window_ = this;
if (!surface()) {
LOG(ERROR) << "Failed to create wl_surface"; LOG(ERROR) << "Failed to create wl_surface";
return false; return false;
} }
wl_surface_set_user_data(surface_.get(), this); wl_surface_set_user_data(surface(), this);
AddSurfaceListener(); AddSurfaceListener();
connection_->wayland_window_manager()->AddWindow(GetWidget(), this); connection_->wayland_window_manager()->AddWindow(GetWidget(), this);
...@@ -354,16 +354,16 @@ bool WaylandWindow::Initialize(PlatformWindowInitProperties properties) { ...@@ -354,16 +354,16 @@ 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);
if (new_scale == buffer_scale_) if (new_scale == buffer_scale())
return; return;
auto old_scale = buffer_scale_; auto old_scale = buffer_scale();
buffer_scale_ = new_scale; wayland_surface_.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));
DCHECK(surface()); DCHECK(surface());
wl_surface_set_buffer_scale(surface(), buffer_scale_); wl_surface_set_buffer_scale(surface(), buffer_scale());
connection_->ScheduleFlush(); connection_->ScheduleFlush();
} }
...@@ -398,7 +398,7 @@ void WaylandWindow::AddSurfaceListener() { ...@@ -398,7 +398,7 @@ void WaylandWindow::AddSurfaceListener() {
&WaylandWindow::Enter, &WaylandWindow::Enter,
&WaylandWindow::Leave, &WaylandWindow::Leave,
}; };
wl_surface_add_listener(surface_.get(), &surface_listener, this); wl_surface_add_listener(surface(), &surface_listener, this);
} }
void WaylandWindow::AddEnteredOutputId(struct wl_output* output) { void WaylandWindow::AddEnteredOutputId(struct wl_output* output) {
...@@ -511,7 +511,7 @@ void WaylandWindow::Enter(void* data, ...@@ -511,7 +511,7 @@ void WaylandWindow::Enter(void* data,
struct wl_output* output) { struct wl_output* output) {
auto* window = static_cast<WaylandWindow*>(data); auto* window = static_cast<WaylandWindow*>(data);
if (window) { if (window) {
DCHECK(window->surface_.get() == wl_surface); DCHECK(window->surface() == wl_surface);
window->AddEnteredOutputId(output); window->AddEnteredOutputId(output);
} }
} }
...@@ -522,7 +522,7 @@ void WaylandWindow::Leave(void* data, ...@@ -522,7 +522,7 @@ void WaylandWindow::Leave(void* data,
struct wl_output* output) { struct wl_output* output) {
auto* window = static_cast<WaylandWindow*>(data); auto* window = static_cast<WaylandWindow*>(data);
if (window) { if (window) {
DCHECK(window->surface_.get() == wl_surface); DCHECK(window->surface() == wl_surface);
window->RemoveEnteredOutputId(output); window->RemoveEnteredOutputId(output);
} }
} }
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#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"
#include "ui/ozone/platform/wayland/host/wayland_surface.h"
#include "ui/platform_window/platform_window.h" #include "ui/platform_window/platform_window.h"
#include "ui/platform_window/platform_window_delegate.h" #include "ui/platform_window/platform_window_delegate.h"
#include "ui/platform_window/platform_window_init_properties.h" #include "ui/platform_window/platform_window_init_properties.h"
...@@ -36,7 +37,7 @@ class WaylandWindow : public PlatformWindow, public PlatformEventDispatcher { ...@@ -36,7 +37,7 @@ class WaylandWindow : public PlatformWindow, public PlatformEventDispatcher {
~WaylandWindow() override; ~WaylandWindow() override;
// A factory method that can create any of the derived types of WaylandWindow // A factory method that can create any of the derived types of WaylandWindow
// (WaylandSurface, WaylandPopup and WaylandSubsurface). // (WaylandToplevelWindow, WaylandPopup and WaylandSubsurface).
static std::unique_ptr<WaylandWindow> Create( static std::unique_ptr<WaylandWindow> Create(
PlatformWindowDelegate* delegate, PlatformWindowDelegate* delegate,
WaylandConnection* connection, WaylandConnection* connection,
...@@ -53,7 +54,8 @@ class WaylandWindow : public PlatformWindow, public PlatformEventDispatcher { ...@@ -53,7 +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);
wl_surface* surface() const { return surface_.get(); } WaylandSurface* wayland_surface() { return &wayland_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;
...@@ -80,7 +82,7 @@ class WaylandWindow : public PlatformWindow, public PlatformEventDispatcher { ...@@ -80,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 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 {
...@@ -214,7 +216,7 @@ class WaylandWindow : public PlatformWindow, public PlatformEventDispatcher { ...@@ -214,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;
wl::Object<wl_surface> surface_; WaylandSurface wayland_surface_;
// The current cursor bitmap (immutable). // The current cursor bitmap (immutable).
scoped_refptr<BitmapCursorOzone> bitmap_; scoped_refptr<BitmapCursorOzone> bitmap_;
...@@ -227,9 +229,6 @@ class WaylandWindow : public PlatformWindow, public PlatformEventDispatcher { ...@@ -227,9 +229,6 @@ class WaylandWindow : public PlatformWindow, public PlatformEventDispatcher {
bool has_pointer_focus_ = false; bool has_pointer_focus_ = false;
bool has_keyboard_focus_ = false; bool has_keyboard_focus_ = false;
bool has_touch_focus_ = false; bool has_touch_focus_ = false;
// Wayland's scale factor for the output that this window currently belongs
// to.
int32_t buffer_scale_ = 1;
// The UI scale may be forced through the command line, which means that it // The UI scale may be forced through the command line, which means that it
// replaces the default value that is equal to the natural device scale. // replaces the default value that is equal to the natural device scale.
// We need it to place and size the menus properly. // We need it to place and size the menus properly.
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "ui/ozone/platform/wayland/host/wayland_connection.h" #include "ui/ozone/platform/wayland/host/wayland_connection.h"
#include "ui/ozone/platform/wayland/host/wayland_popup.h" #include "ui/ozone/platform/wayland/host/wayland_popup.h"
#include "ui/ozone/platform/wayland/host/wayland_subsurface.h" #include "ui/ozone/platform/wayland/host/wayland_subsurface.h"
#include "ui/ozone/platform/wayland/host/wayland_surface.h" #include "ui/ozone/platform/wayland/host/wayland_toplevel_window.h"
#include "ui/ozone/platform/wayland/host/wayland_window.h" #include "ui/ozone/platform/wayland/host/wayland_window.h"
namespace ui { namespace ui {
...@@ -26,7 +26,7 @@ std::unique_ptr<WaylandWindow> WaylandWindow::Create( ...@@ -26,7 +26,7 @@ std::unique_ptr<WaylandWindow> WaylandWindow::Create(
// parent window to be set. Thus, create a normal window instead then. // parent window to be set. Thus, create a normal window instead then.
if (properties.parent_widget == gfx::kNullAcceleratedWidget && if (properties.parent_widget == gfx::kNullAcceleratedWidget &&
!connection->wayland_window_manager()->GetCurrentFocusedWindow()) { !connection->wayland_window_manager()->GetCurrentFocusedWindow()) {
window.reset(new WaylandSurface(delegate, connection)); window.reset(new WaylandToplevelWindow(delegate, connection));
} else if (connection->IsDragInProgress()) { } else if (connection->IsDragInProgress()) {
// We are in the process of drag and requested a popup. Most probably, // We are in the process of drag and requested a popup. Most probably,
// it is an arrow window. // it is an arrow window.
...@@ -43,7 +43,7 @@ std::unique_ptr<WaylandWindow> WaylandWindow::Create( ...@@ -43,7 +43,7 @@ std::unique_ptr<WaylandWindow> WaylandWindow::Create(
case PlatformWindowType::kDrag: case PlatformWindowType::kDrag:
// TODO(msisov): Figure out what kind of surface we need to create for // TODO(msisov): Figure out what kind of surface we need to create for
// bubble and drag windows. // bubble and drag windows.
window.reset(new WaylandSurface(delegate, connection)); window.reset(new WaylandToplevelWindow(delegate, connection));
break; break;
default: default:
NOTREACHED(); NOTREACHED();
......
...@@ -316,9 +316,9 @@ TEST_P(WaylandWindowTest, Minimize) { ...@@ -316,9 +316,9 @@ TEST_P(WaylandWindowTest, Minimize) {
Sync(); Sync();
// Wayland compositor doesn't notify clients about minimized state, but rather // Wayland compositor doesn't notify clients about minimized state, but rather
// if a window is not activated. Thus, a WaylandSurface marks itself as being // if a window is not activated. Thus, a WaylandToplevelWindow marks itself as
// minimized and and sets state to minimized. Thus, the state mustn't change // being minimized and and sets state to minimized. Thus, the state mustn't
// after the configuration event is sent. // change after the configuration event is sent.
EXPECT_EQ(window_->GetPlatformWindowState(), PlatformWindowState::kMinimized); EXPECT_EQ(window_->GetPlatformWindowState(), PlatformWindowState::kMinimized);
// Send one additional empty configuration event (which means the surface is // Send one additional empty configuration event (which means the surface is
...@@ -1931,8 +1931,8 @@ TEST_P(WaylandWindowTest, SetsPropertiesOnShow) { ...@@ -1931,8 +1931,8 @@ TEST_P(WaylandWindowTest, SetsPropertiesOnShow) {
// We can't mock all those methods above as long as the xdg_toplevel is // We can't mock all those methods above as long as the xdg_toplevel is
// created and destroyed on each show and hide call. However, it is the same // created and destroyed on each show and hide call. However, it is the same
// WaylandSurface object that cached the values we set and must restore them // WaylandToplevelWindow object that cached the values we set and must restore
// on Show(). // them on Show().
EXPECT_EQ(mock_xdg_toplevel->min_size(), min_size.value()); EXPECT_EQ(mock_xdg_toplevel->min_size(), min_size.value());
EXPECT_EQ(mock_xdg_toplevel->max_size(), max_size.value()); EXPECT_EQ(mock_xdg_toplevel->max_size(), max_size.value());
EXPECT_EQ(std::string(kAppId), mock_xdg_toplevel->app_id()); EXPECT_EQ(std::string(kAppId), mock_xdg_toplevel->app_id());
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include "ui/ozone/platform/wayland/host/wayland_event_source.h" #include "ui/ozone/platform/wayland/host/wayland_event_source.h"
#include "ui/ozone/platform/wayland/host/wayland_pointer.h" #include "ui/ozone/platform/wayland/host/wayland_pointer.h"
#include "ui/ozone/platform/wayland/host/wayland_popup.h" #include "ui/ozone/platform/wayland/host/wayland_popup.h"
#include "ui/ozone/platform/wayland/host/wayland_surface.h" #include "ui/ozone/platform/wayland/host/wayland_toplevel_window.h"
#include "ui/ozone/platform/wayland/host/xdg_surface_wrapper_impl.h" #include "ui/ozone/platform/wayland/host/xdg_surface_wrapper_impl.h"
namespace ui { namespace ui {
...@@ -286,8 +286,8 @@ bool XDGPopupWrapperImpl::Initialize(WaylandConnection* connection, ...@@ -286,8 +286,8 @@ bool XDGPopupWrapperImpl::Initialize(WaylandConnection* connection,
static_cast<XDGPopupWrapperImpl*>(wayland_popup->shell_popup()); static_cast<XDGPopupWrapperImpl*>(wayland_popup->shell_popup());
parent_xdg_surface = popup->xdg_surface(); parent_xdg_surface = popup->xdg_surface();
} else { } else {
WaylandSurface* wayland_surface = WaylandToplevelWindow* wayland_surface =
static_cast<WaylandSurface*>(wayland_window_->parent_window()); static_cast<WaylandToplevelWindow*>(wayland_window_->parent_window());
parent_xdg_surface = parent_xdg_surface =
static_cast<XDGSurfaceWrapperImpl*>(wayland_surface->shell_surface()); static_cast<XDGSurfaceWrapperImpl*>(wayland_surface->shell_surface());
} }
......
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