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

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

Issue 14328036: Implement support for USB Xbox360 controllers without a driver on Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: move conversions back to xbox-specific code; #if out the TYPE_UI stuff just for mac. Created 7 years, 7 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 | Annotate | Revision Log
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 "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/mac/scoped_cftyperef.h" 10 #include "base/mac/scoped_cftyperef.h"
11 #include "base/memory/scoped_ptr.h"
11 #include "build/build_config.h" 12 #include "build/build_config.h"
12 #include "content/browser/gamepad/gamepad_data_fetcher.h" 13 #include "content/browser/gamepad/gamepad_data_fetcher.h"
13 #include "content/browser/gamepad/gamepad_standard_mappings.h" 14 #include "content/browser/gamepad/gamepad_standard_mappings.h"
15 #include "content/browser/gamepad/xbox_data_fetcher_mac.h"
14 #include "content/common/gamepad_hardware_buffer.h" 16 #include "content/common/gamepad_hardware_buffer.h"
17 #include "third_party/WebKit/Source/Platform/chromium/public/WebGamepads.h"
15 18
16 #include <CoreFoundation/CoreFoundation.h> 19 #include <CoreFoundation/CoreFoundation.h>
17 #include <IOKit/hid/IOHIDManager.h> 20 #include <IOKit/hid/IOHIDManager.h>
18 21
19 #if defined(__OBJC__) 22 #if defined(__OBJC__)
20 @class NSArray; 23 @class NSArray;
21 #else 24 #else
22 class NSArray; 25 class NSArray;
23 #endif 26 #endif
24 27
25 namespace content { 28 namespace content {
26 29
27 class GamepadPlatformDataFetcherMac : public GamepadDataFetcher { 30 class GamepadPlatformDataFetcherMac : public GamepadDataFetcher,
31 public XboxDataFetcher::Delegate {
28 public: 32 public:
29 GamepadPlatformDataFetcherMac(); 33 GamepadPlatformDataFetcherMac();
30 virtual ~GamepadPlatformDataFetcherMac(); 34 virtual ~GamepadPlatformDataFetcherMac();
31 virtual void GetGamepadData(WebKit::WebGamepads* pads, 35 virtual void GetGamepadData(WebKit::WebGamepads* pads,
32 bool devices_changed_hint) OVERRIDE; 36 bool devices_changed_hint) OVERRIDE;
33 virtual void PauseHint(bool paused) OVERRIDE; 37 virtual void PauseHint(bool paused) OVERRIDE;
34 38
35 private: 39 private:
36 bool enabled_; 40 bool enabled_;
37 base::mac::ScopedCFTypeRef<IOHIDManagerRef> hid_manager_ref_; 41 base::mac::ScopedCFTypeRef<IOHIDManagerRef> hid_manager_ref_;
38 42
39 static GamepadPlatformDataFetcherMac* InstanceFromContext(void* context); 43 static GamepadPlatformDataFetcherMac* InstanceFromContext(void* context);
40 static void DeviceAddCallback(void* context, 44 static void DeviceAddCallback(void* context,
41 IOReturn result, 45 IOReturn result,
42 void* sender, 46 void* sender,
43 IOHIDDeviceRef ref); 47 IOHIDDeviceRef ref);
44 static void DeviceRemoveCallback(void* context, 48 static void DeviceRemoveCallback(void* context,
45 IOReturn result, 49 IOReturn result,
46 void* sender, 50 void* sender,
47 IOHIDDeviceRef ref); 51 IOHIDDeviceRef ref);
48 static void ValueChangedCallback(void* context, 52 static void ValueChangedCallback(void* context,
49 IOReturn result, 53 IOReturn result,
50 void* sender, 54 void* sender,
51 IOHIDValueRef ref); 55 IOHIDValueRef ref);
52 56
57 size_t GetEmptySlot();
58 size_t GetSlotForDevice(IOHIDDeviceRef device);
59 size_t GetSlotForXboxDevice(XboxController* device);
60
53 void DeviceAdd(IOHIDDeviceRef device); 61 void DeviceAdd(IOHIDDeviceRef device);
54 void AddButtonsAndAxes(NSArray* elements, size_t slot); 62 void AddButtonsAndAxes(NSArray* elements, size_t slot);
55 void DeviceRemove(IOHIDDeviceRef device); 63 void DeviceRemove(IOHIDDeviceRef device);
56 void ValueChanged(IOHIDValueRef value); 64 void ValueChanged(IOHIDValueRef value);
57 65
66 virtual void XboxDeviceAdd(XboxController* device) OVERRIDE;
67 virtual void XboxDeviceRemove(XboxController* device) OVERRIDE;
68 virtual void XboxValueChanged(XboxController* device,
69 const XboxController::Data& data) OVERRIDE;
70
58 void RegisterForNotifications(); 71 void RegisterForNotifications();
59 void UnregisterFromNotifications(); 72 void UnregisterFromNotifications();
60 73
74 scoped_ptr<XboxDataFetcher> xbox_fetcher_;
75
61 WebKit::WebGamepads data_; 76 WebKit::WebGamepads data_;
62 77
63 // Side-band data that's not passed to the consumer, but we need to maintain 78 // Side-band data that's not passed to the consumer, but we need to maintain
64 // to update data_. 79 // to update data_.
65 struct AssociatedData { 80 struct AssociatedData {
66 IOHIDDeviceRef device_ref; 81 bool is_xbox;
67 IOHIDElementRef button_elements[WebKit::WebGamepad::buttonsLengthCap]; 82 union {
68 IOHIDElementRef axis_elements[WebKit::WebGamepad::buttonsLengthCap]; 83 struct {
69 CFIndex axis_minimums[WebKit::WebGamepad::axesLengthCap]; 84 IOHIDDeviceRef device_ref;
70 CFIndex axis_maximums[WebKit::WebGamepad::axesLengthCap]; 85 IOHIDElementRef button_elements[WebKit::WebGamepad::buttonsLengthCap];
71 // Function to map from device data to standard layout, if available. May 86 IOHIDElementRef axis_elements[WebKit::WebGamepad::buttonsLengthCap];
72 // be null if no mapping is available. 87 CFIndex axis_minimums[WebKit::WebGamepad::axesLengthCap];
73 GamepadStandardMappingFunction mapper; 88 CFIndex axis_maximums[WebKit::WebGamepad::axesLengthCap];
89 // Function to map from device data to standard layout, if available.
90 // May be null if no mapping is available.
91 GamepadStandardMappingFunction mapper;
92 } hid;
93 struct {
94 XboxController* device;
95 UInt32 location_id;
96 } xbox;
97 };
74 }; 98 };
75 AssociatedData associated_[WebKit::WebGamepads::itemsLengthCap]; 99 AssociatedData associated_[WebKit::WebGamepads::itemsLengthCap];
76 100
77 DISALLOW_COPY_AND_ASSIGN(GamepadPlatformDataFetcherMac); 101 DISALLOW_COPY_AND_ASSIGN(GamepadPlatformDataFetcherMac);
78 }; 102 };
79 103
80 } // namespace content 104 } // namespace content
81 105
82 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_MAC_H_ 106 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_MAC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698