aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2019-11-16 21:05:46 +0100
committerDrew DeVault <sir@cmpwn.com>2019-11-21 11:32:30 -0500
commite959b882d52788158fd8cd5db1bc32ef1d93533b (patch)
tree1a3f575a0b8f92a05f18e3739bf3b7a52978a121 /backend
parent2122e49beaac2453707c136e418e196a41537912 (diff)
backend/wayland: add support for presentation-time
Diffstat (limited to 'backend')
-rw-r--r--backend/wayland/backend.c7
-rw-r--r--backend/wayland/output.c87
2 files changed, 89 insertions, 5 deletions
diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c
index 14db4d72..c23be048 100644
--- a/backend/wayland/backend.c
+++ b/backend/wayland/backend.c
@@ -19,6 +19,7 @@
#include "util/signal.h"
#include "linux-dmabuf-unstable-v1-client-protocol.h"
#include "pointer-gestures-unstable-v1-client-protocol.h"
+#include "presentation-time-client-protocol.h"
#include "xdg-decoration-unstable-v1-client-protocol.h"
#include "xdg-shell-client-protocol.h"
#include "tablet-unstable-v2-client-protocol.h"
@@ -108,6 +109,9 @@ static void registry_global(void *data, struct wl_registry *registry,
} else if (strcmp(iface, zwp_pointer_gestures_v1_interface.name) == 0) {
wl->zwp_pointer_gestures_v1 = wl_registry_bind(registry, name,
&zwp_pointer_gestures_v1_interface, 1);
+ } else if (strcmp(iface, wp_presentation_interface.name) == 0) {
+ wl->presentation = wl_registry_bind(registry, name,
+ &wp_presentation_interface, 1);
} else if (strcmp(iface, zwp_tablet_manager_v2_interface.name) == 0) {
wl->tablet_manager = wl_registry_bind(registry, name,
&zwp_tablet_manager_v2_interface, 1);
@@ -202,6 +206,9 @@ static void backend_destroy(struct wlr_backend *backend) {
if (wl->zwp_pointer_gestures_v1) {
zwp_pointer_gestures_v1_destroy(wl->zwp_pointer_gestures_v1);
}
+ if (wl->presentation) {
+ wp_presentation_destroy(wl->presentation);
+ }
if (wl->zwp_linux_dmabuf_v1) {
zwp_linux_dmabuf_v1_destroy(wl->zwp_linux_dmabuf_v1);
}
diff --git a/backend/wayland/output.c b/backend/wayland/output.c
index 808d147a..5d3a5ff5 100644
--- a/backend/wayland/output.c
+++ b/backend/wayland/output.c
@@ -17,6 +17,7 @@
#include "backend/wayland.h"
#include "util/signal.h"
#include "linux-dmabuf-unstable-v1-client-protocol.h"
+#include "presentation-time-client-protocol.h"
#include "xdg-decoration-unstable-v1-client-protocol.h"
#include "xdg-shell-client-protocol.h"
@@ -26,8 +27,6 @@ static struct wlr_wl_output *get_wl_output_from_output(
return (struct wlr_wl_output *)wlr_output;
}
-static struct wl_callback_listener frame_listener;
-
static void surface_frame_callback(void *data, struct wl_callback *cb,
uint32_t time) {
struct wlr_wl_output *output = data;
@@ -38,10 +37,60 @@ static void surface_frame_callback(void *data, struct wl_callback *cb,
wlr_output_send_frame(&output->wlr_output);
}
-static struct wl_callback_listener frame_listener = {
+static const struct wl_callback_listener frame_listener = {
.done = surface_frame_callback
};
+static void presentation_feedback_destroy(
+ struct wlr_wl_presentation_feedback *feedback) {
+ wl_list_remove(&feedback->link);
+ wp_presentation_feedback_destroy(feedback->feedback);
+ free(feedback);
+}
+
+static void presentation_feedback_handle_sync_output(void *data,
+ struct wp_presentation_feedback *feedback, struct wl_output *output) {
+ // This space is intentionally left blank
+}
+
+static void presentation_feedback_handle_presented(void *data,
+ struct wp_presentation_feedback *wp_feedback, uint32_t tv_sec_hi,
+ uint32_t tv_sec_lo, uint32_t tv_nsec, uint32_t refresh_ns,
+ uint32_t seq_hi, uint32_t seq_lo, uint32_t flags) {
+ struct wlr_wl_presentation_feedback *feedback = data;
+
+ struct timespec t = {
+ .tv_sec = ((uint64_t)tv_sec_hi << 32) | tv_sec_lo,
+ .tv_nsec = tv_nsec,
+ };
+ struct wlr_output_event_present event = {
+ .commit_seq = feedback->commit_seq,
+ .when = &t,
+ .seq = ((uint64_t)seq_hi << 32) | seq_lo,
+ .refresh = refresh_ns,
+ .flags = flags,
+ };
+ wlr_output_send_present(&feedback->output->wlr_output, &event);
+
+ presentation_feedback_destroy(feedback);
+}
+
+static void presentation_feedback_handle_discarded(void *data,
+ struct wp_presentation_feedback *wp_feedback) {
+ struct wlr_wl_presentation_feedback *feedback = data;
+
+ wlr_output_send_present(&feedback->output->wlr_output, NULL);
+
+ presentation_feedback_destroy(feedback);
+}
+
+static const struct wp_presentation_feedback_listener
+ presentation_feedback_listener = {
+ .sync_output = presentation_feedback_handle_sync_output,
+ .presented = presentation_feedback_handle_presented,
+ .discarded = presentation_feedback_handle_discarded,
+};
+
static bool output_set_custom_mode(struct wlr_output *wlr_output,
int32_t width, int32_t height, int32_t refresh) {
struct wlr_wl_output *output = get_wl_output_from_output(wlr_output);
@@ -137,6 +186,12 @@ static bool output_commit(struct wlr_output *wlr_output) {
output->current_wl_buffer = NULL;
}
+ struct wp_presentation_feedback *wp_feedback = NULL;
+ if (output->backend->presentation != NULL) {
+ wp_feedback = wp_presentation_feedback(output->backend->presentation,
+ output->surface);
+ }
+
assert(wlr_output->pending.committed & WLR_OUTPUT_STATE_BUFFER);
switch (wlr_output->pending.buffer_type) {
case WLR_OUTPUT_STATE_BUFFER_RENDER:
@@ -167,8 +222,23 @@ static bool output_commit(struct wlr_output *wlr_output) {
break;
}
- // TODO: if available, use the presentation-time protocol
- wlr_output_send_present(wlr_output, NULL);
+ if (wp_feedback != NULL) {
+ struct wlr_wl_presentation_feedback *feedback =
+ calloc(1, sizeof(*feedback));
+ if (feedback == NULL) {
+ wp_presentation_feedback_destroy(wp_feedback);
+ return false;
+ }
+ feedback->output = output;
+ feedback->feedback = wp_feedback;
+ feedback->commit_seq = output->wlr_output.commit_seq + 1;
+ wl_list_insert(&output->presentation_feedbacks, &feedback->link);
+
+ wp_presentation_feedback_add_listener(wp_feedback,
+ &presentation_feedback_listener, feedback);
+ } else {
+ wlr_output_send_present(wlr_output, NULL);
+ }
return true;
}
@@ -267,6 +337,12 @@ static void output_destroy(struct wlr_output *wlr_output) {
wl_callback_destroy(output->frame_callback);
}
+ struct wlr_wl_presentation_feedback *feedback, *feedback_tmp;
+ wl_list_for_each_safe(feedback, feedback_tmp,
+ &output->presentation_feedbacks, link) {
+ presentation_feedback_destroy(feedback);
+ }
+
wlr_egl_destroy_surface(&output->backend->egl, output->egl_surface);
wl_egl_window_destroy(output->egl_window);
if (output->zxdg_toplevel_decoration_v1) {
@@ -383,6 +459,7 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *wlr_backend) {
++backend->last_output_num);
output->backend = backend;
+ wl_list_init(&output->presentation_feedbacks);
output->surface = wl_compositor_create_surface(backend->compositor);
if (!output->surface) {