#ifndef GraphicsLayerCA_h
#define GraphicsLayerCA_h
#if USE(ACCELERATED_COMPOSITING)
#include "GraphicsLayer.h"
#include "StringHash.h"
#include <wtf/HashSet.h>
#include <wtf/RetainPtr.h>
@class CABasicAnimation;
@class CAKeyframeAnimation;
@class CALayer;
@class CAMediaTimingFunction;
@class CAPropertyAnimation;
@class WebAnimationDelegate;
@class WebLayer;
namespace WebCore {
class GraphicsLayerCA : public GraphicsLayer {
public:
GraphicsLayerCA(GraphicsLayerClient*);
virtual ~GraphicsLayerCA();
virtual void setName(const String&);
virtual NativeLayer nativeLayer() const;
virtual bool setChildren(const Vector<GraphicsLayer*>&);
virtual void addChild(GraphicsLayer*);
virtual void addChildAtIndex(GraphicsLayer*, int index);
virtual void addChildAbove(GraphicsLayer* layer, GraphicsLayer* sibling);
virtual void addChildBelow(GraphicsLayer* layer, GraphicsLayer* sibling);
virtual bool replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild);
virtual void removeFromParent();
virtual void setMaskLayer(GraphicsLayer*);
virtual void setPosition(const FloatPoint&);
virtual void setAnchorPoint(const FloatPoint3D&);
virtual void setSize(const FloatSize&);
virtual void setTransform(const TransformationMatrix&);
virtual void setChildrenTransform(const TransformationMatrix&);
virtual void setPreserves3D(bool);
virtual void setMasksToBounds(bool);
virtual void setDrawsContent(bool);
virtual void setBackgroundColor(const Color&);
virtual void clearBackgroundColor();
virtual void setContentsOpaque(bool);
virtual void setBackfaceVisibility(bool);
virtual void setOpacity(float);
virtual void setNeedsDisplay();
virtual void setNeedsDisplayInRect(const FloatRect&);
virtual void setContentsRect(const IntRect&);
virtual void suspendAnimations(double time);
virtual void resumeAnimations();
virtual bool addAnimation(const KeyframeValueList&, const IntSize& boxSize, const Animation*, const String& keyframesName, double timeOffset);
virtual void removeAnimationsForProperty(AnimatedPropertyID);
virtual void removeAnimationsForKeyframes(const String& keyframesName);
virtual void pauseAnimation(const String& keyframesName, double timeOffset);
virtual void setContentsToImage(Image*);
virtual void setContentsToMedia(PlatformLayer*);
virtual PlatformLayer* contentsLayerForMedia() const;
virtual PlatformLayer* platformLayer() const;
virtual void setContentsScale(float);
virtual void setDebugBackgroundColor(const Color&);
virtual void setDebugBorder(const Color&, float borderWidth);
virtual void setGeometryOrientation(CompositingCoordinatesOrientation);
void recursiveCommitChanges();
void commitLayerChanges();
virtual void syncCompositingState();
protected:
virtual void setOpacityInternal(float);
private:
void updateOpacityOnLayer();
WebLayer* primaryLayer() const { return m_transformLayer.get() ? m_transformLayer.get() : m_layer.get(); }
WebLayer* hostLayerForSublayers() const;
WebLayer* layerForSuperlayer() const;
CALayer* animatedLayer(AnimatedPropertyID property) const;
bool createAnimationFromKeyframes(const KeyframeValueList&, const Animation*, const String& keyframesName, double timeOffset);
bool createTransformAnimationsFromKeyframes(const KeyframeValueList&, const Animation*, const String& keyframesName, double timeOffset, const IntSize& boxSize);
CABasicAnimation* createBasicAnimation(const Animation*, AnimatedPropertyID, bool additive);
CAKeyframeAnimation* createKeyframeAnimation(const Animation*, AnimatedPropertyID, bool additive);
void setupAnimation(CAPropertyAnimation*, const Animation*, bool additive);
CAMediaTimingFunction* timingFunctionForAnimationValue(const AnimationValue*, const Animation*);
bool setAnimationEndpoints(const KeyframeValueList&, const Animation*, CABasicAnimation*);
bool setAnimationKeyframes(const KeyframeValueList&, const Animation*, CAKeyframeAnimation*);
bool setTransformAnimationEndpoints(const KeyframeValueList&, const Animation*, CABasicAnimation*, int functionIndex, TransformOperation::OperationType, bool isMatrixAnimation, const IntSize& boxSize);
bool setTransformAnimationKeyframes(const KeyframeValueList&, const Animation*, CAKeyframeAnimation*, int functionIndex, TransformOperation::OperationType, bool isMatrixAnimation, const IntSize& boxSize);
bool animationIsRunning(const String& keyframesName) const
{
return m_runningKeyframeAnimations.find(keyframesName) != m_runningKeyframeAnimations.end();
}
bool requiresTiledLayer(const FloatSize&) const;
void swapFromOrToTiledLayer(bool useTiledLayer);
CompositingCoordinatesOrientation defaultContentsOrientation() const;
void updateContentsTransform();
void setupContentsLayer(CALayer*);
CALayer* contentsLayer() const { return m_contentsLayer.get(); }
#if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
bool mediaLayerMustBeUpdatedOnMainThread() const;
#endif
void updateSublayerList();
void updateLayerPosition();
void updateLayerSize();
void updateAnchorPoint();
void updateTransform();
void updateChildrenTransform();
void updateMasksToBounds();
void updateContentsOpaque();
void updateBackfaceVisibility();
void updateLayerPreserves3D();
void updateLayerDrawsContent();
void updateLayerBackgroundColor();
void updateContentsImage();
void updateContentsMediaLayer();
void updateContentsRect();
void updateGeometryOrientation();
void updateMaskLayer();
void updateLayerAnimations();
void setAnimationOnLayer(CAPropertyAnimation*, AnimatedPropertyID, const String& keyframesName, int index, double timeOffset);
bool removeAnimationFromLayer(AnimatedPropertyID, const String& keyframesName, int index);
void pauseAnimationOnLayer(AnimatedPropertyID, const String& keyframesName, int index, double timeOffset);
void moveAnimationsForProperty(AnimatedPropertyID property, CALayer* fromLayer, CALayer* toLayer);
enum LayerChange {
NoChange = 0,
NameChanged = 1 << 1,
ChildrenChanged = 1 << 2, PositionChanged = 1 << 3,
AnchorPointChanged = 1 << 4,
SizeChanged = 1 << 5,
TransformChanged = 1 << 6,
ChildrenTransformChanged = 1 << 7,
Preserves3DChanged = 1 << 8,
MasksToBoundsChanged = 1 << 9,
DrawsContentChanged = 1 << 10, BackgroundColorChanged = 1 << 11,
ContentsOpaqueChanged = 1 << 12,
BackfaceVisibilityChanged = 1 << 13,
OpacityChanged = 1 << 14,
AnimationChanged = 1 << 15,
DirtyRectsChanged = 1 << 16,
ContentsImageChanged = 1 << 17,
ContentsMediaLayerChanged = 1 << 18,
ContentsRectChanged = 1 << 19,
GeometryOrientationChanged = 1 << 20,
MaskLayerChanged = 1 << 21
};
typedef unsigned LayerChangeFlags;
void noteLayerPropertyChanged(LayerChangeFlags flags);
void repaintLayerDirtyRects();
RetainPtr<WebLayer> m_layer;
RetainPtr<WebLayer> m_transformLayer;
RetainPtr<CALayer> m_contentsLayer;
enum ContentsLayerPurpose {
NoContentsLayer = 0,
ContentsLayerForImage,
ContentsLayerForMedia
};
ContentsLayerPurpose m_contentsLayerPurpose;
bool m_contentsLayerHasBackgroundColor : 1;
RetainPtr<WebAnimationDelegate> m_animationDelegate;
RetainPtr<CGImageRef> m_pendingContentsImage;
struct LayerAnimation {
LayerAnimation(CAPropertyAnimation* caAnim, const String& keyframesName, AnimatedPropertyID property, int index, double timeOffset)
: m_animation(caAnim)
, m_keyframesName(keyframesName)
, m_property(property)
, m_index(index)
, m_timeOffset(timeOffset)
{ }
RetainPtr<CAPropertyAnimation*> m_animation;
String m_keyframesName;
AnimatedPropertyID m_property;
int m_index;
double m_timeOffset;
};
Vector<LayerAnimation> m_uncomittedAnimations;
typedef int AnimatedProperty; typedef pair<AnimatedProperty, int> AnimationPair;
HashSet<AnimatedProperty> m_transitionPropertiesToRemove;
enum Action { Remove, Pause };
struct AnimationProcessingAction {
AnimationProcessingAction(Action action = Remove, double timeOffset = 0)
: action(action)
, timeOffset(timeOffset)
{
}
Action action;
double timeOffset; };
typedef HashMap<String, AnimationProcessingAction> AnimationsToProcessMap;
AnimationsToProcessMap m_keyframeAnimationsToProcess;
typedef HashMap<String, Vector<AnimationPair> > KeyframeAnimationsMap;
KeyframeAnimationsMap m_runningKeyframeAnimations;
Vector<FloatRect> m_dirtyRects;
LayerChangeFlags m_uncommittedChanges;
};
}
#endif // USE(ACCELERATED_COMPOSITING)
#endif // GraphicsLayerCA_h