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.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 ShellTestApi; |
| 25 } // namespace test | 26 } // namespace test |
| 26 | 27 |
| 27 class DisplayAnimator; | 28 class DisplayAnimator; |
| 28 | 29 |
| 29 // This class controls Display related configuration. Specifically it: | 30 // This class controls Display related configuration. Specifically it: |
| 30 // * Handles animated transitions where appropriate. | 31 // * Handles animated transitions where appropriate. |
| 31 // * Limits the frequency of certain operations. | 32 // * Limits the frequency of certain operations. |
| 32 // * Provides a single interface for UI and API classes. | 33 // * Provides a single interface for UI and API classes. |
| 33 // * TODO: Forwards display configuration changed events to UI and API classes. | 34 // * TODO: Forwards display configuration changed events to UI and API classes. |
| 34 class ASH_EXPORT DisplayConfigurationController | 35 class ASH_EXPORT DisplayConfigurationController |
| 35 : public WindowTreeHostManager::Observer { | 36 : public WindowTreeHostManager::Observer, |
| 37 public ScreenRotationAnimator::ScreenRotationAnimatorObserver { | |
| 36 public: | 38 public: |
| 37 DisplayConfigurationController( | 39 DisplayConfigurationController( |
| 38 display::DisplayManager* display_manager, | 40 display::DisplayManager* display_manager, |
| 39 WindowTreeHostManager* window_tree_host_manager); | 41 WindowTreeHostManager* window_tree_host_manager); |
| 40 ~DisplayConfigurationController() override; | 42 ~DisplayConfigurationController() override; |
| 41 | 43 |
| 42 // Sets the layout for the current displays with a fade in/out | 44 // Sets the layout for the current displays with a fade in/out |
| 43 // animation. Currently |display_id| is assumed to be the secondary | 45 // animation. Currently |display_id| is assumed to be the secondary |
| 44 // display. TODO(oshima/stevenjb): Support 3+ displays. | 46 // display. TODO(oshima/stevenjb): Support 3+ displays. |
| 45 void SetDisplayLayout(std::unique_ptr<display::DisplayLayout> layout, | 47 void SetDisplayLayout(std::unique_ptr<display::DisplayLayout> layout, |
| 46 bool user_action); | 48 bool user_action); |
| 47 | 49 |
| 48 // 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 |
| 49 // displays. | 51 // displays. |
| 50 void SetMirrorMode(bool mirror, bool user_action); | 52 void SetMirrorMode(bool mirror, bool user_action); |
| 51 | 53 |
| 52 // Sets the display's rotation with animation if available. | 54 // Sets the display's rotation with animation if available. |
| 53 void SetDisplayRotation(int64_t display_id, | 55 void SetDisplayRotation(int64_t display_id, |
| 54 display::Display::Rotation rotation, | 56 display::Display::Rotation rotation, |
| 55 display::Display::RotationSource source); | 57 display::Display::RotationSource source); |
| 56 | 58 |
| 57 // Sets the primary display id. | 59 // Sets the primary display id. |
| 58 void SetPrimaryDisplayId(int64_t display_id, bool user_action); | 60 void SetPrimaryDisplayId(int64_t display_id, bool user_action); |
| 59 | 61 |
| 60 // WindowTreeHostManager::Observer | 62 // WindowTreeHostManager::Observer |
| 61 void OnDisplayConfigurationChanged() override; | 63 void OnDisplayConfigurationChanged() override; |
| 62 | 64 |
| 65 // ScreenRotationAnimator::ScreenRotationAnimatorObserver | |
| 66 void OnEndedOrAbortedAnimation( | |
| 67 base::WeakPtr<ScreenRotationAnimator> animator) override; | |
| 68 | |
| 63 protected: | 69 protected: |
| 64 friend class ash::test::ShellTestApi; | 70 friend class ash::test::ShellTestApi; |
| 65 | 71 |
| 66 // Allow tests to skip animations. | 72 // Allow tests to skip animations. |
| 67 void ResetAnimatorForTest(); | 73 void ResetAnimatorForTest(); |
| 68 | 74 |
| 69 private: | 75 private: |
| 76 // Returns true if the screen rotation animation can be completed | |
| 77 // successfully. For example an animation is not possible if |display_id_| | |
| 78 // specifies a display::Display that is not currently active. See | |
| 79 // www.crbug.com/479503. | |
| 80 bool CanAnimate(int64_t display_id) const; | |
|
bruthig
2017/03/02 18:25:45
"CanAnimate" is ambiguous, might I suggest "CanAni
wutao
2017/03/03 02:45:52
Done.
| |
| 81 display::Display::Rotation GetCurrentRotation(int64_t display_id) const; | |
|
bruthig
2017/03/02 18:25:45
nit 1: newlines between function declarations here
wutao
2017/03/03 02:45:52
1. Done.
2. Done.
3. Done.
| |
| 82 // Polulate the ash::ScreenRotationAnimator | |
|
bruthig
2017/03/02 18:25:45
nit: Polulate -> populate
wutao
2017/03/03 02:45:52
Removed the comment since I changed the function n
| |
| 83 ScreenRotationAnimator* GetOrMakeAnimatorByDisplayId(int64_t display_id); | |
|
bruthig
2017/03/02 18:25:45
This class also appears to use a DisplayAnimator =
wutao
2017/03/03 02:45:52
Changed to GetScreenRotationAnimatorForDisplay.
| |
| 84 | |
| 70 class DisplayChangeLimiter; | 85 class DisplayChangeLimiter; |
| 71 | 86 |
| 72 // Sets the timeout for the DisplayChangeLimiter if it exists. Call this | 87 // Sets the timeout for the DisplayChangeLimiter if it exists. Call this |
| 73 // *before* starting any animations. | 88 // *before* starting any animations. |
| 74 void SetThrottleTimeout(int64_t throttle_ms); | 89 void SetThrottleTimeout(int64_t throttle_ms); |
| 75 bool IsLimited(); | 90 bool IsLimited(); |
| 76 void SetDisplayLayoutImpl(std::unique_ptr<display::DisplayLayout> layout); | 91 void SetDisplayLayoutImpl(std::unique_ptr<display::DisplayLayout> layout); |
| 77 void SetMirrorModeImpl(bool mirror); | 92 void SetMirrorModeImpl(bool mirror); |
| 78 void SetPrimaryDisplayIdImpl(int64_t display_id); | 93 void SetPrimaryDisplayIdImpl(int64_t display_id); |
| 79 | 94 |
| 80 display::DisplayManager* display_manager_; // weak ptr | 95 display::DisplayManager* display_manager_; // weak ptr |
| 81 WindowTreeHostManager* window_tree_host_manager_; // weak ptr | 96 WindowTreeHostManager* window_tree_host_manager_; // weak ptr |
| 82 std::unique_ptr<DisplayAnimator> display_animator_; | 97 std::unique_ptr<DisplayAnimator> display_animator_; |
| 83 std::unique_ptr<DisplayChangeLimiter> limiter_; | 98 std::unique_ptr<DisplayChangeLimiter> limiter_; |
| 84 | 99 |
| 100 // Tracks |display_id| to ScreenRotationAnimator mappings. The | |
| 101 // |display_animator_map_| is populated on demand the first time a | |
| 102 // ScreenRotationAnimator is needed for a given |display_id|. | |
| 103 // On animation ended or aborted, the animator may be deleted if there is no | |
| 104 // more pending rotation request. | |
|
bruthig
2017/03/02 18:25:45
Very helpful comment!!
wutao
2017/03/03 02:45:52
Acknowledged.
| |
| 105 std::unordered_map<int64_t, std::unique_ptr<ScreenRotationAnimator>> | |
| 106 display_animator_map_; | |
| 107 | |
| 85 base::WeakPtrFactory<DisplayConfigurationController> weak_ptr_factory_; | 108 base::WeakPtrFactory<DisplayConfigurationController> weak_ptr_factory_; |
| 86 | 109 |
| 87 DISALLOW_COPY_AND_ASSIGN(DisplayConfigurationController); | 110 DISALLOW_COPY_AND_ASSIGN(DisplayConfigurationController); |
| 88 }; | 111 }; |
| 89 | 112 |
| 90 } // namespace ash | 113 } // namespace ash |
| 91 | 114 |
| 92 #endif // ASH_DISPLAY_DISPLAY_CONFIGURATION_CONTROLLER_H_ | 115 #endif // ASH_DISPLAY_DISPLAY_CONFIGURATION_CONTROLLER_H_ |
| OLD | NEW |