Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: content/browser/gamepad/gamepad_platform_data_fetcher_win.h

Issue 135523006: Implemented Gamepad support via Raw Input on Windows (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Features, fixes, and cleanups Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 13 #define DIRECTINPUT_VERSION 0x0800
14 #include <dinput.h> 14 #include <dinput.h>
15 #include <stdlib.h> 15 #include <stdlib.h>
16 #include <Unknwn.h> 16 #include <Unknwn.h>
17 #include <WinDef.h> 17 #include <WinDef.h>
18 #include <windows.h> 18 #include <windows.h>
19 #include <XInput.h> 19 #include <XInput.h>
20 20
21 #include "base/basictypes.h" 21 #include "base/basictypes.h"
22 #include "base/compiler_specific.h" 22 #include "base/compiler_specific.h"
23 #include "base/memory/scoped_ptr.h"
24 #include "base/memory/weak_ptr.h"
25 #include "base/message_loop/message_loop.h"
23 #include "base/scoped_native_library.h" 26 #include "base/scoped_native_library.h"
24 #include "content/browser/gamepad/gamepad_data_fetcher.h" 27 #include "content/browser/gamepad/gamepad_data_fetcher.h"
25 #include "content/browser/gamepad/gamepad_standard_mappings.h" 28 #include "content/browser/gamepad/gamepad_standard_mappings.h"
29 #include "content/browser/gamepad/raw_input_data_fetcher_win.h"
26 #include "third_party/WebKit/public/platform/WebGamepads.h" 30 #include "third_party/WebKit/public/platform/WebGamepads.h"
27 31
28 namespace content { 32 namespace content {
29 33
30 class GamepadPlatformDataFetcherWin : public GamepadDataFetcher { 34 class GamepadPlatformDataFetcherWin : public GamepadDataFetcher {
31 public: 35 public:
32 GamepadPlatformDataFetcherWin(); 36 GamepadPlatformDataFetcherWin();
33 virtual ~GamepadPlatformDataFetcherWin(); 37 virtual ~GamepadPlatformDataFetcherWin();
34 virtual void GetGamepadData(blink::WebGamepads* pads, 38 virtual void GetGamepadData(blink::WebGamepads* pads,
35 bool devices_changed_hint) OVERRIDE; 39 bool devices_changed_hint) OVERRIDE;
40 virtual void PauseHint(bool paused) OVERRIDE;
41
36 private: 42 private:
37 // XInput-specific implementation for GetGamepadData. 43 // XInput-specific implementation for GetGamepadData.
38 bool GetXInputGamepadData(blink::WebGamepads* pads, 44 bool GetXInputGamepadData(blink::WebGamepads* pads,
39 bool devices_changed_hint); 45 bool devices_changed_hint);
40 bool GetDirectInputGamepadData(blink::WebGamepads* pads, 46 bool GetDirectInputGamepadData(blink::WebGamepads* pads,
41 bool devices_changed_hint); 47 bool devices_changed_hint);
42 48
43 // The three function types we use from xinput1_3.dll. 49 // The three function types we use from xinput1_3.dll.
44 typedef void (WINAPI *XInputEnableFunc)(BOOL enable); 50 typedef void (WINAPI *XInputEnableFunc)(BOOL enable);
45 typedef DWORD (WINAPI *XInputGetCapabilitiesFunc)( 51 typedef DWORD (WINAPI *XInputGetCapabilitiesFunc)(
46 DWORD dwUserIndex, DWORD dwFlags, XINPUT_CAPABILITIES* pCapabilities); 52 DWORD dwUserIndex, DWORD dwFlags, XINPUT_CAPABILITIES* pCapabilities);
47 typedef DWORD (WINAPI *XInputGetStateFunc)( 53 typedef DWORD (WINAPI *XInputGetStateFunc)(
48 DWORD dwUserIndex, XINPUT_STATE* pState); 54 DWORD dwUserIndex, XINPUT_STATE* pState);
49 55
50 // 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
51 // 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
52 // isn't redistributable. Returns true if loading was successful. We include 58 // isn't redistributable. Returns true if loading was successful. We include
53 // xinput1_3.dll with Chrome. 59 // xinput1_3.dll with Chrome.
54 bool GetXInputDllFunctions(); 60 bool GetXInputDllFunctions();
55 61
56 // Scan for connected XInput and DirectInput gamepads. 62 // Scan for connected XInput and DirectInput gamepads.
57 void EnumerateDevices(blink::WebGamepads* pads); 63 void EnumerateDevices(blink::WebGamepads* pads);
58 bool GetXInputPadConnectivity(int i, blink::WebGamepad* pad) const; 64 bool GetXInputPadConnectivity(int i, blink::WebGamepad* pad) const;
59 65
60 void GetXInputPadData(int i, blink::WebGamepad* pad); 66 void GetXInputPadData(int i, blink::WebGamepad* pad);
61 void GetDirectInputPadData(int i, blink::WebGamepad* pad); 67 void GetDirectInputPadData(int i, blink::WebGamepad* pad);
68 void GetRawInputPadData(int i, blink::WebGamepad* pad);
62 69
63 int FirstAvailableGamepadId() const; 70 int FirstAvailableGamepadId() const;
64 bool HasXInputGamepad(int index) const; 71 bool HasXInputGamepad(int index) const;
65 bool HasDirectInputGamepad(const GUID &guid) const; 72 bool HasDirectInputGamepad(const GUID &guid) const;
73 bool HasRawInputGamepad(const HANDLE handle) const;
66 74
67 base::ScopedNativeLibrary xinput_dll_; 75 base::ScopedNativeLibrary xinput_dll_;
68 bool xinput_available_; 76 bool xinput_available_;
69 bool directinput_available_; 77 bool directinput_available_;
70 78
71 // Function pointers to XInput functionality, retrieved in 79 // Function pointers to XInput functionality, retrieved in
72 // |GetXinputDllFunctions|. 80 // |GetXinputDllFunctions|.
73 XInputEnableFunc xinput_enable_; 81 XInputEnableFunc xinput_enable_;
74 XInputGetCapabilitiesFunc xinput_get_capabilities_; 82 XInputGetCapabilitiesFunc xinput_get_capabilities_;
75 XInputGetStateFunc xinput_get_state_; 83 XInputGetStateFunc xinput_get_state_;
76 84
77 IDirectInput8* directinput_interface_; 85 IDirectInput8* directinput_interface_;
78 86
79 enum PadConnectionStatus { 87 enum PadConnectionStatus {
80 DISCONNECTED, 88 DISCONNECTED,
81 XINPUT_CONNECTED, 89 XINPUT_CONNECTED,
82 DIRECTINPUT_CONNECTED 90 DIRECTINPUT_CONNECTED,
91 RAWINPUT_CONNECTED
83 }; 92 };
84 93
85 struct PadState { 94 struct PadState {
86 PadConnectionStatus status; 95 PadConnectionStatus status;
87 int xinput_index; // XInput-only. 96 GamepadStandardMappingFunction mapper;
88 // Fields below are for DirectInput devices only. 97
98 // XInput-only fields.
99 int xinput_index;
100 // DirectInput-only fields.
89 GUID guid; 101 GUID guid;
90 IDirectInputDevice8* directinput_gamepad; 102 IDirectInputDevice8* directinput_gamepad;
91 GamepadStandardMappingFunction mapper; 103 // RawInput-only fields.
104 HANDLE handle;
92 }; 105 };
93 PadState pad_state_[blink::WebGamepads::itemsLengthCap]; 106 PadState pad_state_[blink::WebGamepads::itemsLengthCap];
107 blink::WebGamepads data_;
scottmg 2014/01/31 20:51:10 i don't like storing this state here. does Raw nee
108
109 scoped_ptr<RawInputDataFetcher> raw_input_fetcher_;
94 110
95 DISALLOW_COPY_AND_ASSIGN(GamepadPlatformDataFetcherWin); 111 DISALLOW_COPY_AND_ASSIGN(GamepadPlatformDataFetcherWin);
96 }; 112 };
97 113
98 } // namespace content 114 } // namespace content
99 115
100 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_WIN_H_ 116 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698