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

Side by Side 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: addressed Luis's comments Created 4 years, 12 months 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 unified diff | Download patch
OLDNEW
(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 while (!callbacks_.empty())
39 ReplyChannelCreated(IPC::ChannelHandle());
40
41 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get();
42 if (bridge_service) {
43 bridge_service->RemoveObserver(this);
44 }
45 }
46
47 void GpuArcVideoServiceHost::Initialize() {
48 DCHECK(CalledOnValidThread());
49
50 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get();
51 DCHECK(bridge_service);
52 bridge_service->AddObserver(this);
Luis Héctor Chávez 2015/12/23 00:02:53 if (arc_bridge_service->video_instance()) OnVide
kcwu 2015/12/23 01:05:23 Done.
53 }
54
55 void GpuArcVideoServiceHost::OnStateChanged(
56 arc::ArcBridgeService::State state) {
57 DCHECK(CalledOnValidThread());
58 switch (state) {
59 case arc::ArcBridgeService::State::STOPPING:
60 Shutdown();
61 break;
62 default:
63 break;
64 }
65 }
66
67 void GpuArcVideoServiceHost::OnVideoInstanceReady() {
68 DCHECK(CalledOnValidThread());
69 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get();
70 DCHECK(bridge_service);
71
72 arc::VideoHostPtr host;
73 binding_.Bind(mojo::GetProxy(&host));
74 bridge_service->video_instance()->Init(std::move(host));
75 }
76
77 void GpuArcVideoServiceHost::OnRequestArcVideoAcceleratorChannel(
78 const OnRequestArcVideoAcceleratorChannelCallback& callback) {
79 DCHECK(CalledOnValidThread());
80
81 callbacks_.push(callback);
82 io_task_runner_->PostTask(
83 FROM_HERE,
84 base::Bind(&CreateChannelOnIOThread,
85 base::Bind(&GpuArcVideoServiceHost::ReplyChannelCreated,
Luis Héctor Chávez 2015/12/23 00:02:53 How about you change ReplyChannelCreated to also r
kcwu 2015/12/23 01:05:23 Done.
86 weak_factory_.GetWeakPtr())));
87 }
88
89 void GpuArcVideoServiceHost::Shutdown() {
90 GpuProcessHost::SendOnIO(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED,
91 CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH,
92 new GpuMsg_ShutdownArcVideoService());
93 }
94
95 void GpuArcVideoServiceHost::ReplyChannelCreated(
96 const IPC::ChannelHandle& handle) {
97 DCHECK(CalledOnValidThread());
98
99 DCHECK(!callbacks_.empty());
100 OnRequestArcVideoAcceleratorChannelCallback callback = callbacks_.front();
101 callbacks_.pop();
102
103 MojoHandle wrapped_handle;
104 MojoResult wrap_result = mojo::embedder::CreatePlatformHandleWrapper(
105 mojo::embedder::ScopedPlatformHandle(
106 mojo::embedder::PlatformHandle(handle.socket.fd)),
107 &wrapped_handle);
108 if (wrap_result != MOJO_RESULT_OK) {
109 LOG(WARNING) << "Pipe failed to wrap handles. Closing: " << wrap_result;
110 callback.Run(mojo::ScopedHandle());
111 return;
112 }
113 callback.Run(mojo::ScopedHandle(mojo::Handle(wrapped_handle)));
114 }
115
116 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698