GraphicsLayerTextureMapper.cpp [plain text]
#include "config.h"
#include "GraphicsLayerTextureMapper.h"
#include "TextureMapperNode.h"
namespace WebCore {
GraphicsLayerTextureMapper::GraphicsLayerTextureMapper(GraphicsLayerClient* client)
: GraphicsLayer(client)
, m_node(adoptPtr(new TextureMapperNode()))
, m_changeMask(0)
, m_animationStartedTimer(this, &GraphicsLayerTextureMapper::animationStartedTimerFired)
{
}
void GraphicsLayerTextureMapper::notifyChange(TextureMapperNode::ChangeMask changeMask)
{
m_changeMask |= changeMask;
if (!client())
return;
client()->notifySyncRequired(this);
}
void GraphicsLayerTextureMapper::didSynchronize()
{
m_syncQueued = false;
m_changeMask = 0;
m_pendingContent.needsDisplay = false;
m_pendingContent.needsDisplayRect = IntRect();
}
void GraphicsLayerTextureMapper::setName(const String& name)
{
GraphicsLayer::setName(name);
}
GraphicsLayerTextureMapper::~GraphicsLayerTextureMapper()
{
}
void GraphicsLayerTextureMapper::setNeedsDisplay()
{
m_pendingContent.needsDisplay = true;
notifyChange(TextureMapperNode::DisplayChange);
}
void GraphicsLayerTextureMapper::setNeedsDisplayInRect(const FloatRect& rect)
{
if (m_pendingContent.needsDisplay)
return;
m_pendingContent.needsDisplayRect.unite(rect);
notifyChange(TextureMapperNode::DisplayChange);
}
void GraphicsLayerTextureMapper::setParent(GraphicsLayer* layer)
{
notifyChange(TextureMapperNode::ParentChange);
GraphicsLayer::setParent(layer);
}
bool GraphicsLayerTextureMapper::setChildren(const Vector<GraphicsLayer*>& children)
{
notifyChange(TextureMapperNode::ChildrenChange);
return GraphicsLayer::setChildren(children);
}
void GraphicsLayerTextureMapper::addChild(GraphicsLayer* layer)
{
notifyChange(TextureMapperNode::ChildrenChange);
GraphicsLayer::addChild(layer);
}
void GraphicsLayerTextureMapper::addChildAtIndex(GraphicsLayer* layer, int index)
{
GraphicsLayer::addChildAtIndex(layer, index);
notifyChange(TextureMapperNode::ChildrenChange);
}
void GraphicsLayerTextureMapper::addChildAbove(GraphicsLayer* layer, GraphicsLayer* sibling)
{
GraphicsLayer::addChildAbove(layer, sibling);
notifyChange(TextureMapperNode::ChildrenChange);
}
void GraphicsLayerTextureMapper::addChildBelow(GraphicsLayer* layer, GraphicsLayer* sibling)
{
GraphicsLayer::addChildBelow(layer, sibling);
notifyChange(TextureMapperNode::ChildrenChange);
}
bool GraphicsLayerTextureMapper::replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild)
{
if (GraphicsLayer::replaceChild(oldChild, newChild)) {
notifyChange(TextureMapperNode::ChildrenChange);
return true;
}
return false;
}
void GraphicsLayerTextureMapper::removeFromParent()
{
if (!parent())
return;
notifyChange(TextureMapperNode::ParentChange);
GraphicsLayer::removeFromParent();
}
void GraphicsLayerTextureMapper::setMaskLayer(GraphicsLayer* value)
{
if (value == maskLayer())
return;
GraphicsLayer::setMaskLayer(value);
notifyChange(TextureMapperNode::MaskLayerChange);
}
void GraphicsLayerTextureMapper::setReplicatedByLayer(GraphicsLayer* value)
{
if (value == replicaLayer())
return;
GraphicsLayer::setReplicatedByLayer(value);
notifyChange(TextureMapperNode::ReplicaLayerChange);
}
void GraphicsLayerTextureMapper::setPosition(const FloatPoint& value)
{
if (value == position())
return;
GraphicsLayer::setPosition(value);
notifyChange(TextureMapperNode::PositionChange);
}
void GraphicsLayerTextureMapper::setAnchorPoint(const FloatPoint3D& value)
{
if (value == anchorPoint())
return;
GraphicsLayer::setAnchorPoint(value);
notifyChange(TextureMapperNode::AnchorPointChange);
}
void GraphicsLayerTextureMapper::setSize(const FloatSize& value)
{
if (value == size())
return;
GraphicsLayer::setSize(value);
notifyChange(TextureMapperNode::SizeChange);
}
void GraphicsLayerTextureMapper::setTransform(const TransformationMatrix& value)
{
if (value == transform())
return;
GraphicsLayer::setTransform(value);
notifyChange(TextureMapperNode::TransformChange);
}
void GraphicsLayerTextureMapper::setChildrenTransform(const TransformationMatrix& value)
{
if (value == childrenTransform())
return;
GraphicsLayer::setChildrenTransform(value);
notifyChange(TextureMapperNode::ChildrenTransformChange);
}
void GraphicsLayerTextureMapper::setPreserves3D(bool value)
{
if (value == preserves3D())
return;
GraphicsLayer::setPreserves3D(value);
notifyChange(TextureMapperNode::Preserves3DChange);
}
void GraphicsLayerTextureMapper::setMasksToBounds(bool value)
{
if (value == masksToBounds())
return;
GraphicsLayer::setMasksToBounds(value);
notifyChange(TextureMapperNode::MasksToBoundsChange);
}
void GraphicsLayerTextureMapper::setDrawsContent(bool value)
{
if (value == drawsContent())
return;
notifyChange(TextureMapperNode::DrawsContentChange);
GraphicsLayer::setDrawsContent(value);
}
void GraphicsLayerTextureMapper::setBackgroundColor(const Color& value)
{
if (value == m_pendingContent.backgroundColor)
return;
m_pendingContent.backgroundColor = value;
GraphicsLayer::setBackgroundColor(value);
notifyChange(TextureMapperNode::BackgroundColorChange);
}
void GraphicsLayerTextureMapper::clearBackgroundColor()
{
if (!m_pendingContent.backgroundColor.isValid())
return;
m_pendingContent.backgroundColor = Color();
GraphicsLayer::clearBackgroundColor();
notifyChange(TextureMapperNode::BackgroundColorChange);
}
void GraphicsLayerTextureMapper::setContentsOpaque(bool value)
{
if (value == contentsOpaque())
return;
notifyChange(TextureMapperNode::ContentsOpaqueChange);
GraphicsLayer::setContentsOpaque(value);
}
void GraphicsLayerTextureMapper::setBackfaceVisibility(bool value)
{
if (value == backfaceVisibility())
return;
GraphicsLayer::setBackfaceVisibility(value);
notifyChange(TextureMapperNode::BackfaceVisibilityChange);
}
void GraphicsLayerTextureMapper::setOpacity(float value)
{
if (value == opacity())
return;
GraphicsLayer::setOpacity(value);
notifyChange(TextureMapperNode::OpacityChange);
}
void GraphicsLayerTextureMapper::setContentsRect(const IntRect& value)
{
if (value == contentsRect())
return;
GraphicsLayer::setContentsRect(value);
notifyChange(TextureMapperNode::ContentsRectChange);
}
void GraphicsLayerTextureMapper::setContentsToImage(Image* image)
{
notifyChange(TextureMapperNode::ContentChange);
m_pendingContent.contentType = image ? TextureMapperNode::DirectImageContentType : TextureMapperNode::HTMLContentType;
m_pendingContent.image = image;
GraphicsLayer::setContentsToImage(image);
}
void GraphicsLayerTextureMapper::setContentsToMedia(TextureMapperPlatformLayer* media)
{
GraphicsLayer::setContentsToMedia(media);
notifyChange(TextureMapperNode::ContentChange);
m_pendingContent.contentType = media ? TextureMapperNode::MediaContentType : TextureMapperNode::HTMLContentType;
m_pendingContent.media = media;
}
void GraphicsLayerTextureMapper::syncCompositingStateForThisLayerOnly()
{
m_node->syncCompositingState(this);
}
void GraphicsLayerTextureMapper::syncCompositingState()
{
m_node->syncCompositingState(this, TextureMapperNode::TraverseDescendants);
}
PlatformLayer* GraphicsLayerTextureMapper::platformLayer() const
{
return const_cast<TextureMapperPlatformLayer*>(node()->media());
}
PassOwnPtr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerClient* client)
{
return adoptPtr(new GraphicsLayerTextureMapper(client));
}
bool GraphicsLayerTextureMapper::addAnimation(const KeyframeValueList& valueList, const IntSize& boxSize, const Animation* anim, const String& keyframesName, double timeOffset)
{
ASSERT(!keyframesName.isEmpty());
if (!anim || anim->isEmptyOrZeroDuration() || valueList.size() < 2 || (valueList.property() != AnimatedPropertyWebkitTransform && valueList.property() != AnimatedPropertyOpacity))
return false;
for (size_t i = 0; i < m_animations.size(); ++i) {
if (m_animations[i]->name != keyframesName || m_animations[i]->keyframes.property() != valueList.property())
continue;
RefPtr<TextureMapperAnimation>& animation = m_animations[i];
animation->animation = Animation::create(anim);
animation->paused = false;
animation->startTime = WTF::currentTime() - timeOffset;
notifyChange(TextureMapperNode::AnimationChange);
m_animationStartedTimer.startOneShot(0);
return true;
}
RefPtr<TextureMapperAnimation> animation = TextureMapperAnimation::create(valueList);
animation->boxSize = boxSize;
animation->name = keyframesName;
animation->animation = Animation::create(anim);
animation->paused = false;
animation->startTime = WTF::currentTime() - timeOffset;
if (valueList.property() == AnimatedPropertyWebkitTransform) {
bool hasBigRotation; fetchTransformOperationList(valueList, animation->functionList, animation->listsMatch, hasBigRotation);
}
m_animations.append(animation);
notifyChange(TextureMapperNode::AnimationChange);
m_animationStartedTimer.startOneShot(0);
return true;
}
void GraphicsLayerTextureMapper::pauseAnimation(const String& animationName, double timeOffset)
{
for (size_t i = 0; i < m_animations.size(); ++i) {
if (m_animations[i]->name != animationName)
continue;
m_animations[i]->paused = true;
notifyChange(TextureMapperNode::AnimationChange);
}
}
void GraphicsLayerTextureMapper::removeAnimation(const String& animationName)
{
for (int i = m_animations.size() - 1; i >= 0; --i) {
if (m_animations[i]->name != animationName)
continue;
m_animations.remove(i);
notifyChange(TextureMapperNode::AnimationChange);
}
}
void GraphicsLayerTextureMapper::animationStartedTimerFired(Timer<GraphicsLayerTextureMapper>*)
{
client()->notifyAnimationStarted(this, WTF::currentTime());
}
}