From cd71ce67b135d7727b119df14fadc54ad62826c8 Mon Sep 17 00:00:00 2001 From: Thomas Hindoe Paaboel Andersen Date: Fri, 29 Sep 2017 00:04:37 +0200 Subject: [PATCH] hidpp10: only update current resolution once per commit With the swtich to the commit style the function hidpp10drv_write_resolution_dpi is doing too much work. Before commit style the function would: * get the profile * get the current resolution * write the profile (resets it to default dpi) * set the current (updated) resolution With the commit style we call the function for every resolution in every dirty profile we now: * get the current resolution * set the current (updated) resolution Then later: * write the profile (resets to default dpi) This patch changes this to only doing one set of the current resolution when the active profile has been written. This reduces the traffic to the device and sets the current resolution after the profile write. --- src/driver-hidpp10.c | 57 +++++++++++++------------------------------- 1 file changed, 17 insertions(+), 40 deletions(-) diff --git a/src/driver-hidpp10.c b/src/driver-hidpp10.c index 8050a9a9..b573e852 100644 --- a/src/driver-hidpp10.c +++ b/src/driver-hidpp10.c @@ -409,40 +409,6 @@ hidpp10drv_write_profile(struct ratbag_profile *profile) return 0; } -static int -hidpp10drv_write_resolution_dpi(struct hidpp10_profile *p, - struct ratbag_resolution *resolution, - int dpi_x, int dpi_y) -{ - struct ratbag_profile *profile = resolution->profile; - struct ratbag_device *device = profile->device; - struct hidpp10drv_data *drv_data = ratbag_get_drv_data(device); - struct hidpp10_device *hidpp10 = drv_data->dev; - unsigned int index; - uint16_t cur_dpi_x, cur_dpi_y; - int rc; - - /* store the current resolution */ - rc = hidpp10_get_current_resolution(hidpp10, &cur_dpi_x, &cur_dpi_y); - if (rc) - return rc; - - if (resolution->is_active) { - /* we need to switch to the new resolution */ - cur_dpi_x = dpi_x; - cur_dpi_y = dpi_y; - } - - /* retrieve which resolution is asked to be changed */ - index = resolution - profile->resolution.modes; - - p->dpi_modes[index].xres = dpi_x; - p->dpi_modes[index].yres = dpi_y; - - /* restore the current setting */ - return hidpp10_set_current_resolution(hidpp10, cur_dpi_x, cur_dpi_y); -} - static int hidpp10drv_fill_from_profile(struct ratbag_device *device, struct hidpp10_device *dev) { @@ -507,6 +473,7 @@ hidpp10drv_commit(struct ratbag_device *device) struct ratbag_profile *profile; struct ratbag_button *button; struct ratbag_resolution *resolution; + struct ratbag_resolution *active_resolution = NULL; struct hidpp10_profile p; int rc; unsigned int i; @@ -524,12 +491,11 @@ hidpp10drv_commit(struct ratbag_device *device) for (i = 0; i < profile->resolution.num_modes; i++) { resolution = &profile->resolution.modes[i]; - rc = hidpp10drv_write_resolution_dpi(&p, - resolution, - resolution->dpi_x, - resolution->dpi_y); - if (rc) - return RATBAG_ERROR_DEVICE; + p.dpi_modes[i].xres = resolution->dpi_x; + p.dpi_modes[i].yres = resolution->dpi_y; + + if (profile->is_active && resolution->is_active) + active_resolution = resolution; } list_for_each(button, &profile->buttons, link) { @@ -548,6 +514,17 @@ hidpp10drv_commit(struct ratbag_device *device) if (rc) return RATBAG_ERROR_DEVICE; } + + /* Update the current resolution in case it changed */ + if (active_resolution) { + rc = hidpp10_set_current_resolution(dev, + active_resolution->dpi_x, + active_resolution->dpi_y); + if (rc) + return RATBAG_ERROR_DEVICE; + + active_resolution = NULL; + } } return RATBAG_SUCCESS;