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

Unified Diff: device/gamepad/xbox_data_fetcher_mac.cc

Issue 2081583002: Migrating majority of gamepad from content/browser/ to device/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Final tweaks Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/gamepad/xbox_data_fetcher_mac.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/gamepad/xbox_data_fetcher_mac.cc
diff --git a/content/browser/gamepad/xbox_data_fetcher_mac.cc b/device/gamepad/xbox_data_fetcher_mac.cc
similarity index 78%
rename from content/browser/gamepad/xbox_data_fetcher_mac.cc
rename to device/gamepad/xbox_data_fetcher_mac.cc
index 7ef35318d1847cea3fc16d818564430f16229e7f..4c526a7c4c58335e3b7c0fb53f1090527bda13ce 100644
--- a/content/browser/gamepad/xbox_data_fetcher_mac.cc
+++ b/device/gamepad/xbox_data_fetcher_mac.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "content/browser/gamepad/xbox_data_fetcher_mac.h"
+#include "device/gamepad/xbox_data_fetcher_mac.h"
#include <algorithm>
#include <cmath>
@@ -49,20 +49,20 @@ enum {
#pragma pack(push, 1)
struct Xbox360ButtonData {
- bool dpad_up : 1;
- bool dpad_down : 1;
- bool dpad_left : 1;
+ bool dpad_up : 1;
+ bool dpad_down : 1;
+ bool dpad_left : 1;
bool dpad_right : 1;
- bool start : 1;
- bool back : 1;
- bool stick_left_click : 1;
+ bool start : 1;
+ bool back : 1;
+ bool stick_left_click : 1;
bool stick_right_click : 1;
- bool bumper_left : 1;
+ bool bumper_left : 1;
bool bumper_right : 1;
- bool guide : 1;
- bool dummy1 : 1; // Always 0.
+ bool guide : 1;
+ bool dummy1 : 1; // Always 0.
bool a : 1;
bool b : 1;
@@ -83,24 +83,24 @@ struct Xbox360ButtonData {
};
struct XboxOneButtonData {
- bool sync : 1;
+ bool sync : 1;
bool dummy1 : 1; // Always 0.
- bool start : 1;
- bool back : 1;
+ bool start : 1;
+ bool back : 1;
bool a : 1;
bool b : 1;
bool x : 1;
bool y : 1;
- bool dpad_up : 1;
- bool dpad_down : 1;
- bool dpad_left : 1;
+ bool dpad_up : 1;
+ bool dpad_down : 1;
+ bool dpad_left : 1;
bool dpad_right : 1;
- bool bumper_left : 1;
- bool bumper_right : 1;
- bool stick_left_click : 1;
+ bool bumper_left : 1;
+ bool bumper_right : 1;
+ bool stick_left_click : 1;
bool stick_right_click : 1;
uint16_t trigger_left;
@@ -166,13 +166,14 @@ float NormalizeTrigger(uint8_t value) {
}
float NormalizeXboxOneTrigger(uint16_t value) {
- return value < kXboxOneTriggerDeadzone ? 0 :
- static_cast<float>(value - kXboxOneTriggerDeadzone) /
- (kXboxOneTriggerMax - kXboxOneTriggerDeadzone);
+ return value < kXboxOneTriggerDeadzone
+ ? 0
+ : static_cast<float>(value - kXboxOneTriggerDeadzone) /
+ (kXboxOneTriggerMax - kXboxOneTriggerDeadzone);
}
void NormalizeXbox360ButtonData(const Xbox360ButtonData& data,
- XboxController::Data* normalized_data) {
+ XboxController::Data* normalized_data) {
normalized_data->buttons[0] = data.a;
normalized_data->buttons[1] = data.b;
normalized_data->buttons[2] = data.x;
@@ -190,20 +191,14 @@ void NormalizeXbox360ButtonData(const Xbox360ButtonData& data,
normalized_data->buttons[14] = data.guide;
normalized_data->triggers[0] = NormalizeTrigger(data.trigger_left);
normalized_data->triggers[1] = NormalizeTrigger(data.trigger_right);
- NormalizeAxis(data.stick_left_x,
- data.stick_left_y,
- kLeftThumbDeadzone,
- &normalized_data->axes[0],
- &normalized_data->axes[1]);
- NormalizeAxis(data.stick_right_x,
- data.stick_right_y,
- kRightThumbDeadzone,
- &normalized_data->axes[2],
- &normalized_data->axes[3]);
+ NormalizeAxis(data.stick_left_x, data.stick_left_y, kLeftThumbDeadzone,
+ &normalized_data->axes[0], &normalized_data->axes[1]);
+ NormalizeAxis(data.stick_right_x, data.stick_right_y, kRightThumbDeadzone,
+ &normalized_data->axes[2], &normalized_data->axes[3]);
}
void NormalizeXboxOneButtonData(const XboxOneButtonData& data,
- XboxController::Data* normalized_data) {
+ XboxController::Data* normalized_data) {
normalized_data->buttons[0] = data.a;
normalized_data->buttons[1] = data.b;
normalized_data->buttons[2] = data.x;
@@ -221,16 +216,10 @@ void NormalizeXboxOneButtonData(const XboxOneButtonData& data,
normalized_data->buttons[14] = data.sync;
normalized_data->triggers[0] = NormalizeXboxOneTrigger(data.trigger_left);
normalized_data->triggers[1] = NormalizeXboxOneTrigger(data.trigger_right);
- NormalizeAxis(data.stick_left_x,
- data.stick_left_y,
- kLeftThumbDeadzone,
- &normalized_data->axes[0],
- &normalized_data->axes[1]);
- NormalizeAxis(data.stick_right_x,
- data.stick_right_y,
- kRightThumbDeadzone,
- &normalized_data->axes[2],
- &normalized_data->axes[3]);
+ NormalizeAxis(data.stick_left_x, data.stick_left_y, kLeftThumbDeadzone,
+ &normalized_data->axes[0], &normalized_data->axes[1]);
+ NormalizeAxis(data.stick_right_x, data.stick_right_y, kRightThumbDeadzone,
+ &normalized_data->axes[2], &normalized_data->axes[3]);
}
} // namespace
@@ -246,8 +235,7 @@ XboxController::XboxController(Delegate* delegate)
delegate_(delegate),
controller_type_(UNKNOWN_CONTROLLER),
read_endpoint_(0),
- control_endpoint_(0) {
-}
+ control_endpoint_(0) {}
XboxController::~XboxController() {
if (source_)
@@ -259,22 +247,18 @@ XboxController::~XboxController() {
}
bool XboxController::OpenDevice(io_service_t service) {
- IOCFPlugInInterface **plugin;
+ IOCFPlugInInterface** plugin;
SInt32 score; // Unused, but required for IOCreatePlugInInterfaceForService.
- kern_return_t kr =
- IOCreatePlugInInterfaceForService(service,
- kIOUSBDeviceUserClientTypeID,
- kIOCFPlugInInterfaceID,
- &plugin,
- &score);
+ kern_return_t kr = IOCreatePlugInInterfaceForService(
+ service, kIOUSBDeviceUserClientTypeID, kIOCFPlugInInterfaceID, &plugin,
+ &score);
if (kr != KERN_SUCCESS)
return false;
base::mac::ScopedIOPluginInterface<IOCFPlugInInterface> plugin_ref(plugin);
- HRESULT res =
- (*plugin)->QueryInterface(plugin,
- CFUUIDGetUUIDBytes(kIOUSBDeviceInterfaceID320),
- (LPVOID *)&device_);
+ HRESULT res = (*plugin)->QueryInterface(
+ plugin, CFUUIDGetUUIDBytes(kIOUSBDeviceInterfaceID320),
+ (LPVOID*)&device_);
if (!SUCCEEDED(res) || !device_)
return false;
@@ -358,12 +342,10 @@ bool XboxController::OpenDevice(io_service_t service) {
// endpoint. This is the same process as earlier: first make a
// PluginInterface from the io_service then make the InterfaceInterface from
// that.
- IOCFPlugInInterface **plugin_interface;
- kr = IOCreatePlugInInterfaceForService(usb_interface,
- kIOUSBInterfaceUserClientTypeID,
- kIOCFPlugInInterfaceID,
- &plugin_interface,
- &score);
+ IOCFPlugInInterface** plugin_interface;
+ kr = IOCreatePlugInInterfaceForService(
+ usb_interface, kIOUSBInterfaceUserClientTypeID, kIOCFPlugInInterfaceID,
+ &plugin_interface, &score);
if (kr != KERN_SUCCESS || !plugin_interface)
return false;
base::mac::ScopedIOPluginInterface<IOCFPlugInInterface> interface_ref(
@@ -377,10 +359,10 @@ bool XboxController::OpenDevice(io_service_t service) {
} while ((usb_interface = IOIteratorNext(iter)));
// Actually create the interface.
- res = (*plugin_interface)->QueryInterface(
- plugin_interface,
- CFUUIDGetUUIDBytes(kIOUSBInterfaceInterfaceID300),
- (LPVOID *)&interface_);
+ res = (*plugin_interface)
+ ->QueryInterface(plugin_interface,
+ CFUUIDGetUUIDBytes(kIOUSBInterfaceInterfaceID300),
+ (LPVOID*)&interface_);
if (!SUCCEEDED(res) || !interface_)
return false;
@@ -412,13 +394,9 @@ bool XboxController::OpenDevice(io_service_t service) {
uint16_t max_packet_size;
uint8_t interval;
- kr = (*interface_)->GetPipeProperties(interface_,
- i,
- &direction,
- &number,
- &transfer_type,
- &max_packet_size,
- &interval);
+ kr = (*interface_)
+ ->GetPipeProperties(interface_, i, &direction, &number,
+ &transfer_type, &max_packet_size, &interval);
if (kr != KERN_SUCCESS || transfer_type != kUSBInterrupt) {
return false;
}
@@ -456,12 +434,10 @@ void XboxController::SetLEDPattern(LEDPattern pattern) {
buffer[0] = static_cast<UInt8>(CONTROL_MESSAGE_SET_LED);
buffer[1] = length;
buffer[2] = static_cast<UInt8>(pattern);
- kern_return_t kr = (*interface_)->WritePipeAsync(interface_,
- control_endpoint_,
- buffer,
- (UInt32)length,
- WriteComplete,
- buffer);
+ kern_return_t kr =
+ (*interface_)
+ ->WritePipeAsync(interface_, control_endpoint_, buffer,
+ (UInt32)length, WriteComplete, buffer);
if (kr != KERN_SUCCESS) {
delete[] buffer;
IOError();
@@ -586,12 +562,10 @@ void XboxController::ProcessXboxOnePacket(size_t length) {
}
void XboxController::QueueRead() {
- kern_return_t kr = (*interface_)->ReadPipeAsync(interface_,
- read_endpoint_,
- read_buffer_.get(),
- read_buffer_size_,
- GotData,
- this);
+ kern_return_t kr =
+ (*interface_)
+ ->ReadPipeAsync(interface_, read_endpoint_, read_buffer_.get(),
+ read_buffer_size_, GotData, this);
if (kr != KERN_SUCCESS)
IOError();
}
@@ -608,12 +582,10 @@ void XboxController::WriteXboxOneInit() {
UInt8* buffer = new UInt8[length];
buffer[0] = 0x05;
buffer[1] = 0x20;
- kern_return_t kr = (*interface_)->WritePipeAsync(interface_,
- control_endpoint_,
- buffer,
- (UInt32)length,
- WriteComplete,
- buffer);
+ kern_return_t kr =
+ (*interface_)
+ ->WritePipeAsync(interface_, control_endpoint_, buffer,
+ (UInt32)length, WriteComplete, buffer);
if (kr != KERN_SUCCESS) {
delete[] buffer;
IOError();
@@ -624,11 +596,7 @@ void XboxController::WriteXboxOneInit() {
//-----------------------------------------------------------------------------
XboxDataFetcher::XboxDataFetcher(Delegate* delegate)
- : delegate_(delegate),
- listening_(false),
- source_(NULL),
- port_(NULL) {
-}
+ : delegate_(delegate), listening_(false), source_(NULL), port_(NULL) {}
XboxDataFetcher::~XboxDataFetcher() {
while (!controllers_.empty()) {
@@ -659,11 +627,9 @@ void XboxDataFetcher::DeviceRemoved(void* context, io_iterator_t iterator) {
while ((ref = IOIteratorNext(iterator))) {
base::mac::ScopedIOObject<io_service_t> scoped_ref(ref);
base::ScopedCFTypeRef<CFNumberRef> number(
- base::mac::CFCastStrict<CFNumberRef>(
- IORegistryEntryCreateCFProperty(ref,
- CFSTR(kUSBDevicePropertyLocationID),
- kCFAllocatorDefault,
- kNilOptions)));
+ base::mac::CFCastStrict<CFNumberRef>(IORegistryEntryCreateCFProperty(
+ ref, CFSTR(kUSBDevicePropertyLocationID), kCFAllocatorDefault,
+ kNilOptions)));
UInt32 location_id = 0;
CFNumberGetValue(number, kCFNumberSInt32Type, &location_id);
fetcher->RemoveControllerByLocationID(location_id);
@@ -684,15 +650,13 @@ bool XboxDataFetcher::RegisterForNotifications() {
listening_ = true;
if (!RegisterForDeviceNotifications(
- kVendorMicrosoft, kProductXboxOneController,
- &xbox_one_device_added_iter_,
- &xbox_one_device_removed_iter_))
+ kVendorMicrosoft, kProductXboxOneController,
+ &xbox_one_device_added_iter_, &xbox_one_device_removed_iter_))
return false;
if (!RegisterForDeviceNotifications(
- kVendorMicrosoft, kProductXbox360Controller,
- &xbox_360_device_added_iter_,
- &xbox_360_device_removed_iter_))
+ kVendorMicrosoft, kProductXbox360Controller,
+ &xbox_360_device_added_iter_, &xbox_360_device_removed_iter_))
return false;
return true;
@@ -703,10 +667,10 @@ bool XboxDataFetcher::RegisterForDeviceNotifications(
int product_id,
base::mac::ScopedIOObject<io_iterator_t>* added_iter,
base::mac::ScopedIOObject<io_iterator_t>* removed_iter) {
- base::ScopedCFTypeRef<CFNumberRef> vendor_cf(CFNumberCreate(
- kCFAllocatorDefault, kCFNumberSInt32Type, &vendor_id));
- base::ScopedCFTypeRef<CFNumberRef> product_cf(CFNumberCreate(
- kCFAllocatorDefault, kCFNumberSInt32Type, &product_id));
+ base::ScopedCFTypeRef<CFNumberRef> vendor_cf(
+ CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &vendor_id));
+ base::ScopedCFTypeRef<CFNumberRef> product_cf(
+ CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &product_id));
base::ScopedCFTypeRef<CFMutableDictionaryRef> matching_dict(
IOServiceMatching(kIOUSBDeviceClassName));
if (!matching_dict)
@@ -720,11 +684,8 @@ bool XboxDataFetcher::RegisterForDeviceNotifications(
CFRetain(matching_dict);
io_iterator_t device_added_iter;
IOReturn ret;
- ret = IOServiceAddMatchingNotification(port_,
- kIOFirstMatchNotification,
- matching_dict,
- DeviceAdded,
- this,
+ ret = IOServiceAddMatchingNotification(port_, kIOFirstMatchNotification,
+ matching_dict, DeviceAdded, this,
&device_added_iter);
added_iter->reset(device_added_iter);
if (ret != kIOReturnSuccess) {
@@ -735,11 +696,8 @@ bool XboxDataFetcher::RegisterForDeviceNotifications(
CFRetain(matching_dict);
io_iterator_t device_removed_iter;
- ret = IOServiceAddMatchingNotification(port_,
- kIOTerminatedNotification,
- matching_dict,
- DeviceRemoved,
- this,
+ ret = IOServiceAddMatchingNotification(port_, kIOTerminatedNotification,
+ matching_dict, DeviceRemoved, this,
&device_removed_iter);
removed_iter->reset(device_removed_iter);
if (ret != kIOReturnSuccess) {
@@ -763,8 +721,7 @@ void XboxDataFetcher::UnregisterFromNotifications() {
XboxController* XboxDataFetcher::ControllerForLocation(UInt32 location_id) {
for (std::set<XboxController*>::iterator i = controllers_.begin();
- i != controllers_.end();
- ++i) {
+ i != controllers_.end(); ++i) {
if ((*i)->location_id() == location_id)
return *i;
}
@@ -788,8 +745,7 @@ void XboxDataFetcher::RemoveController(XboxController* controller) {
void XboxDataFetcher::RemoveControllerByLocationID(uint32_t location_id) {
XboxController* controller = NULL;
for (std::set<XboxController*>::iterator i = controllers_.begin();
- i != controllers_.end();
- ++i) {
+ i != controllers_.end(); ++i) {
if ((*i)->location_id() == location_id) {
controller = *i;
break;
« no previous file with comments | « device/gamepad/xbox_data_fetcher_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698