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.
4
5#ifndef CC_ANIMATION_ANIMATION_CURVE_H_
6#define CC_ANIMATION_ANIMATION_CURVE_H_
7
8#include "base/memory/scoped_ptr.h"
9#include "cc/base/cc_export.h"
10#include "cc/output/filter_operations.h"
11#include "ui/gfx/transform.h"
12
13namespace gfx {
14class BoxF;
15}
16
17namespace cc {
18
19class ColorAnimationCurve;
20class FilterAnimationCurve;
21class FloatAnimationCurve;
22class ScrollOffsetAnimationCurve;
23class TransformAnimationCurve;
24class TransformOperations;
25
26// An animation curve is a function that returns a value given a time.
27class CC_EXPORT AnimationCurve {
28 public:
29  enum CurveType { Color, Float, Transform, Filter, ScrollOffset };
30
31  virtual ~AnimationCurve() {}
32
33  virtual double Duration() const = 0;
34  virtual CurveType Type() const = 0;
35  virtual scoped_ptr<AnimationCurve> Clone() const = 0;
36
37  const ColorAnimationCurve* ToColorAnimationCurve() const;
38  const FloatAnimationCurve* ToFloatAnimationCurve() const;
39  const TransformAnimationCurve* ToTransformAnimationCurve() const;
40  const FilterAnimationCurve* ToFilterAnimationCurve() const;
41  const ScrollOffsetAnimationCurve* ToScrollOffsetAnimationCurve() const;
42
43  ScrollOffsetAnimationCurve* ToScrollOffsetAnimationCurve();
44};
45
46class CC_EXPORT ColorAnimationCurve : public AnimationCurve {
47 public:
48  virtual ~ColorAnimationCurve() {}
49
50  virtual SkColor GetValue(double t) const = 0;
51
52  // Partial Animation implementation.
53  virtual CurveType Type() const OVERRIDE;
54};
55
56class CC_EXPORT FloatAnimationCurve : public AnimationCurve {
57 public:
58  virtual ~FloatAnimationCurve() {}
59
60  virtual float GetValue(double t) const = 0;
61
62  // Partial Animation implementation.
63  virtual CurveType Type() const OVERRIDE;
64};
65
66class CC_EXPORT TransformAnimationCurve : public AnimationCurve {
67 public:
68  virtual ~TransformAnimationCurve() {}
69
70  virtual gfx::Transform GetValue(double t) const = 0;
71
72  // Sets |bounds| to be the bounding box for the region within which |box|
73  // will move during this animation. If this region cannot be computed,
74  // returns false.
75  virtual bool AnimatedBoundsForBox(const gfx::BoxF& box,
76                                    gfx::BoxF* bounds) const = 0;
77
78  // Returns true if this animation affects scale.
79  virtual bool AffectsScale() const = 0;
80
81  // Returns true if this animation is a translation.
82  virtual bool IsTranslation() const = 0;
83
84  // Set |max_scale| to the maximum scale along any dimension at the end of
85  // intermediate animation target points (eg keyframe end points). When
86  // |forward_direction| is true, the animation curve assumes it plays from
87  // the first keyframe to the last, otherwise it assumes the opposite. Returns
88  // false if the maximum scale cannot be computed.
89  virtual bool MaximumTargetScale(bool forward_direction,
90                                  float* max_scale) const = 0;
91
92  // Partial Animation implementation.
93  virtual CurveType Type() const OVERRIDE;
94};
95
96class CC_EXPORT FilterAnimationCurve : public AnimationCurve {
97 public:
98  virtual ~FilterAnimationCurve() {}
99
100  virtual FilterOperations GetValue(double t) const = 0;
101  virtual bool HasFilterThatMovesPixels() const = 0;
102
103  // Partial Animation implementation.
104  virtual CurveType Type() const OVERRIDE;
105};
106
107}  // namespace cc
108
109#endif  // CC_ANIMATION_ANIMATION_CURVE_H_
110