mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/spice
synced 2025-12-28 16:29:56 +00:00
red-parse-qxl: Encapsulate QXL resource management
Reuse code. Signed-off-by: Frediano Ziglio <freddy77@gmail.com> Acked-by: Victor Toso <victortoso@redhat.com>
This commit is contained in:
parent
b6aa5798b7
commit
708cd97212
@ -77,6 +77,22 @@ static void hexdump_qxl(RedMemSlotInfo *slots, int group_id,
|
||||
}
|
||||
#endif
|
||||
|
||||
template <typename T>
|
||||
inline RedQXLResource<T>::~RedQXLResource()
|
||||
{
|
||||
if (qxl) {
|
||||
red_qxl_release_resource(qxl, release_info_ext);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void RedQXLResource<T>::set_resource(QXLInstance *qxl_instance, QXLReleaseInfo *info, uint32_t group_id)
|
||||
{
|
||||
qxl = qxl_instance;
|
||||
release_info_ext.info = info;
|
||||
release_info_ext.group_id = group_id;
|
||||
}
|
||||
|
||||
static inline uint32_t color_16_to_32(uint32_t color)
|
||||
{
|
||||
uint32_t ret;
|
||||
@ -1026,9 +1042,7 @@ static bool red_get_native_drawable(QXLInstance *qxl_instance, RedMemSlotInfo *s
|
||||
if (qxl == nullptr) {
|
||||
return false;
|
||||
}
|
||||
red->qxl = qxl_instance;
|
||||
red->release_info_ext.info = &qxl->release_info;
|
||||
red->release_info_ext.group_id = group_id;
|
||||
red->set_resource(qxl_instance, &qxl->release_info, group_id);
|
||||
|
||||
red_get_rect_ptr(&red->bbox, &qxl->bbox);
|
||||
red_get_clip_ptr(slots, group_id, &red->clip, &qxl->clip);
|
||||
@ -1106,9 +1120,7 @@ static bool red_get_compat_drawable(QXLInstance *qxl_instance, RedMemSlotInfo *s
|
||||
if (qxl == nullptr) {
|
||||
return false;
|
||||
}
|
||||
red->qxl = qxl_instance;
|
||||
red->release_info_ext.info = &qxl->release_info;
|
||||
red->release_info_ext.group_id = group_id;
|
||||
red->set_resource(qxl_instance, &qxl->release_info, group_id);
|
||||
|
||||
red_get_rect_ptr(&red->bbox, &qxl->bbox);
|
||||
red_get_clip_ptr(slots, group_id, &red->clip, &qxl->clip);
|
||||
@ -1240,9 +1252,6 @@ RedDrawable::~RedDrawable()
|
||||
red_put_whiteness(&u.whiteness);
|
||||
break;
|
||||
}
|
||||
if (qxl != nullptr) {
|
||||
red_qxl_release_resource(qxl, release_info_ext);
|
||||
}
|
||||
}
|
||||
|
||||
red::shared_ptr<RedDrawable>
|
||||
@ -1267,9 +1276,7 @@ static bool red_get_update_cmd(QXLInstance *qxl_instance, RedMemSlotInfo *slots,
|
||||
if (qxl == nullptr) {
|
||||
return false;
|
||||
}
|
||||
red->qxl = qxl_instance;
|
||||
red->release_info_ext.info = &qxl->release_info;
|
||||
red->release_info_ext.group_id = group_id;
|
||||
red->set_resource(qxl_instance, &qxl->release_info, group_id);
|
||||
|
||||
red_get_rect_ptr(&red->area, &qxl->area);
|
||||
red->update_id = qxl->update_id;
|
||||
@ -1277,12 +1284,7 @@ static bool red_get_update_cmd(QXLInstance *qxl_instance, RedMemSlotInfo *slots,
|
||||
return true;
|
||||
}
|
||||
|
||||
RedUpdateCmd::~RedUpdateCmd()
|
||||
{
|
||||
if (qxl != nullptr) {
|
||||
red_qxl_release_resource(qxl, release_info_ext);
|
||||
}
|
||||
}
|
||||
RedUpdateCmd::~RedUpdateCmd() = default;
|
||||
|
||||
red::shared_ptr<const RedUpdateCmd>
|
||||
red_update_cmd_new(QXLInstance *qxl, RedMemSlotInfo *slots,
|
||||
@ -1315,9 +1317,7 @@ static bool red_get_message(QXLInstance *qxl_instance, RedMemSlotInfo *slots, in
|
||||
if (qxl == nullptr) {
|
||||
return false;
|
||||
}
|
||||
red->qxl = qxl_instance;
|
||||
red->release_info_ext.info = &qxl->release_info;
|
||||
red->release_info_ext.group_id = group_id;
|
||||
red->set_resource(qxl_instance, &qxl->release_info, group_id);
|
||||
red->data = qxl->data;
|
||||
memslot_id = memslot_get_id(slots, addr+sizeof(*qxl));
|
||||
len = memslot_max_size_virt(slots, ((intptr_t) qxl)+sizeof(*qxl), memslot_id, group_id);
|
||||
@ -1330,12 +1330,7 @@ static bool red_get_message(QXLInstance *qxl_instance, RedMemSlotInfo *slots, in
|
||||
return true;
|
||||
}
|
||||
|
||||
RedMessage::~RedMessage()
|
||||
{
|
||||
if (qxl != nullptr) {
|
||||
red_qxl_release_resource(qxl, release_info_ext);
|
||||
}
|
||||
}
|
||||
RedMessage::~RedMessage() = default;
|
||||
|
||||
red::shared_ptr<const RedMessage>
|
||||
red_message_new(QXLInstance *qxl, RedMemSlotInfo *slots,
|
||||
@ -1403,9 +1398,7 @@ static bool red_get_surface_cmd(QXLInstance *qxl_instance, RedMemSlotInfo *slots
|
||||
if (qxl == nullptr) {
|
||||
return false;
|
||||
}
|
||||
red->qxl = qxl_instance;
|
||||
red->release_info_ext.info = &qxl->release_info;
|
||||
red->release_info_ext.group_id = group_id;
|
||||
red->set_resource(qxl_instance, &qxl->release_info, group_id);
|
||||
|
||||
red->surface_id = qxl->surface_id;
|
||||
red->type = qxl->type;
|
||||
@ -1434,12 +1427,7 @@ static bool red_get_surface_cmd(QXLInstance *qxl_instance, RedMemSlotInfo *slots
|
||||
return true;
|
||||
}
|
||||
|
||||
RedSurfaceCmd::~RedSurfaceCmd()
|
||||
{
|
||||
if (qxl) {
|
||||
red_qxl_release_resource(qxl, release_info_ext);
|
||||
}
|
||||
}
|
||||
RedSurfaceCmd::~RedSurfaceCmd() = default;
|
||||
|
||||
red::shared_ptr<const RedSurfaceCmd>
|
||||
red_surface_cmd_new(QXLInstance *qxl_instance, RedMemSlotInfo *slots,
|
||||
@ -1513,9 +1501,7 @@ static bool red_get_cursor_cmd(QXLInstance *qxl_instance, RedMemSlotInfo *slots,
|
||||
if (qxl == nullptr) {
|
||||
return false;
|
||||
}
|
||||
red->qxl = qxl_instance;
|
||||
red->release_info_ext.info = &qxl->release_info;
|
||||
red->release_info_ext.group_id = group_id;
|
||||
red->set_resource(qxl_instance, &qxl->release_info, group_id);
|
||||
|
||||
red->type = qxl->type;
|
||||
switch (red->type) {
|
||||
@ -1553,7 +1539,4 @@ RedCursorCmd::~RedCursorCmd()
|
||||
red_put_cursor(&u.set.shape);
|
||||
break;
|
||||
}
|
||||
if (qxl) {
|
||||
red_qxl_release_resource(qxl, release_info_ext);
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,10 +27,17 @@
|
||||
|
||||
#include "push-visibility.h"
|
||||
|
||||
struct RedDrawable final: public red::simple_ptr_counted<RedDrawable> {
|
||||
~RedDrawable();
|
||||
QXLInstance *qxl;
|
||||
template <typename T>
|
||||
struct RedQXLResource: public red::simple_ptr_counted<T> {
|
||||
~RedQXLResource();
|
||||
void set_resource(QXLInstance *qxl, QXLReleaseInfo *info, uint32_t group_id);
|
||||
private:
|
||||
QXLInstance *qxl = nullptr;
|
||||
QXLReleaseInfoExt release_info_ext;
|
||||
};
|
||||
|
||||
struct RedDrawable final: public RedQXLResource<RedDrawable> {
|
||||
~RedDrawable();
|
||||
uint32_t surface_id;
|
||||
uint8_t effect;
|
||||
uint8_t type;
|
||||
@ -62,19 +69,15 @@ struct RedDrawable final: public red::simple_ptr_counted<RedDrawable> {
|
||||
} u;
|
||||
};
|
||||
|
||||
struct RedUpdateCmd final: public red::simple_ptr_counted<RedUpdateCmd> {
|
||||
struct RedUpdateCmd final: public RedQXLResource<RedUpdateCmd> {
|
||||
~RedUpdateCmd();
|
||||
QXLInstance *qxl;
|
||||
QXLReleaseInfoExt release_info_ext;
|
||||
SpiceRect area;
|
||||
uint32_t update_id;
|
||||
uint32_t surface_id;
|
||||
};
|
||||
|
||||
struct RedMessage final: public red::simple_ptr_counted<RedMessage> {
|
||||
struct RedMessage final: public RedQXLResource<RedMessage> {
|
||||
~RedMessage();
|
||||
QXLInstance *qxl;
|
||||
QXLReleaseInfoExt release_info_ext;
|
||||
int len;
|
||||
uint8_t *data;
|
||||
};
|
||||
@ -87,10 +90,8 @@ typedef struct RedSurfaceCreate {
|
||||
uint8_t *data;
|
||||
} RedSurfaceCreate;
|
||||
|
||||
struct RedSurfaceCmd final: public red::simple_ptr_counted<RedSurfaceCmd> {
|
||||
struct RedSurfaceCmd final: public RedQXLResource<RedSurfaceCmd> {
|
||||
~RedSurfaceCmd();
|
||||
QXLInstance *qxl;
|
||||
QXLReleaseInfoExt release_info_ext;
|
||||
uint32_t surface_id;
|
||||
uint8_t type;
|
||||
uint32_t flags;
|
||||
@ -99,10 +100,8 @@ struct RedSurfaceCmd final: public red::simple_ptr_counted<RedSurfaceCmd> {
|
||||
} u;
|
||||
};
|
||||
|
||||
struct RedCursorCmd final: public red::simple_ptr_counted<RedCursorCmd> {
|
||||
struct RedCursorCmd final: public RedQXLResource<RedCursorCmd> {
|
||||
~RedCursorCmd();
|
||||
QXLInstance *qxl;
|
||||
QXLReleaseInfoExt release_info_ext;
|
||||
uint8_t type;
|
||||
union {
|
||||
struct {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user