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 CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_WIN_H_ | 5 #ifndef CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_WIN_H_ |
6 #define CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_WIN_H_ | 6 #define CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_WIN_H_ |
7 | 7 |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 | 9 |
10 #ifndef WIN32_LEAN_AND_MEAN | 10 #ifndef WIN32_LEAN_AND_MEAN |
11 #define WIN32_LEAN_AND_MEAN | 11 #define WIN32_LEAN_AND_MEAN |
12 #endif | 12 #endif |
13 #define DIRECTINPUT_VERSION 0x0800 | |
14 #include <dinput.h> | |
15 #include <stdlib.h> | |
16 #include <Unknwn.h> | |
17 #include <WinDef.h> | |
13 #include <windows.h> | 18 #include <windows.h> |
14 #include <XInput.h> | 19 #include <XInput.h> |
15 | 20 |
16 #include "base/basictypes.h" | 21 #include "base/basictypes.h" |
17 #include "base/compiler_specific.h" | 22 #include "base/compiler_specific.h" |
18 #include "base/scoped_native_library.h" | 23 #include "base/scoped_native_library.h" |
19 #include "content/browser/gamepad/gamepad_data_fetcher.h" | 24 #include "content/browser/gamepad/gamepad_data_fetcher.h" |
25 #include "content/browser/gamepad/gamepad_standard_mappings.h" | |
26 | |
27 // struct DIDEVICEINSTANCE; | |
28 // struct IDirectInput8; | |
29 //struct IDirectInputDevice8; | |
scottmg
2013/02/13 19:19:07
nit: delete these
| |
30 namespace WebKit { | |
31 class WebGamepad; | |
32 } | |
20 | 33 |
21 namespace content { | 34 namespace content { |
22 | 35 |
23 class GamepadPlatformDataFetcherWin : public GamepadDataFetcher { | 36 class GamepadPlatformDataFetcherWin : public GamepadDataFetcher { |
24 public: | 37 public: |
25 GamepadPlatformDataFetcherWin(); | 38 GamepadPlatformDataFetcherWin(); |
26 virtual ~GamepadPlatformDataFetcherWin(); | 39 virtual ~GamepadPlatformDataFetcherWin(); |
27 virtual void GetGamepadData(WebKit::WebGamepads* pads, | 40 virtual void GetGamepadData(WebKit::WebGamepads* pads, |
28 bool devices_changed_hint) OVERRIDE; | 41 bool devices_changed_hint) OVERRIDE; |
29 private: | 42 private: |
43 // XInput-specific implementation for GetGamepadData. | |
44 bool GetXInputGamepadData(WebKit::WebGamepads* pads, | |
45 bool devices_changed_hint); | |
46 bool GetDirectInputGamepadData(WebKit::WebGamepads* pads, | |
47 bool devices_changed_hint); | |
48 | |
30 // The three function types we use from xinput1_3.dll. | 49 // The three function types we use from xinput1_3.dll. |
31 typedef void (WINAPI *XInputEnableFunc)(BOOL enable); | 50 typedef void (WINAPI *XInputEnableFunc)(BOOL enable); |
32 typedef DWORD (WINAPI *XInputGetCapabilitiesFunc)( | 51 typedef DWORD (WINAPI *XInputGetCapabilitiesFunc)( |
33 DWORD dwUserIndex, DWORD dwFlags, XINPUT_CAPABILITIES* pCapabilities); | 52 DWORD dwUserIndex, DWORD dwFlags, XINPUT_CAPABILITIES* pCapabilities); |
34 typedef DWORD (WINAPI *XInputGetStateFunc)( | 53 typedef DWORD (WINAPI *XInputGetStateFunc)( |
35 DWORD dwUserIndex, XINPUT_STATE* pState); | 54 DWORD dwUserIndex, XINPUT_STATE* pState); |
36 | 55 |
37 // Get functions from dynamically loaded xinput1_3.dll. We don't use | 56 // Get functions from dynamically loaded xinput1_3.dll. We don't use |
38 // DELAYLOAD because the import library for Win8 SDK pulls xinput1_4 which | 57 // DELAYLOAD because the import library for Win8 SDK pulls xinput1_4 which |
39 // isn't redistributable. Returns true if loading was successful. We include | 58 // isn't redistributable. Returns true if loading was successful. We include |
40 // xinput1_3.dll with Chrome. | 59 // xinput1_3.dll with Chrome. |
41 bool GetXinputDllFunctions(); | 60 bool GetXInputDllFunctions(); |
61 | |
62 bool GetDirectInputDllFunctions(); | |
63 | |
64 // Scan for connected XInput and DirectInput gamepads. | |
65 void EnumerateDevices(WebKit::WebGamepads* pads); | |
66 bool GetXInputPadConnectivity(int i, WebKit::WebGamepad* pad) const; | |
67 | |
68 void GetXInputPadData(int i, WebKit::WebGamepad* pad); | |
69 void GetDirectInputPadData(int i, WebKit::WebGamepad* pad); | |
42 | 70 |
43 base::ScopedNativeLibrary xinput_dll_; | 71 base::ScopedNativeLibrary xinput_dll_; |
44 bool xinput_available_; | 72 bool xinput_available_; |
45 | 73 |
46 // Function pointers to XInput functionality, retrieved in | 74 // Function pointers to XInput functionality, retrieved in |
47 // |GetXinputDllFunctions|. | 75 // |GetXinputDllFunctions|. |
48 XInputEnableFunc xinput_enable_; | 76 XInputEnableFunc xinput_enable_; |
49 XInputGetCapabilitiesFunc xinput_get_capabilities_; | 77 XInputGetCapabilitiesFunc xinput_get_capabilities_; |
50 XInputGetStateFunc xinput_get_state_; | 78 XInputGetStateFunc xinput_get_state_; |
51 | 79 |
80 std::vector<uint32> xinput_devices_; | |
81 typedef HRESULT (WINAPI *DirectInputCreateFunc)(HINSTANCE hinst, | |
82 DWORD dwVersion, | |
83 const IID& riidltf, | |
84 void** ppvOut, | |
85 IUnknown* punkOuter); | |
86 DirectInputCreateFunc directinput_create_; | |
87 base::ScopedNativeLibrary directinput_dll_; | |
88 bool directinput_available_; | |
89 IDirectInput8* directinput_interface_; | |
90 | |
91 enum PadConnectionStatus { | |
92 DISCONNECTED, | |
93 XINPUT_CONNECTED, | |
94 DIRECTINPUT_CONNECTED | |
95 }; | |
96 | |
97 struct PadState { | |
98 PadConnectionStatus status; | |
99 // Fields below are for DirectInput devices only. | |
100 IDirectInputDevice8* directinput_gamepad; | |
101 GamepadStandardMappingFunction mapper; | |
102 }; | |
103 std::vector<PadState> pad_state_; | |
104 | |
52 DISALLOW_COPY_AND_ASSIGN(GamepadPlatformDataFetcherWin); | 105 DISALLOW_COPY_AND_ASSIGN(GamepadPlatformDataFetcherWin); |
53 }; | 106 }; |
54 | 107 |
55 } // namespace content | 108 } // namespace content |
56 | 109 |
57 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_WIN_H_ | 110 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_WIN_H_ |
OLD | NEW |