mirror of
https://gitlab.freedesktop.org/wayland/weston.git
synced 2025-12-25 17:40:11 +01:00
libweston: Set the presentation clock in the compositor
Let backends declare the presentation clocks they can use with a new bitfield weston_backend::supported_presentation_clocks and set presentation clock after loading the backend in the compositor. Make weston_compositor_set_presentation_clock() internal and replace weston_compositor_set_presentation_clock_software() with an exported weston_compositor_backends_loaded(), which is called by the compositor after the backend is loaded. In the future, this can be extended to determine the subset of clocks supported by all backends. Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
This commit is contained in:
parent
51d23a409a
commit
1d59530e4b
12 changed files with 57 additions and 34 deletions
|
|
@ -4141,6 +4141,9 @@ wet_main(int argc, char *argv[], const struct weston_testsuite_data *test_data)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (weston_compositor_backends_loaded(wet.compositor) < 0)
|
||||||
|
goto out;
|
||||||
|
|
||||||
if (test_data && !check_compositor_capabilities(wet.compositor,
|
if (test_data && !check_compositor_capabilities(wet.compositor,
|
||||||
test_data->test_quirks.required_capabilities)) {
|
test_data->test_quirks.required_capabilities)) {
|
||||||
ret = WET_MAIN_RET_MISSING_CAPS;
|
ret = WET_MAIN_RET_MISSING_CAPS;
|
||||||
|
|
|
||||||
|
|
@ -2665,6 +2665,9 @@ weston_compositor_add_screenshot_authority(struct weston_compositor *compositor,
|
||||||
void (*auth)(struct wl_listener *l,
|
void (*auth)(struct wl_listener *l,
|
||||||
struct weston_output_capture_attempt *att));
|
struct weston_output_capture_attempt *att));
|
||||||
|
|
||||||
|
int
|
||||||
|
weston_compositor_backends_loaded(struct weston_compositor *compositor);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1787,7 +1787,6 @@ int
|
||||||
init_kms_caps(struct drm_device *device)
|
init_kms_caps(struct drm_device *device)
|
||||||
{
|
{
|
||||||
struct drm_backend *b = device->backend;
|
struct drm_backend *b = device->backend;
|
||||||
struct weston_compositor *compositor = b->compositor;
|
|
||||||
uint64_t cap;
|
uint64_t cap;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
|
@ -1799,10 +1798,7 @@ init_kms_caps(struct drm_device *device)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (weston_compositor_set_presentation_clock(compositor, CLOCK_MONOTONIC) < 0) {
|
b->base.supported_presentation_clocks = 1 << CLOCK_MONOTONIC;
|
||||||
weston_log("Error: failed to set presentation clock to CLOCK_MONOTONIC.\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = drmGetCap(device->drm.fd, DRM_CAP_CURSOR_WIDTH, &cap);
|
ret = drmGetCap(device->drm.fd, DRM_CAP_CURSOR_WIDTH, &cap);
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
|
|
|
||||||
|
|
@ -539,8 +539,8 @@ headless_backend_create(struct weston_compositor *compositor,
|
||||||
b->compositor = compositor;
|
b->compositor = compositor;
|
||||||
compositor->backend = &b->base;
|
compositor->backend = &b->base;
|
||||||
|
|
||||||
if (weston_compositor_set_presentation_clock_software(compositor) < 0)
|
b->base.supported_presentation_clocks =
|
||||||
goto err_free;
|
WESTON_PRESENTATION_CLOCKS_SOFTWARE;
|
||||||
|
|
||||||
b->base.destroy = headless_destroy;
|
b->base.destroy = headless_destroy;
|
||||||
b->base.create_output = headless_output_create;
|
b->base.create_output = headless_output_create;
|
||||||
|
|
|
||||||
|
|
@ -1041,8 +1041,8 @@ pipewire_backend_create(struct weston_compositor *compositor,
|
||||||
backend->formats = pixel_format_get_array(pipewire_formats,
|
backend->formats = pixel_format_get_array(pipewire_formats,
|
||||||
backend->formats_count);
|
backend->formats_count);
|
||||||
|
|
||||||
if (weston_compositor_set_presentation_clock_software(compositor) < 0)
|
backend->base.supported_presentation_clocks =
|
||||||
goto err_compositor;
|
WESTON_PRESENTATION_CLOCKS_SOFTWARE;
|
||||||
|
|
||||||
switch (config->renderer) {
|
switch (config->renderer) {
|
||||||
case WESTON_RENDERER_AUTO:
|
case WESTON_RENDERER_AUTO:
|
||||||
|
|
|
||||||
|
|
@ -1891,8 +1891,8 @@ rdp_backend_create(struct weston_compositor *compositor,
|
||||||
|
|
||||||
wl_list_init(&b->peers);
|
wl_list_init(&b->peers);
|
||||||
|
|
||||||
if (weston_compositor_set_presentation_clock_software(compositor) < 0)
|
b->base.supported_presentation_clocks =
|
||||||
goto err_compositor;
|
WESTON_PRESENTATION_CLOCKS_SOFTWARE;
|
||||||
|
|
||||||
b->formats_count = ARRAY_LENGTH(rdp_formats);
|
b->formats_count = ARRAY_LENGTH(rdp_formats);
|
||||||
b->formats = pixel_format_get_array(rdp_formats, b->formats_count);
|
b->formats = pixel_format_get_array(rdp_formats, b->formats_count);
|
||||||
|
|
|
||||||
|
|
@ -1188,8 +1188,8 @@ vnc_backend_create(struct weston_compositor *compositor,
|
||||||
|
|
||||||
compositor->backend = &backend->base;
|
compositor->backend = &backend->base;
|
||||||
|
|
||||||
if (weston_compositor_set_presentation_clock_software(compositor) < 0)
|
backend->base.supported_presentation_clocks =
|
||||||
goto err_compositor;
|
WESTON_PRESENTATION_CLOCKS_SOFTWARE;
|
||||||
|
|
||||||
backend->formats_count = ARRAY_LENGTH(vnc_formats);
|
backend->formats_count = ARRAY_LENGTH(vnc_formats);
|
||||||
backend->formats = pixel_format_get_array(vnc_formats,
|
backend->formats = pixel_format_get_array(vnc_formats,
|
||||||
|
|
|
||||||
|
|
@ -2882,8 +2882,8 @@ wayland_backend_create(struct weston_compositor *compositor,
|
||||||
b->compositor = compositor;
|
b->compositor = compositor;
|
||||||
compositor->backend = &b->base;
|
compositor->backend = &b->base;
|
||||||
|
|
||||||
if (weston_compositor_set_presentation_clock_software(compositor) < 0)
|
b->base.supported_presentation_clocks =
|
||||||
goto err_compositor;
|
WESTON_PRESENTATION_CLOCKS_SOFTWARE;
|
||||||
|
|
||||||
b->parent.wl_display = wl_display_connect(new_config->display_name);
|
b->parent.wl_display = wl_display_connect(new_config->display_name);
|
||||||
if (b->parent.wl_display == NULL) {
|
if (b->parent.wl_display == NULL) {
|
||||||
|
|
|
||||||
|
|
@ -1884,8 +1884,8 @@ x11_backend_create(struct weston_compositor *compositor,
|
||||||
|
|
||||||
compositor->backend = &b->base;
|
compositor->backend = &b->base;
|
||||||
|
|
||||||
if (weston_compositor_set_presentation_clock_software(compositor) < 0)
|
b->base.supported_presentation_clocks =
|
||||||
goto err_free;
|
WESTON_PRESENTATION_CLOCKS_SOFTWARE;
|
||||||
|
|
||||||
b->dpy = XOpenDisplay(NULL);
|
b->dpy = XOpenDisplay(NULL);
|
||||||
if (b->dpy == NULL)
|
if (b->dpy == NULL)
|
||||||
|
|
|
||||||
|
|
@ -32,9 +32,20 @@
|
||||||
#ifndef LIBWESTON_BACKEND_INTERNAL_H
|
#ifndef LIBWESTON_BACKEND_INTERNAL_H
|
||||||
#define LIBWESTON_BACKEND_INTERNAL_H
|
#define LIBWESTON_BACKEND_INTERNAL_H
|
||||||
|
|
||||||
|
#define WESTON_PRESENTATION_CLOCKS_SOFTWARE \
|
||||||
|
((1 << CLOCK_MONOTONIC) | \
|
||||||
|
(1 << CLOCK_MONOTONIC_RAW) | \
|
||||||
|
(1 << CLOCK_MONOTONIC_COARSE))
|
||||||
|
|
||||||
struct weston_hdr_metadata_type1;
|
struct weston_hdr_metadata_type1;
|
||||||
|
|
||||||
struct weston_backend {
|
struct weston_backend {
|
||||||
|
/** Bitfield of supported presentation clocks
|
||||||
|
*
|
||||||
|
* Bit positions correspond to system clock IDs.
|
||||||
|
*/
|
||||||
|
unsigned int supported_presentation_clocks;
|
||||||
|
|
||||||
/** Prepare for compositor shutdown (optional)
|
/** Prepare for compositor shutdown (optional)
|
||||||
*
|
*
|
||||||
* This will be called before weston_compositor_shutdown()
|
* This will be called before weston_compositor_shutdown()
|
||||||
|
|
|
||||||
|
|
@ -8841,6 +8841,9 @@ weston_compositor_create(struct wl_display *display,
|
||||||
if (test_data)
|
if (test_data)
|
||||||
ec->test_data = *test_data;
|
ec->test_data = *test_data;
|
||||||
|
|
||||||
|
/* No backend supports CLOCK_REALTIME, use it to mean 'uninitialized' */
|
||||||
|
ec->presentation_clock = CLOCK_REALTIME;
|
||||||
|
|
||||||
ec->weston_log_ctx = log_ctx;
|
ec->weston_log_ctx = log_ctx;
|
||||||
ec->wl_display = display;
|
ec->wl_display = display;
|
||||||
ec->user_data = user_data;
|
ec->user_data = user_data;
|
||||||
|
|
@ -9046,10 +9049,7 @@ weston_compositor_set_default_pointer_grab(struct weston_compositor *ec,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** weston_compositor_set_presentation_clock
|
static int
|
||||||
* \ingroup compositor
|
|
||||||
*/
|
|
||||||
WL_EXPORT int
|
|
||||||
weston_compositor_set_presentation_clock(struct weston_compositor *compositor,
|
weston_compositor_set_presentation_clock(struct weston_compositor *compositor,
|
||||||
clockid_t clk_id)
|
clockid_t clk_id)
|
||||||
{
|
{
|
||||||
|
|
@ -9063,15 +9063,19 @@ weston_compositor_set_presentation_clock(struct weston_compositor *compositor,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** For choosing the software clock, when the display hardware or API
|
/** To be called by the compositor after the last backend is loaded.
|
||||||
* does not expose a compatible presentation timestamp.
|
*
|
||||||
|
* \param compositor A compositor that has all backends loaded.
|
||||||
|
*
|
||||||
|
* \return 0 on success, or -1 on error.
|
||||||
*
|
*
|
||||||
* \ingroup compositor
|
* \ingroup compositor
|
||||||
*/
|
*/
|
||||||
WL_EXPORT int
|
WL_EXPORT int
|
||||||
weston_compositor_set_presentation_clock_software(
|
weston_compositor_backends_loaded(struct weston_compositor *compositor)
|
||||||
struct weston_compositor *compositor)
|
|
||||||
{
|
{
|
||||||
|
struct weston_backend *backend = compositor->backend;
|
||||||
|
uint32_t supported_clocks = backend->supported_presentation_clocks;
|
||||||
/* In order of preference */
|
/* In order of preference */
|
||||||
static const clockid_t clocks[] = {
|
static const clockid_t clocks[] = {
|
||||||
CLOCK_MONOTONIC_RAW, /* no jumps, no crawling */
|
CLOCK_MONOTONIC_RAW, /* no jumps, no crawling */
|
||||||
|
|
@ -9080,10 +9084,17 @@ weston_compositor_set_presentation_clock_software(
|
||||||
};
|
};
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_LENGTH(clocks); i++)
|
for (i = 0; i < ARRAY_LENGTH(clocks); i++) {
|
||||||
|
clockid_t clk_id = clocks[i];
|
||||||
|
bool supported = (supported_clocks >> clocks[i]) & 1;
|
||||||
|
|
||||||
|
if (!supported)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (weston_compositor_set_presentation_clock(compositor,
|
if (weston_compositor_set_presentation_clock(compositor,
|
||||||
clocks[i]) == 0)
|
clk_id) == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
weston_log("Error: no suitable presentation clock available.\n");
|
weston_log("Error: no suitable presentation clock available.\n");
|
||||||
|
|
||||||
|
|
@ -9111,6 +9122,12 @@ weston_compositor_read_presentation_clock(
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Make sure weston_compositor_backends_loaded() was called.
|
||||||
|
* We use CLOCK_REALTIME to mean 'uninitialized'.
|
||||||
|
*/
|
||||||
|
assert(compositor->presentation_clock != CLOCK_REALTIME);
|
||||||
|
|
||||||
ret = clock_gettime(compositor->presentation_clock, ts);
|
ret = clock_gettime(compositor->presentation_clock, ts);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
ts->tv_sec = 0;
|
ts->tv_sec = 0;
|
||||||
|
|
|
||||||
|
|
@ -238,13 +238,6 @@ weston_compositor_set_touch_mode_normal(struct weston_compositor *compositor);
|
||||||
void
|
void
|
||||||
weston_compositor_set_touch_mode_calib(struct weston_compositor *compositor);
|
weston_compositor_set_touch_mode_calib(struct weston_compositor *compositor);
|
||||||
|
|
||||||
int
|
|
||||||
weston_compositor_set_presentation_clock(struct weston_compositor *compositor,
|
|
||||||
clockid_t clk_id);
|
|
||||||
int
|
|
||||||
weston_compositor_set_presentation_clock_software(
|
|
||||||
struct weston_compositor *compositor);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
weston_compositor_xkb_destroy(struct weston_compositor *ec);
|
weston_compositor_xkb_destroy(struct weston_compositor *ec);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue