| 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 CONTENT_BROWSER_GAMEPAD_GAMEPAD_DATA_FETCHER_H_ |
| 6 #define CONTENT_BROWSER_GAMEPAD_GAMEPAD_DATA_FETCHER_H_ | 6 #define CONTENT_BROWSER_GAMEPAD_GAMEPAD_DATA_FETCHER_H_ |
| 7 | 7 |
| 8 #include "content/browser/gamepad/gamepad_provider.h" | 8 #include <stdint.h> |
| 9 #include "content/common/content_export.h" | 9 |
| 10 #include "build/build_config.h" |
| 11 #include "content/browser/gamepad/gamepad_standard_mappings.h" |
| 12 #include "third_party/WebKit/public/platform/WebGamepads.h" |
| 10 | 13 |
| 11 namespace content { | 14 namespace content { |
| 12 | 15 |
| 13 // Abstract interface for imlementing platform- (and test-) specific behavior | 16 // Abstract interface for imlementing platform- (and test-) specific behaviro |
| 14 // for getting the gamepad data. | 17 // for getting the gamepad data. |
| 15 class CONTENT_EXPORT GamepadDataFetcher { | 18 class GamepadDataFetcher { |
| 16 public: | 19 public: |
| 17 GamepadDataFetcher(); | |
| 18 virtual ~GamepadDataFetcher() {} | 20 virtual ~GamepadDataFetcher() {} |
| 19 | 21 virtual void GetGamepadData(blink::WebGamepads* pads, |
| 20 virtual void GetGamepadData(bool devices_changed_hint) = 0; | 22 bool devices_changed_hint) = 0; |
| 21 virtual void PauseHint(bool paused) {} | 23 virtual void PauseHint(bool paused) {} |
| 22 | 24 |
| 23 GamepadProvider* provider() { return provider_; } | 25 #if !defined(OS_ANDROID) |
| 26 struct PadState { |
| 27 // Gamepad data, unmapped. |
| 28 blink::WebGamepad data; |
| 29 |
| 30 // Functions to map from device data to standard layout, if available. May |
| 31 // be null if no mapping is available. |
| 32 GamepadStandardMappingFunction mapper; |
| 33 |
| 34 // Sanitization masks |
| 35 // 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 |
| 37 // corresponding bit will be set to 1. |
| 38 |
| 39 // If we ever increase the max axis count this will need to be updated. |
| 40 static_assert(blink::WebGamepad::axesLengthCap <= |
| 41 std::numeric_limits<uint32_t>::digits, |
| 42 "axis_mask is not large enough"); |
| 43 uint32_t axis_mask; |
| 44 |
| 45 // If we ever increase the max button count this will need to be updated. |
| 46 static_assert(blink::WebGamepad::buttonsLengthCap <= |
| 47 std::numeric_limits<uint32_t>::digits, |
| 48 "button_mask is not large enough"); |
| 49 uint32_t button_mask; |
| 50 }; |
| 51 |
| 52 void MapAndSanitizeGamepadData(PadState* pad_state, blink::WebGamepad* pad); |
| 24 | 53 |
| 25 protected: | 54 protected: |
| 26 friend GamepadProvider; | 55 PadState pad_state_[blink::WebGamepads::itemsLengthCap]; |
| 27 | 56 #endif |
| 28 // To be called by the GamepadProvider on the polling thread; | |
| 29 void InitializeProvider(GamepadProvider* provider); | |
| 30 | |
| 31 // This call will happen on the gamepad polling thread. Any initialization | |
| 32 // that needs to happen on that thread should be done here, not in the | |
| 33 // constructor. | |
| 34 virtual void OnAddedToProvider() {} | |
| 35 | |
| 36 private: | |
| 37 GamepadProvider* provider_; | |
| 38 }; | 57 }; |
| 39 | 58 |
| 40 } // namespace content | 59 } // namespace content |
| 41 | 60 |
| 42 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_DATA_FETCHER_H_ | 61 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_DATA_FETCHER_H_ |
| OLD | NEW |