summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--native_client_sdk/src/examples/gamepad/gamepad.cc7
-rw-r--r--ppapi/api/dev/ppb_gamepad_dev.idl66
-rw-r--r--ppapi/c/dev/ppb_gamepad_dev.h62
-rw-r--r--ppapi/examples/gamepad/gamepad.cc47
-rw-r--r--ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_gamepad_rpc_server.cc6
-rw-r--r--ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_gamepad.cc5
-rw-r--r--ppapi/proxy/ppb_instance_proxy.cc2
-rw-r--r--ppapi/proxy/ppb_instance_proxy.h4
-rw-r--r--ppapi/thunk/interfaces_ppb_public_dev.h2
-rw-r--r--ppapi/thunk/ppb_gamepad_thunk.cc4
-rw-r--r--ppapi/thunk/ppb_instance_api.h2
-rw-r--r--webkit/plugins/ppapi/event_conversion.cc27
-rw-r--r--webkit/plugins/ppapi/event_conversion.h7
-rw-r--r--webkit/plugins/ppapi/ppapi_plugin_instance.cc46
-rw-r--r--webkit/plugins/ppapi/ppapi_plugin_instance.h2
15 files changed, 144 insertions, 145 deletions
diff --git a/native_client_sdk/src/examples/gamepad/gamepad.cc b/native_client_sdk/src/examples/gamepad/gamepad.cc
index c288b8b..9ee653e 100644
--- a/native_client_sdk/src/examples/gamepad/gamepad.cc
+++ b/native_client_sdk/src/examples/gamepad/gamepad.cc
@@ -10,6 +10,7 @@
#include <cmath>
#include <cstring>
#include <string>
+#include "ppapi/c/dev/ppb_gamepad_dev.h"
#include "ppapi/cpp/completion_callback.h"
#include "ppapi/cpp/var.h"
@@ -83,15 +84,15 @@ void Gamepad::Paint() {
FillRect(pixel_buffer_, 0, 0, width(), height(), 0xfff0f0f0);
// Get current gamepad data.
- PP_GamepadsData_Dev gamepad_data;
- gamepad_->SampleGamepads(pp_instance(), &gamepad_data);
+ PP_GamepadsSampleData_Dev gamepad_data;
+ gamepad_->Sample(pp_instance(), &gamepad_data);
// Draw the current state for each connected gamepad.
for (size_t p = 0; p < gamepad_data.length; ++p) {
int width2 = width() / gamepad_data.length / 2;
int height2 = height() / 2;
int offset = width2 * 2 * p;
- PP_GamepadData_Dev& pad = gamepad_data.items[p];
+ PP_GamepadSampleData_Dev& pad = gamepad_data.items[p];
if (!pad.connected)
continue;
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,
diff --git a/webkit/plugins/ppapi/event_conversion.cc b/webkit/plugins/ppapi/event_conversion.cc
index 9936ce3..cfc74a9 100644
--- a/webkit/plugins/ppapi/event_conversion.cc
+++ b/webkit/plugins/ppapi/event_conversion.cc
@@ -16,6 +16,7 @@
#include "ppapi/shared_impl/ppb_input_event_shared.h"
#include "ppapi/shared_impl/time_conversion.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGamepads.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
#include "webkit/plugins/ppapi/common.h"
#include "webkit/plugins/ppapi/usb_key_code_conversion.h"
@@ -522,5 +523,31 @@ PP_InputEvent_Class ClassifyInputEvent(WebInputEvent::Type type) {
}
}
+void ConvertWebKitGamepadData(WebKit::WebGamepads& webkit_data,
+ PP_GamepadsSampleData_Dev* output_data) {
+ output_data->length = webkit_data.length;
+ for (unsigned i = 0; i < webkit_data.length; ++i) {
+ PP_GamepadSampleData_Dev& output_pad = output_data->items[i];
+ const WebKit::WebGamepad& webkit_pad = webkit_data.items[i];
+ output_pad.connected = webkit_pad.connected ? PP_TRUE : PP_FALSE;
+ if (webkit_pad.connected) {
+ COMPILE_ASSERT(sizeof(output_pad.id) == sizeof(webkit_pad.id),
+ id_size_does_not_match);
+ COMPILE_ASSERT(sizeof(output_pad.axes) == sizeof(webkit_pad.axes),
+ axes_size_does_not_match);
+ COMPILE_ASSERT(sizeof(output_pad.buttons) == sizeof(webkit_pad.buttons),
+ buttons_size_does_not_match);
+ memcpy(output_pad.id, webkit_pad.id, sizeof(output_pad.id));
+ output_pad.timestamp = webkit_pad.timestamp;
+ output_pad.axes_length = webkit_pad.axesLength;
+ memcpy(output_pad.axes, webkit_pad.axes, sizeof(output_pad.axes));
+ output_pad.buttons_length = webkit_pad.buttonsLength;
+ memcpy(output_pad.buttons,
+ webkit_pad.buttons,
+ sizeof(output_pad.buttons));
+ }
+ }
+}
+
} // namespace ppapi
} // namespace webkit
diff --git a/webkit/plugins/ppapi/event_conversion.h b/webkit/plugins/ppapi/event_conversion.h
index b9b4004..573e5b6 100644
--- a/webkit/plugins/ppapi/event_conversion.h
+++ b/webkit/plugins/ppapi/event_conversion.h
@@ -8,6 +8,7 @@
#include <vector>
#include "base/memory/linked_ptr.h"
+#include "ppapi/c/dev/ppb_gamepad_dev.h"
#include "ppapi/c/ppb_input_event.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
@@ -18,6 +19,7 @@ struct InputEventData;
}
namespace WebKit {
+class WebGamepads;
class WebInputEvent;
}
@@ -47,6 +49,11 @@ std::vector<linked_ptr<WebKit::WebInputEvent> > CreateSimulatedWebInputEvents(
// type should not be "Undefined" since there's no corresponding PPAPI class.
PP_InputEvent_Class ClassifyInputEvent(WebKit::WebInputEvent::Type type);
+// Translate from WebGamepads to the Gamepad API format
+// PP_GamepadsSampleData_Dev.
+void ConvertWebKitGamepadData(WebKit::WebGamepads& webkit_data,
+ PP_GamepadsSampleData_Dev* output_data);
+
} // namespace ppapi
} // namespace webkit
diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
index 7dde8d7..a5d6515 100644
--- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc
+++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
@@ -220,15 +220,6 @@ COMPILE_ASSERT_MATCHING_ENUM(TypeGrabbing, PP_CURSORTYPE_GRABBING);
// Do not assert WebCursorInfo::TypeCustom == PP_CURSORTYPE_CUSTOM;
// PP_CURSORTYPE_CUSTOM is pinned to allow new cursor types.
-// Ensure conversion from WebKit::WebGamepads to PP_GamepadsData_Dev is safe.
-// See also DCHECKs in SampleGamepads below.
-//
-// Temporarily disabled for 2-sided WebKit roll.
-//COMPILE_ASSERT(sizeof(WebKit::WebGamepads) == sizeof(PP_GamepadsData_Dev),
-// size_difference);
-//COMPILE_ASSERT(sizeof(WebKit::WebGamepad) == sizeof(PP_GamepadData_Dev),
-// size_difference);
-
// Sets |*security_origin| to be the WebKit security origin associated with the
// document containing the given plugin instance. On success, returns true. If
// the instance is invalid, returns false and |*security_origin| will be
@@ -1354,39 +1345,10 @@ bool PluginInstance::IsRectTopmost(const gfx::Rect& rect) {
}
void PluginInstance::SampleGamepads(PP_Instance instance,
- PP_GamepadsData_Dev* data) {
-
- // Because the WebKit objects have trivial ctors, using offsetof doesn't
- // work. Instead use this version based on src/v8/src/globals.h. This
- // workaround doesn't work in constant expressions as required for
- // COMPILE_ASSERT, so DCHECK instead.
-
-#define OFFSET_OF(type, field) \
- (reinterpret_cast<intptr_t>(&(reinterpret_cast<type*>(4)->field)) - 4)
-
-#define DCHECK_GAMEPADS_OFFSET(webkit_name, pp_name) \
- DCHECK(OFFSET_OF(WebKit::WebGamepads, webkit_name) \
- == OFFSET_OF(PP_GamepadsData_Dev, pp_name))
-
-#define DCHECK_GAMEPAD_OFFSET(webkit_name, pp_name) \
- DCHECK(OFFSET_OF(WebKit::WebGamepad, webkit_name) \
- == OFFSET_OF(PP_GamepadData_Dev, pp_name))
-
- DCHECK_GAMEPADS_OFFSET(length, length);
- DCHECK_GAMEPADS_OFFSET(items, items);
- DCHECK_GAMEPAD_OFFSET(connected, connected);
- DCHECK_GAMEPAD_OFFSET(id, id);
- DCHECK_GAMEPAD_OFFSET(timestamp, timestamp);
- DCHECK_GAMEPAD_OFFSET(axesLength, axes_length);
- DCHECK_GAMEPAD_OFFSET(axes, axes);
- DCHECK_GAMEPAD_OFFSET(buttonsLength, buttons_length);
- DCHECK_GAMEPAD_OFFSET(buttons, buttons);
-
-#undef OFFSET_OF
-#undef DCHECK_GAMEPADS_OFFSET
-#undef DCHECK_GAMEPAD_OFFSET
-
- delegate()->SampleGamepads(reinterpret_cast<WebKit::WebGamepads*>(data));
+ PP_GamepadsSampleData_Dev* data) {
+ WebKit::WebGamepads webkit_data;
+ delegate()->SampleGamepads(&webkit_data);
+ ConvertWebKitGamepadData(webkit_data, data);
}
bool PluginInstance::IsViewAccelerated() {
diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.h b/webkit/plugins/ppapi/ppapi_plugin_instance.h
index 65f8475..b81a3e8 100644
--- a/webkit/plugins/ppapi/ppapi_plugin_instance.h
+++ b/webkit/plugins/ppapi/ppapi_plugin_instance.h
@@ -295,7 +295,7 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance :
bool IsRectTopmost(const gfx::Rect& rect);
// Implementation of PPB_Gamepad.
- void SampleGamepads(PP_Instance instance, PP_GamepadsData_Dev* data)
+ void SampleGamepads(PP_Instance instance, PP_GamepadsSampleData_Dev* data)
OVERRIDE;
// Implementation of PPP_Messaging.