OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/frame/FrameView.h" | 5 #include "core/frame/FrameView.h" |
6 #include "core/layout/LayoutTestHelper.h" | 6 #include "core/layout/LayoutTestHelper.h" |
7 #include "core/layout/LayoutView.h" | 7 #include "core/layout/LayoutView.h" |
8 #include "core/paint/PaintLayer.h" | 8 #include "core/paint/PaintLayer.h" |
| 9 #include "platform/graphics/GraphicsLayer.h" |
| 10 #include "platform/graphics/paint/RasterInvalidationTracking.h" |
9 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" | 11 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
11 | 13 |
12 namespace blink { | 14 namespace blink { |
13 | 15 |
14 namespace { | 16 namespace { |
15 | 17 |
16 class PaintInvalidationTest : public ::testing::WithParamInterface<bool>, | 18 class PaintInvalidationTest : public ::testing::WithParamInterface<bool>, |
17 private ScopedRootLayerScrollingForTest, | 19 private ScopedRootLayerScrollingForTest, |
18 public RenderingTest { | 20 public RenderingTest { |
19 public: | 21 public: |
20 PaintInvalidationTest() | 22 PaintInvalidationTest() |
21 : ScopedRootLayerScrollingForTest(GetParam()), | 23 : ScopedRootLayerScrollingForTest(GetParam()), |
22 RenderingTest(SingleChildLocalFrameClient::Create()) {} | 24 RenderingTest(SingleChildLocalFrameClient::Create()) {} |
| 25 |
| 26 protected: |
| 27 const RasterInvalidationTracking* GetRasterInvalidationTracking() const { |
| 28 // TODO(wangxianzhu): Test SPv2. |
| 29 return GetLayoutView() |
| 30 .Layer() |
| 31 ->GraphicsLayerBacking() |
| 32 ->GetRasterInvalidationTracking(); |
| 33 } |
23 }; | 34 }; |
24 | 35 |
25 INSTANTIATE_TEST_CASE_P(All, PaintInvalidationTest, ::testing::Bool()); | 36 INSTANTIATE_TEST_CASE_P(All, PaintInvalidationTest, ::testing::Bool()); |
26 | 37 |
27 // Changing style in a way that changes overflow without layout should cause | 38 // Changing style in a way that changes overflow without layout should cause |
28 // the layout view to possibly need a paint invalidation since we may have | 39 // the layout view to possibly need a paint invalidation since we may have |
29 // revealed additional background that can be scrolled into view. | 40 // revealed additional background that can be scrolled into view. |
30 TEST_P(PaintInvalidationTest, RecalcOverflowInvalidatesBackground) { | 41 TEST_P(PaintInvalidationTest, RecalcOverflowInvalidatesBackground) { |
31 GetDocument().GetPage()->GetSettings().SetViewportEnabled(true); | 42 GetDocument().GetPage()->GetSettings().SetViewportEnabled(true); |
32 SetBodyInnerHTML( | 43 SetBodyInnerHTML( |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 GetDocument().View()->UpdateAllLifecyclePhases(); | 157 GetDocument().View()->UpdateAllLifecyclePhases(); |
147 fixed.setAttribute(HTMLNames::styleAttr, "top: 50px"); | 158 fixed.setAttribute(HTMLNames::styleAttr, "top: 50px"); |
148 GetDocument().View()->UpdateLifecycleToCompositingCleanPlusScrolling(); | 159 GetDocument().View()->UpdateLifecycleToCompositingCleanPlusScrolling(); |
149 EXPECT_TRUE(fixed_object.MayNeedPaintInvalidation()); | 160 EXPECT_TRUE(fixed_object.MayNeedPaintInvalidation()); |
150 EXPECT_FALSE(fixed_layer.SubtreeIsInvisible()); | 161 EXPECT_FALSE(fixed_layer.SubtreeIsInvisible()); |
151 GetDocument().View()->UpdateAllLifecyclePhasesExceptPaint(); | 162 GetDocument().View()->UpdateAllLifecyclePhasesExceptPaint(); |
152 EXPECT_TRUE(fixed_layer.NeedsRepaint()); | 163 EXPECT_TRUE(fixed_layer.NeedsRepaint()); |
153 GetDocument().View()->UpdateAllLifecyclePhases(); | 164 GetDocument().View()->UpdateAllLifecyclePhases(); |
154 } | 165 } |
155 | 166 |
| 167 TEST_P(PaintInvalidationTest, DelayedFullPaintInvalidation) { |
| 168 EnableCompositing(); |
| 169 SetBodyInnerHTML( |
| 170 "<style>body { margin: 0 }</style>" |
| 171 "<div style='height: 4000px'></div>" |
| 172 "<div id='target' style='width: 100px; height: 100px; background: blue'>" |
| 173 "</div>"); |
| 174 |
| 175 auto* target = GetLayoutObjectByElementId("target"); |
| 176 target->SetShouldDoFullPaintInvalidationWithoutGeometryChange( |
| 177 kPaintInvalidationDelayedFull); |
| 178 EXPECT_EQ(kPaintInvalidationDelayedFull, |
| 179 target->FullPaintInvalidationReason()); |
| 180 EXPECT_FALSE(target->NeedsPaintOffsetAndVisualRectUpdate()); |
| 181 |
| 182 GetDocument().View()->SetTracksPaintInvalidations(true); |
| 183 GetDocument().View()->UpdateAllLifecyclePhases(); |
| 184 EXPECT_EQ(nullptr, GetRasterInvalidationTracking()); |
| 185 EXPECT_EQ(kPaintInvalidationDelayedFull, |
| 186 target->FullPaintInvalidationReason()); |
| 187 EXPECT_FALSE(target->NeedsPaintOffsetAndVisualRectUpdate()); |
| 188 GetDocument().View()->SetTracksPaintInvalidations(false); |
| 189 |
| 190 GetDocument().View()->SetTracksPaintInvalidations(true); |
| 191 // Scroll target into view. |
| 192 GetDocument().domWindow()->scrollTo(0, 4000); |
| 193 GetDocument().View()->UpdateAllLifecyclePhases(); |
| 194 const auto& raster_invalidations = |
| 195 GetRasterInvalidationTracking()->tracked_raster_invalidations; |
| 196 ASSERT_EQ(1u, raster_invalidations.size()); |
| 197 EXPECT_EQ(kPaintInvalidationNone, target->FullPaintInvalidationReason()); |
| 198 EXPECT_EQ(IntRect(0, 4000, 100, 100), raster_invalidations[0].rect); |
| 199 EXPECT_EQ(kPaintInvalidationFull, raster_invalidations[0].reason); |
| 200 EXPECT_FALSE(target->NeedsPaintOffsetAndVisualRectUpdate()); |
| 201 GetDocument().View()->SetTracksPaintInvalidations(false); |
| 202 }; |
| 203 |
156 } // namespace | 204 } // namespace |
157 | 205 |
158 } // namespace blink | 206 } // namespace blink |
OLD | NEW |