examples: switch to new frame scheduling

This commit is contained in:
Rose Hudson 2023-07-29 11:26:39 +01:00
parent ea11856851
commit ef710e3fd4
11 changed files with 57 additions and 15 deletions

View file

@ -9,6 +9,7 @@
#include <wlr/backend.h> #include <wlr/backend.h>
#include <wlr/render/allocator.h> #include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h> #include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_frame_scheduler.h>
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_scene.h> #include <wlr/types/wlr_scene.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
@ -104,10 +105,11 @@ static void server_handle_new_output(struct wl_listener *listener, void *data) {
struct output *output = calloc(1, sizeof(struct output)); struct output *output = calloc(1, sizeof(struct output));
output->wlr = wlr_output; output->wlr = wlr_output;
output->server = server; output->server = server;
output->frame.notify = output_handle_frame;
wl_signal_add(&wlr_output->events.frame, &output->frame);
output->scene_output = wlr_scene_output_create(server->scene, wlr_output); output->scene_output = wlr_scene_output_create(server->scene, wlr_output);
output->scene_output->frame_scheduler = wlr_frame_scheduler_autocreate(wlr_output);
output->frame.notify = output_handle_frame;
wl_signal_add(&output->scene_output->frame_scheduler->frame, &output->frame);
struct wlr_output_state state; struct wlr_output_state state;
wlr_output_state_init(&state); wlr_output_state_init(&state);

View file

@ -10,6 +10,7 @@
#include <wlr/render/allocator.h> #include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h> #include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_compositor.h> #include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_frame_scheduler.h>
#include <wlr/types/wlr_fullscreen_shell_v1.h> #include <wlr/types/wlr_fullscreen_shell_v1.h>
#include <wlr/types/wlr_matrix.h> #include <wlr/types/wlr_matrix.h>
#include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_output_layout.h>
@ -39,6 +40,7 @@ struct fullscreen_output {
struct wl_list link; struct wl_list link;
struct fullscreen_server *server; struct fullscreen_server *server;
struct wlr_output *wlr_output; struct wlr_output *wlr_output;
struct wlr_frame_scheduler *frame_scheduler;
struct wlr_surface *surface; struct wlr_surface *surface;
struct wl_listener surface_destroy; struct wl_listener surface_destroy;
@ -158,10 +160,12 @@ static void server_handle_new_output(struct wl_listener *listener, void *data) {
calloc(1, sizeof(struct fullscreen_output)); calloc(1, sizeof(struct fullscreen_output));
output->wlr_output = wlr_output; output->wlr_output = wlr_output;
output->server = server; output->server = server;
output->frame.notify = output_handle_frame;
wl_signal_add(&wlr_output->events.frame, &output->frame);
wl_list_insert(&server->outputs, &output->link); wl_list_insert(&server->outputs, &output->link);
output->frame_scheduler = wlr_frame_scheduler_autocreate(wlr_output);
output->frame.notify = output_handle_frame;
wl_signal_add(&output->frame_scheduler->frame, &output->frame);
wlr_output_layout_add_auto(server->output_layout, wlr_output); wlr_output_layout_add_auto(server->output_layout, wlr_output);
wlr_output_create_global(wlr_output); wlr_output_create_global(wlr_output);

View file

@ -11,6 +11,7 @@
#include <wlr/render/wlr_renderer.h> #include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_compositor.h> #include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_drm.h> #include <wlr/types/wlr_drm.h>
#include <wlr/types/wlr_frame_scheduler.h>
#include <wlr/types/wlr_linux_dmabuf_v1.h> #include <wlr/types/wlr_linux_dmabuf_v1.h>
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_output_layer.h> #include <wlr/types/wlr_output_layer.h>
@ -57,6 +58,7 @@ struct output {
struct wl_list link; struct wl_list link;
struct server *server; struct server *server;
struct wlr_output *wlr_output; struct wlr_output *wlr_output;
struct wlr_frame_scheduler *frame_scheduler;
struct wl_list surfaces; struct wl_list surfaces;
struct wl_listener frame; struct wl_listener frame;
@ -170,10 +172,12 @@ static void server_handle_new_output(struct wl_listener *listener, void *data) {
output->wlr_output = wlr_output; output->wlr_output = wlr_output;
output->server = server; output->server = server;
wl_list_init(&output->surfaces); wl_list_init(&output->surfaces);
output->frame.notify = output_handle_frame;
wl_signal_add(&wlr_output->events.frame, &output->frame);
wl_list_insert(&server->outputs, &output->link); wl_list_insert(&server->outputs, &output->link);
output->frame_scheduler = wlr_frame_scheduler_autocreate(wlr_output);
output->frame.notify = output_handle_frame;
wl_signal_add(&output->frame_scheduler->frame, &output->frame);
struct wlr_output_state state; struct wlr_output_state state;
wlr_output_state_init(&state); wlr_output_state_init(&state);
wlr_output_state_set_enabled(&state, true); wlr_output_state_set_enabled(&state, true);

View file

@ -13,6 +13,7 @@
#include <wlr/backend/session.h> #include <wlr/backend/session.h>
#include <wlr/render/allocator.h> #include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h> #include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_frame_scheduler.h>
#include <wlr/types/wlr_keyboard.h> #include <wlr/types/wlr_keyboard.h>
#include <wlr/types/wlr_matrix.h> #include <wlr/types/wlr_matrix.h>
#include <wlr/types/wlr_input_device.h> #include <wlr/types/wlr_input_device.h>
@ -39,6 +40,7 @@ struct sample_state {
struct sample_output { struct sample_output {
struct sample_state *sample; struct sample_state *sample;
struct wlr_output *output; struct wlr_output *output;
struct wlr_frame_scheduler *frame_scheduler;
struct wl_listener frame; struct wl_listener frame;
struct wl_listener destroy; struct wl_listener destroy;
}; };
@ -172,7 +174,8 @@ static void new_output_notify(struct wl_listener *listener, void *data) {
wlr_output_layout_add_auto(sample->layout, output); wlr_output_layout_add_auto(sample->layout, output);
sample_output->output = output; sample_output->output = output;
sample_output->sample = sample; sample_output->sample = sample;
wl_signal_add(&output->events.frame, &sample_output->frame); sample_output->frame_scheduler = wlr_frame_scheduler_autocreate(output);
wl_signal_add(&sample_output->frame_scheduler->frame, &sample_output->frame);
sample_output->frame.notify = output_frame_notify; sample_output->frame.notify = output_frame_notify;
wl_signal_add(&output->events.destroy, &sample_output->destroy); wl_signal_add(&output->events.destroy, &sample_output->destroy);
sample_output->destroy.notify = output_remove_notify; sample_output->destroy.notify = output_remove_notify;

View file

@ -12,6 +12,7 @@
#include <wlr/render/allocator.h> #include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h> #include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_cursor.h> #include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_frame_scheduler.h>
#include <wlr/types/wlr_keyboard.h> #include <wlr/types/wlr_keyboard.h>
#include <wlr/types/wlr_matrix.h> #include <wlr/types/wlr_matrix.h>
#include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_output_layout.h>
@ -64,6 +65,7 @@ struct touch_point {
struct sample_output { struct sample_output {
struct sample_state *state; struct sample_state *state;
struct wlr_output *output; struct wlr_output *output;
struct wlr_frame_scheduler *frame_scheduler;
struct wl_listener frame; struct wl_listener frame;
struct wl_listener destroy; struct wl_listener destroy;
}; };
@ -269,7 +271,8 @@ static void new_output_notify(struct wl_listener *listener, void *data) {
struct sample_output *sample_output = calloc(1, sizeof(struct sample_output)); struct sample_output *sample_output = calloc(1, sizeof(struct sample_output));
sample_output->output = output; sample_output->output = output;
sample_output->state = sample; sample_output->state = sample;
wl_signal_add(&output->events.frame, &sample_output->frame); sample_output->frame_scheduler = wlr_frame_scheduler_autocreate(output);
wl_signal_add(&sample_output->frame_scheduler->frame, &sample_output->frame);
sample_output->frame.notify = output_frame_notify; sample_output->frame.notify = output_frame_notify;
wl_signal_add(&output->events.destroy, &sample_output->destroy); wl_signal_add(&output->events.destroy, &sample_output->destroy);
sample_output->destroy.notify = output_remove_notify; sample_output->destroy.notify = output_remove_notify;

View file

@ -12,6 +12,7 @@
#include <wlr/backend.h> #include <wlr/backend.h>
#include <wlr/render/allocator.h> #include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h> #include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_frame_scheduler.h>
#include <wlr/types/wlr_keyboard.h> #include <wlr/types/wlr_keyboard.h>
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_input_device.h> #include <wlr/types/wlr_input_device.h>
@ -35,6 +36,7 @@ struct sample_state {
struct sample_output { struct sample_output {
struct sample_state *sample; struct sample_state *sample;
struct wlr_output *output; struct wlr_output *output;
struct wlr_frame_scheduler *frame_scheduler;
struct wl_listener frame; struct wl_listener frame;
struct wl_listener destroy; struct wl_listener destroy;
float x_offs, y_offs; float x_offs, y_offs;
@ -125,7 +127,8 @@ static void new_output_notify(struct wl_listener *listener, void *data) {
sample_output->output = output; sample_output->output = output;
sample_output->sample = sample; sample_output->sample = sample;
wl_signal_add(&output->events.frame, &sample_output->frame); sample_output->frame_scheduler = wlr_frame_scheduler_autocreate(output);
wl_signal_add(&sample_output->frame_scheduler->frame, &sample_output->frame);
sample_output->frame.notify = output_frame_notify; sample_output->frame.notify = output_frame_notify;
wl_signal_add(&output->events.destroy, &sample_output->destroy); wl_signal_add(&output->events.destroy, &sample_output->destroy);
sample_output->destroy.notify = output_remove_notify; sample_output->destroy.notify = output_remove_notify;

View file

@ -11,6 +11,7 @@
#include <wlr/render/allocator.h> #include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h> #include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_compositor.h> #include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_frame_scheduler.h>
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_scene.h> #include <wlr/types/wlr_scene.h>
#include <wlr/types/wlr_xdg_shell.h> #include <wlr/types/wlr_xdg_shell.h>
@ -76,10 +77,11 @@ static void server_handle_new_output(struct wl_listener *listener, void *data) {
calloc(1, sizeof(struct output)); calloc(1, sizeof(struct output));
output->wlr = wlr_output; output->wlr = wlr_output;
output->server = server; output->server = server;
output->frame.notify = output_handle_frame;
wl_signal_add(&wlr_output->events.frame, &output->frame);
output->scene_output = wlr_scene_output_create(server->scene, wlr_output); output->scene_output = wlr_scene_output_create(server->scene, wlr_output);
output->scene_output->frame_scheduler = wlr_frame_scheduler_autocreate(wlr_output);
output->frame.notify = output_handle_frame;
wl_signal_add(&output->scene_output->frame_scheduler->frame, &output->frame);
struct wlr_output_state state; struct wlr_output_state state;
wlr_output_state_init(&state); wlr_output_state_init(&state);

View file

@ -9,6 +9,7 @@
#include <wlr/backend/session.h> #include <wlr/backend/session.h>
#include <wlr/render/allocator.h> #include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h> #include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_frame_scheduler.h>
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_input_device.h> #include <wlr/types/wlr_input_device.h>
#include <wlr/types/wlr_keyboard.h> #include <wlr/types/wlr_keyboard.h>
@ -29,6 +30,7 @@ struct sample_state {
struct sample_output { struct sample_output {
struct sample_state *sample; struct sample_state *sample;
struct wlr_output *output; struct wlr_output *output;
struct wlr_frame_scheduler *frame_scheduler;
struct wl_listener frame; struct wl_listener frame;
struct wl_listener destroy; struct wl_listener destroy;
}; };
@ -101,7 +103,9 @@ static void new_output_notify(struct wl_listener *listener, void *data) {
calloc(1, sizeof(struct sample_output)); calloc(1, sizeof(struct sample_output));
sample_output->output = output; sample_output->output = output;
sample_output->sample = sample; sample_output->sample = sample;
wl_signal_add(&output->events.frame, &sample_output->frame);
sample_output->frame_scheduler = wlr_frame_scheduler_autocreate(output);
wl_signal_add(&sample_output->frame_scheduler->frame, &sample_output->frame);
sample_output->frame.notify = output_frame_notify; sample_output->frame.notify = output_frame_notify;
wl_signal_add(&output->events.destroy, &sample_output->destroy); wl_signal_add(&output->events.destroy, &sample_output->destroy);
sample_output->destroy.notify = output_remove_notify; sample_output->destroy.notify = output_remove_notify;

View file

@ -10,6 +10,7 @@
#include <wlr/backend/session.h> #include <wlr/backend/session.h>
#include <wlr/render/allocator.h> #include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h> #include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_frame_scheduler.h>
#include <wlr/types/wlr_matrix.h> #include <wlr/types/wlr_matrix.h>
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_input_device.h> #include <wlr/types/wlr_input_device.h>
@ -66,6 +67,7 @@ struct tablet_pad_state {
struct sample_output { struct sample_output {
struct sample_state *sample; struct sample_state *sample;
struct wlr_output *output; struct wlr_output *output;
struct wlr_frame_scheduler *frame_scheduler;
struct wl_listener frame; struct wl_listener frame;
struct wl_listener destroy; struct wl_listener destroy;
}; };
@ -273,7 +275,9 @@ static void new_output_notify(struct wl_listener *listener, void *data) {
struct sample_output *sample_output = calloc(1, sizeof(struct sample_output)); struct sample_output *sample_output = calloc(1, sizeof(struct sample_output));
sample_output->output = output; sample_output->output = output;
sample_output->sample = sample; sample_output->sample = sample;
wl_signal_add(&output->events.frame, &sample_output->frame);
sample_output->frame_scheduler = wlr_frame_scheduler_autocreate(output);
wl_signal_add(&sample_output->frame_scheduler->frame, &sample_output->frame);
sample_output->frame.notify = output_frame_notify; sample_output->frame.notify = output_frame_notify;
wl_signal_add(&output->events.destroy, &sample_output->destroy); wl_signal_add(&output->events.destroy, &sample_output->destroy);
sample_output->destroy.notify = output_remove_notify; sample_output->destroy.notify = output_remove_notify;

View file

@ -12,6 +12,7 @@
#include <wlr/backend/session.h> #include <wlr/backend/session.h>
#include <wlr/render/allocator.h> #include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h> #include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_frame_scheduler.h>
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_input_device.h> #include <wlr/types/wlr_input_device.h>
#include <wlr/types/wlr_keyboard.h> #include <wlr/types/wlr_keyboard.h>
@ -54,6 +55,7 @@ struct touch_state {
struct sample_output { struct sample_output {
struct sample_state *sample; struct sample_state *sample;
struct wlr_output *output; struct wlr_output *output;
struct wlr_frame_scheduler *frame_scheduler;
struct wl_listener frame; struct wl_listener frame;
struct wl_listener destroy; struct wl_listener destroy;
}; };
@ -178,7 +180,9 @@ static void new_output_notify(struct wl_listener *listener, void *data) {
struct sample_output *sample_output = calloc(1, sizeof(struct sample_output)); struct sample_output *sample_output = calloc(1, sizeof(struct sample_output));
sample_output->output = output; sample_output->output = output;
sample_output->sample = sample; sample_output->sample = sample;
wl_signal_add(&output->events.frame, &sample_output->frame);
sample_output->frame_scheduler = wlr_frame_scheduler_autocreate(output);
wl_signal_add(&sample_output->frame_scheduler->frame, &sample_output->frame);
sample_output->frame.notify = output_frame_notify; sample_output->frame.notify = output_frame_notify;
wl_signal_add(&output->events.destroy, &sample_output->destroy); wl_signal_add(&output->events.destroy, &sample_output->destroy);
sample_output->destroy.notify = output_remove_notify; sample_output->destroy.notify = output_remove_notify;

View file

@ -13,6 +13,7 @@
#include <wlr/types/wlr_cursor.h> #include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_compositor.h> #include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_data_device.h> #include <wlr/types/wlr_data_device.h>
#include <wlr/types/wlr_frame_scheduler.h>
#include <wlr/types/wlr_input_device.h> #include <wlr/types/wlr_input_device.h>
#include <wlr/types/wlr_keyboard.h> #include <wlr/types/wlr_keyboard.h>
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
@ -72,6 +73,7 @@ struct tinywl_output {
struct wl_list link; struct wl_list link;
struct tinywl_server *server; struct tinywl_server *server;
struct wlr_output *wlr_output; struct wlr_output *wlr_output;
struct wlr_frame_scheduler *frame_scheduler;
struct wl_listener frame; struct wl_listener frame;
struct wl_listener request_state; struct wl_listener request_state;
struct wl_listener destroy; struct wl_listener destroy;
@ -621,9 +623,12 @@ static void server_new_output(struct wl_listener *listener, void *data) {
output->wlr_output = wlr_output; output->wlr_output = wlr_output;
output->server = server; output->server = server;
/* Creates a frame scheduler, which is responsible for telling us when to render. */
output->frame_scheduler = wlr_frame_scheduler_autocreate(wlr_output);
/* Sets up a listener for the frame event. */ /* Sets up a listener for the frame event. */
output->frame.notify = output_frame; output->frame.notify = output_frame;
wl_signal_add(&wlr_output->events.frame, &output->frame); wl_signal_add(&output->frame_scheduler->frame, &output->frame);
/* Sets up a listener for the state request event. */ /* Sets up a listener for the state request event. */
output->request_state.notify = output_request_state; output->request_state.notify = output_request_state;
@ -645,6 +650,10 @@ static void server_new_output(struct wl_listener *listener, void *data) {
* output (such as DPI, scale factor, manufacturer, etc). * output (such as DPI, scale factor, manufacturer, etc).
*/ */
wlr_output_layout_add_auto(server->output_layout, wlr_output); wlr_output_layout_add_auto(server->output_layout, wlr_output);
/* Make the scene aware of the frame scheduler so that it can trigger frames. */
struct wlr_scene_output *scene_output = wlr_scene_get_scene_output(server->scene, wlr_output);
scene_output->frame_scheduler = output->frame_scheduler;
} }
static void xdg_toplevel_map(struct wl_listener *listener, void *data) { static void xdg_toplevel_map(struct wl_listener *listener, void *data) {