| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ppb_graphics_3d_proxy.h" | 5 #include "ppapi/proxy/ppb_graphics_3d_proxy.h" |
| 6 | 6 |
| 7 #include "gpu/command_buffer/client/gles2_implementation.h" | 7 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 8 #include "ppapi/c/pp_errors.h" | 8 #include "ppapi/c/pp_errors.h" |
| 9 #include "ppapi/proxy/enter_proxy.h" | 9 #include "ppapi/proxy/enter_proxy.h" |
| 10 #include "ppapi/proxy/plugin_dispatcher.h" | 10 #include "ppapi/proxy/plugin_dispatcher.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 } | 85 } |
| 86 | 86 |
| 87 bool CommandBuffer::Initialize(int32 size) { | 87 bool CommandBuffer::Initialize(int32 size) { |
| 88 DCHECK(!ring_buffer_.get()); | 88 DCHECK(!ring_buffer_.get()); |
| 89 | 89 |
| 90 // Initialize the service. Assuming we are sandboxed, the GPU | 90 // Initialize the service. Assuming we are sandboxed, the GPU |
| 91 // process is responsible for duplicating the handle. This might not be true | 91 // process is responsible for duplicating the handle. This might not be true |
| 92 // for NaCl. | 92 // for NaCl. |
| 93 base::SharedMemoryHandle handle; | 93 base::SharedMemoryHandle handle; |
| 94 if (Send(new PpapiHostMsg_PPBGraphics3D_InitCommandBuffer( | 94 if (Send(new PpapiHostMsg_PPBGraphics3D_InitCommandBuffer( |
| 95 INTERFACE_ID_PPB_GRAPHICS_3D, resource_, size, &handle)) && | 95 API_ID_PPB_GRAPHICS_3D, resource_, size, &handle)) && |
| 96 base::SharedMemory::IsHandleValid(handle)) { | 96 base::SharedMemory::IsHandleValid(handle)) { |
| 97 ring_buffer_.reset(new base::SharedMemory(handle, false)); | 97 ring_buffer_.reset(new base::SharedMemory(handle, false)); |
| 98 if (ring_buffer_->Map(size)) { | 98 if (ring_buffer_->Map(size)) { |
| 99 num_entries_ = size / sizeof(gpu::CommandBufferEntry); | 99 num_entries_ = size / sizeof(gpu::CommandBufferEntry); |
| 100 return true; | 100 return true; |
| 101 } | 101 } |
| 102 | 102 |
| 103 ring_buffer_.reset(); | 103 ring_buffer_.reset(); |
| 104 } | 104 } |
| 105 | 105 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 119 buffer.size = num_entries_ * sizeof(gpu::CommandBufferEntry); | 119 buffer.size = num_entries_ * sizeof(gpu::CommandBufferEntry); |
| 120 buffer.shared_memory = ring_buffer_.get(); | 120 buffer.shared_memory = ring_buffer_.get(); |
| 121 return buffer; | 121 return buffer; |
| 122 } | 122 } |
| 123 | 123 |
| 124 gpu::CommandBuffer::State CommandBuffer::GetState() { | 124 gpu::CommandBuffer::State CommandBuffer::GetState() { |
| 125 // Send will flag state with lost context if IPC fails. | 125 // Send will flag state with lost context if IPC fails. |
| 126 if (last_state_.error == gpu::error::kNoError) { | 126 if (last_state_.error == gpu::error::kNoError) { |
| 127 gpu::CommandBuffer::State state; | 127 gpu::CommandBuffer::State state; |
| 128 if (Send(new PpapiHostMsg_PPBGraphics3D_GetState( | 128 if (Send(new PpapiHostMsg_PPBGraphics3D_GetState( |
| 129 INTERFACE_ID_PPB_GRAPHICS_3D, resource_, &state))) | 129 API_ID_PPB_GRAPHICS_3D, resource_, &state))) |
| 130 UpdateState(state); | 130 UpdateState(state); |
| 131 } | 131 } |
| 132 | 132 |
| 133 return last_state_; | 133 return last_state_; |
| 134 } | 134 } |
| 135 | 135 |
| 136 gpu::CommandBuffer::State CommandBuffer::GetLastState() { | 136 gpu::CommandBuffer::State CommandBuffer::GetLastState() { |
| 137 return last_state_; | 137 return last_state_; |
| 138 } | 138 } |
| 139 | 139 |
| 140 void CommandBuffer::Flush(int32 put_offset) { | 140 void CommandBuffer::Flush(int32 put_offset) { |
| 141 if (last_state_.error != gpu::error::kNoError) | 141 if (last_state_.error != gpu::error::kNoError) |
| 142 return; | 142 return; |
| 143 | 143 |
| 144 IPC::Message* message = new PpapiHostMsg_PPBGraphics3D_AsyncFlush( | 144 IPC::Message* message = new PpapiHostMsg_PPBGraphics3D_AsyncFlush( |
| 145 INTERFACE_ID_PPB_GRAPHICS_3D, resource_, put_offset); | 145 API_ID_PPB_GRAPHICS_3D, resource_, put_offset); |
| 146 | 146 |
| 147 // Do not let a synchronous flush hold up this message. If this handler is | 147 // Do not let a synchronous flush hold up this message. If this handler is |
| 148 // deferred until after the synchronous flush completes, it will overwrite the | 148 // deferred until after the synchronous flush completes, it will overwrite the |
| 149 // cached last_state_ with out-of-date data. | 149 // cached last_state_ with out-of-date data. |
| 150 message->set_unblock(true); | 150 message->set_unblock(true); |
| 151 Send(message); | 151 Send(message); |
| 152 } | 152 } |
| 153 | 153 |
| 154 gpu::CommandBuffer::State CommandBuffer::FlushSync(int32 put_offset, | 154 gpu::CommandBuffer::State CommandBuffer::FlushSync(int32 put_offset, |
| 155 int32 last_known_get) { | 155 int32 last_known_get) { |
| 156 if (last_known_get == last_state_.get_offset) { | 156 if (last_known_get == last_state_.get_offset) { |
| 157 // Send will flag state with lost context if IPC fails. | 157 // Send will flag state with lost context if IPC fails. |
| 158 if (last_state_.error == gpu::error::kNoError) { | 158 if (last_state_.error == gpu::error::kNoError) { |
| 159 gpu::CommandBuffer::State state; | 159 gpu::CommandBuffer::State state; |
| 160 if (Send(new PpapiHostMsg_PPBGraphics3D_Flush( | 160 if (Send(new PpapiHostMsg_PPBGraphics3D_Flush( |
| 161 INTERFACE_ID_PPB_GRAPHICS_3D, resource_, put_offset, | 161 API_ID_PPB_GRAPHICS_3D, resource_, put_offset, |
| 162 last_known_get, &state))) | 162 last_known_get, &state))) |
| 163 UpdateState(state); | 163 UpdateState(state); |
| 164 } | 164 } |
| 165 } else { | 165 } else { |
| 166 Flush(put_offset); | 166 Flush(put_offset); |
| 167 } | 167 } |
| 168 | 168 |
| 169 return last_state_; | 169 return last_state_; |
| 170 } | 170 } |
| 171 | 171 |
| 172 void CommandBuffer::SetGetOffset(int32 get_offset) { | 172 void CommandBuffer::SetGetOffset(int32 get_offset) { |
| 173 // Not implemented in proxy. | 173 // Not implemented in proxy. |
| 174 NOTREACHED(); | 174 NOTREACHED(); |
| 175 } | 175 } |
| 176 | 176 |
| 177 int32 CommandBuffer::CreateTransferBuffer(size_t size, int32 id_request) { | 177 int32 CommandBuffer::CreateTransferBuffer(size_t size, int32 id_request) { |
| 178 if (last_state_.error == gpu::error::kNoError) { | 178 if (last_state_.error == gpu::error::kNoError) { |
| 179 int32 id; | 179 int32 id; |
| 180 if (Send(new PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer( | 180 if (Send(new PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer( |
| 181 INTERFACE_ID_PPB_GRAPHICS_3D, resource_, size, &id))) { | 181 API_ID_PPB_GRAPHICS_3D, resource_, size, &id))) { |
| 182 return id; | 182 return id; |
| 183 } | 183 } |
| 184 } | 184 } |
| 185 | 185 |
| 186 return -1; | 186 return -1; |
| 187 } | 187 } |
| 188 | 188 |
| 189 int32 CommandBuffer::RegisterTransferBuffer( | 189 int32 CommandBuffer::RegisterTransferBuffer( |
| 190 base::SharedMemory* shared_memory, | 190 base::SharedMemory* shared_memory, |
| 191 size_t size, | 191 size_t size, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 202 // Remove the transfer buffer from the client side4 cache. | 202 // Remove the transfer buffer from the client side4 cache. |
| 203 TransferBufferMap::iterator it = transfer_buffers_.find(id); | 203 TransferBufferMap::iterator it = transfer_buffers_.find(id); |
| 204 DCHECK(it != transfer_buffers_.end()); | 204 DCHECK(it != transfer_buffers_.end()); |
| 205 | 205 |
| 206 // Delete the shared memory object, closing the handle in this process. | 206 // Delete the shared memory object, closing the handle in this process. |
| 207 delete it->second.shared_memory; | 207 delete it->second.shared_memory; |
| 208 | 208 |
| 209 transfer_buffers_.erase(it); | 209 transfer_buffers_.erase(it); |
| 210 | 210 |
| 211 Send(new PpapiHostMsg_PPBGraphics3D_DestroyTransferBuffer( | 211 Send(new PpapiHostMsg_PPBGraphics3D_DestroyTransferBuffer( |
| 212 INTERFACE_ID_PPB_GRAPHICS_3D, resource_, id)); | 212 API_ID_PPB_GRAPHICS_3D, resource_, id)); |
| 213 } | 213 } |
| 214 | 214 |
| 215 gpu::Buffer CommandBuffer::GetTransferBuffer(int32 id) { | 215 gpu::Buffer CommandBuffer::GetTransferBuffer(int32 id) { |
| 216 if (last_state_.error != gpu::error::kNoError) | 216 if (last_state_.error != gpu::error::kNoError) |
| 217 return gpu::Buffer(); | 217 return gpu::Buffer(); |
| 218 | 218 |
| 219 // Check local cache to see if there is already a client side shared memory | 219 // Check local cache to see if there is already a client side shared memory |
| 220 // object for this id. | 220 // object for this id. |
| 221 TransferBufferMap::iterator it = transfer_buffers_.find(id); | 221 TransferBufferMap::iterator it = transfer_buffers_.find(id); |
| 222 if (it != transfer_buffers_.end()) { | 222 if (it != transfer_buffers_.end()) { |
| 223 return it->second; | 223 return it->second; |
| 224 } | 224 } |
| 225 | 225 |
| 226 // Assuming we are in the renderer process, the service is responsible for | 226 // Assuming we are in the renderer process, the service is responsible for |
| 227 // duplicating the handle. This might not be true for NaCl. | 227 // duplicating the handle. This might not be true for NaCl. |
| 228 base::SharedMemoryHandle handle; | 228 base::SharedMemoryHandle handle; |
| 229 uint32 size; | 229 uint32 size; |
| 230 if (!Send(new PpapiHostMsg_PPBGraphics3D_GetTransferBuffer( | 230 if (!Send(new PpapiHostMsg_PPBGraphics3D_GetTransferBuffer( |
| 231 INTERFACE_ID_PPB_GRAPHICS_3D, resource_, id, &handle, &size))) { | 231 API_ID_PPB_GRAPHICS_3D, resource_, id, &handle, &size))) { |
| 232 return gpu::Buffer(); | 232 return gpu::Buffer(); |
| 233 } | 233 } |
| 234 | 234 |
| 235 // Cache the transfer buffer shared memory object client side. | 235 // Cache the transfer buffer shared memory object client side. |
| 236 scoped_ptr<base::SharedMemory> shared_memory( | 236 scoped_ptr<base::SharedMemory> shared_memory( |
| 237 new base::SharedMemory(handle, false)); | 237 new base::SharedMemory(handle, false)); |
| 238 | 238 |
| 239 // Map the shared memory on demand. | 239 // Map the shared memory on demand. |
| 240 if (!shared_memory->memory()) { | 240 if (!shared_memory->memory()) { |
| 241 if (!shared_memory->Map(size)) { | 241 if (!shared_memory->Map(size)) { |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 int32_t last_known_get) { | 376 int32_t last_known_get) { |
| 377 return GetErrorState(); | 377 return GetErrorState(); |
| 378 } | 378 } |
| 379 | 379 |
| 380 gpu::CommandBuffer* Graphics3D::GetCommandBuffer() { | 380 gpu::CommandBuffer* Graphics3D::GetCommandBuffer() { |
| 381 return command_buffer_.get(); | 381 return command_buffer_.get(); |
| 382 } | 382 } |
| 383 | 383 |
| 384 int32 Graphics3D::DoSwapBuffers() { | 384 int32 Graphics3D::DoSwapBuffers() { |
| 385 IPC::Message* msg = new PpapiHostMsg_PPBGraphics3D_SwapBuffers( | 385 IPC::Message* msg = new PpapiHostMsg_PPBGraphics3D_SwapBuffers( |
| 386 INTERFACE_ID_PPB_GRAPHICS_3D, host_resource()); | 386 API_ID_PPB_GRAPHICS_3D, host_resource()); |
| 387 msg->set_unblock(true); | 387 msg->set_unblock(true); |
| 388 PluginDispatcher::GetForResource(this)->Send(msg); | 388 PluginDispatcher::GetForResource(this)->Send(msg); |
| 389 | 389 |
| 390 gles2_impl()->SwapBuffers(); | 390 gles2_impl()->SwapBuffers(); |
| 391 return PP_OK_COMPLETIONPENDING; | 391 return PP_OK_COMPLETIONPENDING; |
| 392 } | 392 } |
| 393 | 393 |
| 394 PPB_Graphics3D_Proxy::PPB_Graphics3D_Proxy(Dispatcher* dispatcher) | 394 PPB_Graphics3D_Proxy::PPB_Graphics3D_Proxy(Dispatcher* dispatcher) |
| 395 : InterfaceProxy(dispatcher), | 395 : InterfaceProxy(dispatcher), |
| 396 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 396 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 419 attr[0] != PP_GRAPHICS3DATTRIB_NONE; | 419 attr[0] != PP_GRAPHICS3DATTRIB_NONE; |
| 420 attr += 2) { | 420 attr += 2) { |
| 421 attribs.push_back(attr[0]); | 421 attribs.push_back(attr[0]); |
| 422 attribs.push_back(attr[1]); | 422 attribs.push_back(attr[1]); |
| 423 } | 423 } |
| 424 } | 424 } |
| 425 attribs.push_back(PP_GRAPHICS3DATTRIB_NONE); | 425 attribs.push_back(PP_GRAPHICS3DATTRIB_NONE); |
| 426 | 426 |
| 427 HostResource result; | 427 HostResource result; |
| 428 dispatcher->Send(new PpapiHostMsg_PPBGraphics3D_Create( | 428 dispatcher->Send(new PpapiHostMsg_PPBGraphics3D_Create( |
| 429 INTERFACE_ID_PPB_GRAPHICS_3D, instance, attribs, &result)); | 429 API_ID_PPB_GRAPHICS_3D, instance, attribs, &result)); |
| 430 if (result.is_null()) | 430 if (result.is_null()) |
| 431 return 0; | 431 return 0; |
| 432 | 432 |
| 433 scoped_refptr<Graphics3D> graphics_3d(new Graphics3D(result)); | 433 scoped_refptr<Graphics3D> graphics_3d(new Graphics3D(result)); |
| 434 if (!graphics_3d->Init()) | 434 if (!graphics_3d->Init()) |
| 435 return 0; | 435 return 0; |
| 436 return graphics_3d->GetReference(); | 436 return graphics_3d->GetReference(); |
| 437 } | 437 } |
| 438 | 438 |
| 439 bool PPB_Graphics3D_Proxy::OnMessageReceived(const IPC::Message& msg) { | 439 bool PPB_Graphics3D_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 int32_t pp_error) { | 577 int32_t pp_error) { |
| 578 EnterPluginFromHostResource<PPB_Graphics3D_API> enter(resource); | 578 EnterPluginFromHostResource<PPB_Graphics3D_API> enter(resource); |
| 579 if (enter.succeeded()) | 579 if (enter.succeeded()) |
| 580 static_cast<Graphics3D*>(enter.object())->SwapBuffersACK(pp_error); | 580 static_cast<Graphics3D*>(enter.object())->SwapBuffersACK(pp_error); |
| 581 } | 581 } |
| 582 | 582 |
| 583 void PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin( | 583 void PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin( |
| 584 int32_t result, | 584 int32_t result, |
| 585 const HostResource& context) { | 585 const HostResource& context) { |
| 586 dispatcher()->Send(new PpapiMsg_PPBGraphics3D_SwapBuffersACK( | 586 dispatcher()->Send(new PpapiMsg_PPBGraphics3D_SwapBuffersACK( |
| 587 INTERFACE_ID_PPB_GRAPHICS_3D, context, result)); | 587 API_ID_PPB_GRAPHICS_3D, context, result)); |
| 588 } | 588 } |
| 589 | 589 |
| 590 } // namespace proxy | 590 } // namespace proxy |
| 591 } // namespace ppapi | 591 } // namespace ppapi |
| 592 | 592 |
| OLD | NEW |