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 #include <utility> |
8 | 9 |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/process/process_handle.h" | 11 #include "base/process/process_handle.h" |
11 #include "base/threading/thread_restrictions.h" | 12 #include "base/threading/thread_restrictions.h" |
12 #include "components/mus/gles2/command_buffer_type_conversions.h" | 13 #include "components/mus/gles2/command_buffer_type_conversions.h" |
13 #include "components/mus/gles2/mojo_buffer_backing.h" | 14 #include "components/mus/gles2/mojo_buffer_backing.h" |
14 #include "components/mus/gles2/mojo_gpu_memory_buffer.h" | 15 #include "components/mus/gles2/mojo_gpu_memory_buffer.h" |
15 #include "gpu/command_buffer/common/sync_token.h" | 16 #include "gpu/command_buffer/common/sync_token.h" |
16 #include "gpu/command_buffer/service/image_factory.h" | 17 #include "gpu/command_buffer/service/image_factory.h" |
17 #include "mojo/platform_handle/platform_handle_functions.h" | 18 #include "mojo/platform_handle/platform_handle_functions.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 observer_binding_(this), | 65 observer_binding_(this), |
65 command_buffer_id_(0), | 66 command_buffer_id_(0), |
66 shared_state_(NULL), | 67 shared_state_(NULL), |
67 last_put_offset_(-1), | 68 last_put_offset_(-1), |
68 next_transfer_buffer_id_(0), | 69 next_transfer_buffer_id_(0), |
69 next_image_id_(0), | 70 next_image_id_(0), |
70 next_fence_sync_release_(1), | 71 next_fence_sync_release_(1), |
71 flushed_fence_sync_release_(0), | 72 flushed_fence_sync_release_(0), |
72 async_waiter_(async_waiter) { | 73 async_waiter_(async_waiter) { |
73 command_buffer_.Bind(mojo::InterfacePtrInfo<mus::mojom::CommandBuffer>( | 74 command_buffer_.Bind(mojo::InterfacePtrInfo<mus::mojom::CommandBuffer>( |
74 command_buffer_handle.Pass(), 0u), | 75 std::move(command_buffer_handle), 0u), |
75 async_waiter); | 76 async_waiter); |
76 command_buffer_.set_connection_error_handler( | 77 command_buffer_.set_connection_error_handler( |
77 [this]() { DidLoseContext(gpu::error::kUnknown); }); | 78 [this]() { DidLoseContext(gpu::error::kUnknown); }); |
78 } | 79 } |
79 | 80 |
80 CommandBufferClientImpl::~CommandBufferClientImpl() {} | 81 CommandBufferClientImpl::~CommandBufferClientImpl() {} |
81 | 82 |
82 bool CommandBufferClientImpl::Initialize() { | 83 bool CommandBufferClientImpl::Initialize() { |
83 const size_t kSharedStateSize = sizeof(gpu::CommandBufferSharedState); | 84 const size_t kSharedStateSize = sizeof(gpu::CommandBufferSharedState); |
84 void* memory = NULL; | 85 void* memory = NULL; |
85 mojo::ScopedSharedBufferHandle duped; | 86 mojo::ScopedSharedBufferHandle duped; |
86 bool result = CreateMapAndDupSharedBuffer( | 87 bool result = CreateMapAndDupSharedBuffer( |
87 kSharedStateSize, &memory, &shared_state_handle_, &duped); | 88 kSharedStateSize, &memory, &shared_state_handle_, &duped); |
88 if (!result) | 89 if (!result) |
89 return false; | 90 return false; |
90 | 91 |
91 shared_state_ = static_cast<gpu::CommandBufferSharedState*>(memory); | 92 shared_state_ = static_cast<gpu::CommandBufferSharedState*>(memory); |
92 | 93 |
93 shared_state()->Initialize(); | 94 shared_state()->Initialize(); |
94 | 95 |
95 mus::mojom::CommandBufferLostContextObserverPtr observer_ptr; | 96 mus::mojom::CommandBufferLostContextObserverPtr observer_ptr; |
96 observer_binding_.Bind(GetProxy(&observer_ptr), async_waiter_); | 97 observer_binding_.Bind(GetProxy(&observer_ptr), async_waiter_); |
97 mus::mojom::CommandBufferInfoPtr info; | 98 mus::mojom::CommandBufferInfoPtr info; |
98 command_buffer_->Initialize( | 99 command_buffer_->Initialize( |
99 observer_ptr.Pass(), duped.Pass(), mojo::Array<int32_t>::From(attribs_), | 100 std::move(observer_ptr), std::move(duped), |
| 101 mojo::Array<int32_t>::From(attribs_), |
100 base::Bind(&Copy<mus::mojom::CommandBufferInfoPtr>, &info)); | 102 base::Bind(&Copy<mus::mojom::CommandBufferInfoPtr>, &info)); |
101 | 103 |
102 base::ThreadRestrictions::ScopedAllowWait wait; | 104 base::ThreadRestrictions::ScopedAllowWait wait; |
103 if (!command_buffer_.WaitForIncomingResponse()) { | 105 if (!command_buffer_.WaitForIncomingResponse()) { |
104 VLOG(1) << "Channel encountered error while creating command buffer."; | 106 VLOG(1) << "Channel encountered error while creating command buffer."; |
105 return false; | 107 return false; |
106 } | 108 } |
107 | 109 |
108 if (!info) { | 110 if (!info) { |
109 VLOG(1) << "Command buffer cannot be initialized successfully."; | 111 VLOG(1) << "Command buffer cannot be initialized successfully."; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 mojo::ScopedSharedBufferHandle handle; | 174 mojo::ScopedSharedBufferHandle handle; |
173 mojo::ScopedSharedBufferHandle duped; | 175 mojo::ScopedSharedBufferHandle duped; |
174 if (!CreateMapAndDupSharedBuffer(size, &memory, &handle, &duped)) { | 176 if (!CreateMapAndDupSharedBuffer(size, &memory, &handle, &duped)) { |
175 if (last_state_.error == gpu::error::kNoError) | 177 if (last_state_.error == gpu::error::kNoError) |
176 last_state_.error = gpu::error::kLostContext; | 178 last_state_.error = gpu::error::kLostContext; |
177 return NULL; | 179 return NULL; |
178 } | 180 } |
179 | 181 |
180 *id = ++next_transfer_buffer_id_; | 182 *id = ++next_transfer_buffer_id_; |
181 | 183 |
182 command_buffer_->RegisterTransferBuffer( | 184 command_buffer_->RegisterTransferBuffer(*id, std::move(duped), |
183 *id, duped.Pass(), static_cast<uint32_t>(size)); | 185 static_cast<uint32_t>(size)); |
184 | 186 |
185 scoped_ptr<gpu::BufferBacking> backing( | 187 scoped_ptr<gpu::BufferBacking> backing( |
186 new mus::MojoBufferBacking(handle.Pass(), memory, size)); | 188 new mus::MojoBufferBacking(std::move(handle), memory, size)); |
187 scoped_refptr<gpu::Buffer> buffer(new gpu::Buffer(backing.Pass())); | 189 scoped_refptr<gpu::Buffer> buffer(new gpu::Buffer(std::move(backing))); |
188 return buffer; | 190 return buffer; |
189 } | 191 } |
190 | 192 |
191 void CommandBufferClientImpl::DestroyTransferBuffer(int32 id) { | 193 void CommandBufferClientImpl::DestroyTransferBuffer(int32 id) { |
192 command_buffer_->DestroyTransferBuffer(id); | 194 command_buffer_->DestroyTransferBuffer(id); |
193 } | 195 } |
194 | 196 |
195 gpu::Capabilities CommandBufferClientImpl::GetCapabilities() { | 197 gpu::Capabilities CommandBufferClientImpl::GetCapabilities() { |
196 return capabilities_; | 198 return capabilities_; |
197 } | 199 } |
(...skipping 30 matching lines...) Expand all Loading... |
228 MojoHandle mojo_handle = MOJO_HANDLE_INVALID; | 230 MojoHandle mojo_handle = MOJO_HANDLE_INVALID; |
229 MojoResult create_result = MojoCreatePlatformHandleWrapper( | 231 MojoResult create_result = MojoCreatePlatformHandleWrapper( |
230 platform_handle, &mojo_handle); | 232 platform_handle, &mojo_handle); |
231 if (create_result != MOJO_RESULT_OK) { | 233 if (create_result != MOJO_RESULT_OK) { |
232 NOTIMPLEMENTED(); | 234 NOTIMPLEMENTED(); |
233 return -1; | 235 return -1; |
234 } | 236 } |
235 mojo::ScopedHandle scoped_handle; | 237 mojo::ScopedHandle scoped_handle; |
236 scoped_handle.reset(mojo::Handle(mojo_handle)); | 238 scoped_handle.reset(mojo::Handle(mojo_handle)); |
237 command_buffer_->CreateImage( | 239 command_buffer_->CreateImage( |
238 new_id, scoped_handle.Pass(), handle.type, size.Pass(), | 240 new_id, std::move(scoped_handle), handle.type, std::move(size), |
239 static_cast<int32_t>(gpu_memory_buffer->GetFormat()), internalformat); | 241 static_cast<int32_t>(gpu_memory_buffer->GetFormat()), internalformat); |
240 if (requires_sync_point) { | 242 if (requires_sync_point) { |
241 NOTIMPLEMENTED(); | 243 NOTIMPLEMENTED(); |
242 // TODO(jam): need to support this if we support types other than | 244 // TODO(jam): need to support this if we support types other than |
243 // SHARED_MEMORY_BUFFER. | 245 // SHARED_MEMORY_BUFFER. |
244 //gpu_memory_buffer_manager->SetDestructionSyncPoint(gpu_memory_buffer, | 246 //gpu_memory_buffer_manager->SetDestructionSyncPoint(gpu_memory_buffer, |
245 // InsertSyncPoint()); | 247 // InsertSyncPoint()); |
246 } | 248 } |
247 | 249 |
248 return new_id; | 250 return new_id; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 | 388 |
387 // It is also safe to wait on the same context. | 389 // It is also safe to wait on the same context. |
388 if (sync_token->namespace_id() == gpu::CommandBufferNamespace::MOJO && | 390 if (sync_token->namespace_id() == gpu::CommandBufferNamespace::MOJO && |
389 sync_token->command_buffer_id() == GetCommandBufferID()) | 391 sync_token->command_buffer_id() == GetCommandBufferID()) |
390 return true; | 392 return true; |
391 | 393 |
392 return false; | 394 return false; |
393 } | 395 } |
394 | 396 |
395 } // namespace gles2 | 397 } // namespace gles2 |
OLD | NEW |