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> |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 "Compositing.%s.RasterTask.RasterPixelsPerMs"); | 43 "Compositing.%s.RasterTask.RasterPixelsPerMs"); |
44 | 44 |
45 class RasterTaskImpl : public TileTask { | 45 class RasterTaskImpl : public TileTask { |
46 public: | 46 public: |
47 RasterTaskImpl(TileManager* tile_manager, | 47 RasterTaskImpl(TileManager* tile_manager, |
48 Tile* tile, | 48 Tile* tile, |
49 Resource* resource, | 49 Resource* resource, |
50 scoped_refptr<RasterSource> raster_source, | 50 scoped_refptr<RasterSource> raster_source, |
51 const RasterSource::PlaybackSettings& playback_settings, | 51 const RasterSource::PlaybackSettings& playback_settings, |
52 TileResolution tile_resolution, | 52 TileResolution tile_resolution, |
| 53 gfx::Rect invalidated_rect, |
53 uint64_t source_prepare_tiles_id, | 54 uint64_t source_prepare_tiles_id, |
54 std::unique_ptr<RasterBuffer> raster_buffer, | 55 std::unique_ptr<RasterBuffer> raster_buffer, |
55 TileTask::Vector* dependencies, | 56 TileTask::Vector* dependencies, |
56 bool supports_concurrent_execution) | 57 bool supports_concurrent_execution) |
57 : TileTask(supports_concurrent_execution, dependencies), | 58 : TileTask(supports_concurrent_execution, dependencies), |
58 tile_manager_(tile_manager), | 59 tile_manager_(tile_manager), |
59 tile_(tile), | 60 tile_(tile), |
60 resource_(resource), | 61 resource_(resource), |
61 raster_source_(std::move(raster_source)), | 62 raster_source_(std::move(raster_source)), |
62 content_rect_(tile->content_rect()), | 63 content_rect_(tile->content_rect()), |
63 invalid_content_rect_(tile->invalidated_content_rect()), | 64 invalid_content_rect_(invalidated_rect), |
64 contents_scale_(tile->contents_scale()), | 65 contents_scale_(tile->contents_scale()), |
65 playback_settings_(playback_settings), | 66 playback_settings_(playback_settings), |
66 tile_resolution_(tile_resolution), | 67 tile_resolution_(tile_resolution), |
67 layer_id_(tile->layer_id()), | 68 layer_id_(tile->layer_id()), |
68 source_prepare_tiles_id_(source_prepare_tiles_id), | 69 source_prepare_tiles_id_(source_prepare_tiles_id), |
69 tile_tracing_id_(static_cast<void*>(tile)), | 70 tile_tracing_id_(static_cast<void*>(tile)), |
70 new_content_id_(tile->id()), | 71 new_content_id_(tile->id()), |
71 source_frame_number_(tile->source_frame_number()), | 72 source_frame_number_(tile->source_frame_number()), |
72 raster_buffer_(std::move(raster_buffer)) { | 73 raster_buffer_(std::move(raster_buffer)) { |
73 DCHECK(origin_thread_checker_.CalledOnValidThread()); | 74 DCHECK(origin_thread_checker_.CalledOnValidThread()); |
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 "all_tiles_that_need_to_be_rasterized_are_scheduled", | 739 "all_tiles_that_need_to_be_rasterized_are_scheduled", |
739 all_tiles_that_need_to_be_rasterized_are_scheduled_, | 740 all_tiles_that_need_to_be_rasterized_are_scheduled_, |
740 "had_enough_memory_to_schedule_tiles_needed_now", | 741 "had_enough_memory_to_schedule_tiles_needed_now", |
741 had_enough_memory_to_schedule_tiles_needed_now); | 742 had_enough_memory_to_schedule_tiles_needed_now); |
742 return work_to_schedule; | 743 return work_to_schedule; |
743 } | 744 } |
744 | 745 |
745 void TileManager::FreeResourcesForTile(Tile* tile) { | 746 void TileManager::FreeResourcesForTile(Tile* tile) { |
746 TileDrawInfo& draw_info = tile->draw_info(); | 747 TileDrawInfo& draw_info = tile->draw_info(); |
747 if (draw_info.resource_) { | 748 if (draw_info.resource_) { |
748 resource_pool_->ReleaseResource(draw_info.resource_, tile->id()); | 749 resource_pool_->ReleaseResource(draw_info.resource_); |
749 draw_info.resource_ = nullptr; | 750 draw_info.resource_ = nullptr; |
750 } | 751 } |
751 } | 752 } |
752 | 753 |
753 void TileManager::FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw( | 754 void TileManager::FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw( |
754 Tile* tile) { | 755 Tile* tile) { |
755 bool was_ready_to_draw = tile->draw_info().IsReadyToDraw(); | 756 bool was_ready_to_draw = tile->draw_info().IsReadyToDraw(); |
756 FreeResourcesForTile(tile); | 757 FreeResourcesForTile(tile); |
757 if (was_ready_to_draw) | 758 if (was_ready_to_draw) |
758 client_->NotifyTileStateChanged(tile); | 759 client_->NotifyTileStateChanged(tile); |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
925 ScheduledTasksStateAsValue()); | 926 ScheduledTasksStateAsValue()); |
926 } | 927 } |
927 | 928 |
928 scoped_refptr<TileTask> TileManager::CreateRasterTask( | 929 scoped_refptr<TileTask> TileManager::CreateRasterTask( |
929 const PrioritizedTile& prioritized_tile) { | 930 const PrioritizedTile& prioritized_tile) { |
930 Tile* tile = prioritized_tile.tile(); | 931 Tile* tile = prioritized_tile.tile(); |
931 | 932 |
932 // Get the resource. | 933 // Get the resource. |
933 uint64_t resource_content_id = 0; | 934 uint64_t resource_content_id = 0; |
934 Resource* resource = nullptr; | 935 Resource* resource = nullptr; |
| 936 gfx::Rect invalidated_rect = tile->invalidated_content_rect(); |
935 if (UsePartialRaster() && tile->invalidated_id()) { | 937 if (UsePartialRaster() && tile->invalidated_id()) { |
936 // TODO(danakj): For resources that are in use, we should still grab them | 938 resource = resource_pool_->TryAcquireResourceForPartialRaster( |
937 // and copy from them instead of rastering everything. crbug.com/492754 | 939 tile->id(), tile->invalidated_content_rect(), tile->invalidated_id(), |
938 resource = | 940 &invalidated_rect); |
939 resource_pool_->TryAcquireResourceWithContentId(tile->invalidated_id()); | |
940 } | 941 } |
| 942 |
941 if (resource) { | 943 if (resource) { |
942 resource_content_id = tile->invalidated_id(); | 944 resource_content_id = tile->invalidated_id(); |
943 DCHECK_EQ(DetermineResourceFormat(tile), resource->format()); | 945 DCHECK_EQ(DetermineResourceFormat(tile), resource->format()); |
944 } else { | 946 } else { |
945 resource = resource_pool_->AcquireResource(tile->desired_texture_size(), | 947 resource = resource_pool_->AcquireResource(tile->desired_texture_size(), |
946 DetermineResourceFormat(tile)); | 948 DetermineResourceFormat(tile)); |
947 } | 949 } |
948 | 950 |
949 // For LOW_RESOLUTION tiles, we don't draw or predecode images. | 951 // For LOW_RESOLUTION tiles, we don't draw or predecode images. |
950 RasterSource::PlaybackSettings playback_settings; | 952 RasterSource::PlaybackSettings playback_settings; |
(...skipping 19 matching lines...) Expand all Loading... |
970 image_decode_controller_->GetTaskForImageAndRef(*it, tracing_info, | 972 image_decode_controller_->GetTaskForImageAndRef(*it, tracing_info, |
971 &task); | 973 &task); |
972 if (task) | 974 if (task) |
973 decode_tasks.push_back(task); | 975 decode_tasks.push_back(task); |
974 | 976 |
975 if (need_to_unref_when_finished) | 977 if (need_to_unref_when_finished) |
976 ++it; | 978 ++it; |
977 else | 979 else |
978 it = images.erase(it); | 980 it = images.erase(it); |
979 } | 981 } |
980 | |
981 bool supports_concurrent_execution = !use_gpu_rasterization_; | 982 bool supports_concurrent_execution = !use_gpu_rasterization_; |
982 std::unique_ptr<RasterBuffer> raster_buffer = | 983 std::unique_ptr<RasterBuffer> raster_buffer = |
983 raster_buffer_provider_->AcquireBufferForRaster( | 984 raster_buffer_provider_->AcquireBufferForRaster( |
984 resource, resource_content_id, tile->invalidated_id()); | 985 resource, resource_content_id, tile->invalidated_id()); |
985 return make_scoped_refptr(new RasterTaskImpl( | 986 return make_scoped_refptr(new RasterTaskImpl( |
986 this, tile, resource, prioritized_tile.raster_source(), playback_settings, | 987 this, tile, resource, prioritized_tile.raster_source(), playback_settings, |
987 prioritized_tile.priority().resolution, prepare_tiles_count_, | 988 prioritized_tile.priority().resolution, invalidated_rect, |
988 std::move(raster_buffer), &decode_tasks, supports_concurrent_execution)); | 989 prepare_tiles_count_, std::move(raster_buffer), &decode_tasks, |
| 990 supports_concurrent_execution)); |
989 } | 991 } |
990 | 992 |
991 void TileManager::OnRasterTaskCompleted( | 993 void TileManager::OnRasterTaskCompleted( |
992 std::unique_ptr<RasterBuffer> raster_buffer, | 994 std::unique_ptr<RasterBuffer> raster_buffer, |
993 Tile* tile, | 995 Tile* tile, |
994 Resource* resource, | 996 Resource* resource, |
995 bool was_canceled) { | 997 bool was_canceled) { |
996 DCHECK(tile); | 998 DCHECK(tile); |
997 DCHECK(tiles_.find(tile->id()) != tiles_.end()); | 999 DCHECK(tiles_.find(tile->id()) != tiles_.end()); |
998 raster_buffer_provider_->ReleaseBufferForRaster(std::move(raster_buffer)); | 1000 raster_buffer_provider_->ReleaseBufferForRaster(std::move(raster_buffer)); |
999 | 1001 |
1000 TileDrawInfo& draw_info = tile->draw_info(); | 1002 TileDrawInfo& draw_info = tile->draw_info(); |
1001 DCHECK(tile->raster_task_.get()); | 1003 DCHECK(tile->raster_task_.get()); |
1002 orphan_tasks_.push_back(tile->raster_task_); | 1004 orphan_tasks_.push_back(tile->raster_task_); |
1003 tile->raster_task_ = nullptr; | 1005 tile->raster_task_ = nullptr; |
1004 | 1006 |
1005 // Unref all the images. | 1007 // Unref all the images. |
1006 auto images_it = scheduled_draw_images_.find(tile->id()); | 1008 auto images_it = scheduled_draw_images_.find(tile->id()); |
1007 const std::vector<DrawImage>& images = images_it->second; | 1009 const std::vector<DrawImage>& images = images_it->second; |
1008 for (const auto& image : images) | 1010 for (const auto& image : images) |
1009 image_decode_controller_->UnrefImage(image); | 1011 image_decode_controller_->UnrefImage(image); |
1010 scheduled_draw_images_.erase(images_it); | 1012 scheduled_draw_images_.erase(images_it); |
1011 | 1013 |
1012 if (was_canceled) { | 1014 if (was_canceled) { |
1013 ++flush_stats_.canceled_count; | 1015 ++flush_stats_.canceled_count; |
1014 // TODO(ericrk): If more partial raster work is done in the future, it may | 1016 resource_pool_->ReleaseResource(resource); |
1015 // be worth returning the resource to the pool with its previous ID (not | |
1016 // currently tracked). crrev.com/1370333002/#ps40001 has a possible method | |
1017 // of achieving this. | |
1018 resource_pool_->ReleaseResource(resource, 0 /* content_id */); | |
1019 return; | 1017 return; |
1020 } | 1018 } |
1021 | 1019 |
| 1020 resource_pool_->OnContentReplaced(resource->id(), tile->id()); |
1022 ++flush_stats_.completed_count; | 1021 ++flush_stats_.completed_count; |
1023 | 1022 |
1024 draw_info.set_use_resource(); | 1023 draw_info.set_use_resource(); |
1025 draw_info.resource_ = resource; | 1024 draw_info.resource_ = resource; |
1026 draw_info.contents_swizzled_ = DetermineResourceRequiresSwizzle(tile); | 1025 draw_info.contents_swizzled_ = DetermineResourceRequiresSwizzle(tile); |
1027 | 1026 |
1028 DCHECK(draw_info.IsReadyToDraw()); | 1027 DCHECK(draw_info.IsReadyToDraw()); |
1029 draw_info.set_was_ever_ready_to_draw(); | 1028 draw_info.set_was_ever_ready_to_draw(); |
1030 | 1029 |
1031 client_->NotifyTileStateChanged(tile); | 1030 client_->NotifyTileStateChanged(tile); |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1334 all_tile_tasks_completed = false; | 1333 all_tile_tasks_completed = false; |
1335 did_notify_all_tile_tasks_completed = false; | 1334 did_notify_all_tile_tasks_completed = false; |
1336 } | 1335 } |
1337 | 1336 |
1338 TileManager::PrioritizedWorkToSchedule::PrioritizedWorkToSchedule() = default; | 1337 TileManager::PrioritizedWorkToSchedule::PrioritizedWorkToSchedule() = default; |
1339 TileManager::PrioritizedWorkToSchedule::PrioritizedWorkToSchedule( | 1338 TileManager::PrioritizedWorkToSchedule::PrioritizedWorkToSchedule( |
1340 PrioritizedWorkToSchedule&& other) = default; | 1339 PrioritizedWorkToSchedule&& other) = default; |
1341 TileManager::PrioritizedWorkToSchedule::~PrioritizedWorkToSchedule() = default; | 1340 TileManager::PrioritizedWorkToSchedule::~PrioritizedWorkToSchedule() = default; |
1342 | 1341 |
1343 } // namespace cc | 1342 } // namespace cc |
OLD | NEW |