Changeset 105858 in webkit


Ignore:
Timestamp:
Jan 25, 2012 3:09:45 AM (12 years ago)
Author:
noam.rosenthal@nokia.com
Message:

[Texmap] Divide TextureMapperNode.cpp to 3 files.
https://bugs.webkit.org/show_bug.cgi?id=76660

Reviewed by Kenneth Rohde Christiansen.

Split the animation part of TextureMapperNode out to a separate file, called
TextureMapperAnimation.
Provide a clean interface for that class, that allows separating the internals of the scene
painting from the internals of the animation interpolation.

No new tests. Existing animation tests cover this.

  • GNUmakefile.list.am: Added new TextureMapper-related files.
  • Target.pri: Added new TextureMapper-related files.
  • WebCore.gypi: Added new TextureMapper-related files.
  • platform/graphics/texmap/GraphicsLayerTextureMapper.cpp:

(WebCore::GraphicsLayerTextureMapper::addAnimation):
(WebCore::GraphicsLayerTextureMapper::pauseAnimation):
(WebCore::GraphicsLayerTextureMapper::removeAnimation):

  • platform/graphics/texmap/GraphicsLayerTextureMapper.h:
  • platform/graphics/texmap/TextureMapperAnimation.cpp: Added.
  • platform/graphics/texmap/TextureMapperAnimation.h: Added.
  • platform/graphics/texmap/TextureMapperNode.cpp:

(WebCore::TextureMapperNode::syncCompositingStateSelf):
(WebCore::TextureMapperNode::descendantsOrSelfHaveRunningAnimations):
(WebCore::TextureMapperNode::syncAnimations):
(WebCore::TextureMapperNode::syncAnimationsRecursively):
(WebCore::TextureMapperNode::syncCompositingState):

  • platform/graphics/texmap/TextureMapperNode.h:
