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

Side by Side Diff: cc/tile_manager.cc

Issue 11637022: Send memory management policies to the tile manager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporate review feedback Created 7 years, 11 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
« cc/tile_manager.h ('K') | « cc/tile_manager.h ('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
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/tile_manager.h" 5 #include "cc/tile_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 21 matching lines...) Expand all
32 const int kNumPendingRasterTasksPerThread = 2; 32 const int kNumPendingRasterTasksPerThread = 2;
33 33
34 // Determine bin based on three categories of tiles: things we need now, 34 // Determine bin based on three categories of tiles: things we need now,
35 // things we need soon, and eventually. 35 // things we need soon, and eventually.
36 cc::TileManagerBin BinFromTilePriority(const cc::TilePriority& prio) { 36 cc::TileManagerBin BinFromTilePriority(const cc::TilePriority& prio) {
37 37
38 // The amount of time for which we want to have prepainting coverage. 38 // The amount of time for which we want to have prepainting coverage.
39 const double prepainting_window_time_seconds = 1.0; 39 const double prepainting_window_time_seconds = 1.0;
40 const double backfling_guard_distance_pixels = 314.0; 40 const double backfling_guard_distance_pixels = 314.0;
41 41
42 // Explicitly limit how far ahead we will prepaint for low and non-low res.
43 const double max_lores_paint_distance_pixels = 8192.0;
44 const double max_hires_paint_distance_pixels = 4096.0;
45 if (prio.resolution == cc::LOW_RESOLUTION) {
46 if (prio.distance_to_visible_in_pixels > max_lores_paint_distance_pixels)
47 return cc::NEVER_BIN;
48 }
49 else {
50 if (prio.distance_to_visible_in_pixels > max_hires_paint_distance_pixels)
51 return cc::NEVER_BIN;
52 }
53
42 if (prio.time_to_needed_in_seconds() == std::numeric_limits<float>::max()) 54 if (prio.time_to_needed_in_seconds() == std::numeric_limits<float>::max())
43 return cc::NEVER_BIN; 55 return cc::NEVER_BIN;
44 56
45 if (prio.resolution == cc::NON_IDEAL_RESOLUTION) 57 if (prio.resolution == cc::NON_IDEAL_RESOLUTION)
46 return cc::EVENTUALLY_BIN; 58 return cc::EVENTUALLY_BIN;
47 59
48 if (prio.time_to_needed_in_seconds() == 0 || 60 if (prio.time_to_needed_in_seconds() == 0 ||
49 prio.distance_to_visible_in_pixels < backfling_guard_distance_pixels) 61 prio.distance_to_visible_in_pixels < backfling_guard_distance_pixels)
50 return cc::NOW_BIN; 62 return cc::NOW_BIN;
51 63
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 int num_pending_tasks_; 152 int num_pending_tasks_;
141 153
142 DISALLOW_COPY_AND_ASSIGN(RasterThread); 154 DISALLOW_COPY_AND_ASSIGN(RasterThread);
143 }; 155 };
144 156
145 ManagedTileState::ManagedTileState() 157 ManagedTileState::ManagedTileState()
146 : can_use_gpu_memory(false), 158 : can_use_gpu_memory(false),
147 can_be_freed(true), 159 can_be_freed(true),
148 resource_is_being_initialized(false), 160 resource_is_being_initialized(false),
149 contents_swizzled(false), 161 contents_swizzled(false),
150 need_to_gather_pixel_refs(true) { 162 need_to_gather_pixel_refs(true),
163 gpu_memmgr_stats_bin(NEVER_BIN) {
151 } 164 }
152 165
153 ManagedTileState::~ManagedTileState() { 166 ManagedTileState::~ManagedTileState() {
154 DCHECK(!resource); 167 DCHECK(!resource);
155 DCHECK(!resource_is_being_initialized); 168 DCHECK(!resource_is_being_initialized);
156 } 169 }
157 170
158 TileManager::TileManager( 171 TileManager::TileManager(
159 TileManagerClient* client, 172 TileManagerClient* client,
160 ResourceProvider* resource_provider, 173 ResourceProvider* resource_provider,
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 292
280 TilePriority prio; 293 TilePriority prio;
281 if (smoothness_takes_priority) 294 if (smoothness_takes_priority)
282 prio = tile->priority(ACTIVE_TREE); 295 prio = tile->priority(ACTIVE_TREE);
283 else 296 else
284 prio = tile->combined_priority(); 297 prio = tile->combined_priority();
285 298
286 mts.resolution = prio.resolution; 299 mts.resolution = prio.resolution;
287 mts.time_to_needed_in_seconds = prio.time_to_needed_in_seconds(); 300 mts.time_to_needed_in_seconds = prio.time_to_needed_in_seconds();
288 mts.raster_bin = BinFromTilePriority(prio); 301 mts.raster_bin = BinFromTilePriority(prio);
302 mts.gpu_memmgr_stats_bin = BinFromTilePriority(tile->combined_priority());
289 } 303 }
290 304
291 // Memory limit policy works by mapping some bin states to the NEVER bin. 305 // Memory limit policy works by mapping some bin states to the NEVER bin.
292 TileManagerBin bin_map[NUM_BINS]; 306 TileManagerBin bin_map[NUM_BINS];
293 if (global_state_.memory_limit_policy == ALLOW_NOTHING) { 307 if (global_state_.memory_limit_policy == ALLOW_NOTHING) {
294 bin_map[NOW_BIN] = NEVER_BIN; 308 bin_map[NOW_BIN] = NEVER_BIN;
295 bin_map[SOON_BIN] = NEVER_BIN; 309 bin_map[SOON_BIN] = NEVER_BIN;
296 bin_map[EVENTUALLY_BIN] = NEVER_BIN; 310 bin_map[EVENTUALLY_BIN] = NEVER_BIN;
297 bin_map[NEVER_BIN] = NEVER_BIN; 311 bin_map[NEVER_BIN] = NEVER_BIN;
298 } else if (global_state_.memory_limit_policy == ALLOW_ABSOLUTE_MINIMUM) { 312 } else if (global_state_.memory_limit_policy == ALLOW_ABSOLUTE_MINIMUM) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 drawable_tiles_in_bin_count_[mts.bin[i]][i]++; 347 drawable_tiles_in_bin_count_[mts.bin[i]][i]++;
334 } 348 }
335 } 349 }
336 350
337 // Sort by bin. 351 // Sort by bin.
338 std::sort(tiles_.begin(), tiles_.end(), BinComparator()); 352 std::sort(tiles_.begin(), tiles_.end(), BinComparator());
339 353
340 // Assign gpu memory and determine what tiles need to be rasterized. 354 // Assign gpu memory and determine what tiles need to be rasterized.
341 AssignGpuMemoryToTiles(); 355 AssignGpuMemoryToTiles();
342 356
343 // Finally, kick the rasterizer. 357 // Kick the rasterizer.
344 DispatchMoreTasks(); 358 DispatchMoreTasks();
359
360 // Finally, send the new managed memory statistics to the GPU memory manager
361 SendManagedMemoryStats();
345 } 362 }
346 363
347 void TileManager::CheckForCompletedSetPixels() { 364 void TileManager::CheckForCompletedSetPixels() {
348 check_for_completed_set_pixels_pending_ = false; 365 check_for_completed_set_pixels_pending_ = false;
349 366
350 while (!tiles_with_pending_set_pixels_.empty()) { 367 while (!tiles_with_pending_set_pixels_.empty()) {
351 Tile* tile = tiles_with_pending_set_pixels_.front(); 368 Tile* tile = tiles_with_pending_set_pixels_.front();
352 DCHECK(tile->managed_state().resource); 369 DCHECK(tile->managed_state().resource);
353 370
354 // Set pixel tasks complete in the order they are posted. 371 // Set pixel tasks complete in the order they are posted.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 409
393 int TileManager::GetDrawableTilesInBinCount( 410 int TileManager::GetDrawableTilesInBinCount(
394 TileManagerBin bin, WhichTree tree) { 411 TileManagerBin bin, WhichTree tree) {
395 DCHECK(bin >= 0); 412 DCHECK(bin >= 0);
396 DCHECK(bin < NUM_BINS); 413 DCHECK(bin < NUM_BINS);
397 DCHECK(tree >= 0); 414 DCHECK(tree >= 0);
398 DCHECK(tree < NUM_TREES); 415 DCHECK(tree < NUM_TREES);
399 return drawable_tiles_in_bin_count_[bin][tree]; 416 return drawable_tiles_in_bin_count_[bin][tree];
400 } 417 }
401 418
419 void TileManager::SendManagedMemoryStats() {
420 size_t memoryRequiredBytes = 0;
421 size_t memoryNiceToHaveBytes = 0;
422 size_t memoryUsedBytes = 0;
423 for (TileVector::iterator it = tiles_.begin(); it != tiles_.end(); ++it) {
424 Tile* tile = *it;
425 ManagedTileState& mts = tile->managed_state();
426 size_t tile_bytes = tile->bytes_consumed_if_allocated();
427 if (mts.gpu_memmgr_stats_bin == NOW_BIN)
428 memoryRequiredBytes += tile_bytes;
429 if (mts.gpu_memmgr_stats_bin != NEVER_BIN)
430 memoryNiceToHaveBytes += tile_bytes;
431 if (mts.can_use_gpu_memory)
432 memoryUsedBytes += tile_bytes;
433 }
434 client_->SendTileManagerMemoryStats(
435 memoryRequiredBytes,
436 memoryNiceToHaveBytes,
437 memoryUsedBytes);
438 }
439
402 void TileManager::ResetBinCounts() { 440 void TileManager::ResetBinCounts() {
403 for (int i = 0; i < NUM_BINS; ++i) 441 for (int i = 0; i < NUM_BINS; ++i)
404 for (int j = 0; j < NUM_TREES; ++j) 442 for (int j = 0; j < NUM_TREES; ++j)
405 tiles_in_bin_count_[i][j] = drawable_tiles_in_bin_count_[i][j] = 0; 443 tiles_in_bin_count_[i][j] = drawable_tiles_in_bin_count_[i][j] = 0;
406 } 444 }
407 445
408 void TileManager::AssignGpuMemoryToTiles() { 446 void TileManager::AssignGpuMemoryToTiles() {
409 TRACE_EVENT0("cc", "TileManager::AssignGpuMemoryToTiles"); 447 TRACE_EVENT0("cc", "TileManager::AssignGpuMemoryToTiles");
410 // Some memory cannot be released. Figure out which. 448 // Some memory cannot be released. Figure out which.
411 size_t unreleasable_bytes = 0; 449 size_t unreleasable_bytes = 0;
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 void TileManager::DidFinishTileInitialization(Tile* tile) { 723 void TileManager::DidFinishTileInitialization(Tile* tile) {
686 ManagedTileState& managed_tile_state = tile->managed_state(); 724 ManagedTileState& managed_tile_state = tile->managed_state();
687 DCHECK(managed_tile_state.resource); 725 DCHECK(managed_tile_state.resource);
688 managed_tile_state.resource_is_being_initialized = false; 726 managed_tile_state.resource_is_being_initialized = false;
689 managed_tile_state.can_be_freed = true; 727 managed_tile_state.can_be_freed = true;
690 for (int i = 0; i < NUM_TREES; ++i) 728 for (int i = 0; i < NUM_TREES; ++i)
691 drawable_tiles_in_bin_count_[managed_tile_state.bin[i]][i]++; 729 drawable_tiles_in_bin_count_[managed_tile_state.bin[i]][i]++;
692 } 730 }
693 731
694 } 732 }
OLDNEW
« cc/tile_manager.h ('K') | « cc/tile_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698