diff options
author | scottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-13 00:16:02 +0000 |
---|---|---|
committer | scottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-13 00:16:02 +0000 |
commit | 12722215c574daa9cc56db926a094e9a2d8a96b6 (patch) | |
tree | 7c5ad1c40914c83e434bbf212d74dad17a3d2b4b /ppapi | |
parent | 759e05106684d005a773c68b867e48316fce553e (diff) | |
download | chromium_src-12722215c574daa9cc56db926a094e9a2d8a96b6.zip chromium_src-12722215c574daa9cc56db926a094e9a2d8a96b6.tar.gz chromium_src-12722215c574daa9cc56db926a094e9a2d8a96b6.tar.bz2 |
Add NaCl proxy for pepper gamepad
BUG=79098
Review URL: http://codereview.chromium.org/9148044
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@117561 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
15 files changed, 195 insertions, 2 deletions
diff --git a/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.cc b/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.cc index 87e170e..06b1843 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.cc @@ -375,6 +375,13 @@ const PPB_Fullscreen* PPBFullscreenInterface() { return ppb; } +const PPB_Gamepad_Dev* PPBGamepadInterface() { + static const PPB_Gamepad_Dev* ppb = + static_cast<const PPB_Gamepad_Dev*>( + GetBrowserInterfaceSafe(PPB_GAMEPAD_DEV_INTERFACE)); + return ppb; +} + const PPB_MouseLock* PPBMouseLockInterface() { static const PPB_MouseLock* ppb = static_cast<const PPB_MouseLock*>( GetBrowserInterfaceSafe(PPB_MOUSELOCK_INTERFACE)); diff --git a/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.h b/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.h index 12d09aa..c54cc9c 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.h +++ b/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.h @@ -8,6 +8,7 @@ #include "ppapi/c/dev/ppb_cursor_control_dev.h" #include "ppapi/c/dev/ppb_find_dev.h" #include "ppapi/c/dev/ppb_font_dev.h" +#include "ppapi/c/dev/ppb_gamepad_dev.h" #include "ppapi/c/dev/ppb_memory_dev.h" #include "ppapi/c/dev/ppb_scrollbar_dev.h" #include "ppapi/c/dev/ppb_testing_dev.h" @@ -104,6 +105,7 @@ const PPB_FileSystem* PPBFileSystemInterface(); const PPB_Find_Dev* PPBFindInterface(); const PPB_Font_Dev* PPBFontInterface(); const PPB_Fullscreen* PPBFullscreenInterface(); +const PPB_Gamepad_Dev* PPBGamepadInterface(); const PPB_Graphics2D* PPBGraphics2DInterface(); const PPB_Graphics3D* PPBGraphics3DInterface(); const PPB_Graphics3DTrusted* PPBGraphics3DTrustedInterface(); diff --git a/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_gamepad_rpc_server.cc b/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_gamepad_rpc_server.cc new file mode 100644 index 0000000..313e83d --- /dev/null +++ b/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_gamepad_rpc_server.cc @@ -0,0 +1,33 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// SRPC-abstraction wrappers around PPB_Gamepad functions. + +#include "native_client/src/shared/ppapi_proxy/browser_globals.h" +#include "native_client/src/shared/ppapi_proxy/utility.h" +#include "ppapi/c/dev/ppb_gamepad_dev.h" +#include "srpcgen/ppb_rpc.h" + +using ppapi_proxy::DebugPrintf; +using ppapi_proxy::PPBGamepadInterface; + +void PpbGamepadRpcServer::PPB_Gamepad_SampleGamepads( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + // inputs + PP_Instance instance, + // outputs + nacl_abi_size_t* pads_bytes, char* pads) { + NaClSrpcClosureRunner runner(done); + rpc->result = NACL_SRPC_RESULT_APP_ERROR; + if (*pads_bytes != sizeof(struct PP_GamepadsData_Dev)) + return; + + PPBGamepadInterface()->SampleGamepads( + instance, + reinterpret_cast<struct PP_GamepadsData_Dev*>(pads)); + DebugPrintf("PPB_Gamepad::SampleGamepads\n"); + + rpc->result = NACL_SRPC_RESULT_OK; +} diff --git a/ppapi/native_client/src/shared/ppapi_proxy/build.scons b/ppapi/native_client/src/shared/ppapi_proxy/build.scons index 2a6a78c..ceccdc2 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/build.scons +++ b/ppapi/native_client/src/shared/ppapi_proxy/build.scons @@ -46,6 +46,7 @@ env.DualLibrary('ppapi_browser', 'browser_ppb_find_rpc_server.cc', 'browser_ppb_font_rpc_server.cc', 'browser_ppb_fullscreen_rpc_server.cc', + 'browser_ppb_gamepad_rpc_server.cc', 'browser_ppb_graphics_2d_rpc_server.cc', 'browser_ppb_graphics_3d_rpc_server.cc', 'browser_ppb_image_data_rpc_server.cc', diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb.cc b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb.cc index b5ebc75..deaeaf5 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb.cc @@ -18,6 +18,7 @@ #include "native_client/src/shared/ppapi_proxy/plugin_ppb_find.h" #include "native_client/src/shared/ppapi_proxy/plugin_ppb_font.h" #include "native_client/src/shared/ppapi_proxy/plugin_ppb_fullscreen.h" +#include "native_client/src/shared/ppapi_proxy/plugin_ppb_gamepad.h" #include "native_client/src/shared/ppapi_proxy/plugin_ppb_graphics_2d.h" #include "native_client/src/shared/ppapi_proxy/plugin_ppb_graphics_3d.h" #include "native_client/src/shared/ppapi_proxy/plugin_ppb_image_data.h" @@ -64,6 +65,7 @@ InterfaceMapElement interface_map[] = { { PPB_FIND_DEV_INTERFACE, PluginFind::GetInterface(), true }, { PPB_FONT_DEV_INTERFACE, PluginFont::GetInterface(), true }, { PPB_FULLSCREEN_INTERFACE, PluginFullscreen::GetInterface(), true }, + { PPB_GAMEPAD_DEV_INTERFACE, PluginGamepad::GetInterface(), true }, { PPB_GRAPHICS_2D_INTERFACE, PluginGraphics2D::GetInterface(), true }, { PPB_GRAPHICS_3D_INTERFACE, PluginGraphics3D::GetInterface(), true }, { PPB_IMAGEDATA_INTERFACE, PluginImageData::GetInterface(), true }, diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_gamepad.cc b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_gamepad.cc new file mode 100644 index 0000000..83b0f9d --- /dev/null +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_gamepad.cc @@ -0,0 +1,47 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "native_client/src/shared/ppapi_proxy/plugin_instance_data.h" +#include "native_client/src/shared/ppapi_proxy/plugin_ppb_gamepad.h" +#include "native_client/src/shared/ppapi_proxy/plugin_globals.h" +#include "native_client/src/shared/ppapi_proxy/utility.h" +#include "ppapi/c/pp_size.h" +#include "ppapi/c/dev/ppb_fullscreen_dev.h" +#include "srpcgen/ppb_rpc.h" + +namespace ppapi_proxy { + +namespace { + +void SampleGamepads(PP_Instance instance, struct PP_GamepadsData_Dev* pads) { + DebugPrintf("PPB_Gamepad::SampleGamepads: instance=%"NACL_PRIu32"\n", + instance); + if (pads == NULL) + return; + + nacl_abi_size_t pads_bytes = + static_cast<nacl_abi_size_t>(sizeof(struct PP_GamepadsData_Dev)); + NaClSrpcError srpc_result = + PpbGamepadRpcClient::PPB_Gamepad_SampleGamepads( + GetMainSrpcChannel(), + instance, + &pads_bytes, + reinterpret_cast<char*>(pads)); + DebugPrintf("PPB_Gamepad::SampleGamepads: %s\n", + NaClSrpcErrorString(srpc_result)); + + if (srpc_result != NACL_SRPC_RESULT_OK) + pads->length = 0; +} + +} // namespace + +const PPB_Gamepad_Dev* PluginGamepad::GetInterface() { + static const PPB_Gamepad_Dev gamepad_interface = { + SampleGamepads + }; + return &gamepad_interface; +} + +} // namespace ppapi_proxy diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_gamepad.h b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_gamepad.h new file mode 100644 index 0000000..9f12fb1 --- /dev/null +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_gamepad.h @@ -0,0 +1,24 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_PLUGIN_PPB_GAMEPAD_H_ +#define NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_PLUGIN_PPB_GAMEPAD_H_ + +#include "native_client/src/include/nacl_macros.h" +#include "ppapi/c/dev/ppb_gamepad_dev.h" + +namespace ppapi_proxy { + +// Implements the untrusted side of the PPB_Gamepad interface. +class PluginGamepad { + public: + static const PPB_Gamepad_Dev* GetInterface(); + + private: + NACL_DISALLOW_COPY_AND_ASSIGN(PluginGamepad); +}; + +} // namespace ppapi_proxy + +#endif // NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_PLUGIN_PPB_GAMEPAD_H_ diff --git a/ppapi/native_client/src/shared/ppapi_proxy/ppapi_proxy.gyp b/ppapi/native_client/src/shared/ppapi_proxy/ppapi_proxy.gyp index a2be0a8..601e3e9 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/ppapi_proxy.gyp +++ b/ppapi/native_client/src/shared/ppapi_proxy/ppapi_proxy.gyp @@ -1,4 +1,4 @@ -# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Copyright (c) 2012 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -24,6 +24,7 @@ 'browser_ppb_find_rpc_server.cc', 'browser_ppb_font_rpc_server.cc', 'browser_ppb_fullscreen_rpc_server.cc', + 'browser_ppb_gamepad_rpc_server.cc', 'browser_ppb_graphics_2d_rpc_server.cc', 'browser_ppb_graphics_3d_rpc_server.cc', 'browser_ppb_image_data_rpc_server.cc', diff --git a/ppapi/native_client/src/shared/ppapi_proxy/ppapi_proxy_untrusted.gyp b/ppapi/native_client/src/shared/ppapi_proxy/ppapi_proxy_untrusted.gyp index 40febe21..1eac078 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/ppapi_proxy_untrusted.gyp +++ b/ppapi/native_client/src/shared/ppapi_proxy/ppapi_proxy_untrusted.gyp @@ -1,4 +1,4 @@ -# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Copyright (c) 2012 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -60,6 +60,7 @@ 'plugin_ppb_find.cc', 'plugin_ppb_font.cc', 'plugin_ppb_fullscreen.cc', + 'plugin_ppb_gamepad.cc', 'plugin_ppb_graphics_2d.cc', 'plugin_ppb_graphics_3d.cc', 'plugin_ppb_image_data.cc', diff --git a/ppapi/native_client/src/shared/ppapi_proxy/ppb_gamepad.srpc b/ppapi/native_client/src/shared/ppapi_proxy/ppb_gamepad.srpc new file mode 100644 index 0000000..e00ac4b --- /dev/null +++ b/ppapi/native_client/src/shared/ppapi_proxy/ppb_gamepad.srpc @@ -0,0 +1,15 @@ +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# RPC methods used to implement PPB_Gamepad interface. +# See ppapi/c/dev/ppb_gamepad_dev.h for interface details. +{ + 'name': 'PpbGamepadRpc', + 'rpcs': [ + {'name': 'PPB_Gamepad_SampleGamepads', + 'inputs': [['instance', 'PP_Instance']], + 'outputs': [['data', 'char[]']] # PP_GamepadsData_Dev + }, + ] +} diff --git a/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_client.cc b/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_client.cc index d529666..85c452f 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_client.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_client.cc @@ -1158,6 +1158,23 @@ NaClSrpcError PpbFullscreenRpcClient::PPB_Fullscreen_GetScreenSize( return retval; } +NaClSrpcError PpbGamepadRpcClient::PPB_Gamepad_SampleGamepads( + NaClSrpcChannel* channel, + PP_Instance instance, + nacl_abi_size_t* data_bytes, char* data) { + VCHECK(ppapi_proxy::PPBCoreInterface()->IsMainThread(), + ("%s: PPAPI calls are not supported off the main thread\n", + __FUNCTION__)); + NaClSrpcError retval; + retval = NaClSrpcInvokeBySignature( + channel, + "PPB_Gamepad_SampleGamepads:i:C", + instance, + data_bytes, data + ); + return retval; +} + NaClSrpcError PpbGraphics2DRpcClient::PPB_Graphics2D_Create( NaClSrpcChannel* channel, PP_Instance instance, diff --git a/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_server.cc b/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_server.cc index 0bbbd2f..5c92a13 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_server.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_server.cc @@ -933,6 +933,20 @@ static void PPB_Fullscreen_GetScreenSizeDispatcher( ); } +static void PPB_Gamepad_SampleGamepadsDispatcher( + NaClSrpcRpc* rpc, + NaClSrpcArg** inputs, + NaClSrpcArg** outputs, + NaClSrpcClosure* done +) { + PpbGamepadRpcServer::PPB_Gamepad_SampleGamepads( + rpc, + done, + inputs[0]->u.ival, + &(outputs[0]->u.count), outputs[0]->arrays.carr + ); +} + static void PPB_Graphics2D_CreateDispatcher( NaClSrpcRpc* rpc, NaClSrpcArg** inputs, @@ -2634,6 +2648,7 @@ NaClSrpcHandlerDesc PpbRpcs::srpc_methods[] = { { "PPB_Font_PixelOffsetForCharacter:iCCi:i", PPB_Font_PixelOffsetForCharacterDispatcher }, { "PPB_Fullscreen_SetFullscreen:ii:i", PPB_Fullscreen_SetFullscreenDispatcher }, { "PPB_Fullscreen_GetScreenSize:i:Ci", PPB_Fullscreen_GetScreenSizeDispatcher }, + { "PPB_Gamepad_SampleGamepads:i:C", PPB_Gamepad_SampleGamepadsDispatcher }, { "PPB_Graphics2D_Create:iCi:i", PPB_Graphics2D_CreateDispatcher }, { "PPB_Graphics2D_IsGraphics2D:i:i", PPB_Graphics2D_IsGraphics2DDispatcher }, { "PPB_Graphics2D_Describe:i:Cii", PPB_Graphics2D_DescribeDispatcher }, diff --git a/ppapi/native_client/src/shared/ppapi_proxy/run_srpcgen.py b/ppapi/native_client/src/shared/ppapi_proxy/run_srpcgen.py index b048888..4d1d0cd 100755 --- a/ppapi/native_client/src/shared/ppapi_proxy/run_srpcgen.py +++ b/ppapi/native_client/src/shared/ppapi_proxy/run_srpcgen.py @@ -68,6 +68,7 @@ all_units = [ 'ppb_find.srpc', 'ppb_font.srpc', 'ppb_fullscreen.srpc', + 'ppb_gamepad.srpc', 'ppb_graphics_2d.srpc', 'ppb_graphics_3d.srpc', 'ppb_image_data.srpc', diff --git a/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppb_rpc.h b/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppb_rpc.h index bde42e8..9d494f8 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppb_rpc.h +++ b/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppb_rpc.h @@ -487,6 +487,20 @@ class PpbFullscreenRpcServer { void operator=(const PpbFullscreenRpcServer); }; // class PpbFullscreenRpcServer +class PpbGamepadRpcServer { + public: + static void PPB_Gamepad_SampleGamepads( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + PP_Instance instance, + nacl_abi_size_t* data_bytes, char* data); + + private: + PpbGamepadRpcServer(); + PpbGamepadRpcServer(const PpbGamepadRpcServer&); + void operator=(const PpbGamepadRpcServer); +}; // class PpbGamepadRpcServer + class PpbGraphics2DRpcServer { public: static void PPB_Graphics2D_Create( diff --git a/ppapi/native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppb_rpc.h b/ppapi/native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppb_rpc.h index a209ecb..b210e58a 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppb_rpc.h +++ b/ppapi/native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppb_rpc.h @@ -427,6 +427,19 @@ class PpbFullscreenRpcClient { void operator=(const PpbFullscreenRpcClient); }; // class PpbFullscreenRpcClient +class PpbGamepadRpcClient { + public: + static NaClSrpcError PPB_Gamepad_SampleGamepads( + NaClSrpcChannel* channel, + PP_Instance instance, + nacl_abi_size_t* data_bytes, char* data); + + private: + PpbGamepadRpcClient(); + PpbGamepadRpcClient(const PpbGamepadRpcClient&); + void operator=(const PpbGamepadRpcClient); +}; // class PpbGamepadRpcClient + class PpbGraphics2DRpcClient { public: static NaClSrpcError PPB_Graphics2D_Create( |