| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <map> | 5 #include <map> |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 cc::DisplayItemList::Create(first_paint, cc::DisplayItemListSettings()); | 521 cc::DisplayItemList::Create(first_paint, cc::DisplayItemListSettings()); |
| 522 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint)); | 522 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint)); |
| 523 | 523 |
| 524 // The empty view has nothing to paint so it doesn't try build a cache, nor do | 524 // The empty view has nothing to paint so it doesn't try build a cache, nor do |
| 525 // its children which would be clipped by its (empty) self. | 525 // its children which would be clipped by its (empty) self. |
| 526 EXPECT_FALSE(v1->did_paint_); | 526 EXPECT_FALSE(v1->did_paint_); |
| 527 EXPECT_FALSE(v11->did_paint_); | 527 EXPECT_FALSE(v11->did_paint_); |
| 528 EXPECT_TRUE(v2->did_paint_); | 528 EXPECT_TRUE(v2->did_paint_); |
| 529 } | 529 } |
| 530 | 530 |
| 531 TEST_F(ViewTest, PaintWithMovedViewUsesCache) { |
| 532 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); |
| 533 View* root_view = widget->GetRootView(); |
| 534 TestView* v1 = new TestView; |
| 535 v1->SetBounds(10, 11, 12, 13); |
| 536 root_view->AddChildView(v1); |
| 537 |
| 538 // Paint everything once, since it has to build its cache. Then we can test |
| 539 // invalidation. |
| 540 gfx::Rect pixel_rect = gfx::Rect(1, 1); |
| 541 float device_scale_factor = 1.f; |
| 542 scoped_refptr<cc::DisplayItemList> list = |
| 543 cc::DisplayItemList::Create(pixel_rect, cc::DisplayItemListSettings()); |
| 544 root_view->Paint( |
| 545 ui::PaintContext(list.get(), device_scale_factor, pixel_rect)); |
| 546 EXPECT_TRUE(v1->did_paint_); |
| 547 v1->Reset(); |
| 548 // The visual rects for (clip, drawing, transform) should be in layer space. |
| 549 gfx::Rect expected_visual_rect_in_layer_space(10, 11, 12, 13); |
| 550 int item_index = 3; |
| 551 EXPECT_EQ(expected_visual_rect_in_layer_space, |
| 552 list->VisualRectForTesting(item_index++)); |
| 553 EXPECT_EQ(expected_visual_rect_in_layer_space, |
| 554 list->VisualRectForTesting(item_index++)); |
| 555 EXPECT_EQ(expected_visual_rect_in_layer_space, |
| 556 list->VisualRectForTesting(item_index)); |
| 557 |
| 558 // If invalidation doesn't intersect v1, we paint with the cache. |
| 559 list = cc::DisplayItemList::Create(pixel_rect, cc::DisplayItemListSettings()); |
| 560 root_view->Paint( |
| 561 ui::PaintContext(list.get(), device_scale_factor, pixel_rect)); |
| 562 EXPECT_FALSE(v1->did_paint_); |
| 563 v1->Reset(); |
| 564 |
| 565 // If invalidation does intersect v1, we don't paint with the cache. |
| 566 list = cc::DisplayItemList::Create(pixel_rect, cc::DisplayItemListSettings()); |
| 567 root_view->Paint( |
| 568 ui::PaintContext(list.get(), device_scale_factor, v1->bounds())); |
| 569 EXPECT_TRUE(v1->did_paint_); |
| 570 v1->Reset(); |
| 571 |
| 572 // Moving the view should still use the cache when the invalidation doesn't |
| 573 // intersect v1. |
| 574 list = cc::DisplayItemList::Create(pixel_rect, cc::DisplayItemListSettings()); |
| 575 v1->SetX(9); |
| 576 root_view->Paint( |
| 577 ui::PaintContext(list.get(), device_scale_factor, pixel_rect)); |
| 578 EXPECT_FALSE(v1->did_paint_); |
| 579 v1->Reset(); |
| 580 item_index = 3; |
| 581 expected_visual_rect_in_layer_space.SetRect(9, 11, 12, 13); |
| 582 EXPECT_EQ(expected_visual_rect_in_layer_space, |
| 583 list->VisualRectForTesting(item_index++)); |
| 584 EXPECT_EQ(expected_visual_rect_in_layer_space, |
| 585 list->VisualRectForTesting(item_index++)); |
| 586 EXPECT_EQ(expected_visual_rect_in_layer_space, |
| 587 list->VisualRectForTesting(item_index)); |
| 588 |
| 589 // Moving the view should not use the cache when painting without |
| 590 // invalidation. |
| 591 list = cc::DisplayItemList::Create(pixel_rect, cc::DisplayItemListSettings()); |
| 592 v1->SetX(8); |
| 593 root_view->Paint(ui::PaintContext( |
| 594 ui::PaintContext(list.get(), device_scale_factor, pixel_rect), |
| 595 ui::PaintContext::CLONE_WITHOUT_INVALIDATION)); |
| 596 EXPECT_TRUE(v1->did_paint_); |
| 597 v1->Reset(); |
| 598 item_index = 3; |
| 599 expected_visual_rect_in_layer_space.SetRect(8, 11, 12, 13); |
| 600 EXPECT_EQ(expected_visual_rect_in_layer_space, |
| 601 list->VisualRectForTesting(item_index++)); |
| 602 EXPECT_EQ(expected_visual_rect_in_layer_space, |
| 603 list->VisualRectForTesting(item_index++)); |
| 604 EXPECT_EQ(expected_visual_rect_in_layer_space, |
| 605 list->VisualRectForTesting(item_index)); |
| 606 } |
| 607 |
| 608 TEST_F(ViewTest, PaintWithMovedViewUsesCacheInRTL) { |
| 609 ScopedRTL rtl; |
| 610 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); |
| 611 View* root_view = widget->GetRootView(); |
| 612 TestView* v1 = new TestView; |
| 613 v1->SetBounds(10, 11, 12, 13); |
| 614 root_view->AddChildView(v1); |
| 615 |
| 616 // Paint everything once, since it has to build its cache. Then we can test |
| 617 // invalidation. |
| 618 gfx::Rect pixel_rect = gfx::Rect(1, 1); |
| 619 float device_scale_factor = 1.f; |
| 620 scoped_refptr<cc::DisplayItemList> list = |
| 621 cc::DisplayItemList::Create(pixel_rect, cc::DisplayItemListSettings()); |
| 622 root_view->Paint( |
| 623 ui::PaintContext(list.get(), device_scale_factor, pixel_rect)); |
| 624 EXPECT_TRUE(v1->did_paint_); |
| 625 v1->Reset(); |
| 626 // The visual rects for (clip, drawing, transform) should be in layer space. |
| 627 // x: 25 - 10(x) - 12(width) = 3 |
| 628 gfx::Rect expected_visual_rect_in_layer_space(3, 11, 12, 13); |
| 629 int item_index = 3; |
| 630 EXPECT_EQ(expected_visual_rect_in_layer_space, |
| 631 list->VisualRectForTesting(item_index++)); |
| 632 EXPECT_EQ(expected_visual_rect_in_layer_space, |
| 633 list->VisualRectForTesting(item_index++)); |
| 634 EXPECT_EQ(expected_visual_rect_in_layer_space, |
| 635 list->VisualRectForTesting(item_index)); |
| 636 |
| 637 // If invalidation doesn't intersect v1, we paint with the cache. |
| 638 list = cc::DisplayItemList::Create(pixel_rect, cc::DisplayItemListSettings()); |
| 639 root_view->Paint( |
| 640 ui::PaintContext(list.get(), device_scale_factor, pixel_rect)); |
| 641 EXPECT_FALSE(v1->did_paint_); |
| 642 v1->Reset(); |
| 643 |
| 644 // If invalidation does intersect v1, we don't paint with the cache. |
| 645 list = cc::DisplayItemList::Create(pixel_rect, cc::DisplayItemListSettings()); |
| 646 root_view->Paint( |
| 647 ui::PaintContext(list.get(), device_scale_factor, v1->bounds())); |
| 648 EXPECT_TRUE(v1->did_paint_); |
| 649 v1->Reset(); |
| 650 |
| 651 // Moving the view should still use the cache when the invalidation doesn't |
| 652 // intersect v1. |
| 653 list = cc::DisplayItemList::Create(pixel_rect, cc::DisplayItemListSettings()); |
| 654 v1->SetX(9); |
| 655 root_view->Paint( |
| 656 ui::PaintContext(list.get(), device_scale_factor, pixel_rect)); |
| 657 EXPECT_FALSE(v1->did_paint_); |
| 658 v1->Reset(); |
| 659 item_index = 3; |
| 660 // x: 25 - 9(x) - 12(width) = 4 |
| 661 expected_visual_rect_in_layer_space.SetRect(4, 11, 12, 13); |
| 662 EXPECT_EQ(expected_visual_rect_in_layer_space, |
| 663 list->VisualRectForTesting(item_index++)); |
| 664 EXPECT_EQ(expected_visual_rect_in_layer_space, |
| 665 list->VisualRectForTesting(item_index++)); |
| 666 EXPECT_EQ(expected_visual_rect_in_layer_space, |
| 667 list->VisualRectForTesting(item_index)); |
| 668 |
| 669 // Moving the view should not use the cache when painting without |
| 670 // invalidation. |
| 671 list = cc::DisplayItemList::Create(pixel_rect, cc::DisplayItemListSettings()); |
| 672 v1->SetX(8); |
| 673 root_view->Paint(ui::PaintContext( |
| 674 ui::PaintContext(list.get(), device_scale_factor, pixel_rect), |
| 675 ui::PaintContext::CLONE_WITHOUT_INVALIDATION)); |
| 676 EXPECT_TRUE(v1->did_paint_); |
| 677 v1->Reset(); |
| 678 item_index = 3; |
| 679 // x: 25 - 8(x) - 12(width) = 5 |
| 680 expected_visual_rect_in_layer_space.SetRect(5, 11, 12, 13); |
| 681 EXPECT_EQ(expected_visual_rect_in_layer_space, |
| 682 list->VisualRectForTesting(item_index++)); |
| 683 EXPECT_EQ(expected_visual_rect_in_layer_space, |
| 684 list->VisualRectForTesting(item_index++)); |
| 685 EXPECT_EQ(expected_visual_rect_in_layer_space, |
| 686 list->VisualRectForTesting(item_index)); |
| 687 } |
| 688 |
| 531 TEST_F(ViewTest, PaintWithUnknownInvalidation) { | 689 TEST_F(ViewTest, PaintWithUnknownInvalidation) { |
| 532 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); | 690 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); |
| 533 View* root_view = widget->GetRootView(); | 691 View* root_view = widget->GetRootView(); |
| 534 | 692 |
| 535 TestView* v1 = new TestView; | 693 TestView* v1 = new TestView; |
| 536 v1->SetBounds(10, 11, 12, 13); | 694 v1->SetBounds(10, 11, 12, 13); |
| 537 root_view->AddChildView(v1); | 695 root_view->AddChildView(v1); |
| 538 | 696 |
| 539 TestView* v2 = new TestView; | 697 TestView* v2 = new TestView; |
| 540 v2->SetBounds(3, 4, 6, 5); | 698 v2->SetBounds(3, 4, 6, 5); |
| (...skipping 3591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4132 // notification. | 4290 // notification. |
| 4133 TestView* test_view_child_2 = new TestView(); | 4291 TestView* test_view_child_2 = new TestView(); |
| 4134 test_view->AddChildView(test_view_child_2); | 4292 test_view->AddChildView(test_view_child_2); |
| 4135 EXPECT_TRUE(test_view_child_2->native_theme_); | 4293 EXPECT_TRUE(test_view_child_2->native_theme_); |
| 4136 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); | 4294 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); |
| 4137 | 4295 |
| 4138 widget->CloseNow(); | 4296 widget->CloseNow(); |
| 4139 } | 4297 } |
| 4140 | 4298 |
| 4141 } // namespace views | 4299 } // namespace views |
| OLD | NEW |