Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: ash/display/display_configuration_controller.h

Issue 2728803002: Handles users rotating screen too early (Closed)
Patch Set: Add MultiLayerAnimatorTestController to controll test animation. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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;
30 class ScreenRotationAnimatorObserver;
bruthig 2017/03/15 23:12:37 nit: remove?
wutao 2017/03/16 07:37:59 Done.
28 31
29 // This class controls Display related configuration. Specifically it: 32 // This class controls Display related configuration. Specifically it:
30 // * Handles animated transitions where appropriate. 33 // * Handles animated transitions where appropriate.
31 // * Limits the frequency of certain operations. 34 // * Limits the frequency of certain operations.
32 // * Provides a single interface for UI and API classes. 35 // * Provides a single interface for UI and API classes.
33 // * TODO: Forwards display configuration changed events to UI and API classes. 36 // * TODO: Forwards display configuration changed events to UI and API classes.
34 class ASH_EXPORT DisplayConfigurationController 37 class ASH_EXPORT DisplayConfigurationController
35 : public WindowTreeHostManager::Observer { 38 : public WindowTreeHostManager::Observer,
39 public ScreenRotationAnimatorObserver {
36 public: 40 public:
37 DisplayConfigurationController( 41 DisplayConfigurationController(
38 display::DisplayManager* display_manager, 42 display::DisplayManager* display_manager,
39 WindowTreeHostManager* window_tree_host_manager); 43 WindowTreeHostManager* window_tree_host_manager);
40 ~DisplayConfigurationController() override; 44 ~DisplayConfigurationController() override;
41 45
42 // Sets the layout for the current displays with a fade in/out 46 // Sets the layout for the current displays with a fade in/out
43 // animation. Currently |display_id| is assumed to be the secondary 47 // animation. Currently |display_id| is assumed to be the secondary
44 // display. TODO(oshima/stevenjb): Support 3+ displays. 48 // display. TODO(oshima/stevenjb): Support 3+ displays.
45 void SetDisplayLayout(std::unique_ptr<display::DisplayLayout> layout, 49 void SetDisplayLayout(std::unique_ptr<display::DisplayLayout> layout,
46 bool user_action); 50 bool user_action);
47 51
48 // Sets the mirror mode with a fade-in/fade-out animation. Affects all 52 // Sets the mirror mode with a fade-in/fade-out animation. Affects all
49 // displays. 53 // displays.
50 void SetMirrorMode(bool mirror, bool user_action); 54 void SetMirrorMode(bool mirror, bool user_action);
51 55
52 // Sets the display's rotation with animation if available. 56 // Sets the display's rotation with animation if available.
53 void SetDisplayRotation(int64_t display_id, 57 void SetDisplayRotation(int64_t display_id,
54 display::Display::Rotation rotation, 58 display::Display::Rotation rotation,
55 display::Display::RotationSource source); 59 display::Display::RotationSource source);
56 60
57 // Sets the primary display id. 61 // Sets the primary display id.
58 void SetPrimaryDisplayId(int64_t display_id, bool user_action); 62 void SetPrimaryDisplayId(int64_t display_id, bool user_action);
59 63
60 // WindowTreeHostManager::Observer 64 // WindowTreeHostManager::Observer
61 void OnDisplayConfigurationChanged() override; 65 void OnDisplayConfigurationChanged() override;
62 66
67 // ScreenRotationAnimatorObserver
68 void OnEndedOrAbortedScreenRotationAnimation(
69 ScreenRotationAnimator* animator) override;
70
63 protected: 71 protected:
64 friend class ash::test::ShellTestApi; 72 friend class ash::test::DisplayConfigurationControllerTestApi;
65 73
66 // Allow tests to skip animations. 74 // Allow tests to skip animations.
67 void ResetAnimatorForTest(); 75 void ResetAnimatorForTest();
68 76
69 private: 77 private:
70 class DisplayChangeLimiter; 78 class DisplayChangeLimiter;
71 79
72 // Sets the timeout for the DisplayChangeLimiter if it exists. Call this 80 // Sets the timeout for the DisplayChangeLimiter if it exists. Call this
73 // *before* starting any animations. 81 // *before* starting any animations.
74 void SetThrottleTimeout(int64_t throttle_ms); 82 void SetThrottleTimeout(int64_t throttle_ms);
75 bool IsLimited(); 83 bool IsLimited();
76 void SetDisplayLayoutImpl(std::unique_ptr<display::DisplayLayout> layout); 84 void SetDisplayLayoutImpl(std::unique_ptr<display::DisplayLayout> layout);
77 void SetMirrorModeImpl(bool mirror); 85 void SetMirrorModeImpl(bool mirror);
78 void SetPrimaryDisplayIdImpl(int64_t display_id); 86 void SetPrimaryDisplayIdImpl(int64_t display_id);
79 87
88 // Returns true if the screen rotation animation can be completed
89 // successfully. For example an animation is not possible if |display_id_|
90 // specifies a display::Display that is not currently active. See
91 // www.crbug.com/479503.
92 bool CanAnimateScreenRotation(int64_t display_id) const;
93
94 // Returns the currently active rotation for the display with |display_id|. If
95 // an animation is in progress, the target rotation will be returned.
96 display::Display::Rotation GetCurrentScreenRotation(int64_t display_id) const;
97
98 // Returns the ScreenRotationAnimator associated with the |display_id|. If
99 // there is no existing ScreenRotationAnimator for |display_id|, it will make
100 // one and store the pair in the |rotation_animator_map_|.
101 ScreenRotationAnimator* GetScreenRotationAnimatorForDisplay(
102 int64_t display_id);
103
80 display::DisplayManager* display_manager_; // weak ptr 104 display::DisplayManager* display_manager_; // weak ptr
81 WindowTreeHostManager* window_tree_host_manager_; // weak ptr 105 WindowTreeHostManager* window_tree_host_manager_; // weak ptr
82 std::unique_ptr<DisplayAnimator> display_animator_; 106 std::unique_ptr<DisplayAnimator> display_animator_;
83 std::unique_ptr<DisplayChangeLimiter> limiter_; 107 std::unique_ptr<DisplayChangeLimiter> limiter_;
84 108
109 // Tracks |display_id| to ScreenRotationAnimator mappings. The
110 // |rotation_animator_map_| is populated on demand the first time a
111 // ScreenRotationAnimator is needed for a given |display_id|.
112 // On animation ended or aborted, the animator may be deleted if there is no
113 // more pending rotation request.
114 std::unordered_map<int64_t, std::unique_ptr<ScreenRotationAnimator>>
115 rotation_animator_map_;
116
85 base::WeakPtrFactory<DisplayConfigurationController> weak_ptr_factory_; 117 base::WeakPtrFactory<DisplayConfigurationController> weak_ptr_factory_;
86 118
87 DISALLOW_COPY_AND_ASSIGN(DisplayConfigurationController); 119 DISALLOW_COPY_AND_ASSIGN(DisplayConfigurationController);
88 }; 120 };
89 121
90 } // namespace ash 122 } // namespace ash
91 123
92 #endif // ASH_DISPLAY_DISPLAY_CONFIGURATION_CONTROLLER_H_ 124 #endif // ASH_DISPLAY_DISPLAY_CONFIGURATION_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698