Commit 407a0120 authored by Xianzhu Wang's avatar Xianzhu Wang Committed by Commit Bot

[CI] Refactor CullRect preparing for SPv2 interest rect implementation

- Combine CullRect::UpdateCullRect() and
  CullRect::UpdateCullRectForScrollingContents() into
  CullRect::ApplyTransform() which accepts a TransformPaintPropertyNode.
  For SPv2, if the transform node has scroll node, we'll expand the cull
  rect for composited scrolling.

- Rename CullRect::IntersectsCullRect() to CullRect::Intersects()

- Change CullRect constructor with offset to mutation methods to keep
  consistent with ApplyTransform().

Bug: 792577
Change-Id: I306f5c7acacf73d97100c6c863b71e0df41c34af
Reviewed-on: https://chromium-review.googlesource.com/c/1319650Reviewed-by: default avatarChris Harrelson <chrishtr@chromium.org>
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607495}
parent 55bd5742
...@@ -168,7 +168,7 @@ void WebPluginContainerImpl::Paint(GraphicsContext& context, ...@@ -168,7 +168,7 @@ void WebPluginContainerImpl::Paint(GraphicsContext& context,
const CullRect& cull_rect, const CullRect& cull_rect,
const IntSize& paint_offset) const { const IntSize& paint_offset) const {
// Don't paint anything if the plugin doesn't intersect. // Don't paint anything if the plugin doesn't intersect.
if (!cull_rect.IntersectsCullRect(FrameRect())) if (!cull_rect.Intersects(FrameRect()))
return; return;
if (RuntimeEnabledFeatures::SlimmingPaintV2Enabled() && layer_) { if (RuntimeEnabledFeatures::SlimmingPaintV2Enabled() && layer_) {
......
...@@ -258,7 +258,7 @@ void RemoteFrameView::Paint(GraphicsContext& context, ...@@ -258,7 +258,7 @@ void RemoteFrameView::Paint(GraphicsContext& context,
if (!context.Printing()) if (!context.Printing())
return; return;
if (!rect.IntersectsCullRect(FrameRect())) if (!rect.Intersects(FrameRect()))
return; return;
DrawingRecorder recorder(context, *GetFrame().OwnerLayoutObject(), DrawingRecorder recorder(context, *GetFrame().OwnerLayoutObject(),
......
...@@ -3438,8 +3438,8 @@ void CompositedLayerMapping::PaintScrollableArea( ...@@ -3438,8 +3438,8 @@ void CompositedLayerMapping::PaintScrollableArea(
const IntRect& interest_rect) const { const IntRect& interest_rect) const {
// cull_rect is in the space of the containing scrollable area in which // cull_rect is in the space of the containing scrollable area in which
// Scrollbar::Paint() will paint the scrollbar. // Scrollbar::Paint() will paint the scrollbar.
CullRect cull_rect(CullRect(interest_rect), CullRect cull_rect(interest_rect);
graphics_layer->OffsetFromLayoutObject()); cull_rect.Move(graphics_layer->OffsetFromLayoutObject());
PaintLayerScrollableArea* scrollable_area = owning_layer_.GetScrollableArea(); PaintLayerScrollableArea* scrollable_area = owning_layer_.GetScrollableArea();
if (graphics_layer == LayerForHorizontalScrollbar()) { if (graphics_layer == LayerForHorizontalScrollbar()) {
if (const Scrollbar* scrollbar = scrollable_area->HorizontalScrollbar()) if (const Scrollbar* scrollbar = scrollable_area->HorizontalScrollbar())
......
...@@ -32,7 +32,8 @@ void EmbeddedContentPainter::PaintReplaced(const PaintInfo& paint_info, ...@@ -32,7 +32,8 @@ void EmbeddedContentPainter::PaintReplaced(const PaintInfo& paint_info,
IntSize view_paint_offset = IntSize view_paint_offset =
paint_location - embedded_content_view->FrameRect().Location(); paint_location - embedded_content_view->FrameRect().Location();
CullRect adjusted_cull_rect(paint_info.GetCullRect(), -view_paint_offset); CullRect adjusted_cull_rect = paint_info.GetCullRect();
adjusted_cull_rect.Move(-view_paint_offset);
embedded_content_view->Paint(paint_info.context, embedded_content_view->Paint(paint_info.context,
paint_info.GetGlobalPaintFlags(), paint_info.GetGlobalPaintFlags(),
adjusted_cull_rect, view_paint_offset); adjusted_cull_rect, view_paint_offset);
......
...@@ -26,7 +26,7 @@ static Color BorderFillColor() { ...@@ -26,7 +26,7 @@ static Color BorderFillColor() {
void FrameSetPainter::PaintColumnBorder(const PaintInfo& paint_info, void FrameSetPainter::PaintColumnBorder(const PaintInfo& paint_info,
const IntRect& border_rect) { const IntRect& border_rect) {
if (!paint_info.GetCullRect().IntersectsCullRect(border_rect)) if (!paint_info.GetCullRect().Intersects(border_rect))
return; return;
// FIXME: We should do something clever when borders from distinct framesets // FIXME: We should do something clever when borders from distinct framesets
......
...@@ -57,7 +57,7 @@ void InlineFlowBoxPainter::Paint(const PaintInfo& paint_info, ...@@ -57,7 +57,7 @@ void InlineFlowBoxPainter::Paint(const PaintInfo& paint_info,
inline_flow_box_.FlipForWritingMode(overflow_rect); inline_flow_box_.FlipForWritingMode(overflow_rect);
overflow_rect.MoveBy(paint_offset); overflow_rect.MoveBy(paint_offset);
if (!paint_info.GetCullRect().IntersectsCullRect(overflow_rect)) if (!paint_info.GetCullRect().Intersects(overflow_rect))
return; return;
if (paint_info.phase == PaintPhase::kMask) { if (paint_info.phase == PaintPhase::kMask) {
......
...@@ -320,7 +320,7 @@ void NGBoxFragmentPainter::PaintBlockFlowContents( ...@@ -320,7 +320,7 @@ void NGBoxFragmentPainter::PaintBlockFlowContents(
LayoutRect overflow_rect(box_fragment_.ChildrenInkOverflow()); LayoutRect overflow_rect(box_fragment_.ChildrenInkOverflow());
overflow_rect.MoveBy(paint_offset); overflow_rect.MoveBy(paint_offset);
if (!paint_info.GetCullRect().IntersectsCullRect(overflow_rect)) if (!paint_info.GetCullRect().Intersects(overflow_rect))
return; return;
if (paint_info.phase == PaintPhase::kMask) { if (paint_info.phase == PaintPhase::kMask) {
......
...@@ -149,15 +149,8 @@ struct CORE_EXPORT PaintInfo { ...@@ -149,15 +149,8 @@ struct CORE_EXPORT PaintInfo {
cull_rect_ = CullRect(LayoutRect::InfiniteIntRect()); cull_rect_ = CullRect(LayoutRect::InfiniteIntRect());
} }
void UpdateCullRect(const AffineTransform& local_to_parent_transform) { void TransformCullRect(const TransformPaintPropertyNode* transform) {
cull_rect_.UpdateCullRect(local_to_parent_transform); cull_rect_.ApplyTransform(transform);
}
void UpdateCullRectForScrollingContents(
const IntRect& overflow_clip_rect,
const AffineTransform& local_to_parent_transform) {
cull_rect_.UpdateForScrollingContents(overflow_clip_rect,
local_to_parent_transform);
} }
// Returns the fragment of the current painting object matching the current // Returns the fragment of the current painting object matching the current
...@@ -208,10 +201,6 @@ struct CORE_EXPORT PaintInfo { ...@@ -208,10 +201,6 @@ struct CORE_EXPORT PaintInfo {
// For SPv2 only. // For SPv2 only.
bool is_painting_scrolling_background_; bool is_painting_scrolling_background_;
// TODO(chrishtr): temporary while we implement CullRect everywhere.
friend class ScopedSVGPaintState;
friend class SVGShapePainter;
}; };
Image::ImageDecodingMode GetImageDecodingMode(Node*); Image::ImageDecodingMode GetImageDecodingMode(Node*);
......
...@@ -52,9 +52,7 @@ ScopedReplacedContentPaintState::ScopedReplacedContentPaintState( ...@@ -52,9 +52,7 @@ ScopedReplacedContentPaintState::ScopedReplacedContentPaintState(
if (content_transform && replaced.IsSVGRoot()) { if (content_transform && replaced.IsSVGRoot()) {
new_properties.SetTransform(content_transform); new_properties.SetTransform(content_transform);
adjusted_paint_info_.emplace(input_paint_info_); adjusted_paint_info_.emplace(input_paint_info_);
DCHECK(content_transform->Matrix().IsAffine()); adjusted_paint_info_->TransformCullRect(content_transform);
adjusted_paint_info_->UpdateCullRect(
content_transform->Matrix().ToAffineTransform());
property_changed = true; property_changed = true;
} }
......
...@@ -32,9 +32,7 @@ void ScopedPaintState::AdjustForPaintOffsetTranslation( ...@@ -32,9 +32,7 @@ void ScopedPaintState::AdjustForPaintOffsetTranslation(
} }
adjusted_paint_info_.emplace(input_paint_info_); adjusted_paint_info_.emplace(input_paint_info_);
DCHECK(paint_offset_translation->Matrix().IsAffine()); adjusted_paint_info_->TransformCullRect(paint_offset_translation);
adjusted_paint_info_->UpdateCullRect(
paint_offset_translation->Matrix().ToAffineTransform());
} }
void ScopedPaintState::FinishPaintOffsetTranslationAsDrawing() { void ScopedPaintState::FinishPaintOffsetTranslationAsDrawing() {
...@@ -72,15 +70,7 @@ void ScopedBoxContentsPaintState::AdjustForBoxContents(const LayoutBox& box) { ...@@ -72,15 +70,7 @@ void ScopedBoxContentsPaintState::AdjustForBoxContents(const LayoutBox& box) {
paint_offset_ += box.ScrollOrigin(); paint_offset_ += box.ScrollOrigin();
adjusted_paint_info_.emplace(input_paint_info_); adjusted_paint_info_.emplace(input_paint_info_);
DCHECK(scroll_translation->Matrix().IsAffine()); adjusted_paint_info_->TransformCullRect(scroll_translation);
if (RuntimeEnabledFeatures::SlimmingPaintV2Enabled()) {
adjusted_paint_info_->UpdateCullRectForScrollingContents(
EnclosingIntRect(box.OverflowClipRect(paint_offset_)),
scroll_translation->Matrix().ToAffineTransform());
} else {
adjusted_paint_info_->UpdateCullRect(
scroll_translation->Matrix().ToAffineTransform());
}
} }
} // namespace blink } // namespace blink
...@@ -86,8 +86,7 @@ class ScopedPaintState { ...@@ -86,8 +86,7 @@ class ScopedPaintState {
bool LocalRectIntersectsCullRect(const LayoutRect& local_rect) const { bool LocalRectIntersectsCullRect(const LayoutRect& local_rect) const {
LayoutRect rect_in_paint_info_space = local_rect; LayoutRect rect_in_paint_info_space = local_rect;
rect_in_paint_info_space.MoveBy(PaintOffset()); rect_in_paint_info_space.MoveBy(PaintOffset());
return GetPaintInfo().GetCullRect().IntersectsCullRect( return GetPaintInfo().GetCullRect().Intersects(rect_in_paint_info_space);
rect_in_paint_info_space);
} }
protected: protected:
......
...@@ -177,7 +177,7 @@ bool ScopedSVGPaintState::ApplyFilterIfNecessary(SVGResources* resources) { ...@@ -177,7 +177,7 @@ bool ScopedSVGPaintState::ApplyFilterIfNecessary(SVGResources* resources) {
// Because we cache the filter contents and do not invalidate on paint // Because we cache the filter contents and do not invalidate on paint
// invalidation rect changes, we need to paint the entire filter region // invalidation rect changes, we need to paint the entire filter region
// so elements outside the initial paint (due to scrolling, etc) paint. // so elements outside the initial paint (due to scrolling, etc) paint.
filter_paint_info_->cull_rect_ = CullRect(LayoutRect::InfiniteIntRect()); filter_paint_info_->ApplyInfiniteCullRect();
return true; return true;
} }
......
...@@ -36,7 +36,7 @@ void ScrollableAreaPainter::PaintResizer(GraphicsContext& context, ...@@ -36,7 +36,7 @@ void ScrollableAreaPainter::PaintResizer(GraphicsContext& context,
abs_rect.MoveBy(paint_offset); abs_rect.MoveBy(paint_offset);
if (const auto* resizer = GetScrollableArea().Resizer()) { if (const auto* resizer = GetScrollableArea().Resizer()) {
if (!cull_rect.IntersectsCullRect(abs_rect)) if (!cull_rect.Intersects(abs_rect))
return; return;
ScrollbarPainter::PaintIntoRect(*resizer, context, paint_offset, ScrollbarPainter::PaintIntoRect(*resizer, context, paint_offset,
LayoutRect(abs_rect)); LayoutRect(abs_rect));
...@@ -133,7 +133,8 @@ void ScrollableAreaPainter::PaintOverflowControls( ...@@ -133,7 +133,8 @@ void ScrollableAreaPainter::PaintOverflowControls(
if (painting_overlay_controls) if (painting_overlay_controls)
adjusted_paint_offset = GetScrollableArea().CachedOverlayScrollbarOffset(); adjusted_paint_offset = GetScrollableArea().CachedOverlayScrollbarOffset();
CullRect adjusted_cull_rect(paint_info.GetCullRect(), -adjusted_paint_offset); CullRect adjusted_cull_rect = paint_info.GetCullRect();
adjusted_cull_rect.MoveBy(-adjusted_paint_offset);
// Overlay scrollbars paint in a second pass through the layer tree so that // Overlay scrollbars paint in a second pass through the layer tree so that
// they will paint on top of everything else. If this is the normal painting // they will paint on top of everything else. If this is the normal painting
// pass, paintingOverlayControls will be false, and we should just tell the // pass, paintingOverlayControls will be false, and we should just tell the
...@@ -214,18 +215,18 @@ bool ScrollableAreaPainter::OverflowControlsIntersectRect( ...@@ -214,18 +215,18 @@ bool ScrollableAreaPainter::OverflowControlsIntersectRect(
GetScrollableArea().GetLayoutBox()->PixelSnappedBorderBoxRect( GetScrollableArea().GetLayoutBox()->PixelSnappedBorderBoxRect(
GetScrollableArea().Layer()->SubpixelAccumulation()); GetScrollableArea().Layer()->SubpixelAccumulation());
if (cull_rect.IntersectsCullRect( if (cull_rect.Intersects(
GetScrollableArea().RectForHorizontalScrollbar(border_box))) GetScrollableArea().RectForHorizontalScrollbar(border_box)))
return true; return true;
if (cull_rect.IntersectsCullRect( if (cull_rect.Intersects(
GetScrollableArea().RectForVerticalScrollbar(border_box))) GetScrollableArea().RectForVerticalScrollbar(border_box)))
return true; return true;
if (cull_rect.IntersectsCullRect(GetScrollableArea().ScrollCornerRect())) if (cull_rect.Intersects(GetScrollableArea().ScrollCornerRect()))
return true; return true;
if (cull_rect.IntersectsCullRect(GetScrollableArea().ResizerCornerRect( if (cull_rect.Intersects(GetScrollableArea().ResizerCornerRect(
border_box, kResizerForPointer))) border_box, kResizerForPointer)))
return true; return true;
...@@ -242,7 +243,7 @@ void ScrollableAreaPainter::PaintScrollCorner( ...@@ -242,7 +243,7 @@ void ScrollableAreaPainter::PaintScrollCorner(
abs_rect.MoveBy(paint_offset); abs_rect.MoveBy(paint_offset);
if (const auto* scroll_corner = GetScrollableArea().ScrollCorner()) { if (const auto* scroll_corner = GetScrollableArea().ScrollCorner()) {
if (!adjusted_cull_rect.IntersectsCullRect(abs_rect)) if (!adjusted_cull_rect.Intersects(abs_rect))
return; return;
ScrollbarPainter::PaintIntoRect(*scroll_corner, context, paint_offset, ScrollbarPainter::PaintIntoRect(*scroll_corner, context, paint_offset,
LayoutRect(abs_rect)); LayoutRect(abs_rect));
......
...@@ -45,9 +45,10 @@ void SVGContainerPainter::Paint(const PaintInfo& paint_info) { ...@@ -45,9 +45,10 @@ void SVGContainerPainter::Paint(const PaintInfo& paint_info) {
// content, does this in PaintLayerPainter::PaintSingleFragment. // content, does this in PaintLayerPainter::PaintSingleFragment.
if (layout_svg_container_.StyleRef().HasTransform()) { if (layout_svg_container_.StyleRef().HasTransform()) {
paint_info_before_filtering.ApplyInfiniteCullRect(); paint_info_before_filtering.ApplyInfiniteCullRect();
} else { } else if (const auto* properties =
paint_info_before_filtering.UpdateCullRect( layout_svg_container_.FirstFragment().PaintProperties()) {
layout_svg_container_.LocalToSVGParentTransform()); if (const auto* transform = properties->Transform())
paint_info_before_filtering.TransformCullRect(transform);
} }
ScopedSVGTransformState transform_state( ScopedSVGTransformState transform_state(
......
...@@ -29,7 +29,7 @@ void SVGImagePainter::Paint(const PaintInfo& paint_info) { ...@@ -29,7 +29,7 @@ void SVGImagePainter::Paint(const PaintInfo& paint_info) {
.CullRectSkipsPainting(paint_info_before_filtering)) { .CullRectSkipsPainting(paint_info_before_filtering)) {
return; return;
} }
// Images cannot have children so do not call UpdateCullRect. // Images cannot have children so do not call TransformCullRect.
ScopedSVGTransformState transform_state( ScopedSVGTransformState transform_state(
paint_info_before_filtering, layout_svg_image_, paint_info_before_filtering, layout_svg_image_,
......
...@@ -24,7 +24,7 @@ bool SVGModelObjectPainter::CullRectSkipsPainting(const PaintInfo& paint_info) { ...@@ -24,7 +24,7 @@ bool SVGModelObjectPainter::CullRectSkipsPainting(const PaintInfo& paint_info) {
if (layout_svg_model_object_.IsSVGHiddenContainer()) if (layout_svg_model_object_.IsSVGHiddenContainer())
return false; return false;
return !paint_info.GetCullRect().IntersectsCullRect( return !paint_info.GetCullRect().IntersectsTransformed(
layout_svg_model_object_.LocalToSVGParentTransform(), layout_svg_model_object_.LocalToSVGParentTransform(),
layout_svg_model_object_.VisualRectInLocalSVGCoordinates()); layout_svg_model_object_.VisualRectInLocalSVGCoordinates());
} }
......
...@@ -53,7 +53,7 @@ void SVGShapePainter::Paint(const PaintInfo& paint_info) { ...@@ -53,7 +53,7 @@ void SVGShapePainter::Paint(const PaintInfo& paint_info) {
.CullRectSkipsPainting(paint_info_before_filtering)) { .CullRectSkipsPainting(paint_info_before_filtering)) {
return; return;
} }
// Shapes cannot have children so do not call UpdateCullRect. // Shapes cannot have children so do not call TransformCullRect.
ScopedSVGTransformState transform_state( ScopedSVGTransformState transform_state(
paint_info_before_filtering, layout_svg_shape_, paint_info_before_filtering, layout_svg_shape_,
...@@ -249,7 +249,7 @@ void SVGShapePainter::PaintMarker(const PaintInfo& paint_info, ...@@ -249,7 +249,7 @@ void SVGShapePainter::PaintMarker(const PaintInfo& paint_info,
// It's expensive to track the transformed paint cull rect for each // It's expensive to track the transformed paint cull rect for each
// marker so just disable culling. The shape paint call will already // marker so just disable culling. The shape paint call will already
// be culled if it is outside the paint info cull rect. // be culled if it is outside the paint info cull rect.
marker_paint_info.cull_rect_ = CullRect(LayoutRect::InfiniteIntRect()); marker_paint_info.ApplyInfiniteCullRect();
SVGContainerPainter(marker).Paint(marker_paint_info); SVGContainerPainter(marker).Paint(marker_paint_info);
builder.EndRecording(*canvas); builder.EndRecording(*canvas);
......
...@@ -18,7 +18,11 @@ void SVGTextPainter::Paint(const PaintInfo& paint_info) { ...@@ -18,7 +18,11 @@ void SVGTextPainter::Paint(const PaintInfo& paint_info) {
return; return;
PaintInfo block_info(paint_info); PaintInfo block_info(paint_info);
block_info.UpdateCullRect(layout_svg_text_.LocalToSVGParentTransform()); if (const auto* properties =
layout_svg_text_.FirstFragment().PaintProperties()) {
if (const auto* transform = properties->Transform())
block_info.TransformCullRect(transform);
}
ScopedSVGTransformState transform_state( ScopedSVGTransformState transform_state(
block_info, layout_svg_text_, block_info, layout_svg_text_,
layout_svg_text_.LocalToSVGParentTransform()); layout_svg_text_.LocalToSVGParentTransform());
......
...@@ -162,7 +162,7 @@ void Scrollbar::SetProportion(int visible_size, int total_size) { ...@@ -162,7 +162,7 @@ void Scrollbar::SetProportion(int visible_size, int total_size) {
void Scrollbar::Paint(GraphicsContext& context, void Scrollbar::Paint(GraphicsContext& context,
const CullRect& cull_rect) const { const CullRect& cull_rect) const {
if (!cull_rect.IntersectsCullRect(FrameRect())) if (!cull_rect.Intersects(FrameRect()))
return; return;
GetTheme().Paint(*this, context, cull_rect); GetTheme().Paint(*this, context, cull_rect);
......
...@@ -53,7 +53,7 @@ bool ScrollbarTheme::g_mock_scrollbars_enabled_ = false; ...@@ -53,7 +53,7 @@ bool ScrollbarTheme::g_mock_scrollbars_enabled_ = false;
static inline bool ShouldPaintScrollbarPart(const IntRect& part_rect, static inline bool ShouldPaintScrollbarPart(const IntRect& part_rect,
const CullRect& cull_rect) { const CullRect& cull_rect) {
return (!part_rect.IsEmpty()) || cull_rect.IntersectsCullRect(part_rect); return (!part_rect.IsEmpty()) || cull_rect.Intersects(part_rect);
} }
bool ScrollbarTheme::Paint(const Scrollbar& scrollbar, bool ScrollbarTheme::Paint(const Scrollbar& scrollbar,
......
...@@ -6,31 +6,24 @@ ...@@ -6,31 +6,24 @@
#include "third_party/blink/renderer/platform/geometry/float_rect.h" #include "third_party/blink/renderer/platform/geometry/float_rect.h"
#include "third_party/blink/renderer/platform/geometry/layout_rect.h" #include "third_party/blink/renderer/platform/geometry/layout_rect.h"
#include "third_party/blink/renderer/platform/graphics/paint/scroll_paint_property_node.h"
#include "third_party/blink/renderer/platform/graphics/paint/transform_paint_property_node.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h" #include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/transforms/affine_transform.h"
namespace blink { namespace blink {
CullRect::CullRect(const CullRect& cull_rect, const IntPoint& offset) { bool CullRect::Intersects(const IntRect& rect) const {
rect_ = cull_rect.rect_; return rect.Intersects(rect_);
rect_.MoveBy(offset);
} }
CullRect::CullRect(const CullRect& cull_rect, const IntSize& offset) { bool CullRect::Intersects(const LayoutRect& rect) const {
rect_ = cull_rect.rect_; return rect_.Intersects(EnclosingIntRect(rect));
rect_.Move(offset);
} }
bool CullRect::IntersectsCullRect(const IntRect& bounding_box) const { bool CullRect::IntersectsTransformed(const AffineTransform& transform,
return bounding_box.Intersects(rect_); const FloatRect& rect) const {
} return transform.MapRect(rect).Intersects(rect_);
bool CullRect::IntersectsCullRect(const AffineTransform& transform,
const FloatRect& bounding_box) const {
return transform.MapRect(bounding_box).Intersects(rect_);
}
bool CullRect::IntersectsCullRect(const LayoutRect& rect_arg) const {
return rect_.Intersects(EnclosingIntRect(rect_arg));
} }
bool CullRect::IntersectsHorizontalRange(LayoutUnit lo, LayoutUnit hi) const { bool CullRect::IntersectsHorizontalRange(LayoutUnit lo, LayoutUnit hi) const {
...@@ -41,23 +34,33 @@ bool CullRect::IntersectsVerticalRange(LayoutUnit lo, LayoutUnit hi) const { ...@@ -41,23 +34,33 @@ bool CullRect::IntersectsVerticalRange(LayoutUnit lo, LayoutUnit hi) const {
return !(lo >= rect_.MaxY() || hi <= rect_.Y()); return !(lo >= rect_.MaxY() || hi <= rect_.Y());
} }
void CullRect::UpdateCullRect( void CullRect::MoveBy(const IntPoint& offset) {
const AffineTransform& local_to_parent_transform) {
if (rect_ != LayoutRect::InfiniteIntRect()) if (rect_ != LayoutRect::InfiniteIntRect())
rect_ = local_to_parent_transform.Inverse().MapRect(rect_); rect_.MoveBy(offset);
} }
void CullRect::UpdateForScrollingContents( void CullRect::Move(const IntSize& offset) {
const IntRect& overflow_clip_rect, if (rect_ != LayoutRect::InfiniteIntRect())
const AffineTransform& local_to_parent_transform) { rect_.Move(offset);
DCHECK(RuntimeEnabledFeatures::SlimmingPaintV2Enabled()); }
rect_.Intersect(overflow_clip_rect);
UpdateCullRect(local_to_parent_transform); void CullRect::ApplyTransform(const TransformPaintPropertyNode* transform) {
if (RuntimeEnabledFeatures::SlimmingPaintV2Enabled()) {
if (const auto* scroll = transform->ScrollNode()) {
rect_.Intersect(scroll->ContainerRect());
rect_ = transform->Matrix().Inverse().MapRect(rect_);
// TODO(wangxianzhu, chrishtr): How about non-composited scrolling contents? // Expand the cull rect for scrolling contents in case of
// The distance to expand the cull rect for scrolling contents. // composited scrolling.
static const int kPixelDistanceToExpand = 4000; // TODO(wangxianzhu): Implement more sophisticated interst rect expansion.
rect_.Inflate(kPixelDistanceToExpand); static const int kPixelDistanceToExpand = 4000;
rect_.Inflate(kPixelDistanceToExpand);
return;
}
}
if (rect_ != LayoutRect::InfiniteIntRect())
rect_ = transform->Matrix().Inverse().MapRect(rect_);
} }
} // namespace blink } // namespace blink
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_PAINT_CULL_RECT_H_ #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_PAINT_CULL_RECT_H_
#include "third_party/blink/renderer/platform/geometry/int_rect.h" #include "third_party/blink/renderer/platform/geometry/int_rect.h"
#include "third_party/blink/renderer/platform/transforms/affine_transform.h"
#include "third_party/blink/renderer/platform/wtf/allocator.h" #include "third_party/blink/renderer/platform/wtf/allocator.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
...@@ -14,9 +13,11 @@ ...@@ -14,9 +13,11 @@
namespace blink { namespace blink {
class AffineTransform;
class FloatRect; class FloatRect;
class LayoutRect; class LayoutRect;
class LayoutUnit; class LayoutUnit;
class TransformPaintPropertyNode;
class PLATFORM_EXPORT CullRect { class PLATFORM_EXPORT CullRect {
DISALLOW_NEW(); DISALLOW_NEW();
...@@ -24,22 +25,16 @@ class PLATFORM_EXPORT CullRect { ...@@ -24,22 +25,16 @@ class PLATFORM_EXPORT CullRect {
public: public:
CullRect() = default; CullRect() = default;
explicit CullRect(const IntRect& rect) : rect_(rect) {} explicit CullRect(const IntRect& rect) : rect_(rect) {}
CullRect(const CullRect&, const IntPoint& offset);
CullRect(const CullRect&, const IntSize& offset);
bool IntersectsCullRect(const AffineTransform&, bool Intersects(const IntRect&) const;
const FloatRect& bounding_box) const; bool Intersects(const LayoutRect&) const;
bool IntersectsCullRect(const IntRect&) const; bool IntersectsTransformed(const AffineTransform&, const FloatRect&) const;
bool IntersectsCullRect(const LayoutRect&) const;
bool IntersectsHorizontalRange(LayoutUnit lo, LayoutUnit hi) const; bool IntersectsHorizontalRange(LayoutUnit lo, LayoutUnit hi) const;
bool IntersectsVerticalRange(LayoutUnit lo, LayoutUnit hi) const; bool IntersectsVerticalRange(LayoutUnit lo, LayoutUnit hi) const;
void UpdateCullRect(const AffineTransform& local_to_parent_transform); void MoveBy(const IntPoint& offset);
void Move(const IntSize& offset);
// |overflow_clip_rect| should be in the same coordinate space as |rect_|. void ApplyTransform(const TransformPaintPropertyNode*);
void UpdateForScrollingContents(
const IntRect& overflow_clip_rect,
const AffineTransform& local_to_parent_transform);
const IntRect& Rect() const { return rect_; } const IntRect& Rect() const { return rect_; }
...@@ -49,10 +44,6 @@ class PLATFORM_EXPORT CullRect { ...@@ -49,10 +44,6 @@ class PLATFORM_EXPORT CullRect {
IntRect rect_; IntRect rect_;
friend bool operator==(const CullRect&, const CullRect&); friend bool operator==(const CullRect&, const CullRect&);
friend class CullRectTest;
friend class TableSectionPainter;
}; };
inline bool operator==(const CullRect& a, const CullRect& b) { inline bool operator==(const CullRect& a, const CullRect& b) {
......
...@@ -7,46 +7,64 @@ ...@@ -7,46 +7,64 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/platform/geometry/float_rect.h" #include "third_party/blink/renderer/platform/geometry/float_rect.h"
#include "third_party/blink/renderer/platform/geometry/layout_rect.h" #include "third_party/blink/renderer/platform/geometry/layout_rect.h"
#include "third_party/blink/renderer/platform/testing/paint_property_test_helpers.h"
#include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h" #include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h"
#include "third_party/blink/renderer/platform/transforms/affine_transform.h"
namespace blink { namespace blink {
class CullRectTest : public testing::Test { using CullRectTest = testing::Test;
protected:
IntRect Rect(const CullRect& cull_rect) { return cull_rect.rect_; }
};
TEST_F(CullRectTest, IntersectsCullRect) { TEST_F(CullRectTest, IntersectsIntRect) {
CullRect cull_rect(IntRect(0, 0, 50, 50)); CullRect cull_rect(IntRect(0, 0, 50, 50));
EXPECT_TRUE(cull_rect.IntersectsCullRect(IntRect(0, 0, 1, 1))); EXPECT_TRUE(cull_rect.Intersects(IntRect(0, 0, 1, 1)));
EXPECT_FALSE(cull_rect.IntersectsCullRect(IntRect(51, 51, 1, 1))); EXPECT_FALSE(cull_rect.Intersects(IntRect(51, 51, 1, 1)));
} }
TEST_F(CullRectTest, IntersectsCullRectWithLayoutRect) { TEST_F(CullRectTest, IntersectsLayoutRect) {
CullRect cull_rect(IntRect(0, 0, 50, 50)); CullRect cull_rect(IntRect(0, 0, 50, 50));
EXPECT_TRUE(cull_rect.IntersectsCullRect(LayoutRect(0, 0, 1, 1))); EXPECT_TRUE(cull_rect.Intersects(LayoutRect(0, 0, 1, 1)));
EXPECT_TRUE(cull_rect.IntersectsCullRect(LayoutRect( EXPECT_TRUE(cull_rect.Intersects(LayoutRect(
LayoutUnit(0.1), LayoutUnit(0.1), LayoutUnit(0.1), LayoutUnit(0.1)))); LayoutUnit(0.1), LayoutUnit(0.1), LayoutUnit(0.1), LayoutUnit(0.1))));
} }
TEST_F(CullRectTest, IntersectsCullRectWithTransform) { TEST_F(CullRectTest, IntersectsTransformed) {
CullRect cull_rect(IntRect(0, 0, 50, 50)); CullRect cull_rect(IntRect(0, 0, 50, 50));
AffineTransform transform; AffineTransform transform;
transform.Translate(-2, -2); transform.Translate(-2, -2);
EXPECT_TRUE(cull_rect.IntersectsCullRect(transform, FloatRect(51, 51, 1, 1))); EXPECT_TRUE(
EXPECT_FALSE(cull_rect.IntersectsCullRect(IntRect(52, 52, 1, 1))); cull_rect.IntersectsTransformed(transform, FloatRect(51, 51, 1, 1)));
EXPECT_FALSE(cull_rect.Intersects(IntRect(52, 52, 1, 1)));
} }
TEST_F(CullRectTest, UpdateCullRect) { TEST_F(CullRectTest, ApplyTransform) {
CullRect cull_rect(IntRect(1, 1, 50, 50)); CullRect cull_rect(IntRect(1, 1, 50, 50));
AffineTransform transform; auto transform =
transform.Translate(1, 1); CreateTransform(t0(), TransformationMatrix().Translate(1, 1));
cull_rect.UpdateCullRect(transform); cull_rect.ApplyTransform(transform.get());
EXPECT_EQ(IntRect(0, 0, 50, 50), cull_rect.Rect());
}
TEST_F(CullRectTest, ApplyScrollTranslation) {
ScopedSlimmingPaintV2ForTest spv2(true);
EXPECT_EQ(IntRect(0, 0, 50, 50), Rect(cull_rect)); ScrollPaintPropertyNode::State scroll_state;
scroll_state.container_rect = IntRect(20, 10, 40, 50);
auto scroll = ScrollPaintPropertyNode::Create(ScrollPaintPropertyNode::Root(),
std::move(scroll_state));
auto scroll_translation = CreateScrollTranslation(t0(), 10, 15, *scroll);
CullRect cull_rect(IntRect(0, 0, 50, 100));
cull_rect.ApplyTransform(scroll_translation.get());
// Clipped: (20, 10, 30, 50)
// Inverse transformed: (10, -5, 30, 50)
// Expanded: (-3990, -4005, 8030, 8050)
EXPECT_EQ(IntRect(-3990, -4005, 8030, 8050), cull_rect.Rect());
} }
TEST_F(CullRectTest, IntersectsVerticalRange) { TEST_F(CullRectTest, IntersectsVerticalRange) {
...@@ -65,18 +83,4 @@ TEST_F(CullRectTest, IntersectsHorizontalRange) { ...@@ -65,18 +83,4 @@ TEST_F(CullRectTest, IntersectsHorizontalRange) {
cull_rect.IntersectsHorizontalRange(LayoutUnit(50), LayoutUnit(51))); cull_rect.IntersectsHorizontalRange(LayoutUnit(50), LayoutUnit(51)));
} }
TEST_F(CullRectTest, UpdateForScrollingContents) {
ScopedSlimmingPaintV2ForTest spv2(true);
CullRect cull_rect(IntRect(0, 0, 50, 100));
AffineTransform transform;
transform.Translate(10, 15);
cull_rect.UpdateForScrollingContents(IntRect(20, 10, 40, 50), transform);
// Clipped: (20, 10, 30, 50)
// Expanded: (-3980, -3990, 8030, 8050)
// Inverse transformed: (-3990, -4005, 8030, 8050)
EXPECT_EQ(IntRect(-3990, -4005, 8030, 8050), Rect(cull_rect));
}
} // namespace blink } // namespace blink
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