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

Unified Diff: ui/views/view_unittest.cc

Issue 1161933007: ui: Introduce CanvasPainter, remove PaintContext(gfx::Canvas*). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: canvaspainter: . Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/view_unittest.cc
diff --git a/ui/views/view_unittest.cc b/ui/views/view_unittest.cc
index d4a270e8fc837b9ac8fb515dba5029fc726139af..1a103b731deb77f359ff10f7048caa4d6c15c196 100644
--- a/ui/views/view_unittest.cc
+++ b/ui/views/view_unittest.cc
@@ -9,6 +9,8 @@
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
+#include "cc/playback/display_item_list.h"
+#include "cc/playback/display_item_list_settings.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/l10n/l10n_util.h"
@@ -445,21 +447,29 @@ TEST_F(ViewTest, PaintWithUnknownInvalidation) {
v2->SetBounds(3, 4, 6, 5);
v1->AddChildView(v2);
- gfx::Canvas canvas(root_view->size(), 1.f, true);
+ // Paint everything once, since it has to build its cache. Then we can test
+ // invalidation.
+ gfx::Rect first_paint(1, 1);
+ scoped_refptr<cc::DisplayItemList> list =
+ cc::DisplayItemList::Create(first_paint, cc::DisplayItemListSettings());
+ root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint, first_paint));
+ v1->Reset();
+ v2->Reset();
+
gfx::Rect paint_area(1, 1);
+ gfx::Rect root_area(root_view->size());
+ list = cc::DisplayItemList::Create(root_area, cc::DisplayItemListSettings());
+ // With a known invalidation, v1 and v2 are not painted.
EXPECT_FALSE(v1->did_paint_);
EXPECT_FALSE(v2->did_paint_);
- root_view->Paint(ui::PaintContext(&canvas));
- EXPECT_TRUE(v1->did_paint_);
- EXPECT_TRUE(v2->did_paint_);
-
- v1->Reset();
- v2->Reset();
+ root_view->Paint(ui::PaintContext(list.get(), 1.f, root_area, paint_area));
EXPECT_FALSE(v1->did_paint_);
EXPECT_FALSE(v2->did_paint_);
+
+ // With unknown invalidation, v1 and v2 are painted.
root_view->Paint(
- ui::PaintContext(ui::PaintContext(&canvas, paint_area),
+ ui::PaintContext(ui::PaintContext(list.get(), 1.f, root_area, paint_area),
ui::PaintContext::CLONE_WITHOUT_INVALIDATION));
EXPECT_TRUE(v1->did_paint_);
EXPECT_TRUE(v2->did_paint_);
@@ -480,12 +490,22 @@ TEST_F(ViewTest, PaintContainsChildren) {
v2->SetBounds(3, 4, 6, 5);
v1->AddChildView(v2);
- gfx::Canvas canvas(root_view->size(), 1.f, true);
+ // Paint everything once, since it has to build its cache. Then we can test
+ // invalidation.
+ gfx::Rect first_paint(1, 1);
+ scoped_refptr<cc::DisplayItemList> list =
+ cc::DisplayItemList::Create(first_paint, cc::DisplayItemListSettings());
+ root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint, first_paint));
+ v1->Reset();
+ v2->Reset();
+
gfx::Rect paint_area(25, 26);
+ gfx::Rect root_area(root_view->size());
+ list = cc::DisplayItemList::Create(root_area, cc::DisplayItemListSettings());
EXPECT_FALSE(v1->did_paint_);
EXPECT_FALSE(v2->did_paint_);
- root_view->Paint(ui::PaintContext(&canvas, paint_area));
+ root_view->Paint(ui::PaintContext(list.get(), 1.f, root_area, paint_area));
EXPECT_TRUE(v1->did_paint_);
EXPECT_TRUE(v2->did_paint_);
}
@@ -518,12 +538,22 @@ TEST_F(ViewTest, PaintContainsChildrenInRTL) {
EXPECT_EQ(gfx::Rect(6, 15, 6, 5), v2->layer()->bounds());
v2->SetPaintToLayer(false);
- gfx::Canvas canvas(root_view->size(), 1.f, true);
+ // Paint everything once, since it has to build its cache. Then we can test
+ // invalidation.
+ gfx::Rect first_paint(1, 1);
+ scoped_refptr<cc::DisplayItemList> list =
+ cc::DisplayItemList::Create(first_paint, cc::DisplayItemListSettings());
+ root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint, first_paint));
+ v1->Reset();
+ v2->Reset();
+
gfx::Rect paint_area(25, 26);
+ gfx::Rect root_area(root_view->size());
+ list = cc::DisplayItemList::Create(root_area, cc::DisplayItemListSettings());
EXPECT_FALSE(v1->did_paint_);
EXPECT_FALSE(v2->did_paint_);
- root_view->Paint(ui::PaintContext(&canvas, paint_area));
+ root_view->Paint(ui::PaintContext(list.get(), 1.f, root_area, paint_area));
EXPECT_TRUE(v1->did_paint_);
EXPECT_TRUE(v2->did_paint_);
}
@@ -543,12 +573,22 @@ TEST_F(ViewTest, PaintIntersectsChildren) {
v2->SetBounds(3, 4, 6, 5);
v1->AddChildView(v2);
- gfx::Canvas canvas(root_view->size(), 1.f, true);
+ // Paint everything once, since it has to build its cache. Then we can test
+ // invalidation.
+ gfx::Rect first_paint(1, 1);
+ scoped_refptr<cc::DisplayItemList> list =
+ cc::DisplayItemList::Create(first_paint, cc::DisplayItemListSettings());
+ root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint, first_paint));
+ v1->Reset();
+ v2->Reset();
+
gfx::Rect paint_area(9, 10, 5, 6);
+ gfx::Rect root_area(root_view->size());
+ list = cc::DisplayItemList::Create(root_area, cc::DisplayItemListSettings());
EXPECT_FALSE(v1->did_paint_);
EXPECT_FALSE(v2->did_paint_);
- root_view->Paint(ui::PaintContext(&canvas, paint_area));
+ root_view->Paint(ui::PaintContext(list.get(), 1.f, root_area, paint_area));
EXPECT_TRUE(v1->did_paint_);
EXPECT_TRUE(v2->did_paint_);
}
@@ -581,12 +621,22 @@ TEST_F(ViewTest, PaintIntersectsChildrenInRTL) {
EXPECT_EQ(gfx::Rect(6, 15, 6, 5), v2->layer()->bounds());
v2->SetPaintToLayer(false);
- gfx::Canvas canvas(root_view->size(), 1.f, true);
+ // Paint everything once, since it has to build its cache. Then we can test
+ // invalidation.
+ gfx::Rect first_paint(1, 1);
+ scoped_refptr<cc::DisplayItemList> list =
+ cc::DisplayItemList::Create(first_paint, cc::DisplayItemListSettings());
+ root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint, first_paint));
+ v1->Reset();
+ v2->Reset();
+
gfx::Rect paint_area(2, 10, 5, 6);
+ gfx::Rect root_area(root_view->size());
+ list = cc::DisplayItemList::Create(root_area, cc::DisplayItemListSettings());
EXPECT_FALSE(v1->did_paint_);
EXPECT_FALSE(v2->did_paint_);
- root_view->Paint(ui::PaintContext(&canvas, paint_area));
+ root_view->Paint(ui::PaintContext(list.get(), 1.f, root_area, paint_area));
EXPECT_TRUE(v1->did_paint_);
EXPECT_TRUE(v2->did_paint_);
}
@@ -606,12 +656,22 @@ TEST_F(ViewTest, PaintIntersectsChildButNotGrandChild) {
v2->SetBounds(3, 4, 6, 5);
v1->AddChildView(v2);
- gfx::Canvas canvas(root_view->size(), 1.f, true);
+ // Paint everything once, since it has to build its cache. Then we can test
+ // invalidation.
+ gfx::Rect first_paint(1, 1);
+ scoped_refptr<cc::DisplayItemList> list =
+ cc::DisplayItemList::Create(first_paint, cc::DisplayItemListSettings());
+ root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint, first_paint));
+ v1->Reset();
+ v2->Reset();
+
gfx::Rect paint_area(9, 10, 2, 3);
+ gfx::Rect root_area(root_view->size());
+ list = cc::DisplayItemList::Create(root_area, cc::DisplayItemListSettings());
EXPECT_FALSE(v1->did_paint_);
EXPECT_FALSE(v2->did_paint_);
- root_view->Paint(ui::PaintContext(&canvas, paint_area));
+ root_view->Paint(ui::PaintContext(list.get(), 1.f, root_area, paint_area));
EXPECT_TRUE(v1->did_paint_);
EXPECT_FALSE(v2->did_paint_);
}
@@ -644,12 +704,22 @@ TEST_F(ViewTest, PaintIntersectsChildButNotGrandChildInRTL) {
EXPECT_EQ(gfx::Rect(6, 15, 6, 5), v2->layer()->bounds());
v2->SetPaintToLayer(false);
- gfx::Canvas canvas(root_view->size(), 1.f, true);
+ // Paint everything once, since it has to build its cache. Then we can test
+ // invalidation.
+ gfx::Rect first_paint(1, 1);
+ scoped_refptr<cc::DisplayItemList> list =
+ cc::DisplayItemList::Create(first_paint, cc::DisplayItemListSettings());
+ root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint, first_paint));
+ v1->Reset();
+ v2->Reset();
+
gfx::Rect paint_area(2, 10, 2, 3);
+ gfx::Rect root_area(root_view->size());
+ list = cc::DisplayItemList::Create(root_area, cc::DisplayItemListSettings());
EXPECT_FALSE(v1->did_paint_);
EXPECT_FALSE(v2->did_paint_);
- root_view->Paint(ui::PaintContext(&canvas, paint_area));
+ root_view->Paint(ui::PaintContext(list.get(), 1.f, root_area, paint_area));
EXPECT_TRUE(v1->did_paint_);
EXPECT_FALSE(v2->did_paint_);
}
@@ -669,12 +739,22 @@ TEST_F(ViewTest, PaintIntersectsNoChildren) {
v2->SetBounds(3, 4, 6, 5);
v1->AddChildView(v2);
- gfx::Canvas canvas(root_view->size(), 1.f, true);
+ // Paint everything once, since it has to build its cache. Then we can test
+ // invalidation.
+ gfx::Rect first_paint(1, 1);
+ scoped_refptr<cc::DisplayItemList> list =
+ cc::DisplayItemList::Create(first_paint, cc::DisplayItemListSettings());
+ root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint, first_paint));
+ v1->Reset();
+ v2->Reset();
+
gfx::Rect paint_area(9, 10, 2, 1);
+ gfx::Rect root_area(root_view->size());
+ list = cc::DisplayItemList::Create(root_area, cc::DisplayItemListSettings());
EXPECT_FALSE(v1->did_paint_);
EXPECT_FALSE(v2->did_paint_);
- root_view->Paint(ui::PaintContext(&canvas, paint_area));
+ root_view->Paint(ui::PaintContext(list.get(), 1.f, root_area, paint_area));
EXPECT_FALSE(v1->did_paint_);
EXPECT_FALSE(v2->did_paint_);
}
@@ -707,12 +787,22 @@ TEST_F(ViewTest, PaintIntersectsNoChildrenInRTL) {
EXPECT_EQ(gfx::Rect(6, 15, 6, 5), v2->layer()->bounds());
v2->SetPaintToLayer(false);
- gfx::Canvas canvas(root_view->size(), 1.f, true);
+ // Paint everything once, since it has to build its cache. Then we can test
+ // invalidation.
+ gfx::Rect first_paint(1, 1);
+ scoped_refptr<cc::DisplayItemList> list =
+ cc::DisplayItemList::Create(first_paint, cc::DisplayItemListSettings());
+ root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint, first_paint));
+ v1->Reset();
+ v2->Reset();
+
gfx::Rect paint_area(2, 10, 2, 1);
+ gfx::Rect root_area(root_view->size());
+ list = cc::DisplayItemList::Create(root_area, cc::DisplayItemListSettings());
EXPECT_FALSE(v1->did_paint_);
EXPECT_FALSE(v2->did_paint_);
- root_view->Paint(ui::PaintContext(&canvas, paint_area));
+ root_view->Paint(ui::PaintContext(list.get(), 1.f, root_area, paint_area));
EXPECT_FALSE(v1->did_paint_);
EXPECT_FALSE(v2->did_paint_);
}
@@ -732,13 +822,23 @@ TEST_F(ViewTest, PaintIntersectsOneChild) {
v2->SetBounds(3, 4, 6, 5);
root_view->AddChildView(v2);
- gfx::Canvas canvas(root_view->size(), 1.f, true);
+ // Paint everything once, since it has to build its cache. Then we can test
+ // invalidation.
+ gfx::Rect first_paint(1, 1);
+ scoped_refptr<cc::DisplayItemList> list =
+ cc::DisplayItemList::Create(first_paint, cc::DisplayItemListSettings());
+ root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint, first_paint));
+ v1->Reset();
+ v2->Reset();
+
// Intersects with the second child only.
gfx::Rect paint_area(3, 3, 1, 2);
+ gfx::Rect root_area(root_view->size());
+ list = cc::DisplayItemList::Create(root_area, cc::DisplayItemListSettings());
EXPECT_FALSE(v1->did_paint_);
EXPECT_FALSE(v2->did_paint_);
- root_view->Paint(ui::PaintContext(&canvas, paint_area));
+ root_view->Paint(ui::PaintContext(list.get(), 1.f, root_area, paint_area));
EXPECT_FALSE(v1->did_paint_);
EXPECT_TRUE(v2->did_paint_);
@@ -749,7 +849,7 @@ TEST_F(ViewTest, PaintIntersectsOneChild) {
v2->Reset();
EXPECT_FALSE(v1->did_paint_);
EXPECT_FALSE(v2->did_paint_);
- root_view->Paint(ui::PaintContext(&canvas, paint_area));
+ root_view->Paint(ui::PaintContext(list.get(), 1.f, root_area, paint_area));
EXPECT_TRUE(v1->did_paint_);
EXPECT_FALSE(v2->did_paint_);
}
@@ -782,13 +882,23 @@ TEST_F(ViewTest, PaintIntersectsOneChildInRTL) {
EXPECT_EQ(gfx::Rect(16, 4, 6, 5), v2->layer()->bounds());
v2->SetPaintToLayer(false);
- gfx::Canvas canvas(root_view->size(), 1.f, true);
+ // Paint everything once, since it has to build its cache. Then we can test
+ // invalidation.
+ gfx::Rect first_paint(1, 1);
+ scoped_refptr<cc::DisplayItemList> list =
+ cc::DisplayItemList::Create(first_paint, cc::DisplayItemListSettings());
+ root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint, first_paint));
+ v1->Reset();
+ v2->Reset();
+
// Intersects with the first child only.
gfx::Rect paint_area(3, 10, 1, 2);
+ gfx::Rect root_area(root_view->size());
+ list = cc::DisplayItemList::Create(root_area, cc::DisplayItemListSettings());
EXPECT_FALSE(v1->did_paint_);
EXPECT_FALSE(v2->did_paint_);
- root_view->Paint(ui::PaintContext(&canvas, paint_area));
+ root_view->Paint(ui::PaintContext(list.get(), 1.f, root_area, paint_area));
EXPECT_TRUE(v1->did_paint_);
EXPECT_FALSE(v2->did_paint_);
@@ -799,7 +909,7 @@ TEST_F(ViewTest, PaintIntersectsOneChildInRTL) {
v2->Reset();
EXPECT_FALSE(v1->did_paint_);
EXPECT_FALSE(v2->did_paint_);
- root_view->Paint(ui::PaintContext(&canvas, paint_area));
+ root_view->Paint(ui::PaintContext(list.get(), 1.f, root_area, paint_area));
EXPECT_FALSE(v1->did_paint_);
EXPECT_TRUE(v2->did_paint_);
}
@@ -820,26 +930,36 @@ TEST_F(ViewTest, PaintInPromotedToLayer) {
v2->SetBounds(3, 4, 6, 5);
v1->AddChildView(v2);
- EXPECT_FALSE(v1->did_paint_);
- EXPECT_FALSE(v2->did_paint_);
+ // Paint everything once, since it has to build its cache. Then we can test
+ // invalidation.
+ gfx::Rect first_paint(1, 1);
+ scoped_refptr<cc::DisplayItemList> list =
+ cc::DisplayItemList::Create(first_paint, cc::DisplayItemListSettings());
+ v1->Paint(ui::PaintContext(list.get(), 1.f, first_paint, first_paint));
+ v1->Reset();
+ v2->Reset();
{
- gfx::Canvas canvas(root_view->size(), 1.f, true);
gfx::Rect paint_area(25, 26);
+ gfx::Rect view_area(root_view->size());
+ scoped_refptr<cc::DisplayItemList> list =
+ cc::DisplayItemList::Create(view_area, cc::DisplayItemListSettings());
// The promoted views are not painted as they are separate paint roots.
- root_view->Paint(ui::PaintContext(&canvas, paint_area));
+ root_view->Paint(ui::PaintContext(list.get(), 1.f, view_area, paint_area));
EXPECT_FALSE(v1->did_paint_);
EXPECT_FALSE(v2->did_paint_);
}
{
- gfx::Canvas canvas(v1->size(), 1.f, true);
gfx::Rect paint_area(1, 1);
+ gfx::Rect view_area(v1->size());
+ scoped_refptr<cc::DisplayItemList> list =
+ cc::DisplayItemList::Create(view_area, cc::DisplayItemListSettings());
// The |v1| view is painted. If it used its offset incorrect, it would think
// its at (10,11) instead of at (0,0) since it is the paint root.
- v1->Paint(ui::PaintContext(&canvas, paint_area));
+ v1->Paint(ui::PaintContext(list.get(), 1.f, view_area, paint_area));
EXPECT_TRUE(v1->did_paint_);
EXPECT_FALSE(v2->did_paint_);
}
@@ -847,12 +967,14 @@ TEST_F(ViewTest, PaintInPromotedToLayer) {
v1->Reset();
{
- gfx::Canvas canvas(v1->size(), 1.f, true);
gfx::Rect paint_area(3, 3, 1, 2);
+ gfx::Rect view_area(v1->size());
+ scoped_refptr<cc::DisplayItemList> list =
+ cc::DisplayItemList::Create(view_area, cc::DisplayItemListSettings());
// The |v2| view is painted also. If it used its offset incorrect, it would
// think its at (13,15) instead of at (3,4) since |v1| is the paint root.
- v1->Paint(ui::PaintContext(&canvas, paint_area));
+ v1->Paint(ui::PaintContext(list.get(), 1.f, view_area, paint_area));
EXPECT_TRUE(v1->did_paint_);
EXPECT_TRUE(v2->did_paint_);
}
« no previous file with comments | « ui/views/controls/textfield/textfield.cc ('k') | ui/views/widget/desktop_aura/desktop_window_tree_host_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698