1/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef AndroidAnimation_h
18#define AndroidAnimation_h
19
20#if USE(ACCELERATED_COMPOSITING)
21
22#include "FloatPoint.h"
23#include "FloatPoint3D.h"
24#include "GraphicsLayer.h"
25#include "HashMap.h"
26#include "LayerAndroid.h"
27#include "RefPtr.h"
28#include "Timer.h"
29#include "Vector.h"
30
31namespace WebCore {
32
33class TimingFunction;
34
35class AndroidAnimation : public RefCounted<AndroidAnimation> {
36  public:
37    AndroidAnimation(const Animation* animation,
38                     double beginTime);
39    AndroidAnimation(AndroidAnimation* anim);
40
41    virtual ~AndroidAnimation();
42    virtual PassRefPtr<AndroidAnimation> copy() = 0;
43    float currentProgress(double time);
44    bool checkIterationsAndProgress(double time, float* finalProgress);
45    virtual void swapDirection() = 0;
46    virtual bool evaluate(LayerAndroid* layer, double time) = 0;
47    static long instancesCount();
48    void setName(const String& name) { m_name = name; }
49    String name() { return m_name; }
50
51  protected:
52    double m_beginTime;
53    double m_elapsedTime;
54    double m_duration;
55    int m_iterationCount;
56    int m_currentIteration;
57    int m_direction;
58    TimingFunction m_timingFunction;
59    String m_name;
60};
61
62class AndroidOpacityAnimation : public AndroidAnimation {
63  public:
64    static PassRefPtr<AndroidOpacityAnimation> create(float fromValue,
65                                                     float toValue,
66                                                     const Animation* animation,
67                                                     double beginTime);
68    AndroidOpacityAnimation(float fromValue, float toValue,
69                            const Animation* animation,
70                            double beginTime);
71    AndroidOpacityAnimation(AndroidOpacityAnimation* anim);
72    virtual PassRefPtr<AndroidAnimation> copy();
73
74    virtual void swapDirection();
75    virtual bool evaluate(LayerAndroid* layer, double time);
76
77  private:
78    float m_fromValue;
79    float m_toValue;
80};
81
82class AndroidTransformAnimation : public AndroidAnimation {
83  public:
84    static PassRefPtr<AndroidTransformAnimation> create(
85                                                     const Animation* animation,
86                                                     double beginTime);
87    AndroidTransformAnimation(const Animation* animation, double beginTime);
88
89    AndroidTransformAnimation(AndroidTransformAnimation* anim);
90    virtual PassRefPtr<AndroidAnimation> copy();
91
92    void setOriginalPosition(FloatPoint position) { m_position = position; }
93    void setRotation(float fA, float tA);
94    void setTranslation(float fX, float fY, float fZ,
95                        float tX, float tY, float tZ);
96    void setScale(float fX, float fY, float fZ,
97                  float tX, float tY, float tZ);
98    virtual void swapDirection();
99    virtual bool evaluate(LayerAndroid* layer, double time);
100
101  private:
102    bool m_doTranslation;
103    bool m_doScaling;
104    bool m_doRotation;
105    FloatPoint m_position;
106    float m_fromX, m_fromY, m_fromZ;
107    float m_toX, m_toY, m_toZ;
108    float m_fromAngle, m_toAngle;
109    float m_fromScaleX, m_fromScaleY, m_fromScaleZ;
110    float m_toScaleX, m_toScaleY, m_toScaleZ;
111};
112
113} // namespace WebCore
114
115
116#endif // USE(ACCELERATED_COMPOSITING)
117
118#endif // AndroidAnimation_h
119