| OLD | NEW |
| 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 DEVICE_GAMEPAD_RAW_INPUT_DATA_FETCHER_WIN_H_ | 5 #ifndef DEVICE_GAMEPAD_RAW_INPUT_DATA_FETCHER_WIN_H_ |
| 6 #define DEVICE_GAMEPAD_RAW_INPUT_DATA_FETCHER_WIN_H_ | 6 #define DEVICE_GAMEPAD_RAW_INPUT_DATA_FETCHER_WIN_H_ |
| 7 | 7 |
| 8 #include <Unknwn.h> | 8 #include <Unknwn.h> |
| 9 #include <WinDef.h> | 9 #include <WinDef.h> |
| 10 #include <hidsdi.h> | 10 #include <hidsdi.h> |
| (...skipping 21 matching lines...) Expand all Loading... |
| 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 int source_id; |
| 43 int enumeration_id; |
| 42 HANDLE handle; | 44 HANDLE handle; |
| 43 std::unique_ptr<uint8_t[]> ppd_buffer; | 45 std::unique_ptr<uint8_t[]> ppd_buffer; |
| 44 PHIDP_PREPARSED_DATA preparsed_data; | 46 PHIDP_PREPARSED_DATA preparsed_data; |
| 45 | 47 |
| 46 uint32_t report_id; | 48 uint32_t report_id; |
| 47 uint32_t vendor_id; | 49 uint32_t vendor_id; |
| 48 uint32_t product_id; | 50 uint32_t product_id; |
| 49 | 51 |
| 50 wchar_t id[blink::WebGamepad::idLengthCap]; | 52 wchar_t id[blink::WebGamepad::idLengthCap]; |
| 51 | 53 |
| 52 uint32_t buttons_length; | 54 uint32_t buttons_length; |
| 53 bool buttons[blink::WebGamepad::buttonsLengthCap]; | 55 bool buttons[blink::WebGamepad::buttonsLengthCap]; |
| 54 | 56 |
| 55 uint32_t axes_length; | 57 uint32_t axes_length; |
| 56 RawGamepadAxis axes[blink::WebGamepad::axesLengthCap]; | 58 RawGamepadAxis axes[blink::WebGamepad::axesLengthCap]; |
| 57 }; | 59 }; |
| 58 | 60 |
| 59 class RawInputDataFetcher : public base::SupportsWeakPtr<RawInputDataFetcher>, | 61 class RawInputDataFetcher : public GamepadDataFetcher, |
| 62 public base::SupportsWeakPtr<RawInputDataFetcher>, |
| 60 public base::MessageLoop::DestructionObserver { | 63 public base::MessageLoop::DestructionObserver { |
| 61 public: | 64 public: |
| 65 typedef GamepadDataFetcherFactoryImpl<RawInputDataFetcher, |
| 66 GAMEPAD_SOURCE_WIN_RAW> |
| 67 Factory; |
| 68 |
| 62 explicit RawInputDataFetcher(); | 69 explicit RawInputDataFetcher(); |
| 63 ~RawInputDataFetcher() override; | 70 ~RawInputDataFetcher() override; |
| 64 | 71 |
| 72 GamepadSource source() override; |
| 73 |
| 65 // DestructionObserver overrides. | 74 // DestructionObserver overrides. |
| 66 void WillDestroyCurrentMessageLoop() override; | 75 void WillDestroyCurrentMessageLoop() override; |
| 67 | 76 |
| 68 bool Available() { return rawinput_available_; } | 77 void GetGamepadData(bool devices_changed_hint) override; |
| 78 void PauseHint(bool paused) override; |
| 79 |
| 80 private: |
| 81 void OnAddedToProvider() override; |
| 82 |
| 69 void StartMonitor(); | 83 void StartMonitor(); |
| 70 void StopMonitor(); | 84 void StopMonitor(); |
| 71 | 85 void EnumerateDevices(); |
| 72 std::vector<RawGamepadInfo*> EnumerateDevices(); | |
| 73 RawGamepadInfo* GetGamepadInfo(HANDLE handle); | |
| 74 | |
| 75 private: | |
| 76 RawGamepadInfo* ParseGamepadInfo(HANDLE hDevice); | 86 RawGamepadInfo* ParseGamepadInfo(HANDLE hDevice); |
| 77 void UpdateGamepad(RAWINPUT* input, RawGamepadInfo* gamepad_info); | 87 void UpdateGamepad(RAWINPUT* input, RawGamepadInfo* gamepad_info); |
| 78 // Handles WM_INPUT messages. | 88 // Handles WM_INPUT messages. |
| 79 LRESULT OnInput(HRAWINPUT input_handle); | 89 LRESULT OnInput(HRAWINPUT input_handle); |
| 80 // Handles messages received by |window_|. | 90 // Handles messages received by |window_|. |
| 81 bool HandleMessage(UINT message, | 91 bool HandleMessage(UINT message, |
| 82 WPARAM wparam, | 92 WPARAM wparam, |
| 83 LPARAM lparam, | 93 LPARAM lparam, |
| 84 LRESULT* result); | 94 LRESULT* result); |
| 85 RAWINPUTDEVICE* GetRawInputDevices(DWORD flags); | 95 RAWINPUTDEVICE* GetRawInputDevices(DWORD flags); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 141 |
| 132 // Get functions from dynamically loaded hid.dll. Returns true if loading was | 142 // Get functions from dynamically loaded hid.dll. Returns true if loading was |
| 133 // successful. | 143 // successful. |
| 134 bool GetHidDllFunctions(); | 144 bool GetHidDllFunctions(); |
| 135 | 145 |
| 136 base::ScopedNativeLibrary hid_dll_; | 146 base::ScopedNativeLibrary hid_dll_; |
| 137 std::unique_ptr<base::win::MessageWindow> window_; | 147 std::unique_ptr<base::win::MessageWindow> window_; |
| 138 bool rawinput_available_; | 148 bool rawinput_available_; |
| 139 bool filter_xinput_; | 149 bool filter_xinput_; |
| 140 bool events_monitored_; | 150 bool events_monitored_; |
| 151 int last_source_id_; |
| 152 int last_enumeration_id_; |
| 141 | 153 |
| 142 std::map<HANDLE, RawGamepadInfo*> controllers_; | 154 typedef std::map<HANDLE, RawGamepadInfo*> ControllerMap; |
| 155 ControllerMap controllers_; |
| 143 | 156 |
| 144 // Function pointers to HID functionality, retrieved in | 157 // Function pointers to HID functionality, retrieved in |
| 145 // |GetHidDllFunctions|. | 158 // |GetHidDllFunctions|. |
| 146 HidPGetCapsFunc hidp_get_caps_; | 159 HidPGetCapsFunc hidp_get_caps_; |
| 147 HidPGetButtonCapsFunc hidp_get_button_caps_; | 160 HidPGetButtonCapsFunc hidp_get_button_caps_; |
| 148 HidPGetValueCapsFunc hidp_get_value_caps_; | 161 HidPGetValueCapsFunc hidp_get_value_caps_; |
| 149 HidPGetUsagesExFunc hidp_get_usages_ex_; | 162 HidPGetUsagesExFunc hidp_get_usages_ex_; |
| 150 HidPGetUsageValueFunc hidp_get_usage_value_; | 163 HidPGetUsageValueFunc hidp_get_usage_value_; |
| 151 HidPGetScaledUsageValueFunc hidp_get_scaled_usage_value_; | 164 HidPGetScaledUsageValueFunc hidp_get_scaled_usage_value_; |
| 152 HidDGetStringFunc hidd_get_product_string_; | 165 HidDGetStringFunc hidd_get_product_string_; |
| 153 | 166 |
| 154 DISALLOW_COPY_AND_ASSIGN(RawInputDataFetcher); | 167 DISALLOW_COPY_AND_ASSIGN(RawInputDataFetcher); |
| 155 }; | 168 }; |
| 156 | 169 |
| 157 } // namespace device | 170 } // namespace device |
| 158 | 171 |
| 159 #endif // DEVICE_GAMEPAD_RAW_INPUT_DATA_FETCHER_WIN_H_ | 172 #endif // DEVICE_GAMEPAD_RAW_INPUT_DATA_FETCHER_WIN_H_ |
| OLD | NEW |