clients: Add tearing control to simple-egl
Add a new command line option to test the tearing-control protocol. Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
This commit is contained in:
parent
58dde0e0c0
commit
ab897491df
@ -43,7 +43,7 @@
|
||||
variables:
|
||||
FDO_UPSTREAM_REPO: wayland/weston
|
||||
FDO_REPO_SUFFIX: "$BUILD_OS/$BUILD_ARCH"
|
||||
FDO_DISTRIBUTION_TAG: '2023-01-25.00-meson-0.63.0'
|
||||
FDO_DISTRIBUTION_TAG: '2023-02-01.00-wayland-protocols-1.30'
|
||||
|
||||
|
||||
include:
|
||||
|
@ -105,7 +105,7 @@ rm -rf wayland
|
||||
# Keep this version in sync with our dependency in meson.build. If you wish to
|
||||
# raise a MR against custom protocol, please change this reference to clone
|
||||
# your relevant tree, and make sure you bump $FDO_DISTRIBUTION_TAG.
|
||||
git clone --branch 1.26 --depth=1 https://gitlab.freedesktop.org/wayland/wayland-protocols
|
||||
git clone --branch 1.30 --depth=1 https://gitlab.freedesktop.org/wayland/wayland-protocols
|
||||
cd wayland-protocols
|
||||
git show -s HEAD
|
||||
meson build
|
||||
|
@ -128,6 +128,8 @@ simple_clients = [
|
||||
'name': 'egl',
|
||||
'sources': [
|
||||
'simple-egl.c',
|
||||
tearing_control_v1_client_protocol_h,
|
||||
tearing_control_v1_protocol_c,
|
||||
xdg_shell_client_protocol_h,
|
||||
xdg_shell_protocol_c,
|
||||
ivi_application_client_protocol_h,
|
||||
|
@ -43,6 +43,8 @@
|
||||
#include <EGL/eglext.h>
|
||||
|
||||
#include "xdg-shell-client-protocol.h"
|
||||
#include "tearing-control-v1-client-protocol.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@ -68,6 +70,7 @@ struct display {
|
||||
struct wl_cursor_theme *cursor_theme;
|
||||
struct wl_cursor *default_cursor;
|
||||
struct wl_surface *cursor_surface;
|
||||
struct wp_tearing_control_manager_v1 *tearing_manager;
|
||||
struct {
|
||||
EGLDisplay dpy;
|
||||
EGLContext ctx;
|
||||
@ -108,6 +111,8 @@ struct window {
|
||||
struct xdg_toplevel *xdg_toplevel;
|
||||
EGLSurface egl_surface;
|
||||
int fullscreen, maximized, opaque, buffer_bpp, frame_sync, delay;
|
||||
struct wp_tearing_control_v1 *tear_control;
|
||||
bool tearing, toggled_tearing, tear_enabled;
|
||||
bool fullscreen_ratio;
|
||||
bool wait_for_configure;
|
||||
|
||||
@ -539,6 +544,22 @@ destroy_window_output(struct window *window, struct wl_output *wl_output)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
set_tearing(struct window *window, bool enable)
|
||||
{
|
||||
if (!window->tear_control)
|
||||
return;
|
||||
|
||||
if (enable) {
|
||||
wp_tearing_control_v1_set_presentation_hint(window->tear_control,
|
||||
WP_TEARING_CONTROL_V1_PRESENTATION_HINT_ASYNC);
|
||||
} else {
|
||||
wp_tearing_control_v1_set_presentation_hint(window->tear_control,
|
||||
WP_TEARING_CONTROL_V1_PRESENTATION_HINT_VSYNC);
|
||||
}
|
||||
window->tear_enabled = enable;
|
||||
}
|
||||
|
||||
static void
|
||||
surface_enter(void *data,
|
||||
struct wl_surface *wl_surface, struct wl_output *wl_output)
|
||||
@ -570,6 +591,13 @@ create_surface(struct window *window)
|
||||
window->surface = wl_compositor_create_surface(display->compositor);
|
||||
wl_surface_add_listener(window->surface, &surface_listener, window);
|
||||
|
||||
if (display->tearing_manager && window->tearing) {
|
||||
window->tear_control = wp_tearing_control_manager_v1_get_tearing_control(
|
||||
display->tearing_manager,
|
||||
window->surface);
|
||||
set_tearing(window, true);
|
||||
}
|
||||
|
||||
window->xdg_surface = xdg_wm_base_get_xdg_surface(display->wm_base,
|
||||
window->surface);
|
||||
xdg_surface_add_listener(window->xdg_surface,
|
||||
@ -651,6 +679,8 @@ redraw(struct window *window)
|
||||
(float) window->frames / benchmark_interval);
|
||||
window->benchmark_time = time;
|
||||
window->frames = 0;
|
||||
if (window->toggled_tearing)
|
||||
set_tearing(window, window->tear_enabled ^ true);
|
||||
}
|
||||
|
||||
weston_matrix_init(&rotation);
|
||||
@ -1075,6 +1105,10 @@ registry_handle_global(void *data, struct wl_registry *registry,
|
||||
}
|
||||
} else if (strcmp(interface, "wl_output") == 0 && version >= 2) {
|
||||
display_add_output(d, name);
|
||||
} else if (strcmp(interface, "wp_tearing_control_manager_v1") == 0) {
|
||||
d->tearing_manager = wl_registry_bind(registry, name,
|
||||
&wp_tearing_control_manager_v1_interface,
|
||||
1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1115,6 +1149,8 @@ usage(int error_code)
|
||||
" -o\tCreate an opaque surface\n"
|
||||
" -s\tUse a 16 bpp EGL config\n"
|
||||
" -b\tDon't sync to compositor redraw (eglSwapInterval 0)\n"
|
||||
" -t\tEnable tearing via the tearing_control protocol\n"
|
||||
" -T\tEnable and disable tearing every 5 seconds\n"
|
||||
" -h\tThis help text\n\n");
|
||||
|
||||
exit(error_code);
|
||||
@ -1159,7 +1195,12 @@ main(int argc, char **argv)
|
||||
window.buffer_bpp = 16;
|
||||
else if (strcmp("-b", argv[i]) == 0)
|
||||
window.frame_sync = 0;
|
||||
else if (strcmp("-h", argv[i]) == 0)
|
||||
else if (strcmp("-t", argv[i]) == 0) {
|
||||
window.tearing = true;
|
||||
} else if (strcmp("-T", argv[i]) == 0) {
|
||||
window.tearing = true;
|
||||
window.toggled_tearing = true;
|
||||
} else if (strcmp("-h", argv[i]) == 0)
|
||||
usage(EXIT_SUCCESS);
|
||||
else
|
||||
usage(EXIT_FAILURE);
|
||||
|
@ -1,7 +1,7 @@
|
||||
dep_scanner = dependency('wayland-scanner', native: true)
|
||||
prog_scanner = find_program(dep_scanner.get_variable(pkgconfig: 'wayland_scanner'))
|
||||
|
||||
dep_wp = dependency('wayland-protocols', version: '>= 1.26',
|
||||
dep_wp = dependency('wayland-protocols', version: '>= 1.30',
|
||||
fallback: ['wayland-protocols', 'wayland_protocols'])
|
||||
dir_wp_base = dep_wp.get_variable(pkgconfig: 'pkgdatadir', internal: 'pkgdatadir')
|
||||
|
||||
@ -28,6 +28,7 @@ generated_protocols = [
|
||||
[ 'relative-pointer', 'unstable', 'v1' ],
|
||||
[ 'single-pixel-buffer', 'staging', 'v1' ],
|
||||
[ 'tablet', 'unstable', 'v2' ],
|
||||
[ 'tearing-control', 'staging', 'v1' ],
|
||||
[ 'text-cursor-position', 'internal' ],
|
||||
[ 'text-input', 'unstable', 'v1' ],
|
||||
[ 'viewporter', 'stable' ],
|
||||
|
Loading…
Reference in New Issue
Block a user