Location:
trunk/Source/WebCore
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r105849 r105858  
     12012-01-25  No'am Rosenthal  <noam.rosenthal@nokia.com>
     2
     3        [Texmap] Divide TextureMapperNode.cpp to 3 files.
     4        https://bugs.webkit.org/show_bug.cgi?id=76660
     5
     6        Reviewed by Kenneth Rohde Christiansen.
     7
     8        Split the animation part of TextureMapperNode out to a separate file, called
     9        TextureMapperAnimation.
     10        Provide a clean interface for that class, that allows separating the internals of the scene
     11        painting from the internals of the animation interpolation.
     12
     13        No new tests. Existing animation tests cover this.
     14
     15        * GNUmakefile.list.am: Added new TextureMapper-related files.
     16        * Target.pri: Added new TextureMapper-related files.
     17        * WebCore.gypi: Added new TextureMapper-related files.
     18        * platform/graphics/texmap/GraphicsLayerTextureMapper.cpp:
     19        (WebCore::GraphicsLayerTextureMapper::addAnimation):
     20        (WebCore::GraphicsLayerTextureMapper::pauseAnimation):
     21        (WebCore::GraphicsLayerTextureMapper::removeAnimation):
     22        * platform/graphics/texmap/GraphicsLayerTextureMapper.h:
     23        * platform/graphics/texmap/TextureMapperAnimation.cpp: Added.
     24        * platform/graphics/texmap/TextureMapperAnimation.h: Added.
     25        * platform/graphics/texmap/TextureMapperNode.cpp:
     26        (WebCore::TextureMapperNode::syncCompositingStateSelf):
     27        (WebCore::TextureMapperNode::descendantsOrSelfHaveRunningAnimations):
     28        (WebCore::TextureMapperNode::syncAnimations):
     29        (WebCore::TextureMapperNode::syncAnimationsRecursively):
     30        (WebCore::TextureMapperNode::syncCompositingState):
     31        * platform/graphics/texmap/TextureMapperNode.h:
     32
    1332012-01-25  Roland Steiner  <rolandsteiner@chromium.org>
    234
  • trunk/Source/WebCore/GNUmakefile.list.am

    r105749 r105858  
    57205720        Source/WebCore/platform/graphics/texmap/TextureMapper.cpp \
    57215721        Source/WebCore/platform/graphics/texmap/TextureMapper.h \
     5722        Source/WebCore/platform/graphics/texmap/TextureMapperAnimation.cpp \
     5723        Source/WebCore/platform/graphics/texmap/TextureMapperAnimation.h \
    57225724        Source/WebCore/platform/graphics/texmap/TextureMapperNode.cpp \
    57235725        Source/WebCore/platform/graphics/texmap/TextureMapperNode.h \
     
    57385740        Source/WebCore/platform/graphics/texmap/TextureMapper.cpp \
    57395741        Source/WebCore/platform/graphics/texmap/TextureMapper.h \
     5742        Source/WebCore/platform/graphics/texmap/TextureMapperAnimation.cpp \
     5743        Source/WebCore/platform/graphics/texmap/TextureMapperAnimation.h \
    57405744        Source/WebCore/platform/graphics/texmap/TextureMapperNode.cpp \
    57415745        Source/WebCore/platform/graphics/texmap/TextureMapperNode.h \
  • trunk/Source/WebCore/Target.pri

    r105648 r105858  
    39303930        platform/graphics/texmap/LayerTransform.h \
    39313931        platform/graphics/texmap/TextureMapper.h \
     3932        platform/graphics/texmap/TextureMapperAnimation.h \
    39323933        platform/graphics/texmap/TextureMapperNode.h \
    39333934        platform/graphics/texmap/TextureMapperPlatformLayer.h
     
    39373938        platform/graphics/texmap/LayerTransform.cpp \
    39383939        platform/graphics/texmap/TextureMapper.cpp \
     3940        platform/graphics/texmap/TextureMapperAnimation.cpp \
    39393941        platform/graphics/texmap/TextureMapperNode.cpp \
    39403942        platform/graphics/texmap/GraphicsLayerTextureMapper.cpp
  • trunk/Source/WebCore/WebCore.gypi

    r105751 r105858  
    35733573            'platform/graphics/texmap/TextureMapper.cpp',
    35743574            'platform/graphics/texmap/TextureMapper.h',
     3575            'platform/graphics/texmap/TextureMapperAnimation.cpp',
     3576            'platform/graphics/texmap/TextureMapperAnimation.h',
    35753577            'platform/graphics/texmap/TextureMapperNode.cpp',
    35763578            'platform/graphics/texmap/TextureMapperNode.h',
  • trunk/Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.cpp

    r102113 r105858  
    366366        return false;
    367367
    368     for (size_t i = 0; i < m_animations.size(); ++i) {
    369         // The same animation name can be used for two animations with different properties.
    370         if (m_animations[i]->name != keyframesName || m_animations[i]->keyframes.property() != valueList.property())
    371             continue;
    372 
    373         // We already have a copy of this animation, that means that we're resuming it rather than adding it.
    374         RefPtr<TextureMapperAnimation>& animation = m_animations[i];
    375         animation->animation = Animation::create(anim);
    376         animation->paused = false;
    377         animation->startTime = WTF::currentTime() - timeOffset;
    378         notifyChange(TextureMapperNode::AnimationChange);
    379         m_animationStartedTimer.startOneShot(0);
    380         return true;
    381     }
    382 
    383     RefPtr<TextureMapperAnimation> animation = TextureMapperAnimation::create(valueList);
    384     animation->boxSize = boxSize;
    385     animation->name = keyframesName;
    386     animation->animation = Animation::create(anim);
    387     animation->paused = false;
    388     animation->startTime = WTF::currentTime() - timeOffset;
    389 
    390     if (valueList.property() == AnimatedPropertyWebkitTransform) {
    391         bool hasBigRotation; // Not used, but required as a pointer parameter for the function.
    392         fetchTransformOperationList(valueList, animation->functionList, animation->listsMatch, hasBigRotation);
    393     }
    394 
    395     m_animations.append(animation);
     368    bool listsMatch;
     369    bool hasBigRotation;
     370    Vector<TransformOperation::OperationType> functionList;
     371
     372    if (valueList.property() == AnimatedPropertyWebkitTransform)
     373        fetchTransformOperationList(valueList, functionList, listsMatch, hasBigRotation);
     374
     375    m_animations.add(keyframesName, TextureMapperAnimation(valueList, boxSize, anim, timeOffset, functionList, listsMatch));
    396376    notifyChange(TextureMapperNode::AnimationChange);
    397377    m_animationStartedTimer.startOneShot(0);
    398 
    399378    return true;
    400379}
     
    402381void GraphicsLayerTextureMapper::pauseAnimation(const String& animationName, double timeOffset)
    403382{
    404     for (size_t i = 0; i < m_animations.size(); ++i) {
    405         if (m_animations[i]->name != animationName)
    406             continue;
    407         m_animations[i]->paused = true;
    408         notifyChange(TextureMapperNode::AnimationChange);
    409     }
     383    m_animations.pause(animationName, timeOffset);
    410384}
    411385
    412386void GraphicsLayerTextureMapper::removeAnimation(const String& animationName)
    413387{
    414     for (int i = m_animations.size() - 1; i >= 0; --i) {
    415         // The same animation name can be used for two animations with different properties. We should remove both.
    416         if (m_animations[i]->name != animationName)
    417             continue;
    418         m_animations.remove(i);
    419         notifyChange(TextureMapperNode::AnimationChange);
    420     }
     388    m_animations.remove(animationName);
    421389}
    422390
  • trunk/Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.h

    r102113 r105858  
    9696    int m_changeMask;
    9797    TextureMapperNode::ContentData m_pendingContent;
    98     Vector<RefPtr<TextureMapperAnimation> > m_animations;
     98    TextureMapperAnimations m_animations;
    9999    void animationStartedTimerFired(Timer<GraphicsLayerTextureMapper>*);
    100100    Timer<GraphicsLayerTextureMapper> m_animationStartedTimer;
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapperNode.cpp

    r105737 r105858  
    586586    }
    587587
    588     if (changeMask & AnimationChange) {
    589         m_animations.clear();
    590         for (size_t i = 0; i < graphicsLayer->m_animations.size(); ++i)
    591             m_animations.append(graphicsLayer->m_animations[i]);
    592     }
     588    if (changeMask & AnimationChange)
     589        m_animations = graphicsLayer->m_animations;
    593590
    594591    m_state.maskLayer = toTextureMapperNode(graphicsLayer->maskLayer());
     
    615612        m_currentContent.needsDisplayRect.unite(pendingContent.needsDisplayRect);
    616613
    617     if (!hasOpacityAnimation())
    618         m_opacity = m_state.opacity;
    619     if (!hasTransformAnimation())
    620         m_transform.setLocalTransform(m_state.transform);
    621 
    622614    m_transform.setPosition(m_state.pos);
    623615    m_transform.setAnchorPoint(m_state.anchorPoint);
     
    629621bool TextureMapperNode::descendantsOrSelfHaveRunningAnimations() const
    630622{
    631     for (size_t i = 0; i < m_animations.size(); ++i) {
    632         if (!m_animations[i]->paused)
    633             return true;
    634     }
     623    if (m_animations.hasRunningAnimations())
     624        return true;
    635625
    636626    for (size_t i = 0; i < m_children.size(); ++i) {
     
    642632}
    643633
    644 static double normalizedAnimationValue(double runningTime, double duration, bool alternate)
    645 {
    646     if (!duration)
    647         return 0;
    648     const int loopCount = runningTime / duration;
    649     const double lastFullLoop = duration * double(loopCount);
    650     const double remainder = runningTime - lastFullLoop;
    651     const double normalized = remainder / duration;
    652     return (loopCount % 2 && alternate) ? (1 - normalized) : normalized;
    653 }
    654 
    655 void TextureMapperNode::applyOpacityAnimation(float fromOpacity, float toOpacity, double progress)
    656 {
    657     // Optimization: special case the edge values (0 and 1).
    658     if (progress == 1.0)
    659         setOpacity(toOpacity);
    660     else if (!progress)
    661         setOpacity(fromOpacity);
    662     else
    663         setOpacity(fromOpacity + progress * (toOpacity - fromOpacity));
    664 }
    665 
    666 static inline double solveEpsilon(double duration)
    667 {
    668     return 1.0 / (200.0 * duration);
    669 }
    670 
    671 static inline double solveCubicBezierFunction(double p1x, double p1y, double p2x, double p2y, double t, double duration)
    672 {
    673     UnitBezier bezier(p1x, p1y, p2x, p2y);
    674     return bezier.solve(t, solveEpsilon(duration));
    675 }
    676 
    677 static inline double solveStepsFunction(int numSteps, bool stepAtStart, double t)
    678 {
    679     if (stepAtStart)
    680         return std::min(1.0, (floor(numSteps * t) + 1) / numSteps);
    681     return floor(numSteps * t) / numSteps;
    682 }
    683 
    684 static inline float applyTimingFunction(const TimingFunction* timingFunction, float progress, double duration)
    685 {
    686     if (!timingFunction)
    687         return progress;
    688 
    689     if (timingFunction->isCubicBezierTimingFunction()) {
    690         const CubicBezierTimingFunction* ctf = static_cast<const CubicBezierTimingFunction*>(timingFunction);
    691         return solveCubicBezierFunction(ctf->x1(),
    692                                         ctf->y1(),
    693                                         ctf->x2(),
    694                                         ctf->y2(),
    695                                         progress, duration);
    696     }
    697 
    698     if (timingFunction->isStepsTimingFunction()) {
    699         const StepsTimingFunction* stf = static_cast<const StepsTimingFunction*>(timingFunction);
    700         return solveStepsFunction(stf->numberOfSteps(), stf->stepAtStart(), double(progress));
    701     }
    702 
    703     return progress;
    704 }
    705 
    706 void TextureMapperNode::applyTransformAnimation(const TextureMapperAnimation& animation, const TransformOperations* from, const TransformOperations* to, double progress)
    707 {
    708     // Optimization: special case the edge values (0 and 1).
    709     if (progress == 1.0 || !progress) {
    710         TransformationMatrix matrix;
    711         const TransformOperations* ops = progress ? to : from;
    712         ops->apply(animation.boxSize, matrix);
    713         setTransform(matrix);
    714     }
    715 
    716     if (!animation.listsMatch) {
    717         TransformationMatrix toMatrix, fromMatrix;
    718         to->apply(animation.boxSize, toMatrix);
    719         from->apply(animation.boxSize, fromMatrix);
    720         toMatrix.blend(fromMatrix, progress);
    721         setTransform(toMatrix);
    722         return;
    723     }
    724 
    725     TransformationMatrix matrix;
    726 
    727     if (!to->size()) {
    728         const TransformOperations* swap = to;
    729         to = from;
    730         from = swap;
    731     } else if (!from->size())
    732         progress = 1.0 - progress;
    733 
    734     TransformOperations blended(*to);
    735     for (size_t i = 0; i < animation.functionList.size(); ++i)
    736         blended.operations()[i]->blend(from->at(i), progress, !from->at(i))->apply(matrix, animation.boxSize);
    737 
    738     setTransform(matrix);
    739 }
    740 
    741 void TextureMapperNode::applyAnimationFrame(const TextureMapperAnimation& animation, const AnimationValue* from, const AnimationValue* to, float progress)
    742 {
    743     switch (animation.keyframes.property()) {
    744     case AnimatedPropertyOpacity:
    745         applyOpacityAnimation((static_cast<const FloatAnimationValue*>(from)->value()), (static_cast<const FloatAnimationValue*>(to)->value()), progress);
    746         return;
    747     case AnimatedPropertyWebkitTransform:
    748         applyTransformAnimation(animation, static_cast<const TransformAnimationValue*>(from)->value(), static_cast<const TransformAnimationValue*>(to)->value(), progress);
    749         return;
    750     default:
    751         ASSERT_NOT_REACHED();
    752     }
    753 }
    754 
    755 void TextureMapperNode::applyAnimation(const TextureMapperAnimation& animation, double normalizedValue)
    756 {
    757     // Optimization: special case the edge values (0 and 1).
    758     if (!normalizedValue) {
    759         applyAnimationFrame(animation, animation.keyframes.at(0), animation.keyframes.at(1), 0);
    760         return;
    761     }
    762     if (normalizedValue == 1.0) {
    763         applyAnimationFrame(animation, animation.keyframes.at(animation.keyframes.size() - 2), animation.keyframes.at(animation.keyframes.size() - 1), 1);
    764         return;
    765     }
    766     if (animation.keyframes.size() == 2) {
    767         normalizedValue = applyTimingFunction(animation.animation->timingFunction().get(), normalizedValue, animation.animation->duration());
    768         applyAnimationFrame(animation, animation.keyframes.at(0), animation.keyframes.at(1), normalizedValue);
    769         return;
    770     }
    771 
    772     for (size_t i = 0; i < animation.keyframes.size() - 1; ++i) {
    773         const AnimationValue* from = animation.keyframes.at(i);
    774         const AnimationValue* to = animation.keyframes.at(i + 1);
    775         if (from->keyTime() > normalizedValue || to->keyTime() < normalizedValue)
    776             continue;
    777 
    778         normalizedValue = (normalizedValue - from->keyTime()) / (to->keyTime() - from->keyTime());
    779         normalizedValue = applyTimingFunction(from->timingFunction(), normalizedValue, animation.animation->duration());
    780         applyAnimationFrame(animation, from, to, normalizedValue);
    781         break;
    782     }
    783 }
    784 
    785 bool TextureMapperNode::hasOpacityAnimation() const
    786 {
    787     for (size_t i = 0; i < m_animations.size(); ++i) {
    788         const TextureMapperAnimation& animation = *m_animations[i].get();
    789         if (animation.keyframes.property() == AnimatedPropertyOpacity)
    790             return true;
    791     }
    792     return false;
    793 }
    794 
    795 bool TextureMapperNode::hasTransformAnimation() const
    796 {
    797     for (size_t i = 0; i < m_animations.size(); ++i) {
    798         const TextureMapperAnimation& animation = *m_animations[i].get();
    799         if (animation.keyframes.property() == AnimatedPropertyWebkitTransform)
    800             return true;
    801     }
    802     return false;
    803 }
    804 
    805 void TextureMapperNode::syncAnimations(GraphicsLayerTextureMapper* layer)
    806 {
    807     for (int i = m_animations.size() - 1; i >= 0; --i) {
    808         RefPtr<TextureMapperAnimation> animation = m_animations[i];
    809 
    810         double totalRunningTime = WTF::currentTime() - animation->startTime;
    811         RefPtr<Animation> anim = animation->animation;
    812         double normalizedValue = normalizedAnimationValue(totalRunningTime, anim->duration(), anim->direction());
    813 
    814         if (anim->iterationCount() != Animation::IterationCountInfinite && totalRunningTime >= anim->duration() * anim->iterationCount()) {
    815             // We apply an animation that very close to the edge, so that the final frame is applied, oterwise we might get, for example, an opacity of 0.01 which is still visible.
    816             if (anim->fillsForwards()) {
    817                 if (animation->keyframes.property() == AnimatedPropertyWebkitTransform)
    818                     setTransform(m_state.transform);
    819                 else if (animation->keyframes.property() == AnimatedPropertyOpacity)
    820                     setOpacity(m_state.opacity);
    821             }
    822 
    823             m_animations.remove(i);
    824             continue;
    825         }
    826 
    827         if (!animation->paused)
    828             applyAnimation(*animation.get(), normalizedValue);
    829     }
     634void TextureMapperNode::syncAnimations()
     635{
     636    m_animations.apply(this);
     637    if (!m_animations.hasActiveAnimationsOfType(AnimatedPropertyWebkitTransform))
     638        setTransform(m_state.transform);
     639    if (!m_animations.hasActiveAnimationsOfType(AnimatedPropertyOpacity))
     640        setOpacity(m_state.opacity);
    830641}
    831642
    832643void TextureMapperNode::syncAnimationsRecursively()
    833644{
    834     syncAnimations(0);
     645    syncAnimations();
    835646
    836647    for (int i = m_children.size() - 1; i >= 0; --i)
     
    856667        m_state.replicaLayer->syncCompositingState(toGraphicsLayerTextureMapper(graphicsLayer->replicaLayer()), textureMapper);
    857668
    858     syncAnimations(graphicsLayer);
    859 
     669    syncAnimations();
    860670    computeTiles();
    861671
     
    880690}
    881691
    882 TextureMapperAnimation::TextureMapperAnimation(const KeyframeValueList& values)
    883     : keyframes(values)
    884 {
    885 }
    886 
    887 }
    888 
     692}
    889693#endif
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapperNode.h

    r105737 r105858  
    2828#include "LayerTransform.h"
    2929#include "TextureMapper.h"
     30#include "TextureMapperAnimation.h"
    3031#include "Timer.h"
    3132#include "TransformOperations.h"
    32 #include "TranslateTransformOperation.h"
    33 #include "UnitBezier.h"
    3433#include <wtf/CurrentTime.h>
    3534#include <wtf/HashMap.h>
     
    5857};
    5958
    60 class TextureMapperAnimation : public RefCounted<TextureMapperAnimation> {
    61 public:
    62     String name;
    63     KeyframeValueList keyframes;
    64     IntSize boxSize;
    65     RefPtr<Animation> animation;
    66     bool paused;
    67     Vector<TransformOperation::OperationType> functionList;
    68     bool listsMatch;
    69     bool hasBigRotation;
    70     double startTime;
    71     TextureMapperAnimation(const KeyframeValueList&);
    72     static PassRefPtr<TextureMapperAnimation> create(const KeyframeValueList& values) { return adoptRef(new TextureMapperAnimation(values)); }
    73 };
    74 
    75 class TextureMapperNode {
     59class TextureMapperNode : public TextureMapperAnimationClient {
    7660
    7761public:
     
    199183    void renderContent(TextureMapper*, GraphicsLayer*);
    200184
    201     void syncAnimations(GraphicsLayerTextureMapper*);
    202     void applyAnimation(const TextureMapperAnimation&, double runningTime);
    203     void applyAnimationFrame(const TextureMapperAnimation&, const AnimationValue* from, const AnimationValue* to, float progress);
    204     void applyOpacityAnimation(float fromOpacity, float toOpacity, double);
    205     void applyTransformAnimation(const TextureMapperAnimation&, const TransformOperations* start, const TransformOperations* end, double);
    206     bool hasOpacityAnimation() const;
    207     bool hasTransformAnimation() const;
     185    void syncAnimations();
    208186    bool isVisible() const;
    209187    bool shouldPaintToIntermediateSurface() const;
     
    316294    State m_state;
    317295    TextureMapper* m_textureMapper;
    318 
    319     Vector<RefPtr<TextureMapperAnimation> > m_animations;
     296    TextureMapperAnimations m_animations;
    320297};
    321298
Note: See TracChangeset for help on using the changeset viewer.