Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ppapi / shared_impl / ppb_gamepad_shared.cc
blob2bf0b572acdbc50850c7786352da003c8c67fd47
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ppapi/shared_impl/ppb_gamepad_shared.h"
7 #include <algorithm>
9 #include "base/basictypes.h"
11 namespace ppapi {
13 const size_t WebKitGamepads::kItemsLengthCap;
15 void ConvertWebKitGamepadData(const WebKitGamepads& webkit_data,
16 PP_GamepadsSampleData* output_data) {
17 size_t length = std::min(WebKitGamepads::kItemsLengthCap,
18 static_cast<const size_t>(webkit_data.length));
19 output_data->length = static_cast<unsigned>(length);
20 for (unsigned i = 0; i < length; ++i) {
21 PP_GamepadSampleData& output_pad = output_data->items[i];
22 const WebKitGamepad& webkit_pad = webkit_data.items[i];
23 output_pad.connected = webkit_pad.connected ? PP_TRUE : PP_FALSE;
24 if (webkit_pad.connected) {
25 static_assert(sizeof(output_pad.id) == sizeof(webkit_pad.id),
26 "id size does not match");
27 memcpy(output_pad.id, webkit_pad.id, sizeof(output_pad.id));
28 output_pad.timestamp = static_cast<double>(webkit_pad.timestamp);
29 output_pad.axes_length = webkit_pad.axes_length;
30 for (unsigned j = 0; j < webkit_pad.axes_length; ++j)
31 output_pad.axes[j] = static_cast<float>(webkit_pad.axes[j]);
32 output_pad.buttons_length = webkit_pad.buttons_length;
33 for (unsigned j = 0; j < webkit_pad.buttons_length; ++j)
34 output_pad.buttons[j] = static_cast<float>(webkit_pad.buttons[j].value);
39 } // namespace ppapi