GraphicsLayerClutter.h [plain text]
#ifndef GraphicsLayerClutter_h
#define GraphicsLayerClutter_h
#if USE(ACCELERATED_COMPOSITING)
#include "GraphicsLayer.h"
#include "GraphicsLayerClient.h"
#include "Image.h"
#include "ImageSource.h"
#include "PlatformClutterAnimation.h"
#include "PlatformClutterLayerClient.h"
#include <wtf/HashMap.h>
#include <wtf/HashSet.h>
#include <wtf/text/StringHash.h>
#include <clutter/clutter.h>
#include <wtf/gobject/GRefPtr.h>
typedef struct _GraphicsLayerActor GraphicsLayerActor;
namespace WebCore {
class TransformState;
typedef Vector<GRefPtr<GraphicsLayerActor> > GraphicsLayerActorList;
class GraphicsLayerClutter : public GraphicsLayer, public PlatformClutterLayerClient {
public:
enum LayerType { LayerTypeLayer, LayerTypeWebLayer, LayerTypeVideoLayer, LayerTypeTransformLayer, LayerTypeRootLayer, LayerTypeCustom };
GraphicsLayerClutter(GraphicsLayerClient*);
virtual ~GraphicsLayerClutter();
virtual ClutterActor* platformLayer() const;
virtual void addChild(GraphicsLayer*);
virtual void addChildAtIndex(GraphicsLayer*, int index);
virtual void addChildAbove(GraphicsLayer*, GraphicsLayer* sibling);
virtual void addChildBelow(GraphicsLayer*, GraphicsLayer* sibling);
virtual void removeFromParent();
virtual bool replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild);
virtual bool setChildren(const Vector<GraphicsLayer*>&);
virtual void setParent(GraphicsLayer*);
virtual void setDrawsContent(bool);
virtual void setAnchorPoint(const FloatPoint3D&);
virtual void setOpacity(float);
virtual void setPosition(const FloatPoint&);
virtual void setSize(const FloatSize&);
virtual void setTransform(const TransformationMatrix&);
virtual void setName(const String&);
virtual void setNeedsDisplay();
virtual void setNeedsDisplayInRect(const FloatRect&);
virtual void setContentsNeedsDisplay();
virtual void setContentsToImage(Image*);
virtual void setContentsRect(const IntRect&);
virtual bool hasContentsLayer() const { return m_contentsLayer; }
virtual void setPreserves3D(bool);
virtual void setMasksToBounds(bool);
virtual bool addAnimation(const KeyframeValueList&, const IntSize& boxSize, const Animation*, const String& animationName, double timeOffset);
virtual void removeAnimation(const String& animationName);
virtual void flushCompositingState(const FloatRect&);
virtual void flushCompositingStateForThisLayerOnly();
struct CommitState {
bool ancestorHasTransformAnimation;
CommitState()
: ancestorHasTransformAnimation(false)
{ }
};
void recursiveCommitChanges(const CommitState&, const TransformState&, float pageScaleFactor = 1, const FloatPoint& positionRelativeToBase = FloatPoint(), bool affectedByPageScale = false);
private:
FloatPoint computePositionRelativeToBase(float& pageScale) const;
bool animationIsRunning(const String& animationName) const
{
return m_runningAnimations.find(animationName) != m_runningAnimations.end();
}
void commitLayerChangesBeforeSublayers(float pageScaleFactor, const FloatPoint& positionRelativeToBase);
void commitLayerChangesAfterSublayers();
void updateOpacityOnLayer();
void setupContentsLayer(GraphicsLayerActor*);
GraphicsLayerActor* contentsLayer() const { return m_contentsLayer.get(); }
virtual void platformClutterLayerAnimationStarted(double beginTime);
virtual void platformClutterLayerPaintContents(GraphicsContext&, const IntRect& clip);
GraphicsLayerActor* primaryLayer() const { return m_structuralLayer.get() ? m_structuralLayer.get() : m_layer.get(); }
GraphicsLayerActor* layerForSuperlayer() const;
GraphicsLayerActor* animatedLayer(AnimatedPropertyID) const;
PassRefPtr<PlatformClutterAnimation> createBasicAnimation(const Animation*, const String& keyPath, bool additive);
PassRefPtr<PlatformClutterAnimation> createKeyframeAnimation(const Animation*, const String&, bool additive);
void setupAnimation(PlatformClutterAnimation*, const Animation*, bool additive);
const TimingFunction* timingFunctionForAnimationValue(const AnimationValue&, const Animation&);
bool setAnimationEndpoints(const KeyframeValueList&, const Animation*, PlatformClutterAnimation*);
bool setAnimationKeyframes(const KeyframeValueList&, const Animation*, PlatformClutterAnimation*);
void setAnimationOnLayer(PlatformClutterAnimation*, AnimatedPropertyID, const String& animationName, int index, double timeOffset);
bool removeClutterAnimationFromLayer(AnimatedPropertyID, const String& animationName, int index);
void pauseClutterAnimationOnLayer(AnimatedPropertyID, const String& animationName, int index, double timeOffset);
bool createAnimationFromKeyframes(const KeyframeValueList&, const Animation*, const String& animationName, double timeOffset);
bool createTransformAnimationsFromKeyframes(const KeyframeValueList&, const Animation*, const String& animationName, double timeOffset, const IntSize& boxSize);
bool setTransformAnimationEndpoints(const KeyframeValueList&, const Animation*, PlatformClutterAnimation*, int functionIndex, TransformOperation::OperationType, bool isMatrixAnimation, const IntSize& boxSize);
bool setTransformAnimationKeyframes(const KeyframeValueList&, const Animation*, PlatformClutterAnimation*, int functionIndex, TransformOperation::OperationType, bool isMatrixAnimation, const IntSize& boxSize);
enum MoveOrCopy { Move, Copy };
static void moveOrCopyLayerAnimation(MoveOrCopy, const String& animationIdentifier, GraphicsLayerActor* fromLayer, GraphicsLayerActor* toLayer);
void moveOrCopyAnimations(MoveOrCopy, GraphicsLayerActor* fromLayer, GraphicsLayerActor* toLayer);
bool appendToUncommittedAnimations(const KeyframeValueList&, const TransformOperations*, const Animation*, const String& animationName, const IntSize& boxSize, int animationIndex, double timeOffset, bool isMatrixAnimation);
enum LayerChange {
NoChange = 0,
NameChanged = 1 << 1,
ChildrenChanged = 1 << 2, GeometryChanged = 1 << 3,
TransformChanged = 1 << 4,
ChildrenTransformChanged = 1 << 5,
Preserves3DChanged = 1 << 6,
MasksToBoundsChanged = 1 << 7,
DrawsContentChanged = 1 << 8, BackgroundColorChanged = 1 << 9,
ContentsOpaqueChanged = 1 << 10,
BackfaceVisibilityChanged = 1 << 11,
OpacityChanged = 1 << 12,
AnimationChanged = 1 << 13,
DirtyRectsChanged = 1 << 14,
ContentsImageChanged = 1 << 15,
ContentsMediaLayerChanged = 1 << 16,
ContentsCanvasLayerChanged = 1 << 17,
ContentsColorLayerChanged = 1 << 18,
ContentsRectChanged = 1 << 19,
MaskLayerChanged = 1 << 20,
ReplicatedLayerChanged = 1 << 21,
ContentsNeedsDisplay = 1 << 22,
AcceleratesDrawingChanged = 1 << 23,
ContentsScaleChanged = 1 << 24,
ContentsVisibilityChanged = 1 << 25,
VisibleRectChanged = 1 << 26,
FiltersChanged = 1 << 27,
DebugIndicatorsChanged = 1 << 28
};
typedef unsigned LayerChangeFlags;
void noteLayerPropertyChanged(LayerChangeFlags);
void noteSublayersChanged();
void updateBackfaceVisibility();
void updateStructuralLayer();
void updateLayerNames();
void updateSublayerList();
void updateGeometry(float pixelAlignmentScale, const FloatPoint& positionRelativeToBase);
void updateTransform();
void updateMasksToBounds();
void updateLayerDrawsContent(float pixelAlignmentScale, const FloatPoint& positionRelativeToBase);
void updateContentsImage();
void updateContentsRect();
void updateContentsNeedsDisplay();
void updateAnimations();
enum StructuralLayerPurpose {
NoStructuralLayer = 0,
StructuralLayerForPreserves3D,
StructuralLayerForReplicaFlattening
};
void ensureStructuralLayer(StructuralLayerPurpose);
StructuralLayerPurpose structuralLayerPurpose() const;
void repaintLayerDirtyRects();
GRefPtr<GraphicsLayerActor> m_layer;
GRefPtr<GraphicsLayerActor> m_structuralLayer; GRefPtr<GraphicsLayerActor> m_contentsLayer; enum ContentsLayerPurpose {
NoContentsLayer = 0,
ContentsLayerForImage,
ContentsLayerForMedia,
ContentsLayerForCanvas,
ContentsLayerForBackgroundColor
};
ContentsLayerPurpose m_contentsLayerPurpose;
RefPtr<cairo_surface_t> m_pendingContentsImage;
Vector<FloatRect> m_dirtyRects;
LayerChangeFlags m_uncommittedChanges;
struct LayerPropertyAnimation {
LayerPropertyAnimation(PassRefPtr<PlatformClutterAnimation> caAnimation, const String& animationName, AnimatedPropertyID property, int index, double timeOffset)
: m_animation(caAnimation)
, m_name(animationName)
, m_property(property)
, m_index(index)
, m_timeOffset(timeOffset)
{ }
RefPtr<PlatformClutterAnimation> m_animation;
String m_name;
AnimatedPropertyID m_property;
int m_index;
double m_timeOffset;
};
Vector<LayerPropertyAnimation> m_uncomittedAnimations;
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_animationsToProcess;
typedef HashMap<String, Vector<LayerPropertyAnimation> > AnimationsMap;
AnimationsMap m_runningAnimations;
};
}
#endif // USE(ACCELERATED_COMPOSITING)
#endif // GraphicsLayerClutter_h