libweston: make weston_renderbuffer refcounted

Add weston_renderbuffer_ref/unref() functions and use them to
eventually destroy the weston_renderbuffer. Drop the explicit
renderbuffer_destroy vfunc from the pixman renderer interface.

Signed-off-by: Philipp Zabel <philipp.zabel@gmail.com>
This commit is contained in:
Philipp Zabel 2023-01-24 07:36:59 +01:00 committed by Philipp Zabel
parent 8642a8e8e4
commit 14533cdd25
10 changed files with 46 additions and 17 deletions

View File

@ -1232,7 +1232,7 @@ err:
if (output->dumb[i])
drm_fb_unref(output->dumb[i]);
if (output->renderbuffer[i])
pixman->renderbuffer_destroy(output->renderbuffer[i]);
weston_renderbuffer_unref(output->renderbuffer[i]);
output->dumb[i] = NULL;
output->renderbuffer[i] = NULL;
@ -1258,7 +1258,7 @@ drm_output_fini_pixman(struct drm_output *output)
}
for (i = 0; i < ARRAY_LENGTH(output->dumb); i++) {
renderer->pixman->renderbuffer_destroy(output->renderbuffer[i]);
weston_renderbuffer_unref(output->renderbuffer[i]);
drm_fb_unref(output->dumb[i]);
output->dumb[i] = NULL;
output->renderbuffer[i] = NULL;

View File

@ -192,7 +192,8 @@ headless_output_disable_pixman(struct headless_output *output)
{
struct weston_renderer *renderer = output->base.compositor->renderer;
renderer->pixman->renderbuffer_destroy(output->renderbuffer);
weston_renderbuffer_unref(output->renderbuffer);
output->renderbuffer = NULL;
renderer->pixman->output_destroy(&output->base);
}

View File

@ -423,7 +423,7 @@ rdp_output_set_mode(struct weston_output *base, struct weston_mode *mode)
pixman_image_composite32(PIXMAN_OP_SRC, old_image, 0, new_image,
0, 0, 0, 0, 0, 0, mode->width,
mode->height);
pixman->renderbuffer_destroy(rdpOutput->renderbuffer);
weston_renderbuffer_unref(rdpOutput->renderbuffer);
rdpOutput->renderbuffer = new_renderbuffer;
}
@ -522,7 +522,8 @@ rdp_output_disable(struct weston_output *base)
if (!output->base.enabled)
return 0;
renderer->pixman->renderbuffer_destroy(output->renderbuffer);
weston_renderbuffer_unref(output->renderbuffer);
output->renderbuffer = NULL;
renderer->pixman->output_destroy(&output->base);
wl_event_source_remove(output->finish_frame_timer);

View File

@ -449,11 +449,10 @@ static void
fb_side_data_destroy(void *userdata)
{
struct fb_side_data *fb_side_data = userdata;
struct weston_renderer *renderer = fb_side_data->renderer;
wl_list_remove(&fb_side_data->link);
pixman_region32_fini(&fb_side_data->damage);
renderer->pixman->renderbuffer_destroy(fb_side_data->renderbuffer);
weston_renderbuffer_unref(fb_side_data->renderbuffer);
free(fb_side_data);
}

View File

@ -257,12 +257,8 @@ static void
wayland_shm_buffer_destroy(struct wayland_shm_buffer *buffer)
{
cairo_surface_destroy(buffer->c_surface);
if (buffer->output) {
const struct pixman_renderer_interface *pixman;
pixman = buffer->output->base.compositor->renderer->pixman;
pixman->renderbuffer_destroy(buffer->renderbuffer);
}
if (buffer->output)
weston_renderbuffer_unref(buffer->renderbuffer);
wl_buffer_destroy(buffer->buffer);
munmap(buffer->data, buffer->size);

View File

@ -554,12 +554,11 @@ finish_frame_handler(void *data)
static void
x11_output_deinit_shm(struct x11_backend *b, struct x11_output *output)
{
const struct weston_renderer *renderer = b->compositor->renderer;
xcb_void_cookie_t cookie;
xcb_generic_error_t *err;
xcb_free_gc(b->conn, output->gc);
renderer->pixman->renderbuffer_destroy(output->renderbuffer);
weston_renderbuffer_unref(output->renderbuffer);
output->renderbuffer = NULL;
cookie = xcb_shm_detach_checked(b->conn, output->segment);
err = xcb_request_check(b->conn, cookie);

View File

@ -8899,6 +8899,25 @@ weston_output_disable_planes_decr(struct weston_output *output)
}
WL_EXPORT struct weston_renderbuffer *
weston_renderbuffer_ref(struct weston_renderbuffer *renderbuffer)
{
renderbuffer->refcount++;
return renderbuffer;
}
WL_EXPORT void
weston_renderbuffer_unref(struct weston_renderbuffer *renderbuffer)
{
assert(renderbuffer->refcount > 0);
if (--renderbuffer->refcount > 0)
return;
renderbuffer->destroy(renderbuffer);
}
/** Tell the renderer that the target framebuffer size has changed
*
* \param output The output that was resized.

View File

@ -48,8 +48,17 @@
struct weston_renderbuffer {
pixman_region32_t damage;
int refcount;
void (*destroy)(struct weston_renderbuffer *renderbuffer);
};
struct weston_renderbuffer *
weston_renderbuffer_ref(struct weston_renderbuffer *renderbuffer);
void
weston_renderbuffer_unref(struct weston_renderbuffer *renderbuffer);
struct weston_renderer_options {
};

View File

@ -1133,6 +1133,9 @@ pixman_renderer_output_destroy(struct weston_output *output)
free(po);
}
static void
pixman_renderer_renderbuffer_destroy(struct weston_renderbuffer *renderbuffer);
static struct weston_renderbuffer *
pixman_renderer_create_image_from_ptr(struct weston_output *output,
pixman_format_code_t format, int width,
@ -1153,6 +1156,8 @@ pixman_renderer_create_image_from_ptr(struct weston_output *output,
}
pixman_region32_init(&renderbuffer->base.damage);
renderbuffer->base.refcount = 1;
renderbuffer->base.destroy = pixman_renderer_renderbuffer_destroy;
wl_list_insert(&po->renderbuffer_list, &renderbuffer->link);
return &renderbuffer->base;
@ -1178,6 +1183,8 @@ pixman_renderer_create_image(struct weston_output *output,
}
pixman_region32_init(&renderbuffer->base.damage);
renderbuffer->base.refcount = 1;
renderbuffer->base.destroy = pixman_renderer_renderbuffer_destroy;
wl_list_insert(&po->renderbuffer_list, &renderbuffer->link);
return &renderbuffer->base;
@ -1200,6 +1207,5 @@ static struct pixman_renderer_interface pixman_renderer_interface = {
.output_destroy = pixman_renderer_output_destroy,
.create_image_from_ptr = pixman_renderer_create_image_from_ptr,
.create_image = pixman_renderer_create_image,
.renderbuffer_destroy = pixman_renderer_renderbuffer_destroy,
.renderbuffer_get_image = pixman_renderer_renderbuffer_get_image,
};

View File

@ -56,6 +56,5 @@ struct pixman_renderer_interface {
struct weston_renderbuffer *(*create_image)(struct weston_output *output,
pixman_format_code_t format,
int width, int height);
void (*renderbuffer_destroy)(struct weston_renderbuffer *renderbuffer);
pixman_image_t *(*renderbuffer_get_image)(struct weston_renderbuffer *renderbuffer);
};