Make Length, LengthSize and LengthPoint blending not use member functions
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 2 May 2016 22:19:33 +0000 (22:19 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 2 May 2016 22:19:33 +0000 (22:19 +0000)
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):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200343 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/page/animation/CSSPropertyAnimation.cpp
Source/WebCore/platform/Length.cpp
Source/WebCore/platform/Length.h
Source/WebCore/platform/LengthPoint.h
Source/WebCore/platform/LengthSize.h
Source/WebCore/platform/graphics/filters/FilterOperation.cpp
Source/WebCore/platform/graphics/transforms/TranslateTransformOperation.cpp
Source/WebCore/rendering/style/BasicShapes.cpp
Source/WebCore/rendering/style/BasicShapes.h

index 7d8d352..148927e 100644 (file)
@@ -1,5 +1,42 @@
 2016-05-02  Simon Fraser  <simon.fraser@apple.com>
 
+        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):
+
+2016-05-02  Simon Fraser  <simon.fraser@apple.com>
+
         Fix shouldUpdateScrollLayerPositionSynchronously() for non-main frames. Remove updatesScrollLayerPositionOnMainThread()
         https://bugs.webkit.org/show_bug.cgi?id=157277
 
index 9e9b275..9fef91f 100644 (file)
@@ -84,7 +84,7 @@ static inline Color blendFunc(const AnimationBase*, const Color& from, const Col
 
 static inline Length blendFunc(const AnimationBase*, const Length& from, const Length& to, double progress)
 {
-    return to.blend(from, progress);
+    return blend(from, to, progress);
 }
 
 static inline LengthSize blendFunc(const AnimationBase* anim, const LengthSize& from, const LengthSize& to, double progress)
index 2e038bd..708f1b0 100644 (file)
@@ -251,18 +251,6 @@ Length::Length(Ref<CalculationValue>&& value)
 {
     m_calculationValueHandle = calculationValues().insert(WTFMove(value));
 }
-        
-Length Length::blendMixedTypes(const Length& from, double progress) const
-{
-    if (progress <= 0.0)
-        return from;
-        
-    if (progress >= 1.0)
-        return *this;
-        
-    auto blend = std::make_unique<CalcExpressionBlendLength>(from, *this, progress);
-    return Length(CalculationValue::create(WTFMove(blend), CalculationRangeAll));
-}
 
 CalculationValue& Length::calculationValue() const
 {
@@ -296,6 +284,44 @@ bool Length::isCalculatedEqual(const Length& other) const
     return calculationValue() == other.calculationValue();
 }
 
+static Length blendMixedTypes(const Length& from, const Length& to, double progress)
+{
+    if (progress <= 0.0)
+        return from;
+        
+    if (progress >= 1.0)
+        return to;
+        
+    auto blend = std::make_unique<CalcExpressionBlendLength>(from, to, progress);
+    return Length(CalculationValue::create(WTFMove(blend), CalculationRangeAll));
+}
+
+Length blend(const Length& from, const Length& to, double progress)
+{
+    if (from.type() == Calculated || to.type() == Calculated)
+        return blendMixedTypes(from, to, progress);
+
+    if (!from.isZero() && !to.isZero() && from.type() != to.type())
+        return blendMixedTypes(from, to, progress);
+
+    if (from.isZero() && to.isZero())
+        return progress ? to : from; // Pick up 'auto' from 'from' if progress is zero.
+
+    LengthType resultType = to.type();
+    if (to.isZero())
+        resultType = from.type();
+
+    if (resultType == Percent) {
+        float fromPercent = from.isZero() ? 0 : from.percent();
+        float toPercent = to.isZero() ? 0 : to.percent();
+        return Length(WebCore::blend(fromPercent, toPercent, progress), Percent);
+    }
+
+    float fromValue = from.isZero() ? 0 : from.value();
+    float toValue = to.isZero() ? 0 : to.value();
+    return Length(WebCore::blend(fromValue, toValue, progress), resultType);
+}
+
 struct SameSizeAsLength {
     int32_t value;
     int32_t metaData;
index fd8bdd4..251a845 100644 (file)
@@ -107,17 +107,12 @@ public:
     bool isSpecified() const;
     bool isSpecifiedOrIntrinsic() const;
 
-    // Blend two lengths to produce a new length that is in between them. Used for animation.
-    // FIXME: Why is this a member function?
-    Length blend(const Length& from, double progress) const;
-
     float nonNanCalculatedValue(int maxValue) const;
 
 private:
     bool isLegacyIntrinsic() const;
 
     bool isCalculatedEqual(const Length&) const;
-    Length blendMixedTypes(const Length& from, double progress) const;
 
     WEBCORE_EXPORT void ref() const;
     WEBCORE_EXPORT void deref() const;
@@ -132,6 +127,9 @@ private:
     bool m_isFloat;
 };
 
+// Blend two lengths to produce a new length that is in between them. Used for animation.
+Length blend(const Length& from, const Length& to, double progress);
+
 std::unique_ptr<Length[]> newCoordsArray(const String&, int& length);
 std::unique_ptr<Length[]> newLengthArray(const String&, int& length);
 
@@ -412,33 +410,6 @@ inline bool Length::isFitContent() const
     return type() == FitContent;
 }
 
