+
+ /* LCOV_EXCL_STOP */
+ }
+
+ ret = tdm_output_add_change_handler(output, _tdm_server_cb_output_change, output_info);
+ if (ret != TDM_ERROR_NONE) {
+ wl_resource_post_no_memory(resource);
+ wl_resource_destroy(output_resource);
+ free(output_info);
+ TDM_ERR("tdm_output_add_change_handler failed");
+ return;
+ }
+
+ LIST_ADDTAIL(&output_info->link, &private_server->output_list);
+ output_info->private_server = private_server;
+ output_info->resource = output_resource;
+ output_info->output = output;
+ LIST_INITHEAD(&output_info->vblank_list);
+
+ wl_resource_set_implementation(output_resource, &tdm_output_implementation,
+ output_info, destroy_output_callback);
+
+ ret = tdm_output_get_conn_status(output, &status);
+ wl_tdm_output_send_connection(output_resource, status, ret);
+
+ if (status != TDM_OUTPUT_CONN_STATUS_DISCONNECTED) {
+ tdm_output_dpms dpms_value = TDM_OUTPUT_DPMS_OFF;
+ const tdm_output_mode *mode = NULL;
+ unsigned int hdisplay, vdisplay, vrefresh;
+
+ ret = tdm_output_get_mode(output, &mode);
+ hdisplay = (mode) ? mode->hdisplay : 0;
+ vdisplay = (mode) ? mode->vdisplay : 0;
+ vrefresh = (mode) ? mode->vrefresh : 0;
+ wl_tdm_output_send_mode(output_resource, hdisplay, vdisplay, vrefresh, ret);
+
+ ret = tdm_output_get_dpms(output, &dpms_value);
+ wl_tdm_output_send_dpms(output_resource, dpms_value, ret);
+ } else {
+ wl_tdm_output_send_mode(output_resource, 0, 0, 0, TDM_ERROR_OUTPUT_DISCONNECTED);
+ wl_tdm_output_send_dpms(output_resource, TDM_OUTPUT_DPMS_OFF, TDM_ERROR_OUTPUT_DISCONNECTED);
+ }
+}
+
+typedef struct _tdm_server_voutput_info {
+ tdm_private_server *private_server;
+ tdm_output_conn_status status;
+ struct
+ {
+ int count;
+ tdm_output_mode *modes;
+ } available_modes;
+} tdm_server_voutput_info;
+
+static void _tdm_voutput_cb_destroy(struct wl_client *client, struct wl_resource *resource)
+{
+ wl_resource_destroy(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)
+{
+ tdm_server_voutput_info *voutput_info;
+ tdm_output_mode *tmp_modes, *old_modes;
+ tdm_output_mode *new_mode;
+ int count, len;
+
+ 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 = index + 1;
+ voutput_info->available_modes.modes =
+ realloc(voutput_info->available_modes.modes,
+ sizeof(tdm_output_mode) * (index + 1));
+
+ if (count > 0)
+ {
+ memcpy(voutput_info->available_modes.modes, tmp_modes, count * sizeof(tdm_output_mode));
+ free(tmp_modes);
+ }
+ }
+
+ 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';
+}
+
+static void
+_tdm_voutput_cb_connect(struct wl_client *client, struct wl_resource *resource)
+{
+ tdm_server_voutput_info *voutput_info;
+
+ voutput_info = wl_resource_get_user_data(resource);
+ voutput_info->status = TDM_OUTPUT_CONN_STATUS_CONNECTED;
+}
+
+static void
+_tdm_voutput_cb_disconnect(struct wl_client *client, struct wl_resource *resource)
+{
+ tdm_server_voutput_info *voutput_info;
+
+ voutput_info = wl_resource_get_user_data(resource);
+ voutput_info->status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED;
+
+ /* Do free resources when it's being disconnected */
+ free(voutput_info->available_modes.modes);
+ voutput_info->available_modes.modes = NULL;
+ voutput_info->available_modes.count = 0;
+}
+
+static const struct wl_tdm_voutput_interface tdm_voutput_implementation = {
+ _tdm_voutput_cb_destroy,
+ _tdm_voutput_cb_set_available_modes,
+ _tdm_voutput_cb_connect,
+ _tdm_voutput_cb_disconnect
+};
+
+void
+tdm_voutput_cb_resource_destroy(struct wl_resource *resource)
+{
+ tdm_server_voutput_info *voutput_info;
+
+ voutput_info = wl_resource_get_user_data(resource);
+
+ /* Do free your own resource */
+ free(voutput_info);
+}
+
+static void
+_tdm_server_cb_create_virtual_output(struct wl_client *client, struct wl_resource *resource, const char *name, uint32_t id)
+{
+ struct wl_resource *voutput_resource = NULL;
+ tdm_private_server *private_server = wl_resource_get_user_data(resource);
+ tdm_server_voutput_info *voutput_info;
+ tdm_output *output;
+ tdm_error ret;
+
+ output = tdm_display_find_output(private_server->private_loop->dpy, name, NULL);
+ if (output) {
+ TDM_ERR("There is '%s' output, cannot create.", name);
+ wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
+ "There is '%s' output", name);
+ return;
+ }
+
+ output = tdm_display_create_output(private_server->private_loop->dpy, name, &ret);
+ if (!output) {
+ TDM_ERR("output creation fail(%s)(%d).", name, ret);
+ wl_resource_post_error(resource, WL_DISPLAY_ERROR_NO_MEMORY,
+ "%s output creation fail", name);
+ return;