Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(550)

Unified Diff: third_party/WebKit/Source/core/paint/BoxPaintInvalidatorTest.cpp

Issue 2498823002: Paint invalidation of local attachment backgrounds (Closed)
Patch Set: Update test expectations Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/paint/BoxPaintInvalidatorTest.cpp
diff --git a/third_party/WebKit/Source/core/paint/BoxPaintInvalidatorTest.cpp b/third_party/WebKit/Source/core/paint/BoxPaintInvalidatorTest.cpp
index 5785e1c943504816957589cb57777c94fa7c4fa9..4d9c0634d72a144414df62fc977f0d3a2b319eb5 100644
--- a/third_party/WebKit/Source/core/paint/BoxPaintInvalidatorTest.cpp
+++ b/third_party/WebKit/Source/core/paint/BoxPaintInvalidatorTest.cpp
@@ -13,13 +13,20 @@
namespace blink {
-class BoxPaintInvalidatorTest : public RenderingTest {
+class BoxPaintInvalidatorTest : public ::testing::WithParamInterface<bool>,
+ private ScopedRootLayerScrollingForTest,
+ public RenderingTest {
+ public:
+ BoxPaintInvalidatorTest()
+ : ScopedRootLayerScrollingForTest(GetParam()),
+ RenderingTest(SingleChildFrameLoaderClient::create()) {}
+
protected:
const RasterInvalidationTracking* getRasterInvalidationTracking() const {
// TODO(wangxianzhu): Test SPv2.
return layoutView()
.layer()
- ->graphicsLayerBacking()
+ ->graphicsLayerBackingForScrolling()
->getRasterInvalidationTracking();
}
@@ -30,27 +37,37 @@ class BoxPaintInvalidatorTest : public RenderingTest {
setBodyInnerHTML(
"<style>"
" body { margin: 0 }"
+ " ::-webkit-scrollbar { display: none }"
" #target {"
" width: 50px;"
" height: 100px;"
" border-width: 20px 10px;"
" border-style: solid;"
" border-color: red;"
- " transform-origin: 0 0"
+ " transform-origin: 0 0;"
+ " }"
+ " #target.local-background {"
+ " background-attachment: local;"
+ " overflow: scroll;"
+ " }"
+ " #target.gradient {"
+ " background-image: linear-gradient(blue, yellow)"
" }"
"</style>"
"<div id='target'></div>");
}
};
-TEST_F(BoxPaintInvalidatorTest, IncrementalInvalidationExpand) {
+INSTANTIATE_TEST_CASE_P(All, BoxPaintInvalidatorTest, ::testing::Bool());
+
+TEST_P(BoxPaintInvalidatorTest, IncrementalInvalidationExpand) {
document().view()->setTracksPaintInvalidations(true);
Element* target = document().getElementById("target");
target->setAttribute(HTMLNames::styleAttr, "width: 100px; height: 200px");
document().view()->updateAllLifecyclePhases();
const auto& rasterInvalidations =
getRasterInvalidationTracking()->trackedRasterInvalidations;
- EXPECT_EQ(2u, rasterInvalidations.size());
+ ASSERT_EQ(2u, rasterInvalidations.size());
EXPECT_EQ(IntRect(60, 0, 60, 240), rasterInvalidations[0].rect);
EXPECT_EQ(PaintInvalidationIncremental, rasterInvalidations[0].reason);
EXPECT_EQ(IntRect(0, 120, 120, 120), rasterInvalidations[1].rect);
@@ -58,14 +75,14 @@ TEST_F(BoxPaintInvalidatorTest, IncrementalInvalidationExpand) {
document().view()->setTracksPaintInvalidations(false);
}
-TEST_F(BoxPaintInvalidatorTest, IncrementalInvalidationShrink) {
+TEST_P(BoxPaintInvalidatorTest, IncrementalInvalidationShrink) {
document().view()->setTracksPaintInvalidations(true);
Element* target = document().getElementById("target");
target->setAttribute(HTMLNames::styleAttr, "width: 20px; height: 80px");
document().view()->updateAllLifecyclePhases();
const auto& rasterInvalidations =
getRasterInvalidationTracking()->trackedRasterInvalidations;
- EXPECT_EQ(2u, rasterInvalidations.size());
+ ASSERT_EQ(2u, rasterInvalidations.size());
EXPECT_EQ(IntRect(30, 0, 40, 140), rasterInvalidations[0].rect);
EXPECT_EQ(PaintInvalidationIncremental, rasterInvalidations[0].reason);
EXPECT_EQ(IntRect(0, 100, 70, 40), rasterInvalidations[1].rect);
@@ -73,14 +90,14 @@ TEST_F(BoxPaintInvalidatorTest, IncrementalInvalidationShrink) {
document().view()->setTracksPaintInvalidations(false);
}
-TEST_F(BoxPaintInvalidatorTest, IncrementalInvalidationMixed) {
+TEST_P(BoxPaintInvalidatorTest, IncrementalInvalidationMixed) {
document().view()->setTracksPaintInvalidations(true);
Element* target = document().getElementById("target");
target->setAttribute(HTMLNames::styleAttr, "width: 100px; height: 80px");
document().view()->updateAllLifecyclePhases();
const auto& rasterInvalidations =
getRasterInvalidationTracking()->trackedRasterInvalidations;
- EXPECT_EQ(2u, rasterInvalidations.size());
+ ASSERT_EQ(2u, rasterInvalidations.size());
EXPECT_EQ(IntRect(60, 0, 60, 120), rasterInvalidations[0].rect);
EXPECT_EQ(PaintInvalidationIncremental, rasterInvalidations[0].reason);
EXPECT_EQ(IntRect(0, 100, 70, 40), rasterInvalidations[1].rect);
@@ -88,7 +105,7 @@ TEST_F(BoxPaintInvalidatorTest, IncrementalInvalidationMixed) {
document().view()->setTracksPaintInvalidations(false);
}
-TEST_F(BoxPaintInvalidatorTest, SubpixelVisualRectChagne) {
+TEST_P(BoxPaintInvalidatorTest, SubpixelVisualRectChagne) {
ScopedSlimmingPaintInvalidationForTest scopedSlimmingPaintInvalidation(true);
Element* target = document().getElementById("target");
@@ -99,7 +116,7 @@ TEST_F(BoxPaintInvalidatorTest, SubpixelVisualRectChagne) {
document().view()->updateAllLifecyclePhases();
const auto* rasterInvalidations =
&getRasterInvalidationTracking()->trackedRasterInvalidations;
- EXPECT_EQ(2u, rasterInvalidations->size());
+ ASSERT_EQ(2u, rasterInvalidations->size());
EXPECT_EQ(IntRect(0, 0, 70, 140), (*rasterInvalidations)[0].rect);
EXPECT_EQ(PaintInvalidationBorderBoxChange, (*rasterInvalidations)[0].reason);
EXPECT_EQ(IntRect(0, 0, 121, 111), (*rasterInvalidations)[1].rect);
@@ -112,7 +129,7 @@ TEST_F(BoxPaintInvalidatorTest, SubpixelVisualRectChagne) {
document().view()->updateAllLifecyclePhases();
rasterInvalidations =
&getRasterInvalidationTracking()->trackedRasterInvalidations;
- EXPECT_EQ(2u, rasterInvalidations->size());
+ ASSERT_EQ(2u, rasterInvalidations->size());
EXPECT_EQ(IntRect(0, 0, 121, 111), (*rasterInvalidations)[0].rect);
EXPECT_EQ(PaintInvalidationBorderBoxChange, (*rasterInvalidations)[0].reason);
EXPECT_EQ(IntRect(0, 0, 70, 140), (*rasterInvalidations)[1].rect);
@@ -120,7 +137,7 @@ TEST_F(BoxPaintInvalidatorTest, SubpixelVisualRectChagne) {
document().view()->setTracksPaintInvalidations(false);
}
-TEST_F(BoxPaintInvalidatorTest, SubpixelChangeWithoutVisualRectChange) {
+TEST_P(BoxPaintInvalidatorTest, SubpixelChangeWithoutVisualRectChange) {
ScopedSlimmingPaintInvalidationForTest scopedSlimmingPaintInvalidation(true);
Element* target = document().getElementById("target");
@@ -136,7 +153,7 @@ TEST_F(BoxPaintInvalidatorTest, SubpixelChangeWithoutVisualRectChange) {
EXPECT_EQ(LayoutRect(0, 0, 70, 140), targetObject->previousVisualRect());
const auto* rasterInvalidations =
&getRasterInvalidationTracking()->trackedRasterInvalidations;
- EXPECT_EQ(1u, rasterInvalidations->size());
+ ASSERT_EQ(1u, rasterInvalidations->size());
EXPECT_EQ(IntRect(0, 0, 70, 140), (*rasterInvalidations)[0].rect);
EXPECT_EQ(PaintInvalidationLocationChange, (*rasterInvalidations)[0].reason);
document().view()->setTracksPaintInvalidations(false);
@@ -148,13 +165,13 @@ TEST_F(BoxPaintInvalidatorTest, SubpixelChangeWithoutVisualRectChange) {
EXPECT_EQ(LayoutRect(0, 0, 70, 140), targetObject->previousVisualRect());
rasterInvalidations =
&getRasterInvalidationTracking()->trackedRasterInvalidations;
- EXPECT_EQ(1u, rasterInvalidations->size());
+ ASSERT_EQ(1u, rasterInvalidations->size());
EXPECT_EQ(IntRect(0, 0, 70, 140), (*rasterInvalidations)[0].rect);
EXPECT_EQ(PaintInvalidationBorderBoxChange, (*rasterInvalidations)[0].reason);
document().view()->setTracksPaintInvalidations(false);
}
-TEST_F(BoxPaintInvalidatorTest, ResizeRotated) {
+TEST_P(BoxPaintInvalidatorTest, ResizeRotated) {
ScopedSlimmingPaintInvalidationForTest scopedSlimmingPaintInvalidation(true);
Element* target = document().getElementById("target");
@@ -168,13 +185,13 @@ TEST_F(BoxPaintInvalidatorTest, ResizeRotated) {
document().view()->updateAllLifecyclePhases();
const auto* rasterInvalidations =
&getRasterInvalidationTracking()->trackedRasterInvalidations;
- EXPECT_EQ(1u, rasterInvalidations->size());
+ ASSERT_EQ(1u, rasterInvalidations->size());
EXPECT_EQ(IntRect(-99, 0, 255, 255), (*rasterInvalidations)[0].rect);
EXPECT_EQ(PaintInvalidationBorderBoxChange, (*rasterInvalidations)[0].reason);
document().view()->setTracksPaintInvalidations(false);
}
-TEST_F(BoxPaintInvalidatorTest, ResizeRotatedChild) {
+TEST_P(BoxPaintInvalidatorTest, ResizeRotatedChild) {
ScopedSlimmingPaintInvalidationForTest scopedSlimmingPaintInvalidation(true);
Element* target = document().getElementById("target");
@@ -193,10 +210,250 @@ TEST_F(BoxPaintInvalidatorTest, ResizeRotatedChild) {
document().view()->updateAllLifecyclePhases();
const auto* rasterInvalidations =
&getRasterInvalidationTracking()->trackedRasterInvalidations;
- EXPECT_EQ(1u, rasterInvalidations->size());
+ ASSERT_EQ(1u, rasterInvalidations->size());
EXPECT_EQ(IntRect(-43, 21, 107, 107), (*rasterInvalidations)[0].rect);
EXPECT_EQ(PaintInvalidationBorderBoxChange, (*rasterInvalidations)[0].reason);
document().view()->setTracksPaintInvalidations(false);
}
+TEST_P(BoxPaintInvalidatorTest, CompositedLayoutViewResize) {
+ enableCompositing();
+ Element* target = document().getElementById("target");
+ target->setAttribute(HTMLNames::styleAttr, "height: 2000px");
+ document().view()->updateAllLifecyclePhases();
+
+ // Resize the content.
+ document().view()->setTracksPaintInvalidations(true);
+ target->setAttribute(HTMLNames::styleAttr, "height: 3000px");
+ document().view()->updateAllLifecyclePhases();
+ const auto& rasterInvalidations =
+ getRasterInvalidationTracking()->trackedRasterInvalidations;
+ if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) {
+ // TODO(skobes): Treat LayoutView in the same way as normal objects having
+ // background-attachment: local. crbug.com/568847.
+ EXPECT_EQ(1u, rasterInvalidations.size());
+ EXPECT_EQ(IntRect(0, 2020, 70, 1020), rasterInvalidations[0].rect);
+ EXPECT_EQ(static_cast<const DisplayItemClient*>(target->layoutObject()),
+ rasterInvalidations[0].client);
+ EXPECT_EQ(PaintInvalidationIncremental, rasterInvalidations[0].reason);
+ } else {
+ EXPECT_EQ(2u, rasterInvalidations.size());
+ EXPECT_EQ(IntRect(0, 2040, 800, 1000), rasterInvalidations[0].rect);
+ EXPECT_EQ(static_cast<const DisplayItemClient*>(&layoutView()),
+ rasterInvalidations[0].client);
+ EXPECT_EQ(PaintInvalidationIncremental, rasterInvalidations[0].reason);
+ EXPECT_EQ(IntRect(0, 2020, 70, 1020), rasterInvalidations[1].rect);
+ EXPECT_EQ(static_cast<const DisplayItemClient*>(target->layoutObject()),
+ rasterInvalidations[1].client);
+ EXPECT_EQ(PaintInvalidationIncremental, rasterInvalidations[1].reason);
+ }
+ document().view()->setTracksPaintInvalidations(false);
+
+ // Resize the viewport. No paint invalidation.
+ document().view()->setTracksPaintInvalidations(true);
+ document().view()->resize(800, 1000);
+ document().view()->updateAllLifecyclePhases();
+ EXPECT_FALSE(getRasterInvalidationTracking());
+ document().view()->setTracksPaintInvalidations(false);
+}
+
+TEST_P(BoxPaintInvalidatorTest, NonCompositedLayoutViewResize) {
+ setBodyInnerHTML(
+ "<style>"
+ " body { margin: 0 }"
+ " iframe { display: block; width: 100px; height: 100px; border: none; }"
+ "</style>"
+ "<iframe id='iframe'></iframe>");
+ Document& frameDocument = setupChildIframe(
+ "iframe",
+ "<style>"
+ " ::-webkit-scrollbar { display: none }"
+ " body { margin: 0; background: green; height: 0 }"
+ "</style>"
+ "<div id='content' style='width: 200px; height: 200px'></div>");
+ document().view()->updateAllLifecyclePhases();
+ Element* iframe = document().getElementById("iframe");
+ Element* content = frameDocument.getElementById("content");
+ EXPECT_EQ(layoutView(),
+ content->layoutObject()->containerForPaintInvalidation());
+
+ // Resize the content.
+ document().view()->setTracksPaintInvalidations(true);
+ content->setAttribute(HTMLNames::styleAttr, "height: 500px");
+ document().view()->updateAllLifecyclePhases();
+ // No invalidation because the changed part of layout overflow is clipped.
+ EXPECT_FALSE(getRasterInvalidationTracking());
+ document().view()->setTracksPaintInvalidations(false);
+
+ // Resize the iframe.
+ document().view()->setTracksPaintInvalidations(true);
+ iframe->setAttribute(HTMLNames::styleAttr, "height: 200px");
+ document().view()->updateAllLifecyclePhases();
+ const auto& rasterInvalidations =
+ getRasterInvalidationTracking()->trackedRasterInvalidations;
+ ASSERT_EQ(2u, rasterInvalidations.size());
+ EXPECT_EQ(IntRect(0, 100, 100, 100), rasterInvalidations[0].rect);
+ EXPECT_EQ(static_cast<const DisplayItemClient*>(iframe->layoutObject()),
+ rasterInvalidations[0].client);
+ EXPECT_EQ(PaintInvalidationIncremental, rasterInvalidations[0].reason);
+ EXPECT_EQ(
+ static_cast<const DisplayItemClient*>(content->layoutObject()->view()),
+ rasterInvalidations[1].client);
+ if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) {
+ // TODO(skobes): Treat LayoutView in the same way as normal objects having
+ // background-attachment: local. crbug.com/568847.
+ EXPECT_EQ(IntRect(0, 0, 100, 200), rasterInvalidations[1].rect);
+ EXPECT_EQ(PaintInvalidationFull, rasterInvalidations[1].reason);
+ } else {
+ EXPECT_EQ(IntRect(0, 100, 100, 100), rasterInvalidations[1].rect);
+ EXPECT_EQ(PaintInvalidationIncremental, rasterInvalidations[1].reason);
+ }
+ document().view()->setTracksPaintInvalidations(false);
+}
+
+TEST_P(BoxPaintInvalidatorTest, CompositedBackgroundAttachmentLocalResize) {
+ enableCompositing();
+
+ Element* target = document().getElementById("target");
+ target->setAttribute(HTMLNames::classAttr, "local-background");
+ target->setAttribute(HTMLNames::styleAttr, "will-change: transform");
+ target->setInnerHTML(
+ "<div id=child style='width: 500px; height: 500px'></div>",
+ ASSERT_NO_EXCEPTION);
+ Element* child = document().getElementById("child");
+ document().view()->updateAllLifecyclePhases();
+
+ // Resize the content.
+ document().view()->setTracksPaintInvalidations(true);
+ child->setAttribute(HTMLNames::styleAttr, "width: 500px; height: 1000px");
+ document().view()->updateAllLifecyclePhases();
+ GraphicsLayer* containerLayer = toLayoutBoxModelObject(target->layoutObject())
+ ->layer()
+ ->graphicsLayerBacking();
+ GraphicsLayer* contentsLayer = toLayoutBoxModelObject(target->layoutObject())
+ ->layer()
+ ->graphicsLayerBackingForScrolling();
+ // No invalidation on the container layer.
+ EXPECT_FALSE(containerLayer->getRasterInvalidationTracking());
+ // Incremental invalidation of background on contents layer.
+ const auto& contentsRasterInvalidations =
+ contentsLayer->getRasterInvalidationTracking()
+ ->trackedRasterInvalidations;
+ ASSERT_EQ(1u, contentsRasterInvalidations.size());
+ EXPECT_EQ(IntRect(0, 500, 500, 500), contentsRasterInvalidations[0].rect);
+ EXPECT_EQ(static_cast<const DisplayItemClient*>(target->layoutObject()),
+ contentsRasterInvalidations[0].client);
+ EXPECT_EQ(PaintInvalidationBackgroundOnScrollingContentsLayer,
+ contentsRasterInvalidations[0].reason);
+ document().view()->setTracksPaintInvalidations(false);
+
+ // Resize the container.
+ document().view()->setTracksPaintInvalidations(true);
+ target->setAttribute(HTMLNames::styleAttr,
+ "will-change: transform; height: 200px");
+ document().view()->updateAllLifecyclePhases();
+ // No invalidation on the contents layer.
+ EXPECT_FALSE(contentsLayer->getRasterInvalidationTracking());
+ // Incremental invalidation on the container layer.
+ const auto& containerRasterInvalidations =
+ containerLayer->getRasterInvalidationTracking()
+ ->trackedRasterInvalidations;
+ ASSERT_EQ(1u, containerRasterInvalidations.size());
+ EXPECT_EQ(IntRect(0, 120, 70, 120), containerRasterInvalidations[0].rect);
+ EXPECT_EQ(static_cast<const DisplayItemClient*>(target->layoutObject()),
+ containerRasterInvalidations[0].client);
+ EXPECT_EQ(PaintInvalidationIncremental,
+ containerRasterInvalidations[0].reason);
+ document().view()->setTracksPaintInvalidations(false);
+}
+
+TEST_P(BoxPaintInvalidatorTest,
+ CompositedBackgroundAttachmentLocalGradientResize) {
+ enableCompositing();
+
+ Element* target = document().getElementById("target");
+ target->setAttribute(HTMLNames::classAttr, "local-background gradient");
+ target->setAttribute(HTMLNames::styleAttr, "will-change: transform");
+ target->setInnerHTML(
+ "<div id='child' style='width: 500px; height: 500px'></div>",
+ ASSERT_NO_EXCEPTION);
+ Element* child = document().getElementById("child");
+ document().view()->updateAllLifecyclePhases();
+
+ // Resize the content.
+ document().view()->setTracksPaintInvalidations(true);
+ child->setAttribute(HTMLNames::styleAttr, "width: 500px; height: 1000px");
+ document().view()->updateAllLifecyclePhases();
+ GraphicsLayer* containerLayer = toLayoutBoxModelObject(target->layoutObject())
+ ->layer()
+ ->graphicsLayerBacking();
+ GraphicsLayer* contentsLayer = toLayoutBoxModelObject(target->layoutObject())
+ ->layer()
+ ->graphicsLayerBackingForScrolling();
+ // No invalidation on the container layer.
+ EXPECT_FALSE(containerLayer->getRasterInvalidationTracking());
+ // Full invalidation of background on contents layer because the gradient
+ // background is resized.
+ const auto& contentsRasterInvalidations =
+ contentsLayer->getRasterInvalidationTracking()
+ ->trackedRasterInvalidations;
+ ASSERT_EQ(1u, contentsRasterInvalidations.size());
+ EXPECT_EQ(IntRect(0, 0, 500, 1000), contentsRasterInvalidations[0].rect);
+ EXPECT_EQ(static_cast<const DisplayItemClient*>(target->layoutObject()),
+ contentsRasterInvalidations[0].client);
+ EXPECT_EQ(PaintInvalidationBackgroundOnScrollingContentsLayer,
+ contentsRasterInvalidations[0].reason);
+ document().view()->setTracksPaintInvalidations(false);
+
+ // Resize the container.
+ document().view()->setTracksPaintInvalidations(true);
+ target->setAttribute(HTMLNames::styleAttr,
+ "will-change: transform; height: 200px");
+ document().view()->updateAllLifecyclePhases();
+ EXPECT_FALSE(contentsLayer->getRasterInvalidationTracking());
+ // Full invalidation on the container layer.
+ const auto& containerRasterInvalidations =
+ containerLayer->getRasterInvalidationTracking()
+ ->trackedRasterInvalidations;
+ ASSERT_EQ(1u, containerRasterInvalidations.size());
+ EXPECT_EQ(IntRect(0, 0, 70, 240), containerRasterInvalidations[0].rect);
+ EXPECT_EQ(static_cast<const DisplayItemClient*>(target->layoutObject()),
+ containerRasterInvalidations[0].client);
+ EXPECT_EQ(PaintInvalidationBorderBoxChange,
+ containerRasterInvalidations[0].reason);
+ document().view()->setTracksPaintInvalidations(false);
+}
+
+TEST_P(BoxPaintInvalidatorTest, NonCompositedBackgroundAttachmentLocalResize) {
+ Element* target = document().getElementById("target");
+ target->setAttribute(HTMLNames::classAttr, "local-background");
+ target->setInnerHTML(
+ "<div id=child style='width: 500px; height: 500px'></div>",
+ ASSERT_NO_EXCEPTION);
+ Element* child = document().getElementById("child");
+ document().view()->updateAllLifecyclePhases();
+ EXPECT_EQ(&layoutView(),
+ &target->layoutObject()->containerForPaintInvalidation());
+
+ // Resize the content.
+ document().view()->setTracksPaintInvalidations(true);
+ child->setAttribute(HTMLNames::styleAttr, "width: 500px; height: 1000px");
+ document().view()->updateAllLifecyclePhases();
+ // No invalidation because the changed part is invisible.
+ EXPECT_FALSE(getRasterInvalidationTracking());
+
+ // Resize the container.
+ document().view()->setTracksPaintInvalidations(true);
+ target->setAttribute(HTMLNames::styleAttr, "height: 200px");
+ document().view()->updateAllLifecyclePhases();
+ const auto& rasterInvalidations =
+ getRasterInvalidationTracking()->trackedRasterInvalidations;
+ ASSERT_EQ(1u, rasterInvalidations.size());
+ EXPECT_EQ(IntRect(0, 120, 70, 120), rasterInvalidations[0].rect);
+ EXPECT_EQ(static_cast<const DisplayItemClient*>(target->layoutObject()),
+ rasterInvalidations[0].client);
+ EXPECT_EQ(PaintInvalidationIncremental, rasterInvalidations[0].reason);
+ document().view()->setTracksPaintInvalidations(false);
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698