| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ash/mus/display_synchronizer.h" |
| 6 |
| 7 #include "ash/shell.h" |
| 8 #include "ui/aura/mus/window_manager_delegate.h" |
| 9 #include "ui/display/manager/display_manager.h" |
| 10 #include "ui/display/manager/managed_display_info.h" |
| 11 |
| 12 namespace ash { |
| 13 |
| 14 DisplaySynchronizer::DisplaySynchronizer( |
| 15 aura::WindowManagerClient* window_manager_client) |
| 16 : window_manager_client_(window_manager_client) { |
| 17 Shell::Get()->window_tree_host_manager()->AddObserver(this); |
| 18 SendDisplayConfigurationToServer(); |
| 19 } |
| 20 |
| 21 DisplaySynchronizer::~DisplaySynchronizer() { |
| 22 Shell::Get()->window_tree_host_manager()->RemoveObserver(this); |
| 23 } |
| 24 |
| 25 void DisplaySynchronizer::SendDisplayConfigurationToServer() { |
| 26 display::DisplayManager* display_manager = Shell::Get()->display_manager(); |
| 27 const size_t display_count = display_manager->GetNumDisplays(); |
| 28 if (display_count == 0) |
| 29 return; |
| 30 |
| 31 std::vector<display::Display> displays; |
| 32 std::vector<ui::mojom::WmViewportMetricsPtr> metrics; |
| 33 for (size_t i = 0; i < display_count; ++i) { |
| 34 displays.push_back(display_manager->GetDisplayAt(i)); |
| 35 ui::mojom::WmViewportMetricsPtr viewport_metrics = |
| 36 ui::mojom::WmViewportMetrics::New(); |
| 37 const display::ManagedDisplayInfo& display_info = |
| 38 display_manager->GetDisplayInfo(displays.back().id()); |
| 39 viewport_metrics->bounds_in_pixels = display_info.bounds_in_native(); |
| 40 viewport_metrics->device_scale_factor = display_info.device_scale_factor(); |
| 41 viewport_metrics->ui_scale_factor = display_info.configured_ui_scale(); |
| 42 metrics.push_back(std::move(viewport_metrics)); |
| 43 } |
| 44 window_manager_client_->SetDisplayConfiguration( |
| 45 displays, std::move(metrics), |
| 46 WindowTreeHostManager::GetPrimaryDisplayId()); |
| 47 } |
| 48 |
| 49 void DisplaySynchronizer::OnDisplaysInitialized() { |
| 50 SendDisplayConfigurationToServer(); |
| 51 } |
| 52 |
| 53 void DisplaySynchronizer::OnDisplayConfigurationChanged() { |
| 54 SendDisplayConfigurationToServer(); |
| 55 } |
| 56 |
| 57 } // namespace ash |
| OLD | NEW |