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

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 discussions 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/managed_memory_policy.cc ('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 20 matching lines...) Expand all
31 // low while making sure raster threads aren't unnecessarily idle. 31 // low while making sure raster threads aren't unnecessarily idle.
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 const double maximum_paint_distance_pixels = 4096.0;
41 42
42 if (prio.time_to_needed_in_seconds() == std::numeric_limits<float>::max()) 43 if (prio.time_to_needed_in_seconds() == std::numeric_limits<float>::max())
43 return cc::NEVER_BIN; 44 return cc::NEVER_BIN;
44 45
46 if (prio.distance_to_visible_in_pixels > maximum_paint_distance_pixels)
ccameron 2012/12/26 23:55:54 I discussed this with Nat earlier. If we allow the
enne (OOO) 2012/12/27 22:06:39 This seems pretty reasonable to me for the moment.
47 return cc::NEVER_BIN;
48
45 if (prio.resolution == cc::NON_IDEAL_RESOLUTION) 49 if (prio.resolution == cc::NON_IDEAL_RESOLUTION)
46 return cc::EVENTUALLY_BIN; 50 return cc::EVENTUALLY_BIN;
47 51
48 if (prio.time_to_needed_in_seconds() == 0 || 52 if (prio.time_to_needed_in_seconds() == 0 ||
49 prio.distance_to_visible_in_pixels < backfling_guard_distance_pixels) 53 prio.distance_to_visible_in_pixels < backfling_guard_distance_pixels)
50 return cc::NOW_BIN; 54 return cc::NOW_BIN;
51 55
52 if (prio.time_to_needed_in_seconds() < prepainting_window_time_seconds) 56 if (prio.time_to_needed_in_seconds() < prepainting_window_time_seconds)
53 return cc::SOON_BIN; 57 return cc::SOON_BIN;
54 58
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 int num_pending_tasks_; 144 int num_pending_tasks_;
141 145
142 DISALLOW_COPY_AND_ASSIGN(RasterThread); 146 DISALLOW_COPY_AND_ASSIGN(RasterThread);
143 }; 147 };
144 148
145 ManagedTileState::ManagedTileState() 149 ManagedTileState::ManagedTileState()
146 : can_use_gpu_memory(false), 150 : can_use_gpu_memory(false),
147 can_be_freed(true), 151 can_be_freed(true),
148 resource_is_being_initialized(false), 152 resource_is_being_initialized(false),
149 contents_swizzled(false), 153 contents_swizzled(false),
150 need_to_gather_pixel_refs(true) { 154 need_to_gather_pixel_refs(true),
155 gpu_memmgr_stats_bin(NEVER_BIN) {
151 } 156 }
152 157
153 ManagedTileState::~ManagedTileState() { 158 ManagedTileState::~ManagedTileState() {
154 DCHECK(!resource); 159 DCHECK(!resource);
155 DCHECK(!resource_is_being_initialized); 160 DCHECK(!resource_is_being_initialized);
156 } 161 }
157 162
158 TileManager::TileManager( 163 TileManager::TileManager(
159 TileManagerClient* client, 164 TileManagerClient* client,
160 ResourceProvider* resource_provider, 165 ResourceProvider* resource_provider,
(...skipping 24 matching lines...) Expand all
185 // This should finish all pending raster tasks and release any 190 // This should finish all pending raster tasks and release any
186 // uninitialized resources. 191 // uninitialized resources.
187 raster_threads_.clear(); 192 raster_threads_.clear();
188 ManageTiles(); 193 ManageTiles();
189 DCHECK(tiles_.size() == 0); 194 DCHECK(tiles_.size() == 0);
190 } 195 }
191 196
192 void TileManager::SetGlobalState(const GlobalStateThatImpactsTilePriority& globa l_state) { 197 void TileManager::SetGlobalState(const GlobalStateThatImpactsTilePriority& globa l_state) {
193 global_state_ = global_state; 198 global_state_ = global_state;
194 resource_pool_->SetMaxMemoryUsageBytes(global_state_.memory_limit_in_bytes); 199 resource_pool_->SetMaxMemoryUsageBytes(global_state_.memory_limit_in_bytes);
195 ScheduleManageTiles(); 200 ManageTiles();
ccameron 2012/12/26 23:55:54 Be sure to verify whether or not this change is ac
enne (OOO) 2012/12/27 22:06:39 This feels a little heavy handed. I think I would
ccameron 2012/12/27 22:42:59 Yes, this wasn't the right way to do it. I changed
enne (OOO) 2012/12/27 23:02:00 That sounds a lot better. :)
196 } 201 }
197 202
198 void TileManager::RegisterTile(Tile* tile) { 203 void TileManager::RegisterTile(Tile* tile) {
199 tiles_.push_back(tile); 204 tiles_.push_back(tile);
200 ScheduleManageTiles(); 205 ScheduleManageTiles();
201 } 206 }
202 207
203 void TileManager::UnregisterTile(Tile* tile) { 208 void TileManager::UnregisterTile(Tile* tile) {
204 for (TileList::iterator it = tiles_with_image_decoding_tasks_.begin(); 209 for (TileList::iterator it = tiles_with_image_decoding_tasks_.begin();
205 it != tiles_with_image_decoding_tasks_.end(); it++) { 210 it != tiles_with_image_decoding_tasks_.end(); it++) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 284
280 TilePriority prio; 285 TilePriority prio;
281 if (smoothness_takes_priority) 286 if (smoothness_takes_priority)
282 prio = tile->priority(ACTIVE_TREE); 287 prio = tile->priority(ACTIVE_TREE);
283 else 288 else
284 prio = tile->combined_priority(); 289 prio = tile->combined_priority();
285 290
286 mts.resolution = prio.resolution; 291 mts.resolution = prio.resolution;
287 mts.time_to_needed_in_seconds = prio.time_to_needed_in_seconds(); 292 mts.time_to_needed_in_seconds = prio.time_to_needed_in_seconds();
288 mts.raster_bin = BinFromTilePriority(prio); 293 mts.raster_bin = BinFromTilePriority(prio);
294 mts.gpu_memmgr_stats_bin = BinFromTilePriority(tile->combined_priority());
ccameron 2012/12/26 23:55:54 I keep this bin around permanently so that we may
289 } 295 }
290 296
291 // Memory limit policy works by mapping some bin states to the NEVER bin. 297 // Memory limit policy works by mapping some bin states to the NEVER bin.
292 TileManagerBin bin_map[NUM_BINS]; 298 TileManagerBin bin_map[NUM_BINS];
293 if (global_state_.memory_limit_policy == ALLOW_NOTHING) { 299 if (global_state_.memory_limit_policy == ALLOW_NOTHING) {
294 bin_map[NOW_BIN] = NEVER_BIN; 300 bin_map[NOW_BIN] = NEVER_BIN;
295 bin_map[SOON_BIN] = NEVER_BIN; 301 bin_map[SOON_BIN] = NEVER_BIN;
296 bin_map[EVENTUALLY_BIN] = NEVER_BIN; 302 bin_map[EVENTUALLY_BIN] = NEVER_BIN;
297 bin_map[NEVER_BIN] = NEVER_BIN; 303 bin_map[NEVER_BIN] = NEVER_BIN;
298 } else if (global_state_.memory_limit_policy == ALLOW_ABSOLUTE_MINIMUM) { 304 } else if (global_state_.memory_limit_policy == ALLOW_ABSOLUTE_MINIMUM) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 398
393 int TileManager::GetDrawableTilesInBinCount( 399 int TileManager::GetDrawableTilesInBinCount(
394 TileManagerBin bin, WhichTree tree) { 400 TileManagerBin bin, WhichTree tree) {
395 DCHECK(bin >= 0); 401 DCHECK(bin >= 0);
396 DCHECK(bin < NUM_BINS); 402 DCHECK(bin < NUM_BINS);
397 DCHECK(tree >= 0); 403 DCHECK(tree >= 0);
398 DCHECK(tree < NUM_TREES); 404 DCHECK(tree < NUM_TREES);
399 return drawable_tiles_in_bin_count_[bin][tree]; 405 return drawable_tiles_in_bin_count_[bin][tree];
400 } 406 }
401 407
408 void TileManager::GetManagedMemoryStats(
409 size_t* memoryVisibleBytes,
410 size_t* memoryVisibleAndNearbyBytes,
411 size_t* memoryAllocated) {
412 *memoryVisibleBytes = 0;
413 *memoryVisibleAndNearbyBytes = 0;
414 *memoryAllocated = 0;
415 for (TileVector::iterator it = tiles_.begin(); it != tiles_.end(); ++it) {
416 Tile* tile = *it;
417 ManagedTileState& mts = tile->managed_state();
418 size_t tile_bytes = tile->bytes_consumed_if_allocated();
419 if (mts.gpu_memmgr_stats_bin == NOW_BIN)
420 *memoryVisibleBytes += tile_bytes;
421 if (mts.gpu_memmgr_stats_bin != NEVER_BIN)
422 *memoryVisibleAndNearbyBytes += tile_bytes;
423 if (mts.can_use_gpu_memory)
424 *memoryAllocated += tile_bytes;
425 }
426 }
427
402 void TileManager::ResetBinCounts() { 428 void TileManager::ResetBinCounts() {
403 for (int i = 0; i < NUM_BINS; ++i) 429 for (int i = 0; i < NUM_BINS; ++i)
404 for (int j = 0; j < NUM_TREES; ++j) 430 for (int j = 0; j < NUM_TREES; ++j)
405 tiles_in_bin_count_[i][j] = drawable_tiles_in_bin_count_[i][j] = 0; 431 tiles_in_bin_count_[i][j] = drawable_tiles_in_bin_count_[i][j] = 0;
406 } 432 }
407 433
408 void TileManager::AssignGpuMemoryToTiles() { 434 void TileManager::AssignGpuMemoryToTiles() {
409 TRACE_EVENT0("cc", "TileManager::AssignGpuMemoryToTiles"); 435 TRACE_EVENT0("cc", "TileManager::AssignGpuMemoryToTiles");
410 // Some memory cannot be released. Figure out which. 436 // Some memory cannot be released. Figure out which.
411 size_t unreleasable_bytes = 0; 437 size_t unreleasable_bytes = 0;
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 void TileManager::DidFinishTileInitialization(Tile* tile) { 711 void TileManager::DidFinishTileInitialization(Tile* tile) {
686 ManagedTileState& managed_tile_state = tile->managed_state(); 712 ManagedTileState& managed_tile_state = tile->managed_state();
687 DCHECK(managed_tile_state.resource); 713 DCHECK(managed_tile_state.resource);
688 managed_tile_state.resource_is_being_initialized = false; 714 managed_tile_state.resource_is_being_initialized = false;
689 managed_tile_state.can_be_freed = true; 715 managed_tile_state.can_be_freed = true;
690 for (int i = 0; i < NUM_TREES; ++i) 716 for (int i = 0; i < NUM_TREES; ++i)
691 drawable_tiles_in_bin_count_[managed_tile_state.bin[i]][i]++; 717 drawable_tiles_in_bin_count_[managed_tile_state.bin[i]][i]++;
692 } 718 }
693 719
694 } 720 }
OLDNEW
« cc/managed_memory_policy.cc ('K') | « cc/tile_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698