| 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/tile_manager.h" | 5 #include "cc/tile_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 } | 202 } |
| 203 | 203 |
| 204 void TileManager::SetGlobalState( | 204 void TileManager::SetGlobalState( |
| 205 const GlobalStateThatImpactsTilePriority& global_state) { | 205 const GlobalStateThatImpactsTilePriority& global_state) { |
| 206 global_state_ = global_state; | 206 global_state_ = global_state; |
| 207 resource_pool_->SetMaxMemoryUsageBytes(global_state_.memory_limit_in_bytes); | 207 resource_pool_->SetMaxMemoryUsageBytes(global_state_.memory_limit_in_bytes); |
| 208 ScheduleManageTiles(); | 208 ScheduleManageTiles(); |
| 209 } | 209 } |
| 210 | 210 |
| 211 void TileManager::RegisterTile(Tile* tile) { | 211 void TileManager::RegisterTile(Tile* tile) { |
| 212 all_tiles_.push_back(tile); | 212 all_tiles_.insert(tile); |
| 213 | 213 |
| 214 const ManagedTileState& mts = tile->managed_state(); | 214 const ManagedTileState& mts = tile->managed_state(); |
| 215 for (int i = 0; i < NUM_TREES; ++i) | 215 for (int i = 0; i < NUM_TREES; ++i) |
| 216 ++raster_state_count_[mts.raster_state][i][mts.tree_bin[i]]; | 216 ++raster_state_count_[mts.raster_state][i][mts.tree_bin[i]]; |
| 217 | 217 |
| 218 ScheduleManageTiles(); | 218 ScheduleManageTiles(); |
| 219 } | 219 } |
| 220 | 220 |
| 221 void TileManager::UnregisterTile(Tile* tile) { | 221 void TileManager::UnregisterTile(Tile* tile) { |
| 222 for (TileList::iterator it = tiles_with_image_decoding_tasks_.begin(); | 222 for (TileList::iterator it = tiles_with_image_decoding_tasks_.begin(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 233 break; | 233 break; |
| 234 } | 234 } |
| 235 } | 235 } |
| 236 for (TileVector::iterator it = live_or_allocated_tiles_.begin(); | 236 for (TileVector::iterator it = live_or_allocated_tiles_.begin(); |
| 237 it != live_or_allocated_tiles_.end(); it++) { | 237 it != live_or_allocated_tiles_.end(); it++) { |
| 238 if (*it == tile) { | 238 if (*it == tile) { |
| 239 live_or_allocated_tiles_.erase(it); | 239 live_or_allocated_tiles_.erase(it); |
| 240 break; | 240 break; |
| 241 } | 241 } |
| 242 } | 242 } |
| 243 for (TileVector::iterator it = all_tiles_.begin(); | 243 TileSet::iterator it = all_tiles_.find(tile); |
| 244 it != all_tiles_.end(); it++) { | 244 DCHECK(it != all_tiles_.end()); |
| 245 if (*it == tile) { | 245 const ManagedTileState& mts = tile->managed_state(); |
| 246 const ManagedTileState& mts = tile->managed_state(); | 246 for (int i = 0; i < NUM_TREES; ++i) |
| 247 for (int i = 0; i < NUM_TREES; ++i) | 247 --raster_state_count_[mts.raster_state][i][mts.tree_bin[i]]; |
| 248 --raster_state_count_[mts.raster_state][i][mts.tree_bin[i]]; | 248 FreeResourcesForTile(tile); |
| 249 FreeResourcesForTile(tile); | 249 all_tiles_.erase(it); |
| 250 all_tiles_.erase(it); | |
| 251 return; | |
| 252 } | |
| 253 } | |
| 254 DCHECK(false) << "Could not find tile version."; | |
| 255 } | 250 } |
| 256 | 251 |
| 257 class BinComparator { | 252 class BinComparator { |
| 258 public: | 253 public: |
| 259 bool operator() (const Tile* a, const Tile* b) const { | 254 bool operator() (const Tile* a, const Tile* b) const { |
| 260 const ManagedTileState& ams = a->managed_state(); | 255 const ManagedTileState& ams = a->managed_state(); |
| 261 const ManagedTileState& bms = b->managed_state(); | 256 const ManagedTileState& bms = b->managed_state(); |
| 262 if (ams.bin[HIGH_PRIORITY_BIN] != bms.bin[HIGH_PRIORITY_BIN]) | 257 if (ams.bin[HIGH_PRIORITY_BIN] != bms.bin[HIGH_PRIORITY_BIN]) |
| 263 return ams.bin[HIGH_PRIORITY_BIN] < bms.bin[HIGH_PRIORITY_BIN]; | 258 return ams.bin[HIGH_PRIORITY_BIN] < bms.bin[HIGH_PRIORITY_BIN]; |
| 264 | 259 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 bin_map[NEVER_BIN] = NEVER_BIN; | 310 bin_map[NEVER_BIN] = NEVER_BIN; |
| 316 } else { | 311 } else { |
| 317 bin_map[NOW_BIN] = NOW_BIN; | 312 bin_map[NOW_BIN] = NOW_BIN; |
| 318 bin_map[SOON_BIN] = SOON_BIN; | 313 bin_map[SOON_BIN] = SOON_BIN; |
| 319 bin_map[EVENTUALLY_BIN] = EVENTUALLY_BIN; | 314 bin_map[EVENTUALLY_BIN] = EVENTUALLY_BIN; |
| 320 bin_map[NEVER_BIN] = NEVER_BIN; | 315 bin_map[NEVER_BIN] = NEVER_BIN; |
| 321 } | 316 } |
| 322 | 317 |
| 323 live_or_allocated_tiles_.clear(); | 318 live_or_allocated_tiles_.clear(); |
| 324 // For each tree, bin into different categories of tiles. | 319 // For each tree, bin into different categories of tiles. |
| 325 for (TileVector::iterator it = all_tiles_.begin(); | 320 for (TileSet::iterator it = all_tiles_.begin(); |
| 326 it != all_tiles_.end(); ++it) { | 321 it != all_tiles_.end(); ++it) { |
| 327 Tile* tile = *it; | 322 Tile* tile = *it; |
| 328 ManagedTileState& mts = tile->managed_state(); | 323 ManagedTileState& mts = tile->managed_state(); |
| 329 | 324 |
| 330 TilePriority prio[NUM_BIN_PRIORITIES]; | 325 TilePriority prio[NUM_BIN_PRIORITIES]; |
| 331 switch (tree_priority) { | 326 switch (tree_priority) { |
| 332 case SAME_PRIORITY_FOR_BOTH_TREES: | 327 case SAME_PRIORITY_FOR_BOTH_TREES: |
| 333 prio[HIGH_PRIORITY_BIN] = prio[LOW_PRIORITY_BIN] = | 328 prio[HIGH_PRIORITY_BIN] = prio[LOW_PRIORITY_BIN] = |
| 334 tile->combined_priority(); | 329 tile->combined_priority(); |
| 335 break; | 330 break; |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 457 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
| 463 state->SetInteger("tile_count", all_tiles_.size()); | 458 state->SetInteger("tile_count", all_tiles_.size()); |
| 464 | 459 |
| 465 state->Set("global_state", global_state_.AsValue().release()); | 460 state->Set("global_state", global_state_.AsValue().release()); |
| 466 | 461 |
| 467 state->Set("memory_requirements", GetMemoryRequirementsAsValue().release()); | 462 state->Set("memory_requirements", GetMemoryRequirementsAsValue().release()); |
| 468 return state.PassAs<base::Value>(); | 463 return state.PassAs<base::Value>(); |
| 469 } | 464 } |
| 470 scoped_ptr<base::Value> TileManager::AllTilesAsValue() const { | 465 scoped_ptr<base::Value> TileManager::AllTilesAsValue() const { |
| 471 scoped_ptr<base::ListValue> state(new base::ListValue()); | 466 scoped_ptr<base::ListValue> state(new base::ListValue()); |
| 472 for (size_t i = 0; i < all_tiles_.size(); i++) | 467 for (TileSet::const_iterator it = all_tiles_.begin(); |
| 473 state->Append(all_tiles_[i]->AsValue().release()); | 468 it != all_tiles_.end(); it++) { |
| 469 state->Append((*it)->AsValue().release()); |
| 470 } |
| 474 return state.PassAs<base::Value>(); | 471 return state.PassAs<base::Value>(); |
| 475 } | 472 } |
| 476 | 473 |
| 477 scoped_ptr<base::Value> TileManager::GetMemoryRequirementsAsValue() const { | 474 scoped_ptr<base::Value> TileManager::GetMemoryRequirementsAsValue() const { |
| 478 scoped_ptr<base::DictionaryValue> requirements( | 475 scoped_ptr<base::DictionaryValue> requirements( |
| 479 new base::DictionaryValue()); | 476 new base::DictionaryValue()); |
| 480 | 477 |
| 481 size_t memoryRequiredBytes; | 478 size_t memoryRequiredBytes; |
| 482 size_t memoryNiceToHaveBytes; | 479 size_t memoryNiceToHaveBytes; |
| 483 size_t memoryUsedBytes; | 480 size_t memoryUsedBytes; |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 decode_begin_time = base::TimeTicks::Now(); | 951 decode_begin_time = base::TimeTicks::Now(); |
| 955 pixel_ref->Decode(); | 952 pixel_ref->Decode(); |
| 956 if (stats) { | 953 if (stats) { |
| 957 stats->totalDeferredImageDecodeCount++; | 954 stats->totalDeferredImageDecodeCount++; |
| 958 stats->totalDeferredImageDecodeTime += | 955 stats->totalDeferredImageDecodeTime += |
| 959 base::TimeTicks::Now() - decode_begin_time; | 956 base::TimeTicks::Now() - decode_begin_time; |
| 960 } | 957 } |
| 961 } | 958 } |
| 962 | 959 |
| 963 } // namespace cc | 960 } // namespace cc |
| OLD | NEW |