void GraphicsLayerUpdater::updateRecursive(RenderLayer& layer, UpdateType updateType, const UpdateContext& context, Vector<RenderLayer*>& layersNeedingPaintInvalidation) { if (layer.hasCompositedLayerMapping()) { CompositedLayerMapping* mapping = layer.compositedLayerMapping(); if (updateType == ForceUpdate || mapping->needsGraphicsLayerUpdate()) { const RenderLayer* compositingContainer = context.compositingContainer(layer); ASSERT(compositingContainer == layer.enclosingLayerWithCompositedLayerMapping(ExcludeSelf)); if (mapping->updateGraphicsLayerConfiguration()) m_needsRebuildTree = true; mapping->updateGraphicsLayerGeometry(compositingContainer, context.compositingStackingContext(), layersNeedingPaintInvalidation); if (mapping->hasUnpositionedOverflowControlsLayers()) layer.scrollableArea()->positionOverflowControls(IntSize()); updateType = mapping->updateTypeForChildren(updateType); mapping->clearNeedsGraphicsLayerUpdate(); } } UpdateContext childContext(context, layer); for (RenderLayer* child = layer.firstChild(); child; child = child->nextSibling()) updateRecursive(*child, updateType, childContext, layersNeedingPaintInvalidation); }
void CompositingRequirementsUpdater::update(PaintLayer* root) { TRACE_EVENT0("blink", "CompositingRequirementsUpdater::updateRecursive"); // Go through the layers in presentation order, so that we can compute which Layers need compositing layers. // FIXME: we could maybe do this and the hierarchy update in one pass, but the parenting logic would be more complex. RecursionData recursionData(root); OverlapMap overlapTestRequestMap; bool saw3DTransform = false; // FIXME: Passing these unclippedDescendants down and keeping track // of them dynamically, we are requiring a full tree walk. This // should be removed as soon as proper overlap testing based on // scrolling and animation bounds is implemented (crbug.com/252472). Vector<PaintLayer*> unclippedDescendants; IntRect absoluteDescendantBoundingBox; updateRecursive(0, root, overlapTestRequestMap, recursionData, saw3DTransform, unclippedDescendants, absoluteDescendantBoundingBox); }
void GraphicsLayerUpdater::update(RenderLayer& layer, Vector<RenderLayer*>& layersNeedingPaintInvalidation) { TRACE_EVENT0("blink", "GraphicsLayerUpdater::update"); updateRecursive(layer, DoNotForceUpdate, UpdateContext(), layersNeedingPaintInvalidation); layer.compositor()->updateRootLayerPosition(); }
void CompositingRequirementsUpdater::updateRecursive(PaintLayer* ancestorLayer, PaintLayer* layer, OverlapMap& overlapMap, RecursionData& currentRecursionData, bool& descendantHas3DTransform, Vector<PaintLayer*>& unclippedDescendants, IntRect& absoluteDescendantBoundingBox) { PaintLayerCompositor* compositor = m_layoutView.compositor(); layer->stackingNode()->updateLayerListsIfNeeded(); CompositingReasons reasonsToComposite = CompositingReasonNone; CompositingReasons directReasons = m_compositingReasonFinder.directReasons(layer); // Video is special. It's the only PaintLayer type that can both have // PaintLayer children and whose children can't use its backing to render // into. These children (the controls) always need to be promoted into their // own layers to draw on top of the accelerated video. if (currentRecursionData.m_compositingAncestor && currentRecursionData.m_compositingAncestor->layoutObject()->isVideo()) directReasons |= CompositingReasonVideoOverlay; if (currentRecursionData.m_hasCompositedScrollingAncestor && layer->layoutObject()->styleRef().hasViewportConstrainedPosition()) directReasons |= CompositingReasonPositionFixed; bool canBeComposited = compositor->canBeComposited(layer); if (canBeComposited) { reasonsToComposite |= directReasons; if (layer->isRootLayer() && compositor->rootShouldAlwaysComposite()) reasonsToComposite |= CompositingReasonRoot; if (reasonsToComposite && layer->scrollsOverflow() && !layer->needsCompositedScrolling()) { // We will only set needsCompositedScrolling if we don't care about // the LCD text hit, we may be able to switch to the compositor // driven path if we're alread composited for other reasons and are // therefore using grayscale AA. // // FIXME: it should also be possible to promote if the layer can // still use LCD text when promoted, but detecting when the // compositor can do this is tricky. Currently, the layer must be // both opaque and may only have an integer translation as its // transform. Both opacity and screen space transform are inherited // properties, so this cannot be determined from local information. layer->scrollableArea()->updateNeedsCompositedScrolling(PaintLayerScrollableArea::IgnoreLCDText); if (layer->needsCompositedScrolling()) reasonsToComposite |= CompositingReasonOverflowScrollingTouch; } } if ((reasonsToComposite & CompositingReasonOverflowScrollingTouch) && !layer->isRootLayer()) currentRecursionData.m_hasCompositedScrollingAncestor = true; // Next, accumulate reasons related to overlap. // If overlap testing is used, this reason will be overridden. If overlap testing is not // used, we must assume we overlap if there is anything composited behind us in paint-order. CompositingReasons overlapCompositingReason = currentRecursionData.m_subtreeIsCompositing ? CompositingReasonAssumedOverlap : CompositingReasonNone; if (currentRecursionData.m_hasCompositedScrollingAncestor) { Vector<size_t> unclippedDescendantsToRemove; for (size_t i = 0; i < unclippedDescendants.size(); i++) { PaintLayer* unclippedDescendant = unclippedDescendants.at(i); // If we've reached the containing block of one of the unclipped // descendants, that element is no longer relevant to whether or not we // should opt in. Unfortunately we can't easily remove from the list // while we're iterating, so we have to store it for later removal. if (unclippedDescendant->layoutObject()->containingBlock() == layer->layoutObject()) { unclippedDescendantsToRemove.append(i); continue; } if (layer->scrollsWithRespectTo(unclippedDescendant)) reasonsToComposite |= CompositingReasonAssumedOverlap; } // Remove irrelevant unclipped descendants in reverse order so our stored // indices remain valid. for (size_t i = 0; i < unclippedDescendantsToRemove.size(); i++) unclippedDescendants.remove(unclippedDescendantsToRemove.at(unclippedDescendantsToRemove.size() - i - 1)); if (reasonsToComposite & CompositingReasonOutOfFlowClipping) unclippedDescendants.append(layer); } const IntRect& absBounds = layer->clippedAbsoluteBoundingBox(); absoluteDescendantBoundingBox = absBounds; if (currentRecursionData.m_testingOverlap && !requiresCompositingOrSquashing(directReasons)) overlapCompositingReason = overlapMap.overlapsLayers(absBounds) ? CompositingReasonOverlap : CompositingReasonNone; reasonsToComposite |= overlapCompositingReason; // The children of this layer don't need to composite, unless there is // a compositing layer among them, so start by inheriting the compositing // ancestor with m_subtreeIsCompositing set to false. RecursionData childRecursionData = currentRecursionData; childRecursionData.m_subtreeIsCompositing = false; bool willBeCompositedOrSquashed = canBeComposited && requiresCompositingOrSquashing(reasonsToComposite); if (willBeCompositedOrSquashed) { // This layer now acts as the ancestor for kids. childRecursionData.m_compositingAncestor = layer; // Here we know that all children and the layer's own contents can blindly paint into // this layer's backing, until a descendant is composited. So, we don't need to check // for overlap with anything behind this layer. overlapMap.beginNewOverlapTestingContext(); // This layer is going to be composited, so children can safely ignore the fact that there's an // animation running behind this layer, meaning they can rely on the overlap map testing again. childRecursionData.m_testingOverlap = true; } #if ENABLE(ASSERT) LayerListMutationDetector mutationChecker(layer->stackingNode()); #endif bool anyDescendantHas3DTransform = false; bool willHaveForegroundLayer = false; if (layer->stackingNode()->isStackingContext()) { PaintLayerStackingNodeIterator iterator(*layer->stackingNode(), NegativeZOrderChildren); while (PaintLayerStackingNode* curNode = iterator.next()) { IntRect absoluteChildDescendantBoundingBox; updateRecursive(layer, curNode->layer(), overlapMap, childRecursionData, anyDescendantHas3DTransform, unclippedDescendants, absoluteChildDescendantBoundingBox); absoluteDescendantBoundingBox.unite(absoluteChildDescendantBoundingBox); // If we have to make a layer for this child, make one now so we can have a contents layer // (since we need to ensure that the -ve z-order child renders underneath our contents). if (childRecursionData.m_subtreeIsCompositing) { reasonsToComposite |= CompositingReasonNegativeZIndexChildren; if (!willBeCompositedOrSquashed) { // make layer compositing childRecursionData.m_compositingAncestor = layer; overlapMap.beginNewOverlapTestingContext(); willBeCompositedOrSquashed = true; willHaveForegroundLayer = true; // FIXME: temporary solution for the first negative z-index composited child: // re-compute the absBounds for the child so that we can add the // negative z-index child's bounds to the new overlap context. overlapMap.beginNewOverlapTestingContext(); overlapMap.add(curNode->layer(), curNode->layer()->clippedAbsoluteBoundingBox()); overlapMap.finishCurrentOverlapTestingContext(); } } } } if (willHaveForegroundLayer) { ASSERT(willBeCompositedOrSquashed); // A foreground layer effectively is a new backing for all subsequent children, so // we don't need to test for overlap with anything behind this. So, we can finish // the previous context that was accumulating rects for the negative z-index // children, and start with a fresh new empty context. overlapMap.finishCurrentOverlapTestingContext(); overlapMap.beginNewOverlapTestingContext(); // This layer is going to be composited, so children can safely ignore the fact that there's an // animation running behind this layer, meaning they can rely on the overlap map testing again childRecursionData.m_testingOverlap = true; } PaintLayerStackingNodeIterator iterator(*layer->stackingNode(), NormalFlowChildren | PositiveZOrderChildren); while (PaintLayerStackingNode* curNode = iterator.next()) { IntRect absoluteChildDescendantBoundingBox; updateRecursive(layer, curNode->layer(), overlapMap, childRecursionData, anyDescendantHas3DTransform, unclippedDescendants, absoluteChildDescendantBoundingBox); absoluteDescendantBoundingBox.unite(absoluteChildDescendantBoundingBox); } // Now that the subtree has been traversed, we can check for compositing reasons that depended on the state of the subtree. if (layer->stackingNode()->isStackingContext()) { layer->setShouldIsolateCompositedDescendants(childRecursionData.m_hasUnisolatedCompositedBlendingDescendant); } else { layer->setShouldIsolateCompositedDescendants(false); currentRecursionData.m_hasUnisolatedCompositedBlendingDescendant = childRecursionData.m_hasUnisolatedCompositedBlendingDescendant; } // Subsequent layers in the parent's stacking context may also need to composite. if (childRecursionData.m_subtreeIsCompositing) currentRecursionData.m_subtreeIsCompositing = true; // Set the flag to say that this SC has compositing children. layer->setHasCompositingDescendant(childRecursionData.m_subtreeIsCompositing); if (layer->isRootLayer()) { // The root layer needs to be composited if anything else in the tree is composited. // Otherwise, we can disable compositing entirely. if (childRecursionData.m_subtreeIsCompositing || requiresCompositingOrSquashing(reasonsToComposite) || compositor->rootShouldAlwaysComposite()) { reasonsToComposite |= CompositingReasonRoot; currentRecursionData.m_subtreeIsCompositing = true; } else { compositor->setCompositingModeEnabled(false); reasonsToComposite = CompositingReasonNone; } } else { // All layers (even ones that aren't being composited) need to get added to // the overlap map. Layers that are not separately composited will paint into their // compositing ancestor's backing, and so are still considered for overlap. if (childRecursionData.m_compositingAncestor && !childRecursionData.m_compositingAncestor->isRootLayer()) overlapMap.add(layer, absBounds); // Now check for reasons to become composited that depend on the state of descendant layers. CompositingReasons subtreeCompositingReasons = subtreeReasonsForCompositing(layer, childRecursionData.m_subtreeIsCompositing, anyDescendantHas3DTransform); reasonsToComposite |= subtreeCompositingReasons; if (!willBeCompositedOrSquashed && canBeComposited && requiresCompositingOrSquashing(subtreeCompositingReasons)) { childRecursionData.m_compositingAncestor = layer; // FIXME: this context push is effectively a no-op but needs to exist for // now, because the code is designed to push overlap information to the // second-from-top context of the stack. overlapMap.beginNewOverlapTestingContext(); overlapMap.add(layer, absoluteDescendantBoundingBox); willBeCompositedOrSquashed = true; } if (willBeCompositedOrSquashed) reasonsToComposite |= layer->potentialCompositingReasonsFromStyle() & CompositingReasonInlineTransform; // If the original layer is composited, the reflection needs to be, too. if (layer->reflectionInfo()) { // FIXME: Shouldn't we call computeCompositingRequirements to handle a reflection overlapping with another layoutObject? PaintLayer* reflectionLayer = layer->reflectionInfo()->reflectionLayer(); CompositingReasons reflectionCompositingReason = willBeCompositedOrSquashed ? CompositingReasonReflectionOfCompositedParent : CompositingReasonNone; reflectionLayer->setCompositingReasons(reflectionCompositingReason, CompositingReasonReflectionOfCompositedParent); } if (willBeCompositedOrSquashed && layer->layoutObject()->style()->hasBlendMode()) currentRecursionData.m_hasUnisolatedCompositedBlendingDescendant = true; // Tell the parent it has compositing descendants. if (willBeCompositedOrSquashed) currentRecursionData.m_subtreeIsCompositing = true; // Turn overlap testing off for later layers if it's already off, or if we have an animating transform. // Note that if the layer clips its descendants, there's no reason to propagate the child animation to the parent layers. That's because // we know for sure the animation is contained inside the clipping rectangle, which is already added to the overlap map. bool isCompositedClippingLayer = canBeComposited && (reasonsToComposite & CompositingReasonClipsCompositingDescendants); bool isCompositedWithInlineTransform = reasonsToComposite & CompositingReasonInlineTransform; if ((!childRecursionData.m_testingOverlap && !isCompositedClippingLayer) || layer->layoutObject()->style()->hasCurrentTransformAnimation() || isCompositedWithInlineTransform) currentRecursionData.m_testingOverlap = false; if (childRecursionData.m_compositingAncestor == layer) overlapMap.finishCurrentOverlapTestingContext(); descendantHas3DTransform |= anyDescendantHas3DTransform || layer->has3DTransform(); } // At this point we have finished collecting all reasons to composite this layer. layer->setCompositingReasons(reasonsToComposite); }
void CompositingInputsUpdater::updateRecursive(DeprecatedPaintLayer* layer, UpdateType updateType, AncestorInfo info) { if (!layer->childNeedsCompositingInputsUpdate() && updateType != ForceUpdate) return; m_geometryMap.pushMappingsToAncestor(layer, layer->parent()); if (layer->hasCompositedDeprecatedPaintLayerMapping()) info.enclosingCompositedLayer = layer; if (layer->needsCompositingInputsUpdate()) { if (info.enclosingCompositedLayer) info.enclosingCompositedLayer->compositedDeprecatedPaintLayerMapping()->setNeedsGraphicsLayerUpdate(GraphicsLayerUpdateSubtree); updateType = ForceUpdate; } if (updateType == ForceUpdate) { DeprecatedPaintLayer::AncestorDependentCompositingInputs properties; if (!layer->isRootLayer()) { properties.clippedAbsoluteBoundingBox = enclosingIntRect(m_geometryMap.absoluteRect(layer->boundingBoxForCompositingOverlapTest())); // FIXME: Setting the absBounds to 1x1 instead of 0x0 makes very little sense, // but removing this code will make JSGameBench sad. // See https://codereview.chromium.org/13912020/ if (properties.clippedAbsoluteBoundingBox.isEmpty()) properties.clippedAbsoluteBoundingBox.setSize(IntSize(1, 1)); IntRect clipRect = pixelSnappedIntRect(layer->clipper().backgroundClipRect(ClipRectsContext(m_rootLayer, AbsoluteClipRects)).rect()); properties.clippedAbsoluteBoundingBox.intersect(clipRect); const DeprecatedPaintLayer* parent = layer->parent(); properties.opacityAncestor = parent->isTransparent() ? parent : parent->opacityAncestor(); properties.transformAncestor = parent->hasTransformRelatedProperty() ? parent : parent->transformAncestor(); properties.filterAncestor = parent->hasFilter() ? parent : parent->filterAncestor(); bool layerIsFixedPosition = layer->layoutObject()->style()->position() == FixedPosition; properties.nearestFixedPositionLayer = layerIsFixedPosition ? layer : parent->nearestFixedPositionLayer(); if (info.hasAncestorWithClipOrOverflowClip) { const DeprecatedPaintLayer* parentLayerOnClippingContainerChain = findParentLayerOnClippingContainerChain(layer); const bool parentHasClipOrOverflowClip = parentLayerOnClippingContainerChain->layoutObject()->hasClipOrOverflowClip(); properties.clippingContainer = parentHasClipOrOverflowClip ? parentLayerOnClippingContainerChain->layoutObject() : parentLayerOnClippingContainerChain->clippingContainer(); } if (info.lastScrollingAncestor) { const LayoutObject* containingBlock = layer->layoutObject()->containingBlock(); const DeprecatedPaintLayer* parentLayerOnContainingBlockChain = findParentLayerOnContainingBlockChain(containingBlock); properties.ancestorScrollingLayer = parentLayerOnContainingBlockChain->ancestorScrollingLayer(); if (parentLayerOnContainingBlockChain->scrollsOverflow()) properties.ancestorScrollingLayer = parentLayerOnContainingBlockChain; if (layer->layoutObject()->isOutOfFlowPositioned() && !layer->subtreeIsInvisible()) { const DeprecatedPaintLayer* clippingLayer = properties.clippingContainer ? properties.clippingContainer->enclosingLayer() : layer->compositor()->rootLayer(); if (hasClippedStackingAncestor(layer, clippingLayer)) properties.clipParent = clippingLayer; } if (layer->stackingNode()->isTreatedAsStackingContextForPainting() && properties.ancestorScrollingLayer && !info.ancestorStackingContext->layoutObject()->isDescendantOf(properties.ancestorScrollingLayer->layoutObject())) properties.scrollParent = properties.ancestorScrollingLayer; } } properties.hasAncestorWithClipPath = info.hasAncestorWithClipPath; layer->updateAncestorDependentCompositingInputs(properties); } if (layer->stackingNode()->isStackingContext()) info.ancestorStackingContext = layer; if (layer->scrollsOverflow()) info.lastScrollingAncestor = layer; if (layer->layoutObject()->hasClipOrOverflowClip()) info.hasAncestorWithClipOrOverflowClip = true; if (layer->layoutObject()->hasClipPath()) info.hasAncestorWithClipPath = true; DeprecatedPaintLayer::DescendantDependentCompositingInputs descendantProperties; for (DeprecatedPaintLayer* child = layer->firstChild(); child; child = child->nextSibling()) { updateRecursive(child, updateType, info); descendantProperties.hasDescendantWithClipPath |= child->hasDescendantWithClipPath() || child->layoutObject()->hasClipPath(); descendantProperties.hasNonIsolatedDescendantWithBlendMode |= (!child->stackingNode()->isStackingContext() && child->hasNonIsolatedDescendantWithBlendMode()) || child->layoutObject()->style()->hasBlendMode(); } layer->updateDescendantDependentCompositingInputs(descendantProperties); layer->didUpdateCompositingInputs(); m_geometryMap.popMappingsToAncestor(layer->parent()); }
void CompositingInputsUpdater::update() { TRACE_EVENT0("blink", "CompositingInputsUpdater::update"); updateRecursive(m_rootLayer, DoNotForceUpdate, AncestorInfo()); }