RenderLayerCompositor.h [plain text]
#ifndef RenderLayerCompositor_h
#define RenderLayerCompositor_h
#if USE(ACCELERATED_COMPOSITING)
#include "ChromeClient.h"
#include "Frame.h"
#include "GraphicsLayerClient.h"
#include "GraphicsLayerUpdater.h"
#include "RenderLayer.h"
#include <wtf/HashMap.h>
namespace WebCore {
class FixedPositionViewportConstraints;
class GraphicsLayer;
class GraphicsLayerUpdater;
class RenderEmbeddedObject;
class RenderPart;
class ScrollingCoordinator;
class StickyPositionViewportConstraints;
#if ENABLE(VIDEO)
class RenderVideo;
#endif
class TiledBacking;
enum CompositingUpdateType {
CompositingUpdateAfterStyleChange,
CompositingUpdateAfterLayout,
CompositingUpdateOnHitTest,
CompositingUpdateOnScroll,
CompositingUpdateOnCompositedScroll
};
enum {
CompositingReasonNone = 0,
CompositingReason3DTransform = 1 << 0,
CompositingReasonVideo = 1 << 1,
CompositingReasonCanvas = 1 << 2,
CompositingReasonPlugin = 1 << 3,
CompositingReasonIFrame = 1 << 4,
CompositingReasonBackfaceVisibilityHidden = 1 << 5,
CompositingReasonClipsCompositingDescendants = 1 << 6,
CompositingReasonAnimation = 1 << 7,
CompositingReasonFilters = 1 << 8,
CompositingReasonPositionFixed = 1 << 9,
CompositingReasonPositionSticky = 1 << 10,
CompositingReasonOverflowScrollingTouch = 1 << 11,
CompositingReasonStacking = 1 << 12,
CompositingReasonOverlap = 1 << 13,
CompositingReasonNegativeZIndexChildren = 1 << 14,
CompositingReasonTransformWithCompositedDescendants = 1 << 15,
CompositingReasonOpacityWithCompositedDescendants = 1 << 16,
CompositingReasonMaskWithCompositedDescendants = 1 << 17,
CompositingReasonReflectionWithCompositedDescendants = 1 << 18,
CompositingReasonFilterWithCompositedDescendants = 1 << 19,
CompositingReasonBlendingWithCompositedDescendants = 1 << 20,
CompositingReasonPerspective = 1 << 21,
CompositingReasonPreserve3D = 1 << 22,
CompositingReasonRoot = 1 << 23
};
typedef unsigned CompositingReasons;
class RenderLayerCompositor : public GraphicsLayerClient, public GraphicsLayerUpdaterClient {
WTF_MAKE_FAST_ALLOCATED;
public:
explicit RenderLayerCompositor(RenderView*);
~RenderLayerCompositor();
bool inCompositingMode() const { return m_compositing; }
void enableCompositingMode(bool enable = true);
bool inForcedCompositingMode() const { return m_forceCompositingMode; }
bool hasAcceleratedCompositing() const { return m_hasAcceleratedCompositing; }
bool canRender3DTransforms() const;
void cacheAcceleratedCompositingFlags();
void setCompositingLayersNeedRebuild(bool needRebuild = true);
bool compositingLayersNeedRebuild() const { return m_compositingLayersNeedRebuild; }
void scheduleLayerFlush(bool canThrottle);
void flushPendingLayerChanges(bool isFlushRoot = true);
RenderLayerCompositor* enclosingCompositorFlushingLayers() const;
void didFlushChangesForLayer(RenderLayer*, const GraphicsLayer*);
void didChangeVisibleRect();
void updateCompositingLayers(CompositingUpdateType, RenderLayer* updateRoot = 0);
void scheduleCompositingLayerUpdate();
enum CompositingChangeRepaint { CompositingChangeRepaintNow, CompositingChangeWillRepaintLater };
bool updateLayerCompositingState(RenderLayer*, CompositingChangeRepaint = CompositingChangeRepaintNow);
void updateCompositingDescendantGeometry(RenderLayer* compositingAncestor, RenderLayer*, bool compositedChildrenOnly);
bool clippedByAncestor(RenderLayer*) const;
bool clipsCompositingDescendants(const RenderLayer*) const;
bool needsContentsCompositingLayer(const RenderLayer*) const;
bool supportsFixedRootBackgroundCompositing() const;
bool needsFixedRootBackgroundLayer(const RenderLayer*) const;
GraphicsLayer* fixedRootBackgroundLayer() const;
IntRect calculateCompositedBounds(const RenderLayer*, const RenderLayer* ancestorLayer) const;
void repaintOnCompositingChange(RenderLayer*);
void repaintInCompositedAncestor(RenderLayer*, const LayoutRect&);
void layerWasAdded(RenderLayer* parent, RenderLayer* child);
void layerWillBeRemoved(RenderLayer* parent, RenderLayer* child);
RenderLayer* enclosingNonStackingClippingLayer(const RenderLayer* layer) const;
void repaintCompositedLayers(const IntRect* = 0);
bool requiresOwnBackingStore(const RenderLayer*, const RenderLayer* compositingAncestorLayer, const IntRect& layerCompositedBoundsInAncestor, const IntRect& ancestorCompositedBounds) const;
RenderLayer* rootRenderLayer() const;
GraphicsLayer* rootGraphicsLayer() const;
GraphicsLayer* scrollLayer() const;
#if ENABLE(RUBBER_BANDING)
GraphicsLayer* headerLayer() const;
GraphicsLayer* footerLayer() const;
#endif
enum RootLayerAttachment {
RootLayerUnattached,
RootLayerAttachedViaChromeClient,
RootLayerAttachedViaEnclosingFrame
};
RootLayerAttachment rootLayerAttachment() const { return m_rootLayerAttachment; }
void updateRootLayerAttachment();
void updateRootLayerPosition();
void setIsInWindow(bool);
void clearBackingForAllLayers();
void layerBecameComposited(const RenderLayer*) { ++m_compositedLayerCount; }
void layerBecameNonComposited(const RenderLayer*);
#if ENABLE(VIDEO)
bool canAccelerateVideoRendering(RenderVideo*) const;
#endif
bool has3DContent() const;
static bool allowsIndependentlyCompositedFrames(const FrameView*);
bool shouldPropagateCompositingToEnclosingFrame() const;
static RenderLayerCompositor* frameContentsCompositor(RenderPart*);
static bool parentFrameContentLayers(RenderPart*);
void frameViewDidChangeLocation(const IntPoint& contentsOffset);
void frameViewDidChangeSize();
void frameViewDidScroll();
void frameViewDidLayout();
void rootFixedBackgroundsChanged();
void scrollingLayerDidChange(RenderLayer*);
void fixedRootBackgroundLayerChanged();
String layerTreeAsText(LayerTreeFlags);
virtual float deviceScaleFactor() const OVERRIDE;
virtual float pageScaleFactor() const OVERRIDE;
virtual void didCommitChangesForLayer(const GraphicsLayer*) const OVERRIDE;
virtual void notifyFlushBeforeDisplayRefresh(const GraphicsLayer*) OVERRIDE;
void layerTiledBackingUsageChanged(const GraphicsLayer*, bool );
bool keepLayersPixelAligned() const;
bool acceleratedDrawingEnabled() const { return m_acceleratedDrawingEnabled; }
void deviceOrPageScaleFactorChanged();
void windowScreenDidChange(PlatformDisplayID);
GraphicsLayer* layerForHorizontalScrollbar() const { return m_layerForHorizontalScrollbar.get(); }
GraphicsLayer* layerForVerticalScrollbar() const { return m_layerForVerticalScrollbar.get(); }
GraphicsLayer* layerForScrollCorner() const { return m_layerForScrollCorner.get(); }
#if ENABLE(RUBBER_BANDING)
GraphicsLayer* layerForOverhangAreas() const { return m_layerForOverhangAreas.get(); }
GraphicsLayer* updateLayerForTopOverhangArea(bool wantsLayer);
GraphicsLayer* updateLayerForBottomOverhangArea(bool wantsLayer);
GraphicsLayer* updateLayerForHeader(bool wantsLayer);
GraphicsLayer* updateLayerForFooter(bool wantsLayer);
#endif
void updateViewportConstraintStatus(RenderLayer*);
void removeViewportConstrainedLayer(RenderLayer*);
void resetTrackedRepaintRects();
void setTracksRepaints(bool);
void setShouldReevaluateCompositingAfterLayout() { m_reevaluateCompositingAfterLayout = true; }
bool viewHasTransparentBackground(Color* backgroundColor = 0) const;
bool hasNonMainLayersWithTiledBacking() const { return m_layersWithTiledBackingCount; }
CompositingReasons reasonsForCompositing(const RenderLayer*) const;
void setLayerFlushThrottlingEnabled(bool);
void disableLayerFlushThrottlingTemporarilyForInteraction();
void didPaintBacking(RenderLayerBacking*);
private:
class OverlapMap;
virtual void notifyAnimationStarted(const GraphicsLayer*, double) OVERRIDE { }
virtual void notifyFlushRequired(const GraphicsLayer*) OVERRIDE;
virtual void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsLayerPaintingPhase, const IntRect&) OVERRIDE;
virtual bool isTrackingRepaints() const OVERRIDE;
virtual void flushLayers(GraphicsLayerUpdater*) OVERRIDE;
virtual void customPositionForVisibleRectComputation(const GraphicsLayer*, FloatPoint&) const OVERRIDE;
bool needsToBeComposited(const RenderLayer*, RenderLayer::ViewportConstrainedNotCompositedReason* = 0) const;
bool requiresCompositingLayer(const RenderLayer*, RenderLayer::ViewportConstrainedNotCompositedReason* = 0) const;
bool canBeComposited(const RenderLayer*) const;
bool updateBacking(RenderLayer*, CompositingChangeRepaint shouldRepaint);
void clearBackingForLayerIncludingDescendants(RenderLayer*);
void recursiveRepaintLayer(RenderLayer*, const IntRect* = 0);
void addToOverlapMap(OverlapMap&, RenderLayer*, IntRect& layerBounds, bool& boundsComputed);
void addToOverlapMapRecursive(OverlapMap&, RenderLayer*, RenderLayer* ancestorLayer = 0);
void updateCompositingLayersTimerFired(Timer<RenderLayerCompositor>*);
void computeCompositingRequirements(RenderLayer* ancestorLayer, RenderLayer*, OverlapMap*, struct CompositingState&, bool& layersChanged, bool& descendantHas3DTransform);
void rebuildCompositingLayerTree(RenderLayer*, Vector<GraphicsLayer*>& childGraphicsLayersOfEnclosingLayer, int depth);
void updateLayerTreeGeometry(RenderLayer*, int depth);
void setCompositingParent(RenderLayer* childLayer, RenderLayer* parentLayer);
void removeCompositedChildren(RenderLayer*);
bool layerHas3DContent(const RenderLayer*) const;
bool isRunningAcceleratedTransformAnimation(RenderObject*) const;
bool hasAnyAdditionalCompositedLayers(const RenderLayer* rootLayer) const;
void ensureRootLayer();
void destroyRootLayer();
void attachRootLayer(RootLayerAttachment);
void detachRootLayer();
void rootLayerAttachmentChanged();
void updateOverflowControlsLayers();
void notifyIFramesOfCompositingChange();
bool isFlushingLayers() const { return m_flushingLayers; }
Page* page() const;
TiledBacking* pageTiledBacking() const;
GraphicsLayerFactory* graphicsLayerFactory() const;
ScrollingCoordinator* scrollingCoordinator() const;
bool requiresCompositingForAnimation(RenderObject*) const;
bool requiresCompositingForTransform(RenderObject*) const;
bool requiresCompositingForVideo(RenderObject*) const;
bool requiresCompositingForCanvas(RenderObject*) const;
bool requiresCompositingForPlugin(RenderObject*) const;
bool requiresCompositingForFrame(RenderObject*) const;
bool requiresCompositingForFilters(RenderObject*) const;
bool requiresCompositingForBlending(RenderObject* renderer) const;
bool requiresCompositingForScrollableFrame() const;
bool requiresCompositingForPosition(RenderObject*, const RenderLayer*, RenderLayer::ViewportConstrainedNotCompositedReason* = 0) const;
bool requiresCompositingForOverflowScrolling(const RenderLayer*) const;
bool requiresCompositingForIndirectReason(RenderObject*, bool hasCompositedDescendants, bool has3DTransformedDescendants, RenderLayer::IndirectCompositingReason&) const;
void addViewportConstrainedLayer(RenderLayer*);
void registerOrUpdateViewportConstrainedLayer(RenderLayer*);
void unregisterViewportConstrainedLayer(RenderLayer*);
FixedPositionViewportConstraints computeFixedViewportConstraints(RenderLayer*) const;
StickyPositionViewportConstraints computeStickyViewportConstraints(RenderLayer*) const;
bool requiresScrollLayer(RootLayerAttachment) const;
bool requiresHorizontalScrollbarLayer() const;
bool requiresVerticalScrollbarLayer() const;
bool requiresScrollCornerLayer() const;
#if ENABLE(RUBBER_BANDING)
bool requiresOverhangAreasLayer() const;
bool requiresContentShadowLayer() const;
#endif
bool hasCoordinatedScrolling() const;
bool shouldCompositeOverflowControls() const;
void scheduleLayerFlushNow();
bool isThrottlingLayerFlushes() const;
void startLayerFlushTimerIfNeeded();
void layerFlushTimerFired(Timer<RenderLayerCompositor>*);
void paintRelatedMilestonesTimerFired(Timer<RenderLayerCompositor>*);
#if !LOG_DISABLED
const char* logReasonsForCompositing(const RenderLayer*);
void logLayerInfo(const RenderLayer*, int depth);
#endif
private:
RenderView* m_renderView;
OwnPtr<GraphicsLayer> m_rootContentLayer;
Timer<RenderLayerCompositor> m_updateCompositingLayersTimer;
bool m_hasAcceleratedCompositing;
ChromeClient::CompositingTriggerFlags m_compositingTriggers;
int m_compositedLayerCount;
bool m_showDebugBorders;
bool m_showRepaintCounter;
bool m_acceleratedDrawingEnabled;
mutable bool m_reevaluateCompositingAfterLayout;
bool m_compositing;
bool m_compositingLayersNeedRebuild;
bool m_flushingLayers;
bool m_shouldFlushOnReattach;
bool m_forceCompositingMode;
bool m_inPostLayoutUpdate;
bool m_isTrackingRepaints;
unsigned m_layersWithTiledBackingCount;
RootLayerAttachment m_rootLayerAttachment;
OwnPtr<GraphicsLayer> m_clipLayer;
OwnPtr<GraphicsLayer> m_scrollLayer;
HashSet<RenderLayer*> m_viewportConstrainedLayers;
HashSet<RenderLayer*> m_viewportConstrainedLayersNeedingUpdate;
OwnPtr<GraphicsLayer> m_overflowControlsHostLayer;
OwnPtr<GraphicsLayer> m_layerForHorizontalScrollbar;
OwnPtr<GraphicsLayer> m_layerForVerticalScrollbar;
OwnPtr<GraphicsLayer> m_layerForScrollCorner;
#if ENABLE(RUBBER_BANDING)
OwnPtr<GraphicsLayer> m_layerForOverhangAreas;
OwnPtr<GraphicsLayer> m_contentShadowLayer;
OwnPtr<GraphicsLayer> m_layerForTopOverhangArea;
OwnPtr<GraphicsLayer> m_layerForBottomOverhangArea;
OwnPtr<GraphicsLayer> m_layerForHeader;
OwnPtr<GraphicsLayer> m_layerForFooter;
#endif
OwnPtr<GraphicsLayerUpdater> m_layerUpdater;
Timer<RenderLayerCompositor> m_layerFlushTimer;
bool m_layerFlushThrottlingEnabled;
bool m_layerFlushThrottlingTemporarilyDisabledForInteraction;
bool m_hasPendingLayerFlush;
Timer<RenderLayerCompositor> m_paintRelatedMilestonesTimer;
#if !LOG_DISABLED
int m_rootLayerUpdateCount;
int m_obligateCompositedLayerCount; int m_secondaryCompositedLayerCount; double m_obligatoryBackingStoreBytes;
double m_secondaryBackingStoreBytes;
#endif
};
}
#endif // USE(ACCELERATED_COMPOSITING)
#endif // RenderLayerCompositor_h