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

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: Resolve merge conflicts. 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
« no previous file with comments | « ash/common/ash_switches.cc ('k') | ash/rotator/screen_rotation_animator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/callback_forward.h"
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
13 #include "base/observer_list.h" 14 #include "base/observer_list.h"
14 #include "ui/display/display.h" 15 #include "ui/display/display.h"
15 16
17 namespace cc {
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 using CopyCallback =
65 base::Callback<void(std::unique_ptr<cc::CopyOutputResult> result)>;
66 struct ScreenRotationRequest {
67 ScreenRotationRequest(display::Display::Rotation to_rotation,
68 display::Display::RotationSource from_source)
69 : new_rotation(to_rotation), source(from_source) {}
70 display::Display::Rotation new_rotation;
71 display::Display::RotationSource source;
72 };
73
74 // This function can be overridden in unit test to test removing external
75 // display.
76 virtual CopyCallback CreateAfterCopyCallback(
77 std::unique_ptr<ScreenRotationRequest> rotation_request);
78
58 private: 79 private:
59 friend class ash::test::ScreenRotationAnimatorTestApi; 80 friend class ash::test::ScreenRotationAnimatorTestApi;
60 struct ScreenRotationRequest;
61 81
62 // Set the screen orientation to |new_rotation| and animate the change. The 82 void StartRotationAnimation(
83 std::unique_ptr<ScreenRotationRequest> rotation_request);
84
85 // This is an asynchronous call to request copy output of root layer.
86 void RequestCopyRootLayerAndAnimateRotation(
87 std::unique_ptr<ScreenRotationRequest> rotation_request);
88
89 // The callback in |RequestCopyRootLayerAndAnimateRotation()|.
90 void OnRootLayerCopiedBeforeRotation(
91 std::unique_ptr<ScreenRotationRequest> rotation_request,
92 std::unique_ptr<cc::CopyOutputResult> result);
93
94 // Recreates all |root_window| layers.
95 void CreateOldLayerTree();
96
97 // Requests a copy of |root_window| root layer output.
98 void CopyOldLayerTree(std::unique_ptr<cc::CopyOutputResult> result);
99
100 // Note: Only call this function when the |old_layer_tree_owner_| is set up
101 // properly.
102 // Sets the screen orientation to |new_rotation| and animate the change. The
63 // animation will rotate the initial orientation's layer towards the new 103 // animation will rotate the initial orientation's layer towards the new
64 // orientation through |rotation_degrees| while fading out, and the new 104 // orientation through |rotation_degrees| while fading out, and the new
65 // orientation's layer will be rotated in to the |new_orientation| through 105 // orientation's layer will be rotated in to the |new_orientation| through
66 // |rotation_degrees| arc. 106 // |rotation_degrees| arc.
67 void AnimateRotation(std::unique_ptr<ScreenRotationRequest> rotation_request); 107 void AnimateRotation(std::unique_ptr<ScreenRotationRequest> rotation_request);
68 108
69 void set_disable_animation_timers_for_test(bool disable_timers); 109 void set_disable_animation_timers_for_test(bool disable_timers);
70 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_;
79 base::ObserverList<ScreenRotationAnimatorObserver> 119 base::ObserverList<ScreenRotationAnimatorObserver>
80 screen_rotation_animator_observers_; 120 screen_rotation_animator_observers_;
81 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree_owner_; 121 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree_owner_;
82 std::unique_ptr<ScreenRotationRequest> last_pending_request_; 122 std::unique_ptr<ScreenRotationRequest> last_pending_request_;
83 base::WeakPtrFactory<ScreenRotationAnimator> weak_factory_; 123 base::WeakPtrFactory<ScreenRotationAnimator> weak_factory_;
84 124
85 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimator); 125 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimator);
86 }; 126 };
87 127
88 } // namespace ash 128 } // namespace ash
89 129
90 #endif // ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_ 130 #endif // ASH_ROTATOR_SCREEN_ROTATION_ANIMATOR_H_
OLDNEW
« no previous file with comments | « ash/common/ash_switches.cc ('k') | ash/rotator/screen_rotation_animator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698