Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: content/browser/gamepad/gamepad_platform_data_fetcher_mac.h

Issue 1586663006: Refactoring gamepad polling to support dynamically added sources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Avoid crash on Android content_unittests Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_MAC_H_ 5 #ifndef CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_MAC_H_
6 #define CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_MAC_H_ 6 #define CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_MAC_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/mac/scoped_cftyperef.h" 11 #include "base/mac/scoped_cftyperef.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "build/build_config.h" 14 #include "build/build_config.h"
15 #include "content/browser/gamepad/gamepad_data_fetcher.h" 15 #include "content/browser/gamepad/gamepad_data_fetcher.h"
16 #include "content/browser/gamepad/xbox_data_fetcher_mac.h"
17 #include "content/common/gamepad_hardware_buffer.h"
18 16
19 #include <CoreFoundation/CoreFoundation.h> 17 #include <CoreFoundation/CoreFoundation.h>
20 #include <IOKit/hid/IOHIDManager.h> 18 #include <IOKit/hid/IOHIDManager.h>
21 19
22 #if defined(__OBJC__) 20 #if defined(__OBJC__)
23 @class NSArray; 21 @class NSArray;
24 #else 22 #else
25 class NSArray; 23 class NSArray;
26 #endif 24 #endif
27 25
28 namespace content { 26 namespace content {
29 27
30 class GamepadPlatformDataFetcherMac : public GamepadDataFetcher, 28 class GamepadPlatformDataFetcherMac : public GamepadDataFetcher {
31 public XboxDataFetcher::Delegate {
32 public: 29 public:
33 GamepadPlatformDataFetcherMac(); 30 GamepadPlatformDataFetcherMac();
34 ~GamepadPlatformDataFetcherMac() override; 31 ~GamepadPlatformDataFetcherMac() override;
35 void GetGamepadData(blink::WebGamepads* pads, 32 void GetGamepadData(bool devices_changed_hint) override;
36 bool devices_changed_hint) override;
37 void PauseHint(bool paused) override; 33 void PauseHint(bool paused) override;
38 34
39 private: 35 private:
40 bool enabled_; 36 bool enabled_;
41 bool paused_; 37 bool paused_;
42 base::ScopedCFTypeRef<IOHIDManagerRef> hid_manager_ref_; 38 base::ScopedCFTypeRef<IOHIDManagerRef> hid_manager_ref_;
43 39
44 static GamepadPlatformDataFetcherMac* InstanceFromContext(void* context); 40 static GamepadPlatformDataFetcherMac* InstanceFromContext(void* context);
45 static void DeviceAddCallback(void* context, 41 static void DeviceAddCallback(void* context,
46 IOReturn result, 42 IOReturn result,
47 void* sender, 43 void* sender,
48 IOHIDDeviceRef ref); 44 IOHIDDeviceRef ref);
49 static void DeviceRemoveCallback(void* context, 45 static void DeviceRemoveCallback(void* context,
50 IOReturn result, 46 IOReturn result,
51 void* sender, 47 void* sender,
52 IOHIDDeviceRef ref); 48 IOHIDDeviceRef ref);
53 static void ValueChangedCallback(void* context, 49 static void ValueChangedCallback(void* context,
54 IOReturn result, 50 IOReturn result,
55 void* sender, 51 void* sender,
56 IOHIDValueRef ref); 52 IOHIDValueRef ref);
57 53
54 void OnAddedToProvider() override;
55
58 size_t GetEmptySlot(); 56 size_t GetEmptySlot();
59 size_t GetSlotForDevice(IOHIDDeviceRef device); 57 size_t GetSlotForDevice(IOHIDDeviceRef device);
60 size_t GetSlotForXboxDevice(XboxController* device);
61 58
62 void DeviceAdd(IOHIDDeviceRef device); 59 void DeviceAdd(IOHIDDeviceRef device);
63 bool AddButtonsAndAxes(NSArray* elements, size_t slot); 60 bool AddButtonsAndAxes(NSArray* elements, PadState* state, size_t slot);
64 void DeviceRemove(IOHIDDeviceRef device); 61 void DeviceRemove(IOHIDDeviceRef device);
65 void ValueChanged(IOHIDValueRef value); 62 void ValueChanged(IOHIDValueRef value);
66 63
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(); 64 void RegisterForNotifications();
73 void UnregisterFromNotifications(); 65 void UnregisterFromNotifications();
74 66
75 void SanitizeGamepadData(size_t index, blink::WebGamepad* pad);
76
77 scoped_ptr<XboxDataFetcher> xbox_fetcher_;
78
79 // Side-band data that's not passed to the consumer, but we need to maintain 67 // Side-band data that's not passed to the consumer, but we need to maintain
80 // to update data_. 68 // to update data_.
81 struct AssociatedData { 69 struct AssociatedData {
82 bool is_xbox; 70 int location_id;
83 union { 71 IOHIDDeviceRef device_ref;
84 struct { 72 IOHIDElementRef button_elements[blink::WebGamepad::buttonsLengthCap];
85 IOHIDDeviceRef device_ref; 73 IOHIDElementRef axis_elements[blink::WebGamepad::axesLengthCap];
86 IOHIDElementRef button_elements[blink::WebGamepad::buttonsLengthCap]; 74 CFIndex axis_minimums[blink::WebGamepad::axesLengthCap];
87 IOHIDElementRef axis_elements[blink::WebGamepad::axesLengthCap]; 75 CFIndex axis_maximums[blink::WebGamepad::axesLengthCap];
88 CFIndex axis_minimums[blink::WebGamepad::axesLengthCap];
89 CFIndex axis_maximums[blink::WebGamepad::axesLengthCap];
90 } hid;
91 struct {
92 XboxController* device;
93 UInt32 location_id;
94 } xbox;
95 };
96 }; 76 };
97 AssociatedData associated_[blink::WebGamepads::itemsLengthCap]; 77 AssociatedData associated_[blink::WebGamepads::itemsLengthCap];
98 78
99 DISALLOW_COPY_AND_ASSIGN(GamepadPlatformDataFetcherMac); 79 DISALLOW_COPY_AND_ASSIGN(GamepadPlatformDataFetcherMac);
100 }; 80 };
101 81
102 } // namespace content 82 } // namespace content
103 83
104 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_MAC_H_ 84 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_MAC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698