1 /* 2 * Copyright (C) 2009, 2010 Apple Inc. All rights reserved. 3 * Copyright (C) 2014 Google Inc. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 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. 13 * 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. 25 */ 26 27 #include "config.h" 28 #include "core/rendering/compositing/GraphicsLayerTreeBuilder.h" 29 30 #include "core/html/HTMLMediaElement.h" 31 #include "core/rendering/RenderLayer.h" 32 #include "core/rendering/RenderLayerReflectionInfo.h" 33 #include "core/rendering/RenderPart.h" 34 #include "core/rendering/RenderView.h" 35 #include "core/rendering/compositing/CompositedLayerMapping.h" 36 #include "core/rendering/compositing/RenderLayerCompositor.h" 37 38 namespace blink { 39 40 GraphicsLayerTreeBuilder::GraphicsLayerTreeBuilder() 41 { 42 } 43 44 GraphicsLayerTreeBuilder::~GraphicsLayerTreeBuilder() 45 { 46 } 47 48 static bool shouldAppendLayer(const RenderLayer& layer) 49 { 50 if (!RuntimeEnabledFeatures::overlayFullscreenVideoEnabled()) 51 return true; 52 Node* node = layer.renderer()->node(); 53 if (node && isHTMLMediaElement(*node) && toHTMLMediaElement(node)->isFullscreen()) 54 return false; 55 return true; 56 } 57 58 void GraphicsLayerTreeBuilder::rebuild(RenderLayer& layer, AncestorInfo info) 59 { 60 // Make the layer compositing if necessary, and set up clipping and content layers. 61 // Note that we can only do work here that is independent of whether the descendant layers 62 // have been processed. computeCompositingRequirements() will already have done the paint invalidation if necessary. 63 64 layer.stackingNode()->updateLayerListsIfNeeded(); 65 66 const bool hasCompositedLayerMapping = layer.hasCompositedLayerMapping(); 67 CompositedLayerMapping* currentCompositedLayerMapping = layer.compositedLayerMapping(); 68 69 // If this layer has a compositedLayerMapping, then that is where we place subsequent children GraphicsLayers. 70 // Otherwise children continue to append to the child list of the enclosing layer. 71 GraphicsLayerVector layerChildren; 72 AncestorInfo infoForChildren(info); 73 if (hasCompositedLayerMapping) { 74 infoForChildren.childLayersOfEnclosingCompositedLayer = &layerChildren; 75 infoForChildren.enclosingCompositedLayer = &layer; 76 } 77 78 #if ENABLE(ASSERT) 79 LayerListMutationDetector mutationChecker(layer.stackingNode()); 80 #endif 81 82 if (layer.stackingNode()->isStackingContext()) { 83 RenderLayerStackingNodeIterator iterator(*layer.stackingNode(), NegativeZOrderChildren); 84 while (RenderLayerStackingNode* curNode = iterator.next()) 85 rebuild(*curNode->layer(), infoForChildren); 86 87 // If a negative z-order child is compositing, we get a foreground layer which needs to get parented. 88 if (hasCompositedLayerMapping && currentCompositedLayerMapping->foregroundLayer()) 89 infoForChildren.childLayersOfEnclosingCompositedLayer->append(currentCompositedLayerMapping->foregroundLayer()); 90 } 91 92 RenderLayerStackingNodeIterator iterator(*layer.stackingNode(), NormalFlowChildren | PositiveZOrderChildren); 93 while (RenderLayerStackingNode* curNode = iterator.next()) 94 rebuild(*curNode->layer(), infoForChildren); 95 96 if (hasCompositedLayerMapping) { 97 bool parented = false; 98 if (layer.renderer()->isRenderPart()) 99 parented = RenderLayerCompositor::parentFrameContentLayers(toRenderPart(layer.renderer())); 100 101 if (!parented) 102 currentCompositedLayerMapping->parentForSublayers()->setChildren(layerChildren); 103 104 // If the layer has a clipping layer the overflow controls layers will be siblings of the clipping layer. 105 // Otherwise, the overflow control layers are normal children. 106 // FIXME: Why isn't this handled in CLM updateInternalHierarchy? 107 if (!currentCompositedLayerMapping->hasClippingLayer() && !currentCompositedLayerMapping->hasScrollingLayer()) { 108 if (GraphicsLayer* overflowControlLayer = currentCompositedLayerMapping->layerForHorizontalScrollbar()) { 109 overflowControlLayer->removeFromParent(); 110 currentCompositedLayerMapping->parentForSublayers()->addChild(overflowControlLayer); 111 } 112 113 if (GraphicsLayer* overflowControlLayer = currentCompositedLayerMapping->layerForVerticalScrollbar()) { 114 overflowControlLayer->removeFromParent(); 115 currentCompositedLayerMapping->parentForSublayers()->addChild(overflowControlLayer); 116 } 117 118 if (GraphicsLayer* overflowControlLayer = currentCompositedLayerMapping->layerForScrollCorner()) { 119 overflowControlLayer->removeFromParent(); 120 currentCompositedLayerMapping->parentForSublayers()->addChild(overflowControlLayer); 121 } 122 } 123 124 if (shouldAppendLayer(layer)) 125 info.childLayersOfEnclosingCompositedLayer->append(currentCompositedLayerMapping->childForSuperlayers()); 126 } 127 128 if (layer.scrollParent() 129 && layer.scrollParent()->hasCompositedLayerMapping() 130 && layer.scrollParent()->compositedLayerMapping()->needsToReparentOverflowControls() 131 && layer.scrollParent()->scrollableArea()->topmostScrollChild() == &layer) 132 info.childLayersOfEnclosingCompositedLayer->append(layer.scrollParent()->compositedLayerMapping()->detachLayerForOverflowControls(*info.enclosingCompositedLayer)); 133 } 134 135 } 136