Chromium Code Reviews| 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, |
| 28 private ScopedSlimmingPaintInvalidationForTest, | |
| 27 private ScopedRootLayerScrollingForTest, | 29 private ScopedRootLayerScrollingForTest, |
| 28 public RenderingTest { | 30 public RenderingTest { |
| 29 public: | 31 public: |
| 30 PrePaintTreeWalkTest() | 32 PrePaintTreeWalkTest() |
| 31 : ScopedSlimmingPaintV2ForTest(true), | 33 : ScopedSlimmingPaintV2ForTest(GetParam().second), |
| 32 ScopedRootLayerScrollingForTest(GetParam()), | 34 ScopedSlimmingPaintInvalidationForTest(true), |
| 35 ScopedRootLayerScrollingForTest(GetParam().first), | |
| 33 RenderingTest(EmptyLocalFrameClient::Create()) {} | 36 RenderingTest(EmptyLocalFrameClient::Create()) {} |
| 34 | 37 |
| 35 const TransformPaintPropertyNode* FramePreTranslation() { | 38 const TransformPaintPropertyNode* FramePreTranslation() { |
| 36 FrameView* frame_view = GetDocument().View(); | 39 FrameView* frame_view = GetDocument().View(); |
| 37 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) { | 40 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) { |
| 38 return frame_view->GetLayoutView() | 41 return frame_view->GetLayoutView() |
| 39 ->PaintProperties() | 42 ->PaintProperties() |
| 40 ->PaintOffsetTranslation(); | 43 ->PaintOffsetTranslation(); |
| 41 } | 44 } |
| 42 return frame_view->PreTranslation(); | 45 return frame_view->PreTranslation(); |
| 43 } | 46 } |
| 44 | 47 |
| 45 const TransformPaintPropertyNode* FrameScrollTranslation() { | 48 const TransformPaintPropertyNode* FrameScrollTranslation() { |
| 46 FrameView* frame_view = GetDocument().View(); | 49 FrameView* frame_view = GetDocument().View(); |
| 47 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) { | 50 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) { |
| 48 return frame_view->GetLayoutView() | 51 return frame_view->GetLayoutView() |
| 49 ->PaintProperties() | 52 ->PaintProperties() |
| 50 ->ScrollTranslation(); | 53 ->ScrollTranslation(); |
| 51 } | 54 } |
| 52 return frame_view->ScrollTranslation(); | 55 return frame_view->ScrollTranslation(); |
| 53 } | 56 } |
| 54 | 57 |
| 58 protected: | |
| 59 PaintLayer* GetPaintLayerByElementId(const char* id) { | |
| 60 return ToLayoutBoxModelObject(GetLayoutObjectByElementId(id))->Layer(); | |
| 61 } | |
| 62 | |
| 55 private: | 63 private: |
| 56 void SetUp() override { | 64 void SetUp() override { |
| 57 Settings::SetMockScrollbarsEnabled(true); | 65 Settings::SetMockScrollbarsEnabled(true); |
| 58 | 66 |
| 59 RenderingTest::SetUp(); | 67 RenderingTest::SetUp(); |
| 60 EnableCompositing(); | 68 EnableCompositing(); |
| 61 } | 69 } |
| 62 | 70 |
| 63 void TearDown() override { | 71 void TearDown() override { |
| 64 RenderingTest::TearDown(); | 72 RenderingTest::TearDown(); |
| 65 | 73 |
| 66 Settings::SetMockScrollbarsEnabled(false); | 74 Settings::SetMockScrollbarsEnabled(false); |
| 67 } | 75 } |
| 68 }; | 76 }; |
| 69 | 77 |
| 70 INSTANTIATE_TEST_CASE_P(All, PrePaintTreeWalkTest, ::testing::Bool()); | 78 SlimmingPaintAndRootLayerScrolling g_prepaint_foo[] = { |
| 79 SlimmingPaintAndRootLayerScrolling(false, false), | |
| 80 SlimmingPaintAndRootLayerScrolling(true, false), | |
| 81 SlimmingPaintAndRootLayerScrolling(false, true), | |
| 82 SlimmingPaintAndRootLayerScrolling(true, true)}; | |
| 83 | |
| 84 INSTANTIATE_TEST_CASE_P(All, | |
| 85 PrePaintTreeWalkTest, | |
| 86 ::testing::ValuesIn(g_prepaint_foo)); | |
| 71 | 87 |
| 72 TEST_P(PrePaintTreeWalkTest, PropertyTreesRebuiltWithBorderInvalidation) { | 88 TEST_P(PrePaintTreeWalkTest, PropertyTreesRebuiltWithBorderInvalidation) { |
| 73 SetBodyInnerHTML( | 89 SetBodyInnerHTML( |
| 74 "<style>" | 90 "<style>" |
| 75 " body { margin: 0; }" | 91 " body { margin: 0; }" |
| 76 " #transformed { transform: translate(100px, 100px); }" | 92 " #transformed { transform: translate(100px, 100px); }" |
| 77 " .border { border: 10px solid black; }" | 93 " .border { border: 10px solid black; }" |
| 78 "</style>" | 94 "</style>" |
| 79 "<div id='transformed'></div>"); | 95 "<div id='transformed'></div>"); |
| 80 | 96 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 // Invalidate the CSS transform property. | 144 // Invalidate the CSS transform property. |
| 129 transformed_element->setAttribute(HTMLNames::classAttr, "transformB"); | 145 transformed_element->setAttribute(HTMLNames::classAttr, "transformB"); |
| 130 GetDocument().View()->UpdateAllLifecyclePhases(); | 146 GetDocument().View()->UpdateAllLifecyclePhases(); |
| 131 | 147 |
| 132 // The transform should have changed. | 148 // The transform should have changed. |
| 133 EXPECT_EQ(TransformationMatrix().Translate(200, 200), | 149 EXPECT_EQ(TransformationMatrix().Translate(200, 200), |
| 134 transformed_properties->Transform()->Matrix()); | 150 transformed_properties->Transform()->Matrix()); |
| 135 } | 151 } |
| 136 | 152 |
| 137 TEST_P(PrePaintTreeWalkTest, PropertyTreesRebuiltWithOpacityInvalidation) { | 153 TEST_P(PrePaintTreeWalkTest, PropertyTreesRebuiltWithOpacityInvalidation) { |
| 154 // In SPv1 mode, we don't need or store property tree nodes for effects. | |
| 155 if (!RuntimeEnabledFeatures::slimmingPaintV2Enabled()) | |
| 156 return; | |
| 138 SetBodyInnerHTML( | 157 SetBodyInnerHTML( |
| 139 "<style>" | 158 "<style>" |
| 140 " .opacityA { opacity: 0.9; }" | 159 " .opacityA { opacity: 0.9; }" |
| 141 " .opacityB { opacity: 0.4; }" | 160 " .opacityB { opacity: 0.4; }" |
| 142 "</style>" | 161 "</style>" |
| 143 "<div id='transparent' class='opacityA'></div>"); | 162 "<div id='transparent' class='opacityA'></div>"); |
| 144 | 163 |
| 145 auto* transparent_element = GetDocument().GetElementById("transparent"); | 164 auto* transparent_element = GetDocument().GetElementById("transparent"); |
| 146 const auto* transparent_properties = | 165 const auto* transparent_properties = |
| 147 transparent_element->GetLayoutObject()->PaintProperties(); | 166 transparent_element->GetLayoutObject()->PaintProperties(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 EXPECT_TRUE(child_paint_layer->NeedsRepaint()); | 224 EXPECT_TRUE(child_paint_layer->NeedsRepaint()); |
| 206 } | 225 } |
| 207 | 226 |
| 208 TEST_P(PrePaintTreeWalkTest, ClearSubsequenceCachingClipChangePosAbs) { | 227 TEST_P(PrePaintTreeWalkTest, ClearSubsequenceCachingClipChangePosAbs) { |
| 209 SetBodyInnerHTML( | 228 SetBodyInnerHTML( |
| 210 "<style>" | 229 "<style>" |
| 211 " .clip { overflow: hidden }" | 230 " .clip { overflow: hidden }" |
| 212 "</style>" | 231 "</style>" |
| 213 "<div id='parent' style='transform: translateZ(0); width: 100px;" | 232 "<div id='parent' style='transform: translateZ(0); width: 100px;" |
| 214 " height: 100px; position: absolute'>" | 233 " height: 100px; position: absolute'>" |
| 215 " <div id='child' style='overflow: hidden; z-index: 0; width: 50px;" | 234 " <div id='child' style='overflow: hidden; position: relative;" |
| 216 " height: 50px'>" | 235 " z-index: 0; width: 50px; height: 50px'>" |
| 217 " content" | 236 " content" |
| 218 " </div>" | 237 " </div>" |
| 219 "</div>"); | 238 "</div>"); |
| 220 | 239 |
| 221 auto* parent = GetDocument().GetElementById("parent"); | 240 auto* parent = GetDocument().GetElementById("parent"); |
| 222 auto* child = GetDocument().GetElementById("child"); | 241 auto* child = GetDocument().GetElementById("child"); |
| 223 auto* child_paint_layer = | 242 auto* child_paint_layer = |
| 224 ToLayoutBoxModelObject(child->GetLayoutObject())->Layer(); | 243 ToLayoutBoxModelObject(child->GetLayoutObject())->Layer(); |
| 225 EXPECT_FALSE(child_paint_layer->NeedsRepaint()); | 244 EXPECT_FALSE(child_paint_layer->NeedsRepaint()); |
| 226 EXPECT_FALSE(child_paint_layer->NeedsPaintPhaseFloat()); | 245 EXPECT_FALSE(child_paint_layer->NeedsPaintPhaseFloat()); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 254 EXPECT_FALSE(child_paint_layer->NeedsPaintPhaseFloat()); | 273 EXPECT_FALSE(child_paint_layer->NeedsPaintPhaseFloat()); |
| 255 | 274 |
| 256 // This changes clips for absolute-positioned descendants of "child" but not | 275 // This changes clips for absolute-positioned descendants of "child" but not |
| 257 // normal-position ones, which are already clipped to 50x50. | 276 // normal-position ones, which are already clipped to 50x50. |
| 258 parent->setAttribute(HTMLNames::classAttr, "clip"); | 277 parent->setAttribute(HTMLNames::classAttr, "clip"); |
| 259 GetDocument().View()->UpdateAllLifecyclePhasesExceptPaint(); | 278 GetDocument().View()->UpdateAllLifecyclePhasesExceptPaint(); |
| 260 | 279 |
| 261 EXPECT_TRUE(child_paint_layer->NeedsRepaint()); | 280 EXPECT_TRUE(child_paint_layer->NeedsRepaint()); |
| 262 } | 281 } |
| 263 | 282 |
| 283 TEST_P(PrePaintTreeWalkTest, ClipRects) { | |
| 284 SetBodyInnerHTML( | |
| 285 "<div id='parent' style='isolation: isolate'>" | |
| 286 " <div id='child' style='position: relative'>" | |
| 287 " <div id='grandchild' style='isolation: isolate'>" | |
| 288 " <div style='position: relative'></div>" | |
| 289 " </div>" | |
| 290 " </div>" | |
| 291 "</div>"); | |
| 292 | |
| 293 auto* parent = GetPaintLayerByElementId("parent"); | |
| 294 auto* child = GetPaintLayerByElementId("child"); | |
| 295 auto* grandchild = GetPaintLayerByElementId("grandchild"); | |
| 296 | |
| 297 EXPECT_TRUE(parent->PreviousPaintingClipRects()); | |
| 298 EXPECT_FALSE(child->PreviousPaintingClipRects()); | |
| 299 EXPECT_TRUE(grandchild->PreviousPaintingClipRects()); | |
| 300 | |
| 301 grandchild->ClearPreviousPaintingClipRects(); | |
| 302 GetDocument().View()->UpdateAllLifecyclePhases(); | |
| 303 // Still no rects, because the walk early-outed at the LayoutView. | |
| 304 EXPECT_FALSE(grandchild->PreviousPaintingClipRects()); | |
| 305 | |
| 306 grandchild->GetLayoutObject().SetNeedsPaintPropertyUpdate(); | |
| 307 GetDocument().View()->UpdateAllLifecyclePhases(); | |
| 308 EXPECT_TRUE(grandchild->PreviousPaintingClipRects()); | |
| 309 } | |
| 310 | |
| 311 TEST_P(PrePaintTreeWalkTest, VisualRectClipForceSubtree) { | |
| 312 SetBodyInnerHTML( | |
| 313 "<style>" | |
| 314 " .heightClass { height: 100px !important }" | |
|
pdr.
2017/04/13 16:21:45
!important is a little confusing and there's an ex
chrishtr
2017/04/13 17:15:38
Done.
| |
| 315 " #parent { height: 75px }" | |
| 316 "</style>" | |
| 317 "<div id='parent' style='width: 100px; position: " | |
| 318 "relative' class='heightClass'>" | |
| 319 " <div id='child' style='overflow: hidden; width: 100%; height: 100%; " | |
| 320 " position: relative'>" | |
| 321 " <div>" | |
| 322 " <div id='grandchild' style='width: 50px; height: 200px; '>" | |
| 323 " </div>" | |
| 324 " </div>" | |
| 325 " </div>" | |
| 326 "</div>"); | |
| 327 | |
| 328 auto* grandchild = GetLayoutObjectByElementId("grandchild"); | |
| 329 | |
| 330 GetDocument().GetElementById("parent")->removeAttribute("class"); | |
| 331 GetDocument().View()->UpdateAllLifecyclePhases(); | |
| 332 | |
| 333 // In SPv2 mode, VisualRects are in the space of the containing transform | |
| 334 // node without applying any ancestor property nodes, including clip. | |
| 335 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) | |
| 336 EXPECT_EQ(200, grandchild->VisualRect().Height()); | |
| 337 else | |
| 338 EXPECT_EQ(75, grandchild->VisualRect().Height()); | |
| 339 } | |
| 340 | |
| 264 } // namespace blink | 341 } // namespace blink |
| OLD | NEW |