| 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 CONTENT_BROWSER_GAMEPAD_RAW_INPUT_DATA_FETCHER_WIN_H_ | 5 #ifndef CONTENT_BROWSER_GAMEPAD_RAW_INPUT_DATA_FETCHER_WIN_H_ |
| 6 #define CONTENT_BROWSER_GAMEPAD_RAW_INPUT_DATA_FETCHER_WIN_H_ | 6 #define CONTENT_BROWSER_GAMEPAD_RAW_INPUT_DATA_FETCHER_WIN_H_ |
| 7 | 7 |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 | 9 |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 HIDP_VALUE_CAPS caps; | 33 HIDP_VALUE_CAPS caps; |
| 34 float value; | 34 float value; |
| 35 bool active; | 35 bool active; |
| 36 unsigned long bitmask; | 36 unsigned long bitmask; |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 struct RawGamepadInfo { | 39 struct RawGamepadInfo { |
| 40 RawGamepadInfo(); | 40 RawGamepadInfo(); |
| 41 ~RawGamepadInfo(); | 41 ~RawGamepadInfo(); |
| 42 | 42 |
| 43 int source_id; | |
| 44 int enumeration_id; | |
| 45 HANDLE handle; | 43 HANDLE handle; |
| 46 scoped_ptr<uint8_t[]> ppd_buffer; | 44 scoped_ptr<uint8_t[]> ppd_buffer; |
| 47 PHIDP_PREPARSED_DATA preparsed_data; | 45 PHIDP_PREPARSED_DATA preparsed_data; |
| 48 | 46 |
| 49 uint32_t report_id; | 47 uint32_t report_id; |
| 50 uint32_t vendor_id; | 48 uint32_t vendor_id; |
| 51 uint32_t product_id; | 49 uint32_t product_id; |
| 52 | 50 |
| 53 wchar_t id[blink::WebGamepad::idLengthCap]; | 51 wchar_t id[blink::WebGamepad::idLengthCap]; |
| 54 | 52 |
| 55 uint32_t buttons_length; | 53 uint32_t buttons_length; |
| 56 bool buttons[blink::WebGamepad::buttonsLengthCap]; | 54 bool buttons[blink::WebGamepad::buttonsLengthCap]; |
| 57 | 55 |
| 58 uint32_t axes_length; | 56 uint32_t axes_length; |
| 59 RawGamepadAxis axes[blink::WebGamepad::axesLengthCap]; | 57 RawGamepadAxis axes[blink::WebGamepad::axesLengthCap]; |
| 60 }; | 58 }; |
| 61 | 59 |
| 62 class RawInputDataFetcher | 60 class RawInputDataFetcher |
| 63 : public GamepadDataFetcher, | 61 : public base::SupportsWeakPtr<RawInputDataFetcher>, |
| 64 public base::SupportsWeakPtr<RawInputDataFetcher>, | |
| 65 public base::MessageLoop::DestructionObserver { | 62 public base::MessageLoop::DestructionObserver { |
| 66 public: | 63 public: |
| 67 explicit RawInputDataFetcher(); | 64 explicit RawInputDataFetcher(); |
| 68 ~RawInputDataFetcher() override; | 65 ~RawInputDataFetcher() override; |
| 69 | 66 |
| 70 // DestructionObserver overrides. | 67 // DestructionObserver overrides. |
| 71 void WillDestroyCurrentMessageLoop() override; | 68 void WillDestroyCurrentMessageLoop() override; |
| 72 | 69 |
| 73 void GetGamepadData(bool devices_changed_hint) override; | 70 bool Available() { return rawinput_available_; } |
| 74 void PauseHint(bool paused) override; | 71 void StartMonitor(); |
| 72 void StopMonitor(); |
| 73 |
| 74 std::vector<RawGamepadInfo*> EnumerateDevices(); |
| 75 RawGamepadInfo* GetGamepadInfo(HANDLE handle); |
| 75 | 76 |
| 76 private: | 77 private: |
| 77 void OnAddedToProvider() override; | |
| 78 | |
| 79 void StartMonitor(); | |
| 80 void StopMonitor(); | |
| 81 void EnumerateDevices(); | |
| 82 RawGamepadInfo* ParseGamepadInfo(HANDLE hDevice); | 78 RawGamepadInfo* ParseGamepadInfo(HANDLE hDevice); |
| 83 void UpdateGamepad(RAWINPUT* input, RawGamepadInfo* gamepad_info); | 79 void UpdateGamepad(RAWINPUT* input, RawGamepadInfo* gamepad_info); |
| 84 // Handles WM_INPUT messages. | 80 // Handles WM_INPUT messages. |
| 85 LRESULT OnInput(HRAWINPUT input_handle); | 81 LRESULT OnInput(HRAWINPUT input_handle); |
| 86 // Handles messages received by |window_|. | 82 // Handles messages received by |window_|. |
| 87 bool HandleMessage(UINT message, | 83 bool HandleMessage(UINT message, |
| 88 WPARAM wparam, | 84 WPARAM wparam, |
| 89 LPARAM lparam, | 85 LPARAM lparam, |
| 90 LRESULT* result); | 86 LRESULT* result); |
| 91 RAWINPUTDEVICE* GetRawInputDevices(DWORD flags); | 87 RAWINPUTDEVICE* GetRawInputDevices(DWORD flags); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 121 | 117 |
| 122 // Get functions from dynamically loaded hid.dll. Returns true if loading was | 118 // Get functions from dynamically loaded hid.dll. Returns true if loading was |
| 123 // successful. | 119 // successful. |
| 124 bool GetHidDllFunctions(); | 120 bool GetHidDllFunctions(); |
| 125 | 121 |
| 126 base::ScopedNativeLibrary hid_dll_; | 122 base::ScopedNativeLibrary hid_dll_; |
| 127 scoped_ptr<base::win::MessageWindow> window_; | 123 scoped_ptr<base::win::MessageWindow> window_; |
| 128 bool rawinput_available_; | 124 bool rawinput_available_; |
| 129 bool filter_xinput_; | 125 bool filter_xinput_; |
| 130 bool events_monitored_; | 126 bool events_monitored_; |
| 131 int last_source_id_; | |
| 132 int last_enumeration_id_; | |
| 133 | 127 |
| 134 typedef std::map<HANDLE, RawGamepadInfo*> ControllerMap; | 128 std::map<HANDLE, RawGamepadInfo*> controllers_; |
| 135 ControllerMap controllers_; | |
| 136 | 129 |
| 137 // Function pointers to HID functionality, retrieved in | 130 // Function pointers to HID functionality, retrieved in |
| 138 // |GetHidDllFunctions|. | 131 // |GetHidDllFunctions|. |
| 139 HidPGetCapsFunc hidp_get_caps_; | 132 HidPGetCapsFunc hidp_get_caps_; |
| 140 HidPGetButtonCapsFunc hidp_get_button_caps_; | 133 HidPGetButtonCapsFunc hidp_get_button_caps_; |
| 141 HidPGetValueCapsFunc hidp_get_value_caps_; | 134 HidPGetValueCapsFunc hidp_get_value_caps_; |
| 142 HidPGetUsagesExFunc hidp_get_usages_ex_; | 135 HidPGetUsagesExFunc hidp_get_usages_ex_; |
| 143 HidPGetUsageValueFunc hidp_get_usage_value_; | 136 HidPGetUsageValueFunc hidp_get_usage_value_; |
| 144 HidPGetScaledUsageValueFunc hidp_get_scaled_usage_value_; | 137 HidPGetScaledUsageValueFunc hidp_get_scaled_usage_value_; |
| 145 HidDGetStringFunc hidd_get_product_string_; | 138 HidDGetStringFunc hidd_get_product_string_; |
| 146 | 139 |
| 147 DISALLOW_COPY_AND_ASSIGN(RawInputDataFetcher); | 140 DISALLOW_COPY_AND_ASSIGN(RawInputDataFetcher); |
| 148 }; | 141 }; |
| 149 | 142 |
| 150 } // namespace content | 143 } // namespace content |
| 151 | 144 |
| 152 #endif // CONTENT_BROWSER_GAMEPAD_RAW_INPUT_DATA_FETCHER_WIN_H_ | 145 #endif // CONTENT_BROWSER_GAMEPAD_RAW_INPUT_DATA_FETCHER_WIN_H_ |
| OLD | NEW |