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