Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperAnimation.cpp (194444 => 194445)
--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperAnimation.cpp 2015-12-30 08:33:32 UTC (rev 194444)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperAnimation.cpp 2015-12-30 09:47:21 UTC (rev 194445)
@@ -26,16 +26,13 @@
namespace WebCore {
-static inline PassRefPtr<FilterOperation> blendFunc(FilterOperation* fromOp, FilterOperation* toOp, double progress, const FloatSize& size, bool blendToPassthrough = false)
+static RefPtr<FilterOperation> blendFunc(FilterOperation* fromOp, FilterOperation& toOp, double progress, const FloatSize& size, bool blendToPassthrough = false)
{
- ASSERT(toOp);
- if (toOp->blendingNeedsRendererSize())
- return toOp->blend(fromOp, progress, LayoutSize(size), blendToPassthrough);
-
- return toOp->blend(fromOp, progress, blendToPassthrough);
+ if (toOp.blendingNeedsRendererSize())
+ return toOp.blend(fromOp, progress, LayoutSize(size), blendToPassthrough);
+ return toOp.blend(fromOp, progress, blendToPassthrough);
}
-
static FilterOperations applyFilterAnimation(const FilterOperations& from, const FilterOperations& to, double progress, const FloatSize& boxSize)
{
// First frame of an animation.
@@ -55,9 +52,9 @@
size_t toSize = to.operations().size();
size_t size = std::max(fromSize, toSize);
for (size_t i = 0; i < size; i++) {
- RefPtr<FilterOperation> fromOp = (i < fromSize) ? from.operations()[i].get() : 0;
- RefPtr<FilterOperation> toOp = (i < toSize) ? to.operations()[i].get() : 0;
- RefPtr<FilterOperation> blendedOp = toOp ? blendFunc(fromOp.get(), toOp.get(), progress, boxSize) : (fromOp ? blendFunc(0, fromOp.get(), progress, boxSize, true) : 0);
+ RefPtr<FilterOperation> fromOp = (i < fromSize) ? from.operations()[i].get() : nullptr;
+ RefPtr<FilterOperation> toOp = (i < toSize) ? to.operations()[i].get() : nullptr;
+ RefPtr<FilterOperation> blendedOp = toOp ? blendFunc(fromOp.get(), *toOp, progress, boxSize) : (fromOp ? blendFunc(nullptr, *fromOp, progress, boxSize, true) : nullptr);
if (blendedOp)
result.operations().append(blendedOp);
else {
@@ -74,11 +71,9 @@
static bool shouldReverseAnimationValue(Animation::AnimationDirection direction, int loopCount)
{
- if (((direction == Animation::AnimationDirectionAlternate) && (loopCount & 1))
- || ((direction == Animation::AnimationDirectionAlternateReverse) && !(loopCount & 1))
- || direction == Animation::AnimationDirectionReverse)
- return true;
- return false;
+ return (direction == Animation::AnimationDirectionAlternate && loopCount & 1)
+ || (direction == Animation::AnimationDirectionAlternateReverse && !(loopCount & 1))
+ || direction == Animation::AnimationDirectionReverse;
}
static double normalizedAnimationValue(double runningTime, double duration, Animation::AnimationDirection direction, double iterationCount)
@@ -179,16 +174,16 @@
// Animation to "-webkit-transform: none".
if (!to.size()) {
TransformOperations blended(from);
- for (size_t i = 0; i < blended.operations().size(); ++i)
- blended.operations()[i]->blend(0, progress, true)->apply(matrix, boxSize);
+ for (auto& operation : blended.operations())
+ operation->blend(nullptr, progress, true)->apply(matrix, boxSize);
return matrix;
}
// Animation from "-webkit-transform: none".
if (!from.size()) {
TransformOperations blended(to);
- for (size_t i = 0; i < blended.operations().size(); ++i)
- blended.operations()[i]->blend(0, 1. - progress, true)->apply(matrix, boxSize);
+ for (auto& operation : blended.operations())
+ operation->blend(nullptr, 1 - progress, true)->apply(matrix, boxSize);
return matrix;
}
@@ -209,80 +204,36 @@
return CubicBezierTimingFunction::defaultTimingFunction();
}
-TextureMapperAnimation::TextureMapperAnimation(const String& name, const KeyframeValueList& keyframes, const FloatSize& boxSize, const Animation* animation, double startTime, bool listsMatch)
- : m_keyframes(keyframes)
+TextureMapperAnimation::TextureMapperAnimation(const String& name, const KeyframeValueList& keyframes, const FloatSize& boxSize, const Animation& animation, bool listsMatch, double startTime, double pauseTime, AnimationState state)
+ : m_name(name.isSafeToSendToAnotherThread() ? name : name.isolatedCopy())
+ , m_keyframes(keyframes)
, m_boxSize(boxSize)
- , m_animation(Animation::create(*animation))
- , m_name(name.isSafeToSendToAnotherThread() ? name : name.isolatedCopy())
+ , m_animation(Animation::create(animation))
, m_listsMatch(listsMatch)
, m_startTime(startTime)
- , m_pauseTime(0)
+ , m_pauseTime(pauseTime)
, m_totalRunningTime(0)
, m_lastRefreshedTime(m_startTime)
- , m_state(PlayingState)
+ , m_state(state)
{
}
TextureMapperAnimation::TextureMapperAnimation(const TextureMapperAnimation& other)
- : m_keyframes(other.keyframes())
- , m_boxSize(other.boxSize())
- , m_animation(Animation::create(*other.animation()))
- , m_name(other.name().isSafeToSendToAnotherThread() ? other.name() : other.name().isolatedCopy())
- , m_listsMatch(other.listsMatch())
- , m_startTime(other.startTime())
- , m_pauseTime(other.pauseTime())
+ : m_name(other.m_name.isSafeToSendToAnotherThread() ? other.m_name : other.m_name.isolatedCopy())
+ , m_keyframes(other.m_keyframes)
+ , m_boxSize(other.m_boxSize)
+ , m_animation(Animation::create(*other.m_animation))
+ , m_listsMatch(other.m_listsMatch)
+ , m_startTime(other.m_startTime)
+ , m_pauseTime(other.m_pauseTime)
, m_totalRunningTime(other.m_totalRunningTime)
, m_lastRefreshedTime(other.m_lastRefreshedTime)
- , m_state(other.state())
+ , m_state(other.m_state)
{
}
-void TextureMapperAnimation::applyInternal(Client* client, const AnimationValue& from, const AnimationValue& to, float progress)
+void TextureMapperAnimation::apply(Client& client)
{
- switch (m_keyframes.property()) {
- case AnimatedPropertyOpacity:
- client->setAnimatedOpacity(applyOpacityAnimation((static_cast<const FloatAnimationValue&>(from).value()), (static_cast<const FloatAnimationValue&>(to).value()), progress));
- return;
- case AnimatedPropertyTransform:
- client->setAnimatedTransform(applyTransformAnimation(static_cast<const TransformAnimationValue&>(from).value(), static_cast<const TransformAnimationValue&>(to).value(), progress, m_boxSize, m_listsMatch));
- return;
- case AnimatedPropertyFilter:
- client->setAnimatedFilters(applyFilterAnimation(static_cast<const FilterAnimationValue&>(from).value(), static_cast<const FilterAnimationValue&>(to).value(), progress, m_boxSize));
- return;
- default:
- ASSERT_NOT_REACHED();
- }
-}
-
-bool TextureMapperAnimation::isActive() const
-{
- if (state() != StoppedState)
- return true;
-
- return m_animation->fillsForwards();
-}
-
-bool TextureMapperAnimations::hasActiveAnimationsOfType(AnimatedPropertyID type) const
-{
- for (size_t i = 0; i < m_animations.size(); ++i) {
- if (m_animations[i].isActive() && m_animations[i].property() == type)
- return true;
- }
- return false;
-}
-
-bool TextureMapperAnimations::hasRunningAnimations() const
-{
- for (size_t i = 0; i < m_animations.size(); ++i) {
- if (m_animations[i].state() == TextureMapperAnimation::PlayingState)
- return true;
- }
-
- return false;
-}
-
-void TextureMapperAnimation::apply(Client* client)
-{
if (!isActive())
return;
@@ -290,7 +241,8 @@
double normalizedValue = normalizedAnimationValue(totalRunningTime, m_animation->duration(), m_animation->direction(), m_animation->iterationCount());
if (m_animation->iterationCount() != Animation::IterationCountInfinite && totalRunningTime >= m_animation->duration() * m_animation->iterationCount()) {
- setState(StoppedState);
+ m_state = AnimationState::Stopped;
+ m_pauseTime = 0;
if (m_animation->fillsForwards())
normalizedValue = normalizedAnimationValueForFillsForwards(m_animation->iterationCount(), m_animation->direction());
}
@@ -325,9 +277,23 @@
}
}
+void TextureMapperAnimation::pause(double time)
+{
+ m_state = AnimationState::Paused;
+ m_pauseTime = time;
+}
+
+void TextureMapperAnimation::resume()
+{
+ m_state = AnimationState::Playing;
+ m_pauseTime = 0;
+ m_totalRunningTime = m_pauseTime;
+ m_lastRefreshedTime = monotonicallyIncreasingTime();
+}
+
double TextureMapperAnimation::computeTotalRunningTime()
{
- if (state() == PausedState)
+ if (m_state == AnimationState::Paused)
return m_pauseTime;
double oldLastRefreshedTime = m_lastRefreshedTime;
@@ -336,74 +302,96 @@
return m_totalRunningTime;
}
-void TextureMapperAnimation::pause(double time)
+bool TextureMapperAnimation::isActive() const
{
- setState(PausedState);
- m_pauseTime = time;
+ return m_state != AnimationState::Stopped || m_animation->fillsForwards();
}
-void TextureMapperAnimation::resume()
+void TextureMapperAnimation::applyInternal(Client& client, const AnimationValue& from, const AnimationValue& to, float progress)
{
- setState(PlayingState);
- m_totalRunningTime = m_pauseTime;
- m_lastRefreshedTime = monotonicallyIncreasingTime();
+ switch (m_keyframes.property()) {
+ case AnimatedPropertyOpacity:
+ client.setAnimatedOpacity(applyOpacityAnimation((static_cast<const FloatAnimationValue&>(from).value()), (static_cast<const FloatAnimationValue&>(to).value()), progress));
+ return;
+ case AnimatedPropertyTransform:
+ client.setAnimatedTransform(applyTransformAnimation(static_cast<const TransformAnimationValue&>(from).value(), static_cast<const TransformAnimationValue&>(to).value(), progress, m_boxSize, m_listsMatch));
+ return;
+ case AnimatedPropertyFilter:
+ client.setAnimatedFilters(applyFilterAnimation(static_cast<const FilterAnimationValue&>(from).value(), static_cast<const FilterAnimationValue&>(to).value(), progress, m_boxSize));
+ return;
+ default:
+ ASSERT_NOT_REACHED();
+ }
}
void TextureMapperAnimations::add(const TextureMapperAnimation& animation)
{
// Remove the old state if we are resuming a paused animation.
- remove(animation.name(), animation.property());
+ remove(animation.name(), animation.keyframes().property());
m_animations.append(animation);
}
+void TextureMapperAnimations::remove(const String& name)
+{
+ m_animations.removeAllMatching([&name] (const TextureMapperAnimation& animation) {
+ return animation.name() == name;
+ });
+}
+
+void TextureMapperAnimations::remove(const String& name, AnimatedPropertyID property)
+{
+ m_animations.removeAllMatching([&name, property] (const TextureMapperAnimation& animation) {
+ return animation.name() == name && animation.keyframes().property() == property;
+ });
+}
+
void TextureMapperAnimations::pause(const String& name, double offset)
{
- for (size_t i = 0; i < m_animations.size(); ++i) {
- if (m_animations[i].name() == name)
- m_animations[i].pause(offset);
+ for (auto& animation : m_animations) {
+ if (animation.name() == name)
+ animation.pause(offset);
}
}
void TextureMapperAnimations::suspend(double offset)
{
- for (size_t i = 0; i < m_animations.size(); ++i)
- m_animations[i].pause(offset);
+ for (auto& animation : m_animations)
+ animation.pause(offset);
}
void TextureMapperAnimations::resume()
{
- for (size_t i = 0; i < m_animations.size(); ++i)
- m_animations[i].resume();
+ for (auto& animation : m_animations)
+ animation.resume();
}
-void TextureMapperAnimations::remove(const String& name)
+void TextureMapperAnimations::apply(TextureMapperAnimation::Client& client)
{
- m_animations.removeAllMatching([&name] (const TextureMapperAnimation& animation) {
- return animation.name() == name;
- });
+ for (auto& animation : m_animations)
+ animation.apply(client);
}
-void TextureMapperAnimations::remove(const String& name, AnimatedPropertyID property)
+bool TextureMapperAnimations::hasActiveAnimationsOfType(AnimatedPropertyID type) const
{
- m_animations.removeAllMatching([&name, property] (const TextureMapperAnimation& animation) {
- return animation.name() == name && animation.property() == property;
- });
+ return std::any_of(m_animations.begin(), m_animations.end(),
+ [&type](const TextureMapperAnimation& animation) { return animation.isActive() && animation.keyframes().property() == type; });
}
-void TextureMapperAnimations::apply(TextureMapperAnimation::Client* client)
+bool TextureMapperAnimations::hasRunningAnimations() const
{
- for (size_t i = 0; i < m_animations.size(); ++i)
- m_animations[i].apply(client);
+ return std::any_of(m_animations.begin(), m_animations.end(),
+ [](const TextureMapperAnimation& animation) { return animation.state() == TextureMapperAnimation::AnimationState::Playing; });
}
TextureMapperAnimations TextureMapperAnimations::getActiveAnimations() const
{
TextureMapperAnimations active;
- for (size_t i = 0; i < m_animations.size(); ++i) {
- if (m_animations[i].isActive())
- active.add(m_animations[i]);
+ for (auto& animation : m_animations) {
+ if (animation.isActive())
+ active.add(animation);
}
return active;
}
-}
+
+} // namespace WebCore
Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperAnimation.h (194444 => 194445)
--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperAnimation.h 2015-12-30 08:33:32 UTC (rev 194444)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperAnimation.h 2015-12-30 09:47:21 UTC (rev 194445)
@@ -21,15 +21,15 @@
#define TextureMapperAnimation_h
#include "GraphicsLayer.h"
-#include "TransformationMatrix.h"
-#include <wtf/HashMap.h>
-#include <wtf/text/StringHash.h>
namespace WebCore {
+class TransformationMatrix;
+
class TextureMapperAnimation {
public:
- enum AnimationState { PlayingState, PausedState, StoppedState };
+ enum class AnimationState { Playing, Paused, Stopped };
+
class Client {
public:
virtual void setAnimatedTransform(const TransformationMatrix&) = 0;
@@ -40,34 +40,31 @@
TextureMapperAnimation()
: m_keyframes(AnimatedPropertyInvalid)
{ }
- TextureMapperAnimation(const String&, const KeyframeValueList&, const FloatSize&, const Animation*, double, bool);
+ TextureMapperAnimation(const String&, const KeyframeValueList&, const FloatSize&, const Animation&, bool, double, double, AnimationState);
TextureMapperAnimation(const TextureMapperAnimation&);
- void apply(Client*);
+
+ void apply(Client&);
void pause(double);
void resume();
- double computeTotalRunningTime();
- AnimationState state() const { return m_state; }
- void setState(AnimationState s, double pauseTime = 0)
- {
- m_state = s;
- m_pauseTime = pauseTime;
- }
- AnimatedPropertyID property() const { return m_keyframes.property(); }
bool isActive() const;
- String name() const { return m_name; }
- FloatSize boxSize() const { return m_boxSize; }
- double startTime() const { return m_startTime; }
- double pauseTime() const { return m_pauseTime; }
- PassRefPtr<Animation> animation() const { return m_animation.get(); }
+
+ const String& name() const { return m_name; }
const KeyframeValueList& keyframes() const { return m_keyframes; }
+ const FloatSize& boxSize() const { return m_boxSize; }
+ const RefPtr<Animation> animation() const { return m_animation; }
bool listsMatch() const { return m_listsMatch; }
+ double startTime() const { return m_startTime; }
+ double pauseTime() const { return m_pauseTime; }
+ AnimationState state() const { return m_state; }
private:
- void applyInternal(Client*, const AnimationValue& from, const AnimationValue& to, float progress);
+ void applyInternal(Client&, const AnimationValue& from, const AnimationValue& to, float progress);
+ double computeTotalRunningTime();
+
+ String m_name;
KeyframeValueList m_keyframes;
FloatSize m_boxSize;
RefPtr<Animation> m_animation;
- String m_name;
bool m_listsMatch;
double m_startTime;
double m_pauseTime;
@@ -78,7 +75,7 @@
class TextureMapperAnimations {
public:
- TextureMapperAnimations() { }
+ TextureMapperAnimations() = default;
void add(const TextureMapperAnimation&);
void remove(const String& name);
@@ -86,7 +83,9 @@
void pause(const String&, double);
void suspend(double);
void resume();
- void apply(TextureMapperAnimation::Client*);
+
+ void apply(TextureMapperAnimation::Client&);
+
bool isEmpty() const { return m_animations.isEmpty(); }
size_t size() const { return m_animations.size(); }
const Vector<TextureMapperAnimation>& animations() const { return m_animations; }
@@ -94,7 +93,6 @@
bool hasRunningAnimations() const;
bool hasActiveAnimationsOfType(AnimatedPropertyID type) const;
-
TextureMapperAnimations getActiveAnimations() const;
private: