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

Side by Side Diff: Source/core/paint/LayoutObjectDrawingRecorderTest.cpp

Issue 1315993004: Implement a paint offset cache for slimming paint v2 (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase more (world moved in the past hour) Created 5 years, 3 months 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "config.h" 5 #include "config.h"
6 #include "core/paint/LayoutObjectDrawingRecorder.h" 6 #include "core/paint/LayoutObjectDrawingRecorder.h"
7 7
8 #include "core/layout/LayoutTestHelper.h" 8 #include "core/layout/LayoutTestHelper.h"
9 #include "core/layout/LayoutView.h" 9 #include "core/layout/LayoutView.h"
10 #include "core/paint/DeprecatedPaintLayer.h" 10 #include "core/paint/DeprecatedPaintLayer.h"
(...skipping 30 matching lines...) Expand all
41 41
42 void TearDown() override 42 void TearDown() override
43 { 43 {
44 RuntimeEnabledFeatures::setSlimmingPaintEnabled(m_originalSlimmingPaintE nabled); 44 RuntimeEnabledFeatures::setSlimmingPaintEnabled(m_originalSlimmingPaintE nabled);
45 } 45 }
46 46
47 LayoutView* m_layoutView; 47 LayoutView* m_layoutView;
48 bool m_originalSlimmingPaintEnabled; 48 bool m_originalSlimmingPaintEnabled;
49 }; 49 };
50 50
51 class LayoutObjectDrawingRecorderTestForSlimmingPaintV2 : public RenderingTest {
52 public:
53 LayoutObjectDrawingRecorderTestForSlimmingPaintV2()
54 : m_layoutView(nullptr)
55 , m_originalSlimmingPaintEnabled(RuntimeEnabledFeatures::slimmingPaintEn abled())
56 , m_originalSlimmingPaintV2Enabled(RuntimeEnabledFeatures::slimmingPaint V2Enabled()) { }
57
58 protected:
59 LayoutView& layoutView() { return *m_layoutView; }
60 DisplayItemList& rootDisplayItemList() { return *layoutView().layer()->graph icsLayerBacking()->displayItemList(); }
61 const DisplayItems& newDisplayItemsBeforeUpdate() { return rootDisplayItemLi st().m_newDisplayItems; }
62
63 private:
64 void SetUp() override
65 {
66 RuntimeEnabledFeatures::setSlimmingPaintEnabled(true);
67 RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(true);
68
69 RenderingTest::SetUp();
70 enableCompositing();
71
72 m_layoutView = document().view()->layoutView();
73 ASSERT_TRUE(m_layoutView);
74 }
75
76 void TearDown() override
77 {
78 RuntimeEnabledFeatures::setSlimmingPaintEnabled(m_originalSlimmingPaintV 2Enabled);
79 RuntimeEnabledFeatures::setSlimmingPaintEnabled(m_originalSlimmingPaintE nabled);
80 }
81
82 LayoutView* m_layoutView;
83 bool m_originalSlimmingPaintEnabled;
84 bool m_originalSlimmingPaintV2Enabled;
85 };
86
51 namespace { 87 namespace {
52 88
53 void drawNothing(GraphicsContext& context, const LayoutView& layoutView, PaintPh ase phase, const LayoutRect& bound) 89 void drawNothing(GraphicsContext& context, const LayoutView& layoutView, PaintPh ase phase, const LayoutRect& bound)
54 { 90 {
55 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, layoutV iew, phase)) 91 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, layoutV iew, phase, LayoutPoint()))
56 return; 92 return;
57 93
58 LayoutObjectDrawingRecorder drawingRecorder(context, layoutView, phase, boun d); 94 LayoutObjectDrawingRecorder drawingRecorder(context, layoutView, phase, boun d, LayoutPoint());
59 } 95 }
60 96
61 void drawRect(GraphicsContext& context, LayoutView& layoutView, PaintPhase phase , const LayoutRect& bound) 97 void drawRect(GraphicsContext& context, LayoutView& layoutView, PaintPhase phase , const LayoutRect& bound)
62 { 98 {
63 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, layoutV iew, phase)) 99 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, layoutV iew, phase, LayoutPoint()))
64 return; 100 return;
65 LayoutObjectDrawingRecorder drawingRecorder(context, layoutView, phase, boun d); 101 LayoutObjectDrawingRecorder drawingRecorder(context, layoutView, phase, boun d, LayoutPoint());
66 IntRect rect(0, 0, 10, 10); 102 IntRect rect(0, 0, 10, 10);
67 context.drawRect(rect); 103 context.drawRect(rect);
68 } 104 }
69 105
70 bool isDrawing(const DisplayItem& item) 106 bool isDrawing(const DisplayItem& item)
71 { 107 {
72 return DisplayItem::isDrawingType(item.type()); 108 return DisplayItem::isDrawingType(item.type());
73 } 109 }
74 110
75 bool isCached(const DisplayItem& item) 111 bool isCached(const DisplayItem& item)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 } 160 }
125 161
126 template <typename T> 162 template <typename T>
127 FloatRect drawAndGetCullRect(DisplayItemList& list, const LayoutObject& layoutOb ject, const T& bounds) 163 FloatRect drawAndGetCullRect(DisplayItemList& list, const LayoutObject& layoutOb ject, const T& bounds)
128 { 164 {
129 list.invalidateAll(); 165 list.invalidateAll();
130 { 166 {
131 // Draw some things which will produce a non-null picture. 167 // Draw some things which will produce a non-null picture.
132 GraphicsContext context(&list); 168 GraphicsContext context(&list);
133 LayoutObjectDrawingRecorder recorder( 169 LayoutObjectDrawingRecorder recorder(
134 context, layoutObject, DisplayItem::BoxDecorationBackground, bounds) ; 170 context, layoutObject, DisplayItem::BoxDecorationBackground, bounds, LayoutPoint());
135 context.drawRect(enclosedIntRect(FloatRect(bounds))); 171 context.drawRect(enclosedIntRect(FloatRect(bounds)));
136 } 172 }
137 list.commitNewDisplayItems(); 173 list.commitNewDisplayItems();
138 const auto& drawing = static_cast<const DrawingDisplayItem&>(list.displayIte ms()[0]); 174 const auto& drawing = static_cast<const DrawingDisplayItem&>(list.displayIte ms()[0]);
139 return drawing.picture()->cullRect(); 175 return drawing.picture()->cullRect();
140 } 176 }
141 177
142 TEST_F(LayoutObjectDrawingRecorderTest, CullRectMatchesProvidedClip) 178 TEST_F(LayoutObjectDrawingRecorderTest, CullRectMatchesProvidedClip)
143 { 179 {
144 // It's safe for the picture's cull rect to be expanded (though doing so 180 // It's safe for the picture's cull rect to be expanded (though doing so
145 // excessively may harm performance), but it cannot be contracted. 181 // excessively may harm performance), but it cannot be contracted.
146 // For now, this test expects the two rects to match completely. 182 // For now, this test expects the two rects to match completely.
147 // 183 //
148 // This rect is chosen so that in the x direction, pixel snapping rounds in 184 // This rect is chosen so that in the x direction, pixel snapping rounds in
149 // the opposite direction to enclosing, and in the y direction, the edges 185 // the opposite direction to enclosing, and in the y direction, the edges
150 // are exactly on a half-pixel boundary. The numbers chosen map nicely to 186 // are exactly on a half-pixel boundary. The numbers chosen map nicely to
151 // both float and LayoutUnit, to make equality checking reliable. 187 // both float and LayoutUnit, to make equality checking reliable.
152 FloatRect rect(20.75, -5.5, 5.375, 10); 188 FloatRect rect(20.75, -5.5, 5.375, 10);
153 EXPECT_EQ(rect, drawAndGetCullRect(rootDisplayItemList(), layoutView(), rect )); 189 EXPECT_EQ(rect, drawAndGetCullRect(rootDisplayItemList(), layoutView(), rect ));
154 EXPECT_EQ(rect, drawAndGetCullRect(rootDisplayItemList(), layoutView(), Layo utRect(rect))); 190 EXPECT_EQ(rect, drawAndGetCullRect(rootDisplayItemList(), layoutView(), Layo utRect(rect)));
155 } 191 }
156 192
193 TEST_F(LayoutObjectDrawingRecorderTestForSlimmingPaintV2, PaintOffsetCache)
194 {
195 GraphicsContext context(&rootDisplayItemList());
196 LayoutRect bounds = layoutView().viewRect();
197 LayoutPoint paintOffset(1, 2);
198
199 rootDisplayItemList().invalidateAll();
200 EXPECT_FALSE(LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context , layoutView(), PaintPhaseForeground, paintOffset));
201 {
202 LayoutObjectDrawingRecorder drawingRecorder(context, layoutView(), Paint PhaseForeground, bounds, paintOffset);
203 IntRect rect(0, 0, 10, 10);
204 context.drawRect(rect);
205 }
206
207 rootDisplayItemList().commitNewDisplayItems();
208 EXPECT_EQ((size_t)1, rootDisplayItemList().displayItems().size());
209 EXPECT_TRUE(isDrawing(rootDisplayItemList().displayItems()[0]));
210
211 // Ensure we cannot use the cache with a new paint offset.
212 LayoutPoint newPaintOffset(2, 3);
213 EXPECT_FALSE(LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context , layoutView(), PaintPhaseForeground, newPaintOffset));
214
215 // Test that a new paint offset is recorded.
216 {
217 LayoutObjectDrawingRecorder drawingRecorder(context, layoutView(), Paint PhaseForeground, bounds, newPaintOffset);
218 IntRect rect(0, 0, 10, 10);
219 context.drawRect(rect);
220 }
221
222 rootDisplayItemList().commitNewDisplayItems();
223 EXPECT_EQ((size_t)1, rootDisplayItemList().displayItems().size());
224 EXPECT_TRUE(isDrawing(rootDisplayItemList().displayItems()[0]));
225
226 // Ensure the old paint offset cannot be used.
227 EXPECT_FALSE(LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context , layoutView(), PaintPhaseForeground, paintOffset));
228
229 // Ensure the new paint offset can be used.
230 EXPECT_TRUE(LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, layoutView(), PaintPhaseForeground, newPaintOffset));
231 rootDisplayItemList().commitNewDisplayItems();
232 EXPECT_EQ((size_t)1, rootDisplayItemList().displayItems().size());
233 EXPECT_TRUE(isDrawing(rootDisplayItemList().displayItems()[0]));
234 }
235
157 } // namespace 236 } // namespace
158 } // namespace blink 237 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/paint/LayoutObjectDrawingRecorder.h ('k') | Source/core/paint/ListMarkerPainter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698