OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ash/display/window_tree_host_manager.h" | 5 #include "ash/display/window_tree_host_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <map> | 9 #include <map> |
10 #include <memory> | 10 #include <memory> |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 // Add 20% more cursor motion on non-integrated displays. | 77 // Add 20% more cursor motion on non-integrated displays. |
78 const float kCursorMultiplierForExternalDisplays = 1.2f; | 78 const float kCursorMultiplierForExternalDisplays = 1.2f; |
79 #endif | 79 #endif |
80 | 80 |
81 DisplayManager* GetDisplayManager() { | 81 DisplayManager* GetDisplayManager() { |
82 return Shell::GetInstance()->display_manager(); | 82 return Shell::GetInstance()->display_manager(); |
83 } | 83 } |
84 | 84 |
85 void SetDisplayPropertiesOnHost(AshWindowTreeHost* ash_host, | 85 void SetDisplayPropertiesOnHost(AshWindowTreeHost* ash_host, |
86 const display::Display& display) { | 86 const display::Display& display) { |
87 DisplayInfo info = GetDisplayManager()->GetDisplayInfo(display.id()); | 87 ui::ManagedDisplayInfo info = |
| 88 GetDisplayManager()->GetDisplayInfo(display.id()); |
88 aura::WindowTreeHost* host = ash_host->AsWindowTreeHost(); | 89 aura::WindowTreeHost* host = ash_host->AsWindowTreeHost(); |
89 #if defined(OS_CHROMEOS) | 90 #if defined(OS_CHROMEOS) |
90 #if defined(USE_X11) | 91 #if defined(USE_X11) |
91 // Native window property (Atom in X11) that specifies the display's | 92 // Native window property (Atom in X11) that specifies the display's |
92 // rotation, scale factor and if it's internal display. They are | 93 // rotation, scale factor and if it's internal display. They are |
93 // read and used by touchpad/mouse driver directly on X (contact | 94 // read and used by touchpad/mouse driver directly on X (contact |
94 // adlr@ for more details on touchpad/mouse driver side). The value | 95 // adlr@ for more details on touchpad/mouse driver side). The value |
95 // of the rotation is one of 0 (normal), 1 (90 degrees clockwise), 2 | 96 // of the rotation is one of 0 (normal), 1 (90 degrees clockwise), 2 |
96 // (180 degree) or 3 (270 degrees clockwise). The value of the | 97 // (180 degree) or 3 (270 degrees clockwise). The value of the |
97 // scale factor is in percent (100, 140, 200 etc). | 98 // scale factor is in percent (100, 140, 200 etc). |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 scale *= kCursorMultiplierForExternalDisplays; | 130 scale *= kCursorMultiplierForExternalDisplays; |
130 | 131 |
131 ui::CursorController::GetInstance()->SetCursorConfigForWindow( | 132 ui::CursorController::GetInstance()->SetCursorConfigForWindow( |
132 host->GetAcceleratedWidget(), info.GetActiveRotation(), scale); | 133 host->GetAcceleratedWidget(), info.GetActiveRotation(), scale); |
133 #endif | 134 #endif |
134 #endif | 135 #endif |
135 std::unique_ptr<RootWindowTransformer> transformer( | 136 std::unique_ptr<RootWindowTransformer> transformer( |
136 CreateRootWindowTransformerForDisplay(host->window(), display)); | 137 CreateRootWindowTransformerForDisplay(host->window(), display)); |
137 ash_host->SetRootWindowTransformer(std::move(transformer)); | 138 ash_host->SetRootWindowTransformer(std::move(transformer)); |
138 | 139 |
139 scoped_refptr<ManagedDisplayMode> mode = | 140 scoped_refptr<ui::ManagedDisplayMode> mode = |
140 GetDisplayManager()->GetActiveModeForDisplayId(display.id()); | 141 GetDisplayManager()->GetActiveModeForDisplayId(display.id()); |
141 if (mode && mode->refresh_rate() > 0.0f) { | 142 if (mode && mode->refresh_rate() > 0.0f) { |
142 host->compositor()->SetAuthoritativeVSyncInterval( | 143 host->compositor()->SetAuthoritativeVSyncInterval( |
143 base::TimeDelta::FromMicroseconds(base::Time::kMicrosecondsPerSecond / | 144 base::TimeDelta::FromMicroseconds(base::Time::kMicrosecondsPerSecond / |
144 mode->refresh_rate())); | 145 mode->refresh_rate())); |
145 } | 146 } |
146 | 147 |
147 // Just movnig the display requires the full redraw. | 148 // Just movnig the display requires the full redraw. |
148 // chrome-os-partner:33558. | 149 // chrome-os-partner:33558. |
149 host->compositor()->ScheduleFullRedraw(); | 150 host->compositor()->ScheduleFullRedraw(); |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 | 474 |
474 gfx::Point point_in_screen = | 475 gfx::Point point_in_screen = |
475 display::Screen::GetScreen()->GetCursorScreenPoint(); | 476 display::Screen::GetScreen()->GetCursorScreenPoint(); |
476 gfx::Point target_location_in_native; | 477 gfx::Point target_location_in_native; |
477 int64_t closest_distance_squared = -1; | 478 int64_t closest_distance_squared = -1; |
478 DisplayManager* display_manager = GetDisplayManager(); | 479 DisplayManager* display_manager = GetDisplayManager(); |
479 | 480 |
480 aura::Window* dst_root_window = nullptr; | 481 aura::Window* dst_root_window = nullptr; |
481 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { | 482 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { |
482 const display::Display& display = display_manager->GetDisplayAt(i); | 483 const display::Display& display = display_manager->GetDisplayAt(i); |
483 const DisplayInfo display_info = | 484 const ui::ManagedDisplayInfo display_info = |
484 display_manager->GetDisplayInfo(display.id()); | 485 display_manager->GetDisplayInfo(display.id()); |
485 aura::Window* root_window = GetRootWindowForDisplayId(display.id()); | 486 aura::Window* root_window = GetRootWindowForDisplayId(display.id()); |
486 if (display_info.bounds_in_native().Contains( | 487 if (display_info.bounds_in_native().Contains( |
487 cursor_location_in_native_coords_for_restore_)) { | 488 cursor_location_in_native_coords_for_restore_)) { |
488 dst_root_window = root_window; | 489 dst_root_window = root_window; |
489 target_location_in_native = cursor_location_in_native_coords_for_restore_; | 490 target_location_in_native = cursor_location_in_native_coords_for_restore_; |
490 break; | 491 break; |
491 } | 492 } |
492 gfx::Point center = display.bounds().CenterPoint(); | 493 gfx::Point center = display.bounds().CenterPoint(); |
493 // Use the distance squared from the center of the dislay. This is not | 494 // Use the distance squared from the center of the dislay. This is not |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 // TODO(oshima): It should be possible to consolidate logic for | 617 // TODO(oshima): It should be possible to consolidate logic for |
617 // unified and non unified, but I'm keeping them separated to minimize | 618 // unified and non unified, but I'm keeping them separated to minimize |
618 // the risk in M44. I'll consolidate this in M45. | 619 // the risk in M44. I'll consolidate this in M45. |
619 if (primary_tree_host_for_replace_) { | 620 if (primary_tree_host_for_replace_) { |
620 DCHECK(window_tree_hosts_.empty()); | 621 DCHECK(window_tree_hosts_.empty()); |
621 primary_display_id = display.id(); | 622 primary_display_id = display.id(); |
622 window_tree_hosts_[display.id()] = primary_tree_host_for_replace_; | 623 window_tree_hosts_[display.id()] = primary_tree_host_for_replace_; |
623 GetRootWindowSettings(GetWindow(primary_tree_host_for_replace_)) | 624 GetRootWindowSettings(GetWindow(primary_tree_host_for_replace_)) |
624 ->display_id = display.id(); | 625 ->display_id = display.id(); |
625 primary_tree_host_for_replace_ = nullptr; | 626 primary_tree_host_for_replace_ = nullptr; |
626 const DisplayInfo& display_info = | 627 const ui::ManagedDisplayInfo& display_info = |
627 GetDisplayManager()->GetDisplayInfo(display.id()); | 628 GetDisplayManager()->GetDisplayInfo(display.id()); |
628 AshWindowTreeHost* ash_host = window_tree_hosts_[display.id()]; | 629 AshWindowTreeHost* ash_host = window_tree_hosts_[display.id()]; |
629 ash_host->AsWindowTreeHost()->SetBounds(display_info.bounds_in_native()); | 630 ash_host->AsWindowTreeHost()->SetBounds(display_info.bounds_in_native()); |
630 SetDisplayPropertiesOnHost(ash_host, display); | 631 SetDisplayPropertiesOnHost(ash_host, display); |
631 } else { | 632 } else { |
632 if (primary_display_id == display::Display::kInvalidDisplayID) | 633 if (primary_display_id == display::Display::kInvalidDisplayID) |
633 primary_display_id = display.id(); | 634 primary_display_id = display.id(); |
634 DCHECK(!window_tree_hosts_.empty()); | 635 DCHECK(!window_tree_hosts_.empty()); |
635 AshWindowTreeHost* ash_host = | 636 AshWindowTreeHost* ash_host = |
636 AddWindowTreeHostForDisplay(display, AshWindowTreeHostInitParams()); | 637 AddWindowTreeHostForDisplay(display, AshWindowTreeHostInitParams()); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 // MoveWindowsTo(). See http://crbug.com/415222 | 698 // MoveWindowsTo(). See http://crbug.com/415222 |
698 window_tree_hosts_.erase(display.id()); | 699 window_tree_hosts_.erase(display.id()); |
699 } | 700 } |
700 | 701 |
701 void WindowTreeHostManager::OnDisplayMetricsChanged( | 702 void WindowTreeHostManager::OnDisplayMetricsChanged( |
702 const display::Display& display, | 703 const display::Display& display, |
703 uint32_t metrics) { | 704 uint32_t metrics) { |
704 if (!(metrics & (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_ROTATION | | 705 if (!(metrics & (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_ROTATION | |
705 DISPLAY_METRIC_DEVICE_SCALE_FACTOR))) | 706 DISPLAY_METRIC_DEVICE_SCALE_FACTOR))) |
706 return; | 707 return; |
707 const DisplayInfo& display_info = | 708 const ui::ManagedDisplayInfo& display_info = |
708 GetDisplayManager()->GetDisplayInfo(display.id()); | 709 GetDisplayManager()->GetDisplayInfo(display.id()); |
709 DCHECK(!display_info.bounds_in_native().IsEmpty()); | 710 DCHECK(!display_info.bounds_in_native().IsEmpty()); |
710 AshWindowTreeHost* ash_host = window_tree_hosts_[display.id()]; | 711 AshWindowTreeHost* ash_host = window_tree_hosts_[display.id()]; |
711 ash_host->AsWindowTreeHost()->SetBounds(display_info.bounds_in_native()); | 712 ash_host->AsWindowTreeHost()->SetBounds(display_info.bounds_in_native()); |
712 SetDisplayPropertiesOnHost(ash_host, display); | 713 SetDisplayPropertiesOnHost(ash_host, display); |
713 } | 714 } |
714 | 715 |
715 void WindowTreeHostManager::OnHostResized(const aura::WindowTreeHost* host) { | 716 void WindowTreeHostManager::OnHostResized(const aura::WindowTreeHost* host) { |
716 display::Display display = | 717 display::Display display = |
717 display::Screen::GetScreen()->GetDisplayNearestWindow( | 718 display::Screen::GetScreen()->GetDisplayNearestWindow( |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 aura::Window* active_window = wm::GetActiveWindow(); | 804 aura::Window* active_window = wm::GetActiveWindow(); |
804 aura::Window* root_window = active_window ? active_window->GetRootWindow() | 805 aura::Window* root_window = active_window ? active_window->GetRootWindow() |
805 : Shell::GetPrimaryRootWindow(); | 806 : Shell::GetPrimaryRootWindow(); |
806 return root_window->GetHost()->DispatchKeyEventPostIME(event); | 807 return root_window->GetHost()->DispatchKeyEventPostIME(event); |
807 } | 808 } |
808 | 809 |
809 AshWindowTreeHost* WindowTreeHostManager::AddWindowTreeHostForDisplay( | 810 AshWindowTreeHost* WindowTreeHostManager::AddWindowTreeHostForDisplay( |
810 const display::Display& display, | 811 const display::Display& display, |
811 const AshWindowTreeHostInitParams& init_params) { | 812 const AshWindowTreeHostInitParams& init_params) { |
812 static int host_count = 0; | 813 static int host_count = 0; |
813 const DisplayInfo& display_info = | 814 const ui::ManagedDisplayInfo& display_info = |
814 GetDisplayManager()->GetDisplayInfo(display.id()); | 815 GetDisplayManager()->GetDisplayInfo(display.id()); |
815 AshWindowTreeHostInitParams params_with_bounds(init_params); | 816 AshWindowTreeHostInitParams params_with_bounds(init_params); |
816 params_with_bounds.initial_bounds = display_info.bounds_in_native(); | 817 params_with_bounds.initial_bounds = display_info.bounds_in_native(); |
817 params_with_bounds.offscreen = | 818 params_with_bounds.offscreen = |
818 display.id() == DisplayManager::kUnifiedDisplayId; | 819 display.id() == DisplayManager::kUnifiedDisplayId; |
819 AshWindowTreeHost* ash_host = AshWindowTreeHost::Create(params_with_bounds); | 820 AshWindowTreeHost* ash_host = AshWindowTreeHost::Create(params_with_bounds); |
820 aura::WindowTreeHost* host = ash_host->AsWindowTreeHost(); | 821 aura::WindowTreeHost* host = ash_host->AsWindowTreeHost(); |
821 if (!input_method_) { // Singleton input method instance for Ash. | 822 if (!input_method_) { // Singleton input method instance for Ash. |
822 input_method_ = ui::CreateInputMethod(this, host->GetAcceleratedWidget()); | 823 input_method_ = ui::CreateInputMethod(this, host->GetAcceleratedWidget()); |
823 // Makes sure the input method is focused by default when created, because | 824 // Makes sure the input method is focused by default when created, because |
(...skipping 21 matching lines...) Expand all Loading... |
845 SetDisplayPropertiesOnHost(ash_host, display); | 846 SetDisplayPropertiesOnHost(ash_host, display); |
846 | 847 |
847 #if defined(OS_CHROMEOS) | 848 #if defined(OS_CHROMEOS) |
848 if (switches::ConstrainPointerToRoot()) | 849 if (switches::ConstrainPointerToRoot()) |
849 ash_host->ConfineCursorToRootWindow(); | 850 ash_host->ConfineCursorToRootWindow(); |
850 #endif | 851 #endif |
851 return ash_host; | 852 return ash_host; |
852 } | 853 } |
853 | 854 |
854 } // namespace ash | 855 } // namespace ash |
OLD | NEW |