HIDAPI_UpdateDiscovery: only treat "add" and "remove" events as relevant

I have a buggy system which reports a udev "change" event for an empty
USB-C port every 0.14 seconds, which causes annoying frame hitches
because SDL decides that means it needs to do a libusb hid_enumerate,
which is slow (~25ms!) because of the get_usb_string() calls in there.

We only need to re-enumerate if we've seen a device added or removed, so
let's filter out the change event first.

Signed-off-by: Steven Noonan <steven@valvesoftware.com>
Signed-off-by: Sam Lantinga <slouken@libsdl.org>
This commit is contained in:
Steven Noonan 2021-04-22 14:35:59 -07:00 committed by Sam Lantinga
parent b15bbd4e3f
commit 4535d65491
1 changed files with 5 additions and 2 deletions

View File

@ -442,10 +442,13 @@ HIDAPI_UpdateDiscovery()
break; break;
} }
SDL_HIDAPI_discovery.m_bHaveDevicesChanged = SDL_TRUE;
pUdevDevice = usyms->udev_monitor_receive_device(SDL_HIDAPI_discovery.m_pUdevMonitor); pUdevDevice = usyms->udev_monitor_receive_device(SDL_HIDAPI_discovery.m_pUdevMonitor);
if (pUdevDevice) { if (pUdevDevice) {
const char *action = NULL;
action = usyms->udev_device_get_action(pUdevDevice);
if (!action || SDL_strcmp(action, "add") == 0 || SDL_strcmp(action, "remove") == 0) {
SDL_HIDAPI_discovery.m_bHaveDevicesChanged = SDL_TRUE;
}
usyms->udev_device_unref(pUdevDevice); usyms->udev_device_unref(pUdevDevice);
} }
} }