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

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

Issue 1323243011: Add DisplayItemList::newDisplayItems() and cleanup tests (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 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 | Annotate | Revision Log
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"
11 #include "core/paint/DisplayItemListPaintTest.h"
11 #include "platform/graphics/GraphicsContext.h" 12 #include "platform/graphics/GraphicsContext.h"
12 #include "platform/graphics/GraphicsLayer.h" 13 #include "platform/graphics/GraphicsLayer.h"
13 #include "platform/graphics/paint/DisplayItemList.h" 14 #include "platform/graphics/paint/DisplayItemList.h"
14 #include "platform/graphics/paint/DrawingDisplayItem.h" 15 #include "platform/graphics/paint/DrawingDisplayItem.h"
15 #include <gtest/gtest.h> 16 #include <gtest/gtest.h>
16 17
17 namespace blink { 18 namespace blink {
18 19
19 class LayoutObjectDrawingRecorderTest : public RenderingTest { 20 using LayoutObjectDrawingRecorderTest = DisplayItemListPaintTest;
20 public: 21 using LayoutObjectDrawingRecorderTestForSlimmingPaintV2 = DisplayItemListPaintTe stForSlimmingPaintV2;
21 LayoutObjectDrawingRecorderTest()
22 : m_layoutView(nullptr)
23 , m_originalSlimmingPaintEnabled(RuntimeEnabledFeatures::slimmingPaintEn abled()) { }
24
25 protected:
26 LayoutView& layoutView() { return *m_layoutView; }
27 DisplayItemList& rootDisplayItemList() { return *layoutView().layer()->graph icsLayerBacking()->displayItemList(); }
28 const DisplayItems& newDisplayItemsBeforeUpdate() { return rootDisplayItemLi st().m_newDisplayItems; }
29
30 private:
31 void SetUp() override
32 {
33 RuntimeEnabledFeatures::setSlimmingPaintEnabled(true);
34
35 RenderingTest::SetUp();
36 enableCompositing();
37
38 m_layoutView = document().view()->layoutView();
39 ASSERT_TRUE(m_layoutView);
40 }
41
42 void TearDown() override
43 {
44 RuntimeEnabledFeatures::setSlimmingPaintEnabled(m_originalSlimmingPaintE nabled);
45 }
46
47 LayoutView* m_layoutView;
48 bool m_originalSlimmingPaintEnabled;
49 };
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 22
87 namespace { 23 namespace {
88 24
89 void drawNothing(GraphicsContext& context, const LayoutView& layoutView, PaintPh ase phase, const LayoutRect& bound) 25 void drawNothing(GraphicsContext& context, const LayoutView& layoutView, PaintPh ase phase, const LayoutRect& bound)
90 { 26 {
91 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, layoutV iew, phase, LayoutPoint())) 27 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, layoutV iew, phase, LayoutPoint()))
92 return; 28 return;
93 29
94 LayoutObjectDrawingRecorder drawingRecorder(context, layoutView, phase, boun d, LayoutPoint()); 30 LayoutObjectDrawingRecorder drawingRecorder(context, layoutView, phase, boun d, LayoutPoint());
95 } 31 }
96 32
97 void drawRect(GraphicsContext& context, LayoutView& layoutView, PaintPhase phase , const LayoutRect& bound) 33 void drawRect(GraphicsContext& context, LayoutView& layoutView, PaintPhase phase , const LayoutRect& bound)
98 { 34 {
99 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, layoutV iew, phase, LayoutPoint())) 35 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, layoutV iew, phase, LayoutPoint()))
100 return; 36 return;
101 LayoutObjectDrawingRecorder drawingRecorder(context, layoutView, phase, boun d, LayoutPoint()); 37 LayoutObjectDrawingRecorder drawingRecorder(context, layoutView, phase, boun d, LayoutPoint());
102 IntRect rect(0, 0, 10, 10); 38 IntRect rect(0, 0, 10, 10);
103 context.drawRect(rect); 39 context.drawRect(rect);
104 } 40 }
105 41
106 bool isDrawing(const DisplayItem& item)
107 {
108 return DisplayItem::isDrawingType(item.type());
109 }
110
111 bool isCached(const DisplayItem& item)
112 {
113 return DisplayItem::isCachedType(item.type());
114 }
115
116 TEST_F(LayoutObjectDrawingRecorderTest, Nothing) 42 TEST_F(LayoutObjectDrawingRecorderTest, Nothing)
117 { 43 {
118 GraphicsContext context(&rootDisplayItemList()); 44 GraphicsContext context(&rootDisplayItemList());
119 LayoutRect bound = layoutView().viewRect(); 45 LayoutRect bound = layoutView().viewRect();
120 EXPECT_EQ((size_t)0, rootDisplayItemList().displayItems().size()); 46 EXPECT_EQ((size_t)0, rootDisplayItemList().displayItems().size());
121 47
122 drawNothing(context, layoutView(), PaintPhaseForeground, bound); 48 drawNothing(context, layoutView(), PaintPhaseForeground, bound);
123 rootDisplayItemList().commitNewDisplayItems(); 49 rootDisplayItemList().commitNewDisplayItems();
124 EXPECT_EQ((size_t)1, rootDisplayItemList().displayItems().size()); 50 EXPECT_DISPLAY_LIST_BASE(rootDisplayItemList().displayItems(), 1,
125 const auto& item = rootDisplayItemList().displayItems()[0]; 51 TestDisplayItem(layoutView(), DisplayItem::paintPhaseToDrawingType(Paint PhaseForeground)));
126 ASSERT_TRUE(isDrawing(item)); 52 EXPECT_FALSE(static_cast<const DrawingDisplayItem&>(rootDisplayItemList().di splayItems()[0]).picture());
127 EXPECT_FALSE(static_cast<const DrawingDisplayItem&>(item).picture());
128 } 53 }
129 54
130 TEST_F(LayoutObjectDrawingRecorderTest, Rect) 55 TEST_F(LayoutObjectDrawingRecorderTest, Rect)
131 { 56 {
132 GraphicsContext context(&rootDisplayItemList()); 57 GraphicsContext context(&rootDisplayItemList());
133 LayoutRect bound = layoutView().viewRect(); 58 LayoutRect bound = layoutView().viewRect();
134 drawRect(context, layoutView(), PaintPhaseForeground, bound); 59 drawRect(context, layoutView(), PaintPhaseForeground, bound);
135 rootDisplayItemList().commitNewDisplayItems(); 60 rootDisplayItemList().commitNewDisplayItems();
136 EXPECT_EQ((size_t)1, rootDisplayItemList().displayItems().size()); 61 EXPECT_DISPLAY_LIST_BASE(rootDisplayItemList().displayItems(), 1,
137 EXPECT_TRUE(isDrawing(rootDisplayItemList().displayItems()[0])); 62 TestDisplayItem(layoutView(), DisplayItem::paintPhaseToDrawingType(Paint PhaseForeground)));
138 } 63 }
139 64
140 TEST_F(LayoutObjectDrawingRecorderTest, Cached) 65 TEST_F(LayoutObjectDrawingRecorderTest, Cached)
141 { 66 {
142 GraphicsContext context(&rootDisplayItemList()); 67 GraphicsContext context(&rootDisplayItemList());
143 LayoutRect bound = layoutView().viewRect(); 68 LayoutRect bound = layoutView().viewRect();
144 drawNothing(context, layoutView(), PaintPhaseBlockBackground, bound); 69 drawNothing(context, layoutView(), PaintPhaseBlockBackground, bound);
145 drawRect(context, layoutView(), PaintPhaseForeground, bound); 70 drawRect(context, layoutView(), PaintPhaseForeground, bound);
146 rootDisplayItemList().commitNewDisplayItems(); 71 rootDisplayItemList().commitNewDisplayItems();
147 EXPECT_EQ((size_t)2, rootDisplayItemList().displayItems().size()); 72
148 EXPECT_TRUE(isDrawing(rootDisplayItemList().displayItems()[0])); 73 EXPECT_DISPLAY_LIST_BASE(rootDisplayItemList().displayItems(), 2,
149 EXPECT_TRUE(isDrawing(rootDisplayItemList().displayItems()[1])); 74 TestDisplayItem(layoutView(), DisplayItem::paintPhaseToDrawingType(Paint PhaseBlockBackground)),
75 TestDisplayItem(layoutView(), DisplayItem::paintPhaseToDrawingType(Paint PhaseForeground)));
150 76
151 drawNothing(context, layoutView(), PaintPhaseBlockBackground, bound); 77 drawNothing(context, layoutView(), PaintPhaseBlockBackground, bound);
152 drawRect(context, layoutView(), PaintPhaseForeground, bound); 78 drawRect(context, layoutView(), PaintPhaseForeground, bound);
153 EXPECT_EQ((size_t)2, newDisplayItemsBeforeUpdate().size()); 79
154 EXPECT_TRUE(isCached(newDisplayItemsBeforeUpdate()[0])); 80 EXPECT_DISPLAY_LIST_BASE(rootDisplayItemList().newDisplayItems(), 2,
155 EXPECT_TRUE(isCached(newDisplayItemsBeforeUpdate()[1])); 81 TestDisplayItem(layoutView(), DisplayItem::drawingTypeToCachedDrawingTyp e(DisplayItem::paintPhaseToDrawingType(PaintPhaseBlockBackground))),
82 TestDisplayItem(layoutView(), DisplayItem::drawingTypeToCachedDrawingTyp e(DisplayItem::paintPhaseToDrawingType(PaintPhaseForeground))));
83
156 rootDisplayItemList().commitNewDisplayItems(); 84 rootDisplayItemList().commitNewDisplayItems();
157 EXPECT_EQ((size_t)2, rootDisplayItemList().displayItems().size()); 85
158 EXPECT_TRUE(isDrawing(rootDisplayItemList().displayItems()[0])); 86 EXPECT_DISPLAY_LIST_BASE(rootDisplayItemList().displayItems(), 2,
159 EXPECT_TRUE(isDrawing(rootDisplayItemList().displayItems()[1])); 87 TestDisplayItem(layoutView(), DisplayItem::paintPhaseToDrawingType(Paint PhaseBlockBackground)),
88 TestDisplayItem(layoutView(), DisplayItem::paintPhaseToDrawingType(Paint PhaseForeground)));
160 } 89 }
161 90
162 template <typename T> 91 template <typename T>
163 FloatRect drawAndGetCullRect(DisplayItemList& list, const LayoutObject& layoutOb ject, const T& bounds) 92 FloatRect drawAndGetCullRect(DisplayItemList& list, const LayoutObject& layoutOb ject, const T& bounds)
164 { 93 {
165 list.invalidateAll(); 94 list.invalidateAll();
166 { 95 {
167 // Draw some things which will produce a non-null picture. 96 // Draw some things which will produce a non-null picture.
168 GraphicsContext context(&list); 97 GraphicsContext context(&list);
169 LayoutObjectDrawingRecorder recorder( 98 LayoutObjectDrawingRecorder recorder(
(...skipping 28 matching lines...) Expand all
198 127
199 rootDisplayItemList().invalidateAll(); 128 rootDisplayItemList().invalidateAll();
200 EXPECT_FALSE(LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context , layoutView(), PaintPhaseForeground, paintOffset)); 129 EXPECT_FALSE(LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context , layoutView(), PaintPhaseForeground, paintOffset));
201 { 130 {
202 LayoutObjectDrawingRecorder drawingRecorder(context, layoutView(), Paint PhaseForeground, bounds, paintOffset); 131 LayoutObjectDrawingRecorder drawingRecorder(context, layoutView(), Paint PhaseForeground, bounds, paintOffset);
203 IntRect rect(0, 0, 10, 10); 132 IntRect rect(0, 0, 10, 10);
204 context.drawRect(rect); 133 context.drawRect(rect);
205 } 134 }
206 135
207 rootDisplayItemList().commitNewDisplayItems(); 136 rootDisplayItemList().commitNewDisplayItems();
208 EXPECT_EQ((size_t)1, rootDisplayItemList().displayItems().size()); 137 EXPECT_DISPLAY_LIST_BASE(rootDisplayItemList().displayItems(), 1,
209 EXPECT_TRUE(isDrawing(rootDisplayItemList().displayItems()[0])); 138 TestDisplayItem(layoutView(), DisplayItem::paintPhaseToDrawingType(Paint PhaseForeground)));
210 139
211 // Ensure we cannot use the cache with a new paint offset. 140 // Ensure we cannot use the cache with a new paint offset.
212 LayoutPoint newPaintOffset(2, 3); 141 LayoutPoint newPaintOffset(2, 3);
213 EXPECT_FALSE(LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context , layoutView(), PaintPhaseForeground, newPaintOffset)); 142 EXPECT_FALSE(LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context , layoutView(), PaintPhaseForeground, newPaintOffset));
214 143
215 // Test that a new paint offset is recorded. 144 // Test that a new paint offset is recorded.
216 { 145 {
217 LayoutObjectDrawingRecorder drawingRecorder(context, layoutView(), Paint PhaseForeground, bounds, newPaintOffset); 146 LayoutObjectDrawingRecorder drawingRecorder(context, layoutView(), Paint PhaseForeground, bounds, newPaintOffset);
218 IntRect rect(0, 0, 10, 10); 147 IntRect rect(0, 0, 10, 10);
219 context.drawRect(rect); 148 context.drawRect(rect);
220 } 149 }
221 150
222 rootDisplayItemList().commitNewDisplayItems(); 151 rootDisplayItemList().commitNewDisplayItems();
223 EXPECT_EQ((size_t)1, rootDisplayItemList().displayItems().size()); 152 EXPECT_DISPLAY_LIST_BASE(rootDisplayItemList().displayItems(), 1,
224 EXPECT_TRUE(isDrawing(rootDisplayItemList().displayItems()[0])); 153 TestDisplayItem(layoutView(), DisplayItem::paintPhaseToDrawingType(Paint PhaseForeground)));
225 154
226 // Ensure the old paint offset cannot be used. 155 // Ensure the old paint offset cannot be used.
227 EXPECT_FALSE(LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context , layoutView(), PaintPhaseForeground, paintOffset)); 156 EXPECT_FALSE(LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context , layoutView(), PaintPhaseForeground, paintOffset));
228 157
229 // Ensure the new paint offset can be used. 158 // Ensure the new paint offset can be used.
230 EXPECT_TRUE(LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, layoutView(), PaintPhaseForeground, newPaintOffset)); 159 EXPECT_TRUE(LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, layoutView(), PaintPhaseForeground, newPaintOffset));
231 rootDisplayItemList().commitNewDisplayItems(); 160 rootDisplayItemList().commitNewDisplayItems();
232 EXPECT_EQ((size_t)1, rootDisplayItemList().displayItems().size()); 161 EXPECT_DISPLAY_LIST_BASE(rootDisplayItemList().displayItems(), 1,
233 EXPECT_TRUE(isDrawing(rootDisplayItemList().displayItems()[0])); 162 TestDisplayItem(layoutView(), DisplayItem::paintPhaseToDrawingType(Paint PhaseForeground)));
234 } 163 }
235 164
236 } // namespace 165 } // namespace
237 } // namespace blink 166 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/paint/DisplayItemListPaintTest.cpp ('k') | Source/platform/graphics/paint/DisplayItemList.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698