| 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" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 return true; | 39 return true; |
| 40 } | 40 } |
| 41 | 41 |
| 42 } // namespace | 42 } // namespace |
| 43 | 43 |
| 44 CommandBufferDelegate::~CommandBufferDelegate() {} | 44 CommandBufferDelegate::~CommandBufferDelegate() {} |
| 45 | 45 |
| 46 void CommandBufferDelegate::ContextLost() {} | 46 void CommandBufferDelegate::ContextLost() {} |
| 47 | 47 |
| 48 class CommandBufferClientImpl::SyncClientImpl | 48 class CommandBufferClientImpl::SyncClientImpl : public CommandBufferSyncClient { |
| 49 : public InterfaceImpl<CommandBufferSyncClient> { | |
| 50 public: | 49 public: |
| 51 SyncClientImpl() : initialized_successfully_(false) {} | 50 SyncClientImpl(CommandBufferSyncClientPtr* ptr, |
| 51 const MojoAsyncWaiter* async_waiter) |
| 52 : initialized_successfully_(false), binding_(this, ptr, async_waiter) {} |
| 52 | 53 |
| 53 bool WaitForInitialization() { | 54 bool WaitForInitialization() { |
| 54 if (!WaitForIncomingMethodCall()) | 55 if (!binding_.WaitForIncomingMethodCall()) |
| 55 return false; | 56 return false; |
| 56 return initialized_successfully_; | 57 return initialized_successfully_; |
| 57 } | 58 } |
| 58 | 59 |
| 59 CommandBufferStatePtr WaitForProgress() { | 60 CommandBufferStatePtr WaitForProgress() { |
| 60 if (!WaitForIncomingMethodCall()) | 61 if (!binding_.WaitForIncomingMethodCall()) |
| 61 return CommandBufferStatePtr(); | 62 return CommandBufferStatePtr(); |
| 62 return command_buffer_state_.Pass(); | 63 return command_buffer_state_.Pass(); |
| 63 } | 64 } |
| 64 | 65 |
| 65 gpu::Capabilities GetCapabilities() { | 66 gpu::Capabilities GetCapabilities() { |
| 66 return capabilities_.To<gpu::Capabilities>(); | 67 return capabilities_.To<gpu::Capabilities>(); |
| 67 } | 68 } |
| 68 | 69 |
| 69 private: | 70 private: |
| 70 // CommandBufferSyncClient methods: | 71 // CommandBufferSyncClient methods: |
| 71 void DidInitialize(bool success, GpuCapabilitiesPtr capabilities) override { | 72 void DidInitialize(bool success, GpuCapabilitiesPtr capabilities) override { |
| 72 initialized_successfully_ = success; | 73 initialized_successfully_ = success; |
| 73 capabilities_ = capabilities.Pass(); | 74 capabilities_ = capabilities.Pass(); |
| 74 } | 75 } |
| 75 void DidMakeProgress(CommandBufferStatePtr state) override { | 76 void DidMakeProgress(CommandBufferStatePtr state) override { |
| 76 command_buffer_state_ = state.Pass(); | 77 command_buffer_state_ = state.Pass(); |
| 77 } | 78 } |
| 78 | 79 |
| 79 bool initialized_successfully_; | 80 bool initialized_successfully_; |
| 80 GpuCapabilitiesPtr capabilities_; | 81 GpuCapabilitiesPtr capabilities_; |
| 81 CommandBufferStatePtr command_buffer_state_; | 82 CommandBufferStatePtr command_buffer_state_; |
| 83 Binding<CommandBufferSyncClient> binding_; |
| 84 |
| 85 DISALLOW_COPY_AND_ASSIGN(SyncClientImpl); |
| 82 }; | 86 }; |
| 83 | 87 |
| 84 CommandBufferClientImpl::CommandBufferClientImpl( | 88 CommandBufferClientImpl::CommandBufferClientImpl( |
| 85 CommandBufferDelegate* delegate, | 89 CommandBufferDelegate* delegate, |
| 86 const MojoAsyncWaiter* async_waiter, | 90 const MojoAsyncWaiter* async_waiter, |
| 87 ScopedMessagePipeHandle command_buffer_handle) | 91 ScopedMessagePipeHandle command_buffer_handle) |
| 88 : delegate_(delegate), | 92 : delegate_(delegate), |
| 89 shared_state_(NULL), | 93 shared_state_(NULL), |
| 90 last_put_offset_(-1), | 94 last_put_offset_(-1), |
| 91 next_transfer_buffer_id_(0), | 95 next_transfer_buffer_id_(0), |
| (...skipping 12 matching lines...) Expand all Loading... |
| 104 bool result = CreateMapAndDupSharedBuffer( | 108 bool result = CreateMapAndDupSharedBuffer( |
| 105 kSharedStateSize, &memory, &shared_state_handle_, &duped); | 109 kSharedStateSize, &memory, &shared_state_handle_, &duped); |
| 106 if (!result) | 110 if (!result) |
| 107 return false; | 111 return false; |
| 108 | 112 |
| 109 shared_state_ = static_cast<gpu::CommandBufferSharedState*>(memory); | 113 shared_state_ = static_cast<gpu::CommandBufferSharedState*>(memory); |
| 110 | 114 |
| 111 shared_state()->Initialize(); | 115 shared_state()->Initialize(); |
| 112 | 116 |
| 113 CommandBufferSyncClientPtr sync_client; | 117 CommandBufferSyncClientPtr sync_client; |
| 114 sync_client_impl_.reset( | 118 sync_client_impl_.reset(new SyncClientImpl(&sync_client, async_waiter_)); |
| 115 WeakBindToProxy(new SyncClientImpl(), &sync_client, async_waiter_)); | |
| 116 | 119 |
| 117 command_buffer_->Initialize(sync_client.Pass(), duped.Pass()); | 120 command_buffer_->Initialize(sync_client.Pass(), duped.Pass()); |
| 118 | 121 |
| 119 // Wait for DidInitialize to come on the sync client pipe. | 122 // Wait for DidInitialize to come on the sync client pipe. |
| 120 if (!sync_client_impl_->WaitForInitialization()) { | 123 if (!sync_client_impl_->WaitForInitialization()) { |
| 121 VLOG(1) << "Channel encountered error while creating command buffer"; | 124 VLOG(1) << "Channel encountered error while creating command buffer"; |
| 122 return false; | 125 return false; |
| 123 } | 126 } |
| 124 capabilities_ = sync_client_impl_->GetCapabilities(); | 127 capabilities_ = sync_client_impl_->GetCapabilities(); |
| 125 return true; | 128 return true; |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 DidDestroy(); | 292 DidDestroy(); |
| 290 return; | 293 return; |
| 291 } | 294 } |
| 292 | 295 |
| 293 if (state->generation - last_state_.generation < 0x80000000U) | 296 if (state->generation - last_state_.generation < 0x80000000U) |
| 294 last_state_ = state.To<State>(); | 297 last_state_ = state.To<State>(); |
| 295 } | 298 } |
| 296 | 299 |
| 297 } // namespace gles2 | 300 } // namespace gles2 |
| 298 } // namespace mojo | 301 } // namespace mojo |
| OLD | NEW |