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