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

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

Issue 1627643002: Revert of Refactoring gamepad polling to support dynamically added sources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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"
16 18
17 #include <CoreFoundation/CoreFoundation.h> 19 #include <CoreFoundation/CoreFoundation.h>
18 #include <IOKit/hid/IOHIDManager.h> 20 #include <IOKit/hid/IOHIDManager.h>
19 21
20 #if defined(__OBJC__) 22 #if defined(__OBJC__)
21 @class NSArray; 23 @class NSArray;
22 #else 24 #else
23 class NSArray; 25 class NSArray;
24 #endif 26 #endif
25 27
26 namespace content { 28 namespace content {
27 29
28 class GamepadPlatformDataFetcherMac : public GamepadDataFetcher { 30 class GamepadPlatformDataFetcherMac : public GamepadDataFetcher,
31 public XboxDataFetcher::Delegate {
29 public: 32 public:
30 GamepadPlatformDataFetcherMac(); 33 GamepadPlatformDataFetcherMac();
31 ~GamepadPlatformDataFetcherMac() override; 34 ~GamepadPlatformDataFetcherMac() override;
32 void GetGamepadData(bool devices_changed_hint) override; 35 void GetGamepadData(blink::WebGamepads* pads,
36 bool devices_changed_hint) override;
33 void PauseHint(bool paused) override; 37 void PauseHint(bool paused) override;
34 38
35 private: 39 private:
36 bool enabled_; 40 bool enabled_;
37 bool paused_; 41 bool paused_;
38 base::ScopedCFTypeRef<IOHIDManagerRef> hid_manager_ref_; 42 base::ScopedCFTypeRef<IOHIDManagerRef> hid_manager_ref_;
39 43
40 static GamepadPlatformDataFetcherMac* InstanceFromContext(void* context); 44 static GamepadPlatformDataFetcherMac* InstanceFromContext(void* context);
41 static void DeviceAddCallback(void* context, 45 static void DeviceAddCallback(void* context,
42 IOReturn result, 46 IOReturn result,
43 void* sender, 47 void* sender,
44 IOHIDDeviceRef ref); 48 IOHIDDeviceRef ref);
45 static void DeviceRemoveCallback(void* context, 49 static void DeviceRemoveCallback(void* context,
46 IOReturn result, 50 IOReturn result,
47 void* sender, 51 void* sender,
48 IOHIDDeviceRef ref); 52 IOHIDDeviceRef ref);
49 static void ValueChangedCallback(void* context, 53 static void ValueChangedCallback(void* context,
50 IOReturn result, 54 IOReturn result,
51 void* sender, 55 void* sender,
52 IOHIDValueRef ref); 56 IOHIDValueRef ref);
53 57
54 void OnAddedToProvider() override;
55
56 size_t GetEmptySlot(); 58 size_t GetEmptySlot();
57 size_t GetSlotForDevice(IOHIDDeviceRef device); 59 size_t GetSlotForDevice(IOHIDDeviceRef device);
60 size_t GetSlotForXboxDevice(XboxController* device);
58 61
59 void DeviceAdd(IOHIDDeviceRef device); 62 void DeviceAdd(IOHIDDeviceRef device);
60 bool AddButtonsAndAxes(NSArray* elements, PadState* state, size_t slot); 63 bool AddButtonsAndAxes(NSArray* elements, size_t slot);
61 void DeviceRemove(IOHIDDeviceRef device); 64 void DeviceRemove(IOHIDDeviceRef device);
62 void ValueChanged(IOHIDValueRef value); 65 void ValueChanged(IOHIDValueRef value);
63 66
67 void XboxDeviceAdd(XboxController* device) override;
68 void XboxDeviceRemove(XboxController* device) override;
69 void XboxValueChanged(XboxController* device,
70 const XboxController::Data& data) override;
71
64 void RegisterForNotifications(); 72 void RegisterForNotifications();
65 void UnregisterFromNotifications(); 73 void UnregisterFromNotifications();
66 74
75 void SanitizeGamepadData(size_t index, blink::WebGamepad* pad);
76
77 scoped_ptr<XboxDataFetcher> xbox_fetcher_;
78
67 // Side-band data that's not passed to the consumer, but we need to maintain 79 // Side-band data that's not passed to the consumer, but we need to maintain
68 // to update data_. 80 // to update data_.
69 struct AssociatedData { 81 struct AssociatedData {
70 int location_id; 82 bool is_xbox;
71 IOHIDDeviceRef device_ref; 83 union {
72 IOHIDElementRef button_elements[blink::WebGamepad::buttonsLengthCap]; 84 struct {
73 IOHIDElementRef axis_elements[blink::WebGamepad::axesLengthCap]; 85 IOHIDDeviceRef device_ref;
74 CFIndex axis_minimums[blink::WebGamepad::axesLengthCap]; 86 IOHIDElementRef button_elements[blink::WebGamepad::buttonsLengthCap];
75 CFIndex axis_maximums[blink::WebGamepad::axesLengthCap]; 87 IOHIDElementRef axis_elements[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 };
76 }; 96 };
77 AssociatedData associated_[blink::WebGamepads::itemsLengthCap]; 97 AssociatedData associated_[blink::WebGamepads::itemsLengthCap];
78 98
79 DISALLOW_COPY_AND_ASSIGN(GamepadPlatformDataFetcherMac); 99 DISALLOW_COPY_AND_ASSIGN(GamepadPlatformDataFetcherMac);
80 }; 100 };
81 101
82 } // namespace content 102 } // namespace content
83 103
84 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_MAC_H_ 104 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_MAC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698