Chromium Code Reviews| 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/platform_thread.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 // TODO(prashant.n): Separate out members needed in RunOnWorkerThread() and |
| 45 // OnTaskCompleted() in RasterTaskImpl. crbug.com/613812. | 46 // OnTaskCompleted() in RasterTaskImpl. crbug.com/613812. |
|
prashant.n
2016/05/24 15:46:09
I'll remove this comment.
| |
| 46 class RasterTaskImpl : public TileTask { | 47 class RasterTaskImpl : public TileTask { |
| 47 public: | 48 public: |
| 48 RasterTaskImpl(TileManager* tile_manager, | 49 struct CompletionData { |
|
reveman
2016/05/25 04:19:44
not sure moving it to a struct makes much differen
prashant.n
2016/05/25 04:25:06
Hmm. So we can have another approach mentioned in
| |
| 49 Resource* resource, | 50 TileManager* tile_manager; |
| 51 Resource* resource; | |
| 52 Tile* tile; | |
| 53 }; | |
|
prashant.n
2016/05/25 03:48:04
Another approach -
1. Have empty CompletionData
| |
| 54 | |
| 55 RasterTaskImpl(const CompletionData& completion_data, | |
| 56 base::PlatformThreadId origin_thread_id, | |
| 50 scoped_refptr<RasterSource> raster_source, | 57 scoped_refptr<RasterSource> raster_source, |
| 51 const gfx::Rect& content_rect, | 58 const gfx::Rect& content_rect, |
| 52 const gfx::Rect& invalid_content_rect, | 59 const gfx::Rect& invalid_content_rect, |
| 53 float contents_scale, | 60 float contents_scale, |
| 54 const RasterSource::PlaybackSettings& playback_settings, | 61 const RasterSource::PlaybackSettings& playback_settings, |
| 55 TileResolution tile_resolution, | 62 TileResolution tile_resolution, |
| 56 int layer_id, | 63 int layer_id, |
| 57 uint64_t source_prepare_tiles_id, | 64 uint64_t source_prepare_tiles_id, |
| 58 Tile* tile, | 65 void* tile_ptr, |
| 59 uint64_t new_content_id, | 66 uint64_t new_content_id, |
| 60 uint64_t previous_content_id, | 67 uint64_t previous_content_id, |
| 61 uint64_t resource_content_id, | 68 uint64_t resource_content_id, |
| 62 int source_frame_number, | 69 int source_frame_number, |
| 63 std::unique_ptr<RasterBuffer> raster_buffer, | 70 std::unique_ptr<RasterBuffer> raster_buffer, |
| 64 TileTask::Vector* dependencies, | 71 TileTask::Vector* dependencies, |
| 65 bool supports_concurrent_execution) | 72 bool supports_concurrent_execution) |
| 66 : TileTask(supports_concurrent_execution, dependencies), | 73 : TileTask(supports_concurrent_execution, dependencies), |
| 67 tile_manager_(tile_manager), | 74 completion_data_(completion_data), |
| 68 resource_(resource), | 75 origin_thread_id_(origin_thread_id), |
| 69 raster_source_(std::move(raster_source)), | 76 raster_source_(std::move(raster_source)), |
| 70 content_rect_(content_rect), | 77 content_rect_(content_rect), |
| 71 invalid_content_rect_(invalid_content_rect), | 78 invalid_content_rect_(invalid_content_rect), |
| 72 contents_scale_(contents_scale), | 79 contents_scale_(contents_scale), |
| 73 playback_settings_(playback_settings), | 80 playback_settings_(playback_settings), |
| 74 tile_resolution_(tile_resolution), | 81 tile_resolution_(tile_resolution), |
| 75 layer_id_(layer_id), | 82 layer_id_(layer_id), |
| 76 source_prepare_tiles_id_(source_prepare_tiles_id), | 83 source_prepare_tiles_id_(source_prepare_tiles_id), |
| 77 tile_(tile), | 84 tile_ptr_(tile_ptr), |
| 78 new_content_id_(new_content_id), | 85 new_content_id_(new_content_id), |
| 79 previous_content_id_(previous_content_id), | 86 previous_content_id_(previous_content_id), |
| 80 resource_content_id_(resource_content_id), | 87 resource_content_id_(resource_content_id), |
| 81 source_frame_number_(source_frame_number), | 88 source_frame_number_(source_frame_number), |
| 82 raster_buffer_(std::move(raster_buffer)) {} | 89 raster_buffer_(std::move(raster_buffer)) {} |
| 83 | 90 |
| 84 // Overridden from Task: | 91 // Overridden from Task: |
| 85 void RunOnWorkerThread() override { | 92 void RunOnWorkerThread() override { |
| 86 TRACE_EVENT1("cc", "RasterizerTaskImpl::RunOnWorkerThread", | 93 TRACE_EVENT1("cc", "RasterizerTaskImpl::RunOnWorkerThread", |
| 87 "source_prepare_tiles_id", source_prepare_tiles_id_); | 94 "source_prepare_tiles_id", source_prepare_tiles_id_); |
| 88 | 95 |
| 89 DCHECK(raster_source_.get()); | 96 DCHECK(raster_source_.get()); |
| 90 DCHECK(raster_buffer_); | 97 DCHECK(raster_buffer_); |
| 91 | 98 |
| 92 frame_viewer_instrumentation::ScopedRasterTask raster_task( | 99 frame_viewer_instrumentation::ScopedRasterTask raster_task( |
| 93 tile_, tile_resolution_, source_frame_number_, layer_id_); | 100 tile_ptr_, tile_resolution_, source_frame_number_, layer_id_); |
| 94 ScopedRasterTaskTimer timer; | 101 ScopedRasterTaskTimer timer; |
| 95 timer.SetArea(content_rect_.size().GetArea()); | 102 timer.SetArea(content_rect_.size().GetArea()); |
| 96 | 103 |
| 97 DCHECK(raster_source_); | 104 DCHECK(raster_source_); |
| 98 | 105 |
| 99 raster_buffer_->Playback(raster_source_.get(), content_rect_, | 106 raster_buffer_->Playback(raster_source_.get(), content_rect_, |
| 100 invalid_content_rect_, new_content_id_, | 107 invalid_content_rect_, new_content_id_, |
| 101 contents_scale_, playback_settings_); | 108 contents_scale_, playback_settings_); |
| 102 } | 109 } |
| 103 | 110 |
| 104 // Overridden from TileTask: | 111 // Overridden from TileTask: |
| 105 void OnTaskCompleted() override { | 112 void OnTaskCompleted() override { |
| 106 tile_manager_->OnRasterTaskCompleted(std::move(raster_buffer_), tile_, | 113 CompletionData& data = GetCompletionData(); |
| 107 resource_, state().IsCanceled()); | 114 data.tile_manager->OnRasterTaskCompleted(std::move(raster_buffer_), |
| 115 data.tile, data.resource, | |
| 116 state().IsCanceled()); | |
| 108 } | 117 } |
| 109 | 118 |
| 110 protected: | 119 protected: |
| 111 ~RasterTaskImpl() override { DCHECK(!raster_buffer_); } | 120 ~RasterTaskImpl() override { DCHECK(!raster_buffer_); } |
| 112 | 121 |
| 113 private: | 122 private: |
| 114 TileManager* tile_manager_; | 123 bool IsRunningOnOriginThread() { |
|
reveman
2016/05/25 04:19:44
hm, can we use base::ThreadChecker instead?
| |
| 115 Resource* resource_; | 124 return origin_thread_id_ == base::PlatformThread::CurrentId(); |
| 125 } | |
| 126 | |
| 127 CompletionData& GetCompletionData() { | |
| 128 DCHECK(IsRunningOnOriginThread()); | |
| 129 return completion_data_; | |
| 130 } | |
| 131 | |
| 132 // This member is accessed only in origin thread and do not access it | |
| 133 // directly. Use accessor method GetCompletionData() instead. | |
| 134 CompletionData completion_data_; | |
| 135 | |
| 136 // Members accessed on worker or origin thread. | |
| 137 base::PlatformThreadId origin_thread_id_; | |
| 116 scoped_refptr<RasterSource> raster_source_; | 138 scoped_refptr<RasterSource> raster_source_; |
| 117 gfx::Rect content_rect_; | 139 gfx::Rect content_rect_; |
| 118 gfx::Rect invalid_content_rect_; | 140 gfx::Rect invalid_content_rect_; |
| 119 float contents_scale_; | 141 float contents_scale_; |
| 120 RasterSource::PlaybackSettings playback_settings_; | 142 RasterSource::PlaybackSettings playback_settings_; |
| 121 TileResolution tile_resolution_; | 143 TileResolution tile_resolution_; |
| 122 int layer_id_; | 144 int layer_id_; |
| 123 uint64_t source_prepare_tiles_id_; | 145 uint64_t source_prepare_tiles_id_; |
| 124 Tile* tile_; | 146 void* tile_ptr_; |
|
reveman
2016/05/25 04:19:44
what is this tile_ptr used for? logging? do we hav
prashant.n
2016/05/25 04:25:06
Yes for logging it is used (frame_viewer_instrumen
| |
| 125 uint64_t new_content_id_; | 147 uint64_t new_content_id_; |
| 126 uint64_t previous_content_id_; | 148 uint64_t previous_content_id_; |
| 127 uint64_t resource_content_id_; | 149 uint64_t resource_content_id_; |
| 128 int source_frame_number_; | 150 int source_frame_number_; |
| 129 std::unique_ptr<RasterBuffer> raster_buffer_; | 151 std::unique_ptr<RasterBuffer> raster_buffer_; |
| 130 | 152 |
| 131 DISALLOW_COPY_AND_ASSIGN(RasterTaskImpl); | 153 DISALLOW_COPY_AND_ASSIGN(RasterTaskImpl); |
| 132 }; | 154 }; |
| 133 | 155 |
| 134 TaskCategory TaskCategoryForTileTask(TileTask* task, | 156 TaskCategory TaskCategoryForTileTask(TileTask* task, |
| (...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 933 if (need_to_unref_when_finished) | 955 if (need_to_unref_when_finished) |
| 934 ++it; | 956 ++it; |
| 935 else | 957 else |
| 936 it = images.erase(it); | 958 it = images.erase(it); |
| 937 } | 959 } |
| 938 | 960 |
| 939 bool supports_concurrent_execution = !use_gpu_rasterization_; | 961 bool supports_concurrent_execution = !use_gpu_rasterization_; |
| 940 std::unique_ptr<RasterBuffer> raster_buffer = | 962 std::unique_ptr<RasterBuffer> raster_buffer = |
| 941 tile_task_manager_->GetRasterBufferProvider()->AcquireBufferForRaster( | 963 tile_task_manager_->GetRasterBufferProvider()->AcquireBufferForRaster( |
| 942 resource, resource_content_id, tile->invalidated_id()); | 964 resource, resource_content_id, tile->invalidated_id()); |
| 965 RasterTaskImpl::CompletionData completion_data; | |
| 966 completion_data.tile_manager = this; | |
| 967 completion_data.resource = resource; | |
| 968 completion_data.tile = tile; | |
| 969 // TODO(prashant.n): Cache thread id in TileManager. | |
| 943 return make_scoped_refptr(new RasterTaskImpl( | 970 return make_scoped_refptr(new RasterTaskImpl( |
| 944 this, resource, prioritized_tile.raster_source(), tile->content_rect(), | 971 completion_data, base::PlatformThread::CurrentId(), |
| 972 prioritized_tile.raster_source(), tile->content_rect(), | |
| 945 tile->invalidated_content_rect(), tile->contents_scale(), | 973 tile->invalidated_content_rect(), tile->contents_scale(), |
| 946 playback_settings, prioritized_tile.priority().resolution, | 974 playback_settings, prioritized_tile.priority().resolution, |
| 947 tile->layer_id(), prepare_tiles_count_, tile, tile->id(), | 975 tile->layer_id(), prepare_tiles_count_, static_cast<void*>(tile), |
| 948 tile->invalidated_id(), resource_content_id, tile->source_frame_number(), | 976 tile->id(), tile->invalidated_id(), resource_content_id, |
| 949 std::move(raster_buffer), &decode_tasks, supports_concurrent_execution)); | 977 tile->source_frame_number(), std::move(raster_buffer), &decode_tasks, |
| 978 supports_concurrent_execution)); | |
| 950 } | 979 } |
| 951 | 980 |
| 952 void TileManager::OnRasterTaskCompleted( | 981 void TileManager::OnRasterTaskCompleted( |
| 953 std::unique_ptr<RasterBuffer> raster_buffer, | 982 std::unique_ptr<RasterBuffer> raster_buffer, |
| 954 Tile* tile, | 983 Tile* tile, |
| 955 Resource* resource, | 984 Resource* resource, |
| 956 bool was_canceled) { | 985 bool was_canceled) { |
| 957 DCHECK(tile); | 986 DCHECK(tile); |
| 958 DCHECK(tiles_.find(tile->id()) != tiles_.end()); | 987 DCHECK(tiles_.find(tile->id()) != tiles_.end()); |
| 959 tile_task_manager_->GetRasterBufferProvider()->ReleaseBufferForRaster( | 988 tile_task_manager_->GetRasterBufferProvider()->ReleaseBufferForRaster( |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1281 void TileManager::Signals::reset() { | 1310 void TileManager::Signals::reset() { |
| 1282 ready_to_activate = false; | 1311 ready_to_activate = false; |
| 1283 did_notify_ready_to_activate = false; | 1312 did_notify_ready_to_activate = false; |
| 1284 ready_to_draw = false; | 1313 ready_to_draw = false; |
| 1285 did_notify_ready_to_draw = false; | 1314 did_notify_ready_to_draw = false; |
| 1286 all_tile_tasks_completed = false; | 1315 all_tile_tasks_completed = false; |
| 1287 did_notify_all_tile_tasks_completed = false; | 1316 did_notify_all_tile_tasks_completed = false; |
| 1288 } | 1317 } |
| 1289 | 1318 |
| 1290 } // namespace cc | 1319 } // namespace cc |
| OLD | NEW |