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