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