| OLD | NEW |
| 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 "core/paint/DisplayItemListPaintTest.h" |
| 7 | 7 |
| 8 #include "core/layout/LayoutTestHelper.h" | |
| 9 #include "core/layout/LayoutText.h" | 8 #include "core/layout/LayoutText.h" |
| 10 #include "core/layout/LayoutView.h" | |
| 11 #include "core/layout/line/InlineTextBox.h" | 9 #include "core/layout/line/InlineTextBox.h" |
| 12 #include "core/page/FocusController.h" | 10 #include "core/page/FocusController.h" |
| 13 #include "core/paint/DeprecatedPaintLayer.h" | |
| 14 #include "core/paint/DeprecatedPaintLayerPainter.h" | 11 #include "core/paint/DeprecatedPaintLayerPainter.h" |
| 15 #include "core/paint/LayerClipRecorder.h" | 12 #include "core/paint/LayerClipRecorder.h" |
| 16 #include "core/paint/LayoutObjectDrawingRecorder.h" | 13 #include "core/paint/LayoutObjectDrawingRecorder.h" |
| 17 #include "core/paint/ScopeRecorder.h" | 14 #include "core/paint/ScopeRecorder.h" |
| 18 #include "platform/graphics/GraphicsContext.h" | 15 #include "platform/graphics/GraphicsContext.h" |
| 19 #include "platform/graphics/GraphicsLayer.h" | |
| 20 #include "platform/graphics/paint/DrawingDisplayItem.h" | 16 #include "platform/graphics/paint/DrawingDisplayItem.h" |
| 21 #include <gtest/gtest.h> | |
| 22 | 17 |
| 23 namespace blink { | 18 namespace blink { |
| 24 | 19 |
| 25 class DisplayItemListPaintTest : public RenderingTest { | |
| 26 public: | |
| 27 DisplayItemListPaintTest() | |
| 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& newDisplayItemsBeforeUpdate() { return rootDisplayItemLi
st().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) | |
| 63 , m_originalSlimmingPaintV2Enabled(RuntimeEnabledFeatures::slimmingPaint
V2Enabled()) { } | |
| 64 | |
| 65 protected: | |
| 66 LayoutView& layoutView() { return *m_layoutView; } | |
| 67 DisplayItemList& rootDisplayItemList() { return *layoutView().layer()->graph
icsLayerBacking()->displayItemList(); } | |
| 68 const DisplayItems& newDisplayItemsBeforeUpdate() { return rootDisplayItemLi
st().m_newDisplayItems; } | |
| 69 | |
| 70 // Expose some document lifecycle steps for checking new display items befor
e commiting. | |
| 71 void updateLifecyclePhasesToPaintForSlimmingPaintV2Clean() | |
| 72 { | |
| 73 document().view()->updateLifecyclePhasesInternal(FrameView::OnlyUpToComp
ositingCleanPlusScrolling); | |
| 74 document().view()->invalidateTreeIfNeededRecursive(); | |
| 75 document().view()->paintForSlimmingPaintV2(); | |
| 76 } | |
| 77 void compositeForSlimmingPaintV2() { document().view()->compositeForSlimming
PaintV2(); } | |
| 78 | |
| 79 private: | |
| 80 void SetUp() override | |
| 81 { | |
| 82 ASSERT_TRUE(RuntimeEnabledFeatures::slimmingPaintEnabled()); | |
| 83 RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(true); | |
| 84 | |
| 85 RenderingTest::SetUp(); | |
| 86 enableCompositing(); | |
| 87 | |
| 88 m_layoutView = document().view()->layoutView(); | |
| 89 ASSERT_TRUE(m_layoutView); | |
| 90 } | |
| 91 | |
| 92 void TearDown() override | |
| 93 { | |
| 94 RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(m_originalSlimmingPain
tV2Enabled); | |
| 95 } | |
| 96 | |
| 97 LayoutView* m_layoutView; | |
| 98 bool m_originalSlimmingPaintV2Enabled; | |
| 99 }; | |
| 100 | |
| 101 class TestDisplayItem final : public DisplayItem { | |
| 102 public: | |
| 103 TestDisplayItem(const DisplayItemClientWrapper& client, Type type) : Display
Item(client, type, sizeof(*this)) { } | |
| 104 | |
| 105 void replay(GraphicsContext&) final { ASSERT_NOT_REACHED(); } | |
| 106 void appendToWebDisplayItemList(WebDisplayItemList*) const final { ASSERT_NO
T_REACHED(); } | |
| 107 }; | |
| 108 | |
| 109 #ifndef NDEBUG | |
| 110 #define TRACE_DISPLAY_ITEMS(i, expected, actual) \ | |
| 111 String trace = String::format("%d: ", (int)i) + "Expected: " + (expected).as
DebugString() + " Actual: " + (actual).asDebugString(); \ | |
| 112 SCOPED_TRACE(trace.utf8().data()); | |
| 113 #else | |
| 114 #define TRACE_DISPLAY_ITEMS(i, expected, actual) | |
| 115 #endif | |
| 116 | |
| 117 #define EXPECT_DISPLAY_LIST_BASE(actual, expectedSize, ...) \ | |
| 118 do { \ | |
| 119 EXPECT_EQ((size_t)expectedSize, actual.size()); \ | |
| 120 if (expectedSize != actual.size()) \ | |
| 121 break; \ | |
| 122 const TestDisplayItem expected[] = { __VA_ARGS__ }; \ | |
| 123 for (size_t index = 0; index < std::min<size_t>(actual.size(), expectedS
ize); index++) { \ | |
| 124 TRACE_DISPLAY_ITEMS(index, expected[index], actual[index]); \ | |
| 125 EXPECT_EQ(expected[index].client(), actual[index].client()); \ | |
| 126 EXPECT_EQ(expected[index].type(), actual[index].type()); \ | |
| 127 } \ | |
| 128 } while (false); | |
| 129 | |
| 130 #ifndef NDEBUG | |
| 131 #define EXPECT_DISPLAY_LIST_WITH_RED_FILL_IN_DEBUG(actual, expectedSizeWithoutFi
ll, ...) \ | |
| 132 EXPECT_DISPLAY_LIST_BASE( \ | |
| 133 actual, expectedSizeWithoutFill + 1, \ | |
| 134 TestDisplayItem(*document().layoutView()->layer()->graphicsLayerBacking(
), DisplayItem::DebugRedFill), \ | |
| 135 __VA_ARGS__) | |
| 136 #define EXPECT_DISPLAY_LIST_WITH_CACHED_RED_FILL_IN_DEBUG(actual, expectedSizeWi
thoutFill, ...) \ | |
| 137 EXPECT_DISPLAY_LIST_BASE( \ | |
| 138 actual, expectedSizeWithoutFill + 1, \ | |
| 139 TestDisplayItem(*document().layoutView()->layer()->graphicsLayerBacking(
), DisplayItem::drawingTypeToCachedDrawingType(DisplayItem::DebugRedFill)), \ | |
| 140 __VA_ARGS__) | |
| 141 #else | |
| 142 #define EXPECT_DISPLAY_LIST_WITH_RED_FILL_IN_DEBUG EXPECT_DISPLAY_LIST_BASE | |
| 143 #define EXPECT_DISPLAY_LIST_WITH_CACHED_RED_FILL_IN_DEBUG EXPECT_DISPLAY_LIST_BA
SE | |
| 144 #endif | |
| 145 | |
| 146 TEST_F(DisplayItemListPaintTest, FullDocumentPaintingWithCaret) | 20 TEST_F(DisplayItemListPaintTest, FullDocumentPaintingWithCaret) |
| 147 { | 21 { |
| 148 setBodyInnerHTML("<div id='div' contentEditable='true' style='outline:none'>
XYZ</div>"); | 22 setBodyInnerHTML("<div id='div' contentEditable='true' style='outline:none'>
XYZ</div>"); |
| 149 document().page()->focusController().setActive(true); | 23 document().page()->focusController().setActive(true); |
| 150 document().page()->focusController().setFocused(true); | 24 document().page()->focusController().setFocused(true); |
| 151 LayoutView& layoutView = *document().layoutView(); | 25 LayoutView& layoutView = *document().layoutView(); |
| 152 DeprecatedPaintLayer& rootLayer = *layoutView.layer(); | 26 DeprecatedPaintLayer& rootLayer = *layoutView.layer(); |
| 153 Element& div = *toElement(document().body()->firstChild()); | 27 Element& div = *toElement(document().body()->firstChild()); |
| 154 LayoutObject& divLayoutObject = *document().body()->firstChild()->layoutObje
ct(); | 28 LayoutObject& divLayoutObject = *document().body()->firstChild()->layoutObje
ct(); |
| 155 InlineTextBox& textInlineBox = *toLayoutText(div.firstChild()->layoutObject(
))->firstTextBox(); | 29 InlineTextBox& textInlineBox = *toLayoutText(div.firstChild()->layoutObject(
))->firstTextBox(); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 TestDisplayItem(content1, DisplayItem::BoxDecorationBackground), | 208 TestDisplayItem(content1, DisplayItem::BoxDecorationBackground), |
| 335 TestDisplayItem(container1Layer, DisplayItem::EndSubsequence), | 209 TestDisplayItem(container1Layer, DisplayItem::EndSubsequence), |
| 336 TestDisplayItem(container2Layer, DisplayItem::BeginSubsequence), | 210 TestDisplayItem(container2Layer, DisplayItem::BeginSubsequence), |
| 337 TestDisplayItem(container2, DisplayItem::BoxDecorationBackground), | 211 TestDisplayItem(container2, DisplayItem::BoxDecorationBackground), |
| 338 TestDisplayItem(content2, DisplayItem::BoxDecorationBackground), | 212 TestDisplayItem(content2, DisplayItem::BoxDecorationBackground), |
| 339 TestDisplayItem(container2Layer, DisplayItem::EndSubsequence), | 213 TestDisplayItem(container2Layer, DisplayItem::EndSubsequence), |
| 340 TestDisplayItem(htmlLayer, DisplayItem::EndSubsequence)); | 214 TestDisplayItem(htmlLayer, DisplayItem::EndSubsequence)); |
| 341 } | 215 } |
| 342 | 216 |
| 343 } // namespace blink | 217 } // namespace blink |
| OLD | NEW |