| 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 "base/threading/thread_restrictions.h" | 11 #include "base/threading/thread_restrictions.h" |
| 12 #include "components/mus/gles2/command_buffer_type_conversions.h" | 12 #include "components/mus/gles2/command_buffer_type_conversions.h" |
| 13 #include "components/mus/gles2/mojo_buffer_backing.h" | 13 #include "components/mus/gles2/mojo_buffer_backing.h" |
| 14 #include "components/mus/gles2/mojo_gpu_memory_buffer.h" | 14 #include "components/mus/gles2/mojo_gpu_memory_buffer.h" |
| 15 #include "gpu/command_buffer/common/sync_token.h" |
| 15 #include "gpu/command_buffer/service/image_factory.h" | 16 #include "gpu/command_buffer/service/image_factory.h" |
| 16 #include "mojo/platform_handle/platform_handle_functions.h" | 17 #include "mojo/platform_handle/platform_handle_functions.h" |
| 17 | 18 |
| 18 namespace gles2 { | 19 namespace gles2 { |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 bool CreateMapAndDupSharedBuffer(size_t size, | 23 bool CreateMapAndDupSharedBuffer(size_t size, |
| 23 void** memory, | 24 void** memory, |
| 24 mojo::ScopedSharedBufferHandle* handle, | 25 mojo::ScopedSharedBufferHandle* handle, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 46 | 47 |
| 47 CommandBufferDelegate::~CommandBufferDelegate() {} | 48 CommandBufferDelegate::~CommandBufferDelegate() {} |
| 48 | 49 |
| 49 void CommandBufferDelegate::ContextLost() {} | 50 void CommandBufferDelegate::ContextLost() {} |
| 50 | 51 |
| 51 class CommandBufferClientImpl::SyncClientImpl | 52 class CommandBufferClientImpl::SyncClientImpl |
| 52 : public mus::mojom::CommandBufferSyncClient { | 53 : public mus::mojom::CommandBufferSyncClient { |
| 53 public: | 54 public: |
| 54 SyncClientImpl(mus::mojom::CommandBufferSyncClientPtr* ptr, | 55 SyncClientImpl(mus::mojom::CommandBufferSyncClientPtr* ptr, |
| 55 const MojoAsyncWaiter* async_waiter) | 56 const MojoAsyncWaiter* async_waiter) |
| 56 : initialized_successfully_(false), binding_(this, ptr, async_waiter) {} | 57 : initialized_successfully_(false), |
| 58 command_buffer_id_(0), |
| 59 binding_(this, ptr, async_waiter) {} |
| 57 | 60 |
| 58 bool WaitForInitialization() { | 61 bool WaitForInitialization() { |
| 59 base::ThreadRestrictions::ScopedAllowWait wait; | 62 base::ThreadRestrictions::ScopedAllowWait wait; |
| 60 if (!binding_.WaitForIncomingMethodCall()) | 63 if (!binding_.WaitForIncomingMethodCall()) |
| 61 return false; | 64 return false; |
| 62 return initialized_successfully_; | 65 return initialized_successfully_; |
| 63 } | 66 } |
| 64 | 67 |
| 65 mus::mojom::CommandBufferStatePtr WaitForProgress() { | 68 mus::mojom::CommandBufferStatePtr WaitForProgress() { |
| 66 base::ThreadRestrictions::ScopedAllowWait wait; | 69 base::ThreadRestrictions::ScopedAllowWait wait; |
| 67 if (!binding_.WaitForIncomingMethodCall()) | 70 if (!binding_.WaitForIncomingMethodCall()) |
| 68 return mus::mojom::CommandBufferStatePtr(); | 71 return mus::mojom::CommandBufferStatePtr(); |
| 69 return command_buffer_state_.Pass(); | 72 return command_buffer_state_.Pass(); |
| 70 } | 73 } |
| 71 | 74 |
| 72 gpu::Capabilities GetCapabilities() { | 75 gpu::Capabilities GetCapabilities() { |
| 73 if (capabilities_) | 76 if (capabilities_) |
| 74 return capabilities_.To<gpu::Capabilities>(); | 77 return capabilities_.To<gpu::Capabilities>(); |
| 75 return gpu::Capabilities(); | 78 return gpu::Capabilities(); |
| 76 } | 79 } |
| 77 | 80 |
| 81 uint64_t GetCommandBufferID() const { |
| 82 return command_buffer_id_; |
| 83 } |
| 84 |
| 78 private: | 85 private: |
| 79 // CommandBufferSyncClient methods: | 86 // CommandBufferSyncClient methods: |
| 80 void DidInitialize(bool success, | 87 void DidInitialize(bool success, |
| 88 int32_t command_buffer_namespace, |
| 89 uint64_t command_buffer_id, |
| 81 mus::mojom::GpuCapabilitiesPtr capabilities) override { | 90 mus::mojom::GpuCapabilitiesPtr capabilities) override { |
| 91 DCHECK_EQ(command_buffer_namespace, gpu::CommandBufferNamespace::MOJO); |
| 82 initialized_successfully_ = success; | 92 initialized_successfully_ = success; |
| 93 command_buffer_id_ = command_buffer_id; |
| 83 capabilities_ = capabilities.Pass(); | 94 capabilities_ = capabilities.Pass(); |
| 84 } | 95 } |
| 85 void DidMakeProgress(mus::mojom::CommandBufferStatePtr state) override { | 96 void DidMakeProgress(mus::mojom::CommandBufferStatePtr state) override { |
| 86 command_buffer_state_ = state.Pass(); | 97 command_buffer_state_ = state.Pass(); |
| 87 } | 98 } |
| 88 | 99 |
| 89 bool initialized_successfully_; | 100 bool initialized_successfully_; |
| 101 uint64_t command_buffer_id_; |
| 90 mus::mojom::GpuCapabilitiesPtr capabilities_; | 102 mus::mojom::GpuCapabilitiesPtr capabilities_; |
| 91 mus::mojom::CommandBufferStatePtr command_buffer_state_; | 103 mus::mojom::CommandBufferStatePtr command_buffer_state_; |
| 92 mojo::Binding<mus::mojom::CommandBufferSyncClient> binding_; | 104 mojo::Binding<mus::mojom::CommandBufferSyncClient> binding_; |
| 93 | 105 |
| 94 DISALLOW_COPY_AND_ASSIGN(SyncClientImpl); | 106 DISALLOW_COPY_AND_ASSIGN(SyncClientImpl); |
| 95 }; | 107 }; |
| 96 | 108 |
| 97 class CommandBufferClientImpl::SyncPointClientImpl | 109 class CommandBufferClientImpl::SyncPointClientImpl |
| 98 : public mus::mojom::CommandBufferSyncPointClient { | 110 : public mus::mojom::CommandBufferSyncPointClient { |
| 99 public: | 111 public: |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 bool CommandBufferClientImpl::IsGpuChannelLost() { | 408 bool CommandBufferClientImpl::IsGpuChannelLost() { |
| 397 // This is only possible for out-of-process command buffers. | 409 // This is only possible for out-of-process command buffers. |
| 398 return false; | 410 return false; |
| 399 } | 411 } |
| 400 | 412 |
| 401 gpu::CommandBufferNamespace CommandBufferClientImpl::GetNamespaceID() const { | 413 gpu::CommandBufferNamespace CommandBufferClientImpl::GetNamespaceID() const { |
| 402 return gpu::CommandBufferNamespace::MOJO; | 414 return gpu::CommandBufferNamespace::MOJO; |
| 403 } | 415 } |
| 404 | 416 |
| 405 uint64_t CommandBufferClientImpl::GetCommandBufferID() const { | 417 uint64_t CommandBufferClientImpl::GetCommandBufferID() const { |
| 406 // TODO (rjkroege): This must correspond to the command buffer ID on the | 418 return sync_client_impl_->GetCommandBufferID(); |
| 407 // server side. Most likely a combination of the client-specific integer and | |
| 408 // the connect id. | |
| 409 NOTIMPLEMENTED(); | |
| 410 return 0; | |
| 411 } | 419 } |
| 412 | 420 |
| 413 uint64_t CommandBufferClientImpl::GenerateFenceSyncRelease() { | 421 uint64_t CommandBufferClientImpl::GenerateFenceSyncRelease() { |
| 414 return next_fence_sync_release_++; | 422 return next_fence_sync_release_++; |
| 415 } | 423 } |
| 416 | 424 |
| 417 bool CommandBufferClientImpl::IsFenceSyncRelease(uint64_t release) { | 425 bool CommandBufferClientImpl::IsFenceSyncRelease(uint64_t release) { |
| 418 return release != 0 && release < next_fence_sync_release_; | 426 return release != 0 && release < next_fence_sync_release_; |
| 419 } | 427 } |
| 420 | 428 |
| 421 bool CommandBufferClientImpl::IsFenceSyncFlushed(uint64_t release) { | 429 bool CommandBufferClientImpl::IsFenceSyncFlushed(uint64_t release) { |
| 422 return release != 0 && release <= flushed_fence_sync_release_; | 430 return release != 0 && release <= flushed_fence_sync_release_; |
| 423 } | 431 } |
| 424 | 432 |
| 425 bool CommandBufferClientImpl::IsFenceSyncFlushReceived(uint64_t release) { | 433 bool CommandBufferClientImpl::IsFenceSyncFlushReceived(uint64_t release) { |
| 426 return IsFenceSyncFlushed(release); | 434 return IsFenceSyncFlushed(release); |
| 427 } | 435 } |
| 428 | 436 |
| 429 void CommandBufferClientImpl::SignalSyncToken(const gpu::SyncToken& sync_token, | 437 void CommandBufferClientImpl::SignalSyncToken(const gpu::SyncToken& sync_token, |
| 430 const base::Closure& callback) { | 438 const base::Closure& callback) { |
| 431 // TODO(dyen) | 439 // TODO(dyen) |
| 432 } | 440 } |
| 433 | 441 |
| 434 bool CommandBufferClientImpl::CanWaitUnverifiedSyncToken( | 442 bool CommandBufferClientImpl::CanWaitUnverifiedSyncToken( |
| 435 const gpu::SyncToken* sync_token) { | 443 const gpu::SyncToken* sync_token) { |
| 436 // All sync tokens must be flushed before being waited on. | 444 // Right now, MOJO_LOCAL is only used by trusted code, so it is safe to wait |
| 445 // on a sync token in MOJO_LOCAL command buffer. |
| 446 if (sync_token->namespace_id() == gpu::CommandBufferNamespace::MOJO_LOCAL) |
| 447 return true; |
| 448 |
| 449 // It is also safe to wait on the same context. |
| 450 if (sync_token->namespace_id() == gpu::CommandBufferNamespace::MOJO && |
| 451 sync_token->command_buffer_id() == GetCommandBufferID()) |
| 452 return true; |
| 453 |
| 437 return false; | 454 return false; |
| 438 } | 455 } |
| 439 | 456 |
| 440 } // namespace gles2 | 457 } // namespace gles2 |
| OLD | NEW |