GraphicsLayerTextureMapper.cpp [plain text]
#include "config.h"
#include "GraphicsLayerTextureMapper.h"
#include "TextureMapperLayer.h"
namespace WebCore {
GraphicsLayerTextureMapper::GraphicsLayerTextureMapper(GraphicsLayerClient* client)
: GraphicsLayer(client)
, m_layer(adoptPtr(new TextureMapperLayer()))
, m_changeMask(0)
, m_needsDisplay(false)
, m_fixedToViewport(false)
, m_contentsLayer(0)
, m_animationStartedTimer(this, &GraphicsLayerTextureMapper::animationStartedTimerFired)
{
}
void GraphicsLayerTextureMapper::notifyChange(TextureMapperLayer::ChangeMask changeMask)
{
m_changeMask |= changeMask;
if (!client())
return;
client()->notifySyncRequired(this);
}
void GraphicsLayerTextureMapper::didSynchronize()
{
m_syncQueued = false;
m_changeMask = 0;
m_needsDisplay = false;
m_needsDisplayRect = IntRect();
}
void GraphicsLayerTextureMapper::setName(const String& name)
{
GraphicsLayer::setName(name);
}
GraphicsLayerTextureMapper::~GraphicsLayerTextureMapper()
{
willBeDestroyed();
}
void GraphicsLayerTextureMapper::willBeDestroyed()
{
GraphicsLayer::willBeDestroyed();
}
void GraphicsLayerTextureMapper::setNeedsDisplay()
{
m_needsDisplay = true;
notifyChange(TextureMapperLayer::DisplayChange);
}
void GraphicsLayerTextureMapper::setContentsNeedsDisplay()
{
if (m_image)
setContentsToImage(m_image.get());
notifyChange(TextureMapperLayer::DisplayChange);
}
void GraphicsLayerTextureMapper::setNeedsDisplayInRect(const FloatRect& rect)
{
if (m_needsDisplay)
return;
m_needsDisplayRect.unite(rect);
notifyChange(TextureMapperLayer::DisplayChange);
}
void GraphicsLayerTextureMapper::setParent(GraphicsLayer* layer)
{
notifyChange(TextureMapperLayer::ParentChange);
GraphicsLayer::setParent(layer);
}
bool GraphicsLayerTextureMapper::setChildren(const Vector<GraphicsLayer*>& children)
{
notifyChange(TextureMapperLayer::ChildrenChange);
return GraphicsLayer::setChildren(children);
}
void GraphicsLayerTextureMapper::addChild(GraphicsLayer* layer)
{
notifyChange(TextureMapperLayer::ChildrenChange);
GraphicsLayer::addChild(layer);
}
void GraphicsLayerTextureMapper::addChildAtIndex(GraphicsLayer* layer, int index)
{
GraphicsLayer::addChildAtIndex(layer, index);
notifyChange(TextureMapperLayer::ChildrenChange);
}
void GraphicsLayerTextureMapper::addChildAbove(GraphicsLayer* layer, GraphicsLayer* sibling)
{
GraphicsLayer::addChildAbove(layer, sibling);
notifyChange(TextureMapperLayer::ChildrenChange);
}
void GraphicsLayerTextureMapper::addChildBelow(GraphicsLayer* layer, GraphicsLayer* sibling)
{
GraphicsLayer::addChildBelow(layer, sibling);
notifyChange(TextureMapperLayer::ChildrenChange);
}
bool GraphicsLayerTextureMapper::replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild)
{
if (GraphicsLayer::replaceChild(oldChild, newChild)) {
notifyChange(TextureMapperLayer::ChildrenChange);
return true;
}
return false;
}
void GraphicsLayerTextureMapper::removeFromParent()
{
if (!parent())
return;
notifyChange(TextureMapperLayer::ParentChange);
GraphicsLayer::removeFromParent();
}
void GraphicsLayerTextureMapper::setMaskLayer(GraphicsLayer* value)
{
if (value == maskLayer())
return;
GraphicsLayer::setMaskLayer(value);
notifyChange(TextureMapperLayer::MaskLayerChange);
}
void GraphicsLayerTextureMapper::setReplicatedByLayer(GraphicsLayer* value)
{
if (value == replicaLayer())
return;
GraphicsLayer::setReplicatedByLayer(value);
notifyChange(TextureMapperLayer::ReplicaLayerChange);
}
void GraphicsLayerTextureMapper::setPosition(const FloatPoint& value)
{
if (value == position())
return;
GraphicsLayer::setPosition(value);
notifyChange(TextureMapperLayer::PositionChange);
}
void GraphicsLayerTextureMapper::setAnchorPoint(const FloatPoint3D& value)
{
if (value == anchorPoint())
return;
GraphicsLayer::setAnchorPoint(value);
notifyChange(TextureMapperLayer::AnchorPointChange);
}
void GraphicsLayerTextureMapper::setSize(const FloatSize& value)
{
if (value == size())
return;
GraphicsLayer::setSize(value);
notifyChange(TextureMapperLayer::SizeChange);
}
void GraphicsLayerTextureMapper::setTransform(const TransformationMatrix& value)
{
if (value == transform())
return;
GraphicsLayer::setTransform(value);
notifyChange(TextureMapperLayer::TransformChange);
}
void GraphicsLayerTextureMapper::setChildrenTransform(const TransformationMatrix& value)
{
if (value == childrenTransform())
return;
GraphicsLayer::setChildrenTransform(value);
notifyChange(TextureMapperLayer::ChildrenTransformChange);
}
void GraphicsLayerTextureMapper::setPreserves3D(bool value)
{
if (value == preserves3D())
return;
GraphicsLayer::setPreserves3D(value);
notifyChange(TextureMapperLayer::Preserves3DChange);
}
void GraphicsLayerTextureMapper::setMasksToBounds(bool value)
{
if (value == masksToBounds())
return;
GraphicsLayer::setMasksToBounds(value);
notifyChange(TextureMapperLayer::MasksToBoundsChange);
}
void GraphicsLayerTextureMapper::setDrawsContent(bool value)
{
if (value == drawsContent())
return;
notifyChange(TextureMapperLayer::DrawsContentChange);
GraphicsLayer::setDrawsContent(value);
}
void GraphicsLayerTextureMapper::setContentsOpaque(bool value)
{
if (value == contentsOpaque())
return;
notifyChange(TextureMapperLayer::ContentsOpaqueChange);
GraphicsLayer::setContentsOpaque(value);
}
void GraphicsLayerTextureMapper::setBackfaceVisibility(bool value)
{
if (value == backfaceVisibility())
return;
GraphicsLayer::setBackfaceVisibility(value);
notifyChange(TextureMapperLayer::BackfaceVisibilityChange);
}
void GraphicsLayerTextureMapper::setOpacity(float value)
{
if (value == opacity())
return;
GraphicsLayer::setOpacity(value);
notifyChange(TextureMapperLayer::OpacityChange);
}
void GraphicsLayerTextureMapper::setContentsRect(const IntRect& value)
{
if (value == contentsRect())
return;
GraphicsLayer::setContentsRect(value);
notifyChange(TextureMapperLayer::ContentsRectChange);
}
void GraphicsLayerTextureMapper::setContentsToImage(Image* image)
{
if (image == m_image)
return;
m_image = image;
if (m_image) {
RefPtr<TextureMapperTiledBackingStore> backingStore = TextureMapperTiledBackingStore::create();
backingStore->setContentsToImage(image);
m_compositedImage = backingStore;
} else
m_compositedImage = 0;
setContentsToMedia(m_compositedImage.get());
notifyChange(TextureMapperLayer::ContentChange);
GraphicsLayer::setContentsToImage(image);
}
void GraphicsLayerTextureMapper::setContentsToMedia(TextureMapperPlatformLayer* media)
{
if (media == m_contentsLayer)
return;
GraphicsLayer::setContentsToMedia(media);
notifyChange(TextureMapperLayer::ContentChange);
m_contentsLayer = media;
}
void GraphicsLayerTextureMapper::syncCompositingStateForThisLayerOnly()
{
m_layer->syncCompositingState(this);
}
void GraphicsLayerTextureMapper::syncCompositingState(const FloatRect&)
{
m_layer->syncCompositingState(this, TextureMapperLayer::TraverseDescendants);
}
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;
bool listsMatch = false;
bool hasBigRotation;
if (valueList.property() == AnimatedPropertyWebkitTransform)
listsMatch = validateTransformOperations(valueList, hasBigRotation) >= 0;
m_animations.add(keyframesName, TextureMapperAnimation(valueList, boxSize, anim, timeOffset, listsMatch));
notifyChange(TextureMapperLayer::AnimationChange);
m_animationStartedTimer.startOneShot(0);
return true;
}
void GraphicsLayerTextureMapper::pauseAnimation(const String& animationName, double timeOffset)
{
m_animations.pause(animationName, timeOffset);
}
void GraphicsLayerTextureMapper::removeAnimation(const String& animationName)
{
m_animations.remove(animationName);
}
void GraphicsLayerTextureMapper::animationStartedTimerFired(Timer<GraphicsLayerTextureMapper>*)
{
client()->notifyAnimationStarted(this, WTF::currentTime());
}
PassOwnPtr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerClient* client)
{
if (s_graphicsLayerFactory)
return (*s_graphicsLayerFactory)(client);
return adoptPtr(new GraphicsLayerTextureMapper(client));
}
#if ENABLE(CSS_FILTERS)
bool GraphicsLayerTextureMapper::setFilters(const FilterOperations& filters)
{
notifyChange(TextureMapperLayer::FilterChange);
return GraphicsLayer::setFilters(filters);
}
#endif
}