Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef ASH_DISPLAY_DISPLAY_CONFIGURATION_CONTROLLER_H_ | 5 #ifndef ASH_DISPLAY_DISPLAY_CONFIGURATION_CONTROLLER_H_ |
| 6 #define ASH_DISPLAY_DISPLAY_CONFIGURATION_CONTROLLER_H_ | 6 #define ASH_DISPLAY_DISPLAY_CONFIGURATION_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "ash/ash_export.h" | 10 #include "ash/ash_export.h" |
| 11 #include "ash/display/window_tree_host_manager.h" | 11 #include "ash/display/window_tree_host_manager.h" |
| 12 #include "ash/rotator/screen_rotation_animator_observer.h" | |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 14 #include "ui/display/display.h" | 15 #include "ui/display/display.h" |
| 15 | 16 |
| 16 namespace display { | 17 namespace display { |
| 17 class DisplayLayout; | 18 class DisplayLayout; |
| 18 class DisplayManager; | 19 class DisplayManager; |
| 19 } | 20 } |
| 20 | 21 |
| 21 namespace ash { | 22 namespace ash { |
| 22 | 23 |
| 23 namespace test { | 24 namespace test { |
| 24 class ShellTestApi; | 25 class DisplayConfigurationControllerTestApi; |
| 25 } // namespace test | 26 } // namespace test |
| 26 | 27 |
| 27 class DisplayAnimator; | 28 class DisplayAnimator; |
| 29 class ScreenRotationAnimator; | |
| 28 | 30 |
| 29 // This class controls Display related configuration. Specifically it: | 31 // This class controls Display related configuration. Specifically it: |
| 30 // * Handles animated transitions where appropriate. | 32 // * Handles animated transitions where appropriate. |
| 31 // * Limits the frequency of certain operations. | 33 // * Limits the frequency of certain operations. |
| 32 // * Provides a single interface for UI and API classes. | 34 // * Provides a single interface for UI and API classes. |
| 33 // * TODO: Forwards display configuration changed events to UI and API classes. | 35 // * TODO: Forwards display configuration changed events to UI and API classes. |
| 34 class ASH_EXPORT DisplayConfigurationController | 36 class ASH_EXPORT DisplayConfigurationController |
| 35 : public WindowTreeHostManager::Observer { | 37 : public WindowTreeHostManager::Observer, |
| 38 public ScreenRotationAnimatorObserver { | |
| 36 public: | 39 public: |
| 37 DisplayConfigurationController( | 40 DisplayConfigurationController( |
| 38 display::DisplayManager* display_manager, | 41 display::DisplayManager* display_manager, |
| 39 WindowTreeHostManager* window_tree_host_manager); | 42 WindowTreeHostManager* window_tree_host_manager); |
| 40 ~DisplayConfigurationController() override; | 43 ~DisplayConfigurationController() override; |
| 41 | 44 |
| 42 // Sets the layout for the current displays with a fade in/out | 45 // Sets the layout for the current displays with a fade in/out |
| 43 // animation. Currently |display_id| is assumed to be the secondary | 46 // animation. Currently |display_id| is assumed to be the secondary |
| 44 // display. TODO(oshima/stevenjb): Support 3+ displays. | 47 // display. TODO(oshima/stevenjb): Support 3+ displays. |
| 45 void SetDisplayLayout(std::unique_ptr<display::DisplayLayout> layout); | 48 void SetDisplayLayout(std::unique_ptr<display::DisplayLayout> layout); |
| 46 | 49 |
| 47 // Sets the mirror mode with a fade-in/fade-out animation. Affects all | 50 // Sets the mirror mode with a fade-in/fade-out animation. Affects all |
| 48 // displays. | 51 // displays. |
| 49 void SetMirrorMode(bool mirror); | 52 void SetMirrorMode(bool mirror); |
| 50 | 53 |
| 51 // Sets the display's rotation with animation if available. | 54 // Sets the display's rotation with animation if available. |
| 52 void SetDisplayRotation(int64_t display_id, | 55 void SetDisplayRotation(int64_t display_id, |
| 53 display::Display::Rotation rotation, | 56 display::Display::Rotation rotation, |
| 54 display::Display::RotationSource source); | 57 display::Display::RotationSource source); |
| 55 | 58 |
| 56 // Sets the primary display id. | 59 // Sets the primary display id. |
| 57 void SetPrimaryDisplayId(int64_t display_id); | 60 void SetPrimaryDisplayId(int64_t display_id); |
| 58 | 61 |
| 59 // WindowTreeHostManager::Observer | 62 // WindowTreeHostManager::Observer |
| 60 void OnDisplayConfigurationChanged() override; | 63 void OnDisplayConfigurationChanged() override; |
| 61 | 64 |
| 65 // ScreenRotationAnimatorObserver | |
| 66 void OnEndedOrAbortedScreenRotationAnimation( | |
|
oshima
2017/03/16 20:13:09
OnRotationAnimationFinished. then document that it
wutao
2017/03/17 00:01:03
Changed to OnScreenRotationAnimationFinished
| |
| 67 ScreenRotationAnimator* animator) override; | |
| 68 | |
| 62 protected: | 69 protected: |
| 63 friend class ash::test::ShellTestApi; | 70 friend class ash::test::DisplayConfigurationControllerTestApi; |
| 64 | 71 |
| 65 // Allow tests to skip animations. | 72 // Allow tests to skip animations. |
| 66 void ResetAnimatorForTest(); | 73 void ResetAnimatorForTest(); |
| 67 | 74 |
| 68 private: | 75 private: |
| 69 class DisplayChangeLimiter; | 76 class DisplayChangeLimiter; |
| 70 | 77 |
| 71 // Sets the timeout for the DisplayChangeLimiter if it exists. Call this | 78 // Sets the timeout for the DisplayChangeLimiter if it exists. Call this |
| 72 // *before* starting any animations. | 79 // *before* starting any animations. |
| 73 void SetThrottleTimeout(int64_t throttle_ms); | 80 void SetThrottleTimeout(int64_t throttle_ms); |
| 74 bool IsLimited(); | 81 bool IsLimited(); |
| 75 void SetDisplayLayoutImpl(std::unique_ptr<display::DisplayLayout> layout); | 82 void SetDisplayLayoutImpl(std::unique_ptr<display::DisplayLayout> layout); |
| 76 void SetMirrorModeImpl(bool mirror); | 83 void SetMirrorModeImpl(bool mirror); |
| 77 void SetPrimaryDisplayIdImpl(int64_t display_id); | 84 void SetPrimaryDisplayIdImpl(int64_t display_id); |
| 78 | 85 |
| 86 // Returns true if the screen rotation animation can be completed | |
| 87 // successfully. For example an animation is not possible if |display_id_| | |
| 88 // specifies a display::Display that is not currently active. See | |
| 89 // www.crbug.com/479503. | |
| 90 bool CanAnimateScreenRotation(int64_t display_id) const; | |
| 91 | |
| 92 // Returns the currently active rotation for the display with |display_id|. If | |
| 93 // an animation is in progress, the target rotation will be returned. | |
| 94 display::Display::Rotation GetCurrentScreenRotation(int64_t display_id) const; | |
| 95 | |
| 96 // Returns the ScreenRotationAnimator associated with the |display_id|. If | |
| 97 // there is no existing ScreenRotationAnimator for |display_id|, it will make | |
| 98 // one and store the pair in the |rotation_animator_map_|. | |
| 99 ScreenRotationAnimator* GetScreenRotationAnimatorForDisplay( | |
| 100 int64_t display_id); | |
| 101 | |
| 79 display::DisplayManager* display_manager_; // weak ptr | 102 display::DisplayManager* display_manager_; // weak ptr |
| 80 WindowTreeHostManager* window_tree_host_manager_; // weak ptr | 103 WindowTreeHostManager* window_tree_host_manager_; // weak ptr |
| 81 std::unique_ptr<DisplayAnimator> display_animator_; | 104 std::unique_ptr<DisplayAnimator> display_animator_; |
| 82 std::unique_ptr<DisplayChangeLimiter> limiter_; | 105 std::unique_ptr<DisplayChangeLimiter> limiter_; |
| 83 | 106 |
| 107 // Tracks |display_id| to ScreenRotationAnimator mappings. The | |
| 108 // |rotation_animator_map_| is populated on demand the first time a | |
| 109 // ScreenRotationAnimator is needed for a given |display_id|. | |
| 110 // On animation ended or aborted, the animator may be deleted if there is no | |
| 111 // more pending rotation request. | |
| 112 std::unordered_map<int64_t, std::unique_ptr<ScreenRotationAnimator>> | |
| 113 rotation_animator_map_; | |
| 114 | |
| 84 base::WeakPtrFactory<DisplayConfigurationController> weak_ptr_factory_; | 115 base::WeakPtrFactory<DisplayConfigurationController> weak_ptr_factory_; |
| 85 | 116 |
| 86 DISALLOW_COPY_AND_ASSIGN(DisplayConfigurationController); | 117 DISALLOW_COPY_AND_ASSIGN(DisplayConfigurationController); |
| 87 }; | 118 }; |
| 88 | 119 |
| 89 } // namespace ash | 120 } // namespace ash |
| 90 | 121 |
| 91 #endif // ASH_DISPLAY_DISPLAY_CONFIGURATION_CONTROLLER_H_ | 122 #endif // ASH_DISPLAY_DISPLAY_CONFIGURATION_CONTROLLER_H_ |
| OLD | NEW |