OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "cc/resources/tile_manager.h" | 5 #include "cc/resources/tile_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... | |
25 namespace { | 25 namespace { |
26 | 26 |
27 // Memory limit policy works by mapping some bin states to the NEVER bin. | 27 // Memory limit policy works by mapping some bin states to the NEVER bin. |
28 const ManagedTileBin kBinPolicyMap[NUM_TILE_MEMORY_LIMIT_POLICIES][NUM_BINS] = { | 28 const ManagedTileBin kBinPolicyMap[NUM_TILE_MEMORY_LIMIT_POLICIES][NUM_BINS] = { |
29 { // [ALLOW_NOTHING] | 29 { // [ALLOW_NOTHING] |
30 NEVER_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | 30 NEVER_BIN, // [NOW_AND_READY_TO_DRAW_BIN] |
31 NEVER_BIN, // [NOW_BIN] | 31 NEVER_BIN, // [NOW_BIN] |
32 NEVER_BIN, // [SOON_BIN] | 32 NEVER_BIN, // [SOON_BIN] |
33 NEVER_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | 33 NEVER_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] |
34 NEVER_BIN, // [EVENTUALLY_BIN] | 34 NEVER_BIN, // [EVENTUALLY_BIN] |
35 NEVER_BIN, // [NEVER_AND_ACTIVE_BIN] | 35 NEVER_BIN, // [AT_LAST_AND_ACTIVE_BIN] |
36 NEVER_BIN, // [AT_LAST_BIN] | |
36 NEVER_BIN // [NEVER_BIN] | 37 NEVER_BIN // [NEVER_BIN] |
37 }, { // [ALLOW_ABSOLUTE_MINIMUM] | 38 }, { // [ALLOW_ABSOLUTE_MINIMUM] |
38 NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | 39 NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] |
39 NOW_BIN, // [NOW_BIN] | 40 NOW_BIN, // [NOW_BIN] |
40 NEVER_BIN, // [SOON_BIN] | 41 NEVER_BIN, // [SOON_BIN] |
41 NEVER_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | 42 NEVER_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] |
42 NEVER_BIN, // [EVENTUALLY_BIN] | 43 NEVER_BIN, // [EVENTUALLY_BIN] |
43 NEVER_BIN, // [NEVER_AND_ACTIVE_BIN] | 44 NEVER_BIN, // [AT_LAST_AND_ACTIVE_BIN] |
45 NEVER_BIN, // [AT_LAST_BIN] | |
44 NEVER_BIN // [NEVER_BIN] | 46 NEVER_BIN // [NEVER_BIN] |
45 }, { // [ALLOW_PREPAINT_ONLY] | 47 }, { // [ALLOW_PREPAINT_ONLY] |
46 NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | 48 NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] |
47 NOW_BIN, // [NOW_BIN] | 49 NOW_BIN, // [NOW_BIN] |
48 SOON_BIN, // [SOON_BIN] | 50 SOON_BIN, // [SOON_BIN] |
49 NEVER_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | 51 NEVER_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] |
50 NEVER_BIN, // [EVENTUALLY_BIN] | 52 NEVER_BIN, // [EVENTUALLY_BIN] |
51 NEVER_BIN, // [NEVER_AND_ACTIVE_BIN] | 53 NEVER_BIN, // [AT_LAST_AND_ACTIVE_BIN] |
54 NEVER_BIN, // [AT_LAST_BIN] | |
52 NEVER_BIN // [NEVER_BIN] | 55 NEVER_BIN // [NEVER_BIN] |
53 }, { // [ALLOW_ANYTHING] | 56 }, { // [ALLOW_ANYTHING] |
54 NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | 57 NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] |
55 NOW_BIN, // [NOW_BIN] | 58 NOW_BIN, // [NOW_BIN] |
56 SOON_BIN, // [SOON_BIN] | 59 SOON_BIN, // [SOON_BIN] |
57 EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | 60 EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] |
58 EVENTUALLY_BIN, // [EVENTUALLY_BIN] | 61 EVENTUALLY_BIN, // [EVENTUALLY_BIN] |
59 NEVER_AND_ACTIVE_BIN, // [NEVER_AND_ACTIVE_BIN] | 62 AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_AND_ACTIVE_BIN] |
63 AT_LAST_BIN, // [AT_LAST_BIN] | |
60 NEVER_BIN // [NEVER_BIN] | 64 NEVER_BIN // [NEVER_BIN] |
61 } | 65 } |
62 }; | 66 }; |
63 | 67 |
64 // Determine bin based on three categories of tiles: things we need now, | 68 // Determine bin based on three categories of tiles: things we need now, |
65 // things we need soon, and eventually. | 69 // things we need soon, and eventually. |
66 inline ManagedTileBin BinFromTilePriority(const TilePriority& prio, | 70 inline ManagedTileBin BinFromTilePriority(const TilePriority& prio, |
67 TreePriority tree_priority, | 71 TreePriority tree_priority, |
68 bool is_ready_to_draw, | 72 bool is_ready_to_draw, |
69 bool is_active) { | 73 bool is_active) { |
70 // The amount of time for which we want to have prepainting coverage. | 74 // The amount of time for which we want to have prepainting coverage. |
71 const float kPrepaintingWindowTimeSeconds = 1.0f; | 75 const float kPrepaintingWindowTimeSeconds = 1.0f; |
72 const float kBackflingGuardDistancePixels = 314.0f; | 76 const float kBackflingGuardDistancePixels = 314.0f; |
73 | 77 |
74 // Don't let low res tiles be in the now bin unless we're in a mode where | 78 // Don't let low res tiles be in the now bin unless we're in a mode where |
75 // we're prioritizing checkerboard prevention. | 79 // we're prioritizing checkerboard prevention. |
76 bool can_be_in_now_bin = tree_priority == SMOOTHNESS_TAKES_PRIORITY || | 80 bool can_be_in_now_bin = tree_priority == SMOOTHNESS_TAKES_PRIORITY || |
77 prio.resolution != LOW_RESOLUTION; | 81 prio.resolution != LOW_RESOLUTION; |
78 | 82 |
79 if (prio.distance_to_visible_in_pixels == | 83 if (prio.distance_to_visible_in_pixels == |
80 std::numeric_limits<float>::infinity()) | 84 std::numeric_limits<float>::infinity()) |
81 return is_active ? NEVER_AND_ACTIVE_BIN : NEVER_BIN; | 85 return NEVER_BIN; |
82 | 86 |
83 if (can_be_in_now_bin && prio.time_to_visible_in_seconds == 0) | 87 if (can_be_in_now_bin && prio.time_to_visible_in_seconds == 0) |
84 return is_ready_to_draw ? NOW_AND_READY_TO_DRAW_BIN : NOW_BIN; | 88 return is_ready_to_draw ? NOW_AND_READY_TO_DRAW_BIN : NOW_BIN; |
85 | 89 |
86 if (prio.resolution == NON_IDEAL_RESOLUTION) | 90 if (prio.resolution == NON_IDEAL_RESOLUTION) |
87 return is_active ? EVENTUALLY_AND_ACTIVE_BIN : EVENTUALLY_BIN; | 91 return is_active ? EVENTUALLY_AND_ACTIVE_BIN : EVENTUALLY_BIN; |
88 | 92 |
89 if (prio.distance_to_visible_in_pixels < kBackflingGuardDistancePixels || | 93 if (prio.distance_to_visible_in_pixels < kBackflingGuardDistancePixels || |
90 prio.time_to_visible_in_seconds < kPrepaintingWindowTimeSeconds) | 94 prio.time_to_visible_in_seconds < kPrepaintingWindowTimeSeconds) |
91 return SOON_BIN; | 95 return SOON_BIN; |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
299 tree_priority, | 303 tree_priority, |
300 tile_is_ready_to_draw, | 304 tile_is_ready_to_draw, |
301 tile_is_active); | 305 tile_is_active); |
302 // Note that |gpu_memmgr_stats_bin| does not care about memory_policy, so we | 306 // Note that |gpu_memmgr_stats_bin| does not care about memory_policy, so we |
303 // have to save it first. | 307 // have to save it first. |
304 mts.gpu_memmgr_stats_bin = combined_bin; | 308 mts.gpu_memmgr_stats_bin = combined_bin; |
305 | 309 |
306 combined_bin = kBinPolicyMap[memory_policy][combined_bin]; | 310 combined_bin = kBinPolicyMap[memory_policy][combined_bin]; |
307 | 311 |
308 TilePriority* high_priority = NULL; | 312 TilePriority* high_priority = NULL; |
313 bool dual_bin_is_never = false; | |
309 switch (tree_priority) { | 314 switch (tree_priority) { |
310 case SAME_PRIORITY_FOR_BOTH_TREES: | 315 case SAME_PRIORITY_FOR_BOTH_TREES: |
311 mts.bin[HIGH_PRIORITY_BIN] = mts.bin[LOW_PRIORITY_BIN] = combined_bin; | 316 mts.bin = combined_bin; |
317 dual_bin_is_never = (combined_bin == NEVER_BIN); | |
312 high_priority = &combined_priority; | 318 high_priority = &combined_priority; |
313 break; | 319 break; |
314 case SMOOTHNESS_TAKES_PRIORITY: | 320 case SMOOTHNESS_TAKES_PRIORITY: |
315 mts.bin[HIGH_PRIORITY_BIN] = mts.tree_bin[ACTIVE_TREE]; | 321 mts.bin = mts.tree_bin[ACTIVE_TREE]; |
316 mts.bin[LOW_PRIORITY_BIN] = mts.tree_bin[PENDING_TREE]; | 322 dual_bin_is_never = (mts.tree_bin[PENDING_TREE] == NEVER_BIN); |
317 high_priority = &active_priority; | 323 high_priority = &active_priority; |
318 break; | 324 break; |
319 case NEW_CONTENT_TAKES_PRIORITY: | 325 case NEW_CONTENT_TAKES_PRIORITY: |
320 mts.bin[HIGH_PRIORITY_BIN] = mts.tree_bin[PENDING_TREE]; | 326 mts.bin = mts.tree_bin[PENDING_TREE]; |
321 mts.bin[LOW_PRIORITY_BIN] = mts.tree_bin[ACTIVE_TREE]; | 327 dual_bin_is_never = (mts.tree_bin[ACTIVE_TREE] == NEVER_BIN); |
322 high_priority = &pending_priority; | 328 high_priority = &pending_priority; |
323 break; | 329 break; |
324 } | 330 } |
325 | 331 |
332 // Bump up the priority if we determined it's NEVER_BIN on one tree, | |
333 // but is still required on the other tree. | |
334 if (mts.bin == NEVER_BIN && !dual_bin_is_never) | |
reveman
2013/08/26 20:56:29
would:
bool is_in_never_bin_on_both_trees =
m
vmpstr
2013/08/26 21:08:08
Yep. That looks better to me, I've changed it.
| |
335 mts.bin = tile_is_active ? AT_LAST_AND_ACTIVE_BIN : AT_LAST_BIN; | |
336 | |
326 DCHECK(high_priority != NULL); | 337 DCHECK(high_priority != NULL); |
327 | 338 |
328 mts.resolution = high_priority->resolution; | 339 mts.resolution = high_priority->resolution; |
329 mts.time_to_needed_in_seconds = high_priority->time_to_visible_in_seconds; | 340 mts.time_to_needed_in_seconds = high_priority->time_to_visible_in_seconds; |
330 mts.distance_to_visible_in_pixels = | 341 mts.distance_to_visible_in_pixels = |
331 high_priority->distance_to_visible_in_pixels; | 342 high_priority->distance_to_visible_in_pixels; |
332 mts.required_for_activation = high_priority->required_for_activation; | 343 mts.required_for_activation = high_priority->required_for_activation; |
333 | 344 |
334 mts.visible_and_ready_to_draw = | 345 mts.visible_and_ready_to_draw = |
335 mts.tree_bin[ACTIVE_TREE] == NOW_AND_READY_TO_DRAW_BIN; | 346 mts.tree_bin[ACTIVE_TREE] == NOW_AND_READY_TO_DRAW_BIN; |
336 | 347 |
337 if (mts.is_in_never_bin_on_both_trees()) { | 348 if (mts.bin == NEVER_BIN) { |
338 FreeResourcesForTile(tile); | 349 FreeResourcesForTile(tile); |
339 continue; | 350 continue; |
340 } | 351 } |
341 | 352 |
342 // Note that if the tile is visible_and_ready_to_draw, then we always want | 353 // Note that if the tile is visible_and_ready_to_draw, then we always want |
343 // the priority to be NOW_AND_READY_TO_DRAW_BIN, even if HIGH_PRIORITY_BIN | 354 // the priority to be NOW_AND_READY_TO_DRAW_BIN, even if HIGH_PRIORITY_BIN |
344 // is something different. The reason for this is that if we're prioritizing | 355 // is something different. The reason for this is that if we're prioritizing |
345 // the pending tree, we still want visible tiles to take the highest | 356 // the pending tree, we still want visible tiles to take the highest |
346 // priority. | 357 // priority. |
347 ManagedTileBin priority_bin = mts.visible_and_ready_to_draw | 358 ManagedTileBin priority_bin = mts.visible_and_ready_to_draw |
348 ? NOW_AND_READY_TO_DRAW_BIN | 359 ? NOW_AND_READY_TO_DRAW_BIN |
349 : mts.bin[HIGH_PRIORITY_BIN]; | 360 : mts.bin; |
350 | 361 |
351 // Insert the tile into a priority set. | 362 // Insert the tile into a priority set. |
352 tiles->InsertTile(tile, priority_bin); | 363 tiles->InsertTile(tile, priority_bin); |
353 } | 364 } |
354 } | 365 } |
355 | 366 |
356 void TileManager::ManageTiles() { | 367 void TileManager::ManageTiles() { |
357 TRACE_EVENT0("cc", "TileManager::ManageTiles"); | 368 TRACE_EVENT0("cc", "TileManager::ManageTiles"); |
358 | 369 |
359 TileVector tiles_that_need_to_be_rasterized; | 370 TileVector tiles_that_need_to_be_rasterized; |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
519 mts.raster_mode = DetermineRasterMode(tile); | 530 mts.raster_mode = DetermineRasterMode(tile); |
520 | 531 |
521 ManagedTileState::TileVersion& tile_version = | 532 ManagedTileState::TileVersion& tile_version = |
522 mts.tile_versions[mts.raster_mode]; | 533 mts.tile_versions[mts.raster_mode]; |
523 | 534 |
524 // If this tile doesn't need a resource, then nothing to do. | 535 // If this tile doesn't need a resource, then nothing to do. |
525 if (!tile_version.requires_resource()) | 536 if (!tile_version.requires_resource()) |
526 continue; | 537 continue; |
527 | 538 |
528 // If the tile is not needed, free it up. | 539 // If the tile is not needed, free it up. |
529 if (mts.is_in_never_bin_on_both_trees()) { | 540 if (mts.bin == NEVER_BIN) { |
530 FreeResourcesForTile(tile); | 541 FreeResourcesForTile(tile); |
531 continue; | 542 continue; |
532 } | 543 } |
533 | 544 |
534 size_t tile_bytes = 0; | 545 size_t tile_bytes = 0; |
535 size_t tile_resources = 0; | 546 size_t tile_resources = 0; |
536 | 547 |
537 // It costs to maintain a resource. | 548 // It costs to maintain a resource. |
538 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { | 549 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { |
539 if (mts.tile_versions[mode].resource_) { | 550 if (mts.tile_versions[mode].resource_) { |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
837 bytes_releasable_ += tile->bytes_consumed_if_allocated(); | 848 bytes_releasable_ += tile->bytes_consumed_if_allocated(); |
838 ++resources_releasable_; | 849 ++resources_releasable_; |
839 } | 850 } |
840 | 851 |
841 FreeUnusedResourcesForTile(tile); | 852 FreeUnusedResourcesForTile(tile); |
842 if (tile->priority(ACTIVE_TREE).distance_to_visible_in_pixels == 0) | 853 if (tile->priority(ACTIVE_TREE).distance_to_visible_in_pixels == 0) |
843 did_initialize_visible_tile_ = true; | 854 did_initialize_visible_tile_ = true; |
844 } | 855 } |
845 | 856 |
846 } // namespace cc | 857 } // namespace cc |
OLD | NEW |