2 * Copyright (C) 2009, 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2014 Google Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include "core/rendering/compositing/GraphicsLayerTreeBuilder.h"
30 #include "core/html/HTMLMediaElement.h"
31 #include "core/html/HTMLVideoElement.h"
32 #include "core/rendering/RenderLayer.h"
33 #include "core/rendering/RenderLayerReflectionInfo.h"
34 #include "core/rendering/RenderPart.h"
35 #include "core/rendering/RenderView.h"
36 #include "core/rendering/compositing/CompositedLayerMapping.h"
37 #include "core/rendering/compositing/RenderLayerCompositor.h"
41 GraphicsLayerTreeBuilder::GraphicsLayerTreeBuilder()
45 GraphicsLayerTreeBuilder::~GraphicsLayerTreeBuilder()
49 static bool shouldAppendLayer(const RenderLayer& layer)
51 if (!RuntimeEnabledFeatures::overlayFullscreenVideoEnabled())
53 Node* node = layer.renderer()->node();
54 if (node && isHTMLVideoElement(*node)) {
55 HTMLVideoElement* element = toHTMLVideoElement(node);
56 // For WebRTC, video frame contains all the data and no hardware surface is used.
57 // We should always append the layer in this case.
58 if (element->isFullscreen() && !HTMLMediaElement::isMediaStreamURL(element->sourceURL().string()))
64 void GraphicsLayerTreeBuilder::rebuild(RenderLayer& layer, AncestorInfo info)
66 // Make the layer compositing if necessary, and set up clipping and content layers.
67 // Note that we can only do work here that is independent of whether the descendant layers
68 // have been processed. computeCompositingRequirements() will already have done the paint invalidation if necessary.
70 layer.stackingNode()->updateLayerListsIfNeeded();
72 const bool hasCompositedLayerMapping = layer.hasCompositedLayerMapping();
73 CompositedLayerMapping* currentCompositedLayerMapping = layer.compositedLayerMapping();
75 // If this layer has a compositedLayerMapping, then that is where we place subsequent children GraphicsLayers.
76 // Otherwise children continue to append to the child list of the enclosing layer.
77 GraphicsLayerVector layerChildren;
78 AncestorInfo infoForChildren(info);
79 if (hasCompositedLayerMapping) {
80 infoForChildren.childLayersOfEnclosingCompositedLayer = &layerChildren;
81 infoForChildren.enclosingCompositedLayer = &layer;
85 LayerListMutationDetector mutationChecker(layer.stackingNode());
88 if (layer.stackingNode()->isStackingContext()) {
89 RenderLayerStackingNodeIterator iterator(*layer.stackingNode(), NegativeZOrderChildren);
90 while (RenderLayerStackingNode* curNode = iterator.next())
91 rebuild(*curNode->layer(), infoForChildren);
93 // If a negative z-order child is compositing, we get a foreground layer which needs to get parented.
94 if (hasCompositedLayerMapping && currentCompositedLayerMapping->foregroundLayer())
95 infoForChildren.childLayersOfEnclosingCompositedLayer->append(currentCompositedLayerMapping->foregroundLayer());
98 RenderLayerStackingNodeIterator iterator(*layer.stackingNode(), NormalFlowChildren | PositiveZOrderChildren);
99 while (RenderLayerStackingNode* curNode = iterator.next())
100 rebuild(*curNode->layer(), infoForChildren);
102 if (hasCompositedLayerMapping) {
103 bool parented = false;
104 if (layer.renderer()->isRenderPart())
105 parented = RenderLayerCompositor::parentFrameContentLayers(toRenderPart(layer.renderer()));
108 currentCompositedLayerMapping->parentForSublayers()->setChildren(layerChildren);
110 // If the layer has a clipping layer the overflow controls layers will be siblings of the clipping layer.
111 // Otherwise, the overflow control layers are normal children.
112 // FIXME: Why isn't this handled in CLM updateInternalHierarchy?
113 if (!currentCompositedLayerMapping->hasClippingLayer() && !currentCompositedLayerMapping->hasScrollingLayer()) {
114 if (GraphicsLayer* overflowControlLayer = currentCompositedLayerMapping->layerForHorizontalScrollbar()) {
115 overflowControlLayer->removeFromParent();
116 currentCompositedLayerMapping->parentForSublayers()->addChild(overflowControlLayer);
119 if (GraphicsLayer* overflowControlLayer = currentCompositedLayerMapping->layerForVerticalScrollbar()) {
120 overflowControlLayer->removeFromParent();
121 currentCompositedLayerMapping->parentForSublayers()->addChild(overflowControlLayer);
124 if (GraphicsLayer* overflowControlLayer = currentCompositedLayerMapping->layerForScrollCorner()) {
125 overflowControlLayer->removeFromParent();
126 currentCompositedLayerMapping->parentForSublayers()->addChild(overflowControlLayer);
130 if (shouldAppendLayer(layer))
131 info.childLayersOfEnclosingCompositedLayer->append(currentCompositedLayerMapping->childForSuperlayers());
134 if (layer.scrollParent()
135 && layer.scrollParent()->hasCompositedLayerMapping()
136 && layer.scrollParent()->compositedLayerMapping()->needsToReparentOverflowControls()
137 && layer.scrollParent()->scrollableArea()->topmostScrollChild() == &layer)
138 info.childLayersOfEnclosingCompositedLayer->append(layer.scrollParent()->compositedLayerMapping()->detachLayerForOverflowControls(*info.enclosingCompositedLayer));