#ifndef RenderLayerCompositor_h
#define RenderLayerCompositor_h
#include "core/page/ChromeClient.h"
#include "core/rendering/RenderLayer.h"
#include "core/rendering/compositing/CompositingPropertyUpdater.h"
#include "core/rendering/compositing/CompositingReasonFinder.h"
#include "core/rendering/compositing/GraphicsLayerUpdater.h"
#include "platform/graphics/GraphicsLayerClient.h"
#include "wtf/HashMap.h"
namespace WebCore {
class FixedPositionViewportConstraints;
class GraphicsLayer;
class RenderEmbeddedObject;
class RenderLayerStackingNode;
class RenderPart;
class RenderVideo;
class ScrollingCoordinator;
class StickyPositionViewportConstraints;
enum CompositingUpdateType {
CompositingUpdateNone,
CompositingUpdateAfterStyleChange,
CompositingUpdateAfterLayout,
CompositingUpdateOnScroll,
CompositingUpdateOnCompositedScroll,
CompositingUpdateAfterCanvasContextChange,
};
class RenderLayerCompositor FINAL : public GraphicsLayerClient {
WTF_MAKE_FAST_ALLOCATED;
public:
explicit RenderLayerCompositor(RenderView&);
virtual ~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 layerSquashingEnabled() const;
bool canRender3DTransforms() const;
void cacheAcceleratedCompositingFlags();
void setCompositingLayersNeedRebuild();
bool compositingLayersNeedRebuild() const { return m_compositingLayersNeedRebuild; }
void updateCompositingRequirementsState();
void setNeedsUpdateCompositingRequirementsState() { m_needsUpdateCompositingRequirementsState = true; }
void setNeedsCompositingUpdate(CompositingUpdateType);
void updateCompositingLayers();
enum UpdateLayerCompositingStateOptions {
Normal,
UseChickenEggHacks,
};
void updateLayerCompositingState(RenderLayer*, UpdateLayerCompositingStateOptions = Normal);
bool clippedByAncestor(const RenderLayer*) const;
bool clipsCompositingDescendants(const RenderLayer*) const;
bool needsContentsCompositingLayer(const RenderLayer*) const;
bool supportsFixedRootBackgroundCompositing() const;
bool needsFixedRootBackgroundLayer(const RenderLayer*) const;
GraphicsLayer* fixedRootBackgroundLayer() const;
LayoutRect 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);
void repaintCompositedLayers();
RenderLayer* rootRenderLayer() const;
GraphicsLayer* rootGraphicsLayer() const;
GraphicsLayer* scrollLayer() const;
GraphicsLayer* containerLayer() const;
GraphicsLayer* ensureRootTransformLayer();
enum RootLayerAttachment {
RootLayerUnattached,
RootLayerAttachedViaChromeClient,
RootLayerAttachedViaEnclosingFrame
};
RootLayerAttachment rootLayerAttachment() const { return m_rootLayerAttachment; }
void updateRootLayerAttachment();
void updateRootLayerPosition();
void setIsInWindow(bool);
static RenderLayerCompositor* frameContentsCompositor(RenderPart*);
static bool parentFrameContentLayers(RenderPart*);
void frameViewDidChangeLocation(const IntPoint& contentsOffset);
void frameViewDidChangeSize();
void frameViewDidScroll();
void frameViewScrollbarsExistenceDidChange();
void rootFixedBackgroundsChanged();
bool scrollingLayerDidChange(RenderLayer*);
String layerTreeAsText(LayerTreeFlags);
GraphicsLayer* layerForHorizontalScrollbar() const { return m_layerForHorizontalScrollbar.get(); }
GraphicsLayer* layerForVerticalScrollbar() const { return m_layerForVerticalScrollbar.get(); }
GraphicsLayer* layerForScrollCorner() const { return m_layerForScrollCorner.get(); }
void updateViewportConstraintStatus(RenderLayer*);
void removeViewportConstrainedLayer(RenderLayer*);
void addOutOfFlowPositionedLayer(RenderLayer*);
void removeOutOfFlowPositionedLayer(RenderLayer*);
void resetTrackedRepaintRects();
void setTracksRepaints(bool);
void setNeedsToRecomputeCompositingRequirements() { m_needsToRecomputeCompositingRequirements = true; }
virtual String debugName(const GraphicsLayer*) OVERRIDE;
void updateStyleDeterminedCompositingReasons(RenderLayer*);
void scheduleAnimationIfNeeded();
private:
class OverlapMap;
enum CompositingStateTransitionType {
NoCompositingStateChange,
AllocateOwnCompositedLayerMapping,
RemoveOwnCompositedLayerMapping,
PutInSquashingLayer,
RemoveFromSquashingLayer
};
struct SquashingState {
SquashingState()
: mostRecentMapping(0)
, hasMostRecentMapping(false)
, nextSquashedLayerIndex(0) { }
void updateSquashingStateForNewMapping(CompositedLayerMappingPtr, bool hasNewCompositedLayerMapping, LayoutPoint newOffsetFromAbsoluteForSquashingCLM);
CompositedLayerMappingPtr mostRecentMapping;
bool hasMostRecentMapping;
LayoutPoint offsetFromAbsoluteForSquashingCLM;
size_t nextSquashedLayerIndex;
};
bool hasUnresolvedDirtyBits();
bool canSquashIntoCurrentSquashingOwner(const RenderLayer* candidate, const SquashingState&);
CompositingStateTransitionType computeCompositedLayerUpdate(RenderLayer*);
bool updateLayerIfViewportConstrained(RenderLayer*);
virtual void notifyAnimationStarted(const GraphicsLayer*, double) OVERRIDE { }
virtual void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsLayerPaintingPhase, const IntRect&) OVERRIDE;
virtual bool isTrackingRepaints() const OVERRIDE;
bool needsOwnBacking(const RenderLayer*) const;
bool canBeComposited(const RenderLayer*) const;
void updateDirectCompositingReasons(RenderLayer*);
void updateCompositingLayersInternal();
CompositingReasons subtreeReasonsForCompositing(RenderObject*, bool hasCompositedDescendants, bool has3DTransformedDescendants) const;
bool allocateOrClearCompositedLayerMapping(RenderLayer*, CompositingStateTransitionType compositedLayerUpdate);
bool updateSquashingAssignment(RenderLayer*, SquashingState&, CompositingStateTransitionType compositedLayerUpdate);
void recursiveRepaintLayer(RenderLayer*);
static void finishCompositingUpdateForFrameTree(LocalFrame*);
void computeCompositingRequirements(RenderLayer* ancestorLayer, RenderLayer*, OverlapMap&, struct CompositingRecursionData&, bool& descendantHas3DTransform, Vector<RenderLayer*>& unclippedDescendants, IntRect& absoluteDecendantBoundingBox);
void assignLayersToBackings(RenderLayer*, bool& layersChanged);
void assignLayersToBackingsInternal(RenderLayer*, SquashingState&, bool& layersChanged);
void setCompositingParent(RenderLayer* childLayer, RenderLayer* parentLayer);
void removeCompositedChildren(RenderLayer*);
bool isRunningAcceleratedTransformAnimation(RenderObject*) const;
bool hasAnyAdditionalCompositedLayers(const RenderLayer* rootLayer) const;
void ensureRootLayer();
void destroyRootLayer();
void attachRootLayer(RootLayerAttachment);
void detachRootLayer();
bool isMainFrame() const;
void updateOverflowControlsLayers();
void notifyIFramesOfCompositingChange();
Page* page() const;
GraphicsLayerFactory* graphicsLayerFactory() const;
ScrollingCoordinator* scrollingCoordinator() const;
void addViewportConstrainedLayer(RenderLayer*);
bool requiresHorizontalScrollbarLayer() const;
bool requiresVerticalScrollbarLayer() const;
bool requiresScrollCornerLayer() const;
#if USE(RUBBER_BANDING)
bool requiresOverhangLayers() const;
#endif
void applyUpdateLayerCompositingStateChickenEggHacks(RenderLayer*, CompositingStateTransitionType compositedLayerUpdate);
void assignLayersToBackingsForReflectionLayer(RenderLayer* reflectionLayer, bool& layersChanged);
private:
DocumentLifecycle& lifecycle() const;
RenderView& m_renderView;
OwnPtr<GraphicsLayer> m_rootContentLayer;
OwnPtr<GraphicsLayer> m_rootTransformLayer;
CompositingReasonFinder m_compositingReasonFinder;
CompositingUpdateType m_pendingUpdateType;
bool m_hasAcceleratedCompositing;
bool m_showRepaintCounter;
bool m_needsToRecomputeCompositingRequirements;
bool m_compositing;
bool m_compositingLayersNeedRebuild;
bool m_forceCompositingMode;
bool m_needsUpdateCompositingRequirementsState;
bool m_isTrackingRepaints;
RootLayerAttachment m_rootLayerAttachment;
OwnPtr<GraphicsLayer> m_containerLayer;
OwnPtr<GraphicsLayer> m_scrollLayer;
HashSet<RenderLayer*> m_viewportConstrainedLayers;
HashSet<RenderLayer*> m_viewportConstrainedLayersNeedingUpdate;
HashSet<RenderLayer*> m_outOfFlowPositionedLayers;
OwnPtr<GraphicsLayer> m_overflowControlsHostLayer;
OwnPtr<GraphicsLayer> m_layerForHorizontalScrollbar;
OwnPtr<GraphicsLayer> m_layerForVerticalScrollbar;
OwnPtr<GraphicsLayer> m_layerForScrollCorner;
#if USE(RUBBER_BANDING)
OwnPtr<GraphicsLayer> m_layerForOverhangShadow;
#endif
};
}
#endif