OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_GAMEPAD_PLATFORM_DATA_FETCHER_MAC_H_ | 5 #ifndef DEVICE_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_MAC_H_ |
6 #define DEVICE_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_MAC_H_ | 6 #define DEVICE_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_MAC_H_ |
7 | 7 |
8 #include <CoreFoundation/CoreFoundation.h> | 8 #include <CoreFoundation/CoreFoundation.h> |
9 #include <IOKit/hid/IOHIDManager.h> | 9 #include <IOKit/hid/IOHIDManager.h> |
10 #include <stddef.h> | 10 #include <stddef.h> |
11 | 11 |
12 #include <memory> | 12 #include <memory> |
13 | 13 |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/mac/scoped_cftyperef.h" | 15 #include "base/mac/scoped_cftyperef.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
18 #include "device/gamepad/gamepad_data_fetcher.h" | 18 #include "device/gamepad/gamepad_data_fetcher.h" |
19 #include "device/gamepad/xbox_data_fetcher_mac.h" | |
20 | 19 |
21 #if defined(__OBJC__) | 20 #if defined(__OBJC__) |
22 @class NSArray; | 21 @class NSArray; |
23 #else | 22 #else |
24 class NSArray; | 23 class NSArray; |
25 #endif | 24 #endif |
26 | 25 |
27 namespace device { | 26 namespace device { |
28 | 27 |
29 class GamepadPlatformDataFetcherMac : public GamepadDataFetcher, | 28 class GamepadPlatformDataFetcherMac : public GamepadDataFetcher { |
30 public XboxDataFetcher::Delegate { | |
31 public: | 29 public: |
| 30 typedef GamepadDataFetcherFactoryImpl<GamepadPlatformDataFetcherMac, |
| 31 GAMEPAD_SOURCE_MAC_HID> |
| 32 Factory; |
| 33 |
32 GamepadPlatformDataFetcherMac(); | 34 GamepadPlatformDataFetcherMac(); |
33 ~GamepadPlatformDataFetcherMac() override; | 35 ~GamepadPlatformDataFetcherMac() override; |
34 void GetGamepadData(blink::WebGamepads* pads, | 36 |
35 bool devices_changed_hint) override; | 37 GamepadSource source() override; |
| 38 |
| 39 void GetGamepadData(bool devices_changed_hint) override; |
36 void PauseHint(bool paused) override; | 40 void PauseHint(bool paused) override; |
37 | 41 |
38 private: | 42 private: |
39 bool enabled_; | 43 bool enabled_; |
40 bool paused_; | 44 bool paused_; |
41 base::ScopedCFTypeRef<IOHIDManagerRef> hid_manager_ref_; | 45 base::ScopedCFTypeRef<IOHIDManagerRef> hid_manager_ref_; |
42 | 46 |
43 static GamepadPlatformDataFetcherMac* InstanceFromContext(void* context); | 47 static GamepadPlatformDataFetcherMac* InstanceFromContext(void* context); |
44 static void DeviceAddCallback(void* context, | 48 static void DeviceAddCallback(void* context, |
45 IOReturn result, | 49 IOReturn result, |
46 void* sender, | 50 void* sender, |
47 IOHIDDeviceRef ref); | 51 IOHIDDeviceRef ref); |
48 static void DeviceRemoveCallback(void* context, | 52 static void DeviceRemoveCallback(void* context, |
49 IOReturn result, | 53 IOReturn result, |
50 void* sender, | 54 void* sender, |
51 IOHIDDeviceRef ref); | 55 IOHIDDeviceRef ref); |
52 static void ValueChangedCallback(void* context, | 56 static void ValueChangedCallback(void* context, |
53 IOReturn result, | 57 IOReturn result, |
54 void* sender, | 58 void* sender, |
55 IOHIDValueRef ref); | 59 IOHIDValueRef ref); |
56 | 60 |
| 61 void OnAddedToProvider() override; |
| 62 |
57 size_t GetEmptySlot(); | 63 size_t GetEmptySlot(); |
58 size_t GetSlotForDevice(IOHIDDeviceRef device); | 64 size_t GetSlotForDevice(IOHIDDeviceRef device); |
59 size_t GetSlotForXboxDevice(XboxController* device); | |
60 | 65 |
61 void DeviceAdd(IOHIDDeviceRef device); | 66 void DeviceAdd(IOHIDDeviceRef device); |
62 bool CheckCollection(IOHIDElementRef element); | 67 bool CheckCollection(IOHIDElementRef element); |
63 bool AddButtonsAndAxes(NSArray* elements, size_t slot); | 68 bool AddButtonsAndAxes(NSArray* elements, PadState* state, size_t slot); |
64 void DeviceRemove(IOHIDDeviceRef device); | 69 void DeviceRemove(IOHIDDeviceRef device); |
65 void ValueChanged(IOHIDValueRef value); | 70 void ValueChanged(IOHIDValueRef value); |
66 | 71 |
67 void XboxDeviceAdd(XboxController* device) override; | |
68 void XboxDeviceRemove(XboxController* device) override; | |
69 void XboxValueChanged(XboxController* device, | |
70 const XboxController::Data& data) override; | |
71 | |
72 void RegisterForNotifications(); | 72 void RegisterForNotifications(); |
73 void UnregisterFromNotifications(); | 73 void UnregisterFromNotifications(); |
74 | 74 |
75 void SanitizeGamepadData(size_t index, blink::WebGamepad* pad); | |
76 | |
77 std::unique_ptr<XboxDataFetcher> xbox_fetcher_; | |
78 | |
79 // Side-band data that's not passed to the consumer, but we need to maintain | 75 // Side-band data that's not passed to the consumer, but we need to maintain |
80 // to update data_. | 76 // to update data_. |
81 struct AssociatedData { | 77 struct AssociatedData { |
82 bool is_xbox; | 78 int location_id; |
83 union { | 79 IOHIDDeviceRef device_ref; |
84 struct { | 80 IOHIDElementRef button_elements[blink::WebGamepad::buttonsLengthCap]; |
85 IOHIDDeviceRef device_ref; | 81 IOHIDElementRef axis_elements[blink::WebGamepad::axesLengthCap]; |
86 IOHIDElementRef button_elements[blink::WebGamepad::buttonsLengthCap]; | 82 CFIndex axis_minimums[blink::WebGamepad::axesLengthCap]; |
87 IOHIDElementRef axis_elements[blink::WebGamepad::axesLengthCap]; | 83 CFIndex axis_maximums[blink::WebGamepad::axesLengthCap]; |
88 CFIndex axis_minimums[blink::WebGamepad::axesLengthCap]; | 84 CFIndex axis_report_sizes[blink::WebGamepad::axesLengthCap]; |
89 CFIndex axis_maximums[blink::WebGamepad::axesLengthCap]; | |
90 CFIndex axis_report_sizes[blink::WebGamepad::axesLengthCap]; | |
91 } hid; | |
92 struct { | |
93 XboxController* device; | |
94 UInt32 location_id; | |
95 } xbox; | |
96 }; | |
97 }; | 85 }; |
98 AssociatedData associated_[blink::WebGamepads::itemsLengthCap]; | 86 AssociatedData associated_[blink::WebGamepads::itemsLengthCap]; |
99 | 87 |
100 DISALLOW_COPY_AND_ASSIGN(GamepadPlatformDataFetcherMac); | 88 DISALLOW_COPY_AND_ASSIGN(GamepadPlatformDataFetcherMac); |
101 }; | 89 }; |
102 | 90 |
103 } // namespace device | 91 } // namespace device |
104 | 92 |
105 #endif // DEVICE_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_MAC_H_ | 93 #endif // DEVICE_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_MAC_H_ |
OLD | NEW |