#ifndef GraphicsLayer_h
#define GraphicsLayer_h
#if USE(ACCELERATED_COMPOSITING)
#include "Animation.h"
#include "Color.h"
#include "FloatPoint.h"
#include "FloatPoint3D.h"
#include "FloatSize.h"
#include "GraphicsLayerClient.h"
#include "IntRect.h"
#include "PlatformLayer.h"
#include "TransformOperations.h"
#include <wtf/OwnPtr.h>
#include <wtf/PassOwnPtr.h>
#if ENABLE(CSS_FILTERS)
#include "FilterOperations.h"
#endif
enum LayerTreeAsTextBehaviorFlags {
LayerTreeAsTextBehaviorNormal = 0,
LayerTreeAsTextDebug = 1 << 0, LayerTreeAsTextIncludeVisibleRects = 1 << 1,
LayerTreeAsTextIncludeTileCaches = 1 << 2,
LayerTreeAsTextIncludeRepaintRects = 1 << 3,
LayerTreeAsTextIncludePaintingPhases = 1 << 4
};
typedef unsigned LayerTreeAsTextBehavior;
namespace WebCore {
class FloatRect;
class GraphicsContext;
class GraphicsLayerFactory;
class Image;
class TextStream;
class TiledBacking;
class TimingFunction;
class TransformationMatrix;
class AnimationValue {
WTF_MAKE_FAST_ALLOCATED;
public:
virtual ~AnimationValue() { }
float keyTime() const { return m_keyTime; }
const TimingFunction* timingFunction() const { return m_timingFunction.get(); }
virtual PassOwnPtr<AnimationValue> clone() const = 0;
protected:
AnimationValue(float keyTime, PassRefPtr<TimingFunction> timingFunction = 0)
: m_keyTime(keyTime)
, m_timingFunction(timingFunction)
{
}
private:
float m_keyTime;
RefPtr<TimingFunction> m_timingFunction;
};
class FloatAnimationValue : public AnimationValue {
public:
static PassOwnPtr<FloatAnimationValue> create(float keyTime, float value, PassRefPtr<TimingFunction> timingFunction = 0)
{
return adoptPtr(new FloatAnimationValue(keyTime, value, timingFunction));
}
virtual PassOwnPtr<AnimationValue> clone() const OVERRIDE
{
return adoptPtr(new FloatAnimationValue(*this));
}
float value() const { return m_value; }
private:
FloatAnimationValue(float keyTime, float value, PassRefPtr<TimingFunction> timingFunction)
: AnimationValue(keyTime, timingFunction)
, m_value(value)
{
}
float m_value;
};
class TransformAnimationValue : public AnimationValue {
public:
static PassOwnPtr<TransformAnimationValue> create(float keyTime, const TransformOperations& value, PassRefPtr<TimingFunction> timingFunction = 0)
{
return adoptPtr(new TransformAnimationValue(keyTime, value, timingFunction));
}
virtual PassOwnPtr<AnimationValue> clone() const OVERRIDE
{
return adoptPtr(new TransformAnimationValue(*this));
}
const TransformOperations& value() const { return m_value; }
private:
TransformAnimationValue(float keyTime, const TransformOperations& value, PassRefPtr<TimingFunction> timingFunction)
: AnimationValue(keyTime, timingFunction)
, m_value(value)
{
}
TransformOperations m_value;
};
#if ENABLE(CSS_FILTERS)
class FilterAnimationValue : public AnimationValue {
public:
static PassOwnPtr<FilterAnimationValue> create(float keyTime, const FilterOperations& value, PassRefPtr<TimingFunction> timingFunction = 0)
{
return adoptPtr(new FilterAnimationValue(keyTime, value, timingFunction));
}
virtual PassOwnPtr<AnimationValue> clone() const OVERRIDE
{
return adoptPtr(new FilterAnimationValue(*this));
}
const FilterOperations& value() const { return m_value; }
private:
FilterAnimationValue(float keyTime, const FilterOperations& value, PassRefPtr<TimingFunction> timingFunction)
: AnimationValue(keyTime, timingFunction)
, m_value(value)
{
}
FilterOperations m_value;
};
#endif
class KeyframeValueList {
public:
explicit KeyframeValueList(AnimatedPropertyID property)
: m_property(property)
{
}
KeyframeValueList(const KeyframeValueList& other)
: m_property(other.property())
{
for (size_t i = 0; i < other.m_values.size(); ++i)
m_values.append(other.m_values[i]->clone());
}
~KeyframeValueList()
{
}
KeyframeValueList& operator=(const KeyframeValueList& other)
{
KeyframeValueList copy(other);
swap(copy);
return *this;
}
void swap(KeyframeValueList& other)
{
std::swap(m_property, other.m_property);
m_values.swap(other.m_values);
}
AnimatedPropertyID property() const { return m_property; }
size_t size() const { return m_values.size(); }
const AnimationValue& at(size_t i) const { return *m_values.at(i); }
void insert(PassOwnPtr<const AnimationValue>);
protected:
Vector<OwnPtr<const AnimationValue> > m_values;
AnimatedPropertyID m_property;
};
class GraphicsLayer {
WTF_MAKE_NONCOPYABLE(GraphicsLayer); WTF_MAKE_FAST_ALLOCATED;
public:
static PassOwnPtr<GraphicsLayer> create(GraphicsLayerFactory*, GraphicsLayerClient*);
static PassOwnPtr<GraphicsLayer> create(GraphicsLayerClient*);
virtual ~GraphicsLayer();
GraphicsLayerClient* client() const { return m_client; }
const String& name() const { return m_name; }
virtual void setName(const String& name) { m_name = name; }
GraphicsLayer* parent() const { return m_parent; };
void setParent(GraphicsLayer*);
bool hasAncestor(GraphicsLayer*) const;
const Vector<GraphicsLayer*>& children() const { return m_children; }
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);
void removeAllChildren();
virtual void removeFromParent();
GraphicsLayer* maskLayer() const { return m_maskLayer; }
virtual void setMaskLayer(GraphicsLayer* layer) { m_maskLayer = layer; }
virtual void setReplicatedByLayer(GraphicsLayer*);
bool isReplicated() const { return m_replicaLayer; }
GraphicsLayer* replicaLayer() const { return m_replicaLayer; }
const FloatPoint& replicatedLayerPosition() const { return m_replicatedLayerPosition; }
void setReplicatedLayerPosition(const FloatPoint& p) { m_replicatedLayerPosition = p; }
enum ShouldSetNeedsDisplay {
DontSetNeedsDisplay,
SetNeedsDisplay
};
IntSize offsetFromRenderer() const { return m_offsetFromRenderer; }
void setOffsetFromRenderer(const IntSize&, ShouldSetNeedsDisplay = SetNeedsDisplay);
const FloatPoint& position() const { return m_position; }
virtual void setPosition(const FloatPoint& p) { m_position = p; }
virtual void syncPosition(const FloatPoint& p) { m_position = p; }
const FloatPoint3D& anchorPoint() const { return m_anchorPoint; }
virtual void setAnchorPoint(const FloatPoint3D& p) { m_anchorPoint = p; }
const FloatSize& size() const { return m_size; }
virtual void setSize(const FloatSize& size) { m_size = size; }
const FloatPoint& boundsOrigin() const { return m_boundsOrigin; }
virtual void setBoundsOrigin(const FloatPoint& origin) { m_boundsOrigin = origin; }
const TransformationMatrix& transform() const { return m_transform; }
virtual void setTransform(const TransformationMatrix& t) { m_transform = t; }
const TransformationMatrix& childrenTransform() const { return m_childrenTransform; }
virtual void setChildrenTransform(const TransformationMatrix& t) { m_childrenTransform = t; }
bool preserves3D() const { return m_preserves3D; }
virtual void setPreserves3D(bool b) { m_preserves3D = b; }
bool masksToBounds() const { return m_masksToBounds; }
virtual void setMasksToBounds(bool b) { m_masksToBounds = b; }
bool drawsContent() const { return m_drawsContent; }
virtual void setDrawsContent(bool b) { m_drawsContent = b; }
bool contentsAreVisible() const { return m_contentsVisible; }
virtual void setContentsVisible(bool b) { m_contentsVisible = b; }
bool acceleratesDrawing() const { return m_acceleratesDrawing; }
virtual void setAcceleratesDrawing(bool b) { m_acceleratesDrawing = b; }
const Color& backgroundColor() const { return m_backgroundColor; }
virtual void setBackgroundColor(const Color&);
bool contentsOpaque() const { return m_contentsOpaque; }
virtual void setContentsOpaque(bool b) { m_contentsOpaque = b; }
bool backfaceVisibility() const { return m_backfaceVisibility; }
virtual void setBackfaceVisibility(bool b) { m_backfaceVisibility = b; }
float opacity() const { return m_opacity; }
virtual void setOpacity(float opacity) { m_opacity = opacity; }
#if ENABLE(CSS_FILTERS)
const FilterOperations& filters() const { return m_filters; }
virtual bool setFilters(const FilterOperations& filters) { m_filters = filters; return true; }
#endif
GraphicsLayerPaintingPhase paintingPhase() const { return m_paintingPhase; }
void setPaintingPhase(GraphicsLayerPaintingPhase phase) { m_paintingPhase = phase; }
virtual void setNeedsDisplay() = 0;
virtual void setNeedsDisplayInRect(const FloatRect&) = 0;
virtual void setContentsNeedsDisplay() { };
virtual void setContentsTilePhase(const IntPoint& p) { m_contentsTilePhase = p; }
IntPoint contentsTilePhase() const { return m_contentsTilePhase; }
virtual void setContentsTileSize(const IntSize& s) { m_contentsTileSize = s; }
IntSize contentsTileSize() const { return m_contentsTileSize; }
bool hasContentsTiling() const { return !m_contentsTileSize.isEmpty(); }
IntRect contentsRect() const { return m_contentsRect; }
virtual void setContentsRect(const IntRect& r) { m_contentsRect = r; }
static String animationNameForTransition(AnimatedPropertyID);
virtual bool addAnimation(const KeyframeValueList&, const IntSize& , const Animation*, const String& , double ) { return false; }
virtual void pauseAnimation(const String& , double ) { }
virtual void removeAnimation(const String& ) { }
virtual void suspendAnimations(double time);
virtual void resumeAnimations();
virtual void setContentsToImage(Image*) { }
virtual bool shouldDirectlyCompositeImage(Image*) const { return true; }
virtual void setContentsToMedia(PlatformLayer*) { } virtual void setContentsToSolidColor(const Color&) { }
virtual void setContentsToCanvas(PlatformLayer*) { }
virtual void setContentsToPlatformLayer(PlatformLayer* layer) { setContentsToMedia(layer); }
virtual bool hasContentsLayer() const { return false; }
void paintGraphicsLayerContents(GraphicsContext&, const IntRect& clip);
virtual void layerDidDisplay(PlatformLayer*) { }
virtual PlatformLayer* platformLayer() const { return 0; }
enum CompositingCoordinatesOrientation { CompositingCoordinatesTopDown, CompositingCoordinatesBottomUp };
virtual void setContentsOrientation(CompositingCoordinatesOrientation orientation) { m_contentsOrientation = orientation; }
CompositingCoordinatesOrientation contentsOrientation() const { return m_contentsOrientation; }
void dumpLayer(TextStream&, int indent = 0, LayerTreeAsTextBehavior = LayerTreeAsTextBehaviorNormal) const;
virtual void setShowDebugBorder(bool show) { m_showDebugBorder = show; }
bool isShowingDebugBorder() const { return m_showDebugBorder; }
virtual void setShowRepaintCounter(bool show) { m_showRepaintCounter = show; }
bool isShowingRepaintCounter() const { return m_showRepaintCounter; }
int repaintCount() const { return m_repaintCount; }
int incrementRepaintCount() { return ++m_repaintCount; }
virtual void setDebugBackgroundColor(const Color&) { }
virtual void setDebugBorder(const Color&, float ) { }
virtual float zPosition() const { return m_zPosition; }
virtual void setZPosition(float);
virtual void distributeOpacity(float);
virtual float accumulatedOpacity() const;
virtual void setMaintainsPixelAlignment(bool maintainsAlignment) { m_maintainsPixelAlignment = maintainsAlignment; }
virtual bool maintainsPixelAlignment() const { return m_maintainsPixelAlignment; }
virtual void setAppliesPageScale(bool appliesScale = true) { m_appliesPageScale = appliesScale; }
virtual bool appliesPageScale() const { return m_appliesPageScale; }
float pageScaleFactor() const { return m_client ? m_client->pageScaleFactor() : 1; }
float deviceScaleFactor() const { return m_client ? m_client->deviceScaleFactor() : 1; }
virtual void deviceOrPageScaleFactorChanged() { }
void noteDeviceOrPageScaleFactorChangedIncludingDescendants();
virtual void flushCompositingState(const FloatRect& ) { }
virtual void flushCompositingStateForThisLayerOnly() { }
virtual bool visibleRectChangeRequiresFlush(const FloatRect& ) const { return false; }
String layerTreeAsText(LayerTreeAsTextBehavior = LayerTreeAsTextBehaviorNormal) const;
virtual double backingStoreMemoryEstimate() const;
bool usingTiledBacking() const { return m_usingTiledBacking; }
virtual TiledBacking* tiledBacking() const { return 0; }
void resetTrackedRepaints();
void addRepaintRect(const FloatRect&);
static bool supportsBackgroundColorContent()
{
#if USE(CA) || USE(TEXTURE_MAPPER)
return true;
#else
return false;
#endif
}
#if USE(COORDINATED_GRAPHICS)
static bool supportsContentsTiling();
#else
static bool supportsContentsTiling()
{
return false;
}
#endif
void updateDebugIndicators();
virtual bool canThrottleLayerFlush() const { return false; }
protected:
virtual void willBeDestroyed();
#if ENABLE(CSS_FILTERS)
void clearFilters() { m_filters.clear(); }
static int validateFilterOperations(const KeyframeValueList&);
#endif
static int validateTransformOperations(const KeyframeValueList&, bool& hasBigRotation);
virtual void setOpacityInternal(float) { }
GraphicsLayer* replicatedLayer() const { return m_replicatedLayer; }
virtual void setReplicatedLayer(GraphicsLayer* layer) { m_replicatedLayer = layer; }
GraphicsLayer(GraphicsLayerClient*);
static void writeIndent(TextStream&, int indent);
void dumpProperties(TextStream&, int indent, LayerTreeAsTextBehavior) const;
virtual void dumpAdditionalProperties(TextStream&, int , LayerTreeAsTextBehavior) const { }
virtual void getDebugBorderInfo(Color&, float& width) const;
GraphicsLayerClient* m_client;
String m_name;
IntSize m_offsetFromRenderer;
FloatPoint m_position;
FloatPoint3D m_anchorPoint;
FloatSize m_size;
FloatPoint m_boundsOrigin;
TransformationMatrix m_transform;
TransformationMatrix m_childrenTransform;
Color m_backgroundColor;
float m_opacity;
float m_zPosition;
#if ENABLE(CSS_FILTERS)
FilterOperations m_filters;
#endif
bool m_contentsOpaque : 1;
bool m_preserves3D: 1;
bool m_backfaceVisibility : 1;
bool m_usingTiledBacking : 1;
bool m_masksToBounds : 1;
bool m_drawsContent : 1;
bool m_contentsVisible : 1;
bool m_acceleratesDrawing : 1;
bool m_maintainsPixelAlignment : 1;
bool m_appliesPageScale : 1; bool m_showDebugBorder : 1;
bool m_showRepaintCounter : 1;
GraphicsLayerPaintingPhase m_paintingPhase;
CompositingCoordinatesOrientation m_contentsOrientation;
Vector<GraphicsLayer*> m_children;
GraphicsLayer* m_parent;
GraphicsLayer* m_maskLayer;
GraphicsLayer* m_replicaLayer; GraphicsLayer* m_replicatedLayer; FloatPoint m_replicatedLayerPosition;
IntRect m_contentsRect;
IntPoint m_contentsTilePhase;
IntSize m_contentsTileSize;
int m_repaintCount;
};
}
#ifndef NDEBUG
void showGraphicsLayerTree(const WebCore::GraphicsLayer* layer);
#endif
#endif // USE(ACCELERATED_COMPOSITING)
#endif // GraphicsLayer_h