| 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 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 MemoryUsage* usage) { | 436 MemoryUsage* usage) { |
| 437 while (usage->Exceeds(limit)) { | 437 while (usage->Exceeds(limit)) { |
| 438 if (!eviction_priority_queue) { | 438 if (!eviction_priority_queue) { |
| 439 eviction_priority_queue = | 439 eviction_priority_queue = |
| 440 client_->BuildEvictionQueue(global_state_.tree_priority); | 440 client_->BuildEvictionQueue(global_state_.tree_priority); |
| 441 } | 441 } |
| 442 if (eviction_priority_queue->IsEmpty()) | 442 if (eviction_priority_queue->IsEmpty()) |
| 443 break; | 443 break; |
| 444 | 444 |
| 445 Tile* tile = eviction_priority_queue->Top(); | 445 Tile* tile = eviction_priority_queue->Top(); |
| 446 if (!other_priority.IsHigherPriorityThan(tile->combined_priority())) | 446 if (!other_priority.IsHigherPriorityThan(tile->priority())) |
| 447 break; | 447 break; |
| 448 | 448 |
| 449 *usage -= MemoryUsage::FromTile(tile); | 449 *usage -= MemoryUsage::FromTile(tile); |
| 450 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile); | 450 FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(tile); |
| 451 eviction_priority_queue->Pop(); | 451 eviction_priority_queue->Pop(); |
| 452 } | 452 } |
| 453 return eviction_priority_queue; | 453 return eviction_priority_queue; |
| 454 } | 454 } |
| 455 | 455 |
| 456 bool TileManager::TilePriorityViolatesMemoryPolicy( | 456 bool TileManager::TilePriorityViolatesMemoryPolicy( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 MemoryUsage hard_memory_limit(global_state_.hard_memory_limit_in_bytes, | 491 MemoryUsage hard_memory_limit(global_state_.hard_memory_limit_in_bytes, |
| 492 global_state_.num_resources_limit); | 492 global_state_.num_resources_limit); |
| 493 MemoryUsage soft_memory_limit(global_state_.soft_memory_limit_in_bytes, | 493 MemoryUsage soft_memory_limit(global_state_.soft_memory_limit_in_bytes, |
| 494 global_state_.num_resources_limit); | 494 global_state_.num_resources_limit); |
| 495 MemoryUsage memory_usage(resource_pool_->acquired_memory_usage_bytes(), | 495 MemoryUsage memory_usage(resource_pool_->acquired_memory_usage_bytes(), |
| 496 resource_pool_->acquired_resource_count()); | 496 resource_pool_->acquired_resource_count()); |
| 497 | 497 |
| 498 scoped_ptr<EvictionTilePriorityQueue> eviction_priority_queue; | 498 scoped_ptr<EvictionTilePriorityQueue> eviction_priority_queue; |
| 499 for (; !raster_priority_queue->IsEmpty(); raster_priority_queue->Pop()) { | 499 for (; !raster_priority_queue->IsEmpty(); raster_priority_queue->Pop()) { |
| 500 Tile* tile = raster_priority_queue->Top(); | 500 Tile* tile = raster_priority_queue->Top(); |
| 501 TilePriority priority = tile->combined_priority(); | 501 TilePriority priority = tile->priority(); |
| 502 | 502 |
| 503 if (TilePriorityViolatesMemoryPolicy(priority)) { | 503 if (TilePriorityViolatesMemoryPolicy(priority)) { |
| 504 TRACE_EVENT_INSTANT0( | 504 TRACE_EVENT_INSTANT0( |
| 505 "cc", "TileManager::AssignGpuMemory tile violates memory policy", | 505 "cc", "TileManager::AssignGpuMemory tile violates memory policy", |
| 506 TRACE_EVENT_SCOPE_THREAD); | 506 TRACE_EVENT_SCOPE_THREAD); |
| 507 break; | 507 break; |
| 508 } | 508 } |
| 509 | 509 |
| 510 // We won't be able to schedule this tile, so break out early. | 510 // We won't be able to schedule this tile, so break out early. |
| 511 if (tiles_that_need_to_be_rasterized->size() >= | 511 if (tiles_that_need_to_be_rasterized->size() >= |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 | 683 |
| 684 // Create and append new image decode task for this pixel ref. | 684 // Create and append new image decode task for this pixel ref. |
| 685 scoped_refptr<ImageDecodeTask> decode_task = | 685 scoped_refptr<ImageDecodeTask> decode_task = |
| 686 CreateImageDecodeTask(tile, pixel_ref); | 686 CreateImageDecodeTask(tile, pixel_ref); |
| 687 decode_tasks.push_back(decode_task); | 687 decode_tasks.push_back(decode_task); |
| 688 existing_pixel_refs[id] = decode_task; | 688 existing_pixel_refs[id] = decode_task; |
| 689 } | 689 } |
| 690 | 690 |
| 691 return make_scoped_refptr(new RasterTaskImpl( | 691 return make_scoped_refptr(new RasterTaskImpl( |
| 692 const_resource, tile->raster_source(), tile->content_rect(), | 692 const_resource, tile->raster_source(), tile->content_rect(), |
| 693 tile->contents_scale(), tile->combined_priority().resolution, | 693 tile->contents_scale(), tile->priority().resolution, tile->layer_id(), |
| 694 tile->layer_id(), static_cast<const void*>(tile), | 694 static_cast<const void*>(tile), tile->source_frame_number(), |
| 695 tile->source_frame_number(), tile->use_picture_analysis(), | 695 tile->use_picture_analysis(), |
| 696 base::Bind(&TileManager::OnRasterTaskCompleted, base::Unretained(this), | 696 base::Bind(&TileManager::OnRasterTaskCompleted, base::Unretained(this), |
| 697 tile->id(), base::Passed(&resource)), | 697 tile->id(), base::Passed(&resource)), |
| 698 &decode_tasks)); | 698 &decode_tasks)); |
| 699 } | 699 } |
| 700 | 700 |
| 701 void TileManager::OnImageDecodeTaskCompleted(int layer_id, | 701 void TileManager::OnImageDecodeTaskCompleted(int layer_id, |
| 702 SkPixelRef* pixel_ref, | 702 SkPixelRef* pixel_ref, |
| 703 bool was_canceled) { | 703 bool was_canceled) { |
| 704 // If the task was canceled, we need to clean it up | 704 // If the task was canceled, we need to clean it up |
| 705 // from |image_decode_tasks_|. | 705 // from |image_decode_tasks_|. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 } else { | 754 } else { |
| 755 DCHECK(resource); | 755 DCHECK(resource); |
| 756 draw_info.set_use_resource(); | 756 draw_info.set_use_resource(); |
| 757 draw_info.resource_ = resource.Pass(); | 757 draw_info.resource_ = resource.Pass(); |
| 758 } | 758 } |
| 759 | 759 |
| 760 client_->NotifyTileStateChanged(tile); | 760 client_->NotifyTileStateChanged(tile); |
| 761 } | 761 } |
| 762 | 762 |
| 763 scoped_refptr<Tile> TileManager::CreateTile( | 763 scoped_refptr<Tile> TileManager::CreateTile( |
| 764 RasterSource* raster_source, | 764 scoped_refptr<RasterSource>* raster_source, |
| 765 const gfx::Size& desired_texture_size, | 765 const gfx::Size& desired_texture_size, |
| 766 const gfx::Rect& content_rect, | 766 const gfx::Rect& content_rect, |
| 767 float contents_scale, | 767 float contents_scale, |
| 768 int layer_id, | 768 int layer_id, |
| 769 int source_frame_number, | 769 int source_frame_number, |
| 770 int flags) { | 770 int flags) { |
| 771 scoped_refptr<Tile> tile = make_scoped_refptr( | 771 scoped_refptr<Tile> tile = make_scoped_refptr( |
| 772 new Tile(this, raster_source, desired_texture_size, content_rect, | 772 new Tile(this, raster_source, desired_texture_size, content_rect, |
| 773 contents_scale, layer_id, source_frame_number, flags)); | 773 contents_scale, layer_id, source_frame_number, flags)); |
| 774 DCHECK(tiles_.find(tile->id()) == tiles_.end()); | 774 DCHECK(tiles_.find(tile->id()) == tiles_.end()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 790 client_->BuildRasterQueue(global_state_.tree_priority, type)); | 790 client_->BuildRasterQueue(global_state_.tree_priority, type)); |
| 791 // It is insufficient to check whether the raster queue we constructed is | 791 // It is insufficient to check whether the raster queue we constructed is |
| 792 // empty. The reason for this is that there are situations (rasterize on | 792 // empty. The reason for this is that there are situations (rasterize on |
| 793 // demand) when the tile both needs raster and it's ready to draw. Hence, we | 793 // demand) when the tile both needs raster and it's ready to draw. Hence, we |
| 794 // have to iterate the queue to check whether the required tiles are ready to | 794 // have to iterate the queue to check whether the required tiles are ready to |
| 795 // draw. | 795 // draw. |
| 796 for (; !raster_priority_queue->IsEmpty(); raster_priority_queue->Pop()) { | 796 for (; !raster_priority_queue->IsEmpty(); raster_priority_queue->Pop()) { |
| 797 if (!raster_priority_queue->Top()->IsReadyToDraw()) | 797 if (!raster_priority_queue->Top()->IsReadyToDraw()) |
| 798 return false; | 798 return false; |
| 799 } | 799 } |
| 800 |
| 801 #if DCHECK_IS_ON() |
| 802 scoped_ptr<RasterTilePriorityQueue> all_queue( |
| 803 client_->BuildRasterQueue(global_state_.tree_priority, type)); |
| 804 for (; !all_queue->IsEmpty(); all_queue->Pop()) { |
| 805 auto* tile = all_queue->Top(); |
| 806 DCHECK_IMPLIES(tile->required_for_activation(), tile->IsReadyToDraw()); |
| 807 } |
| 808 #endif |
| 800 return true; | 809 return true; |
| 801 } | 810 } |
| 802 bool TileManager::IsReadyToActivate() const { | 811 bool TileManager::IsReadyToActivate() const { |
| 803 TRACE_EVENT0("cc", "TileManager::IsReadyToActivate"); | 812 TRACE_EVENT0("cc", "TileManager::IsReadyToActivate"); |
| 804 return AreRequiredTilesReadyToDraw( | 813 return AreRequiredTilesReadyToDraw( |
| 805 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION); | 814 RasterTilePriorityQueue::Type::REQUIRED_FOR_ACTIVATION); |
| 806 } | 815 } |
| 807 | 816 |
| 808 bool TileManager::IsReadyToDraw() const { | 817 bool TileManager::IsReadyToDraw() const { |
| 809 TRACE_EVENT0("cc", "TileManager::IsReadyToDraw"); | 818 TRACE_EVENT0("cc", "TileManager::IsReadyToDraw"); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 967 result -= other; | 976 result -= other; |
| 968 return result; | 977 return result; |
| 969 } | 978 } |
| 970 | 979 |
| 971 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { | 980 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { |
| 972 return memory_bytes_ > limit.memory_bytes_ || | 981 return memory_bytes_ > limit.memory_bytes_ || |
| 973 resource_count_ > limit.resource_count_; | 982 resource_count_ > limit.resource_count_; |
| 974 } | 983 } |
| 975 | 984 |
| 976 } // namespace cc | 985 } // namespace cc |
| OLD | NEW |