From 6e43d642b2d0db5a3bd711507133abdb4da2d47c Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 14 Apr 2021 19:36:17 +0200 Subject: [PATCH] render/gles2: add support for DATA_PTR buffers in texture_from_buffer --- render/gles2/texture.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/render/gles2/texture.c b/render/gles2/texture.c index 7d8ad106..d42cff18 100644 --- a/render/gles2/texture.c +++ b/render/gles2/texture.c @@ -13,6 +13,7 @@ #include #include "render/gles2.h" #include "render/pixel_format.h" +#include "types/wlr_buffer.h" #include "util/signal.h" static const struct wlr_texture_impl texture_impl; @@ -364,15 +365,9 @@ static void texture_handle_buffer_destroy(struct wl_listener *listener, gles2_texture_destroy(texture); } -struct wlr_texture *gles2_texture_from_buffer(struct wlr_renderer *wlr_renderer, - struct wlr_buffer *buffer) { - struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer); - - struct wlr_dmabuf_attributes dmabuf; - if (!wlr_buffer_get_dmabuf(buffer, &dmabuf)) { - return false; - } - +static struct wlr_texture *gles2_texture_from_dmabuf_buffer( + struct wlr_gles2_renderer *renderer, struct wlr_buffer *buffer, + struct wlr_dmabuf_attributes *dmabuf) { struct wlr_gles2_texture *texture; wl_list_for_each(texture, &renderer->textures, link) { if (texture->buffer == buffer) { @@ -386,7 +381,7 @@ struct wlr_texture *gles2_texture_from_buffer(struct wlr_renderer *wlr_renderer, } struct wlr_texture *wlr_texture = - gles2_texture_from_dmabuf(wlr_renderer, &dmabuf); + gles2_texture_from_dmabuf(&renderer->wlr_renderer, dmabuf); if (wlr_texture == NULL) { return false; } @@ -400,6 +395,26 @@ struct wlr_texture *gles2_texture_from_buffer(struct wlr_renderer *wlr_renderer, return &texture->wlr_texture; } +struct wlr_texture *gles2_texture_from_buffer(struct wlr_renderer *wlr_renderer, + struct wlr_buffer *buffer) { + struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer); + + void *data; + uint32_t format; + size_t stride; + struct wlr_dmabuf_attributes dmabuf; + if (wlr_buffer_get_dmabuf(buffer, &dmabuf)) { + return gles2_texture_from_dmabuf_buffer(renderer, buffer, &dmabuf); + } else if (buffer_begin_data_ptr_access(buffer, &data, &format, &stride)) { + struct wlr_texture *tex = gles2_texture_from_pixels(wlr_renderer, + format, stride, buffer->width, buffer->height, data); + buffer_end_data_ptr_access(buffer); + return tex; + } else { + return NULL; + } +} + void wlr_gles2_texture_get_attribs(struct wlr_texture *wlr_texture, struct wlr_gles2_texture_attribs *attribs) { struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture);