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 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 MemoryUsage* usage) { | 444 MemoryUsage* usage) { |
445 while (usage->Exceeds(limit)) { | 445 while (usage->Exceeds(limit)) { |
446 if (!eviction_priority_queue) { | 446 if (!eviction_priority_queue) { |
447 eviction_priority_queue = | 447 eviction_priority_queue = |
448 client_->BuildEvictionQueue(global_state_.tree_priority); | 448 client_->BuildEvictionQueue(global_state_.tree_priority); |
449 } | 449 } |
450 if (eviction_priority_queue->IsEmpty()) | 450 if (eviction_priority_queue->IsEmpty()) |
451 break; | 451 break; |
452 | 452 |
453 Tile* tile = eviction_priority_queue->Top(); | 453 Tile* tile = eviction_priority_queue->Top(); |
454 if (!other_priority.IsHigherPriorityThan(tile->combined_priority())) | 454 if (!other_priority.IsHigherPriorityThan(tile->priority())) |
455 break; | 455 break; |
456 | 456 |
457 *usage -= MemoryUsage::FromTile(tile); | 457 *usage -= MemoryUsage::FromTile(tile); |
458 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile); | 458 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile); |
459 eviction_priority_queue->Pop(); | 459 eviction_priority_queue->Pop(); |
460 } | 460 } |
461 return eviction_priority_queue; | 461 return eviction_priority_queue; |
462 } | 462 } |
463 | 463 |
464 bool TileManager::TilePriorityViolatesMemoryPolicy( | 464 bool TileManager::TilePriorityViolatesMemoryPolicy( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 MemoryUsage hard_memory_limit(global_state_.hard_memory_limit_in_bytes, | 499 MemoryUsage hard_memory_limit(global_state_.hard_memory_limit_in_bytes, |
500 global_state_.num_resources_limit); | 500 global_state_.num_resources_limit); |
501 MemoryUsage soft_memory_limit(global_state_.soft_memory_limit_in_bytes, | 501 MemoryUsage soft_memory_limit(global_state_.soft_memory_limit_in_bytes, |
502 global_state_.num_resources_limit); | 502 global_state_.num_resources_limit); |
503 MemoryUsage memory_usage(resource_pool_->acquired_memory_usage_bytes(), | 503 MemoryUsage memory_usage(resource_pool_->acquired_memory_usage_bytes(), |
504 resource_pool_->acquired_resource_count()); | 504 resource_pool_->acquired_resource_count()); |
505 | 505 |
506 scoped_ptr<EvictionTilePriorityQueue> eviction_priority_queue; | 506 scoped_ptr<EvictionTilePriorityQueue> eviction_priority_queue; |
507 for (; !raster_priority_queue->IsEmpty(); raster_priority_queue->Pop()) { | 507 for (; !raster_priority_queue->IsEmpty(); raster_priority_queue->Pop()) { |
508 Tile* tile = raster_priority_queue->Top(); | 508 Tile* tile = raster_priority_queue->Top(); |
509 TilePriority priority = tile->combined_priority(); | 509 TilePriority priority = tile->priority(); |
510 | 510 |
511 if (TilePriorityViolatesMemoryPolicy(priority)) { | 511 if (TilePriorityViolatesMemoryPolicy(priority)) { |
512 TRACE_EVENT_INSTANT0( | 512 TRACE_EVENT_INSTANT0( |
513 "cc", "TileManager::AssignGpuMemory tile violates memory policy", | 513 "cc", "TileManager::AssignGpuMemory tile violates memory policy", |
514 TRACE_EVENT_SCOPE_THREAD); | 514 TRACE_EVENT_SCOPE_THREAD); |
515 break; | 515 break; |
516 } | 516 } |
517 | 517 |
518 // We won't be able to schedule this tile, so break out early. | 518 // We won't be able to schedule this tile, so break out early. |
519 if (tiles_that_need_to_be_rasterized->size() >= | 519 if (tiles_that_need_to_be_rasterized->size() >= |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 | 691 |
692 // Create and append new image decode task for this pixel ref. | 692 // Create and append new image decode task for this pixel ref. |
693 scoped_refptr<ImageDecodeTask> decode_task = | 693 scoped_refptr<ImageDecodeTask> decode_task = |
694 CreateImageDecodeTask(tile, pixel_ref); | 694 CreateImageDecodeTask(tile, pixel_ref); |
695 decode_tasks.push_back(decode_task); | 695 decode_tasks.push_back(decode_task); |
696 existing_pixel_refs[id] = decode_task; | 696 existing_pixel_refs[id] = decode_task; |
697 } | 697 } |
698 | 698 |
699 return make_scoped_refptr(new RasterTaskImpl( | 699 return make_scoped_refptr(new RasterTaskImpl( |
700 const_resource, tile->raster_source(), tile->content_rect(), | 700 const_resource, tile->raster_source(), tile->content_rect(), |
701 tile->contents_scale(), tile->combined_priority().resolution, | 701 tile->contents_scale(), tile->priority().resolution, tile->layer_id(), |
702 tile->layer_id(), static_cast<const void*>(tile), | 702 static_cast<const void*>(tile), tile->source_frame_number(), |
703 tile->source_frame_number(), tile->use_picture_analysis(), | 703 tile->use_picture_analysis(), |
704 base::Bind(&TileManager::OnRasterTaskCompleted, base::Unretained(this), | 704 base::Bind(&TileManager::OnRasterTaskCompleted, base::Unretained(this), |
705 tile->id(), base::Passed(&resource)), | 705 tile->id(), base::Passed(&resource)), |
706 &decode_tasks)); | 706 &decode_tasks)); |
707 } | 707 } |
708 | 708 |
709 void TileManager::OnImageDecodeTaskCompleted(int layer_id, | 709 void TileManager::OnImageDecodeTaskCompleted(int layer_id, |
710 SkPixelRef* pixel_ref, | 710 SkPixelRef* pixel_ref, |
711 bool was_canceled) { | 711 bool was_canceled) { |
712 // If the task was canceled, we need to clean it up | 712 // If the task was canceled, we need to clean it up |
713 // from |image_decode_tasks_|. | 713 // from |image_decode_tasks_|. |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 client_->BuildRasterQueue(global_state_.tree_priority, type)); | 798 client_->BuildRasterQueue(global_state_.tree_priority, type)); |
799 // It is insufficient to check whether the raster queue we constructed is | 799 // It is insufficient to check whether the raster queue we constructed is |
800 // empty. The reason for this is that there are situations (rasterize on | 800 // empty. The reason for this is that there are situations (rasterize on |
801 // demand) when the tile both needs raster and it's ready to draw. Hence, we | 801 // demand) when the tile both needs raster and it's ready to draw. Hence, we |
802 // have to iterate the queue to check whether the required tiles are ready to | 802 // have to iterate the queue to check whether the required tiles are ready to |
803 // draw. | 803 // draw. |
804 for (; !raster_priority_queue->IsEmpty(); raster_priority_queue->Pop()) { | 804 for (; !raster_priority_queue->IsEmpty(); raster_priority_queue->Pop()) { |
805 if (!raster_priority_queue->Top()->IsReadyToDraw()) | 805 if (!raster_priority_queue->Top()->IsReadyToDraw()) |
806 return false; | 806 return false; |
807 } | 807 } |
| 808 |
| 809 #if DCHECK_IS_ON() |
| 810 scoped_ptr<RasterTilePriorityQueue> all_queue( |
| 811 client_->BuildRasterQueue(global_state_.tree_priority, type)); |
| 812 for (; !all_queue->IsEmpty(); all_queue->Pop()) { |
| 813 auto* tile = all_queue->Top(); |
| 814 DCHECK_IMPLIES(tile->required_for_activation(), tile->IsReadyToDraw()); |
| 815 } |
| 816 #endif |
808 return true; | 817 return true; |
809 } | 818 } |
810 bool TileManager::IsReadyToActivate() const { | 819 bool TileManager::IsReadyToActivate() const { |
811 TRACE_EVENT0("cc", "TileManager::IsReadyToActivate"); | 820 TRACE_EVENT0("cc", "TileManager::IsReadyToActivate"); |
812 return AreRequiredTilesReadyToDraw( | 821 return AreRequiredTilesReadyToDraw( |
813 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION); | 822 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION); |
814 } | 823 } |
815 | 824 |
816 bool TileManager::IsReadyToDraw() const { | 825 bool TileManager::IsReadyToDraw() const { |
817 TRACE_EVENT0("cc", "TileManager::IsReadyToDraw"); | 826 TRACE_EVENT0("cc", "TileManager::IsReadyToDraw"); |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 result -= other; | 984 result -= other; |
976 return result; | 985 return result; |
977 } | 986 } |
978 | 987 |
979 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { | 988 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { |
980 return memory_bytes_ > limit.memory_bytes_ || | 989 return memory_bytes_ > limit.memory_bytes_ || |
981 resource_count_ > limit.resource_count_; | 990 resource_count_ > limit.resource_count_; |
982 } | 991 } |
983 | 992 |
984 } // namespace cc | 993 } // namespace cc |
OLD | NEW |