Chromium Code Reviews| Index: content/browser/gpu/gpu_arc_video_service_host.cc |
| diff --git a/content/browser/gpu/gpu_arc_video_service_host.cc b/content/browser/gpu/gpu_arc_video_service_host.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5e174ddf0c44a438172841a4f1ec49d07e77839e |
| --- /dev/null |
| +++ b/content/browser/gpu/gpu_arc_video_service_host.cc |
| @@ -0,0 +1,116 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/browser/gpu/gpu_arc_video_service_host.h" |
| + |
| +#include "base/location.h" |
| +#include "base/logging.h" |
| +#include "base/message_loop/message_loop.h" |
| +#include "content/browser/gpu/gpu_process_host.h" |
| +#include "content/common/gpu/gpu_messages.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "ipc/ipc_message_macros.h" |
| +#include "ipc/ipc_message_utils.h" |
| +#include "third_party/mojo/src/mojo/edk/embedder/embedder.h" |
| + |
| +namespace content { |
| + |
| +namespace { |
| +void CreateChannelOnIOThread( |
| + const GpuProcessHost::CreateArcVideoAcceleratorChannelCallback& callback) { |
| + GpuProcessHost* gpu_process_host = |
| + GpuProcessHost::Get(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, |
| + CAUSE_FOR_GPU_LAUNCH_ARCVIDEOACCELERATOR); |
| + gpu_process_host->CreateArcVideoAcceleratorChannel(callback); |
| +} |
| +} |
| + |
| +GpuArcVideoServiceHost::GpuArcVideoServiceHost() |
| + : io_task_runner_(content::BrowserThread::GetMessageLoopProxyForThread( |
| + content::BrowserThread::IO)), |
| + binding_(this), |
| + weak_factory_(this) {} |
| + |
| +GpuArcVideoServiceHost::~GpuArcVideoServiceHost() { |
| + DCHECK(CalledOnValidThread()); |
| + |
| + while (!callbacks_.empty()) |
| + ReplyChannelCreated(IPC::ChannelHandle()); |
| + |
| + arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); |
| + if (bridge_service) { |
| + bridge_service->RemoveObserver(this); |
| + } |
| +} |
| + |
| +void GpuArcVideoServiceHost::Initialize() { |
| + DCHECK(CalledOnValidThread()); |
| + |
| + arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); |
| + DCHECK(bridge_service); |
| + bridge_service->AddObserver(this); |
|
Luis Héctor Chávez
2015/12/23 00:02:53
if (arc_bridge_service->video_instance())
OnVide
kcwu
2015/12/23 01:05:23
Done.
|
| +} |
| + |
| +void GpuArcVideoServiceHost::OnStateChanged( |
| + arc::ArcBridgeService::State state) { |
| + DCHECK(CalledOnValidThread()); |
| + switch (state) { |
| + case arc::ArcBridgeService::State::STOPPING: |
| + Shutdown(); |
| + break; |
| + default: |
| + break; |
| + } |
| +} |
| + |
| +void GpuArcVideoServiceHost::OnVideoInstanceReady() { |
| + DCHECK(CalledOnValidThread()); |
| + arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); |
| + DCHECK(bridge_service); |
| + |
| + arc::VideoHostPtr host; |
| + binding_.Bind(mojo::GetProxy(&host)); |
| + bridge_service->video_instance()->Init(std::move(host)); |
| +} |
| + |
| +void GpuArcVideoServiceHost::OnRequestArcVideoAcceleratorChannel( |
| + const OnRequestArcVideoAcceleratorChannelCallback& callback) { |
| + DCHECK(CalledOnValidThread()); |
| + |
| + callbacks_.push(callback); |
| + io_task_runner_->PostTask( |
| + FROM_HERE, |
| + base::Bind(&CreateChannelOnIOThread, |
| + base::Bind(&GpuArcVideoServiceHost::ReplyChannelCreated, |
|
Luis Héctor Chávez
2015/12/23 00:02:53
How about you change ReplyChannelCreated to also r
kcwu
2015/12/23 01:05:23
Done.
|
| + weak_factory_.GetWeakPtr()))); |
| +} |
| + |
| +void GpuArcVideoServiceHost::Shutdown() { |
| + GpuProcessHost::SendOnIO(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, |
| + CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH, |
| + new GpuMsg_ShutdownArcVideoService()); |
| +} |
| + |
| +void GpuArcVideoServiceHost::ReplyChannelCreated( |
| + const IPC::ChannelHandle& handle) { |
| + DCHECK(CalledOnValidThread()); |
| + |
| + DCHECK(!callbacks_.empty()); |
| + OnRequestArcVideoAcceleratorChannelCallback callback = callbacks_.front(); |
| + callbacks_.pop(); |
| + |
| + MojoHandle wrapped_handle; |
| + MojoResult wrap_result = mojo::embedder::CreatePlatformHandleWrapper( |
| + mojo::embedder::ScopedPlatformHandle( |
| + mojo::embedder::PlatformHandle(handle.socket.fd)), |
| + &wrapped_handle); |
| + if (wrap_result != MOJO_RESULT_OK) { |
| + LOG(WARNING) << "Pipe failed to wrap handles. Closing: " << wrap_result; |
| + callback.Run(mojo::ScopedHandle()); |
| + return; |
| + } |
| + callback.Run(mojo::ScopedHandle(mojo::Handle(wrapped_handle))); |
| +} |
| + |
| +} // namespace content |