| 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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 189 |
| 190 TileManager::~TileManager() { | 190 TileManager::~TileManager() { |
| 191 // Reset global state and manage. This should cause | 191 // Reset global state and manage. This should cause |
| 192 // our memory usage to drop to zero. | 192 // our memory usage to drop to zero. |
| 193 global_state_ = GlobalStateThatImpactsTilePriority(); | 193 global_state_ = GlobalStateThatImpactsTilePriority(); |
| 194 AssignGpuMemoryToTiles(); | 194 AssignGpuMemoryToTiles(); |
| 195 // This should finish all pending tasks and release any uninitialized | 195 // This should finish all pending tasks and release any uninitialized |
| 196 // resources. | 196 // resources. |
| 197 raster_worker_pool_.reset(); | 197 raster_worker_pool_.reset(); |
| 198 AbortPendingTileUploads(); | 198 AbortPendingTileUploads(); |
| 199 DCHECK(tiles_with_pending_set_pixels_.size() == 0); | 199 DCHECK_EQ(tiles_with_pending_set_pixels_.size(), 0); |
| 200 DCHECK(tiles_.size() == 0); | 200 DCHECK_EQ(all_tiles_.size(), 0); |
| 201 DCHECK_EQ(live_or_allocated_tiles_.size(), 0); |
| 201 } | 202 } |
| 202 | 203 |
| 203 void TileManager::SetGlobalState( | 204 void TileManager::SetGlobalState( |
| 204 const GlobalStateThatImpactsTilePriority& global_state) { | 205 const GlobalStateThatImpactsTilePriority& global_state) { |
| 205 global_state_ = global_state; | 206 global_state_ = global_state; |
| 206 resource_pool_->SetMaxMemoryUsageBytes(global_state_.memory_limit_in_bytes); | 207 resource_pool_->SetMaxMemoryUsageBytes(global_state_.memory_limit_in_bytes); |
| 207 ScheduleManageTiles(); | 208 ScheduleManageTiles(); |
| 208 } | 209 } |
| 209 | 210 |
| 210 void TileManager::RegisterTile(Tile* tile) { | 211 void TileManager::RegisterTile(Tile* tile) { |
| 211 tiles_.push_back(tile); | 212 all_tiles_.push_back(tile); |
| 212 | 213 |
| 213 const ManagedTileState& mts = tile->managed_state(); | 214 const ManagedTileState& mts = tile->managed_state(); |
| 214 for (int i = 0; i < NUM_TREES; ++i) | 215 for (int i = 0; i < NUM_TREES; ++i) |
| 215 ++raster_state_count_[mts.raster_state][i][mts.tree_bin[i]]; | 216 ++raster_state_count_[mts.raster_state][i][mts.tree_bin[i]]; |
| 216 | 217 |
| 217 ScheduleManageTiles(); | 218 ScheduleManageTiles(); |
| 218 } | 219 } |
| 219 | 220 |
| 220 void TileManager::UnregisterTile(Tile* tile) { | 221 void TileManager::UnregisterTile(Tile* tile) { |
| 221 for (TileList::iterator it = tiles_with_image_decoding_tasks_.begin(); | 222 for (TileList::iterator it = tiles_with_image_decoding_tasks_.begin(); |
| 222 it != tiles_with_image_decoding_tasks_.end(); it++) { | 223 it != tiles_with_image_decoding_tasks_.end(); it++) { |
| 223 if (*it == tile) { | 224 if (*it == tile) { |
| 224 tiles_with_image_decoding_tasks_.erase(it); | 225 tiles_with_image_decoding_tasks_.erase(it); |
| 225 break; | 226 break; |
| 226 } | 227 } |
| 227 } | 228 } |
| 228 for (TileVector::iterator it = tiles_that_need_to_be_rasterized_.begin(); | 229 for (TileVector::iterator it = tiles_that_need_to_be_rasterized_.begin(); |
| 229 it != tiles_that_need_to_be_rasterized_.end(); it++) { | 230 it != tiles_that_need_to_be_rasterized_.end(); it++) { |
| 230 if (*it == tile) { | 231 if (*it == tile) { |
| 231 tiles_that_need_to_be_rasterized_.erase(it); | 232 tiles_that_need_to_be_rasterized_.erase(it); |
| 232 break; | 233 break; |
| 233 } | 234 } |
| 234 } | 235 } |
| 235 for (TileVector::iterator it = tiles_.begin(); it != tiles_.end(); it++) { | 236 for (TileVector::iterator it = live_or_allocated_tiles_.begin(); |
| 237 it != live_or_allocated_tiles_.end(); it++) { |
| 238 if (*it == tile) { |
| 239 live_or_allocated_tiles_.erase(it); |
| 240 break; |
| 241 } |
| 242 } |
| 243 for (TileVector::iterator it = all_tiles_.begin(); |
| 244 it != all_tiles_.end(); it++) { |
| 236 if (*it == tile) { | 245 if (*it == tile) { |
| 237 const ManagedTileState& mts = tile->managed_state(); | 246 const ManagedTileState& mts = tile->managed_state(); |
| 238 for (int i = 0; i < NUM_TREES; ++i) | 247 for (int i = 0; i < NUM_TREES; ++i) |
| 239 --raster_state_count_[mts.raster_state][i][mts.tree_bin[i]]; | 248 --raster_state_count_[mts.raster_state][i][mts.tree_bin[i]]; |
| 240 FreeResourcesForTile(tile); | 249 FreeResourcesForTile(tile); |
| 241 tiles_.erase(it); | 250 all_tiles_.erase(it); |
| 242 return; | 251 return; |
| 243 } | 252 } |
| 244 } | 253 } |
| 245 DCHECK(false) << "Could not find tile version."; | 254 DCHECK(false) << "Could not find tile version."; |
| 246 } | 255 } |
| 247 | 256 |
| 248 class BinComparator { | 257 class BinComparator { |
| 249 public: | 258 public: |
| 250 bool operator() (const Tile* a, const Tile* b) const { | 259 bool operator() (const Tile* a, const Tile* b) const { |
| 251 const ManagedTileState& ams = a->managed_state(); | 260 const ManagedTileState& ams = a->managed_state(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 265 gfx::Rect a_rect = a->content_rect(); | 274 gfx::Rect a_rect = a->content_rect(); |
| 266 gfx::Rect b_rect = b->content_rect(); | 275 gfx::Rect b_rect = b->content_rect(); |
| 267 if (a_rect.y() != b_rect.y()) | 276 if (a_rect.y() != b_rect.y()) |
| 268 return a_rect.y() < b_rect.y(); | 277 return a_rect.y() < b_rect.y(); |
| 269 return a_rect.x() < b_rect.x(); | 278 return a_rect.x() < b_rect.x(); |
| 270 } | 279 } |
| 271 }; | 280 }; |
| 272 | 281 |
| 273 void TileManager::SortTiles() { | 282 void TileManager::SortTiles() { |
| 274 TRACE_EVENT0("cc", "TileManager::SortTiles"); | 283 TRACE_EVENT0("cc", "TileManager::SortTiles"); |
| 275 | 284 TRACE_COUNTER_ID1("cc", "LiveTileCount", this, live_or_allocated_tiles_.size()
); |
| 276 if (tiles_.size() == 0) { | |
| 277 TRACE_COUNTER_ID1("cc", "LiveTileCount", this, 0); | |
| 278 return; | |
| 279 } | |
| 280 | |
| 281 TileVector::iterator i = tiles_.begin(); | |
| 282 TileVector::iterator j = tiles_.end() - 1; | |
| 283 | |
| 284 // Sift the live tiles to the front of the list. | |
| 285 while (i != j) { | |
| 286 while (i != j && ( | |
| 287 !(*j)->priority( ACTIVE_TREE).is_live && | |
| 288 !(*j)->priority(PENDING_TREE).is_live)) | |
| 289 j--; | |
| 290 | |
| 291 // j now points to i or a live tile. | |
| 292 while (i != j && ( | |
| 293 (*i)->priority( ACTIVE_TREE).is_live || | |
| 294 (*i)->priority(PENDING_TREE).is_live)) | |
| 295 i++; | |
| 296 // i now points to j or a non-live tile. | |
| 297 if (i == j) | |
| 298 break; | |
| 299 | |
| 300 // If i does not equal j then we'll swap them. | |
| 301 Tile* temp = *i; | |
| 302 *i = *j; | |
| 303 *j = temp; | |
| 304 } | |
| 305 | |
| 306 TRACE_COUNTER_ID1("cc", "LiveTileCount", this, i + 1 - tiles_.begin()); | |
| 307 | 285 |
| 308 // Sort by bin, resolution and time until needed. | 286 // Sort by bin, resolution and time until needed. |
| 309 std::sort(tiles_.begin(), i + 1, BinComparator()); | 287 std::sort(live_or_allocated_tiles_.begin(), |
| 288 live_or_allocated_tiles_.end(), BinComparator()); |
| 310 } | 289 } |
| 311 | 290 |
| 312 void TileManager::ManageTiles() { | 291 void TileManager::ManageTiles() { |
| 313 TRACE_EVENT0("cc", "TileManager::ManageTiles"); | 292 TRACE_EVENT0("cc", "TileManager::ManageTiles"); |
| 314 manage_tiles_pending_ = false; | 293 manage_tiles_pending_ = false; |
| 315 ++manage_tiles_call_count_; | 294 ++manage_tiles_call_count_; |
| 316 | 295 |
| 317 const TreePriority tree_priority = global_state_.tree_priority; | 296 const TreePriority tree_priority = global_state_.tree_priority; |
| 318 TRACE_COUNTER_ID1("cc", "TileCount", this, tiles_.size()); | 297 TRACE_COUNTER_ID1("cc", "TileCount", this, all_tiles_.size()); |
| 319 | 298 |
| 299 // Memory limit policy works by mapping some bin states to the NEVER bin. |
| 300 TileManagerBin bin_map[NUM_BINS]; |
| 301 if (global_state_.memory_limit_policy == ALLOW_NOTHING) { |
| 302 bin_map[NOW_BIN] = NEVER_BIN; |
| 303 bin_map[SOON_BIN] = NEVER_BIN; |
| 304 bin_map[EVENTUALLY_BIN] = NEVER_BIN; |
| 305 bin_map[NEVER_BIN] = NEVER_BIN; |
| 306 } else if (global_state_.memory_limit_policy == ALLOW_ABSOLUTE_MINIMUM) { |
| 307 bin_map[NOW_BIN] = NOW_BIN; |
| 308 bin_map[SOON_BIN] = NEVER_BIN; |
| 309 bin_map[EVENTUALLY_BIN] = NEVER_BIN; |
| 310 bin_map[NEVER_BIN] = NEVER_BIN; |
| 311 } else if (global_state_.memory_limit_policy == ALLOW_PREPAINT_ONLY) { |
| 312 bin_map[NOW_BIN] = NOW_BIN; |
| 313 bin_map[SOON_BIN] = SOON_BIN; |
| 314 bin_map[EVENTUALLY_BIN] = NEVER_BIN; |
| 315 bin_map[NEVER_BIN] = NEVER_BIN; |
| 316 } else { |
| 317 bin_map[NOW_BIN] = NOW_BIN; |
| 318 bin_map[SOON_BIN] = SOON_BIN; |
| 319 bin_map[EVENTUALLY_BIN] = EVENTUALLY_BIN; |
| 320 bin_map[NEVER_BIN] = NEVER_BIN; |
| 321 } |
| 322 |
| 323 live_or_allocated_tiles_.clear(); |
| 320 // For each tree, bin into different categories of tiles. | 324 // For each tree, bin into different categories of tiles. |
| 321 for (TileVector::iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | 325 for (TileVector::iterator it = all_tiles_.begin(); |
| 326 it != all_tiles_.end(); ++it) { |
| 322 Tile* tile = *it; | 327 Tile* tile = *it; |
| 323 ManagedTileState& mts = tile->managed_state(); | 328 ManagedTileState& mts = tile->managed_state(); |
| 324 | 329 |
| 325 TilePriority prio[NUM_BIN_PRIORITIES]; | 330 TilePriority prio[NUM_BIN_PRIORITIES]; |
| 326 switch (tree_priority) { | 331 switch (tree_priority) { |
| 327 case SAME_PRIORITY_FOR_BOTH_TREES: | 332 case SAME_PRIORITY_FOR_BOTH_TREES: |
| 328 prio[HIGH_PRIORITY_BIN] = prio[LOW_PRIORITY_BIN] = | 333 prio[HIGH_PRIORITY_BIN] = prio[LOW_PRIORITY_BIN] = |
| 329 tile->combined_priority(); | 334 tile->combined_priority(); |
| 330 break; | 335 break; |
| 331 case SMOOTHNESS_TAKES_PRIORITY: | 336 case SMOOTHNESS_TAKES_PRIORITY: |
| 332 prio[HIGH_PRIORITY_BIN] = tile->priority(ACTIVE_TREE); | 337 prio[HIGH_PRIORITY_BIN] = tile->priority(ACTIVE_TREE); |
| 333 prio[LOW_PRIORITY_BIN] = tile->priority(PENDING_TREE); | 338 prio[LOW_PRIORITY_BIN] = tile->priority(PENDING_TREE); |
| 334 break; | 339 break; |
| 335 case NEW_CONTENT_TAKES_PRIORITY: | 340 case NEW_CONTENT_TAKES_PRIORITY: |
| 336 prio[HIGH_PRIORITY_BIN] = tile->priority(PENDING_TREE); | 341 prio[HIGH_PRIORITY_BIN] = tile->priority(PENDING_TREE); |
| 337 prio[LOW_PRIORITY_BIN] = tile->priority(ACTIVE_TREE); | 342 prio[LOW_PRIORITY_BIN] = tile->priority(ACTIVE_TREE); |
| 338 break; | 343 break; |
| 339 } | 344 } |
| 340 | 345 |
| 341 mts.resolution = prio[HIGH_PRIORITY_BIN].resolution; | 346 mts.resolution = prio[HIGH_PRIORITY_BIN].resolution; |
| 342 mts.time_to_needed_in_seconds = | 347 mts.time_to_needed_in_seconds = |
| 343 prio[HIGH_PRIORITY_BIN].time_to_visible_in_seconds; | 348 prio[HIGH_PRIORITY_BIN].time_to_visible_in_seconds; |
| 344 mts.bin[HIGH_PRIORITY_BIN] = BinFromTilePriority(prio[HIGH_PRIORITY_BIN]); | 349 mts.bin[HIGH_PRIORITY_BIN] = BinFromTilePriority(prio[HIGH_PRIORITY_BIN]); |
| 345 mts.bin[LOW_PRIORITY_BIN] = BinFromTilePriority(prio[LOW_PRIORITY_BIN]); | 350 mts.bin[LOW_PRIORITY_BIN] = BinFromTilePriority(prio[LOW_PRIORITY_BIN]); |
| 346 mts.gpu_memmgr_stats_bin = BinFromTilePriority(tile->combined_priority()); | 351 mts.gpu_memmgr_stats_bin = BinFromTilePriority(tile->combined_priority()); |
| 347 | 352 |
| 348 DidTileBinChange(tile, | 353 DidTileTreeBinChange(tile, |
| 349 BinFromTilePriority(tile->priority(ACTIVE_TREE)), | 354 BinFromTilePriority(tile->priority(ACTIVE_TREE)), |
| 350 ACTIVE_TREE); | 355 ACTIVE_TREE); |
| 351 DidTileBinChange(tile, | 356 DidTileTreeBinChange(tile, |
| 352 BinFromTilePriority(tile->priority(PENDING_TREE)), | 357 BinFromTilePriority(tile->priority(PENDING_TREE)), |
| 353 PENDING_TREE); | 358 PENDING_TREE); |
| 354 } | |
| 355 | 359 |
| 356 // Memory limit policy works by mapping some bin states to the NEVER bin. | |
| 357 TileManagerBin bin_map[NUM_BINS]; | |
| 358 if (global_state_.memory_limit_policy == ALLOW_NOTHING) { | |
| 359 bin_map[NOW_BIN] = NEVER_BIN; | |
| 360 bin_map[SOON_BIN] = NEVER_BIN; | |
| 361 bin_map[EVENTUALLY_BIN] = NEVER_BIN; | |
| 362 bin_map[NEVER_BIN] = NEVER_BIN; | |
| 363 } else if (global_state_.memory_limit_policy == ALLOW_ABSOLUTE_MINIMUM) { | |
| 364 bin_map[NOW_BIN] = NOW_BIN; | |
| 365 bin_map[SOON_BIN] = NEVER_BIN; | |
| 366 bin_map[EVENTUALLY_BIN] = NEVER_BIN; | |
| 367 bin_map[NEVER_BIN] = NEVER_BIN; | |
| 368 } else if (global_state_.memory_limit_policy == ALLOW_PREPAINT_ONLY) { | |
| 369 bin_map[NOW_BIN] = NOW_BIN; | |
| 370 bin_map[SOON_BIN] = SOON_BIN; | |
| 371 bin_map[EVENTUALLY_BIN] = NEVER_BIN; | |
| 372 bin_map[NEVER_BIN] = NEVER_BIN; | |
| 373 } else { | |
| 374 bin_map[NOW_BIN] = NOW_BIN; | |
| 375 bin_map[SOON_BIN] = SOON_BIN; | |
| 376 bin_map[EVENTUALLY_BIN] = EVENTUALLY_BIN; | |
| 377 bin_map[NEVER_BIN] = NEVER_BIN; | |
| 378 } | |
| 379 for (TileVector::iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | |
| 380 Tile* tile = *it; | |
| 381 ManagedTileState& mts = tile->managed_state(); | |
| 382 for (int i = 0; i < NUM_BIN_PRIORITIES; ++i) | 360 for (int i = 0; i < NUM_BIN_PRIORITIES; ++i) |
| 383 mts.bin[i] = bin_map[mts.bin[i]]; | 361 mts.bin[i] = bin_map[mts.bin[i]]; |
| 384 | 362 |
| 385 DidTileBinChange(tile, bin_map[mts.tree_bin[ACTIVE_TREE]], ACTIVE_TREE); | 363 DidTileTreeBinChange(tile, bin_map[mts.tree_bin[ACTIVE_TREE]], |
| 386 DidTileBinChange(tile, bin_map[mts.tree_bin[PENDING_TREE]], PENDING_TREE); | 364 ACTIVE_TREE); |
| 365 DidTileTreeBinChange(tile, bin_map[mts.tree_bin[PENDING_TREE]], |
| 366 PENDING_TREE); |
| 367 |
| 368 if (tile->priority(ACTIVE_TREE).is_live || |
| 369 tile->priority(PENDING_TREE).is_live || |
| 370 tile->managed_state().resource || |
| 371 tile->managed_state().resource_is_being_initialized) { |
| 372 live_or_allocated_tiles_.push_back(tile); |
| 373 } |
| 387 } | 374 } |
| 375 TRACE_COUNTER_ID1("cc", "LiveOrAllocatedTileCount", this, |
| 376 live_or_allocated_tiles_.size()); |
| 388 | 377 |
| 389 SortTiles(); | 378 SortTiles(); |
| 390 | 379 |
| 391 // Assign gpu memory and determine what tiles need to be rasterized. | 380 // Assign gpu memory and determine what tiles need to be rasterized. |
| 392 AssignGpuMemoryToTiles(); | 381 AssignGpuMemoryToTiles(); |
| 393 | 382 |
| 394 TRACE_EVENT_INSTANT1("cc", "DidManage", "state", | 383 TRACE_EVENT_INSTANT1("cc", "DidManage", "state", |
| 395 ValueToString(BasicStateAsValue())); | 384 ValueToString(BasicStateAsValue())); |
| 396 | 385 |
| 397 // Finally, kick the rasterizer. | 386 // Finally, kick the rasterizer. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 } | 438 } |
| 450 } | 439 } |
| 451 | 440 |
| 452 void TileManager::GetMemoryStats( | 441 void TileManager::GetMemoryStats( |
| 453 size_t* memoryRequiredBytes, | 442 size_t* memoryRequiredBytes, |
| 454 size_t* memoryNiceToHaveBytes, | 443 size_t* memoryNiceToHaveBytes, |
| 455 size_t* memoryUsedBytes) const { | 444 size_t* memoryUsedBytes) const { |
| 456 *memoryRequiredBytes = 0; | 445 *memoryRequiredBytes = 0; |
| 457 *memoryNiceToHaveBytes = 0; | 446 *memoryNiceToHaveBytes = 0; |
| 458 *memoryUsedBytes = 0; | 447 *memoryUsedBytes = 0; |
| 459 for(size_t i = 0; i < tiles_.size(); i++) { | 448 for (size_t i = 0; i < live_or_allocated_tiles_.size(); i++) { |
| 460 const Tile* tile = tiles_[i]; | 449 const Tile* tile = live_or_allocated_tiles_[i]; |
| 461 const ManagedTileState& mts = tile->managed_state(); | 450 const ManagedTileState& mts = tile->managed_state(); |
| 462 size_t tile_bytes = tile->bytes_consumed_if_allocated(); | 451 size_t tile_bytes = tile->bytes_consumed_if_allocated(); |
| 463 if (mts.gpu_memmgr_stats_bin == NOW_BIN) | 452 if (mts.gpu_memmgr_stats_bin == NOW_BIN) |
| 464 *memoryRequiredBytes += tile_bytes; | 453 *memoryRequiredBytes += tile_bytes; |
| 465 if (mts.gpu_memmgr_stats_bin != NEVER_BIN) | 454 if (mts.gpu_memmgr_stats_bin != NEVER_BIN) |
| 466 *memoryNiceToHaveBytes += tile_bytes; | 455 *memoryNiceToHaveBytes += tile_bytes; |
| 467 if (mts.can_use_gpu_memory) | 456 if (mts.can_use_gpu_memory) |
| 468 *memoryUsedBytes += tile_bytes; | 457 *memoryUsedBytes += tile_bytes; |
| 469 } | 458 } |
| 470 } | 459 } |
| 471 | 460 |
| 472 scoped_ptr<base::Value> TileManager::BasicStateAsValue() const { | 461 scoped_ptr<base::Value> TileManager::BasicStateAsValue() const { |
| 473 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 462 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
| 474 state->SetInteger("tile_count", tiles_.size()); | 463 state->SetInteger("tile_count", all_tiles_.size()); |
| 475 | 464 |
| 476 state->Set("global_state", global_state_.AsValue().release()); | 465 state->Set("global_state", global_state_.AsValue().release()); |
| 477 | 466 |
| 478 state->Set("memory_requirements", GetMemoryRequirementsAsValue().release()); | 467 state->Set("memory_requirements", GetMemoryRequirementsAsValue().release()); |
| 479 return state.PassAs<base::Value>(); | 468 return state.PassAs<base::Value>(); |
| 480 } | 469 } |
| 481 scoped_ptr<base::Value> TileManager::AllTilesAsValue() const { | 470 scoped_ptr<base::Value> TileManager::AllTilesAsValue() const { |
| 482 scoped_ptr<base::ListValue> state(new base::ListValue()); | 471 scoped_ptr<base::ListValue> state(new base::ListValue()); |
| 483 for (size_t i = 0; i < tiles_.size(); i++) | 472 for (size_t i = 0; i < all_tiles_.size(); i++) |
| 484 state->Append(tiles_[i]->AsValue().release()); | 473 state->Append(all_tiles_[i]->AsValue().release()); |
| 485 return state.PassAs<base::Value>(); | 474 return state.PassAs<base::Value>(); |
| 486 } | 475 } |
| 487 | 476 |
| 488 scoped_ptr<base::Value> TileManager::GetMemoryRequirementsAsValue() const { | 477 scoped_ptr<base::Value> TileManager::GetMemoryRequirementsAsValue() const { |
| 489 scoped_ptr<base::DictionaryValue> requirements( | 478 scoped_ptr<base::DictionaryValue> requirements( |
| 490 new base::DictionaryValue()); | 479 new base::DictionaryValue()); |
| 491 | 480 |
| 492 size_t memoryRequiredBytes; | 481 size_t memoryRequiredBytes; |
| 493 size_t memoryNiceToHaveBytes; | 482 size_t memoryNiceToHaveBytes; |
| 494 size_t memoryUsedBytes; | 483 size_t memoryUsedBytes; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 default: | 528 default: |
| 540 NOTREACHED(); | 529 NOTREACHED(); |
| 541 } | 530 } |
| 542 } | 531 } |
| 543 | 532 |
| 544 return false; | 533 return false; |
| 545 } | 534 } |
| 546 | 535 |
| 547 void TileManager::AssignGpuMemoryToTiles() { | 536 void TileManager::AssignGpuMemoryToTiles() { |
| 548 TRACE_EVENT0("cc", "TileManager::AssignGpuMemoryToTiles"); | 537 TRACE_EVENT0("cc", "TileManager::AssignGpuMemoryToTiles"); |
| 549 // Some memory cannot be released. Figure out which. | |
| 550 size_t unreleasable_bytes = 0; | 538 size_t unreleasable_bytes = 0; |
| 551 for (TileVector::iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | |
| 552 Tile* tile = *it; | |
| 553 if (!tile->managed_state().can_be_freed) | |
| 554 unreleasable_bytes += tile->bytes_consumed_if_allocated(); | |
| 555 } | |
| 556 | 539 |
| 557 // Now give memory out to the tiles until we're out, and build | 540 // Now give memory out to the tiles until we're out, and build |
| 558 // the needs-to-be-rasterized queue. | 541 // the needs-to-be-rasterized queue. |
| 559 tiles_that_need_to_be_rasterized_.erase( | 542 tiles_that_need_to_be_rasterized_.clear(); |
| 560 tiles_that_need_to_be_rasterized_.begin(), | |
| 561 tiles_that_need_to_be_rasterized_.end()); | |
| 562 | 543 |
| 563 // Reset the image decoding list so that we don't mess up with tile | 544 // Reset the image decoding list so that we don't mess up with tile |
| 564 // priorities. Tiles will be added to the image decoding list again | 545 // priorities. Tiles will be added to the image decoding list again |
| 565 // when DispatchMoreTasks() is called. | 546 // when DispatchMoreTasks() is called. |
| 566 tiles_with_image_decoding_tasks_.clear(); | 547 tiles_with_image_decoding_tasks_.clear(); |
| 567 | 548 |
| 568 // By clearing the tiles_that_need_to_be_rasterized_ vector and | 549 // By clearing the tiles_that_need_to_be_rasterized_ vector and |
| 569 // tiles_with_image_decoding_tasks_ list above we move all tiles | 550 // tiles_with_image_decoding_tasks_ list above we move all tiles |
| 570 // currently waiting for raster to idle state. | 551 // currently waiting for raster to idle state. |
| 571 // Call DidTileRasterStateChange() for each of these tiles to | 552 // Call DidTileRasterStateChange() for each of these tiles to |
| 572 // have this state change take effect. | 553 // have this state change take effect. |
| 573 for (TileVector::iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | 554 // Some memory cannot be released. We figure out how much in this |
| 555 // loop as well. |
| 556 for (TileVector::iterator it = live_or_allocated_tiles_.begin(); |
| 557 it != live_or_allocated_tiles_.end(); ++it) { |
| 574 Tile* tile = *it; | 558 Tile* tile = *it; |
| 559 if (!tile->managed_state().can_be_freed) |
| 560 unreleasable_bytes += tile->bytes_consumed_if_allocated(); |
| 575 if (tile->managed_state().raster_state == WAITING_FOR_RASTER_STATE) | 561 if (tile->managed_state().raster_state == WAITING_FOR_RASTER_STATE) |
| 576 DidTileRasterStateChange(tile, IDLE_STATE); | 562 DidTileRasterStateChange(tile, IDLE_STATE); |
| 577 } | 563 } |
| 578 | 564 |
| 579 size_t bytes_allocatable = global_state_.memory_limit_in_bytes - unreleasable_
bytes; | 565 size_t bytes_allocatable = global_state_.memory_limit_in_bytes - unreleasable_
bytes; |
| 580 size_t bytes_that_exceeded_memory_budget = 0; | 566 size_t bytes_that_exceeded_memory_budget = 0; |
| 581 size_t bytes_left = bytes_allocatable; | 567 size_t bytes_left = bytes_allocatable; |
| 582 for (TileVector::iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | 568 for (TileVector::iterator it = live_or_allocated_tiles_.begin(); |
| 569 it != live_or_allocated_tiles_.end(); ++it) { |
| 583 Tile* tile = *it; | 570 Tile* tile = *it; |
| 584 size_t tile_bytes = tile->bytes_consumed_if_allocated(); | 571 size_t tile_bytes = tile->bytes_consumed_if_allocated(); |
| 585 ManagedTileState& managed_tile_state = tile->managed_state(); | 572 ManagedTileState& managed_tile_state = tile->managed_state(); |
| 586 if (!managed_tile_state.can_be_freed) | 573 if (!managed_tile_state.can_be_freed) |
| 587 continue; | 574 continue; |
| 588 if (managed_tile_state.bin[HIGH_PRIORITY_BIN] == NEVER_BIN && | 575 if (managed_tile_state.bin[HIGH_PRIORITY_BIN] == NEVER_BIN && |
| 589 managed_tile_state.bin[LOW_PRIORITY_BIN] == NEVER_BIN) { | 576 managed_tile_state.bin[LOW_PRIORITY_BIN] == NEVER_BIN) { |
| 590 managed_tile_state.can_use_gpu_memory = false; | 577 managed_tile_state.can_use_gpu_memory = false; |
| 591 FreeResourcesForTile(tile); | 578 FreeResourcesForTile(tile); |
| 592 continue; | 579 continue; |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 880 --raster_state_count_[mts.raster_state][i][mts.tree_bin[i]]; | 867 --raster_state_count_[mts.raster_state][i][mts.tree_bin[i]]; |
| 881 DCHECK_GE(raster_state_count_[mts.raster_state][i][mts.tree_bin[i]], 0); | 868 DCHECK_GE(raster_state_count_[mts.raster_state][i][mts.tree_bin[i]], 0); |
| 882 | 869 |
| 883 // Increment count for new state. | 870 // Increment count for new state. |
| 884 ++raster_state_count_[state][i][mts.tree_bin[i]]; | 871 ++raster_state_count_[state][i][mts.tree_bin[i]]; |
| 885 } | 872 } |
| 886 | 873 |
| 887 mts.raster_state = state; | 874 mts.raster_state = state; |
| 888 } | 875 } |
| 889 | 876 |
| 890 void TileManager::DidTileBinChange(Tile* tile, | 877 void TileManager::DidTileTreeBinChange(Tile* tile, |
| 891 TileManagerBin bin, | 878 TileManagerBin new_tree_bin, |
| 892 WhichTree tree) { | 879 WhichTree tree) { |
| 893 ManagedTileState& mts = tile->managed_state(); | 880 ManagedTileState& mts = tile->managed_state(); |
| 894 | 881 |
| 895 // Decrement count for current bin. | 882 // Decrement count for current bin. |
| 896 --raster_state_count_[mts.raster_state][tree][mts.tree_bin[tree]]; | 883 --raster_state_count_[mts.raster_state][tree][mts.tree_bin[tree]]; |
| 897 DCHECK_GE(raster_state_count_[mts.raster_state][tree][mts.tree_bin[tree]], 0); | 884 DCHECK_GE(raster_state_count_[mts.raster_state][tree][mts.tree_bin[tree]], 0); |
| 898 | 885 |
| 899 // Increment count for new bin. | 886 // Increment count for new bin. |
| 900 ++raster_state_count_[mts.raster_state][tree][bin]; | 887 ++raster_state_count_[mts.raster_state][tree][new_tree_bin]; |
| 901 | 888 |
| 902 mts.tree_bin[tree] = bin; | 889 mts.tree_bin[tree] = new_tree_bin; |
| 903 } | 890 } |
| 904 | 891 |
| 905 // static | 892 // static |
| 906 void TileManager::PerformRaster(uint8* buffer, | 893 void TileManager::PerformRaster(uint8* buffer, |
| 907 const gfx::Rect& rect, | 894 const gfx::Rect& rect, |
| 908 float contents_scale, | 895 float contents_scale, |
| 909 bool use_cheapness_estimator, | 896 bool use_cheapness_estimator, |
| 910 PicturePileImpl* picture_pile, | 897 PicturePileImpl* picture_pile, |
| 911 RenderingStats* stats) { | 898 RenderingStats* stats) { |
| 912 TRACE_EVENT0("cc", "TileManager::PerformRaster"); | 899 TRACE_EVENT0("cc", "TileManager::PerformRaster"); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 967 decode_begin_time = base::TimeTicks::Now(); | 954 decode_begin_time = base::TimeTicks::Now(); |
| 968 pixel_ref->Decode(); | 955 pixel_ref->Decode(); |
| 969 if (stats) { | 956 if (stats) { |
| 970 stats->totalDeferredImageDecodeCount++; | 957 stats->totalDeferredImageDecodeCount++; |
| 971 stats->totalDeferredImageDecodeTime += | 958 stats->totalDeferredImageDecodeTime += |
| 972 base::TimeTicks::Now() - decode_begin_time; | 959 base::TimeTicks::Now() - decode_begin_time; |
| 973 } | 960 } |
| 974 } | 961 } |
| 975 | 962 |
| 976 } // namespace cc | 963 } // namespace cc |
| OLD | NEW |