| OLD | NEW |
| (Empty) |
| 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 #include "config.h" | |
| 28 | |
| 29 #if USE(ACCELERATED_COMPOSITING) | |
| 30 | |
| 31 #include "PlatformClutterAnimation.h" | |
| 32 | |
| 33 #include "FloatConversion.h" | |
| 34 #include "GraphicsLayerActor.h" | |
| 35 #include "Logging.h" | |
| 36 #include "NotImplemented.h" | |
| 37 #include "TimingFunction.h" | |
| 38 #include "UnitBezier.h" | |
| 39 #include <limits.h> | |
| 40 #include <wtf/CurrentTime.h> | |
| 41 #include <wtf/OwnArrayPtr.h> | |
| 42 #include <wtf/UnusedParam.h> | |
| 43 #include <wtf/gobject/GOwnPtr.h> | |
| 44 #include <wtf/text/CString.h> | |
| 45 | |
| 46 using namespace std; | |
| 47 | |
| 48 namespace WebCore { | |
| 49 | |
| 50 static void timelineStartedCallback(ClutterTimeline*, PlatformClutterAnimation*
animation) | |
| 51 { | |
| 52 animation->animationDidStart(); | |
| 53 } | |
| 54 | |
| 55 static String toClutterActorPropertyString(const PlatformClutterAnimation::Value
FunctionType valueFunctionType) | |
| 56 { | |
| 57 // ClutterActor doesn't have 'scale' and 'translate' properties. So we shoul
d support | |
| 58 // 'scale' and 'translate' ValueFunctionType by combination of existing prop
erty animations. | |
| 59 const char* clutterActorProperty[] = { "NoProperty", "rotation-angle-x", "ro
tation-angle-y", "rotation-angle-z", "scale-x", "scale-y", "scale-z", "scale", "
translation-x", "translation-y", "translation-z", "translate", "transform" }; | |
| 60 return clutterActorProperty[valueFunctionType]; | |
| 61 } | |
| 62 | |
| 63 static ClutterAnimationMode toClutterAnimationMode(const TimingFunction* timingF
unction) | |
| 64 { | |
| 65 ASSERT(timingFunction); | |
| 66 | |
| 67 if (timingFunction->isLinearTimingFunction()) | |
| 68 return CLUTTER_LINEAR; | |
| 69 if (timingFunction->isCubicBezierTimingFunction()) { | |
| 70 CubicBezierTimingFunction::TimingFunctionPreset timingFunctionPreset = s
tatic_cast<const CubicBezierTimingFunction*>(timingFunction)->timingFunctionPres
et(); | |
| 71 switch (timingFunctionPreset) { | |
| 72 case CubicBezierTimingFunction::Ease: | |
| 73 return CLUTTER_EASE; | |
| 74 case CubicBezierTimingFunction::EaseIn: | |
| 75 return CLUTTER_EASE_IN; | |
| 76 case CubicBezierTimingFunction::EaseOut: | |
| 77 return CLUTTER_EASE_OUT; | |
| 78 case CubicBezierTimingFunction::EaseInOut: | |
| 79 return CLUTTER_EASE_IN_OUT; | |
| 80 default: | |
| 81 ASSERT_NOT_REACHED(); | |
| 82 } | |
| 83 } | |
| 84 | |
| 85 return CLUTTER_EASE; | |
| 86 } | |
| 87 | |
| 88 static gboolean clutterMatrixProgress(const GValue* fromValue, const GValue* toV
alue, gdouble progress, GValue* returnValue) | |
| 89 { | |
| 90 const CoglMatrix* fromCoglMatrix = static_cast<CoglMatrix*>(g_value_get_boxe
d(fromValue)); | |
| 91 const CoglMatrix* toCoglMatrix = static_cast<CoglMatrix*>(g_value_get_boxed(
toValue)); | |
| 92 | |
| 93 ASSERT(fromCoglMatrix && toCoglMatrix); | |
| 94 | |
| 95 TransformationMatrix fromMatrix(fromCoglMatrix); | |
| 96 TransformationMatrix toMatrix(toCoglMatrix); | |
| 97 toMatrix.blend(fromMatrix, progress); | |
| 98 | |
| 99 CoglMatrix resultCoglMatrix = toMatrix; | |
| 100 g_value_set_boxed(returnValue, &resultCoglMatrix); | |
| 101 | |
| 102 return true; | |
| 103 } | |
| 104 | |
| 105 PlatformClutterAnimation::AnimatedPropertyType PlatformClutterAnimation::stringT
oAnimatedPropertyType(const String& keyPath) const | |
| 106 { | |
| 107 if (keyPath == "transform") | |
| 108 return Transform; | |
| 109 if (keyPath == "opacity") | |
| 110 return Opacity; | |
| 111 if (keyPath == "backgroundColor") | |
| 112 return BackgroundColor; | |
| 113 return NoAnimatedPropertyType; | |
| 114 } | |
| 115 | |
| 116 PassRefPtr<PlatformClutterAnimation> PlatformClutterAnimation::create(AnimationT
ype type, const String& keyPath) | |
| 117 { | |
| 118 return adoptRef(new PlatformClutterAnimation(type, keyPath)); | |
| 119 } | |
| 120 | |
| 121 PassRefPtr<PlatformClutterAnimation> PlatformClutterAnimation::create(PlatformCl
utterAnimation* animation) | |
| 122 { | |
| 123 return adoptRef(new PlatformClutterAnimation(animation)); | |
| 124 } | |
| 125 | |
| 126 PlatformClutterAnimation::PlatformClutterAnimation(AnimationType type, const Str
ing& keyPath) | |
| 127 : m_type(type) | |
| 128 , m_animatedPropertyType(stringToAnimatedPropertyType(keyPath)) | |
| 129 , m_additive(false) | |
| 130 , m_fromValue(0) | |
| 131 , m_toValue(0) | |
| 132 , m_repeatCount(0) | |
| 133 , m_timingFunction(0) | |
| 134 , m_valueFunctionType(NoValueFunction) | |
| 135 { | |
| 136 m_animation = adoptGRef(G_OBJECT(clutter_transition_group_new())); | |
| 137 } | |
| 138 | |
| 139 PlatformClutterAnimation::PlatformClutterAnimation(const PlatformClutterAnimatio
n* animation) | |
| 140 { | |
| 141 notImplemented(); | |
| 142 } | |
| 143 | |
| 144 PlatformClutterAnimation::~PlatformClutterAnimation() | |
| 145 { | |
| 146 m_animation.clear(); | |
| 147 m_layer.clear(); | |
| 148 } | |
| 149 | |
| 150 bool PlatformClutterAnimation::supportsValueFunction() | |
| 151 { | |
| 152 return true; | |
| 153 } | |
| 154 | |
| 155 bool PlatformClutterAnimation::supportsAdditiveValueFunction() | |
| 156 { | |
| 157 // FIXME: Clutter 1.12 doesn't support additive valueFunction type animation
s. | |
| 158 // So, we use matrix animation instead until clutter supports it. | |
| 159 return false; | |
| 160 } | |
| 161 | |
| 162 double PlatformClutterAnimation::beginTime() const | |
| 163 { | |
| 164 notImplemented(); | |
| 165 return 0; | |
| 166 } | |
| 167 | |
| 168 void PlatformClutterAnimation::setBeginTime(double value) | |
| 169 { | |
| 170 notImplemented(); | |
| 171 } | |
| 172 | |
| 173 double PlatformClutterAnimation::duration() const | |
| 174 { | |
| 175 double duration = clutter_timeline_get_duration(CLUTTER_TIMELINE(m_animation
.get())); | |
| 176 return duration / 1000; | |
| 177 } | |
| 178 | |
| 179 void PlatformClutterAnimation::setDuration(double value) | |
| 180 { | |
| 181 // Clutter Animation sets the duration time in milliseconds. | |
| 182 gint duration = value * 1000; | |
| 183 clutter_timeline_set_duration(CLUTTER_TIMELINE(m_animation.get()), duration)
; | |
| 184 } | |
| 185 | |
| 186 float PlatformClutterAnimation::speed() const | |
| 187 { | |
| 188 notImplemented(); | |
| 189 return 0; | |
| 190 } | |
| 191 | |
| 192 void PlatformClutterAnimation::setSpeed(float value) | |
| 193 { | |
| 194 notImplemented(); | |
| 195 } | |
| 196 | |
| 197 double PlatformClutterAnimation::timeOffset() const | |
| 198 { | |
| 199 notImplemented(); | |
| 200 return 0; | |
| 201 } | |
| 202 | |
| 203 void PlatformClutterAnimation::setTimeOffset(double value) | |
| 204 { | |
| 205 notImplemented(); | |
| 206 } | |
| 207 | |
| 208 float PlatformClutterAnimation::repeatCount() const | |
| 209 { | |
| 210 return m_repeatCount; | |
| 211 } | |
| 212 | |
| 213 void PlatformClutterAnimation::setRepeatCount(float value) | |
| 214 { | |
| 215 if (m_repeatCount == value) | |
| 216 return; | |
| 217 | |
| 218 m_repeatCount = value; | |
| 219 clutter_timeline_set_repeat_count(timeline(), static_cast<gint>(value == num
eric_limits<float>::max() ? -1 : value)); | |
| 220 } | |
| 221 | |
| 222 bool PlatformClutterAnimation::autoreverses() const | |
| 223 { | |
| 224 notImplemented(); | |
| 225 return false; | |
| 226 } | |
| 227 | |
| 228 void PlatformClutterAnimation::setAutoreverses(bool value) | |
| 229 { | |
| 230 notImplemented(); | |
| 231 } | |
| 232 | |
| 233 PlatformClutterAnimation::FillModeType PlatformClutterAnimation::fillMode() cons
t | |
| 234 { | |
| 235 notImplemented(); | |
| 236 return PlatformClutterAnimation::NoFillMode; | |
| 237 } | |
| 238 | |
| 239 void PlatformClutterAnimation::setFillMode(FillModeType value) | |
| 240 { | |
| 241 notImplemented(); | |
| 242 } | |
| 243 | |
| 244 void PlatformClutterAnimation::setTimingFunction(const TimingFunction* timingFun
ction, bool reverse) | |
| 245 { | |
| 246 if (!timingFunction) | |
| 247 return; | |
| 248 | |
| 249 m_timingFunction = timingFunction; | |
| 250 } | |
| 251 | |
| 252 void PlatformClutterAnimation::copyTimingFunctionFrom(const PlatformClutterAnima
tion* value) | |
| 253 { | |
| 254 notImplemented(); | |
| 255 } | |
| 256 | |
| 257 bool PlatformClutterAnimation::isRemovedOnCompletion() const | |
| 258 { | |
| 259 notImplemented(); | |
| 260 return false; | |
| 261 } | |
| 262 | |
| 263 void PlatformClutterAnimation::setRemovedOnCompletion(bool value) | |
| 264 { | |
| 265 notImplemented(); | |
| 266 } | |
| 267 | |
| 268 bool PlatformClutterAnimation::isAdditive() const | |
| 269 { | |
| 270 return m_additive; | |
| 271 } | |
| 272 | |
| 273 void PlatformClutterAnimation::setAdditive(bool value) | |
| 274 { | |
| 275 if (m_additive == value) | |
| 276 return; | |
| 277 | |
| 278 m_additive = value; | |
| 279 } | |
| 280 | |
| 281 PlatformClutterAnimation::ValueFunctionType PlatformClutterAnimation::valueFunct
ion() const | |
| 282 { | |
| 283 return m_valueFunctionType; | |
| 284 } | |
| 285 | |
| 286 void PlatformClutterAnimation::setValueFunction(ValueFunctionType value) | |
| 287 { | |
| 288 if (m_valueFunctionType == value) | |
| 289 return; | |
| 290 | |
| 291 m_valueFunctionType = value; | |
| 292 } | |
| 293 | |
| 294 void PlatformClutterAnimation::setFromValue(float value) | |
| 295 { | |
| 296 if (animationType() != Basic || m_fromValue == value) | |
| 297 return; | |
| 298 | |
| 299 m_fromValue = value; | |
| 300 } | |
| 301 | |
| 302 void PlatformClutterAnimation::setFromValue(const WebCore::TransformationMatrix&
value) | |
| 303 { | |
| 304 if (animationType() != Basic || m_fromValueMatrix == value) | |
| 305 return; | |
| 306 | |
| 307 m_fromValueMatrix = value; | |
| 308 } | |
| 309 | |
| 310 void PlatformClutterAnimation::setFromValue(const FloatPoint3D& value) | |
| 311 { | |
| 312 if (animationType() != Basic || m_fromValue3D == value) | |
| 313 return; | |
| 314 | |
| 315 m_fromValue3D = value; | |
| 316 } | |
| 317 | |
| 318 void PlatformClutterAnimation::setFromValue(const WebCore::Color& value) | |
| 319 { | |
| 320 notImplemented(); | |
| 321 } | |
| 322 | |
| 323 void PlatformClutterAnimation::copyFromValueFrom(const PlatformClutterAnimation*
value) | |
| 324 { | |
| 325 notImplemented(); | |
| 326 } | |
| 327 | |
| 328 void PlatformClutterAnimation::setToValue(float value) | |
| 329 { | |
| 330 if (animationType() != Basic || m_toValue == value) | |
| 331 return; | |
| 332 | |
| 333 m_toValue = value; | |
| 334 } | |
| 335 | |
| 336 void PlatformClutterAnimation::setToValue(const WebCore::TransformationMatrix& v
alue) | |
| 337 { | |
| 338 if (animationType() != Basic || m_toValueMatrix == value) | |
| 339 return; | |
| 340 | |
| 341 m_toValueMatrix = value; | |
| 342 } | |
| 343 | |
| 344 void PlatformClutterAnimation::setToValue(const FloatPoint3D& value) | |
| 345 { | |
| 346 if (animationType() != Basic || m_toValue3D == value) | |
| 347 return; | |
| 348 | |
| 349 m_toValue3D = value; | |
| 350 } | |
| 351 | |
| 352 void PlatformClutterAnimation::setToValue(const WebCore::Color& value) | |
| 353 { | |
| 354 notImplemented(); | |
| 355 } | |
| 356 | |
| 357 void PlatformClutterAnimation::copyToValueFrom(const PlatformClutterAnimation* v
alue) | |
| 358 { | |
| 359 notImplemented(); | |
| 360 } | |
| 361 | |
| 362 void PlatformClutterAnimation::setValues(const Vector<float>& value) | |
| 363 { | |
| 364 ASSERT(animationType() == Keyframe); | |
| 365 | |
| 366 m_values = value; | |
| 367 } | |
| 368 | |
| 369 void PlatformClutterAnimation::setValues(const Vector<WebCore::TransformationMat
rix>& value) | |
| 370 { | |
| 371 notImplemented(); | |
| 372 } | |
| 373 | |
| 374 void PlatformClutterAnimation::setValues(const Vector<FloatPoint3D>& value) | |
| 375 { | |
| 376 ASSERT(animationType() == Keyframe); | |
| 377 | |
| 378 m_values3D = value; | |
| 379 } | |
| 380 | |
| 381 void PlatformClutterAnimation::setValues(const Vector<WebCore::Color>& value) | |
| 382 { | |
| 383 notImplemented(); | |
| 384 } | |
| 385 | |
| 386 void PlatformClutterAnimation::copyValuesFrom(const PlatformClutterAnimation* va
lue) | |
| 387 { | |
| 388 notImplemented(); | |
| 389 } | |
| 390 | |
| 391 void PlatformClutterAnimation::setKeyTimes(const Vector<float>& value) | |
| 392 { | |
| 393 ASSERT(animationType() == Keyframe); | |
| 394 | |
| 395 m_keyTimes = value; | |
| 396 } | |
| 397 | |
| 398 void PlatformClutterAnimation::copyKeyTimesFrom(const PlatformClutterAnimation*
value) | |
| 399 { | |
| 400 notImplemented(); | |
| 401 } | |
| 402 | |
| 403 void PlatformClutterAnimation::setTimingFunctions(const Vector<const TimingFunct
ion*>& value, bool reverse) | |
| 404 { | |
| 405 ASSERT(animationType() == Keyframe); | |
| 406 | |
| 407 m_timingFunctions = value; | |
| 408 } | |
| 409 | |
| 410 void PlatformClutterAnimation::copyTimingFunctionsFrom(const PlatformClutterAnim
ation* value) | |
| 411 { | |
| 412 notImplemented(); | |
| 413 } | |
| 414 | |
| 415 void PlatformClutterAnimation::animationDidStart() | |
| 416 { | |
| 417 ASSERT(CLUTTER_IS_ACTOR(m_layer.get())); | |
| 418 | |
| 419 PlatformClutterLayerClient* client = graphicsLayerActorGetClient(GRAPHICS_LA
YER_ACTOR(m_layer.get())); | |
| 420 if (!client) | |
| 421 return; | |
| 422 | |
| 423 client->platformClutterLayerAnimationStarted(WTF::currentTime()); | |
| 424 } | |
| 425 | |
| 426 ClutterTimeline* PlatformClutterAnimation::timeline() const | |
| 427 { | |
| 428 ASSERT(m_animation); | |
| 429 return CLUTTER_TIMELINE(m_animation.get()); | |
| 430 } | |
| 431 | |
| 432 void PlatformClutterAnimation::addClutterTransitionForProperty(const String& pro
perty, const float fromValue, const float toValue) | |
| 433 { | |
| 434 ASSERT(property != "NoProperty"); | |
| 435 | |
| 436 GRefPtr<ClutterTransition> transition = adoptGRef(clutter_property_transitio
n_new(property.utf8().data())); | |
| 437 if (property == "opacity") { | |
| 438 clutter_transition_set_from(transition.get(), G_TYPE_UINT, static_cast<u
nsigned>(fromValue)); | |
| 439 clutter_transition_set_to(transition.get(), G_TYPE_UINT, static_cast<uns
igned>(toValue)); | |
| 440 } else { | |
| 441 clutter_transition_set_from(transition.get(), G_TYPE_FLOAT, fromValue); | |
| 442 clutter_transition_set_to(transition.get(), G_TYPE_FLOAT, toValue); | |
| 443 } | |
| 444 | |
| 445 clutter_timeline_set_progress_mode(timeline(), toClutterAnimationMode(m_timi
ngFunction)); | |
| 446 | |
| 447 clutter_transition_group_add_transition(CLUTTER_TRANSITION_GROUP(m_animation
.get()), transition.get()); | |
| 448 } | |
| 449 | |
| 450 void PlatformClutterAnimation::addClutterTransitionForProperty(const String& pro
perty, const WebCore::TransformationMatrix& fromValue, const WebCore::Transforma
tionMatrix& toValue) | |
| 451 { | |
| 452 ASSERT(property != "NoProperty"); | |
| 453 | |
| 454 const CoglMatrix fromCoglMatrix = fromValue; | |
| 455 const CoglMatrix toCoglMatrix = toValue; | |
| 456 | |
| 457 GRefPtr<ClutterTransition> transition = adoptGRef(clutter_property_transitio
n_new(property.utf8().data())); | |
| 458 clutter_transition_set_from(transition.get(), CLUTTER_TYPE_MATRIX, &fromCogl
Matrix); | |
| 459 clutter_transition_set_to(transition.get(), CLUTTER_TYPE_MATRIX, &toCoglMatr
ix); | |
| 460 | |
| 461 clutter_timeline_set_progress_mode(timeline(), toClutterAnimationMode(m_timi
ngFunction)); | |
| 462 | |
| 463 clutter_transition_group_add_transition(CLUTTER_TRANSITION_GROUP(m_animation
.get()), transition.get()); | |
| 464 | |
| 465 // FIXME: The matrix interpolation api, clutter_matrix_progress of Clutter 1
.12 works unexpectedly. | |
| 466 // So we overwrite it and handle the interpolation of two matrices with Tran
sformationMatrix. | |
| 467 // See https://bugzilla.gnome.org/show_bug.cgi?id=694197 | |
| 468 clutter_interval_register_progress_func(CLUTTER_TYPE_MATRIX, clutterMatrixPr
ogress); | |
| 469 } | |
| 470 | |
| 471 void PlatformClutterAnimation::addClutterTransitionForProperty(const String& pro
perty, const FloatPoint3D& fromValue, const FloatPoint3D& toValue) | |
| 472 { | |
| 473 ASSERT(property != "NoProperty"); | |
| 474 | |
| 475 if (property == "scale") { | |
| 476 addClutterTransitionForProperty(String("scale-x"), fromValue.x(), toValu
e.x()); | |
| 477 addClutterTransitionForProperty(String("scale-y"), fromValue.y(), toValu
e.y()); | |
| 478 return; | |
| 479 } | |
| 480 if (property == "translate") { | |
| 481 addClutterTransitionForProperty(String("translation-x"), fromValue.x(),
toValue.x()); | |
| 482 addClutterTransitionForProperty(String("translation-y"), fromValue.x(),
toValue.y()); | |
| 483 return; | |
| 484 } | |
| 485 | |
| 486 ASSERT_NOT_REACHED(); | |
| 487 } | |
| 488 | |
| 489 void PlatformClutterAnimation::addClutterKeyframeTransitionForProperty(const Str
ing& property, const Vector<float>& values) | |
| 490 { | |
| 491 ASSERT(property != "NoProperty"); | |
| 492 | |
| 493 GType gType = (property == "opacity" ? G_TYPE_UINT : G_TYPE_FLOAT); | |
| 494 | |
| 495 GRefPtr<ClutterTransition> transition = adoptGRef(clutter_keyframe_transitio
n_new(property.utf8().data())); | |
| 496 if (gType == G_TYPE_UINT) { | |
| 497 clutter_transition_set_from(transition.get(), gType, static_cast<unsigne
d>(values.first())); | |
| 498 clutter_transition_set_to(transition.get(), gType, static_cast<unsigned>
(values.last())); | |
| 499 } else { | |
| 500 clutter_transition_set_from(transition.get(), gType, values.first()); | |
| 501 clutter_transition_set_to(transition.get(), gType, values.last()); | |
| 502 } | |
| 503 | |
| 504 // Ignore the first keyframe, since it's a '0' frame, meaningless. | |
| 505 const unsigned nKeyframes = values.size() - 1; | |
| 506 OwnArrayPtr<ClutterAnimationMode> animationModes = adoptArrayPtr(new Clutter
AnimationMode[nKeyframes]); | |
| 507 OwnArrayPtr<double> keyTimes = adoptArrayPtr(new double[nKeyframes]); | |
| 508 GOwnPtr<GValue> keyValues(g_new0(GValue, nKeyframes)); | |
| 509 | |
| 510 for (unsigned i = 0; i < nKeyframes; ++i) { | |
| 511 keyTimes[i] = static_cast<double>(m_keyTimes[i + 1]); | |
| 512 animationModes[i] = toClutterAnimationMode(m_timingFunctions[i]); | |
| 513 g_value_init(&keyValues.get()[i], gType); | |
| 514 if (gType == G_TYPE_UINT) | |
| 515 g_value_set_uint(&keyValues.get()[i], static_cast<unsigned>(values[i
+ 1])); | |
| 516 else | |
| 517 g_value_set_float(&keyValues.get()[i], values[i + 1]); | |
| 518 } | |
| 519 | |
| 520 clutter_keyframe_transition_set_key_frames(CLUTTER_KEYFRAME_TRANSITION(trans
ition.get()), nKeyframes, keyTimes.get()); | |
| 521 clutter_keyframe_transition_set_values(CLUTTER_KEYFRAME_TRANSITION(transitio
n.get()), nKeyframes, keyValues.get()); | |
| 522 clutter_keyframe_transition_set_modes(CLUTTER_KEYFRAME_TRANSITION(transition
.get()), nKeyframes, animationModes.get()); | |
| 523 | |
| 524 clutter_transition_group_add_transition(CLUTTER_TRANSITION_GROUP(m_animation
.get()), transition.get()); | |
| 525 | |
| 526 for (unsigned i = 0; i < nKeyframes; ++i) | |
| 527 g_value_unset(&keyValues.get()[i]); | |
| 528 } | |
| 529 | |
| 530 void PlatformClutterAnimation::addClutterKeyframeTransitionForProperty(const Str
ing& property, const Vector<FloatPoint3D>& values) | |
| 531 { | |
| 532 ASSERT(property != "NoProperty"); | |
| 533 | |
| 534 Vector<float> valuesX, valuesY; | |
| 535 for (unsigned i = 0; i < values.size(); ++i) { | |
| 536 valuesX.append(values[i].x()); | |
| 537 valuesY.append(values[i].y()); | |
| 538 } | |
| 539 | |
| 540 if (property == "scale") { | |
| 541 addClutterKeyframeTransitionForProperty(String("scale-x"), valuesX); | |
| 542 addClutterKeyframeTransitionForProperty(String("scale-y"), valuesY); | |
| 543 return; | |
| 544 } | |
| 545 if (property == "translate") { | |
| 546 addClutterKeyframeTransitionForProperty(String("translation-x"), valuesX
); | |
| 547 addClutterKeyframeTransitionForProperty(String("translation-y"), valuesY
); | |
| 548 return; | |
| 549 } | |
| 550 | |
| 551 ASSERT_NOT_REACHED(); | |
| 552 } | |
| 553 | |
| 554 void PlatformClutterAnimation::addOpacityTransition() | |
| 555 { | |
| 556 if (animationType() == Keyframe) { | |
| 557 for (unsigned i = 0; i < m_values.size(); ++i) | |
| 558 m_values[i] *= 255; | |
| 559 | |
| 560 addClutterKeyframeTransitionForProperty(String("opacity"), m_values); | |
| 561 } else { | |
| 562 m_fromValue *= 255; | |
| 563 m_toValue *= 255; | |
| 564 | |
| 565 addClutterTransitionForProperty(String("opacity"), m_fromValue, m_toValu
e); | |
| 566 } | |
| 567 } | |
| 568 | |
| 569 void PlatformClutterAnimation::addTransformTransition() | |
| 570 { | |
| 571 const bool isKeyframe = (animationType() == Keyframe); | |
| 572 | |
| 573 switch (m_valueFunctionType) { | |
| 574 case RotateX: | |
| 575 case RotateY: | |
| 576 case RotateZ: | |
| 577 if (isKeyframe) { | |
| 578 for (unsigned i = 0; i < m_values.size(); ++i) | |
| 579 m_values[i] = rad2deg(m_values[i]); | |
| 580 | |
| 581 addClutterKeyframeTransitionForProperty(toClutterActorPropertyString
(m_valueFunctionType), m_values); | |
| 582 } else { | |
| 583 m_fromValue = rad2deg(m_fromValue); | |
| 584 m_toValue = rad2deg(m_toValue); | |
| 585 | |
| 586 addClutterTransitionForProperty(toClutterActorPropertyString(m_value
FunctionType), m_fromValue, m_toValue); | |
| 587 } | |
| 588 break; | |
| 589 case ScaleX: | |
| 590 case ScaleY: | |
| 591 case ScaleZ: | |
| 592 case TranslateX: | |
| 593 case TranslateY: | |
| 594 case TranslateZ: | |
| 595 if (isKeyframe) | |
| 596 addClutterKeyframeTransitionForProperty(toClutterActorPropertyString
(m_valueFunctionType), m_values); | |
| 597 else | |
| 598 addClutterTransitionForProperty(toClutterActorPropertyString(m_value
FunctionType), m_fromValue, m_toValue); | |
| 599 break; | |
| 600 case Scale: | |
| 601 case Translate: | |
| 602 if (isKeyframe) | |
| 603 addClutterKeyframeTransitionForProperty(toClutterActorPropertyString
(m_valueFunctionType), m_values3D); | |
| 604 else | |
| 605 addClutterTransitionForProperty(toClutterActorPropertyString(m_value
FunctionType), m_fromValue3D, m_toValue3D); | |
| 606 break; | |
| 607 case Matrix: | |
| 608 addClutterTransitionForProperty(toClutterActorPropertyString(m_valueFunc
tionType), m_fromValueMatrix, m_toValueMatrix); | |
| 609 break; | |
| 610 default: | |
| 611 ASSERT_NOT_REACHED(); | |
| 612 } | |
| 613 | |
| 614 // FIXME: Work-around the fact that if there is a transform already set the
animation fails to start. | |
| 615 // https://bugzilla.gnome.org/show_bug.cgi?id=696804 | |
| 616 clutter_actor_set_transform(m_layer.get(), 0); | |
| 617 } | |
| 618 | |
| 619 void PlatformClutterAnimation::addAnimationForKey(GraphicsLayerActor* platformLa
yer, const String& key) | |
| 620 { | |
| 621 ASSERT(!g_object_get_data(G_OBJECT(platformLayer), key.utf8().data())); | |
| 622 | |
| 623 m_layer = CLUTTER_ACTOR(platformLayer); | |
| 624 | |
| 625 if (m_animatedPropertyType == Opacity) | |
| 626 addOpacityTransition(); | |
| 627 else if (m_animatedPropertyType == Transform) | |
| 628 addTransformTransition(); | |
| 629 else if (m_animatedPropertyType == BackgroundColor) | |
| 630 ASSERT_NOT_REACHED(); | |
| 631 else | |
| 632 ASSERT_NOT_REACHED(); | |
| 633 | |
| 634 g_signal_connect(timeline(), "started", G_CALLBACK(timelineStartedCallback),
this); | |
| 635 g_object_set_data(G_OBJECT(platformLayer), key.utf8().data(), this); | |
| 636 | |
| 637 clutter_actor_add_transition(m_layer.get(), key.utf8().data(), CLUTTER_TRANS
ITION(m_animation.get())); | |
| 638 } | |
| 639 | |
| 640 void PlatformClutterAnimation::removeAnimationForKey(GraphicsLayerActor* layer,
const String& key) | |
| 641 { | |
| 642 clutter_actor_remove_transition(CLUTTER_ACTOR(layer), key.utf8().data()); | |
| 643 g_object_set_data(G_OBJECT(layer), key.utf8().data(), 0); | |
| 644 } | |
| 645 | |
| 646 } // namespace WebCore | |
| 647 | |
| 648 #endif // USE(ACCELERATED_COMPOSITING) | |
| OLD | NEW |