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

Side by Side Diff: third_party/WebKit/Source/core/paint/BoxPaintInvalidatorTest.cpp

Issue 2449953005: [SPInvalidation] Handle pixel-snapping of paint invalidation rects (Closed)
Patch Set: 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 unified diff | Download patch
OLDNEW
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/HTMLNames.h" 5 #include "core/HTMLNames.h"
6 #include "core/frame/FrameView.h" 6 #include "core/frame/FrameView.h"
7 #include "core/layout/LayoutTestHelper.h" 7 #include "core/layout/LayoutTestHelper.h"
8 #include "core/layout/LayoutView.h" 8 #include "core/layout/LayoutView.h"
9 #include "core/paint/PaintLayer.h" 9 #include "core/paint/PaintLayer.h"
10 #include "platform/graphics/GraphicsLayer.h" 10 #include "platform/graphics/GraphicsLayer.h"
11 #include "platform/graphics/paint/RasterInvalidationTracking.h" 11 #include "platform/graphics/paint/RasterInvalidationTracking.h"
12 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h"
12 13
13 namespace blink { 14 namespace blink {
14 15
15 class BoxPaintInvalidatorTest : public RenderingTest { 16 class BoxPaintInvalidatorTest : public RenderingTest {
16 protected: 17 protected:
17 const RasterInvalidationTracking* getRasterInvalidationTracking() const { 18 const RasterInvalidationTracking* getRasterInvalidationTracking() const {
18 // TODO(wangxianzhu): Test SPv2. 19 // TODO(wangxianzhu): Test SPv2.
19 return layoutView() 20 return layoutView()
20 .layer() 21 .layer()
21 ->graphicsLayerBacking() 22 ->graphicsLayerBacking()
(...skipping 17 matching lines...) Expand all
39 "</style>" 40 "</style>"
40 "<div id='target'></div>"); 41 "<div id='target'></div>");
41 } 42 }
42 }; 43 };
43 44
44 TEST_F(BoxPaintInvalidatorTest, IncrementalInvalidationExpand) { 45 TEST_F(BoxPaintInvalidatorTest, IncrementalInvalidationExpand) {
45 document().view()->setTracksPaintInvalidations(true); 46 document().view()->setTracksPaintInvalidations(true);
46 Element* target = document().getElementById("target"); 47 Element* target = document().getElementById("target");
47 target->setAttribute(HTMLNames::styleAttr, "width: 100px; height: 200px"); 48 target->setAttribute(HTMLNames::styleAttr, "width: 100px; height: 200px");
48 document().view()->updateAllLifecyclePhases(); 49 document().view()->updateAllLifecyclePhases();
49 const auto* rasterInvalidations = 50 const auto& rasterInvalidations =
50 &getRasterInvalidationTracking()->trackedRasterInvalidations; 51 getRasterInvalidationTracking()->trackedRasterInvalidations;
51 EXPECT_EQ(2u, rasterInvalidations->size()); 52 EXPECT_EQ(2u, rasterInvalidations.size());
52 EXPECT_EQ(IntRect(60, 0, 60, 240), (*rasterInvalidations)[0].rect); 53 EXPECT_EQ(IntRect(60, 0, 60, 240), rasterInvalidations[0].rect);
53 EXPECT_EQ(PaintInvalidationIncremental, (*rasterInvalidations)[0].reason); 54 EXPECT_EQ(PaintInvalidationIncremental, rasterInvalidations[0].reason);
54 EXPECT_EQ(IntRect(0, 120, 120, 120), (*rasterInvalidations)[1].rect); 55 EXPECT_EQ(IntRect(0, 120, 120, 120), rasterInvalidations[1].rect);
55 EXPECT_EQ(PaintInvalidationIncremental, (*rasterInvalidations)[1].reason); 56 EXPECT_EQ(PaintInvalidationIncremental, rasterInvalidations[1].reason);
56 document().view()->setTracksPaintInvalidations(false); 57 document().view()->setTracksPaintInvalidations(false);
57 } 58 }
58 59
59 TEST_F(BoxPaintInvalidatorTest, IncrementalInvalidationShrink) { 60 TEST_F(BoxPaintInvalidatorTest, IncrementalInvalidationShrink) {
60 document().view()->setTracksPaintInvalidations(true); 61 document().view()->setTracksPaintInvalidations(true);
61 Element* target = document().getElementById("target"); 62 Element* target = document().getElementById("target");
62 target->setAttribute(HTMLNames::styleAttr, "width: 20px; height: 80px"); 63 target->setAttribute(HTMLNames::styleAttr, "width: 20px; height: 80px");
63 document().view()->updateAllLifecyclePhases(); 64 document().view()->updateAllLifecyclePhases();
64 const auto* rasterInvalidations = 65 const auto& rasterInvalidations =
65 &getRasterInvalidationTracking()->trackedRasterInvalidations; 66 getRasterInvalidationTracking()->trackedRasterInvalidations;
66 EXPECT_EQ(2u, rasterInvalidations->size()); 67 EXPECT_EQ(2u, rasterInvalidations.size());
67 EXPECT_EQ(IntRect(30, 0, 40, 140), (*rasterInvalidations)[0].rect); 68 EXPECT_EQ(IntRect(30, 0, 40, 140), rasterInvalidations[0].rect);
68 EXPECT_EQ(PaintInvalidationIncremental, (*rasterInvalidations)[0].reason); 69 EXPECT_EQ(PaintInvalidationIncremental, rasterInvalidations[0].reason);
69 EXPECT_EQ(IntRect(0, 100, 70, 40), (*rasterInvalidations)[1].rect); 70 EXPECT_EQ(IntRect(0, 100, 70, 40), rasterInvalidations[1].rect);
70 EXPECT_EQ(PaintInvalidationIncremental, (*rasterInvalidations)[1].reason); 71 EXPECT_EQ(PaintInvalidationIncremental, rasterInvalidations[1].reason);
71 document().view()->setTracksPaintInvalidations(false); 72 document().view()->setTracksPaintInvalidations(false);
72 } 73 }
73 74
74 TEST_F(BoxPaintInvalidatorTest, IncrementalInvalidationMixed) { 75 TEST_F(BoxPaintInvalidatorTest, IncrementalInvalidationMixed) {
75 document().view()->setTracksPaintInvalidations(true); 76 document().view()->setTracksPaintInvalidations(true);
76 Element* target = document().getElementById("target"); 77 Element* target = document().getElementById("target");
77 target->setAttribute(HTMLNames::styleAttr, "width: 100px; height: 80px"); 78 target->setAttribute(HTMLNames::styleAttr, "width: 100px; height: 80px");
78 document().view()->updateAllLifecyclePhases(); 79 document().view()->updateAllLifecyclePhases();
79 const auto* rasterInvalidations = 80 const auto& rasterInvalidations =
80 &getRasterInvalidationTracking()->trackedRasterInvalidations; 81 getRasterInvalidationTracking()->trackedRasterInvalidations;
81 EXPECT_EQ(2u, rasterInvalidations->size()); 82 EXPECT_EQ(2u, rasterInvalidations.size());
82 EXPECT_EQ(IntRect(60, 0, 60, 120), (*rasterInvalidations)[0].rect); 83 EXPECT_EQ(IntRect(60, 0, 60, 120), rasterInvalidations[0].rect);
83 EXPECT_EQ(PaintInvalidationIncremental, (*rasterInvalidations)[0].reason); 84 EXPECT_EQ(PaintInvalidationIncremental, rasterInvalidations[0].reason);
84 EXPECT_EQ(IntRect(0, 100, 70, 40), (*rasterInvalidations)[1].rect); 85 EXPECT_EQ(IntRect(0, 100, 70, 40), rasterInvalidations[1].rect);
85 EXPECT_EQ(PaintInvalidationIncremental, (*rasterInvalidations)[1].reason); 86 EXPECT_EQ(PaintInvalidationIncremental, rasterInvalidations[1].reason);
86 document().view()->setTracksPaintInvalidations(false); 87 document().view()->setTracksPaintInvalidations(false);
87 } 88 }
88 89
90 TEST_F(BoxPaintInvalidatorTest, Subpixel) {
91 ScopedSlimmingPaintInvalidationForTest scopedSlimmingPaintInvalidation(true);
92
93 Element* target = document().getElementById("target");
94 LayoutObject* targetObject = target->layoutObject();
95 EXPECT_FALSE(targetObject->previousPaintInvalidationRectCoversExtraPixels());
96
97 // Should do full invalidation if new geometry has subpixels.
98 document().view()->setTracksPaintInvalidations(true);
99 target->setAttribute(HTMLNames::styleAttr, "width: 20.6px; height: 80.3px");
100 document().view()->updateAllLifecyclePhases();
101 EXPECT_TRUE(targetObject->previousPaintInvalidationRectCoversExtraPixels());
102 const auto* rasterInvalidations =
103 &getRasterInvalidationTracking()->trackedRasterInvalidations;
104 EXPECT_EQ(1u, rasterInvalidations->size());
105 EXPECT_EQ(IntRect(0, 0, 70, 140), (*rasterInvalidations)[0].rect);
106 EXPECT_EQ(PaintInvalidationBoundsChange, (*rasterInvalidations)[0].reason);
107 document().view()->setTracksPaintInvalidations(false);
108
109 // Should do full invalidation if old geometry has subpixels.
110 document().view()->setTracksPaintInvalidations(true);
111 target->setAttribute(HTMLNames::styleAttr, "width: 50px; height: 100px");
112 document().view()->updateAllLifecyclePhases();
113 EXPECT_FALSE(targetObject->previousPaintInvalidationRectCoversExtraPixels());
114 rasterInvalidations =
115 &getRasterInvalidationTracking()->trackedRasterInvalidations;
116 EXPECT_EQ(1u, rasterInvalidations->size());
117 EXPECT_EQ(IntRect(0, 0, 70, 140), (*rasterInvalidations)[0].rect);
118 EXPECT_EQ(PaintInvalidationBoundsChange, (*rasterInvalidations)[0].reason);
119 document().view()->setTracksPaintInvalidations(false);
120
121 // Should do full invalidation if new geometry has subpixels even if the paint
122 // invalidation rect doesn't change.
123 document().view()->setTracksPaintInvalidations(true);
124 target->setAttribute(HTMLNames::styleAttr,
125 "margin-top: 0.6px; width: 50px; height: 99.3px");
126 document().view()->updateAllLifecyclePhases();
127 EXPECT_TRUE(targetObject->previousPaintInvalidationRectCoversExtraPixels());
128 rasterInvalidations =
129 &getRasterInvalidationTracking()->trackedRasterInvalidations;
130 EXPECT_EQ(1u, rasterInvalidations->size());
131 EXPECT_EQ(IntRect(0, 0, 70, 140), (*rasterInvalidations)[0].rect);
132 EXPECT_EQ(PaintInvalidationLocationChange, (*rasterInvalidations)[0].reason);
133 document().view()->setTracksPaintInvalidations(false);
134
135 document().view()->setTracksPaintInvalidations(true);
136 target->setAttribute(HTMLNames::styleAttr,
137 "margin-top: 0.6px; width: 50px; height: 100px");
138 document().view()->updateAllLifecyclePhases();
139 EXPECT_TRUE(targetObject->previousPaintInvalidationRectCoversExtraPixels());
140 rasterInvalidations =
141 &getRasterInvalidationTracking()->trackedRasterInvalidations;
142 EXPECT_EQ(1u, rasterInvalidations->size());
143 EXPECT_EQ(IntRect(0, 0, 70, 141), (*rasterInvalidations)[0].rect);
144 EXPECT_EQ(PaintInvalidationBoundsChange, (*rasterInvalidations)[0].reason);
145 document().view()->setTracksPaintInvalidations(false);
146 }
147
89 } // namespace blink 148 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698