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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 skia::RefPtr<SkPixelRef> pixel_ref_; | 251 skia::RefPtr<SkPixelRef> pixel_ref_; |
| 252 int layer_id_; | 252 int layer_id_; |
| 253 RenderingStatsInstrumentation* rendering_stats_; | 253 RenderingStatsInstrumentation* rendering_stats_; |
| 254 const base::Callback<void(bool was_canceled)> reply_; | 254 const base::Callback<void(bool was_canceled)> reply_; |
| 255 | 255 |
| 256 DISALLOW_COPY_AND_ASSIGN(ImageDecodeTaskImpl); | 256 DISALLOW_COPY_AND_ASSIGN(ImageDecodeTaskImpl); |
| 257 }; | 257 }; |
| 258 | 258 |
| 259 const size_t kScheduledRasterTasksLimit = 32u; | 259 const size_t kScheduledRasterTasksLimit = 32u; |
| 260 | 260 |
| 261 // Memory limit policy works by mapping some bin states to the NEVER bin. | |
| 262 const ManagedTileBin kBinPolicyMap[NUM_TILE_MEMORY_LIMIT_POLICIES][NUM_BINS] = { | |
| 263 // [ALLOW_NOTHING] | |
| 264 {NEVER_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | |
| 265 NEVER_BIN, // [NOW_BIN] | |
| 266 NEVER_BIN, // [SOON_BIN] | |
| 267 NEVER_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | |
| 268 NEVER_BIN, // [EVENTUALLY_BIN] | |
| 269 NEVER_BIN, // [AT_LAST_AND_ACTIVE_BIN] | |
| 270 NEVER_BIN, // [AT_LAST_BIN] | |
| 271 NEVER_BIN // [NEVER_BIN] | |
| 272 }, | |
| 273 // [ALLOW_ABSOLUTE_MINIMUM] | |
| 274 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | |
| 275 NOW_BIN, // [NOW_BIN] | |
| 276 NEVER_BIN, // [SOON_BIN] | |
| 277 NEVER_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | |
| 278 NEVER_BIN, // [EVENTUALLY_BIN] | |
| 279 NEVER_BIN, // [AT_LAST_AND_ACTIVE_BIN] | |
| 280 NEVER_BIN, // [AT_LAST_BIN] | |
| 281 NEVER_BIN // [NEVER_BIN] | |
| 282 }, | |
| 283 // [ALLOW_PREPAINT_ONLY] | |
| 284 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | |
| 285 NOW_BIN, // [NOW_BIN] | |
| 286 SOON_BIN, // [SOON_BIN] | |
| 287 NEVER_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | |
| 288 NEVER_BIN, // [EVENTUALLY_BIN] | |
| 289 NEVER_BIN, // [AT_LAST_AND_ACTIVE_BIN] | |
| 290 NEVER_BIN, // [AT_LAST_BIN] | |
| 291 NEVER_BIN // [NEVER_BIN] | |
| 292 }, | |
| 293 // [ALLOW_ANYTHING] | |
| 294 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | |
| 295 NOW_BIN, // [NOW_BIN] | |
| 296 SOON_BIN, // [SOON_BIN] | |
| 297 EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | |
| 298 EVENTUALLY_BIN, // [EVENTUALLY_BIN] | |
| 299 AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_AND_ACTIVE_BIN] | |
| 300 AT_LAST_BIN, // [AT_LAST_BIN] | |
| 301 NEVER_BIN // [NEVER_BIN] | |
| 302 }}; | |
| 303 | |
| 304 // Ready to draw works by mapping NOW_BIN to NOW_AND_READY_TO_DRAW_BIN. | |
| 305 const ManagedTileBin kBinReadyToDrawMap[2][NUM_BINS] = { | |
| 306 // Not ready | |
| 307 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | |
| 308 NOW_BIN, // [NOW_BIN] | |
| 309 SOON_BIN, // [SOON_BIN] | |
| 310 EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | |
| 311 EVENTUALLY_BIN, // [EVENTUALLY_BIN] | |
| 312 AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_AND_ACTIVE_BIN] | |
| 313 AT_LAST_BIN, // [AT_LAST_BIN] | |
| 314 NEVER_BIN // [NEVER_BIN] | |
| 315 }, | |
| 316 // Ready | |
| 317 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | |
| 318 NOW_AND_READY_TO_DRAW_BIN, // [NOW_BIN] | |
| 319 SOON_BIN, // [SOON_BIN] | |
| 320 EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | |
| 321 EVENTUALLY_BIN, // [EVENTUALLY_BIN] | |
| 322 AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_AND_ACTIVE_BIN] | |
| 323 AT_LAST_BIN, // [AT_LAST_BIN] | |
| 324 NEVER_BIN // [NEVER_BIN] | |
| 325 }}; | |
| 326 | |
| 327 // Active works by mapping some bin stats to equivalent _ACTIVE_BIN state. | |
| 328 const ManagedTileBin kBinIsActiveMap[2][NUM_BINS] = { | |
| 329 // Inactive | |
| 330 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | |
| 331 NOW_BIN, // [NOW_BIN] | |
| 332 SOON_BIN, // [SOON_BIN] | |
| 333 EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | |
| 334 EVENTUALLY_BIN, // [EVENTUALLY_BIN] | |
| 335 AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_AND_ACTIVE_BIN] | |
| 336 AT_LAST_BIN, // [AT_LAST_BIN] | |
| 337 NEVER_BIN // [NEVER_BIN] | |
| 338 }, | |
| 339 // Active | |
| 340 {NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] | |
| 341 NOW_BIN, // [NOW_BIN] | |
| 342 SOON_BIN, // [SOON_BIN] | |
| 343 EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] | |
| 344 EVENTUALLY_AND_ACTIVE_BIN, // [EVENTUALLY_BIN] | |
| 345 AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_AND_ACTIVE_BIN] | |
| 346 AT_LAST_AND_ACTIVE_BIN, // [AT_LAST_BIN] | |
| 347 NEVER_BIN // [NEVER_BIN] | |
| 348 }}; | |
| 349 | |
| 350 // Determine bin based on three categories of tiles: things we need now, | |
| 351 // things we need soon, and eventually. | |
| 352 inline ManagedTileBin BinFromTilePriority(const TilePriority& prio) { | |
| 353 const float kBackflingGuardDistancePixels = 314.0f; | |
| 354 | |
| 355 if (prio.priority_bin == TilePriority::NOW) | |
| 356 return NOW_BIN; | |
| 357 | |
| 358 if (prio.priority_bin == TilePriority::SOON || | |
| 359 prio.distance_to_visible < kBackflingGuardDistancePixels) | |
| 360 return SOON_BIN; | |
| 361 | |
| 362 if (prio.distance_to_visible == std::numeric_limits<float>::infinity()) | |
| 363 return NEVER_BIN; | |
| 364 | |
| 365 return EVENTUALLY_BIN; | |
| 366 } | |
| 367 | |
| 368 } // namespace | 261 } // namespace |
| 369 | 262 |
| 370 RasterTaskCompletionStats::RasterTaskCompletionStats() | 263 RasterTaskCompletionStats::RasterTaskCompletionStats() |
| 371 : completed_count(0u), canceled_count(0u) {} | 264 : completed_count(0u), canceled_count(0u) {} |
| 372 | 265 |
| 373 scoped_ptr<base::Value> RasterTaskCompletionStatsAsValue( | 266 scoped_ptr<base::Value> RasterTaskCompletionStatsAsValue( |
| 374 const RasterTaskCompletionStats& stats) { | 267 const RasterTaskCompletionStats& stats) { |
| 375 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 268 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
| 376 state->SetInteger("completed_count", stats.completed_count); | 269 state->SetInteger("completed_count", stats.completed_count); |
| 377 state->SetInteger("canceled_count", stats.canceled_count); | 270 state->SetInteger("canceled_count", stats.canceled_count); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 399 TileManager::TileManager( | 292 TileManager::TileManager( |
| 400 TileManagerClient* client, | 293 TileManagerClient* client, |
| 401 ResourcePool* resource_pool, | 294 ResourcePool* resource_pool, |
| 402 Rasterizer* rasterizer, | 295 Rasterizer* rasterizer, |
| 403 Rasterizer* gpu_rasterizer, | 296 Rasterizer* gpu_rasterizer, |
| 404 size_t max_raster_usage_bytes, | 297 size_t max_raster_usage_bytes, |
| 405 bool use_rasterize_on_demand, | 298 bool use_rasterize_on_demand, |
| 406 RenderingStatsInstrumentation* rendering_stats_instrumentation) | 299 RenderingStatsInstrumentation* rendering_stats_instrumentation) |
| 407 : client_(client), | 300 : client_(client), |
| 408 resource_pool_(resource_pool), | 301 resource_pool_(resource_pool), |
| 409 prioritized_tiles_dirty_(false), | |
| 410 all_tiles_that_need_to_be_rasterized_have_memory_(true), | 302 all_tiles_that_need_to_be_rasterized_have_memory_(true), |
| 411 all_tiles_required_for_activation_have_memory_(true), | 303 all_tiles_required_for_activation_have_memory_(true), |
| 412 memory_required_bytes_(0), | |
| 413 memory_nice_to_have_bytes_(0), | |
| 414 bytes_releasable_(0), | 304 bytes_releasable_(0), |
| 415 resources_releasable_(0), | 305 resources_releasable_(0), |
| 416 max_raster_usage_bytes_(max_raster_usage_bytes), | 306 max_raster_usage_bytes_(max_raster_usage_bytes), |
| 417 ever_exceeded_memory_budget_(false), | 307 ever_exceeded_memory_budget_(false), |
| 418 rendering_stats_instrumentation_(rendering_stats_instrumentation), | 308 rendering_stats_instrumentation_(rendering_stats_instrumentation), |
| 419 did_initialize_visible_tile_(false), | 309 did_initialize_visible_tile_(false), |
| 420 did_check_for_completed_tasks_since_last_schedule_tasks_(true), | 310 did_check_for_completed_tasks_since_last_schedule_tasks_(true), |
| 421 use_rasterize_on_demand_(use_rasterize_on_demand) { | 311 use_rasterize_on_demand_(use_rasterize_on_demand) { |
| 422 Rasterizer* rasterizers[NUM_RASTERIZER_TYPES] = { | 312 Rasterizer* rasterizers[NUM_RASTERIZER_TYPES] = { |
| 423 rasterizer, // RASTERIZER_TYPE_DEFAULT | 313 rasterizer, // RASTERIZER_TYPE_DEFAULT |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 449 | 339 |
| 450 for (std::vector<PictureLayerImpl*>::iterator it = layers_.begin(); | 340 for (std::vector<PictureLayerImpl*>::iterator it = layers_.begin(); |
| 451 it != layers_.end(); | 341 it != layers_.end(); |
| 452 ++it) { | 342 ++it) { |
| 453 (*it)->DidUnregisterLayer(); | 343 (*it)->DidUnregisterLayer(); |
| 454 } | 344 } |
| 455 layers_.clear(); | 345 layers_.clear(); |
| 456 } | 346 } |
| 457 | 347 |
| 458 void TileManager::Release(Tile* tile) { | 348 void TileManager::Release(Tile* tile) { |
| 459 prioritized_tiles_dirty_ = true; | |
| 460 released_tiles_.push_back(tile); | 349 released_tiles_.push_back(tile); |
| 461 } | 350 } |
| 462 | 351 |
| 463 void TileManager::DidChangeTilePriority(Tile* tile) { | 352 void TileManager::DidChangeTilePriority(Tile* tile) { |
|
reveman
2014/04/24 00:17:34
Can we remove this function now?
vmpstr
2014/04/28 18:50:37
Done.
| |
| 464 prioritized_tiles_dirty_ = true; | |
| 465 } | 353 } |
| 466 | 354 |
| 467 bool TileManager::ShouldForceTasksRequiredForActivationToComplete() const { | 355 bool TileManager::ShouldForceTasksRequiredForActivationToComplete() const { |
| 468 return global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY; | 356 return global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY; |
| 469 } | 357 } |
| 470 | 358 |
| 471 void TileManager::CleanUpReleasedTiles() { | 359 void TileManager::CleanUpReleasedTiles() { |
| 472 for (std::vector<Tile*>::iterator it = released_tiles_.begin(); | 360 for (std::vector<Tile*>::iterator it = released_tiles_.begin(); |
| 473 it != released_tiles_.end(); | 361 it != released_tiles_.end(); |
| 474 ++it) { | 362 ++it) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 490 used_layer_counts_.erase(layer_it); | 378 used_layer_counts_.erase(layer_it); |
| 491 image_decode_tasks_.erase(tile->layer_id()); | 379 image_decode_tasks_.erase(tile->layer_id()); |
| 492 } | 380 } |
| 493 | 381 |
| 494 delete tile; | 382 delete tile; |
| 495 } | 383 } |
| 496 | 384 |
| 497 released_tiles_.clear(); | 385 released_tiles_.clear(); |
| 498 } | 386 } |
| 499 | 387 |
| 500 void TileManager::UpdatePrioritizedTileSetIfNeeded() { | |
| 501 if (!prioritized_tiles_dirty_) | |
| 502 return; | |
| 503 | |
| 504 CleanUpReleasedTiles(); | |
| 505 | |
| 506 prioritized_tiles_.Clear(); | |
| 507 GetTilesWithAssignedBins(&prioritized_tiles_); | |
| 508 prioritized_tiles_dirty_ = false; | |
| 509 } | |
| 510 | |
| 511 void TileManager::DidFinishRunningTasks() { | 388 void TileManager::DidFinishRunningTasks() { |
| 512 TRACE_EVENT0("cc", "TileManager::DidFinishRunningTasks"); | 389 TRACE_EVENT0("cc", "TileManager::DidFinishRunningTasks"); |
| 513 | 390 |
| 514 bool memory_usage_above_limit = resource_pool_->total_memory_usage_bytes() > | 391 bool memory_usage_above_limit = resource_pool_->total_memory_usage_bytes() > |
| 515 global_state_.soft_memory_limit_in_bytes; | 392 global_state_.soft_memory_limit_in_bytes; |
| 516 | 393 |
| 517 // When OOM, keep re-assigning memory until we reach a steady state | 394 // When OOM, keep re-assigning memory until we reach a steady state |
| 518 // where top-priority tiles are initialized. | 395 // where top-priority tiles are initialized. |
| 519 if (all_tiles_that_need_to_be_rasterized_have_memory_ && | 396 if (all_tiles_that_need_to_be_rasterized_have_memory_ && |
| 520 !memory_usage_above_limit) | 397 !memory_usage_above_limit) |
| 521 return; | 398 return; |
| 522 | 399 |
| 523 rasterizer_delegate_->CheckForCompletedTasks(); | 400 rasterizer_delegate_->CheckForCompletedTasks(); |
| 524 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 401 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
| 525 | 402 |
| 526 TileVector tiles_that_need_to_be_rasterized; | 403 TileVector tiles_that_need_to_be_rasterized; |
| 527 AssignGpuMemoryToTiles(&prioritized_tiles_, | 404 AssignGpuMemoryToTiles(&tiles_that_need_to_be_rasterized); |
| 528 &tiles_that_need_to_be_rasterized); | |
| 529 | 405 |
| 530 // |tiles_that_need_to_be_rasterized| will be empty when we reach a | 406 // |tiles_that_need_to_be_rasterized| will be empty when we reach a |
| 531 // steady memory state. Keep scheduling tasks until we reach this state. | 407 // steady memory state. Keep scheduling tasks until we reach this state. |
| 532 if (!tiles_that_need_to_be_rasterized.empty()) { | 408 if (!tiles_that_need_to_be_rasterized.empty()) { |
| 533 ScheduleTasks(tiles_that_need_to_be_rasterized); | 409 ScheduleTasks(tiles_that_need_to_be_rasterized); |
| 534 return; | 410 return; |
| 535 } | 411 } |
| 536 | 412 |
| 537 resource_pool_->ReduceResourceUsage(); | 413 resource_pool_->ReduceResourceUsage(); |
| 538 | 414 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 568 // activation are initialized when no tiles are OOM. We need to | 444 // activation are initialized when no tiles are OOM. We need to |
| 569 // wait for DidFinishRunningTasks() to be called, try to re-assign | 445 // wait for DidFinishRunningTasks() to be called, try to re-assign |
| 570 // memory and in worst case use on-demand raster when tiles | 446 // memory and in worst case use on-demand raster when tiles |
| 571 // required for activation are OOM. | 447 // required for activation are OOM. |
| 572 if (!all_tiles_required_for_activation_have_memory_) | 448 if (!all_tiles_required_for_activation_have_memory_) |
| 573 return; | 449 return; |
| 574 | 450 |
| 575 client_->NotifyReadyToActivate(); | 451 client_->NotifyReadyToActivate(); |
| 576 } | 452 } |
| 577 | 453 |
| 578 void TileManager::GetTilesWithAssignedBins(PrioritizedTileSet* tiles) { | |
| 579 TRACE_EVENT0("cc", "TileManager::GetTilesWithAssignedBins"); | |
| 580 | |
| 581 // Compute new stats to be return by GetMemoryStats(). | |
| 582 memory_required_bytes_ = 0; | |
| 583 memory_nice_to_have_bytes_ = 0; | |
| 584 | |
| 585 const TileMemoryLimitPolicy memory_policy = global_state_.memory_limit_policy; | |
| 586 const TreePriority tree_priority = global_state_.tree_priority; | |
| 587 | |
| 588 // For each tree, bin into different categories of tiles. | |
| 589 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | |
| 590 Tile* tile = it->second; | |
| 591 ManagedTileState& mts = tile->managed_state(); | |
| 592 | |
| 593 const ManagedTileState::TileVersion& tile_version = | |
| 594 tile->GetTileVersionForDrawing(); | |
| 595 bool tile_is_ready_to_draw = tile_version.IsReadyToDraw(); | |
| 596 bool tile_is_active = tile_is_ready_to_draw || | |
| 597 mts.tile_versions[mts.raster_mode].raster_task_; | |
| 598 | |
| 599 // Get the active priority and bin. | |
| 600 TilePriority active_priority = tile->priority(ACTIVE_TREE); | |
| 601 ManagedTileBin active_bin = BinFromTilePriority(active_priority); | |
| 602 | |
| 603 // Get the pending priority and bin. | |
| 604 TilePriority pending_priority = tile->priority(PENDING_TREE); | |
| 605 ManagedTileBin pending_bin = BinFromTilePriority(pending_priority); | |
| 606 | |
| 607 bool pending_is_low_res = pending_priority.resolution == LOW_RESOLUTION; | |
| 608 bool pending_is_non_ideal = | |
| 609 pending_priority.resolution == NON_IDEAL_RESOLUTION; | |
| 610 bool active_is_non_ideal = | |
| 611 active_priority.resolution == NON_IDEAL_RESOLUTION; | |
| 612 | |
| 613 // Adjust pending bin state for low res tiles. This prevents | |
| 614 // pending tree low-res tiles from being initialized before | |
| 615 // high-res tiles. | |
| 616 if (pending_is_low_res) | |
| 617 pending_bin = std::max(pending_bin, EVENTUALLY_BIN); | |
| 618 | |
| 619 // Adjust bin state based on if ready to draw. | |
| 620 active_bin = kBinReadyToDrawMap[tile_is_ready_to_draw][active_bin]; | |
| 621 pending_bin = kBinReadyToDrawMap[tile_is_ready_to_draw][pending_bin]; | |
| 622 | |
| 623 // Adjust bin state based on if active. | |
| 624 active_bin = kBinIsActiveMap[tile_is_active][active_bin]; | |
| 625 pending_bin = kBinIsActiveMap[tile_is_active][pending_bin]; | |
| 626 | |
| 627 // We never want to paint new non-ideal tiles, as we always have | |
| 628 // a high-res tile covering that content (paint that instead). | |
| 629 if (!tile_is_ready_to_draw && active_is_non_ideal) | |
| 630 active_bin = NEVER_BIN; | |
| 631 if (!tile_is_ready_to_draw && pending_is_non_ideal) | |
| 632 pending_bin = NEVER_BIN; | |
| 633 | |
| 634 // Compute combined bin. | |
| 635 ManagedTileBin combined_bin = std::min(active_bin, pending_bin); | |
| 636 | |
| 637 if (!tile_is_ready_to_draw || tile_version.requires_resource()) { | |
| 638 // The bin that the tile would have if the GPU memory manager had | |
| 639 // a maximally permissive policy, send to the GPU memory manager | |
| 640 // to determine policy. | |
| 641 ManagedTileBin gpu_memmgr_stats_bin = combined_bin; | |
| 642 if ((gpu_memmgr_stats_bin == NOW_BIN) || | |
| 643 (gpu_memmgr_stats_bin == NOW_AND_READY_TO_DRAW_BIN)) | |
| 644 memory_required_bytes_ += BytesConsumedIfAllocated(tile); | |
| 645 if (gpu_memmgr_stats_bin != NEVER_BIN) | |
| 646 memory_nice_to_have_bytes_ += BytesConsumedIfAllocated(tile); | |
| 647 } | |
| 648 | |
| 649 ManagedTileBin tree_bin[NUM_TREES]; | |
| 650 tree_bin[ACTIVE_TREE] = kBinPolicyMap[memory_policy][active_bin]; | |
| 651 tree_bin[PENDING_TREE] = kBinPolicyMap[memory_policy][pending_bin]; | |
| 652 | |
| 653 TilePriority tile_priority; | |
| 654 switch (tree_priority) { | |
| 655 case SAME_PRIORITY_FOR_BOTH_TREES: | |
| 656 mts.bin = kBinPolicyMap[memory_policy][combined_bin]; | |
| 657 tile_priority = tile->combined_priority(); | |
| 658 break; | |
| 659 case SMOOTHNESS_TAKES_PRIORITY: | |
| 660 mts.bin = tree_bin[ACTIVE_TREE]; | |
| 661 tile_priority = active_priority; | |
| 662 break; | |
| 663 case NEW_CONTENT_TAKES_PRIORITY: | |
| 664 mts.bin = tree_bin[PENDING_TREE]; | |
| 665 tile_priority = pending_priority; | |
| 666 break; | |
| 667 } | |
| 668 | |
| 669 // Bump up the priority if we determined it's NEVER_BIN on one tree, | |
| 670 // but is still required on the other tree. | |
| 671 bool is_in_never_bin_on_both_trees = tree_bin[ACTIVE_TREE] == NEVER_BIN && | |
| 672 tree_bin[PENDING_TREE] == NEVER_BIN; | |
| 673 | |
| 674 if (mts.bin == NEVER_BIN && !is_in_never_bin_on_both_trees) | |
| 675 mts.bin = tile_is_active ? AT_LAST_AND_ACTIVE_BIN : AT_LAST_BIN; | |
| 676 | |
| 677 mts.resolution = tile_priority.resolution; | |
| 678 mts.priority_bin = tile_priority.priority_bin; | |
| 679 mts.distance_to_visible = tile_priority.distance_to_visible; | |
| 680 mts.required_for_activation = tile_priority.required_for_activation; | |
| 681 | |
| 682 mts.visible_and_ready_to_draw = | |
| 683 tree_bin[ACTIVE_TREE] == NOW_AND_READY_TO_DRAW_BIN; | |
| 684 | |
| 685 // If the tile is in NEVER_BIN and it does not have an active task, then we | |
| 686 // can release the resources early. If it does have the task however, we | |
| 687 // should keep it in the prioritized tile set to ensure that AssignGpuMemory | |
| 688 // can visit it. | |
| 689 if (mts.bin == NEVER_BIN && | |
| 690 !mts.tile_versions[mts.raster_mode].raster_task_) { | |
| 691 FreeResourcesForTile(tile); | |
| 692 continue; | |
| 693 } | |
| 694 | |
| 695 // Insert the tile into a priority set. | |
| 696 tiles->InsertTile(tile, mts.bin); | |
| 697 } | |
| 698 } | |
| 699 | |
| 700 void TileManager::ManageTiles(const GlobalStateThatImpactsTilePriority& state) { | 454 void TileManager::ManageTiles(const GlobalStateThatImpactsTilePriority& state) { |
| 701 TRACE_EVENT0("cc", "TileManager::ManageTiles"); | 455 TRACE_EVENT0("cc", "TileManager::ManageTiles"); |
| 702 | 456 |
| 703 // Update internal state. | 457 // Update internal state. |
| 704 if (state != global_state_) { | 458 if (state != global_state_) |
|
reveman
2014/04/24 00:17:34
I don't think we need this anymore :) Please remov
vmpstr
2014/04/28 18:50:37
Done.
| |
| 705 global_state_ = state; | 459 global_state_ = state; |
| 706 prioritized_tiles_dirty_ = true; | 460 |
| 707 } | 461 // TODO(vmpstr): See if we still need to keep tiles alive when layers release |
| 462 // them. | |
| 463 CleanUpReleasedTiles(); | |
|
reveman
2014/04/24 00:17:34
No need to do anything in this patch but we should
vmpstr
2014/04/28 18:50:37
Sounds good.
| |
| 708 | 464 |
| 709 // We need to call CheckForCompletedTasks() once in-between each call | 465 // We need to call CheckForCompletedTasks() once in-between each call |
| 710 // to ScheduleTasks() to prevent canceled tasks from being scheduled. | 466 // to ScheduleTasks() to prevent canceled tasks from being scheduled. |
| 711 if (!did_check_for_completed_tasks_since_last_schedule_tasks_) { | 467 if (!did_check_for_completed_tasks_since_last_schedule_tasks_) { |
| 712 rasterizer_delegate_->CheckForCompletedTasks(); | 468 rasterizer_delegate_->CheckForCompletedTasks(); |
| 713 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 469 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
| 714 } | 470 } |
| 715 | 471 |
| 716 UpdatePrioritizedTileSetIfNeeded(); | |
| 717 | |
| 718 TileVector tiles_that_need_to_be_rasterized; | 472 TileVector tiles_that_need_to_be_rasterized; |
| 719 AssignGpuMemoryToTiles(&prioritized_tiles_, | 473 AssignGpuMemoryToTiles(&tiles_that_need_to_be_rasterized); |
| 720 &tiles_that_need_to_be_rasterized); | |
| 721 | 474 |
| 722 // Finally, schedule rasterizer tasks. | 475 // Finally, schedule rasterizer tasks. |
| 723 ScheduleTasks(tiles_that_need_to_be_rasterized); | 476 ScheduleTasks(tiles_that_need_to_be_rasterized); |
| 724 | 477 |
| 725 TRACE_EVENT_INSTANT1("cc", | 478 TRACE_EVENT_INSTANT1("cc", |
| 726 "DidManage", | 479 "DidManage", |
| 727 TRACE_EVENT_SCOPE_THREAD, | 480 TRACE_EVENT_SCOPE_THREAD, |
| 728 "state", | 481 "state", |
| 729 TracedValue::FromValue(BasicStateAsValue().release())); | 482 TracedValue::FromValue(BasicStateAsValue().release())); |
| 730 | 483 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 752 | 505 |
| 753 bool did_initialize_visible_tile = did_initialize_visible_tile_; | 506 bool did_initialize_visible_tile = did_initialize_visible_tile_; |
| 754 did_initialize_visible_tile_ = false; | 507 did_initialize_visible_tile_ = false; |
| 755 return did_initialize_visible_tile; | 508 return did_initialize_visible_tile; |
| 756 } | 509 } |
| 757 | 510 |
| 758 void TileManager::GetMemoryStats(size_t* memory_required_bytes, | 511 void TileManager::GetMemoryStats(size_t* memory_required_bytes, |
| 759 size_t* memory_nice_to_have_bytes, | 512 size_t* memory_nice_to_have_bytes, |
| 760 size_t* memory_allocated_bytes, | 513 size_t* memory_allocated_bytes, |
| 761 size_t* memory_used_bytes) const { | 514 size_t* memory_used_bytes) const { |
| 762 *memory_required_bytes = memory_required_bytes_; | 515 *memory_required_bytes = resource_pool_->total_memory_usage_bytes(); |
| 763 *memory_nice_to_have_bytes = memory_nice_to_have_bytes_; | 516 *memory_nice_to_have_bytes = resource_pool_->total_memory_usage_bytes(); |
| 764 *memory_allocated_bytes = resource_pool_->total_memory_usage_bytes(); | 517 *memory_allocated_bytes = resource_pool_->total_memory_usage_bytes(); |
| 765 *memory_used_bytes = resource_pool_->acquired_memory_usage_bytes(); | 518 *memory_used_bytes = resource_pool_->acquired_memory_usage_bytes(); |
| 766 } | 519 } |
| 767 | 520 |
| 768 scoped_ptr<base::Value> TileManager::BasicStateAsValue() const { | 521 scoped_ptr<base::Value> TileManager::BasicStateAsValue() const { |
| 769 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 522 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
| 770 state->SetInteger("tile_count", tiles_.size()); | 523 state->SetInteger("tile_count", tiles_.size()); |
| 771 state->Set("global_state", global_state_.AsValue().release()); | 524 state->Set("global_state", global_state_.AsValue().release()); |
| 772 state->Set("memory_requirements", GetMemoryRequirementsAsValue().release()); | 525 state->Set("memory_requirements", GetMemoryRequirementsAsValue().release()); |
| 773 return state.PassAs<base::Value>(); | 526 return state.PassAs<base::Value>(); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 794 &memory_used_bytes); | 547 &memory_used_bytes); |
| 795 requirements->SetInteger("memory_required_bytes", memory_required_bytes); | 548 requirements->SetInteger("memory_required_bytes", memory_required_bytes); |
| 796 requirements->SetInteger("memory_nice_to_have_bytes", | 549 requirements->SetInteger("memory_nice_to_have_bytes", |
| 797 memory_nice_to_have_bytes); | 550 memory_nice_to_have_bytes); |
| 798 requirements->SetInteger("memory_allocated_bytes", memory_allocated_bytes); | 551 requirements->SetInteger("memory_allocated_bytes", memory_allocated_bytes); |
| 799 requirements->SetInteger("memory_used_bytes", memory_used_bytes); | 552 requirements->SetInteger("memory_used_bytes", memory_used_bytes); |
| 800 return requirements.PassAs<base::Value>(); | 553 return requirements.PassAs<base::Value>(); |
| 801 } | 554 } |
| 802 | 555 |
| 803 void TileManager::AssignGpuMemoryToTiles( | 556 void TileManager::AssignGpuMemoryToTiles( |
| 804 PrioritizedTileSet* tiles, | |
| 805 TileVector* tiles_that_need_to_be_rasterized) { | 557 TileVector* tiles_that_need_to_be_rasterized) { |
| 806 TRACE_EVENT0("cc", "TileManager::AssignGpuMemoryToTiles"); | 558 TRACE_EVENT0("cc", "TileManager::AssignGpuMemoryToTiles"); |
| 807 | 559 |
| 808 // Maintain the list of released resources that can potentially be re-used | 560 // Maintain the list of released resources that can potentially be re-used |
| 809 // or deleted. | 561 // or deleted. |
| 810 // If this operation becomes expensive too, only do this after some | 562 // If this operation becomes expensive too, only do this after some |
| 811 // resource(s) was returned. Note that in that case, one also need to | 563 // resource(s) was returned. Note that in that case, one also need to |
| 812 // invalidate when releasing some resource from the pool. | 564 // invalidate when releasing some resource from the pool. |
| 813 resource_pool_->CheckBusyResources(); | 565 resource_pool_->CheckBusyResources(); |
| 814 | 566 |
| 815 // Now give memory out to the tiles until we're out, and build | 567 // Now give memory out to the tiles until we're out, and build |
| 816 // the needs-to-be-rasterized queue. | 568 // the needs-to-be-rasterized queue. |
| 817 all_tiles_that_need_to_be_rasterized_have_memory_ = true; | 569 all_tiles_that_need_to_be_rasterized_have_memory_ = true; |
| 818 all_tiles_required_for_activation_have_memory_ = true; | 570 all_tiles_required_for_activation_have_memory_ = true; |
| 819 | 571 |
| 820 // Cast to prevent overflow. | 572 // Cast to prevent overflow. |
| 821 int64 soft_bytes_available = | 573 int64 soft_bytes_available = |
| 822 static_cast<int64>(bytes_releasable_) + | |
| 823 static_cast<int64>(global_state_.soft_memory_limit_in_bytes) - | 574 static_cast<int64>(global_state_.soft_memory_limit_in_bytes) - |
| 824 static_cast<int64>(resource_pool_->acquired_memory_usage_bytes()); | 575 static_cast<int64>(resource_pool_->acquired_memory_usage_bytes()); |
| 825 int64 hard_bytes_available = | 576 int64 hard_bytes_available = |
| 826 static_cast<int64>(bytes_releasable_) + | |
| 827 static_cast<int64>(global_state_.hard_memory_limit_in_bytes) - | 577 static_cast<int64>(global_state_.hard_memory_limit_in_bytes) - |
| 828 static_cast<int64>(resource_pool_->acquired_memory_usage_bytes()); | 578 static_cast<int64>(resource_pool_->acquired_memory_usage_bytes()); |
| 829 int resources_available = resources_releasable_ + | 579 int resources_available = global_state_.num_resources_limit - |
| 830 global_state_.num_resources_limit - | |
| 831 resource_pool_->acquired_resource_count(); | 580 resource_pool_->acquired_resource_count(); |
| 832 size_t soft_bytes_allocatable = | 581 |
| 582 EvictionTileIterator eviction_it; | |
| 583 bool eviction_iterator_created = false; | |
|
reveman
2014/04/24 00:17:34
Would it be too expensive to create a new eviction
vmpstr
2014/04/28 18:50:37
Yeah, we can move the initialization code outside
| |
| 584 bool evicted_tiles_required_for_activation = false; | |
| 585 if (hard_bytes_available < 0 || resources_available < 0) { | |
| 586 eviction_it = EvictionTileIterator(this, global_state_.tree_priority); | |
| 587 eviction_iterator_created = true; | |
| 588 while (hard_bytes_available < 0 || resources_available < 0) { | |
| 589 if (!eviction_it) | |
| 590 break; | |
| 591 | |
| 592 Tile* eviction_tile = *eviction_it; | |
| 593 const TilePriority& eviction_priority = | |
| 594 eviction_tile->priority_for_tree_priority( | |
| 595 global_state_.tree_priority); | |
| 596 size_t eviction_bytes_if_allocated = | |
| 597 BytesConsumedIfAllocated(eviction_tile); | |
| 598 ManagedTileState& eviction_mts = eviction_tile->managed_state(); | |
| 599 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { | |
| 600 if (eviction_mts.tile_versions[mode].resource_) { | |
| 601 hard_bytes_available += eviction_bytes_if_allocated; | |
| 602 if (eviction_priority.priority_bin != TilePriority::NOW) | |
| 603 soft_bytes_available += eviction_bytes_if_allocated; | |
| 604 resources_available++; | |
| 605 } | |
| 606 } | |
| 607 FreeResourcesForTile(eviction_tile); | |
| 608 ++eviction_it; | |
| 609 | |
| 610 evicted_tiles_required_for_activation |= | |
| 611 eviction_tile->required_for_activation(); | |
| 612 } | |
| 613 } | |
| 614 | |
| 615 int64 soft_bytes_allocatable = | |
| 833 std::max(static_cast<int64>(0), soft_bytes_available); | 616 std::max(static_cast<int64>(0), soft_bytes_available); |
| 834 size_t hard_bytes_allocatable = | 617 int64 hard_bytes_allocatable = |
| 835 std::max(static_cast<int64>(0), hard_bytes_available); | 618 std::max(static_cast<int64>(0), hard_bytes_available); |
| 836 size_t resources_allocatable = std::max(0, resources_available); | 619 int resources_allocatable = std::max(0, resources_available); |
| 837 | 620 |
| 838 size_t bytes_that_exceeded_memory_budget = 0; | 621 size_t bytes_that_exceeded_memory_budget = 0; |
| 839 size_t soft_bytes_left = soft_bytes_allocatable; | 622 int64 soft_bytes_left = soft_bytes_allocatable; |
| 840 size_t hard_bytes_left = hard_bytes_allocatable; | 623 int64 hard_bytes_left = hard_bytes_allocatable; |
| 841 | 624 |
| 842 size_t resources_left = resources_allocatable; | 625 int& resources_left = resources_allocatable; |
|
reveman
2014/04/24 00:17:34
nit: "int*" instead
vmpstr
2014/04/28 18:50:37
Done.
| |
| 843 bool oomed_soft = false; | 626 bool oomed_soft = false; |
| 844 bool oomed_hard = false; | 627 bool oomed_hard = false; |
| 845 bool have_hit_soft_memory = false; // Soft memory comes after hard. | 628 bool have_hit_soft_memory = false; // Soft memory comes after hard. |
| 846 | 629 |
| 847 // Memory we assign to raster tasks now will be deducted from our memory | 630 // Memory we assign to raster tasks now will be deducted from our memory |
| 848 // in future iterations if priorities change. By assigning at most half | 631 // in future iterations if priorities change. By assigning at most half |
| 849 // the raster limit, we will always have another 50% left even if priorities | 632 // the raster limit, we will always have another 50% left even if priorities |
| 850 // change completely (assuming we check for completed/cancelled rasters | 633 // change completely (assuming we check for completed/cancelled rasters |
| 851 // between each call to this function). | 634 // between each call to this function). |
| 852 size_t max_raster_bytes = max_raster_usage_bytes_ / 2; | 635 size_t max_raster_bytes = max_raster_usage_bytes_ / 2; |
| 853 size_t raster_bytes = 0; | 636 size_t raster_bytes = 0; |
| 854 | 637 |
| 855 unsigned schedule_priority = 1u; | 638 unsigned schedule_priority = 1u; |
| 856 for (PrioritizedTileSet::Iterator it(tiles, true); it; ++it) { | 639 for (RasterTileIterator it(this, global_state_.tree_priority); it; ++it) { |
| 857 Tile* tile = *it; | 640 Tile* tile = *it; |
| 641 TilePriority priority = | |
| 642 tile->priority_for_tree_priority(global_state_.tree_priority); | |
| 858 ManagedTileState& mts = tile->managed_state(); | 643 ManagedTileState& mts = tile->managed_state(); |
| 859 | 644 |
| 860 mts.scheduled_priority = schedule_priority++; | 645 mts.scheduled_priority = schedule_priority++; |
| 861 | 646 |
| 862 mts.raster_mode = tile->DetermineOverallRasterMode(); | 647 mts.raster_mode = tile->DetermineOverallRasterMode(); |
| 863 | 648 |
| 864 ManagedTileState::TileVersion& tile_version = | 649 ManagedTileState::TileVersion& tile_version = |
| 865 mts.tile_versions[mts.raster_mode]; | 650 mts.tile_versions[mts.raster_mode]; |
| 866 | 651 |
| 867 // If this tile doesn't need a resource, then nothing to do. | 652 // If this version is ready to draw, then nothing to do. |
| 868 if (!tile_version.requires_resource()) | 653 if (tile_version.IsReadyToDraw()) |
| 869 continue; | 654 continue; |
| 870 | 655 |
| 871 // If the tile is not needed, free it up. | 656 const bool tile_uses_hard_limit = |
| 872 if (mts.bin == NEVER_BIN) { | 657 priority.priority_bin == TilePriority::NOW; |
| 873 FreeResourcesForTile(tile); | |
| 874 continue; | |
| 875 } | |
| 876 | 658 |
| 877 const bool tile_uses_hard_limit = mts.bin <= NOW_BIN; | |
| 878 const size_t bytes_if_allocated = BytesConsumedIfAllocated(tile); | 659 const size_t bytes_if_allocated = BytesConsumedIfAllocated(tile); |
| 879 const size_t raster_bytes_if_rastered = raster_bytes + bytes_if_allocated; | 660 const size_t raster_bytes_if_rastered = raster_bytes + bytes_if_allocated; |
| 880 const size_t tile_bytes_left = | 661 int64& tile_bytes_left = |
|
reveman
2014/04/24 00:17:34
nit: int64*
vmpstr
2014/04/28 18:50:37
Done.
| |
| 881 (tile_uses_hard_limit) ? hard_bytes_left : soft_bytes_left; | 662 (tile_uses_hard_limit) ? hard_bytes_left : soft_bytes_left; |
| 882 | 663 |
| 883 // Hard-limit is reserved for tiles that would cause a calamity | 664 // Hard-limit is reserved for tiles that would cause a calamity |
| 884 // if they were to go away, so by definition they are the highest | 665 // if they were to go away, so by definition they are the highest |
| 885 // priority memory, and must be at the front of the list. | 666 // priority memory, and must be at the front of the list. |
| 886 DCHECK(!(have_hit_soft_memory && tile_uses_hard_limit)); | 667 DCHECK(!(have_hit_soft_memory && tile_uses_hard_limit)); |
| 887 have_hit_soft_memory |= !tile_uses_hard_limit; | 668 have_hit_soft_memory |= !tile_uses_hard_limit; |
| 888 | 669 |
| 889 size_t tile_bytes = 0; | 670 int64 tile_bytes = 0; |
| 890 size_t tile_resources = 0; | 671 int tile_resources = 0; |
| 891 | 672 |
| 892 // It costs to maintain a resource. | 673 // It costs to maintain a resource. |
| 893 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { | 674 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { |
| 894 if (mts.tile_versions[mode].resource_) { | 675 if (mts.tile_versions[mode].resource_) { |
| 895 tile_bytes += bytes_if_allocated; | 676 tile_bytes += bytes_if_allocated; |
| 896 tile_resources++; | 677 tile_resources++; |
| 897 } | 678 } |
| 898 } | 679 } |
| 899 | 680 |
| 900 // Allow lower priority tiles with initialized resources to keep | 681 // If we don't have the required version, and it's not in flight |
| 901 // their memory by only assigning memory to new raster tasks if | 682 // then we'll have to pay to create a new task. |
| 902 // they can be scheduled. | 683 if (!tile_version.resource_ && !tile_version.raster_task_) { |
| 903 if (raster_bytes_if_rastered <= max_raster_bytes) { | 684 tile_bytes += bytes_if_allocated; |
| 904 // If we don't have the required version, and it's not in flight | 685 tile_resources++; |
| 905 // then we'll have to pay to create a new task. | |
| 906 if (!tile_version.resource_ && !tile_version.raster_task_) { | |
| 907 tile_bytes += bytes_if_allocated; | |
| 908 tile_resources++; | |
| 909 } | |
| 910 } | 686 } |
| 911 | 687 |
| 912 // Tile is OOM. | 688 // Handle OOM tiles. |
| 689 while (tile_bytes > tile_bytes_left || tile_resources > resources_left) { | |
| 690 if (!eviction_iterator_created) { | |
| 691 eviction_it = EvictionTileIterator(this, global_state_.tree_priority); | |
| 692 eviction_iterator_created = true; | |
| 693 } | |
| 694 | |
| 695 if (!eviction_it) | |
| 696 break; | |
| 697 | |
| 698 Tile* eviction_tile = *eviction_it; | |
| 699 DCHECK(eviction_tile); | |
| 700 | |
| 701 TilePriority eviction_priority = | |
| 702 eviction_tile->priority_for_tree_priority( | |
| 703 global_state_.tree_priority); | |
| 704 | |
| 705 if (!priority.IsHigherPriorityThan(eviction_priority)) | |
| 706 break; | |
| 707 | |
| 708 size_t eviction_tile_bytes = 0; | |
| 709 size_t eviction_tile_resources = 0; | |
| 710 size_t eviction_bytes_if_allocated = BytesConsumedIfAllocated(tile); | |
| 711 ManagedTileState& eviction_mts = eviction_tile->managed_state(); | |
| 712 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { | |
| 713 if (eviction_mts.tile_versions[mode].resource_) { | |
| 714 eviction_tile_bytes += eviction_bytes_if_allocated; | |
| 715 eviction_tile_resources++; | |
| 716 } | |
| 717 } | |
| 718 | |
| 719 FreeResourcesForTile(eviction_tile); | |
| 720 ++eviction_it; | |
| 721 | |
| 722 evicted_tiles_required_for_activation |= | |
| 723 eviction_tile->required_for_activation(); | |
| 724 | |
| 725 tile_bytes_left += eviction_tile_bytes; | |
| 726 resources_left += eviction_tile_resources; | |
| 727 } | |
| 728 | |
| 729 // Tile is still OOM. | |
| 913 if (tile_bytes > tile_bytes_left || tile_resources > resources_left) { | 730 if (tile_bytes > tile_bytes_left || tile_resources > resources_left) { |
| 914 FreeResourcesForTile(tile); | |
| 915 | |
| 916 // This tile was already on screen and now its resources have been | 731 // This tile was already on screen and now its resources have been |
| 917 // released. In order to prevent checkerboarding, set this tile as | 732 // released. In order to prevent checkerboarding, set this tile as |
| 918 // rasterize on demand immediately. | 733 // rasterize on demand immediately. |
| 919 if (mts.visible_and_ready_to_draw && use_rasterize_on_demand_) | 734 if (mts.visible_and_ready_to_draw && use_rasterize_on_demand_) |
| 920 tile_version.set_rasterize_on_demand(); | 735 tile_version.set_rasterize_on_demand(); |
| 921 | 736 |
| 922 oomed_soft = true; | 737 oomed_soft = true; |
| 923 if (tile_uses_hard_limit) { | 738 if (tile_uses_hard_limit) { |
| 924 oomed_hard = true; | 739 oomed_hard = true; |
| 925 bytes_that_exceeded_memory_budget += tile_bytes; | 740 bytes_that_exceeded_memory_budget += tile_bytes; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 942 // important for two reasons: | 757 // important for two reasons: |
| 943 // 1. Tile size should not impact raster priority. | 758 // 1. Tile size should not impact raster priority. |
| 944 // 2. Tiles with existing raster task could otherwise incorrectly | 759 // 2. Tiles with existing raster task could otherwise incorrectly |
| 945 // be added as they are not affected by |bytes_allocatable|. | 760 // be added as they are not affected by |bytes_allocatable|. |
| 946 bool can_schedule_tile = | 761 bool can_schedule_tile = |
| 947 !oomed_soft && raster_bytes_if_rastered <= max_raster_bytes && | 762 !oomed_soft && raster_bytes_if_rastered <= max_raster_bytes && |
| 948 tiles_that_need_to_be_rasterized->size() < kScheduledRasterTasksLimit; | 763 tiles_that_need_to_be_rasterized->size() < kScheduledRasterTasksLimit; |
| 949 | 764 |
| 950 if (!can_schedule_tile) { | 765 if (!can_schedule_tile) { |
| 951 all_tiles_that_need_to_be_rasterized_have_memory_ = false; | 766 all_tiles_that_need_to_be_rasterized_have_memory_ = false; |
| 952 if (tile->required_for_activation()) | 767 all_tiles_required_for_activation_have_memory_ = |
|
reveman
2014/04/24 00:17:34
As discussed, I'd like to see this removed and ins
vmpstr
2014/04/28 18:50:37
Moved to a separate patch.
| |
| 953 all_tiles_required_for_activation_have_memory_ = false; | 768 !it.HasTilesRequiredForActivation() && |
| 954 it.DisablePriorityOrdering(); | 769 !evicted_tiles_required_for_activation; |
| 955 continue; | 770 break; |
| 956 } | 771 } |
| 957 | 772 |
| 958 raster_bytes = raster_bytes_if_rastered; | 773 raster_bytes = raster_bytes_if_rastered; |
| 959 tiles_that_need_to_be_rasterized->push_back(tile); | 774 tiles_that_need_to_be_rasterized->push_back(tile); |
| 960 } | 775 } |
| 961 | 776 |
| 962 // OOM reporting uses hard-limit, soft-OOM is normal depending on limit. | 777 // OOM reporting uses hard-limit, soft-OOM is normal depending on limit. |
| 963 ever_exceeded_memory_budget_ |= oomed_hard; | 778 ever_exceeded_memory_budget_ |= oomed_hard; |
| 964 if (ever_exceeded_memory_budget_) { | 779 if (ever_exceeded_memory_budget_) { |
| 965 TRACE_COUNTER_ID2("cc", | 780 TRACE_COUNTER_ID2("cc", |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1230 content_rect, | 1045 content_rect, |
| 1231 opaque_rect, | 1046 opaque_rect, |
| 1232 contents_scale, | 1047 contents_scale, |
| 1233 layer_id, | 1048 layer_id, |
| 1234 source_frame_number, | 1049 source_frame_number, |
| 1235 flags)); | 1050 flags)); |
| 1236 DCHECK(tiles_.find(tile->id()) == tiles_.end()); | 1051 DCHECK(tiles_.find(tile->id()) == tiles_.end()); |
| 1237 | 1052 |
| 1238 tiles_[tile->id()] = tile; | 1053 tiles_[tile->id()] = tile; |
| 1239 used_layer_counts_[tile->layer_id()]++; | 1054 used_layer_counts_[tile->layer_id()]++; |
| 1240 prioritized_tiles_dirty_ = true; | |
| 1241 return tile; | 1055 return tile; |
| 1242 } | 1056 } |
| 1243 | 1057 |
| 1244 void TileManager::RegisterPictureLayerImpl(PictureLayerImpl* layer) { | 1058 void TileManager::RegisterPictureLayerImpl(PictureLayerImpl* layer) { |
| 1245 DCHECK(std::find(layers_.begin(), layers_.end(), layer) == layers_.end()); | 1059 DCHECK(std::find(layers_.begin(), layers_.end(), layer) == layers_.end()); |
| 1246 layers_.push_back(layer); | 1060 layers_.push_back(layer); |
| 1247 } | 1061 } |
| 1248 | 1062 |
| 1249 void TileManager::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { | 1063 void TileManager::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { |
| 1250 std::vector<PictureLayerImpl*>::iterator it = | 1064 std::vector<PictureLayerImpl*>::iterator it = |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1327 | 1141 |
| 1328 if (paired_iterator.PeekTile(tree_priority_) != NULL) { | 1142 if (paired_iterator.PeekTile(tree_priority_) != NULL) { |
| 1329 paired_iterators_.push_back(paired_iterator); | 1143 paired_iterators_.push_back(paired_iterator); |
| 1330 iterator_heap_.push_back(&paired_iterators_.back()); | 1144 iterator_heap_.push_back(&paired_iterators_.back()); |
| 1331 } | 1145 } |
| 1332 } | 1146 } |
| 1333 | 1147 |
| 1334 std::make_heap(iterator_heap_.begin(), iterator_heap_.end(), comparator_); | 1148 std::make_heap(iterator_heap_.begin(), iterator_heap_.end(), comparator_); |
| 1335 } | 1149 } |
| 1336 | 1150 |
| 1151 TileManager::RasterTileIterator::RasterTileIterator( | |
| 1152 const RasterTileIterator& other) | |
| 1153 : comparator_(other.comparator_) { | |
| 1154 *this = other; | |
| 1155 } | |
| 1156 | |
| 1157 TileManager::RasterTileIterator& TileManager::RasterTileIterator::operator=( | |
| 1158 const RasterTileIterator& other) { | |
| 1159 paired_iterators_ = other.paired_iterators_; | |
| 1160 tree_priority_ = other.tree_priority_; | |
| 1161 comparator_ = other.comparator_; | |
| 1162 | |
| 1163 iterator_heap_.reserve(paired_iterators_.size()); | |
| 1164 for (size_t i = 0; i < paired_iterators_.size(); ++i) { | |
| 1165 if (paired_iterators_[i].PeekTile(tree_priority_) != NULL) | |
| 1166 iterator_heap_.push_back(&paired_iterators_[i]); | |
| 1167 } | |
| 1168 std::make_heap(iterator_heap_.begin(), iterator_heap_.end(), comparator_); | |
| 1169 return *this; | |
| 1170 } | |
| 1171 | |
| 1337 TileManager::RasterTileIterator::~RasterTileIterator() {} | 1172 TileManager::RasterTileIterator::~RasterTileIterator() {} |
| 1338 | 1173 |
| 1174 bool TileManager::RasterTileIterator::HasTilesRequiredForActivation() const { | |
| 1175 for (std::vector<PairedPictureLayerIterator*>::const_iterator it = | |
| 1176 iterator_heap_.begin(); | |
| 1177 it != iterator_heap_.end(); | |
| 1178 ++it) { | |
| 1179 const PairedPictureLayerIterator* pair = *it; | |
| 1180 | |
| 1181 // Tiles required for activation can only come from pending layers. | |
| 1182 if (pair->pending_iterator.HasTilesRequiredForActivation()) | |
| 1183 return true; | |
| 1184 } | |
| 1185 return false; | |
| 1186 } | |
| 1187 | |
| 1339 TileManager::RasterTileIterator& TileManager::RasterTileIterator::operator++() { | 1188 TileManager::RasterTileIterator& TileManager::RasterTileIterator::operator++() { |
| 1340 DCHECK(*this); | 1189 DCHECK(*this); |
| 1341 | 1190 |
| 1342 std::pop_heap(iterator_heap_.begin(), iterator_heap_.end(), comparator_); | 1191 std::pop_heap(iterator_heap_.begin(), iterator_heap_.end(), comparator_); |
| 1343 PairedPictureLayerIterator* paired_iterator = iterator_heap_.back(); | 1192 PairedPictureLayerIterator* paired_iterator = iterator_heap_.back(); |
| 1344 iterator_heap_.pop_back(); | 1193 iterator_heap_.pop_back(); |
| 1345 | 1194 |
| 1346 paired_iterator->PopTile(tree_priority_); | 1195 paired_iterator->PopTile(tree_priority_); |
| 1347 if (paired_iterator->PeekTile(tree_priority_) != NULL) { | 1196 if (paired_iterator->PeekTile(tree_priority_) != NULL) { |
| 1348 iterator_heap_.push_back(paired_iterator); | 1197 iterator_heap_.push_back(paired_iterator); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1461 | 1310 |
| 1462 Tile* a_tile = **a_pair.first; | 1311 Tile* a_tile = **a_pair.first; |
| 1463 Tile* b_tile = **b_pair.first; | 1312 Tile* b_tile = **b_pair.first; |
| 1464 | 1313 |
| 1465 const TilePriority& a_priority = | 1314 const TilePriority& a_priority = |
| 1466 a_tile->priority_for_tree_priority(tree_priority_); | 1315 a_tile->priority_for_tree_priority(tree_priority_); |
| 1467 const TilePriority& b_priority = | 1316 const TilePriority& b_priority = |
| 1468 b_tile->priority_for_tree_priority(tree_priority_); | 1317 b_tile->priority_for_tree_priority(tree_priority_); |
| 1469 bool prioritize_low_res = tree_priority_ == SMOOTHNESS_TAKES_PRIORITY; | 1318 bool prioritize_low_res = tree_priority_ == SMOOTHNESS_TAKES_PRIORITY; |
| 1470 | 1319 |
| 1471 if (b_priority.resolution != a_priority.resolution) { | 1320 if (b_priority.priority_bin == a_priority.priority_bin && |
| 1321 b_priority.resolution != a_priority.resolution) { | |
| 1472 return (prioritize_low_res && b_priority.resolution == LOW_RESOLUTION) || | 1322 return (prioritize_low_res && b_priority.resolution == LOW_RESOLUTION) || |
| 1473 (!prioritize_low_res && b_priority.resolution == HIGH_RESOLUTION) || | 1323 (!prioritize_low_res && b_priority.resolution == HIGH_RESOLUTION) || |
| 1474 (a_priority.resolution == NON_IDEAL_RESOLUTION); | 1324 (a_priority.resolution == NON_IDEAL_RESOLUTION); |
| 1475 } | 1325 } |
| 1476 | 1326 |
| 1477 return b_priority.IsHigherPriorityThan(a_priority); | 1327 return b_priority.IsHigherPriorityThan(a_priority); |
| 1478 } | 1328 } |
| 1479 | 1329 |
| 1480 TileManager::EvictionTileIterator::EvictionTileIterator() | 1330 TileManager::EvictionTileIterator::EvictionTileIterator() |
| 1481 : comparator_(SAME_PRIORITY_FOR_BOTH_TREES) {} | 1331 : comparator_(SAME_PRIORITY_FOR_BOTH_TREES) {} |
| 1482 | 1332 |
| 1483 TileManager::EvictionTileIterator::EvictionTileIterator( | 1333 TileManager::EvictionTileIterator::EvictionTileIterator( |
| 1334 const EvictionTileIterator& other) | |
| 1335 : comparator_(other.comparator_) { | |
| 1336 *this = other; | |
| 1337 } | |
| 1338 | |
| 1339 TileManager::EvictionTileIterator& TileManager::EvictionTileIterator::operator=( | |
| 1340 const EvictionTileIterator& other) { | |
| 1341 paired_iterators_ = other.paired_iterators_; | |
| 1342 tree_priority_ = other.tree_priority_; | |
| 1343 comparator_ = other.comparator_; | |
| 1344 | |
| 1345 iterator_heap_.reserve(paired_iterators_.size()); | |
| 1346 for (size_t i = 0; i < paired_iterators_.size(); ++i) { | |
| 1347 if (paired_iterators_[i].PeekTile(tree_priority_) != NULL) | |
| 1348 iterator_heap_.push_back(&paired_iterators_[i]); | |
| 1349 } | |
| 1350 std::make_heap(iterator_heap_.begin(), iterator_heap_.end(), comparator_); | |
| 1351 return *this; | |
| 1352 } | |
| 1353 | |
| 1354 TileManager::EvictionTileIterator::EvictionTileIterator( | |
| 1484 TileManager* tile_manager, | 1355 TileManager* tile_manager, |
| 1485 TreePriority tree_priority) | 1356 TreePriority tree_priority) |
| 1486 : tree_priority_(tree_priority), comparator_(tree_priority) { | 1357 : tree_priority_(tree_priority), comparator_(tree_priority) { |
| 1487 std::vector<TileManager::PairedPictureLayer> paired_layers; | 1358 std::vector<TileManager::PairedPictureLayer> paired_layers; |
| 1488 | 1359 |
| 1489 tile_manager->GetPairedPictureLayers(&paired_layers); | 1360 tile_manager->GetPairedPictureLayers(&paired_layers); |
| 1490 | 1361 |
| 1491 paired_iterators_.reserve(paired_layers.size()); | 1362 paired_iterators_.reserve(paired_layers.size()); |
| 1492 iterator_heap_.reserve(paired_layers.size()); | 1363 iterator_heap_.reserve(paired_layers.size()); |
| 1493 for (std::vector<TileManager::PairedPictureLayer>::iterator it = | 1364 for (std::vector<TileManager::PairedPictureLayer>::iterator it = |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1636 | 1507 |
| 1637 if (b_priority.resolution != a_priority.resolution) { | 1508 if (b_priority.resolution != a_priority.resolution) { |
| 1638 return (prioritize_low_res && b_priority.resolution == LOW_RESOLUTION) || | 1509 return (prioritize_low_res && b_priority.resolution == LOW_RESOLUTION) || |
| 1639 (!prioritize_low_res && b_priority.resolution == HIGH_RESOLUTION) || | 1510 (!prioritize_low_res && b_priority.resolution == HIGH_RESOLUTION) || |
| 1640 (a_priority.resolution == NON_IDEAL_RESOLUTION); | 1511 (a_priority.resolution == NON_IDEAL_RESOLUTION); |
| 1641 } | 1512 } |
| 1642 return a_priority.IsHigherPriorityThan(b_priority); | 1513 return a_priority.IsHigherPriorityThan(b_priority); |
| 1643 } | 1514 } |
| 1644 | 1515 |
| 1645 } // namespace cc | 1516 } // namespace cc |
| OLD | NEW |