Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Commit

Permalink
add destroy listener for textures
Browse files Browse the repository at this point in the history
Add a destroy listener for textures, which destroys the textures of a
renderer upon renderer destruction.

Fixes #1949
  • Loading branch information
Emantor committed Dec 29, 2019
1 parent 18775fd commit 197e5b5
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 27 deletions.
2 changes: 2 additions & 0 deletions include/render/gles2.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const enum wl_shm_format *get_gles2_wl_formats(size_t *len);

struct wlr_gles2_texture *gles2_get_texture(
struct wlr_texture *wlr_texture);
struct wlr_gles2_renderer *gles2_get_renderer(
struct wlr_renderer *wlr_renderer);

void push_gles2_marker(const char *file, const char *func);
void pop_gles2_marker(void);
Expand Down
6 changes: 3 additions & 3 deletions include/wlr/render/gles2.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl);

struct wlr_egl *wlr_gles2_renderer_get_egl(struct wlr_renderer *renderer);

struct wlr_texture *wlr_gles2_texture_from_pixels(struct wlr_egl *egl,
struct wlr_texture *wlr_gles2_texture_from_pixels(struct wlr_renderer *renderer,
enum wl_shm_format wl_fmt, uint32_t stride, uint32_t width, uint32_t height,
const void *data);
struct wlr_texture *wlr_gles2_texture_from_wl_drm(struct wlr_egl *egl,
struct wlr_texture *wlr_gles2_texture_from_wl_drm(struct wlr_renderer *renderer,
struct wl_resource *data);
struct wlr_texture *wlr_gles2_texture_from_dmabuf(struct wlr_egl *egl,
struct wlr_texture *wlr_gles2_texture_from_dmabuf(struct wlr_renderer *renderer,
struct wlr_dmabuf_attributes *attribs);

struct wlr_gles2_texture_attribs {
Expand Down
2 changes: 1 addition & 1 deletion include/wlr/render/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,6 @@ struct wlr_texture_impl {
};

void wlr_texture_init(struct wlr_texture *texture,
const struct wlr_texture_impl *impl);
struct wlr_renderer *renderer, const struct wlr_texture_impl *impl);

#endif
2 changes: 2 additions & 0 deletions include/wlr/render/wlr_texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ struct wlr_texture_impl;

struct wlr_texture {
const struct wlr_texture_impl *impl;

struct wl_listener renderer_destroy;
};

/**
Expand Down
11 changes: 4 additions & 7 deletions render/gles2/renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct wlr_gles2_procs gles2_procs = {0};

static const struct wlr_renderer_impl renderer_impl;

static struct wlr_gles2_renderer *gles2_get_renderer(
struct wlr_gles2_renderer *gles2_get_renderer(
struct wlr_renderer *wlr_renderer) {
assert(wlr_renderer->impl == &renderer_impl);
return (struct wlr_gles2_renderer *)wlr_renderer;
Expand Down Expand Up @@ -331,22 +331,19 @@ static bool gles2_read_pixels(struct wlr_renderer *wlr_renderer,
static struct wlr_texture *gles2_texture_from_pixels(
struct wlr_renderer *wlr_renderer, enum wl_shm_format wl_fmt,
uint32_t stride, uint32_t width, uint32_t height, const void *data) {
struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer);
return wlr_gles2_texture_from_pixels(renderer->egl, wl_fmt, stride, width,
return wlr_gles2_texture_from_pixels(wlr_renderer, wl_fmt, stride, width,
height, data);
}

static struct wlr_texture *gles2_texture_from_wl_drm(
struct wlr_renderer *wlr_renderer, struct wl_resource *data) {
struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer);
return wlr_gles2_texture_from_wl_drm(renderer->egl, data);
return wlr_gles2_texture_from_wl_drm(wlr_renderer, data);
}

static struct wlr_texture *gles2_texture_from_dmabuf(
struct wlr_renderer *wlr_renderer,
struct wlr_dmabuf_attributes *attribs) {
struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer);
return wlr_gles2_texture_from_dmabuf(renderer->egl, attribs);
return wlr_gles2_texture_from_dmabuf(wlr_renderer, attribs);
}

static void gles2_init_wl_display(struct wlr_renderer *wlr_renderer,
Expand Down
48 changes: 33 additions & 15 deletions render/gles2/texture.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ static void gles2_texture_destroy(struct wlr_texture *wlr_texture) {
return;
}

wl_list_remove(&wlr_texture->renderer_destroy.link);

struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture);

if (!wlr_egl_is_current(texture->egl)) {
Expand All @@ -140,9 +142,28 @@ static const struct wlr_texture_impl texture_impl = {
.destroy = gles2_texture_destroy,
};

struct wlr_texture *wlr_gles2_texture_from_pixels(struct wlr_egl *egl,
static struct wlr_gles2_texture *create_gles2_texture(
struct wlr_renderer *renderer){
struct wlr_gles2_texture *texture;

texture = calloc(1, sizeof(struct wlr_gles2_texture));
if (texture == NULL) {
wlr_log(WLR_ERROR, "Allocation failed");
return NULL;
}
wlr_texture_init(&texture->wlr_texture, renderer,
&texture_impl);

return texture;
}

struct wlr_texture *wlr_gles2_texture_from_pixels(struct wlr_renderer *renderer,
enum wl_shm_format wl_fmt, uint32_t stride, uint32_t width,
uint32_t height, const void *data) {

struct wlr_gles2_renderer *gles_renderer = gles2_get_renderer(renderer);
struct wlr_egl *egl = gles_renderer->egl;

if (!wlr_egl_is_current(egl)) {
wlr_egl_make_current(egl, EGL_NO_SURFACE, NULL);
}
Expand All @@ -153,13 +174,10 @@ struct wlr_texture *wlr_gles2_texture_from_pixels(struct wlr_egl *egl,
return NULL;
}

struct wlr_gles2_texture *texture =
calloc(1, sizeof(struct wlr_gles2_texture));
struct wlr_gles2_texture *texture = create_gles2_texture(renderer);
if (texture == NULL) {
wlr_log(WLR_ERROR, "Allocation failed");
return NULL;
}
wlr_texture_init(&texture->wlr_texture, &texture_impl);
texture->egl = egl;
texture->width = width;
texture->height = height;
Expand All @@ -181,8 +199,11 @@ struct wlr_texture *wlr_gles2_texture_from_pixels(struct wlr_egl *egl,
return &texture->wlr_texture;
}

struct wlr_texture *wlr_gles2_texture_from_wl_drm(struct wlr_egl *egl,
struct wlr_texture *wlr_gles2_texture_from_wl_drm(struct wlr_renderer *renderer,
struct wl_resource *data) {
struct wlr_gles2_renderer *gles_renderer = gles2_get_renderer(renderer);
struct wlr_egl *egl = gles_renderer->egl;

if (!wlr_egl_is_current(egl)) {
wlr_egl_make_current(egl, EGL_NO_SURFACE, NULL);
}
Expand All @@ -191,13 +212,10 @@ struct wlr_texture *wlr_gles2_texture_from_wl_drm(struct wlr_egl *egl,
return NULL;
}

struct wlr_gles2_texture *texture =
calloc(1, sizeof(struct wlr_gles2_texture));
struct wlr_gles2_texture *texture = create_gles2_texture(renderer);
if (texture == NULL) {
wlr_log(WLR_ERROR, "Allocation failed");
return NULL;
}
wlr_texture_init(&texture->wlr_texture, &texture_impl);
texture->egl = egl;

EGLint fmt;
Expand Down Expand Up @@ -236,8 +254,11 @@ struct wlr_texture *wlr_gles2_texture_from_wl_drm(struct wlr_egl *egl,
return &texture->wlr_texture;
}

struct wlr_texture *wlr_gles2_texture_from_dmabuf(struct wlr_egl *egl,
struct wlr_texture *wlr_gles2_texture_from_dmabuf(struct wlr_renderer *renderer,
struct wlr_dmabuf_attributes *attribs) {
struct wlr_gles2_renderer *gles_renderer = gles2_get_renderer(renderer);
struct wlr_egl *egl = gles_renderer->egl;

if (!wlr_egl_is_current(egl)) {
wlr_egl_make_current(egl, EGL_NO_SURFACE, NULL);
}
Expand All @@ -264,13 +285,10 @@ struct wlr_texture *wlr_gles2_texture_from_dmabuf(struct wlr_egl *egl,
break;
}

struct wlr_gles2_texture *texture =
calloc(1, sizeof(struct wlr_gles2_texture));
struct wlr_gles2_texture *texture = create_gles2_texture(renderer);
if (texture == NULL) {
wlr_log(WLR_ERROR, "Allocation failed");
return NULL;
}
wlr_texture_init(&texture->wlr_texture, &texture_impl);
texture->egl = egl;
texture->width = attribs->width;
texture->height = attribs->height;
Expand Down
14 changes: 13 additions & 1 deletion render/wlr_texture.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,24 @@
#include <stdlib.h>
#include <wlr/render/interface.h>
#include <wlr/render/wlr_texture.h>
#include <wlr/render/wlr_renderer.h>

static void wlr_texture_handle_renderer_destroy(struct wl_listener *listener,
void *data){
struct wlr_texture *wlr_texture;
wlr_texture = wl_container_of(listener, wlr_texture, renderer_destroy);
wlr_texture_destroy(wlr_texture);
}


void wlr_texture_init(struct wlr_texture *texture,
const struct wlr_texture_impl *impl) {
struct wlr_renderer *renderer, const struct wlr_texture_impl *impl) {
assert(impl->get_size);
assert(impl->write_pixels);
texture->impl = impl;

texture->renderer_destroy.notify = wlr_texture_handle_renderer_destroy;
wl_signal_add(&renderer->events.destroy, &texture->renderer_destroy);
}

void wlr_texture_destroy(struct wlr_texture *texture) {
Expand Down

0 comments on commit 197e5b5

Please sign in to comment.