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

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

Issue 17351017: Re-land: cc: Add raster finished signals to RasterWorkerPool. (Closed) Base URL: http://git.chromium.org/chromium/src.git@new-graph-build
Patch Set: fix flaky unit tests Created 7 years, 5 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
« no previous file with comments | « cc/resources/tile_manager.cc ('k') | cc/resources/worker_pool.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 "cc/resources/tile.h" 5 #include "cc/resources/tile.h"
6 #include "cc/resources/tile_priority.h" 6 #include "cc/resources/tile_priority.h"
7 #include "cc/test/fake_output_surface.h" 7 #include "cc/test/fake_output_surface.h"
8 #include "cc/test/fake_tile_manager.h" 8 #include "cc/test/fake_tile_manager.h"
9 #include "cc/test/fake_tile_manager_client.h" 9 #include "cc/test/fake_tile_manager_client.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 }; 42 };
43 43
44 class TilePriorityForNowBin : public TilePriority { 44 class TilePriorityForNowBin : public TilePriority {
45 public: 45 public:
46 TilePriorityForNowBin() : TilePriority( 46 TilePriorityForNowBin() : TilePriority(
47 HIGH_RESOLUTION, 47 HIGH_RESOLUTION,
48 0, 48 0,
49 0) {} 49 0) {}
50 }; 50 };
51 51
52 class TilePriorityRequiredForActivation : public TilePriority {
53 public:
54 TilePriorityRequiredForActivation() : TilePriority(
55 HIGH_RESOLUTION,
56 0,
57 0) {
58 required_for_activation = true;
59 }
60 };
61
52 class TileManagerTest : public testing::Test { 62 class TileManagerTest : public testing::Test {
53 public: 63 public:
54 typedef std::vector<scoped_refptr<Tile> > TileVector; 64 typedef std::vector<scoped_refptr<Tile> > TileVector;
55 65
56 void Initialize(int max_memory_tiles, 66 void Initialize(int max_memory_tiles,
57 TileMemoryLimitPolicy memory_limit_policy, 67 TileMemoryLimitPolicy memory_limit_policy,
58 TreePriority tree_priority) { 68 TreePriority tree_priority) {
59 output_surface_ = FakeOutputSurface::Create3d(); 69 output_surface_ = FakeOutputSurface::Create3d();
60 resource_provider_ = ResourceProvider::Create(output_surface_.get(), 0); 70 resource_provider_ = ResourceProvider::Create(output_surface_.get(), 0);
61 tile_manager_ = make_scoped_ptr( 71 tile_manager_ = make_scoped_ptr(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 113
104 FakeTileManager* tile_manager() { 114 FakeTileManager* tile_manager() {
105 return tile_manager_.get(); 115 return tile_manager_.get();
106 } 116 }
107 117
108 int AssignedMemoryCount(const TileVector& tiles) { 118 int AssignedMemoryCount(const TileVector& tiles) {
109 int has_memory_count = 0; 119 int has_memory_count = 0;
110 for (TileVector::const_iterator it = tiles.begin(); 120 for (TileVector::const_iterator it = tiles.begin();
111 it != tiles.end(); 121 it != tiles.end();
112 ++it) { 122 ++it) {
113 if ((*it)->HasRasterTaskForTesting()) 123 if (tile_manager_->HasBeenAssignedMemory(*it))
114 ++has_memory_count; 124 ++has_memory_count;
115 (*it)->ResetRasterTaskForTesting();
116 } 125 }
117 return has_memory_count; 126 return has_memory_count;
118 } 127 }
119 128
120 int TilesWithLCDCount(const TileVector& tiles) { 129 int TilesWithLCDCount(const TileVector& tiles) {
121 int has_lcd_count = 0; 130 int has_lcd_count = 0;
122 for (TileVector::const_iterator it = tiles.begin(); 131 for (TileVector::const_iterator it = tiles.begin();
123 it != tiles.end(); 132 it != tiles.end();
124 ++it) { 133 ++it) {
125 if ((*it)->GetRasterModeForTesting() == HIGH_QUALITY_RASTER_MODE) 134 if ((*it)->GetRasterModeForTesting() == HIGH_QUALITY_RASTER_MODE)
126 ++has_lcd_count; 135 ++has_lcd_count;
127 (*it)->ResetRasterTaskForTesting();
128 } 136 }
129 return has_lcd_count; 137 return has_lcd_count;
130 } 138 }
131 139
132 private: 140 private:
133 FakeTileManagerClient tile_manager_client_; 141 FakeTileManagerClient tile_manager_client_;
134 LayerTreeSettings settings_; 142 LayerTreeSettings settings_;
135 scoped_ptr<FakeTileManager> tile_manager_; 143 scoped_ptr<FakeTileManager> tile_manager_;
136 scoped_refptr<FakePicturePileImpl> picture_pile_; 144 scoped_refptr<FakePicturePileImpl> picture_pile_;
137 scoped_ptr<FakeOutputSurface> output_surface_; 145 scoped_ptr<FakeOutputSurface> output_surface_;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 223
216 tile_manager()->ManageTiles(); 224 tile_manager()->ManageTiles();
217 225
218 EXPECT_EQ(0, AssignedMemoryCount(active_now)); 226 EXPECT_EQ(0, AssignedMemoryCount(active_now));
219 EXPECT_EQ(0, AssignedMemoryCount(pending_now)); 227 EXPECT_EQ(0, AssignedMemoryCount(pending_now));
220 EXPECT_EQ(0, AssignedMemoryCount(active_pending_soon)); 228 EXPECT_EQ(0, AssignedMemoryCount(active_pending_soon));
221 EXPECT_EQ(0, AssignedMemoryCount(never_bin)); 229 EXPECT_EQ(0, AssignedMemoryCount(never_bin));
222 } 230 }
223 231
224 TEST_F(TileManagerTest, PartialOOMMemoryToPending) { 232 TEST_F(TileManagerTest, PartialOOMMemoryToPending) {
225 // 5 tiles on active tree eventually bin, 5 tiles on pending tree now bin, 233 // 5 tiles on active tree eventually bin, 5 tiles on pending tree that are
226 // but only enough memory for 8 tiles. The result is all pending tree tiles 234 // required for activation, but only enough memory for 8 tiles. The result
227 // get memory, and 3 of the active tree tiles get memory. 235 // is all pending tree tiles get memory, and 3 of the active tree tiles
236 // get memory.
228 237
229 Initialize(8, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); 238 Initialize(8, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY);
230 TileVector active_tree_tiles = 239 TileVector active_tree_tiles =
231 CreateTiles(5, TilePriorityForEventualBin(), TilePriority()); 240 CreateTiles(5, TilePriorityForEventualBin(), TilePriority());
232 TileVector pending_tree_tiles = 241 TileVector pending_tree_tiles =
233 CreateTiles(5, TilePriority(), TilePriorityForNowBin()); 242 CreateTiles(5, TilePriority(), TilePriorityRequiredForActivation());
234 243
235 tile_manager()->ManageTiles(); 244 tile_manager()->ManageTiles();
236 245
246 EXPECT_EQ(5, AssignedMemoryCount(active_tree_tiles));
247 EXPECT_EQ(3, AssignedMemoryCount(pending_tree_tiles));
248
249 tile_manager()->ReassignMemoryToOOMTilesRequiredForActivation();
250
237 EXPECT_EQ(3, AssignedMemoryCount(active_tree_tiles)); 251 EXPECT_EQ(3, AssignedMemoryCount(active_tree_tiles));
238 EXPECT_EQ(5, AssignedMemoryCount(pending_tree_tiles)); 252 EXPECT_EQ(5, AssignedMemoryCount(pending_tree_tiles));
239 } 253 }
240 254
241 TEST_F(TileManagerTest, PartialOOMMemoryToActive) { 255 TEST_F(TileManagerTest, PartialOOMMemoryToActive) {
242 // 5 tiles on active tree eventually bin, 5 tiles on pending tree now bin, 256 // 5 tiles on active tree eventually bin, 5 tiles on pending tree now bin,
243 // but only enough memory for 8 tiles. The result is all active tree tiles 257 // but only enough memory for 8 tiles. The result is all active tree tiles
244 // get memory, and 3 of the pending tree tiles get memory. 258 // get memory, and 3 of the pending tree tiles get memory.
245 259
246 Initialize(8, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); 260 Initialize(8, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY);
247 TileVector active_tree_tiles = 261 TileVector active_tree_tiles =
248 CreateTiles(5, TilePriorityForNowBin(), TilePriority()); 262 CreateTiles(5, TilePriorityForNowBin(), TilePriority());
249 TileVector pending_tree_tiles = 263 TileVector pending_tree_tiles =
250 CreateTiles(5, TilePriority(), TilePriorityForNowBin()); 264 CreateTiles(5, TilePriority(), TilePriorityForNowBin());
251 265
252 tile_manager()->ManageTiles(); 266 tile_manager()->ManageTiles();
253 267
254 EXPECT_EQ(5, AssignedMemoryCount(active_tree_tiles)); 268 EXPECT_EQ(5, AssignedMemoryCount(active_tree_tiles));
255 EXPECT_EQ(3, AssignedMemoryCount(pending_tree_tiles)); 269 EXPECT_EQ(3, AssignedMemoryCount(pending_tree_tiles));
256 } 270 }
257 271
258 TEST_F(TileManagerTest, TotalOOMMemoryToPending) { 272 TEST_F(TileManagerTest, TotalOOMMemoryToPending) {
259 // 5 tiles on active tree eventually bin, 5 tiles on pending tree now bin, 273 // 5 tiles on active tree eventually bin, 5 tiles on pending tree that are
260 // but only enough memory for 4 tiles. The result is 4 pending tree tiles 274 // required for activation, but only enough memory for 4 tiles. The result
261 // get memory, and none of the active tree tiles get memory. 275 // is 4 pending tree tiles get memory, and none of the active tree tiles
276 // get memory.
262 277
263 Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); 278 Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY);
264 TileVector active_tree_tiles = 279 TileVector active_tree_tiles =
265 CreateTiles(5, TilePriorityForEventualBin(), TilePriority()); 280 CreateTiles(5, TilePriorityForEventualBin(), TilePriority());
266 TileVector pending_tree_tiles = 281 TileVector pending_tree_tiles =
267 CreateTiles(5, TilePriority(), TilePriorityForNowBin()); 282 CreateTiles(5, TilePriority(), TilePriorityRequiredForActivation());
268 283
269 tile_manager()->ManageTiles(); 284 tile_manager()->ManageTiles();
270 285
286 EXPECT_EQ(4, AssignedMemoryCount(active_tree_tiles));
287 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles));
288
289 tile_manager()->ReassignMemoryToOOMTilesRequiredForActivation();
290
271 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); 291 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles));
272 EXPECT_EQ(4, AssignedMemoryCount(pending_tree_tiles)); 292 EXPECT_EQ(4, AssignedMemoryCount(pending_tree_tiles));
273 } 293 }
274 294
275 TEST_F(TileManagerTest, TotalOOMActiveSoonMemoryToPending) { 295 TEST_F(TileManagerTest, TotalOOMActiveSoonMemoryToPending) {
276 // 5 tiles on active tree soon bin, 5 tiles on pending tree now bin, 296 // 5 tiles on active tree soon bin, 5 tiles on pending tree that are
277 // but only enough memory for 4 tiles. The result is 4 pending tree tiles 297 // required for activation, but only enough memory for 4 tiles. The result
278 // get memory, and none of the active tree tiles get memory. 298 // is 4 pending tree tiles get memory, and none of the active tree tiles
299 // get memory.
279 300
280 Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); 301 Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY);
281 TileVector active_tree_tiles = 302 TileVector active_tree_tiles =
282 CreateTiles(5, TilePriorityForSoonBin(), TilePriority()); 303 CreateTiles(5, TilePriorityForSoonBin(), TilePriority());
283 TileVector pending_tree_tiles = 304 TileVector pending_tree_tiles =
284 CreateTiles(5, TilePriority(), TilePriorityForNowBin()); 305 CreateTiles(5, TilePriority(), TilePriorityRequiredForActivation());
285 306
286 tile_manager()->ManageTiles(); 307 tile_manager()->ManageTiles();
287 308
309 EXPECT_EQ(4, AssignedMemoryCount(active_tree_tiles));
310 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles));
311
312 tile_manager()->ReassignMemoryToOOMTilesRequiredForActivation();
313
288 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); 314 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles));
289 EXPECT_EQ(4, AssignedMemoryCount(pending_tree_tiles)); 315 EXPECT_EQ(4, AssignedMemoryCount(pending_tree_tiles));
290 } 316 }
291 317
292 TEST_F(TileManagerTest, TotalOOMMemoryToActive) { 318 TEST_F(TileManagerTest, TotalOOMMemoryToActive) {
293 // 5 tiles on active tree eventually bin, 5 tiles on pending tree now bin, 319 // 5 tiles on active tree eventually bin, 5 tiles on pending tree now bin,
294 // but only enough memory for 4 tiles. The result is 5 active tree tiles 320 // but only enough memory for 4 tiles. The result is 5 active tree tiles
295 // get memory, and none of the pending tree tiles get memory. 321 // get memory, and none of the pending tree tiles get memory.
296 322
297 Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); 323 Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 } 467 }
442 468
443 tile_manager()->ManageTiles(); 469 tile_manager()->ManageTiles();
444 470
445 EXPECT_EQ(0, TilesWithLCDCount(active_tree_tiles)); 471 EXPECT_EQ(0, TilesWithLCDCount(active_tree_tiles));
446 EXPECT_EQ(0, TilesWithLCDCount(pending_tree_tiles)); 472 EXPECT_EQ(0, TilesWithLCDCount(pending_tree_tiles));
447 } 473 }
448 474
449 } // namespace 475 } // namespace
450 } // namespace cc 476 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/tile_manager.cc ('k') | cc/resources/worker_pool.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698