Commit e8df1be2 authored by Fredrik Söderqvist's avatar Fredrik Söderqvist Committed by Commit Bot

Clean up redundant PaintInfo's in SVG painters

Since ScopedSVGPaintState has its own "internal" PaintInfo (accessed via
GetPaintInfo()) we don't need to have local PaintInfos in a number of
SVG painters, but can use the one passed in (or one that is actually
being locally mutated like in SVGContainerPainter).

Add a comment in SVGForeignObjectPainter about the seemingly frivolous
PaintInfo usage. Also drop some level of indentation where possible.

Change-Id: I59efc150c666a725d626b1b5ca643d3041d3fe3a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2106167
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751009}
parent 100022ba
......@@ -32,10 +32,8 @@ void SVGContainerPainter::Paint(const PaintInfo& paint_info) {
if (svg_svg_element && svg_svg_element->HasEmptyViewBox())
return;
PaintInfo paint_info_before_filtering(paint_info);
if (SVGModelObjectPainter(layout_svg_container_)
.CullRectSkipsPainting(paint_info_before_filtering)) {
.CullRectSkipsPainting(paint_info)) {
return;
}
......@@ -44,6 +42,7 @@ void SVGContainerPainter::Paint(const PaintInfo& paint_info) {
// 2) Complexity: Difficulty updating clips when ancestor transforms change.
// This is why we use an infinite cull rect if there is a transform. Non-svg
// content, does this in PaintLayerPainter::PaintSingleFragment.
PaintInfo paint_info_before_filtering(paint_info);
if (layout_svg_container_.StyleRef().HasTransform()) {
paint_info_before_filtering.ApplyInfiniteCullRect();
} else if (const auto* properties =
......
......@@ -6,9 +6,7 @@
#include "base/optional.h"
#include "third_party/blink/renderer/core/layout/svg/layout_svg_foreign_object.h"
#include "third_party/blink/renderer/core/layout/svg/svg_layout_support.h"
#include "third_party/blink/renderer/core/paint/block_painter.h"
#include "third_party/blink/renderer/core/paint/object_painter.h"
#include "third_party/blink/renderer/core/paint/paint_info.h"
#include "third_party/blink/renderer/core/paint/paint_layer.h"
#include "third_party/blink/renderer/core/paint/paint_layer_painter.h"
......@@ -51,14 +49,13 @@ void SVGForeignObjectPainter::PaintLayer(const PaintInfo& paint_info) {
}
void SVGForeignObjectPainter::Paint(const PaintInfo& paint_info) {
PaintInfo paint_info_before_filtering(paint_info);
ScopedSVGPaintState paint_state(layout_svg_foreign_object_,
paint_info_before_filtering);
if (paint_state.GetPaintInfo().phase == PaintPhase::kForeground &&
ScopedSVGPaintState paint_state(layout_svg_foreign_object_, paint_info);
// ScopedSVGPaintState only applies masks (and clips-within-clips)
// here and thus does not mutate PaintInfo, so we can use the passed
// in PaintInfo below.
if (paint_info.phase == PaintPhase::kForeground &&
!paint_state.ApplyEffects())
return;
BlockPainter(layout_svg_foreign_object_).Paint(paint_info);
}
......
......@@ -27,20 +27,17 @@ void SVGImagePainter::Paint(const PaintInfo& paint_info) {
!layout_svg_image_.ImageResource()->HasImage())
return;
PaintInfo paint_info_before_filtering(paint_info);
if (SVGModelObjectPainter(layout_svg_image_)
.CullRectSkipsPainting(paint_info_before_filtering)) {
.CullRectSkipsPainting(paint_info)) {
return;
}
// Images cannot have children so do not call TransformCullRect.
ScopedSVGTransformState transform_state(
paint_info_before_filtering, layout_svg_image_,
paint_info, layout_svg_image_,
layout_svg_image_.LocalToSVGParentTransform());
{
ScopedSVGPaintState paint_state(layout_svg_image_,
paint_info_before_filtering);
ScopedSVGPaintState paint_state(layout_svg_image_, paint_info);
if (paint_state.ApplyEffects() &&
!DrawingRecorder::UseCachedDrawingIfPossible(
paint_state.GetPaintInfo().context, layout_svg_image_,
......@@ -53,8 +50,7 @@ void SVGImagePainter::Paint(const PaintInfo& paint_info) {
}
}
SVGModelObjectPainter(layout_svg_image_)
.PaintOutline(paint_info_before_filtering);
SVGModelObjectPainter(layout_svg_image_).PaintOutline(paint_info);
}
void SVGImagePainter::PaintForeground(const PaintInfo& paint_info) {
......
......@@ -18,15 +18,15 @@ void SVGInlineFlowBoxPainter::PaintSelectionBackground(
DCHECK(paint_info.phase == PaintPhase::kForeground ||
paint_info.phase == PaintPhase::kSelection);
PaintInfo child_paint_info(paint_info);
for (InlineBox* child = svg_inline_flow_box_.FirstChild(); child;
child = child->NextOnLine()) {
if (auto* svg_inline_text_box = DynamicTo<SVGInlineTextBox>(child))
if (auto* svg_inline_text_box = DynamicTo<SVGInlineTextBox>(child)) {
SVGInlineTextBoxPainter(*svg_inline_text_box)
.PaintSelectionBackground(child_paint_info);
else if (auto* svg_inline_flow_box = DynamicTo<SVGInlineFlowBox>(child))
.PaintSelectionBackground(paint_info);
} else if (auto* svg_inline_flow_box = DynamicTo<SVGInlineFlowBox>(child)) {
SVGInlineFlowBoxPainter(*svg_inline_flow_box)
.PaintSelectionBackground(child_paint_info);
.PaintSelectionBackground(paint_info);
}
}
}
......@@ -38,11 +38,12 @@ void SVGInlineFlowBoxPainter::Paint(const PaintInfo& paint_info,
ScopedSVGPaintState paint_state(*LineLayoutAPIShim::ConstLayoutObjectFrom(
svg_inline_flow_box_.GetLineLayoutItem()),
paint_info, svg_inline_flow_box_);
if (paint_state.ApplyEffects()) {
for (InlineBox* child = svg_inline_flow_box_.FirstChild(); child;
child = child->NextOnLine())
child->Paint(paint_state.GetPaintInfo(), paint_offset, LayoutUnit(),
LayoutUnit());
if (!paint_state.ApplyEffects())
return;
for (InlineBox* child = svg_inline_flow_box_.FirstChild(); child;
child = child->NextOnLine()) {
child->Paint(paint_state.GetPaintInfo(), paint_offset, LayoutUnit(),
LayoutUnit());
}
}
......
......@@ -24,35 +24,37 @@ void SVGRootInlineBoxPainter::Paint(const PaintInfo& paint_info,
bool has_selection =
!paint_info.IsPrinting() && svg_root_inline_box_.IsSelected();
PaintInfo paint_info_before_filtering(paint_info);
if (has_selection && !DrawingRecorder::UseCachedDrawingIfPossible(
paint_info_before_filtering.context,
paint_info.context,
*LineLayoutAPIShim::ConstLayoutObjectFrom(
svg_root_inline_box_.GetLineLayoutItem()),
paint_info_before_filtering.phase)) {
DrawingRecorder recorder(paint_info_before_filtering.context,
paint_info.phase)) {
DrawingRecorder recorder(paint_info.context,
*LineLayoutAPIShim::ConstLayoutObjectFrom(
svg_root_inline_box_.GetLineLayoutItem()),
paint_info_before_filtering.phase);
paint_info.phase);
for (InlineBox* child = svg_root_inline_box_.FirstChild(); child;
child = child->NextOnLine()) {
if (auto* svg_inline_text_box = DynamicTo<SVGInlineTextBox>(child))
if (auto* svg_inline_text_box = DynamicTo<SVGInlineTextBox>(child)) {
SVGInlineTextBoxPainter(*svg_inline_text_box)
.PaintSelectionBackground(paint_info_before_filtering);
else if (auto* svg_inline_flow_box = DynamicTo<SVGInlineFlowBox>(child))
.PaintSelectionBackground(paint_info);
} else if (auto* svg_inline_flow_box =
DynamicTo<SVGInlineFlowBox>(child)) {
SVGInlineFlowBoxPainter(*svg_inline_flow_box)
.PaintSelectionBackground(paint_info_before_filtering);
.PaintSelectionBackground(paint_info);
}
}
}
ScopedSVGPaintState paint_state(*LineLayoutAPIShim::ConstLayoutObjectFrom(
svg_root_inline_box_.GetLineLayoutItem()),
paint_info_before_filtering);
if (paint_state.ApplyEffects()) {
for (InlineBox* child = svg_root_inline_box_.FirstChild(); child;
child = child->NextOnLine())
child->Paint(paint_state.GetPaintInfo(), paint_offset, LayoutUnit(),
LayoutUnit());
paint_info);
if (!paint_state.ApplyEffects())
return;
for (InlineBox* child = svg_root_inline_box_.FirstChild(); child;
child = child->NextOnLine()) {
child->Paint(paint_state.GetPaintInfo(), paint_offset, LayoutUnit(),
LayoutUnit());
}
}
......
......@@ -47,20 +47,16 @@ void SVGShapePainter::Paint(const PaintInfo& paint_info) {
layout_svg_shape_.IsShapeEmpty())
return;
PaintInfo paint_info_before_filtering(paint_info);
if (SVGModelObjectPainter(layout_svg_shape_)
.CullRectSkipsPainting(paint_info_before_filtering)) {
.CullRectSkipsPainting(paint_info)) {
return;
}
// Shapes cannot have children so do not call TransformCullRect.
ScopedSVGTransformState transform_state(
paint_info_before_filtering, layout_svg_shape_,
layout_svg_shape_.LocalSVGTransform());
paint_info, layout_svg_shape_, layout_svg_shape_.LocalSVGTransform());
{
ScopedSVGPaintState paint_state(layout_svg_shape_,
paint_info_before_filtering);
ScopedSVGPaintState paint_state(layout_svg_shape_, paint_info);
if (paint_state.ApplyEffects() &&
!DrawingRecorder::UseCachedDrawingIfPossible(
paint_state.GetPaintInfo().context, layout_svg_shape_,
......@@ -139,8 +135,7 @@ void SVGShapePainter::Paint(const PaintInfo& paint_info) {
}
}
SVGModelObjectPainter(layout_svg_shape_)
.PaintOutline(paint_info_before_filtering);
SVGModelObjectPainter(layout_svg_shape_).PaintOutline(paint_info);
}
class PathWithTemporaryWindingRule {
......
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