| 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/tiles/tile_manager.h" | 5 #include "cc/tiles/tile_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 #include <limits> | 11 #include <limits> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/json/json_writer.h" | 15 #include "base/json/json_writer.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
| 19 #include "base/metrics/histogram.h" | 19 #include "base/metrics/histogram.h" |
| 20 #include "base/numerics/safe_conversions.h" | 20 #include "base/numerics/safe_conversions.h" |
| 21 #include "base/trace_event/trace_event_argument.h" | 21 #include "base/trace_event/trace_event_argument.h" |
| 22 #include "cc/base/histograms.h" | 22 #include "cc/base/histograms.h" |
| 23 #include "cc/debug/devtools_instrumentation.h" | 23 #include "cc/debug/devtools_instrumentation.h" |
| 24 #include "cc/debug/frame_viewer_instrumentation.h" | 24 #include "cc/debug/frame_viewer_instrumentation.h" |
| 25 #include "cc/debug/traced_value.h" | 25 #include "cc/debug/traced_value.h" |
| 26 #include "cc/layers/picture_layer_impl.h" | 26 #include "cc/layers/picture_layer_impl.h" |
| 27 #include "cc/raster/raster_buffer.h" | 27 #include "cc/raster/raster_buffer.h" |
| 28 #include "cc/raster/task_category.h" | 28 #include "cc/raster/task_category.h" |
| 29 #include "cc/raster/tile_task_runner.h" | |
| 30 #include "cc/tiles/tile.h" | 29 #include "cc/tiles/tile.h" |
| 31 #include "ui/gfx/geometry/rect_conversions.h" | 30 #include "ui/gfx/geometry/rect_conversions.h" |
| 32 | 31 |
| 33 namespace cc { | 32 namespace cc { |
| 34 namespace { | 33 namespace { |
| 35 | 34 |
| 36 // Flag to indicate whether we should try and detect that | 35 // Flag to indicate whether we should try and detect that |
| 37 // a tile is of solid color. | 36 // a tile is of solid color. |
| 38 const bool kUseColorEstimator = true; | 37 const bool kUseColorEstimator = true; |
| 39 | 38 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 uint32_t dependency_count = 0u; | 161 uint32_t dependency_count = 0u; |
| 163 if (task->dependencies().size()) { | 162 if (task->dependencies().size()) { |
| 164 DCHECK_EQ(task->dependencies().size(), 1u); | 163 DCHECK_EQ(task->dependencies().size(), 1u); |
| 165 auto* dependency = task->dependencies()[0].get(); | 164 auto* dependency = task->dependencies()[0].get(); |
| 166 if (!dependency->HasCompleted()) { | 165 if (!dependency->HasCompleted()) { |
| 167 InsertNodeForDecodeTask(graph, dependency, category, priority); | 166 InsertNodeForDecodeTask(graph, dependency, category, priority); |
| 168 graph->edges.push_back(TaskGraph::Edge(dependency, task)); | 167 graph->edges.push_back(TaskGraph::Edge(dependency, task)); |
| 169 dependency_count = 1u; | 168 dependency_count = 1u; |
| 170 } | 169 } |
| 171 } | 170 } |
| 172 InsertNodeForTask(graph, task, task->SupportsConcurrentExecution() | 171 InsertNodeForTask(graph, task, task->supports_concurrent_execution() |
| 173 ? category | 172 ? category |
| 174 : TASK_CATEGORY_NONCONCURRENT_FOREGROUND, | 173 : TASK_CATEGORY_NONCONCURRENT_FOREGROUND, |
| 175 priority, dependency_count); | 174 priority, dependency_count); |
| 176 } | 175 } |
| 177 | 176 |
| 178 void InsertNodesForRasterTask(TaskGraph* graph, | 177 void InsertNodesForRasterTask(TaskGraph* graph, |
| 179 TileTask* raster_task, | 178 TileTask* raster_task, |
| 180 const TileTask::Vector& decode_tasks, | 179 const TileTask::Vector& decode_tasks, |
| 181 size_t priority, | 180 size_t priority, |
| 182 bool use_gpu_rasterization, | 181 bool use_gpu_rasterization, |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 client, task_runner, scheduled_raster_task_limit, use_partial_raster)); | 301 client, task_runner, scheduled_raster_task_limit, use_partial_raster)); |
| 303 } | 302 } |
| 304 | 303 |
| 305 TileManager::TileManager(TileManagerClient* client, | 304 TileManager::TileManager(TileManagerClient* client, |
| 306 scoped_refptr<base::SequencedTaskRunner> task_runner, | 305 scoped_refptr<base::SequencedTaskRunner> task_runner, |
| 307 size_t scheduled_raster_task_limit, | 306 size_t scheduled_raster_task_limit, |
| 308 bool use_partial_raster) | 307 bool use_partial_raster) |
| 309 : client_(client), | 308 : client_(client), |
| 310 task_runner_(std::move(task_runner)), | 309 task_runner_(std::move(task_runner)), |
| 311 resource_pool_(nullptr), | 310 resource_pool_(nullptr), |
| 312 tile_task_runner_(nullptr), | 311 tile_task_worker_pool_(nullptr), |
| 313 scheduled_raster_task_limit_(scheduled_raster_task_limit), | 312 scheduled_raster_task_limit_(scheduled_raster_task_limit), |
| 314 use_partial_raster_(use_partial_raster), | 313 use_partial_raster_(use_partial_raster), |
| 315 use_gpu_rasterization_(false), | 314 use_gpu_rasterization_(false), |
| 316 all_tiles_that_need_to_be_rasterized_are_scheduled_(true), | 315 all_tiles_that_need_to_be_rasterized_are_scheduled_(true), |
| 317 did_check_for_completed_tasks_since_last_schedule_tasks_(true), | 316 did_check_for_completed_tasks_since_last_schedule_tasks_(true), |
| 318 did_oom_on_last_assign_(false), | 317 did_oom_on_last_assign_(false), |
| 319 more_tiles_need_prepare_check_notifier_( | 318 more_tiles_need_prepare_check_notifier_( |
| 320 task_runner_.get(), | 319 task_runner_.get(), |
| 321 base::Bind(&TileManager::CheckIfMoreTilesNeedToBePrepared, | 320 base::Bind(&TileManager::CheckIfMoreTilesNeedToBePrepared, |
| 322 base::Unretained(this))), | 321 base::Unretained(this))), |
| 323 signals_check_notifier_(task_runner_.get(), | 322 signals_check_notifier_(task_runner_.get(), |
| 324 base::Bind(&TileManager::CheckAndIssueSignals, | 323 base::Bind(&TileManager::CheckAndIssueSignals, |
| 325 base::Unretained(this))), | 324 base::Unretained(this))), |
| 326 has_scheduled_tile_tasks_(false), | 325 has_scheduled_tile_tasks_(false), |
| 327 prepare_tiles_count_(0u), | 326 prepare_tiles_count_(0u), |
| 328 next_tile_id_(0u), | 327 next_tile_id_(0u), |
| 329 task_set_finished_weak_ptr_factory_(this) {} | 328 task_set_finished_weak_ptr_factory_(this) {} |
| 330 | 329 |
| 331 TileManager::~TileManager() { | 330 TileManager::~TileManager() { |
| 332 FinishTasksAndCleanUp(); | 331 FinishTasksAndCleanUp(); |
| 333 } | 332 } |
| 334 | 333 |
| 335 void TileManager::FinishTasksAndCleanUp() { | 334 void TileManager::FinishTasksAndCleanUp() { |
| 336 if (!tile_task_runner_) | 335 if (!tile_task_worker_pool_) |
| 337 return; | 336 return; |
| 338 | 337 |
| 339 global_state_ = GlobalStateThatImpactsTilePriority(); | 338 global_state_ = GlobalStateThatImpactsTilePriority(); |
| 340 | 339 |
| 341 // This cancels tasks if possible, finishes pending tasks, and release any | 340 // This cancels tasks if possible, finishes pending tasks, and release any |
| 342 // uninitialized resources. | 341 // uninitialized resources. |
| 343 tile_task_runner_->Shutdown(); | 342 tile_task_worker_pool_->Shutdown(); |
| 344 | 343 |
| 345 // Now that all tasks have been finished, we can clear any | 344 // Now that all tasks have been finished, we can clear any |
| 346 // |orphan_tasks_|. | 345 // |orphan_tasks_|. |
| 347 orphan_tasks_.clear(); | 346 orphan_tasks_.clear(); |
| 348 | 347 |
| 349 tile_task_runner_->CheckForCompletedTasks(); | 348 tile_task_worker_pool_->CheckForCompletedTasks(); |
| 350 | 349 |
| 351 FreeResourcesForReleasedTiles(); | 350 FreeResourcesForReleasedTiles(); |
| 352 CleanUpReleasedTiles(); | 351 CleanUpReleasedTiles(); |
| 353 | 352 |
| 354 tile_task_runner_ = nullptr; | 353 tile_task_worker_pool_ = nullptr; |
| 355 resource_pool_ = nullptr; | 354 resource_pool_ = nullptr; |
| 356 more_tiles_need_prepare_check_notifier_.Cancel(); | 355 more_tiles_need_prepare_check_notifier_.Cancel(); |
| 357 signals_check_notifier_.Cancel(); | 356 signals_check_notifier_.Cancel(); |
| 358 task_set_finished_weak_ptr_factory_.InvalidateWeakPtrs(); | 357 task_set_finished_weak_ptr_factory_.InvalidateWeakPtrs(); |
| 359 } | 358 } |
| 360 | 359 |
| 361 void TileManager::SetResources(ResourcePool* resource_pool, | 360 void TileManager::SetResources(ResourcePool* resource_pool, |
| 362 TileTaskRunner* tile_task_runner, | 361 TileTaskWorkerPool* tile_task_worker_pool, |
| 363 ImageDecodeController* image_decode_controller, | 362 ImageDecodeController* image_decode_controller, |
| 364 size_t scheduled_raster_task_limit, | 363 size_t scheduled_raster_task_limit, |
| 365 bool use_gpu_rasterization) { | 364 bool use_gpu_rasterization) { |
| 366 DCHECK(!tile_task_runner_); | 365 DCHECK(!tile_task_worker_pool_); |
| 367 DCHECK(tile_task_runner); | 366 DCHECK(tile_task_worker_pool); |
| 368 | 367 |
| 369 use_gpu_rasterization_ = use_gpu_rasterization; | 368 use_gpu_rasterization_ = use_gpu_rasterization; |
| 370 scheduled_raster_task_limit_ = scheduled_raster_task_limit; | 369 scheduled_raster_task_limit_ = scheduled_raster_task_limit; |
| 371 resource_pool_ = resource_pool; | 370 resource_pool_ = resource_pool; |
| 372 tile_task_runner_ = tile_task_runner; | 371 tile_task_worker_pool_ = tile_task_worker_pool; |
| 373 image_decode_controller_ = image_decode_controller; | 372 image_decode_controller_ = image_decode_controller; |
| 374 } | 373 } |
| 375 | 374 |
| 376 void TileManager::Release(Tile* tile) { | 375 void TileManager::Release(Tile* tile) { |
| 377 released_tiles_.push_back(tile); | 376 released_tiles_.push_back(tile); |
| 378 } | 377 } |
| 379 | 378 |
| 380 void TileManager::FreeResourcesForReleasedTiles() { | 379 void TileManager::FreeResourcesForReleasedTiles() { |
| 381 for (auto* tile : released_tiles_) | 380 for (auto* tile : released_tiles_) |
| 382 FreeResourcesForTile(tile); | 381 FreeResourcesForTile(tile); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 413 TRACE_EVENT_ASYNC_STEP_INTO1("cc", "ScheduledTasks", this, "running", "state", | 412 TRACE_EVENT_ASYNC_STEP_INTO1("cc", "ScheduledTasks", this, "running", "state", |
| 414 ScheduledTasksStateAsValue()); | 413 ScheduledTasksStateAsValue()); |
| 415 signals_.ready_to_draw = true; | 414 signals_.ready_to_draw = true; |
| 416 signals_check_notifier_.Schedule(); | 415 signals_check_notifier_.Schedule(); |
| 417 } | 416 } |
| 418 | 417 |
| 419 void TileManager::DidFinishRunningAllTileTasks() { | 418 void TileManager::DidFinishRunningAllTileTasks() { |
| 420 TRACE_EVENT0("cc", "TileManager::DidFinishRunningAllTileTasks"); | 419 TRACE_EVENT0("cc", "TileManager::DidFinishRunningAllTileTasks"); |
| 421 TRACE_EVENT_ASYNC_END0("cc", "ScheduledTasks", this); | 420 TRACE_EVENT_ASYNC_END0("cc", "ScheduledTasks", this); |
| 422 DCHECK(resource_pool_); | 421 DCHECK(resource_pool_); |
| 423 DCHECK(tile_task_runner_); | 422 DCHECK(tile_task_worker_pool_); |
| 424 | 423 |
| 425 has_scheduled_tile_tasks_ = false; | 424 has_scheduled_tile_tasks_ = false; |
| 426 | 425 |
| 427 bool memory_usage_above_limit = resource_pool_->memory_usage_bytes() > | 426 bool memory_usage_above_limit = resource_pool_->memory_usage_bytes() > |
| 428 global_state_.soft_memory_limit_in_bytes; | 427 global_state_.soft_memory_limit_in_bytes; |
| 429 | 428 |
| 430 if (all_tiles_that_need_to_be_rasterized_are_scheduled_ && | 429 if (all_tiles_that_need_to_be_rasterized_are_scheduled_ && |
| 431 !memory_usage_above_limit) { | 430 !memory_usage_above_limit) { |
| 432 // TODO(ericrk): We should find a better way to safely handle re-entrant | 431 // TODO(ericrk): We should find a better way to safely handle re-entrant |
| 433 // notifications than always having to schedule a new task. | 432 // notifications than always having to schedule a new task. |
| 434 // http://crbug.com/498439 | 433 // http://crbug.com/498439 |
| 435 signals_.all_tile_tasks_completed = true; | 434 signals_.all_tile_tasks_completed = true; |
| 436 signals_check_notifier_.Schedule(); | 435 signals_check_notifier_.Schedule(); |
| 437 return; | 436 return; |
| 438 } | 437 } |
| 439 | 438 |
| 440 more_tiles_need_prepare_check_notifier_.Schedule(); | 439 more_tiles_need_prepare_check_notifier_.Schedule(); |
| 441 } | 440 } |
| 442 | 441 |
| 443 bool TileManager::PrepareTiles( | 442 bool TileManager::PrepareTiles( |
| 444 const GlobalStateThatImpactsTilePriority& state) { | 443 const GlobalStateThatImpactsTilePriority& state) { |
| 445 ++prepare_tiles_count_; | 444 ++prepare_tiles_count_; |
| 446 | 445 |
| 447 TRACE_EVENT1("cc", "TileManager::PrepareTiles", "prepare_tiles_id", | 446 TRACE_EVENT1("cc", "TileManager::PrepareTiles", "prepare_tiles_id", |
| 448 prepare_tiles_count_); | 447 prepare_tiles_count_); |
| 449 | 448 |
| 450 if (!tile_task_runner_) { | 449 if (!tile_task_worker_pool_) { |
| 451 TRACE_EVENT_INSTANT0("cc", "PrepareTiles aborted", | 450 TRACE_EVENT_INSTANT0("cc", "PrepareTiles aborted", |
| 452 TRACE_EVENT_SCOPE_THREAD); | 451 TRACE_EVENT_SCOPE_THREAD); |
| 453 return false; | 452 return false; |
| 454 } | 453 } |
| 455 | 454 |
| 456 signals_.reset(); | 455 signals_.reset(); |
| 457 global_state_ = state; | 456 global_state_ = state; |
| 458 | 457 |
| 459 // We need to call CheckForCompletedTasks() once in-between each call | 458 // We need to call CheckForCompletedTasks() once in-between each call |
| 460 // to ScheduleTasks() to prevent canceled tasks from being scheduled. | 459 // to ScheduleTasks() to prevent canceled tasks from being scheduled. |
| 461 if (!did_check_for_completed_tasks_since_last_schedule_tasks_) { | 460 if (!did_check_for_completed_tasks_since_last_schedule_tasks_) { |
| 462 tile_task_runner_->CheckForCompletedTasks(); | 461 tile_task_worker_pool_->CheckForCompletedTasks(); |
| 463 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 462 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
| 464 } | 463 } |
| 465 | 464 |
| 466 FreeResourcesForReleasedTiles(); | 465 FreeResourcesForReleasedTiles(); |
| 467 CleanUpReleasedTiles(); | 466 CleanUpReleasedTiles(); |
| 468 | 467 |
| 469 PrioritizedTileVector tiles_that_need_to_be_rasterized; | 468 PrioritizedTileVector tiles_that_need_to_be_rasterized; |
| 470 std::unique_ptr<RasterTilePriorityQueue> raster_priority_queue( | 469 std::unique_ptr<RasterTilePriorityQueue> raster_priority_queue( |
| 471 client_->BuildRasterQueue(global_state_.tree_priority, | 470 client_->BuildRasterQueue(global_state_.tree_priority, |
| 472 RasterTilePriorityQueue::Type::ALL)); | 471 RasterTilePriorityQueue::Type::ALL)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 484 ScheduleTasks(tiles_that_need_to_be_rasterized); | 483 ScheduleTasks(tiles_that_need_to_be_rasterized); |
| 485 | 484 |
| 486 TRACE_EVENT_INSTANT1("cc", "DidPrepareTiles", TRACE_EVENT_SCOPE_THREAD, | 485 TRACE_EVENT_INSTANT1("cc", "DidPrepareTiles", TRACE_EVENT_SCOPE_THREAD, |
| 487 "state", BasicStateAsValue()); | 486 "state", BasicStateAsValue()); |
| 488 return true; | 487 return true; |
| 489 } | 488 } |
| 490 | 489 |
| 491 void TileManager::Flush() { | 490 void TileManager::Flush() { |
| 492 TRACE_EVENT0("cc", "TileManager::Flush"); | 491 TRACE_EVENT0("cc", "TileManager::Flush"); |
| 493 | 492 |
| 494 if (!tile_task_runner_) { | 493 if (!tile_task_worker_pool_) { |
| 495 TRACE_EVENT_INSTANT0("cc", "Flush aborted", TRACE_EVENT_SCOPE_THREAD); | 494 TRACE_EVENT_INSTANT0("cc", "Flush aborted", TRACE_EVENT_SCOPE_THREAD); |
| 496 return; | 495 return; |
| 497 } | 496 } |
| 498 | 497 |
| 499 tile_task_runner_->CheckForCompletedTasks(); | 498 tile_task_worker_pool_->CheckForCompletedTasks(); |
| 500 | 499 |
| 501 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 500 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
| 502 | 501 |
| 503 TRACE_EVENT_INSTANT1("cc", "DidFlush", TRACE_EVENT_SCOPE_THREAD, "stats", | 502 TRACE_EVENT_INSTANT1("cc", "DidFlush", TRACE_EVENT_SCOPE_THREAD, "stats", |
| 504 RasterTaskCompletionStatsAsValue(flush_stats_)); | 503 RasterTaskCompletionStatsAsValue(flush_stats_)); |
| 505 flush_stats_ = RasterTaskCompletionStats(); | 504 flush_stats_ = RasterTaskCompletionStats(); |
| 506 } | 505 } |
| 507 | 506 |
| 508 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> | 507 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> |
| 509 TileManager::BasicStateAsValue() const { | 508 TileManager::BasicStateAsValue() const { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 return true; | 585 return true; |
| 587 } | 586 } |
| 588 | 587 |
| 589 void TileManager::AssignGpuMemoryToTiles( | 588 void TileManager::AssignGpuMemoryToTiles( |
| 590 RasterTilePriorityQueue* raster_priority_queue, | 589 RasterTilePriorityQueue* raster_priority_queue, |
| 591 size_t scheduled_raster_task_limit, | 590 size_t scheduled_raster_task_limit, |
| 592 PrioritizedTileVector* tiles_that_need_to_be_rasterized) { | 591 PrioritizedTileVector* tiles_that_need_to_be_rasterized) { |
| 593 TRACE_EVENT_BEGIN0("cc", "TileManager::AssignGpuMemoryToTiles"); | 592 TRACE_EVENT_BEGIN0("cc", "TileManager::AssignGpuMemoryToTiles"); |
| 594 | 593 |
| 595 DCHECK(resource_pool_); | 594 DCHECK(resource_pool_); |
| 596 DCHECK(tile_task_runner_); | 595 DCHECK(tile_task_worker_pool_); |
| 597 | 596 |
| 598 // Maintain the list of released resources that can potentially be re-used | 597 // Maintain the list of released resources that can potentially be re-used |
| 599 // or deleted. If this operation becomes expensive too, only do this after | 598 // or deleted. If this operation becomes expensive too, only do this after |
| 600 // some resource(s) was returned. Note that in that case, one also need to | 599 // some resource(s) was returned. Note that in that case, one also need to |
| 601 // invalidate when releasing some resource from the pool. | 600 // invalidate when releasing some resource from the pool. |
| 602 resource_pool_->CheckBusyResources(); | 601 resource_pool_->CheckBusyResources(); |
| 603 | 602 |
| 604 // Now give memory out to the tiles until we're out, and build | 603 // Now give memory out to the tiles until we're out, and build |
| 605 // the needs-to-be-rasterized queue. | 604 // the needs-to-be-rasterized queue. |
| 606 unsigned schedule_priority = 1u; | 605 unsigned schedule_priority = 1u; |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 823 kAllDoneTaskPriority, all_count); | 822 kAllDoneTaskPriority, all_count); |
| 824 | 823 |
| 825 // We must reduce the amount of unused resoruces before calling | 824 // We must reduce the amount of unused resoruces before calling |
| 826 // ScheduleTasks to prevent usage from rising above limits. | 825 // ScheduleTasks to prevent usage from rising above limits. |
| 827 resource_pool_->ReduceResourceUsage(); | 826 resource_pool_->ReduceResourceUsage(); |
| 828 image_decode_controller_->ReduceCacheUsage(); | 827 image_decode_controller_->ReduceCacheUsage(); |
| 829 | 828 |
| 830 // Schedule running of |raster_queue_|. This replaces any previously | 829 // Schedule running of |raster_queue_|. This replaces any previously |
| 831 // scheduled tasks and effectively cancels all tasks not present | 830 // scheduled tasks and effectively cancels all tasks not present |
| 832 // in |raster_queue_|. | 831 // in |raster_queue_|. |
| 833 tile_task_runner_->ScheduleTasks(&graph_); | 832 tile_task_worker_pool_->ScheduleTasks(&graph_); |
| 834 | 833 |
| 835 // It's now safe to clean up orphan tasks as raster worker pool is not | 834 // It's now safe to clean up orphan tasks as raster worker pool is not |
| 836 // allowed to keep around unreferenced raster tasks after ScheduleTasks() has | 835 // allowed to keep around unreferenced raster tasks after ScheduleTasks() has |
| 837 // been called. | 836 // been called. |
| 838 orphan_tasks_.clear(); | 837 orphan_tasks_.clear(); |
| 839 | 838 |
| 840 // It's also now safe to replace our *_done_task_ tasks. | 839 // It's also now safe to replace our *_done_task_ tasks. |
| 841 required_for_activation_done_task_ = | 840 required_for_activation_done_task_ = |
| 842 std::move(required_for_activation_done_task); | 841 std::move(required_for_activation_done_task); |
| 843 required_for_draw_done_task_ = std::move(required_for_draw_done_task); | 842 required_for_draw_done_task_ = std::move(required_for_draw_done_task); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 952 | 951 |
| 953 client_->NotifyTileStateChanged(tile); | 952 client_->NotifyTileStateChanged(tile); |
| 954 } | 953 } |
| 955 | 954 |
| 956 ScopedTilePtr TileManager::CreateTile(const Tile::CreateInfo& info, | 955 ScopedTilePtr TileManager::CreateTile(const Tile::CreateInfo& info, |
| 957 int layer_id, | 956 int layer_id, |
| 958 int source_frame_number, | 957 int source_frame_number, |
| 959 int flags) { | 958 int flags) { |
| 960 // We need to have a tile task worker pool to do anything meaningful with | 959 // We need to have a tile task worker pool to do anything meaningful with |
| 961 // tiles. | 960 // tiles. |
| 962 DCHECK(tile_task_runner_); | 961 DCHECK(tile_task_worker_pool_); |
| 963 ScopedTilePtr tile( | 962 ScopedTilePtr tile( |
| 964 new Tile(this, info, layer_id, source_frame_number, flags)); | 963 new Tile(this, info, layer_id, source_frame_number, flags)); |
| 965 DCHECK(tiles_.find(tile->id()) == tiles_.end()); | 964 DCHECK(tiles_.find(tile->id()) == tiles_.end()); |
| 966 | 965 |
| 967 tiles_[tile->id()] = tile.get(); | 966 tiles_[tile->id()] = tile.get(); |
| 968 return tile; | 967 return tile; |
| 969 } | 968 } |
| 970 | 969 |
| 971 void TileManager::SetTileTaskRunnerForTesting( | 970 void TileManager::SetTileTaskWorkerPoolForTesting( |
| 972 TileTaskRunner* tile_task_runner) { | 971 TileTaskWorkerPool* tile_task_worker_pool) { |
| 973 tile_task_runner_ = tile_task_runner; | 972 tile_task_worker_pool_ = tile_task_worker_pool; |
| 974 } | 973 } |
| 975 | 974 |
| 976 bool TileManager::AreRequiredTilesReadyToDraw( | 975 bool TileManager::AreRequiredTilesReadyToDraw( |
| 977 RasterTilePriorityQueue::Type type) const { | 976 RasterTilePriorityQueue::Type type) const { |
| 978 std::unique_ptr<RasterTilePriorityQueue> raster_priority_queue( | 977 std::unique_ptr<RasterTilePriorityQueue> raster_priority_queue( |
| 979 client_->BuildRasterQueue(global_state_.tree_priority, type)); | 978 client_->BuildRasterQueue(global_state_.tree_priority, type)); |
| 980 // It is insufficient to check whether the raster queue we constructed is | 979 // It is insufficient to check whether the raster queue we constructed is |
| 981 // empty. The reason for this is that there are situations (rasterize on | 980 // empty. The reason for this is that there are situations (rasterize on |
| 982 // demand) when the tile both needs raster and it's ready to draw. Hence, we | 981 // demand) when the tile both needs raster and it's ready to draw. Hence, we |
| 983 // have to iterate the queue to check whether the required tiles are ready to | 982 // have to iterate the queue to check whether the required tiles are ready to |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1006 } | 1005 } |
| 1007 | 1006 |
| 1008 bool TileManager::IsReadyToDraw() const { | 1007 bool TileManager::IsReadyToDraw() const { |
| 1009 TRACE_EVENT0("cc", "TileManager::IsReadyToDraw"); | 1008 TRACE_EVENT0("cc", "TileManager::IsReadyToDraw"); |
| 1010 return AreRequiredTilesReadyToDraw( | 1009 return AreRequiredTilesReadyToDraw( |
| 1011 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW); | 1010 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW); |
| 1012 } | 1011 } |
| 1013 | 1012 |
| 1014 void TileManager::CheckAndIssueSignals() { | 1013 void TileManager::CheckAndIssueSignals() { |
| 1015 TRACE_EVENT0("cc", "TileManager::CheckAndIssueSignals"); | 1014 TRACE_EVENT0("cc", "TileManager::CheckAndIssueSignals"); |
| 1016 tile_task_runner_->CheckForCompletedTasks(); | 1015 tile_task_worker_pool_->CheckForCompletedTasks(); |
| 1017 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 1016 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
| 1018 | 1017 |
| 1019 // Ready to activate. | 1018 // Ready to activate. |
| 1020 if (signals_.ready_to_activate && !signals_.did_notify_ready_to_activate) { | 1019 if (signals_.ready_to_activate && !signals_.did_notify_ready_to_activate) { |
| 1021 signals_.ready_to_activate = false; | 1020 signals_.ready_to_activate = false; |
| 1022 if (IsReadyToActivate()) { | 1021 if (IsReadyToActivate()) { |
| 1023 TRACE_EVENT0("disabled-by-default-cc.debug", | 1022 TRACE_EVENT0("disabled-by-default-cc.debug", |
| 1024 "TileManager::CheckAndIssueSignals - ready to activate"); | 1023 "TileManager::CheckAndIssueSignals - ready to activate"); |
| 1025 signals_.did_notify_ready_to_activate = true; | 1024 signals_.did_notify_ready_to_activate = true; |
| 1026 client_->NotifyReadyToActivate(); | 1025 client_->NotifyReadyToActivate(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1046 TRACE_EVENT0( | 1045 TRACE_EVENT0( |
| 1047 "disabled-by-default-cc.debug", | 1046 "disabled-by-default-cc.debug", |
| 1048 "TileManager::CheckAndIssueSignals - all tile tasks completed"); | 1047 "TileManager::CheckAndIssueSignals - all tile tasks completed"); |
| 1049 signals_.did_notify_all_tile_tasks_completed = true; | 1048 signals_.did_notify_all_tile_tasks_completed = true; |
| 1050 client_->NotifyAllTileTasksCompleted(); | 1049 client_->NotifyAllTileTasksCompleted(); |
| 1051 } | 1050 } |
| 1052 } | 1051 } |
| 1053 } | 1052 } |
| 1054 | 1053 |
| 1055 void TileManager::CheckIfMoreTilesNeedToBePrepared() { | 1054 void TileManager::CheckIfMoreTilesNeedToBePrepared() { |
| 1056 tile_task_runner_->CheckForCompletedTasks(); | 1055 tile_task_worker_pool_->CheckForCompletedTasks(); |
| 1057 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; | 1056 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; |
| 1058 | 1057 |
| 1059 // When OOM, keep re-assigning memory until we reach a steady state | 1058 // When OOM, keep re-assigning memory until we reach a steady state |
| 1060 // where top-priority tiles are initialized. | 1059 // where top-priority tiles are initialized. |
| 1061 PrioritizedTileVector tiles_that_need_to_be_rasterized; | 1060 PrioritizedTileVector tiles_that_need_to_be_rasterized; |
| 1062 std::unique_ptr<RasterTilePriorityQueue> raster_priority_queue( | 1061 std::unique_ptr<RasterTilePriorityQueue> raster_priority_queue( |
| 1063 client_->BuildRasterQueue(global_state_.tree_priority, | 1062 client_->BuildRasterQueue(global_state_.tree_priority, |
| 1064 RasterTilePriorityQueue::Type::ALL)); | 1063 RasterTilePriorityQueue::Type::ALL)); |
| 1065 AssignGpuMemoryToTiles(raster_priority_queue.get(), | 1064 AssignGpuMemoryToTiles(raster_priority_queue.get(), |
| 1066 scheduled_raster_task_limit_, | 1065 scheduled_raster_task_limit_, |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1133 Tile* tile = queue->Top().tile(); | 1132 Tile* tile = queue->Top().tile(); |
| 1134 if (tile->draw_info().IsReadyToDraw()) | 1133 if (tile->draw_info().IsReadyToDraw()) |
| 1135 continue; | 1134 continue; |
| 1136 tile->draw_info().set_oom(); | 1135 tile->draw_info().set_oom(); |
| 1137 client_->NotifyTileStateChanged(tile); | 1136 client_->NotifyTileStateChanged(tile); |
| 1138 } | 1137 } |
| 1139 return true; | 1138 return true; |
| 1140 } | 1139 } |
| 1141 | 1140 |
| 1142 ResourceFormat TileManager::DetermineResourceFormat(const Tile* tile) const { | 1141 ResourceFormat TileManager::DetermineResourceFormat(const Tile* tile) const { |
| 1143 return tile_task_runner_->GetResourceFormat(!tile->is_opaque()); | 1142 return tile_task_worker_pool_->GetResourceFormat(!tile->is_opaque()); |
| 1144 } | 1143 } |
| 1145 | 1144 |
| 1146 bool TileManager::DetermineResourceRequiresSwizzle(const Tile* tile) const { | 1145 bool TileManager::DetermineResourceRequiresSwizzle(const Tile* tile) const { |
| 1147 return tile_task_runner_->GetResourceRequiresSwizzle(!tile->is_opaque()); | 1146 return tile_task_worker_pool_->GetResourceRequiresSwizzle(!tile->is_opaque()); |
| 1148 } | 1147 } |
| 1149 | 1148 |
| 1150 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> | 1149 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> |
| 1151 TileManager::ScheduledTasksStateAsValue() const { | 1150 TileManager::ScheduledTasksStateAsValue() const { |
| 1152 std::unique_ptr<base::trace_event::TracedValue> state( | 1151 std::unique_ptr<base::trace_event::TracedValue> state( |
| 1153 new base::trace_event::TracedValue()); | 1152 new base::trace_event::TracedValue()); |
| 1154 state->BeginDictionary("tasks_pending"); | 1153 state->BeginDictionary("tasks_pending"); |
| 1155 state->SetBoolean("ready_to_activate", signals_.ready_to_activate); | 1154 state->SetBoolean("ready_to_activate", signals_.ready_to_activate); |
| 1156 state->SetBoolean("ready_to_draw", signals_.ready_to_draw); | 1155 state->SetBoolean("ready_to_draw", signals_.ready_to_draw); |
| 1157 state->SetBoolean("all_tile_tasks_completed", | 1156 state->SetBoolean("all_tile_tasks_completed", |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1239 void TileManager::Signals::reset() { | 1238 void TileManager::Signals::reset() { |
| 1240 ready_to_activate = false; | 1239 ready_to_activate = false; |
| 1241 did_notify_ready_to_activate = false; | 1240 did_notify_ready_to_activate = false; |
| 1242 ready_to_draw = false; | 1241 ready_to_draw = false; |
| 1243 did_notify_ready_to_draw = false; | 1242 did_notify_ready_to_draw = false; |
| 1244 all_tile_tasks_completed = false; | 1243 all_tile_tasks_completed = false; |
| 1245 did_notify_all_tile_tasks_completed = false; | 1244 did_notify_all_tile_tasks_completed = false; |
| 1246 } | 1245 } |
| 1247 | 1246 |
| 1248 } // namespace cc | 1247 } // namespace cc |
| OLD | NEW |