• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "TransformOperation.h"
30 #include "Vector.h"
31 
32 namespace WebCore {
33 
34 class TimingFunction;
35 
36 class AndroidAnimation : public ThreadSafeRefCounted<AndroidAnimation> {
37 public:
38     AndroidAnimation(AnimatedPropertyID type,
39                      const Animation* animation,
40                      KeyframeValueList* operations,
41                      double beginTime);
42 
43     virtual ~AndroidAnimation();
44     void suggestBeginTime(double time);
45     double elapsedTime(double time);
46     void pickValues(double progress, int* start, int* end);
47     bool checkIterationsAndProgress(double time, float* finalProgress);
48     double applyTimingFunction(float from, float to, double progress,
49                                const TimingFunction* timingFunction);
50     bool evaluate(LayerAndroid* layer, double time);
51     virtual void applyForProgress(LayerAndroid* layer, float progress) = 0;
52     static long instancesCount();
53 
54     // Since this class is shared between WebKit/UI thread, deep copy the name in the setter and
55     // don't share the value of m_name - this way this AndroidAnimation can be safely destroyed on
56     //any thread, since it is deref'd on both
setName(const String & name)57     void setName(const String& name) { m_name = name.threadsafeCopy(); }
isNamed(const String & name)58     bool isNamed(const String& name) { return m_name == name; }
nameCopy()59     String nameCopy() { return m_name.threadsafeCopy(); }
60 
type()61     AnimatedPropertyID type() { return m_type; }
fillsBackwards()62     bool fillsBackwards() { return m_fillsBackwards; }
fillsForwards()63     bool fillsForwards() { return m_fillsForwards; }
uniqueId()64     int uniqueId() { return m_uniqueId; }
65 
66 protected:
67     double m_beginTime;
68     double m_duration;
69     bool m_fillsBackwards;
70     bool m_fillsForwards;
71     int m_iterationCount;
72     int m_direction;
73     RefPtr<TimingFunction> m_timingFunction;
74     String m_name; // Unique to this object, see comments for 'name' functions above
75     AnimatedPropertyID m_type;
76     KeyframeValueList* m_operations;
77     int m_uniqueId;
78     bool m_hasFinished;
79 };
80 
81 class AndroidOpacityAnimation : public AndroidAnimation {
82 public:
83     static PassRefPtr<AndroidOpacityAnimation> create(const Animation* animation,
84                                                       KeyframeValueList* operations,
85                                                       double beginTime);
86     AndroidOpacityAnimation(const Animation* animation,
87                             KeyframeValueList* operations,
88                             double beginTime);
89 
90     virtual void applyForProgress(LayerAndroid* layer, float progress);
91 };
92 
93 class AndroidTransformAnimation : public AndroidAnimation {
94 public:
95     static PassRefPtr<AndroidTransformAnimation> create(
96                                                      const Animation* animation,
97                                                      KeyframeValueList* operations,
98                                                      double beginTime);
99     AndroidTransformAnimation(const Animation* animation,
100                               KeyframeValueList* operations,
101                               double beginTime);
102 
103     virtual void applyForProgress(LayerAndroid* layer, float progress);
104 };
105 
106 } // namespace WebCore
107 
108 
109 #endif // USE(ACCELERATED_COMPOSITING)
110 
111 #endif // AndroidAnimation_h
112