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

Unified Diff: content/browser/gamepad/platform_data_fetcher_mac.mm

Issue 9270015: Add Mac gamepad input remapper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix linux Created 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/gamepad/platform_data_fetcher_mac.h ('k') | content/content_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/gamepad/platform_data_fetcher_mac.mm
diff --git a/content/browser/gamepad/platform_data_fetcher_mac.mm b/content/browser/gamepad/platform_data_fetcher_mac.mm
index 5e4ba8f9a213f98795a63c157f70d1adae7f0225..fe4300e384ca88dc4cdb3d6c57dbd00bd2e20222 100644
--- a/content/browser/gamepad/platform_data_fetcher_mac.mm
+++ b/content/browser/gamepad/platform_data_fetcher_mac.mm
@@ -43,6 +43,7 @@ const uint32_t kAxisMaximumUsageNumber = 0x35;
GamepadPlatformDataFetcherMac::GamepadPlatformDataFetcherMac()
: enabled_(true) {
+ memset(associated_, 0, sizeof(associated_));
hid_manager_ref_.reset(IOHIDManagerCreate(kCFAllocatorDefault,
kIOHIDOptionsTypeNone));
if (CFGetTypeID(hid_manager_ref_) != IOHIDManagerGetTypeID()) {
@@ -200,12 +201,21 @@ void GamepadPlatformDataFetcherMac::DeviceAdd(IOHIDDeviceRef device) {
IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductIDKey))));
NSString* product = CFToNSCast(CFCastStrict<CFStringRef>(
IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductKey))));
+ int vendor_int = [vendor_id intValue];
+ int product_int = [product_id intValue];
- NSString* ident([NSString stringWithFormat:
- @"%@ (Vendor: %04x Product: %04x)",
+ char vendor_as_str[5], product_as_str[5];
+ snprintf(vendor_as_str, sizeof(vendor_as_str), "%04x", vendor_int);
+ snprintf(product_as_str, sizeof(product_as_str), "%04x", product_int);
+ associated_[slot].mapper =
+ GetGamepadStandardMappingFunction(vendor_as_str, product_as_str);
+
+ NSString* ident = [NSString stringWithFormat:
+ @"%@ (%sVendor: %04x Product: %04x)",
product,
- [vendor_id intValue],
- [product_id intValue]]);
+ associated_[slot].mapper ? "STANDARD GAMEPAD " : "",
+ vendor_int,
+ product_int];
NSData* as16 = [ident dataUsingEncoding:NSUTF16StringEncoding];
const size_t kOutputLengthBytes = sizeof(data_.items[slot].id);
@@ -285,7 +295,16 @@ void GamepadPlatformDataFetcherMac::GetGamepadData(
pads->length = 0;
return;
}
- memcpy(pads, &data_, sizeof(WebKit::WebGamepads));
+
+ // Copy to the current state to the output buffer, using the mapping
+ // function, if there is one available.
+ pads->length = data_.length;
+ for (size_t i = 0; i < WebKit::WebGamepads::itemsLengthCap; ++i) {
+ if (associated_[i].mapper)
+ associated_[i].mapper(data_.items[i], &pads->items[i]);
+ else
+ pads->items[i] = data_.items[i];
+ }
}
} // namespace content
« no previous file with comments | « content/browser/gamepad/platform_data_fetcher_mac.h ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698