2
* Copyright (C) 2011, 2012 Research In Motion Limited. All rights reserved.
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Library General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Library General Public License for more details.
14
* You should have received a copy of the GNU Library General Public License
15
* along with this library; see the file COPYING.LIB. If not, write to
16
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
* Boston, MA 02110-1301, USA.
21
#ifndef LayerAnimation_h
22
#define LayerAnimation_h
24
#include "GraphicsLayer.h"
26
#include <wtf/PassRefPtr.h>
27
#include <wtf/RefCounted.h>
29
#define DEBUG_LAYER_ANIMATION 0
34
class LayerCompositingThread;
35
class TransformationMatrix;
37
class LayerAnimation : public ThreadSafeRefCounted<LayerAnimation> {
39
// The setStartTime method is not threadsafe and must only be called on a newly
40
// created LayerAnimation before sending it off to the compositing thread.
41
static PassRefPtr<LayerAnimation> create(const KeyframeValueList& values, const IntSize& boxSize, const Animation* animation, const String& name, double timeOffset)
43
return adoptRef(new LayerAnimation(values, boxSize, animation, name, timeOffset));
46
PassRefPtr<LayerAnimation> clone(double timeOffset)
48
LayerAnimation* animation = new LayerAnimation(*this);
49
// The cloned animation should get a different timeOffset if it's paused.
50
animation->m_timeOffset = timeOffset;
52
return adoptRef(animation);
63
return String(m_name);
66
void setStartTime(double time) { m_startTime = time; }
68
// These functions are thread safe (immutable state).
69
static int idFromAnimation(const Animation* animation) { return reinterpret_cast<int>(animation); }
70
bool isEqualToAnimation(const Animation* animation) const { return idFromAnimation(animation) == id(); }
71
int id() const { return m_id; }
72
AnimatedPropertyID property() const { return m_values.property(); }
73
IntSize boxSize() const { return m_boxSize; }
74
double timeOffset() const { return m_timeOffset; }
75
double startTime() const { return m_startTime; }
76
size_t valueCount() const { return m_values.size(); }
77
const TimingFunction* timingFunction() const { return m_timingFunction.get(); }
78
double duration() const { return m_duration; }
79
int iterationCount() const { return m_iterationCount; }
80
Animation::AnimationDirection direction() const { return m_direction; }
81
const AnimationValue* valueAt(size_t i) const { return m_values.at(i); }
82
bool finished() const { return m_finished; }
84
TransformationMatrix blendTransform(const TransformOperations* from, const TransformOperations*, double progress) const;
85
float blendOpacity(float from, float to, double progress) const;
86
void apply(LayerCompositingThread*, double elapsedTime);
89
LayerAnimation(const KeyframeValueList& values, const IntSize& boxSize, const Animation* animation, const String& name, double timeOffset)
90
: m_id(reinterpret_cast<int>(animation))
93
, m_timeOffset(timeOffset)
96
, m_duration(animation->duration())
97
, m_iterationCount(animation->iterationCount())
98
, m_direction(animation->direction())
101
if (animation->isTimingFunctionSet())
102
m_timingFunction = animation->timingFunction();
104
validateTransformLists();
108
LayerAnimation(const LayerAnimation& other)
109
: ThreadSafeRefCounted<LayerAnimation>()
111
, m_values(other.m_values)
112
, m_boxSize(other.m_boxSize)
113
, m_timeOffset(other.m_timeOffset)
114
, m_startTime(other.m_startTime)
115
, m_transformFunctionListValid(other.m_transformFunctionListValid)
116
, m_timingFunction(other.m_timingFunction)
117
, m_duration(other.m_duration)
118
, m_iterationCount(other.m_iterationCount)
119
, m_direction(other.m_direction)
122
setName(other.name());
125
void validateTransformLists();
127
void setName(const String& name)
129
unsigned length = name.length();
130
m_name.resize(length);
132
memcpy(m_name.data(), name.characters(), sizeof(UChar) * length);
137
// NOTE: Don't expose the KeyframeValueList directly, since its copy
138
// constructor mutates refcounts and thus is not thread safe.
139
KeyframeValueList m_values;
141
Vector<UChar> m_name; // Must not use String member when deriving from ThreadSafeRefCounted
144
bool m_transformFunctionListValid;
146
RefPtr<TimingFunction> m_timingFunction;
148
int m_iterationCount;
149
Animation::AnimationDirection m_direction;
155
#endif // LayerAnimation_h