GraphicsLayerTransform.cpp [plain text]
#include "config.h"
#include "GraphicsLayerTransform.h"
namespace WebCore {
GraphicsLayerTransform::GraphicsLayerTransform()
: m_anchorPoint(0.5, 0.5, 0)
, m_flattening(true)
, m_dirty(false) , m_childrenDirty(false)
{
}
void GraphicsLayerTransform::setPosition(const FloatPoint& position)
{
if (m_position == position)
return;
m_position = position;
m_dirty = true;
}
void GraphicsLayerTransform::setSize(const FloatSize& size)
{
if (m_size == size)
return;
m_size = size;
m_dirty = true;
}
void GraphicsLayerTransform::setAnchorPoint(const FloatPoint3D& anchorPoint)
{
if (m_anchorPoint == anchorPoint)
return;
m_anchorPoint = anchorPoint;
m_dirty = true;
}
void GraphicsLayerTransform::setFlattening(bool flattening)
{
if (m_flattening == flattening)
return;
m_flattening = flattening;
m_dirty = true;
}
void GraphicsLayerTransform::setLocalTransform(const TransformationMatrix& transform)
{
if (m_local == transform)
return;
m_local = transform;
m_dirty = true;
}
void GraphicsLayerTransform::setChildrenTransform(const TransformationMatrix& transform)
{
if (m_children == transform)
return;
m_children = transform;
m_dirty = true;
}
TransformationMatrix GraphicsLayerTransform::combined()
{
ASSERT(!m_dirty);
return m_combined;
}
TransformationMatrix GraphicsLayerTransform::combinedForChildren()
{
ASSERT(!m_dirty);
if (m_childrenDirty)
combineTransformsForChildren();
return m_combinedForChildren;
}
void GraphicsLayerTransform::combineTransforms(const TransformationMatrix& parentTransform)
{
float originX = m_anchorPoint.x() * m_size.width();
float originY = m_anchorPoint.y() * m_size.height();
m_combined =
TransformationMatrix(parentTransform)
.translate3d(originX + m_position.x(), originY + m_position.y(), m_anchorPoint.z() )
.multiply(m_local);
m_combinedForChildren = m_combined;
m_combined.translate3d(-originX, -originY, -m_anchorPoint.z());
m_dirty = false;
m_childrenDirty = true;
}
void GraphicsLayerTransform::combineTransformsForChildren()
{
ASSERT(!m_dirty);
ASSERT(m_childrenDirty);
float originX = m_anchorPoint.x() * m_size.width();
float originY = m_anchorPoint.y() * m_size.height();
if (m_flattening)
m_combinedForChildren = m_combinedForChildren.to2dTransform();
m_combinedForChildren.multiply(m_children);
m_combinedForChildren.translate3d(-originX, -originY, -m_anchorPoint.z());
m_childrenDirty = false;
}
}