mirror of
https://gitlab.freedesktop.org/wayland/weston.git
synced 2025-12-24 13:40:13 +01:00
clients: screenshot: Use shared client-buffer utils
In preparation for dmabuf support. Signed-off-by: Robert Mader <robert.mader@collabora.com>
This commit is contained in:
parent
4d43e63ab5
commit
ccce6cfdda
2 changed files with 11 additions and 41 deletions
|
|
@ -491,6 +491,7 @@ if get_option('shell-desktop') or get_option('deprecated-shell-fullscreen') or g
|
||||||
weston_output_capture_protocol_c,
|
weston_output_capture_protocol_c,
|
||||||
include_directories: common_inc,
|
include_directories: common_inc,
|
||||||
dependencies: [
|
dependencies: [
|
||||||
|
dep_client_buffer,
|
||||||
dep_toytoolkit,
|
dep_toytoolkit,
|
||||||
dep_libweston_private, # for pixel-formats.h
|
dep_libweston_private, # for pixel-formats.h
|
||||||
dep_pixman,
|
dep_pixman,
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@
|
||||||
#include <wayland-client.h>
|
#include <wayland-client.h>
|
||||||
|
|
||||||
#include "pixel-formats.h"
|
#include "pixel-formats.h"
|
||||||
|
#include "shared/client-buffer-util.h"
|
||||||
#include "shared/file-util.h"
|
#include "shared/file-util.h"
|
||||||
#include "shared/os-compatibility.h"
|
#include "shared/os-compatibility.h"
|
||||||
#include "shared/xalloc.h"
|
#include "shared/xalloc.h"
|
||||||
|
|
@ -59,9 +60,7 @@ struct screenshooter_app {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct screenshooter_buffer {
|
struct screenshooter_buffer {
|
||||||
size_t len;
|
struct client_buffer *buf;
|
||||||
void *data;
|
|
||||||
struct wl_buffer *wl_buffer;
|
|
||||||
pixman_image_t *image;
|
pixman_image_t *image;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -93,10 +92,6 @@ screenshot_create_shm_buffer(struct screenshooter_app *app,
|
||||||
const struct pixel_format_info *fmt)
|
const struct pixel_format_info *fmt)
|
||||||
{
|
{
|
||||||
struct screenshooter_buffer *buffer;
|
struct screenshooter_buffer *buffer;
|
||||||
struct wl_shm_pool *pool;
|
|
||||||
int fd;
|
|
||||||
size_t bytes_pp;
|
|
||||||
size_t stride;
|
|
||||||
|
|
||||||
assert(width > 0);
|
assert(width > 0);
|
||||||
assert(height > 0);
|
assert(height > 0);
|
||||||
|
|
@ -105,40 +100,15 @@ screenshot_create_shm_buffer(struct screenshooter_app *app,
|
||||||
|
|
||||||
buffer = xzalloc(sizeof *buffer);
|
buffer = xzalloc(sizeof *buffer);
|
||||||
|
|
||||||
bytes_pp = fmt->bpp / 8;
|
buffer->buf = client_buffer_util_create_shm_buffer(app->shm,
|
||||||
stride = width * bytes_pp;
|
fmt,
|
||||||
buffer->len = stride * height;
|
width,
|
||||||
|
height);
|
||||||
assert(width == stride / bytes_pp);
|
|
||||||
assert(height == buffer->len / stride);
|
|
||||||
|
|
||||||
fd = os_create_anonymous_file(buffer->len);
|
|
||||||
if (fd < 0) {
|
|
||||||
fprintf(stderr, "creating a buffer file for %zd B failed: %s\n",
|
|
||||||
buffer->len, strerror(errno));
|
|
||||||
free(buffer);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer->data = mmap(NULL, buffer->len, PROT_READ | PROT_WRITE,
|
|
||||||
MAP_SHARED, fd, 0);
|
|
||||||
if (buffer->data == MAP_FAILED) {
|
|
||||||
fprintf(stderr, "mmap failed: %s\n", strerror(errno));
|
|
||||||
close(fd);
|
|
||||||
free(buffer);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
pool = wl_shm_create_pool(app->shm, fd, buffer->len);
|
|
||||||
close(fd);
|
|
||||||
buffer->wl_buffer =
|
|
||||||
wl_shm_pool_create_buffer(pool, 0, width, height, stride,
|
|
||||||
pixel_format_get_shm_format(fmt));
|
|
||||||
wl_shm_pool_destroy(pool);
|
|
||||||
|
|
||||||
buffer->image = pixman_image_create_bits(fmt->pixman_format,
|
buffer->image = pixman_image_create_bits(fmt->pixman_format,
|
||||||
width, height,
|
width, height,
|
||||||
buffer->data, stride);
|
buffer->buf->data,
|
||||||
|
buffer->buf->strides[0]);
|
||||||
abort_oom_if_null(buffer->image);
|
abort_oom_if_null(buffer->image);
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
|
|
@ -151,8 +121,7 @@ screenshooter_buffer_destroy(struct screenshooter_buffer *buffer)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pixman_image_unref(buffer->image);
|
pixman_image_unref(buffer->image);
|
||||||
munmap(buffer->data, buffer->len);
|
client_buffer_util_destroy_buffer(buffer->buf);
|
||||||
wl_buffer_destroy(buffer->wl_buffer);
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -305,7 +274,7 @@ screenshooter_output_capture(struct screenshooter_output *output)
|
||||||
abort_oom_if_null(output->buffer);
|
abort_oom_if_null(output->buffer);
|
||||||
|
|
||||||
weston_capture_source_v1_capture(output->source,
|
weston_capture_source_v1_capture(output->source,
|
||||||
output->buffer->wl_buffer);
|
output->buffer->buf->wl_buffer);
|
||||||
output->app->waitcount++;
|
output->app->waitcount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue