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 #ifndef DEVICE_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_WIN_H_ | 5 #ifndef DEVICE_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_WIN_H_ |
6 #define DEVICE_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_WIN_H_ | 6 #define DEVICE_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_WIN_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 | 11 |
12 #ifndef WIN32_LEAN_AND_MEAN | 12 #ifndef WIN32_LEAN_AND_MEAN |
13 #define WIN32_LEAN_AND_MEAN | 13 #define WIN32_LEAN_AND_MEAN |
14 #endif | 14 #endif |
15 #include <Unknwn.h> | 15 #include <Unknwn.h> |
16 #include <WinDef.h> | 16 #include <WinDef.h> |
17 #include <XInput.h> | 17 #include <XInput.h> |
18 #include <stdlib.h> | 18 #include <stdlib.h> |
19 #include <windows.h> | 19 #include <windows.h> |
20 | 20 |
21 #include "base/compiler_specific.h" | 21 #include "base/compiler_specific.h" |
22 #include "base/macros.h" | 22 #include "base/macros.h" |
23 #include "base/memory/weak_ptr.h" | 23 #include "base/memory/weak_ptr.h" |
24 #include "base/message_loop/message_loop.h" | 24 #include "base/message_loop/message_loop.h" |
25 #include "base/scoped_native_library.h" | 25 #include "base/scoped_native_library.h" |
26 #include "device/gamepad/gamepad_data_fetcher.h" | 26 #include "device/gamepad/gamepad_data_fetcher.h" |
27 #include "device/gamepad/gamepad_standard_mappings.h" | 27 #include "device/gamepad/gamepad_standard_mappings.h" |
28 #include "device/gamepad/raw_input_data_fetcher_win.h" | |
29 #include "third_party/WebKit/public/platform/WebGamepads.h" | 28 #include "third_party/WebKit/public/platform/WebGamepads.h" |
30 | 29 |
31 namespace device { | 30 namespace device { |
32 | 31 |
33 class GamepadPlatformDataFetcherWin : public GamepadDataFetcher { | 32 class GamepadPlatformDataFetcherWin : public GamepadDataFetcher { |
34 public: | 33 public: |
| 34 typedef GamepadDataFetcherFactoryImpl<GamepadPlatformDataFetcherWin, |
| 35 GAMEPAD_SOURCE_WIN_XINPUT> |
| 36 Factory; |
| 37 |
35 GamepadPlatformDataFetcherWin(); | 38 GamepadPlatformDataFetcherWin(); |
36 ~GamepadPlatformDataFetcherWin() override; | 39 ~GamepadPlatformDataFetcherWin() override; |
37 void GetGamepadData(blink::WebGamepads* pads, | 40 |
38 bool devices_changed_hint) override; | 41 GamepadSource source() override; |
39 void PauseHint(bool paused) override; | 42 |
| 43 void GetGamepadData(bool devices_changed_hint) override; |
40 | 44 |
41 private: | 45 private: |
42 // XInput-specific implementation for GetGamepadData. | 46 void OnAddedToProvider() override; |
43 bool GetXInputGamepadData(blink::WebGamepads* pads, | |
44 bool devices_changed_hint); | |
45 | 47 |
46 // The three function types we use from xinput1_3.dll. | 48 // The three function types we use from xinput1_3.dll. |
47 typedef void(WINAPI* XInputEnableFunc)(BOOL enable); | 49 typedef void(WINAPI* XInputEnableFunc)(BOOL enable); |
48 typedef DWORD(WINAPI* XInputGetCapabilitiesFunc)( | 50 typedef DWORD(WINAPI* XInputGetCapabilitiesFunc)( |
49 DWORD dwUserIndex, | 51 DWORD dwUserIndex, |
50 DWORD dwFlags, | 52 DWORD dwFlags, |
51 XINPUT_CAPABILITIES* pCapabilities); | 53 XINPUT_CAPABILITIES* pCapabilities); |
52 typedef DWORD(WINAPI* XInputGetStateFunc)(DWORD dwUserIndex, | 54 typedef DWORD(WINAPI* XInputGetStateFunc)(DWORD dwUserIndex, |
53 XINPUT_STATE* pState); | 55 XINPUT_STATE* pState); |
54 | 56 |
55 // Get functions from dynamically loading the xinput dll. | 57 // Get functions from dynamically loading the xinput dll. |
56 // Returns true if loading was successful. | 58 // Returns true if loading was successful. |
57 bool GetXInputDllFunctions(); | 59 bool GetXInputDllFunctions(); |
58 | 60 |
59 // Scan for connected XInput and DirectInput gamepads. | 61 // Scan for connected XInput and DirectInput gamepads. |
60 void EnumerateDevices(); | 62 void EnumerateDevices(); |
61 bool GetXInputPadConnectivity(int i, blink::WebGamepad* pad) const; | 63 void GetXInputPadData(int i); |
62 | |
63 void GetXInputPadData(int i, blink::WebGamepad* pad); | |
64 void GetRawInputPadData(int i, blink::WebGamepad* pad); | |
65 | |
66 int FirstAvailableGamepadId() const; | |
67 bool HasXInputGamepad(int index) const; | |
68 bool HasRawInputGamepad(const HANDLE handle) const; | |
69 | 64 |
70 base::ScopedNativeLibrary xinput_dll_; | 65 base::ScopedNativeLibrary xinput_dll_; |
71 bool xinput_available_; | 66 bool xinput_available_; |
72 | 67 |
73 // Function pointers to XInput functionality, retrieved in | 68 // Function pointers to XInput functionality, retrieved in |
74 // |GetXinputDllFunctions|. | 69 // |GetXinputDllFunctions|. |
75 XInputGetCapabilitiesFunc xinput_get_capabilities_; | 70 XInputGetCapabilitiesFunc xinput_get_capabilities_; |
76 XInputGetStateFunc xinput_get_state_; | 71 XInputGetStateFunc xinput_get_state_; |
77 | 72 |
78 enum PadConnectionStatus { | 73 bool xinuput_connected_[XUSER_MAX_COUNT]; |
79 DISCONNECTED, | |
80 XINPUT_CONNECTED, | |
81 RAWINPUT_CONNECTED | |
82 }; | |
83 | |
84 struct PlatformPadState { | |
85 PadConnectionStatus status; | |
86 | |
87 int xinput_index; // XInput-only | |
88 HANDLE raw_input_handle; // RawInput-only fields. | |
89 }; | |
90 PlatformPadState platform_pad_state_[blink::WebGamepads::itemsLengthCap]; | |
91 | |
92 std::unique_ptr<RawInputDataFetcher> raw_input_fetcher_; | |
93 | 74 |
94 DISALLOW_COPY_AND_ASSIGN(GamepadPlatformDataFetcherWin); | 75 DISALLOW_COPY_AND_ASSIGN(GamepadPlatformDataFetcherWin); |
95 }; | 76 }; |
96 | 77 |
97 } // namespace device | 78 } // namespace device |
98 | 79 |
99 #endif // DEVICE_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_WIN_H_ | 80 #endif // DEVICE_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_WIN_H_ |
OLD | NEW |