Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: services/ui/ws/window_tree.cc

Issue 2804403002: Adds ability for WindowManager to create display roots (Closed)
Patch Set: cleanup Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « services/ui/ws/window_tree.h ('k') | services/ui/ws/window_tree_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "services/ui/ws/window_tree.h" 5 #include "services/ui/ws/window_tree.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 roots_.insert(root); 94 roots_.insert(root);
95 access_policy_->Init(id_, this); 95 access_policy_->Init(id_, this);
96 } 96 }
97 97
98 WindowTree::~WindowTree() { 98 WindowTree::~WindowTree() {
99 DestroyWindows(); 99 DestroyWindows();
100 100
101 // We alert the WindowManagerState that we're destroying this state here 101 // We alert the WindowManagerState that we're destroying this state here
102 // because WindowManagerState would attempt to use things that wouldn't have 102 // because WindowManagerState would attempt to use things that wouldn't have
103 // been cleaned up by OnWindowDestroyingTreeImpl(). 103 // been cleaned up by OnWindowDestroyingTreeImpl().
104 if (window_manager_state_) 104 if (window_manager_state_) {
105 window_manager_state_->OnWillDestroyTree(this); 105 window_manager_state_->OnWillDestroyTree(this);
106 window_manager_state_.reset();
107 }
106 } 108 }
107 109
108 void WindowTree::Init(std::unique_ptr<WindowTreeBinding> binding, 110 void WindowTree::Init(std::unique_ptr<WindowTreeBinding> binding,
109 mojom::WindowTreePtr tree) { 111 mojom::WindowTreePtr tree) {
110 DCHECK(!binding_); 112 DCHECK(!binding_);
111 binding_ = std::move(binding); 113 binding_ = std::move(binding);
112 114
113 if (roots_.empty()) 115 if (roots_.empty())
114 return; 116 return;
115 117
(...skipping 11 matching lines...) Expand all
127 ClientWindowId focused_window_id; 129 ClientWindowId focused_window_id;
128 if (focused_window) 130 if (focused_window)
129 IsWindowKnown(focused_window, &focused_window_id); 131 IsWindowKnown(focused_window, &focused_window_id);
130 132
131 const bool drawn = root->parent() && root->parent()->IsDrawn(); 133 const bool drawn = root->parent() && root->parent()->IsDrawn();
132 client()->OnEmbed(id_, WindowToWindowData(to_send.front()), std::move(tree), 134 client()->OnEmbed(id_, WindowToWindowData(to_send.front()), std::move(tree),
133 display_id, focused_window_id.id, drawn, 135 display_id, focused_window_id.id, drawn,
134 root->frame_sink_id(), root->current_local_surface_id()); 136 root->frame_sink_id(), root->current_local_surface_id());
135 } 137 }
136 138
137 void WindowTree::ConfigureWindowManager() { 139 void WindowTree::ConfigureWindowManager(
140 bool automatically_create_display_roots) {
138 // ConfigureWindowManager() should be called early on, before anything 141 // ConfigureWindowManager() should be called early on, before anything
139 // else. |waiting_for_top_level_window_info_| must be null as if 142 // else. |waiting_for_top_level_window_info_| must be null as if
140 // |waiting_for_top_level_window_info_| is non-null it means we're about to 143 // |waiting_for_top_level_window_info_| is non-null it means we're about to
141 // create an associated interface, which doesn't work with pause/resume. 144 // create an associated interface, which doesn't work with pause/resume.
142 // TODO(sky): DCHECK temporary until 626869 is sorted out. 145 // TODO(sky): DCHECK temporary until 626869 is sorted out.
143 DCHECK(!waiting_for_top_level_window_info_); 146 DCHECK(!waiting_for_top_level_window_info_);
144 DCHECK(!window_manager_internal_); 147 DCHECK(!window_manager_internal_);
148 automatically_create_display_roots_ = automatically_create_display_roots;
145 window_manager_internal_ = binding_->GetWindowManager(); 149 window_manager_internal_ = binding_->GetWindowManager();
146 window_manager_internal_->OnConnect(id_); 150 window_manager_internal_->OnConnect(id_);
147 window_manager_state_ = base::MakeUnique<WindowManagerState>(this); 151 window_manager_state_ = base::MakeUnique<WindowManagerState>(this);
148 } 152 }
149 153
150 const ServerWindow* WindowTree::GetWindow(const WindowId& id) const { 154 const ServerWindow* WindowTree::GetWindow(const WindowId& id) const {
151 if (id_ == id.client_id) { 155 if (id_ == id.client_id) {
152 auto iter = created_window_map_.find(id); 156 auto iter = created_window_map_.find(id);
153 return iter == created_window_map_.end() ? nullptr : iter->second; 157 return iter == created_window_map_.end() ? nullptr : iter->second;
154 } 158 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } 201 }
198 202
199 void WindowTree::PrepareForWindowServerShutdown() { 203 void WindowTree::PrepareForWindowServerShutdown() {
200 window_manager_internal_client_binding_.reset(); 204 window_manager_internal_client_binding_.reset();
201 binding_->ResetClientForShutdown(); 205 binding_->ResetClientForShutdown();
202 if (window_manager_internal_) 206 if (window_manager_internal_)
203 window_manager_internal_ = binding_->GetWindowManager(); 207 window_manager_internal_ = binding_->GetWindowManager();
204 } 208 }
205 209
206 void WindowTree::AddRootForWindowManager(const ServerWindow* root) { 210 void WindowTree::AddRootForWindowManager(const ServerWindow* root) {
211 if (!automatically_create_display_roots_)
212 return;
213
214 DCHECK(automatically_create_display_roots_);
207 DCHECK(window_manager_internal_); 215 DCHECK(window_manager_internal_);
208 const ClientWindowId client_window_id(WindowIdToTransportId(root->id())); 216 const ClientWindowId client_window_id(WindowIdToTransportId(root->id()));
209 DCHECK_EQ(0u, client_id_to_window_id_map_.count(client_window_id)); 217 DCHECK_EQ(0u, client_id_to_window_id_map_.count(client_window_id));
210 client_id_to_window_id_map_[client_window_id] = root->id(); 218 client_id_to_window_id_map_[client_window_id] = root->id();
211 window_id_to_client_id_map_[root->id()] = client_window_id; 219 window_id_to_client_id_map_[root->id()] = client_window_id;
212 roots_.insert(root); 220 roots_.insert(root);
213 221
214 Display* ws_display = GetDisplay(root); 222 Display* ws_display = GetDisplay(root);
215 DCHECK(ws_display); 223 DCHECK(ws_display);
216 224
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 void WindowTree::OnWmMoveDragImageAck() { 256 void WindowTree::OnWmMoveDragImageAck() {
249 if (drag_move_state_->has_queued_drag_window_move) { 257 if (drag_move_state_->has_queued_drag_window_move) {
250 gfx::Point queued_location = drag_move_state_->queued_cursor_location; 258 gfx::Point queued_location = drag_move_state_->queued_cursor_location;
251 drag_move_state_.reset(); 259 drag_move_state_.reset();
252 OnDragMoved(queued_location); 260 OnDragMoved(queued_location);
253 } else { 261 } else {
254 drag_move_state_.reset(); 262 drag_move_state_.reset();
255 } 263 }
256 } 264 }
257 265
266 bool WindowTree::ProcessSetDisplayRoot(int64_t display_id,
267 const ClientWindowId& client_window_id) {
268 DCHECK(window_manager_state_); // Only called for window manager.
269 Display* display =
270 window_server_->display_manager()->GetDisplayById(display_id);
271 if (!display) {
272 DVLOG(1) << "SetDisplayRoot called with unknown display " << display_id;
273 return false;
274 }
275
276 if (automatically_create_display_roots_) {
277 DVLOG(1) << "SetDisplayRoot is only applicable when "
278 << "automatically_create_display_roots is false";
279 return false;
280 }
281
282 ServerWindow* window = GetWindowByClientId(client_window_id);
283 // The window must not have a parent.
284 if (!window || window->parent()) {
285 DVLOG(1) << "SetDisplayRoot called with invalid window id "
286 << client_window_id.id;
287 return false;
288 }
289
290 WindowManagerDisplayRoot* display_root =
291 display->GetWindowManagerDisplayRootForUser(
292 window_manager_state_->user_id());
293 DCHECK(display_root);
294 if (!display_root->root()->children().empty()) {
295 DVLOG(1) << "SetDisplayRoot called more than once";
296 return false;
297 }
298
299 if (base::ContainsValue(roots_, window)) {
300 DVLOG(1) << "SetDisplayRoot called with existing root";
301 return false;
302 }
303
304 // NOTE: this doesn't resize the window in anyway. We assume the client takes
305 // care of any modifications it needs to do.
306 roots_.insert(window);
307 Operation op(this, window_server_, OperationType::ADD_WINDOW);
308 display_root->root()->Add(window);
309 return true;
310 }
311
258 bool WindowTree::SetCapture(const ClientWindowId& client_window_id) { 312 bool WindowTree::SetCapture(const ClientWindowId& client_window_id) {
259 ServerWindow* window = GetWindowByClientId(client_window_id); 313 ServerWindow* window = GetWindowByClientId(client_window_id);
260 WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(window); 314 WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(window);
261 ServerWindow* current_capture_window = 315 ServerWindow* current_capture_window =
262 display_root ? display_root->window_manager_state()->capture_window() 316 display_root ? display_root->window_manager_state()->capture_window()
263 : nullptr; 317 : nullptr;
264 if (window && window->IsDrawn() && display_root && 318 if (window && window->IsDrawn() && display_root &&
265 display_root->window_manager_state()->IsActive() && 319 display_root->window_manager_state()->IsActive() &&
266 access_policy_->CanSetCapture(window) && 320 access_policy_->CanSetCapture(window) &&
267 (!current_capture_window || 321 (!current_capture_window ||
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 else 643 else
590 DCHECK_EQ(0u, event_ack_id_); 644 DCHECK_EQ(0u, event_ack_id_);
591 // TODO(moshayedi): crbug.com/617167. Don't clone even once we map 645 // TODO(moshayedi): crbug.com/617167. Don't clone even once we map
592 // mojom::Event directly to ui::Event. 646 // mojom::Event directly to ui::Event.
593 window_manager_internal_->OnAccelerator(event_ack_id_, accelerator_id, 647 window_manager_internal_->OnAccelerator(event_ack_id_, accelerator_id,
594 ui::Event::Clone(event)); 648 ui::Event::Clone(event));
595 } 649 }
596 650
597 void WindowTree::OnDisplayDestroying(int64_t display_id) { 651 void WindowTree::OnDisplayDestroying(int64_t display_id) {
598 DCHECK(window_manager_internal_); 652 DCHECK(window_manager_internal_);
599 window_manager_internal_->WmDisplayRemoved(display_id); 653 if (automatically_create_display_roots_)
654 window_manager_internal_->WmDisplayRemoved(display_id);
655 // For the else case the client should detect removal directly.
600 } 656 }
601 657
602 void WindowTree::ClientJankinessChanged(WindowTree* tree) { 658 void WindowTree::ClientJankinessChanged(WindowTree* tree) {
603 tree->janky_ = !tree->janky_; 659 tree->janky_ = !tree->janky_;
604 // Don't inform the client if it is the source of jank (which generally only 660 // Don't inform the client if it is the source of jank (which generally only
605 // happens while debugging). 661 // happens while debugging).
606 if (window_manager_internal_ && tree != this) { 662 if (window_manager_internal_ && tree != this) {
607 window_manager_internal_->WmClientJankinessChanged( 663 window_manager_internal_->WmClientJankinessChanged(
608 tree->id(), tree->janky()); 664 tree->id(), tree->janky());
609 } 665 }
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 1093
1038 const ServerWindow::Windows& children = window->children(); 1094 const ServerWindow::Windows& children = window->children();
1039 for (ServerWindow* child : children) 1095 for (ServerWindow* child : children)
1040 RemoveFromKnown(child, local_windows); 1096 RemoveFromKnown(child, local_windows);
1041 } 1097 }
1042 1098
1043 void WindowTree::RemoveRoot(ServerWindow* window, RemoveRootReason reason) { 1099 void WindowTree::RemoveRoot(ServerWindow* window, RemoveRootReason reason) {
1044 DCHECK(roots_.count(window) > 0); 1100 DCHECK(roots_.count(window) > 0);
1045 roots_.erase(window); 1101 roots_.erase(window);
1046 1102
1103 if (window->id().client_id == id_) {
1104 // This cllient created the window. If this client is the window manager and
1105 // display roots are manually created, then |window| is a display root and
1106 // needs be cleaned.
1107 if (window_manager_state_ && !automatically_create_display_roots_) {
1108 // The window manager is asking to delete the root it created.
1109 window_manager_state_->DeleteWindowManagerDisplayRoot(window->parent());
1110 DeleteWindowImpl(this, window);
1111 }
1112 return;
1113 }
1114
1047 const ClientWindowId client_window_id(ClientWindowIdForWindow(window)); 1115 const ClientWindowId client_window_id(ClientWindowIdForWindow(window));
1048 1116
1049 // No need to do anything if we created the window.
1050 if (window->id().client_id == id_)
1051 return;
1052
1053 if (reason == RemoveRootReason::EMBED) { 1117 if (reason == RemoveRootReason::EMBED) {
1054 client()->OnUnembed(client_window_id.id); 1118 client()->OnUnembed(client_window_id.id);
1055 client()->OnWindowDeleted(client_window_id.id); 1119 client()->OnWindowDeleted(client_window_id.id);
1056 window_server_->OnTreeMessagedClient(id_); 1120 window_server_->OnTreeMessagedClient(id_);
1057 } 1121 }
1058 1122
1059 // This client no longer knows about the window. Unparent any windows that 1123 // This client no longer knows about the window. Unparent any windows that
1060 // were parented to windows in the root. 1124 // were parented to windows in the root.
1061 std::vector<ServerWindow*> local_windows; 1125 std::vector<ServerWindow*> local_windows;
1062 RemoveFromKnown(window, &local_windows); 1126 RemoveFromKnown(window, &local_windows);
(...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after
2034 DVLOG(1) << "SetExtendedHitArea supplied unknown window"; 2098 DVLOG(1) << "SetExtendedHitArea supplied unknown window";
2035 return; 2099 return;
2036 } 2100 }
2037 if (window->id().client_id != id_) { 2101 if (window->id().client_id != id_) {
2038 DVLOG(1) << "SetExtendedHitArea supplied window that client does not own"; 2102 DVLOG(1) << "SetExtendedHitArea supplied window that client does not own";
2039 return; 2103 return;
2040 } 2104 }
2041 window->set_extended_hit_test_region(hit_area); 2105 window->set_extended_hit_test_region(hit_area);
2042 } 2106 }
2043 2107
2108 void WindowTree::SetDisplayRoot(int64_t display_id,
2109 Id window_id,
2110 const SetDisplayRootCallback& callback) {
2111 callback.Run(ProcessSetDisplayRoot(display_id, ClientWindowId(window_id)));
2112 }
2113
2044 void WindowTree::WmResponse(uint32_t change_id, bool response) { 2114 void WindowTree::WmResponse(uint32_t change_id, bool response) {
2045 if (window_server_->in_move_loop() && 2115 if (window_server_->in_move_loop() &&
2046 window_server_->GetCurrentMoveLoopChangeId() == change_id) { 2116 window_server_->GetCurrentMoveLoopChangeId() == change_id) {
2047 ServerWindow* window = window_server_->GetCurrentMoveLoopWindow(); 2117 ServerWindow* window = window_server_->GetCurrentMoveLoopWindow();
2048 2118
2049 if (window->id().client_id != id_) { 2119 if (window->id().client_id != id_) {
2050 window_server_->WindowManagerSentBogusMessage(); 2120 window_server_->WindowManagerSentBogusMessage();
2051 window = nullptr; 2121 window = nullptr;
2052 } else { 2122 } else {
2053 WindowManagerDisplayRoot* display_root = 2123 WindowManagerDisplayRoot* display_root =
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
2281 client()->OnCompleteDrop(client_window_id.id, event_flags, cursor_offset, 2351 client()->OnCompleteDrop(client_window_id.id, event_flags, cursor_offset,
2282 effect_bitmask, callback); 2352 effect_bitmask, callback);
2283 } 2353 }
2284 2354
2285 void WindowTree::PerformOnDragDropDone() { 2355 void WindowTree::PerformOnDragDropDone() {
2286 client()->OnDragDropDone(); 2356 client()->OnDragDropDone();
2287 } 2357 }
2288 2358
2289 } // namespace ws 2359 } // namespace ws
2290 } // namespace ui 2360 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/ws/window_tree.h ('k') | services/ui/ws/window_tree_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698