| 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 "components/mus/ws/display_manager.h" | 5 #include "components/mus/ws/display_manager.h" |
| 6 | 6 |
| 7 #include "components/mus/ws/display.h" | 7 #include "components/mus/ws/display.h" |
| 8 #include "components/mus/ws/display_manager_delegate.h" | 8 #include "components/mus/ws/display_manager_delegate.h" |
| 9 #include "components/mus/ws/server_window.h" | 9 #include "components/mus/ws/server_window.h" |
| 10 #include "components/mus/ws/user_display_manager.h" |
| 10 | 11 |
| 11 namespace mus { | 12 namespace mus { |
| 12 namespace ws { | 13 namespace ws { |
| 13 | 14 |
| 14 DisplayManager::DisplayManager(DisplayManagerDelegate* delegate) | 15 DisplayManager::DisplayManager(DisplayManagerDelegate* delegate) |
| 15 : delegate_(delegate), next_root_id_(0) {} | 16 // |next_root_id_| is used as the lower bits, so that starting at 0 is |
| 17 // fine. |next_display_id_| is used by itself, so we start at 1 to reserve |
| 18 // 0 as invalid. |
| 19 : delegate_(delegate), |
| 20 next_root_id_(0), |
| 21 next_display_id_(1) {} |
| 16 | 22 |
| 17 DisplayManager::~DisplayManager() { | 23 DisplayManager::~DisplayManager() { |
| 18 DestroyAllDisplays(); | 24 DestroyAllDisplays(); |
| 19 } | 25 } |
| 20 | 26 |
| 27 UserDisplayManager* DisplayManager::GetUserDisplayManager( |
| 28 const UserId& user_id) { |
| 29 if (!user_display_managers_.count(user_id)) { |
| 30 user_display_managers_[user_id] = |
| 31 make_scoped_ptr(new UserDisplayManager(this, user_id)); |
| 32 } |
| 33 return user_display_managers_[user_id].get(); |
| 34 } |
| 35 |
| 21 void DisplayManager::AddDisplay(Display* display) { | 36 void DisplayManager::AddDisplay(Display* display) { |
| 22 DCHECK_EQ(0u, pending_displays_.count(display)); | 37 DCHECK_EQ(0u, pending_displays_.count(display)); |
| 23 pending_displays_.insert(display); | 38 pending_displays_.insert(display); |
| 24 } | 39 } |
| 25 | 40 |
| 26 void DisplayManager::DestroyDisplay(Display* display) { | 41 void DisplayManager::DestroyDisplay(Display* display) { |
| 27 delegate_->OnWillDestroyDisplay(display); | 42 delegate_->OnWillDestroyDisplay(display); |
| 28 | 43 |
| 29 if (pending_displays_.count(display)) { | 44 if (pending_displays_.count(display)) { |
| 30 pending_displays_.erase(display); | 45 pending_displays_.erase(display); |
| 31 } else { | 46 } else { |
| 47 for (const auto& pair : user_display_managers_) |
| 48 pair.second->OnWillDestroyDisplay(display); |
| 49 |
| 32 DCHECK(displays_.count(display)); | 50 DCHECK(displays_.count(display)); |
| 33 displays_.erase(display); | 51 displays_.erase(display); |
| 34 } | 52 } |
| 35 delete display; | 53 delete display; |
| 36 | 54 |
| 37 // If we have no more roots left, let the app know so it can terminate. | 55 // If we have no more roots left, let the app know so it can terminate. |
| 38 // TODO(sky): move to delegate/observer. | 56 // TODO(sky): move to delegate/observer. |
| 39 if (!displays_.size() && !pending_displays_.size()) | 57 if (!displays_.size() && !pending_displays_.size()) |
| 40 delegate_->OnNoMoreDisplays(); | 58 delegate_->OnNoMoreDisplays(); |
| 41 } | 59 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 return result; | 125 return result; |
| 108 } | 126 } |
| 109 | 127 |
| 110 WindowId DisplayManager::GetAndAdvanceNextRootId() { | 128 WindowId DisplayManager::GetAndAdvanceNextRootId() { |
| 111 // TODO(sky): handle wrapping! | 129 // TODO(sky): handle wrapping! |
| 112 const uint16_t id = next_root_id_++; | 130 const uint16_t id = next_root_id_++; |
| 113 DCHECK_LT(id, next_root_id_); | 131 DCHECK_LT(id, next_root_id_); |
| 114 return RootWindowId(id); | 132 return RootWindowId(id); |
| 115 } | 133 } |
| 116 | 134 |
| 135 uint32_t DisplayManager::GetAndAdvanceNextDisplayId() { |
| 136 // TODO(sky): handle wrapping! |
| 137 const uint32_t id = next_display_id_++; |
| 138 DCHECK_LT(id, next_display_id_); |
| 139 return id; |
| 140 } |
| 141 |
| 117 void DisplayManager::OnDisplayAcceleratedWidgetAvailable(Display* display) { | 142 void DisplayManager::OnDisplayAcceleratedWidgetAvailable(Display* display) { |
| 118 DCHECK_NE(0u, pending_displays_.count(display)); | 143 DCHECK_NE(0u, pending_displays_.count(display)); |
| 119 DCHECK_EQ(0u, displays_.count(display)); | 144 DCHECK_EQ(0u, displays_.count(display)); |
| 120 const bool is_first_display = displays_.empty(); | 145 const bool is_first_display = displays_.empty(); |
| 121 displays_.insert(display); | 146 displays_.insert(display); |
| 122 pending_displays_.erase(display); | 147 pending_displays_.erase(display); |
| 123 if (is_first_display) | 148 if (is_first_display) |
| 124 delegate_->OnFirstDisplayReady(); | 149 delegate_->OnFirstDisplayReady(); |
| 125 } | 150 } |
| 126 | 151 |
| 127 } // namespace ws | 152 } // namespace ws |
| 128 } // namespace mus | 153 } // namespace mus |
| OLD | NEW |