Commit 10056cdd authored by wangxianzhu's avatar wangxianzhu Committed by Commit bot

Optimize offscreen animation: don't update paint properties/visual rects

CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2

Review-Url: https://codereview.chromium.org/2821323002
Cr-Commit-Position: refs/heads/master@{#468081}
parent 89209614
......@@ -1756,7 +1756,7 @@ void LayoutBox::PaintMask(const PaintInfo& paint_info,
}
void LayoutBox::ImageChanged(WrappedImagePtr image, const IntRect*) {
// TODO(chrishtr): support PaintInvalidationDelayedFull for animated border
// TODO(chrishtr): support kPaintInvalidationDelayedFull for animated border
// images.
if ((StyleRef().BorderImage().GetImage() &&
StyleRef().BorderImage().GetImage()->Data() == image) ||
......@@ -1878,14 +1878,11 @@ void LayoutBox::EnsureIsReadyForPaintInvalidation() {
return;
// Do regular full paint invalidation if the object with
// PaintInvalidationDelayedFull is onscreen.
if (IntersectsVisibleViewport()) {
// kPaintInvalidationDelayedFull is onscreen.
// Conservatively assume the delayed paint invalidation was caused by
// background image change.
SetBackgroundChangedSinceLastPaintInvalidation();
SetShouldDoFullPaintInvalidationWithoutGeometryChange(
kPaintInvalidationFull);
}
SetShouldDoFullPaintInvalidationWithoutGeometryChange(kPaintInvalidationFull);
}
PaintInvalidationReason LayoutBox::InvalidatePaint(
......
......@@ -170,10 +170,10 @@ void LayoutImage::InvalidatePaintAndMarkForLayoutIfNeeded() {
return;
}
if (ImageResource() && ImageResource()->MaybeAnimated())
SetShouldDoFullPaintInvalidation(kPaintInvalidationDelayedFull);
else
SetShouldDoFullPaintInvalidation(kPaintInvalidationFull);
SetShouldDoFullPaintInvalidationWithoutGeometryChange(
ImageResource() && ImageResource()->MaybeAnimated()
? kPaintInvalidationDelayedFull
: kPaintInvalidationFull);
// Tell any potential compositing layers that the image needs updating.
ContentChanged(kImageChanged);
......
......@@ -6,6 +6,8 @@
#include "core/layout/LayoutTestHelper.h"
#include "core/layout/LayoutView.h"
#include "core/paint/PaintLayer.h"
#include "platform/graphics/GraphicsLayer.h"
#include "platform/graphics/paint/RasterInvalidationTracking.h"
#include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -20,6 +22,15 @@ class PaintInvalidationTest : public ::testing::WithParamInterface<bool>,
PaintInvalidationTest()
: ScopedRootLayerScrollingForTest(GetParam()),
RenderingTest(SingleChildLocalFrameClient::Create()) {}
protected:
const RasterInvalidationTracking* GetRasterInvalidationTracking() const {
// TODO(wangxianzhu): Test SPv2.
return GetLayoutView()
.Layer()
->GraphicsLayerBacking()
->GetRasterInvalidationTracking();
}
};
INSTANTIATE_TEST_CASE_P(All, PaintInvalidationTest, ::testing::Bool());
......@@ -153,6 +164,43 @@ TEST_P(PaintInvalidationTest, InvisibleTransformUnderFixedOnScroll) {
GetDocument().View()->UpdateAllLifecyclePhases();
}
TEST_P(PaintInvalidationTest, DelayedFullPaintInvalidation) {
EnableCompositing();
SetBodyInnerHTML(
"<style>body { margin: 0 }</style>"
"<div style='height: 4000px'></div>"
"<div id='target' style='width: 100px; height: 100px; background: blue'>"
"</div>");
auto* target = GetLayoutObjectByElementId("target");
target->SetShouldDoFullPaintInvalidationWithoutGeometryChange(
kPaintInvalidationDelayedFull);
EXPECT_EQ(kPaintInvalidationDelayedFull,
target->FullPaintInvalidationReason());
EXPECT_FALSE(target->NeedsPaintOffsetAndVisualRectUpdate());
GetDocument().View()->SetTracksPaintInvalidations(true);
GetDocument().View()->UpdateAllLifecyclePhases();
EXPECT_EQ(nullptr, GetRasterInvalidationTracking());
EXPECT_EQ(kPaintInvalidationDelayedFull,
target->FullPaintInvalidationReason());
EXPECT_FALSE(target->NeedsPaintOffsetAndVisualRectUpdate());
GetDocument().View()->SetTracksPaintInvalidations(false);
GetDocument().View()->SetTracksPaintInvalidations(true);
// Scroll target into view.
GetDocument().domWindow()->scrollTo(0, 4000);
GetDocument().View()->UpdateAllLifecyclePhases();
const auto& raster_invalidations =
GetRasterInvalidationTracking()->tracked_raster_invalidations;
ASSERT_EQ(1u, raster_invalidations.size());
EXPECT_EQ(kPaintInvalidationNone, target->FullPaintInvalidationReason());
EXPECT_EQ(IntRect(0, 4000, 100, 100), raster_invalidations[0].rect);
EXPECT_EQ(kPaintInvalidationFull, raster_invalidations[0].reason);
EXPECT_FALSE(target->NeedsPaintOffsetAndVisualRectUpdate());
GetDocument().View()->SetTracksPaintInvalidations(false);
};
} // namespace
} // namespace blink
......@@ -510,7 +510,8 @@ void PaintInvalidator::InvalidatePaint(const LayoutObject& object,
void PaintInvalidator::ProcessPendingDelayedPaintInvalidations() {
for (auto target : pending_delayed_paint_invalidations_) {
target->GetMutableForPainting().SetShouldDoFullPaintInvalidation(
target->GetMutableForPainting()
.SetShouldDoFullPaintInvalidationWithoutGeometryChange(
kPaintInvalidationDelayedFull);
}
}
......
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