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 display::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<display::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 display::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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 // TODO(oshima): It should be possible to consolidate logic for | 618 // TODO(oshima): It should be possible to consolidate logic for |
618 // unified and non unified, but I'm keeping them separated to minimize | 619 // unified and non unified, but I'm keeping them separated to minimize |
619 // the risk in M44. I'll consolidate this in M45. | 620 // the risk in M44. I'll consolidate this in M45. |
620 if (primary_tree_host_for_replace_) { | 621 if (primary_tree_host_for_replace_) { |
621 DCHECK(window_tree_hosts_.empty()); | 622 DCHECK(window_tree_hosts_.empty()); |
622 primary_display_id = display.id(); | 623 primary_display_id = display.id(); |
623 window_tree_hosts_[display.id()] = primary_tree_host_for_replace_; | 624 window_tree_hosts_[display.id()] = primary_tree_host_for_replace_; |
624 GetRootWindowSettings(GetWindow(primary_tree_host_for_replace_)) | 625 GetRootWindowSettings(GetWindow(primary_tree_host_for_replace_)) |
625 ->display_id = display.id(); | 626 ->display_id = display.id(); |
626 primary_tree_host_for_replace_ = nullptr; | 627 primary_tree_host_for_replace_ = nullptr; |
627 const DisplayInfo& display_info = | 628 const display::ManagedDisplayInfo& display_info = |
628 GetDisplayManager()->GetDisplayInfo(display.id()); | 629 GetDisplayManager()->GetDisplayInfo(display.id()); |
629 AshWindowTreeHost* ash_host = window_tree_hosts_[display.id()]; | 630 AshWindowTreeHost* ash_host = window_tree_hosts_[display.id()]; |
630 ash_host->AsWindowTreeHost()->SetBounds(display_info.bounds_in_native()); | 631 ash_host->AsWindowTreeHost()->SetBounds(display_info.bounds_in_native()); |
631 SetDisplayPropertiesOnHost(ash_host, display); | 632 SetDisplayPropertiesOnHost(ash_host, display); |
632 } else { | 633 } else { |
633 if (primary_display_id == display::Display::kInvalidDisplayID) | 634 if (primary_display_id == display::Display::kInvalidDisplayID) |
634 primary_display_id = display.id(); | 635 primary_display_id = display.id(); |
635 DCHECK(!window_tree_hosts_.empty()); | 636 DCHECK(!window_tree_hosts_.empty()); |
636 AshWindowTreeHost* ash_host = | 637 AshWindowTreeHost* ash_host = |
637 AddWindowTreeHostForDisplay(display, AshWindowTreeHostInitParams()); | 638 AddWindowTreeHostForDisplay(display, AshWindowTreeHostInitParams()); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 // MoveWindowsTo(). See http://crbug.com/415222 | 699 // MoveWindowsTo(). See http://crbug.com/415222 |
699 window_tree_hosts_.erase(display.id()); | 700 window_tree_hosts_.erase(display.id()); |
700 } | 701 } |
701 | 702 |
702 void WindowTreeHostManager::OnDisplayMetricsChanged( | 703 void WindowTreeHostManager::OnDisplayMetricsChanged( |
703 const display::Display& display, | 704 const display::Display& display, |
704 uint32_t metrics) { | 705 uint32_t metrics) { |
705 if (!(metrics & (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_ROTATION | | 706 if (!(metrics & (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_ROTATION | |
706 DISPLAY_METRIC_DEVICE_SCALE_FACTOR))) | 707 DISPLAY_METRIC_DEVICE_SCALE_FACTOR))) |
707 return; | 708 return; |
708 const DisplayInfo& display_info = | 709 const display::ManagedDisplayInfo& display_info = |
709 GetDisplayManager()->GetDisplayInfo(display.id()); | 710 GetDisplayManager()->GetDisplayInfo(display.id()); |
710 DCHECK(!display_info.bounds_in_native().IsEmpty()); | 711 DCHECK(!display_info.bounds_in_native().IsEmpty()); |
711 AshWindowTreeHost* ash_host = window_tree_hosts_[display.id()]; | 712 AshWindowTreeHost* ash_host = window_tree_hosts_[display.id()]; |
712 ash_host->AsWindowTreeHost()->SetBounds(display_info.bounds_in_native()); | 713 ash_host->AsWindowTreeHost()->SetBounds(display_info.bounds_in_native()); |
713 SetDisplayPropertiesOnHost(ash_host, display); | 714 SetDisplayPropertiesOnHost(ash_host, display); |
714 } | 715 } |
715 | 716 |
716 void WindowTreeHostManager::OnHostResized(const aura::WindowTreeHost* host) { | 717 void WindowTreeHostManager::OnHostResized(const aura::WindowTreeHost* host) { |
717 display::Display display = | 718 display::Display display = |
718 display::Screen::GetScreen()->GetDisplayNearestWindow( | 719 display::Screen::GetScreen()->GetDisplayNearestWindow( |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 aura::Window* active_window = wm::GetActiveWindow(); | 805 aura::Window* active_window = wm::GetActiveWindow(); |
805 aura::Window* root_window = active_window ? active_window->GetRootWindow() | 806 aura::Window* root_window = active_window ? active_window->GetRootWindow() |
806 : Shell::GetPrimaryRootWindow(); | 807 : Shell::GetPrimaryRootWindow(); |
807 return root_window->GetHost()->DispatchKeyEventPostIME(event); | 808 return root_window->GetHost()->DispatchKeyEventPostIME(event); |
808 } | 809 } |
809 | 810 |
810 AshWindowTreeHost* WindowTreeHostManager::AddWindowTreeHostForDisplay( | 811 AshWindowTreeHost* WindowTreeHostManager::AddWindowTreeHostForDisplay( |
811 const display::Display& display, | 812 const display::Display& display, |
812 const AshWindowTreeHostInitParams& init_params) { | 813 const AshWindowTreeHostInitParams& init_params) { |
813 static int host_count = 0; | 814 static int host_count = 0; |
814 const DisplayInfo& display_info = | 815 const display::ManagedDisplayInfo& display_info = |
815 GetDisplayManager()->GetDisplayInfo(display.id()); | 816 GetDisplayManager()->GetDisplayInfo(display.id()); |
816 AshWindowTreeHostInitParams params_with_bounds(init_params); | 817 AshWindowTreeHostInitParams params_with_bounds(init_params); |
817 params_with_bounds.initial_bounds = display_info.bounds_in_native(); | 818 params_with_bounds.initial_bounds = display_info.bounds_in_native(); |
818 params_with_bounds.offscreen = | 819 params_with_bounds.offscreen = |
819 display.id() == DisplayManager::kUnifiedDisplayId; | 820 display.id() == DisplayManager::kUnifiedDisplayId; |
820 AshWindowTreeHost* ash_host = AshWindowTreeHost::Create(params_with_bounds); | 821 AshWindowTreeHost* ash_host = AshWindowTreeHost::Create(params_with_bounds); |
821 aura::WindowTreeHost* host = ash_host->AsWindowTreeHost(); | 822 aura::WindowTreeHost* host = ash_host->AsWindowTreeHost(); |
822 if (!input_method_) { // Singleton input method instance for Ash. | 823 if (!input_method_) { // Singleton input method instance for Ash. |
823 input_method_ = ui::CreateInputMethod(this, host->GetAcceleratedWidget()); | 824 input_method_ = ui::CreateInputMethod(this, host->GetAcceleratedWidget()); |
824 // Makes sure the input method is focused by default when created, because | 825 // Makes sure the input method is focused by default when created, because |
(...skipping 21 matching lines...) Expand all Loading... |
846 SetDisplayPropertiesOnHost(ash_host, display); | 847 SetDisplayPropertiesOnHost(ash_host, display); |
847 | 848 |
848 #if defined(OS_CHROMEOS) | 849 #if defined(OS_CHROMEOS) |
849 if (switches::ConstrainPointerToRoot()) | 850 if (switches::ConstrainPointerToRoot()) |
850 ash_host->ConfineCursorToRootWindow(); | 851 ash_host->ConfineCursorToRootWindow(); |
851 #endif | 852 #endif |
852 return ash_host; | 853 return ash_host; |
853 } | 854 } |
854 | 855 |
855 } // namespace ash | 856 } // namespace ash |
OLD | NEW |