diff options
-rw-r--r-- | cc/resources/direct_raster_worker_pool.cc | 76 | ||||
-rw-r--r-- | cc/resources/direct_raster_worker_pool.h | 29 | ||||
-rw-r--r-- | cc/resources/image_raster_worker_pool.cc | 71 | ||||
-rw-r--r-- | cc/resources/image_raster_worker_pool.h | 29 | ||||
-rw-r--r-- | cc/resources/pixel_buffer_raster_worker_pool.cc | 116 | ||||
-rw-r--r-- | cc/resources/pixel_buffer_raster_worker_pool.h | 35 | ||||
-rw-r--r-- | cc/resources/raster_worker_pool.cc | 138 | ||||
-rw-r--r-- | cc/resources/raster_worker_pool.h | 158 | ||||
-rw-r--r-- | cc/resources/raster_worker_pool_perftest.cc | 28 | ||||
-rw-r--r-- | cc/resources/raster_worker_pool_unittest.cc | 32 | ||||
-rw-r--r-- | cc/resources/task_graph_runner.h | 7 | ||||
-rw-r--r-- | cc/resources/tile_manager.cc | 60 | ||||
-rw-r--r-- | cc/resources/tile_manager.h | 31 | ||||
-rw-r--r-- | cc/test/fake_tile_manager.cc | 66 | ||||
-rw-r--r-- | cc/trees/layer_tree_host_impl.cc | 41 | ||||
-rw-r--r-- | cc/trees/layer_tree_host_impl.h | 10 |
16 files changed, 495 insertions, 432 deletions
diff --git a/cc/resources/direct_raster_worker_pool.cc b/cc/resources/direct_raster_worker_pool.cc index 6b27846..abe73da 100644 --- a/cc/resources/direct_raster_worker_pool.cc +++ b/cc/resources/direct_raster_worker_pool.cc @@ -14,11 +14,11 @@ namespace cc { // static -scoped_ptr<RasterWorkerPool> DirectRasterWorkerPool::Create( +scoped_ptr<DirectRasterWorkerPool> DirectRasterWorkerPool::Create( base::SequencedTaskRunner* task_runner, ResourceProvider* resource_provider, ContextProvider* context_provider) { - return make_scoped_ptr<RasterWorkerPool>(new DirectRasterWorkerPool( + return make_scoped_ptr(new DirectRasterWorkerPool( task_runner, resource_provider, context_provider)); } @@ -26,17 +26,23 @@ DirectRasterWorkerPool::DirectRasterWorkerPool( base::SequencedTaskRunner* task_runner, ResourceProvider* resource_provider, ContextProvider* context_provider) - : RasterWorkerPool(task_runner, NULL, resource_provider), + : task_runner_(task_runner), + resource_provider_(resource_provider), context_provider_(context_provider), run_tasks_on_origin_thread_pending_(false), raster_tasks_pending_(false), raster_tasks_required_for_activation_pending_(false), - weak_factory_(this) {} + raster_finished_weak_ptr_factory_(this), + weak_ptr_factory_(this) {} DirectRasterWorkerPool::~DirectRasterWorkerPool() { DCHECK_EQ(0u, completed_tasks_.size()); } +void DirectRasterWorkerPool::SetClient(RasterWorkerPoolClient* client) { + client_ = client; +} + void DirectRasterWorkerPool::ScheduleTasks(RasterTaskQueue* queue) { TRACE_EVENT0("cc", "DirectRasterWorkerPool::ScheduleTasks"); @@ -49,12 +55,22 @@ void DirectRasterWorkerPool::ScheduleTasks(RasterTaskQueue* queue) { raster_tasks_pending_ = true; raster_tasks_required_for_activation_pending_ = true; + // Cancel existing OnRasterFinished callbacks. + raster_finished_weak_ptr_factory_.InvalidateWeakPtrs(); + scoped_refptr<internal::WorkerPoolTask> new_raster_required_for_activation_finished_task( CreateRasterRequiredForActivationFinishedTask( - queue->required_for_activation_count)); + queue->required_for_activation_count, + task_runner_.get(), + base::Bind(&DirectRasterWorkerPool:: + OnRasterRequiredForActivationFinished, + raster_finished_weak_ptr_factory_.GetWeakPtr()))); scoped_refptr<internal::WorkerPoolTask> new_raster_finished_task( - CreateRasterFinishedTask()); + CreateRasterFinishedTask( + task_runner_.get(), + base::Bind(&DirectRasterWorkerPool::OnRasterFinished, + raster_finished_weak_ptr_factory_.GetWeakPtr()))); // Need to cancel tasks not present in new queue if we haven't had a // chance to run the previous set of tasks yet. @@ -79,9 +95,9 @@ void DirectRasterWorkerPool::ScheduleTasks(RasterTaskQueue* queue) { raster_tasks_.Swap(queue); - set_raster_finished_task(new_raster_finished_task); - set_raster_required_for_activation_finished_task( - new_raster_required_for_activation_finished_task); + raster_finished_task_ = new_raster_finished_task; + raster_required_for_activation_finished_task_ = + new_raster_required_for_activation_finished_task; } unsigned DirectRasterWorkerPool::GetResourceTarget() const { @@ -89,7 +105,7 @@ unsigned DirectRasterWorkerPool::GetResourceTarget() const { } ResourceFormat DirectRasterWorkerPool::GetResourceFormat() const { - return resource_provider()->best_texture_format(); + return resource_provider_->best_texture_format(); } void DirectRasterWorkerPool::CheckForCompletedTasks() { @@ -109,35 +125,40 @@ void DirectRasterWorkerPool::CheckForCompletedTasks() { SkCanvas* DirectRasterWorkerPool::AcquireCanvasForRaster( internal::WorkerPoolTask* task, const Resource* resource) { - return resource_provider()->MapDirectRasterBuffer(resource->id()); + return resource_provider_->MapDirectRasterBuffer(resource->id()); } void DirectRasterWorkerPool::ReleaseCanvasForRaster( internal::WorkerPoolTask* task, const Resource* resource) { - resource_provider()->UnmapDirectRasterBuffer(resource->id()); + resource_provider_->UnmapDirectRasterBuffer(resource->id()); } -void DirectRasterWorkerPool::OnRasterTasksFinished() { +void DirectRasterWorkerPool::OnRasterFinished() { + TRACE_EVENT0("cc", "DirectRasterWorkerPool::OnRasterFinished"); + DCHECK(raster_tasks_pending_); raster_tasks_pending_ = false; - client()->DidFinishRunningTasks(); + client_->DidFinishRunningTasks(); } -void DirectRasterWorkerPool::OnRasterTasksRequiredForActivationFinished() { +void DirectRasterWorkerPool::OnRasterRequiredForActivationFinished() { + TRACE_EVENT0("cc", + "DirectRasterWorkerPool::OnRasterRequiredForActivationFinished"); + DCHECK(raster_tasks_required_for_activation_pending_); raster_tasks_required_for_activation_pending_ = false; - client()->DidFinishRunningTasksRequiredForActivation(); + client_->DidFinishRunningTasksRequiredForActivation(); } void DirectRasterWorkerPool::ScheduleRunTasksOnOriginThread() { if (run_tasks_on_origin_thread_pending_) return; - task_runner()->PostTask( + task_runner_->PostTask( FROM_HERE, base::Bind(&DirectRasterWorkerPool::RunTasksOnOriginThread, - weak_factory_.GetWeakPtr())); + weak_ptr_factory_.GetWeakPtr())); run_tasks_on_origin_thread_pending_ = true; } @@ -192,8 +213,23 @@ void DirectRasterWorkerPool::RunTasksOnOriginThread() { context_provider_->ContextGL()->PopGroupMarkerEXT(); } - RunTaskOnOriginThread(raster_required_for_activation_finished_task()); - RunTaskOnOriginThread(raster_finished_task()); + RunTaskOnOriginThread(raster_required_for_activation_finished_task_.get()); + RunTaskOnOriginThread(raster_finished_task_.get()); +} + +void DirectRasterWorkerPool::RunTaskOnOriginThread( + internal::WorkerPoolTask* task) { + task->WillSchedule(); + task->ScheduleOnOriginThread(this); + task->DidSchedule(); + + task->WillRun(); + task->RunOnOriginThread(); + task->DidRun(); + + task->WillComplete(); + task->CompleteOnOriginThread(this); + task->DidComplete(); } } // namespace cc diff --git a/cc/resources/direct_raster_worker_pool.h b/cc/resources/direct_raster_worker_pool.h index d2a6fd5..74013b6 100644 --- a/cc/resources/direct_raster_worker_pool.h +++ b/cc/resources/direct_raster_worker_pool.h @@ -5,22 +5,26 @@ #ifndef CC_RESOURCES_DIRECT_RASTER_WORKER_POOL_H_ #define CC_RESOURCES_DIRECT_RASTER_WORKER_POOL_H_ +#include "base/memory/weak_ptr.h" #include "cc/resources/raster_worker_pool.h" namespace cc { - class ContextProvider; +class ResourceProvider; -class CC_EXPORT DirectRasterWorkerPool : public RasterWorkerPool { +class CC_EXPORT DirectRasterWorkerPool : public RasterWorkerPool, + public internal::WorkerPoolTaskClient { public: virtual ~DirectRasterWorkerPool(); - static scoped_ptr<RasterWorkerPool> Create( + static scoped_ptr<DirectRasterWorkerPool> Create( base::SequencedTaskRunner* task_runner, ResourceProvider* resource_provider, ContextProvider* context_provider); // Overridden from RasterWorkerPool: + virtual void SetClient(RasterWorkerPoolClient* client) OVERRIDE; + virtual void Shutdown() OVERRIDE {} virtual void ScheduleTasks(RasterTaskQueue* queue) OVERRIDE; virtual unsigned GetResourceTarget() const OVERRIDE; virtual ResourceFormat GetResourceFormat() const OVERRIDE; @@ -38,13 +42,15 @@ class CC_EXPORT DirectRasterWorkerPool : public RasterWorkerPool { ContextProvider* context_provider); private: - // Overridden from RasterWorkerPool: - virtual void OnRasterTasksFinished() OVERRIDE; - virtual void OnRasterTasksRequiredForActivationFinished() OVERRIDE; - + void OnRasterFinished(); + void OnRasterRequiredForActivationFinished(); void ScheduleRunTasksOnOriginThread(); void RunTasksOnOriginThread(); + void RunTaskOnOriginThread(internal::WorkerPoolTask* task); + scoped_refptr<base::SequencedTaskRunner> task_runner_; + RasterWorkerPoolClient* client_; + ResourceProvider* resource_provider_; ContextProvider* context_provider_; bool run_tasks_on_origin_thread_pending_; @@ -54,9 +60,16 @@ class CC_EXPORT DirectRasterWorkerPool : public RasterWorkerPool { bool raster_tasks_pending_; bool raster_tasks_required_for_activation_pending_; + base::WeakPtrFactory<DirectRasterWorkerPool> + raster_finished_weak_ptr_factory_; + + scoped_refptr<internal::WorkerPoolTask> raster_finished_task_; + scoped_refptr<internal::WorkerPoolTask> + raster_required_for_activation_finished_task_; + internal::WorkerPoolTask::Vector completed_tasks_; - base::WeakPtrFactory<DirectRasterWorkerPool> weak_factory_; + base::WeakPtrFactory<DirectRasterWorkerPool> weak_ptr_factory_; DISALLOW_COPY_AND_ASSIGN(DirectRasterWorkerPool); }; diff --git a/cc/resources/image_raster_worker_pool.cc b/cc/resources/image_raster_worker_pool.cc index bbaa2c5..6adf02b 100644 --- a/cc/resources/image_raster_worker_pool.cc +++ b/cc/resources/image_raster_worker_pool.cc @@ -11,11 +11,11 @@ namespace cc { // static -scoped_ptr<RasterWorkerPool> ImageRasterWorkerPool::Create( +scoped_ptr<ImageRasterWorkerPool> ImageRasterWorkerPool::Create( base::SequencedTaskRunner* task_runner, ResourceProvider* resource_provider, unsigned texture_target) { - return make_scoped_ptr<RasterWorkerPool>(new ImageRasterWorkerPool( + return make_scoped_ptr(new ImageRasterWorkerPool( task_runner, GetTaskGraphRunner(), resource_provider, texture_target)); } @@ -24,13 +24,29 @@ ImageRasterWorkerPool::ImageRasterWorkerPool( internal::TaskGraphRunner* task_graph_runner, ResourceProvider* resource_provider, unsigned texture_target) - : RasterWorkerPool(task_runner, task_graph_runner, resource_provider), + : task_runner_(task_runner), + task_graph_runner_(task_graph_runner), + namespace_token_(task_graph_runner->GetNamespaceToken()), + resource_provider_(resource_provider), texture_target_(texture_target), raster_tasks_pending_(false), - raster_tasks_required_for_activation_pending_(false) {} + raster_tasks_required_for_activation_pending_(false), + raster_finished_weak_ptr_factory_(this) {} ImageRasterWorkerPool::~ImageRasterWorkerPool() {} +void ImageRasterWorkerPool::SetClient(RasterWorkerPoolClient* client) { + client_ = client; +} + +void ImageRasterWorkerPool::Shutdown() { + TRACE_EVENT0("cc", "ImageRasterWorkerPool::Shutdown"); + + internal::TaskGraph empty; + task_graph_runner_->ScheduleTasks(namespace_token_, &empty); + task_graph_runner_->WaitForTasksToFinishRunning(namespace_token_); +} + void ImageRasterWorkerPool::ScheduleTasks(RasterTaskQueue* queue) { TRACE_EVENT0("cc", "ImageRasterWorkerPool::ScheduleTasks"); @@ -50,12 +66,22 @@ void ImageRasterWorkerPool::ScheduleTasks(RasterTaskQueue* queue) { graph_.Reset(); + // Cancel existing OnRasterFinished callbacks. + raster_finished_weak_ptr_factory_.InvalidateWeakPtrs(); + scoped_refptr<internal::WorkerPoolTask> new_raster_required_for_activation_finished_task( CreateRasterRequiredForActivationFinishedTask( - queue->required_for_activation_count)); + queue->required_for_activation_count, + task_runner_.get(), + base::Bind( + &ImageRasterWorkerPool::OnRasterRequiredForActivationFinished, + raster_finished_weak_ptr_factory_.GetWeakPtr()))); scoped_refptr<internal::WorkerPoolTask> new_raster_finished_task( - CreateRasterFinishedTask()); + CreateRasterFinishedTask( + task_runner_.get(), + base::Bind(&ImageRasterWorkerPool::OnRasterFinished, + raster_finished_weak_ptr_factory_.GetWeakPtr()))); for (RasterTaskQueue::Item::Vector::const_iterator it = queue->items.begin(); it != queue->items.end(); @@ -69,7 +95,7 @@ void ImageRasterWorkerPool::ScheduleTasks(RasterTaskQueue* queue) { task, new_raster_required_for_activation_finished_task.get())); } - InsertNodeForRasterTask(&graph_, task, task->dependencies(), priority++); + InsertNodesForRasterTask(&graph_, task, task->dependencies(), priority++); graph_.edges.push_back( internal::TaskGraph::Edge(task, new_raster_finished_task.get())); @@ -84,11 +110,12 @@ void ImageRasterWorkerPool::ScheduleTasks(RasterTaskQueue* queue) { kRasterFinishedTaskPriority, queue->items.size()); - SetTaskGraph(&graph_); + ScheduleTasksOnOriginThread(this, &graph_); + task_graph_runner_->ScheduleTasks(namespace_token_, &graph_); - set_raster_finished_task(new_raster_finished_task); - set_raster_required_for_activation_finished_task( - new_raster_required_for_activation_finished_task); + raster_finished_task_ = new_raster_finished_task; + raster_required_for_activation_finished_task_ = + new_raster_required_for_activation_finished_task; TRACE_EVENT_ASYNC_STEP_INTO1( "cc", @@ -104,13 +131,14 @@ unsigned ImageRasterWorkerPool::GetResourceTarget() const { } ResourceFormat ImageRasterWorkerPool::GetResourceFormat() const { - return resource_provider()->best_texture_format(); + return resource_provider_->best_texture_format(); } void ImageRasterWorkerPool::CheckForCompletedTasks() { TRACE_EVENT0("cc", "ImageRasterWorkerPool::CheckForCompletedTasks"); - CollectCompletedWorkerPoolTasks(&completed_tasks_); + task_graph_runner_->CollectCompletedTasks(namespace_token_, + &completed_tasks_); for (internal::Task::Vector::const_iterator it = completed_tasks_.begin(); it != completed_tasks_.end(); ++it) { @@ -129,23 +157,28 @@ void ImageRasterWorkerPool::CheckForCompletedTasks() { SkCanvas* ImageRasterWorkerPool::AcquireCanvasForRaster( internal::WorkerPoolTask* task, const Resource* resource) { - return resource_provider()->MapImageRasterBuffer(resource->id()); + return resource_provider_->MapImageRasterBuffer(resource->id()); } void ImageRasterWorkerPool::ReleaseCanvasForRaster( internal::WorkerPoolTask* task, const Resource* resource) { - resource_provider()->UnmapImageRasterBuffer(resource->id()); + resource_provider_->UnmapImageRasterBuffer(resource->id()); } -void ImageRasterWorkerPool::OnRasterTasksFinished() { +void ImageRasterWorkerPool::OnRasterFinished() { + TRACE_EVENT0("cc", "ImageRasterWorkerPool::OnRasterFinished"); + DCHECK(raster_tasks_pending_); raster_tasks_pending_ = false; TRACE_EVENT_ASYNC_END0("cc", "ScheduledTasks", this); - client()->DidFinishRunningTasks(); + client_->DidFinishRunningTasks(); } -void ImageRasterWorkerPool::OnRasterTasksRequiredForActivationFinished() { +void ImageRasterWorkerPool::OnRasterRequiredForActivationFinished() { + TRACE_EVENT0("cc", + "ImageRasterWorkerPool::OnRasterRequiredForActivationFinished"); + DCHECK(raster_tasks_required_for_activation_pending_); raster_tasks_required_for_activation_pending_ = false; TRACE_EVENT_ASYNC_STEP_INTO1( @@ -155,7 +188,7 @@ void ImageRasterWorkerPool::OnRasterTasksRequiredForActivationFinished() { "rasterizing", "state", TracedValue::FromValue(StateAsValue().release())); - client()->DidFinishRunningTasksRequiredForActivation(); + client_->DidFinishRunningTasksRequiredForActivation(); } scoped_ptr<base::Value> ImageRasterWorkerPool::StateAsValue() const { diff --git a/cc/resources/image_raster_worker_pool.h b/cc/resources/image_raster_worker_pool.h index 279ff46..7720d4b 100644 --- a/cc/resources/image_raster_worker_pool.h +++ b/cc/resources/image_raster_worker_pool.h @@ -5,22 +5,26 @@ #ifndef CC_RESOURCES_IMAGE_RASTER_WORKER_POOL_H_ #define CC_RESOURCES_IMAGE_RASTER_WORKER_POOL_H_ -#include "cc/resources/raster_worker_pool.h" - +#include "base/memory/weak_ptr.h" #include "base/values.h" +#include "cc/resources/raster_worker_pool.h" namespace cc { +class ResourceProvider; -class CC_EXPORT ImageRasterWorkerPool : public RasterWorkerPool { +class CC_EXPORT ImageRasterWorkerPool : public RasterWorkerPool, + public internal::WorkerPoolTaskClient { public: virtual ~ImageRasterWorkerPool(); - static scoped_ptr<RasterWorkerPool> Create( + static scoped_ptr<ImageRasterWorkerPool> Create( base::SequencedTaskRunner* task_runner, ResourceProvider* resource_provider, unsigned texture_target); // Overridden from RasterWorkerPool: + virtual void SetClient(RasterWorkerPoolClient* client) OVERRIDE; + virtual void Shutdown() OVERRIDE; virtual void ScheduleTasks(RasterTaskQueue* queue) OVERRIDE; virtual unsigned GetResourceTarget() const OVERRIDE; virtual ResourceFormat GetResourceFormat() const OVERRIDE; @@ -39,17 +43,26 @@ class CC_EXPORT ImageRasterWorkerPool : public RasterWorkerPool { unsigned texture_target); private: - // Overridden from RasterWorkerPool: - virtual void OnRasterTasksFinished() OVERRIDE; - virtual void OnRasterTasksRequiredForActivationFinished() OVERRIDE; - + void OnRasterFinished(); + void OnRasterRequiredForActivationFinished(); scoped_ptr<base::Value> StateAsValue() const; + scoped_refptr<base::SequencedTaskRunner> task_runner_; + internal::TaskGraphRunner* task_graph_runner_; + const internal::NamespaceToken namespace_token_; + RasterWorkerPoolClient* client_; + ResourceProvider* resource_provider_; const unsigned texture_target_; bool raster_tasks_pending_; bool raster_tasks_required_for_activation_pending_; + base::WeakPtrFactory<ImageRasterWorkerPool> raster_finished_weak_ptr_factory_; + + scoped_refptr<internal::WorkerPoolTask> raster_finished_task_; + scoped_refptr<internal::WorkerPoolTask> + raster_required_for_activation_finished_task_; + // Task graph used when scheduling tasks and vector used to gather // completed tasks. internal::TaskGraph graph_; diff --git a/cc/resources/pixel_buffer_raster_worker_pool.cc b/cc/resources/pixel_buffer_raster_worker_pool.cc index 80ddcd9..9f72d04 100644 --- a/cc/resources/pixel_buffer_raster_worker_pool.cc +++ b/cc/resources/pixel_buffer_raster_worker_pool.cc @@ -24,11 +24,11 @@ typedef base::StackVector<internal::WorkerPoolTask*, kMaxScheduledRasterTasks> } // namespace // static -scoped_ptr<RasterWorkerPool> PixelBufferRasterWorkerPool::Create( +scoped_ptr<PixelBufferRasterWorkerPool> PixelBufferRasterWorkerPool::Create( base::SequencedTaskRunner* task_runner, ResourceProvider* resource_provider, size_t max_transfer_buffer_usage_bytes) { - return make_scoped_ptr<RasterWorkerPool>( + return make_scoped_ptr( new PixelBufferRasterWorkerPool(task_runner, GetTaskGraphRunner(), resource_provider, @@ -40,7 +40,10 @@ PixelBufferRasterWorkerPool::PixelBufferRasterWorkerPool( internal::TaskGraphRunner* task_graph_runner, ResourceProvider* resource_provider, size_t max_transfer_buffer_usage_bytes) - : RasterWorkerPool(task_runner, task_graph_runner, resource_provider), + : task_runner_(task_runner), + task_graph_runner_(task_graph_runner), + namespace_token_(task_graph_runner->GetNamespaceToken()), + resource_provider_(resource_provider), shutdown_(false), scheduled_raster_task_count_(0u), raster_tasks_required_for_activation_count_(0u), @@ -53,10 +56,10 @@ PixelBufferRasterWorkerPool::PixelBufferRasterWorkerPool( false), raster_finished_task_pending_(false), raster_required_for_activation_finished_task_pending_(false), - weak_factory_(this) {} + raster_finished_weak_ptr_factory_(this), + weak_ptr_factory_(this) {} PixelBufferRasterWorkerPool::~PixelBufferRasterWorkerPool() { - DCHECK(shutdown_); DCHECK(!check_for_completed_raster_tasks_pending_); DCHECK_EQ(0u, raster_task_states_.size()); DCHECK_EQ(0u, raster_tasks_with_pending_upload_.size()); @@ -65,14 +68,22 @@ PixelBufferRasterWorkerPool::~PixelBufferRasterWorkerPool() { DCHECK_EQ(0u, raster_tasks_required_for_activation_count_); } +void PixelBufferRasterWorkerPool::SetClient(RasterWorkerPoolClient* client) { + client_ = client; +} + void PixelBufferRasterWorkerPool::Shutdown() { + TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::Shutdown"); + shutdown_ = true; - RasterWorkerPool::Shutdown(); + + internal::TaskGraph empty; + task_graph_runner_->ScheduleTasks(namespace_token_, &empty); + task_graph_runner_->WaitForTasksToFinishRunning(namespace_token_); CheckForCompletedWorkerPoolTasks(); CheckForCompletedUploads(); - weak_factory_.InvalidateWeakPtrs(); check_for_completed_raster_tasks_pending_ = false; for (RasterTaskState::Vector::iterator it = raster_task_states_.begin(); @@ -213,7 +224,7 @@ unsigned PixelBufferRasterWorkerPool::GetResourceTarget() const { } ResourceFormat PixelBufferRasterWorkerPool::GetResourceFormat() const { - return resource_provider()->memory_efficient_texture_format(); + return resource_provider_->memory_efficient_texture_format(); } void PixelBufferRasterWorkerPool::CheckForCompletedTasks() { @@ -223,7 +234,8 @@ void PixelBufferRasterWorkerPool::CheckForCompletedTasks() { CheckForCompletedUploads(); FlushUploads(); - for (TaskVector::const_iterator it = completed_image_decode_tasks_.begin(); + for (internal::WorkerPoolTask::Vector::const_iterator it = + completed_image_decode_tasks_.begin(); it != completed_image_decode_tasks_.end(); ++it) { internal::WorkerPoolTask* task = it->get(); @@ -231,7 +243,8 @@ void PixelBufferRasterWorkerPool::CheckForCompletedTasks() { } completed_image_decode_tasks_.clear(); - for (TaskVector::const_iterator it = completed_raster_tasks_.begin(); + for (internal::WorkerPoolTask::Vector::const_iterator it = + completed_raster_tasks_.begin(); it != completed_raster_tasks_.end(); ++it) { internal::WorkerPoolTask* task = it->get(); @@ -260,8 +273,8 @@ SkCanvas* PixelBufferRasterWorkerPool::AcquireCanvasForRaster( DCHECK(it != raster_task_states_.end()); DCHECK(!it->resource); it->resource = resource; - resource_provider()->AcquirePixelRasterBuffer(resource->id()); - return resource_provider()->MapPixelRasterBuffer(resource->id()); + resource_provider_->AcquirePixelRasterBuffer(resource->id()); + return resource_provider_->MapPixelRasterBuffer(resource->id()); } void PixelBufferRasterWorkerPool::ReleaseCanvasForRaster( @@ -273,10 +286,12 @@ void PixelBufferRasterWorkerPool::ReleaseCanvasForRaster( RasterTaskState::TaskComparator(task)); DCHECK(it != raster_task_states_.end()); DCHECK(it->resource == resource); - resource_provider()->ReleasePixelRasterBuffer(resource->id()); + resource_provider_->ReleasePixelRasterBuffer(resource->id()); } -void PixelBufferRasterWorkerPool::OnRasterTasksFinished() { +void PixelBufferRasterWorkerPool::OnRasterFinished() { + TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::OnRasterFinished"); + // |should_notify_client_if_no_tasks_are_pending_| can be set to false as // a result of a scheduled CheckForCompletedRasterTasks() call. No need to // perform another check in that case as we've already notified the client. @@ -291,7 +306,11 @@ void PixelBufferRasterWorkerPool::OnRasterTasksFinished() { CheckForCompletedRasterTasks(); } -void PixelBufferRasterWorkerPool::OnRasterTasksRequiredForActivationFinished() { +void PixelBufferRasterWorkerPool::OnRasterRequiredForActivationFinished() { + TRACE_EVENT0( + "cc", + "PixelBufferRasterWorkerPool::OnRasterRequiredForActivationFinished"); + // Analogous to OnRasterTasksFinished(), there's no need to call // CheckForCompletedRasterTasks() if the client has already been notified. if (!should_notify_client_if_no_tasks_required_for_activation_are_pending_) @@ -308,12 +327,12 @@ void PixelBufferRasterWorkerPool::FlushUploads() { if (!has_performed_uploads_since_last_flush_) return; - resource_provider()->ShallowFlushIfSupported(); + resource_provider_->ShallowFlushIfSupported(); has_performed_uploads_since_last_flush_ = false; } void PixelBufferRasterWorkerPool::CheckForCompletedUploads() { - TaskVector tasks_with_completed_uploads; + internal::WorkerPoolTask::Vector tasks_with_completed_uploads; // First check if any have completed. while (!raster_tasks_with_pending_upload_.empty()) { @@ -327,19 +346,19 @@ void PixelBufferRasterWorkerPool::CheckForCompletedUploads() { DCHECK_EQ(RasterTaskState::UPLOADING, it->type); // Uploads complete in the order they are issued. - if (!resource_provider()->DidSetPixelsComplete(it->resource->id())) + if (!resource_provider_->DidSetPixelsComplete(it->resource->id())) break; tasks_with_completed_uploads.push_back(task); raster_tasks_with_pending_upload_.pop_front(); } - DCHECK(client()); + DCHECK(client_); bool should_force_some_uploads_to_complete = - shutdown_ || client()->ShouldForceTasksRequiredForActivationToComplete(); + shutdown_ || client_->ShouldForceTasksRequiredForActivationToComplete(); if (should_force_some_uploads_to_complete) { - TaskVector tasks_with_uploads_to_force; + internal::WorkerPoolTask::Vector tasks_with_uploads_to_force; TaskDeque::iterator it = raster_tasks_with_pending_upload_.begin(); while (it != raster_tasks_with_pending_upload_.end()) { internal::WorkerPoolTask* task = it->get(); @@ -363,7 +382,8 @@ void PixelBufferRasterWorkerPool::CheckForCompletedUploads() { // Force uploads in reverse order. Since forcing can cause a wait on // all previous uploads, we would rather wait only once downstream. - for (TaskVector::reverse_iterator it = tasks_with_uploads_to_force.rbegin(); + for (internal::WorkerPoolTask::Vector::reverse_iterator it = + tasks_with_uploads_to_force.rbegin(); it != tasks_with_uploads_to_force.rend(); ++it) { internal::WorkerPoolTask* task = it->get(); @@ -374,14 +394,15 @@ void PixelBufferRasterWorkerPool::CheckForCompletedUploads() { DCHECK(state_it != raster_task_states_.end()); DCHECK(state_it->resource); - resource_provider()->ForceSetPixelsToComplete(state_it->resource->id()); + resource_provider_->ForceSetPixelsToComplete(state_it->resource->id()); has_performed_uploads_since_last_flush_ = true; } } // Release shared memory and move tasks with completed uploads // to |completed_raster_tasks_|. - for (TaskVector::const_iterator it = tasks_with_completed_uploads.begin(); + for (internal::WorkerPoolTask::Vector::const_iterator it = + tasks_with_completed_uploads.begin(); it != tasks_with_completed_uploads.end(); ++it) { internal::WorkerPoolTask* task = it->get(); @@ -419,10 +440,10 @@ void PixelBufferRasterWorkerPool::ScheduleCheckForCompletedRasterTasks() { if (check_for_completed_raster_tasks_pending_) return; - task_runner()->PostDelayedTask( + task_runner_->PostDelayedTask( FROM_HERE, base::Bind(&PixelBufferRasterWorkerPool::OnCheckForCompletedRasterTasks, - weak_factory_.GetWeakPtr()), + weak_ptr_factory_.GetWeakPtr()), delay); check_for_completed_raster_tasks_pending_ = true; } @@ -439,10 +460,10 @@ void PixelBufferRasterWorkerPool::OnCheckForCompletedRasterTasks() { // Post another delayed task if it is not yet time to check for completed // raster tasks. if (delay > base::TimeDelta()) { - task_runner()->PostDelayedTask( + task_runner_->PostDelayedTask( FROM_HERE, base::Bind(&PixelBufferRasterWorkerPool::OnCheckForCompletedRasterTasks, - weak_factory_.GetWeakPtr()), + weak_ptr_factory_.GetWeakPtr()), delay); return; } @@ -498,12 +519,12 @@ void PixelBufferRasterWorkerPool::CheckForCompletedRasterTasks() { // Generate client notifications. if (will_notify_client_that_no_tasks_required_for_activation_are_pending) { DCHECK(!HasPendingTasksRequiredForActivation()); - client()->DidFinishRunningTasksRequiredForActivation(); + client_->DidFinishRunningTasksRequiredForActivation(); } if (will_notify_client_that_no_tasks_are_pending) { TRACE_EVENT_ASYNC_END0("cc", "ScheduledTasks", this); DCHECK(!HasPendingTasksRequiredForActivation()); - client()->DidFinishRunningTasks(); + client_->DidFinishRunningTasks(); } } @@ -580,13 +601,16 @@ void PixelBufferRasterWorkerPool::ScheduleMoreTasks() { state.type == RasterTaskState::SCHEDULED); state.type = RasterTaskState::SCHEDULED; - InsertNodeForRasterTask(&graph_, task, task->dependencies(), priority++); + InsertNodesForRasterTask(&graph_, task, task->dependencies(), priority++); tasks.container().push_back(task); if (item.required_for_activation) tasks_required_for_activation.container().push_back(task); } + // Cancel existing OnRasterFinished callbacks. + raster_finished_weak_ptr_factory_.InvalidateWeakPtrs(); + scoped_refptr<internal::WorkerPoolTask> new_raster_required_for_activation_finished_task; @@ -601,7 +625,11 @@ void PixelBufferRasterWorkerPool::ScheduleMoreTasks() { should_notify_client_if_no_tasks_required_for_activation_are_pending_) { new_raster_required_for_activation_finished_task = CreateRasterRequiredForActivationFinishedTask( - raster_tasks_.required_for_activation_count); + raster_tasks_.required_for_activation_count, + task_runner_.get(), + base::Bind(&PixelBufferRasterWorkerPool:: + OnRasterRequiredForActivationFinished, + raster_finished_weak_ptr_factory_.GetWeakPtr())); raster_required_for_activation_finished_task_pending_ = true; InsertNodeForTask(&graph_, new_raster_required_for_activation_finished_task.get(), @@ -624,7 +652,10 @@ void PixelBufferRasterWorkerPool::ScheduleMoreTasks() { // and throttling is not preventing all pending tasks from being scheduled. if (!did_throttle_raster_tasks && should_notify_client_if_no_tasks_are_pending_) { - new_raster_finished_task = CreateRasterFinishedTask(); + new_raster_finished_task = CreateRasterFinishedTask( + task_runner_.get(), + base::Bind(&PixelBufferRasterWorkerPool::OnRasterFinished, + raster_finished_weak_ptr_factory_.GetWeakPtr())); raster_finished_task_pending_ = true; InsertNodeForTask(&graph_, new_raster_finished_task.get(), @@ -639,13 +670,14 @@ void PixelBufferRasterWorkerPool::ScheduleMoreTasks() { } } - SetTaskGraph(&graph_); + ScheduleTasksOnOriginThread(this, &graph_); + task_graph_runner_->ScheduleTasks(namespace_token_, &graph_); scheduled_raster_task_count_ = scheduled_raster_task_count; - set_raster_finished_task(new_raster_finished_task); - set_raster_required_for_activation_finished_task( - new_raster_required_for_activation_finished_task); + raster_finished_task_ = new_raster_finished_task; + raster_required_for_activation_finished_task_ = + new_raster_required_for_activation_finished_task; } unsigned PixelBufferRasterWorkerPool::PendingRasterTaskCount() const { @@ -675,7 +707,11 @@ const char* PixelBufferRasterWorkerPool::StateName() const { } void PixelBufferRasterWorkerPool::CheckForCompletedWorkerPoolTasks() { - CollectCompletedWorkerPoolTasks(&completed_tasks_); + TRACE_EVENT0("cc", + "PixelBufferRasterWorkerPool::CheckForCompletedWorkerPoolTasks"); + + task_graph_runner_->CollectCompletedTasks(namespace_token_, + &completed_tasks_); for (internal::Task::Vector::const_iterator it = completed_tasks_.begin(); it != completed_tasks_.end(); ++it) { @@ -701,7 +737,7 @@ void PixelBufferRasterWorkerPool::CheckForCompletedWorkerPoolTasks() { // Balanced with MapPixelRasterBuffer() call in AcquireCanvasForRaster(). bool content_has_changed = - resource_provider()->UnmapPixelRasterBuffer(state.resource->id()); + resource_provider_->UnmapPixelRasterBuffer(state.resource->id()); // |content_has_changed| can be false as result of task being canceled or // task implementation deciding not to modify bitmap (ie. analysis of raster @@ -740,7 +776,7 @@ void PixelBufferRasterWorkerPool::CheckForCompletedWorkerPoolTasks() { DCHECK(task->HasFinishedRunning()); - resource_provider()->BeginSetPixels(state.resource->id()); + resource_provider_->BeginSetPixels(state.resource->id()); has_performed_uploads_since_last_flush_ = true; bytes_pending_upload_ += state.resource->bytes(); diff --git a/cc/resources/pixel_buffer_raster_worker_pool.h b/cc/resources/pixel_buffer_raster_worker_pool.h index 884213c..eb8fe51 100644 --- a/cc/resources/pixel_buffer_raster_worker_pool.h +++ b/cc/resources/pixel_buffer_raster_worker_pool.h @@ -5,23 +5,29 @@ #ifndef CC_RESOURCES_PIXEL_BUFFER_RASTER_WORKER_POOL_H_ #define CC_RESOURCES_PIXEL_BUFFER_RASTER_WORKER_POOL_H_ +#include <deque> #include <vector> +#include "base/memory/weak_ptr.h" #include "base/values.h" #include "cc/resources/raster_worker_pool.h" namespace cc { +class ResourceProvider; -class CC_EXPORT PixelBufferRasterWorkerPool : public RasterWorkerPool { +class CC_EXPORT PixelBufferRasterWorkerPool + : public RasterWorkerPool, + public internal::WorkerPoolTaskClient { public: virtual ~PixelBufferRasterWorkerPool(); - static scoped_ptr<RasterWorkerPool> Create( + static scoped_ptr<PixelBufferRasterWorkerPool> Create( base::SequencedTaskRunner* task_runner, ResourceProvider* resource_provider, size_t max_transfer_buffer_usage_bytes); // Overridden from RasterWorkerPool: + virtual void SetClient(RasterWorkerPoolClient* client) OVERRIDE; virtual void Shutdown() OVERRIDE; virtual void ScheduleTasks(RasterTaskQueue* queue) OVERRIDE; virtual unsigned GetResourceTarget() const OVERRIDE; @@ -70,10 +76,10 @@ class CC_EXPORT PixelBufferRasterWorkerPool : public RasterWorkerPool { bool required_for_activation; }; - // Overridden from RasterWorkerPool: - virtual void OnRasterTasksFinished() OVERRIDE; - virtual void OnRasterTasksRequiredForActivationFinished() OVERRIDE; + typedef std::deque<scoped_refptr<internal::WorkerPoolTask> > TaskDeque; + void OnRasterFinished(); + void OnRasterRequiredForActivationFinished(); void FlushUploads(); void CheckForCompletedUploads(); void ScheduleCheckForCompletedRasterTasks(); @@ -89,13 +95,19 @@ class CC_EXPORT PixelBufferRasterWorkerPool : public RasterWorkerPool { scoped_ptr<base::Value> StateAsValue() const; scoped_ptr<base::Value> ThrottleStateAsValue() const; + scoped_refptr<base::SequencedTaskRunner> task_runner_; + internal::TaskGraphRunner* task_graph_runner_; + const internal::NamespaceToken namespace_token_; + RasterWorkerPoolClient* client_; + ResourceProvider* resource_provider_; + bool shutdown_; RasterTaskQueue raster_tasks_; RasterTaskState::Vector raster_task_states_; TaskDeque raster_tasks_with_pending_upload_; - TaskVector completed_raster_tasks_; - TaskVector completed_image_decode_tasks_; + internal::WorkerPoolTask::Vector completed_raster_tasks_; + internal::WorkerPoolTask::Vector completed_image_decode_tasks_; size_t scheduled_raster_task_count_; size_t raster_tasks_required_for_activation_count_; @@ -110,12 +122,19 @@ class CC_EXPORT PixelBufferRasterWorkerPool : public RasterWorkerPool { bool raster_finished_task_pending_; bool raster_required_for_activation_finished_task_pending_; + base::WeakPtrFactory<PixelBufferRasterWorkerPool> + raster_finished_weak_ptr_factory_; + + scoped_refptr<internal::WorkerPoolTask> raster_finished_task_; + scoped_refptr<internal::WorkerPoolTask> + raster_required_for_activation_finished_task_; + // Task graph used when scheduling tasks and vector used to gather // completed tasks. internal::TaskGraph graph_; internal::Task::Vector completed_tasks_; - base::WeakPtrFactory<PixelBufferRasterWorkerPool> weak_factory_; + base::WeakPtrFactory<PixelBufferRasterWorkerPool> weak_ptr_factory_; DISALLOW_COPY_AND_ASSIGN(PixelBufferRasterWorkerPool); }; diff --git a/cc/resources/raster_worker_pool.cc b/cc/resources/raster_worker_pool.cc index 6a807e6..0db46fc 100644 --- a/cc/resources/raster_worker_pool.cc +++ b/cc/resources/raster_worker_pool.cc @@ -87,11 +87,9 @@ int g_num_raster_threads = 0; class RasterFinishedWorkerPoolTaskImpl : public internal::WorkerPoolTask { public: - typedef base::Callback<void(const internal::WorkerPoolTask* source)> Callback; - explicit RasterFinishedWorkerPoolTaskImpl( base::SequencedTaskRunner* task_runner, - const Callback& on_raster_finished_callback) + const base::Closure& on_raster_finished_callback) : task_runner_(task_runner), on_raster_finished_callback_(on_raster_finished_callback) {} @@ -116,20 +114,12 @@ class RasterFinishedWorkerPoolTaskImpl : public internal::WorkerPoolTask { virtual ~RasterFinishedWorkerPoolTaskImpl() {} void RasterFinished() { - task_runner_->PostTask( - FROM_HERE, - base::Bind( - &RasterFinishedWorkerPoolTaskImpl::OnRasterFinishedOnOriginThread, - this)); + task_runner_->PostTask(FROM_HERE, on_raster_finished_callback_); } private: - void OnRasterFinishedOnOriginThread() const { - on_raster_finished_callback_.Run(this); - } - scoped_refptr<base::SequencedTaskRunner> task_runner_; - const Callback on_raster_finished_callback_; + const base::Closure on_raster_finished_callback_; DISALLOW_COPY_AND_ASSIGN(RasterFinishedWorkerPoolTaskImpl); }; @@ -139,7 +129,7 @@ class RasterRequiredForActivationFinishedWorkerPoolTaskImpl public: RasterRequiredForActivationFinishedWorkerPoolTaskImpl( base::SequencedTaskRunner* task_runner, - const Callback& on_raster_finished_callback, + const base::Closure& on_raster_finished_callback, size_t tasks_required_for_activation_count) : RasterFinishedWorkerPoolTaskImpl(task_runner, on_raster_finished_callback), @@ -261,20 +251,6 @@ unsigned RasterWorkerPool::kRasterRequiredForActivationFinishedTaskPriority = 1u; unsigned RasterWorkerPool::kRasterTaskPriorityBase = 3u; -RasterWorkerPool::RasterWorkerPool(base::SequencedTaskRunner* task_runner, - internal::TaskGraphRunner* task_graph_runner, - ResourceProvider* resource_provider) - : task_runner_(task_runner), - task_graph_runner_(task_graph_runner), - client_(NULL), - resource_provider_(resource_provider), - weak_ptr_factory_(this) { - if (task_graph_runner_) - namespace_token_ = task_graph_runner_->GetNamespaceToken(); -} - -RasterWorkerPool::~RasterWorkerPool() {} - // static void RasterWorkerPool::SetNumRasterThreads(int num_threads) { DCHECK_LT(0, num_threads); @@ -301,26 +277,34 @@ size_t RasterWorkerPool::GetPictureCloneIndexForCurrentThread() { return g_task_graph_runner.Pointer()->GetPictureCloneIndexForCurrentThread(); } -void RasterWorkerPool::SetClient(RasterWorkerPoolClient* client) { - client_ = client; +// static +scoped_refptr<internal::WorkerPoolTask> +RasterWorkerPool::CreateRasterFinishedTask( + base::SequencedTaskRunner* task_runner, + const base::Closure& on_raster_finished_callback) { + return make_scoped_refptr(new RasterFinishedWorkerPoolTaskImpl( + task_runner, on_raster_finished_callback)); } -void RasterWorkerPool::Shutdown() { - TRACE_EVENT0("cc", "RasterWorkerPool::Shutdown"); - - if (task_graph_runner_) { - internal::TaskGraph empty; - task_graph_runner_->ScheduleTasks(namespace_token_, &empty); - task_graph_runner_->WaitForTasksToFinishRunning(namespace_token_); - } - - weak_ptr_factory_.InvalidateWeakPtrs(); +// static +scoped_refptr<internal::WorkerPoolTask> +RasterWorkerPool::CreateRasterRequiredForActivationFinishedTask( + size_t tasks_required_for_activation_count, + base::SequencedTaskRunner* task_runner, + const base::Closure& on_raster_finished_callback) { + return make_scoped_refptr( + new RasterRequiredForActivationFinishedWorkerPoolTaskImpl( + task_runner, + on_raster_finished_callback, + tasks_required_for_activation_count)); } -void RasterWorkerPool::SetTaskGraph(internal::TaskGraph* graph) { - TRACE_EVENT0("cc", "RasterWorkerPool::SetTaskGraph"); +// static +void RasterWorkerPool::ScheduleTasksOnOriginThread( + internal::WorkerPoolTaskClient* client, + internal::TaskGraph* graph) { + TRACE_EVENT0("cc", "RasterWorkerPool::ScheduleTasksOnOriginThread"); - DCHECK(task_graph_runner_); for (internal::TaskGraph::Node::Vector::iterator it = graph->nodes.begin(); it != graph->nodes.end(); ++it) { @@ -330,74 +314,10 @@ void RasterWorkerPool::SetTaskGraph(internal::TaskGraph* graph) { if (!task->HasBeenScheduled()) { task->WillSchedule(); - task->ScheduleOnOriginThread(this); + task->ScheduleOnOriginThread(client); task->DidSchedule(); } } - - task_graph_runner_->ScheduleTasks(namespace_token_, graph); -} - -void RasterWorkerPool::CollectCompletedWorkerPoolTasks( - internal::Task::Vector* completed_tasks) { - DCHECK(task_graph_runner_); - task_graph_runner_->CollectCompletedTasks(namespace_token_, completed_tasks); -} - -scoped_refptr<internal::WorkerPoolTask> -RasterWorkerPool::CreateRasterFinishedTask() { - return make_scoped_refptr(new RasterFinishedWorkerPoolTaskImpl( - task_runner_, - base::Bind(&RasterWorkerPool::OnRasterFinished, - weak_ptr_factory_.GetWeakPtr()))); -} - -scoped_refptr<internal::WorkerPoolTask> -RasterWorkerPool::CreateRasterRequiredForActivationFinishedTask( - size_t tasks_required_for_activation_count) { - return make_scoped_refptr( - new RasterRequiredForActivationFinishedWorkerPoolTaskImpl( - task_runner_, - base::Bind(&RasterWorkerPool::OnRasterRequiredForActivationFinished, - weak_ptr_factory_.GetWeakPtr()), - tasks_required_for_activation_count)); -} - -void RasterWorkerPool::RunTaskOnOriginThread(internal::WorkerPoolTask* task) { - task->WillSchedule(); - task->ScheduleOnOriginThread(this); - task->DidSchedule(); - - task->WillRun(); - task->RunOnOriginThread(); - task->DidRun(); - - task->WillComplete(); - task->CompleteOnOriginThread(this); - task->DidComplete(); -} - -void RasterWorkerPool::OnRasterFinished( - const internal::WorkerPoolTask* source) { - TRACE_EVENT0("cc", "RasterWorkerPool::OnRasterFinished"); - - // Early out if current |raster_finished_task_| is not the source. - if (source != raster_finished_task_.get()) - return; - - OnRasterTasksFinished(); -} - -void RasterWorkerPool::OnRasterRequiredForActivationFinished( - const internal::WorkerPoolTask* source) { - TRACE_EVENT0("cc", "RasterWorkerPool::OnRasterRequiredForActivationFinished"); - - // Early out if current |raster_required_for_activation_finished_task_| - // is not the source. - if (source != raster_required_for_activation_finished_task_.get()) - return; - - OnRasterTasksRequiredForActivationFinished(); } // static @@ -414,7 +334,7 @@ void RasterWorkerPool::InsertNodeForTask(internal::TaskGraph* graph, } // static -void RasterWorkerPool::InsertNodeForRasterTask( +void RasterWorkerPool::InsertNodesForRasterTask( internal::TaskGraph* graph, internal::WorkerPoolTask* raster_task, const internal::WorkerPoolTask::Vector& decode_tasks, diff --git a/cc/resources/raster_worker_pool.h b/cc/resources/raster_worker_pool.h index e257e07..059c77e 100644 --- a/cc/resources/raster_worker_pool.h +++ b/cc/resources/raster_worker_pool.h @@ -5,10 +5,9 @@ #ifndef CC_RESOURCES_RASTER_WORKER_POOL_H_ #define CC_RESOURCES_RASTER_WORKER_POOL_H_ -#include <deque> #include <vector> -#include "base/memory/weak_ptr.h" +#include "base/callback.h" #include "cc/resources/resource_format.h" #include "cc/resources/task_graph_runner.h" @@ -20,7 +19,6 @@ class SequencedTaskRunner; namespace cc { class Resource; -class ResourceProvider; namespace internal { class WorkerPoolTask; @@ -126,38 +124,88 @@ struct CC_EXPORT RasterTaskQueue { size_t required_for_activation_count; }; -// A worker thread pool that runs raster tasks. -class CC_EXPORT RasterWorkerPool : public internal::WorkerPoolTaskClient { +// This interface can be used to schedule and run raster tasks. The client will +// be notified asynchronously when the set of tasks marked as "required for +// activation" have finished running and when all scheduled tasks have finished +// running. The client can call CheckForCompletedTasks() at any time to dispatch +// pending completion callbacks for all tasks that have finished running. +class CC_EXPORT RasterWorkerPool { public: - virtual ~RasterWorkerPool(); + static unsigned kOnDemandRasterTaskPriority; + static unsigned kBenchmarkRasterTaskPriority; + static unsigned kRasterFinishedTaskPriority; + static unsigned kRasterRequiredForActivationFinishedTaskPriority; + static unsigned kRasterTaskPriorityBase; + // Set the number of threads to use for the global TaskGraphRunner instance. + // This can only be called once and must be called prior to + // GetNumRasterThreads(). static void SetNumRasterThreads(int num_threads); + + // Returns the number of threads used for the global TaskGraphRunner instance. static int GetNumRasterThreads(); + // Returns a pointer to the global TaskGraphRunner instance. static internal::TaskGraphRunner* GetTaskGraphRunner(); + // Returns a unique clone index for the current thread. Guaranteed to be a + // value between 0 and GetNumRasterThreads() - 1. static size_t GetPictureCloneIndexForCurrentThread(); - static unsigned kOnDemandRasterTaskPriority; - static unsigned kBenchmarkRasterTaskPriority; - static unsigned kRasterFinishedTaskPriority; - static unsigned kRasterRequiredForActivationFinishedTaskPriority; - static unsigned kRasterTaskPriorityBase; + // Utility function that can be used by implementations to create a "raster + // finished" task that posts |callback| to |task_runner| when run. + static scoped_refptr<internal::WorkerPoolTask> CreateRasterFinishedTask( + base::SequencedTaskRunner* task_runner, + const base::Closure& callback); - void SetClient(RasterWorkerPoolClient* client); + // Utility function that can be used by implementations to create a "raster + // required for activation finished" task that posts |callback| to + // |task_runner| when run. + static scoped_refptr<internal::WorkerPoolTask> + CreateRasterRequiredForActivationFinishedTask( + size_t tasks_required_for_activation_count, + base::SequencedTaskRunner* task_runner, + const base::Closure& callback); + + // Utility function that can be used by implementations to call + // ::ScheduleOnOriginThread() for each task in |graph|. + static void ScheduleTasksOnOriginThread( + internal::WorkerPoolTaskClient* client, + internal::TaskGraph* graph); + + // Utility function that can be used by implementations to build a task graph. + // Inserts a node that represents |task| in |graph|. See TaskGraph definition + // for valid |priority| values. + static void InsertNodeForTask(internal::TaskGraph* graph, + internal::WorkerPoolTask* task, + unsigned priority, + size_t dependencies); - // Tells the worker pool to shutdown after canceling all previously - // scheduled tasks. Reply callbacks are still guaranteed to run. - virtual void Shutdown(); + // Utility function that can be used by implementations to build a task graph. + // Inserts nodes that represent |task| and all its image decode dependencies + // in |graph|. + static void InsertNodesForRasterTask( + internal::TaskGraph* graph, + internal::WorkerPoolTask* task, + const internal::WorkerPoolTask::Vector& decode_tasks, + unsigned priority); + + // Set the client instance to be notified when finished running tasks. + virtual void SetClient(RasterWorkerPoolClient* client) = 0; + + // Tells the worker pool to shutdown after canceling all previously scheduled + // tasks. Reply callbacks are still guaranteed to run when + // CheckForCompletedTasks() is called. + virtual void Shutdown() = 0; // Schedule running of raster tasks in |queue| and all dependencies. - // Previously scheduled tasks that are no longer needed to run - // raster tasks in |queue| will be canceled unless already running. - // Once scheduled, reply callbacks are guaranteed to run for all tasks - // even if they later get canceled by another call to ScheduleTasks(). + // Previously scheduled tasks that are not in |queue| will be canceled unless + // already running. Once scheduled, reply callbacks are guaranteed to run for + // all tasks even if they later get canceled by another call to + // ScheduleTasks(). virtual void ScheduleTasks(RasterTaskQueue* queue) = 0; - // Force a check for completed tasks. + // Check for completed tasks and dispatch reply callbacks. virtual void CheckForCompletedTasks() = 0; // Returns the target that needs to be used for raster task resources. @@ -167,75 +215,7 @@ class CC_EXPORT RasterWorkerPool : public internal::WorkerPoolTaskClient { virtual ResourceFormat GetResourceFormat() const = 0; protected: - typedef std::vector<scoped_refptr<internal::WorkerPoolTask> > TaskVector; - typedef std::deque<scoped_refptr<internal::WorkerPoolTask> > TaskDeque; - typedef std::vector<scoped_refptr<internal::RasterWorkerPoolTask> > - RasterTaskVector; - - RasterWorkerPool(base::SequencedTaskRunner* task_runner, - internal::TaskGraphRunner* task_graph_runner, - ResourceProvider* resource_provider); - - virtual void OnRasterTasksFinished() = 0; - virtual void OnRasterTasksRequiredForActivationFinished() = 0; - - void SetTaskGraph(internal::TaskGraph* graph); - void CollectCompletedWorkerPoolTasks(internal::Task::Vector* completed_tasks); - - base::SequencedTaskRunner* task_runner() const { return task_runner_; } - RasterWorkerPoolClient* client() const { return client_; } - ResourceProvider* resource_provider() const { return resource_provider_; } - - void set_raster_finished_task( - internal::WorkerPoolTask* raster_finished_task) { - raster_finished_task_ = raster_finished_task; - } - internal::WorkerPoolTask* raster_finished_task() const { - return raster_finished_task_.get(); - } - void set_raster_required_for_activation_finished_task( - internal::WorkerPoolTask* raster_required_for_activation_finished_task) { - raster_required_for_activation_finished_task_ = - raster_required_for_activation_finished_task; - } - internal::WorkerPoolTask* raster_required_for_activation_finished_task() - const { - return raster_required_for_activation_finished_task_.get(); - } - - scoped_refptr<internal::WorkerPoolTask> CreateRasterFinishedTask(); - scoped_refptr<internal::WorkerPoolTask> - CreateRasterRequiredForActivationFinishedTask( - size_t tasks_required_for_activation_count); - - void RunTaskOnOriginThread(internal::WorkerPoolTask* task); - - static void InsertNodeForTask(internal::TaskGraph* graph, - internal::WorkerPoolTask* task, - unsigned priority, - size_t dependencies); - - static void InsertNodeForRasterTask( - internal::TaskGraph* graph, - internal::WorkerPoolTask* task, - const internal::WorkerPoolTask::Vector& decode_tasks, - unsigned priority); - - private: - void OnRasterFinished(const internal::WorkerPoolTask* source); - void OnRasterRequiredForActivationFinished( - const internal::WorkerPoolTask* source); - - scoped_refptr<base::SequencedTaskRunner> task_runner_; - internal::TaskGraphRunner* task_graph_runner_; - internal::NamespaceToken namespace_token_; - RasterWorkerPoolClient* client_; - ResourceProvider* resource_provider_; - - scoped_refptr<internal::WorkerPoolTask> raster_finished_task_; - scoped_refptr<internal::WorkerPoolTask> - raster_required_for_activation_finished_task_; - base::WeakPtrFactory<RasterWorkerPool> weak_ptr_factory_; + virtual ~RasterWorkerPool() {} }; } // namespace cc diff --git a/cc/resources/raster_worker_pool_perftest.cc b/cc/resources/raster_worker_pool_perftest.cc index b4533bc..de4cac4 100644 --- a/cc/resources/raster_worker_pool_perftest.cc +++ b/cc/resources/raster_worker_pool_perftest.cc @@ -180,6 +180,7 @@ class RasterWorkerPoolPerfTestBase { RasterWorkerPoolPerfTestBase() : context_provider_(make_scoped_refptr(new PerfContextProvider)), + task_graph_runner_(new internal::TaskGraphRunner), timer_(kWarmupRuns, base::TimeDelta::FromMilliseconds(kTimeLimitMillis), kTimeCheckInterval) { @@ -191,8 +192,14 @@ class RasterWorkerPoolPerfTestBase { ResourceProvider::Create( output_surface_.get(), shared_bitmap_manager_.get(), 0, false, 1) .Pass(); + pixel_buffer_raster_worker_pool_.reset( + new PerfPixelBufferRasterWorkerPoolImpl(task_graph_runner_.get(), + resource_provider_.get())); + image_raster_worker_pool_.reset(new PerfImageRasterWorkerPoolImpl( + task_graph_runner_.get(), resource_provider_.get())); + direct_raster_worker_pool_.reset(new PerfDirectRasterWorkerPoolImpl( + resource_provider_.get(), context_provider_)); } - virtual ~RasterWorkerPoolPerfTestBase() { resource_provider_.reset(); } void CreateImageDecodeTasks( unsigned num_image_decode_tasks, @@ -234,6 +241,10 @@ class RasterWorkerPoolPerfTestBase { scoped_ptr<FakeOutputSurface> output_surface_; scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; scoped_ptr<ResourceProvider> resource_provider_; + scoped_ptr<internal::TaskGraphRunner> task_graph_runner_; + scoped_ptr<PixelBufferRasterWorkerPool> pixel_buffer_raster_worker_pool_; + scoped_ptr<ImageRasterWorkerPool> image_raster_worker_pool_; + scoped_ptr<DirectRasterWorkerPool> direct_raster_worker_pool_; LapTimer timer_; }; @@ -242,20 +253,16 @@ class RasterWorkerPoolPerfTest public testing::TestWithParam<RasterWorkerPoolType>, public RasterWorkerPoolClient { public: - RasterWorkerPoolPerfTest() - : task_graph_runner_(new internal::TaskGraphRunner) { + RasterWorkerPoolPerfTest() : raster_worker_pool_(NULL) { switch (GetParam()) { case RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER: - raster_worker_pool_.reset(new PerfPixelBufferRasterWorkerPoolImpl( - task_graph_runner_.get(), resource_provider_.get())); + raster_worker_pool_ = pixel_buffer_raster_worker_pool_.get(); break; case RASTER_WORKER_POOL_TYPE_IMAGE: - raster_worker_pool_.reset(new PerfImageRasterWorkerPoolImpl( - task_graph_runner_.get(), resource_provider_.get())); + raster_worker_pool_ = image_raster_worker_pool_.get(); break; case RASTER_WORKER_POOL_TYPE_DIRECT: - raster_worker_pool_.reset(new PerfDirectRasterWorkerPoolImpl( - resource_provider_.get(), context_provider_)); + raster_worker_pool_ = direct_raster_worker_pool_.get(); break; } @@ -401,8 +408,7 @@ class RasterWorkerPoolPerfTest return std::string(); } - scoped_ptr<internal::TaskGraphRunner> task_graph_runner_; - scoped_ptr<RasterWorkerPool> raster_worker_pool_; + RasterWorkerPool* raster_worker_pool_; }; TEST_P(RasterWorkerPoolPerfTest, ScheduleTasks) { diff --git a/cc/resources/raster_worker_pool_unittest.cc b/cc/resources/raster_worker_pool_unittest.cc index 8728111..a7e18ff 100644 --- a/cc/resources/raster_worker_pool_unittest.cc +++ b/cc/resources/raster_worker_pool_unittest.cc @@ -135,25 +135,28 @@ class RasterWorkerPoolTest ResourceProvider::Create( output_surface_.get(), shared_bitmap_manager_.get(), 0, false, 1) .Pass(); + pixel_buffer_raster_worker_pool_ = PixelBufferRasterWorkerPool::Create( + base::MessageLoopProxy::current().get(), + resource_provider_.get(), + std::numeric_limits<size_t>::max()); + image_raster_worker_pool_ = + ImageRasterWorkerPool::Create(base::MessageLoopProxy::current().get(), + resource_provider_.get(), + GL_TEXTURE_2D); + direct_raster_worker_pool_ = + DirectRasterWorkerPool::Create(base::MessageLoopProxy::current().get(), + resource_provider_.get(), + context_provider_.get()); switch (GetParam()) { case RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER: - raster_worker_pool_ = PixelBufferRasterWorkerPool::Create( - base::MessageLoopProxy::current().get(), - resource_provider_.get(), - std::numeric_limits<size_t>::max()); + raster_worker_pool_ = pixel_buffer_raster_worker_pool_.get(); break; case RASTER_WORKER_POOL_TYPE_IMAGE: - raster_worker_pool_ = ImageRasterWorkerPool::Create( - base::MessageLoopProxy::current().get(), - resource_provider_.get(), - GL_TEXTURE_2D); + raster_worker_pool_ = image_raster_worker_pool_.get(); break; case RASTER_WORKER_POOL_TYPE_DIRECT: - raster_worker_pool_ = DirectRasterWorkerPool::Create( - base::MessageLoopProxy::current().get(), - resource_provider_.get(), - context_provider_.get()); + raster_worker_pool_ = direct_raster_worker_pool_.get(); break; } @@ -272,7 +275,10 @@ class RasterWorkerPoolTest scoped_ptr<FakeOutputSurface> output_surface_; scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; scoped_ptr<ResourceProvider> resource_provider_; - scoped_ptr<RasterWorkerPool> raster_worker_pool_; + scoped_ptr<PixelBufferRasterWorkerPool> pixel_buffer_raster_worker_pool_; + scoped_ptr<ImageRasterWorkerPool> image_raster_worker_pool_; + scoped_ptr<DirectRasterWorkerPool> direct_raster_worker_pool_; + RasterWorkerPool* raster_worker_pool_; base::CancelableClosure timeout_; int timeout_seconds_; bool timed_out_; diff --git a/cc/resources/task_graph_runner.h b/cc/resources/task_graph_runner.h index fe605d1..f1b4c74 100644 --- a/cc/resources/task_graph_runner.h +++ b/cc/resources/task_graph_runner.h @@ -35,9 +35,10 @@ class CC_EXPORT Task : public base::RefCountedThreadSafe<Task> { bool did_run_; }; -// Dependencies are represented as edges in a task graph. Each graph node -// is assigned a priority and a run count that matches the number of -// dependencies. +// Dependencies are represented as edges in a task graph. Each graph node is +// assigned a priority and a run count that matches the number of dependencies. +// Priority range from 0 (most favorable scheduling) to UINT_MAX (least +// favorable). struct CC_EXPORT TaskGraph { struct Node { class TaskComparator { diff --git a/cc/resources/tile_manager.cc b/cc/resources/tile_manager.cc index 405aee0..76cdb96 100644 --- a/cc/resources/tile_manager.cc +++ b/cc/resources/tile_manager.cc @@ -15,9 +15,6 @@ #include "cc/debug/devtools_instrumentation.h" #include "cc/debug/traced_value.h" #include "cc/layers/picture_layer_impl.h" -#include "cc/resources/direct_raster_worker_pool.h" -#include "cc/resources/image_raster_worker_pool.h" -#include "cc/resources/pixel_buffer_raster_worker_pool.h" #include "cc/resources/raster_worker_pool_delegate.h" #include "cc/resources/tile.h" #include "skia/ext/paint_simplifier.h" @@ -400,52 +397,34 @@ scoped_ptr<base::Value> RasterTaskCompletionStatsAsValue( // static scoped_ptr<TileManager> TileManager::Create( TileManagerClient* client, - base::SequencedTaskRunner* task_runner, ResourceProvider* resource_provider, - ContextProvider* context_provider, - RenderingStatsInstrumentation* rendering_stats_instrumentation, - bool use_map_image, - bool use_rasterize_on_demand, - size_t max_transfer_buffer_usage_bytes, + RasterWorkerPool* raster_worker_pool, + RasterWorkerPool* gpu_raster_worker_pool, size_t max_raster_usage_bytes, - unsigned map_image_texture_target) { - return make_scoped_ptr(new TileManager( - client, - task_runner, - resource_provider, - context_provider, - use_map_image - ? ImageRasterWorkerPool::Create( - task_runner, resource_provider, map_image_texture_target) - : PixelBufferRasterWorkerPool::Create( - task_runner, - resource_provider, - max_transfer_buffer_usage_bytes), - DirectRasterWorkerPool::Create( - task_runner, resource_provider, context_provider), - max_raster_usage_bytes, - rendering_stats_instrumentation, - use_rasterize_on_demand)); + bool use_rasterize_on_demand, + RenderingStatsInstrumentation* rendering_stats_instrumentation) { + return make_scoped_ptr(new TileManager(client, + resource_provider, + raster_worker_pool, + gpu_raster_worker_pool, + max_raster_usage_bytes, + use_rasterize_on_demand, + rendering_stats_instrumentation)); } TileManager::TileManager( TileManagerClient* client, - base::SequencedTaskRunner* task_runner, ResourceProvider* resource_provider, - ContextProvider* context_provider, - scoped_ptr<RasterWorkerPool> raster_worker_pool, - scoped_ptr<RasterWorkerPool> direct_raster_worker_pool, + RasterWorkerPool* raster_worker_pool, + RasterWorkerPool* gpu_raster_worker_pool, size_t max_raster_usage_bytes, - RenderingStatsInstrumentation* rendering_stats_instrumentation, - bool use_rasterize_on_demand) + bool use_rasterize_on_demand, + RenderingStatsInstrumentation* rendering_stats_instrumentation) : client_(client), - context_provider_(context_provider), resource_pool_( ResourcePool::Create(resource_provider, raster_worker_pool->GetResourceTarget(), raster_worker_pool->GetResourceFormat())), - raster_worker_pool_(raster_worker_pool.Pass()), - direct_raster_worker_pool_(direct_raster_worker_pool.Pass()), prioritized_tiles_dirty_(false), all_tiles_that_need_to_be_rasterized_have_memory_(true), all_tiles_required_for_activation_have_memory_(true), @@ -458,10 +437,11 @@ TileManager::TileManager( rendering_stats_instrumentation_(rendering_stats_instrumentation), did_initialize_visible_tile_(false), did_check_for_completed_tasks_since_last_schedule_tasks_(true), - use_rasterize_on_demand_(use_rasterize_on_demand) { + use_rasterize_on_demand_(use_rasterize_on_demand), + resource_format_(raster_worker_pool->GetResourceFormat()) { RasterWorkerPool* raster_worker_pools[NUM_RASTER_WORKER_POOL_TYPES] = { - raster_worker_pool_.get(), // RASTER_WORKER_POOL_TYPE_DEFAULT - direct_raster_worker_pool_.get() // RASTER_WORKER_POOL_TYPE_DIRECT + raster_worker_pool, // RASTER_WORKER_POOL_TYPE_DEFAULT + gpu_raster_worker_pool, // RASTER_WORKER_POOL_TYPE_GPU }; raster_worker_pool_delegate_ = RasterWorkerPoolDelegate::Create( this, raster_worker_pools, arraysize(raster_worker_pools)); @@ -1090,7 +1070,7 @@ void TileManager::ScheduleTasks( tile_version.raster_task_ = CreateRasterTask(tile); size_t pool_type = tile->use_gpu_rasterization() - ? RASTER_WORKER_POOL_TYPE_DIRECT + ? RASTER_WORKER_POOL_TYPE_GPU : RASTER_WORKER_POOL_TYPE_DEFAULT; raster_queue_[pool_type].items.push_back(RasterTaskQueue::Item( diff --git a/cc/resources/tile_manager.h b/cc/resources/tile_manager.h index 94fe357..97b785a0 100644 --- a/cc/resources/tile_manager.h +++ b/cc/resources/tile_manager.h @@ -108,15 +108,12 @@ class CC_EXPORT TileManager : public RasterWorkerPoolClient, static scoped_ptr<TileManager> Create( TileManagerClient* client, - base::SequencedTaskRunner* task_runner, ResourceProvider* resource_provider, - ContextProvider* context_provider, - RenderingStatsInstrumentation* rendering_stats_instrumentation, - bool use_map_image, - bool use_rasterize_on_demand, - size_t max_transfer_buffer_usage_bytes, + RasterWorkerPool* raster_worker_pool, + RasterWorkerPool* gpu_raster_worker_pool, size_t max_raster_usage_bytes, - unsigned map_image_texture_target); + bool use_rasterize_on_demand, + RenderingStatsInstrumentation* rendering_stats_instrumentation); virtual ~TileManager(); void ManageTiles(const GlobalStateThatImpactsTilePriority& state); @@ -180,14 +177,12 @@ class CC_EXPORT TileManager : public RasterWorkerPoolClient, protected: TileManager(TileManagerClient* client, - base::SequencedTaskRunner* task_runner, ResourceProvider* resource_provider, - ContextProvider* context_provider, - scoped_ptr<RasterWorkerPool> raster_worker_pool, - scoped_ptr<RasterWorkerPool> direct_raster_worker_pool, + RasterWorkerPool* raster_worker_pool, + RasterWorkerPool* gpu_raster_worker_pool, size_t max_raster_usage_bytes, - RenderingStatsInstrumentation* rendering_stats_instrumentation, - bool use_rasterize_on_demand); + bool use_rasterize_on_demand, + RenderingStatsInstrumentation* rendering_stats_instrumentation); // Methods called by Tile friend class Tile; @@ -217,7 +212,7 @@ class CC_EXPORT TileManager : public RasterWorkerPoolClient, private: enum RasterWorkerPoolType { RASTER_WORKER_POOL_TYPE_DEFAULT, - RASTER_WORKER_POOL_TYPE_DIRECT, + RASTER_WORKER_POOL_TYPE_GPU, NUM_RASTER_WORKER_POOL_TYPES }; @@ -231,8 +226,7 @@ class CC_EXPORT TileManager : public RasterWorkerPoolClient, bool was_canceled); inline size_t BytesConsumedIfAllocated(const Tile* tile) const { - return Resource::MemorySizeBytes(tile->size(), - raster_worker_pool_->GetResourceFormat()); + return Resource::MemorySizeBytes(tile->size(), resource_format_); } void FreeResourceForTile(Tile* tile, RasterMode mode); @@ -246,10 +240,7 @@ class CC_EXPORT TileManager : public RasterWorkerPoolClient, void UpdatePrioritizedTileSetIfNeeded(); TileManagerClient* client_; - ContextProvider* context_provider_; scoped_ptr<ResourcePool> resource_pool_; - scoped_ptr<RasterWorkerPool> raster_worker_pool_; - scoped_ptr<RasterWorkerPool> direct_raster_worker_pool_; scoped_ptr<RasterWorkerPoolDelegate> raster_worker_pool_delegate_; GlobalStateThatImpactsTilePriority global_state_; @@ -291,6 +282,8 @@ class CC_EXPORT TileManager : public RasterWorkerPoolClient, bool use_rasterize_on_demand_; + ResourceFormat resource_format_; + // Queues used when scheduling raster tasks. RasterTaskQueue raster_queue_[NUM_RASTER_WORKER_POOL_TYPES]; diff --git a/cc/test/fake_tile_manager.cc b/cc/test/fake_tile_manager.cc index cf797f1..da365e7 100644 --- a/cc/test/fake_tile_manager.cc +++ b/cc/test/fake_tile_manager.cc @@ -7,17 +7,19 @@ #include <deque> #include <limits> +#include "base/lazy_instance.h" #include "cc/resources/raster_worker_pool.h" namespace cc { namespace { -class FakeRasterWorkerPool : public RasterWorkerPool { +class FakeRasterWorkerPool : public RasterWorkerPool, + public internal::WorkerPoolTaskClient { public: - FakeRasterWorkerPool() : RasterWorkerPool(NULL, NULL, NULL) {} - // Overridden from RasterWorkerPool: + virtual void SetClient(RasterWorkerPoolClient* client) OVERRIDE {} + virtual void Shutdown() OVERRIDE {} virtual void ScheduleTasks(RasterTaskQueue* queue) OVERRIDE { for (RasterTaskQueue::Item::Vector::const_iterator it = queue->items.begin(); @@ -33,17 +35,19 @@ class FakeRasterWorkerPool : public RasterWorkerPool { } } virtual void CheckForCompletedTasks() OVERRIDE { - while (!completed_tasks_.empty()) { - internal::WorkerPoolTask* task = completed_tasks_.front().get(); + for (internal::WorkerPoolTask::Vector::iterator it = + completed_tasks_.begin(); + it != completed_tasks_.end(); + ++it) { + internal::WorkerPoolTask* task = it->get(); task->WillComplete(); task->CompleteOnOriginThread(this); task->DidComplete(); task->RunReplyOnOriginThread(); - - completed_tasks_.pop_front(); } + completed_tasks_.clear(); } virtual GLenum GetResourceTarget() const OVERRIDE { return GL_TEXTURE_2D; @@ -61,63 +65,53 @@ class FakeRasterWorkerPool : public RasterWorkerPool { const Resource* resource) OVERRIDE {} private: - // Overridden from RasterWorkerPool: - virtual void OnRasterTasksFinished() OVERRIDE {} - virtual void OnRasterTasksRequiredForActivationFinished() OVERRIDE {} - - TaskDeque completed_tasks_; + internal::WorkerPoolTask::Vector completed_tasks_; }; +base::LazyInstance<FakeRasterWorkerPool> g_fake_raster_worker_pool = + LAZY_INSTANCE_INITIALIZER; } // namespace FakeTileManager::FakeTileManager(TileManagerClient* client) : TileManager(client, - base::MessageLoopProxy::current().get(), - NULL, NULL, - make_scoped_ptr<RasterWorkerPool>(new FakeRasterWorkerPool), - make_scoped_ptr<RasterWorkerPool>(new FakeRasterWorkerPool), + g_fake_raster_worker_pool.Pointer(), + g_fake_raster_worker_pool.Pointer(), std::numeric_limits<unsigned>::max(), - NULL, - true) {} + true, + NULL) {} FakeTileManager::FakeTileManager(TileManagerClient* client, ResourceProvider* resource_provider) : TileManager(client, - base::MessageLoopProxy::current().get(), resource_provider, - NULL, - make_scoped_ptr<RasterWorkerPool>(new FakeRasterWorkerPool), - make_scoped_ptr<RasterWorkerPool>(new FakeRasterWorkerPool), + g_fake_raster_worker_pool.Pointer(), + g_fake_raster_worker_pool.Pointer(), std::numeric_limits<unsigned>::max(), - NULL, - true) {} + true, + NULL) {} FakeTileManager::FakeTileManager(TileManagerClient* client, ResourceProvider* resource_provider, bool allow_on_demand_raster) : TileManager(client, - base::MessageLoopProxy::current().get(), resource_provider, - NULL, - make_scoped_ptr<RasterWorkerPool>(new FakeRasterWorkerPool), - make_scoped_ptr<RasterWorkerPool>(new FakeRasterWorkerPool), + g_fake_raster_worker_pool.Pointer(), + g_fake_raster_worker_pool.Pointer(), std::numeric_limits<unsigned>::max(), - NULL, - allow_on_demand_raster) {} + allow_on_demand_raster, + NULL) {} FakeTileManager::FakeTileManager(TileManagerClient* client, ResourceProvider* resource_provider, size_t raster_task_limit_bytes) : TileManager(client, - base::MessageLoopProxy::current().get(), resource_provider, - NULL, - make_scoped_ptr<RasterWorkerPool>(new FakeRasterWorkerPool), - make_scoped_ptr<RasterWorkerPool>(new FakeRasterWorkerPool), + g_fake_raster_worker_pool.Pointer(), + g_fake_raster_worker_pool.Pointer(), raster_task_limit_bytes, - NULL, - true) {} + true, + NULL) {} FakeTileManager::~FakeTileManager() {} diff --git a/cc/trees/layer_tree_host_impl.cc b/cc/trees/layer_tree_host_impl.cc index 0325d58..685cfb9 100644 --- a/cc/trees/layer_tree_host_impl.cc +++ b/cc/trees/layer_tree_host_impl.cc @@ -43,8 +43,11 @@ #include "cc/quads/shared_quad_state.h" #include "cc/quads/solid_color_draw_quad.h" #include "cc/quads/texture_draw_quad.h" +#include "cc/resources/direct_raster_worker_pool.h" +#include "cc/resources/image_raster_worker_pool.h" #include "cc/resources/memory_history.h" #include "cc/resources/picture_layer_tiling.h" +#include "cc/resources/pixel_buffer_raster_worker_pool.h" #include "cc/resources/prioritized_resource_manager.h" #include "cc/resources/texture_mailbox_deleter.h" #include "cc/resources/ui_resource_bitmap.h" @@ -302,6 +305,10 @@ LayerTreeHostImpl::~LayerTreeHostImpl() { recycle_tree_.reset(); pending_tree_.reset(); active_tree_.reset(); + tile_manager_.reset(); + image_raster_worker_pool_.reset(); + pixel_buffer_raster_worker_pool_.reset(); + direct_raster_worker_pool_.reset(); } void LayerTreeHostImpl::BeginMainFrameAborted(bool did_handle) { @@ -1783,17 +1790,31 @@ void LayerTreeHostImpl::CreateAndSetTileManager( DCHECK(settings_.impl_side_painting); DCHECK(resource_provider); DCHECK(proxy_->ImplThreadTaskRunner()); + + RasterWorkerPool* default_raster_worker_pool = NULL; + if (using_map_image) { + image_raster_worker_pool_ = ImageRasterWorkerPool::Create( + proxy_->ImplThreadTaskRunner(), + resource_provider, + GetMapImageTextureTarget(context_provider)); + default_raster_worker_pool = image_raster_worker_pool_.get(); + } else { + pixel_buffer_raster_worker_pool_ = PixelBufferRasterWorkerPool::Create( + proxy_->ImplThreadTaskRunner(), + resource_provider, + GetMaxTransferBufferUsageBytes(context_provider)); + default_raster_worker_pool = pixel_buffer_raster_worker_pool_.get(); + } + direct_raster_worker_pool_ = DirectRasterWorkerPool::Create( + proxy_->ImplThreadTaskRunner(), resource_provider, context_provider); tile_manager_ = TileManager::Create(this, - proxy_->ImplThreadTaskRunner(), resource_provider, - context_provider, - rendering_stats_instrumentation_, - using_map_image, - allow_rasterize_on_demand, - GetMaxTransferBufferUsageBytes(context_provider), + default_raster_worker_pool, + direct_raster_worker_pool_.get(), GetMaxRasterTasksUsageBytes(context_provider), - GetMapImageTextureTarget(context_provider)); + allow_rasterize_on_demand, + rendering_stats_instrumentation_); UpdateTileManagerMemoryPolicy(ActualManagedMemoryPolicy()); need_to_update_visible_tiles_before_draw_ = false; @@ -1817,6 +1838,9 @@ bool LayerTreeHostImpl::InitializeRenderer( // Note: order is important here. renderer_.reset(); tile_manager_.reset(); + image_raster_worker_pool_.reset(); + pixel_buffer_raster_worker_pool_.reset(); + direct_raster_worker_pool_.reset(); resource_provider_.reset(); output_surface_.reset(); @@ -1942,6 +1966,9 @@ void LayerTreeHostImpl::ReleaseGL() { ReleaseTreeResources(); renderer_.reset(); tile_manager_.reset(); + image_raster_worker_pool_.reset(); + pixel_buffer_raster_worker_pool_.reset(); + direct_raster_worker_pool_.reset(); resource_provider_->InitializeSoftware(); bool skip_gl_renderer = true; diff --git a/cc/trees/layer_tree_host_impl.h b/cc/trees/layer_tree_host_impl.h index 09b468d..7c528fb 100644 --- a/cc/trees/layer_tree_host_impl.h +++ b/cc/trees/layer_tree_host_impl.h @@ -40,15 +40,18 @@ namespace cc { class CompletionEvent; class CompositorFrameMetadata; class DebugRectHistory; +class DirectRasterWorkerPool; class FrameRateCounter; +class ImageRasterWorkerPool; class LayerImpl; class LayerTreeHostImplTimeSourceAdapter; class LayerTreeImpl; +class MemoryHistory; class PageScaleAnimation; class PaintTimeCounter; -class MemoryHistory; -class RenderingStatsInstrumentation; +class PixelBufferRasterWorkerPool; class RenderPassDrawQuad; +class RenderingStatsInstrumentation; class ScrollbarLayerImplBase; class TextureMailboxDeleter; class TopControlsManager; @@ -537,6 +540,9 @@ class CC_EXPORT LayerTreeHostImpl // free rendering - see OutputSurface::ForcedDrawToSoftwareDevice(). scoped_ptr<ResourceProvider> resource_provider_; scoped_ptr<TileManager> tile_manager_; + scoped_ptr<ImageRasterWorkerPool> image_raster_worker_pool_; + scoped_ptr<PixelBufferRasterWorkerPool> pixel_buffer_raster_worker_pool_; + scoped_ptr<DirectRasterWorkerPool> direct_raster_worker_pool_; scoped_ptr<Renderer> renderer_; GlobalStateThatImpactsTilePriority global_tile_state_; |