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

Side by Side Diff: ui/aura/mus/window_tree_client.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
« no previous file with comments | « ui/aura/mus/window_tree_client.h ('k') | ui/aura/mus/window_tree_host_mus.h » ('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 "ui/aura/mus/window_tree_client.h" 5 #include "ui/aura/mus/window_tree_client.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/auto_reset.h" 13 #include "base/auto_reset.h"
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/debug/stack_trace.h"
15 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "cc/surfaces/frame_sink_id.h"
16 #include "mojo/public/cpp/bindings/map.h" 18 #include "mojo/public/cpp/bindings/map.h"
17 #include "services/service_manager/public/cpp/connector.h" 19 #include "services/service_manager/public/cpp/connector.h"
18 #include "services/ui/common/accelerator_util.h" 20 #include "services/ui/common/accelerator_util.h"
19 #include "services/ui/public/cpp/gpu/gpu.h" 21 #include "services/ui/public/cpp/gpu/gpu.h"
20 #include "services/ui/public/cpp/property_type_converters.h" 22 #include "services/ui/public/cpp/property_type_converters.h"
21 #include "services/ui/public/interfaces/constants.mojom.h" 23 #include "services/ui/public/interfaces/constants.mojom.h"
22 #include "services/ui/public/interfaces/window_manager.mojom.h" 24 #include "services/ui/public/interfaces/window_manager.mojom.h"
23 #include "services/ui/public/interfaces/window_manager_window_tree_factory.mojom .h" 25 #include "services/ui/public/interfaces/window_manager_window_tree_factory.mojom .h"
24 #include "ui/aura/client/aura_constants.h" 26 #include "ui/aura/client/aura_constants.h"
25 #include "ui/aura/client/drag_drop_client.h" 27 #include "ui/aura/client/drag_drop_client.h"
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 window_manager_delegate->SetWindowManagerClient(this); 173 window_manager_delegate->SetWindowManagerClient(this);
172 if (connector) { // |connector| can be null in tests. 174 if (connector) { // |connector| can be null in tests.
173 gpu_ = ui::Gpu::Create(connector, std::move(io_task_runner)); 175 gpu_ = ui::Gpu::Create(connector, std::move(io_task_runner));
174 compositor_context_factory_ = 176 compositor_context_factory_ =
175 base::MakeUnique<MusContextFactory>(gpu_.get()); 177 base::MakeUnique<MusContextFactory>(gpu_.get());
176 Env::GetInstance()->set_context_factory(compositor_context_factory_.get()); 178 Env::GetInstance()->set_context_factory(compositor_context_factory_.get());
177 } 179 }
178 } 180 }
179 181
180 WindowTreeClient::~WindowTreeClient() { 182 WindowTreeClient::~WindowTreeClient() {
183 fprintf(stderr, ">>>%s\n", __PRETTY_FUNCTION__);
181 in_destructor_ = true; 184 in_destructor_ = true;
182 185
183 for (WindowTreeClientObserver& observer : observers_) 186 for (WindowTreeClientObserver& observer : observers_)
184 observer.OnWillDestroyClient(this); 187 observer.OnWillDestroyClient(this);
185 188
186 std::vector<Window*> non_owned; 189 std::vector<Window*> non_owned;
187 WindowTracker tracker; 190 WindowTracker tracker;
188 while (!windows_.empty()) { 191 while (!windows_.empty()) {
189 IdToWindowMap::iterator it = windows_.begin(); 192 IdToWindowMap::iterator it = windows_.begin();
190 if (WasCreatedByThisClient(it->second)) { 193 if (WasCreatedByThisClient(it->second)) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 // Window::Init() must be called before Embed() (otherwise the server hasn't 279 // Window::Init() must be called before Embed() (otherwise the server hasn't
277 // been told about the window). 280 // been told about the window).
278 DCHECK(window->layer()); 281 DCHECK(window->layer());
279 if (!window->children().empty()) { 282 if (!window->children().empty()) {
280 // The window server removes all children before embedding. In other words, 283 // The window server removes all children before embedding. In other words,
281 // it's generally an error to Embed() with existing children. So, fail 284 // it's generally an error to Embed() with existing children. So, fail
282 // early. 285 // early.
283 callback.Run(false); 286 callback.Run(false);
284 return; 287 return;
285 } 288 }
286 289 WindowMus* window_mus = WindowMus::Get(window);
287 tree_->Embed(WindowMus::Get(window)->server_id(), std::move(client), flags, 290 tree_->Embed(window_mus->server_id(), std::move(client), flags, callback);
288 callback); 291 fprintf(stderr, ">>>>WindowTreeClient::Embed\n");
292 // window->SetLocalFrameIdFromServer(local_frame_id);
289 } 293 }
290 294
291 void WindowTreeClient::AttachCompositorFrameSink( 295 void WindowTreeClient::AttachCompositorFrameSink(
292 Id window_id, 296 Id window_id,
293 cc::mojom::MojoCompositorFrameSinkRequest compositor_frame_sink, 297 cc::mojom::MojoCompositorFrameSinkRequest compositor_frame_sink,
294 cc::mojom::MojoCompositorFrameSinkClientPtr client) { 298 cc::mojom::MojoCompositorFrameSinkClientPtr client) {
295 DCHECK(tree_); 299 DCHECK(tree_);
296 tree_->AttachCompositorFrameSink(window_id, std::move(compositor_frame_sink), 300 tree_->AttachCompositorFrameSink(window_id, std::move(compositor_frame_sink),
297 std::move(client)); 301 std::move(client));
298 } 302 }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 } 390 }
387 } 391 }
388 392
389 std::unique_ptr<WindowPortMus> WindowTreeClient::CreateWindowPortMus( 393 std::unique_ptr<WindowPortMus> WindowTreeClient::CreateWindowPortMus(
390 const ui::mojom::WindowData& window_data, 394 const ui::mojom::WindowData& window_data,
391 WindowMusType window_mus_type) { 395 WindowMusType window_mus_type) {
392 std::unique_ptr<WindowPortMus> window_port_mus( 396 std::unique_ptr<WindowPortMus> window_port_mus(
393 base::MakeUnique<WindowPortMus>(this, window_mus_type)); 397 base::MakeUnique<WindowPortMus>(this, window_mus_type));
394 window_port_mus->set_server_id(window_data.window_id); 398 window_port_mus->set_server_id(window_data.window_id);
395 RegisterWindowMus(window_port_mus.get()); 399 RegisterWindowMus(window_port_mus.get());
400 // If (window_port_mus->server_id() == 65566)
401 // base::debug::StackTrace().Print();
396 return window_port_mus; 402 return window_port_mus;
397 } 403 }
398 404
399 void WindowTreeClient::SetLocalPropertiesFromServerProperties( 405 void WindowTreeClient::SetLocalPropertiesFromServerProperties(
400 WindowMus* window, 406 WindowMus* window,
401 const ui::mojom::WindowData& window_data) { 407 const ui::mojom::WindowData& window_data) {
402 for (auto& pair : window_data.properties) 408 for (auto& pair : window_data.properties)
403 window->SetPropertyFromServer(pair.first, &pair.second); 409 window->SetPropertyFromServer(pair.first, &pair.second);
404 } 410 }
405 411
406 std::unique_ptr<WindowTreeHostMus> WindowTreeClient::CreateWindowTreeHost( 412 std::unique_ptr<WindowTreeHostMus> WindowTreeClient::CreateWindowTreeHost(
407 WindowMusType window_mus_type, 413 WindowMusType window_mus_type,
408 const ui::mojom::WindowData& window_data, 414 const ui::mojom::WindowData& window_data,
409 int64_t display_id) { 415 int64_t display_id) {
410 std::unique_ptr<WindowPortMus> window_port = 416 std::unique_ptr<WindowPortMus> window_port =
411 CreateWindowPortMus(window_data, window_mus_type); 417 CreateWindowPortMus(window_data, window_mus_type);
412 roots_.insert(window_port.get()); 418 roots_.insert(window_port.get());
413 std::unique_ptr<WindowTreeHostMus> window_tree_host = 419 std::unique_ptr<WindowTreeHostMus> window_tree_host =
414 base::MakeUnique<WindowTreeHostMus>(std::move(window_port), this, 420 base::MakeUnique<WindowTreeHostMus>(std::move(window_port), this,
415 display_id); 421 display_id);
416 window_tree_host->InitHost(); 422 window_tree_host->InitHost();
417 SetLocalPropertiesFromServerProperties( 423 SetLocalPropertiesFromServerProperties(
418 WindowMus::Get(window_tree_host->window()), window_data); 424 WindowMus::Get(window_tree_host->window()), window_data);
419 if (window_data.visible) { 425 if (window_data.visible) {
420 SetWindowVisibleFromServer(WindowMus::Get(window_tree_host->window()), 426 SetWindowVisibleFromServer(WindowMus::Get(window_tree_host->window()),
421 true); 427 true);
422 } 428 }
423 SetWindowBoundsFromServer(WindowMus::Get(window_tree_host->window()), 429 WindowMus* window = WindowMus::Get(window_tree_host->window());
424 window_data.bounds); 430
431 SetWindowBoundsFromServer(window, window_data.bounds,
432 window_data.local_frame_id);
433 fprintf(stderr, ">>>WindowTreeClient::CreateWindowTreeHost %s\n",
434 cc::SurfaceId(cc::FrameSinkId(window->server_id(), 0),
435 window_data.local_frame_id)
436 .ToString()
437 .c_str());
425 return window_tree_host; 438 return window_tree_host;
426 } 439 }
427 440
428 WindowMus* WindowTreeClient::NewWindowFromWindowData( 441 WindowMus* WindowTreeClient::NewWindowFromWindowData(
429 WindowMus* parent, 442 WindowMus* parent,
430 const ui::mojom::WindowData& window_data) { 443 const ui::mojom::WindowData& window_data) {
431 // This function is only called for windows coming from other clients. 444 // This function is only called for windows coming from other clients.
432 std::unique_ptr<WindowPortMus> window_port_mus( 445 std::unique_ptr<WindowPortMus> window_port_mus(
433 CreateWindowPortMus(window_data, WindowMusType::OTHER)); 446 CreateWindowPortMus(window_data, WindowMusType::OTHER));
434 WindowPortMus* window_port_mus_ptr = window_port_mus.get(); 447 WindowPortMus* window_port_mus_ptr = window_port_mus.get();
435 Window* window = new Window(nullptr, std::move(window_port_mus)); 448 Window* window = new Window(nullptr, std::move(window_port_mus));
436 WindowMus* window_mus = window_port_mus_ptr; 449 WindowMus* window_mus = window_port_mus_ptr;
437 SetWindowTypeFromProperties(window, window_data.properties); 450 SetWindowTypeFromProperties(window, window_data.properties);
438 window->Init(ui::LAYER_NOT_DRAWN); 451 window->Init(ui::LAYER_NOT_DRAWN);
439 SetLocalPropertiesFromServerProperties(window_mus, window_data); 452 SetLocalPropertiesFromServerProperties(window_mus, window_data);
440 window_mus->SetBoundsFromServer( 453 window_mus->SetBoundsFromServer(
441 gfx::ConvertRectToDIP(ScaleFactorForDisplay(window), window_data.bounds)); 454 gfx::ConvertRectToDIP(ScaleFactorForDisplay(window), window_data.bounds),
455 window_data.local_frame_id);
442 if (parent) 456 if (parent)
443 parent->AddChildFromServer(window_port_mus_ptr); 457 parent->AddChildFromServer(window_port_mus_ptr);
444 if (window_data.visible) 458 if (window_data.visible)
445 window_mus->SetVisibleFromServer(true); 459 window_mus->SetVisibleFromServer(true);
446 return window_port_mus_ptr; 460 return window_port_mus_ptr;
447 } 461 }
448 462
449 void WindowTreeClient::SetWindowTree(ui::mojom::WindowTreePtr window_tree_ptr) { 463 void WindowTreeClient::SetWindowTree(ui::mojom::WindowTreePtr window_tree_ptr) {
450 tree_ptr_ = std::move(window_tree_ptr); 464 tree_ptr_ = std::move(window_tree_ptr);
451 WindowTreeConnectionEstablished(tree_ptr_.get()); 465 WindowTreeConnectionEstablished(tree_ptr_.get());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 tree_->SetModal(change_id, window->server_id()); 509 tree_->SetModal(change_id, window->server_id());
496 return true; 510 return true;
497 } 511 }
498 512
499 void WindowTreeClient::OnEmbedImpl(ui::mojom::WindowTree* window_tree, 513 void WindowTreeClient::OnEmbedImpl(ui::mojom::WindowTree* window_tree,
500 ClientSpecificId client_id, 514 ClientSpecificId client_id,
501 ui::mojom::WindowDataPtr root_data, 515 ui::mojom::WindowDataPtr root_data,
502 int64_t display_id, 516 int64_t display_id,
503 Id focused_window_id, 517 Id focused_window_id,
504 bool drawn) { 518 bool drawn) {
519 fprintf(stderr, ">>%s\n", __PRETTY_FUNCTION__);
505 // WARNING: this is only called if WindowTreeClient was created as the 520 // WARNING: this is only called if WindowTreeClient was created as the
506 // result of an embedding. 521 // result of an embedding.
507 client_id_ = client_id; 522 client_id_ = client_id;
508 WindowTreeConnectionEstablished(window_tree); 523 WindowTreeConnectionEstablished(window_tree);
509 524
510 DCHECK(roots_.empty()); 525 DCHECK(roots_.empty());
511 std::unique_ptr<WindowTreeHostMus> window_tree_host = 526 std::unique_ptr<WindowTreeHostMus> window_tree_host =
512 CreateWindowTreeHost(WindowMusType::EMBED, *root_data, display_id); 527 CreateWindowTreeHost(WindowMusType::EMBED, *root_data, display_id);
513 528
514 focus_synchronizer_->SetFocusFromServer( 529 focus_synchronizer_->SetFocusFromServer(
(...skipping 27 matching lines...) Expand all
542 } 557 }
543 558
544 void WindowTreeClient::OnReceivedCursorLocationMemory( 559 void WindowTreeClient::OnReceivedCursorLocationMemory(
545 mojo::ScopedSharedBufferHandle handle) { 560 mojo::ScopedSharedBufferHandle handle) {
546 cursor_location_mapping_ = handle->Map(sizeof(base::subtle::Atomic32)); 561 cursor_location_mapping_ = handle->Map(sizeof(base::subtle::Atomic32));
547 DCHECK(cursor_location_mapping_); 562 DCHECK(cursor_location_mapping_);
548 } 563 }
549 564
550 void WindowTreeClient::SetWindowBoundsFromServer( 565 void WindowTreeClient::SetWindowBoundsFromServer(
551 WindowMus* window, 566 WindowMus* window,
552 const gfx::Rect& revert_bounds_in_pixels) { 567 const gfx::Rect& revert_bounds_in_pixels,
568 const cc::LocalFrameId& local_frame_id) {
569 cc::FrameSinkId frame_sink_id(window->server_id(), 0);
570 cc::SurfaceId surface_id(frame_sink_id, local_frame_id);
571 fprintf(stderr,
572 ">>>>WindowTreeClient::SetWindowBoundsFromServer %s root? %d\n",
573 surface_id.ToString().c_str(), IsRoot(window));
574
553 if (IsRoot(window)) { 575 if (IsRoot(window)) {
554 // WindowTreeHost expects bounds to be in pixels. 576 // WindowTreeHost expects bounds to be in pixels.
555 GetWindowTreeHostMus(window)->SetBoundsFromServer(revert_bounds_in_pixels); 577 GetWindowTreeHostMus(window)->SetBoundsFromServer(revert_bounds_in_pixels);
556 return;
mfomitchev 2017/01/25 21:41:18 Removing this might be problematic. Not entirely s
557 } 578 }
558 579
559 window->SetBoundsFromServer(gfx::ConvertRectToDIP( 580 window->SetBoundsFromServer(
560 ScaleFactorForDisplay(window->GetWindow()), revert_bounds_in_pixels)); 581 gfx::ConvertRectToDIP(ScaleFactorForDisplay(window->GetWindow()),
582 revert_bounds_in_pixels),
583 local_frame_id);
561 } 584 }
562 585
563 void WindowTreeClient::SetWindowVisibleFromServer(WindowMus* window, 586 void WindowTreeClient::SetWindowVisibleFromServer(WindowMus* window,
564 bool visible) { 587 bool visible) {
565 if (!IsRoot(window)) { 588 if (!IsRoot(window)) {
566 window->SetVisibleFromServer(visible); 589 window->SetVisibleFromServer(visible);
567 return; 590 return;
568 } 591 }
569 592
570 std::unique_ptr<WindowMusChangeData> data = 593 std::unique_ptr<WindowMusChangeData> data =
571 window->PrepareForServerVisibilityChange(visible); 594 window->PrepareForServerVisibilityChange(visible);
572 WindowTreeHostMus* window_tree_host = GetWindowTreeHostMus(window); 595 WindowTreeHostMus* window_tree_host = GetWindowTreeHostMus(window);
573 if (visible) 596 if (visible)
574 window_tree_host->Show(); 597 window_tree_host->Show();
575 else 598 else
576 window_tree_host->Hide(); 599 window_tree_host->Hide();
577 } 600 }
578 601
579 void WindowTreeClient::ScheduleInFlightBoundsChange( 602 void WindowTreeClient::ScheduleInFlightBoundsChange(
580 WindowMus* window, 603 WindowMus* window,
581 const gfx::Rect& old_bounds, 604 const gfx::Rect& old_bounds,
582 const gfx::Rect& new_bounds) { 605 const gfx::Rect& new_bounds) {
583 const uint32_t change_id = ScheduleInFlightChange( 606 cc::FrameSinkId frame_sink_id(window->server_id(), 0);
584 base::MakeUnique<InFlightBoundsChange>(this, window, old_bounds)); 607 std::unique_ptr<cc::SurfaceIdAllocator>& allocator =
585 tree_->SetWindowBounds(change_id, window->server_id(), new_bounds); 608 local_frame_id_allocators_[frame_sink_id];
609 if (!allocator)
610 allocator.reset(new cc::SurfaceIdAllocator());
611 const uint32_t change_id =
612 ScheduleInFlightChange(base::MakeUnique<InFlightBoundsChange>(
613 this, window, old_bounds, allocator->GenerateId()));
614 cc::LocalFrameId local_frame_id;
615 if (!allocator->current_local_frame_id().is_valid() ||
616 new_bounds.size() != old_bounds.size()) {
617 local_frame_id = allocator->GenerateId();
618 } else {
619 local_frame_id = allocator->current_local_frame_id();
620 }
621
622 tree_->SetWindowBounds(change_id, window->server_id(), new_bounds,
623 local_frame_id);
624 // fprintf(stderr, ">>>ScheduleInFlightBoundsChange window_type: %d\n",
625 // window->window_mus_type());
626 // if (window->server_id() == 65566)
627 // base::debug::StackTrace().Print();
628 if (window->GetLayerType() == ui::LAYER_SURFACE)
629 window->SetLocalFrameIdFromServer(local_frame_id);
586 } 630 }
587 631
588 void WindowTreeClient::OnWindowMusCreated(WindowMus* window) { 632 void WindowTreeClient::OnWindowMusCreated(WindowMus* window,
633 ui::LayerType layer_type) {
589 if (window->server_id() != kInvalidServerId) 634 if (window->server_id() != kInvalidServerId)
590 return; 635 return;
591 636
592 window->set_server_id(MakeTransportId(client_id_, next_window_id_++)); 637 window->set_server_id(MakeTransportId(client_id_, next_window_id_++));
593 RegisterWindowMus(window); 638 RegisterWindowMus(window);
594 639
595 DCHECK(window_manager_delegate_ || !IsRoot(window)); 640 DCHECK(window_manager_delegate_ || !IsRoot(window));
596 641
597 std::unordered_map<std::string, std::vector<uint8_t>> transport_properties; 642 std::unordered_map<std::string, std::vector<uint8_t>> transport_properties;
598 std::set<const void*> property_keys = 643 std::set<const void*> property_keys =
599 window->GetWindow()->GetAllPropertKeys(); 644 window->GetWindow()->GetAllPropertKeys();
600 PropertyConverter* property_converter = delegate_->GetPropertyConverter(); 645 PropertyConverter* property_converter = delegate_->GetPropertyConverter();
601 for (const void* key : property_keys) { 646 for (const void* key : property_keys) {
602 std::string transport_name; 647 std::string transport_name;
603 std::unique_ptr<std::vector<uint8_t>> transport_value; 648 std::unique_ptr<std::vector<uint8_t>> transport_value;
604 if (!property_converter->ConvertPropertyForTransport( 649 if (!property_converter->ConvertPropertyForTransport(
605 window->GetWindow(), key, &transport_name, &transport_value)) { 650 window->GetWindow(), key, &transport_name, &transport_value)) {
606 continue; 651 continue;
607 } 652 }
608 if (!transport_value) { 653 if (!transport_value) {
609 transport_properties[transport_name] = std::vector<uint8_t>(); 654 transport_properties[transport_name] = std::vector<uint8_t>();
610 } else { 655 } else {
611 transport_properties[transport_name] = std::move(*transport_value); 656 transport_properties[transport_name] = std::move(*transport_value);
612 } 657 }
613 } 658 }
614 659
615 const uint32_t change_id = ScheduleInFlightChange( 660 const uint32_t change_id = ScheduleInFlightChange(
616 base::MakeUnique<CrashInFlightChange>(window, ChangeType::NEW_WINDOW)); 661 base::MakeUnique<CrashInFlightChange>(window, ChangeType::NEW_WINDOW));
662 cc::FrameSinkId frame_sink_id(window->server_id(), 0);
663 std::unique_ptr<cc::SurfaceIdAllocator>& allocator =
664 local_frame_id_allocators_[frame_sink_id];
665 if (!allocator)
666 allocator.reset(new cc::SurfaceIdAllocator());
667 cc::LocalFrameId local_frame_id = allocator->GenerateId();
617 tree_->NewWindow(change_id, window->server_id(), 668 tree_->NewWindow(change_id, window->server_id(),
618 std::move(transport_properties)); 669 std::move(transport_properties), local_frame_id);
670 window->SetLayerType(layer_type);
671 fprintf(stderr, ">>>New Window window_type: %d\n", window->window_mus_type());
672 // if (window->server_id() == 65566)
673 // base::debug::StackTrace().Print();
674 if (layer_type == ui::LAYER_SURFACE)
675 window->SetLocalFrameIdFromServer(local_frame_id);
619 } 676 }
620 677
621 void WindowTreeClient::OnWindowMusDestroyed(WindowMus* window, Origin origin) { 678 void WindowTreeClient::OnWindowMusDestroyed(WindowMus* window, Origin origin) {
622 if (focus_synchronizer_->focused_window() == window) 679 if (focus_synchronizer_->focused_window() == window)
623 focus_synchronizer_->OnFocusedWindowDestroyed(); 680 focus_synchronizer_->OnFocusedWindowDestroyed();
624 681
625 // TODO: decide how to deal with windows not owned by this client. 682 // TODO: decide how to deal with windows not owned by this client.
626 if (origin == Origin::CLIENT && 683 if (origin == Origin::CLIENT &&
627 (WasCreatedByThisClient(window) || IsRoot(window))) { 684 (WasCreatedByThisClient(window) || IsRoot(window))) {
628 const uint32_t change_id = 685 const uint32_t change_id =
(...skipping 20 matching lines...) Expand all
649 } 706 }
650 for (auto change_id : in_flight_change_ids_to_remove) 707 for (auto change_id : in_flight_change_ids_to_remove)
651 in_flight_map_.erase(change_id); 708 in_flight_map_.erase(change_id);
652 709
653 roots_.erase(window); 710 roots_.erase(window);
654 } 711 }
655 712
656 void WindowTreeClient::OnWindowMusBoundsChanged(WindowMus* window, 713 void WindowTreeClient::OnWindowMusBoundsChanged(WindowMus* window,
657 const gfx::Rect& old_bounds, 714 const gfx::Rect& old_bounds,
658 const gfx::Rect& new_bounds) { 715 const gfx::Rect& new_bounds) {
716 // Called from window->SetBounds in aura.
659 // Changes to bounds of root windows are routed through 717 // Changes to bounds of root windows are routed through
660 // OnWindowTreeHostBoundsWillChange(). Any bounds that happen here are a side 718 // OnWindowTreeHostBoundsWillChange(). Any bounds that happen here are a side
661 // effect of those and can be ignored. 719 // effect of those and can be ignored.
662 if (IsRoot(window)) 720 if (IsRoot(window))
663 return; 721 return;
664 722
665 float device_scale_factor = ScaleFactorForDisplay(window->GetWindow()); 723 float device_scale_factor = ScaleFactorForDisplay(window->GetWindow());
666 ScheduleInFlightBoundsChange( 724 ScheduleInFlightBoundsChange(
667 window, gfx::ConvertRectToPixel(device_scale_factor, old_bounds), 725 window, gfx::ConvertRectToPixel(device_scale_factor, old_bounds),
668 gfx::ConvertRectToPixel(device_scale_factor, new_bounds)); 726 gfx::ConvertRectToPixel(device_scale_factor, new_bounds));
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 967
910 void WindowTreeClient::OnTopLevelCreated(uint32_t change_id, 968 void WindowTreeClient::OnTopLevelCreated(uint32_t change_id,
911 ui::mojom::WindowDataPtr data, 969 ui::mojom::WindowDataPtr data,
912 int64_t display_id, 970 int64_t display_id,
913 bool drawn) { 971 bool drawn) {
914 // The server ack'd the top level window we created and supplied the state 972 // The server ack'd the top level window we created and supplied the state
915 // of the window at the time the server created it. For properties we do not 973 // of the window at the time the server created it. For properties we do not
916 // have changes in flight for we can update them immediately. For properties 974 // have changes in flight for we can update them immediately. For properties
917 // with changes in flight we set the revert value from the server. 975 // with changes in flight we set the revert value from the server.
918 976
977 const cc::LocalFrameId local_frame_id(data->local_frame_id);
919 if (!in_flight_map_.count(change_id)) { 978 if (!in_flight_map_.count(change_id)) {
920 // The window may have been destroyed locally before the server could finish 979 // The window may have been destroyed locally before the server could finish
921 // creating the window, and before the server received the notification that 980 // creating the window, and before the server received the notification that
922 // the window has been destroyed. 981 // the window has been destroyed.
982 fprintf(stderr,
983 ">>>WindowTreeClient::OnTopLevelCreated early exit server_id: %d, "
984 "localframeid: %s\n",
985 data->window_id, local_frame_id.ToString().c_str());
923 return; 986 return;
924 } 987 }
925 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); 988 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id]));
926 in_flight_map_.erase(change_id); 989 in_flight_map_.erase(change_id);
927 990
928 WindowMus* window = change->window(); 991 WindowMus* window = change->window();
929 WindowTreeHostMus* window_tree_host = GetWindowTreeHostMus(window); 992 WindowTreeHostMus* window_tree_host = GetWindowTreeHostMus(window);
930 993
931 // Drawn state and display-id always come from the server (they can't be 994 // Drawn state and display-id always come from the server (they can't be
932 // modified locally). 995 // modified locally).
933 window_tree_host->set_display_id(display_id); 996 window_tree_host->set_display_id(display_id);
934 997
935 // The default visibilty is false, we only need update visibility if it 998 // The default visibilty is false, we only need update visibility if it
936 // differs from that. 999 // differs from that.
937 if (data->visible) { 1000 if (data->visible) {
938 InFlightVisibleChange visible_change(this, window, data->visible); 1001 InFlightVisibleChange visible_change(this, window, data->visible);
939 InFlightChange* current_change = 1002 InFlightChange* current_change =
940 GetOldestInFlightChangeMatching(visible_change); 1003 GetOldestInFlightChangeMatching(visible_change);
941 if (current_change) 1004 if (current_change)
942 current_change->SetRevertValueFrom(visible_change); 1005 current_change->SetRevertValueFrom(visible_change);
943 else 1006 else
944 SetWindowVisibleFromServer(window, true); 1007 SetWindowVisibleFromServer(window, true);
945 } 1008 }
946 1009
947 const gfx::Rect bounds(data->bounds); 1010 const gfx::Rect bounds(data->bounds);
1011 fprintf(stderr,
1012 ">>>WindowTreeClient::OnTopLevelCreated server_id: %d, localframeid: "
1013 "%s\n",
1014 window->server_id(), local_frame_id.ToString().c_str());
948 { 1015 {
949 InFlightBoundsChange bounds_change(this, window, bounds); 1016 InFlightBoundsChange bounds_change(this, window, bounds, local_frame_id);
950 InFlightChange* current_change = 1017 InFlightChange* current_change =
951 GetOldestInFlightChangeMatching(bounds_change); 1018 GetOldestInFlightChangeMatching(bounds_change);
1019 // TODO(fsamuel): We need to inform the window even if bounds have not
1020 // changed because the embedded LocalFrameId might have changed.
952 if (current_change) 1021 if (current_change)
953 current_change->SetRevertValueFrom(bounds_change); 1022 current_change->SetRevertValueFrom(bounds_change);
954 else if (gfx::ConvertRectToPixel(ScaleFactorForDisplay(window->GetWindow()), 1023 else /*if
1024 (gfx::ConvertRectToPixel(ScaleFactorForDisplay(window->GetWindow()),
955 window->GetWindow()->bounds()) != bounds) 1025 window->GetWindow()->bounds()) != bounds)
956 SetWindowBoundsFromServer(window, bounds); 1026 */
1027 SetWindowBoundsFromServer(window, bounds, local_frame_id);
957 } 1028 }
958 1029
959 // There is currently no API to bulk set properties, so we iterate over each 1030 // There is currently no API to bulk set properties, so we iterate over each
960 // property individually. 1031 // property individually.
961 for (const auto& pair : data->properties) { 1032 for (const auto& pair : data->properties) {
962 std::unique_ptr<std::vector<uint8_t>> revert_value( 1033 std::unique_ptr<std::vector<uint8_t>> revert_value(
963 base::MakeUnique<std::vector<uint8_t>>(pair.second)); 1034 base::MakeUnique<std::vector<uint8_t>>(pair.second));
964 InFlightPropertyChange property_change(window, pair.first, 1035 InFlightPropertyChange property_change(window, pair.first,
965 std::move(revert_value)); 1036 std::move(revert_value));
966 InFlightChange* current_change = 1037 InFlightChange* current_change =
967 GetOldestInFlightChangeMatching(property_change); 1038 GetOldestInFlightChangeMatching(property_change);
968 if (current_change) { 1039 if (current_change) {
969 current_change->SetRevertValueFrom(property_change); 1040 current_change->SetRevertValueFrom(property_change);
970 } else { 1041 } else {
971 window->SetPropertyFromServer(pair.first, &pair.second); 1042 window->SetPropertyFromServer(pair.first, &pair.second);
972 } 1043 }
973 } 1044 }
974 1045
975 // Top level windows should not have a parent. 1046 // Top level windows should not have a parent.
976 DCHECK_EQ(0u, data->parent_id); 1047 DCHECK_EQ(0u, data->parent_id);
977 } 1048 }
978 1049
979 void WindowTreeClient::OnWindowBoundsChanged(Id window_id, 1050 void WindowTreeClient::OnWindowBoundsChanged(
980 const gfx::Rect& old_bounds, 1051 Id window_id,
981 const gfx::Rect& new_bounds) { 1052 const gfx::Rect& old_bounds,
1053 const gfx::Rect& new_bounds,
1054 const cc::LocalFrameId& local_frame_id) {
982 WindowMus* window = GetWindowByServerId(window_id); 1055 WindowMus* window = GetWindowByServerId(window_id);
983 if (!window) 1056 if (!window)
984 return; 1057 return;
985 1058
986 InFlightBoundsChange new_change(this, window, new_bounds); 1059 InFlightBoundsChange new_change(this, window, new_bounds, local_frame_id);
987 if (ApplyServerChangeToExistingInFlightChange(new_change)) 1060 if (ApplyServerChangeToExistingInFlightChange(new_change))
988 return; 1061 return;
989 1062
990 SetWindowBoundsFromServer(window, new_bounds); 1063 SetWindowBoundsFromServer(window, new_bounds, local_frame_id);
991 } 1064 }
992 1065
993 void WindowTreeClient::OnClientAreaChanged( 1066 void WindowTreeClient::OnClientAreaChanged(
994 uint32_t window_id, 1067 uint32_t window_id,
995 const gfx::Insets& new_client_area, 1068 const gfx::Insets& new_client_area,
996 const std::vector<gfx::Rect>& new_additional_client_areas) { 1069 const std::vector<gfx::Rect>& new_additional_client_areas) {
997 WindowMus* window = GetWindowByServerId(window_id); 1070 WindowMus* window = GetWindowByServerId(window_id);
998 if (!window) 1071 if (!window)
999 return; 1072 return;
1000 1073
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
1368 } 1441 }
1369 1442
1370 void WindowTreeClient::WmDisplayModified(const display::Display& display) { 1443 void WindowTreeClient::WmDisplayModified(const display::Display& display) {
1371 DCHECK(window_manager_delegate_); 1444 DCHECK(window_manager_delegate_);
1372 // TODO(sky): this should likely route to WindowTreeHost. 1445 // TODO(sky): this should likely route to WindowTreeHost.
1373 window_manager_delegate_->OnWmDisplayModified(display); 1446 window_manager_delegate_->OnWmDisplayModified(display);
1374 } 1447 }
1375 1448
1376 void WindowTreeClient::WmSetBounds(uint32_t change_id, 1449 void WindowTreeClient::WmSetBounds(uint32_t change_id,
1377 Id window_id, 1450 Id window_id,
1378 const gfx::Rect& transit_bounds_in_pixels) { 1451 const gfx::Rect& transit_bounds_in_pixels,
1452 const cc::LocalFrameId& local_frame_id) {
1379 WindowMus* window = GetWindowByServerId(window_id); 1453 WindowMus* window = GetWindowByServerId(window_id);
1380 bool result = false; 1454 bool result = false;
1381 if (window) { 1455 if (window) {
1382 float device_scale_factor = ScaleFactorForDisplay(window->GetWindow()); 1456 float device_scale_factor = ScaleFactorForDisplay(window->GetWindow());
1383 DCHECK(window_manager_delegate_); 1457 DCHECK(window_manager_delegate_);
1384 gfx::Rect transit_bounds_in_dip = 1458 gfx::Rect transit_bounds_in_dip =
1385 gfx::ConvertRectToDIP(device_scale_factor, transit_bounds_in_pixels); 1459 gfx::ConvertRectToDIP(device_scale_factor, transit_bounds_in_pixels);
1386 gfx::Rect bounds_in_dip = transit_bounds_in_dip; 1460 gfx::Rect bounds_in_dip = transit_bounds_in_dip;
1387 // TODO: this needs to trigger scheduling a bounds change on |window|. 1461 // TODO: this needs to trigger scheduling a bounds change on |window|.
1388 result = window_manager_delegate_->OnWmSetBounds(window->GetWindow(), 1462 result = window_manager_delegate_->OnWmSetBounds(window->GetWindow(),
1389 &bounds_in_dip); 1463 &bounds_in_dip);
1390 if (result) { 1464 if (result) {
1391 // If the resulting bounds differ return false. Returning false ensures 1465 // If the resulting bounds differ return false. Returning false ensures
1392 // the client applies the bounds we set below. 1466 // the client applies the bounds we set below.
1393 result = bounds_in_dip == transit_bounds_in_dip; 1467 result = bounds_in_dip == transit_bounds_in_dip;
1394 window->SetBoundsFromServer(bounds_in_dip); 1468 window->SetBoundsFromServer(bounds_in_dip, local_frame_id);
1395 } 1469 }
1396 } 1470 }
1397 if (window_manager_internal_client_) 1471 if (window_manager_internal_client_)
1398 window_manager_internal_client_->WmResponse(change_id, result); 1472 window_manager_internal_client_->WmResponse(change_id, result);
1399 } 1473 }
1400 1474
1401 void WindowTreeClient::WmSetProperty( 1475 void WindowTreeClient::WmSetProperty(
1402 uint32_t change_id, 1476 uint32_t change_id,
1403 Id window_id, 1477 Id window_id,
1404 const std::string& name, 1478 const std::string& name,
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
1663 tree_->StackAtTop(change_id, window->server_id()); 1737 tree_->StackAtTop(change_id, window->server_id());
1664 } 1738 }
1665 1739
1666 std::unique_ptr<WindowPortMus> WindowTreeClient::CreateWindowPortForTopLevel( 1740 std::unique_ptr<WindowPortMus> WindowTreeClient::CreateWindowPortForTopLevel(
1667 const std::map<std::string, std::vector<uint8_t>>* properties) { 1741 const std::map<std::string, std::vector<uint8_t>>* properties) {
1668 std::unique_ptr<WindowPortMus> window_port = 1742 std::unique_ptr<WindowPortMus> window_port =
1669 base::MakeUnique<WindowPortMus>(this, WindowMusType::TOP_LEVEL); 1743 base::MakeUnique<WindowPortMus>(this, WindowMusType::TOP_LEVEL);
1670 roots_.insert(window_port.get()); 1744 roots_.insert(window_port.get());
1671 1745
1672 window_port->set_server_id(MakeTransportId(client_id_, next_window_id_++)); 1746 window_port->set_server_id(MakeTransportId(client_id_, next_window_id_++));
1747 fprintf(stderr,
1748 ">>>WindowTreeClient::CreateWindowPortForTopLevel server_id: %d\n",
1749 window_port->server_id());
1673 RegisterWindowMus(window_port.get()); 1750 RegisterWindowMus(window_port.get());
1674 1751
1675 std::unordered_map<std::string, std::vector<uint8_t>> transport_properties; 1752 std::unordered_map<std::string, std::vector<uint8_t>> transport_properties;
1676 if (properties) { 1753 if (properties) {
1677 for (const auto& property_pair : *properties) 1754 for (const auto& property_pair : *properties)
1678 transport_properties[property_pair.first] = property_pair.second; 1755 transport_properties[property_pair.first] = property_pair.second;
1679 } 1756 }
1680 1757
1681 const uint32_t change_id = 1758 const uint32_t change_id =
1682 ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>( 1759 ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>(
1683 window_port.get(), ChangeType::NEW_TOP_LEVEL_WINDOW)); 1760 window_port.get(), ChangeType::NEW_TOP_LEVEL_WINDOW));
1684 tree_->NewTopLevelWindow(change_id, window_port->server_id(), 1761 tree_->NewTopLevelWindow(change_id, window_port->server_id(),
1685 transport_properties); 1762 transport_properties);
1763
1764 // if (window_port->server_id() == 65566)
1765 // base::debug::StackTrace().Print();
1686 return window_port; 1766 return window_port;
1687 } 1767 }
1688 1768
1689 void WindowTreeClient::OnWindowTreeHostCreated( 1769 void WindowTreeClient::OnWindowTreeHostCreated(
1690 WindowTreeHostMus* window_tree_host) { 1770 WindowTreeHostMus* window_tree_host) {
1691 // All WindowTreeHosts are destroyed before this, so we don't need to unset 1771 // All WindowTreeHosts are destroyed before this, so we don't need to unset
1692 // the DragDropClient. 1772 // the DragDropClient.
1693 client::SetDragDropClient(window_tree_host->window(), 1773 client::SetDragDropClient(window_tree_host->window(),
1694 drag_drop_controller_.get()); 1774 drag_drop_controller_.get());
1695 } 1775 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1770 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( 1850 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>(
1771 this, capture_synchronizer_.get(), window)); 1851 this, capture_synchronizer_.get(), window));
1772 } 1852 }
1773 1853
1774 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { 1854 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) {
1775 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( 1855 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>(
1776 this, focus_synchronizer_.get(), window)); 1856 this, focus_synchronizer_.get(), window));
1777 } 1857 }
1778 1858
1779 } // namespace aura 1859 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/mus/window_tree_client.h ('k') | ui/aura/mus/window_tree_host_mus.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698