OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ppapi/proxy/ppapi_command_buffer_proxy.h" | 5 #include "ppapi/proxy/ppapi_command_buffer_proxy.h" |
6 | 6 |
7 #include "base/numerics/safe_conversions.h" | 7 #include "base/numerics/safe_conversions.h" |
8 #include "ppapi/proxy/ppapi_messages.h" | 8 #include "ppapi/proxy/ppapi_messages.h" |
9 #include "ppapi/shared_impl/api_id.h" | 9 #include "ppapi/shared_impl/api_id.h" |
10 #include "ppapi/shared_impl/host_resource.h" | 10 #include "ppapi/shared_impl/host_resource.h" |
11 #include "ppapi/shared_impl/proxy_lock.h" | 11 #include "ppapi/shared_impl/proxy_lock.h" |
12 | 12 |
13 namespace ppapi { | 13 namespace ppapi { |
14 namespace proxy { | 14 namespace proxy { |
15 | 15 |
16 PpapiCommandBufferProxy::PpapiCommandBufferProxy( | 16 PpapiCommandBufferProxy::PpapiCommandBufferProxy( |
17 const ppapi::HostResource& resource, | 17 const ppapi::HostResource& resource, |
18 PluginDispatcher* dispatcher, | 18 PluginDispatcher* dispatcher, |
19 const gpu::Capabilities& capabilities, | 19 const gpu::Capabilities& capabilities, |
20 const SerializedHandle& shared_state, | 20 const SerializedHandle& shared_state, |
21 uint64_t command_buffer_id) | 21 uint64_t command_buffer_id) |
22 : command_buffer_id_(command_buffer_id), | 22 : command_buffer_id_(command_buffer_id), |
23 capabilities_(capabilities), | 23 capabilities_(capabilities), |
24 resource_(resource), | 24 resource_(resource), |
25 dispatcher_(dispatcher) { | 25 dispatcher_(dispatcher), |
| 26 next_fence_sync_release_(1), |
| 27 pending_fence_sync_release_(0), |
| 28 flushed_fence_sync_release_(0) { |
26 shared_state_shm_.reset( | 29 shared_state_shm_.reset( |
27 new base::SharedMemory(shared_state.shmem(), false)); | 30 new base::SharedMemory(shared_state.shmem(), false)); |
28 shared_state_shm_->Map(shared_state.size()); | 31 shared_state_shm_->Map(shared_state.size()); |
29 InstanceData* data = dispatcher->GetInstanceData(resource.instance()); | 32 InstanceData* data = dispatcher->GetInstanceData(resource.instance()); |
30 flush_info_ = &data->flush_info_; | 33 flush_info_ = &data->flush_info_; |
31 } | 34 } |
32 | 35 |
33 PpapiCommandBufferProxy::~PpapiCommandBufferProxy() { | 36 PpapiCommandBufferProxy::~PpapiCommandBufferProxy() { |
34 // gpu::Buffers are no longer referenced, allowing shared memory objects to be | 37 // gpu::Buffers are no longer referenced, allowing shared memory objects to be |
35 // deleted, closing the handle in this process. | 38 // deleted, closing the handle in this process. |
(...skipping 19 matching lines...) Expand all Loading... |
55 return; | 58 return; |
56 | 59 |
57 OrderingBarrier(put_offset); | 60 OrderingBarrier(put_offset); |
58 FlushInternal(); | 61 FlushInternal(); |
59 } | 62 } |
60 | 63 |
61 void PpapiCommandBufferProxy::OrderingBarrier(int32 put_offset) { | 64 void PpapiCommandBufferProxy::OrderingBarrier(int32 put_offset) { |
62 if (last_state_.error != gpu::error::kNoError) | 65 if (last_state_.error != gpu::error::kNoError) |
63 return; | 66 return; |
64 | 67 |
65 if (flush_info_->flush_pending && flush_info_->resource != resource_) | 68 if (flush_info_->flush_pending && flush_info_->resource != resource_) { |
66 FlushInternal(); | 69 FlushInternal(); |
| 70 } |
67 | 71 |
68 flush_info_->flush_pending = true; | 72 flush_info_->flush_pending = true; |
69 flush_info_->resource = resource_; | 73 flush_info_->resource = resource_; |
70 flush_info_->put_offset = put_offset; | 74 flush_info_->put_offset = put_offset; |
| 75 pending_fence_sync_release_ = next_fence_sync_release_ - 1; |
71 } | 76 } |
72 | 77 |
73 void PpapiCommandBufferProxy::WaitForTokenInRange(int32 start, int32 end) { | 78 void PpapiCommandBufferProxy::WaitForTokenInRange(int32 start, int32 end) { |
74 TryUpdateState(); | 79 TryUpdateState(); |
75 if (!InRange(start, end, last_state_.token) && | 80 if (!InRange(start, end, last_state_.token) && |
76 last_state_.error == gpu::error::kNoError) { | 81 last_state_.error == gpu::error::kNoError) { |
77 bool success = false; | 82 bool success = false; |
78 gpu::CommandBuffer::State state; | 83 gpu::CommandBuffer::State state; |
79 if (Send(new PpapiHostMsg_PPBGraphics3D_WaitForTokenInRange( | 84 if (Send(new PpapiHostMsg_PPBGraphics3D_WaitForTokenInRange( |
80 ppapi::API_ID_PPB_GRAPHICS_3D, | 85 ppapi::API_ID_PPB_GRAPHICS_3D, |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 } | 185 } |
181 | 186 |
182 gpu::CommandBufferNamespace PpapiCommandBufferProxy::GetNamespaceID() const { | 187 gpu::CommandBufferNamespace PpapiCommandBufferProxy::GetNamespaceID() const { |
183 return gpu::CommandBufferNamespace::GPU_IO; | 188 return gpu::CommandBufferNamespace::GPU_IO; |
184 } | 189 } |
185 | 190 |
186 uint64_t PpapiCommandBufferProxy::GetCommandBufferID() const { | 191 uint64_t PpapiCommandBufferProxy::GetCommandBufferID() const { |
187 return command_buffer_id_; | 192 return command_buffer_id_; |
188 } | 193 } |
189 | 194 |
| 195 uint64_t PpapiCommandBufferProxy::GenerateFenceSyncRelease() { |
| 196 return next_fence_sync_release_++; |
| 197 } |
| 198 |
| 199 bool PpapiCommandBufferProxy::IsFenceSyncRelease(uint64_t release) { |
| 200 return release != 0 && release < next_fence_sync_release_; |
| 201 } |
| 202 |
| 203 bool PpapiCommandBufferProxy::IsFenceSyncFlushed(uint64_t release) { |
| 204 return release <= flushed_fence_sync_release_; |
| 205 } |
| 206 |
190 uint32 PpapiCommandBufferProxy::InsertSyncPoint() { | 207 uint32 PpapiCommandBufferProxy::InsertSyncPoint() { |
191 uint32 sync_point = 0; | 208 uint32 sync_point = 0; |
192 if (last_state_.error == gpu::error::kNoError) { | 209 if (last_state_.error == gpu::error::kNoError) { |
193 Send(new PpapiHostMsg_PPBGraphics3D_InsertSyncPoint( | 210 Send(new PpapiHostMsg_PPBGraphics3D_InsertSyncPoint( |
194 ppapi::API_ID_PPB_GRAPHICS_3D, resource_, &sync_point)); | 211 ppapi::API_ID_PPB_GRAPHICS_3D, resource_, &sync_point)); |
195 } | 212 } |
196 return sync_point; | 213 return sync_point; |
197 } | 214 } |
198 | 215 |
199 uint32 PpapiCommandBufferProxy::InsertFutureSyncPoint() { | 216 uint32 PpapiCommandBufferProxy::InsertFutureSyncPoint() { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 | 304 |
288 gpu::CommandBufferSharedState* PpapiCommandBufferProxy::shared_state() const { | 305 gpu::CommandBufferSharedState* PpapiCommandBufferProxy::shared_state() const { |
289 return reinterpret_cast<gpu::CommandBufferSharedState*>( | 306 return reinterpret_cast<gpu::CommandBufferSharedState*>( |
290 shared_state_shm_->memory()); | 307 shared_state_shm_->memory()); |
291 } | 308 } |
292 | 309 |
293 void PpapiCommandBufferProxy::FlushInternal() { | 310 void PpapiCommandBufferProxy::FlushInternal() { |
294 DCHECK(last_state_.error == gpu::error::kNoError); | 311 DCHECK(last_state_.error == gpu::error::kNoError); |
295 | 312 |
296 DCHECK(flush_info_->flush_pending); | 313 DCHECK(flush_info_->flush_pending); |
| 314 DCHECK_GE(pending_fence_sync_release_, flushed_fence_sync_release_); |
297 | 315 |
298 IPC::Message* message = new PpapiHostMsg_PPBGraphics3D_AsyncFlush( | 316 IPC::Message* message = new PpapiHostMsg_PPBGraphics3D_AsyncFlush( |
299 ppapi::API_ID_PPB_GRAPHICS_3D, flush_info_->resource, | 317 ppapi::API_ID_PPB_GRAPHICS_3D, flush_info_->resource, |
300 flush_info_->put_offset); | 318 flush_info_->put_offset); |
301 | 319 |
302 // Do not let a synchronous flush hold up this message. If this handler is | 320 // Do not let a synchronous flush hold up this message. If this handler is |
303 // deferred until after the synchronous flush completes, it will overwrite the | 321 // deferred until after the synchronous flush completes, it will overwrite the |
304 // cached last_state_ with out-of-date data. | 322 // cached last_state_ with out-of-date data. |
305 message->set_unblock(true); | 323 message->set_unblock(true); |
306 Send(message); | 324 Send(message); |
307 | 325 |
308 flush_info_->flush_pending = false; | 326 flush_info_->flush_pending = false; |
309 flush_info_->resource.SetHostResource(0, 0); | 327 flush_info_->resource.SetHostResource(0, 0); |
| 328 flushed_fence_sync_release_ = pending_fence_sync_release_; |
310 } | 329 } |
311 | 330 |
312 } // namespace proxy | 331 } // namespace proxy |
313 } // namespace ppapi | 332 } // namespace ppapi |
OLD | NEW |