2010-06-11 20:56:24 +04:00
|
|
|
/*
|
Change remaining GPLv2 headers to MIT
The files in question are copyright Benjamin Franzke (who agrees),
Intel Corporation, Red Hat and myself. On behalf of Red Hat,
Richard Fontana says:
"Therefore, to the extent that Red Hat, Inc. has any copyright
interest in the files you cited as of this date (compositor-drm.c,
compositor.c, compositor.h, screenshooter.c in
http://cgit.freedesktop.org/wayland/wayland-demos/tree/compositor),
Red Hat hereby elects to apply the CC0 1.0 Universal Public Domain
Dedication to such copyrighted material. See:
http://creativecommons.org/publicdomain/zero/1.0/legalcode .
Thanks,
Richard E. Fontana
Open Source Licensing and Patent Counsel
Red Hat, Inc."
2011-09-15 23:43:14 +04:00
|
|
|
* Copyright © 2008-2011 Kristian Høgsberg
|
2010-06-11 20:56:24 +04:00
|
|
|
*
|
2015-06-12 01:35:43 +03:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
2010-06-11 20:56:24 +04:00
|
|
|
*
|
2015-06-12 01:35:43 +03:00
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial
|
|
|
|
* portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
2010-06-11 20:56:24 +04:00
|
|
|
*/
|
|
|
|
|
2013-05-22 19:03:19 +04:00
|
|
|
#include "config.h"
|
|
|
|
|
2010-06-11 20:56:24 +04:00
|
|
|
#include <stdlib.h>
|
2012-05-24 20:29:46 +04:00
|
|
|
#include <stdio.h>
|
2012-03-12 09:05:25 +04:00
|
|
|
#include <string.h>
|
2012-03-24 02:42:04 +04:00
|
|
|
#include <linux/input.h>
|
2012-05-24 20:29:46 +04:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/uio.h>
|
2010-06-11 20:56:24 +04:00
|
|
|
|
|
|
|
#include "compositor.h"
|
2015-11-17 11:00:34 +03:00
|
|
|
#include "weston-screenshooter-server-protocol.h"
|
2015-06-16 01:37:10 +03:00
|
|
|
#include "shared/helpers.h"
|
2010-06-11 20:56:24 +04:00
|
|
|
|
2015-06-16 01:37:07 +03:00
|
|
|
#include "wcap/wcap-decode.h"
|
2012-05-26 01:55:20 +04:00
|
|
|
|
2011-04-18 18:33:25 +04:00
|
|
|
struct screenshooter {
|
Rename wayland-compositor to weston
This rename addresses a few problems around the split between core
Wayland and the wayland-demos repository.
1) Initially, we had one big repository with protocol code, sample
compositor and sample clients. We split that repository to make it
possible to implement the protocol without pulling in the sample/demo
code. At this point, the compositor is more than just a "demo" and
wayland-demos doesn't send the right message. The sample compositor
is a useful, self-contained project in it's own right, and we want to
move away from the "demos" label.
2) Another problem is that the wayland-demos compositor is often
called "the wayland compsitor", but it's really just one possible
compositor. Existing X11 compositors are expected to add Wayland
support and then gradually phase out/modularize the X11 support, for
example. Conversely, it's hard to talk about the wayland-demos
compositor specifically as opposed to, eg, the wayland protocol or a
wayland compositor in general.
We are also renaming the repo to weston, and the compositor
subdirectory to src/, to emphasize that the main "output" is the
compositor.
2012-01-03 19:29:47 +04:00
|
|
|
struct weston_compositor *ec;
|
2012-01-03 13:39:13 +04:00
|
|
|
struct wl_global *global;
|
2012-03-24 02:42:04 +04:00
|
|
|
struct wl_client *client;
|
2012-04-04 21:49:21 +04:00
|
|
|
struct weston_process process;
|
2012-04-12 17:55:26 +04:00
|
|
|
struct wl_listener destroy_listener;
|
2010-06-11 20:56:24 +04:00
|
|
|
};
|
|
|
|
|
2012-06-20 08:05:46 +04:00
|
|
|
struct screenshooter_frame_listener {
|
|
|
|
struct wl_listener listener;
|
2013-06-21 05:38:23 +04:00
|
|
|
struct weston_buffer *buffer;
|
2013-12-12 02:45:11 +04:00
|
|
|
weston_screenshooter_done_func_t done;
|
|
|
|
void *data;
|
2012-04-20 23:37:33 +04:00
|
|
|
};
|
|
|
|
|
2012-04-17 12:55:41 +04:00
|
|
|
static void
|
2012-04-20 23:37:34 +04:00
|
|
|
copy_bgra_yflip(uint8_t *dst, uint8_t *src, int height, int stride)
|
2012-04-17 12:55:41 +04:00
|
|
|
{
|
|
|
|
uint8_t *end;
|
|
|
|
|
2012-04-20 23:37:34 +04:00
|
|
|
end = dst + height * stride;
|
2012-04-17 12:55:41 +04:00
|
|
|
while (dst < end) {
|
2012-04-20 23:37:34 +04:00
|
|
|
memcpy(dst, src, stride);
|
|
|
|
dst += stride;
|
|
|
|
src -= stride;
|
2012-04-17 12:55:41 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-22 19:03:05 +04:00
|
|
|
static void
|
|
|
|
copy_bgra(uint8_t *dst, uint8_t *src, int height, int stride)
|
|
|
|
{
|
|
|
|
/* TODO: optimize this out */
|
|
|
|
memcpy(dst, src, height * stride);
|
|
|
|
}
|
|
|
|
|
2012-04-17 16:02:08 +04:00
|
|
|
static void
|
|
|
|
copy_row_swap_RB(void *vdst, void *vsrc, int bytes)
|
|
|
|
{
|
|
|
|
uint32_t *dst = vdst;
|
|
|
|
uint32_t *src = vsrc;
|
|
|
|
uint32_t *end = dst + bytes / 4;
|
|
|
|
|
|
|
|
while (dst < end) {
|
|
|
|
uint32_t v = *src++;
|
|
|
|
/* A R G B */
|
|
|
|
uint32_t tmp = v & 0xff00ff00;
|
|
|
|
tmp |= (v >> 16) & 0x000000ff;
|
|
|
|
tmp |= (v << 16) & 0x00ff0000;
|
|
|
|
*dst++ = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-04-20 23:37:34 +04:00
|
|
|
copy_rgba_yflip(uint8_t *dst, uint8_t *src, int height, int stride)
|
2012-04-17 16:02:08 +04:00
|
|
|
{
|
|
|
|
uint8_t *end;
|
|
|
|
|
2012-04-20 23:37:34 +04:00
|
|
|
end = dst + height * stride;
|
2012-04-17 16:02:08 +04:00
|
|
|
while (dst < end) {
|
2012-04-20 23:37:34 +04:00
|
|
|
copy_row_swap_RB(dst, src, stride);
|
|
|
|
dst += stride;
|
|
|
|
src -= stride;
|
2012-04-17 16:02:08 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-22 19:03:05 +04:00
|
|
|
static void
|
|
|
|
copy_rgba(uint8_t *dst, uint8_t *src, int height, int stride)
|
|
|
|
{
|
|
|
|
uint8_t *end;
|
|
|
|
|
|
|
|
end = dst + height * stride;
|
|
|
|
while (dst < end) {
|
|
|
|
copy_row_swap_RB(dst, src, stride);
|
|
|
|
dst += stride;
|
|
|
|
src += stride;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-20 23:37:33 +04:00
|
|
|
static void
|
2012-06-20 08:05:46 +04:00
|
|
|
screenshooter_frame_notify(struct wl_listener *listener, void *data)
|
2012-04-20 23:37:33 +04:00
|
|
|
{
|
2012-06-20 08:05:46 +04:00
|
|
|
struct screenshooter_frame_listener *l =
|
|
|
|
container_of(listener,
|
|
|
|
struct screenshooter_frame_listener, listener);
|
2012-06-20 08:13:18 +04:00
|
|
|
struct weston_output *output = data;
|
2013-05-22 19:03:05 +04:00
|
|
|
struct weston_compositor *compositor = output->compositor;
|
2012-04-20 23:37:34 +04:00
|
|
|
int32_t stride;
|
2012-06-20 08:05:46 +04:00
|
|
|
uint8_t *pixels, *d, *s;
|
2012-04-20 23:37:33 +04:00
|
|
|
|
2012-08-03 23:45:23 +04:00
|
|
|
output->disable_planes--;
|
2012-06-20 08:05:46 +04:00
|
|
|
wl_list_remove(&listener->link);
|
2013-05-22 19:03:05 +04:00
|
|
|
stride = l->buffer->width * (PIXMAN_FORMAT_BPP(compositor->read_format) / 8);
|
2012-06-20 08:05:46 +04:00
|
|
|
pixels = malloc(stride * l->buffer->height);
|
2012-04-20 23:37:33 +04:00
|
|
|
|
2012-06-20 08:05:46 +04:00
|
|
|
if (pixels == NULL) {
|
2013-12-12 02:45:11 +04:00
|
|
|
l->done(l->data, WESTON_SCREENSHOOTER_NO_MEMORY);
|
2012-06-20 08:05:46 +04:00
|
|
|
free(l);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-22 19:03:05 +04:00
|
|
|
compositor->renderer->read_pixels(output,
|
|
|
|
compositor->read_format, pixels,
|
2013-09-19 01:56:35 +04:00
|
|
|
0, 0, output->current_mode->width,
|
|
|
|
output->current_mode->height);
|
2012-06-20 08:05:46 +04:00
|
|
|
|
2013-06-21 05:38:23 +04:00
|
|
|
stride = wl_shm_buffer_get_stride(l->buffer->shm_buffer);
|
2012-06-20 08:05:46 +04:00
|
|
|
|
2013-06-21 05:38:23 +04:00
|
|
|
d = wl_shm_buffer_get_data(l->buffer->shm_buffer);
|
2012-06-20 08:05:46 +04:00
|
|
|
s = pixels + stride * (l->buffer->height - 1);
|
2012-04-20 23:37:33 +04:00
|
|
|
|
2013-11-13 19:44:06 +04:00
|
|
|
wl_shm_buffer_begin_access(l->buffer->shm_buffer);
|
|
|
|
|
2013-05-22 19:03:05 +04:00
|
|
|
switch (compositor->read_format) {
|
2012-11-13 22:10:22 +04:00
|
|
|
case PIXMAN_a8r8g8b8:
|
2013-01-06 13:12:41 +04:00
|
|
|
case PIXMAN_x8r8g8b8:
|
2013-05-22 19:03:05 +04:00
|
|
|
if (compositor->capabilities & WESTON_CAP_CAPTURE_YFLIP)
|
2013-09-19 01:56:35 +04:00
|
|
|
copy_bgra_yflip(d, s, output->current_mode->height, stride);
|
2013-05-22 19:03:05 +04:00
|
|
|
else
|
2013-09-19 01:56:35 +04:00
|
|
|
copy_bgra(d, pixels, output->current_mode->height, stride);
|
2012-04-20 23:37:33 +04:00
|
|
|
break;
|
2013-01-06 13:12:41 +04:00
|
|
|
case PIXMAN_x8b8g8r8:
|
2012-11-13 22:10:22 +04:00
|
|
|
case PIXMAN_a8b8g8r8:
|
2013-05-22 19:03:05 +04:00
|
|
|
if (compositor->capabilities & WESTON_CAP_CAPTURE_YFLIP)
|
2013-09-19 01:56:35 +04:00
|
|
|
copy_rgba_yflip(d, s, output->current_mode->height, stride);
|
2013-05-22 19:03:05 +04:00
|
|
|
else
|
2013-09-19 01:56:35 +04:00
|
|
|
copy_rgba(d, pixels, output->current_mode->height, stride);
|
2012-04-20 23:37:33 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-11-13 19:44:06 +04:00
|
|
|
wl_shm_buffer_end_access(l->buffer->shm_buffer);
|
|
|
|
|
2013-12-12 02:45:11 +04:00
|
|
|
l->done(l->data, WESTON_SCREENSHOOTER_SUCCESS);
|
2012-06-20 08:05:46 +04:00
|
|
|
free(pixels);
|
|
|
|
free(l);
|
2012-04-20 23:37:33 +04:00
|
|
|
}
|
|
|
|
|
2013-12-12 02:45:11 +04:00
|
|
|
WL_EXPORT int
|
|
|
|
weston_screenshooter_shoot(struct weston_output *output,
|
|
|
|
struct weston_buffer *buffer,
|
|
|
|
weston_screenshooter_done_func_t done, void *data)
|
2010-06-11 20:56:24 +04:00
|
|
|
{
|
2012-06-20 08:05:46 +04:00
|
|
|
struct screenshooter_frame_listener *l;
|
2010-06-11 20:56:24 +04:00
|
|
|
|
2013-12-12 02:45:11 +04:00
|
|
|
if (!wl_shm_buffer_get(buffer->resource)) {
|
|
|
|
done(data, WESTON_SCREENSHOOTER_BAD_BUFFER);
|
|
|
|
return -1;
|
2013-08-15 23:26:42 +04:00
|
|
|
}
|
2014-01-15 21:36:00 +04:00
|
|
|
|
2013-06-21 05:38:23 +04:00
|
|
|
buffer->shm_buffer = wl_shm_buffer_get(buffer->resource);
|
|
|
|
buffer->width = wl_shm_buffer_get_width(buffer->shm_buffer);
|
|
|
|
buffer->height = wl_shm_buffer_get_height(buffer->shm_buffer);
|
2010-06-11 20:56:24 +04:00
|
|
|
|
2013-09-19 01:56:35 +04:00
|
|
|
if (buffer->width < output->current_mode->width ||
|
2013-12-12 02:45:11 +04:00
|
|
|
buffer->height < output->current_mode->height) {
|
|
|
|
done(data, WESTON_SCREENSHOOTER_BAD_BUFFER);
|
|
|
|
return -1;
|
|
|
|
}
|
2010-06-11 20:56:24 +04:00
|
|
|
|
2012-06-20 08:05:46 +04:00
|
|
|
l = malloc(sizeof *l);
|
|
|
|
if (l == NULL) {
|
2013-12-12 02:45:11 +04:00
|
|
|
done(data, WESTON_SCREENSHOOTER_NO_MEMORY);
|
|
|
|
return -1;
|
2012-03-12 09:05:25 +04:00
|
|
|
}
|
|
|
|
|
2012-06-20 08:05:46 +04:00
|
|
|
l->buffer = buffer;
|
2013-12-12 02:45:11 +04:00
|
|
|
l->done = done;
|
|
|
|
l->data = data;
|
2012-06-20 08:05:46 +04:00
|
|
|
l->listener.notify = screenshooter_frame_notify;
|
|
|
|
wl_signal_add(&output->frame_signal, &l->listener);
|
2012-08-03 23:45:23 +04:00
|
|
|
output->disable_planes++;
|
2012-06-20 08:35:59 +04:00
|
|
|
weston_output_schedule_repaint(output);
|
2013-12-12 02:45:11 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
screenshooter_done(void *data, enum weston_screenshooter_outcome outcome)
|
|
|
|
{
|
|
|
|
struct wl_resource *resource = data;
|
|
|
|
|
|
|
|
switch (outcome) {
|
|
|
|
case WESTON_SCREENSHOOTER_SUCCESS:
|
2015-11-17 11:00:34 +03:00
|
|
|
weston_screenshooter_send_done(resource);
|
2013-12-12 02:45:11 +04:00
|
|
|
break;
|
|
|
|
case WESTON_SCREENSHOOTER_NO_MEMORY:
|
|
|
|
wl_resource_post_no_memory(resource);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
screenshooter_shoot(struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
struct wl_resource *output_resource,
|
|
|
|
struct wl_resource *buffer_resource)
|
|
|
|
{
|
|
|
|
struct weston_output *output =
|
|
|
|
wl_resource_get_user_data(output_resource);
|
|
|
|
struct weston_buffer *buffer =
|
|
|
|
weston_buffer_from_resource(buffer_resource);
|
|
|
|
|
|
|
|
if (buffer == NULL) {
|
|
|
|
wl_resource_post_no_memory(resource);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
weston_screenshooter_shoot(output, buffer, screenshooter_done, resource);
|
2010-06-11 20:56:24 +04:00
|
|
|
}
|
|
|
|
|
2015-11-17 11:00:34 +03:00
|
|
|
struct weston_screenshooter_interface screenshooter_implementation = {
|
2010-06-11 20:56:24 +04:00
|
|
|
screenshooter_shoot
|
|
|
|
};
|
|
|
|
|
2011-08-27 01:21:20 +04:00
|
|
|
static void
|
|
|
|
bind_shooter(struct wl_client *client,
|
|
|
|
void *data, uint32_t version, uint32_t id)
|
|
|
|
{
|
2012-03-24 02:42:04 +04:00
|
|
|
struct screenshooter *shooter = data;
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
2013-06-28 05:17:02 +04:00
|
|
|
resource = wl_resource_create(client,
|
2015-11-17 11:00:34 +03:00
|
|
|
&weston_screenshooter_interface, 1, id);
|
2012-03-24 02:42:04 +04:00
|
|
|
|
|
|
|
if (client != shooter->client) {
|
|
|
|
wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
|
|
|
|
"screenshooter failed: permission denied");
|
2014-08-08 00:43:14 +04:00
|
|
|
return;
|
2012-03-24 02:42:04 +04:00
|
|
|
}
|
2013-06-28 05:17:02 +04:00
|
|
|
|
|
|
|
wl_resource_set_implementation(resource, &screenshooter_implementation,
|
|
|
|
data, NULL);
|
2012-03-24 02:42:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
screenshooter_sigchld(struct weston_process *process, int status)
|
|
|
|
{
|
|
|
|
struct screenshooter *shooter =
|
2012-04-04 21:49:21 +04:00
|
|
|
container_of(process, struct screenshooter, process);
|
2012-03-24 02:42:04 +04:00
|
|
|
|
|
|
|
shooter->client = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-07-15 21:00:36 +03:00
|
|
|
screenshooter_binding(struct weston_keyboard *keyboard, uint32_t time,
|
|
|
|
uint32_t key, void *data)
|
2012-03-24 02:42:04 +04:00
|
|
|
{
|
|
|
|
struct screenshooter *shooter = data;
|
2014-08-21 20:32:38 +04:00
|
|
|
char *screenshooter_exe;
|
2014-09-05 15:45:09 +04:00
|
|
|
int ret;
|
2014-08-21 20:32:38 +04:00
|
|
|
|
2014-09-05 15:45:09 +04:00
|
|
|
ret = asprintf(&screenshooter_exe, "%s/%s",
|
|
|
|
weston_config_get_libexec_dir(),
|
|
|
|
"/weston-screenshooter");
|
|
|
|
if (ret < 0) {
|
|
|
|
weston_log("Could not construct screenshooter path.\n");
|
|
|
|
return;
|
|
|
|
}
|
2012-03-24 02:42:04 +04:00
|
|
|
|
|
|
|
if (!shooter->client)
|
|
|
|
shooter->client = weston_client_launch(shooter->ec,
|
2012-04-04 21:49:21 +04:00
|
|
|
&shooter->process,
|
2012-03-24 02:42:04 +04:00
|
|
|
screenshooter_exe, screenshooter_sigchld);
|
2014-08-21 20:32:38 +04:00
|
|
|
free(screenshooter_exe);
|
2011-08-27 01:21:20 +04:00
|
|
|
}
|
|
|
|
|
2012-05-24 20:29:46 +04:00
|
|
|
struct weston_recorder {
|
2012-08-03 23:45:23 +04:00
|
|
|
struct weston_output *output;
|
2012-05-24 20:29:46 +04:00
|
|
|
uint32_t *frame, *rect;
|
2013-05-22 19:03:05 +04:00
|
|
|
uint32_t *tmpbuf;
|
2012-05-24 20:29:46 +04:00
|
|
|
uint32_t total;
|
|
|
|
int fd;
|
|
|
|
struct wl_listener frame_listener;
|
2013-12-17 16:18:01 +04:00
|
|
|
int count, destroying;
|
2012-05-24 20:29:46 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static uint32_t *
|
|
|
|
output_run(uint32_t *p, uint32_t delta, int run)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
while (run > 0) {
|
|
|
|
if (run <= 0xe0) {
|
|
|
|
*p++ = delta | ((run - 1) << 24);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 24 - __builtin_clz(run);
|
|
|
|
*p++ = delta | ((i + 0xe0) << 24);
|
|
|
|
run -= 1 << (7 + i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2012-05-29 20:15:47 +04:00
|
|
|
static uint32_t
|
|
|
|
component_delta(uint32_t next, uint32_t prev)
|
|
|
|
{
|
|
|
|
unsigned char dr, dg, db;
|
|
|
|
|
|
|
|
dr = (next >> 16) - (prev >> 16);
|
|
|
|
dg = (next >> 8) - (prev >> 8);
|
|
|
|
db = (next >> 0) - (prev >> 0);
|
|
|
|
|
|
|
|
return (dr << 16) | (dg << 8) | (db << 0);
|
|
|
|
}
|
|
|
|
|
2013-12-17 16:18:01 +04:00
|
|
|
static void
|
|
|
|
weston_recorder_destroy(struct weston_recorder *recorder);
|
|
|
|
|
2012-05-24 20:29:46 +04:00
|
|
|
static void
|
|
|
|
weston_recorder_frame_notify(struct wl_listener *listener, void *data)
|
|
|
|
{
|
|
|
|
struct weston_recorder *recorder =
|
|
|
|
container_of(listener, struct weston_recorder, frame_listener);
|
2012-06-20 08:13:18 +04:00
|
|
|
struct weston_output *output = data;
|
2013-05-22 19:03:05 +04:00
|
|
|
struct weston_compositor *compositor = output->compositor;
|
2012-06-20 08:13:18 +04:00
|
|
|
uint32_t msecs = output->frame_time;
|
2012-05-24 20:29:46 +04:00
|
|
|
pixman_box32_t *r;
|
2013-12-18 21:51:39 +04:00
|
|
|
pixman_region32_t damage, transformed_damage;
|
2012-05-24 20:29:46 +04:00
|
|
|
int i, j, k, n, width, height, run, stride;
|
|
|
|
uint32_t delta, prev, *d, *s, *p, next;
|
|
|
|
struct {
|
|
|
|
uint32_t msecs;
|
|
|
|
uint32_t nrects;
|
|
|
|
} header;
|
|
|
|
struct iovec v[2];
|
2013-05-22 19:03:05 +04:00
|
|
|
int do_yflip;
|
|
|
|
int y_orig;
|
|
|
|
uint32_t *outbuf;
|
|
|
|
|
|
|
|
do_yflip = !!(compositor->capabilities & WESTON_CAP_CAPTURE_YFLIP);
|
|
|
|
if (do_yflip)
|
|
|
|
outbuf = recorder->rect;
|
|
|
|
else
|
|
|
|
outbuf = recorder->tmpbuf;
|
2012-05-24 20:29:46 +04:00
|
|
|
|
|
|
|
pixman_region32_init(&damage);
|
2013-12-18 21:51:39 +04:00
|
|
|
pixman_region32_init(&transformed_damage);
|
2012-11-16 19:23:52 +04:00
|
|
|
pixman_region32_intersect(&damage, &output->region,
|
|
|
|
&output->previous_damage);
|
2013-12-18 21:51:39 +04:00
|
|
|
pixman_region32_translate(&damage, -output->x, -output->y);
|
|
|
|
weston_transformed_region(output->width, output->height,
|
|
|
|
output->transform, output->current_scale,
|
|
|
|
&damage, &transformed_damage);
|
|
|
|
pixman_region32_fini(&damage);
|
2012-05-24 20:29:46 +04:00
|
|
|
|
2013-12-18 21:51:39 +04:00
|
|
|
r = pixman_region32_rectangles(&transformed_damage, &n);
|
|
|
|
if (n == 0) {
|
|
|
|
pixman_region32_fini(&transformed_damage);
|
2012-05-24 20:29:46 +04:00
|
|
|
return;
|
2013-12-18 21:51:39 +04:00
|
|
|
}
|
2012-11-15 05:28:30 +04:00
|
|
|
|
2012-05-24 20:29:46 +04:00
|
|
|
header.msecs = msecs;
|
|
|
|
header.nrects = n;
|
|
|
|
v[0].iov_base = &header;
|
|
|
|
v[0].iov_len = sizeof header;
|
|
|
|
v[1].iov_base = r;
|
|
|
|
v[1].iov_len = n * sizeof *r;
|
|
|
|
recorder->total += writev(recorder->fd, v, 2);
|
2013-09-19 01:56:35 +04:00
|
|
|
stride = output->current_mode->width;
|
2012-05-24 20:29:46 +04:00
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
width = r[i].x2 - r[i].x1;
|
|
|
|
height = r[i].y2 - r[i].y1;
|
2013-05-22 19:03:05 +04:00
|
|
|
|
|
|
|
if (do_yflip)
|
2013-09-19 01:56:35 +04:00
|
|
|
y_orig = output->current_mode->height - r[i].y2;
|
2013-05-22 19:03:05 +04:00
|
|
|
else
|
|
|
|
y_orig = r[i].y1;
|
|
|
|
|
|
|
|
compositor->renderer->read_pixels(output,
|
|
|
|
compositor->read_format, recorder->rect,
|
|
|
|
r[i].x1, y_orig, width, height);
|
2012-05-24 20:29:46 +04:00
|
|
|
|
2013-05-22 19:03:05 +04:00
|
|
|
p = outbuf;
|
2012-05-24 20:29:46 +04:00
|
|
|
run = prev = 0; /* quiet gcc */
|
|
|
|
for (j = 0; j < height; j++) {
|
2013-05-22 19:03:05 +04:00
|
|
|
if (do_yflip)
|
2015-07-07 13:06:05 +03:00
|
|
|
s = recorder->rect + width * j;
|
2013-05-22 19:03:05 +04:00
|
|
|
else
|
2015-07-07 13:06:05 +03:00
|
|
|
s = recorder->rect + width * (height - j - 1);
|
|
|
|
y_orig = r[i].y2 - j - 1;
|
2013-05-22 19:03:05 +04:00
|
|
|
d = recorder->frame + stride * y_orig + r[i].x1;
|
|
|
|
|
2012-05-24 20:29:46 +04:00
|
|
|
for (k = 0; k < width; k++) {
|
|
|
|
next = *s++;
|
2012-05-29 20:15:47 +04:00
|
|
|
delta = component_delta(next, *d);
|
2012-05-24 20:29:46 +04:00
|
|
|
*d++ = next;
|
|
|
|
if (run == 0 || delta == prev) {
|
|
|
|
run++;
|
|
|
|
} else {
|
|
|
|
p = output_run(p, prev, run);
|
|
|
|
run = 1;
|
|
|
|
}
|
2012-06-20 08:28:16 +04:00
|
|
|
prev = delta;
|
2012-05-24 20:29:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p = output_run(p, prev, run);
|
|
|
|
|
|
|
|
recorder->total += write(recorder->fd,
|
2013-05-22 19:03:05 +04:00
|
|
|
outbuf, (p - outbuf) * 4);
|
2012-05-24 20:29:46 +04:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
fprintf(stderr,
|
|
|
|
"%dx%d at %d,%d rle from %d to %d bytes (%f) total %dM\n",
|
|
|
|
width, height, r[i].x1, r[i].y1,
|
2013-05-22 19:03:05 +04:00
|
|
|
width * height * 4, (int) (p - outbuf) * 4,
|
|
|
|
(float) (p - outbuf) / (width * height),
|
2012-06-19 01:10:19 +04:00
|
|
|
recorder->total / 1024 / 1024);
|
2012-05-24 20:29:46 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-12-18 21:51:39 +04:00
|
|
|
pixman_region32_fini(&transformed_damage);
|
2013-05-22 19:03:12 +04:00
|
|
|
recorder->count++;
|
2013-12-17 16:18:01 +04:00
|
|
|
|
|
|
|
if (recorder->destroying)
|
|
|
|
weston_recorder_destroy(recorder);
|
2012-05-24 20:29:46 +04:00
|
|
|
}
|
|
|
|
|
2014-04-22 03:51:02 +04:00
|
|
|
static void
|
|
|
|
weston_recorder_free(struct weston_recorder *recorder)
|
|
|
|
{
|
|
|
|
if (recorder == NULL)
|
|
|
|
return;
|
2014-12-10 13:50:46 +03:00
|
|
|
|
2014-04-22 03:51:02 +04:00
|
|
|
free(recorder->tmpbuf);
|
2014-12-10 13:50:46 +03:00
|
|
|
free(recorder->rect);
|
2014-04-22 03:51:02 +04:00
|
|
|
free(recorder->frame);
|
|
|
|
free(recorder);
|
|
|
|
}
|
|
|
|
|
2012-05-24 20:29:46 +04:00
|
|
|
static void
|
|
|
|
weston_recorder_create(struct weston_output *output, const char *filename)
|
|
|
|
{
|
2013-05-22 19:03:05 +04:00
|
|
|
struct weston_compositor *compositor = output->compositor;
|
2012-05-24 20:29:46 +04:00
|
|
|
struct weston_recorder *recorder;
|
|
|
|
int stride, size;
|
2012-05-26 01:45:39 +04:00
|
|
|
struct { uint32_t magic, format, width, height; } header;
|
2013-05-22 19:03:05 +04:00
|
|
|
int do_yflip;
|
|
|
|
|
|
|
|
do_yflip = !!(compositor->capabilities & WESTON_CAP_CAPTURE_YFLIP);
|
2012-05-24 20:29:46 +04:00
|
|
|
|
2014-11-21 09:21:55 +03:00
|
|
|
recorder = zalloc(sizeof *recorder);
|
2014-01-15 21:36:00 +04:00
|
|
|
if (recorder == NULL) {
|
|
|
|
weston_log("%s: out of memory\n", __func__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-19 01:56:35 +04:00
|
|
|
stride = output->current_mode->width;
|
|
|
|
size = stride * 4 * output->current_mode->height;
|
2013-08-08 05:57:05 +04:00
|
|
|
recorder->frame = zalloc(size);
|
2012-05-24 20:29:46 +04:00
|
|
|
recorder->rect = malloc(size);
|
2012-08-03 23:45:23 +04:00
|
|
|
recorder->output = output;
|
2012-05-24 20:29:46 +04:00
|
|
|
|
2014-04-22 03:51:02 +04:00
|
|
|
if ((recorder->frame == NULL) || (recorder->rect == NULL)) {
|
|
|
|
weston_log("%s: out of memory\n", __func__);
|
2014-12-10 13:50:46 +03:00
|
|
|
goto err_recorder;
|
2014-04-22 03:51:02 +04:00
|
|
|
}
|
|
|
|
|
2014-12-10 13:50:46 +03:00
|
|
|
if (!do_yflip) {
|
2013-05-22 19:03:05 +04:00
|
|
|
recorder->tmpbuf = malloc(size);
|
2014-12-10 13:50:46 +03:00
|
|
|
if (recorder->tmpbuf == NULL) {
|
|
|
|
weston_log("%s: out of memory\n", __func__);
|
|
|
|
goto err_recorder;
|
|
|
|
}
|
|
|
|
}
|
2013-05-22 19:03:05 +04:00
|
|
|
|
2012-05-26 01:45:39 +04:00
|
|
|
header.magic = WCAP_HEADER_MAGIC;
|
|
|
|
|
2013-05-22 19:03:05 +04:00
|
|
|
switch (compositor->read_format) {
|
2013-05-29 14:01:32 +04:00
|
|
|
case PIXMAN_x8r8g8b8:
|
2012-11-13 22:10:22 +04:00
|
|
|
case PIXMAN_a8r8g8b8:
|
2012-05-26 01:45:39 +04:00
|
|
|
header.format = WCAP_FORMAT_XRGB8888;
|
|
|
|
break;
|
2012-11-13 22:10:22 +04:00
|
|
|
case PIXMAN_a8b8g8r8:
|
2012-05-26 01:45:39 +04:00
|
|
|
header.format = WCAP_FORMAT_XBGR8888;
|
|
|
|
break;
|
2012-11-13 22:10:22 +04:00
|
|
|
default:
|
|
|
|
weston_log("unknown recorder format\n");
|
2014-12-10 13:50:46 +03:00
|
|
|
goto err_recorder;
|
2012-05-26 01:45:39 +04:00
|
|
|
}
|
|
|
|
|
2012-12-05 22:47:04 +04:00
|
|
|
recorder->fd = open(filename,
|
|
|
|
O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
|
|
|
|
|
|
|
|
if (recorder->fd < 0) {
|
|
|
|
weston_log("problem opening output file %s: %m\n", filename);
|
2014-12-10 13:50:46 +03:00
|
|
|
goto err_recorder;
|
2012-12-05 22:47:04 +04:00
|
|
|
}
|
|
|
|
|
2013-09-19 01:56:35 +04:00
|
|
|
header.width = output->current_mode->width;
|
|
|
|
header.height = output->current_mode->height;
|
2012-05-24 20:29:46 +04:00
|
|
|
recorder->total += write(recorder->fd, &header, sizeof header);
|
|
|
|
|
|
|
|
recorder->frame_listener.notify = weston_recorder_frame_notify;
|
|
|
|
wl_signal_add(&output->frame_signal, &recorder->frame_listener);
|
2012-08-03 23:45:23 +04:00
|
|
|
output->disable_planes++;
|
2012-05-24 20:29:46 +04:00
|
|
|
weston_output_damage(output);
|
2014-12-10 13:50:46 +03:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
err_recorder:
|
|
|
|
weston_recorder_free(recorder);
|
|
|
|
return;
|
2012-05-24 20:29:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
weston_recorder_destroy(struct weston_recorder *recorder)
|
|
|
|
{
|
|
|
|
wl_list_remove(&recorder->frame_listener.link);
|
|
|
|
close(recorder->fd);
|
2012-08-03 23:45:23 +04:00
|
|
|
recorder->output->disable_planes--;
|
2014-04-22 03:51:02 +04:00
|
|
|
weston_recorder_free(recorder);
|
2012-05-24 20:29:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-07-15 21:00:36 +03:00
|
|
|
recorder_binding(struct weston_keyboard *keyboard, uint32_t time,
|
|
|
|
uint32_t key, void *data)
|
2012-05-24 20:29:46 +04:00
|
|
|
{
|
2015-07-15 21:00:36 +03:00
|
|
|
struct weston_compositor *ec = keyboard->seat->compositor;
|
2013-12-18 21:51:39 +04:00
|
|
|
struct weston_output *output;
|
2014-01-08 17:39:18 +04:00
|
|
|
struct wl_listener *listener = NULL;
|
2012-05-24 20:29:46 +04:00
|
|
|
struct weston_recorder *recorder;
|
|
|
|
static const char filename[] = "capture.wcap";
|
|
|
|
|
2015-06-03 23:53:29 +03:00
|
|
|
wl_list_for_each(output, &ec->output_list, link) {
|
2013-12-18 21:51:39 +04:00
|
|
|
listener = wl_signal_get(&output->frame_signal,
|
|
|
|
weston_recorder_frame_notify);
|
|
|
|
if (listener)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-05-24 20:29:46 +04:00
|
|
|
if (listener) {
|
|
|
|
recorder = container_of(listener, struct weston_recorder,
|
|
|
|
frame_listener);
|
|
|
|
|
2013-05-22 19:03:12 +04:00
|
|
|
weston_log(
|
2012-05-26 01:50:42 +04:00
|
|
|
"stopping recorder, total file size %dM, %d frames\n",
|
|
|
|
recorder->total / (1024 * 1024), recorder->count);
|
2012-05-24 20:29:46 +04:00
|
|
|
|
2013-12-17 16:18:01 +04:00
|
|
|
recorder->destroying = 1;
|
|
|
|
weston_output_schedule_repaint(recorder->output);
|
2012-05-24 20:29:46 +04:00
|
|
|
} else {
|
2015-07-15 21:00:36 +03:00
|
|
|
if (keyboard->focus && keyboard->focus->output)
|
|
|
|
output = keyboard->focus->output;
|
2013-12-18 21:51:39 +04:00
|
|
|
else
|
|
|
|
output = container_of(ec->output_list.next,
|
|
|
|
struct weston_output, link);
|
|
|
|
|
|
|
|
weston_log("starting recorder for output %s, file %s\n",
|
|
|
|
output->name, filename);
|
2012-05-24 20:29:46 +04:00
|
|
|
weston_recorder_create(output, filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-12 17:55:26 +04:00
|
|
|
static void
|
|
|
|
screenshooter_destroy(struct wl_listener *listener, void *data)
|
|
|
|
{
|
|
|
|
struct screenshooter *shooter =
|
|
|
|
container_of(listener, struct screenshooter, destroy_listener);
|
|
|
|
|
2013-07-09 03:03:57 +04:00
|
|
|
wl_global_destroy(shooter->global);
|
2012-04-12 17:55:26 +04:00
|
|
|
free(shooter);
|
|
|
|
}
|
|
|
|
|
2013-12-12 02:45:12 +04:00
|
|
|
WL_EXPORT void
|
Rename wayland-compositor to weston
This rename addresses a few problems around the split between core
Wayland and the wayland-demos repository.
1) Initially, we had one big repository with protocol code, sample
compositor and sample clients. We split that repository to make it
possible to implement the protocol without pulling in the sample/demo
code. At this point, the compositor is more than just a "demo" and
wayland-demos doesn't send the right message. The sample compositor
is a useful, self-contained project in it's own right, and we want to
move away from the "demos" label.
2) Another problem is that the wayland-demos compositor is often
called "the wayland compsitor", but it's really just one possible
compositor. Existing X11 compositors are expected to add Wayland
support and then gradually phase out/modularize the X11 support, for
example. Conversely, it's hard to talk about the wayland-demos
compositor specifically as opposed to, eg, the wayland protocol or a
wayland compositor in general.
We are also renaming the repo to weston, and the compositor
subdirectory to src/, to emphasize that the main "output" is the
compositor.
2012-01-03 19:29:47 +04:00
|
|
|
screenshooter_create(struct weston_compositor *ec)
|
2010-06-11 20:56:24 +04:00
|
|
|
{
|
2011-04-18 18:33:25 +04:00
|
|
|
struct screenshooter *shooter;
|
2010-06-11 20:56:24 +04:00
|
|
|
|
|
|
|
shooter = malloc(sizeof *shooter);
|
|
|
|
if (shooter == NULL)
|
2012-04-12 17:55:26 +04:00
|
|
|
return;
|
2010-06-11 20:56:24 +04:00
|
|
|
|
|
|
|
shooter->ec = ec;
|
2012-03-24 02:42:04 +04:00
|
|
|
shooter->client = NULL;
|
2010-06-11 20:56:24 +04:00
|
|
|
|
2013-07-09 03:03:57 +04:00
|
|
|
shooter->global = wl_global_create(ec->wl_display,
|
2015-11-17 11:00:34 +03:00
|
|
|
&weston_screenshooter_interface, 1,
|
2013-07-09 03:03:57 +04:00
|
|
|
shooter, bind_shooter);
|
2012-05-30 19:31:58 +04:00
|
|
|
weston_compositor_add_key_binding(ec, KEY_S, MODIFIER_SUPER,
|
|
|
|
screenshooter_binding, shooter);
|
|
|
|
weston_compositor_add_key_binding(ec, KEY_R, MODIFIER_SUPER,
|
|
|
|
recorder_binding, shooter);
|
2012-01-03 13:39:13 +04:00
|
|
|
|
2012-04-12 17:55:26 +04:00
|
|
|
shooter->destroy_listener.notify = screenshooter_destroy;
|
|
|
|
wl_signal_add(&ec->destroy_signal, &shooter->destroy_listener);
|
2012-01-03 13:39:13 +04:00
|
|
|
}
|