OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "services/ui/ws/user_display_manager.h" | 5 #include "services/ui/ws/user_display_manager.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "services/ui/display/screen_manager.h" | |
10 #include "services/ui/ws/display.h" | |
11 #include "services/ui/ws/display_manager.h" | |
12 #include "services/ui/ws/user_display_manager_delegate.h" | 9 #include "services/ui/ws/user_display_manager_delegate.h" |
| 10 #include "ui/display/display.h" |
| 11 #include "ui/display/screen.h" |
13 #include "ui/display/types/display_constants.h" | 12 #include "ui/display/types/display_constants.h" |
14 | 13 |
15 namespace ui { | 14 namespace ui { |
16 namespace ws { | 15 namespace ws { |
17 namespace { | 16 namespace { |
18 | 17 |
19 std::vector<mojom::WsDisplayPtr> CloneDisplays( | 18 std::vector<mojom::WsDisplayPtr> CloneDisplays( |
20 const std::vector<mojom::WsDisplayPtr>& input) { | 19 const std::vector<mojom::WsDisplayPtr>& input) { |
21 std::vector<mojom::WsDisplayPtr> result; | 20 std::vector<mojom::WsDisplayPtr> result; |
22 result.reserve(input.size()); | 21 result.reserve(input.size()); |
23 for (const auto& display : input) { | 22 for (const auto& display : input) { |
24 result.push_back(display.Clone()); | 23 result.push_back(display.Clone()); |
25 } | 24 } |
26 return result; | 25 return result; |
27 } | 26 } |
28 | 27 |
| 28 int64_t GetInternalDisplayId() { |
| 29 if (!display::Display::HasInternalDisplay()) |
| 30 return display::kInvalidDisplayId; |
| 31 |
| 32 return display::Display::InternalDisplayId(); |
| 33 } |
| 34 |
29 } // namespace | 35 } // namespace |
30 | 36 |
31 UserDisplayManager::UserDisplayManager(ws::DisplayManager* display_manager, | 37 UserDisplayManager::UserDisplayManager(UserDisplayManagerDelegate* delegate, |
32 UserDisplayManagerDelegate* delegate, | |
33 const UserId& user_id) | 38 const UserId& user_id) |
34 : display_manager_(display_manager), | 39 : delegate_(delegate), |
35 delegate_(delegate), | |
36 user_id_(user_id), | 40 user_id_(user_id), |
37 got_valid_frame_decorations_( | 41 got_valid_frame_decorations_( |
38 delegate->GetFrameDecorationsForUser(user_id, nullptr)) {} | 42 delegate->GetFrameDecorationsForUser(user_id, nullptr)) {} |
39 | 43 |
40 UserDisplayManager::~UserDisplayManager() {} | 44 UserDisplayManager::~UserDisplayManager() {} |
41 | 45 |
42 void UserDisplayManager::OnFrameDecorationValuesChanged() { | 46 void UserDisplayManager::OnFrameDecorationValuesChanged() { |
43 if (!got_valid_frame_decorations_) { | 47 if (!got_valid_frame_decorations_) { |
44 got_valid_frame_decorations_ = true; | 48 got_valid_frame_decorations_ = true; |
45 display_manager_observers_.ForAllPtrs([this]( | 49 display_manager_observers_.ForAllPtrs([this]( |
46 mojom::DisplayManagerObserver* observer) { CallOnDisplays(observer); }); | 50 mojom::DisplayManagerObserver* observer) { CallOnDisplays(observer); }); |
47 return; | 51 return; |
48 } | 52 } |
49 | 53 |
50 std::vector<mojom::WsDisplayPtr> displays = GetAllDisplays(); | 54 std::vector<mojom::WsDisplayPtr> displays = GetAllDisplays(); |
51 display_manager_observers_.ForAllPtrs( | 55 display_manager_observers_.ForAllPtrs( |
52 [&displays](mojom::DisplayManagerObserver* observer) { | 56 [&displays](mojom::DisplayManagerObserver* observer) { |
53 observer->OnDisplaysChanged(CloneDisplays(displays)); | 57 observer->OnDisplaysChanged(CloneDisplays(displays)); |
54 }); | 58 }); |
55 } | 59 } |
56 | 60 |
57 void UserDisplayManager::AddDisplayManagerBinding( | 61 void UserDisplayManager::AddDisplayManagerBinding( |
58 mojo::InterfaceRequest<mojom::DisplayManager> request) { | 62 mojo::InterfaceRequest<mojom::DisplayManager> request) { |
59 display_manager_bindings_.AddBinding(this, std::move(request)); | 63 display_manager_bindings_.AddBinding(this, std::move(request)); |
60 } | 64 } |
61 | 65 |
62 void UserDisplayManager::OnDisplayUpdate(Display* display) { | 66 void UserDisplayManager::OnDisplayUpdate(const display::Display& display) { |
63 if (!got_valid_frame_decorations_) | 67 if (!got_valid_frame_decorations_) |
64 return; | 68 return; |
65 | 69 |
66 std::vector<mojom::WsDisplayPtr> displays(1); | 70 std::vector<mojom::WsDisplayPtr> displays(1); |
67 displays[0] = GetWsDisplayPtr(*display); | 71 displays[0] = ToWsDisplayPtr(display); |
68 | 72 |
69 display_manager_observers_.ForAllPtrs( | 73 display_manager_observers_.ForAllPtrs( |
70 [&displays](mojom::DisplayManagerObserver* observer) { | 74 [&displays](mojom::DisplayManagerObserver* observer) { |
71 observer->OnDisplaysChanged(CloneDisplays(displays)); | 75 observer->OnDisplaysChanged(CloneDisplays(displays)); |
72 }); | 76 }); |
73 } | 77 } |
74 | 78 |
75 void UserDisplayManager::OnWillDestroyDisplay(Display* display) { | 79 void UserDisplayManager::OnWillDestroyDisplay(int64_t display_id) { |
76 if (!got_valid_frame_decorations_) | 80 if (!got_valid_frame_decorations_) |
77 return; | 81 return; |
78 | 82 |
79 display_manager_observers_.ForAllPtrs( | 83 display_manager_observers_.ForAllPtrs( |
80 [&display](mojom::DisplayManagerObserver* observer) { | 84 [display_id](mojom::DisplayManagerObserver* observer) { |
81 observer->OnDisplayRemoved(display->GetId()); | 85 observer->OnDisplayRemoved(display_id); |
82 }); | 86 }); |
83 } | 87 } |
84 | 88 |
85 void UserDisplayManager::OnPrimaryDisplayChanged(int64_t primary_display_id) { | 89 void UserDisplayManager::OnPrimaryDisplayChanged(int64_t primary_display_id) { |
86 if (!got_valid_frame_decorations_) | 90 if (!got_valid_frame_decorations_) |
87 return; | 91 return; |
88 | 92 |
89 display_manager_observers_.ForAllPtrs( | 93 display_manager_observers_.ForAllPtrs( |
90 [primary_display_id](mojom::DisplayManagerObserver* observer) { | 94 [primary_display_id](mojom::DisplayManagerObserver* observer) { |
91 observer->OnPrimaryDisplayChanged(primary_display_id); | 95 observer->OnPrimaryDisplayChanged(primary_display_id); |
(...skipping 11 matching lines...) Expand all Loading... |
103 mojom::DisplayManagerObserver* observer) { | 107 mojom::DisplayManagerObserver* observer) { |
104 // Many clients key off the frame decorations to size widgets. Wait for frame | 108 // Many clients key off the frame decorations to size widgets. Wait for frame |
105 // decorations before notifying so that we don't have to worry about clients | 109 // decorations before notifying so that we don't have to worry about clients |
106 // resizing appropriately. | 110 // resizing appropriately. |
107 if (!got_valid_frame_decorations_) | 111 if (!got_valid_frame_decorations_) |
108 return; | 112 return; |
109 | 113 |
110 CallOnDisplays(observer); | 114 CallOnDisplays(observer); |
111 } | 115 } |
112 | 116 |
113 mojom::WsDisplayPtr UserDisplayManager::GetWsDisplayPtr( | 117 mojom::WsDisplayPtr UserDisplayManager::ToWsDisplayPtr( |
114 const Display& display) { | 118 const display::Display& display) { |
115 mojom::WsDisplayPtr ws_display = mojom::WsDisplay::New(); | 119 mojom::WsDisplayPtr ws_display = mojom::WsDisplay::New(); |
116 ws_display->display = display.ToDisplay(); | 120 ws_display->display = display; |
117 delegate_->GetFrameDecorationsForUser(user_id_, | 121 delegate_->GetFrameDecorationsForUser(user_id_, |
118 &ws_display->frame_decoration_values); | 122 &ws_display->frame_decoration_values); |
119 return ws_display; | 123 return ws_display; |
120 } | 124 } |
121 | 125 |
122 std::vector<mojom::WsDisplayPtr> UserDisplayManager::GetAllDisplays() { | 126 std::vector<mojom::WsDisplayPtr> UserDisplayManager::GetAllDisplays() { |
123 const auto& displays = display_manager_->displays(); | 127 const auto& displays = display::Screen::GetScreen()->GetAllDisplays(); |
124 std::vector<mojom::WsDisplayPtr> display_ptrs; | |
125 display_ptrs.reserve(displays.size()); | |
126 | 128 |
127 // TODO(sky): need ordering! | 129 std::vector<mojom::WsDisplayPtr> ws_display; |
128 for (Display* display : displays) { | 130 ws_display.reserve(displays.size()); |
129 display_ptrs.push_back(GetWsDisplayPtr(*display)); | |
130 } | |
131 | 131 |
132 return display_ptrs; | 132 for (const auto& display : displays) |
| 133 ws_display.push_back(ToWsDisplayPtr(display)); |
| 134 |
| 135 return ws_display; |
133 } | 136 } |
134 | 137 |
135 void UserDisplayManager::CallOnDisplays( | 138 void UserDisplayManager::CallOnDisplays( |
136 mojom::DisplayManagerObserver* observer) { | 139 mojom::DisplayManagerObserver* observer) { |
137 // TODO(kylechar): Pass internal display id to clients here. | 140 observer->OnDisplays(GetAllDisplays(), |
138 observer->OnDisplays( | 141 display::Screen::GetScreen()->GetPrimaryDisplay().id(), |
139 GetAllDisplays(), | 142 GetInternalDisplayId()); |
140 display::ScreenManager::GetInstance()->GetPrimaryDisplayId(), | |
141 display::kInvalidDisplayId); | |
142 } | 143 } |
143 | 144 |
144 } // namespace ws | 145 } // namespace ws |
145 } // namespace ui | 146 } // namespace ui |
OLD | NEW |