| 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 "platform/graphics/paint/DisplayItemList.h" |
| 7 | 7 |
| 8 #include "platform/RuntimeEnabledFeatures.h" | 8 #include "platform/RuntimeEnabledFeatures.h" |
| 9 #include "platform/graphics/GraphicsContext.h" | 9 #include "platform/graphics/GraphicsContext.h" |
| 10 #include "platform/graphics/paint/ClipRecorder.h" | 10 #include "platform/graphics/paint/ClipRecorder.h" |
| 11 #include "platform/graphics/paint/DrawingDisplayItem.h" | 11 #include "platform/graphics/paint/DrawingDisplayItem.h" |
| 12 #include "platform/graphics/paint/DrawingRecorder.h" | 12 #include "platform/graphics/paint/DrawingRecorder.h" |
| 13 #include <gtest/gtest.h> | 13 #include <gtest/gtest.h> |
| 14 | 14 |
| 15 namespace blink { | 15 namespace blink { |
| 16 | 16 |
| 17 class DisplayItemListTest : public ::testing::Test { | 17 class DisplayItemListTest : public ::testing::Test { |
| 18 protected: | 18 protected: |
| 19 DisplayItemList& displayItemList() { return m_displayItemList; } | 19 DisplayItemList& displayItemList() { return m_displayItemList; } |
| 20 const Vector<OwnPtr<DisplayItem>>& newPaintListBeforeUpdate() { return displ
ayItemList().m_newDisplayItems; } | 20 const DisplayItems& newPaintListBeforeUpdate() { return displayItemList().m_
newDisplayItems; } |
| 21 | 21 |
| 22 private: | 22 private: |
| 23 virtual void SetUp() override | 23 virtual void SetUp() override |
| 24 { | 24 { |
| 25 RuntimeEnabledFeatures::setSlimmingPaintEnabled(true); | 25 RuntimeEnabledFeatures::setSlimmingPaintEnabled(true); |
| 26 } | 26 } |
| 27 virtual void TearDown() override | 27 virtual void TearDown() override |
| 28 { | 28 { |
| 29 RuntimeEnabledFeatures::setSlimmingPaintEnabled(false); | 29 RuntimeEnabledFeatures::setSlimmingPaintEnabled(false); |
| 30 } | 30 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 #define TRACE_DISPLAY_ITEMS(i, expected, actual) | 65 #define TRACE_DISPLAY_ITEMS(i, expected, actual) |
| 66 #endif | 66 #endif |
| 67 | 67 |
| 68 #define EXPECT_DISPLAY_LIST(actual, expectedSize, ...) \ | 68 #define EXPECT_DISPLAY_LIST(actual, expectedSize, ...) \ |
| 69 do { \ | 69 do { \ |
| 70 EXPECT_EQ((size_t)expectedSize, actual.size()); \ | 70 EXPECT_EQ((size_t)expectedSize, actual.size()); \ |
| 71 if (expectedSize != actual.size()) \ | 71 if (expectedSize != actual.size()) \ |
| 72 break; \ | 72 break; \ |
| 73 const TestDisplayItem expected[] = { __VA_ARGS__ }; \ | 73 const TestDisplayItem expected[] = { __VA_ARGS__ }; \ |
| 74 for (size_t index = 0; index < std::min<size_t>(actual.size(), expectedS
ize); index++) { \ | 74 for (size_t index = 0; index < std::min<size_t>(actual.size(), expectedS
ize); index++) { \ |
| 75 TRACE_DISPLAY_ITEMS(index, expected[index], *actual[index]); \ | 75 TRACE_DISPLAY_ITEMS(index, expected[index], actual[index]); \ |
| 76 EXPECT_EQ(expected[index].client(), actual[index]->client()); \ | 76 EXPECT_EQ(expected[index].client(), actual[index].client()); \ |
| 77 EXPECT_EQ(expected[index].type(), actual[index]->type()); \ | 77 EXPECT_EQ(expected[index].type(), actual[index].type()); \ |
| 78 } \ | 78 } \ |
| 79 } while (false); | 79 } while (false); |
| 80 | 80 |
| 81 void drawRect(GraphicsContext& context, const TestDisplayItemClient& client, Dis
playItem::Type type, const FloatRect& bound) | 81 void drawRect(GraphicsContext& context, const TestDisplayItemClient& client, Dis
playItem::Type type, const FloatRect& bound) |
| 82 { | 82 { |
| 83 DrawingRecorder drawingRecorder(context, client, type, bound); | 83 DrawingRecorder drawingRecorder(context, client, type, bound); |
| 84 if (drawingRecorder.canUseCachedDrawing()) | 84 if (drawingRecorder.canUseCachedDrawing()) |
| 85 return; | 85 return; |
| 86 IntRect rect(0, 0, 10, 10); | 86 IntRect rect(0, 0, 10, 10); |
| 87 context.drawRect(rect); | 87 context.drawRect(rect); |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 | 358 |
| 359 drawRect(context, first, backgroundDrawingType, FloatRect(100, 100, 150, 150
)); | 359 drawRect(context, first, backgroundDrawingType, FloatRect(100, 100, 150, 150
)); |
| 360 drawRect(context, second, backgroundDrawingType, FloatRect(100, 100, 150, 15
0)); | 360 drawRect(context, second, backgroundDrawingType, FloatRect(100, 100, 150, 15
0)); |
| 361 displayItemList().commitNewDisplayItems(); | 361 displayItemList().commitNewDisplayItems(); |
| 362 | 362 |
| 363 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 2, | 363 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 2, |
| 364 TestDisplayItem(first, backgroundDrawingType), | 364 TestDisplayItem(first, backgroundDrawingType), |
| 365 TestDisplayItem(second, backgroundDrawingType)); | 365 TestDisplayItem(second, backgroundDrawingType)); |
| 366 EXPECT_TRUE(displayItemList().clientCacheIsValid(first.displayItemClient()))
; | 366 EXPECT_TRUE(displayItemList().clientCacheIsValid(first.displayItemClient()))
; |
| 367 EXPECT_TRUE(displayItemList().clientCacheIsValid(second.displayItemClient())
); | 367 EXPECT_TRUE(displayItemList().clientCacheIsValid(second.displayItemClient())
); |
| 368 DisplayItem* firstDisplayItem = displayItemList().displayItems()[0].get(); | 368 const SkPicture* firstPicture = displayItemList().displayItems()[0].picture(
); |
| 369 DisplayItem* secondDisplayItem = displayItemList().displayItems()[1].get(); | 369 const SkPicture* secondPicture = displayItemList().displayItems()[1].picture
(); |
| 370 | 370 |
| 371 displayItemList().invalidate(first.displayItemClient()); | 371 displayItemList().invalidate(first.displayItemClient()); |
| 372 EXPECT_FALSE(displayItemList().clientCacheIsValid(first.displayItemClient())
); | 372 EXPECT_FALSE(displayItemList().clientCacheIsValid(first.displayItemClient())
); |
| 373 EXPECT_TRUE(displayItemList().clientCacheIsValid(second.displayItemClient())
); | 373 EXPECT_TRUE(displayItemList().clientCacheIsValid(second.displayItemClient())
); |
| 374 | 374 |
| 375 drawRect(context, first, backgroundDrawingType, FloatRect(100, 100, 150, 150
)); | 375 drawRect(context, first, backgroundDrawingType, FloatRect(100, 100, 150, 150
)); |
| 376 drawRect(context, second, backgroundDrawingType, FloatRect(100, 100, 150, 15
0)); | 376 drawRect(context, second, backgroundDrawingType, FloatRect(100, 100, 150, 15
0)); |
| 377 displayItemList().commitNewDisplayItems(); | 377 displayItemList().commitNewDisplayItems(); |
| 378 | 378 |
| 379 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 2, | 379 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 2, |
| 380 TestDisplayItem(first, backgroundDrawingType), | 380 TestDisplayItem(first, backgroundDrawingType), |
| 381 TestDisplayItem(second, backgroundDrawingType)); | 381 TestDisplayItem(second, backgroundDrawingType)); |
| 382 // The first display item should be updated. | 382 // The first display item should be updated. |
| 383 EXPECT_NE(firstDisplayItem, displayItemList().displayItems()[0].get()); | 383 EXPECT_NE(firstPicture, displayItemList().displayItems()[0].picture()); |
| 384 // The second display item should be cached. | 384 // The second display item should be cached. |
| 385 EXPECT_EQ(secondDisplayItem, displayItemList().displayItems()[1].get()); | 385 EXPECT_EQ(secondPicture, displayItemList().displayItems()[1].picture()); |
| 386 EXPECT_TRUE(displayItemList().clientCacheIsValid(first.displayItemClient()))
; | 386 EXPECT_TRUE(displayItemList().clientCacheIsValid(first.displayItemClient()))
; |
| 387 EXPECT_TRUE(displayItemList().clientCacheIsValid(second.displayItemClient())
); | 387 EXPECT_TRUE(displayItemList().clientCacheIsValid(second.displayItemClient())
); |
| 388 | 388 |
| 389 displayItemList().invalidateAll(); | 389 displayItemList().invalidateAll(); |
| 390 EXPECT_FALSE(displayItemList().clientCacheIsValid(first.displayItemClient())
); | 390 EXPECT_FALSE(displayItemList().clientCacheIsValid(first.displayItemClient())
); |
| 391 EXPECT_FALSE(displayItemList().clientCacheIsValid(second.displayItemClient()
)); | 391 EXPECT_FALSE(displayItemList().clientCacheIsValid(second.displayItemClient()
)); |
| 392 } | 392 } |
| 393 | 393 |
| 394 TEST_F(DisplayItemListTest, ComplexUpdateSwapOrder) | 394 TEST_F(DisplayItemListTest, ComplexUpdateSwapOrder) |
| 395 { | 395 { |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 TestDisplayItem(content1, backgroundDrawingType), | 540 TestDisplayItem(content1, backgroundDrawingType), |
| 541 TestDisplayItem(container1, DisplayItem::paintPhaseToEndSubtreeType(back
groundDrawingType)), | 541 TestDisplayItem(container1, DisplayItem::paintPhaseToEndSubtreeType(back
groundDrawingType)), |
| 542 | 542 |
| 543 TestDisplayItem(container1, DisplayItem::paintPhaseToBeginSubtreeType(fo
regroundDrawingType)), | 543 TestDisplayItem(container1, DisplayItem::paintPhaseToBeginSubtreeType(fo
regroundDrawingType)), |
| 544 TestDisplayItem(content1, foregroundDrawingType), | 544 TestDisplayItem(content1, foregroundDrawingType), |
| 545 TestDisplayItem(container1, foregroundDrawingType), | 545 TestDisplayItem(container1, foregroundDrawingType), |
| 546 TestDisplayItem(container1, DisplayItem::paintPhaseToEndSubtreeType(fore
groundDrawingType))); | 546 TestDisplayItem(container1, DisplayItem::paintPhaseToEndSubtreeType(fore
groundDrawingType))); |
| 547 } | 547 } |
| 548 #endif | 548 #endif |
| 549 | 549 |
| 550 static bool isDrawing(const DisplayItems::ItemHandle& item) |
| 551 { |
| 552 return DisplayItem::isDrawingType(item.type()); |
| 553 } |
| 554 |
| 555 static bool isCached(const DisplayItems::ItemHandle& item) |
| 556 { |
| 557 return DisplayItem::isCachedType(item.type()); |
| 558 } |
| 559 |
| 550 TEST_F(DisplayItemListTest, Scope) | 560 TEST_F(DisplayItemListTest, Scope) |
| 551 { | 561 { |
| 552 TestDisplayItemClient multicol("multicol"); | 562 TestDisplayItemClient multicol("multicol"); |
| 553 TestDisplayItemClient content("content"); | 563 TestDisplayItemClient content("content"); |
| 554 GraphicsContext context(&displayItemList()); | 564 GraphicsContext context(&displayItemList()); |
| 555 | 565 |
| 556 FloatRect rect1(100, 100, 50, 50); | 566 FloatRect rect1(100, 100, 50, 50); |
| 557 FloatRect rect2(150, 100, 50, 50); | 567 FloatRect rect2(150, 100, 50, 50); |
| 558 FloatRect rect3(200, 100, 50, 50); | 568 FloatRect rect3(200, 100, 50, 50); |
| 559 | 569 |
| 560 drawRect(context, multicol, backgroundDrawingType, FloatRect(100, 200, 100,
100)); | 570 drawRect(context, multicol, backgroundDrawingType, FloatRect(100, 200, 100,
100)); |
| 561 | 571 |
| 562 displayItemList().beginScope(multicol.displayItemClient()); | 572 displayItemList().beginScope(multicol.displayItemClient()); |
| 563 drawRect(context, content, foregroundDrawingType, rect1); | 573 drawRect(context, content, foregroundDrawingType, rect1); |
| 564 displayItemList().endScope(multicol.displayItemClient()); | 574 displayItemList().endScope(multicol.displayItemClient()); |
| 565 | 575 |
| 566 displayItemList().beginScope(multicol.displayItemClient()); | 576 displayItemList().beginScope(multicol.displayItemClient()); |
| 567 drawRect(context, content, foregroundDrawingType, rect2); | 577 drawRect(context, content, foregroundDrawingType, rect2); |
| 568 displayItemList().endScope(multicol.displayItemClient()); | 578 displayItemList().endScope(multicol.displayItemClient()); |
| 569 displayItemList().commitNewDisplayItems(); | 579 displayItemList().commitNewDisplayItems(); |
| 570 | 580 |
| 571 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 3, | 581 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 3, |
| 572 TestDisplayItem(multicol, backgroundDrawingType), | 582 TestDisplayItem(multicol, backgroundDrawingType), |
| 573 TestDisplayItem(content, foregroundDrawingType), | 583 TestDisplayItem(content, foregroundDrawingType), |
| 574 TestDisplayItem(content, foregroundDrawingType)); | 584 TestDisplayItem(content, foregroundDrawingType)); |
| 575 RefPtr<const SkPicture> picture1 = static_cast<DrawingDisplayItem*>(displayI
temList().displayItems()[1].get())->picture(); | 585 RefPtr<const SkPicture> picture1 = displayItemList().displayItems()[1].pictu
re(); |
| 576 RefPtr<const SkPicture> picture2 = static_cast<DrawingDisplayItem*>(displayI
temList().displayItems()[2].get())->picture(); | 586 RefPtr<const SkPicture> picture2 = displayItemList().displayItems()[2].pictu
re(); |
| 577 EXPECT_NE(picture1, picture2); | 587 EXPECT_NE(picture1, picture2); |
| 578 | 588 |
| 579 // Draw again with nothing invalidated. | 589 // Draw again with nothing invalidated. |
| 580 drawRect(context, multicol, backgroundDrawingType, FloatRect(100, 100, 100,
100)); | 590 drawRect(context, multicol, backgroundDrawingType, FloatRect(100, 100, 100,
100)); |
| 581 displayItemList().beginScope(multicol.displayItemClient()); | 591 displayItemList().beginScope(multicol.displayItemClient()); |
| 582 drawRect(context, content, foregroundDrawingType, rect1); | 592 drawRect(context, content, foregroundDrawingType, rect1); |
| 583 displayItemList().endScope(multicol.displayItemClient()); | 593 displayItemList().endScope(multicol.displayItemClient()); |
| 584 | 594 |
| 585 displayItemList().beginScope(multicol.displayItemClient()); | 595 displayItemList().beginScope(multicol.displayItemClient()); |
| 586 drawRect(context, content, foregroundDrawingType, rect2); | 596 drawRect(context, content, foregroundDrawingType, rect2); |
| 587 displayItemList().endScope(multicol.displayItemClient()); | 597 displayItemList().endScope(multicol.displayItemClient()); |
| 588 | 598 |
| 589 EXPECT_TRUE(newPaintListBeforeUpdate()[0]->isCached()); | 599 EXPECT_TRUE(isCached(newPaintListBeforeUpdate()[0])); |
| 590 EXPECT_TRUE(newPaintListBeforeUpdate()[1]->isCached()); | 600 EXPECT_TRUE(isCached(newPaintListBeforeUpdate()[1])); |
| 591 EXPECT_TRUE(newPaintListBeforeUpdate()[2]->isCached()); | 601 EXPECT_TRUE(isCached(newPaintListBeforeUpdate()[2])); |
| 592 displayItemList().commitNewDisplayItems(); | 602 displayItemList().commitNewDisplayItems(); |
| 593 | 603 |
| 594 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 3, | 604 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 3, |
| 595 TestDisplayItem(multicol, backgroundDrawingType), | 605 TestDisplayItem(multicol, backgroundDrawingType), |
| 596 TestDisplayItem(content, foregroundDrawingType), | 606 TestDisplayItem(content, foregroundDrawingType), |
| 597 TestDisplayItem(content, foregroundDrawingType)); | 607 TestDisplayItem(content, foregroundDrawingType)); |
| 598 EXPECT_EQ(picture1, static_cast<DrawingDisplayItem*>(displayItemList().displ
ayItems()[1].get())->picture()); | 608 EXPECT_EQ(picture1, displayItemList().displayItems()[1].picture()); |
| 599 EXPECT_EQ(picture2, static_cast<DrawingDisplayItem*>(displayItemList().displ
ayItems()[2].get())->picture()); | 609 EXPECT_EQ(picture2, displayItemList().displayItems()[2].picture()); |
| 600 | 610 |
| 601 // Now the multicol becomes 3 columns and repaints. | 611 // Now the multicol becomes 3 columns and repaints. |
| 602 displayItemList().invalidate(multicol.displayItemClient()); | 612 displayItemList().invalidate(multicol.displayItemClient()); |
| 603 displayItemList().invalidate(content.displayItemClient()); | 613 displayItemList().invalidate(content.displayItemClient()); |
| 604 drawRect(context, multicol, backgroundDrawingType, FloatRect(100, 100, 100,
100)); | 614 drawRect(context, multicol, backgroundDrawingType, FloatRect(100, 100, 100,
100)); |
| 605 | 615 |
| 606 displayItemList().beginScope(multicol.displayItemClient()); | 616 displayItemList().beginScope(multicol.displayItemClient()); |
| 607 drawRect(context, content, foregroundDrawingType, rect1); | 617 drawRect(context, content, foregroundDrawingType, rect1); |
| 608 displayItemList().endScope(multicol.displayItemClient()); | 618 displayItemList().endScope(multicol.displayItemClient()); |
| 609 | 619 |
| 610 displayItemList().beginScope(multicol.displayItemClient()); | 620 displayItemList().beginScope(multicol.displayItemClient()); |
| 611 drawRect(context, content, foregroundDrawingType, rect2); | 621 drawRect(context, content, foregroundDrawingType, rect2); |
| 612 displayItemList().endScope(multicol.displayItemClient()); | 622 displayItemList().endScope(multicol.displayItemClient()); |
| 613 | 623 |
| 614 displayItemList().beginScope(multicol.displayItemClient()); | 624 displayItemList().beginScope(multicol.displayItemClient()); |
| 615 drawRect(context, content, foregroundDrawingType, rect3); | 625 drawRect(context, content, foregroundDrawingType, rect3); |
| 616 displayItemList().endScope(multicol.displayItemClient()); | 626 displayItemList().endScope(multicol.displayItemClient()); |
| 617 | 627 |
| 618 // We should repaint everything on invalidation of the scope container. | 628 // We should repaint everything on invalidation of the scope container. |
| 619 EXPECT_TRUE(newPaintListBeforeUpdate()[0]->isDrawing()); | 629 EXPECT_TRUE(isDrawing(newPaintListBeforeUpdate()[0])); |
| 620 EXPECT_TRUE(newPaintListBeforeUpdate()[1]->isDrawing()); | 630 EXPECT_TRUE(isDrawing(newPaintListBeforeUpdate()[1])); |
| 621 EXPECT_TRUE(newPaintListBeforeUpdate()[2]->isDrawing()); | 631 EXPECT_TRUE(isDrawing(newPaintListBeforeUpdate()[2])); |
| 622 EXPECT_TRUE(newPaintListBeforeUpdate()[3]->isDrawing()); | 632 EXPECT_TRUE(isDrawing(newPaintListBeforeUpdate()[3])); |
| 623 displayItemList().commitNewDisplayItems(); | 633 displayItemList().commitNewDisplayItems(); |
| 624 | 634 |
| 625 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 4, | 635 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 4, |
| 626 TestDisplayItem(multicol, backgroundDrawingType), | 636 TestDisplayItem(multicol, backgroundDrawingType), |
| 627 TestDisplayItem(content, foregroundDrawingType), | 637 TestDisplayItem(content, foregroundDrawingType), |
| 628 TestDisplayItem(content, foregroundDrawingType), | 638 TestDisplayItem(content, foregroundDrawingType), |
| 629 TestDisplayItem(content, foregroundDrawingType)); | 639 TestDisplayItem(content, foregroundDrawingType)); |
| 630 EXPECT_NE(picture1, static_cast<DrawingDisplayItem*>(displayItemList().displ
ayItems()[1].get())->picture()); | 640 EXPECT_NE(picture1, displayItemList().displayItems()[1].picture()); |
| 631 EXPECT_NE(picture2, static_cast<DrawingDisplayItem*>(displayItemList().displ
ayItems()[2].get())->picture()); | 641 EXPECT_NE(picture2, displayItemList().displayItems()[2].picture()); |
| 632 } | 642 } |
| 633 | 643 |
| 634 } // namespace blink | 644 } // namespace blink |
| OLD | NEW |