| Index: chrome/browser/chromeos/arc/gpu_arc_video_service_host.cc
|
| diff --git a/chrome/browser/chromeos/arc/gpu_arc_video_service_host.cc b/chrome/browser/chromeos/arc/gpu_arc_video_service_host.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..490b3b44fbabc6330d4618fb8943ac89ceeaa495
|
| --- /dev/null
|
| +++ b/chrome/browser/chromeos/arc/gpu_arc_video_service_host.cc
|
| @@ -0,0 +1,80 @@
|
| +// Copyright 2016 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 "chrome/browser/chromeos/arc/gpu_arc_video_service_host.h"
|
| +
|
| +#include "base/location.h"
|
| +#include "base/logging.h"
|
| +#include "base/message_loop/message_loop.h"
|
| +#include "base/thread_task_runner_handle.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| +#include "content/public/browser/gpu_service_registry.h"
|
| +#include "content/public/common/service_registry.h"
|
| +
|
| +namespace {
|
| +
|
| +void GetServiceOnIOThread(mojo::InterfacePtrInfo<arc::VideoHost>* ptr_info) {
|
| + arc::VideoHostPtr host_ptr;
|
| + content::ServiceRegistry* registry = content::GetGpuServiceRegistry();
|
| + registry->ConnectToRemoteService<arc::VideoHost>(mojo::GetProxy(&host_ptr));
|
| +
|
| + // Unbind and reply back to UI thread.
|
| + *ptr_info = host_ptr.PassInterface();
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +namespace arc {
|
| +
|
| +GpuArcVideoServiceHost::GpuArcVideoServiceHost(
|
| + arc::ArcBridgeService* bridge_service)
|
| + : ArcService(bridge_service),
|
| + binding_(this),
|
| + io_task_runner_(content::BrowserThread::GetMessageLoopProxyForThread(
|
| + content::BrowserThread::IO)),
|
| + weak_factory_(this) {
|
| + arc_bridge_service()->AddObserver(this);
|
| +}
|
| +
|
| +GpuArcVideoServiceHost::~GpuArcVideoServiceHost() {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| + arc_bridge_service()->RemoveObserver(this);
|
| +}
|
| +
|
| +void GpuArcVideoServiceHost::OnVideoInstanceReady() {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| + arc_bridge_service()->video_instance()->Init(
|
| + binding_.CreateInterfacePtrAndBind());
|
| +}
|
| +
|
| +void GpuArcVideoServiceHost::OnVideoInstanceClosed() {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| + service_ptr_.reset();
|
| +}
|
| +
|
| +void GpuArcVideoServiceHost::OnRequestArcVideoAcceleratorChannel(
|
| + uint32_t pid,
|
| + const OnRequestArcVideoAcceleratorChannelCallback& callback) {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| +
|
| + auto* ptr_info = new mojo::InterfacePtrInfo<arc::VideoHost>();
|
| +
|
| + io_task_runner_->PostTaskAndReply(
|
| + FROM_HERE, base::Bind(&GetServiceOnIOThread, base::Unretained(ptr_info)),
|
| + base::Bind(&GpuArcVideoServiceHost::BindServiceAndCreateChannel,
|
| + weak_factory_.GetWeakPtr(), pid, callback,
|
| + base::Owned(ptr_info)));
|
| +}
|
| +
|
| +void GpuArcVideoServiceHost::BindServiceAndCreateChannel(
|
| + uint32_t pid,
|
| + const OnRequestArcVideoAcceleratorChannelCallback& callback,
|
| + mojo::InterfacePtrInfo<arc::VideoHost>* ptr_info) {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| +
|
| + service_ptr_.Bind(std::move(*ptr_info));
|
| + service_ptr_->OnRequestArcVideoAcceleratorChannel(pid, callback);
|
| +}
|
| +
|
| +} // namespace arc
|
|
|