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..ea9aa8c971cf54f904594d9069aec02ac11d1d73 |
--- /dev/null |
+++ b/content/browser/gpu/gpu_arc_video_service_host.cc |
@@ -0,0 +1,96 @@ |
+// 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 "ipc/ipc_message_macros.h" |
+#include "ipc/ipc_message_utils.h" |
+ |
+namespace content { |
+ |
+namespace { |
+void CreateConnectionOnIOThread( |
+ 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.
|
+ GpuProcessHost* gpu_process_host = |
+ GpuProcessHost::Get(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, |
+ CAUSE_FOR_GPU_LAUNCH_ARCVIDEOACCELERATOR); |
+ gpu_process_host->CreateArcVideoAcceleratorChannel(callback); |
+} |
+} |
+ |
+GpuArcVideoServiceHost::GpuArcVideoServiceHost( |
+ const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) |
+ : io_task_runner_(io_task_runner), |
+ num_pending_request_(0), |
+ weak_factory_(this) {} |
+ |
+GpuArcVideoServiceHost::~GpuArcVideoServiceHost() { |
+ DCHECK(CalledOnValidThread()); |
+ |
+ 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.
|
+ arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); |
+ if (bridge_service) { |
+ while (num_pending_request_ > 0) |
+ NotifyArcAcceleratorChannelCreated(IPC::ChannelHandle()); |
+ bridge_service->RemoveObserver(this); |
+ } |
+} |
+ |
+void GpuArcVideoServiceHost::Initialize() { |
+ DCHECK(CalledOnValidThread()); |
+ |
+ arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); |
+ DCHECK(bridge_service); |
+ bridge_service->AddObserver(this); |
+} |
+ |
+void GpuArcVideoServiceHost::OnStateChanged( |
+ arc::ArcBridgeService::State state) { |
+ DCHECK(CalledOnValidThread()); |
+ switch (state) { |
+ 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
|
+ Shutdown(); |
+ break; |
+ default: |
+ break; |
+ } |
+} |
+ |
+void GpuArcVideoServiceHost::OnCreateArcVideoAcceleratorConnection() { |
+ DCHECK(CalledOnValidThread()); |
+ num_pending_request_++; |
+ io_task_runner_->PostTask( |
+ FROM_HERE, |
+ base::Bind( |
+ &CreateConnectionOnIOThread, |
+ base::Bind( |
+ &GpuArcVideoServiceHost::NotifyArcAcceleratorChannelCreated, |
+ weak_factory_.GetWeakPtr()))); |
+} |
+ |
+void GpuArcVideoServiceHost::Shutdown() { |
+ GpuProcessHost::SendOnIO(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, |
+ CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH, |
+ new GpuMsg_ShutdownArcVideoService()); |
+} |
+ |
+void GpuArcVideoServiceHost::NotifyArcAcceleratorChannelCreated( |
+ const IPC::ChannelHandle& handle) { |
+ DCHECK(CalledOnValidThread()); |
+ |
+ DCHECK_GT(num_pending_request_, 0); |
+ |
+ arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); |
+ DCHECK(bridge_service); |
+ num_pending_request_--; |
+ ignore_result( |
+ bridge_service->NotifyVideoAcceleratorConnectionCreated(handle)); |
+} |
+ |
+} // namespace content |