| 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_raster_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/debug/traced_value.h" | 13 #include "cc/debug/traced_value.h" |
| 14 #include "cc/resources/raster_buffer.h" | 14 #include "cc/resources/raster_buffer.h" |
| 15 #include "cc/resources/resource.h" | 15 #include "cc/resources/resource.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 34 resource_provider_->ReleasePixelBuffer(resource_->id()); | 34 resource_provider_->ReleasePixelBuffer(resource_->id()); |
| 35 } | 35 } |
| 36 | 36 |
| 37 // Overridden from RasterBuffer: | 37 // Overridden from RasterBuffer: |
| 38 void Playback(const RasterSource* raster_source, | 38 void Playback(const RasterSource* raster_source, |
| 39 const gfx::Rect& rect, | 39 const gfx::Rect& rect, |
| 40 float scale) override { | 40 float scale) override { |
| 41 if (!memory_) | 41 if (!memory_) |
| 42 return; | 42 return; |
| 43 | 43 |
| 44 RasterWorkerPool::PlaybackToMemory(memory_, resource_->format(), | 44 TileTaskWorkerPool::PlaybackToMemory(memory_, resource_->format(), |
| 45 resource_->size(), stride_, | 45 resource_->size(), stride_, |
| 46 raster_source, rect, scale); | 46 raster_source, rect, scale); |
| 47 } | 47 } |
| 48 | 48 |
| 49 private: | 49 private: |
| 50 ResourceProvider* resource_provider_; | 50 ResourceProvider* resource_provider_; |
| 51 const Resource* resource_; | 51 const Resource* resource_; |
| 52 uint8_t* memory_; | 52 uint8_t* memory_; |
| 53 int stride_; | 53 int stride_; |
| 54 | 54 |
| 55 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); | 55 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); |
| 56 }; | 56 }; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 82 void RemoveTaskSetsFromTaskCounts(size_t* task_counts, | 82 void RemoveTaskSetsFromTaskCounts(size_t* task_counts, |
| 83 const TaskSetCollection& task_sets) { | 83 const TaskSetCollection& task_sets) { |
| 84 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) { | 84 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) { |
| 85 if (task_sets[task_set]) | 85 if (task_sets[task_set]) |
| 86 task_counts[task_set]--; | 86 task_counts[task_set]--; |
| 87 } | 87 } |
| 88 } | 88 } |
| 89 | 89 |
| 90 } // namespace | 90 } // namespace |
| 91 | 91 |
| 92 PixelBufferRasterWorkerPool::RasterTaskState::RasterTaskState( | 92 PixelBufferTileTaskWorkerPool::RasterTaskState::RasterTaskState( |
| 93 RasterTask* task, | 93 RasterTask* task, |
| 94 const TaskSetCollection& task_sets) | 94 const TaskSetCollection& task_sets) |
| 95 : type(UNSCHEDULED), task(task), task_sets(task_sets) { | 95 : type(UNSCHEDULED), task(task), task_sets(task_sets) { |
| 96 } | 96 } |
| 97 | 97 |
| 98 // static | 98 // static |
| 99 scoped_ptr<RasterWorkerPool> PixelBufferRasterWorkerPool::Create( | 99 scoped_ptr<TileTaskWorkerPool> PixelBufferTileTaskWorkerPool::Create( |
| 100 base::SequencedTaskRunner* task_runner, | 100 base::SequencedTaskRunner* task_runner, |
| 101 TaskGraphRunner* task_graph_runner, | 101 TaskGraphRunner* task_graph_runner, |
| 102 ContextProvider* context_provider, | 102 ContextProvider* context_provider, |
| 103 ResourceProvider* resource_provider, | 103 ResourceProvider* resource_provider, |
| 104 size_t max_transfer_buffer_usage_bytes) { | 104 size_t max_transfer_buffer_usage_bytes) { |
| 105 return make_scoped_ptr<RasterWorkerPool>( | 105 return make_scoped_ptr<TileTaskWorkerPool>(new PixelBufferTileTaskWorkerPool( |
| 106 new PixelBufferRasterWorkerPool(task_runner, | 106 task_runner, task_graph_runner, context_provider, resource_provider, |
| 107 task_graph_runner, | 107 max_transfer_buffer_usage_bytes)); |
| 108 context_provider, | |
| 109 resource_provider, | |
| 110 max_transfer_buffer_usage_bytes)); | |
| 111 } | 108 } |
| 112 | 109 |
| 113 PixelBufferRasterWorkerPool::PixelBufferRasterWorkerPool( | 110 PixelBufferTileTaskWorkerPool::PixelBufferTileTaskWorkerPool( |
| 114 base::SequencedTaskRunner* task_runner, | 111 base::SequencedTaskRunner* task_runner, |
| 115 TaskGraphRunner* task_graph_runner, | 112 TaskGraphRunner* task_graph_runner, |
| 116 ContextProvider* context_provider, | 113 ContextProvider* context_provider, |
| 117 ResourceProvider* resource_provider, | 114 ResourceProvider* resource_provider, |
| 118 size_t max_transfer_buffer_usage_bytes) | 115 size_t max_transfer_buffer_usage_bytes) |
| 119 : task_runner_(task_runner), | 116 : task_runner_(task_runner), |
| 120 task_graph_runner_(task_graph_runner), | 117 task_graph_runner_(task_graph_runner), |
| 121 namespace_token_(task_graph_runner->GetNamespaceToken()), | 118 namespace_token_(task_graph_runner->GetNamespaceToken()), |
| 122 context_provider_(context_provider), | 119 context_provider_(context_provider), |
| 123 resource_provider_(resource_provider), | 120 resource_provider_(resource_provider), |
| 124 shutdown_(false), | 121 shutdown_(false), |
| 125 scheduled_raster_task_count_(0u), | 122 scheduled_raster_task_count_(0u), |
| 126 bytes_pending_upload_(0u), | 123 bytes_pending_upload_(0u), |
| 127 max_bytes_pending_upload_(max_transfer_buffer_usage_bytes), | 124 max_bytes_pending_upload_(max_transfer_buffer_usage_bytes), |
| 128 has_performed_uploads_since_last_flush_(false), | 125 has_performed_uploads_since_last_flush_(false), |
| 129 check_for_completed_raster_task_notifier_( | 126 check_for_completed_raster_task_notifier_( |
| 130 task_runner, | 127 task_runner, |
| 131 base::Bind(&PixelBufferRasterWorkerPool::CheckForCompletedRasterTasks, | 128 base::Bind( |
| 132 base::Unretained(this)), | 129 &PixelBufferTileTaskWorkerPool::CheckForCompletedRasterTasks, |
| 130 base::Unretained(this)), |
| 133 base::TimeDelta::FromMilliseconds( | 131 base::TimeDelta::FromMilliseconds( |
| 134 kCheckForCompletedRasterTasksDelayMs)), | 132 kCheckForCompletedRasterTasksDelayMs)), |
| 135 raster_finished_weak_ptr_factory_(this) { | 133 task_set_finished_weak_ptr_factory_(this) { |
| 136 DCHECK(context_provider_); | 134 DCHECK(context_provider_); |
| 137 std::fill(task_counts_, task_counts_ + kNumberOfTaskSets, 0); | 135 std::fill(task_counts_, task_counts_ + kNumberOfTaskSets, 0); |
| 138 } | 136 } |
| 139 | 137 |
| 140 PixelBufferRasterWorkerPool::~PixelBufferRasterWorkerPool() { | 138 PixelBufferTileTaskWorkerPool::~PixelBufferTileTaskWorkerPool() { |
| 141 DCHECK_EQ(0u, raster_task_states_.size()); | 139 DCHECK_EQ(0u, raster_task_states_.size()); |
| 142 DCHECK_EQ(0u, raster_tasks_with_pending_upload_.size()); | 140 DCHECK_EQ(0u, raster_tasks_with_pending_upload_.size()); |
| 143 DCHECK_EQ(0u, completed_raster_tasks_.size()); | 141 DCHECK_EQ(0u, completed_raster_tasks_.size()); |
| 144 DCHECK_EQ(0u, completed_image_decode_tasks_.size()); | 142 DCHECK_EQ(0u, completed_image_decode_tasks_.size()); |
| 145 DCHECK(NonEmptyTaskSetsFromTaskCounts(task_counts_).none()); | 143 DCHECK(NonEmptyTaskSetsFromTaskCounts(task_counts_).none()); |
| 146 } | 144 } |
| 147 | 145 |
| 148 Rasterizer* PixelBufferRasterWorkerPool::AsRasterizer() { return this; } | 146 TileTaskRunner* PixelBufferTileTaskWorkerPool::AsTileTaskRunner() { |
| 147 return this; |
| 148 } |
| 149 | 149 |
| 150 void PixelBufferRasterWorkerPool::SetClient(RasterizerClient* client) { | 150 void PixelBufferTileTaskWorkerPool::SetClient(TileTaskRunnerClient* client) { |
| 151 client_ = client; | 151 client_ = client; |
| 152 } | 152 } |
| 153 | 153 |
| 154 void PixelBufferRasterWorkerPool::Shutdown() { | 154 void PixelBufferTileTaskWorkerPool::Shutdown() { |
| 155 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::Shutdown"); | 155 TRACE_EVENT0("cc", "PixelBufferTileTaskWorkerPool::Shutdown"); |
| 156 | 156 |
| 157 shutdown_ = true; | 157 shutdown_ = true; |
| 158 | 158 |
| 159 TaskGraph empty; | 159 TaskGraph empty; |
| 160 task_graph_runner_->ScheduleTasks(namespace_token_, &empty); | 160 task_graph_runner_->ScheduleTasks(namespace_token_, &empty); |
| 161 task_graph_runner_->WaitForTasksToFinishRunning(namespace_token_); | 161 task_graph_runner_->WaitForTasksToFinishRunning(namespace_token_); |
| 162 | 162 |
| 163 CheckForCompletedRasterizerTasks(); | 163 CheckForCompletedRasterizerTasks(); |
| 164 CheckForCompletedUploads(); | 164 CheckForCompletedUploads(); |
| 165 | 165 |
| 166 check_for_completed_raster_task_notifier_.Shutdown(); | 166 check_for_completed_raster_task_notifier_.Shutdown(); |
| 167 | 167 |
| 168 for (RasterTaskState::Vector::iterator it = raster_task_states_.begin(); | 168 for (RasterTaskState::Vector::iterator it = raster_task_states_.begin(); |
| 169 it != raster_task_states_.end(); | 169 it != raster_task_states_.end(); ++it) { |
| 170 ++it) { | |
| 171 RasterTaskState& state = *it; | 170 RasterTaskState& state = *it; |
| 172 | 171 |
| 173 // All unscheduled tasks need to be canceled. | 172 // All unscheduled tasks need to be canceled. |
| 174 if (state.type == RasterTaskState::UNSCHEDULED) { | 173 if (state.type == RasterTaskState::UNSCHEDULED) { |
| 175 completed_raster_tasks_.push_back(state.task); | 174 completed_raster_tasks_.push_back(state.task); |
| 176 state.type = RasterTaskState::COMPLETED; | 175 state.type = RasterTaskState::COMPLETED; |
| 177 } | 176 } |
| 178 } | 177 } |
| 179 DCHECK_EQ(completed_raster_tasks_.size(), raster_task_states_.size()); | 178 DCHECK_EQ(completed_raster_tasks_.size(), raster_task_states_.size()); |
| 180 } | 179 } |
| 181 | 180 |
| 182 void PixelBufferRasterWorkerPool::ScheduleTasks(RasterTaskQueue* queue) { | 181 void PixelBufferTileTaskWorkerPool::ScheduleTasks(TileTaskQueue* queue) { |
| 183 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::ScheduleTasks"); | 182 TRACE_EVENT0("cc", "PixelBufferTileTaskWorkerPool::ScheduleTasks"); |
| 184 | 183 |
| 185 if (should_notify_client_if_no_tasks_are_pending_.none()) | 184 if (should_notify_client_if_no_tasks_are_pending_.none()) |
| 186 TRACE_EVENT_ASYNC_BEGIN0("cc", "ScheduledTasks", this); | 185 TRACE_EVENT_ASYNC_BEGIN0("cc", "ScheduledTasks", this); |
| 187 | 186 |
| 188 should_notify_client_if_no_tasks_are_pending_.set(); | 187 should_notify_client_if_no_tasks_are_pending_.set(); |
| 189 std::fill(task_counts_, task_counts_ + kNumberOfTaskSets, 0); | 188 std::fill(task_counts_, task_counts_ + kNumberOfTaskSets, 0); |
| 190 | 189 |
| 191 // Update raster task state and remove items from old queue. | 190 // Update raster task state and remove items from old queue. |
| 192 for (RasterTaskQueue::Item::Vector::const_iterator it = queue->items.begin(); | 191 for (TileTaskQueue::Item::Vector::const_iterator it = queue->items.begin(); |
| 193 it != queue->items.end(); | 192 it != queue->items.end(); ++it) { |
| 194 ++it) { | 193 const TileTaskQueue::Item& item = *it; |
| 195 const RasterTaskQueue::Item& item = *it; | |
| 196 RasterTask* task = item.task; | 194 RasterTask* task = item.task; |
| 197 | 195 |
| 198 // Remove any old items that are associated with this task. The result is | 196 // Remove any old items that are associated with this task. The result is |
| 199 // that the old queue is left with all items not present in this queue, | 197 // that the old queue is left with all items not present in this queue, |
| 200 // which we use below to determine what tasks need to be canceled. | 198 // which we use below to determine what tasks need to be canceled. |
| 201 RasterTaskQueue::Item::Vector::iterator old_it = | 199 TileTaskQueue::Item::Vector::iterator old_it = |
| 202 std::find_if(raster_tasks_.items.begin(), | 200 std::find_if(raster_tasks_.items.begin(), raster_tasks_.items.end(), |
| 203 raster_tasks_.items.end(), | 201 TileTaskQueue::Item::TaskComparator(task)); |
| 204 RasterTaskQueue::Item::TaskComparator(task)); | |
| 205 if (old_it != raster_tasks_.items.end()) { | 202 if (old_it != raster_tasks_.items.end()) { |
| 206 std::swap(*old_it, raster_tasks_.items.back()); | 203 std::swap(*old_it, raster_tasks_.items.back()); |
| 207 raster_tasks_.items.pop_back(); | 204 raster_tasks_.items.pop_back(); |
| 208 } | 205 } |
| 209 | 206 |
| 210 RasterTaskState::Vector::iterator state_it = | 207 RasterTaskState::Vector::iterator state_it = |
| 211 std::find_if(raster_task_states_.begin(), | 208 std::find_if(raster_task_states_.begin(), raster_task_states_.end(), |
| 212 raster_task_states_.end(), | |
| 213 RasterTaskState::TaskComparator(task)); | 209 RasterTaskState::TaskComparator(task)); |
| 214 if (state_it != raster_task_states_.end()) { | 210 if (state_it != raster_task_states_.end()) { |
| 215 RasterTaskState& state = *state_it; | 211 RasterTaskState& state = *state_it; |
| 216 | 212 |
| 217 state.task_sets = item.task_sets; | 213 state.task_sets = item.task_sets; |
| 218 // |raster_tasks_required_for_activation_count| accounts for all tasks | 214 // |raster_tasks_required_for_activation_count| accounts for all tasks |
| 219 // that need to complete before we can send a "ready to activate" signal. | 215 // that need to complete before we can send a "ready to activate" signal. |
| 220 // Tasks that have already completed should not be part of this count. | 216 // Tasks that have already completed should not be part of this count. |
| 221 if (state.type != RasterTaskState::COMPLETED) | 217 if (state.type != RasterTaskState::COMPLETED) |
| 222 AddTaskSetsToTaskCounts(task_counts_, item.task_sets); | 218 AddTaskSetsToTaskCounts(task_counts_, item.task_sets); |
| 223 | 219 |
| 224 continue; | 220 continue; |
| 225 } | 221 } |
| 226 | 222 |
| 227 DCHECK(!task->HasBeenScheduled()); | 223 DCHECK(!task->HasBeenScheduled()); |
| 228 raster_task_states_.push_back(RasterTaskState(task, item.task_sets)); | 224 raster_task_states_.push_back(RasterTaskState(task, item.task_sets)); |
| 229 AddTaskSetsToTaskCounts(task_counts_, item.task_sets); | 225 AddTaskSetsToTaskCounts(task_counts_, item.task_sets); |
| 230 } | 226 } |
| 231 | 227 |
| 232 // Determine what tasks in old queue need to be canceled. | 228 // Determine what tasks in old queue need to be canceled. |
| 233 for (RasterTaskQueue::Item::Vector::const_iterator it = | 229 for (TileTaskQueue::Item::Vector::const_iterator it = |
| 234 raster_tasks_.items.begin(); | 230 raster_tasks_.items.begin(); |
| 235 it != raster_tasks_.items.end(); | 231 it != raster_tasks_.items.end(); ++it) { |
| 236 ++it) { | 232 const TileTaskQueue::Item& item = *it; |
| 237 const RasterTaskQueue::Item& item = *it; | |
| 238 RasterTask* task = item.task; | 233 RasterTask* task = item.task; |
| 239 | 234 |
| 240 RasterTaskState::Vector::iterator state_it = | 235 RasterTaskState::Vector::iterator state_it = |
| 241 std::find_if(raster_task_states_.begin(), | 236 std::find_if(raster_task_states_.begin(), raster_task_states_.end(), |
| 242 raster_task_states_.end(), | |
| 243 RasterTaskState::TaskComparator(task)); | 237 RasterTaskState::TaskComparator(task)); |
| 244 // We've already processed completion if we can't find a RasterTaskState for | 238 // We've already processed completion if we can't find a RasterTaskState for |
| 245 // this task. | 239 // this task. |
| 246 if (state_it == raster_task_states_.end()) | 240 if (state_it == raster_task_states_.end()) |
| 247 continue; | 241 continue; |
| 248 | 242 |
| 249 RasterTaskState& state = *state_it; | 243 RasterTaskState& state = *state_it; |
| 250 | 244 |
| 251 // Unscheduled task can be canceled. | 245 // Unscheduled task can be canceled. |
| 252 if (state.type == RasterTaskState::UNSCHEDULED) { | 246 if (state.type == RasterTaskState::UNSCHEDULED) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 270 CheckForCompletedRasterizerTasks(); | 264 CheckForCompletedRasterizerTasks(); |
| 271 CheckForCompletedUploads(); | 265 CheckForCompletedUploads(); |
| 272 FlushUploads(); | 266 FlushUploads(); |
| 273 | 267 |
| 274 // Schedule new tasks. | 268 // Schedule new tasks. |
| 275 ScheduleMoreTasks(); | 269 ScheduleMoreTasks(); |
| 276 | 270 |
| 277 // Reschedule check for completed raster tasks. | 271 // Reschedule check for completed raster tasks. |
| 278 check_for_completed_raster_task_notifier_.Schedule(); | 272 check_for_completed_raster_task_notifier_.Schedule(); |
| 279 | 273 |
| 280 TRACE_EVENT_ASYNC_STEP_INTO1( | 274 TRACE_EVENT_ASYNC_STEP_INTO1("cc", "ScheduledTasks", this, StateName(), |
| 281 "cc", "ScheduledTasks", this, StateName(), "state", StateAsValue()); | 275 "state", StateAsValue()); |
| 282 } | 276 } |
| 283 | 277 |
| 284 void PixelBufferRasterWorkerPool::CheckForCompletedTasks() { | 278 void PixelBufferTileTaskWorkerPool::CheckForCompletedTasks() { |
| 285 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::CheckForCompletedTasks"); | 279 TRACE_EVENT0("cc", "PixelBufferTileTaskWorkerPool::CheckForCompletedTasks"); |
| 286 | 280 |
| 287 CheckForCompletedRasterizerTasks(); | 281 CheckForCompletedRasterizerTasks(); |
| 288 CheckForCompletedUploads(); | 282 CheckForCompletedUploads(); |
| 289 FlushUploads(); | 283 FlushUploads(); |
| 290 | 284 |
| 291 for (RasterizerTask::Vector::const_iterator it = | 285 for (TileTask::Vector::const_iterator it = |
| 292 completed_image_decode_tasks_.begin(); | 286 completed_image_decode_tasks_.begin(); |
| 293 it != completed_image_decode_tasks_.end(); | 287 it != completed_image_decode_tasks_.end(); ++it) { |
| 294 ++it) { | 288 TileTask* task = it->get(); |
| 295 RasterizerTask* task = it->get(); | |
| 296 task->RunReplyOnOriginThread(); | 289 task->RunReplyOnOriginThread(); |
| 297 } | 290 } |
| 298 completed_image_decode_tasks_.clear(); | 291 completed_image_decode_tasks_.clear(); |
| 299 | 292 |
| 300 for (RasterTask::Vector::const_iterator it = completed_raster_tasks_.begin(); | 293 for (RasterTask::Vector::const_iterator it = completed_raster_tasks_.begin(); |
| 301 it != completed_raster_tasks_.end(); | 294 it != completed_raster_tasks_.end(); ++it) { |
| 302 ++it) { | |
| 303 RasterTask* task = it->get(); | 295 RasterTask* task = it->get(); |
| 304 RasterTaskState::Vector::iterator state_it = | 296 RasterTaskState::Vector::iterator state_it = |
| 305 std::find_if(raster_task_states_.begin(), | 297 std::find_if(raster_task_states_.begin(), raster_task_states_.end(), |
| 306 raster_task_states_.end(), | |
| 307 RasterTaskState::TaskComparator(task)); | 298 RasterTaskState::TaskComparator(task)); |
| 308 DCHECK(state_it != raster_task_states_.end()); | 299 DCHECK(state_it != raster_task_states_.end()); |
| 309 DCHECK_EQ(RasterTaskState::COMPLETED, state_it->type); | 300 DCHECK_EQ(RasterTaskState::COMPLETED, state_it->type); |
| 310 | 301 |
| 311 std::swap(*state_it, raster_task_states_.back()); | 302 std::swap(*state_it, raster_task_states_.back()); |
| 312 raster_task_states_.pop_back(); | 303 raster_task_states_.pop_back(); |
| 313 | 304 |
| 314 task->RunReplyOnOriginThread(); | 305 task->RunReplyOnOriginThread(); |
| 315 } | 306 } |
| 316 completed_raster_tasks_.clear(); | 307 completed_raster_tasks_.clear(); |
| 317 } | 308 } |
| 318 | 309 |
| 319 scoped_ptr<RasterBuffer> PixelBufferRasterWorkerPool::AcquireBufferForRaster( | 310 scoped_ptr<RasterBuffer> PixelBufferTileTaskWorkerPool::AcquireBufferForRaster( |
| 320 const Resource* resource) { | 311 const Resource* resource) { |
| 321 return make_scoped_ptr<RasterBuffer>( | 312 return make_scoped_ptr<RasterBuffer>( |
| 322 new RasterBufferImpl(resource_provider_, resource)); | 313 new RasterBufferImpl(resource_provider_, resource)); |
| 323 } | 314 } |
| 324 | 315 |
| 325 void PixelBufferRasterWorkerPool::ReleaseBufferForRaster( | 316 void PixelBufferTileTaskWorkerPool::ReleaseBufferForRaster( |
| 326 scoped_ptr<RasterBuffer> buffer) { | 317 scoped_ptr<RasterBuffer> buffer) { |
| 327 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. | 318 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. |
| 328 } | 319 } |
| 329 | 320 |
| 330 void PixelBufferRasterWorkerPool::OnRasterFinished(TaskSet task_set) { | 321 void PixelBufferTileTaskWorkerPool::OnTaskSetFinished(TaskSet task_set) { |
| 331 TRACE_EVENT2("cc", | 322 TRACE_EVENT2("cc", "PixelBufferTileTaskWorkerPool::OnTaskSetFinished", |
| 332 "PixelBufferRasterWorkerPool::OnRasterFinished", | 323 "task_set", task_set, |
| 333 "task_set", | |
| 334 task_set, | |
| 335 "should_notify_client_if_no_tasks_are_pending", | 324 "should_notify_client_if_no_tasks_are_pending", |
| 336 should_notify_client_if_no_tasks_are_pending_[task_set]); | 325 should_notify_client_if_no_tasks_are_pending_[task_set]); |
| 337 | 326 |
| 338 // There's no need to call CheckForCompletedRasterTasks() if the client has | 327 // There's no need to call CheckForCompletedRasterTasks() if the client has |
| 339 // already been notified. | 328 // already been notified. |
| 340 if (!should_notify_client_if_no_tasks_are_pending_[task_set]) | 329 if (!should_notify_client_if_no_tasks_are_pending_[task_set]) |
| 341 return; | 330 return; |
| 342 raster_finished_tasks_pending_[task_set] = false; | 331 task_set_finished_tasks_pending_[task_set] = false; |
| 343 | 332 |
| 344 // This reduces latency between the time when all tasks required for | 333 // This reduces latency between the time when all tasks required for |
| 345 // activation have finished running and the time when the client is | 334 // activation have finished running and the time when the client is |
| 346 // notified. | 335 // notified. |
| 347 CheckForCompletedRasterTasks(); | 336 CheckForCompletedRasterTasks(); |
| 348 } | 337 } |
| 349 | 338 |
| 350 void PixelBufferRasterWorkerPool::FlushUploads() { | 339 void PixelBufferTileTaskWorkerPool::FlushUploads() { |
| 351 if (!has_performed_uploads_since_last_flush_) | 340 if (!has_performed_uploads_since_last_flush_) |
| 352 return; | 341 return; |
| 353 | 342 |
| 354 context_provider_->ContextGL()->ShallowFlushCHROMIUM(); | 343 context_provider_->ContextGL()->ShallowFlushCHROMIUM(); |
| 355 has_performed_uploads_since_last_flush_ = false; | 344 has_performed_uploads_since_last_flush_ = false; |
| 356 } | 345 } |
| 357 | 346 |
| 358 void PixelBufferRasterWorkerPool::CheckForCompletedUploads() { | 347 void PixelBufferTileTaskWorkerPool::CheckForCompletedUploads() { |
| 359 RasterTask::Vector tasks_with_completed_uploads; | 348 RasterTask::Vector tasks_with_completed_uploads; |
| 360 | 349 |
| 361 // First check if any have completed. | 350 // First check if any have completed. |
| 362 while (!raster_tasks_with_pending_upload_.empty()) { | 351 while (!raster_tasks_with_pending_upload_.empty()) { |
| 363 RasterTask* task = raster_tasks_with_pending_upload_.front().get(); | 352 RasterTask* task = raster_tasks_with_pending_upload_.front().get(); |
| 364 DCHECK(std::find_if(raster_task_states_.begin(), | 353 DCHECK(std::find_if(raster_task_states_.begin(), raster_task_states_.end(), |
| 365 raster_task_states_.end(), | |
| 366 RasterTaskState::TaskComparator(task)) != | 354 RasterTaskState::TaskComparator(task)) != |
| 367 raster_task_states_.end()); | 355 raster_task_states_.end()); |
| 368 DCHECK_EQ(RasterTaskState::UPLOADING, | 356 DCHECK_EQ( |
| 369 std::find_if(raster_task_states_.begin(), | 357 RasterTaskState::UPLOADING, |
| 370 raster_task_states_.end(), | 358 std::find_if(raster_task_states_.begin(), raster_task_states_.end(), |
| 371 RasterTaskState::TaskComparator(task))->type); | 359 RasterTaskState::TaskComparator(task))->type); |
| 372 | 360 |
| 373 // Uploads complete in the order they are issued. | 361 // Uploads complete in the order they are issued. |
| 374 if (!resource_provider_->DidSetPixelsComplete(task->resource()->id())) | 362 if (!resource_provider_->DidSetPixelsComplete(task->resource()->id())) |
| 375 break; | 363 break; |
| 376 | 364 |
| 377 tasks_with_completed_uploads.push_back(task); | 365 tasks_with_completed_uploads.push_back(task); |
| 378 raster_tasks_with_pending_upload_.pop_front(); | 366 raster_tasks_with_pending_upload_.pop_front(); |
| 379 } | 367 } |
| 380 | 368 |
| 381 DCHECK(client_); | 369 DCHECK(client_); |
| 382 TaskSetCollection tasks_that_should_be_forced_to_complete = | 370 TaskSetCollection tasks_that_should_be_forced_to_complete = |
| 383 client_->TasksThatShouldBeForcedToComplete(); | 371 client_->TasksThatShouldBeForcedToComplete(); |
| 384 bool should_force_some_uploads_to_complete = | 372 bool should_force_some_uploads_to_complete = |
| 385 shutdown_ || tasks_that_should_be_forced_to_complete.any(); | 373 shutdown_ || tasks_that_should_be_forced_to_complete.any(); |
| 386 | 374 |
| 387 if (should_force_some_uploads_to_complete) { | 375 if (should_force_some_uploads_to_complete) { |
| 388 RasterTask::Vector tasks_with_uploads_to_force; | 376 RasterTask::Vector tasks_with_uploads_to_force; |
| 389 RasterTaskDeque::iterator it = raster_tasks_with_pending_upload_.begin(); | 377 RasterTaskDeque::iterator it = raster_tasks_with_pending_upload_.begin(); |
| 390 while (it != raster_tasks_with_pending_upload_.end()) { | 378 while (it != raster_tasks_with_pending_upload_.end()) { |
| 391 RasterTask* task = it->get(); | 379 RasterTask* task = it->get(); |
| 392 RasterTaskState::Vector::const_iterator state_it = | 380 RasterTaskState::Vector::const_iterator state_it = |
| 393 std::find_if(raster_task_states_.begin(), | 381 std::find_if(raster_task_states_.begin(), raster_task_states_.end(), |
| 394 raster_task_states_.end(), | |
| 395 RasterTaskState::TaskComparator(task)); | 382 RasterTaskState::TaskComparator(task)); |
| 396 DCHECK(state_it != raster_task_states_.end()); | 383 DCHECK(state_it != raster_task_states_.end()); |
| 397 const RasterTaskState& state = *state_it; | 384 const RasterTaskState& state = *state_it; |
| 398 | 385 |
| 399 // Force all uploads to complete for which the client requests to do so. | 386 // Force all uploads to complete for which the client requests to do so. |
| 400 // During shutdown, force all pending uploads to complete. | 387 // During shutdown, force all pending uploads to complete. |
| 401 if (shutdown_ || | 388 if (shutdown_ || |
| 402 (state.task_sets & tasks_that_should_be_forced_to_complete).any()) { | 389 (state.task_sets & tasks_that_should_be_forced_to_complete).any()) { |
| 403 tasks_with_uploads_to_force.push_back(task); | 390 tasks_with_uploads_to_force.push_back(task); |
| 404 tasks_with_completed_uploads.push_back(task); | 391 tasks_with_completed_uploads.push_back(task); |
| 405 it = raster_tasks_with_pending_upload_.erase(it); | 392 it = raster_tasks_with_pending_upload_.erase(it); |
| 406 continue; | 393 continue; |
| 407 } | 394 } |
| 408 | 395 |
| 409 ++it; | 396 ++it; |
| 410 } | 397 } |
| 411 | 398 |
| 412 // Force uploads in reverse order. Since forcing can cause a wait on | 399 // Force uploads in reverse order. Since forcing can cause a wait on |
| 413 // all previous uploads, we would rather wait only once downstream. | 400 // all previous uploads, we would rather wait only once downstream. |
| 414 for (RasterTask::Vector::reverse_iterator it = | 401 for (RasterTask::Vector::reverse_iterator it = |
| 415 tasks_with_uploads_to_force.rbegin(); | 402 tasks_with_uploads_to_force.rbegin(); |
| 416 it != tasks_with_uploads_to_force.rend(); | 403 it != tasks_with_uploads_to_force.rend(); ++it) { |
| 417 ++it) { | |
| 418 RasterTask* task = it->get(); | 404 RasterTask* task = it->get(); |
| 419 | 405 |
| 420 resource_provider_->ForceSetPixelsToComplete(task->resource()->id()); | 406 resource_provider_->ForceSetPixelsToComplete(task->resource()->id()); |
| 421 has_performed_uploads_since_last_flush_ = true; | 407 has_performed_uploads_since_last_flush_ = true; |
| 422 } | 408 } |
| 423 } | 409 } |
| 424 | 410 |
| 425 // Release shared memory and move tasks with completed uploads | 411 // Release shared memory and move tasks with completed uploads |
| 426 // to |completed_raster_tasks_|. | 412 // to |completed_raster_tasks_|. |
| 427 for (RasterTask::Vector::const_iterator it = | 413 for (RasterTask::Vector::const_iterator it = |
| 428 tasks_with_completed_uploads.begin(); | 414 tasks_with_completed_uploads.begin(); |
| 429 it != tasks_with_completed_uploads.end(); | 415 it != tasks_with_completed_uploads.end(); ++it) { |
| 430 ++it) { | |
| 431 RasterTask* task = it->get(); | 416 RasterTask* task = it->get(); |
| 432 RasterTaskState::Vector::iterator state_it = | 417 RasterTaskState::Vector::iterator state_it = |
| 433 std::find_if(raster_task_states_.begin(), | 418 std::find_if(raster_task_states_.begin(), raster_task_states_.end(), |
| 434 raster_task_states_.end(), | |
| 435 RasterTaskState::TaskComparator(task)); | 419 RasterTaskState::TaskComparator(task)); |
| 436 DCHECK(state_it != raster_task_states_.end()); | 420 DCHECK(state_it != raster_task_states_.end()); |
| 437 RasterTaskState& state = *state_it; | 421 RasterTaskState& state = *state_it; |
| 438 | 422 |
| 439 bytes_pending_upload_ -= task->resource()->bytes(); | 423 bytes_pending_upload_ -= task->resource()->bytes(); |
| 440 | 424 |
| 441 task->WillComplete(); | 425 task->WillComplete(); |
| 442 task->CompleteOnOriginThread(this); | 426 task->CompleteOnOriginThread(this); |
| 443 task->DidComplete(); | 427 task->DidComplete(); |
| 444 | 428 |
| 445 DCHECK(std::find(completed_raster_tasks_.begin(), | 429 DCHECK(std::find(completed_raster_tasks_.begin(), |
| 446 completed_raster_tasks_.end(), | 430 completed_raster_tasks_.end(), |
| 447 task) == completed_raster_tasks_.end()); | 431 task) == completed_raster_tasks_.end()); |
| 448 completed_raster_tasks_.push_back(task); | 432 completed_raster_tasks_.push_back(task); |
| 449 state.type = RasterTaskState::COMPLETED; | 433 state.type = RasterTaskState::COMPLETED; |
| 450 // Triggers if the current task belongs to a set that should be empty. | 434 // Triggers if the current task belongs to a set that should be empty. |
| 451 DCHECK((state.task_sets & ~NonEmptyTaskSetsFromTaskCounts(task_counts_)) | 435 DCHECK((state.task_sets & ~NonEmptyTaskSetsFromTaskCounts(task_counts_)) |
| 452 .none()); | 436 .none()); |
| 453 RemoveTaskSetsFromTaskCounts(task_counts_, state.task_sets); | 437 RemoveTaskSetsFromTaskCounts(task_counts_, state.task_sets); |
| 454 } | 438 } |
| 455 } | 439 } |
| 456 | 440 |
| 457 void PixelBufferRasterWorkerPool::CheckForCompletedRasterTasks() { | 441 void PixelBufferTileTaskWorkerPool::CheckForCompletedRasterTasks() { |
| 458 TRACE_EVENT0("cc", | 442 TRACE_EVENT0("cc", |
| 459 "PixelBufferRasterWorkerPool::CheckForCompletedRasterTasks"); | 443 "PixelBufferTileTaskWorkerPool::CheckForCompletedRasterTasks"); |
| 460 | 444 |
| 461 // Since this function can be called directly, cancel any pending checks. | 445 // Since this function can be called directly, cancel any pending checks. |
| 462 check_for_completed_raster_task_notifier_.Cancel(); | 446 check_for_completed_raster_task_notifier_.Cancel(); |
| 463 | 447 |
| 464 DCHECK(should_notify_client_if_no_tasks_are_pending_.any()); | 448 DCHECK(should_notify_client_if_no_tasks_are_pending_.any()); |
| 465 | 449 |
| 466 CheckForCompletedRasterizerTasks(); | 450 CheckForCompletedRasterizerTasks(); |
| 467 CheckForCompletedUploads(); | 451 CheckForCompletedUploads(); |
| 468 FlushUploads(); | 452 FlushUploads(); |
| 469 | 453 |
| 470 // Determine what client notifications to generate. | 454 // Determine what client notifications to generate. |
| 471 TaskSetCollection will_notify_client_that_no_tasks_are_pending = | 455 TaskSetCollection will_notify_client_that_no_tasks_are_pending = |
| 472 should_notify_client_if_no_tasks_are_pending_ & | 456 should_notify_client_if_no_tasks_are_pending_ & |
| 473 ~raster_finished_tasks_pending_ & ~PendingTasks(); | 457 ~task_set_finished_tasks_pending_ & ~PendingTasks(); |
| 474 | 458 |
| 475 // Adjust the need to generate notifications before scheduling more tasks. | 459 // Adjust the need to generate notifications before scheduling more tasks. |
| 476 should_notify_client_if_no_tasks_are_pending_ &= | 460 should_notify_client_if_no_tasks_are_pending_ &= |
| 477 ~will_notify_client_that_no_tasks_are_pending; | 461 ~will_notify_client_that_no_tasks_are_pending; |
| 478 | 462 |
| 479 scheduled_raster_task_count_ = 0; | 463 scheduled_raster_task_count_ = 0; |
| 480 if (PendingRasterTaskCount()) | 464 if (PendingRasterTaskCount()) |
| 481 ScheduleMoreTasks(); | 465 ScheduleMoreTasks(); |
| 482 | 466 |
| 483 TRACE_EVENT_ASYNC_STEP_INTO1( | 467 TRACE_EVENT_ASYNC_STEP_INTO1("cc", "ScheduledTasks", this, StateName(), |
| 484 "cc", "ScheduledTasks", this, StateName(), "state", StateAsValue()); | 468 "state", StateAsValue()); |
| 485 | 469 |
| 486 // Schedule another check for completed raster tasks while there are | 470 // Schedule another check for completed raster tasks while there are |
| 487 // pending raster tasks or pending uploads. | 471 // pending raster tasks or pending uploads. |
| 488 if (PendingTasks().any()) | 472 if (PendingTasks().any()) |
| 489 check_for_completed_raster_task_notifier_.Schedule(); | 473 check_for_completed_raster_task_notifier_.Schedule(); |
| 490 | 474 |
| 491 if (should_notify_client_if_no_tasks_are_pending_.none()) | 475 if (should_notify_client_if_no_tasks_are_pending_.none()) |
| 492 TRACE_EVENT_ASYNC_END0("cc", "ScheduledTasks", this); | 476 TRACE_EVENT_ASYNC_END0("cc", "ScheduledTasks", this); |
| 493 | 477 |
| 494 // Generate client notifications. | 478 // Generate client notifications. |
| 495 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) { | 479 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) { |
| 496 if (will_notify_client_that_no_tasks_are_pending[task_set]) { | 480 if (will_notify_client_that_no_tasks_are_pending[task_set]) { |
| 497 DCHECK(!PendingTasks()[task_set]); | 481 DCHECK(!PendingTasks()[task_set]); |
| 498 client_->DidFinishRunningTasks(task_set); | 482 client_->DidFinishRunningTileTasks(task_set); |
| 499 } | 483 } |
| 500 } | 484 } |
| 501 } | 485 } |
| 502 | 486 |
| 503 void PixelBufferRasterWorkerPool::ScheduleMoreTasks() { | 487 void PixelBufferTileTaskWorkerPool::ScheduleMoreTasks() { |
| 504 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::ScheduleMoreTasks"); | 488 TRACE_EVENT0("cc", "PixelBufferTileTaskWorkerPool::ScheduleMoreTasks"); |
| 505 | 489 |
| 506 RasterTaskVector tasks[kNumberOfTaskSets]; | 490 RasterTaskVector tasks[kNumberOfTaskSets]; |
| 507 | 491 |
| 508 unsigned priority = kRasterTaskPriorityBase; | 492 unsigned priority = kTileTaskPriorityBase; |
| 509 | 493 |
| 510 graph_.Reset(); | 494 graph_.Reset(); |
| 511 | 495 |
| 512 size_t bytes_pending_upload = bytes_pending_upload_; | 496 size_t bytes_pending_upload = bytes_pending_upload_; |
| 513 TaskSetCollection did_throttle_raster_tasks; | 497 TaskSetCollection did_throttle_raster_tasks; |
| 514 size_t scheduled_raster_task_count = 0; | 498 size_t scheduled_raster_task_count = 0; |
| 515 | 499 |
| 516 for (RasterTaskQueue::Item::Vector::const_iterator it = | 500 for (TileTaskQueue::Item::Vector::const_iterator it = |
| 517 raster_tasks_.items.begin(); | 501 raster_tasks_.items.begin(); |
| 518 it != raster_tasks_.items.end(); | 502 it != raster_tasks_.items.end(); ++it) { |
| 519 ++it) { | 503 const TileTaskQueue::Item& item = *it; |
| 520 const RasterTaskQueue::Item& item = *it; | |
| 521 RasterTask* task = item.task; | 504 RasterTask* task = item.task; |
| 522 DCHECK(item.task_sets.any()); | 505 DCHECK(item.task_sets.any()); |
| 523 | 506 |
| 524 // |raster_task_states_| contains the state of all tasks that we have not | 507 // |raster_task_states_| contains the state of all tasks that we have not |
| 525 // yet run reply callbacks for. | 508 // yet run reply callbacks for. |
| 526 RasterTaskState::Vector::iterator state_it = | 509 RasterTaskState::Vector::iterator state_it = |
| 527 std::find_if(raster_task_states_.begin(), | 510 std::find_if(raster_task_states_.begin(), raster_task_states_.end(), |
| 528 raster_task_states_.end(), | |
| 529 RasterTaskState::TaskComparator(task)); | 511 RasterTaskState::TaskComparator(task)); |
| 530 if (state_it == raster_task_states_.end()) | 512 if (state_it == raster_task_states_.end()) |
| 531 continue; | 513 continue; |
| 532 | 514 |
| 533 RasterTaskState& state = *state_it; | 515 RasterTaskState& state = *state_it; |
| 534 | 516 |
| 535 // Skip task if completed. | 517 // Skip task if completed. |
| 536 if (state.type == RasterTaskState::COMPLETED) { | 518 if (state.type == RasterTaskState::COMPLETED) { |
| 537 DCHECK(std::find(completed_raster_tasks_.begin(), | 519 DCHECK(std::find(completed_raster_tasks_.begin(), |
| 538 completed_raster_tasks_.end(), | 520 completed_raster_tasks_.end(), |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 | 556 |
| 575 InsertNodesForRasterTask(&graph_, task, task->dependencies(), priority++); | 557 InsertNodesForRasterTask(&graph_, task, task->dependencies(), priority++); |
| 576 | 558 |
| 577 ++scheduled_raster_task_count; | 559 ++scheduled_raster_task_count; |
| 578 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) { | 560 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) { |
| 579 if (item.task_sets[task_set]) | 561 if (item.task_sets[task_set]) |
| 580 tasks[task_set].container().push_back(task); | 562 tasks[task_set].container().push_back(task); |
| 581 } | 563 } |
| 582 } | 564 } |
| 583 | 565 |
| 584 // Cancel existing OnRasterFinished callbacks. | 566 // Cancel existing OnTaskSetFinished callbacks. |
| 585 raster_finished_weak_ptr_factory_.InvalidateWeakPtrs(); | 567 task_set_finished_weak_ptr_factory_.InvalidateWeakPtrs(); |
| 586 | 568 |
| 587 scoped_refptr<RasterizerTask> new_raster_finished_tasks[kNumberOfTaskSets]; | 569 scoped_refptr<TileTask> new_task_set_finished_tasks[kNumberOfTaskSets]; |
| 588 size_t scheduled_task_counts[kNumberOfTaskSets] = {0}; | 570 size_t scheduled_task_counts[kNumberOfTaskSets] = {0}; |
| 589 | 571 |
| 590 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) { | 572 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) { |
| 591 scheduled_task_counts[task_set] = tasks[task_set].container().size(); | 573 scheduled_task_counts[task_set] = tasks[task_set].container().size(); |
| 592 DCHECK_LE(scheduled_task_counts[task_set], task_counts_[task_set]); | 574 DCHECK_LE(scheduled_task_counts[task_set], task_counts_[task_set]); |
| 593 // Schedule OnRasterFinished call for task set only when notification is | 575 // Schedule OnTaskSetFinished call for task set only when notification is |
| 594 // pending and throttling is not preventing all pending tasks in the set | 576 // pending and throttling is not preventing all pending tasks in the set |
| 595 // from being scheduled. | 577 // from being scheduled. |
| 596 if (!did_throttle_raster_tasks[task_set] && | 578 if (!did_throttle_raster_tasks[task_set] && |
| 597 should_notify_client_if_no_tasks_are_pending_[task_set]) { | 579 should_notify_client_if_no_tasks_are_pending_[task_set]) { |
| 598 new_raster_finished_tasks[task_set] = CreateRasterFinishedTask( | 580 new_task_set_finished_tasks[task_set] = CreateTaskSetFinishedTask( |
| 599 task_runner_.get(), | 581 task_runner_.get(), |
| 600 base::Bind(&PixelBufferRasterWorkerPool::OnRasterFinished, | 582 base::Bind(&PixelBufferTileTaskWorkerPool::OnTaskSetFinished, |
| 601 raster_finished_weak_ptr_factory_.GetWeakPtr(), | 583 task_set_finished_weak_ptr_factory_.GetWeakPtr(), |
| 602 task_set)); | 584 task_set)); |
| 603 raster_finished_tasks_pending_[task_set] = true; | 585 task_set_finished_tasks_pending_[task_set] = true; |
| 604 InsertNodeForTask(&graph_, | 586 InsertNodeForTask(&graph_, new_task_set_finished_tasks[task_set].get(), |
| 605 new_raster_finished_tasks[task_set].get(), | 587 kTaskSetFinishedTaskPriority, |
| 606 kRasterFinishedTaskPriority, | |
| 607 scheduled_task_counts[task_set]); | 588 scheduled_task_counts[task_set]); |
| 608 for (RasterTaskVector::ContainerType::const_iterator it = | 589 for (RasterTaskVector::ContainerType::const_iterator it = |
| 609 tasks[task_set].container().begin(); | 590 tasks[task_set].container().begin(); |
| 610 it != tasks[task_set].container().end(); | 591 it != tasks[task_set].container().end(); ++it) { |
| 611 ++it) { | |
| 612 graph_.edges.push_back( | 592 graph_.edges.push_back( |
| 613 TaskGraph::Edge(*it, new_raster_finished_tasks[task_set].get())); | 593 TaskGraph::Edge(*it, new_task_set_finished_tasks[task_set].get())); |
| 614 } | 594 } |
| 615 } | 595 } |
| 616 } | 596 } |
| 617 | 597 |
| 618 DCHECK_LE(scheduled_raster_task_count, PendingRasterTaskCount()); | 598 DCHECK_LE(scheduled_raster_task_count, PendingRasterTaskCount()); |
| 619 | 599 |
| 620 ScheduleTasksOnOriginThread(this, &graph_); | 600 ScheduleTasksOnOriginThread(this, &graph_); |
| 621 task_graph_runner_->ScheduleTasks(namespace_token_, &graph_); | 601 task_graph_runner_->ScheduleTasks(namespace_token_, &graph_); |
| 622 | 602 |
| 623 scheduled_raster_task_count_ = scheduled_raster_task_count; | 603 scheduled_raster_task_count_ = scheduled_raster_task_count; |
| 624 | 604 |
| 625 std::copy(new_raster_finished_tasks, | 605 std::copy(new_task_set_finished_tasks, |
| 626 new_raster_finished_tasks + kNumberOfTaskSets, | 606 new_task_set_finished_tasks + kNumberOfTaskSets, |
| 627 raster_finished_tasks_); | 607 task_set_finished_tasks_); |
| 628 } | 608 } |
| 629 | 609 |
| 630 unsigned PixelBufferRasterWorkerPool::PendingRasterTaskCount() const { | 610 unsigned PixelBufferTileTaskWorkerPool::PendingRasterTaskCount() const { |
| 631 unsigned num_completed_raster_tasks = | 611 unsigned num_completed_raster_tasks = |
| 632 raster_tasks_with_pending_upload_.size() + completed_raster_tasks_.size(); | 612 raster_tasks_with_pending_upload_.size() + completed_raster_tasks_.size(); |
| 633 DCHECK_GE(raster_task_states_.size(), num_completed_raster_tasks); | 613 DCHECK_GE(raster_task_states_.size(), num_completed_raster_tasks); |
| 634 return raster_task_states_.size() - num_completed_raster_tasks; | 614 return raster_task_states_.size() - num_completed_raster_tasks; |
| 635 } | 615 } |
| 636 | 616 |
| 637 TaskSetCollection PixelBufferRasterWorkerPool::PendingTasks() const { | 617 TaskSetCollection PixelBufferTileTaskWorkerPool::PendingTasks() const { |
| 638 return NonEmptyTaskSetsFromTaskCounts(task_counts_); | 618 return NonEmptyTaskSetsFromTaskCounts(task_counts_); |
| 639 } | 619 } |
| 640 | 620 |
| 641 const char* PixelBufferRasterWorkerPool::StateName() const { | 621 const char* PixelBufferTileTaskWorkerPool::StateName() const { |
| 642 if (scheduled_raster_task_count_) | 622 if (scheduled_raster_task_count_) |
| 643 return "rasterizing"; | 623 return "rasterizing"; |
| 644 if (PendingRasterTaskCount()) | 624 if (PendingRasterTaskCount()) |
| 645 return "throttled"; | 625 return "throttled"; |
| 646 if (!raster_tasks_with_pending_upload_.empty()) | 626 if (!raster_tasks_with_pending_upload_.empty()) |
| 647 return "waiting_for_uploads"; | 627 return "waiting_for_uploads"; |
| 648 | 628 |
| 649 return "finishing"; | 629 return "finishing"; |
| 650 } | 630 } |
| 651 | 631 |
| 652 void PixelBufferRasterWorkerPool::CheckForCompletedRasterizerTasks() { | 632 void PixelBufferTileTaskWorkerPool::CheckForCompletedRasterizerTasks() { |
| 653 TRACE_EVENT0("cc", | 633 TRACE_EVENT0( |
| 654 "PixelBufferRasterWorkerPool::CheckForCompletedRasterizerTasks"); | 634 "cc", "PixelBufferTileTaskWorkerPool::CheckForCompletedRasterizerTasks"); |
| 655 | 635 |
| 656 task_graph_runner_->CollectCompletedTasks(namespace_token_, | 636 task_graph_runner_->CollectCompletedTasks(namespace_token_, |
| 657 &completed_tasks_); | 637 &completed_tasks_); |
| 658 for (Task::Vector::const_iterator it = completed_tasks_.begin(); | 638 for (Task::Vector::const_iterator it = completed_tasks_.begin(); |
| 659 it != completed_tasks_.end(); | 639 it != completed_tasks_.end(); ++it) { |
| 660 ++it) { | 640 TileTask* task = static_cast<TileTask*>(it->get()); |
| 661 RasterizerTask* task = static_cast<RasterizerTask*>(it->get()); | |
| 662 | 641 |
| 663 RasterTask* raster_task = task->AsRasterTask(); | 642 RasterTask* raster_task = task->AsRasterTask(); |
| 664 if (!raster_task) { | 643 if (!raster_task) { |
| 665 task->WillComplete(); | 644 task->WillComplete(); |
| 666 task->CompleteOnOriginThread(this); | 645 task->CompleteOnOriginThread(this); |
| 667 task->DidComplete(); | 646 task->DidComplete(); |
| 668 | 647 |
| 669 completed_image_decode_tasks_.push_back(task); | 648 completed_image_decode_tasks_.push_back(task); |
| 670 continue; | 649 continue; |
| 671 } | 650 } |
| 672 | 651 |
| 673 RasterTaskState::Vector::iterator state_it = | 652 RasterTaskState::Vector::iterator state_it = |
| 674 std::find_if(raster_task_states_.begin(), | 653 std::find_if(raster_task_states_.begin(), raster_task_states_.end(), |
| 675 raster_task_states_.end(), | |
| 676 RasterTaskState::TaskComparator(raster_task)); | 654 RasterTaskState::TaskComparator(raster_task)); |
| 677 DCHECK(state_it != raster_task_states_.end()); | 655 DCHECK(state_it != raster_task_states_.end()); |
| 678 | 656 |
| 679 RasterTaskState& state = *state_it; | 657 RasterTaskState& state = *state_it; |
| 680 DCHECK_EQ(RasterTaskState::SCHEDULED, state.type); | 658 DCHECK_EQ(RasterTaskState::SCHEDULED, state.type); |
| 681 | 659 |
| 682 resource_provider_->UnmapPixelBuffer(raster_task->resource()->id()); | 660 resource_provider_->UnmapPixelBuffer(raster_task->resource()->id()); |
| 683 | 661 |
| 684 if (!raster_task->HasFinishedRunning()) { | 662 if (!raster_task->HasFinishedRunning()) { |
| 685 // When priorites change, a raster task can be canceled as a result of | 663 // When priorites change, a raster task can be canceled as a result of |
| 686 // no longer being of high enough priority to fit in our throttled | 664 // no longer being of high enough priority to fit in our throttled |
| 687 // raster task budget. The task has not yet completed in this case. | 665 // raster task budget. The task has not yet completed in this case. |
| 688 raster_task->WillComplete(); | 666 raster_task->WillComplete(); |
| 689 raster_task->CompleteOnOriginThread(this); | 667 raster_task->CompleteOnOriginThread(this); |
| 690 raster_task->DidComplete(); | 668 raster_task->DidComplete(); |
| 691 | 669 |
| 692 RasterTaskQueue::Item::Vector::const_iterator item_it = | 670 TileTaskQueue::Item::Vector::const_iterator item_it = |
| 693 std::find_if(raster_tasks_.items.begin(), | 671 std::find_if(raster_tasks_.items.begin(), raster_tasks_.items.end(), |
| 694 raster_tasks_.items.end(), | 672 TileTaskQueue::Item::TaskComparator(raster_task)); |
| 695 RasterTaskQueue::Item::TaskComparator(raster_task)); | |
| 696 if (item_it != raster_tasks_.items.end()) { | 673 if (item_it != raster_tasks_.items.end()) { |
| 697 state.type = RasterTaskState::UNSCHEDULED; | 674 state.type = RasterTaskState::UNSCHEDULED; |
| 698 continue; | 675 continue; |
| 699 } | 676 } |
| 700 | 677 |
| 701 DCHECK(std::find(completed_raster_tasks_.begin(), | 678 DCHECK(std::find(completed_raster_tasks_.begin(), |
| 702 completed_raster_tasks_.end(), | 679 completed_raster_tasks_.end(), |
| 703 raster_task) == completed_raster_tasks_.end()); | 680 raster_task) == completed_raster_tasks_.end()); |
| 704 completed_raster_tasks_.push_back(raster_task); | 681 completed_raster_tasks_.push_back(raster_task); |
| 705 state.type = RasterTaskState::COMPLETED; | 682 state.type = RasterTaskState::COMPLETED; |
| 706 // Triggers if the current task belongs to a set that should be empty. | 683 // Triggers if the current task belongs to a set that should be empty. |
| 707 DCHECK((state.task_sets & ~NonEmptyTaskSetsFromTaskCounts(task_counts_)) | 684 DCHECK((state.task_sets & ~NonEmptyTaskSetsFromTaskCounts(task_counts_)) |
| 708 .none()); | 685 .none()); |
| 709 RemoveTaskSetsFromTaskCounts(task_counts_, state.task_sets); | 686 RemoveTaskSetsFromTaskCounts(task_counts_, state.task_sets); |
| 710 continue; | 687 continue; |
| 711 } | 688 } |
| 712 | 689 |
| 713 resource_provider_->BeginSetPixels(raster_task->resource()->id()); | 690 resource_provider_->BeginSetPixels(raster_task->resource()->id()); |
| 714 has_performed_uploads_since_last_flush_ = true; | 691 has_performed_uploads_since_last_flush_ = true; |
| 715 | 692 |
| 716 bytes_pending_upload_ += raster_task->resource()->bytes(); | 693 bytes_pending_upload_ += raster_task->resource()->bytes(); |
| 717 raster_tasks_with_pending_upload_.push_back(raster_task); | 694 raster_tasks_with_pending_upload_.push_back(raster_task); |
| 718 state.type = RasterTaskState::UPLOADING; | 695 state.type = RasterTaskState::UPLOADING; |
| 719 } | 696 } |
| 720 completed_tasks_.clear(); | 697 completed_tasks_.clear(); |
| 721 } | 698 } |
| 722 | 699 |
| 723 scoped_refptr<base::debug::ConvertableToTraceFormat> | 700 scoped_refptr<base::debug::ConvertableToTraceFormat> |
| 724 PixelBufferRasterWorkerPool::StateAsValue() const { | 701 PixelBufferTileTaskWorkerPool::StateAsValue() const { |
| 725 scoped_refptr<base::debug::TracedValue> state = | 702 scoped_refptr<base::debug::TracedValue> state = |
| 726 new base::debug::TracedValue(); | 703 new base::debug::TracedValue(); |
| 727 state->SetInteger("completed_count", completed_raster_tasks_.size()); | 704 state->SetInteger("completed_count", completed_raster_tasks_.size()); |
| 728 state->BeginArray("pending_count"); | 705 state->BeginArray("pending_count"); |
| 729 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) | 706 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) |
| 730 state->AppendInteger(task_counts_[task_set]); | 707 state->AppendInteger(task_counts_[task_set]); |
| 731 state->EndArray(); | 708 state->EndArray(); |
| 732 state->SetInteger("pending_upload_count", | 709 state->SetInteger("pending_upload_count", |
| 733 raster_tasks_with_pending_upload_.size()); | 710 raster_tasks_with_pending_upload_.size()); |
| 734 state->BeginDictionary("throttle_state"); | 711 state->BeginDictionary("throttle_state"); |
| 735 ThrottleStateAsValueInto(state.get()); | 712 ThrottleStateAsValueInto(state.get()); |
| 736 state->EndDictionary(); | 713 state->EndDictionary(); |
| 737 return state; | 714 return state; |
| 738 } | 715 } |
| 739 | 716 |
| 740 void PixelBufferRasterWorkerPool::ThrottleStateAsValueInto( | 717 void PixelBufferTileTaskWorkerPool::ThrottleStateAsValueInto( |
| 741 base::debug::TracedValue* throttle_state) const { | 718 base::debug::TracedValue* throttle_state) const { |
| 742 throttle_state->SetInteger("bytes_available_for_upload", | 719 throttle_state->SetInteger("bytes_available_for_upload", |
| 743 max_bytes_pending_upload_ - bytes_pending_upload_); | 720 max_bytes_pending_upload_ - bytes_pending_upload_); |
| 744 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_); | 721 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_); |
| 745 throttle_state->SetInteger("scheduled_raster_task_count", | 722 throttle_state->SetInteger("scheduled_raster_task_count", |
| 746 scheduled_raster_task_count_); | 723 scheduled_raster_task_count_); |
| 747 } | 724 } |
| 748 | 725 |
| 749 } // namespace cc | 726 } // namespace cc |
| OLD | NEW |