| 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 ui::mojom::WmViewportMetricsPtr viewport_metrics = |
| 716 window_tree_host->ReleaseInitialMetrics(); |
| 717 DCHECK(viewport_metrics); |
| 718 display::Display display; |
| 719 std::unique_ptr<display::Display> initial_display = |
| 720 window_tree_host->ReleaseInitialDisplay(); |
| 721 if (initial_display) { |
| 722 display = *initial_display; |
| 723 } else { |
| 724 const bool has_display = |
| 725 display::Screen::GetScreen()->GetDisplayWithDisplayId( |
| 726 window_tree_host->display_id(), &display); |
| 727 DCHECK(has_display); |
| 728 } |
| 729 // As |window| is a root, changes to its bounds are ignored (it's assumed |
| 730 // bounds changes are routed through OnWindowTreeHostBoundsWillChange()). |
| 731 // But the display is created with an initial bounds, and we need to push |
| 732 // that to the server. |
| 733 DCHECK(kRootWindowBoundsChangesAreIgnored); |
| 734 ScheduleInFlightBoundsChange( |
| 735 window, gfx::Rect(), |
| 736 gfx::Rect(viewport_metrics->bounds_in_pixels.size())); |
| 737 |
| 738 // TODO: file bug on this, need to map to primary. |
| 739 const bool is_primary_display = true; |
| 740 // Tests may not config |window_manager_internal_client_|. |
| 741 if (window_manager_internal_client_) { |
| 742 window_manager_internal_client_->SetDisplayRoot( |
| 743 display, std::move(viewport_metrics), is_primary_display, |
| 744 window->server_id(), |
| 745 base::Bind(&WindowTreeClient::OnSetDisplayRootDone, |
| 746 base::Unretained(this), window->server_id())); |
| 747 } |
| 748 } |
| 696 } | 749 } |
| 697 | 750 |
| 698 void WindowTreeClient::OnWindowMusDestroyed(WindowMus* window, Origin origin) { | 751 void WindowTreeClient::OnWindowMusDestroyed(WindowMus* window, Origin origin) { |
| 699 if (focus_synchronizer_->focused_window() == window) | 752 if (focus_synchronizer_->focused_window() == window) |
| 700 focus_synchronizer_->OnFocusedWindowDestroyed(); | 753 focus_synchronizer_->OnFocusedWindowDestroyed(); |
| 701 | 754 |
| 702 // TODO: decide how to deal with windows not owned by this client. | 755 // TODO: decide how to deal with windows not owned by this client. |
| 703 if (origin == Origin::CLIENT && | 756 if (origin == Origin::CLIENT && |
| 704 (WasCreatedByThisClient(window) || IsRoot(window))) { | 757 (WasCreatedByThisClient(window) || IsRoot(window))) { |
| 705 const uint32_t change_id = | 758 const uint32_t change_id = |
| (...skipping 23 matching lines...) Expand all Loading... |
| 729 | 782 |
| 730 roots_.erase(window); | 783 roots_.erase(window); |
| 731 } | 784 } |
| 732 | 785 |
| 733 void WindowTreeClient::OnWindowMusBoundsChanged(WindowMus* window, | 786 void WindowTreeClient::OnWindowMusBoundsChanged(WindowMus* window, |
| 734 const gfx::Rect& old_bounds, | 787 const gfx::Rect& old_bounds, |
| 735 const gfx::Rect& new_bounds) { | 788 const gfx::Rect& new_bounds) { |
| 736 // Changes to bounds of root windows are routed through | 789 // Changes to bounds of root windows are routed through |
| 737 // OnWindowTreeHostBoundsWillChange(). Any bounds that happen here are a side | 790 // OnWindowTreeHostBoundsWillChange(). Any bounds that happen here are a side |
| 738 // effect of those and can be ignored. | 791 // effect of those and can be ignored. |
| 739 if (IsRoot(window)) | 792 if (IsRoot(window)) { |
| 793 DCHECK(kRootWindowBoundsChangesAreIgnored); |
| 740 return; | 794 return; |
| 795 } |
| 741 | 796 |
| 742 float device_scale_factor = ScaleFactorForDisplay(window->GetWindow()); | 797 float device_scale_factor = ScaleFactorForDisplay(window->GetWindow()); |
| 743 ScheduleInFlightBoundsChange( | 798 ScheduleInFlightBoundsChange( |
| 744 window, gfx::ConvertRectToPixel(device_scale_factor, old_bounds), | 799 window, gfx::ConvertRectToPixel(device_scale_factor, old_bounds), |
| 745 gfx::ConvertRectToPixel(device_scale_factor, new_bounds)); | 800 gfx::ConvertRectToPixel(device_scale_factor, new_bounds)); |
| 746 } | 801 } |
| 747 | 802 |
| 748 void WindowTreeClient::OnWindowMusAddChild(WindowMus* parent, | 803 void WindowTreeClient::OnWindowMusAddChild(WindowMus* parent, |
| 749 WindowMus* child) { | 804 WindowMus* child) { |
| 750 // TODO: add checks to ensure this can work. | 805 // TODO: add checks to ensure this can work. |
| (...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1408 WindowMus* window = GetWindowByServerId(window_id); | 1463 WindowMus* window = GetWindowByServerId(window_id); |
| 1409 if (!window || !IsRoot(window)) | 1464 if (!window || !IsRoot(window)) |
| 1410 return; | 1465 return; |
| 1411 | 1466 |
| 1412 // Since the window is the root window, we send close request to the entire | 1467 // Since the window is the root window, we send close request to the entire |
| 1413 // WindowTreeHost. | 1468 // WindowTreeHost. |
| 1414 GetWindowTreeHostMus(window->GetWindow())->OnCloseRequest(); | 1469 GetWindowTreeHostMus(window->GetWindow())->OnCloseRequest(); |
| 1415 } | 1470 } |
| 1416 | 1471 |
| 1417 bool WindowTreeClient::WaitForInitialDisplays() { | 1472 bool WindowTreeClient::WaitForInitialDisplays() { |
| 1473 LOG(WARNING) << "WaitForInitialDisplays got=" << got_initial_displays_; |
| 1418 if (got_initial_displays_) | 1474 if (got_initial_displays_) |
| 1419 return true; | 1475 return true; |
| 1420 | 1476 |
| 1421 bool valid_wait = true; | 1477 bool valid_wait = true; |
| 1422 // TODO(sky): having to block here is not ideal. http://crbug.com/594852. | 1478 // TODO(sky): having to block here is not ideal. http://crbug.com/594852. |
| 1423 while (!got_initial_displays_ && valid_wait) | 1479 while (!got_initial_displays_ && valid_wait) |
| 1424 valid_wait = binding_.WaitForIncomingMethodCall(); | 1480 valid_wait = binding_.WaitForIncomingMethodCall(); |
| 1481 LOG(WARNING) << "wait done, valid=" << valid_wait; |
| 1425 return valid_wait; | 1482 return valid_wait; |
| 1426 } | 1483 } |
| 1427 | 1484 |
| 1485 WindowTreeHostMusInitParams WindowTreeClient::CreateInitParamsForNewDisplay() { |
| 1486 WindowTreeHostMusInitParams init_params; |
| 1487 init_params.window_port = base::MakeUnique<WindowPortMus>( |
| 1488 this, WindowMusType::DISPLAY_MANUALLY_CREATED); |
| 1489 roots_.insert(init_params.window_port.get()); |
| 1490 init_params.window_tree_client = this; |
| 1491 return init_params; |
| 1492 } |
| 1493 |
| 1428 void WindowTreeClient::OnConnect(ClientSpecificId client_id) { | 1494 void WindowTreeClient::OnConnect(ClientSpecificId client_id) { |
| 1495 LOG(WARNING) << "OnConnect"; |
| 1429 client_id_ = client_id; | 1496 client_id_ = client_id; |
| 1497 got_initial_displays_ = true; |
| 1430 if (window_manager_delegate_) | 1498 if (window_manager_delegate_) |
| 1431 window_manager_delegate_->OnWmConnected(); | 1499 window_manager_delegate_->OnWmConnected(); |
| 1432 } | 1500 } |
| 1433 | 1501 |
| 1434 void WindowTreeClient::WmNewDisplayAdded( | 1502 void WindowTreeClient::WmNewDisplayAdded( |
| 1435 const display::Display& display, | 1503 const display::Display& display, |
| 1436 ui::mojom::WindowDataPtr root_data, | 1504 ui::mojom::WindowDataPtr root_data, |
| 1437 bool parent_drawn, | 1505 bool parent_drawn, |
| 1438 const cc::FrameSinkId& frame_sink_id, | 1506 const cc::FrameSinkId& frame_sink_id, |
| 1439 const base::Optional<cc::LocalSurfaceId>& local_surface_id) { | 1507 const base::Optional<cc::LocalSurfaceId>& local_surface_id) { |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1970 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( | 2038 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( |
| 1971 this, capture_synchronizer_.get(), window)); | 2039 this, capture_synchronizer_.get(), window)); |
| 1972 } | 2040 } |
| 1973 | 2041 |
| 1974 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { | 2042 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { |
| 1975 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( | 2043 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( |
| 1976 this, focus_synchronizer_.get(), window)); | 2044 this, focus_synchronizer_.get(), window)); |
| 1977 } | 2045 } |
| 1978 | 2046 |
| 1979 } // namespace aura | 2047 } // namespace aura |
| OLD | NEW |