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

Unified Diff: content/browser/gamepad/raw_input_data_fetcher_win.cc

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 side-by-side diff with in-line comments
Download patch
Index: content/browser/gamepad/raw_input_data_fetcher_win.cc
diff --git a/content/browser/gamepad/raw_input_data_fetcher_win.cc b/content/browser/gamepad/raw_input_data_fetcher_win.cc
index e9238f3d38b31d682e3b572138fde8b26963d6c3..0693eef9eb87b51ccefc95850f8d2d676ac6338e 100644
--- a/content/browser/gamepad/raw_input_data_fetcher_win.cc
+++ b/content/browser/gamepad/raw_input_data_fetcher_win.cc
@@ -8,6 +8,7 @@
#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 {
@@ -43,11 +44,10 @@
}
RawInputDataFetcher::RawInputDataFetcher()
- : rawinput_available_(false),
+ : hid_dll_(base::FilePath(FILE_PATH_LITERAL("hid.dll"))),
+ rawinput_available_(GetHidDllFunctions()),
filter_xinput_(true),
- events_monitored_(false),
- last_source_id_(0),
- last_enumeration_id_(0) {
+ events_monitored_(false) {
}
RawInputDataFetcher::~RawInputDataFetcher() {
@@ -58,12 +58,6 @@
void RawInputDataFetcher::WillDestroyCurrentMessageLoop() {
StopMonitor();
-}
-
-void RawInputDataFetcher::OnAddedToProvider() {
- hid_dll_.Reset(base::LoadNativeLibrary(
- base::FilePath(FILE_PATH_LITERAL("hid.dll")), nullptr));
- rawinput_available_ = GetHidDllFunctions();
}
RAWINPUTDEVICE* RawInputDataFetcher::GetRawInputDevices(DWORD flags) {
@@ -78,13 +72,6 @@
return devices.release();
}
-void RawInputDataFetcher::PauseHint(bool pause) {
- if (pause)
- StopMonitor();
- else
- StartMonitor();
-}
-
void RawInputDataFetcher::StartMonitor() {
if (!rawinput_available_ || events_monitored_)
return;
@@ -144,44 +131,16 @@
}
}
-void RawInputDataFetcher::GetGamepadData(bool devices_changed_hint) {
- if (!rawinput_available_)
- return;
-
- if (devices_changed_hint)
- EnumerateDevices();
-
- for (const auto& controller : controllers_) {
- RawGamepadInfo* gamepad = controller.second;
- PadState* state = provider()->GetPadState(GAMEPAD_SOURCE_WIN_RAW,
- gamepad->source_id);
- if (!state)
- continue;
-
- WebGamepad& pad = state->data;
-
- pad.timestamp = gamepad->report_id;
- pad.buttonsLength = gamepad->buttons_length;
- pad.axesLength = gamepad->axes_length;
-
- for (unsigned int i = 0; i < pad.buttonsLength; i++) {
- pad.buttons[i].pressed = gamepad->buttons[i];
- pad.buttons[i].value = gamepad->buttons[i] ? 1.0 : 0.0;
- }
-
- for (unsigned int i = 0; i < pad.axesLength; i++)
- pad.axes[i] = gamepad->axes[i].value;
- }
-}
-
-void RawInputDataFetcher::EnumerateDevices() {
- last_enumeration_id_++;
+std::vector<RawGamepadInfo*> RawInputDataFetcher::EnumerateDevices() {
+ std::vector<RawGamepadInfo*> valid_controllers;
+
+ ClearControllers();
UINT count = 0;
UINT result = GetRawInputDeviceList(NULL, &count, sizeof(RAWINPUTDEVICELIST));
if (result == static_cast<UINT>(-1)) {
PLOG(ERROR) << "GetRawInputDeviceList() failed";
- return;
+ return valid_controllers;
}
DCHECK_EQ(0u, result);
@@ -190,68 +149,37 @@
sizeof(RAWINPUTDEVICELIST));
if (result == static_cast<UINT>(-1)) {
PLOG(ERROR) << "GetRawInputDeviceList() failed";
- return;
+ return valid_controllers;
}
DCHECK_EQ(count, result);
for (UINT i = 0; i < count; ++i) {
if (device_list[i].dwType == RIM_TYPEHID) {
HANDLE device_handle = device_list[i].hDevice;
- ControllerMap::iterator controller = controllers_.find(device_handle);
-
- RawGamepadInfo* gamepad;
- if (controller != controllers_.end()) {
- gamepad = controller->second;
- } else {
- gamepad = ParseGamepadInfo(device_handle);
- if (!gamepad)
- continue;
-
- PadState* state = provider()->GetPadState(GAMEPAD_SOURCE_WIN_RAW,
- gamepad->source_id);
- if (!state)
- continue; // No slot available for this gamepad.
-
- controllers_[device_handle] = gamepad;
-
- WebGamepad& pad = state->data;
- pad.connected = true;
-
- std::string vendor = base::StringPrintf("%04x", gamepad->vendor_id);
- std::string product = base::StringPrintf("%04x", gamepad->product_id);
- state->mapper = GetGamepadStandardMappingFunction(vendor, product);
- state->axis_mask = 0;
- state->button_mask = 0;
-
- swprintf(pad.id, WebGamepad::idLengthCap,
- L"%ls (%lsVendor: %04x Product: %04x)",
- gamepad->id, state->mapper ? L"STANDARD GAMEPAD " : L"",
- gamepad->vendor_id, gamepad->product_id);
-
- if (state->mapper)
- swprintf(pad.mapping, WebGamepad::mappingLengthCap, L"standard");
- else
- pad.mapping[0] = 0;
+ RawGamepadInfo* gamepad_info = ParseGamepadInfo(device_handle);
+ if (gamepad_info) {
+ controllers_[device_handle] = gamepad_info;
+ valid_controllers.push_back(gamepad_info);
}
-
- gamepad->enumeration_id = last_enumeration_id_;
- }
- }
-
- // Clear out old controllers that weren't part of this enumeration pass.
- for (const auto& controller : controllers_) {
- RawGamepadInfo* gamepad = controller.second;
- if (gamepad->enumeration_id != last_enumeration_id_) {
- controllers_.erase(gamepad->handle);
- delete gamepad;
- }
- }
-
- return;
+ }
+ }
+ return valid_controllers;
+}
+
+RawGamepadInfo* RawInputDataFetcher::GetGamepadInfo(HANDLE handle) {
+ std::map<HANDLE, RawGamepadInfo*>::iterator it = controllers_.find(handle);
+ if (it != controllers_.end())
+ return it->second;
+
+ return NULL;
}
RawGamepadInfo* RawInputDataFetcher::ParseGamepadInfo(HANDLE hDevice) {
UINT size = 0;
+
+ // Do we already have this device in the map?
+ if (GetGamepadInfo(hDevice))
+ return NULL;
// Query basic device info.
UINT result = GetRawInputDeviceInfo(hDevice, RIDI_DEVICEINFO,
@@ -286,8 +214,6 @@
return NULL;
scoped_ptr<RawGamepadInfo> gamepad_info(new RawGamepadInfo);
- gamepad_info->source_id = ++last_source_id_;
- gamepad_info->enumeration_id = last_enumeration_id_;
gamepad_info->handle = hDevice;
gamepad_info->report_id = 0;
gamepad_info->vendor_id = device_info->hid.dwVendorId;
@@ -426,10 +352,6 @@
break;
}
}
-
- // Sometimes devices show up with no buttons or axes. Don't return these.
- if (gamepad_info->buttons_length == 0 && gamepad_info->axes_length == 0)
- return nullptr;
return gamepad_info.release();
}
@@ -535,9 +457,9 @@
// Notify the observer about events generated locally.
if (input->header.dwType == RIM_TYPEHID && input->header.hDevice != NULL) {
- ControllerMap::iterator it = controllers_.find(input->header.hDevice);
- if (it != controllers_.end())
- UpdateGamepad(input, it->second);
+ RawGamepadInfo* gamepad = GetGamepadInfo(input->header.hDevice);
+ if (gamepad)
+ UpdateGamepad(input, gamepad);
}
return DefRawInputProc(&input, 1, sizeof(RAWINPUTHEADER));
« no previous file with comments | « content/browser/gamepad/raw_input_data_fetcher_win.h ('k') | content/browser/gamepad/xbox_data_fetcher_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698