red-parse-qxl: Use a base reference class for RedDrawable

Don't code manually reference counting for this structure

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
This commit is contained in:
Frediano Ziglio 2020-05-05 17:39:14 +01:00
parent 110b97e51e
commit b6aa5798b7
10 changed files with 96 additions and 118 deletions

View File

@ -530,7 +530,7 @@ static void marshall_qxl_draw_fill(DisplayChannelClient *dcc,
RedDrawablePipeItem *dpi)
{
Drawable *item = dpi->drawable;
RedDrawable *drawable = item->red_drawable;
RedDrawable *drawable = item->red_drawable.get();
SpiceMarshaller *brush_pat_out;
SpiceMarshaller *mask_bitmap_out;
SpiceFill fill;
@ -561,7 +561,7 @@ static void surface_lossy_region_update(DisplayChannelClient *dcc,
}
surface_lossy_region = &dcc->priv->surface_client_lossy_region[item->surface_id];
drawable = item->red_drawable;
drawable = item->red_drawable.get();
if (drawable->clip.type == SPICE_CLIP_TYPE_RECTS ) {
QRegion clip_rgn;
@ -636,7 +636,7 @@ static bool drawable_depends_on_areas(Drawable *drawable, int surface_ids[],
int drawable_has_shadow;
SpiceRect shadow_rect = {0, 0, 0, 0};
red_drawable = drawable->red_drawable;
red_drawable = drawable->red_drawable.get();
drawable_has_shadow = has_shadow(red_drawable);
if (drawable_has_shadow) {
@ -737,7 +737,7 @@ static void red_add_lossless_drawable_dependencies(DisplayChannelClient *dcc,
int num_deps)
{
DisplayChannel *display = DCC_TO_DC(dcc);
RedDrawable *drawable = item->red_drawable;
RedDrawable *drawable = item->red_drawable.get();
int sync_rendered = FALSE;
int i;
@ -803,7 +803,7 @@ static void red_lossy_marshall_qxl_draw_fill(DisplayChannelClient *dcc,
RedDrawablePipeItem *dpi)
{
Drawable *item = dpi->drawable;
RedDrawable *drawable = item->red_drawable;
RedDrawable *drawable = item->red_drawable.get();
int dest_allowed_lossy = FALSE;
int dest_is_lossy = FALSE;
@ -860,7 +860,7 @@ static FillBitsType red_marshall_qxl_draw_opaque(DisplayChannelClient *dcc,
int src_allowed_lossy)
{
Drawable *item = dpi->drawable;
RedDrawable *drawable = item->red_drawable;
RedDrawable *drawable = item->red_drawable.get();
SpiceMarshaller *brush_pat_out;
SpiceMarshaller *src_bitmap_out;
SpiceMarshaller *mask_bitmap_out;
@ -892,7 +892,7 @@ static void red_lossy_marshall_qxl_draw_opaque(DisplayChannelClient *dcc,
RedDrawablePipeItem *dpi)
{
Drawable *item = dpi->drawable;
RedDrawable *drawable = item->red_drawable;
RedDrawable *drawable = item->red_drawable.get();
int src_allowed_lossy;
int rop;
@ -956,7 +956,7 @@ static FillBitsType red_marshall_qxl_draw_copy(DisplayChannelClient *dcc,
int src_allowed_lossy)
{
Drawable *item = dpi->drawable;
RedDrawable *drawable = item->red_drawable;
RedDrawable *drawable = item->red_drawable.get();
SpiceMarshaller *src_bitmap_out;
SpiceMarshaller *mask_bitmap_out;
SpiceCopy copy;
@ -981,7 +981,7 @@ static void red_lossy_marshall_qxl_draw_copy(DisplayChannelClient *dcc,
RedDrawablePipeItem *dpi)
{
Drawable *item = dpi->drawable;
RedDrawable *drawable = item->red_drawable;
RedDrawable *drawable = item->red_drawable.get();
int has_mask = !!drawable->u.copy.mask.bitmap;
int src_is_lossy;
BitmapData src_bitmap_data;
@ -1005,7 +1005,7 @@ static void red_marshall_qxl_draw_transparent(DisplayChannelClient *dcc,
RedDrawablePipeItem *dpi)
{
Drawable *item = dpi->drawable;
RedDrawable *drawable = item->red_drawable;
RedDrawable *drawable = item->red_drawable.get();
SpiceMarshaller *src_bitmap_out;
SpiceTransparent transparent;
@ -1023,7 +1023,7 @@ static void red_lossy_marshall_qxl_draw_transparent(DisplayChannelClient *dcc,
RedDrawablePipeItem *dpi)
{
Drawable *item = dpi->drawable;
RedDrawable *drawable = item->red_drawable;
RedDrawable *drawable = item->red_drawable.get();
int src_is_lossy;
BitmapData src_bitmap_data;
@ -1051,7 +1051,7 @@ static FillBitsType red_marshall_qxl_draw_alpha_blend(DisplayChannelClient *dcc,
int src_allowed_lossy)
{
Drawable *item = dpi->drawable;
RedDrawable *drawable = item->red_drawable;
RedDrawable *drawable = item->red_drawable.get();
SpiceMarshaller *src_bitmap_out;
SpiceAlphaBlend alpha_blend;
FillBitsType src_send_type;
@ -1073,7 +1073,7 @@ static void red_lossy_marshall_qxl_draw_alpha_blend(DisplayChannelClient *dcc,
RedDrawablePipeItem *dpi)
{
Drawable *item = dpi->drawable;
RedDrawable *drawable = item->red_drawable;
RedDrawable *drawable = item->red_drawable.get();
int src_is_lossy;
BitmapData src_bitmap_data;
FillBitsType src_send_type;
@ -1099,7 +1099,7 @@ static void red_marshall_qxl_copy_bits(RedChannelClient *rcc,
RedDrawablePipeItem *dpi)
{
Drawable *item = dpi->drawable;
RedDrawable *drawable = item->red_drawable;
RedDrawable *drawable = item->red_drawable.get();
SpicePoint copy_bits;
rcc->init_send_data(SPICE_MSG_DISPLAY_COPY_BITS);
@ -1114,7 +1114,7 @@ static void red_lossy_marshall_qxl_copy_bits(DisplayChannelClient *dcc,
RedDrawablePipeItem *dpi)
{
Drawable *item = dpi->drawable;
RedDrawable *drawable = item->red_drawable;
RedDrawable *drawable = item->red_drawable.get();
SpiceRect src_rect;
int horz_offset;
int vert_offset;
@ -1142,7 +1142,7 @@ static void red_marshall_qxl_draw_blend(DisplayChannelClient *dcc,
RedDrawablePipeItem *dpi)
{
Drawable *item = dpi->drawable;
RedDrawable *drawable = item->red_drawable;
RedDrawable *drawable = item->red_drawable.get();
SpiceMarshaller *src_bitmap_out;
SpiceMarshaller *mask_bitmap_out;
SpiceBlend blend;
@ -1165,7 +1165,7 @@ static void red_lossy_marshall_qxl_draw_blend(DisplayChannelClient *dcc,
RedDrawablePipeItem *dpi)
{
Drawable *item = dpi->drawable;
RedDrawable *drawable = item->red_drawable;
RedDrawable *drawable = item->red_drawable.get();
int src_is_lossy;
BitmapData src_bitmap_data;
int dest_is_lossy;
@ -1206,7 +1206,7 @@ static void red_marshall_qxl_draw_blackness(DisplayChannelClient *dcc,
RedDrawablePipeItem *dpi)
{
Drawable *item = dpi->drawable;
RedDrawable *drawable = item->red_drawable;
RedDrawable *drawable = item->red_drawable.get();
SpiceMarshaller *mask_bitmap_out;
SpiceBlackness blackness;
@ -1226,7 +1226,7 @@ static void red_lossy_marshall_qxl_draw_blackness(DisplayChannelClient *dcc,
RedDrawablePipeItem *dpi)
{
Drawable *item = dpi->drawable;
RedDrawable *drawable = item->red_drawable;
RedDrawable *drawable = item->red_drawable.get();
int has_mask = !!drawable->u.blackness.mask.bitmap;
red_marshall_qxl_draw_blackness(dcc, base_marshaller, dpi);
@ -1239,7 +1239,7 @@ static void red_marshall_qxl_draw_whiteness(DisplayChannelClient *dcc,
RedDrawablePipeItem *dpi)
{
Drawable *item = dpi->drawable;
RedDrawable *drawable = item->red_drawable;
RedDrawable *drawable = item->red_drawable.get();
SpiceMarshaller *mask_bitmap_out;
SpiceWhiteness whiteness;
@ -1259,7 +1259,7 @@ static void red_lossy_marshall_qxl_draw_whiteness(DisplayChannelClient *dcc,
RedDrawablePipeItem *dpi)
{
Drawable *item = dpi->drawable;
RedDrawable *drawable = item->red_drawable;
RedDrawable *drawable = item->red_drawable.get();
int has_mask = !!drawable->u.whiteness.mask.bitmap;
red_marshall_qxl_draw_whiteness(dcc, base_marshaller, dpi);
@ -1271,7 +1271,7 @@ static void red_marshall_qxl_draw_inverse(DisplayChannelClient *dcc,
SpiceMarshaller *base_marshaller,
Drawable *item)
{
RedDrawable *drawable = item->red_drawable;
RedDrawable *drawable = item->red_drawable.get();
SpiceMarshaller *mask_bitmap_out;
SpiceInvers inverse;
@ -1298,7 +1298,7 @@ static void red_marshall_qxl_draw_rop3(DisplayChannelClient *dcc,
RedDrawablePipeItem *dpi)
{
Drawable *item = dpi->drawable;
RedDrawable *drawable = item->red_drawable;
RedDrawable *drawable = item->red_drawable.get();
SpiceRop3 rop3;
SpiceMarshaller *src_bitmap_out;
SpiceMarshaller *brush_pat_out;
@ -1326,7 +1326,7 @@ static void red_lossy_marshall_qxl_draw_rop3(DisplayChannelClient *dcc,
RedDrawablePipeItem *dpi)
{
Drawable *item = dpi->drawable;
RedDrawable *drawable = item->red_drawable;
RedDrawable *drawable = item->red_drawable.get();
int src_is_lossy;
BitmapData src_bitmap_data;
int brush_is_lossy;
@ -1380,7 +1380,7 @@ static void red_marshall_qxl_draw_composite(DisplayChannelClient *dcc,
RedDrawablePipeItem *dpi)
{
Drawable *item = dpi->drawable;
RedDrawable *drawable = item->red_drawable;
RedDrawable *drawable = item->red_drawable.get();
SpiceMarshaller *src_bitmap_out;
SpiceMarshaller *mask_bitmap_out;
SpiceComposite composite;
@ -1404,7 +1404,7 @@ static void red_lossy_marshall_qxl_draw_composite(DisplayChannelClient *dcc,
RedDrawablePipeItem *dpi)
{
Drawable *item = dpi->drawable;
RedDrawable *drawable = item->red_drawable;
RedDrawable *drawable = item->red_drawable.get();
int src_is_lossy;
BitmapData src_bitmap_data;
int mask_is_lossy;
@ -1459,7 +1459,7 @@ static void red_marshall_qxl_draw_stroke(DisplayChannelClient *dcc,
RedDrawablePipeItem *dpi)
{
Drawable *item = dpi->drawable;
RedDrawable *drawable = item->red_drawable;
RedDrawable *drawable = item->red_drawable.get();
SpiceStroke stroke;
SpiceMarshaller *brush_pat_out;
SpiceMarshaller *style_out;
@ -1483,7 +1483,7 @@ static void red_lossy_marshall_qxl_draw_stroke(DisplayChannelClient *dcc,
RedDrawablePipeItem *dpi)
{
Drawable *item = dpi->drawable;
RedDrawable *drawable = item->red_drawable;
RedDrawable *drawable = item->red_drawable.get();
int brush_is_lossy;
BitmapData brush_bitmap_data;
int dest_is_lossy = FALSE;
@ -1537,7 +1537,7 @@ static void red_marshall_qxl_draw_text(DisplayChannelClient *dcc,
RedDrawablePipeItem *dpi)
{
Drawable *item = dpi->drawable;
RedDrawable *drawable = item->red_drawable;
RedDrawable *drawable = item->red_drawable.get();
SpiceText text;
SpiceMarshaller *brush_pat_out;
SpiceMarshaller *back_brush_pat_out;
@ -1563,7 +1563,7 @@ static void red_lossy_marshall_qxl_draw_text(DisplayChannelClient *dcc,
RedDrawablePipeItem *dpi)
{
Drawable *item = dpi->drawable;
RedDrawable *drawable = item->red_drawable;
RedDrawable *drawable = item->red_drawable.get();
int fg_is_lossy;
BitmapData fg_bitmap_data;
int bg_is_lossy;
@ -1669,7 +1669,7 @@ static bool red_marshall_stream_data(DisplayChannelClient *dcc,
frame_mm_time,
&copy->src_bitmap->u.bitmap,
&copy->src_area, stream->top_down,
drawable->red_drawable,
drawable->red_drawable.get(),
&outbuf);
switch (ret) {
case VIDEO_ENCODER_FRAME_DROP:
@ -2019,7 +2019,7 @@ static void marshall_lossless_qxl_drawable(DisplayChannelClient *dcc,
RedDrawablePipeItem *dpi)
{
Drawable *item = dpi->drawable;
RedDrawable *drawable = item->red_drawable;
RedDrawable *drawable = item->red_drawable.get();
switch (drawable->type) {
case QXL_DRAW_FILL:
@ -2117,7 +2117,7 @@ static void marshall_stream_start(DisplayChannelClient *dcc,
stream_create.dest = stream->dest_area;
if (stream->current) {
RedDrawable *red_drawable = stream->current->red_drawable;
RedDrawable *red_drawable = stream->current->red_drawable.get();
stream_create.clip = red_drawable->clip;
} else {
stream_create.clip.type = SPICE_CLIP_TYPE_RECTS;
@ -2171,7 +2171,7 @@ static void marshall_upgrade(DisplayChannelClient *dcc, SpiceMarshaller *m,
spice_assert(channel && item && item->drawable);
dcc->init_send_data(SPICE_MSG_DISPLAY_DRAW_COPY);
red_drawable = item->drawable->red_drawable;
red_drawable = item->drawable->red_drawable.get();
spice_assert(red_drawable->type == QXL_DRAW_COPY);
spice_assert(red_drawable->u.copy.rop_descriptor == SPICE_ROPD_OP_PUT);
spice_assert(red_drawable->u.copy.mask.bitmap == nullptr);

View File

@ -665,7 +665,7 @@ int dcc_compress_image(DisplayChannelClient *dcc,
break;
case SPICE_IMAGE_COMPRESSION_GLZ:
success = image_encoders_compress_glz(&dcc->priv->encoders, dest, src,
drawable->red_drawable, &drawable->glz_retention,
drawable->red_drawable.get(), &drawable->glz_retention,
o_comp_data,
display_channel->priv->enable_zlib_glz_wrap);
if (success) {

View File

@ -799,7 +799,7 @@ static bool current_add_with_shadow(DisplayChannel *display, Ring *ring, Drawabl
++display->priv->add_with_shadow_count;
#endif
RedDrawable *red_drawable = item->red_drawable;
RedDrawable *red_drawable = item->red_drawable.get();
SpicePoint delta = {
.x = red_drawable->u.copy_bits.src_pos.x - red_drawable->bbox.left,
.y = red_drawable->u.copy_bits.src_pos.y - red_drawable->bbox.top
@ -1043,7 +1043,7 @@ static bool current_add(DisplayChannel *display, Ring *ring, Drawable *drawable)
static bool drawable_can_stream(DisplayChannel *display, Drawable *drawable)
{
RedDrawable *red_drawable = drawable->red_drawable;
RedDrawable *red_drawable = drawable->red_drawable.get();
SpiceImage *image;
if (display->priv->stream_video == SPICE_STREAM_VIDEO_OFF) {
@ -1131,7 +1131,7 @@ static void surface_read_bits(DisplayChannel *display, int surface_id,
static void handle_self_bitmap(DisplayChannel *display, Drawable *drawable)
{
RedDrawable *red_drawable = drawable->red_drawable;
RedDrawable *red_drawable = drawable->red_drawable.get();
SpiceImage *image;
int32_t width;
int32_t height;
@ -1274,7 +1274,7 @@ static bool validate_drawable_bbox(DisplayChannel *display, RedDrawable *drawabl
* @return initialized Drawable or NULL on failure
*/
static Drawable *display_channel_get_drawable(DisplayChannel *display, uint8_t effect,
RedDrawable *red_drawable,
red::shared_ptr<RedDrawable> &&red_drawable,
uint32_t process_commands_generation)
{
Drawable *drawable;
@ -1282,7 +1282,7 @@ static Drawable *display_channel_get_drawable(DisplayChannel *display, uint8_t e
/* Validate all surface ids before updating counters
* to avoid invalid updates if we find an invalid id.
*/
if (!validate_drawable_bbox(display, red_drawable)) {
if (!validate_drawable_bbox(display, red_drawable.get())) {
return nullptr;
}
for (const auto surface_id : red_drawable->surface_deps) {
@ -1297,12 +1297,14 @@ static Drawable *display_channel_get_drawable(DisplayChannel *display, uint8_t e
}
drawable->tree_item.effect = effect;
drawable->red_drawable = red_drawable_ref(red_drawable);
drawable->surface_id = red_drawable->surface_id;
display->priv->surfaces[drawable->surface_id].refs++;
memcpy(drawable->surface_deps, red_drawable->surface_deps, sizeof(drawable->surface_deps));
drawable->red_drawable = red_drawable;
/*
surface->refs is affected by a drawable (that is
dependent on the surface) as long as the drawable is alive.
@ -1321,7 +1323,7 @@ static Drawable *display_channel_get_drawable(DisplayChannel *display, uint8_t e
static void display_channel_add_drawable(DisplayChannel *display, Drawable *drawable)
{
int surface_id = drawable->surface_id;
RedDrawable *red_drawable = drawable->red_drawable;
RedDrawable *red_drawable = drawable->red_drawable.get();
red_drawable->mm_time = reds_get_mm_time();
@ -1368,11 +1370,12 @@ static void display_channel_add_drawable(DisplayChannel *display, Drawable *draw
#endif
}
void display_channel_process_draw(DisplayChannel *display, RedDrawable *red_drawable,
void display_channel_process_draw(DisplayChannel *display,
red::shared_ptr<RedDrawable> &&red_drawable,
uint32_t process_commands_generation)
{
Drawable *drawable =
display_channel_get_drawable(display, red_drawable->effect, red_drawable,
display_channel_get_drawable(display, red_drawable->effect, std::move(red_drawable),
process_commands_generation);
if (!drawable) {
@ -1630,9 +1633,6 @@ void drawable_unref(Drawable *drawable)
glz_retention_detach_drawables(&drawable->glz_retention);
if (drawable->red_drawable) {
red_drawable_unref(drawable->red_drawable);
}
drawable_free(display, drawable);
}

View File

@ -64,7 +64,7 @@ struct Drawable {
RingItem list_link;
DrawItem tree_item;
GList *pipes;
RedDrawable *red_drawable;
red::shared_ptr<RedDrawable> red_drawable;
GlzImageRetention glz_retention;
@ -121,14 +121,14 @@ void display_channel_free_glz_drawables (DisplayCha
void display_channel_destroy_surface_wait (DisplayChannel *display,
uint32_t surface_id);
void display_channel_destroy_surfaces (DisplayChannel *display);
void display_channel_process_draw (DisplayChannel *display,
RedDrawable *red_drawable,
uint32_t process_commands_generation);
void display_channel_gl_scanout (DisplayChannel *display);
void display_channel_gl_draw (DisplayChannel *display,
SpiceMsgDisplayGlDraw *draw);
void display_channel_gl_draw_done (DisplayChannel *display);
void display_channel_process_draw(DisplayChannel *display,
red::shared_ptr<RedDrawable> &&red_drawable,
uint32_t process_commands_generation);
void display_channel_process_surface_cmd(DisplayChannel *display,
red::shared_ptr<const RedSurfaceCmd> &&surface_cmd,
bool loadvm);

View File

@ -67,7 +67,7 @@ struct GlzDrawableInstanceItem {
struct RedGlzDrawable {
RingItem link; // ordered by the time it was encoded
RingItem drawable_link;
RedDrawable *red_drawable;
red::shared_ptr<RedDrawable> red_drawable;
GlzDrawableInstanceItem instances_pool[MAX_GLZ_DRAWABLE_INSTANCES];
Ring instances;
uint8_t instances_count;
@ -524,7 +524,7 @@ static void glz_drawable_instance_item_free(GlzDrawableInstanceItem *instance)
if (glz_drawable->has_drawable) {
ring_remove(&glz_drawable->drawable_link);
}
red_drawable_unref(glz_drawable->red_drawable);
glz_drawable->red_drawable.reset();
glz_drawable->encoders->shared_data->glz_drawable_count--;
if (ring_item_is_linked(&glz_drawable->link)) {
ring_remove(&glz_drawable->link);
@ -1166,10 +1166,10 @@ static RedGlzDrawable *get_glz_drawable(ImageEncoders *enc, RedDrawable *red_dra
}
}
ret = g_new(RedGlzDrawable, 1);
ret = g_new0(RedGlzDrawable, 1);
ret->encoders = enc;
ret->red_drawable = red_drawable_ref(red_drawable);
ret->red_drawable.reset(red_drawable);
ret->has_drawable = TRUE;
ret->instances_count = 0;
ring_init(&ret->instances);

View File

@ -1193,89 +1193,71 @@ static bool red_get_drawable(QXLInstance *qxl, RedMemSlotInfo *slots, int group_
return ret;
}
static void red_put_drawable(RedDrawable *red)
RedDrawable::~RedDrawable()
{
red_put_clip(&red->clip);
if (red->self_bitmap_image) {
red_put_image(red->self_bitmap_image);
red_put_clip(&clip);
if (self_bitmap_image) {
red_put_image(self_bitmap_image);
}
switch (red->type) {
switch (type) {
case QXL_DRAW_ALPHA_BLEND:
red_put_alpha_blend(&red->u.alpha_blend);
red_put_alpha_blend(&u.alpha_blend);
break;
case QXL_DRAW_BLACKNESS:
red_put_blackness(&red->u.blackness);
red_put_blackness(&u.blackness);
break;
case QXL_DRAW_BLEND:
red_put_blend(&red->u.blend);
red_put_blend(&u.blend);
break;
case QXL_DRAW_COPY:
red_put_copy(&red->u.copy);
red_put_copy(&u.copy);
break;
case QXL_DRAW_FILL:
red_put_fill(&red->u.fill);
red_put_fill(&u.fill);
break;
case QXL_DRAW_OPAQUE:
red_put_opaque(&red->u.opaque);
red_put_opaque(&u.opaque);
break;
case QXL_DRAW_INVERS:
red_put_invers(&red->u.invers);
red_put_invers(&u.invers);
break;
case QXL_DRAW_ROP3:
red_put_rop3(&red->u.rop3);
red_put_rop3(&u.rop3);
break;
case QXL_DRAW_COMPOSITE:
red_put_composite(&red->u.composite);
red_put_composite(&u.composite);
break;
case QXL_DRAW_STROKE:
red_put_stroke(&red->u.stroke);
red_put_stroke(&u.stroke);
break;
case QXL_DRAW_TEXT:
red_put_text_ptr(&red->u.text);
red_put_text_ptr(&u.text);
break;
case QXL_DRAW_TRANSPARENT:
red_put_transparent(&red->u.transparent);
red_put_transparent(&u.transparent);
break;
case QXL_DRAW_WHITENESS:
red_put_whiteness(&red->u.whiteness);
red_put_whiteness(&u.whiteness);
break;
}
if (red->qxl != nullptr) {
red_qxl_release_resource(red->qxl, red->release_info_ext);
if (qxl != nullptr) {
red_qxl_release_resource(qxl, release_info_ext);
}
}
RedDrawable *red_drawable_new(QXLInstance *qxl, RedMemSlotInfo *slots,
int group_id, QXLPHYSICAL addr,
uint32_t flags)
red::shared_ptr<RedDrawable>
red_drawable_new(QXLInstance *qxl, RedMemSlotInfo *slots,
int group_id, QXLPHYSICAL addr, uint32_t flags)
{
auto red = g_new0(RedDrawable, 1);
auto red = red::make_shared<RedDrawable>();
red->refs = 1;
if (!red_get_drawable(qxl, slots, group_id, red, addr, flags)) {
red_drawable_unref(red);
return nullptr;
if (!red_get_drawable(qxl, slots, group_id, red.get(), addr, flags)) {
red.reset();
}
return red;
}
RedDrawable *red_drawable_ref(RedDrawable *drawable)
{
drawable->refs++;
return drawable;
}
void red_drawable_unref(RedDrawable *red_drawable)
{
if (--red_drawable->refs) {
return;
}
red_put_drawable(red_drawable);
g_free(red_drawable);
}
static bool red_get_update_cmd(QXLInstance *qxl_instance, RedMemSlotInfo *slots, int group_id,
RedUpdateCmd *red, QXLPHYSICAL addr)
{

View File

@ -27,8 +27,8 @@
#include "push-visibility.h"
typedef struct RedDrawable {
int refs;
struct RedDrawable final: public red::simple_ptr_counted<RedDrawable> {
~RedDrawable();
QXLInstance *qxl;
QXLReleaseInfoExt release_info_ext;
uint32_t surface_id;
@ -60,7 +60,7 @@ typedef struct RedDrawable {
SpiceWhiteness whiteness;
SpiceComposite composite;
} u;
} RedDrawable;
};
struct RedUpdateCmd final: public red::simple_ptr_counted<RedUpdateCmd> {
~RedUpdateCmd();
@ -120,11 +120,9 @@ struct RedCursorCmd final: public red::simple_ptr_counted<RedCursorCmd> {
void red_get_rect_ptr(SpiceRect *red, const QXLRect *qxl);
RedDrawable *red_drawable_new(QXLInstance *qxl, RedMemSlotInfo *slots,
int group_id, QXLPHYSICAL addr,
uint32_t flags);
RedDrawable *red_drawable_ref(RedDrawable *drawable);
void red_drawable_unref(RedDrawable *red_drawable);
red::shared_ptr<RedDrawable>
red_drawable_new(QXLInstance *qxl, RedMemSlotInfo *slots,
int group_id, QXLPHYSICAL addr, uint32_t flags);
red::shared_ptr<const RedUpdateCmd>
red_update_cmd_new(QXLInstance *qxl, RedMemSlotInfo *slots,

View File

@ -191,15 +191,13 @@ static int red_process_display(RedWorker *worker, int *ring_is_empty)
worker->display_poll_tries = 0;
switch (ext_cmd.cmd.type) {
case QXL_CMD_DRAW: {
RedDrawable *red_drawable;
red_drawable = red_drawable_new(worker->qxl, &worker->mem_slots,
ext_cmd.group_id, ext_cmd.cmd.data,
ext_cmd.flags); // returns with 1 ref
auto red_drawable = red_drawable_new(worker->qxl, &worker->mem_slots,
ext_cmd.group_id, ext_cmd.cmd.data,
ext_cmd.flags); // returns with 1 ref
if (red_drawable != nullptr) {
display_channel_process_draw(worker->display_channel, red_drawable,
if (red_drawable) {
display_channel_process_draw(worker->display_channel, std::move(red_drawable),
worker->process_display_generation);
red_drawable_unref(red_drawable);
}
break;
}

View File

@ -136,7 +136,7 @@ static void dump_item(TreeItem *item, void *data)
printf(" ");
}
printf(item_prefix, 0);
show_red_drawable(drawable->red_drawable, nullptr);
show_red_drawable(drawable->red_drawable.get(), nullptr);
for (i = 0; i < di->level; i++) {
printf(" ");
}

View File

@ -224,7 +224,7 @@ static bool is_next_stream_frame(const Drawable *candidate,
return FALSE;
}
red_drawable = candidate->red_drawable;
red_drawable = candidate->red_drawable.get();
if (!container_candidate_allowed) {
SpiceRect* candidate_src;
@ -692,13 +692,13 @@ static void update_client_playback_delay(void *opaque, uint32_t delay_ms)
static void bitmap_ref(gpointer data)
{
auto red_drawable = (RedDrawable*)data;
red_drawable_ref(red_drawable);
shared_ptr_add_ref(red_drawable);
}
static void bitmap_unref(gpointer data)
{
auto red_drawable = (RedDrawable*)data;
red_drawable_unref(red_drawable);
shared_ptr_unref(red_drawable);
}
/* A helper for dcc_create_stream(). */