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

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

Issue 1287093004: Slimming Paint phase 2 compositing algorithm plumbing (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Update per reviewer comments. Still need to find a home for the Transform Tree. Created 5 years, 4 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 "platform/graphics/paint/DisplayItemList.h" 6 #include "platform/graphics/paint/DisplayItemList.h"
7 7
8 #include "core/layout/LayoutTestHelper.h" 8 #include "core/layout/LayoutTestHelper.h"
9 #include "core/layout/LayoutText.h" 9 #include "core/layout/LayoutText.h"
10 #include "core/layout/LayoutView.h" 10 #include "core/layout/LayoutView.h"
11 #include "core/layout/line/InlineTextBox.h" 11 #include "core/layout/line/InlineTextBox.h"
12 #include "core/page/FocusController.h" 12 #include "core/page/FocusController.h"
13 #include "core/paint/DeprecatedPaintLayer.h" 13 #include "core/paint/DeprecatedPaintLayer.h"
14 #include "core/paint/DeprecatedPaintLayerPainter.h" 14 #include "core/paint/DeprecatedPaintLayerPainter.h"
15 #include "core/paint/LayerClipRecorder.h" 15 #include "core/paint/LayerClipRecorder.h"
16 #include "core/paint/LayoutObjectDrawingRecorder.h" 16 #include "core/paint/LayoutObjectDrawingRecorder.h"
17 #include "core/paint/ScopeRecorder.h" 17 #include "core/paint/ScopeRecorder.h"
18 #include "core/paint/SubtreeRecorder.h" 18 #include "core/paint/SubtreeRecorder.h"
19 #include "platform/graphics/GraphicsContext.h" 19 #include "platform/graphics/GraphicsContext.h"
20 #include "platform/graphics/GraphicsLayer.h" 20 #include "platform/graphics/GraphicsLayer.h"
21 #include "platform/graphics/paint/DrawingDisplayItem.h" 21 #include "platform/graphics/paint/DrawingDisplayItem.h"
22 #include <gtest/gtest.h> 22 #include <gtest/gtest.h>
23 23
24 namespace blink { 24 namespace blink {
25 25
26 class DisplayItemListPaintTest : public RenderingTest { 26 class DisplayItemListPaintTest : public RenderingTest {
27 public: 27 public:
28 DisplayItemListPaintTest() 28 DisplayItemListPaintTest()
29 : m_layoutView(nullptr) 29 : m_layoutView(nullptr)
30 , m_originalSlimmingPaintEnabled(RuntimeEnabledFeatures::slimmingPaintEn abled()) { }
31
32 protected:
33 LayoutView& layoutView() { return *m_layoutView; }
34 DisplayItemList& rootDisplayItemList() { return *layoutView().layer()->graph icsLayerBacking()->displayItemList(); }
35 const DisplayItems& newPaintListBeforeUpdate() { return rootDisplayItemList( ).m_newDisplayItems; }
36
37 private:
38 void SetUp() override
39 {
40 RuntimeEnabledFeatures::setSlimmingPaintEnabled(true);
41
42 RenderingTest::SetUp();
43 enableCompositing();
44
45 m_layoutView = document().view()->layoutView();
46 ASSERT_TRUE(m_layoutView);
47 }
48
49 void TearDown() override
50 {
51 RuntimeEnabledFeatures::setSlimmingPaintEnabled(m_originalSlimmingPaintE nabled);
52 }
53
54 LayoutView* m_layoutView;
55 bool m_originalSlimmingPaintEnabled;
56 };
57
58 // Slimming paint v2 has subtly different behavior on some paint tests. This
59 // class is used to test only v2 behavior while maintaining v1 test coverage.
60 class DisplayItemListPaintTestForSlimmingPaintV2 : public RenderingTest {
61 public:
62 DisplayItemListPaintTestForSlimmingPaintV2()
63 : m_layoutView(nullptr)
30 , m_originalSlimmingPaintV2Enabled(RuntimeEnabledFeatures::slimmingPaint V2Enabled()) { } 64 , m_originalSlimmingPaintV2Enabled(RuntimeEnabledFeatures::slimmingPaint V2Enabled()) { }
31 65
32 protected: 66 protected:
33 LayoutView& layoutView() { return *m_layoutView; } 67 LayoutView& layoutView() { return *m_layoutView; }
34 DisplayItemList& rootDisplayItemList() { return *layoutView().layer()->graph icsLayerBacking()->displayItemList(); } 68 DisplayItemList& rootDisplayItemList() { return *layoutView().layer()->graph icsLayerBacking()->displayItemList(); }
35 const DisplayItems& newPaintListBeforeUpdate() { return rootDisplayItemList( ).m_newDisplayItems; } 69 const DisplayItems& newPaintListBeforeUpdate() { return rootDisplayItemList( ).m_newDisplayItems; }
36 70
37 private: 71 private:
38 void SetUp() override 72 void SetUp() override
39 { 73 {
(...skipping 25 matching lines...) Expand all
65 }; 99 };
66 100
67 #ifndef NDEBUG 101 #ifndef NDEBUG
68 #define TRACE_DISPLAY_ITEMS(i, expected, actual) \ 102 #define TRACE_DISPLAY_ITEMS(i, expected, actual) \
69 String trace = String::format("%d: ", (int)i) + "Expected: " + (expected).as DebugString() + " Actual: " + (actual).asDebugString(); \ 103 String trace = String::format("%d: ", (int)i) + "Expected: " + (expected).as DebugString() + " Actual: " + (actual).asDebugString(); \
70 SCOPED_TRACE(trace.utf8().data()); 104 SCOPED_TRACE(trace.utf8().data());
71 #else 105 #else
72 #define TRACE_DISPLAY_ITEMS(i, expected, actual) 106 #define TRACE_DISPLAY_ITEMS(i, expected, actual)
73 #endif 107 #endif
74 108
75 #define EXPECT_DISPLAY_LIST(actual, expectedSize, ...) \ 109 #define EXPECT_DISPLAY_LIST_BASE(actual, expectedSize, ...) \
76 do { \ 110 do { \
77 EXPECT_EQ((size_t)expectedSize, actual.size()); \ 111 EXPECT_EQ((size_t)expectedSize, actual.size()); \
78 if (expectedSize != actual.size()) \ 112 if (expectedSize != actual.size()) \
79 break; \ 113 break; \
80 const TestDisplayItem expected[] = { __VA_ARGS__ }; \ 114 const TestDisplayItem expected[] = { __VA_ARGS__ }; \
81 for (size_t index = 0; index < std::min<size_t>(actual.size(), expectedS ize); index++) { \ 115 for (size_t index = 0; index < std::min<size_t>(actual.size(), expectedS ize); index++) { \
82 TRACE_DISPLAY_ITEMS(index, expected[index], actual[index]); \ 116 TRACE_DISPLAY_ITEMS(index, expected[index], actual[index]); \
83 EXPECT_EQ(expected[index].client(), actual[index].client()); \ 117 EXPECT_EQ(expected[index].client(), actual[index].client()); \
84 EXPECT_EQ(expected[index].type(), actual[index].type()); \ 118 EXPECT_EQ(expected[index].type(), actual[index].type()); \
85 } \ 119 } \
86 } while (false); 120 } while (false);
87 121
122 #ifndef NDEBUG
123 #define EXPECT_DISPLAY_LIST_WITH_RED_FILL_IN_DEBUG(actual, expectedSizeWithoutFi ll, ...) \
124 EXPECT_DISPLAY_LIST_BASE( \
125 actual, expectedSizeWithoutFill + 1, \
126 TestDisplayItem(*document().layoutView()->layer()->graphicsLayerBacking( ), DisplayItem::DebugRedFill), \
127 __VA_ARGS__)
128 #else
129 #define EXPECT_DISPLAY_LIST_WITH_RED_FILL_IN_DEBUG EXPECT_DISPLAY_LIST_BASE
130 #endif
131
88 TEST_F(DisplayItemListPaintTest, FullDocumentPaintingWithCaret) 132 TEST_F(DisplayItemListPaintTest, FullDocumentPaintingWithCaret)
89 { 133 {
90 setBodyInnerHTML("<div id='div' contentEditable='true' style='outline:none'> XYZ</div>"); 134 setBodyInnerHTML("<div id='div' contentEditable='true' style='outline:none'> XYZ</div>");
91 document().page()->focusController().setActive(true); 135 document().page()->focusController().setActive(true);
92 document().page()->focusController().setFocused(true); 136 document().page()->focusController().setFocused(true);
93 LayoutView& layoutView = *document().layoutView(); 137 LayoutView& layoutView = *document().layoutView();
94 DeprecatedPaintLayer& rootLayer = *layoutView.layer(); 138 DeprecatedPaintLayer& rootLayer = *layoutView.layer();
95 Element& div = *toElement(document().body()->firstChild()); 139 Element& div = *toElement(document().body()->firstChild());
96 LayoutObject& divLayoutObject = *document().body()->firstChild()->layoutObje ct(); 140 LayoutObject& divLayoutObject = *document().body()->firstChild()->layoutObje ct();
97 InlineTextBox& textInlineBox = *toLayoutText(div.firstChild()->layoutObject( ))->firstTextBox(); 141 InlineTextBox& textInlineBox = *toLayoutText(div.firstChild()->layoutObject( ))->firstTextBox();
98 142
99 GraphicsContext context(&rootDisplayItemList()); 143 GraphicsContext context(&rootDisplayItemList());
100 DeprecatedPaintLayerPaintingInfo paintingInfo(&rootLayer, LayoutRect(0, 0, 8 00, 600), GlobalPaintNormalPhase, LayoutSize()); 144 DeprecatedPaintLayerPaintingInfo paintingInfo(&rootLayer, LayoutRect(0, 0, 8 00, 600), GlobalPaintNormalPhase, LayoutSize());
101 DeprecatedPaintLayerPainter(rootLayer).paintLayerContents(&context, painting Info, PaintLayerPaintingCompositingAllPhases); 145 DeprecatedPaintLayerPainter(rootLayer).paintLayerContents(&context, painting Info, PaintLayerPaintingCompositingAllPhases);
102 rootDisplayItemList().commitNewDisplayItems(); 146 rootDisplayItemList().commitNewDisplayItems();
103 147
104 EXPECT_DISPLAY_LIST(rootDisplayItemList().displayItems(), 2, 148 EXPECT_DISPLAY_LIST_BASE(rootDisplayItemList().displayItems(), 2,
105 TestDisplayItem(layoutView, DisplayItem::BoxDecorationBackground), 149 TestDisplayItem(layoutView, DisplayItem::BoxDecorationBackground),
106 TestDisplayItem(textInlineBox, DisplayItem::paintPhaseToDrawingType(Pain tPhaseForeground))); 150 TestDisplayItem(textInlineBox, DisplayItem::paintPhaseToDrawingType(Pain tPhaseForeground)));
107 151
108 div.focus(); 152 div.focus();
109 document().view()->updateAllLifecyclePhases(); 153 document().view()->updateAllLifecyclePhases();
110 EXPECT_TRUE(rootDisplayItemList().clientCacheIsValid(layoutView.displayItemC lient())); 154 EXPECT_TRUE(rootDisplayItemList().clientCacheIsValid(layoutView.displayItemC lient()));
111 EXPECT_FALSE(rootDisplayItemList().clientCacheIsValid(divLayoutObject.displa yItemClient())); 155 EXPECT_FALSE(rootDisplayItemList().clientCacheIsValid(divLayoutObject.displa yItemClient()));
112 EXPECT_TRUE(rootDisplayItemList().clientCacheIsValid(textInlineBox.displayIt emClient())); 156 EXPECT_TRUE(rootDisplayItemList().clientCacheIsValid(textInlineBox.displayIt emClient()));
113 DeprecatedPaintLayerPainter(rootLayer).paintLayerContents(&context, painting Info, PaintLayerPaintingCompositingAllPhases); 157 DeprecatedPaintLayerPainter(rootLayer).paintLayerContents(&context, painting Info, PaintLayerPaintingCompositingAllPhases);
114 rootDisplayItemList().commitNewDisplayItems(); 158 rootDisplayItemList().commitNewDisplayItems();
115 159
116 EXPECT_DISPLAY_LIST(rootDisplayItemList().displayItems(), 3, 160 EXPECT_DISPLAY_LIST_BASE(rootDisplayItemList().displayItems(), 3,
117 TestDisplayItem(layoutView, DisplayItem::BoxDecorationBackground), 161 TestDisplayItem(layoutView, DisplayItem::BoxDecorationBackground),
118 TestDisplayItem(textInlineBox, DisplayItem::paintPhaseToDrawingType(Pain tPhaseForeground)), 162 TestDisplayItem(textInlineBox, DisplayItem::paintPhaseToDrawingType(Pain tPhaseForeground)),
119 TestDisplayItem(divLayoutObject, DisplayItem::Caret)); // New! 163 TestDisplayItem(divLayoutObject, DisplayItem::Caret)); // New!
120 } 164 }
121 165
122 TEST_F(DisplayItemListPaintTest, InlineRelayout) 166 TEST_F(DisplayItemListPaintTest, InlineRelayout)
123 { 167 {
124 setBodyInnerHTML("<div id='div' style='width:100px; height: 200px'>AAAAAAAAA A BBBBBBBBBB</div>"); 168 setBodyInnerHTML("<div id='div' style='width:100px; height: 200px'>AAAAAAAAA A BBBBBBBBBB</div>");
125 LayoutView& layoutView = *document().layoutView(); 169 LayoutView& layoutView = *document().layoutView();
126 DeprecatedPaintLayer& rootLayer = *layoutView.layer(); 170 DeprecatedPaintLayer& rootLayer = *layoutView.layer();
127 Element& div = *toElement(document().body()->firstChild()); 171 Element& div = *toElement(document().body()->firstChild());
128 LayoutBlock& divBlock = *toLayoutBlock(document().body()->firstChild()->layo utObject()); 172 LayoutBlock& divBlock = *toLayoutBlock(document().body()->firstChild()->layo utObject());
129 LayoutText& text = *toLayoutText(divBlock.firstChild()); 173 LayoutText& text = *toLayoutText(divBlock.firstChild());
130 InlineTextBox& firstTextBox = *text.firstTextBox(); 174 InlineTextBox& firstTextBox = *text.firstTextBox();
131 DisplayItemClient firstTextBoxDisplayItemClient = firstTextBox.displayItemCl ient(); 175 DisplayItemClient firstTextBoxDisplayItemClient = firstTextBox.displayItemCl ient();
132 176
133 GraphicsContext context(&rootDisplayItemList()); 177 GraphicsContext context(&rootDisplayItemList());
134 DeprecatedPaintLayerPaintingInfo paintingInfo(&rootLayer, LayoutRect(0, 0, 8 00, 600), GlobalPaintNormalPhase, LayoutSize()); 178 DeprecatedPaintLayerPaintingInfo paintingInfo(&rootLayer, LayoutRect(0, 0, 8 00, 600), GlobalPaintNormalPhase, LayoutSize());
135 DeprecatedPaintLayerPainter(rootLayer).paintLayerContents(&context, painting Info, PaintLayerPaintingCompositingAllPhases); 179 DeprecatedPaintLayerPainter(rootLayer).paintLayerContents(&context, painting Info, PaintLayerPaintingCompositingAllPhases);
136 rootDisplayItemList().commitNewDisplayItems(); 180 rootDisplayItemList().commitNewDisplayItems();
137 181
138 EXPECT_DISPLAY_LIST(rootDisplayItemList().displayItems(), 2, 182 EXPECT_DISPLAY_LIST_BASE(rootDisplayItemList().displayItems(), 2,
139 TestDisplayItem(layoutView, DisplayItem::BoxDecorationBackground), 183 TestDisplayItem(layoutView, DisplayItem::BoxDecorationBackground),
140 TestDisplayItem(firstTextBox, DisplayItem::paintPhaseToDrawingType(Paint PhaseForeground))); 184 TestDisplayItem(firstTextBox, DisplayItem::paintPhaseToDrawingType(Paint PhaseForeground)));
141 185
142 div.setAttribute(HTMLNames::styleAttr, "width: 10px; height: 200px"); 186 div.setAttribute(HTMLNames::styleAttr, "width: 10px; height: 200px");
143 document().view()->updateAllLifecyclePhases(); 187 document().view()->updateAllLifecyclePhases();
144 EXPECT_TRUE(rootDisplayItemList().clientCacheIsValid(layoutView.displayItemC lient())); 188 EXPECT_TRUE(rootDisplayItemList().clientCacheIsValid(layoutView.displayItemC lient()));
145 EXPECT_FALSE(rootDisplayItemList().clientCacheIsValid(divBlock.displayItemCl ient())); 189 EXPECT_FALSE(rootDisplayItemList().clientCacheIsValid(divBlock.displayItemCl ient()));
146 EXPECT_FALSE(rootDisplayItemList().clientCacheIsValid(firstTextBoxDisplayIte mClient)); 190 EXPECT_FALSE(rootDisplayItemList().clientCacheIsValid(firstTextBoxDisplayIte mClient));
147 DeprecatedPaintLayerPainter(rootLayer).paintLayerContents(&context, painting Info, PaintLayerPaintingCompositingAllPhases); 191 DeprecatedPaintLayerPainter(rootLayer).paintLayerContents(&context, painting Info, PaintLayerPaintingCompositingAllPhases);
148 rootDisplayItemList().commitNewDisplayItems(); 192 rootDisplayItemList().commitNewDisplayItems();
149 193
150 LayoutText& newText = *toLayoutText(divBlock.firstChild()); 194 LayoutText& newText = *toLayoutText(divBlock.firstChild());
151 InlineTextBox& newFirstTextBox = *newText.firstTextBox(); 195 InlineTextBox& newFirstTextBox = *newText.firstTextBox();
152 InlineTextBox& secondTextBox = *newText.firstTextBox()->nextTextBox(); 196 InlineTextBox& secondTextBox = *newText.firstTextBox()->nextTextBox();
153 197
154 EXPECT_DISPLAY_LIST(rootDisplayItemList().displayItems(), 5, 198 EXPECT_DISPLAY_LIST_BASE(rootDisplayItemList().displayItems(), 3,
199 TestDisplayItem(layoutView, DisplayItem::BoxDecorationBackground),
200 TestDisplayItem(newFirstTextBox, DisplayItem::paintPhaseToDrawingType(Pa intPhaseForeground)),
201 TestDisplayItem(secondTextBox, DisplayItem::paintPhaseToDrawingType(Pain tPhaseForeground)));
202 }
203
204 TEST_F(DisplayItemListPaintTestForSlimmingPaintV2, FullDocumentPaintingWithCaret )
205 {
206 setBodyInnerHTML("<div id='div' contentEditable='true' style='outline:none'> XYZ</div>");
207 document().page()->focusController().setActive(true);
208 document().page()->focusController().setFocused(true);
209 LayoutView& layoutView = *document().layoutView();
210 Element& div = *toElement(document().body()->firstChild());
211 LayoutObject& divLayoutObject = *document().body()->firstChild()->layoutObje ct();
212 InlineTextBox& textInlineBox = *toLayoutText(div.firstChild()->layoutObject( ))->firstTextBox();
213
214 document().view()->updateAllLifecyclePhases();
215
216 EXPECT_DISPLAY_LIST_WITH_RED_FILL_IN_DEBUG(rootDisplayItemList().displayItem s(), 2,
217 TestDisplayItem(layoutView, DisplayItem::BoxDecorationBackground),
218 TestDisplayItem(textInlineBox, DisplayItem::paintPhaseToDrawingType(Pain tPhaseForeground)));
219
220 div.focus();
221 document().view()->updateAllLifecyclePhases();
222
223 EXPECT_DISPLAY_LIST_WITH_RED_FILL_IN_DEBUG(rootDisplayItemList().displayItem s(), 3,
224 TestDisplayItem(layoutView, DisplayItem::BoxDecorationBackground),
225 TestDisplayItem(textInlineBox, DisplayItem::paintPhaseToDrawingType(Pain tPhaseForeground)),
226 TestDisplayItem(divLayoutObject, DisplayItem::Caret)); // New!
227 }
228
229 TEST_F(DisplayItemListPaintTestForSlimmingPaintV2, InlineRelayout)
230 {
231 setBodyInnerHTML("<div id='div' style='width:100px; height: 200px'>AAAAAAAAA A BBBBBBBBBB</div>");
232 LayoutView& layoutView = *document().layoutView();
233 Element& div = *toElement(document().body()->firstChild());
234 LayoutBlock& divBlock = *toLayoutBlock(document().body()->firstChild()->layo utObject());
235 LayoutText& text = *toLayoutText(divBlock.firstChild());
236 InlineTextBox& firstTextBox = *text.firstTextBox();
237
238 document().view()->updateAllLifecyclePhases();
239
240 EXPECT_DISPLAY_LIST_WITH_RED_FILL_IN_DEBUG(rootDisplayItemList().displayItem s(), 2,
241 TestDisplayItem(layoutView, DisplayItem::BoxDecorationBackground),
242 TestDisplayItem(firstTextBox, DisplayItem::paintPhaseToDrawingType(Paint PhaseForeground)));
243
244 div.setAttribute(HTMLNames::styleAttr, "width: 10px; height: 200px");
245 document().view()->updateAllLifecyclePhases();
246
247 LayoutText& newText = *toLayoutText(divBlock.firstChild());
248 InlineTextBox& newFirstTextBox = *newText.firstTextBox();
249 InlineTextBox& secondTextBox = *newText.firstTextBox()->nextTextBox();
250
251 EXPECT_DISPLAY_LIST_WITH_RED_FILL_IN_DEBUG(rootDisplayItemList().displayItem s(), 5,
155 TestDisplayItem(layoutView, DisplayItem::BoxDecorationBackground), 252 TestDisplayItem(layoutView, DisplayItem::BoxDecorationBackground),
156 TestDisplayItem(divBlock, DisplayItem::paintPhaseToBeginSubtreeType(Pain tPhaseForeground)), 253 TestDisplayItem(divBlock, DisplayItem::paintPhaseToBeginSubtreeType(Pain tPhaseForeground)),
157 TestDisplayItem(newFirstTextBox, DisplayItem::paintPhaseToDrawingType(Pa intPhaseForeground)), 254 TestDisplayItem(newFirstTextBox, DisplayItem::paintPhaseToDrawingType(Pa intPhaseForeground)),
158 TestDisplayItem(secondTextBox, DisplayItem::paintPhaseToDrawingType(Pain tPhaseForeground)), 255 TestDisplayItem(secondTextBox, DisplayItem::paintPhaseToDrawingType(Pain tPhaseForeground)),
159 TestDisplayItem(divBlock, DisplayItem::paintPhaseToEndSubtreeType(PaintP haseForeground))); 256 TestDisplayItem(divBlock, DisplayItem::paintPhaseToEndSubtreeType(PaintP haseForeground)));
160 } 257 }
161 258
162 } // namespace blink 259 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698