diff options
author | Russell Brenner <russellbrenner@google.com> | 2011-03-08 14:20:31 -0800 |
---|---|---|
committer | Russell Brenner <russellbrenner@google.com> | 2011-03-08 16:43:43 -0800 |
commit | 8d060c05a073fedcf8cd4142926ff5a5e1991de9 (patch) | |
tree | 75568185c4a640e20b8b2b41d56f0cd3a4870ce5 /WebCore | |
parent | 4ffd02f8c673bc6ce1a6b96f9fd3b21e8337ec7c (diff) | |
download | external_webkit-8d060c05a073fedcf8cd4142926ff5a5e1991de9.zip external_webkit-8d060c05a073fedcf8cd4142926ff5a5e1991de9.tar.gz external_webkit-8d060c05a073fedcf8cd4142926ff5a5e1991de9.tar.bz2 |
Fix 2453890: animation via css -webkit-transform
Followed model used for transform animations. Tested with
http://www.webkit.org/blog-files/leaves/.
Fixes http://b/2453890.
Change-Id: Ie71217743b6e1ee9ab0e023fdff44e8c65c8d477
Diffstat (limited to 'WebCore')
3 files changed, 70 insertions, 26 deletions
diff --git a/WebCore/platform/graphics/android/AndroidAnimation.cpp b/WebCore/platform/graphics/android/AndroidAnimation.cpp index e01bf55..47fc82c 100644 --- a/WebCore/platform/graphics/android/AndroidAnimation.cpp +++ b/WebCore/platform/graphics/android/AndroidAnimation.cpp @@ -136,28 +136,25 @@ bool AndroidAnimation::checkIterationsAndProgress(double time, float* finalProgr } PassRefPtr<AndroidOpacityAnimation> AndroidOpacityAnimation::create( - float fromValue, - float toValue, const Animation* animation, + KeyframeValueList* operations, double beginTime) { - return adoptRef(new AndroidOpacityAnimation(fromValue, toValue, - animation, beginTime)); + return adoptRef(new AndroidOpacityAnimation(animation, operations, + beginTime)); } -AndroidOpacityAnimation::AndroidOpacityAnimation(float fromValue, float toValue, - const Animation* animation, +AndroidOpacityAnimation::AndroidOpacityAnimation(const Animation* animation, + KeyframeValueList* operations, double beginTime) : AndroidAnimation(animation, beginTime) - , m_fromValue(fromValue) - , m_toValue(toValue) + , m_operations(operations) { } AndroidOpacityAnimation::AndroidOpacityAnimation(AndroidOpacityAnimation* anim) : AndroidAnimation(anim) - , m_fromValue(anim->m_fromValue) - , m_toValue(anim->m_toValue) + , m_operations(anim->m_operations) { } @@ -175,8 +172,51 @@ bool AndroidOpacityAnimation::evaluate(LayerAndroid* layer, double time) if (progress < 0) // we still want to be evaluated until we get progress > 0 return true; - float value = m_fromValue + ((m_toValue - m_fromValue) * progress); + // First, we need to get the from and to values + + FloatAnimationValue* fromValue = 0; + FloatAnimationValue* toValue = 0; + + float distance = 0; + unsigned int foundAt = 0; + for (unsigned int i = 0; i < m_operations->size(); i++) { + FloatAnimationValue* value = (FloatAnimationValue*) m_operations->at(i); + float opacity = (float) value->value(); + float key = value->keyTime(); + float d = progress - key; + XLOG("[%d] Key %.2f, opacity %.4f", i, key, opacity); + if (!fromValue || (d > 0 && d < distance && i + 1 < m_operations->size())) { + fromValue = value; + distance = d; + foundAt = i; + } + } + + if (foundAt + 1 < m_operations->size()) + toValue = (FloatAnimationValue*) m_operations->at(foundAt + 1); + else + toValue = fromValue; + + XLOG("[layer %d] fromValue %x, key %.2f, toValue %x, key %.2f for progress %.2f", + layer->uniqueId(), + fromValue, fromValue->keyTime(), + toValue, toValue->keyTime(), progress); + + // We now have the correct two values to work with, let's compute the + // progress value + + float delta = toValue->keyTime() - fromValue->keyTime(); + float rprogress = (progress - fromValue->keyTime()) / delta; + XLOG("We picked keys %.2f to %.2f for progress %.2f, real progress %.2f", + fromValue->keyTime(), toValue->keyTime(), progress, rprogress); + progress = rprogress; + + float from = (float) fromValue->value(); + float to = (float) toValue->value(); + float value = from + ((to - from) * progress); + layer->setOpacity(value); + XLOG("AndroidOpacityAnimation::evaluate(%p, %p, %L) value=%.6f", this, layer, time, value); return true; } diff --git a/WebCore/platform/graphics/android/AndroidAnimation.h b/WebCore/platform/graphics/android/AndroidAnimation.h index 3cc1608..ed2789e 100644 --- a/WebCore/platform/graphics/android/AndroidAnimation.h +++ b/WebCore/platform/graphics/android/AndroidAnimation.h @@ -63,12 +63,11 @@ class AndroidAnimation : public RefCounted<AndroidAnimation> { class AndroidOpacityAnimation : public AndroidAnimation { public: - static PassRefPtr<AndroidOpacityAnimation> create(float fromValue, - float toValue, - const Animation* animation, - double beginTime); - AndroidOpacityAnimation(float fromValue, float toValue, - const Animation* animation, + static PassRefPtr<AndroidOpacityAnimation> create(const Animation* animation, + KeyframeValueList* operations, + double beginTime); + AndroidOpacityAnimation(const Animation* animation, + KeyframeValueList* operations, double beginTime); AndroidOpacityAnimation(AndroidOpacityAnimation* anim); virtual PassRefPtr<AndroidAnimation> copy(); @@ -76,8 +75,7 @@ class AndroidOpacityAnimation : public AndroidAnimation { virtual bool evaluate(LayerAndroid* layer, double time); private: - float m_fromValue; - float m_toValue; + KeyframeValueList* m_operations; }; class AndroidTransformAnimation : public AndroidAnimation { diff --git a/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp b/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp index 7963ae0..26bce59 100644 --- a/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp +++ b/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp @@ -734,15 +734,21 @@ bool GraphicsLayerAndroid::createAnimationFromKeyframes(const KeyframeValueList& case AnimatedPropertyInvalid: break; case AnimatedPropertyWebkitTransform: break; case AnimatedPropertyBackgroundColor: break; + case AnimatedPropertyOpacity: { MLOG("ANIMATEDPROPERTYOPACITY"); - const FloatAnimationValue* startVal = - static_cast<const FloatAnimationValue*>(valueList.at(0)); - const FloatAnimationValue* endVal = - static_cast<const FloatAnimationValue*>(valueList.at(1)); - RefPtr<AndroidOpacityAnimation> anim = AndroidOpacityAnimation::create(startVal->value(), - endVal->value(), - animation, + + KeyframeValueList* operationsList = new KeyframeValueList(AnimatedPropertyOpacity); + for (unsigned int i = 0; i < valueList.size(); i++) { + FloatAnimationValue* originalValue = (FloatAnimationValue*)valueList.at(i); + FloatAnimationValue* value = new FloatAnimationValue(originalValue->keyTime(), + originalValue->value(), 0); + // TODO: pass the timing function originalValue->timingFunction()); + operationsList->insert(value); + } + + RefPtr<AndroidOpacityAnimation> anim = AndroidOpacityAnimation::create(animation, + operationsList, beginTime); if (keyframesName.isEmpty()) anim->setName(propertyIdToString(valueList.property())); |