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