Chromium Code Reviews| 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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 skia::RefPtr<SkPixelRef> pixel_ref_; | 220 skia::RefPtr<SkPixelRef> pixel_ref_; |
| 221 int layer_id_; | 221 int layer_id_; |
| 222 RenderingStatsInstrumentation* rendering_stats_; | 222 RenderingStatsInstrumentation* rendering_stats_; |
| 223 const base::Callback<void(bool was_canceled)> reply_; | 223 const base::Callback<void(bool was_canceled)> reply_; |
| 224 | 224 |
| 225 DISALLOW_COPY_AND_ASSIGN(ImageDecodeTaskImpl); | 225 DISALLOW_COPY_AND_ASSIGN(ImageDecodeTaskImpl); |
| 226 }; | 226 }; |
| 227 | 227 |
| 228 const size_t kScheduledRasterTasksLimit = 32u; | 228 const size_t kScheduledRasterTasksLimit = 32u; |
| 229 | 229 |
| 230 // Memory limit policy works by mapping some bin states to the NEVER bin. | |
| 231 const ManagedTileBin kBinPolicyMap[NUM_TILE_MEMORY_LIMIT_POLICIES][NUM_BINS] = { | |
| 232 // [ALLOW_NOTHING] | |
| 233 {NEVER_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | |
| 234 NEVER_BIN, // [NOW_BIN] | |
| 235 NEVER_BIN, // [SOON_BIN] | |
| 236 NEVER_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | |
| 237 NEVER_BIN, // [EVENTUALLY_BIN] | |
| 238 NEVER_BIN, // [AT_LAST_AND_ACTIVE_BIN] | |
| 239 NEVER_BIN, // [AT_LAST_BIN] | |
| 240 NEVER_BIN // [NEVER_BIN] | |
| 241 }, | |
| 242 // [ALLOW_ABSOLUTE_MINIMUM] | |
| 243 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | |
| 244 NOW_BIN, // [NOW_BIN] | |
| 245 NEVER_BIN, // [SOON_BIN] | |
| 246 NEVER_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | |
| 247 NEVER_BIN, // [EVENTUALLY_BIN] | |
| 248 NEVER_BIN, // [AT_LAST_AND_ACTIVE_BIN] | |
| 249 NEVER_BIN, // [AT_LAST_BIN] | |
| 250 NEVER_BIN // [NEVER_BIN] | |
| 251 }, | |
| 252 // [ALLOW_PREPAINT_ONLY] | |
| 253 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | |
| 254 NOW_BIN, // [NOW_BIN] | |
| 255 SOON_BIN, // [SOON_BIN] | |
| 256 NEVER_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | |
| 257 NEVER_BIN, // [EVENTUALLY_BIN] | |
| 258 NEVER_BIN, // [AT_LAST_AND_ACTIVE_BIN] | |
| 259 NEVER_BIN, // [AT_LAST_BIN] | |
| 260 NEVER_BIN // [NEVER_BIN] | |
| 261 }, | |
| 262 // [ALLOW_ANYTHING] | |
| 263 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | |
| 264 NOW_BIN, // [NOW_BIN] | |
| 265 SOON_BIN, // [SOON_BIN] | |
| 266 EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | |
| 267 EVENTUALLY_BIN, // [EVENTUALLY_BIN] | |
| 268 AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_AND_ACTIVE_BIN] | |
| 269 AT_LAST_BIN, // [AT_LAST_BIN] | |
| 270 NEVER_BIN // [NEVER_BIN] | |
| 271 }}; | |
| 272 | |
| 273 // Ready to draw works by mapping NOW_BIN to NOW_AND_READY_TO_DRAW_BIN. | |
| 274 const ManagedTileBin kBinReadyToDrawMap[2][NUM_BINS] = { | |
| 275 // Not ready | |
| 276 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | |
| 277 NOW_BIN, // [NOW_BIN] | |
| 278 SOON_BIN, // [SOON_BIN] | |
| 279 EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | |
| 280 EVENTUALLY_BIN, // [EVENTUALLY_BIN] | |
| 281 AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_AND_ACTIVE_BIN] | |
| 282 AT_LAST_BIN, // [AT_LAST_BIN] | |
| 283 NEVER_BIN // [NEVER_BIN] | |
| 284 }, | |
| 285 // Ready | |
| 286 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | |
| 287 NOW_AND_READY_TO_DRAW_BIN, // [NOW_BIN] | |
| 288 SOON_BIN, // [SOON_BIN] | |
| 289 EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | |
| 290 EVENTUALLY_BIN, // [EVENTUALLY_BIN] | |
| 291 AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_AND_ACTIVE_BIN] | |
| 292 AT_LAST_BIN, // [AT_LAST_BIN] | |
| 293 NEVER_BIN // [NEVER_BIN] | |
| 294 }}; | |
| 295 | |
| 296 // Active works by mapping some bin stats to equivalent _ACTIVE_BIN state. | |
| 297 const ManagedTileBin kBinIsActiveMap[2][NUM_BINS] = { | |
| 298 // Inactive | |
| 299 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | |
| 300 NOW_BIN, // [NOW_BIN] | |
| 301 SOON_BIN, // [SOON_BIN] | |
| 302 EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | |
| 303 EVENTUALLY_BIN, // [EVENTUALLY_BIN] | |
| 304 AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_AND_ACTIVE_BIN] | |
| 305 AT_LAST_BIN, // [AT_LAST_BIN] | |
| 306 NEVER_BIN // [NEVER_BIN] | |
| 307 }, | |
| 308 // Active | |
| 309 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | |
| 310 NOW_BIN, // [NOW_BIN] | |
| 311 SOON_BIN, // [SOON_BIN] | |
| 312 EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | |
| 313 EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_BIN] | |
| 314 AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_AND_ACTIVE_BIN] | |
| 315 AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_BIN] | |
| 316 NEVER_BIN // [NEVER_BIN] | |
| 317 }}; | |
| 318 | |
| 319 // Determine bin based on three categories of tiles: things we need now, | |
| 320 // things we need soon, and eventually. | |
| 321 inline ManagedTileBin BinFromTilePriority(const TilePriority& prio) { | |
| 322 if (prio.priority_bin == TilePriority::NOW) | |
| 323 return NOW_BIN; | |
| 324 | |
| 325 if (prio.priority_bin == TilePriority::SOON) | |
| 326 return SOON_BIN; | |
| 327 | |
| 328 if (prio.distance_to_visible == std::numeric_limits<float>::infinity()) | |
| 329 return NEVER_BIN; | |
| 330 | |
| 331 return EVENTUALLY_BIN; | |
| 332 } | |
| 333 | |
| 334 } // namespace | 230 } // namespace |
| 335 | 231 |
| 336 RasterTaskCompletionStats::RasterTaskCompletionStats() | 232 RasterTaskCompletionStats::RasterTaskCompletionStats() |
| 337 : completed_count(0u), canceled_count(0u) {} | 233 : completed_count(0u), canceled_count(0u) {} |
| 338 | 234 |
| 339 scoped_ptr<base::Value> RasterTaskCompletionStatsAsValue( | 235 scoped_ptr<base::Value> RasterTaskCompletionStatsAsValue( |
| 340 const RasterTaskCompletionStats& stats) { | 236 const RasterTaskCompletionStats& stats) { |
| 341 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 237 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
| 342 state->SetInteger("completed_count", stats.completed_count); | 238 state->SetInteger("completed_count", stats.completed_count); |
| 343 state->SetInteger("canceled_count", stats.canceled_count); | 239 state->SetInteger("canceled_count", stats.canceled_count); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 361 TileManager::TileManager( | 257 TileManager::TileManager( |
| 362 TileManagerClient* client, | 258 TileManagerClient* client, |
| 363 base::SequencedTaskRunner* task_runner, | 259 base::SequencedTaskRunner* task_runner, |
| 364 ResourcePool* resource_pool, | 260 ResourcePool* resource_pool, |
| 365 Rasterizer* rasterizer, | 261 Rasterizer* rasterizer, |
| 366 RenderingStatsInstrumentation* rendering_stats_instrumentation) | 262 RenderingStatsInstrumentation* rendering_stats_instrumentation) |
| 367 : client_(client), | 263 : client_(client), |
| 368 task_runner_(task_runner), | 264 task_runner_(task_runner), |
| 369 resource_pool_(resource_pool), | 265 resource_pool_(resource_pool), |
| 370 rasterizer_(rasterizer), | 266 rasterizer_(rasterizer), |
| 371 prioritized_tiles_dirty_(false), | |
| 372 all_tiles_that_need_to_be_rasterized_have_memory_(true), | 267 all_tiles_that_need_to_be_rasterized_have_memory_(true), |
| 373 all_tiles_required_for_activation_have_memory_(true), | |
| 374 memory_required_bytes_(0), | |
| 375 memory_nice_to_have_bytes_(0), | |
| 376 bytes_releasable_(0), | 268 bytes_releasable_(0), |
| 377 resources_releasable_(0), | 269 resources_releasable_(0), |
| 270 bytes_required_but_not_allocated_(0), | |
| 378 ever_exceeded_memory_budget_(false), | 271 ever_exceeded_memory_budget_(false), |
| 379 rendering_stats_instrumentation_(rendering_stats_instrumentation), | 272 rendering_stats_instrumentation_(rendering_stats_instrumentation), |
| 380 did_initialize_visible_tile_(false), | 273 did_initialize_visible_tile_(false), |
| 381 did_check_for_completed_tasks_since_last_schedule_tasks_(true), | 274 did_check_for_completed_tasks_since_last_schedule_tasks_(true), |
| 382 ready_to_activate_check_notifier_( | 275 ready_to_activate_check_notifier_( |
| 383 task_runner_, | 276 task_runner_, |
| 384 base::Bind(&TileManager::CheckIfReadyToActivate, | 277 base::Bind(&TileManager::CheckIfReadyToActivate, |
| 385 base::Unretained(this))) { | 278 base::Unretained(this))) { |
| 386 rasterizer_->SetClient(this); | 279 rasterizer_->SetClient(this); |
| 387 } | 280 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 401 // This should finish all pending tasks and release any uninitialized | 294 // This should finish all pending tasks and release any uninitialized |
| 402 // resources. | 295 // resources. |
| 403 rasterizer_->Shutdown(); | 296 rasterizer_->Shutdown(); |
| 404 rasterizer_->CheckForCompletedTasks(); | 297 rasterizer_->CheckForCompletedTasks(); |
| 405 | 298 |
| 406 DCHECK_EQ(0u, bytes_releasable_); | 299 DCHECK_EQ(0u, bytes_releasable_); |
| 407 DCHECK_EQ(0u, resources_releasable_); | 300 DCHECK_EQ(0u, resources_releasable_); |
| 408 } | 301 } |
| 409 | 302 |
| 410 void TileManager::Release(Tile* tile) { | 303 void TileManager::Release(Tile* tile) { |
| 411 prioritized_tiles_dirty_ = true; | |
| 412 released_tiles_.push_back(tile); | 304 released_tiles_.push_back(tile); |
| 413 } | 305 } |
| 414 | 306 |
| 415 void TileManager::DidChangeTilePriority(Tile* tile) { | |
| 416 prioritized_tiles_dirty_ = true; | |
| 417 } | |
| 418 | |
| 419 bool TileManager::ShouldForceTasksRequiredForActivationToComplete() const { | 307 bool TileManager::ShouldForceTasksRequiredForActivationToComplete() const { |
| 420 return global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY; | 308 return global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY; |
| 421 } | 309 } |
| 422 | 310 |
| 423 void TileManager::CleanUpReleasedTiles() { | 311 void TileManager::CleanUpReleasedTiles() { |
| 424 for (std::vector<Tile*>::iterator it = released_tiles_.begin(); | 312 for (std::vector<Tile*>::iterator it = released_tiles_.begin(); |
| 425 it != released_tiles_.end(); | 313 it != released_tiles_.end(); |
| 426 ++it) { | 314 ++it) { |
| 427 Tile* tile = *it; | 315 Tile* tile = *it; |
| 428 ManagedTileState& mts = tile->managed_state(); | 316 ManagedTileState& mts = tile->managed_state(); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 442 used_layer_counts_.erase(layer_it); | 330 used_layer_counts_.erase(layer_it); |
| 443 image_decode_tasks_.erase(tile->layer_id()); | 331 image_decode_tasks_.erase(tile->layer_id()); |
| 444 } | 332 } |
| 445 | 333 |
| 446 delete tile; | 334 delete tile; |
| 447 } | 335 } |
| 448 | 336 |
| 449 released_tiles_.clear(); | 337 released_tiles_.clear(); |
| 450 } | 338 } |
| 451 | 339 |
| 452 void TileManager::UpdatePrioritizedTileSetIfNeeded() { | |
| 453 if (!prioritized_tiles_dirty_) | |
| 454 return; | |
| 455 | |
| 456 CleanUpReleasedTiles(); | |
| 457 | |
| 458 prioritized_tiles_.Clear(); | |
| 459 GetTilesWithAssignedBins(&prioritized_tiles_); | |
| 460 prioritized_tiles_dirty_ = false; | |
| 461 } | |
| 462 | |
| 463 void TileManager::DidFinishRunningTasks() { | 340 void TileManager::DidFinishRunningTasks() { |
| 464 TRACE_EVENT0("cc", "TileManager::DidFinishRunningTasks"); | 341 TRACE_EVENT0("cc", "TileManager::DidFinishRunningTasks"); |
| 465 | 342 |
| 466 bool memory_usage_above_limit = resource_pool_->total_memory_usage_bytes() > | 343 bool memory_usage_above_limit = resource_pool_->total_memory_usage_bytes() > |
| 467 global_state_.soft_memory_limit_in_bytes; | 344 global_state_.soft_memory_limit_in_bytes; |
| 468 | 345 |
| 469 // When OOM, keep re-assigning memory until we reach a steady state | 346 // When OOM, keep re-assigning memory until we reach a steady state |
| 470 // where top-priority tiles are initialized. | 347 // where top-priority tiles are initialized. |
| 471 if (all_tiles_that_need_to_be_rasterized_have_memory_ && | 348 if (all_tiles_that_need_to_be_rasterized_have_memory_ && |
| 472 !memory_usage_above_limit) | 349 !memory_usage_above_limit) |
| 473 return; | 350 return; |
| 474 | 351 |
| 475 rasterizer_->CheckForCompletedTasks(); | 352 rasterizer_->CheckForCompletedTasks(); |
| 476 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 353 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
| 477 | 354 |
| 478 TileVector tiles_that_need_to_be_rasterized; | 355 TileVector tiles_that_need_to_be_rasterized; |
| 479 AssignGpuMemoryToTiles(&prioritized_tiles_, | 356 AssignGpuMemoryToTiles(&tiles_that_need_to_be_rasterized); |
| 480 &tiles_that_need_to_be_rasterized); | |
| 481 | 357 |
| 482 // |tiles_that_need_to_be_rasterized| will be empty when we reach a | 358 // |tiles_that_need_to_be_rasterized| will be empty when we reach a |
| 483 // steady memory state. Keep scheduling tasks until we reach this state. | 359 // steady memory state. Keep scheduling tasks until we reach this state. |
| 484 if (!tiles_that_need_to_be_rasterized.empty()) { | 360 if (!tiles_that_need_to_be_rasterized.empty()) { |
| 485 ScheduleTasks(tiles_that_need_to_be_rasterized); | 361 ScheduleTasks(tiles_that_need_to_be_rasterized); |
| 486 return; | 362 return; |
| 487 } | 363 } |
| 488 | 364 |
| 489 resource_pool_->ReduceResourceUsage(); | 365 resource_pool_->ReduceResourceUsage(); |
| 490 | 366 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 511 tile_version.set_rasterize_on_demand(); | 387 tile_version.set_rasterize_on_demand(); |
| 512 client_->NotifyTileStateChanged(tile); | 388 client_->NotifyTileStateChanged(tile); |
| 513 } | 389 } |
| 514 } | 390 } |
| 515 | 391 |
| 516 DCHECK(IsReadyToActivate()); | 392 DCHECK(IsReadyToActivate()); |
| 517 ready_to_activate_check_notifier_.Schedule(); | 393 ready_to_activate_check_notifier_.Schedule(); |
| 518 } | 394 } |
| 519 | 395 |
| 520 void TileManager::DidFinishRunningTasksRequiredForActivation() { | 396 void TileManager::DidFinishRunningTasksRequiredForActivation() { |
| 521 // This is only a true indication that all tiles required for | |
| 522 // activation are initialized when no tiles are OOM. We need to | |
| 523 // wait for DidFinishRunningTasks() to be called, try to re-assign | |
| 524 // memory and in worst case use on-demand raster when tiles | |
| 525 // required for activation are OOM. | |
| 526 if (!all_tiles_required_for_activation_have_memory_) | |
| 527 return; | |
| 528 | |
| 529 ready_to_activate_check_notifier_.Schedule(); | 397 ready_to_activate_check_notifier_.Schedule(); |
| 530 } | 398 } |
| 531 | 399 |
| 532 void TileManager::GetTilesWithAssignedBins(PrioritizedTileSet* tiles) { | |
| 533 TRACE_EVENT0("cc", "TileManager::GetTilesWithAssignedBins"); | |
| 534 | |
| 535 // Compute new stats to be return by GetMemoryStats(). | |
| 536 memory_required_bytes_ = 0; | |
| 537 memory_nice_to_have_bytes_ = 0; | |
| 538 | |
| 539 const TileMemoryLimitPolicy memory_policy = global_state_.memory_limit_policy; | |
| 540 const TreePriority tree_priority = global_state_.tree_priority; | |
| 541 | |
| 542 // For each tree, bin into different categories of tiles. | |
| 543 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | |
| 544 Tile* tile = it->second; | |
| 545 ManagedTileState& mts = tile->managed_state(); | |
| 546 | |
| 547 const ManagedTileState::TileVersion& tile_version = | |
| 548 tile->GetTileVersionForDrawing(); | |
| 549 bool tile_is_ready_to_draw = tile_version.IsReadyToDraw(); | |
| 550 bool tile_is_active = tile_is_ready_to_draw || | |
| 551 mts.tile_versions[mts.raster_mode].raster_task_; | |
| 552 | |
| 553 // Get the active priority and bin. | |
| 554 TilePriority active_priority = tile->priority(ACTIVE_TREE); | |
| 555 ManagedTileBin active_bin = BinFromTilePriority(active_priority); | |
| 556 | |
| 557 // Get the pending priority and bin. | |
| 558 TilePriority pending_priority = tile->priority(PENDING_TREE); | |
| 559 ManagedTileBin pending_bin = BinFromTilePriority(pending_priority); | |
| 560 | |
| 561 bool pending_is_low_res = pending_priority.resolution == LOW_RESOLUTION; | |
| 562 bool pending_is_non_ideal = | |
| 563 pending_priority.resolution == NON_IDEAL_RESOLUTION; | |
| 564 bool active_is_non_ideal = | |
| 565 active_priority.resolution == NON_IDEAL_RESOLUTION; | |
| 566 | |
| 567 // Adjust bin state based on if ready to draw. | |
| 568 active_bin = kBinReadyToDrawMap[tile_is_ready_to_draw][active_bin]; | |
| 569 pending_bin = kBinReadyToDrawMap[tile_is_ready_to_draw][pending_bin]; | |
| 570 | |
| 571 // Adjust bin state based on if active. | |
| 572 active_bin = kBinIsActiveMap[tile_is_active][active_bin]; | |
| 573 pending_bin = kBinIsActiveMap[tile_is_active][pending_bin]; | |
| 574 | |
| 575 // We never want to paint new non-ideal tiles, as we always have | |
| 576 // a high-res tile covering that content (paint that instead). | |
| 577 if (!tile_is_ready_to_draw && active_is_non_ideal) | |
| 578 active_bin = NEVER_BIN; | |
| 579 if (!tile_is_ready_to_draw && pending_is_non_ideal) | |
| 580 pending_bin = NEVER_BIN; | |
| 581 | |
| 582 if (!tile_is_ready_to_draw || tile_version.requires_resource()) { | |
| 583 // The bin that the tile would have if the GPU memory manager had | |
| 584 // a maximally permissive policy, send to the GPU memory manager | |
| 585 // to determine policy. | |
| 586 ManagedTileBin gpu_memmgr_stats_bin = std::min(active_bin, pending_bin); | |
| 587 if ((gpu_memmgr_stats_bin == NOW_BIN) || | |
| 588 (gpu_memmgr_stats_bin == NOW_AND_READY_TO_DRAW_BIN)) | |
| 589 memory_required_bytes_ += BytesConsumedIfAllocated(tile); | |
| 590 if (gpu_memmgr_stats_bin != NEVER_BIN) | |
| 591 memory_nice_to_have_bytes_ += BytesConsumedIfAllocated(tile); | |
| 592 } | |
| 593 | |
| 594 ManagedTileBin tree_bin[NUM_TREES]; | |
| 595 tree_bin[ACTIVE_TREE] = kBinPolicyMap[memory_policy][active_bin]; | |
| 596 tree_bin[PENDING_TREE] = kBinPolicyMap[memory_policy][pending_bin]; | |
| 597 | |
| 598 // Adjust pending bin state for low res tiles. This prevents pending tree | |
| 599 // low-res tiles from being initialized before high-res tiles. | |
| 600 if (pending_is_low_res) | |
| 601 tree_bin[PENDING_TREE] = std::max(tree_bin[PENDING_TREE], EVENTUALLY_BIN); | |
| 602 | |
| 603 TilePriority tile_priority; | |
| 604 switch (tree_priority) { | |
| 605 case SAME_PRIORITY_FOR_BOTH_TREES: | |
| 606 mts.bin = std::min(tree_bin[ACTIVE_TREE], tree_bin[PENDING_TREE]); | |
| 607 tile_priority = tile->combined_priority(); | |
| 608 break; | |
| 609 case SMOOTHNESS_TAKES_PRIORITY: | |
| 610 mts.bin = tree_bin[ACTIVE_TREE]; | |
| 611 tile_priority = active_priority; | |
| 612 break; | |
| 613 case NEW_CONTENT_TAKES_PRIORITY: | |
| 614 mts.bin = tree_bin[PENDING_TREE]; | |
| 615 tile_priority = pending_priority; | |
| 616 break; | |
| 617 } | |
| 618 | |
| 619 // Bump up the priority if we determined it's NEVER_BIN on one tree, | |
| 620 // but is still required on the other tree. | |
| 621 bool is_in_never_bin_on_both_trees = tree_bin[ACTIVE_TREE] == NEVER_BIN && | |
| 622 tree_bin[PENDING_TREE] == NEVER_BIN; | |
| 623 | |
| 624 if (mts.bin == NEVER_BIN && !is_in_never_bin_on_both_trees) | |
| 625 mts.bin = tile_is_active ? AT_LAST_AND_ACTIVE_BIN : AT_LAST_BIN; | |
| 626 | |
| 627 mts.resolution = tile_priority.resolution; | |
| 628 mts.priority_bin = tile_priority.priority_bin; | |
| 629 mts.distance_to_visible = tile_priority.distance_to_visible; | |
| 630 mts.required_for_activation = tile_priority.required_for_activation; | |
| 631 | |
| 632 mts.visible_and_ready_to_draw = | |
| 633 tree_bin[ACTIVE_TREE] == NOW_AND_READY_TO_DRAW_BIN; | |
| 634 | |
| 635 // Tiles that are required for activation shouldn't be in NEVER_BIN unless | |
| 636 // smoothness takes priority or memory policy allows nothing to be | |
| 637 // initialized. | |
| 638 DCHECK(!mts.required_for_activation || mts.bin != NEVER_BIN || | |
| 639 tree_priority == SMOOTHNESS_TAKES_PRIORITY || | |
| 640 memory_policy == ALLOW_NOTHING); | |
| 641 | |
| 642 // If the tile is in NEVER_BIN and it does not have an active task, then we | |
| 643 // can release the resources early. If it does have the task however, we | |
| 644 // should keep it in the prioritized tile set to ensure that AssignGpuMemory | |
| 645 // can visit it. | |
| 646 if (mts.bin == NEVER_BIN && | |
| 647 !mts.tile_versions[mts.raster_mode].raster_task_) { | |
| 648 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile); | |
| 649 continue; | |
| 650 } | |
| 651 | |
| 652 // Insert the tile into a priority set. | |
| 653 tiles->InsertTile(tile, mts.bin); | |
| 654 } | |
| 655 } | |
| 656 | |
| 657 void TileManager::ManageTiles(const GlobalStateThatImpactsTilePriority& state) { | 400 void TileManager::ManageTiles(const GlobalStateThatImpactsTilePriority& state) { |
| 658 TRACE_EVENT0("cc", "TileManager::ManageTiles"); | 401 TRACE_EVENT0("cc", "TileManager::ManageTiles"); |
| 659 | 402 |
| 660 // Update internal state. | 403 // Update internal state. |
| 661 if (state != global_state_) { | 404 global_state_ = state; |
| 662 global_state_ = state; | 405 |
| 663 prioritized_tiles_dirty_ = true; | 406 // TODO(vmpstr): See if we still need to keep tiles alive when layers release |
| 664 } | 407 // them. |
| 408 CleanUpReleasedTiles(); | |
| 665 | 409 |
| 666 // We need to call CheckForCompletedTasks() once in-between each call | 410 // We need to call CheckForCompletedTasks() once in-between each call |
| 667 // to ScheduleTasks() to prevent canceled tasks from being scheduled. | 411 // to ScheduleTasks() to prevent canceled tasks from being scheduled. |
| 668 if (!did_check_for_completed_tasks_since_last_schedule_tasks_) { | 412 if (!did_check_for_completed_tasks_since_last_schedule_tasks_) { |
| 669 rasterizer_->CheckForCompletedTasks(); | 413 rasterizer_->CheckForCompletedTasks(); |
| 670 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 414 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
| 671 } | 415 } |
| 672 | 416 |
| 673 UpdatePrioritizedTileSetIfNeeded(); | |
| 674 | |
| 675 TileVector tiles_that_need_to_be_rasterized; | 417 TileVector tiles_that_need_to_be_rasterized; |
| 676 AssignGpuMemoryToTiles(&prioritized_tiles_, | 418 AssignGpuMemoryToTiles(&tiles_that_need_to_be_rasterized); |
| 677 &tiles_that_need_to_be_rasterized); | |
| 678 | 419 |
| 679 // Finally, schedule rasterizer tasks. | 420 // Finally, schedule rasterizer tasks. |
| 680 ScheduleTasks(tiles_that_need_to_be_rasterized); | 421 ScheduleTasks(tiles_that_need_to_be_rasterized); |
| 681 | 422 |
| 682 TRACE_EVENT_INSTANT1("cc", | 423 TRACE_EVENT_INSTANT1("cc", |
| 683 "DidManage", | 424 "DidManage", |
| 684 TRACE_EVENT_SCOPE_THREAD, | 425 TRACE_EVENT_SCOPE_THREAD, |
| 685 "state", | 426 "state", |
| 686 TracedValue::FromValue(BasicStateAsValue().release())); | 427 TracedValue::FromValue(BasicStateAsValue().release())); |
| 687 | 428 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 709 | 450 |
| 710 bool did_initialize_visible_tile = did_initialize_visible_tile_; | 451 bool did_initialize_visible_tile = did_initialize_visible_tile_; |
| 711 did_initialize_visible_tile_ = false; | 452 did_initialize_visible_tile_ = false; |
| 712 return did_initialize_visible_tile; | 453 return did_initialize_visible_tile; |
| 713 } | 454 } |
| 714 | 455 |
| 715 void TileManager::GetMemoryStats(size_t* memory_required_bytes, | 456 void TileManager::GetMemoryStats(size_t* memory_required_bytes, |
| 716 size_t* memory_nice_to_have_bytes, | 457 size_t* memory_nice_to_have_bytes, |
| 717 size_t* memory_allocated_bytes, | 458 size_t* memory_allocated_bytes, |
| 718 size_t* memory_used_bytes) const { | 459 size_t* memory_used_bytes) const { |
| 719 *memory_required_bytes = memory_required_bytes_; | 460 *memory_required_bytes = resource_pool_->total_memory_usage_bytes() + |
| 720 *memory_nice_to_have_bytes = memory_nice_to_have_bytes_; | 461 bytes_required_but_not_allocated_; |
| 462 *memory_nice_to_have_bytes = resource_pool_->total_memory_usage_bytes() + | |
| 463 bytes_required_but_not_allocated_; | |
| 721 *memory_allocated_bytes = resource_pool_->total_memory_usage_bytes(); | 464 *memory_allocated_bytes = resource_pool_->total_memory_usage_bytes(); |
| 722 *memory_used_bytes = resource_pool_->acquired_memory_usage_bytes(); | 465 *memory_used_bytes = resource_pool_->acquired_memory_usage_bytes(); |
| 723 } | 466 } |
| 724 | 467 |
| 725 scoped_ptr<base::Value> TileManager::BasicStateAsValue() const { | 468 scoped_ptr<base::Value> TileManager::BasicStateAsValue() const { |
| 726 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 469 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
| 727 state->SetInteger("tile_count", tiles_.size()); | 470 state->SetInteger("tile_count", tiles_.size()); |
| 728 state->Set("global_state", global_state_.AsValue().release()); | 471 state->Set("global_state", global_state_.AsValue().release()); |
| 729 state->Set("memory_requirements", GetMemoryRequirementsAsValue().release()); | 472 state->Set("memory_requirements", GetMemoryRequirementsAsValue().release()); |
| 730 return state.PassAs<base::Value>(); | 473 return state.PassAs<base::Value>(); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 750 &memory_allocated_bytes, | 493 &memory_allocated_bytes, |
| 751 &memory_used_bytes); | 494 &memory_used_bytes); |
| 752 requirements->SetInteger("memory_required_bytes", memory_required_bytes); | 495 requirements->SetInteger("memory_required_bytes", memory_required_bytes); |
| 753 requirements->SetInteger("memory_nice_to_have_bytes", | 496 requirements->SetInteger("memory_nice_to_have_bytes", |
| 754 memory_nice_to_have_bytes); | 497 memory_nice_to_have_bytes); |
| 755 requirements->SetInteger("memory_allocated_bytes", memory_allocated_bytes); | 498 requirements->SetInteger("memory_allocated_bytes", memory_allocated_bytes); |
| 756 requirements->SetInteger("memory_used_bytes", memory_used_bytes); | 499 requirements->SetInteger("memory_used_bytes", memory_used_bytes); |
| 757 return requirements.PassAs<base::Value>(); | 500 return requirements.PassAs<base::Value>(); |
| 758 } | 501 } |
| 759 | 502 |
| 503 bool TileManager::FreeTileResourcesUntilUsageIsWithinLimit( | |
| 504 EvictionTileIterator* eviction_iterator, | |
|
reveman
2014/06/17 17:15:08
nit: this could just be named iterator, iter or it
vmpstr
2014/06/17 18:23:22
Done.
| |
| 505 const MemoryUsage& limit, | |
| 506 const TilePriority& max_priority, | |
| 507 bool evict_unconditionally, | |
|
reveman
2014/06/17 17:15:08
I think this would be cleaner if you split this in
vmpstr
2014/06/17 18:23:22
Done.
| |
| 508 MemoryUsage* usage) { | |
| 509 while (usage->Exceeds(limit)) { | |
| 510 if (!*eviction_iterator) | |
| 511 return false; | |
| 512 | |
| 513 Tile* eviction_tile = **eviction_iterator; | |
|
reveman
2014/06/17 17:15:08
nit: simply |tile| would be fine unless you prefer
vmpstr
2014/06/17 18:23:22
Done.
| |
| 514 DCHECK(eviction_tile); | |
|
reveman
2014/06/17 17:15:08
nit: maybe move this DCHECK into the iterator as a
vmpstr
2014/06/17 18:23:22
This was a carryover from debugging, removed.
| |
| 515 | |
| 516 TilePriority eviction_priority = | |
|
reveman
2014/06/17 17:15:08
nit: do you need this temporary variable? I think
vmpstr
2014/06/17 18:23:22
Done.
| |
| 517 eviction_tile->priority_for_tree_priority(global_state_.tree_priority); | |
| 518 | |
| 519 if (!evict_unconditionally && | |
| 520 !max_priority.IsHigherPriorityThan(eviction_priority)) | |
| 521 return false; | |
| 522 | |
| 523 *usage -= TileMemoryUsage(eviction_tile); | |
| 524 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(eviction_tile); | |
| 525 ++(*eviction_iterator); | |
| 526 } | |
| 527 return true; | |
| 528 } | |
| 529 | |
| 530 bool TileManager::TilePriorityViolatesMemoryPolicy( | |
| 531 const TilePriority& priority) { | |
| 532 switch (global_state_.memory_limit_policy) { | |
| 533 case ALLOW_NOTHING: | |
| 534 return true; | |
| 535 case ALLOW_ABSOLUTE_MINIMUM: | |
| 536 return priority.priority_bin > TilePriority::NOW; | |
| 537 case ALLOW_PREPAINT_ONLY: | |
| 538 return priority.priority_bin > TilePriority::SOON; | |
| 539 case ALLOW_ANYTHING: | |
| 540 return priority.distance_to_visible == | |
| 541 std::numeric_limits<float>::infinity(); | |
| 542 } | |
| 543 NOTREACHED(); | |
| 544 return true; | |
| 545 } | |
| 546 | |
| 760 void TileManager::AssignGpuMemoryToTiles( | 547 void TileManager::AssignGpuMemoryToTiles( |
| 761 PrioritizedTileSet* tiles, | |
| 762 TileVector* tiles_that_need_to_be_rasterized) { | 548 TileVector* tiles_that_need_to_be_rasterized) { |
| 763 TRACE_EVENT0("cc", "TileManager::AssignGpuMemoryToTiles"); | 549 TRACE_EVENT0("cc", "TileManager::AssignGpuMemoryToTiles"); |
| 764 | 550 |
| 765 // Maintain the list of released resources that can potentially be re-used | 551 // Maintain the list of released resources that can potentially be re-used |
| 766 // or deleted. | 552 // or deleted. |
| 767 // If this operation becomes expensive too, only do this after some | 553 // If this operation becomes expensive too, only do this after some |
| 768 // resource(s) was returned. Note that in that case, one also need to | 554 // resource(s) was returned. Note that in that case, one also need to |
| 769 // invalidate when releasing some resource from the pool. | 555 // invalidate when releasing some resource from the pool. |
| 770 resource_pool_->CheckBusyResources(); | 556 resource_pool_->CheckBusyResources(); |
| 771 | 557 |
| 772 // Now give memory out to the tiles until we're out, and build | 558 // Now give memory out to the tiles until we're out, and build |
| 773 // the needs-to-be-rasterized queue. | 559 // the needs-to-be-rasterized queue. |
| 774 all_tiles_that_need_to_be_rasterized_have_memory_ = true; | 560 all_tiles_that_need_to_be_rasterized_have_memory_ = true; |
| 775 all_tiles_required_for_activation_have_memory_ = true; | |
| 776 | 561 |
| 777 // Cast to prevent overflow. | 562 MemoryUsage hard_memory_limit(global_state_.hard_memory_limit_in_bytes, |
| 778 int64 soft_bytes_available = | 563 global_state_.num_resources_limit); |
| 779 static_cast<int64>(bytes_releasable_) + | 564 MemoryUsage soft_memory_limit(global_state_.soft_memory_limit_in_bytes, |
| 780 static_cast<int64>(global_state_.soft_memory_limit_in_bytes) - | 565 global_state_.num_resources_limit); |
|
reveman
2014/06/17 17:15:08
You can use "const" here. I don't care much if you
vmpstr
2014/06/17 18:23:22
I removed the other const. I kind of prefer it wit
| |
| 781 static_cast<int64>(resource_pool_->acquired_memory_usage_bytes()); | 566 MemoryUsage memory_usage(resource_pool_->acquired_memory_usage_bytes(), |
| 782 int64 hard_bytes_available = | 567 resource_pool_->acquired_resource_count()); |
| 783 static_cast<int64>(bytes_releasable_) + | 568 MemoryUsage initial_memory_usage = memory_usage; |
| 784 static_cast<int64>(global_state_.hard_memory_limit_in_bytes) - | 569 |
| 785 static_cast<int64>(resource_pool_->acquired_memory_usage_bytes()); | 570 EvictionTileIterator eviction_it(this, global_state_.tree_priority); |
| 786 int resources_available = resources_releasable_ + | 571 |
| 787 global_state_.num_resources_limit - | 572 FreeTileResourcesUntilUsageIsWithinLimit( |
| 788 resource_pool_->acquired_resource_count(); | 573 &eviction_it, hard_memory_limit, TilePriority(), true, &memory_usage); |
| 789 size_t soft_bytes_allocatable = | |
| 790 std::max(static_cast<int64>(0), soft_bytes_available); | |
| 791 size_t hard_bytes_allocatable = | |
| 792 std::max(static_cast<int64>(0), hard_bytes_available); | |
| 793 size_t resources_allocatable = std::max(0, resources_available); | |
| 794 | 574 |
| 795 size_t bytes_that_exceeded_memory_budget = 0; | 575 size_t bytes_that_exceeded_memory_budget = 0; |
| 796 size_t soft_bytes_left = soft_bytes_allocatable; | |
| 797 size_t hard_bytes_left = hard_bytes_allocatable; | |
| 798 | 576 |
| 799 size_t resources_left = resources_allocatable; | |
| 800 bool oomed_soft = false; | 577 bool oomed_soft = false; |
| 801 bool oomed_hard = false; | 578 bool oomed_hard = false; |
| 802 bool have_hit_soft_memory = false; // Soft memory comes after hard. | 579 bool have_hit_soft_memory = false; // Soft memory comes after hard. |
| 803 | 580 |
| 804 unsigned schedule_priority = 1u; | 581 unsigned schedule_priority = 1u; |
| 805 for (PrioritizedTileSet::Iterator it(tiles, true); it; ++it) { | 582 RasterTileIterator it(this, global_state_.tree_priority); |
| 583 for (; it; ++it) { | |
| 806 Tile* tile = *it; | 584 Tile* tile = *it; |
| 585 TilePriority priority = | |
| 586 tile->priority_for_tree_priority(global_state_.tree_priority); | |
| 587 | |
| 588 if (TilePriorityViolatesMemoryPolicy(priority)) | |
| 589 break; | |
| 590 | |
| 807 ManagedTileState& mts = tile->managed_state(); | 591 ManagedTileState& mts = tile->managed_state(); |
| 808 | 592 |
| 809 mts.scheduled_priority = schedule_priority++; | 593 mts.scheduled_priority = schedule_priority++; |
| 810 | 594 |
| 811 mts.raster_mode = tile->DetermineOverallRasterMode(); | 595 mts.raster_mode = tile->DetermineOverallRasterMode(); |
| 812 | 596 |
| 813 ManagedTileState::TileVersion& tile_version = | 597 ManagedTileState::TileVersion& tile_version = |
| 814 mts.tile_versions[mts.raster_mode]; | 598 mts.tile_versions[mts.raster_mode]; |
| 815 | 599 |
| 816 // If this tile doesn't need a resource, then nothing to do. | 600 // If this tile version is ready to draw, then nothing to do. |
| 817 if (!tile_version.requires_resource()) | 601 if (tile_version.IsReadyToDraw()) |
|
reveman
2014/06/17 17:15:08
Why would the iterator return a tile that is alrea
vmpstr
2014/06/17 18:23:22
Done.
| |
| 818 continue; | 602 continue; |
| 819 | 603 |
| 820 // If the tile is not needed, free it up. | 604 const bool tile_uses_hard_limit = |
| 821 if (mts.bin == NEVER_BIN) { | 605 priority.priority_bin == TilePriority::NOW; |
| 822 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile); | 606 MemoryUsage& memory_limit = |
| 823 continue; | 607 tile_uses_hard_limit ? hard_memory_limit : soft_memory_limit; |
| 824 } | |
| 825 | |
| 826 const bool tile_uses_hard_limit = mts.bin <= NOW_BIN; | |
| 827 const size_t bytes_if_allocated = BytesConsumedIfAllocated(tile); | 608 const size_t bytes_if_allocated = BytesConsumedIfAllocated(tile); |
| 828 const size_t tile_bytes_left = | |
| 829 (tile_uses_hard_limit) ? hard_bytes_left : soft_bytes_left; | |
| 830 | 609 |
| 831 // Hard-limit is reserved for tiles that would cause a calamity | 610 // Hard-limit is reserved for tiles that would cause a calamity |
| 832 // if they were to go away, so by definition they are the highest | 611 // if they were to go away, so by definition they are the highest |
| 833 // priority memory, and must be at the front of the list. | 612 // priority memory, and must be at the front of the list. |
| 834 DCHECK(!(have_hit_soft_memory && tile_uses_hard_limit)); | 613 DCHECK(!(have_hit_soft_memory && tile_uses_hard_limit)); |
| 835 have_hit_soft_memory |= !tile_uses_hard_limit; | 614 have_hit_soft_memory |= !tile_uses_hard_limit; |
| 836 | 615 |
| 837 size_t tile_bytes = 0; | 616 MemoryUsage tile_usage = TileMemoryUsage(tile); |
| 838 size_t tile_resources = 0; | |
| 839 | 617 |
| 840 // It costs to maintain a resource. | 618 // If we don't have the required version, and it's not in flight |
| 841 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { | 619 // then we'll have to pay to create a new task. |
| 842 if (mts.tile_versions[mode].resource_) { | 620 if (!tile_version.resource_ && !tile_version.raster_task_) |
| 843 tile_bytes += bytes_if_allocated; | 621 tile_usage += MemoryUsage(bytes_if_allocated, 1); |
| 844 tile_resources++; | |
| 845 } | |
| 846 } | |
| 847 | 622 |
| 848 // Allow lower priority tiles with initialized resources to keep | 623 // Handle OOM tiles. |
| 849 // their memory by only assigning memory to new raster tasks if | 624 bool memory_reduced_successfully = |
| 850 // they can be scheduled. | 625 FreeTileResourcesUntilUsageIsWithinLimit(&eviction_it, |
| 851 bool reached_scheduled_raster_tasks_limit = | 626 memory_limit - tile_usage, |
| 852 tiles_that_need_to_be_rasterized->size() >= kScheduledRasterTasksLimit; | 627 priority, |
| 853 if (!reached_scheduled_raster_tasks_limit) { | 628 false, |
| 854 // If we don't have the required version, and it's not in flight | 629 &memory_usage); |
| 855 // then we'll have to pay to create a new task. | |
| 856 if (!tile_version.resource_ && !tile_version.raster_task_) { | |
| 857 tile_bytes += bytes_if_allocated; | |
| 858 tile_resources++; | |
| 859 } | |
| 860 } | |
| 861 | 630 |
| 862 // Tile is OOM. | 631 // Tile is still OOM. |
| 863 if (tile_bytes > tile_bytes_left || tile_resources > resources_left) { | 632 if (!memory_reduced_successfully) { |
| 864 bool was_ready_to_draw = tile->IsReadyToDraw(); | 633 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile); |
|
reveman
2014/06/17 17:15:08
It seems wrong to have to release resources here w
vmpstr
2014/06/17 18:23:22
Hmm. Initially this was here because of tile versi
| |
| 865 | |
| 866 FreeResourcesForTile(tile); | |
| 867 | 634 |
| 868 // This tile was already on screen and now its resources have been | 635 // This tile was already on screen and now its resources have been |
| 869 // released. In order to prevent checkerboarding, set this tile as | 636 // released. In order to prevent checkerboarding, set this tile as |
| 870 // rasterize on demand immediately. | 637 // rasterize on demand immediately. |
| 871 if (mts.visible_and_ready_to_draw) | 638 if (mts.visible_and_ready_to_draw) |
| 872 tile_version.set_rasterize_on_demand(); | 639 tile_version.set_rasterize_on_demand(); |
| 873 | 640 |
| 874 if (was_ready_to_draw) | |
| 875 client_->NotifyTileStateChanged(tile); | |
| 876 | |
| 877 oomed_soft = true; | 641 oomed_soft = true; |
| 878 if (tile_uses_hard_limit) { | 642 if (tile_uses_hard_limit) { |
| 879 oomed_hard = true; | 643 oomed_hard = true; |
| 880 bytes_that_exceeded_memory_budget += tile_bytes; | 644 bytes_that_exceeded_memory_budget += tile_usage.memory_bytes(); |
| 881 } | 645 } |
| 882 } else { | 646 } else { |
| 883 resources_left -= tile_resources; | 647 memory_usage += tile_usage; |
| 884 hard_bytes_left -= tile_bytes; | |
| 885 soft_bytes_left = | |
| 886 (soft_bytes_left > tile_bytes) ? soft_bytes_left - tile_bytes : 0; | |
| 887 if (tile_version.resource_) | 648 if (tile_version.resource_) |
| 888 continue; | 649 continue; |
| 889 } | 650 } |
| 890 | 651 |
| 891 DCHECK(!tile_version.resource_); | 652 DCHECK(!tile_version.resource_); |
| 892 | 653 |
| 893 // Tile shouldn't be rasterized if |tiles_that_need_to_be_rasterized| | 654 // Tile shouldn't be rasterized if |tiles_that_need_to_be_rasterized| |
| 894 // has reached it's limit or we've failed to assign gpu memory to this | 655 // has reached it's limit or we've failed to assign gpu memory to this |
| 895 // or any higher priority tile. Preventing tiles that fit into memory | 656 // or any higher priority tile. Preventing tiles that fit into memory |
| 896 // budget to be rasterized when higher priority tile is oom is | 657 // budget to be rasterized when higher priority tile is oom is |
| 897 // important for two reasons: | 658 // important for two reasons: |
| 898 // 1. Tile size should not impact raster priority. | 659 // 1. Tile size should not impact raster priority. |
| 899 // 2. Tiles with existing raster task could otherwise incorrectly | 660 // 2. Tiles with existing raster task could otherwise incorrectly |
| 900 // be added as they are not affected by |bytes_allocatable|. | 661 // be added as they are not affected by |bytes_allocatable|. |
| 901 bool can_schedule_tile = | 662 bool can_schedule_tile = |
| 902 !oomed_soft && !reached_scheduled_raster_tasks_limit; | 663 !oomed_soft && |
| 664 tiles_that_need_to_be_rasterized->size() < kScheduledRasterTasksLimit; | |
| 903 | 665 |
| 904 if (!can_schedule_tile) { | 666 if (!can_schedule_tile) { |
| 905 all_tiles_that_need_to_be_rasterized_have_memory_ = false; | 667 all_tiles_that_need_to_be_rasterized_have_memory_ = false; |
| 906 if (tile->required_for_activation()) | 668 break; |
| 907 all_tiles_required_for_activation_have_memory_ = false; | |
| 908 it.DisablePriorityOrdering(); | |
| 909 continue; | |
| 910 } | 669 } |
| 911 | 670 |
| 912 tiles_that_need_to_be_rasterized->push_back(tile); | 671 tiles_that_need_to_be_rasterized->push_back(tile); |
| 913 } | 672 } |
| 914 | 673 |
| 674 // Count up the memory that would be required on top of the allocated memory | |
| 675 // in order to initialize all visible tiles. | |
| 676 // TODO(vmpstr): Remove this once the memory manager doesn't need required | |
| 677 // bytes. | |
| 678 bytes_required_but_not_allocated_ = 0; | |
| 679 for (; it; ++it) { | |
| 680 Tile* tile = *it; | |
| 681 TilePriority priority = | |
| 682 tile->priority_for_tree_priority(global_state_.tree_priority); | |
| 683 | |
| 684 if (TilePriorityViolatesMemoryPolicy(priority) || | |
| 685 priority.priority_bin != TilePriority::NOW) | |
| 686 break; | |
| 687 | |
| 688 ManagedTileState& mts = tile->managed_state(); | |
| 689 mts.raster_mode = tile->DetermineOverallRasterMode(); | |
| 690 | |
| 691 ManagedTileState::TileVersion& tile_version = | |
| 692 mts.tile_versions[mts.raster_mode]; | |
| 693 | |
| 694 // If this tile version is ready to draw, then nothing to do. | |
| 695 if (tile_version.IsReadyToDraw()) | |
| 696 continue; | |
| 697 | |
| 698 bytes_required_but_not_allocated_ += BytesConsumedIfAllocated(tile); | |
| 699 } | |
| 700 | |
| 915 // OOM reporting uses hard-limit, soft-OOM is normal depending on limit. | 701 // OOM reporting uses hard-limit, soft-OOM is normal depending on limit. |
| 916 ever_exceeded_memory_budget_ |= oomed_hard; | 702 ever_exceeded_memory_budget_ |= oomed_hard; |
| 917 if (ever_exceeded_memory_budget_) { | 703 if (ever_exceeded_memory_budget_) { |
| 918 TRACE_COUNTER_ID2("cc", | 704 TRACE_COUNTER_ID2("cc", |
| 919 "over_memory_budget", | 705 "over_memory_budget", |
| 920 this, | 706 this, |
| 921 "budget", | 707 "budget", |
| 922 global_state_.hard_memory_limit_in_bytes, | 708 global_state_.hard_memory_limit_in_bytes, |
| 923 "over", | 709 "over", |
| 924 bytes_that_exceeded_memory_budget); | 710 bytes_that_exceeded_memory_budget); |
| 925 } | 711 } |
| 926 memory_stats_from_last_assign_.total_budget_in_bytes = | 712 memory_stats_from_last_assign_.total_budget_in_bytes = |
| 927 global_state_.hard_memory_limit_in_bytes; | 713 global_state_.hard_memory_limit_in_bytes; |
| 928 memory_stats_from_last_assign_.bytes_allocated = | 714 memory_stats_from_last_assign_.bytes_allocated = |
| 929 hard_bytes_allocatable - hard_bytes_left; | 715 initial_memory_usage.memory_bytes() - memory_usage.memory_bytes(); |
|
reveman
2014/06/17 17:15:08
How about using resource_pool->acquired_mem.. here
vmpstr
2014/06/17 18:23:22
Done.
| |
| 930 memory_stats_from_last_assign_.bytes_unreleasable = | 716 memory_stats_from_last_assign_.bytes_unreleasable = |
| 931 resource_pool_->acquired_memory_usage_bytes() - bytes_releasable_; | 717 resource_pool_->acquired_memory_usage_bytes() - bytes_releasable_; |
| 932 memory_stats_from_last_assign_.bytes_over = bytes_that_exceeded_memory_budget; | 718 memory_stats_from_last_assign_.bytes_over = bytes_that_exceeded_memory_budget; |
| 933 } | 719 } |
| 934 | 720 |
| 935 void TileManager::FreeResourceForTile(Tile* tile, RasterMode mode) { | 721 void TileManager::FreeResourceForTile(Tile* tile, RasterMode mode) { |
| 936 ManagedTileState& mts = tile->managed_state(); | 722 ManagedTileState& mts = tile->managed_state(); |
| 937 if (mts.tile_versions[mode].resource_) { | 723 if (mts.tile_versions[mode].resource_) { |
| 938 resource_pool_->ReleaseResource(mts.tile_versions[mode].resource_.Pass()); | 724 resource_pool_->ReleaseResource(mts.tile_versions[mode].resource_.Pass()); |
| 939 | 725 |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1170 content_rect, | 956 content_rect, |
| 1171 opaque_rect, | 957 opaque_rect, |
| 1172 contents_scale, | 958 contents_scale, |
| 1173 layer_id, | 959 layer_id, |
| 1174 source_frame_number, | 960 source_frame_number, |
| 1175 flags)); | 961 flags)); |
| 1176 DCHECK(tiles_.find(tile->id()) == tiles_.end()); | 962 DCHECK(tiles_.find(tile->id()) == tiles_.end()); |
| 1177 | 963 |
| 1178 tiles_[tile->id()] = tile; | 964 tiles_[tile->id()] = tile; |
| 1179 used_layer_counts_[tile->layer_id()]++; | 965 used_layer_counts_[tile->layer_id()]++; |
| 1180 prioritized_tiles_dirty_ = true; | |
| 1181 return tile; | 966 return tile; |
| 1182 } | 967 } |
| 1183 | 968 |
| 1184 void TileManager::GetPairedPictureLayers( | 969 void TileManager::GetPairedPictureLayers( |
| 1185 std::vector<PairedPictureLayer>* paired_layers) const { | 970 std::vector<PairedPictureLayer>* paired_layers) const { |
| 1186 const std::vector<PictureLayerImpl*>& layers = client_->GetPictureLayers(); | 971 const std::vector<PictureLayerImpl*>& layers = client_->GetPictureLayers(); |
| 1187 | 972 |
| 1188 paired_layers->clear(); | 973 paired_layers->clear(); |
| 1189 // Reserve a maximum possible paired layers. | 974 // Reserve a maximum possible paired layers. |
| 1190 paired_layers->reserve(layers.size()); | 975 paired_layers->reserve(layers.size()); |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1623 void TileManager::CheckIfReadyToActivate() { | 1408 void TileManager::CheckIfReadyToActivate() { |
| 1624 TRACE_EVENT0("cc", "TileManager::CheckIfReadyToActivate"); | 1409 TRACE_EVENT0("cc", "TileManager::CheckIfReadyToActivate"); |
| 1625 | 1410 |
| 1626 rasterizer_->CheckForCompletedTasks(); | 1411 rasterizer_->CheckForCompletedTasks(); |
| 1627 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 1412 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
| 1628 | 1413 |
| 1629 if (IsReadyToActivate()) | 1414 if (IsReadyToActivate()) |
| 1630 client_->NotifyReadyToActivate(); | 1415 client_->NotifyReadyToActivate(); |
| 1631 } | 1416 } |
| 1632 | 1417 |
| 1418 TileManager::MemoryUsage TileManager::TileMemoryUsage(Tile* tile) { | |
| 1419 ManagedTileState& mts = tile->managed_state(); | |
| 1420 size_t bytes_consumed_if_allocated = BytesConsumedIfAllocated(tile); | |
| 1421 | |
| 1422 MemoryUsage total_usage; | |
| 1423 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { | |
| 1424 if (mts.tile_versions[mode].resource_) | |
| 1425 total_usage += MemoryUsage(bytes_consumed_if_allocated, 1); | |
| 1426 } | |
| 1427 return total_usage; | |
| 1428 } | |
| 1429 | |
| 1430 TileManager::MemoryUsage::MemoryUsage() : memory_bytes_(0), resource_count_(0) { | |
| 1431 } | |
| 1432 | |
| 1433 TileManager::MemoryUsage::MemoryUsage(int64 memory_bytes, int resource_count) | |
| 1434 : memory_bytes_(memory_bytes), resource_count_(resource_count) { | |
| 1435 } | |
| 1436 | |
| 1437 TileManager::MemoryUsage& TileManager::MemoryUsage::operator+=( | |
| 1438 const MemoryUsage& other) { | |
| 1439 memory_bytes_ += other.memory_bytes_; | |
| 1440 resource_count_ += other.resource_count_; | |
| 1441 return *this; | |
| 1442 } | |
| 1443 | |
| 1444 TileManager::MemoryUsage& TileManager::MemoryUsage::operator-=( | |
| 1445 const MemoryUsage& other) { | |
| 1446 memory_bytes_ -= other.memory_bytes_; | |
| 1447 resource_count_ -= other.resource_count_; | |
| 1448 return *this; | |
| 1449 } | |
| 1450 | |
| 1451 TileManager::MemoryUsage TileManager::MemoryUsage::operator-( | |
| 1452 const MemoryUsage& other) { | |
| 1453 MemoryUsage result = *this; | |
| 1454 result -= other; | |
| 1455 return result; | |
| 1456 } | |
| 1457 | |
| 1458 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { | |
| 1459 return memory_bytes_ > limit.memory_bytes_ || | |
| 1460 resource_count_ > limit.resource_count_; | |
| 1461 } | |
| 1462 | |
| 1633 } // namespace cc | 1463 } // namespace cc |
| OLD | NEW |