Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(746)

Unified Diff: ppapi/shared_impl/ppb_gamepad_shared.cc

Issue 2808093006: [Device Service] Move Gamepad Blink headers to be part of the Gamepad client library (Closed)
Patch Set: rebase and address comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ppapi/shared_impl/ppb_gamepad_shared.h ('k') | third_party/WebKit/Source/modules/gamepad/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/shared_impl/ppb_gamepad_shared.cc
diff --git a/ppapi/shared_impl/ppb_gamepad_shared.cc b/ppapi/shared_impl/ppb_gamepad_shared.cc
index 4ee0dd94761e3d20df3a029d4fda65fed7da78b5..12b732e55602b9ae87cc805c6152f7785ced665d 100644
--- a/ppapi/shared_impl/ppb_gamepad_shared.cc
+++ b/ppapi/shared_impl/ppb_gamepad_shared.cc
@@ -8,10 +8,13 @@
#include <algorithm>
+#include "device/gamepad/public/cpp/gamepads.h"
+
namespace ppapi {
const size_t WebKitGamepads::kItemsLengthCap;
+// TODO: Remove this function and use ConvertDeviceGamepadData() instead.
void ConvertWebKitGamepadData(const WebKitGamepads& webkit_data,
PP_GamepadsSampleData* output_data) {
output_data->length = WebKitGamepads::kItemsLengthCap;
@@ -34,4 +37,26 @@ void ConvertWebKitGamepadData(const WebKitGamepads& webkit_data,
}
}
+void ConvertDeviceGamepadData(const device::Gamepads& device_data,
+ PP_GamepadsSampleData* output_data) {
+ output_data->length = device::Gamepads::kItemsLengthCap;
+ for (unsigned i = 0; i < device::Gamepads::kItemsLengthCap; ++i) {
+ PP_GamepadSampleData& output_pad = output_data->items[i];
+ const device::Gamepad& device_pad = device_data.items[i];
+ output_pad.connected = device_pad.connected ? PP_TRUE : PP_FALSE;
+ if (device_pad.connected) {
+ static_assert(sizeof(output_pad.id) == sizeof(device_pad.id),
+ "id size does not match");
+ memcpy(output_pad.id, device_pad.id, sizeof(output_pad.id));
+ output_pad.timestamp = static_cast<double>(device_pad.timestamp);
+ output_pad.axes_length = device_pad.axes_length;
+ for (unsigned j = 0; j < device_pad.axes_length; ++j)
+ output_pad.axes[j] = static_cast<float>(device_pad.axes[j]);
+ output_pad.buttons_length = device_pad.buttons_length;
+ for (unsigned j = 0; j < device_pad.buttons_length; ++j)
+ output_pad.buttons[j] = static_cast<float>(device_pad.buttons[j].value);
+ }
+ }
+}
+
} // namespace ppapi
« no previous file with comments | « ppapi/shared_impl/ppb_gamepad_shared.h ('k') | third_party/WebKit/Source/modules/gamepad/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698