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

Side by Side Diff: ui/views/view_unittest.cc

Issue 1423653005: Further plumb visual rect into cc:DisplayItemList. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Document size param in recorders. Created 5 years 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
« no previous file with comments | « ui/views/view.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 static void TestPaintWithMovedViewUsesCache(
532 ViewTest* test,
533 const gfx::Rect& visual_rect_in_layer_space) {
danakj 2015/11/25 00:30:56 expected_vis...
wkorman 2015/11/25 00:44:51 Done.
534 ScopedTestPaintWidget widget(
535 test->CreateParams(Widget::InitParams::TYPE_POPUP));
536 View* root_view = widget->GetRootView();
537 TestView* v1 = new TestView;
538 v1->SetBounds(10, 11, 12, 13);
539 root_view->AddChildView(v1);
540
541 // Paint everything once, since it has to build its cache. Then we can test
542 // invalidation.
543 gfx::Rect pixel_rect = gfx::Rect(1, 1);
544 float device_scale_factor = 1.f;
545 scoped_refptr<cc::DisplayItemList> list =
546 cc::DisplayItemList::Create(pixel_rect, cc::DisplayItemListSettings());
547 root_view->Paint(
548 ui::PaintContext(list.get(), device_scale_factor, pixel_rect));
549 EXPECT_TRUE(v1->did_paint_);
550 v1->Reset();
551 // The visual rects for (clip, drawing, transform) should be in layer space.
552 int item_index = 3;
553 EXPECT_EQ(visual_rect_in_layer_space,
554 list->VisualRectForTesting(item_index++));
555 EXPECT_EQ(visual_rect_in_layer_space,
556 list->VisualRectForTesting(item_index++));
557 EXPECT_EQ(visual_rect_in_layer_space, list->VisualRectForTesting(item_index));
558
559 // If invalidation doesn't intersect v1, we paint with the cache.
560 list = cc::DisplayItemList::Create(pixel_rect, cc::DisplayItemListSettings());
561 root_view->Paint(
562 ui::PaintContext(list.get(), device_scale_factor, pixel_rect));
563 EXPECT_FALSE(v1->did_paint_);
564 v1->Reset();
565
566 // If invalidation does intersect v1, we don't paint with the cache.
567 list = cc::DisplayItemList::Create(pixel_rect, cc::DisplayItemListSettings());
568 root_view->Paint(
569 ui::PaintContext(list.get(), device_scale_factor, v1->bounds()));
570 EXPECT_TRUE(v1->did_paint_);
571 v1->Reset();
572
573 // Moving the view should still use the cache when the invalidation doesn't
574 // intersect v1.
575 list = cc::DisplayItemList::Create(pixel_rect, cc::DisplayItemListSettings());
576 v1->SetX(9);
577 root_view->Paint(
578 ui::PaintContext(list.get(), device_scale_factor, pixel_rect));
579 EXPECT_FALSE(v1->did_paint_);
580 v1->Reset();
581
danakj 2015/11/25 00:30:56 check the visual rects after moving, both with and
wkorman 2015/11/25 00:44:51 Done.
582 // Moving the view should not use the cache when there is no invalidation.
583 list = cc::DisplayItemList::Create(pixel_rect, cc::DisplayItemListSettings());
584 v1->SetX(8);
585 root_view->Paint(ui::PaintContext(
586 ui::PaintContext(list.get(), device_scale_factor, pixel_rect),
587 ui::PaintContext::CLONE_WITHOUT_INVALIDATION));
588 EXPECT_TRUE(v1->did_paint_);
589 v1->Reset();
590 }
591
592 TEST_F(ViewTest, PaintWithMovedViewUsesCache) {
593 TestPaintWithMovedViewUsesCache(this, gfx::Rect(10, 11, 12, 13));
594 }
595
596 TEST_F(ViewTest, PaintWithMovedViewUsesCacheInRTL) {
597 ScopedRTL rtl;
598 TestPaintWithMovedViewUsesCache(this, gfx::Rect(3, 11, 12, 13));
599 }
600
531 TEST_F(ViewTest, PaintWithUnknownInvalidation) { 601 TEST_F(ViewTest, PaintWithUnknownInvalidation) {
532 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); 602 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP));
533 View* root_view = widget->GetRootView(); 603 View* root_view = widget->GetRootView();
534 604
535 TestView* v1 = new TestView; 605 TestView* v1 = new TestView;
536 v1->SetBounds(10, 11, 12, 13); 606 v1->SetBounds(10, 11, 12, 13);
537 root_view->AddChildView(v1); 607 root_view->AddChildView(v1);
538 608
539 TestView* v2 = new TestView; 609 TestView* v2 = new TestView;
540 v2->SetBounds(3, 4, 6, 5); 610 v2->SetBounds(3, 4, 6, 5);
(...skipping 3591 matching lines...) Expand 10 before | Expand all | Expand 10 after
4132 // notification. 4202 // notification.
4133 TestView* test_view_child_2 = new TestView(); 4203 TestView* test_view_child_2 = new TestView();
4134 test_view->AddChildView(test_view_child_2); 4204 test_view->AddChildView(test_view_child_2);
4135 EXPECT_TRUE(test_view_child_2->native_theme_); 4205 EXPECT_TRUE(test_view_child_2->native_theme_);
4136 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); 4206 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_);
4137 4207
4138 widget->CloseNow(); 4208 widget->CloseNow();
4139 } 4209 }
4140 4210
4141 } // namespace views 4211 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698