| 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_raster_worker_pool.h" |
| 6 | 6 |
| 7 #include "base/containers/stack_container.h" | 7 #include "base/containers/stack_container.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "cc/debug/traced_value.h" | 10 #include "cc/debug/traced_value.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 PixelBufferWorkerPoolTaskImpl(internal::RasterWorkerPoolTask* task, | 26 PixelBufferWorkerPoolTaskImpl(internal::RasterWorkerPoolTask* task, |
| 27 uint8_t* buffer, | 27 uint8_t* buffer, |
| 28 const Reply& reply) | 28 const Reply& reply) |
| 29 : task_(task), | 29 : task_(task), |
| 30 buffer_(buffer), | 30 buffer_(buffer), |
| 31 reply_(reply), | 31 reply_(reply), |
| 32 needs_upload_(false) { | 32 needs_upload_(false) { |
| 33 } | 33 } |
| 34 | 34 |
| 35 // Overridden from internal::Task: | 35 // Overridden from internal::WorkerPoolTask: |
| 36 virtual void RunOnWorkerThread(unsigned thread_index) OVERRIDE { | 36 virtual void RunOnWorkerThread(unsigned thread_index) OVERRIDE { |
| 37 // |buffer_| can be NULL in lost context situations. | 37 // |buffer_| can be NULL in lost context situations. |
| 38 if (!buffer_) { | 38 if (!buffer_) { |
| 39 // |needs_upload_| still needs to be true as task has not | 39 // |needs_upload_| still needs to be true as task has not |
| 40 // been canceled. | 40 // been canceled. |
| 41 needs_upload_ = true; | 41 needs_upload_ = true; |
| 42 return; | 42 return; |
| 43 } | 43 } |
| 44 needs_upload_ = task_->RunOnWorkerThread(thread_index, | 44 needs_upload_ = task_->RunOnWorkerThread(thread_index, |
| 45 buffer_, | 45 buffer_, |
| 46 task_->resource()->size(), | 46 task_->resource()->size(), |
| 47 0); | 47 0); |
| 48 } | 48 } |
| 49 | |
| 50 // Overridden from internal::WorkerPoolTask: | |
| 51 virtual void CompleteOnOriginThread() OVERRIDE { | 49 virtual void CompleteOnOriginThread() OVERRIDE { |
| 52 // |needs_upload_| must be be false if task didn't run. | 50 // |needs_upload_| must be be false if task didn't run. |
| 53 DCHECK(HasFinishedRunning() || !needs_upload_); | 51 DCHECK(HasFinishedRunning() || !needs_upload_); |
| 54 reply_.Run(!HasFinishedRunning(), needs_upload_); | 52 reply_.Run(!HasFinishedRunning(), needs_upload_); |
| 55 } | 53 } |
| 56 | 54 |
| 57 private: | 55 private: |
| 58 virtual ~PixelBufferWorkerPoolTaskImpl() {} | 56 virtual ~PixelBufferWorkerPoolTaskImpl() {} |
| 59 | 57 |
| 60 scoped_refptr<internal::RasterWorkerPoolTask> task_; | 58 scoped_refptr<internal::RasterWorkerPoolTask> task_; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 DCHECK(shutdown_); | 111 DCHECK(shutdown_); |
| 114 DCHECK(!check_for_completed_raster_tasks_pending_); | 112 DCHECK(!check_for_completed_raster_tasks_pending_); |
| 115 DCHECK_EQ(0u, pixel_buffer_tasks_.size()); | 113 DCHECK_EQ(0u, pixel_buffer_tasks_.size()); |
| 116 DCHECK_EQ(0u, tasks_with_pending_upload_.size()); | 114 DCHECK_EQ(0u, tasks_with_pending_upload_.size()); |
| 117 DCHECK_EQ(0u, completed_tasks_.size()); | 115 DCHECK_EQ(0u, completed_tasks_.size()); |
| 118 } | 116 } |
| 119 | 117 |
| 120 void PixelBufferRasterWorkerPool::Shutdown() { | 118 void PixelBufferRasterWorkerPool::Shutdown() { |
| 121 shutdown_ = true; | 119 shutdown_ = true; |
| 122 RasterWorkerPool::Shutdown(); | 120 RasterWorkerPool::Shutdown(); |
| 123 | 121 CheckForCompletedWorkerTasks(); |
| 124 CheckForCompletedWorkerPoolTasks(); | |
| 125 CheckForCompletedUploads(); | 122 CheckForCompletedUploads(); |
| 126 check_for_completed_raster_tasks_callback_.Cancel(); | 123 check_for_completed_raster_tasks_callback_.Cancel(); |
| 127 check_for_completed_raster_tasks_pending_ = false; | 124 check_for_completed_raster_tasks_pending_ = false; |
| 128 for (TaskMap::iterator it = pixel_buffer_tasks_.begin(); | 125 for (TaskMap::iterator it = pixel_buffer_tasks_.begin(); |
| 129 it != pixel_buffer_tasks_.end(); ++it) { | 126 it != pixel_buffer_tasks_.end(); ++it) { |
| 130 internal::RasterWorkerPoolTask* task = it->first; | 127 internal::RasterWorkerPoolTask* task = it->first; |
| 131 internal::WorkerPoolTask* pixel_buffer_task = it->second.get(); | 128 internal::WorkerPoolTask* pixel_buffer_task = it->second.get(); |
| 132 | 129 |
| 133 // All inactive tasks needs to be canceled. | 130 // All inactive tasks needs to be canceled. |
| 134 if (!pixel_buffer_task && !task->HasFinishedRunning()) { | 131 if (!pixel_buffer_task && !task->HasFinishedRunning()) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 it != completed_tasks_.end() && !tasks_required_for_activation_.empty(); | 200 it != completed_tasks_.end() && !tasks_required_for_activation_.empty(); |
| 204 ++it) { | 201 ++it) { |
| 205 tasks_required_for_activation_.erase(*it); | 202 tasks_required_for_activation_.erase(*it); |
| 206 } | 203 } |
| 207 | 204 |
| 208 pixel_buffer_tasks_.swap(new_pixel_buffer_tasks); | 205 pixel_buffer_tasks_.swap(new_pixel_buffer_tasks); |
| 209 | 206 |
| 210 // Check for completed tasks when ScheduleTasks() is called as | 207 // Check for completed tasks when ScheduleTasks() is called as |
| 211 // priorities might have changed and this maximizes the number | 208 // priorities might have changed and this maximizes the number |
| 212 // of top priority tasks that are scheduled. | 209 // of top priority tasks that are scheduled. |
| 213 CheckForCompletedWorkerPoolTasks(); | 210 CheckForCompletedWorkerTasks(); |
| 214 CheckForCompletedUploads(); | 211 CheckForCompletedUploads(); |
| 215 FlushUploads(); | 212 FlushUploads(); |
| 216 | 213 |
| 217 // Schedule new tasks. | 214 // Schedule new tasks. |
| 218 ScheduleMoreTasks(); | 215 ScheduleMoreTasks(); |
| 219 | 216 |
| 220 // Cancel any pending check for completed raster tasks and schedule | 217 // Cancel any pending check for completed raster tasks and schedule |
| 221 // another check. | 218 // another check. |
| 222 check_for_completed_raster_tasks_callback_.Cancel(); | 219 check_for_completed_raster_tasks_callback_.Cancel(); |
| 223 check_for_completed_raster_tasks_pending_ = false; | 220 check_for_completed_raster_tasks_pending_ = false; |
| 224 ScheduleCheckForCompletedRasterTasks(); | 221 ScheduleCheckForCompletedRasterTasks(); |
| 225 | 222 |
| 226 RunGpuRasterTasks(gpu_raster_tasks); | 223 RunGpuRasterTasks(gpu_raster_tasks); |
| 227 | 224 |
| 228 TRACE_EVENT_ASYNC_STEP_INTO1( | 225 TRACE_EVENT_ASYNC_STEP_INTO1( |
| 229 "cc", "ScheduledTasks", this, StateName(), | 226 "cc", "ScheduledTasks", this, StateName(), |
| 230 "state", TracedValue::FromValue(StateAsValue().release())); | 227 "state", TracedValue::FromValue(StateAsValue().release())); |
| 231 } | 228 } |
| 232 | 229 |
| 233 unsigned PixelBufferRasterWorkerPool::GetResourceTarget() const { | 230 GLenum PixelBufferRasterWorkerPool::GetResourceTarget() const { |
| 234 return GL_TEXTURE_2D; | 231 return GL_TEXTURE_2D; |
| 235 } | 232 } |
| 236 | 233 |
| 237 ResourceFormat PixelBufferRasterWorkerPool::GetResourceFormat() const { | 234 ResourceFormat PixelBufferRasterWorkerPool::GetResourceFormat() const { |
| 238 return resource_provider()->memory_efficient_texture_format(); | 235 return resource_provider()->memory_efficient_texture_format(); |
| 239 } | 236 } |
| 240 | 237 |
| 241 void PixelBufferRasterWorkerPool::CheckForCompletedTasks() { | 238 void PixelBufferRasterWorkerPool::CheckForCompletedTasks() { |
| 242 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::CheckForCompletedTasks"); | 239 TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::CheckForCompletedTasks"); |
| 243 | 240 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 | 384 |
| 388 void PixelBufferRasterWorkerPool::CheckForCompletedRasterTasks() { | 385 void PixelBufferRasterWorkerPool::CheckForCompletedRasterTasks() { |
| 389 TRACE_EVENT0( | 386 TRACE_EVENT0( |
| 390 "cc", "PixelBufferRasterWorkerPool::CheckForCompletedRasterTasks"); | 387 "cc", "PixelBufferRasterWorkerPool::CheckForCompletedRasterTasks"); |
| 391 | 388 |
| 392 DCHECK(should_notify_client_if_no_tasks_are_pending_); | 389 DCHECK(should_notify_client_if_no_tasks_are_pending_); |
| 393 | 390 |
| 394 check_for_completed_raster_tasks_callback_.Cancel(); | 391 check_for_completed_raster_tasks_callback_.Cancel(); |
| 395 check_for_completed_raster_tasks_pending_ = false; | 392 check_for_completed_raster_tasks_pending_ = false; |
| 396 | 393 |
| 397 CheckForCompletedWorkerPoolTasks(); | 394 CheckForCompletedWorkerTasks(); |
| 398 CheckForCompletedUploads(); | 395 CheckForCompletedUploads(); |
| 399 FlushUploads(); | 396 FlushUploads(); |
| 400 | 397 |
| 401 // Determine what client notifications to generate. | 398 // Determine what client notifications to generate. |
| 402 bool will_notify_client_that_no_tasks_required_for_activation_are_pending = | 399 bool will_notify_client_that_no_tasks_required_for_activation_are_pending = |
| 403 (should_notify_client_if_no_tasks_required_for_activation_are_pending_ && | 400 (should_notify_client_if_no_tasks_required_for_activation_are_pending_ && |
| 404 !raster_required_for_activation_finished_task_pending_ && | 401 !raster_required_for_activation_finished_task_pending_ && |
| 405 !HasPendingTasksRequiredForActivation()); | 402 !HasPendingTasksRequiredForActivation()); |
| 406 bool will_notify_client_that_no_tasks_are_pending = | 403 bool will_notify_client_that_no_tasks_are_pending = |
| 407 (should_notify_client_if_no_tasks_are_pending_ && | 404 (should_notify_client_if_no_tasks_are_pending_ && |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 | 691 |
| 695 throttle_state->SetInteger("bytes_available_for_upload", | 692 throttle_state->SetInteger("bytes_available_for_upload", |
| 696 max_bytes_pending_upload_ - bytes_pending_upload_); | 693 max_bytes_pending_upload_ - bytes_pending_upload_); |
| 697 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_); | 694 throttle_state->SetInteger("bytes_pending_upload", bytes_pending_upload_); |
| 698 throttle_state->SetInteger("scheduled_raster_task_count", | 695 throttle_state->SetInteger("scheduled_raster_task_count", |
| 699 scheduled_raster_task_count_); | 696 scheduled_raster_task_count_); |
| 700 return throttle_state.PassAs<base::Value>(); | 697 return throttle_state.PassAs<base::Value>(); |
| 701 } | 698 } |
| 702 | 699 |
| 703 } // namespace cc | 700 } // namespace cc |
| OLD | NEW |