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

Side by Side Diff: device/gamepad/raw_input_data_fetcher_win.h

Issue 2081583002: Migrating majority of gamepad from content/browser/ to device/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Final tweaks Created 4 years, 5 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
« no previous file with comments | « device/gamepad/gamepad_user_gesture.cc ('k') | device/gamepad/raw_input_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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_RAW_INPUT_DATA_FETCHER_WIN_H_ 5 #ifndef DEVICE_GAMEPAD_RAW_INPUT_DATA_FETCHER_WIN_H_
6 #define CONTENT_BROWSER_GAMEPAD_RAW_INPUT_DATA_FETCHER_WIN_H_ 6 #define DEVICE_GAMEPAD_RAW_INPUT_DATA_FETCHER_WIN_H_
7 7
8 #include <Unknwn.h>
9 #include <WinDef.h>
10 #include <hidsdi.h>
8 #include <stdint.h> 11 #include <stdint.h>
9 #include <stdlib.h> 12 #include <stdlib.h>
10 #include <Unknwn.h>
11 #include <WinDef.h>
12 #include <windows.h> 13 #include <windows.h>
13 #include <hidsdi.h>
14 14
15 #include <map> 15 #include <map>
16 #include <memory> 16 #include <memory>
17 #include <vector> 17 #include <vector>
18 18
19 #include "base/macros.h" 19 #include "base/macros.h"
20 #include "base/memory/weak_ptr.h" 20 #include "base/memory/weak_ptr.h"
21 #include "base/message_loop/message_loop.h" 21 #include "base/message_loop/message_loop.h"
22 #include "base/scoped_native_library.h" 22 #include "base/scoped_native_library.h"
23 #include "base/win/message_window.h" 23 #include "base/win/message_window.h"
24 #include "build/build_config.h" 24 #include "build/build_config.h"
25 #include "content/browser/gamepad/gamepad_data_fetcher.h" 25 #include "device/gamepad/gamepad_data_fetcher.h"
26 #include "content/browser/gamepad/gamepad_standard_mappings.h" 26 #include "device/gamepad/gamepad_standard_mappings.h"
27 #include "third_party/WebKit/public/platform/WebGamepads.h" 27 #include "third_party/WebKit/public/platform/WebGamepads.h"
28 28
29 namespace content { 29 namespace device {
30 30
31 struct RawGamepadAxis { 31 struct RawGamepadAxis {
32 HIDP_VALUE_CAPS caps; 32 HIDP_VALUE_CAPS caps;
33 float value; 33 float value;
34 bool active; 34 bool active;
35 unsigned long bitmask; 35 unsigned long bitmask;
36 }; 36 };
37 37
38 struct RawGamepadInfo { 38 struct RawGamepadInfo {
39 RawGamepadInfo(); 39 RawGamepadInfo();
40 ~RawGamepadInfo(); 40 ~RawGamepadInfo();
41 41
42 HANDLE handle; 42 HANDLE handle;
43 std::unique_ptr<uint8_t[]> ppd_buffer; 43 std::unique_ptr<uint8_t[]> ppd_buffer;
44 PHIDP_PREPARSED_DATA preparsed_data; 44 PHIDP_PREPARSED_DATA preparsed_data;
45 45
46 uint32_t report_id; 46 uint32_t report_id;
47 uint32_t vendor_id; 47 uint32_t vendor_id;
48 uint32_t product_id; 48 uint32_t product_id;
49 49
50 wchar_t id[blink::WebGamepad::idLengthCap]; 50 wchar_t id[blink::WebGamepad::idLengthCap];
51 51
52 uint32_t buttons_length; 52 uint32_t buttons_length;
53 bool buttons[blink::WebGamepad::buttonsLengthCap]; 53 bool buttons[blink::WebGamepad::buttonsLengthCap];
54 54
55 uint32_t axes_length; 55 uint32_t axes_length;
56 RawGamepadAxis axes[blink::WebGamepad::axesLengthCap]; 56 RawGamepadAxis axes[blink::WebGamepad::axesLengthCap];
57 }; 57 };
58 58
59 class RawInputDataFetcher 59 class RawInputDataFetcher : public base::SupportsWeakPtr<RawInputDataFetcher>,
60 : public base::SupportsWeakPtr<RawInputDataFetcher>, 60 public base::MessageLoop::DestructionObserver {
61 public base::MessageLoop::DestructionObserver {
62 public: 61 public:
63 explicit RawInputDataFetcher(); 62 explicit RawInputDataFetcher();
64 ~RawInputDataFetcher() override; 63 ~RawInputDataFetcher() override;
65 64
66 // DestructionObserver overrides. 65 // DestructionObserver overrides.
67 void WillDestroyCurrentMessageLoop() override; 66 void WillDestroyCurrentMessageLoop() override;
68 67
69 bool Available() { return rawinput_available_; } 68 bool Available() { return rawinput_available_; }
70 void StartMonitor(); 69 void StartMonitor();
71 void StopMonitor(); 70 void StopMonitor();
72 71
73 std::vector<RawGamepadInfo*> EnumerateDevices(); 72 std::vector<RawGamepadInfo*> EnumerateDevices();
74 RawGamepadInfo* GetGamepadInfo(HANDLE handle); 73 RawGamepadInfo* GetGamepadInfo(HANDLE handle);
75 74
76 private: 75 private:
77 RawGamepadInfo* ParseGamepadInfo(HANDLE hDevice); 76 RawGamepadInfo* ParseGamepadInfo(HANDLE hDevice);
78 void UpdateGamepad(RAWINPUT* input, RawGamepadInfo* gamepad_info); 77 void UpdateGamepad(RAWINPUT* input, RawGamepadInfo* gamepad_info);
79 // Handles WM_INPUT messages. 78 // Handles WM_INPUT messages.
80 LRESULT OnInput(HRAWINPUT input_handle); 79 LRESULT OnInput(HRAWINPUT input_handle);
81 // Handles messages received by |window_|. 80 // Handles messages received by |window_|.
82 bool HandleMessage(UINT message, 81 bool HandleMessage(UINT message,
83 WPARAM wparam, 82 WPARAM wparam,
84 LPARAM lparam, 83 LPARAM lparam,
85 LRESULT* result); 84 LRESULT* result);
86 RAWINPUTDEVICE* GetRawInputDevices(DWORD flags); 85 RAWINPUTDEVICE* GetRawInputDevices(DWORD flags);
87 void ClearControllers(); 86 void ClearControllers();
88 87
89 // Function types we use from hid.dll. 88 // Function types we use from hid.dll.
90 typedef NTSTATUS (__stdcall *HidPGetCapsFunc)( 89 typedef NTSTATUS(__stdcall* HidPGetCapsFunc)(
91 PHIDP_PREPARSED_DATA PreparsedData, PHIDP_CAPS Capabilities); 90 PHIDP_PREPARSED_DATA PreparsedData,
92 typedef NTSTATUS (__stdcall *HidPGetButtonCapsFunc)( 91 PHIDP_CAPS Capabilities);
93 HIDP_REPORT_TYPE ReportType, PHIDP_BUTTON_CAPS ButtonCaps, 92 typedef NTSTATUS(__stdcall* HidPGetButtonCapsFunc)(
94 PUSHORT ButtonCapsLength, PHIDP_PREPARSED_DATA PreparsedData); 93 HIDP_REPORT_TYPE ReportType,
95 typedef NTSTATUS (__stdcall *HidPGetValueCapsFunc)( 94 PHIDP_BUTTON_CAPS ButtonCaps,
96 HIDP_REPORT_TYPE ReportType, PHIDP_VALUE_CAPS ValueCaps, 95 PUSHORT ButtonCapsLength,
97 PUSHORT ValueCapsLength, PHIDP_PREPARSED_DATA PreparsedData); 96 PHIDP_PREPARSED_DATA PreparsedData);
97 typedef NTSTATUS(__stdcall* HidPGetValueCapsFunc)(
98 HIDP_REPORT_TYPE ReportType,
99 PHIDP_VALUE_CAPS ValueCaps,
100 PUSHORT ValueCapsLength,
101 PHIDP_PREPARSED_DATA PreparsedData);
98 typedef NTSTATUS(__stdcall* HidPGetUsagesExFunc)( 102 typedef NTSTATUS(__stdcall* HidPGetUsagesExFunc)(
99 HIDP_REPORT_TYPE ReportType, 103 HIDP_REPORT_TYPE ReportType,
100 USHORT LinkCollection, 104 USHORT LinkCollection,
101 PUSAGE_AND_PAGE ButtonList, 105 PUSAGE_AND_PAGE ButtonList,
102 ULONG* UsageLength, 106 ULONG* UsageLength,
103 PHIDP_PREPARSED_DATA PreparsedData, 107 PHIDP_PREPARSED_DATA PreparsedData,
104 PCHAR Report, 108 PCHAR Report,
105 ULONG ReportLength); 109 ULONG ReportLength);
106 typedef NTSTATUS (__stdcall *HidPGetUsageValueFunc)( 110 typedef NTSTATUS(__stdcall* HidPGetUsageValueFunc)(
107 HIDP_REPORT_TYPE ReportType, USAGE UsagePage, USHORT LinkCollection, 111 HIDP_REPORT_TYPE ReportType,
108 USAGE Usage, PULONG UsageValue, PHIDP_PREPARSED_DATA PreparsedData, 112 USAGE UsagePage,
109 PCHAR Report, ULONG ReportLength); 113 USHORT LinkCollection,
110 typedef NTSTATUS (__stdcall *HidPGetScaledUsageValueFunc)( 114 USAGE Usage,
111 HIDP_REPORT_TYPE ReportType, USAGE UsagePage, USHORT LinkCollection, 115 PULONG UsageValue,
112 USAGE Usage, PLONG UsageValue, PHIDP_PREPARSED_DATA PreparsedData, 116 PHIDP_PREPARSED_DATA PreparsedData,
113 PCHAR Report, ULONG ReportLength); 117 PCHAR Report,
114 typedef BOOLEAN (__stdcall *HidDGetStringFunc)( 118 ULONG ReportLength);
115 HANDLE HidDeviceObject, PVOID Buffer, ULONG BufferLength); 119 typedef NTSTATUS(__stdcall* HidPGetScaledUsageValueFunc)(
120 HIDP_REPORT_TYPE ReportType,
121 USAGE UsagePage,
122 USHORT LinkCollection,
123 USAGE Usage,
124 PLONG UsageValue,
125 PHIDP_PREPARSED_DATA PreparsedData,
126 PCHAR Report,
127 ULONG ReportLength);
128 typedef BOOLEAN(__stdcall* HidDGetStringFunc)(HANDLE HidDeviceObject,
129 PVOID Buffer,
130 ULONG BufferLength);
116 131
117 // Get functions from dynamically loaded hid.dll. Returns true if loading was 132 // Get functions from dynamically loaded hid.dll. Returns true if loading was
118 // successful. 133 // successful.
119 bool GetHidDllFunctions(); 134 bool GetHidDllFunctions();
120 135
121 base::ScopedNativeLibrary hid_dll_; 136 base::ScopedNativeLibrary hid_dll_;
122 std::unique_ptr<base::win::MessageWindow> window_; 137 std::unique_ptr<base::win::MessageWindow> window_;
123 bool rawinput_available_; 138 bool rawinput_available_;
124 bool filter_xinput_; 139 bool filter_xinput_;
125 bool events_monitored_; 140 bool events_monitored_;
126 141
127 std::map<HANDLE, RawGamepadInfo*> controllers_; 142 std::map<HANDLE, RawGamepadInfo*> controllers_;
128 143
129 // Function pointers to HID functionality, retrieved in 144 // Function pointers to HID functionality, retrieved in
130 // |GetHidDllFunctions|. 145 // |GetHidDllFunctions|.
131 HidPGetCapsFunc hidp_get_caps_; 146 HidPGetCapsFunc hidp_get_caps_;
132 HidPGetButtonCapsFunc hidp_get_button_caps_; 147 HidPGetButtonCapsFunc hidp_get_button_caps_;
133 HidPGetValueCapsFunc hidp_get_value_caps_; 148 HidPGetValueCapsFunc hidp_get_value_caps_;
134 HidPGetUsagesExFunc hidp_get_usages_ex_; 149 HidPGetUsagesExFunc hidp_get_usages_ex_;
135 HidPGetUsageValueFunc hidp_get_usage_value_; 150 HidPGetUsageValueFunc hidp_get_usage_value_;
136 HidPGetScaledUsageValueFunc hidp_get_scaled_usage_value_; 151 HidPGetScaledUsageValueFunc hidp_get_scaled_usage_value_;
137 HidDGetStringFunc hidd_get_product_string_; 152 HidDGetStringFunc hidd_get_product_string_;
138 153
139 DISALLOW_COPY_AND_ASSIGN(RawInputDataFetcher); 154 DISALLOW_COPY_AND_ASSIGN(RawInputDataFetcher);
140 }; 155 };
141 156
142 } // namespace content 157 } // namespace device
143 158
144 #endif // CONTENT_BROWSER_GAMEPAD_RAW_INPUT_DATA_FETCHER_WIN_H_ 159 #endif // DEVICE_GAMEPAD_RAW_INPUT_DATA_FETCHER_WIN_H_
OLDNEW
« no previous file with comments | « device/gamepad/gamepad_user_gesture.cc ('k') | device/gamepad/raw_input_data_fetcher_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698