| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ppapi/shared_impl/ppb_gamepad_shared.h" | 5 #include "ppapi/shared_impl/ppb_gamepad_shared.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| 11 #include "device/gamepad/public/cpp/gamepads.h" |
| 12 |
| 11 namespace ppapi { | 13 namespace ppapi { |
| 12 | 14 |
| 13 const size_t WebKitGamepads::kItemsLengthCap; | 15 const size_t WebKitGamepads::kItemsLengthCap; |
| 14 | 16 |
| 17 // TODO: Remove this function and use ConvertDeviceGamepadData() instead. |
| 15 void ConvertWebKitGamepadData(const WebKitGamepads& webkit_data, | 18 void ConvertWebKitGamepadData(const WebKitGamepads& webkit_data, |
| 16 PP_GamepadsSampleData* output_data) { | 19 PP_GamepadsSampleData* output_data) { |
| 17 output_data->length = WebKitGamepads::kItemsLengthCap; | 20 output_data->length = WebKitGamepads::kItemsLengthCap; |
| 18 for (unsigned i = 0; i < WebKitGamepads::kItemsLengthCap; ++i) { | 21 for (unsigned i = 0; i < WebKitGamepads::kItemsLengthCap; ++i) { |
| 19 PP_GamepadSampleData& output_pad = output_data->items[i]; | 22 PP_GamepadSampleData& output_pad = output_data->items[i]; |
| 20 const WebKitGamepad& webkit_pad = webkit_data.items[i]; | 23 const WebKitGamepad& webkit_pad = webkit_data.items[i]; |
| 21 output_pad.connected = webkit_pad.connected ? PP_TRUE : PP_FALSE; | 24 output_pad.connected = webkit_pad.connected ? PP_TRUE : PP_FALSE; |
| 22 if (webkit_pad.connected) { | 25 if (webkit_pad.connected) { |
| 23 static_assert(sizeof(output_pad.id) == sizeof(webkit_pad.id), | 26 static_assert(sizeof(output_pad.id) == sizeof(webkit_pad.id), |
| 24 "id size does not match"); | 27 "id size does not match"); |
| 25 memcpy(output_pad.id, webkit_pad.id, sizeof(output_pad.id)); | 28 memcpy(output_pad.id, webkit_pad.id, sizeof(output_pad.id)); |
| 26 output_pad.timestamp = static_cast<double>(webkit_pad.timestamp); | 29 output_pad.timestamp = static_cast<double>(webkit_pad.timestamp); |
| 27 output_pad.axes_length = webkit_pad.axes_length; | 30 output_pad.axes_length = webkit_pad.axes_length; |
| 28 for (unsigned j = 0; j < webkit_pad.axes_length; ++j) | 31 for (unsigned j = 0; j < webkit_pad.axes_length; ++j) |
| 29 output_pad.axes[j] = static_cast<float>(webkit_pad.axes[j]); | 32 output_pad.axes[j] = static_cast<float>(webkit_pad.axes[j]); |
| 30 output_pad.buttons_length = webkit_pad.buttons_length; | 33 output_pad.buttons_length = webkit_pad.buttons_length; |
| 31 for (unsigned j = 0; j < webkit_pad.buttons_length; ++j) | 34 for (unsigned j = 0; j < webkit_pad.buttons_length; ++j) |
| 32 output_pad.buttons[j] = static_cast<float>(webkit_pad.buttons[j].value); | 35 output_pad.buttons[j] = static_cast<float>(webkit_pad.buttons[j].value); |
| 33 } | 36 } |
| 34 } | 37 } |
| 35 } | 38 } |
| 36 | 39 |
| 40 void ConvertDeviceGamepadData(const device::Gamepads& device_data, |
| 41 PP_GamepadsSampleData* output_data) { |
| 42 output_data->length = device::Gamepads::kItemsLengthCap; |
| 43 for (unsigned i = 0; i < device::Gamepads::kItemsLengthCap; ++i) { |
| 44 PP_GamepadSampleData& output_pad = output_data->items[i]; |
| 45 const device::Gamepad& device_pad = device_data.items[i]; |
| 46 output_pad.connected = device_pad.connected ? PP_TRUE : PP_FALSE; |
| 47 if (device_pad.connected) { |
| 48 static_assert(sizeof(output_pad.id) == sizeof(device_pad.id), |
| 49 "id size does not match"); |
| 50 memcpy(output_pad.id, device_pad.id, sizeof(output_pad.id)); |
| 51 output_pad.timestamp = static_cast<double>(device_pad.timestamp); |
| 52 output_pad.axes_length = device_pad.axes_length; |
| 53 for (unsigned j = 0; j < device_pad.axes_length; ++j) |
| 54 output_pad.axes[j] = static_cast<float>(device_pad.axes[j]); |
| 55 output_pad.buttons_length = device_pad.buttons_length; |
| 56 for (unsigned j = 0; j < device_pad.buttons_length; ++j) |
| 57 output_pad.buttons[j] = static_cast<float>(device_pad.buttons[j].value); |
| 58 } |
| 59 } |
| 60 } |
| 61 |
| 37 } // namespace ppapi | 62 } // namespace ppapi |
| OLD | NEW |