Changeset 200343 in webkit


Ignore:
Timestamp:
May 2, 2016 3:19:33 PM (8 years ago)
Author:
Simon Fraser
Message:

Make Length, LengthSize and LengthPoint blending not use member functions
https://bugs.webkit.org/show_bug.cgi?id=157281

Reviewed by Zalan Bujtas.

Having blend() be a member function is ambiguous because it's hard to tell which are
the 'from' and 'to' values. Fix Length, LengthSize and LengthPoint accordingly.

No behavior change.

  • page/animation/CSSPropertyAnimation.cpp:

(WebCore::blendFunc):

  • platform/Length.cpp:

(WebCore::blendMixedTypes):
(WebCore::blend):
(WebCore::Length::blendMixedTypes): Deleted.

  • platform/Length.h:

(WebCore::Length::blend): Deleted.

  • platform/LengthPoint.h:

(WebCore::blend):
(WebCore::LengthPoint::blend): Deleted.

  • platform/LengthSize.h:

(WebCore::blend):
(WebCore::LengthSize::blend): Deleted.

  • platform/graphics/filters/FilterOperation.cpp:

(WebCore::BlurFilterOperation::blend):

  • platform/graphics/transforms/TranslateTransformOperation.cpp:

(WebCore::TranslateTransformOperation::blend):

  • rendering/style/BasicShapes.cpp:

(WebCore::BasicShapePolygon::blend):
(WebCore::BasicShapeInset::blend):

  • rendering/style/BasicShapes.h:

(WebCore::BasicShapeCenterCoordinate::blend):
(WebCore::BasicShapeRadius::blend):

