| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 DisplayManager::~DisplayManager() { | 39 DisplayManager::~DisplayManager() { |
| 40 user_id_tracker_->RemoveObserver(this); | 40 user_id_tracker_->RemoveObserver(this); |
| 41 DestroyAllDisplays(); | 41 DestroyAllDisplays(); |
| 42 } | 42 } |
| 43 | 43 |
| 44 UserDisplayManager* DisplayManager::GetUserDisplayManager( | 44 UserDisplayManager* DisplayManager::GetUserDisplayManager( |
| 45 const UserId& user_id) { | 45 const UserId& user_id) { |
| 46 if (!user_display_managers_.count(user_id)) { | 46 if (!user_display_managers_.count(user_id)) { |
| 47 user_display_managers_[user_id] = | 47 user_display_managers_[user_id] = |
| 48 base::MakeUnique<UserDisplayManager>(this, window_server_, user_id); | 48 base::MakeUnique<UserDisplayManager>(window_server_, user_id); |
| 49 } | 49 } |
| 50 return user_display_managers_[user_id].get(); | 50 return user_display_managers_[user_id].get(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 CursorLocationManager* DisplayManager::GetCursorLocationManager( | 53 CursorLocationManager* DisplayManager::GetCursorLocationManager( |
| 54 const UserId& user_id) { | 54 const UserId& user_id) { |
| 55 if (!cursor_location_managers_.count(user_id)) { | 55 if (!cursor_location_managers_.count(user_id)) { |
| 56 cursor_location_managers_[user_id] = | 56 cursor_location_managers_[user_id] = |
| 57 base::MakeUnique<CursorLocationManager>(); | 57 base::MakeUnique<CursorLocationManager>(); |
| 58 } | 58 } |
| 59 return cursor_location_managers_[user_id].get(); | 59 return cursor_location_managers_[user_id].get(); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void DisplayManager::AddDisplay(Display* display) { | 62 void DisplayManager::AddDisplay(Display* display) { |
| 63 DCHECK_EQ(0u, pending_displays_.count(display)); | 63 DCHECK_EQ(0u, pending_displays_.count(display)); |
| 64 pending_displays_.insert(display); | 64 pending_displays_.insert(display); |
| 65 } | 65 } |
| 66 | 66 |
| 67 void DisplayManager::DestroyDisplay(Display* display) { | 67 void DisplayManager::DestroyDisplay(Display* display) { |
| 68 if (pending_displays_.count(display)) { | 68 if (pending_displays_.count(display)) { |
| 69 pending_displays_.erase(display); | 69 pending_displays_.erase(display); |
| 70 } else { | 70 } else { |
| 71 for (const auto& pair : user_display_managers_) | 71 for (const auto& pair : user_display_managers_) |
| 72 pair.second->OnWillDestroyDisplay(display); | 72 pair.second->OnWillDestroyDisplay(display->GetId()); |
| 73 | 73 |
| 74 DCHECK(displays_.count(display)); | 74 DCHECK(displays_.count(display)); |
| 75 displays_.erase(display); | 75 displays_.erase(display); |
| 76 window_server_->OnDisplayDestroyed(display); | 76 window_server_->OnDisplayDestroyed(display); |
| 77 } | 77 } |
| 78 delete display; | 78 delete display; |
| 79 | 79 |
| 80 // If we have no more roots left, let the app know so it can terminate. | 80 // If we have no more roots left, let the app know so it can terminate. |
| 81 // TODO(sky): move to delegate/observer. | 81 // TODO(sky): move to delegate/observer. |
| 82 if (displays_.empty() && pending_displays_.empty()) | 82 if (displays_.empty() && pending_displays_.empty()) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 93 DCHECK(displays_.empty()); | 93 DCHECK(displays_.empty()); |
| 94 } | 94 } |
| 95 | 95 |
| 96 std::set<const Display*> DisplayManager::displays() const { | 96 std::set<const Display*> DisplayManager::displays() const { |
| 97 std::set<const Display*> ret_value(displays_.begin(), displays_.end()); | 97 std::set<const Display*> ret_value(displays_.begin(), displays_.end()); |
| 98 return ret_value; | 98 return ret_value; |
| 99 } | 99 } |
| 100 | 100 |
| 101 void DisplayManager::OnDisplayUpdate(Display* display) { | 101 void DisplayManager::OnDisplayUpdate(Display* display) { |
| 102 for (const auto& pair : user_display_managers_) | 102 for (const auto& pair : user_display_managers_) |
| 103 pair.second->OnDisplayUpdate(display); | 103 pair.second->OnDisplayUpdate(display->ToDisplay()); |
| 104 } | 104 } |
| 105 | 105 |
| 106 Display* DisplayManager::GetDisplayContaining(const ServerWindow* window) { | 106 Display* DisplayManager::GetDisplayContaining(const ServerWindow* window) { |
| 107 return const_cast<Display*>( | 107 return const_cast<Display*>( |
| 108 static_cast<const DisplayManager*>(this)->GetDisplayContaining(window)); | 108 static_cast<const DisplayManager*>(this)->GetDisplayContaining(window)); |
| 109 } | 109 } |
| 110 | 110 |
| 111 const Display* DisplayManager::GetDisplayContaining( | 111 const Display* DisplayManager::GetDisplayContaining( |
| 112 const ServerWindow* window) const { | 112 const ServerWindow* window) const { |
| 113 while (window && window->parent()) | 113 while (window && window->parent()) |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 void DisplayManager::OnPrimaryDisplayChanged(int64_t primary_display_id) { | 227 void DisplayManager::OnPrimaryDisplayChanged(int64_t primary_display_id) { |
| 228 // TODO(kylechar): Send IPCs to WM clients first. | 228 // TODO(kylechar): Send IPCs to WM clients first. |
| 229 | 229 |
| 230 // Send IPCs to any DisplayManagerObservers. | 230 // Send IPCs to any DisplayManagerObservers. |
| 231 for (const auto& pair : user_display_managers_) | 231 for (const auto& pair : user_display_managers_) |
| 232 pair.second->OnPrimaryDisplayChanged(primary_display_id); | 232 pair.second->OnPrimaryDisplayChanged(primary_display_id); |
| 233 } | 233 } |
| 234 | 234 |
| 235 } // namespace ws | 235 } // namespace ws |
| 236 } // namespace ui | 236 } // namespace ui |
| OLD | NEW |