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

Side by Side Diff: cc/test/animation_timelines_test_common.h

Issue 1904653002: CC Animation: Merge LayerAnimationController into ElementAnimations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor optimization: Don't init value observations if same host. Created 4 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 | « cc/test/animation_test_common.cc ('k') | cc/test/animation_timelines_test_common.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 CC_TEST_ANIMATION_TIMELINES_TEST_COMMON_H_ 5 #ifndef CC_TEST_ANIMATION_TIMELINES_TEST_COMMON_H_
6 #define CC_TEST_ANIMATION_TIMELINES_TEST_COMMON_H_ 6 #define CC_TEST_ANIMATION_TIMELINES_TEST_COMMON_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <unordered_map> 9 #include <unordered_map>
10 10
11 #include "cc/animation/animation.h" 11 #include "cc/animation/animation.h"
12 #include "cc/animation/animation_delegate.h" 12 #include "cc/animation/animation_delegate.h"
13 #include "cc/animation/animation_host.h" 13 #include "cc/animation/animation_host.h"
14 #include "cc/trees/mutator_host_client.h" 14 #include "cc/trees/mutator_host_client.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "ui/gfx/geometry/scroll_offset.h" 16 #include "ui/gfx/geometry/scroll_offset.h"
17 17
18 namespace cc { 18 namespace cc {
19 19
20 class TestLayer { 20 class TestLayer {
21 public: 21 public:
22 static std::unique_ptr<TestLayer> Create(); 22 static std::unique_ptr<TestLayer> Create();
23 23
24 void ClearMutatedProperties(); 24 void ClearMutatedProperties();
25 25
26 int transform_x() const { return transform_x_; } 26 int transform_x() const;
27 int transform_y() const { return transform_y_; } 27 int transform_y() const;
28 float brightness() const;
28 29
29 void set_transform(int transform_x, int transform_y) { 30 const gfx::Transform& transform() const { return transform_; }
30 transform_x_ = transform_x; 31 void set_transform(const gfx::Transform& transform) {
31 transform_y_ = transform_y; 32 transform_ = transform;
32 mutated_properties_[TargetProperty::TRANSFORM] = true; 33 mutated_properties_[TargetProperty::TRANSFORM] = true;
33 } 34 }
34 35
35 float opacity() const { return opacity_; } 36 float opacity() const { return opacity_; }
36 void set_opacity(float opacity) { 37 void set_opacity(float opacity) {
37 opacity_ = opacity; 38 opacity_ = opacity;
38 mutated_properties_[TargetProperty::OPACITY] = true; 39 mutated_properties_[TargetProperty::OPACITY] = true;
39 } 40 }
40 41
41 float brightness() const { return brightness_; } 42 FilterOperations filters() const { return filters_; }
42 void set_brightness(float brightness) { 43 void set_filters(const FilterOperations& filters) {
43 brightness_ = brightness; 44 filters_ = filters;
44 mutated_properties_[TargetProperty::FILTER] = true; 45 mutated_properties_[TargetProperty::FILTER] = true;
45 } 46 }
46 47
47 gfx::ScrollOffset scroll_offset() const { return scroll_offset_; } 48 gfx::ScrollOffset scroll_offset() const { return scroll_offset_; }
48 void set_scroll_offset(const gfx::ScrollOffset& scroll_offset) { 49 void set_scroll_offset(const gfx::ScrollOffset& scroll_offset) {
49 scroll_offset_ = scroll_offset; 50 scroll_offset_ = scroll_offset;
50 mutated_properties_[TargetProperty::SCROLL_OFFSET] = true; 51 mutated_properties_[TargetProperty::SCROLL_OFFSET] = true;
51 } 52 }
52 53
54 bool transform_is_animating() const { return transform_is_animating_; }
55 void set_transform_is_animating(bool is_animating) {
56 transform_is_animating_ = is_animating;
57 }
58
53 bool is_property_mutated(TargetProperty::Type property) const { 59 bool is_property_mutated(TargetProperty::Type property) const {
54 return mutated_properties_[property]; 60 return mutated_properties_[property];
55 } 61 }
56 62
57 private: 63 private:
58 TestLayer(); 64 TestLayer();
59 65
60 int transform_x_; 66 gfx::Transform transform_;
61 int transform_y_;
62
63 float opacity_; 67 float opacity_;
64 float brightness_; 68 FilterOperations filters_;
65 gfx::ScrollOffset scroll_offset_; 69 gfx::ScrollOffset scroll_offset_;
70 bool transform_is_animating_;
66 71
67 bool mutated_properties_[TargetProperty::LAST_TARGET_PROPERTY + 1]; 72 bool mutated_properties_[TargetProperty::LAST_TARGET_PROPERTY + 1];
68 }; 73 };
69 74
70 class TestHostClient : public MutatorHostClient { 75 class TestHostClient : public MutatorHostClient {
71 public: 76 public:
72 explicit TestHostClient(ThreadInstance thread_instance); 77 explicit TestHostClient(ThreadInstance thread_instance);
73 ~TestHostClient(); 78 ~TestHostClient();
74 79
75 void ClearMutatedProperties(); 80 void ClearMutatedProperties();
(...skipping 15 matching lines...) Expand all
91 LayerTreeType tree_type, 96 LayerTreeType tree_type,
92 const gfx::Transform& transform) override; 97 const gfx::Transform& transform) override;
93 98
94 void SetLayerScrollOffsetMutated( 99 void SetLayerScrollOffsetMutated(
95 int layer_id, 100 int layer_id,
96 LayerTreeType tree_type, 101 LayerTreeType tree_type,
97 const gfx::ScrollOffset& scroll_offset) override; 102 const gfx::ScrollOffset& scroll_offset) override;
98 103
99 void LayerTransformIsPotentiallyAnimatingChanged(int layer_id, 104 void LayerTransformIsPotentiallyAnimatingChanged(int layer_id,
100 LayerTreeType tree_type, 105 LayerTreeType tree_type,
101 bool is_animating) override { 106 bool is_animating) override;
102 }
103 107
104 void ScrollOffsetAnimationFinished() override {} 108 void ScrollOffsetAnimationFinished() override {}
109
110 void SetScrollOffsetForAnimation(const gfx::ScrollOffset& scroll_offset);
105 gfx::ScrollOffset GetScrollOffsetForAnimation(int layer_id) const override; 111 gfx::ScrollOffset GetScrollOffsetForAnimation(int layer_id) const override;
106 112
107 bool mutators_need_commit() const { return mutators_need_commit_; } 113 bool mutators_need_commit() const { return mutators_need_commit_; }
108 void set_mutators_need_commit(bool need) { mutators_need_commit_ = need; } 114 void set_mutators_need_commit(bool need) { mutators_need_commit_ = need; }
109 115
110 void RegisterLayer(int layer_id, LayerTreeType tree_type); 116 void RegisterLayer(int layer_id, LayerTreeType tree_type);
111 void UnregisterLayer(int layer_id, LayerTreeType tree_type); 117 void UnregisterLayer(int layer_id, LayerTreeType tree_type);
112 118
113 AnimationHost* host() { 119 AnimationHost* host() {
114 DCHECK(host_); 120 DCHECK(host_);
115 return host_.get(); 121 return host_.get();
116 } 122 }
117 123
118 bool IsPropertyMutated(int layer_id, 124 bool IsPropertyMutated(int layer_id,
119 LayerTreeType tree_type, 125 LayerTreeType tree_type,
120 TargetProperty::Type property) const; 126 TargetProperty::Type property) const;
121 127
128 FilterOperations GetFilters(int layer_id, LayerTreeType tree_type) const;
129 float GetOpacity(int layer_id, LayerTreeType tree_type) const;
130 gfx::Transform GetTransform(int layer_id, LayerTreeType tree_type) const;
131 gfx::ScrollOffset GetScrollOffset(int layer_id,
132 LayerTreeType tree_type) const;
133 bool GetTransformIsAnimating(int layer_id, LayerTreeType tree_type) const;
134
122 void ExpectFilterPropertyMutated(int layer_id, 135 void ExpectFilterPropertyMutated(int layer_id,
123 LayerTreeType tree_type, 136 LayerTreeType tree_type,
124 float brightness) const; 137 float brightness) const;
125 void ExpectOpacityPropertyMutated(int layer_id, 138 void ExpectOpacityPropertyMutated(int layer_id,
126 LayerTreeType tree_type, 139 LayerTreeType tree_type,
127 float opacity) const; 140 float opacity) const;
128 void ExpectTransformPropertyMutated(int layer_id, 141 void ExpectTransformPropertyMutated(int layer_id,
129 LayerTreeType tree_type, 142 LayerTreeType tree_type,
130 int transform_x, 143 int transform_x,
131 int transform_y) const; 144 int transform_y) const;
132 145
133 TestLayer* FindTestLayer(int layer_id, LayerTreeType tree_type) const; 146 TestLayer* FindTestLayer(int layer_id, LayerTreeType tree_type) const;
134 147
135 private: 148 private:
136 std::unique_ptr<AnimationHost> host_; 149 std::unique_ptr<AnimationHost> host_;
137 150
138 using LayerIdToTestLayer = 151 using LayerIdToTestLayer =
139 std::unordered_map<int, std::unique_ptr<TestLayer>>; 152 std::unordered_map<int, std::unique_ptr<TestLayer>>;
140 LayerIdToTestLayer layers_in_active_tree_; 153 LayerIdToTestLayer layers_in_active_tree_;
141 LayerIdToTestLayer layers_in_pending_tree_; 154 LayerIdToTestLayer layers_in_pending_tree_;
142 155
156 gfx::ScrollOffset scroll_offset_;
143 bool mutators_need_commit_; 157 bool mutators_need_commit_;
144 }; 158 };
145 159
146 class TestAnimationDelegate : public AnimationDelegate { 160 class TestAnimationDelegate : public AnimationDelegate {
147 public: 161 public:
148 TestAnimationDelegate(); 162 TestAnimationDelegate();
149 163
150 void NotifyAnimationStarted(base::TimeTicks monotonic_time, 164 void NotifyAnimationStarted(base::TimeTicks monotonic_time,
151 TargetProperty::Type target_property, 165 TargetProperty::Type target_property,
152 int group) override; 166 int group) override;
153 void NotifyAnimationFinished(base::TimeTicks monotonic_time, 167 void NotifyAnimationFinished(base::TimeTicks monotonic_time,
154 TargetProperty::Type target_property, 168 TargetProperty::Type target_property,
155 int group) override; 169 int group) override;
156 void NotifyAnimationAborted(base::TimeTicks monotonic_time, 170 void NotifyAnimationAborted(base::TimeTicks monotonic_time,
157 TargetProperty::Type target_property, 171 TargetProperty::Type target_property,
158 int group) override {} 172 int group) override;
159 void NotifyAnimationTakeover(base::TimeTicks monotonic_time, 173 void NotifyAnimationTakeover(base::TimeTicks monotonic_time,
160 TargetProperty::Type target_property, 174 TargetProperty::Type target_property,
161 double animation_start_time, 175 double animation_start_time,
162 std::unique_ptr<AnimationCurve> curve) override { 176 std::unique_ptr<AnimationCurve> curve) override;
163 } 177
178 bool started() { return started_; }
179
180 bool finished() { return finished_; }
181
182 bool aborted() { return aborted_; }
183
184 bool takeover() { return takeover_; }
185
186 base::TimeTicks start_time() { return start_time_; }
187
188 private:
164 bool started_; 189 bool started_;
165 bool finished_; 190 bool finished_;
191 bool aborted_;
192 bool takeover_;
193 base::TimeTicks start_time_;
166 }; 194 };
167 195
168 class AnimationTimelinesTest : public testing::Test { 196 class AnimationTimelinesTest : public testing::Test {
169 public: 197 public:
170 AnimationTimelinesTest(); 198 AnimationTimelinesTest();
171 ~AnimationTimelinesTest() override; 199 ~AnimationTimelinesTest() override;
172 200
173 protected: 201 protected:
174 void SetUp() override; 202 void SetUp() override;
175 void TearDown() override; 203 void TearDown() override;
176 204
177 void GetImplTimelineAndPlayerByID(); 205 void GetImplTimelineAndPlayerByID();
178 206
207 void CreateTestLayer(bool needs_active_value_observations,
208 bool needs_pending_value_observations);
209 void AttachTimelinePlayerLayer();
210 void CreateImplTimelineAndPlayer();
211
212 void CreateTestMainLayer();
213 void CreateTestImplLayer(LayerTreeType layer_tree_type);
214
215 scoped_refptr<ElementAnimations> element_animations() const;
216 scoped_refptr<ElementAnimations> element_animations_impl() const;
217
179 void ReleaseRefPtrs(); 218 void ReleaseRefPtrs();
180 219
181 void AnimateLayersTransferEvents(base::TimeTicks time, 220 void AnimateLayersTransferEvents(base::TimeTicks time,
182 unsigned expect_events); 221 unsigned expect_events);
183 222
184 AnimationPlayer* GetPlayerForLayerId(int layer_id); 223 AnimationPlayer* GetPlayerForLayerId(int layer_id);
185 AnimationPlayer* GetImplPlayerForLayerId(int layer_id); 224 AnimationPlayer* GetImplPlayerForLayerId(int layer_id);
186 225
187 int NextTestLayerId(); 226 int NextTestLayerId();
188 227
(...skipping 12 matching lines...) Expand all
201 scoped_refptr<AnimationTimeline> timeline_; 240 scoped_refptr<AnimationTimeline> timeline_;
202 scoped_refptr<AnimationPlayer> player_; 241 scoped_refptr<AnimationPlayer> player_;
203 242
204 scoped_refptr<AnimationTimeline> timeline_impl_; 243 scoped_refptr<AnimationTimeline> timeline_impl_;
205 scoped_refptr<AnimationPlayer> player_impl_; 244 scoped_refptr<AnimationPlayer> player_impl_;
206 }; 245 };
207 246
208 } // namespace cc 247 } // namespace cc
209 248
210 #endif // CC_TEST_ANIMATION_TIMELINES_TEST_COMMON_H_ 249 #endif // CC_TEST_ANIMATION_TIMELINES_TEST_COMMON_H_
OLDNEW
« no previous file with comments | « cc/test/animation_test_common.cc ('k') | cc/test/animation_timelines_test_common.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698