Chromium Code Reviews| 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 "ipc/ipc_message_macros.h" | |
| 13 #include "ipc/ipc_message_utils.h" | |
| 14 | |
| 15 namespace content { | |
| 16 | |
| 17 namespace { | |
| 18 void CreateConnectionOnIOThread( | |
| 19 const GpuProcessHost::CreateArcVideoAcceleratorChannelCallback& callback) { | |
|
Owen Lin
2015/12/07 09:05:23
Can we unify the naming? Is connection == channel?
kcwu
2015/12/10 10:17:37
Done.
| |
| 20 GpuProcessHost* gpu_process_host = | |
| 21 GpuProcessHost::Get(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, | |
| 22 CAUSE_FOR_GPU_LAUNCH_ARCVIDEOACCELERATOR); | |
| 23 gpu_process_host->CreateArcVideoAcceleratorChannel(callback); | |
| 24 } | |
| 25 } | |
| 26 | |
| 27 GpuArcVideoServiceHost::GpuArcVideoServiceHost( | |
| 28 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) | |
| 29 : io_task_runner_(io_task_runner), | |
| 30 num_pending_request_(0), | |
| 31 weak_factory_(this) {} | |
| 32 | |
| 33 GpuArcVideoServiceHost::~GpuArcVideoServiceHost() { | |
| 34 DCHECK(CalledOnValidThread()); | |
| 35 | |
| 36 weak_factory_.InvalidateWeakPtrs(); | |
|
Owen Lin
2015/12/07 09:05:23
I thought it will be called automatically.
kcwu
2015/12/10 10:17:37
Done.
| |
| 37 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); | |
| 38 if (bridge_service) { | |
| 39 while (num_pending_request_ > 0) | |
| 40 NotifyArcAcceleratorChannelCreated(IPC::ChannelHandle()); | |
| 41 bridge_service->RemoveObserver(this); | |
| 42 } | |
| 43 } | |
| 44 | |
| 45 void GpuArcVideoServiceHost::Initialize() { | |
| 46 DCHECK(CalledOnValidThread()); | |
| 47 | |
| 48 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); | |
| 49 DCHECK(bridge_service); | |
| 50 bridge_service->AddObserver(this); | |
| 51 } | |
| 52 | |
| 53 void GpuArcVideoServiceHost::OnStateChanged( | |
| 54 arc::ArcBridgeService::State state) { | |
| 55 DCHECK(CalledOnValidThread()); | |
| 56 switch (state) { | |
| 57 case arc::ArcBridgeService::State::STOPPING: | |
|
Owen Lin
2015/12/07 09:05:23
When will this happened? Will it happens when we r
kcwu
2015/12/10 10:17:37
Yes
| |
| 58 Shutdown(); | |
| 59 break; | |
| 60 default: | |
| 61 break; | |
| 62 } | |
| 63 } | |
| 64 | |
| 65 void GpuArcVideoServiceHost::OnCreateArcVideoAcceleratorConnection() { | |
| 66 DCHECK(CalledOnValidThread()); | |
| 67 num_pending_request_++; | |
| 68 io_task_runner_->PostTask( | |
| 69 FROM_HERE, | |
| 70 base::Bind( | |
| 71 &CreateConnectionOnIOThread, | |
| 72 base::Bind( | |
| 73 &GpuArcVideoServiceHost::NotifyArcAcceleratorChannelCreated, | |
| 74 weak_factory_.GetWeakPtr()))); | |
| 75 } | |
| 76 | |
| 77 void GpuArcVideoServiceHost::Shutdown() { | |
| 78 GpuProcessHost::SendOnIO(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, | |
| 79 CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH, | |
| 80 new GpuMsg_ShutdownArcVideoService()); | |
| 81 } | |
| 82 | |
| 83 void GpuArcVideoServiceHost::NotifyArcAcceleratorChannelCreated( | |
| 84 const IPC::ChannelHandle& handle) { | |
| 85 DCHECK(CalledOnValidThread()); | |
| 86 | |
| 87 DCHECK_GT(num_pending_request_, 0); | |
| 88 | |
| 89 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); | |
| 90 DCHECK(bridge_service); | |
| 91 num_pending_request_--; | |
| 92 ignore_result( | |
| 93 bridge_service->NotifyVideoAcceleratorConnectionCreated(handle)); | |
| 94 } | |
| 95 | |
| 96 } // namespace content | |
| OLD | NEW |