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" |
11 #include "base/threading/thread_restrictions.h" | 11 #include "base/threading/thread_restrictions.h" |
12 #include "components/mus/gles2/command_buffer_type_conversions.h" | 12 #include "components/mus/gles2/command_buffer_type_conversions.h" |
13 #include "components/mus/gles2/mojo_buffer_backing.h" | 13 #include "components/mus/gles2/mojo_buffer_backing.h" |
14 #include "components/mus/gles2/mojo_gpu_memory_buffer.h" | 14 #include "components/mus/gles2/mojo_gpu_memory_buffer.h" |
15 #include "gpu/command_buffer/common/sync_token.h" | |
15 #include "gpu/command_buffer/service/image_factory.h" | 16 #include "gpu/command_buffer/service/image_factory.h" |
16 #include "mojo/platform_handle/platform_handle_functions.h" | 17 #include "mojo/platform_handle/platform_handle_functions.h" |
17 | 18 |
18 namespace gles2 { | 19 namespace gles2 { |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 bool CreateMapAndDupSharedBuffer(size_t size, | 23 bool CreateMapAndDupSharedBuffer(size_t size, |
23 void** memory, | 24 void** memory, |
24 mojo::ScopedSharedBufferHandle* handle, | 25 mojo::ScopedSharedBufferHandle* handle, |
(...skipping 21 matching lines...) Expand all Loading... | |
46 | 47 |
47 CommandBufferDelegate::~CommandBufferDelegate() {} | 48 CommandBufferDelegate::~CommandBufferDelegate() {} |
48 | 49 |
49 void CommandBufferDelegate::ContextLost() {} | 50 void CommandBufferDelegate::ContextLost() {} |
50 | 51 |
51 class CommandBufferClientImpl::SyncClientImpl | 52 class CommandBufferClientImpl::SyncClientImpl |
52 : public mus::mojom::CommandBufferSyncClient { | 53 : public mus::mojom::CommandBufferSyncClient { |
53 public: | 54 public: |
54 SyncClientImpl(mus::mojom::CommandBufferSyncClientPtr* ptr, | 55 SyncClientImpl(mus::mojom::CommandBufferSyncClientPtr* ptr, |
55 const MojoAsyncWaiter* async_waiter) | 56 const MojoAsyncWaiter* async_waiter) |
56 : initialized_successfully_(false), binding_(this, ptr, async_waiter) {} | 57 : initialized_successfully_(false), |
58 command_buffer_id_(0), | |
59 binding_(this, ptr, async_waiter) {} | |
57 | 60 |
58 bool WaitForInitialization() { | 61 bool WaitForInitialization() { |
62 base::ThreadRestrictions::ScopedAllowWait wait; | |
59 if (!binding_.WaitForIncomingMethodCall()) | 63 if (!binding_.WaitForIncomingMethodCall()) |
60 return false; | 64 return false; |
61 return initialized_successfully_; | 65 return initialized_successfully_; |
62 } | 66 } |
63 | 67 |
64 mus::mojom::CommandBufferStatePtr WaitForProgress() { | 68 mus::mojom::CommandBufferStatePtr WaitForProgress() { |
69 base::ThreadRestrictions::ScopedAllowWait wait; | |
65 if (!binding_.WaitForIncomingMethodCall()) | 70 if (!binding_.WaitForIncomingMethodCall()) |
66 return mus::mojom::CommandBufferStatePtr(); | 71 return mus::mojom::CommandBufferStatePtr(); |
67 return command_buffer_state_.Pass(); | 72 return command_buffer_state_.Pass(); |
68 } | 73 } |
69 | 74 |
70 gpu::Capabilities GetCapabilities() { | 75 gpu::Capabilities GetCapabilities() { |
71 if (capabilities_) | 76 if (capabilities_) |
72 return capabilities_.To<gpu::Capabilities>(); | 77 return capabilities_.To<gpu::Capabilities>(); |
73 return gpu::Capabilities(); | 78 return gpu::Capabilities(); |
74 } | 79 } |
75 | 80 |
81 uint64_t GetCommandBufferID() const { | |
82 return command_buffer_id_; | |
83 } | |
84 | |
76 private: | 85 private: |
77 // CommandBufferSyncClient methods: | 86 // CommandBufferSyncClient methods: |
78 void DidInitialize(bool success, | 87 void DidInitialize(bool success, |
88 int32_t command_buffer_namespace, | |
89 uint64_t command_buffer_id, | |
79 mus::mojom::GpuCapabilitiesPtr capabilities) override { | 90 mus::mojom::GpuCapabilitiesPtr capabilities) override { |
91 CHECK_EQ(command_buffer_namespace, gpu::CommandBufferNamespace::MOJO); | |
piman
2015/11/24 21:49:45
nit: DCHECK_EQ
Peng
2015/11/24 22:52:09
Done.
| |
80 initialized_successfully_ = success; | 92 initialized_successfully_ = success; |
93 command_buffer_id_ = command_buffer_id; | |
81 capabilities_ = capabilities.Pass(); | 94 capabilities_ = capabilities.Pass(); |
82 } | 95 } |
83 void DidMakeProgress(mus::mojom::CommandBufferStatePtr state) override { | 96 void DidMakeProgress(mus::mojom::CommandBufferStatePtr state) override { |
84 command_buffer_state_ = state.Pass(); | 97 command_buffer_state_ = state.Pass(); |
85 } | 98 } |
86 | 99 |
87 bool initialized_successfully_; | 100 bool initialized_successfully_; |
101 uint64_t command_buffer_id_; | |
88 mus::mojom::GpuCapabilitiesPtr capabilities_; | 102 mus::mojom::GpuCapabilitiesPtr capabilities_; |
89 mus::mojom::CommandBufferStatePtr command_buffer_state_; | 103 mus::mojom::CommandBufferStatePtr command_buffer_state_; |
90 mojo::Binding<mus::mojom::CommandBufferSyncClient> binding_; | 104 mojo::Binding<mus::mojom::CommandBufferSyncClient> binding_; |
91 | 105 |
92 DISALLOW_COPY_AND_ASSIGN(SyncClientImpl); | 106 DISALLOW_COPY_AND_ASSIGN(SyncClientImpl); |
93 }; | 107 }; |
94 | 108 |
95 class CommandBufferClientImpl::SyncPointClientImpl | 109 class CommandBufferClientImpl::SyncPointClientImpl |
96 : public mus::mojom::CommandBufferSyncPointClient { | 110 : public mus::mojom::CommandBufferSyncPointClient { |
97 public: | 111 public: |
98 SyncPointClientImpl(mus::mojom::CommandBufferSyncPointClientPtr* ptr, | 112 SyncPointClientImpl(mus::mojom::CommandBufferSyncPointClientPtr* ptr, |
99 const MojoAsyncWaiter* async_waiter) | 113 const MojoAsyncWaiter* async_waiter) |
100 : sync_point_(0u), binding_(this, ptr, async_waiter) {} | 114 : sync_point_(0u), binding_(this, ptr, async_waiter) {} |
101 | 115 |
102 uint32_t WaitForInsertSyncPoint() { | 116 uint32_t WaitForInsertSyncPoint() { |
117 base::ThreadRestrictions::ScopedAllowWait wait; | |
103 if (!binding_.WaitForIncomingMethodCall()) | 118 if (!binding_.WaitForIncomingMethodCall()) |
104 return 0u; | 119 return 0u; |
105 uint32_t result = sync_point_; | 120 uint32_t result = sync_point_; |
106 sync_point_ = 0u; | 121 sync_point_ = 0u; |
107 return result; | 122 return result; |
108 } | 123 } |
109 | 124 |
110 private: | 125 private: |
111 void DidInsertSyncPoint(uint32_t sync_point) override { | 126 void DidInsertSyncPoint(uint32_t sync_point) override { |
112 sync_point_ = sync_point; | 127 sync_point_ = sync_point; |
(...skipping 22 matching lines...) Expand all Loading... | |
135 command_buffer_.Bind(mojo::InterfacePtrInfo<mus::mojom::CommandBuffer>( | 150 command_buffer_.Bind(mojo::InterfacePtrInfo<mus::mojom::CommandBuffer>( |
136 command_buffer_handle.Pass(), 0u), | 151 command_buffer_handle.Pass(), 0u), |
137 async_waiter); | 152 async_waiter); |
138 command_buffer_.set_connection_error_handler( | 153 command_buffer_.set_connection_error_handler( |
139 [this]() { DidLoseContext(gpu::error::kUnknown); }); | 154 [this]() { DidLoseContext(gpu::error::kUnknown); }); |
140 } | 155 } |
141 | 156 |
142 CommandBufferClientImpl::~CommandBufferClientImpl() {} | 157 CommandBufferClientImpl::~CommandBufferClientImpl() {} |
143 | 158 |
144 bool CommandBufferClientImpl::Initialize() { | 159 bool CommandBufferClientImpl::Initialize() { |
145 base::ThreadRestrictions::ScopedAllowWait wait; | |
146 | |
147 const size_t kSharedStateSize = sizeof(gpu::CommandBufferSharedState); | 160 const size_t kSharedStateSize = sizeof(gpu::CommandBufferSharedState); |
148 void* memory = NULL; | 161 void* memory = NULL; |
149 mojo::ScopedSharedBufferHandle duped; | 162 mojo::ScopedSharedBufferHandle duped; |
150 bool result = CreateMapAndDupSharedBuffer( | 163 bool result = CreateMapAndDupSharedBuffer( |
151 kSharedStateSize, &memory, &shared_state_handle_, &duped); | 164 kSharedStateSize, &memory, &shared_state_handle_, &duped); |
152 if (!result) | 165 if (!result) |
153 return false; | 166 return false; |
154 | 167 |
155 shared_state_ = static_cast<gpu::CommandBufferSharedState*>(memory); | 168 shared_state_ = static_cast<gpu::CommandBufferSharedState*>(memory); |
156 | 169 |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
325 gfx::Size(static_cast<int>(width), static_cast<int>(height)), | 338 gfx::Size(static_cast<int>(width), static_cast<int>(height)), |
326 gpu::ImageFactory::DefaultBufferFormatForImageFormat(internalformat), | 339 gpu::ImageFactory::DefaultBufferFormatForImageFormat(internalformat), |
327 gfx::BufferUsage::SCANOUT)); | 340 gfx::BufferUsage::SCANOUT)); |
328 if (!buffer) | 341 if (!buffer) |
329 return -1; | 342 return -1; |
330 | 343 |
331 return CreateImage(buffer->AsClientBuffer(), width, height, internalformat); | 344 return CreateImage(buffer->AsClientBuffer(), width, height, internalformat); |
332 } | 345 } |
333 | 346 |
334 uint32_t CommandBufferClientImpl::InsertSyncPoint() { | 347 uint32_t CommandBufferClientImpl::InsertSyncPoint() { |
335 base::ThreadRestrictions::ScopedAllowWait wait; | |
336 command_buffer_->InsertSyncPoint(true); | 348 command_buffer_->InsertSyncPoint(true); |
337 return sync_point_client_impl_->WaitForInsertSyncPoint(); | 349 return sync_point_client_impl_->WaitForInsertSyncPoint(); |
338 } | 350 } |
339 | 351 |
340 uint32_t CommandBufferClientImpl::InsertFutureSyncPoint() { | 352 uint32_t CommandBufferClientImpl::InsertFutureSyncPoint() { |
341 command_buffer_->InsertSyncPoint(false); | 353 command_buffer_->InsertSyncPoint(false); |
342 return sync_point_client_impl_->WaitForInsertSyncPoint(); | 354 return sync_point_client_impl_->WaitForInsertSyncPoint(); |
343 } | 355 } |
344 | 356 |
345 void CommandBufferClientImpl::RetireSyncPoint(uint32_t sync_point) { | 357 void CommandBufferClientImpl::RetireSyncPoint(uint32_t sync_point) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
396 bool CommandBufferClientImpl::IsGpuChannelLost() { | 408 bool CommandBufferClientImpl::IsGpuChannelLost() { |
397 // This is only possible for out-of-process command buffers. | 409 // This is only possible for out-of-process command buffers. |
398 return false; | 410 return false; |
399 } | 411 } |
400 | 412 |
401 gpu::CommandBufferNamespace CommandBufferClientImpl::GetNamespaceID() const { | 413 gpu::CommandBufferNamespace CommandBufferClientImpl::GetNamespaceID() const { |
402 return gpu::CommandBufferNamespace::MOJO; | 414 return gpu::CommandBufferNamespace::MOJO; |
403 } | 415 } |
404 | 416 |
405 uint64_t CommandBufferClientImpl::GetCommandBufferID() const { | 417 uint64_t CommandBufferClientImpl::GetCommandBufferID() const { |
406 // TODO (rjkroege): This must correspond to the command buffer ID on the | 418 return sync_client_impl_->GetCommandBufferID(); |
407 // server side. Most likely a combination of the client-specific integer and | |
408 // the connect id. | |
409 NOTIMPLEMENTED(); | |
410 return 0; | |
411 } | 419 } |
412 | 420 |
413 uint64_t CommandBufferClientImpl::GenerateFenceSyncRelease() { | 421 uint64_t CommandBufferClientImpl::GenerateFenceSyncRelease() { |
414 return next_fence_sync_release_++; | 422 return next_fence_sync_release_++; |
415 } | 423 } |
416 | 424 |
417 bool CommandBufferClientImpl::IsFenceSyncRelease(uint64_t release) { | 425 bool CommandBufferClientImpl::IsFenceSyncRelease(uint64_t release) { |
418 return release != 0 && release < next_fence_sync_release_; | 426 return release != 0 && release < next_fence_sync_release_; |
419 } | 427 } |
420 | 428 |
421 bool CommandBufferClientImpl::IsFenceSyncFlushed(uint64_t release) { | 429 bool CommandBufferClientImpl::IsFenceSyncFlushed(uint64_t release) { |
422 return release != 0 && release <= flushed_fence_sync_release_; | 430 return release != 0 && release <= flushed_fence_sync_release_; |
423 } | 431 } |
424 | 432 |
425 bool CommandBufferClientImpl::IsFenceSyncFlushReceived(uint64_t release) { | 433 bool CommandBufferClientImpl::IsFenceSyncFlushReceived(uint64_t release) { |
426 return IsFenceSyncFlushed(release); | 434 return IsFenceSyncFlushed(release); |
427 } | 435 } |
428 | 436 |
429 void CommandBufferClientImpl::SignalSyncToken(const gpu::SyncToken& sync_token, | 437 void CommandBufferClientImpl::SignalSyncToken(const gpu::SyncToken& sync_token, |
430 const base::Closure& callback) { | 438 const base::Closure& callback) { |
431 // TODO(dyen) | 439 // TODO(dyen) |
432 } | 440 } |
433 | 441 |
434 bool CommandBufferClientImpl::CanWaitUnverifiedSyncToken( | 442 bool CommandBufferClientImpl::CanWaitUnverifiedSyncToken( |
435 const gpu::SyncToken* sync_token) { | 443 const gpu::SyncToken* sync_token) { |
436 // All sync tokens must be flushed before being waited on. | 444 // Right now, MOJO_LOCAL is only used by trusted code, so it is safe to wait |
437 return false; | 445 // on a sync token in MOJO_LOCAL command buffer. |
446 return sync_token->namespace_id() == gpu::CommandBufferNamespace::MOJO_LOCAL; | |
piman
2015/11/24 21:49:45
It is also safe to wait on the same context (i.e.
Peng
2015/11/24 22:52:09
Done.
| |
438 } | 447 } |
439 | 448 |
440 } // namespace gles2 | 449 } // namespace gles2 |
OLD | NEW |