| 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_manager_delegate.h" |
| 10 #include "services/ui/ws/event_dispatcher.h" | 10 #include "services/ui/ws/event_dispatcher.h" |
| 11 #include "services/ui/ws/server_window.h" | 11 #include "services/ui/ws/server_window.h" |
| 12 #include "services/ui/ws/user_display_manager.h" | 12 #include "services/ui/ws/user_display_manager.h" |
| 13 #include "services/ui/ws/user_id_tracker.h" | 13 #include "services/ui/ws/user_id_tracker.h" |
| 14 #include "services/ui/ws/window_manager_state.h" | 14 #include "services/ui/ws/window_manager_state.h" |
| 15 | 15 |
| 16 namespace ui { | 16 namespace ui { |
| 17 namespace ws { | 17 namespace ws { |
| 18 | 18 |
| 19 DisplayManager::DisplayManager(DisplayManagerDelegate* delegate, | 19 DisplayManager::DisplayManager(DisplayManagerDelegate* delegate, |
| 20 UserIdTracker* user_id_tracker) | 20 UserIdTracker* user_id_tracker) |
| 21 // |next_root_id_| is used as the lower bits, so that starting at 0 is | 21 // |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 | 22 // fine. |next_display_id_| is used by itself, so we start at 1 to reserve |
| 23 // 0 as invalid. | 23 // 0 as invalid. |
| 24 : delegate_(delegate), | 24 : delegate_(delegate), |
| 25 user_id_tracker_(user_id_tracker), | 25 user_id_tracker_(user_id_tracker), |
| 26 next_root_id_(0), | 26 next_root_id_(0) { |
| 27 next_display_id_(1) { | |
| 28 user_id_tracker_->AddObserver(this); | 27 user_id_tracker_->AddObserver(this); |
| 29 } | 28 } |
| 30 | 29 |
| 31 DisplayManager::~DisplayManager() { | 30 DisplayManager::~DisplayManager() { |
| 32 user_id_tracker_->RemoveObserver(this); | 31 user_id_tracker_->RemoveObserver(this); |
| 33 DestroyAllDisplays(); | 32 DestroyAllDisplays(); |
| 34 } | 33 } |
| 35 | 34 |
| 36 UserDisplayManager* DisplayManager::GetUserDisplayManager( | 35 UserDisplayManager* DisplayManager::GetUserDisplayManager( |
| 37 const UserId& user_id) { | 36 const UserId& user_id) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 window)); | 121 window)); |
| 123 } | 122 } |
| 124 | 123 |
| 125 WindowId DisplayManager::GetAndAdvanceNextRootId() { | 124 WindowId DisplayManager::GetAndAdvanceNextRootId() { |
| 126 // TODO(sky): handle wrapping! | 125 // TODO(sky): handle wrapping! |
| 127 const uint16_t id = next_root_id_++; | 126 const uint16_t id = next_root_id_++; |
| 128 DCHECK_LT(id, next_root_id_); | 127 DCHECK_LT(id, next_root_id_); |
| 129 return RootWindowId(id); | 128 return RootWindowId(id); |
| 130 } | 129 } |
| 131 | 130 |
| 132 uint32_t DisplayManager::GetAndAdvanceNextDisplayId() { | |
| 133 // TODO(sky): handle wrapping! | |
| 134 const uint32_t id = next_display_id_++; | |
| 135 DCHECK_LT(id, next_display_id_); | |
| 136 return id; | |
| 137 } | |
| 138 | |
| 139 void DisplayManager::OnDisplayAcceleratedWidgetAvailable(Display* display) { | 131 void DisplayManager::OnDisplayAcceleratedWidgetAvailable(Display* display) { |
| 140 DCHECK_NE(0u, pending_displays_.count(display)); | 132 DCHECK_NE(0u, pending_displays_.count(display)); |
| 141 DCHECK_EQ(0u, displays_.count(display)); | 133 DCHECK_EQ(0u, displays_.count(display)); |
| 142 const bool is_first_display = displays_.empty(); | 134 const bool is_first_display = displays_.empty(); |
| 143 displays_.insert(display); | 135 displays_.insert(display); |
| 144 pending_displays_.erase(display); | 136 pending_displays_.erase(display); |
| 145 if (is_first_display) | 137 if (is_first_display) |
| 146 delegate_->OnFirstDisplayReady(); | 138 delegate_->OnFirstDisplayReady(); |
| 147 } | 139 } |
| 148 | 140 |
| 149 void DisplayManager::OnActiveUserIdChanged(const UserId& previously_active_id, | 141 void DisplayManager::OnActiveUserIdChanged(const UserId& previously_active_id, |
| 150 const UserId& active_id) { | 142 const UserId& active_id) { |
| 151 WindowManagerState* previous_window_manager_state = | 143 WindowManagerState* previous_window_manager_state = |
| 152 delegate_->GetWindowManagerStateForUser(previously_active_id); | 144 delegate_->GetWindowManagerStateForUser(previously_active_id); |
| 153 gfx::Point mouse_location_on_screen; | 145 gfx::Point mouse_location_on_screen; |
| 154 if (previous_window_manager_state) { | 146 if (previous_window_manager_state) { |
| 155 mouse_location_on_screen = previous_window_manager_state->event_dispatcher() | 147 mouse_location_on_screen = previous_window_manager_state->event_dispatcher() |
| 156 ->mouse_pointer_last_location(); | 148 ->mouse_pointer_last_location(); |
| 157 previous_window_manager_state->Deactivate(); | 149 previous_window_manager_state->Deactivate(); |
| 158 } | 150 } |
| 159 | 151 |
| 160 WindowManagerState* current_window_manager_state = | 152 WindowManagerState* current_window_manager_state = |
| 161 delegate_->GetWindowManagerStateForUser(active_id); | 153 delegate_->GetWindowManagerStateForUser(active_id); |
| 162 if (current_window_manager_state) | 154 if (current_window_manager_state) |
| 163 current_window_manager_state->Activate(mouse_location_on_screen); | 155 current_window_manager_state->Activate(mouse_location_on_screen); |
| 164 } | 156 } |
| 165 | 157 |
| 166 } // namespace ws | 158 } // namespace ws |
| 167 } // namespace ui | 159 } // namespace ui |
| OLD | NEW |