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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/paint/LayoutObjectDrawingRecorder.h ('k') | Source/core/paint/ListMarkerPainter.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/paint/LayoutObjectDrawingRecorderTest.cpp
diff --git a/Source/core/paint/LayoutObjectDrawingRecorderTest.cpp b/Source/core/paint/LayoutObjectDrawingRecorderTest.cpp
index 021bb763d4a9e19859f6b0428fd86da0548c8521..4539c20e77996a19cff8c43bd8fbac4ecde5f310 100644
--- a/Source/core/paint/LayoutObjectDrawingRecorderTest.cpp
+++ b/Source/core/paint/LayoutObjectDrawingRecorderTest.cpp
@@ -48,21 +48,57 @@ private:
bool m_originalSlimmingPaintEnabled;
};
+class LayoutObjectDrawingRecorderTestForSlimmingPaintV2 : public RenderingTest {
+public:
+ LayoutObjectDrawingRecorderTestForSlimmingPaintV2()
+ : m_layoutView(nullptr)
+ , m_originalSlimmingPaintEnabled(RuntimeEnabledFeatures::slimmingPaintEnabled())
+ , m_originalSlimmingPaintV2Enabled(RuntimeEnabledFeatures::slimmingPaintV2Enabled()) { }
+
+protected:
+ LayoutView& layoutView() { return *m_layoutView; }
+ DisplayItemList& rootDisplayItemList() { return *layoutView().layer()->graphicsLayerBacking()->displayItemList(); }
+ const DisplayItems& newDisplayItemsBeforeUpdate() { return rootDisplayItemList().m_newDisplayItems; }
+
+private:
+ void SetUp() override
+ {
+ RuntimeEnabledFeatures::setSlimmingPaintEnabled(true);
+ RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(true);
+
+ RenderingTest::SetUp();
+ enableCompositing();
+
+ m_layoutView = document().view()->layoutView();
+ ASSERT_TRUE(m_layoutView);
+ }
+
+ void TearDown() override
+ {
+ RuntimeEnabledFeatures::setSlimmingPaintEnabled(m_originalSlimmingPaintV2Enabled);
+ RuntimeEnabledFeatures::setSlimmingPaintEnabled(m_originalSlimmingPaintEnabled);
+ }
+
+ LayoutView* m_layoutView;
+ bool m_originalSlimmingPaintEnabled;
+ bool m_originalSlimmingPaintV2Enabled;
+};
+
namespace {
void drawNothing(GraphicsContext& context, const LayoutView& layoutView, PaintPhase phase, const LayoutRect& bound)
{
- if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, layoutView, phase))
+ if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, layoutView, phase, LayoutPoint()))
return;
- LayoutObjectDrawingRecorder drawingRecorder(context, layoutView, phase, bound);
+ LayoutObjectDrawingRecorder drawingRecorder(context, layoutView, phase, bound, LayoutPoint());
}
void drawRect(GraphicsContext& context, LayoutView& layoutView, PaintPhase phase, const LayoutRect& bound)
{
- if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, layoutView, phase))
+ if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, layoutView, phase, LayoutPoint()))
return;
- LayoutObjectDrawingRecorder drawingRecorder(context, layoutView, phase, bound);
+ LayoutObjectDrawingRecorder drawingRecorder(context, layoutView, phase, bound, LayoutPoint());
IntRect rect(0, 0, 10, 10);
context.drawRect(rect);
}
@@ -131,7 +167,7 @@ FloatRect drawAndGetCullRect(DisplayItemList& list, const LayoutObject& layoutOb
// Draw some things which will produce a non-null picture.
GraphicsContext context(&list);
LayoutObjectDrawingRecorder recorder(
- context, layoutObject, DisplayItem::BoxDecorationBackground, bounds);
+ context, layoutObject, DisplayItem::BoxDecorationBackground, bounds, LayoutPoint());
context.drawRect(enclosedIntRect(FloatRect(bounds)));
}
list.commitNewDisplayItems();
@@ -154,5 +190,48 @@ TEST_F(LayoutObjectDrawingRecorderTest, CullRectMatchesProvidedClip)
EXPECT_EQ(rect, drawAndGetCullRect(rootDisplayItemList(), layoutView(), LayoutRect(rect)));
}
+TEST_F(LayoutObjectDrawingRecorderTestForSlimmingPaintV2, PaintOffsetCache)
+{
+ GraphicsContext context(&rootDisplayItemList());
+ LayoutRect bounds = layoutView().viewRect();
+ LayoutPoint paintOffset(1, 2);
+
+ rootDisplayItemList().invalidateAll();
+ EXPECT_FALSE(LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, layoutView(), PaintPhaseForeground, paintOffset));
+ {
+ LayoutObjectDrawingRecorder drawingRecorder(context, layoutView(), PaintPhaseForeground, bounds, paintOffset);
+ IntRect rect(0, 0, 10, 10);
+ context.drawRect(rect);
+ }
+
+ rootDisplayItemList().commitNewDisplayItems();
+ EXPECT_EQ((size_t)1, rootDisplayItemList().displayItems().size());
+ EXPECT_TRUE(isDrawing(rootDisplayItemList().displayItems()[0]));
+
+ // Ensure we cannot use the cache with a new paint offset.
+ LayoutPoint newPaintOffset(2, 3);
+ EXPECT_FALSE(LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, layoutView(), PaintPhaseForeground, newPaintOffset));
+
+ // Test that a new paint offset is recorded.
+ {
+ LayoutObjectDrawingRecorder drawingRecorder(context, layoutView(), PaintPhaseForeground, bounds, newPaintOffset);
+ IntRect rect(0, 0, 10, 10);
+ context.drawRect(rect);
+ }
+
+ rootDisplayItemList().commitNewDisplayItems();
+ EXPECT_EQ((size_t)1, rootDisplayItemList().displayItems().size());
+ EXPECT_TRUE(isDrawing(rootDisplayItemList().displayItems()[0]));
+
+ // Ensure the old paint offset cannot be used.
+ EXPECT_FALSE(LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, layoutView(), PaintPhaseForeground, paintOffset));
+
+ // Ensure the new paint offset can be used.
+ EXPECT_TRUE(LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, layoutView(), PaintPhaseForeground, newPaintOffset));
+ rootDisplayItemList().commitNewDisplayItems();
+ EXPECT_EQ((size_t)1, rootDisplayItemList().displayItems().size());
+ EXPECT_TRUE(isDrawing(rootDisplayItemList().displayItems()[0]));
+}
+
} // namespace
} // namespace blink
« 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