scoped_layer_animation_settings.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. #ifndef UI_COMPOSITOR_SCOPED_LAYER_ANIMATION_SETTINGS_H_
  5. #define UI_COMPOSITOR_SCOPED_LAYER_ANIMATION_SETTINGS_H_
  6. #include <set>
  7. #include "base/time/time.h"
  8. #include "ui/compositor/compositor_export.h"
  9. #include "ui/compositor/layer_animation_element.h"
  10. #include "ui/compositor/layer_animator.h"
  11. #include "ui/gfx/animation/tween.h"
  12. namespace ui {
  13. class ImplicitAnimationObserver;
  14. // Scoped settings allow you to temporarily change the animator's settings and
  15. // these changes are reverted when the object is destroyed. NOTE: when the
  16. // settings object is created, it applies the default transition duration
  17. // (200ms).
  18. class COMPOSITOR_EXPORT ScopedLayerAnimationSettings {
  19. public:
  20. explicit ScopedLayerAnimationSettings(scoped_refptr<LayerAnimator> animator);
  21. ScopedLayerAnimationSettings(const ScopedLayerAnimationSettings&) = delete;
  22. ScopedLayerAnimationSettings& operator=(const ScopedLayerAnimationSettings&) =
  23. delete;
  24. virtual ~ScopedLayerAnimationSettings();
  25. void AddObserver(ImplicitAnimationObserver* observer);
  26. void SetTransitionDuration(base::TimeDelta duration);
  27. base::TimeDelta GetTransitionDuration() const;
  28. // Locks transition duration in |animator_|. When transition duration
  29. // is locked any subsequent changes to it are ignored until the
  30. // ScopedLayerAnimationSettings object that has locked the duration goes out
  31. // of scope.
  32. void LockTransitionDuration();
  33. void SetTweenType(gfx::Tween::Type tween_type);
  34. gfx::Tween::Type GetTweenType() const;
  35. void SetPreemptionStrategy(LayerAnimator::PreemptionStrategy strategy);
  36. LayerAnimator::PreemptionStrategy GetPreemptionStrategy() const;
  37. // This will request render surface caching on the animating layer. The cache
  38. // request will be removed at the end of the animation.
  39. void CacheRenderSurface();
  40. // This will defer painting on the animating layer. The deferred paint
  41. // request will be removed at the end of the animation.
  42. void DeferPaint();
  43. // This will request trilinear filtering on the animating layer. The filtering
  44. // request will be removed at the end of the animation.
  45. void TrilinearFiltering();
  46. LayerAnimator* GetAnimator() { return animator_.get(); }
  47. private:
  48. scoped_refptr<LayerAnimator> animator_;
  49. bool old_is_transition_duration_locked_;
  50. base::TimeDelta old_transition_duration_;
  51. gfx::Tween::Type old_tween_type_;
  52. LayerAnimator::PreemptionStrategy old_preemption_strategy_;
  53. std::set<ImplicitAnimationObserver*> observers_;
  54. };
  55. } // namespace ui
  56. #endif // UI_COMPOSITOR_SCOPED_LAYER_ANIMATION_SETTINGS_H_