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

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

Issue 2582823002: WIP: Surface Synchronization System
Patch Set: Only create ClientSurfaceEmbedder if window is visible. Trash it otherwise. Created 3 years, 10 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
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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 next_window_id_(1), 75 next_window_id_(1),
76 access_policy_(std::move(access_policy)), 76 access_policy_(std::move(access_policy)),
77 event_ack_id_(0), 77 event_ack_id_(0),
78 window_manager_internal_(nullptr) { 78 window_manager_internal_(nullptr) {
79 if (root) 79 if (root)
80 roots_.insert(root); 80 roots_.insert(root);
81 access_policy_->Init(id_, this); 81 access_policy_->Init(id_, this);
82 } 82 }
83 83
84 WindowTree::~WindowTree() { 84 WindowTree::~WindowTree() {
85 fprintf(stderr, ">>>%s\n", __PRETTY_FUNCTION__);
85 DestroyWindows(); 86 DestroyWindows();
86 87
87 // We alert the WindowManagerState that we're destroying this state here 88 // We alert the WindowManagerState that we're destroying this state here
88 // because WindowManagerState would attempt to use things that wouldn't have 89 // because WindowManagerState would attempt to use things that wouldn't have
89 // been cleaned up by OnWindowDestroyingTreeImpl(). 90 // been cleaned up by OnWindowDestroyingTreeImpl().
90 if (window_manager_state_) 91 if (window_manager_state_)
91 window_manager_state_->OnWillDestroyTree(this); 92 window_manager_state_->OnWillDestroyTree(this);
92 } 93 }
93 94
94 void WindowTree::Init(std::unique_ptr<WindowTreeBinding> binding, 95 void WindowTree::Init(std::unique_ptr<WindowTreeBinding> binding,
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 window != current_capture_window) { 260 window != current_capture_window) {
260 return false; 261 return false;
261 } 262 }
262 Operation op(this, window_server_, OperationType::RELEASE_CAPTURE); 263 Operation op(this, window_server_, OperationType::RELEASE_CAPTURE);
263 return display_root->window_manager_state()->SetCapture(nullptr, 264 return display_root->window_manager_state()->SetCapture(nullptr,
264 kInvalidClientId); 265 kInvalidClientId);
265 } 266 }
266 267
267 bool WindowTree::NewWindow( 268 bool WindowTree::NewWindow(
268 const ClientWindowId& client_window_id, 269 const ClientWindowId& client_window_id,
269 const std::map<std::string, std::vector<uint8_t>>& properties) { 270 const std::map<std::string, std::vector<uint8_t>>& properties,
271 const cc::LocalFrameId& local_frame_id) {
270 if (!IsValidIdForNewWindow(client_window_id)) 272 if (!IsValidIdForNewWindow(client_window_id))
271 return false; 273 return false;
272 const WindowId window_id = GenerateNewWindowId(); 274 const WindowId window_id = GenerateNewWindowId();
273 DCHECK(!GetWindow(window_id)); 275 DCHECK(!GetWindow(window_id));
274 ServerWindow* window = 276 ServerWindow* window =
275 window_server_->CreateServerWindow(window_id, properties); 277 window_server_->CreateServerWindow(window_id, properties, local_frame_id);
276 created_window_map_[window_id] = window; 278 created_window_map_[window_id] = window;
277 client_id_to_window_id_map_[client_window_id] = window_id; 279 client_id_to_window_id_map_[client_window_id] = window_id;
278 window_id_to_client_id_map_[window_id] = client_window_id; 280 window_id_to_client_id_map_[window_id] = client_window_id;
279 return true; 281 return true;
280 } 282 }
281 283
282 bool WindowTree::AddWindow(const ClientWindowId& parent_id, 284 bool WindowTree::AddWindow(const ClientWindowId& parent_id,
283 const ClientWindowId& child_id) { 285 const ClientWindowId& child_id) {
284 ServerWindow* parent = GetWindowByClientId(parent_id); 286 ServerWindow* parent = GetWindowByClientId(parent_id);
285 ServerWindow* child = GetWindowByClientId(child_id); 287 ServerWindow* child = GetWindowByClientId(child_id);
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 const ServerWindow* window) { 481 const ServerWindow* window) {
480 DCHECK(IsWaitingForNewTopLevelWindow(wm_change_id)); 482 DCHECK(IsWaitingForNewTopLevelWindow(wm_change_id));
481 std::unique_ptr<WaitingForTopLevelWindowInfo> 483 std::unique_ptr<WaitingForTopLevelWindowInfo>
482 waiting_for_top_level_window_info( 484 waiting_for_top_level_window_info(
483 std::move(waiting_for_top_level_window_info_)); 485 std::move(waiting_for_top_level_window_info_));
484 binding_->SetIncomingMethodCallProcessingPaused(false); 486 binding_->SetIncomingMethodCallProcessingPaused(false);
485 // We were paused, so the id should still be valid. 487 // We were paused, so the id should still be valid.
486 DCHECK(IsValidIdForNewWindow( 488 DCHECK(IsValidIdForNewWindow(
487 waiting_for_top_level_window_info->client_window_id)); 489 waiting_for_top_level_window_info->client_window_id));
488 if (!window) { 490 if (!window) {
491 fprintf(stderr, ">>>LOST A WINDOW :S\n");
489 client()->OnChangeCompleted(client_change_id, false); 492 client()->OnChangeCompleted(client_change_id, false);
490 return; 493 return;
491 } 494 }
492 client_id_to_window_id_map_[waiting_for_top_level_window_info 495 client_id_to_window_id_map_[waiting_for_top_level_window_info
493 ->client_window_id] = window->id(); 496 ->client_window_id] = window->id();
494 window_id_to_client_id_map_[window->id()] = 497 window_id_to_client_id_map_[window->id()] =
495 waiting_for_top_level_window_info->client_window_id; 498 waiting_for_top_level_window_info->client_window_id;
496 roots_.insert(window); 499 roots_.insert(window);
497 Display* display = GetDisplay(window); 500 Display* display = GetDisplay(window);
498 int64_t display_id = display ? display->GetId() : display::kInvalidDisplayId; 501 int64_t display_id = display ? display->GetId() : display::kInvalidDisplayId;
499 const bool drawn = window->parent() && window->parent()->IsDrawn(); 502 const bool drawn = window->parent() && window->parent()->IsDrawn();
503 fprintf(stderr,
504 ">>>>WindowTree::OnWindowManagerCreatedTopLevelWindow frame_sink_id: "
505 "%d\n",
506 WindowIdToTransportId(window->id()));
500 client()->OnTopLevelCreated(client_change_id, WindowToWindowData(window), 507 client()->OnTopLevelCreated(client_change_id, WindowToWindowData(window),
501 display_id, drawn); 508 display_id, drawn);
502 } 509 }
503 510
504 void WindowTree::AddActivationParent(const ClientWindowId& window_id) { 511 void WindowTree::AddActivationParent(const ClientWindowId& window_id) {
505 ServerWindow* window = GetWindowByClientId(window_id); 512 ServerWindow* window = GetWindowByClientId(window_id);
506 if (window) { 513 if (window) {
507 Display* display = GetDisplay(window); 514 Display* display = GetDisplay(window);
508 if (display) 515 if (display)
509 display->AddActivationParent(window); 516 display->AddActivationParent(window);
(...skipping 30 matching lines...) Expand all
540 void WindowTree::ClientJankinessChanged(WindowTree* tree) { 547 void WindowTree::ClientJankinessChanged(WindowTree* tree) {
541 tree->janky_ = !tree->janky_; 548 tree->janky_ = !tree->janky_;
542 // Don't inform the client if it is the source of jank (which generally only 549 // Don't inform the client if it is the source of jank (which generally only
543 // happens while debugging). 550 // happens while debugging).
544 if (window_manager_internal_ && tree != this) { 551 if (window_manager_internal_ && tree != this) {
545 window_manager_internal_->WmClientJankinessChanged( 552 window_manager_internal_->WmClientJankinessChanged(
546 tree->id(), tree->janky()); 553 tree->id(), tree->janky());
547 } 554 }
548 } 555 }
549 556
550 void WindowTree::ProcessWindowBoundsChanged(const ServerWindow* window, 557 void WindowTree::ProcessWindowBoundsChanged(
551 const gfx::Rect& old_bounds, 558 const ServerWindow* window,
552 const gfx::Rect& new_bounds, 559 const gfx::Rect& old_bounds,
553 bool originated_change) { 560 const gfx::Rect& new_bounds,
561 bool originated_change,
562 const cc::LocalFrameId& local_frame_id) {
554 ClientWindowId client_window_id; 563 ClientWindowId client_window_id;
555 if (originated_change || !IsWindowKnown(window, &client_window_id)) 564 if (originated_change || !IsWindowKnown(window, &client_window_id))
556 return; 565 return;
557 client()->OnWindowBoundsChanged(client_window_id.id, old_bounds, new_bounds); 566 client()->OnWindowBoundsChanged(client_window_id.id, old_bounds, new_bounds,
567 local_frame_id);
558 } 568 }
559 569
560 void WindowTree::ProcessClientAreaChanged( 570 void WindowTree::ProcessClientAreaChanged(
561 const ServerWindow* window, 571 const ServerWindow* window,
562 const gfx::Insets& new_client_area, 572 const gfx::Insets& new_client_area,
563 const std::vector<gfx::Rect>& new_additional_client_areas, 573 const std::vector<gfx::Rect>& new_additional_client_areas,
564 bool originated_change) { 574 bool originated_change) {
565 ClientWindowId client_window_id; 575 ClientWindowId client_window_id;
566 if (originated_change || !IsWindowKnown(window, &client_window_id)) 576 if (originated_change || !IsWindowKnown(window, &client_window_id))
567 return; 577 return;
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 window_data->parent_id = 1046 window_data->parent_id =
1037 parent ? ClientWindowIdForWindow(parent).id : ClientWindowId().id; 1047 parent ? ClientWindowIdForWindow(parent).id : ClientWindowId().id;
1038 window_data->window_id = 1048 window_data->window_id =
1039 window ? ClientWindowIdForWindow(window).id : ClientWindowId().id; 1049 window ? ClientWindowIdForWindow(window).id : ClientWindowId().id;
1040 window_data->transient_parent_id = 1050 window_data->transient_parent_id =
1041 transient_parent ? ClientWindowIdForWindow(transient_parent).id 1051 transient_parent ? ClientWindowIdForWindow(transient_parent).id
1042 : ClientWindowId().id; 1052 : ClientWindowId().id;
1043 window_data->bounds = window->bounds(); 1053 window_data->bounds = window->bounds();
1044 window_data->properties = mojo::MapToUnorderedMap(window->properties()); 1054 window_data->properties = mojo::MapToUnorderedMap(window->properties());
1045 window_data->visible = window->visible(); 1055 window_data->visible = window->visible();
1056 window_data->local_frame_id = window->local_frame_id();
1046 return window_data; 1057 return window_data;
1047 } 1058 }
1048 1059
1049 void WindowTree::GetWindowTreeImpl( 1060 void WindowTree::GetWindowTreeImpl(
1050 const ServerWindow* window, 1061 const ServerWindow* window,
1051 std::vector<const ServerWindow*>* windows) const { 1062 std::vector<const ServerWindow*>* windows) const {
1052 DCHECK(window); 1063 DCHECK(window);
1053 1064
1054 if (!access_policy_->CanGetWindowTree(window)) 1065 if (!access_policy_->CanGetWindowTree(window))
1055 return; 1066 return;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1160 return true; 1171 return true;
1161 return event.type() == ui::ET_POINTER_DOWN || 1172 return event.type() == ui::ET_POINTER_DOWN ||
1162 event.type() == ui::ET_POINTER_UP || 1173 event.type() == ui::ET_POINTER_UP ||
1163 event.type() == ui::ET_POINTER_WHEEL_CHANGED; 1174 event.type() == ui::ET_POINTER_WHEEL_CHANGED;
1164 } 1175 }
1165 1176
1166 void WindowTree::NewWindow( 1177 void WindowTree::NewWindow(
1167 uint32_t change_id, 1178 uint32_t change_id,
1168 Id transport_window_id, 1179 Id transport_window_id,
1169 const base::Optional<std::unordered_map<std::string, std::vector<uint8_t>>>& 1180 const base::Optional<std::unordered_map<std::string, std::vector<uint8_t>>>&
1170 transport_properties) { 1181 transport_properties,
1182 const cc::LocalFrameId& local_frame_id) {
1171 std::map<std::string, std::vector<uint8_t>> properties; 1183 std::map<std::string, std::vector<uint8_t>> properties;
1172 if (transport_properties.has_value()) 1184 if (transport_properties.has_value())
1173 properties = mojo::UnorderedMapToMap(transport_properties.value()); 1185 properties = mojo::UnorderedMapToMap(transport_properties.value());
1174 1186
1175 client()->OnChangeCompleted( 1187 client()->OnChangeCompleted(
1176 change_id, NewWindow(ClientWindowId(transport_window_id), properties)); 1188 change_id, NewWindow(ClientWindowId(transport_window_id), properties,
1189 local_frame_id));
1177 } 1190 }
1178 1191
1179 void WindowTree::NewTopLevelWindow( 1192 void WindowTree::NewTopLevelWindow(
1180 uint32_t change_id, 1193 uint32_t change_id,
1181 Id transport_window_id, 1194 Id transport_window_id,
1182 const std::unordered_map<std::string, std::vector<uint8_t>>& 1195 const std::unordered_map<std::string, std::vector<uint8_t>>&
1183 transport_properties) { 1196 transport_properties) {
1184 // TODO(sky): rather than DCHECK, have this kill connection. 1197 // TODO(sky): rather than DCHECK, have this kill connection.
1185 DCHECK(!window_manager_internal_); // Not valid for the windowmanager. 1198 DCHECK(!window_manager_internal_); // Not valid for the windowmanager.
1186 DCHECK(!waiting_for_top_level_window_info_); 1199 DCHECK(!waiting_for_top_level_window_info_);
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1324 pointer_watcher_want_moves_ = want_moves; 1337 pointer_watcher_want_moves_ = want_moves;
1325 } 1338 }
1326 1339
1327 void WindowTree::StopPointerWatcher() { 1340 void WindowTree::StopPointerWatcher() {
1328 has_pointer_watcher_ = false; 1341 has_pointer_watcher_ = false;
1329 pointer_watcher_want_moves_ = false; 1342 pointer_watcher_want_moves_ = false;
1330 } 1343 }
1331 1344
1332 void WindowTree::SetWindowBounds(uint32_t change_id, 1345 void WindowTree::SetWindowBounds(uint32_t change_id,
1333 Id window_id, 1346 Id window_id,
1334 const gfx::Rect& bounds) { 1347 const gfx::Rect& bounds,
1348 const cc::LocalFrameId& local_frame_id) {
1335 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); 1349 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id));
1336 if (window && ShouldRouteToWindowManager(window)) { 1350 if (window && ShouldRouteToWindowManager(window)) {
1337 const uint32_t wm_change_id = 1351 const uint32_t wm_change_id =
1338 window_server_->GenerateWindowManagerChangeId(this, change_id); 1352 window_server_->GenerateWindowManagerChangeId(this, change_id);
1339 // |window_id| may be a client id, use the id from the window to ensure 1353 // |window_id| may be a client id, use the id from the window to ensure
1340 // the windowmanager doesn't get an id it doesn't know about. 1354 // the windowmanager doesn't get an id it doesn't know about.
1341 WindowManagerDisplayRoot* display_root = 1355 WindowManagerDisplayRoot* display_root =
1342 GetWindowManagerDisplayRoot(window); 1356 GetWindowManagerDisplayRoot(window);
1343 WindowTree* wm_tree = display_root->window_manager_state()->window_tree(); 1357 WindowTree* wm_tree = display_root->window_manager_state()->window_tree();
1344 wm_tree->window_manager_internal_->WmSetBounds( 1358 wm_tree->window_manager_internal_->WmSetBounds(
1345 wm_change_id, wm_tree->ClientWindowIdForWindow(window).id, 1359 wm_change_id, wm_tree->ClientWindowIdForWindow(window).id,
1346 std::move(bounds)); 1360 std::move(bounds), local_frame_id);
1347 return; 1361 return;
1348 } 1362 }
1349 1363
1350 DVLOG(3) << "set window bounds client window_id=" << window_id 1364 DVLOG(3) << "set window bounds client window_id=" << window_id
1351 << " global window_id=" 1365 << " global window_id="
1352 << (window ? WindowIdToTransportId(window->id()) : 0) 1366 << (window ? WindowIdToTransportId(window->id()) : 0)
1353 << " bounds=" << bounds.ToString(); 1367 << " bounds=" << bounds.ToString();
1354 // Only the owner of the window can change the bounds. 1368 // Only the owner of the window can change the bounds.
1355 bool success = window && access_policy_->CanSetWindowBounds(window); 1369 bool success = window && access_policy_->CanSetWindowBounds(window);
1356 if (success) { 1370 if (success) {
1357 Operation op(this, window_server_, OperationType::SET_WINDOW_BOUNDS); 1371 Operation op(this, window_server_, OperationType::SET_WINDOW_BOUNDS);
1358 window->SetBounds(bounds); 1372 window->SetBounds(bounds, local_frame_id);
1359 } 1373 }
1360 client()->OnChangeCompleted(change_id, success); 1374 client()->OnChangeCompleted(change_id, success);
1361 } 1375 }
1362 1376
1363 void WindowTree::SetWindowVisibility(uint32_t change_id, 1377 void WindowTree::SetWindowVisibility(uint32_t change_id,
1364 Id transport_window_id, 1378 Id transport_window_id,
1365 bool visible) { 1379 bool visible) {
1366 client()->OnChangeCompleted( 1380 client()->OnChangeCompleted(
1367 change_id, 1381 change_id,
1368 SetWindowVisibility(ClientWindowId(transport_window_id), visible)); 1382 SetWindowVisibility(ClientWindowId(transport_window_id), visible));
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
1891 if (display_root) { 1905 if (display_root) {
1892 WindowManagerState* wms = display_root->window_manager_state(); 1906 WindowManagerState* wms = display_root->window_manager_state();
1893 // Clear the implicit capture. 1907 // Clear the implicit capture.
1894 wms->SetCapture(nullptr, false); 1908 wms->SetCapture(nullptr, false);
1895 } 1909 }
1896 } 1910 }
1897 1911
1898 if (!response && window) { 1912 if (!response && window) {
1899 // Our move loop didn't succeed, which means that we must restore the 1913 // Our move loop didn't succeed, which means that we must restore the
1900 // original bounds of the window. 1914 // original bounds of the window.
1901 window->SetBounds(window_server_->GetCurrentMoveLoopRevertBounds()); 1915 // TODO(fsamuel): Figure out what to do here.
1916 window->SetBounds(window_server_->GetCurrentMoveLoopRevertBounds(),
1917 cc::LocalFrameId());
1902 } 1918 }
1903 1919
1904 window_server_->EndMoveLoop(); 1920 window_server_->EndMoveLoop();
1905 } 1921 }
1906 1922
1907 window_server_->WindowManagerChangeCompleted(change_id, response); 1923 window_server_->WindowManagerChangeCompleted(change_id, response);
1908 } 1924 }
1909 1925
1910 void WindowTree::WmRequestClose(Id transport_window_id) { 1926 void WindowTree::WmRequestClose(Id transport_window_id) {
1911 ServerWindow* window = 1927 ServerWindow* window =
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
2080 client()->OnCompleteDrop(client_window_id.id, event_flags, cursor_offset, 2096 client()->OnCompleteDrop(client_window_id.id, event_flags, cursor_offset,
2081 effect_bitmask, callback); 2097 effect_bitmask, callback);
2082 } 2098 }
2083 2099
2084 void WindowTree::PerformOnDragDropDone() { 2100 void WindowTree::PerformOnDragDropDone() {
2085 client()->OnDragDropDone(); 2101 client()->OnDragDropDone();
2086 } 2102 }
2087 2103
2088 } // namespace ws 2104 } // namespace ws
2089 } // namespace ui 2105 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698