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 <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
536 | 536 |
537 DCHECK_IMPLIES(tile->draw_info().mode() != TileDrawInfo::OOM_MODE, | 537 DCHECK_IMPLIES(tile->draw_info().mode() != TileDrawInfo::OOM_MODE, |
538 !tile->draw_info().IsReadyToDraw()); | 538 !tile->draw_info().IsReadyToDraw()); |
539 | 539 |
540 // If the tile already has a raster_task, then the memory used by it is | 540 // If the tile already has a raster_task, then the memory used by it is |
541 // already accounted for in memory_usage. Otherwise, we'll have to acquire | 541 // already accounted for in memory_usage. Otherwise, we'll have to acquire |
542 // more memory to create a raster task. | 542 // more memory to create a raster task. |
543 MemoryUsage memory_required_by_tile_to_be_scheduled; | 543 MemoryUsage memory_required_by_tile_to_be_scheduled; |
544 if (!tile->raster_task_.get()) { | 544 if (!tile->raster_task_.get()) { |
545 memory_required_by_tile_to_be_scheduled = MemoryUsage::FromConfig( | 545 memory_required_by_tile_to_be_scheduled = MemoryUsage::FromConfig( |
546 tile->desired_texture_size(), tile_task_runner_->GetResourceFormat()); | 546 tile->desired_texture_size(), DetermineResourceFormat(tile)); |
547 } | 547 } |
548 | 548 |
549 bool tile_is_needed_now = priority.priority_bin == TilePriority::NOW; | 549 bool tile_is_needed_now = priority.priority_bin == TilePriority::NOW; |
550 | 550 |
551 // This is the memory limit that will be used by this tile. Depending on | 551 // This is the memory limit that will be used by this tile. Depending on |
552 // the tile priority, it will be one of hard_memory_limit or | 552 // the tile priority, it will be one of hard_memory_limit or |
553 // soft_memory_limit. | 553 // soft_memory_limit. |
554 MemoryUsage& tile_memory_limit = | 554 MemoryUsage& tile_memory_limit = |
555 tile_is_needed_now ? hard_memory_limit : soft_memory_limit; | 555 tile_is_needed_now ? hard_memory_limit : soft_memory_limit; |
556 | 556 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
680 uint64_t resource_content_id = 0; | 680 uint64_t resource_content_id = 0; |
681 scoped_ptr<ScopedResource> resource; | 681 scoped_ptr<ScopedResource> resource; |
682 if (tile->invalidated_id()) { | 682 if (tile->invalidated_id()) { |
683 // TODO(danakj): For resources that are in use, we should still grab them | 683 // TODO(danakj): For resources that are in use, we should still grab them |
684 // and copy from them instead of rastering everything. crbug.com/492754 | 684 // and copy from them instead of rastering everything. crbug.com/492754 |
685 resource = | 685 resource = |
686 resource_pool_->TryAcquireResourceWithContentId(tile->invalidated_id()); | 686 resource_pool_->TryAcquireResourceWithContentId(tile->invalidated_id()); |
687 } | 687 } |
688 if (resource) { | 688 if (resource) { |
689 resource_content_id = tile->invalidated_id(); | 689 resource_content_id = tile->invalidated_id(); |
690 DCHECK_EQ(tile_task_runner_->GetResourceFormat(), resource->format()); | 690 DCHECK_EQ(DetermineResourceFormat(tile), resource->format()); |
691 DCHECK_EQ(tile->desired_texture_size().ToString(), | 691 DCHECK_EQ(tile->desired_texture_size().ToString(), |
692 resource->size().ToString()); | 692 resource->size().ToString()); |
693 } else { | 693 } else { |
694 resource = resource_pool_->AcquireResource( | 694 resource = resource_pool_->AcquireResource(tile->desired_texture_size(), |
695 tile->desired_texture_size(), tile_task_runner_->GetResourceFormat()); | 695 DetermineResourceFormat(tile)); |
696 } | 696 } |
697 const ScopedResource* const_resource = resource.get(); | 697 const ScopedResource* const_resource = resource.get(); |
698 | 698 |
699 // Create and queue all image decode tasks that this tile depends on. | 699 // Create and queue all image decode tasks that this tile depends on. |
700 ImageDecodeTask::Vector decode_tasks; | 700 ImageDecodeTask::Vector decode_tasks; |
701 PixelRefTaskMap& existing_pixel_refs = image_decode_tasks_[tile->layer_id()]; | 701 PixelRefTaskMap& existing_pixel_refs = image_decode_tasks_[tile->layer_id()]; |
702 std::vector<SkPixelRef*> pixel_refs; | 702 std::vector<SkPixelRef*> pixel_refs; |
703 prioritized_tile.raster_source()->GatherPixelRefs( | 703 prioritized_tile.raster_source()->GatherPixelRefs( |
704 tile->content_rect(), tile->contents_scale(), &pixel_refs); | 704 tile->content_rect(), tile->contents_scale(), &pixel_refs); |
705 for (SkPixelRef* pixel_ref : pixel_refs) { | 705 for (SkPixelRef* pixel_ref : pixel_refs) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
784 draw_info.set_solid_color(analysis.solid_color); | 784 draw_info.set_solid_color(analysis.solid_color); |
785 if (resource) { | 785 if (resource) { |
786 // Pass the old tile id here because the tile is solid color so we did not | 786 // Pass the old tile id here because the tile is solid color so we did not |
787 // raster anything into the tile resource. | 787 // raster anything into the tile resource. |
788 resource_pool_->ReleaseResource(resource.Pass(), tile->invalidated_id()); | 788 resource_pool_->ReleaseResource(resource.Pass(), tile->invalidated_id()); |
789 } | 789 } |
790 } else { | 790 } else { |
791 DCHECK(resource); | 791 DCHECK(resource); |
792 draw_info.set_use_resource(); | 792 draw_info.set_use_resource(); |
793 draw_info.resource_ = resource.Pass(); | 793 draw_info.resource_ = resource.Pass(); |
794 draw_info.contents_swizzled_ = | 794 draw_info.contents_swizzled_ = DetermineResourceRequiresSwizzle(tile); |
795 tile_task_runner_->GetResourceRequiresSwizzle(); | |
796 } | 795 } |
797 client_->NotifyTileStateChanged(tile); | 796 client_->NotifyTileStateChanged(tile); |
798 } | 797 } |
799 | 798 |
800 ScopedTilePtr TileManager::CreateTile(const gfx::Size& desired_texture_size, | 799 ScopedTilePtr TileManager::CreateTile(const gfx::Size& desired_texture_size, |
801 const gfx::Rect& content_rect, | 800 const gfx::Rect& content_rect, |
802 float contents_scale, | 801 float contents_scale, |
803 int layer_id, | 802 int layer_id, |
804 int source_frame_number, | 803 int source_frame_number, |
805 int flags) { | 804 int flags) { |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
961 required_for_activation_queue->Pop()) { | 960 required_for_activation_queue->Pop()) { |
962 Tile* tile = required_for_activation_queue->Top().tile(); | 961 Tile* tile = required_for_activation_queue->Top().tile(); |
963 tile->draw_info().set_oom(); | 962 tile->draw_info().set_oom(); |
964 client_->NotifyTileStateChanged(tile); | 963 client_->NotifyTileStateChanged(tile); |
965 } | 964 } |
966 | 965 |
967 DCHECK(IsReadyToActivate()); | 966 DCHECK(IsReadyToActivate()); |
968 ready_to_activate_check_notifier_.Schedule(); | 967 ready_to_activate_check_notifier_.Schedule(); |
969 } | 968 } |
970 | 969 |
970 ResourceFormat TileManager::DetermineResourceFormat(const Tile* tile) const { | |
971 bool dont_compress = tile->desired_texture_size().width() % 4 != 0 || | |
972 tile->desired_texture_size().height() % 4 != 0; | |
reveman
2015/07/21 04:26:33
Can we instead clamp tile size to multiple of 4 if
| |
973 return tile_task_runner_->GetResourceFormat(dont_compress, | |
974 !tile->is_opaque()); | |
975 } | |
976 | |
977 bool TileManager::DetermineResourceRequiresSwizzle(const Tile* tile) const { | |
978 bool dont_compress = tile->desired_texture_size().width() % 4 != 0 || | |
979 tile->desired_texture_size().height() % 4 != 0; | |
980 return tile_task_runner_->GetResourceRequiresSwizzle(dont_compress, | |
981 !tile->is_opaque()); | |
982 } | |
983 | |
971 TileManager::MemoryUsage::MemoryUsage() : memory_bytes_(0), resource_count_(0) { | 984 TileManager::MemoryUsage::MemoryUsage() : memory_bytes_(0), resource_count_(0) { |
972 } | 985 } |
973 | 986 |
974 TileManager::MemoryUsage::MemoryUsage(size_t memory_bytes, | 987 TileManager::MemoryUsage::MemoryUsage(size_t memory_bytes, |
975 size_t resource_count) | 988 size_t resource_count) |
976 : memory_bytes_(static_cast<int64>(memory_bytes)), | 989 : memory_bytes_(static_cast<int64>(memory_bytes)), |
977 resource_count_(static_cast<int>(resource_count)) { | 990 resource_count_(static_cast<int>(resource_count)) { |
978 // MemoryUsage is constructed using size_ts, since it deals with memory and | 991 // MemoryUsage is constructed using size_ts, since it deals with memory and |
979 // the inputs are typically size_t. However, during the course of usage (in | 992 // the inputs are typically size_t. However, during the course of usage (in |
980 // particular operator-=) can cause internal values to become negative. Thus, | 993 // particular operator-=) can cause internal values to become negative. Thus, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1024 result -= other; | 1037 result -= other; |
1025 return result; | 1038 return result; |
1026 } | 1039 } |
1027 | 1040 |
1028 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { | 1041 bool TileManager::MemoryUsage::Exceeds(const MemoryUsage& limit) const { |
1029 return memory_bytes_ > limit.memory_bytes_ || | 1042 return memory_bytes_ > limit.memory_bytes_ || |
1030 resource_count_ > limit.resource_count_; | 1043 resource_count_ > limit.resource_count_; |
1031 } | 1044 } |
1032 | 1045 |
1033 } // namespace cc | 1046 } // namespace cc |
OLD | NEW |