Index: device/gamepad/raw_input_data_fetcher_win.cc |
diff --git a/content/browser/gamepad/raw_input_data_fetcher_win.cc b/device/gamepad/raw_input_data_fetcher_win.cc |
similarity index 83% |
rename from content/browser/gamepad/raw_input_data_fetcher_win.cc |
rename to device/gamepad/raw_input_data_fetcher_win.cc |
index 765e0d7fa33f193f2910c768c9f2608c2866dde0..1379dc75a702a6f72bb51f26307f63c439d1fc8c 100644 |
--- a/content/browser/gamepad/raw_input_data_fetcher_win.cc |
+++ b/device/gamepad/raw_input_data_fetcher_win.cc |
@@ -2,16 +2,14 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "content/browser/gamepad/raw_input_data_fetcher_win.h" |
+#include "device/gamepad/raw_input_data_fetcher_win.h" |
#include <stddef.h> |
#include "base/macros.h" |
#include "base/trace_event/trace_event.h" |
-#include "content/common/gamepad_hardware_buffer.h" |
-#include "content/common/gamepad_messages.h" |
-namespace content { |
+namespace device { |
using namespace blink; |
@@ -27,9 +25,9 @@ unsigned long GetBitmask(unsigned short bits) { |
// From the HID Usage Tables specification. |
USHORT DeviceUsages[] = { |
- 0x04, // Joysticks |
- 0x05, // Gamepads |
- 0x08, // Multi Axis |
+ 0x04, // Joysticks |
+ 0x05, // Gamepads |
+ 0x08, // Multi Axis |
}; |
const uint32_t kAxisMinimumUsageNumber = 0x30; |
@@ -38,18 +36,15 @@ const uint32_t kButtonUsagePage = 0x09; |
} // namespace |
-RawGamepadInfo::RawGamepadInfo() { |
-} |
+RawGamepadInfo::RawGamepadInfo() {} |
-RawGamepadInfo::~RawGamepadInfo() { |
-} |
+RawGamepadInfo::~RawGamepadInfo() {} |
RawInputDataFetcher::RawInputDataFetcher() |
: hid_dll_(base::FilePath(FILE_PATH_LITERAL("hid.dll"))), |
rawinput_available_(GetHidDllFunctions()), |
filter_xinput_(true), |
- events_monitored_(false) { |
-} |
+ events_monitored_(false) {} |
RawInputDataFetcher::~RawInputDataFetcher() { |
ClearControllers(); |
@@ -91,7 +86,7 @@ void RawInputDataFetcher::StartMonitor() { |
std::unique_ptr<RAWINPUTDEVICE[]> devices( |
GetRawInputDevices(RIDEV_INPUTSINK)); |
if (!RegisterRawInputDevices(devices.get(), arraysize(DeviceUsages), |
- sizeof(RAWINPUTDEVICE))) { |
+ sizeof(RAWINPUTDEVICE))) { |
PLOG(ERROR) << "RegisterRawInputDevices() failed for RIDEV_INPUTSINK"; |
window_.reset(); |
return; |
@@ -114,7 +109,7 @@ void RawInputDataFetcher::StopMonitor() { |
std::unique_ptr<RAWINPUTDEVICE[]> devices(GetRawInputDevices(RIDEV_REMOVE)); |
if (!RegisterRawInputDevices(devices.get(), arraysize(DeviceUsages), |
- sizeof(RAWINPUTDEVICE))) { |
+ sizeof(RAWINPUTDEVICE))) { |
PLOG(INFO) << "RegisterRawInputDevices() failed for RIDEV_REMOVE"; |
} |
@@ -149,7 +144,7 @@ std::vector<RawGamepadInfo*> RawInputDataFetcher::EnumerateDevices() { |
std::unique_ptr<RAWINPUTDEVICELIST[]> device_list( |
new RAWINPUTDEVICELIST[count]); |
result = GetRawInputDeviceList(device_list.get(), &count, |
- sizeof(RAWINPUTDEVICELIST)); |
+ sizeof(RAWINPUTDEVICELIST)); |
if (result == static_cast<UINT>(-1)) { |
PLOG(ERROR) << "GetRawInputDeviceList() failed"; |
return valid_controllers; |
@@ -185,8 +180,7 @@ RawGamepadInfo* RawInputDataFetcher::ParseGamepadInfo(HANDLE hDevice) { |
return NULL; |
// Query basic device info. |
- UINT result = GetRawInputDeviceInfo(hDevice, RIDI_DEVICEINFO, |
- NULL, &size); |
+ UINT result = GetRawInputDeviceInfo(hDevice, RIDI_DEVICEINFO, NULL, &size); |
if (result == static_cast<UINT>(-1)) { |
PLOG(ERROR) << "GetRawInputDeviceInfo() failed"; |
return NULL; |
@@ -196,8 +190,8 @@ RawGamepadInfo* RawInputDataFetcher::ParseGamepadInfo(HANDLE hDevice) { |
std::unique_ptr<uint8_t[]> di_buffer(new uint8_t[size]); |
RID_DEVICE_INFO* device_info = |
reinterpret_cast<RID_DEVICE_INFO*>(di_buffer.get()); |
- result = GetRawInputDeviceInfo(hDevice, RIDI_DEVICEINFO, |
- di_buffer.get(), &size); |
+ result = |
+ GetRawInputDeviceInfo(hDevice, RIDI_DEVICEINFO, di_buffer.get(), &size); |
if (result == static_cast<UINT>(-1)) { |
PLOG(ERROR) << "GetRawInputDeviceInfo() failed"; |
return NULL; |
@@ -227,8 +221,7 @@ RawGamepadInfo* RawInputDataFetcher::ParseGamepadInfo(HANDLE hDevice) { |
ZeroMemory(gamepad_info->axes, sizeof(gamepad_info->axes)); |
// Query device identifier |
- result = GetRawInputDeviceInfo(hDevice, RIDI_DEVICENAME, |
- NULL, &size); |
+ result = GetRawInputDeviceInfo(hDevice, RIDI_DEVICENAME, NULL, &size); |
if (result == static_cast<UINT>(-1)) { |
PLOG(ERROR) << "GetRawInputDeviceInfo() failed"; |
return NULL; |
@@ -236,8 +229,8 @@ RawGamepadInfo* RawInputDataFetcher::ParseGamepadInfo(HANDLE hDevice) { |
DCHECK_EQ(0u, result); |
std::unique_ptr<wchar_t[]> name_buffer(new wchar_t[size]); |
- result = GetRawInputDeviceInfo(hDevice, RIDI_DEVICENAME, |
- name_buffer.get(), &size); |
+ result = |
+ GetRawInputDeviceInfo(hDevice, RIDI_DEVICENAME, name_buffer.get(), &size); |
if (result == static_cast<UINT>(-1)) { |
PLOG(ERROR) << "GetRawInputDeviceInfo() failed"; |
return NULL; |
@@ -247,16 +240,17 @@ RawGamepadInfo* RawInputDataFetcher::ParseGamepadInfo(HANDLE hDevice) { |
// The presence of "IG_" in the device name indicates that this is an XInput |
// Gamepad. Skip enumerating these devices and let the XInput path handle it. |
// http://msdn.microsoft.com/en-us/library/windows/desktop/ee417014.aspx |
- if (filter_xinput_ && wcsstr( name_buffer.get(), L"IG_" ) ) |
+ if (filter_xinput_ && wcsstr(name_buffer.get(), L"IG_")) |
return NULL; |
// Get a friendly device name |
BOOLEAN got_product_string = FALSE; |
- HANDLE hid_handle = CreateFile(name_buffer.get(), GENERIC_READ|GENERIC_WRITE, |
- FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, NULL, NULL); |
+ HANDLE hid_handle = CreateFile( |
+ name_buffer.get(), GENERIC_READ | GENERIC_WRITE, |
+ FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, NULL, NULL); |
if (hid_handle) { |
got_product_string = hidd_get_product_string_(hid_handle, gamepad_info->id, |
- sizeof(gamepad_info->id)); |
+ sizeof(gamepad_info->id)); |
CloseHandle(hid_handle); |
} |
@@ -264,8 +258,7 @@ RawGamepadInfo* RawInputDataFetcher::ParseGamepadInfo(HANDLE hDevice) { |
swprintf(gamepad_info->id, WebGamepad::idLengthCap, L"Unknown Gamepad"); |
// Query device capabilities. |
- result = GetRawInputDeviceInfo(hDevice, RIDI_PREPARSEDDATA, |
- NULL, &size); |
+ result = GetRawInputDeviceInfo(hDevice, RIDI_PREPARSEDDATA, NULL, &size); |
if (result == static_cast<UINT>(-1)) { |
PLOG(ERROR) << "GetRawInputDeviceInfo() failed"; |
return NULL; |
@@ -276,7 +269,7 @@ RawGamepadInfo* RawInputDataFetcher::ParseGamepadInfo(HANDLE hDevice) { |
gamepad_info->preparsed_data = |
reinterpret_cast<PHIDP_PREPARSED_DATA>(gamepad_info->ppd_buffer.get()); |
result = GetRawInputDeviceInfo(hDevice, RIDI_PREPARSEDDATA, |
- gamepad_info->ppd_buffer.get(), &size); |
+ gamepad_info->ppd_buffer.get(), &size); |
if (result == static_cast<UINT>(-1)) { |
PLOG(ERROR) << "GetRawInputDeviceInfo() failed"; |
return NULL; |
@@ -292,8 +285,8 @@ RawGamepadInfo* RawInputDataFetcher::ParseGamepadInfo(HANDLE hDevice) { |
if (count > 0) { |
std::unique_ptr<HIDP_BUTTON_CAPS[]> button_caps( |
new HIDP_BUTTON_CAPS[count]); |
- status = hidp_get_button_caps_( |
- HidP_Input, button_caps.get(), &count, gamepad_info->preparsed_data); |
+ status = hidp_get_button_caps_(HidP_Input, button_caps.get(), &count, |
+ gamepad_info->preparsed_data); |
DCHECK_EQ(HIDP_STATUS_SUCCESS, status); |
for (uint32_t i = 0; i < count; ++i) { |
@@ -302,8 +295,8 @@ RawGamepadInfo* RawInputDataFetcher::ParseGamepadInfo(HANDLE hDevice) { |
uint32_t max_index = |
std::min(WebGamepad::buttonsLengthCap, |
static_cast<size_t>(button_caps[i].Range.UsageMax)); |
- gamepad_info->buttons_length = std::max( |
- gamepad_info->buttons_length, max_index); |
+ gamepad_info->buttons_length = |
+ std::max(gamepad_info->buttons_length, max_index); |
} |
} |
} |
@@ -312,7 +305,7 @@ RawGamepadInfo* RawInputDataFetcher::ParseGamepadInfo(HANDLE hDevice) { |
count = caps.NumberInputValueCaps; |
std::unique_ptr<HIDP_VALUE_CAPS[]> axes_caps(new HIDP_VALUE_CAPS[count]); |
status = hidp_get_value_caps_(HidP_Input, axes_caps.get(), &count, |
- gamepad_info->preparsed_data); |
+ gamepad_info->preparsed_data); |
bool mapped_all_axes = true; |
@@ -337,7 +330,6 @@ RawGamepadInfo* RawInputDataFetcher::ParseGamepadInfo(HANDLE hDevice) { |
uint32_t usage = axes_caps[i].Range.UsageMin - kAxisMinimumUsageNumber; |
if (usage >= WebGamepad::axesLengthCap && |
axes_caps[i].UsagePage <= kGameControlsUsagePage) { |
- |
for (; next_index < WebGamepad::axesLengthCap; ++next_index) { |
if (!gamepad_info->axes[next_index].active) |
break; |
@@ -346,8 +338,8 @@ RawGamepadInfo* RawInputDataFetcher::ParseGamepadInfo(HANDLE hDevice) { |
gamepad_info->axes[next_index].caps = axes_caps[i]; |
gamepad_info->axes[next_index].value = 0; |
gamepad_info->axes[next_index].active = true; |
- gamepad_info->axes[next_index].bitmask = GetBitmask( |
- axes_caps[i].BitSize); |
+ gamepad_info->axes[next_index].bitmask = |
+ GetBitmask(axes_caps[i].BitSize); |
gamepad_info->axes_length = |
std::max(gamepad_info->axes_length, next_index + 1); |
} |
@@ -361,9 +353,8 @@ RawGamepadInfo* RawInputDataFetcher::ParseGamepadInfo(HANDLE hDevice) { |
return gamepad_info.release(); |
} |
-void RawInputDataFetcher::UpdateGamepad( |
- RAWINPUT* input, |
- RawGamepadInfo* gamepad_info) { |
+void RawInputDataFetcher::UpdateGamepad(RAWINPUT* input, |
+ RawGamepadInfo* gamepad_info) { |
NTSTATUS status; |
gamepad_info->report_id++; |
@@ -374,10 +365,7 @@ void RawInputDataFetcher::UpdateGamepad( |
ZeroMemory(gamepad_info->buttons, sizeof(gamepad_info->buttons)); |
ULONG buttons_length = 0; |
- hidp_get_usages_ex_(HidP_Input, |
- 0, |
- NULL, |
- &buttons_length, |
+ hidp_get_usages_ex_(HidP_Input, 0, NULL, &buttons_length, |
gamepad_info->preparsed_data, |
reinterpret_cast<PCHAR>(input->data.hid.bRawData), |
input->data.hid.dwSizeHid); |
@@ -385,10 +373,7 @@ void RawInputDataFetcher::UpdateGamepad( |
std::unique_ptr<USAGE_AND_PAGE[]> usages( |
new USAGE_AND_PAGE[buttons_length]); |
status = |
- hidp_get_usages_ex_(HidP_Input, |
- 0, |
- usages.get(), |
- &buttons_length, |
+ hidp_get_usages_ex_(HidP_Input, 0, usages.get(), &buttons_length, |
gamepad_info->preparsed_data, |
reinterpret_cast<PCHAR>(input->data.hid.bRawData), |
input->data.hid.dwSizeHid); |
@@ -397,8 +382,7 @@ void RawInputDataFetcher::UpdateGamepad( |
// Set each reported button to true. |
for (uint32_t j = 0; j < buttons_length; j++) { |
int32_t button_index = usages[j].Usage - 1; |
- if (usages[j].UsagePage == kButtonUsagePage && |
- button_index >= 0 && |
+ if (usages[j].UsagePage == kButtonUsagePage && button_index >= 0 && |
button_index < |
static_cast<int>(blink::WebGamepad::buttonsLengthCap)) { |
gamepad_info->buttons[button_index] = true; |
@@ -416,25 +400,25 @@ void RawInputDataFetcher::UpdateGamepad( |
// If the min is < 0 we have to query the scaled value, otherwise we need |
// the normal unscaled value. |
if (axis->caps.LogicalMin < 0) { |
- status = hidp_get_scaled_usage_value_(HidP_Input, axis->caps.UsagePage, 0, |
- axis->caps.Range.UsageMin, &scaled_axis_value, |
- gamepad_info->preparsed_data, |
+ status = hidp_get_scaled_usage_value_( |
+ HidP_Input, axis->caps.UsagePage, 0, axis->caps.Range.UsageMin, |
+ &scaled_axis_value, gamepad_info->preparsed_data, |
reinterpret_cast<PCHAR>(input->data.hid.bRawData), |
input->data.hid.dwSizeHid); |
if (status == HIDP_STATUS_SUCCESS) { |
- axis->value = NormalizeAxis(scaled_axis_value, |
- axis->caps.PhysicalMin, axis->caps.PhysicalMax); |
+ axis->value = NormalizeAxis(scaled_axis_value, axis->caps.PhysicalMin, |
+ axis->caps.PhysicalMax); |
} |
} else { |
- status = hidp_get_usage_value_(HidP_Input, axis->caps.UsagePage, 0, |
- axis->caps.Range.UsageMin, &axis_value, |
- gamepad_info->preparsed_data, |
+ status = hidp_get_usage_value_( |
+ HidP_Input, axis->caps.UsagePage, 0, axis->caps.Range.UsageMin, |
+ &axis_value, gamepad_info->preparsed_data, |
reinterpret_cast<PCHAR>(input->data.hid.bRawData), |
input->data.hid.dwSizeHid); |
if (status == HIDP_STATUS_SUCCESS) { |
axis->value = NormalizeAxis(axis_value & axis->bitmask, |
- axis->caps.LogicalMin & axis->bitmask, |
- axis->caps.LogicalMax & axis->bitmask); |
+ axis->caps.LogicalMin & axis->bitmask, |
+ axis->caps.LogicalMax & axis->bitmask); |
} |
} |
} |
@@ -443,8 +427,8 @@ void RawInputDataFetcher::UpdateGamepad( |
LRESULT RawInputDataFetcher::OnInput(HRAWINPUT input_handle) { |
// Get the size of the input record. |
UINT size = 0; |
- UINT result = GetRawInputData( |
- input_handle, RID_INPUT, NULL, &size, sizeof(RAWINPUTHEADER)); |
+ UINT result = GetRawInputData(input_handle, RID_INPUT, NULL, &size, |
+ sizeof(RAWINPUTHEADER)); |
if (result == static_cast<UINT>(-1)) { |
PLOG(ERROR) << "GetRawInputData() failed"; |
return 0; |
@@ -454,8 +438,8 @@ LRESULT RawInputDataFetcher::OnInput(HRAWINPUT input_handle) { |
// Retrieve the input record. |
std::unique_ptr<uint8_t[]> buffer(new uint8_t[size]); |
RAWINPUT* input = reinterpret_cast<RAWINPUT*>(buffer.get()); |
- result = GetRawInputData( |
- input_handle, RID_INPUT, buffer.get(), &size, sizeof(RAWINPUTHEADER)); |
+ result = GetRawInputData(input_handle, RID_INPUT, buffer.get(), &size, |
+ sizeof(RAWINPUTHEADER)); |
if (result == static_cast<UINT>(-1)) { |
PLOG(ERROR) << "GetRawInputData() failed"; |
return 0; |
@@ -495,7 +479,8 @@ bool RawInputDataFetcher::GetHidDllFunctions() { |
hidp_get_scaled_usage_value_ = NULL; |
hidd_get_product_string_ = NULL; |
- if (!hid_dll_.is_valid()) return false; |
+ if (!hid_dll_.is_valid()) |
+ return false; |
hidp_get_caps_ = reinterpret_cast<HidPGetCapsFunc>( |
hid_dll_.GetFunctionPointer("HidP_GetCaps")); |
@@ -529,4 +514,4 @@ bool RawInputDataFetcher::GetHidDllFunctions() { |
return true; |
} |
-} // namespace content |
+} // namespace device |