| 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 "components/mus/public/cpp/lib/command_buffer_client_impl.h" | 5 #include "components/mus/public/cpp/lib/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> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/process/process_handle.h" | 14 #include "base/process/process_handle.h" |
| 15 #include "base/threading/thread_restrictions.h" | |
| 16 #include "components/mus/common/gpu_type_converters.h" | 15 #include "components/mus/common/gpu_type_converters.h" |
| 17 #include "components/mus/common/mojo_buffer_backing.h" | 16 #include "components/mus/common/mojo_buffer_backing.h" |
| 18 #include "components/mus/common/mojo_gpu_memory_buffer.h" | 17 #include "components/mus/common/mojo_gpu_memory_buffer.h" |
| 19 #include "gpu/command_buffer/client/gpu_control_client.h" | 18 #include "gpu/command_buffer/client/gpu_control_client.h" |
| 20 #include "gpu/command_buffer/common/command_buffer_id.h" | 19 #include "gpu/command_buffer/common/command_buffer_id.h" |
| 21 #include "gpu/command_buffer/common/gpu_memory_buffer_support.h" | 20 #include "gpu/command_buffer/common/gpu_memory_buffer_support.h" |
| 22 #include "gpu/command_buffer/common/sync_token.h" | 21 #include "gpu/command_buffer/common/sync_token.h" |
| 23 #include "mojo/public/cpp/system/platform_handle.h" | 22 #include "mojo/public/cpp/system/platform_handle.h" |
| 24 | 23 |
| 25 namespace mus { | 24 namespace mus { |
| 26 | 25 |
| 27 namespace { | 26 namespace { |
| 28 | 27 |
| 29 bool CreateAndMapSharedBuffer(size_t size, | 28 bool CreateAndMapSharedBuffer(size_t size, |
| 30 mojo::ScopedSharedBufferMapping* mapping, | 29 mojo::ScopedSharedBufferMapping* mapping, |
| 31 mojo::ScopedSharedBufferHandle* handle) { | 30 mojo::ScopedSharedBufferHandle* handle) { |
| 32 *handle = mojo::SharedBufferHandle::Create(size); | 31 *handle = mojo::SharedBufferHandle::Create(size); |
| 33 if (!handle->is_valid()) | 32 if (!handle->is_valid()) |
| 34 return false; | 33 return false; |
| 35 | 34 |
| 36 *mapping = (*handle)->Map(size); | 35 *mapping = (*handle)->Map(size); |
| 37 if (!*mapping) | 36 if (!*mapping) |
| 38 return false; | 37 return false; |
| 39 | 38 |
| 40 return true; | 39 return true; |
| 41 } | 40 } |
| 42 | 41 |
| 43 void MakeProgressCallback(gpu::CommandBuffer::State* output, | |
| 44 const gpu::CommandBuffer::State& input) { | |
| 45 *output = input; | |
| 46 } | |
| 47 | |
| 48 void InitializeCallback(mus::mojom::CommandBufferInitializeResultPtr* output, | |
| 49 mus::mojom::CommandBufferInitializeResultPtr input) { | |
| 50 *output = std::move(input); | |
| 51 } | |
| 52 | |
| 53 } // namespace | 42 } // namespace |
| 54 | 43 |
| 55 CommandBufferClientImpl::CommandBufferClientImpl( | 44 CommandBufferClientImpl::CommandBufferClientImpl( |
| 56 const std::vector<int32_t>& attribs, | 45 const std::vector<int32_t>& attribs, |
| 57 mus::mojom::CommandBufferPtr command_buffer_ptr) | 46 mus::mojom::CommandBufferPtr command_buffer_ptr) |
| 58 : gpu_control_client_(nullptr), | 47 : gpu_control_client_(nullptr), |
| 59 destroyed_(false), | 48 destroyed_(false), |
| 60 attribs_(attribs), | 49 attribs_(attribs), |
| 61 client_binding_(this), | 50 client_binding_(this), |
| 62 command_buffer_(std::move(command_buffer_ptr)), | 51 command_buffer_(std::move(command_buffer_ptr)), |
| (...skipping 17 matching lines...) Expand all Loading... |
| 80 CreateAndMapSharedBuffer(kSharedStateSize, &shared_state_, &handle); | 69 CreateAndMapSharedBuffer(kSharedStateSize, &shared_state_, &handle); |
| 81 if (!result) | 70 if (!result) |
| 82 return false; | 71 return false; |
| 83 | 72 |
| 84 shared_state()->Initialize(); | 73 shared_state()->Initialize(); |
| 85 | 74 |
| 86 mus::mojom::CommandBufferClientPtr client_ptr; | 75 mus::mojom::CommandBufferClientPtr client_ptr; |
| 87 client_binding_.Bind(GetProxy(&client_ptr)); | 76 client_binding_.Bind(GetProxy(&client_ptr)); |
| 88 | 77 |
| 89 mus::mojom::CommandBufferInitializeResultPtr initialize_result; | 78 mus::mojom::CommandBufferInitializeResultPtr initialize_result; |
| 90 command_buffer_->Initialize( | 79 bool handled = command_buffer_->Initialize( |
| 91 std::move(client_ptr), std::move(handle), | 80 std::move(client_ptr), std::move(handle), |
| 92 mojo::Array<int32_t>::From(attribs_), | 81 mojo::Array<int32_t>::From(attribs_), &initialize_result); |
| 93 base::Bind(&InitializeCallback, &initialize_result)); | |
| 94 | 82 |
| 95 base::ThreadRestrictions::ScopedAllowWait wait; | 83 if (!handled) { |
| 96 if (!command_buffer_.WaitForIncomingResponse()) { | |
| 97 VLOG(1) << "Channel encountered error while creating command buffer."; | 84 VLOG(1) << "Channel encountered error while creating command buffer."; |
| 98 return false; | 85 return false; |
| 99 } | 86 } |
| 100 | 87 |
| 101 if (!initialize_result) { | 88 if (!initialize_result) { |
| 102 VLOG(1) << "Command buffer cannot be initialized successfully."; | 89 VLOG(1) << "Command buffer cannot be initialized successfully."; |
| 103 return false; | 90 return false; |
| 104 } | 91 } |
| 105 | 92 |
| 106 DCHECK_EQ(gpu::CommandBufferNamespace::MOJO, | 93 DCHECK_EQ(gpu::CommandBufferNamespace::MOJO, |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 void CommandBufferClientImpl::UpdateVSyncParameters(int64_t timebase, | 277 void CommandBufferClientImpl::UpdateVSyncParameters(int64_t timebase, |
| 291 int64_t interval) {} | 278 int64_t interval) {} |
| 292 | 279 |
| 293 void CommandBufferClientImpl::TryUpdateState() { | 280 void CommandBufferClientImpl::TryUpdateState() { |
| 294 if (last_state_.error == gpu::error::kNoError) | 281 if (last_state_.error == gpu::error::kNoError) |
| 295 shared_state()->Read(&last_state_); | 282 shared_state()->Read(&last_state_); |
| 296 } | 283 } |
| 297 | 284 |
| 298 void CommandBufferClientImpl::MakeProgressAndUpdateState() { | 285 void CommandBufferClientImpl::MakeProgressAndUpdateState() { |
| 299 gpu::CommandBuffer::State state; | 286 gpu::CommandBuffer::State state; |
| 300 command_buffer_->MakeProgress(last_state_.get_offset, | 287 bool handled = command_buffer_->MakeProgress(last_state_.get_offset, &state); |
| 301 base::Bind(&MakeProgressCallback, &state)); | |
| 302 | 288 |
| 303 base::ThreadRestrictions::ScopedAllowWait wait; | 289 if (!handled) { |
| 304 if (!command_buffer_.WaitForIncomingResponse()) { | |
| 305 VLOG(1) << "Channel encountered error while waiting for command buffer."; | 290 VLOG(1) << "Channel encountered error while waiting for command buffer."; |
| 306 // TODO(piman): is it ok for this to re-enter? | 291 // TODO(piman): is it ok for this to re-enter? |
| 307 Destroyed(gpu::error::kUnknown, gpu::error::kLostContext); | 292 Destroyed(gpu::error::kUnknown, gpu::error::kLostContext); |
| 308 return; | 293 return; |
| 309 } | 294 } |
| 310 | 295 |
| 311 if (state.generation - last_state_.generation < 0x80000000U) | 296 if (state.generation - last_state_.generation < 0x80000000U) |
| 312 last_state_ = state; | 297 last_state_ = state; |
| 313 } | 298 } |
| 314 | 299 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 | 346 |
| 362 // It is also safe to wait on the same context. | 347 // It is also safe to wait on the same context. |
| 363 if (sync_token->namespace_id() == gpu::CommandBufferNamespace::MOJO && | 348 if (sync_token->namespace_id() == gpu::CommandBufferNamespace::MOJO && |
| 364 sync_token->command_buffer_id() == GetCommandBufferID()) | 349 sync_token->command_buffer_id() == GetCommandBufferID()) |
| 365 return true; | 350 return true; |
| 366 | 351 |
| 367 return false; | 352 return false; |
| 368 } | 353 } |
| 369 | 354 |
| 370 } // namespace mus | 355 } // namespace mus |
| OLD | NEW |