OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/pixel_buffer_tile_task_worker_pool.h" | 5 #include "cc/resources/pixel_buffer_tile_task_worker_pool.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/containers/stack_container.h" | 9 #include "base/containers/stack_container.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
11 #include "base/debug/trace_event_argument.h" | 11 #include "base/debug/trace_event_argument.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "cc/base/util.h" |
13 #include "cc/debug/traced_value.h" | 14 #include "cc/debug/traced_value.h" |
14 #include "cc/resources/raster_buffer.h" | 15 #include "cc/resources/raster_buffer.h" |
15 #include "cc/resources/resource.h" | 16 #include "cc/resources/resource.h" |
16 #include "gpu/command_buffer/client/gles2_interface.h" | 17 #include "gpu/command_buffer/client/gles2_interface.h" |
17 | 18 |
18 namespace cc { | 19 namespace cc { |
19 namespace { | 20 namespace { |
20 | 21 |
21 class RasterBufferImpl : public RasterBuffer { | 22 class RasterBufferImpl : public RasterBuffer { |
22 public: | 23 public: |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 task_runner, task_graph_runner, context_provider, resource_provider, | 107 task_runner, task_graph_runner, context_provider, resource_provider, |
107 max_transfer_buffer_usage_bytes)); | 108 max_transfer_buffer_usage_bytes)); |
108 } | 109 } |
109 | 110 |
110 PixelBufferTileTaskWorkerPool::PixelBufferTileTaskWorkerPool( | 111 PixelBufferTileTaskWorkerPool::PixelBufferTileTaskWorkerPool( |
111 base::SequencedTaskRunner* task_runner, | 112 base::SequencedTaskRunner* task_runner, |
112 TaskGraphRunner* task_graph_runner, | 113 TaskGraphRunner* task_graph_runner, |
113 ContextProvider* context_provider, | 114 ContextProvider* context_provider, |
114 ResourceProvider* resource_provider, | 115 ResourceProvider* resource_provider, |
115 size_t max_transfer_buffer_usage_bytes) | 116 size_t max_transfer_buffer_usage_bytes) |
116 : task_runner_(task_runner), | 117 : single_entry_holder(false), |
| 118 task_runner_(task_runner), |
117 task_graph_runner_(task_graph_runner), | 119 task_graph_runner_(task_graph_runner), |
118 namespace_token_(task_graph_runner->GetNamespaceToken()), | 120 namespace_token_(task_graph_runner->GetNamespaceToken()), |
119 context_provider_(context_provider), | 121 context_provider_(context_provider), |
120 resource_provider_(resource_provider), | 122 resource_provider_(resource_provider), |
121 shutdown_(false), | 123 shutdown_(false), |
122 scheduled_raster_task_count_(0u), | 124 scheduled_raster_task_count_(0u), |
123 bytes_pending_upload_(0u), | 125 bytes_pending_upload_(0u), |
124 max_bytes_pending_upload_(max_transfer_buffer_usage_bytes), | 126 max_bytes_pending_upload_(max_transfer_buffer_usage_bytes), |
125 has_performed_uploads_since_last_flush_(false), | 127 has_performed_uploads_since_last_flush_(false), |
126 check_for_completed_raster_task_notifier_( | 128 check_for_completed_raster_task_notifier_( |
(...skipping 19 matching lines...) Expand all Loading... |
146 TileTaskRunner* PixelBufferTileTaskWorkerPool::AsTileTaskRunner() { | 148 TileTaskRunner* PixelBufferTileTaskWorkerPool::AsTileTaskRunner() { |
147 return this; | 149 return this; |
148 } | 150 } |
149 | 151 |
150 void PixelBufferTileTaskWorkerPool::SetClient(TileTaskRunnerClient* client) { | 152 void PixelBufferTileTaskWorkerPool::SetClient(TileTaskRunnerClient* client) { |
151 client_ = client; | 153 client_ = client; |
152 } | 154 } |
153 | 155 |
154 void PixelBufferTileTaskWorkerPool::Shutdown() { | 156 void PixelBufferTileTaskWorkerPool::Shutdown() { |
155 TRACE_EVENT0("cc", "PixelBufferTileTaskWorkerPool::Shutdown"); | 157 TRACE_EVENT0("cc", "PixelBufferTileTaskWorkerPool::Shutdown"); |
| 158 ScopedSingleEntry scoped_single_entry(&single_entry_holder); |
156 | 159 |
157 shutdown_ = true; | 160 shutdown_ = true; |
158 | 161 |
159 TaskGraph empty; | 162 TaskGraph empty; |
160 task_graph_runner_->ScheduleTasks(namespace_token_, &empty); | 163 task_graph_runner_->ScheduleTasks(namespace_token_, &empty); |
161 task_graph_runner_->WaitForTasksToFinishRunning(namespace_token_); | 164 task_graph_runner_->WaitForTasksToFinishRunning(namespace_token_); |
162 | 165 |
163 CheckForCompletedRasterizerTasks(); | 166 CheckForCompletedRasterizerTasks(); |
164 CheckForCompletedUploads(); | 167 CheckForCompletedUploads(); |
165 | 168 |
166 check_for_completed_raster_task_notifier_.Shutdown(); | 169 check_for_completed_raster_task_notifier_.Shutdown(); |
167 | 170 |
168 for (RasterTaskState::Vector::iterator it = raster_task_states_.begin(); | 171 for (RasterTaskState::Vector::iterator it = raster_task_states_.begin(); |
169 it != raster_task_states_.end(); ++it) { | 172 it != raster_task_states_.end(); ++it) { |
170 RasterTaskState& state = *it; | 173 RasterTaskState& state = *it; |
171 | 174 |
172 // All unscheduled tasks need to be canceled. | 175 // All unscheduled tasks need to be canceled. |
173 if (state.type == RasterTaskState::UNSCHEDULED) { | 176 if (state.type == RasterTaskState::UNSCHEDULED) { |
174 completed_raster_tasks_.push_back(state.task); | 177 completed_raster_tasks_.push_back(state.task); |
175 state.type = RasterTaskState::COMPLETED; | 178 state.type = RasterTaskState::COMPLETED; |
176 } | 179 } |
177 } | 180 } |
178 DCHECK_EQ(completed_raster_tasks_.size(), raster_task_states_.size()); | 181 DCHECK_EQ(completed_raster_tasks_.size(), raster_task_states_.size()); |
179 } | 182 } |
180 | 183 |
181 void PixelBufferTileTaskWorkerPool::ScheduleTasks(TileTaskQueue* queue) { | 184 void PixelBufferTileTaskWorkerPool::ScheduleTasks(TileTaskQueue* queue) { |
182 TRACE_EVENT0("cc", "PixelBufferTileTaskWorkerPool::ScheduleTasks"); | 185 TRACE_EVENT0("cc", "PixelBufferTileTaskWorkerPool::ScheduleTasks"); |
| 186 ScopedSingleEntry scoped_single_entry(&single_entry_holder); |
183 | 187 |
184 if (should_notify_client_if_no_tasks_are_pending_.none()) | 188 if (should_notify_client_if_no_tasks_are_pending_.none()) |
185 TRACE_EVENT_ASYNC_BEGIN0("cc", "ScheduledTasks", this); | 189 TRACE_EVENT_ASYNC_BEGIN0("cc", "ScheduledTasks", this); |
186 | 190 |
187 should_notify_client_if_no_tasks_are_pending_.set(); | 191 should_notify_client_if_no_tasks_are_pending_.set(); |
188 std::fill(task_counts_, task_counts_ + kNumberOfTaskSets, 0); | 192 std::fill(task_counts_, task_counts_ + kNumberOfTaskSets, 0); |
189 | 193 |
190 // Update raster task state and remove items from old queue. | 194 // Update raster task state and remove items from old queue. |
191 for (TileTaskQueue::Item::Vector::const_iterator it = queue->items.begin(); | 195 for (TileTaskQueue::Item::Vector::const_iterator it = queue->items.begin(); |
192 it != queue->items.end(); ++it) { | 196 it != queue->items.end(); ++it) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 | 274 |
271 // Reschedule check for completed raster tasks. | 275 // Reschedule check for completed raster tasks. |
272 check_for_completed_raster_task_notifier_.Schedule(); | 276 check_for_completed_raster_task_notifier_.Schedule(); |
273 | 277 |
274 TRACE_EVENT_ASYNC_STEP_INTO1("cc", "ScheduledTasks", this, StateName(), | 278 TRACE_EVENT_ASYNC_STEP_INTO1("cc", "ScheduledTasks", this, StateName(), |
275 "state", StateAsValue()); | 279 "state", StateAsValue()); |
276 } | 280 } |
277 | 281 |
278 void PixelBufferTileTaskWorkerPool::CheckForCompletedTasks() { | 282 void PixelBufferTileTaskWorkerPool::CheckForCompletedTasks() { |
279 TRACE_EVENT0("cc", "PixelBufferTileTaskWorkerPool::CheckForCompletedTasks"); | 283 TRACE_EVENT0("cc", "PixelBufferTileTaskWorkerPool::CheckForCompletedTasks"); |
| 284 ScopedSingleEntry scoped_single_entry(&single_entry_holder); |
280 | 285 |
281 CheckForCompletedRasterizerTasks(); | 286 CheckForCompletedRasterizerTasks(); |
282 CheckForCompletedUploads(); | 287 CheckForCompletedUploads(); |
283 FlushUploads(); | 288 FlushUploads(); |
284 | 289 |
285 for (TileTask::Vector::const_iterator it = | 290 for (TileTask::Vector::const_iterator it = |
286 completed_image_decode_tasks_.begin(); | 291 completed_image_decode_tasks_.begin(); |
287 it != completed_image_decode_tasks_.end(); ++it) { | 292 it != completed_image_decode_tasks_.end(); ++it) { |
288 TileTask* task = it->get(); | 293 TileTask* task = it->get(); |
289 task->RunReplyOnOriginThread(); | 294 task->RunReplyOnOriginThread(); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 // Triggers if the current task belongs to a set that should be empty. | 439 // Triggers if the current task belongs to a set that should be empty. |
435 DCHECK((state.task_sets & ~NonEmptyTaskSetsFromTaskCounts(task_counts_)) | 440 DCHECK((state.task_sets & ~NonEmptyTaskSetsFromTaskCounts(task_counts_)) |
436 .none()); | 441 .none()); |
437 RemoveTaskSetsFromTaskCounts(task_counts_, state.task_sets); | 442 RemoveTaskSetsFromTaskCounts(task_counts_, state.task_sets); |
438 } | 443 } |
439 } | 444 } |
440 | 445 |
441 void PixelBufferTileTaskWorkerPool::CheckForCompletedRasterTasks() { | 446 void PixelBufferTileTaskWorkerPool::CheckForCompletedRasterTasks() { |
442 TRACE_EVENT0("cc", | 447 TRACE_EVENT0("cc", |
443 "PixelBufferTileTaskWorkerPool::CheckForCompletedRasterTasks"); | 448 "PixelBufferTileTaskWorkerPool::CheckForCompletedRasterTasks"); |
| 449 ScopedSingleEntry scoped_single_entry(&single_entry_holder); |
444 | 450 |
445 // Since this function can be called directly, cancel any pending checks. | 451 // Since this function can be called directly, cancel any pending checks. |
446 check_for_completed_raster_task_notifier_.Cancel(); | 452 check_for_completed_raster_task_notifier_.Cancel(); |
447 | 453 |
448 DCHECK(should_notify_client_if_no_tasks_are_pending_.any()); | 454 DCHECK(should_notify_client_if_no_tasks_are_pending_.any()); |
449 | 455 |
450 CheckForCompletedRasterizerTasks(); | 456 CheckForCompletedRasterizerTasks(); |
451 CheckForCompletedUploads(); | 457 CheckForCompletedUploads(); |
452 FlushUploads(); | 458 FlushUploads(); |
453 | 459 |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 void PixelBufferTileTaskWorkerPool::ThrottleStateAsValueInto( | 723 void PixelBufferTileTaskWorkerPool::ThrottleStateAsValueInto( |
718 base::debug::TracedValue* throttle_state) const { | 724 base::debug::TracedValue* throttle_state) const { |
719 throttle_state->SetInteger("bytes_available_for_upload", | 725 throttle_state->SetInteger("bytes_available_for_upload", |
720 max_bytes_pending_upload_ - bytes_pending_upload_); | 726 max_bytes_pending_upload_ - bytes_pending_upload_); |
721 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_); | 727 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_); |
722 throttle_state->SetInteger("scheduled_raster_task_count", | 728 throttle_state->SetInteger("scheduled_raster_task_count", |
723 scheduled_raster_task_count_); | 729 scheduled_raster_task_count_); |
724 } | 730 } |
725 | 731 |
726 } // namespace cc | 732 } // namespace cc |
OLD | NEW |