2012-10-29 20:19:24 +04:00
|
|
|
/*
|
|
|
|
* Copyright © 2010-2011 Benjamin Franzke
|
|
|
|
* Copyright © 2012 Intel Corporation
|
2022-07-13 16:03:44 +03:00
|
|
|
* Copyright © 2013 Jason Ekstrand
|
|
|
|
* Copyright 2022 Collabora, Ltd.
|
2012-10-29 20:19: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:
|
2012-10-29 20:19: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.
|
2012-10-29 20:19:24 +04:00
|
|
|
*/
|
|
|
|
|
2013-05-22 19:03:19 +04:00
|
|
|
#include "config.h"
|
2012-10-29 20:19:24 +04:00
|
|
|
|
2016-09-30 15:11:07 +03:00
|
|
|
#include <assert.h>
|
2016-07-19 14:16:27 +03:00
|
|
|
#include <stdint.h>
|
2012-10-29 20:19:24 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/time.h>
|
2014-11-20 02:06:17 +03:00
|
|
|
#include <stdbool.h>
|
2012-10-29 20:19:24 +04:00
|
|
|
|
2019-03-28 17:28:47 +03:00
|
|
|
#include <libweston/libweston.h>
|
2019-03-29 17:39:12 +03:00
|
|
|
#include <libweston/backend-headless.h>
|
2016-04-16 06:28:32 +03:00
|
|
|
#include "shared/helpers.h"
|
2018-10-19 12:14:11 +03:00
|
|
|
#include "linux-explicit-synchronization.h"
|
2022-07-20 14:52:41 +03:00
|
|
|
#include "pixel-formats.h"
|
2014-11-20 02:06:17 +03:00
|
|
|
#include "pixman-renderer.h"
|
2019-09-20 14:23:12 +03:00
|
|
|
#include "renderer-gl/gl-renderer.h"
|
2022-12-08 18:15:21 +03:00
|
|
|
#include "gl-borders.h"
|
2021-02-04 18:39:45 +03:00
|
|
|
#include "shared/weston-drm-fourcc.h"
|
2019-10-20 17:40:07 +03:00
|
|
|
#include "shared/weston-egl-ext.h"
|
2022-07-13 16:03:44 +03:00
|
|
|
#include "shared/cairo-util.h"
|
2023-01-26 19:33:05 +03:00
|
|
|
#include "shared/xalloc.h"
|
2019-09-20 14:23:12 +03:00
|
|
|
#include "linux-dmabuf.h"
|
2023-01-12 01:01:15 +03:00
|
|
|
#include "output-capture.h"
|
2016-02-18 17:53:27 +03:00
|
|
|
#include "presentation-time-server-protocol.h"
|
2019-03-29 18:14:29 +03:00
|
|
|
#include <libweston/windowed-output-api.h>
|
2012-10-29 20:19:24 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
struct headless_backend {
|
|
|
|
struct weston_backend base;
|
|
|
|
struct weston_compositor *compositor;
|
2016-04-16 06:28:32 +03:00
|
|
|
|
2012-10-29 20:19:24 +04:00
|
|
|
struct weston_seat fake_seat;
|
2019-09-20 14:23:12 +03:00
|
|
|
|
2022-07-13 16:03:44 +03:00
|
|
|
bool decorate;
|
|
|
|
struct theme *theme;
|
2023-01-26 19:33:05 +03:00
|
|
|
|
|
|
|
const struct pixel_format_info **formats;
|
|
|
|
unsigned int formats_count;
|
2012-10-29 20:19:24 +04:00
|
|
|
};
|
|
|
|
|
2017-08-24 16:40:17 +03:00
|
|
|
struct headless_head {
|
|
|
|
struct weston_head base;
|
|
|
|
};
|
|
|
|
|
2012-10-29 20:19:24 +04:00
|
|
|
struct headless_output {
|
|
|
|
struct weston_output base;
|
2022-05-29 09:01:29 +03:00
|
|
|
struct headless_backend *backend;
|
2016-04-16 06:28:32 +03:00
|
|
|
|
2012-10-29 20:19:24 +04:00
|
|
|
struct weston_mode mode;
|
|
|
|
struct wl_event_source *finish_frame_timer;
|
2023-01-11 23:53:43 +03:00
|
|
|
struct weston_renderbuffer *renderbuffer;
|
2022-07-13 16:03:44 +03:00
|
|
|
|
|
|
|
struct frame *frame;
|
|
|
|
struct {
|
2022-12-05 17:54:39 +03:00
|
|
|
struct weston_gl_borders borders;
|
2022-07-13 16:03:44 +03:00
|
|
|
} gl;
|
2012-10-29 20:19:24 +04:00
|
|
|
};
|
|
|
|
|
2019-09-20 14:23:12 +03:00
|
|
|
static const uint32_t headless_formats[] = {
|
2022-07-20 14:52:41 +03:00
|
|
|
DRM_FORMAT_XRGB8888, /* default for pixman-renderer */
|
2019-09-20 14:23:12 +03:00
|
|
|
DRM_FORMAT_ARGB8888,
|
|
|
|
};
|
|
|
|
|
2021-03-11 13:31:14 +03:00
|
|
|
static void
|
2023-01-13 20:21:31 +03:00
|
|
|
headless_destroy(struct weston_backend *backend);
|
2021-03-11 13:31:14 +03:00
|
|
|
|
2017-08-24 16:40:17 +03:00
|
|
|
static inline struct headless_head *
|
|
|
|
to_headless_head(struct weston_head *base)
|
|
|
|
{
|
2021-03-11 15:26:45 +03:00
|
|
|
if (base->backend->destroy != headless_destroy)
|
2021-03-11 13:31:14 +03:00
|
|
|
return NULL;
|
2017-08-24 16:40:17 +03:00
|
|
|
return container_of(base, struct headless_head, base);
|
|
|
|
}
|
|
|
|
|
2021-03-11 13:31:14 +03:00
|
|
|
static void
|
|
|
|
headless_output_destroy(struct weston_output *base);
|
|
|
|
|
2016-08-01 20:17:55 +03:00
|
|
|
static inline struct headless_output *
|
|
|
|
to_headless_output(struct weston_output *base)
|
|
|
|
{
|
2021-03-11 13:31:14 +03:00
|
|
|
if (base->destroy != headless_output_destroy)
|
|
|
|
return NULL;
|
2016-08-01 20:17:55 +03:00
|
|
|
return container_of(base, struct headless_output, base);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct headless_backend *
|
2023-04-16 19:20:10 +03:00
|
|
|
to_headless_backend(struct weston_backend *base)
|
2016-08-01 20:17:55 +03:00
|
|
|
{
|
2023-04-16 19:20:10 +03:00
|
|
|
return container_of(base, struct headless_backend, base);
|
2016-08-01 20:17:55 +03:00
|
|
|
}
|
|
|
|
|
2019-06-30 16:51:10 +03:00
|
|
|
static int
|
2013-04-06 01:07:11 +04:00
|
|
|
headless_output_start_repaint_loop(struct weston_output *output)
|
2012-10-29 20:19:24 +04:00
|
|
|
{
|
2014-09-24 06:08:45 +04:00
|
|
|
struct timespec ts;
|
2012-10-29 20:19:24 +04:00
|
|
|
|
2015-03-18 13:17:26 +03:00
|
|
|
weston_compositor_read_presentation_clock(output->compositor, &ts);
|
2016-02-18 17:53:27 +03:00
|
|
|
weston_output_finish_frame(output, &ts, WP_PRESENTATION_FEEDBACK_INVALID);
|
2019-06-30 16:51:10 +03:00
|
|
|
|
|
|
|
return 0;
|
2013-04-06 01:07:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
finish_frame_handler(void *data)
|
|
|
|
{
|
compositor: set presentation.presented flags
Change weston_output_finish_frame() signature so that backends are
required to set the flags, that will be reported on the Presentation
'presented' event. This is meant for output-wide feedback flags. Flags
that vary per wl_surface are subject for the following patch.
All start_repaint_loop functions use the special private flag
PRESENTATION_FEEDBACK_INVALID to mark, that this call of
weston_output_finish_frame() cannot trigger the 'presented' event. If it
does, we now hit an assert, and should then investigate why a fake update
triggered Presentation feedback.
DRM:
Page flip is always vsync'd, and always gets the completion timestamp
from the kernel which should correspond well to hardware. Completion is
triggered by the kernel/hardware.
Vblank handler is only used with the broken planes path, therefore do
not report VSYNC, because we cannot guarantee all the planes updated at
the same time. We cannot set the INVALID, because it would abort the
compositor if the broken planes path was ever used. This is a hack that
will get fixed with nuclear pageflip support in the future.
fbdev:
No vsync, update done by copy, no completion event from hardware, and
completion time is totally fake.
headless:
No real output to update.
RDP:
Guessing that maybe no vsync, fake time, and copy make sense (pixels
sent over network). Also no event that the pixels have been shown?
RPI:
Presumably Dispmanx updates are vsync'd. We get a completion event from
the driver, but need to read the clock ourselves, so the completion time
is somewhat unreliable. Zero-copy flag not implemented though it would
be theoretically possible with EGL clients (zero-copy is a per-surface
flag anyway, so in this patch).
Wayland:
No information how the host compositor is doing updates, so make a safe
guess without assuming vsync or hardware completion event. While we do
get some timestamp from the host compositor, it is not the completion
time. Would need to hook to the Presentation extension of the host
compositor to get more accurate flags.
X11:
No idea about vsync, completion event, or copying. Also the timestamp is
a fake.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Tested-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Acked-by: Mario Kleiner <mario.kleiner.de@gmail.com>
2014-12-17 17:20:40 +03:00
|
|
|
struct headless_output *output = data;
|
|
|
|
struct timespec ts;
|
|
|
|
|
2015-03-18 13:17:26 +03:00
|
|
|
weston_compositor_read_presentation_clock(output->base.compositor, &ts);
|
compositor: set presentation.presented flags
Change weston_output_finish_frame() signature so that backends are
required to set the flags, that will be reported on the Presentation
'presented' event. This is meant for output-wide feedback flags. Flags
that vary per wl_surface are subject for the following patch.
All start_repaint_loop functions use the special private flag
PRESENTATION_FEEDBACK_INVALID to mark, that this call of
weston_output_finish_frame() cannot trigger the 'presented' event. If it
does, we now hit an assert, and should then investigate why a fake update
triggered Presentation feedback.
DRM:
Page flip is always vsync'd, and always gets the completion timestamp
from the kernel which should correspond well to hardware. Completion is
triggered by the kernel/hardware.
Vblank handler is only used with the broken planes path, therefore do
not report VSYNC, because we cannot guarantee all the planes updated at
the same time. We cannot set the INVALID, because it would abort the
compositor if the broken planes path was ever used. This is a hack that
will get fixed with nuclear pageflip support in the future.
fbdev:
No vsync, update done by copy, no completion event from hardware, and
completion time is totally fake.
headless:
No real output to update.
RDP:
Guessing that maybe no vsync, fake time, and copy make sense (pixels
sent over network). Also no event that the pixels have been shown?
RPI:
Presumably Dispmanx updates are vsync'd. We get a completion event from
the driver, but need to read the clock ourselves, so the completion time
is somewhat unreliable. Zero-copy flag not implemented though it would
be theoretically possible with EGL clients (zero-copy is a per-surface
flag anyway, so in this patch).
Wayland:
No information how the host compositor is doing updates, so make a safe
guess without assuming vsync or hardware completion event. While we do
get some timestamp from the host compositor, it is not the completion
time. Would need to hook to the Presentation extension of the host
compositor to get more accurate flags.
X11:
No idea about vsync, completion event, or copying. Also the timestamp is
a fake.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Tested-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Acked-by: Mario Kleiner <mario.kleiner.de@gmail.com>
2014-12-17 17:20:40 +03:00
|
|
|
weston_output_finish_frame(&output->base, &ts, 0);
|
2012-10-29 20:19:24 +04:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-12-05 17:54:39 +03:00
|
|
|
static void
|
|
|
|
headless_output_update_gl_border(struct headless_output *output)
|
|
|
|
{
|
|
|
|
if (!output->frame)
|
|
|
|
return;
|
|
|
|
if (!(frame_status(output->frame) & FRAME_STATUS_REPAINT))
|
|
|
|
return;
|
|
|
|
|
|
|
|
weston_gl_borders_update(&output->gl.borders, output->frame,
|
2022-12-14 18:29:29 +03:00
|
|
|
&output->base);
|
2022-12-05 17:54:39 +03:00
|
|
|
}
|
|
|
|
|
2013-10-22 19:11:26 +04:00
|
|
|
static int
|
2012-10-29 20:19:24 +04:00
|
|
|
headless_output_repaint(struct weston_output *output_base,
|
compositor: remove repaint_data from compositor
The repaint_data is entirely backend specific. Moreover, it is only used by the
drm backend, while other backends ignore the repaint data.
There will always be only one repaint active, thus, there is no need to pass the
repaint data from the outside.
The repaint_data breaks with the multi-backend series, which calls repaint begin
for all backends to get the repaint_data. The repaint_data of the last backend
will then be passed to all other backend. At the moment, this works, because the
drm backend is the only backend that implements the begin_repaint call.
Another option would be to track the repaint data per backend in the compositor,
but actually, it the backend needs to track state across the calls, it's its own
responsibility.
Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
2021-11-03 13:14:11 +03:00
|
|
|
pixman_region32_t *damage)
|
2012-10-29 20:19:24 +04:00
|
|
|
{
|
2016-08-01 20:17:55 +03:00
|
|
|
struct headless_output *output = to_headless_output(output_base);
|
2021-03-11 13:31:14 +03:00
|
|
|
struct weston_compositor *ec;
|
|
|
|
|
|
|
|
assert(output);
|
|
|
|
|
|
|
|
ec = output->base.compositor;
|
2012-10-29 20:19:24 +04:00
|
|
|
|
2022-07-13 16:03:44 +03:00
|
|
|
headless_output_update_gl_border(output);
|
|
|
|
|
2023-01-12 01:01:15 +03:00
|
|
|
ec->renderer->repaint_output(&output->base, damage,
|
|
|
|
output->renderbuffer);
|
2012-10-29 20:19:24 +04:00
|
|
|
|
2012-11-22 17:57:00 +04:00
|
|
|
pixman_region32_subtract(&ec->primary_plane.damage,
|
|
|
|
&ec->primary_plane.damage, damage);
|
|
|
|
|
2012-10-29 20:19:24 +04:00
|
|
|
wl_event_source_timer_update(output->finish_frame_timer, 16);
|
|
|
|
|
2013-10-22 19:11:26 +04:00
|
|
|
return 0;
|
2012-10-29 20:19:24 +04:00
|
|
|
}
|
|
|
|
|
2019-09-20 14:23:12 +03:00
|
|
|
static void
|
|
|
|
headless_output_disable_gl(struct headless_output *output)
|
|
|
|
{
|
2022-12-14 18:29:29 +03:00
|
|
|
struct weston_compositor *compositor = output->base.compositor;
|
|
|
|
const struct weston_renderer *renderer = compositor->renderer;
|
2019-09-20 14:23:12 +03:00
|
|
|
|
2022-12-14 18:29:29 +03:00
|
|
|
weston_gl_borders_fini(&output->gl.borders, &output->base);
|
2022-12-09 13:03:00 +03:00
|
|
|
|
2023-01-11 21:03:21 +03:00
|
|
|
weston_renderbuffer_unref(output->renderbuffer);
|
|
|
|
output->renderbuffer = NULL;
|
2022-12-14 18:29:29 +03:00
|
|
|
renderer->gl->output_destroy(&output->base);
|
2022-07-13 16:03:44 +03:00
|
|
|
|
|
|
|
if (output->frame) {
|
|
|
|
frame_destroy(output->frame);
|
|
|
|
output->frame = NULL;
|
|
|
|
}
|
2019-09-20 14:23:12 +03:00
|
|
|
}
|
|
|
|
|
2019-09-12 17:17:55 +03:00
|
|
|
static void
|
|
|
|
headless_output_disable_pixman(struct headless_output *output)
|
|
|
|
{
|
2023-01-11 23:28:52 +03:00
|
|
|
struct weston_renderer *renderer = output->base.compositor->renderer;
|
|
|
|
|
2023-01-24 09:36:59 +03:00
|
|
|
weston_renderbuffer_unref(output->renderbuffer);
|
|
|
|
output->renderbuffer = NULL;
|
2023-01-12 01:34:39 +03:00
|
|
|
renderer->pixman->output_destroy(&output->base);
|
2019-09-12 17:17:55 +03:00
|
|
|
}
|
|
|
|
|
2016-09-30 15:11:07 +03:00
|
|
|
static int
|
|
|
|
headless_output_disable(struct weston_output *base)
|
2012-10-29 20:19:24 +04:00
|
|
|
{
|
2016-09-30 15:11:07 +03:00
|
|
|
struct headless_output *output = to_headless_output(base);
|
2021-03-11 13:31:14 +03:00
|
|
|
struct headless_backend *b;
|
|
|
|
|
|
|
|
assert(output);
|
2016-09-30 15:11:07 +03:00
|
|
|
|
|
|
|
if (!output->base.enabled)
|
|
|
|
return 0;
|
2012-10-29 20:19:24 +04:00
|
|
|
|
2022-05-29 09:01:29 +03:00
|
|
|
b = output->backend;
|
2021-03-11 13:31:14 +03:00
|
|
|
|
2012-10-29 20:19:24 +04:00
|
|
|
wl_event_source_remove(output->finish_frame_timer);
|
2014-11-20 02:06:17 +03:00
|
|
|
|
2022-11-30 12:34:52 +03:00
|
|
|
switch (b->compositor->renderer->type) {
|
|
|
|
case WESTON_RENDERER_GL:
|
2019-09-20 14:23:12 +03:00
|
|
|
headless_output_disable_gl(output);
|
|
|
|
break;
|
2022-11-30 12:34:52 +03:00
|
|
|
case WESTON_RENDERER_PIXMAN:
|
2019-09-12 17:17:55 +03:00
|
|
|
headless_output_disable_pixman(output);
|
2019-09-12 17:21:12 +03:00
|
|
|
break;
|
2022-11-30 12:34:52 +03:00
|
|
|
case WESTON_RENDERER_NOOP:
|
2019-09-12 17:21:12 +03:00
|
|
|
break;
|
2022-12-29 23:08:27 +03:00
|
|
|
case WESTON_RENDERER_AUTO:
|
|
|
|
unreachable("cannot have auto renderer at runtime");
|
2019-09-12 17:21:12 +03:00
|
|
|
}
|
2014-11-20 02:06:17 +03:00
|
|
|
|
2016-09-30 15:11:07 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
headless_output_destroy(struct weston_output *base)
|
|
|
|
{
|
|
|
|
struct headless_output *output = to_headless_output(base);
|
|
|
|
|
2021-03-11 13:31:14 +03:00
|
|
|
assert(output);
|
|
|
|
|
2016-09-30 15:11:07 +03:00
|
|
|
headless_output_disable(&output->base);
|
2017-08-16 12:07:14 +03:00
|
|
|
weston_output_release(&output->base);
|
2014-11-20 02:06:17 +03:00
|
|
|
|
2022-07-13 16:03:44 +03:00
|
|
|
assert(!output->frame);
|
2012-10-29 20:19:24 +04:00
|
|
|
free(output);
|
|
|
|
}
|
|
|
|
|
2019-09-20 14:23:12 +03:00
|
|
|
static int
|
|
|
|
headless_output_enable_gl(struct headless_output *output)
|
|
|
|
{
|
2022-05-29 09:01:29 +03:00
|
|
|
struct headless_backend *b = output->backend;
|
2022-12-14 18:29:29 +03:00
|
|
|
const struct weston_renderer *renderer = b->compositor->renderer;
|
2022-07-26 17:22:04 +03:00
|
|
|
const struct weston_mode *mode = output->base.current_mode;
|
2023-01-11 21:03:21 +03:00
|
|
|
struct gl_renderer_fbo_options options = { 0 };
|
2020-03-06 16:04:18 +03:00
|
|
|
|
2022-07-13 16:03:44 +03:00
|
|
|
if (b->decorate) {
|
|
|
|
/*
|
|
|
|
* Start with a dummy exterior size and then resize, because
|
|
|
|
* there is no frame_create() with interior size.
|
|
|
|
*/
|
|
|
|
output->frame = frame_create(b->theme, 100, 100,
|
|
|
|
FRAME_BUTTON_CLOSE, NULL, NULL);
|
|
|
|
if (!output->frame) {
|
|
|
|
weston_log("failed to create frame for output\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
frame_resize_inside(output->frame, mode->width, mode->height);
|
|
|
|
|
|
|
|
options.fb_size.width = frame_width(output->frame);
|
|
|
|
options.fb_size.height = frame_height(output->frame);
|
|
|
|
frame_interior(output->frame, &options.area.x, &options.area.y,
|
|
|
|
&options.area.width, &options.area.height);
|
|
|
|
} else {
|
|
|
|
options.area.x = 0;
|
|
|
|
options.area.y = 0;
|
|
|
|
options.area.width = mode->width;
|
|
|
|
options.area.height = mode->height;
|
|
|
|
options.fb_size.width = mode->width;
|
|
|
|
options.fb_size.height = mode->height;
|
|
|
|
}
|
|
|
|
|
2023-01-11 21:03:21 +03:00
|
|
|
if (renderer->gl->output_fbo_create(&output->base, &options) < 0) {
|
2019-09-20 14:23:12 +03:00
|
|
|
weston_log("failed to create gl renderer output state\n");
|
2022-07-13 16:03:44 +03:00
|
|
|
if (output->frame) {
|
|
|
|
frame_destroy(output->frame);
|
|
|
|
output->frame = NULL;
|
|
|
|
}
|
2019-09-20 14:23:12 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2023-01-11 21:03:21 +03:00
|
|
|
output->renderbuffer =
|
|
|
|
renderer->gl->create_fbo(&output->base, b->formats[0],
|
|
|
|
options.fb_size.width,
|
2023-06-06 15:58:57 +03:00
|
|
|
options.fb_size.height, NULL);
|
2023-01-11 21:03:21 +03:00
|
|
|
if (!output->renderbuffer)
|
|
|
|
goto err_renderbuffer;
|
|
|
|
|
2019-09-20 14:23:12 +03:00
|
|
|
return 0;
|
2023-01-11 21:03:21 +03:00
|
|
|
|
|
|
|
err_renderbuffer:
|
|
|
|
renderer->gl->output_destroy(&output->base);
|
|
|
|
|
|
|
|
return -1;
|
2019-09-20 14:23:12 +03:00
|
|
|
}
|
|
|
|
|
2019-09-12 17:13:20 +03:00
|
|
|
static int
|
|
|
|
headless_output_enable_pixman(struct headless_output *output)
|
|
|
|
{
|
2023-01-11 23:28:52 +03:00
|
|
|
const struct pixman_renderer_interface *pixman;
|
2020-03-06 15:46:30 +03:00
|
|
|
const struct pixman_renderer_output_options options = {
|
|
|
|
.use_shadow = true,
|
2022-07-22 14:47:03 +03:00
|
|
|
.fb_size = {
|
|
|
|
.width = output->base.current_mode->width,
|
|
|
|
.height = output->base.current_mode->height
|
|
|
|
},
|
2023-01-26 14:30:23 +03:00
|
|
|
.format = pixel_format_get_info(headless_formats[0])
|
2020-03-06 15:46:30 +03:00
|
|
|
};
|
|
|
|
|
2023-01-11 23:28:52 +03:00
|
|
|
pixman = output->base.compositor->renderer->pixman;
|
2022-07-20 14:52:41 +03:00
|
|
|
|
2023-01-12 01:34:39 +03:00
|
|
|
if (pixman->output_create(&output->base, &options) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2023-01-11 23:53:43 +03:00
|
|
|
output->renderbuffer =
|
2023-01-26 14:30:23 +03:00
|
|
|
pixman->create_image(&output->base, options.format,
|
2023-01-26 14:49:33 +03:00
|
|
|
output->base.current_mode->width,
|
|
|
|
output->base.current_mode->height);
|
2023-01-11 23:53:43 +03:00
|
|
|
if (!output->renderbuffer)
|
2019-09-12 17:13:20 +03:00
|
|
|
goto err_renderer;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_renderer:
|
2023-01-12 01:34:39 +03:00
|
|
|
pixman->output_destroy(&output->base);
|
2019-09-12 17:13:20 +03:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-10-29 20:19:24 +04:00
|
|
|
static int
|
2016-09-30 15:11:07 +03:00
|
|
|
headless_output_enable(struct weston_output *base)
|
2012-10-29 20:19:24 +04:00
|
|
|
{
|
2016-09-30 15:11:07 +03:00
|
|
|
struct headless_output *output = to_headless_output(base);
|
2021-03-11 13:31:14 +03:00
|
|
|
struct headless_backend *b;
|
2012-10-29 20:19:24 +04:00
|
|
|
struct wl_event_loop *loop;
|
2019-09-12 17:13:20 +03:00
|
|
|
int ret = 0;
|
2012-10-29 20:19:24 +04:00
|
|
|
|
2021-03-11 13:31:14 +03:00
|
|
|
assert(output);
|
|
|
|
|
2022-05-29 09:01:29 +03:00
|
|
|
b = output->backend;
|
2021-03-11 13:31:14 +03:00
|
|
|
|
2016-09-30 15:11:07 +03:00
|
|
|
loop = wl_display_get_event_loop(b->compositor->wl_display);
|
|
|
|
output->finish_frame_timer =
|
|
|
|
wl_event_loop_add_timer(loop, finish_frame_handler, output);
|
|
|
|
|
2020-11-06 13:02:13 +03:00
|
|
|
if (output->finish_frame_timer == NULL) {
|
|
|
|
weston_log("failed to add finish frame timer\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2022-11-30 12:34:52 +03:00
|
|
|
switch (b->compositor->renderer->type) {
|
|
|
|
case WESTON_RENDERER_GL:
|
2019-09-20 14:23:12 +03:00
|
|
|
ret = headless_output_enable_gl(output);
|
|
|
|
break;
|
2022-11-30 12:34:52 +03:00
|
|
|
case WESTON_RENDERER_PIXMAN:
|
2019-09-12 17:13:20 +03:00
|
|
|
ret = headless_output_enable_pixman(output);
|
2019-09-12 17:21:12 +03:00
|
|
|
break;
|
2022-11-30 12:34:52 +03:00
|
|
|
case WESTON_RENDERER_NOOP:
|
2019-09-12 17:21:12 +03:00
|
|
|
break;
|
2022-12-29 23:08:27 +03:00
|
|
|
case WESTON_RENDERER_AUTO:
|
|
|
|
unreachable("cannot have auto renderer at runtime");
|
2019-09-12 17:21:12 +03:00
|
|
|
}
|
2019-09-12 17:13:20 +03:00
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
wl_event_source_remove(output->finish_frame_timer);
|
|
|
|
return -1;
|
2016-09-30 15:11:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
headless_output_set_size(struct weston_output *base,
|
|
|
|
int width, int height)
|
|
|
|
{
|
|
|
|
struct headless_output *output = to_headless_output(base);
|
2017-08-24 16:40:17 +03:00
|
|
|
struct weston_head *head;
|
2016-09-30 15:11:07 +03:00
|
|
|
int output_width, output_height;
|
|
|
|
|
2021-03-11 13:31:14 +03:00
|
|
|
if (!output)
|
|
|
|
return -1;
|
|
|
|
|
2016-09-30 15:11:07 +03:00
|
|
|
/* We can only be called once. */
|
|
|
|
assert(!output->base.current_mode);
|
|
|
|
|
|
|
|
/* Make sure we have scale set. */
|
|
|
|
assert(output->base.scale);
|
|
|
|
|
2017-08-24 16:40:17 +03:00
|
|
|
wl_list_for_each(head, &output->base.head_list, output_link) {
|
|
|
|
weston_head_set_monitor_strings(head, "weston", "headless",
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
/* XXX: Calculate proper size. */
|
|
|
|
weston_head_set_physical_size(head, width, height);
|
|
|
|
}
|
|
|
|
|
2016-09-30 15:11:07 +03:00
|
|
|
output_width = width * output->base.scale;
|
|
|
|
output_height = height * output->base.scale;
|
2012-10-29 20:19:24 +04:00
|
|
|
|
|
|
|
output->mode.flags =
|
|
|
|
WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
|
2016-09-30 15:11:07 +03:00
|
|
|
output->mode.width = output_width;
|
|
|
|
output->mode.height = output_height;
|
2014-05-23 13:48:45 +04:00
|
|
|
output->mode.refresh = 60000;
|
2012-10-29 20:19:24 +04:00
|
|
|
wl_list_insert(&output->base.mode_list, &output->mode.link);
|
|
|
|
|
2013-09-19 01:56:35 +04:00
|
|
|
output->base.current_mode = &output->mode;
|
2017-03-24 16:39:24 +03:00
|
|
|
|
2013-04-06 01:07:11 +04:00
|
|
|
output->base.start_repaint_loop = headless_output_start_repaint_loop;
|
2012-10-29 20:19:24 +04:00
|
|
|
output->base.repaint = headless_output_repaint;
|
|
|
|
output->base.assign_planes = NULL;
|
|
|
|
output->base.set_backlight = NULL;
|
|
|
|
output->base.set_dpms = NULL;
|
|
|
|
output->base.switch_mode = NULL;
|
|
|
|
|
2016-09-30 15:11:07 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2014-11-20 02:06:17 +03:00
|
|
|
|
2017-08-24 16:40:17 +03:00
|
|
|
static struct weston_output *
|
2023-01-13 20:21:31 +03:00
|
|
|
headless_output_create(struct weston_backend *backend, const char *name)
|
2016-09-30 15:11:07 +03:00
|
|
|
{
|
2023-01-13 20:21:31 +03:00
|
|
|
struct headless_backend *b = container_of(backend, struct headless_backend, base);
|
|
|
|
struct weston_compositor *compositor = b->compositor;
|
2016-09-30 15:11:07 +03:00
|
|
|
struct headless_output *output;
|
2014-11-20 02:06:17 +03:00
|
|
|
|
2016-09-30 15:11:07 +03:00
|
|
|
/* name can't be NULL. */
|
|
|
|
assert(name);
|
2014-11-20 02:06:17 +03:00
|
|
|
|
2016-09-30 15:11:07 +03:00
|
|
|
output = zalloc(sizeof *output);
|
2017-08-24 16:40:17 +03:00
|
|
|
if (!output)
|
|
|
|
return NULL;
|
2016-09-30 15:11:07 +03:00
|
|
|
|
2017-04-03 13:18:13 +03:00
|
|
|
weston_output_init(&output->base, compositor, name);
|
|
|
|
|
2016-09-30 15:11:07 +03:00
|
|
|
output->base.destroy = headless_output_destroy;
|
|
|
|
output->base.disable = headless_output_disable;
|
|
|
|
output->base.enable = headless_output_enable;
|
2017-08-24 16:40:17 +03:00
|
|
|
output->base.attach_head = NULL;
|
2014-11-20 02:06:17 +03:00
|
|
|
|
2022-05-29 09:01:29 +03:00
|
|
|
output->backend = b;
|
|
|
|
|
2016-09-30 15:11:07 +03:00
|
|
|
weston_compositor_add_pending_output(&output->base, compositor);
|
2012-10-29 20:19:24 +04:00
|
|
|
|
2017-08-24 16:40:17 +03:00
|
|
|
return &output->base;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2023-04-16 19:20:10 +03:00
|
|
|
headless_head_create(struct weston_backend *base,
|
2017-08-24 16:40:17 +03:00
|
|
|
const char *name)
|
|
|
|
{
|
2023-04-16 19:20:10 +03:00
|
|
|
struct headless_backend *backend = to_headless_backend(base);
|
2017-08-24 16:40:17 +03:00
|
|
|
struct headless_head *head;
|
|
|
|
|
|
|
|
/* name can't be NULL. */
|
|
|
|
assert(name);
|
|
|
|
|
|
|
|
head = zalloc(sizeof *head);
|
|
|
|
if (head == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
weston_head_init(&head->base, name);
|
2021-03-11 13:31:14 +03:00
|
|
|
|
2021-03-11 15:26:45 +03:00
|
|
|
head->base.backend = &backend->base;
|
2021-03-11 13:31:14 +03:00
|
|
|
|
2017-08-24 16:40:17 +03:00
|
|
|
weston_head_set_connection_status(&head->base, true);
|
2022-03-16 15:27:55 +03:00
|
|
|
weston_head_set_supported_eotf_mask(&head->base,
|
|
|
|
WESTON_EOTF_MODE_ALL_MASK);
|
2017-08-24 16:40:17 +03:00
|
|
|
|
|
|
|
/* Ideally all attributes of the head would be set here, so that the
|
|
|
|
* user has all the information when deciding to create outputs.
|
|
|
|
* We do not have those until set_size() time through.
|
|
|
|
*/
|
|
|
|
|
2023-04-16 19:20:10 +03:00
|
|
|
weston_compositor_add_head(backend->compositor, &head->base);
|
2017-08-24 16:40:17 +03:00
|
|
|
|
2012-10-29 20:19:24 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-08-24 16:40:17 +03:00
|
|
|
static void
|
2021-03-11 13:31:14 +03:00
|
|
|
headless_head_destroy(struct weston_head *base)
|
2017-08-24 16:40:17 +03:00
|
|
|
{
|
2021-03-11 13:31:14 +03:00
|
|
|
struct headless_head *head = to_headless_head(base);
|
|
|
|
|
|
|
|
assert(head);
|
|
|
|
|
2017-08-24 16:40:17 +03:00
|
|
|
weston_head_release(&head->base);
|
|
|
|
free(head);
|
|
|
|
}
|
|
|
|
|
2012-10-29 20:19:24 +04:00
|
|
|
static void
|
2023-01-13 20:21:31 +03:00
|
|
|
headless_destroy(struct weston_backend *backend)
|
2012-10-29 20:19:24 +04:00
|
|
|
{
|
2023-01-13 20:21:31 +03:00
|
|
|
struct headless_backend *b = container_of(backend, struct headless_backend, base);
|
|
|
|
struct weston_compositor *ec = b->compositor;
|
2017-08-24 16:40:17 +03:00
|
|
|
struct weston_head *base, *next;
|
2012-10-29 20:19:24 +04:00
|
|
|
|
|
|
|
weston_compositor_shutdown(ec);
|
|
|
|
|
2021-03-11 13:31:14 +03:00
|
|
|
wl_list_for_each_safe(base, next, &ec->head_list, compositor_link) {
|
|
|
|
if (to_headless_head(base))
|
|
|
|
headless_head_destroy(base);
|
|
|
|
}
|
2017-08-24 16:40:17 +03:00
|
|
|
|
2022-07-13 16:03:44 +03:00
|
|
|
if (b->theme)
|
|
|
|
theme_destroy(b->theme);
|
|
|
|
|
2023-01-26 19:33:05 +03:00
|
|
|
free(b->formats);
|
2014-10-11 19:27:30 +04:00
|
|
|
free(b);
|
2023-04-12 13:55:07 +03:00
|
|
|
|
2023-05-29 22:19:56 +03:00
|
|
|
/* XXX: cleaning up after cairo/fontconfig here might seem suitable,
|
|
|
|
* but fontconfig will create additional threads which we can't wait
|
|
|
|
* for -- in order to realiably de-allocate all resources, as to get a
|
|
|
|
* report without any mem leaks. */
|
2012-10-29 20:19:24 +04:00
|
|
|
}
|
|
|
|
|
2016-09-30 15:11:07 +03:00
|
|
|
static const struct weston_windowed_output_api api = {
|
|
|
|
headless_output_set_size,
|
2017-08-24 16:40:17 +03:00
|
|
|
headless_head_create,
|
2016-09-30 15:11:07 +03:00
|
|
|
};
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
static struct headless_backend *
|
|
|
|
headless_backend_create(struct weston_compositor *compositor,
|
2016-04-16 06:28:32 +03:00
|
|
|
struct weston_headless_backend_config *config)
|
2012-10-29 20:19:24 +04:00
|
|
|
{
|
2014-10-11 19:27:30 +04:00
|
|
|
struct headless_backend *b;
|
2016-09-30 15:11:07 +03:00
|
|
|
int ret;
|
2012-10-29 20:19:24 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
b = zalloc(sizeof *b);
|
|
|
|
if (b == NULL)
|
2012-10-29 20:19:24 +04:00
|
|
|
return NULL;
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
b->compositor = compositor;
|
2017-08-30 11:29:49 +03:00
|
|
|
compositor->backend = &b->base;
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
if (weston_compositor_set_presentation_clock_software(compositor) < 0)
|
|
|
|
goto err_free;
|
2014-09-24 06:08:45 +04:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
b->base.destroy = headless_destroy;
|
2017-08-24 16:40:17 +03:00
|
|
|
b->base.create_output = headless_output_create;
|
2012-10-29 20:19:24 +04:00
|
|
|
|
2022-07-13 16:03:44 +03:00
|
|
|
b->decorate = config->decorate;
|
|
|
|
if (b->decorate) {
|
|
|
|
b->theme = theme_create();
|
|
|
|
if (!b->theme) {
|
|
|
|
weston_log("Error: could not load decorations theme.\n");
|
|
|
|
goto err_free;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-26 19:33:05 +03:00
|
|
|
b->formats_count = ARRAY_LENGTH(headless_formats);
|
|
|
|
b->formats = pixel_format_get_array(headless_formats, b->formats_count);
|
|
|
|
|
2022-12-29 21:20:26 +03:00
|
|
|
switch (config->renderer) {
|
2022-12-14 18:29:29 +03:00
|
|
|
case WESTON_RENDERER_GL: {
|
|
|
|
const struct gl_renderer_display_options options = {
|
|
|
|
.egl_platform = EGL_PLATFORM_SURFACELESS_MESA,
|
|
|
|
.egl_native_display = NULL,
|
2023-01-26 19:33:05 +03:00
|
|
|
.formats = b->formats,
|
|
|
|
.formats_count = b->formats_count,
|
2022-12-14 18:29:29 +03:00
|
|
|
};
|
|
|
|
ret = weston_compositor_init_renderer(compositor,
|
|
|
|
WESTON_RENDERER_GL,
|
|
|
|
&options.base);
|
2022-12-29 21:20:26 +03:00
|
|
|
break;
|
2022-12-14 18:29:29 +03:00
|
|
|
}
|
2022-12-29 21:20:26 +03:00
|
|
|
case WESTON_RENDERER_PIXMAN:
|
|
|
|
if (config->decorate) {
|
|
|
|
weston_log("Error: Pixman renderer does not support decorations.\n");
|
|
|
|
goto err_input;
|
|
|
|
}
|
2023-01-17 19:10:36 +03:00
|
|
|
ret = weston_compositor_init_renderer(compositor,
|
|
|
|
WESTON_RENDERER_PIXMAN,
|
|
|
|
NULL);
|
2022-12-29 21:20:26 +03:00
|
|
|
break;
|
|
|
|
case WESTON_RENDERER_AUTO:
|
|
|
|
case WESTON_RENDERER_NOOP:
|
|
|
|
if (config->decorate) {
|
|
|
|
weston_log("Error: no-op renderer does not support decorations.\n");
|
|
|
|
goto err_input;
|
|
|
|
}
|
2019-09-12 17:21:12 +03:00
|
|
|
ret = noop_renderer_init(compositor);
|
2022-12-29 21:20:26 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
weston_log("Error: unsupported renderer\n");
|
|
|
|
break;
|
|
|
|
}
|
2016-06-23 12:59:29 +03:00
|
|
|
|
2019-09-12 17:21:12 +03:00
|
|
|
if (ret < 0)
|
2014-02-07 12:34:43 +04:00
|
|
|
goto err_input;
|
2012-10-29 20:19:24 +04:00
|
|
|
|
2019-09-20 14:23:12 +03:00
|
|
|
if (compositor->renderer->import_dmabuf) {
|
|
|
|
if (linux_dmabuf_setup(compositor) < 0) {
|
|
|
|
weston_log("Error: dmabuf protocol setup failed.\n");
|
|
|
|
goto err_input;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-19 12:14:11 +03:00
|
|
|
/* Support zwp_linux_explicit_synchronization_unstable_v1 to enable
|
|
|
|
* testing. */
|
|
|
|
if (linux_explicit_synchronization_setup(compositor) < 0)
|
|
|
|
goto err_input;
|
|
|
|
|
2016-09-30 15:11:07 +03:00
|
|
|
ret = weston_plugin_api_register(compositor, WESTON_WINDOWED_OUTPUT_API_NAME,
|
|
|
|
&api, sizeof(api));
|
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
weston_log("Failed to register output API.\n");
|
|
|
|
goto err_input;
|
|
|
|
}
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
return b;
|
2012-10-29 20:19:24 +04:00
|
|
|
|
2014-02-07 12:34:43 +04:00
|
|
|
err_input:
|
2022-07-13 16:03:44 +03:00
|
|
|
if (b->theme)
|
|
|
|
theme_destroy(b->theme);
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
weston_compositor_shutdown(compositor);
|
2012-10-29 20:19:24 +04:00
|
|
|
err_free:
|
2014-10-11 19:27:30 +04:00
|
|
|
free(b);
|
2012-10-29 20:19:24 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-04-16 06:28:32 +03:00
|
|
|
static void
|
|
|
|
config_init_to_defaults(struct weston_headless_backend_config *config)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
WL_EXPORT int
|
2016-12-02 16:08:44 +03:00
|
|
|
weston_backend_init(struct weston_compositor *compositor,
|
|
|
|
struct weston_backend_config *config_base)
|
2012-10-29 20:19:24 +04:00
|
|
|
{
|
2014-10-11 19:27:30 +04:00
|
|
|
struct headless_backend *b;
|
2016-04-16 06:28:32 +03:00
|
|
|
struct weston_headless_backend_config config = {{ 0, }};
|
2012-10-29 20:19:24 +04:00
|
|
|
|
2016-04-16 06:28:32 +03:00
|
|
|
if (config_base == NULL ||
|
|
|
|
config_base->struct_version != WESTON_HEADLESS_BACKEND_CONFIG_VERSION ||
|
|
|
|
config_base->struct_size > sizeof(struct weston_headless_backend_config)) {
|
|
|
|
weston_log("headless backend config structure is invalid\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2014-11-20 02:06:17 +03:00
|
|
|
|
2016-04-16 06:28:32 +03:00
|
|
|
config_init_to_defaults(&config);
|
|
|
|
memcpy(&config, config_base, config_base->struct_size);
|
2014-11-20 02:06:18 +03:00
|
|
|
|
2016-04-16 06:28:32 +03:00
|
|
|
b = headless_backend_create(compositor, &config);
|
2014-10-11 19:27:30 +04:00
|
|
|
if (b == NULL)
|
|
|
|
return -1;
|
2016-04-16 06:28:32 +03:00
|
|
|
|
2014-10-11 19:27:30 +04:00
|
|
|
return 0;
|
2012-10-29 20:19:24 +04:00
|
|
|
}
|