-// FIXME: Does this need to be in the header? Is it valuable to inline? Does it get inlined?
-inline Length Length::blend(const Length& from, double progress) const
-{
-    if (from.type() == Calculated || type() == Calculated)
-        return blendMixedTypes(from, progress);
-
-    if (!from.isZero() && !isZero() && from.type() != type())
-        return blendMixedTypes(from, progress);
-
-    if (from.isZero() && isZero())
-        return progress ? *this : from; // Pick up 'auto' from 'from' if progress is zero.
-
-    LengthType resultType = type();
-    if (isZero())
-        resultType = from.type();
-
-    if (resultType == Percent) {
-        float fromPercent = from.isZero() ? 0 : from.percent();
-        float toPercent = isZero() ? 0 : percent();
-        return Length(WebCore::blend(fromPercent, toPercent, progress), Percent);
-    }
-
-    float fromValue = from.isZero() ? 0 : from.value();
-    float toValue = isZero() ? 0 : value();
-    return Length(WebCore::blend(fromValue, toValue, progress), resultType);
-}
-
 TextStream& operator<<(TextStream&, Length);
 
 } // namespace WebCore
index 21b1a3f..f73cb55 100644 (file)
@@ -58,17 +58,17 @@ public:
     void setY(Length y) { m_y = WTFMove(y); }
     const Length& y() const { return m_y; }
 
-    LengthPoint blend(const LengthPoint& from, double progress) const
-    {
-        return LengthPoint(m_x.blend(from.x(), progress), m_y.blend(from.y(), progress));
-    }
-
 private:
     // FIXME: it would be nice to pack the two Lengths together better somehow (to avoid padding between them).
     Length m_x;
     Length m_y;
 };
 
+inline LengthPoint blend(const LengthPoint& from, const LengthPoint& to, double progress)
+{
+    return LengthPoint(blend(from.x(), to.x(), progress), blend(from.y(), to.y(), progress));
+}
+
 TextStream& operator<<(TextStream&, const LengthPoint&);
 
 } // namespace WebCore
index 0e486aa..d713e18 100644 (file)
@@ -48,16 +48,16 @@ public:
     void setHeight(Length height) { m_height = WTFMove(height); }
     const Length& height() const { return m_height; }
 
-    LengthSize blend(const LengthSize& from, double progress) const
-    {
-        return LengthSize(m_width.blend(from.width(), progress), m_height.blend(from.height(), progress));
-    }
-
 private:
     Length m_width;
     Length m_height;
 };
 
+inline LengthSize blend(const LengthSize& from, const LengthSize& to, double progress)
+{
+    return LengthSize(blend(from.width(), to.width(), progress), blend(from.height(), to.height(), progress));
+}
+
 TextStream& operator<<(TextStream&, const LengthSize&);
 
 } // namespace WebCore
