| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "components/mus/gles2/command_buffer_local.h" | 5 #include "components/mus/gles2/command_buffer_local.h" |
| 6 | 6 |
| 7 #include "base/atomic_sequence_num.h" | 7 #include "base/atomic_sequence_num.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/memory/shared_memory.h" | 9 #include "base/memory/shared_memory.h" |
| 10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 size_t height, | 226 size_t height, |
| 227 unsigned internal_format) { | 227 unsigned internal_format) { |
| 228 DCHECK(CalledOnValidThread()); | 228 DCHECK(CalledOnValidThread()); |
| 229 int32_t new_id = ++next_image_id_; | 229 int32_t new_id = ++next_image_id_; |
| 230 mojo::SizePtr size = mojo::Size::New(); | 230 mojo::SizePtr size = mojo::Size::New(); |
| 231 size->width = static_cast<int32_t>(width); | 231 size->width = static_cast<int32_t>(width); |
| 232 size->height = static_cast<int32_t>(height); | 232 size->height = static_cast<int32_t>(height); |
| 233 | 233 |
| 234 mus::MojoGpuMemoryBufferImpl* gpu_memory_buffer = | 234 mus::MojoGpuMemoryBufferImpl* gpu_memory_buffer = |
| 235 mus::MojoGpuMemoryBufferImpl::FromClientBuffer(buffer); | 235 mus::MojoGpuMemoryBufferImpl::FromClientBuffer(buffer); |
| 236 gfx::GpuMemoryBufferHandle handle = gpu_memory_buffer->GetHandle(); | |
| 237 | 236 |
| 238 bool requires_sync_point = false; | 237 bool requires_sync_point = false; |
| 239 if (handle.type != gfx::SHARED_MEMORY_BUFFER) { | 238 |
| 240 requires_sync_point = true; | 239 if (gpu_memory_buffer->GetBufferType() == gfx::SHARED_MEMORY_BUFFER) { |
| 240 gfx::GpuMemoryBufferHandle handle = gpu_memory_buffer->GetHandle(); |
| 241 // TODO(rjkroege): Verify that this is required and update appropriately. |
| 242 base::SharedMemoryHandle dupd_handle = |
| 243 base::SharedMemory::DuplicateHandle(handle.handle); |
| 244 #if defined(OS_WIN) |
| 245 HANDLE platform_handle = dupd_handle.GetHandle(); |
| 246 #else |
| 247 int platform_handle = dupd_handle.fd; |
| 248 #endif |
| 249 |
| 250 MojoHandle mojo_handle = MOJO_HANDLE_INVALID; |
| 251 MojoResult create_result = |
| 252 MojoCreatePlatformHandleWrapper(platform_handle, &mojo_handle); |
| 253 // |MojoCreatePlatformHandleWrapper()| always takes the ownership of the |
| 254 // |platform_handle|, so we don't need to close |platform_handle|. |
| 255 if (create_result != MOJO_RESULT_OK) { |
| 256 NOTIMPLEMENTED(); |
| 257 return -1; |
| 258 } |
| 259 mojo::ScopedHandle scoped_handle; |
| 260 scoped_handle.reset(mojo::Handle(mojo_handle)); |
| 261 |
| 262 const int32_t format = static_cast<int32_t>(gpu_memory_buffer->GetFormat()); |
| 263 gpu_state_->command_buffer_task_runner()->PostTask( |
| 264 driver_.get(), |
| 265 base::Bind(&CommandBufferLocal::CreateImageOnGpuThread, |
| 266 base::Unretained(this), new_id, base::Passed(&scoped_handle), |
| 267 handle.type, base::Passed(&size), format, internal_format)); |
| 268 #if defined(USE_OZONE) |
| 269 } else if (gpu_memory_buffer->GetBufferType() == gfx::OZONE_NATIVE_PIXMAP) { |
| 270 gpu_state_->command_buffer_task_runner()->PostTask( |
| 271 driver_.get(), |
| 272 base::Bind(&CommandBufferLocal::CreateImageNativeOzoneOnGpuThread, |
| 273 base::Unretained(this), new_id, |
| 274 gpu_memory_buffer->GetBufferType(), |
| 275 gpu_memory_buffer->GetSize(), gpu_memory_buffer->GetFormat(), |
| 276 internal_format, |
| 277 base::RetainedRef(gpu_memory_buffer->GetNativePixmap()))); |
| 278 #endif |
| 279 } else { |
| 241 NOTIMPLEMENTED(); | 280 NOTIMPLEMENTED(); |
| 242 return -1; | 281 return -1; |
| 243 } | 282 } |
| 244 | 283 |
| 245 base::SharedMemoryHandle dupd_handle = | |
| 246 base::SharedMemory::DuplicateHandle(handle.handle); | |
| 247 #if defined(OS_WIN) | |
| 248 HANDLE platform_handle = dupd_handle.GetHandle(); | |
| 249 #else | |
| 250 int platform_handle = dupd_handle.fd; | |
| 251 #endif | |
| 252 | |
| 253 MojoHandle mojo_handle = MOJO_HANDLE_INVALID; | |
| 254 MojoResult create_result = | |
| 255 MojoCreatePlatformHandleWrapper(platform_handle, &mojo_handle); | |
| 256 // |MojoCreatePlatformHandleWrapper()| always takes the ownership of the | |
| 257 // |platform_handle|, so we don't need close |platform_handle|. | |
| 258 if (create_result != MOJO_RESULT_OK) { | |
| 259 NOTIMPLEMENTED(); | |
| 260 return -1; | |
| 261 } | |
| 262 mojo::ScopedHandle scoped_handle; | |
| 263 scoped_handle.reset(mojo::Handle(mojo_handle)); | |
| 264 | |
| 265 const int32_t format = static_cast<int32_t>(gpu_memory_buffer->GetFormat()); | |
| 266 gpu_state_->command_buffer_task_runner()->PostTask( | |
| 267 driver_.get(), | |
| 268 base::Bind(&CommandBufferLocal::CreateImageOnGpuThread, | |
| 269 base::Unretained(this), new_id, base::Passed(&scoped_handle), | |
| 270 handle.type, base::Passed(&size), format, internal_format)); | |
| 271 | |
| 272 if (requires_sync_point) { | 284 if (requires_sync_point) { |
| 273 NOTIMPLEMENTED(); | 285 NOTIMPLEMENTED() << "Require sync points"; |
| 274 // TODO(jam): need to support this if we support types other than | 286 // TODO(jam): need to support this if we support types other than |
| 275 // SHARED_MEMORY_BUFFER. | 287 // SHARED_MEMORY_BUFFER. |
| 276 // gpu_memory_buffer_manager->SetDestructionSyncPoint(gpu_memory_buffer, | 288 // gpu_memory_buffer_manager->SetDestructionSyncPoint(gpu_memory_buffer, |
| 277 // InsertSyncPoint()); | 289 // InsertSyncPoint()); |
| 278 } | 290 } |
| 279 | 291 |
| 280 return new_id; | 292 return new_id; |
| 281 } | 293 } |
| 282 | 294 |
| 283 void CommandBufferLocal::DestroyImage(int32_t id) { | 295 void CommandBufferLocal::DestroyImage(int32_t id) { |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 int32_t type, | 516 int32_t type, |
| 505 mojo::SizePtr size, | 517 mojo::SizePtr size, |
| 506 int32_t format, | 518 int32_t format, |
| 507 int32_t internal_format) { | 519 int32_t internal_format) { |
| 508 DCHECK(driver_->IsScheduled()); | 520 DCHECK(driver_->IsScheduled()); |
| 509 driver_->CreateImage(id, std::move(memory_handle), type, std::move(size), | 521 driver_->CreateImage(id, std::move(memory_handle), type, std::move(size), |
| 510 format, internal_format); | 522 format, internal_format); |
| 511 return true; | 523 return true; |
| 512 } | 524 } |
| 513 | 525 |
| 526 bool CommandBufferLocal::CreateImageNativeOzoneOnGpuThread( |
| 527 int32_t id, |
| 528 int32_t type, |
| 529 gfx::Size size, |
| 530 gfx::BufferFormat format, |
| 531 uint32_t internal_format, |
| 532 ui::NativePixmap* pixmap) { |
| 533 DCHECK(driver_->IsScheduled()); |
| 534 driver_->CreateImageNativeOzone(id, type, size, format, internal_format, |
| 535 pixmap); |
| 536 return true; |
| 537 } |
| 538 |
| 514 bool CommandBufferLocal::DestroyImageOnGpuThread(int32_t id) { | 539 bool CommandBufferLocal::DestroyImageOnGpuThread(int32_t id) { |
| 515 DCHECK(driver_->IsScheduled()); | 540 DCHECK(driver_->IsScheduled()); |
| 516 driver_->DestroyImage(id); | 541 driver_->DestroyImage(id); |
| 517 return true; | 542 return true; |
| 518 } | 543 } |
| 519 | 544 |
| 520 bool CommandBufferLocal::MakeProgressOnGpuThread( | 545 bool CommandBufferLocal::MakeProgressOnGpuThread( |
| 521 base::WaitableEvent* event, | 546 base::WaitableEvent* event, |
| 522 gpu::CommandBuffer::State* state) { | 547 gpu::CommandBuffer::State* state) { |
| 523 DCHECK(driver_->IsScheduled()); | 548 DCHECK(driver_->IsScheduled()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 551 client_->UpdateVSyncParameters(timebase, interval); | 576 client_->UpdateVSyncParameters(timebase, interval); |
| 552 } | 577 } |
| 553 | 578 |
| 554 void CommandBufferLocal::OnGpuCompletedSwapBuffersOnClientThread( | 579 void CommandBufferLocal::OnGpuCompletedSwapBuffersOnClientThread( |
| 555 gfx::SwapResult result) { | 580 gfx::SwapResult result) { |
| 556 if (client_) | 581 if (client_) |
| 557 client_->GpuCompletedSwapBuffers(result); | 582 client_->GpuCompletedSwapBuffers(result); |
| 558 } | 583 } |
| 559 | 584 |
| 560 } // namespace mus | 585 } // namespace mus |
| OLD | NEW |