OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/arc/gpu_arc_video_service_host.h" |
| 6 |
| 7 #include "base/location.h" |
| 8 #include "base/logging.h" |
| 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/thread_task_runner_handle.h" |
| 11 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/public/browser/gpu_service_registry.h" |
| 13 #include "content/public/common/service_registry.h" |
| 14 |
| 15 namespace { |
| 16 |
| 17 void GetServiceOnIOThread(mojo::InterfacePtrInfo<arc::VideoHost>* ptr_info) { |
| 18 arc::VideoHostPtr host_ptr; |
| 19 content::ServiceRegistry* registry = content::GetGpuServiceRegistry(); |
| 20 registry->ConnectToRemoteService<arc::VideoHost>(mojo::GetProxy(&host_ptr)); |
| 21 |
| 22 // Unbind and reply back to UI thread. |
| 23 *ptr_info = host_ptr.PassInterface(); |
| 24 } |
| 25 |
| 26 } // namespace |
| 27 |
| 28 namespace arc { |
| 29 |
| 30 GpuArcVideoServiceHost::GpuArcVideoServiceHost( |
| 31 arc::ArcBridgeService* bridge_service) |
| 32 : ArcService(bridge_service), |
| 33 binding_(this), |
| 34 io_task_runner_(content::BrowserThread::GetMessageLoopProxyForThread( |
| 35 content::BrowserThread::IO)), |
| 36 weak_factory_(this) { |
| 37 arc_bridge_service()->AddObserver(this); |
| 38 } |
| 39 |
| 40 GpuArcVideoServiceHost::~GpuArcVideoServiceHost() { |
| 41 DCHECK(thread_checker_.CalledOnValidThread()); |
| 42 arc_bridge_service()->RemoveObserver(this); |
| 43 } |
| 44 |
| 45 void GpuArcVideoServiceHost::OnVideoInstanceReady() { |
| 46 DCHECK(thread_checker_.CalledOnValidThread()); |
| 47 arc_bridge_service()->video_instance()->Init( |
| 48 binding_.CreateInterfacePtrAndBind()); |
| 49 } |
| 50 |
| 51 void GpuArcVideoServiceHost::OnVideoInstanceClosed() { |
| 52 DCHECK(thread_checker_.CalledOnValidThread()); |
| 53 service_ptr_.reset(); |
| 54 } |
| 55 |
| 56 void GpuArcVideoServiceHost::OnRequestArcVideoAcceleratorChannel( |
| 57 uint32_t pid, |
| 58 const OnRequestArcVideoAcceleratorChannelCallback& callback) { |
| 59 DCHECK(thread_checker_.CalledOnValidThread()); |
| 60 |
| 61 auto* ptr_info = new mojo::InterfacePtrInfo<arc::VideoHost>(); |
| 62 |
| 63 io_task_runner_->PostTaskAndReply( |
| 64 FROM_HERE, base::Bind(&GetServiceOnIOThread, base::Unretained(ptr_info)), |
| 65 base::Bind(&GpuArcVideoServiceHost::BindServiceAndCreateChannel, |
| 66 weak_factory_.GetWeakPtr(), pid, callback, |
| 67 base::Owned(ptr_info))); |
| 68 } |
| 69 |
| 70 void GpuArcVideoServiceHost::BindServiceAndCreateChannel( |
| 71 uint32_t pid, |
| 72 const OnRequestArcVideoAcceleratorChannelCallback& callback, |
| 73 mojo::InterfacePtrInfo<arc::VideoHost>* ptr_info) { |
| 74 DCHECK(thread_checker_.CalledOnValidThread()); |
| 75 |
| 76 service_ptr_.Bind(std::move(*ptr_info)); |
| 77 service_ptr_->OnRequestArcVideoAcceleratorChannel(pid, callback); |
| 78 } |
| 79 |
| 80 } // namespace arc |
OLD | NEW |