diff options
author | scottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-01 06:44:51 +0000 |
---|---|---|
committer | scottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-01 06:44:51 +0000 |
commit | 957c93abd8af4170e5da2d5d0f0862e46cb8491e (patch) | |
tree | 49a5c7b114c65c8531041c008f6f9c77c3fd7c8e /ppapi | |
parent | 78b0b3703719ceba85cf99d8e5f27424c57e796c (diff) | |
download | chromium_src-957c93abd8af4170e5da2d5d0f0862e46cb8491e.zip chromium_src-957c93abd8af4170e5da2d5d0f0862e46cb8491e.tar.gz chromium_src-957c93abd8af4170e5da2d5d0f0862e46cb8491e.tar.bz2 |
Revise gamepad interface
Per API review, revision to gamepad interface. Still in _dev for now, will move to stable as separate change once we're happy with the interface.
Change summary:
- renames of various fields, and main function in idl per discussion
- timestamp to double, connected to PP_Bool
- remove #pragma pack in header, now copied member-by-member
- update examples
One complication was in removing the #pragma pack. Copying by member in webkit/plugins/ppapi/ppapi_plugin_instance.cc avoids the need to keep webkit and pepper in sync and exactly the same layout (a good thing).
However, when the native_client ppapi proxy is going between 32 and 64 the data structure ends up being a different size due to padding (all the fields are teh same sizes though). To workaround this, I added padding fields, and assert_sizes to confirm the sizes are the same on both "sides". This is similar to how PP_Point, input events, etc. get rpc'd, but perhaps there's a better way.
BUG=112879
Review URL: http://codereview.chromium.org/9405033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124375 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r-- | ppapi/api/dev/ppb_gamepad_dev.idl | 66 | ||||
-rw-r--r-- | ppapi/c/dev/ppb_gamepad_dev.h | 62 | ||||
-rw-r--r-- | ppapi/examples/gamepad/gamepad.cc | 47 | ||||
-rw-r--r-- | ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_gamepad_rpc_server.cc | 6 | ||||
-rw-r--r-- | ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_gamepad.cc | 5 | ||||
-rw-r--r-- | ppapi/proxy/ppb_instance_proxy.cc | 2 | ||||
-rw-r--r-- | ppapi/proxy/ppb_instance_proxy.h | 4 | ||||
-rw-r--r-- | ppapi/thunk/interfaces_ppb_public_dev.h | 2 | ||||
-rw-r--r-- | ppapi/thunk/ppb_gamepad_thunk.cc | 4 | ||||
-rw-r--r-- | ppapi/thunk/ppb_instance_api.h | 2 |
10 files changed, 101 insertions, 99 deletions
diff --git a/ppapi/api/dev/ppb_gamepad_dev.idl b/ppapi/api/dev/ppb_gamepad_dev.idl index 8e6a4a9..a9b5918 100644 --- a/ppapi/api/dev/ppb_gamepad_dev.idl +++ b/ppapi/api/dev/ppb_gamepad_dev.idl @@ -9,87 +9,87 @@ */ label Chrome { - M18 = 0.1 + M19 = 0.2 }; -#inline c -#pragma pack(push, 1) -#endinl - /** * The data for one gamepad device. */ -struct PP_GamepadData_Dev { +[assert_size(472)] +struct PP_GamepadSampleData_Dev { /** - * Is there a gamepad connected at this index? If this is false, no other - * data in this structure is valid. + * Number of valid elements in the |axes| array. */ - char connected; + uint32_t axes_length; /** - * String identifier for the type of device/manufacturer. + * Normalized values for the axes, indices valid up to |axes_length|-1. Axis + * values range from -1..1, and are in order of "importance". */ - uint16_t[128] id; + float_t[16] axes; /** - * Monotonically increasing value that is incremented when the data have - * been updated. + * Number of valid elements in the |buttons| array. */ - uint64_t timestamp; + uint32_t buttons_length; /** - * Number of valid elements in the |axes| array. + * Normalized values for the buttons, indices valid up to |buttons_length| + * - 1. Button values range from 0..1, and are in order of importance. */ - uint32_t axes_length; + float_t[32] buttons; /** - * Normalized values for the axes, indices valid up to |axesLength|-1. Axis - * values range from -1..1, and are in order of "importance". + * Monotonically increasing value that is incremented when the data have + * been updated. */ - float_t[16] axes; + double_t timestamp; /** - * Number of valid elements in the |buttons| array. + * Identifier for the type of device/manufacturer. */ - uint32_t buttons_length; + uint16_t[128] id; /** - * Normalized values for the buttons, indices valid up to |buttonsLength| - * - 1. Button values range from 0..1, and are in order of importance. + * Is there a gamepad connected at this index? If this is false, no other + * data in this structure is valid. */ - float_t[32] buttons; + PP_Bool connected; + + /* Padding to make the struct the same size between 64 and 32. */ + char[4] unused_pad_; }; /** * The data for all gamepads connected to the system. */ -struct PP_GamepadsData_Dev { +[assert_size(1896)] +struct PP_GamepadsSampleData_Dev { /** * Number of valid elements in the |items| array. */ uint32_t length; + /* Padding to make the struct the same size between 64 and 32. */ + char[4] unused_pad_; + /** * Data for an individual gamepad device connected to the system. */ - PP_GamepadData_Dev[4] items; + PP_GamepadSampleData_Dev[4] items; }; -#inline c -#pragma pack(pop) -#endinl - /** * The <code>PPB_Gamepad_Dev</code> interface allows retrieving data from * gamepad/joystick devices that are connected to the system. */ -[version=0.1, macro="PPB_GAMEPAD_DEV_INTERFACE"] +[version=0.2, macro="PPB_GAMEPAD_DEV_INTERFACE"] interface PPB_Gamepad_Dev { /** * Samples the current state of the connected gamepads. */ - void SampleGamepads( + void Sample( [in] PP_Instance instance, - [out] PP_GamepadsData_Dev data); + [out] PP_GamepadsSampleData_Dev data); }; diff --git a/ppapi/c/dev/ppb_gamepad_dev.h b/ppapi/c/dev/ppb_gamepad_dev.h index e37362b..33a0f4c 100644 --- a/ppapi/c/dev/ppb_gamepad_dev.h +++ b/ppapi/c/dev/ppb_gamepad_dev.h @@ -3,17 +3,18 @@ * found in the LICENSE file. */ -/* From dev/ppb_gamepad_dev.idl modified Tue Feb 7 12:49:02 2012. */ +/* From dev/ppb_gamepad_dev.idl modified Mon Feb 27 13:23:13 2012. */ #ifndef PPAPI_C_DEV_PPB_GAMEPAD_DEV_H_ #define PPAPI_C_DEV_PPB_GAMEPAD_DEV_H_ +#include "ppapi/c/pp_bool.h" #include "ppapi/c/pp_instance.h" #include "ppapi/c/pp_macros.h" #include "ppapi/c/pp_stdint.h" -#define PPB_GAMEPAD_DEV_INTERFACE_0_1 "PPB_Gamepad(Dev);0.1" -#define PPB_GAMEPAD_DEV_INTERFACE PPB_GAMEPAD_DEV_INTERFACE_0_1 +#define PPB_GAMEPAD_DEV_INTERFACE_0_2 "PPB_Gamepad(Dev);0.2" +#define PPB_GAMEPAD_DEV_INTERFACE PPB_GAMEPAD_DEV_INTERFACE_0_2 /** * @file @@ -22,8 +23,6 @@ */ -#pragma pack(push, 1) - /** * @addtogroup Structs * @{ @@ -31,27 +30,13 @@ /** * The data for one gamepad device. */ -struct PP_GamepadData_Dev { - /** - * Is there a gamepad connected at this index? If this is false, no other - * data in this structure is valid. - */ - char connected; - /** - * String identifier for the type of device/manufacturer. - */ - uint16_t id[128]; - /** - * Monotonically increasing value that is incremented when the data have - * been updated. - */ - uint64_t timestamp; +struct PP_GamepadSampleData_Dev { /** * Number of valid elements in the |axes| array. */ uint32_t axes_length; /** - * Normalized values for the axes, indices valid up to |axesLength|-1. Axis + * Normalized values for the axes, indices valid up to |axes_length|-1. Axis * values range from -1..1, and are in order of "importance". */ float axes[16]; @@ -60,31 +45,49 @@ struct PP_GamepadData_Dev { */ uint32_t buttons_length; /** - * Normalized values for the buttons, indices valid up to |buttonsLength| + * Normalized values for the buttons, indices valid up to |buttons_length| * - 1. Button values range from 0..1, and are in order of importance. */ float buttons[32]; + /** + * Monotonically increasing value that is incremented when the data have + * been updated. + */ + double timestamp; + /** + * Identifier for the type of device/manufacturer. + */ + uint16_t id[128]; + /** + * Is there a gamepad connected at this index? If this is false, no other + * data in this structure is valid. + */ + PP_Bool connected; + /* Padding to make the struct the same size between 64 and 32. */ + char unused_pad_[4]; }; +PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_GamepadSampleData_Dev, 472); /** * The data for all gamepads connected to the system. */ -struct PP_GamepadsData_Dev { +struct PP_GamepadsSampleData_Dev { /** * Number of valid elements in the |items| array. */ uint32_t length; + /* Padding to make the struct the same size between 64 and 32. */ + char unused_pad_[4]; /** * Data for an individual gamepad device connected to the system. */ - struct PP_GamepadData_Dev items[4]; + struct PP_GamepadSampleData_Dev items[4]; }; +PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_GamepadsSampleData_Dev, 1896); /** * @} */ -#pragma pack(pop) - /** * @addtogroup Interfaces * @{ @@ -93,15 +96,14 @@ struct PP_GamepadsData_Dev { * The <code>PPB_Gamepad_Dev</code> interface allows retrieving data from * gamepad/joystick devices that are connected to the system. */ -struct PPB_Gamepad_Dev_0_1 { +struct PPB_Gamepad_Dev_0_2 { /** * Samples the current state of the connected gamepads. */ - void (*SampleGamepads)(PP_Instance instance, - struct PP_GamepadsData_Dev* data); + void (*Sample)(PP_Instance instance, struct PP_GamepadsSampleData_Dev* data); }; -typedef struct PPB_Gamepad_Dev_0_1 PPB_Gamepad_Dev; +typedef struct PPB_Gamepad_Dev_0_2 PPB_Gamepad_Dev; /** * @} */ diff --git a/ppapi/examples/gamepad/gamepad.cc b/ppapi/examples/gamepad/gamepad.cc index 60ef589..7006dd1 100644 --- a/ppapi/examples/gamepad/gamepad.cc +++ b/ppapi/examples/gamepad/gamepad.cc @@ -49,9 +49,6 @@ class MyInstance : public pp::Instance { pp::Module::Get()->GetBrowserInterface(PPB_GAMEPAD_DEV_INTERFACE)); if (!gamepad_) return false; - - RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | - PP_INPUTEVENT_CLASS_KEYBOARD); return true; } @@ -92,27 +89,29 @@ class MyInstance : public pp::Instance { if (image.is_null()) return image; - PP_GamepadsData_Dev gamepad_data; - gamepad_->SampleGamepads(pp_instance(), &gamepad_data); - - int width2 = size.width() / 2; - int height2 = size.height() / 2; - // Draw 2 axes - for (size_t i = 0; i < gamepad_data.items[0].axes_length; i += 2) { - int x = static_cast<int>( - gamepad_data.items[0].axes[i + 0] * width2 + width2); - int y = static_cast<int>( - gamepad_data.items[0].axes[i + 1] * height2 + height2); - uint32_t box_bgra = 0x80000000; // Alpha 50%. - FillRect(&image, x - 3, y - 3, 7, 7, box_bgra); - } - - for (size_t i = 0; i < gamepad_data.items[0].buttons_length; ++i) { - float button_val = gamepad_data.items[0].buttons[i]; - uint32_t colour = static_cast<uint32_t>((button_val * 192) + 63) << 24; - int x = i * 8 + 10; - int y = 10; - FillRect(&image, x - 3, y - 3, 7, 7, colour); + PP_GamepadsSampleData_Dev gamepad_data; + gamepad_->Sample(pp_instance(), &gamepad_data); + + if (gamepad_data.length > 1 && gamepad_data.items[0].connected) { + int width2 = size.width() / 2; + int height2 = size.height() / 2; + // Draw 2 axes + for (size_t i = 0; i < gamepad_data.items[0].axes_length; i += 2) { + int x = static_cast<int>( + gamepad_data.items[0].axes[i + 0] * width2 + width2); + int y = static_cast<int>( + gamepad_data.items[0].axes[i + 1] * height2 + height2); + uint32_t box_bgra = 0x80000000; // Alpha 50%. + FillRect(&image, x - 3, y - 3, 7, 7, box_bgra); + } + + for (size_t i = 0; i < gamepad_data.items[0].buttons_length; ++i) { + float button_val = gamepad_data.items[0].buttons[i]; + uint32_t colour = static_cast<uint32_t>((button_val * 192) + 63) << 24; + int x = i * 8 + 10; + int y = 10; + FillRect(&image, x - 3, y - 3, 7, 7, colour); + } } return image; } 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 index 313e83d..7ef24ca 100644 --- 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 @@ -21,12 +21,12 @@ void PpbGamepadRpcServer::PPB_Gamepad_SampleGamepads( 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)) + if (*pads_bytes != sizeof(struct PP_GamepadsSampleData_Dev)) return; - PPBGamepadInterface()->SampleGamepads( + PPBGamepadInterface()->Sample( instance, - reinterpret_cast<struct PP_GamepadsData_Dev*>(pads)); + reinterpret_cast<struct PP_GamepadsSampleData_Dev*>(pads)); DebugPrintf("PPB_Gamepad::SampleGamepads\n"); rpc->result = NACL_SRPC_RESULT_OK; 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 index 021e6f2..2e2256b 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_gamepad.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_gamepad.cc @@ -14,14 +14,15 @@ namespace ppapi_proxy { namespace { -void SampleGamepads(PP_Instance instance, struct PP_GamepadsData_Dev* pads) { +void SampleGamepads(PP_Instance instance, + struct PP_GamepadsSampleData_Dev* pads) { DebugPrintf("PPB_Gamepad::SampleGamepads: instance=%"NACL_PRId32"\n", instance); if (pads == NULL) return; nacl_abi_size_t pads_bytes = - static_cast<nacl_abi_size_t>(sizeof(struct PP_GamepadsData_Dev)); + static_cast<nacl_abi_size_t>(sizeof(struct PP_GamepadsSampleData_Dev)); NaClSrpcError srpc_result = PpbGamepadRpcClient::PPB_Gamepad_SampleGamepads( GetMainSrpcChannel(), diff --git a/ppapi/proxy/ppb_instance_proxy.cc b/ppapi/proxy/ppb_instance_proxy.cc index 1f71e87..8842783 100644 --- a/ppapi/proxy/ppb_instance_proxy.cc +++ b/ppapi/proxy/ppb_instance_proxy.cc @@ -288,7 +288,7 @@ PP_Bool PPB_Instance_Proxy::FlashGetScreenSize(PP_Instance instance, } void PPB_Instance_Proxy::SampleGamepads(PP_Instance instance, - PP_GamepadsData_Dev* data) { + PP_GamepadsSampleData_Dev* data) { NOTIMPLEMENTED(); } diff --git a/ppapi/proxy/ppb_instance_proxy.h b/ppapi/proxy/ppb_instance_proxy.h index 80927a3..60661f7 100644 --- a/ppapi/proxy/ppb_instance_proxy.h +++ b/ppapi/proxy/ppb_instance_proxy.h @@ -72,8 +72,8 @@ class PPB_Instance_Proxy : public InterfaceProxy, PP_Bool fullscreen) OVERRIDE; virtual PP_Bool FlashGetScreenSize(PP_Instance instance, PP_Size* size) OVERRIDE; - virtual void SampleGamepads(PP_Instance instance, PP_GamepadsData_Dev* data) - OVERRIDE; + virtual void SampleGamepads(PP_Instance instance, + PP_GamepadsSampleData_Dev* data) OVERRIDE; virtual int32_t RequestInputEvents(PP_Instance instance, uint32_t event_classes) OVERRIDE; virtual int32_t RequestFilteringInputEvents(PP_Instance instance, diff --git a/ppapi/thunk/interfaces_ppb_public_dev.h b/ppapi/thunk/interfaces_ppb_public_dev.h index 94696e4..5a7ca47 100644 --- a/ppapi/thunk/interfaces_ppb_public_dev.h +++ b/ppapi/thunk/interfaces_ppb_public_dev.h @@ -41,7 +41,7 @@ PROXIED_IFACE(PPB_FileChooser, PPB_FILECHOOSER_DEV_INTERFACE_0_5, PPB_FileChooser_Dev_0_5) PROXIED_IFACE(PPB_Instance, PPB_CHAR_SET_DEV_INTERFACE_0_4, PPB_CharSet_Dev_0_4) PROXIED_IFACE(PPB_Instance, PPB_CONSOLE_DEV_INTERFACE_0_1, PPB_Console_Dev_0_1) -PROXIED_IFACE(PPB_Instance, PPB_GAMEPAD_DEV_INTERFACE_0_1, PPB_Gamepad_Dev_0_1) +PROXIED_IFACE(PPB_Instance, PPB_GAMEPAD_DEV_INTERFACE_0_2, PPB_Gamepad_Dev_0_2) PROXIED_IFACE(PPB_Instance, PPB_URLUTIL_DEV_INTERFACE_0_6, PPB_URLUtil_Dev_0_6) UNPROXIED_IFACE(PPB_Instance, PPB_ZOOM_DEV_INTERFACE_0_2, PPB_Zoom_Dev_0_2) PROXIED_IFACE(NoAPIName, PPB_KEYBOARD_INPUT_EVENT_DEV_INTERFACE_0_1, diff --git a/ppapi/thunk/ppb_gamepad_thunk.cc b/ppapi/thunk/ppb_gamepad_thunk.cc index 9bf2122..376faa4 100644 --- a/ppapi/thunk/ppb_gamepad_thunk.cc +++ b/ppapi/thunk/ppb_gamepad_thunk.cc @@ -13,7 +13,7 @@ namespace thunk { namespace { -void SampleGamepads(PP_Instance instance, PP_GamepadsData_Dev* data) { +void SampleGamepads(PP_Instance instance, PP_GamepadsSampleData_Dev* data) { EnterFunction<PPB_Instance_FunctionAPI> enter(instance, true); if (enter.failed()) return; @@ -26,7 +26,7 @@ const PPB_Gamepad_Dev g_ppb_gamepad_thunk = { } // namespace -const PPB_Gamepad_Dev* GetPPB_Gamepad_Dev_0_1_Thunk() { +const PPB_Gamepad_Dev* GetPPB_Gamepad_Dev_0_2_Thunk() { return &g_ppb_gamepad_thunk; } diff --git a/ppapi/thunk/ppb_instance_api.h b/ppapi/thunk/ppb_instance_api.h index 3055d73..87ea79c 100644 --- a/ppapi/thunk/ppb_instance_api.h +++ b/ppapi/thunk/ppb_instance_api.h @@ -83,7 +83,7 @@ class PPB_Instance_FunctionAPI { // Gamepad. virtual void SampleGamepads(PP_Instance instance, - PP_GamepadsData_Dev* data) = 0; + PP_GamepadsSampleData_Dev* data) = 0; // InputEvent. virtual int32_t RequestInputEvents(PP_Instance instance, |