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

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

Issue 2202343003: Use the current primary display to update output/configure. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 return WL_OUTPUT_TRANSFORM_90; 1031 return WL_OUTPUT_TRANSFORM_90;
1032 case display::Display::ROTATE_180: 1032 case display::Display::ROTATE_180:
1033 return WL_OUTPUT_TRANSFORM_180; 1033 return WL_OUTPUT_TRANSFORM_180;
1034 case display::Display::ROTATE_270: 1034 case display::Display::ROTATE_270:
1035 return WL_OUTPUT_TRANSFORM_270; 1035 return WL_OUTPUT_TRANSFORM_270;
1036 } 1036 }
1037 NOTREACHED(); 1037 NOTREACHED();
1038 return WL_OUTPUT_TRANSFORM_NORMAL; 1038 return WL_OUTPUT_TRANSFORM_NORMAL;
1039 } 1039 }
1040 1040
1041 class WaylandDisplayObserver : public display::DisplayObserver { 1041 class WaylandDisplayObserver : public display::DisplayObserver {
reveman 2016/08/02 22:12:35 nit: can you change the name of this to WaylandPri
oshima 2016/08/03 00:22:55 Done.
1042 public: 1042 public:
1043 WaylandDisplayObserver(const display::Display& display, 1043 WaylandDisplayObserver(wl_resource* output_resource)
1044 wl_resource* output_resource) 1044 : output_resource_(output_resource) {
1045 : display_id_(display.id()), output_resource_(output_resource) {
1046 display::Screen::GetScreen()->AddObserver(this); 1045 display::Screen::GetScreen()->AddObserver(this);
1047 SendDisplayMetrics(display); 1046 SendPrimaryDisplayMetrics();
1048 } 1047 }
1049 ~WaylandDisplayObserver() override { 1048 ~WaylandDisplayObserver() override {
1050 display::Screen::GetScreen()->RemoveObserver(this); 1049 display::Screen::GetScreen()->RemoveObserver(this);
1051 } 1050 }
1052 1051
1053 // Overridden from display::DisplayObserver: 1052 // Overridden from display::DisplayObserver:
1054 void OnDisplayAdded(const display::Display& new_display) override {} 1053 void OnDisplayAdded(const display::Display& new_display) override {}
1055 void OnDisplayRemoved(const display::Display& new_display) override {} 1054 void OnDisplayRemoved(const display::Display& new_display) override {}
1056 void OnDisplayMetricsChanged(const display::Display& display, 1055 void OnDisplayMetricsChanged(const display::Display& display,
1057 uint32_t changed_metrics) override { 1056 uint32_t changed_metrics) override {
1058 if (display.id() != display_id_) 1057 if (display::Screen::GetScreen()->GetPrimaryDisplay().id() != display.id())
1059 return; 1058 return;
1060 1059
1061 if (changed_metrics & 1060 if (changed_metrics &
reveman 2016/08/02 22:12:35 nit: can you add a short comment here that makes i
oshima 2016/08/03 00:22:55 Done.
1062 (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_DEVICE_SCALE_FACTOR | 1061 (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_DEVICE_SCALE_FACTOR |
1063 DISPLAY_METRIC_ROTATION)) { 1062 DISPLAY_METRIC_ROTATION)) {
1064 SendDisplayMetrics(display); 1063 SendPrimaryDisplayMetrics();
1065 } 1064 }
1066 } 1065 }
1067 1066
1068 private: 1067 private:
1069 void SendDisplayMetrics(const display::Display& display) { 1068 void SendPrimaryDisplayMetrics() {
reveman 2016/08/02 22:12:35 nit: keep name as SendDisplayMetrics if you change
oshima 2016/08/03 00:22:55 Done.
1069 // TODO(reveman): Multi-display support.
reveman 2016/08/02 22:12:35 nit: move this TODO to where we instantiate the cl
oshima 2016/08/03 00:22:55 Done.
1070 display::Display display =
1071 display::Screen::GetScreen()->GetPrimaryDisplay();
1072
1070 const ash::DisplayInfo& info = 1073 const ash::DisplayInfo& info =
1071 ash::Shell::GetInstance()->display_manager()->GetDisplayInfo( 1074 ash::Shell::GetInstance()->display_manager()->GetDisplayInfo(
1072 display.id()); 1075 display.id());
1073 1076
1074 const float kInchInMm = 25.4f; 1077 const float kInchInMm = 25.4f;
1075 const char* kUnknownMake = "unknown"; 1078 const char* kUnknownMake = "unknown";
1076 const char* kUnknownModel = "unknown"; 1079 const char* kUnknownModel = "unknown";
1077 1080
1078 gfx::Rect bounds = info.bounds_in_native(); 1081 gfx::Rect bounds = info.bounds_in_native();
1079 wl_output_send_geometry( 1082 wl_output_send_geometry(
(...skipping 12 matching lines...) Expand all
1092 wl_output_send_mode( 1095 wl_output_send_mode(
1093 output_resource_, WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED, 1096 output_resource_, WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED,
1094 bounds.width(), bounds.height(), static_cast<int>(60000)); 1097 bounds.width(), bounds.height(), static_cast<int>(60000));
1095 1098
1096 if (wl_resource_get_version(output_resource_) >= 1099 if (wl_resource_get_version(output_resource_) >=
1097 WL_OUTPUT_DONE_SINCE_VERSION) { 1100 WL_OUTPUT_DONE_SINCE_VERSION) {
1098 wl_output_send_done(output_resource_); 1101 wl_output_send_done(output_resource_);
1099 } 1102 }
1100 } 1103 }
1101 1104
1102 // The identifier associated with the observed display.
1103 const int64_t display_id_;
1104
1105 // The output resource associated with the display. 1105 // The output resource associated with the display.
1106 wl_resource* const output_resource_; 1106 wl_resource* const output_resource_;
1107 1107
1108 DISALLOW_COPY_AND_ASSIGN(WaylandDisplayObserver); 1108 DISALLOW_COPY_AND_ASSIGN(WaylandDisplayObserver);
1109 }; 1109 };
1110 1110
1111 const uint32_t output_version = 2; 1111 const uint32_t output_version = 2;
1112 1112
1113 void bind_output(wl_client* client, void* data, uint32_t version, uint32_t id) { 1113 void bind_output(wl_client* client, void* data, uint32_t version, uint32_t id) {
1114 wl_resource* resource = wl_resource_create( 1114 wl_resource* resource = wl_resource_create(
1115 client, &wl_output_interface, std::min(version, output_version), id); 1115 client, &wl_output_interface, std::min(version, output_version), id);
1116 1116
1117 // TODO(reveman): Multi-display support. 1117 SetImplementation(resource, nullptr,
1118 const display::Display& display = ash::Shell::GetInstance() 1118 base::WrapUnique(new WaylandDisplayObserver(resource)));
1119 ->display_manager()
1120 ->GetPrimaryDisplayCandidate();
1121
1122 SetImplementation(
1123 resource, nullptr,
1124 base::WrapUnique(new WaylandDisplayObserver(display, resource)));
1125 } 1119 }
1126 1120
1127 //////////////////////////////////////////////////////////////////////////////// 1121 ////////////////////////////////////////////////////////////////////////////////
1128 // xdg_surface_interface: 1122 // xdg_surface_interface:
1129 1123
1130 int XdgResizeComponent(uint32_t edges) { 1124 int XdgResizeComponent(uint32_t edges) {
1131 switch (edges) { 1125 switch (edges) {
1132 case XDG_SURFACE_RESIZE_EDGE_TOP: 1126 case XDG_SURFACE_RESIZE_EDGE_TOP:
1133 return HTTOP; 1127 return HTTOP;
1134 case XDG_SURFACE_RESIZE_EDGE_BOTTOM: 1128 case XDG_SURFACE_RESIZE_EDGE_BOTTOM:
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
1568 //////////////////////////////////////////////////////////////////////////////// 1562 ////////////////////////////////////////////////////////////////////////////////
1569 // remote_shell_interface: 1563 // remote_shell_interface:
1570 1564
1571 // Implements remote shell interface and monitors workspace state needed 1565 // Implements remote shell interface and monitors workspace state needed
1572 // for the remote shell interface. 1566 // for the remote shell interface.
1573 class WaylandRemoteShell : public ash::ShellObserver, 1567 class WaylandRemoteShell : public ash::ShellObserver,
1574 public aura::client::ActivationChangeObserver, 1568 public aura::client::ActivationChangeObserver,
1575 public display::DisplayObserver { 1569 public display::DisplayObserver {
1576 public: 1570 public:
1577 WaylandRemoteShell(Display* display, 1571 WaylandRemoteShell(Display* display,
1578 int64_t display_id,
1579 wl_resource* remote_shell_resource) 1572 wl_resource* remote_shell_resource)
1580 : display_(display), 1573 : display_(display),
1581 display_id_(display_id),
1582 remote_shell_resource_(remote_shell_resource), 1574 remote_shell_resource_(remote_shell_resource),
1583 weak_ptr_factory_(this) { 1575 weak_ptr_factory_(this) {
1584 ash::WmShell::Get()->AddShellObserver(this); 1576 ash::WmShell::Get()->AddShellObserver(this);
1585 ash::Shell* shell = ash::Shell::GetInstance(); 1577 ash::Shell* shell = ash::Shell::GetInstance();
1586 shell->activation_client()->AddObserver(this); 1578 shell->activation_client()->AddObserver(this);
1587 display::Screen::GetScreen()->AddObserver(this); 1579 display::Screen::GetScreen()->AddObserver(this);
1588 SendPrimaryDisplayMetrics(); 1580 SendPrimaryDisplayMetrics();
1589 SendActivated(shell->activation_client()->GetActiveWindow(), nullptr); 1581 SendActivated(shell->activation_client()->GetActiveWindow(), nullptr);
1590 } 1582 }
1591 ~WaylandRemoteShell() override { 1583 ~WaylandRemoteShell() override {
(...skipping 11 matching lines...) Expand all
1603 Surface* surface, 1595 Surface* surface,
1604 const std::string& notification_id) { 1596 const std::string& notification_id) {
1605 return display_->CreateNotificationSurface(surface, notification_id); 1597 return display_->CreateNotificationSurface(surface, notification_id);
1606 } 1598 }
1607 1599
1608 // Overridden from display::DisplayObserver: 1600 // Overridden from display::DisplayObserver:
1609 void OnDisplayAdded(const display::Display& new_display) override {} 1601 void OnDisplayAdded(const display::Display& new_display) override {}
1610 void OnDisplayRemoved(const display::Display& new_display) override {} 1602 void OnDisplayRemoved(const display::Display& new_display) override {}
1611 void OnDisplayMetricsChanged(const display::Display& display, 1603 void OnDisplayMetricsChanged(const display::Display& display,
1612 uint32_t changed_metrics) override { 1604 uint32_t changed_metrics) override {
1613 if (display.id() != display_id_) 1605 if (display::Screen::GetScreen()->GetPrimaryDisplay().id() != display.id())
1614 return; 1606 return;
1615 1607
1616 if (changed_metrics & 1608 if (changed_metrics &
1617 (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_DEVICE_SCALE_FACTOR | 1609 (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_DEVICE_SCALE_FACTOR |
1618 DISPLAY_METRIC_ROTATION | DISPLAY_METRIC_WORK_AREA)) { 1610 DISPLAY_METRIC_ROTATION | DISPLAY_METRIC_WORK_AREA)) {
1619 SendDisplayMetrics(display); 1611 SendDisplayMetrics(display);
1620 } 1612 }
1621 SendConfigure_DEPRECATED(display); 1613 SendConfigure_DEPRECATED(display);
1622 } 1614 }
1623 1615
(...skipping 21 matching lines...) Expand all
1645 // Overridden from aura::client::ActivationChangeObserver: 1637 // Overridden from aura::client::ActivationChangeObserver:
1646 void OnWindowActivated( 1638 void OnWindowActivated(
1647 aura::client::ActivationChangeObserver::ActivationReason reason, 1639 aura::client::ActivationChangeObserver::ActivationReason reason,
1648 aura::Window* gained_active, 1640 aura::Window* gained_active,
1649 aura::Window* lost_active) override { 1641 aura::Window* lost_active) override {
1650 SendActivated(gained_active, lost_active); 1642 SendActivated(gained_active, lost_active);
1651 } 1643 }
1652 1644
1653 private: 1645 private:
1654 void SendPrimaryDisplayMetrics() { 1646 void SendPrimaryDisplayMetrics() {
1655 const display::Display& primary = 1647 const display::Display primary =
1656 ash::Shell::GetInstance()->display_manager()->GetDisplayForId( 1648 display::Screen::GetScreen()->GetPrimaryDisplay();
1657 display_id_); 1649
1658 SendConfigure_DEPRECATED(primary); 1650 SendConfigure_DEPRECATED(primary);
1659 SendDisplayMetrics(primary); 1651 SendDisplayMetrics(primary);
1660 } 1652 }
1661 1653
1662 void MaybeSendConfigure() { 1654 void MaybeSendConfigure() {
1663 if (send_configure_after_layout_change_) 1655 if (send_configure_after_layout_change_)
1664 SendPrimaryDisplayMetrics(); 1656 SendPrimaryDisplayMetrics();
1665 } 1657 }
1666 1658
1667 void SendDisplayMetrics(const display::Display& display) { 1659 void SendDisplayMetrics(const display::Display& display) {
(...skipping 13 matching lines...) Expand all
1681 1673
1682 wl_client_flush(wl_resource_get_client(remote_shell_resource_)); 1674 wl_client_flush(wl_resource_get_client(remote_shell_resource_));
1683 } 1675 }
1684 1676
1685 void SendConfigure_DEPRECATED(const display::Display& display) { 1677 void SendConfigure_DEPRECATED(const display::Display& display) {
1686 send_configure_after_layout_change_ = false; 1678 send_configure_after_layout_change_ = false;
1687 1679
1688 if (wl_resource_get_version(remote_shell_resource_) >= 9) 1680 if (wl_resource_get_version(remote_shell_resource_) >= 9)
1689 return; 1681 return;
1690 1682
1691 gfx::Insets work_area_insets = display.GetWorkAreaInsets(); 1683 const gfx::Insets& work_area_insets = display.GetWorkAreaInsets();
1692 zwp_remote_shell_v1_send_configure( 1684 zwp_remote_shell_v1_send_configure(
1693 remote_shell_resource_, display.size().width(), display.size().height(), 1685 remote_shell_resource_, display.size().width(), display.size().height(),
1694 work_area_insets.left(), work_area_insets.top(), 1686 work_area_insets.left(), work_area_insets.top(),
1695 work_area_insets.right(), work_area_insets.bottom()); 1687 work_area_insets.right(), work_area_insets.bottom());
1696 wl_client_flush(wl_resource_get_client(remote_shell_resource_)); 1688 wl_client_flush(wl_resource_get_client(remote_shell_resource_));
1697 } 1689 }
1698 1690
1699 void SendLayoutModeChange_DEPRECATED() { 1691 void SendLayoutModeChange_DEPRECATED() {
1700 if (wl_resource_get_version(remote_shell_resource_) < 8) 1692 if (wl_resource_get_version(remote_shell_resource_) < 8)
1701 return; 1693 return;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1733 1725
1734 zwp_remote_shell_v1_send_activated(remote_shell_resource_, 1726 zwp_remote_shell_v1_send_activated(remote_shell_resource_,
1735 gained_active_surface_resource, 1727 gained_active_surface_resource,
1736 lost_active_surface_resource); 1728 lost_active_surface_resource);
1737 wl_client_flush(client); 1729 wl_client_flush(client);
1738 } 1730 }
1739 1731
1740 // The exo display instance. Not owned. 1732 // The exo display instance. Not owned.
1741 Display* const display_; 1733 Display* const display_;
1742 1734
1743 // The identifier associated with the observed display.
1744 const int64_t display_id_;
1745
1746 // The remote shell resource associated with observer. 1735 // The remote shell resource associated with observer.
1747 wl_resource* const remote_shell_resource_; 1736 wl_resource* const remote_shell_resource_;
1748 1737
1749 bool send_configure_after_layout_change_ = false; 1738 bool send_configure_after_layout_change_ = false;
1750 1739
1751 int layout_mode_ = ZWP_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED; 1740 int layout_mode_ = ZWP_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED;
1752 1741
1753 base::WeakPtrFactory<WaylandRemoteShell> weak_ptr_factory_; 1742 base::WeakPtrFactory<WaylandRemoteShell> weak_ptr_factory_;
1754 1743
1755 DISALLOW_COPY_AND_ASSIGN(WaylandRemoteShell); 1744 DISALLOW_COPY_AND_ASSIGN(WaylandRemoteShell);
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1898 const uint32_t remote_shell_version = 10; 1887 const uint32_t remote_shell_version = 10;
1899 1888
1900 void bind_remote_shell(wl_client* client, 1889 void bind_remote_shell(wl_client* client,
1901 void* data, 1890 void* data,
1902 uint32_t version, 1891 uint32_t version,
1903 uint32_t id) { 1892 uint32_t id) {
1904 wl_resource* resource = 1893 wl_resource* resource =
1905 wl_resource_create(client, &zwp_remote_shell_v1_interface, 1894 wl_resource_create(client, &zwp_remote_shell_v1_interface,
1906 std::min(version, remote_shell_version), id); 1895 std::min(version, remote_shell_version), id);
1907 1896
1908 // TODO(reveman): Multi-display support.
1909 const display::Display& display = ash::Shell::GetInstance()
1910 ->display_manager()
1911 ->GetPrimaryDisplayCandidate();
1912
1913 SetImplementation(resource, &remote_shell_implementation, 1897 SetImplementation(resource, &remote_shell_implementation,
1914 base::WrapUnique(new WaylandRemoteShell( 1898 base::WrapUnique(new WaylandRemoteShell(
1915 static_cast<Display*>(data), display.id(), resource))); 1899 static_cast<Display*>(data), resource)));
1916 } 1900 }
1917 1901
1918 //////////////////////////////////////////////////////////////////////////////// 1902 ////////////////////////////////////////////////////////////////////////////////
1919 // zwp_vsync_timing_v1_interface: 1903 // zwp_vsync_timing_v1_interface:
1920 1904
1921 // Implements VSync timing interface by monitoring a compositor for updates 1905 // Implements VSync timing interface by monitoring a compositor for updates
1922 // to VSync parameters. 1906 // to VSync parameters.
1923 class VSyncTiming : public ui::CompositorVSyncManager::Observer { 1907 class VSyncTiming : public ui::CompositorVSyncManager::Observer {
1924 public: 1908 public:
1925 ~VSyncTiming() { vsync_manager_->RemoveObserver(this); } 1909 ~VSyncTiming() { vsync_manager_->RemoveObserver(this); }
(...skipping 1204 matching lines...) Expand 10 before | Expand all | Expand 10 after
3130 DCHECK(event_loop); 3114 DCHECK(event_loop);
3131 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); 3115 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds());
3132 } 3116 }
3133 3117
3134 void Server::Flush() { 3118 void Server::Flush() {
3135 wl_display_flush_clients(wl_display_.get()); 3119 wl_display_flush_clients(wl_display_.get());
3136 } 3120 }
3137 3121
3138 } // namespace wayland 3122 } // namespace wayland
3139 } // namespace exo 3123 } // 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