#ifndef GraphicsLayer_h
#define GraphicsLayer_h
#include "platform/PlatformExport.h"
#include "platform/geometry/FloatPoint.h"
#include "platform/geometry/FloatPoint3D.h"
#include "platform/geometry/FloatSize.h"
#include "platform/geometry/IntRect.h"
#include "platform/graphics/Color.h"
#include "platform/graphics/GraphicsLayerClient.h"
#include "platform/graphics/GraphicsLayerDebugInfo.h"
#include "platform/graphics/OpaqueRectTrackingContentLayerDelegate.h"
#include "platform/graphics/filters/FilterOperations.h"
#include "platform/transforms/TransformationMatrix.h"
#include "public/platform/WebAnimationDelegate.h"
#include "public/platform/WebContentLayer.h"
#include "public/platform/WebImageLayer.h"
#include "public/platform/WebLayerClient.h"
#include "public/platform/WebLayerScrollClient.h"
#include "public/platform/WebNinePatchLayer.h"
#include "public/platform/WebSolidColorLayer.h"
#include "wtf/OwnPtr.h"
#include "wtf/PassOwnPtr.h"
#include "wtf/Vector.h"
namespace blink {
class GraphicsLayerFactoryChromium;
class WebAnimation;
class WebLayer;
}
namespace WebCore {
class FloatRect;
class GraphicsContext;
class GraphicsLayer;
class GraphicsLayerFactory;
class Image;
class ScrollableArea;
class TextStream;
class PLATFORM_EXPORT LinkHighlightClient {
public:
virtual void invalidate() = 0;
virtual void clearCurrentGraphicsLayer() = 0;
virtual blink::WebLayer* layer() = 0;
protected:
virtual ~LinkHighlightClient() { }
};
typedef Vector<GraphicsLayer*, 64> GraphicsLayerVector;
class PLATFORM_EXPORT GraphicsLayer : public GraphicsContextPainter, public blink::WebAnimationDelegate, public blink::WebLayerScrollClient, public blink::WebLayerClient {
WTF_MAKE_NONCOPYABLE(GraphicsLayer); WTF_MAKE_FAST_ALLOCATED;
public:
static PassOwnPtr<GraphicsLayer> create(GraphicsLayerFactory*, GraphicsLayerClient*);
virtual ~GraphicsLayer();
GraphicsLayerClient* client() const { return m_client; }
virtual blink::WebGraphicsLayerDebugInfo* takeDebugInfoFor(blink::WebLayer*) OVERRIDE;
GraphicsLayerDebugInfo& debugInfo();
void setCompositingReasons(CompositingReasons);
CompositingReasons compositingReasons() const { return m_debugInfo.compositingReasons(); }
GraphicsLayer* parent() const { return m_parent; };
void setParent(GraphicsLayer*);
bool hasAncestor(GraphicsLayer*) const;
const Vector<GraphicsLayer*>& children() const { return m_children; }
bool setChildren(const GraphicsLayerVector&);
void addChild(GraphicsLayer*);
void addChildAtIndex(GraphicsLayer*, int index);
void addChildAbove(GraphicsLayer*, GraphicsLayer* sibling);
void addChildBelow(GraphicsLayer*, GraphicsLayer* sibling);
bool replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild);
void removeAllChildren();
void removeFromParent();
GraphicsLayer* maskLayer() const { return m_maskLayer; }
void setMaskLayer(GraphicsLayer*);
GraphicsLayer* contentsClippingMaskLayer() const { return m_contentsClippingMaskLayer; }
void setContentsClippingMaskLayer(GraphicsLayer*);
void setReplicatedByLayer(GraphicsLayer*);
bool isReplicated() const { return m_replicaLayer; }
GraphicsLayer* replicaLayer() const { return m_replicaLayer; }
GraphicsLayer* replicatedLayer() const { return m_replicatedLayer; }
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; }
void setPosition(const FloatPoint&);
const FloatPoint3D& anchorPoint() const { return m_anchorPoint; }
void setAnchorPoint(const FloatPoint3D&);
const FloatSize& size() const { return m_size; }
void setSize(const FloatSize&);
const FloatPoint& boundsOrigin() const { return m_boundsOrigin; }
void setBoundsOrigin(const FloatPoint& origin) { m_boundsOrigin = origin; }
const TransformationMatrix& transform() const { return m_transform; }
void setTransform(const TransformationMatrix&);
bool shouldFlattenTransform() const { return m_shouldFlattenTransform; }
void setShouldFlattenTransform(bool);
int renderingContext() const { return m_3dRenderingContext; }
void setRenderingContext(int id);
bool masksToBounds() const { return m_masksToBounds; }
void setMasksToBounds(bool);
bool drawsContent() const { return m_drawsContent; }
void setDrawsContent(bool);
bool contentsAreVisible() const { return m_contentsVisible; }
void setContentsVisible(bool);
void setScrollParent(blink::WebLayer*);
void setClipParent(blink::WebLayer*);
const Color& backgroundColor() const { return m_backgroundColor; }
void setBackgroundColor(const Color&);
bool contentsOpaque() const { return m_contentsOpaque; }
void setContentsOpaque(bool);
bool backfaceVisibility() const { return m_backfaceVisibility; }
void setBackfaceVisibility(bool visible);
float opacity() const { return m_opacity; }
void setOpacity(float);
blink::WebBlendMode blendMode() const { return m_blendMode; }
void setBlendMode(blink::WebBlendMode);
bool isRootForIsolatedGroup() const { return m_isRootForIsolatedGroup; }
void setIsRootForIsolatedGroup(bool);
bool hasGpuRasterizationHint() const { return m_hasGpuRasterizationHint; }
void setHasGpuRasterizationHint(bool);
const FilterOperations& filters() const { return m_filters; }
bool setFilters(const FilterOperations&);
void setBackgroundFilters(const FilterOperations&);
GraphicsLayerPaintingPhase paintingPhase() const { return m_paintingPhase; }
void setPaintingPhase(GraphicsLayerPaintingPhase phase) { m_paintingPhase = phase; }
void setNeedsDisplay();
void setNeedsDisplayInRect(const FloatRect&);
void setContentsNeedsDisplay();
IntRect contentsRect() const { return m_contentsRect; }
void setContentsRect(const IntRect&);
bool addAnimation(PassOwnPtr<blink::WebAnimation>);
void pauseAnimation(int animationId, double );
void removeAnimation(int animationId);
void setContentsToImage(Image*);
void setContentsToNinePatch(Image*, const IntRect& aperture);
void setContentsToPlatformLayer(blink::WebLayer* layer) { setContentsTo(layer); }
bool hasContentsLayer() const { return m_contentsLayer; }
void paintGraphicsLayerContents(GraphicsContext&, const IntRect& clip);
blink::WebLayer* platformLayer() const;
enum CompositingCoordinatesOrientation { CompositingCoordinatesTopDown, CompositingCoordinatesBottomUp };
void setContentsOrientation(CompositingCoordinatesOrientation orientation) { m_contentsOrientation = orientation; }
CompositingCoordinatesOrientation contentsOrientation() const { return m_contentsOrientation; }
typedef HashMap<int, int> RenderingContextMap;
void dumpLayer(TextStream&, int indent, LayerTreeFlags, RenderingContextMap&) const;
int paintCount() const { return m_paintCount; }
float zPosition() const { return m_zPosition; }
void setZPosition(float);
bool visibleRectChangeRequiresFlush(const FloatRect& ) const { return false; }
String layerTreeAsText(LayerTreeFlags = LayerTreeNormal) const;
String debugName(blink::WebLayer*) const;
void resetTrackedRepaints();
void addRepaintRect(const FloatRect&);
void collectTrackedRepaintRects(Vector<FloatRect>&) const;
void addLinkHighlight(LinkHighlightClient*);
void removeLinkHighlight(LinkHighlightClient*);
unsigned numLinkHighlights() { return m_linkHighlights.size(); }
LinkHighlightClient* linkHighlight(int i) { return m_linkHighlights[i]; }
void setScrollableArea(ScrollableArea*, bool isMainFrame);
ScrollableArea* scrollableArea() const { return m_scrollableArea; }
blink::WebContentLayer* contentLayer() const { return m_layer.get(); }
static void registerContentsLayer(blink::WebLayer*);
static void unregisterContentsLayer(blink::WebLayer*);
virtual void paint(GraphicsContext&, const IntRect& clip) OVERRIDE;
virtual void notifyAnimationStarted(double monotonicTime, blink::WebAnimation::TargetProperty) OVERRIDE;
virtual void notifyAnimationFinished(double monotonicTime, blink::WebAnimation::TargetProperty) OVERRIDE;
virtual void didScroll() OVERRIDE;
protected:
explicit GraphicsLayer(GraphicsLayerClient*);
friend class blink::GraphicsLayerFactoryChromium;
virtual blink::WebLayer* contentsLayer() const { return m_contentsLayer; }
private:
void addChildInternal(GraphicsLayer*);
void clearFilters() { m_filters.clear(); }
void setReplicatedLayer(GraphicsLayer* layer) { m_replicatedLayer = layer; }
int incrementPaintCount() { return ++m_paintCount; }
void dumpProperties(TextStream&, int indent, LayerTreeFlags, RenderingContextMap&) const;
void updateChildList();
void updateLayerIsDrawable();
void updateContentsRect();
void setContentsTo(blink::WebLayer*);
void setupContentsLayer(blink::WebLayer*);
void clearContentsLayerIfUnregistered();
blink::WebLayer* contentsLayerIfRegistered();
GraphicsLayerClient* m_client;
IntSize m_offsetFromRenderer;
FloatPoint m_position;
FloatPoint3D m_anchorPoint;
FloatSize m_size;
FloatPoint m_boundsOrigin;
TransformationMatrix m_transform;
Color m_backgroundColor;
float m_opacity;
float m_zPosition;
blink::WebBlendMode m_blendMode;
FilterOperations m_filters;
bool m_contentsOpaque : 1;
bool m_shouldFlattenTransform: 1;
bool m_backfaceVisibility : 1;
bool m_masksToBounds : 1;
bool m_drawsContent : 1;
bool m_contentsVisible : 1;
bool m_isRootForIsolatedGroup : 1;
bool m_hasGpuRasterizationHint: 1;
bool m_hasScrollParent : 1;
bool m_hasClipParent : 1;
GraphicsLayerPaintingPhase m_paintingPhase;
CompositingCoordinatesOrientation m_contentsOrientation;
Vector<GraphicsLayer*> m_children;
GraphicsLayer* m_parent;
GraphicsLayer* m_maskLayer;
GraphicsLayer* m_contentsClippingMaskLayer;
GraphicsLayer* m_replicaLayer;
GraphicsLayer* m_replicatedLayer;
FloatPoint m_replicatedLayerPosition;
IntRect m_contentsRect;
int m_paintCount;
OwnPtr<blink::WebContentLayer> m_layer;
OwnPtr<blink::WebImageLayer> m_imageLayer;
OwnPtr<blink::WebNinePatchLayer> m_ninePatchLayer;
blink::WebLayer* m_contentsLayer;
int m_contentsLayerId;
Vector<LinkHighlightClient*> m_linkHighlights;
OwnPtr<OpaqueRectTrackingContentLayerDelegate> m_opaqueRectTrackingContentLayerDelegate;
ScrollableArea* m_scrollableArea;
GraphicsLayerDebugInfo m_debugInfo;
int m_3dRenderingContext;
};
}
#ifndef NDEBUG
void PLATFORM_EXPORT showGraphicsLayerTree(const WebCore::GraphicsLayer*);
#endif
#endif