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

Side by Side Diff: cc/resources/picture_pile_unittest.cc

Issue 14874004: cc: Inflate invalidation in each picture list (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « cc/resources/picture_pile_impl.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
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "cc/resources/picture_pile.h"
6 #include "cc/test/fake_content_layer_client.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/gfx/rect_conversions.h"
9 #include "ui/gfx/size_conversions.h"
10
11 namespace cc {
12 namespace {
13
14 class TestPicturePile : public PicturePile {
15 public:
16 using PicturePile::buffer_pixels;
17
18 PictureListMap& picture_list_map() { return picture_list_map_; }
19
20 typedef PicturePile::PictureList PictureList;
21 typedef PicturePile::PictureListMapKey PictureListMapKey;
22 typedef PicturePile::PictureListMap PictureListMap;
23
24 protected:
25 virtual ~TestPicturePile() {}
26 };
27
28 TEST(PicturePileTest, SmallInvalidateInflated) {
29 FakeContentLayerClient client;
30 scoped_refptr<TestPicturePile> pile = new TestPicturePile;
31 SkColor background_color = SK_ColorBLUE;
32
33 float min_scale = 0.125;
34 gfx::Size base_picture_size = pile->tiling().max_texture_size();
35
36 gfx::Size layer_size = base_picture_size;
37 pile->Resize(layer_size);
38 pile->SetTileGridSize(gfx::Size(1000, 1000));
39 pile->SetMinContentsScale(min_scale);
40
41 // Update the whole layer.
42 pile->Update(&client,
43 background_color,
44 gfx::Rect(layer_size),
45 gfx::Rect(layer_size),
46 NULL);
47
48 // Invalidate something inside a tile.
49 gfx::Rect invalidate_rect(50, 50, 1, 1);
50 pile->Update(&client,
51 background_color,
52 invalidate_rect,
53 gfx::Rect(layer_size),
54 NULL);
55
56 EXPECT_EQ(1, pile->tiling().num_tiles_x());
57 EXPECT_EQ(1, pile->tiling().num_tiles_y());
58
59 TestPicturePile::PictureList& picture_list =
60 pile->picture_list_map().find(
61 TestPicturePile::PictureListMapKey(0, 0))->second;
62 EXPECT_EQ(2u, picture_list.size());
63 for (TestPicturePile::PictureList::iterator it = picture_list.begin();
64 it != picture_list.end();
65 ++it) {
66 scoped_refptr<Picture> picture = *it;
67 gfx::Rect picture_rect = gfx::ToEnclosedRect(
68 gfx::ScaleRect(picture->LayerRect(), min_scale));
69
70 // The invalidation in each tile should have been made large enough
71 // that scaling it never makes a rect smaller than 1 px wide or tall.
72 EXPECT_FALSE(picture_rect.IsEmpty()) << "Picture rect " <<
73 picture_rect.ToString();
74 }
75 }
76
77 TEST(PicturePileTest, LargeInvalidateInflated) {
78 FakeContentLayerClient client;
79 scoped_refptr<TestPicturePile> pile = new TestPicturePile;
80 SkColor background_color = SK_ColorBLUE;
81
82 float min_scale = 0.125;
83 gfx::Size base_picture_size = pile->tiling().max_texture_size();
84
85 gfx::Size layer_size = base_picture_size;
86 pile->Resize(layer_size);
87 pile->SetTileGridSize(gfx::Size(1000, 1000));
88 pile->SetMinContentsScale(min_scale);
89
90 // Update the whole layer.
91 pile->Update(&client,
92 background_color,
93 gfx::Rect(layer_size),
94 gfx::Rect(layer_size),
95 NULL);
96
97 // Invalidate something inside a tile.
98 gfx::Rect invalidate_rect(50, 50, 100, 100);
99 pile->Update(&client,
100 background_color,
101 invalidate_rect,
102 gfx::Rect(layer_size),
103 NULL);
104
105 EXPECT_EQ(1, pile->tiling().num_tiles_x());
106 EXPECT_EQ(1, pile->tiling().num_tiles_y());
107
108 TestPicturePile::PictureList& picture_list =
109 pile->picture_list_map().find(
110 TestPicturePile::PictureListMapKey(0, 0))->second;
111 EXPECT_EQ(2u, picture_list.size());
112
113 int expected_inflation = pile->buffer_pixels();
114
115 scoped_refptr<Picture> base_picture = *picture_list.begin();
116 gfx::Rect base_picture_rect(layer_size);
117 base_picture_rect.Inset(-expected_inflation, -expected_inflation);
118 EXPECT_EQ(base_picture_rect.ToString(),
119 base_picture->LayerRect().ToString());
120
121 scoped_refptr<Picture> picture = *(++picture_list.begin());
122 gfx::Rect picture_rect(invalidate_rect);
123 picture_rect.Inset(-expected_inflation, -expected_inflation);
124 EXPECT_EQ(picture_rect.ToString(),
125 picture->LayerRect().ToString());
126 }
127
128 TEST(PicturePileTest, InvalidateOnTileBoundaryInflated) {
129 FakeContentLayerClient client;
130 scoped_refptr<TestPicturePile> pile = new TestPicturePile;
131 SkColor background_color = SK_ColorBLUE;
132
133 float min_scale = 0.125;
134 gfx::Size base_picture_size = pile->tiling().max_texture_size();
135
136 gfx::Size layer_size =
137 gfx::ToFlooredSize(gfx::ScaleSize(base_picture_size, 2.f));
138 pile->Resize(layer_size);
139 pile->SetTileGridSize(gfx::Size(1000, 1000));
140 pile->SetMinContentsScale(min_scale);
141
142 // Due to border pixels, we should have 3 tiles.
143 EXPECT_EQ(3, pile->tiling().num_tiles_x());
144 EXPECT_EQ(3, pile->tiling().num_tiles_y());
145
146 // We should have 1/.125 - 1 = 7 border pixels.
147 EXPECT_EQ(7, pile->buffer_pixels());
148 EXPECT_EQ(7, pile->tiling().border_texels());
149
150 // Update the whole layer.
151 pile->Update(&client,
152 background_color,
153 gfx::Rect(layer_size),
154 gfx::Rect(layer_size),
155 NULL);
156
157 // Invalidate something just over a tile boundary by a single pixel.
158 // This will invalidate the tile (1, 1), as well as 1 row of pixels in (1, 0).
159 gfx::Rect invalidate_rect(
160 pile->tiling().TileBoundsWithBorder(0, 0).right(),
161 pile->tiling().TileBoundsWithBorder(0, 0).bottom() - 1,
162 50,
163 50);
164 pile->Update(&client,
165 background_color,
166 invalidate_rect,
167 gfx::Rect(layer_size),
168 NULL);
169
170 for (int i = 0; i < pile->tiling().num_tiles_x(); ++i) {
171 for (int j = 0; j < pile->tiling().num_tiles_y(); ++j) {
172 // (1, 0) and (1, 1) should be invalidated partially.
173 bool expect_invalidated = i == 1 && (j == 0 || j == 1);
174
175 TestPicturePile::PictureList& picture_list =
176 pile->picture_list_map().find(
177 TestPicturePile::PictureListMapKey(i, j))->second;
178 if (!expect_invalidated) {
179 EXPECT_EQ(1u, picture_list.size()) << "For i,j " << i << "," << j;
180 continue;
181 }
182
183 EXPECT_EQ(2u, picture_list.size()) << "For i,j " << i << "," << j;
184 for (TestPicturePile::PictureList::iterator it = picture_list.begin();
185 it != picture_list.end();
186 ++it) {
187 scoped_refptr<Picture> picture = *it;
188 gfx::Rect picture_rect = gfx::ToEnclosedRect(
189 gfx::ScaleRect(picture->LayerRect(), min_scale));
190
191 // The invalidation in each tile should have been made large enough
192 // that scaling it never makes a rect smaller than 1 px wide or tall.
193 EXPECT_FALSE(picture_rect.IsEmpty()) << "Picture rect " <<
194 picture_rect.ToString();
195 }
196 }
197 }
198 }
199
200 } // namespace
201 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/picture_pile_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698