| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 64 |
| 65 void CommandBufferDelegate::ContextLost() {} | 65 void CommandBufferDelegate::ContextLost() {} |
| 66 | 66 |
| 67 CommandBufferClientImpl::CommandBufferClientImpl( | 67 CommandBufferClientImpl::CommandBufferClientImpl( |
| 68 CommandBufferDelegate* delegate, | 68 CommandBufferDelegate* delegate, |
| 69 const std::vector<int32_t>& attribs, | 69 const std::vector<int32_t>& attribs, |
| 70 const MojoAsyncWaiter* async_waiter, | 70 const MojoAsyncWaiter* async_waiter, |
| 71 mojo::ScopedMessagePipeHandle command_buffer_handle) | 71 mojo::ScopedMessagePipeHandle command_buffer_handle) |
| 72 : delegate_(delegate), | 72 : delegate_(delegate), |
| 73 attribs_(attribs), | 73 attribs_(attribs), |
| 74 observer_binding_(this), | 74 client_binding_(this), |
| 75 command_buffer_id_(0), | 75 command_buffer_id_(0), |
| 76 shared_state_(NULL), | 76 shared_state_(NULL), |
| 77 last_put_offset_(-1), | 77 last_put_offset_(-1), |
| 78 next_transfer_buffer_id_(0), | 78 next_transfer_buffer_id_(0), |
| 79 next_image_id_(0), | 79 next_image_id_(0), |
| 80 next_fence_sync_release_(1), | 80 next_fence_sync_release_(1), |
| 81 flushed_fence_sync_release_(0), | 81 flushed_fence_sync_release_(0), |
| 82 async_waiter_(async_waiter) { | 82 async_waiter_(async_waiter) { |
| 83 command_buffer_.Bind(mojo::InterfacePtrInfo<mus::mojom::CommandBuffer>( | 83 command_buffer_.Bind(mojo::InterfacePtrInfo<mus::mojom::CommandBuffer>( |
| 84 std::move(command_buffer_handle), 0u), | 84 std::move(command_buffer_handle), 0u), |
| 85 async_waiter); | 85 async_waiter); |
| 86 command_buffer_.set_connection_error_handler( | 86 command_buffer_.set_connection_error_handler( |
| 87 [this]() { DidLoseContext(gpu::error::kUnknown); }); | 87 [this]() { Destroyed(gpu::error::kUnknown, gpu::error::kLostContext); }); |
| 88 } | 88 } |
| 89 | 89 |
| 90 CommandBufferClientImpl::~CommandBufferClientImpl() {} | 90 CommandBufferClientImpl::~CommandBufferClientImpl() {} |
| 91 | 91 |
| 92 bool CommandBufferClientImpl::Initialize() { | 92 bool CommandBufferClientImpl::Initialize() { |
| 93 const size_t kSharedStateSize = sizeof(gpu::CommandBufferSharedState); | 93 const size_t kSharedStateSize = sizeof(gpu::CommandBufferSharedState); |
| 94 void* memory = NULL; | 94 void* memory = NULL; |
| 95 mojo::ScopedSharedBufferHandle duped; | 95 mojo::ScopedSharedBufferHandle duped; |
| 96 bool result = CreateMapAndDupSharedBuffer( | 96 bool result = CreateMapAndDupSharedBuffer( |
| 97 kSharedStateSize, &memory, &shared_state_handle_, &duped); | 97 kSharedStateSize, &memory, &shared_state_handle_, &duped); |
| 98 if (!result) | 98 if (!result) |
| 99 return false; | 99 return false; |
| 100 | 100 |
| 101 shared_state_ = static_cast<gpu::CommandBufferSharedState*>(memory); | 101 shared_state_ = static_cast<gpu::CommandBufferSharedState*>(memory); |
| 102 | 102 |
| 103 shared_state()->Initialize(); | 103 shared_state()->Initialize(); |
| 104 | 104 |
| 105 mus::mojom::CommandBufferLostContextObserverPtr observer_ptr; | 105 mus::mojom::CommandBufferClientPtr client_ptr; |
| 106 observer_binding_.Bind(GetProxy(&observer_ptr), async_waiter_); | 106 client_binding_.Bind(GetProxy(&client_ptr), async_waiter_); |
| 107 | 107 |
| 108 mus::mojom::CommandBufferInitializeResultPtr initialize_result; | 108 mus::mojom::CommandBufferInitializeResultPtr initialize_result; |
| 109 command_buffer_->Initialize( | 109 command_buffer_->Initialize( |
| 110 std::move(observer_ptr), std::move(duped), | 110 std::move(client_ptr), std::move(duped), |
| 111 mojo::Array<int32_t>::From(attribs_), | 111 mojo::Array<int32_t>::From(attribs_), |
| 112 base::Bind(&InitializeCallback, &initialize_result)); | 112 base::Bind(&InitializeCallback, &initialize_result)); |
| 113 | 113 |
| 114 base::ThreadRestrictions::ScopedAllowWait wait; | 114 base::ThreadRestrictions::ScopedAllowWait wait; |
| 115 if (!command_buffer_.WaitForIncomingResponse()) { | 115 if (!command_buffer_.WaitForIncomingResponse()) { |
| 116 VLOG(1) << "Channel encountered error while creating command buffer."; | 116 VLOG(1) << "Channel encountered error while creating command buffer."; |
| 117 return false; | 117 return false; |
| 118 } | 118 } |
| 119 | 119 |
| 120 if (!initialize_result) { | 120 if (!initialize_result) { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 | 278 |
| 279 return CreateImage(buffer->AsClientBuffer(), width, height, internalformat); | 279 return CreateImage(buffer->AsClientBuffer(), width, height, internalformat); |
| 280 } | 280 } |
| 281 | 281 |
| 282 void CommandBufferClientImpl::SignalQuery(uint32_t query, | 282 void CommandBufferClientImpl::SignalQuery(uint32_t query, |
| 283 const base::Closure& callback) { | 283 const base::Closure& callback) { |
| 284 // TODO(piman) | 284 // TODO(piman) |
| 285 NOTIMPLEMENTED(); | 285 NOTIMPLEMENTED(); |
| 286 } | 286 } |
| 287 | 287 |
| 288 void CommandBufferClientImpl::DidLoseContext(int32_t lost_reason) { | 288 void CommandBufferClientImpl::Destroyed(int32_t lost_reason, int32_t error) { |
| 289 last_state_.error = gpu::error::kLostContext; | |
| 290 last_state_.context_lost_reason = | 289 last_state_.context_lost_reason = |
| 291 static_cast<gpu::error::ContextLostReason>(lost_reason); | 290 static_cast<gpu::error::ContextLostReason>(lost_reason); |
| 291 last_state_.error = static_cast<gpu::error::Error>(error); |
| 292 delegate_->ContextLost(); | 292 delegate_->ContextLost(); |
| 293 } | 293 } |
| 294 | 294 |
| 295 void CommandBufferClientImpl::SignalAck(uint32_t id) { |
| 296 } |
| 297 |
| 298 void CommandBufferClientImpl::SwapBuffersCompleted(int32_t result) { |
| 299 } |
| 300 |
| 301 void CommandBufferClientImpl::UpdateState( |
| 302 const gpu::CommandBuffer::State& state) { |
| 303 } |
| 304 |
| 305 void CommandBufferClientImpl::UpdateVSyncParameters(int64_t timebase, |
| 306 int64_t interval) { |
| 307 } |
| 308 |
| 295 void CommandBufferClientImpl::TryUpdateState() { | 309 void CommandBufferClientImpl::TryUpdateState() { |
| 296 if (last_state_.error == gpu::error::kNoError) | 310 if (last_state_.error == gpu::error::kNoError) |
| 297 shared_state()->Read(&last_state_); | 311 shared_state()->Read(&last_state_); |
| 298 } | 312 } |
| 299 | 313 |
| 300 void CommandBufferClientImpl::MakeProgressAndUpdateState() { | 314 void CommandBufferClientImpl::MakeProgressAndUpdateState() { |
| 301 gpu::CommandBuffer::State state; | 315 gpu::CommandBuffer::State state; |
| 302 command_buffer_->MakeProgress( | 316 command_buffer_->MakeProgress( |
| 303 last_state_.get_offset, | 317 last_state_.get_offset, |
| 304 base::Bind(&MakeProgressCallback, &state)); | 318 base::Bind(&MakeProgressCallback, &state)); |
| 305 | 319 |
| 306 base::ThreadRestrictions::ScopedAllowWait wait; | 320 base::ThreadRestrictions::ScopedAllowWait wait; |
| 307 if (!command_buffer_.WaitForIncomingResponse()) { | 321 if (!command_buffer_.WaitForIncomingResponse()) { |
| 308 VLOG(1) << "Channel encountered error while waiting for command buffer."; | 322 VLOG(1) << "Channel encountered error while waiting for command buffer."; |
| 309 // TODO(piman): is it ok for this to re-enter? | 323 // TODO(piman): is it ok for this to re-enter? |
| 310 DidLoseContext(gpu::error::kUnknown); | 324 Destroyed(gpu::error::kUnknown, gpu::error::kLostContext); |
| 311 return; | 325 return; |
| 312 } | 326 } |
| 313 | 327 |
| 314 if (state.generation - last_state_.generation < 0x80000000U) | 328 if (state.generation - last_state_.generation < 0x80000000U) |
| 315 last_state_ = state; | 329 last_state_ = state; |
| 316 } | 330 } |
| 317 | 331 |
| 318 void CommandBufferClientImpl::SetLock(base::Lock* lock) { | 332 void CommandBufferClientImpl::SetLock(base::Lock* lock) { |
| 319 } | 333 } |
| 320 | 334 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 | 384 |
| 371 // It is also safe to wait on the same context. | 385 // It is also safe to wait on the same context. |
| 372 if (sync_token->namespace_id() == gpu::CommandBufferNamespace::MOJO && | 386 if (sync_token->namespace_id() == gpu::CommandBufferNamespace::MOJO && |
| 373 sync_token->command_buffer_id() == GetCommandBufferID()) | 387 sync_token->command_buffer_id() == GetCommandBufferID()) |
| 374 return true; | 388 return true; |
| 375 | 389 |
| 376 return false; | 390 return false; |
| 377 } | 391 } |
| 378 | 392 |
| 379 } // namespace gles2 | 393 } // namespace gles2 |
| OLD | NEW |