~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebCore/platform/graphics/blackberry/LayerAnimation.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2011, 2012 Research In Motion Limited. All rights reserved.
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
18
 *
 
19
 */
 
20
 
 
21
#ifndef LayerAnimation_h
 
22
#define LayerAnimation_h
 
23
 
 
24
#include "GraphicsLayer.h"
 
25
 
 
26
#include <wtf/PassRefPtr.h>
 
27
#include <wtf/RefCounted.h>
 
28
 
 
29
#define DEBUG_LAYER_ANIMATION 0
 
30
 
 
31
namespace WebCore {
 
32
 
 
33
class Animation;
 
34
class LayerCompositingThread;
 
35
class TransformationMatrix;
 
36
 
 
37
class LayerAnimation : public ThreadSafeRefCounted<LayerAnimation> {
 
38
public:
 
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)
 
42
    {
 
43
        return adoptRef(new LayerAnimation(values, boxSize, animation, name, timeOffset));
 
44
    }
 
45
 
 
46
    PassRefPtr<LayerAnimation> clone(double timeOffset)
 
47
    {
 
48
        LayerAnimation* animation = new LayerAnimation(*this);
 
49
        // The cloned animation should get a different timeOffset if it's paused.
 
50
        animation->m_timeOffset = timeOffset;
 
51
 
 
52
        return adoptRef(animation);
 
53
    }
 
54
 
 
55
    ~LayerAnimation()
 
56
    {
 
57
    }
 
58
 
 
59
    String name() const
 
60
    {
 
61
        if (m_name.isEmpty())
 
62
            return String("");
 
63
        return String(m_name);
 
64
    }
 
65
 
 
66
    void setStartTime(double time) { m_startTime = time; }
 
67
 
 
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; }
 
83
 
 
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);
 
87
 
 
88
private:
 
89
    LayerAnimation(const KeyframeValueList& values, const IntSize& boxSize, const Animation* animation, const String& name, double timeOffset)
 
90
        : m_id(reinterpret_cast<int>(animation))
 
91
        , m_values(values)
 
92
        , m_boxSize(boxSize)
 
93
        , m_timeOffset(timeOffset)
 
94
        , m_startTime(0)
 
95
        , m_timingFunction(0)
 
96
        , m_duration(animation->duration())
 
97
        , m_iterationCount(animation->iterationCount())
 
98
        , m_direction(animation->direction())
 
99
        , m_finished(false)
 
100
    {
 
101
        if (animation->isTimingFunctionSet())
 
102
            m_timingFunction = animation->timingFunction();
 
103
 
 
104
        validateTransformLists();
 
105
        setName(name);
 
106
    }
 
107
 
 
108
    LayerAnimation(const LayerAnimation& other)
 
109
        :  ThreadSafeRefCounted<LayerAnimation>()
 
110
        , m_id(other.m_id)
 
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)
 
120
        , m_finished(false)
 
121
    {
 
122
        setName(other.name());
 
123
    }
 
124
 
 
125
    void validateTransformLists();
 
126
 
 
127
    void setName(const String& name)
 
128
    {
 
129
        unsigned length = name.length();
 
130
        m_name.resize(length);
 
131
        if (length)
 
132
            memcpy(m_name.data(), name.characters(), sizeof(UChar) * length);
 
133
    }
 
134
 
 
135
    int m_id;
 
136
 
 
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;
 
140
    IntSize m_boxSize;
 
141
    Vector<UChar> m_name; // Must not use String member when deriving from ThreadSafeRefCounted
 
142
    double m_timeOffset;
 
143
    double m_startTime;
 
144
    bool m_transformFunctionListValid;
 
145
 
 
146
    RefPtr<TimingFunction> m_timingFunction;
 
147
    double m_duration;
 
148
    int m_iterationCount;
 
149
    Animation::AnimationDirection m_direction;
 
150
    bool m_finished;
 
151
};
 
152
 
 
153
}
 
154
 
 
155
#endif // LayerAnimation_h