render/gles2: implement texture_from_buffer

Make it so wlr_gles2_texture is ref'counted (via wlr_buffer). This
is similar to wlr_gles2_buffer or wlr_drm_fb work.

When creating a wlr_texture from a wlr_buffer, first check if we
already have a texture for the buffer. If so, increase the
wlr_buffer ref'count and make sure any changes made by an external
process are made visible (by invalidating the texture).

When destroying a wlr_texture created from a wlr_buffer, decrease
the ref'count, but keep the wlr_texture around in case the caller
uses it again. When the wlr_buffer is destroyed, cleanup the
wlr_texture.
This commit is contained in:
Simon Ser 2021-04-12 11:58:31 +02:00
parent 9d55f712e3
commit f6ba26ff58
3 changed files with 91 additions and 3 deletions

View file

@ -103,6 +103,10 @@ struct wlr_gles2_texture {
// Only affects target == GL_TEXTURE_2D
uint32_t drm_format; // used to interpret upload data
// If imported from a wlr_buffer
struct wlr_buffer *buffer;
struct wl_listener buffer_destroy;
};
const struct wlr_gles2_pixel_format *get_gles2_format_from_drm(uint32_t fmt);
@ -122,6 +126,8 @@ struct wlr_texture *gles2_texture_from_wl_drm(struct wlr_renderer *wlr_renderer,
struct wl_resource *data);
struct wlr_texture *gles2_texture_from_dmabuf(struct wlr_renderer *wlr_renderer,
struct wlr_dmabuf_attributes *attribs);
struct wlr_texture *gles2_texture_from_buffer(struct wlr_renderer *wlr_renderer,
struct wlr_buffer *buffer);
void push_gles2_debug_(struct wlr_gles2_renderer *renderer,
const char *file, const char *func);