Chromium Code Reviews| Index: Source/platform/graphics/paint/DisplayItemListTest.cpp |
| diff --git a/Source/platform/graphics/paint/DisplayItemListTest.cpp b/Source/platform/graphics/paint/DisplayItemListTest.cpp |
| index 59e7642e15a0df630c18a0e3f31dec68c67c752b..926f40f4f708c0516a369f11cb8c702a140d9eeb 100644 |
| --- a/Source/platform/graphics/paint/DisplayItemListTest.cpp |
| +++ b/Source/platform/graphics/paint/DisplayItemListTest.cpp |
| @@ -458,92 +458,152 @@ TEST_F(DisplayItemListTest, CachedSubtreeSwapOrder) |
| TestDisplayItemClient container2("container2"); |
| TestDisplayItemClient content2("content2"); |
| GraphicsContext context(&displayItemList()); |
| - const int backgroundPaintPhase = backgroundDrawingType - DisplayItem::DrawingPaintPhaseFirst; |
| - const int foregroundPaintPhase = foregroundDrawingType - DisplayItem::DrawingPaintPhaseFirst; |
| { |
| - SubtreeRecorder r(context, container1, backgroundPaintPhase); |
| - EXPECT_FALSE(r.canUseCache()); |
| + SubtreeRecorder r(context, container1); |
| drawRect(context, container1, backgroundDrawingType, FloatRect(100, 100, 100, 100)); |
| drawRect(context, content1, backgroundDrawingType, FloatRect(100, 100, 50, 200)); |
| - } |
| - { |
| - SubtreeRecorder r(context, container1, foregroundPaintPhase); |
| - EXPECT_FALSE(r.canUseCache()); |
| drawRect(context, content1, foregroundDrawingType, FloatRect(100, 100, 50, 200)); |
| drawRect(context, container1, foregroundDrawingType, FloatRect(100, 100, 100, 100)); |
| } |
| { |
| - SubtreeRecorder r(context, container2, backgroundPaintPhase); |
| - EXPECT_FALSE(r.canUseCache()); |
| + SubtreeRecorder r(context, container2); |
| drawRect(context, container2, backgroundDrawingType, FloatRect(100, 200, 100, 100)); |
| drawRect(context, content2, backgroundDrawingType, FloatRect(100, 200, 50, 200)); |
| - } |
| - { |
| - SubtreeRecorder r(context, container2, foregroundPaintPhase); |
| - EXPECT_FALSE(r.canUseCache()); |
| drawRect(context, content2, foregroundDrawingType, FloatRect(100, 200, 50, 200)); |
| drawRect(context, container2, foregroundDrawingType, FloatRect(100, 200, 100, 100)); |
| } |
| displayItemList().commitNewDisplayItems(); |
| - EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 16, |
| - TestDisplayItem(container1, DisplayItem::paintPhaseToBeginSubtreeType(backgroundPaintPhase)), |
| + EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 12, |
| + TestDisplayItem(container1, DisplayItem::BeginSubtree), |
| TestDisplayItem(container1, backgroundDrawingType), |
| TestDisplayItem(content1, backgroundDrawingType), |
| - TestDisplayItem(container1, DisplayItem::paintPhaseToEndSubtreeType(backgroundPaintPhase)), |
| - |
| - TestDisplayItem(container1, DisplayItem::paintPhaseToBeginSubtreeType(foregroundPaintPhase)), |
| TestDisplayItem(content1, foregroundDrawingType), |
| TestDisplayItem(container1, foregroundDrawingType), |
| - TestDisplayItem(container1, DisplayItem::paintPhaseToEndSubtreeType(foregroundPaintPhase)), |
| + TestDisplayItem(container1, DisplayItem::EndSubtree), |
| - TestDisplayItem(container2, DisplayItem::paintPhaseToBeginSubtreeType(backgroundPaintPhase)), |
| + TestDisplayItem(container2, DisplayItem::BeginSubtree), |
| TestDisplayItem(container2, backgroundDrawingType), |
| TestDisplayItem(content2, backgroundDrawingType), |
| - TestDisplayItem(container2, DisplayItem::paintPhaseToEndSubtreeType(backgroundPaintPhase)), |
| - |
| - TestDisplayItem(container2, DisplayItem::paintPhaseToBeginSubtreeType(foregroundPaintPhase)), |
| TestDisplayItem(content2, foregroundDrawingType), |
| TestDisplayItem(container2, foregroundDrawingType), |
| - TestDisplayItem(container2, DisplayItem::paintPhaseToEndSubtreeType(foregroundPaintPhase))); |
| + TestDisplayItem(container2, DisplayItem::EndSubtree)); |
| // Simulate the situation when container1 e.g. gets a z-index that is now greater than container2. |
| - displayItemList().createAndAppend<CachedDisplayItem>(container2, DisplayItem::paintPhaseToCachedSubtreeType(backgroundPaintPhase)); |
| + EXPECT_TRUE(SubtreeRecorder::useCachedSubtreeIfPossible(context, container2)); |
| EXPECT_EQ((size_t)1, newPaintListBeforeUpdate().size()); |
| - EXPECT_TRUE(newPaintListBeforeUpdate().last().isCachedSubtree()); |
| - displayItemList().createAndAppend<CachedDisplayItem>(container2, DisplayItem::paintPhaseToCachedSubtreeType(foregroundPaintPhase)); |
| - EXPECT_EQ((size_t)2, newPaintListBeforeUpdate().size()); |
| - EXPECT_TRUE(newPaintListBeforeUpdate().last().isCachedSubtree()); |
| + EXPECT_TRUE(newPaintListBeforeUpdate().last().type() == DisplayItem::CachedSubtree); |
| - displayItemList().createAndAppend<CachedDisplayItem>(container1, DisplayItem::paintPhaseToCachedSubtreeType(backgroundPaintPhase)); |
| - EXPECT_EQ((size_t)3, newPaintListBeforeUpdate().size()); |
| - EXPECT_TRUE(newPaintListBeforeUpdate().last().isCachedSubtree()); |
| - displayItemList().createAndAppend<CachedDisplayItem>(container1, DisplayItem::paintPhaseToCachedSubtreeType(foregroundPaintPhase)); |
| - EXPECT_EQ((size_t)4, newPaintListBeforeUpdate().size()); |
| - EXPECT_TRUE(newPaintListBeforeUpdate().last().isCachedSubtree()); |
| + EXPECT_TRUE(SubtreeRecorder::useCachedSubtreeIfPossible(context, container1)); |
| + EXPECT_EQ((size_t)2, newPaintListBeforeUpdate().size()); |
| + EXPECT_TRUE(newPaintListBeforeUpdate().last().type() == DisplayItem::CachedSubtree); |
| displayItemList().commitNewDisplayItems(); |
| - EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 16, |
| - TestDisplayItem(container2, DisplayItem::paintPhaseToBeginSubtreeType(backgroundDrawingType)), |
| + EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 12, |
| + TestDisplayItem(container2, DisplayItem::BeginSubtree), |
| TestDisplayItem(container2, backgroundDrawingType), |
| TestDisplayItem(content2, backgroundDrawingType), |
| - TestDisplayItem(container2, DisplayItem::paintPhaseToEndSubtreeType(backgroundDrawingType)), |
| - |
| - TestDisplayItem(container2, DisplayItem::paintPhaseToBeginSubtreeType(foregroundDrawingType)), |
| TestDisplayItem(content2, foregroundDrawingType), |
| TestDisplayItem(container2, foregroundDrawingType), |
| - TestDisplayItem(container2, DisplayItem::paintPhaseToEndSubtreeType(foregroundDrawingType)), |
| + TestDisplayItem(container2, DisplayItem::EndSubtree), |
| - TestDisplayItem(container1, DisplayItem::paintPhaseToBeginSubtreeType(backgroundDrawingType)), |
| + TestDisplayItem(container1, DisplayItem::BeginSubtree), |
| TestDisplayItem(container1, backgroundDrawingType), |
| TestDisplayItem(content1, backgroundDrawingType), |
| - TestDisplayItem(container1, DisplayItem::paintPhaseToEndSubtreeType(backgroundDrawingType)), |
| + TestDisplayItem(content1, foregroundDrawingType), |
| + TestDisplayItem(container1, foregroundDrawingType), |
| + TestDisplayItem(container1, DisplayItem::EndSubtree)); |
| +} |
| + |
| +TEST_F(DisplayItemListTest, CachedNestedSubtreeUpdate) |
| +{ |
| + TestDisplayItemClient container1("container1"); |
| + TestDisplayItemClient content1("content1"); |
| + TestDisplayItemClient container2("container2"); |
| + TestDisplayItemClient content2("content2"); |
| + GraphicsContext context(&displayItemList()); |
| - TestDisplayItem(container1, DisplayItem::paintPhaseToBeginSubtreeType(foregroundDrawingType)), |
| + { |
| + SubtreeRecorder r(context, container1); |
| + drawRect(context, container1, backgroundDrawingType, FloatRect(100, 100, 100, 100)); |
| + { |
| + SubtreeRecorder r(context, content1); |
| + drawRect(context, content1, backgroundDrawingType, FloatRect(100, 100, 50, 200)); |
| + drawRect(context, content1, foregroundDrawingType, FloatRect(100, 100, 50, 200)); |
| + } |
| + drawRect(context, container1, foregroundDrawingType, FloatRect(100, 100, 100, 100)); |
| + } |
| + { |
| + SubtreeRecorder r(context, container2); |
| + drawRect(context, container2, backgroundDrawingType, FloatRect(100, 200, 100, 100)); |
| + { |
| + SubtreeRecorder r(context, content2); |
| + drawRect(context, content2, backgroundDrawingType, FloatRect(100, 200, 50, 200)); |
| + } |
| + } |
| + displayItemList().commitNewDisplayItems(); |
| + |
| + EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 14, |
| + TestDisplayItem(container1, DisplayItem::BeginSubtree), |
| + TestDisplayItem(container1, backgroundDrawingType), |
| + TestDisplayItem(content1, DisplayItem::BeginSubtree), |
| + TestDisplayItem(content1, backgroundDrawingType), |
| + TestDisplayItem(content1, foregroundDrawingType), |
| + TestDisplayItem(content1, DisplayItem::EndSubtree), |
| + TestDisplayItem(container1, foregroundDrawingType), |
| + TestDisplayItem(container1, DisplayItem::EndSubtree), |
| + |
| + TestDisplayItem(container2, DisplayItem::BeginSubtree), |
| + TestDisplayItem(container2, backgroundDrawingType), |
| + TestDisplayItem(content2, DisplayItem::BeginSubtree), |
| + TestDisplayItem(content2, backgroundDrawingType), |
| + TestDisplayItem(content2, DisplayItem::EndSubtree), |
| + TestDisplayItem(container2, DisplayItem::EndSubtree)); |
| + |
| + // Invalidate container1 but not content1. |
| + displayItemList().invalidate(container1.displayItemClient()); |
| + |
| + // Container2 itself now becomes empty (but still has the 'content2' child), and chooses not to output subtree info. |
| + displayItemList().invalidate(container2.displayItemClient()); |
| + displayItemList().invalidate(content2.displayItemClient()); |
| + EXPECT_FALSE(SubtreeRecorder::useCachedSubtreeIfPossible(context, container2)); |
| + EXPECT_FALSE(SubtreeRecorder::useCachedSubtreeIfPossible(context, content2)); |
| + // Content2 now outputs foreground only. |
| + { |
| + SubtreeRecorder r(context, content2); |
| + drawRect(context, content2, foregroundDrawingType, FloatRect(100, 200, 50, 200)); |
| + } |
| + EXPECT_EQ((size_t)3, newPaintListBeforeUpdate().size()); |
| + |
| + // Repaint container1 with foreground only. |
| + { |
| + EXPECT_FALSE(SubtreeRecorder::useCachedSubtreeIfPossible(context, container1)); |
| + SubtreeRecorder r(context, container1); |
| + |
| + // Use cached subtree of content1. |
| + EXPECT_TRUE(SubtreeRecorder::useCachedSubtreeIfPossible(context, content1)); |
| + EXPECT_EQ((size_t)5, newPaintListBeforeUpdate().size()); |
| + EXPECT_TRUE(newPaintListBeforeUpdate().last().type() == DisplayItem::CachedSubtree); |
| + |
| + drawRect(context, container1, foregroundDrawingType, FloatRect(100, 100, 100, 100)); |
| + } |
| + EXPECT_EQ((size_t)7, newPaintListBeforeUpdate().size()); |
|
chrishtr
2015/08/25 23:48:19
Check that newPaintListBeforeUpdate() has cached s
Xianzhu
2015/08/26 23:21:06
Done.
|
| + |
| + displayItemList().commitNewDisplayItems(); |
| + |
| + EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 10, |
| + TestDisplayItem(content2, DisplayItem::BeginSubtree), |
| + TestDisplayItem(content2, foregroundDrawingType), |
| + TestDisplayItem(content2, DisplayItem::EndSubtree), |
| + |
| + TestDisplayItem(container1, DisplayItem::BeginSubtree), |
| + TestDisplayItem(content1, DisplayItem::BeginSubtree), |
| + TestDisplayItem(content1, backgroundDrawingType), |
| TestDisplayItem(content1, foregroundDrawingType), |
| + TestDisplayItem(content1, DisplayItem::EndSubtree), |
| TestDisplayItem(container1, foregroundDrawingType), |
| - TestDisplayItem(container1, DisplayItem::paintPhaseToEndSubtreeType(foregroundDrawingType))); |
| + TestDisplayItem(container1, DisplayItem::EndSubtree)); |
| } |
| TEST_F(DisplayItemListTest, Scope) |