test_layer_animation_delegate.cc 6.1 KB

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