| 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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 skia::RefPtr<SkPixelRef> pixel_ref_; | 221 skia::RefPtr<SkPixelRef> pixel_ref_; |
| 222 int layer_id_; | 222 int layer_id_; |
| 223 RenderingStatsInstrumentation* rendering_stats_; | 223 RenderingStatsInstrumentation* rendering_stats_; |
| 224 const base::Callback<void(bool was_canceled)> reply_; | 224 const base::Callback<void(bool was_canceled)> reply_; |
| 225 | 225 |
| 226 DISALLOW_COPY_AND_ASSIGN(ImageDecodeTaskImpl); | 226 DISALLOW_COPY_AND_ASSIGN(ImageDecodeTaskImpl); |
| 227 }; | 227 }; |
| 228 | 228 |
| 229 const size_t kScheduledRasterTasksLimit = 32u; | 229 const size_t kScheduledRasterTasksLimit = 32u; |
| 230 | 230 |
| 231 // Memory limit policy works by mapping some bin states to the NEVER bin. | |
| 232 const ManagedTileBin kBinPolicyMap[NUM_TILE_MEMORY_LIMIT_POLICIES][NUM_BINS] = { | |
| 233 // [ALLOW_NOTHING] | |
| 234 {NEVER_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | |
| 235 NEVER_BIN, // [NOW_BIN] | |
| 236 NEVER_BIN, // [SOON_BIN] | |
| 237 NEVER_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | |
| 238 NEVER_BIN, // [EVENTUALLY_BIN] | |
| 239 NEVER_BIN, // [AT_LAST_AND_ACTIVE_BIN] | |
| 240 NEVER_BIN, // [AT_LAST_BIN] | |
| 241 NEVER_BIN // [NEVER_BIN] | |
| 242 }, | |
| 243 // [ALLOW_ABSOLUTE_MINIMUM] | |
| 244 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | |
| 245 NOW_BIN, // [NOW_BIN] | |
| 246 NEVER_BIN, // [SOON_BIN] | |
| 247 NEVER_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | |
| 248 NEVER_BIN, // [EVENTUALLY_BIN] | |
| 249 NEVER_BIN, // [AT_LAST_AND_ACTIVE_BIN] | |
| 250 NEVER_BIN, // [AT_LAST_BIN] | |
| 251 NEVER_BIN // [NEVER_BIN] | |
| 252 }, | |
| 253 // [ALLOW_PREPAINT_ONLY] | |
| 254 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | |
| 255 NOW_BIN, // [NOW_BIN] | |
| 256 SOON_BIN, // [SOON_BIN] | |
| 257 NEVER_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | |
| 258 NEVER_BIN, // [EVENTUALLY_BIN] | |
| 259 NEVER_BIN, // [AT_LAST_AND_ACTIVE_BIN] | |
| 260 NEVER_BIN, // [AT_LAST_BIN] | |
| 261 NEVER_BIN // [NEVER_BIN] | |
| 262 }, | |
| 263 // [ALLOW_ANYTHING] | |
| 264 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | |
| 265 NOW_BIN, // [NOW_BIN] | |
| 266 SOON_BIN, // [SOON_BIN] | |
| 267 EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | |
| 268 EVENTUALLY_BIN, // [EVENTUALLY_BIN] | |
| 269 AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_AND_ACTIVE_BIN] | |
| 270 AT_LAST_BIN, // [AT_LAST_BIN] | |
| 271 NEVER_BIN // [NEVER_BIN] | |
| 272 }}; | |
| 273 | |
| 274 // Ready to draw works by mapping NOW_BIN to NOW_AND_READY_TO_DRAW_BIN. | |
| 275 const ManagedTileBin kBinReadyToDrawMap[2][NUM_BINS] = { | |
| 276 // Not ready | |
| 277 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | |
| 278 NOW_BIN, // [NOW_BIN] | |
| 279 SOON_BIN, // [SOON_BIN] | |
| 280 EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | |
| 281 EVENTUALLY_BIN, // [EVENTUALLY_BIN] | |
| 282 AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_AND_ACTIVE_BIN] | |
| 283 AT_LAST_BIN, // [AT_LAST_BIN] | |
| 284 NEVER_BIN // [NEVER_BIN] | |
| 285 }, | |
| 286 // Ready | |
| 287 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | |
| 288 NOW_AND_READY_TO_DRAW_BIN, // [NOW_BIN] | |
| 289 SOON_BIN, // [SOON_BIN] | |
| 290 EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | |
| 291 EVENTUALLY_BIN, // [EVENTUALLY_BIN] | |
| 292 AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_AND_ACTIVE_BIN] | |
| 293 AT_LAST_BIN, // [AT_LAST_BIN] | |
| 294 NEVER_BIN // [NEVER_BIN] | |
| 295 }}; | |
| 296 | |
| 297 // Active works by mapping some bin stats to equivalent _ACTIVE_BIN state. | |
| 298 const ManagedTileBin kBinIsActiveMap[2][NUM_BINS] = { | |
| 299 // Inactive | |
| 300 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | |
| 301 NOW_BIN, // [NOW_BIN] | |
| 302 SOON_BIN, // [SOON_BIN] | |
| 303 EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | |
| 304 EVENTUALLY_BIN, // [EVENTUALLY_BIN] | |
| 305 AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_AND_ACTIVE_BIN] | |
| 306 AT_LAST_BIN, // [AT_LAST_BIN] | |
| 307 NEVER_BIN // [NEVER_BIN] | |
| 308 }, | |
| 309 // Active | |
| 310 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | |
| 311 NOW_BIN, // [NOW_BIN] | |
| 312 SOON_BIN, // [SOON_BIN] | |
| 313 EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | |
| 314 EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_BIN] | |
| 315 AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_AND_ACTIVE_BIN] | |
| 316 AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_BIN] | |
| 317 NEVER_BIN // [NEVER_BIN] | |
| 318 }}; | |
| 319 | |
| 320 // Determine bin based on three categories of tiles: things we need now, | |
| 321 // things we need soon, and eventually. | |
| 322 inline ManagedTileBin BinFromTilePriority(const TilePriority& prio) { | |
| 323 if (prio.priority_bin == TilePriority::NOW) | |
| 324 return NOW_BIN; | |
| 325 | |
| 326 if (prio.priority_bin == TilePriority::SOON) | |
| 327 return SOON_BIN; | |
| 328 | |
| 329 if (prio.distance_to_visible == std::numeric_limits<float>::infinity()) | |
| 330 return NEVER_BIN; | |
| 331 | |
| 332 return EVENTUALLY_BIN; | |
| 333 } | |
| 334 | |
| 335 } // namespace | 231 } // namespace |
| 336 | 232 |
| 337 RasterTaskCompletionStats::RasterTaskCompletionStats() | 233 RasterTaskCompletionStats::RasterTaskCompletionStats() |
| 338 : completed_count(0u), canceled_count(0u) {} | 234 : completed_count(0u), canceled_count(0u) {} |
| 339 | 235 |
| 340 scoped_refptr<base::debug::ConvertableToTraceFormat> | 236 scoped_refptr<base::debug::ConvertableToTraceFormat> |
| 341 RasterTaskCompletionStatsAsValue(const RasterTaskCompletionStats& stats) { | 237 RasterTaskCompletionStatsAsValue(const RasterTaskCompletionStats& stats) { |
| 342 scoped_refptr<base::debug::TracedValue> state = | 238 scoped_refptr<base::debug::TracedValue> state = |
| 343 new base::debug::TracedValue(); | 239 new base::debug::TracedValue(); |
| 344 state->SetInteger("completed_count", stats.completed_count); | 240 state->SetInteger("completed_count", stats.completed_count); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 363 TileManager::TileManager( | 259 TileManager::TileManager( |
| 364 TileManagerClient* client, | 260 TileManagerClient* client, |
| 365 const scoped_refptr<base::SequencedTaskRunner>& task_runner, | 261 const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
| 366 ResourcePool* resource_pool, | 262 ResourcePool* resource_pool, |
| 367 Rasterizer* rasterizer, | 263 Rasterizer* rasterizer, |
| 368 RenderingStatsInstrumentation* rendering_stats_instrumentation) | 264 RenderingStatsInstrumentation* rendering_stats_instrumentation) |
| 369 : client_(client), | 265 : client_(client), |
| 370 task_runner_(task_runner), | 266 task_runner_(task_runner), |
| 371 resource_pool_(resource_pool), | 267 resource_pool_(resource_pool), |
| 372 rasterizer_(rasterizer), | 268 rasterizer_(rasterizer), |
| 373 prioritized_tiles_dirty_(false), | 269 all_tiles_that_need_to_be_rasterized_are_scheduled_(true), |
| 374 all_tiles_that_need_to_be_rasterized_have_memory_(true), | |
| 375 all_tiles_required_for_activation_have_memory_(true), | |
| 376 bytes_releasable_(0), | |
| 377 resources_releasable_(0), | |
| 378 ever_exceeded_memory_budget_(false), | |
| 379 rendering_stats_instrumentation_(rendering_stats_instrumentation), | 270 rendering_stats_instrumentation_(rendering_stats_instrumentation), |
| 380 did_initialize_visible_tile_(false), | 271 did_initialize_visible_tile_(false), |
| 381 did_check_for_completed_tasks_since_last_schedule_tasks_(true), | 272 did_check_for_completed_tasks_since_last_schedule_tasks_(true), |
| 382 did_oom_on_last_assign_(false), | 273 did_oom_on_last_assign_(false), |
| 383 ready_to_activate_check_notifier_( | 274 ready_to_activate_check_notifier_( |
| 384 task_runner_.get(), | 275 task_runner_.get(), |
| 385 base::Bind(&TileManager::CheckIfReadyToActivate, | 276 base::Bind(&TileManager::CheckIfReadyToActivate, |
| 386 base::Unretained(this))) { | 277 base::Unretained(this))) { |
| 387 rasterizer_->SetClient(this); | 278 rasterizer_->SetClient(this); |
| 388 } | 279 } |
| 389 | 280 |
| 390 TileManager::~TileManager() { | 281 TileManager::~TileManager() { |
| 391 // Reset global state and manage. This should cause | 282 // Reset global state and manage. This should cause |
| 392 // our memory usage to drop to zero. | 283 // our memory usage to drop to zero. |
| 393 global_state_ = GlobalStateThatImpactsTilePriority(); | 284 global_state_ = GlobalStateThatImpactsTilePriority(); |
| 394 | 285 |
| 395 RasterTaskQueue empty; | 286 RasterTaskQueue empty; |
| 396 rasterizer_->ScheduleTasks(&empty); | 287 rasterizer_->ScheduleTasks(&empty); |
| 397 orphan_raster_tasks_.clear(); | 288 orphan_raster_tasks_.clear(); |
| 398 | 289 |
| 399 // This should finish all pending tasks and release any uninitialized | 290 // This should finish all pending tasks and release any uninitialized |
| 400 // resources. | 291 // resources. |
| 401 rasterizer_->Shutdown(); | 292 rasterizer_->Shutdown(); |
| 402 rasterizer_->CheckForCompletedTasks(); | 293 rasterizer_->CheckForCompletedTasks(); |
| 403 | 294 |
| 404 prioritized_tiles_.Clear(); | |
| 405 | |
| 406 FreeResourcesForReleasedTiles(); | 295 FreeResourcesForReleasedTiles(); |
| 407 CleanUpReleasedTiles(); | 296 CleanUpReleasedTiles(); |
| 408 | |
| 409 DCHECK_EQ(0u, bytes_releasable_); | |
| 410 DCHECK_EQ(0u, resources_releasable_); | |
| 411 } | 297 } |
| 412 | 298 |
| 413 void TileManager::Release(Tile* tile) { | 299 void TileManager::Release(Tile* tile) { |
| 414 DCHECK(TilePriority() == tile->combined_priority()); | |
| 415 | |
| 416 prioritized_tiles_dirty_ = true; | |
| 417 released_tiles_.push_back(tile); | 300 released_tiles_.push_back(tile); |
| 418 } | 301 } |
| 419 | 302 |
| 420 void TileManager::DidChangeTilePriority(Tile* tile) { | |
| 421 prioritized_tiles_dirty_ = true; | |
| 422 } | |
| 423 | |
| 424 bool TileManager::ShouldForceTasksRequiredForActivationToComplete() const { | 303 bool TileManager::ShouldForceTasksRequiredForActivationToComplete() const { |
| 425 return global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY; | 304 return global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY; |
| 426 } | 305 } |
| 427 | 306 |
| 428 void TileManager::FreeResourcesForReleasedTiles() { | 307 void TileManager::FreeResourcesForReleasedTiles() { |
| 429 for (std::vector<Tile*>::iterator it = released_tiles_.begin(); | 308 for (std::vector<Tile*>::iterator it = released_tiles_.begin(); |
| 430 it != released_tiles_.end(); | 309 it != released_tiles_.end(); |
| 431 ++it) { | 310 ++it) { |
| 432 Tile* tile = *it; | 311 Tile* tile = *it; |
| 433 FreeResourcesForTile(tile); | 312 FreeResourcesForTile(tile); |
| 434 } | 313 } |
| 435 } | 314 } |
| 436 | 315 |
| 437 void TileManager::CleanUpReleasedTiles() { | 316 void TileManager::CleanUpReleasedTiles() { |
| 438 // Make sure |prioritized_tiles_| doesn't contain any of the tiles | |
| 439 // we're about to delete. | |
| 440 DCHECK(prioritized_tiles_.IsEmpty()); | |
| 441 | |
| 442 std::vector<Tile*>::iterator it = released_tiles_.begin(); | 317 std::vector<Tile*>::iterator it = released_tiles_.begin(); |
| 443 while (it != released_tiles_.end()) { | 318 while (it != released_tiles_.end()) { |
| 444 Tile* tile = *it; | 319 Tile* tile = *it; |
| 445 | 320 |
| 446 if (tile->HasRasterTask()) { | 321 if (tile->HasRasterTask()) { |
| 447 ++it; | 322 ++it; |
| 448 continue; | 323 continue; |
| 449 } | 324 } |
| 450 | 325 |
| 451 DCHECK(!tile->HasResources()); | 326 DCHECK(!tile->HasResources()); |
| 452 DCHECK(tiles_.find(tile->id()) != tiles_.end()); | 327 DCHECK(tiles_.find(tile->id()) != tiles_.end()); |
| 453 tiles_.erase(tile->id()); | 328 tiles_.erase(tile->id()); |
| 454 | 329 |
| 455 LayerCountMap::iterator layer_it = | 330 LayerCountMap::iterator layer_it = |
| 456 used_layer_counts_.find(tile->layer_id()); | 331 used_layer_counts_.find(tile->layer_id()); |
| 457 DCHECK_GT(layer_it->second, 0); | 332 DCHECK_GT(layer_it->second, 0); |
| 458 if (--layer_it->second == 0) { | 333 if (--layer_it->second == 0) { |
| 459 used_layer_counts_.erase(layer_it); | 334 used_layer_counts_.erase(layer_it); |
| 460 image_decode_tasks_.erase(tile->layer_id()); | 335 image_decode_tasks_.erase(tile->layer_id()); |
| 461 } | 336 } |
| 462 | 337 |
| 463 delete tile; | 338 delete tile; |
| 464 it = released_tiles_.erase(it); | 339 it = released_tiles_.erase(it); |
| 465 } | 340 } |
| 466 } | 341 } |
| 467 | 342 |
| 468 void TileManager::UpdatePrioritizedTileSetIfNeeded() { | |
| 469 if (!prioritized_tiles_dirty_) | |
| 470 return; | |
| 471 | |
| 472 prioritized_tiles_.Clear(); | |
| 473 | |
| 474 FreeResourcesForReleasedTiles(); | |
| 475 CleanUpReleasedTiles(); | |
| 476 | |
| 477 GetTilesWithAssignedBins(&prioritized_tiles_); | |
| 478 prioritized_tiles_dirty_ = false; | |
| 479 } | |
| 480 | |
| 481 void TileManager::DidFinishRunningTasks() { | 343 void TileManager::DidFinishRunningTasks() { |
| 482 TRACE_EVENT0("cc", "TileManager::DidFinishRunningTasks"); | 344 TRACE_EVENT0("cc", "TileManager::DidFinishRunningTasks"); |
| 483 | 345 |
| 484 bool memory_usage_above_limit = resource_pool_->total_memory_usage_bytes() > | 346 bool memory_usage_above_limit = resource_pool_->total_memory_usage_bytes() > |
| 485 global_state_.soft_memory_limit_in_bytes; | 347 global_state_.soft_memory_limit_in_bytes; |
| 486 | 348 |
| 487 // When OOM, keep re-assigning memory until we reach a steady state | 349 // When OOM, keep re-assigning memory until we reach a steady state |
| 488 // where top-priority tiles are initialized. | 350 // where top-priority tiles are initialized. |
| 489 if (all_tiles_that_need_to_be_rasterized_have_memory_ && | 351 if (all_tiles_that_need_to_be_rasterized_are_scheduled_ && |
| 490 !memory_usage_above_limit) | 352 !memory_usage_above_limit) |
| 491 return; | 353 return; |
| 492 | 354 |
| 493 rasterizer_->CheckForCompletedTasks(); | 355 rasterizer_->CheckForCompletedTasks(); |
| 494 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 356 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
| 495 | 357 |
| 496 TileVector tiles_that_need_to_be_rasterized; | 358 TileVector tiles_that_need_to_be_rasterized; |
| 497 AssignGpuMemoryToTiles(&prioritized_tiles_, | 359 AssignGpuMemoryToTiles(&tiles_that_need_to_be_rasterized); |
| 498 &tiles_that_need_to_be_rasterized); | |
| 499 | 360 |
| 500 // |tiles_that_need_to_be_rasterized| will be empty when we reach a | 361 // |tiles_that_need_to_be_rasterized| will be empty when we reach a |
| 501 // steady memory state. Keep scheduling tasks until we reach this state. | 362 // steady memory state. Keep scheduling tasks until we reach this state. |
| 502 if (!tiles_that_need_to_be_rasterized.empty()) { | 363 if (!tiles_that_need_to_be_rasterized.empty()) { |
| 503 ScheduleTasks(tiles_that_need_to_be_rasterized); | 364 ScheduleTasks(tiles_that_need_to_be_rasterized); |
| 504 return; | 365 return; |
| 505 } | 366 } |
| 506 | 367 |
| 507 FreeResourcesForReleasedTiles(); | 368 FreeResourcesForReleasedTiles(); |
| 508 | 369 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 531 tile_version.set_rasterize_on_demand(); | 392 tile_version.set_rasterize_on_demand(); |
| 532 client_->NotifyTileStateChanged(tile); | 393 client_->NotifyTileStateChanged(tile); |
| 533 } | 394 } |
| 534 } | 395 } |
| 535 | 396 |
| 536 DCHECK(IsReadyToActivate()); | 397 DCHECK(IsReadyToActivate()); |
| 537 ready_to_activate_check_notifier_.Schedule(); | 398 ready_to_activate_check_notifier_.Schedule(); |
| 538 } | 399 } |
| 539 | 400 |
| 540 void TileManager::DidFinishRunningTasksRequiredForActivation() { | 401 void TileManager::DidFinishRunningTasksRequiredForActivation() { |
| 541 // This is only a true indication that all tiles required for | |
| 542 // activation are initialized when no tiles are OOM. We need to | |
| 543 // wait for DidFinishRunningTasks() to be called, try to re-assign | |
| 544 // memory and in worst case use on-demand raster when tiles | |
| 545 // required for activation are OOM. | |
| 546 if (!all_tiles_required_for_activation_have_memory_) | |
| 547 return; | |
| 548 | |
| 549 ready_to_activate_check_notifier_.Schedule(); | 402 ready_to_activate_check_notifier_.Schedule(); |
| 550 } | 403 } |
| 551 | 404 |
| 552 void TileManager::GetTilesWithAssignedBins(PrioritizedTileSet* tiles) { | |
| 553 TRACE_EVENT0("cc", "TileManager::GetTilesWithAssignedBins"); | |
| 554 | |
| 555 const TileMemoryLimitPolicy memory_policy = global_state_.memory_limit_policy; | |
| 556 const TreePriority tree_priority = global_state_.tree_priority; | |
| 557 | |
| 558 // For each tree, bin into different categories of tiles. | |
| 559 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | |
| 560 Tile* tile = it->second; | |
| 561 ManagedTileState& mts = tile->managed_state(); | |
| 562 | |
| 563 const ManagedTileState::TileVersion& tile_version = | |
| 564 tile->GetTileVersionForDrawing(); | |
| 565 bool tile_is_ready_to_draw = tile_version.IsReadyToDraw(); | |
| 566 bool tile_is_active = tile_is_ready_to_draw || | |
| 567 mts.tile_versions[mts.raster_mode].raster_task_.get(); | |
| 568 | |
| 569 // Get the active priority and bin. | |
| 570 TilePriority active_priority = tile->priority(ACTIVE_TREE); | |
| 571 ManagedTileBin active_bin = BinFromTilePriority(active_priority); | |
| 572 | |
| 573 // Get the pending priority and bin. | |
| 574 TilePriority pending_priority = tile->priority(PENDING_TREE); | |
| 575 ManagedTileBin pending_bin = BinFromTilePriority(pending_priority); | |
| 576 | |
| 577 bool pending_is_low_res = pending_priority.resolution == LOW_RESOLUTION; | |
| 578 bool pending_is_non_ideal = | |
| 579 pending_priority.resolution == NON_IDEAL_RESOLUTION; | |
| 580 bool active_is_non_ideal = | |
| 581 active_priority.resolution == NON_IDEAL_RESOLUTION; | |
| 582 | |
| 583 // Adjust bin state based on if ready to draw. | |
| 584 active_bin = kBinReadyToDrawMap[tile_is_ready_to_draw][active_bin]; | |
| 585 pending_bin = kBinReadyToDrawMap[tile_is_ready_to_draw][pending_bin]; | |
| 586 | |
| 587 // Adjust bin state based on if active. | |
| 588 active_bin = kBinIsActiveMap[tile_is_active][active_bin]; | |
| 589 pending_bin = kBinIsActiveMap[tile_is_active][pending_bin]; | |
| 590 | |
| 591 // We never want to paint new non-ideal tiles, as we always have | |
| 592 // a high-res tile covering that content (paint that instead). | |
| 593 if (!tile_is_ready_to_draw && active_is_non_ideal) | |
| 594 active_bin = NEVER_BIN; | |
| 595 if (!tile_is_ready_to_draw && pending_is_non_ideal) | |
| 596 pending_bin = NEVER_BIN; | |
| 597 | |
| 598 ManagedTileBin tree_bin[NUM_TREES]; | |
| 599 tree_bin[ACTIVE_TREE] = kBinPolicyMap[memory_policy][active_bin]; | |
| 600 tree_bin[PENDING_TREE] = kBinPolicyMap[memory_policy][pending_bin]; | |
| 601 | |
| 602 // Adjust pending bin state for low res tiles. This prevents pending tree | |
| 603 // low-res tiles from being initialized before high-res tiles. | |
| 604 if (pending_is_low_res) | |
| 605 tree_bin[PENDING_TREE] = std::max(tree_bin[PENDING_TREE], EVENTUALLY_BIN); | |
| 606 | |
| 607 TilePriority tile_priority; | |
| 608 switch (tree_priority) { | |
| 609 case SAME_PRIORITY_FOR_BOTH_TREES: | |
| 610 mts.bin = std::min(tree_bin[ACTIVE_TREE], tree_bin[PENDING_TREE]); | |
| 611 tile_priority = tile->combined_priority(); | |
| 612 break; | |
| 613 case SMOOTHNESS_TAKES_PRIORITY: | |
| 614 mts.bin = tree_bin[ACTIVE_TREE]; | |
| 615 tile_priority = active_priority; | |
| 616 break; | |
| 617 case NEW_CONTENT_TAKES_PRIORITY: | |
| 618 mts.bin = tree_bin[PENDING_TREE]; | |
| 619 tile_priority = pending_priority; | |
| 620 break; | |
| 621 default: | |
| 622 NOTREACHED(); | |
| 623 } | |
| 624 | |
| 625 // Bump up the priority if we determined it's NEVER_BIN on one tree, | |
| 626 // but is still required on the other tree. | |
| 627 bool is_in_never_bin_on_both_trees = tree_bin[ACTIVE_TREE] == NEVER_BIN && | |
| 628 tree_bin[PENDING_TREE] == NEVER_BIN; | |
| 629 | |
| 630 if (mts.bin == NEVER_BIN && !is_in_never_bin_on_both_trees) | |
| 631 mts.bin = tile_is_active ? AT_LAST_AND_ACTIVE_BIN : AT_LAST_BIN; | |
| 632 | |
| 633 mts.resolution = tile_priority.resolution; | |
| 634 mts.priority_bin = tile_priority.priority_bin; | |
| 635 mts.distance_to_visible = tile_priority.distance_to_visible; | |
| 636 mts.required_for_activation = tile_priority.required_for_activation; | |
| 637 | |
| 638 mts.visible_and_ready_to_draw = | |
| 639 tree_bin[ACTIVE_TREE] == NOW_AND_READY_TO_DRAW_BIN; | |
| 640 | |
| 641 // Tiles that are required for activation shouldn't be in NEVER_BIN unless | |
| 642 // smoothness takes priority or memory policy allows nothing to be | |
| 643 // initialized. | |
| 644 DCHECK(!mts.required_for_activation || mts.bin != NEVER_BIN || | |
| 645 tree_priority == SMOOTHNESS_TAKES_PRIORITY || | |
| 646 memory_policy == ALLOW_NOTHING); | |
| 647 | |
| 648 // If the tile is in NEVER_BIN and it does not have an active task, then we | |
| 649 // can release the resources early. If it does have the task however, we | |
| 650 // should keep it in the prioritized tile set to ensure that AssignGpuMemory | |
| 651 // can visit it. | |
| 652 if (mts.bin == NEVER_BIN && | |
| 653 !mts.tile_versions[mts.raster_mode].raster_task_.get()) { | |
| 654 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile); | |
| 655 continue; | |
| 656 } | |
| 657 | |
| 658 // Insert the tile into a priority set. | |
| 659 tiles->InsertTile(tile, mts.bin); | |
| 660 } | |
| 661 } | |
| 662 | |
| 663 void TileManager::ManageTiles(const GlobalStateThatImpactsTilePriority& state) { | 405 void TileManager::ManageTiles(const GlobalStateThatImpactsTilePriority& state) { |
| 664 TRACE_EVENT0("cc", "TileManager::ManageTiles"); | 406 TRACE_EVENT0("cc", "TileManager::ManageTiles"); |
| 665 | 407 |
| 666 // Update internal state. | 408 global_state_ = state; |
| 667 if (state != global_state_) { | |
| 668 global_state_ = state; | |
| 669 prioritized_tiles_dirty_ = true; | |
| 670 } | |
| 671 | 409 |
| 672 // We need to call CheckForCompletedTasks() once in-between each call | 410 // We need to call CheckForCompletedTasks() once in-between each call |
| 673 // to ScheduleTasks() to prevent canceled tasks from being scheduled. | 411 // to ScheduleTasks() to prevent canceled tasks from being scheduled. |
| 674 if (!did_check_for_completed_tasks_since_last_schedule_tasks_) { | 412 if (!did_check_for_completed_tasks_since_last_schedule_tasks_) { |
| 675 rasterizer_->CheckForCompletedTasks(); | 413 rasterizer_->CheckForCompletedTasks(); |
| 676 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 414 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
| 677 } | 415 } |
| 678 | 416 |
| 679 UpdatePrioritizedTileSetIfNeeded(); | 417 FreeResourcesForReleasedTiles(); |
| 418 CleanUpReleasedTiles(); |
| 680 | 419 |
| 681 TileVector tiles_that_need_to_be_rasterized; | 420 TileVector tiles_that_need_to_be_rasterized; |
| 682 AssignGpuMemoryToTiles(&prioritized_tiles_, | 421 AssignGpuMemoryToTiles(&tiles_that_need_to_be_rasterized); |
| 683 &tiles_that_need_to_be_rasterized); | |
| 684 | 422 |
| 685 // Finally, schedule rasterizer tasks. | 423 // Finally, schedule rasterizer tasks. |
| 686 ScheduleTasks(tiles_that_need_to_be_rasterized); | 424 ScheduleTasks(tiles_that_need_to_be_rasterized); |
| 687 | 425 |
| 688 TRACE_EVENT_INSTANT1("cc", | 426 TRACE_EVENT_INSTANT1("cc", |
| 689 "DidManage", | 427 "DidManage", |
| 690 TRACE_EVENT_SCOPE_THREAD, | 428 TRACE_EVENT_SCOPE_THREAD, |
| 691 "state", | 429 "state", |
| 692 BasicStateAsValue()); | 430 BasicStateAsValue()); |
| 693 | 431 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 } | 464 } |
| 727 | 465 |
| 728 void TileManager::BasicStateAsValueInto(base::debug::TracedValue* state) const { | 466 void TileManager::BasicStateAsValueInto(base::debug::TracedValue* state) const { |
| 729 state->SetInteger("tile_count", tiles_.size()); | 467 state->SetInteger("tile_count", tiles_.size()); |
| 730 state->SetBoolean("did_oom_on_last_assign", did_oom_on_last_assign_); | 468 state->SetBoolean("did_oom_on_last_assign", did_oom_on_last_assign_); |
| 731 state->BeginDictionary("global_state"); | 469 state->BeginDictionary("global_state"); |
| 732 global_state_.AsValueInto(state); | 470 global_state_.AsValueInto(state); |
| 733 state->EndDictionary(); | 471 state->EndDictionary(); |
| 734 } | 472 } |
| 735 | 473 |
| 474 void TileManager::RebuildEvictionQueueIfNeeded() { |
| 475 if (eviction_priority_queue_is_up_to_date_) |
| 476 return; |
| 477 |
| 478 eviction_priority_queue_.Reset(); |
| 479 client_->BuildEvictionQueue(&eviction_priority_queue_, |
| 480 global_state_.tree_priority); |
| 481 eviction_priority_queue_is_up_to_date_ = true; |
| 482 } |
| 483 |
| 484 bool TileManager::FreeTileResourcesUntilUsageIsWithinLimit( |
| 485 const MemoryUsage& limit, |
| 486 MemoryUsage* usage) { |
| 487 while (usage->Exceeds(limit)) { |
| 488 RebuildEvictionQueueIfNeeded(); |
| 489 if (eviction_priority_queue_.IsEmpty()) |
| 490 return false; |
| 491 |
| 492 Tile* tile = eviction_priority_queue_.Top(); |
| 493 *usage -= MemoryUsage::FromTile(tile); |
| 494 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile); |
| 495 eviction_priority_queue_.Pop(); |
| 496 } |
| 497 return true; |
| 498 } |
| 499 |
| 500 bool TileManager::FreeTileResourcesWithLowerPriorityUntilUsageIsWithinLimit( |
| 501 const MemoryUsage& limit, |
| 502 const TilePriority& other_priority, |
| 503 MemoryUsage* usage) { |
| 504 while (usage->Exceeds(limit)) { |
| 505 RebuildEvictionQueueIfNeeded(); |
| 506 if (eviction_priority_queue_.IsEmpty()) |
| 507 return false; |
| 508 |
| 509 Tile* tile = eviction_priority_queue_.Top(); |
| 510 if (!other_priority.IsHigherPriorityThan( |
| 511 tile->priority_for_tree_priority(global_state_.tree_priority))) { |
| 512 return false; |
| 513 } |
| 514 |
| 515 *usage -= MemoryUsage::FromTile(tile); |
| 516 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile); |
| 517 eviction_priority_queue_.Pop(); |
| 518 } |
| 519 return true; |
| 520 } |
| 521 |
| 522 bool TileManager::TilePriorityViolatesMemoryPolicy( |
| 523 const TilePriority& priority) { |
| 524 switch (global_state_.memory_limit_policy) { |
| 525 case ALLOW_NOTHING: |
| 526 return true; |
| 527 case ALLOW_ABSOLUTE_MINIMUM: |
| 528 return priority.priority_bin > TilePriority::NOW; |
| 529 case ALLOW_PREPAINT_ONLY: |
| 530 return priority.priority_bin > TilePriority::SOON; |
| 531 case ALLOW_ANYTHING: |
| 532 return priority.distance_to_visible == |
| 533 std::numeric_limits<float>::infinity(); |
| 534 } |
| 535 NOTREACHED(); |
| 536 return true; |
| 537 } |
| 538 |
| 736 void TileManager::AssignGpuMemoryToTiles( | 539 void TileManager::AssignGpuMemoryToTiles( |
| 737 PrioritizedTileSet* tiles, | |
| 738 TileVector* tiles_that_need_to_be_rasterized) { | 540 TileVector* tiles_that_need_to_be_rasterized) { |
| 739 TRACE_EVENT0("cc", "TileManager::AssignGpuMemoryToTiles"); | 541 TRACE_EVENT0("cc", "TileManager::AssignGpuMemoryToTiles"); |
| 740 | 542 |
| 741 // Maintain the list of released resources that can potentially be re-used | 543 // Maintain the list of released resources that can potentially be re-used |
| 742 // or deleted. | 544 // or deleted. |
| 743 // If this operation becomes expensive too, only do this after some | 545 // If this operation becomes expensive too, only do this after some |
| 744 // resource(s) was returned. Note that in that case, one also need to | 546 // resource(s) was returned. Note that in that case, one also need to |
| 745 // invalidate when releasing some resource from the pool. | 547 // invalidate when releasing some resource from the pool. |
| 746 resource_pool_->CheckBusyResources(); | 548 resource_pool_->CheckBusyResources(); |
| 747 | 549 |
| 748 // Now give memory out to the tiles until we're out, and build | 550 // Now give memory out to the tiles until we're out, and build |
| 749 // the needs-to-be-rasterized queue. | 551 // the needs-to-be-rasterized queue. |
| 750 all_tiles_that_need_to_be_rasterized_have_memory_ = true; | 552 unsigned schedule_priority = 1u; |
| 751 all_tiles_required_for_activation_have_memory_ = true; | 553 all_tiles_that_need_to_be_rasterized_are_scheduled_ = true; |
| 554 bool had_enough_memory_to_schedule_tiles_needed_now = true; |
| 752 | 555 |
| 753 // Cast to prevent overflow. | 556 MemoryUsage hard_memory_limit(global_state_.hard_memory_limit_in_bytes, |
| 754 int64 soft_bytes_available = | 557 global_state_.num_resources_limit); |
| 755 static_cast<int64>(bytes_releasable_) + | 558 MemoryUsage soft_memory_limit(global_state_.soft_memory_limit_in_bytes, |
| 756 static_cast<int64>(global_state_.soft_memory_limit_in_bytes) - | 559 global_state_.num_resources_limit); |
| 757 static_cast<int64>(resource_pool_->acquired_memory_usage_bytes()); | 560 MemoryUsage memory_usage(resource_pool_->acquired_memory_usage_bytes(), |
| 758 int64 hard_bytes_available = | 561 resource_pool_->acquired_resource_count()); |
| 759 static_cast<int64>(bytes_releasable_) + | |
| 760 static_cast<int64>(global_state_.hard_memory_limit_in_bytes) - | |
| 761 static_cast<int64>(resource_pool_->acquired_memory_usage_bytes()); | |
| 762 int resources_available = resources_releasable_ + | |
| 763 global_state_.num_resources_limit - | |
| 764 resource_pool_->acquired_resource_count(); | |
| 765 size_t soft_bytes_allocatable = | |
| 766 std::max(static_cast<int64>(0), soft_bytes_available); | |
| 767 size_t hard_bytes_allocatable = | |
| 768 std::max(static_cast<int64>(0), hard_bytes_available); | |
| 769 size_t resources_allocatable = std::max(0, resources_available); | |
| 770 | 562 |
| 771 size_t bytes_that_exceeded_memory_budget = 0; | 563 eviction_priority_queue_is_up_to_date_ = false; |
| 772 size_t soft_bytes_left = soft_bytes_allocatable; | 564 raster_priority_queue_.Reset(); |
| 773 size_t hard_bytes_left = hard_bytes_allocatable; | 565 client_->BuildRasterQueue(&raster_priority_queue_, |
| 566 global_state_.tree_priority); |
| 774 | 567 |
| 775 size_t resources_left = resources_allocatable; | 568 while (!raster_priority_queue_.IsEmpty()) { |
| 776 bool oomed_soft = false; | 569 Tile* tile = raster_priority_queue_.Top(); |
| 777 bool oomed_hard = false; | 570 TilePriority priority = |
| 778 bool have_hit_soft_memory = false; // Soft memory comes after hard. | 571 tile->priority_for_tree_priority(global_state_.tree_priority); |
| 779 | 572 |
| 780 unsigned schedule_priority = 1u; | 573 if (TilePriorityViolatesMemoryPolicy(priority)) |
| 781 for (PrioritizedTileSet::Iterator it(tiles, true); it; ++it) { | 574 break; |
| 782 Tile* tile = *it; | 575 |
| 576 // We won't be able to schedule this tile, so break out early. |
| 577 if (tiles_that_need_to_be_rasterized->size() >= |
| 578 kScheduledRasterTasksLimit) { |
| 579 all_tiles_that_need_to_be_rasterized_are_scheduled_ = false; |
| 580 break; |
| 581 } |
| 582 |
| 783 ManagedTileState& mts = tile->managed_state(); | 583 ManagedTileState& mts = tile->managed_state(); |
| 784 | |
| 785 mts.scheduled_priority = schedule_priority++; | 584 mts.scheduled_priority = schedule_priority++; |
| 786 | |
| 787 mts.raster_mode = tile->DetermineOverallRasterMode(); | 585 mts.raster_mode = tile->DetermineOverallRasterMode(); |
| 788 | |
| 789 ManagedTileState::TileVersion& tile_version = | 586 ManagedTileState::TileVersion& tile_version = |
| 790 mts.tile_versions[mts.raster_mode]; | 587 mts.tile_versions[mts.raster_mode]; |
| 791 | 588 |
| 792 // If this tile doesn't need a resource, then nothing to do. | 589 DCHECK(tile_version.mode() == |
| 793 if (!tile_version.requires_resource()) | 590 ManagedTileState::TileVersion::PICTURE_PILE_MODE || |
| 794 continue; | 591 !tile_version.IsReadyToDraw()); |
| 795 | 592 |
| 796 // If the tile is not needed, free it up. | 593 // If the tile already has a raster_task, then the memory used by it is |
| 797 if (mts.bin == NEVER_BIN) { | 594 // already accounted for in memory_usage. Otherwise, we'll have to acquire |
| 798 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile); | 595 // more memory to create a raster task. |
| 799 continue; | 596 MemoryUsage memory_required_by_tile_to_be_scheduled; |
| 597 if (!tile_version.raster_task_.get()) { |
| 598 memory_required_by_tile_to_be_scheduled = MemoryUsage::FromConfig( |
| 599 tile->size(), resource_pool_->resource_format()); |
| 800 } | 600 } |
| 801 | 601 |
| 802 const bool tile_uses_hard_limit = mts.bin <= NOW_BIN; | 602 bool tile_is_needed_now = priority.priority_bin == TilePriority::NOW; |
| 803 const size_t bytes_if_allocated = BytesConsumedIfAllocated(tile); | |
| 804 const size_t tile_bytes_left = | |
| 805 (tile_uses_hard_limit) ? hard_bytes_left : soft_bytes_left; | |
| 806 | 603 |
| 807 // Hard-limit is reserved for tiles that would cause a calamity | 604 // This is the memory limit that will be used by this tile. Depending on |
| 808 // if they were to go away, so by definition they are the highest | 605 // the tile priority, it will be one of hard_memory_limit or |
| 809 // priority memory, and must be at the front of the list. | 606 // soft_memory_limit. |
| 810 DCHECK(!(have_hit_soft_memory && tile_uses_hard_limit)); | 607 MemoryUsage& tile_memory_limit = |
| 811 have_hit_soft_memory |= !tile_uses_hard_limit; | 608 tile_is_needed_now ? hard_memory_limit : soft_memory_limit; |
| 812 | 609 |
| 813 size_t tile_bytes = 0; | 610 bool memory_usage_is_within_limit = |
| 814 size_t tile_resources = 0; | 611 FreeTileResourcesWithLowerPriorityUntilUsageIsWithinLimit( |
| 612 tile_memory_limit - memory_required_by_tile_to_be_scheduled, |
| 613 priority, |
| 614 &memory_usage); |
| 815 | 615 |
| 816 // It costs to maintain a resource. | 616 // If we couldn't fit the tile into our current memory limit, then we're |
| 817 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { | 617 // done. |
| 818 if (mts.tile_versions[mode].resource_) { | 618 if (!memory_usage_is_within_limit) { |
| 819 tile_bytes += bytes_if_allocated; | 619 if (tile_is_needed_now) |
| 820 tile_resources++; | 620 had_enough_memory_to_schedule_tiles_needed_now = false; |
| 821 } | 621 all_tiles_that_need_to_be_rasterized_are_scheduled_ = false; |
| 622 break; |
| 822 } | 623 } |
| 823 | 624 |
| 824 // Allow lower priority tiles with initialized resources to keep | 625 memory_usage += memory_required_by_tile_to_be_scheduled; |
| 825 // their memory by only assigning memory to new raster tasks if | |
| 826 // they can be scheduled. | |
| 827 bool reached_scheduled_raster_tasks_limit = | |
| 828 tiles_that_need_to_be_rasterized->size() >= kScheduledRasterTasksLimit; | |
| 829 if (!reached_scheduled_raster_tasks_limit) { | |
| 830 // If we don't have the required version, and it's not in flight | |
| 831 // then we'll have to pay to create a new task. | |
| 832 if (!tile_version.resource_ && !tile_version.raster_task_.get()) { | |
| 833 tile_bytes += bytes_if_allocated; | |
| 834 tile_resources++; | |
| 835 } | |
| 836 } | |
| 837 | |
| 838 // Tile is OOM. | |
| 839 if (tile_bytes > tile_bytes_left || tile_resources > resources_left) { | |
| 840 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile); | |
| 841 | |
| 842 // This tile was already on screen and now its resources have been | |
| 843 // released. In order to prevent checkerboarding, set this tile as | |
| 844 // rasterize on demand immediately. | |
| 845 if (mts.visible_and_ready_to_draw) | |
| 846 tile_version.set_rasterize_on_demand(); | |
| 847 | |
| 848 oomed_soft = true; | |
| 849 if (tile_uses_hard_limit) { | |
| 850 oomed_hard = true; | |
| 851 bytes_that_exceeded_memory_budget += tile_bytes; | |
| 852 } | |
| 853 } else { | |
| 854 resources_left -= tile_resources; | |
| 855 hard_bytes_left -= tile_bytes; | |
| 856 soft_bytes_left = | |
| 857 (soft_bytes_left > tile_bytes) ? soft_bytes_left - tile_bytes : 0; | |
| 858 if (tile_version.resource_) | |
| 859 continue; | |
| 860 } | |
| 861 | |
| 862 DCHECK(!tile_version.resource_); | |
| 863 | |
| 864 // Tile shouldn't be rasterized if |tiles_that_need_to_be_rasterized| | |
| 865 // has reached it's limit or we've failed to assign gpu memory to this | |
| 866 // or any higher priority tile. Preventing tiles that fit into memory | |
| 867 // budget to be rasterized when higher priority tile is oom is | |
| 868 // important for two reasons: | |
| 869 // 1. Tile size should not impact raster priority. | |
| 870 // 2. Tiles with existing raster task could otherwise incorrectly | |
| 871 // be added as they are not affected by |bytes_allocatable|. | |
| 872 bool can_schedule_tile = | |
| 873 !oomed_soft && !reached_scheduled_raster_tasks_limit; | |
| 874 | |
| 875 if (!can_schedule_tile) { | |
| 876 all_tiles_that_need_to_be_rasterized_have_memory_ = false; | |
| 877 if (tile->required_for_activation()) | |
| 878 all_tiles_required_for_activation_have_memory_ = false; | |
| 879 it.DisablePriorityOrdering(); | |
| 880 continue; | |
| 881 } | |
| 882 | |
| 883 tiles_that_need_to_be_rasterized->push_back(tile); | 626 tiles_that_need_to_be_rasterized->push_back(tile); |
| 627 raster_priority_queue_.Pop(); |
| 884 } | 628 } |
| 885 | 629 |
| 886 // OOM reporting uses hard-limit, soft-OOM is normal depending on limit. | 630 // Note that we should try and further reduce memory in case the above loop |
| 887 ever_exceeded_memory_budget_ |= oomed_hard; | 631 // didn't reduce memory. This ensures that we always release as many resources |
| 888 if (ever_exceeded_memory_budget_) { | 632 // as possible to stay within the memory limit. |
| 889 TRACE_COUNTER_ID2("cc", | 633 FreeTileResourcesUntilUsageIsWithinLimit(hard_memory_limit, &memory_usage); |
| 890 "over_memory_budget", | 634 |
| 891 this, | 635 UMA_HISTOGRAM_BOOLEAN("TileManager.ExceededMemoryBudget", |
| 892 "budget", | 636 !had_enough_memory_to_schedule_tiles_needed_now); |
| 893 global_state_.hard_memory_limit_in_bytes, | 637 did_oom_on_last_assign_ = !had_enough_memory_to_schedule_tiles_needed_now; |
| 894 "over", | 638 |
| 895 bytes_that_exceeded_memory_budget); | |
| 896 } | |
| 897 did_oom_on_last_assign_ = oomed_hard; | |
| 898 UMA_HISTOGRAM_BOOLEAN("TileManager.ExceededMemoryBudget", oomed_hard); | |
| 899 memory_stats_from_last_assign_.total_budget_in_bytes = | 639 memory_stats_from_last_assign_.total_budget_in_bytes = |
| 900 global_state_.hard_memory_limit_in_bytes; | 640 global_state_.hard_memory_limit_in_bytes; |
| 901 memory_stats_from_last_assign_.bytes_allocated = | 641 memory_stats_from_last_assign_.total_bytes_used = memory_usage.memory_bytes(); |
| 902 hard_bytes_allocatable - hard_bytes_left; | 642 memory_stats_from_last_assign_.had_enough_memory = |
| 903 memory_stats_from_last_assign_.bytes_unreleasable = | 643 had_enough_memory_to_schedule_tiles_needed_now; |
| 904 resource_pool_->acquired_memory_usage_bytes() - bytes_releasable_; | |
| 905 memory_stats_from_last_assign_.bytes_over = bytes_that_exceeded_memory_budget; | |
| 906 } | 644 } |
| 907 | 645 |
| 908 void TileManager::FreeResourceForTile(Tile* tile, RasterMode mode) { | 646 void TileManager::FreeResourceForTile(Tile* tile, RasterMode mode) { |
| 909 ManagedTileState& mts = tile->managed_state(); | 647 ManagedTileState& mts = tile->managed_state(); |
| 910 if (mts.tile_versions[mode].resource_) { | 648 if (mts.tile_versions[mode].resource_) |
| 911 resource_pool_->ReleaseResource(mts.tile_versions[mode].resource_.Pass()); | 649 resource_pool_->ReleaseResource(mts.tile_versions[mode].resource_.Pass()); |
| 912 | |
| 913 DCHECK_GE(bytes_releasable_, BytesConsumedIfAllocated(tile)); | |
| 914 DCHECK_GE(resources_releasable_, 1u); | |
| 915 | |
| 916 bytes_releasable_ -= BytesConsumedIfAllocated(tile); | |
| 917 --resources_releasable_; | |
| 918 } | |
| 919 } | 650 } |
| 920 | 651 |
| 921 void TileManager::FreeResourcesForTile(Tile* tile) { | 652 void TileManager::FreeResourcesForTile(Tile* tile) { |
| 922 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { | 653 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { |
| 923 FreeResourceForTile(tile, static_cast<RasterMode>(mode)); | 654 FreeResourceForTile(tile, static_cast<RasterMode>(mode)); |
| 924 } | 655 } |
| 925 } | 656 } |
| 926 | 657 |
| 927 void TileManager::FreeUnusedResourcesForTile(Tile* tile) { | 658 void TileManager::FreeUnusedResourcesForTile(Tile* tile) { |
| 928 DCHECK(tile->IsReadyToDraw()); | 659 DCHECK(tile->IsReadyToDraw()); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1105 } | 836 } |
| 1106 | 837 |
| 1107 ++update_visible_tiles_stats_.completed_count; | 838 ++update_visible_tiles_stats_.completed_count; |
| 1108 | 839 |
| 1109 if (analysis.is_solid_color) { | 840 if (analysis.is_solid_color) { |
| 1110 tile_version.set_solid_color(analysis.solid_color); | 841 tile_version.set_solid_color(analysis.solid_color); |
| 1111 resource_pool_->ReleaseResource(resource.Pass()); | 842 resource_pool_->ReleaseResource(resource.Pass()); |
| 1112 } else { | 843 } else { |
| 1113 tile_version.set_use_resource(); | 844 tile_version.set_use_resource(); |
| 1114 tile_version.resource_ = resource.Pass(); | 845 tile_version.resource_ = resource.Pass(); |
| 1115 | |
| 1116 bytes_releasable_ += BytesConsumedIfAllocated(tile); | |
| 1117 ++resources_releasable_; | |
| 1118 } | 846 } |
| 1119 | 847 |
| 1120 FreeUnusedResourcesForTile(tile); | 848 FreeUnusedResourcesForTile(tile); |
| 1121 if (tile->priority(ACTIVE_TREE).distance_to_visible == 0.f) | 849 if (tile->priority(ACTIVE_TREE).distance_to_visible == 0.f) |
| 1122 did_initialize_visible_tile_ = true; | 850 did_initialize_visible_tile_ = true; |
| 1123 | 851 |
| 1124 client_->NotifyTileStateChanged(tile); | 852 client_->NotifyTileStateChanged(tile); |
| 1125 } | 853 } |
| 1126 | 854 |
| 1127 scoped_refptr<Tile> TileManager::CreateTile(PicturePileImpl* picture_pile, | 855 scoped_refptr<Tile> TileManager::CreateTile(PicturePileImpl* picture_pile, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1138 content_rect, | 866 content_rect, |
| 1139 opaque_rect, | 867 opaque_rect, |
| 1140 contents_scale, | 868 contents_scale, |
| 1141 layer_id, | 869 layer_id, |
| 1142 source_frame_number, | 870 source_frame_number, |
| 1143 flags)); | 871 flags)); |
| 1144 DCHECK(tiles_.find(tile->id()) == tiles_.end()); | 872 DCHECK(tiles_.find(tile->id()) == tiles_.end()); |
| 1145 | 873 |
| 1146 tiles_[tile->id()] = tile.get(); | 874 tiles_[tile->id()] = tile.get(); |
| 1147 used_layer_counts_[tile->layer_id()]++; | 875 used_layer_counts_[tile->layer_id()]++; |
| 1148 prioritized_tiles_dirty_ = true; | |
| 1149 return tile; | 876 return tile; |
| 1150 } | 877 } |
| 1151 | 878 |
| 1152 void TileManager::SetRasterizerForTesting(Rasterizer* rasterizer) { | 879 void TileManager::SetRasterizerForTesting(Rasterizer* rasterizer) { |
| 1153 rasterizer_ = rasterizer; | 880 rasterizer_ = rasterizer; |
| 1154 rasterizer_->SetClient(this); | 881 rasterizer_->SetClient(this); |
| 1155 } | 882 } |
| 1156 | 883 |
| 1157 bool TileManager::IsReadyToActivate() const { | 884 bool TileManager::IsReadyToActivate() const { |
| 1158 const std::vector<PictureLayerImpl*>& layers = client_->GetPictureLayers(); | 885 const std::vector<PictureLayerImpl*>& layers = client_->GetPictureLayers(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1170 void TileManager::CheckIfReadyToActivate() { | 897 void TileManager::CheckIfReadyToActivate() { |
| 1171 TRACE_EVENT0("cc", "TileManager::CheckIfReadyToActivate"); | 898 TRACE_EVENT0("cc", "TileManager::CheckIfReadyToActivate"); |
| 1172 | 899 |
| 1173 rasterizer_->CheckForCompletedTasks(); | 900 rasterizer_->CheckForCompletedTasks(); |
| 1174 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 901 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
| 1175 | 902 |
| 1176 if (IsReadyToActivate()) | 903 if (IsReadyToActivate()) |
| 1177 client_->NotifyReadyToActivate(); | 904 client_->NotifyReadyToActivate(); |
| 1178 } | 905 } |
| 1179 | 906 |
| 907 TileManager::MemoryUsage::MemoryUsage() : memory_bytes_(0), resource_count_(0) { |
| 908 } |
| 909 |
| 910 TileManager::MemoryUsage::MemoryUsage(int64 memory_bytes, int resource_count) |
| 911 : memory_bytes_(memory_bytes), resource_count_(resource_count) { |
| 912 } |
| 913 |
| 914 // static |
| 915 TileManager::MemoryUsage TileManager::MemoryUsage::FromConfig( |
| 916 const gfx::Size& size, |
| 917 ResourceFormat format) { |
| 918 return MemoryUsage(Resource::MemorySizeBytes(size, format), 1); |
| 919 } |
| 920 |
| 921 // static |
| 922 TileManager::MemoryUsage TileManager::MemoryUsage::FromTile(const Tile* tile) { |
| 923 const ManagedTileState& mts = tile->managed_state(); |
| 924 MemoryUsage total_usage; |
| 925 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { |
| 926 if (mts.tile_versions[mode].resource_) { |
| 927 total_usage += MemoryUsage::FromConfig( |
| 928 tile->size(), mts.tile_versions[mode].resource_->format()); |
| 929 } |
| 930 } |
| 931 return total_usage; |
| 932 } |
| 933 |
| 934 TileManager::MemoryUsage& TileManager::MemoryUsage::operator+=( |
| 935 const MemoryUsage& other) { |
| 936 memory_bytes_ += other.memory_bytes_; |
| 937 resource_count_ += other.resource_count_; |
| 938 return *this; |
| 939 } |
| 940 |
| 941 TileManager::MemoryUsage& TileManager::MemoryUsage::operator-=( |
| 942 const MemoryUsage& other) { |
| 943 memory_bytes_ -= other.memory_bytes_; |
| 944 resource_count_ -= other.resource_count_; |
| 945 return *this; |
| 946 } |
| 947 |
| 948 TileManager::MemoryUsage TileManager::MemoryUsage::operator-( |
| 949 const MemoryUsage& other) { |
| 950 MemoryUsage result = *this; |
| 951 result -= other; |
| 952 return result; |
| 953 } |
| 954 |
| 955 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { |
| 956 return memory_bytes_ > limit.memory_bytes_ || |
| 957 resource_count_ > limit.resource_count_; |
| 958 } |
| 959 |
| 1180 } // namespace cc | 960 } // namespace cc |
| OLD | NEW |