| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/numerics/safe_conversions.h" | 9 #include "base/numerics/safe_conversions.h" |
| 10 #include "ppapi/proxy/ppapi_messages.h" | 10 #include "ppapi/proxy/ppapi_messages.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 const SerializedHandle& shared_state, | 22 const SerializedHandle& shared_state, |
| 23 gpu::CommandBufferId command_buffer_id) | 23 gpu::CommandBufferId command_buffer_id) |
| 24 : command_buffer_id_(command_buffer_id), | 24 : command_buffer_id_(command_buffer_id), |
| 25 capabilities_(capabilities), | 25 capabilities_(capabilities), |
| 26 resource_(resource), | 26 resource_(resource), |
| 27 dispatcher_(dispatcher), | 27 dispatcher_(dispatcher), |
| 28 next_fence_sync_release_(1), | 28 next_fence_sync_release_(1), |
| 29 pending_fence_sync_release_(0), | 29 pending_fence_sync_release_(0), |
| 30 flushed_fence_sync_release_(0), | 30 flushed_fence_sync_release_(0), |
| 31 validated_fence_sync_release_(0) { | 31 validated_fence_sync_release_(0) { |
| 32 shared_state_shm_.reset( | 32 shared_state_shm_.reset(new base::SharedMemory(shared_state.shmem(), false)); |
| 33 new base::SharedMemory(shared_state.shmem(), false)); | |
| 34 shared_state_shm_->Map(shared_state.size()); | 33 shared_state_shm_->Map(shared_state.size()); |
| 35 InstanceData* data = dispatcher->GetInstanceData(resource.instance()); | 34 InstanceData* data = dispatcher->GetInstanceData(resource.instance()); |
| 36 flush_info_ = &data->flush_info_; | 35 flush_info_ = &data->flush_info_; |
| 37 } | 36 } |
| 38 | 37 |
| 39 PpapiCommandBufferProxy::~PpapiCommandBufferProxy() { | 38 PpapiCommandBufferProxy::~PpapiCommandBufferProxy() { |
| 40 // gpu::Buffers are no longer referenced, allowing shared memory objects to be | 39 // gpu::Buffers are no longer referenced, allowing shared memory objects to be |
| 41 // deleted, closing the handle in this process. | 40 // deleted, closing the handle in this process. |
| 42 } | 41 } |
| 43 | 42 |
| 44 gpu::CommandBuffer::State PpapiCommandBufferProxy::GetLastState() { | 43 gpu::CommandBuffer::State PpapiCommandBufferProxy::GetLastState() { |
| 45 ppapi::ProxyLock::AssertAcquiredDebugOnly(); | 44 ppapi::ProxyLock::AssertAcquiredDebugOnly(); |
| 45 TryUpdateState(); |
| 46 return last_state_; | 46 return last_state_; |
| 47 } | 47 } |
| 48 | 48 |
| 49 int32_t PpapiCommandBufferProxy::GetLastToken() { | |
| 50 ppapi::ProxyLock::AssertAcquiredDebugOnly(); | |
| 51 TryUpdateState(); | |
| 52 return last_state_.token; | |
| 53 } | |
| 54 | |
| 55 void PpapiCommandBufferProxy::Flush(int32_t put_offset) { | 49 void PpapiCommandBufferProxy::Flush(int32_t put_offset) { |
| 56 if (last_state_.error != gpu::error::kNoError) | 50 if (last_state_.error != gpu::error::kNoError) |
| 57 return; | 51 return; |
| 58 | 52 |
| 59 OrderingBarrier(put_offset); | 53 OrderingBarrier(put_offset); |
| 60 FlushInternal(); | 54 FlushInternal(); |
| 61 } | 55 } |
| 62 | 56 |
| 63 void PpapiCommandBufferProxy::OrderingBarrier(int32_t put_offset) { | 57 void PpapiCommandBufferProxy::OrderingBarrier(int32_t put_offset) { |
| 64 if (last_state_.error != gpu::error::kNoError) | 58 if (last_state_.error != gpu::error::kNoError) |
| 65 return; | 59 return; |
| 66 | 60 |
| 67 if (flush_info_->flush_pending && flush_info_->resource != resource_) { | 61 if (flush_info_->flush_pending && flush_info_->resource != resource_) { |
| 68 FlushInternal(); | 62 FlushInternal(); |
| 69 } | 63 } |
| 70 | 64 |
| 71 flush_info_->flush_pending = true; | 65 flush_info_->flush_pending = true; |
| 72 flush_info_->resource = resource_; | 66 flush_info_->resource = resource_; |
| 73 flush_info_->put_offset = put_offset; | 67 flush_info_->put_offset = put_offset; |
| 74 pending_fence_sync_release_ = next_fence_sync_release_ - 1; | 68 pending_fence_sync_release_ = next_fence_sync_release_ - 1; |
| 75 } | 69 } |
| 76 | 70 |
| 77 void PpapiCommandBufferProxy::WaitForTokenInRange(int32_t start, int32_t end) { | 71 gpu::CommandBuffer::State PpapiCommandBufferProxy::WaitForTokenInRange( |
| 72 int32_t start, |
| 73 int32_t end) { |
| 78 TryUpdateState(); | 74 TryUpdateState(); |
| 79 if (!InRange(start, end, last_state_.token) && | 75 if (!InRange(start, end, last_state_.token) && |
| 80 last_state_.error == gpu::error::kNoError) { | 76 last_state_.error == gpu::error::kNoError) { |
| 81 bool success = false; | 77 bool success = false; |
| 82 gpu::CommandBuffer::State state; | 78 gpu::CommandBuffer::State state; |
| 83 if (Send(new PpapiHostMsg_PPBGraphics3D_WaitForTokenInRange( | 79 if (Send(new PpapiHostMsg_PPBGraphics3D_WaitForTokenInRange( |
| 84 ppapi::API_ID_PPB_GRAPHICS_3D, | 80 ppapi::API_ID_PPB_GRAPHICS_3D, resource_, start, end, &state, |
| 85 resource_, | 81 &success))) |
| 86 start, | |
| 87 end, | |
| 88 &state, | |
| 89 &success))) | |
| 90 UpdateState(state, success); | 82 UpdateState(state, success); |
| 91 } | 83 } |
| 92 DCHECK(InRange(start, end, last_state_.token) || | 84 DCHECK(InRange(start, end, last_state_.token) || |
| 93 last_state_.error != gpu::error::kNoError); | 85 last_state_.error != gpu::error::kNoError); |
| 86 return last_state_; |
| 94 } | 87 } |
| 95 | 88 |
| 96 void PpapiCommandBufferProxy::WaitForGetOffsetInRange(int32_t start, | 89 gpu::CommandBuffer::State PpapiCommandBufferProxy::WaitForGetOffsetInRange( |
| 97 int32_t end) { | 90 int32_t start, |
| 91 int32_t end) { |
| 98 TryUpdateState(); | 92 TryUpdateState(); |
| 99 if (!InRange(start, end, last_state_.get_offset) && | 93 if (!InRange(start, end, last_state_.get_offset) && |
| 100 last_state_.error == gpu::error::kNoError) { | 94 last_state_.error == gpu::error::kNoError) { |
| 101 bool success = false; | 95 bool success = false; |
| 102 gpu::CommandBuffer::State state; | 96 gpu::CommandBuffer::State state; |
| 103 if (Send(new PpapiHostMsg_PPBGraphics3D_WaitForGetOffsetInRange( | 97 if (Send(new PpapiHostMsg_PPBGraphics3D_WaitForGetOffsetInRange( |
| 104 ppapi::API_ID_PPB_GRAPHICS_3D, | 98 ppapi::API_ID_PPB_GRAPHICS_3D, resource_, start, end, &state, |
| 105 resource_, | 99 &success))) |
| 106 start, | |
| 107 end, | |
| 108 &state, | |
| 109 &success))) | |
| 110 UpdateState(state, success); | 100 UpdateState(state, success); |
| 111 } | 101 } |
| 112 DCHECK(InRange(start, end, last_state_.get_offset) || | 102 DCHECK(InRange(start, end, last_state_.get_offset) || |
| 113 last_state_.error != gpu::error::kNoError); | 103 last_state_.error != gpu::error::kNoError); |
| 104 return last_state_; |
| 114 } | 105 } |
| 115 | 106 |
| 116 void PpapiCommandBufferProxy::SetGetBuffer(int32_t transfer_buffer_id) { | 107 void PpapiCommandBufferProxy::SetGetBuffer(int32_t transfer_buffer_id) { |
| 117 if (last_state_.error == gpu::error::kNoError) { | 108 if (last_state_.error == gpu::error::kNoError) { |
| 118 Send(new PpapiHostMsg_PPBGraphics3D_SetGetBuffer( | 109 Send(new PpapiHostMsg_PPBGraphics3D_SetGetBuffer( |
| 119 ppapi::API_ID_PPB_GRAPHICS_3D, resource_, transfer_buffer_id)); | 110 ppapi::API_ID_PPB_GRAPHICS_3D, resource_, transfer_buffer_id)); |
| 120 } | 111 } |
| 121 } | 112 } |
| 122 | 113 |
| 123 scoped_refptr<gpu::Buffer> PpapiCommandBufferProxy::CreateTransferBuffer( | 114 scoped_refptr<gpu::Buffer> PpapiCommandBufferProxy::CreateTransferBuffer( |
| 124 size_t size, | 115 size_t size, |
| 125 int32_t* id) { | 116 int32_t* id) { |
| 126 *id = -1; | 117 *id = -1; |
| 127 | 118 |
| 128 if (last_state_.error != gpu::error::kNoError) | 119 if (last_state_.error != gpu::error::kNoError) |
| 129 return NULL; | 120 return NULL; |
| 130 | 121 |
| 131 // Assuming we are in the renderer process, the service is responsible for | 122 // Assuming we are in the renderer process, the service is responsible for |
| 132 // duplicating the handle. This might not be true for NaCl. | 123 // duplicating the handle. This might not be true for NaCl. |
| 133 ppapi::proxy::SerializedHandle handle( | 124 ppapi::proxy::SerializedHandle handle( |
| 134 ppapi::proxy::SerializedHandle::SHARED_MEMORY); | 125 ppapi::proxy::SerializedHandle::SHARED_MEMORY); |
| 135 if (!Send(new PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer( | 126 if (!Send(new PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer( |
| 136 ppapi::API_ID_PPB_GRAPHICS_3D, resource_, | 127 ppapi::API_ID_PPB_GRAPHICS_3D, resource_, |
| 137 base::checked_cast<uint32_t>(size), id, &handle))) { | 128 base::checked_cast<uint32_t>(size), id, &handle))) { |
| 138 if (last_state_.error == gpu::error::kNoError) | 129 if (last_state_.error == gpu::error::kNoError) |
| 139 last_state_.error = gpu::error::kLostContext; | 130 last_state_.error = gpu::error::kLostContext; |
| 140 return NULL; | 131 return NULL; |
| 141 } | 132 } |
| 142 | 133 |
| 143 if (*id <= 0 || !handle.is_shmem()) { | 134 if (*id <= 0 || !handle.is_shmem()) { |
| 144 if (last_state_.error == gpu::error::kNoError) | 135 if (last_state_.error == gpu::error::kNoError) |
| 145 last_state_.error = gpu::error::kOutOfBounds; | 136 last_state_.error = gpu::error::kOutOfBounds; |
| 146 return NULL; | 137 return NULL; |
| 147 } | 138 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 if (!IsFenceSyncFlushed(release)) | 197 if (!IsFenceSyncFlushed(release)) |
| 207 return false; | 198 return false; |
| 208 | 199 |
| 209 if (release <= validated_fence_sync_release_) | 200 if (release <= validated_fence_sync_release_) |
| 210 return true; | 201 return true; |
| 211 | 202 |
| 212 EnsureWorkVisible(); | 203 EnsureWorkVisible(); |
| 213 return release <= validated_fence_sync_release_; | 204 return release <= validated_fence_sync_release_; |
| 214 } | 205 } |
| 215 | 206 |
| 207 bool PpapiCommandBufferProxy::IsFenceSyncReleased(uint64_t release) { |
| 208 NOTIMPLEMENTED(); |
| 209 return false; |
| 210 } |
| 211 |
| 216 void PpapiCommandBufferProxy::SignalSyncToken(const gpu::SyncToken& sync_token, | 212 void PpapiCommandBufferProxy::SignalSyncToken(const gpu::SyncToken& sync_token, |
| 217 const base::Closure& callback) { | 213 const base::Closure& callback) { |
| 218 NOTIMPLEMENTED(); | 214 NOTIMPLEMENTED(); |
| 219 } | 215 } |
| 220 | 216 |
| 221 bool PpapiCommandBufferProxy::CanWaitUnverifiedSyncToken( | 217 bool PpapiCommandBufferProxy::CanWaitUnverifiedSyncToken( |
| 222 const gpu::SyncToken* sync_token) { | 218 const gpu::SyncToken* sync_token) { |
| 223 return false; | 219 return false; |
| 224 } | 220 } |
| 225 | 221 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 message->set_unblock(true); | 313 message->set_unblock(true); |
| 318 Send(message); | 314 Send(message); |
| 319 | 315 |
| 320 flush_info_->flush_pending = false; | 316 flush_info_->flush_pending = false; |
| 321 flush_info_->resource.SetHostResource(0, 0); | 317 flush_info_->resource.SetHostResource(0, 0); |
| 322 flushed_fence_sync_release_ = pending_fence_sync_release_; | 318 flushed_fence_sync_release_ = pending_fence_sync_release_; |
| 323 } | 319 } |
| 324 | 320 |
| 325 } // namespace proxy | 321 } // namespace proxy |
| 326 } // namespace ppapi | 322 } // namespace ppapi |
| OLD | NEW |