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

Side by Side Diff: Source/platform/graphics/paint/DisplayItemListTest.cpp

Issue 1323243011: Add DisplayItemList::newDisplayItems() and cleanup tests (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "platform/graphics/paint/ClipPathRecorder.h" 11 #include "platform/graphics/paint/ClipPathRecorder.h"
12 #include "platform/graphics/paint/ClipRecorder.h" 12 #include "platform/graphics/paint/ClipRecorder.h"
13 #include "platform/graphics/paint/DrawingDisplayItem.h" 13 #include "platform/graphics/paint/DrawingDisplayItem.h"
14 #include "platform/graphics/paint/DrawingRecorder.h" 14 #include "platform/graphics/paint/DrawingRecorder.h"
15 #include "platform/graphics/paint/SubsequenceRecorder.h" 15 #include "platform/graphics/paint/SubsequenceRecorder.h"
16 #include <gtest/gtest.h> 16 #include <gtest/gtest.h>
17 17
18 namespace blink { 18 namespace blink {
19 19
20 class DisplayItemListTest : public ::testing::Test { 20 class DisplayItemListTest : public ::testing::Test {
21 public: 21 public:
22 DisplayItemListTest() 22 DisplayItemListTest()
23 : m_originalSlimmingPaintV2Enabled(RuntimeEnabledFeatures::slimmingPaint V2Enabled()) { } 23 : m_displayItemList(DisplayItemList::create())
24 , m_originalSlimmingPaintV2Enabled(RuntimeEnabledFeatures::slimmingPaint V2Enabled()) { }
24 25
25 protected: 26 protected:
26 DisplayItemList& displayItemList() { return m_displayItemList; } 27 DisplayItemList& displayItemList() { return *m_displayItemList; }
27 const DisplayItems& newDisplayItemsBeforeUpdate() { return displayItemList() .m_newDisplayItems; }
28 28
29 private: 29 private:
30 void SetUp() override 30 void SetUp() override
31 { 31 {
32 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled()); 32 ASSERT(RuntimeEnabledFeatures::slimmingPaintEnabled());
33 RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(true); 33 RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(true);
34 } 34 }
35 void TearDown() override 35 void TearDown() override
36 { 36 {
37 RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(m_originalSlimmingPain tV2Enabled); 37 RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(m_originalSlimmingPain tV2Enabled);
38 } 38 }
39 39
40 DisplayItemList m_displayItemList; 40 OwnPtr<DisplayItemList> m_displayItemList;
41 bool m_originalSlimmingPaintV2Enabled; 41 bool m_originalSlimmingPaintV2Enabled;
42 }; 42 };
43 43
44 const DisplayItem::Type foregroundDrawingType = static_cast<DisplayItem::Type>(D isplayItem::DrawingPaintPhaseFirst + 4); 44 const DisplayItem::Type foregroundDrawingType = static_cast<DisplayItem::Type>(D isplayItem::DrawingPaintPhaseFirst + 4);
45 const DisplayItem::Type backgroundDrawingType = DisplayItem::DrawingPaintPhaseFi rst; 45 const DisplayItem::Type backgroundDrawingType = DisplayItem::DrawingPaintPhaseFi rst;
46 const DisplayItem::Type clipType = DisplayItem::ClipFirst; 46 const DisplayItem::Type clipType = DisplayItem::ClipFirst;
47 47
48 class TestDisplayItemClient { 48 class TestDisplayItemClient {
49 public: 49 public:
50 TestDisplayItemClient(const String& name) 50 TestDisplayItemClient(const String& name)
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 TestDisplayItem(container2, backgroundDrawingType), 487 TestDisplayItem(container2, backgroundDrawingType),
488 TestDisplayItem(content2, backgroundDrawingType), 488 TestDisplayItem(content2, backgroundDrawingType),
489 TestDisplayItem(content2, foregroundDrawingType), 489 TestDisplayItem(content2, foregroundDrawingType),
490 TestDisplayItem(container2, foregroundDrawingType), 490 TestDisplayItem(container2, foregroundDrawingType),
491 TestDisplayItem(container2, DisplayItem::EndSubsequence)); 491 TestDisplayItem(container2, DisplayItem::EndSubsequence));
492 492
493 // 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.
494 EXPECT_TRUE(SubsequenceRecorder::useCachedSubsequenceIfPossible(context, con tainer2)); 494 EXPECT_TRUE(SubsequenceRecorder::useCachedSubsequenceIfPossible(context, con tainer2));
495 EXPECT_TRUE(SubsequenceRecorder::useCachedSubsequenceIfPossible(context, con tainer1)); 495 EXPECT_TRUE(SubsequenceRecorder::useCachedSubsequenceIfPossible(context, con tainer1));
496 496
497 EXPECT_DISPLAY_LIST(newDisplayItemsBeforeUpdate(), 2, 497 EXPECT_DISPLAY_LIST(displayItemList().newDisplayItems(), 2,
498 TestDisplayItem(container2, DisplayItem::CachedSubsequence), 498 TestDisplayItem(container2, DisplayItem::CachedSubsequence),
499 TestDisplayItem(container1, DisplayItem::CachedSubsequence)); 499 TestDisplayItem(container1, DisplayItem::CachedSubsequence));
500 500
501 displayItemList().commitNewDisplayItems(); 501 displayItemList().commitNewDisplayItems();
502 502
503 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 12, 503 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 12,
504 TestDisplayItem(container2, DisplayItem::BeginSubsequence), 504 TestDisplayItem(container2, DisplayItem::BeginSubsequence),
505 TestDisplayItem(container2, backgroundDrawingType), 505 TestDisplayItem(container2, backgroundDrawingType),
506 TestDisplayItem(content2, backgroundDrawingType), 506 TestDisplayItem(content2, backgroundDrawingType),
507 TestDisplayItem(content2, foregroundDrawingType), 507 TestDisplayItem(content2, foregroundDrawingType),
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 drawRect(context, content2, foregroundDrawingType, FloatRect(100, 200, 5 0, 200)); 601 drawRect(context, content2, foregroundDrawingType, FloatRect(100, 200, 5 0, 200));
602 } 602 }
603 // Repaint container1 with foreground only. 603 // Repaint container1 with foreground only.
604 { 604 {
605 EXPECT_FALSE(SubsequenceRecorder::useCachedSubsequenceIfPossible(context , container1)); 605 EXPECT_FALSE(SubsequenceRecorder::useCachedSubsequenceIfPossible(context , container1));
606 SubsequenceRecorder r(context, container1); 606 SubsequenceRecorder r(context, container1);
607 // Use cached subsequence of content1. 607 // Use cached subsequence of content1.
608 EXPECT_TRUE(SubsequenceRecorder::useCachedSubsequenceIfPossible(context, content1)); 608 EXPECT_TRUE(SubsequenceRecorder::useCachedSubsequenceIfPossible(context, content1));
609 drawRect(context, container1, foregroundDrawingType, FloatRect(100, 100, 100, 100)); 609 drawRect(context, container1, foregroundDrawingType, FloatRect(100, 100, 100, 100));
610 } 610 }
611 EXPECT_DISPLAY_LIST(newDisplayItemsBeforeUpdate(), 7, 611 EXPECT_DISPLAY_LIST(displayItemList().newDisplayItems(), 7,
612 TestDisplayItem(content2, DisplayItem::BeginSubsequence), 612 TestDisplayItem(content2, DisplayItem::BeginSubsequence),
613 TestDisplayItem(content2, foregroundDrawingType), 613 TestDisplayItem(content2, foregroundDrawingType),
614 TestDisplayItem(content2, DisplayItem::EndSubsequence), 614 TestDisplayItem(content2, DisplayItem::EndSubsequence),
615 TestDisplayItem(container1, DisplayItem::BeginSubsequence), 615 TestDisplayItem(container1, DisplayItem::BeginSubsequence),
616 TestDisplayItem(content1, DisplayItem::CachedSubsequence), 616 TestDisplayItem(content1, DisplayItem::CachedSubsequence),
617 TestDisplayItem(container1, foregroundDrawingType), 617 TestDisplayItem(container1, foregroundDrawingType),
618 TestDisplayItem(container1, DisplayItem::EndSubsequence)); 618 TestDisplayItem(container1, DisplayItem::EndSubsequence));
619 619
620 displayItemList().commitNewDisplayItems(); 620 displayItemList().commitNewDisplayItems();
621 621
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 EXPECT_TRUE(displayItemList().clientCacheIsValid(multicol.displayItemClient( ))); 666 EXPECT_TRUE(displayItemList().clientCacheIsValid(multicol.displayItemClient( )));
667 drawRect(context, multicol, backgroundDrawingType, FloatRect(100, 200, 100, 100)); 667 drawRect(context, multicol, backgroundDrawingType, FloatRect(100, 200, 100, 100));
668 displayItemList().beginScope(); 668 displayItemList().beginScope();
669 drawRect(context, content, foregroundDrawingType, rect1); 669 drawRect(context, content, foregroundDrawingType, rect1);
670 displayItemList().endScope(); 670 displayItemList().endScope();
671 671
672 displayItemList().beginScope(); 672 displayItemList().beginScope();
673 drawRect(context, content, foregroundDrawingType, rect2); 673 drawRect(context, content, foregroundDrawingType, rect2);
674 displayItemList().endScope(); 674 displayItemList().endScope();
675 675
676 EXPECT_TRUE(newDisplayItemsBeforeUpdate()[0].isCachedDrawing()); 676 EXPECT_DISPLAY_LIST(displayItemList().newDisplayItems(), 3,
677 EXPECT_TRUE(newDisplayItemsBeforeUpdate()[1].isDrawing()); 677 TestDisplayItem(multicol, DisplayItem::drawingTypeToCachedDrawingType(ba ckgroundDrawingType)),
678 EXPECT_TRUE(newDisplayItemsBeforeUpdate()[2].isDrawing()); 678 TestDisplayItem(content, foregroundDrawingType),
679 TestDisplayItem(content, foregroundDrawingType));
680
679 displayItemList().commitNewDisplayItems(); 681 displayItemList().commitNewDisplayItems();
680 682
681 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 3, 683 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 3,
682 TestDisplayItem(multicol, backgroundDrawingType), 684 TestDisplayItem(multicol, backgroundDrawingType),
683 TestDisplayItem(content, foregroundDrawingType), 685 TestDisplayItem(content, foregroundDrawingType),
684 TestDisplayItem(content, foregroundDrawingType)); 686 TestDisplayItem(content, foregroundDrawingType));
685 EXPECT_NE(picture1, static_cast<const DrawingDisplayItem&>(displayItemList() .displayItems()[1]).picture()); 687 EXPECT_NE(picture1, static_cast<const DrawingDisplayItem&>(displayItemList() .displayItems()[1]).picture());
686 EXPECT_NE(picture2, static_cast<const DrawingDisplayItem&>(displayItemList() .displayItems()[2]).picture()); 688 EXPECT_NE(picture2, static_cast<const DrawingDisplayItem&>(displayItemList() .displayItems()[2]).picture());
687 689
688 // Now the multicol becomes 3 columns and repaints. 690 // Now the multicol becomes 3 columns and repaints.
689 displayItemList().invalidate(multicol); 691 displayItemList().invalidate(multicol);
690 drawRect(context, multicol, backgroundDrawingType, FloatRect(100, 100, 100, 100)); 692 drawRect(context, multicol, backgroundDrawingType, FloatRect(100, 100, 100, 100));
691 693
692 displayItemList().beginScope(); 694 displayItemList().beginScope();
693 drawRect(context, content, foregroundDrawingType, rect1); 695 drawRect(context, content, foregroundDrawingType, rect1);
694 displayItemList().endScope(); 696 displayItemList().endScope();
695 697
696 displayItemList().beginScope(); 698 displayItemList().beginScope();
697 drawRect(context, content, foregroundDrawingType, rect2); 699 drawRect(context, content, foregroundDrawingType, rect2);
698 displayItemList().endScope(); 700 displayItemList().endScope();
699 701
700 displayItemList().beginScope(); 702 displayItemList().beginScope();
701 drawRect(context, content, foregroundDrawingType, rect3); 703 drawRect(context, content, foregroundDrawingType, rect3);
702 displayItemList().endScope(); 704 displayItemList().endScope();
703 705
704 // We should repaint everything on invalidation of the scope container. 706 // We should repaint everything on invalidation of the scope container.
705 EXPECT_TRUE(newDisplayItemsBeforeUpdate()[0].isDrawing()); 707 EXPECT_DISPLAY_LIST(displayItemList().newDisplayItems(), 4,
706 EXPECT_TRUE(newDisplayItemsBeforeUpdate()[1].isDrawing());
707 EXPECT_TRUE(newDisplayItemsBeforeUpdate()[2].isDrawing());
708 EXPECT_TRUE(newDisplayItemsBeforeUpdate()[3].isDrawing());
709 displayItemList().commitNewDisplayItems();
710
711 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 4,
712 TestDisplayItem(multicol, backgroundDrawingType), 708 TestDisplayItem(multicol, backgroundDrawingType),
713 TestDisplayItem(content, foregroundDrawingType), 709 TestDisplayItem(content, foregroundDrawingType),
714 TestDisplayItem(content, foregroundDrawingType), 710 TestDisplayItem(content, foregroundDrawingType),
715 TestDisplayItem(content, foregroundDrawingType)); 711 TestDisplayItem(content, foregroundDrawingType));
716 EXPECT_NE(picture1, static_cast<const DrawingDisplayItem&>(displayItemList() .displayItems()[1]).picture()); 712 EXPECT_NE(picture1, static_cast<const DrawingDisplayItem&>(displayItemList() .newDisplayItems()[1]).picture());
717 EXPECT_NE(picture2, static_cast<const DrawingDisplayItem&>(displayItemList() .displayItems()[2]).picture()); 713 EXPECT_NE(picture2, static_cast<const DrawingDisplayItem&>(displayItemList() .newDisplayItems()[2]).picture());
714
715 displayItemList().commitNewDisplayItems();
718 } 716 }
719 717
720 TEST_F(DisplayItemListTest, OptimizeNoopPairs) 718 TEST_F(DisplayItemListTest, OptimizeNoopPairs)
721 { 719 {
722 TestDisplayItemClient first("first"); 720 TestDisplayItemClient first("first");
723 TestDisplayItemClient second("second"); 721 TestDisplayItemClient second("second");
724 TestDisplayItemClient third("third"); 722 TestDisplayItemClient third("third");
725 723
726 GraphicsContext context(&displayItemList()); 724 GraphicsContext context(&displayItemList());
727 drawRect(context, first, backgroundDrawingType, FloatRect(0, 0, 100, 100)); 725 drawRect(context, first, backgroundDrawingType, FloatRect(0, 0, 100, 100));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 drawRect(context, third, backgroundDrawingType, FloatRect(0, 0, 100, 100)); 763 drawRect(context, third, backgroundDrawingType, FloatRect(0, 0, 100, 100));
766 displayItemList().commitNewDisplayItems(); 764 displayItemList().commitNewDisplayItems();
767 765
768 // Empty clips should have been optimized out. 766 // Empty clips should have been optimized out.
769 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 2, 767 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 2,
770 TestDisplayItem(first, backgroundDrawingType), 768 TestDisplayItem(first, backgroundDrawingType),
771 TestDisplayItem(third, backgroundDrawingType)); 769 TestDisplayItem(third, backgroundDrawingType));
772 } 770 }
773 771
774 } // namespace blink 772 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/graphics/paint/DisplayItemList.h ('k') | Source/platform/graphics/paint/DrawingRecorder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698