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

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

Issue 1425593007: Separate display item clients for negative and normal/positive z-order children (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Struct DisplayItemClient Created 5 years, 1 month 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/PaintController.h" 6 #include "platform/graphics/paint/PaintController.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 24 matching lines...) Expand all
35 } 35 }
36 36
37 OwnPtr<PaintController> m_paintController; 37 OwnPtr<PaintController> m_paintController;
38 bool m_originalSlimmingPaintSynchronizedPaintingEnabled; 38 bool m_originalSlimmingPaintSynchronizedPaintingEnabled;
39 bool m_originalSlimmingPaintV2Enabled; 39 bool m_originalSlimmingPaintV2Enabled;
40 }; 40 };
41 41
42 const DisplayItem::Type foregroundDrawingType = static_cast<DisplayItem::Type>(D isplayItem::DrawingPaintPhaseFirst + 4); 42 const DisplayItem::Type foregroundDrawingType = static_cast<DisplayItem::Type>(D isplayItem::DrawingPaintPhaseFirst + 4);
43 const DisplayItem::Type backgroundDrawingType = DisplayItem::DrawingPaintPhaseFi rst; 43 const DisplayItem::Type backgroundDrawingType = DisplayItem::DrawingPaintPhaseFi rst;
44 const DisplayItem::Type clipType = DisplayItem::ClipFirst; 44 const DisplayItem::Type clipType = DisplayItem::ClipFirst;
45 const DisplayItem::Type subsequenceType = DisplayItem::SubsequenceNormalFlowAndP ositiveZOrder;
46 const DisplayItem::Type endSubsequenceType = DisplayItem::subsequenceTypeToEndSu bsequenceType(subsequenceType);
47 const DisplayItem::Type cachedSubsequenceType = DisplayItem::subsequenceTypeToCa chedSubsequenceType(subsequenceType);
48 45
49 class TestDisplayItemClient { 46 class TestDisplayItemClient {
50 public: 47 public:
51 TestDisplayItemClient(const String& name) 48 TestDisplayItemClient(const String& name)
52 : m_name(name) 49 : m_name(name)
53 { } 50 { }
54 51
55 DisplayItemClient displayItemClient() const { return toDisplayItemClient(thi s); } 52 DisplayItemClient displayItemClient() const { return DisplayItemClient(this) ; }
56 String debugName() const { return m_name; } 53 String debugName() const { return m_name; }
57 54
58 private: 55 private:
59 String m_name; 56 String m_name;
60 }; 57 };
61 58
62 class TestDisplayItem final : public DisplayItem { 59 class TestDisplayItem final : public DisplayItem {
63 public: 60 public:
64 TestDisplayItem(const TestDisplayItemClient& client, Type type) : DisplayIte m(client, type, sizeof(*this)) { } 61 TestDisplayItem(const TestDisplayItemClient& client, Type type) : DisplayIte m(client, type, sizeof(*this)) { }
65 62
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 { 453 {
457 RuntimeEnabledFeatures::setSlimmingPaintSynchronizedPaintingEnabled(true); 454 RuntimeEnabledFeatures::setSlimmingPaintSynchronizedPaintingEnabled(true);
458 455
459 TestDisplayItemClient container1("container1"); 456 TestDisplayItemClient container1("container1");
460 TestDisplayItemClient content1("content1"); 457 TestDisplayItemClient content1("content1");
461 TestDisplayItemClient container2("container2"); 458 TestDisplayItemClient container2("container2");
462 TestDisplayItemClient content2("content2"); 459 TestDisplayItemClient content2("content2");
463 GraphicsContext context(paintController()); 460 GraphicsContext context(paintController());
464 461
465 { 462 {
466 SubsequenceRecorder r(context, container1, subsequenceType); 463 SubsequenceRecorder r(context, container1);
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 drawRect(context, content1, foregroundDrawingType, FloatRect(100, 100, 5 0, 200)); 466 drawRect(context, content1, foregroundDrawingType, FloatRect(100, 100, 5 0, 200));
470 drawRect(context, container1, foregroundDrawingType, FloatRect(100, 100, 100, 100)); 467 drawRect(context, container1, foregroundDrawingType, FloatRect(100, 100, 100, 100));
471 } 468 }
472 { 469 {
473 SubsequenceRecorder r(context, container2, subsequenceType); 470 SubsequenceRecorder r(context, container2);
474 drawRect(context, container2, backgroundDrawingType, FloatRect(100, 200, 100, 100)); 471 drawRect(context, container2, backgroundDrawingType, FloatRect(100, 200, 100, 100));
475 drawRect(context, content2, backgroundDrawingType, FloatRect(100, 200, 5 0, 200)); 472 drawRect(context, content2, backgroundDrawingType, FloatRect(100, 200, 5 0, 200));
476 drawRect(context, content2, foregroundDrawingType, FloatRect(100, 200, 5 0, 200)); 473 drawRect(context, content2, foregroundDrawingType, FloatRect(100, 200, 5 0, 200));
477 drawRect(context, container2, foregroundDrawingType, FloatRect(100, 200, 100, 100)); 474 drawRect(context, container2, foregroundDrawingType, FloatRect(100, 200, 100, 100));
478 } 475 }
479 paintController().commitNewDisplayItems(); 476 paintController().commitNewDisplayItems();
480 477
481 EXPECT_DISPLAY_LIST(paintController().displayItemList(), 12, 478 EXPECT_DISPLAY_LIST(paintController().displayItemList(), 12,
482 TestDisplayItem(container1, subsequenceType), 479 TestDisplayItem(container1, DisplayItem::Subsequence),
483 TestDisplayItem(container1, backgroundDrawingType), 480 TestDisplayItem(container1, backgroundDrawingType),
484 TestDisplayItem(content1, backgroundDrawingType), 481 TestDisplayItem(content1, backgroundDrawingType),
485 TestDisplayItem(content1, foregroundDrawingType), 482 TestDisplayItem(content1, foregroundDrawingType),
486 TestDisplayItem(container1, foregroundDrawingType), 483 TestDisplayItem(container1, foregroundDrawingType),
487 TestDisplayItem(container1, endSubsequenceType), 484 TestDisplayItem(container1, DisplayItem::EndSubsequence),
488 485
489 TestDisplayItem(container2, subsequenceType), 486 TestDisplayItem(container2, DisplayItem::Subsequence),
490 TestDisplayItem(container2, backgroundDrawingType), 487 TestDisplayItem(container2, backgroundDrawingType),
491 TestDisplayItem(content2, backgroundDrawingType), 488 TestDisplayItem(content2, backgroundDrawingType),
492 TestDisplayItem(content2, foregroundDrawingType), 489 TestDisplayItem(content2, foregroundDrawingType),
493 TestDisplayItem(container2, foregroundDrawingType), 490 TestDisplayItem(container2, foregroundDrawingType),
494 TestDisplayItem(container2, endSubsequenceType)); 491 TestDisplayItem(container2, DisplayItem::EndSubsequence));
495 492
496 // 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.
497 EXPECT_TRUE(SubsequenceRecorder::useCachedSubsequenceIfPossible(context, con tainer2, subsequenceType)); 494 EXPECT_TRUE(SubsequenceRecorder::useCachedSubsequenceIfPossible(context, con tainer2));
498 EXPECT_TRUE(SubsequenceRecorder::useCachedSubsequenceIfPossible(context, con tainer1, subsequenceType)); 495 EXPECT_TRUE(SubsequenceRecorder::useCachedSubsequenceIfPossible(context, con tainer1));
499 496
500 EXPECT_DISPLAY_LIST(paintController().newDisplayItemList(), 2, 497 EXPECT_DISPLAY_LIST(paintController().newDisplayItemList(), 2,
501 TestDisplayItem(container2, cachedSubsequenceType), 498 TestDisplayItem(container2, DisplayItem::CachedSubsequence),
502 TestDisplayItem(container1, cachedSubsequenceType)); 499 TestDisplayItem(container1, DisplayItem::CachedSubsequence));
503 500
504 paintController().commitNewDisplayItems(); 501 paintController().commitNewDisplayItems();
505 502
506 EXPECT_DISPLAY_LIST(paintController().displayItemList(), 12, 503 EXPECT_DISPLAY_LIST(paintController().displayItemList(), 12,
507 TestDisplayItem(container2, subsequenceType), 504 TestDisplayItem(container2, DisplayItem::Subsequence),
508 TestDisplayItem(container2, backgroundDrawingType), 505 TestDisplayItem(container2, backgroundDrawingType),
509 TestDisplayItem(content2, backgroundDrawingType), 506 TestDisplayItem(content2, backgroundDrawingType),
510 TestDisplayItem(content2, foregroundDrawingType), 507 TestDisplayItem(content2, foregroundDrawingType),
511 TestDisplayItem(container2, foregroundDrawingType), 508 TestDisplayItem(container2, foregroundDrawingType),
512 TestDisplayItem(container2, endSubsequenceType), 509 TestDisplayItem(container2, DisplayItem::EndSubsequence),
513 510
514 TestDisplayItem(container1, subsequenceType), 511 TestDisplayItem(container1, DisplayItem::Subsequence),
515 TestDisplayItem(container1, backgroundDrawingType), 512 TestDisplayItem(container1, backgroundDrawingType),
516 TestDisplayItem(content1, backgroundDrawingType), 513 TestDisplayItem(content1, backgroundDrawingType),
517 TestDisplayItem(content1, foregroundDrawingType), 514 TestDisplayItem(content1, foregroundDrawingType),
518 TestDisplayItem(container1, foregroundDrawingType), 515 TestDisplayItem(container1, foregroundDrawingType),
519 TestDisplayItem(container1, endSubsequenceType)); 516 TestDisplayItem(container1, DisplayItem::EndSubsequence));
520 } 517 }
521 518
522 TEST_F(PaintControllerTest, OutOfOrderNoCrash) 519 TEST_F(PaintControllerTest, OutOfOrderNoCrash)
523 { 520 {
524 TestDisplayItemClient client("client"); 521 TestDisplayItemClient client("client");
525 GraphicsContext context(paintController()); 522 GraphicsContext context(paintController());
526 523
527 const DisplayItem::Type type1 = DisplayItem::DrawingFirst; 524 const DisplayItem::Type type1 = DisplayItem::DrawingFirst;
528 const DisplayItem::Type type2 = static_cast<DisplayItem::Type>(DisplayItem:: DrawingFirst + 1); 525 const DisplayItem::Type type2 = static_cast<DisplayItem::Type>(DisplayItem:: DrawingFirst + 1);
529 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
548 { 545 {
549 RuntimeEnabledFeatures::setSlimmingPaintSynchronizedPaintingEnabled(true); 546 RuntimeEnabledFeatures::setSlimmingPaintSynchronizedPaintingEnabled(true);
550 547
551 TestDisplayItemClient container1("container1"); 548 TestDisplayItemClient container1("container1");
552 TestDisplayItemClient content1("content1"); 549 TestDisplayItemClient content1("content1");
553 TestDisplayItemClient container2("container2"); 550 TestDisplayItemClient container2("container2");
554 TestDisplayItemClient content2("content2"); 551 TestDisplayItemClient content2("content2");
555 GraphicsContext context(paintController()); 552 GraphicsContext context(paintController());
556 553
557 { 554 {
558 SubsequenceRecorder r(context, container1, subsequenceType); 555 SubsequenceRecorder r(context, container1);
559 drawRect(context, container1, backgroundDrawingType, FloatRect(100, 100, 100, 100)); 556 drawRect(context, container1, backgroundDrawingType, FloatRect(100, 100, 100, 100));
560 { 557 {
561 SubsequenceRecorder r(context, content1, subsequenceType); 558 SubsequenceRecorder r(context, content1);
562 drawRect(context, content1, backgroundDrawingType, FloatRect(100, 10 0, 50, 200)); 559 drawRect(context, content1, backgroundDrawingType, FloatRect(100, 10 0, 50, 200));
563 drawRect(context, content1, foregroundDrawingType, FloatRect(100, 10 0, 50, 200)); 560 drawRect(context, content1, foregroundDrawingType, FloatRect(100, 10 0, 50, 200));
564 } 561 }
565 drawRect(context, container1, foregroundDrawingType, FloatRect(100, 100, 100, 100)); 562 drawRect(context, container1, foregroundDrawingType, FloatRect(100, 100, 100, 100));
566 } 563 }
567 { 564 {
568 SubsequenceRecorder r(context, container2, subsequenceType); 565 SubsequenceRecorder r(context, container2);
569 drawRect(context, container2, backgroundDrawingType, FloatRect(100, 200, 100, 100)); 566 drawRect(context, container2, backgroundDrawingType, FloatRect(100, 200, 100, 100));
570 { 567 {
571 SubsequenceRecorder r(context, content2, subsequenceType); 568 SubsequenceRecorder r(context, content2);
572 drawRect(context, content2, backgroundDrawingType, FloatRect(100, 20 0, 50, 200)); 569 drawRect(context, content2, backgroundDrawingType, FloatRect(100, 20 0, 50, 200));
573 } 570 }
574 } 571 }
575 paintController().commitNewDisplayItems(); 572 paintController().commitNewDisplayItems();
576 573
577 EXPECT_DISPLAY_LIST(paintController().displayItemList(), 14, 574 EXPECT_DISPLAY_LIST(paintController().displayItemList(), 14,
578 TestDisplayItem(container1, subsequenceType), 575 TestDisplayItem(container1, DisplayItem::Subsequence),
579 TestDisplayItem(container1, backgroundDrawingType), 576 TestDisplayItem(container1, backgroundDrawingType),
580 TestDisplayItem(content1, subsequenceType), 577 TestDisplayItem(content1, DisplayItem::Subsequence),
581 TestDisplayItem(content1, backgroundDrawingType), 578 TestDisplayItem(content1, backgroundDrawingType),
582 TestDisplayItem(content1, foregroundDrawingType), 579 TestDisplayItem(content1, foregroundDrawingType),
583 TestDisplayItem(content1, endSubsequenceType), 580 TestDisplayItem(content1, DisplayItem::EndSubsequence),
584 TestDisplayItem(container1, foregroundDrawingType), 581 TestDisplayItem(container1, foregroundDrawingType),
585 TestDisplayItem(container1, endSubsequenceType), 582 TestDisplayItem(container1, DisplayItem::EndSubsequence),
586 583
587 TestDisplayItem(container2, subsequenceType), 584 TestDisplayItem(container2, DisplayItem::Subsequence),
588 TestDisplayItem(container2, backgroundDrawingType), 585 TestDisplayItem(container2, backgroundDrawingType),
589 TestDisplayItem(content2, subsequenceType), 586 TestDisplayItem(content2, DisplayItem::Subsequence),
590 TestDisplayItem(content2, backgroundDrawingType), 587 TestDisplayItem(content2, backgroundDrawingType),
591 TestDisplayItem(content2, endSubsequenceType), 588 TestDisplayItem(content2, DisplayItem::EndSubsequence),
592 TestDisplayItem(container2, endSubsequenceType)); 589 TestDisplayItem(container2, DisplayItem::EndSubsequence));
593 590
594 // Invalidate container1 but not content1. 591 // Invalidate container1 but not content1.
595 paintController().invalidate(container1, PaintInvalidationFull, nullptr); 592 paintController().invalidate(container1, PaintInvalidationFull, nullptr);
596 593
597 // Container2 itself now becomes empty (but still has the 'content2' child), 594 // Container2 itself now becomes empty (but still has the 'content2' child),
598 // and chooses not to output subsequence info. 595 // and chooses not to output subsequence info.
599 596
600 paintController().invalidate(container2, PaintInvalidationFull, nullptr); 597 paintController().invalidate(container2, PaintInvalidationFull, nullptr);
601 paintController().invalidate(content2, PaintInvalidationFull, nullptr); 598 paintController().invalidate(content2, PaintInvalidationFull, nullptr);
602 EXPECT_FALSE(SubsequenceRecorder::useCachedSubsequenceIfPossible(context, co ntainer2, subsequenceType)); 599 EXPECT_FALSE(SubsequenceRecorder::useCachedSubsequenceIfPossible(context, co ntainer2));
603 EXPECT_FALSE(SubsequenceRecorder::useCachedSubsequenceIfPossible(context, co ntent2, subsequenceType)); 600 EXPECT_FALSE(SubsequenceRecorder::useCachedSubsequenceIfPossible(context, co ntent2));
604 // Content2 now outputs foreground only. 601 // Content2 now outputs foreground only.
605 { 602 {
606 SubsequenceRecorder r(context, content2, subsequenceType); 603 SubsequenceRecorder r(context, content2);
607 drawRect(context, content2, foregroundDrawingType, FloatRect(100, 200, 5 0, 200)); 604 drawRect(context, content2, foregroundDrawingType, FloatRect(100, 200, 5 0, 200));
608 } 605 }
609 // Repaint container1 with foreground only. 606 // Repaint container1 with foreground only.
610 { 607 {
611 EXPECT_FALSE(SubsequenceRecorder::useCachedSubsequenceIfPossible(context , container1, subsequenceType)); 608 EXPECT_FALSE(SubsequenceRecorder::useCachedSubsequenceIfPossible(context , container1));
612 SubsequenceRecorder r(context, container1, subsequenceType); 609 SubsequenceRecorder r(context, container1);
613 // Use cached subsequence of content1. 610 // Use cached subsequence of content1.
614 EXPECT_TRUE(SubsequenceRecorder::useCachedSubsequenceIfPossible(context, content1, subsequenceType)); 611 EXPECT_TRUE(SubsequenceRecorder::useCachedSubsequenceIfPossible(context, content1));
615 drawRect(context, container1, foregroundDrawingType, FloatRect(100, 100, 100, 100)); 612 drawRect(context, container1, foregroundDrawingType, FloatRect(100, 100, 100, 100));
616 } 613 }
617 EXPECT_DISPLAY_LIST(paintController().newDisplayItemList(), 7, 614 EXPECT_DISPLAY_LIST(paintController().newDisplayItemList(), 7,
618 TestDisplayItem(content2, subsequenceType), 615 TestDisplayItem(content2, DisplayItem::Subsequence),
619 TestDisplayItem(content2, foregroundDrawingType), 616 TestDisplayItem(content2, foregroundDrawingType),
620 TestDisplayItem(content2, endSubsequenceType), 617 TestDisplayItem(content2, DisplayItem::EndSubsequence),
621 TestDisplayItem(container1, subsequenceType), 618 TestDisplayItem(container1, DisplayItem::Subsequence),
622 TestDisplayItem(content1, cachedSubsequenceType), 619 TestDisplayItem(content1, DisplayItem::CachedSubsequence),
623 TestDisplayItem(container1, foregroundDrawingType), 620 TestDisplayItem(container1, foregroundDrawingType),
624 TestDisplayItem(container1, endSubsequenceType)); 621 TestDisplayItem(container1, DisplayItem::EndSubsequence));
625 622
626 paintController().commitNewDisplayItems(); 623 paintController().commitNewDisplayItems();
627 624
628 EXPECT_DISPLAY_LIST(paintController().displayItemList(), 10, 625 EXPECT_DISPLAY_LIST(paintController().displayItemList(), 10,
629 TestDisplayItem(content2, subsequenceType), 626 TestDisplayItem(content2, DisplayItem::Subsequence),
630 TestDisplayItem(content2, foregroundDrawingType), 627 TestDisplayItem(content2, foregroundDrawingType),
631 TestDisplayItem(content2, endSubsequenceType), 628 TestDisplayItem(content2, DisplayItem::EndSubsequence),
632 629
633 TestDisplayItem(container1, subsequenceType), 630 TestDisplayItem(container1, DisplayItem::Subsequence),
634 TestDisplayItem(content1, subsequenceType), 631 TestDisplayItem(content1, DisplayItem::Subsequence),
635 TestDisplayItem(content1, backgroundDrawingType), 632 TestDisplayItem(content1, backgroundDrawingType),
636 TestDisplayItem(content1, foregroundDrawingType), 633 TestDisplayItem(content1, foregroundDrawingType),
637 TestDisplayItem(content1, endSubsequenceType), 634 TestDisplayItem(content1, DisplayItem::EndSubsequence),
638 TestDisplayItem(container1, foregroundDrawingType), 635 TestDisplayItem(container1, foregroundDrawingType),
639 TestDisplayItem(container1, endSubsequenceType)); 636 TestDisplayItem(container1, DisplayItem::EndSubsequence));
640 } 637 }
641 638
642 TEST_F(PaintControllerTest, Scope) 639 TEST_F(PaintControllerTest, Scope)
643 { 640 {
644 TestDisplayItemClient multicol("multicol"); 641 TestDisplayItemClient multicol("multicol");
645 TestDisplayItemClient content("content"); 642 TestDisplayItemClient content("content");
646 GraphicsContext context(paintController()); 643 GraphicsContext context(paintController());
647 644
648 FloatRect rect1(100, 100, 50, 50); 645 FloatRect rect1(100, 100, 50, 50);
649 FloatRect rect2(150, 100, 50, 50); 646 FloatRect rect2(150, 100, 50, 50);
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 drawRect(context, client, backgroundDrawingType, FloatRect(0, 0, 100, 100)); 781 drawRect(context, client, backgroundDrawingType, FloatRect(0, 0, 100, 100));
785 782
786 paintController().commitNewDisplayItems(); 783 paintController().commitNewDisplayItems();
787 const auto& paintChunks = paintController().paintChunks(); 784 const auto& paintChunks = paintController().paintChunks();
788 ASSERT_EQ(1u, paintChunks.size()); 785 ASSERT_EQ(1u, paintChunks.size());
789 EXPECT_EQ(0u, paintChunks[0].beginIndex); 786 EXPECT_EQ(0u, paintChunks[0].beginIndex);
790 EXPECT_EQ(1u, paintChunks[0].endIndex); 787 EXPECT_EQ(1u, paintChunks[0].endIndex);
791 } 788 }
792 789
793 } // namespace blink 790 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698