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 // This will be called when the animation is ended or aborted. | |
| 67 void OnScreenRotationAnimationFinished( | |
| 68 ScreenRotationAnimator* animator) override; | |
| 69 | |
| 62 protected: | 70 protected: |
| 63 friend class ash::test::ShellTestApi; | 71 friend class ash::test::DisplayConfigurationControllerTestApi; |
| 64 | 72 |
| 65 // Allow tests to skip animations. | 73 // Allow tests to skip animations. |
| 66 void ResetAnimatorForTest(); | 74 void ResetAnimatorForTest(); |
| 67 | 75 |
| 68 private: | 76 private: |
| 69 class DisplayChangeLimiter; | 77 class DisplayChangeLimiter; |
| 70 | 78 |
| 71 // Sets the timeout for the DisplayChangeLimiter if it exists. Call this | 79 // Sets the timeout for the DisplayChangeLimiter if it exists. Call this |
| 72 // *before* starting any animations. | 80 // *before* starting any animations. |
| 73 void SetThrottleTimeout(int64_t throttle_ms); | 81 void SetThrottleTimeout(int64_t throttle_ms); |
| 74 bool IsLimited(); | 82 bool IsLimited(); |
| 75 void SetDisplayLayoutImpl(std::unique_ptr<display::DisplayLayout> layout); | 83 void SetDisplayLayoutImpl(std::unique_ptr<display::DisplayLayout> layout); |
| 76 void SetMirrorModeImpl(bool mirror); | 84 void SetMirrorModeImpl(bool mirror); |
| 77 void SetPrimaryDisplayIdImpl(int64_t display_id); | 85 void SetPrimaryDisplayIdImpl(int64_t display_id); |
| 78 | 86 |
| 87 // Returns the currently active rotation for the display with |display_id|. If | |
| 88 // an animation is in progress, the target rotation will be returned. | |
| 89 display::Display::Rotation GetCurrentScreenRotation( | |
| 90 int64_t display_id) const { | |
| 91 return display_manager_->GetDisplayInfo(display_id).GetActiveRotation(); | |
|
oshima
2017/03/17 19:41:59
this looks simple enough to do this in .cc file?
wutao
2017/03/17 20:35:00
Removed.
| |
| 92 } | |
| 93 | |
| 94 // Returns the ScreenRotationAnimator associated with the |display_id|. If | |
| 95 // there is no existing ScreenRotationAnimator for |display_id|, it will make | |
| 96 // one and store the pair in the |rotation_animator_map_|. | |
| 97 ScreenRotationAnimator* GetScreenRotationAnimatorForDisplay( | |
| 98 int64_t display_id); | |
| 99 | |
| 79 display::DisplayManager* display_manager_; // weak ptr | 100 display::DisplayManager* display_manager_; // weak ptr |
| 80 WindowTreeHostManager* window_tree_host_manager_; // weak ptr | 101 WindowTreeHostManager* window_tree_host_manager_; // weak ptr |
| 81 std::unique_ptr<DisplayAnimator> display_animator_; | 102 std::unique_ptr<DisplayAnimator> display_animator_; |
| 82 std::unique_ptr<DisplayChangeLimiter> limiter_; | 103 std::unique_ptr<DisplayChangeLimiter> limiter_; |
| 83 | 104 |
| 105 // Tracks |display_id| to ScreenRotationAnimator mappings. The | |
| 106 // |rotation_animator_map_| is populated on demand the first time a | |
| 107 // ScreenRotationAnimator is needed for a given |display_id|. | |
| 108 // On animation ended or aborted, the animator may be deleted if there is no | |
| 109 // more pending rotation request. | |
| 110 std::unordered_map<int64_t, std::unique_ptr<ScreenRotationAnimator>> | |
| 111 rotation_animator_map_; | |
| 112 | |
| 84 base::WeakPtrFactory<DisplayConfigurationController> weak_ptr_factory_; | 113 base::WeakPtrFactory<DisplayConfigurationController> weak_ptr_factory_; |
| 85 | 114 |
| 86 DISALLOW_COPY_AND_ASSIGN(DisplayConfigurationController); | 115 DISALLOW_COPY_AND_ASSIGN(DisplayConfigurationController); |
| 87 }; | 116 }; |
| 88 | 117 |
| 89 } // namespace ash | 118 } // namespace ash |
| 90 | 119 |
| 91 #endif // ASH_DISPLAY_DISPLAY_CONFIGURATION_CONTROLLER_H_ | 120 #endif // ASH_DISPLAY_DISPLAY_CONFIGURATION_CONTROLLER_H_ |
| OLD | NEW |