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

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

Powered by Google App Engine
This is Rietveld 408576698