index cc84d44..4c1704d 100644 (file)
@@ -162,11 +162,11 @@ PassRefPtr<FilterOperation> BlurFilterOperation::blend(const FilterOperation* fr
     LengthType lengthType = m_stdDeviation.type();
 
     if (blendToPassthrough)
-        return BlurFilterOperation::create(Length(lengthType).blend(m_stdDeviation, progress));
+        return BlurFilterOperation::create(WebCore::blend(m_stdDeviation, Length(lengthType), progress));
 
     const BlurFilterOperation* fromOperation = downcast<BlurFilterOperation>(from);
     Length fromLength = fromOperation ? fromOperation->m_stdDeviation : Length(lengthType);
-    return BlurFilterOperation::create(m_stdDeviation.blend(fromLength, progress));
+    return BlurFilterOperation::create(WebCore::blend(fromLength, m_stdDeviation, progress));
 }
     
 bool DropShadowFilterOperation::operator==(const FilterOperation& operation) const
index bb9fdce..0288084 100644 (file)
@@ -42,13 +42,13 @@ Ref<TransformOperation> TranslateTransformOperation::blend(const TransformOperat
 
     Length zeroLength(0, Fixed);
     if (blendToIdentity)
-        return TranslateTransformOperation::create(zeroLength.blend(m_x, progress), zeroLength.blend(m_y, progress), zeroLength.blend(m_z, progress), m_type);
+        return TranslateTransformOperation::create(WebCore::blend(m_x, zeroLength, progress), WebCore::blend(m_y, zeroLength, progress), WebCore::blend(m_z, zeroLength, progress), m_type);
 
     const TranslateTransformOperation* fromOp = downcast<TranslateTransformOperation>(from);
     Length fromX = fromOp ? fromOp->m_x : zeroLength;
     Length fromY = fromOp ? fromOp->m_y : zeroLength;
     Length fromZ = fromOp ? fromOp->m_z : zeroLength;
-    return TranslateTransformOperation::create(m_x.blend(fromX, progress), m_y.blend(fromY, progress), m_z.blend(fromZ, progress), m_type);
+    return TranslateTransformOperation::create(WebCore::blend(fromX, x(), progress), WebCore::blend(fromY, y(), progress), WebCore::blend(fromZ, z(), progress), m_type);
 }
 
 void TranslateTransformOperation::dump(TextStream& ts) const
index eafeff7..433366b 100644 (file)
@@ -319,8 +319,9 @@ Ref<BasicShape> BasicShapePolygon::blend(const BasicShape& other, double progres
     result->setWindRule(otherPolygon.windRule());
 
     for (size_t i = 0; i < length; i = i + 2) {
-        result->appendPoint(m_values.at(i).blend(otherPolygon.values().at(i), progress),
-            m_values.at(i + 1).blend(otherPolygon.values().at(i + 1), progress));
+        result->appendPoint(
+            WebCore::blend(otherPolygon.values().at(i), m_values.at(i), progress),
+            WebCore::blend(otherPolygon.values().at(i + 1), m_values.at(i + 1), progress));
     }
 
     return WTFMove(result);
@@ -411,21 +412,21 @@ bool BasicShapeInset::canBlend(const BasicShape& other) const
     return type() == other.type();
 }
 
-Ref<BasicShape> BasicShapeInset::blend(const BasicShape& other, double progress) const
+Ref<BasicShape> BasicShapeInset::blend(const BasicShape& from, double progress) const
 {
-    ASSERT(type() == other.type());
+    ASSERT(type() == from.type());
 
-    auto& otherInset = downcast<BasicShapeInset>(other);
+    auto& fromInset = downcast<BasicShapeInset>(from);
     auto result =  BasicShapeInset::create();
-    result->setTop(m_top.blend(otherInset.top(), progress));
-    result->setRight(m_right.blend(otherInset.right(), progress));
-    result->setBottom(m_bottom.blend(otherInset.bottom(), progress));
-    result->setLeft(m_left.blend(otherInset.left(), progress));
-
-    result->setTopLeftRadius(m_topLeftRadius.blend(otherInset.topLeftRadius(), progress));
-    result->setTopRightRadius(m_topRightRadius.blend(otherInset.topRightRadius(), progress));
-    result->setBottomRightRadius(m_bottomRightRadius.blend(otherInset.bottomRightRadius(), progress));
-    result->setBottomLeftRadius(m_bottomLeftRadius.blend(otherInset.bottomLeftRadius(), progress));
+    result->setTop(WebCore::blend(fromInset.top(), top(), progress));
+    result->setRight(WebCore::blend(fromInset.right(), right(), progress));
+    result->setBottom(WebCore::blend(fromInset.bottom(), bottom(), progress));
+    result->setLeft(WebCore::blend(fromInset.left(), left(), progress));
+
+    result->setTopLeftRadius(WebCore::blend(fromInset.topLeftRadius(), topLeftRadius(), progress));
+    result->setTopRightRadius(WebCore::blend(fromInset.topRightRadius(), topRightRadius(), progress));
+    result->setBottomRightRadius(WebCore::blend(fromInset.bottomRightRadius(), bottomRightRadius(), progress));
+    result->setBottomLeftRadius(WebCore::blend(fromInset.bottomLeftRadius(), bottomLeftRadius(), progress));
 
     return WTFMove(result);
 }
