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

Side by Side Diff: ppapi/native_client/src/shared/ppapi_proxy/command_buffer_nacl.cc

Issue 7740013: Cloning a bunch of stuff from the native_client repository at r6528 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 4 months 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
(Empty)
1 // Copyright (c) 2011 The Native Client Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "native_client/src/shared/ppapi_proxy/command_buffer_nacl.h"
6
7 #include <sys/mman.h>
8 #include "gpu/command_buffer/common/logging.h"
9 #include "native_client/src/shared/ppapi_proxy/plugin_globals.h"
10 #include "native_client/src/shared/ppapi_proxy/utility.h"
11 #include "ppapi/c/ppb_core.h"
12
13 #include "srpcgen/ppb_rpc.h"
14
15 using ppapi_proxy::DebugPrintf;
16
17 CommandBufferNacl::CommandBufferNacl(PP_Resource graphics_3d,
18 const PPB_Core* iface_core)
19 : graphics_3d_(graphics_3d), iface_core_(iface_core) {
20 iface_core_->AddRefResource(graphics_3d_);
21 }
22
23 CommandBufferNacl::~CommandBufferNacl() {
24 iface_core_->ReleaseResource(graphics_3d_);
25 }
26
27 bool CommandBufferNacl::Initialize(int32 size) {
28 DebugPrintf("CommandBufferNacl::Initialize\n");
29 int32_t success;
30 NaClSrpcChannel* channel = ppapi_proxy::GetMainSrpcChannel();
31 NaClSrpcError retval =
32 PpbGraphics3DRpcClient::PPB_Graphics3DTrusted_InitCommandBuffer(
33 channel, graphics_3d_, size, &success);
34 DebugPrintf("CommandBufferNaCl::Initialize returned success=%s\n",
35 (PP_TRUE == success) ? "TRUE" : "FALSE");
36 return NACL_SRPC_RESULT_OK == retval && PP_TRUE == success;
37 }
38
39 gpu::Buffer CommandBufferNacl::GetRingBuffer() {
40 DebugPrintf("CommandBufferNacl::GetRingBuffer\n");
41 if (!buffer_.ptr) {
42 DebugPrintf("CommandBufferNacl::GetRingBuffer: Fetching\n");
43 int shm_handle = -1;
44 int32_t shm_size = 0;
45
46 NaClSrpcChannel* channel = ppapi_proxy::GetMainSrpcChannel();
47 NaClSrpcError retval =
48 PpbGraphics3DRpcClient::PPB_Graphics3DTrusted_GetRingBuffer(
49 channel, graphics_3d_, &shm_handle, &shm_size);
50 if (NACL_SRPC_RESULT_OK != retval) {
51 shm_handle = -1;
52 }
53 buffer_ = BufferFromShm(shm_handle, shm_size);
54 }
55
56 return buffer_;
57 }
58
59 gpu::CommandBuffer::State CommandBufferNacl::GetState() {
60 DebugPrintf("CommandBufferNacl::GetState\n");
61 PP_Graphics3DTrustedState state;
62 nacl_abi_size_t state_size = static_cast<nacl_abi_size_t>(sizeof(state));
63
64 NaClSrpcChannel* channel = ppapi_proxy::GetMainSrpcChannel();
65 NaClSrpcError retval =
66 PpbGraphics3DRpcClient::PPB_Graphics3DTrusted_GetState(
67 channel, graphics_3d_, &state_size, reinterpret_cast<char*>(&state));
68 if (NACL_SRPC_RESULT_OK != retval
69 || state_size != static_cast<nacl_abi_size_t>(sizeof(state))) {
70 return ErrorGpuState();
71 }
72
73 last_state_ = PpapiToGpuState(state);
74 return last_state_;
75 }
76
77 gpu::CommandBuffer::State CommandBufferNacl::GetLastState() {
78 return last_state_;
79 }
80
81 void CommandBufferNacl::Flush(int32 put_offset) {
82 DebugPrintf("CommandBufferNacl::Flush\n");
83 NaClSrpcChannel* channel = ppapi_proxy::GetMainSrpcChannel();
84 PpbGraphics3DRpcClient::PPB_Graphics3DTrusted_Flush(
85 channel, graphics_3d_, put_offset);
86 }
87
88 gpu::CommandBuffer::State CommandBufferNacl::FlushSync(int32 put_offset,
89 int32 last_known_get) {
90 DebugPrintf("CommandBufferNacl::FlushSync\n");
91 PP_Graphics3DTrustedState state;
92 nacl_abi_size_t state_size = static_cast<nacl_abi_size_t>(sizeof(state));
93
94 NaClSrpcChannel* channel = ppapi_proxy::GetMainSrpcChannel();
95 NaClSrpcError retval =
96 PpbGraphics3DRpcClient::PPB_Graphics3DTrusted_FlushSync(
97 channel,
98 graphics_3d_,
99 put_offset,
100 &state_size,
101 reinterpret_cast<char*>(&state));
102 if (NACL_SRPC_RESULT_OK != retval
103 || state_size != static_cast<nacl_abi_size_t>(sizeof(state))) {
104 return ErrorGpuState();
105 }
106
107 last_state_ = PpapiToGpuState(state);
108 return last_state_;
109 }
110
111 void CommandBufferNacl::SetGetOffset(int32 get_offset) {
112 DebugPrintf("CommandBufferNacl::SetGetOffset\n");
113 // Not implemented by proxy.
114 GPU_NOTREACHED();
115 }
116
117 int32 CommandBufferNacl::CreateTransferBuffer(size_t size, int32 id_request) {
118 DebugPrintf("CommandBufferNacl::CreateTransferBuffer\n");
119 int32_t id;
120
121 NaClSrpcChannel* channel = ppapi_proxy::GetMainSrpcChannel();
122 NaClSrpcError retval =
123 PpbGraphics3DRpcClient::PPB_Graphics3DTrusted_CreateTransferBuffer(
124 channel, graphics_3d_, size, id_request, &id);
125 if (NACL_SRPC_RESULT_OK != retval)
126 return 0;
127
128 return id;
129 }
130
131 void CommandBufferNacl::DestroyTransferBuffer(int32 id) {
132 DebugPrintf("CommandBufferNacl::DestroyTransferBuffer\n");
133 NaClSrpcChannel* channel = ppapi_proxy::GetMainSrpcChannel();
134 PpbGraphics3DRpcClient::PPB_Graphics3DTrusted_DestroyTransferBuffer(
135 channel, graphics_3d_, id);
136 }
137
138 gpu::Buffer CommandBufferNacl::GetTransferBuffer(int32 id) {
139 DebugPrintf("CommandBufferNacl::GetTransferBuffer\n");
140 int shm_handle;
141 int32_t shm_size;
142
143 NaClSrpcChannel* channel = ppapi_proxy::GetMainSrpcChannel();
144 NaClSrpcError retval =
145 PpbGraphics3DRpcClient::PPB_Graphics3DTrusted_GetTransferBuffer(
146 channel, graphics_3d_, id, &shm_handle, &shm_size);
147 if (NACL_SRPC_RESULT_OK != retval) {
148 return BufferFromShm(-1, 0);
149 }
150 return BufferFromShm(shm_handle, shm_size);
151 }
152
153 void CommandBufferNacl::SetToken(int32 token) {
154 DebugPrintf("CommandBufferNacl::SetToken\n");
155 // Not implemented by proxy.
156 GPU_NOTREACHED();
157 }
158
159 void CommandBufferNacl::SetParseError(
160 gpu::error::Error error) {
161 DebugPrintf("CommandBufferNacl::SetParseError\n");
162 // Not implemented by proxy.
163 GPU_NOTREACHED();
164 }
165
166 void CommandBufferNacl::SetContextLostReason(gpu::error::ContextLostReason) {
167 // Not implemented by proxy.
168 GPU_NOTREACHED();
169 }
170
171 // static
172 gpu::Buffer CommandBufferNacl::BufferFromShm(int shm_handle,
173 uint32_t shm_size) {
174 gpu::Buffer buffer;
175 buffer.ptr = mmap(0,
176 shm_size,
177 PROT_READ | PROT_WRITE,
178 MAP_SHARED,
179 shm_handle,
180 0);
181 // TODO(neb): Close the fd now that it's mapped.
182 // TODO(neb): Unmap ring & transfer buffers in the destructor.
183 if (NULL != buffer.ptr)
184 buffer.size = shm_size;
185 return buffer;
186 }
187
188 // static
189 gpu::CommandBuffer::State CommandBufferNacl::ErrorGpuState() {
190 gpu::CommandBuffer::State state;
191 state.error = gpu::error::kGenericError;
192 return state;
193 }
194
195 // static
196 gpu::CommandBuffer::State CommandBufferNacl::PpapiToGpuState(
197 PP_Graphics3DTrustedState s) {
198 gpu::CommandBuffer::State state;
199 state.num_entries = s.num_entries;
200 state.get_offset = s.get_offset;
201 state.put_offset = s.put_offset;
202 state.token = s.token;
203 state.error = static_cast<gpu::error::Error>(s.error);
204 return state;
205 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698