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

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

Issue 1375393002: Output subsequence for children layers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix blink_platform_unittests and address pdr's comments Created 5 years, 2 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
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"
(...skipping 21 matching lines...) Expand all
32 RuntimeEnabledFeatures::setSlimmingPaintSubsequenceCachingEnabled(m_orig inalSlimmingPaintSubsequenceCachingEnabled); 32 RuntimeEnabledFeatures::setSlimmingPaintSubsequenceCachingEnabled(m_orig inalSlimmingPaintSubsequenceCachingEnabled);
33 } 33 }
34 34
35 OwnPtr<DisplayItemList> m_displayItemList; 35 OwnPtr<DisplayItemList> m_displayItemList;
36 bool m_originalSlimmingPaintSubsequenceCachingEnabled; 36 bool m_originalSlimmingPaintSubsequenceCachingEnabled;
37 }; 37 };
38 38
39 const DisplayItem::Type foregroundDrawingType = static_cast<DisplayItem::Type>(D isplayItem::DrawingPaintPhaseFirst + 4); 39 const DisplayItem::Type foregroundDrawingType = static_cast<DisplayItem::Type>(D isplayItem::DrawingPaintPhaseFirst + 4);
40 const DisplayItem::Type backgroundDrawingType = DisplayItem::DrawingPaintPhaseFi rst; 40 const DisplayItem::Type backgroundDrawingType = DisplayItem::DrawingPaintPhaseFi rst;
41 const DisplayItem::Type clipType = DisplayItem::ClipFirst; 41 const DisplayItem::Type clipType = DisplayItem::ClipFirst;
42 const DisplayItem::Type subsequenceType = DisplayItem::SubsequenceNormalFlowAndP ositiveZOrder;
pdr. 2015/09/30 23:36:54 Aren't these already defined in the header?
Xianzhu 2015/09/30 23:48:48 These are defined in Source/core/paint/DisplayItem
43 const DisplayItem::Type endSubsequenceType = DisplayItem::subsequenceTypeToEndSu bsequenceType(subsequenceType);
44 const DisplayItem::Type cachedSubsequenceType = DisplayItem::subsequenceTypeToCa chedSubsequenceType(subsequenceType);
42 45
43 class TestDisplayItemClient { 46 class TestDisplayItemClient {
44 public: 47 public:
45 TestDisplayItemClient(const String& name) 48 TestDisplayItemClient(const String& name)
46 : m_name(name) 49 : m_name(name)
47 { } 50 { }
48 51
49 DisplayItemClient displayItemClient() const { return toDisplayItemClient(thi s); } 52 DisplayItemClient displayItemClient() const { return toDisplayItemClient(thi s); }
50 String debugName() const { return m_name; } 53 String debugName() const { return m_name; }
51 54
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 { 453 {
451 RuntimeEnabledFeatures::setSlimmingPaintSubsequenceCachingEnabled(true); 454 RuntimeEnabledFeatures::setSlimmingPaintSubsequenceCachingEnabled(true);
452 455
453 TestDisplayItemClient container1("container1"); 456 TestDisplayItemClient container1("container1");
454 TestDisplayItemClient content1("content1"); 457 TestDisplayItemClient content1("content1");
455 TestDisplayItemClient container2("container2"); 458 TestDisplayItemClient container2("container2");
456 TestDisplayItemClient content2("content2"); 459 TestDisplayItemClient content2("content2");
457 GraphicsContext context(&displayItemList()); 460 GraphicsContext context(&displayItemList());
458 461
459 { 462 {
460 SubsequenceRecorder r(context, container1); 463 SubsequenceRecorder r(context, container1, subsequenceType);
461 drawRect(context, container1, backgroundDrawingType, FloatRect(100, 100, 100, 100)); 464 drawRect(context, container1, backgroundDrawingType, FloatRect(100, 100, 100, 100));
462 drawRect(context, content1, backgroundDrawingType, FloatRect(100, 100, 5 0, 200)); 465 drawRect(context, content1, backgroundDrawingType, FloatRect(100, 100, 5 0, 200));
463 drawRect(context, content1, foregroundDrawingType, FloatRect(100, 100, 5 0, 200)); 466 drawRect(context, content1, foregroundDrawingType, FloatRect(100, 100, 5 0, 200));
464 drawRect(context, container1, foregroundDrawingType, FloatRect(100, 100, 100, 100)); 467 drawRect(context, container1, foregroundDrawingType, FloatRect(100, 100, 100, 100));
465 } 468 }
466 { 469 {
467 SubsequenceRecorder r(context, container2); 470 SubsequenceRecorder r(context, container2, subsequenceType);
468 drawRect(context, container2, backgroundDrawingType, FloatRect(100, 200, 100, 100)); 471 drawRect(context, container2, backgroundDrawingType, FloatRect(100, 200, 100, 100));
469 drawRect(context, content2, backgroundDrawingType, FloatRect(100, 200, 5 0, 200)); 472 drawRect(context, content2, backgroundDrawingType, FloatRect(100, 200, 5 0, 200));
470 drawRect(context, content2, foregroundDrawingType, FloatRect(100, 200, 5 0, 200)); 473 drawRect(context, content2, foregroundDrawingType, FloatRect(100, 200, 5 0, 200));
471 drawRect(context, container2, foregroundDrawingType, FloatRect(100, 200, 100, 100)); 474 drawRect(context, container2, foregroundDrawingType, FloatRect(100, 200, 100, 100));
472 } 475 }
473 displayItemList().commitNewDisplayItems(); 476 displayItemList().commitNewDisplayItems();
474 477
475 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 12, 478 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 12,
476 TestDisplayItem(container1, DisplayItem::BeginSubsequence), 479 TestDisplayItem(container1, subsequenceType),
477 TestDisplayItem(container1, backgroundDrawingType), 480 TestDisplayItem(container1, backgroundDrawingType),
478 TestDisplayItem(content1, backgroundDrawingType), 481 TestDisplayItem(content1, backgroundDrawingType),
479 TestDisplayItem(content1, foregroundDrawingType), 482 TestDisplayItem(content1, foregroundDrawingType),
480 TestDisplayItem(container1, foregroundDrawingType), 483 TestDisplayItem(container1, foregroundDrawingType),
481 TestDisplayItem(container1, DisplayItem::EndSubsequence), 484 TestDisplayItem(container1, endSubsequenceType),
482 485
483 TestDisplayItem(container2, DisplayItem::BeginSubsequence), 486 TestDisplayItem(container2, subsequenceType),
484 TestDisplayItem(container2, backgroundDrawingType), 487 TestDisplayItem(container2, backgroundDrawingType),
485 TestDisplayItem(content2, backgroundDrawingType), 488 TestDisplayItem(content2, backgroundDrawingType),
486 TestDisplayItem(content2, foregroundDrawingType), 489 TestDisplayItem(content2, foregroundDrawingType),
487 TestDisplayItem(container2, foregroundDrawingType), 490 TestDisplayItem(container2, foregroundDrawingType),
488 TestDisplayItem(container2, DisplayItem::EndSubsequence)); 491 TestDisplayItem(container2, endSubsequenceType));
489 492
490 // 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.
491 EXPECT_TRUE(SubsequenceRecorder::useCachedSubsequenceIfPossible(context, con tainer2)); 494 EXPECT_TRUE(SubsequenceRecorder::useCachedSubsequenceIfPossible(context, con tainer2, subsequenceType));
492 EXPECT_TRUE(SubsequenceRecorder::useCachedSubsequenceIfPossible(context, con tainer1)); 495 EXPECT_TRUE(SubsequenceRecorder::useCachedSubsequenceIfPossible(context, con tainer1, subsequenceType));
493 496
494 EXPECT_DISPLAY_LIST(displayItemList().newDisplayItems(), 2, 497 EXPECT_DISPLAY_LIST(displayItemList().newDisplayItems(), 2,
495 TestDisplayItem(container2, DisplayItem::CachedSubsequence), 498 TestDisplayItem(container2, cachedSubsequenceType),
496 TestDisplayItem(container1, DisplayItem::CachedSubsequence)); 499 TestDisplayItem(container1, cachedSubsequenceType));
497 500
498 displayItemList().commitNewDisplayItems(); 501 displayItemList().commitNewDisplayItems();
499 502
500 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 12, 503 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 12,
501 TestDisplayItem(container2, DisplayItem::BeginSubsequence), 504 TestDisplayItem(container2, subsequenceType),
502 TestDisplayItem(container2, backgroundDrawingType), 505 TestDisplayItem(container2, backgroundDrawingType),
503 TestDisplayItem(content2, backgroundDrawingType), 506 TestDisplayItem(content2, backgroundDrawingType),
504 TestDisplayItem(content2, foregroundDrawingType), 507 TestDisplayItem(content2, foregroundDrawingType),
505 TestDisplayItem(container2, foregroundDrawingType), 508 TestDisplayItem(container2, foregroundDrawingType),
506 TestDisplayItem(container2, DisplayItem::EndSubsequence), 509 TestDisplayItem(container2, endSubsequenceType),
507 510
508 TestDisplayItem(container1, DisplayItem::BeginSubsequence), 511 TestDisplayItem(container1, subsequenceType),
509 TestDisplayItem(container1, backgroundDrawingType), 512 TestDisplayItem(container1, backgroundDrawingType),
510 TestDisplayItem(content1, backgroundDrawingType), 513 TestDisplayItem(content1, backgroundDrawingType),
511 TestDisplayItem(content1, foregroundDrawingType), 514 TestDisplayItem(content1, foregroundDrawingType),
512 TestDisplayItem(container1, foregroundDrawingType), 515 TestDisplayItem(container1, foregroundDrawingType),
513 TestDisplayItem(container1, DisplayItem::EndSubsequence)); 516 TestDisplayItem(container1, endSubsequenceType));
514 } 517 }
515 518
516 TEST_F(DisplayItemListTest, OutOfOrderNoCrash) 519 TEST_F(DisplayItemListTest, OutOfOrderNoCrash)
517 { 520 {
518 TestDisplayItemClient client("client"); 521 TestDisplayItemClient client("client");
519 GraphicsContext context(&displayItemList()); 522 GraphicsContext context(&displayItemList());
520 523
521 const DisplayItem::Type type1 = DisplayItem::DrawingFirst; 524 const DisplayItem::Type type1 = DisplayItem::DrawingFirst;
522 const DisplayItem::Type type2 = static_cast<DisplayItem::Type>(DisplayItem:: DrawingFirst + 1); 525 const DisplayItem::Type type2 = static_cast<DisplayItem::Type>(DisplayItem:: DrawingFirst + 1);
523 const DisplayItem::Type type3 = static_cast<DisplayItem::Type>(DisplayItem:: DrawingFirst + 2); 526 const DisplayItem::Type type3 = static_cast<DisplayItem::Type>(DisplayItem:: DrawingFirst + 2);
(...skipping 18 matching lines...) Expand all
542 { 545 {
543 RuntimeEnabledFeatures::setSlimmingPaintSubsequenceCachingEnabled(true); 546 RuntimeEnabledFeatures::setSlimmingPaintSubsequenceCachingEnabled(true);
544 547
545 TestDisplayItemClient container1("container1"); 548 TestDisplayItemClient container1("container1");
546 TestDisplayItemClient content1("content1"); 549 TestDisplayItemClient content1("content1");
547 TestDisplayItemClient container2("container2"); 550 TestDisplayItemClient container2("container2");
548 TestDisplayItemClient content2("content2"); 551 TestDisplayItemClient content2("content2");
549 GraphicsContext context(&displayItemList()); 552 GraphicsContext context(&displayItemList());
550 553
551 { 554 {
552 SubsequenceRecorder r(context, container1); 555 SubsequenceRecorder r(context, container1, subsequenceType);
553 drawRect(context, container1, backgroundDrawingType, FloatRect(100, 100, 100, 100)); 556 drawRect(context, container1, backgroundDrawingType, FloatRect(100, 100, 100, 100));
554 { 557 {
555 SubsequenceRecorder r(context, content1); 558 SubsequenceRecorder r(context, content1, subsequenceType);
556 drawRect(context, content1, backgroundDrawingType, FloatRect(100, 10 0, 50, 200)); 559 drawRect(context, content1, backgroundDrawingType, FloatRect(100, 10 0, 50, 200));
557 drawRect(context, content1, foregroundDrawingType, FloatRect(100, 10 0, 50, 200)); 560 drawRect(context, content1, foregroundDrawingType, FloatRect(100, 10 0, 50, 200));
558 } 561 }
559 drawRect(context, container1, foregroundDrawingType, FloatRect(100, 100, 100, 100)); 562 drawRect(context, container1, foregroundDrawingType, FloatRect(100, 100, 100, 100));
560 } 563 }
561 { 564 {
562 SubsequenceRecorder r(context, container2); 565 SubsequenceRecorder r(context, container2, subsequenceType);
563 drawRect(context, container2, backgroundDrawingType, FloatRect(100, 200, 100, 100)); 566 drawRect(context, container2, backgroundDrawingType, FloatRect(100, 200, 100, 100));
564 { 567 {
565 SubsequenceRecorder r(context, content2); 568 SubsequenceRecorder r(context, content2, subsequenceType);
566 drawRect(context, content2, backgroundDrawingType, FloatRect(100, 20 0, 50, 200)); 569 drawRect(context, content2, backgroundDrawingType, FloatRect(100, 20 0, 50, 200));
567 } 570 }
568 } 571 }
569 displayItemList().commitNewDisplayItems(); 572 displayItemList().commitNewDisplayItems();
570 573
571 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 14, 574 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 14,
572 TestDisplayItem(container1, DisplayItem::BeginSubsequence), 575 TestDisplayItem(container1, subsequenceType),
573 TestDisplayItem(container1, backgroundDrawingType), 576 TestDisplayItem(container1, backgroundDrawingType),
574 TestDisplayItem(content1, DisplayItem::BeginSubsequence), 577 TestDisplayItem(content1, subsequenceType),
575 TestDisplayItem(content1, backgroundDrawingType), 578 TestDisplayItem(content1, backgroundDrawingType),
576 TestDisplayItem(content1, foregroundDrawingType), 579 TestDisplayItem(content1, foregroundDrawingType),
577 TestDisplayItem(content1, DisplayItem::EndSubsequence), 580 TestDisplayItem(content1, endSubsequenceType),
578 TestDisplayItem(container1, foregroundDrawingType), 581 TestDisplayItem(container1, foregroundDrawingType),
579 TestDisplayItem(container1, DisplayItem::EndSubsequence), 582 TestDisplayItem(container1, endSubsequenceType),
580 583
581 TestDisplayItem(container2, DisplayItem::BeginSubsequence), 584 TestDisplayItem(container2, subsequenceType),
582 TestDisplayItem(container2, backgroundDrawingType), 585 TestDisplayItem(container2, backgroundDrawingType),
583 TestDisplayItem(content2, DisplayItem::BeginSubsequence), 586 TestDisplayItem(content2, subsequenceType),
584 TestDisplayItem(content2, backgroundDrawingType), 587 TestDisplayItem(content2, backgroundDrawingType),
585 TestDisplayItem(content2, DisplayItem::EndSubsequence), 588 TestDisplayItem(content2, endSubsequenceType),
586 TestDisplayItem(container2, DisplayItem::EndSubsequence)); 589 TestDisplayItem(container2, endSubsequenceType));
587 590
588 // Invalidate container1 but not content1. 591 // Invalidate container1 but not content1.
589 displayItemList().invalidate(container1); 592 displayItemList().invalidate(container1);
590 593
591 // Container2 itself now becomes empty (but still has the 'content2' child), 594 // Container2 itself now becomes empty (but still has the 'content2' child),
592 // and chooses not to output subsequence info. 595 // and chooses not to output subsequence info.
593 displayItemList().invalidate(container2); 596 displayItemList().invalidate(container2);
594 displayItemList().invalidate(content2); 597 displayItemList().invalidate(content2);
595 EXPECT_FALSE(SubsequenceRecorder::useCachedSubsequenceIfPossible(context, co ntainer2)); 598 EXPECT_FALSE(SubsequenceRecorder::useCachedSubsequenceIfPossible(context, co ntainer2, subsequenceType));
596 EXPECT_FALSE(SubsequenceRecorder::useCachedSubsequenceIfPossible(context, co ntent2)); 599 EXPECT_FALSE(SubsequenceRecorder::useCachedSubsequenceIfPossible(context, co ntent2, subsequenceType));
597 // Content2 now outputs foreground only. 600 // Content2 now outputs foreground only.
598 { 601 {
599 SubsequenceRecorder r(context, content2); 602 SubsequenceRecorder r(context, content2, subsequenceType);
600 drawRect(context, content2, foregroundDrawingType, FloatRect(100, 200, 5 0, 200)); 603 drawRect(context, content2, foregroundDrawingType, FloatRect(100, 200, 5 0, 200));
601 } 604 }
602 // Repaint container1 with foreground only. 605 // Repaint container1 with foreground only.
603 { 606 {
604 EXPECT_FALSE(SubsequenceRecorder::useCachedSubsequenceIfPossible(context , container1)); 607 EXPECT_FALSE(SubsequenceRecorder::useCachedSubsequenceIfPossible(context , container1, subsequenceType));
605 SubsequenceRecorder r(context, container1); 608 SubsequenceRecorder r(context, container1, subsequenceType);
606 // Use cached subsequence of content1. 609 // Use cached subsequence of content1.
607 EXPECT_TRUE(SubsequenceRecorder::useCachedSubsequenceIfPossible(context, content1)); 610 EXPECT_TRUE(SubsequenceRecorder::useCachedSubsequenceIfPossible(context, content1, subsequenceType));
608 drawRect(context, container1, foregroundDrawingType, FloatRect(100, 100, 100, 100)); 611 drawRect(context, container1, foregroundDrawingType, FloatRect(100, 100, 100, 100));
609 } 612 }
610 EXPECT_DISPLAY_LIST(displayItemList().newDisplayItems(), 7, 613 EXPECT_DISPLAY_LIST(displayItemList().newDisplayItems(), 7,
611 TestDisplayItem(content2, DisplayItem::BeginSubsequence), 614 TestDisplayItem(content2, subsequenceType),
612 TestDisplayItem(content2, foregroundDrawingType), 615 TestDisplayItem(content2, foregroundDrawingType),
613 TestDisplayItem(content2, DisplayItem::EndSubsequence), 616 TestDisplayItem(content2, endSubsequenceType),
614 TestDisplayItem(container1, DisplayItem::BeginSubsequence), 617 TestDisplayItem(container1, subsequenceType),
615 TestDisplayItem(content1, DisplayItem::CachedSubsequence), 618 TestDisplayItem(content1, cachedSubsequenceType),
616 TestDisplayItem(container1, foregroundDrawingType), 619 TestDisplayItem(container1, foregroundDrawingType),
617 TestDisplayItem(container1, DisplayItem::EndSubsequence)); 620 TestDisplayItem(container1, endSubsequenceType));
618 621
619 displayItemList().commitNewDisplayItems(); 622 displayItemList().commitNewDisplayItems();
620 623
621 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 10, 624 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 10,
622 TestDisplayItem(content2, DisplayItem::BeginSubsequence), 625 TestDisplayItem(content2, subsequenceType),
623 TestDisplayItem(content2, foregroundDrawingType), 626 TestDisplayItem(content2, foregroundDrawingType),
624 TestDisplayItem(content2, DisplayItem::EndSubsequence), 627 TestDisplayItem(content2, endSubsequenceType),
625 628
626 TestDisplayItem(container1, DisplayItem::BeginSubsequence), 629 TestDisplayItem(container1, subsequenceType),
627 TestDisplayItem(content1, DisplayItem::BeginSubsequence), 630 TestDisplayItem(content1, subsequenceType),
628 TestDisplayItem(content1, backgroundDrawingType), 631 TestDisplayItem(content1, backgroundDrawingType),
629 TestDisplayItem(content1, foregroundDrawingType), 632 TestDisplayItem(content1, foregroundDrawingType),
630 TestDisplayItem(content1, DisplayItem::EndSubsequence), 633 TestDisplayItem(content1, endSubsequenceType),
631 TestDisplayItem(container1, foregroundDrawingType), 634 TestDisplayItem(container1, foregroundDrawingType),
632 TestDisplayItem(container1, DisplayItem::EndSubsequence)); 635 TestDisplayItem(container1, endSubsequenceType));
633 } 636 }
634 637
635 TEST_F(DisplayItemListTest, Scope) 638 TEST_F(DisplayItemListTest, Scope)
636 { 639 {
637 TestDisplayItemClient multicol("multicol"); 640 TestDisplayItemClient multicol("multicol");
638 TestDisplayItemClient content("content"); 641 TestDisplayItemClient content("content");
639 GraphicsContext context(&displayItemList()); 642 GraphicsContext context(&displayItemList());
640 643
641 FloatRect rect1(100, 100, 50, 50); 644 FloatRect rect1(100, 100, 50, 50);
642 FloatRect rect2(150, 100, 50, 50); 645 FloatRect rect2(150, 100, 50, 50);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 drawRect(context, third, backgroundDrawingType, FloatRect(0, 0, 100, 100)); 765 drawRect(context, third, backgroundDrawingType, FloatRect(0, 0, 100, 100));
763 displayItemList().commitNewDisplayItems(); 766 displayItemList().commitNewDisplayItems();
764 767
765 // Empty clips should have been optimized out. 768 // Empty clips should have been optimized out.
766 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 2, 769 EXPECT_DISPLAY_LIST(displayItemList().displayItems(), 2,
767 TestDisplayItem(first, backgroundDrawingType), 770 TestDisplayItem(first, backgroundDrawingType),
768 TestDisplayItem(third, backgroundDrawingType)); 771 TestDisplayItem(third, backgroundDrawingType));
769 } 772 }
770 773
771 } // namespace blink 774 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698