PerspectiveTransformOperation.cpp [plain text]
#include "config.h"
#include "PerspectiveTransformOperation.h"
#include "AnimationUtilities.h"
#include "TextStream.h"
#include <wtf/MathExtras.h>
namespace WebCore {
bool PerspectiveTransformOperation::operator==(const TransformOperation& other) const
{
if (!isSameType(other))
return false;
return m_p == downcast<PerspectiveTransformOperation>(other).m_p;
}
Ref<TransformOperation> PerspectiveTransformOperation::blend(const TransformOperation* from, double progress, bool blendToIdentity)
{
if (from && !from->isSameType(*this))
return *this;
if (blendToIdentity) {
double p = floatValueForLength(m_p, 1);
p = WebCore::blend(p, 1.0, progress); return PerspectiveTransformOperation::create(Length(clampToPositiveInteger(p), Fixed));
}
const PerspectiveTransformOperation* fromOp = downcast<PerspectiveTransformOperation>(from);
Length fromP = fromOp ? fromOp->m_p : Length(m_p.type());
Length toP = m_p;
TransformationMatrix fromT;
TransformationMatrix toT;
fromT.applyPerspective(floatValueForLength(fromP, 1));
toT.applyPerspective(floatValueForLength(toP, 1));
toT.blend(fromT, progress);
TransformationMatrix::Decomposed4Type decomp;
toT.decompose4(decomp);
if (decomp.perspectiveZ) {
double val = -1.0 / decomp.perspectiveZ;
return PerspectiveTransformOperation::create(Length(clampToPositiveInteger(val), Fixed));
}
return PerspectiveTransformOperation::create(Length(0, Fixed));
}
void PerspectiveTransformOperation::dump(TextStream& ts) const
{
ts << type() << "(" << m_p << ")";
}
}