summaryrefslogtreecommitdiffstats
path: root/ppapi/examples
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 /ppapi/examples
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 'ppapi/examples')
-rw-r--r--ppapi/examples/gamepad/gamepad.cc47
1 files changed, 23 insertions, 24 deletions
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;
}