| 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 |
| 76 InterfacePipe<CommandBufferSyncClient, NoInterface> sync_pipe; | 80 // TODO(darin): We need better sugar for sync calls. |
| 81 MessagePipe 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.handle0.Pass(), this)); |
| 84 CommandBufferSyncClientPtr sync_client = |
| 85 MakeProxy<CommandBufferSyncClient>(sync_pipe.handle1.Pass()); |
| 79 AllocationScope scope; | 86 AllocationScope scope; |
| 80 command_buffer_->Initialize(sync_pipe.handle_to_self.Pass(), duped.Pass()); | 87 command_buffer_->Initialize(sync_client.Pass(), duped.Pass()); |
| 81 // Wait for DidInitialize to come on the sync client pipe. | 88 // Wait for DidInitialize to come on the sync client pipe. |
| 82 if (!sync_dispatcher_->WaitAndDispatchOneMessage()) { | 89 if (!sync_dispatcher_->WaitAndDispatchOneMessage()) { |
| 83 VLOG(1) << "Channel encountered error while creating command buffer"; | 90 VLOG(1) << "Channel encountered error while creating command buffer"; |
| 84 return false; | 91 return false; |
| 85 } | 92 } |
| 86 return initialize_result_; | 93 return initialize_result_; |
| 87 } | 94 } |
| 88 | 95 |
| 89 gpu::CommandBuffer::State CommandBufferClientImpl::GetLastState() { | 96 gpu::CommandBuffer::State CommandBufferClientImpl::GetLastState() { |
| 90 return last_state_; | 97 return last_state_; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 LostContext(gpu::error::kUnknown); | 243 LostContext(gpu::error::kUnknown); |
| 237 } | 244 } |
| 238 | 245 |
| 239 void CommandBufferClientImpl::LostContext(int32_t lost_reason) { | 246 void CommandBufferClientImpl::LostContext(int32_t lost_reason) { |
| 240 last_state_.error = gpu::error::kLostContext; | 247 last_state_.error = gpu::error::kLostContext; |
| 241 last_state_.context_lost_reason = | 248 last_state_.context_lost_reason = |
| 242 static_cast<gpu::error::ContextLostReason>(lost_reason); | 249 static_cast<gpu::error::ContextLostReason>(lost_reason); |
| 243 delegate_->ContextLost(); | 250 delegate_->ContextLost(); |
| 244 } | 251 } |
| 245 | 252 |
| 246 void CommandBufferClientImpl::OnError() { LostContext(gpu::error::kUnknown); } | 253 void CommandBufferClientImpl::OnConnectionError() { |
| 254 LostContext(gpu::error::kUnknown); |
| 255 } |
| 247 | 256 |
| 248 void CommandBufferClientImpl::TryUpdateState() { | 257 void CommandBufferClientImpl::TryUpdateState() { |
| 249 if (last_state_.error == gpu::error::kNoError) | 258 if (last_state_.error == gpu::error::kNoError) |
| 250 shared_state()->Read(&last_state_); | 259 shared_state()->Read(&last_state_); |
| 251 } | 260 } |
| 252 | 261 |
| 253 void CommandBufferClientImpl::MakeProgressAndUpdateState() { | 262 void CommandBufferClientImpl::MakeProgressAndUpdateState() { |
| 254 command_buffer_->MakeProgress(last_state_.get_offset); | 263 command_buffer_->MakeProgress(last_state_.get_offset); |
| 255 if (!sync_dispatcher_->WaitAndDispatchOneMessage()) { | 264 if (!sync_dispatcher_->WaitAndDispatchOneMessage()) { |
| 256 VLOG(1) << "Channel encountered error while waiting for command buffer"; | 265 VLOG(1) << "Channel encountered error while waiting for command buffer"; |
| 257 // TODO(piman): is it ok for this to re-enter? | 266 // TODO(piman): is it ok for this to re-enter? |
| 258 DidDestroy(); | 267 DidDestroy(); |
| 259 return; | 268 return; |
| 260 } | 269 } |
| 261 } | 270 } |
| 262 | 271 |
| 263 void CommandBufferClientImpl::DrawAnimationFrame() { | 272 void CommandBufferClientImpl::DrawAnimationFrame() { |
| 264 delegate_->DrawAnimationFrame(); | 273 delegate_->DrawAnimationFrame(); |
| 265 } | 274 } |
| 266 | 275 |
| 267 } // namespace gles2 | 276 } // namespace gles2 |
| 268 } // namespace mojo | 277 } // namespace mojo |
| OLD | NEW |