index e8c469a..5baf06e 100644 (file)
@@ -64,7 +64,7 @@ public:
     virtual WindRule windRule() const { return RULE_NONZERO; }
 
     virtual bool canBlend(const BasicShape&) const = 0;
-    virtual Ref<BasicShape> blend(const BasicShape&, double) const = 0;
+    virtual Ref<BasicShape> blend(const BasicShape& from, double) const = 0;
 
     virtual bool operator==(const BasicShape&) const = 0;
 };
@@ -101,9 +101,9 @@ public:
     const Length& length() const { return m_length; }
     const Length& computedLength() const { return m_computedLength; }
 
-    BasicShapeCenterCoordinate blend(const BasicShapeCenterCoordinate& other, double progress) const
+    BasicShapeCenterCoordinate blend(const BasicShapeCenterCoordinate& from, double progress) const
     {
-        return BasicShapeCenterCoordinate(TopLeft, m_computedLength.blend(other.m_computedLength, progress));
+        return BasicShapeCenterCoordinate(TopLeft, WebCore::blend(from.m_computedLength, m_computedLength, progress));
     }
     
     bool operator==(const BasicShapeCenterCoordinate& other) const
@@ -155,12 +155,12 @@ public:
         return m_type == Value && other.type() == Value;
     }
 
-    BasicShapeRadius blend(const BasicShapeRadius& other, double progress) const
+    BasicShapeRadius blend(const BasicShapeRadius& from, double progress) const
     {
-        if (m_type != Value || other.type() != Value)
-            return BasicShapeRadius(other);
+        if (m_type != Value || from.type() != Value)
+            return BasicShapeRadius(from);
 
-        return BasicShapeRadius(m_value.blend(other.value(), progress));
+        return BasicShapeRadius(WebCore::blend(from.value(), value(), progress));
     }
     
     bool operator==(const BasicShapeRadius& other) const
@@ -195,7 +195,7 @@ private:
     const Path& path(const FloatRect&) override;
 
     bool canBlend(const BasicShape&) const override;
-    Ref<BasicShape> blend(const BasicShape&, double) const override;
+    Ref<BasicShape> blend(const BasicShape& from, double) const override;
 
     bool operator==(const BasicShape&) const override;
 
@@ -227,7 +227,7 @@ private:
     const Path& path(const FloatRect&) override;
 
     bool canBlend(const BasicShape&) const override;
-    Ref<BasicShape> blend(const BasicShape&, double) const override;
+    Ref<BasicShape> blend(const BasicShape& from, double) const override;
 
     bool operator==(const BasicShape&) const override;
 
@@ -258,7 +258,7 @@ private:
     const Path& path(const FloatRect&) override;
 
     bool canBlend(const BasicShape&) const override;
-    Ref<BasicShape> blend(const BasicShape&, double) const override;
+    Ref<BasicShape> blend(const BasicShape& from, double) const override;
 
     bool operator==(const BasicShape&) const override;
 
@@ -286,7 +286,7 @@ private:
     const Path& path(const FloatRect&) override;
 
     bool canBlend(const BasicShape&) const override;
-    Ref<BasicShape> blend(const BasicShape&, double) const override;
+    Ref<BasicShape> blend(const BasicShape& from, double) const override;
 
     bool operator==(const BasicShape&) const override;
 
@@ -326,7 +326,7 @@ private:
     const Path& path(const FloatRect&) override;
 
     bool canBlend(const BasicShape&) const override;
-    Ref<BasicShape> blend(const BasicShape&, double) const override;
+    Ref<BasicShape> blend(const BasicShape& from, double) const override;
 
     bool operator==(const BasicShape&) const override;