1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "core/layout/compositing/CompositingInputsUpdater.h"
#include "core/dom/Document.h"
#include "core/frame/FrameHost.h"
#include "core/frame/FrameView.h"
#include "core/layout/LayoutBlock.h"
#include "core/layout/LayoutView.h"
#include "core/layout/compositing/CompositedLayerMapping.h"
#include "core/layout/compositing/PaintLayerCompositor.h"
#include "core/paint/PaintLayer.h"
#include "platform/instrumentation/tracing/TraceEvent.h"
namespace blink {
CompositingInputsUpdater::CompositingInputsUpdater(PaintLayer* rootLayer)
: m_geometryMap(UseTransforms), m_rootLayer(rootLayer) {}
CompositingInputsUpdater::~CompositingInputsUpdater() {}
void CompositingInputsUpdater::update() {
TRACE_EVENT0("blink", "CompositingInputsUpdater::update");
updateRecursive(m_rootLayer, DoNotForceUpdate, AncestorInfo());
}
static const PaintLayer* findParentLayerOnClippingContainerChain(
const PaintLayer* layer) {
LayoutObject* current = layer->layoutObject();
while (current) {
if (current->style()->position() == FixedPosition) {
for (current = current->parent();
current && !current->canContainFixedPositionObjects();
current = current->parent()) {
// CSS clip applies to fixed position elements even for ancestors that
// are not what the fixed element is positioned with respect to.
if (current->hasClip()) {
DCHECK(current->hasLayer());
return static_cast<const LayoutBoxModelObject*>(current)->layer();
}
}
} else {
current = current->containingBlock();
}
if (current->hasLayer())
return static_cast<const LayoutBoxModelObject*>(current)->layer();
// Having clip or overflow clip forces the LayoutObject to become a layer,
// except for contains: paint, which may apply to SVG.
// SVG (other than LayoutSVGRoot) cannot have PaintLayers.
DCHECK(!current->hasClipRelatedProperty() ||
current->styleRef().containsPaint());
}
ASSERT_NOT_REACHED();
return nullptr;
}
static const PaintLayer* findParentLayerOnContainingBlockChain(
const LayoutObject* object) {
for (const LayoutObject* current = object; current;
current = current->containingBlock()) {
if (current->hasLayer())
return static_cast<const LayoutBoxModelObject*>(current)->layer();
}
ASSERT_NOT_REACHED();
return nullptr;
}
static bool hasClippedStackingAncestor(const PaintLayer* layer,
const PaintLayer* clippingLayer) {
if (layer == clippingLayer)
return false;
bool foundInterveningClip = false;
const LayoutObject* clippingLayoutObject = clippingLayer->layoutObject();
for (const PaintLayer* current = layer->compositingContainer(); current;
current = current->compositingContainer()) {
if (current == clippingLayer)
return foundInterveningClip;
if (current->layoutObject()->hasClipRelatedProperty() &&
!clippingLayoutObject->isDescendantOf(current->layoutObject()))
foundInterveningClip = true;
if (const LayoutObject* container = current->clippingContainer()) {
if (clippingLayoutObject != container &&
!clippingLayoutObject->isDescendantOf(container))
foundInterveningClip = true;
}
}
return false;
}
void CompositingInputsUpdater::updateRecursive(PaintLayer* layer,
UpdateType updateType,
AncestorInfo info) {
if (!layer->childNeedsCompositingInputsUpdate() && updateType != ForceUpdate)
return;
const PaintLayer* previousOverflowLayer = layer->ancestorOverflowLayer();
layer->updateAncestorOverflowLayer(info.lastOverflowClipLayer);
if (info.lastOverflowClipLayer && layer->needsCompositingInputsUpdate() &&
layer->layoutObject()->style()->position() == StickyPosition) {
if (info.lastOverflowClipLayer != previousOverflowLayer &&
!RuntimeEnabledFeatures::rootLayerScrollingEnabled()) {
// Old ancestor scroller should no longer have these constraints.
ASSERT(!previousOverflowLayer ||
!previousOverflowLayer->getScrollableArea()
->stickyConstraintsMap()
.contains(layer));
if (info.lastOverflowClipLayer->isRootLayer())
layer->layoutObject()
->view()
->frameView()
->addViewportConstrainedObject(layer->layoutObject());
else if (previousOverflowLayer && previousOverflowLayer->isRootLayer())
layer->layoutObject()
->view()
->frameView()
->removeViewportConstrainedObject(layer->layoutObject());
}
layer->layoutObject()->updateStickyPositionConstraints();
// Sticky position constraints and ancestor overflow scroller affect
// the sticky layer position, so we need to update it again here.
// TODO(flackr): This should be refactored in the future to be clearer
// (i.e. update layer position and ancestor inputs updates in the
// same walk)
layer->updateLayerPosition();
}
m_geometryMap.pushMappingsToAncestor(layer, layer->parent());
if (layer->hasCompositedLayerMapping())
info.enclosingCompositedLayer = layer;
if (layer->needsCompositingInputsUpdate()) {
if (info.enclosingCompositedLayer)
info.enclosingCompositedLayer->compositedLayerMapping()
->setNeedsGraphicsLayerUpdate(GraphicsLayerUpdateSubtree);
updateType = ForceUpdate;
}
if (updateType == ForceUpdate) {
PaintLayer::AncestorDependentCompositingInputs properties;
if (!layer->isRootLayer()) {
if (!RuntimeEnabledFeatures::slimmingPaintV2Enabled()) {
properties.unclippedAbsoluteBoundingBox =
enclosingIntRect(m_geometryMap.absoluteRect(
FloatRect(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.unclippedAbsoluteBoundingBox.isEmpty())
properties.unclippedAbsoluteBoundingBox.setSize(IntSize(1, 1));
IntRect clipRect =
pixelSnappedIntRect(layer->clipper()
.backgroundClipRect(ClipRectsContext(
m_rootLayer, AbsoluteClipRects))
.rect());
properties.clippedAbsoluteBoundingBox =
properties.unclippedAbsoluteBoundingBox;
properties.clippedAbsoluteBoundingBox.intersect(clipRect);
}
const PaintLayer* parent = layer->parent();
properties.opacityAncestor =
parent->isTransparent() ? parent : parent->opacityAncestor();
properties.transformAncestor =
parent->transform() ? parent : parent->transformAncestor();
properties.filterAncestor = parent->hasFilterInducingProperty()
? parent
: parent->filterAncestor();
bool layerIsFixedPosition =
layer->layoutObject()->style()->position() == FixedPosition;
properties.nearestFixedPositionLayer =
layerIsFixedPosition ? layer : parent->nearestFixedPositionLayer();
if (info.hasAncestorWithClipRelatedProperty) {
const PaintLayer* parentLayerOnClippingContainerChain =
findParentLayerOnClippingContainerChain(layer);
const bool parentHasClipRelatedProperty =
parentLayerOnClippingContainerChain->layoutObject()
->hasClipRelatedProperty();
properties.clippingContainer =
parentHasClipRelatedProperty
? parentLayerOnClippingContainerChain->layoutObject()
: parentLayerOnClippingContainerChain->clippingContainer();
if (layer->layoutObject()->isOutOfFlowPositioned() &&
!layer->subtreeIsInvisible()) {
const PaintLayer* clippingLayer =
properties.clippingContainer
? properties.clippingContainer->enclosingLayer()
: layer->compositor()->rootLayer();
if (hasClippedStackingAncestor(layer, clippingLayer))
properties.clipParent = clippingLayer;
}
}
if (info.lastScrollingAncestor) {
const LayoutObject* containingBlock =
layer->layoutObject()->containingBlock();
const PaintLayer* parentLayerOnContainingBlockChain =
findParentLayerOnContainingBlockChain(containingBlock);
properties.ancestorScrollingLayer =
parentLayerOnContainingBlockChain->ancestorScrollingLayer();
if (parentLayerOnContainingBlockChain->scrollsOverflow())
properties.ancestorScrollingLayer = parentLayerOnContainingBlockChain;
if (layer->stackingNode()->isStacked() &&
properties.ancestorScrollingLayer &&
!info.ancestorStackingContext->layoutObject()->isDescendantOf(
properties.ancestorScrollingLayer->layoutObject()))
properties.scrollParent = properties.ancestorScrollingLayer;
}
}
layer->updateAncestorDependentCompositingInputs(
properties, info.hasAncestorWithClipPath);
}
if (layer->stackingNode()->isStackingContext())
info.ancestorStackingContext = layer;
if (layer->isRootLayer() || layer->layoutObject()->hasOverflowClip())
info.lastOverflowClipLayer = layer;
if (layer->scrollsOverflow())
info.lastScrollingAncestor = layer;
if (layer->layoutObject()->hasClipRelatedProperty())
info.hasAncestorWithClipRelatedProperty = true;
if (layer->layoutObject()->hasClipPath())
info.hasAncestorWithClipPath = true;
for (PaintLayer* child = layer->firstChild(); child;
child = child->nextSibling())
updateRecursive(child, updateType, info);
layer->didUpdateCompositingInputs();
m_geometryMap.popMappingsToAncestor(layer->parent());
if (layer->selfPaintingStatusChanged()) {
layer->clearSelfPaintingStatusChanged();
// If the floating object becomes non-self-painting, so some ancestor should
// paint it; if it becomes self-painting, it should paint itself and no
// ancestor should paint it.
if (layer->layoutObject()->isFloating()) {
LayoutBlockFlow::updateAncestorShouldPaintFloatingObject(
*layer->layoutBox());
}
}
}
#if DCHECK_IS_ON()
void CompositingInputsUpdater::assertNeedsCompositingInputsUpdateBitsCleared(
PaintLayer* layer) {
ASSERT(!layer->childNeedsCompositingInputsUpdate());
ASSERT(!layer->needsCompositingInputsUpdate());
for (PaintLayer* child = layer->firstChild(); child;
child = child->nextSibling())
assertNeedsCompositingInputsUpdateBitsCleared(child);
}
#endif
} // namespace blink
|