1/* 2 * Copyright (C) 2010 Apple Inc. All rights reserved. 3 * Copyright (C) 2013 Collabora Ltd. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#ifndef PlatformClutterAnimation_h 28#define PlatformClutterAnimation_h 29 30#if USE(ACCELERATED_COMPOSITING) 31 32#include "Color.h" 33#include "FilterOperation.h" 34#include "FloatPoint3D.h" 35#include "TransformationMatrix.h" 36#include <glib-object.h> 37#include <glib.h> 38#include <wtf/RefCounted.h> 39#include <wtf/RetainPtr.h> 40#include <wtf/Vector.h> 41#include <wtf/gobject/GRefPtr.h> 42 43typedef struct _ClutterActor ClutterActor; 44typedef struct _ClutterTimeline ClutterTimeline; 45typedef struct _GraphicsLayerActor GraphicsLayerActor; 46 47namespace WebCore { 48 49class FloatRect; 50class PlatformClutterAnimation; 51class TimingFunction; 52 53class PlatformClutterAnimation : public RefCounted<PlatformClutterAnimation> { 54public: 55 enum AnimationType { Basic, Keyframe }; 56 enum AnimatedPropertyType { NoAnimatedPropertyType, Transform, Opacity, BackgroundColor }; 57 enum FillModeType { NoFillMode, Forwards, Backwards, Both }; 58 enum ValueFunctionType { NoValueFunction, RotateX, RotateY, RotateZ, ScaleX, ScaleY, ScaleZ, Scale, TranslateX, TranslateY, TranslateZ, Translate, Matrix }; 59 60 static PassRefPtr<PlatformClutterAnimation> create(AnimationType, const String& keyPath); 61 static PassRefPtr<PlatformClutterAnimation> create(PlatformClutterAnimation*); 62 63 ~PlatformClutterAnimation(); 64 65 static bool supportsValueFunction(); 66 static bool supportsAdditiveValueFunction(); 67 68 AnimationType animationType() const { return m_type; } 69 70 double beginTime() const; 71 void setBeginTime(double); 72 73 double duration() const; 74 void setDuration(double); 75 76 float speed() const; 77 void setSpeed(float); 78 79 double timeOffset() const; 80 void setTimeOffset(double); 81 82 float repeatCount() const; 83 void setRepeatCount(float); 84 85 bool autoreverses() const; 86 void setAutoreverses(bool); 87 88 FillModeType fillMode() const; 89 void setFillMode(FillModeType); 90 91 void setTimingFunction(const TimingFunction*, bool reverse = false); 92 void copyTimingFunctionFrom(const PlatformClutterAnimation*); 93 94 bool isRemovedOnCompletion() const; 95 void setRemovedOnCompletion(bool); 96 97 bool isAdditive() const; 98 void setAdditive(bool); 99 100 ValueFunctionType valueFunction() const; 101 void setValueFunction(ValueFunctionType); 102 103 // Basic-animation properties. 104 void setFromValue(float); 105 void setFromValue(const WebCore::TransformationMatrix&); 106 void setFromValue(const FloatPoint3D&); 107 void setFromValue(const WebCore::Color&); 108 void copyFromValueFrom(const PlatformClutterAnimation*); 109 110 void setToValue(float); 111 void setToValue(const WebCore::TransformationMatrix&); 112 void setToValue(const FloatPoint3D&); 113 void setToValue(const WebCore::Color&); 114 void copyToValueFrom(const PlatformClutterAnimation*); 115 116 // Keyframe-animation properties. 117 void setValues(const Vector<float>&); 118 void setValues(const Vector<WebCore::TransformationMatrix>&); 119 void setValues(const Vector<FloatPoint3D>&); 120 void setValues(const Vector<WebCore::Color>&); 121 void copyValuesFrom(const PlatformClutterAnimation*); 122 123 void setKeyTimes(const Vector<float>&); 124 void copyKeyTimesFrom(const PlatformClutterAnimation*); 125 126 void setTimingFunctions(const Vector<const TimingFunction*>&, bool reverse = false); 127 void copyTimingFunctionsFrom(const PlatformClutterAnimation*); 128 129 void addAnimationForKey(GraphicsLayerActor*, const String&); 130 void removeAnimationForKey(GraphicsLayerActor*, const String&); 131 132 void animationDidStart(); 133 134protected: 135 PlatformClutterAnimation(AnimationType, const String& keyPath); 136 PlatformClutterAnimation(const PlatformClutterAnimation*); 137 138private: 139 ClutterTimeline* timeline() const; 140 AnimatedPropertyType stringToAnimatedPropertyType(const String& keyPath) const; 141 142 void addClutterTransitionForProperty(const String& property, const float fromValue, const float toValue); 143 void addClutterTransitionForProperty(const String& property, const WebCore::TransformationMatrix&, const WebCore::TransformationMatrix&); 144 void addClutterTransitionForProperty(const String& property, const FloatPoint3D& fromValue, const FloatPoint3D& toValue); 145 146 void addClutterKeyframeTransitionForProperty(const String& property, const Vector<float>& values); 147 void addClutterKeyframeTransitionForProperty(const String& property, const Vector<WebCore::TransformationMatrix>& values); 148 void addClutterKeyframeTransitionForProperty(const String& property, const Vector<FloatPoint3D>& values); 149 150 void addOpacityTransition(); 151 void addTransformTransition(); 152 153 AnimationType m_type; 154 AnimatedPropertyType m_animatedPropertyType; 155 156 GRefPtr<GObject> m_animation; 157 GRefPtr<ClutterActor> m_layer; 158 159 bool m_additive; 160 161 float m_fromValue; 162 float m_toValue; 163 164 FloatPoint3D m_fromValue3D; 165 FloatPoint3D m_toValue3D; 166 167 WebCore::TransformationMatrix m_fromValueMatrix; 168 WebCore::TransformationMatrix m_toValueMatrix; 169 170 float m_repeatCount; 171 172 const TimingFunction* m_timingFunction; 173 ValueFunctionType m_valueFunctionType; 174 175 Vector<float> m_keyTimes; 176 Vector<const TimingFunction*> m_timingFunctions; 177 178 Vector<float> m_values; 179 Vector<FloatPoint3D> m_values3D; 180 Vector<WebCore::TransformationMatrix> m_valuesMatrix; 181}; 182 183} 184 185#endif // USE(ACCELERATED_COMPOSITING) 186 187#endif // PlatformClutterAnimation_h 188