From bc53c79048b48f8d84a9246bf98b5f3201eb2a71 Mon Sep 17 00:00:00 2001 From: Alexander Orzechowski Date: Thu, 23 Jun 2022 19:28:05 -0400 Subject: [PATCH] wlr_raster: Introduce wlr_raster_from_pixels --- include/wlr/types/wlr_raster.h | 6 ++++++ types/wlr_raster.c | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/wlr/types/wlr_raster.h b/include/wlr/types/wlr_raster.h index 1cc9cabc3..f10a09b3b 100644 --- a/include/wlr/types/wlr_raster.h +++ b/include/wlr/types/wlr_raster.h @@ -75,4 +75,10 @@ void wlr_raster_attach(struct wlr_raster *raster, struct wlr_texture *texture); */ void wlr_raster_detach(struct wlr_raster *raster, struct wlr_texture *texture); +/** + * Create a new raster from raw pixel data. `stride` is in bytes. + */ +struct wlr_raster *wlr_raster_from_pixels(uint32_t fmt, uint32_t stride, + uint32_t width, uint32_t height, const void *data); + #endif diff --git a/types/wlr_raster.c b/types/wlr_raster.c index 63ccf9bf4..3bc408ef2 100644 --- a/types/wlr_raster.c +++ b/types/wlr_raster.c @@ -2,6 +2,7 @@ #include #include #include +#include "types/wlr_buffer.h" #include "util/signal.h" struct wlr_raster *wlr_raster_create(struct wlr_buffer *buffer) { @@ -81,3 +82,22 @@ void wlr_raster_detach(struct wlr_raster *raster, struct wlr_texture *texture) { texture->raster = NULL; wl_list_remove(&texture->link); } + +struct wlr_raster *wlr_raster_from_pixels(uint32_t fmt, uint32_t stride, + uint32_t width, uint32_t height, const void *data) { + assert(data); + + struct wlr_readonly_data_buffer *buffer = + readonly_data_buffer_create(fmt, stride, width, height, data); + if (buffer == NULL) { + return NULL; + } + + struct wlr_raster *raster = wlr_raster_create(&buffer->base); + + // By this point, the renderer should have locked the buffer if it still + // needs to access it in the future. + readonly_data_buffer_drop(buffer); + + return raster; +}