| 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/display_manager.h" | 5 #include "services/ui/ws/display_manager.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "services/ui/display/platform_screen.h" |
| 8 #include "services/ui/ws/display.h" | 9 #include "services/ui/ws/display.h" |
| 9 #include "services/ui/ws/display_manager_delegate.h" | 10 #include "services/ui/ws/display_binding.h" |
| 10 #include "services/ui/ws/event_dispatcher.h" | 11 #include "services/ui/ws/event_dispatcher.h" |
| 12 #include "services/ui/ws/platform_display_init_params.h" |
| 11 #include "services/ui/ws/server_window.h" | 13 #include "services/ui/ws/server_window.h" |
| 12 #include "services/ui/ws/user_display_manager.h" | 14 #include "services/ui/ws/user_display_manager.h" |
| 15 #include "services/ui/ws/user_display_manager_delegate.h" |
| 13 #include "services/ui/ws/user_id_tracker.h" | 16 #include "services/ui/ws/user_id_tracker.h" |
| 14 #include "services/ui/ws/window_manager_state.h" | 17 #include "services/ui/ws/window_manager_state.h" |
| 18 #include "services/ui/ws/window_server_delegate.h" |
| 15 | 19 |
| 16 namespace ui { | 20 namespace ui { |
| 17 namespace ws { | 21 namespace ws { |
| 18 | 22 |
| 19 DisplayManager::DisplayManager(DisplayManagerDelegate* delegate, | 23 DisplayManager::DisplayManager(WindowServer* window_server, |
| 20 UserIdTracker* user_id_tracker) | 24 UserIdTracker* user_id_tracker) |
| 21 // |next_root_id_| is used as the lower bits, so that starting at 0 is | 25 // |next_root_id_| is used as the lower bits, so that starting at 0 is |
| 22 // fine. |next_display_id_| is used by itself, so we start at 1 to reserve | 26 // fine. |next_display_id_| is used by itself, so we start at 1 to reserve |
| 23 // 0 as invalid. | 27 // 0 as invalid. |
| 24 : delegate_(delegate), | 28 : window_server_(window_server), |
| 25 user_id_tracker_(user_id_tracker), | 29 user_id_tracker_(user_id_tracker), |
| 26 next_root_id_(0) { | 30 next_root_id_(0) { |
| 27 user_id_tracker_->AddObserver(this); | 31 user_id_tracker_->AddObserver(this); |
| 28 } | 32 } |
| 29 | 33 |
| 30 DisplayManager::~DisplayManager() { | 34 DisplayManager::~DisplayManager() { |
| 31 user_id_tracker_->RemoveObserver(this); | 35 user_id_tracker_->RemoveObserver(this); |
| 32 DestroyAllDisplays(); | 36 DestroyAllDisplays(); |
| 33 } | 37 } |
| 34 | 38 |
| 35 UserDisplayManager* DisplayManager::GetUserDisplayManager( | 39 UserDisplayManager* DisplayManager::GetUserDisplayManager( |
| 36 const UserId& user_id) { | 40 const UserId& user_id) { |
| 37 if (!user_display_managers_.count(user_id)) { | 41 if (!user_display_managers_.count(user_id)) { |
| 38 user_display_managers_[user_id] = | 42 user_display_managers_[user_id] = |
| 39 base::MakeUnique<UserDisplayManager>(this, delegate_, user_id); | 43 base::MakeUnique<UserDisplayManager>(this, window_server_, user_id); |
| 40 } | 44 } |
| 41 return user_display_managers_[user_id].get(); | 45 return user_display_managers_[user_id].get(); |
| 42 } | 46 } |
| 43 | 47 |
| 44 void DisplayManager::AddDisplay(Display* display) { | 48 void DisplayManager::AddDisplay(Display* display) { |
| 45 DCHECK_EQ(0u, pending_displays_.count(display)); | 49 DCHECK_EQ(0u, pending_displays_.count(display)); |
| 46 pending_displays_.insert(display); | 50 pending_displays_.insert(display); |
| 47 } | 51 } |
| 48 | 52 |
| 49 void DisplayManager::DestroyDisplay(Display* display) { | 53 void DisplayManager::DestroyDisplay(Display* display) { |
| 50 if (pending_displays_.count(display)) { | 54 if (pending_displays_.count(display)) { |
| 51 pending_displays_.erase(display); | 55 pending_displays_.erase(display); |
| 52 } else { | 56 } else { |
| 53 for (const auto& pair : user_display_managers_) | 57 for (const auto& pair : user_display_managers_) |
| 54 pair.second->OnWillDestroyDisplay(display); | 58 pair.second->OnWillDestroyDisplay(display); |
| 55 | 59 |
| 56 DCHECK(displays_.count(display)); | 60 DCHECK(displays_.count(display)); |
| 57 displays_.erase(display); | 61 displays_.erase(display); |
| 58 } | 62 } |
| 59 delete display; | 63 delete display; |
| 60 | 64 |
| 61 // If we have no more roots left, let the app know so it can terminate. | 65 // If we have no more roots left, let the app know so it can terminate. |
| 62 // TODO(sky): move to delegate/observer. | 66 // TODO(sky): move to delegate/observer. |
| 63 if (displays_.empty() && pending_displays_.empty()) | 67 if (displays_.empty() && pending_displays_.empty()) |
| 64 delegate_->OnNoMoreDisplays(); | 68 window_server_->OnNoMoreDisplays(); |
| 65 } | 69 } |
| 66 | 70 |
| 67 void DisplayManager::DestroyAllDisplays() { | 71 void DisplayManager::DestroyAllDisplays() { |
| 68 while (!pending_displays_.empty()) | 72 while (!pending_displays_.empty()) |
| 69 DestroyDisplay(*pending_displays_.begin()); | 73 DestroyDisplay(*pending_displays_.begin()); |
| 70 DCHECK(pending_displays_.empty()); | 74 DCHECK(pending_displays_.empty()); |
| 71 | 75 |
| 72 while (!displays_.empty()) | 76 while (!displays_.empty()) |
| 73 DestroyDisplay(*displays_.begin()); | 77 DestroyDisplay(*displays_.begin()); |
| 74 DCHECK(displays_.empty()); | 78 DCHECK(displays_.empty()); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 return RootWindowId(id); | 132 return RootWindowId(id); |
| 129 } | 133 } |
| 130 | 134 |
| 131 void DisplayManager::OnDisplayAcceleratedWidgetAvailable(Display* display) { | 135 void DisplayManager::OnDisplayAcceleratedWidgetAvailable(Display* display) { |
| 132 DCHECK_NE(0u, pending_displays_.count(display)); | 136 DCHECK_NE(0u, pending_displays_.count(display)); |
| 133 DCHECK_EQ(0u, displays_.count(display)); | 137 DCHECK_EQ(0u, displays_.count(display)); |
| 134 const bool is_first_display = displays_.empty(); | 138 const bool is_first_display = displays_.empty(); |
| 135 displays_.insert(display); | 139 displays_.insert(display); |
| 136 pending_displays_.erase(display); | 140 pending_displays_.erase(display); |
| 137 if (is_first_display) | 141 if (is_first_display) |
| 138 delegate_->OnFirstDisplayReady(); | 142 window_server_->OnFirstDisplayReady(); |
| 139 } | 143 } |
| 140 | 144 |
| 141 void DisplayManager::OnActiveUserIdChanged(const UserId& previously_active_id, | 145 void DisplayManager::OnActiveUserIdChanged(const UserId& previously_active_id, |
| 142 const UserId& active_id) { | 146 const UserId& active_id) { |
| 143 WindowManagerState* previous_window_manager_state = | 147 WindowManagerState* previous_window_manager_state = |
| 144 delegate_->GetWindowManagerStateForUser(previously_active_id); | 148 window_server_->GetWindowManagerStateForUser(previously_active_id); |
| 145 gfx::Point mouse_location_on_screen; | 149 gfx::Point mouse_location_on_screen; |
| 146 if (previous_window_manager_state) { | 150 if (previous_window_manager_state) { |
| 147 mouse_location_on_screen = previous_window_manager_state->event_dispatcher() | 151 mouse_location_on_screen = previous_window_manager_state->event_dispatcher() |
| 148 ->mouse_pointer_last_location(); | 152 ->mouse_pointer_last_location(); |
| 149 previous_window_manager_state->Deactivate(); | 153 previous_window_manager_state->Deactivate(); |
| 150 } | 154 } |
| 151 | 155 |
| 152 WindowManagerState* current_window_manager_state = | 156 WindowManagerState* current_window_manager_state = |
| 153 delegate_->GetWindowManagerStateForUser(active_id); | 157 window_server_->GetWindowManagerStateForUser(active_id); |
| 154 if (current_window_manager_state) | 158 if (current_window_manager_state) |
| 155 current_window_manager_state->Activate(mouse_location_on_screen); | 159 current_window_manager_state->Activate(mouse_location_on_screen); |
| 156 } | 160 } |
| 157 | 161 |
| 162 void DisplayManager::OnDisplayAdded(display::PlatformScreen* platform_screen, |
| 163 int64_t id, |
| 164 const gfx::Rect& bounds) { |
| 165 PlatformDisplayInitParams params; |
| 166 params.display_bounds = bounds; |
| 167 params.display_id = id; |
| 168 params.platform_screen = platform_screen; |
| 169 params.surfaces_state = window_server_->GetSurfacesState(); |
| 170 |
| 171 ws::Display* display = new ws::Display(window_server_, params); |
| 172 display->Init(nullptr); |
| 173 |
| 174 window_server_->delegate()->UpdateTouchTransforms(); |
| 175 } |
| 176 |
| 177 void DisplayManager::OnDisplayRemoved(int64_t id) { |
| 178 // TODO(kylechar): Implement. |
| 179 NOTREACHED(); |
| 180 } |
| 181 |
| 182 void DisplayManager::OnDisplayModified(int64_t id, const gfx::Rect& bounds) { |
| 183 // TODO(kylechar): Implement. |
| 184 NOTREACHED(); |
| 185 } |
| 186 |
| 158 } // namespace ws | 187 } // namespace ws |
| 159 } // namespace ui | 188 } // namespace ui |
| OLD | NEW |