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

Side by Side Diff: content/browser/gamepad/raw_input_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: Addressed feedback, fixed some issues observed with certain controllers 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
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
scottmg 2014/02/03 23:58:15 nit; 2014
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 "build/build_config.h"
9
10 #ifndef WIN32_LEAN_AND_MEAN
11 #define WIN32_LEAN_AND_MEAN
scottmg 2014/02/03 23:58:15 is this necessary to avoid a conflict? there's oth
12 #endif
13 #include <stdlib.h>
14 #include <Unknwn.h>
15 #include <WinDef.h>
16 #include <windows.h>
17
18 #include <hidsdi.h>
19 #include <map>
20 #include <vector>
21
22 #include "base/memory/scoped_ptr.h"
23 #include "base/memory/weak_ptr.h"
24 #include "base/message_loop/message_loop.h"
25 #include "base/scoped_native_library.h"
26 #include "base/win/message_window.h"
27 #include "content/browser/gamepad/gamepad_data_fetcher.h"
28 #include "content/browser/gamepad/gamepad_standard_mappings.h"
29 #include "third_party/WebKit/public/platform/WebGamepads.h"
30
31 namespace content {
32
33 struct RawGamepadAxis {
34 HIDP_VALUE_CAPS caps;
35 float value;
36 };
37
38 struct RawGamepadInfo {
39 HANDLE handle;
40 scoped_ptr<uint8[]> ppd_buffer;
41 PHIDP_PREPARSED_DATA preparsed_data;
42
43 uint32_t report_id;
44 uint32_t vendor_id;
45 uint32_t product_id;
46
47 wchar_t id[blink::WebGamepad::idLengthCap];
48
49 uint32_t button_caps_length;
50 scoped_ptr<HIDP_BUTTON_CAPS[]> button_caps;
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();
65
66 // DestructionObserver overrides.
67 virtual 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 *HidPGetUsagesFunc)(
99 HIDP_REPORT_TYPE ReportType, USAGE UsagePage, USHORT LinkCollection,
100 PUSAGE UsageList, PULONG UsageLength, PHIDP_PREPARSED_DATA PreparsedData,
101 PCHAR Report, ULONG ReportLength);
102 typedef NTSTATUS (__stdcall *HidPGetUsageValueFunc)(
103 HIDP_REPORT_TYPE ReportType, USAGE UsagePage, USHORT LinkCollection,
104 USAGE Usage, PULONG UsageValue, PHIDP_PREPARSED_DATA PreparsedData,
105 PCHAR Report, ULONG ReportLength);
106 typedef NTSTATUS (__stdcall *HidPGetScaledUsageValueFunc)(
107 HIDP_REPORT_TYPE ReportType, USAGE UsagePage, USHORT LinkCollection,
108 USAGE Usage, PLONG UsageValue, PHIDP_PREPARSED_DATA PreparsedData,
109 PCHAR Report, ULONG ReportLength);
110 typedef BOOLEAN (__stdcall *HidDGetStringFunc)(
111 HANDLE HidDeviceObject, PVOID Buffer, ULONG BufferLength);
112
113 // Get functions from dynamically loaded hid.dll. Returns true if loading was
114 // successful.
115 bool GetHidDllFunctions();
116
117 base::ScopedNativeLibrary hid_dll_;
118 scoped_ptr<base::win::MessageWindow> window_;
119 bool rawinput_available_;
120 bool filter_xinput_;
121 bool events_monitored_;
122
123 std::map<HANDLE, RawGamepadInfo*> controllers_;
124
125 // Function pointers to HID functionality, retrieved in
126 // |GetHidDllFunctions|.
127 HidPGetCapsFunc hidp_get_caps_;
128 HidPGetButtonCapsFunc hidp_get_button_caps_;
129 HidPGetValueCapsFunc hidp_get_value_caps_;
130 HidPGetUsagesFunc hidp_get_usages_;
131 HidPGetUsageValueFunc hidp_get_usage_value_;
132 HidPGetScaledUsageValueFunc hidp_get_scaled_usage_value_;
133 HidDGetStringFunc hidd_get_product_string_;
134
135 DISALLOW_COPY_AND_ASSIGN(RawInputDataFetcher);
136 };
137
138 } // namespace content
139
140 #endif // CONTENT_BROWSER_GAMEPAD_RAW_INPUT_DATA_FETCHER_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698