| 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..12299c5c29af26213a6bd95cfdaf3bda0ae2e04d
|
| --- /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 CreateChannelOnIOThread(
|
| + const GpuProcessHost::CreateArcVideoAcceleratorChannelCallback& callback) {
|
| + 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_requests_(0),
|
| + weak_factory_(this) {}
|
| +
|
| +GpuArcVideoServiceHost::~GpuArcVideoServiceHost() {
|
| + DCHECK(CalledOnValidThread());
|
| +
|
| + arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get();
|
| + if (bridge_service) {
|
| + while (num_pending_requests_ > 0)
|
| + NotifyArcAcceleratorChannelCreated(IPC::ChannelHandle());
|
| + bridge_service->SetVideoService(nullptr);
|
| + bridge_service->RemoveObserver(this);
|
| + }
|
| +}
|
| +
|
| +void GpuArcVideoServiceHost::Initialize() {
|
| + DCHECK(CalledOnValidThread());
|
| +
|
| + arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get();
|
| + DCHECK(bridge_service);
|
| + bridge_service->AddObserver(this);
|
| + bridge_service->SetVideoService(this);
|
| +}
|
| +
|
| +void GpuArcVideoServiceHost::OnStateChanged(
|
| + arc::ArcBridgeService::State state) {
|
| + DCHECK(CalledOnValidThread());
|
| + switch (state) {
|
| + case arc::ArcBridgeService::State::STOPPING:
|
| + Shutdown();
|
| + break;
|
| + default:
|
| + break;
|
| + }
|
| +}
|
| +
|
| +void GpuArcVideoServiceHost::OnRequestArcVideoAcceleratorChannel() {
|
| + DCHECK(CalledOnValidThread());
|
| + num_pending_requests_++;
|
| + io_task_runner_->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(
|
| + &CreateChannelOnIOThread,
|
| + 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_requests_, 0);
|
| +
|
| + arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get();
|
| + DCHECK(bridge_service);
|
| + num_pending_requests_--;
|
| + bridge_service->NotifyVideoAcceleratorChannelCreated(handle);
|
| +}
|
| +
|
| +} // namespace content
|
|
|