| 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 13 matching lines...) Expand all Loading... |
| 49 TryUpdateState(); | 52 TryUpdateState(); |
| 50 return last_state_.token; | 53 return last_state_.token; |
| 51 } | 54 } |
| 52 | 55 |
| 53 void PpapiCommandBufferProxy::Flush(int32 put_offset) { | 56 void PpapiCommandBufferProxy::Flush(int32 put_offset) { |
| 54 if (last_state_.error != gpu::error::kNoError) | 57 if (last_state_.error != gpu::error::kNoError) |
| 55 return; | 58 return; |
| 56 | 59 |
| 57 OrderingBarrier(put_offset); | 60 OrderingBarrier(put_offset); |
| 58 FlushInternal(); | 61 FlushInternal(); |
| 62 flushed_fence_sync_release_ = next_fence_sync_release_ - 1; |
| 59 } | 63 } |
| 60 | 64 |
| 61 void PpapiCommandBufferProxy::OrderingBarrier(int32 put_offset) { | 65 void PpapiCommandBufferProxy::OrderingBarrier(int32 put_offset) { |
| 62 if (last_state_.error != gpu::error::kNoError) | 66 if (last_state_.error != gpu::error::kNoError) |
| 63 return; | 67 return; |
| 64 | 68 |
| 65 if (flush_info_->flush_pending && flush_info_->resource != resource_) | 69 if (flush_info_->flush_pending && flush_info_->resource != resource_) { |
| 70 DCHECK(pending_fence_sync_release_ > flushed_fence_sync_release_); |
| 66 FlushInternal(); | 71 FlushInternal(); |
| 72 flushed_fence_sync_release_ = pending_fence_sync_release_; |
| 73 } |
| 67 | 74 |
| 68 flush_info_->flush_pending = true; | 75 flush_info_->flush_pending = true; |
| 69 flush_info_->resource = resource_; | 76 flush_info_->resource = resource_; |
| 70 flush_info_->put_offset = put_offset; | 77 flush_info_->put_offset = put_offset; |
| 78 pending_fence_sync_release_ = next_fence_sync_release_ - 1; |
| 71 } | 79 } |
| 72 | 80 |
| 73 void PpapiCommandBufferProxy::WaitForTokenInRange(int32 start, int32 end) { | 81 void PpapiCommandBufferProxy::WaitForTokenInRange(int32 start, int32 end) { |
| 74 TryUpdateState(); | 82 TryUpdateState(); |
| 75 if (!InRange(start, end, last_state_.token) && | 83 if (!InRange(start, end, last_state_.token) && |
| 76 last_state_.error == gpu::error::kNoError) { | 84 last_state_.error == gpu::error::kNoError) { |
| 77 bool success = false; | 85 bool success = false; |
| 78 gpu::CommandBuffer::State state; | 86 gpu::CommandBuffer::State state; |
| 79 if (Send(new PpapiHostMsg_PPBGraphics3D_WaitForTokenInRange( | 87 if (Send(new PpapiHostMsg_PPBGraphics3D_WaitForTokenInRange( |
| 80 ppapi::API_ID_PPB_GRAPHICS_3D, | 88 ppapi::API_ID_PPB_GRAPHICS_3D, |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 } | 188 } |
| 181 | 189 |
| 182 gpu::CommandBufferNamespace PpapiCommandBufferProxy::GetNamespaceID() const { | 190 gpu::CommandBufferNamespace PpapiCommandBufferProxy::GetNamespaceID() const { |
| 183 return gpu::CommandBufferNamespace::GPU_IO; | 191 return gpu::CommandBufferNamespace::GPU_IO; |
| 184 } | 192 } |
| 185 | 193 |
| 186 uint64_t PpapiCommandBufferProxy::GetCommandBufferID() const { | 194 uint64_t PpapiCommandBufferProxy::GetCommandBufferID() const { |
| 187 return command_buffer_id_; | 195 return command_buffer_id_; |
| 188 } | 196 } |
| 189 | 197 |
| 198 uint32_t PpapiCommandBufferProxy::GenerateFenceSyncRelease() { |
| 199 return next_fence_sync_release_++; |
| 200 } |
| 201 |
| 202 bool PpapiCommandBufferProxy::IsFenceSyncRelease(uint32_t release) { |
| 203 return release != 0 && release < next_fence_sync_release_; |
| 204 } |
| 205 |
| 206 bool PpapiCommandBufferProxy::IsFenceSyncFlushed(uint32_t release) { |
| 207 return release <= flushed_fence_sync_release_; |
| 208 } |
| 209 |
| 190 uint32 PpapiCommandBufferProxy::InsertSyncPoint() { | 210 uint32 PpapiCommandBufferProxy::InsertSyncPoint() { |
| 191 uint32 sync_point = 0; | 211 uint32 sync_point = 0; |
| 192 if (last_state_.error == gpu::error::kNoError) { | 212 if (last_state_.error == gpu::error::kNoError) { |
| 193 Send(new PpapiHostMsg_PPBGraphics3D_InsertSyncPoint( | 213 Send(new PpapiHostMsg_PPBGraphics3D_InsertSyncPoint( |
| 194 ppapi::API_ID_PPB_GRAPHICS_3D, resource_, &sync_point)); | 214 ppapi::API_ID_PPB_GRAPHICS_3D, resource_, &sync_point)); |
| 195 } | 215 } |
| 196 return sync_point; | 216 return sync_point; |
| 197 } | 217 } |
| 198 | 218 |
| 199 uint32 PpapiCommandBufferProxy::InsertFutureSyncPoint() { | 219 uint32 PpapiCommandBufferProxy::InsertFutureSyncPoint() { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 // cached last_state_ with out-of-date data. | 324 // cached last_state_ with out-of-date data. |
| 305 message->set_unblock(true); | 325 message->set_unblock(true); |
| 306 Send(message); | 326 Send(message); |
| 307 | 327 |
| 308 flush_info_->flush_pending = false; | 328 flush_info_->flush_pending = false; |
| 309 flush_info_->resource.SetHostResource(0, 0); | 329 flush_info_->resource.SetHostResource(0, 0); |
| 310 } | 330 } |
| 311 | 331 |
| 312 } // namespace proxy | 332 } // namespace proxy |
| 313 } // namespace ppapi | 333 } // namespace ppapi |
| OLD | NEW |