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

Side by Side Diff: ash/rotator/screen_rotation_animator.h

Issue 2780823002: Uses copy request to flatten the layers to do screen rotation animation. (Closed)
Patch Set: Add tests for enable_smooth_screen_rotation code path. Created 3 years, 8 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ 5 #ifndef ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_
6 #define ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ 6 #define ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "ash/ash_export.h" 10 #include "ash/ash_export.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/observer_list.h" 13 #include "base/observer_list.h"
14 #include "ui/display/display.h" 14 #include "ui/display/display.h"
15 15
16 namespace cc {
17 class CopyOutputRequest;
18 class CopyOutputResult;
19 } // namespace cc
20
16 namespace ui { 21 namespace ui {
17 class AnimationMetricsReporter; 22 class AnimationMetricsReporter;
18 class Layer; 23 class Layer;
19 class LayerTreeOwner; 24 class LayerTreeOwner;
20 } // namespace ui 25 } // namespace ui
21 26
22 namespace ash { 27 namespace ash {
23 namespace test { 28 namespace test {
24 class ScreenRotationAnimatorTestApi; 29 class ScreenRotationAnimatorTestApi;
25 } // namespace test 30 } // namespace test
26 31
27 class ScreenRotationAnimatorObserver; 32 class ScreenRotationAnimatorObserver;
28 33
29 // Utility to perform a screen rotation with an animation. 34 // Utility to perform a screen rotation with an animation.
30 class ASH_EXPORT ScreenRotationAnimator { 35 class ASH_EXPORT ScreenRotationAnimator {
31 public: 36 public:
32 explicit ScreenRotationAnimator(int64_t display_id); 37 explicit ScreenRotationAnimator(int64_t display_id);
33 ~ScreenRotationAnimator(); 38 virtual ~ScreenRotationAnimator();
34 39
35 // Rotates the display::Display specified by |display_id_| to the 40 // Rotates the display::Display specified by |display_id_| to the
36 // |new_rotation| orientation, for the given |source|. The rotation will also 41 // |new_rotation| orientation, for the given |source|. The rotation will also
37 // become active. Should only be called when |display_id_| references a valid 42 // become active. Should only be called when |display_id_| references a valid
38 // display::Display. |screen_rotation_animator_observer_| will be notified 43 // display::Display. |screen_rotation_animator_observer_| will be notified
39 // when rotation is finished and there is no more pending rotation request. 44 // when rotation is finished and there is no more pending rotation request.
40 // Otherwise, any ongoing animation will be stopped and progressed to the 45 // Otherwise, any ongoing animation will be stopped and progressed to the
41 // target position, followed by a new |Rotate()| call with the pending 46 // target position, followed by a new |Rotate()| call with the pending
42 // rotation request. 47 // rotation request.
43 void Rotate(display::Display::Rotation new_rotation, 48 void Rotate(display::Display::Rotation new_rotation,
44 display::Display::RotationSource source); 49 display::Display::RotationSource source);
45 50
46 int64_t display_id() const { return display_id_; } 51 int64_t display_id() const { return display_id_; }
47 52
48 void AddScreenRotationAnimatorObserver( 53 void AddScreenRotationAnimatorObserver(
49 ScreenRotationAnimatorObserver* observer); 54 ScreenRotationAnimatorObserver* observer);
50 void RemoveScreenRotationAnimatorObserver( 55 void RemoveScreenRotationAnimatorObserver(
51 ScreenRotationAnimatorObserver* observer); 56 ScreenRotationAnimatorObserver* observer);
52 57
53 // When screen rotation animation is ended or aborted, calls |Rotate()| with 58 // When screen rotation animation is ended or aborted, calls |Rotate()| with
54 // the pending rotation request if the request queue is not empty. Otherwise 59 // the pending rotation request if the request queue is not empty. Otherwise
55 // notifies |screen_rotation_animator_observer_|. 60 // notifies |screen_rotation_animator_observer_|.
56 void ProcessAnimationQueue(); 61 void ProcessAnimationQueue();
57 62
63 protected:
64 struct ScreenRotationRequest {
65 ScreenRotationRequest(display::Display::Rotation to_rotation,
66 display::Display::RotationSource from_source)
67 : new_rotation(to_rotation), source(from_source) {}
68 display::Display::Rotation new_rotation;
69 display::Display::RotationSource source;
70 };
oshima 2017/04/04 20:23:13 can you move the definition to .cc?
wutao 2017/04/05 00:09:22 Tested, but have error: invalid application of 'si
71
72 // This function can be overridden in unit test to test removing external
73 // display.
74 virtual std::unique_ptr<cc::CopyOutputRequest> CreateAfterCopyCallback(
75 std::unique_ptr<ScreenRotationRequest> rotation_request);
oshima 2017/04/04 20:23:13 you should be able to just call OnceClosure Crea
wutao 2017/04/05 00:09:22 Done. But I need to specify the callback type, can
76
77 // The callback in |RequestCopyRootLayerAndAnimateRotation()|.
78 void OnRootLayerCopiedBeforeRotation(
79 std::unique_ptr<ScreenRotationRequest> rotation_request,
80 std::unique_ptr<cc::CopyOutputResult> result);
81
58 private: 82 private:
59 friend class ash::test::ScreenRotationAnimatorTestApi; 83 friend class ash::test::ScreenRotationAnimatorTestApi;
60 struct ScreenRotationRequest;
61 84
62 // Set the screen orientation to |new_rotation| and animate the change. The 85 void StartRotationAnimation(
86 std::unique_ptr<ScreenRotationRequest> rotation_request);
87
88 // This is an asynchronous call to request copy output of root layer.
89 void RequestCopyRootLayerAndAnimateRotation(
90 std::unique_ptr<ScreenRotationRequest> rotation_request);
91
92 // Recreates all |root_window| layers.
93 void CreateOldLayerTree();
94
95 // Requests a copy of |root_window| root layer output.
96 void CopyOldLayerTree(std::unique_ptr<cc::CopyOutputResult> result);
97
98 // Note: Only call this function when the |old_layer_tree_owner_| is set up
99 // properly.
100 // Sets the screen orientation to |new_rotation| and animate the change. The
63 // animation will rotate the initial orientation's layer towards the new 101 // animation will rotate the initial orientation's layer towards the new
64 // orientation through |rotation_degrees| while fading out, and the new 102 // orientation through |rotation_degrees| while fading out, and the new
65 // orientation's layer will be rotated in to the |new_orientation| through 103 // orientation's layer will be rotated in to the |new_orientation| through
66 // |rotation_degrees| arc. 104 // |rotation_degrees| arc.
67 void AnimateRotation(std::unique_ptr<ScreenRotationRequest> rotation_request); 105 void AnimateRotation(std::unique_ptr<ScreenRotationRequest> rotation_request);
68 106
69 void set_disable_animation_timers_for_test(bool disable_timers); 107 void set_disable_animation_timers_for_test(bool disable_timers);
70 108
109 void set_enable_smooth_rotation_for_test(bool enable_smooth_rotation);
110
71 void StopAnimating(); 111 void StopAnimating();
72 112
73 // The id of the display to rotate. 113 // The id of the display to rotate.
74 int64_t display_id_; 114 int64_t display_id_;
75 bool is_rotating_; 115 bool is_rotating_;
76 std::unique_ptr<ui::AnimationMetricsReporter> metrics_reporter_; 116 std::unique_ptr<ui::AnimationMetricsReporter> metrics_reporter_;
77 // Only set in unittest to disable animation timers. 117 // Only set in unittest to disable animation timers.
78 bool disable_animation_timers_for_test_; 118 bool disable_animation_timers_for_test_;
119 // Only set in unittest to enable smooth rotation.
120 bool enable_smooth_rotation_for_test_;
79 base::ObserverList<ScreenRotationAnimatorObserver> 121 base::ObserverList<ScreenRotationAnimatorObserver>
80 screen_rotation_animator_observers_; 122 screen_rotation_animator_observers_;
81 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree_owner_; 123 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree_owner_;
82 std::unique_ptr<ScreenRotationRequest> last_pending_request_; 124 std::unique_ptr<ScreenRotationRequest> last_pending_request_;
83 base::WeakPtrFactory<ScreenRotationAnimator> weak_factory_; 125 base::WeakPtrFactory<ScreenRotationAnimator> weak_factory_;
84 126
85 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimator); 127 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimator);
86 }; 128 };
87 129
88 } // namespace ash 130 } // namespace ash
89 131
90 #endif // ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ 132 #endif // ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698