Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 // SRPC-abstraction wrappers around PPB_Graphics3D functions. | |
| 6 | |
| 7 #include <limits> | |
| 8 | |
| 9 #include "native_client/src/include/nacl_scoped_ptr.h" | |
| 10 #include "native_client/src/include/portability.h" | |
| 11 #include "native_client/src/shared/ppapi_proxy/browser_callback.h" | |
| 12 #include "native_client/src/shared/ppapi_proxy/browser_globals.h" | |
| 13 #include "native_client/src/shared/ppapi_proxy/object_serialize.h" | |
| 14 #include "native_client/src/shared/ppapi_proxy/plugin_resource.h" | |
| 15 #include "native_client/src/shared/ppapi_proxy/utility.h" | |
| 16 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" | |
| 17 #include "native_client/src/third_party/ppapi/c/dev/pp_graphics_3d_dev.h" | |
| 18 #include "native_client/src/third_party/ppapi/c/dev/ppb_graphics_3d_dev.h" | |
| 19 #include "native_client/src/third_party/ppapi/c/dev/ppb_graphics_3d_trusted_dev. h" | |
| 20 #include "native_client/src/third_party/ppapi/c/pp_errors.h" | |
| 21 #include "srpcgen/ppb_rpc.h" | |
| 22 | |
| 23 using ppapi_proxy::DebugPrintf; | |
| 24 using ppapi_proxy::SerializeTo; | |
| 25 | |
| 26 namespace { | |
| 27 | |
| 28 const int32_t kMaxAllowedBufferSize = 16777216; | |
| 29 | |
| 30 /// Check that the attribute list is well formed. | |
| 31 bool ValidateAttribList(nacl_abi_size_t attrib_list_count, | |
| 32 int32_t* attrib_list) { | |
| 33 DebugPrintf("ValidateAttribList: count = %d, ptr_null = %d\n", | |
| 34 (int) attrib_list_count, attrib_list == NULL ? 1 : 0); | |
|
sehr (please use chromium)
2011/08/17 20:44:36
(attrib_list == NULL) ? 1 : 0
here and below.
nfullagar
2011/08/18 00:23:57
Done.
| |
| 35 // Zero count lists are ok. | |
| 36 if (attrib_list_count == 0) | |
| 37 return true; | |
| 38 // NULL lists w/ a non-zero count are not allowed. | |
| 39 if (attrib_list == NULL) | |
| 40 return false; | |
| 41 // Must be an odd count, and the last item must be the terminator. | |
| 42 return (attrib_list_count & 1) && | |
| 43 (attrib_list[attrib_list_count - 1] == PP_GRAPHICS3DATTRIB_NONE); | |
| 44 } | |
| 45 | |
| 46 /// Check that the attribute list is well formed, then copy to output. | |
| 47 bool ValidateAndCopyAttribList(nacl_abi_size_t in_attrib_list_count, | |
| 48 int32_t* in_attrib_list, | |
| 49 nacl_abi_size_t* out_attrib_list_count, | |
| 50 int32_t* out_attrib_list) { | |
| 51 | |
| 52 DebugPrintf("ValidateAndCopyAttribList: in_count = %d, in_ptr_null = %d\n", | |
| 53 (int) in_attrib_list_count, in_attrib_list == NULL ? 1 : 0); | |
| 54 DebugPrintf(" out_count = %d, out_ptr_null = %d\n", | |
| 55 (int) *out_attrib_list_count, out_attrib_list == NULL ? 1 : 0); | |
| 56 | |
| 57 // Attrib lists can both be NULL w/ 0 count. | |
| 58 if ((in_attrib_list == NULL) && (out_attrib_list == NULL)) | |
| 59 return (in_attrib_list_count == 0) && (*out_attrib_list_count == 0); | |
| 60 // Don't allow only one list to be NULL. | |
| 61 if ((in_attrib_list == NULL) || (out_attrib_list == NULL)) | |
| 62 return false; | |
| 63 // Input and output lists must be the same size. | |
| 64 if (in_attrib_list_count != *out_attrib_list_count) | |
| 65 return false; | |
| 66 // Make sure input list is well formed. | |
| 67 if (!ValidateAttribList(in_attrib_list_count, in_attrib_list)) | |
| 68 return false; | |
| 69 // Copy input list to output list. | |
| 70 for (nacl_abi_size_t i = 0; i < in_attrib_list_count; ++i) | |
| 71 out_attrib_list[i] = in_attrib_list[i]; | |
| 72 return true; | |
| 73 } | |
| 74 | |
| 75 } // namespace | |
| 76 | |
| 77 //@{ | |
| 78 /// The following methods are SRPC dispatchers for ppapi/c/ppb_graphics_3d.h. | |
| 79 | |
| 80 void PpbGraphics3DRpcServer::PPB_Graphics3D_Create( | |
| 81 NaClSrpcRpc* rpc, | |
| 82 NaClSrpcClosure* done, | |
| 83 PP_Instance instance, | |
| 84 PP_Resource share_context, | |
| 85 nacl_abi_size_t num_attrib_list, int32_t* attrib_list, | |
| 86 PP_Resource* graphics3d_id) { | |
| 87 DebugPrintf("PpbGraphics3DRpcServer::PPB_Graphics3D_Create(...)\n"); | |
| 88 NaClSrpcClosureRunner runner(done); | |
| 89 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | |
| 90 if (!ValidateAttribList(num_attrib_list, attrib_list)) | |
| 91 return; | |
| 92 *graphics3d_id = ppapi_proxy::PPBGraphics3DInterface()->Create( | |
| 93 instance, share_context, attrib_list); | |
| 94 rpc->result = NACL_SRPC_RESULT_OK; | |
| 95 } | |
| 96 | |
| 97 void PpbGraphics3DRpcServer::PPB_Graphics3D_GetAttribs( | |
| 98 NaClSrpcRpc* rpc, | |
| 99 NaClSrpcClosure* done, | |
| 100 PP_Resource graphics3d_id, | |
| 101 nacl_abi_size_t in_attrib_list_count, int32_t* in_attrib_list, | |
| 102 nacl_abi_size_t* out_attrib_list_count, int32_t* out_attrib_list, | |
| 103 int32_t* pp_error) { | |
| 104 DebugPrintf("PpbGraphics3DRpcServer::PPB_Graphics3D_GetAttrib(...)\n"); | |
| 105 NaClSrpcClosureRunner runner(done); | |
| 106 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | |
| 107 if (!ValidateAndCopyAttribList(in_attrib_list_count, in_attrib_list, | |
| 108 out_attrib_list_count, out_attrib_list)) | |
| 109 return; | |
| 110 *pp_error = ppapi_proxy::PPBGraphics3DInterface()->GetAttribs( | |
| 111 graphics3d_id, out_attrib_list); | |
| 112 rpc->result = NACL_SRPC_RESULT_OK; | |
| 113 } | |
| 114 | |
| 115 void PpbGraphics3DRpcServer::PPB_Graphics3D_SetAttribs( | |
| 116 NaClSrpcRpc* rpc, | |
| 117 NaClSrpcClosure* done, | |
| 118 PP_Resource graphics3d_id, | |
| 119 nacl_abi_size_t attrib_list_count, int32_t* attrib_list, | |
| 120 int32_t* pp_error) { | |
| 121 DebugPrintf("PpbGraphics3DRpcServer::PPB_Graphics3D_SetAttrib(...)\n"); | |
| 122 NaClSrpcClosureRunner runner(done); | |
| 123 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | |
| 124 if (!ValidateAttribList(attrib_list_count, attrib_list)) | |
| 125 return; | |
| 126 *pp_error = ppapi_proxy::PPBGraphics3DInterface()->SetAttribs( | |
| 127 graphics3d_id, attrib_list); | |
| 128 rpc->result = NACL_SRPC_RESULT_OK; | |
| 129 } | |
| 130 | |
| 131 void PpbGraphics3DRpcServer::PPB_Graphics3D_ResizeBuffers( | |
| 132 NaClSrpcRpc* rpc, | |
| 133 NaClSrpcClosure* done, | |
| 134 PP_Resource graphics3d_id, | |
| 135 int32_t width, | |
| 136 int32_t height, | |
| 137 int32_t* pp_error) { | |
| 138 DebugPrintf("PpbGraphics3DRpcServer::PPB_Graphics3D_ResizeBuffers(...)\n"); | |
| 139 NaClSrpcClosureRunner runner(done); | |
| 140 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | |
| 141 *pp_error = ppapi_proxy::PPBGraphics3DInterface()->ResizeBuffers( | |
| 142 graphics3d_id, width, height); | |
| 143 rpc->result = NACL_SRPC_RESULT_OK; | |
| 144 } | |
| 145 | |
| 146 void PpbGraphics3DRpcServer::PPB_Graphics3D_SwapBuffers( | |
| 147 NaClSrpcRpc* rpc, | |
| 148 NaClSrpcClosure* done, | |
| 149 PP_Resource graphics3d_id, | |
| 150 int32_t callback_id, | |
| 151 int32_t* pp_error) { | |
| 152 DebugPrintf("PpbGraphics3DRpcServer::PPB_Graphics3D_SwapBuffers(...)\n"); | |
| 153 NaClSrpcClosureRunner runner(done); | |
| 154 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | |
| 155 PP_CompletionCallback remote_callback = | |
| 156 ppapi_proxy::MakeRemoteCompletionCallback(rpc->channel, callback_id); | |
| 157 if (remote_callback.func == NULL) { | |
| 158 DebugPrintf(" PPB_Graphics3D_SwapBuffers() FAILED!\n"); | |
| 159 return; // Treat this as a generic SRPC error. | |
| 160 } | |
| 161 *pp_error = ppapi_proxy::PPBGraphics3DInterface()->SwapBuffers( | |
| 162 graphics3d_id, remote_callback); | |
| 163 if (*pp_error != PP_OK_COMPLETIONPENDING) | |
| 164 ppapi_proxy::DeleteRemoteCallbackInfo(remote_callback); | |
| 165 DebugPrintf(" PPB_Graphics3D_SwapBuffers: pp_error=%"NACL_PRId32"\n", | |
| 166 *pp_error); | |
| 167 rpc->result = NACL_SRPC_RESULT_OK; | |
| 168 } | |
| 169 | |
| 170 //@} | |
| 171 | |
| 172 //@{ | |
| 173 /// The following methods are the SRPC dispatchers for | |
| 174 /// ppapi/c/ppb_graphics_3d_trusted.h. | |
| 175 void PpbGraphics3DRpcServer::PPB_Graphics3DTrusted_CreateRaw( | |
| 176 NaClSrpcRpc* rpc, | |
| 177 NaClSrpcClosure* done, | |
| 178 PP_Instance instance, | |
| 179 PP_Resource share_context, | |
| 180 nacl_abi_size_t attrib_list_bytes, int32_t* attrib_list, | |
| 181 PP_Resource* resource_id) { | |
| 182 DebugPrintf("PPB_Graphics3DTrusted_CreateRaw: instance: %"NACL_PRIu32"\n", | |
| 183 instance); | |
| 184 | |
| 185 NaClSrpcClosureRunner runner(done); | |
| 186 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | |
| 187 if (!ValidateAttribList(attrib_list_bytes, attrib_list)) | |
| 188 return; | |
| 189 | |
| 190 *resource_id = ppapi_proxy::PPBGraphics3DTrustedInterface()->CreateRaw( | |
| 191 instance, share_context, attrib_list); | |
| 192 rpc->result = NACL_SRPC_RESULT_OK; | |
| 193 } | |
| 194 | |
| 195 void PpbGraphics3DRpcServer::PPB_Graphics3DTrusted_InitCommandBuffer( | |
| 196 NaClSrpcRpc* rpc, | |
| 197 NaClSrpcClosure* done, | |
| 198 PP_Resource resource_id, | |
| 199 int32_t size, | |
| 200 int32_t* success) { | |
| 201 DebugPrintf("PPB_Graphics3DTrusted_InitCommandBuffer() resource_id: %d size: % d\n", | |
| 202 (int)resource_id, (int)size); | |
|
sehr (please use chromium)
2011/08/17 20:44:36
no c-style casts.
nfullagar
2011/08/18 00:23:57
Done.
| |
| 203 NaClSrpcClosureRunner runner(done); | |
| 204 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | |
| 205 if ((size > kMaxAllowedBufferSize) || (size < 0)) | |
| 206 return; | |
| 207 *success = ppapi_proxy::PPBGraphics3DTrustedInterface()->InitCommandBuffer( | |
| 208 resource_id, size); | |
| 209 rpc->result = NACL_SRPC_RESULT_OK; | |
| 210 } | |
| 211 | |
| 212 | |
| 213 void PpbGraphics3DRpcServer::PPB_Graphics3DTrusted_GetRingBuffer( | |
| 214 NaClSrpcRpc* rpc, | |
| 215 NaClSrpcClosure* done, | |
| 216 PP_Resource resource_id, | |
| 217 NaClSrpcImcDescType* shm_desc, | |
| 218 int32_t* shm_size) { | |
| 219 DebugPrintf("PPB_Graphics3DTrusted_GetRingBuffer\n"); | |
| 220 nacl::DescWrapperFactory factory; | |
| 221 nacl::scoped_ptr<nacl::DescWrapper> desc_wrapper; | |
| 222 NaClSrpcClosureRunner runner(done); | |
| 223 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | |
| 224 | |
| 225 int native_handle = 0; | |
| 226 uint32_t native_size = 0; | |
| 227 ppapi_proxy::PPBGraphics3DTrustedInterface()->GetRingBuffer( | |
| 228 resource_id, &native_handle, &native_size); | |
| 229 desc_wrapper.reset(factory.ImportShmHandle((NaClHandle)native_handle, | |
|
sehr (please use chromium)
2011/08/17 20:44:36
ditto.
nfullagar
2011/08/18 00:23:57
Done.
| |
| 230 native_size)); | |
| 231 *shm_desc = desc_wrapper->desc(); | |
| 232 *shm_size = native_size; | |
| 233 rpc->result = NACL_SRPC_RESULT_OK; | |
| 234 } | |
| 235 | |
| 236 void PpbGraphics3DRpcServer::PPB_Graphics3DTrusted_GetState( | |
| 237 NaClSrpcRpc* rpc, | |
| 238 NaClSrpcClosure* done, | |
| 239 PP_Resource resource_id, | |
| 240 nacl_abi_size_t* state_bytes, char* state) { | |
| 241 DebugPrintf("PPB_Graphics3DTrusted_GetState\n"); | |
| 242 NaClSrpcClosureRunner runner(done); | |
| 243 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | |
| 244 PP_Graphics3DTrustedState trusted_state = | |
| 245 ppapi_proxy::PPBGraphics3DTrustedInterface()->GetState(resource_id); | |
| 246 *reinterpret_cast<PP_Graphics3DTrustedState*>(state) = trusted_state; | |
| 247 *state_bytes = sizeof(trusted_state); | |
| 248 rpc->result = NACL_SRPC_RESULT_OK; | |
| 249 } | |
| 250 | |
| 251 void PpbGraphics3DRpcServer::PPB_Graphics3DTrusted_Flush( | |
| 252 NaClSrpcRpc* rpc, | |
| 253 NaClSrpcClosure* done, | |
| 254 PP_Resource resource_id, | |
| 255 int32_t put_offset) { | |
| 256 DebugPrintf("PPB_Graphics3DTrusted_Flush(id: %d, put_offset: %d\n", | |
| 257 resource_id, put_offset); | |
| 258 NaClSrpcClosureRunner runner(done); | |
| 259 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | |
| 260 ppapi_proxy::PPBGraphics3DTrustedInterface()->Flush(resource_id, put_offset); | |
| 261 rpc->result = NACL_SRPC_RESULT_OK; | |
| 262 } | |
| 263 | |
| 264 void PpbGraphics3DRpcServer::PPB_Graphics3DTrusted_FlushSync( | |
| 265 NaClSrpcRpc* rpc, | |
| 266 NaClSrpcClosure* done, | |
| 267 PP_Resource resource_id, | |
| 268 int32_t put_offset, | |
| 269 nacl_abi_size_t* state_bytes, char* state) { | |
| 270 DebugPrintf("PPB_Graphics3DTrusted_FlushSync\n"); | |
| 271 NaClSrpcClosureRunner runner(done); | |
| 272 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | |
| 273 PP_Graphics3DTrustedState trusted_state = | |
| 274 ppapi_proxy::PPBGraphics3DTrustedInterface()->FlushSync(resource_id, | |
| 275 put_offset); | |
| 276 *reinterpret_cast<PP_Graphics3DTrustedState*>(state) = trusted_state; | |
| 277 *state_bytes = sizeof(trusted_state); | |
| 278 rpc->result = NACL_SRPC_RESULT_OK; | |
| 279 | |
| 280 } | |
| 281 | |
| 282 void PpbGraphics3DRpcServer::PPB_Graphics3DTrusted_CreateTransferBuffer( | |
| 283 NaClSrpcRpc* rpc, | |
| 284 NaClSrpcClosure* done, | |
| 285 PP_Resource resource_id, | |
| 286 int32_t size, | |
| 287 int32_t id_request, | |
| 288 int32_t* id) { | |
| 289 UNREFERENCED_PARAMETER(id_request); | |
| 290 NaClSrpcClosureRunner runner(done); | |
| 291 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | |
| 292 DebugPrintf("PPB_Graphics3DTrusted_CreateTransferBuffer\n"); | |
| 293 if ((size > kMaxAllowedBufferSize) || (size < 0)) | |
| 294 return; | |
| 295 *id = ppapi_proxy::PPBGraphics3DTrustedInterface()->CreateTransferBuffer( | |
| 296 resource_id, size); | |
| 297 rpc->result = NACL_SRPC_RESULT_OK; | |
| 298 } | |
| 299 | |
| 300 void PpbGraphics3DRpcServer::PPB_Graphics3DTrusted_DestroyTransferBuffer( | |
| 301 NaClSrpcRpc* rpc, | |
| 302 NaClSrpcClosure* done, | |
| 303 PP_Resource resource_id, | |
| 304 int32_t id) { | |
| 305 DebugPrintf("PPB_Graphics3DTrusted_DestroyTransferBuffer\n"); | |
| 306 NaClSrpcClosureRunner runner(done); | |
| 307 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | |
| 308 ppapi_proxy::PPBGraphics3DTrustedInterface()->DestroyTransferBuffer( | |
| 309 resource_id, id); | |
| 310 rpc->result = NACL_SRPC_RESULT_OK; | |
| 311 | |
| 312 } | |
| 313 | |
| 314 void PpbGraphics3DRpcServer::PPB_Graphics3DTrusted_GetTransferBuffer( | |
| 315 NaClSrpcRpc* rpc, | |
| 316 NaClSrpcClosure* done, | |
| 317 PP_Resource resource_id, | |
| 318 int32_t id, | |
| 319 NaClSrpcImcDescType* shm_desc, | |
| 320 int32_t* shm_size) { | |
| 321 DebugPrintf("PPB_Graphics3DTrusted_GetTransferBuffer\n"); | |
| 322 nacl::DescWrapperFactory factory; | |
| 323 nacl::scoped_ptr<nacl::DescWrapper> desc_wrapper; | |
| 324 NaClSrpcClosureRunner runner(done); | |
| 325 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | |
| 326 | |
| 327 int native_handle = 0; | |
| 328 uint32_t native_size = 0; | |
| 329 ppapi_proxy::PPBGraphics3DTrustedInterface()->GetTransferBuffer(resource_id, | |
| 330 id, | |
|
sehr (please use chromium)
2011/08/17 20:44:36
alignment is off for this and the next two lines.
nfullagar
2011/08/18 00:23:57
Done.
| |
| 331 &native_handle, | |
| 332 &native_size); | |
| 333 desc_wrapper.reset(factory.ImportShmHandle((NaClHandle)native_handle, | |
| 334 native_size)); | |
| 335 *shm_desc = desc_wrapper->desc(); | |
| 336 *shm_size = native_size; | |
| 337 rpc->result = NACL_SRPC_RESULT_OK; | |
| 338 | |
| 339 } | |
| 340 | |
| 341 //@} | |
| OLD | NEW |