Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(565)

Side by Side Diff: ppapi/proxy/ppb_graphics_3d_proxy.cc

Issue 8566059: Add CommandBuffer::SetGetBuffer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: etc Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 13 matching lines...) Expand all
24 namespace { 24 namespace {
25 const int32 kCommandBufferSize = 1024 * 1024; 25 const int32 kCommandBufferSize = 1024 * 1024;
26 const int32 kTransferBufferSize = 1024 * 1024; 26 const int32 kTransferBufferSize = 1024 * 1024;
27 27
28 class CommandBuffer : public gpu::CommandBuffer { 28 class CommandBuffer : public gpu::CommandBuffer {
29 public: 29 public:
30 CommandBuffer(const HostResource& resource, PluginDispatcher* dispatcher); 30 CommandBuffer(const HostResource& resource, PluginDispatcher* dispatcher);
31 virtual ~CommandBuffer(); 31 virtual ~CommandBuffer();
32 32
33 // gpu::CommandBuffer implementation: 33 // gpu::CommandBuffer implementation:
34 virtual bool Initialize(int32 size); 34 virtual bool Initialize();
35 virtual bool Initialize(base::SharedMemory* buffer, int32 size);
36 virtual gpu::Buffer GetRingBuffer();
37 virtual State GetState(); 35 virtual State GetState();
38 virtual State GetLastState(); 36 virtual State GetLastState();
39 virtual void Flush(int32 put_offset); 37 virtual void Flush(int32 put_offset);
40 virtual State FlushSync(int32 put_offset, int32 last_known_get); 38 virtual State FlushSync(int32 put_offset, int32 last_known_get);
39 virtual void SetGetBuffer(int32 shm_id);
41 virtual void SetGetOffset(int32 get_offset); 40 virtual void SetGetOffset(int32 get_offset);
42 virtual int32 CreateTransferBuffer(size_t size, int32 id_request); 41 virtual int32 CreateTransferBuffer(size_t size, int32 id_request);
43 virtual int32 RegisterTransferBuffer(base::SharedMemory* shared_memory, 42 virtual int32 RegisterTransferBuffer(base::SharedMemory* shared_memory,
44 size_t size, 43 size_t size,
45 int32 id_request); 44 int32 id_request);
46 virtual void DestroyTransferBuffer(int32 id); 45 virtual void DestroyTransferBuffer(int32 id);
47 virtual gpu::Buffer GetTransferBuffer(int32 handle); 46 virtual gpu::Buffer GetTransferBuffer(int32 handle);
48 virtual void SetToken(int32 token); 47 virtual void SetToken(int32 token);
49 virtual void SetParseError(gpu::error::Error error); 48 virtual void SetParseError(gpu::error::Error error);
50 virtual void SetContextLostReason(gpu::error::ContextLostReason reason); 49 virtual void SetContextLostReason(gpu::error::ContextLostReason reason);
51 50
52 private: 51 private:
53 bool Send(IPC::Message* msg); 52 bool Send(IPC::Message* msg);
54 void UpdateState(const gpu::CommandBuffer::State& state); 53 void UpdateState(const gpu::CommandBuffer::State& state);
55 54
56 int32 num_entries_;
57 scoped_ptr<base::SharedMemory> ring_buffer_;
58
59 typedef base::hash_map<int32, gpu::Buffer> TransferBufferMap; 55 typedef base::hash_map<int32, gpu::Buffer> TransferBufferMap;
60 TransferBufferMap transfer_buffers_; 56 TransferBufferMap transfer_buffers_;
61 57
62 State last_state_; 58 State last_state_;
63 59
64 HostResource resource_; 60 HostResource resource_;
65 PluginDispatcher* dispatcher_; 61 PluginDispatcher* dispatcher_;
66 62
67 DISALLOW_COPY_AND_ASSIGN(CommandBuffer); 63 DISALLOW_COPY_AND_ASSIGN(CommandBuffer);
68 }; 64 };
69 65
70 CommandBuffer::CommandBuffer(const HostResource& resource, 66 CommandBuffer::CommandBuffer(const HostResource& resource,
71 PluginDispatcher* dispatcher) 67 PluginDispatcher* dispatcher)
72 : num_entries_(0), 68 : resource_(resource),
73 resource_(resource),
74 dispatcher_(dispatcher) { 69 dispatcher_(dispatcher) {
75 } 70 }
76 71
77 CommandBuffer::~CommandBuffer() { 72 CommandBuffer::~CommandBuffer() {
78 // Delete all the locally cached shared memory objects, closing the handle 73 // Delete all the locally cached shared memory objects, closing the handle
79 // in this process. 74 // in this process.
80 for (TransferBufferMap::iterator it = transfer_buffers_.begin(); 75 for (TransferBufferMap::iterator it = transfer_buffers_.begin();
81 it != transfer_buffers_.end(); ++it) { 76 it != transfer_buffers_.end(); ++it) {
82 delete it->second.shared_memory; 77 delete it->second.shared_memory;
83 it->second.shared_memory = NULL; 78 it->second.shared_memory = NULL;
84 } 79 }
85 } 80 }
86 81
87 bool CommandBuffer::Initialize(int32 size) { 82 bool CommandBuffer::Initialize() {
88 DCHECK(!ring_buffer_.get()); 83 return Send(new PpapiHostMsg_PPBGraphics3D_InitCommandBuffer(
89 84 API_ID_PPB_GRAPHICS_3D, resource_));
90 // Initialize the service. Assuming we are sandboxed, the GPU
91 // process is responsible for duplicating the handle. This might not be true
92 // for NaCl.
93 base::SharedMemoryHandle handle;
94 if (Send(new PpapiHostMsg_PPBGraphics3D_InitCommandBuffer(
95 API_ID_PPB_GRAPHICS_3D, resource_, size, &handle)) &&
96 base::SharedMemory::IsHandleValid(handle)) {
97 ring_buffer_.reset(new base::SharedMemory(handle, false));
98 if (ring_buffer_->Map(size)) {
99 num_entries_ = size / sizeof(gpu::CommandBufferEntry);
100 return true;
101 }
102
103 ring_buffer_.reset();
104 }
105
106 return false;
107 }
108
109 bool CommandBuffer::Initialize(base::SharedMemory* buffer, int32 size) {
110 // Not implemented in proxy.
111 NOTREACHED();
112 return false;
113 }
114
115 gpu::Buffer CommandBuffer::GetRingBuffer() {
116 // Return locally cached ring buffer.
117 gpu::Buffer buffer;
118 buffer.ptr = ring_buffer_->memory();
119 buffer.size = num_entries_ * sizeof(gpu::CommandBufferEntry);
120 buffer.shared_memory = ring_buffer_.get();
121 return buffer;
122 } 85 }
123 86
124 gpu::CommandBuffer::State CommandBuffer::GetState() { 87 gpu::CommandBuffer::State CommandBuffer::GetState() {
125 // Send will flag state with lost context if IPC fails. 88 // Send will flag state with lost context if IPC fails.
126 if (last_state_.error == gpu::error::kNoError) { 89 if (last_state_.error == gpu::error::kNoError) {
127 gpu::CommandBuffer::State state; 90 gpu::CommandBuffer::State state;
128 if (Send(new PpapiHostMsg_PPBGraphics3D_GetState( 91 if (Send(new PpapiHostMsg_PPBGraphics3D_GetState(
129 API_ID_PPB_GRAPHICS_3D, resource_, &state))) 92 API_ID_PPB_GRAPHICS_3D, resource_, &state)))
130 UpdateState(state); 93 UpdateState(state);
131 } 94 }
(...skipping 30 matching lines...) Expand all
162 last_known_get, &state))) 125 last_known_get, &state)))
163 UpdateState(state); 126 UpdateState(state);
164 } 127 }
165 } else { 128 } else {
166 Flush(put_offset); 129 Flush(put_offset);
167 } 130 }
168 131
169 return last_state_; 132 return last_state_;
170 } 133 }
171 134
135 void CommandBuffer::SetGetBuffer(int32 shm_id) {
136 if (last_state_.error == gpu::error::kNoError) {
137 Send(new PpapiHostMsg_PPBGraphics3D_SetGetBuffer(
138 API_ID_PPB_GRAPHICS_3D, resource_, shm_id));
139 }
140 }
141
172 void CommandBuffer::SetGetOffset(int32 get_offset) { 142 void CommandBuffer::SetGetOffset(int32 get_offset) {
173 // Not implemented in proxy. 143 // Not implemented in proxy.
174 NOTREACHED(); 144 NOTREACHED();
175 } 145 }
176 146
177 int32 CommandBuffer::CreateTransferBuffer(size_t size, int32 id_request) { 147 int32 CommandBuffer::CreateTransferBuffer(size_t size, int32 id_request) {
178 if (last_state_.error == gpu::error::kNoError) { 148 if (last_state_.error == gpu::error::kNoError) {
179 int32 id; 149 int32 id;
180 if (Send(new PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer( 150 if (Send(new PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer(
181 API_ID_PPB_GRAPHICS_3D, resource_, size, &id))) { 151 API_ID_PPB_GRAPHICS_3D, resource_, size, &id))) {
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 Graphics3D::~Graphics3D() { 295 Graphics3D::~Graphics3D() {
326 DestroyGLES2Impl(); 296 DestroyGLES2Impl();
327 } 297 }
328 298
329 bool Graphics3D::Init() { 299 bool Graphics3D::Init() {
330 PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(this); 300 PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(this);
331 if (!dispatcher) 301 if (!dispatcher)
332 return false; 302 return false;
333 303
334 command_buffer_.reset(new CommandBuffer(host_resource(), dispatcher)); 304 command_buffer_.reset(new CommandBuffer(host_resource(), dispatcher));
335 if (!command_buffer_->Initialize(kCommandBufferSize)) 305 if (!command_buffer_->Initialize())
336 return false; 306 return false;
337 307
338 return CreateGLES2Impl(kCommandBufferSize, kTransferBufferSize); 308 return CreateGLES2Impl(kCommandBufferSize, kTransferBufferSize);
339 } 309 }
340 310
341 PP_Bool Graphics3D::InitCommandBuffer(int32_t size) { 311 PP_Bool Graphics3D::InitCommandBuffer() {
342 return PP_FALSE; 312 return PP_FALSE;
343 } 313 }
344 314
345 PP_Bool Graphics3D::GetRingBuffer(int* shm_handle, uint32_t* shm_size) { 315 PP_Bool Graphics3D::SetGetBuffer(int32_t /* shm_id */) {
346 return PP_FALSE; 316 return PP_FALSE;
347 } 317 }
348 318
349 PP_Graphics3DTrustedState Graphics3D::GetState() { 319 PP_Graphics3DTrustedState Graphics3D::GetState() {
350 return GetErrorState(); 320 return GetErrorState();
351 } 321 }
352 322
353 PP_Bool Graphics3D::Flush(int32_t put_offset) { 323 PP_Bool Graphics3D::Flush(int32_t put_offset) {
354 return PP_FALSE; 324 return PP_FALSE;
355 } 325 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 return graphics_3d->GetReference(); 406 return graphics_3d->GetReference();
437 } 407 }
438 408
439 bool PPB_Graphics3D_Proxy::OnMessageReceived(const IPC::Message& msg) { 409 bool PPB_Graphics3D_Proxy::OnMessageReceived(const IPC::Message& msg) {
440 bool handled = true; 410 bool handled = true;
441 IPC_BEGIN_MESSAGE_MAP(PPB_Graphics3D_Proxy, msg) 411 IPC_BEGIN_MESSAGE_MAP(PPB_Graphics3D_Proxy, msg)
442 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_Create, 412 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_Create,
443 OnMsgCreate) 413 OnMsgCreate)
444 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_InitCommandBuffer, 414 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_InitCommandBuffer,
445 OnMsgInitCommandBuffer) 415 OnMsgInitCommandBuffer)
416 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_SetGetBuffer,
417 OnMsgSetGetBuffer)
446 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_GetState, 418 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_GetState,
447 OnMsgGetState) 419 OnMsgGetState)
448 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_Flush, 420 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_Flush,
449 OnMsgFlush) 421 OnMsgFlush)
450 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_AsyncFlush, 422 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_AsyncFlush,
451 OnMsgAsyncFlush) 423 OnMsgAsyncFlush)
452 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer, 424 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer,
453 OnMsgCreateTransferBuffer) 425 OnMsgCreateTransferBuffer)
454 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_DestroyTransferBuffer, 426 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_DestroyTransferBuffer,
455 OnMsgDestroyTransferBuffer) 427 OnMsgDestroyTransferBuffer)
(...skipping 19 matching lines...) Expand all
475 447
476 thunk::EnterResourceCreation enter(instance); 448 thunk::EnterResourceCreation enter(instance);
477 if (enter.succeeded()) { 449 if (enter.succeeded()) {
478 result->SetHostResource( 450 result->SetHostResource(
479 instance, 451 instance,
480 enter.functions()->CreateGraphics3DRaw(instance, 0, &attribs.front())); 452 enter.functions()->CreateGraphics3DRaw(instance, 0, &attribs.front()));
481 } 453 }
482 } 454 }
483 455
484 void PPB_Graphics3D_Proxy::OnMsgInitCommandBuffer( 456 void PPB_Graphics3D_Proxy::OnMsgInitCommandBuffer(
485 const HostResource& context, 457 const HostResource& context) {
486 int32 size,
487 base::SharedMemoryHandle* ring_buffer) {
488 *ring_buffer = base::SharedMemory::NULLHandle();
489 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); 458 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
490 if (enter.failed()) 459 if (enter.failed())
491 return; 460 return;
492 461
493 if (!enter.object()->InitCommandBuffer(size)) 462 if (!enter.object()->InitCommandBuffer())
494 return; 463 return;
464 }
495 465
496 int shm_handle; 466 void PPB_Graphics3D_Proxy::OnMsgSetGetBuffer(
497 uint32_t shm_size; 467 const HostResource& context,
498 if (!enter.object()->GetRingBuffer(&shm_handle, &shm_size)) 468 int32 shm_id) {
499 return; 469 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
500 *ring_buffer = TransportSHMHandleFromInt(dispatcher(), shm_handle); 470 if (enter.succeeded())
471 enter.object()->SetGetBuffer(shm_id);
501 } 472 }
502 473
503 void PPB_Graphics3D_Proxy::OnMsgGetState(const HostResource& context, 474 void PPB_Graphics3D_Proxy::OnMsgGetState(const HostResource& context,
504 gpu::CommandBuffer::State* state) { 475 gpu::CommandBuffer::State* state) {
505 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); 476 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
506 if (enter.failed()) 477 if (enter.failed())
507 return; 478 return;
508 PP_Graphics3DTrustedState pp_state = enter.object()->GetState(); 479 PP_Graphics3DTrustedState pp_state = enter.object()->GetState();
509 *state = GPUStateFromPPState(pp_state); 480 *state = GPUStateFromPPState(pp_state);
510 } 481 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 void PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin( 554 void PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin(
584 int32_t result, 555 int32_t result,
585 const HostResource& context) { 556 const HostResource& context) {
586 dispatcher()->Send(new PpapiMsg_PPBGraphics3D_SwapBuffersACK( 557 dispatcher()->Send(new PpapiMsg_PPBGraphics3D_SwapBuffersACK(
587 API_ID_PPB_GRAPHICS_3D, context, result)); 558 API_ID_PPB_GRAPHICS_3D, context, result));
588 } 559 }
589 560
590 } // namespace proxy 561 } // namespace proxy
591 } // namespace ppapi 562 } // namespace ppapi
592 563
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698