1 // Copyright (c) 2012 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 #include "ui/compositor/test/test_layer_animation_delegate.h"
6 
7 #include "base/optional.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/compositor/layer.h"
10 
11 namespace ui {
12 
TestLayerThreadedAnimationDelegate()13 TestLayerThreadedAnimationDelegate::TestLayerThreadedAnimationDelegate() {}
14 
~TestLayerThreadedAnimationDelegate()15 TestLayerThreadedAnimationDelegate::~TestLayerThreadedAnimationDelegate() {}
16 
TestLayerAnimationDelegate()17 TestLayerAnimationDelegate::TestLayerAnimationDelegate()
18     : opacity_(1.0f),
19       visibility_(true),
20       brightness_(0.0f),
21       grayscale_(0.0f),
22       color_(SK_ColorBLACK) {
23   CreateCcLayer();
24 }
25 
TestLayerAnimationDelegate(const LayerAnimationDelegate & other)26 TestLayerAnimationDelegate::TestLayerAnimationDelegate(
27     const LayerAnimationDelegate& other)
28     : bounds_(other.GetBoundsForAnimation()),
29       transform_(other.GetTransformForAnimation()),
30       opacity_(other.GetOpacityForAnimation()),
31       visibility_(other.GetVisibilityForAnimation()),
32       color_(SK_ColorBLACK) {
33   CreateCcLayer();
34 }
35 
36 TestLayerAnimationDelegate::TestLayerAnimationDelegate(
37     const TestLayerAnimationDelegate& other) = default;
38 
~TestLayerAnimationDelegate()39 TestLayerAnimationDelegate::~TestLayerAnimationDelegate() {
40 }
41 
ExpectLastPropertyChangeReasonIsUnset()42 void TestLayerAnimationDelegate::ExpectLastPropertyChangeReasonIsUnset() {
43   EXPECT_FALSE(last_property_change_reason_is_set_);
44 }
45 
ExpectLastPropertyChangeReason(PropertyChangeReason reason)46 void TestLayerAnimationDelegate::ExpectLastPropertyChangeReason(
47     PropertyChangeReason reason) {
48   EXPECT_TRUE(last_property_change_reason_is_set_);
49   EXPECT_EQ(last_property_change_reason_, reason);
50   last_property_change_reason_is_set_ = false;
51 }
52 
SetFrameNumber(base::Optional<int> frame_number)53 void TestLayerAnimationDelegate::SetFrameNumber(
54     base::Optional<int> frame_number) {
55   frame_number_ = frame_number;
56 }
57 
SetBoundsFromAnimation(const gfx::Rect & bounds,PropertyChangeReason reason)58 void TestLayerAnimationDelegate::SetBoundsFromAnimation(
59     const gfx::Rect& bounds,
60     PropertyChangeReason reason) {
61   bounds_ = bounds;
62   last_property_change_reason_ = reason;
63   last_property_change_reason_is_set_ = true;
64 }
65 
SetTransformFromAnimation(const gfx::Transform & transform,PropertyChangeReason reason)66 void TestLayerAnimationDelegate::SetTransformFromAnimation(
67     const gfx::Transform& transform,
68     PropertyChangeReason reason) {
69   transform_ = transform;
70   last_property_change_reason_ = reason;
71   last_property_change_reason_is_set_ = true;
72 }
73 
SetOpacityFromAnimation(float opacity,PropertyChangeReason reason)74 void TestLayerAnimationDelegate::SetOpacityFromAnimation(
75     float opacity,
76     PropertyChangeReason reason) {
77   opacity_ = opacity;
78   last_property_change_reason_ = reason;
79   last_property_change_reason_is_set_ = true;
80 }
81 
SetVisibilityFromAnimation(bool visibility,PropertyChangeReason reason)82 void TestLayerAnimationDelegate::SetVisibilityFromAnimation(
83     bool visibility,
84     PropertyChangeReason reason) {
85   visibility_ = visibility;
86   last_property_change_reason_ = reason;
87   last_property_change_reason_is_set_ = true;
88 }
89 
SetBrightnessFromAnimation(float brightness,PropertyChangeReason reason)90 void TestLayerAnimationDelegate::SetBrightnessFromAnimation(
91     float brightness,
92     PropertyChangeReason reason) {
93   brightness_ = brightness;
94   last_property_change_reason_ = reason;
95   last_property_change_reason_is_set_ = true;
96 }
97 
SetGrayscaleFromAnimation(float grayscale,PropertyChangeReason reason)98 void TestLayerAnimationDelegate::SetGrayscaleFromAnimation(
99     float grayscale,
100     PropertyChangeReason reason) {
101   grayscale_ = grayscale;
102   last_property_change_reason_ = reason;
103   last_property_change_reason_is_set_ = true;
104 }
105 
SetColorFromAnimation(SkColor color,PropertyChangeReason reason)106 void TestLayerAnimationDelegate::SetColorFromAnimation(
107     SkColor color,
108     PropertyChangeReason reason) {
109   color_ = color;
110   last_property_change_reason_ = reason;
111   last_property_change_reason_is_set_ = true;
112 }
113 
SetClipRectFromAnimation(const gfx::Rect & clip_rect,PropertyChangeReason reason)114 void TestLayerAnimationDelegate::SetClipRectFromAnimation(
115     const gfx::Rect& clip_rect,
116     PropertyChangeReason reason) {
117   clip_rect_ = clip_rect;
118   last_property_change_reason_ = reason;
119   last_property_change_reason_is_set_ = true;
120 }
121 
SetRoundedCornersFromAnimation(const gfx::RoundedCornersF & rounded_corners,PropertyChangeReason reason)122 void TestLayerAnimationDelegate::SetRoundedCornersFromAnimation(
123     const gfx::RoundedCornersF& rounded_corners,
124     PropertyChangeReason reason) {
125   rounded_corners_ = rounded_corners;
126   last_property_change_reason_ = reason;
127   last_property_change_reason_is_set_ = true;
128 }
129 
ScheduleDrawForAnimation()130 void TestLayerAnimationDelegate::ScheduleDrawForAnimation() {
131 }
132 
GetBoundsForAnimation() const133 const gfx::Rect& TestLayerAnimationDelegate::GetBoundsForAnimation() const {
134   return bounds_;
135 }
136 
GetTransformForAnimation() const137 gfx::Transform TestLayerAnimationDelegate::GetTransformForAnimation() const {
138   return transform_;
139 }
140 
GetOpacityForAnimation() const141 float TestLayerAnimationDelegate::GetOpacityForAnimation() const {
142   return opacity_;
143 }
144 
GetVisibilityForAnimation() const145 bool TestLayerAnimationDelegate::GetVisibilityForAnimation() const {
146   return visibility_;
147 }
148 
GetBrightnessForAnimation() const149 float TestLayerAnimationDelegate::GetBrightnessForAnimation() const {
150   return brightness_;
151 }
152 
GetGrayscaleForAnimation() const153 float TestLayerAnimationDelegate::GetGrayscaleForAnimation() const {
154   return grayscale_;
155 }
156 
GetColorForAnimation() const157 SkColor TestLayerAnimationDelegate::GetColorForAnimation() const {
158   return color_;
159 }
160 
GetClipRectForAnimation() const161 gfx::Rect TestLayerAnimationDelegate::GetClipRectForAnimation() const {
162   return clip_rect_;
163 }
164 
GetRoundedCornersForAnimation() const165 gfx::RoundedCornersF TestLayerAnimationDelegate::GetRoundedCornersForAnimation()
166     const {
167   return rounded_corners_;
168 }
169 
GetDeviceScaleFactor() const170 float TestLayerAnimationDelegate::GetDeviceScaleFactor() const {
171   return 1.0f;
172 }
173 
174 LayerAnimatorCollection*
GetLayerAnimatorCollection()175 TestLayerAnimationDelegate::GetLayerAnimatorCollection() {
176   return nullptr;
177 }
178 
GetLayer()179 ui::Layer* TestLayerAnimationDelegate::GetLayer() {
180   return nullptr;
181 }
182 
GetCcLayer() const183 cc::Layer* TestLayerAnimationDelegate::GetCcLayer() const {
184   return cc_layer_.get();
185 }
186 
187 LayerThreadedAnimationDelegate*
GetThreadedAnimationDelegate()188 TestLayerAnimationDelegate::GetThreadedAnimationDelegate() {
189   return &threaded_delegate_;
190 }
191 
GetFrameNumber() const192 base::Optional<int> TestLayerAnimationDelegate::GetFrameNumber() const {
193   return frame_number_;
194 }
195 
GetRefreshRate() const196 float TestLayerAnimationDelegate::GetRefreshRate() const {
197   return 60.0;
198 }
199 
200 
CreateCcLayer()201 void TestLayerAnimationDelegate::CreateCcLayer() {
202   cc_layer_ = cc::Layer::Create();
203 }
204 
AddThreadedAnimation(std::unique_ptr<cc::KeyframeModel> keyframe_model)205 void TestLayerThreadedAnimationDelegate::AddThreadedAnimation(
206     std::unique_ptr<cc::KeyframeModel> keyframe_model) {}
207 
RemoveThreadedAnimation(int keyframe_model_id)208 void TestLayerThreadedAnimationDelegate::RemoveThreadedAnimation(
209     int keyframe_model_id) {}
210 
211 }  // namespace ui
212