OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CONTENT_BROWSER_GAMEPAD_GAMEPAD_DATA_FETCHER_H_ | 5 #ifndef DEVICE_GAMEPAD_GAMEPAD_DATA_FETCHER_H_ |
6 #define CONTENT_BROWSER_GAMEPAD_GAMEPAD_DATA_FETCHER_H_ | 6 #define DEVICE_GAMEPAD_GAMEPAD_DATA_FETCHER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
| 10 #include <limits> |
| 11 |
10 #include "build/build_config.h" | 12 #include "build/build_config.h" |
11 #include "content/browser/gamepad/gamepad_standard_mappings.h" | 13 #include "device/gamepad/gamepad_standard_mappings.h" |
12 #include "third_party/WebKit/public/platform/WebGamepads.h" | 14 #include "third_party/WebKit/public/platform/WebGamepads.h" |
13 | 15 |
14 namespace content { | 16 namespace device { |
15 | 17 |
16 // Abstract interface for imlementing platform- (and test-) specific behaviro | 18 // Abstract interface for imlementing platform- (and test-) specific behaviro |
17 // for getting the gamepad data. | 19 // for getting the gamepad data. |
18 class GamepadDataFetcher { | 20 class GamepadDataFetcher { |
19 public: | 21 public: |
20 virtual ~GamepadDataFetcher() {} | 22 virtual ~GamepadDataFetcher() {} |
21 virtual void GetGamepadData(blink::WebGamepads* pads, | 23 virtual void GetGamepadData(blink::WebGamepads* pads, |
22 bool devices_changed_hint) = 0; | 24 bool devices_changed_hint) = 0; |
23 virtual void PauseHint(bool paused) {} | 25 virtual void PauseHint(bool paused) {} |
24 | 26 |
25 #if !defined(OS_ANDROID) | 27 #if !defined(OS_ANDROID) |
26 struct PadState { | 28 struct PadState { |
27 // Gamepad data, unmapped. | 29 // Gamepad data, unmapped. |
28 blink::WebGamepad data; | 30 blink::WebGamepad data; |
29 | 31 |
30 // Functions to map from device data to standard layout, if available. May | 32 // Functions to map from device data to standard layout, if available. May |
31 // be null if no mapping is available. | 33 // be null if no mapping is available. |
32 GamepadStandardMappingFunction mapper; | 34 GamepadStandardMappingFunction mapper; |
33 | 35 |
34 // Sanitization masks | 36 // Sanitization masks |
35 // axis_mask and button_mask are bitfields that represent the reset state of | 37 // axis_mask and button_mask are bitfields that represent the reset state of |
36 // each input. If a button or axis has ever reported 0 in the past the | 38 // each input. If a button or axis has ever reported 0 in the past the |
37 // corresponding bit will be set to 1. | 39 // corresponding bit will be set to 1. |
38 | 40 |
39 // If we ever increase the max axis count this will need to be updated. | 41 // If we ever increase the max axis count this will need to be updated. |
40 static_assert(blink::WebGamepad::axesLengthCap <= | 42 static_assert(blink::WebGamepad::axesLengthCap <= |
41 std::numeric_limits<uint32_t>::digits, | 43 std::numeric_limits<uint32_t>::digits, |
42 "axis_mask is not large enough"); | 44 "axis_mask is not large enough"); |
43 uint32_t axis_mask; | 45 uint32_t axis_mask; |
44 | 46 |
45 // If we ever increase the max button count this will need to be updated. | 47 // If we ever increase the max button count this will need to be updated. |
46 static_assert(blink::WebGamepad::buttonsLengthCap <= | 48 static_assert(blink::WebGamepad::buttonsLengthCap <= |
47 std::numeric_limits<uint32_t>::digits, | 49 std::numeric_limits<uint32_t>::digits, |
48 "button_mask is not large enough"); | 50 "button_mask is not large enough"); |
49 uint32_t button_mask; | 51 uint32_t button_mask; |
50 }; | 52 }; |
51 | 53 |
52 void MapAndSanitizeGamepadData(PadState* pad_state, blink::WebGamepad* pad); | 54 void MapAndSanitizeGamepadData(PadState* pad_state, blink::WebGamepad* pad); |
53 | 55 |
54 protected: | 56 protected: |
55 PadState pad_state_[blink::WebGamepads::itemsLengthCap]; | 57 PadState pad_state_[blink::WebGamepads::itemsLengthCap]; |
56 #endif | 58 #endif |
57 }; | 59 }; |
58 | 60 |
59 } // namespace content | 61 } // namespace device |
60 | 62 |
61 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_DATA_FETCHER_H_ | 63 #endif // DEVICE_GAMEPAD_GAMEPAD_DATA_FETCHER_H_ |
OLD | NEW |