Location:
trunk/Source/WebCore
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r200342 r200343  
     12016-05-02  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Make Length, LengthSize and LengthPoint blending not use member functions
     4        https://bugs.webkit.org/show_bug.cgi?id=157281
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        Having blend() be a member function is ambiguous because it's hard to tell which are
     9        the 'from' and 'to' values. Fix Length, LengthSize and LengthPoint accordingly.
     10
     11        No behavior change.
     12
     13        * page/animation/CSSPropertyAnimation.cpp:
     14        (WebCore::blendFunc):
     15        * platform/Length.cpp:
     16        (WebCore::blendMixedTypes):
     17        (WebCore::blend):
     18        (WebCore::Length::blendMixedTypes): Deleted.
     19        * platform/Length.h:
     20        (WebCore::Length::blend): Deleted.
     21        * platform/LengthPoint.h:
     22        (WebCore::blend):
     23        (WebCore::LengthPoint::blend): Deleted.
     24        * platform/LengthSize.h:
     25        (WebCore::blend):
     26        (WebCore::LengthSize::blend): Deleted.
     27        * platform/graphics/filters/FilterOperation.cpp:
     28        (WebCore::BlurFilterOperation::blend):
     29        * platform/graphics/transforms/TranslateTransformOperation.cpp:
     30        (WebCore::TranslateTransformOperation::blend):
     31        * rendering/style/BasicShapes.cpp:
     32        (WebCore::BasicShapePolygon::blend):
     33        (WebCore::BasicShapeInset::blend):
     34        * rendering/style/BasicShapes.h:
     35        (WebCore::BasicShapeCenterCoordinate::blend):
     36        (WebCore::BasicShapeRadius::blend):
     37
    1382016-05-02  Simon Fraser  <simon.fraser@apple.com>
    239
  • trunk/Source/WebCore/page/animation/CSSPropertyAnimation.cpp

    r200341 r200343  
    8585static inline Length blendFunc(const AnimationBase*, const Length& from, const Length& to, double progress)
    8686{
    87     return to.blend(from, progress);
     87    return blend(from, to, progress);
    8888}
    8989
  • trunk/Source/WebCore/platform/Length.cpp

    r200341 r200343  
    252252    m_calculationValueHandle = calculationValues().insert(WTFMove(value));
    253253}
    254        
    255 Length Length::blendMixedTypes(const Length& from, double progress) const
    256 {
    257     if (progress <= 0.0)
    258         return from;
    259        
    260     if (progress >= 1.0)
    261         return *this;
    262        
    263     auto blend = std::make_unique<CalcExpressionBlendLength>(from, *this, progress);
    264     return Length(CalculationValue::create(WTFMove(blend), CalculationRangeAll));
    265 }
    266254
    267255CalculationValue& Length::calculationValue() const
     
    295283{
    296284    return calculationValue() == other.calculationValue();
     285}
     286
     287static Length blendMixedTypes(const Length& from, const Length& to, double progress)
     288{
     289    if (progress <= 0.0)
     290        return from;
     291       
     292    if (progress >= 1.0)
     293        return to;
     294       
     295    auto blend = std::make_unique<CalcExpressionBlendLength>(from, to, progress);
     296    return Length(CalculationValue::create(WTFMove(blend), CalculationRangeAll));
     297}
     298
     299Length blend(const Length& from, const Length& to, double progress)
     300{
     301    if (from.type() == Calculated || to.type() == Calculated)
     302        return blendMixedTypes(from, to, progress);
     303
     304    if (!from.isZero() && !to.isZero() && from.type() != to.type())
     305        return blendMixedTypes(from, to, progress);
     306
     307    if (from.isZero() && to.isZero())
     308        return progress ? to : from; // Pick up 'auto' from 'from' if progress is zero.
     309
     310    LengthType resultType = to.type();
     311    if (to.isZero())
     312        resultType = from.type();
     313
     314    if (resultType == Percent) {
     315        float fromPercent = from.isZero() ? 0 : from.percent();
     316        float toPercent = to.isZero() ? 0 : to.percent();
     317        return Length(WebCore::blend(fromPercent, toPercent, progress), Percent);
     318    }
     319
     320    float fromValue = from.isZero() ? 0 : from.value();
     321    float toValue = to.isZero() ? 0 : to.value();
     322    return Length(WebCore::blend(fromValue, toValue, progress), resultType);
    297323}
    298324
  • trunk/Source/WebCore/platform/Length.h

    r193610 r200343  
    108108    bool isSpecifiedOrIntrinsic() const;
    109109
    110     // Blend two lengths to produce a new length that is in between them. Used for animation.
    111     // FIXME: Why is this a member function?
    112     Length blend(const Length& from, double progress) const;
    113 
    114110    float nonNanCalculatedValue(int maxValue) const;
    115111
     
    118114
    119115    bool isCalculatedEqual(const Length&) const;
    120     Length blendMixedTypes(const Length& from, double progress) const;
    121116
    122117    WEBCORE_EXPORT void ref() const;
     
    133128};
    134129
     130// Blend two lengths to produce a new length that is in between them. Used for animation.
     131Length blend(const Length& from, const Length& to, double progress);
     132
    135133std::unique_ptr<Length[]> newCoordsArray(const String&, int& length);
    136134std::unique_ptr<Length[]> newLengthArray(const String&, int& length);
     
    413411}
    414412
    415 // FIXME: Does this need to be in the header? Is it valuable to inline? Does it get inlined?
    416 inline Length Length::blend(const Length& from, double progress) const
    417 {
    418     if (from.type() == Calculated || type() == Calculated)
    419         return blendMixedTypes(from, progress);
    420 
    421     if (!from.isZero() && !isZero() && from.type() != type())
    422         return blendMixedTypes(from, progress);
    423 
    424     if (from.isZero() && isZero())
    425         return progress ? *this : from; // Pick up 'auto' from 'from' if progress is zero.
    426 
    427     LengthType resultType = type();
    428     if (isZero())
    429         resultType = from.type();
    430 
    431     if (resultType == Percent) {
    432         float fromPercent = from.isZero() ? 0 : from.percent();
    433         float toPercent = isZero() ? 0 : percent();
    434         return Length(WebCore::blend(fromPercent, toPercent, progress), Percent);
    435     }
    436 
    437     float fromValue = from.isZero() ? 0 : from.value();
    438     float toValue = isZero() ? 0 : value();
    439     return Length(WebCore::blend(fromValue, toValue, progress), resultType);
    440 }
    441 
    442413TextStream& operator<<(TextStream&, Length);
    443414
  • trunk/Source/WebCore/platform/LengthPoint.h

    r197617 r200343  
    5959    const Length& y() const { return m_y; }
    6060
    61     LengthPoint blend(const LengthPoint& from, double progress) const
    62     {
    63         return LengthPoint(m_x.blend(from.x(), progress), m_y.blend(from.y(), progress));
    64     }
    65 
    6661private:
    6762    // FIXME: it would be nice to pack the two Lengths together better somehow (to avoid padding between them).
     
    7065};
    7166
     67inline LengthPoint blend(const LengthPoint& from, const LengthPoint& to, double progress)
     68{
     69    return LengthPoint(blend(from.x(), to.x(), progress), blend(from.y(), to.y(), progress));
     70}
     71
    7272TextStream& operator<<(TextStream&, const LengthPoint&);
    7373
  • trunk/Source/WebCore/platform/LengthSize.h

    r194496 r200343  
    4949    const Length& height() const { return m_height; }
    5050
    51     LengthSize blend(const LengthSize& from, double progress) const
    52     {
    53         return LengthSize(m_width.blend(from.width(), progress), m_height.blend(from.height(), progress));
    54     }
    55 
    5651private:
    5752    Length m_width;
    5853    Length m_height;
    5954};
     55
     56inline LengthSize blend(const LengthSize& from, const LengthSize& to, double progress)
     57{
     58    return LengthSize(blend(from.width(), to.width(), progress), blend(from.height(), to.height(), progress));
     59}
    6060
    6161TextStream& operator<<(TextStream&, const LengthSize&);
  • trunk/Source/WebCore/platform/graphics/filters/FilterOperation.cpp

    r191243 r200343  
    163163
    164164    if (blendToPassthrough)
    165         return BlurFilterOperation::create(Length(lengthType).blend(m_stdDeviation, progress));
     165        return BlurFilterOperation::create(WebCore::blend(m_stdDeviation, Length(lengthType), progress));
    166166
    167167    const BlurFilterOperation* fromOperation = downcast<BlurFilterOperation>(from);
    168168    Length fromLength = fromOperation ? fromOperation->m_stdDeviation : Length(lengthType);
    169     return BlurFilterOperation::create(m_stdDeviation.blend(fromLength, progress));
     169    return BlurFilterOperation::create(WebCore::blend(fromLength, m_stdDeviation, progress));
    170170}
    171171   
  • trunk/Source/WebCore/platform/graphics/transforms/TranslateTransformOperation.cpp

    r200341 r200343  
    4343    Length zeroLength(0, Fixed);
    4444    if (blendToIdentity)
    45         return TranslateTransformOperation::create(zeroLength.blend(m_x, progress), zeroLength.blend(m_y, progress), zeroLength.blend(m_z, progress), m_type);
     45        return TranslateTransformOperation::create(WebCore::blend(m_x, zeroLength, progress), WebCore::blend(m_y, zeroLength, progress), WebCore::blend(m_z, zeroLength, progress), m_type);
    4646
    4747    const TranslateTransformOperation* fromOp = downcast<TranslateTransformOperation>(from);
     
    4949    Length fromY = fromOp ? fromOp->m_y : zeroLength;
    5050    Length fromZ = fromOp ? fromOp->m_z : zeroLength;
    51     return TranslateTransformOperation::create(m_x.blend(fromX, progress), m_y.blend(fromY, progress), m_z.blend(fromZ, progress), m_type);
     51    return TranslateTransformOperation::create(WebCore::blend(fromX, x(), progress), WebCore::blend(fromY, y(), progress), WebCore::blend(fromZ, z(), progress), m_type);
    5252}
    5353
  • trunk/Source/WebCore/rendering/style/BasicShapes.cpp

    r195970 r200343  
    320320
    321321    for (size_t i = 0; i < length; i = i + 2) {
    322         result->appendPoint(m_values.at(i).blend(otherPolygon.values().at(i), progress),
    323             m_values.at(i + 1).blend(otherPolygon.values().at(i + 1), progress));
     322        result->appendPoint(
     323            WebCore::blend(otherPolygon.values().at(i), m_values.at(i), progress),
     324            WebCore::blend(otherPolygon.values().at(i + 1), m_values.at(i + 1), progress));
    324325    }
    325326
     
    412413}
    413414
    414 Ref<BasicShape> BasicShapeInset::blend(const BasicShape& other, double progress) const
    415 {
    416     ASSERT(type() == other.type());
    417 
    418     auto& otherInset = downcast<BasicShapeInset>(other);
     415Ref<BasicShape> BasicShapeInset::blend(const BasicShape& from, double progress) const
     416{
     417    ASSERT(type() == from.type());
     418
     419    auto& fromInset = downcast<BasicShapeInset>(from);
    419420    auto result =  BasicShapeInset::create();
    420     result->setTop(m_top.blend(otherInset.top(), progress));
    421     result->setRight(m_right.blend(otherInset.right(), progress));
    422     result->setBottom(m_bottom.blend(otherInset.bottom(), progress));
    423     result->setLeft(m_left.blend(otherInset.left(), progress));
    424 
    425     result->setTopLeftRadius(m_topLeftRadius.blend(otherInset.topLeftRadius(), progress));
    426     result->setTopRightRadius(m_topRightRadius.blend(otherInset.topRightRadius(), progress));
    427     result->setBottomRightRadius(m_bottomRightRadius.blend(otherInset.bottomRightRadius(), progress));
    428     result->setBottomLeftRadius(m_bottomLeftRadius.blend(otherInset.bottomLeftRadius(), progress));
     421    result->setTop(WebCore::blend(fromInset.top(), top(), progress));
     422    result->setRight(WebCore::blend(fromInset.right(), right(), progress));
     423    result->setBottom(WebCore::blend(fromInset.bottom(), bottom(), progress));
     424    result->setLeft(WebCore::blend(fromInset.left(), left(), progress));
     425
     426    result->setTopLeftRadius(WebCore::blend(fromInset.topLeftRadius(), topLeftRadius(), progress));
     427    result->setTopRightRadius(WebCore::blend(fromInset.topRightRadius(), topRightRadius(), progress));
     428    result->setBottomRightRadius(WebCore::blend(fromInset.bottomRightRadius(), bottomRightRadius(), progress));
     429    result->setBottomLeftRadius(WebCore::blend(fromInset.bottomLeftRadius(), bottomLeftRadius(), progress));
    429430
    430431    return WTFMove(result);
  • trunk/Source/WebCore/rendering/style/BasicShapes.h

    r197563 r200343  
    6565
    6666    virtual bool canBlend(const BasicShape&) const = 0;
    67     virtual Ref<BasicShape> blend(const BasicShape&, double) const = 0;
     67    virtual Ref<BasicShape> blend(const BasicShape& from, double) const = 0;
    6868
    6969    virtual bool operator==(const BasicShape&) const = 0;
     
    102102    const Length& computedLength() const { return m_computedLength; }
    103103
    104     BasicShapeCenterCoordinate blend(const BasicShapeCenterCoordinate& other, double progress) const
    105     {
    106         return BasicShapeCenterCoordinate(TopLeft, m_computedLength.blend(other.m_computedLength, progress));
     104    BasicShapeCenterCoordinate blend(const BasicShapeCenterCoordinate& from, double progress) const
     105    {
     106        return BasicShapeCenterCoordinate(TopLeft, WebCore::blend(from.m_computedLength, m_computedLength, progress));
    107107    }
    108108   
     
    156156    }
    157157
    158     BasicShapeRadius blend(const BasicShapeRadius& other, double progress) const
    159     {
    160         if (m_type != Value || other.type() != Value)
    161             return BasicShapeRadius(other);
    162 
    163         return BasicShapeRadius(m_value.blend(other.value(), progress));
     158    BasicShapeRadius blend(const BasicShapeRadius& from, double progress) const
     159    {
     160        if (m_type != Value || from.type() != Value)
     161            return BasicShapeRadius(from);
     162
     163        return BasicShapeRadius(WebCore::blend(from.value(), value(), progress));
    164164    }
    165165   
     
    196196
    197197    bool canBlend(const BasicShape&) const override;
    198     Ref<BasicShape> blend(const BasicShape&, double) const override;
     198    Ref<BasicShape> blend(const BasicShape& from, double) const override;
    199199
    200200    bool operator==(const BasicShape&) const override;
     
    228228
    229229    bool canBlend(const BasicShape&) const override;
    230     Ref<BasicShape> blend(const BasicShape&, double) const override;
     230    Ref<BasicShape> blend(const BasicShape& from, double) const override;
    231231
    232232    bool operator==(const BasicShape&) const override;
     
    259259
    260260    bool canBlend(const BasicShape&) const override;
    261     Ref<BasicShape> blend(const BasicShape&, double) const override;
     261    Ref<BasicShape> blend(const BasicShape& from, double) const override;
    262262
    263263    bool operator==(const BasicShape&) const override;
     
    287287
    288288    bool canBlend(const BasicShape&) const override;
    289     Ref<BasicShape> blend(const BasicShape&, double) const override;
     289    Ref<BasicShape> blend(const BasicShape& from, double) const override;
    290290
    291291    bool operator==(const BasicShape&) const override;
     
    327327
    328328    bool canBlend(const BasicShape&) const override;
    329     Ref<BasicShape> blend(const BasicShape&, double) const override;
     329    Ref<BasicShape> blend(const BasicShape& from, double) const override;
    330330
    331331    bool operator==(const BasicShape&) const override;
Note: See TracChangeset for help on using the changeset viewer.