diff options
author | wangxianzhu <wangxianzhu@chromium.org> | 2016-01-28 11:36:25 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-01-28 19:38:32 +0000 |
commit | 299d5beba4af85652d96a2b2da1733ebcdec2c5e (patch) | |
tree | e448aa233d3445a16fbae7c7e5abf6ac31ec0de1 /third_party | |
parent | 364981e00bc0a6b1a0dfa9dfe8b42821c3e5a5f8 (diff) | |
download | chromium_src-299d5beba4af85652d96a2b2da1733ebcdec2c5e.zip chromium_src-299d5beba4af85652d96a2b2da1733ebcdec2c5e.tar.gz chromium_src-299d5beba4af85652d96a2b2da1733ebcdec2c5e.tar.bz2 |
Put rare PaintLayer fields into PaintLayerRareData
Rare rates of the fields, based on top 10k sites
(See run 475 in http://ct.skia.org for details):
stackingNode 100.00%
ancestorDependentCompositingInputs 82.17%
clipper 36.25%
staticBlockPosition 11.00%
staticInlinePosition 7.49%
(The following fields are put into PaintLayerRareData)
potentialCompositingReasonsFromStyle 7.13%
(^this is likely to cover most of the following)
compositingReasons 5.77%
compositedLayerMapping 3.32%
subpixelAccumulation 2.86%
offsetForInFlowPosition 2.70%
grouppedMapping 2.35%
transform 2.02%
enclosingPaginationLayer 0.01%
reflectionInfo (count) 0.00%
blockSelectionGapsBounds 0.00%
AncestorDependentCompositingInputs fields:
clippedAbsoluteBoundingBox 69.73%
clippingContainer 46.57%
(The following fields are put into RareAncestorDependentCompositingInputs)
transformAncestor 6.14%
opacityAncestor 4.73%
ancestorScrollingLayer 4.26%
scrollParent 2.76%
nearestFixedPositionLayer 2.31%
filterAncestor 0.02%
Rare rate of a field is defined as: number of PaintLayers with the field
ever assigned non-default value / total number of PaintLayers.
This CL reduces sizeof(PaintLayer) from 344 bytes to 208 bytes on LP 64
systems.
BUG=581124
Review URL: https://codereview.chromium.org/1636563003
Cr-Commit-Position: refs/heads/master@{#372141}
Diffstat (limited to 'third_party')
8 files changed, 286 insertions, 211 deletions
diff --git a/third_party/WebKit/Source/core/layout/compositing/CompositedLayerMapping.cpp b/third_party/WebKit/Source/core/layout/compositing/CompositedLayerMapping.cpp index 8afe09c..57b0a50 100644 --- a/third_party/WebKit/Source/core/layout/compositing/CompositedLayerMapping.cpp +++ b/third_party/WebKit/Source/core/layout/compositing/CompositedLayerMapping.cpp @@ -349,7 +349,7 @@ void CompositedLayerMapping::updateCompositingReasons() m_graphicsLayer->setCompositingReasons(m_owningLayer.compositingReasons()); } -bool CompositedLayerMapping::owningLayerClippedByLayerNotAboveCompositedAncestor(PaintLayer* scrollParent) +bool CompositedLayerMapping::owningLayerClippedByLayerNotAboveCompositedAncestor(const PaintLayer* scrollParent) { if (!m_owningLayer.parent()) return false; @@ -382,9 +382,9 @@ bool CompositedLayerMapping::owningLayerClippedByLayerNotAboveCompositedAncestor return parentClipRect != LayoutRect::infiniteIntRect(); } -PaintLayer* CompositedLayerMapping::scrollParent() +const PaintLayer* CompositedLayerMapping::scrollParent() { - PaintLayer* scrollParent = m_owningLayer.scrollParent(); + const PaintLayer* scrollParent = m_owningLayer.scrollParent(); if (scrollParent && !scrollParent->needsCompositedScrolling()) return nullptr; return scrollParent; @@ -422,7 +422,7 @@ bool CompositedLayerMapping::updateGraphicsLayerConfiguration() if (m_owningLayer.needsCompositedScrolling()) needsDescendantsClippingLayer = false; - PaintLayer* scrollParent = this->scrollParent(); + const PaintLayer* scrollParent = this->scrollParent(); // This is required because compositing layers are parented according to the z-order hierarchy, yet // clipping goes down the layoutObject hierarchy. Thus, a PaintLayer can be clipped by a @@ -1665,7 +1665,7 @@ bool CompositedLayerMapping::updateScrollingLayers(bool needsScrollingLayers) return layerChanged; } -static void updateScrollParentForGraphicsLayer(GraphicsLayer* layer, GraphicsLayer* topmostLayer, PaintLayer* scrollParent, ScrollingCoordinator* scrollingCoordinator) +static void updateScrollParentForGraphicsLayer(GraphicsLayer* layer, GraphicsLayer* topmostLayer, const PaintLayer* scrollParent, ScrollingCoordinator* scrollingCoordinator) { if (!layer) return; @@ -1677,7 +1677,7 @@ static void updateScrollParentForGraphicsLayer(GraphicsLayer* layer, GraphicsLay scrollingCoordinator->updateScrollParentForGraphicsLayer(layer, scrollParent); } -void CompositedLayerMapping::updateScrollParent(PaintLayer* scrollParent) +void CompositedLayerMapping::updateScrollParent(const PaintLayer* scrollParent) { if (ScrollingCoordinator* scrollingCoordinator = scrollingCoordinatorFromLayer(m_owningLayer)) { GraphicsLayer* topmostLayer = childForSuperlayers(); @@ -1687,7 +1687,7 @@ void CompositedLayerMapping::updateScrollParent(PaintLayer* scrollParent) } } -static void updateClipParentForGraphicsLayer(GraphicsLayer* layer, GraphicsLayer* topmostLayer, PaintLayer* clipParent, ScrollingCoordinator* scrollingCoordinator) +static void updateClipParentForGraphicsLayer(GraphicsLayer* layer, GraphicsLayer* topmostLayer, const PaintLayer* clipParent, ScrollingCoordinator* scrollingCoordinator) { if (!layer) return; @@ -1699,12 +1699,12 @@ static void updateClipParentForGraphicsLayer(GraphicsLayer* layer, GraphicsLayer scrollingCoordinator->updateClipParentForGraphicsLayer(layer, clipParent); } -void CompositedLayerMapping::updateClipParent(PaintLayer* scrollParent) +void CompositedLayerMapping::updateClipParent(const PaintLayer* scrollParent) { if (owningLayerClippedByLayerNotAboveCompositedAncestor(scrollParent)) return; - PaintLayer* clipParent = m_owningLayer.clipParent(); + const PaintLayer* clipParent = m_owningLayer.clipParent(); if (clipParent) clipParent = clipParent->enclosingLayerWithCompositedLayerMapping(IncludeSelf); diff --git a/third_party/WebKit/Source/core/layout/compositing/CompositedLayerMapping.h b/third_party/WebKit/Source/core/layout/compositing/CompositedLayerMapping.h index e133f32..ade9026 100644 --- a/third_party/WebKit/Source/core/layout/compositing/CompositedLayerMapping.h +++ b/third_party/WebKit/Source/core/layout/compositing/CompositedLayerMapping.h @@ -61,13 +61,19 @@ enum GraphicsLayerUpdateScope { GraphicsLayerUpdateSubtree, }; -// CompositedLayerMapping keeps track of how Layers of the layout tree correspond to +// CompositedLayerMapping keeps track of how PaintLayers correspond to // GraphicsLayers of the composited layer tree. Each instance of CompositedLayerMapping // manages a small cluster of GraphicsLayers and the references to which Layers // and paint phases contribute to each GraphicsLayer. // -// Currently (Oct. 2013) there is one CompositedLayerMapping for each Layer, -// but this is likely to evolve soon. +// - If a PaintLayer is composited, +// - if it paints into its own backings (GraphicsLayers), it owns a +// CompositedLayerMapping (PaintLayer::compositedLayerMapping()) to keep +// track the backings; +// - if it paints into grouped backing (i.e. it's squashed), it has a pointer +// (PaintLayer::groupedMapping()) to the CompositedLayerMapping into which +// the PaintLayer is squashed; +// - Otherwise the PaintLayer doesn't own or directly reference any CompositedLayerMapping. class CORE_EXPORT CompositedLayerMapping final : public GraphicsLayerClient { WTF_MAKE_NONCOPYABLE(CompositedLayerMapping); USING_FAST_MALLOC(CompositedLayerMapping); @@ -253,8 +259,8 @@ private: bool requiresVerticalScrollbarLayer() const { return m_owningLayer.scrollableArea() && m_owningLayer.scrollableArea()->verticalScrollbar(); } bool requiresScrollCornerLayer() const { return m_owningLayer.scrollableArea() && !m_owningLayer.scrollableArea()->scrollCornerAndResizerRect().isEmpty(); } bool updateScrollingLayers(bool scrollingLayers); - void updateScrollParent(PaintLayer*); - void updateClipParent(PaintLayer* scrollParent); + void updateScrollParent(const PaintLayer*); + void updateClipParent(const PaintLayer* scrollParent); bool updateSquashingLayers(bool needsSquashingLayers); void updateDrawsContent(); void updateChildrenTransform(); @@ -306,9 +312,9 @@ private: // Return true if |m_owningLayer|'s compositing ancestor is not a descendant (inclusive) of the // clipping container for |m_owningLayer|. - bool owningLayerClippedByLayerNotAboveCompositedAncestor(PaintLayer* scrollParent); + bool owningLayerClippedByLayerNotAboveCompositedAncestor(const PaintLayer* scrollParent); - PaintLayer* scrollParent(); + const PaintLayer* scrollParent(); // Clear the groupedMapping entry on the layer at the given index, only if that layer does // not appear earlier in the set of layers for this object. diff --git a/third_party/WebKit/Source/core/layout/compositing/CompositingInputsUpdater.cpp b/third_party/WebKit/Source/core/layout/compositing/CompositingInputsUpdater.cpp index 0df4cb7..5fe741f 100644 --- a/third_party/WebKit/Source/core/layout/compositing/CompositingInputsUpdater.cpp +++ b/third_party/WebKit/Source/core/layout/compositing/CompositingInputsUpdater.cpp @@ -110,6 +110,7 @@ void CompositingInputsUpdater::updateRecursive(PaintLayer* layer, UpdateType upd if (updateType == ForceUpdate) { PaintLayer::AncestorDependentCompositingInputs properties; + PaintLayer::RareAncestorDependentCompositingInputs rareProperties; if (!layer->isRootLayer()) { properties.clippedAbsoluteBoundingBox = enclosingIntRect(m_geometryMap.absoluteRect(FloatRect(layer->boundingBoxForCompositingOverlapTest()))); @@ -123,11 +124,11 @@ void CompositingInputsUpdater::updateRecursive(PaintLayer* layer, UpdateType upd properties.clippedAbsoluteBoundingBox.intersect(clipRect); const PaintLayer* parent = layer->parent(); - properties.opacityAncestor = parent->isTransparent() ? parent : parent->opacityAncestor(); - properties.transformAncestor = parent->hasTransformRelatedProperty() ? parent : parent->transformAncestor(); - properties.filterAncestor = parent->hasFilter() ? parent : parent->filterAncestor(); + rareProperties.opacityAncestor = parent->isTransparent() ? parent : parent->opacityAncestor(); + rareProperties.transformAncestor = parent->hasTransformRelatedProperty() ? parent : parent->transformAncestor(); + rareProperties.filterAncestor = parent->hasFilter() ? parent : parent->filterAncestor(); bool layerIsFixedPosition = layer->layoutObject()->style()->position() == FixedPosition; - properties.nearestFixedPositionLayer = layerIsFixedPosition ? layer : parent->nearestFixedPositionLayer(); + rareProperties.nearestFixedPositionLayer = layerIsFixedPosition ? layer : parent->nearestFixedPositionLayer(); if (info.hasAncestorWithClipRelatedProperty) { const PaintLayer* parentLayerOnClippingContainerChain = findParentLayerOnClippingContainerChain(layer); @@ -139,25 +140,24 @@ void CompositingInputsUpdater::updateRecursive(PaintLayer* layer, UpdateType upd const LayoutObject* containingBlock = layer->layoutObject()->containingBlock(); const PaintLayer* parentLayerOnContainingBlockChain = findParentLayerOnContainingBlockChain(containingBlock); - properties.ancestorScrollingLayer = parentLayerOnContainingBlockChain->ancestorScrollingLayer(); + rareProperties.ancestorScrollingLayer = parentLayerOnContainingBlockChain->ancestorScrollingLayer(); if (parentLayerOnContainingBlockChain->scrollsOverflow()) - properties.ancestorScrollingLayer = parentLayerOnContainingBlockChain; + rareProperties.ancestorScrollingLayer = parentLayerOnContainingBlockChain; if (layer->layoutObject()->isOutOfFlowPositioned() && !layer->subtreeIsInvisible()) { const PaintLayer* clippingLayer = properties.clippingContainer ? properties.clippingContainer->enclosingLayer() : layer->compositor()->rootLayer(); if (hasClippedStackingAncestor(layer, clippingLayer)) - properties.clipParent = clippingLayer; + rareProperties.clipParent = clippingLayer; } if (layer->stackingNode()->isTreatedAsOrStackingContext() - && properties.ancestorScrollingLayer - && !info.ancestorStackingContext->layoutObject()->isDescendantOf(properties.ancestorScrollingLayer->layoutObject())) - properties.scrollParent = properties.ancestorScrollingLayer; + && rareProperties.ancestorScrollingLayer + && !info.ancestorStackingContext->layoutObject()->isDescendantOf(rareProperties.ancestorScrollingLayer->layoutObject())) + rareProperties.scrollParent = rareProperties.ancestorScrollingLayer; } } - properties.hasAncestorWithClipPath = info.hasAncestorWithClipPath; - layer->updateAncestorDependentCompositingInputs(properties); + layer->updateAncestorDependentCompositingInputs(properties, rareProperties, info.hasAncestorWithClipPath); } if (layer->stackingNode()->isStackingContext()) @@ -172,15 +172,16 @@ void CompositingInputsUpdater::updateRecursive(PaintLayer* layer, UpdateType upd if (layer->layoutObject()->hasClipPath()) info.hasAncestorWithClipPath = true; - PaintLayer::DescendantDependentCompositingInputs descendantProperties; + bool hasDescendantWithClipPath = false; + bool hasNonIsolatedDescendantWithBlendMode = false; for (PaintLayer* 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(); + hasDescendantWithClipPath |= child->hasDescendantWithClipPath() || child->layoutObject()->hasClipPath(); + hasNonIsolatedDescendantWithBlendMode |= (!child->stackingNode()->isStackingContext() && child->hasNonIsolatedDescendantWithBlendMode()) || child->layoutObject()->style()->hasBlendMode(); } - layer->updateDescendantDependentCompositingInputs(descendantProperties); + layer->updateDescendantDependentCompositingInputs(hasDescendantWithClipPath, hasNonIsolatedDescendantWithBlendMode); layer->didUpdateCompositingInputs(); m_geometryMap.popMappingsToAncestor(layer->parent()); diff --git a/third_party/WebKit/Source/core/layout/compositing/CompositingLayerAssigner.cpp b/third_party/WebKit/Source/core/layout/compositing/CompositingLayerAssigner.cpp index 35daf9f..873ec4b 100644 --- a/third_party/WebKit/Source/core/layout/compositing/CompositingLayerAssigner.cpp +++ b/third_party/WebKit/Source/core/layout/compositing/CompositingLayerAssigner.cpp @@ -159,19 +159,16 @@ CompositingReasons CompositingLayerAssigner::getReasonsPreventingSquashing(const if (layer->scrollParent() && layer->hasCompositingDescendant()) return CompositingReasonScrollChildWithCompositedDescendants; - const PaintLayer::AncestorDependentCompositingInputs& compositingInputs = layer->ancestorDependentCompositingInputs(); - const PaintLayer::AncestorDependentCompositingInputs& squashingLayerCompositingInputs = squashingLayer.ancestorDependentCompositingInputs(); - - if (compositingInputs.opacityAncestor != squashingLayerCompositingInputs.opacityAncestor) + if (layer->opacityAncestor() != squashingLayer.opacityAncestor()) return CompositingReasonSquashingOpacityAncestorMismatch; - if (compositingInputs.transformAncestor != squashingLayerCompositingInputs.transformAncestor) + if (layer->transformAncestor() != squashingLayer.transformAncestor()) return CompositingReasonSquashingTransformAncestorMismatch; - if (layer->hasFilter() || compositingInputs.filterAncestor != squashingLayerCompositingInputs.filterAncestor) + if (layer->hasFilter() || layer->filterAncestor() != squashingLayer.filterAncestor()) return CompositingReasonSquashingFilterMismatch; - if (compositingInputs.nearestFixedPositionLayer != squashingLayerCompositingInputs.nearestFixedPositionLayer) + if (layer->nearestFixedPositionLayer() != squashingLayer.nearestFixedPositionLayer()) return CompositingReasonSquashingNearestFixedPositionMismatch; ASSERT(layer->layoutObject()->style()->position() != FixedPosition); diff --git a/third_party/WebKit/Source/core/page/scrolling/ScrollingCoordinator.cpp b/third_party/WebKit/Source/core/page/scrolling/ScrollingCoordinator.cpp index 8474484..51f933c 100644 --- a/third_party/WebKit/Source/core/page/scrolling/ScrollingCoordinator.cpp +++ b/third_party/WebKit/Source/core/page/scrolling/ScrollingCoordinator.cpp @@ -657,7 +657,7 @@ void ScrollingCoordinator::touchEventTargetRectsDidChange() m_touchEventTargetRectsAreDirty = true; } -void ScrollingCoordinator::updateScrollParentForGraphicsLayer(GraphicsLayer* child, PaintLayer* parent) +void ScrollingCoordinator::updateScrollParentForGraphicsLayer(GraphicsLayer* child, const PaintLayer* parent) { WebLayer* scrollParentWebLayer = nullptr; if (parent && parent->hasCompositedLayerMapping()) @@ -666,7 +666,7 @@ void ScrollingCoordinator::updateScrollParentForGraphicsLayer(GraphicsLayer* chi child->setScrollParent(scrollParentWebLayer); } -void ScrollingCoordinator::updateClipParentForGraphicsLayer(GraphicsLayer* child, PaintLayer* parent) +void ScrollingCoordinator::updateClipParentForGraphicsLayer(GraphicsLayer* child, const PaintLayer* parent) { WebLayer* clipParentWebLayer = nullptr; if (parent && parent->hasCompositedLayerMapping()) diff --git a/third_party/WebKit/Source/core/page/scrolling/ScrollingCoordinator.h b/third_party/WebKit/Source/core/page/scrolling/ScrollingCoordinator.h index 882605d..132cc2d 100644 --- a/third_party/WebKit/Source/core/page/scrolling/ScrollingCoordinator.h +++ b/third_party/WebKit/Source/core/page/scrolling/ScrollingCoordinator.h @@ -110,8 +110,8 @@ public: void touchEventTargetRectsDidChange(); void willDestroyLayer(PaintLayer*); - void updateScrollParentForGraphicsLayer(GraphicsLayer* child, PaintLayer* parent); - void updateClipParentForGraphicsLayer(GraphicsLayer* child, PaintLayer* parent); + void updateScrollParentForGraphicsLayer(GraphicsLayer* child, const PaintLayer* parent); + void updateClipParentForGraphicsLayer(GraphicsLayer* child, const PaintLayer* parent); static String mainThreadScrollingReasonsAsText(MainThreadScrollingReasons); String mainThreadScrollingReasonsAsText() const; diff --git a/third_party/WebKit/Source/core/paint/PaintLayer.cpp b/third_party/WebKit/Source/core/paint/PaintLayer.cpp index f30cfee..791357a 100644 --- a/third_party/WebKit/Source/core/paint/PaintLayer.cpp +++ b/third_party/WebKit/Source/core/paint/PaintLayer.cpp @@ -97,10 +97,44 @@ namespace { static CompositingQueryMode gCompositingQueryMode = CompositingQueriesAreOnlyAllowedInCertainDocumentLifecyclePhases; +struct SameSizeAsPaintLayer : DisplayItemClient { + int bitFields; + void* pointers[8]; + LayoutUnit layoutUnits[4]; + IntSize size; + OwnPtrWillBePersistent<PaintLayerScrollableArea> scrollableArea; + struct { + IntRect rect; + void* pointers[2]; + } ancestorCompositingInputs; + struct { + void* pointers[2]; + } clipper; + struct { + IntSize size; + void* pointer; + LayoutRect rect; + } previousPaintStatus; +}; + +static_assert(sizeof(PaintLayer) == sizeof(SameSizeAsPaintLayer), "PaintLayer should stay small"); + } // namespace using namespace HTMLNames; +PaintLayerRareData::PaintLayerRareData() + : enclosingPaginationLayer(nullptr) + , potentialCompositingReasonsFromStyle(CompositingReasonNone) + , compositingReasons(CompositingReasonNone) + , groupedMapping(nullptr) +{ +} + +PaintLayerRareData::~PaintLayerRareData() +{ +} + PaintLayer::PaintLayer(LayoutBoxModelObject* layoutObject, PaintLayerType type) : m_layerType(type) , m_hasSelfPaintingLayerDescendant(false) @@ -129,6 +163,9 @@ PaintLayer::PaintLayer(LayoutBoxModelObject* layoutObject, PaintLayerType type) , m_previousPaintResult(PaintLayerPainter::FullyPainted) , m_needsPaintPhaseDescendantOutlines(false) , m_needsPaintPhaseFloat(false) + , m_hasDescendantWithClipPath(false) + , m_hasNonIsolatedDescendantWithBlendMode(false) + , m_hasAncestorWithClipPath(false) , m_layoutObject(layoutObject) , m_parent(0) , m_previous(0) @@ -137,10 +174,6 @@ PaintLayer::PaintLayer(LayoutBoxModelObject* layoutObject, PaintLayerType type) , m_last(0) , m_staticInlinePosition(0) , m_staticBlockPosition(0) - , m_enclosingPaginationLayer(0) - , m_potentialCompositingReasonsFromStyle(CompositingReasonNone) - , m_compositingReasons(CompositingReasonNone) - , m_groupedMapping(0) , m_clipper(*layoutObject) { updateStackingNode(); @@ -174,8 +207,8 @@ PaintLayer::~PaintLayer() clearCompositedLayerMapping(true); - if (m_reflectionInfo) - m_reflectionInfo->destroy(); + if (PaintLayerReflectionInfo* reflectionInfo = this->reflectionInfo()) + reflectionInfo->destroy(); if (m_scrollableArea) m_scrollableArea->dispose(); @@ -220,8 +253,8 @@ void PaintLayer::contentChanged(ContentChangeType changeType) compositedLayerMapping()->setNeedsGraphicsLayerUpdate(GraphicsLayerUpdateSubtree); } - if (m_compositedLayerMapping) - m_compositedLayerMapping->contentChanged(changeType); + if (CompositedLayerMapping* compositedLayerMapping = this->compositedLayerMapping()) + compositedLayerMapping->contentChanged(changeType); } bool PaintLayer::paintsWithFilters() const @@ -231,7 +264,7 @@ bool PaintLayer::paintsWithFilters() const // https://code.google.com/p/chromium/issues/detail?id=343759 DisableCompositingQueryAsserts disabler; - return !m_compositedLayerMapping || compositingState() != PaintsIntoOwnBacking; + return !compositedLayerMapping() || compositingState() != PaintsIntoOwnBacking; } bool PaintLayer::paintsWithBackdropFilters() const @@ -241,17 +274,18 @@ bool PaintLayer::paintsWithBackdropFilters() const // https://code.google.com/p/chromium/issues/detail?id=343759 DisableCompositingQueryAsserts disabler; - return !m_compositedLayerMapping || compositingState() != PaintsIntoOwnBacking; + return !compositedLayerMapping() || compositingState() != PaintsIntoOwnBacking; } LayoutSize PaintLayer::subpixelAccumulation() const { - return m_subpixelAccumulation; + return m_rareData ? m_rareData->subpixelAccumulation : LayoutSize(); } void PaintLayer::setSubpixelAccumulation(const LayoutSize& size) { - m_subpixelAccumulation = size; + if (m_rareData || !size.isZero()) + ensureRareData().subpixelAccumulation = size; } void PaintLayer::updateLayerPositionsAfterLayout() @@ -273,8 +307,8 @@ void PaintLayer::updateLayerPositionRecursive() { updateLayerPosition(); - if (m_reflectionInfo) - m_reflectionInfo->reflection()->layout(); + if (m_rareData && m_rareData->reflectionInfo) + m_rareData->reflectionInfo->reflection()->layout(); // FIXME(400589): We would like to do this in PaintLayerScrollableArea::updateAfterLayout, // but it depends on the size computed by updateLayerPosition. @@ -358,12 +392,12 @@ void PaintLayer::updateLayerPositionsAfterScrollRecursive(const DoubleSize& scro void PaintLayer::updateTransformationMatrix() { - if (m_transform) { + if (TransformationMatrix* transform = this->transform()) { LayoutBox* box = layoutBox(); ASSERT(box); - m_transform->makeIdentity(); - box->style()->applyTransform(*m_transform, LayoutSize(box->pixelSnappedSize()), ComputedStyle::IncludeTransformOrigin, ComputedStyle::IncludeMotionPath, ComputedStyle::IncludeIndependentTransformProperties); - makeMatrixRenderable(*m_transform, compositor()->hasAcceleratedCompositing()); + transform->makeIdentity(); + box->style()->applyTransform(*transform, LayoutSize(box->pixelSnappedSize()), ComputedStyle::IncludeTransformOrigin, ComputedStyle::IncludeMotionPath, ComputedStyle::IncludeIndependentTransformProperties); + makeMatrixRenderable(*transform, compositor()->hasAcceleratedCompositing()); } } @@ -377,12 +411,12 @@ void PaintLayer::updateTransform(const ComputedStyle* oldStyle, const ComputedSt bool hasTransform = layoutObject()->hasTransformRelatedProperty() && newStyle.hasTransform(); bool had3DTransform = has3DTransform(); - bool hadTransform = m_transform; + bool hadTransform = transform(); if (hasTransform != hadTransform) { if (hasTransform) - m_transform = adoptPtr(new TransformationMatrix); + ensureRareData().transform = adoptPtr(new TransformationMatrix); else - m_transform.clear(); + m_rareData->transform.clear(); // PaintLayers with transforms act as clip rects roots, so clear the cached clip rects here. m_clipper.clearClipRectsIncludingDescendants(); @@ -418,23 +452,24 @@ PaintLayer* PaintLayer::renderingContextRoot() TransformationMatrix PaintLayer::currentTransform() const { - if (!m_transform) - return TransformationMatrix(); - return *m_transform; + if (TransformationMatrix* transform = this->transform()) + return *transform; + return TransformationMatrix(); } TransformationMatrix PaintLayer::renderableTransform(GlobalPaintFlags globalPaintFlags) const { - if (!m_transform) + TransformationMatrix* transform = this->transform(); + if (!transform) return TransformationMatrix(); if (globalPaintFlags & GlobalPaintFlattenCompositingLayers) { - TransformationMatrix matrix = *m_transform; + TransformationMatrix matrix = *transform; makeMatrixRenderable(matrix, false /* flatten 3d */); return matrix; } - return *m_transform; + return *transform; } void PaintLayer::convertFromFlowThreadToVisualBoundingBoxInAncestor(const PaintLayer* ancestorLayer, LayoutRect& rect) const @@ -465,7 +500,8 @@ void PaintLayer::convertFromFlowThreadToVisualBoundingBoxInAncestor(const PaintL void PaintLayer::updatePaginationRecursive(bool needsPaginationUpdate) { - m_enclosingPaginationLayer = 0; + if (m_rareData) + m_rareData->enclosingPaginationLayer = nullptr; if (layoutObject()->isLayoutFlowThread()) needsPaginationUpdate = true; @@ -477,7 +513,7 @@ void PaintLayer::updatePaginationRecursive(bool needsPaginationUpdate) // enclosingPaginationLayer instead of using a simple bit, since we want to be able to get back // to that layer easily. if (LayoutFlowThread* containingFlowThread = layoutObject()->flowThreadContainingBlock()) - m_enclosingPaginationLayer = containingFlowThread->layer(); + ensureRareData().enclosingPaginationLayer = containingFlowThread->layer(); } for (PaintLayer* child = firstChild(); child; child = child->nextSibling()) @@ -486,7 +522,8 @@ void PaintLayer::updatePaginationRecursive(bool needsPaginationUpdate) void PaintLayer::clearPaginationRecursive() { - m_enclosingPaginationLayer = 0; + if (m_rareData) + m_rareData->enclosingPaginationLayer = nullptr; for (PaintLayer* child = firstChild(); child; child = child->nextSibling()) child->clearPaginationRecursive(); } @@ -773,11 +810,12 @@ bool PaintLayer::updateLayerPosition() bool positionOrOffsetChanged = false; if (layoutObject()->isInFlowPositioned()) { LayoutSize newOffset = layoutObject()->offsetForInFlowPosition(); - positionOrOffsetChanged = newOffset != m_offsetForInFlowPosition; - m_offsetForInFlowPosition = newOffset; - localPoint.move(m_offsetForInFlowPosition); - } else { - m_offsetForInFlowPosition = LayoutSize(); + positionOrOffsetChanged = newOffset != offsetForInFlowPosition(); + if (m_rareData || !newOffset.isZero()) + ensureRareData().offsetForInFlowPosition = newOffset; + localPoint.move(newOffset); + } else if (m_rareData) { + m_rareData->offsetForInFlowPosition = LayoutSize(); } // FIXME: We'd really like to just get rid of the concept of a layer rectangle and rely on the layoutObjects. @@ -871,11 +909,9 @@ PaintLayer* PaintLayer::enclosingTransformedAncestor() const LayoutPoint PaintLayer::computeOffsetFromTransformedAncestor() const { - const AncestorDependentCompositingInputs& properties = ancestorDependentCompositingInputs(); - TransformState transformState(TransformState::ApplyTransformDirection, FloatPoint()); // FIXME: add a test that checks flipped writing mode and ApplyContainerFlip are correct. - layoutObject()->mapLocalToAncestor(properties.transformAncestor ? properties.transformAncestor->layoutObject() : 0, transformState, ApplyContainerFlip); + layoutObject()->mapLocalToAncestor(transformAncestor() ? transformAncestor()->layoutObject() : nullptr, transformState, ApplyContainerFlip); transformState.flatten(); return LayoutPoint(transformState.lastPlanarPoint()); } @@ -956,15 +992,21 @@ void PaintLayer::setNeedsCompositingInputsUpdate() compositor()->setNeedsCompositingUpdate(CompositingUpdateAfterCompositingInputChange); } -void PaintLayer::updateAncestorDependentCompositingInputs(const AncestorDependentCompositingInputs& compositingInputs) +void PaintLayer::updateAncestorDependentCompositingInputs(const AncestorDependentCompositingInputs& compositingInputs, const RareAncestorDependentCompositingInputs& rareCompositingInputs, bool hasAncestorWithClipPath) { m_ancestorDependentCompositingInputs = compositingInputs; + if (rareCompositingInputs.isDefault()) + m_rareAncestorDependentCompositingInputs.clear(); + else + m_rareAncestorDependentCompositingInputs = adoptPtr(new RareAncestorDependentCompositingInputs(rareCompositingInputs)); + m_hasAncestorWithClipPath = hasAncestorWithClipPath; m_needsAncestorDependentCompositingInputsUpdate = false; } -void PaintLayer::updateDescendantDependentCompositingInputs(const DescendantDependentCompositingInputs& compositingInputs) +void PaintLayer::updateDescendantDependentCompositingInputs(bool hasDescendantWithClipPath, bool hasNonIsolatedDescendantWithBlendMode) { - m_descendantDependentCompositingInputs = compositingInputs; + m_hasDescendantWithClipPath = hasDescendantWithClipPath; + m_hasNonIsolatedDescendantWithBlendMode = hasNonIsolatedDescendantWithBlendMode; m_needsDescendantDependentCompositingInputsUpdate = false; } @@ -978,7 +1020,8 @@ void PaintLayer::didUpdateCompositingInputs() bool PaintLayer::hasNonIsolatedDescendantWithBlendMode() const { - if (descendantDependentCompositingInputs().hasNonIsolatedDescendantWithBlendMode) + ASSERT(!m_needsDescendantDependentCompositingInputsUpdate); + if (m_hasNonIsolatedDescendantWithBlendMode) return true; if (layoutObject()->isSVGRoot()) return toLayoutSVGRoot(layoutObject())->hasNonIsolatedBlendingDescendants(); @@ -987,9 +1030,12 @@ bool PaintLayer::hasNonIsolatedDescendantWithBlendMode() const void PaintLayer::setCompositingReasons(CompositingReasons reasons, CompositingReasons mask) { - if ((compositingReasons() & mask) == (reasons & mask)) + CompositingReasons oldReasons = m_rareData ? m_rareData->compositingReasons : CompositingReasonNone; + if ((oldReasons & mask) == (reasons & mask)) return; - m_compositingReasons = (reasons & mask) | (compositingReasons() & ~mask); + CompositingReasons newReasons = (reasons & mask) | (oldReasons & ~mask); + if (m_rareData || newReasons != CompositingReasonNone) + ensureRareData().compositingReasons = newReasons; } void PaintLayer::setHasCompositingDescendant(bool hasCompositingDescendant) @@ -1230,8 +1276,8 @@ void PaintLayer::removeOnlyThisLayer() // Remove the child reflection layer before moving other child layers. // The reflection layer should not be moved to the parent. - if (m_reflectionInfo) - removeChild(m_reflectionInfo->reflectionLayer()); + if (PaintLayerReflectionInfo* reflectionInfo = this->reflectionInfo()) + removeChild(reflectionInfo->reflectionLayer()); // Now walk our kids and reattach them to our parent. PaintLayer* current = m_first; @@ -1374,12 +1420,11 @@ void PaintLayer::updateReflectionInfo(const ComputedStyle* oldStyle) { ASSERT(!oldStyle || !layoutObject()->style()->reflectionDataEquivalent(oldStyle)); if (layoutObject()->hasReflection()) { - if (!m_reflectionInfo) - m_reflectionInfo = adoptPtr(new PaintLayerReflectionInfo(*layoutBox())); - m_reflectionInfo->updateAfterStyleChange(oldStyle); - } else if (m_reflectionInfo) { - m_reflectionInfo->destroy(); - m_reflectionInfo = nullptr; + ensureRareData().reflectionInfo = adoptPtr(new PaintLayerReflectionInfo(*layoutBox())); + m_rareData->reflectionInfo->updateAfterStyleChange(oldStyle); + } else if (m_rareData && m_rareData->reflectionInfo) { + m_rareData->reflectionInfo->destroy(); + m_rareData->reflectionInfo = nullptr; } } @@ -2024,7 +2069,8 @@ void PaintLayer::addBlockSelectionGapsBounds(const LayoutRect& bounds) { if (RuntimeEnabledFeatures::selectionPaintingWithoutSelectionGapsEnabled()) return; - m_blockSelectionGapsBounds.unite(enclosingIntRect(bounds)); + if (!bounds.isEmpty()) + ensureRareData().blockSelectionGapsBounds.unite(enclosingIntRect(bounds)); blockSelectionGapsBoundsChanged(); } @@ -2032,7 +2078,8 @@ void PaintLayer::clearBlockSelectionGapsBounds() { if (RuntimeEnabledFeatures::selectionPaintingWithoutSelectionGapsEnabled()) return; - m_blockSelectionGapsBounds = IntRect(); + if (m_rareData) + m_rareData->blockSelectionGapsBounds = IntRect(); for (PaintLayer* child = firstChild(); child; child = child->nextSibling()) child->clearBlockSelectionGapsBounds(); blockSelectionGapsBoundsChanged(); @@ -2049,10 +2096,10 @@ void PaintLayer::invalidatePaintForBlockSelectionGaps() child->invalidatePaintForBlockSelectionGaps(); } - if (m_blockSelectionGapsBounds.isEmpty()) + if (!m_rareData || m_rareData->blockSelectionGapsBounds.isEmpty()) return; - LayoutRect rect(m_blockSelectionGapsBounds); + LayoutRect rect(m_rareData->blockSelectionGapsBounds); if (layoutObject()->hasOverflowClip()) { LayoutBox* box = layoutBox(); rect.move(-box->scrolledContentOffset()); @@ -2270,12 +2317,12 @@ CompositingState PaintLayer::compositingState() const // This is computed procedurally so there is no redundant state variable that // can get out of sync from the real actual compositing state. - if (m_groupedMapping) { - ASSERT(!m_compositedLayerMapping); + if (groupedMapping()) { + ASSERT(!compositedLayerMapping()); return PaintsIntoGroupedBacking; } - if (!m_compositedLayerMapping) + if (!compositedLayerMapping()) return NotComposited; return PaintsIntoOwnBacking; @@ -2291,7 +2338,7 @@ bool PaintLayer::isAllowedToQueryCompositingState() const CompositedLayerMapping* PaintLayer::compositedLayerMapping() const { ASSERT(isAllowedToQueryCompositingState()); - return m_compositedLayerMapping.get(); + return m_rareData ? m_rareData->compositedLayerMapping.get() : nullptr; } GraphicsLayer* PaintLayer::graphicsLayerBacking() const @@ -2320,11 +2367,11 @@ GraphicsLayer* PaintLayer::graphicsLayerBackingForScrolling() const void PaintLayer::ensureCompositedLayerMapping() { - if (m_compositedLayerMapping) + if (m_rareData && m_rareData->compositedLayerMapping) return; - m_compositedLayerMapping = adoptPtr(new CompositedLayerMapping(*this)); - m_compositedLayerMapping->setNeedsGraphicsLayerUpdate(GraphicsLayerUpdateSubtree); + ensureRareData().compositedLayerMapping = adoptPtr(new CompositedLayerMapping(*this)); + m_rareData->compositedLayerMapping->setNeedsGraphicsLayerUpdate(GraphicsLayerUpdateSubtree); updateOrRemoveFilterEffectBuilder(); } @@ -2340,7 +2387,8 @@ void PaintLayer::clearCompositedLayerMapping(bool layerBeingDestroyed) compositingParent->compositedLayerMapping()->setNeedsGraphicsLayerUpdate(GraphicsLayerUpdateSubtree); } - m_compositedLayerMapping.clear(); + if (m_rareData) + m_rareData->compositedLayerMapping.clear(); if (!layerBeingDestroyed) updateOrRemoveFilterEffectBuilder(); @@ -2348,27 +2396,29 @@ void PaintLayer::clearCompositedLayerMapping(bool layerBeingDestroyed) void PaintLayer::setGroupedMapping(CompositedLayerMapping* groupedMapping, SetGroupMappingOptions options) { - if (groupedMapping == m_groupedMapping) + CompositedLayerMapping* oldGroupedMapping = this->groupedMapping(); + if (groupedMapping == oldGroupedMapping) return; - if (options == InvalidateLayerAndRemoveFromMapping && m_groupedMapping) { - m_groupedMapping->setNeedsGraphicsLayerUpdate(GraphicsLayerUpdateSubtree); - m_groupedMapping->removeLayerFromSquashingGraphicsLayer(this); + if (options == InvalidateLayerAndRemoveFromMapping && oldGroupedMapping) { + oldGroupedMapping->setNeedsGraphicsLayerUpdate(GraphicsLayerUpdateSubtree); + oldGroupedMapping->removeLayerFromSquashingGraphicsLayer(this); } - m_groupedMapping = groupedMapping; - ASSERT(!m_groupedMapping || m_groupedMapping->verifyLayerInSquashingVector(this)); - if (options == InvalidateLayerAndRemoveFromMapping && m_groupedMapping) - m_groupedMapping->setNeedsGraphicsLayerUpdate(GraphicsLayerUpdateSubtree); + if (m_rareData || groupedMapping) + ensureRareData().groupedMapping = groupedMapping; + ASSERT(!groupedMapping || groupedMapping->verifyLayerInSquashingVector(this)); + if (options == InvalidateLayerAndRemoveFromMapping && groupedMapping) + groupedMapping->setNeedsGraphicsLayerUpdate(GraphicsLayerUpdateSubtree); } bool PaintLayer::hasCompositedMask() const { - return m_compositedLayerMapping && m_compositedLayerMapping->hasMaskLayer(); + return m_rareData && m_rareData->compositedLayerMapping && m_rareData->compositedLayerMapping->hasMaskLayer(); } bool PaintLayer::hasCompositedClippingMask() const { - return m_compositedLayerMapping && m_compositedLayerMapping->hasChildClippingMaskLayer(); + return m_rareData && m_rareData->compositedLayerMapping && m_rareData->compositedLayerMapping->hasChildClippingMaskLayer(); } bool PaintLayer::paintsWithTransform(GlobalPaintFlags globalPaintFlags) const @@ -2502,7 +2552,7 @@ void PaintLayer::updateFilters(const ComputedStyle* oldStyle, const ComputedStyl bool PaintLayer::attemptDirectCompositingUpdate(StyleDifference diff, const ComputedStyle* oldStyle) { - CompositingReasons oldPotentialCompositingReasonsFromStyle = m_potentialCompositingReasonsFromStyle; + CompositingReasons oldPotentialCompositingReasonsFromStyle = potentialCompositingReasonsFromStyle(); compositor()->updatePotentialCompositingReasonsFromStyle(this); // This function implements an optimization for transforms and opacity. @@ -2516,7 +2566,7 @@ bool PaintLayer::attemptDirectCompositingUpdate(StyleDifference diff, const Comp return false; // The potentialCompositingReasonsFromStyle could have changed without // a corresponding StyleDifference if an animation started or ended. - if (m_potentialCompositingReasonsFromStyle != oldPotentialCompositingReasonsFromStyle) + if (potentialCompositingReasonsFromStyle() != oldPotentialCompositingReasonsFromStyle) return false; // We could add support for reflections if we updated the transform on // the reflection layers. @@ -2529,7 +2579,7 @@ bool PaintLayer::attemptDirectCompositingUpdate(StyleDifference diff, const Comp // scheduleSVGFilterLayerUpdateHack(). if (layoutObject()->node() && layoutObject()->node()->svgFilterNeedsLayerUpdate()) return false; - if (!m_compositedLayerMapping) + if (!m_rareData || !m_rareData->compositedLayerMapping) return false; // To cut off almost all the work in the compositing update for @@ -2538,7 +2588,7 @@ bool PaintLayer::attemptDirectCompositingUpdate(StyleDifference diff, const Comp // CompositingReasonInlineTransform from the m_compositingReasons, which // means that the inline transform actually triggered assumed overlap in // the overlap map. - if (diff.transformChanged() && !(m_compositingReasons & CompositingReasonInlineTransform)) + if (diff.transformChanged() && (!m_rareData || !(m_rareData->compositingReasons & CompositingReasonInlineTransform))) return false; // We composite transparent Layers differently from non-transparent @@ -2559,7 +2609,7 @@ bool PaintLayer::attemptDirectCompositingUpdate(StyleDifference diff, const Comp // that just handles transforms and opacity. GraphicsLayerUpdateLocal // will also program bounds, clips, and many other properties that could // not possibly have changed. - m_compositedLayerMapping->setNeedsGraphicsLayerUpdate(GraphicsLayerUpdateLocal); + m_rareData->compositedLayerMapping->setNeedsGraphicsLayerUpdate(GraphicsLayerUpdateLocal); compositor()->setNeedsCompositingUpdate(CompositingUpdateAfterGeometryChange); if (m_scrollableArea) diff --git a/third_party/WebKit/Source/core/paint/PaintLayer.h b/third_party/WebKit/Source/core/paint/PaintLayer.h index 073009e9..dd5f4f5 100644 --- a/third_party/WebKit/Source/core/paint/PaintLayer.h +++ b/third_party/WebKit/Source/core/paint/PaintLayer.h @@ -90,6 +90,49 @@ private: TemporaryChange<CompositingQueryMode> m_disabler; }; +struct PaintLayerRareData { + PaintLayerRareData(); + ~PaintLayerRareData(); + + // Our current relative position offset. + LayoutSize offsetForInFlowPosition; + + OwnPtr<TransformationMatrix> transform; + + // Pointer to the enclosing Layer that caused us to be paginated. It is 0 if we are not paginated. + // + // See LayoutMultiColumnFlowThread and + // https://sites.google.com/a/chromium.org/dev/developers/design-documents/multi-column-layout + // for more information about the multicol implementation. It's important to understand the + // difference between flow thread coordinates and visual coordinates when working with multicol + // in Layer, since Layer is one of the few places where we have to worry about the + // visual ones. Internally we try to use flow-thread coordinates whenever possible. + PaintLayer* enclosingPaginationLayer; + + // These compositing reasons are updated whenever style changes, not while updating compositing layers. + // They should not be used to infer the compositing state of this layer. + CompositingReasons potentialCompositingReasonsFromStyle; + + // Once computed, indicates all that a layer needs to become composited using the CompositingReasons enum bitfield. + CompositingReasons compositingReasons; + + // If the layer paints into its own backings, this keeps track of the backings. + // It's nullptr if the layer is not composited or paints into grouped backing. + OwnPtr<CompositedLayerMapping> compositedLayerMapping; + + // If the layer paints into grouped backing (i.e. squashed), this points to the + // grouped CompositedLayerMapping. It's null if the layer is not composited or + // paints into its own backing. + CompositedLayerMapping* groupedMapping; + + IntRect blockSelectionGapsBounds; + + OwnPtr<PaintLayerReflectionInfo> reflectionInfo; + + // The accumulated subpixel offset of a composited layer's composited bounds compared to absolute coordinates. + LayoutSize subpixelAccumulation; +}; + // PaintLayer is an old object that handles lots of unrelated operations. // // We want it to die at some point and be replaced by more focused objects, @@ -161,11 +204,11 @@ class CORE_EXPORT PaintLayer : public DisplayItemClient { WTF_MAKE_NONCOPYABLE(PaintLayer); public: PaintLayer(LayoutBoxModelObject*, PaintLayerType); - ~PaintLayer(); + ~PaintLayer() override; // DisplayItemClient methods String debugName() const final; - IntRect visualRect() const override; + IntRect visualRect() const final; LayoutBoxModelObject* layoutObject() const { return m_layoutObject; } LayoutBox* layoutBox() const { return m_layoutObject && m_layoutObject->isBox() ? toLayoutBox(m_layoutObject) : 0; } @@ -190,13 +233,13 @@ public: // FIXME: Many people call this function while it has out-of-date information. bool isSelfPaintingLayer() const { return m_isSelfPaintingLayer; } - void setLayerType(PaintLayerType layerType) { m_layerType = layerType; } + void setLayerType(PaintLayerType layerType) { m_layerType = layerType; ASSERT(static_cast<PaintLayerType>(m_layerType) == layerType); } bool isTransparent() const { return layoutObject()->isTransparent() || layoutObject()->style()->hasBlendMode() || layoutObject()->hasMask(); } bool isReflection() const { return layoutObject()->isReplica(); } - PaintLayerReflectionInfo* reflectionInfo() { return m_reflectionInfo.get(); } - const PaintLayerReflectionInfo* reflectionInfo() const { return m_reflectionInfo.get(); } + PaintLayerReflectionInfo* reflectionInfo() { return m_rareData ? m_rareData->reflectionInfo.get() : nullptr; } + const PaintLayerReflectionInfo* reflectionInfo() const { return const_cast<PaintLayer*>(this)->reflectionInfo(); } const PaintLayer* root() const { @@ -225,12 +268,12 @@ public: void updateLayerPositionsAfterLayout(); void updateLayerPositionsAfterOverflowScroll(const DoubleSize& scrollDelta); - PaintLayer* enclosingPaginationLayer() const { return m_enclosingPaginationLayer; } + PaintLayer* enclosingPaginationLayer() const { return m_rareData ? m_rareData->enclosingPaginationLayer : nullptr; } void updateTransformationMatrix(); PaintLayer* renderingContextRoot(); - const LayoutSize& offsetForInFlowPosition() const { return m_offsetForInFlowPosition; } + LayoutSize offsetForInFlowPosition() const { return m_rareData ? m_rareData->offsetForInFlowPosition : LayoutSize(); } void addBlockSelectionGapsBounds(const LayoutRect&); void clearBlockSelectionGapsBounds(); @@ -341,9 +384,7 @@ public: bool hasTransformRelatedProperty() const { return layoutObject()->hasTransformRelatedProperty(); } // Note that this transform has the transform-origin baked in. - TransformationMatrix* transform() const { return m_transform.get(); } - void setTransform(PassOwnPtr<TransformationMatrix> transform) { m_transform = transform; } - void clearTransform() { m_transform.clear(); } + TransformationMatrix* transform() const { return m_rareData ? m_rareData->transform.get() : nullptr; } // currentTransform computes a transform which takes accelerated animations into account. The // resulting transform has transform-origin baked in. If the layer does not have a transform, @@ -357,7 +398,7 @@ public: TransformationMatrix perspectiveTransform() const; FloatPoint perspectiveOrigin() const; bool preserves3D() const { return layoutObject()->style()->transformStyle3D() == TransformStyle3DPreserve3D; } - bool has3DTransform() const { return m_transform && !m_transform->isAffine(); } + bool has3DTransform() const { return m_rareData && m_rareData->transform && !m_rareData->transform->isAffine(); } // FIXME: reflections should force transform-style to be flat in the style: https://bugs.webkit.org/show_bug.cgi?id=106959 bool shouldPreserve3D() const { return !layoutObject()->hasReflection() && layoutObject()->style()->transformStyle3D() == TransformStyle3DPreserve3D; } @@ -384,10 +425,10 @@ public: // (and not just to do bookkeeping related to the mapping like, say, allocating or deallocating a mapping), // then you may have incorrect logic. Use compositingState() instead. // FIXME: This is identical to null checking compositedLayerMapping(), why not just call that? - bool hasCompositedLayerMapping() const { return m_compositedLayerMapping.get(); } + bool hasCompositedLayerMapping() const { return m_rareData && m_rareData->compositedLayerMapping; } void ensureCompositedLayerMapping(); void clearCompositedLayerMapping(bool layerBeingDestroyed = false); - CompositedLayerMapping* groupedMapping() const { return m_groupedMapping; } + CompositedLayerMapping* groupedMapping() const { return m_rareData ? m_rareData->groupedMapping : nullptr; } enum SetGroupMappingOptions { InvalidateLayerAndRemoveFromMapping, DoNotInvalidateLayerAndRemoveFromMapping @@ -466,31 +507,44 @@ public: bool scrollsOverflow() const; - CompositingReasons potentialCompositingReasonsFromStyle() const { return m_potentialCompositingReasonsFromStyle; } - void setPotentialCompositingReasonsFromStyle(CompositingReasons reasons) { ASSERT(reasons == (reasons & CompositingReasonComboAllStyleDeterminedReasons)); m_potentialCompositingReasonsFromStyle = reasons; } + CompositingReasons potentialCompositingReasonsFromStyle() const { return m_rareData ? m_rareData->potentialCompositingReasonsFromStyle : CompositingReasonNone; } + void setPotentialCompositingReasonsFromStyle(CompositingReasons reasons) + { + ASSERT(reasons == (reasons & CompositingReasonComboAllStyleDeterminedReasons)); + if (m_rareData || reasons != CompositingReasonNone) + ensureRareData().potentialCompositingReasonsFromStyle = reasons; + } - bool hasStyleDeterminedDirectCompositingReasons() const { return m_potentialCompositingReasonsFromStyle & CompositingReasonComboAllDirectStyleDeterminedReasons; } + bool hasStyleDeterminedDirectCompositingReasons() const { return potentialCompositingReasonsFromStyle() & CompositingReasonComboAllDirectStyleDeterminedReasons; } class AncestorDependentCompositingInputs { DISALLOW_NEW(); public: AncestorDependentCompositingInputs() - : opacityAncestor(0) - , transformAncestor(0) - , filterAncestor(0) - , clippingContainer(0) - , ancestorScrollingLayer(0) - , nearestFixedPositionLayer(0) - , scrollParent(0) - , clipParent(0) - , hasAncestorWithClipPath(false) + : clippingContainer(nullptr) { } IntRect clippedAbsoluteBoundingBox; + const LayoutObject* clippingContainer; + }; + + class RareAncestorDependentCompositingInputs { + public: + RareAncestorDependentCompositingInputs() + : opacityAncestor(nullptr) + , transformAncestor(nullptr) + , filterAncestor(nullptr) + , ancestorScrollingLayer(nullptr) + , nearestFixedPositionLayer(nullptr) + , scrollParent(nullptr) + , clipParent(nullptr) + { } + + bool isDefault() const { return !opacityAncestor && !transformAncestor && !filterAncestor && !ancestorScrollingLayer && !nearestFixedPositionLayer && !scrollParent && !clipParent; } + const PaintLayer* opacityAncestor; const PaintLayer* transformAncestor; const PaintLayer* filterAncestor; - const LayoutObject* clippingContainer; const PaintLayer* ancestorScrollingLayer; const PaintLayer* nearestFixedPositionLayer; @@ -508,20 +562,6 @@ public: // needs to know about clip parents in order to circumvent its normal // clipping logic. const PaintLayer* clipParent; - - unsigned hasAncestorWithClipPath : 1; - }; - - class DescendantDependentCompositingInputs { - DISALLOW_NEW(); - public: - DescendantDependentCompositingInputs() - : hasDescendantWithClipPath(false) - , hasNonIsolatedDescendantWithBlendMode(false) - { } - - unsigned hasDescendantWithClipPath : 1; - unsigned hasNonIsolatedDescendantWithBlendMode : 1; }; void setNeedsCompositingInputsUpdate(); @@ -534,30 +574,27 @@ public: return m_needsDescendantDependentCompositingInputsUpdate; } - void updateAncestorDependentCompositingInputs(const AncestorDependentCompositingInputs&); - void updateDescendantDependentCompositingInputs(const DescendantDependentCompositingInputs&); + void updateAncestorDependentCompositingInputs(const AncestorDependentCompositingInputs&, const RareAncestorDependentCompositingInputs&, bool hasAncestorWithClipPath); + void updateDescendantDependentCompositingInputs(bool hasDescendantWithClipPath, bool hasNonIsolatedDescendantWithBlendMode); void didUpdateCompositingInputs(); - const AncestorDependentCompositingInputs& ancestorDependentCompositingInputs() const { ASSERT(!m_needsAncestorDependentCompositingInputsUpdate); return m_ancestorDependentCompositingInputs; } - const DescendantDependentCompositingInputs& descendantDependentCompositingInputs() const { ASSERT(!m_needsDescendantDependentCompositingInputsUpdate); return m_descendantDependentCompositingInputs; } - - IntRect clippedAbsoluteBoundingBox() const { return ancestorDependentCompositingInputs().clippedAbsoluteBoundingBox; } - const PaintLayer* opacityAncestor() const { return ancestorDependentCompositingInputs().opacityAncestor; } - const PaintLayer* transformAncestor() const { return ancestorDependentCompositingInputs().transformAncestor; } - const PaintLayer* filterAncestor() const { return ancestorDependentCompositingInputs().filterAncestor; } - const LayoutObject* clippingContainer() const { return ancestorDependentCompositingInputs().clippingContainer; } - const PaintLayer* ancestorScrollingLayer() const { return ancestorDependentCompositingInputs().ancestorScrollingLayer; } - const PaintLayer* nearestFixedPositionLayer() const { return ancestorDependentCompositingInputs().nearestFixedPositionLayer; } - PaintLayer* scrollParent() const { return const_cast<PaintLayer*>(ancestorDependentCompositingInputs().scrollParent); } - PaintLayer* clipParent() const { return const_cast<PaintLayer*>(ancestorDependentCompositingInputs().clipParent); } - bool hasAncestorWithClipPath() const { return ancestorDependentCompositingInputs().hasAncestorWithClipPath; } - bool hasDescendantWithClipPath() const { return descendantDependentCompositingInputs().hasDescendantWithClipPath; } + IntRect clippedAbsoluteBoundingBox() const { ASSERT(!m_needsAncestorDependentCompositingInputsUpdate); return m_ancestorDependentCompositingInputs.clippedAbsoluteBoundingBox; } + const PaintLayer* opacityAncestor() const { ASSERT(!m_needsAncestorDependentCompositingInputsUpdate); return m_rareAncestorDependentCompositingInputs ? m_rareAncestorDependentCompositingInputs->opacityAncestor : nullptr; } + const PaintLayer* transformAncestor() const { ASSERT(!m_needsAncestorDependentCompositingInputsUpdate); return m_rareAncestorDependentCompositingInputs ? m_rareAncestorDependentCompositingInputs->transformAncestor : nullptr; } + const PaintLayer* filterAncestor() const { ASSERT(!m_needsAncestorDependentCompositingInputsUpdate); return m_rareAncestorDependentCompositingInputs ? m_rareAncestorDependentCompositingInputs->filterAncestor : nullptr; } + const LayoutObject* clippingContainer() const { ASSERT(!m_needsAncestorDependentCompositingInputsUpdate); return m_ancestorDependentCompositingInputs.clippingContainer; } + const PaintLayer* ancestorScrollingLayer() const { ASSERT(!m_needsAncestorDependentCompositingInputsUpdate); return m_rareAncestorDependentCompositingInputs ? m_rareAncestorDependentCompositingInputs->ancestorScrollingLayer : nullptr; } + const PaintLayer* nearestFixedPositionLayer() const { ASSERT(!m_needsAncestorDependentCompositingInputsUpdate); return m_rareAncestorDependentCompositingInputs ? m_rareAncestorDependentCompositingInputs->nearestFixedPositionLayer : nullptr; } + const PaintLayer* scrollParent() const { ASSERT(!m_needsAncestorDependentCompositingInputsUpdate); return m_rareAncestorDependentCompositingInputs ? m_rareAncestorDependentCompositingInputs->scrollParent : nullptr; } + const PaintLayer* clipParent() const { ASSERT(!m_needsAncestorDependentCompositingInputsUpdate); return m_rareAncestorDependentCompositingInputs ? m_rareAncestorDependentCompositingInputs->clipParent : nullptr; } + bool hasAncestorWithClipPath() const { ASSERT(!m_needsAncestorDependentCompositingInputsUpdate); return m_hasAncestorWithClipPath; } + bool hasDescendantWithClipPath() const { ASSERT(!m_needsDescendantDependentCompositingInputsUpdate); return m_hasDescendantWithClipPath; } bool hasNonIsolatedDescendantWithBlendMode() const; bool lostGroupedMapping() const { ASSERT(isAllowedToQueryCompositingState()); return m_lostGroupedMapping; } void setLostGroupedMapping(bool b) { m_lostGroupedMapping = b; } - CompositingReasons compositingReasons() const { ASSERT(isAllowedToQueryCompositingState()); return m_compositingReasons; } + CompositingReasons compositingReasons() const { ASSERT(isAllowedToQueryCompositingState()); return m_rareData ? m_rareData->compositingReasons : CompositingReasonNone; } void setCompositingReasons(CompositingReasons, CompositingReasons mask = CompositingReasonAll); bool hasCompositingDescendant() const { ASSERT(isAllowedToQueryCompositingState()); return m_hasCompositingDescendant; } @@ -713,7 +750,14 @@ private: void markCompositingContainerChainForNeedsRepaint(); - PaintLayerType m_layerType; + PaintLayerRareData& ensureRareData() + { + if (!m_rareData) + m_rareData = adoptPtr(new PaintLayerRareData); + return *m_rareData; + } + + unsigned m_layerType : 2; // PaintLayerType // Self-painting layer is an optimization where we avoid the heavy Layer painting // machinery for a Layer allocated only to handle the overflow clip case. @@ -770,6 +814,11 @@ private: unsigned m_needsPaintPhaseDescendantOutlines : 1; unsigned m_needsPaintPhaseFloat : 1; + // These bitfields are part of ancestor/descendant dependent compositing inputs. + unsigned m_hasDescendantWithClipPath : 1; + unsigned m_hasNonIsolatedDescendantWithBlendMode : 1; + unsigned m_hasAncestorWithClipPath : 1; + LayoutBoxModelObject* m_layoutObject; PaintLayer* m_parent; @@ -778,9 +827,6 @@ private: PaintLayer* m_first; PaintLayer* m_last; - // Our current relative position offset. - LayoutSize m_offsetForInFlowPosition; - // Our (x,y) coordinates are in our parent layer's coordinate space. LayoutPoint m_location; @@ -794,44 +840,19 @@ private: LayoutUnit m_staticInlinePosition; LayoutUnit m_staticBlockPosition; - OwnPtr<TransformationMatrix> m_transform; - - // Pointer to the enclosing Layer that caused us to be paginated. It is 0 if we are not paginated. - // - // See LayoutMultiColumnFlowThread and - // https://sites.google.com/a/chromium.org/dev/developers/design-documents/multi-column-layout - // for more information about the multicol implementation. It's important to understand the - // difference between flow thread coordinates and visual coordinates when working with multicol - // in Layer, since Layer is one of the few places where we have to worry about the - // visual ones. Internally we try to use flow-thread coordinates whenever possible. - PaintLayer* m_enclosingPaginationLayer; - - // These compositing reasons are updated whenever style changes, not while updating compositing layers. - // They should not be used to infer the compositing state of this layer. - CompositingReasons m_potentialCompositingReasonsFromStyle; - - // Once computed, indicates all that a layer needs to become composited using the CompositingReasons enum bitfield. - CompositingReasons m_compositingReasons; - - DescendantDependentCompositingInputs m_descendantDependentCompositingInputs; AncestorDependentCompositingInputs m_ancestorDependentCompositingInputs; + OwnPtr<RareAncestorDependentCompositingInputs> m_rareAncestorDependentCompositingInputs; - IntRect m_blockSelectionGapsBounds; - - OwnPtr<CompositedLayerMapping> m_compositedLayerMapping; OwnPtrWillBePersistent<PaintLayerScrollableArea> m_scrollableArea; - CompositedLayerMapping* m_groupedMapping; - PaintLayerClipper m_clipper; // FIXME: Lazily allocate? OwnPtr<PaintLayerStackingNode> m_stackingNode; - OwnPtr<PaintLayerReflectionInfo> m_reflectionInfo; - - LayoutSize m_subpixelAccumulation; // The accumulated subpixel offset of a composited layer's composited bounds compared to absolute coordinates. IntSize m_previousScrollOffsetAccumulationForPainting; RefPtr<ClipRects> m_previousPaintingClipRects; LayoutRect m_previousPaintDirtyRect; + + OwnPtr<PaintLayerRareData> m_rareData; }; } // namespace blink |