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