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 <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "cc/debug/devtools_instrumentation.h" | 14 #include "cc/debug/devtools_instrumentation.h" |
| 15 #include "cc/debug/traced_value.h" | 15 #include "cc/debug/traced_value.h" |
| 16 #include "cc/resources/raster_worker_pool.h" | 16 #include "cc/resources/image_raster_worker_pool.h" |
| 17 #include "cc/resources/resource_pool.h" | 17 #include "cc/resources/pixel_buffer_raster_worker_pool.h" |
| 18 #include "cc/resources/tile.h" | 18 #include "cc/resources/tile.h" |
| 19 #include "third_party/skia/include/core/SkDevice.h" | 19 #include "third_party/skia/include/core/SkDevice.h" |
| 20 #include "ui/gfx/rect_conversions.h" | 20 #include "ui/gfx/rect_conversions.h" |
| 21 | 21 |
| 22 namespace cc { | 22 namespace cc { |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 // If we raster too fast we become upload bound, and pending | |
| 27 // uploads consume memory. For maximum upload throughput, we would | |
| 28 // want to allow for upload_throughput * pipeline_time of pending | |
| 29 // uploads, after which we are just wasting memory. Since we don't | |
| 30 // know our upload throughput yet, this just caps our memory usage. | |
| 31 #if defined(OS_ANDROID) | |
| 32 // For reference, the Nexus10 can upload 1MB in about 2.5ms. | |
| 33 // Assuming a three frame deep pipeline this implies ~20MB. | |
| 34 const size_t kMaxPendingUploadBytes = 20 * 1024 * 1024; | |
| 35 // TODO(epenner): We should remove this upload limit (crbug.com/176197) | |
| 36 const size_t kMaxPendingUploads = 72; | |
| 37 #else | |
| 38 const size_t kMaxPendingUploadBytes = 100 * 1024 * 1024; | |
| 39 const size_t kMaxPendingUploads = 1000; | |
| 40 #endif | |
| 41 | |
| 42 #if defined(OS_ANDROID) | |
| 43 const int kMaxNumPendingTasksPerThread = 8; | |
| 44 #else | |
| 45 const int kMaxNumPendingTasksPerThread = 40; | |
| 46 #endif | |
| 47 | |
| 48 // Determine bin based on three categories of tiles: things we need now, | 26 // Determine bin based on three categories of tiles: things we need now, |
| 49 // things we need soon, and eventually. | 27 // things we need soon, and eventually. |
| 50 inline TileManagerBin BinFromTilePriority(const TilePriority& prio) { | 28 inline TileManagerBin BinFromTilePriority(const TilePriority& prio) { |
| 51 // The amount of time for which we want to have prepainting coverage. | 29 // The amount of time for which we want to have prepainting coverage. |
| 52 const float kPrepaintingWindowTimeSeconds = 1.0f; | 30 const float kPrepaintingWindowTimeSeconds = 1.0f; |
| 53 const float kBackflingGuardDistancePixels = 314.0f; | 31 const float kBackflingGuardDistancePixels = 314.0f; |
| 54 | 32 |
| 55 if (prio.time_to_visible_in_seconds == 0) | 33 if (prio.time_to_visible_in_seconds == 0) |
| 56 return NOW_BIN; | 34 return NOW_BIN; |
| 57 | 35 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 } | 83 } |
| 106 | 84 |
| 107 // static | 85 // static |
| 108 scoped_ptr<TileManager> TileManager::Create( | 86 scoped_ptr<TileManager> TileManager::Create( |
| 109 TileManagerClient* client, | 87 TileManagerClient* client, |
| 110 ResourceProvider* resource_provider, | 88 ResourceProvider* resource_provider, |
| 111 size_t num_raster_threads, | 89 size_t num_raster_threads, |
| 112 bool use_color_estimator, | 90 bool use_color_estimator, |
| 113 RenderingStatsInstrumentation* rendering_stats_instrumentation, | 91 RenderingStatsInstrumentation* rendering_stats_instrumentation, |
| 114 bool use_map_image) { | 92 bool use_map_image) { |
| 115 scoped_ptr<RasterWorkerPool> raster_worker_pool = | 93 return make_scoped_ptr( |
| 116 RasterWorkerPool::Create(num_raster_threads); | 94 new TileManager(client, |
| 117 return make_scoped_ptr(new TileManager(client, | 95 resource_provider, |
| 118 resource_provider, | 96 use_map_image ? |
| 119 raster_worker_pool.Pass(), | 97 ImageRasterWorkerPool::Create( |
| 120 num_raster_threads, | 98 resource_provider, num_raster_threads) : |
| 121 use_color_estimator, | 99 PixelBufferRasterWorkerPool::Create( |
| 122 rendering_stats_instrumentation, | 100 resource_provider, num_raster_threads), |
| 123 use_map_image)); | 101 num_raster_threads, |
| 102 use_color_estimator, | |
| 103 rendering_stats_instrumentation, | |
| 104 use_map_image)); | |
| 124 } | 105 } |
| 125 | 106 |
| 126 TileManager::TileManager( | 107 TileManager::TileManager( |
| 127 TileManagerClient* client, | 108 TileManagerClient* client, |
| 128 ResourceProvider* resource_provider, | 109 ResourceProvider* resource_provider, |
| 129 scoped_ptr<RasterWorkerPool> raster_worker_pool, | 110 scoped_ptr<RasterWorkerPool> raster_worker_pool, |
| 130 size_t num_raster_threads, | 111 size_t num_raster_threads, |
| 131 bool use_color_estimator, | 112 bool use_color_estimator, |
| 132 RenderingStatsInstrumentation* rendering_stats_instrumentation, | 113 RenderingStatsInstrumentation* rendering_stats_instrumentation, |
| 133 bool use_map_image) | 114 bool use_map_image) |
| 134 : client_(client), | 115 : client_(client), |
| 135 resource_pool_(ResourcePool::Create(resource_provider)), | 116 resource_pool_(ResourcePool::Create(resource_provider)), |
| 136 raster_worker_pool_(raster_worker_pool.Pass()), | 117 raster_worker_pool_(raster_worker_pool.Pass()), |
| 137 manage_tiles_pending_(false), | 118 manage_tiles_pending_(false), |
| 138 bytes_pending_upload_(0), | |
| 139 has_performed_uploads_since_last_flush_(false), | |
| 140 ever_exceeded_memory_budget_(false), | 119 ever_exceeded_memory_budget_(false), |
| 141 rendering_stats_instrumentation_(rendering_stats_instrumentation), | 120 rendering_stats_instrumentation_(rendering_stats_instrumentation), |
| 142 use_color_estimator_(use_color_estimator), | 121 use_color_estimator_(use_color_estimator), |
| 143 did_initialize_visible_tile_(false), | 122 did_initialize_visible_tile_(false) { |
| 144 max_pending_tasks_(kMaxNumPendingTasksPerThread * num_raster_threads) { | |
| 145 raster_worker_pool_->SetClient(this); | 123 raster_worker_pool_->SetClient(this); |
| 146 } | 124 } |
| 147 | 125 |
| 148 TileManager::~TileManager() { | 126 TileManager::~TileManager() { |
| 149 // Reset global state and manage. This should cause | 127 // Reset global state and manage. This should cause |
| 150 // our memory usage to drop to zero. | 128 // our memory usage to drop to zero. |
| 151 global_state_ = GlobalStateThatImpactsTilePriority(); | 129 global_state_ = GlobalStateThatImpactsTilePriority(); |
| 152 AssignGpuMemoryToTiles(); | 130 AssignGpuMemoryToTiles(); |
| 153 // This should finish all pending tasks and release any uninitialized | 131 // This should finish all pending tasks and release any uninitialized |
| 154 // resources. | 132 // resources. |
| 155 raster_worker_pool_->Shutdown(); | 133 raster_worker_pool_->Shutdown(); |
| 156 AbortPendingTileUploads(); | |
| 157 DCHECK_EQ(0u, tiles_with_pending_upload_.size()); | |
| 158 DCHECK_EQ(0u, tiles_.size()); | 134 DCHECK_EQ(0u, tiles_.size()); |
| 159 } | 135 } |
| 160 | 136 |
| 161 void TileManager::SetGlobalState( | 137 void TileManager::SetGlobalState( |
| 162 const GlobalStateThatImpactsTilePriority& global_state) { | 138 const GlobalStateThatImpactsTilePriority& global_state) { |
| 163 global_state_ = global_state; | 139 global_state_ = global_state; |
| 164 resource_pool_->SetMaxMemoryUsageBytes( | 140 resource_pool_->SetMaxMemoryUsageBytes( |
| 165 global_state_.memory_limit_in_bytes, | 141 global_state_.memory_limit_in_bytes, |
| 166 global_state_.unused_memory_limit_in_bytes); | 142 global_state_.unused_memory_limit_in_bytes); |
| 167 ScheduleManageTiles(); | 143 ScheduleManageTiles(); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 | 290 |
| 315 TRACE_EVENT_INSTANT1( | 291 TRACE_EVENT_INSTANT1( |
| 316 "cc", "DidManage", TRACE_EVENT_SCOPE_THREAD, | 292 "cc", "DidManage", TRACE_EVENT_SCOPE_THREAD, |
| 317 "state", TracedValue::FromValue(BasicStateAsValue().release())); | 293 "state", TracedValue::FromValue(BasicStateAsValue().release())); |
| 318 | 294 |
| 319 // Finally, schedule rasterizer tasks. | 295 // Finally, schedule rasterizer tasks. |
| 320 ScheduleTasks(); | 296 ScheduleTasks(); |
| 321 } | 297 } |
| 322 | 298 |
| 323 void TileManager::CheckForCompletedTileUploads() { | 299 void TileManager::CheckForCompletedTileUploads() { |
| 324 while (!tiles_with_pending_upload_.empty()) { | 300 raster_worker_pool_->CheckForCompletedTasks(); |
| 325 Tile* tile = tiles_with_pending_upload_.front(); | |
| 326 DCHECK(tile->tile_version().resource_); | |
| 327 | |
| 328 // Set pixel tasks complete in the order they are posted. | |
| 329 if (!resource_pool_->resource_provider()->DidSetPixelsComplete( | |
| 330 tile->tile_version().resource_->id())) { | |
| 331 break; | |
| 332 } | |
| 333 | |
| 334 // It's now safe to release the pixel buffer. | |
| 335 resource_pool_->resource_provider()->ReleasePixelBuffer( | |
| 336 tile->tile_version().resource_->id()); | |
| 337 | |
| 338 bytes_pending_upload_ -= tile->bytes_consumed_if_allocated(); | |
| 339 bool was_forced = tile->tile_version().forced_upload_; | |
| 340 // Reset forced_upload_ since we now got the upload completed notification. | |
| 341 tile->tile_version().forced_upload_ = false; | |
| 342 tile->tile_version().memory_state_ = USING_RELEASABLE_MEMORY; | |
| 343 if (!was_forced) | |
| 344 DidFinishTileInitialization(tile); | |
| 345 | |
| 346 tiles_with_pending_upload_.pop(); | |
| 347 } | |
| 348 | |
| 349 ScheduleTasks(); | |
| 350 } | |
| 351 | |
| 352 void TileManager::AbortPendingTileUploads() { | |
| 353 while (!tiles_with_pending_upload_.empty()) { | |
| 354 Tile* tile = tiles_with_pending_upload_.front(); | |
| 355 DCHECK(tile->tile_version().resource_); | |
| 356 | |
| 357 resource_pool_->resource_provider()->AbortSetPixels( | |
| 358 tile->tile_version().resource_->id()); | |
| 359 resource_pool_->resource_provider()->ReleasePixelBuffer( | |
| 360 tile->tile_version().resource_->id()); | |
| 361 tile->tile_version().memory_state_ = USING_RELEASABLE_MEMORY; | |
| 362 | |
| 363 FreeResourcesForTile(tile); | |
| 364 | |
| 365 bytes_pending_upload_ -= tile->bytes_consumed_if_allocated(); | |
| 366 tiles_with_pending_upload_.pop(); | |
| 367 } | |
| 368 } | 301 } |
| 369 | 302 |
| 370 void TileManager::ForceTileUploadToComplete(Tile* tile) { | 303 void TileManager::ForceTileUploadToComplete(Tile* tile) { |
| 371 DCHECK(tile); | 304 DCHECK(tile); |
| 372 if (tile->tile_version().resource_ && | 305 if (tile->tile_version().resource_id_ && |
| 373 tile->tile_version().memory_state_ == USING_UNRELEASABLE_MEMORY && | 306 tile->tile_version().memory_state_ == USING_UNRELEASABLE_MEMORY && |
| 374 !tile->tile_version().forced_upload_) { | 307 !tile->tile_version().forced_upload_) { |
| 375 resource_pool_->resource_provider()-> | 308 if (!raster_worker_pool_->ForceUploadToComplete( |
| 376 ForceSetPixelsToComplete(tile->tile_version().resource_->id()); | 309 tile->tile_version().resource_id_)) |
| 310 return; | |
| 377 | 311 |
| 378 // We have to set the memory state to be unreleasable, to ensure | 312 // Setting |forced_upload_| to true makes this tile ready to draw. |
| 379 // that the tile will not be freed until we get the upload finished | |
| 380 // notification. However, setting |forced_upload_| to true makes | |
| 381 // this tile ready to draw. | |
| 382 tile->tile_version().memory_state_ = USING_UNRELEASABLE_MEMORY; | |
| 383 tile->tile_version().forced_upload_ = true; | 313 tile->tile_version().forced_upload_ = true; |
| 384 DidFinishTileInitialization(tile); | 314 DidFinishTileInitialization(tile); |
| 385 DCHECK(tile->tile_version().IsReadyToDraw()); | 315 DCHECK(tile->tile_version().IsReadyToDraw()); |
| 386 } | 316 } |
| 387 | 317 |
| 388 if (did_initialize_visible_tile_) { | 318 if (did_initialize_visible_tile_) { |
| 389 did_initialize_visible_tile_ = false; | 319 did_initialize_visible_tile_ = false; |
| 390 client_->DidInitializeVisibleTile(); | 320 client_->DidInitializeVisibleTile(); |
| 391 } | 321 } |
| 392 } | 322 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 452 } | 382 } |
| 453 | 383 |
| 454 void TileManager::AddRequiredTileForActivation(Tile* tile) { | 384 void TileManager::AddRequiredTileForActivation(Tile* tile) { |
| 455 DCHECK(std::find(tiles_that_need_to_be_initialized_for_activation_.begin(), | 385 DCHECK(std::find(tiles_that_need_to_be_initialized_for_activation_.begin(), |
| 456 tiles_that_need_to_be_initialized_for_activation_.end(), | 386 tiles_that_need_to_be_initialized_for_activation_.end(), |
| 457 tile) == | 387 tile) == |
| 458 tiles_that_need_to_be_initialized_for_activation_.end()); | 388 tiles_that_need_to_be_initialized_for_activation_.end()); |
| 459 tiles_that_need_to_be_initialized_for_activation_.insert(tile); | 389 tiles_that_need_to_be_initialized_for_activation_.insert(tile); |
| 460 } | 390 } |
| 461 | 391 |
| 462 void TileManager::DidFinishDispatchingWorkerPoolCompletionCallbacks() { | 392 void TileManager::DidFinishDispatchingRasterWorkerPoolCompletionCallbacks() { |
| 463 // If a flush is needed, do it now before starting to dispatch more tasks. | 393 if (did_initialize_visible_tile_) { |
|
vmpstr
2013/05/29 16:55:03
This block of code repeats in at least one other s
reveman
2013/05/29 19:39:12
I'm planning to remove this function and the Raste
vmpstr
2013/05/29 20:45:06
Sounds good.
reveman
2013/05/30 01:46:10
Please take a look at latest patch.
| |
| 464 if (has_performed_uploads_since_last_flush_) { | 394 did_initialize_visible_tile_ = false; |
| 465 resource_pool_->resource_provider()->ShallowFlushIfSupported(); | 395 client_->DidInitializeVisibleTile(); |
| 466 has_performed_uploads_since_last_flush_ = false; | |
| 467 } | 396 } |
| 468 | |
| 469 ScheduleTasks(); | |
| 470 } | 397 } |
| 471 | 398 |
| 472 void TileManager::AssignGpuMemoryToTiles() { | 399 void TileManager::AssignGpuMemoryToTiles() { |
| 473 TRACE_EVENT0("cc", "TileManager::AssignGpuMemoryToTiles"); | 400 TRACE_EVENT0("cc", "TileManager::AssignGpuMemoryToTiles"); |
| 474 size_t unreleasable_bytes = 0; | 401 size_t unreleasable_bytes = 0; |
| 475 | 402 |
| 476 // Now give memory out to the tiles until we're out, and build | 403 // Now give memory out to the tiles until we're out, and build |
| 477 // the needs-to-be-rasterized queue. | 404 // the needs-to-be-rasterized queue. |
| 478 tiles_that_need_to_be_rasterized_.clear(); | 405 tiles_that_need_to_be_rasterized_.clear(); |
| 479 tiles_that_need_to_be_initialized_for_activation_.clear(); | 406 tiles_that_need_to_be_initialized_for_activation_.clear(); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 631 DCHECK_NE(USING_UNRELEASABLE_MEMORY, tile->tile_version().memory_state_); | 558 DCHECK_NE(USING_UNRELEASABLE_MEMORY, tile->tile_version().memory_state_); |
| 632 if (tile->tile_version().resource_) { | 559 if (tile->tile_version().resource_) { |
| 633 resource_pool_->ReleaseResource( | 560 resource_pool_->ReleaseResource( |
| 634 tile->tile_version().resource_.Pass()); | 561 tile->tile_version().resource_.Pass()); |
| 635 } | 562 } |
| 636 tile->tile_version().memory_state_ = NOT_ALLOWED_TO_USE_MEMORY; | 563 tile->tile_version().memory_state_ = NOT_ALLOWED_TO_USE_MEMORY; |
| 637 } | 564 } |
| 638 | 565 |
| 639 void TileManager::ScheduleTasks() { | 566 void TileManager::ScheduleTasks() { |
| 640 TRACE_EVENT0("cc", "TileManager::ScheduleTasks"); | 567 TRACE_EVENT0("cc", "TileManager::ScheduleTasks"); |
| 641 RasterWorkerPool::Task::Queue tasks; | 568 RasterWorkerPool::RasterTask::Queue tasks; |
| 642 | |
| 643 size_t bytes_pending_upload = bytes_pending_upload_; | |
| 644 unsigned pending_tasks = 0; | |
| 645 | 569 |
| 646 // Build a new task queue containing all task currently needed. Tasks | 570 // Build a new task queue containing all task currently needed. Tasks |
| 647 // are added in order of priority, highest priority task first. | 571 // are added in order of priority, highest priority task first. |
| 648 for (TileVector::iterator it = tiles_that_need_to_be_rasterized_.begin(); | 572 for (TileVector::iterator it = tiles_that_need_to_be_rasterized_.begin(); |
| 649 it != tiles_that_need_to_be_rasterized_.end(); | 573 it != tiles_that_need_to_be_rasterized_.end(); |
| 650 ++it) { | 574 ++it) { |
| 651 Tile* tile = *it; | 575 Tile* tile = *it; |
| 652 ManagedTileState& mts = tile->managed_state(); | 576 ManagedTileState& mts = tile->managed_state(); |
| 653 | 577 |
| 654 // Skip tile if determined to not require resource. | 578 DCHECK(tile->tile_version().requires_resource()); |
| 655 if (!tile->tile_version().requires_resource()) | 579 DCHECK(!tile->tile_version().resource_); |
| 656 continue; | |
| 657 | |
| 658 // Skip tile if already rasterized. | |
| 659 if (tile->tile_version().resource_) | |
| 660 continue; | |
| 661 | |
| 662 // TODO(reveman): Remove throttling based on max pending tasks. | |
| 663 if (pending_tasks >= max_pending_tasks_) | |
| 664 break; | |
| 665 | |
| 666 // TODO(reveman): Remove throttling based on max pending uploads. | |
| 667 if (tiles_with_pending_upload_.size() >= kMaxPendingUploads) | |
| 668 break; | |
| 669 | |
| 670 // TODO(reveman): Throttle based on shared memory usage rather | |
| 671 // than bytes pending upload. | |
| 672 size_t new_bytes_pending = bytes_pending_upload; | |
| 673 new_bytes_pending += tile->bytes_consumed_if_allocated(); | |
| 674 if (new_bytes_pending > kMaxPendingUploadBytes) | |
| 675 break; | |
| 676 bytes_pending_upload = new_bytes_pending; | |
| 677 | 580 |
| 678 // Create raster task for this tile if necessary. | 581 // Create raster task for this tile if necessary. |
| 679 if (mts.raster_task.is_null()) | 582 if (mts.raster_task.is_null()) |
| 680 mts.raster_task = CreateRasterTask(tile); | 583 mts.raster_task = CreateRasterTask(tile); |
| 681 | 584 |
| 682 // Finally append raster task. | 585 // Finally append raster task. |
| 683 tasks.Append(mts.raster_task); | 586 tasks.Append(mts.raster_task); |
| 684 pending_tasks++; | |
| 685 } | 587 } |
| 686 | 588 |
| 687 if (!tasks.empty()) { | 589 // Schedule running of |tasks|. This replaces any previously |
| 688 RasterWorkerPool::Task root(&tasks); | 590 // scheduled tasks and effectively cancels all tasks not present |
| 689 | 591 // in |tasks|. |
| 690 // Schedule running of |tasks|. This replaces any previously | 592 raster_worker_pool_->ScheduleTasks(&tasks); |
| 691 // scheduled tasks and effectively cancels all tasks not present | |
| 692 // in |tasks|. | |
| 693 raster_worker_pool_->ScheduleTasks(&root); | |
| 694 } else { | |
| 695 raster_worker_pool_->ScheduleTasks(NULL); | |
| 696 } | |
| 697 | |
| 698 if (did_initialize_visible_tile_) { | |
| 699 did_initialize_visible_tile_ = false; | |
| 700 client_->DidInitializeVisibleTile(); | |
| 701 } | |
| 702 } | 593 } |
| 703 | 594 |
| 704 RasterWorkerPool::Task TileManager::CreateImageDecodeTask( | 595 RasterWorkerPool::Task TileManager::CreateImageDecodeTask( |
| 705 Tile* tile, skia::LazyPixelRef* pixel_ref) { | 596 Tile* tile, skia::LazyPixelRef* pixel_ref) { |
| 706 TRACE_EVENT0("cc", "TileManager::CreateImageDecodeTask"); | 597 TRACE_EVENT0("cc", "TileManager::CreateImageDecodeTask"); |
| 707 | 598 |
| 708 return RasterWorkerPool::Task( | 599 return RasterWorkerPool::Task( |
| 709 base::Bind(&TileManager::RunImageDecodeTask, | 600 base::Bind(&TileManager::RunImageDecodeTask, |
| 710 pixel_ref, | 601 pixel_ref, |
| 711 tile->layer_id(), | 602 tile->layer_id(), |
| 712 rendering_stats_instrumentation_), | 603 rendering_stats_instrumentation_), |
| 713 base::Bind(&TileManager::OnImageDecodeTaskCompleted, | 604 base::Bind(&TileManager::OnImageDecodeTaskCompleted, |
| 714 base::Unretained(this), | 605 base::Unretained(this), |
| 715 make_scoped_refptr(tile), | 606 make_scoped_refptr(tile), |
| 716 pixel_ref->getGenerationID())); | 607 pixel_ref->getGenerationID())); |
| 717 } | 608 } |
| 718 | 609 |
| 719 void TileManager::OnImageDecodeTaskCompleted(scoped_refptr<Tile> tile, | 610 void TileManager::OnImageDecodeTaskCompleted(scoped_refptr<Tile> tile, |
| 720 uint32_t pixel_ref_id, | 611 uint32_t pixel_ref_id) { |
| 721 bool was_canceled) { | |
| 722 TRACE_EVENT0("cc", "TileManager::OnImageDecodeTaskCompleted"); | 612 TRACE_EVENT0("cc", "TileManager::OnImageDecodeTaskCompleted"); |
| 723 DCHECK(pending_decode_tasks_.find(pixel_ref_id) != | 613 DCHECK(pending_decode_tasks_.find(pixel_ref_id) != |
| 724 pending_decode_tasks_.end()); | 614 pending_decode_tasks_.end()); |
| 725 pending_decode_tasks_.erase(pixel_ref_id); | 615 pending_decode_tasks_.erase(pixel_ref_id); |
| 726 } | 616 } |
| 727 | 617 |
| 728 TileManager::RasterTaskMetadata TileManager::GetRasterTaskMetadata( | 618 TileManager::RasterTaskMetadata TileManager::GetRasterTaskMetadata( |
| 729 const Tile& tile) const { | 619 const Tile& tile) const { |
| 730 RasterTaskMetadata metadata; | 620 RasterTaskMetadata metadata; |
| 731 const ManagedTileState& mts = tile.managed_state(); | 621 const ManagedTileState& mts = tile.managed_state(); |
| 732 metadata.is_tile_in_pending_tree_now_bin = | 622 metadata.is_tile_in_pending_tree_now_bin = |
| 733 mts.tree_bin[PENDING_TREE] == NOW_BIN; | 623 mts.tree_bin[PENDING_TREE] == NOW_BIN; |
| 734 metadata.tile_resolution = mts.resolution; | 624 metadata.tile_resolution = mts.resolution; |
| 735 metadata.layer_id = tile.layer_id(); | 625 metadata.layer_id = tile.layer_id(); |
| 736 metadata.tile_id = &tile; | 626 metadata.tile_id = &tile; |
| 737 metadata.source_frame_number = tile.source_frame_number(); | 627 metadata.source_frame_number = tile.source_frame_number(); |
| 738 return metadata; | 628 return metadata; |
| 739 } | 629 } |
| 740 | 630 |
| 741 RasterWorkerPool::Task TileManager::CreateRasterTask(Tile* tile) { | 631 RasterWorkerPool::RasterTask TileManager::CreateRasterTask(Tile* tile) { |
| 742 TRACE_EVENT0("cc", "TileManager::CreateRasterTask"); | 632 TRACE_EVENT0("cc", "TileManager::CreateRasterTask"); |
| 743 | 633 |
| 744 scoped_ptr<ResourcePool::Resource> resource = | 634 scoped_ptr<ResourcePool::Resource> resource = |
| 745 resource_pool_->AcquireResource( | 635 resource_pool_->AcquireResource( |
| 746 tile->tile_size_.size(), | 636 tile->tile_size_.size(), |
| 747 tile->tile_version().resource_format_); | 637 tile->tile_version().resource_format_); |
| 748 resource_pool_->resource_provider()->AcquirePixelBuffer(resource->id()); | 638 const Resource* const_resource = resource.get(); |
| 749 | 639 |
| 750 DCHECK_EQ(CAN_USE_MEMORY, tile->tile_version().memory_state_); | 640 DCHECK_EQ(CAN_USE_MEMORY, tile->tile_version().memory_state_); |
| 751 tile->tile_version().memory_state_ = USING_UNRELEASABLE_MEMORY; | 641 tile->tile_version().memory_state_ = USING_UNRELEASABLE_MEMORY; |
| 752 | 642 |
| 753 PicturePileImpl::Analysis* analysis = new PicturePileImpl::Analysis; | 643 PicturePileImpl::Analysis* analysis = new PicturePileImpl::Analysis; |
| 754 | 644 |
| 755 // MapPixelBuffer() returns NULL if context was lost at the time | |
| 756 // AcquirePixelBuffer() was called. For simplicity we still create | |
| 757 // a raster task that is essentially a noop in these situations. | |
| 758 uint8* buffer = resource_pool_->resource_provider()->MapPixelBuffer( | |
| 759 resource->id()); | |
| 760 | |
| 761 // Create and queue all image decode tasks that this tile depends on. | 645 // Create and queue all image decode tasks that this tile depends on. |
| 762 RasterWorkerPool::Task::Queue decode_tasks; | 646 RasterWorkerPool::Task::Set decode_tasks; |
| 763 for (PicturePileImpl::PixelRefIterator iter(tile->content_rect(), | 647 for (PicturePileImpl::PixelRefIterator iter(tile->content_rect(), |
| 764 tile->contents_scale(), | 648 tile->contents_scale(), |
| 765 tile->picture_pile()); | 649 tile->picture_pile()); |
| 766 iter; ++iter) { | 650 iter; ++iter) { |
| 767 skia::LazyPixelRef* pixel_ref = *iter; | 651 skia::LazyPixelRef* pixel_ref = *iter; |
| 768 uint32_t id = pixel_ref->getGenerationID(); | 652 uint32_t id = pixel_ref->getGenerationID(); |
| 769 | 653 |
| 770 // Append existing image decode task if available. | 654 // Append existing image decode task if available. |
| 771 PixelRefMap::iterator decode_task_it = pending_decode_tasks_.find(id); | 655 PixelRefMap::iterator decode_task_it = pending_decode_tasks_.find(id); |
| 772 if (decode_task_it != pending_decode_tasks_.end()) { | 656 if (decode_task_it != pending_decode_tasks_.end()) { |
| 773 decode_tasks.Append(decode_task_it->second); | 657 decode_tasks.Insert(decode_task_it->second); |
| 774 continue; | 658 continue; |
| 775 } | 659 } |
| 776 | 660 |
| 777 // TODO(qinmin): passing correct image size to PrepareToDecode(). | 661 // TODO(qinmin): passing correct image size to PrepareToDecode(). |
| 778 if (pixel_ref->PrepareToDecode(skia::LazyPixelRef::PrepareParams())) { | 662 if (pixel_ref->PrepareToDecode(skia::LazyPixelRef::PrepareParams())) { |
| 779 rendering_stats_instrumentation_->IncrementDeferredImageCacheHitCount(); | 663 rendering_stats_instrumentation_->IncrementDeferredImageCacheHitCount(); |
| 780 continue; | 664 continue; |
| 781 } | 665 } |
| 782 | 666 |
| 783 // Create and append new image decode task for this pixel ref. | 667 // Create and append new image decode task for this pixel ref. |
| 784 RasterWorkerPool::Task decode_task = CreateImageDecodeTask( | 668 RasterWorkerPool::Task decode_task = CreateImageDecodeTask( |
| 785 tile, pixel_ref); | 669 tile, pixel_ref); |
| 786 decode_tasks.Append(decode_task); | 670 decode_tasks.Insert(decode_task); |
| 787 pending_decode_tasks_[id] = decode_task; | 671 pending_decode_tasks_[id] = decode_task; |
| 788 } | 672 } |
| 789 | 673 |
| 790 return RasterWorkerPool::PictureTask( | 674 return RasterWorkerPool::RasterTask( |
| 791 tile->picture_pile(), | 675 tile->picture_pile(), |
| 676 const_resource, | |
| 792 base::Bind(&TileManager::RunAnalyzeAndRasterTask, | 677 base::Bind(&TileManager::RunAnalyzeAndRasterTask, |
| 793 base::Bind(&TileManager::RunAnalyzeTask, | 678 base::Bind(&TileManager::RunAnalyzeTask, |
| 794 analysis, | 679 analysis, |
| 795 tile->content_rect(), | 680 tile->content_rect(), |
| 796 tile->contents_scale(), | 681 tile->contents_scale(), |
| 797 use_color_estimator_, | 682 use_color_estimator_, |
| 798 GetRasterTaskMetadata(*tile), | 683 GetRasterTaskMetadata(*tile), |
| 799 rendering_stats_instrumentation_), | 684 rendering_stats_instrumentation_), |
| 800 base::Bind(&TileManager::RunRasterTask, | 685 base::Bind(&TileManager::RunRasterTask, |
| 801 buffer, | |
| 802 analysis, | 686 analysis, |
| 803 tile->content_rect(), | 687 tile->content_rect(), |
| 804 tile->contents_scale(), | 688 tile->contents_scale(), |
| 805 GetRasterTaskMetadata(*tile), | 689 GetRasterTaskMetadata(*tile), |
| 806 rendering_stats_instrumentation_)), | 690 rendering_stats_instrumentation_)), |
| 807 base::Bind(&TileManager::OnRasterTaskCompleted, | 691 base::Bind(&TileManager::OnRasterTaskCompleted, |
| 808 base::Unretained(this), | 692 base::Unretained(this), |
| 809 make_scoped_refptr(tile), | 693 make_scoped_refptr(tile), |
| 810 base::Passed(&resource), | 694 base::Passed(&resource), |
| 811 base::Owned(analysis)), | 695 base::Owned(analysis)), |
| 812 &decode_tasks); | 696 &decode_tasks); |
| 813 } | 697 } |
| 814 | 698 |
| 815 void TileManager::OnRasterTaskCompleted( | 699 void TileManager::OnRasterTaskCompleted( |
| 816 scoped_refptr<Tile> tile, | 700 scoped_refptr<Tile> tile, |
| 817 scoped_ptr<ResourcePool::Resource> resource, | 701 scoped_ptr<ResourcePool::Resource> resource, |
| 818 PicturePileImpl::Analysis* analysis, | 702 PicturePileImpl::Analysis* analysis, |
| 819 bool was_canceled) { | 703 bool was_canceled) { |
| 820 TRACE_EVENT0("cc", "TileManager::OnRasterTaskCompleted"); | 704 TRACE_EVENT0("cc", "TileManager::OnRasterTaskCompleted"); |
| 821 | 705 |
| 822 ManagedTileState& mts = tile->managed_state(); | 706 ManagedTileState& mts = tile->managed_state(); |
| 823 DCHECK(!mts.raster_task.is_null()); | 707 DCHECK(!mts.raster_task.is_null()); |
| 824 mts.raster_task.Reset(); | 708 mts.raster_task.Reset(); |
| 825 | 709 |
| 826 // Tile resources can't be freed until upload has completed. | 710 // Tile resources can't be freed until upload has completed. |
| 827 DCHECK_EQ(USING_UNRELEASABLE_MEMORY, tile->tile_version().memory_state_); | 711 DCHECK_EQ(USING_UNRELEASABLE_MEMORY, tile->tile_version().memory_state_); |
| 828 | 712 |
| 829 // Release raster resources. | |
| 830 resource_pool_->resource_provider()->UnmapPixelBuffer(resource->id()); | |
| 831 | |
| 832 if (was_canceled) { | 713 if (was_canceled) { |
| 833 tile->tile_version().memory_state_ = CAN_USE_MEMORY; | 714 tile->tile_version().memory_state_ = CAN_USE_MEMORY; |
| 834 resource_pool_->resource_provider()->ReleasePixelBuffer(resource->id()); | |
| 835 resource_pool_->ReleaseResource(resource.Pass()); | 715 resource_pool_->ReleaseResource(resource.Pass()); |
| 836 return; | 716 return; |
| 837 } | 717 } |
| 838 | 718 |
| 839 mts.picture_pile_analysis = *analysis; | 719 mts.picture_pile_analysis = *analysis; |
| 840 mts.picture_pile_analyzed = true; | 720 mts.picture_pile_analyzed = true; |
| 841 | 721 |
| 842 if (analysis->is_solid_color) { | 722 if (analysis->is_solid_color) { |
| 843 tile->tile_version().set_solid_color(analysis->solid_color); | 723 tile->tile_version().set_solid_color(analysis->solid_color); |
| 844 resource_pool_->resource_provider()->ReleasePixelBuffer(resource->id()); | 724 tile->tile_version().memory_state_ = CAN_USE_MEMORY; |
|
vmpstr
2013/05/29 16:55:03
Why CAN_USE_MEMORY? set_solid_color sets it to NOT
reveman
2013/05/29 19:39:12
Oh, this is not needed in that case. I still have
vmpstr
2013/05/29 20:45:06
Agreed. CAN_USE_MEMORY right now means "this versi
| |
| 845 resource_pool_->ReleaseResource(resource.Pass()); | 725 resource_pool_->ReleaseResource(resource.Pass()); |
| 846 DidFinishTileInitialization(tile); | 726 } else { |
| 847 return; | 727 tile->tile_version().memory_state_ = USING_RELEASABLE_MEMORY; |
| 728 tile->tile_version().resource_ = resource.Pass(); | |
|
vmpstr
2013/05/29 16:55:03
Do you have to set the resource_id_ as well? I can
reveman
2013/05/29 19:39:12
resource_id_ is needed for ForceUpload. Maybe we s
vmpstr
2013/05/29 20:45:06
I like ForceUpload taking a task, since it makes i
reveman
2013/05/30 01:46:10
ForceUpload takes a task in latest patch. It's out
| |
| 848 } | 729 } |
| 849 | 730 |
| 850 resource_pool_->resource_provider()->BeginSetPixels(resource->id()); | 731 DidFinishTileInitialization(tile); |
| 851 has_performed_uploads_since_last_flush_ = true; | |
| 852 | |
| 853 tile->tile_version().resource_ = resource.Pass(); | |
| 854 | |
| 855 bytes_pending_upload_ += tile->bytes_consumed_if_allocated(); | |
| 856 tiles_with_pending_upload_.push(tile); | |
| 857 | |
| 858 if (tile->required_for_activation() && | |
| 859 client_->ShouldForceTileUploadsRequiredForActivationToComplete()) | |
| 860 ForceTileUploadToComplete(tile); | |
| 861 } | 732 } |
| 862 | 733 |
| 863 void TileManager::DidFinishTileInitialization(Tile* tile) { | 734 void TileManager::DidFinishTileInitialization(Tile* tile) { |
| 864 if (tile->priority(ACTIVE_TREE).distance_to_visible_in_pixels == 0) | 735 if (tile->priority(ACTIVE_TREE).distance_to_visible_in_pixels == 0) |
| 865 did_initialize_visible_tile_ = true; | 736 did_initialize_visible_tile_ = true; |
| 866 if (tile->required_for_activation()) { | 737 if (tile->required_for_activation()) { |
| 867 // It's possible that a tile required for activation is not in this list | 738 // It's possible that a tile required for activation is not in this list |
| 868 // if it was marked as being required after being dispatched for | 739 // if it was marked as being required after being dispatched for |
| 869 // rasterization but before AssignGPUMemory was called again. | 740 // rasterization but before AssignGPUMemory was called again. |
| 870 tiles_that_need_to_be_initialized_for_activation_.erase(tile); | 741 tiles_that_need_to_be_initialized_for_activation_.erase(tile); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 886 TRACE_EVENT0("cc", "TileManager::RunImageDecodeTask"); | 757 TRACE_EVENT0("cc", "TileManager::RunImageDecodeTask"); |
| 887 devtools_instrumentation::ScopedLayerTask image_decode_task( | 758 devtools_instrumentation::ScopedLayerTask image_decode_task( |
| 888 devtools_instrumentation::kImageDecodeTask, layer_id); | 759 devtools_instrumentation::kImageDecodeTask, layer_id); |
| 889 base::TimeTicks start_time = stats_instrumentation->StartRecording(); | 760 base::TimeTicks start_time = stats_instrumentation->StartRecording(); |
| 890 pixel_ref->Decode(); | 761 pixel_ref->Decode(); |
| 891 base::TimeDelta duration = stats_instrumentation->EndRecording(start_time); | 762 base::TimeDelta duration = stats_instrumentation->EndRecording(start_time); |
| 892 stats_instrumentation->AddDeferredImageDecode(duration); | 763 stats_instrumentation->AddDeferredImageDecode(duration); |
| 893 } | 764 } |
| 894 | 765 |
| 895 // static | 766 // static |
| 896 void TileManager::RunAnalyzeAndRasterTask( | 767 bool TileManager::RunAnalyzeAndRasterTask( |
| 897 const RasterWorkerPool::PictureTask::Callback& analyze_task, | 768 const base::Callback<void(PicturePileImpl*)>& analyze_task, |
| 898 const RasterWorkerPool::PictureTask::Callback& raster_task, | 769 const RasterWorkerPool::RasterTask::Callback& raster_task, |
| 770 uint8* buffer, | |
| 899 PicturePileImpl* picture_pile) { | 771 PicturePileImpl* picture_pile) { |
| 900 analyze_task.Run(picture_pile); | 772 analyze_task.Run(picture_pile); |
| 901 raster_task.Run(picture_pile); | 773 return raster_task.Run(buffer, picture_pile); |
| 902 } | 774 } |
| 903 | 775 |
| 904 // static | 776 // static |
| 905 void TileManager::RunAnalyzeTask( | 777 void TileManager::RunAnalyzeTask( |
| 906 PicturePileImpl::Analysis* analysis, | 778 PicturePileImpl::Analysis* analysis, |
| 907 gfx::Rect rect, | 779 gfx::Rect rect, |
| 908 float contents_scale, | 780 float contents_scale, |
| 909 bool use_color_estimator, | 781 bool use_color_estimator, |
| 910 const RasterTaskMetadata& metadata, | 782 const RasterTaskMetadata& metadata, |
| 911 RenderingStatsInstrumentation* stats_instrumentation, | 783 RenderingStatsInstrumentation* stats_instrumentation, |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 934 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); | 806 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); |
| 935 res->Set("tile_id", TracedValue::CreateIDRef(tile_id).release()); | 807 res->Set("tile_id", TracedValue::CreateIDRef(tile_id).release()); |
| 936 res->SetBoolean("is_tile_in_pending_tree_now_bin", | 808 res->SetBoolean("is_tile_in_pending_tree_now_bin", |
| 937 is_tile_in_pending_tree_now_bin); | 809 is_tile_in_pending_tree_now_bin); |
| 938 res->Set("resolution", TileResolutionAsValue(tile_resolution).release()); | 810 res->Set("resolution", TileResolutionAsValue(tile_resolution).release()); |
| 939 res->SetInteger("source_frame_number", source_frame_number); | 811 res->SetInteger("source_frame_number", source_frame_number); |
| 940 return res.PassAs<base::Value>(); | 812 return res.PassAs<base::Value>(); |
| 941 } | 813 } |
| 942 | 814 |
| 943 // static | 815 // static |
| 944 void TileManager::RunRasterTask( | 816 bool TileManager::RunRasterTask( |
| 945 uint8* buffer, | |
| 946 PicturePileImpl::Analysis* analysis, | 817 PicturePileImpl::Analysis* analysis, |
| 947 gfx::Rect rect, | 818 gfx::Rect rect, |
| 948 float contents_scale, | 819 float contents_scale, |
| 949 const RasterTaskMetadata& metadata, | 820 const RasterTaskMetadata& metadata, |
| 950 RenderingStatsInstrumentation* stats_instrumentation, | 821 RenderingStatsInstrumentation* stats_instrumentation, |
| 822 uint8* buffer, | |
| 951 PicturePileImpl* picture_pile) { | 823 PicturePileImpl* picture_pile) { |
| 952 TRACE_EVENT1( | 824 TRACE_EVENT1( |
| 953 "cc", "TileManager::RunRasterTask", | 825 "cc", "TileManager::RunRasterTask", |
| 954 "metadata", TracedValue::FromValue(metadata.AsValue().release())); | 826 "metadata", TracedValue::FromValue(metadata.AsValue().release())); |
| 955 devtools_instrumentation::ScopedLayerTask raster_task( | 827 devtools_instrumentation::ScopedLayerTask raster_task( |
| 956 devtools_instrumentation::kRasterTask, metadata.layer_id); | 828 devtools_instrumentation::kRasterTask, metadata.layer_id); |
| 957 | 829 |
| 958 DCHECK(picture_pile); | 830 DCHECK(picture_pile); |
| 959 DCHECK(analysis); | 831 DCHECK(analysis); |
| 960 | 832 |
| 961 // |buffer| can be NULL in lost context situations. | 833 // |buffer| can be NULL in lost context situations. |
| 962 if (!buffer) | 834 if (!buffer) |
| 963 return; | 835 return false; |
| 964 | 836 |
| 965 if (analysis->is_solid_color) | 837 if (analysis->is_solid_color) |
| 966 return; | 838 return false; |
| 967 | 839 |
| 968 SkBitmap bitmap; | 840 SkBitmap bitmap; |
| 969 bitmap.setConfig(SkBitmap::kARGB_8888_Config, rect.width(), rect.height()); | 841 bitmap.setConfig(SkBitmap::kARGB_8888_Config, rect.width(), rect.height()); |
| 970 bitmap.setPixels(buffer); | 842 bitmap.setPixels(buffer); |
| 971 SkDevice device(bitmap); | 843 SkDevice device(bitmap); |
| 972 SkCanvas canvas(&device); | 844 SkCanvas canvas(&device); |
| 973 | 845 |
| 974 if (stats_instrumentation->record_rendering_stats()) { | 846 if (stats_instrumentation->record_rendering_stats()) { |
| 975 PicturePileImpl::RasterStats raster_stats; | 847 PicturePileImpl::RasterStats raster_stats; |
| 976 picture_pile->RasterToBitmap(&canvas, rect, contents_scale, &raster_stats); | 848 picture_pile->RasterToBitmap(&canvas, rect, contents_scale, &raster_stats); |
| 977 stats_instrumentation->AddRaster( | 849 stats_instrumentation->AddRaster( |
| 978 raster_stats.total_rasterize_time, | 850 raster_stats.total_rasterize_time, |
| 979 raster_stats.best_rasterize_time, | 851 raster_stats.best_rasterize_time, |
| 980 raster_stats.total_pixels_rasterized, | 852 raster_stats.total_pixels_rasterized, |
| 981 metadata.is_tile_in_pending_tree_now_bin); | 853 metadata.is_tile_in_pending_tree_now_bin); |
| 982 | 854 |
| 983 HISTOGRAM_CUSTOM_COUNTS( | 855 HISTOGRAM_CUSTOM_COUNTS( |
| 984 "Renderer4.PictureRasterTimeUS", | 856 "Renderer4.PictureRasterTimeUS", |
| 985 raster_stats.total_rasterize_time.InMicroseconds(), | 857 raster_stats.total_rasterize_time.InMicroseconds(), |
| 986 0, | 858 0, |
| 987 100000, | 859 100000, |
| 988 100); | 860 100); |
| 989 } else { | 861 } else { |
| 990 picture_pile->RasterToBitmap(&canvas, rect, contents_scale, NULL); | 862 picture_pile->RasterToBitmap(&canvas, rect, contents_scale, NULL); |
| 991 } | 863 } |
| 864 | |
| 865 return true; | |
| 992 } | 866 } |
| 993 | 867 |
| 994 } // namespace cc | 868 } // namespace cc |
| OLD | NEW |