From e1e0134f1c58c97b0b28eb2e26086666c0ec93ea Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Thu, 26 Jul 2018 14:17:09 +0900 Subject: [PATCH] virtual (client): Use 'wl_array' when client sends available modes to server. Change-Id: I022945ad04eeb7b684305cc6604033c9760b005a --- client/tdm_client.c | 35 ++++++++++++++++------------ protocol/tdm.xml | 17 +------------- src/tdm_server.c | 67 +++++++++++------------------------------------------ 3 files changed, 34 insertions(+), 85 deletions(-) diff --git a/client/tdm_client.c b/client/tdm_client.c index d3e8b47..65c37da 100644 --- a/client/tdm_client.c +++ b/client/tdm_client.c @@ -1889,6 +1889,25 @@ _tdm_client_voutput_send_available_formats(tdm_private_client_voutput *private_v *format = private_voutput->available_formats.formats[i]; } wl_tdm_voutput_set_available_formats(private_voutput->wl_voutput, &array); + wl_array_release(&array); +} + +void +_tdm_client_voutput_send_available_modes(tdm_private_client_voutput *private_voutput) +{ + tdm_client_output_mode *modes, *mode; + struct wl_array array; + int i, size; + + modes = private_voutput->available_modes.modes; + size = sizeof(tdm_client_output_mode); + + wl_array_init(&array); + for (i = 0; i < private_voutput->available_modes.count; i++) { + mode = wl_array_add(&array, size); + memcpy(mode, &modes[i], size); + } + wl_tdm_voutput_set_available_modes(private_voutput->wl_voutput, &array); wl_array_release(&array); } @@ -1897,8 +1916,6 @@ tdm_client_output_connect(tdm_client_output *output) { tdm_private_client_output *private_output; tdm_private_client_voutput *private_voutput; - tdm_client_output_mode *modes; - int i; TDM_RETURN_VAL_IF_FAIL(output != NULL, TDM_ERROR_INVALID_PARAMETER); @@ -1910,19 +1927,7 @@ tdm_client_output_connect(tdm_client_output *output) private_output->connection = TDM_OUTPUT_CONN_STATUS_CONNECTED; - modes = private_voutput->available_modes.modes; - for (i = 0; i < private_voutput->available_modes.count; i++) { - wl_tdm_voutput_set_available_modes(private_voutput->wl_voutput, i, - modes[i].clock, modes[i].hdisplay, - modes[i].hsync_start, modes[i].hsync_end, - modes[i].htotal, modes[i].hskew, - modes[i].vdisplay, modes[i].vsync_start, - modes[i].vsync_end, modes[i].vtotal, - modes[i].vscan, modes[i].vrefresh, - modes[i].flags, modes[i].type, - modes[i].name); - } - + _tdm_client_voutput_send_available_modes(private_voutput); _tdm_client_voutput_send_available_formats(private_voutput); wl_tdm_voutput_set_physical_size(private_voutput->wl_voutput, private_voutput->mmwidth, private_voutput->mmheight); diff --git a/protocol/tdm.xml b/protocol/tdm.xml index 4cc3aae..f36636e 100644 --- a/protocol/tdm.xml +++ b/protocol/tdm.xml @@ -78,22 +78,7 @@ - - - - - - - - - - - - - - - - + diff --git a/src/tdm_server.c b/src/tdm_server.c index b394618..08fb539 100644 --- a/src/tdm_server.c +++ b/src/tdm_server.c @@ -730,68 +730,27 @@ static void _tdm_voutput_cb_destroy(struct wl_client *client, struct wl_resource static void _tdm_voutput_cb_set_available_modes(struct wl_client *client, struct wl_resource *resource, - uint32_t index, - uint32_t clock, - uint32_t hdisplay, - uint32_t hsync_start, - uint32_t hsync_end, - uint32_t htotal, - uint32_t hskew, - uint32_t vdisplay, - uint32_t vsync_start, - uint32_t vsync_end, - uint32_t vtotal, - uint32_t vscan, - uint32_t vrefresh, - uint32_t flags, - uint32_t type, - const char *name) + struct wl_array *modes) { tdm_server_voutput_info *voutput_info; - tdm_output_mode *tmp_modes, *old_modes; - tdm_output_mode *new_mode; - int count, len; + tdm_output_mode *mode; + int size, count = 0, i = 0; voutput_info = wl_resource_get_user_data(resource); - count = voutput_info->available_modes.count; - old_modes = voutput_info->available_modes.modes; - if (index >= count) { - if (count > 0) { - tmp_modes = malloc(count * sizeof(*tmp_modes)); - memcpy(tmp_modes, old_modes, count * sizeof(tdm_output_mode)); - } + voutput_info->available_modes.count = 0; + if (voutput_info->available_modes.modes) + free(voutput_info->available_modes.modes); - voutput_info->available_modes.count = index + 1; - voutput_info->available_modes.modes = - realloc(voutput_info->available_modes.modes, - sizeof(tdm_output_mode) * (index + 1)); + wl_array_for_each(mode, modes) + count++; + size = sizeof(tdm_output_mode); - if (count > 0) { - memcpy(voutput_info->available_modes.modes, tmp_modes, count * sizeof(tdm_output_mode)); - free(tmp_modes); - } - } + voutput_info->available_modes.modes = malloc(count * size); + voutput_info->available_modes.count = count; - new_mode = &voutput_info->available_modes.modes[index]; - new_mode->clock = clock; - new_mode->hdisplay = hdisplay; - new_mode->hsync_start = hsync_start; - new_mode->hsync_end = hsync_end; - new_mode->htotal = htotal; - new_mode->hskew= hskew; - new_mode->vdisplay= vdisplay; - new_mode->vsync_start= vsync_start; - new_mode->vsync_end = vsync_end; - new_mode->vtotal = vtotal; - new_mode->vscan = vscan; - new_mode->vrefresh = vrefresh; - new_mode->flags = flags; - new_mode->type = type; - - len = strlen(name); - strncpy(new_mode->name, name, len); - new_mode->name[len] = '\0'; + wl_array_for_each(mode, modes) + memcpy(&voutput_info->available_modes.modes[i++], mode, size); } static void -- 2.7.4