PassRefPtr<TypeBuilder::Array<TypeBuilder::LayerTree::Layer> > InspectorLayerTreeAgent::buildLayerTree() { PaintLayerCompositor* compositor = paintLayerCompositor(); if (!compositor || !compositor->inCompositingMode()) return nullptr; LayerIdToNodeIdMap layerIdToNodeIdMap; RefPtr<TypeBuilder::Array<TypeBuilder::LayerTree::Layer> > layers = TypeBuilder::Array<TypeBuilder::LayerTree::Layer>::create(); buildLayerIdToNodeIdMap(compositor->rootLayer(), layerIdToNodeIdMap); gatherGraphicsLayers(rootGraphicsLayer(), layerIdToNodeIdMap, layers); return layers.release(); }
bool PaintLayerCompositor::attachFrameContentLayersToIframeLayer(LayoutPart* layoutObject) { PaintLayerCompositor* innerCompositor = frameContentsCompositor(layoutObject); if (!innerCompositor || !innerCompositor->staleInCompositingMode() || innerCompositor->rootLayerAttachment() != RootLayerAttachedViaEnclosingFrame) return false; PaintLayer* layer = layoutObject->layer(); if (!layer->hasCompositedLayerMapping()) return false; layer->compositedLayerMapping()->setSublayers(GraphicsLayerVector(1, innerCompositor->rootGraphicsLayer())); return true; }
WebLayer* getRootScrollLayer() { if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) { DCHECK(frame()); DCHECK(frame()->view()); DCHECK(frame()->view()->layoutViewportScrollableArea()); DCHECK( frame()->view()->layoutViewportScrollableArea()->layerForScrolling()); return frame() ->view() ->layoutViewportScrollableArea() ->layerForScrolling() ->platformLayer(); } PaintLayerCompositor* compositor = frame()->contentLayoutItem().compositor(); DCHECK(compositor); DCHECK(compositor->scrollLayer()); WebLayer* webScrollLayer = compositor->scrollLayer()->platformLayer(); return webScrollLayer; }
TEST_F(ScrollingCoordinatorTest, rtlIframe) { registerMockedHttpURLLoad("rtl-iframe.html"); registerMockedHttpURLLoad("rtl-iframe-inner.html"); navigateTo(m_baseURL + "rtl-iframe.html"); forceFullCompositingUpdate(); // Verify the properties of the accelerated scrolling element starting from the LayoutObject // all the way to the WebLayer. Element* scrollableFrame = frame()->document()->getElementById("scrollable"); ASSERT_TRUE(scrollableFrame); LayoutObject* layoutObject = scrollableFrame->layoutObject(); ASSERT_TRUE(layoutObject); ASSERT_TRUE(layoutObject->isLayoutPart()); LayoutPart* layoutPart = toLayoutPart(layoutObject); ASSERT_TRUE(layoutPart); ASSERT_TRUE(layoutPart->widget()); ASSERT_TRUE(layoutPart->widget()->isFrameView()); FrameView* innerFrameView = toFrameView(layoutPart->widget()); LayoutView* innerLayoutView = innerFrameView->layoutView(); ASSERT_TRUE(innerLayoutView); PaintLayerCompositor* innerCompositor = innerLayoutView->compositor(); ASSERT_TRUE(innerCompositor->inCompositingMode()); ASSERT_TRUE(innerCompositor->scrollLayer()); GraphicsLayer* scrollLayer = innerCompositor->scrollLayer(); ASSERT_EQ(innerFrameView, scrollLayer->scrollableArea()); WebLayer* webScrollLayer = scrollLayer->platformLayer(); ASSERT_TRUE(webScrollLayer->scrollable()); int expectedScrollPosition = 958 + (innerFrameView->verticalScrollbar()->isOverlayScrollbar() ? 0 : 15); ASSERT_EQ(expectedScrollPosition, webScrollLayer->scrollPositionDouble().x); }
void VisualViewport::registerLayersWithTreeView(WebLayerTreeView* layerTreeView) const { TRACE_EVENT0("blink", "VisualViewport::registerLayersWithTreeView"); ASSERT(layerTreeView); if (!mainFrame()) return; ASSERT(frameHost().page().deprecatedLocalMainFrame()->contentLayoutObject()); PaintLayerCompositor* compositor = frameHost().page().deprecatedLocalMainFrame()->contentLayoutObject()->compositor(); // Get the outer viewport scroll layer. WebLayer* scrollLayer = compositor->scrollLayer() ? compositor->scrollLayer()->platformLayer() : 0; m_webOverlayScrollbarHorizontal->setScrollLayer(scrollLayer); m_webOverlayScrollbarVertical->setScrollLayer(scrollLayer); ASSERT(compositor); layerTreeView->registerViewportLayers( m_overscrollElasticityLayer->platformLayer(), m_pageScaleLayer->platformLayer(), m_innerViewportScrollLayer->platformLayer(), scrollLayer); }
std::unique_ptr<Array<protocol::LayerTree::Layer>> InspectorLayerTreeAgent::buildLayerTree() { PaintLayerCompositor* compositor = paintLayerCompositor(); if (!compositor || !compositor->inCompositingMode()) return nullptr; LayerIdToNodeIdMap layerIdToNodeIdMap; std::unique_ptr<Array<protocol::LayerTree::Layer>> layers = Array<protocol::LayerTree::Layer>::create(); buildLayerIdToNodeIdMap(compositor->rootLayer(), layerIdToNodeIdMap); int scrollingLayerId = m_inspectedFrames->root() ->view() ->layerForScrolling() ->platformLayer() ->id(); bool haveBlockingWheelEventHandlers = m_inspectedFrames->root()->chromeClient().eventListenerProperties( WebEventListenerClass::MouseWheel) == WebEventListenerProperties::Blocking; gatherGraphicsLayers(rootGraphicsLayer(), layerIdToNodeIdMap, layers, haveBlockingWheelEventHandlers, scrollingLayerId); return layers; }
TEST_F(ScrollingCoordinatorTest, iframeScrolling) { registerMockedHttpURLLoad("iframe-scrolling.html"); registerMockedHttpURLLoad("iframe-scrolling-inner.html"); navigateTo(m_baseURL + "iframe-scrolling.html"); forceFullCompositingUpdate(); // Verify the properties of the accelerated scrolling element starting from the LayoutObject // all the way to the WebLayer. Element* scrollableFrame = frame()->document()->getElementById("scrollable"); ASSERT_TRUE(scrollableFrame); LayoutObject* layoutObject = scrollableFrame->layoutObject(); ASSERT_TRUE(layoutObject); ASSERT_TRUE(layoutObject->isLayoutPart()); LayoutPart* layoutPart = toLayoutPart(layoutObject); ASSERT_TRUE(layoutPart); ASSERT_TRUE(layoutPart->widget()); ASSERT_TRUE(layoutPart->widget()->isFrameView()); FrameView* innerFrameView = toFrameView(layoutPart->widget()); LayoutView* innerLayoutView = innerFrameView->layoutView(); ASSERT_TRUE(innerLayoutView); PaintLayerCompositor* innerCompositor = innerLayoutView->compositor(); ASSERT_TRUE(innerCompositor->inCompositingMode()); ASSERT_TRUE(innerCompositor->scrollLayer()); GraphicsLayer* scrollLayer = innerCompositor->scrollLayer(); ASSERT_EQ(innerFrameView, scrollLayer->scrollableArea()); WebLayer* webScrollLayer = scrollLayer->platformLayer(); ASSERT_TRUE(webScrollLayer->scrollable()); #if OS(ANDROID) // Now verify we've attached impl-side scrollbars onto the scrollbar layers ASSERT_TRUE(innerCompositor->layerForHorizontalScrollbar()); ASSERT_TRUE(innerCompositor->layerForHorizontalScrollbar()->hasContentsLayer()); ASSERT_TRUE(innerCompositor->layerForVerticalScrollbar()); ASSERT_TRUE(innerCompositor->layerForVerticalScrollbar()->hasContentsLayer()); #endif }
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); }
bool PaintLayerCompositor::allocateOrClearCompositedLayerMapping(PaintLayer* layer, const CompositingStateTransitionType compositedLayerUpdate) { bool compositedLayerMappingChanged = false; // FIXME: It would be nice to directly use the layer's compositing reason, // but allocateOrClearCompositedLayerMapping also gets called without having updated compositing // requirements fully. switch (compositedLayerUpdate) { case AllocateOwnCompositedLayerMapping: ASSERT(!layer->hasCompositedLayerMapping()); setCompositingModeEnabled(true); // If we need to issue paint invalidations, do so before allocating the compositedLayerMapping and clearing out the groupedMapping. paintInvalidationOnCompositingChange(layer); // If this layer was previously squashed, we need to remove its reference to a groupedMapping right away, so // that computing paint invalidation rects will know the layer's correct compositingState. // FIXME: do we need to also remove the layer from it's location in the squashing list of its groupedMapping? // Need to create a test where a squashed layer pops into compositing. And also to cover all other // sorts of compositingState transitions. layer->setLostGroupedMapping(false); layer->setGroupedMapping(nullptr, PaintLayer::InvalidateLayerAndRemoveFromMapping); layer->ensureCompositedLayerMapping(); compositedLayerMappingChanged = true; // At this time, the ScrollingCooridnator only supports the top-level frame. if (layer->isRootLayer() && m_layoutView.frame()->isLocalRoot()) { if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator()) scrollingCoordinator->frameViewRootLayerDidChange(m_layoutView.frameView()); } break; case RemoveOwnCompositedLayerMapping: // PutInSquashingLayer means you might have to remove the composited layer mapping first. case PutInSquashingLayer: if (layer->hasCompositedLayerMapping()) { // If we're removing the compositedLayerMapping from a reflection, clear the source GraphicsLayer's pointer to // its replica GraphicsLayer. In practice this should never happen because reflectee and reflection // are both either composited, or not composited. if (layer->isReflection()) { PaintLayer* sourceLayer = toLayoutBoxModelObject(layer->layoutObject()->parent())->layer(); if (sourceLayer->hasCompositedLayerMapping()) { ASSERT(sourceLayer->compositedLayerMapping()->mainGraphicsLayer()->replicaLayer() == layer->compositedLayerMapping()->mainGraphicsLayer()); sourceLayer->compositedLayerMapping()->mainGraphicsLayer()->setReplicatedByLayer(nullptr); } } layer->clearCompositedLayerMapping(); compositedLayerMappingChanged = true; } break; case RemoveFromSquashingLayer: case NoCompositingStateChange: // Do nothing. break; } if (compositedLayerMappingChanged && layer->layoutObject()->isLayoutPart()) { PaintLayerCompositor* innerCompositor = frameContentsCompositor(toLayoutPart(layer->layoutObject())); if (innerCompositor && innerCompositor->staleInCompositingMode()) innerCompositor->updateRootLayerAttachment(); } if (compositedLayerMappingChanged) layer->clipper().clearClipRectsIncludingDescendants(PaintingClipRects); // If a fixed position layer gained/lost a compositedLayerMapping or the reason not compositing it changed, // the scrolling coordinator needs to recalculate whether it can do fast scrolling. if (compositedLayerMappingChanged) { if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator()) scrollingCoordinator->frameViewFixedObjectsDidChange(m_layoutView.frameView()); } return compositedLayerMappingChanged; }