| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/connection_manager.h" | 5 #include "components/mus/ws/connection_manager.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "components/mus/ws/connection_manager_delegate.h" | 9 #include "components/mus/ws/connection_manager_delegate.h" |
| 10 #include "components/mus/ws/display.h" |
| 10 #include "components/mus/ws/display_binding.h" | 11 #include "components/mus/ws/display_binding.h" |
| 12 #include "components/mus/ws/display_manager.h" |
| 11 #include "components/mus/ws/operation.h" | 13 #include "components/mus/ws/operation.h" |
| 12 #include "components/mus/ws/server_window.h" | 14 #include "components/mus/ws/server_window.h" |
| 13 #include "components/mus/ws/window_coordinate_conversions.h" | 15 #include "components/mus/ws/window_coordinate_conversions.h" |
| 14 #include "components/mus/ws/window_manager_factory_service.h" | 16 #include "components/mus/ws/window_manager_factory_service.h" |
| 15 #include "components/mus/ws/window_manager_state.h" | 17 #include "components/mus/ws/window_manager_state.h" |
| 16 #include "components/mus/ws/window_tree.h" | 18 #include "components/mus/ws/window_tree.h" |
| 17 #include "components/mus/ws/window_tree_binding.h" | 19 #include "components/mus/ws/window_tree_binding.h" |
| 18 #include "mojo/converters/geometry/geometry_type_converters.h" | 20 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 19 #include "mojo/converters/input_events/input_events_type_converters.h" | 21 #include "mojo/converters/input_events/input_events_type_converters.h" |
| 20 #include "mojo/converters/surfaces/surfaces_type_converters.h" | 22 #include "mojo/converters/surfaces/surfaces_type_converters.h" |
| 21 #include "mojo/shell/public/cpp/connection.h" | 23 #include "mojo/shell/public/cpp/connection.h" |
| 22 #include "ui/gfx/geometry/size_conversions.h" | 24 #include "ui/gfx/geometry/size_conversions.h" |
| 23 | 25 |
| 24 namespace mus { | 26 namespace mus { |
| 25 namespace ws { | 27 namespace ws { |
| 26 | 28 |
| 27 ConnectionManager::ConnectionManager( | 29 ConnectionManager::ConnectionManager( |
| 28 ConnectionManagerDelegate* delegate, | 30 ConnectionManagerDelegate* delegate, |
| 29 const scoped_refptr<mus::SurfacesState>& surfaces_state) | 31 const scoped_refptr<mus::SurfacesState>& surfaces_state) |
| 30 : delegate_(delegate), | 32 : delegate_(delegate), |
| 31 surfaces_state_(surfaces_state), | 33 surfaces_state_(surfaces_state), |
| 32 next_connection_id_(1), | 34 next_connection_id_(1), |
| 33 next_root_id_(0), | 35 display_manager_(new ws::DisplayManager(this)), |
| 34 current_operation_(nullptr), | 36 current_operation_(nullptr), |
| 35 in_destructor_(false), | 37 in_destructor_(false), |
| 36 next_wm_change_id_(0), | 38 next_wm_change_id_(0), |
| 37 got_valid_frame_decorations_(false), | 39 got_valid_frame_decorations_(false), |
| 38 window_manager_factory_registry_(this, &user_id_tracker_) {} | 40 window_manager_factory_registry_(this, &user_id_tracker_) {} |
| 39 | 41 |
| 40 ConnectionManager::~ConnectionManager() { | 42 ConnectionManager::~ConnectionManager() { |
| 41 in_destructor_ = true; | 43 in_destructor_ = true; |
| 42 | 44 |
| 43 while (!pending_displays_.empty()) | 45 // Destroys the window trees results in querying for the display. Tear down |
| 44 DestroyDisplay(*pending_displays_.begin()); | 46 // the displays first so that the trees are notified of the display going |
| 45 DCHECK(pending_displays_.empty()); | 47 // away while the display is still valid. |
| 48 display_manager_->DestroyAllDisplays(); |
| 46 | 49 |
| 47 // DestroyDisplay() removes from |displays_| and deletes the Display. | 50 while (!tree_map_.empty()) |
| 48 while (!displays_.empty()) | 51 DestroyTree(tree_map_.begin()->second.get()); |
| 49 DestroyDisplay(*displays_.begin()); | |
| 50 DCHECK(displays_.empty()); | |
| 51 | 52 |
| 52 tree_map_.clear(); | 53 display_manager_.reset(); |
| 53 } | |
| 54 | |
| 55 void ConnectionManager::AddDisplay(Display* display) { | |
| 56 DCHECK_EQ(0u, pending_displays_.count(display)); | |
| 57 pending_displays_.insert(display); | |
| 58 } | |
| 59 | |
| 60 void ConnectionManager::DestroyDisplay(Display* display) { | |
| 61 for (auto& pair : tree_map_) | |
| 62 pair.second->OnWillDestroyDisplay(display); | |
| 63 | |
| 64 if (pending_displays_.count(display)) { | |
| 65 pending_displays_.erase(display); | |
| 66 } else { | |
| 67 DCHECK(displays_.count(display)); | |
| 68 displays_.erase(display); | |
| 69 } | |
| 70 delete display; | |
| 71 | |
| 72 // If we have no more roots left, let the app know so it can terminate. | |
| 73 if (!displays_.size() && !pending_displays_.size()) | |
| 74 delegate_->OnNoMoreRootConnections(); | |
| 75 } | 54 } |
| 76 | 55 |
| 77 ServerWindow* ConnectionManager::CreateServerWindow( | 56 ServerWindow* ConnectionManager::CreateServerWindow( |
| 78 const WindowId& id, | 57 const WindowId& id, |
| 79 const std::map<std::string, std::vector<uint8_t>>& properties) { | 58 const std::map<std::string, std::vector<uint8_t>>& properties) { |
| 80 ServerWindow* window = new ServerWindow(this, id, properties); | 59 ServerWindow* window = new ServerWindow(this, id, properties); |
| 81 window->AddObserver(this); | 60 window->AddObserver(this); |
| 82 return window; | 61 return window; |
| 83 } | 62 } |
| 84 | 63 |
| 85 ConnectionSpecificId ConnectionManager::GetAndAdvanceNextConnectionId() { | 64 ConnectionSpecificId ConnectionManager::GetAndAdvanceNextConnectionId() { |
| 86 const ConnectionSpecificId id = next_connection_id_++; | 65 const ConnectionSpecificId id = next_connection_id_++; |
| 87 DCHECK_LT(id, next_connection_id_); | 66 DCHECK_LT(id, next_connection_id_); |
| 88 return id; | 67 return id; |
| 89 } | 68 } |
| 90 | 69 |
| 91 uint16_t ConnectionManager::GetAndAdvanceNextRootId() { | |
| 92 // TODO(sky): handle wrapping! | |
| 93 const uint16_t id = next_root_id_++; | |
| 94 DCHECK_LT(id, next_root_id_); | |
| 95 return id; | |
| 96 } | |
| 97 | |
| 98 WindowTree* ConnectionManager::EmbedAtWindow( | 70 WindowTree* ConnectionManager::EmbedAtWindow( |
| 99 ServerWindow* root, | 71 ServerWindow* root, |
| 100 uint32_t policy_bitmask, | 72 uint32_t policy_bitmask, |
| 101 mojom::WindowTreeClientPtr client) { | 73 mojom::WindowTreeClientPtr client) { |
| 102 scoped_ptr<WindowTree> tree_ptr( | 74 scoped_ptr<WindowTree> tree_ptr( |
| 103 new ws::WindowTree(this, root, policy_bitmask)); | 75 new ws::WindowTree(this, root, policy_bitmask)); |
| 104 WindowTree* tree = tree_ptr.get(); | 76 WindowTree* tree = tree_ptr.get(); |
| 105 | 77 |
| 106 mojom::WindowTreePtr window_tree_ptr; | 78 mojom::WindowTreePtr window_tree_ptr; |
| 107 scoped_ptr<WindowTreeBinding> binding = | 79 scoped_ptr<WindowTreeBinding> binding = |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 tree_map_.erase(iter); | 123 tree_map_.erase(iter); |
| 152 } | 124 } |
| 153 | 125 |
| 154 // Notify remaining connections so that they can cleanup. | 126 // Notify remaining connections so that they can cleanup. |
| 155 for (auto& pair : tree_map_) | 127 for (auto& pair : tree_map_) |
| 156 pair.second->OnWindowDestroyingTreeImpl(tree); | 128 pair.second->OnWindowDestroyingTreeImpl(tree); |
| 157 | 129 |
| 158 // Notify the hosts, taking care to only notify each host once. | 130 // Notify the hosts, taking care to only notify each host once. |
| 159 std::set<Display*> displays_notified; | 131 std::set<Display*> displays_notified; |
| 160 for (auto* root : tree->roots()) { | 132 for (auto* root : tree->roots()) { |
| 161 Display* display = GetDisplayContaining(root); | 133 // WindowTree holds its roots as a const, which is right as WindowTree |
| 134 // doesn't need to modify the window. OTOH we do. We could look up the |
| 135 // window using the id to get non-const version, but instead we cast. |
| 136 Display* display = |
| 137 display_manager_->GetDisplayContaining(const_cast<ServerWindow*>(root)); |
| 162 if (display && displays_notified.count(display) == 0) { | 138 if (display && displays_notified.count(display) == 0) { |
| 163 display->OnWindowTreeConnectionError(tree); | 139 display->OnWillDestroyTree(tree); |
| 164 displays_notified.insert(display); | 140 displays_notified.insert(display); |
| 165 } | 141 } |
| 166 } | 142 } |
| 167 | 143 |
| 168 // Remove any requests from the client that resulted in a call to the window | 144 // Remove any requests from the client that resulted in a call to the window |
| 169 // manager and we haven't gotten a response back yet. | 145 // manager and we haven't gotten a response back yet. |
| 170 std::set<uint32_t> to_remove; | 146 std::set<uint32_t> to_remove; |
| 171 for (auto& pair : in_flight_wm_change_map_) { | 147 for (auto& pair : in_flight_wm_change_map_) { |
| 172 if (pair.second.connection_id == tree->id()) | 148 if (pair.second.connection_id == tree->id()) |
| 173 to_remove.insert(pair.first); | 149 to_remove.insert(pair.first); |
| 174 } | 150 } |
| 175 for (uint32_t id : to_remove) | 151 for (uint32_t id : to_remove) |
| 176 in_flight_wm_change_map_.erase(id); | 152 in_flight_wm_change_map_.erase(id); |
| 177 } | 153 } |
| 178 | 154 |
| 179 WindowTree* ConnectionManager::GetTreeWithId( | 155 WindowTree* ConnectionManager::GetTreeWithId( |
| 180 ConnectionSpecificId connection_id) { | 156 ConnectionSpecificId connection_id) { |
| 181 auto iter = tree_map_.find(connection_id); | 157 auto iter = tree_map_.find(connection_id); |
| 182 return iter == tree_map_.end() ? nullptr : iter->second.get(); | 158 return iter == tree_map_.end() ? nullptr : iter->second.get(); |
| 183 } | 159 } |
| 184 | 160 |
| 185 ServerWindow* ConnectionManager::GetWindow(const WindowId& id) { | 161 ServerWindow* ConnectionManager::GetWindow(const WindowId& id) { |
| 186 // kInvalidConnectionId is used for Display and WindowManager nodes. | 162 // kInvalidConnectionId is used for Display and WindowManager nodes. |
| 187 if (id.connection_id == kInvalidConnectionId) { | 163 if (id.connection_id == kInvalidConnectionId) { |
| 188 for (Display* display : displays_) { | 164 for (Display* display : display_manager_->displays()) { |
| 189 ServerWindow* window = display->GetRootWithId(id); | 165 ServerWindow* window = display->GetRootWithId(id); |
| 190 if (window) | 166 if (window) |
| 191 return window; | 167 return window; |
| 192 } | 168 } |
| 193 } | 169 } |
| 194 WindowTree* tree = GetTreeWithId(id.connection_id); | 170 WindowTree* tree = GetTreeWithId(id.connection_id); |
| 195 return tree ? tree->GetWindow(id) : nullptr; | 171 return tree ? tree->GetWindow(id) : nullptr; |
| 196 } | 172 } |
| 197 | 173 |
| 198 void ConnectionManager::SchedulePaint(const ServerWindow* window, | 174 void ConnectionManager::SchedulePaint(ServerWindow* window, |
| 199 const gfx::Rect& bounds) { | 175 const gfx::Rect& bounds) { |
| 200 for (Display* display : displays_) { | 176 Display* display = display_manager_->GetDisplayContaining(window); |
| 201 if (display->SchedulePaintIfInViewport(window, bounds)) | 177 if (display) |
| 202 return; | 178 display->SchedulePaint(window, bounds); |
| 203 } | |
| 204 } | |
| 205 | |
| 206 void ConnectionManager::OnDisplayAcceleratedWidgetAvailable(Display* display) { | |
| 207 DCHECK_NE(0u, pending_displays_.count(display)); | |
| 208 DCHECK_EQ(0u, displays_.count(display)); | |
| 209 const bool is_first_display = displays_.empty(); | |
| 210 displays_.insert(display); | |
| 211 pending_displays_.erase(display); | |
| 212 if (is_first_display) | |
| 213 delegate_->OnFirstDisplayReady(); | |
| 214 } | 179 } |
| 215 | 180 |
| 216 void ConnectionManager::OnTreeMessagedClient(ConnectionSpecificId id) { | 181 void ConnectionManager::OnTreeMessagedClient(ConnectionSpecificId id) { |
| 217 if (current_operation_) | 182 if (current_operation_) |
| 218 current_operation_->MarkTreeAsMessaged(id); | 183 current_operation_->MarkTreeAsMessaged(id); |
| 219 } | 184 } |
| 220 | 185 |
| 221 bool ConnectionManager::DidTreeMessageClient(ConnectionSpecificId id) const { | 186 bool ConnectionManager::DidTreeMessageClient(ConnectionSpecificId id) const { |
| 222 return current_operation_ && current_operation_->DidMessageTree(id); | 187 return current_operation_ && current_operation_->DidMessageTree(id); |
| 223 } | 188 } |
| 224 | 189 |
| 225 mojom::ViewportMetricsPtr ConnectionManager::GetViewportMetricsForWindow( | 190 mojom::ViewportMetricsPtr ConnectionManager::GetViewportMetricsForWindow( |
| 226 const ServerWindow* window) { | 191 const ServerWindow* window) { |
| 227 Display* display = GetDisplayContaining(window); | 192 const Display* display = display_manager_->GetDisplayContaining(window); |
| 228 if (display) | 193 if (display) |
| 229 return display->GetViewportMetrics().Clone(); | 194 return display->GetViewportMetrics().Clone(); |
| 230 | 195 |
| 231 if (!displays_.empty()) | 196 if (!display_manager_->displays().empty()) |
| 232 return (*displays_.begin())->GetViewportMetrics().Clone(); | 197 return (*display_manager_->displays().begin()) |
| 198 ->GetViewportMetrics() |
| 199 .Clone(); |
| 233 | 200 |
| 234 mojom::ViewportMetricsPtr metrics = mojom::ViewportMetrics::New(); | 201 mojom::ViewportMetricsPtr metrics = mojom::ViewportMetrics::New(); |
| 235 metrics->size_in_pixels = mojo::Size::New(); | 202 metrics->size_in_pixels = mojo::Size::New(); |
| 236 return metrics; | 203 return metrics; |
| 237 } | 204 } |
| 238 | 205 |
| 239 const WindowTree* ConnectionManager::GetTreeWithRoot( | 206 const WindowTree* ConnectionManager::GetTreeWithRoot( |
| 240 const ServerWindow* window) const { | 207 const ServerWindow* window) const { |
| 241 if (!window) | 208 if (!window) |
| 242 return nullptr; | 209 return nullptr; |
| 243 for (auto& pair : tree_map_) { | 210 for (auto& pair : tree_map_) { |
| 244 if (pair.second->HasRoot(window)) | 211 if (pair.second->HasRoot(window)) |
| 245 return pair.second.get(); | 212 return pair.second.get(); |
| 246 } | 213 } |
| 247 return nullptr; | 214 return nullptr; |
| 248 } | 215 } |
| 249 | 216 |
| 250 WindowManagerAndDisplayConst ConnectionManager::GetWindowManagerAndDisplay( | |
| 251 const ServerWindow* window) const { | |
| 252 const ServerWindow* last = window; | |
| 253 while (window && window->parent()) { | |
| 254 last = window; | |
| 255 window = window->parent(); | |
| 256 } | |
| 257 for (Display* display : displays_) { | |
| 258 if (window == display->root_window()) { | |
| 259 WindowManagerAndDisplayConst result; | |
| 260 result.display = display; | |
| 261 result.window_manager_state = | |
| 262 display->GetWindowManagerStateWithRoot(last); | |
| 263 return result; | |
| 264 } | |
| 265 } | |
| 266 return WindowManagerAndDisplayConst(); | |
| 267 } | |
| 268 | |
| 269 WindowManagerAndDisplay ConnectionManager::GetWindowManagerAndDisplay( | |
| 270 const ServerWindow* window) { | |
| 271 WindowManagerAndDisplayConst result_const = | |
| 272 const_cast<const ConnectionManager*>(this)->GetWindowManagerAndDisplay( | |
| 273 window); | |
| 274 WindowManagerAndDisplay result; | |
| 275 result.display = const_cast<Display*>(result_const.display); | |
| 276 result.window_manager_state = | |
| 277 const_cast<WindowManagerState*>(result_const.window_manager_state); | |
| 278 return result; | |
| 279 } | |
| 280 | |
| 281 Display* ConnectionManager::GetDisplayContaining(const ServerWindow* window) { | |
| 282 return const_cast<Display*>( | |
| 283 static_cast<const ConnectionManager*>(this)->GetDisplayContaining( | |
| 284 window)); | |
| 285 } | |
| 286 | |
| 287 const Display* ConnectionManager::GetDisplayContaining( | |
| 288 const ServerWindow* window) const { | |
| 289 while (window && window->parent()) | |
| 290 window = window->parent(); | |
| 291 for (Display* display : displays_) { | |
| 292 if (window == display->root_window()) | |
| 293 return display; | |
| 294 } | |
| 295 return nullptr; | |
| 296 } | |
| 297 | |
| 298 Display* ConnectionManager::GetActiveDisplay() { | |
| 299 // TODO(sky): this isn't active, but first. Make it active. | |
| 300 return displays_.size() ? *displays_.begin() : nullptr; | |
| 301 } | |
| 302 | |
| 303 void ConnectionManager::AddDisplayManagerBinding( | 217 void ConnectionManager::AddDisplayManagerBinding( |
| 304 mojo::InterfaceRequest<mojom::DisplayManager> request) { | 218 mojo::InterfaceRequest<mojom::DisplayManager> request) { |
| 305 display_manager_bindings_.AddBinding(this, std::move(request)); | 219 display_manager_bindings_.AddBinding(this, std::move(request)); |
| 306 } | 220 } |
| 307 | 221 |
| 308 void ConnectionManager::OnFirstWindowManagerFactorySet() { | 222 void ConnectionManager::OnFirstWindowManagerFactorySet() { |
| 309 if (!displays_.empty() || !pending_displays_.empty()) | 223 if (display_manager_->has_active_or_pending_displays()) |
| 310 return; | 224 return; |
| 311 | 225 |
| 312 // We've been supplied a WindowManagerFactory and no displays have been | 226 // We've been supplied a WindowManagerFactory and no displays have been |
| 313 // created yet. Treat this as a signal to create a Display. | 227 // created yet. Treat this as a signal to create a Display. |
| 314 // TODO(sky): we need a better way to determine this, most likely a switch. | 228 // TODO(sky): we need a better way to determine this, most likely a switch. |
| 315 delegate_->CreateDefaultDisplays(); | 229 delegate_->CreateDefaultDisplays(); |
| 316 } | 230 } |
| 317 | 231 |
| 318 uint32_t ConnectionManager::GenerateWindowManagerChangeId( | 232 uint32_t ConnectionManager::GenerateWindowManagerChangeId( |
| 319 WindowTree* source, | 233 WindowTree* source, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 return; | 274 return; |
| 361 } | 275 } |
| 362 | 276 |
| 363 tree->OnWindowManagerCreatedTopLevelWindow(window_manager_change_id, | 277 tree->OnWindowManagerCreatedTopLevelWindow(window_manager_change_id, |
| 364 change.client_change_id, window); | 278 change.client_change_id, window); |
| 365 } | 279 } |
| 366 | 280 |
| 367 mojom::DisplayPtr ConnectionManager::DisplayToMojomDisplay(Display* display) { | 281 mojom::DisplayPtr ConnectionManager::DisplayToMojomDisplay(Display* display) { |
| 368 size_t i = 0; | 282 size_t i = 0; |
| 369 int next_x = 0; | 283 int next_x = 0; |
| 370 for (Display* display2 : displays_) { | 284 for (Display* display2 : display_manager_->displays()) { |
| 371 const ServerWindow* root = display->root_window(); | 285 const ServerWindow* root = display->root_window(); |
| 372 if (display == display2) { | 286 if (display == display2) { |
| 373 mojom::DisplayPtr display_ptr = mojom::Display::New(); | 287 mojom::DisplayPtr display_ptr = mojom::Display::New(); |
| 374 display_ptr = mojom::Display::New(); | 288 display_ptr = mojom::Display::New(); |
| 375 display_ptr->id = display->id(); | 289 display_ptr->id = display->id(); |
| 376 display_ptr->bounds = mojo::Rect::New(); | 290 display_ptr->bounds = mojo::Rect::New(); |
| 377 display_ptr->bounds->x = next_x; | 291 display_ptr->bounds->x = next_x; |
| 378 display_ptr->bounds->y = 0; | 292 display_ptr->bounds->y = 0; |
| 379 display_ptr->bounds->width = root->bounds().size().width(); | 293 display_ptr->bounds->width = root->bounds().size().width(); |
| 380 display_ptr->bounds->height = root->bounds().size().height(); | 294 display_ptr->bounds->height = root->bounds().size().height(); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 OperationType::REMOVE_TRANSIENT_WINDOW_FROM_PARENT)) { | 369 OperationType::REMOVE_TRANSIENT_WINDOW_FROM_PARENT)) { |
| 456 return; | 370 return; |
| 457 } | 371 } |
| 458 for (auto& pair : tree_map_) { | 372 for (auto& pair : tree_map_) { |
| 459 pair.second->ProcessWindowReorder(window, relative_window, direction, | 373 pair.second->ProcessWindowReorder(window, relative_window, direction, |
| 460 IsOperationSource(pair.first)); | 374 IsOperationSource(pair.first)); |
| 461 } | 375 } |
| 462 } | 376 } |
| 463 | 377 |
| 464 void ConnectionManager::ProcessWindowDeleted(const ServerWindow* window) { | 378 void ConnectionManager::ProcessWindowDeleted(const ServerWindow* window) { |
| 465 for (auto& pair : tree_map_) { | 379 for (auto& pair : tree_map_) |
| 466 pair.second->ProcessWindowDeleted(window, IsOperationSource(pair.first)); | 380 pair.second->ProcessWindowDeleted(window, IsOperationSource(pair.first)); |
| 467 } | |
| 468 } | 381 } |
| 469 | 382 |
| 470 void ConnectionManager::ProcessWillChangeWindowPredefinedCursor( | 383 void ConnectionManager::ProcessWillChangeWindowPredefinedCursor( |
| 471 ServerWindow* window, | 384 ServerWindow* window, |
| 472 int32_t cursor_id) { | 385 int32_t cursor_id) { |
| 473 for (auto& pair : tree_map_) { | 386 for (auto& pair : tree_map_) { |
| 474 pair.second->ProcessCursorChanged(window, cursor_id, | 387 pair.second->ProcessCursorChanged(window, cursor_id, |
| 475 IsOperationSource(pair.first)); | 388 IsOperationSource(pair.first)); |
| 476 } | 389 } |
| 477 | 390 |
| 478 // Pass the cursor change to the native window. | 391 // Pass the cursor change to the native window. |
| 479 Display* display = GetDisplayContaining(window); | 392 Display* display = display_manager_->GetDisplayContaining(window); |
| 480 if (display) | 393 if (display) |
| 481 display->OnCursorUpdated(window); | 394 display->OnCursorUpdated(window); |
| 482 } | 395 } |
| 483 | 396 |
| 484 void ConnectionManager::ProcessViewportMetricsChanged( | 397 void ConnectionManager::ProcessViewportMetricsChanged( |
| 485 Display* display, | 398 Display* display, |
| 486 const mojom::ViewportMetrics& old_metrics, | 399 const mojom::ViewportMetrics& old_metrics, |
| 487 const mojom::ViewportMetrics& new_metrics) { | 400 const mojom::ViewportMetrics& new_metrics) { |
| 488 for (auto& pair : tree_map_) { | 401 for (auto& pair : tree_map_) { |
| 489 pair.second->ProcessViewportMetricsChanged( | 402 pair.second->ProcessViewportMetricsChanged( |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 } | 443 } |
| 531 | 444 |
| 532 void ConnectionManager::FinishOperation() { | 445 void ConnectionManager::FinishOperation() { |
| 533 // PrepareForOperation/FinishOperation should be balanced. | 446 // PrepareForOperation/FinishOperation should be balanced. |
| 534 CHECK(current_operation_); | 447 CHECK(current_operation_); |
| 535 current_operation_ = nullptr; | 448 current_operation_ = nullptr; |
| 536 } | 449 } |
| 537 | 450 |
| 538 void ConnectionManager::MaybeUpdateNativeCursor(ServerWindow* window) { | 451 void ConnectionManager::MaybeUpdateNativeCursor(ServerWindow* window) { |
| 539 // This can be null in unit tests. | 452 // This can be null in unit tests. |
| 540 Display* display = GetDisplayContaining(window); | 453 Display* display = display_manager_->GetDisplayContaining(window); |
| 541 if (display) | 454 if (display) |
| 542 display->MaybeChangeCursorOnWindowTreeChange(); | 455 display->MaybeChangeCursorOnWindowTreeChange(); |
| 543 } | 456 } |
| 544 | 457 |
| 545 void ConnectionManager::CallOnDisplays( | 458 void ConnectionManager::CallOnDisplays( |
| 546 mojom::DisplayManagerObserver* observer) { | 459 mojom::DisplayManagerObserver* observer) { |
| 547 mojo::Array<mojom::DisplayPtr> displays(displays_.size()); | 460 std::set<Display*> displays = display_manager_->displays(); |
| 461 mojo::Array<mojom::DisplayPtr> display_ptrs(displays.size()); |
| 548 { | 462 { |
| 549 size_t i = 0; | 463 size_t i = 0; |
| 550 // TODO(sky): need ordering! | 464 // TODO(sky): need ordering! |
| 551 for (Display* display : displays_) { | 465 for (Display* display : displays) { |
| 552 displays[i] = DisplayToMojomDisplay(display); | 466 display_ptrs[i] = DisplayToMojomDisplay(display); |
| 553 ++i; | 467 ++i; |
| 554 } | 468 } |
| 555 } | 469 } |
| 556 observer->OnDisplays(std::move(displays)); | 470 observer->OnDisplays(std::move(display_ptrs)); |
| 557 } | 471 } |
| 558 | 472 |
| 559 void ConnectionManager::CallOnDisplayChanged( | 473 void ConnectionManager::CallOnDisplayChanged( |
| 560 mojom::DisplayManagerObserver* observer, | 474 mojom::DisplayManagerObserver* observer, |
| 561 Display* display) { | 475 Display* display) { |
| 562 mojo::Array<mojom::DisplayPtr> displays(1); | 476 mojo::Array<mojom::DisplayPtr> displays(1); |
| 563 displays[0] = DisplayToMojomDisplay(display); | 477 displays[0] = DisplayToMojomDisplay(display); |
| 564 display_manager_observers_.ForAllPtrs( | 478 display_manager_observers_.ForAllPtrs( |
| 565 [&displays](mojom::DisplayManagerObserver* observer) { | 479 [&displays](mojom::DisplayManagerObserver* observer) { |
| 566 observer->OnDisplaysChanged(displays.Clone()); | 480 observer->OnDisplaysChanged(displays.Clone()); |
| 567 }); | 481 }); |
| 568 } | 482 } |
| 569 | 483 |
| 570 mus::SurfacesState* ConnectionManager::GetSurfacesState() { | 484 mus::SurfacesState* ConnectionManager::GetSurfacesState() { |
| 571 return surfaces_state_.get(); | 485 return surfaces_state_.get(); |
| 572 } | 486 } |
| 573 | 487 |
| 574 void ConnectionManager::OnScheduleWindowPaint(const ServerWindow* window) { | 488 void ConnectionManager::OnScheduleWindowPaint(ServerWindow* window) { |
| 575 if (!in_destructor_) | 489 if (!in_destructor_) |
| 576 SchedulePaint(window, gfx::Rect(window->bounds().size())); | 490 SchedulePaint(window, gfx::Rect(window->bounds().size())); |
| 577 } | 491 } |
| 578 | 492 |
| 579 const ServerWindow* ConnectionManager::GetRootWindow( | 493 const ServerWindow* ConnectionManager::GetRootWindow( |
| 580 const ServerWindow* window) const { | 494 const ServerWindow* window) const { |
| 581 const Display* display = GetDisplayContaining(window); | 495 const Display* display = display_manager_->GetDisplayContaining(window); |
| 582 return display ? display->root_window() : nullptr; | 496 return display ? display->root_window() : nullptr; |
| 583 } | 497 } |
| 584 | 498 |
| 585 void ConnectionManager::ScheduleSurfaceDestruction(ServerWindow* window) { | 499 void ConnectionManager::ScheduleSurfaceDestruction(ServerWindow* window) { |
| 586 for (Display* display : displays_) { | 500 Display* display = display_manager_->GetDisplayContaining(window); |
| 587 if (display->root_window()->Contains(window)) { | 501 if (display) |
| 588 display->ScheduleSurfaceDestruction(window); | 502 display->ScheduleSurfaceDestruction(window); |
| 589 break; | |
| 590 } | |
| 591 } | |
| 592 } | 503 } |
| 593 | 504 |
| 594 ServerWindow* ConnectionManager::FindWindowForSurface( | 505 ServerWindow* ConnectionManager::FindWindowForSurface( |
| 595 const ServerWindow* ancestor, | 506 const ServerWindow* ancestor, |
| 596 mojom::SurfaceType surface_type, | 507 mojom::SurfaceType surface_type, |
| 597 const ClientWindowId& client_window_id) { | 508 const ClientWindowId& client_window_id) { |
| 598 WindowTree* window_tree; | 509 WindowTree* window_tree; |
| 599 if (ancestor->id().connection_id == kInvalidConnectionId) { | 510 if (ancestor->id().connection_id == kInvalidConnectionId) { |
| 600 WindowManagerAndDisplay wm_and_display = | 511 WindowManagerAndDisplay wm_and_display = |
| 601 GetWindowManagerAndDisplay(ancestor); | 512 display_manager_->GetWindowManagerAndDisplay(ancestor); |
| 602 window_tree = wm_and_display.window_manager_state | 513 window_tree = wm_and_display.window_manager_state |
| 603 ? wm_and_display.window_manager_state->tree() | 514 ? wm_and_display.window_manager_state->tree() |
| 604 : nullptr; | 515 : nullptr; |
| 605 } else { | 516 } else { |
| 606 window_tree = GetTreeWithId(ancestor->id().connection_id); | 517 window_tree = GetTreeWithId(ancestor->id().connection_id); |
| 607 } | 518 } |
| 608 if (!window_tree) | 519 if (!window_tree) |
| 609 return nullptr; | 520 return nullptr; |
| 610 if (surface_type == mojom::SurfaceType::DEFAULT) { | 521 if (surface_type == mojom::SurfaceType::DEFAULT) { |
| 611 // At embed points the default surface comes from the embedded app. | 522 // At embed points the default surface comes from the embedded app. |
| 612 WindowTree* tree_with_root = GetTreeWithRoot(ancestor); | 523 WindowTree* tree_with_root = GetTreeWithRoot(ancestor); |
| 613 if (tree_with_root) | 524 if (tree_with_root) |
| 614 window_tree = tree_with_root; | 525 window_tree = tree_with_root; |
| 615 } | 526 } |
| 616 return window_tree->GetWindowByClientId(client_window_id); | 527 return window_tree->GetWindowByClientId(client_window_id); |
| 617 } | 528 } |
| 618 | 529 |
| 619 void ConnectionManager::OnWindowDestroyed(ServerWindow* window) { | 530 void ConnectionManager::OnWindowDestroyed(ServerWindow* window) { |
| 620 if (!in_destructor_) | 531 ProcessWindowDeleted(window); |
| 621 ProcessWindowDeleted(window); | |
| 622 } | 532 } |
| 623 | 533 |
| 624 void ConnectionManager::OnWillChangeWindowHierarchy(ServerWindow* window, | 534 void ConnectionManager::OnWillChangeWindowHierarchy(ServerWindow* window, |
| 625 ServerWindow* new_parent, | 535 ServerWindow* new_parent, |
| 626 ServerWindow* old_parent) { | 536 ServerWindow* old_parent) { |
| 627 if (in_destructor_) | 537 if (in_destructor_) |
| 628 return; | 538 return; |
| 629 | 539 |
| 630 ProcessWillChangeWindowHierarchy(window, new_parent, old_parent); | 540 ProcessWillChangeWindowHierarchy(window, new_parent, old_parent); |
| 631 } | 541 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 const std::vector<uint8_t>* new_data) { | 626 const std::vector<uint8_t>* new_data) { |
| 717 for (auto& pair : tree_map_) { | 627 for (auto& pair : tree_map_) { |
| 718 pair.second->ProcessWindowPropertyChanged(window, name, new_data, | 628 pair.second->ProcessWindowPropertyChanged(window, name, new_data, |
| 719 IsOperationSource(pair.first)); | 629 IsOperationSource(pair.first)); |
| 720 } | 630 } |
| 721 } | 631 } |
| 722 | 632 |
| 723 void ConnectionManager::OnWindowTextInputStateChanged( | 633 void ConnectionManager::OnWindowTextInputStateChanged( |
| 724 ServerWindow* window, | 634 ServerWindow* window, |
| 725 const ui::TextInputState& state) { | 635 const ui::TextInputState& state) { |
| 726 Display* display = GetDisplayContaining(window); | 636 Display* display = display_manager_->GetDisplayContaining(window); |
| 727 display->UpdateTextInputState(window, state); | 637 display->UpdateTextInputState(window, state); |
| 728 } | 638 } |
| 729 | 639 |
| 730 void ConnectionManager::OnTransientWindowAdded(ServerWindow* window, | 640 void ConnectionManager::OnTransientWindowAdded(ServerWindow* window, |
| 731 ServerWindow* transient_child) { | 641 ServerWindow* transient_child) { |
| 732 for (auto& pair : tree_map_) { | 642 for (auto& pair : tree_map_) { |
| 733 pair.second->ProcessTransientWindowAdded(window, transient_child, | 643 pair.second->ProcessTransientWindowAdded(window, transient_child, |
| 734 IsOperationSource(pair.first)); | 644 IsOperationSource(pair.first)); |
| 735 } | 645 } |
| 736 } | 646 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 754 // decorations before notifying so that we don't have to worry about clients | 664 // decorations before notifying so that we don't have to worry about clients |
| 755 // resizing appropriately. | 665 // resizing appropriately. |
| 756 if (!got_valid_frame_decorations_) { | 666 if (!got_valid_frame_decorations_) { |
| 757 display_manager_observers_.AddInterfacePtr(std::move(observer)); | 667 display_manager_observers_.AddInterfacePtr(std::move(observer)); |
| 758 return; | 668 return; |
| 759 } | 669 } |
| 760 CallOnDisplays(observer.get()); | 670 CallOnDisplays(observer.get()); |
| 761 display_manager_observers_.AddInterfacePtr(std::move(observer)); | 671 display_manager_observers_.AddInterfacePtr(std::move(observer)); |
| 762 } | 672 } |
| 763 | 673 |
| 674 void ConnectionManager::OnWillDestroyDisplay(Display* display) { |
| 675 for (auto& pair : tree_map_) |
| 676 pair.second->OnWillDestroyDisplay(display); |
| 677 } |
| 678 |
| 679 void ConnectionManager::OnFirstDisplayReady() { |
| 680 delegate_->OnFirstDisplayReady(); |
| 681 } |
| 682 |
| 683 void ConnectionManager::OnNoMoreDisplays() { |
| 684 delegate_->OnNoMoreDisplays(); |
| 685 } |
| 686 |
| 764 } // namespace ws | 687 } // namespace ws |
| 765 } // namespace mus | 688 } // namespace mus |
| OLD | NEW |