Changeset 123419 in webkit


Ignore:
Timestamp:
Jul 23, 2012 7:44:29 PM (12 years ago)
Author:
mikelawther@chromium.org
Message:

CSS3 calc: optimise blending expression
https://bugs.webkit.org/show_bug.cgi?id=90037

Reviewed by Tony Chang.

Introduce a new calc expression node - a BlendLength node. Given two Lengths and a progress
this blends them together when evaluated.

An alternative and more general approach of being able to blend two CalcExpressionNodes was
tested, but involves more memory allocations, was measurably slower, and nothing currently
would make use of the generality.

No functional change. Covered by existing tests.

  • platform/CalculationValue.h:

(CalcExpressionBlendLength):
(WebCore::CalcExpressionBlendLength::CalcExpressionBlendLength):
(WebCore::CalcExpressionBlendLength::operator==):
(WebCore::CalcExpressionBlendLength::evaluate):
(WebCore):

  • platform/Length.cpp:

(WebCore::Length::blendCalculation):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r123418 r123419  
     12012-07-23  Mike Lawther  <mikelawther@chromium.org>
     2
     3        CSS3 calc: optimise blending expression
     4        https://bugs.webkit.org/show_bug.cgi?id=90037
     5
     6        Reviewed by Tony Chang.
     7
     8        Introduce a new calc expression node - a BlendLength node. Given two Lengths and a progress
     9        this blends them together when evaluated.
     10
     11        An alternative and more general approach of being able to blend two CalcExpressionNodes was
     12        tested, but involves more memory allocations, was measurably slower, and nothing currently
     13        would make use of the generality.
     14
     15        No functional change. Covered by existing tests.
     16
     17        * platform/CalculationValue.h:
     18        (CalcExpressionBlendLength):
     19        (WebCore::CalcExpressionBlendLength::CalcExpressionBlendLength):
     20        (WebCore::CalcExpressionBlendLength::operator==):
     21        (WebCore::CalcExpressionBlendLength::evaluate):
     22        (WebCore):
     23        * platform/Length.cpp:
     24        (WebCore::Length::blendCalculation):
     25
    1262012-07-23  Nico Weber  <thakis@chromium.org>
    227
  • trunk/Source/WebCore/platform/CalculationValue.h

    r121132 r123419  
    5757    CalcExpressionNodeNumber,
    5858    CalcExpressionNodeLength,
    59     CalcExpressionNodeBinaryOperation
     59    CalcExpressionNodeBinaryOperation,
     60    CalcExpressionNodeBlendLength,
    6061};
    6162       
     
    184185};
    185186
     187class CalcExpressionBlendLength : public CalcExpressionNode {
     188public:
     189    CalcExpressionBlendLength(Length from, Length to, float progress)
     190        : m_from(from)
     191        , m_to(to)
     192        , m_progress(progress)
     193    {
     194        m_type = CalcExpressionNodeBlendLength;
     195    }
     196   
     197    bool operator==(const CalcExpressionBlendLength& o) const
     198    {
     199        return m_progress == o.m_progress && m_from == o.m_from && m_to == o.m_to;
     200    }
     201   
     202    virtual bool operator==(const CalcExpressionNode& o) const
     203    {
     204        return type() == o.type() && *this == static_cast<const CalcExpressionBlendLength&>(o);
     205    }
     206   
     207    virtual float evaluate(float maxValue) const
     208    {
     209        return (1.0f - m_progress) * floatValueForLength(m_from, maxValue) + m_progress * floatValueForLength(m_to, maxValue);
     210    }
     211   
     212private: 
     213    Length m_from;
     214    Length m_to;
     215    float m_progress;
     216};
     217   
    186218} // namespace WebCore
    187219
  • trunk/Source/WebCore/platform/Length.cpp

    r121351 r123419  
    211211        return *this;
    212212       
    213     // FIXME: https://webkit.org/b/90037 - some of these allocations can be eliminated
    214     OwnPtr<CalcExpressionNode> startScale = adoptPtr(new CalcExpressionNumber(1.0 - progress));
    215     OwnPtr<CalcExpressionNode> startLength = adoptPtr(new CalcExpressionLength(from));
    216     OwnPtr<CalcExpressionNode> startNode = adoptPtr(new CalcExpressionBinaryOperation(startScale.release(), startLength.release(), CalcMultiply));
    217    
    218     OwnPtr<CalcExpressionNode> endScale = adoptPtr(new CalcExpressionNumber(progress));
    219     OwnPtr<CalcExpressionNode> endLength = adoptPtr(new CalcExpressionLength(*this));
    220     OwnPtr<CalcExpressionNode> endNode = adoptPtr(new CalcExpressionBinaryOperation(endScale.release(), endLength.release(), CalcMultiply));
    221    
    222     OwnPtr<CalcExpressionNode> blend = adoptPtr(new CalcExpressionBinaryOperation(startNode.release(), endNode.release(), CalcAdd));
    223        
     213    OwnPtr<CalcExpressionNode> blend = adoptPtr(new CalcExpressionBlendLength(from, *this, progress));
    224214    return Length(CalculationValue::create(blend.release(), CalculationRangeAll));
    225215}
Note: See TracChangeset for help on using the changeset viewer.