Skip to content
This repository has been archived by the owner on Jul 20, 2024. It is now read-only.

Commit

Permalink
wlr_texture: Introduce wlr_texture_read_pixels_options helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
Nefsen402 committed Dec 1, 2023
1 parent 4c6caa7 commit e85e8bc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/wlr/render/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,10 @@ float wlr_render_texture_options_get_alpha(const struct wlr_render_texture_optio
void wlr_render_rect_options_get_box(const struct wlr_render_rect_options *options,
const struct wlr_buffer *buffer, struct wlr_box *box);

void wlr_texture_read_pixels_options_get_src_box(
const struct wlr_texture_read_pixels_options *options,
const struct wlr_texture *texture, struct wlr_box *box);
void *wlr_texture_read_pixel_options_get_data(
const struct wlr_texture_read_pixels_options *options);

#endif
26 changes: 26 additions & 0 deletions render/wlr_texture.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <string.h>
#include <wlr/render/interface.h>
#include <wlr/render/wlr_texture.h>
#include "render/pixel_format.h"
#include "types/wlr_buffer.h"

void wlr_texture_init(struct wlr_texture *texture, struct wlr_renderer *renderer,
Expand All @@ -26,6 +27,31 @@ void wlr_texture_destroy(struct wlr_texture *texture) {
}
}

void wlr_texture_read_pixels_options_get_src_box(
const struct wlr_texture_read_pixels_options *options,
const struct wlr_texture *texture, struct wlr_box *box) {
if (wlr_box_empty(&options->src_box)) {
*box = (struct wlr_box){
.x = 0,
.y = 0,
.width = texture->width,
.height = texture->height,
};
return;
}

*box = options->src_box;
}

void *wlr_texture_read_pixel_options_get_data(
const struct wlr_texture_read_pixels_options *options) {
const struct wlr_pixel_format_info *fmt = drm_get_pixel_format_info(options->format);

return (char *)options->data +
pixel_format_info_min_stride(fmt, options->dst_x) +
options->dst_y * options->stride;
}

bool wlr_texture_read_pixels(struct wlr_texture *texture,
const struct wlr_texture_read_pixels_options *options) {
if (!texture->impl->read_pixels) {
Expand Down

0 comments on commit e85e8bc

Please sign in to comment.