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

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

Powered by Google App Engine
This is Rietveld 408576698