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

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: Features, fixes, and cleanups 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.
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
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 RawJoystickAxis {
34 HIDP_VALUE_CAPS caps;
35 float value;
36 };
37
38 struct RawJoystickInfo {
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 HIDP_BUTTON_CAPS button_caps;
50 uint32_t buttons_length;
51 bool buttons[blink::WebGamepad::buttonsLengthCap];
52
53 uint32_t axes_length;
54 RawJoystickAxis axes[blink::WebGamepad::axesLengthCap];
55 };
56
57 class RawInputDataFetcher
58 : public base::SupportsWeakPtr<RawInputDataFetcher>,
59 public base::MessageLoop::DestructionObserver {
60 public:
61 explicit RawInputDataFetcher();
62 ~RawInputDataFetcher();
63
64 // DestructionObserver overrides.
65 virtual void WillDestroyCurrentMessageLoop() OVERRIDE;
66
67 bool Available() { return rawinput_available_; }
68 void StartMonitor();
69 void StopMonitor();
70
71 std::vector<RawJoystickInfo*> EnumerateDevices();
72 RawJoystickInfo* GetJoystickInfo(HANDLE handle);
73
74 private:
75 RawJoystickInfo* ParseJoystickInfo(HANDLE hDevice);
76 void UpdateJoystick(RAWINPUT* input, RawJoystickInfo* joystick_info);
77 // Handles WM_INPUT messages.
78 LRESULT OnInput(HRAWINPUT input_handle);
79 // Handles messages received by |window_|.
80 bool HandleMessage(UINT message,
81 WPARAM wparam,
82 LPARAM lparam,
83 LRESULT* result);
84 RAWINPUTDEVICE* GetRawInputDevices(DWORD flags);
85 void ClearControllers();
86
87 // Function types we use from hid.dll.
88 typedef NTSTATUS (__stdcall *HidPGetCapsFunc)(
89 PHIDP_PREPARSED_DATA PreparsedData, PHIDP_CAPS Capabilities);
90 typedef NTSTATUS (__stdcall *HidPGetButtonCapsFunc)(
91 HIDP_REPORT_TYPE ReportType, PHIDP_BUTTON_CAPS ButtonCaps,
92 PUSHORT ButtonCapsLength, PHIDP_PREPARSED_DATA PreparsedData);
93 typedef NTSTATUS (__stdcall *HidPGetValueCapsFunc)(
94 HIDP_REPORT_TYPE ReportType, PHIDP_VALUE_CAPS ValueCaps,
95 PUSHORT ValueCapsLength, PHIDP_PREPARSED_DATA PreparsedData);
96 typedef NTSTATUS (__stdcall *HidPGetUsagesFunc)(
97 HIDP_REPORT_TYPE ReportType, USAGE UsagePage, USHORT LinkCollection,
98 PUSAGE UsageList, PULONG UsageLength, PHIDP_PREPARSED_DATA PreparsedData,
99 PCHAR Report, ULONG ReportLength);
100 typedef NTSTATUS (__stdcall *HidPGetUsageValueFunc)(
101 HIDP_REPORT_TYPE ReportType, USAGE UsagePage, USHORT LinkCollection,
102 USAGE Usage, PULONG UsageValue, PHIDP_PREPARSED_DATA PreparsedData,
103 PCHAR Report, ULONG ReportLength);
104 typedef BOOLEAN (__stdcall *HidDGetStringFunc)(
105 HANDLE HidDeviceObject, PVOID Buffer, ULONG BufferLength);
106
107 // Get functions from dynamically loaded hid.dll. Returns true if loading was
108 // successful.
109 bool GetHidDllFunctions();
110
111 base::ScopedNativeLibrary hid_dll_;
112 scoped_ptr<base::win::MessageWindow> window_;
113 bool rawinput_available_;
114 bool filter_xinput_;
115 bool events_monitored_;
116
117 std::map<HANDLE, RawJoystickInfo*> controllers_;
118
119 // Function pointers to HID functionality, retrieved in
120 // |GetHidDllFunctions|.
121 HidPGetCapsFunc hidp_get_caps_;
122 HidPGetButtonCapsFunc hidp_get_button_caps_;
123 HidPGetValueCapsFunc hidp_get_value_caps_;
124 HidPGetUsagesFunc hidp_get_usages_;
125 HidPGetUsageValueFunc hidp_get_usage_value_;
126 HidDGetStringFunc hidd_get_product_string_;
127
128 DISALLOW_COPY_AND_ASSIGN(RawInputDataFetcher);
129 };
130
131 } // namespace content
132
133 #endif // CONTENT_BROWSER_GAMEPAD_RAW_INPUT_DATA_FETCHER_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698