Commit d404e0ef authored by Xianzhu Wang's avatar Xianzhu Wang Committed by Commit Bot

Use display item visual rects for NG box fragments

Bug: 1104064
Change-Id: I518bc448da22853a2e58eb59b9373965d6dfb343
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2304989
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790154}
parent d6373d01
...@@ -513,12 +513,12 @@ void NGBoxFragmentPainter::PaintObject( ...@@ -513,12 +513,12 @@ void NGBoxFragmentPainter::PaintObject(
const NGPhysicalBoxFragment& physical_box_fragment = PhysicalFragment(); const NGPhysicalBoxFragment& physical_box_fragment = PhysicalFragment();
const ComputedStyle& style = box_fragment_.Style(); const ComputedStyle& style = box_fragment_.Style();
bool is_visible = IsVisibleToPaint(physical_box_fragment, style); bool is_visible = IsVisibleToPaint(physical_box_fragment, style);
if (!is_visible)
suppress_box_decoration_background = true;
if (ShouldPaintSelfBlockBackground(paint_phase)) { if (ShouldPaintSelfBlockBackground(paint_phase)) {
PaintBoxDecorationBackground(paint_info, paint_offset, if (is_visible) {
suppress_box_decoration_background); PaintBoxDecorationBackground(paint_info, paint_offset,
suppress_box_decoration_background);
}
// We're done. We don't bother painting any children. // We're done. We don't bother painting any children.
if (paint_phase == PaintPhase::kSelfBlockBackgroundOnly) if (paint_phase == PaintPhase::kSelfBlockBackgroundOnly)
return; return;
...@@ -542,9 +542,9 @@ void NGBoxFragmentPainter::PaintObject( ...@@ -542,9 +542,9 @@ void NGBoxFragmentPainter::PaintObject(
(!physical_box_fragment.Children().empty() || (!physical_box_fragment.Children().empty() ||
physical_box_fragment.HasItems() || inline_box_cursor_) && physical_box_fragment.HasItems() || inline_box_cursor_) &&
!paint_info.DescendantPaintingBlocked()) { !paint_info.DescendantPaintingBlocked()) {
if (UNLIKELY(paint_phase == PaintPhase::kForeground && if (is_visible && UNLIKELY(paint_phase == PaintPhase::kForeground &&
box_fragment_.IsCSSBox() && box_fragment_.IsCSSBox() &&
box_fragment_.Style().HasColumnRule())) box_fragment_.Style().HasColumnRule()))
PaintColumnRules(paint_info, paint_offset); PaintColumnRules(paint_info, paint_offset);
if (paint_phase != PaintPhase::kFloat) { if (paint_phase != PaintPhase::kFloat) {
...@@ -619,7 +619,7 @@ void NGBoxFragmentPainter::PaintObject( ...@@ -619,7 +619,7 @@ void NGBoxFragmentPainter::PaintObject(
} }
} }
if (ShouldPaintSelfOutline(paint_phase)) { if (is_visible && ShouldPaintSelfOutline(paint_phase)) {
NGFragmentPainter(box_fragment_, GetDisplayItemClient()) NGFragmentPainter(box_fragment_, GetDisplayItemClient())
.PaintOutline(paint_info, paint_offset); .PaintOutline(paint_info, paint_offset);
} }
...@@ -893,7 +893,7 @@ void NGBoxFragmentPainter::PaintMask(const PaintInfo& paint_info, ...@@ -893,7 +893,7 @@ void NGBoxFragmentPainter::PaintMask(const PaintInfo& paint_info,
box_fragment_.GetLayoutObject())); box_fragment_.GetLayoutObject()));
DrawingRecorder recorder(paint_info.context, GetDisplayItemClient(), DrawingRecorder recorder(paint_info.context, GetDisplayItemClient(),
paint_info.phase); paint_info.phase, VisualRect(paint_offset));
PhysicalRect paint_rect(paint_offset, box_fragment_.Size()); PhysicalRect paint_rect(paint_offset, box_fragment_.Size());
const NGBorderEdges& border_edges = BorderEdges(); const NGBorderEdges& border_edges = BorderEdges();
PaintMaskImages(paint_info, paint_rect, *box_fragment_.GetLayoutObject(), PaintMaskImages(paint_info, paint_rect, *box_fragment_.GetLayoutObject(),
...@@ -914,6 +914,7 @@ void NGBoxFragmentPainter::PaintBoxDecorationBackground( ...@@ -914,6 +914,7 @@ void NGBoxFragmentPainter::PaintBoxDecorationBackground(
base::Optional<ScopedBoxContentsPaintState> contents_paint_state; base::Optional<ScopedBoxContentsPaintState> contents_paint_state;
bool painting_scrolling_background = bool painting_scrolling_background =
IsPaintingScrollingBackground(paint_info); IsPaintingScrollingBackground(paint_info);
IntRect visual_rect;
if (painting_scrolling_background) { if (painting_scrolling_background) {
// For the case where we are painting the background into the scrolling // For the case where we are painting the background into the scrolling
// contents layer of a composited scroller we need to include the entire // contents layer of a composited scroller we need to include the entire
...@@ -931,6 +932,8 @@ void NGBoxFragmentPainter::PaintBoxDecorationBackground( ...@@ -931,6 +932,8 @@ void NGBoxFragmentPainter::PaintBoxDecorationBackground(
background_client = &layout_box.GetScrollableArea() background_client = &layout_box.GetScrollableArea()
->GetScrollingBackgroundDisplayItemClient(); ->GetScrollingBackgroundDisplayItemClient();
visual_rect = layout_box.GetScrollableArea()->ScrollingBackgroundVisualRect(
paint_offset);
} else { } else {
paint_rect.offset = paint_offset; paint_rect.offset = paint_offset;
paint_rect.size = box_fragment_.Size(); paint_rect.size = box_fragment_.Size();
...@@ -939,6 +942,7 @@ void NGBoxFragmentPainter::PaintBoxDecorationBackground( ...@@ -939,6 +942,7 @@ void NGBoxFragmentPainter::PaintBoxDecorationBackground(
PhysicalSize(ToLayoutBox(layout_object).PixelSnappedSize()); PhysicalSize(ToLayoutBox(layout_object).PixelSnappedSize());
} }
background_client = &GetDisplayItemClient(); background_client = &GetDisplayItemClient();
visual_rect = VisualRect(paint_offset);
} }
if (!suppress_box_decoration_background) { if (!suppress_box_decoration_background) {
...@@ -951,7 +955,7 @@ void NGBoxFragmentPainter::PaintBoxDecorationBackground( ...@@ -951,7 +955,7 @@ void NGBoxFragmentPainter::PaintBoxDecorationBackground(
PaintBoxDecorationBackgroundWithRect( PaintBoxDecorationBackgroundWithRect(
contents_paint_state ? contents_paint_state->GetPaintInfo() contents_paint_state ? contents_paint_state->GetPaintInfo()
: paint_info, : paint_info,
paint_rect, *background_client); visual_rect, paint_rect, *background_client);
} }
} }
...@@ -985,6 +989,7 @@ void NGBoxFragmentPainter::PaintBoxDecorationBackground( ...@@ -985,6 +989,7 @@ void NGBoxFragmentPainter::PaintBoxDecorationBackground(
void NGBoxFragmentPainter::PaintBoxDecorationBackgroundWithRect( void NGBoxFragmentPainter::PaintBoxDecorationBackgroundWithRect(
const PaintInfo& paint_info, const PaintInfo& paint_info,
const IntRect& visual_rect,
const PhysicalRect& paint_rect, const PhysicalRect& paint_rect,
const DisplayItemClient& background_client) { const DisplayItemClient& background_client) {
const LayoutBox& layout_box = ToLayoutBox(*box_fragment_.GetLayoutObject()); const LayoutBox& layout_box = ToLayoutBox(*box_fragment_.GetLayoutObject());
...@@ -1004,7 +1009,7 @@ void NGBoxFragmentPainter::PaintBoxDecorationBackgroundWithRect( ...@@ -1004,7 +1009,7 @@ void NGBoxFragmentPainter::PaintBoxDecorationBackgroundWithRect(
return; return;
DrawingRecorder recorder(paint_info.context, background_client, DrawingRecorder recorder(paint_info.context, background_client,
DisplayItem::kBoxDecorationBackground); DisplayItem::kBoxDecorationBackground, visual_rect);
PaintBoxDecorationBackgroundWithRectImpl(paint_info, paint_rect, PaintBoxDecorationBackgroundWithRectImpl(paint_info, paint_rect,
box_decoration_data); box_decoration_data);
...@@ -1133,7 +1138,7 @@ void NGBoxFragmentPainter::PaintColumnRules( ...@@ -1133,7 +1138,7 @@ void NGBoxFragmentPainter::PaintColumnRules(
return; return;
DrawingRecorder recorder(paint_info.context, GetDisplayItemClient(), DrawingRecorder recorder(paint_info.context, GetDisplayItemClient(),
DisplayItem::kColumnRules); DisplayItem::kColumnRules, IntRect());
const Color& rule_color = const Color& rule_color =
LayoutObject::ResolveColor(style, GetCSSPropertyColumnRuleColor()); LayoutObject::ResolveColor(style, GetCSSPropertyColumnRuleColor());
...@@ -1211,6 +1216,7 @@ void NGBoxFragmentPainter::PaintColumnRules( ...@@ -1211,6 +1216,7 @@ void NGBoxFragmentPainter::PaintColumnRules(
snapped_rule.Y(), snapped_rule.MaxX(), snapped_rule.Y(), snapped_rule.MaxX(),
snapped_rule.MaxY(), box_side, rule_color, snapped_rule.MaxY(), box_side, rule_color,
rule_style, 0, 0, true); rule_style, 0, 0, true);
recorder.UniteVisualRect(snapped_rule);
previous_column = current_column; previous_column = current_column;
} }
...@@ -1509,14 +1515,15 @@ void NGBoxFragmentPainter::PaintBackplate(NGInlineCursor* line_boxes, ...@@ -1509,14 +1515,15 @@ void NGBoxFragmentPainter::PaintBackplate(NGInlineCursor* line_boxes,
DisplayItem::kForcedColorsModeBackplate)) DisplayItem::kForcedColorsModeBackplate))
return; return;
DrawingRecorder recorder(paint_info.context, GetDisplayItemClient(),
DisplayItem::kForcedColorsModeBackplate);
Color backplate_color = PhysicalFragment() Color backplate_color = PhysicalFragment()
.GetLayoutObject() .GetLayoutObject()
->GetDocument() ->GetDocument()
.GetStyleEngine() .GetStyleEngine()
.ForcedBackgroundColor(); .ForcedBackgroundColor();
const auto& backplates = BuildBackplate(line_boxes, paint_offset); const auto& backplates = BuildBackplate(line_boxes, paint_offset);
DrawingRecorder recorder(paint_info.context, GetDisplayItemClient(),
DisplayItem::kForcedColorsModeBackplate,
EnclosingIntRect(UnionRect(backplates)));
for (const auto backplate : backplates) for (const auto backplate : backplates)
paint_info.context.FillRect(FloatRect(backplate), backplate_color); paint_info.context.FillRect(FloatRect(backplate), backplate_color);
} }
...@@ -2522,4 +2529,20 @@ bool NGBoxFragmentPainter::HitTestOverflowControl( ...@@ -2522,4 +2529,20 @@ bool NGBoxFragmentPainter::HitTestOverflowControl(
accumulated_offset); accumulated_offset);
} }
IntRect NGBoxFragmentPainter::VisualRect(const PhysicalOffset& paint_offset) {
if (const auto* layout_box =
ToLayoutBoxOrNull(box_fragment_.GetLayoutObject()))
return BoxPainter(*layout_box).VisualRect(paint_offset);
PhysicalRect ink_overflow;
if (paint_fragment_)
ink_overflow = paint_fragment_->InkOverflow();
else if (box_item_)
ink_overflow = box_item_->InkOverflow();
else
NOTREACHED();
ink_overflow.Move(paint_offset);
return EnclosingIntRect(ink_overflow);
}
} // namespace blink } // namespace blink
...@@ -75,6 +75,8 @@ class NGBoxFragmentPainter : public BoxPainterBase { ...@@ -75,6 +75,8 @@ class NGBoxFragmentPainter : public BoxPainterBase {
const PhysicalRect&, const PhysicalRect&,
const BoxDecorationData&); const BoxDecorationData&);
IntRect VisualRect(const PhysicalOffset& paint_offset);
protected: protected:
LayoutRectOutsets ComputeBorders() const override; LayoutRectOutsets ComputeBorders() const override;
LayoutRectOutsets ComputePadding() const override; LayoutRectOutsets ComputePadding() const override;
...@@ -110,8 +112,13 @@ class NGBoxFragmentPainter : public BoxPainterBase { ...@@ -110,8 +112,13 @@ class NGBoxFragmentPainter : public BoxPainterBase {
void PaintBoxDecorationBackground(const PaintInfo&, void PaintBoxDecorationBackground(const PaintInfo&,
const PhysicalOffset& paint_offset, const PhysicalOffset& paint_offset,
bool suppress_box_decoration_background); bool suppress_box_decoration_background);
// |visual_rect| is for the drawing display item, covering overflowing box
// shadows and border image outsets. |paint_rect| is the border box rect in
// paint coordinates.
void PaintBoxDecorationBackgroundWithRect(const PaintInfo&, void PaintBoxDecorationBackgroundWithRect(const PaintInfo&,
const PhysicalRect&, const IntRect& visual_rect,
const PhysicalRect& paint_rect,
const DisplayItemClient&); const DisplayItemClient&);
void PaintColumnRules(const PaintInfo&, const PhysicalOffset& paint_offset); void PaintColumnRules(const PaintInfo&, const PhysicalOffset& paint_offset);
......
...@@ -83,8 +83,9 @@ void NGFieldsetPainter::PaintFieldsetDecorationBackground( ...@@ -83,8 +83,9 @@ void NGFieldsetPainter::PaintFieldsetDecorationBackground(
PhysicalRect contracted_rect(paint_rect); PhysicalRect contracted_rect(paint_rect);
contracted_rect.Contract(fieldset_paint_info.border_outsets); contracted_rect.Contract(fieldset_paint_info.border_outsets);
DrawingRecorder recorder(paint_info.context, *fieldset_.GetLayoutObject(), DrawingRecorder recorder(
paint_info.phase); paint_info.context, *fieldset_.GetLayoutObject(), paint_info.phase,
NGBoxFragmentPainter(fieldset_).VisualRect(paint_offset));
NGBoxFragmentPainter fragment_painter(fieldset_); NGBoxFragmentPainter fragment_painter(fieldset_);
if (box_decoration_data.ShouldPaintShadow()) { if (box_decoration_data.ShouldPaintShadow()) {
......
...@@ -44,10 +44,7 @@ void NGMathMLPainter::PaintStretchyOrLargeOperator( ...@@ -44,10 +44,7 @@ void NGMathMLPainter::PaintStretchyOrLargeOperator(
void NGMathMLPainter::PaintFractionBar( void NGMathMLPainter::PaintFractionBar(
const PaintInfo& info, const PaintInfo& info,
const DisplayItemClient& display_item_client,
PhysicalOffset paint_offset) { PhysicalOffset paint_offset) {
DrawingRecorder recorder(info.context, display_item_client, info.phase);
DCHECK(box_fragment_.Style().IsHorizontalWritingMode()); DCHECK(box_fragment_.Style().IsHorizontalWritingMode());
const ComputedStyle& style = box_fragment_.Style(); const ComputedStyle& style = box_fragment_.Style();
LayoutUnit line_thickness = FractionLineThickness(style); LayoutUnit line_thickness = FractionLineThickness(style);
...@@ -69,7 +66,6 @@ void NGMathMLPainter::PaintFractionBar( ...@@ -69,7 +66,6 @@ void NGMathMLPainter::PaintFractionBar(
void NGMathMLPainter::PaintRadicalSymbol( void NGMathMLPainter::PaintRadicalSymbol(
const PaintInfo& info, const PaintInfo& info,
const DisplayItemClient& display_item_client,
PhysicalOffset paint_offset) { PhysicalOffset paint_offset) {
auto children = box_fragment_.Children(); auto children = box_fragment_.Children();
if (children.size() == 0) if (children.size() == 0)
...@@ -78,8 +74,6 @@ void NGMathMLPainter::PaintRadicalSymbol( ...@@ -78,8 +74,6 @@ void NGMathMLPainter::PaintRadicalSymbol(
const auto& base_child = To<NGPhysicalBoxFragment>(*children[0]); const auto& base_child = To<NGPhysicalBoxFragment>(*children[0]);
const NGMathMLPaintInfo& parameters = box_fragment_.GetMathMLPaintInfo(); const NGMathMLPaintInfo& parameters = box_fragment_.GetMathMLPaintInfo();
DrawingRecorder recorder(info.context, display_item_client, info.phase);
DCHECK(box_fragment_.Style().IsHorizontalWritingMode()); DCHECK(box_fragment_.Style().IsHorizontalWritingMode());
// Paint the vertical symbol. // Paint the vertical symbol.
...@@ -137,15 +131,18 @@ void NGMathMLPainter::Paint(const PaintInfo& info, ...@@ -137,15 +131,18 @@ void NGMathMLPainter::Paint(const PaintInfo& info,
if (DrawingRecorder::UseCachedDrawingIfPossible( if (DrawingRecorder::UseCachedDrawingIfPossible(
info.context, display_item_client, info.phase)) info.context, display_item_client, info.phase))
return; return;
DrawingRecorder recorder(
info.context, display_item_client, info.phase,
NGBoxFragmentPainter(box_fragment_).VisualRect(paint_offset));
// Fraction // Fraction
if (box_fragment_.IsMathMLFraction()) { if (box_fragment_.IsMathMLFraction()) {
PaintFractionBar(info, display_item_client, paint_offset); PaintFractionBar(info, paint_offset);
return; return;
} }
// TODO(rbuis): paint operator // TODO(rbuis): paint operator
PaintRadicalSymbol(info, display_item_client, paint_offset); PaintRadicalSymbol(info, paint_offset);
} }
} // namespace blink } // namespace blink
...@@ -11,7 +11,6 @@ namespace blink { ...@@ -11,7 +11,6 @@ namespace blink {
struct PaintInfo; struct PaintInfo;
struct PhysicalOffset; struct PhysicalOffset;
class DisplayItemClient;
class IntRect; class IntRect;
class NGPhysicalBoxFragment; class NGPhysicalBoxFragment;
...@@ -26,10 +25,8 @@ class NGMathMLPainter { ...@@ -26,10 +25,8 @@ class NGMathMLPainter {
private: private:
void PaintBar(const PaintInfo&, const IntRect&); void PaintBar(const PaintInfo&, const IntRect&);
void PaintFractionBar(const PaintInfo&, void PaintFractionBar(const PaintInfo&,
const DisplayItemClient&,
PhysicalOffset); PhysicalOffset);
void PaintRadicalSymbol(const PaintInfo&, void PaintRadicalSymbol(const PaintInfo&,
const DisplayItemClient&,
PhysicalOffset); PhysicalOffset);
void PaintStretchyOrLargeOperator(const PaintInfo&, PhysicalOffset); void PaintStretchyOrLargeOperator(const PaintInfo&, PhysicalOffset);
......
...@@ -641,15 +641,6 @@ const LayoutObject& NGPaintFragment::VisualRectLayoutObject( ...@@ -641,15 +641,6 @@ const LayoutObject& NGPaintFragment::VisualRectLayoutObject(
return *containing_block_fragment->GetLayoutObject(); return *containing_block_fragment->GetLayoutObject();
} }
IntRect NGPaintFragment::VisualRect() const {
// VisualRect is computed from fragment tree and set to LayoutObject in
// pre-paint. Use the stored value in the LayoutObject.
bool this_as_inline_box;
const auto& layout_object = VisualRectLayoutObject(this_as_inline_box);
DCHECK(!this_as_inline_box);
return layout_object.FragmentsVisualRectBoundingBox();
}
IntRect NGPaintFragment::PartialInvalidationVisualRect() const { IntRect NGPaintFragment::PartialInvalidationVisualRect() const {
bool this_as_inline_box; bool this_as_inline_box;
const auto& layout_object = VisualRectLayoutObject(this_as_inline_box); const auto& layout_object = VisualRectLayoutObject(this_as_inline_box);
......
...@@ -177,8 +177,6 @@ class CORE_EXPORT NGPaintFragment : public RefCounted<NGPaintFragment>, ...@@ -177,8 +177,6 @@ class CORE_EXPORT NGPaintFragment : public RefCounted<NGPaintFragment>,
bool HasOverflowClip() const { return PhysicalFragment().HasOverflowClip(); } bool HasOverflowClip() const { return PhysicalFragment().HasOverflowClip(); }
bool ShouldClipOverflow() const; bool ShouldClipOverflow() const;
bool HasSelfPaintingLayer() const; bool HasSelfPaintingLayer() const;
// This is equivalent to LayoutObject::VisualRect
IntRect VisualRect() const override;
IntRect PartialInvalidationVisualRect() const override; IntRect PartialInvalidationVisualRect() const override;
// Set ShouldDoFullPaintInvalidation flag in the corresponding LayoutObject. // Set ShouldDoFullPaintInvalidation flag in the corresponding LayoutObject.
......
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