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

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

Powered by Google App Engine
This is Rietveld 408576698