| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 #if defined(USE_X11) | 52 #if defined(USE_X11) |
| 53 #include "ui/base/x/x11_util.h" // nogncheck | 53 #include "ui/base/x/x11_util.h" // nogncheck |
| 54 #include "ui/gfx/x/x11_types.h" // nogncheck | 54 #include "ui/gfx/x/x11_types.h" // nogncheck |
| 55 | 55 |
| 56 // Including this at the bottom to avoid other | 56 // Including this at the bottom to avoid other |
| 57 // potential conflict with chrome headers. | 57 // potential conflict with chrome headers. |
| 58 #include <X11/extensions/Xrandr.h> | 58 #include <X11/extensions/Xrandr.h> |
| 59 #undef RootWindow | 59 #undef RootWindow |
| 60 #endif // defined(USE_X11) | 60 #endif // defined(USE_X11) |
| 61 | 61 |
| 62 #if defined(OS_CHROMEOS) && defined(USE_OZONE) | 62 #if defined(USE_OZONE) |
| 63 #include "ui/events/ozone/chromeos/cursor_controller.h" | 63 #include "ui/events/ozone/chromeos/cursor_controller.h" |
| 64 #endif | 64 #endif |
| 65 | 65 |
| 66 namespace ash { | 66 namespace ash { |
| 67 namespace { | 67 namespace { |
| 68 | 68 |
| 69 // Primary display stored in global object as it can be | 69 // Primary display stored in global object as it can be |
| 70 // accessed after Shell is deleted. A separate display instance is created | 70 // accessed after Shell is deleted. A separate display instance is created |
| 71 // during the shutdown instead of always keeping two display instances | 71 // during the shutdown instead of always keeping two display instances |
| 72 // (one here and another one in display_manager) in sync, which is error prone. | 72 // (one here and another one in display_manager) in sync, which is error prone. |
| 73 // This is initialized in the constructor, and then in CreatePrimaryHost(). | 73 // This is initialized in the constructor, and then in CreatePrimaryHost(). |
| 74 int64_t primary_display_id = -1; | 74 int64_t primary_display_id = -1; |
| 75 | 75 |
| 76 #if defined(USE_OZONE) && defined(OS_CHROMEOS) | 76 #if defined(USE_OZONE) |
| 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 display::DisplayManager* GetDisplayManager() { | 81 display::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 display::ManagedDisplayInfo info = | 87 display::ManagedDisplayInfo info = |
| 88 GetDisplayManager()->GetDisplayInfo(display.id()); | 88 GetDisplayManager()->GetDisplayInfo(display.id()); |
| 89 aura::WindowTreeHost* host = ash_host->AsWindowTreeHost(); | 89 aura::WindowTreeHost* host = ash_host->AsWindowTreeHost(); |
| 90 #if defined(OS_CHROMEOS) | |
| 91 #if defined(USE_X11) | 90 #if defined(USE_X11) |
| 92 // Native window property (Atom in X11) that specifies the display's | 91 // Native window property (Atom in X11) that specifies the display's |
| 93 // rotation, scale factor and if it's internal display. They are | 92 // rotation, scale factor and if it's internal display. They are |
| 94 // read and used by touchpad/mouse driver directly on X (contact | 93 // read and used by touchpad/mouse driver directly on X (contact |
| 95 // adlr@ for more details on touchpad/mouse driver side). The value | 94 // adlr@ for more details on touchpad/mouse driver side). The value |
| 96 // 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 |
| 97 // (180 degree) or 3 (270 degrees clockwise). The value of the | 96 // (180 degree) or 3 (270 degrees clockwise). The value of the |
| 98 // scale factor is in percent (100, 140, 200 etc). | 97 // scale factor is in percent (100, 140, 200 etc). |
| 99 const char kRotationProp[] = "_CHROME_DISPLAY_ROTATION"; | 98 const char kRotationProp[] = "_CHROME_DISPLAY_ROTATION"; |
| 100 const char kScaleFactorProp[] = "_CHROME_DISPLAY_SCALE_FACTOR"; | 99 const char kScaleFactorProp[] = "_CHROME_DISPLAY_SCALE_FACTOR"; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 125 #elif defined(USE_OZONE) | 124 #elif defined(USE_OZONE) |
| 126 // Scale all motion on High-DPI displays. | 125 // Scale all motion on High-DPI displays. |
| 127 float scale = display.device_scale_factor(); | 126 float scale = display.device_scale_factor(); |
| 128 | 127 |
| 129 if (!display.IsInternal()) | 128 if (!display.IsInternal()) |
| 130 scale *= kCursorMultiplierForExternalDisplays; | 129 scale *= kCursorMultiplierForExternalDisplays; |
| 131 | 130 |
| 132 ui::CursorController::GetInstance()->SetCursorConfigForWindow( | 131 ui::CursorController::GetInstance()->SetCursorConfigForWindow( |
| 133 host->GetAcceleratedWidget(), info.GetActiveRotation(), scale); | 132 host->GetAcceleratedWidget(), info.GetActiveRotation(), scale); |
| 134 #endif | 133 #endif |
| 135 #endif | |
| 136 std::unique_ptr<RootWindowTransformer> transformer( | 134 std::unique_ptr<RootWindowTransformer> transformer( |
| 137 CreateRootWindowTransformerForDisplay(host->window(), display)); | 135 CreateRootWindowTransformerForDisplay(host->window(), display)); |
| 138 ash_host->SetRootWindowTransformer(std::move(transformer)); | 136 ash_host->SetRootWindowTransformer(std::move(transformer)); |
| 139 | 137 |
| 140 scoped_refptr<display::ManagedDisplayMode> mode = | 138 scoped_refptr<display::ManagedDisplayMode> mode = |
| 141 GetDisplayManager()->GetActiveModeForDisplayId(display.id()); | 139 GetDisplayManager()->GetActiveModeForDisplayId(display.id()); |
| 142 if (mode && mode->refresh_rate() > 0.0f) { | 140 if (mode && mode->refresh_rate() > 0.0f) { |
| 143 host->compositor()->SetAuthoritativeVSyncInterval( | 141 host->compositor()->SetAuthoritativeVSyncInterval( |
| 144 base::TimeDelta::FromMicroseconds(base::Time::kMicrosecondsPerSecond / | 142 base::TimeDelta::FromMicroseconds(base::Time::kMicrosecondsPerSecond / |
| 145 mode->refresh_rate())); | 143 mode->refresh_rate())); |
| 146 } | 144 } |
| 147 | 145 |
| 148 // Just movnig the display requires the full redraw. | 146 // Just movnig the display requires the full redraw. |
| 149 // chrome-os-partner:33558. | 147 // chrome-os-partner:33558. |
| 150 host->compositor()->ScheduleFullRedraw(); | 148 host->compositor()->ScheduleFullRedraw(); |
| 151 } | 149 } |
| 152 | 150 |
| 153 void ClearDisplayPropertiesOnHost(AshWindowTreeHost* ash_host) { | 151 void ClearDisplayPropertiesOnHost(AshWindowTreeHost* ash_host) { |
| 154 #if defined(OS_CHROMEOS) && defined(USE_OZONE) | 152 #if defined(USE_OZONE) |
| 155 aura::WindowTreeHost* host = ash_host->AsWindowTreeHost(); | 153 aura::WindowTreeHost* host = ash_host->AsWindowTreeHost(); |
| 156 ui::CursorController::GetInstance()->ClearCursorConfigForWindow( | 154 ui::CursorController::GetInstance()->ClearCursorConfigForWindow( |
| 157 host->GetAcceleratedWidget()); | 155 host->GetAcceleratedWidget()); |
| 158 #endif | 156 #endif |
| 159 } | 157 } |
| 160 | 158 |
| 161 aura::Window* GetWindow(AshWindowTreeHost* ash_host) { | 159 aura::Window* GetWindow(AshWindowTreeHost* ash_host) { |
| 162 CHECK(ash_host->AsWindowTreeHost()); | 160 CHECK(ash_host->AsWindowTreeHost()); |
| 163 return ash_host->AsWindowTreeHost()->window(); | 161 return ash_host->AsWindowTreeHost()->window(); |
| 164 } | 162 } |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 const aura::Window* window, | 582 const aura::Window* window, |
| 585 const gfx::Insets& insets) { | 583 const gfx::Insets& insets) { |
| 586 const aura::Window* root_window = window->GetRootWindow(); | 584 const aura::Window* root_window = window->GetRootWindow(); |
| 587 int64_t id = GetRootWindowSettings(root_window)->display_id; | 585 int64_t id = GetRootWindowSettings(root_window)->display_id; |
| 588 // if id is |kInvaildDisplayID|, it's being deleted. | 586 // if id is |kInvaildDisplayID|, it's being deleted. |
| 589 DCHECK(id != display::kInvalidDisplayId); | 587 DCHECK(id != display::kInvalidDisplayId); |
| 590 return GetDisplayManager()->UpdateWorkAreaOfDisplay(id, insets); | 588 return GetDisplayManager()->UpdateWorkAreaOfDisplay(id, insets); |
| 591 } | 589 } |
| 592 | 590 |
| 593 void WindowTreeHostManager::OnDisplayAdded(const display::Display& display) { | 591 void WindowTreeHostManager::OnDisplayAdded(const display::Display& display) { |
| 594 #if defined(OS_CHROMEOS) | |
| 595 // If we're switching from/to offscreen WTH, we need to | 592 // If we're switching from/to offscreen WTH, we need to |
| 596 // create new WTH for primary display instead of reusing. | 593 // create new WTH for primary display instead of reusing. |
| 597 if (primary_tree_host_for_replace_ && | 594 if (primary_tree_host_for_replace_ && |
| 598 (GetRootWindowSettings(GetWindow(primary_tree_host_for_replace_)) | 595 (GetRootWindowSettings(GetWindow(primary_tree_host_for_replace_)) |
| 599 ->display_id == display::DisplayManager::kUnifiedDisplayId || | 596 ->display_id == display::DisplayManager::kUnifiedDisplayId || |
| 600 display.id() == display::DisplayManager::kUnifiedDisplayId)) { | 597 display.id() == display::DisplayManager::kUnifiedDisplayId)) { |
| 601 DCHECK_EQ(display::kInvalidDisplayId, primary_display_id); | 598 DCHECK_EQ(display::kInvalidDisplayId, primary_display_id); |
| 602 primary_display_id = display.id(); | 599 primary_display_id = display.id(); |
| 603 | 600 |
| 604 AshWindowTreeHost* ash_host = | 601 AshWindowTreeHost* ash_host = |
| (...skipping 27 matching lines...) Expand all Loading... |
| 632 DeleteHost(to_delete); | 629 DeleteHost(to_delete); |
| 633 #ifndef NDEBUG | 630 #ifndef NDEBUG |
| 634 auto iter = std::find_if( | 631 auto iter = std::find_if( |
| 635 window_tree_hosts_.begin(), window_tree_hosts_.end(), | 632 window_tree_hosts_.begin(), window_tree_hosts_.end(), |
| 636 [to_delete](const std::pair<int64_t, AshWindowTreeHost*>& pair) { | 633 [to_delete](const std::pair<int64_t, AshWindowTreeHost*>& pair) { |
| 637 return pair.second == to_delete; | 634 return pair.second == to_delete; |
| 638 }); | 635 }); |
| 639 DCHECK(iter == window_tree_hosts_.end()); | 636 DCHECK(iter == window_tree_hosts_.end()); |
| 640 #endif | 637 #endif |
| 641 // the host has already been removed from the window_tree_host_. | 638 // the host has already been removed from the window_tree_host_. |
| 642 } else | 639 } else if (primary_tree_host_for_replace_) { |
| 643 #endif | 640 // TODO(oshima): It should be possible to consolidate logic for |
| 644 // TODO(oshima): It should be possible to consolidate logic for | 641 // unified and non unified, but I'm keeping them separated to minimize |
| 645 // unified and non unified, but I'm keeping them separated to minimize | 642 // the risk in M44. I'll consolidate this in M45. |
| 646 // the risk in M44. I'll consolidate this in M45. | |
| 647 if (primary_tree_host_for_replace_) { | |
| 648 DCHECK(window_tree_hosts_.empty()); | 643 DCHECK(window_tree_hosts_.empty()); |
| 649 primary_display_id = display.id(); | 644 primary_display_id = display.id(); |
| 650 window_tree_hosts_[display.id()] = primary_tree_host_for_replace_; | 645 window_tree_hosts_[display.id()] = primary_tree_host_for_replace_; |
| 651 GetRootWindowSettings(GetWindow(primary_tree_host_for_replace_)) | 646 GetRootWindowSettings(GetWindow(primary_tree_host_for_replace_)) |
| 652 ->display_id = display.id(); | 647 ->display_id = display.id(); |
| 653 primary_tree_host_for_replace_ = nullptr; | 648 primary_tree_host_for_replace_ = nullptr; |
| 654 const display::ManagedDisplayInfo& display_info = | 649 const display::ManagedDisplayInfo& display_info = |
| 655 GetDisplayManager()->GetDisplayInfo(display.id()); | 650 GetDisplayManager()->GetDisplayInfo(display.id()); |
| 656 AshWindowTreeHost* ash_host = window_tree_hosts_[display.id()]; | 651 AshWindowTreeHost* ash_host = window_tree_hosts_[display.id()]; |
| 657 ash_host->AsWindowTreeHost()->SetBoundsInPixels( | 652 ash_host->AsWindowTreeHost()->SetBoundsInPixels( |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 GetAshWindowTreeHostForDisplayId(display.id()) | 815 GetAshWindowTreeHostForDisplayId(display.id()) |
| 821 ->AsWindowTreeHost() | 816 ->AsWindowTreeHost() |
| 822 ->compositor() | 817 ->compositor() |
| 823 ->SetOutputIsSecure(output_is_secure); | 818 ->SetOutputIsSecure(output_is_secure); |
| 824 } | 819 } |
| 825 | 820 |
| 826 for (auto& observer : observers_) | 821 for (auto& observer : observers_) |
| 827 observer.OnDisplayConfigurationChanged(); | 822 observer.OnDisplayConfigurationChanged(); |
| 828 UpdateMouseLocationAfterDisplayChange(); | 823 UpdateMouseLocationAfterDisplayChange(); |
| 829 | 824 |
| 830 #if defined(USE_X11) && defined(OS_CHROMEOS) | 825 #if defined(USE_X11) |
| 831 if (must_clear_window) | 826 if (must_clear_window) |
| 832 ui::ClearX11DefaultRootWindow(); | 827 ui::ClearX11DefaultRootWindow(); |
| 833 #endif | 828 #endif |
| 834 } | 829 } |
| 835 | 830 |
| 836 #if defined(OS_CHROMEOS) | |
| 837 ui::DisplayConfigurator* WindowTreeHostManager::display_configurator() { | 831 ui::DisplayConfigurator* WindowTreeHostManager::display_configurator() { |
| 838 return Shell::GetInstance()->display_configurator(); | 832 return Shell::GetInstance()->display_configurator(); |
| 839 } | 833 } |
| 840 #endif | |
| 841 | 834 |
| 842 ui::EventDispatchDetails WindowTreeHostManager::DispatchKeyEventPostIME( | 835 ui::EventDispatchDetails WindowTreeHostManager::DispatchKeyEventPostIME( |
| 843 ui::KeyEvent* event) { | 836 ui::KeyEvent* event) { |
| 844 // Getting the active root window to dispatch the event. This isn't | 837 // Getting the active root window to dispatch the event. This isn't |
| 845 // significant as the event will be sent to the window resolved by | 838 // significant as the event will be sent to the window resolved by |
| 846 // aura::client::FocusClient which is FocusController in ash. | 839 // aura::client::FocusClient which is FocusController in ash. |
| 847 aura::Window* active_window = wm::GetActiveWindow(); | 840 aura::Window* active_window = wm::GetActiveWindow(); |
| 848 aura::Window* root_window = active_window ? active_window->GetRootWindow() | 841 aura::Window* root_window = active_window ? active_window->GetRootWindow() |
| 849 : Shell::GetPrimaryRootWindow(); | 842 : Shell::GetPrimaryRootWindow(); |
| 850 return root_window->GetHost()->DispatchKeyEventPostIME(event); | 843 return root_window->GetHost()->DispatchKeyEventPostIME(event); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 // No need to remove our observer observer because the WindowTreeHostManager | 875 // No need to remove our observer observer because the WindowTreeHostManager |
| 883 // outlives the host. | 876 // outlives the host. |
| 884 host->AddObserver(this); | 877 host->AddObserver(this); |
| 885 InitRootWindowSettings(host->window())->display_id = display.id(); | 878 InitRootWindowSettings(host->window())->display_id = display.id(); |
| 886 host->InitHost(); | 879 host->InitHost(); |
| 887 host->window()->Show(); | 880 host->window()->Show(); |
| 888 | 881 |
| 889 window_tree_hosts_[display.id()] = ash_host; | 882 window_tree_hosts_[display.id()] = ash_host; |
| 890 SetDisplayPropertiesOnHost(ash_host, display); | 883 SetDisplayPropertiesOnHost(ash_host, display); |
| 891 | 884 |
| 892 #if defined(OS_CHROMEOS) | |
| 893 if (switches::ConstrainPointerToRoot()) | 885 if (switches::ConstrainPointerToRoot()) |
| 894 ash_host->ConfineCursorToRootWindow(); | 886 ash_host->ConfineCursorToRootWindow(); |
| 895 #endif | |
| 896 return ash_host; | 887 return ash_host; |
| 897 } | 888 } |
| 898 | 889 |
| 899 } // namespace ash | 890 } // namespace ash |
| OLD | NEW |