Share blend progress code

https://bugs.webkit.org/show_bug.cgi?id=74464

Reviewed by Dean Jackson.

Lots of places in the code had copies of the animation interpolation
logic "from + (to - from) * progress", in various forms.

Coalesce all these into calls to a few new inline functions in a new
AnimationUtilities.h header. Color and Length get their own blend fuctions
in their respective headers.

Covered by existing tests.

* GNUmakefile.list.am:
* Target.pri:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* css/CSSGradientValue.cpp:
* page/animation/AnimationBase.cpp:
(WebCore::blendFunc):
* platform/Length.h:
(WebCore::Length::blend):
* platform/animation/AnimationUtilities.h: Added.
(WebCore::blend):
* platform/graphics/Color.h:
(WebCore::blend):
* platform/graphics/transforms/PerspectiveTransformOperation.cpp:
(WebCore::PerspectiveTransformOperation::blend):
* platform/graphics/transforms/RotateTransformOperation.cpp:
(WebCore::RotateTransformOperation::blend):
* platform/graphics/transforms/ScaleTransformOperation.cpp:
(WebCore::ScaleTransformOperation::blend):
* platform/graphics/transforms/SkewTransformOperation.cpp:
(WebCore::SkewTransformOperation::blend):
* platform/graphics/transforms/TranslateTransformOperation.cpp:
(WebCore::TranslateTransformOperation::blend):
* svg/SVGLength.h:
(WebCore::SVGLength::blend):
* svg/SVGPathBlender.cpp:
(WebCore::blendFloatPoint):
(WebCore::SVGPathBlender::blendAnimatedDimensonalFloat):
(WebCore::SVGPathBlender::blendArcToSegment):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@102740 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent b1492450
2011-12-13 Simon Fraser <simon.fraser@apple.com>
Share blend progress code
https://bugs.webkit.org/show_bug.cgi?id=74464
Reviewed by Dean Jackson.
Lots of places in the code had copies of the animation interpolation
logic "from + (to - from) * progress", in various forms.
Coalesce all these into calls to a few new inline functions in a new
AnimationUtilities.h header. Color and Length get their own blend fuctions
in their respective headers.
Covered by existing tests.
* GNUmakefile.list.am:
* Target.pri:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* css/CSSGradientValue.cpp:
* page/animation/AnimationBase.cpp:
(WebCore::blendFunc):
* platform/Length.h:
(WebCore::Length::blend):
* platform/animation/AnimationUtilities.h: Added.
(WebCore::blend):
* platform/graphics/Color.h:
(WebCore::blend):
* platform/graphics/transforms/PerspectiveTransformOperation.cpp:
(WebCore::PerspectiveTransformOperation::blend):
* platform/graphics/transforms/RotateTransformOperation.cpp:
(WebCore::RotateTransformOperation::blend):
* platform/graphics/transforms/ScaleTransformOperation.cpp:
(WebCore::ScaleTransformOperation::blend):
* platform/graphics/transforms/SkewTransformOperation.cpp:
(WebCore::SkewTransformOperation::blend):
* platform/graphics/transforms/TranslateTransformOperation.cpp:
(WebCore::TranslateTransformOperation::blend):
* svg/SVGLength.h:
(WebCore::SVGLength::blend):
* svg/SVGPathBlender.cpp:
(WebCore::blendFloatPoint):
(WebCore::SVGPathBlender::blendAnimatedDimensonalFloat):
(WebCore::SVGPathBlender::blendArcToSegment):
2011-12-13 Mary Wu <mary.wu@torchmobile.com.cn>
Upstream 3 files into WebCore/platform/blackberry
......@@ -2460,6 +2460,7 @@ webcore_sources += \
Source/WebCore/platform/animation/Animation.h \
Source/WebCore/platform/animation/AnimationList.cpp \
Source/WebCore/platform/animation/AnimationList.h \
Source/WebCore/platform/animation/AnimationUtilities.h \
Source/WebCore/platform/animation/TimingFunction.h \
Source/WebCore/platform/Arena.cpp \
Source/WebCore/platform/Arena.h \
......
......@@ -2050,6 +2050,7 @@ HEADERS += \
page/WorkerNavigator.h \
platform/animation/Animation.h \
platform/animation/AnimationList.h \
platform/animation/AnimationUtilities.h \
platform/Arena.h \
platform/AsyncFileStream.h \
platform/Clock.h \
......
......@@ -730,6 +730,7 @@
'platform/WindowsKeyboardCodes.h',
'platform/animation/Animation.h',
'platform/animation/AnimationList.h',
'platform/animation/AnimationUtilities.h',
'platform/animation/TimingFunction.h',
'platform/cf/BinaryPropertyList.h',
'platform/cf/SchedulePair.h',
......
......@@ -32384,6 +32384,10 @@
RelativePath="..\platform\animation\AnimationList.h"
>
</File>
<File
RelativePath="..\platform\animation\AnimationUtilities.h"
>
</File>
<File
RelativePath="..\platform\animation\TimingFunction.h"
>
......@@ -243,6 +243,7 @@
0F580D000F12DE9B0051D689 /* RenderLayerBacking.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F580CFC0F12DE9B0051D689 /* RenderLayerBacking.cpp */; };
0F580FA31496939100FB5BD8 /* WebTileCacheLayer.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F580FA11496939100FB5BD8 /* WebTileCacheLayer.h */; };
0F580FA41496939100FB5BD8 /* WebTileCacheLayer.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F580FA21496939100FB5BD8 /* WebTileCacheLayer.mm */; };
0F580FAF149800D400FB5BD8 /* AnimationUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F580FAE149800D400FB5BD8 /* AnimationUtilities.h */; settings = {ATTRIBUTES = (Private, ); }; };
0F5B7A5410F65D7A00376302 /* RenderEmbeddedObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F5B7A5210F65D7A00376302 /* RenderEmbeddedObject.cpp */; };
0F5B7A5510F65D7A00376302 /* RenderEmbeddedObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F5B7A5310F65D7A00376302 /* RenderEmbeddedObject.h */; settings = {ATTRIBUTES = (Private, ); }; };
0F6ECD450F252F3700BDE271 /* CSSPropertyLonghand.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F6ECD430F252F3700BDE271 /* CSSPropertyLonghand.h */; };
......@@ -7326,6 +7327,7 @@
0F580CFC0F12DE9B0051D689 /* RenderLayerBacking.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderLayerBacking.cpp; sourceTree = "<group>"; };
0F580FA11496939100FB5BD8 /* WebTileCacheLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebTileCacheLayer.h; path = ca/mac/WebTileCacheLayer.h; sourceTree = "<group>"; };
0F580FA21496939100FB5BD8 /* WebTileCacheLayer.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WebTileCacheLayer.mm; path = ca/mac/WebTileCacheLayer.mm; sourceTree = "<group>"; };
0F580FAE149800D400FB5BD8 /* AnimationUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AnimationUtilities.h; path = animation/AnimationUtilities.h; sourceTree = "<group>"; };
0F5B7A5210F65D7A00376302 /* RenderEmbeddedObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderEmbeddedObject.cpp; sourceTree = "<group>"; };
0F5B7A5310F65D7A00376302 /* RenderEmbeddedObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderEmbeddedObject.h; sourceTree = "<group>"; };
0F6ECD430F252F3700BDE271 /* CSSPropertyLonghand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSPropertyLonghand.h; sourceTree = "<group>"; };
......@@ -15130,6 +15132,7 @@
49E912A60EFAC906009D0CAF /* Animation.h */,
49E912A70EFAC906009D0CAF /* AnimationList.cpp */,
49E912A80EFAC906009D0CAF /* AnimationList.h */,
0F580FAE149800D400FB5BD8 /* AnimationUtilities.h */,
49E912A90EFAC906009D0CAF /* TimingFunction.h */,
);
name = animation;
......@@ -24823,6 +24826,7 @@
F35AE5AC14925F5B004D5776 /* DOMWrapperVisitor.h in Headers */,
26C17A3E1491D2D400D12BA2 /* FileSystemIOS.h in Headers */,
0F580FA31496939100FB5BD8 /* WebTileCacheLayer.h in Headers */,
0F580FAF149800D400FB5BD8 /* AnimationUtilities.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -93,20 +93,6 @@ void CSSGradientValue::sortStopsIfNeeded()
}
}
static inline int blend(int from, int to, float progress)
{
return int(from + (to - from) * progress);
}
static inline Color blend(const Color& from, const Color& to, float progress)
{
// FIXME: when we interpolate gradients using premultiplied colors, this should also do premultiplication.
return Color(blend(from.red(), to.red(), progress),
blend(from.green(), to.green(), progress),
blend(from.blue(), to.blue(), progress),
blend(from.alpha(), to.alpha(), progress));
}
struct GradientStop {
Color color;
float offset;
......@@ -344,6 +330,7 @@ void CSSGradientValue::addStops(Gradient* gradient, RenderObject* renderer, Rend
float nextOffset = stops[firstZeroOrGreaterIndex].offset;
float interStopProportion = -prevOffset / (nextOffset - prevOffset);
// FIXME: when we interpolate gradients using premultiplied colors, this should do premultiplication.
Color blendedColor = blend(stops[firstZeroOrGreaterIndex - 1].color, stops[firstZeroOrGreaterIndex].color, interStopProportion);
// Clamp the positions to 0 and set the color.
......
......@@ -81,12 +81,12 @@ static inline double solveStepsFunction(int numSteps, bool stepAtStart, double t
static inline int blendFunc(const AnimationBase*, int from, int to, double progress)
{
return lround(from + (to - from) * progress);
return blend(from, to, progress);
}
static inline double blendFunc(const AnimationBase*, double from, double to, double progress)
{
return from + (to - from) * progress;
return blend(from, to, progress);
}
static inline float blendFunc(const AnimationBase*, float from, float to, double progress)
......@@ -94,23 +94,9 @@ static inline float blendFunc(const AnimationBase*, float from, float to, double
return narrowPrecisionToFloat(from + (to - from) * progress);
}
static inline Color blendFunc(const AnimationBase* anim, const Color& from, const Color& to, double progress)
static inline Color blendFunc(const AnimationBase*, const Color& from, const Color& to, double progress)
{
// We need to preserve the state of the valid flag at the end of the animation
if (progress == 1 && !to.isValid())
return Color();
// Contrary to the name, RGBA32 actually stores ARGB, so we can initialize Color directly from premultipliedARGBFromColor().
// Also, premultipliedARGBFromColor() bails on zero alpha, so special-case that.
Color premultFrom = from.alpha() ? premultipliedARGBFromColor(from) : 0;
Color premultTo = to.alpha() ? premultipliedARGBFromColor(to) : 0;
Color premultBlended(blendFunc(anim, premultFrom.red(), premultTo.red(), progress),
blendFunc(anim, premultFrom.green(), premultTo.green(), progress),
blendFunc(anim, premultFrom.blue(), premultTo.blue(), progress),
blendFunc(anim, premultFrom.alpha(), premultTo.alpha(), progress));
return Color(colorFromPremultipliedARGB(premultBlended.rgb()));
return blend(from, to, progress);
}
static inline Length blendFunc(const AnimationBase*, const Length& from, const Length& to, double progress)
......@@ -147,13 +133,13 @@ static inline PassOwnPtr<ShadowData> blendFunc(const AnimationBase* anim, const
if (from->style() != to->style())
return adoptPtr(new ShadowData(*to));
return adoptPtr(new ShadowData(blendFunc(anim, from->x(), to->x(), progress),
blendFunc(anim, from->y(), to->y(), progress),
blendFunc(anim, from->blur(), to->blur(), progress),
blendFunc(anim, from->spread(), to->spread(), progress),
return adoptPtr(new ShadowData(blend(from->x(), to->x(), progress),
blend(from->y(), to->y(), progress),
blend(from->blur(), to->blur(), progress),
blend(from->spread(), to->spread(), progress),
blendFunc(anim, from->style(), to->style(), progress),
from->isWebkitBoxShadow(),
blendFunc(anim, from->color(), to->color(), progress)));
blend(from->color(), to->color(), progress)));
}
static inline TransformOperations blendFunc(const AnimationBase* anim, const TransformOperations& from, const TransformOperations& to, double progress)
......
......@@ -22,6 +22,7 @@
#ifndef Length_h
#define Length_h
#include "AnimationUtilities.h"
#include <wtf/Assertions.h>
#include <wtf/FastAllocBase.h>
#include <wtf/Forward.h>
......@@ -201,7 +202,7 @@ public:
bool isIntrinsicOrAuto() const { return type() == Auto || type() == MinIntrinsic || type() == Intrinsic; }
bool isSpecified() const { return type() == Fixed || type() == Percent; }
Length blend(const Length& from, float progress) const
Length blend(const Length& from, double progress) const
{
// Blend two lengths to produce a new length that is in between them. Used for animation.
if (!from.isZero() && !isZero() && from.type() != type())
......@@ -217,12 +218,12 @@ public:
if (resultType == Percent) {
float fromPercent = from.isZero() ? 0 : from.percent();
float toPercent = isZero() ? 0 : percent();
return Length(fromPercent + (toPercent - fromPercent) * progress, Percent);
return Length(WebCore::blend(fromPercent, toPercent, progress), Percent);
}
float fromValue = from.isZero() ? 0 : from.value();
float toValue = isZero() ? 0 : value();
return Length(fromValue + (toValue - fromValue) * progress, resultType);
return Length(WebCore::blend(fromValue, toValue, progress), resultType);
}
private:
......
/*
* Copyright (C) 2011 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef AnimationUtilities_h
#define AnimationUtilities_h
#include <math.h>
namespace WebCore {
inline int blend(int from, int to, double progress)
{
return lround(from + (to - from) * progress);
}
inline double blend(double from, double to, double progress)
{
return from + (to - from) * progress;
}
inline float blend(float from, float to, double progress)
{
return static_cast<float>(from + (to - from) * progress);
}
} // namespace WebCore
#endif // AnimationUtilities_h
......@@ -26,6 +26,7 @@
#ifndef Color_h
#define Color_h
#include "AnimationUtilities.h"
#include <wtf/FastAllocBase.h>
#include <wtf/Forward.h>
#include <wtf/unicode/Unicode.h>
......@@ -172,6 +173,32 @@ inline bool operator!=(const Color& a, const Color& b)
Color colorFromPremultipliedARGB(unsigned);
unsigned premultipliedARGBFromColor(const Color&);
inline Color blend(const Color& from, const Color& to, double progress, bool blendPremultiplied = true)
{
// We need to preserve the state of the valid flag at the end of the animation
if (progress == 1 && !to.isValid())
return Color();
if (blendPremultiplied) {
// Contrary to the name, RGBA32 actually stores ARGB, so we can initialize Color directly from premultipliedARGBFromColor().
// Also, premultipliedARGBFromColor() bails on zero alpha, so special-case that.
Color premultFrom = from.alpha() ? premultipliedARGBFromColor(from) : 0;
Color premultTo = to.alpha() ? premultipliedARGBFromColor(to) : 0;
Color premultBlended(blend(premultFrom.red(), premultTo.red(), progress),
blend(premultFrom.green(), premultTo.green(), progress),
blend(premultFrom.blue(), premultTo.blue(), progress),
blend(premultFrom.alpha(), premultTo.alpha(), progress));
return Color(colorFromPremultipliedARGB(premultBlended.rgb()));
}
return Color(blend(from.red(), to.red(), progress),
blend(from.green(), to.green(), progress),
blend(from.blue(), to.blue(), progress),
blend(from.alpha(), to.alpha(), progress));
}
#if USE(CG)
CGColorRef cachedCGColor(const Color&, ColorSpace);
#endif
......
......@@ -26,6 +26,7 @@
#include "config.h"
#include "PerspectiveTransformOperation.h"
#include "AnimationUtilities.h"
#include <wtf/MathExtras.h>
using namespace std;
......@@ -39,7 +40,7 @@ PassRefPtr<TransformOperation> PerspectiveTransformOperation::blend(const Transf
if (blendToIdentity) {
double p = m_p.calcFloatValue(1);
p = p + (1. - p) * progress; // FIXME: this seems wrong. https://bugs.webkit.org/show_bug.cgi?id=52700
p = WebCore::blend(p, 1.0, progress); // FIXME: this seems wrong. https://bugs.webkit.org/show_bug.cgi?id=52700
return PerspectiveTransformOperation::create(Length(clampToPositiveInteger(p), Fixed));
}
......
......@@ -22,6 +22,7 @@
#include "config.h"
#include "RotateTransformOperation.h"
#include "AnimationUtilities.h"
#include <algorithm>
#include <wtf/MathExtras.h>
......@@ -47,7 +48,7 @@ PassRefPtr<TransformOperation> RotateTransformOperation::blend(const TransformOp
return RotateTransformOperation::create(fromOp ? fromOp->m_x : m_x,
fromOp ? fromOp->m_y : m_y,
fromOp ? fromOp->m_z : m_z,
fromAngle + (m_angle - fromAngle) * progress, m_type);
WebCore::blend(fromAngle, m_angle, progress), m_type);
}
const RotateTransformOperation* toOp = this;
......
......@@ -22,6 +22,8 @@
#include "config.h"
#include "ScaleTransformOperation.h"
#include "AnimationUtilities.h"
namespace WebCore {
PassRefPtr<TransformOperation> ScaleTransformOperation::blend(const TransformOperation* from, double progress, bool blendToIdentity)
......@@ -30,17 +32,17 @@ PassRefPtr<TransformOperation> ScaleTransformOperation::blend(const TransformOpe
return this;
if (blendToIdentity)
return ScaleTransformOperation::create(m_x + (1. - m_x) * progress,
m_y + (1. - m_y) * progress,
m_z + (1. - m_z) * progress, m_type);
return ScaleTransformOperation::create(WebCore::blend(m_x, 1.0, progress),
WebCore::blend(m_y, 1.0, progress),
WebCore::blend(m_z, 1.0, progress), m_type);
const ScaleTransformOperation* fromOp = static_cast<const ScaleTransformOperation*>(from);
double fromX = fromOp ? fromOp->m_x : 1.;
double fromY = fromOp ? fromOp->m_y : 1.;
double fromZ = fromOp ? fromOp->m_z : 1.;
return ScaleTransformOperation::create(fromX + (m_x - fromX) * progress,
fromY + (m_y - fromY) * progress,
fromZ + (m_z - fromZ) * progress, m_type);
double fromX = fromOp ? fromOp->m_x : 1.0;
double fromY = fromOp ? fromOp->m_y : 1.0;
double fromZ = fromOp ? fromOp->m_z : 1.0;
return ScaleTransformOperation::create(WebCore::blend(fromX, m_x, progress),
WebCore::blend(fromY, m_y, progress),
WebCore::blend(fromZ, m_z, progress), m_type);
}
} // namespace WebCore
......@@ -22,6 +22,8 @@
#include "config.h"
#include "SkewTransformOperation.h"
#include "AnimationUtilities.h"
namespace WebCore {
PassRefPtr<TransformOperation> SkewTransformOperation::blend(const TransformOperation* from, double progress, bool blendToIdentity)
......@@ -30,12 +32,12 @@ PassRefPtr<TransformOperation> SkewTransformOperation::blend(const TransformOper
return this;
if (blendToIdentity)
return SkewTransformOperation::create(m_angleX - m_angleX * progress, m_angleY - m_angleY * progress, m_type);
return SkewTransformOperation::create(WebCore::blend(m_angleX, 0.0, progress), WebCore::blend(m_angleY, 0.0, progress), m_type);
const SkewTransformOperation* fromOp = static_cast<const SkewTransformOperation*>(from);
double fromAngleX = fromOp ? fromOp->m_angleX : 0;
double fromAngleY = fromOp ? fromOp->m_angleY : 0;
return SkewTransformOperation::create(fromAngleX + (m_angleX - fromAngleX) * progress, fromAngleY + (m_angleY - fromAngleY) * progress, m_type);
return SkewTransformOperation::create(WebCore::blend(fromAngleX, m_angleX, progress), WebCore::blend(fromAngleY, m_angleY, progress), m_type);
}
} // namespace WebCore
......@@ -31,15 +31,15 @@ PassRefPtr<TransformOperation> TranslateTransformOperation::blend(const Transfor
return this;
if (blendToIdentity)
return TranslateTransformOperation::create(Length(m_x.type()).blend(m_x, narrowPrecisionToFloat(progress)),
Length(m_y.type()).blend(m_y, narrowPrecisionToFloat(progress)),
Length(m_z.type()).blend(m_z, narrowPrecisionToFloat(progress)), m_type);
return TranslateTransformOperation::create(Length(m_x.type()).blend(m_x, progress),
Length(m_y.type()).blend(m_y, progress),
Length(m_z.type()).blend(m_z, progress), m_type);
const TranslateTransformOperation* fromOp = static_cast<const TranslateTransformOperation*>(from);
Length fromX = fromOp ? fromOp->m_x : Length(m_x.type());
Length fromY = fromOp ? fromOp->m_y : Length(m_y.type());
Length fromZ = fromOp ? fromOp->m_z : Length(m_z.type());
return TranslateTransformOperation::create(m_x.blend(fromX, narrowPrecisionToFloat(progress)), m_y.blend(fromY, narrowPrecisionToFloat(progress)), m_z.blend(fromZ, narrowPrecisionToFloat(progress)), m_type);
return TranslateTransformOperation::create(m_x.blend(fromX, progress), m_y.blend(fromY, progress), m_z.blend(fromZ, progress), m_type);
}
} // namespace WebCore
......@@ -22,6 +22,7 @@
#define SVGLength_h
#if ENABLE(SVG)
#include "AnimationUtilities.h"
#include "SVGLengthContext.h"
#include "SVGParsingError.h"
#include "SVGPropertyTraits.h"
......@@ -118,7 +119,7 @@ public:
if (fromType == LengthTypePercentage || toType == LengthTypePercentage) {
float fromPercent = from.valueAsPercentage() * 100;
float toPercent = valueAsPercentage() * 100;
length.newValueSpecifiedUnits(LengthTypePercentage, fromPercent + (toPercent - fromPercent) * progress, ec);
length.newValueSpecifiedUnits(LengthTypePercentage, WebCore::blend(fromPercent, toPercent, progress), ec);
if (ec)
return SVGLength();
return length;
......@@ -128,9 +129,9 @@ public:
float fromValue = from.valueInSpecifiedUnits();
float toValue = valueInSpecifiedUnits();
if (isZero())
length.newValueSpecifiedUnits(fromType, fromValue + (toValue - fromValue) * progress, ec);
length.newValueSpecifiedUnits(fromType, WebCore::blend(fromValue, toValue, progress), ec);
else
length.newValueSpecifiedUnits(toType, fromValue + (toValue - fromValue) * progress, ec);
length.newValueSpecifiedUnits(toType, WebCore::blend(fromValue, toValue, progress), ec);
if (ec)
return SVGLength();
return length;
......@@ -149,7 +150,7 @@ public:
return SVGLength();
float toValue = valueInSpecifiedUnits();
length.newValueSpecifiedUnits(toType, fromValue + (toValue - fromValue) * progress, ec);
length.newValueSpecifiedUnits(toType, WebCore::blend(fromValue, toValue, progress), ec);
if (ec)
return SVGLength();
......
......@@ -22,6 +22,7 @@
#if ENABLE(SVG)
#include "SVGPathBlender.h"
#include "AnimationUtilities.h"
#include "SVGPathSeg.h"
namespace WebCore {
......@@ -37,30 +38,25 @@ SVGPathBlender::SVGPathBlender()
// Helper functions
static inline FloatPoint blendFloatPoint(const FloatPoint& a, const FloatPoint& b, float progress)
{
return FloatPoint((b.x() - a.x()) * progress + a.x(), (b.y() - a.y()) * progress + a.y());
}
static inline float blendAnimatedFloat(float from, float to, float progress)
{
return (to - from) * progress + from;
return FloatPoint(blend(a.x(), b.x(), progress), blend(a.y(), b.y(), progress));
}
float SVGPathBlender::blendAnimatedDimensonalFloat(float from, float to, FloatBlendMode blendMode)
{
if (m_fromMode == m_toMode)
return blendAnimatedFloat(from, to, m_progress);
return blend(from, to, m_progress);
float fromValue = blendMode == BlendHorizontal ? m_fromCurrentPoint.x() : m_fromCurrentPoint.y();
float toValue = blendMode == BlendHorizontal ? m_toCurrentPoint.x() : m_toCurrentPoint.y();
// Transform toY to the coordinate mode of fromY
float animValue = blendAnimatedFloat(from, m_fromMode == AbsoluteCoordinates ? to + toValue : to - toValue, m_progress);
float animValue = blend(from, m_fromMode == AbsoluteCoordinates ? to + toValue : to - toValue, m_progress);
if (m_isInFirstHalfOfAnimation)
return animValue;
// Transform the animated point to the coordinate mode, needed for the current progress.
float currentValue = blendAnimatedFloat(fromValue, toValue, m_progress);
float currentValue = blend(fromValue, toValue, m_progress);
return m_toMode == AbsoluteCoordinates ? animValue + currentValue : animValue - currentValue;
}
......@@ -235,9 +231,9 @@ bool SVGPathBlender::blendArcToSegment()
|| !m_toSource->parseArcToSegment(toRx, toRy, toAngle, toLargeArc, toSweep, toTargetPoint))
return false;
m_consumer->arcTo(blendAnimatedFloat(fromRx, toRx, m_progress),
blendAnimatedFloat(fromRy, toRy, m_progress),
blendAnimatedFloat(fromAngle, toAngle, m_progress),
m_consumer->arcTo(blend(fromRx, toRx, m_progress),
blend(fromRy, toRy, m_progress),
blend(fromAngle, toAngle, m_progress),
m_isInFirstHalfOfAnimation ? fromLargeArc : toLargeArc,
m_isInFirstHalfOfAnimation ? fromSweep : toSweep,
blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint),
......
......@@ -51,6 +51,7 @@ SET(DumpRenderTree_INCLUDE_DIRECTORIES
${WEBCORE_DIR}/page
${WEBCORE_DIR}/page/animation
${WEBCORE_DIR}/platform
${WEBCORE_DIR}/platform/animation
${WEBCORE_DIR}/platform/text
${WEBCORE_DIR}/platform/graphics
${WEBCORE_DIR}/platform/graphics/cairo
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment