aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Zeni <simon@bl4ckb0ne.ca>2021-04-27 12:17:15 -0400
committerSimon Ser <contact@emersion.fr>2021-04-27 18:28:41 +0200
commit144b41a45cc0b7d7793e1e7e2e318548cd3f5531 (patch)
tree9eeb24a34a0281eecb3fe3492276d2fa81887ee7
parent30706b71fbdefa9e23c637dd1a5e85306817211c (diff)
pixman: implement read pixels
-rw-r--r--render/pixman/renderer.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/render/pixman/renderer.c b/render/pixman/renderer.c
index 16541e50..3aa32f15 100644
--- a/render/pixman/renderer.c
+++ b/render/pixman/renderer.c
@@ -380,6 +380,34 @@ static uint32_t pixman_preferred_read_format(
return get_drm_format_from_pixman(pixman_format);
}
+static bool pixman_read_pixels(struct wlr_renderer *wlr_renderer,
+ uint32_t drm_format, uint32_t *flags, uint32_t stride,
+ uint32_t width, uint32_t height, uint32_t src_x, uint32_t src_y,
+ uint32_t dst_x, uint32_t dst_y, void *data) {
+ struct wlr_pixman_renderer *renderer = get_renderer(wlr_renderer);
+ struct wlr_pixman_buffer *buffer = renderer->current_buffer;
+
+ pixman_format_code_t fmt = get_pixman_format_from_drm(drm_format);
+ if (fmt == 0) {
+ wlr_log(WLR_ERROR, "Cannot read pixels: unsupported pixel format");
+ return false;
+ }
+
+ const struct wlr_pixel_format_info *drm_fmt =
+ drm_get_pixel_format_info(drm_format);
+ assert(drm_fmt);
+
+ pixman_image_t *dst = pixman_image_create_bits_no_clear(fmt, width, height,
+ data, stride);
+
+ pixman_image_composite32(PIXMAN_OP_SRC, buffer->image, NULL, dst,
+ src_x, src_y, 0, 0, dst_x, dst_y, width, height);
+
+ pixman_image_unref(dst);
+
+ return true;
+}
+
static const struct wlr_renderer_impl renderer_impl = {
.begin = pixman_begin,
.clear = pixman_clear,
@@ -392,6 +420,7 @@ static const struct wlr_renderer_impl renderer_impl = {
.bind_buffer = pixman_bind_buffer,
.destroy = pixman_destroy,
.preferred_read_format = pixman_preferred_read_format,
+ .read_pixels = pixman_read_pixels,
};
struct wlr_renderer *wlr_pixman_renderer_create(void) {