OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 "content/browser/gpu/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 "content/browser/gpu/gpu_process_host.h" |
| 11 #include "content/common/gpu/gpu_messages.h" |
| 12 #include "content/public/browser/browser_thread.h" |
| 13 #include "ipc/ipc_message_macros.h" |
| 14 #include "ipc/ipc_message_utils.h" |
| 15 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h" |
| 16 |
| 17 namespace content { |
| 18 |
| 19 namespace { |
| 20 void CreateChannelOnIOThread( |
| 21 const GpuProcessHost::CreateArcVideoAcceleratorChannelCallback& callback) { |
| 22 GpuProcessHost* gpu_process_host = |
| 23 GpuProcessHost::Get(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, |
| 24 CAUSE_FOR_GPU_LAUNCH_ARCVIDEOACCELERATOR); |
| 25 gpu_process_host->CreateArcVideoAcceleratorChannel(callback); |
| 26 } |
| 27 } |
| 28 |
| 29 GpuArcVideoServiceHost::GpuArcVideoServiceHost() |
| 30 : io_task_runner_(content::BrowserThread::GetMessageLoopProxyForThread( |
| 31 content::BrowserThread::IO)), |
| 32 binding_(this), |
| 33 weak_factory_(this) {} |
| 34 |
| 35 GpuArcVideoServiceHost::~GpuArcVideoServiceHost() { |
| 36 DCHECK(CalledOnValidThread()); |
| 37 |
| 38 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); |
| 39 if (bridge_service) { |
| 40 bridge_service->RemoveObserver(this); |
| 41 } |
| 42 } |
| 43 |
| 44 void GpuArcVideoServiceHost::Initialize() { |
| 45 DCHECK(CalledOnValidThread()); |
| 46 |
| 47 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); |
| 48 DCHECK(bridge_service); |
| 49 bridge_service->AddObserver(this); |
| 50 if (bridge_service->video_instance()) |
| 51 OnVideoInstanceReady(); |
| 52 } |
| 53 |
| 54 void GpuArcVideoServiceHost::OnStateChanged( |
| 55 arc::ArcBridgeService::State state) { |
| 56 DCHECK(CalledOnValidThread()); |
| 57 switch (state) { |
| 58 case arc::ArcBridgeService::State::STOPPING: |
| 59 Shutdown(); |
| 60 break; |
| 61 default: |
| 62 break; |
| 63 } |
| 64 } |
| 65 |
| 66 void GpuArcVideoServiceHost::OnVideoInstanceReady() { |
| 67 DCHECK(CalledOnValidThread()); |
| 68 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); |
| 69 DCHECK(bridge_service); |
| 70 |
| 71 arc::VideoHostPtr host; |
| 72 binding_.Bind(mojo::GetProxy(&host)); |
| 73 bridge_service->video_instance()->Init(std::move(host)); |
| 74 } |
| 75 |
| 76 void GpuArcVideoServiceHost::OnRequestArcVideoAcceleratorChannel( |
| 77 const OnRequestArcVideoAcceleratorChannelCallback& callback) { |
| 78 DCHECK(CalledOnValidThread()); |
| 79 |
| 80 io_task_runner_->PostTask( |
| 81 FROM_HERE, |
| 82 base::Bind(&CreateChannelOnIOThread, |
| 83 base::Bind(&GpuArcVideoServiceHost::ReplyChannelCreated, |
| 84 weak_factory_.GetWeakPtr(), callback))); |
| 85 } |
| 86 |
| 87 void GpuArcVideoServiceHost::Shutdown() { |
| 88 GpuProcessHost::SendOnIO(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, |
| 89 CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH, |
| 90 new GpuMsg_ShutdownArcVideoService()); |
| 91 } |
| 92 |
| 93 void GpuArcVideoServiceHost::ReplyChannelCreated( |
| 94 const OnRequestArcVideoAcceleratorChannelCallback& callback, |
| 95 const IPC::ChannelHandle& handle) { |
| 96 DCHECK(CalledOnValidThread()); |
| 97 |
| 98 MojoHandle wrapped_handle; |
| 99 MojoResult wrap_result = mojo::embedder::CreatePlatformHandleWrapper( |
| 100 mojo::embedder::ScopedPlatformHandle( |
| 101 mojo::embedder::PlatformHandle(handle.socket.fd)), |
| 102 &wrapped_handle); |
| 103 if (wrap_result != MOJO_RESULT_OK) { |
| 104 LOG(WARNING) << "Pipe failed to wrap handles. Closing: " << wrap_result; |
| 105 callback.Run(mojo::ScopedHandle()); |
| 106 return; |
| 107 } |
| 108 callback.Run(mojo::ScopedHandle(mojo::Handle(wrapped_handle))); |
| 109 } |
| 110 |
| 111 } // namespace content |
OLD | NEW |