Chromium Code Reviews| 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/CachedDisplayItem.h" | 10 #include "platform/graphics/paint/CachedDisplayItem.h" |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 451 TestDisplayItem(container1, foregroundDrawingType)); | 451 TestDisplayItem(container1, foregroundDrawingType)); |
| 452 } | 452 } |
| 453 | 453 |
| 454 TEST_F(DisplayItemListTest, CachedSubtreeSwapOrder) | 454 TEST_F(DisplayItemListTest, CachedSubtreeSwapOrder) |
| 455 { | 455 { |
| 456 TestDisplayItemClient container1("container1"); | 456 TestDisplayItemClient container1("container1"); |
| 457 TestDisplayItemClient content1("content1"); | 457 TestDisplayItemClient content1("content1"); |
| 458 TestDisplayItemClient container2("container2"); | 458 TestDisplayItemClient container2("container2"); |
| 459 TestDisplayItemClient content2("content2"); | 459 TestDisplayItemClient content2("content2"); |
| 460 GraphicsContext context(&displayItemList()); | 460 GraphicsContext context(&displayItemList()); |
| 461 const int backgroundPaintPhase = backgroundDrawingType - DisplayItem::Drawin gPaintPhaseFirst; | |
| 462 const int foregroundPaintPhase = foregroundDrawingType - DisplayItem::Drawin gPaintPhaseFirst; | |
| 463 | 461 |
| 464 { | 462 { |
| 465 SubtreeRecorder r(context, container1, backgroundPaintPhase); | 463 SubtreeRecorder r(context, container1); |
| 466 EXPECT_FALSE(r.canUseCache()); | |
| 467 drawRect(context, container1, backgroundDrawingType, FloatRect(100, 100, 100, 100)); | 464 drawRect(context, container1, backgroundDrawingType, FloatRect(100, 100, 100, 100)); |
| 468 drawRect(context, content1, backgroundDrawingType, FloatRect(100, 100, 5 0, 200)); | 465 drawRect(context, content1, backgroundDrawingType, FloatRect(100, 100, 5 0, 200)); |
| 469 } | |
| 470 { | |
| 471 SubtreeRecorder r(context, container1, foregroundPaintPhase); | |
| 472 EXPECT_FALSE(r.canUseCache()); | |
| 473 drawRect(context, content1, foregroundDrawingType, FloatRect(100, 100, 5 0, 200)); | 466 drawRect(context, content1, foregroundDrawingType, FloatRect(100, 100, 5 0, 200)); |
| 474 drawRect(context, container1, foregroundDrawingType, FloatRect(100, 100, 100, 100)); | 467 drawRect(context, container1, foregroundDrawingType, FloatRect(100, 100, 100, 100)); |
| 475 } | 468 } |
| 476 { | 469 { |
| 477 SubtreeRecorder r(context, container2, backgroundPaintPhase); | 470 SubtreeRecorder r(context, container2); |
| 478 EXPECT_FALSE(r.canUseCache()); | |
| 479 drawRect(context, container2, backgroundDrawingType, FloatRect(100, 200, 100, 100)); | 471 drawRect(context, container2, backgroundDrawingType, FloatRect(100, 200, 100, 100)); |
| 480 drawRect(context, content2, backgroundDrawingType, FloatRect(100, 200, 5 0, 200)); | 472 drawRect(context, content2, backgroundDrawingType, FloatRect(100, 200, 5 0, 200)); |
| 481 } | |
| 482 { | |
| 483 SubtreeRecorder r(context, container2, foregroundPaintPhase); | |
| 484 EXPECT_FALSE(r.canUseCache()); | |
| 485 drawRect(context, content2, foregroundDrawingType, FloatRect(100, 200, 5 0, 200)); | 473 drawRect(context, content2, foregroundDrawingType, FloatRect(100, 200, 5 0, 200)); |
| 486 drawRect(context, container2, foregroundDrawingType, FloatRect(100, 200, 100, 100)); | 474 drawRect(context, container2, foregroundDrawingType, FloatRect(100, 200, 100, 100)); |
| 487 } | 475 } |
| 488 displayItemList().commitNewDisplayItems(); | 476 displayItemList().commitNewDisplayItems(); |
| 489 | 477 |
| 490 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 16, | 478 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 12, |
| 491 TestDisplayItem(container1, DisplayItem::paintPhaseToBeginSubtreeType(ba ckgroundPaintPhase)), | 479 TestDisplayItem(container1, DisplayItem::BeginSubtree), |
| 492 TestDisplayItem(container1, backgroundDrawingType), | 480 TestDisplayItem(container1, backgroundDrawingType), |
| 493 TestDisplayItem(content1, backgroundDrawingType), | 481 TestDisplayItem(content1, backgroundDrawingType), |
| 494 TestDisplayItem(container1, DisplayItem::paintPhaseToEndSubtreeType(back groundPaintPhase)), | |
| 495 | |
| 496 TestDisplayItem(container1, DisplayItem::paintPhaseToBeginSubtreeType(fo regroundPaintPhase)), | |
| 497 TestDisplayItem(content1, foregroundDrawingType), | 482 TestDisplayItem(content1, foregroundDrawingType), |
| 498 TestDisplayItem(container1, foregroundDrawingType), | 483 TestDisplayItem(container1, foregroundDrawingType), |
| 499 TestDisplayItem(container1, DisplayItem::paintPhaseToEndSubtreeType(fore groundPaintPhase)), | 484 TestDisplayItem(container1, DisplayItem::EndSubtree), |
| 500 | 485 |
| 501 TestDisplayItem(container2, DisplayItem::paintPhaseToBeginSubtreeType(ba ckgroundPaintPhase)), | 486 TestDisplayItem(container2, DisplayItem::BeginSubtree), |
| 502 TestDisplayItem(container2, backgroundDrawingType), | 487 TestDisplayItem(container2, backgroundDrawingType), |
| 503 TestDisplayItem(content2, backgroundDrawingType), | 488 TestDisplayItem(content2, backgroundDrawingType), |
| 504 TestDisplayItem(container2, DisplayItem::paintPhaseToEndSubtreeType(back groundPaintPhase)), | |
| 505 | |
| 506 TestDisplayItem(container2, DisplayItem::paintPhaseToBeginSubtreeType(fo regroundPaintPhase)), | |
| 507 TestDisplayItem(content2, foregroundDrawingType), | 489 TestDisplayItem(content2, foregroundDrawingType), |
| 508 TestDisplayItem(container2, foregroundDrawingType), | 490 TestDisplayItem(container2, foregroundDrawingType), |
| 509 TestDisplayItem(container2, DisplayItem::paintPhaseToEndSubtreeType(fore groundPaintPhase))); | 491 TestDisplayItem(container2, DisplayItem::EndSubtree)); |
| 510 | 492 |
| 511 // Simulate the situation when container1 e.g. gets a z-index that is now gr eater than container2. | 493 // Simulate the situation when container1 e.g. gets a z-index that is now gr eater than container2. |
| 512 displayItemList().createAndAppend<CachedDisplayItem>(container2, DisplayItem ::paintPhaseToCachedSubtreeType(backgroundPaintPhase)); | 494 EXPECT_TRUE(SubtreeRecorder::useCachedSubtreeIfPossible(context, container2) ); |
| 513 EXPECT_EQ((size_t)1, newPaintListBeforeUpdate().size()); | 495 EXPECT_EQ((size_t)1, newPaintListBeforeUpdate().size()); |
| 514 EXPECT_TRUE(newPaintListBeforeUpdate().last().isCachedSubtree()); | 496 EXPECT_TRUE(newPaintListBeforeUpdate().last().type() == DisplayItem::CachedS ubtree); |
| 515 displayItemList().createAndAppend<CachedDisplayItem>(container2, DisplayItem ::paintPhaseToCachedSubtreeType(foregroundPaintPhase)); | 497 |
| 498 EXPECT_TRUE(SubtreeRecorder::useCachedSubtreeIfPossible(context, container1) ); | |
| 516 EXPECT_EQ((size_t)2, newPaintListBeforeUpdate().size()); | 499 EXPECT_EQ((size_t)2, newPaintListBeforeUpdate().size()); |
| 517 EXPECT_TRUE(newPaintListBeforeUpdate().last().isCachedSubtree()); | 500 EXPECT_TRUE(newPaintListBeforeUpdate().last().type() == DisplayItem::CachedS ubtree); |
| 518 | |
| 519 displayItemList().createAndAppend<CachedDisplayItem>(container1, DisplayItem ::paintPhaseToCachedSubtreeType(backgroundPaintPhase)); | |
| 520 EXPECT_EQ((size_t)3, newPaintListBeforeUpdate().size()); | |
| 521 EXPECT_TRUE(newPaintListBeforeUpdate().last().isCachedSubtree()); | |
| 522 displayItemList().createAndAppend<CachedDisplayItem>(container1, DisplayItem ::paintPhaseToCachedSubtreeType(foregroundPaintPhase)); | |
| 523 EXPECT_EQ((size_t)4, newPaintListBeforeUpdate().size()); | |
| 524 EXPECT_TRUE(newPaintListBeforeUpdate().last().isCachedSubtree()); | |
| 525 displayItemList().commitNewDisplayItems(); | 501 displayItemList().commitNewDisplayItems(); |
| 526 | 502 |
| 527 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 16, | 503 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 12, |
| 528 TestDisplayItem(container2, DisplayItem::paintPhaseToBeginSubtreeType(ba ckgroundDrawingType)), | 504 TestDisplayItem(container2, DisplayItem::BeginSubtree), |
| 529 TestDisplayItem(container2, backgroundDrawingType), | 505 TestDisplayItem(container2, backgroundDrawingType), |
| 530 TestDisplayItem(content2, backgroundDrawingType), | 506 TestDisplayItem(content2, backgroundDrawingType), |
| 531 TestDisplayItem(container2, DisplayItem::paintPhaseToEndSubtreeType(back groundDrawingType)), | |
| 532 | |
| 533 TestDisplayItem(container2, DisplayItem::paintPhaseToBeginSubtreeType(fo regroundDrawingType)), | |
| 534 TestDisplayItem(content2, foregroundDrawingType), | 507 TestDisplayItem(content2, foregroundDrawingType), |
| 535 TestDisplayItem(container2, foregroundDrawingType), | 508 TestDisplayItem(container2, foregroundDrawingType), |
| 536 TestDisplayItem(container2, DisplayItem::paintPhaseToEndSubtreeType(fore groundDrawingType)), | 509 TestDisplayItem(container2, DisplayItem::EndSubtree), |
| 537 | 510 |
| 538 TestDisplayItem(container1, DisplayItem::paintPhaseToBeginSubtreeType(ba ckgroundDrawingType)), | 511 TestDisplayItem(container1, DisplayItem::BeginSubtree), |
| 539 TestDisplayItem(container1, backgroundDrawingType), | 512 TestDisplayItem(container1, backgroundDrawingType), |
| 540 TestDisplayItem(content1, backgroundDrawingType), | 513 TestDisplayItem(content1, backgroundDrawingType), |
| 541 TestDisplayItem(container1, DisplayItem::paintPhaseToEndSubtreeType(back groundDrawingType)), | |
| 542 | |
| 543 TestDisplayItem(container1, DisplayItem::paintPhaseToBeginSubtreeType(fo regroundDrawingType)), | |
| 544 TestDisplayItem(content1, foregroundDrawingType), | 514 TestDisplayItem(content1, foregroundDrawingType), |
| 545 TestDisplayItem(container1, foregroundDrawingType), | 515 TestDisplayItem(container1, foregroundDrawingType), |
| 546 TestDisplayItem(container1, DisplayItem::paintPhaseToEndSubtreeType(fore groundDrawingType))); | 516 TestDisplayItem(container1, DisplayItem::EndSubtree)); |
| 517 } | |
| 518 | |
| 519 TEST_F(DisplayItemListTest, CachedNestedSubtreeUpdate) | |
| 520 { | |
| 521 TestDisplayItemClient container1("container1"); | |
| 522 TestDisplayItemClient content1("content1"); | |
| 523 TestDisplayItemClient container2("container2"); | |
| 524 TestDisplayItemClient content2("content2"); | |
| 525 GraphicsContext context(&displayItemList()); | |
| 526 | |
| 527 { | |
| 528 SubtreeRecorder r(context, container1); | |
| 529 drawRect(context, container1, backgroundDrawingType, FloatRect(100, 100, 100, 100)); | |
| 530 { | |
| 531 SubtreeRecorder r(context, content1); | |
| 532 drawRect(context, content1, backgroundDrawingType, FloatRect(100, 10 0, 50, 200)); | |
| 533 drawRect(context, content1, foregroundDrawingType, FloatRect(100, 10 0, 50, 200)); | |
| 534 } | |
| 535 drawRect(context, container1, foregroundDrawingType, FloatRect(100, 100, 100, 100)); | |
| 536 } | |
| 537 { | |
| 538 SubtreeRecorder r(context, container2); | |
| 539 drawRect(context, container2, backgroundDrawingType, FloatRect(100, 200, 100, 100)); | |
| 540 { | |
| 541 SubtreeRecorder r(context, content2); | |
| 542 drawRect(context, content2, backgroundDrawingType, FloatRect(100, 20 0, 50, 200)); | |
| 543 } | |
| 544 } | |
| 545 displayItemList().commitNewDisplayItems(); | |
| 546 | |
| 547 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 14, | |
| 548 TestDisplayItem(container1, DisplayItem::BeginSubtree), | |
| 549 TestDisplayItem(container1, backgroundDrawingType), | |
| 550 TestDisplayItem(content1, DisplayItem::BeginSubtree), | |
| 551 TestDisplayItem(content1, backgroundDrawingType), | |
| 552 TestDisplayItem(content1, foregroundDrawingType), | |
| 553 TestDisplayItem(content1, DisplayItem::EndSubtree), | |
| 554 TestDisplayItem(container1, foregroundDrawingType), | |
| 555 TestDisplayItem(container1, DisplayItem::EndSubtree), | |
| 556 | |
| 557 TestDisplayItem(container2, DisplayItem::BeginSubtree), | |
| 558 TestDisplayItem(container2, backgroundDrawingType), | |
| 559 TestDisplayItem(content2, DisplayItem::BeginSubtree), | |
| 560 TestDisplayItem(content2, backgroundDrawingType), | |
| 561 TestDisplayItem(content2, DisplayItem::EndSubtree), | |
| 562 TestDisplayItem(container2, DisplayItem::EndSubtree)); | |
| 563 | |
| 564 // Invalidate container1 but not content1. | |
| 565 displayItemList().invalidate(container1.displayItemClient()); | |
| 566 | |
| 567 // Container2 itself now becomes empty (but still has the 'content2' child), and chooses not to output subtree info. | |
| 568 displayItemList().invalidate(container2.displayItemClient()); | |
| 569 displayItemList().invalidate(content2.displayItemClient()); | |
| 570 EXPECT_FALSE(SubtreeRecorder::useCachedSubtreeIfPossible(context, container2 )); | |
| 571 EXPECT_FALSE(SubtreeRecorder::useCachedSubtreeIfPossible(context, content2)) ; | |
| 572 // Content2 now outputs foreground only. | |
| 573 { | |
| 574 SubtreeRecorder r(context, content2); | |
| 575 drawRect(context, content2, foregroundDrawingType, FloatRect(100, 200, 5 0, 200)); | |
| 576 } | |
| 577 EXPECT_EQ((size_t)3, newPaintListBeforeUpdate().size()); | |
| 578 | |
| 579 // Repaint container1 with foreground only. | |
| 580 { | |
| 581 EXPECT_FALSE(SubtreeRecorder::useCachedSubtreeIfPossible(context, contai ner1)); | |
| 582 SubtreeRecorder r(context, container1); | |
| 583 | |
| 584 // Use cached subtree of content1. | |
| 585 EXPECT_TRUE(SubtreeRecorder::useCachedSubtreeIfPossible(context, content 1)); | |
| 586 EXPECT_EQ((size_t)5, newPaintListBeforeUpdate().size()); | |
| 587 EXPECT_TRUE(newPaintListBeforeUpdate().last().type() == DisplayItem::Cac hedSubtree); | |
| 588 | |
| 589 drawRect(context, container1, foregroundDrawingType, FloatRect(100, 100, 100, 100)); | |
| 590 } | |
| 591 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.
| |
| 592 | |
| 593 displayItemList().commitNewDisplayItems(); | |
| 594 | |
| 595 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 10, | |
| 596 TestDisplayItem(content2, DisplayItem::BeginSubtree), | |
| 597 TestDisplayItem(content2, foregroundDrawingType), | |
| 598 TestDisplayItem(content2, DisplayItem::EndSubtree), | |
| 599 | |
| 600 TestDisplayItem(container1, DisplayItem::BeginSubtree), | |
| 601 TestDisplayItem(content1, DisplayItem::BeginSubtree), | |
| 602 TestDisplayItem(content1, backgroundDrawingType), | |
| 603 TestDisplayItem(content1, foregroundDrawingType), | |
| 604 TestDisplayItem(content1, DisplayItem::EndSubtree), | |
| 605 TestDisplayItem(container1, foregroundDrawingType), | |
| 606 TestDisplayItem(container1, DisplayItem::EndSubtree)); | |
| 547 } | 607 } |
| 548 | 608 |
| 549 TEST_F(DisplayItemListTest, Scope) | 609 TEST_F(DisplayItemListTest, Scope) |
| 550 { | 610 { |
| 551 TestDisplayItemClient multicol("multicol"); | 611 TestDisplayItemClient multicol("multicol"); |
| 552 TestDisplayItemClient content("content"); | 612 TestDisplayItemClient content("content"); |
| 553 GraphicsContext context(&displayItemList()); | 613 GraphicsContext context(&displayItemList()); |
| 554 | 614 |
| 555 FloatRect rect1(100, 100, 50, 50); | 615 FloatRect rect1(100, 100, 50, 50); |
| 556 FloatRect rect2(150, 100, 50, 50); | 616 FloatRect rect2(150, 100, 50, 50); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 678 drawRect(context, third, backgroundDrawingType, FloatRect(0, 0, 100, 100)); | 738 drawRect(context, third, backgroundDrawingType, FloatRect(0, 0, 100, 100)); |
| 679 displayItemList().commitNewDisplayItems(); | 739 displayItemList().commitNewDisplayItems(); |
| 680 | 740 |
| 681 // Empty clips should have been optimized out. | 741 // Empty clips should have been optimized out. |
| 682 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 2, | 742 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 2, |
| 683 TestDisplayItem(first, backgroundDrawingType), | 743 TestDisplayItem(first, backgroundDrawingType), |
| 684 TestDisplayItem(third, backgroundDrawingType)); | 744 TestDisplayItem(third, backgroundDrawingType)); |
| 685 } | 745 } |
| 686 | 746 |
| 687 } // namespace blink | 747 } // namespace blink |
| OLD | NEW |