| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 } | 43 } |
| 44 | 44 |
| 45 CommandBufferDelegate::~CommandBufferDelegate() {} | 45 CommandBufferDelegate::~CommandBufferDelegate() {} |
| 46 | 46 |
| 47 void CommandBufferDelegate::ContextLost() {} | 47 void CommandBufferDelegate::ContextLost() {} |
| 48 void CommandBufferDelegate::DrawAnimationFrame() {} | 48 void CommandBufferDelegate::DrawAnimationFrame() {} |
| 49 | 49 |
| 50 CommandBufferClientImpl::CommandBufferClientImpl( | 50 CommandBufferClientImpl::CommandBufferClientImpl( |
| 51 CommandBufferDelegate* delegate, | 51 CommandBufferDelegate* delegate, |
| 52 MojoAsyncWaiter* async_waiter, | 52 MojoAsyncWaiter* async_waiter, |
| 53 ScopedCommandBufferHandle command_buffer_handle) | 53 ScopedMessagePipeHandle command_buffer_handle) |
| 54 : delegate_(delegate), | 54 : delegate_(delegate), |
| 55 command_buffer_(command_buffer_handle.Pass(), this, this, async_waiter), | 55 command_buffer_(MakeProxy<mojo::CommandBuffer>( |
| 56 command_buffer_handle.Pass(), async_waiter)), |
| 56 shared_state_(NULL), | 57 shared_state_(NULL), |
| 57 last_put_offset_(-1), | 58 last_put_offset_(-1), |
| 58 next_transfer_buffer_id_(0), | 59 next_transfer_buffer_id_(0), |
| 59 initialize_result_(false) {} | 60 initialize_result_(false) { |
| 61 command_buffer_.set_error_handler(this); |
| 62 command_buffer_->SetClient(this); |
| 63 } |
| 60 | 64 |
| 61 CommandBufferClientImpl::~CommandBufferClientImpl() {} | 65 CommandBufferClientImpl::~CommandBufferClientImpl() {} |
| 62 | 66 |
| 63 bool CommandBufferClientImpl::Initialize() { | 67 bool CommandBufferClientImpl::Initialize() { |
| 64 const size_t kSharedStateSize = sizeof(gpu::CommandBufferSharedState); | 68 const size_t kSharedStateSize = sizeof(gpu::CommandBufferSharedState); |
| 65 void* memory = NULL; | 69 void* memory = NULL; |
| 66 mojo::ScopedSharedBufferHandle duped; | 70 mojo::ScopedSharedBufferHandle duped; |
| 67 bool result = CreateMapAndDupSharedBuffer( | 71 bool result = CreateMapAndDupSharedBuffer( |
| 68 kSharedStateSize, &memory, &shared_state_handle_, &duped); | 72 kSharedStateSize, &memory, &shared_state_handle_, &duped); |
| 69 if (!result) | 73 if (!result) |
| 70 return false; | 74 return false; |
| 71 | 75 |
| 72 shared_state_ = static_cast<gpu::CommandBufferSharedState*>(memory); | 76 shared_state_ = static_cast<gpu::CommandBufferSharedState*>(memory); |
| 73 | 77 |
| 74 shared_state()->Initialize(); | 78 shared_state()->Initialize(); |
| 75 | 79 |
| 80 #if 0 |
| 76 InterfacePipe<CommandBufferSyncClient, NoInterface> sync_pipe; | 81 InterfacePipe<CommandBufferSyncClient, NoInterface> sync_pipe; |
| 77 sync_dispatcher_.reset(new SyncDispatcher<CommandBufferSyncClient>( | 82 sync_dispatcher_.reset(new SyncDispatcher<CommandBufferSyncClient>( |
| 78 sync_pipe.handle_to_peer.Pass(), this)); | 83 sync_pipe.handle_to_peer.Pass(), this)); |
| 79 AllocationScope scope; | 84 AllocationScope scope; |
| 80 command_buffer_->Initialize(sync_pipe.handle_to_self.Pass(), duped.Pass()); | 85 command_buffer_->Initialize(sync_pipe.handle_to_self.Pass(), duped.Pass()); |
| 81 // Wait for DidInitialize to come on the sync client pipe. | 86 // Wait for DidInitialize to come on the sync client pipe. |
| 82 if (!sync_dispatcher_->WaitAndDispatchOneMessage()) { | 87 if (!sync_dispatcher_->WaitAndDispatchOneMessage()) { |
| 83 VLOG(1) << "Channel encountered error while creating command buffer"; | 88 VLOG(1) << "Channel encountered error while creating command buffer"; |
| 84 return false; | 89 return false; |
| 85 } | 90 } |
| 91 #endif |
| 86 return initialize_result_; | 92 return initialize_result_; |
| 87 } | 93 } |
| 88 | 94 |
| 89 gpu::CommandBuffer::State CommandBufferClientImpl::GetLastState() { | 95 gpu::CommandBuffer::State CommandBufferClientImpl::GetLastState() { |
| 90 return last_state_; | 96 return last_state_; |
| 91 } | 97 } |
| 92 | 98 |
| 93 int32 CommandBufferClientImpl::GetLastToken() { | 99 int32 CommandBufferClientImpl::GetLastToken() { |
| 94 TryUpdateState(); | 100 TryUpdateState(); |
| 95 return last_state_.token; | 101 return last_state_.token; |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 | 251 |
| 246 void CommandBufferClientImpl::OnError() { LostContext(gpu::error::kUnknown); } | 252 void CommandBufferClientImpl::OnError() { LostContext(gpu::error::kUnknown); } |
| 247 | 253 |
| 248 void CommandBufferClientImpl::TryUpdateState() { | 254 void CommandBufferClientImpl::TryUpdateState() { |
| 249 if (last_state_.error == gpu::error::kNoError) | 255 if (last_state_.error == gpu::error::kNoError) |
| 250 shared_state()->Read(&last_state_); | 256 shared_state()->Read(&last_state_); |
| 251 } | 257 } |
| 252 | 258 |
| 253 void CommandBufferClientImpl::MakeProgressAndUpdateState() { | 259 void CommandBufferClientImpl::MakeProgressAndUpdateState() { |
| 254 command_buffer_->MakeProgress(last_state_.get_offset); | 260 command_buffer_->MakeProgress(last_state_.get_offset); |
| 261 #if 0 |
| 255 if (!sync_dispatcher_->WaitAndDispatchOneMessage()) { | 262 if (!sync_dispatcher_->WaitAndDispatchOneMessage()) { |
| 256 VLOG(1) << "Channel encountered error while waiting for command buffer"; | 263 VLOG(1) << "Channel encountered error while waiting for command buffer"; |
| 257 // TODO(piman): is it ok for this to re-enter? | 264 // TODO(piman): is it ok for this to re-enter? |
| 258 DidDestroy(); | 265 DidDestroy(); |
| 259 return; | 266 return; |
| 260 } | 267 } |
| 268 #endif |
| 261 } | 269 } |
| 262 | 270 |
| 263 void CommandBufferClientImpl::DrawAnimationFrame() { | 271 void CommandBufferClientImpl::DrawAnimationFrame() { |
| 264 delegate_->DrawAnimationFrame(); | 272 delegate_->DrawAnimationFrame(); |
| 265 } | 273 } |
| 266 | 274 |
| 267 } // namespace gles2 | 275 } // namespace gles2 |
| 268 } // namespace mojo | 276 } // namespace mojo |
| OLD | NEW |