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 "native_client/src/shared/ppapi_proxy/command_buffer_nacl.h" | 5 #include "native_client/src/shared/ppapi_proxy/command_buffer_nacl.h" |
6 | 6 |
7 #include <sys/mman.h> | 7 #include <sys/mman.h> |
8 #include "gpu/command_buffer/common/logging.h" | 8 #include "gpu/command_buffer/common/logging.h" |
9 #include "native_client/src/shared/ppapi_proxy/plugin_globals.h" | 9 #include "native_client/src/shared/ppapi_proxy/plugin_globals.h" |
10 #include "native_client/src/shared/ppapi_proxy/utility.h" | 10 #include "native_client/src/shared/ppapi_proxy/utility.h" |
11 #include "ppapi/c/ppb_core.h" | 11 #include "ppapi/c/ppb_core.h" |
12 | 12 |
13 #include "srpcgen/ppb_rpc.h" | 13 #include "srpcgen/ppb_rpc.h" |
14 | 14 |
15 using ppapi_proxy::DebugPrintf; | 15 using ppapi_proxy::DebugPrintf; |
16 | 16 |
17 CommandBufferNacl::CommandBufferNacl(PP_Resource graphics_3d, | 17 CommandBufferNacl::CommandBufferNacl(PP_Resource graphics_3d, |
18 const PPB_Core* iface_core) | 18 const PPB_Core* iface_core) |
19 : graphics_3d_(graphics_3d), iface_core_(iface_core) { | 19 : graphics_3d_(graphics_3d), iface_core_(iface_core) { |
20 iface_core_->AddRefResource(graphics_3d_); | 20 iface_core_->AddRefResource(graphics_3d_); |
21 } | 21 } |
22 | 22 |
23 CommandBufferNacl::~CommandBufferNacl() { | 23 CommandBufferNacl::~CommandBufferNacl() { |
24 DebugPrintf("CommandBufferNacl::~CommandBufferNacl()\n"); | 24 DebugPrintf("CommandBufferNacl::~CommandBufferNacl()\n"); |
25 iface_core_->ReleaseResource(graphics_3d_); | 25 iface_core_->ReleaseResource(graphics_3d_); |
26 } | 26 } |
27 | 27 |
28 bool CommandBufferNacl::Initialize(int32 size) { | 28 bool CommandBufferNacl::Initialize() { |
29 DebugPrintf("CommandBufferNacl::Initialize\n"); | 29 DebugPrintf("CommandBufferNacl::Initialize\n"); |
30 int32_t success; | 30 int32_t success; |
31 NaClSrpcChannel* channel = ppapi_proxy::GetMainSrpcChannel(); | 31 NaClSrpcChannel* channel = ppapi_proxy::GetMainSrpcChannel(); |
32 NaClSrpcError retval = | 32 NaClSrpcError retval = |
33 PpbGraphics3DRpcClient::PPB_Graphics3DTrusted_InitCommandBuffer( | 33 PpbGraphics3DRpcClient::PPB_Graphics3DTrusted_InitCommandBuffer( |
34 channel, graphics_3d_, size, &success); | 34 channel, graphics_3d_, &success); |
35 DebugPrintf("CommandBufferNaCl::Initialize returned success=%s\n", | 35 DebugPrintf("CommandBufferNaCl::Initialize returned success=%s\n", |
36 (PP_TRUE == success) ? "TRUE" : "FALSE"); | 36 (PP_TRUE == success) ? "TRUE" : "FALSE"); |
37 return NACL_SRPC_RESULT_OK == retval && PP_TRUE == success; | 37 return NACL_SRPC_RESULT_OK == retval && PP_TRUE == success; |
38 } | 38 } |
39 | 39 |
40 gpu::Buffer CommandBufferNacl::GetRingBuffer() { | |
41 DebugPrintf("CommandBufferNacl::GetRingBuffer\n"); | |
42 if (!buffer_.ptr) { | |
43 DebugPrintf("CommandBufferNacl::GetRingBuffer: Fetching\n"); | |
44 int shm_handle = -1; | |
45 int32_t shm_size = 0; | |
46 | |
47 NaClSrpcChannel* channel = ppapi_proxy::GetMainSrpcChannel(); | |
48 NaClSrpcError retval = | |
49 PpbGraphics3DRpcClient::PPB_Graphics3DTrusted_GetRingBuffer( | |
50 channel, graphics_3d_, &shm_handle, &shm_size); | |
51 if (NACL_SRPC_RESULT_OK != retval) { | |
52 shm_handle = -1; | |
53 } | |
54 buffer_ = BufferFromShm(shm_handle, shm_size); | |
55 } | |
56 | |
57 return buffer_; | |
58 } | |
59 | |
60 gpu::CommandBuffer::State CommandBufferNacl::GetState() { | 40 gpu::CommandBuffer::State CommandBufferNacl::GetState() { |
61 DebugPrintf("CommandBufferNacl::GetState\n"); | 41 DebugPrintf("CommandBufferNacl::GetState\n"); |
62 PP_Graphics3DTrustedState state; | 42 PP_Graphics3DTrustedState state; |
63 nacl_abi_size_t state_size = static_cast<nacl_abi_size_t>(sizeof(state)); | 43 nacl_abi_size_t state_size = static_cast<nacl_abi_size_t>(sizeof(state)); |
64 | 44 |
65 NaClSrpcChannel* channel = ppapi_proxy::GetMainSrpcChannel(); | 45 NaClSrpcChannel* channel = ppapi_proxy::GetMainSrpcChannel(); |
66 NaClSrpcError retval = | 46 NaClSrpcError retval = |
67 PpbGraphics3DRpcClient::PPB_Graphics3DTrusted_GetState( | 47 PpbGraphics3DRpcClient::PPB_Graphics3DTrusted_GetState( |
68 channel, graphics_3d_, &state_size, reinterpret_cast<char*>(&state)); | 48 channel, graphics_3d_, &state_size, reinterpret_cast<char*>(&state)); |
69 if (NACL_SRPC_RESULT_OK != retval | 49 if (NACL_SRPC_RESULT_OK != retval |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 reinterpret_cast<char*>(&state)); | 83 reinterpret_cast<char*>(&state)); |
104 if (NACL_SRPC_RESULT_OK != retval | 84 if (NACL_SRPC_RESULT_OK != retval |
105 || state_size != static_cast<nacl_abi_size_t>(sizeof(state))) { | 85 || state_size != static_cast<nacl_abi_size_t>(sizeof(state))) { |
106 return ErrorGpuState(); | 86 return ErrorGpuState(); |
107 } | 87 } |
108 | 88 |
109 last_state_ = PpapiToGpuState(state); | 89 last_state_ = PpapiToGpuState(state); |
110 return last_state_; | 90 return last_state_; |
111 } | 91 } |
112 | 92 |
| 93 void CommandBufferNacl::SetGetBuffer(int32 transfer_buffer_id) { |
| 94 DebugPrintf("CommandBufferNacl::SetGetBuffer\n"); |
| 95 NaClSrpcChannel* channel = ppapi_proxy::GetMainSrpcChannel(); |
| 96 PpbGraphics3DRpcClient::PPB_Graphics3DTrusted_SetGetBuffer( |
| 97 channel, graphics_3d_, transfer_buffer_id); |
| 98 } |
| 99 |
113 void CommandBufferNacl::SetGetOffset(int32 get_offset) { | 100 void CommandBufferNacl::SetGetOffset(int32 get_offset) { |
114 DebugPrintf("CommandBufferNacl::SetGetOffset\n"); | 101 DebugPrintf("CommandBufferNacl::SetGetOffset\n"); |
115 // Not implemented by proxy. | 102 // Not implemented by proxy. |
116 GPU_NOTREACHED(); | 103 GPU_NOTREACHED(); |
117 } | 104 } |
118 | 105 |
119 int32 CommandBufferNacl::CreateTransferBuffer(size_t size, int32 id_request) { | 106 int32 CommandBufferNacl::CreateTransferBuffer(size_t size, int32 id_request) { |
120 DebugPrintf("CommandBufferNacl::CreateTransferBuffer\n"); | 107 DebugPrintf("CommandBufferNacl::CreateTransferBuffer\n"); |
121 int32_t id; | 108 int32_t id; |
122 | 109 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 gpu::CommandBuffer::State CommandBufferNacl::PpapiToGpuState( | 185 gpu::CommandBuffer::State CommandBufferNacl::PpapiToGpuState( |
199 PP_Graphics3DTrustedState s) { | 186 PP_Graphics3DTrustedState s) { |
200 gpu::CommandBuffer::State state; | 187 gpu::CommandBuffer::State state; |
201 state.num_entries = s.num_entries; | 188 state.num_entries = s.num_entries; |
202 state.get_offset = s.get_offset; | 189 state.get_offset = s.get_offset; |
203 state.put_offset = s.put_offset; | 190 state.put_offset = s.put_offset; |
204 state.token = s.token; | 191 state.token = s.token; |
205 state.error = static_cast<gpu::error::Error>(s.error); | 192 state.error = static_cast<gpu::error::Error>(s.error); |
206 return state; | 193 return state; |
207 } | 194 } |
OLD | NEW |