| 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 "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> |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 #if defined(HiWord) | 59 #if defined(HiWord) |
| 60 #undef HiWord | 60 #undef HiWord |
| 61 #endif | 61 #endif |
| 62 #if defined(LoWord) | 62 #if defined(LoWord) |
| 63 #undef LoWord | 63 #undef LoWord |
| 64 #endif | 64 #endif |
| 65 | 65 |
| 66 namespace aura { | 66 namespace aura { |
| 67 namespace { | 67 namespace { |
| 68 | 68 |
| 69 // This serves to document the places that rely on bounds changes to the |
| 70 // root window being ignored. |
| 71 constexpr bool kRootWindowBoundsChangesAreIgnored = true; |
| 72 |
| 69 Id MakeTransportId(ClientSpecificId client_id, ClientSpecificId local_id) { | 73 Id MakeTransportId(ClientSpecificId client_id, ClientSpecificId local_id) { |
| 70 return (client_id << 16) | local_id; | 74 return (client_id << 16) | local_id; |
| 71 } | 75 } |
| 72 | 76 |
| 73 inline uint16_t HiWord(uint32_t id) { | 77 inline uint16_t HiWord(uint32_t id) { |
| 74 return static_cast<uint16_t>((id >> 16) & 0xFFFF); | 78 return static_cast<uint16_t>((id >> 16) & 0xFFFF); |
| 75 } | 79 } |
| 76 | 80 |
| 77 struct WindowPortPropertyDataMus : public ui::PropertyData { | 81 struct WindowPortPropertyDataMus : public ui::PropertyData { |
| 78 std::string transport_name; | 82 std::string transport_name; |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 std::unique_ptr<WindowTreeHostMus> window_tree_host = | 574 std::unique_ptr<WindowTreeHostMus> window_tree_host = |
| 571 CreateWindowTreeHost(WindowMusType::EMBED, *root_data, display_id, | 575 CreateWindowTreeHost(WindowMusType::EMBED, *root_data, display_id, |
| 572 frame_sink_id, local_surface_id); | 576 frame_sink_id, local_surface_id); |
| 573 | 577 |
| 574 focus_synchronizer_->SetFocusFromServer( | 578 focus_synchronizer_->SetFocusFromServer( |
| 575 GetWindowByServerId(focused_window_id)); | 579 GetWindowByServerId(focused_window_id)); |
| 576 | 580 |
| 577 delegate_->OnEmbed(std::move(window_tree_host)); | 581 delegate_->OnEmbed(std::move(window_tree_host)); |
| 578 } | 582 } |
| 579 | 583 |
| 584 void WindowTreeClient::OnSetDisplayRootDone( |
| 585 Id window_id, |
| 586 const base::Optional<cc::FrameSinkId>& frame_sink_id) { |
| 587 // The only way SetDisplayRoot() should fail is if we've done something wrong. |
| 588 CHECK(frame_sink_id); |
| 589 |
| 590 WindowMus* window = GetWindowByServerId(window_id); |
| 591 if (!window) |
| 592 return; // Display was already deleted. |
| 593 |
| 594 window->SetFrameSinkIdFromServer(*frame_sink_id); |
| 595 } |
| 596 |
| 580 WindowTreeHostMus* WindowTreeClient::WmNewDisplayAddedImpl( | 597 WindowTreeHostMus* WindowTreeClient::WmNewDisplayAddedImpl( |
| 581 const display::Display& display, | 598 const display::Display& display, |
| 582 ui::mojom::WindowDataPtr root_data, | 599 ui::mojom::WindowDataPtr root_data, |
| 583 bool parent_drawn, | 600 bool parent_drawn, |
| 584 const cc::FrameSinkId& frame_sink_id, | 601 const cc::FrameSinkId& frame_sink_id, |
| 585 const base::Optional<cc::LocalSurfaceId>& local_surface_id) { | 602 const base::Optional<cc::LocalSurfaceId>& local_surface_id) { |
| 586 DCHECK(window_manager_delegate_); | 603 DCHECK(window_manager_delegate_); |
| 587 | 604 |
| 588 got_initial_displays_ = true; | 605 got_initial_displays_ = true; |
| 589 | 606 |
| 590 window_manager_delegate_->OnWmWillCreateDisplay(display); | 607 window_manager_delegate_->OnWmWillCreateDisplay(display); |
| 591 | 608 |
| 592 std::unique_ptr<WindowTreeHostMus> window_tree_host = | 609 std::unique_ptr<WindowTreeHostMus> window_tree_host = CreateWindowTreeHost( |
| 593 CreateWindowTreeHost(WindowMusType::DISPLAY, *root_data, display.id(), | 610 WindowMusType::DISPLAY_AUTOMATICALLY_CREATED, *root_data, display.id(), |
| 594 frame_sink_id, local_surface_id); | 611 frame_sink_id, local_surface_id); |
| 595 | 612 |
| 596 WindowTreeHostMus* window_tree_host_ptr = window_tree_host.get(); | 613 WindowTreeHostMus* window_tree_host_ptr = window_tree_host.get(); |
| 597 window_manager_delegate_->OnWmNewDisplay(std::move(window_tree_host), | 614 window_manager_delegate_->OnWmNewDisplay(std::move(window_tree_host), |
| 598 display); | 615 display); |
| 599 return window_tree_host_ptr; | 616 return window_tree_host_ptr; |
| 600 } | 617 } |
| 601 | 618 |
| 602 std::unique_ptr<EventResultCallback> | 619 std::unique_ptr<EventResultCallback> |
| 603 WindowTreeClient::CreateEventResultCallback(int32_t event_id) { | 620 WindowTreeClient::CreateEventResultCallback(int32_t event_id) { |
| 604 return base::MakeUnique<EventResultCallback>( | 621 return base::MakeUnique<EventResultCallback>( |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 continue; | 703 continue; |
| 687 } | 704 } |
| 688 transport_properties[transport_name] = | 705 transport_properties[transport_name] = |
| 689 transport_value ? std::move(*transport_value) : std::vector<uint8_t>(); | 706 transport_value ? std::move(*transport_value) : std::vector<uint8_t>(); |
| 690 } | 707 } |
| 691 | 708 |
| 692 const uint32_t change_id = ScheduleInFlightChange( | 709 const uint32_t change_id = ScheduleInFlightChange( |
| 693 base::MakeUnique<CrashInFlightChange>(window, ChangeType::NEW_WINDOW)); | 710 base::MakeUnique<CrashInFlightChange>(window, ChangeType::NEW_WINDOW)); |
| 694 tree_->NewWindow(change_id, window->server_id(), | 711 tree_->NewWindow(change_id, window->server_id(), |
| 695 std::move(transport_properties)); | 712 std::move(transport_properties)); |
| 713 if (window->window_mus_type() == WindowMusType::DISPLAY_MANUALLY_CREATED) { |
| 714 WindowTreeHostMus* window_tree_host = GetWindowTreeHostMus(window); |
| 715 std::unique_ptr<DisplayInitParams> display_init_params = |
| 716 window_tree_host->ReleaseDisplayInitParams(); |
| 717 DCHECK(display_init_params); |
| 718 display::Display display; |
| 719 if (display_init_params->display) { |
| 720 display = *display_init_params->display; |
| 721 } else { |
| 722 const bool has_display = |
| 723 display::Screen::GetScreen()->GetDisplayWithDisplayId( |
| 724 window_tree_host->display_id(), &display); |
| 725 DCHECK(has_display); |
| 726 } |
| 727 // As |window| is a root, changes to its bounds are ignored (it's assumed |
| 728 // bounds changes are routed through OnWindowTreeHostBoundsWillChange()). |
| 729 // But the display is created with an initial bounds, and we need to push |
| 730 // that to the server. |
| 731 DCHECK(kRootWindowBoundsChangesAreIgnored); |
| 732 ScheduleInFlightBoundsChange( |
| 733 window, gfx::Rect(), |
| 734 gfx::Rect( |
| 735 display_init_params->viewport_metrics.bounds_in_pixels.size())); |
| 736 |
| 737 // Tests may not config |window_manager_internal_client_|. |
| 738 if (window_manager_internal_client_) { |
| 739 window_manager_internal_client_->SetDisplayRoot( |
| 740 display, display_init_params->viewport_metrics.Clone(), |
| 741 display_init_params->is_primary_display, window->server_id(), |
| 742 base::Bind(&WindowTreeClient::OnSetDisplayRootDone, |
| 743 base::Unretained(this), window->server_id())); |
| 744 } |
| 745 } |
| 696 } | 746 } |
| 697 | 747 |
| 698 void WindowTreeClient::OnWindowMusDestroyed(WindowMus* window, Origin origin) { | 748 void WindowTreeClient::OnWindowMusDestroyed(WindowMus* window, Origin origin) { |
| 699 if (focus_synchronizer_->focused_window() == window) | 749 if (focus_synchronizer_->focused_window() == window) |
| 700 focus_synchronizer_->OnFocusedWindowDestroyed(); | 750 focus_synchronizer_->OnFocusedWindowDestroyed(); |
| 701 | 751 |
| 702 // TODO: decide how to deal with windows not owned by this client. | 752 // TODO: decide how to deal with windows not owned by this client. |
| 703 if (origin == Origin::CLIENT && | 753 if (origin == Origin::CLIENT && |
| 704 (WasCreatedByThisClient(window) || IsRoot(window))) { | 754 (WasCreatedByThisClient(window) || IsRoot(window))) { |
| 705 const uint32_t change_id = | 755 const uint32_t change_id = |
| (...skipping 23 matching lines...) Expand all Loading... |
| 729 | 779 |
| 730 roots_.erase(window); | 780 roots_.erase(window); |
| 731 } | 781 } |
| 732 | 782 |
| 733 void WindowTreeClient::OnWindowMusBoundsChanged(WindowMus* window, | 783 void WindowTreeClient::OnWindowMusBoundsChanged(WindowMus* window, |
| 734 const gfx::Rect& old_bounds, | 784 const gfx::Rect& old_bounds, |
| 735 const gfx::Rect& new_bounds) { | 785 const gfx::Rect& new_bounds) { |
| 736 // Changes to bounds of root windows are routed through | 786 // Changes to bounds of root windows are routed through |
| 737 // OnWindowTreeHostBoundsWillChange(). Any bounds that happen here are a side | 787 // OnWindowTreeHostBoundsWillChange(). Any bounds that happen here are a side |
| 738 // effect of those and can be ignored. | 788 // effect of those and can be ignored. |
| 739 if (IsRoot(window)) | 789 if (IsRoot(window)) { |
| 790 DCHECK(kRootWindowBoundsChangesAreIgnored); |
| 740 return; | 791 return; |
| 792 } |
| 741 | 793 |
| 742 float device_scale_factor = ScaleFactorForDisplay(window->GetWindow()); | 794 float device_scale_factor = ScaleFactorForDisplay(window->GetWindow()); |
| 743 ScheduleInFlightBoundsChange( | 795 ScheduleInFlightBoundsChange( |
| 744 window, gfx::ConvertRectToPixel(device_scale_factor, old_bounds), | 796 window, gfx::ConvertRectToPixel(device_scale_factor, old_bounds), |
| 745 gfx::ConvertRectToPixel(device_scale_factor, new_bounds)); | 797 gfx::ConvertRectToPixel(device_scale_factor, new_bounds)); |
| 746 } | 798 } |
| 747 | 799 |
| 748 void WindowTreeClient::OnWindowMusAddChild(WindowMus* parent, | 800 void WindowTreeClient::OnWindowMusAddChild(WindowMus* parent, |
| 749 WindowMus* child) { | 801 WindowMus* child) { |
| 750 // TODO: add checks to ensure this can work. | 802 // TODO: add checks to ensure this can work. |
| (...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1418 if (got_initial_displays_) | 1470 if (got_initial_displays_) |
| 1419 return true; | 1471 return true; |
| 1420 | 1472 |
| 1421 bool valid_wait = true; | 1473 bool valid_wait = true; |
| 1422 // TODO(sky): having to block here is not ideal. http://crbug.com/594852. | 1474 // TODO(sky): having to block here is not ideal. http://crbug.com/594852. |
| 1423 while (!got_initial_displays_ && valid_wait) | 1475 while (!got_initial_displays_ && valid_wait) |
| 1424 valid_wait = binding_.WaitForIncomingMethodCall(); | 1476 valid_wait = binding_.WaitForIncomingMethodCall(); |
| 1425 return valid_wait; | 1477 return valid_wait; |
| 1426 } | 1478 } |
| 1427 | 1479 |
| 1480 WindowTreeHostMusInitParams WindowTreeClient::CreateInitParamsForNewDisplay() { |
| 1481 WindowTreeHostMusInitParams init_params; |
| 1482 init_params.window_port = base::MakeUnique<WindowPortMus>( |
| 1483 this, WindowMusType::DISPLAY_MANUALLY_CREATED); |
| 1484 roots_.insert(init_params.window_port.get()); |
| 1485 init_params.window_tree_client = this; |
| 1486 return init_params; |
| 1487 } |
| 1488 |
| 1428 void WindowTreeClient::OnConnect(ClientSpecificId client_id) { | 1489 void WindowTreeClient::OnConnect(ClientSpecificId client_id) { |
| 1429 client_id_ = client_id; | 1490 client_id_ = client_id; |
| 1430 if (window_manager_delegate_) | 1491 if (window_manager_delegate_) |
| 1431 window_manager_delegate_->OnWmConnected(); | 1492 window_manager_delegate_->OnWmConnected(); |
| 1432 } | 1493 } |
| 1433 | 1494 |
| 1434 void WindowTreeClient::WmNewDisplayAdded( | 1495 void WindowTreeClient::WmNewDisplayAdded( |
| 1435 const display::Display& display, | 1496 const display::Display& display, |
| 1436 ui::mojom::WindowDataPtr root_data, | 1497 ui::mojom::WindowDataPtr root_data, |
| 1437 bool parent_drawn, | 1498 bool parent_drawn, |
| (...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1970 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( | 2031 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( |
| 1971 this, capture_synchronizer_.get(), window)); | 2032 this, capture_synchronizer_.get(), window)); |
| 1972 } | 2033 } |
| 1973 | 2034 |
| 1974 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { | 2035 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { |
| 1975 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( | 2036 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( |
| 1976 this, focus_synchronizer_.get(), window)); | 2037 this, focus_synchronizer_.get(), window)); |
| 1977 } | 2038 } |
| 1978 | 2039 |
| 1979 } // namespace aura | 2040 } // namespace aura |
| OLD | NEW |