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

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

Issue 2207313002: Use the current primary display to update output/configure. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2785
Patch Set: Use the current primary display to update output/configure. Created 4 years, 4 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 | « no previous file | 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 <grp.h> 7 #include <grp.h>
8 #include <linux/input.h> 8 #include <linux/input.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <stdint.h> 10 #include <stdint.h>
(...skipping 1019 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 return WL_OUTPUT_TRANSFORM_90; 1030 return WL_OUTPUT_TRANSFORM_90;
1031 case display::Display::ROTATE_180: 1031 case display::Display::ROTATE_180:
1032 return WL_OUTPUT_TRANSFORM_180; 1032 return WL_OUTPUT_TRANSFORM_180;
1033 case display::Display::ROTATE_270: 1033 case display::Display::ROTATE_270:
1034 return WL_OUTPUT_TRANSFORM_270; 1034 return WL_OUTPUT_TRANSFORM_270;
1035 } 1035 }
1036 NOTREACHED(); 1036 NOTREACHED();
1037 return WL_OUTPUT_TRANSFORM_NORMAL; 1037 return WL_OUTPUT_TRANSFORM_NORMAL;
1038 } 1038 }
1039 1039
1040 class WaylandDisplayObserver : public display::DisplayObserver { 1040 class WaylandPrimaryDisplayObserver : public display::DisplayObserver {
1041 public: 1041 public:
1042 WaylandDisplayObserver(const display::Display& display, 1042 WaylandPrimaryDisplayObserver(wl_resource* output_resource)
1043 wl_resource* output_resource) 1043 : output_resource_(output_resource) {
1044 : display_id_(display.id()), output_resource_(output_resource) {
1045 display::Screen::GetScreen()->AddObserver(this); 1044 display::Screen::GetScreen()->AddObserver(this);
1046 SendDisplayMetrics(display); 1045 SendDisplayMetrics();
1047 } 1046 }
1048 ~WaylandDisplayObserver() override { 1047 ~WaylandPrimaryDisplayObserver() override {
1049 display::Screen::GetScreen()->RemoveObserver(this); 1048 display::Screen::GetScreen()->RemoveObserver(this);
1050 } 1049 }
1051 1050
1052 // Overridden from display::DisplayObserver: 1051 // Overridden from display::DisplayObserver:
1053 void OnDisplayAdded(const display::Display& new_display) override {} 1052 void OnDisplayAdded(const display::Display& new_display) override {}
1054 void OnDisplayRemoved(const display::Display& new_display) override {} 1053 void OnDisplayRemoved(const display::Display& new_display) override {}
1055 void OnDisplayMetricsChanged(const display::Display& display, 1054 void OnDisplayMetricsChanged(const display::Display& display,
1056 uint32_t changed_metrics) override { 1055 uint32_t changed_metrics) override {
1057 if (display.id() != display_id_) 1056 if (display::Screen::GetScreen()->GetPrimaryDisplay().id() != display.id())
1058 return; 1057 return;
1059 1058
1059 // There is no need to check DISPLAY_METRIC_PRIMARY because when primary
1060 // changes, bounds always changes. (new primary should have had non
1061 // 0,0 origin).
1062 // Only exception is when switching to newly connected primary with
1063 // the same bounds. This happens whenyou're in docked mode, suspend,
1064 // unplug the dislpay, then resume to the internal display which has
1065 // the same resolution. Since metrics does not change, there is no need
1066 // to notify clients.
1060 if (changed_metrics & 1067 if (changed_metrics &
1061 (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_DEVICE_SCALE_FACTOR | 1068 (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_DEVICE_SCALE_FACTOR |
1062 DISPLAY_METRIC_ROTATION)) { 1069 DISPLAY_METRIC_ROTATION)) {
1063 SendDisplayMetrics(display); 1070 SendDisplayMetrics();
1064 } 1071 }
1065 } 1072 }
1066 1073
1067 private: 1074 private:
1068 void SendDisplayMetrics(const display::Display& display) { 1075 void SendDisplayMetrics() {
1076 display::Display display =
1077 display::Screen::GetScreen()->GetPrimaryDisplay();
1078
1069 const ash::DisplayInfo& info = 1079 const ash::DisplayInfo& info =
1070 ash::Shell::GetInstance()->display_manager()->GetDisplayInfo( 1080 ash::Shell::GetInstance()->display_manager()->GetDisplayInfo(
1071 display.id()); 1081 display.id());
1072 1082
1073 const float kInchInMm = 25.4f; 1083 const float kInchInMm = 25.4f;
1074 const char* kUnknownMake = "unknown"; 1084 const char* kUnknownMake = "unknown";
1075 const char* kUnknownModel = "unknown"; 1085 const char* kUnknownModel = "unknown";
1076 1086
1077 gfx::Rect bounds = info.bounds_in_native(); 1087 gfx::Rect bounds = info.bounds_in_native();
1078 wl_output_send_geometry( 1088 wl_output_send_geometry(
(...skipping 12 matching lines...) Expand all
1091 wl_output_send_mode( 1101 wl_output_send_mode(
1092 output_resource_, WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED, 1102 output_resource_, WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED,
1093 bounds.width(), bounds.height(), static_cast<int>(60000)); 1103 bounds.width(), bounds.height(), static_cast<int>(60000));
1094 1104
1095 if (wl_resource_get_version(output_resource_) >= 1105 if (wl_resource_get_version(output_resource_) >=
1096 WL_OUTPUT_DONE_SINCE_VERSION) { 1106 WL_OUTPUT_DONE_SINCE_VERSION) {
1097 wl_output_send_done(output_resource_); 1107 wl_output_send_done(output_resource_);
1098 } 1108 }
1099 } 1109 }
1100 1110
1101 // The identifier associated with the observed display.
1102 const int64_t display_id_;
1103
1104 // The output resource associated with the display. 1111 // The output resource associated with the display.
1105 wl_resource* const output_resource_; 1112 wl_resource* const output_resource_;
1106 1113
1107 DISALLOW_COPY_AND_ASSIGN(WaylandDisplayObserver); 1114 DISALLOW_COPY_AND_ASSIGN(WaylandPrimaryDisplayObserver);
1108 }; 1115 };
1109 1116
1110 const uint32_t output_version = 2; 1117 const uint32_t output_version = 2;
1111 1118
1112 void bind_output(wl_client* client, void* data, uint32_t version, uint32_t id) { 1119 void bind_output(wl_client* client, void* data, uint32_t version, uint32_t id) {
1113 wl_resource* resource = wl_resource_create( 1120 wl_resource* resource = wl_resource_create(
1114 client, &wl_output_interface, std::min(version, output_version), id); 1121 client, &wl_output_interface, std::min(version, output_version), id);
1115 1122
1116 // TODO(reveman): Multi-display support.
1117 const display::Display& display = ash::Shell::GetInstance()
1118 ->display_manager()
1119 ->GetPrimaryDisplayCandidate();
1120
1121 SetImplementation( 1123 SetImplementation(
1122 resource, nullptr, 1124 resource, nullptr,
1123 base::WrapUnique(new WaylandDisplayObserver(display, resource))); 1125 base::WrapUnique(new WaylandPrimaryDisplayObserver(resource)));
1124 } 1126 }
1125 1127
1126 //////////////////////////////////////////////////////////////////////////////// 1128 ////////////////////////////////////////////////////////////////////////////////
1127 // xdg_surface_interface: 1129 // xdg_surface_interface:
1128 1130
1129 int XdgResizeComponent(uint32_t edges) { 1131 int XdgResizeComponent(uint32_t edges) {
1130 switch (edges) { 1132 switch (edges) {
1131 case XDG_SURFACE_RESIZE_EDGE_TOP: 1133 case XDG_SURFACE_RESIZE_EDGE_TOP:
1132 return HTTOP; 1134 return HTTOP;
1133 case XDG_SURFACE_RESIZE_EDGE_BOTTOM: 1135 case XDG_SURFACE_RESIZE_EDGE_BOTTOM:
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
1560 //////////////////////////////////////////////////////////////////////////////// 1562 ////////////////////////////////////////////////////////////////////////////////
1561 // remote_shell_interface: 1563 // remote_shell_interface:
1562 1564
1563 // Implements remote shell interface and monitors workspace state needed 1565 // Implements remote shell interface and monitors workspace state needed
1564 // for the remote shell interface. 1566 // for the remote shell interface.
1565 class WaylandRemoteShell : public ash::ShellObserver, 1567 class WaylandRemoteShell : public ash::ShellObserver,
1566 public aura::client::ActivationChangeObserver, 1568 public aura::client::ActivationChangeObserver,
1567 public display::DisplayObserver { 1569 public display::DisplayObserver {
1568 public: 1570 public:
1569 WaylandRemoteShell(Display* display, 1571 WaylandRemoteShell(Display* display,
1570 int64_t display_id,
1571 wl_resource* remote_shell_resource) 1572 wl_resource* remote_shell_resource)
1572 : display_(display), 1573 : display_(display),
1573 display_id_(display_id),
1574 remote_shell_resource_(remote_shell_resource), 1574 remote_shell_resource_(remote_shell_resource),
1575 weak_ptr_factory_(this) { 1575 weak_ptr_factory_(this) {
1576 ash::WmShell::Get()->AddShellObserver(this); 1576 ash::WmShell::Get()->AddShellObserver(this);
1577 ash::Shell* shell = ash::Shell::GetInstance(); 1577 ash::Shell* shell = ash::Shell::GetInstance();
1578 shell->activation_client()->AddObserver(this); 1578 shell->activation_client()->AddObserver(this);
1579 display::Screen::GetScreen()->AddObserver(this); 1579 display::Screen::GetScreen()->AddObserver(this);
1580 SendPrimaryDisplayMetrics(); 1580 SendPrimaryDisplayMetrics();
1581 SendActivated(shell->activation_client()->GetActiveWindow(), nullptr); 1581 SendActivated(shell->activation_client()->GetActiveWindow(), nullptr);
1582 } 1582 }
1583 ~WaylandRemoteShell() override { 1583 ~WaylandRemoteShell() override {
(...skipping 11 matching lines...) Expand all
1595 Surface* surface, 1595 Surface* surface,
1596 const std::string& notification_id) { 1596 const std::string& notification_id) {
1597 return display_->CreateNotificationSurface(surface, notification_id); 1597 return display_->CreateNotificationSurface(surface, notification_id);
1598 } 1598 }
1599 1599
1600 // Overridden from display::DisplayObserver: 1600 // Overridden from display::DisplayObserver:
1601 void OnDisplayAdded(const display::Display& new_display) override {} 1601 void OnDisplayAdded(const display::Display& new_display) override {}
1602 void OnDisplayRemoved(const display::Display& new_display) override {} 1602 void OnDisplayRemoved(const display::Display& new_display) override {}
1603 void OnDisplayMetricsChanged(const display::Display& display, 1603 void OnDisplayMetricsChanged(const display::Display& display,
1604 uint32_t changed_metrics) override { 1604 uint32_t changed_metrics) override {
1605 if (display.id() != display_id_) 1605 if (display::Screen::GetScreen()->GetPrimaryDisplay().id() != display.id())
1606 return; 1606 return;
1607 1607
1608 // No need to update when a primary dislpay has changed without bounds
1609 // change. See WaylandPrimaryDisplayObserver::OnDisplayMetricsChanged
1610 // for more details.
1608 if (changed_metrics & 1611 if (changed_metrics &
1609 (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_DEVICE_SCALE_FACTOR | 1612 (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_DEVICE_SCALE_FACTOR |
1610 DISPLAY_METRIC_ROTATION | DISPLAY_METRIC_WORK_AREA)) { 1613 DISPLAY_METRIC_ROTATION | DISPLAY_METRIC_WORK_AREA)) {
1611 SendDisplayMetrics(display); 1614 SendDisplayMetrics(display);
1612 } 1615 }
1613 SendConfigure_DEPRECATED(display); 1616 SendConfigure_DEPRECATED(display);
1614 } 1617 }
1615 1618
1616 // Overridden from ash::ShellObserver: 1619 // Overridden from ash::ShellObserver:
1617 void OnDisplayWorkAreaInsetsChanged() override { 1620 void OnDisplayWorkAreaInsetsChanged() override {
1618 const display::Display& primary = 1621 const display::Display primary =
1619 ash::Shell::GetInstance()->display_manager()->GetDisplayForId( 1622 display::Screen::GetScreen()->GetPrimaryDisplay();
1620 display_id_);
1621 SendConfigure_DEPRECATED(primary); 1623 SendConfigure_DEPRECATED(primary);
1622 } 1624 }
1623 void OnMaximizeModeStarted() override { 1625 void OnMaximizeModeStarted() override {
1624 layout_mode_ = ZWP_REMOTE_SHELL_V1_LAYOUT_MODE_TABLET; 1626 layout_mode_ = ZWP_REMOTE_SHELL_V1_LAYOUT_MODE_TABLET;
1625 SendLayoutModeChange_DEPRECATED(); 1627 SendLayoutModeChange_DEPRECATED();
1626 1628
1627 send_configure_after_layout_change_ = true; 1629 send_configure_after_layout_change_ = true;
1628 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 1630 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
1629 FROM_HERE, base::Bind(&WaylandRemoteShell::MaybeSendConfigure, 1631 FROM_HERE, base::Bind(&WaylandRemoteShell::MaybeSendConfigure,
1630 weak_ptr_factory_.GetWeakPtr()), 1632 weak_ptr_factory_.GetWeakPtr()),
(...skipping 12 matching lines...) Expand all
1643 // Overridden from aura::client::ActivationChangeObserver: 1645 // Overridden from aura::client::ActivationChangeObserver:
1644 void OnWindowActivated( 1646 void OnWindowActivated(
1645 aura::client::ActivationChangeObserver::ActivationReason reason, 1647 aura::client::ActivationChangeObserver::ActivationReason reason,
1646 aura::Window* gained_active, 1648 aura::Window* gained_active,
1647 aura::Window* lost_active) override { 1649 aura::Window* lost_active) override {
1648 SendActivated(gained_active, lost_active); 1650 SendActivated(gained_active, lost_active);
1649 } 1651 }
1650 1652
1651 private: 1653 private:
1652 void SendPrimaryDisplayMetrics() { 1654 void SendPrimaryDisplayMetrics() {
1653 const display::Display& primary = 1655 const display::Display primary =
1654 ash::Shell::GetInstance()->display_manager()->GetDisplayForId( 1656 display::Screen::GetScreen()->GetPrimaryDisplay();
1655 display_id_); 1657
1656 SendConfigure_DEPRECATED(primary); 1658 SendConfigure_DEPRECATED(primary);
1657 SendDisplayMetrics(primary); 1659 SendDisplayMetrics(primary);
1658 } 1660 }
1659 1661
1660 void MaybeSendConfigure() { 1662 void MaybeSendConfigure() {
1661 if (send_configure_after_layout_change_) 1663 if (send_configure_after_layout_change_)
1662 SendPrimaryDisplayMetrics(); 1664 SendPrimaryDisplayMetrics();
1663 } 1665 }
1664 1666
1665 void SendDisplayMetrics(const display::Display& display) { 1667 void SendDisplayMetrics(const display::Display& display) {
(...skipping 13 matching lines...) Expand all
1679 1681
1680 wl_client_flush(wl_resource_get_client(remote_shell_resource_)); 1682 wl_client_flush(wl_resource_get_client(remote_shell_resource_));
1681 } 1683 }
1682 1684
1683 void SendConfigure_DEPRECATED(const display::Display& display) { 1685 void SendConfigure_DEPRECATED(const display::Display& display) {
1684 send_configure_after_layout_change_ = false; 1686 send_configure_after_layout_change_ = false;
1685 1687
1686 if (wl_resource_get_version(remote_shell_resource_) >= 9) 1688 if (wl_resource_get_version(remote_shell_resource_) >= 9)
1687 return; 1689 return;
1688 1690
1689 gfx::Insets work_area_insets = display.GetWorkAreaInsets(); 1691 const gfx::Insets& work_area_insets = display.GetWorkAreaInsets();
1690 zwp_remote_shell_v1_send_configure( 1692 zwp_remote_shell_v1_send_configure(
1691 remote_shell_resource_, display.size().width(), display.size().height(), 1693 remote_shell_resource_, display.size().width(), display.size().height(),
1692 work_area_insets.left(), work_area_insets.top(), 1694 work_area_insets.left(), work_area_insets.top(),
1693 work_area_insets.right(), work_area_insets.bottom()); 1695 work_area_insets.right(), work_area_insets.bottom());
1694 wl_client_flush(wl_resource_get_client(remote_shell_resource_)); 1696 wl_client_flush(wl_resource_get_client(remote_shell_resource_));
1695 } 1697 }
1696 1698
1697 void SendLayoutModeChange_DEPRECATED() { 1699 void SendLayoutModeChange_DEPRECATED() {
1698 if (wl_resource_get_version(remote_shell_resource_) < 8) 1700 if (wl_resource_get_version(remote_shell_resource_) < 8)
1699 return; 1701 return;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1731 1733
1732 zwp_remote_shell_v1_send_activated(remote_shell_resource_, 1734 zwp_remote_shell_v1_send_activated(remote_shell_resource_,
1733 gained_active_surface_resource, 1735 gained_active_surface_resource,
1734 lost_active_surface_resource); 1736 lost_active_surface_resource);
1735 wl_client_flush(client); 1737 wl_client_flush(client);
1736 } 1738 }
1737 1739
1738 // The exo display instance. Not owned. 1740 // The exo display instance. Not owned.
1739 Display* const display_; 1741 Display* const display_;
1740 1742
1741 // The identifier associated with the observed display.
1742 const int64_t display_id_;
1743
1744 // The remote shell resource associated with observer. 1743 // The remote shell resource associated with observer.
1745 wl_resource* const remote_shell_resource_; 1744 wl_resource* const remote_shell_resource_;
1746 1745
1747 bool send_configure_after_layout_change_ = false; 1746 bool send_configure_after_layout_change_ = false;
1748 1747
1749 int layout_mode_ = ZWP_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; 1748 int layout_mode_ = ZWP_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED;
1750 1749
1751 base::WeakPtrFactory<WaylandRemoteShell> weak_ptr_factory_; 1750 base::WeakPtrFactory<WaylandRemoteShell> weak_ptr_factory_;
1752 1751
1753 DISALLOW_COPY_AND_ASSIGN(WaylandRemoteShell); 1752 DISALLOW_COPY_AND_ASSIGN(WaylandRemoteShell);
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1896 const uint32_t remote_shell_version = 9; 1895 const uint32_t remote_shell_version = 9;
1897 1896
1898 void bind_remote_shell(wl_client* client, 1897 void bind_remote_shell(wl_client* client,
1899 void* data, 1898 void* data,
1900 uint32_t version, 1899 uint32_t version,
1901 uint32_t id) { 1900 uint32_t id) {
1902 wl_resource* resource = 1901 wl_resource* resource =
1903 wl_resource_create(client, &zwp_remote_shell_v1_interface, 1902 wl_resource_create(client, &zwp_remote_shell_v1_interface,
1904 std::min(version, remote_shell_version), id); 1903 std::min(version, remote_shell_version), id);
1905 1904
1906 // TODO(reveman): Multi-display support.
1907 const display::Display& display = ash::Shell::GetInstance()
1908 ->display_manager()
1909 ->GetPrimaryDisplayCandidate();
1910
1911 SetImplementation(resource, &remote_shell_implementation, 1905 SetImplementation(resource, &remote_shell_implementation,
1912 base::WrapUnique(new WaylandRemoteShell( 1906 base::WrapUnique(new WaylandRemoteShell(
1913 static_cast<Display*>(data), display.id(), resource))); 1907 static_cast<Display*>(data), resource)));
1914 } 1908 }
1915 1909
1916 //////////////////////////////////////////////////////////////////////////////// 1910 ////////////////////////////////////////////////////////////////////////////////
1917 // zwp_vsync_timing_v1_interface: 1911 // zwp_vsync_timing_v1_interface:
1918 1912
1919 // Implements VSync timing interface by monitoring a compositor for updates 1913 // Implements VSync timing interface by monitoring a compositor for updates
1920 // to VSync parameters. 1914 // to VSync parameters.
1921 class VSyncTiming : public ui::CompositorVSyncManager::Observer { 1915 class VSyncTiming : public ui::CompositorVSyncManager::Observer {
1922 public: 1916 public:
1923 ~VSyncTiming() { vsync_manager_->RemoveObserver(this); } 1917 ~VSyncTiming() { vsync_manager_->RemoveObserver(this); }
(...skipping 1127 matching lines...) Expand 10 before | Expand all | Expand 10 after
3051 DCHECK(event_loop); 3045 DCHECK(event_loop);
3052 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); 3046 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds());
3053 } 3047 }
3054 3048
3055 void Server::Flush() { 3049 void Server::Flush() {
3056 wl_display_flush_clients(wl_display_.get()); 3050 wl_display_flush_clients(wl_display_.get());
3057 } 3051 }
3058 3052
3059 } // namespace wayland 3053 } // namespace wayland
3060 } // namespace exo 3054 } // namespace exo
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698