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

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

Issue 1586663006: Refactoring gamepad polling to support dynamically added sources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Avoid crash on Android content_unittests Created 4 years, 11 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
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/compiler_specific.h" 19 #include "base/compiler_specific.h"
20 #include "base/macros.h" 20 #include "base/macros.h"
21 #include "base/memory/scoped_ptr.h" 21 #include "base/memory/scoped_ptr.h"
22 #include "base/memory/weak_ptr.h" 22 #include "base/memory/weak_ptr.h"
23 #include "base/message_loop/message_loop.h" 23 #include "base/message_loop/message_loop.h"
24 #include "base/scoped_native_library.h" 24 #include "base/scoped_native_library.h"
25 #include "content/browser/gamepad/gamepad_data_fetcher.h" 25 #include "content/browser/gamepad/gamepad_data_fetcher.h"
26 #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"
28 #include "third_party/WebKit/public/platform/WebGamepads.h" 27 #include "third_party/WebKit/public/platform/WebGamepads.h"
29 28
30 namespace content { 29 namespace content {
31 30
32 class GamepadPlatformDataFetcherWin : public GamepadDataFetcher { 31 class GamepadPlatformDataFetcherWin : public GamepadDataFetcher {
33 public: 32 public:
34 GamepadPlatformDataFetcherWin(); 33 GamepadPlatformDataFetcherWin();
35 ~GamepadPlatformDataFetcherWin() override; 34 ~GamepadPlatformDataFetcherWin() override;
36 void GetGamepadData(blink::WebGamepads* pads, 35 void GetGamepadData(bool devices_changed_hint) override;
37 bool devices_changed_hint) override;
38 void PauseHint(bool paused) override;
39 36
40 private: 37 private:
41 // XInput-specific implementation for GetGamepadData. 38 void OnAddedToProvider() override;
42 bool GetXInputGamepadData(blink::WebGamepads* pads,
43 bool devices_changed_hint);
44 39
45 // The three function types we use from xinput1_3.dll. 40 // The three function types we use from xinput1_3.dll.
46 typedef void (WINAPI *XInputEnableFunc)(BOOL enable); 41 typedef void (WINAPI *XInputEnableFunc)(BOOL enable);
47 typedef DWORD (WINAPI *XInputGetCapabilitiesFunc)( 42 typedef DWORD (WINAPI *XInputGetCapabilitiesFunc)(
48 DWORD dwUserIndex, DWORD dwFlags, XINPUT_CAPABILITIES* pCapabilities); 43 DWORD dwUserIndex, DWORD dwFlags, XINPUT_CAPABILITIES* pCapabilities);
49 typedef DWORD (WINAPI *XInputGetStateFunc)( 44 typedef DWORD (WINAPI *XInputGetStateFunc)(
50 DWORD dwUserIndex, XINPUT_STATE* pState); 45 DWORD dwUserIndex, XINPUT_STATE* pState);
51 46
52 // Get functions from dynamically loaded xinput1_3.dll. We don't use 47 // Get functions from dynamically loaded xinput1_3.dll. We don't use
53 // DELAYLOAD because the import library for Win8 SDK pulls xinput1_4 which 48 // DELAYLOAD because the import library for Win8 SDK pulls xinput1_4 which
54 // isn't redistributable. Returns true if loading was successful. We include 49 // isn't redistributable. Returns true if loading was successful. We include
55 // xinput1_3.dll with Chrome. 50 // xinput1_3.dll with Chrome.
56 bool GetXInputDllFunctions(); 51 bool GetXInputDllFunctions();
57 52
58 // Scan for connected XInput and DirectInput gamepads. 53 // Scan for connected XInput and DirectInput gamepads.
59 void EnumerateDevices(); 54 void EnumerateDevices();
60 bool GetXInputPadConnectivity(int i, blink::WebGamepad* pad) const; 55 void GetXInputPadData(int i);
61
62 void GetXInputPadData(int i, blink::WebGamepad* pad);
63 void GetRawInputPadData(int i, blink::WebGamepad* pad);
64
65 int FirstAvailableGamepadId() const;
66 bool HasXInputGamepad(int index) const;
67 bool HasRawInputGamepad(const HANDLE handle) const;
68 56
69 base::ScopedNativeLibrary xinput_dll_; 57 base::ScopedNativeLibrary xinput_dll_;
70 bool xinput_available_; 58 bool xinput_available_;
71 59
72 // Function pointers to XInput functionality, retrieved in 60 // Function pointers to XInput functionality, retrieved in
73 // |GetXinputDllFunctions|. 61 // |GetXinputDllFunctions|.
74 XInputEnableFunc xinput_enable_; 62 XInputEnableFunc xinput_enable_;
75 XInputGetCapabilitiesFunc xinput_get_capabilities_; 63 XInputGetCapabilitiesFunc xinput_get_capabilities_;
76 XInputGetStateFunc xinput_get_state_; 64 XInputGetStateFunc xinput_get_state_;
77 65
78 enum PadConnectionStatus { 66 bool xinput_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 scoped_ptr<RawInputDataFetcher> raw_input_fetcher_;
93 67
94 DISALLOW_COPY_AND_ASSIGN(GamepadPlatformDataFetcherWin); 68 DISALLOW_COPY_AND_ASSIGN(GamepadPlatformDataFetcherWin);
95 }; 69 };
96 70
97 } // namespace content 71 } // namespace content
98 72
99 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_WIN_H_ 73 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698