OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "mojo/gles2/command_buffer_client_impl.h" | 5 #include "mojo/gles2/command_buffer_client_impl.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/process/process_handle.h" | 10 #include "base/process/process_handle.h" |
11 #include "components/view_manager/gles2/command_buffer_type_conversions.h" | 11 #include "components/view_manager/gles2/command_buffer_type_conversions.h" |
12 #include "components/view_manager/gles2/mojo_buffer_backing.h" | 12 #include "components/view_manager/gles2/mojo_buffer_backing.h" |
| 13 #include "components/view_manager/gles2/mojo_gpu_memory_buffer.h" |
| 14 #include "gpu/command_buffer/service/image_factory.h" |
| 15 #include "mojo/platform_handle/platform_handle_functions.h" |
13 | 16 |
14 namespace gles2 { | 17 namespace gles2 { |
15 | 18 |
16 namespace { | 19 namespace { |
17 | 20 |
18 bool CreateMapAndDupSharedBuffer(size_t size, | 21 bool CreateMapAndDupSharedBuffer(size_t size, |
19 void** memory, | 22 void** memory, |
20 mojo::ScopedSharedBufferHandle* handle, | 23 mojo::ScopedSharedBufferHandle* handle, |
21 mojo::ScopedSharedBufferHandle* duped) { | 24 mojo::ScopedSharedBufferHandle* duped) { |
22 MojoResult result = mojo::CreateSharedBuffer(NULL, size, handle); | 25 MojoResult result = mojo::CreateSharedBuffer(NULL, size, handle); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 | 116 |
114 CommandBufferClientImpl::CommandBufferClientImpl( | 117 CommandBufferClientImpl::CommandBufferClientImpl( |
115 CommandBufferDelegate* delegate, | 118 CommandBufferDelegate* delegate, |
116 const MojoAsyncWaiter* async_waiter, | 119 const MojoAsyncWaiter* async_waiter, |
117 mojo::ScopedMessagePipeHandle command_buffer_handle) | 120 mojo::ScopedMessagePipeHandle command_buffer_handle) |
118 : delegate_(delegate), | 121 : delegate_(delegate), |
119 observer_binding_(this), | 122 observer_binding_(this), |
120 shared_state_(NULL), | 123 shared_state_(NULL), |
121 last_put_offset_(-1), | 124 last_put_offset_(-1), |
122 next_transfer_buffer_id_(0), | 125 next_transfer_buffer_id_(0), |
| 126 next_image_id_(0), |
123 async_waiter_(async_waiter) { | 127 async_waiter_(async_waiter) { |
124 command_buffer_.Bind(mojo::InterfacePtrInfo<mojo::CommandBuffer>( | 128 command_buffer_.Bind(mojo::InterfacePtrInfo<mojo::CommandBuffer>( |
125 command_buffer_handle.Pass(), 0u), | 129 command_buffer_handle.Pass(), 0u), |
126 async_waiter); | 130 async_waiter); |
127 command_buffer_.set_error_handler(this); | 131 command_buffer_.set_error_handler(this); |
128 } | 132 } |
129 | 133 |
130 CommandBufferClientImpl::~CommandBufferClientImpl() {} | 134 CommandBufferClientImpl::~CommandBufferClientImpl() {} |
131 | 135 |
132 bool CommandBufferClientImpl::Initialize() { | 136 bool CommandBufferClientImpl::Initialize() { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 } | 242 } |
239 | 243 |
240 gpu::Capabilities CommandBufferClientImpl::GetCapabilities() { | 244 gpu::Capabilities CommandBufferClientImpl::GetCapabilities() { |
241 return capabilities_; | 245 return capabilities_; |
242 } | 246 } |
243 | 247 |
244 int32_t CommandBufferClientImpl::CreateImage(ClientBuffer buffer, | 248 int32_t CommandBufferClientImpl::CreateImage(ClientBuffer buffer, |
245 size_t width, | 249 size_t width, |
246 size_t height, | 250 size_t height, |
247 unsigned internalformat) { | 251 unsigned internalformat) { |
248 // TODO(piman) | 252 int32 new_id = ++next_image_id_; |
249 NOTIMPLEMENTED(); | 253 |
250 return -1; | 254 mojo::SizePtr size = mojo::Size::New(); |
| 255 size->width = width; |
| 256 size->height = height; |
| 257 |
| 258 MojoGpuMemoryBufferImpl* gpu_memory_buffer = |
| 259 MojoGpuMemoryBufferImpl::FromClientBuffer(buffer); |
| 260 gfx::GpuMemoryBufferHandle handle = gpu_memory_buffer->GetHandle(); |
| 261 |
| 262 bool requires_sync_point = false; |
| 263 base::SharedMemoryHandle dupd_handle = |
| 264 base::SharedMemory::DuplicateHandle(handle.handle); |
| 265 #if defined(OS_WIN) |
| 266 HANDLE platform_handle = dupd_handle; |
| 267 #else |
| 268 int platform_handle = dupd_handle.fd; |
| 269 #endif |
| 270 |
| 271 if (handle.type != gfx::SHARED_MEMORY_BUFFER) { |
| 272 requires_sync_point = true; |
| 273 NOTIMPLEMENTED(); |
| 274 return -1; |
| 275 } |
| 276 |
| 277 MojoHandle mojo_handle = MOJO_HANDLE_INVALID; |
| 278 MojoResult create_result = MojoCreatePlatformHandleWrapper( |
| 279 platform_handle, &mojo_handle); |
| 280 if (create_result != MOJO_RESULT_OK) { |
| 281 NOTIMPLEMENTED(); |
| 282 return -1; |
| 283 } |
| 284 mojo::ScopedHandle scoped_handle; |
| 285 scoped_handle.reset(mojo::Handle(mojo_handle)); |
| 286 command_buffer_->CreateImage(new_id, |
| 287 scoped_handle.Pass(), |
| 288 handle.type, |
| 289 size.Pass(), |
| 290 gpu_memory_buffer->GetFormat(), |
| 291 internalformat); |
| 292 if (requires_sync_point) { |
| 293 NOTIMPLEMENTED(); |
| 294 // TODO(jam): need to support this if we support types other than |
| 295 // SHARED_MEMORY_BUFFER. |
| 296 //gpu_memory_buffer_manager->SetDestructionSyncPoint(gpu_memory_buffer, |
| 297 // InsertSyncPoint()); |
| 298 } |
| 299 |
| 300 return new_id; |
251 } | 301 } |
252 | 302 |
253 void CommandBufferClientImpl::DestroyImage(int32 id) { | 303 void CommandBufferClientImpl::DestroyImage(int32 id) { |
254 // TODO(piman) | 304 command_buffer_->DestroyImage(id); |
255 NOTIMPLEMENTED(); | |
256 } | 305 } |
257 | 306 |
258 int32_t CommandBufferClientImpl::CreateGpuMemoryBufferImage( | 307 int32_t CommandBufferClientImpl::CreateGpuMemoryBufferImage( |
259 size_t width, | 308 size_t width, |
260 size_t height, | 309 size_t height, |
261 unsigned internalformat, | 310 unsigned internalformat, |
262 unsigned usage) { | 311 unsigned usage) { |
263 // TODO(piman) | 312 scoped_ptr<gfx::GpuMemoryBuffer> buffer(MojoGpuMemoryBufferImpl::Create( |
264 NOTIMPLEMENTED(); | 313 gfx::Size(width, height), |
265 return -1; | 314 gpu::ImageFactory::ImageFormatToGpuMemoryBufferFormat(internalformat), |
| 315 gpu::ImageFactory::ImageUsageToGpuMemoryBufferUsage(usage))); |
| 316 if (!buffer) |
| 317 return -1; |
| 318 |
| 319 return CreateImage(buffer->AsClientBuffer(), width, height, internalformat); |
266 } | 320 } |
267 | 321 |
268 uint32_t CommandBufferClientImpl::InsertSyncPoint() { | 322 uint32_t CommandBufferClientImpl::InsertSyncPoint() { |
269 command_buffer_->InsertSyncPoint(true); | 323 command_buffer_->InsertSyncPoint(true); |
270 return sync_point_client_impl_->WaitForInsertSyncPoint(); | 324 return sync_point_client_impl_->WaitForInsertSyncPoint(); |
271 } | 325 } |
272 | 326 |
273 uint32_t CommandBufferClientImpl::InsertFutureSyncPoint() { | 327 uint32_t CommandBufferClientImpl::InsertFutureSyncPoint() { |
274 command_buffer_->InsertSyncPoint(false); | 328 command_buffer_->InsertSyncPoint(false); |
275 return sync_point_client_impl_->WaitForInsertSyncPoint(); | 329 return sync_point_client_impl_->WaitForInsertSyncPoint(); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 | 388 |
335 void CommandBufferClientImpl::SetLock(base::Lock* lock) { | 389 void CommandBufferClientImpl::SetLock(base::Lock* lock) { |
336 } | 390 } |
337 | 391 |
338 bool CommandBufferClientImpl::IsGpuChannelLost() { | 392 bool CommandBufferClientImpl::IsGpuChannelLost() { |
339 // This is only possible for out-of-process command buffers. | 393 // This is only possible for out-of-process command buffers. |
340 return false; | 394 return false; |
341 } | 395 } |
342 | 396 |
343 } // namespace gles2 | 397 } // namespace gles2 |
OLD | NEW |