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

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: Rebase 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
« no previous file with comments | « no previous file | content/browser/gamepad/gamepad_platform_data_fetcher_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include <stdlib.h> 13 #include <stdlib.h>
14 #include <Unknwn.h> 14 #include <Unknwn.h>
15 #include <WinDef.h> 15 #include <WinDef.h>
16 #include <windows.h> 16 #include <windows.h>
17 #include <XInput.h> 17 #include <XInput.h>
18 18
19 #include "base/basictypes.h" 19 #include "base/basictypes.h"
20 #include "base/compiler_specific.h" 20 #include "base/compiler_specific.h"
21 #include "base/memory/scoped_ptr.h"
22 #include "base/memory/weak_ptr.h"
23 #include "base/message_loop/message_loop.h"
21 #include "base/scoped_native_library.h" 24 #include "base/scoped_native_library.h"
22 #include "content/browser/gamepad/gamepad_data_fetcher.h" 25 #include "content/browser/gamepad/gamepad_data_fetcher.h"
23 #include "content/browser/gamepad/gamepad_standard_mappings.h" 26 #include "content/browser/gamepad/gamepad_standard_mappings.h"
27 #include "content/browser/gamepad/raw_input_data_fetcher_win.h"
24 #include "third_party/WebKit/public/platform/WebGamepads.h" 28 #include "third_party/WebKit/public/platform/WebGamepads.h"
25 29
26 namespace content { 30 namespace content {
27 31
28 class GamepadPlatformDataFetcherWin : public GamepadDataFetcher { 32 class GamepadPlatformDataFetcherWin : public GamepadDataFetcher {
29 public: 33 public:
30 GamepadPlatformDataFetcherWin(); 34 GamepadPlatformDataFetcherWin();
31 virtual ~GamepadPlatformDataFetcherWin(); 35 virtual ~GamepadPlatformDataFetcherWin();
32 virtual void GetGamepadData(blink::WebGamepads* pads, 36 virtual void GetGamepadData(blink::WebGamepads* pads,
33 bool devices_changed_hint) OVERRIDE; 37 bool devices_changed_hint) OVERRIDE;
38 virtual void PauseHint(bool paused) OVERRIDE;
39
34 private: 40 private:
35 // XInput-specific implementation for GetGamepadData. 41 // XInput-specific implementation for GetGamepadData.
36 bool GetXInputGamepadData(blink::WebGamepads* pads, 42 bool GetXInputGamepadData(blink::WebGamepads* pads,
37 bool devices_changed_hint); 43 bool devices_changed_hint);
38 44
39 // The three function types we use from xinput1_3.dll. 45 // The three function types we use from xinput1_3.dll.
40 typedef void (WINAPI *XInputEnableFunc)(BOOL enable); 46 typedef void (WINAPI *XInputEnableFunc)(BOOL enable);
41 typedef DWORD (WINAPI *XInputGetCapabilitiesFunc)( 47 typedef DWORD (WINAPI *XInputGetCapabilitiesFunc)(
42 DWORD dwUserIndex, DWORD dwFlags, XINPUT_CAPABILITIES* pCapabilities); 48 DWORD dwUserIndex, DWORD dwFlags, XINPUT_CAPABILITIES* pCapabilities);
43 typedef DWORD (WINAPI *XInputGetStateFunc)( 49 typedef DWORD (WINAPI *XInputGetStateFunc)(
44 DWORD dwUserIndex, XINPUT_STATE* pState); 50 DWORD dwUserIndex, XINPUT_STATE* pState);
45 51
46 // Get functions from dynamically loaded xinput1_3.dll. We don't use 52 // Get functions from dynamically loaded xinput1_3.dll. We don't use
47 // DELAYLOAD because the import library for Win8 SDK pulls xinput1_4 which 53 // DELAYLOAD because the import library for Win8 SDK pulls xinput1_4 which
48 // isn't redistributable. Returns true if loading was successful. We include 54 // isn't redistributable. Returns true if loading was successful. We include
49 // xinput1_3.dll with Chrome. 55 // xinput1_3.dll with Chrome.
50 bool GetXInputDllFunctions(); 56 bool GetXInputDllFunctions();
51 57
52 // Scan for connected XInput and DirectInput gamepads. 58 // Scan for connected XInput and DirectInput gamepads.
53 void EnumerateDevices(blink::WebGamepads* pads); 59 void EnumerateDevices(blink::WebGamepads* pads);
54 bool GetXInputPadConnectivity(int i, blink::WebGamepad* pad) const; 60 bool GetXInputPadConnectivity(int i, blink::WebGamepad* pad) const;
55 61
56 void GetXInputPadData(int i, blink::WebGamepad* pad); 62 void GetXInputPadData(int i, blink::WebGamepad* pad);
63 void GetRawInputPadData(int i, blink::WebGamepad* pad);
57 64
58 int FirstAvailableGamepadId() const; 65 int FirstAvailableGamepadId() const;
59 bool HasXInputGamepad(int index) const; 66 bool HasXInputGamepad(int index) const;
67 bool HasRawInputGamepad(const HANDLE handle) const;
60 68
61 base::ScopedNativeLibrary xinput_dll_; 69 base::ScopedNativeLibrary xinput_dll_;
62 bool xinput_available_; 70 bool xinput_available_;
63 71
64 // Function pointers to XInput functionality, retrieved in 72 // Function pointers to XInput functionality, retrieved in
65 // |GetXinputDllFunctions|. 73 // |GetXinputDllFunctions|.
66 XInputEnableFunc xinput_enable_; 74 XInputEnableFunc xinput_enable_;
67 XInputGetCapabilitiesFunc xinput_get_capabilities_; 75 XInputGetCapabilitiesFunc xinput_get_capabilities_;
68 XInputGetStateFunc xinput_get_state_; 76 XInputGetStateFunc xinput_get_state_;
69 77
70 enum PadConnectionStatus { 78 enum PadConnectionStatus {
71 DISCONNECTED, 79 DISCONNECTED,
72 XINPUT_CONNECTED 80 XINPUT_CONNECTED,
81 RAWINPUT_CONNECTED
73 }; 82 };
74 83
75 struct PadState { 84 struct PadState {
76 PadConnectionStatus status; 85 PadConnectionStatus status;
77 int xinput_index; // XInput-only.
78 GamepadStandardMappingFunction mapper; 86 GamepadStandardMappingFunction mapper;
87
88 int xinput_index; // XInput-only
89 HANDLE raw_input_handle; // RawInput-only fields.
79 }; 90 };
80 PadState pad_state_[blink::WebGamepads::itemsLengthCap]; 91 PadState pad_state_[blink::WebGamepads::itemsLengthCap];
81 92
93 scoped_ptr<RawInputDataFetcher> raw_input_fetcher_;
94
82 DISALLOW_COPY_AND_ASSIGN(GamepadPlatformDataFetcherWin); 95 DISALLOW_COPY_AND_ASSIGN(GamepadPlatformDataFetcherWin);
83 }; 96 };
84 97
85 } // namespace content 98 } // namespace content
86 99
87 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_WIN_H_ 100 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_WIN_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/gamepad/gamepad_platform_data_fetcher_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698