summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorscottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-01 06:44:51 +0000
committerscottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-01 06:44:51 +0000
commit957c93abd8af4170e5da2d5d0f0862e46cb8491e (patch)
tree49a5c7b114c65c8531041c008f6f9c77c3fd7c8e /webkit
parent78b0b3703719ceba85cf99d8e5f27424c57e796c (diff)
downloadchromium_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 'webkit')
-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
4 files changed, 39 insertions, 43 deletions
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.