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

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

Issue 947033002: CC Animations: Establish AnimationHost, AnimationTimeline and AnimationPlayer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix MSVC warning. Created 5 years, 5 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CC_TEST_ANIMATION_TIMELINES_TEST_COMMON_H_
6 #define CC_TEST_ANIMATION_TIMELINES_TEST_COMMON_H_
7
8 #include "base/containers/scoped_ptr_hash_map.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "cc/animation/animation.h"
11 #include "cc/animation/animation_delegate.h"
12 #include "cc/animation/animation_host.h"
13 #include "cc/trees/mutator_host_client.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/gfx/geometry/scroll_offset.h"
16
17 namespace cc {
18
19 class TestLayer {
20 public:
21 static scoped_ptr<TestLayer> Create();
22
23 void ClearMutatedProperties();
24
25 int transform_x() const { return transform_x_; }
26 int transform_y() const { return transform_y_; }
27
28 void set_transform(int transform_x, int transform_y) {
29 transform_x_ = transform_x;
30 transform_y_ = transform_y;
31 mutated_properties_[Animation::TRANSFORM] = true;
32 }
33
34 float opacity() const { return opacity_; }
35 void set_opacity(float opacity) {
36 opacity_ = opacity;
37 mutated_properties_[Animation::OPACITY] = true;
38 }
39
40 float brightness() const { return brightness_; }
41 void set_brightness(float brightness) {
42 brightness_ = brightness;
43 mutated_properties_[Animation::FILTER] = true;
44 }
45
46 gfx::ScrollOffset scroll_offset() const { return scroll_offset_; }
47 void set_scroll_offset(const gfx::ScrollOffset& scroll_offset) {
48 scroll_offset_ = scroll_offset;
49 mutated_properties_[Animation::SCROLL_OFFSET] = true;
50 }
51
52 bool is_property_mutated(Animation::TargetProperty property) const {
53 return mutated_properties_[property];
54 }
55
56 private:
57 TestLayer();
58
59 int transform_x_;
60 int transform_y_;
61
62 float opacity_;
63 float brightness_;
64 gfx::ScrollOffset scroll_offset_;
65
66 bool mutated_properties_[Animation::LAST_TARGET_PROPERTY + 1];
67 };
68
69 class TestHostClient : public MutatorHostClient {
70 public:
71 explicit TestHostClient(ThreadInstance thread_instance);
72 ~TestHostClient();
73
74 void ClearMutatedProperties();
75
76 bool IsLayerInTree(int layer_id, LayerTreeType tree_type) const override;
77
78 void SetMutatorsNeedCommit() override;
79
80 void SetLayerFilterMutated(int layer_id,
81 LayerTreeType tree_type,
82 const FilterOperations& filters) override;
83
84 void SetLayerOpacityMutated(int layer_id,
85 LayerTreeType tree_type,
86 float opacity) override;
87
88 void SetLayerTransformMutated(int layer_id,
89 LayerTreeType tree_type,
90 const gfx::Transform& transform) override;
91
92 void SetLayerScrollOffsetMutated(
93 int layer_id,
94 LayerTreeType tree_type,
95 const gfx::ScrollOffset& scroll_offset) override;
96
97 bool mutators_need_commit() const { return mutators_need_commit_; }
98 void set_mutators_need_commit(bool need) { mutators_need_commit_ = need; }
99
100 void RegisterLayer(int layer_id, LayerTreeType tree_type);
101 void UnregisterLayer(int layer_id, LayerTreeType tree_type);
102
103 AnimationHost* host() {
104 DCHECK(host_);
105 return host_.get();
106 }
107
108 bool IsPropertyMutated(int layer_id,
109 LayerTreeType tree_type,
110 Animation::TargetProperty property) const;
111
112 void ExpectFilterPropertyMutated(int layer_id,
113 LayerTreeType tree_type,
114 float brightness) const;
115 void ExpectOpacityPropertyMutated(int layer_id,
116 LayerTreeType tree_type,
117 float opacity) const;
118 void ExpectTransformPropertyMutated(int layer_id,
119 LayerTreeType tree_type,
120 int transform_x,
121 int transform_y) const;
122 void ExpectScrollOffsetPropertyMutated(
123 int layer_id,
124 LayerTreeType tree_type,
125 const gfx::ScrollOffset& scroll_offset) const;
126
127 TestLayer* FindTestLayer(int layer_id, LayerTreeType tree_type) const;
128
129 private:
130 scoped_ptr<AnimationHost> host_;
131
132 typedef base::ScopedPtrHashMap<int, scoped_ptr<TestLayer>> LayerIdToTestLayer;
133 LayerIdToTestLayer layers_in_active_tree_;
134 LayerIdToTestLayer layers_in_pending_tree_;
135
136 bool mutators_need_commit_;
137 };
138
139 class TestAnimationDelegate : public AnimationDelegate {
140 public:
141 TestAnimationDelegate();
142
143 void NotifyAnimationStarted(base::TimeTicks monotonic_time,
144 Animation::TargetProperty target_property,
145 int group) override;
146 void NotifyAnimationFinished(base::TimeTicks monotonic_time,
147 Animation::TargetProperty target_property,
148 int group) override;
149 bool started_;
150 bool finished_;
151 };
152
153 class AnimationTimelinesTest : public testing::Test {
154 public:
155 AnimationTimelinesTest();
156 ~AnimationTimelinesTest() override;
157
158 protected:
159 void SetUp() override;
160
161 void GetImplTimelineAndPlayerByID();
162
163 void ReleaseRefPtrs();
164
165 void AnimateLayersTransferEvents(base::TimeTicks time,
166 unsigned expect_events);
167
168 AnimationPlayer* GetPlayerForLayerId(int layer_id);
169 AnimationPlayer* GetImplPlayerForLayerId(int layer_id);
170
171 TestHostClient client_;
172 TestHostClient client_impl_;
173
174 AnimationHost* host_;
175 AnimationHost* host_impl_;
176
177 const int timeline_id_;
178 const int player_id_;
179 const int layer_id_;
180
181 scoped_refptr<AnimationTimeline> timeline_;
182 scoped_refptr<AnimationPlayer> player_;
183
184 scoped_refptr<AnimationTimeline> timeline_impl_;
185 scoped_refptr<AnimationPlayer> player_impl_;
186 };
187
188 } // namespace cc
189
190 #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