wlr_raster: Introduce wlr_raster_from_pixels

This commit is contained in:
Alexander Orzechowski 2022-06-23 19:28:05 -04:00
parent 31bc571e98
commit bc53c79048
2 changed files with 26 additions and 0 deletions

View file

@ -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); 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 #endif

View file

@ -2,6 +2,7 @@
#include <wlr/types/wlr_raster.h> #include <wlr/types/wlr_raster.h>
#include <wlr/types/wlr_buffer.h> #include <wlr/types/wlr_buffer.h>
#include <wlr/render/wlr_texture.h> #include <wlr/render/wlr_texture.h>
#include "types/wlr_buffer.h"
#include "util/signal.h" #include "util/signal.h"
struct wlr_raster *wlr_raster_create(struct wlr_buffer *buffer) { 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; texture->raster = NULL;
wl_list_remove(&texture->link); 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;
}