Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: components/exo/wayland/server.cc

Issue 2688483003: exo: Refactor ShellSurface and WaylandRemoteShell (Closed)
Patch Set: Revert unnecessary changes Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/exo/test/exo_test_helper.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/exo/wayland/server.h" 5 #include "components/exo/wayland/server.h"
6 6
7 #include <alpha-compositing-unstable-v1-server-protocol.h> 7 #include <alpha-compositing-unstable-v1-server-protocol.h>
8 #include <gaming-input-unstable-v1-server-protocol.h> 8 #include <gaming-input-unstable-v1-server-protocol.h>
9 #include <grp.h> 9 #include <grp.h>
10 #include <keyboard-configuration-unstable-v1-server-protocol.h> 10 #include <keyboard-configuration-unstable-v1-server-protocol.h>
(...skipping 11 matching lines...) Expand all
22 #include <wayland-server-protocol-core.h> 22 #include <wayland-server-protocol-core.h>
23 #include <xdg-shell-unstable-v5-server-protocol.h> 23 #include <xdg-shell-unstable-v5-server-protocol.h>
24 #include <xdg-shell-unstable-v6-server-protocol.h> 24 #include <xdg-shell-unstable-v6-server-protocol.h>
25 25
26 #include <algorithm> 26 #include <algorithm>
27 #include <cstdlib> 27 #include <cstdlib>
28 #include <iterator> 28 #include <iterator>
29 #include <string> 29 #include <string>
30 #include <utility> 30 #include <utility>
31 31
32 #include "ash/common/shell_observer.h"
33 #include "ash/public/cpp/shell_window_ids.h" 32 #include "ash/public/cpp/shell_window_ids.h"
34 #include "ash/shell.h" 33 #include "ash/shell.h"
35 #include "base/bind.h" 34 #include "base/bind.h"
36 #include "base/cancelable_callback.h" 35 #include "base/cancelable_callback.h"
37 #include "base/files/file_path.h" 36 #include "base/files/file_path.h"
38 #include "base/macros.h" 37 #include "base/macros.h"
39 #include "base/memory/free_deleter.h" 38 #include "base/memory/free_deleter.h"
40 #include "base/memory/ptr_util.h" 39 #include "base/memory/ptr_util.h"
41 #include "base/memory/weak_ptr.h" 40 #include "base/memory/weak_ptr.h"
42 #include "base/strings/stringprintf.h" 41 #include "base/strings/stringprintf.h"
(...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 WaylandPrimaryDisplayObserver(wl_resource* output_resource) 1081 WaylandPrimaryDisplayObserver(wl_resource* output_resource)
1083 : output_resource_(output_resource) { 1082 : output_resource_(output_resource) {
1084 display::Screen::GetScreen()->AddObserver(this); 1083 display::Screen::GetScreen()->AddObserver(this);
1085 SendDisplayMetrics(); 1084 SendDisplayMetrics();
1086 } 1085 }
1087 ~WaylandPrimaryDisplayObserver() override { 1086 ~WaylandPrimaryDisplayObserver() override {
1088 display::Screen::GetScreen()->RemoveObserver(this); 1087 display::Screen::GetScreen()->RemoveObserver(this);
1089 } 1088 }
1090 1089
1091 // Overridden from display::DisplayObserver: 1090 // Overridden from display::DisplayObserver:
1092 void OnDisplayAdded(const display::Display& new_display) override {}
1093 void OnDisplayRemoved(const display::Display& new_display) override {}
1094 void OnDisplayMetricsChanged(const display::Display& display, 1091 void OnDisplayMetricsChanged(const display::Display& display,
1095 uint32_t changed_metrics) override { 1092 uint32_t changed_metrics) override {
1096 if (display::Screen::GetScreen()->GetPrimaryDisplay().id() != display.id()) 1093 if (display::Screen::GetScreen()->GetPrimaryDisplay().id() != display.id())
1097 return; 1094 return;
1098 1095
1099 // There is no need to check DISPLAY_METRIC_PRIMARY because when primary 1096 // There is no need to check DISPLAY_METRIC_PRIMARY because when primary
1100 // changes, bounds always changes. (new primary should have had non 1097 // changes, bounds always changes. (new primary should have had non
1101 // 0,0 origin). 1098 // 0,0 origin).
1102 // Only exception is when switching to newly connected primary with 1099 // Only exception is when switching to newly connected primary with
1103 // the same bounds. This happens whenyou're in docked mode, suspend, 1100 // the same bounds. This happens whenyou're in docked mode, suspend,
(...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after
2039 weak_ptr_factory_(this) { 2036 weak_ptr_factory_(this) {
2040 auto* helper = WMHelper::GetInstance(); 2037 auto* helper = WMHelper::GetInstance();
2041 helper->AddMaximizeModeObserver(this); 2038 helper->AddMaximizeModeObserver(this);
2042 helper->AddActivationObserver(this); 2039 helper->AddActivationObserver(this);
2043 display::Screen::GetScreen()->AddObserver(this); 2040 display::Screen::GetScreen()->AddObserver(this);
2044 2041
2045 layout_mode_ = helper->IsMaximizeModeWindowManagerEnabled() 2042 layout_mode_ = helper->IsMaximizeModeWindowManagerEnabled()
2046 ? ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_TABLET 2043 ? ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_TABLET
2047 : ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; 2044 : ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED;
2048 2045
2049 SendPrimaryDisplayMetrics(); 2046 SendDisplayMetrics();
2050 SendActivated(helper->GetActiveWindow(), nullptr); 2047 SendActivated(helper->GetActiveWindow(), nullptr);
2051 } 2048 }
2052 ~WaylandRemoteShell() override { 2049 ~WaylandRemoteShell() override {
2053 auto* helper = WMHelper::GetInstance(); 2050 auto* helper = WMHelper::GetInstance();
2054 helper->RemoveMaximizeModeObserver(this); 2051 helper->RemoveMaximizeModeObserver(this);
2055 helper->RemoveActivationObserver(this); 2052 helper->RemoveActivationObserver(this);
2056 display::Screen::GetScreen()->RemoveObserver(this); 2053 display::Screen::GetScreen()->RemoveObserver(this);
2057 } 2054 }
2058 2055
2059 std::unique_ptr<ShellSurface> CreateShellSurface(Surface* surface, 2056 std::unique_ptr<ShellSurface> CreateShellSurface(Surface* surface,
2060 int container) { 2057 int container) {
2061 return display_->CreateRemoteShellSurface(surface, container); 2058 return display_->CreateRemoteShellSurface(surface, container);
2062 } 2059 }
2063 2060
2064 std::unique_ptr<NotificationSurface> CreateNotificationSurface( 2061 std::unique_ptr<NotificationSurface> CreateNotificationSurface(
2065 Surface* surface, 2062 Surface* surface,
2066 const std::string& notification_id) { 2063 const std::string& notification_id) {
2067 return display_->CreateNotificationSurface(surface, notification_id); 2064 return display_->CreateNotificationSurface(surface, notification_id);
2068 } 2065 }
2069 2066
2070 // Overridden from display::DisplayObserver: 2067 // Overridden from display::DisplayObserver:
2071 void OnDisplayAdded(const display::Display& new_display) override {}
2072 void OnDisplayRemoved(const display::Display& new_display) override {}
2073 void OnDisplayMetricsChanged(const display::Display& display, 2068 void OnDisplayMetricsChanged(const display::Display& display,
2074 uint32_t changed_metrics) override { 2069 uint32_t changed_metrics) override {
2075 if (display::Screen::GetScreen()->GetPrimaryDisplay().id() != display.id()) 2070 if (display::Screen::GetScreen()->GetPrimaryDisplay().id() != display.id())
2076 return; 2071 return;
2077 2072
2078 // No need to update when a primary dislpay has changed without bounds 2073 // No need to update when a primary display has changed without bounds
2079 // change. See WaylandPrimaryDisplayObserver::OnDisplayMetricsChanged 2074 // change. See WaylandPrimaryDisplayObserver::OnDisplayMetricsChanged
2080 // for more details. 2075 // for more details.
2081 if (changed_metrics & 2076 if (changed_metrics &
2082 (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_DEVICE_SCALE_FACTOR | 2077 (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_DEVICE_SCALE_FACTOR |
2083 DISPLAY_METRIC_ROTATION | DISPLAY_METRIC_WORK_AREA)) { 2078 DISPLAY_METRIC_ROTATION | DISPLAY_METRIC_WORK_AREA)) {
2084 SendDisplayMetrics(display); 2079 ScheduleSendDisplayMetrics(0);
2085 } 2080 }
2086 } 2081 }
2087 2082
2088 // Overridden from WMHelper::MaximizeModeObserver: 2083 // Overridden from WMHelper::MaximizeModeObserver:
2089 void OnMaximizeModeStarted() override { 2084 void OnMaximizeModeStarted() override {
2090 layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_TABLET; 2085 layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_TABLET;
2091 2086 ScheduleSendDisplayMetrics(kConfigureDelayAfterLayoutSwitchMs);
2092 send_configure_after_layout_change_ = true;
2093 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
2094 FROM_HERE, base::Bind(&WaylandRemoteShell::MaybeSendConfigure,
2095 weak_ptr_factory_.GetWeakPtr()),
2096 base::TimeDelta::FromMilliseconds(kConfigureDelayAfterLayoutSwitchMs));
2097 } 2087 }
2098 void OnMaximizeModeEnded() override { 2088 void OnMaximizeModeEnded() override {
2099 layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; 2089 layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED;
2100 send_configure_after_layout_change_ = true; 2090 ScheduleSendDisplayMetrics(kConfigureDelayAfterLayoutSwitchMs);
2101 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
2102 FROM_HERE, base::Bind(&WaylandRemoteShell::MaybeSendConfigure,
2103 weak_ptr_factory_.GetWeakPtr()),
2104 base::TimeDelta::FromMilliseconds(kConfigureDelayAfterLayoutSwitchMs));
2105 } 2091 }
2106 2092
2107 // Overridden from WMHelper::ActivationObserver: 2093 // Overridden from WMHelper::ActivationObserver:
2108 void OnWindowActivated(aura::Window* gained_active, 2094 void OnWindowActivated(aura::Window* gained_active,
2109 aura::Window* lost_active) override { 2095 aura::Window* lost_active) override {
2110 SendActivated(gained_active, lost_active); 2096 SendActivated(gained_active, lost_active);
2111 } 2097 }
2112 2098
2113 private: 2099 private:
2114 void SendPrimaryDisplayMetrics() { 2100 void ScheduleSendDisplayMetrics(int delay_ms) {
2115 const display::Display primary = 2101 needs_send_display_metrics_ = true;
2116 display::Screen::GetScreen()->GetPrimaryDisplay(); 2102 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
2117 2103 FROM_HERE, base::Bind(&WaylandRemoteShell::SendDisplayMetrics,
2118 SendDisplayMetrics(primary); 2104 weak_ptr_factory_.GetWeakPtr()),
2105 base::TimeDelta::FromMilliseconds(delay_ms));
2119 } 2106 }
2120 2107
2121 void MaybeSendConfigure() { 2108 void SendDisplayMetrics() {
2122 if (send_configure_after_layout_change_) 2109 if (!needs_send_display_metrics_)
2123 SendPrimaryDisplayMetrics(); 2110 return;
2124 } 2111 needs_send_display_metrics_ = false;
2125 2112
2126 void SendDisplayMetrics(const display::Display& display) { 2113 const display::Screen* screen = display::Screen::GetScreen();
2127 send_configure_after_layout_change_ = false; 2114 const display::Display primary_display = screen->GetPrimaryDisplay();
2128 2115
2129 const gfx::Insets& work_area_insets = display.GetWorkAreaInsets(); 2116 const gfx::Insets& work_area_insets = primary_display.GetWorkAreaInsets();
2130 2117
2131 zcr_remote_shell_v1_send_configuration_changed( 2118 zcr_remote_shell_v1_send_configuration_changed(
2132 remote_shell_resource_, display.size().width(), display.size().height(), 2119 remote_shell_resource_,
2133 OutputTransform(display.rotation()), 2120 primary_display.size().width(),
2134 wl_fixed_from_double(display.device_scale_factor()), 2121 primary_display.size().height(),
2122 OutputTransform(primary_display.rotation()),
2123 wl_fixed_from_double(primary_display.device_scale_factor()),
2135 work_area_insets.left(), work_area_insets.top(), 2124 work_area_insets.left(), work_area_insets.top(),
2136 work_area_insets.right(), work_area_insets.bottom(), layout_mode_); 2125 work_area_insets.right(), work_area_insets.bottom(), layout_mode_);
2137 wl_client_flush(wl_resource_get_client(remote_shell_resource_)); 2126 wl_client_flush(wl_resource_get_client(remote_shell_resource_));
2138 } 2127 }
2139 2128
2140 void SendActivated(aura::Window* gained_active, aura::Window* lost_active) { 2129 void SendActivated(aura::Window* gained_active, aura::Window* lost_active) {
2141 Surface* gained_active_surface = 2130 Surface* gained_active_surface =
2142 gained_active ? ShellSurface::GetMainSurface(gained_active) : nullptr; 2131 gained_active ? ShellSurface::GetMainSurface(gained_active) : nullptr;
2143 Surface* lost_active_surface = 2132 Surface* lost_active_surface =
2144 lost_active ? ShellSurface::GetMainSurface(lost_active) : nullptr; 2133 lost_active ? ShellSurface::GetMainSurface(lost_active) : nullptr;
(...skipping 24 matching lines...) Expand all
2169 lost_active_surface_resource); 2158 lost_active_surface_resource);
2170 wl_client_flush(client); 2159 wl_client_flush(client);
2171 } 2160 }
2172 2161
2173 // The exo display instance. Not owned. 2162 // The exo display instance. Not owned.
2174 Display* const display_; 2163 Display* const display_;
2175 2164
2176 // The remote shell resource associated with observer. 2165 // The remote shell resource associated with observer.
2177 wl_resource* const remote_shell_resource_; 2166 wl_resource* const remote_shell_resource_;
2178 2167
2179 bool send_configure_after_layout_change_ = false; 2168 bool needs_send_display_metrics_ = true;
2180 2169
2181 int layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; 2170 int layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED;
2182 2171
2183 base::WeakPtrFactory<WaylandRemoteShell> weak_ptr_factory_; 2172 base::WeakPtrFactory<WaylandRemoteShell> weak_ptr_factory_;
2184 2173
2185 DISALLOW_COPY_AND_ASSIGN(WaylandRemoteShell); 2174 DISALLOW_COPY_AND_ASSIGN(WaylandRemoteShell);
2186 }; 2175 };
2187 2176
2188 void remote_shell_destroy(wl_client* client, wl_resource* resource) { 2177 void remote_shell_destroy(wl_client* client, wl_resource* resource) {
2189 // Nothing to do here. 2178 // Nothing to do here.
(...skipping 1559 matching lines...) Expand 10 before | Expand all | Expand 10 after
3749 DCHECK(event_loop); 3738 DCHECK(event_loop);
3750 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); 3739 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds());
3751 } 3740 }
3752 3741
3753 void Server::Flush() { 3742 void Server::Flush() {
3754 wl_display_flush_clients(wl_display_.get()); 3743 wl_display_flush_clients(wl_display_.get());
3755 } 3744 }
3756 3745
3757 } // namespace wayland 3746 } // namespace wayland
3758 } // namespace exo 3747 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/test/exo_test_helper.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698