diff options
author | skyostil <skyostil@chromium.org> | 2015-05-14 07:41:53 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-05-14 14:41:58 +0000 |
commit | d445291dc69fa20ff01879180fb7928d146ca729 (patch) | |
tree | 8c713eb186235f66cbefc6ffa1f6447b2b83ca64 | |
parent | 4cac9b119cae33bf6277195cec857e97d7111690 (diff) | |
download | chromium_src-d445291dc69fa20ff01879180fb7928d146ca729.zip chromium_src-d445291dc69fa20ff01879180fb7928d146ca729.tar.gz chromium_src-d445291dc69fa20ff01879180fb7928d146ca729.tar.bz2 |
content/common: Remove use of MessageLoopProxy and deprecated MessageLoop APIs
This patch was mostly autogenerated with https://codereview.chromium.org/1010073002/.
BUG=465354
Committed: https://crrev.com/adc9b4ed3d797c2990d682a3784d2e892198ce00
Cr-Commit-Position: refs/heads/master@{#329696}
Review URL: https://codereview.chromium.org/1134113002
Cr-Commit-Position: refs/heads/master@{#329846}
41 files changed, 438 insertions, 516 deletions
diff --git a/content/browser/android/java/gin_java_bridge_dispatcher_host.cc b/content/browser/android/java/gin_java_bridge_dispatcher_host.cc index 748bd8b2..fc4c55e 100644 --- a/content/browser/android/java/gin_java_bridge_dispatcher_host.cc +++ b/content/browser/android/java/gin_java_bridge_dispatcher_host.cc @@ -345,7 +345,7 @@ base::TaskRunner* GinJavaBridgeDispatcherHost::OverrideTaskRunnerForMessage( { base::AutoLock locker(objects_lock_); if (objects_.find(object_id) != objects_.end()) { - return g_background_thread.Get().message_loop()->task_runner().get(); + return g_background_thread.Get().message_loop()->task_runner().get(); } } return NULL; diff --git a/content/browser/gpu/browser_gpu_channel_host_factory.cc b/content/browser/gpu/browser_gpu_channel_host_factory.cc index 11bbe83..205542c 100644 --- a/content/browser/gpu/browser_gpu_channel_host_factory.cc +++ b/content/browser/gpu/browser_gpu_channel_host_factory.cc @@ -305,8 +305,8 @@ bool BrowserGpuChannelHostFactory::IsMainThread() { return BrowserThread::CurrentlyOn(BrowserThread::UI); } -scoped_refptr<base::MessageLoopProxy> -BrowserGpuChannelHostFactory::GetIOLoopProxy() { +scoped_refptr<base::SingleThreadTaskRunner> +BrowserGpuChannelHostFactory::GetIOThreadTaskRunner() { return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); } @@ -353,12 +353,10 @@ CreateCommandBufferResult BrowserGpuChannelHostFactory::CreateViewCommandBuffer( const GPUCreateCommandBufferConfig& init_params, int32 route_id) { CreateRequest request(route_id); - GetIOLoopProxy()->PostTask(FROM_HERE, base::Bind( - &BrowserGpuChannelHostFactory::CreateViewCommandBufferOnIO, - base::Unretained(this), - &request, - surface_id, - init_params)); + GetIOThreadTaskRunner()->PostTask( + FROM_HERE, + base::Bind(&BrowserGpuChannelHostFactory::CreateViewCommandBufferOnIO, + base::Unretained(this), &request, surface_id, init_params)); // TODO(vadimt): Remove ScopedTracker below once crbug.com/125248 is fixed. tracked_objects::ScopedTracker tracking_profile( FROM_HERE_WITH_EXPLICIT_FUNCTION( diff --git a/content/browser/gpu/browser_gpu_channel_host_factory.h b/content/browser/gpu/browser_gpu_channel_host_factory.h index bb24f94..b4df563 100644 --- a/content/browser/gpu/browser_gpu_channel_host_factory.h +++ b/content/browser/gpu/browser_gpu_channel_host_factory.h @@ -33,7 +33,7 @@ class CONTENT_EXPORT BrowserGpuChannelHostFactory // Overridden from GpuChannelHostFactory: bool IsMainThread() override; - scoped_refptr<base::MessageLoopProxy> GetIOLoopProxy() override; + scoped_refptr<base::SingleThreadTaskRunner> GetIOThreadTaskRunner() override; scoped_ptr<base::SharedMemory> AllocateSharedMemory(size_t size) override; CreateCommandBufferResult CreateViewCommandBuffer( int32 surface_id, diff --git a/content/common/database_connections_unittest.cc b/content/common/database_connections_unittest.cc index 7f9a9b2..8992f0d 100644 --- a/content/common/database_connections_unittest.cc +++ b/content/common/database_connections_unittest.cc @@ -5,6 +5,7 @@ #include "base/bind.h" #include "base/message_loop/message_loop.h" #include "base/strings/utf_string_conversions.h" +#include "base/thread_task_runner_handle.h" #include "base/threading/thread.h" #include "storage/common/database/database_connections.h" #include "testing/gtest/include/gtest/gtest.h" @@ -30,10 +31,9 @@ void ScheduleRemoveConnectionTask( const base::string16& database_name, scoped_refptr<DatabaseConnectionsWrapper> obj, bool* did_task_execute) { - thread->message_loop()->PostTask( - FROM_HERE, - base::Bind(&RemoveConnectionTask, origin_id, database_name, obj, - did_task_execute)); + thread->task_runner()->PostTask( + FROM_HERE, base::Bind(&RemoveConnectionTask, origin_id, database_name, + obj, did_task_execute)); } } // anonymous namespace @@ -121,10 +121,9 @@ TEST(DatabaseConnectionsTest, DatabaseConnectionsWrapperTest) { // being removed on the current thread. obj->AddOpenConnection(kOriginId, kName); bool did_task_execute = false; - base::MessageLoop::current()->PostTask( - FROM_HERE, - base::Bind(&RemoveConnectionTask, kOriginId, kName, obj, - &did_task_execute)); + base::ThreadTaskRunnerHandle::Get()->PostTask( + FROM_HERE, base::Bind(&RemoveConnectionTask, kOriginId, kName, obj, + &did_task_execute)); obj->WaitForAllDatabasesToClose(); // should return after the task executes EXPECT_TRUE(did_task_execute); EXPECT_FALSE(obj->HasOpenConnections()); @@ -135,10 +134,9 @@ TEST(DatabaseConnectionsTest, DatabaseConnectionsWrapperTest) { base::Thread thread("WrapperTestThread"); thread.Start(); did_task_execute = false; - base::MessageLoop::current()->PostTask( - FROM_HERE, - base::Bind(&ScheduleRemoveConnectionTask, &thread, kOriginId, kName, obj, - &did_task_execute)); + base::ThreadTaskRunnerHandle::Get()->PostTask( + FROM_HERE, base::Bind(&ScheduleRemoveConnectionTask, &thread, kOriginId, + kName, obj, &did_task_execute)); obj->WaitForAllDatabasesToClose(); // should return after the task executes EXPECT_TRUE(did_task_execute); EXPECT_FALSE(obj->HasOpenConnections()); diff --git a/content/common/gpu/client/gpu_channel_host.cc b/content/common/gpu/client/gpu_channel_host.cc index 475eeb1..b4460bb 100644 --- a/content/common/gpu/client/gpu_channel_host.cc +++ b/content/common/gpu/client/gpu_channel_host.cc @@ -7,9 +7,10 @@ #include <algorithm> #include "base/bind.h" -#include "base/message_loop/message_loop.h" -#include "base/message_loop/message_loop_proxy.h" +#include "base/location.h" #include "base/posix/eintr_wrapper.h" +#include "base/single_thread_task_runner.h" +#include "base/thread_task_runner_handle.h" #include "base/threading/thread_restrictions.h" #include "base/trace_event/trace_event.h" #include "content/common/gpu/client/command_buffer_proxy_impl.h" @@ -22,7 +23,6 @@ #endif using base::AutoLock; -using base::MessageLoopProxy; namespace content { @@ -71,13 +71,11 @@ void GpuChannelHost::Connect(const IPC::ChannelHandle& channel_handle, DCHECK(factory_->IsMainThread()); // Open a channel to the GPU process. We pass NULL as the main listener here // since we need to filter everything to route it to the right thread. - scoped_refptr<base::MessageLoopProxy> io_loop = factory_->GetIOLoopProxy(); - channel_ = IPC::SyncChannel::Create(channel_handle, - IPC::Channel::MODE_CLIENT, - NULL, - io_loop.get(), - true, - shutdown_event); + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner = + factory_->GetIOThreadTaskRunner(); + channel_ = + IPC::SyncChannel::Create(channel_handle, IPC::Channel::MODE_CLIENT, NULL, + io_task_runner.get(), true, shutdown_event); sync_filter_ = new IPC::SyncMessageFilter(shutdown_event); @@ -186,14 +184,11 @@ CommandBufferProxyImpl* GpuChannelHost::CreateViewCommandBuffer( // then set up a new connection, and the GPU channel and any // view command buffers will all be associated with the same GPU // process. - DCHECK(MessageLoopProxy::current().get()); - - scoped_refptr<base::MessageLoopProxy> io_loop = - factory_->GetIOLoopProxy(); - io_loop->PostTask( - FROM_HERE, - base::Bind(&GpuChannelHost::MessageFilter::OnChannelError, - channel_filter_.get())); + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner = + factory_->GetIOThreadTaskRunner(); + io_task_runner->PostTask( + FROM_HERE, base::Bind(&GpuChannelHost::MessageFilter::OnChannelError, + channel_filter_.get())); } return NULL; @@ -287,20 +282,20 @@ void GpuChannelHost::DestroyChannel() { void GpuChannelHost::AddRoute( int route_id, base::WeakPtr<IPC::Listener> listener) { - DCHECK(MessageLoopProxy::current().get()); - - scoped_refptr<base::MessageLoopProxy> io_loop = factory_->GetIOLoopProxy(); - io_loop->PostTask(FROM_HERE, - base::Bind(&GpuChannelHost::MessageFilter::AddRoute, - channel_filter_.get(), route_id, listener, - MessageLoopProxy::current())); + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner = + factory_->GetIOThreadTaskRunner(); + io_task_runner->PostTask(FROM_HERE, + base::Bind(&GpuChannelHost::MessageFilter::AddRoute, + channel_filter_.get(), route_id, listener, + base::ThreadTaskRunnerHandle::Get())); } void GpuChannelHost::RemoveRoute(int route_id) { - scoped_refptr<base::MessageLoopProxy> io_loop = factory_->GetIOLoopProxy(); - io_loop->PostTask(FROM_HERE, - base::Bind(&GpuChannelHost::MessageFilter::RemoveRoute, - channel_filter_.get(), route_id)); + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner = + factory_->GetIOThreadTaskRunner(); + io_task_runner->PostTask( + FROM_HERE, base::Bind(&GpuChannelHost::MessageFilter::RemoveRoute, + channel_filter_.get(), route_id)); } base::SharedMemoryHandle GpuChannelHost::ShareToGpuProcess( @@ -387,11 +382,12 @@ GpuChannelHost::MessageFilter::~MessageFilter() {} void GpuChannelHost::MessageFilter::AddRoute( int route_id, base::WeakPtr<IPC::Listener> listener, - scoped_refptr<MessageLoopProxy> loop) { + scoped_refptr<base::SingleThreadTaskRunner> task_runner) { DCHECK(listeners_.find(route_id) == listeners_.end()); + DCHECK(task_runner); GpuListenerInfo info; info.listener = listener; - info.loop = loop; + info.task_runner = task_runner; listeners_[route_id] = info; } @@ -412,12 +408,10 @@ bool GpuChannelHost::MessageFilter::OnMessageReceived( return false; const GpuListenerInfo& info = it->second; - info.loop->PostTask( + info.task_runner->PostTask( FROM_HERE, - base::Bind( - base::IgnoreResult(&IPC::Listener::OnMessageReceived), - info.listener, - message)); + base::Bind(base::IgnoreResult(&IPC::Listener::OnMessageReceived), + info.listener, message)); return true; } @@ -436,9 +430,8 @@ void GpuChannelHost::MessageFilter::OnChannelError() { it != listeners_.end(); it++) { const GpuListenerInfo& info = it->second; - info.loop->PostTask( - FROM_HERE, - base::Bind(&IPC::Listener::OnChannelError, info.listener)); + info.task_runner->PostTask( + FROM_HERE, base::Bind(&IPC::Listener::OnChannelError, info.listener)); } listeners_.clear(); diff --git a/content/common/gpu/client/gpu_channel_host.h b/content/common/gpu/client/gpu_channel_host.h index ea1b6b8..4ec2e06 100644 --- a/content/common/gpu/client/gpu_channel_host.h +++ b/content/common/gpu/client/gpu_channel_host.h @@ -35,7 +35,6 @@ struct GPUCreateCommandBufferConfig; namespace base { class MessageLoop; -class MessageLoopProxy; class WaitableEvent; } @@ -61,7 +60,7 @@ struct GpuListenerInfo { ~GpuListenerInfo(); base::WeakPtr<IPC::Listener> listener; - scoped_refptr<base::MessageLoopProxy> loop; + scoped_refptr<base::SingleThreadTaskRunner> task_runner; }; struct ProxyFlushInfo { @@ -80,7 +79,8 @@ class CONTENT_EXPORT GpuChannelHostFactory { virtual ~GpuChannelHostFactory() {} virtual bool IsMainThread() = 0; - virtual scoped_refptr<base::MessageLoopProxy> GetIOLoopProxy() = 0; + virtual scoped_refptr<base::SingleThreadTaskRunner> + GetIOThreadTaskRunner() = 0; virtual scoped_ptr<base::SharedMemory> AllocateSharedMemory(size_t size) = 0; virtual CreateCommandBufferResult CreateViewCommandBuffer( int32 surface_id, @@ -207,7 +207,7 @@ class GpuChannelHost : public IPC::Sender, // Called on the IO thread. void AddRoute(int route_id, base::WeakPtr<IPC::Listener> listener, - scoped_refptr<base::MessageLoopProxy> loop); + scoped_refptr<base::SingleThreadTaskRunner> task_runner); // Called on the IO thread. void RemoveRoute(int route_id); diff --git a/content/common/gpu/client/gpu_video_decode_accelerator_host.cc b/content/common/gpu/client/gpu_video_decode_accelerator_host.cc index cef83f6..86894bc 100644 --- a/content/common/gpu/client/gpu_video_decode_accelerator_host.cc +++ b/content/common/gpu/client/gpu_video_decode_accelerator_host.cc @@ -188,11 +188,9 @@ void GpuVideoDecodeAcceleratorHost::OnWillDeleteImpl() { void GpuVideoDecodeAcceleratorHost::PostNotifyError(Error error) { DCHECK(CalledOnValidThread()); DVLOG(2) << "PostNotifyError(): error=" << error; - base::MessageLoopProxy::current()->PostTask( - FROM_HERE, - base::Bind(&GpuVideoDecodeAcceleratorHost::OnNotifyError, - weak_this_factory_.GetWeakPtr(), - error)); + base::ThreadTaskRunnerHandle::Get()->PostTask( + FROM_HERE, base::Bind(&GpuVideoDecodeAcceleratorHost::OnNotifyError, + weak_this_factory_.GetWeakPtr(), error)); } void GpuVideoDecodeAcceleratorHost::Send(IPC::Message* message) { diff --git a/content/common/gpu/client/gpu_video_encode_accelerator_host.cc b/content/common/gpu/client/gpu_video_encode_accelerator_host.cc index 214b32d..1cbfeaa 100644 --- a/content/common/gpu/client/gpu_video_encode_accelerator_host.cc +++ b/content/common/gpu/client/gpu_video_encode_accelerator_host.cc @@ -5,7 +5,6 @@ #include "content/common/gpu/client/gpu_video_encode_accelerator_host.h" #include "base/logging.h" -#include "base/message_loop/message_loop_proxy.h" #include "content/common/gpu/client/gpu_channel_host.h" #include "content/common/gpu/gpu_messages.h" #include "content/common/gpu/media/gpu_video_accelerator_util.h" @@ -200,11 +199,9 @@ void GpuVideoEncodeAcceleratorHost::PostNotifyError(Error error) { DCHECK(CalledOnValidThread()); DVLOG(2) << "PostNotifyError(): error=" << error; // Post the error notification back to this thread, to avoid re-entrancy. - base::MessageLoopProxy::current()->PostTask( - FROM_HERE, - base::Bind(&GpuVideoEncodeAcceleratorHost::OnNotifyError, - weak_this_factory_.GetWeakPtr(), - error)); + base::ThreadTaskRunnerHandle::Get()->PostTask( + FROM_HERE, base::Bind(&GpuVideoEncodeAcceleratorHost::OnNotifyError, + weak_this_factory_.GetWeakPtr(), error)); } void GpuVideoEncodeAcceleratorHost::Send(IPC::Message* message) { diff --git a/content/common/gpu/gpu_channel.cc b/content/common/gpu/gpu_channel.cc index c12c762..2768eea 100644 --- a/content/common/gpu/gpu_channel.cc +++ b/content/common/gpu/gpu_channel.cc @@ -13,9 +13,11 @@ #include "base/bind.h" #include "base/command_line.h" -#include "base/message_loop/message_loop_proxy.h" +#include "base/location.h" +#include "base/single_thread_task_runner.h" #include "base/stl_util.h" #include "base/strings/string_util.h" +#include "base/thread_task_runner_handle.h" #include "base/timer/timer.h" #include "base/trace_event/trace_event.h" #include "content/common/gpu/gpu_channel_manager.h" @@ -77,13 +79,13 @@ class GpuChannelMessageFilter : public IPC::MessageFilter { GpuChannelMessageFilter( base::WeakPtr<GpuChannel> gpu_channel, scoped_refptr<gpu::SyncPointManager> sync_point_manager, - scoped_refptr<base::MessageLoopProxy> message_loop, + scoped_refptr<base::SingleThreadTaskRunner> task_runner, bool future_sync_points) : preemption_state_(IDLE), gpu_channel_(gpu_channel), sender_(NULL), sync_point_manager_(sync_point_manager), - message_loop_(message_loop), + task_runner_(task_runner), messages_forwarded_to_channel_(0), a_stub_is_descheduled_(false), future_sync_points_(future_sync_points) {} @@ -127,14 +129,11 @@ class GpuChannelMessageFilter : public IPC::MessageFilter { uint32 sync_point = sync_point_manager_->GenerateSyncPoint(); GpuCommandBufferMsg_InsertSyncPoint::WriteReplyParams(reply, sync_point); Send(reply); - message_loop_->PostTask( + task_runner_->PostTask( FROM_HERE, base::Bind(&GpuChannelMessageFilter::InsertSyncPointOnMainThread, - gpu_channel_, - sync_point_manager_, - message.routing_id(), - get<0>(retire), - sync_point)); + gpu_channel_, sync_point_manager_, message.routing_id(), + get<0>(retire), sync_point)); handled = true; } @@ -383,7 +382,7 @@ class GpuChannelMessageFilter : public IPC::MessageFilter { base::WeakPtr<GpuChannel> gpu_channel_; IPC::Sender* sender_; scoped_refptr<gpu::SyncPointManager> sync_point_manager_; - scoped_refptr<base::MessageLoopProxy> message_loop_; + scoped_refptr<base::SingleThreadTaskRunner> task_runner_; scoped_refptr<gpu::PreemptionFlag> preempting_flag_; std::queue<PendingMessage> pending_messages_; @@ -437,24 +436,19 @@ GpuChannel::~GpuChannel() { preempting_flag_->Reset(); } -void GpuChannel::Init(base::MessageLoopProxy* io_message_loop, +void GpuChannel::Init(base::SingleThreadTaskRunner* io_task_runner, base::WaitableEvent* shutdown_event) { DCHECK(!channel_.get()); // Map renderer ID to a (single) channel to that process. - channel_ = IPC::SyncChannel::Create(channel_id_, - IPC::Channel::MODE_SERVER, - this, - io_message_loop, - false, - shutdown_event); - - filter_ = - new GpuChannelMessageFilter(weak_factory_.GetWeakPtr(), - gpu_channel_manager_->sync_point_manager(), - base::MessageLoopProxy::current(), - allow_future_sync_points_); - io_message_loop_ = io_message_loop; + channel_ = + IPC::SyncChannel::Create(channel_id_, IPC::Channel::MODE_SERVER, this, + io_task_runner, false, shutdown_event); + + filter_ = new GpuChannelMessageFilter( + weak_factory_.GetWeakPtr(), gpu_channel_manager_->sync_point_manager(), + base::ThreadTaskRunnerHandle::Get(), allow_future_sync_points_); + io_task_runner_ = io_task_runner; channel_->AddFilter(filter_.get()); pending_valuebuffer_state_ = new gpu::ValueStateMap(); } @@ -540,7 +534,7 @@ void GpuChannel::OnScheduled() { // defer newly received messages until the ones in the queue have all been // handled by HandleMessage. HandleMessage is invoked as a // task to prevent reentrancy. - base::MessageLoop::current()->PostTask( + base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, base::Bind(&GpuChannel::HandleMessage, weak_factory_.GetWeakPtr())); handle_messages_scheduled_ = true; @@ -559,11 +553,10 @@ void GpuChannel::StubSchedulingChanged(bool scheduled) { if (a_stub_is_descheduled != a_stub_was_descheduled) { if (preempting_flag_.get()) { - io_message_loop_->PostTask( + io_task_runner_->PostTask( FROM_HERE, base::Bind(&GpuChannelMessageFilter::UpdateStubSchedulingState, - filter_, - a_stub_is_descheduled)); + filter_, a_stub_is_descheduled)); } } } @@ -642,8 +635,9 @@ void GpuChannel::RemoveRoute(int32 route_id) { gpu::PreemptionFlag* GpuChannel::GetPreemptionFlag() { if (!preempting_flag_.get()) { preempting_flag_ = new gpu::PreemptionFlag; - io_message_loop_->PostTask( - FROM_HERE, base::Bind( + io_task_runner_->PostTask( + FROM_HERE, + base::Bind( &GpuChannelMessageFilter::SetPreemptingFlagAndSchedulingState, filter_, preempting_flag_, num_stubs_descheduled_ > 0)); } @@ -796,11 +790,9 @@ void GpuChannel::OnDestroyCommandBuffer(int32 route_id) { void GpuChannel::MessageProcessed() { messages_processed_++; if (preempting_flag_.get()) { - io_message_loop_->PostTask( - FROM_HERE, - base::Bind(&GpuChannelMessageFilter::MessageProcessed, - filter_, - messages_processed_)); + io_task_runner_->PostTask( + FROM_HERE, base::Bind(&GpuChannelMessageFilter::MessageProcessed, + filter_, messages_processed_)); } } diff --git a/content/common/gpu/gpu_channel.h b/content/common/gpu/gpu_channel.h index df2fd54..710b31a 100644 --- a/content/common/gpu/gpu_channel.h +++ b/content/common/gpu/gpu_channel.h @@ -29,7 +29,6 @@ struct GPUCreateCommandBufferConfig; namespace base { -class MessageLoopProxy; class WaitableEvent; } @@ -66,7 +65,7 @@ class GpuChannel : public IPC::Listener, public IPC::Sender, bool allow_future_sync_points); ~GpuChannel() override; - void Init(base::MessageLoopProxy* io_message_loop, + void Init(base::SingleThreadTaskRunner* io_task_runner, base::WaitableEvent* shutdown_event); // Get the GpuChannelManager that owns this channel. @@ -85,8 +84,8 @@ class GpuChannel : public IPC::Listener, public IPC::Sender, int client_id() const { return client_id_; } - scoped_refptr<base::MessageLoopProxy> io_message_loop() const { - return io_message_loop_; + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner() const { + return io_task_runner_; } // IPC::Listener implementation: @@ -238,7 +237,7 @@ class GpuChannel : public IPC::Listener, public IPC::Sender, IPC::Message* currently_processing_message_; scoped_refptr<GpuChannelMessageFilter> filter_; - scoped_refptr<base::MessageLoopProxy> io_message_loop_; + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; size_t num_stubs_descheduled_; diff --git a/content/common/gpu/gpu_channel_manager.cc b/content/common/gpu/gpu_channel_manager.cc index cb26cf2..4cec7cb 100644 --- a/content/common/gpu/gpu_channel_manager.cc +++ b/content/common/gpu/gpu_channel_manager.cc @@ -6,6 +6,9 @@ #include "base/bind.h" #include "base/command_line.h" +#include "base/location.h" +#include "base/single_thread_task_runner.h" +#include "base/thread_task_runner_handle.h" #include "content/common/gpu/gpu_channel.h" #include "content/common/gpu/gpu_memory_buffer_factory.h" #include "content/common/gpu/gpu_memory_manager.h" @@ -85,12 +88,13 @@ gfx::GpuMemoryBufferType GetGpuMemoryBufferFactoryType() { } // namespace -GpuChannelManager::GpuChannelManager(MessageRouter* router, - GpuWatchdog* watchdog, - base::MessageLoopProxy* io_message_loop, - base::WaitableEvent* shutdown_event, - IPC::SyncChannel* channel) - : io_message_loop_(io_message_loop), +GpuChannelManager::GpuChannelManager( + MessageRouter* router, + GpuWatchdog* watchdog, + base::SingleThreadTaskRunner* io_task_runner, + base::WaitableEvent* shutdown_event, + IPC::SyncChannel* channel) + : io_task_runner_(io_task_runner), shutdown_event_(shutdown_event), router_(router), gpu_memory_manager_( @@ -106,7 +110,7 @@ GpuChannelManager::GpuChannelManager(MessageRouter* router, relinquish_resources_pending_(false), weak_factory_(this) { DCHECK(router_); - DCHECK(io_message_loop); + DCHECK(io_task_runner); DCHECK(shutdown_event); channel_->AddFilter(filter_.get()); } @@ -206,7 +210,7 @@ void GpuChannelManager::OnEstablishChannel(int client_id, client_id, false, allow_future_sync_points)); - channel->Init(io_message_loop_.get(), shutdown_event_); + channel->Init(io_task_runner_.get(), shutdown_event_); channel_handle.name = channel->GetChannelName(); #if defined(OS_POSIX) @@ -255,12 +259,9 @@ void GpuChannelManager::OnCreateViewCommandBuffer( void GpuChannelManager::DestroyGpuMemoryBuffer( gfx::GpuMemoryBufferId id, int client_id) { - io_message_loop_->PostTask( - FROM_HERE, - base::Bind(&GpuChannelManager::DestroyGpuMemoryBufferOnIO, - base::Unretained(this), - id, - client_id)); + io_task_runner_->PostTask( + FROM_HERE, base::Bind(&GpuChannelManager::DestroyGpuMemoryBufferOnIO, + base::Unretained(this), id, client_id)); } void GpuChannelManager::DestroyGpuMemoryBufferOnIO( @@ -324,10 +325,9 @@ void GpuChannelManager::LoseAllContexts() { iter != gpu_channels_.end(); ++iter) { iter->second->MarkAllContextsLost(); } - base::MessageLoop::current()->PostTask( - FROM_HERE, - base::Bind(&GpuChannelManager::OnLoseAllContexts, - weak_factory_.GetWeakPtr())); + base::ThreadTaskRunnerHandle::Get()->PostTask( + FROM_HERE, base::Bind(&GpuChannelManager::OnLoseAllContexts, + weak_factory_.GetWeakPtr())); } void GpuChannelManager::OnLoseAllContexts() { diff --git a/content/common/gpu/gpu_channel_manager.h b/content/common/gpu/gpu_channel_manager.h index 7116fda..a15a8adb 100644 --- a/content/common/gpu/gpu_channel_manager.h +++ b/content/common/gpu/gpu_channel_manager.h @@ -13,7 +13,6 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" -#include "base/message_loop/message_loop_proxy.h" #include "build/build_config.h" #include "content/common/content_export.h" #include "content/common/content_param_traits.h" @@ -65,7 +64,7 @@ class CONTENT_EXPORT GpuChannelManager : public IPC::Listener, public: GpuChannelManager(MessageRouter* router, GpuWatchdog* watchdog, - base::MessageLoopProxy* io_message_loop, + base::SingleThreadTaskRunner* io_task_runner, base::WaitableEvent* shutdown_event, IPC::SyncChannel* channel); ~GpuChannelManager() override; @@ -138,7 +137,7 @@ class CONTENT_EXPORT GpuChannelManager : public IPC::Listener, void OnLoseAllContexts(); void CheckRelinquishGpuResources(); - scoped_refptr<base::MessageLoopProxy> io_message_loop_; + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; base::WaitableEvent* shutdown_event_; // Used to send and receive IPC messages from the browser process. diff --git a/content/common/gpu/gpu_channel_manager_unittest.cc b/content/common/gpu/gpu_channel_manager_unittest.cc index 5f190f4..2388a2e 100644 --- a/content/common/gpu/gpu_channel_manager_unittest.cc +++ b/content/common/gpu/gpu_channel_manager_unittest.cc @@ -44,7 +44,7 @@ class SimpleWorker : public Listener, public Sender { virtual void Shutdown() { WaitableEvent ipc_done(false, false); - ipc_thread_.message_loop()->PostTask( + ipc_thread_.task_runner()->PostTask( FROM_HERE, base::Bind(&SimpleWorker::OnShutdown, this, &ipc_done)); channel_.reset(); @@ -56,8 +56,8 @@ class SimpleWorker : public Listener, public Sender { protected: SyncChannel* CreateChannel() { scoped_ptr<SyncChannel> channel = SyncChannel::Create( - channel_name_, mode_, this, ipc_thread_.message_loop_proxy().get(), - true, &shutdown_event_); + channel_name_, mode_, this, ipc_thread_.task_runner().get(), true, + &shutdown_event_); return channel.release(); } @@ -111,11 +111,8 @@ class SimpleGpuClient : public IPC::SimpleWorker { void Start() override { IPC::SimpleWorker::Start(); gpu_channel_manager_.reset( - new GpuChannelManager(&router_, - NULL, - ipc_thread().message_loop_proxy().get(), - shutdown_event(), - channel())); + new GpuChannelManager(&router_, NULL, ipc_thread().task_runner().get(), + shutdown_event(), channel())); } void Shutdown() override { diff --git a/content/common/gpu/gpu_command_buffer_stub.cc b/content/common/gpu/gpu_command_buffer_stub.cc index b026052..5c878fc 100644 --- a/content/common/gpu/gpu_command_buffer_stub.cc +++ b/content/common/gpu/gpu_command_buffer_stub.cc @@ -385,9 +385,8 @@ void GpuCommandBufferStub::ScheduleDelayedWork(int64 delay) { delay = 0; } - base::MessageLoop::current()->PostDelayedTask( - FROM_HERE, - base::Bind(&GpuCommandBufferStub::PollWork, AsWeakPtr()), + base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( + FROM_HERE, base::Bind(&GpuCommandBufferStub::PollWork, AsWeakPtr()), base::TimeDelta::FromMilliseconds(delay)); } @@ -831,7 +830,7 @@ void GpuCommandBufferStub::OnCreateVideoDecoder( IPC::Message* reply_message) { TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnCreateVideoDecoder"); GpuVideoDecodeAccelerator* decoder = new GpuVideoDecodeAccelerator( - decoder_route_id, this, channel_->io_message_loop()); + decoder_route_id, this, channel_->io_task_runner()); decoder->Initialize(profile, reply_message); // decoder is registered as a DestructionObserver of this stub and will // self-delete during destruction of this stub. diff --git a/content/common/gpu/gpu_memory_manager.cc b/content/common/gpu/gpu_memory_manager.cc index c32cc92..ceedf09 100644 --- a/content/common/gpu/gpu_memory_manager.cc +++ b/content/common/gpu/gpu_memory_manager.cc @@ -117,7 +117,7 @@ void GpuMemoryManager::ScheduleManage( if (manage_immediate_scheduled_) return; if (schedule_manage_time == kScheduleManageNow) { - base::MessageLoop::current()->PostTask( + base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, base::Bind(&GpuMemoryManager::Manage, AsWeakPtr())); manage_immediate_scheduled_ = true; if (!delayed_manage_callback_.IsCancelled()) @@ -127,9 +127,8 @@ void GpuMemoryManager::ScheduleManage( return; delayed_manage_callback_.Reset(base::Bind(&GpuMemoryManager::Manage, AsWeakPtr())); - base::MessageLoop::current()->PostDelayedTask( - FROM_HERE, - delayed_manage_callback_.callback(), + base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( + FROM_HERE, delayed_manage_callback_.callback(), base::TimeDelta::FromMilliseconds(kDelayedScheduleManageTimeoutMs)); } } diff --git a/content/common/gpu/media/fake_video_decode_accelerator.cc b/content/common/gpu/media/fake_video_decode_accelerator.cc index 84a40eb..eff497f 100644 --- a/content/common/gpu/media/fake_video_decode_accelerator.cc +++ b/content/common/gpu/media/fake_video_decode_accelerator.cc @@ -6,6 +6,7 @@ #include "base/bind.h" #include "base/location.h" +#include "base/thread_task_runner_handle.h" #include "media/base/bitstream_buffer.h" #include "media/base/limits.h" #include "ui/gl/gl_context.h" @@ -28,7 +29,7 @@ FakeVideoDecodeAccelerator::FakeVideoDecodeAccelerator( gfx::GLContext* gl, gfx::Size size, const base::Callback<bool(void)>& make_context_current) - : child_message_loop_proxy_(base::MessageLoopProxy::current()), + : child_task_runner_(base::ThreadTaskRunnerHandle::Get()), client_(NULL), make_context_current_(make_context_current), gl_(gl), @@ -42,7 +43,7 @@ FakeVideoDecodeAccelerator::~FakeVideoDecodeAccelerator() { bool FakeVideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile, Client* client) { - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); if (profile == media::VIDEO_CODEC_PROFILE_UNKNOWN) { LOG(ERROR) << "unknown codec profile"; return false; @@ -60,10 +61,9 @@ void FakeVideoDecodeAccelerator::Decode( const media::BitstreamBuffer& bitstream_buffer) { int bitstream_buffer_id = bitstream_buffer.id(); queued_bitstream_ids_.push(bitstream_buffer_id); - child_message_loop_proxy_->PostTask( - FROM_HERE, - base::Bind(&FakeVideoDecodeAccelerator::DoPictureReady, - weak_this_factory_.GetWeakPtr())); + child_task_runner_->PostTask( + FROM_HERE, base::Bind(&FakeVideoDecodeAccelerator::DoPictureReady, + weak_this_factory_.GetWeakPtr())); } // Similar to UseOutputBitstreamBuffer for the encode accelerator. @@ -107,26 +107,23 @@ void FakeVideoDecodeAccelerator::AssignPictureBuffers( glBindTexture(GL_TEXTURE_2D, 0); free_output_buffers_.push(buffers[index].id()); } - child_message_loop_proxy_->PostTask( - FROM_HERE, - base::Bind(&FakeVideoDecodeAccelerator::DoPictureReady, - weak_this_factory_.GetWeakPtr())); + child_task_runner_->PostTask( + FROM_HERE, base::Bind(&FakeVideoDecodeAccelerator::DoPictureReady, + weak_this_factory_.GetWeakPtr())); } void FakeVideoDecodeAccelerator::ReusePictureBuffer(int32 picture_buffer_id) { free_output_buffers_.push(picture_buffer_id); - child_message_loop_proxy_->PostTask( - FROM_HERE, - base::Bind(&FakeVideoDecodeAccelerator::DoPictureReady, - weak_this_factory_.GetWeakPtr())); + child_task_runner_->PostTask( + FROM_HERE, base::Bind(&FakeVideoDecodeAccelerator::DoPictureReady, + weak_this_factory_.GetWeakPtr())); } void FakeVideoDecodeAccelerator::Flush() { flushing_ = true; - child_message_loop_proxy_->PostTask( - FROM_HERE, - base::Bind(&FakeVideoDecodeAccelerator::DoPictureReady, - weak_this_factory_.GetWeakPtr())); + child_task_runner_->PostTask( + FROM_HERE, base::Bind(&FakeVideoDecodeAccelerator::DoPictureReady, + weak_this_factory_.GetWeakPtr())); } void FakeVideoDecodeAccelerator::Reset() { diff --git a/content/common/gpu/media/fake_video_decode_accelerator.h b/content/common/gpu/media/fake_video_decode_accelerator.h index de7df4a..a669c82 100644 --- a/content/common/gpu/media/fake_video_decode_accelerator.h +++ b/content/common/gpu/media/fake_video_decode_accelerator.h @@ -9,7 +9,6 @@ #include <vector> #include "base/memory/weak_ptr.h" -#include "base/message_loop/message_loop_proxy.h" #include "content/common/content_export.h" #include "media/video/video_decode_accelerator.h" #include "ui/gfx/geometry/size_f.h" @@ -43,7 +42,7 @@ class CONTENT_EXPORT FakeVideoDecodeAccelerator // The message loop that created the class. Used for all callbacks. This // class expects all calls to this class to be on this message loop (not // checked). - const scoped_refptr<base::MessageLoopProxy> child_message_loop_proxy_; + const scoped_refptr<base::SingleThreadTaskRunner> child_task_runner_; Client* client_; diff --git a/content/common/gpu/media/gpu_video_decode_accelerator.cc b/content/common/gpu/media/gpu_video_decode_accelerator.cc index bcd510c..c4d7eb9 100644 --- a/content/common/gpu/media/gpu_video_decode_accelerator.cc +++ b/content/common/gpu/media/gpu_video_decode_accelerator.cc @@ -8,10 +8,12 @@ #include "base/bind.h" #include "base/command_line.h" +#include "base/location.h" #include "base/logging.h" #include "base/memory/ref_counted.h" -#include "base/message_loop/message_loop_proxy.h" +#include "base/single_thread_task_runner.h" #include "base/stl_util.h" +#include "base/thread_task_runner_handle.h" #include "content/common/gpu/gpu_channel.h" #include "content/common/gpu/gpu_messages.h" @@ -127,13 +129,13 @@ class GpuVideoDecodeAccelerator::MessageFilter : public IPC::MessageFilter { GpuVideoDecodeAccelerator::GpuVideoDecodeAccelerator( int32 host_route_id, GpuCommandBufferStub* stub, - const scoped_refptr<base::MessageLoopProxy>& io_message_loop) + const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) : host_route_id_(host_route_id), stub_(stub), texture_target_(0), filter_removed_(true, false), - child_message_loop_(base::MessageLoopProxy::current()), - io_message_loop_(io_message_loop), + child_task_runner_(base::ThreadTaskRunnerHandle::Get()), + io_task_runner_(io_task_runner), weak_factory_for_io_(this) { DCHECK(stub_); stub_->AddDestructionObserver(this); @@ -205,10 +207,10 @@ void GpuVideoDecodeAccelerator::PictureReady( // VDA may call PictureReady on IO thread. SetTextureCleared should run on // the child thread. VDA is responsible to call PictureReady on the child // thread when a picture buffer is delivered the first time. - if (child_message_loop_->BelongsToCurrentThread()) { + if (child_task_runner_->BelongsToCurrentThread()) { SetTextureCleared(picture); } else { - DCHECK(io_message_loop_->BelongsToCurrentThread()); + DCHECK(io_task_runner_->BelongsToCurrentThread()); DebugAutoLock auto_lock(debug_uncleared_textures_lock_); DCHECK_EQ(0u, uncleared_textures_.count(picture.picture_buffer_id())); } @@ -306,7 +308,7 @@ GpuVideoDecodeAccelerator::CreateV4L2VDA() { weak_factory_for_io_.GetWeakPtr(), make_context_current_, device, - io_message_loop_)); + io_task_runner_)); } #endif return decoder.Pass(); @@ -324,7 +326,7 @@ GpuVideoDecodeAccelerator::CreateV4L2SliceVDA() { stub_->decoder()->GetGLContext()->GetHandle(), weak_factory_for_io_.GetWeakPtr(), make_context_current_, - io_message_loop_)); + io_task_runner_)); } #endif return decoder.Pass(); @@ -425,10 +427,10 @@ void GpuVideoDecodeAccelerator::OnDecode( DCHECK(video_decode_accelerator_.get()); if (id < 0) { DLOG(ERROR) << "BitstreamBuffer id " << id << " out of range"; - if (child_message_loop_->BelongsToCurrentThread()) { + if (child_task_runner_->BelongsToCurrentThread()) { NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT); } else { - child_message_loop_->PostTask( + child_task_runner_->PostTask( FROM_HERE, base::Bind(&GpuVideoDecodeAccelerator::NotifyError, base::Unretained(this), @@ -588,7 +590,7 @@ void GpuVideoDecodeAccelerator::OnWillDestroyStub() { void GpuVideoDecodeAccelerator::SetTextureCleared( const media::Picture& picture) { - DCHECK(child_message_loop_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); DebugAutoLock auto_lock(debug_uncleared_textures_lock_); std::map<int32, scoped_refptr<gpu::gles2::TextureRef> >::iterator it; it = uncleared_textures_.find(picture.picture_buffer_id()); @@ -605,9 +607,9 @@ void GpuVideoDecodeAccelerator::SetTextureCleared( } bool GpuVideoDecodeAccelerator::Send(IPC::Message* message) { - if (filter_.get() && io_message_loop_->BelongsToCurrentThread()) + if (filter_.get() && io_task_runner_->BelongsToCurrentThread()) return filter_->SendOnIOThread(message); - DCHECK(child_message_loop_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); return stub_->channel()->Send(message); } diff --git a/content/common/gpu/media/gpu_video_decode_accelerator.h b/content/common/gpu/media/gpu_video_decode_accelerator.h index 85a4652..cab2a22 100644 --- a/content/common/gpu/media/gpu_video_decode_accelerator.h +++ b/content/common/gpu/media/gpu_video_decode_accelerator.h @@ -20,10 +20,6 @@ #include "media/video/video_decode_accelerator.h" #include "ui/gfx/geometry/size.h" -namespace base { -class MessageLoopProxy; -} - namespace content { class GpuVideoDecodeAccelerator @@ -38,7 +34,7 @@ class GpuVideoDecodeAccelerator GpuVideoDecodeAccelerator( int32 host_route_id, GpuCommandBufferStub* stub, - const scoped_refptr<base::MessageLoopProxy>& io_message_loop); + const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); // IPC::Listener implementation. bool OnMessageReceived(const IPC::Message& message) override; @@ -140,11 +136,11 @@ class GpuVideoDecodeAccelerator // destroy the VDA. base::WaitableEvent filter_removed_; - // GPU child message loop. - const scoped_refptr<base::MessageLoopProxy> child_message_loop_; + // GPU child thread task runner. + const scoped_refptr<base::SingleThreadTaskRunner> child_task_runner_; - // GPU IO message loop. - const scoped_refptr<base::MessageLoopProxy> io_message_loop_; + // GPU IO thread task runner. + const scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; // Weak pointers will be invalidated on IO thread. base::WeakPtrFactory<Client> weak_factory_for_io_; diff --git a/content/common/gpu/media/gpu_video_encode_accelerator.cc b/content/common/gpu/media/gpu_video_encode_accelerator.cc index 8fea29e..4dd875b 100644 --- a/content/common/gpu/media/gpu_video_encode_accelerator.cc +++ b/content/common/gpu/media/gpu_video_encode_accelerator.cc @@ -8,7 +8,6 @@ #include "base/command_line.h" #include "base/logging.h" #include "base/memory/shared_memory.h" -#include "base/message_loop/message_loop_proxy.h" #include "base/numerics/safe_math.h" #include "base/sys_info.h" #include "build/build_config.h" @@ -280,8 +279,9 @@ void GpuVideoEncodeAccelerator::OnEncode(int32 frame_id, buffer_offset, base::TimeDelta(), // It's turtles all the way down... - base::Bind(base::IgnoreResult(&base::MessageLoopProxy::PostTask), - base::MessageLoopProxy::current(), + base::Bind(base::IgnoreResult( + &base::SingleThreadTaskRunner::PostTask), + base::ThreadTaskRunnerHandle::Get(), FROM_HERE, base::Bind(&GpuVideoEncodeAccelerator::EncodeFrameFinished, weak_this_factory_.GetWeakPtr(), diff --git a/content/common/gpu/media/h264_decoder.h b/content/common/gpu/media/h264_decoder.h index 32bedaa..a82a6aa 100644 --- a/content/common/gpu/media/h264_decoder.h +++ b/content/common/gpu/media/h264_decoder.h @@ -9,7 +9,6 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" -#include "base/message_loop/message_loop_proxy.h" #include "content/common/content_export.h" #include "content/common/gpu/media/accelerated_video_decoder.h" #include "content/common/gpu/media/h264_dpb.h" diff --git a/content/common/gpu/media/v4l2_image_processor.cc b/content/common/gpu/media/v4l2_image_processor.cc index 8894661..4063e4c 100644 --- a/content/common/gpu/media/v4l2_image_processor.cc +++ b/content/common/gpu/media/v4l2_image_processor.cc @@ -12,7 +12,6 @@ #include "base/bind.h" #include "base/bind_helpers.h" #include "base/callback.h" -#include "base/message_loop/message_loop_proxy.h" #include "base/numerics/safe_conversions.h" #include "content/common/gpu/media/v4l2_image_processor.h" #include "media/base/bind_to_current_loop.h" @@ -71,7 +70,7 @@ V4L2ImageProcessor::V4L2ImageProcessor(const scoped_refptr<V4L2Device>& device) output_format_fourcc_(0), input_planes_count_(0), output_planes_count_(0), - child_message_loop_proxy_(base::MessageLoopProxy::current()), + child_task_runner_(base::ThreadTaskRunnerHandle::Get()), device_(device), device_thread_("V4L2ImageProcessorThread"), device_poll_thread_("V4L2ImageProcessorDevicePollThread"), @@ -83,7 +82,7 @@ V4L2ImageProcessor::V4L2ImageProcessor(const scoped_refptr<V4L2Device>& device) } V4L2ImageProcessor::~V4L2ImageProcessor() { - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); DCHECK(!device_thread_.IsRunning()); DCHECK(!device_poll_thread_.IsRunning()); @@ -92,8 +91,8 @@ V4L2ImageProcessor::~V4L2ImageProcessor() { } void V4L2ImageProcessor::NotifyError() { - if (!child_message_loop_proxy_->BelongsToCurrentThread()) - child_message_loop_proxy_->PostTask(FROM_HERE, error_cb_); + if (!child_task_runner_->BelongsToCurrentThread()) + child_task_runner_->PostTask(FROM_HERE, error_cb_); else error_cb_.Run(); } @@ -195,7 +194,7 @@ void V4L2ImageProcessor::ProcessTask(scoped_ptr<JobRecord> job_record) { void V4L2ImageProcessor::Destroy() { DVLOG(3) << __func__; - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); // If the device thread is running, destroy using posted task. if (device_thread_.IsRunning()) { @@ -224,7 +223,7 @@ void V4L2ImageProcessor::DestroyTask() { bool V4L2ImageProcessor::CreateInputBuffers() { DVLOG(3) << __func__; - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); DCHECK(!input_streamon_); struct v4l2_control control; @@ -295,7 +294,7 @@ bool V4L2ImageProcessor::CreateInputBuffers() { bool V4L2ImageProcessor::CreateOutputBuffers() { DVLOG(3) << __func__; - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); DCHECK(!output_streamon_); struct v4l2_format format; @@ -358,7 +357,7 @@ bool V4L2ImageProcessor::CreateOutputBuffers() { } void V4L2ImageProcessor::DestroyInputBuffers() { - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); DCHECK(!input_streamon_); struct v4l2_requestbuffers reqbufs; @@ -373,7 +372,7 @@ void V4L2ImageProcessor::DestroyInputBuffers() { } void V4L2ImageProcessor::DestroyOutputBuffers() { - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); DCHECK(!output_streamon_); for (size_t buf = 0; buf < output_buffer_map_.size(); ++buf) { @@ -570,7 +569,7 @@ void V4L2ImageProcessor::Dequeue() { DVLOG(3) << "Processing finished, returning frame, ts=" << output_frame->timestamp().InMilliseconds(); - child_message_loop_proxy_->PostTask( + child_task_runner_->PostTask( FROM_HERE, base::Bind(job_record->ready_cb, output_frame)); } } diff --git a/content/common/gpu/media/v4l2_image_processor.h b/content/common/gpu/media/v4l2_image_processor.h index f396b0b..5b8069d 100644 --- a/content/common/gpu/media/v4l2_image_processor.h +++ b/content/common/gpu/media/v4l2_image_processor.h @@ -133,8 +133,8 @@ class CONTENT_EXPORT V4L2ImageProcessor { size_t input_planes_count_; size_t output_planes_count_; - // Our original calling message loop for the child thread. - const scoped_refptr<base::MessageLoopProxy> child_message_loop_proxy_; + // Our original calling task runner for the child thread. + const scoped_refptr<base::SingleThreadTaskRunner> child_task_runner_; // V4L2 device in use. scoped_refptr<V4L2Device> device_; diff --git a/content/common/gpu/media/v4l2_slice_video_decode_accelerator.cc b/content/common/gpu/media/v4l2_slice_video_decode_accelerator.cc index 4a7d8ec..c1853cb 100644 --- a/content/common/gpu/media/v4l2_slice_video_decode_accelerator.cc +++ b/content/common/gpu/media/v4l2_slice_video_decode_accelerator.cc @@ -14,7 +14,6 @@ #include "base/callback.h" #include "base/callback_helpers.h" #include "base/command_line.h" -#include "base/message_loop/message_loop_proxy.h" #include "base/numerics/safe_conversions.h" #include "base/strings/stringprintf.h" #include "content/common/gpu/media/v4l2_slice_video_decode_accelerator.h" @@ -162,13 +161,13 @@ V4L2SliceVideoDecodeAccelerator::OutputRecord::OutputRecord() struct V4L2SliceVideoDecodeAccelerator::BitstreamBufferRef { BitstreamBufferRef( base::WeakPtr<VideoDecodeAccelerator::Client>& client, - const scoped_refptr<base::MessageLoopProxy>& client_message_loop_proxy, + const scoped_refptr<base::SingleThreadTaskRunner>& client_task_runner, base::SharedMemory* shm, size_t size, int32 input_id); ~BitstreamBufferRef(); const base::WeakPtr<VideoDecodeAccelerator::Client> client; - const scoped_refptr<base::MessageLoopProxy> client_message_loop_proxy; + const scoped_refptr<base::SingleThreadTaskRunner> client_task_runner; const scoped_ptr<base::SharedMemory> shm; const size_t size; off_t bytes_used; @@ -177,12 +176,12 @@ struct V4L2SliceVideoDecodeAccelerator::BitstreamBufferRef { V4L2SliceVideoDecodeAccelerator::BitstreamBufferRef::BitstreamBufferRef( base::WeakPtr<VideoDecodeAccelerator::Client>& client, - const scoped_refptr<base::MessageLoopProxy>& client_message_loop_proxy, + const scoped_refptr<base::SingleThreadTaskRunner>& client_task_runner, base::SharedMemory* shm, size_t size, int32 input_id) : client(client), - client_message_loop_proxy(client_message_loop_proxy), + client_task_runner(client_task_runner), shm(shm), size(size), bytes_used(0), @@ -192,7 +191,7 @@ V4L2SliceVideoDecodeAccelerator::BitstreamBufferRef::BitstreamBufferRef( V4L2SliceVideoDecodeAccelerator::BitstreamBufferRef::~BitstreamBufferRef() { if (input_id >= 0) { DVLOGF(5) << "returning input_id: " << input_id; - client_message_loop_proxy->PostTask( + client_task_runner->PostTask( FROM_HERE, base::Bind(&VideoDecodeAccelerator::Client::NotifyEndOfBitstreamBuffer, client, input_id)); @@ -380,11 +379,11 @@ V4L2SliceVideoDecodeAccelerator::V4L2SliceVideoDecodeAccelerator( EGLContext egl_context, const base::WeakPtr<Client>& io_client, const base::Callback<bool(void)>& make_context_current, - const scoped_refptr<base::MessageLoopProxy>& io_message_loop_proxy) + const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) : input_planes_count_(0), output_planes_count_(0), - child_message_loop_proxy_(base::MessageLoopProxy::current()), - io_message_loop_proxy_(io_message_loop_proxy), + child_task_runner_(base::ThreadTaskRunnerHandle::Get()), + io_task_runner_(io_task_runner), io_client_(io_client), device_(device), decoder_thread_("V4L2SliceVideoDecodeAcceleratorThread"), @@ -411,7 +410,7 @@ V4L2SliceVideoDecodeAccelerator::V4L2SliceVideoDecodeAccelerator( V4L2SliceVideoDecodeAccelerator::~V4L2SliceVideoDecodeAccelerator() { DVLOGF(2); - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); DCHECK(!decoder_thread_.IsRunning()); DCHECK(!device_poll_thread_.IsRunning()); @@ -420,8 +419,8 @@ V4L2SliceVideoDecodeAccelerator::~V4L2SliceVideoDecodeAccelerator() { } void V4L2SliceVideoDecodeAccelerator::NotifyError(Error error) { - if (!child_message_loop_proxy_->BelongsToCurrentThread()) { - child_message_loop_proxy_->PostTask( + if (!child_task_runner_->BelongsToCurrentThread()) { + child_task_runner_->PostTask( FROM_HERE, base::Bind(&V4L2SliceVideoDecodeAccelerator::NotifyError, weak_this_, error)); return; @@ -437,7 +436,7 @@ bool V4L2SliceVideoDecodeAccelerator::Initialize( media::VideoCodecProfile profile, VideoDecodeAccelerator::Client* client) { DVLOGF(3) << "profile: " << profile; - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); DCHECK_EQ(state_, kUninitialized); client_ptr_factory_.reset( @@ -499,12 +498,12 @@ bool V4L2SliceVideoDecodeAccelerator::Initialize( DLOG(ERROR) << "Initialize(): device thread failed to start"; return false; } - decoder_thread_proxy_ = decoder_thread_.message_loop_proxy(); + decoder_thread_task_runner_ = decoder_thread_.task_runner(); state_ = kInitialized; // InitializeTask will NOTIFY_ERROR on failure. - decoder_thread_proxy_->PostTask( + decoder_thread_task_runner_->PostTask( FROM_HERE, base::Bind(&V4L2SliceVideoDecodeAccelerator::InitializeTask, base::Unretained(this))); @@ -514,7 +513,7 @@ bool V4L2SliceVideoDecodeAccelerator::Initialize( void V4L2SliceVideoDecodeAccelerator::InitializeTask() { DVLOGF(3); - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); DCHECK_EQ(state_, kInitialized); if (!CreateInputBuffers()) @@ -527,10 +526,10 @@ void V4L2SliceVideoDecodeAccelerator::InitializeTask() { void V4L2SliceVideoDecodeAccelerator::Destroy() { DVLOGF(3); - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); if (decoder_thread_.IsRunning()) { - decoder_thread_proxy_->PostTask( + decoder_thread_task_runner_->PostTask( FROM_HERE, base::Bind(&V4L2SliceVideoDecodeAccelerator::DestroyTask, base::Unretained(this))); @@ -544,7 +543,7 @@ void V4L2SliceVideoDecodeAccelerator::Destroy() { void V4L2SliceVideoDecodeAccelerator::DestroyTask() { DVLOGF(3); - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); state_ = kError; @@ -625,7 +624,7 @@ bool V4L2SliceVideoDecodeAccelerator::SetupFormats() { bool V4L2SliceVideoDecodeAccelerator::CreateInputBuffers() { DVLOGF(3); - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); DCHECK(!input_streamon_); DCHECK(input_buffer_map_.empty()); @@ -672,7 +671,7 @@ bool V4L2SliceVideoDecodeAccelerator::CreateInputBuffers() { bool V4L2SliceVideoDecodeAccelerator::CreateOutputBuffers() { DVLOGF(3); - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); DCHECK(!output_streamon_); DCHECK(output_buffer_map_.empty()); DCHECK(surfaces_at_display_.empty()); @@ -726,7 +725,7 @@ bool V4L2SliceVideoDecodeAccelerator::CreateOutputBuffers() { << ", visible size=" << visible_size_.ToString() << ", coded size=" << coded_size_.ToString(); - child_message_loop_proxy_->PostTask( + child_task_runner_->PostTask( FROM_HERE, base::Bind(&VideoDecodeAccelerator::Client::ProvidePictureBuffers, client_, output_buffer_map_.size(), coded_size_, @@ -743,7 +742,7 @@ bool V4L2SliceVideoDecodeAccelerator::CreateOutputBuffers() { void V4L2SliceVideoDecodeAccelerator::DestroyInputBuffers() { DVLOGF(3); - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread() || + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread() || !decoder_thread_.IsRunning()); DCHECK(!input_streamon_); @@ -767,7 +766,7 @@ void V4L2SliceVideoDecodeAccelerator::DismissPictures( std::vector<int32> picture_buffer_ids, base::WaitableEvent* done) { DVLOGF(3); - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); for (auto picture_buffer_id : picture_buffer_ids) { DVLOGF(1) << "dismissing PictureBuffer id=" << picture_buffer_id; @@ -789,14 +788,14 @@ void V4L2SliceVideoDecodeAccelerator::DevicePollTask(bool poll_device) { // All processing should happen on ServiceDeviceTask(), since we shouldn't // touch encoder state from this thread. - decoder_thread_proxy_->PostTask( + decoder_thread_task_runner_->PostTask( FROM_HERE, base::Bind(&V4L2SliceVideoDecodeAccelerator::ServiceDeviceTask, base::Unretained(this))); } void V4L2SliceVideoDecodeAccelerator::ServiceDeviceTask() { DVLOGF(4); - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); // ServiceDeviceTask() should only ever be scheduled from DevicePollTask(). @@ -805,7 +804,7 @@ void V4L2SliceVideoDecodeAccelerator::ServiceDeviceTask() { } void V4L2SliceVideoDecodeAccelerator::SchedulePollIfNeeded() { - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); if (!device_poll_thread_.IsRunning()) { DVLOGF(2) << "Device poll thread stopped, will not schedule poll"; @@ -840,7 +839,7 @@ void V4L2SliceVideoDecodeAccelerator::SchedulePollIfNeeded() { void V4L2SliceVideoDecodeAccelerator::Enqueue( const scoped_refptr<V4L2DecodeSurface>& dec_surface) { - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); const int old_inputs_queued = input_buffer_queued_count_; const int old_outputs_queued = output_buffer_queued_count_; @@ -869,7 +868,7 @@ void V4L2SliceVideoDecodeAccelerator::Enqueue( void V4L2SliceVideoDecodeAccelerator::Dequeue() { DVLOGF(3); - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); struct v4l2_buffer dqbuf; struct v4l2_plane planes[VIDEO_MAX_PLANES]; @@ -954,7 +953,7 @@ void V4L2SliceVideoDecodeAccelerator::ProcessPendingEventsIfNeeded() { void V4L2SliceVideoDecodeAccelerator::ReuseInputBuffer(int index) { DVLOGF(4) << "Reusing input buffer, index=" << index; - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); DCHECK_LT(index, static_cast<int>(input_buffer_map_.size())); InputRecord& input_record = input_buffer_map_[index]; @@ -970,7 +969,7 @@ void V4L2SliceVideoDecodeAccelerator::ReuseInputBuffer(int index) { void V4L2SliceVideoDecodeAccelerator::ReuseOutputBuffer(int index) { DVLOGF(4) << "Reusing output buffer, index=" << index; - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); DCHECK_LT(index, static_cast<int>(output_buffer_map_.size())); OutputRecord& output_record = output_buffer_map_[index]; @@ -1062,7 +1061,7 @@ bool V4L2SliceVideoDecodeAccelerator::EnqueueOutputRecord(int index) { bool V4L2SliceVideoDecodeAccelerator::StartDevicePoll() { DVLOGF(3) << "Starting device poll"; - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); DCHECK(!device_poll_thread_.IsRunning()); // Start up the device poll thread and schedule its first DevicePollTask(). @@ -1093,7 +1092,7 @@ bool V4L2SliceVideoDecodeAccelerator::StartDevicePoll() { bool V4L2SliceVideoDecodeAccelerator::StopDevicePoll(bool keep_input_state) { DVLOGF(3) << "Stopping device poll"; if (decoder_thread_.IsRunning()) - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); // Signal the DevicePollTask() to stop, and stop the device poll thread. if (!device_->SetDevicePollInterrupt()) { @@ -1161,9 +1160,9 @@ void V4L2SliceVideoDecodeAccelerator::Decode( const media::BitstreamBuffer& bitstream_buffer) { DVLOGF(3) << "input_id=" << bitstream_buffer.id() << ", size=" << bitstream_buffer.size(); - DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(io_task_runner_->BelongsToCurrentThread()); - decoder_thread_proxy_->PostTask( + decoder_thread_task_runner_->PostTask( FROM_HERE, base::Bind(&V4L2SliceVideoDecodeAccelerator::DecodeTask, base::Unretained(this), bitstream_buffer)); } @@ -1172,10 +1171,10 @@ void V4L2SliceVideoDecodeAccelerator::DecodeTask( const media::BitstreamBuffer& bitstream_buffer) { DVLOGF(3) << "input_id=" << bitstream_buffer.id() << " size=" << bitstream_buffer.size(); - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); scoped_ptr<BitstreamBufferRef> bitstream_record(new BitstreamBufferRef( - io_client_, io_message_loop_proxy_, + io_client_, io_task_runner_, new base::SharedMemory(bitstream_buffer.handle(), true), bitstream_buffer.size(), bitstream_buffer.id())); if (!bitstream_record->shm->Map(bitstream_buffer.size())) { @@ -1192,7 +1191,7 @@ void V4L2SliceVideoDecodeAccelerator::DecodeTask( } bool V4L2SliceVideoDecodeAccelerator::TrySetNewBistreamBuffer() { - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); DCHECK(!decoder_current_bitstream_buffer_); if (decoder_input_queue_.empty()) @@ -1217,9 +1216,9 @@ bool V4L2SliceVideoDecodeAccelerator::TrySetNewBistreamBuffer() { } void V4L2SliceVideoDecodeAccelerator::ScheduleDecodeBufferTaskIfNeeded() { - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); if (state_ == kDecoding) { - decoder_thread_proxy_->PostTask( + decoder_thread_task_runner_->PostTask( FROM_HERE, base::Bind(&V4L2SliceVideoDecodeAccelerator::DecodeBufferTask, base::Unretained(this))); @@ -1228,7 +1227,7 @@ void V4L2SliceVideoDecodeAccelerator::ScheduleDecodeBufferTaskIfNeeded() { void V4L2SliceVideoDecodeAccelerator::DecodeBufferTask() { DVLOGF(3); - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); if (state_ != kDecoding) { DVLOGF(3) << "Early exit, not in kDecoding"; @@ -1266,7 +1265,7 @@ void V4L2SliceVideoDecodeAccelerator::DecodeBufferTask() { void V4L2SliceVideoDecodeAccelerator::InitiateSurfaceSetChange() { DVLOGF(2); - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); DCHECK_EQ(state_, kDecoding); state_ = kIdle; @@ -1279,7 +1278,7 @@ void V4L2SliceVideoDecodeAccelerator::InitiateSurfaceSetChange() { void V4L2SliceVideoDecodeAccelerator::FinishSurfaceSetChangeIfNeeded() { DVLOGF(2); - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); if (!surface_set_change_pending_ || !surfaces_at_device_.empty()) return; @@ -1326,7 +1325,7 @@ void V4L2SliceVideoDecodeAccelerator::FinishSurfaceSetChangeIfNeeded() { bool V4L2SliceVideoDecodeAccelerator::DestroyOutputs(bool dismiss) { DVLOGF(3); - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); std::vector<EGLImageKHR> egl_images_to_destroy; std::vector<int32> picture_buffers_to_dismiss; @@ -1342,7 +1341,7 @@ bool V4L2SliceVideoDecodeAccelerator::DestroyOutputs(bool dismiss) { } if (output_record.egl_image != EGL_NO_IMAGE_KHR) { - child_message_loop_proxy_->PostTask( + child_task_runner_->PostTask( FROM_HERE, base::Bind(base::IgnoreResult(&V4L2Device::DestroyEGLImage), device_, egl_display_, output_record.egl_image)); @@ -1354,7 +1353,7 @@ bool V4L2SliceVideoDecodeAccelerator::DestroyOutputs(bool dismiss) { if (dismiss) { DVLOGF(2) << "Scheduling picture dismissal"; base::WaitableEvent done(false, false); - child_message_loop_proxy_->PostTask( + child_task_runner_->PostTask( FROM_HERE, base::Bind(&V4L2SliceVideoDecodeAccelerator::DismissPictures, weak_this_, picture_buffers_to_dismiss, &done)); done.Wait(); @@ -1367,7 +1366,7 @@ bool V4L2SliceVideoDecodeAccelerator::DestroyOutputs(bool dismiss) { bool V4L2SliceVideoDecodeAccelerator::DestroyOutputBuffers() { DVLOGF(3); - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread() || + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread() || !decoder_thread_.IsRunning()); DCHECK(!output_streamon_); DCHECK(surfaces_at_device_.empty()); @@ -1409,7 +1408,7 @@ bool V4L2SliceVideoDecodeAccelerator::DestroyOutputBuffers() { void V4L2SliceVideoDecodeAccelerator::AssignPictureBuffers( const std::vector<media::PictureBuffer>& buffers) { DVLOGF(3); - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); if (buffers.size() != output_buffer_map_.size()) { DLOG(ERROR) << "Failed to provide requested picture buffers. " @@ -1468,7 +1467,7 @@ void V4L2SliceVideoDecodeAccelerator::AssignPictureBuffers( void V4L2SliceVideoDecodeAccelerator::ReusePictureBuffer( int32 picture_buffer_id) { - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); DVLOGF(4) << "picture_buffer_id=" << picture_buffer_id; if (!make_context_current_.Run()) { @@ -1487,7 +1486,7 @@ void V4L2SliceVideoDecodeAccelerator::ReusePictureBuffer( scoped_ptr<EGLSyncKHRRef> egl_sync_ref( new EGLSyncKHRRef(egl_display_, egl_sync)); - decoder_thread_proxy_->PostTask( + decoder_thread_task_runner_->PostTask( FROM_HERE, base::Bind(&V4L2SliceVideoDecodeAccelerator::ReusePictureBufferTask, base::Unretained(this), picture_buffer_id, @@ -1498,7 +1497,7 @@ void V4L2SliceVideoDecodeAccelerator::ReusePictureBufferTask( int32 picture_buffer_id, scoped_ptr<EGLSyncKHRRef> egl_sync_ref) { DVLOGF(3) << "picture_buffer_id=" << picture_buffer_id; - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); V4L2DecodeSurfaceByPictureBufferId::iterator it = surfaces_at_display_.find(picture_buffer_id); @@ -1531,23 +1530,23 @@ void V4L2SliceVideoDecodeAccelerator::ReusePictureBufferTask( void V4L2SliceVideoDecodeAccelerator::Flush() { DVLOGF(3); - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); - decoder_thread_proxy_->PostTask( + decoder_thread_task_runner_->PostTask( FROM_HERE, base::Bind(&V4L2SliceVideoDecodeAccelerator::FlushTask, base::Unretained(this))); } void V4L2SliceVideoDecodeAccelerator::FlushTask() { DVLOGF(3); - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); if (!decoder_input_queue_.empty()) { // We are not done with pending inputs, so queue an empty buffer, // which - when reached - will trigger flush sequence. decoder_input_queue_.push( linked_ptr<BitstreamBufferRef>(new BitstreamBufferRef( - io_client_, io_message_loop_proxy_, nullptr, 0, kFlushBufferId))); + io_client_, io_task_runner_, nullptr, 0, kFlushBufferId))); return; } @@ -1557,7 +1556,7 @@ void V4L2SliceVideoDecodeAccelerator::FlushTask() { void V4L2SliceVideoDecodeAccelerator::InitiateFlush() { DVLOGF(3); - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); DCHECK(!decoder_flushing_); DCHECK_EQ(state_, kDecoding); @@ -1577,7 +1576,7 @@ void V4L2SliceVideoDecodeAccelerator::InitiateFlush() { decoder_flushing_ = true; - decoder_thread_proxy_->PostTask( + decoder_thread_task_runner_->PostTask( FROM_HERE, base::Bind(&V4L2SliceVideoDecodeAccelerator::FinishFlushIfNeeded, base::Unretained(this))); @@ -1585,7 +1584,7 @@ void V4L2SliceVideoDecodeAccelerator::InitiateFlush() { void V4L2SliceVideoDecodeAccelerator::FinishFlushIfNeeded() { DVLOGF(3); - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); if (!decoder_flushing_ || !surfaces_at_device_.empty()) return; @@ -1606,8 +1605,8 @@ void V4L2SliceVideoDecodeAccelerator::FinishFlushIfNeeded() { SendPictureReady(); - child_message_loop_proxy_->PostTask( - FROM_HERE, base::Bind(&Client::NotifyFlushDone, client_)); + child_task_runner_->PostTask(FROM_HERE, + base::Bind(&Client::NotifyFlushDone, client_)); decoder_flushing_ = false; @@ -1618,16 +1617,16 @@ void V4L2SliceVideoDecodeAccelerator::FinishFlushIfNeeded() { void V4L2SliceVideoDecodeAccelerator::Reset() { DVLOGF(3); - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); - decoder_thread_proxy_->PostTask( + decoder_thread_task_runner_->PostTask( FROM_HERE, base::Bind(&V4L2SliceVideoDecodeAccelerator::ResetTask, base::Unretained(this))); } void V4L2SliceVideoDecodeAccelerator::ResetTask() { DVLOGF(3); - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); if (decoder_resetting_) { // This is a bug in the client, multiple Reset()s before NotifyResetDone() @@ -1654,7 +1653,7 @@ void V4L2SliceVideoDecodeAccelerator::ResetTask() { void V4L2SliceVideoDecodeAccelerator::FinishResetIfNeeded() { DVLOGF(3); - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); if (!decoder_resetting_ || !surfaces_at_device_.empty()) return; @@ -1682,8 +1681,8 @@ void V4L2SliceVideoDecodeAccelerator::FinishResetIfNeeded() { decoder_resetting_ = false; - child_message_loop_proxy_->PostTask( - FROM_HERE, base::Bind(&Client::NotifyResetDone, client_)); + child_task_runner_->PostTask(FROM_HERE, + base::Bind(&Client::NotifyResetDone, client_)); DVLOGF(3) << "Reset finished"; @@ -1695,8 +1694,8 @@ void V4L2SliceVideoDecodeAccelerator::SetErrorState(Error error) { // We can touch decoder_state_ only if this is the decoder thread or the // decoder thread isn't running. if (decoder_thread_.IsRunning() && - !decoder_thread_proxy_->BelongsToCurrentThread()) { - decoder_thread_proxy_->PostTask( + !decoder_thread_task_runner_->BelongsToCurrentThread()) { + decoder_thread_task_runner_->PostTask( FROM_HERE, base::Bind(&V4L2SliceVideoDecodeAccelerator::SetErrorState, base::Unretained(this), error)); return; @@ -2049,7 +2048,7 @@ bool V4L2SliceVideoDecodeAccelerator::V4L2H264Accelerator::SubmitSlice( bool V4L2SliceVideoDecodeAccelerator::SubmitSlice(int index, const uint8_t* data, size_t size) { - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); InputRecord& input_record = input_buffer_map_[index]; @@ -2361,7 +2360,7 @@ V4L2SliceVideoDecodeAccelerator::V4L2VP8Accelerator:: void V4L2SliceVideoDecodeAccelerator::DecodeSurface( const scoped_refptr<V4L2DecodeSurface>& dec_surface) { - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); DVLOGF(3) << "Submitting decode for surface: " << dec_surface->ToString(); Enqueue(dec_surface); @@ -2370,7 +2369,7 @@ void V4L2SliceVideoDecodeAccelerator::DecodeSurface( void V4L2SliceVideoDecodeAccelerator::SurfaceReady( const scoped_refptr<V4L2DecodeSurface>& dec_surface) { DVLOGF(3); - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); decoder_display_queue_.push(dec_surface); TryOutputSurfaces(); @@ -2391,7 +2390,7 @@ void V4L2SliceVideoDecodeAccelerator::TryOutputSurfaces() { void V4L2SliceVideoDecodeAccelerator::OutputSurface( const scoped_refptr<V4L2DecodeSurface>& dec_surface) { - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); OutputRecord& output_record = output_buffer_map_[dec_surface->output_record()]; @@ -2419,7 +2418,7 @@ void V4L2SliceVideoDecodeAccelerator::OutputSurface( scoped_refptr<V4L2SliceVideoDecodeAccelerator::V4L2DecodeSurface> V4L2SliceVideoDecodeAccelerator::CreateSurface() { - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); DCHECK_EQ(state_, kDecoding); if (free_input_buffers_.empty() || free_output_buffers_.empty()) @@ -2447,7 +2446,7 @@ V4L2SliceVideoDecodeAccelerator::CreateSurface() { void V4L2SliceVideoDecodeAccelerator::SendPictureReady() { DVLOGF(3); - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); bool resetting_or_flushing = (decoder_resetting_ || decoder_flushing_); while (!pending_picture_ready_.empty()) { bool cleared = pending_picture_ready_.front().cleared; @@ -2457,7 +2456,7 @@ void V4L2SliceVideoDecodeAccelerator::SendPictureReady() { << picture.picture_buffer_id(); // This picture is cleared. Post it to IO thread to reduce latency. This // should be the case after all pictures are cleared at the beginning. - io_message_loop_proxy_->PostTask( + io_task_runner_->PostTask( FROM_HERE, base::Bind(&Client::PictureReady, io_client_, picture)); pending_picture_ready_.pop(); } else if (!cleared || resetting_or_flushing) { @@ -2471,7 +2470,7 @@ void V4L2SliceVideoDecodeAccelerator::SendPictureReady() { // has to be cleared in the child thread. A picture only needs to be // cleared once. If the decoder is resetting or flushing, send all // pictures to ensure PictureReady arrive before reset or flush done. - child_message_loop_proxy_->PostTaskAndReply( + child_task_runner_->PostTaskAndReply( FROM_HERE, base::Bind(&Client::PictureReady, client_, picture), // Unretained is safe. If Client::PictureReady gets to run, |this| is // alive. Destroy() will wait the decode thread to finish. @@ -2490,7 +2489,7 @@ void V4L2SliceVideoDecodeAccelerator::SendPictureReady() { void V4L2SliceVideoDecodeAccelerator::PictureCleared() { DVLOGF(3) << "clearing count=" << picture_clearing_count_; - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); DCHECK_GT(picture_clearing_count_, 0); picture_clearing_count_--; SendPictureReady(); diff --git a/content/common/gpu/media/v4l2_slice_video_decode_accelerator.h b/content/common/gpu/media/v4l2_slice_video_decode_accelerator.h index b6ecf0e..dd12487 100644 --- a/content/common/gpu/media/v4l2_slice_video_decode_accelerator.h +++ b/content/common/gpu/media/v4l2_slice_video_decode_accelerator.h @@ -38,7 +38,7 @@ class CONTENT_EXPORT V4L2SliceVideoDecodeAccelerator EGLContext egl_context, const base::WeakPtr<Client>& io_client_, const base::Callback<bool(void)>& make_context_current, - const scoped_refptr<base::MessageLoopProxy>& io_message_loop_proxy); + const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); ~V4L2SliceVideoDecodeAccelerator() override; // media::VideoDecodeAccelerator implementation. @@ -274,11 +274,11 @@ class CONTENT_EXPORT V4L2SliceVideoDecodeAccelerator size_t input_planes_count_; size_t output_planes_count_; - // GPU Child thread message loop. - const scoped_refptr<base::MessageLoopProxy> child_message_loop_proxy_; + // GPU Child thread task runner. + const scoped_refptr<base::SingleThreadTaskRunner> child_task_runner_; - // IO thread message loop. - scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; + // IO thread task runner. + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; // WeakPtr<> pointing to |this| for use in posting tasks from the decoder or // device worker threads back to the child thread. @@ -286,11 +286,11 @@ class CONTENT_EXPORT V4L2SliceVideoDecodeAccelerator // To expose client callbacks from VideoDecodeAccelerator. // NOTE: all calls to these objects *MUST* be executed on - // child_message_loop_proxy_. + // child_task_runner_. scoped_ptr<base::WeakPtrFactory<VideoDecodeAccelerator::Client>> client_ptr_factory_; base::WeakPtr<VideoDecodeAccelerator::Client> client_; - // Callbacks to |io_client_| must be executed on |io_message_loop_proxy_|. + // Callbacks to |io_client_| must be executed on |io_task_runner_|. base::WeakPtr<Client> io_client_; // V4L2 device in use. @@ -298,7 +298,7 @@ class CONTENT_EXPORT V4L2SliceVideoDecodeAccelerator // Thread to communicate with the device on. base::Thread decoder_thread_; - scoped_refptr<base::MessageLoopProxy> decoder_thread_proxy_; + scoped_refptr<base::SingleThreadTaskRunner> decoder_thread_task_runner_; // Thread used to poll the device for events. base::Thread device_poll_thread_; diff --git a/content/common/gpu/media/v4l2_video_decode_accelerator.cc b/content/common/gpu/media/v4l2_video_decode_accelerator.cc index bf83407..dfd0866 100644 --- a/content/common/gpu/media/v4l2_video_decode_accelerator.cc +++ b/content/common/gpu/media/v4l2_video_decode_accelerator.cc @@ -15,8 +15,8 @@ #include "base/command_line.h" #include "base/memory/shared_memory.h" #include "base/message_loop/message_loop.h" -#include "base/message_loop/message_loop_proxy.h" #include "base/numerics/safe_conversions.h" +#include "base/thread_task_runner_handle.h" #include "base/trace_event/trace_event.h" #include "content/common/gpu/media/v4l2_video_decode_accelerator.h" #include "media/base/media_switches.h" @@ -65,13 +65,13 @@ namespace { struct V4L2VideoDecodeAccelerator::BitstreamBufferRef { BitstreamBufferRef( base::WeakPtr<Client>& client, - scoped_refptr<base::MessageLoopProxy>& client_message_loop_proxy, + scoped_refptr<base::SingleThreadTaskRunner>& client_task_runner, base::SharedMemory* shm, size_t size, int32 input_id); ~BitstreamBufferRef(); const base::WeakPtr<Client> client; - const scoped_refptr<base::MessageLoopProxy> client_message_loop_proxy; + const scoped_refptr<base::SingleThreadTaskRunner> client_task_runner; const scoped_ptr<base::SharedMemory> shm; const size_t size; size_t bytes_used; @@ -94,10 +94,12 @@ struct V4L2VideoDecodeAccelerator::PictureRecord { V4L2VideoDecodeAccelerator::BitstreamBufferRef::BitstreamBufferRef( base::WeakPtr<Client>& client, - scoped_refptr<base::MessageLoopProxy>& client_message_loop_proxy, - base::SharedMemory* shm, size_t size, int32 input_id) + scoped_refptr<base::SingleThreadTaskRunner>& client_task_runner, + base::SharedMemory* shm, + size_t size, + int32 input_id) : client(client), - client_message_loop_proxy(client_message_loop_proxy), + client_task_runner(client_task_runner), shm(shm), size(size), bytes_used(0), @@ -106,8 +108,9 @@ V4L2VideoDecodeAccelerator::BitstreamBufferRef::BitstreamBufferRef( V4L2VideoDecodeAccelerator::BitstreamBufferRef::~BitstreamBufferRef() { if (input_id >= 0) { - client_message_loop_proxy->PostTask(FROM_HERE, base::Bind( - &Client::NotifyEndOfBitstreamBuffer, client, input_id)); + client_task_runner->PostTask( + FROM_HERE, + base::Bind(&Client::NotifyEndOfBitstreamBuffer, client, input_id)); } } @@ -160,9 +163,9 @@ V4L2VideoDecodeAccelerator::V4L2VideoDecodeAccelerator( const base::WeakPtr<Client>& io_client, const base::Callback<bool(void)>& make_context_current, const scoped_refptr<V4L2Device>& device, - const scoped_refptr<base::MessageLoopProxy>& io_message_loop_proxy) - : child_message_loop_proxy_(base::MessageLoopProxy::current()), - io_message_loop_proxy_(io_message_loop_proxy), + const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) + : child_task_runner_(base::ThreadTaskRunnerHandle::Get()), + io_task_runner_(io_task_runner), io_client_(io_client), decoder_thread_("V4L2DecoderThread"), decoder_state_(kUninitialized), @@ -209,7 +212,7 @@ V4L2VideoDecodeAccelerator::~V4L2VideoDecodeAccelerator() { bool V4L2VideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile, Client* client) { DVLOG(3) << "Initialize()"; - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); DCHECK_EQ(decoder_state_, kUninitialized); client_ptr_factory_.reset(new base::WeakPtrFactory<Client>(client)); @@ -307,7 +310,7 @@ void V4L2VideoDecodeAccelerator::Decode( const media::BitstreamBuffer& bitstream_buffer) { DVLOG(1) << "Decode(): input_id=" << bitstream_buffer.id() << ", size=" << bitstream_buffer.size(); - DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(io_task_runner_->BelongsToCurrentThread()); // DecodeTask() will take care of running a DecodeBufferTask(). decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( @@ -318,7 +321,7 @@ void V4L2VideoDecodeAccelerator::Decode( void V4L2VideoDecodeAccelerator::AssignPictureBuffers( const std::vector<media::PictureBuffer>& buffers) { DVLOG(3) << "AssignPictureBuffers(): buffer_count=" << buffers.size(); - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); if (buffers.size() != output_buffer_map_.size()) { LOG(ERROR) << "AssignPictureBuffers(): Failed to provide requested picture" @@ -379,7 +382,7 @@ void V4L2VideoDecodeAccelerator::AssignPictureBuffers( void V4L2VideoDecodeAccelerator::ReusePictureBuffer(int32 picture_buffer_id) { DVLOG(3) << "ReusePictureBuffer(): picture_buffer_id=" << picture_buffer_id; // Must be run on child thread, as we'll insert a sync in the EGL context. - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); if (!make_context_current_.Run()) { LOG(ERROR) << "ReusePictureBuffer(): could not make context current"; @@ -407,21 +410,21 @@ void V4L2VideoDecodeAccelerator::ReusePictureBuffer(int32 picture_buffer_id) { void V4L2VideoDecodeAccelerator::Flush() { DVLOG(3) << "Flush()"; - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( &V4L2VideoDecodeAccelerator::FlushTask, base::Unretained(this))); } void V4L2VideoDecodeAccelerator::Reset() { DVLOG(3) << "Reset()"; - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); decoder_thread_.message_loop()->PostTask(FROM_HERE, base::Bind( &V4L2VideoDecodeAccelerator::ResetTask, base::Unretained(this))); } void V4L2VideoDecodeAccelerator::Destroy() { DVLOG(3) << "Destroy()"; - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); // We're destroying; cancel all callbacks. client_ptr_factory_.reset(); @@ -466,7 +469,7 @@ void V4L2VideoDecodeAccelerator::DecodeTask( bitstream_buffer.id()); scoped_ptr<BitstreamBufferRef> bitstream_record(new BitstreamBufferRef( - io_client_, io_message_loop_proxy_, + io_client_, io_task_runner_, new base::SharedMemory(bitstream_buffer.handle(), true), bitstream_buffer.size(), bitstream_buffer.id())); if (!bitstream_record->shm->Map(bitstream_buffer.size())) { @@ -1243,8 +1246,8 @@ void V4L2VideoDecodeAccelerator::FlushTask() { if (decoder_state_ == kInitialized || decoder_state_ == kAfterReset) { // There's nothing in the pipe, so return done immediately. DVLOG(3) << "FlushTask(): returning flush"; - child_message_loop_proxy_->PostTask( - FROM_HERE, base::Bind(&Client::NotifyFlushDone, client_)); + child_task_runner_->PostTask(FROM_HERE, + base::Bind(&Client::NotifyFlushDone, client_)); return; } else if (decoder_state_ == kError) { DVLOG(2) << "FlushTask(): early out: kError state"; @@ -1257,7 +1260,7 @@ void V4L2VideoDecodeAccelerator::FlushTask() { // Queue up an empty buffer -- this triggers the flush. decoder_input_queue_.push( linked_ptr<BitstreamBufferRef>(new BitstreamBufferRef( - io_client_, io_message_loop_proxy_, NULL, 0, kFlushBufferId))); + io_client_, io_task_runner_, NULL, 0, kFlushBufferId))); decoder_flushing_ = true; SendPictureReady(); // Send all pending PictureReady. @@ -1301,8 +1304,8 @@ void V4L2VideoDecodeAccelerator::NotifyFlushDoneIfNeeded() { decoder_delay_bitstream_buffer_id_ = -1; decoder_flushing_ = false; DVLOG(3) << "NotifyFlushDoneIfNeeded(): returning flush"; - child_message_loop_proxy_->PostTask( - FROM_HERE, base::Bind(&Client::NotifyFlushDone, client_)); + child_task_runner_->PostTask(FROM_HERE, + base::Bind(&Client::NotifyFlushDone, client_)); // While we were flushing, we early-outed DecodeBufferTask()s. ScheduleDecodeBufferTaskIfNeeded(); @@ -1388,8 +1391,8 @@ void V4L2VideoDecodeAccelerator::ResetDoneTask() { decoder_partial_frame_pending_ = false; decoder_delay_bitstream_buffer_id_ = -1; - child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind( - &Client::NotifyResetDone, client_)); + child_task_runner_->PostTask(FROM_HERE, + base::Bind(&Client::NotifyResetDone, client_)); // While we were resetting, we early-outed DecodeBufferTask()s. ScheduleDecodeBufferTaskIfNeeded(); @@ -1524,9 +1527,10 @@ void V4L2VideoDecodeAccelerator::StartResolutionChangeIfNeeded() { // Post a task to clean up buffers on child thread. This will also ensure // that we won't accept ReusePictureBuffer() anymore after that. - child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind( - &V4L2VideoDecodeAccelerator::ResolutionChangeDestroyBuffers, - weak_this_)); + child_task_runner_->PostTask( + FROM_HERE, + base::Bind(&V4L2VideoDecodeAccelerator::ResolutionChangeDestroyBuffers, + weak_this_)); } void V4L2VideoDecodeAccelerator::FinishResolutionChange() { @@ -1592,9 +1596,10 @@ void V4L2VideoDecodeAccelerator::DevicePollTask(bool poll_device) { void V4L2VideoDecodeAccelerator::NotifyError(Error error) { DVLOG(2) << "NotifyError()"; - if (!child_message_loop_proxy_->BelongsToCurrentThread()) { - child_message_loop_proxy_->PostTask(FROM_HERE, base::Bind( - &V4L2VideoDecodeAccelerator::NotifyError, weak_this_, error)); + if (!child_task_runner_->BelongsToCurrentThread()) { + child_task_runner_->PostTask( + FROM_HERE, base::Bind(&V4L2VideoDecodeAccelerator::NotifyError, + weak_this_, error)); return; } @@ -1841,12 +1846,10 @@ bool V4L2VideoDecodeAccelerator::CreateOutputBuffers() { DVLOG(3) << "CreateOutputBuffers(): ProvidePictureBuffers(): " << "buffer_count=" << output_buffer_map_.size() << ", coded_size=" << coded_size_.ToString(); - child_message_loop_proxy_->PostTask(FROM_HERE, - base::Bind(&Client::ProvidePictureBuffers, - client_, - output_buffer_map_.size(), - coded_size_, - device_->GetTextureTarget())); + child_task_runner_->PostTask( + FROM_HERE, base::Bind(&Client::ProvidePictureBuffers, client_, + output_buffer_map_.size(), coded_size_, + device_->GetTextureTarget())); // Wait for the client to call AssignPictureBuffers() on the Child thread. // We do this, because if we continue decoding without finishing buffer @@ -1869,7 +1872,7 @@ bool V4L2VideoDecodeAccelerator::CreateOutputBuffers() { void V4L2VideoDecodeAccelerator::DestroyInputBuffers() { DVLOG(3) << "DestroyInputBuffers()"; - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); DCHECK(!input_streamon_); for (size_t i = 0; i < input_buffer_map_.size(); ++i) { @@ -1892,7 +1895,7 @@ void V4L2VideoDecodeAccelerator::DestroyInputBuffers() { bool V4L2VideoDecodeAccelerator::DestroyOutputBuffers() { DVLOG(3) << "DestroyOutputBuffers()"; - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); DCHECK(!output_streamon_); bool success = true; @@ -1916,10 +1919,9 @@ bool V4L2VideoDecodeAccelerator::DestroyOutputBuffers() { DVLOG(1) << "DestroyOutputBuffers(): dismissing PictureBuffer id=" << output_record.picture_id; - child_message_loop_proxy_->PostTask( - FROM_HERE, - base::Bind( - &Client::DismissPictureBuffer, client_, output_record.picture_id)); + child_task_runner_->PostTask( + FROM_HERE, base::Bind(&Client::DismissPictureBuffer, client_, + output_record.picture_id)); } struct v4l2_requestbuffers reqbufs; @@ -1940,7 +1942,7 @@ bool V4L2VideoDecodeAccelerator::DestroyOutputBuffers() { } void V4L2VideoDecodeAccelerator::ResolutionChangeDestroyBuffers() { - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); DVLOG(3) << "ResolutionChangeDestroyBuffers()"; if (!DestroyOutputBuffers()) { @@ -1966,7 +1968,7 @@ void V4L2VideoDecodeAccelerator::SendPictureReady() { if (cleared && picture_clearing_count_ == 0) { // This picture is cleared. Post it to IO thread to reduce latency. This // should be the case after all pictures are cleared at the beginning. - io_message_loop_proxy_->PostTask( + io_task_runner_->PostTask( FROM_HERE, base::Bind(&Client::PictureReady, io_client_, picture)); pending_picture_ready_.pop(); } else if (!cleared || resetting_or_flushing) { @@ -1979,9 +1981,8 @@ void V4L2VideoDecodeAccelerator::SendPictureReady() { // has to be cleared in the child thread. A picture only needs to be // cleared once. If the decoder is resetting or flushing, send all // pictures to ensure PictureReady arrive before reset or flush done. - child_message_loop_proxy_->PostTaskAndReply( - FROM_HERE, - base::Bind(&Client::PictureReady, client_, picture), + child_task_runner_->PostTaskAndReply( + FROM_HERE, base::Bind(&Client::PictureReady, client_, picture), // Unretained is safe. If Client::PictureReady gets to run, |this| is // alive. Destroy() will wait the decode thread to finish. base::Bind(&V4L2VideoDecodeAccelerator::PictureCleared, diff --git a/content/common/gpu/media/v4l2_video_decode_accelerator.h b/content/common/gpu/media/v4l2_video_decode_accelerator.h index d0b7d59..3dfd860 100644 --- a/content/common/gpu/media/v4l2_video_decode_accelerator.h +++ b/content/common/gpu/media/v4l2_video_decode_accelerator.h @@ -27,10 +27,6 @@ #include "ui/gfx/geometry/size.h" #include "ui/gl/gl_bindings.h" -namespace base { -class MessageLoopProxy; -} // namespace base - namespace media { class H264Parser; } // namespace media @@ -82,7 +78,7 @@ class CONTENT_EXPORT V4L2VideoDecodeAccelerator const base::WeakPtr<Client>& io_client_, const base::Callback<bool(void)>& make_context_current, const scoped_refptr<V4L2Device>& device, - const scoped_refptr<base::MessageLoopProxy>& io_message_loop_proxy); + const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); ~V4L2VideoDecodeAccelerator() override; // media::VideoDecodeAccelerator implementation. @@ -315,11 +311,11 @@ class CONTENT_EXPORT V4L2VideoDecodeAccelerator // - V4L2_CID_MIN_BUFFERS_FOR_CAPTURE has changed. bool IsResolutionChangeNecessary(); - // Our original calling message loop for the child thread. - scoped_refptr<base::MessageLoopProxy> child_message_loop_proxy_; + // Our original calling task runner for the child thread. + scoped_refptr<base::SingleThreadTaskRunner> child_task_runner_; - // Message loop of the IO thread. - scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; + // Task runner of the IO thread. + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; // WeakPtr<> pointing to |this| for use in posting tasks from the decoder or // device worker threads back to the child thread. Because the worker threads @@ -331,10 +327,10 @@ class CONTENT_EXPORT V4L2VideoDecodeAccelerator // To expose client callbacks from VideoDecodeAccelerator. // NOTE: all calls to these objects *MUST* be executed on - // child_message_loop_proxy_. + // child_task_runner_. scoped_ptr<base::WeakPtrFactory<Client> > client_ptr_factory_; base::WeakPtr<Client> client_; - // Callbacks to |io_client_| must be executed on |io_message_loop_proxy_|. + // Callbacks to |io_client_| must be executed on |io_task_runner_|. base::WeakPtr<Client> io_client_; // diff --git a/content/common/gpu/media/v4l2_video_encode_accelerator.cc b/content/common/gpu/media/v4l2_video_encode_accelerator.cc index 7f47908..8ee6ec9 100644 --- a/content/common/gpu/media/v4l2_video_encode_accelerator.cc +++ b/content/common/gpu/media/v4l2_video_encode_accelerator.cc @@ -11,8 +11,8 @@ #include "base/callback.h" #include "base/command_line.h" -#include "base/message_loop/message_loop_proxy.h" #include "base/numerics/safe_conversions.h" +#include "base/thread_task_runner_handle.h" #include "base/trace_event/trace_event.h" #include "content/common/gpu/media/v4l2_video_encode_accelerator.h" #include "content/public/common/content_switches.h" @@ -70,7 +70,7 @@ V4L2VideoEncodeAccelerator::OutputRecord::~OutputRecord() { V4L2VideoEncodeAccelerator::V4L2VideoEncodeAccelerator( const scoped_refptr<V4L2Device>& device) - : child_message_loop_proxy_(base::MessageLoopProxy::current()), + : child_task_runner_(base::ThreadTaskRunnerHandle::Get()), output_buffer_byte_size_(0), device_input_format_(media::VideoFrame::UNKNOWN), input_planes_count_(0), @@ -115,7 +115,7 @@ bool V4L2VideoEncodeAccelerator::Initialize( client_ptr_factory_.reset(new base::WeakPtrFactory<Client>(client)); client_ = client_ptr_factory_->GetWeakPtr(); - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); DCHECK_EQ(encoder_state_, kUninitialized); struct v4l2_capability caps; @@ -173,14 +173,12 @@ bool V4L2VideoEncodeAccelerator::Initialize( encoder_state_ = kInitialized; - child_message_loop_proxy_->PostTask( + child_task_runner_->PostTask( FROM_HERE, - base::Bind(&Client::RequireBitstreamBuffers, - client_, - kInputBufferCount, - image_processor_.get() ? - image_processor_->input_allocated_size() : - input_allocated_size_, + base::Bind(&Client::RequireBitstreamBuffers, client_, kInputBufferCount, + image_processor_.get() + ? image_processor_->input_allocated_size() + : input_allocated_size_, output_buffer_byte_size_)); return true; } @@ -194,7 +192,7 @@ void V4L2VideoEncodeAccelerator::Encode( const scoped_refptr<media::VideoFrame>& frame, bool force_keyframe) { DVLOG(3) << "Encode(): force_keyframe=" << force_keyframe; - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); if (image_processor_) { image_processor_->Process( @@ -215,7 +213,7 @@ void V4L2VideoEncodeAccelerator::Encode( void V4L2VideoEncodeAccelerator::UseOutputBitstreamBuffer( const media::BitstreamBuffer& buffer) { DVLOG(3) << "UseOutputBitstreamBuffer(): id=" << buffer.id(); - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); if (buffer.size() < output_buffer_byte_size_) { NOTIFY_ERROR(kInvalidArgumentError); @@ -243,7 +241,7 @@ void V4L2VideoEncodeAccelerator::RequestEncodingParametersChange( uint32 framerate) { DVLOG(3) << "RequestEncodingParametersChange(): bitrate=" << bitrate << ", framerate=" << framerate; - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); encoder_thread_.message_loop()->PostTask( FROM_HERE, @@ -256,7 +254,7 @@ void V4L2VideoEncodeAccelerator::RequestEncodingParametersChange( void V4L2VideoEncodeAccelerator::Destroy() { DVLOG(3) << "Destroy()"; - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); // We're destroying; cancel all callbacks. client_ptr_factory_.reset(); @@ -321,7 +319,7 @@ V4L2VideoEncodeAccelerator::GetSupportedProfiles() { void V4L2VideoEncodeAccelerator::FrameProcessed( bool force_keyframe, const scoped_refptr<media::VideoFrame>& frame) { - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); DVLOG(3) << "FrameProcessed(): force_keyframe=" << force_keyframe; encoder_thread_.message_loop()->PostTask( @@ -584,13 +582,10 @@ void V4L2VideoEncodeAccelerator::Dequeue() { DVLOG(3) << "Dequeue(): returning " "bitstream_buffer_id=" << output_record.buffer_ref->id << ", size=" << output_size << ", key_frame=" << key_frame; - child_message_loop_proxy_->PostTask( + child_task_runner_->PostTask( FROM_HERE, - base::Bind(&Client::BitstreamBufferReady, - client_, - output_record.buffer_ref->id, - output_size, - key_frame)); + base::Bind(&Client::BitstreamBufferReady, client_, + output_record.buffer_ref->id, output_size, key_frame)); output_record.at_device = false; output_record.buffer_ref.reset(); free_output_buffers_.push_back(dqbuf.index); @@ -774,11 +769,10 @@ void V4L2VideoEncodeAccelerator::DevicePollTask(bool poll_device) { void V4L2VideoEncodeAccelerator::NotifyError(Error error) { DVLOG(1) << "NotifyError(): error=" << error; - if (!child_message_loop_proxy_->BelongsToCurrentThread()) { - child_message_loop_proxy_->PostTask( - FROM_HERE, - base::Bind( - &V4L2VideoEncodeAccelerator::NotifyError, weak_this_, error)); + if (!child_task_runner_->BelongsToCurrentThread()) { + child_task_runner_->PostTask( + FROM_HERE, base::Bind(&V4L2VideoEncodeAccelerator::NotifyError, + weak_this_, error)); return; } @@ -843,7 +837,7 @@ void V4L2VideoEncodeAccelerator::RequestEncodingParametersChangeTask( bool V4L2VideoEncodeAccelerator::SetOutputFormat( media::VideoCodecProfile output_profile) { - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); DCHECK(!input_streamon_); DCHECK(!output_streamon_); @@ -878,7 +872,7 @@ bool V4L2VideoEncodeAccelerator::SetOutputFormat( bool V4L2VideoEncodeAccelerator::NegotiateInputFormat( media::VideoFrame::Format input_format) { DVLOG(3) << "NegotiateInputFormat()"; - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); DCHECK(!input_streamon_); DCHECK(!output_streamon_); @@ -938,7 +932,7 @@ bool V4L2VideoEncodeAccelerator::SetFormats( media::VideoFrame::Format input_format, media::VideoCodecProfile output_profile) { DVLOG(3) << "SetFormats()"; - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); DCHECK(!input_streamon_); DCHECK(!output_streamon_); @@ -1078,7 +1072,7 @@ bool V4L2VideoEncodeAccelerator::CreateInputBuffers() { bool V4L2VideoEncodeAccelerator::CreateOutputBuffers() { DVLOG(3) << "CreateOutputBuffers()"; - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); DCHECK(!output_streamon_); struct v4l2_requestbuffers reqbufs; @@ -1120,7 +1114,7 @@ bool V4L2VideoEncodeAccelerator::CreateOutputBuffers() { void V4L2VideoEncodeAccelerator::DestroyInputBuffers() { DVLOG(3) << "DestroyInputBuffers()"; - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); DCHECK(!input_streamon_); struct v4l2_requestbuffers reqbufs; @@ -1136,7 +1130,7 @@ void V4L2VideoEncodeAccelerator::DestroyInputBuffers() { void V4L2VideoEncodeAccelerator::DestroyOutputBuffers() { DVLOG(3) << "DestroyOutputBuffers()"; - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); DCHECK(!output_streamon_); for (size_t i = 0; i < output_buffer_map_.size(); ++i) { diff --git a/content/common/gpu/media/v4l2_video_encode_accelerator.h b/content/common/gpu/media/v4l2_video_encode_accelerator.h index 165da9d..d292f22 100644 --- a/content/common/gpu/media/v4l2_video_encode_accelerator.h +++ b/content/common/gpu/media/v4l2_video_encode_accelerator.h @@ -18,12 +18,6 @@ #include "media/video/video_encode_accelerator.h" #include "ui/gfx/geometry/size.h" -namespace base { - -class MessageLoopProxy; - -} // namespace base - namespace media { class BitstreamBuffer; @@ -192,8 +186,8 @@ class CONTENT_EXPORT V4L2VideoEncodeAccelerator // Set controls in |ctrls| and return true if successful. bool SetExtCtrls(std::vector<struct v4l2_ext_control> ctrls); - // Our original calling message loop for the child thread. - const scoped_refptr<base::MessageLoopProxy> child_message_loop_proxy_; + // Our original calling task runner for the child thread. + const scoped_refptr<base::SingleThreadTaskRunner> child_task_runner_; gfx::Size visible_size_; // Input allocated size required by the device. @@ -262,7 +256,7 @@ class CONTENT_EXPORT V4L2VideoEncodeAccelerator // To expose client callbacks from VideoEncodeAccelerator. // NOTE: all calls to these objects *MUST* be executed on - // child_message_loop_proxy_. + // child_task_runner_. base::WeakPtr<Client> client_; scoped_ptr<base::WeakPtrFactory<Client> > client_ptr_factory_; diff --git a/content/common/gpu/media/vaapi_video_decode_accelerator.cc b/content/common/gpu/media/vaapi_video_decode_accelerator.cc index 1a46f1e..2d638cb 100644 --- a/content/common/gpu/media/vaapi_video_decode_accelerator.cc +++ b/content/common/gpu/media/vaapi_video_decode_accelerator.cc @@ -206,7 +206,7 @@ VaapiVideoDecodeAccelerator::InputBuffer::~InputBuffer() { void VaapiVideoDecodeAccelerator::NotifyError(Error error) { if (message_loop_ != base::MessageLoop::current()) { - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); message_loop_->PostTask(FROM_HERE, base::Bind( &VaapiVideoDecodeAccelerator::NotifyError, weak_this_, error)); return; @@ -307,7 +307,7 @@ bool VaapiVideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile, } CHECK(decoder_thread_.Start()); - decoder_thread_proxy_ = decoder_thread_.message_loop_proxy(); + decoder_thread_task_runner_ = decoder_thread_.task_runner(); state_ = kIdle; return true; @@ -399,7 +399,7 @@ void VaapiVideoDecodeAccelerator::MapAndQueueNewInputBuffer( } bool VaapiVideoDecodeAccelerator::GetInputBuffer_Locked() { - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); lock_.AssertAcquired(); if (curr_input_buffer_.get()) @@ -445,7 +445,7 @@ bool VaapiVideoDecodeAccelerator::GetInputBuffer_Locked() { void VaapiVideoDecodeAccelerator::ReturnCurrInputBuffer_Locked() { lock_.AssertAcquired(); - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); DCHECK(curr_input_buffer_.get()); int32 id = curr_input_buffer_->id; @@ -463,7 +463,7 @@ void VaapiVideoDecodeAccelerator::ReturnCurrInputBuffer_Locked() { // surfaces, and reschedule DecodeTask instead. bool VaapiVideoDecodeAccelerator::WaitForSurfaces_Locked() { lock_.AssertAcquired(); - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); while (available_va_surfaces_.empty() && (state_ == kDecoding || state_ == kFlushing || state_ == kIdle)) { @@ -477,7 +477,7 @@ bool VaapiVideoDecodeAccelerator::WaitForSurfaces_Locked() { } void VaapiVideoDecodeAccelerator::DecodeTask() { - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); TRACE_EVENT0("Video Decoder", "VAVDA::DecodeTask"); base::AutoLock auto_lock(lock_); @@ -610,9 +610,9 @@ void VaapiVideoDecodeAccelerator::Decode( switch (state_) { case kIdle: state_ = kDecoding; - decoder_thread_proxy_->PostTask(FROM_HERE, base::Bind( - &VaapiVideoDecodeAccelerator::DecodeTask, - base::Unretained(this))); + decoder_thread_task_runner_->PostTask( + FROM_HERE, base::Bind(&VaapiVideoDecodeAccelerator::DecodeTask, + base::Unretained(this))); break; case kDecoding: @@ -693,8 +693,9 @@ void VaapiVideoDecodeAccelerator::AssignPictureBuffers( } state_ = kDecoding; - decoder_thread_proxy_->PostTask(FROM_HERE, base::Bind( - &VaapiVideoDecodeAccelerator::DecodeTask, base::Unretained(this))); + decoder_thread_task_runner_->PostTask( + FROM_HERE, base::Bind(&VaapiVideoDecodeAccelerator::DecodeTask, + base::Unretained(this))); } void VaapiVideoDecodeAccelerator::ReusePictureBuffer(int32 picture_buffer_id) { @@ -710,7 +711,7 @@ void VaapiVideoDecodeAccelerator::ReusePictureBuffer(int32 picture_buffer_id) { } void VaapiVideoDecodeAccelerator::FlushTask() { - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); DVLOG(1) << "Flush task"; // First flush all the pictures that haven't been outputted, notifying the @@ -733,8 +734,9 @@ void VaapiVideoDecodeAccelerator::Flush() { base::AutoLock auto_lock(lock_); state_ = kFlushing; // Queue a flush task after all existing decoding tasks to clean up. - decoder_thread_proxy_->PostTask(FROM_HERE, base::Bind( - &VaapiVideoDecodeAccelerator::FlushTask, base::Unretained(this))); + decoder_thread_task_runner_->PostTask( + FROM_HERE, base::Bind(&VaapiVideoDecodeAccelerator::FlushTask, + base::Unretained(this))); input_ready_.Signal(); surfaces_available_.Signal(); @@ -767,7 +769,7 @@ void VaapiVideoDecodeAccelerator::FinishFlush() { } void VaapiVideoDecodeAccelerator::ResetTask() { - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); DVLOG(1) << "ResetTask"; // All the decoding tasks from before the reset request from client are done @@ -803,8 +805,9 @@ void VaapiVideoDecodeAccelerator::Reset() { input_buffers_.pop(); } - decoder_thread_proxy_->PostTask(FROM_HERE, base::Bind( - &VaapiVideoDecodeAccelerator::ResetTask, base::Unretained(this))); + decoder_thread_task_runner_->PostTask( + FROM_HERE, base::Bind(&VaapiVideoDecodeAccelerator::ResetTask, + base::Unretained(this))); input_ready_.Signal(); surfaces_available_.Signal(); @@ -847,9 +850,9 @@ void VaapiVideoDecodeAccelerator::FinishReset() { // that we are back in kDecoding state. if (!input_buffers_.empty()) { state_ = kDecoding; - decoder_thread_proxy_->PostTask(FROM_HERE, base::Bind( - &VaapiVideoDecodeAccelerator::DecodeTask, - base::Unretained(this))); + decoder_thread_task_runner_->PostTask( + FROM_HERE, base::Bind(&VaapiVideoDecodeAccelerator::DecodeTask, + base::Unretained(this))); } DVLOG(1) << "Reset finished"; @@ -929,7 +932,7 @@ void VaapiVideoDecodeAccelerator::SurfaceReady( scoped_refptr<VaapiVideoDecodeAccelerator::VaapiDecodeSurface> VaapiVideoDecodeAccelerator::CreateSurface() { - DCHECK(decoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(decoder_thread_task_runner_->BelongsToCurrentThread()); base::AutoLock auto_lock(lock_); if (available_va_surfaces_.empty()) diff --git a/content/common/gpu/media/vaapi_video_decode_accelerator.h b/content/common/gpu/media/vaapi_video_decode_accelerator.h index dca54d3..268439b 100644 --- a/content/common/gpu/media/vaapi_video_decode_accelerator.h +++ b/content/common/gpu/media/vaapi_video_decode_accelerator.h @@ -282,7 +282,7 @@ class CONTENT_EXPORT VaapiVideoDecodeAccelerator // Use this to post tasks to |decoder_thread_| instead of // |decoder_thread_.message_loop()| because the latter will be NULL once // |decoder_thread_.Stop()| returns. - scoped_refptr<base::MessageLoopProxy> decoder_thread_proxy_; + scoped_refptr<base::SingleThreadTaskRunner> decoder_thread_task_runner_; int num_frames_at_client_; int num_stream_bufs_at_decoder_; diff --git a/content/common/gpu/media/vaapi_video_encode_accelerator.cc b/content/common/gpu/media/vaapi_video_encode_accelerator.cc index 3ea4f91..cdd03a1 100644 --- a/content/common/gpu/media/vaapi_video_encode_accelerator.cc +++ b/content/common/gpu/media/vaapi_video_encode_accelerator.cc @@ -6,7 +6,6 @@ #include "base/bind.h" #include "base/callback.h" -#include "base/message_loop/message_loop_proxy.h" #include "base/metrics/histogram.h" #include "base/numerics/safe_conversions.h" #include "content/common/gpu/media/h264_dpb.h" @@ -133,7 +132,7 @@ VaapiVideoEncodeAccelerator::VaapiVideoEncodeAccelerator() cpb_size_(0), encoding_parameters_changed_(false), encoder_thread_("VAVEAEncoderThread"), - child_message_loop_proxy_(base::MessageLoopProxy::current()), + child_task_runner_(base::ThreadTaskRunnerHandle::Get()), weak_this_ptr_factory_(this) { DVLOGF(4); weak_this_ = weak_this_ptr_factory_.GetWeakPtr(); @@ -147,7 +146,7 @@ VaapiVideoEncodeAccelerator::VaapiVideoEncodeAccelerator() VaapiVideoEncodeAccelerator::~VaapiVideoEncodeAccelerator() { DVLOGF(4); - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); DCHECK(!encoder_thread_.IsRunning()); } @@ -157,7 +156,7 @@ bool VaapiVideoEncodeAccelerator::Initialize( media::VideoCodecProfile output_profile, uint32 initial_bitrate, Client* client) { - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); DCHECK(!encoder_thread_.IsRunning()); DCHECK_EQ(state_, kUninitialized); @@ -207,19 +206,18 @@ bool VaapiVideoEncodeAccelerator::Initialize( LOG(ERROR) << "Failed to start encoder thread"; return false; } - encoder_thread_proxy_ = encoder_thread_.message_loop_proxy(); + encoder_thread_task_runner_ = encoder_thread_.task_runner(); // Finish the remaining initialization on the encoder thread. - encoder_thread_proxy_->PostTask( - FROM_HERE, - base::Bind(&VaapiVideoEncodeAccelerator::InitializeTask, - base::Unretained(this))); + encoder_thread_task_runner_->PostTask( + FROM_HERE, base::Bind(&VaapiVideoEncodeAccelerator::InitializeTask, + base::Unretained(this))); return true; } void VaapiVideoEncodeAccelerator::InitializeTask() { - DCHECK(encoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(encoder_thread_task_runner_->BelongsToCurrentThread()); DCHECK_EQ(state_, kUninitialized); DVLOGF(4); @@ -239,13 +237,10 @@ void VaapiVideoEncodeAccelerator::InitializeTask() { UpdatePPS(); GeneratePackedPPS(); - child_message_loop_proxy_->PostTask( + child_task_runner_->PostTask( FROM_HERE, - base::Bind(&Client::RequireBitstreamBuffers, - client_, - kNumInputBuffers, - coded_size_, - output_buffer_byte_size_)); + base::Bind(&Client::RequireBitstreamBuffers, client_, kNumInputBuffers, + coded_size_, output_buffer_byte_size_)); SetState(kEncoding); } @@ -253,7 +248,7 @@ void VaapiVideoEncodeAccelerator::InitializeTask() { void VaapiVideoEncodeAccelerator::RecycleVASurfaceID( VASurfaceID va_surface_id) { DVLOGF(4) << "va_surface_id: " << va_surface_id; - DCHECK(encoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(encoder_thread_task_runner_->BelongsToCurrentThread()); available_va_surface_ids_.push_back(va_surface_id); EncodeFrameTask(); @@ -525,7 +520,7 @@ bool VaapiVideoEncodeAccelerator::UploadFrame( } void VaapiVideoEncodeAccelerator::TryToReturnBitstreamBuffer() { - DCHECK(encoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(encoder_thread_task_runner_->BelongsToCurrentThread()); if (state_ != kEncoding) return; @@ -556,12 +551,9 @@ void VaapiVideoEncodeAccelerator::TryToReturnBitstreamBuffer() { << (encode_job->keyframe ? "(keyframe)" : "") << " id: " << buffer->id << " size: " << data_size; - child_message_loop_proxy_->PostTask(FROM_HERE, - base::Bind(&Client::BitstreamBufferReady, - client_, - buffer->id, - data_size, - encode_job->keyframe)); + child_task_runner_->PostTask( + FROM_HERE, base::Bind(&Client::BitstreamBufferReady, client_, buffer->id, + data_size, encode_job->keyframe)); } void VaapiVideoEncodeAccelerator::Encode( @@ -569,14 +561,11 @@ void VaapiVideoEncodeAccelerator::Encode( bool force_keyframe) { DVLOGF(3) << "Frame timestamp: " << frame->timestamp().InMilliseconds() << " force_keyframe: " << force_keyframe; - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); - encoder_thread_proxy_->PostTask( - FROM_HERE, - base::Bind(&VaapiVideoEncodeAccelerator::EncodeTask, - base::Unretained(this), - frame, - force_keyframe)); + encoder_thread_task_runner_->PostTask( + FROM_HERE, base::Bind(&VaapiVideoEncodeAccelerator::EncodeTask, + base::Unretained(this), frame, force_keyframe)); } bool VaapiVideoEncodeAccelerator::PrepareNextJob() { @@ -611,7 +600,7 @@ bool VaapiVideoEncodeAccelerator::PrepareNextJob() { void VaapiVideoEncodeAccelerator::EncodeTask( const scoped_refptr<media::VideoFrame>& frame, bool force_keyframe) { - DCHECK(encoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(encoder_thread_task_runner_->BelongsToCurrentThread()); DCHECK_NE(state_, kUninitialized); encoder_input_queue_.push( @@ -620,7 +609,7 @@ void VaapiVideoEncodeAccelerator::EncodeTask( } void VaapiVideoEncodeAccelerator::EncodeFrameTask() { - DCHECK(encoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(encoder_thread_task_runner_->BelongsToCurrentThread()); if (state_ != kEncoding || encoder_input_queue_.empty()) return; @@ -663,7 +652,7 @@ void VaapiVideoEncodeAccelerator::EncodeFrameTask() { void VaapiVideoEncodeAccelerator::UseOutputBitstreamBuffer( const media::BitstreamBuffer& buffer) { DVLOGF(4) << "id: " << buffer.id(); - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); if (buffer.size() < output_buffer_byte_size_) { NOTIFY_ERROR(kInvalidArgumentError, "Provided bitstream buffer too small"); @@ -680,16 +669,15 @@ void VaapiVideoEncodeAccelerator::UseOutputBitstreamBuffer( scoped_ptr<BitstreamBufferRef> buffer_ref( new BitstreamBufferRef(buffer.id(), shm.Pass(), buffer.size())); - encoder_thread_proxy_->PostTask( + encoder_thread_task_runner_->PostTask( FROM_HERE, base::Bind(&VaapiVideoEncodeAccelerator::UseOutputBitstreamBufferTask, - base::Unretained(this), - base::Passed(&buffer_ref))); + base::Unretained(this), base::Passed(&buffer_ref))); } void VaapiVideoEncodeAccelerator::UseOutputBitstreamBufferTask( scoped_ptr<BitstreamBufferRef> buffer_ref) { - DCHECK(encoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(encoder_thread_task_runner_->BelongsToCurrentThread()); DCHECK_NE(state_, kUninitialized); available_bitstream_buffers_.push(make_linked_ptr(buffer_ref.release())); @@ -700,21 +688,19 @@ void VaapiVideoEncodeAccelerator::RequestEncodingParametersChange( uint32 bitrate, uint32 framerate) { DVLOGF(2) << "bitrate: " << bitrate << " framerate: " << framerate; - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); - encoder_thread_proxy_->PostTask( + encoder_thread_task_runner_->PostTask( FROM_HERE, base::Bind( &VaapiVideoEncodeAccelerator::RequestEncodingParametersChangeTask, - base::Unretained(this), - bitrate, - framerate)); + base::Unretained(this), bitrate, framerate)); } void VaapiVideoEncodeAccelerator::UpdateRates(uint32 bitrate, uint32 framerate) { if (encoder_thread_.IsRunning()) - DCHECK(encoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(encoder_thread_task_runner_->BelongsToCurrentThread()); DCHECK_NE(bitrate, 0u); DCHECK_NE(framerate, 0u); bitrate_ = bitrate; @@ -726,7 +712,7 @@ void VaapiVideoEncodeAccelerator::RequestEncodingParametersChangeTask( uint32 bitrate, uint32 framerate) { DVLOGF(2) << "bitrate: " << bitrate << " framerate: " << framerate; - DCHECK(encoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(encoder_thread_task_runner_->BelongsToCurrentThread()); DCHECK_NE(state_, kUninitialized); // This is a workaround to zero being temporarily, as part of the initial @@ -752,7 +738,7 @@ void VaapiVideoEncodeAccelerator::RequestEncodingParametersChangeTask( } void VaapiVideoEncodeAccelerator::Destroy() { - DCHECK(child_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(child_task_runner_->BelongsToCurrentThread()); // Can't call client anymore after Destroy() returns. client_ptr_factory_.reset(); @@ -772,7 +758,7 @@ void VaapiVideoEncodeAccelerator::Destroy() { void VaapiVideoEncodeAccelerator::DestroyTask() { DVLOGF(2); - DCHECK(encoder_thread_proxy_->BelongsToCurrentThread()); + DCHECK(encoder_thread_task_runner_->BelongsToCurrentThread()); SetState(kError); } @@ -1036,12 +1022,10 @@ void VaapiVideoEncodeAccelerator::GeneratePackedPPS() { void VaapiVideoEncodeAccelerator::SetState(State state) { // Only touch state on encoder thread, unless it's not running. if (encoder_thread_.IsRunning() && - !encoder_thread_proxy_->BelongsToCurrentThread()) { - encoder_thread_proxy_->PostTask( - FROM_HERE, - base::Bind(&VaapiVideoEncodeAccelerator::SetState, - base::Unretained(this), - state)); + !encoder_thread_task_runner_->BelongsToCurrentThread()) { + encoder_thread_task_runner_->PostTask( + FROM_HERE, base::Bind(&VaapiVideoEncodeAccelerator::SetState, + base::Unretained(this), state)); return; } @@ -1050,11 +1034,10 @@ void VaapiVideoEncodeAccelerator::SetState(State state) { } void VaapiVideoEncodeAccelerator::NotifyError(Error error) { - if (!child_message_loop_proxy_->BelongsToCurrentThread()) { - child_message_loop_proxy_->PostTask( - FROM_HERE, - base::Bind( - &VaapiVideoEncodeAccelerator::NotifyError, weak_this_, error)); + if (!child_task_runner_->BelongsToCurrentThread()) { + child_task_runner_->PostTask( + FROM_HERE, base::Bind(&VaapiVideoEncodeAccelerator::NotifyError, + weak_this_, error)); return; } diff --git a/content/common/gpu/media/vaapi_video_encode_accelerator.h b/content/common/gpu/media/vaapi_video_encode_accelerator.h index 3e7d51c..8a5cf7f 100644 --- a/content/common/gpu/media/vaapi_video_encode_accelerator.h +++ b/content/common/gpu/media/vaapi_video_encode_accelerator.h @@ -235,13 +235,13 @@ class CONTENT_EXPORT VaapiVideoEncodeAccelerator // Encoder thread. All tasks are executed on it. base::Thread encoder_thread_; - scoped_refptr<base::MessageLoopProxy> encoder_thread_proxy_; + scoped_refptr<base::SingleThreadTaskRunner> encoder_thread_task_runner_; - const scoped_refptr<base::MessageLoopProxy> child_message_loop_proxy_; + const scoped_refptr<base::SingleThreadTaskRunner> child_task_runner_; // To expose client callbacks from VideoEncodeAccelerator. // NOTE: all calls to these objects *MUST* be executed on - // child_message_loop_proxy_. + // child_task_runner_. scoped_ptr<base::WeakPtrFactory<Client> > client_ptr_factory_; base::WeakPtr<Client> client_; diff --git a/content/common/gpu/media/video_decode_accelerator_unittest.cc b/content/common/gpu/media/video_decode_accelerator_unittest.cc index 65bfaa2..fb0a217 100644 --- a/content/common/gpu/media/video_decode_accelerator_unittest.cc +++ b/content/common/gpu/media/video_decode_accelerator_unittest.cc @@ -35,7 +35,6 @@ #include "base/files/file_util.h" #include "base/format_macros.h" #include "base/md5.h" -#include "base/message_loop/message_loop_proxy.h" #include "base/process/process_handle.h" #include "base/stl_util.h" #include "base/strings/string_number_conversions.h" @@ -535,10 +534,8 @@ GLRenderingVDAClient::CreateV4L2VDA() { decoder.reset(new V4L2VideoDecodeAccelerator( static_cast<EGLDisplay>(rendering_helper_->GetGLDisplay()), static_cast<EGLContext>(rendering_helper_->GetGLContextHandle()), - weak_client, - base::Bind(&DoNothingReturnTrue), - device, - base::MessageLoopProxy::current())); + weak_client, base::Bind(&DoNothingReturnTrue), device, + base::ThreadTaskRunnerHandle::Get())); } #endif return decoder.Pass(); @@ -552,12 +549,10 @@ GLRenderingVDAClient::CreateV4L2SliceVDA() { if (device.get()) { base::WeakPtr<VideoDecodeAccelerator::Client> weak_client = AsWeakPtr(); decoder.reset(new V4L2SliceVideoDecodeAccelerator( - device, - static_cast<EGLDisplay>(rendering_helper_->GetGLDisplay()), + device, static_cast<EGLDisplay>(rendering_helper_->GetGLDisplay()), static_cast<EGLContext>(rendering_helper_->GetGLContextHandle()), - weak_client, - base::Bind(&DoNothingReturnTrue), - base::MessageLoopProxy::current())); + weak_client, base::Bind(&DoNothingReturnTrue), + base::ThreadTaskRunnerHandle::Get())); } #endif return decoder.Pass(); diff --git a/content/common/gpu/media/video_encode_accelerator_unittest.cc b/content/common/gpu/media/video_encode_accelerator_unittest.cc index 9ae8f1c..8036737 100644 --- a/content/common/gpu/media/video_encode_accelerator_unittest.cc +++ b/content/common/gpu/media/video_encode_accelerator_unittest.cc @@ -828,10 +828,9 @@ VEAClient::~VEAClient() { CHECK(!has_encoder()); } scoped_ptr<media::VideoEncodeAccelerator> VEAClient::CreateFakeVEA() { scoped_ptr<media::VideoEncodeAccelerator> encoder; if (g_fake_encoder) { - encoder.reset( - new media::FakeVideoEncodeAccelerator( - scoped_refptr<base::SingleThreadTaskRunner>( - base::MessageLoopProxy::current()))); + encoder.reset(new media::FakeVideoEncodeAccelerator( + scoped_refptr<base::SingleThreadTaskRunner>( + base::ThreadTaskRunnerHandle::Get()))); } return encoder.Pass(); } diff --git a/content/common/gpu/media/vt_video_decode_accelerator.cc b/content/common/gpu/media/vt_video_decode_accelerator.cc index 4af6e6c..4435cd7 100644 --- a/content/common/gpu/media/vt_video_decode_accelerator.cc +++ b/content/common/gpu/media/vt_video_decode_accelerator.cc @@ -324,7 +324,7 @@ bool VTVideoDecodeAccelerator::Initialize( } bool VTVideoDecodeAccelerator::FinishDelayedFrames() { - DCHECK(decoder_thread_.message_loop_proxy()->BelongsToCurrentThread()); + DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread()); if (session_) { OSStatus status = VTDecompressionSessionWaitForAsynchronousFrames(session_); if (status) { @@ -337,7 +337,7 @@ bool VTVideoDecodeAccelerator::FinishDelayedFrames() { } bool VTVideoDecodeAccelerator::ConfigureDecoder() { - DCHECK(decoder_thread_.message_loop_proxy()->BelongsToCurrentThread()); + DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread()); DCHECK(!last_sps_.empty()); DCHECK(!last_pps_.empty()); @@ -447,7 +447,7 @@ bool VTVideoDecodeAccelerator::ConfigureDecoder() { void VTVideoDecodeAccelerator::DecodeTask( const media::BitstreamBuffer& bitstream, Frame* frame) { - DCHECK(decoder_thread_.message_loop_proxy()->BelongsToCurrentThread()); + DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread()); // Map the bitstream buffer. base::SharedMemory memory(bitstream.handle(), true); @@ -744,7 +744,7 @@ void VTVideoDecodeAccelerator::DecodeDone(Frame* frame) { } void VTVideoDecodeAccelerator::FlushTask(TaskType type) { - DCHECK(decoder_thread_.message_loop_proxy()->BelongsToCurrentThread()); + DCHECK(decoder_thread_.task_runner()->BelongsToCurrentThread()); FinishDelayedFrames(); // Always queue a task, even if FinishDelayedFrames() fails, so that @@ -765,9 +765,9 @@ void VTVideoDecodeAccelerator::Decode(const media::BitstreamBuffer& bitstream) { assigned_bitstream_ids_.insert(bitstream.id()); Frame* frame = new Frame(bitstream.id()); pending_frames_[frame->bitstream_id] = make_linked_ptr(frame); - decoder_thread_.message_loop_proxy()->PostTask(FROM_HERE, base::Bind( - &VTVideoDecodeAccelerator::DecodeTask, base::Unretained(this), - bitstream, frame)); + decoder_thread_.task_runner()->PostTask( + FROM_HERE, base::Bind(&VTVideoDecodeAccelerator::DecodeTask, + base::Unretained(this), bitstream, frame)); } void VTVideoDecodeAccelerator::AssignPictureBuffers( @@ -1004,9 +1004,9 @@ void VTVideoDecodeAccelerator::NotifyError( void VTVideoDecodeAccelerator::QueueFlush(TaskType type) { DCHECK(gpu_thread_checker_.CalledOnValidThread()); pending_flush_tasks_.push(type); - decoder_thread_.message_loop_proxy()->PostTask(FROM_HERE, base::Bind( - &VTVideoDecodeAccelerator::FlushTask, base::Unretained(this), - type)); + decoder_thread_.task_runner()->PostTask( + FROM_HERE, base::Bind(&VTVideoDecodeAccelerator::FlushTask, + base::Unretained(this), type)); // If this is a new flush request, see if we can make progress. if (pending_flush_tasks_.size() == 1) diff --git a/content/common/gpu/media/vt_video_decode_accelerator.h b/content/common/gpu/media/vt_video_decode_accelerator.h index 0ec7114..7fbc888 100644 --- a/content/common/gpu/media/vt_video_decode_accelerator.h +++ b/content/common/gpu/media/vt_video_decode_accelerator.h @@ -23,10 +23,6 @@ #include "ui/gfx/geometry/size.h" #include "ui/gl/gl_context_cgl.h" -namespace base { -class SingleThreadTaskRunner; -} // namespace base - namespace content { // Preload VideoToolbox libraries, needed for sandbox warmup. diff --git a/content/common/host_discardable_shared_memory_manager.cc b/content/common/host_discardable_shared_memory_manager.cc index 6709c25..99db117 100644 --- a/content/common/host_discardable_shared_memory_manager.cc +++ b/content/common/host_discardable_shared_memory_manager.cc @@ -15,6 +15,7 @@ #include "base/numerics/safe_math.h" #include "base/strings/string_number_conversions.h" #include "base/sys_info.h" +#include "base/thread_task_runner_handle.h" #include "base/trace_event/trace_event.h" namespace content { @@ -389,7 +390,7 @@ void HostDiscardableSharedMemoryManager::ScheduleEnforceMemoryPolicy() { return; enforce_memory_policy_pending_ = true; - base::MessageLoop::current()->PostDelayedTask( + base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( FROM_HERE, base::Bind(&HostDiscardableSharedMemoryManager::EnforceMemoryPolicy, weak_ptr_factory_.GetWeakPtr()), diff --git a/content/common/mojo/channel_init.h b/content/common/mojo/channel_init.h index 1dd7f15..2660a7b 100644 --- a/content/common/mojo/channel_init.h +++ b/content/common/mojo/channel_init.h @@ -14,7 +14,6 @@ #include "third_party/mojo/src/mojo/public/cpp/system/message_pipe.h" namespace base { -class MessageLoopProxy; class TaskRunner; } diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc index 6167af5..bb9e409 100644 --- a/content/renderer/render_thread_impl.cc +++ b/content/renderer/render_thread_impl.cc @@ -1470,8 +1470,9 @@ bool RenderThreadImpl::IsMainThread() { return !!current(); } -scoped_refptr<base::MessageLoopProxy> RenderThreadImpl::GetIOLoopProxy() { - return io_message_loop_proxy_; +scoped_refptr<base::SingleThreadTaskRunner> +RenderThreadImpl::GetIOThreadTaskRunner() { + return io_thread_task_runner_; } scoped_ptr<base::SharedMemory> RenderThreadImpl::AllocateSharedMemory( @@ -1615,7 +1616,7 @@ GpuChannelHost* RenderThreadImpl::EstablishGpuChannelSync( // Cache some variables that are needed on the compositor thread for our // implementation of GpuChannelHostFactory. - io_message_loop_proxy_ = ChildProcess::current()->io_message_loop_proxy(); + io_thread_task_runner_ = ChildProcess::current()->io_message_loop_proxy(); gpu_channel_ = GpuChannelHost::Create(this, diff --git a/content/renderer/render_thread_impl.h b/content/renderer/render_thread_impl.h index a17d1f7..5b79e72 100644 --- a/content/renderer/render_thread_impl.h +++ b/content/renderer/render_thread_impl.h @@ -427,7 +427,7 @@ class CONTENT_EXPORT RenderThreadImpl // GpuChannelHostFactory implementation: bool IsMainThread() override; - scoped_refptr<base::MessageLoopProxy> GetIOLoopProxy() override; + scoped_refptr<base::SingleThreadTaskRunner> GetIOThreadTaskRunner() override; scoped_ptr<base::SharedMemory> AllocateSharedMemory(size_t size) override; CreateCommandBufferResult CreateViewCommandBuffer( int32 surface_id, @@ -545,7 +545,7 @@ class CONTENT_EXPORT RenderThreadImpl // Cache of variables that are needed on the compositor thread by // GpuChannelHostFactory methods. - scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; + scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner_; // The message loop of the renderer main thread. // This message loop should be destructed before the RenderThreadImpl |