Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 1965 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1976 shell_surface->SetRectangularSurfaceShadow(content_bounds); | 1976 shell_surface->SetRectangularSurfaceShadow(content_bounds); |
| 1977 } | 1977 } |
| 1978 | 1978 |
| 1979 void remote_surface_ack_configure(wl_client* client, | 1979 void remote_surface_ack_configure(wl_client* client, |
| 1980 wl_resource* resource, | 1980 wl_resource* resource, |
| 1981 uint32_t serial) { | 1981 uint32_t serial) { |
| 1982 GetUserDataAs<ShellSurface>(resource)->AcknowledgeConfigure(serial); | 1982 GetUserDataAs<ShellSurface>(resource)->AcknowledgeConfigure(serial); |
| 1983 } | 1983 } |
| 1984 | 1984 |
| 1985 void remote_surface_move(wl_client* client, wl_resource* resource) { | 1985 void remote_surface_move(wl_client* client, wl_resource* resource) { |
| 1986 NOTIMPLEMENTED(); | 1986 GetUserDataAs<ShellSurface>(resource)->Move(); |
| 1987 } | 1987 } |
| 1988 | 1988 |
| 1989 const struct zcr_remote_surface_v1_interface remote_surface_implementation = { | 1989 const struct zcr_remote_surface_v1_interface remote_surface_implementation = { |
| 1990 remote_surface_destroy, | 1990 remote_surface_destroy, |
| 1991 remote_surface_set_app_id, | 1991 remote_surface_set_app_id, |
| 1992 remote_surface_set_window_geometry, | 1992 remote_surface_set_window_geometry, |
| 1993 remote_surface_set_scale, | 1993 remote_surface_set_scale, |
| 1994 remote_surface_set_rectangular_shadow_DEPRECATED, | 1994 remote_surface_set_rectangular_shadow_DEPRECATED, |
| 1995 remote_surface_set_rectangular_shadow_background_opacity, | 1995 remote_surface_set_rectangular_shadow_background_opacity, |
| 1996 remote_surface_set_title, | 1996 remote_surface_set_title, |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 2017 } | 2017 } |
| 2018 | 2018 |
| 2019 const struct zcr_notification_surface_v1_interface | 2019 const struct zcr_notification_surface_v1_interface |
| 2020 notification_surface_implementation = {notification_surface_destroy}; | 2020 notification_surface_implementation = {notification_surface_destroy}; |
| 2021 | 2021 |
| 2022 //////////////////////////////////////////////////////////////////////////////// | 2022 //////////////////////////////////////////////////////////////////////////////// |
| 2023 // remote_shell_interface: | 2023 // remote_shell_interface: |
| 2024 | 2024 |
| 2025 // Implements remote shell interface and monitors workspace state needed | 2025 // Implements remote shell interface and monitors workspace state needed |
| 2026 // for the remote shell interface. | 2026 // for the remote shell interface. |
| 2027 // | |
| 2028 // This class is also responsible for conversion between server-side screen | |
|
reveman
2017/03/02 02:00:38
I don't understand why we need to create another c
Dominik Laskowski
2017/03/03 13:50:41
Because from the perspective of SF and DMS/WMS/AMS
reveman
2017/03/06 19:02:13
This is android specific so very confusing to see
Dominik Laskowski
2017/03/08 23:13:22
But the server needs to know about the virtual dis
| |
| 2029 // coordinates and client-side virtual coordinates. This mapping enables | |
| 2030 // support for multiple displays when the client is limited to a single | |
| 2031 // display. In that case, the client uses a virtual display computed as | |
| 2032 // the bounding box of the physical displays, and the server translates | |
| 2033 // positions based on the display layout. For example, P is the client's | |
| 2034 // origin in virtual coordinates, and Q is the server's origin in screen | |
| 2035 // coordinates. | |
| 2036 // | |
| 2037 // P Q | |
| 2038 // +-----+ / | |
| 2039 // | |/ | |
| 2040 // | 2 +-----------+ | |
| 2041 // | | | | |
| 2042 // +-----+ 1 | | |
| 2043 // | | | |
| 2044 // +-----------+ | |
| 2045 // | |
| 2027 class WaylandRemoteShell : public WMHelper::MaximizeModeObserver, | 2046 class WaylandRemoteShell : public WMHelper::MaximizeModeObserver, |
| 2028 public WMHelper::ActivationObserver, | 2047 public WMHelper::ActivationObserver, |
| 2029 public display::DisplayObserver { | 2048 public display::DisplayObserver { |
| 2030 public: | 2049 public: |
| 2031 WaylandRemoteShell(Display* display, wl_resource* remote_shell_resource) | 2050 WaylandRemoteShell(Display* display, wl_resource* remote_shell_resource) |
| 2032 : display_(display), | 2051 : display_(display), |
| 2033 remote_shell_resource_(remote_shell_resource), | 2052 remote_shell_resource_(remote_shell_resource), |
| 2034 weak_ptr_factory_(this) { | 2053 weak_ptr_factory_(this) { |
| 2035 auto* helper = WMHelper::GetInstance(); | 2054 auto* helper = WMHelper::GetInstance(); |
| 2036 helper->AddMaximizeModeObserver(this); | 2055 helper->AddMaximizeModeObserver(this); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 2050 helper->RemoveActivationObserver(this); | 2069 helper->RemoveActivationObserver(this); |
| 2051 display::Screen::GetScreen()->RemoveObserver(this); | 2070 display::Screen::GetScreen()->RemoveObserver(this); |
| 2052 } | 2071 } |
| 2053 | 2072 |
| 2054 bool IsMultiDisplaySupported() const { | 2073 bool IsMultiDisplaySupported() const { |
| 2055 return wl_resource_get_version(remote_shell_resource_) >= 3; | 2074 return wl_resource_get_version(remote_shell_resource_) >= 3; |
| 2056 } | 2075 } |
| 2057 | 2076 |
| 2058 std::unique_ptr<ShellSurface> CreateShellSurface(Surface* surface, | 2077 std::unique_ptr<ShellSurface> CreateShellSurface(Surface* surface, |
| 2059 int container) { | 2078 int container) { |
| 2060 return display_->CreateRemoteShellSurface(surface, gfx::Point(), container); | 2079 gfx::Point origin = ComputeVirtualDisplayBounds().origin(); |
| 2080 std::unique_ptr<ShellSurface> shell_surface = | |
| 2081 display_->CreateRemoteShellSurface(surface, origin, container); | |
| 2082 | |
| 2083 if (IsMultiDisplaySupported()) { | |
| 2084 shell_surface->set_display_config_changed_callback(base::Bind( | |
| 2085 [](ShellSurface* shell_surface) { | |
| 2086 shell_surface->SetOrigin(ComputeVirtualDisplayBounds().origin()); | |
| 2087 }, | |
| 2088 shell_surface.get())); | |
| 2089 } | |
| 2090 | |
| 2091 return shell_surface; | |
| 2061 } | 2092 } |
| 2062 | 2093 |
| 2063 std::unique_ptr<NotificationSurface> CreateNotificationSurface( | 2094 std::unique_ptr<NotificationSurface> CreateNotificationSurface( |
| 2064 Surface* surface, | 2095 Surface* surface, |
| 2065 const std::string& notification_id) { | 2096 const std::string& notification_id) { |
| 2066 return display_->CreateNotificationSurface(surface, notification_id); | 2097 return display_->CreateNotificationSurface(surface, notification_id); |
| 2067 } | 2098 } |
| 2068 | 2099 |
| 2069 // Overridden from display::DisplayObserver: | 2100 // Overridden from display::DisplayObserver: |
| 2101 void OnDisplayAdded(const display::Display& new_display) override { | |
| 2102 if (IsMultiDisplaySupported()) | |
| 2103 ScheduleSendDisplayMetrics(0); | |
| 2104 } | |
| 2105 | |
| 2106 void OnDisplayRemoved(const display::Display& old_display) override { | |
| 2107 if (IsMultiDisplaySupported()) | |
| 2108 ScheduleSendDisplayMetrics(0); | |
| 2109 } | |
| 2110 | |
| 2070 void OnDisplayMetricsChanged(const display::Display& display, | 2111 void OnDisplayMetricsChanged(const display::Display& display, |
| 2071 uint32_t changed_metrics) override { | 2112 uint32_t changed_metrics) override { |
| 2072 if (display::Screen::GetScreen()->GetPrimaryDisplay().id() != display.id()) | 2113 if (!IsMultiDisplaySupported() && |
| 2114 display::Screen::GetScreen()->GetPrimaryDisplay().id() != display.id()) | |
| 2073 return; | 2115 return; |
| 2074 | 2116 |
| 2075 // No need to update when a primary display has changed without bounds | 2117 // No need to update when a primary display has changed without bounds |
| 2076 // change. See WaylandPrimaryDisplayObserver::OnDisplayMetricsChanged | 2118 // change. See WaylandPrimaryDisplayObserver::OnDisplayMetricsChanged |
| 2077 // for more details. | 2119 // for more details. |
| 2078 if (changed_metrics & | 2120 if (changed_metrics & |
| 2079 (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_DEVICE_SCALE_FACTOR | | 2121 (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_DEVICE_SCALE_FACTOR | |
| 2080 DISPLAY_METRIC_ROTATION | DISPLAY_METRIC_WORK_AREA)) { | 2122 DISPLAY_METRIC_ROTATION | DISPLAY_METRIC_WORK_AREA)) { |
| 2081 ScheduleSendDisplayMetrics(0); | 2123 ScheduleSendDisplayMetrics(0); |
| 2082 } | 2124 } |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 2106 FROM_HERE, base::Bind(&WaylandRemoteShell::SendDisplayMetrics, | 2148 FROM_HERE, base::Bind(&WaylandRemoteShell::SendDisplayMetrics, |
| 2107 weak_ptr_factory_.GetWeakPtr()), | 2149 weak_ptr_factory_.GetWeakPtr()), |
| 2108 base::TimeDelta::FromMilliseconds(delay_ms)); | 2150 base::TimeDelta::FromMilliseconds(delay_ms)); |
| 2109 } | 2151 } |
| 2110 | 2152 |
| 2111 void SendDisplayMetrics() { | 2153 void SendDisplayMetrics() { |
| 2112 if (!needs_send_display_metrics_) | 2154 if (!needs_send_display_metrics_) |
| 2113 return; | 2155 return; |
| 2114 needs_send_display_metrics_ = false; | 2156 needs_send_display_metrics_ = false; |
| 2115 | 2157 |
| 2116 const display::Screen* screen = display::Screen::GetScreen(); | 2158 display::Display primary_display = |
| 2117 const display::Display primary_display = screen->GetPrimaryDisplay(); | 2159 display::Screen::GetScreen()->GetPrimaryDisplay(); |
| 2118 | 2160 |
| 2161 gfx::Size display_size = IsMultiDisplaySupported() | |
| 2162 ? ComputeVirtualDisplayBounds().size() | |
| 2163 : primary_display.size(); | |
| 2164 | |
| 2165 // TODO(domlaskowski): Send insets for each workspace. | |
| 2119 const gfx::Insets& work_area_insets = primary_display.GetWorkAreaInsets(); | 2166 const gfx::Insets& work_area_insets = primary_display.GetWorkAreaInsets(); |
| 2120 | 2167 |
| 2121 zcr_remote_shell_v1_send_configuration_changed( | 2168 zcr_remote_shell_v1_send_configuration_changed( |
| 2122 remote_shell_resource_, | 2169 remote_shell_resource_, display_size.width(), display_size.height(), |
| 2123 primary_display.size().width(), | |
| 2124 primary_display.size().height(), | |
| 2125 OutputTransform(primary_display.rotation()), | 2170 OutputTransform(primary_display.rotation()), |
| 2126 wl_fixed_from_double(primary_display.device_scale_factor()), | 2171 wl_fixed_from_double(primary_display.device_scale_factor()), |
| 2127 work_area_insets.left(), work_area_insets.top(), | 2172 work_area_insets.left(), work_area_insets.top(), |
| 2128 work_area_insets.right(), work_area_insets.bottom(), layout_mode_); | 2173 work_area_insets.right(), work_area_insets.bottom(), layout_mode_); |
| 2129 wl_client_flush(wl_resource_get_client(remote_shell_resource_)); | 2174 wl_client_flush(wl_resource_get_client(remote_shell_resource_)); |
| 2130 } | 2175 } |
| 2131 | 2176 |
| 2132 void SendActivated(aura::Window* gained_active, aura::Window* lost_active) { | 2177 void SendActivated(aura::Window* gained_active, aura::Window* lost_active) { |
| 2133 Surface* gained_active_surface = | 2178 Surface* gained_active_surface = |
| 2134 gained_active ? ShellSurface::GetMainSurface(gained_active) : nullptr; | 2179 gained_active ? ShellSurface::GetMainSurface(gained_active) : nullptr; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 2155 wl_resource_get_client(lost_active_surface_resource) != client) { | 2200 wl_resource_get_client(lost_active_surface_resource) != client) { |
| 2156 lost_active_surface_resource = nullptr; | 2201 lost_active_surface_resource = nullptr; |
| 2157 } | 2202 } |
| 2158 | 2203 |
| 2159 zcr_remote_shell_v1_send_activated(remote_shell_resource_, | 2204 zcr_remote_shell_v1_send_activated(remote_shell_resource_, |
| 2160 gained_active_surface_resource, | 2205 gained_active_surface_resource, |
| 2161 lost_active_surface_resource); | 2206 lost_active_surface_resource); |
| 2162 wl_client_flush(client); | 2207 wl_client_flush(client); |
| 2163 } | 2208 } |
| 2164 | 2209 |
| 2210 static gfx::Rect ComputeVirtualDisplayBounds() { | |
| 2211 // Virtual screen is the bounding box of the displays in screen coordinates. | |
| 2212 gfx::Rect bounds; | |
| 2213 for (const auto& display : display::Screen::GetScreen()->GetAllDisplays()) | |
| 2214 bounds.Union(display.bounds()); | |
| 2215 return bounds; | |
| 2216 } | |
| 2217 | |
| 2165 // The exo display instance. Not owned. | 2218 // The exo display instance. Not owned. |
| 2166 Display* const display_; | 2219 Display* const display_; |
| 2167 | 2220 |
| 2168 // The remote shell resource associated with observer. | 2221 // The remote shell resource associated with observer. |
| 2169 wl_resource* const remote_shell_resource_; | 2222 wl_resource* const remote_shell_resource_; |
| 2170 | 2223 |
| 2171 bool needs_send_display_metrics_ = true; | 2224 bool needs_send_display_metrics_ = true; |
| 2172 | 2225 |
| 2173 int layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; | 2226 int layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; |
| 2174 | 2227 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2307 wl_resource_get_version(resource), id); | 2360 wl_resource_get_version(resource), id); |
| 2308 SetImplementation(notification_surface_resource, | 2361 SetImplementation(notification_surface_resource, |
| 2309 ¬ification_surface_implementation, | 2362 ¬ification_surface_implementation, |
| 2310 std::move(notification_surface)); | 2363 std::move(notification_surface)); |
| 2311 } | 2364 } |
| 2312 | 2365 |
| 2313 const struct zcr_remote_shell_v1_interface remote_shell_implementation = { | 2366 const struct zcr_remote_shell_v1_interface remote_shell_implementation = { |
| 2314 remote_shell_destroy, remote_shell_get_remote_surface, | 2367 remote_shell_destroy, remote_shell_get_remote_surface, |
| 2315 remote_shell_get_notification_surface}; | 2368 remote_shell_get_notification_surface}; |
| 2316 | 2369 |
| 2317 const uint32_t remote_shell_version = 2; | 2370 const uint32_t remote_shell_version = 3; |
| 2318 | 2371 |
| 2319 void bind_remote_shell(wl_client* client, | 2372 void bind_remote_shell(wl_client* client, |
| 2320 void* data, | 2373 void* data, |
| 2321 uint32_t version, | 2374 uint32_t version, |
| 2322 uint32_t id) { | 2375 uint32_t id) { |
| 2323 wl_resource* resource = | 2376 wl_resource* resource = |
| 2324 wl_resource_create(client, &zcr_remote_shell_v1_interface, | 2377 wl_resource_create(client, &zcr_remote_shell_v1_interface, |
| 2325 std::min(version, remote_shell_version), id); | 2378 std::min(version, remote_shell_version), id); |
| 2326 | 2379 |
| 2327 SetImplementation(resource, &remote_shell_implementation, | 2380 SetImplementation(resource, &remote_shell_implementation, |
| (...skipping 1436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3764 DCHECK(event_loop); | 3817 DCHECK(event_loop); |
| 3765 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); | 3818 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); |
| 3766 } | 3819 } |
| 3767 | 3820 |
| 3768 void Server::Flush() { | 3821 void Server::Flush() { |
| 3769 wl_display_flush_clients(wl_display_.get()); | 3822 wl_display_flush_clients(wl_display_.get()); |
| 3770 } | 3823 } |
| 3771 | 3824 |
| 3772 } // namespace wayland | 3825 } // namespace wayland |
| 3773 } // namespace exo | 3826 } // namespace exo |
| OLD | NEW |