From 98805e6990c30ba99eebf9b1da1c382a1b21cfbd Mon Sep 17 00:00:00 2001 From: "boliu@chromium.org" Date: Wed, 5 Mar 2014 01:33:59 +0000 Subject: cc: Use explicit SequencedTaskRunner current loop in TileManager Remove MessageLoopProxy::current calls from different RasterWorker classes. Instead pass down the impl SequencedTaskRunner from LayerTreeHostImpl to where its needed. Fixed a bunch of unit tests that used to create TileManager with a proxy with no ImplThreadTaskRunner. BUG=348796 Review URL: https://codereview.chromium.org/186013004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@254903 0039d316-1c4b-4281-b951-d872f2087c98 --- cc/resources/direct_raster_worker_pool.cc | 10 ++++++---- cc/resources/direct_raster_worker_pool.h | 4 +++- cc/resources/image_raster_worker_pool.cc | 10 +++++----- cc/resources/image_raster_worker_pool.h | 4 +++- cc/resources/pixel_buffer_raster_worker_pool.cc | 11 +++++++---- cc/resources/pixel_buffer_raster_worker_pool.h | 4 +++- cc/resources/raster_worker_pool.cc | 24 ++++++++++++++++-------- cc/resources/raster_worker_pool.h | 5 ++++- cc/resources/raster_worker_pool_delegate.cc | 9 +++++---- cc/resources/raster_worker_pool_delegate.h | 3 +++ cc/resources/raster_worker_pool_perftest.cc | 10 +++++++--- cc/resources/raster_worker_pool_unittest.cc | 9 +++++++-- cc/resources/tile_manager.cc | 19 +++++++++++++------ cc/resources/tile_manager.h | 2 ++ 14 files changed, 84 insertions(+), 40 deletions(-) (limited to 'cc/resources') diff --git a/cc/resources/direct_raster_worker_pool.cc b/cc/resources/direct_raster_worker_pool.cc index ba08306..fb0eab5 100644 --- a/cc/resources/direct_raster_worker_pool.cc +++ b/cc/resources/direct_raster_worker_pool.cc @@ -14,16 +14,18 @@ namespace cc { // static scoped_ptr DirectRasterWorkerPool::Create( + base::SequencedTaskRunner* task_runner, ResourceProvider* resource_provider, ContextProvider* context_provider) { - return make_scoped_ptr( - new DirectRasterWorkerPool(resource_provider, context_provider)); + return make_scoped_ptr(new DirectRasterWorkerPool( + task_runner, resource_provider, context_provider)); } DirectRasterWorkerPool::DirectRasterWorkerPool( + base::SequencedTaskRunner* task_runner, ResourceProvider* resource_provider, ContextProvider* context_provider) - : RasterWorkerPool(NULL, resource_provider), + : RasterWorkerPool(task_runner, NULL, resource_provider), context_provider_(context_provider), run_tasks_on_origin_thread_pending_(false), raster_tasks_pending_(false), @@ -131,7 +133,7 @@ void DirectRasterWorkerPool::ScheduleRunTasksOnOriginThread() { if (run_tasks_on_origin_thread_pending_) return; - base::MessageLoopProxy::current()->PostTask( + task_runner()->PostTask( FROM_HERE, base::Bind(&DirectRasterWorkerPool::RunTasksOnOriginThread, weak_factory_.GetWeakPtr())); diff --git a/cc/resources/direct_raster_worker_pool.h b/cc/resources/direct_raster_worker_pool.h index 8dc8942..d2a6fd5 100644 --- a/cc/resources/direct_raster_worker_pool.h +++ b/cc/resources/direct_raster_worker_pool.h @@ -16,6 +16,7 @@ class CC_EXPORT DirectRasterWorkerPool : public RasterWorkerPool { virtual ~DirectRasterWorkerPool(); static scoped_ptr Create( + base::SequencedTaskRunner* task_runner, ResourceProvider* resource_provider, ContextProvider* context_provider); @@ -32,7 +33,8 @@ class CC_EXPORT DirectRasterWorkerPool : public RasterWorkerPool { const Resource* resource) OVERRIDE; protected: - DirectRasterWorkerPool(ResourceProvider* resource_provider, + DirectRasterWorkerPool(base::SequencedTaskRunner* task_runner, + ResourceProvider* resource_provider, ContextProvider* context_provider); private: diff --git a/cc/resources/image_raster_worker_pool.cc b/cc/resources/image_raster_worker_pool.cc index a892b3e..bffebf2 100644 --- a/cc/resources/image_raster_worker_pool.cc +++ b/cc/resources/image_raster_worker_pool.cc @@ -13,19 +13,19 @@ namespace cc { // static scoped_ptr ImageRasterWorkerPool::Create( + base::SequencedTaskRunner* task_runner, ResourceProvider* resource_provider, unsigned texture_target) { - return make_scoped_ptr( - new ImageRasterWorkerPool(GetTaskGraphRunner(), - resource_provider, - texture_target)); + return make_scoped_ptr(new ImageRasterWorkerPool( + task_runner, GetTaskGraphRunner(), resource_provider, texture_target)); } ImageRasterWorkerPool::ImageRasterWorkerPool( + base::SequencedTaskRunner* task_runner, internal::TaskGraphRunner* task_graph_runner, ResourceProvider* resource_provider, unsigned texture_target) - : RasterWorkerPool(task_graph_runner, resource_provider), + : RasterWorkerPool(task_runner, task_graph_runner, resource_provider), texture_target_(texture_target), raster_tasks_pending_(false), raster_tasks_required_for_activation_pending_(false) {} diff --git a/cc/resources/image_raster_worker_pool.h b/cc/resources/image_raster_worker_pool.h index aa7817b..4f28929 100644 --- a/cc/resources/image_raster_worker_pool.h +++ b/cc/resources/image_raster_worker_pool.h @@ -14,6 +14,7 @@ class CC_EXPORT ImageRasterWorkerPool : public RasterWorkerPool { virtual ~ImageRasterWorkerPool(); static scoped_ptr Create( + base::SequencedTaskRunner* task_runner, ResourceProvider* resource_provider, unsigned texture_target); @@ -30,7 +31,8 @@ class CC_EXPORT ImageRasterWorkerPool : public RasterWorkerPool { const Resource* resource) OVERRIDE; protected: - ImageRasterWorkerPool(internal::TaskGraphRunner* task_graph_runner, + ImageRasterWorkerPool(base::SequencedTaskRunner* task_runner, + internal::TaskGraphRunner* task_graph_runner, ResourceProvider* resource_provider, unsigned texture_target); diff --git a/cc/resources/pixel_buffer_raster_worker_pool.cc b/cc/resources/pixel_buffer_raster_worker_pool.cc index 752cbcd..af3a086 100644 --- a/cc/resources/pixel_buffer_raster_worker_pool.cc +++ b/cc/resources/pixel_buffer_raster_worker_pool.cc @@ -24,19 +24,22 @@ typedef base::StackVector // static scoped_ptr PixelBufferRasterWorkerPool::Create( + base::SequencedTaskRunner* task_runner, ResourceProvider* resource_provider, size_t max_transfer_buffer_usage_bytes) { return make_scoped_ptr( - new PixelBufferRasterWorkerPool(GetTaskGraphRunner(), + new PixelBufferRasterWorkerPool(task_runner, + GetTaskGraphRunner(), resource_provider, max_transfer_buffer_usage_bytes)); } PixelBufferRasterWorkerPool::PixelBufferRasterWorkerPool( + base::SequencedTaskRunner* task_runner, internal::TaskGraphRunner* task_graph_runner, ResourceProvider* resource_provider, size_t max_transfer_buffer_usage_bytes) - : RasterWorkerPool(task_graph_runner, resource_provider), + : RasterWorkerPool(task_runner, task_graph_runner, resource_provider), shutdown_(false), scheduled_raster_task_count_(0u), raster_tasks_required_for_activation_count_(0u), @@ -373,7 +376,7 @@ void PixelBufferRasterWorkerPool::ScheduleCheckForCompletedRasterTasks() { if (check_for_completed_raster_tasks_pending_) return; - base::MessageLoopProxy::current()->PostDelayedTask( + task_runner()->PostDelayedTask( FROM_HERE, base::Bind(&PixelBufferRasterWorkerPool::OnCheckForCompletedRasterTasks, weak_factory_.GetWeakPtr()), @@ -393,7 +396,7 @@ void PixelBufferRasterWorkerPool::OnCheckForCompletedRasterTasks() { // Post another delayed task if it is not yet time to check for completed // raster tasks. if (delay > base::TimeDelta()) { - base::MessageLoopProxy::current()->PostDelayedTask( + task_runner()->PostDelayedTask( FROM_HERE, base::Bind(&PixelBufferRasterWorkerPool::OnCheckForCompletedRasterTasks, weak_factory_.GetWeakPtr()), diff --git a/cc/resources/pixel_buffer_raster_worker_pool.h b/cc/resources/pixel_buffer_raster_worker_pool.h index fe34d1b..61ed979 100644 --- a/cc/resources/pixel_buffer_raster_worker_pool.h +++ b/cc/resources/pixel_buffer_raster_worker_pool.h @@ -28,6 +28,7 @@ class CC_EXPORT PixelBufferRasterWorkerPool : public RasterWorkerPool { virtual ~PixelBufferRasterWorkerPool(); static scoped_ptr Create( + base::SequencedTaskRunner* task_runner, ResourceProvider* resource_provider, size_t max_transfer_buffer_usage_bytes); @@ -45,7 +46,8 @@ class CC_EXPORT PixelBufferRasterWorkerPool : public RasterWorkerPool { const Resource* resource) OVERRIDE; protected: - PixelBufferRasterWorkerPool(internal::TaskGraphRunner* task_graph_runner, + PixelBufferRasterWorkerPool(base::SequencedTaskRunner* task_runner, + internal::TaskGraphRunner* task_graph_runner, ResourceProvider* resource_provider, size_t max_transfer_buffer_usage_bytes); diff --git a/cc/resources/raster_worker_pool.cc b/cc/resources/raster_worker_pool.cc index 859f57e..e1470c4 100644 --- a/cc/resources/raster_worker_pool.cc +++ b/cc/resources/raster_worker_pool.cc @@ -297,8 +297,9 @@ class RasterFinishedWorkerPoolTaskImpl : public internal::WorkerPoolTask { typedef base::Callback Callback; explicit RasterFinishedWorkerPoolTaskImpl( + base::SequencedTaskRunner* task_runner, const Callback& on_raster_finished_callback) - : origin_loop_(base::MessageLoopProxy::current().get()), + : task_runner_(task_runner), on_raster_finished_callback_(on_raster_finished_callback) {} // Overridden from internal::Task: @@ -322,7 +323,7 @@ class RasterFinishedWorkerPoolTaskImpl : public internal::WorkerPoolTask { virtual ~RasterFinishedWorkerPoolTaskImpl() {} void RasterFinished() { - origin_loop_->PostTask( + task_runner_->PostTask( FROM_HERE, base::Bind( &RasterFinishedWorkerPoolTaskImpl::OnRasterFinishedOnOriginThread, @@ -334,7 +335,7 @@ class RasterFinishedWorkerPoolTaskImpl : public internal::WorkerPoolTask { on_raster_finished_callback_.Run(this); } - scoped_refptr origin_loop_; + scoped_refptr task_runner_; const Callback on_raster_finished_callback_; DISALLOW_COPY_AND_ASSIGN(RasterFinishedWorkerPoolTaskImpl); @@ -344,9 +345,11 @@ class RasterRequiredForActivationFinishedWorkerPoolTaskImpl : public RasterFinishedWorkerPoolTaskImpl { public: RasterRequiredForActivationFinishedWorkerPoolTaskImpl( + base::SequencedTaskRunner* task_runner, const Callback& on_raster_finished_callback, size_t tasks_required_for_activation_count) - : RasterFinishedWorkerPoolTaskImpl(on_raster_finished_callback), + : RasterFinishedWorkerPoolTaskImpl(task_runner, + on_raster_finished_callback), tasks_required_for_activation_count_( tasks_required_for_activation_count) { if (tasks_required_for_activation_count_) { @@ -475,9 +478,11 @@ unsigned RasterWorkerPool::kRasterRequiredForActivationFinishedTaskPriority = 1u; unsigned RasterWorkerPool::kRasterTaskPriorityBase = 3u; -RasterWorkerPool::RasterWorkerPool(internal::TaskGraphRunner* task_graph_runner, +RasterWorkerPool::RasterWorkerPool(base::SequencedTaskRunner* task_runner, + internal::TaskGraphRunner* task_graph_runner, ResourceProvider* resource_provider) - : task_graph_runner_(task_graph_runner), + : task_runner_(task_runner), + task_graph_runner_(task_graph_runner), client_(NULL), resource_provider_(resource_provider), weak_ptr_factory_(this) { @@ -594,8 +599,10 @@ void RasterWorkerPool::CollectCompletedWorkerPoolTasks( scoped_refptr RasterWorkerPool::CreateRasterFinishedTask() { - return make_scoped_refptr(new RasterFinishedWorkerPoolTaskImpl(base::Bind( - &RasterWorkerPool::OnRasterFinished, weak_ptr_factory_.GetWeakPtr()))); + return make_scoped_refptr(new RasterFinishedWorkerPoolTaskImpl( + task_runner_, + base::Bind(&RasterWorkerPool::OnRasterFinished, + weak_ptr_factory_.GetWeakPtr()))); } scoped_refptr @@ -603,6 +610,7 @@ 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)); diff --git a/cc/resources/raster_worker_pool.h b/cc/resources/raster_worker_pool.h index a0ce885..520efba 100644 --- a/cc/resources/raster_worker_pool.h +++ b/cc/resources/raster_worker_pool.h @@ -192,7 +192,8 @@ class CC_EXPORT RasterWorkerPool : public internal::WorkerPoolTaskClient { typedef std::vector > RasterTaskVector; - RasterWorkerPool(internal::TaskGraphRunner* task_graph_runner, + RasterWorkerPool(base::SequencedTaskRunner* task_runner, + internal::TaskGraphRunner* task_graph_runner, ResourceProvider* resource_provider); virtual void OnRasterTasksFinished() = 0; @@ -201,6 +202,7 @@ class CC_EXPORT RasterWorkerPool : public internal::WorkerPoolTaskClient { 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_; } @@ -244,6 +246,7 @@ class CC_EXPORT RasterWorkerPool : public internal::WorkerPoolTaskClient { void OnRasterRequiredForActivationFinished( const internal::WorkerPoolTask* source); + scoped_refptr task_runner_; internal::TaskGraphRunner* task_graph_runner_; internal::NamespaceToken namespace_token_; RasterWorkerPoolClient* client_; diff --git a/cc/resources/raster_worker_pool_delegate.cc b/cc/resources/raster_worker_pool_delegate.cc index f91f25a..690b135 100644 --- a/cc/resources/raster_worker_pool_delegate.cc +++ b/cc/resources/raster_worker_pool_delegate.cc @@ -4,15 +4,15 @@ #include "cc/resources/raster_worker_pool_delegate.h" -#include "base/message_loop/message_loop_proxy.h" - namespace cc { RasterWorkerPoolDelegate::RasterWorkerPoolDelegate( RasterWorkerPoolClient* client, + base::SequencedTaskRunner* task_runner, RasterWorkerPool** raster_worker_pools, size_t num_raster_worker_pools) : client_(client), + task_runner_(task_runner), raster_worker_pools_(raster_worker_pools, raster_worker_pools + num_raster_worker_pools), did_finish_running_tasks_pending_(num_raster_worker_pools, false), @@ -32,10 +32,11 @@ RasterWorkerPoolDelegate::~RasterWorkerPoolDelegate() {} // static scoped_ptr RasterWorkerPoolDelegate::Create( RasterWorkerPoolClient* client, + base::SequencedTaskRunner* task_runner, RasterWorkerPool** raster_worker_pools, size_t num_raster_worker_pools) { return make_scoped_ptr(new RasterWorkerPoolDelegate( - client, raster_worker_pools, num_raster_worker_pools)); + client, task_runner, raster_worker_pools, num_raster_worker_pools)); } void RasterWorkerPoolDelegate::Shutdown() { @@ -99,7 +100,7 @@ void RasterWorkerPoolDelegate::ScheduleRunDidFinishRunningTasks() { if (run_did_finish_running_tasks_pending_) return; - base::MessageLoopProxy::current()->PostTask( + task_runner_->PostTask( FROM_HERE, base::Bind(&RasterWorkerPoolDelegate::OnRunDidFinishRunningTasks, weak_ptr_factory_.GetWeakPtr())); diff --git a/cc/resources/raster_worker_pool_delegate.h b/cc/resources/raster_worker_pool_delegate.h index 1d7234e..3eec088 100644 --- a/cc/resources/raster_worker_pool_delegate.h +++ b/cc/resources/raster_worker_pool_delegate.h @@ -18,6 +18,7 @@ class RasterWorkerPoolDelegate : public RasterWorkerPoolClient { static scoped_ptr Create( RasterWorkerPoolClient* client, + base::SequencedTaskRunner* task_runner, RasterWorkerPool** raster_worker_pools, size_t num_raster_worker_pools); @@ -33,6 +34,7 @@ class RasterWorkerPoolDelegate : public RasterWorkerPoolClient { private: RasterWorkerPoolDelegate(RasterWorkerPoolClient* client, + base::SequencedTaskRunner* task_runner, RasterWorkerPool** raster_worker_pools, size_t num_raster_worker_pools); @@ -41,6 +43,7 @@ class RasterWorkerPoolDelegate : public RasterWorkerPoolClient { void RunDidFinishRunningTasks(); RasterWorkerPoolClient* client_; + scoped_refptr task_runner_; typedef std::vector RasterWorkerPoolVector; RasterWorkerPoolVector raster_worker_pools_; std::vector did_finish_running_tasks_pending_; diff --git a/cc/resources/raster_worker_pool_perftest.cc b/cc/resources/raster_worker_pool_perftest.cc index dfd3955..9fb7dfc 100644 --- a/cc/resources/raster_worker_pool_perftest.cc +++ b/cc/resources/raster_worker_pool_perftest.cc @@ -104,7 +104,8 @@ class PerfPixelBufferRasterWorkerPoolImpl : public PixelBufferRasterWorkerPool { PerfPixelBufferRasterWorkerPoolImpl( internal::TaskGraphRunner* task_graph_runner, ResourceProvider* resource_provider) - : PixelBufferRasterWorkerPool(task_graph_runner, + : PixelBufferRasterWorkerPool(base::MessageLoopProxy::current().get(), + task_graph_runner, resource_provider, std::numeric_limits::max()) {} }; @@ -113,7 +114,8 @@ class PerfImageRasterWorkerPoolImpl : public ImageRasterWorkerPool { public: PerfImageRasterWorkerPoolImpl(internal::TaskGraphRunner* task_graph_runner, ResourceProvider* resource_provider) - : ImageRasterWorkerPool(task_graph_runner, + : ImageRasterWorkerPool(base::MessageLoopProxy::current().get(), + task_graph_runner, resource_provider, GL_TEXTURE_2D) {} }; @@ -122,7 +124,9 @@ class PerfDirectRasterWorkerPoolImpl : public DirectRasterWorkerPool { public: PerfDirectRasterWorkerPoolImpl(ResourceProvider* resource_provider, ContextProvider* context_provider) - : DirectRasterWorkerPool(resource_provider, context_provider) {} + : DirectRasterWorkerPool(base::MessageLoopProxy::current().get(), + resource_provider, + context_provider) {} }; class RasterWorkerPoolPerfTestBase { diff --git a/cc/resources/raster_worker_pool_unittest.cc b/cc/resources/raster_worker_pool_unittest.cc index 791273d..613c946 100644 --- a/cc/resources/raster_worker_pool_unittest.cc +++ b/cc/resources/raster_worker_pool_unittest.cc @@ -135,16 +135,21 @@ class RasterWorkerPoolTest switch (GetParam()) { case RASTER_WORKER_POOL_TYPE_PIXEL_BUFFER: raster_worker_pool_ = PixelBufferRasterWorkerPool::Create( + base::MessageLoopProxy::current().get(), resource_provider_.get(), std::numeric_limits::max()); break; case RASTER_WORKER_POOL_TYPE_IMAGE: raster_worker_pool_ = ImageRasterWorkerPool::Create( - resource_provider_.get(), GL_TEXTURE_2D); + base::MessageLoopProxy::current().get(), + resource_provider_.get(), + GL_TEXTURE_2D); break; case RASTER_WORKER_POOL_TYPE_DIRECT: raster_worker_pool_ = DirectRasterWorkerPool::Create( - resource_provider_.get(), context_provider_.get()); + base::MessageLoopProxy::current().get(), + resource_provider_.get(), + context_provider_.get()); break; } diff --git a/cc/resources/tile_manager.cc b/cc/resources/tile_manager.cc index f36a2cd..c2cb67b 100644 --- a/cc/resources/tile_manager.cc +++ b/cc/resources/tile_manager.cc @@ -148,6 +148,7 @@ scoped_ptr RasterTaskCompletionStatsAsValue( // static scoped_ptr TileManager::Create( TileManagerClient* client, + base::SequencedTaskRunner* task_runner, ResourceProvider* resource_provider, ContextProvider* context_provider, RenderingStatsInstrumentation* rendering_stats_instrumentation, @@ -158,13 +159,18 @@ scoped_ptr TileManager::Create( unsigned map_image_texture_target) { return make_scoped_ptr(new TileManager( client, + task_runner, resource_provider, context_provider, - use_map_image ? ImageRasterWorkerPool::Create(resource_provider, - map_image_texture_target) - : PixelBufferRasterWorkerPool::Create( - resource_provider, max_transfer_buffer_usage_bytes), - DirectRasterWorkerPool::Create(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)); @@ -172,6 +178,7 @@ scoped_ptr TileManager::Create( TileManager::TileManager( TileManagerClient* client, + base::SequencedTaskRunner* task_runner, ResourceProvider* resource_provider, ContextProvider* context_provider, scoped_ptr raster_worker_pool, @@ -205,7 +212,7 @@ TileManager::TileManager( direct_raster_worker_pool_.get() // RASTER_WORKER_POOL_TYPE_DIRECT }; raster_worker_pool_delegate_ = RasterWorkerPoolDelegate::Create( - this, raster_worker_pools, arraysize(raster_worker_pools)); + this, task_runner, raster_worker_pools, arraysize(raster_worker_pools)); } TileManager::~TileManager() { diff --git a/cc/resources/tile_manager.h b/cc/resources/tile_manager.h index 1a33876..d691d035 100644 --- a/cc/resources/tile_manager.h +++ b/cc/resources/tile_manager.h @@ -52,6 +52,7 @@ class CC_EXPORT TileManager : public RasterWorkerPoolClient, public: static scoped_ptr Create( TileManagerClient* client, + base::SequencedTaskRunner* task_runner, ResourceProvider* resource_provider, ContextProvider* context_provider, RenderingStatsInstrumentation* rendering_stats_instrumentation, @@ -118,6 +119,7 @@ class CC_EXPORT TileManager : public RasterWorkerPoolClient, protected: TileManager(TileManagerClient* client, + base::SequencedTaskRunner* task_runner, ResourceProvider* resource_provider, ContextProvider* context_provider, scoped_ptr raster_worker_pool, -- cgit v1.1