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> |
11 #include <limits> | 11 #include <limits> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/bind.h" | 14 #include "base/bind.h" |
15 #include "base/json/json_writer.h" | 15 #include "base/json/json_writer.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
19 #include "base/metrics/histogram.h" | 19 #include "base/metrics/histogram.h" |
20 #include "base/numerics/safe_conversions.h" | 20 #include "base/numerics/safe_conversions.h" |
21 #include "base/threading/thread_checker.h" | |
21 #include "base/trace_event/trace_event_argument.h" | 22 #include "base/trace_event/trace_event_argument.h" |
22 #include "cc/base/histograms.h" | 23 #include "cc/base/histograms.h" |
23 #include "cc/debug/devtools_instrumentation.h" | 24 #include "cc/debug/devtools_instrumentation.h" |
24 #include "cc/debug/frame_viewer_instrumentation.h" | 25 #include "cc/debug/frame_viewer_instrumentation.h" |
25 #include "cc/debug/traced_value.h" | 26 #include "cc/debug/traced_value.h" |
26 #include "cc/layers/picture_layer_impl.h" | 27 #include "cc/layers/picture_layer_impl.h" |
27 #include "cc/raster/raster_buffer.h" | 28 #include "cc/raster/raster_buffer.h" |
28 #include "cc/raster/task_category.h" | 29 #include "cc/raster/task_category.h" |
29 #include "cc/tiles/tile.h" | 30 #include "cc/tiles/tile.h" |
30 #include "ui/gfx/geometry/rect_conversions.h" | 31 #include "ui/gfx/geometry/rect_conversions.h" |
31 | 32 |
32 namespace cc { | 33 namespace cc { |
33 namespace { | 34 namespace { |
34 | 35 |
35 // Flag to indicate whether we should try and detect that | 36 // Flag to indicate whether we should try and detect that |
36 // a tile is of solid color. | 37 // a tile is of solid color. |
37 const bool kUseColorEstimator = true; | 38 const bool kUseColorEstimator = true; |
38 | 39 |
39 DEFINE_SCOPED_UMA_HISTOGRAM_AREA_TIMER( | 40 DEFINE_SCOPED_UMA_HISTOGRAM_AREA_TIMER( |
40 ScopedRasterTaskTimer, | 41 ScopedRasterTaskTimer, |
41 "Compositing.%s.RasterTask.RasterUs", | 42 "Compositing.%s.RasterTask.RasterUs", |
42 "Compositing.%s.RasterTask.RasterPixelsPerMs"); | 43 "Compositing.%s.RasterTask.RasterPixelsPerMs"); |
43 | 44 |
44 // TODO(prashant.n): Separate out members needed in RunOnWorkerThread() and | |
45 // OnTaskCompleted() in RasterTaskImpl. crbug.com/613812. | |
46 class RasterTaskImpl : public TileTask { | 45 class RasterTaskImpl : public TileTask { |
47 public: | 46 public: |
48 RasterTaskImpl(TileManager* tile_manager, | 47 RasterTaskImpl(std::unique_ptr<TaskCompletionInfo> completion_info, |
49 Resource* resource, | |
50 scoped_refptr<RasterSource> raster_source, | 48 scoped_refptr<RasterSource> raster_source, |
51 const gfx::Rect& content_rect, | 49 const gfx::Rect& content_rect, |
52 const gfx::Rect& invalid_content_rect, | 50 const gfx::Rect& invalid_content_rect, |
53 float contents_scale, | 51 float contents_scale, |
54 const RasterSource::PlaybackSettings& playback_settings, | 52 const RasterSource::PlaybackSettings& playback_settings, |
55 TileResolution tile_resolution, | 53 TileResolution tile_resolution, |
56 int layer_id, | 54 int layer_id, |
57 uint64_t source_prepare_tiles_id, | 55 uint64_t source_prepare_tiles_id, |
58 Tile* tile, | 56 void* tile_ptr, |
59 uint64_t new_content_id, | 57 uint64_t new_content_id, |
60 uint64_t previous_content_id, | 58 uint64_t previous_content_id, |
61 uint64_t resource_content_id, | 59 uint64_t resource_content_id, |
62 int source_frame_number, | 60 int source_frame_number, |
63 std::unique_ptr<RasterBuffer> raster_buffer, | 61 std::unique_ptr<RasterBuffer> raster_buffer, |
64 TileTask::Vector* dependencies, | 62 TileTask::Vector* dependencies, |
65 bool supports_concurrent_execution) | 63 bool supports_concurrent_execution) |
66 : TileTask(supports_concurrent_execution, dependencies), | 64 : TileTask(supports_concurrent_execution, dependencies), |
67 tile_manager_(tile_manager), | 65 completion_info_(std::move(completion_info)), |
68 resource_(resource), | |
69 raster_source_(std::move(raster_source)), | 66 raster_source_(std::move(raster_source)), |
70 content_rect_(content_rect), | 67 content_rect_(content_rect), |
71 invalid_content_rect_(invalid_content_rect), | 68 invalid_content_rect_(invalid_content_rect), |
72 contents_scale_(contents_scale), | 69 contents_scale_(contents_scale), |
73 playback_settings_(playback_settings), | 70 playback_settings_(playback_settings), |
74 tile_resolution_(tile_resolution), | 71 tile_resolution_(tile_resolution), |
75 layer_id_(layer_id), | 72 layer_id_(layer_id), |
76 source_prepare_tiles_id_(source_prepare_tiles_id), | 73 source_prepare_tiles_id_(source_prepare_tiles_id), |
77 tile_(tile), | 74 tile_ptr_(tile_ptr), |
78 new_content_id_(new_content_id), | 75 new_content_id_(new_content_id), |
79 previous_content_id_(previous_content_id), | 76 previous_content_id_(previous_content_id), |
80 resource_content_id_(resource_content_id), | 77 resource_content_id_(resource_content_id), |
81 source_frame_number_(source_frame_number), | 78 source_frame_number_(source_frame_number), |
82 raster_buffer_(std::move(raster_buffer)) {} | 79 raster_buffer_(std::move(raster_buffer)) {} |
83 | 80 |
84 // Overridden from Task: | 81 // Overridden from Task: |
85 void RunOnWorkerThread() override { | 82 void RunOnWorkerThread() override { |
86 TRACE_EVENT1("cc", "RasterizerTaskImpl::RunOnWorkerThread", | 83 TRACE_EVENT1("cc", "RasterizerTaskImpl::RunOnWorkerThread", |
87 "source_prepare_tiles_id", source_prepare_tiles_id_); | 84 "source_prepare_tiles_id", source_prepare_tiles_id_); |
88 | 85 |
89 DCHECK(raster_source_.get()); | 86 DCHECK(raster_source_.get()); |
90 DCHECK(raster_buffer_); | 87 DCHECK(raster_buffer_); |
91 | 88 |
92 frame_viewer_instrumentation::ScopedRasterTask raster_task( | 89 frame_viewer_instrumentation::ScopedRasterTask raster_task( |
93 tile_, tile_resolution_, source_frame_number_, layer_id_); | 90 tile_ptr_, tile_resolution_, source_frame_number_, layer_id_); |
94 ScopedRasterTaskTimer timer; | 91 ScopedRasterTaskTimer timer; |
95 timer.SetArea(content_rect_.size().GetArea()); | 92 timer.SetArea(content_rect_.size().GetArea()); |
96 | 93 |
97 DCHECK(raster_source_); | 94 DCHECK(raster_source_); |
98 | 95 |
99 raster_buffer_->Playback(raster_source_.get(), content_rect_, | 96 raster_buffer_->Playback(raster_source_.get(), content_rect_, |
100 invalid_content_rect_, new_content_id_, | 97 invalid_content_rect_, new_content_id_, |
101 contents_scale_, playback_settings_); | 98 contents_scale_, playback_settings_); |
102 } | 99 } |
103 | 100 |
104 // Overridden from TileTask: | 101 // Overridden from TileTask: |
105 void OnTaskCompleted() override { | 102 void OnTaskCompleted() override { |
106 tile_manager_->OnRasterTaskCompleted(std::move(raster_buffer_), tile_, | 103 DCHECK(origin_thread_checker_.CalledOnValidThread()); |
prashant.n
2016/05/26 13:43:22
Add DCHECK_IS_ON() as we want to call this explici
reveman
2016/05/26 14:49:03
the thread checker is alleady a noop in non-debug
| |
107 resource_, state().IsCanceled()); | 104 |
105 TileManager::OnRasterTaskCompleted(std::move(raster_buffer_), | |
106 completion_info_.get(), | |
107 state().IsCanceled()); | |
108 } | 108 } |
109 | 109 |
110 protected: | 110 protected: |
111 ~RasterTaskImpl() override { DCHECK(!raster_buffer_); } | 111 ~RasterTaskImpl() override { DCHECK(!raster_buffer_); } |
112 | 112 |
113 private: | 113 private: |
114 TileManager* tile_manager_; | 114 #if DCHECK_IS_ON() |
115 Resource* resource_; | 115 base::ThreadChecker origin_thread_checker_; |
116 #endif | |
117 | |
118 // This member should be accessed only in origin thread. | |
119 std::unique_ptr<TaskCompletionInfo> completion_info_; | |
120 | |
121 // The following members should be accessed only in worker thread. | |
116 scoped_refptr<RasterSource> raster_source_; | 122 scoped_refptr<RasterSource> raster_source_; |
117 gfx::Rect content_rect_; | 123 gfx::Rect content_rect_; |
118 gfx::Rect invalid_content_rect_; | 124 gfx::Rect invalid_content_rect_; |
119 float contents_scale_; | 125 float contents_scale_; |
120 RasterSource::PlaybackSettings playback_settings_; | 126 RasterSource::PlaybackSettings playback_settings_; |
121 TileResolution tile_resolution_; | 127 TileResolution tile_resolution_; |
122 int layer_id_; | 128 int layer_id_; |
123 uint64_t source_prepare_tiles_id_; | 129 uint64_t source_prepare_tiles_id_; |
124 Tile* tile_; | 130 void* tile_ptr_; |
125 uint64_t new_content_id_; | 131 uint64_t new_content_id_; |
126 uint64_t previous_content_id_; | 132 uint64_t previous_content_id_; |
127 uint64_t resource_content_id_; | 133 uint64_t resource_content_id_; |
128 int source_frame_number_; | 134 int source_frame_number_; |
135 | |
129 std::unique_ptr<RasterBuffer> raster_buffer_; | 136 std::unique_ptr<RasterBuffer> raster_buffer_; |
130 | 137 |
131 DISALLOW_COPY_AND_ASSIGN(RasterTaskImpl); | 138 DISALLOW_COPY_AND_ASSIGN(RasterTaskImpl); |
132 }; | 139 }; |
133 | 140 |
141 struct RasterTaskCompletionInfo : public TileTask::TaskCompletionInfo { | |
142 TileManager* task_owner; | |
143 Resource* resource; | |
144 Tile* tile; | |
145 }; | |
146 | |
134 TaskCategory TaskCategoryForTileTask(TileTask* task, | 147 TaskCategory TaskCategoryForTileTask(TileTask* task, |
135 bool use_foreground_category) { | 148 bool use_foreground_category) { |
136 if (!task->supports_concurrent_execution()) | 149 if (!task->supports_concurrent_execution()) |
137 return TASK_CATEGORY_NONCONCURRENT_FOREGROUND; | 150 return TASK_CATEGORY_NONCONCURRENT_FOREGROUND; |
138 | 151 |
139 if (use_foreground_category) | 152 if (use_foreground_category) |
140 return TASK_CATEGORY_FOREGROUND; | 153 return TASK_CATEGORY_FOREGROUND; |
141 | 154 |
142 return TASK_CATEGORY_BACKGROUND; | 155 return TASK_CATEGORY_BACKGROUND; |
143 } | 156 } |
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
929 &task); | 942 &task); |
930 if (task) | 943 if (task) |
931 decode_tasks.push_back(task); | 944 decode_tasks.push_back(task); |
932 | 945 |
933 if (need_to_unref_when_finished) | 946 if (need_to_unref_when_finished) |
934 ++it; | 947 ++it; |
935 else | 948 else |
936 it = images.erase(it); | 949 it = images.erase(it); |
937 } | 950 } |
938 | 951 |
939 bool supports_concurrent_execution = !use_gpu_rasterization_; | 952 std::unique_ptr<RasterTaskCompletionInfo> completion_info( |
953 new RasterTaskCompletionInfo); | |
954 completion_info->task_owner = this; | |
955 completion_info->resource = resource; | |
956 completion_info->tile = tile; | |
940 std::unique_ptr<RasterBuffer> raster_buffer = | 957 std::unique_ptr<RasterBuffer> raster_buffer = |
941 tile_task_manager_->GetRasterBufferProvider()->AcquireBufferForRaster( | 958 tile_task_manager_->GetRasterBufferProvider()->AcquireBufferForRaster( |
942 resource, resource_content_id, tile->invalidated_id()); | 959 resource, resource_content_id, tile->invalidated_id()); |
960 bool supports_concurrent_execution = !use_gpu_rasterization_; | |
943 return make_scoped_refptr(new RasterTaskImpl( | 961 return make_scoped_refptr(new RasterTaskImpl( |
944 this, resource, prioritized_tile.raster_source(), tile->content_rect(), | 962 std::move(completion_info), prioritized_tile.raster_source(), |
945 tile->invalidated_content_rect(), tile->contents_scale(), | 963 tile->content_rect(), tile->invalidated_content_rect(), |
946 playback_settings, prioritized_tile.priority().resolution, | 964 tile->contents_scale(), playback_settings, |
947 tile->layer_id(), prepare_tiles_count_, tile, tile->id(), | 965 prioritized_tile.priority().resolution, tile->layer_id(), |
966 prepare_tiles_count_, static_cast<void*>(tile), tile->id(), | |
948 tile->invalidated_id(), resource_content_id, tile->source_frame_number(), | 967 tile->invalidated_id(), resource_content_id, tile->source_frame_number(), |
949 std::move(raster_buffer), &decode_tasks, supports_concurrent_execution)); | 968 std::move(raster_buffer), &decode_tasks, supports_concurrent_execution)); |
950 } | 969 } |
951 | 970 |
971 // static | |
952 void TileManager::OnRasterTaskCompleted( | 972 void TileManager::OnRasterTaskCompleted( |
953 std::unique_ptr<RasterBuffer> raster_buffer, | 973 std::unique_ptr<RasterBuffer> raster_buffer, |
954 Tile* tile, | 974 TileTask::TaskCompletionInfo* completion_info, |
955 Resource* resource, | |
956 bool was_canceled) { | 975 bool was_canceled) { |
957 DCHECK(tile); | 976 RasterTaskCompletionInfo* info = |
958 DCHECK(tiles_.find(tile->id()) != tiles_.end()); | 977 static_cast<RasterTaskCompletionInfo*>(completion_info); |
959 tile_task_manager_->GetRasterBufferProvider()->ReleaseBufferForRaster( | 978 DCHECK(info->tile); |
960 std::move(raster_buffer)); | 979 DCHECK(info->task_owner->tiles_.find(info->tile->id()) != |
980 info->task_owner->tiles_.end()); | |
981 info->task_owner->tile_task_manager_->GetRasterBufferProvider() | |
982 ->ReleaseBufferForRaster(std::move(raster_buffer)); | |
961 | 983 |
962 TileDrawInfo& draw_info = tile->draw_info(); | 984 TileDrawInfo& draw_info = info->tile->draw_info(); |
963 DCHECK(tile->raster_task_.get()); | 985 DCHECK(info->tile->raster_task_.get()); |
964 orphan_tasks_.push_back(tile->raster_task_); | 986 info->task_owner->orphan_tasks_.push_back(info->tile->raster_task_); |
965 tile->raster_task_ = nullptr; | 987 info->tile->raster_task_ = nullptr; |
966 | 988 |
967 // Unref all the images. | 989 // Unref all the images. |
968 auto images_it = scheduled_draw_images_.find(tile->id()); | 990 auto images_it = |
991 info->task_owner->scheduled_draw_images_.find(info->tile->id()); | |
969 const std::vector<DrawImage>& images = images_it->second; | 992 const std::vector<DrawImage>& images = images_it->second; |
970 for (const auto& image : images) | 993 for (const auto& image : images) |
971 image_decode_controller_->UnrefImage(image); | 994 info->task_owner->image_decode_controller_->UnrefImage(image); |
972 scheduled_draw_images_.erase(images_it); | 995 info->task_owner->scheduled_draw_images_.erase(images_it); |
973 | 996 |
974 if (was_canceled) { | 997 if (was_canceled) { |
975 ++flush_stats_.canceled_count; | 998 ++info->task_owner->flush_stats_.canceled_count; |
976 // TODO(ericrk): If more partial raster work is done in the future, it may | 999 // TODO(ericrk): If more partial raster work is done in the future, it may |
977 // be worth returning the resource to the pool with its previous ID (not | 1000 // be worth returning the resource to the pool with its previous ID (not |
978 // currently tracked). crrev.com/1370333002/#ps40001 has a possible method | 1001 // currently tracked). crrev.com/1370333002/#ps40001 has a possible method |
979 // of achieving this. | 1002 // of achieving this. |
980 resource_pool_->ReleaseResource(resource, 0 /* content_id */); | 1003 info->task_owner->resource_pool_->ReleaseResource(info->resource, |
1004 0 /* content_id */); | |
981 return; | 1005 return; |
982 } | 1006 } |
983 | 1007 |
984 ++flush_stats_.completed_count; | 1008 ++info->task_owner->flush_stats_.completed_count; |
985 | 1009 |
986 draw_info.set_use_resource(); | 1010 draw_info.set_use_resource(); |
987 draw_info.resource_ = resource; | 1011 draw_info.resource_ = info->resource; |
988 draw_info.contents_swizzled_ = DetermineResourceRequiresSwizzle(tile); | 1012 draw_info.contents_swizzled_ = |
1013 info->task_owner->DetermineResourceRequiresSwizzle(info->tile); | |
989 | 1014 |
990 DCHECK(draw_info.IsReadyToDraw()); | 1015 DCHECK(draw_info.IsReadyToDraw()); |
991 draw_info.set_was_ever_ready_to_draw(); | 1016 draw_info.set_was_ever_ready_to_draw(); |
992 | 1017 |
993 client_->NotifyTileStateChanged(tile); | 1018 info->task_owner->client_->NotifyTileStateChanged(info->tile); |
994 } | 1019 } |
995 | 1020 |
996 ScopedTilePtr TileManager::CreateTile(const Tile::CreateInfo& info, | 1021 ScopedTilePtr TileManager::CreateTile(const Tile::CreateInfo& info, |
997 int layer_id, | 1022 int layer_id, |
998 int source_frame_number, | 1023 int source_frame_number, |
999 int flags) { | 1024 int flags) { |
1000 // We need to have a tile task worker pool to do anything meaningful with | 1025 // We need to have a tile task worker pool to do anything meaningful with |
1001 // tiles. | 1026 // tiles. |
1002 DCHECK(tile_task_manager_); | 1027 DCHECK(tile_task_manager_); |
1003 ScopedTilePtr tile( | 1028 ScopedTilePtr tile( |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1281 void TileManager::Signals::reset() { | 1306 void TileManager::Signals::reset() { |
1282 ready_to_activate = false; | 1307 ready_to_activate = false; |
1283 did_notify_ready_to_activate = false; | 1308 did_notify_ready_to_activate = false; |
1284 ready_to_draw = false; | 1309 ready_to_draw = false; |
1285 did_notify_ready_to_draw = false; | 1310 did_notify_ready_to_draw = false; |
1286 all_tile_tasks_completed = false; | 1311 all_tile_tasks_completed = false; |
1287 did_notify_all_tile_tasks_completed = false; | 1312 did_notify_all_tile_tasks_completed = false; |
1288 } | 1313 } |
1289 | 1314 |
1290 } // namespace cc | 1315 } // namespace cc |
OLD | NEW |