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

Side by Side Diff: chrome/gpu/gpu_arc_video_service.cc

Issue 1885683005: Add module suffix in .mojom files for components/arc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase only Created 4 years, 8 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
« no previous file with comments | « chrome/gpu/gpu_arc_video_service.h ('k') | components/arc/arc_bridge_bootstrap.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/gpu/gpu_arc_video_service.h" 5 #include "chrome/gpu/gpu_arc_video_service.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/thread_task_runner_handle.h" 13 #include "base/thread_task_runner_handle.h"
14 #include "chrome/gpu/arc_video_accelerator.h" 14 #include "chrome/gpu/arc_video_accelerator.h"
15 #include "components/arc/common/video_accelerator.mojom.h" 15 #include "components/arc/common/video_accelerator.mojom.h"
16 #include "mojo/edk/embedder/embedder.h" 16 #include "mojo/edk/embedder/embedder.h"
17 #include "mojo/public/cpp/bindings/binding.h" 17 #include "mojo/public/cpp/bindings/binding.h"
18 #include "mojo/public/cpp/bindings/type_converter.h" 18 #include "mojo/public/cpp/bindings/type_converter.h"
19 19
20 namespace mojo { 20 namespace mojo {
21 21
22 template <> 22 template <>
23 struct TypeConverter<arc::BufferMetadataPtr, chromeos::arc::BufferMetadata> { 23 struct TypeConverter<arc::mojom::BufferMetadataPtr,
24 static arc::BufferMetadataPtr Convert( 24 chromeos::arc::BufferMetadata> {
25 static arc::mojom::BufferMetadataPtr Convert(
25 const chromeos::arc::BufferMetadata& input) { 26 const chromeos::arc::BufferMetadata& input) {
26 arc::BufferMetadataPtr result = arc::BufferMetadata::New(); 27 arc::mojom::BufferMetadataPtr result = arc::mojom::BufferMetadata::New();
27 result->timestamp = input.timestamp; 28 result->timestamp = input.timestamp;
28 result->flags = input.flags; 29 result->flags = input.flags;
29 result->bytes_used = input.bytes_used; 30 result->bytes_used = input.bytes_used;
30 return result; 31 return result;
31 } 32 }
32 }; 33 };
33 34
34 template <> 35 template <>
35 struct TypeConverter<chromeos::arc::BufferMetadata, arc::BufferMetadataPtr> { 36 struct TypeConverter<chromeos::arc::BufferMetadata,
37 arc::mojom::BufferMetadataPtr> {
36 static chromeos::arc::BufferMetadata Convert( 38 static chromeos::arc::BufferMetadata Convert(
37 const arc::BufferMetadataPtr& input) { 39 const arc::mojom::BufferMetadataPtr& input) {
38 chromeos::arc::BufferMetadata result; 40 chromeos::arc::BufferMetadata result;
39 result.timestamp = input->timestamp; 41 result.timestamp = input->timestamp;
40 result.flags = input->flags; 42 result.flags = input->flags;
41 result.bytes_used = input->bytes_used; 43 result.bytes_used = input->bytes_used;
42 return result; 44 return result;
43 } 45 }
44 }; 46 };
45 47
46 template <> 48 template <>
47 struct TypeConverter<arc::VideoFormatPtr, chromeos::arc::VideoFormat> { 49 struct TypeConverter<arc::mojom::VideoFormatPtr, chromeos::arc::VideoFormat> {
48 static arc::VideoFormatPtr Convert(const chromeos::arc::VideoFormat& input) { 50 static arc::mojom::VideoFormatPtr Convert(
49 arc::VideoFormatPtr result = arc::VideoFormat::New(); 51 const chromeos::arc::VideoFormat& input) {
52 arc::mojom::VideoFormatPtr result = arc::mojom::VideoFormat::New();
50 result->pixel_format = input.pixel_format; 53 result->pixel_format = input.pixel_format;
51 result->buffer_size = input.buffer_size; 54 result->buffer_size = input.buffer_size;
52 result->min_num_buffers = input.min_num_buffers; 55 result->min_num_buffers = input.min_num_buffers;
53 result->coded_width = input.coded_width; 56 result->coded_width = input.coded_width;
54 result->coded_height = input.coded_height; 57 result->coded_height = input.coded_height;
55 result->crop_left = input.crop_left; 58 result->crop_left = input.crop_left;
56 result->crop_width = input.crop_width; 59 result->crop_width = input.crop_width;
57 result->crop_top = input.crop_top; 60 result->crop_top = input.crop_top;
58 result->crop_height = input.crop_height; 61 result->crop_height = input.crop_height;
59 return result; 62 return result;
60 } 63 }
61 }; 64 };
62 65
63 template <> 66 template <>
64 struct TypeConverter<chromeos::arc::ArcVideoAccelerator::Config, 67 struct TypeConverter<chromeos::arc::ArcVideoAccelerator::Config,
65 arc::ArcVideoAcceleratorConfigPtr> { 68 arc::mojom::ArcVideoAcceleratorConfigPtr> {
66 static chromeos::arc::ArcVideoAccelerator::Config Convert( 69 static chromeos::arc::ArcVideoAccelerator::Config Convert(
67 const arc::ArcVideoAcceleratorConfigPtr& input) { 70 const arc::mojom::ArcVideoAcceleratorConfigPtr& input) {
68 chromeos::arc::ArcVideoAccelerator::Config result; 71 chromeos::arc::ArcVideoAccelerator::Config result;
69 result.device_type = 72 result.device_type =
70 static_cast<chromeos::arc::ArcVideoAccelerator::Config::DeviceType>( 73 static_cast<chromeos::arc::ArcVideoAccelerator::Config::DeviceType>(
71 input->device_type); 74 input->device_type);
72 result.num_input_buffers = input->num_input_buffers; 75 result.num_input_buffers = input->num_input_buffers;
73 result.input_pixel_format = input->input_pixel_format; 76 result.input_pixel_format = input->input_pixel_format;
74 return result; 77 return result;
75 } 78 }
76 }; 79 };
77 80
78 } // namespace mojo 81 } // namespace mojo
79 82
80 namespace chromeos { 83 namespace chromeos {
81 namespace arc { 84 namespace arc {
82 85
83 class GpuArcVideoService::AcceleratorStub 86 class GpuArcVideoService::AcceleratorStub
84 : public ::arc::VideoAcceleratorService, 87 : public ::arc::mojom::VideoAcceleratorService,
85 public ArcVideoAccelerator::Client { 88 public ArcVideoAccelerator::Client {
86 public: 89 public:
87 // |owner| outlives AcceleratorStub. 90 // |owner| outlives AcceleratorStub.
88 explicit AcceleratorStub(GpuArcVideoService* owner) 91 explicit AcceleratorStub(GpuArcVideoService* owner)
89 : owner_(owner), binding_(this) {} 92 : owner_(owner), binding_(this) {}
90 93
91 ~AcceleratorStub() override { DCHECK(thread_checker_.CalledOnValidThread()); } 94 ~AcceleratorStub() override { DCHECK(thread_checker_.CalledOnValidThread()); }
92 95
93 bool Connect(const std::string& token) { 96 bool Connect(const std::string& token) {
94 DVLOG(2) << "Connect"; 97 DVLOG(2) << "Connect";
95 98
96 mojo::ScopedMessagePipeHandle server_pipe = 99 mojo::ScopedMessagePipeHandle server_pipe =
97 mojo::edk::CreateParentMessagePipe(token); 100 mojo::edk::CreateParentMessagePipe(token);
98 if (!server_pipe.is_valid()) { 101 if (!server_pipe.is_valid()) {
99 LOG(ERROR) << "Invalid pipe"; 102 LOG(ERROR) << "Invalid pipe";
100 return false; 103 return false;
101 } 104 }
102 105
103 client_.Bind(mojo::InterfacePtrInfo<::arc::VideoAcceleratorServiceClient>( 106 client_.Bind(
104 std::move(server_pipe), 0u)); 107 mojo::InterfacePtrInfo<::arc::mojom::VideoAcceleratorServiceClient>(
108 std::move(server_pipe), 0u));
105 109
106 // base::Unretained is safe because we own |client_| 110 // base::Unretained is safe because we own |client_|
107 client_.set_connection_error_handler( 111 client_.set_connection_error_handler(
108 base::Bind(&GpuArcVideoService::AcceleratorStub::OnConnectionError, 112 base::Bind(&GpuArcVideoService::AcceleratorStub::OnConnectionError,
109 base::Unretained(this))); 113 base::Unretained(this)));
110 114
111 // TODO(kcwu): create ArcGpuVideoDecodeAccelerator here. 115 // TODO(kcwu): create ArcGpuVideoDecodeAccelerator here.
112 // accelerator_.reset(new ArcGpuVideoDecodeAccelerator()); 116 // accelerator_.reset(new ArcGpuVideoDecodeAccelerator());
113 117
114 ::arc::VideoAcceleratorServicePtr service; 118 ::arc::mojom::VideoAcceleratorServicePtr service;
115 binding_.Bind(GetProxy(&service)); 119 binding_.Bind(GetProxy(&service));
116 // base::Unretained is safe because we own |binding_| 120 // base::Unretained is safe because we own |binding_|
117 binding_.set_connection_error_handler( 121 binding_.set_connection_error_handler(
118 base::Bind(&GpuArcVideoService::AcceleratorStub::OnConnectionError, 122 base::Bind(&GpuArcVideoService::AcceleratorStub::OnConnectionError,
119 base::Unretained(this))); 123 base::Unretained(this)));
120 124
121 client_->Init(std::move(service)); 125 client_->Init(std::move(service));
122 return true; 126 return true;
123 } 127 }
124 128
125 void OnConnectionError() { 129 void OnConnectionError() {
126 DVLOG(2) << "OnConnectionError"; 130 DVLOG(2) << "OnConnectionError";
127 owner_->RemoveClient(this); 131 owner_->RemoveClient(this);
128 // |this| is deleted. 132 // |this| is deleted.
129 } 133 }
130 134
131 // ArcVideoAccelerator::Client implementation: 135 // ArcVideoAccelerator::Client implementation:
132 void OnError(ArcVideoAccelerator::Error error) override { 136 void OnError(ArcVideoAccelerator::Error error) override {
133 DVLOG(2) << "OnError " << error; 137 DVLOG(2) << "OnError " << error;
134 client_->OnError( 138 client_->OnError(
135 static_cast<::arc::VideoAcceleratorServiceClient::Error>(error)); 139 static_cast<::arc::mojom::VideoAcceleratorServiceClient::Error>(error));
136 } 140 }
137 141
138 void OnBufferDone(PortType port, 142 void OnBufferDone(PortType port,
139 uint32_t index, 143 uint32_t index,
140 const BufferMetadata& metadata) override { 144 const BufferMetadata& metadata) override {
141 DVLOG(2) << "OnBufferDone " << port << "," << index; 145 DVLOG(2) << "OnBufferDone " << port << "," << index;
142 client_->OnBufferDone(static_cast<::arc::PortType>(port), index, 146 client_->OnBufferDone(static_cast<::arc::mojom::PortType>(port), index,
143 ::arc::BufferMetadata::From(metadata)); 147 ::arc::mojom::BufferMetadata::From(metadata));
144 } 148 }
145 149
146 void OnResetDone() override { 150 void OnResetDone() override {
147 DVLOG(2) << "OnResetDone"; 151 DVLOG(2) << "OnResetDone";
148 client_->OnResetDone(); 152 client_->OnResetDone();
149 } 153 }
150 154
151 void OnOutputFormatChanged(const VideoFormat& format) override { 155 void OnOutputFormatChanged(const VideoFormat& format) override {
152 DVLOG(2) << "OnOutputFormatChanged"; 156 DVLOG(2) << "OnOutputFormatChanged";
153 client_->OnOutputFormatChanged(::arc::VideoFormat::From(format)); 157 client_->OnOutputFormatChanged(::arc::mojom::VideoFormat::From(format));
154 } 158 }
155 159
156 // ::arc::VideoAcceleratorService impementation. 160 // ::arc::mojom::VideoAcceleratorService impementation.
157 void Initialize(::arc::ArcVideoAcceleratorConfigPtr config, 161 void Initialize(::arc::mojom::ArcVideoAcceleratorConfigPtr config,
158 const InitializeCallback& callback) override { 162 const InitializeCallback& callback) override {
159 DVLOG(2) << "Initialize"; 163 DVLOG(2) << "Initialize";
160 bool result = accelerator_->Initialize( 164 bool result = accelerator_->Initialize(
161 config.To<ArcVideoAccelerator::Config>(), this); 165 config.To<ArcVideoAccelerator::Config>(), this);
162 callback.Run(result); 166 callback.Run(result);
163 } 167 }
164 168
165 void BindSharedMemory(::arc::PortType port, 169 void BindSharedMemory(::arc::mojom::PortType port,
166 uint32_t index, 170 uint32_t index,
167 mojo::ScopedHandle ashmem_handle, 171 mojo::ScopedHandle ashmem_handle,
168 uint32_t offset, 172 uint32_t offset,
169 uint32_t length) override { 173 uint32_t length) override {
170 DVLOG(2) << "BindSharedMemoryCallback port=" << port << ", index=" << index 174 DVLOG(2) << "BindSharedMemoryCallback port=" << port << ", index=" << index
171 << ", offset=" << offset << ", length=" << length; 175 << ", offset=" << offset << ", length=" << length;
172 176
173 // TODO(kcwu) make sure do we need special care for invalid handle? 177 // TODO(kcwu) make sure do we need special care for invalid handle?
174 mojo::edk::ScopedPlatformHandle scoped_platform_handle; 178 mojo::edk::ScopedPlatformHandle scoped_platform_handle;
175 MojoResult mojo_result = mojo::edk::PassWrappedPlatformHandle( 179 MojoResult mojo_result = mojo::edk::PassWrappedPlatformHandle(
176 ashmem_handle.release().value(), &scoped_platform_handle); 180 ashmem_handle.release().value(), &scoped_platform_handle);
177 DCHECK_EQ(mojo_result, MOJO_RESULT_OK); 181 DCHECK_EQ(mojo_result, MOJO_RESULT_OK);
178 182
179 auto fd = base::ScopedFD(scoped_platform_handle.release().handle); 183 auto fd = base::ScopedFD(scoped_platform_handle.release().handle);
180 accelerator_->BindSharedMemory(static_cast<PortType>(port), index, 184 accelerator_->BindSharedMemory(static_cast<PortType>(port), index,
181 std::move(fd), offset, length); 185 std::move(fd), offset, length);
182 } 186 }
183 187
184 void BindDmabuf(::arc::PortType port, 188 void BindDmabuf(::arc::mojom::PortType port,
185 uint32_t index, 189 uint32_t index,
186 mojo::ScopedHandle dmabuf_handle) override { 190 mojo::ScopedHandle dmabuf_handle) override {
187 DVLOG(2) << "BindDmabuf port=" << port << ", index=" << index; 191 DVLOG(2) << "BindDmabuf port=" << port << ", index=" << index;
188 mojo::edk::ScopedPlatformHandle scoped_platform_handle; 192 mojo::edk::ScopedPlatformHandle scoped_platform_handle;
189 MojoResult mojo_result = mojo::edk::PassWrappedPlatformHandle( 193 MojoResult mojo_result = mojo::edk::PassWrappedPlatformHandle(
190 dmabuf_handle.release().value(), &scoped_platform_handle); 194 dmabuf_handle.release().value(), &scoped_platform_handle);
191 DCHECK_EQ(mojo_result, MOJO_RESULT_OK); 195 DCHECK_EQ(mojo_result, MOJO_RESULT_OK);
192 196
193 auto fd = base::ScopedFD(scoped_platform_handle.release().handle); 197 auto fd = base::ScopedFD(scoped_platform_handle.release().handle);
194 accelerator_->BindDmabuf(static_cast<PortType>(port), index, std::move(fd)); 198 accelerator_->BindDmabuf(static_cast<PortType>(port), index, std::move(fd));
195 } 199 }
196 200
197 void UseBuffer(::arc::PortType port, 201 void UseBuffer(::arc::mojom::PortType port,
198 uint32_t index, 202 uint32_t index,
199 ::arc::BufferMetadataPtr metadata) override { 203 ::arc::mojom::BufferMetadataPtr metadata) override {
200 DVLOG(2) << "UseBuffer port=" << port << ", index=" << index; 204 DVLOG(2) << "UseBuffer port=" << port << ", index=" << index;
201 accelerator_->UseBuffer(static_cast<PortType>(port), index, 205 accelerator_->UseBuffer(static_cast<PortType>(port), index,
202 metadata.To<BufferMetadata>()); 206 metadata.To<BufferMetadata>());
203 } 207 }
204 208
205 void SetNumberOfOutputBuffers(uint32_t number) override { 209 void SetNumberOfOutputBuffers(uint32_t number) override {
206 DVLOG(2) << "SetNumberOfOutputBuffers number=" << number; 210 DVLOG(2) << "SetNumberOfOutputBuffers number=" << number;
207 accelerator_->SetNumberOfOutputBuffers(number); 211 accelerator_->SetNumberOfOutputBuffers(number);
208 } 212 }
209 213
210 void Reset() override { accelerator_->Reset(); } 214 void Reset() override { accelerator_->Reset(); }
211 215
212 private: 216 private:
213 base::ThreadChecker thread_checker_; 217 base::ThreadChecker thread_checker_;
214 GpuArcVideoService* const owner_; 218 GpuArcVideoService* const owner_;
215 std::unique_ptr<ArcVideoAccelerator> accelerator_; 219 std::unique_ptr<ArcVideoAccelerator> accelerator_;
216 ::arc::VideoAcceleratorServiceClientPtr client_; 220 ::arc::mojom::VideoAcceleratorServiceClientPtr client_;
217 mojo::Binding<::arc::VideoAcceleratorService> binding_; 221 mojo::Binding<::arc::mojom::VideoAcceleratorService> binding_;
218 }; 222 };
219 223
220 GpuArcVideoService::GpuArcVideoService( 224 GpuArcVideoService::GpuArcVideoService(
221 mojo::InterfaceRequest<::arc::VideoHost> request) 225 mojo::InterfaceRequest<::arc::mojom::VideoHost> request)
222 : binding_(this, std::move(request)) {} 226 : binding_(this, std::move(request)) {}
223 227
224 GpuArcVideoService::~GpuArcVideoService() {} 228 GpuArcVideoService::~GpuArcVideoService() {}
225 229
226 void GpuArcVideoService::OnRequestArcVideoAcceleratorChannel( 230 void GpuArcVideoService::OnRequestArcVideoAcceleratorChannel(
227 const OnRequestArcVideoAcceleratorChannelCallback& callback) { 231 const OnRequestArcVideoAcceleratorChannelCallback& callback) {
228 DVLOG(1) << "OnRequestArcVideoAcceleratorChannelCallback"; 232 DVLOG(1) << "OnRequestArcVideoAcceleratorChannelCallback";
229 233
230 // Hardcode pid 0 since it is unused in mojo. 234 // Hardcode pid 0 since it is unused in mojo.
231 const base::ProcessHandle kUnusedChildProcessHandle = 0; 235 const base::ProcessHandle kUnusedChildProcessHandle = 0;
(...skipping 20 matching lines...) Expand all
252 256
253 callback.Run(mojo::ScopedHandle(mojo::Handle(wrapped_handle)), token); 257 callback.Run(mojo::ScopedHandle(mojo::Handle(wrapped_handle)), token);
254 } 258 }
255 259
256 void GpuArcVideoService::RemoveClient(AcceleratorStub* stub) { 260 void GpuArcVideoService::RemoveClient(AcceleratorStub* stub) {
257 accelerator_stubs_.erase(stub); 261 accelerator_stubs_.erase(stub);
258 } 262 }
259 263
260 } // namespace arc 264 } // namespace arc
261 } // namespace chromeos 265 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/gpu/gpu_arc_video_service.h ('k') | components/arc/arc_bridge_bootstrap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698