| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/layout/LayoutTestHelper.h" | 5 #include "core/layout/LayoutTestHelper.h" |
| 6 #include "core/layout/LayoutTreeAsText.h" | 6 #include "core/layout/LayoutTreeAsText.h" |
| 7 #include "core/layout/api/LayoutViewItem.h" | 7 #include "core/layout/api/LayoutViewItem.h" |
| 8 #include "core/paint/ObjectPaintProperties.h" | 8 #include "core/paint/ObjectPaintProperties.h" |
| 9 #include "core/paint/PaintLayer.h" | 9 #include "core/paint/PaintLayer.h" |
| 10 #include "core/paint/PaintPropertyTreePrinter.h" | 10 #include "core/paint/PaintPropertyTreePrinter.h" |
| 11 #include "core/paint/PrePaintTreeWalk.h" |
| 11 #include "platform/graphics/paint/GeometryMapper.h" | 12 #include "platform/graphics/paint/GeometryMapper.h" |
| 12 #include "platform/graphics/paint/ScrollPaintPropertyNode.h" | 13 #include "platform/graphics/paint/ScrollPaintPropertyNode.h" |
| 13 #include "platform/graphics/paint/TransformPaintPropertyNode.h" | 14 #include "platform/graphics/paint/TransformPaintPropertyNode.h" |
| 14 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" | 15 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" |
| 15 #include "platform/testing/UnitTestHelpers.h" | 16 #include "platform/testing/UnitTestHelpers.h" |
| 16 #include "platform/text/TextStream.h" | 17 #include "platform/text/TextStream.h" |
| 17 #include "platform/wtf/HashMap.h" | 18 #include "platform/wtf/HashMap.h" |
| 18 #include "platform/wtf/Vector.h" | 19 #include "platform/wtf/Vector.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 21 |
| 21 namespace blink { | 22 namespace blink { |
| 22 | 23 |
| 23 typedef bool TestParamRootLayerScrolling; | 24 typedef std::pair<bool, bool> SlimmingPaintAndRootLayerScrolling; |
| 24 class PrePaintTreeWalkTest | 25 class PrePaintTreeWalkTest |
| 25 : public ::testing::WithParamInterface<TestParamRootLayerScrolling>, | 26 : public ::testing::WithParamInterface<SlimmingPaintAndRootLayerScrolling>, |
| 26 private ScopedSlimmingPaintV2ForTest, | 27 private ScopedSlimmingPaintV2ForTest, |
| 27 private ScopedRootLayerScrollingForTest, | 28 private ScopedRootLayerScrollingForTest, |
| 28 public RenderingTest { | 29 public RenderingTest { |
| 29 public: | 30 public: |
| 30 PrePaintTreeWalkTest() | 31 PrePaintTreeWalkTest() |
| 31 : ScopedSlimmingPaintV2ForTest(true), | 32 : ScopedSlimmingPaintV2ForTest(GetParam().second), |
| 32 ScopedRootLayerScrollingForTest(GetParam()), | 33 ScopedRootLayerScrollingForTest(GetParam().first), |
| 33 RenderingTest(EmptyLocalFrameClient::Create()) {} | 34 RenderingTest(EmptyLocalFrameClient::Create()) {} |
| 34 | 35 |
| 35 const TransformPaintPropertyNode* FramePreTranslation() { | 36 const TransformPaintPropertyNode* FramePreTranslation() { |
| 36 FrameView* frame_view = GetDocument().View(); | 37 FrameView* frame_view = GetDocument().View(); |
| 37 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) { | 38 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) { |
| 38 return frame_view->GetLayoutView() | 39 return frame_view->GetLayoutView() |
| 39 ->PaintProperties() | 40 ->PaintProperties() |
| 40 ->PaintOffsetTranslation(); | 41 ->PaintOffsetTranslation(); |
| 41 } | 42 } |
| 42 return frame_view->PreTranslation(); | 43 return frame_view->PreTranslation(); |
| 43 } | 44 } |
| 44 | 45 |
| 45 const TransformPaintPropertyNode* FrameScrollTranslation() { | 46 const TransformPaintPropertyNode* FrameScrollTranslation() { |
| 46 FrameView* frame_view = GetDocument().View(); | 47 FrameView* frame_view = GetDocument().View(); |
| 47 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) { | 48 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) { |
| 48 return frame_view->GetLayoutView() | 49 return frame_view->GetLayoutView() |
| 49 ->PaintProperties() | 50 ->PaintProperties() |
| 50 ->ScrollTranslation(); | 51 ->ScrollTranslation(); |
| 51 } | 52 } |
| 52 return frame_view->ScrollTranslation(); | 53 return frame_view->ScrollTranslation(); |
| 53 } | 54 } |
| 54 | 55 |
| 56 protected: |
| 57 PaintLayer* GetPaintLayerByElementId(const char* id) { |
| 58 return ToLayoutBoxModelObject(GetLayoutObjectByElementId(id))->Layer(); |
| 59 } |
| 60 |
| 55 private: | 61 private: |
| 56 void SetUp() override { | 62 void SetUp() override { |
| 57 Settings::SetMockScrollbarsEnabled(true); | 63 Settings::SetMockScrollbarsEnabled(true); |
| 58 | 64 |
| 59 RenderingTest::SetUp(); | 65 RenderingTest::SetUp(); |
| 60 EnableCompositing(); | 66 EnableCompositing(); |
| 61 } | 67 } |
| 62 | 68 |
| 63 void TearDown() override { | 69 void TearDown() override { |
| 64 RenderingTest::TearDown(); | 70 RenderingTest::TearDown(); |
| 65 | 71 |
| 66 Settings::SetMockScrollbarsEnabled(false); | 72 Settings::SetMockScrollbarsEnabled(false); |
| 67 } | 73 } |
| 68 }; | 74 }; |
| 69 | 75 |
| 70 INSTANTIATE_TEST_CASE_P(All, PrePaintTreeWalkTest, ::testing::Bool()); | 76 SlimmingPaintAndRootLayerScrolling g_prepaint_foo[] = { |
| 77 SlimmingPaintAndRootLayerScrolling(false, false), |
| 78 SlimmingPaintAndRootLayerScrolling(true, false), |
| 79 SlimmingPaintAndRootLayerScrolling(false, true), |
| 80 SlimmingPaintAndRootLayerScrolling(true, true)}; |
| 81 |
| 82 INSTANTIATE_TEST_CASE_P(All, |
| 83 PrePaintTreeWalkTest, |
| 84 ::testing::ValuesIn(g_prepaint_foo)); |
| 71 | 85 |
| 72 TEST_P(PrePaintTreeWalkTest, PropertyTreesRebuiltWithBorderInvalidation) { | 86 TEST_P(PrePaintTreeWalkTest, PropertyTreesRebuiltWithBorderInvalidation) { |
| 73 SetBodyInnerHTML( | 87 SetBodyInnerHTML( |
| 74 "<style>" | 88 "<style>" |
| 75 " body { margin: 0; }" | 89 " body { margin: 0; }" |
| 76 " #transformed { transform: translate(100px, 100px); }" | 90 " #transformed { transform: translate(100px, 100px); }" |
| 77 " .border { border: 10px solid black; }" | 91 " .border { border: 10px solid black; }" |
| 78 "</style>" | 92 "</style>" |
| 79 "<div id='transformed'></div>"); | 93 "<div id='transformed'></div>"); |
| 80 | 94 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 EXPECT_TRUE(child_paint_layer->NeedsRepaint()); | 219 EXPECT_TRUE(child_paint_layer->NeedsRepaint()); |
| 206 } | 220 } |
| 207 | 221 |
| 208 TEST_P(PrePaintTreeWalkTest, ClearSubsequenceCachingClipChangePosAbs) { | 222 TEST_P(PrePaintTreeWalkTest, ClearSubsequenceCachingClipChangePosAbs) { |
| 209 SetBodyInnerHTML( | 223 SetBodyInnerHTML( |
| 210 "<style>" | 224 "<style>" |
| 211 " .clip { overflow: hidden }" | 225 " .clip { overflow: hidden }" |
| 212 "</style>" | 226 "</style>" |
| 213 "<div id='parent' style='transform: translateZ(0); width: 100px;" | 227 "<div id='parent' style='transform: translateZ(0); width: 100px;" |
| 214 " height: 100px; position: absolute'>" | 228 " height: 100px; position: absolute'>" |
| 215 " <div id='child' style='overflow: hidden; z-index: 0; width: 50px;" | 229 " <div id='child' style='overflow: hidden; position: relative;" |
| 216 " height: 50px'>" | 230 " z-index: 0; width: 50px; height: 50px'>" |
| 217 " content" | 231 " content" |
| 218 " </div>" | 232 " </div>" |
| 219 "</div>"); | 233 "</div>"); |
| 220 | 234 |
| 221 auto* parent = GetDocument().GetElementById("parent"); | 235 auto* parent = GetDocument().GetElementById("parent"); |
| 222 auto* child = GetDocument().GetElementById("child"); | 236 auto* child = GetDocument().GetElementById("child"); |
| 223 auto* child_paint_layer = | 237 auto* child_paint_layer = |
| 224 ToLayoutBoxModelObject(child->GetLayoutObject())->Layer(); | 238 ToLayoutBoxModelObject(child->GetLayoutObject())->Layer(); |
| 225 EXPECT_FALSE(child_paint_layer->NeedsRepaint()); | 239 EXPECT_FALSE(child_paint_layer->NeedsRepaint()); |
| 226 EXPECT_FALSE(child_paint_layer->NeedsPaintPhaseFloat()); | 240 EXPECT_FALSE(child_paint_layer->NeedsPaintPhaseFloat()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 254 EXPECT_FALSE(child_paint_layer->NeedsPaintPhaseFloat()); | 268 EXPECT_FALSE(child_paint_layer->NeedsPaintPhaseFloat()); |
| 255 | 269 |
| 256 // This changes clips for absolute-positioned descendants of "child" but not | 270 // This changes clips for absolute-positioned descendants of "child" but not |
| 257 // normal-position ones, which are already clipped to 50x50. | 271 // normal-position ones, which are already clipped to 50x50. |
| 258 parent->setAttribute(HTMLNames::classAttr, "clip"); | 272 parent->setAttribute(HTMLNames::classAttr, "clip"); |
| 259 GetDocument().View()->UpdateAllLifecyclePhasesExceptPaint(); | 273 GetDocument().View()->UpdateAllLifecyclePhasesExceptPaint(); |
| 260 | 274 |
| 261 EXPECT_TRUE(child_paint_layer->NeedsRepaint()); | 275 EXPECT_TRUE(child_paint_layer->NeedsRepaint()); |
| 262 } | 276 } |
| 263 | 277 |
| 278 TEST_P(PrePaintTreeWalkTest, ClipRects) { |
| 279 SetBodyInnerHTML( |
| 280 "<div id='parent' style='isolation: isolate'>" |
| 281 " <div id='child' style='position: relative'>" |
| 282 " <div id='grandchild' style='isolation: isolate'>" |
| 283 " <div style='position: relative'></div>" |
| 284 " </div>" |
| 285 " </div>" |
| 286 "</div>"); |
| 287 |
| 288 auto* parent = GetPaintLayerByElementId("parent"); |
| 289 auto* child = GetPaintLayerByElementId("child"); |
| 290 auto* grandchild = GetPaintLayerByElementId("grandchild"); |
| 291 |
| 292 EXPECT_TRUE(parent->PreviousPaintingClipRects()); |
| 293 EXPECT_FALSE(child->PreviousPaintingClipRects()); |
| 294 EXPECT_TRUE(grandchild->PreviousPaintingClipRects()); |
| 295 |
| 296 grandchild->ClearPreviousPaintingClipRects(); |
| 297 GetDocument().View()->UpdateAllLifecyclePhases(); |
| 298 // Still no rects, because the walk early-outed at the LayoutView. |
| 299 EXPECT_FALSE(grandchild->PreviousPaintingClipRects()); |
| 300 |
| 301 grandchild->GetLayoutObject().SetNeedsPaintPropertyUpdate(); |
| 302 GetDocument().View()->UpdateAllLifecyclePhases(); |
| 303 EXPECT_TRUE(grandchild->PreviousPaintingClipRects()); |
| 304 } |
| 305 |
| 306 TEST_P(PrePaintTreeWalkTest, VisualRectClipForceSubtree) { |
| 307 SetBodyInnerHTML( |
| 308 "<style>" |
| 309 " .heightClass { height: 100px !important }" |
| 310 " #parent { height: 75px }" |
| 311 "</style>" |
| 312 "<div id='parent' style='width: 100px; position: " |
| 313 "relative' class='heightClass'>" |
| 314 " <div id='child' style='overflow: hidden; width: 100%; height: 100%; " |
| 315 " position: relative'>" |
| 316 " <div>" |
| 317 " <div id='grandchild' style='width: 50px; height: 200px; '>" |
| 318 " </div>" |
| 319 " </div>" |
| 320 " </div>" |
| 321 "</div>"); |
| 322 |
| 323 auto* grandchild = GetLayoutObjectByElementId("grandchild"); |
| 324 |
| 325 GetDocument().GetElementById("parent")->removeAttribute("class"); |
| 326 GetDocument().View()->UpdateAllLifecyclePhases(); |
| 327 |
| 328 // In SPv2 mode, VisualRects are in the space of the containing transform |
| 329 // node without applying any ancestor property nodes, including clip. |
| 330 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) |
| 331 EXPECT_EQ(200, grandchild->VisualRect().Height()); |
| 332 else |
| 333 EXPECT_EQ(75, grandchild->VisualRect().Height()); |
| 334 } |
| 335 |
| 264 } // namespace blink | 336 } // namespace blink |
| OLD | NEW |