[Spice-devel] [RFC PATCH spice 2/3] Send the graphics device info to the vd_agent

Jonathon Jongsma jjongsma at redhat.com
Thu Nov 8 20:36:35 UTC 2018


On Wed, 2018-11-07 at 18:23 +0100, Lukáš Hrázký wrote:
> Sends the device address and device display IDs to the vdagent. The
> message is sent either in reaction to the SPICE_MSGC_MAIN_AGENT_START
> message or when the graphics device ino changes.

typo: "ino"?

Otherwise looks OK

> 
> Signed-off-by: Lukáš Hrázký <lhrazky at redhat.com>
> ---
>  server/red-qxl.c      | 20 +++++++++++++
>  server/red-qxl.h      |  3 ++
>  server/reds-private.h |  1 +
>  server/reds.c         | 68
> +++++++++++++++++++++++++++++++++++++++++++
>  server/reds.h         |  1 +
>  5 files changed, 93 insertions(+)
> 
> diff --git a/server/red-qxl.c b/server/red-qxl.c
> index 6ffd8286..ebc14a46 100644
> --- a/server/red-qxl.c
> +++ b/server/red-qxl.c
> @@ -889,6 +889,26 @@ void spice_qxl_set_device_info(QXLInstance
> *instance,
>  
>      instance->st->monitors_count = device_display_id_count;
>      instance->st->max_monitors = device_display_id_count;
> +
> +    reds_send_device_display_info(red_qxl_get_server(instance->st));
> +}
> +
> +const char* red_qxl_get_device_address(const QXLInstance *qxl)
> +{
> +    const QXLState *qxl_state = qxl->st;
> +    return qxl_state->device_address;
> +}
> +
> +const uint32_t* red_qxl_get_device_display_ids(const QXLInstance
> *qxl)
> +{
> +    const QXLState *qxl_state = qxl->st;
> +    return qxl_state->device_display_ids;
> +}
> +
> +size_t red_qxl_get_monitors_count(const QXLInstance *qxl)
> +{
> +    const QXLState *qxl_state = qxl->st;
> +    return qxl_state->monitors_count;
>  }
>  
>  void red_qxl_init(RedsState *reds, QXLInstance *qxl)
> diff --git a/server/red-qxl.h b/server/red-qxl.h
> index 6014d32a..94753948 100644
> --- a/server/red-qxl.h
> +++ b/server/red-qxl.h
> @@ -40,6 +40,9 @@ void red_qxl_put_gl_scanout(QXLInstance *qxl,
> SpiceMsgDisplayGlScanoutUnix *scan
>  void red_qxl_gl_draw_async_complete(QXLInstance *qxl);
>  int red_qxl_check_qxl_version(QXLInstance *qxl, int major, int
> minor);
>  SpiceServer* red_qxl_get_server(QXLState *qxl);
> +const char* red_qxl_get_device_address(const QXLInstance *qxl);
> +const uint32_t* red_qxl_get_device_display_ids(const QXLInstance
> *qxl);
> +size_t red_qxl_get_monitors_count(const QXLInstance *qxl);
>  
>  /* Wrappers around QXLInterface vfuncs */
>  void red_qxl_get_init_info(QXLInstance *qxl, QXLDevInitInfo *info);
> diff --git a/server/reds-private.h b/server/reds-private.h
> index 920edc5c..9dbc7fa9 100644
> --- a/server/reds-private.h
> +++ b/server/reds-private.h
> @@ -81,6 +81,7 @@ struct RedsState {
>      SpiceWatch *secure_listen_watch;
>      RedCharDeviceVDIPort *agent_dev;
>      int pending_mouse_event;
> +    bool pending_device_display_info_message;
>      GList *clients;
>      MainChannel *main_channel;
>      InputsChannel *inputs_channel;
> diff --git a/server/reds.c b/server/reds.c
> index 1ea5897b..a6d3fd73 100644
> --- a/server/reds.c
> +++ b/server/reds.c
> @@ -257,6 +257,7 @@ typedef struct __attribute__ ((__packed__))
> VDInternalBuf {
>      VDAgentMessage header;
>      union {
>          VDAgentMouseState mouse_state;
> +        VDAgentGraphicsDeviceInfos graphics_device_info;
>      }
>      u;
>  } VDInternalBuf;
> @@ -894,6 +895,66 @@ static RedPipeItem
> *vdi_port_read_one_msg_from_device(RedCharDevice *self,
>      return NULL;
>  }
>  
> +void reds_send_device_display_info(RedsState *reds)
> +{
> +    g_info("Sending device display info to the agent:");
> +    if (!reds->agent_dev->priv->agent_attached) {
> +        g_warning("   no agent attached!");
> +        return;
> +    }
> +
> +    size_t message_size = sizeof(VDAgentGraphicsDeviceInfos);
> +    QXLInstance *qxl;
> +    FOREACH_QXL_INSTANCE(reds, qxl) {
> +        message_size +=
> +            (sizeof(VDAgentGraphicsDeviceInfo) +
> strlen(red_qxl_get_device_address(qxl)) + 1) *
> +            red_qxl_get_monitors_count(qxl);
> +    }
> +
> +    RedCharDeviceWriteBuffer *char_dev_buf =
> vdagent_new_write_buffer(reds->agent_dev,
> +                                         VD_AGENT_GRAPHICS_DEVICE_IN
> FO,
> +                                         message_size,
> +                                         true);
> +
> +    if (!char_dev_buf) {
> +        reds->pending_device_display_info_message = true;
> +        return;
> +    }
> +
> +    VDInternalBuf *internal_buf = (VDInternalBuf *)char_dev_buf-
> >buf;
> +    VDAgentGraphicsDeviceInfos *graphics_device_infos =
> &internal_buf->u.graphics_device_info;
> +    graphics_device_infos->count = 0;
> +
> +    VDAgentGraphicsDeviceInfo *graphics_device_info =
> graphics_device_infos->graphics_device_infos;
> +    FOREACH_QXL_INSTANCE(reds, qxl) {
> +        for (size_t i = 0; i < red_qxl_get_monitors_count(qxl); ++i)
> {
> +            graphics_device_info->channel_id = qxl->id;
> +            graphics_device_info->monitor_id = i;
> +            graphics_device_info->device_display_id =
> red_qxl_get_device_display_ids(qxl)[i];
> +
> +            strcpy((char*) graphics_device_info->device_address,
> red_qxl_get_device_address(qxl));
> +
> +            graphics_device_info->device_address_len =
> +                strlen((char*) graphics_device_info->device_address) 
> + 1;
> +
> +            g_info("   channel_id: %u monitor_id: %u,
> device_address: %s, device_display_id: %u",
> +                graphics_device_info->channel_id,
> +                graphics_device_info->monitor_id,
> +                graphics_device_info->device_address,
> +                graphics_device_info->device_display_id);
> +
> +            graphics_device_info = (VDAgentGraphicsDeviceInfo*)
> ((char*) graphics_device_info +
> +                    sizeof(VDAgentGraphicsDeviceInfo) +
> graphics_device_info->device_address_len);
> +
> +            graphics_device_infos->count++;
> +        }
> +    }
> +
> +    reds->pending_device_display_info_message = false;
> +
> +    red_char_device_write_buffer_add(RED_CHAR_DEVICE(reds-
> >agent_dev), char_dev_buf);
> +}
> +
>  /* after calling this, we unref the message, and the ref is in the
> instance side */
>  static void vdi_port_send_msg_to_client(RedCharDevice *self,
>                                          RedPipeItem *msg,
> @@ -925,6 +986,11 @@ static void
> vdi_port_on_free_self_token(RedCharDevice *self)
>          spice_debug("pending mouse event");
>          reds_handle_agent_mouse_event(reds,
> inputs_channel_get_mouse_state(reds->inputs_channel));
>      }
> +
> +    if (reds->pending_device_display_info_message) {
> +        spice_debug("pending device display info message");
> +        reds_send_device_display_info(reds);
> +    }
>  }
>  
>  static void vdi_port_remove_client(RedCharDevice *self,
> @@ -1062,6 +1128,8 @@ void reds_on_main_agent_start(RedsState *reds,
> MainChannelClient *mcc, uint32_t
>                                                    num_tokens);
>      }
>  
> +    reds_send_device_display_info(reds);
> +
>      agent_msg_filter_config(&reds->agent_dev->priv->write_filter,
> reds->config->agent_copypaste,
>                              reds->config->agent_file_xfer,
>                              reds_use_client_monitors_config(reds));
> diff --git a/server/reds.h b/server/reds.h
> index 9f17a5ec..8260ab5c 100644
> --- a/server/reds.h
> +++ b/server/reds.h
> @@ -50,6 +50,7 @@ gboolean reds_config_get_agent_mouse(const
> RedsState *reds); // used by inputs_c
>  int reds_has_vdagent(RedsState *reds); // used by inputs channel
>  bool reds_config_get_playback_compression(RedsState *reds); // used
> by playback channel
>  
> +void reds_send_device_display_info(RedsState *reds);
>  void reds_handle_agent_mouse_event(RedsState *reds, const
> VDAgentMouseState *mouse_state); // used by inputs_channel
>  
>  GArray* reds_get_renderers(RedsState *reds);



More information about the Spice-devel mailing list