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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
286 tile_is_active); | 290 tile_is_active); |
287 // Note that |gpu_memmgr_stats_bin| does not care about memory_policy, so we | 291 // Note that |gpu_memmgr_stats_bin| does not care about memory_policy, so we |
288 // have to save it first. | 292 // have to save it first. |
289 mts.gpu_memmgr_stats_bin = combined_bin; | 293 mts.gpu_memmgr_stats_bin = combined_bin; |
290 | 294 |
291 combined_bin = kBinPolicyMap[memory_policy][combined_bin]; | 295 combined_bin = kBinPolicyMap[memory_policy][combined_bin]; |
292 | 296 |
293 TilePriority* high_priority = NULL; | 297 TilePriority* high_priority = NULL; |
294 switch (tree_priority) { | 298 switch (tree_priority) { |
295 case SAME_PRIORITY_FOR_BOTH_TREES: | 299 case SAME_PRIORITY_FOR_BOTH_TREES: |
296 mts.bin[HIGH_PRIORITY_BIN] = mts.bin[LOW_PRIORITY_BIN] = combined_bin; | 300 mts.bin = combined_bin; |
297 high_priority = &combined_priority; | 301 high_priority = &combined_priority; |
298 break; | 302 break; |
299 case SMOOTHNESS_TAKES_PRIORITY: | 303 case SMOOTHNESS_TAKES_PRIORITY: |
300 mts.bin[HIGH_PRIORITY_BIN] = mts.tree_bin[ACTIVE_TREE]; | 304 if (mts.tree_bin[ACTIVE_TREE] == NEVER_BIN && |
301 mts.bin[LOW_PRIORITY_BIN] = mts.tree_bin[PENDING_TREE]; | 305 mts.tree_bin[PENDING_TREE] != NEVER_BIN) |
306 mts.bin = tile_is_active ? AT_LAST_AND_ACTIVE_BIN : AT_LAST_BIN; | |
307 else | |
308 mts.bin = mts.tree_bin[ACTIVE_TREE]; | |
302 high_priority = &active_priority; | 309 high_priority = &active_priority; |
303 break; | 310 break; |
304 case NEW_CONTENT_TAKES_PRIORITY: | 311 case NEW_CONTENT_TAKES_PRIORITY: |
305 mts.bin[HIGH_PRIORITY_BIN] = mts.tree_bin[PENDING_TREE]; | 312 if (mts.tree_bin[PENDING_TREE] == NEVER_BIN && |
306 mts.bin[LOW_PRIORITY_BIN] = mts.tree_bin[ACTIVE_TREE]; | 313 mts.tree_bin[ACTIVE_TREE] != NEVER_BIN) |
314 mts.bin = tile_is_active ? AT_LAST_AND_ACTIVE_BIN : AT_LAST_BIN; | |
315 else | |
316 mts.bin = mts.tree_bin[PENDING_TREE]; | |
reveman
2013/08/26 16:55:46
can we clean this up somehow? maybe bump the bin u
vmpstr
2013/08/26 17:30:59
Done.
| |
307 high_priority = &pending_priority; | 317 high_priority = &pending_priority; |
308 break; | 318 break; |
309 } | 319 } |
310 | 320 |
311 DCHECK(high_priority != NULL); | 321 DCHECK(high_priority != NULL); |
312 | 322 |
313 mts.resolution = high_priority->resolution; | 323 mts.resolution = high_priority->resolution; |
314 mts.time_to_needed_in_seconds = high_priority->time_to_visible_in_seconds; | 324 mts.time_to_needed_in_seconds = high_priority->time_to_visible_in_seconds; |
315 mts.distance_to_visible_in_pixels = | 325 mts.distance_to_visible_in_pixels = |
316 high_priority->distance_to_visible_in_pixels; | 326 high_priority->distance_to_visible_in_pixels; |
317 mts.required_for_activation = high_priority->required_for_activation; | 327 mts.required_for_activation = high_priority->required_for_activation; |
318 | 328 |
319 mts.visible_and_ready_to_draw = | 329 mts.visible_and_ready_to_draw = |
320 mts.tree_bin[ACTIVE_TREE] == NOW_AND_READY_TO_DRAW_BIN; | 330 mts.tree_bin[ACTIVE_TREE] == NOW_AND_READY_TO_DRAW_BIN; |
321 | 331 |
322 if (mts.is_in_never_bin_on_both_trees()) { | 332 if (mts.bin == NEVER_BIN) { |
323 FreeResourcesForTile(tile); | 333 FreeResourcesForTile(tile); |
324 continue; | 334 continue; |
325 } | 335 } |
326 | 336 |
327 // Note that if the tile is visible_and_ready_to_draw, then we always want | 337 // Note that if the tile is visible_and_ready_to_draw, then we always want |
328 // the priority to be NOW_AND_READY_TO_DRAW_BIN, even if HIGH_PRIORITY_BIN | 338 // the priority to be NOW_AND_READY_TO_DRAW_BIN, even if HIGH_PRIORITY_BIN |
329 // is something different. The reason for this is that if we're prioritizing | 339 // is something different. The reason for this is that if we're prioritizing |
330 // the pending tree, we still want visible tiles to take the highest | 340 // the pending tree, we still want visible tiles to take the highest |
331 // priority. | 341 // priority. |
332 ManagedTileBin priority_bin = mts.visible_and_ready_to_draw | 342 ManagedTileBin priority_bin = mts.visible_and_ready_to_draw |
333 ? NOW_AND_READY_TO_DRAW_BIN | 343 ? NOW_AND_READY_TO_DRAW_BIN |
334 : mts.bin[HIGH_PRIORITY_BIN]; | 344 : mts.bin; |
335 | 345 |
336 // Insert the tile into a priority set. | 346 // Insert the tile into a priority set. |
337 tiles->InsertTile(tile, priority_bin); | 347 tiles->InsertTile(tile, priority_bin); |
338 } | 348 } |
339 } | 349 } |
340 | 350 |
341 void TileManager::ManageTiles() { | 351 void TileManager::ManageTiles() { |
342 TRACE_EVENT0("cc", "TileManager::ManageTiles"); | 352 TRACE_EVENT0("cc", "TileManager::ManageTiles"); |
343 | 353 |
344 // Clear |prioritized_tiles_| so that tiles kept alive by it can be freed. | 354 // Clear |prioritized_tiles_| so that tiles kept alive by it can be freed. |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
509 mts.raster_mode = DetermineRasterMode(tile); | 519 mts.raster_mode = DetermineRasterMode(tile); |
510 | 520 |
511 ManagedTileState::TileVersion& tile_version = | 521 ManagedTileState::TileVersion& tile_version = |
512 mts.tile_versions[mts.raster_mode]; | 522 mts.tile_versions[mts.raster_mode]; |
513 | 523 |
514 // If this tile doesn't need a resource, then nothing to do. | 524 // If this tile doesn't need a resource, then nothing to do. |
515 if (!tile_version.requires_resource()) | 525 if (!tile_version.requires_resource()) |
516 continue; | 526 continue; |
517 | 527 |
518 // If the tile is not needed, free it up. | 528 // If the tile is not needed, free it up. |
519 if (mts.is_in_never_bin_on_both_trees()) { | 529 if (mts.bin == NEVER_BIN) { |
520 FreeResourcesForTile(tile); | 530 FreeResourcesForTile(tile); |
521 continue; | 531 continue; |
522 } | 532 } |
523 | 533 |
524 size_t tile_bytes = 0; | 534 size_t tile_bytes = 0; |
525 size_t tile_resources = 0; | 535 size_t tile_resources = 0; |
526 | 536 |
527 // It costs to maintain a resource. | 537 // It costs to maintain a resource. |
528 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { | 538 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { |
529 if (mts.tile_versions[mode].resource_) { | 539 if (mts.tile_versions[mode].resource_) { |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
827 bytes_releasable_ += tile->bytes_consumed_if_allocated(); | 837 bytes_releasable_ += tile->bytes_consumed_if_allocated(); |
828 ++resources_releasable_; | 838 ++resources_releasable_; |
829 } | 839 } |
830 | 840 |
831 FreeUnusedResourcesForTile(tile); | 841 FreeUnusedResourcesForTile(tile); |
832 if (tile->priority(ACTIVE_TREE).distance_to_visible_in_pixels == 0) | 842 if (tile->priority(ACTIVE_TREE).distance_to_visible_in_pixels == 0) |
833 did_initialize_visible_tile_ = true; | 843 did_initialize_visible_tile_ = true; |
834 } | 844 } |
835 | 845 |
836 } // namespace cc | 846 } // namespace cc |
OLD | NEW |