renderers: pull dmabuf initial setup out of attach

With attach only being called at render time, the dmabuf can be deleted
along with its private data before we attach for the first time.

Let's move the first-time logic into its own callback to call at
buffer setup time instead.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
This commit is contained in:
Derek Foreman 2024-06-13 10:03:11 -05:00
parent 2b6fe57e81
commit 83b37c0ac4
3 changed files with 28 additions and 15 deletions

View File

@ -2848,6 +2848,9 @@ weston_buffer_from_resource(struct weston_compositor *ec,
buffer->type = WESTON_BUFFER_RENDERER_OPAQUE;
}
if (ec->renderer->buffer_init)
ec->renderer->buffer_init(ec, buffer);
/* Don't accept any formats we can't reason about: the importer should
* make sure this never happens */
assert(buffer->pixel_format);

View File

@ -99,6 +99,9 @@ struct weston_renderer {
bool (*fill_buffer_info)(struct weston_compositor *ec,
struct weston_buffer *buffer);
void (*buffer_init)(struct weston_compositor *ec,
struct weston_buffer *buffer);
enum weston_renderer_type type;
const struct gl_renderer_interface *gl;
const struct pixman_renderer_interface *pixman;

View File

@ -3335,25 +3335,10 @@ gl_renderer_attach_dmabuf(struct weston_surface *surface,
struct gl_renderer *gr = get_renderer(surface->compositor);
struct gl_surface_state *gs = get_surface_state(surface);
struct gl_buffer_state *gb;
struct linux_dmabuf_buffer *dmabuf = buffer->dmabuf;
GLenum target;
int i;
/* Thanks to linux-dmabuf being totally independent of libweston,
* the first time a dmabuf is attached, the gl_buffer_state will
* only be set as userdata on the dmabuf, not on the weston_buffer.
* When this happens, steal it away into the weston_buffer. */
if (!buffer->renderer_private) {
gb = linux_dmabuf_buffer_get_user_data(dmabuf);
assert(gb);
linux_dmabuf_buffer_set_user_data(dmabuf, NULL, NULL);
buffer->renderer_private = gb;
gb->destroy_listener.notify = handle_buffer_destroy;
wl_signal_add(&buffer->destroy_signal, &gb->destroy_listener);
}
assert(buffer->renderer_private);
assert(linux_dmabuf_buffer_get_user_data(dmabuf) == NULL);
gb = buffer->renderer_private;
gs->buffer = gb;
@ -3520,6 +3505,27 @@ out:
weston_buffer_release_reference(&gs->buffer_release_ref, NULL);
}
static void
gl_renderer_buffer_init(struct weston_compositor *etc,
struct weston_buffer *buffer)
{
struct gl_buffer_state *gb;
if (buffer->type != WESTON_BUFFER_DMABUF)
return;
/* Thanks to linux-dmabuf being totally independent of libweston,
* the gl_buffer_state willonly be set as userdata on the dmabuf,
* not on the weston_buffer. Steal it away into the weston_buffer. */
assert(!buffer->renderer_private);
gb = linux_dmabuf_buffer_get_user_data(buffer->dmabuf);
assert(gb);
linux_dmabuf_buffer_set_user_data(buffer->dmabuf, NULL, NULL);
buffer->renderer_private = gb;
gb->destroy_listener.notify = handle_buffer_destroy;
wl_signal_add(&buffer->destroy_signal, &gb->destroy_listener);
}
static void
gl_renderer_attach(struct weston_paint_node *pnode)
{
@ -4177,6 +4183,7 @@ gl_renderer_display_create(struct weston_compositor *ec,
gr->base.destroy = gl_renderer_destroy;
gr->base.surface_copy_content = gl_renderer_surface_copy_content;
gr->base.fill_buffer_info = gl_renderer_fill_buffer_info;
gr->base.buffer_init = gl_renderer_buffer_init;
gr->base.type = WESTON_RENDERER_GL;
if (gl_renderer_setup_egl_display(gr, options->egl_native_display) < 0)