Chromium Code Reviews| Index: Source/core/rendering/CompositedLayerMapping.cpp |
| diff --git a/Source/core/rendering/CompositedLayerMapping.cpp b/Source/core/rendering/CompositedLayerMapping.cpp |
| index 383e2d1ba84bd928b8aa8844e554940253280754..2bc3855b0f7c0cf05d234c26df3f272aecc56204 100644 |
| --- a/Source/core/rendering/CompositedLayerMapping.cpp |
| +++ b/Source/core/rendering/CompositedLayerMapping.cpp |
| @@ -159,6 +159,7 @@ static ScrollingCoordinator* scrollingCoordinatorFromLayer(RenderLayer* layer) |
| CompositedLayerMapping::CompositedLayerMapping(RenderLayer* layer) |
| : m_owningLayer(layer) |
| , m_animationProvider(adoptPtr(new WebAnimationProvider)) |
| + , m_nextSquashedLayerIndex(0x0fff0000) |
| , m_artificiallyInflatedBounds(false) |
| , m_boundsConstrainedByClipping(false) |
| , m_isMainFrameRenderViewLayer(false) |
| @@ -175,6 +176,13 @@ CompositedLayerMapping::CompositedLayerMapping(RenderLayer* layer) |
| CompositedLayerMapping::~CompositedLayerMapping() |
| { |
| + // FIXME: this almost certainly needs to go somewhere more appropriate so it occurs |
| + // when things change as well as things getting destroyed. |
| + for (size_t i = 0; i < m_squashedLayers.size(); ++i) { |
| + if (m_squashedLayers[i].renderLayer->compositingState() == PaintsIntoGroupedBacking) |
| + m_squashedLayers[i].renderLayer->setGroupedMapping(0); |
| + } |
| + |
| updateClippingLayers(false, false); |
| updateOverflowControlsLayers(false, false, false); |
| updateForegroundLayer(false); |
| @@ -182,6 +190,7 @@ CompositedLayerMapping::~CompositedLayerMapping() |
| updateMaskLayer(false); |
| updateClippingMaskLayers(false); |
| updateScrollingLayers(false); |
| + updateSquashingLayers(false); |
| destroyGraphicsLayers(); |
| } |
| @@ -457,6 +466,9 @@ bool CompositedLayerMapping::updateGraphicsLayerConfiguration() |
| updateScrollParent(scrollParent); |
| updateClipParent(m_owningLayer->clipParent()); |
| + if (updateSquashingLayers(!m_squashedLayers.isEmpty())) |
| + layerConfigChanged = true; |
| + |
| if (layerConfigChanged) |
| updateInternalHierarchy(); |
| @@ -566,6 +578,7 @@ void CompositedLayerMapping::updateGraphicsLayerGeometry() |
| // We compute everything relative to the enclosing compositing layer. |
| IntRect ancestorCompositingBounds; |
| if (compAncestor) { |
| + // FIXME: is it correct to fix the ASSERT by adding the squashing condition here, too? |
| ASSERT(compAncestor->hasCompositedLayerMapping()); |
| ancestorCompositingBounds = pixelSnappedIntRect(compAncestor->compositedLayerMapping()->compositedBounds()); |
| } |
| @@ -780,6 +793,44 @@ void CompositedLayerMapping::updateGraphicsLayerGeometry() |
| } |
| } |
| + if (m_squashingLayer) { |
| + ASSERT(compositor()->isLayerSquashingEnabled()); |
| + |
| + IntRect totalSquashBounds; |
| + for (size_t i = 0; i < m_squashedLayers.size(); ++i) { |
| + IntRect squashedBounds = compositor()->calculateCompositedBounds(m_squashedLayers[i].renderLayer, m_squashedLayers[i].renderLayer); |
| + |
| + // Store the composited bounds before applying the offset. |
| + // FIXME: do we need to? is it better for some reason? |
| + m_squashedLayers[i].compositedBounds = squashedBounds; |
| + |
| + squashedBounds.move(m_squashedLayers[i].offsetFromBackingRoot); |
| + totalSquashBounds.unite(squashedBounds); |
| + } |
| + |
| + IntPoint squashLayerPosition; |
| + if (m_ancestorClippingLayer) { |
| + squashLayerPosition = IntPoint(m_ancestorClippingLayer->position().x() + totalSquashBounds.location().x(), |
| + m_ancestorClippingLayer->position().y() + totalSquashBounds.location().y()); |
| + } else { |
| + squashLayerPosition = IntPoint(m_graphicsLayer->position().x() + totalSquashBounds.location().x(), |
| + m_graphicsLayer->position().y() + totalSquashBounds.location().y()); |
| + } |
| + |
| + m_squashingLayer->setPosition(squashLayerPosition); |
| + m_squashingLayer->setSize(totalSquashBounds.size()); |
| + |
| + // Now that the position of the squashing layer is known, update the offsets for each squashed RenderLayer. |
| + // FIXME: find a cleaner way to compute renderer offsets, hopefully that supports transforms, too? |
| + for (size_t i = 0; i < m_squashedLayers.size(); ++i) { |
| + m_squashedLayers[i].offsetFromRenderer = IntSize(-m_squashedLayers[i].offsetFromBackingRoot.width() - m_graphicsLayer->position().x() + m_squashingLayer->position().x(), |
| + -m_squashedLayers[i].offsetFromBackingRoot.height() - m_graphicsLayer->position().y() + m_squashingLayer->position().y()); |
| + |
| + // FIXME: find a better design to avoid this redundant value |
| + m_squashedLayers[i].renderLayer->setOffsetFromSquashingLayerOrigin(m_squashedLayers[i].offsetFromRenderer); |
| + } |
| + } |
| + |
| if (m_owningLayer->scrollableArea()) |
| m_owningLayer->scrollableArea()->positionOverflowControls(); |
| @@ -853,6 +904,19 @@ void CompositedLayerMapping::updateInternalHierarchy() |
| m_layerForScrollCorner->removeFromParent(); |
| m_graphicsLayer->addChild(m_layerForScrollCorner.get()); |
| } |
| + |
| + // The squashing containment layer, if it exists, becomes a no-op parent. |
| + if (m_squashingLayer) { |
| + ASSERT(compositor()->isLayerSquashingEnabled()); |
| + ASSERT(m_squashingContainmentLayer); |
| + |
| + if (m_ancestorClippingLayer) |
| + m_squashingContainmentLayer->addChild(m_ancestorClippingLayer.get()); |
| + else |
| + m_squashingContainmentLayer->addChild(m_graphicsLayer.get()); |
| + |
| + m_squashingContainmentLayer->addChild(m_squashingLayer.get()); |
| + } |
| } |
| void CompositedLayerMapping::updateContentsRect(bool isSimpleContainer) |
| @@ -1179,6 +1243,8 @@ bool CompositedLayerMapping::updateScrollingLayers(bool needsScrollingLayers) |
| void CompositedLayerMapping::updateScrollParent(RenderLayer* scrollParent) |
| { |
| + // FIXME: Either the asserts or the code in his function are broken for squashing. (I think it's the asserts?) |
| + |
| if (ScrollingCoordinator* scrollingCoordinator = scrollingCoordinatorFromLayer(m_owningLayer)) { |
| if (m_ancestorClippingLayer) { |
| ASSERT(childForSuperlayers() == m_ancestorClippingLayer.get()); |
| @@ -1200,6 +1266,50 @@ void CompositedLayerMapping::updateClipParent(RenderLayer* clipParent) |
| scrollingCoordinator->updateClipParentForGraphicsLayer(m_graphicsLayer.get(), clipParent); |
| } |
| +bool CompositedLayerMapping::updateSquashingLayers(bool needsSquashingLayers) |
| +{ |
| + bool layersChanged = false; |
| + |
| + if (needsSquashingLayers) { |
| + ASSERT(compositor()->isLayerSquashingEnabled()); |
| + |
| + if (!m_squashingLayer) { |
| + m_squashingLayer = createGraphicsLayer(CompositingReasonOverlap); |
| + m_squashingLayer->setDrawsContent(true); |
| + m_squashingLayer->setNeedsDisplay(); |
| + layersChanged = true; |
| + } |
| + |
| + if (!m_squashingContainmentLayer) { |
| + // FIXME: containment layer needs a new CompositingReason, CompositingReasonOverlap is not appropriate. |
| + m_squashingContainmentLayer = createGraphicsLayer(CompositingReasonOverlap); |
| + // FIXME: reflections should force transform-style to be flat in the style: https://bugs.webkit.org/show_bug.cgi?id=106959 |
| + bool preserves3D = renderer()->style()->transformStyle3D() == TransformStyle3DPreserve3D && !renderer()->hasReflection(); |
| + m_squashingContainmentLayer->setPreserves3D(preserves3D); |
| + layersChanged = true; |
| + } |
| + |
| + ASSERT(m_squashingLayer && m_squashingContainmentLayer); |
| + } else { |
| + if (m_squashingLayer) { |
| + m_squashingLayer->removeFromParent(); |
| + m_squashingLayer = nullptr; |
| + layersChanged = true; |
| + // FIXME: do we need to invalidate something here? |
| + } |
| + |
| + if (m_squashingContainmentLayer) { |
| + m_squashingContainmentLayer->removeFromParent(); |
| + m_squashingContainmentLayer = nullptr; |
| + layersChanged = true; |
| + } |
| + |
| + ASSERT(!m_squashingLayer && !m_squashingContainmentLayer); |
| + } |
| + |
| + return layersChanged; |
| +} |
| + |
| GraphicsLayerPaintingPhase CompositedLayerMapping::paintingPhaseForPrimaryLayer() const |
| { |
| unsigned phase = 0; |
| @@ -1541,6 +1651,9 @@ GraphicsLayer* CompositedLayerMapping::parentForSublayers() const |
| GraphicsLayer* CompositedLayerMapping::childForSuperlayers() const |
| { |
| + if (m_squashingContainmentLayer) |
| + return m_squashingContainmentLayer.get(); |
| + |
| if (m_ancestorClippingLayer) |
| return m_ancestorClippingLayer.get(); |
| @@ -1708,14 +1821,20 @@ void CompositedLayerMapping::doPaintTask(GraphicsLayerPaintInfo& paintInfo, Grap |
| paintInfo.renderLayer->renderer()->assertSubtreeIsLaidOut(); |
| #endif |
| - // FIXME: GraphicsLayers need a way to split for RenderRegions. |
| - LayerPaintingInfo paintingInfo(paintInfo.renderLayer, dirtyRect, PaintBehaviorNormal, LayoutSize()); |
| - paintInfo.renderLayer->paintLayerContents(context, paintingInfo, paintFlags); |
| + if (paintInfo.renderLayer->compositingState() != PaintsIntoGroupedBacking) { |
| + // FIXME: GraphicsLayers need a way to split for RenderRegions. |
| + LayerPaintingInfo paintingInfo(paintInfo.renderLayer, dirtyRect, PaintBehaviorNormal, LayoutSize()); |
| + paintInfo.renderLayer->paintLayerContents(context, paintingInfo, paintFlags); |
| - ASSERT(!paintInfo.isBackgroundLayer || paintFlags & PaintLayerPaintingRootBackgroundOnly); |
| + ASSERT(!paintInfo.isBackgroundLayer || paintFlags & PaintLayerPaintingRootBackgroundOnly); |
| - if (paintInfo.renderLayer->containsDirtyOverlayScrollbars()) |
| - paintInfo.renderLayer->paintLayerContents(context, paintingInfo, paintFlags | PaintLayerPaintingOverlayScrollbars); |
| + if (paintInfo.renderLayer->containsDirtyOverlayScrollbars()) |
| + paintInfo.renderLayer->paintLayerContents(context, paintingInfo, paintFlags | PaintLayerPaintingOverlayScrollbars); |
| + } else { |
| + ASSERT(compositor()->isLayerSquashingEnabled()); |
| + LayerPaintingInfo paintingInfo(paintInfo.renderLayer, dirtyRect, PaintBehaviorNormal, LayoutSize()); |
| + paintInfo.renderLayer->paintLayer(context, paintingInfo, paintFlags); |
| + } |
| ASSERT(!paintInfo.renderLayer->m_usedTransparency); |
| @@ -1762,6 +1881,10 @@ void CompositedLayerMapping::paintContents(const GraphicsLayer* graphicsLayer, G |
| // We have to use the same root as for hit testing, because both methods can compute and cache clipRects. |
| doPaintTask(paintInfo, &context, clip); |
| + } else if (graphicsLayer == m_squashingLayer.get()) { |
| + ASSERT(compositor()->isLayerSquashingEnabled()); |
| + for (size_t i = 0; i < m_squashedLayers.size(); ++i) |
| + doPaintTask(m_squashedLayers[i], &context, clip); |
| } else if (graphicsLayer == layerForHorizontalScrollbar()) { |
| paintScrollbar(m_owningLayer->scrollableArea()->horizontalScrollbar(), context, clip); |
| } else if (graphicsLayer == layerForVerticalScrollbar()) { |
| @@ -1957,6 +2080,71 @@ void CompositedLayerMapping::setCompositedBounds(const IntRect& bounds) |
| m_compositedBounds = bounds; |
| } |
| +void CompositedLayerMapping::addRenderLayerToSquashingGraphicsLayer(RenderLayer* layer, IntSize offsetFromTargetBacking) |
| +{ |
| + ASSERT(compositor()->isLayerSquashingEnabled()); |
| + ASSERT(m_nextSquashedLayerIndex >= 0 && m_nextSquashedLayerIndex < 0x0fff0000); |
| + |
| + // Temporary release mode sanity check |
| + if (m_nextSquashedLayerIndex == 0x0fff0000) { |
|
enne (OOO)
2013/11/27 23:20:26
There's just something about temporary and "only v
shawnsingh
2013/12/02 01:55:03
Done - new patch is indeed much more elegant about
|
| + fprintf(stderr, "ERROR - trying to addRenderLayerToSquashingGraphicsLayer() outside of begin/finish\n"); |
| + exit(1); |
| + } |
| + |
| + GraphicsLayerPaintInfo paintInfo; |
| + paintInfo.renderLayer = layer; |
| + // NOTE: composited bounds are updated elsewhere |
| + // NOTE: offsetFromRenderer is updated elsewhere |
| + paintInfo.offsetFromBackingRoot = offsetFromTargetBacking; |
| + paintInfo.paintingPhase = GraphicsLayerPaintAllWithOverflowClip; |
| + paintInfo.isBackgroundLayer = false; |
| + |
| + // Change tracking on squashing layers: at the first sign of something changed, just invalidate the layer. |
| + // FIXME: Perhaps we can find a tighter more clever mechanism later. |
| + if (m_nextSquashedLayerIndex < m_squashedLayers.size()) { |
| + if (m_squashedLayers[m_nextSquashedLayerIndex].renderLayer != layer) { |
| + m_squashedLayers[m_nextSquashedLayerIndex] = paintInfo; |
| + m_squashingLayer->setNeedsDisplay(); |
| + } |
| + } else { |
| + m_squashedLayers.append(paintInfo); |
| + if (m_squashingLayer) |
| + m_squashingLayer->setNeedsDisplay(); |
| + } |
| + m_nextSquashedLayerIndex++; |
| + |
| + layer->setGroupedMapping(this); |
| +} |
| + |
| +void CompositedLayerMapping::beginAccumulatingSquashingLayers() |
| +{ |
| + ASSERT(compositor()->isLayerSquashingEnabled()); |
| + ASSERT(m_nextSquashedLayerIndex == 0x0fff0000); |
| + |
| + // temporary release mode sanity check |
| + if (m_nextSquashedLayerIndex != 0x0fff0000) { |
| + fprintf(stderr, "ERROR - DID NOT EXPECT 0x0fff000 here, got %lu instead\n", m_nextSquashedLayerIndex); |
| + exit(1); |
| + } |
| + |
| + m_nextSquashedLayerIndex = 0; |
| +} |
| + |
| +void CompositedLayerMapping::finishAccumulatingSquashingLayers() |
| +{ |
| + ASSERT(compositor()->isLayerSquashingEnabled()); |
| + |
| + // Any additional squashed RenderLayers in the array no longer exist, and removing invalidates the squashingLayer contents. |
| + if (m_nextSquashedLayerIndex < m_squashedLayers.size()) { |
| + m_squashedLayers.remove(m_nextSquashedLayerIndex, m_squashedLayers.size() - m_nextSquashedLayerIndex); |
| + if (m_squashingLayer) |
| + m_squashingLayer->setNeedsDisplay(); |
| + } |
| + |
| + // FIXME: do something better than this encoded hack. This value is size_t and shouldn't be negative anyway. |
| + m_nextSquashedLayerIndex = 0x0fff0000; |
| +} |
| + |
| CompositingLayerType CompositedLayerMapping::compositingLayerType() const |
| { |
| if (m_graphicsLayer->hasContentsLayer()) |