1 // Copyright 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.
5 #ifndef CC_ANIMATION_ANIMATION_CURVE_H_
6 #define CC_ANIMATION_ANIMATION_CURVE_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/time/time.h"
10 #include "cc/base/cc_export.h"
11 #include "cc/output/filter_operations.h"
12 #include "ui/gfx/transform.h"
20 class ColorAnimationCurve
;
21 class FilterAnimationCurve
;
22 class FloatAnimationCurve
;
23 class ScrollOffsetAnimationCurve
;
24 class TransformAnimationCurve
;
25 class TransformOperations
;
27 // An animation curve is a function that returns a value given a time.
28 class CC_EXPORT AnimationCurve
{
30 enum CurveType
{ COLOR
, FLOAT
, TRANSFORM
, FILTER
, SCROLL_OFFSET
};
32 virtual ~AnimationCurve() {}
34 virtual base::TimeDelta
Duration() const = 0;
35 virtual CurveType
Type() const = 0;
36 virtual scoped_ptr
<AnimationCurve
> Clone() const = 0;
38 const ColorAnimationCurve
* ToColorAnimationCurve() const;
39 const FloatAnimationCurve
* ToFloatAnimationCurve() const;
40 const TransformAnimationCurve
* ToTransformAnimationCurve() const;
41 const FilterAnimationCurve
* ToFilterAnimationCurve() const;
42 const ScrollOffsetAnimationCurve
* ToScrollOffsetAnimationCurve() const;
44 ScrollOffsetAnimationCurve
* ToScrollOffsetAnimationCurve();
47 class CC_EXPORT ColorAnimationCurve
: public AnimationCurve
{
49 ~ColorAnimationCurve() override
{}
51 virtual SkColor
GetValue(base::TimeDelta t
) const = 0;
53 // Partial Animation implementation.
54 CurveType
Type() const override
;
57 class CC_EXPORT FloatAnimationCurve
: public AnimationCurve
{
59 ~FloatAnimationCurve() override
{}
61 virtual float GetValue(base::TimeDelta t
) const = 0;
63 // Partial Animation implementation.
64 CurveType
Type() const override
;
67 class CC_EXPORT TransformAnimationCurve
: public AnimationCurve
{
69 ~TransformAnimationCurve() override
{}
71 virtual gfx::Transform
GetValue(base::TimeDelta t
) const = 0;
73 // Sets |bounds| to be the bounding box for the region within which |box|
74 // will move during this animation. If this region cannot be computed,
76 virtual bool AnimatedBoundsForBox(const gfx::BoxF
& box
,
77 gfx::BoxF
* bounds
) const = 0;
79 // Returns true if this animation affects scale.
80 virtual bool AffectsScale() const = 0;
82 // Returns true if this animation is a translation.
83 virtual bool IsTranslation() const = 0;
85 // Returns true if this animation preserves axis alignment.
86 virtual bool PreservesAxisAlignment() const = 0;
88 // Set |max_scale| to the maximum scale along any dimension at the end of
89 // intermediate animation target points (eg keyframe end points). When
90 // |forward_direction| is true, the animation curve assumes it plays from
91 // the first keyframe to the last, otherwise it assumes the opposite. Returns
92 // false if the maximum scale cannot be computed.
93 virtual bool MaximumTargetScale(bool forward_direction
,
94 float* max_scale
) const = 0;
96 // Partial Animation implementation.
97 CurveType
Type() const override
;
100 class CC_EXPORT FilterAnimationCurve
: public AnimationCurve
{
102 ~FilterAnimationCurve() override
{}
104 virtual FilterOperations
GetValue(base::TimeDelta t
) const = 0;
105 virtual bool HasFilterThatMovesPixels() const = 0;
107 // Partial Animation implementation.
108 CurveType
Type() const override
;
113 #endif // CC_ANIMATION_ANIMATION_CURVE_H_