| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 pending_displays_.insert(display); | 77 pending_displays_.insert(display); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void DisplayManager::AddDisplayForWindowManager( | 80 void DisplayManager::AddDisplayForWindowManager( |
| 81 const display::Display& display, | 81 const display::Display& display, |
| 82 const display::ViewportMetrics& metrics) { | 82 const display::ViewportMetrics& metrics) { |
| 83 OnDisplayAdded(display, metrics); | 83 OnDisplayAdded(display, metrics); |
| 84 } | 84 } |
| 85 | 85 |
| 86 void DisplayManager::DestroyDisplay(Display* display) { | 86 void DisplayManager::DestroyDisplay(Display* display) { |
| 87 if (pending_displays_.count(display)) { | 87 const bool is_pending = pending_displays_.count(display) > 0; |
| 88 if (is_pending) { |
| 88 pending_displays_.erase(display); | 89 pending_displays_.erase(display); |
| 89 } else { | 90 } else { |
| 90 for (const auto& pair : user_display_managers_) | |
| 91 pair.second->OnWillDestroyDisplay(display->GetId()); | |
| 92 | |
| 93 DCHECK(displays_.count(display)); | 91 DCHECK(displays_.count(display)); |
| 94 displays_.erase(display); | 92 displays_.erase(display); |
| 95 window_server_->OnDisplayDestroyed(display); | 93 window_server_->OnDisplayDestroyed(display); |
| 96 } | 94 } |
| 95 const int64_t display_id = display->GetId(); |
| 97 delete display; | 96 delete display; |
| 98 | 97 |
| 99 // If we have no more roots left, let the app know so it can terminate. | 98 // If we have no more roots left, let the app know so it can terminate. |
| 100 // TODO(sky): move to delegate/observer. | 99 // TODO(sky): move to delegate/observer. |
| 101 if (displays_.empty() && pending_displays_.empty()) | 100 if (displays_.empty() && pending_displays_.empty()) { |
| 102 window_server_->OnNoMoreDisplays(); | 101 window_server_->OnNoMoreDisplays(); |
| 102 } else { |
| 103 for (const auto& pair : user_display_managers_) |
| 104 pair.second->OnDisplayDestroyed(display_id); |
| 105 } |
| 103 } | 106 } |
| 104 | 107 |
| 105 void DisplayManager::DestroyAllDisplays() { | 108 void DisplayManager::DestroyAllDisplays() { |
| 106 while (!pending_displays_.empty()) | 109 while (!pending_displays_.empty()) |
| 107 DestroyDisplay(*pending_displays_.begin()); | 110 DestroyDisplay(*pending_displays_.begin()); |
| 108 DCHECK(pending_displays_.empty()); | 111 DCHECK(pending_displays_.empty()); |
| 109 | 112 |
| 110 while (!displays_.empty()) | 113 while (!displays_.empty()) |
| 111 DestroyDisplay(*displays_.begin()); | 114 DestroyDisplay(*displays_.begin()); |
| 112 DCHECK(displays_.empty()); | 115 DCHECK(displays_.empty()); |
| 113 } | 116 } |
| 114 | 117 |
| 115 std::set<const Display*> DisplayManager::displays() const { | 118 std::set<const Display*> DisplayManager::displays() const { |
| 116 std::set<const Display*> ret_value(displays_.begin(), displays_.end()); | 119 std::set<const Display*> ret_value(displays_.begin(), displays_.end()); |
| 117 return ret_value; | 120 return ret_value; |
| 118 } | 121 } |
| 119 | 122 |
| 120 void DisplayManager::OnDisplayUpdate(const display::Display& display) { | 123 void DisplayManager::OnDisplayUpdated(const display::Display& display) { |
| 121 for (const auto& pair : user_display_managers_) | 124 for (const auto& pair : user_display_managers_) |
| 122 pair.second->OnDisplayUpdate(display); | 125 pair.second->OnDisplayUpdated(display); |
| 123 } | 126 } |
| 124 | 127 |
| 125 Display* DisplayManager::GetDisplayContaining(const ServerWindow* window) { | 128 Display* DisplayManager::GetDisplayContaining(const ServerWindow* window) { |
| 126 return const_cast<Display*>( | 129 return const_cast<Display*>( |
| 127 static_cast<const DisplayManager*>(this)->GetDisplayContaining(window)); | 130 static_cast<const DisplayManager*>(this)->GetDisplayContaining(window)); |
| 128 } | 131 } |
| 129 | 132 |
| 130 const Display* DisplayManager::GetDisplayContaining( | 133 const Display* DisplayManager::GetDisplayContaining( |
| 131 const ServerWindow* window) const { | 134 const ServerWindow* window) const { |
| 132 while (window && window->parent()) | 135 while (window && window->parent()) |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 window_server_->window_manager_window_tree_factory_set()->GetFactories(); | 244 window_server_->window_manager_window_tree_factory_set()->GetFactories(); |
| 242 for (WindowManagerWindowTreeFactory* factory : factories) { | 245 for (WindowManagerWindowTreeFactory* factory : factories) { |
| 243 if (factory->window_tree()) | 246 if (factory->window_tree()) |
| 244 factory->window_tree()->OnWmDisplayModified(display); | 247 factory->window_tree()->OnWmDisplayModified(display); |
| 245 } | 248 } |
| 246 | 249 |
| 247 // Update the PlatformWindow and ServerWindow size. This must happen after | 250 // Update the PlatformWindow and ServerWindow size. This must happen after |
| 248 // OnWmDisplayModified() so the WM has updated the display size. | 251 // OnWmDisplayModified() so the WM has updated the display size. |
| 249 ws_display->OnViewportMetricsChanged(metrics); | 252 ws_display->OnViewportMetricsChanged(metrics); |
| 250 | 253 |
| 251 OnDisplayUpdate(display); | 254 OnDisplayUpdated(display); |
| 252 } | 255 } |
| 253 | 256 |
| 254 void DisplayManager::OnPrimaryDisplayChanged(int64_t primary_display_id) { | 257 void DisplayManager::OnPrimaryDisplayChanged(int64_t primary_display_id) { |
| 255 DVLOG(3) << "OnPrimaryDisplayChanged: " << primary_display_id; | 258 DVLOG(3) << "OnPrimaryDisplayChanged: " << primary_display_id; |
| 256 // TODO(kylechar): Send IPCs to WM clients first. | 259 // TODO(kylechar): Send IPCs to WM clients first. |
| 257 | 260 |
| 258 // Send IPCs to any DisplayManagerObservers. | 261 // Send IPCs to any DisplayManagerObservers. |
| 259 for (const auto& pair : user_display_managers_) | 262 for (const auto& pair : user_display_managers_) |
| 260 pair.second->OnPrimaryDisplayChanged(primary_display_id); | 263 pair.second->OnPrimaryDisplayChanged(primary_display_id); |
| 261 } | 264 } |
| 262 | 265 |
| 263 } // namespace ws | 266 } // namespace ws |
| 264 } // namespace ui | 267 } // namespace ui |
| OLD | NEW |