| 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 "ppapi/proxy/ppapi_messages.h" | 7 #include "ppapi/proxy/ppapi_messages.h" |
| 8 #include "ppapi/proxy/proxy_channel.h" | 8 #include "ppapi/proxy/proxy_channel.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 ProxyChannel* channel) | 18 ProxyChannel* channel, |
| 19 const SerializedHandle& shared_state) |
| 19 : resource_(resource), | 20 : resource_(resource), |
| 20 channel_(channel) { | 21 channel_(channel) { |
| 22 shared_state_shm_.reset( |
| 23 new base::SharedMemory(shared_state.shmem(), false)); |
| 24 shared_state_shm_->Map(shared_state.size()); |
| 21 } | 25 } |
| 22 | 26 |
| 23 PpapiCommandBufferProxy::~PpapiCommandBufferProxy() { | 27 PpapiCommandBufferProxy::~PpapiCommandBufferProxy() { |
| 24 // gpu::Buffers are no longer referenced, allowing shared memory objects to be | 28 // gpu::Buffers are no longer referenced, allowing shared memory objects to be |
| 25 // deleted, closing the handle in this process. | 29 // deleted, closing the handle in this process. |
| 26 } | 30 } |
| 27 | 31 |
| 28 bool PpapiCommandBufferProxy::Initialize() { | 32 bool PpapiCommandBufferProxy::Initialize() { |
| 29 return true; | 33 return true; |
| 30 } | 34 } |
| 31 | 35 |
| 32 gpu::CommandBuffer::State PpapiCommandBufferProxy::GetLastState() { | 36 gpu::CommandBuffer::State PpapiCommandBufferProxy::GetLastState() { |
| 33 ppapi::ProxyLock::AssertAcquiredDebugOnly(); | 37 ppapi::ProxyLock::AssertAcquiredDebugOnly(); |
| 34 return last_state_; | 38 return last_state_; |
| 35 } | 39 } |
| 36 | 40 |
| 37 int32 PpapiCommandBufferProxy::GetLastToken() { | 41 int32 PpapiCommandBufferProxy::GetLastToken() { |
| 38 ppapi::ProxyLock::AssertAcquiredDebugOnly(); | 42 ppapi::ProxyLock::AssertAcquiredDebugOnly(); |
| 43 TryUpdateState(); |
| 39 return last_state_.token; | 44 return last_state_.token; |
| 40 } | 45 } |
| 41 | 46 |
| 42 void PpapiCommandBufferProxy::Flush(int32 put_offset) { | 47 void PpapiCommandBufferProxy::Flush(int32 put_offset) { |
| 43 if (last_state_.error != gpu::error::kNoError) | 48 if (last_state_.error != gpu::error::kNoError) |
| 44 return; | 49 return; |
| 45 | 50 |
| 46 IPC::Message* message = new PpapiHostMsg_PPBGraphics3D_AsyncFlush( | 51 IPC::Message* message = new PpapiHostMsg_PPBGraphics3D_AsyncFlush( |
| 47 ppapi::API_ID_PPB_GRAPHICS_3D, resource_, put_offset); | 52 ppapi::API_ID_PPB_GRAPHICS_3D, resource_, put_offset); |
| 48 | 53 |
| 49 // Do not let a synchronous flush hold up this message. If this handler is | 54 // Do not let a synchronous flush hold up this message. If this handler is |
| 50 // deferred until after the synchronous flush completes, it will overwrite the | 55 // deferred until after the synchronous flush completes, it will overwrite the |
| 51 // cached last_state_ with out-of-date data. | 56 // cached last_state_ with out-of-date data. |
| 52 message->set_unblock(true); | 57 message->set_unblock(true); |
| 53 Send(message); | 58 Send(message); |
| 54 } | 59 } |
| 55 | 60 |
| 56 void PpapiCommandBufferProxy::WaitForTokenInRange(int32 start, int32 end) { | 61 void PpapiCommandBufferProxy::WaitForTokenInRange(int32 start, int32 end) { |
| 57 if (last_state_.error != gpu::error::kNoError) | 62 TryUpdateState(); |
| 58 return; | 63 if (!InRange(start, end, last_state_.token) && |
| 59 | 64 last_state_.error == gpu::error::kNoError) { |
| 60 bool success = false; | 65 bool success = false; |
| 61 gpu::CommandBuffer::State state; | 66 gpu::CommandBuffer::State state; |
| 62 if (Send(new PpapiHostMsg_PPBGraphics3D_WaitForTokenInRange( | 67 if (Send(new PpapiHostMsg_PPBGraphics3D_WaitForTokenInRange( |
| 63 ppapi::API_ID_PPB_GRAPHICS_3D, | 68 ppapi::API_ID_PPB_GRAPHICS_3D, |
| 64 resource_, | 69 resource_, |
| 65 start, | 70 start, |
| 66 end, | 71 end, |
| 67 &state, | 72 &state, |
| 68 &success))) | 73 &success))) |
| 69 UpdateState(state, success); | 74 UpdateState(state, success); |
| 75 } |
| 76 DCHECK(InRange(start, end, last_state_.token) || |
| 77 last_state_.error != gpu::error::kNoError); |
| 70 } | 78 } |
| 71 | 79 |
| 72 void PpapiCommandBufferProxy::WaitForGetOffsetInRange(int32 start, int32 end) { | 80 void PpapiCommandBufferProxy::WaitForGetOffsetInRange(int32 start, int32 end) { |
| 73 if (last_state_.error != gpu::error::kNoError) | 81 TryUpdateState(); |
| 74 return; | 82 if (!InRange(start, end, last_state_.get_offset) && |
| 75 | 83 last_state_.error == gpu::error::kNoError) { |
| 76 bool success = false; | 84 bool success = false; |
| 77 gpu::CommandBuffer::State state; | 85 gpu::CommandBuffer::State state; |
| 78 if (Send(new PpapiHostMsg_PPBGraphics3D_WaitForGetOffsetInRange( | 86 if (Send(new PpapiHostMsg_PPBGraphics3D_WaitForGetOffsetInRange( |
| 79 ppapi::API_ID_PPB_GRAPHICS_3D, | 87 ppapi::API_ID_PPB_GRAPHICS_3D, |
| 80 resource_, | 88 resource_, |
| 81 start, | 89 start, |
| 82 end, | 90 end, |
| 83 &state, | 91 &state, |
| 84 &success))) | 92 &success))) |
| 85 UpdateState(state, success); | 93 UpdateState(state, success); |
| 94 } |
| 95 DCHECK(InRange(start, end, last_state_.get_offset) || |
| 96 last_state_.error != gpu::error::kNoError); |
| 86 } | 97 } |
| 87 | 98 |
| 88 void PpapiCommandBufferProxy::SetGetBuffer(int32 transfer_buffer_id) { | 99 void PpapiCommandBufferProxy::SetGetBuffer(int32 transfer_buffer_id) { |
| 89 if (last_state_.error == gpu::error::kNoError) { | 100 if (last_state_.error == gpu::error::kNoError) { |
| 90 Send(new PpapiHostMsg_PPBGraphics3D_SetGetBuffer( | 101 Send(new PpapiHostMsg_PPBGraphics3D_SetGetBuffer( |
| 91 ppapi::API_ID_PPB_GRAPHICS_3D, resource_, transfer_buffer_id)); | 102 ppapi::API_ID_PPB_GRAPHICS_3D, resource_, transfer_buffer_id)); |
| 92 } | 103 } |
| 93 } | 104 } |
| 94 | 105 |
| 95 scoped_refptr<gpu::Buffer> PpapiCommandBufferProxy::CreateTransferBuffer( | 106 scoped_refptr<gpu::Buffer> PpapiCommandBufferProxy::CreateTransferBuffer( |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 if (success) { | 231 if (success) { |
| 221 if (state.generation - last_state_.generation < 0x80000000U) { | 232 if (state.generation - last_state_.generation < 0x80000000U) { |
| 222 last_state_ = state; | 233 last_state_ = state; |
| 223 } | 234 } |
| 224 } else { | 235 } else { |
| 225 last_state_.error = gpu::error::kLostContext; | 236 last_state_.error = gpu::error::kLostContext; |
| 226 ++last_state_.generation; | 237 ++last_state_.generation; |
| 227 } | 238 } |
| 228 } | 239 } |
| 229 | 240 |
| 241 void PpapiCommandBufferProxy::TryUpdateState() { |
| 242 if (last_state_.error == gpu::error::kNoError) |
| 243 shared_state()->Read(&last_state_); |
| 244 } |
| 245 |
| 246 gpu::CommandBufferSharedState* PpapiCommandBufferProxy::shared_state() const { |
| 247 return reinterpret_cast<gpu::CommandBufferSharedState*>( |
| 248 shared_state_shm_->memory()); |
| 249 } |
| 250 |
| 230 } // namespace proxy | 251 } // namespace proxy |
| 231 } // namespace ppapi | 252 } // namespace ppapi |
| OLD | NEW |