Commit 65fe1a36 authored by Tien-Ren Chen's avatar Tien-Ren Chen Committed by Commit Bot

[Blink/SPv175] Support more layers for SPv175

Added support for squashing layers and threaded scrolling layers.

BUG=771643

Cq-Include-Trybots: master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2
Change-Id: Iab0ecf45816be33c2a69d743a8cbd13689234402
Reviewed-on: https://chromium-review.googlesource.com/724187Reviewed-by: default avatarXianzhu Wang <wangxianzhu@chromium.org>
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#510108}
parent c6fd2efb
......@@ -228,6 +228,8 @@ blink_core_sources("paint") {
"compositing/CompositingInputsUpdater.h",
"compositing/CompositingLayerAssigner.cpp",
"compositing/CompositingLayerAssigner.h",
"compositing/CompositingLayerPropertyUpdater.cpp",
"compositing/CompositingLayerPropertyUpdater.h",
"compositing/CompositingReasonFinder.cpp",
"compositing/CompositingReasonFinder.h",
"compositing/CompositingRequirementsUpdater.cpp",
......
......@@ -24,6 +24,7 @@
#include "platform/graphics/GraphicsContextStateSaver.h"
#include "platform/graphics/paint/DisplayItemCacheSkipper.h"
#include "platform/graphics/paint/DrawingRecorder.h"
#include "platform/graphics/paint/ScopedPaintChunkProperties.h"
#include "platform/wtf/Optional.h"
namespace blink {
......@@ -47,6 +48,7 @@ void BoxPainter::PaintBoxDecorationBackground(const PaintInfo& paint_info,
const LayoutPoint& paint_offset) {
LayoutRect paint_rect;
Optional<ScrollRecorder> scroll_recorder;
Optional<ScopedPaintChunkProperties> scoped_scroll_property;
if (BoxModelObjectPainter::
IsPaintingBackgroundOfPaintContainerIntoScrollingContentsLayer(
&layout_box_, paint_info)) {
......@@ -54,8 +56,17 @@ void BoxPainter::PaintBoxDecorationBackground(const PaintInfo& paint_info,
// contents layer of a composited scroller we need to include the entire
// overflow rect.
paint_rect = layout_box_.LayoutOverflowRect();
scroll_recorder.emplace(paint_info.context, layout_box_, paint_info.phase,
layout_box_.ScrolledContentOffset());
if (RuntimeEnabledFeatures::SlimmingPaintV175Enabled()) {
PaintChunkProperties properties(
layout_box_.FirstFragment()->ContentsProperties());
properties.backface_hidden = layout_box_.HasHiddenBackface();
scoped_scroll_property.emplace(
paint_info.context.GetPaintController(), layout_box_,
DisplayItem::PaintPhaseToScrollType(paint_info.phase), properties);
}
// The background painting code assumes that the borders are part of the
// paintRect so we expand the paintRect by the border size when painting the
......
......@@ -34,21 +34,60 @@ FragmentData& FragmentData::EnsureNextFragment() {
return *next_fragment_.get();
}
const TransformPaintPropertyNode* FragmentData::GetPreTransform() const {
if (!paint_properties_)
return local_border_box_properties_->Transform();
if (paint_properties_->Transform())
return paint_properties_->Transform()->Parent();
return local_border_box_properties_->Transform();
}
const TransformPaintPropertyNode* FragmentData::GetPostScrollTranslation()
const {
if (!paint_properties_)
return local_border_box_properties_->Transform();
if (paint_properties_->ScrollTranslation())
return paint_properties_->ScrollTranslation();
if (paint_properties_->Perspective())
return paint_properties_->Perspective();
return local_border_box_properties_->Transform();
}
const ClipPaintPropertyNode* FragmentData::GetPreCssClip() const {
if (!paint_properties_)
return local_border_box_properties_->Clip();
if (paint_properties_->CssClip())
return paint_properties_->CssClip()->Parent();
return local_border_box_properties_->Clip();
}
const ClipPaintPropertyNode* FragmentData::GetPostOverflowClip() const {
if (!paint_properties_)
return local_border_box_properties_->Clip();
if (paint_properties_->OverflowClip())
return paint_properties_->OverflowClip();
return local_border_box_properties_->Clip();
}
const EffectPaintPropertyNode* FragmentData::GetPreEffect() const {
if (!paint_properties_)
return local_border_box_properties_->Effect();
if (paint_properties_->Effect())
return paint_properties_->Effect()->Parent();
if (paint_properties_->Filter())
return paint_properties_->Filter()->Parent();
return local_border_box_properties_->Effect();
}
PropertyTreeState FragmentData::PreEffectProperties() const {
DCHECK(local_border_box_properties_);
return PropertyTreeState(GetPreTransform(), GetPreCssClip(), GetPreEffect());
}
PropertyTreeState FragmentData::ContentsProperties() const {
DCHECK(local_border_box_properties_);
PropertyTreeState contents(*local_border_box_properties_);
if (auto* properties = PaintProperties()) {
if (properties->ScrollTranslation())
contents.SetTransform(properties->ScrollTranslation());
if (properties->OverflowClip())
contents.SetClip(properties->OverflowClip());
else if (properties->CssClip())
contents.SetClip(properties->CssClip());
}
// TODO(chrishtr): cssClipFixedPosition needs to be handled somehow.
return contents;
return PropertyTreeState(GetPostScrollTranslation(), GetPostOverflowClip(),
local_border_box_properties_->Effect());
}
} // namespace blink
......@@ -29,7 +29,7 @@ class CORE_EXPORT FragmentData {
ObjectPaintProperties& EnsurePaintProperties();
void ClearPaintProperties();
FragmentData* NextFragment() { return next_fragment_.get(); }
FragmentData* NextFragment() const { return next_fragment_.get(); }
FragmentData& EnsureNextFragment();
void ClearNextFragment() { next_fragment_.reset(); }
......@@ -44,6 +44,11 @@ class CORE_EXPORT FragmentData {
void ClearLocalBorderBoxProperties();
void SetLocalBorderBoxProperties(PropertyTreeState&);
// This is the complete set of property nodes that is inherited
// from the ancestor before applying any local CSS properties,
// but includes paint offset transform.
PropertyTreeState PreEffectProperties() const;
// This is the complete set of property nodes that can be used to
// paint the contents of this fragment. It is similar to
// |local_border_box_properties_| but includes properties (e.g.,
......@@ -67,6 +72,12 @@ class CORE_EXPORT FragmentData {
}
private:
const TransformPaintPropertyNode* GetPreTransform() const;
const TransformPaintPropertyNode* GetPostScrollTranslation() const;
const ClipPaintPropertyNode* GetPreCssClip() const;
const ClipPaintPropertyNode* GetPostOverflowClip() const;
const EffectPaintPropertyNode* GetPreEffect() const;
// Holds references to the paint property nodes created by this object.
std::unique_ptr<ObjectPaintProperties> paint_properties_;
......
......@@ -879,37 +879,6 @@ static bool NeedsScrollbarPaintOffset(const LayoutObject& object) {
return false;
}
void PaintPropertyTreeBuilder::UpdateCompositedLayerStates(
const LayoutObject& object,
PaintPropertyTreeBuilderFragmentContext& context,
bool& force_subtree_update) {
DCHECK(RuntimeEnabledFeatures::SlimmingPaintV175Enabled() &&
!RuntimeEnabledFeatures::SlimmingPaintV2Enabled());
if (!object.NeedsPaintPropertyUpdate() && !force_subtree_update)
return;
if (!object.HasLayer())
return;
CompositedLayerMapping* mapping =
ToLayoutBoxModelObject(object).Layer()->GetCompositedLayerMapping();
if (!mapping)
return;
LayoutPoint snapped_paint_offset =
context.current.paint_offset - mapping->SubpixelAccumulation();
DCHECK(snapped_paint_offset == RoundedIntPoint(snapped_paint_offset));
if (GraphicsLayer* main_layer = mapping->MainGraphicsLayer()) {
PropertyTreeState layer_state(context.current.transform,
context.current.clip, context.current_effect);
IntPoint layer_offset = RoundedIntPoint(snapped_paint_offset) +
main_layer->OffsetFromLayoutObject();
main_layer->SetLayerState(std::move(layer_state), layer_offset);
}
// TODO(trchen): Complete for all drawable layers.
}
// TODO(trchen): Remove this once we bake the paint offset into frameRect.
void PaintPropertyTreeBuilder::UpdateScrollbarPaintOffset(
const LayoutObject& object,
......@@ -1448,6 +1417,8 @@ void PaintPropertyTreeBuilder::UpdateForObjectLocationAndSize(
context.fragment_clip_context->paint_offset = paint_offset;
fragment_data->SetPaintOffset(paint_offset);
} else if (fragment_data) {
fragment_data->SetPaintOffset(context.current.paint_offset);
}
if (paint_offset_translation)
......@@ -1686,11 +1657,6 @@ void PaintPropertyTreeBuilder::UpdateFragmentPropertiesForSelf(
}
UpdateLocalBorderBoxContext(object, fragment_context, fragment_data,
full_context.force_subtree_update);
if (RuntimeEnabledFeatures::SlimmingPaintV175Enabled() &&
!RuntimeEnabledFeatures::SlimmingPaintV2Enabled()) {
UpdateCompositedLayerStates(object, fragment_context,
full_context.force_subtree_update);
}
if (fragment_data && fragment_data->PaintProperties()) {
ObjectPaintProperties* properties = fragment_data->PaintProperties();
if (RuntimeEnabledFeatures::SlimmingPaintV175Enabled()) {
......
......@@ -227,10 +227,6 @@ class PaintPropertyTreeBuilder {
PaintPropertyTreeBuilderFragmentContext&,
FragmentData*,
bool& force_subtree_update);
ALWAYS_INLINE static void UpdateCompositedLayerStates(
const LayoutObject&,
PaintPropertyTreeBuilderFragmentContext&,
bool& force_subtree_update);
ALWAYS_INLINE static void UpdateScrollbarPaintOffset(
const LayoutObject&,
ObjectPaintProperties&,
......
......@@ -11,6 +11,7 @@
#include "core/layout/LayoutMultiColumnSpannerPlaceholder.h"
#include "core/layout/LayoutView.h"
#include "core/paint/PaintLayer.h"
#include "core/paint/compositing/CompositingLayerPropertyUpdater.h"
#include "platform/graphics/paint/GeometryMapper.h"
namespace blink {
......@@ -206,6 +207,8 @@ void PrePaintTreeWalk::Walk(const LayoutObject& object,
InvalidatePaintLayerOptimizationsIfNeeded(object, context);
}
CompositingLayerPropertyUpdater::Update(object);
for (const LayoutObject* child = object.SlowFirstChild(); child;
child = child->NextSibling()) {
if (child->IsLayoutMultiColumnSpannerPlaceholder()) {
......
......@@ -904,11 +904,8 @@ static LayoutPoint ComputeOffsetFromCompositedAncestor(
// there is one and only one fragment.
LayoutPoint offset = layer->VisualOffsetFromAncestor(
composited_ancestor, local_representative_point_for_fragmentation);
if (composited_ancestor) {
offset.Move(composited_ancestor->GetCompositedLayerMapping()
->OwningLayer()
.SubpixelAccumulation());
}
if (composited_ancestor)
offset.Move(composited_ancestor->SubpixelAccumulation());
offset.MoveBy(-local_representative_point_for_fragmentation);
offset.MoveBy(-LayoutPoint(offset_for_sticky_position));
return offset;
......@@ -977,11 +974,11 @@ void CompositedLayerMapping::ComputeBoundsOfOwningLayer(
void CompositedLayerMapping::UpdateSquashingLayerGeometry(
const IntPoint& graphics_layer_parent_location,
const PaintLayer* compositing_container,
const IntPoint& snapped_offset_from_composited_ancestor,
Vector<GraphicsLayerPaintInfo>& layers,
GraphicsLayer* squashing_layer,
LayoutPoint* offset_from_transformed_ancestor,
Vector<PaintLayer*>& layers_needing_paint_invalidation) {
if (!squashing_layer)
if (!squashing_layer_)
return;
LayoutPoint compositing_container_offset_from_parent_graphics_layer =
......@@ -1088,8 +1085,15 @@ void CompositedLayerMapping::UpdateSquashingLayerGeometry(
layers[i].paint_layer->SetSubpixelAccumulation(subpixel_accumulation);
}
squashing_layer->SetPosition(squash_layer_bounds.Location());
squashing_layer->SetSize(FloatSize(squash_layer_bounds.Size()));
squashing_layer_->SetPosition(squash_layer_bounds.Location());
squashing_layer_->SetSize(FloatSize(squash_layer_bounds.Size()));
// We can't squashing_layer_->SetOffsetFromLayoutObject().
// Squashing layer has special paint and invalidation logic that already
// compensated for compositing bounds, setting it here would end up
// double adjustment. The value is stored to be used by SPv175.
squashing_layer_offset_from_layout_object_ =
squash_layer_bounds.Location() - snapped_offset_from_composited_ancestor +
ToIntSize(graphics_layer_parent_location);
*offset_from_transformed_ancestor =
compositing_container_offset_from_transformed_ancestor;
......@@ -1166,8 +1170,8 @@ void CompositedLayerMapping::UpdateGraphicsLayerGeometry(
snapped_offset_from_composited_ancestor, graphics_layer_parent_location);
UpdateStickyConstraints(GetLayoutObject().StyleRef());
UpdateSquashingLayerGeometry(
graphics_layer_parent_location, compositing_container, squashed_layers_,
squashing_layer_.get(),
graphics_layer_parent_location, compositing_container,
snapped_offset_from_composited_ancestor, squashed_layers_,
&squashing_layer_offset_from_transformed_ancestor_,
layers_needing_paint_invalidation);
......@@ -1596,7 +1600,7 @@ void CompositedLayerMapping::UpdateScrollingLayerGeometry(
IntSize old_scrolling_layer_offset =
scrolling_layer_->OffsetFromLayoutObject();
scrolling_layer_->SetOffsetFromLayoutObject(
-ToIntSize(overflow_clip_rect.Location()));
ToIntSize(overflow_clip_rect.Location()));
if (child_clipping_mask_layer_ && !GetLayoutObject().Style()->ClipPath()) {
child_clipping_mask_layer_->SetPosition(scrolling_layer_->GetPosition());
......
......@@ -166,6 +166,9 @@ class CORE_EXPORT CompositedLayerMapping final : public GraphicsLayerClient {
return squashing_containment_layer_.get();
}
GraphicsLayer* SquashingLayer() const { return squashing_layer_.get(); }
const IntSize& SquashingLayerOffsetFromLayoutObject() const {
return squashing_layer_offset_from_layout_object_;
}
void SetSquashingContentsNeedDisplay();
void SetContentsNeedDisplay();
......@@ -335,8 +338,8 @@ class CORE_EXPORT CompositedLayerMapping final : public GraphicsLayerClient {
void UpdateSquashingLayerGeometry(
const IntPoint& graphics_layer_parent_location,
const PaintLayer* compositing_container,
const IntPoint& snapped_offset_from_composited_ancestor,
Vector<GraphicsLayerPaintInfo>& layers,
GraphicsLayer*,
LayoutPoint* offset_from_transformed_ancestor,
Vector<PaintLayer*>& layers_needing_paint_invalidation);
void UpdateMainGraphicsLayerGeometry(
......@@ -665,24 +668,24 @@ class CORE_EXPORT CompositedLayerMapping final : public GraphicsLayerClient {
// A squashing CLM has two possible squashing-related structures.
//
// If m_ancestorClippingLayer is present:
// If ancestor_clipping_layer_ is present:
//
// m_ancestorClippingLayer
// + m_graphicsLayer
// + m_squashingLayer
// ancestor_clipping_layer_
// + graphics_layer_
// + squashing_layer_
//
// If not:
//
// m_squashingContainmentLayer
// + m_graphicsLayer
// + m_squashingLayer
// squashing_containment_layer_
// + graphics_layer_
// + squashing_layer_
//
// Stacking children of a squashed layer receive graphics layers that are
// parented to the compositd ancestor of the squashed layer (i.e. nearest
// enclosing composited layer that is not
// squashed).
// Only used if any squashed layers exist and m_squashingContainmentLayer is
// Only used if any squashed layers exist and ancestor_clipping_layer_ is
// not present, to contain the squashed layers as siblings to the rest of the
// GraphicsLayer tree chunk.
std::unique_ptr<GraphicsLayer> squashing_containment_layer_;
......@@ -692,6 +695,7 @@ class CORE_EXPORT CompositedLayerMapping final : public GraphicsLayerClient {
std::unique_ptr<GraphicsLayer> squashing_layer_;
Vector<GraphicsLayerPaintInfo> squashed_layers_;
LayoutPoint squashing_layer_offset_from_transformed_ancestor_;
IntSize squashing_layer_offset_from_layout_object_;
LayoutRect composited_bounds_;
......
// Copyright 2017 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/paint/compositing/CompositingLayerPropertyUpdater.h"
#include "core/layout/LayoutBoxModelObject.h"
#include "core/paint/FragmentData.h"
#include "core/paint/compositing/CompositedLayerMapping.h"
#include "platform/runtime_enabled_features.h"
namespace blink {
void CompositingLayerPropertyUpdater::Update(const LayoutObject& object) {
if (!RuntimeEnabledFeatures::SlimmingPaintV175Enabled() ||
RuntimeEnabledFeatures::SlimmingPaintV2Enabled())
return;
if (!object.HasLayer())
return;
CompositedLayerMapping* mapping =
ToLayoutBoxModelObject(object).Layer()->GetCompositedLayerMapping();
if (!mapping)
return;
const FragmentData* fragment_data = object.FirstFragment();
DCHECK(fragment_data);
DCHECK(fragment_data->LocalBorderBoxProperties());
// SPv1 compositing forces single fragment for composited elements.
DCHECK(!fragment_data->NextFragment());
LayoutPoint layout_snapped_paint_offset =
fragment_data->PaintOffset() - mapping->SubpixelAccumulation();
IntPoint snapped_paint_offset = RoundedIntPoint(layout_snapped_paint_offset);
DCHECK(layout_snapped_paint_offset == snapped_paint_offset);
if (GraphicsLayer* main_layer = mapping->MainGraphicsLayer()) {
main_layer->SetLayerState(
PropertyTreeState(*fragment_data->LocalBorderBoxProperties()),
snapped_paint_offset + main_layer->OffsetFromLayoutObject());
}
if (GraphicsLayer* scrolling_contents_layer =
mapping->ScrollingContentsLayer()) {
scrolling_contents_layer->SetLayerState(
fragment_data->ContentsProperties(),
snapped_paint_offset +
scrolling_contents_layer->OffsetFromLayoutObject());
}
if (GraphicsLayer* squashing_layer = mapping->SquashingLayer()) {
squashing_layer->SetLayerState(
fragment_data->PreEffectProperties(),
snapped_paint_offset + mapping->SquashingLayerOffsetFromLayoutObject());
}
if (GraphicsLayer* foreground_layer = mapping->ForegroundLayer()) {
foreground_layer->SetLayerState(
fragment_data->ContentsProperties(),
snapped_paint_offset + foreground_layer->OffsetFromLayoutObject());
}
// TODO(trchen): Complete for all drawable layers.
}
} // namespace blink
// Copyright 2017 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.
#ifndef CompositingLayerPropertyUpdater_h
#define CompositingLayerPropertyUpdater_h
#include "platform/wtf/Allocator.h"
namespace blink {
class LayoutObject;
class CompositingLayerPropertyUpdater {
STATIC_ONLY(CompositingLayerPropertyUpdater);
public:
static void Update(const LayoutObject&);
};
} // namespace blink
#endif // PaintPropertyTreeBuilder_h
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment