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

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

Issue 1627643002: Revert of Refactoring gamepad polling to support dynamically added sources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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"
27 #include "third_party/WebKit/public/platform/WebGamepads.h" 28 #include "third_party/WebKit/public/platform/WebGamepads.h"
28 29
29 namespace content { 30 namespace content {
30 31
31 class GamepadPlatformDataFetcherWin : public GamepadDataFetcher { 32 class GamepadPlatformDataFetcherWin : public GamepadDataFetcher {
32 public: 33 public:
33 GamepadPlatformDataFetcherWin(); 34 GamepadPlatformDataFetcherWin();
34 ~GamepadPlatformDataFetcherWin() override; 35 ~GamepadPlatformDataFetcherWin() override;
35 void GetGamepadData(bool devices_changed_hint) override; 36 void GetGamepadData(blink::WebGamepads* pads,
37 bool devices_changed_hint) override;
38 void PauseHint(bool paused) override;
36 39
37 private: 40 private:
38 void OnAddedToProvider() override; 41 // XInput-specific implementation for GetGamepadData.
42 bool GetXInputGamepadData(blink::WebGamepads* pads,
43 bool devices_changed_hint);
39 44
40 // The three function types we use from xinput1_3.dll. 45 // The three function types we use from xinput1_3.dll.
41 typedef void (WINAPI *XInputEnableFunc)(BOOL enable); 46 typedef void (WINAPI *XInputEnableFunc)(BOOL enable);
42 typedef DWORD (WINAPI *XInputGetCapabilitiesFunc)( 47 typedef DWORD (WINAPI *XInputGetCapabilitiesFunc)(
43 DWORD dwUserIndex, DWORD dwFlags, XINPUT_CAPABILITIES* pCapabilities); 48 DWORD dwUserIndex, DWORD dwFlags, XINPUT_CAPABILITIES* pCapabilities);
44 typedef DWORD (WINAPI *XInputGetStateFunc)( 49 typedef DWORD (WINAPI *XInputGetStateFunc)(
45 DWORD dwUserIndex, XINPUT_STATE* pState); 50 DWORD dwUserIndex, XINPUT_STATE* pState);
46 51
47 // 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
48 // 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
49 // isn't redistributable. Returns true if loading was successful. We include 54 // isn't redistributable. Returns true if loading was successful. We include
50 // xinput1_3.dll with Chrome. 55 // xinput1_3.dll with Chrome.
51 bool GetXInputDllFunctions(); 56 bool GetXInputDllFunctions();
52 57
53 // Scan for connected XInput and DirectInput gamepads. 58 // Scan for connected XInput and DirectInput gamepads.
54 void EnumerateDevices(); 59 void EnumerateDevices();
55 void GetXInputPadData(int i); 60 bool GetXInputPadConnectivity(int i, blink::WebGamepad* pad) const;
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;
56 68
57 base::ScopedNativeLibrary xinput_dll_; 69 base::ScopedNativeLibrary xinput_dll_;
58 bool xinput_available_; 70 bool xinput_available_;
59 71
60 // Function pointers to XInput functionality, retrieved in 72 // Function pointers to XInput functionality, retrieved in
61 // |GetXinputDllFunctions|. 73 // |GetXinputDllFunctions|.
62 XInputEnableFunc xinput_enable_; 74 XInputEnableFunc xinput_enable_;
63 XInputGetCapabilitiesFunc xinput_get_capabilities_; 75 XInputGetCapabilitiesFunc xinput_get_capabilities_;
64 XInputGetStateFunc xinput_get_state_; 76 XInputGetStateFunc xinput_get_state_;
65 77
66 bool xinput_connected_[XUSER_MAX_COUNT]; 78 enum PadConnectionStatus {
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_;
67 93
68 DISALLOW_COPY_AND_ASSIGN(GamepadPlatformDataFetcherWin); 94 DISALLOW_COPY_AND_ASSIGN(GamepadPlatformDataFetcherWin);
69 }; 95 };
70 96
71 } // namespace content 97 } // namespace content
72 98
73 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_WIN_H_ 99 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698