Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(603)

Unified Diff: content/browser/gpu/gpu_arc_video_service_host.cc

Issue 1451353002: Implement GpuArcVideoService for arc video accelerator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased with new ArcBridgeService; addressed Owen's comments Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..5c512b3f0d21206342d1956e36907d3fac30fdf4
--- /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_request_(0),
+ weak_factory_(this) {}
+
+GpuArcVideoServiceHost::~GpuArcVideoServiceHost() {
+ DCHECK(CalledOnValidThread());
+
+ arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get();
+ if (bridge_service) {
+ while (num_pending_request_ > 0)
+ NotifyArcAcceleratorChannelCreated(IPC::ChannelHandle());
+ bridge_service->RemoveObserver(this);
+ bridge_service->RemoveVideoServiceObserver(this);
+ }
+}
+
+void GpuArcVideoServiceHost::Initialize() {
+ DCHECK(CalledOnValidThread());
+
+ arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get();
+ DCHECK(bridge_service);
Pawel Osciak 2015/12/16 10:17:58 Should we actually if(bridge_service) here (and in
kcwu 2015/12/16 14:05:33 Basically it is bug if bridge_service is null, hen
+ bridge_service->AddObserver(this);
+ bridge_service->AddVideoServiceObserver(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_request_++;
+ 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_request_, 0);
+
+ arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get();
+ DCHECK(bridge_service);
+ num_pending_request_--;
+ ignore_result(bridge_service->NotifyVideoAcceleratorChannelCreated(handle));
Pawel Osciak 2015/12/16 10:17:58 Is there any other caller that doesn't ignore_resu
kcwu 2015/12/16 14:05:33 Done.
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698